@henryqw/pi-herdr-clone 0.2.6 → 0.2.8

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.
@@ -12,7 +12,7 @@ import {
12
12
  import {
13
13
  createHerdrClient,
14
14
  herdrCommandFailure,
15
- hasHerdrErrorCode,
15
+ startPiAgent,
16
16
  withWorktreeLock,
17
17
  type HerdrClient,
18
18
  type HerdrExecResult,
@@ -129,14 +129,12 @@ async function createBranchedClone(
129
129
  const createdClone = session.createBranchedSession(source.leafId);
130
130
  if (!createdClone) throw new Error("Pi did not create a persisted clone session file.");
131
131
  const cloneFile = resolve(createdClone);
132
- let cloneStat;
133
132
  try {
134
- cloneStat = await stat(cloneFile);
133
+ if ((await stat(cloneFile)).isFile()) return cloneFile;
135
134
  } catch (error) {
136
135
  throw new Error(`Pi clone session file was not created: ${cloneFile}`, { cause: error });
137
136
  }
138
- if (!cloneStat.isFile()) throw new Error(`Pi clone session path is not a file: ${cloneFile}`);
139
- return cloneFile;
137
+ throw new Error(`Pi clone session path is not a file: ${cloneFile}`);
140
138
  }
141
139
 
142
140
  // A worktree layout plugin (e.g. herdr-plus) can start its own agent in a new
@@ -201,24 +199,25 @@ async function launchCloneAgent(
201
199
  ): Promise<string> {
202
200
  const agentName = `clone-${randomUUID().replaceAll("-", "").slice(0, 24)}`;
203
201
  try {
204
- for (let attempt = 1; attempt <= 5; attempt += 1) {
205
- const startArgs = [
206
- "agent", "start", agentName, "--kind", "pi", "--pane", rootPaneId,
207
- "--", "--session", cloneFile,
208
- ];
209
- const result = await herdr.exec(startArgs, { cwd: ctx.cwd });
210
- if (result.code === 0 && !result.killed) return agentName;
211
- if (hasHerdrErrorCode(result, "agent_pane_busy") && onPaneBusy) {
212
- ({ rootPaneId, retained } = await onPaneBusy());
213
- onPaneBusy = undefined;
214
- continue;
215
- }
216
- if (!hasHerdrErrorCode(result, "agent_pane_busy") || attempt === 5) {
217
- throw new Error(herdrCommandFailure(startArgs, result));
218
- }
219
- await delay(250);
220
- }
221
- throw new Error("Herdr agent start retry loop exited unexpectedly.");
202
+ const result = await startPiAgent(herdr, {
203
+ name: agentName,
204
+ pane: rootPaneId,
205
+ args: ["--session", cloneFile],
206
+ options: { cwd: ctx.cwd },
207
+ onPaneBusy: onPaneBusy
208
+ ? async () => {
209
+ const next = await onPaneBusy!();
210
+ rootPaneId = next.rootPaneId;
211
+ retained = next.retained;
212
+ return rootPaneId;
213
+ }
214
+ : undefined,
215
+ });
216
+ if (result.code === 0 && !result.killed) return agentName;
217
+ const startArgs = [
218
+ "agent", "start", agentName, "--kind", "pi", "--pane", rootPaneId, "--", "--session", cloneFile,
219
+ ];
220
+ throw new Error(herdrCommandFailure(startArgs, result));
222
221
  } catch (error) {
223
222
  throw new Error(
224
223
  `Clone launch could not be confirmed after starting agent ${agentName}; retained ${retained}: ${errorMessage(error)}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henryqw/pi-herdr-clone",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Clone the current Pi conversation path into a new Herdr tab.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -28,7 +28,7 @@
28
28
  "@earendil-works/pi-coding-agent": "^0.84.2"
29
29
  },
30
30
  "dependencies": {
31
- "@henryqw/pi-herdr": "^0.3.0"
31
+ "@henryqw/pi-herdr": "^0.4.0"
32
32
  },
33
33
  "repository": {
34
34
  "type": "git",