pi-archimedes 1.8.0 → 1.8.2

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.
Files changed (2) hide show
  1. package/package.json +9 -9
  2. package/src/index.ts +25 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-archimedes",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -11,14 +11,14 @@
11
11
  ],
12
12
  "main": "./src/index.ts",
13
13
  "dependencies": {
14
- "@pi-archimedes/core": "1.8.0",
15
- "@pi-archimedes/diff": "1.8.0",
16
- "@pi-archimedes/ask": "1.8.0",
17
- "@pi-archimedes/image-paste": "1.8.0",
18
- "@pi-archimedes/subagent": "1.8.0",
19
- "@pi-archimedes/todo": "1.8.0",
20
- "@pi-archimedes/notify": "1.8.0",
21
- "@pi-archimedes/footer": "1.8.0"
14
+ "@pi-archimedes/core": "1.8.2",
15
+ "@pi-archimedes/footer": "1.8.2",
16
+ "@pi-archimedes/ask": "1.8.2",
17
+ "@pi-archimedes/diff": "1.8.2",
18
+ "@pi-archimedes/image-paste": "1.8.2",
19
+ "@pi-archimedes/subagent": "1.8.2",
20
+ "@pi-archimedes/todo": "1.8.2",
21
+ "@pi-archimedes/notify": "1.8.2"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@earendil-works/pi-coding-agent": ">=0.1.0",
package/src/index.ts CHANGED
@@ -14,13 +14,12 @@ import { registerNotify } from "@pi-archimedes/notify";
14
14
  import { loadDiffConfig } from "./config.js";
15
15
  import { openSettings } from "./settings.js"
16
16
 
17
- // Module-level refs for shutdown (survive hot-reloads)
17
+ // Module-level ref for shutdown (survives session replacements)
18
18
  let imagePasteShutdown: (() => void) | undefined;
19
- // Guard: tracks which lazy-loaded packages have been registered.
20
- // session_start fires for /new, /resume, /fork, /reload each tears down the
21
- // old runtime and rebuilds, but pi itself stays loaded, so this module is
22
- // evaluated once and these guards prevent handler accumulation on reload.
23
- const registeredLazy = new Set<string>();
19
+ // Module-level ref for current session context (survives /reload, /new, /fork)
20
+ // Used by diff's theme getter callbackupdated every session_start so the
21
+ // getter always returns the latest ctx's theme even after session replacement.
22
+ let currentCtx: ExtensionContext | undefined;
24
23
 
25
24
  export default function (pi: ExtensionAPI): void {
26
25
  archResetTimings();
@@ -58,6 +57,9 @@ export default function (pi: ExtensionAPI): void {
58
57
  pi.on("session_start", async (_event, ctx: ExtensionContext) => {
59
58
  archTime(`session_start (factory was ${Date.now() - _moduleEvalAt}ms ago)`);
60
59
 
60
+ // Update module-level context ref so lazy-loaded callbacks always see current session
61
+ currentCtx = ctx;
62
+
61
63
  // ── Parallel lazy-load all three packages (saves ~100ms vs sequential) ──
62
64
  const [diffMod, ipMod, saMod] = await Promise.all([
63
65
  import("@pi-archimedes/diff").catch((e) => { console.error("[archimedes] diff load failed:", e); return null; }),
@@ -66,26 +68,28 @@ export default function (pi: ExtensionAPI): void {
66
68
  ]);
67
69
  archTime("3 packages loaded in parallel");
68
70
 
69
- if (diffMod && !registeredLazy.has("diff")) {
70
- diffMod.registerDiffTools(pi, () => ctx.ui.theme, () => loadDiffConfig());
71
- registeredLazy.add("diff");
71
+ // Each session_start fires on a fresh Extension (pi creates a new
72
+ // ExtensionRunner per session). Registration is safe to — and must —
73
+ // run every time. The registeredLazy guard was removed because it
74
+ // prevented subagent/diff/image-paste from being registered after
75
+ // /new, /fork, /resume: jiti caches the compiled module, so the guard
76
+ // persisted across sessions while each new session creates a fresh
77
+ // Extension with empty tools/commands maps.
78
+ if (diffMod) {
79
+ diffMod.registerDiffTools(pi, () => currentCtx!.ui.theme, () => loadDiffConfig());
72
80
  }
73
81
  if (ipMod) {
74
- // initImagePasteSession must run every session_start (it captures the new ctx)
75
- // but the actual handler registration via pi.on("input", ...) must only happen once.
76
- if (!registeredLazy.has("image-paste")) {
77
- ipMod.registerImagePaste(pi);
78
- imagePasteShutdown = ipMod.shutdownImagePaste;
79
- registeredLazy.add("image-paste");
80
- }
82
+ // registerImagePaste calls pi.on("input", ...) and pi.registerShortcut()
83
+ // on the current Extension. Since each session replacement creates a
84
+ // new Extension with its own handler list, there is no accumulation.
85
+ ipMod.registerImagePaste(pi);
86
+ imagePasteShutdown = ipMod.shutdownImagePaste;
87
+ // initImagePasteSession must run every session_start (captures fresh ctx)
81
88
  ipMod.initImagePasteSession(ctx);
82
89
  }
83
90
  if (saMod) {
84
- if (!registeredLazy.has("subagent")) {
85
- saMod.registerSubagent(pi);
86
- saMod.registerAgentsCommand(pi);
87
- registeredLazy.add("subagent");
88
- }
91
+ saMod.registerSubagent(pi);
92
+ saMod.registerAgentsCommand(pi);
89
93
  }
90
94
  });
91
95