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.
- package/README.md +201 -513
- package/core/api-guide-types.ts +263 -46
- package/core/api-toggle.ts +245 -40
- package/core/auth.ts +996 -76
- package/core/delete-command.ts +1 -1
- package/core/fs-0600.ts +39 -0
- package/core/guide-catalog.ts +349 -0
- package/core/guide-picker.ts +76 -61
- package/core/guide-store.ts +21 -6
- package/core/helpers-command.ts +6 -5
- package/core/helpers.ts +551 -148
- package/core/local-helpers.ts +17 -2
- package/core/oauth-command.ts +911 -0
- package/core/oauth-flow.ts +376 -0
- package/core/oauth-store.ts +306 -0
- package/core/parse-api-guide.ts +1153 -542
- package/core/path-template.ts +147 -0
- package/core/portal-projection.ts +3 -4
- package/core/resolve-op.ts +113 -67
- package/core/response-spill.ts +10 -7
- package/core/secrets-command.ts +18 -13
- package/core/secrets-store.ts +11 -44
- package/core/select-picker.ts +171 -0
- package/core/staging.ts +29 -0
- package/core/status-hint.ts +61 -0
- package/core/transport.ts +321 -34
- package/core/verify-command.ts +215 -116
- package/docs/migration-v1.md +56 -0
- package/index.ts +24 -7
- package/package.json +18 -6
- package/tools/api-fetch.ts +49 -21
- package/tools/api-guide.ts +21 -12
- package/tools/api-learn.ts +515 -126
- package/tools/api-probe.ts +473 -323
- package/tools/api-scaffold.ts +413 -0
- package/tools/api-store.ts +381 -0
- package/tools/oauth-mint.ts +338 -0
- package/tools/utils.ts +1 -1
- package/core/verify-ship-manifest.ts +0 -118
- package/tools/index.ts +0 -7
package/core/local-helpers.ts
CHANGED
|
@@ -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/<
|
|
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}`))) {
|