@pi-vault/pi-status 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lanh Hoang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # @pi-vault/pi-status
2
+
3
+ [![npm version](https://img.shields.io/npm/v/%40pi-vault%2Fpi-status)](https://www.npmjs.com/package/@pi-vault/pi-status)
4
+ [![Quality](https://github.com/pi-vault/pi-status/actions/workflows/quality.yml/badge.svg?branch=master)](https://github.com/pi-vault/pi-status/actions/workflows/quality.yml)
5
+ [![Node >= 22.12](https://img.shields.io/badge/node-%3E%3D22.12-339933?logo=node.js&logoColor=white)](https://nodejs.org/)
6
+ [![License: MIT](https://img.shields.io/badge/license-MIT-yellow.svg)](LICENSE)
7
+
8
+ Replace Pi's default footer with a cleaner Codex-style status line that stays out of the way but keeps the useful bits visible.
9
+
10
+ Default status line:
11
+
12
+ `model-with-reasoning · current-dir`
13
+
14
+ > **Status:** Early-adopter release (`v0.1.0`). It is ready to use, but the available segments and configuration details may still change before `v1.0`.
15
+
16
+ ## Install
17
+
18
+ ```bash
19
+ pi install npm:@pi-vault/pi-status
20
+ ```
21
+
22
+ Then reload Pi:
23
+
24
+ ```bash
25
+ /reload
26
+ ```
27
+
28
+ ## Use
29
+
30
+ Once installed, the footer updates automatically.
31
+
32
+ Use `/statusline` inside Pi to:
33
+
34
+ - turn footer items on or off
35
+ - reorder the items you want to see
36
+ - preview the result before saving
37
+ - control which extension status messages are shown
38
+
39
+ Changes are saved and reused the next time Pi starts.
40
+
41
+ ## Available Status Items
42
+
43
+ You can build your footer from these items:
44
+
45
+ - `model`
46
+ - `model-with-reasoning`
47
+ - `project-name`
48
+ - `current-dir`
49
+ - `git-branch`
50
+ - `run-state`
51
+ - `context-remaining`
52
+ - `context-used`
53
+ - `context-window-size`
54
+ - `used-tokens`
55
+ - `total-input-tokens`
56
+ - `total-output-tokens`
57
+ - `session-id`
58
+ - `five-hour-limit`
59
+ - `weekly-limit`
60
+ - `extension-statuses`
61
+
62
+ `five-hour-limit` and `weekly-limit` come from [`@pi-vault/pi-usage`](https://www.npmjs.com/package/@pi-vault/pi-usage) and only appear when that usage data is available.
63
+
64
+ ## Common Setups
65
+
66
+ Keep it minimal:
67
+
68
+ ```text
69
+ model-with-reasoning · current-dir
70
+ ```
71
+
72
+ Show more session detail:
73
+
74
+ ```text
75
+ model · run-state · git-branch · context-used · context-remaining · session-id
76
+ ```
77
+
78
+ ## Compatibility
79
+
80
+ - Node.js `>=22.12`
81
+ - Pi host environment with `@earendil-works/pi-coding-agent` and `@earendil-works/pi-tui`
82
+ - Tested in this repo against `@earendil-works/pi-coding-agent@0.78.x` and `@earendil-works/pi-tui@0.78.x`
83
+
84
+ ## Development Setup
85
+
86
+ ```bash
87
+ pnpm install
88
+ pnpm check
89
+ pnpm pack --dry-run
90
+ pi -e .
91
+ ```
92
+
93
+ ## License
94
+
95
+ MIT
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@pi-vault/pi-status",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Pi extension that replaces the default status with a Codex-like status",
6
+ "author": "Lanh Hoang <lanhhoang@users.noreply.github.com>",
7
+ "license": "MIT",
8
+ "homepage": "https://github.com/pi-vault/pi-status#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/pi-vault/pi-status.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/pi-vault/pi-status/issues"
15
+ },
16
+ "keywords": [
17
+ "pi",
18
+ "pi-package",
19
+ "pi-extension",
20
+ "pi-status"
21
+ ],
22
+ "scripts": {
23
+ "format": "biome format --write .",
24
+ "lint": "biome lint .",
25
+ "typecheck": "tsc --noEmit",
26
+ "test": "vitest run",
27
+ "check": "biome lint . && tsc --noEmit && vitest run",
28
+ "pack:dry-run": "pnpm pack --dry-run"
29
+ },
30
+ "pi": {
31
+ "extensions": [
32
+ "./src/index.ts",
33
+ "node_modules/@pi-vault/pi-usage/src/index.ts"
34
+ ]
35
+ },
36
+ "engines": {
37
+ "node": ">=22.12"
38
+ },
39
+ "files": [
40
+ "src",
41
+ "README.md"
42
+ ],
43
+ "dependencies": {
44
+ "@pi-vault/pi-usage": "^0.1.1"
45
+ },
46
+ "peerDependencies": {
47
+ "@earendil-works/pi-coding-agent": "*",
48
+ "@earendil-works/pi-tui": "*"
49
+ },
50
+ "devDependencies": {
51
+ "@biomejs/biome": "^2.4.16",
52
+ "@earendil-works/pi-coding-agent": "^0.78.0",
53
+ "@earendil-works/pi-tui": "^0.78.0",
54
+ "@types/node": "^25.9.1",
55
+ "typescript": "^6.0.3",
56
+ "vitest": "^4.1.7"
57
+ }
58
+ }
package/src/config.ts ADDED
@@ -0,0 +1,272 @@
1
+ import {
2
+ mkdirSync,
3
+ mkdtempSync,
4
+ existsSync,
5
+ readFileSync,
6
+ renameSync,
7
+ rmSync,
8
+ writeFileSync,
9
+ } from "node:fs";
10
+ import { homedir } from "node:os";
11
+ import { dirname, join, resolve } from "node:path";
12
+ import {
13
+ DEFAULT_SEGMENTS,
14
+ type StatusFilter,
15
+ type StatusLineSegmentId,
16
+ } from "./render.ts";
17
+
18
+ export type PiStatusConfig = {
19
+ segments: StatusLineSegmentId[];
20
+ filter: StatusFilter;
21
+ };
22
+
23
+ export type ConfigLoadResult = {
24
+ config: PiStatusConfig;
25
+ source: "settings" | "default";
26
+ };
27
+
28
+ export const DEFAULT_CONFIG: PiStatusConfig = {
29
+ segments: [...DEFAULT_SEGMENTS],
30
+ filter: { mode: "all", hidden: [] },
31
+ };
32
+
33
+ const KNOWN_SEGMENTS = new Set<StatusLineSegmentId>([
34
+ "model",
35
+ "model-with-reasoning",
36
+ "project-name",
37
+ "current-dir",
38
+ "git-branch",
39
+ "run-state",
40
+ "context-remaining",
41
+ "context-used",
42
+ "context-window-size",
43
+ "used-tokens",
44
+ "total-input-tokens",
45
+ "total-output-tokens",
46
+ "session-id",
47
+ "five-hour-limit",
48
+ "weekly-limit",
49
+ "extension-statuses",
50
+ ]);
51
+
52
+ function cloneDefaultConfig(): PiStatusConfig {
53
+ return {
54
+ segments: [...DEFAULT_CONFIG.segments],
55
+ filter:
56
+ DEFAULT_CONFIG.filter.mode === "all"
57
+ ? { mode: "all", hidden: [...DEFAULT_CONFIG.filter.hidden] }
58
+ : { mode: "only", shown: [...DEFAULT_CONFIG.filter.shown] },
59
+ };
60
+ }
61
+
62
+ export function getSettingsPaths(cwd = process.cwd()): {
63
+ global: string;
64
+ project: string;
65
+ } {
66
+ return {
67
+ global: resolve(homedir(), ".pi/agent/settings.json"),
68
+ project: resolve(cwd, ".pi/settings.json"),
69
+ };
70
+ }
71
+
72
+ export function normalizeSegments(input: unknown): StatusLineSegmentId[] {
73
+ if (!Array.isArray(input)) return [...DEFAULT_SEGMENTS];
74
+ const out: StatusLineSegmentId[] = [];
75
+ const seen = new Set<StatusLineSegmentId>();
76
+
77
+ for (const value of input) {
78
+ if (typeof value !== "string") continue;
79
+ if (!KNOWN_SEGMENTS.has(value as StatusLineSegmentId)) continue;
80
+ const id = value as StatusLineSegmentId;
81
+ if (seen.has(id)) continue;
82
+ seen.add(id);
83
+ out.push(id);
84
+ }
85
+
86
+ return out;
87
+ }
88
+
89
+ function normalizeFilterValues(input: unknown): string[] {
90
+ if (!Array.isArray(input)) return [];
91
+ const out: string[] = [];
92
+ const seen = new Set<string>();
93
+
94
+ for (const value of input) {
95
+ if (typeof value !== "string") continue;
96
+ if (value.length === 0) continue;
97
+ if (seen.has(value)) continue;
98
+ seen.add(value);
99
+ out.push(value);
100
+ }
101
+
102
+ return out;
103
+ }
104
+
105
+ export function normalizeStatusFilter(input: unknown): StatusFilter {
106
+ if (!input || typeof input !== "object" || Array.isArray(input))
107
+ return { mode: "all", hidden: [] };
108
+ const mode = (input as { mode?: unknown }).mode;
109
+
110
+ if (mode === "all") {
111
+ return {
112
+ mode: "all",
113
+ hidden: normalizeFilterValues((input as { hidden?: unknown }).hidden),
114
+ };
115
+ }
116
+
117
+ if (mode === "only") {
118
+ return {
119
+ mode: "only",
120
+ shown: normalizeFilterValues((input as { shown?: unknown }).shown),
121
+ };
122
+ }
123
+
124
+ return { mode: "all", hidden: [] };
125
+ }
126
+
127
+ function readJsonObject(path: string): Record<string, unknown> | null {
128
+ try {
129
+ const parsed: unknown = JSON.parse(readFileSync(path, "utf8"));
130
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
131
+ return null;
132
+ return parsed as Record<string, unknown>;
133
+ } catch {
134
+ return null;
135
+ }
136
+ }
137
+
138
+ type SettingsFileState =
139
+ | { exists: false; value: Record<string, never> }
140
+ | { exists: true; value: Record<string, unknown> }
141
+ | { exists: true; malformed: true };
142
+
143
+ function readSettingsFileState(path: string): SettingsFileState {
144
+ if (!existsSync(path)) {
145
+ return { exists: false, value: {} };
146
+ }
147
+
148
+ const parsed = readJsonObject(path);
149
+ if (parsed) {
150
+ return { exists: true, value: parsed };
151
+ }
152
+
153
+ return { exists: true, malformed: true };
154
+ }
155
+
156
+ function normalizePiStatus(input: unknown): PiStatusConfig {
157
+ if (!input || typeof input !== "object" || Array.isArray(input))
158
+ return cloneDefaultConfig();
159
+ const segments = normalizeSegments(
160
+ (input as { segments?: unknown }).segments,
161
+ );
162
+ const filter = normalizeStatusFilter((input as { filter?: unknown }).filter);
163
+ return {
164
+ segments: segments.length > 0 ? segments : [...DEFAULT_SEGMENTS],
165
+ filter,
166
+ };
167
+ }
168
+
169
+ function mergePiStatus(globalValue: unknown, projectValue: unknown): unknown {
170
+ if (
171
+ !globalValue ||
172
+ typeof globalValue !== "object" ||
173
+ Array.isArray(globalValue)
174
+ )
175
+ return projectValue ?? globalValue;
176
+ if (
177
+ !projectValue ||
178
+ typeof projectValue !== "object" ||
179
+ Array.isArray(projectValue)
180
+ )
181
+ return globalValue;
182
+ const g = globalValue as Record<string, unknown>;
183
+ const p = projectValue as Record<string, unknown>;
184
+ const merged: Record<string, unknown> = { ...g, ...p };
185
+
186
+ const gFilter = g.filter;
187
+ const pFilter = p.filter;
188
+ if (
189
+ gFilter &&
190
+ typeof gFilter === "object" &&
191
+ !Array.isArray(gFilter) &&
192
+ pFilter &&
193
+ typeof pFilter === "object" &&
194
+ !Array.isArray(pFilter)
195
+ ) {
196
+ merged.filter = {
197
+ ...(gFilter as Record<string, unknown>),
198
+ ...(pFilter as Record<string, unknown>),
199
+ };
200
+ }
201
+
202
+ return merged;
203
+ }
204
+
205
+ export function loadConfig(options?: { cwd?: string }): ConfigLoadResult {
206
+ const cwd = options?.cwd ?? process.cwd();
207
+ const settingsPaths = getSettingsPaths(cwd);
208
+ const globalSettings = readJsonObject(settingsPaths.global);
209
+ const projectSettings = readJsonObject(settingsPaths.project);
210
+ const mergedPiStatus = mergePiStatus(
211
+ globalSettings?.statusLine,
212
+ projectSettings?.statusLine,
213
+ );
214
+ if (mergedPiStatus !== undefined) {
215
+ return { config: normalizePiStatus(mergedPiStatus), source: "settings" };
216
+ }
217
+
218
+ return { config: cloneDefaultConfig(), source: "default" };
219
+ }
220
+
221
+ export function saveConfigToSettings(
222
+ config: PiStatusConfig,
223
+ options?: { cwd?: string },
224
+ ): { target: "project" | "global"; path: string } {
225
+ const cwd = options?.cwd ?? process.cwd();
226
+ const paths = getSettingsPaths(cwd);
227
+
228
+ const projectState = readSettingsFileState(paths.project);
229
+ if ("malformed" in projectState) {
230
+ throw new Error(
231
+ `Refusing to select settings target because project settings are malformed or not a JSON object: ${paths.project}`,
232
+ );
233
+ }
234
+
235
+ const target: "project" | "global" =
236
+ projectState.exists && Object.hasOwn(projectState.value, "statusLine")
237
+ ? "project"
238
+ : "global";
239
+ const path = target === "project" ? paths.project : paths.global;
240
+
241
+ const targetState = readSettingsFileState(path);
242
+ if ("malformed" in targetState) {
243
+ throw new Error(
244
+ `Refusing to write malformed or non-object settings file: ${path}`,
245
+ );
246
+ }
247
+
248
+ const base = targetState.value;
249
+ const next = {
250
+ ...base,
251
+ statusLine: {
252
+ segments: [...config.segments],
253
+ filter:
254
+ config.filter.mode === "all"
255
+ ? { mode: "all", hidden: [...config.filter.hidden] }
256
+ : { mode: "only", shown: [...config.filter.shown] },
257
+ },
258
+ };
259
+
260
+ const parent = dirname(path);
261
+ mkdirSync(parent, { recursive: true });
262
+ const tempDir = mkdtempSync(join(parent, ".pi-status-"));
263
+ const tempFile = join(tempDir, "settings.json.tmp");
264
+ try {
265
+ writeFileSync(tempFile, `${JSON.stringify(next, null, 2)}\n`, "utf8");
266
+ renameSync(tempFile, path);
267
+ } finally {
268
+ rmSync(tempDir, { recursive: true, force: true });
269
+ }
270
+
271
+ return { target, path };
272
+ }