@narumitw/pi-starship 0.60.1 → 0.63.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 +67 -9
- package/dist/chunks/chunk-63R6R5DH.ts +679 -0
- package/dist/chunks/chunk-63R6R5DH.ts.map +7 -0
- package/dist/chunks/{chunk-KZZKGGFW.ts → chunk-A65IOGL6.ts} +858 -1007
- package/dist/chunks/chunk-A65IOGL6.ts.map +7 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts +69 -0
- package/dist/chunks/chunk-IYDZ3R2T.ts.map +7 -0
- package/dist/chunks/chunk-KP33I6BR.ts +579 -0
- package/dist/chunks/chunk-KP33I6BR.ts.map +7 -0
- package/dist/chunks/{chunk-PD457PX5.ts → chunk-S2KBLHE2.ts} +75 -10
- package/dist/chunks/chunk-S2KBLHE2.ts.map +7 -0
- package/dist/chunks/chunk-XQUIQO2G.ts +20 -0
- package/dist/chunks/chunk-XQUIQO2G.ts.map +7 -0
- package/dist/chunks/{chunk-ADX4CY27.ts → chunk-XTLQ4WUL.ts} +1 -1
- package/dist/chunks/chunk-XTLQ4WUL.ts.map +7 -0
- package/dist/chunks/chunk-Y24TJYG6.ts +1586 -0
- package/dist/chunks/chunk-Y24TJYG6.ts.map +7 -0
- package/dist/chunks/{cloud-EPAEV4ZB.ts → cloud-J2ZOE3HE.ts} +6 -2
- package/dist/chunks/cloud-J2ZOE3HE.ts.map +7 -0
- package/dist/chunks/command-configuration-menu-YOLN2SPR.ts +147 -0
- package/dist/chunks/command-configuration-menu-YOLN2SPR.ts.map +7 -0
- package/dist/chunks/command-settings-chat-5AHP3JGV.ts +1124 -0
- package/dist/chunks/command-settings-chat-5AHP3JGV.ts.map +7 -0
- package/dist/chunks/commands-IOG2PL67.ts +1026 -0
- package/dist/chunks/commands-IOG2PL67.ts.map +7 -0
- package/dist/chunks/{deployment-7J54EHNR.ts → deployment-NOJ2KCLI.ts} +85 -5
- package/dist/chunks/deployment-NOJ2KCLI.ts.map +7 -0
- package/dist/chunks/{development-IWJAAAEV.ts → development-T3XXVVDP.ts} +67 -15
- package/dist/chunks/development-T3XXVVDP.ts.map +7 -0
- package/dist/chunks/directory-OX6BWJZA.ts +31 -0
- package/dist/chunks/directory-OX6BWJZA.ts.map +7 -0
- package/dist/chunks/{execution-P4WZALW2.ts → execution-R2OHIP2L.ts} +8 -4
- package/dist/chunks/execution-R2OHIP2L.ts.map +7 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts +174 -0
- package/dist/chunks/jujutsu-XLDYKSX2.ts.map +7 -0
- package/dist/chunks/languages-CBQNNYXM.ts +262 -0
- package/dist/chunks/languages-CBQNNYXM.ts.map +7 -0
- package/dist/chunks/{package-H24VJEX3.ts → package-7KVAK3TC.ts} +6 -2
- package/dist/chunks/package-7KVAK3TC.ts.map +7 -0
- package/dist/chunks/system-574MHB4R.ts +165 -0
- package/dist/chunks/system-574MHB4R.ts.map +7 -0
- package/dist/index.ts +670 -206
- package/dist/index.ts.map +4 -4
- package/package.json +5 -1
- package/skills/configure-pi-starship/SKILL.md +17 -1
- package/skills/configure-pi-starship/references/configuration.md +119 -32
- package/skills/configure-pi-starship/references/module-catalog.md +278 -25
- package/skills/configure-pi-starship/references/modules.md +213 -36
- package/skills/configure-pi-starship/references/runtime-and-security.md +88 -28
- package/src/command-commit.ts +41 -7
- package/src/command-configuration-menu.ts +155 -0
- package/src/command-configuration.ts +15 -94
- package/src/command-preview.ts +3 -3
- package/src/command-settings-chat.ts +168 -0
- package/src/commands.ts +76 -124
- package/src/config/module-options.ts +112 -0
- package/src/config.ts +23 -59
- package/src/effective-config.ts +5 -4
- package/src/format/bounded-regex.ts +66 -0
- package/src/format/version.ts +24 -0
- package/src/modules/catalog.ts +10 -0
- package/src/modules/cloud.ts +1 -0
- package/src/modules/deployment.ts +8 -0
- package/src/modules/development.ts +20 -2
- package/src/modules/directory.ts +171 -51
- package/src/modules/execution.ts +2 -0
- package/src/modules/git/branch.ts +19 -4
- package/src/modules/git/commit.ts +9 -2
- package/src/modules/git/metrics.ts +9 -4
- package/src/modules/git/runtime.ts +122 -33
- package/src/modules/git/state.ts +23 -2
- package/src/modules/git/status-templates.ts +58 -0
- package/src/modules/git/status.ts +96 -30
- package/src/modules/jujutsu.ts +225 -0
- package/src/modules/languages.ts +26 -2
- package/src/modules/package.ts +1 -0
- package/src/modules/render.ts +42 -16
- package/src/modules/system.ts +54 -0
- package/src/modules/time-format.ts +188 -0
- package/src/modules/time.ts +11 -5
- package/src/modules/types.ts +42 -4
- package/src/pi-starship.ts +198 -88
- package/src/profile-store.ts +5 -0
- package/src/runtime/cloud.ts +3 -0
- package/src/runtime/command.ts +1 -1
- package/src/runtime/deployment.ts +120 -4
- package/src/runtime/development.ts +86 -13
- package/src/runtime/directory.ts +33 -0
- package/src/runtime/execution.ts +12 -2
- package/src/runtime/helpers.ts +57 -8
- package/src/runtime/jujutsu.ts +225 -0
- package/src/runtime/languages.ts +106 -19
- package/src/runtime/package.ts +3 -0
- package/src/runtime/system.ts +202 -0
- package/src/runtime/types.ts +3 -0
- package/src/runtime/version-requirements.ts +30 -0
- package/src/runtime/workspace.ts +12 -1
- package/src/settings-agent.ts +80 -0
- package/src/settings-chat-transcript.ts +192 -0
- package/src/settings-chat-ui.ts +526 -0
- package/src/settings-draft.ts +260 -0
- package/src/settings-snapshots.ts +41 -0
- package/dist/chunks/chunk-ADX4CY27.ts.map +0 -7
- package/dist/chunks/chunk-KZZKGGFW.ts.map +0 -7
- package/dist/chunks/chunk-PD457PX5.ts.map +0 -7
- package/dist/chunks/cloud-EPAEV4ZB.ts.map +0 -7
- package/dist/chunks/commands-C2VJ6ZBN.ts +0 -3374
- package/dist/chunks/commands-C2VJ6ZBN.ts.map +0 -7
- package/dist/chunks/deployment-7J54EHNR.ts.map +0 -7
- package/dist/chunks/development-IWJAAAEV.ts.map +0 -7
- package/dist/chunks/execution-P4WZALW2.ts.map +0 -7
- package/dist/chunks/languages-JO6R2PHL.ts +0 -168
- package/dist/chunks/languages-JO6R2PHL.ts.map +0 -7
- package/dist/chunks/package-H24VJEX3.ts.map +0 -7
- package/src/command-inspector.ts +0 -41
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { extname, isAbsolute, join, resolve } from "node:path";
|
|
2
|
+
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
2
3
|
import { parse as parseYaml } from "yaml";
|
|
4
|
+
import { matchPattern, replacePattern } from "../format/bounded-regex.js";
|
|
5
|
+
import type { ModuleContextRule } from "../modules/types.js";
|
|
3
6
|
import {
|
|
7
|
+
detectEnvironment,
|
|
4
8
|
directMatch,
|
|
5
9
|
exactAlias,
|
|
6
10
|
formatVersion,
|
|
@@ -15,18 +19,26 @@ import {
|
|
|
15
19
|
runBounded,
|
|
16
20
|
safeMetadata,
|
|
17
21
|
} from "./helpers.js";
|
|
18
|
-
import
|
|
22
|
+
import {
|
|
23
|
+
type CollectorContext,
|
|
24
|
+
type MutableModuleSnapshot,
|
|
25
|
+
PRIVATE_STYLE_SELECTOR,
|
|
26
|
+
type WorkspaceEntry,
|
|
27
|
+
} from "./types.js";
|
|
19
28
|
|
|
20
29
|
export async function collectDeployment(context: CollectorContext): Promise<MutableModuleSnapshot> {
|
|
21
30
|
const result: MutableModuleSnapshot = {};
|
|
31
|
+
if (context.input.signal?.aborted) return result;
|
|
22
32
|
if (context.needs("docker_context")) {
|
|
23
33
|
const docker = await collectDocker(context);
|
|
24
34
|
if (docker) result.docker_context = docker;
|
|
25
35
|
}
|
|
36
|
+
if (context.input.signal?.aborted) return result;
|
|
26
37
|
if (context.needs("kubernetes")) {
|
|
27
38
|
const kubernetes = await collectKubernetes(context);
|
|
28
39
|
if (kubernetes) result.kubernetes = kubernetes;
|
|
29
40
|
}
|
|
41
|
+
if (context.input.signal?.aborted) return result;
|
|
30
42
|
if (context.needs("terraform")) {
|
|
31
43
|
const terraform = await collectTerraform(context);
|
|
32
44
|
if (terraform) result.terraform = terraform;
|
|
@@ -69,6 +81,7 @@ async function collectDocker(context: CollectorContext): Promise<Record<string,
|
|
|
69
81
|
}
|
|
70
82
|
|
|
71
83
|
async function collectKubernetes(context: CollectorContext): Promise<Record<string, string> | undefined> {
|
|
84
|
+
if (!(await kubernetesDetected(context)) || context.input.signal?.aborted) return undefined;
|
|
72
85
|
const selected = safeMetadata(context.input.environment.KUBECONFIG, 4_096);
|
|
73
86
|
const candidates = selected
|
|
74
87
|
? selected.split(context.input.platform === "win32" ? ";" : ":").filter(Boolean)
|
|
@@ -79,7 +92,9 @@ async function collectKubernetes(context: CollectorContext): Promise<Record<stri
|
|
|
79
92
|
const users = new Set<string>();
|
|
80
93
|
let currentContext: string | undefined;
|
|
81
94
|
for (const path of candidates.slice(0, limit)) {
|
|
95
|
+
if (context.input.signal?.aborted) return undefined;
|
|
82
96
|
const source = await context.fs.readFile(path, MAX_METADATA_FILE_BYTES);
|
|
97
|
+
if (context.input.signal?.aborted) return undefined;
|
|
83
98
|
if (!source) continue;
|
|
84
99
|
try {
|
|
85
100
|
const document = parseYaml(source) as unknown;
|
|
@@ -106,19 +121,120 @@ async function collectKubernetes(context: CollectorContext): Promise<Record<stri
|
|
|
106
121
|
const cluster = safeMetadata(selectedContext?.cluster);
|
|
107
122
|
const user = safeMetadata(selectedContext?.user);
|
|
108
123
|
const namespace = safeMetadata(selectedContext?.namespace) ?? "default";
|
|
124
|
+
const matched = matchKubernetesRule(context.options("kubernetes").contexts, currentContext, user);
|
|
125
|
+
const displayContext = matched?.context ?? currentContext;
|
|
126
|
+
const displayUser = matched?.user ?? user;
|
|
109
127
|
const values: Record<string, string> = {
|
|
110
|
-
context: exactAlias(
|
|
128
|
+
context: exactAlias(displayContext, optionMap(context, "kubernetes", "context_aliases")) ?? displayContext,
|
|
111
129
|
namespace: exactAlias(namespace, optionMap(context, "kubernetes", "namespace_aliases")) ?? namespace,
|
|
112
130
|
};
|
|
113
131
|
if (cluster && clusters.has(cluster)) {
|
|
114
132
|
values.cluster = exactAlias(cluster, optionMap(context, "kubernetes", "cluster_aliases")) ?? cluster;
|
|
115
133
|
}
|
|
116
|
-
|
|
117
|
-
|
|
134
|
+
// Preserve Pi's existing named-user requirement unless a rule supplies a label.
|
|
135
|
+
if (displayUser !== undefined && ((user && users.has(user)) || matched?.rule.user_alias !== undefined)) {
|
|
136
|
+
values.user = exactAlias(displayUser, optionMap(context, "kubernetes", "user_aliases")) ?? displayUser;
|
|
118
137
|
}
|
|
138
|
+
if (matched?.rule.symbol !== undefined) values.symbol = matched.rule.symbol;
|
|
139
|
+
if (matched?.rule.style !== undefined) values[PRIVATE_STYLE_SELECTOR] = matched.rule.style;
|
|
119
140
|
return values;
|
|
120
141
|
}
|
|
121
142
|
|
|
143
|
+
async function kubernetesDetected(context: CollectorContext): Promise<boolean> {
|
|
144
|
+
const files = optionStrings(context, "kubernetes", "detect_files");
|
|
145
|
+
const extensions = optionStrings(context, "kubernetes", "detect_extensions");
|
|
146
|
+
const folders = optionStrings(context, "kubernetes", "detect_folders");
|
|
147
|
+
// Upstream gives a configured directory scan precedence over environment checks.
|
|
148
|
+
if (files.length + extensions.length + folders.length > 0) {
|
|
149
|
+
const entries = await context.entries();
|
|
150
|
+
return !context.input.signal?.aborted && kubernetesDirectoryMatch(entries, files, extensions, folders);
|
|
151
|
+
}
|
|
152
|
+
return detectEnvironment(context.input.environment, optionStrings(context, "kubernetes", "detect_env_vars"));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function kubernetesDirectoryMatch(
|
|
156
|
+
entries: readonly WorkspaceEntry[],
|
|
157
|
+
files: readonly string[],
|
|
158
|
+
extensions: readonly string[],
|
|
159
|
+
folders: readonly string[],
|
|
160
|
+
): boolean {
|
|
161
|
+
// Unlike the shared legacy detector, upstream ignores hidden-file extensions
|
|
162
|
+
// and recognizes both the last suffix and a complete compound suffix.
|
|
163
|
+
// Use only regular entries from the bounded listing; do not follow symlinks.
|
|
164
|
+
const foundFiles = new Set<string>();
|
|
165
|
+
const foundFolders = new Set<string>();
|
|
166
|
+
const foundExtensions = new Set<string>();
|
|
167
|
+
for (const entry of entries) {
|
|
168
|
+
if (entry.isDirectory) foundFolders.add(entry.name);
|
|
169
|
+
if (!entry.isFile) continue;
|
|
170
|
+
foundFiles.add(entry.name);
|
|
171
|
+
if (entry.name.startsWith(".")) continue;
|
|
172
|
+
const firstDot = entry.name.indexOf(".");
|
|
173
|
+
if (firstDot < 0) continue;
|
|
174
|
+
foundExtensions.add(entry.name.slice(firstDot + 1));
|
|
175
|
+
foundExtensions.add(entry.name.slice(entry.name.lastIndexOf(".") + 1));
|
|
176
|
+
}
|
|
177
|
+
const criteria = [
|
|
178
|
+
[files, foundFiles],
|
|
179
|
+
[extensions, foundExtensions],
|
|
180
|
+
[folders, foundFolders],
|
|
181
|
+
] as const;
|
|
182
|
+
return (
|
|
183
|
+
criteria.every(([patterns, found]) => !patterns.some((name) => name.startsWith("!") && found.has(name.slice(1)))) &&
|
|
184
|
+
criteria.some(([patterns, found]) => patterns.some((name) => !name.startsWith("!") && found.has(name)))
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
interface MatchedKubernetesRule {
|
|
189
|
+
rule: ModuleContextRule;
|
|
190
|
+
context: string;
|
|
191
|
+
user?: string;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function matchKubernetesRule(
|
|
195
|
+
rules: unknown,
|
|
196
|
+
context: string,
|
|
197
|
+
user: string | undefined,
|
|
198
|
+
): MatchedKubernetesRule | undefined {
|
|
199
|
+
if (!Array.isArray(rules)) return undefined;
|
|
200
|
+
for (const rule of rules.slice(0, 64)) {
|
|
201
|
+
if (!isKubernetesRule(rule)) continue;
|
|
202
|
+
const contextAlias = kubernetesRuleAlias(rule.context_pattern, context, rule.context_alias);
|
|
203
|
+
if (contextAlias === undefined) continue;
|
|
204
|
+
const userAlias = kubernetesRuleAlias(rule.user_pattern, user, rule.user_alias);
|
|
205
|
+
if (rule.user_pattern !== undefined && userAlias === undefined) continue;
|
|
206
|
+
return { rule, context: contextAlias, user: userAlias };
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function isKubernetesRule(rule: unknown): rule is ModuleContextRule {
|
|
212
|
+
return (
|
|
213
|
+
isRecord(rule) &&
|
|
214
|
+
typeof rule.context_pattern === "string" &&
|
|
215
|
+
["user_pattern", "symbol", "style", "context_alias", "user_alias"].every(
|
|
216
|
+
(key) => rule[key] === undefined || typeof rule[key] === "string",
|
|
217
|
+
)
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function kubernetesRuleAlias(
|
|
222
|
+
pattern: string | undefined,
|
|
223
|
+
value: string | undefined,
|
|
224
|
+
alias: string | undefined,
|
|
225
|
+
): string | undefined {
|
|
226
|
+
const replacement = alias ?? value;
|
|
227
|
+
if (replacement === undefined) return undefined;
|
|
228
|
+
if (pattern === undefined || value === pattern) {
|
|
229
|
+
return alias === undefined ? replacement : (safeMetadata(sanitizeTerminalText(replacement)) ?? "");
|
|
230
|
+
}
|
|
231
|
+
if (value === undefined || !matchPattern(pattern, value)) return undefined;
|
|
232
|
+
if (alias === undefined) return value;
|
|
233
|
+
// Grouped anchors keep replacements whole-label even with alternation.
|
|
234
|
+
const replaced = replacePattern(`^(?:${pattern})$`, value, alias);
|
|
235
|
+
return replaced === undefined ? undefined : (safeMetadata(sanitizeTerminalText(replaced)) ?? "");
|
|
236
|
+
}
|
|
237
|
+
|
|
122
238
|
async function collectTerraform(context: CollectorContext): Promise<Record<string, string> | undefined> {
|
|
123
239
|
const entries = await context.entries();
|
|
124
240
|
const configuredFiles = optionStrings(context, "terraform", "detect_files");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import { parse } from "smol-toml";
|
|
3
3
|
import {
|
|
4
|
+
detectEnvironment,
|
|
4
5
|
directMatch,
|
|
5
6
|
formatVersion,
|
|
6
7
|
isRecord,
|
|
@@ -25,22 +26,47 @@ export async function collectDevelopment(context: CollectorContext): Promise<Mut
|
|
|
25
26
|
if (context.needs("mise", "health")) {
|
|
26
27
|
const output = await runBounded(context, "mise", ["doctor"]);
|
|
27
28
|
const health = output ? parseMiseHealth(output) : undefined;
|
|
28
|
-
if (health)
|
|
29
|
+
if (health) {
|
|
30
|
+
values.health =
|
|
31
|
+
optionString(context, "mise", health === "healthy" ? "healthy_symbol" : "unhealthy_symbol") ?? health;
|
|
32
|
+
}
|
|
29
33
|
}
|
|
30
34
|
result.mise = values;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
if (
|
|
37
|
+
if (
|
|
38
|
+
context.needs("direnv") &&
|
|
39
|
+
(detected(context, entries, "direnv", [".envrc"]) ||
|
|
40
|
+
(optionStrings(context, "direnv", "detect_env_vars").length > 0 &&
|
|
41
|
+
detectEnvironment(context.input.environment, optionStrings(context, "direnv", "detect_env_vars"))))
|
|
42
|
+
) {
|
|
34
43
|
const values: Record<string, string> = {};
|
|
35
44
|
if (["rc_path", "allowed", "loaded"].some((variable) => context.needs("direnv", variable))) {
|
|
36
45
|
const output = await runBounded(context, "direnv", ["status", "--json"]);
|
|
37
|
-
if (output)
|
|
46
|
+
if (output) {
|
|
47
|
+
Object.assign(
|
|
48
|
+
values,
|
|
49
|
+
parseDirenvStatus(output, {
|
|
50
|
+
allowed: optionString(context, "direnv", "allowed_msg"),
|
|
51
|
+
notAllowed: optionString(context, "direnv", "not_allowed_msg"),
|
|
52
|
+
denied: optionString(context, "direnv", "denied_msg"),
|
|
53
|
+
loaded: optionString(context, "direnv", "loaded_msg"),
|
|
54
|
+
unloaded: optionString(context, "direnv", "unloaded_msg"),
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
38
58
|
}
|
|
39
59
|
result.direnv = values;
|
|
40
60
|
}
|
|
41
61
|
|
|
62
|
+
if (context.input.signal?.aborted) return {};
|
|
42
63
|
const conda = safeMetadata(context.input.environment.CONDA_DEFAULT_ENV);
|
|
43
|
-
if (
|
|
64
|
+
if (
|
|
65
|
+
context.needs("conda") &&
|
|
66
|
+
conda &&
|
|
67
|
+
!(optionBoolean(context, "conda", "ignore_base") && conda === "base") &&
|
|
68
|
+
detectEnvironment(context.input.environment, optionStrings(context, "conda", "detect_env_vars"))
|
|
69
|
+
) {
|
|
44
70
|
result.conda = { environment: conda };
|
|
45
71
|
}
|
|
46
72
|
|
|
@@ -52,6 +78,7 @@ export async function collectDevelopment(context: CollectorContext): Promise<Mut
|
|
|
52
78
|
}
|
|
53
79
|
const project = safeMetadata(context.input.environment.PIXI_PROJECT_NAME) ?? (await readPixiProject(context));
|
|
54
80
|
if (project) values.project_name = project;
|
|
81
|
+
if (context.input.signal?.aborted) return {};
|
|
55
82
|
if (context.needs("pixi", "version")) {
|
|
56
83
|
const output = await runBounded(context, "pixi", ["--version"]);
|
|
57
84
|
const version = output ? parsePixiVersion(output) : undefined;
|
|
@@ -62,7 +89,9 @@ export async function collectDevelopment(context: CollectorContext): Promise<Mut
|
|
|
62
89
|
|
|
63
90
|
const nixState = safeMetadata(context.input.environment.IN_NIX_SHELL);
|
|
64
91
|
if (context.needs("nix_shell") && (nixState === "pure" || nixState === "impure")) {
|
|
65
|
-
const values: Record<string, string> = {
|
|
92
|
+
const values: Record<string, string> = {
|
|
93
|
+
state: optionString(context, "nix_shell", nixState === "pure" ? "pure_msg" : "impure_msg") ?? nixState,
|
|
94
|
+
};
|
|
66
95
|
setString(values, "name", context.input.environment.NIX_SHELL_NAME);
|
|
67
96
|
setString(values, "level", context.input.environment.NIX_SHELL_LEVEL);
|
|
68
97
|
result.nix_shell = values;
|
|
@@ -97,26 +126,70 @@ export function parseMiseHealth(output: string): string | undefined {
|
|
|
97
126
|
return undefined;
|
|
98
127
|
}
|
|
99
128
|
|
|
100
|
-
|
|
129
|
+
interface DirenvMessages {
|
|
130
|
+
allowed?: string;
|
|
131
|
+
notAllowed?: string;
|
|
132
|
+
denied?: string;
|
|
133
|
+
loaded?: string;
|
|
134
|
+
unloaded?: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export function parseDirenvStatus(output: string, messages: DirenvMessages = {}): Record<string, string> {
|
|
138
|
+
const labels = {
|
|
139
|
+
allowed: messages.allowed ?? "allowed",
|
|
140
|
+
notAllowed: messages.notAllowed ?? "not allowed",
|
|
141
|
+
denied: messages.denied ?? "denied",
|
|
142
|
+
loaded: messages.loaded ?? "loaded",
|
|
143
|
+
unloaded: messages.unloaded ?? "not loaded",
|
|
144
|
+
};
|
|
101
145
|
try {
|
|
102
146
|
const document = JSON.parse(output) as unknown;
|
|
103
147
|
if (!isRecord(document)) return {};
|
|
148
|
+
if (Object.hasOwn(document, "state")) {
|
|
149
|
+
if (!isRecord(document.state)) return {};
|
|
150
|
+
const found = isRecord(document.state.foundRC) ? document.state.foundRC : undefined;
|
|
151
|
+
const loaded = isRecord(document.state.loadedRC) ? document.state.loadedRC : undefined;
|
|
152
|
+
const path = safeMetadata(found?.path);
|
|
153
|
+
const allowed = typeof found?.allowed === "number" ? direnvAllowed(found.allowed) : undefined;
|
|
154
|
+
const loadedAllowed = loaded && typeof loaded.allowed === "number" ? direnvAllowed(loaded.allowed) : undefined;
|
|
155
|
+
if (!found || !path || !allowed || (loaded && !loadedAllowed)) return {};
|
|
156
|
+
return {
|
|
157
|
+
rc_path: path,
|
|
158
|
+
allowed: labels[allowed],
|
|
159
|
+
loaded: loadedAllowed === "allowed" ? labels.loaded : labels.unloaded,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
// Retain Pi's older top-level boolean/0-or-1 snapshot interpretation.
|
|
163
|
+
// Actual direnv JSON nests numeric 0/1/2 statuses under state (handled above).
|
|
104
164
|
const values: Record<string, string> = {};
|
|
105
165
|
const found = isRecord(document.foundRC) ? document.foundRC : undefined;
|
|
106
166
|
const loaded = isRecord(document.loadedRC) ? document.loadedRC : undefined;
|
|
107
167
|
setString(values, "rc_path", found?.path ?? loaded?.path);
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
else if (found) values.loaded = "not loaded";
|
|
168
|
+
if (found?.allowed === true || found?.allowed === 1) values.allowed = labels.allowed;
|
|
169
|
+
if (found?.allowed === false || found?.allowed === 0) values.allowed = labels.denied;
|
|
170
|
+
if (loaded) values.loaded = labels.loaded;
|
|
171
|
+
else if (found) values.loaded = labels.unloaded;
|
|
113
172
|
return values;
|
|
114
173
|
} catch {
|
|
115
|
-
const path = /^Found RC path ([^\r\n]+)$/mu.exec(output)?.[1];
|
|
116
|
-
|
|
174
|
+
const path = safeMetadata(/^Found RC path[ \t]+([^\r\n]+)$/mu.exec(output)?.[1]);
|
|
175
|
+
if (!path) return {};
|
|
176
|
+
const values: Record<string, string> = { rc_path: path };
|
|
177
|
+
const allowed = direnvAllowed(/^Found RC allowed[ \t]+([^\r\n]+)$/mu.exec(output)?.[1]);
|
|
178
|
+
if (allowed) {
|
|
179
|
+
values.allowed = labels[allowed];
|
|
180
|
+
values.loaded = output.includes("No .envrc or .env loaded") ? labels.unloaded : labels.loaded;
|
|
181
|
+
}
|
|
182
|
+
return values;
|
|
117
183
|
}
|
|
118
184
|
}
|
|
119
185
|
|
|
186
|
+
function direnvAllowed(value: unknown): "allowed" | "notAllowed" | "denied" | undefined {
|
|
187
|
+
if (value === 0 || value === "0" || value === "true") return "allowed";
|
|
188
|
+
if (value === 1 || value === "1") return "notAllowed";
|
|
189
|
+
if (value === 2 || value === "2" || value === "false") return "denied";
|
|
190
|
+
return undefined;
|
|
191
|
+
}
|
|
192
|
+
|
|
120
193
|
async function readPixiProject(context: CollectorContext): Promise<string | undefined> {
|
|
121
194
|
const source = await context.fs.readFile(join(context.input.cwd, "pixi.toml"), MAX_METADATA_FILE_BYTES);
|
|
122
195
|
if (!source) return undefined;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { sanitizeTerminalText } from "@narumitw/pi-tui-kit/terminal-text";
|
|
3
|
+
import type { CollectorContext, MutableModuleSnapshot } from "./types.js";
|
|
4
|
+
|
|
5
|
+
const PATH_VARIABLES = ["path", "full_path", "before_root_path", "repo_root"] as const;
|
|
6
|
+
|
|
7
|
+
/** Collect only requested metadata. Rendering and previews consume this cache. */
|
|
8
|
+
export async function collectDirectory(context: CollectorContext): Promise<MutableModuleSnapshot> {
|
|
9
|
+
const { input } = context;
|
|
10
|
+
if (input.signal?.aborted || !context.needs("directory")) return {};
|
|
11
|
+
const options = context.options("directory");
|
|
12
|
+
const needsPhysicalPath =
|
|
13
|
+
options.use_logical_path === false && PATH_VARIABLES.some((name) => context.needs("directory", name));
|
|
14
|
+
const needsPermission =
|
|
15
|
+
context.needs("directory", "read_only") &&
|
|
16
|
+
typeof options.read_only === "string" &&
|
|
17
|
+
sanitizeTerminalText(options.read_only).length > 0;
|
|
18
|
+
if (!needsPhysicalPath && !needsPermission) return {};
|
|
19
|
+
const values: Record<string, string> = {};
|
|
20
|
+
if (needsPhysicalPath) {
|
|
21
|
+
const path = await context.fs.realPath?.(input.cwd).catch(() => undefined);
|
|
22
|
+
if (input.signal?.aborted) return {};
|
|
23
|
+
if (typeof path === "string" && isAbsolute(path)) values.physical_path = path;
|
|
24
|
+
}
|
|
25
|
+
if (needsPermission) {
|
|
26
|
+
// fs access follows symlinks, so a permission-only format does not need a
|
|
27
|
+
// physical-path probe. Unknown permissions do not imply read-only status.
|
|
28
|
+
const writable = await context.fs.isWritable?.(input.cwd).catch(() => undefined);
|
|
29
|
+
if (input.signal?.aborted) return {};
|
|
30
|
+
if (typeof writable === "boolean") values.read_only = writable ? "false" : "true";
|
|
31
|
+
}
|
|
32
|
+
return Object.keys(values).length > 0 ? { directory: values } : {};
|
|
33
|
+
}
|
package/src/runtime/execution.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
detectEnvironment,
|
|
3
|
+
exactAlias,
|
|
4
|
+
optionBoolean,
|
|
5
|
+
optionMap,
|
|
6
|
+
optionString,
|
|
7
|
+
optionStrings,
|
|
8
|
+
safeMetadata,
|
|
9
|
+
} from "./helpers.js";
|
|
2
10
|
import { type CollectorContext, type MutableModuleSnapshot, PRIVATE_STYLE_SELECTOR } from "./types.js";
|
|
3
11
|
|
|
4
12
|
export async function collectExecution(context: CollectorContext): Promise<MutableModuleSnapshot> {
|
|
@@ -82,6 +90,8 @@ async function containerValues(context: CollectorContext): Promise<Record<string
|
|
|
82
90
|
function hostnameValues(context: CollectorContext): Record<string, string> | undefined {
|
|
83
91
|
const ssh = isSsh(context);
|
|
84
92
|
if (optionBoolean(context, "hostname", "ssh_only") && !ssh) return undefined;
|
|
93
|
+
if (!detectEnvironment(context.input.environment, optionStrings(context, "hostname", "detect_env_vars")))
|
|
94
|
+
return undefined;
|
|
85
95
|
const raw = safeMetadata(context.input.hostname);
|
|
86
96
|
if (!raw) return undefined;
|
|
87
97
|
const aliases = optionMap(context, "hostname", "aliases");
|
|
@@ -89,7 +99,7 @@ function hostnameValues(context: CollectorContext): Record<string, string> | und
|
|
|
89
99
|
const index = trimAt ? raw.indexOf(trimAt) : -1;
|
|
90
100
|
const trimmed = index >= 0 ? raw.slice(0, index) : raw;
|
|
91
101
|
const hostname = exactAlias(trimmed, aliases) ?? trimmed;
|
|
92
|
-
return { hostname, ssh_symbol: ssh ? "🌐 " : "" };
|
|
102
|
+
return { hostname, ssh_symbol: ssh ? (optionString(context, "hostname", "ssh_symbol") ?? "🌐 ") : "" };
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
function usernameValues(context: CollectorContext): Record<string, string> | undefined {
|
package/src/runtime/helpers.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { access, type FileHandle, open, opendir, realpath, stat } from "node:fs/promises";
|
|
2
3
|
import { basename, delimiter, dirname, extname, join, resolve } from "node:path";
|
|
3
4
|
import type { CollectorContext, WorkspaceEntry, WorkspaceFileSystem, WorkspaceRefreshInput } from "./types.js";
|
|
4
5
|
|
|
6
|
+
export { formatVersion } from "../format/version.js";
|
|
7
|
+
|
|
5
8
|
export const MAX_METADATA_FILE_BYTES = 64 * 1024;
|
|
6
9
|
export const COMMAND_TIMEOUT_MS = 2_000;
|
|
7
10
|
export const MAX_COMMAND_OUTPUT_BYTES = 64 * 1024;
|
|
@@ -11,15 +14,24 @@ const MAX_LABEL_LENGTH = 160;
|
|
|
11
14
|
export function createFileSystem(input: WorkspaceRefreshInput): WorkspaceFileSystem {
|
|
12
15
|
const defaults: WorkspaceFileSystem = {
|
|
13
16
|
async readFile(path, maxBytes) {
|
|
17
|
+
if (input.signal?.aborted) return undefined;
|
|
14
18
|
let handle: FileHandle | undefined;
|
|
15
19
|
try {
|
|
16
20
|
handle = await open(path, "r");
|
|
17
21
|
const info = await handle.stat();
|
|
18
22
|
if (!info.isFile() || info.size > maxBytes) return undefined;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
// procfs can report zero bytes and sysfs can report a nominal page size.
|
|
24
|
+
// Read through EOF, not stat.size, while keeping one overflow byte.
|
|
25
|
+
const buffer = Buffer.alloc(maxBytes + 1);
|
|
26
|
+
let offset = 0;
|
|
27
|
+
while (offset < buffer.length) {
|
|
28
|
+
if (input.signal?.aborted) return undefined;
|
|
29
|
+
const { bytesRead } = await handle.read(buffer, offset, buffer.length - offset, null);
|
|
30
|
+
if (bytesRead === 0) break;
|
|
31
|
+
offset += bytesRead;
|
|
32
|
+
}
|
|
33
|
+
if (input.signal?.aborted || offset > maxBytes) return undefined;
|
|
34
|
+
return buffer.subarray(0, offset).toString("utf8");
|
|
23
35
|
} catch {
|
|
24
36
|
return undefined;
|
|
25
37
|
} finally {
|
|
@@ -27,10 +39,12 @@ export function createFileSystem(input: WorkspaceRefreshInput): WorkspaceFileSys
|
|
|
27
39
|
}
|
|
28
40
|
},
|
|
29
41
|
async readDirectory(path) {
|
|
42
|
+
if (input.signal?.aborted) return [];
|
|
30
43
|
const entries: WorkspaceEntry[] = [];
|
|
31
44
|
try {
|
|
32
45
|
const directory = await opendir(path);
|
|
33
46
|
for await (const entry of directory) {
|
|
47
|
+
if (input.signal?.aborted) break;
|
|
34
48
|
entries.push({
|
|
35
49
|
name: entry.name,
|
|
36
50
|
isFile: entry.isFile(),
|
|
@@ -51,6 +65,22 @@ export function createFileSystem(input: WorkspaceRefreshInput): WorkspaceFileSys
|
|
|
51
65
|
return false;
|
|
52
66
|
}
|
|
53
67
|
},
|
|
68
|
+
async realPath(path) {
|
|
69
|
+
try {
|
|
70
|
+
return await realpath(path);
|
|
71
|
+
} catch {
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
async isWritable(path) {
|
|
76
|
+
try {
|
|
77
|
+
await access(path, constants.W_OK);
|
|
78
|
+
return true;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
const code = isRecord(error) ? error.code : undefined;
|
|
81
|
+
return code === "EACCES" || code === "EPERM" || code === "EROFS" ? false : undefined;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
54
84
|
};
|
|
55
85
|
return {
|
|
56
86
|
...defaults,
|
|
@@ -140,8 +170,26 @@ export function exactAlias(value: string | undefined, aliases: Readonly<Record<s
|
|
|
140
170
|
return Object.hasOwn(aliases, value) ? safeMetadata(aliases[value]) : value;
|
|
141
171
|
}
|
|
142
172
|
|
|
143
|
-
|
|
144
|
-
|
|
173
|
+
/** Empty values count as present, as in Starship's Context::detect_env_vars. */
|
|
174
|
+
export function detectEnvironment(
|
|
175
|
+
environment: Readonly<Record<string, string | undefined>>,
|
|
176
|
+
names: readonly string[],
|
|
177
|
+
): boolean {
|
|
178
|
+
if (names.length === 0) return true;
|
|
179
|
+
let hasPositive = false;
|
|
180
|
+
let positiveMatch = false;
|
|
181
|
+
for (const name of names) {
|
|
182
|
+
const negative = name.startsWith("!");
|
|
183
|
+
const key = negative ? name.slice(1) : name;
|
|
184
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/u.test(key)) return false;
|
|
185
|
+
const present = Object.hasOwn(environment, key) && typeof environment[key] === "string";
|
|
186
|
+
if (negative && present) return false;
|
|
187
|
+
if (!negative) {
|
|
188
|
+
hasPositive = true;
|
|
189
|
+
positiveMatch ||= present;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return !hasPositive || positiveMatch;
|
|
145
193
|
}
|
|
146
194
|
|
|
147
195
|
export async function runBounded(
|
|
@@ -149,6 +197,7 @@ export async function runBounded(
|
|
|
149
197
|
command: string,
|
|
150
198
|
args: string[],
|
|
151
199
|
): Promise<string | undefined> {
|
|
200
|
+
if (context.input.signal?.aborted) return undefined;
|
|
152
201
|
try {
|
|
153
202
|
const result = await context.input.exec(command, args, {
|
|
154
203
|
cwd: context.input.cwd,
|
|
@@ -157,7 +206,7 @@ export async function runBounded(
|
|
|
157
206
|
signal: context.input.signal,
|
|
158
207
|
environment: context.input.environment,
|
|
159
208
|
});
|
|
160
|
-
if (result.code !== 0 || result.killed) return undefined;
|
|
209
|
+
if (context.input.signal?.aborted || result.code !== 0 || result.killed) return undefined;
|
|
161
210
|
const selectedOutput = result.stdout || result.stderr;
|
|
162
211
|
const output = Buffer.from(selectedOutput).subarray(0, MAX_COMMAND_OUTPUT_BYTES + 1);
|
|
163
212
|
if (output.byteLength > MAX_COMMAND_OUTPUT_BYTES) return undefined;
|