@deathbeam/pi-delegate 0.0.31 → 0.0.32
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/index.ts +7 -5
- package/isolation.ts +5 -3
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -270,14 +270,16 @@ export default function (pi: ExtensionAPI) {
|
|
|
270
270
|
if (agent.prompt) args.push("--append-system-prompt", agent.prompt);
|
|
271
271
|
const entrypoint = process.argv[1];
|
|
272
272
|
if (!entrypoint) throw new Error("Pi CLI entrypoint missing; start Pi from its CLI to delegate.");
|
|
273
|
+
const cwd = isolation ? cloneCwd(isolation, ctx.cwd) : ctx.cwd;
|
|
273
274
|
const child = spawn(process.execPath, [entrypoint, "--mode", "rpc", ...args], {
|
|
274
|
-
cwd
|
|
275
|
+
cwd,
|
|
275
276
|
shell: false,
|
|
276
277
|
stdio: "pipe",
|
|
277
278
|
});
|
|
278
279
|
store.launch(job);
|
|
280
|
+
// The brief was written against the main tree, so its absolute paths need mapping to the clone.
|
|
279
281
|
const isolatedPrompt = isolation
|
|
280
|
-
? `You are working in an isolated git clone at ${isolation.clone}
|
|
282
|
+
? `You are working in an isolated git clone at ${isolation.clone}. Your working directory ${cwd} is already inside it, so use relative paths and do not cd into it. Paths under ${ctx.cwd} in the task refer to the same files under ${cwd}. The main working tree is untouched; any edits or commits you make stay in this clone until the orchestrator applies them.${tools.includes("bash") ? " `git diff main-snapshot` shows all changes made in this clone." : ""}`
|
|
281
283
|
: "";
|
|
282
284
|
const run = runChild(
|
|
283
285
|
child,
|
|
@@ -432,9 +434,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
432
434
|
"",
|
|
433
435
|
"A delegate gets the project instructions but not this conversation: it cannot see the user's request, the files you read, or your decisions. Write `task` as a self-contained brief: the goal and why, what you already know (paths, symbols, errors), scope and constraints, whether to edit files or only report, and what to return (format, length, path:line evidence).",
|
|
434
436
|
"",
|
|
435
|
-
"With isolated: true, the delegate runs in an isolated git clone at .pi/worktrees/<job id
|
|
437
|
+
"With isolated: true, the delegate runs in an isolated git clone at .pi/worktrees/<job id>, starting from the main tree exactly as it is now, uncommitted and untracked files included. It never touches the main tree and may commit freely; delegate_apply brings its changes back, delegate_discard drops them.",
|
|
436
438
|
"",
|
|
437
|
-
"To run another delegate in an isolated job's clone, pass that job id as `clone`.
|
|
439
|
+
"To run another delegate in an isolated job's clone, pass that job id as `clone`. delegate_apply or delegate_discard with any job id from that clone acts on the whole clone, and only one job can run in a clone at a time.",
|
|
438
440
|
"",
|
|
439
441
|
"To follow up on or redirect an existing job, see delegate_steer.",
|
|
440
442
|
].join("\n"),
|
|
@@ -677,7 +679,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
677
679
|
store.save(shared);
|
|
678
680
|
}
|
|
679
681
|
throw new Error(
|
|
680
|
-
`Main tree changed under delegate job "${job.id}"; conflicting files: ${result.files.join(", ") || "(unknown)"}. The clone at ${isolation.clone} was kept. Steer job ${job.id} with: "
|
|
682
|
+
`Main tree changed under delegate job "${job.id}"; conflicting files: ${result.files.join(", ") || "(unknown)"}. The clone at ${isolation.clone} was kept. Steer job ${job.id} with: "The main tree changed under you. Run \`git rebase main-snapshot\`, resolve each conflict, then \`git add\` the files and run \`git rebase --continue\` until the rebase finishes." Then call delegate_apply again.`,
|
|
681
683
|
);
|
|
682
684
|
}
|
|
683
685
|
const stat = result.kind === "applied" ? `\n${result.stat}` : "";
|
package/isolation.ts
CHANGED
|
@@ -72,7 +72,7 @@ export function createIsolation(cwd: string, jobId: string): IsolationState {
|
|
|
72
72
|
try {
|
|
73
73
|
root = git(["rev-parse", "--show-toplevel"], { cwd }).trim();
|
|
74
74
|
} catch {
|
|
75
|
-
throw new Error(
|
|
75
|
+
throw new Error("isolated: true requires the session to run inside a git repository.");
|
|
76
76
|
}
|
|
77
77
|
const clone = join(root, ".pi", "worktrees", jobId);
|
|
78
78
|
rmSync(clone, { recursive: true, force: true });
|
|
@@ -118,7 +118,7 @@ export function isolationSummary(iso: IsolationState): string {
|
|
|
118
118
|
// Staging first pulls uncommitted and untracked changes into the stat.
|
|
119
119
|
git(["add", "-A"], { cwd: iso.clone });
|
|
120
120
|
const stat = git(["diff", "--stat", iso.base], { cwd: iso.clone }).trimEnd();
|
|
121
|
-
if (stat) lines.push(`Changes
|
|
121
|
+
if (stat) lines.push(`Changes in this clone:\n${stat}`);
|
|
122
122
|
} catch {
|
|
123
123
|
// The clone may already be applied or gone; the path alone still says where the work lives.
|
|
124
124
|
}
|
|
@@ -142,7 +142,9 @@ export function applyClone(iso: IsolationState): ApplyResult {
|
|
|
142
142
|
if (run(["status", "--porcelain"]).trim()) run([...IDENTITY, "commit", "--no-verify", "-m", "delegate work"]);
|
|
143
143
|
const branch = run(["rev-parse", "--abbrev-ref", "HEAD"]).trim();
|
|
144
144
|
if (branch === SNAPSHOT_BRANCH)
|
|
145
|
-
throw new Error(
|
|
145
|
+
throw new Error(
|
|
146
|
+
`the clone is checked out on ${SNAPSHOT_BRANCH}; steer the delegate to move its work onto its own branch, then apply again`,
|
|
147
|
+
);
|
|
146
148
|
// Snapshot the current main tree, then replay the delegate's commits onto it with a real 3-way
|
|
147
149
|
// merge: git tolerates nearby, non-overlapping edits that raw patch context matching rejects.
|
|
148
150
|
const snapshot = snapshotMainTree(iso, root);
|