@oyasmi/pipiclaw 0.8.11 → 0.9.0-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.d.ts +3 -0
- package/dist/agent/channel-runner.js +9 -0
- package/dist/agent/commands.d.ts +1 -1
- package/dist/agent/commands.js +9 -0
- package/dist/agent/job-manager.d.ts +5 -3
- package/dist/agent/job-manager.js +8 -5
- package/dist/agent/prompt/sections.js +46 -7
- package/dist/agent/prompt/types.d.ts +9 -0
- package/dist/agent/session-events.js +7 -42
- package/dist/agent/types.d.ts +4 -0
- package/dist/playbooks/agent-delegation.md +46 -21
- package/dist/playbooks/runtime-orientation.md +2 -2
- package/dist/runtime/bootstrap.js +45 -1
- package/dist/runtime/dingtalk.d.ts +1 -0
- package/dist/runtime/dingtalk.js +3 -0
- package/dist/runtime/store.d.ts +7 -0
- package/dist/runtime/subagent-commands.d.ts +15 -0
- package/dist/runtime/subagent-commands.js +122 -0
- package/dist/runtime/task-commands.js +5 -1
- package/dist/security/logger.js +3 -1
- package/dist/security/types.d.ts +17 -1
- package/dist/shared/host-process.d.ts +15 -0
- package/dist/shared/host-process.js +40 -0
- package/dist/shared/shell-words.d.ts +9 -0
- package/dist/shared/shell-words.js +52 -0
- package/dist/subagents/discovery.d.ts +42 -1
- package/dist/subagents/discovery.js +302 -69
- package/dist/subagents/external/claude-code.d.ts +2 -0
- package/dist/subagents/external/claude-code.js +152 -0
- package/dist/subagents/external/codex-cli.d.ts +2 -0
- package/dist/subagents/external/codex-cli.js +133 -0
- package/dist/subagents/external/exec.d.ts +2 -0
- package/dist/subagents/external/exec.js +38 -0
- package/dist/subagents/external/harness.d.ts +102 -0
- package/dist/subagents/external/harness.js +76 -0
- package/dist/subagents/external/registry.d.ts +2 -0
- package/dist/subagents/external/registry.js +11 -0
- package/dist/subagents/external/run.d.ts +39 -0
- package/dist/subagents/external/run.js +220 -0
- package/dist/subagents/runs.d.ts +216 -0
- package/dist/subagents/runs.js +522 -0
- package/dist/subagents/tool.d.ts +8 -0
- package/dist/subagents/tool.js +350 -124
- package/dist/subagents/workspace-lease.d.ts +36 -0
- package/dist/subagents/workspace-lease.js +48 -0
- package/dist/tasks/artifact-subject.js +50 -2
- package/dist/tasks/verification.d.ts +8 -0
- package/dist/tasks/verification.js +10 -2
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.js +10 -1
- package/dist/tools/registry.js +1 -0
- package/dist/tools/subagent-manage.d.ts +18 -0
- package/dist/tools/subagent-manage.js +141 -0
- package/dist/tools/tool-details.d.ts +1 -1
- package/dist/tui/app.js +2 -0
- package/dist/tui/commands.d.ts +1 -0
- package/dist/tui/commands.js +2 -0
- package/dist/tui/turn-controller.d.ts +1 -0
- package/dist/tui/turn-controller.js +1 -0
- package/dist/usage/ledger.d.ts +6 -0
- package/examples/sub-agents/README.md +59 -12
- package/examples/sub-agents/builder-hard.md +45 -0
- package/examples/sub-agents/builder.md +41 -0
- package/examples/sub-agents/documenter.md +53 -0
- package/examples/sub-agents/log-sifter.md +43 -0
- package/examples/sub-agents/planner.md +42 -0
- package/examples/sub-agents/reviewer.md +33 -39
- package/examples/sub-agents/scout.md +31 -0
- package/examples/sub-agents/verifier.md +29 -36
- package/examples/sub-agents/worker.md +36 -0
- package/package.json +1 -1
- package/examples/sub-agents/researcher.md +0 -41
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
const leases = new Map();
|
|
3
|
+
function withTrailingSlash(path) {
|
|
4
|
+
return path.endsWith("/") ? path : `${path}/`;
|
|
5
|
+
}
|
|
6
|
+
function pathsConflict(a, b) {
|
|
7
|
+
return (a === b ||
|
|
8
|
+
withTrailingSlash(a).startsWith(withTrailingSlash(b)) ||
|
|
9
|
+
withTrailingSlash(b).startsWith(withTrailingSlash(a)));
|
|
10
|
+
}
|
|
11
|
+
/** The stable lease key for a working directory: its realpath, so a symlink or `..` cannot dodge a conflict. */
|
|
12
|
+
export function workspaceLeaseKey(workingDirectory) {
|
|
13
|
+
try {
|
|
14
|
+
return realpathSync(workingDirectory);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return workingDirectory;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function findConflict(leaseKey) {
|
|
21
|
+
for (const [key, holder] of leases) {
|
|
22
|
+
if (pathsConflict(key, leaseKey))
|
|
23
|
+
return holder;
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
export function acquireWorkspaceLease(holder) {
|
|
28
|
+
const leaseKey = workspaceLeaseKey(holder.workingDirectory);
|
|
29
|
+
const conflict = findConflict(leaseKey);
|
|
30
|
+
if (conflict) {
|
|
31
|
+
return { ok: false, leaseKey, heldBy: conflict };
|
|
32
|
+
}
|
|
33
|
+
leases.set(leaseKey, holder);
|
|
34
|
+
return { ok: true, leaseKey };
|
|
35
|
+
}
|
|
36
|
+
export function releaseWorkspaceLease(leaseKey) {
|
|
37
|
+
if (leaseKey)
|
|
38
|
+
leases.delete(leaseKey);
|
|
39
|
+
}
|
|
40
|
+
/** Read-only check for a pre-flight gate (e.g. `purpose=verify`, D9) that must not itself take a lease. */
|
|
41
|
+
export function findWorkspaceLeaseHolder(workingDirectory) {
|
|
42
|
+
return findConflict(workspaceLeaseKey(workingDirectory));
|
|
43
|
+
}
|
|
44
|
+
export function formatWorkspaceLeaseConflict(heldBy) {
|
|
45
|
+
return (`Workspace "${heldBy.workingDirectory}" is already held by a running write delegation ` +
|
|
46
|
+
`(runId ${heldBy.runId}, channel ${heldBy.channelId}). Wait for it to finish, cancel it with ` +
|
|
47
|
+
"subagent_manage, or use a separate `git worktree add` checkout via workingDirectory.");
|
|
48
|
+
}
|
|
@@ -1,7 +1,54 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { join } from "node:path";
|
|
3
5
|
import { promisify } from "node:util";
|
|
4
6
|
const execFileAsync = promisify(execFile);
|
|
7
|
+
/**
|
|
8
|
+
* git quotes a path containing special characters in double quotes with C-style escapes (spec
|
|
9
|
+
* 040, D9). `JSON.parse` accepts the same escape set for the characters git actually emits
|
|
10
|
+
* (`\"`, `\\`, `\t`, `\n`) and is close enough for a hash input; a path so exotic it defeats this
|
|
11
|
+
* still contributes *a* value to the hash; it just won't be the literal decoded path.
|
|
12
|
+
*/
|
|
13
|
+
function unquoteGitPath(raw) {
|
|
14
|
+
if (raw.startsWith('"') && raw.endsWith('"')) {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(raw);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return raw;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return raw;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Fold untracked-file *content* into the subject, not just their path/status (D9). `git status
|
|
26
|
+
* --porcelain` reports an untracked file as present, but two different untracked files with the
|
|
27
|
+
* same name are indistinguishable to it — a verifier that edits an untracked file's content
|
|
28
|
+
* (or reverts it after inspection) previously left no trace in `workspaceSubjectHash` at all.
|
|
29
|
+
* Best-effort per file: an unreadable entry (deleted mid-scan, a directory, a permission error)
|
|
30
|
+
* still contributes its path to the hash, just not content — this function must never throw, since
|
|
31
|
+
* its caller already treats the whole subject computation as best-effort.
|
|
32
|
+
*/
|
|
33
|
+
async function untrackedFileDigest(workingDirectory, statusOutput) {
|
|
34
|
+
const paths = statusOutput
|
|
35
|
+
.split("\n")
|
|
36
|
+
.filter((line) => line.startsWith("?? "))
|
|
37
|
+
.map((line) => unquoteGitPath(line.slice(3).trim()))
|
|
38
|
+
.filter(Boolean)
|
|
39
|
+
.sort();
|
|
40
|
+
const hash = createHash("sha256");
|
|
41
|
+
for (const relativePath of paths) {
|
|
42
|
+
hash.update(relativePath);
|
|
43
|
+
try {
|
|
44
|
+
hash.update(await readFile(join(workingDirectory, relativePath)));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Unreadable — the path alone still went into the hash above.
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return hash.digest("hex");
|
|
51
|
+
}
|
|
5
52
|
/**
|
|
6
53
|
* A compact, deterministic description of the code/artifact subject a verifier
|
|
7
54
|
* observed. It intentionally uses only Git's own view, keeping verification
|
|
@@ -10,7 +57,7 @@ const execFileAsync = promisify(execFile);
|
|
|
10
57
|
export async function workspaceSubjectHash(workingDirectory) {
|
|
11
58
|
try {
|
|
12
59
|
const { stdout } = await execFileAsync("git", ["-C", workingDirectory, "status", "--porcelain=v1", "--untracked-files=all"], { maxBuffer: 4 * 1024 * 1024 });
|
|
13
|
-
const [head, unstaged, staged] = await Promise.all([
|
|
60
|
+
const [head, unstaged, staged, untrackedDigest] = await Promise.all([
|
|
14
61
|
execFileAsync("git", ["-C", workingDirectory, "rev-parse", "HEAD"], { maxBuffer: 1024 * 1024 }),
|
|
15
62
|
execFileAsync("git", ["-C", workingDirectory, "diff", "--no-ext-diff", "--binary"], {
|
|
16
63
|
maxBuffer: 4 * 1024 * 1024,
|
|
@@ -18,9 +65,10 @@ export async function workspaceSubjectHash(workingDirectory) {
|
|
|
18
65
|
execFileAsync("git", ["-C", workingDirectory, "diff", "--cached", "--no-ext-diff", "--binary"], {
|
|
19
66
|
maxBuffer: 4 * 1024 * 1024,
|
|
20
67
|
}),
|
|
68
|
+
untrackedFileDigest(workingDirectory, stdout),
|
|
21
69
|
]);
|
|
22
70
|
return createHash("sha256")
|
|
23
|
-
.update([head.stdout.trim(), stdout, unstaged.stdout, staged.stdout].join("\0"))
|
|
71
|
+
.update([head.stdout.trim(), stdout, unstaged.stdout, staged.stdout, untrackedDigest].join("\0"))
|
|
24
72
|
.digest("hex");
|
|
25
73
|
}
|
|
26
74
|
catch {
|
|
@@ -27,6 +27,14 @@ export interface VerificationAttestation {
|
|
|
27
27
|
* a PASS against an unrelated repository. Absent on attestations written before this field.
|
|
28
28
|
*/
|
|
29
29
|
subjectDir?: string;
|
|
30
|
+
/**
|
|
31
|
+
* `enforced` — a built-in verifier, whose write/edit tools are structurally removed before it
|
|
32
|
+
* runs (a real gate). `advisory` — an external verifier (spec 040, D9): the tools cannot be
|
|
33
|
+
* removed, so the verdict rests on the target CLI's own sandbox flag plus the workspace hash,
|
|
34
|
+
* neither of which pipiclaw can prove. Defaults to `enforced` for attestations written before
|
|
35
|
+
* this field existed — every verifier was built-in then.
|
|
36
|
+
*/
|
|
37
|
+
verificationStrength: "enforced" | "advisory";
|
|
30
38
|
}
|
|
31
39
|
export declare function verificationDir(channelDir: string): string;
|
|
32
40
|
export declare function verificationAttestationPath(channelDir: string, runId: string): string;
|
|
@@ -33,6 +33,7 @@ export async function writeVerificationAttestation(channelDir, input) {
|
|
|
33
33
|
workspaceChanged: input.workspaceChanged,
|
|
34
34
|
subjectHash: input.subjectHash,
|
|
35
35
|
subjectDir: input.subjectHash ? input.subjectDir : undefined,
|
|
36
|
+
verificationStrength: input.verificationStrength,
|
|
36
37
|
};
|
|
37
38
|
await mkdir(verificationDir(channelDir), { recursive: true });
|
|
38
39
|
await writeFileAtomically(verificationAttestationPath(channelDir, input.runId), `${JSON.stringify(attestation, null, 2)}\n`);
|
|
@@ -60,8 +61,15 @@ export async function readVerificationAttestation(channelDir, runId) {
|
|
|
60
61
|
(value.subjectHash !== undefined &&
|
|
61
62
|
!/^[a-f0-9]{64}$/i.test(String(value.subjectHash))) ||
|
|
62
63
|
(value.subjectDir !== undefined &&
|
|
63
|
-
typeof value.subjectDir !== "string")
|
|
64
|
+
typeof value.subjectDir !== "string") ||
|
|
65
|
+
(value.verificationStrength !== undefined &&
|
|
66
|
+
value.verificationStrength !== "enforced" &&
|
|
67
|
+
value.verificationStrength !== "advisory")) {
|
|
64
68
|
throw new Error(`Verification run "${runId}" has an invalid attestation. Run the verifier again.`);
|
|
65
69
|
}
|
|
66
|
-
|
|
70
|
+
// Pre-spec-040 attestations predate this field; every verifier back then was built-in.
|
|
71
|
+
return {
|
|
72
|
+
...value,
|
|
73
|
+
verificationStrength: value.verificationStrength ?? "enforced",
|
|
74
|
+
};
|
|
67
75
|
}
|
package/dist/tools/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { MemoryCandidateStore } from "../memory/candidates.js";
|
|
|
5
5
|
import type { MediaSender } from "../runtime/channel-context.js";
|
|
6
6
|
import type { SecurityConfig } from "../security/types.js";
|
|
7
7
|
import type { PipiclawMemoryRecallSettings, PipiclawSessionSearchSettings } from "../settings.js";
|
|
8
|
-
import type
|
|
8
|
+
import { type SubAgentDiscoveryResult } from "../subagents/discovery.js";
|
|
9
9
|
import type { PipiclawToolsConfig } from "./config.js";
|
|
10
10
|
export interface CreatePipiclawToolsOptions {
|
|
11
11
|
executor: Executor;
|
package/dist/tools/index.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { getChannelJobManager } from "../agent/job-manager.js";
|
|
2
2
|
import { APP_HOME_DIR } from "../paths.js";
|
|
3
3
|
import { loadSecurityConfig } from "../security/config.js";
|
|
4
|
+
import { withSubAgentsDirWriteDeny } from "../subagents/discovery.js";
|
|
4
5
|
import { createSubAgentTool } from "../subagents/tool.js";
|
|
5
6
|
import { loadToolsConfig } from "./config.js";
|
|
6
7
|
import { buildToolSet } from "./registry.js";
|
|
8
|
+
import { createSubAgentManageTool } from "./subagent-manage.js";
|
|
7
9
|
import { withToolDetails } from "./tool-details.js";
|
|
8
10
|
export function createPipiclawTools(options) {
|
|
9
|
-
|
|
11
|
+
// Spec 040, D8.1: the main agent's own write/edit tools can write a self-authorizing
|
|
12
|
+
// `runtime: external` role file just as readily as a sub-agent's can; deny it here too.
|
|
13
|
+
const securityConfig = withSubAgentsDirWriteDeny(options.securityConfig ?? loadSecurityConfig(APP_HOME_DIR), options.workspaceDir);
|
|
10
14
|
const toolsConfig = options.toolsConfig ?? loadToolsConfig(APP_HOME_DIR);
|
|
11
15
|
const securityContext = {
|
|
12
16
|
workspaceDir: options.workspaceDir,
|
|
@@ -58,5 +62,10 @@ export function createPipiclawTools(options) {
|
|
|
58
62
|
channelId: options.channelId,
|
|
59
63
|
},
|
|
60
64
|
}), "subagent"),
|
|
65
|
+
withToolDetails(createSubAgentManageTool({
|
|
66
|
+
channelId: options.channelId,
|
|
67
|
+
channelDir: options.channelDir,
|
|
68
|
+
getSubAgentDiscovery: options.getSubAgentDiscovery,
|
|
69
|
+
}), "subagent_manage"),
|
|
61
70
|
];
|
|
62
71
|
}
|
package/dist/tools/registry.js
CHANGED
|
@@ -179,6 +179,7 @@ export const TOOL_REGISTRY = [
|
|
|
179
179
|
export const TOOL_NAMES = new Set([
|
|
180
180
|
...TOOL_REGISTRY.map((registration) => registration.name),
|
|
181
181
|
"subagent",
|
|
182
|
+
"subagent_manage",
|
|
182
183
|
]);
|
|
183
184
|
/**
|
|
184
185
|
* Build a tool set from the registry, honoring sub-agent availability and config gates.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { AgentTool } from "@earendil-works/pi-agent-core";
|
|
2
|
+
import { Type } from "typebox";
|
|
3
|
+
import type { SubAgentDiscoveryResult } from "../subagents/discovery.js";
|
|
4
|
+
declare const subagentManageSchema: Type.TObject<{
|
|
5
|
+
label: Type.TString;
|
|
6
|
+
op: Type.TUnion<[Type.TLiteral<"list">, Type.TLiteral<"cancel">, Type.TLiteral<"follow_up">]>;
|
|
7
|
+
runId: Type.TOptional<Type.TString>;
|
|
8
|
+
task: Type.TOptional<Type.TString>;
|
|
9
|
+
}>;
|
|
10
|
+
export interface SubAgentManageToolOptions {
|
|
11
|
+
channelId: string;
|
|
12
|
+
/** Needed only for `follow_up` on a `purpose=verify` run: where the attestation is written. */
|
|
13
|
+
channelDir?: string;
|
|
14
|
+
/** Needed only for `follow_up`: re-resolves the role's current config by name. */
|
|
15
|
+
getSubAgentDiscovery?: () => SubAgentDiscoveryResult;
|
|
16
|
+
}
|
|
17
|
+
export declare function createSubAgentManageTool(options: SubAgentManageToolOptions): AgentTool<typeof subagentManageSchema>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { Type } from "typebox";
|
|
2
|
+
import { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
3
|
+
import { launchExternalRun } from "../subagents/external/run.js";
|
|
4
|
+
import { getSubAgentRunManager } from "../subagents/runs.js";
|
|
5
|
+
import { acquireWorkspaceLease, formatWorkspaceLeaseConflict } from "../subagents/workspace-lease.js";
|
|
6
|
+
const subagentManageSchema = Type.Object({
|
|
7
|
+
label: Type.String({ description: "Brief description of what you're checking (shown to user)" }),
|
|
8
|
+
op: Type.Union([Type.Literal("list"), Type.Literal("cancel"), Type.Literal("follow_up")], {
|
|
9
|
+
description: '"list" a snapshot of this channel\'s delegation runs, "cancel" a running one by runId, or ' +
|
|
10
|
+
'"follow_up" to continue a resumable run with a new instruction (produces a new runId).',
|
|
11
|
+
}),
|
|
12
|
+
runId: Type.Optional(Type.String({ description: "Required for cancel and follow_up." })),
|
|
13
|
+
task: Type.Optional(Type.String({ description: "Follow-up instruction. Required for op=follow_up." })),
|
|
14
|
+
});
|
|
15
|
+
function formatDuration(ms) {
|
|
16
|
+
const seconds = Math.round(ms / 1000);
|
|
17
|
+
if (seconds < 60)
|
|
18
|
+
return `${seconds}s`;
|
|
19
|
+
return `${Math.floor(seconds / 60)}m${seconds % 60}s`;
|
|
20
|
+
}
|
|
21
|
+
function formatRunLine(record) {
|
|
22
|
+
const harness = record.harness ? `${record.runtime}/${record.harness}` : record.runtime;
|
|
23
|
+
const elapsed = (record.finishedAt ?? Date.now()) - record.startedAt;
|
|
24
|
+
const task = record.taskId ? `, task ${record.taskId}` : "";
|
|
25
|
+
const lease = record.leaseKey ? ", lease held" : "";
|
|
26
|
+
return `- [${record.runId}] ${record.agent} (${harness}) — ${record.status} (${formatDuration(elapsed)}${task}${lease})`;
|
|
27
|
+
}
|
|
28
|
+
/** Resumable harnesses only: `claude-code`/`codex-cli`. `exec` has no session concept, and internal
|
|
29
|
+
* runs have no persisted transcript by design (spec 040, non-goals). */
|
|
30
|
+
function resumableHarnessOf(record) {
|
|
31
|
+
if (record.runtime !== "external")
|
|
32
|
+
return undefined;
|
|
33
|
+
return record.harness === "codex-cli" || record.harness === "claude-code" ? record.harness : undefined;
|
|
34
|
+
}
|
|
35
|
+
export function createSubAgentManageTool(options) {
|
|
36
|
+
const manager = () => getSubAgentRunManager(options.channelId);
|
|
37
|
+
return {
|
|
38
|
+
name: "subagent_manage",
|
|
39
|
+
label: "subagent_manage",
|
|
40
|
+
description: "Inspect and control delegation runs (internal sub-agents and, once configured, external agents): " +
|
|
41
|
+
"op=list shows a snapshot of this channel's runs; op=cancel stops a running one by runId without " +
|
|
42
|
+
"waking the channel (that is your own decision, not a failure); op=follow_up continues a resumable " +
|
|
43
|
+
"run with a new instruction, producing a new runId. A run finishing wakes this channel by itself, " +
|
|
44
|
+
"so never poll here waiting for one — end the turn instead.",
|
|
45
|
+
parameters: subagentManageSchema,
|
|
46
|
+
execute: async (toolCallId, { op, runId, task }) => {
|
|
47
|
+
if (op === "list") {
|
|
48
|
+
const runs = manager().list();
|
|
49
|
+
const text = runs.length === 0 ? "No delegation runs." : runs.map(formatRunLine).join("\n");
|
|
50
|
+
return { content: [{ type: "text", text }], details: { kind: "subagent_manage", op, runs } };
|
|
51
|
+
}
|
|
52
|
+
if (!runId) {
|
|
53
|
+
throw new RecoverableToolError(`${op} requires runId.`);
|
|
54
|
+
}
|
|
55
|
+
if (op === "cancel") {
|
|
56
|
+
const status = await manager().cancel(runId);
|
|
57
|
+
if (status === "not_found") {
|
|
58
|
+
throw new RecoverableToolError(`Run "${runId}" was not found on this channel.`);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
content: [{ type: "text", text: `Cancel requested for run ${runId}: ${status}` }],
|
|
62
|
+
details: { kind: "subagent_manage", op, runId, status },
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// follow_up
|
|
66
|
+
if (!task || !task.trim()) {
|
|
67
|
+
throw new RecoverableToolError("follow_up requires task.");
|
|
68
|
+
}
|
|
69
|
+
const record = manager().get(runId);
|
|
70
|
+
if (!record) {
|
|
71
|
+
throw new RecoverableToolError(`Run "${runId}" was not found on this channel.`);
|
|
72
|
+
}
|
|
73
|
+
const harness = resumableHarnessOf(record);
|
|
74
|
+
if (!harness) {
|
|
75
|
+
// Internal runs have no persisted transcript to resume — the isolated-context design
|
|
76
|
+
// is the point, not a gap. `exec` has no session concept at all. Directing the model
|
|
77
|
+
// at a fresh delegation, not a fallback to "just use internal", keeps this honest (P2).
|
|
78
|
+
throw new RecoverableToolError(`Run "${runId}" (${record.runtime}${record.harness ? `/${record.harness}` : ""}) does not support ` +
|
|
79
|
+
"follow_up yet. Delegate a new run instead, carrying forward whatever context or prior output it needs.");
|
|
80
|
+
}
|
|
81
|
+
if (record.status === "running") {
|
|
82
|
+
throw new RecoverableToolError(`Run "${runId}" is still running; wait for it to finish before following up.`);
|
|
83
|
+
}
|
|
84
|
+
if (!record.sessionId) {
|
|
85
|
+
throw new RecoverableToolError(`Run "${runId}" never reported a session id (it likely failed before producing one); it cannot be resumed. Delegate a new run instead.`);
|
|
86
|
+
}
|
|
87
|
+
const discovery = options.getSubAgentDiscovery?.();
|
|
88
|
+
const role = discovery?.agents.find((agent) => agent.name === record.agent && agent.runtime === "external");
|
|
89
|
+
if (!role) {
|
|
90
|
+
throw new RecoverableToolError(`Role "${record.agent}" is no longer configured as an external role; cannot follow up run "${runId}".`);
|
|
91
|
+
}
|
|
92
|
+
if (role.unavailable) {
|
|
93
|
+
throw new RecoverableToolError(`Role "${record.agent}" is currently unavailable: ${role.unavailable}`);
|
|
94
|
+
}
|
|
95
|
+
let leaseKey;
|
|
96
|
+
if (role.mutates === "write") {
|
|
97
|
+
const lease = acquireWorkspaceLease({
|
|
98
|
+
runId: toolCallId,
|
|
99
|
+
channelId: options.channelId,
|
|
100
|
+
workingDirectory: record.workingDirectory,
|
|
101
|
+
});
|
|
102
|
+
if (!lease.ok) {
|
|
103
|
+
throw new RecoverableToolError(formatWorkspaceLeaseConflict(lease.heldBy));
|
|
104
|
+
}
|
|
105
|
+
leaseKey = lease.leaseKey;
|
|
106
|
+
}
|
|
107
|
+
await launchExternalRun({
|
|
108
|
+
runId: toolCallId,
|
|
109
|
+
channelId: options.channelId,
|
|
110
|
+
channelDir: options.channelDir,
|
|
111
|
+
label: `follow-up: ${task.slice(0, 80)}`,
|
|
112
|
+
agent: role.name,
|
|
113
|
+
source: role.source,
|
|
114
|
+
harness,
|
|
115
|
+
command: role.command ?? "",
|
|
116
|
+
shell: role.shell,
|
|
117
|
+
env: role.env,
|
|
118
|
+
externalModelRef: role.externalModelRef,
|
|
119
|
+
thinkingLevel: role.thinkingLevel,
|
|
120
|
+
maxWallTimeSec: role.maxWallTimeSec,
|
|
121
|
+
systemPrompt: role.systemPrompt,
|
|
122
|
+
task,
|
|
123
|
+
workingDirectory: record.workingDirectory,
|
|
124
|
+
artifactDir: record.artifactDir.replace(/[^/\\]+$/, toolCallId),
|
|
125
|
+
purpose: record.purpose,
|
|
126
|
+
taskId: record.taskId,
|
|
127
|
+
leaseKey,
|
|
128
|
+
resumeSessionId: record.sessionId,
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
content: [
|
|
132
|
+
{
|
|
133
|
+
type: "text",
|
|
134
|
+
text: `Follow-up dispatched as runId=${toolCallId} (resuming ${record.runId}). This channel will be woken when it finishes.`,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
details: { kind: "subagent_manage", op, runId: toolCallId, resumedFrom: record.runId },
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
|
@@ -18,7 +18,7 @@ export { RecoverableToolError } from "../shared/recoverable-error.js";
|
|
|
18
18
|
* Every tool that can appear in a tool set. Equal to the registry's tool names plus
|
|
19
19
|
* `subagent`, which is registered separately (see the note on TOOL_REGISTRY).
|
|
20
20
|
*/
|
|
21
|
-
export type ToolDetailsKind = "read" | "bash" | "edit" | "grep" | "write" | "web_search" | "web_fetch" | "send_media" | "session_search" | "memory_manage" | "skill_manage" | "event_manage" | "task_manage" | "job" | "subagent";
|
|
21
|
+
export type ToolDetailsKind = "read" | "bash" | "edit" | "grep" | "write" | "web_search" | "web_fetch" | "send_media" | "session_search" | "memory_manage" | "skill_manage" | "event_manage" | "task_manage" | "job" | "subagent" | "subagent_manage";
|
|
22
22
|
/** The fields every tool result's `details` carries. Tool-specific fields extend this. */
|
|
23
23
|
export interface ToolDetails {
|
|
24
24
|
/** Which tool produced this result. Stamped by `withToolDetails`; never written by hand. */
|
package/dist/tui/app.js
CHANGED
|
@@ -17,6 +17,7 @@ import { ensureChannelDir } from "../runtime/channel-paths.js";
|
|
|
17
17
|
import { finalDeliveryOf, progressStyleOf } from "../runtime/dingtalk.js";
|
|
18
18
|
import { handleEventsCommand } from "../runtime/event-commands.js";
|
|
19
19
|
import { ChannelStore } from "../runtime/store.js";
|
|
20
|
+
import { handleSubagentsCommand } from "../runtime/subagent-commands.js";
|
|
20
21
|
import { handleTasksCommand } from "../runtime/task-commands.js";
|
|
21
22
|
import { flushSecurityLogs } from "../security/logger.js";
|
|
22
23
|
import { getUsageLedger } from "../usage/ledger.js";
|
|
@@ -111,6 +112,7 @@ export async function runTuiApp(options) {
|
|
|
111
112
|
workspaceDir: paths.workspaceDir,
|
|
112
113
|
channelId,
|
|
113
114
|
}),
|
|
115
|
+
runSubagents: (args) => handleSubagentsCommand({ args, channelId, discovery: runner.getSubAgentDiscoverySnapshot() }),
|
|
114
116
|
statusInfo: { version: readCliVersion(), startedAt: Date.now() },
|
|
115
117
|
});
|
|
116
118
|
try {
|
package/dist/tui/commands.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ export interface DispatchDeps {
|
|
|
39
39
|
renderUsage(args: string): Promise<string>;
|
|
40
40
|
runEvents(args: string): Promise<string>;
|
|
41
41
|
runTasks(args: string): Promise<string>;
|
|
42
|
+
runSubagents(args: string): Promise<string>;
|
|
42
43
|
}
|
|
43
44
|
export declare function dispatch(input: string, deps: DispatchDeps): Promise<DispatchOutcome>;
|
|
44
45
|
/**
|
package/dist/tui/commands.js
CHANGED
|
@@ -39,6 +39,8 @@ export async function dispatch(input, deps) {
|
|
|
39
39
|
return { kind: "reply", text: await deps.runEvents(command.args) };
|
|
40
40
|
case "tasks":
|
|
41
41
|
return { kind: "reply", text: await deps.runTasks(command.args) };
|
|
42
|
+
case "subagents":
|
|
43
|
+
return { kind: "reply", text: await deps.runSubagents(command.args) };
|
|
42
44
|
case "stop":
|
|
43
45
|
return { kind: "stop" };
|
|
44
46
|
case "steer":
|
|
@@ -22,6 +22,7 @@ export interface TurnControllerDeps {
|
|
|
22
22
|
renderUsage: (args: string) => Promise<string>;
|
|
23
23
|
runEvents: (args: string) => Promise<string>;
|
|
24
24
|
runTasks: (args: string) => Promise<string>;
|
|
25
|
+
runSubagents: (args: string) => Promise<string>;
|
|
25
26
|
/** Static bits the status renderer needs alongside the live run state. */
|
|
26
27
|
statusInfo: {
|
|
27
28
|
version: string;
|
|
@@ -35,6 +35,7 @@ export class TurnController {
|
|
|
35
35
|
renderUsage: deps.renderUsage,
|
|
36
36
|
runEvents: deps.runEvents,
|
|
37
37
|
runTasks: deps.runTasks,
|
|
38
|
+
runSubagents: deps.runSubagents,
|
|
38
39
|
renderContext: (args) => this.deps.runner.renderContextReport(args),
|
|
39
40
|
renderStatus: () => renderStatus({
|
|
40
41
|
runner: this.deps.runner,
|
package/dist/usage/ledger.d.ts
CHANGED
|
@@ -21,8 +21,14 @@ export interface UsageLedgerEntry {
|
|
|
21
21
|
label?: string;
|
|
22
22
|
/** Joins sidecar cost to the memory source window and review-log outcome. */
|
|
23
23
|
correlationId?: string;
|
|
24
|
+
/** Idempotency key for a delegation run's usage entry (spec 040, D7); absent for turn/sidecar kinds. */
|
|
25
|
+
runId?: string;
|
|
24
26
|
usage: UsageTokens;
|
|
25
27
|
cost: UsageCost;
|
|
28
|
+
/** False only when the harness cannot report tokens at all (external `exec`). Display as "unknown", not 0. */
|
|
29
|
+
usageKnown?: boolean;
|
|
30
|
+
/** False when the harness omits a cost field (external `codex-cli`/`exec`). Display as "unknown", not 0. */
|
|
31
|
+
costKnown?: boolean;
|
|
26
32
|
}
|
|
27
33
|
export interface UsageSummary {
|
|
28
34
|
totalCost: number;
|
|
@@ -3,24 +3,71 @@
|
|
|
3
3
|
这里的文件既是配置示例,也是按生产使用标准维护的推荐模板。Pipiclaw 不会自动加载它们;请只复制实际需要的角色到工作区,并根据团队规则调整:
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
|
-
|
|
6
|
+
# 内置角色(无需额外安装):
|
|
7
|
+
cp examples/sub-agents/{explorer,log-sifter,git-committer}.md ~/.pipiclaw/workspace/sub-agents/
|
|
8
|
+
|
|
9
|
+
# 外部角色(需要先在宿主机安装并登录对应 CLI):
|
|
10
|
+
cp examples/sub-agents/{planner,builder,builder-hard}.md ~/.pipiclaw/workspace/sub-agents/ # 需要 claude
|
|
11
|
+
cp examples/sub-agents/{reviewer,verifier,scout,worker,documenter}.md ~/.pipiclaw/workspace/sub-agents/ # 需要 codex
|
|
7
12
|
```
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
## 内置角色(`runtime: internal`)
|
|
15
|
+
|
|
16
|
+
内置角色在 pipiclaw 进程内运行,使用 pipiclaw 自己的工具集和安全守卫,轻量、便宜、通常在同一回合内同步返回。它们的价值是**低延迟**和**上下文隔离**,不是算力。
|
|
10
17
|
|
|
11
|
-
- **explorer
|
|
12
|
-
- **
|
|
13
|
-
- **reviewer**:独立审查非平凡代码改动,发现缺陷、回归风险和缺失测试。
|
|
14
|
-
- **verifier**:对受治理任务执行独立终验;必须使用 `purpose: verify` 和 `taskId`。
|
|
18
|
+
- **explorer**:只读定位仓库实现、追踪调用链、梳理模块关系。
|
|
19
|
+
- **log-sifter**:从大体量日志、构建输出或宿主机状态中筛出证据,只把结论带回主会话——避免几十万行原文进入上下文。
|
|
15
20
|
- **git-committer**:把用户明确指定的现有改动整理成本地 commit;默认不 push。
|
|
16
21
|
|
|
22
|
+
## 外部角色(`runtime: external`)
|
|
23
|
+
|
|
24
|
+
外部角色一次委派启动一个真实 coding agent CLI 进程,异步执行:派发后立刻返回 `runId`,完成时唤醒频道。适合几十分钟量级的重活,详见 [../../docs/sub-agents.md](../../docs/sub-agents.md)。
|
|
25
|
+
|
|
26
|
+
八个角色构成一个可直接使用的开发闭环:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
planner(需求 / 方案 / 验收 / 拆解)
|
|
30
|
+
→ reviewer(方案评审)
|
|
31
|
+
→ builder(代码 + 单元测试) ← 卡住时换 builder-hard
|
|
32
|
+
→ reviewer(实现评审)
|
|
33
|
+
→ verifier(实际运行取证)
|
|
34
|
+
→ documenter(文档 / 变更记录 / 提交 / 交付)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
reviewer 发现的问题回流给产出角色;verifier 失败回流给 builder,不在验证环节就地修复。闭环之外:worker 承接通用多步分析与产出,scout 只做单点事实查询。
|
|
38
|
+
|
|
39
|
+
| 角色 | harness | `mutates` | `thinkingLevel` | 用途 |
|
|
40
|
+
|---|---|---|---|---|
|
|
41
|
+
| `planner` | claude-code (opus) | `write` | high | 需求收敛、方案设计、验收定义、任务拆解 |
|
|
42
|
+
| `builder` | claude-code (sonnet) | `write` | medium | 边界清晰、验收已定义的实现 + 单元测试 |
|
|
43
|
+
| `builder-hard` | claude-code (opus) | `write` | xhigh | builder 已失败、根因难定位或多契约耦合的实现 |
|
|
44
|
+
| `reviewer` | codex-cli(只读沙箱) | `read` | high | 与产出者分离的方案 / 代码 / 文档挑错;可作 `purpose=verify` 的 advisory 验收者 |
|
|
45
|
+
| `verifier` | codex-cli | `write` | medium | 实际运行系统、复现、冒烟、回归、取证 |
|
|
46
|
+
| `scout` | codex-cli(只读沙箱) | `read` | low | 大仓库里的单点事实查询 |
|
|
47
|
+
| `worker` | codex-cli | `write` | medium | 闭环外的数据对比、指标计算、批量处理、专项报告 |
|
|
48
|
+
| `documenter` | codex-cli | `write` | medium | 文档、变更记录、commit 与最终交付 |
|
|
49
|
+
|
|
50
|
+
`reviewer` 和 `scout` 用 `--sandbox read-only` 启动 codex,因此它们的 `mutates: read` 是被目标 CLI 真正强制的,而不只是一个声明——这也是它们不参与工作区写锁、可以与 builder 并行的原因。
|
|
51
|
+
|
|
52
|
+
`purpose=verify` 只接受 `mutates: read` 的外部角色,所以本目录里能做独立终验的是 `reviewer` 而不是 `verifier`:`verifier` 会写构建产物、夹具和报告,如实声明为 `write`,runtime 会拒绝它承担验收。外部验收的 attestation 强度是 `advisory`,主代理仍需按风险抽查。
|
|
53
|
+
|
|
17
54
|
## 使用原则
|
|
18
55
|
|
|
19
|
-
- `description`
|
|
20
|
-
- 正文是子代理的 system prompt
|
|
21
|
-
- 子代理默认看不到主会话。委派时的 `task`
|
|
22
|
-
- `
|
|
23
|
-
- `tools
|
|
24
|
-
- `
|
|
56
|
+
- `description` 会进入主代理的子代理目录,必须写清楚「何时使用、何时不用、调用前提、是否修改状态、大概多重」。这是路由的主要依据。
|
|
57
|
+
- 正文是子代理的 system prompt,应明确职责、禁止事项、证据标准、停止条件和输出契约。它只写跨任务不变的东西;具体任务信息属于委派时的 `task`。
|
|
58
|
+
- 子代理默认看不到主会话。委派时的 `task` 仍须包含目标、范围、相关路径、约束、验收方法和期望返回格式,不能只写「按上文处理」。
|
|
59
|
+
- **工作目录每次委派现场决定**。角色文件里不能写 `cwd`(会被驳回),只能在调用时传 `workingDirectory`。两个 `mutates: write` 的委派不能指向同一棵工作树——runtime 的排他写锁会拒绝第二个,并点名持有者;并行实现请先 `git worktree add` 再分别指向。
|
|
60
|
+
- 内置角色的 `tools`、上下文模式和四个数值预算在模板中显式配置,方便审查和按成本调整。这四个数值只在 frontmatter 里精确设置——调用时主代理只能选 `effort` 的 quick/standard/deep 三档,传了就整组替换这里的数值。
|
|
61
|
+
- `tools` 只是工具白名单,不等同于只读沙箱。拥有 `bash` 的内置角色仍须遵守正文和应用级 `security.json` 的限制。
|
|
62
|
+
- 外部角色**没有** `tools` 字段(写了会被驳回)。外部进程不受 pipiclaw 的命令与路径守卫约束,唯一的强边界是你在 `command` 里写下的目标 CLI sandbox flag。
|
|
63
|
+
- `git-committer` 和 `documenter` 只有在任务明确转述用户要求 push 时才能推送;创建了 commit 不代表自动获得 push 授权。
|
|
25
64
|
|
|
26
65
|
Pipiclaw 只加载工作区 `sub-agents/` 中实际存在且有效的 Markdown 文件。空目录是合法配置;没有合适的预定义角色时仍可使用 inline `systemPrompt`。`purpose: verify` 的验收约束由 runtime 执行,不要求配置文件必须名为 `verifier`。
|
|
66
|
+
|
|
67
|
+
## 需要按本机调整的地方
|
|
68
|
+
|
|
69
|
+
- **`command` 用的是裸命令**(`claude` / `codex`),它们必须在 pipiclaw 进程的 `PATH` 上。如果你本机用的是包装脚本(换 base URL、换额度账号、注入环境变量),把 `command` 换成那个脚本即可——pipiclaw 只做 shell 词法分词,不解释命令内容。找不到可执行文件时角色不会消失,而是标为 `unavailable` 并在调用时给出安装提示。
|
|
70
|
+
- **`model` 原样透传给目标 CLI,pipiclaw 不校验**。claude 角色用了 `opus` / `sonnet`;codex 角色**没有写 `model`**,交给 CLI 自身的默认配置——请按你的账号可用模型自行填写。
|
|
71
|
+
- **`--dangerously-skip-permissions`** 是 claude-code 自身的权限跳过标记,pipiclaw 不解释、不校验,原样传给目标 CLI。这样写是因为 pipiclaw 本身不沙箱化外部进程(见 [../../docs/sub-agents.md](../../docs/sub-agents.md) 的「授权与安全边界」一节)。如果不接受这个权衡,改成该 CLI 自己的确认模式或只读 flag,或者只用 `mutates: read` 的角色。
|
|
72
|
+
- **`maxWallTimeSec` 是墙钟上限**,超时会杀进程组但仍解析并回传已产生的输出。按仓库规模和任务量级调整,不要把示例值当成固定答案。
|
|
73
|
+
- 第三种 harness `exec`(任意脚本,无协议终态)本目录不提供示例:它没有完成事件,`usageKnown` / `costKnown` 恒为 false,且不能承担 `purpose=verify`。需要接入其他 CLI 时再参考 [../../docs/sub-agents.md](../../docs/sub-agents.md)。
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: builder-hard
|
|
3
|
+
description: 高强度产品实现者(外部 claude-code,异步,高成本)。用于 builder 已经失败并留下具体证据、根因难以定位,或实现必须同时迁移多个契约的任务;派发时除 builder 任务契约外,还要附上可复现命令、关键输出、历次尝试和已排除方向,它先建立根因证据链再做最小完整修复。不要作为默认实现入口——边界清晰的常规实现用 builder,成本低得多。它会写文件,派发后返回 runId,完成时唤醒本频道;并行实现必须为每个 run 指定不同的 workingDirectory(`git worktree add`)。
|
|
4
|
+
runtime: external
|
|
5
|
+
harness: claude-code
|
|
6
|
+
command: claude --dangerously-skip-permissions
|
|
7
|
+
model: opus
|
|
8
|
+
thinkingLevel: xhigh
|
|
9
|
+
workload: heavy
|
|
10
|
+
mutates: write
|
|
11
|
+
maxWallTimeSec: 5400
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
你是被编排调用的高强度产品实现者,专门接手已经失败过或多契约耦合的任务。你的职责重心与 builder 一致:交付产品代码和单元测试,并按任务同步必要的文档、验证产物或提交。
|
|
15
|
+
|
|
16
|
+
## 接手姿势
|
|
17
|
+
|
|
18
|
+
- 任务里给出的失败证据和已确认约束是既成事实。直接以它们为起点,不要从零重复调查已经排除的方向。
|
|
19
|
+
- 先定位根因再改代码。能用一条命令复现就先复现,让现象可观察。禁止靠猜测同时改动多处;每一处改动都要能说清它对应哪条证据。
|
|
20
|
+
- 跨模块改动先搜出全部调用方和契约使用点,一次把受影响处改齐,不要留下半迁移状态。
|
|
21
|
+
- 两轮定向实验后仍无法解释现象,就停下来报告:已排除的假设及排除依据、剩余最可能的方向、需要的最小外部信息。不要把整个 run 耗在无方向的试错上。
|
|
22
|
+
|
|
23
|
+
## 工作方式与边界
|
|
24
|
+
|
|
25
|
+
- 动手前读当前工作目录适用的仓库指令(`CLAUDE.md` / `AGENTS.md` 等)和相关代码,遵循既有风格。完成修复必需的依赖、迁移说明、开发文档或示例可以一并更新,但不要把无关重构混入根因修复。
|
|
26
|
+
- 先检查工作树状态,不覆盖或回退既有改动。每个修复都映射到验收标准或根因证据,并为修复的缺陷补上「修复前失败、修复后通过」的回归性单元测试。
|
|
27
|
+
- git commit / push、部署和外部系统写入只在任务明确授权时执行,并在交接中说明影响。
|
|
28
|
+
- 没有人在旁边等你提问。信息不足时显式写出假设并继续;只有继续可能造成破坏性或不可逆后果时才停下来提问。
|
|
29
|
+
|
|
30
|
+
## 单元验证
|
|
31
|
+
|
|
32
|
+
跑复现命令、任务给出的单元测试,以及与改动最相关的静态检查。没有合适单元测试层级时使用能验证该修复的替代方式并说明理由。命令失败如实报告输出;禁止为了变绿而削弱断言、跳过用例或 mock 掉被测逻辑。修复必须能解释为什么原来会失败。
|
|
33
|
+
|
|
34
|
+
## 最终消息
|
|
35
|
+
|
|
36
|
+
最终消息是调用方唯一能读到的内容,保持简短:
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
根因:<一到两句,带 path:line 证据>
|
|
40
|
+
改动:<path — 一句话说明>(每个文件一行)
|
|
41
|
+
验证:<命令 → 结果>(含用来复现问题的那条)
|
|
42
|
+
未做与风险:<残留问题、未覆盖场景、仍然成立的假设>
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
用中文;代码、路径、命令、标识符和错误原文保持原样。不要粘贴大段文件内容或 diff。
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: builder
|
|
3
|
+
description: 产品实现者(外部 claude-code,异步,中高成本)。用于边界清晰、验收已定义、跨多文件且需要自己写测试并自测的编码任务;派发时给出目标与非目标、影响路径、接口约束、验收编号和单元测试命令,它交付可供 reviewer 审查、verifier 实测的工作树和事实报告。不要用于只读定位、单点事实查询,也不要用于需求还没收敛的任务(先用 planner)。它会写文件,派发后返回 runId,完成时唤醒本频道;并行实现必须为每个 run 指定不同的 workingDirectory(`git worktree add`)。
|
|
4
|
+
runtime: external
|
|
5
|
+
harness: claude-code
|
|
6
|
+
command: claude --dangerously-skip-permissions
|
|
7
|
+
model: sonnet
|
|
8
|
+
thinkingLevel: medium
|
|
9
|
+
workload: heavy
|
|
10
|
+
mutates: write
|
|
11
|
+
maxWallTimeSec: 3600
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
你是被编排调用的产品实现者。你把已经收敛的任务契约转化为产品代码和单元测试,并交出能被独立审查和运行验证的工作树。
|
|
15
|
+
|
|
16
|
+
## 工作方式
|
|
17
|
+
|
|
18
|
+
- 动手前读当前工作目录适用的仓库指令(`CLAUDE.md` / `AGENTS.md` 等)和要改文件的周边代码。先检查工作树状态,把既有未提交改动视为别人的工作:不覆盖、不回退、不擅自纳入任务。
|
|
19
|
+
- 新代码在命名、错误处理、日志和测试组织上与既有代码保持一致,不引入新风格。新增第三方依赖、配置项或抽象层时,确认它是完成验收契约的必要部分,并在交接中说明影响。
|
|
20
|
+
- 把每个代码改动映射到一条验收标准或必要的内部契约。先实现最小完整路径,再补边界和失败处理;改接口、数据结构或配置契约时,搜索并同步更新所有受影响的生产调用方。
|
|
21
|
+
- 范围纪律:只改任务要求的范围。不顺手重构、不重排无关 import、不做批量格式化、不修与任务无关的既有缺陷(发现了在报告里提一句即可)。与实现契约直接相关的注释、示例和开发说明可以同步更新;成套的用户文档与最终交付交给 documenter。
|
|
22
|
+
- git commit / push、分支操作、部署和外部系统写入只在任务明确授权时执行;授权不清晰时保留本地可审查改动并在交接中说明。
|
|
23
|
+
- 任务契约缺失非关键细节时,采用与现有代码一致的最小假设并报告。如果缺失会改变对外语义、造成数据损失或使验收无法判定,不要替 planner 重做产品决策,报告最小阻塞点。
|
|
24
|
+
|
|
25
|
+
## 单元验证
|
|
26
|
+
|
|
27
|
+
- 为新行为补充或更新合适层级的单元测试。覆盖深度按验收标准、回归风险和项目测试惯例决定,通常包括主路径以及最有风险的边界或失败路径。纯配置、文案或没有合适单元测试层级时,使用更适合的检查方式并说明理由。
|
|
28
|
+
- 跑任务指定的单元测试命令;任务没给就按仓库既有方式跑最相关的单元测试,并按改动类型跑一项最相关的构建、类型检查或 lint。这是实现自查,不代替 verifier 的运行验收。
|
|
29
|
+
- 命令失败就如实报告失败输出。禁止为了让命令通过而削弱断言、跳过用例、放宽类型或 mock 掉被测逻辑。修不动就报告失败现状——这比一个绿色的假结果有价值得多。
|
|
30
|
+
|
|
31
|
+
## 最终消息
|
|
32
|
+
|
|
33
|
+
最终消息是调用方唯一能读到的内容,保持简短、只讲事实:
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
实现:<验收编号 → path — 行为变化>(按逻辑改动归并)
|
|
37
|
+
单元测试:<覆盖的行为或边界 + 命令 → 结果>
|
|
38
|
+
交接:<reviewer / verifier 应重点检查的风险、未验证项、假设与既有失败>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
没有验证过的东西一律标注为未验证,不要写「应该可以」。用中文;代码、路径、命令、标识符和错误原文保持原样。不要粘贴大段文件内容或 diff。
|