@oyasmi/pipiclaw 0.9.3 → 0.9.4-beta.1
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/dist/agent/channel-runner.js +137 -61
- package/dist/agent/command-extension.js +47 -34
- package/dist/agent/job-manager.js +31 -11
- package/dist/agent/model-fallback.js +1 -1
- package/dist/agent/prompt/manifest.d.ts +6 -1
- package/dist/agent/prompt/manifest.js +45 -64
- package/dist/agent/prompt/resources.js +4 -1
- package/dist/agent/run-queue.js +7 -2
- package/dist/agent/session-adapter.js +1 -1
- package/dist/agent/session-events.js +17 -6
- package/dist/agent/session-resource-gate.js +3 -1
- package/dist/agent/status-render.d.ts +0 -1
- package/dist/agent/status-render.js +4 -16
- package/dist/agent/turn-error.d.ts +31 -0
- package/dist/agent/turn-error.js +68 -0
- package/dist/app-services.js +7 -4
- package/dist/channel/channel-index.js +4 -1
- package/dist/channel/project-scope-store.js +1 -1
- package/dist/commands/catalog.d.ts +21 -4
- package/dist/commands/catalog.js +88 -41
- package/dist/commands/reply-limits.d.ts +6 -0
- package/dist/commands/reply-limits.js +24 -0
- package/dist/events/event-commands.js +94 -44
- package/dist/events/event-validation.d.ts +13 -2
- package/dist/events/event-validation.js +17 -9
- package/dist/events/events.js +77 -32
- package/dist/executor.js +2 -2
- package/dist/log.d.ts +12 -2
- package/dist/log.js +26 -34
- package/dist/main.js +1 -1
- package/dist/memory/commands.js +29 -23
- package/dist/memory/lifecycle.js +26 -5
- package/dist/memory/maintenance-state.js +4 -1
- package/dist/memory/scheduler.js +3 -1
- package/dist/models/auth-cli.js +3 -2
- package/dist/paths.d.ts +2 -0
- package/dist/paths.js +9 -0
- package/dist/playbooks/agent-delegation.md +2 -2
- package/dist/runtime/app-home.d.ts +6 -0
- package/dist/runtime/app-home.js +21 -3
- package/dist/runtime/bootstrap.js +189 -60
- package/dist/runtime/channel-queue.js +1 -1
- package/dist/runtime/delivery.js +29 -15
- package/dist/runtime/dingtalk.js +96 -42
- package/dist/runtime/durable-dispatch.d.ts +27 -1
- package/dist/runtime/durable-dispatch.js +111 -3
- package/dist/runtime/project-commands.js +16 -15
- package/dist/runtime/proxy.js +4 -2
- package/dist/runtime/report-commands.js +1 -1
- package/dist/runtime/skill-commands.d.ts +1 -1
- package/dist/runtime/skill-commands.js +17 -10
- package/dist/runtime/subagent-commands.d.ts +5 -4
- package/dist/runtime/subagent-commands.js +116 -77
- package/dist/runtime/task-commands.d.ts +1 -1
- package/dist/runtime/task-commands.js +110 -64
- package/dist/runtime/task-driver.d.ts +4 -2
- package/dist/runtime/task-driver.js +55 -20
- package/dist/runtime/task-migration.js +23 -6
- package/dist/runtime/task-spawn.js +12 -5
- package/dist/runtime/wake-coalescing.d.ts +18 -0
- package/dist/runtime/wake-coalescing.js +29 -0
- package/dist/security/block-message.d.ts +22 -1
- package/dist/security/block-message.js +66 -1
- package/dist/security/network.d.ts +2 -1
- package/dist/security/network.js +3 -2
- package/dist/security/path-guard-check.js +2 -2
- package/dist/settings.d.ts +3 -2
- package/dist/settings.js +4 -1
- package/dist/shared/format.d.ts +12 -0
- package/dist/shared/format.js +37 -0
- package/dist/shared/host-process.js +15 -3
- package/dist/shared/with-timeout.d.ts +3 -2
- package/dist/shared/with-timeout.js +14 -3
- package/dist/subagents/external/claude-code.js +23 -1
- package/dist/subagents/external/progress-tail.d.ts +17 -0
- package/dist/subagents/external/progress-tail.js +64 -17
- package/dist/subagents/external/run.d.ts +3 -0
- package/dist/subagents/external/run.js +21 -7
- package/dist/subagents/external/settlement.d.ts +3 -0
- package/dist/subagents/external/settlement.js +1 -1
- package/dist/subagents/runs.d.ts +21 -1
- package/dist/subagents/runs.js +137 -32
- package/dist/subagents/tool.d.ts +22 -15
- package/dist/subagents/tool.js +226 -32
- package/dist/subagents/workspace-summary.d.ts +16 -4
- package/dist/subagents/workspace-summary.js +74 -18
- package/dist/tasks/board.d.ts +8 -1
- package/dist/tasks/board.js +37 -2
- package/dist/tasks/frontmatter.d.ts +5 -0
- package/dist/tasks/frontmatter.js +8 -0
- package/dist/tasks/log.d.ts +11 -1
- package/dist/tasks/log.js +58 -2
- package/dist/tasks/store.js +4 -2
- package/dist/tasks/ticket.d.ts +3 -1
- package/dist/tasks/ticket.js +19 -1
- package/dist/tools/bash.js +2 -2
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +1 -0
- package/dist/tools/memory-manage.js +4 -1
- package/dist/tools/subagent-manage.d.ts +1 -1
- package/dist/tools/subagent-manage.js +16 -11
- package/dist/tools/task-manage/step-end.js +4 -1
- package/dist/tools/tool-details.d.ts +10 -2
- package/dist/tools/tool-details.js +39 -2
- package/dist/tui/cli.js +2 -2
- package/dist/tui/commands.js +4 -4
- package/dist/tui/pitui-frontend.js +1 -1
- package/dist/tui/renderer.js +3 -2
- package/dist/tui/turn-controller.d.ts +2 -0
- package/dist/tui/turn-controller.js +36 -21
- package/dist/usage/ledger.js +3 -1
- package/dist/usage/render.js +3 -1
- package/package.json +1 -1
package/dist/tasks/board.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { formatElapsedZh } from "../shared/format.js";
|
|
1
2
|
import { parseLocalTime } from "../shared/local-time.js";
|
|
3
|
+
import { truncate } from "../shared/text-utils.js";
|
|
2
4
|
import { parseTaskItems } from "./ledger.js";
|
|
3
|
-
import { readTaskLog } from "./log.js";
|
|
5
|
+
import { describeSettlement, describeWorkRef, readTaskLog, } from "./log.js";
|
|
4
6
|
/** Ref lines the board renders before folding old, already-seen results away. */
|
|
5
7
|
export const BOARD_REF_LINE_BUDGET = 12;
|
|
6
8
|
export async function buildTaskBoard(channelDir, taskId, body) {
|
|
@@ -91,7 +93,7 @@ function renderRef(entry, nowMs) {
|
|
|
91
93
|
return `${label} ${parts.join(" ")}${tail ? ` ${tail}` : ""}`;
|
|
92
94
|
}
|
|
93
95
|
const ITEM_MARKER = { todo: " ", done: "x", blocked: "!", dropped: "~" };
|
|
94
|
-
/** Render the `<task_board>` block body. */
|
|
96
|
+
/** Render the `<task_board>` block body (model-facing; `/tasks show` uses `renderTaskBoardForUser`). */
|
|
95
97
|
export function renderTaskBoard(board, nowMs = Date.now()) {
|
|
96
98
|
const lines = [];
|
|
97
99
|
for (const { item, refs } of board.items) {
|
|
@@ -110,6 +112,39 @@ export function renderTaskBoard(board, nowMs = Date.now()) {
|
|
|
110
112
|
lines.push(`- (另有 ${board.hiddenSettled} 项已结算且已看过,见 task_log)`);
|
|
111
113
|
return lines.join("\n");
|
|
112
114
|
}
|
|
115
|
+
const ITEM_STATUS_LABEL = {
|
|
116
|
+
todo: "待办",
|
|
117
|
+
done: "已完成",
|
|
118
|
+
blocked: "受阻",
|
|
119
|
+
dropped: "已放弃",
|
|
120
|
+
};
|
|
121
|
+
function renderRefForUser(entry, nowMs) {
|
|
122
|
+
const who = entry.agent && entry.agent !== "job" ? `(${entry.agent}${entry.purpose === "verify" ? ",验收" : ""})` : "";
|
|
123
|
+
const state = entry.settled
|
|
124
|
+
? describeSettlement(entry.settled)
|
|
125
|
+
: `进行中 ${formatElapsedZh(nowMs - entry.dispatchedAtMs)}`;
|
|
126
|
+
return `${describeWorkRef(entry.ref)}${who} ${state}`;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The board as `/tasks show` presents it (spec 053, D2): flat bullets only — DingTalk drops
|
|
130
|
+
* indentation, so the brief's `↳` continuation lines would read as orphans — with every ref a
|
|
131
|
+
* work item has folded into its one line. No "seen / new" split (that is the leader's
|
|
132
|
+
* de-duplication aid) and no pointer at a model tool.
|
|
133
|
+
*/
|
|
134
|
+
export function renderTaskBoardForUser(board, taskId, nowMs = Date.now()) {
|
|
135
|
+
const lines = [];
|
|
136
|
+
for (const { item, refs } of board.items) {
|
|
137
|
+
const head = `- ${item.id} ${truncate(item.text.replace(/\s+/g, " "), 80)}(${ITEM_STATUS_LABEL[item.status]})`;
|
|
138
|
+
lines.push(refs.length > 0 ? `${head}:${refs.map((ref) => renderRefForUser(ref, nowMs)).join("、")}` : head);
|
|
139
|
+
}
|
|
140
|
+
if (board.unlinked.length > 0) {
|
|
141
|
+
lines.push(`- 未关联工作项:${board.unlinked.map((ref) => renderRefForUser(ref, nowMs)).join("、")}`);
|
|
142
|
+
}
|
|
143
|
+
if (board.hiddenSettled > 0) {
|
|
144
|
+
lines.push(`- 另有 ${board.hiddenSettled} 项较早结束的工作未列出,用 \`/tasks log ${taskId}\` 查看`);
|
|
145
|
+
}
|
|
146
|
+
return lines.join("\n");
|
|
147
|
+
}
|
|
113
148
|
/**
|
|
114
149
|
* The `<task_results>` block body: what came back since the previous step, as the completion wake
|
|
115
150
|
* showed it — the output's tail and, for a run, what it left changed. A task step's brief replaces
|
|
@@ -48,6 +48,11 @@ export interface ParsedTaskFrontmatter {
|
|
|
48
48
|
/** True when a v3 line (`status`, `control`, `schedule`…) is present — the file is not converted, so it never runs. */
|
|
49
49
|
legacy: boolean;
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* The one user-facing name for a task state (spec 053, D8). `/tasks`, the stop receipt and the
|
|
53
|
+
* spawn-skip receipt all read it here, so a third hand-written copy cannot drift again.
|
|
54
|
+
*/
|
|
55
|
+
export declare function taskStateLabel(state: TaskState): string;
|
|
51
56
|
/**
|
|
52
57
|
* Read the leading frontmatter block. Unreadable input fails **open** to a live `open` task: a
|
|
53
58
|
* corrupt file has to surface as work the runtime tries to touch, not silently disappear from the
|
|
@@ -2,6 +2,14 @@ import { formatLocalTime } from "../shared/local-time.js";
|
|
|
2
2
|
import { isPlainObject } from "../shared/type-guards.js";
|
|
3
3
|
import { parseTicket } from "./ticket.js";
|
|
4
4
|
const STATES = ["open", "parked", "done"];
|
|
5
|
+
const STATE_LABELS = { open: "进行中", parked: "等待中", done: "已结束" };
|
|
6
|
+
/**
|
|
7
|
+
* The one user-facing name for a task state (spec 053, D8). `/tasks`, the stop receipt and the
|
|
8
|
+
* spawn-skip receipt all read it here, so a third hand-written copy cannot drift again.
|
|
9
|
+
*/
|
|
10
|
+
export function taskStateLabel(state) {
|
|
11
|
+
return STATE_LABELS[state] ?? state;
|
|
12
|
+
}
|
|
5
13
|
/** Fixed render order, so a diff of a task file reads the same way every time. */
|
|
6
14
|
const FIELD_ORDER = ["state", "paused", "origin", "ticket", "usage", "budget"];
|
|
7
15
|
/** v3 frontmatter keys; their presence means the one-time conversion has not run on this file. */
|
package/dist/tasks/log.d.ts
CHANGED
|
@@ -115,5 +115,15 @@ export interface ReadTaskLogOptions {
|
|
|
115
115
|
* alike even though it was still on disk.
|
|
116
116
|
*/
|
|
117
117
|
export declare function readTaskLog(channelDir: string, id: string, options?: ReadTaskLogOptions): Promise<TaskLogRecord[]>;
|
|
118
|
-
/** One line per record, for the step brief and `/tasks
|
|
118
|
+
/** One line per record, for the step brief and `task_log` (model-facing; `/tasks` uses `renderTaskLogLineForUser`). */
|
|
119
119
|
export declare function renderTaskLogLine(record: TaskLogRecord): string;
|
|
120
|
+
/** A run id is `run_…`; anything else bound to a task is a background job. */
|
|
121
|
+
export declare function describeWorkRef(ref: string): string;
|
|
122
|
+
/** A settled run/job's outcome in words: `完成,验收通过` / `失败(退出码 1)`. */
|
|
123
|
+
export declare function describeSettlement(settle: Pick<TaskSettleRecord, "status" | "verdict" | "exitCode">): string;
|
|
124
|
+
/**
|
|
125
|
+
* One line per record for `/tasks show` and `/tasks log` (spec 053, D2). The same records as
|
|
126
|
+
* `renderTaskLogLine`, said in the user's terms: no `task_step_end` outcome values, no `VERDICT`,
|
|
127
|
+
* no tool names, minute precision.
|
|
128
|
+
*/
|
|
129
|
+
export declare function renderTaskLogLineForUser(record: TaskLogRecord): string;
|
package/dist/tasks/log.js
CHANGED
|
@@ -3,7 +3,7 @@ import { readFile } from "node:fs/promises";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { createJsonlAppender } from "../shared/jsonl-appender.js";
|
|
5
5
|
import { formatLocalTime } from "../shared/local-time.js";
|
|
6
|
-
import { clipText } from "../shared/text-utils.js";
|
|
6
|
+
import { clipText, truncate } from "../shared/text-utils.js";
|
|
7
7
|
import { isPlainObject } from "../shared/type-guards.js";
|
|
8
8
|
import { normalizeTaskId } from "./ledger.js";
|
|
9
9
|
/** Same rotation shape as the channel archive: the log is working history, not an audit trail. */
|
|
@@ -112,7 +112,7 @@ export async function readTaskLog(channelDir, id, options = {}) {
|
|
|
112
112
|
}
|
|
113
113
|
return options.limit !== undefined && records.length > options.limit ? records.slice(-options.limit) : records;
|
|
114
114
|
}
|
|
115
|
-
/** One line per record, for the step brief and `/tasks
|
|
115
|
+
/** One line per record, for the step brief and `task_log` (model-facing; `/tasks` uses `renderTaskLogLineForUser`). */
|
|
116
116
|
export function renderTaskLogLine(record) {
|
|
117
117
|
switch (record.kind) {
|
|
118
118
|
case "step":
|
|
@@ -129,3 +129,59 @@ export function renderTaskLogLine(record) {
|
|
|
129
129
|
return `- [${record.ts}] ${record.note}`;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
+
/** `2026-10-11T14:02:33.000+08:00` → `10-11 14:02`: read straight off the stored wall-clock text, never re-zoned. */
|
|
133
|
+
function minuteStamp(ts) {
|
|
134
|
+
const match = /^\d{4}-(\d{2}-\d{2})T(\d{2}:\d{2})/.exec(ts);
|
|
135
|
+
return match ? `${match[1]} ${match[2]}` : ts;
|
|
136
|
+
}
|
|
137
|
+
/** A run id is `run_…`; anything else bound to a task is a background job. */
|
|
138
|
+
export function describeWorkRef(ref) {
|
|
139
|
+
return /^run_/i.test(ref) ? `委派 \`${ref}\`` : `后台作业 \`${ref}\``;
|
|
140
|
+
}
|
|
141
|
+
const SETTLE_STATUS = {
|
|
142
|
+
completed: "完成",
|
|
143
|
+
failed: "失败",
|
|
144
|
+
cancelled: "已取消",
|
|
145
|
+
lost: "已丢失",
|
|
146
|
+
running: "进行中",
|
|
147
|
+
};
|
|
148
|
+
/** A settled run/job's outcome in words: `完成,验收通过` / `失败(退出码 1)`. */
|
|
149
|
+
export function describeSettlement(settle) {
|
|
150
|
+
const parts = [SETTLE_STATUS[settle.status] ?? settle.status];
|
|
151
|
+
if (settle.verdict)
|
|
152
|
+
parts.push(settle.verdict === "pass" ? "验收通过" : "验收未通过");
|
|
153
|
+
const exit = settle.exitCode !== undefined && settle.exitCode !== 0 ? `(退出码 ${settle.exitCode})` : "";
|
|
154
|
+
return `${parts.join(",")}${exit}`;
|
|
155
|
+
}
|
|
156
|
+
function oneLine(text, max) {
|
|
157
|
+
return truncate(text.replace(/\s+/g, " ").trim(), max);
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* One line per record for `/tasks show` and `/tasks log` (spec 053, D2). The same records as
|
|
161
|
+
* `renderTaskLogLine`, said in the user's terms: no `task_step_end` outcome values, no `VERDICT`,
|
|
162
|
+
* no tool names, minute precision.
|
|
163
|
+
*/
|
|
164
|
+
export function renderTaskLogLineForUser(record) {
|
|
165
|
+
const at = minuteStamp(record.ts);
|
|
166
|
+
switch (record.kind) {
|
|
167
|
+
case "step": {
|
|
168
|
+
const after = record.outcome === "park" ? "(之后转入等待)" : record.outcome === "done" ? "(任务完成)" : "";
|
|
169
|
+
const reported = record.report ? ",已向你汇报" : "";
|
|
170
|
+
return `- ${at} 第 ${record.seq} 步:${oneLine(record.note, 160)}${after}${reported}`;
|
|
171
|
+
}
|
|
172
|
+
case "dispatch": {
|
|
173
|
+
const who = record.agent && record.agent !== "job"
|
|
174
|
+
? `(${record.agent}${record.purpose === "verify" ? ",验收" : ""})`
|
|
175
|
+
: "";
|
|
176
|
+
return `- ${at} 开始${describeWorkRef(record.ref)}${who}${record.item ? `,对应工作项 ${record.item}` : ""}`;
|
|
177
|
+
}
|
|
178
|
+
case "settle":
|
|
179
|
+
return `- ${at} ${describeWorkRef(record.ref)}结束:${describeSettlement(record)}`;
|
|
180
|
+
case "expired":
|
|
181
|
+
return `- ${at} 等待超时(${oneLine(record.ticket, 80)}),${record.action === "reopened" ? "已重新开始" : "已暂停"}`;
|
|
182
|
+
case "close":
|
|
183
|
+
return `- ${at} ${record.outcome === "done" ? "任务完成" : "任务取消"}:${oneLine(record.note, 160)}`;
|
|
184
|
+
case "note":
|
|
185
|
+
return `- ${at} ${oneLine(record.note, 160)}`;
|
|
186
|
+
}
|
|
187
|
+
}
|
package/dist/tasks/store.js
CHANGED
|
@@ -46,7 +46,9 @@ export async function writeStoredTask(document) {
|
|
|
46
46
|
const rendered = renderTaskDocument(fields, document.body);
|
|
47
47
|
const size = Buffer.byteLength(rendered, "utf-8");
|
|
48
48
|
if (size > MAX_CONTRACT_BYTES) {
|
|
49
|
-
log.
|
|
49
|
+
log.logWarn("tasks.contract.oversized", "Task contract exceeds its byte target; every step pays for it", {
|
|
50
|
+
fields: { taskId: document.id, bytes: size, targetBytes: MAX_CONTRACT_BYTES },
|
|
51
|
+
});
|
|
50
52
|
}
|
|
51
53
|
await writeFileAtomically(document.path, rendered);
|
|
52
54
|
}
|
|
@@ -132,7 +134,7 @@ export async function expireTicket(channelDir, id, limit = 2) {
|
|
|
132
134
|
outcome = "paused";
|
|
133
135
|
task.fields.paused = {
|
|
134
136
|
by: "runtime",
|
|
135
|
-
reason:
|
|
137
|
+
reason: `等待条件连续 ${expired} 次未满足:${summary}`,
|
|
136
138
|
at: formatLocalTime(),
|
|
137
139
|
};
|
|
138
140
|
return;
|
package/dist/tasks/ticket.d.ts
CHANGED
|
@@ -65,5 +65,7 @@ export declare function ticketBackstopMs(ticket: Ticket): number | undefined;
|
|
|
65
65
|
export declare function ticketExpired(ticket: Ticket, now?: Date): boolean;
|
|
66
66
|
/** The moment a `time` ticket is *due*. Only `time` tickets are driver-polled; the rest are pushed by their owner. */
|
|
67
67
|
export declare function ticketDueMs(ticket: Ticket): number | undefined;
|
|
68
|
-
/** One-line summary for
|
|
68
|
+
/** One-line summary for the step brief and the expiry record (model-facing). */
|
|
69
69
|
export declare function describeTicket(ticket: Ticket): string;
|
|
70
|
+
/** The same summary in the user's terms, for `/tasks` (spec 053, D4). */
|
|
71
|
+
export declare function describeTicketForUser(ticket: Ticket): string;
|
package/dist/tasks/ticket.js
CHANGED
|
@@ -107,7 +107,7 @@ export function ticketExpired(ticket, now = new Date()) {
|
|
|
107
107
|
export function ticketDueMs(ticket) {
|
|
108
108
|
return ticket.kind === "time" ? parseLocalTime(ticket.at) : undefined;
|
|
109
109
|
}
|
|
110
|
-
/** One-line summary for
|
|
110
|
+
/** One-line summary for the step brief and the expiry record (model-facing). */
|
|
111
111
|
export function describeTicket(ticket) {
|
|
112
112
|
switch (ticket.kind) {
|
|
113
113
|
case "time":
|
|
@@ -118,3 +118,21 @@ export function describeTicket(ticket) {
|
|
|
118
118
|
return `等待用户回答:${ticket.asked}`;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
+
/** `2026-10-12T09:00:00.000+08:00` → `10-12 09:00`, read off the stored wall-clock text. */
|
|
122
|
+
function minuteOf(at) {
|
|
123
|
+
const match = /^\d{4}-(\d{2}-\d{2})T(\d{2}:\d{2})/.exec(at);
|
|
124
|
+
return match ? `${match[1]} ${match[2]}` : at;
|
|
125
|
+
}
|
|
126
|
+
/** The same summary in the user's terms, for `/tasks` (spec 053, D4). */
|
|
127
|
+
export function describeTicketForUser(ticket) {
|
|
128
|
+
switch (ticket.kind) {
|
|
129
|
+
case "time":
|
|
130
|
+
return `等到 ${minuteOf(ticket.at)}`;
|
|
131
|
+
case "work":
|
|
132
|
+
return ticket.refs.length > 0
|
|
133
|
+
? `等待 ${ticket.refs.map((ref) => `\`${ref}\``).join("、")} 完成`
|
|
134
|
+
: "等待委派或后台作业完成";
|
|
135
|
+
case "ask":
|
|
136
|
+
return `等你回答:${ticket.asked}`;
|
|
137
|
+
}
|
|
138
|
+
}
|
package/dist/tools/bash.js
CHANGED
|
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
|
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { Type } from "typebox";
|
|
6
6
|
import { CommandTerminatedError, EXECUTOR_SHELL_IS_BASH } from "../executor.js";
|
|
7
|
-
import { formatBlockMessage } from "../security/block-message.js";
|
|
7
|
+
import { formatBlockMessage, GuardBlockedError } from "../security/block-message.js";
|
|
8
8
|
import { guardCommand } from "../security/command-guard.js";
|
|
9
9
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
10
10
|
import { logSecurityEvent } from "../security/logger.js";
|
|
@@ -188,7 +188,7 @@ export function createBashTool(executor, options = {}) {
|
|
|
188
188
|
reason: guardResult.reason,
|
|
189
189
|
matchedText: guardResult.matchedText,
|
|
190
190
|
});
|
|
191
|
-
throw new
|
|
191
|
+
throw new GuardBlockedError(formatCommandBlockMessage(command, guardResult.category, guardResult.reason, guardResult.matchedText), { guard: "command", category: guardResult.category, target: command });
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
// Steer a few bare shell patterns to their dedicated tool. After the guard (which must see
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface CreatePipiclawToolsOptions {
|
|
|
27
27
|
channelId: string;
|
|
28
28
|
getSubAgentDiscovery: () => SubAgentDiscoveryResult;
|
|
29
29
|
getSubAgentModelReference?: () => string | null;
|
|
30
|
+
/** `settings.fallbackModel`, resolved; an internal sub-agent switches to it once on a failed run. */
|
|
31
|
+
resolveFallbackModel?: () => Promise<Model<Api> | null>;
|
|
30
32
|
getSessionSearchSettings: () => PipiclawSessionSearchSettings;
|
|
31
33
|
securityConfig: SecurityConfig;
|
|
32
34
|
toolsConfig: PipiclawToolsConfig;
|
package/dist/tools/index.js
CHANGED
|
@@ -59,6 +59,7 @@ export function createPipiclawTools(options) {
|
|
|
59
59
|
channelDir: options.channelDir,
|
|
60
60
|
getSubAgentDiscovery: options.getSubAgentDiscovery,
|
|
61
61
|
getSubAgentModelReference: options.getSubAgentModelReference,
|
|
62
|
+
resolveFallbackModel: options.resolveFallbackModel,
|
|
62
63
|
securityConfig,
|
|
63
64
|
webConfig: toolsConfig.tools.web,
|
|
64
65
|
rtkEnabled: toolsConfig.tools.rtk.enabled,
|
|
@@ -191,7 +191,10 @@ function buildMemoryClosures(options) {
|
|
|
191
191
|
reason: "memory-forget",
|
|
192
192
|
actions: [{ op: "forget", name: trimmed, contentHash: hashMemoryContent(entry.description) }],
|
|
193
193
|
}).catch((error) => {
|
|
194
|
-
log.
|
|
194
|
+
log.logWarn("memory.review_log.write_failed", "Memory review log write failed", {
|
|
195
|
+
channelId: options.channelId,
|
|
196
|
+
reason: errorMessage(error),
|
|
197
|
+
});
|
|
195
198
|
});
|
|
196
199
|
return textResult(`Removed \`${trimmed}\` from channel memory. Its content is tombstoned against automatic replay; if the fact is stated again later it may be re-learned. Journal and session history are unchanged.`, { forgotten: true, name: trimmed });
|
|
197
200
|
}
|
|
@@ -15,7 +15,7 @@ export interface SubAgentManageToolOptions {
|
|
|
15
15
|
/**
|
|
16
16
|
* Spec 042 D7: required, not defaulted. `follow_up` dispatches a new external process through
|
|
17
17
|
* the same envelope and audit path the initial dispatch uses (D9's verify task path, D8.1's
|
|
18
|
-
* audit log, D7's `
|
|
18
|
+
* audit log, D7's `buildFollowUpTask`) — all of which need the real value. The previous
|
|
19
19
|
* `options.workspaceDir ?? ""` silently pointed the audit log at the daemon's own cwd and
|
|
20
20
|
* malformed the verify task path; production has always supplied both, so making them required
|
|
21
21
|
* only tightens what was already true rather than changing production behavior.
|
|
@@ -4,10 +4,12 @@ import { Type } from "typebox";
|
|
|
4
4
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
5
5
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
6
6
|
import { externalRoleFingerprint, validateSubAgentTask } from "../subagents/discovery.js";
|
|
7
|
+
import { readLastOutputAt, STALL_THRESHOLD_MS } from "../subagents/external/progress-tail.js";
|
|
7
8
|
import { launchExternalRun } from "../subagents/external/run.js";
|
|
8
9
|
import { formatCost, formatRunDuration, harnessLabel } from "../subagents/format.js";
|
|
9
|
-
import { assertVerifyAdmissible, assertWithinProjectBoundary,
|
|
10
|
+
import { assertVerifyAdmissible, assertWithinProjectBoundary, buildFollowUpTask, } from "../subagents/tool.js";
|
|
10
11
|
import { acquireWorkspaceLease, formatWorkspaceLeaseConflict, releaseWorkspaceLease, } from "../subagents/workspace-lease.js";
|
|
12
|
+
import { snapshotWorkspace } from "../subagents/workspace-summary.js";
|
|
11
13
|
// Spec 047, P3: `subagent_list` is zero-argument and shape-independent (like `task_list`); the
|
|
12
14
|
// other three ops all take `runId`, so they stay together in `subagent_run` rather than being
|
|
13
15
|
// split per-verb (`cancel` and `show` have identical parameter sets).
|
|
@@ -73,6 +75,13 @@ async function formatRunShow(record) {
|
|
|
73
75
|
}
|
|
74
76
|
if (record.sessionId)
|
|
75
77
|
lines.push(`sessionId: ${record.sessionId} (usable with subagent_run op=follow_up)`);
|
|
78
|
+
if (record.runtime === "external" && record.status === "running") {
|
|
79
|
+
// The one signal that tells a long, busy run apart from a stuck one without reading its logs.
|
|
80
|
+
const lastOutputAt = await readLastOutputAt(record.artifactDir);
|
|
81
|
+
const silentMs = Date.now() - (lastOutputAt ?? record.processStartedAt ?? record.startedAt);
|
|
82
|
+
const stalled = silentMs >= STALL_THRESHOLD_MS ? " — possibly stalled; cancel if it should have progressed" : "";
|
|
83
|
+
lines.push(`last output: ${Math.round(silentMs / 1000)}s ago${stalled}`);
|
|
84
|
+
}
|
|
76
85
|
if (record.runtime === "external") {
|
|
77
86
|
const stderrTail = await readFile(join(record.artifactDir, "stderr.log"), "utf-8")
|
|
78
87
|
.then((text) => text.slice(-STDERR_TAIL_CHARS))
|
|
@@ -237,18 +246,13 @@ export function createSubAgentRunTool(options) {
|
|
|
237
246
|
workingDirectory: record.workingDirectory,
|
|
238
247
|
artifactDir,
|
|
239
248
|
};
|
|
240
|
-
//
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
// that left the external agent unaware of its own working/artifact directories.
|
|
249
|
+
// The resumed session already holds the first dispatch's full envelope; the follow-up
|
|
250
|
+
// envelope carries only what is new (its own artifact directory, the instruction, and the
|
|
251
|
+
// checker protocol again for a verify run) — see `buildFollowUpTask`.
|
|
244
252
|
let launchResult;
|
|
245
253
|
try {
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
workspaceDir: options.workspaceDir,
|
|
249
|
-
runtimeContext: { workspaceDir: options.workspaceDir, channelId: options.channelId },
|
|
250
|
-
});
|
|
251
|
-
const envelopedTask = buildSubAgentTask(task, role, { workspaceDir: options.workspaceDir, channelId: options.channelId }, contextualBlocks, runContext);
|
|
254
|
+
const envelopedTask = buildFollowUpTask(task, { workspaceDir: options.workspaceDir, channelId: options.channelId }, runContext);
|
|
255
|
+
const workspaceBaseline = role.mutates === "write" ? await snapshotWorkspace(record.workingDirectory) : undefined;
|
|
252
256
|
launchResult = await launchExternalRun({
|
|
253
257
|
runManager: manager,
|
|
254
258
|
runId: newRunId,
|
|
@@ -274,6 +278,7 @@ export function createSubAgentRunTool(options) {
|
|
|
274
278
|
leaseKey,
|
|
275
279
|
resumeSessionId: record.sessionId,
|
|
276
280
|
mutates: role.mutates,
|
|
281
|
+
workspaceBaseline,
|
|
277
282
|
roleFingerprint: currentFingerprint,
|
|
278
283
|
workspaceDir: options.workspaceDir,
|
|
279
284
|
securityConfig: options.securityConfig ?? DEFAULT_SECURITY_CONFIG,
|
|
@@ -101,7 +101,10 @@ export async function endTaskStep(options, request) {
|
|
|
101
101
|
// A task waiting on the user that says nothing is the same silent dead end tickets exist to
|
|
102
102
|
// prevent, so an `ask` park always speaks.
|
|
103
103
|
if (ticket.kind === "ask") {
|
|
104
|
-
pendingNotice = [
|
|
104
|
+
pendingNotice = [
|
|
105
|
+
report,
|
|
106
|
+
`⚠️ 任务 \`${id}\` 需要你的决定:${ticket.asked}\n用 \`/tasks reply ${id} <内容>\` 回答。`,
|
|
107
|
+
]
|
|
105
108
|
.filter(Boolean)
|
|
106
109
|
.join("\n\n");
|
|
107
110
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import { type GuardBlock } from "../security/block-message.js";
|
|
2
3
|
/**
|
|
3
4
|
* The `details` contract for tool results, and the recoverable-rejection mechanism
|
|
4
5
|
* built on it.
|
|
@@ -50,8 +51,15 @@ export declare function isRecoverableRejection(result: unknown): boolean;
|
|
|
50
51
|
*/
|
|
51
52
|
export declare function isArgumentValidationFailure(result: unknown, isError: boolean): boolean;
|
|
52
53
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
54
|
+
* Claim the guard refusal behind a failed tool call. `resultText` must be the error text the SDK
|
|
55
|
+
* reported for that call: a stale or colliding id from another channel never matches it, so the
|
|
56
|
+
* worst case is falling back to the plain error line, never showing someone else's refusal.
|
|
57
|
+
*/
|
|
58
|
+
export declare function takeGuardBlock(toolCallId: string, resultText: string): GuardBlock | undefined;
|
|
59
|
+
/**
|
|
60
|
+
* Bind a tool to the contract: stamp `kind` on every result it returns, convert a
|
|
61
|
+
* `RecoverableToolError` into a normal result the model can read and act on, and park a guard
|
|
62
|
+
* refusal's structured form for the chat (`takeGuardBlock`).
|
|
55
63
|
*
|
|
56
64
|
* Applied once in `buildToolSet`, so every registered tool is covered without each one
|
|
57
65
|
* having to remember. `kind` is stamped last and unconditionally: the name a tool is
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GuardBlockedError } from "../security/block-message.js";
|
|
1
2
|
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
2
3
|
import { isRecord } from "../shared/type-guards.js";
|
|
3
4
|
/**
|
|
@@ -52,8 +53,42 @@ export function isArgumentValidationFailure(result, isError) {
|
|
|
52
53
|
return text.startsWith('Validation failed for tool "');
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
|
-
*
|
|
56
|
-
*
|
|
56
|
+
* Guard refusals waiting for their `tool_execution_end` (spec 053, D5.2).
|
|
57
|
+
*
|
|
58
|
+
* A refusal must stay a *thrown* error — that is what makes the SDK mark the result `isError`,
|
|
59
|
+
* which the model sees — but the SDK rebuilds a thrown error's result from `message` alone
|
|
60
|
+
* (`createErrorToolResult`, `details: {}`), so structured data cannot ride on the result itself.
|
|
61
|
+
* It is parked here under the tool call id instead and claimed by the session-event handler.
|
|
62
|
+
* Bounded, because a tool set whose events nobody consumes (an internal sub-agent) never claims.
|
|
63
|
+
*/
|
|
64
|
+
const pendingGuardBlocks = new Map();
|
|
65
|
+
const MAX_PENDING_GUARD_BLOCKS = 64;
|
|
66
|
+
function noteGuardBlock(toolCallId, error) {
|
|
67
|
+
pendingGuardBlocks.delete(toolCallId);
|
|
68
|
+
pendingGuardBlocks.set(toolCallId, { message: error.message, blocked: error.blocked });
|
|
69
|
+
while (pendingGuardBlocks.size > MAX_PENDING_GUARD_BLOCKS) {
|
|
70
|
+
const oldest = pendingGuardBlocks.keys().next().value;
|
|
71
|
+
if (oldest === undefined)
|
|
72
|
+
break;
|
|
73
|
+
pendingGuardBlocks.delete(oldest);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Claim the guard refusal behind a failed tool call. `resultText` must be the error text the SDK
|
|
78
|
+
* reported for that call: a stale or colliding id from another channel never matches it, so the
|
|
79
|
+
* worst case is falling back to the plain error line, never showing someone else's refusal.
|
|
80
|
+
*/
|
|
81
|
+
export function takeGuardBlock(toolCallId, resultText) {
|
|
82
|
+
const entry = pendingGuardBlocks.get(toolCallId);
|
|
83
|
+
if (!entry || entry.message !== resultText)
|
|
84
|
+
return undefined;
|
|
85
|
+
pendingGuardBlocks.delete(toolCallId);
|
|
86
|
+
return entry.blocked;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Bind a tool to the contract: stamp `kind` on every result it returns, convert a
|
|
90
|
+
* `RecoverableToolError` into a normal result the model can read and act on, and park a guard
|
|
91
|
+
* refusal's structured form for the chat (`takeGuardBlock`).
|
|
57
92
|
*
|
|
58
93
|
* Applied once in `buildToolSet`, so every registered tool is covered without each one
|
|
59
94
|
* having to remember. `kind` is stamped last and unconditionally: the name a tool is
|
|
@@ -79,6 +114,8 @@ export function withToolDetails(tool, kind) {
|
|
|
79
114
|
details: { kind, recoverable: true },
|
|
80
115
|
};
|
|
81
116
|
}
|
|
117
|
+
if (error instanceof GuardBlockedError)
|
|
118
|
+
noteGuardBlock(toolCallId, error);
|
|
82
119
|
throw error;
|
|
83
120
|
}
|
|
84
121
|
},
|
package/dist/tui/cli.js
CHANGED
|
@@ -61,8 +61,8 @@ function printTuiHelp(io) {
|
|
|
61
61
|
io.log(" --channel <id> Channel to attach to (default: tui_local).");
|
|
62
62
|
io.log(" Use dm_<staffId> to share a DingTalk conversation's memory.");
|
|
63
63
|
io.log(" --print, -p One-shot: run [prompt] (or stdin), print the answer, exit");
|
|
64
|
-
io.log(" --
|
|
65
|
-
io.log(" --
|
|
64
|
+
io.log(" --plain Use the line-based frontend instead of the full-screen UI");
|
|
65
|
+
io.log(" --quiet, -q Print only the final answer, no progress (implies --plain)");
|
|
66
66
|
io.log(" --version Print the version and exit");
|
|
67
67
|
io.log("");
|
|
68
68
|
io.log("Note: do not attach --channel to a DingTalk conversation the daemon is actively serving.");
|
package/dist/tui/commands.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* depend on whether a turn is running, which only the app knows — so those come
|
|
14
14
|
* back as intents rather than being applied here.
|
|
15
15
|
*/
|
|
16
|
-
import { BUILT_IN_COMMANDS, parseBuiltInCommand, SESSION_COMMANDS, } from "../commands/catalog.js";
|
|
16
|
+
import { BUILT_IN_COMMANDS, formatMissingQueueMessage, parseBuiltInCommand, SESSION_COMMANDS, } from "../commands/catalog.js";
|
|
17
17
|
export async function dispatch(input, deps) {
|
|
18
18
|
const trimmed = input.trim();
|
|
19
19
|
if (!trimmed)
|
|
@@ -43,11 +43,11 @@ export async function dispatch(input, deps) {
|
|
|
43
43
|
case "steer":
|
|
44
44
|
return command.args.trim()
|
|
45
45
|
? { kind: "steer", text: command.args }
|
|
46
|
-
: { kind: "noop", text: "
|
|
46
|
+
: { kind: "noop", text: formatMissingQueueMessage("steer") };
|
|
47
47
|
case "followup":
|
|
48
48
|
return command.args.trim()
|
|
49
49
|
? { kind: "followup", text: command.args }
|
|
50
|
-
: { kind: "noop", text: "
|
|
50
|
+
: { kind: "noop", text: formatMissingQueueMessage("followup") };
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
function toAutocompleteEntry(spec) {
|
|
@@ -60,5 +60,5 @@ function toAutocompleteEntry(spec) {
|
|
|
60
60
|
export const TUI_SLASH_COMMANDS = [
|
|
61
61
|
...BUILT_IN_COMMANDS.map(toAutocompleteEntry),
|
|
62
62
|
...SESSION_COMMANDS.map(toAutocompleteEntry),
|
|
63
|
-
{ name: "exit", description: "
|
|
63
|
+
{ name: "exit", description: "退出终端界面" },
|
|
64
64
|
];
|
|
@@ -47,7 +47,7 @@ export class PiTuiFrontend {
|
|
|
47
47
|
this.spinnerShown = false;
|
|
48
48
|
this.ui = new TuiMainScreen(new ProcessTerminal(), true);
|
|
49
49
|
this.editor = new Editor(this.ui, EDITOR_THEME, { paddingX: 1 });
|
|
50
|
-
this.loader = new Loader(this.ui, (s) => cyan(s), (s) => gray(s), "
|
|
50
|
+
this.loader = new Loader(this.ui, (s) => cyan(s), (s) => gray(s), "处理中…");
|
|
51
51
|
if (options.commands?.length) {
|
|
52
52
|
this.editor.setAutocompleteProvider(new CombinedAutocompleteProvider(options.commands, options.basePath ?? process.cwd(), null));
|
|
53
53
|
}
|
package/dist/tui/renderer.js
CHANGED
|
@@ -8,8 +8,9 @@ export function createFrontend(options = {}) {
|
|
|
8
8
|
const isTty = process.stdout.isTTY === true && process.stdin.isTTY === true;
|
|
9
9
|
// `--print`/one-shot (interactive === false) must use the plain stream even on a
|
|
10
10
|
// TTY, or the answer is trapped in a full-screen pi-tui frame and never reaches a
|
|
11
|
-
// clean stdout.
|
|
12
|
-
|
|
11
|
+
// clean stdout. `--quiet` is about how much is printed, and only the plain stream can print
|
|
12
|
+
// less, so it implies `--plain` rather than being silently ignored by the full-screen UI.
|
|
13
|
+
if (options.plain || options.quiet || !isTty || options.interactive === false) {
|
|
13
14
|
return new PlainFrontend({ quiet: options.quiet, interactive: options.interactive });
|
|
14
15
|
}
|
|
15
16
|
return new PiTuiFrontend({ commands: options.commands, basePath: options.basePath });
|
|
@@ -57,6 +57,8 @@ export declare class TurnController {
|
|
|
57
57
|
private handleInterrupt;
|
|
58
58
|
private requestExit;
|
|
59
59
|
private buildWelcome;
|
|
60
|
+
/** One word per state; `idle` and `ready` used to name the same one. */
|
|
61
|
+
private runStateLabel;
|
|
60
62
|
private updateStatus;
|
|
61
63
|
private shutdown;
|
|
62
64
|
}
|