@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.
Files changed (115) hide show
  1. package/README.md +67 -9
  2. package/dist/chunks/chunk-63R6R5DH.ts +679 -0
  3. package/dist/chunks/chunk-63R6R5DH.ts.map +7 -0
  4. package/dist/chunks/{chunk-KZZKGGFW.ts → chunk-A65IOGL6.ts} +858 -1007
  5. package/dist/chunks/chunk-A65IOGL6.ts.map +7 -0
  6. package/dist/chunks/chunk-IYDZ3R2T.ts +69 -0
  7. package/dist/chunks/chunk-IYDZ3R2T.ts.map +7 -0
  8. package/dist/chunks/chunk-KP33I6BR.ts +579 -0
  9. package/dist/chunks/chunk-KP33I6BR.ts.map +7 -0
  10. package/dist/chunks/{chunk-PD457PX5.ts → chunk-S2KBLHE2.ts} +75 -10
  11. package/dist/chunks/chunk-S2KBLHE2.ts.map +7 -0
  12. package/dist/chunks/chunk-XQUIQO2G.ts +20 -0
  13. package/dist/chunks/chunk-XQUIQO2G.ts.map +7 -0
  14. package/dist/chunks/{chunk-ADX4CY27.ts → chunk-XTLQ4WUL.ts} +1 -1
  15. package/dist/chunks/chunk-XTLQ4WUL.ts.map +7 -0
  16. package/dist/chunks/chunk-Y24TJYG6.ts +1586 -0
  17. package/dist/chunks/chunk-Y24TJYG6.ts.map +7 -0
  18. package/dist/chunks/{cloud-EPAEV4ZB.ts → cloud-J2ZOE3HE.ts} +6 -2
  19. package/dist/chunks/cloud-J2ZOE3HE.ts.map +7 -0
  20. package/dist/chunks/command-configuration-menu-YOLN2SPR.ts +147 -0
  21. package/dist/chunks/command-configuration-menu-YOLN2SPR.ts.map +7 -0
  22. package/dist/chunks/command-settings-chat-5AHP3JGV.ts +1124 -0
  23. package/dist/chunks/command-settings-chat-5AHP3JGV.ts.map +7 -0
  24. package/dist/chunks/commands-IOG2PL67.ts +1026 -0
  25. package/dist/chunks/commands-IOG2PL67.ts.map +7 -0
  26. package/dist/chunks/{deployment-7J54EHNR.ts → deployment-NOJ2KCLI.ts} +85 -5
  27. package/dist/chunks/deployment-NOJ2KCLI.ts.map +7 -0
  28. package/dist/chunks/{development-IWJAAAEV.ts → development-T3XXVVDP.ts} +67 -15
  29. package/dist/chunks/development-T3XXVVDP.ts.map +7 -0
  30. package/dist/chunks/directory-OX6BWJZA.ts +31 -0
  31. package/dist/chunks/directory-OX6BWJZA.ts.map +7 -0
  32. package/dist/chunks/{execution-P4WZALW2.ts → execution-R2OHIP2L.ts} +8 -4
  33. package/dist/chunks/execution-R2OHIP2L.ts.map +7 -0
  34. package/dist/chunks/jujutsu-XLDYKSX2.ts +174 -0
  35. package/dist/chunks/jujutsu-XLDYKSX2.ts.map +7 -0
  36. package/dist/chunks/languages-CBQNNYXM.ts +262 -0
  37. package/dist/chunks/languages-CBQNNYXM.ts.map +7 -0
  38. package/dist/chunks/{package-H24VJEX3.ts → package-7KVAK3TC.ts} +6 -2
  39. package/dist/chunks/package-7KVAK3TC.ts.map +7 -0
  40. package/dist/chunks/system-574MHB4R.ts +165 -0
  41. package/dist/chunks/system-574MHB4R.ts.map +7 -0
  42. package/dist/index.ts +670 -206
  43. package/dist/index.ts.map +4 -4
  44. package/package.json +5 -1
  45. package/skills/configure-pi-starship/SKILL.md +17 -1
  46. package/skills/configure-pi-starship/references/configuration.md +119 -32
  47. package/skills/configure-pi-starship/references/module-catalog.md +278 -25
  48. package/skills/configure-pi-starship/references/modules.md +213 -36
  49. package/skills/configure-pi-starship/references/runtime-and-security.md +88 -28
  50. package/src/command-commit.ts +41 -7
  51. package/src/command-configuration-menu.ts +155 -0
  52. package/src/command-configuration.ts +15 -94
  53. package/src/command-preview.ts +3 -3
  54. package/src/command-settings-chat.ts +168 -0
  55. package/src/commands.ts +76 -124
  56. package/src/config/module-options.ts +112 -0
  57. package/src/config.ts +23 -59
  58. package/src/effective-config.ts +5 -4
  59. package/src/format/bounded-regex.ts +66 -0
  60. package/src/format/version.ts +24 -0
  61. package/src/modules/catalog.ts +10 -0
  62. package/src/modules/cloud.ts +1 -0
  63. package/src/modules/deployment.ts +8 -0
  64. package/src/modules/development.ts +20 -2
  65. package/src/modules/directory.ts +171 -51
  66. package/src/modules/execution.ts +2 -0
  67. package/src/modules/git/branch.ts +19 -4
  68. package/src/modules/git/commit.ts +9 -2
  69. package/src/modules/git/metrics.ts +9 -4
  70. package/src/modules/git/runtime.ts +122 -33
  71. package/src/modules/git/state.ts +23 -2
  72. package/src/modules/git/status-templates.ts +58 -0
  73. package/src/modules/git/status.ts +96 -30
  74. package/src/modules/jujutsu.ts +225 -0
  75. package/src/modules/languages.ts +26 -2
  76. package/src/modules/package.ts +1 -0
  77. package/src/modules/render.ts +42 -16
  78. package/src/modules/system.ts +54 -0
  79. package/src/modules/time-format.ts +188 -0
  80. package/src/modules/time.ts +11 -5
  81. package/src/modules/types.ts +42 -4
  82. package/src/pi-starship.ts +198 -88
  83. package/src/profile-store.ts +5 -0
  84. package/src/runtime/cloud.ts +3 -0
  85. package/src/runtime/command.ts +1 -1
  86. package/src/runtime/deployment.ts +120 -4
  87. package/src/runtime/development.ts +86 -13
  88. package/src/runtime/directory.ts +33 -0
  89. package/src/runtime/execution.ts +12 -2
  90. package/src/runtime/helpers.ts +57 -8
  91. package/src/runtime/jujutsu.ts +225 -0
  92. package/src/runtime/languages.ts +106 -19
  93. package/src/runtime/package.ts +3 -0
  94. package/src/runtime/system.ts +202 -0
  95. package/src/runtime/types.ts +3 -0
  96. package/src/runtime/version-requirements.ts +30 -0
  97. package/src/runtime/workspace.ts +12 -1
  98. package/src/settings-agent.ts +80 -0
  99. package/src/settings-chat-transcript.ts +192 -0
  100. package/src/settings-chat-ui.ts +526 -0
  101. package/src/settings-draft.ts +260 -0
  102. package/src/settings-snapshots.ts +41 -0
  103. package/dist/chunks/chunk-ADX4CY27.ts.map +0 -7
  104. package/dist/chunks/chunk-KZZKGGFW.ts.map +0 -7
  105. package/dist/chunks/chunk-PD457PX5.ts.map +0 -7
  106. package/dist/chunks/cloud-EPAEV4ZB.ts.map +0 -7
  107. package/dist/chunks/commands-C2VJ6ZBN.ts +0 -3374
  108. package/dist/chunks/commands-C2VJ6ZBN.ts.map +0 -7
  109. package/dist/chunks/deployment-7J54EHNR.ts.map +0 -7
  110. package/dist/chunks/development-IWJAAAEV.ts.map +0 -7
  111. package/dist/chunks/execution-P4WZALW2.ts.map +0 -7
  112. package/dist/chunks/languages-JO6R2PHL.ts +0 -168
  113. package/dist/chunks/languages-JO6R2PHL.ts.map +0 -7
  114. package/dist/chunks/package-H24VJEX3.ts.map +0 -7
  115. package/src/command-inspector.ts +0 -41
@@ -0,0 +1,260 @@
1
+ import {
2
+ closeSync,
3
+ constants,
4
+ fstatSync,
5
+ ftruncateSync,
6
+ mkdtempSync,
7
+ openSync,
8
+ readFileSync,
9
+ realpathSync,
10
+ rmSync,
11
+ writeFileSync,
12
+ } from "node:fs";
13
+ import { tmpdir } from "node:os";
14
+ import { isAbsolute, join, relative, resolve } from "node:path";
15
+ import {
16
+ createEditTool,
17
+ createReadTool,
18
+ createWriteTool,
19
+ truncateHead,
20
+ withFileMutationQueue,
21
+ } from "@earendil-works/pi-coding-agent";
22
+ import { BUILT_IN_EXAMPLE, type LoadedStarshipConfig, validateConfigDocument } from "./config.js";
23
+ import type { settingsSnapshots } from "./settings-snapshots.js";
24
+
25
+ const MAX_DRAFT_BYTES = 64 * 1024;
26
+
27
+ export interface SettingsDraftOptions {
28
+ settingsPath: string;
29
+ baseline: Buffer | undefined;
30
+ packageRoot: string;
31
+ snapshots?: ReturnType<typeof settingsSnapshots>;
32
+ isCurrent(): boolean;
33
+ onPreview(loaded: LoadedStarshipConfig): void;
34
+ }
35
+
36
+ /** Private file tools; the active settings path is only an immutable read snapshot. */
37
+ export function createSettingsDraft(options: SettingsDraftOptions) {
38
+ if (options.baseline && options.baseline.length > MAX_DRAFT_BYTES)
39
+ throw new Error("The settings draft exceeds 64 KiB");
40
+ const roots = ["skills/configure-pi-starship", "src"].map((part) => realpathSync(join(options.packageRoot, part)));
41
+ const directory = realpathSync(mkdtempSync(join(tmpdir(), "pi-starship-draft-")));
42
+ const path = join(directory, "pi-starship.toml");
43
+ const baseline = options.baseline && Buffer.from(options.baseline);
44
+ const snapshots = new Map(
45
+ Object.entries(options.snapshots ?? {}).map(([name, content]) => [join(directory, name), content]),
46
+ );
47
+ const snapshotPaths = [...snapshots.keys()];
48
+ let disposed = false;
49
+ let removed = false;
50
+ let revision = 0;
51
+ let valid: LoadedStarshipConfig | undefined;
52
+ let diagnostics = "";
53
+ const assertCurrent = () => {
54
+ if (disposed || !options.isCurrent()) throw new Error("The settings draft owner is no longer active");
55
+ };
56
+ const assertDraft = (target: string) => {
57
+ assertCurrent();
58
+ if (resolve(target) !== path || realpathSync(directory) !== directory || realpathSync(path) !== path) {
59
+ throw new Error("Only the owned settings draft can be changed");
60
+ }
61
+ };
62
+ const readDraft = () => {
63
+ assertDraft(path);
64
+ const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
65
+ try {
66
+ const stat = fstatSync(fd);
67
+ if (!stat.isFile() || stat.nlink !== 1 || stat.size > MAX_DRAFT_BYTES)
68
+ throw new Error("The owned draft is not a private regular file up to 64 KiB");
69
+ return readFileSync(fd);
70
+ } finally {
71
+ closeSync(fd);
72
+ }
73
+ };
74
+ const validate = (publish = true) => {
75
+ valid = undefined;
76
+ let candidate: LoadedStarshipConfig;
77
+ try {
78
+ candidate = validateConfigDocument(options.settingsPath, readDraft().toString("utf8"));
79
+ } catch (error) {
80
+ diagnostics = error instanceof Error ? error.message : String(error);
81
+ return;
82
+ }
83
+ diagnostics = candidate.diagnostics.map((item) => `${item.severity}: ${item.path}: ${item.message}`).join("\n");
84
+ if (publish) options.onPreview(candidate);
85
+ valid = candidate;
86
+ };
87
+ try {
88
+ writeFileSync(path, baseline ?? BUILT_IN_EXAMPLE, { mode: 0o600, flag: "wx" });
89
+ validate(false);
90
+ } catch (error) {
91
+ try {
92
+ rmSync(directory, { recursive: true, force: true });
93
+ } catch (cleanupError) {
94
+ throw new AggregateError(
95
+ [error, cleanupError],
96
+ `Settings draft initialization and cleanup failed at ${directory}`,
97
+ );
98
+ }
99
+ throw error;
100
+ }
101
+ const readAllowed = (target: string): Buffer => {
102
+ assertCurrent();
103
+ if (resolve(target) === resolve(options.settingsPath)) {
104
+ if (!baseline) throw new Error("The active settings file was missing when this preview started");
105
+ return Buffer.from(baseline);
106
+ }
107
+ if (resolve(target) === path) return readDraft();
108
+ if (snapshots.has(resolve(target))) {
109
+ const content = snapshots.get(resolve(target));
110
+ if (content === undefined)
111
+ throw new Error(
112
+ "No exact loaded settings document is available; read active-state.json for its source and diagnostics",
113
+ );
114
+ return Buffer.from(content);
115
+ }
116
+ const canonical = realpathSync(target);
117
+ if (
118
+ !roots.some((root) => {
119
+ const child = relative(root, canonical);
120
+ return (
121
+ child !== "" &&
122
+ child !== ".." &&
123
+ !child.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) &&
124
+ !isAbsolute(child)
125
+ );
126
+ })
127
+ )
128
+ throw new Error("Read access is limited to the settings snapshot, draft, and bundled configuration documents");
129
+ const fd = openSync(canonical, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
130
+ try {
131
+ const stat = fstatSync(fd);
132
+ if (!stat.isFile() || stat.size > 1024 * 1024)
133
+ throw new Error("Only bundled text documents up to 1 MiB can be read");
134
+ return readFileSync(fd);
135
+ } finally {
136
+ closeSync(fd);
137
+ }
138
+ };
139
+ const writeDraft = async (target: string, text: string) => {
140
+ assertDraft(target);
141
+ if (Buffer.byteLength(text) > MAX_DRAFT_BYTES) throw new Error("The settings draft exceeds 64 KiB");
142
+ const fd = openSync(path, constants.O_WRONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
143
+ try {
144
+ const stat = fstatSync(fd);
145
+ if (!stat.isFile() || stat.nlink !== 1) throw new Error("The owned draft is not a private regular file");
146
+ // Keep validation and preview in the core tool's mutation queue, without an await boundary.
147
+ valid = undefined;
148
+ ftruncateSync(fd, 0);
149
+ writeFileSync(fd, text);
150
+ } catch (error) {
151
+ diagnostics = error instanceof Error ? error.message : String(error);
152
+ throw error;
153
+ } finally {
154
+ closeSync(fd);
155
+ }
156
+ revision += 1;
157
+ validate();
158
+ if (!valid)
159
+ throw new Error(
160
+ `Draft saved but preview rejected; repair the draft. ${truncateHead(diagnostics, { maxBytes: 48 * 1024, maxLines: 1900 }).content}`,
161
+ );
162
+ };
163
+ const read = createReadTool(directory, {
164
+ operations: {
165
+ access: async (target) => {
166
+ readAllowed(target);
167
+ },
168
+ readFile: async (target) => readAllowed(target),
169
+ },
170
+ });
171
+ const write = createWriteTool(directory, {
172
+ operations: {
173
+ mkdir: async (target) => {
174
+ assertCurrent();
175
+ if (target !== directory) throw new Error("Only the draft directory is writable");
176
+ },
177
+ writeFile: writeDraft,
178
+ },
179
+ });
180
+ const edit = createEditTool(directory, {
181
+ operations: {
182
+ access: async (target) => assertDraft(target),
183
+ readFile: async (target) => {
184
+ assertDraft(target);
185
+ return readDraft();
186
+ },
187
+ writeFile: writeDraft,
188
+ },
189
+ });
190
+ read.description =
191
+ "Read text from immutable disk/active configuration and module snapshots, the owned draft, or bundled configuration skill/source documents. Output is limited to 50 KiB or 2,000 lines; use offset and limit to continue.";
192
+ write.description =
193
+ "Replace only the owned pi-starship TOML draft, up to 64 KiB. The host validates and previews it. Invalid text stays in the draft and returns an error for repair. Never writes the active settings file.";
194
+ edit.description +=
195
+ " Only the owned pi-starship TOML draft is editable. The host validates and previews the result; invalid text stays in the draft for repair. Never changes active settings.";
196
+ // The outer queue includes reads and result diagnostics. Core mutators retain their
197
+ // own file-path queue; a distinct directory key avoids recursive queue admission.
198
+ const ordered = <T>(operation: () => Promise<T>) =>
199
+ withFileMutationQueue(directory, async () => {
200
+ assertCurrent();
201
+ const result = await operation();
202
+ assertCurrent();
203
+ return result;
204
+ });
205
+ const readExecute = read.execute.bind(read);
206
+ read.execute = (...args) => ordered(() => readExecute(...args));
207
+ const warningResult = async <T extends { content: Awaited<ReturnType<typeof read.execute>>["content"] }>(
208
+ operation: Promise<T>,
209
+ ): Promise<T> => {
210
+ const result = await operation;
211
+ assertCurrent();
212
+ return {
213
+ ...result,
214
+ content: [
215
+ ...result.content,
216
+ {
217
+ type: "text" as const,
218
+ text: truncateHead(`Draft validated. Preview updated; active settings unchanged.\n${diagnostics}`, {
219
+ maxBytes: 48 * 1024,
220
+ maxLines: 1900,
221
+ }).content,
222
+ },
223
+ ],
224
+ };
225
+ };
226
+ const writeExecute = write.execute.bind(write);
227
+ write.execute = (...args) => ordered(() => warningResult(writeExecute(...args)));
228
+ const editExecute = edit.execute.bind(edit);
229
+ edit.execute = (...args) => ordered(() => warningResult(editExecute(...args)));
230
+ return {
231
+ directory,
232
+ path,
233
+ snapshotPaths,
234
+ tools: [read, write, edit] as [typeof read, typeof write, typeof edit],
235
+ get revision() {
236
+ return revision;
237
+ },
238
+ get candidate() {
239
+ return valid;
240
+ },
241
+ get rawDocument() {
242
+ return readDraft().toString("utf8");
243
+ },
244
+ get diagnostics() {
245
+ return diagnostics;
246
+ },
247
+ assertRevision(expected: number) {
248
+ assertCurrent();
249
+ if (revision !== expected || !valid || valid.rawDocument !== readDraft().toString("utf8"))
250
+ throw new Error("The settings draft changed after review");
251
+ },
252
+ dispose() {
253
+ disposed = true;
254
+ if (removed) return;
255
+ rmSync(directory, { recursive: true, force: true });
256
+ removed = true;
257
+ },
258
+ };
259
+ }
260
+ export type SettingsDraft = ReturnType<typeof createSettingsDraft>;
@@ -0,0 +1,41 @@
1
+ import { configurationPresentation } from "./command-configuration.js";
2
+ import type { LoadedStarshipConfig } from "./config.js";
3
+ import { serializeEffectiveConfig } from "./effective-config.js";
4
+ import type { StatuslineInspection } from "./modules/inspection.js";
5
+
6
+ /** Serialize once at chat opening; neither draft previews nor later runtime changes update these documents. */
7
+ export function settingsSnapshots(
8
+ loaded: LoadedStarshipConfig,
9
+ settingsPath: string,
10
+ inspection: StatuslineInspection | undefined,
11
+ ) {
12
+ const presentation = configurationPresentation(loaded);
13
+ return {
14
+ "active-document.toml": loaded.rawDocument,
15
+ "active-effective.toml": serializeEffectiveConfig(loaded.config),
16
+ "active-state.json": JSON.stringify(
17
+ {
18
+ snapshot: "Active configuration at chat opening; not the draft or a continuously current view",
19
+ state: presentation.state,
20
+ source: presentation.source,
21
+ path: settingsPath,
22
+ health: presentation.health,
23
+ loadedDocumentAvailable: loaded.rawDocument !== undefined,
24
+ diagnostics: loaded.diagnostics,
25
+ },
26
+ null,
27
+ 2,
28
+ ),
29
+ "active-modules.json": JSON.stringify(
30
+ {
31
+ snapshot: "Module inspection at chat opening; draft previews do not change this snapshot",
32
+ available: inspection !== undefined,
33
+ ...(inspection
34
+ ? { inspection }
35
+ : { reason: "Runtime inspection unavailable: the footer is not ready. Do not infer live module states." }),
36
+ },
37
+ null,
38
+ 2,
39
+ ),
40
+ };
41
+ }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/runtime/types.ts"],
4
- "sourcesContent": ["import type { StarshipConfig } from \"../config.js\";\nimport type { ModuleName } from \"../modules/catalog.js\";\nimport type { WorkspaceSnapshot } from \"../modules/types.js\";\n\nexport interface WorkspaceExecResult {\n stdout: string;\n stderr: string;\n code: number;\n killed: boolean;\n}\n\nexport type WorkspaceExec = (\n command: string,\n args: string[],\n options: {\n cwd: string;\n timeout: number;\n maxOutputBytes: number;\n signal?: AbortSignal;\n environment: Readonly<Record<string, string | undefined>>;\n },\n) => Promise<WorkspaceExecResult>;\n\nexport interface WorkspaceEntry {\n name: string;\n isFile: boolean;\n isDirectory: boolean;\n}\n\nexport interface WorkspaceFileSystem {\n readFile(path: string, maxBytes: number): Promise<string | undefined>;\n readDirectory(path: string): Promise<readonly WorkspaceEntry[]>;\n fileExists(path: string): Promise<boolean>;\n}\n\nexport interface WorkspaceRefreshInput {\n cwd: string;\n config: StarshipConfig;\n environment: Readonly<Record<string, string | undefined>>;\n homeDir: string;\n platform: NodeJS.Platform;\n hostname: string;\n username: string;\n exec: WorkspaceExec;\n fileSystem?: Partial<WorkspaceFileSystem>;\n fileExists?(path: string): Promise<boolean>;\n reason?: \"initial\" | \"event\" | \"periodic\";\n previous?: WorkspaceSnapshot;\n signal?: AbortSignal;\n}\n\nexport interface CollectorContext {\n input: WorkspaceRefreshInput;\n fs: WorkspaceFileSystem;\n requirements: ReadonlyMap<ModuleName, ReadonlySet<string>>;\n entries(): Promise<readonly WorkspaceEntry[]>;\n options(name: ModuleName): Readonly<Record<string, unknown>>;\n needs(name: ModuleName, variable?: string): boolean;\n}\n\nexport const PRIVATE_STYLE_SELECTOR = \"__pi_style_selector\";\n\nexport type MutableModuleSnapshot = Record<string, Record<string, string>>;\n"],
5
- "mappings": ";;;;AA4DO,IAAM,yBAAyB;",
6
- "names": []
7
- }