@ferris1225/pi-subagents 4.0.0 → 4.1.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.
@@ -1,80 +1,80 @@
1
- /** Pi SessionManager-backed cloning of a retained sub-agent session branch. */
2
-
3
- import { SessionManager } from "@earendil-works/pi-coding-agent";
4
- import { existsSync } from "node:fs";
5
- import { mkdtemp, rm } from "node:fs/promises";
6
- import { tmpdir } from "node:os";
7
- import { join } from "node:path";
8
-
9
- export interface ForkedSession {
10
- sessionDir: string;
11
- sessionId: string;
12
- sessionFile: string;
13
- }
14
-
15
- /** Locate one retained session by its authoritative header id. */
16
- export async function findRetainedSessionFile(
17
- sessionDir: string,
18
- sessionId: string,
19
- ): Promise<string> {
20
- // The retained header may point at a worktree that has since been removed.
21
- // The session id is authoritative inside this explicit private directory;
22
- // listing the directory directly avoids a stale-cwd filter rejecting it.
23
- const sessions = await SessionManager.listAll(sessionDir);
24
- const matches = sessions.filter((session) => session.id === sessionId);
25
- if (matches.length === 0) {
26
- throw new Error(`Retained session ${sessionId} was not found in ${sessionDir}.`);
27
- }
28
- if (matches.length > 1) {
29
- throw new Error(`Retained session id ${sessionId} is ambiguous in ${sessionDir}.`);
30
- }
31
- return matches[0].path;
32
- }
33
-
34
- /**
35
- * Copy only the source file's active branch into a new isolated temp session
36
- * directory. SessionManager performs all JSONL/tree handling; source state is
37
- * never mutated.
38
- */
39
- export async function forkRetainedSession(options: {
40
- /** Cwd stored in the source session header (used for exact lookup). */
41
- cwd: string;
42
- /** Optional cwd for the cloned session header and future child tools. */
43
- targetCwd?: string;
44
- sessionDir: string;
45
- sessionId: string;
46
- }): Promise<ForkedSession> {
47
- const sourceSessionFile = await findRetainedSessionFile(
48
- options.sessionDir,
49
- options.sessionId,
50
- );
51
- const sessionDir = await mkdtemp(join(tmpdir(), "pi-subagent-session-fork-"));
52
- try {
53
- // Supplying the new directory makes createBranchedSession write there.
54
- // cwdOverride rewrites the cloned header so a settled isolated session can
55
- // safely continue in its fresh worktree instead of a removed old path.
56
- const manager = SessionManager.open(
57
- sourceSessionFile,
58
- sessionDir,
59
- options.targetCwd ?? options.cwd,
60
- );
61
- const leafId = manager.getLeafId();
62
- if (!leafId) throw new Error(`Retained session ${options.sessionId} has no active branch to fork.`);
63
- const sessionFile = manager.createBranchedSession(leafId);
64
- if (!sessionFile) throw new Error("Pi SessionManager did not create a persistent fork.");
65
- // Pi defers branch files that contain no assistant response. Such a file
66
- // cannot be resumed by RPC without creating a blank session, so reject
67
- // rather than pretending context was preserved.
68
- if (!existsSync(sessionFile)) {
69
- throw new Error(`Forked session branch has no persisted assistant checkpoint at ${sessionFile}.`);
70
- }
71
- return {
72
- sessionDir,
73
- sessionId: manager.getSessionId(),
74
- sessionFile,
75
- };
76
- } catch (error) {
77
- await rm(sessionDir, { recursive: true, force: true }).catch(() => undefined);
78
- throw error;
79
- }
80
- }
1
+ /** Pi SessionManager-backed cloning of a retained sub-agent session branch. */
2
+
3
+ import { SessionManager } from "@earendil-works/pi-coding-agent";
4
+ import { existsSync } from "node:fs";
5
+ import { mkdtemp, rm } from "node:fs/promises";
6
+ import { tmpdir } from "node:os";
7
+ import { join } from "node:path";
8
+
9
+ export interface ForkedSession {
10
+ sessionDir: string;
11
+ sessionId: string;
12
+ sessionFile: string;
13
+ }
14
+
15
+ /** Locate one retained session by its authoritative header id. */
16
+ export async function findRetainedSessionFile(
17
+ sessionDir: string,
18
+ sessionId: string,
19
+ ): Promise<string> {
20
+ // The retained header may point at a worktree that has since been removed.
21
+ // The session id is authoritative inside this explicit private directory;
22
+ // listing the directory directly avoids a stale-cwd filter rejecting it.
23
+ const sessions = await SessionManager.listAll(sessionDir);
24
+ const matches = sessions.filter((session) => session.id === sessionId);
25
+ if (matches.length === 0) {
26
+ throw new Error(`Retained session ${sessionId} was not found in ${sessionDir}.`);
27
+ }
28
+ if (matches.length > 1) {
29
+ throw new Error(`Retained session id ${sessionId} is ambiguous in ${sessionDir}.`);
30
+ }
31
+ return matches[0].path;
32
+ }
33
+
34
+ /**
35
+ * Copy only the source file's active branch into a new isolated temp session
36
+ * directory. SessionManager performs all JSONL/tree handling; source state is
37
+ * never mutated.
38
+ */
39
+ export async function forkRetainedSession(options: {
40
+ /** Cwd stored in the source session header (used for exact lookup). */
41
+ cwd: string;
42
+ /** Optional cwd for the cloned session header and future child tools. */
43
+ targetCwd?: string;
44
+ sessionDir: string;
45
+ sessionId: string;
46
+ }): Promise<ForkedSession> {
47
+ const sourceSessionFile = await findRetainedSessionFile(
48
+ options.sessionDir,
49
+ options.sessionId,
50
+ );
51
+ const sessionDir = await mkdtemp(join(tmpdir(), "pi-subagent-session-fork-"));
52
+ try {
53
+ // Supplying the new directory makes createBranchedSession write there.
54
+ // cwdOverride rewrites the cloned header so a settled isolated session can
55
+ // safely continue in its fresh worktree instead of a removed old path.
56
+ const manager = SessionManager.open(
57
+ sourceSessionFile,
58
+ sessionDir,
59
+ options.targetCwd ?? options.cwd,
60
+ );
61
+ const leafId = manager.getLeafId();
62
+ if (!leafId) throw new Error(`Retained session ${options.sessionId} has no active branch to fork.`);
63
+ const sessionFile = manager.createBranchedSession(leafId);
64
+ if (!sessionFile) throw new Error("Pi SessionManager did not create a persistent fork.");
65
+ // Pi defers branch files that contain no assistant response. Such a file
66
+ // cannot be resumed by RPC without creating a blank session, so reject
67
+ // rather than pretending context was preserved.
68
+ if (!existsSync(sessionFile)) {
69
+ throw new Error(`Forked session branch has no persisted assistant checkpoint at ${sessionFile}.`);
70
+ }
71
+ return {
72
+ sessionDir,
73
+ sessionId: manager.getSessionId(),
74
+ sessionFile,
75
+ };
76
+ } catch (error) {
77
+ await rm(sessionDir, { recursive: true, force: true }).catch(() => undefined);
78
+ throw error;
79
+ }
80
+ }
package/src/setup.ts CHANGED
@@ -13,6 +13,7 @@ import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
13
13
  import {
14
14
  AGENT_SCOPE_VALUES,
15
15
  BUILTIN_AGENT_NAMES,
16
+ CLEANER_DEFAULTED_FEATURE,
16
17
  DEFAULT_CONFIG,
17
18
  DEFAULT_ENABLED_AGENTS,
18
19
  DEFAULT_IDLE_TIMEOUT_SEC,
@@ -329,7 +330,9 @@ async function runFullSetup(ctx: ExtensionCommandContext, configPath: string, ba
329
330
  maxConcurrency,
330
331
  maxFixRounds,
331
332
  idleTimeoutSec,
332
- announcedFeatures: base.announcedFeatures,
333
+ // Full setup is an explicit decision point: mark the cleaner
334
+ // default-enable upgrade as processed so the saved list is kept as-is.
335
+ announcedFeatures: [...new Set([...base.announcedFeatures, CLEANER_DEFAULTED_FEATURE])],
333
336
  };
334
337
  await saveConfig(next, configPath);
335
338
  ctx.ui.notify(`pi-subagents configured with Auto thinking. Saved to ${configPath}`, "info");
@@ -391,6 +394,17 @@ async function runMenu(ctx: ExtensionCommandContext, configPath: string, config:
391
394
  const enabled = await pickEnabledAgents(ctx, config.enabledAgents);
392
395
  if (enabled === undefined) return notifyCancelled(ctx);
393
396
  next.enabledAgents = enabled;
397
+ // Newly enabling cleaner inherits the reviewer's configured model and
398
+ // thinking level, so the file reflects what cleaner will actually run
399
+ // instead of silently falling back to the current main model.
400
+ if (!config.enabledAgents.includes("cleaner") && enabled.includes("cleaner")) {
401
+ if (!next.agentModels.cleaner && config.agentModels.reviewer) {
402
+ next.agentModels.cleaner = config.agentModels.reviewer;
403
+ }
404
+ if (!next.agentThinkingLevels.cleaner && config.agentThinkingLevels.reviewer) {
405
+ next.agentThinkingLevels.cleaner = config.agentThinkingLevels.reviewer;
406
+ }
407
+ }
394
408
  next.agentModels = keepAgentEntries(next.agentModels, enabled);
395
409
  next.agentThinkingLevels = keepAgentEntries(next.agentThinkingLevels, enabled);
396
410
  } else if (choice.startsWith("Configure")) {