@milanglacier/pi-plan-mode 0.5.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.
- package/README.md +99 -0
- package/flow.ts +665 -0
- package/index.ts +240 -0
- package/install.mjs +107 -0
- package/package.json +54 -0
- package/plan-files.ts +154 -0
- package/prompts/PLAN.prompt.md +13 -0
- package/prompts.ts +45 -0
- package/qna/index.ts +3 -0
- package/qna/pi-tui-loader.ts +92 -0
- package/qna/qna-tui.ts +877 -0
- package/qna/scroll-select.ts +353 -0
- package/request-user-input.ts +259 -0
- package/schemas.ts +53 -0
- package/state.ts +164 -0
- package/types.ts +36 -0
- package/utils.ts +64 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
<!-- {=sharedQnaPiTuiLoaderOverview} -->
|
|
3
|
+
|
|
4
|
+
`local qna helpers` centralizes `@earendil-works/pi-tui` loading so first-party packages reuse one
|
|
5
|
+
fallback strategy instead of embedding Bun-global lookup logic in multiple runtime modules.
|
|
6
|
+
|
|
7
|
+
The shared loader returns pi's extension-provided `@earendil-works/pi-tui` module by default.
|
|
8
|
+
Custom require functions can still exercise the normal package resolution path and Bun global
|
|
9
|
+
fallback locations for tests or standalone callers running outside pi's extension loader.
|
|
10
|
+
|
|
11
|
+
<!-- {/sharedQnaPiTuiLoaderOverview} -->
|
|
12
|
+
*/
|
|
13
|
+
import * as piTuiModule from "@earendil-works/pi-tui";
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
import os from "node:os";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
|
|
18
|
+
export type PiTuiRequire = (specifier: string) => unknown;
|
|
19
|
+
|
|
20
|
+
export interface PiTuiLoaderOptions {
|
|
21
|
+
homeDir?: string;
|
|
22
|
+
bunInstallDir?: string | undefined;
|
|
23
|
+
requireFn?: PiTuiRequire;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
<!-- {=sharedQnaGetPiTuiFallbackPathsDocs} -->
|
|
28
|
+
|
|
29
|
+
Return the ordered list of Bun global fallback paths to try for `@earendil-works/pi-tui`.
|
|
30
|
+
|
|
31
|
+
The list prefers an explicit `BUN_INSTALL` root when provided and always includes the default
|
|
32
|
+
`~/.bun/install/global/node_modules/@earendil-works/pi-tui` fallback without duplicates.
|
|
33
|
+
|
|
34
|
+
<!-- {/sharedQnaGetPiTuiFallbackPathsDocs} -->
|
|
35
|
+
*/
|
|
36
|
+
export function getPiTuiFallbackPaths(options: Omit<PiTuiLoaderOptions, "requireFn"> = {}): string[] {
|
|
37
|
+
const homeDir = options.homeDir ?? os.homedir();
|
|
38
|
+
const roots = new Set<string>();
|
|
39
|
+
if (options.bunInstallDir) {
|
|
40
|
+
roots.add(options.bunInstallDir);
|
|
41
|
+
}
|
|
42
|
+
roots.add(path.join(homeDir, ".bun"));
|
|
43
|
+
return [...roots].map((root) => path.join(root, "install", "global", "node_modules", "@earendil-works", "pi-tui"));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
<!-- {=sharedQnaRequirePiTuiModuleDocs} -->
|
|
48
|
+
|
|
49
|
+
Load `@earendil-works/pi-tui` with a shared fallback strategy.
|
|
50
|
+
|
|
51
|
+
Pi exposes `@earendil-works/pi-tui` as an available extension import. Returning the static import
|
|
52
|
+
keeps us on pi's module resolver; using `createRequire(import.meta.url)` in that path bypasses pi's
|
|
53
|
+
resolver and can crash render callbacks when the peer dependency is not locally installed.
|
|
54
|
+
|
|
55
|
+
When a custom `requireFn` or fallback path options are provided, the loader keeps the older
|
|
56
|
+
standalone behavior: try normal package resolution, then walk Bun-global fallback locations, and
|
|
57
|
+
finally throw a helpful error that names every checked location when none resolve.
|
|
58
|
+
|
|
59
|
+
<!-- {/sharedQnaRequirePiTuiModuleDocs} -->
|
|
60
|
+
*/
|
|
61
|
+
export function requirePiTuiModule(options: PiTuiLoaderOptions = {}): unknown {
|
|
62
|
+
if (!options.requireFn && !options.homeDir && !options.bunInstallDir) {
|
|
63
|
+
return piTuiModule;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const requireFn = options.requireFn ?? createRequire(import.meta.url);
|
|
67
|
+
try {
|
|
68
|
+
return requireFn("@earendil-works/pi-tui");
|
|
69
|
+
} catch (error) {
|
|
70
|
+
const code = (error as { code?: string }).code;
|
|
71
|
+
if (code !== "MODULE_NOT_FOUND") {
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const fallbackPaths = getPiTuiFallbackPaths(options);
|
|
76
|
+
for (const fallbackPath of fallbackPaths) {
|
|
77
|
+
try {
|
|
78
|
+
return requireFn(fallbackPath);
|
|
79
|
+
} catch (fallbackError) {
|
|
80
|
+
const fallbackCode = (fallbackError as { code?: string }).code;
|
|
81
|
+
if (fallbackCode !== "MODULE_NOT_FOUND") {
|
|
82
|
+
throw fallbackError;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Unable to load @earendil-works/pi-tui. Checked the local dependency and Bun global fallbacks: ${fallbackPaths.join(", ")}`,
|
|
89
|
+
{ cause: error },
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
}
|