pi-petrroll 0.2.0 → 0.2.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/README.md CHANGED
@@ -11,7 +11,7 @@ Independent, focused extensions. No skills, shell wrappers, or replacement built
11
11
 
12
12
  ## Install
13
13
 
14
- Requires **Pi 0.85.1 or newer** (`@earendil-works/pi-coding-agent`); tested against 0.85.1. Change directory requires interactive mode; external cost recording works in all modes. Earlier Pi versions may not rebuild cwd-bound services when switching sessions.
14
+ Requires **Pi 0.85.1 or newer** (`@earendil-works/pi-coding-agent`); tested against 0.85.1 and 1.1.0. Change directory requires interactive mode; external cost recording works in all modes. Earlier Pi versions may not rebuild cwd-bound services when switching sessions.
15
15
 
16
16
  ```sh
17
17
  pi install npm:pi-petrroll
@@ -78,7 +78,7 @@ No quit, terminal `cd`, restart, or cross-directory session-copy confirmation. *
78
78
 
79
79
  Bare `/cd` shows the current directory and usage. Relative paths use Pi's current cwd. `~`, `~/…`, single-quoted paths, JSON double-quoted paths, and symlinks are supported. Paths are not shell commands: no variable expansion, globbing, `~username`, or `cd -`.
80
80
 
81
- Manual `/cd` switches without starting another model response; the agent tool resumes automatically. An existing destination is required. The extension does not create directories or worktrees itself.
81
+ Manual `/cd` switches without starting another model response; the agent tool resumes automatically **after session replacement has fully completed**. The tool intentionally ends the old run, but normally needs no manual `continue`. An existing destination is required. The extension does not create directories or worktrees itself.
82
82
 
83
83
  ### What changes
84
84
 
@@ -98,6 +98,7 @@ Manual `/cd` switches without starting another model response; the agent tool re
98
98
  - The agent should call `change_directory` **alone**, after worktree creation has completed. The tool requests early termination and the command waits for idle so completed tool results are included in the copy. If mixed with other tools, those calls still run in the **old** directory; the switch waits until the run settles.
99
99
  - Explicitly aborting a pending tool handoff prevents the switch. Invalid paths and concurrent requests are rejected.
100
100
  - A cancelled session switch removes the unused copy and keeps the original session. If Pi fails while rebuilding the replacement runtime, its normal fatal-error handling applies; the original and any created copy remain available for recovery.
101
+ - If submitting the automatic continuation fails, the extension warns without treating the successful switch as a failure. Model errors and user aborts still follow Pi's normal behavior; the extension does not retry aborted runs. Send `continue` in the destination if needed.
101
102
  - The copied history can contain references to the old project. A visible context message records the change, and the new system prompt contains the destination's instructions.
102
103
  - Switching reloads project extensions according to Pi's trust policy. Install only code you trust.
103
104
 
@@ -130,7 +131,7 @@ npm run check
130
131
  npm test
131
132
  ```
132
133
 
133
- Tests cover cost validation, native cost accumulation, persistence/resume, compaction, path handling, copy/branch preservation, cancellation, aborts, concurrency, and a real Pi runtime handoff with a fake model stream. The runtime test verifies that tool results are copied, `read` and `bash` use the new cwd, destination `AGENTS.md` replaces source context, and the agent continues. Tests do not call a model API or use your credentials.
134
+ Tests cover cost validation, native cost accumulation, persistence/resume, compaction, path handling, copy/branch preservation, cancellation, aborts, concurrency, and a real Pi runtime handoff with a fake model stream. The runtime test verifies that tool results are copied, `read` and `bash` use the new cwd, destination `AGENTS.md` replaces source context, and the agent continues only after the host finishes switching. Unit tests also cover continuation-submission failures without rolling back the successful switch. Tests do not call a model API or use your credentials.
134
135
 
135
136
  ```text
136
137
  extensions/
@@ -80,15 +80,27 @@ export default function cdExtension(pi: ExtensionAPI) {
80
80
  { from: ctx.cwd, to: target, parentSession: source },
81
81
  );
82
82
  const destination = copy.getSessionFile()!;
83
- // Do not use captured pi/ctx in withSession: the old runtime is invalid.
83
+ let resume: (() => Promise<void>) | undefined;
84
84
  const result = await ctx.switchSession(destination, {
85
85
  withSession: async (fresh) => {
86
86
  fresh.ui.notify(`Changed directory to ${fresh.cwd}`, "info");
87
87
  if (request) {
88
- await fresh.sendUserMessage(
89
- "The requested directory change has completed. Continue the outstanding task in this directory. " +
90
- "If no work remains, briefly confirm the change.",
91
- );
88
+ // Capture only the fresh context, not the invalidated pi/ctx.
89
+ resume = async () => {
90
+ try {
91
+ await fresh.sendUserMessage(
92
+ "The requested directory change has completed. Continue the outstanding task in this directory. " +
93
+ "If no work remains, briefly confirm the change.",
94
+ { deliverAs: "followUp" },
95
+ );
96
+ } catch (error) {
97
+ fresh.ui.notify(
98
+ `Directory changed, but automatic continuation failed: ${error instanceof Error ? error.message : String(error)}. ` +
99
+ 'Send "continue" to resume.',
100
+ "warning",
101
+ );
102
+ }
103
+ };
92
104
  }
93
105
  },
94
106
  });
@@ -100,7 +112,12 @@ export default function cdExtension(pi: ExtensionAPI) {
100
112
  display: true,
101
113
  });
102
114
  ctx.ui.notify("Directory change cancelled.", "warning");
115
+ return;
103
116
  }
117
+ // sendUserMessage awaits the entire agent run. Do not run it inside
118
+ // withSession: the host must finish switching first, and prompt errors
119
+ // must not be treated as fatal failures to replace the runtime.
120
+ await resume?.();
104
121
  } finally {
105
122
  // Local state only; session-bound pi/ctx may now be stale.
106
123
  busy = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-petrroll",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Small, focused Pi extensions by petrroll: switch projects and track external costs in your session.",
5
5
  "type": "module",
6
6
  "license": "MIT",