@oyasmi/pipiclaw 0.8.10-beta.2 → 0.8.10-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/dist/agent/channel-runner.d.ts +12 -0
- package/dist/agent/channel-runner.js +46 -13
- package/dist/agent/commands.js +30 -28
- package/dist/agent/effect-ledger.d.ts +13 -4
- package/dist/agent/effect-ledger.js +18 -5
- package/dist/agent/job-manager.d.ts +9 -0
- package/dist/agent/job-manager.js +45 -10
- package/dist/agent/maintenance-context.js +3 -2
- package/dist/agent/progress-formatter.d.ts +10 -1
- package/dist/agent/progress-formatter.js +14 -2
- package/dist/executor.d.ts +2 -0
- package/dist/executor.js +1 -0
- package/dist/memory/maintenance-gates.d.ts +24 -10
- package/dist/memory/maintenance-gates.js +11 -9
- package/dist/memory/maintenance-jobs.d.ts +3 -2
- package/dist/memory/maintenance-jobs.js +33 -21
- package/dist/memory/scheduler.d.ts +7 -2
- package/dist/playbooks/task-closeout.md +2 -0
- package/dist/playbooks/task-delegation.md +12 -8
- package/dist/playbooks/task-driving.md +2 -2
- package/dist/playbooks/task-planning.md +1 -1
- package/dist/runtime/bootstrap.js +7 -4
- package/dist/runtime/delivery.js +31 -6
- package/dist/runtime/dingtalk.d.ts +9 -1
- package/dist/runtime/dingtalk.js +7 -4
- package/dist/runtime/task-commands.js +130 -53
- package/dist/runtime/task-driver.js +38 -9
- package/dist/shared/task-ledger.js +19 -3
- package/dist/subagents/tool.d.ts +1 -0
- package/dist/subagents/tool.js +33 -3
- package/dist/tasks/control.d.ts +1 -0
- package/dist/tasks/control.js +2 -2
- package/dist/tasks/verification.d.ts +8 -0
- package/dist/tasks/verification.js +4 -1
- package/dist/tools/bash.js +12 -12
- package/dist/tools/task-manage/lifecycle.js +6 -3
- package/dist/tools/task-manage/verification.d.ts +2 -1
- package/dist/tools/task-manage/verification.js +2 -1
- package/dist/tui/turn-controller.js +3 -3
- package/dist/usage/ledger.d.ts +2 -0
- package/dist/usage/ledger.js +7 -2
- package/dist/usage/render.js +17 -8
- package/package.json +1 -1
|
@@ -31,6 +31,7 @@ export async function writeVerificationAttestation(channelDir, input) {
|
|
|
31
31
|
evidence: input.evidence,
|
|
32
32
|
workspaceChanged: input.workspaceChanged,
|
|
33
33
|
subjectHash: input.subjectHash,
|
|
34
|
+
subjectDir: input.subjectHash ? input.subjectDir : undefined,
|
|
34
35
|
};
|
|
35
36
|
await mkdir(verificationDir(channelDir), { recursive: true });
|
|
36
37
|
await writeFileAtomically(verificationAttestationPath(channelDir, input.runId), `${JSON.stringify(attestation, null, 2)}\n`);
|
|
@@ -56,7 +57,9 @@ export async function readVerificationAttestation(channelDir, runId) {
|
|
|
56
57
|
typeof value.evidence !== "string" ||
|
|
57
58
|
typeof value.workspaceChanged !== "boolean" ||
|
|
58
59
|
(value.subjectHash !== undefined &&
|
|
59
|
-
!/^[a-f0-9]{64}$/i.test(String(value.subjectHash)))
|
|
60
|
+
!/^[a-f0-9]{64}$/i.test(String(value.subjectHash))) ||
|
|
61
|
+
(value.subjectDir !== undefined &&
|
|
62
|
+
typeof value.subjectDir !== "string")) {
|
|
60
63
|
throw new Error(`Verification run "${runId}" has an invalid attestation. Run the verifier again.`);
|
|
61
64
|
}
|
|
62
65
|
return value;
|
package/dist/tools/bash.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { randomBytes } from "node:crypto";
|
|
2
|
+
import { writeFile } from "node:fs/promises";
|
|
2
3
|
import { Type } from "typebox";
|
|
3
4
|
import { guardCommand } from "../security/command-guard.js";
|
|
4
5
|
import { DEFAULT_SECURITY_CONFIG } from "../security/config.js";
|
|
5
6
|
import { logSecurityEvent } from "../security/logger.js";
|
|
6
|
-
import { shellEscape } from "../shared/shell-escape.js";
|
|
7
7
|
import { maybeOptimizeCommand } from "./command-optimizer.js";
|
|
8
8
|
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateTail } from "./truncate.js";
|
|
9
9
|
/**
|
|
@@ -165,20 +165,17 @@ export function createBashTool(executor, options = {}) {
|
|
|
165
165
|
output += result.stderr;
|
|
166
166
|
}
|
|
167
167
|
const totalBytes = Buffer.byteLength(output, "utf-8");
|
|
168
|
-
// Spill the full output to a temp file
|
|
169
|
-
//
|
|
170
|
-
//
|
|
168
|
+
// Spill the full output to a temp file when it exceeds the inline limit, so the model
|
|
169
|
+
// can page through the rest with `read`. Written straight to disk rather than piped
|
|
170
|
+
// through a second `sh -c 'cat > file'`: that spawned a process and copied the whole
|
|
171
|
+
// (up to 10MB) buffer over a pipe to reach the same local filesystem the executor
|
|
172
|
+
// already runs on. Best-effort: on failure we simply omit the path hint.
|
|
171
173
|
let tempFilePath;
|
|
172
174
|
if (totalBytes > DEFAULT_MAX_BYTES) {
|
|
173
175
|
const candidatePath = getSpillFilePath();
|
|
174
176
|
try {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
stdin: output,
|
|
178
|
-
});
|
|
179
|
-
if (spillResult.code === 0) {
|
|
180
|
-
tempFilePath = candidatePath;
|
|
181
|
-
}
|
|
177
|
+
await writeFile(candidatePath, output, { mode: 0o600 });
|
|
178
|
+
tempFilePath = candidatePath;
|
|
182
179
|
}
|
|
183
180
|
catch {
|
|
184
181
|
// Ignore spill failures; the truncated output is still returned.
|
|
@@ -215,8 +212,11 @@ export function createBashTool(executor, options = {}) {
|
|
|
215
212
|
// Report the code inline so the model can react without treating it as an error.
|
|
216
213
|
if (result.code !== 0) {
|
|
217
214
|
outputText += `\n\nExit code: ${result.code}`;
|
|
218
|
-
details = { ...details, exitCode: result.code };
|
|
219
215
|
}
|
|
216
|
+
// Recorded unconditionally (not only on failure) because the task governor judges a
|
|
217
|
+
// wake's productivity from it: a command that ran clean and returned something is the
|
|
218
|
+
// evidence that a turn spent driving an external tool was not idle.
|
|
219
|
+
details = { ...details, exitCode: result.code, producedOutput: output.trim().length > 0 };
|
|
220
220
|
return { content: [{ type: "text", text: outputText }], details };
|
|
221
221
|
},
|
|
222
222
|
};
|
|
@@ -89,18 +89,21 @@ export async function doneTask(options, request) {
|
|
|
89
89
|
if (verification.bodyHash !== taskBodyHash(body)) {
|
|
90
90
|
throw new RecoverableToolError(`Task "${id}" changed after its independent PASS; rerun verification before done.`);
|
|
91
91
|
}
|
|
92
|
+
// Read the attestation first: it names the checkout the verifier actually inspected, which
|
|
93
|
+
// is what the subject must be recomputed in (a sub-agent may have been pointed elsewhere).
|
|
94
|
+
const attestation = await assertVerificationAttestationMatches(options.channelDir, id, verification);
|
|
92
95
|
if (verification.subjectHash) {
|
|
93
96
|
// Fail closed (spec 036, D7): an attestation bound to a Git subject that cannot be
|
|
94
97
|
// recomputed is unverifiable, not implicitly fine.
|
|
95
|
-
const
|
|
98
|
+
const subjectDir = attestation.subjectDir ?? options.workingDirectory ?? process.cwd();
|
|
99
|
+
const currentSubject = await workspaceSubjectHash(subjectDir);
|
|
96
100
|
if (!currentSubject) {
|
|
97
|
-
throw new RecoverableToolError(`Task "${id}" has an independent PASS bound to
|
|
101
|
+
throw new RecoverableToolError(`Task "${id}" has an independent PASS bound to the Git artifact subject of ${subjectDir}, but that checkout cannot be read. Restore it, or rerun verification.`);
|
|
98
102
|
}
|
|
99
103
|
if (currentSubject !== verification.subjectHash) {
|
|
100
104
|
throw new RecoverableToolError(`Task "${id}" artifacts changed after its independent PASS; rerun verification before done.`);
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
|
-
await assertVerificationAttestationMatches(options.channelDir, id, verification);
|
|
104
107
|
}
|
|
105
108
|
// Spec 036 D5: `done` always records Summary/Evidence in the body. It no longer also stamps
|
|
106
109
|
// `verification.status = "passed"` for unverified tasks — that was the maker grading itself,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type TaskVerification } from "../../tasks/control.js";
|
|
2
|
+
import { type VerificationAttestation } from "../../tasks/verification.js";
|
|
2
3
|
import type { TaskManageRequest, TaskManageResult, TaskManageToolOptions } from "./types.js";
|
|
3
4
|
/**
|
|
4
5
|
* Move a task into the verification lane. The runtime driver will explicitly
|
|
@@ -13,4 +14,4 @@ export declare function verifyTask(options: TaskManageToolOptions, request: Task
|
|
|
13
14
|
* a "passed" verification block that was never backed by a real verifier run. Re-check the
|
|
14
15
|
* attestation file on the consuming side (done/doctor) too, not just at import time.
|
|
15
16
|
*/
|
|
16
|
-
export declare function assertVerificationAttestationMatches(channelDir: string, id: string, verification: TaskVerification): Promise<
|
|
17
|
+
export declare function assertVerificationAttestationMatches(channelDir: string, id: string, verification: TaskVerification): Promise<VerificationAttestation>;
|
|
@@ -58,7 +58,7 @@ export async function verifyTask(options, request) {
|
|
|
58
58
|
throw new RecoverableToolError(`Task "${id}" changed after verification run "${runId}"; rerun the verifier on current content.`);
|
|
59
59
|
}
|
|
60
60
|
if (attestation.subjectHash) {
|
|
61
|
-
const currentSubject = await workspaceSubjectHash(options.workingDirectory ?? process.cwd());
|
|
61
|
+
const currentSubject = await workspaceSubjectHash(attestation.subjectDir ?? options.workingDirectory ?? process.cwd());
|
|
62
62
|
if (!currentSubject) {
|
|
63
63
|
throw new RecoverableToolError(`Verification run "${runId}" is bound to a Git artifact subject, but the current checkout cannot be read. Rerun verification from the project checkout.`);
|
|
64
64
|
}
|
|
@@ -108,4 +108,5 @@ export async function assertVerificationAttestationMatches(channelDir, id, verif
|
|
|
108
108
|
if (attestation.bodyHash !== verification.bodyHash) {
|
|
109
109
|
throw new RecoverableToolError(`Task "${id}" control.verification.bodyHash does not match the attestation for run "${verification.runId}"; rerun task_manage verify.`);
|
|
110
110
|
}
|
|
111
|
+
return attestation;
|
|
111
112
|
}
|
|
@@ -101,10 +101,10 @@ export class TurnController {
|
|
|
101
101
|
case "stop":
|
|
102
102
|
if (this.deps.runner.isBusy()) {
|
|
103
103
|
void this.deps.runner.abort();
|
|
104
|
-
this.deps.frontend.showNotice("
|
|
104
|
+
this.deps.frontend.showNotice("正在停止…");
|
|
105
105
|
}
|
|
106
106
|
else {
|
|
107
|
-
this.deps.frontend.showNotice("
|
|
107
|
+
this.deps.frontend.showNotice("当前没有运行中的回合。");
|
|
108
108
|
}
|
|
109
109
|
return;
|
|
110
110
|
case "followup":
|
|
@@ -212,7 +212,7 @@ export class TurnController {
|
|
|
212
212
|
handleInterrupt() {
|
|
213
213
|
if (this.deps.runner.isBusy()) {
|
|
214
214
|
void this.deps.runner.abort();
|
|
215
|
-
this.deps.frontend.showNotice("
|
|
215
|
+
this.deps.frontend.showNotice("正在停止…");
|
|
216
216
|
return;
|
|
217
217
|
}
|
|
218
218
|
// Idle: first Ctrl-C arms the exit prompt, the next one exits (no time
|
package/dist/usage/ledger.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export interface UsageLedgerEntry {
|
|
|
26
26
|
}
|
|
27
27
|
export interface UsageSummary {
|
|
28
28
|
totalCost: number;
|
|
29
|
+
/** Tokens behind `totalCost`; the only signal there is when a model reports no pricing. */
|
|
30
|
+
totalTokens: number;
|
|
29
31
|
entryCount: number;
|
|
30
32
|
byKind: Record<string, number>;
|
|
31
33
|
byModel: Record<string, number>;
|
package/dist/usage/ledger.js
CHANGED
|
@@ -23,8 +23,11 @@ export function createUsageLedger(options = {}) {
|
|
|
23
23
|
const appender = createJsonlAppender({ pathFor: fileFor });
|
|
24
24
|
return {
|
|
25
25
|
record(entry) {
|
|
26
|
-
//
|
|
27
|
-
|
|
26
|
+
// Record anything that consumed tokens, even at zero cost: a local model, or one whose
|
|
27
|
+
// pricing metadata is missing, still has to show up somewhere or `/usage` reports nothing
|
|
28
|
+
// at all and any spend guard built on this ledger fails open. Only a genuinely empty
|
|
29
|
+
// entry (no tokens, no cost) is dropped as noise.
|
|
30
|
+
if (!(entry.cost.total > 0) && !(entry.usage.total > 0))
|
|
28
31
|
return;
|
|
29
32
|
if (!entry.channelId) {
|
|
30
33
|
log.logWarning("Usage ledger entry missing channelId; recording as untracked", `kind=${entry.kind}`);
|
|
@@ -44,6 +47,7 @@ export function createUsageLedger(options = {}) {
|
|
|
44
47
|
const untilMs = until.getTime();
|
|
45
48
|
const summary = {
|
|
46
49
|
totalCost: 0,
|
|
50
|
+
totalTokens: 0,
|
|
47
51
|
entryCount: 0,
|
|
48
52
|
byKind: {},
|
|
49
53
|
byModel: {},
|
|
@@ -77,6 +81,7 @@ export function createUsageLedger(options = {}) {
|
|
|
77
81
|
continue;
|
|
78
82
|
const cost = entry.cost?.total ?? 0;
|
|
79
83
|
summary.totalCost += cost;
|
|
84
|
+
summary.totalTokens += entry.usage?.total ?? 0;
|
|
80
85
|
summary.entryCount += 1;
|
|
81
86
|
summary.byKind[entry.kind] = (summary.byKind[entry.kind] ?? 0) + cost;
|
|
82
87
|
summary.byModel[entry.model] = (summary.byModel[entry.model] ?? 0) + cost;
|
package/dist/usage/render.js
CHANGED
|
@@ -13,15 +13,15 @@ function startOfUtcMonth(now) {
|
|
|
13
13
|
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
|
|
14
14
|
}
|
|
15
15
|
export function usageWindows(mode, now) {
|
|
16
|
-
const monthTitle =
|
|
16
|
+
const monthTitle = `本月(${now.getUTCFullYear()}-${String(now.getUTCMonth() + 1).padStart(2, "0")})`;
|
|
17
17
|
switch (mode) {
|
|
18
18
|
case "7d":
|
|
19
|
-
return [{ title: "
|
|
19
|
+
return [{ title: "最近 7 天", since: new Date(now.getTime() - 7 * 86_400_000), until: now }];
|
|
20
20
|
case "month":
|
|
21
21
|
return [{ title: monthTitle, since: startOfUtcMonth(now), until: now }];
|
|
22
22
|
default:
|
|
23
23
|
return [
|
|
24
|
-
{ title: "
|
|
24
|
+
{ title: "今天(UTC)", since: startOfUtcDay(now), until: now },
|
|
25
25
|
{ title: monthTitle, since: startOfUtcMonth(now), until: now },
|
|
26
26
|
];
|
|
27
27
|
}
|
|
@@ -29,6 +29,13 @@ export function usageWindows(mode, now) {
|
|
|
29
29
|
function money(n) {
|
|
30
30
|
return `$${n.toFixed(4)}`;
|
|
31
31
|
}
|
|
32
|
+
function tokens(n) {
|
|
33
|
+
return n >= 1_000_000
|
|
34
|
+
? `${(n / 1_000_000).toFixed(1)}M tokens`
|
|
35
|
+
: n >= 1_000
|
|
36
|
+
? `${Math.round(n / 1_000)}k tokens`
|
|
37
|
+
: `${n} tokens`;
|
|
38
|
+
}
|
|
32
39
|
function topEntries(map, limit) {
|
|
33
40
|
return Object.entries(map)
|
|
34
41
|
.filter(([, cost]) => cost > 0)
|
|
@@ -44,24 +51,26 @@ function renderWindow(window, ledger, channelId) {
|
|
|
44
51
|
const channel = ledger.summarize({ since: window.since, until: window.until, channelId });
|
|
45
52
|
const lines = [`## ${window.title}`];
|
|
46
53
|
if (global.entryCount === 0) {
|
|
47
|
-
lines.push("
|
|
54
|
+
lines.push("暂无用量记录。");
|
|
48
55
|
return lines.join("\n");
|
|
49
56
|
}
|
|
50
|
-
|
|
57
|
+
// Tokens are reported next to cost because a local or pricing-less model bills nothing while
|
|
58
|
+
// still consuming context — "$0.0000" alone would read as "nothing happened".
|
|
59
|
+
lines.push(`本频道:${money(channel.totalCost)} · ${tokens(channel.totalTokens)}`);
|
|
51
60
|
const channelKinds = renderKindBreakdown(channel);
|
|
52
61
|
if (channelKinds) {
|
|
53
62
|
lines.push(` ${channelKinds}`);
|
|
54
63
|
}
|
|
55
64
|
const channelCount = Object.keys(global.byChannel).length;
|
|
56
|
-
lines.push(
|
|
65
|
+
lines.push(`全局:${money(global.totalCost)} · ${tokens(global.totalTokens)},覆盖 ${channelCount} 个频道`);
|
|
57
66
|
const topModels = topEntries(global.byModel, 3);
|
|
58
67
|
if (topModels.length > 0) {
|
|
59
|
-
lines.push(`
|
|
68
|
+
lines.push(` 用量最高的模型:${topModels.map(([model, cost]) => `${model} ${money(cost)}`).join(",")}`);
|
|
60
69
|
}
|
|
61
70
|
return lines.join("\n");
|
|
62
71
|
}
|
|
63
72
|
export function renderUsageReport(ledger, channelId, mode, now) {
|
|
64
73
|
const windows = usageWindows(mode, now);
|
|
65
74
|
const body = windows.map((window) => renderWindow(window, ledger, channelId)).join("\n\n");
|
|
66
|
-
return `#
|
|
75
|
+
return `# 用量\n\n${body}`;
|
|
67
76
|
}
|
package/package.json
CHANGED