@caplets/pi 0.1.2 → 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.
package/README.md CHANGED
@@ -26,4 +26,9 @@ pnpm add -D @caplets/pi
26
26
 
27
27
  The extension reads your existing Caplets configuration through `@caplets/core`; it does not create or mutate Pi config files.
28
28
 
29
- New or removed Caplets are snapshotted at extension load. Restart Pi or reload extensions to refresh the native tool list.
29
+ The extension hot reloads Caplets config and Caplet file edits. Existing tools execute against
30
+ the latest valid backend config. Newly added Caplets are registered in the current Pi session;
31
+ removed or disabled Caplets are deactivated with Pi's active-tool APIs when available. If Pi is
32
+ running without `getActiveTools()` / `setActiveTools()`, stale tools may remain registered until
33
+ Pi reloads extensions or restarts, but calls to removed Caplets return Caplets' normal structured
34
+ "server not found" error.
package/dist/index.js CHANGED
@@ -15,9 +15,43 @@ function capletsPiParameters() {
15
15
  //#endregion
16
16
  //#region src/index.ts
17
17
  function capletsPiExtension(pi, options = {}) {
18
+ const ownsService = !options.service;
18
19
  const service = options.service ?? createNativeCapletsService();
19
- if (!options.service) registerNativeCapletsProcessCleanup(service);
20
- for (const caplet of service.listTools()) pi.registerTool({
20
+ if (ownsService) registerNativeCapletsProcessCleanup(service);
21
+ const registeredCapletToolSignatures = /* @__PURE__ */ new Map();
22
+ let knownCapletTools = new Set(pi.getActiveTools?.().filter((name) => name.startsWith("caplets_")) ?? []);
23
+ const syncTools = (caplets = service.listTools()) => {
24
+ const nextCapletTools = new Set(caplets.map((caplet) => caplet.toolName));
25
+ for (const [toolName] of registeredCapletToolSignatures) if (!nextCapletTools.has(toolName)) registeredCapletToolSignatures.delete(toolName);
26
+ for (const caplet of caplets) {
27
+ const signature = piToolSignature(caplet);
28
+ if (registeredCapletToolSignatures.get(caplet.toolName) === signature) continue;
29
+ registeredCapletToolSignatures.set(caplet.toolName, signature);
30
+ pi.registerTool(createPiTool(service, caplet));
31
+ }
32
+ if (pi.getActiveTools && pi.setActiveTools) {
33
+ const activeNonCaplets = pi.getActiveTools().filter((name) => !knownCapletTools.has(name) && !nextCapletTools.has(name));
34
+ pi.setActiveTools([...activeNonCaplets, ...nextCapletTools]);
35
+ }
36
+ knownCapletTools = nextCapletTools;
37
+ };
38
+ syncTools();
39
+ const unsubscribe = service.onToolsChanged(syncTools);
40
+ pi.on?.("session_shutdown", () => {
41
+ unsubscribe();
42
+ if (ownsService) service.close();
43
+ });
44
+ }
45
+ function piToolSignature(caplet) {
46
+ return JSON.stringify({
47
+ caplet: caplet.caplet,
48
+ title: caplet.title,
49
+ description: caplet.description,
50
+ promptGuidance: caplet.promptGuidance
51
+ });
52
+ }
53
+ function createPiTool(service, caplet) {
54
+ return {
21
55
  name: caplet.toolName,
22
56
  label: caplet.title,
23
57
  description: caplet.description,
@@ -38,7 +72,7 @@ function capletsPiExtension(pi, options = {}) {
38
72
  } : { result }
39
73
  };
40
74
  }
41
- });
75
+ };
42
76
  }
43
77
  function serializeResult(result) {
44
78
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caplets/pi",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Native Pi extension for Caplets.",
5
5
  "homepage": "https://github.com/spiritledsoftware/caplets#readme",
6
6
  "bugs": {
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@sinclair/typebox": "^0.34.49",
30
- "@caplets/core": "0.12.0"
30
+ "@caplets/core": "0.12.2"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/node": "^25.7.0",