pi-lean-host 0.3.1 → 0.5.0

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.
@@ -2,7 +2,7 @@
2
2
  * Local user helpers — `import()`-loaded transform modules.
3
3
  *
4
4
  * User-authored TypeScript helpers live alongside their guide in a per-domain
5
- * subdirectory: `~/.pi/agent/pi-lean-host/api-guides/<domain>/helper.ts`.
5
+ * subdirectory: `~/.pi/agent/pi-lean-host/api-guides/<slug(shortName)>/helper.ts`.
6
6
  * They are loaded on demand via dynamic `import()` when an API guide's
7
7
  * operation sets `helper: true`. A load failure (syntax error, missing
8
8
  * dep, top-level throw) or execution throw disables the helper for the
@@ -23,12 +23,19 @@
23
23
  * templating / query assembly. It must be synchronous-pure or
24
24
  * fully-awaited — no background work (setTimeout/setInterval/process.on
25
25
  * callbacks escape as uncaughtException and cannot be caught here).
26
+ *
27
+ * Reserved seam — the return contract. The default export's return stays
28
+ * the params record. Richer pre-call control (request headers, path
29
+ * rewrite) must land as a NEW named export (e.g. `buildRequest`) or a new
30
+ * op field — never by overloading the return shape with reserved wrapper
31
+ * keys ({ params, headers, path }): a legitimate params record whose query
32
+ * params are literally named `params`/`headers`/`path` would be re-meaned.
26
33
  */
27
34
 
28
35
  import { join } from "node:path";
29
36
  import { pathToFileURL } from "node:url";
30
37
  import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
31
- import { getUserGuidesDir } from "./guide-store.js";
38
+ import { getUserGuidesDir, loadAllGuides } from "./guide-store.js";
32
39
  import { assertSafeDomain } from "./path-template.js";
33
40
 
34
41
  // ═══════════════════════════════════════════════════════════════════
@@ -93,10 +100,17 @@ export type CallHelperResult =
93
100
 
94
101
  /**
95
102
  * List all persisted helper domains (domain subdirs with a helper.ts).
103
+ *
104
+ * Only helpers whose folder holds a LOADED (non-malformed) guide are surfaced
105
+ * — a malformed guide's helper is dead (it can never be routed to at fetch
106
+ * time), so listing it is misleading. A helper in a folder with no guide at
107
+ * all is equally dead and hidden. The enumeration intersects the raw
108
+ * filesystem scan with the loader's active-guide set.
96
109
  */
97
110
  export function getAllHelpers(): string[] {
98
111
  const guidesDir = getUserGuidesDir();
99
112
  if (!existsSync(guidesDir)) return [];
113
+ const loadedDirs = new Set(Object.keys(loadAllGuides().guides));
100
114
  const result: string[] = [];
101
115
  for (const entry of readdirSync(guidesDir)) {
102
116
  const entryPath = join(guidesDir, entry);
@@ -105,6 +119,7 @@ export function getAllHelpers(): string[] {
105
119
  } catch {
106
120
  continue;
107
121
  }
122
+ if (!loadedDirs.has(entry)) continue;
108
123
  // Check for helper.ts (or .mjs / .js fallback for tests)
109
124
  for (const ext of [".ts", ".mjs", ".js"] as const) {
110
125
  if (existsSync(join(entryPath, `helper${ext}`))) {