@bismawy/pi-arnative 0.8.2 → 0.9.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/CHANGELOG.md +81 -63
- package/README.md +52 -83
- package/extensions/arnative.ts +27 -4
- package/extensions/autocompact.ts +1 -1
- package/extensions/footer.ts +5 -2
- package/extensions/section-headers.ts +126 -44
- package/extensions/todos.ts +489 -0
- package/extensions/tools.ts +308 -100
- package/lib/box.ts +77 -12
- package/lib/list-picker.ts +0 -3
- package/lib/preset-store.ts +83 -4
- package/lib/shortcuts.ts +8 -0
- package/lib/todos.ts +473 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -10,45 +10,30 @@ Refined aesthetics. Cohesive tools. Built for Pi.
|
|
|
10
10
|
|
|
11
11
|
## Overview
|
|
12
12
|
|
|
13
|
-
pi-arnative replaces pi’s default terminal chrome with a unified
|
|
13
|
+
pi-arnative replaces pi’s default terminal chrome with a unified visual interface.
|
|
14
14
|
|
|
15
|
-
- Warm Themes:
|
|
15
|
+
- Warm Themes: Contrast-checked OKLCH color palettes generated without drift (`arnative` plus 10 variants).
|
|
16
16
|
- Tabbed Header: Compact box menu showing Directory, Model, Context, Skills, Extensions, and Shortcuts.
|
|
17
|
-
- Rounded Tool Boxes: Status, spinner,
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
17
|
+
- Rounded Tool Boxes: Status, spinner, runtime duration, and clickable `[show]` / `[hide]` output toggles.
|
|
18
|
+
- Task List: `todo` tool, `/todos` view, and a boxed widget above the editor that auto-hides 30s after all tasks finish.
|
|
19
|
+
- Enhanced Footer: 3-row status grid (`Arnative (Full)`) or single collapsible row (`Arnative (Minimal)`) tracking branch, diff, active duration, and token speed.
|
|
20
|
+
- Working Spinners: 18 animated presets with live picker preview and optional `[g]` gradient sweep.
|
|
21
|
+
- Transcript Clock: Per-message timestamps with clean bubble backgrounds.
|
|
22
|
+
- Usage Dashboard: Real-time token counts and cost tracking across local sessions via `/usage`.
|
|
23
|
+
- Custom Providers: Interactive `/providers` wizard to probe endpoints, pick models, set thinking levels, and save OpenAI-, Anthropic-, Gemini-, or Ollama-compatible channels to `models.json` and `auth.json`.
|
|
24
|
+
- Model Heal: Background sync (`/model-heal`) that fills missing compat flags, `/models` token limits, and accepted reasoning effort levels in `models.json`.
|
|
25
|
+
- Auto-compact: Automatic context compaction after a turn settles using smart window tiers or a fixed token budget.
|
|
23
26
|
|
|
24
27
|
<details>
|
|
25
28
|
<summary><b>Configuration & Presets</b></summary>
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
Configurable via `/arnative` → **Animations** (saved to `~/.pi/agent/arnative/config.json`).
|
|
29
|
-
Features 18 presets with live animated preview in the picker (`Arnative` as default, `Pi (system)`, and alphabetical variants). Press `[g]` in the picker to toggle Google brand gradient sweep on accent presets.
|
|
30
|
+
Saved to `~/.pi/agent/arnative/config.json` via `/arnative`:
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
-
|
|
34
|
-
-
|
|
35
|
-
- `
|
|
36
|
-
|
|
37
|
-
### Auto-compact
|
|
38
|
-
Configurable via `/arnative` → **Auto-compact** (saved to `~/.pi/agent/arnative/config.json`).
|
|
39
|
-
When the context crosses the chosen threshold after a run settles, pi's own compaction fires — the same machinery and summary as `/compact`, keeping long sessions light without the manual step. Two shapes of control:
|
|
40
|
-
- **Smart** (tiered by context window): ≥768k→20% · ≥384k→40% · ≥192k→80% · below 192k→pi core. Every tier lands the trigger near the same ~200k-token transcript ceiling — a 1M window trips at a fifth of its window, a 256k at 80%, and a 128k model defers entirely to pi's own near-full compaction (the behavior that is already safe there).
|
|
41
|
-
- **A manual token budget** (`100k`–`400k`): one absolute number, whatever the window.
|
|
42
|
-
|
|
43
|
-
Off by default. Guards: no re-trigger while a compaction runs, a growth-margin wait (5% of the threshold) after an attempt that freed too little or failed, and a full reset on session start. Pi's own `compaction.reserveTokens` threshold, including per-model overrides, is unaffected; whichever fires first wins.
|
|
44
|
-
|
|
45
|
-
### Model heal
|
|
46
|
-
Configurable via `/arnative` → **Model heal** (saved to `~/.pi/agent/arnative/config.json`). Runs on its own on session start, model select, a change to `models.json`, and an error that names a rejected parameter:
|
|
47
|
-
- **Full** (default): compat flags offline, plus `contextWindow`/`maxTokens` from each channel's `GET /models` (6 h TTL) and the accepted `reasoning_effort` levels written as a `thinkingLevelMap` (24 h TTL).
|
|
48
|
-
- **Flags**: the offline compat pass only, no network.
|
|
49
|
-
- **Off**: nothing.
|
|
50
|
-
|
|
51
|
-
`/model-heal` forces every pass now, ignoring the TTLs (`/auto-compat` is an alias once pi-auto-compat is uninstalled). A value you set by hand — even `false` — is never overwritten, a corrupt `models.json` is reported and never rewritten, and the first write keeps a backup. While pi-auto-compat is still installed, pi-arnative defers to it and says so once.
|
|
32
|
+
- **Headers & Footers:** `Arnative (Full)` (default), `Arnative (Minimal)` (footer only; click head text or press `ctrl+alt+m` to toggle), or `Pi (system)`.
|
|
33
|
+
- **Animations:** 18 presets (`Arnative` default, `Pi (system)`, and alphabetical variants). Press `[g]` in the picker to toggle the Google gradient sweep.
|
|
34
|
+
- **Auto-compact:** Off by default. **Smart** tiers trigger near ~200k tokens (`≥768k→20%`, `≥384k→40%`, `≥192k→80%`, `<192k→pi core`), or pick a fixed budget (`100k` to `400k`).
|
|
35
|
+
- **Model heal:** **Full** (default: offline compat flags, `GET /models` limits with 6h TTL, reasoning effort probe with 24h TTL), **Flags** (offline only), or **Off**. Hand-edited fields are never overwritten.
|
|
36
|
+
- **Task list (`todo`):** Stored per session in `~/.pi/agent/arnative/todos/<session-id>.json` (uninstall `@juicesharp/rpiv-todo` first to avoid tool name conflict). Click `[click to expand]` / `[click to collapse]` or press `ctrl+alt+o` (`alt+o`) to toggle; click `↑`/`↓` counters or press `ctrl+alt+j`/`k` (`alt+j`/`k`) to scroll. Auto-hides 30s after completion (set `PI_ARNATIVE_TODO_HIDE_MS` to override, `0` for immediate hide; expanding pauses the timer).
|
|
52
37
|
|
|
53
38
|
</details>
|
|
54
39
|
|
|
@@ -58,11 +43,9 @@ Configurable via `/arnative` → **Model heal** (saved to `~/.pi/agent/arnative/
|
|
|
58
43
|
pi install npm:@bismawy/pi-arnative
|
|
59
44
|
```
|
|
60
45
|
|
|
61
|
-
|
|
62
|
-
On a fresh install the `arnative` theme is applied automatically when pi has no theme of its
|
|
63
|
-
own; a theme you already chose is never overridden.
|
|
46
|
+
Requires a [Nerd Font](https://www.nerdfonts.com/font-downloads). On a fresh install, `arnative` is applied automatically if no theme is set; switch anytime via `/arnative themes` or `/settings` → **Theme**.
|
|
64
47
|
|
|
65
|
-
|
|
48
|
+
Local development:
|
|
66
49
|
```bash
|
|
67
50
|
npm run dev
|
|
68
51
|
```
|
|
@@ -75,27 +58,30 @@ npm run dev
|
|
|
75
58
|
| `ctrl+alt+r` · `alt+r` | Quick reload (`/reload`) |
|
|
76
59
|
| `ctrl+alt+n` · `alt+n` | New session (`/new`) |
|
|
77
60
|
| `ctrl+alt+m` · `alt+m` | Toggle Minimal footer |
|
|
78
|
-
|
|
|
61
|
+
| `ctrl+alt+o` · `alt+o` | Expand or collapse task list |
|
|
62
|
+
| `ctrl+alt+j` · `alt+j` | Scroll task list down |
|
|
63
|
+
| `ctrl+alt+k` · `alt+k` | Scroll task list up |
|
|
64
|
+
| Click `[show]` / `[hide]` · `ctrl+o` | Toggle tool output box |
|
|
65
|
+
| `←` / `Esc` | Step back to parent menu / close active screen |
|
|
79
66
|
| `/arnative` | Settings menu (Themes, Headers, Footers, Animations, Auto-compact, Model heal, Providers, Usage) |
|
|
80
|
-
| `/
|
|
81
|
-
| `/
|
|
82
|
-
|
|
|
83
|
-
|
|
|
67
|
+
| `/usage` | Token & cost dashboard |
|
|
68
|
+
| `/todos` | Full task list recap |
|
|
69
|
+
| `/providers` | Custom provider manager |
|
|
70
|
+
| `/model-heal` | Run `models.json` heal passes now |
|
|
84
71
|
|
|
85
72
|
<details>
|
|
86
73
|
<summary><b>Keybindings & Platform Notes</b></summary>
|
|
87
74
|
|
|
88
|
-
|
|
75
|
+
Bind `app.session.new` in `~/.pi/agent/keybindings.json`:
|
|
89
76
|
```json
|
|
90
77
|
{
|
|
91
78
|
"app.session.new": ["ctrl+alt+n", "alt+n"]
|
|
92
79
|
}
|
|
93
80
|
```
|
|
94
81
|
|
|
95
|
-
- **Windows / WSL:** Windows Terminal
|
|
96
|
-
- **macOS:**
|
|
97
|
-
- **tmux / Herdr:**
|
|
98
|
-
- **Navigation:** `←` navigates back to parent menus; `Esc` cancels or closes the active screen.
|
|
82
|
+
- **Windows / WSL:** Windows Terminal maps `Ctrl+Alt` to AltGr; use `alt+…` or disable `altGrAliasing`.
|
|
83
|
+
- **macOS:** Use `ctrl+option+…`.
|
|
84
|
+
- **tmux / Herdr:** Set `PI_TUI_ESC_TIMEOUT=100` if `Esc` has a delay.
|
|
99
85
|
|
|
100
86
|
</details>
|
|
101
87
|
|
|
@@ -106,52 +92,35 @@ To bind `app.session.new` in `~/.pi/agent/keybindings.json`:
|
|
|
106
92
|
|
|
107
93
|
| File | Role |
|
|
108
94
|
| --- | --- |
|
|
109
|
-
| `extensions/
|
|
110
|
-
| `extensions/section-headers.ts` | Tabbed header and resource box
|
|
111
|
-
| `extensions/footer.ts` | 3-row status grid footer and boxed editor
|
|
112
|
-
| `extensions/
|
|
113
|
-
| `extensions/
|
|
114
|
-
| `extensions/
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `extensions/arnative.ts` | Settings menu with live preview and navigation |
|
|
118
|
-
| `lib/provider.ts` | Custom provider wizard: probe, model pick, edit actions, `models.json`/`auth.json` save |
|
|
119
|
-
| `lib/list-picker.ts` | The live-preview/multi-select picker every arnative screen shares |
|
|
95
|
+
| `extensions/arnative.ts` | `/arnative` settings menu and live preview pickers |
|
|
96
|
+
| `extensions/section-headers.ts` | Tabbed header and resource box |
|
|
97
|
+
| `extensions/footer.ts` | 3-row status grid, Minimal footer, and boxed editor |
|
|
98
|
+
| `extensions/tools.ts` | Rounded tool boxes, spinners, duration, and `[show]` / `[hide]` toggles |
|
|
99
|
+
| `extensions/todos.ts` | `todo` tool, boxed widget above editor, and `/todos` screen |
|
|
100
|
+
| `extensions/animations.ts` | Spinner preset picker and live preview |
|
|
101
|
+
| `extensions/autocompact.ts` | Smart and fixed-budget context compaction |
|
|
102
|
+
| `extensions/model-heal.ts` | Automatic `models.json` heal triggers and `/model-heal` |
|
|
120
103
|
| `extensions/timestamps.ts` | Message timestamps and bubble backgrounds |
|
|
121
|
-
| `extensions/ui-render-tweaks.ts` | Contrast tweaks, selection
|
|
104
|
+
| `extensions/ui-render-tweaks.ts` | Contrast tweaks, selection styling, and UI polish |
|
|
122
105
|
| `extensions/usage.ts` | Token and cost dashboard (`/usage`) |
|
|
106
|
+
| `lib/todos.ts` | Task state, window layout, box rows, and session store |
|
|
107
|
+
| `lib/spinner.ts` | Spinner preset catalog, frames, and gradient painters |
|
|
108
|
+
| `lib/provider.ts` | Custom provider probe, model picker, and config writer |
|
|
109
|
+
| `lib/model-heal.ts` | Compat flags, `/models` limit sync, and reasoning effort probe |
|
|
110
|
+
| `lib/list-picker.ts` | Shared live-preview and multi-select picker component |
|
|
123
111
|
|
|
124
112
|
</details>
|
|
125
113
|
|
|
126
114
|
<details>
|
|
127
|
-
<summary><b>Theme Variants</b></summary>
|
|
128
|
-
|
|
129
|
-
Theme definitions are generated via `themes/gen-themes.mjs` using OKLCH color math (`lib/color.ts`).
|
|
130
|
-
|
|
131
|
-
**Variants:** `sun` · `zinc` · `violet` · `emerald` · `matrix` · `cyberpunk` · `synthwave` · `gruvbox` · `nord` · `dracula`
|
|
132
|
-
|
|
133
|
-
</details>
|
|
134
|
-
|
|
135
|
-
<details>
|
|
136
|
-
<summary><b>Development & Verification</b></summary>
|
|
137
|
-
|
|
138
|
-
```bash
|
|
139
|
-
npm test # Run unit tests and self-checks
|
|
140
|
-
npm run themes # Rebuild all theme variants
|
|
141
|
-
npm run preview # Live preview the working tree in your own Pi (stamps a pushable commit)
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
Pre-publish verification and tag validation are enforced via `scripts/release-check.mjs`.
|
|
115
|
+
<summary><b>Theme Variants & Development</b></summary>
|
|
145
116
|
|
|
146
|
-
**
|
|
147
|
-
carries no live-preview stamp, so a fix cannot reach GitHub unseen. `npm run preview`
|
|
148
|
-
launches Pi with this working tree and writes `.git/arnative-preview` for the exact commit
|
|
149
|
-
that was shown; editing `extensions/`, `lib/`, `themes/`, or `package.json` afterwards
|
|
150
|
-
invalidates it and the hook asks for a fresh preview. The preview must run on a clean tree
|
|
151
|
-
— commit or stash first. Git does not auto-install hooks; activate per clone:
|
|
117
|
+
**Themes (`themes/gen-themes.mjs` + `lib/color.ts`):** `arnative` · `sun` · `zinc` · `violet` · `emerald` · `matrix` · `cyberpunk` · `synthwave` · `gruvbox` · `nord` · `dracula`
|
|
152
118
|
|
|
153
119
|
```bash
|
|
154
|
-
|
|
120
|
+
npm test # Run self-checks and unit tests
|
|
121
|
+
npm run themes # Regenerate theme JSON files
|
|
122
|
+
npm run preview # Live preview in Pi and stamp .git/arnative-preview
|
|
123
|
+
git config core.hooksPath .githooks # Enable pre-push preview verification hook
|
|
155
124
|
```
|
|
156
125
|
|
|
157
126
|
</details>
|
package/extensions/arnative.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { stripAnsi } from "../lib/ansi.ts";
|
|
|
11
11
|
import { screenTitle } from "../lib/box.ts";
|
|
12
12
|
import { assert, isMain } from "../lib/check.ts";
|
|
13
13
|
import { markedLabels, ROW_DIVIDER } from "../lib/format.ts";
|
|
14
|
-
import { SPINNER_PRESETS, type SpinnerPreset } from "../lib/spinner.ts";
|
|
14
|
+
import { SPINNER_GRADIENT_KEY, SPINNER_PRESET_KEY, SPINNER_PRESETS, type SpinnerPreset } from "../lib/spinner.ts";
|
|
15
15
|
import {
|
|
16
16
|
activeSpinnerGradient,
|
|
17
17
|
animationsPickerText,
|
|
@@ -22,11 +22,18 @@ import {
|
|
|
22
22
|
setSpinnerGradient,
|
|
23
23
|
setSpinnerPreset,
|
|
24
24
|
} from "./animations.ts";
|
|
25
|
+
import { FOOTER_PRESET_KEY, HEADER_PRESET_KEY, ensureChoices } from "../lib/preset-store.ts";
|
|
25
26
|
import { FOOTER_PRESETS, activeFooterPreset, setFooterPreset, type FooterPreset } from "./footer.ts";
|
|
26
27
|
import { HEADER_PRESETS, activeHeaderPreset, setHeaderPreset, type HeaderPreset } from "./section-headers.ts";
|
|
27
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
AUTO_COMPACT_CHOICES,
|
|
30
|
+
AUTO_COMPACT_KEY,
|
|
31
|
+
activeAutoCompact,
|
|
32
|
+
setAutoCompact,
|
|
33
|
+
type AutoCompactChoice,
|
|
34
|
+
} from "./autocompact.ts";
|
|
28
35
|
import { healNow } from "./model-heal.ts";
|
|
29
|
-
import { MODEL_HEAL_CHOICES, activeModelHeal, setModelHeal, type ModelHealChoice } from "../lib/model-heal.ts";
|
|
36
|
+
import { MODEL_HEAL_CHOICES, MODEL_HEAL_KEY, activeModelHeal, setModelHeal, type ModelHealChoice } from "../lib/model-heal.ts";
|
|
30
37
|
import { LIST_LEGEND_LIVE, LIST_LEGEND_MOVE, LIST_LEGEND_ROOT, ListPicker, nameRows, rowText, type ListPickerText, type ListRow } from "../lib/list-picker.ts";
|
|
31
38
|
import { openProviders } from "../lib/provider.ts";
|
|
32
39
|
import { openUsage } from "./usage.ts";
|
|
@@ -518,7 +525,7 @@ export function shouldApplyDefaultTheme(
|
|
|
518
525
|
* set without starting a session. */
|
|
519
526
|
export function registerCommands(pi: Pick<ExtensionAPI, "registerCommand">): void {
|
|
520
527
|
pi.registerCommand("arnative", {
|
|
521
|
-
description: "Arnative settings menu: themes, headers, footers, providers, usage",
|
|
528
|
+
description: "Arnative settings menu: themes, headers, footers, animations, auto-compact, model heal, providers, usage",
|
|
522
529
|
getArgumentCompletions: arnativeCompletions,
|
|
523
530
|
handler: arnativeHandler,
|
|
524
531
|
});
|
|
@@ -530,8 +537,24 @@ export function registerCommands(pi: Pick<ExtensionAPI, "registerCommand">): voi
|
|
|
530
537
|
});
|
|
531
538
|
}
|
|
532
539
|
|
|
540
|
+
/** Record the choices in use in `config.json`, defaults included, so the file reads as the
|
|
541
|
+
* profile instead of a diff against it. Idempotent: only keys that differ get written. */
|
|
542
|
+
export function recordProfile(): void {
|
|
543
|
+
ensureChoices({
|
|
544
|
+
[HEADER_PRESET_KEY]: activeHeaderPreset(),
|
|
545
|
+
[FOOTER_PRESET_KEY]: activeFooterPreset(),
|
|
546
|
+
[SPINNER_PRESET_KEY]: activeSpinnerPreset(),
|
|
547
|
+
[SPINNER_GRADIENT_KEY]: activeSpinnerGradient() ? "on" : "off",
|
|
548
|
+
[AUTO_COMPACT_KEY]: activeAutoCompact(),
|
|
549
|
+
[MODEL_HEAL_KEY]: activeModelHeal(),
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
|
|
533
553
|
export default function (pi: ExtensionAPI) {
|
|
534
554
|
pi.on("session_start", async (_event, ctx) => {
|
|
555
|
+
// Before the theme branch below returns: the profile is recorded once per install, so
|
|
556
|
+
// `config.json` lists every choice even when it never left its default.
|
|
557
|
+
recordProfile();
|
|
535
558
|
// `setTheme` writes the choice into pi's settings, so this runs once per install and the
|
|
536
559
|
// second session already sees an explicit setting.
|
|
537
560
|
if (!shouldApplyDefaultTheme(pi.getSettings()?.theme, ctx.ui.getAllThemes())) return;
|
|
@@ -30,7 +30,7 @@ import { loadChoice, resetPresetCache, saveChoice } from "../lib/preset-store.ts
|
|
|
30
30
|
export const AUTO_COMPACT_CHOICES = ["Off", "Smart", "100k", "150k", "200k", "300k", "400k"] as const;
|
|
31
31
|
export type AutoCompactChoice = (typeof AUTO_COMPACT_CHOICES)[number];
|
|
32
32
|
export const DEFAULT_AUTO_COMPACT: AutoCompactChoice = "Off";
|
|
33
|
-
const AUTO_COMPACT_KEY = "autoCompact";
|
|
33
|
+
export const AUTO_COMPACT_KEY = "autoCompact";
|
|
34
34
|
|
|
35
35
|
/** Smart's tier table, first match wins. `null` defers the window to pi's own
|
|
36
36
|
* compaction — the "100%" tier, where the current behavior is already safe. */
|
package/extensions/footer.ts
CHANGED
|
@@ -1380,9 +1380,12 @@ if (isMain(import.meta.url)) {
|
|
|
1380
1380
|
writeFileSync(join(repo, ".git", "HEAD"), "ref: refs/heads/arnative-tests\n");
|
|
1381
1381
|
git = null;
|
|
1382
1382
|
const noGit = mkdtempSync(join(tmpdir(), "pi-arnative-nogit-"));
|
|
1383
|
-
|
|
1383
|
+
// `noGit` is not always repo-free: a temp dir under a versioned home finds the home
|
|
1384
|
+
// repo, so this first refresh really is in flight and can publish the home branch
|
|
1385
|
+
// before the queued one lands. Wait for the queued result, not for "not null".
|
|
1386
|
+
void refreshGit(noGit);
|
|
1384
1387
|
await refreshGit(repo); // queued behind it with the newest cwd
|
|
1385
|
-
for (let i = 0; i <
|
|
1388
|
+
for (let i = 0; i < 250 && git?.branch !== "arnative-tests"; i++) await new Promise((r) => setTimeout(r, 20));
|
|
1386
1389
|
assert(git !== null && git.branch === "arnative-tests", "queued git refresh re-ran on the newest cwd (not dropped)");
|
|
1387
1390
|
rmSync(noGit, { recursive: true, force: true });
|
|
1388
1391
|
rmSync(repo, { recursive: true, force: true });
|
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
* - Box divider '├────┤'. Active tab content is left-aligned, wrapped, soft.
|
|
13
13
|
* - Hides pi's built-in stacked list in loadedResourcesContainer.
|
|
14
14
|
*/
|
|
15
|
-
import { readFileSync
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
|
-
import { userInfo } from "node:os";
|
|
17
|
+
import { homedir, userInfo } from "node:os";
|
|
18
18
|
import { join } from "node:path";
|
|
19
19
|
import {
|
|
20
|
+
CONFIG_DIR_NAME,
|
|
20
21
|
UserMessageComponent,
|
|
21
22
|
getAgentDir,
|
|
22
23
|
VERSION,
|
|
@@ -140,14 +141,6 @@ export function sectionNameOf(text: string): "Context" | "Skills" | "Extensions"
|
|
|
140
141
|
return null;
|
|
141
142
|
}
|
|
142
143
|
|
|
143
|
-
export function packageNameOf(label: string): string | null {
|
|
144
|
-
const base = label.split(":")[0].trim();
|
|
145
|
-
if (base === "") return null;
|
|
146
|
-
const at = base.lastIndexOf("@");
|
|
147
|
-
if (at > 0 && /^\d/.test(base.slice(at + 1))) return null;
|
|
148
|
-
return /^[\w.@/-]+$/.test(base) ? base : null;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
144
|
/**
|
|
152
145
|
* OS account name of whoever is running pi, for the header greeting. Falls back to the
|
|
153
146
|
* usual env vars, then to a neutral word so the line is never empty.
|
|
@@ -163,8 +156,6 @@ export function deviceUser(): string {
|
|
|
163
156
|
return u || "there";
|
|
164
157
|
}
|
|
165
158
|
|
|
166
|
-
const versionCache = new Map<string, string | null>();
|
|
167
|
-
|
|
168
159
|
export function readVersion(dir: string): string | null {
|
|
169
160
|
try {
|
|
170
161
|
const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")) as { version?: unknown };
|
|
@@ -174,27 +165,123 @@ export function readVersion(dir: string): string | null {
|
|
|
174
165
|
}
|
|
175
166
|
}
|
|
176
167
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
// Extensions tab = the `pi list` rows, then the loose extension files.
|
|
170
|
+
// pi's own listing names one loaded module per row, so a package shows up as
|
|
171
|
+
// eleven file names and the package itself never appears.
|
|
172
|
+
// ---------------------------------------------------------------------------
|
|
173
|
+
|
|
174
|
+
export interface InstalledPackage {
|
|
175
|
+
/** Row text: the configured source without its `npm:` prefix, plus the installed version
|
|
176
|
+
* when the source names none. */
|
|
177
|
+
label: string;
|
|
178
|
+
/** Absolute dir for a local-path source (null for npm and git packages). */
|
|
179
|
+
localPath: string | null;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Installed version per `agentDir` and package name; one read per package per process. */
|
|
183
|
+
const versionCache = new Map<string, string | null>();
|
|
184
|
+
|
|
185
|
+
/** `name@1.2.3` -> `{ name: "name", version: "1.2.3" }`; a scope's `@` is not a version. */
|
|
186
|
+
function splitVersion(label: string): { name: string; version: string | null } {
|
|
187
|
+
const at = label.lastIndexOf("@");
|
|
188
|
+
if (at > 0 && /\d/.test(label.slice(at + 1))) return { name: label.slice(0, at), version: label.slice(at + 1) };
|
|
189
|
+
return { name: label, version: null };
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** The row text of an npm package: the source as configured, or with the installed version.
|
|
193
|
+
* The version lives in the package's own `package.json`, the same place `pi list` resolves it. */
|
|
194
|
+
function npmRow(source: string, agentDir: string): string {
|
|
195
|
+
const label = source.slice("npm:".length);
|
|
196
|
+
const { name, version } = splitVersion(label);
|
|
197
|
+
if (version !== null) return label; // pinned in settings: show what was asked for
|
|
198
|
+
const key = `${agentDir}\0${name}`;
|
|
199
|
+
if (!versionCache.has(key)) versionCache.set(key, readVersion(join(agentDir, "npm", "node_modules", name)));
|
|
200
|
+
const installed = versionCache.get(key) ?? null;
|
|
201
|
+
return installed ? `${label}@${installed}` : label;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Slashes forward, `~` expanded, lower case: comparable against a listing path. */
|
|
205
|
+
function comparablePath(path: string): string {
|
|
206
|
+
const home = homedir().replace(/\\/g, "/");
|
|
207
|
+
const expanded = path.startsWith("~") ? home + path.slice(1) : path;
|
|
208
|
+
return expanded.replace(/\\/g, "/").replace(/\/+$/, "").toLowerCase();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Packages configured in settings, in `pi list` order: user scope first, then project.
|
|
213
|
+
* Read straight from the two settings files; the header runs on every render, so it
|
|
214
|
+
* must not build a package manager for this.
|
|
215
|
+
*/
|
|
216
|
+
export function installedPackages(agentDir: string, cwd: string): InstalledPackage[] {
|
|
217
|
+
const sourcesOf = (file: string): string[] => {
|
|
187
218
|
try {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
219
|
+
const settings = JSON.parse(readFileSync(file, "utf8")) as {
|
|
220
|
+
packages?: Array<string | { source?: unknown }>;
|
|
221
|
+
};
|
|
222
|
+
return (settings.packages ?? [])
|
|
223
|
+
.map((pkg) => (typeof pkg === "string" ? pkg : typeof pkg.source === "string" ? pkg.source : ""))
|
|
224
|
+
.filter((source) => source !== "");
|
|
192
225
|
} catch {
|
|
193
|
-
|
|
226
|
+
return []; // no settings file (or unreadable JSON): the tab shows no package, not an error
|
|
194
227
|
}
|
|
228
|
+
};
|
|
229
|
+
const scopes = [
|
|
230
|
+
{ sources: sourcesOf(join(agentDir, "settings.json")), baseDir: agentDir },
|
|
231
|
+
{ sources: sourcesOf(join(cwd, CONFIG_DIR_NAME, "settings.json")), baseDir: join(cwd, CONFIG_DIR_NAME) },
|
|
232
|
+
];
|
|
233
|
+
return scopes.flatMap(({ sources, baseDir }) =>
|
|
234
|
+
sources.map((source) => {
|
|
235
|
+
const packaged = /^(npm|git):/.test(source);
|
|
236
|
+
// Relative local sources resolve against their own scope dir, the way pi installs them.
|
|
237
|
+
const absolute = /^([A-Za-z]:)?[\\/]/.test(source) || source.startsWith("~") ? source : join(baseDir, source);
|
|
238
|
+
const label = source.startsWith("npm:") ? npmRow(source, agentDir) : source;
|
|
239
|
+
return { label, localPath: packaged ? null : comparablePath(absolute) };
|
|
240
|
+
}),
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Loose extension files from pi's expanded `[Extensions]` listing (never package modules). */
|
|
245
|
+
export function listingLocalPaths(expanded: string): string[] {
|
|
246
|
+
const paths: string[] = [];
|
|
247
|
+
for (const line of stripAnsi(expanded).split("\n")) {
|
|
248
|
+
if (line.trim() === "") continue;
|
|
249
|
+
// pi indents the groups by 2, a loose path or a package source by 4, a package module by 6.
|
|
250
|
+
if (line.length - line.trimStart().length !== 4) continue;
|
|
251
|
+
const text = line.trim();
|
|
252
|
+
if (!/^(npm|git):/.test(text)) paths.push(text);
|
|
195
253
|
}
|
|
196
|
-
|
|
197
|
-
|
|
254
|
+
return paths;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Last segment of a path; an `index.ts` file names its folder instead. */
|
|
258
|
+
function fileLabel(path: string): string {
|
|
259
|
+
const segments = path.split("/").filter(Boolean);
|
|
260
|
+
const last = segments[segments.length - 1] ?? path;
|
|
261
|
+
if ((last === "index.ts" || last === "index.js") && segments.length > 1) {
|
|
262
|
+
return segments[segments.length - 2]!;
|
|
263
|
+
}
|
|
264
|
+
return last;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** Tab rows: one per installed package, then the loose extension files, sorted. */
|
|
268
|
+
export function extensionTabItems(expanded: string, agentDir: string, cwd: string): string[] {
|
|
269
|
+
const packages = installedPackages(agentDir, cwd);
|
|
270
|
+
const localRoots = packages.map((pkg) => pkg.localPath).filter((root): root is string => root !== null);
|
|
271
|
+
const items = packages.map((pkg) => pkg.label);
|
|
272
|
+
const seen = new Set(items);
|
|
273
|
+
const locals: string[] = [];
|
|
274
|
+
for (const path of listingLocalPaths(expanded)) {
|
|
275
|
+
const comparable = comparablePath(path);
|
|
276
|
+
// Modules of a local-path package are rows of that package, not files of their own.
|
|
277
|
+
if (localRoots.some((root) => comparable === root || comparable.startsWith(`${root}/`))) continue;
|
|
278
|
+
const label = fileLabel(path.replace(/\\/g, "/"));
|
|
279
|
+
if (seen.has(label)) continue;
|
|
280
|
+
seen.add(label);
|
|
281
|
+
locals.push(label);
|
|
282
|
+
}
|
|
283
|
+
locals.sort((a, b) => a.localeCompare(b));
|
|
284
|
+
return [...items, ...locals];
|
|
198
285
|
}
|
|
199
286
|
|
|
200
287
|
// Arnative build actually running: package.json one level above this extension file.
|
|
@@ -202,7 +289,7 @@ export function installedVersion(
|
|
|
202
289
|
// behind whenever the local clone (or a hand-copied extensions/) is what pi loaded.
|
|
203
290
|
const ARNATIVE_VERSION = readVersion(fileURLToPath(new URL("..", import.meta.url)));
|
|
204
291
|
|
|
205
|
-
export function extractItemsFromBody(body: string
|
|
292
|
+
export function extractItemsFromBody(body: string): string[] {
|
|
206
293
|
const plain = stripAnsi(body).trim();
|
|
207
294
|
if (!plain) return [];
|
|
208
295
|
const lines = plain.split("\n").map((l) => l.trim()).filter(Boolean);
|
|
@@ -214,17 +301,7 @@ export function extractItemsFromBody(body: string, isExtensions = false): string
|
|
|
214
301
|
items.push(line);
|
|
215
302
|
}
|
|
216
303
|
}
|
|
217
|
-
|
|
218
|
-
// One row per package (like `pi list`): drop the `:subpath` of every module inside a
|
|
219
|
-
// package and repeat nothing. Local single-file extensions (`hark.ts`) stay as they are.
|
|
220
|
-
const labels = new Set<string>();
|
|
221
|
-
for (const item of items) {
|
|
222
|
-
const colon = item.indexOf(":");
|
|
223
|
-
const base = (colon === -1 ? item : item.slice(0, colon)).trim();
|
|
224
|
-
const ver = installedVersion(base);
|
|
225
|
-
labels.add(ver ? `${base}@${ver}` : base);
|
|
226
|
-
}
|
|
227
|
-
return [...labels];
|
|
304
|
+
return items;
|
|
228
305
|
}
|
|
229
306
|
|
|
230
307
|
// Cheatsheet for the Shortcut tab. Mirrors README "Shortcuts" plus the bindings the
|
|
@@ -731,9 +808,14 @@ if (UserMessageComponent?.prototype) {
|
|
|
731
808
|
(this as Record<string, unknown>)._isLoadedResourcesContainer = true;
|
|
732
809
|
|
|
733
810
|
countsKnown = true;
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
811
|
+
if (sectionName === "Extensions") {
|
|
812
|
+
// The expanded listing carries the loose files; the packages come from settings.
|
|
813
|
+
const expanded = typeof child.getExpandedText === "function" ? String(child.getExpandedText()) : "";
|
|
814
|
+
tabStore.set("Extensions", extensionTabItems(expanded, getAgentDir(), getCwd() || process.cwd()));
|
|
815
|
+
} else {
|
|
816
|
+
const rawBody = body.split("\n").slice(1).join("\n");
|
|
817
|
+
tabStore.set(sectionName, extractItemsFromBody(rawBody));
|
|
818
|
+
}
|
|
737
819
|
|
|
738
820
|
// Hide this child from the built-in display so it does not stack under the header
|
|
739
821
|
child.render = () => [];
|