codecartographer-pi 0.1.3 → 0.1.4

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.
@@ -216,26 +216,34 @@ export default function codeCartographerExtension(pi) {
216
216
  }
217
217
  // Orchestrator path: we're the parent. Spawn a child session for the
218
218
  // phase so its tool calls and reasoning land in an isolated context.
219
+ //
220
+ // SDK contract: after `ctx.newSession()` resolves, `ctx` is invalidated
221
+ // — touching `ctx.ui` or `ctx.sessionManager` from the outer scope
222
+ // raises "extension ctx is stale after session replacement". So all
223
+ // outer-session work (status line, widget) has to happen BEFORE the
224
+ // call, and any work that needs a fresh ctx happens INSIDE the
225
+ // `withSession` callback against the new session's ctx.
219
226
  if (currentSessionFile === orchestrator.sessionFile) {
220
- const result = await ctx.newSession({
227
+ lastFeedbackLines = [`Spawned ${phase.id} phase in a sub-agent`];
228
+ setUiState(ctx, state, lastFeedbackLines);
229
+ ctx.ui.notify(`CodeCartographer phase: ${phase.id} (sub-agent)`, "info");
230
+ await ctx.newSession({
221
231
  parentSession: orchestrator.sessionFile,
222
232
  withSession: async (childCtx) => {
223
233
  childCtx.sendUserMessage(prompt);
224
234
  },
225
235
  });
226
- if (result.cancelled) {
227
- ctx.ui.notify("Sub-agent spawn cancelled.", "warning");
228
- return;
229
- }
230
- lastFeedbackLines = [`Spawned ${phase.id} phase in a sub-agent`];
231
- setUiState(ctx, state, lastFeedbackLines);
232
- ctx.ui.notify(`CodeCartographer phase: ${phase.id} (sub-agent)`, "info");
233
236
  return;
234
237
  }
235
- // Phase-child path: we're inside a phase sub-agent. Switch the TUI back
236
- // to the orchestrator and chain the next phase atomically. The fresh
237
- // state read inside withSession reflects any closeouts the child wrote.
238
- const switchResult = await ctx.switchSession(orchestrator.sessionFile, {
238
+ // Phase-child path: switch the TUI back to the orchestrator and chain
239
+ // the next phase atomically. Same staleness rule: pre-switch work uses
240
+ // `ctx`; post-switch work uses the fresh `orchestratorCtx` passed to
241
+ // `withSession`. Inside that callback the inner `newSession()` again
242
+ // invalidates `orchestratorCtx`, so the inner spawn must be the last
243
+ // thing the callback does.
244
+ lastFeedbackLines = ["Returning to orchestrator and queuing next phase as a sub-agent"];
245
+ setUiState(ctx, state, lastFeedbackLines);
246
+ await ctx.switchSession(orchestrator.sessionFile, {
239
247
  withSession: async (orchestratorCtx) => {
240
248
  const freshState = await getWorkspaceState(orchestratorCtx.cwd);
241
249
  if (!freshState) {
@@ -256,12 +264,6 @@ export default function codeCartographerExtension(pi) {
256
264
  });
257
265
  },
258
266
  });
259
- if (switchResult.cancelled) {
260
- ctx.ui.notify("Switch back to orchestrator cancelled.", "warning");
261
- return;
262
- }
263
- lastFeedbackLines = ["Returned to orchestrator and queued next phase as a sub-agent"];
264
- setUiState(ctx, state, lastFeedbackLines);
265
267
  },
266
268
  });
267
269
  pi.registerCommand("codecarto-phase", {
@@ -367,7 +367,7 @@ const HANDLERS = {
367
367
  };
368
368
  // ---------- server bootstrap ----------
369
369
  export function buildServer() {
370
- const server = new Server({ name: "codecartographer", version: "0.1.3" }, { capabilities: { tools: {} } });
370
+ const server = new Server({ name: "codecartographer", version: "0.1.4" }, { capabilities: { tools: {} } });
371
371
  server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
372
372
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
373
373
  const handler = HANDLERS[request.params.name];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codecartographer-pi",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "CodeCartographer packaged for Pi as an extension-driven workflow wrapper.",
5
5
  "type": "module",
6
6
  "keywords": [