@mrclrchtr/supi-extras 7.2.1 → 7.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -24
- package/node_modules/@mrclrchtr/supi-core/README.md +10 -0
- package/node_modules/@mrclrchtr/supi-core/package.json +3 -2
- package/node_modules/@mrclrchtr/supi-core/src/api.ts +2 -0
- package/node_modules/@mrclrchtr/supi-core/src/index.ts +2 -0
- package/node_modules/@mrclrchtr/supi-core/src/session-capabilities.ts +188 -0
- package/node_modules/@mrclrchtr/supi-core/src/session.ts +17 -0
- package/node_modules/@mrclrchtr/supi-core/src/tui.ts +141 -0
- package/package.json +3 -3
- package/src/index.ts +2 -0
- package/src/session-capabilities-state.ts +60 -0
- package/src/session-capabilities-tools.ts +103 -0
- package/src/session-capabilities-ui-rows.ts +192 -0
- package/src/session-capabilities-ui.ts +356 -0
- package/src/session-capabilities.ts +350 -0
package/README.md
CHANGED
|
@@ -16,18 +16,8 @@ Adds a bundle of small quality-of-life features to the [pi coding agent](https:/
|
|
|
16
16
|
pi install npm:@mrclrchtr/supi-extras
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
For local development:
|
|
20
|
-
|
|
21
|
-
```bash
|
|
22
|
-
pi install ./packages/supi-extras
|
|
23
|
-
```
|
|
24
|
-
|
|
25
19
|

|
|
26
20
|
|
|
27
|
-
## What you get
|
|
28
|
-
|
|
29
|
-
This package mixes a few commands and shortcuts with a few always-on UI tweaks. Skill controls and `$skill-name` shortcuts live in [`@mrclrchtr/supi-skills`](https://github.com/mrclrchtr/supi/tree/main/packages/supi-skills).
|
|
30
|
-
|
|
31
21
|
## Commands
|
|
32
22
|
|
|
33
23
|
- `/exit` — exit pi
|
|
@@ -35,6 +25,22 @@ This package mixes a few commands and shortcuts with a few always-on UI tweaks.
|
|
|
35
25
|
- `/clear` — start a new session (alias for `/new`)
|
|
36
26
|
- `/clone-session <session-id>` — clone a session into the current worktree and switch to it; autocomplete searches IDs and session names
|
|
37
27
|
- `/supi-stash` — browse, restore, copy, delete, or clear saved prompt drafts
|
|
28
|
+
- `/supi-capabilities` — choose extension tools and model-visible skills for this session
|
|
29
|
+
|
|
30
|
+
## Session capabilities
|
|
31
|
+
|
|
32
|
+
`/supi-capabilities` opens a searchable selector. Use it to change extension tool and skill visibility for the current session.
|
|
33
|
+
|
|
34
|
+
- The selector lists only extension tools that were active at startup. It does not list PI built-in tools or tools supplied by integrations.
|
|
35
|
+
- Tool and skill overrides are stored in the session. Resume restores them. Fork and `/clone-session` copy them. `/new` starts without overrides.
|
|
36
|
+
- Tree navigation keeps explicit capability tool choices and does not change other tool choices.
|
|
37
|
+
- Tool changes affect later requests. They do not stop a tool call that is already running.
|
|
38
|
+
- Saved tool restrictions also apply if a tool becomes available later. Use **Reset Tools** to clear them.
|
|
39
|
+
- Skill changes affect the model skill catalog only. Explicit `/skill:name` commands and `$name` shortcuts stay available.
|
|
40
|
+
- Use **Reset Tools**, **Reset Skills**, or **Reset All** to remove overrides.
|
|
41
|
+
- The footer shows a count while overrides are active.
|
|
42
|
+
|
|
43
|
+
Install [`@mrclrchtr/supi-skills`](https://github.com/mrclrchtr/supi/tree/main/packages/supi-skills) to manage skills. Tool controls work without that package.
|
|
38
44
|
|
|
39
45
|
## Shortcuts
|
|
40
46
|
|
|
@@ -53,17 +59,17 @@ Prompt stash stores drafts in `~/.pi/agent/supi/prompt-stash.json` so they survi
|
|
|
53
59
|
- `D` — clear all drafts
|
|
54
60
|
- `Esc` — close the overlay
|
|
55
61
|
|
|
56
|
-
If the stash file cannot be read or written,
|
|
62
|
+
If the stash file cannot be read or written, drafts are kept in memory only and can be lost when pi closes.
|
|
57
63
|
|
|
58
64
|
## Passive behavior
|
|
59
65
|
|
|
60
66
|
### Tab-title spinner
|
|
61
67
|
|
|
62
|
-
While the agent is working, the package animates a spinner in the terminal tab title. When the turn finishes, it shows a done marker.
|
|
68
|
+
While the agent is working, the package animates a spinner in the terminal tab title. When the turn finishes, it shows a done marker. The spinner pauses while a question waits for your answer.
|
|
63
69
|
|
|
64
70
|
### Footer replacement
|
|
65
71
|
|
|
66
|
-
The package replaces pi's default footer.
|
|
72
|
+
The package replaces pi's default footer. It shows the model and thinking level with theme colors.
|
|
67
73
|
|
|
68
74
|
### Headless git safety
|
|
69
75
|
|
|
@@ -73,14 +79,3 @@ The package sets:
|
|
|
73
79
|
- `GIT_SEQUENCE_EDITOR=true`
|
|
74
80
|
|
|
75
81
|
That prevents git subprocesses from hanging while waiting for an interactive editor.
|
|
76
|
-
|
|
77
|
-
## Source
|
|
78
|
-
|
|
79
|
-
- `src/aliases.ts` — command aliases
|
|
80
|
-
- `src/clone-session.ts` — cross-worktree session cloning by ID
|
|
81
|
-
- `src/prompt-stash.ts` — prompt stash shortcuts, persistence, and overlay
|
|
82
|
-
- `src/tab-spinner.ts` — terminal tab-title spinner
|
|
83
|
-
- `src/copy-prompt.ts` and `src/clipboard.ts` — copy-to-clipboard shortcut and helper
|
|
84
|
-
- `src/supi-footer.ts` — footer replacement
|
|
85
|
-
- `src/supi-footer-helpers.ts` — pure helpers
|
|
86
|
-
- `src/git-editor.ts` — git editor environment guard
|
|
@@ -23,6 +23,7 @@ pnpm add @mrclrchtr/supi-core
|
|
|
23
23
|
- `@mrclrchtr/supi-core/api` — reusable helpers for other packages and extensions
|
|
24
24
|
- `@mrclrchtr/supi-core/llm` — PI-owned direct model requests and JSON helpers
|
|
25
25
|
- `@mrclrchtr/supi-core/report` — shared text/report rendering helpers for TUI and plain-text summaries
|
|
26
|
+
- `@mrclrchtr/supi-core/tui` — shared terminal UI helpers for list titles, rows, menus, and descriptions
|
|
26
27
|
|
|
27
28
|
## What you get from the API
|
|
28
29
|
|
|
@@ -70,6 +71,14 @@ Both completion helpers require a stable `affinityScope`. PI owns auth and endpo
|
|
|
70
71
|
- active-branch session helper: `getActiveBranchEntries()`
|
|
71
72
|
- terminal helpers such as `formatTitle()`, `signalWaiting()`, and `signalDone()`
|
|
72
73
|
|
|
74
|
+
### TUI helpers
|
|
75
|
+
|
|
76
|
+
- `formatTuiTitleLine()` — use the shared title style in terminal lists
|
|
77
|
+
- `renderSelectableRow()` — render a selected row with an aligned value
|
|
78
|
+
- `renderDescriptionViewport()` — show a fixed-height description preview
|
|
79
|
+
- `renderTuiHintLine()` — render short key hints in one line
|
|
80
|
+
- `createSelectListMenu()` — build an action menu with shared key hints
|
|
81
|
+
|
|
73
82
|
### Report helpers
|
|
74
83
|
|
|
75
84
|
- `clampReportWidth()` — enforce a minimum readable report width
|
|
@@ -125,3 +134,4 @@ export default function myExtension(pi: ExtensionAPI) {
|
|
|
125
134
|
- `src/debug-timing.ts` — monotonic total and phase timers for Debug Event Producers
|
|
126
135
|
- `src/settings/` — settings registry, schema, scope resolution, and persistence
|
|
127
136
|
- `src/report.ts` — shared text/report rendering helpers
|
|
137
|
+
- `src/tui.ts` — shared terminal UI list and action-menu helpers
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.1",
|
|
4
4
|
"description": "Shared settings, configuration, reporting, and session infrastructure",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"./settings": "./src/settings.ts",
|
|
68
68
|
"./spinner-frames": "./src/spinner-frames.ts",
|
|
69
69
|
"./status-spinner": "./src/status-spinner.ts",
|
|
70
|
-
"./terminal": "./src/terminal.ts"
|
|
70
|
+
"./terminal": "./src/terminal.ts",
|
|
71
|
+
"./tui": "./src/tui.ts"
|
|
71
72
|
}
|
|
72
73
|
}
|
|
@@ -38,3 +38,5 @@ export * from "./spinner-frames.ts";
|
|
|
38
38
|
export * from "./status-spinner.ts";
|
|
39
39
|
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
40
40
|
export * from "./terminal.ts";
|
|
41
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
42
|
+
export * from "./tui.ts";
|
|
@@ -34,3 +34,5 @@ export * from "./settings.ts";
|
|
|
34
34
|
export * from "./status-spinner.ts";
|
|
35
35
|
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
36
36
|
export * from "./terminal.ts";
|
|
37
|
+
// biome-ignore lint/performance/noReExportAll: intentional convenience barrel
|
|
38
|
+
export * from "./tui.ts";
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/** Session-only tool and skill visibility state. */
|
|
2
|
+
export interface SessionCapabilityState {
|
|
3
|
+
version: 1;
|
|
4
|
+
eligibleToolNames: string[];
|
|
5
|
+
initiallyInactiveToolNames: string[];
|
|
6
|
+
toolDenylist: string[];
|
|
7
|
+
/** Tools that the user explicitly enabled for this session. */
|
|
8
|
+
toolEnabledNames?: string[];
|
|
9
|
+
hiddenSkillNames: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** A model-visible skill that a provider can offer to the selector. */
|
|
13
|
+
export interface SessionCapabilitySkill {
|
|
14
|
+
name: string;
|
|
15
|
+
description: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Skill inventory provider registered by the skills extension. */
|
|
19
|
+
export interface SessionCapabilitySkillProvider<TContext = unknown> {
|
|
20
|
+
listEligibleSkills(
|
|
21
|
+
context: TContext,
|
|
22
|
+
): Promise<SessionCapabilitySkill[]> | SessionCapabilitySkill[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Custom session-entry type used for hidden capability snapshots. */
|
|
26
|
+
export const SESSION_CAPABILITIES_ENTRY = "supi-capabilities";
|
|
27
|
+
|
|
28
|
+
const REGISTRY_PREFIX = "@mrclrchtr/supi-core/session-capabilities/";
|
|
29
|
+
const STATE_KEY = Symbol.for(`${REGISTRY_PREFIX}state`);
|
|
30
|
+
const PROVIDER_KEY = Symbol.for(`${REGISTRY_PREFIX}skill-providers`);
|
|
31
|
+
const FORK_KEY = Symbol.for(`${REGISTRY_PREFIX}pending-forks`);
|
|
32
|
+
|
|
33
|
+
type GlobalRegistry = typeof globalThis & Record<symbol, unknown>;
|
|
34
|
+
|
|
35
|
+
type SkillProviderMap = Map<string, SessionCapabilitySkillProvider<unknown>>;
|
|
36
|
+
type ForkStateMap = Map<string, SessionCapabilityState>;
|
|
37
|
+
|
|
38
|
+
function getStateMap(): Map<string, SessionCapabilityState> {
|
|
39
|
+
const target = globalThis as GlobalRegistry;
|
|
40
|
+
let map = target[STATE_KEY] as Map<string, SessionCapabilityState> | undefined;
|
|
41
|
+
if (!map) {
|
|
42
|
+
map = new Map();
|
|
43
|
+
target[STATE_KEY] = map;
|
|
44
|
+
}
|
|
45
|
+
return map;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getProviderMap(): SkillProviderMap {
|
|
49
|
+
const target = globalThis as GlobalRegistry;
|
|
50
|
+
let map = target[PROVIDER_KEY] as SkillProviderMap | undefined;
|
|
51
|
+
if (!map) {
|
|
52
|
+
map = new Map();
|
|
53
|
+
target[PROVIDER_KEY] = map;
|
|
54
|
+
}
|
|
55
|
+
return map;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function getForkMap(): ForkStateMap {
|
|
59
|
+
const target = globalThis as GlobalRegistry;
|
|
60
|
+
let map = target[FORK_KEY] as ForkStateMap | undefined;
|
|
61
|
+
if (!map) {
|
|
62
|
+
map = new Map();
|
|
63
|
+
target[FORK_KEY] = map;
|
|
64
|
+
}
|
|
65
|
+
return map;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function stringList(value: unknown): string[] {
|
|
69
|
+
if (!Array.isArray(value)) return [];
|
|
70
|
+
return Array.from(new Set(value.filter((item): item is string => typeof item === "string")));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Create an empty state snapshot. */
|
|
74
|
+
export function createEmptySessionCapabilityState(): SessionCapabilityState {
|
|
75
|
+
return {
|
|
76
|
+
version: 1,
|
|
77
|
+
eligibleToolNames: [],
|
|
78
|
+
initiallyInactiveToolNames: [],
|
|
79
|
+
toolDenylist: [],
|
|
80
|
+
toolEnabledNames: [],
|
|
81
|
+
hiddenSkillNames: [],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Validate and copy one stored snapshot. */
|
|
86
|
+
export function decodeSessionCapabilities(value: unknown): SessionCapabilityState | undefined {
|
|
87
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined;
|
|
88
|
+
const record = value as Record<string, unknown>;
|
|
89
|
+
if (record.version !== 1) return undefined;
|
|
90
|
+
|
|
91
|
+
const initiallyInactiveToolNames = stringList(record.initiallyInactiveToolNames);
|
|
92
|
+
const initiallyInactive = new Set(initiallyInactiveToolNames);
|
|
93
|
+
const eligibleToolNames = stringList(record.eligibleToolNames).filter(
|
|
94
|
+
(name) => !initiallyInactive.has(name),
|
|
95
|
+
);
|
|
96
|
+
const eligible = new Set(eligibleToolNames);
|
|
97
|
+
const toolDenylist = stringList(record.toolDenylist).filter((name) => eligible.has(name));
|
|
98
|
+
const denied = new Set(toolDenylist);
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
version: 1,
|
|
102
|
+
eligibleToolNames,
|
|
103
|
+
initiallyInactiveToolNames,
|
|
104
|
+
toolDenylist,
|
|
105
|
+
toolEnabledNames: stringList(record.toolEnabledNames).filter(
|
|
106
|
+
(name) => eligible.has(name) && !denied.has(name),
|
|
107
|
+
),
|
|
108
|
+
hiddenSkillNames: stringList(record.hiddenSkillNames),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Return a safe copy of the latest valid snapshot in all session entries. */
|
|
113
|
+
export function findSessionCapabilities(
|
|
114
|
+
entries: readonly unknown[],
|
|
115
|
+
): SessionCapabilityState | undefined {
|
|
116
|
+
for (let index = entries.length - 1; index >= 0; index--) {
|
|
117
|
+
const entry = entries[index];
|
|
118
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
119
|
+
const record = entry as Record<string, unknown>;
|
|
120
|
+
if (record.type !== "custom" || record.customType !== SESSION_CAPABILITIES_ENTRY) continue;
|
|
121
|
+
const state = decodeSessionCapabilities(record.data);
|
|
122
|
+
if (state) return state;
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Shared session state. Session IDs keep sessions in the same cwd separate. */
|
|
128
|
+
export const sessionCapabilityState = {
|
|
129
|
+
get(sessionId: string): SessionCapabilityState | undefined {
|
|
130
|
+
const state = getStateMap().get(sessionId);
|
|
131
|
+
return state ? decodeSessionCapabilities(state) : undefined;
|
|
132
|
+
},
|
|
133
|
+
set(sessionId: string, state: SessionCapabilityState): void {
|
|
134
|
+
const decoded = decodeSessionCapabilities(state);
|
|
135
|
+
if (decoded) getStateMap().set(sessionId, decoded);
|
|
136
|
+
},
|
|
137
|
+
clear(sessionId: string): void {
|
|
138
|
+
getStateMap().delete(sessionId);
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** Register the current session's skill inventory provider. */
|
|
143
|
+
export function registerSessionCapabilitySkillProvider<TContext>(
|
|
144
|
+
sessionId: string,
|
|
145
|
+
provider: SessionCapabilitySkillProvider<TContext>,
|
|
146
|
+
): () => void {
|
|
147
|
+
const providers = getProviderMap();
|
|
148
|
+
providers.set(sessionId, provider as SessionCapabilitySkillProvider<unknown>);
|
|
149
|
+
return () => {
|
|
150
|
+
if (providers.get(sessionId) === provider) providers.delete(sessionId);
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/** Get the current session's skill inventory provider, if one is loaded. */
|
|
155
|
+
export function getSessionCapabilitySkillProvider<TContext = unknown>(
|
|
156
|
+
sessionId: string,
|
|
157
|
+
): SessionCapabilitySkillProvider<TContext> | undefined {
|
|
158
|
+
return getProviderMap().get(sessionId) as SessionCapabilitySkillProvider<TContext> | undefined;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function forkKey(sourceSessionFile: string | undefined): string {
|
|
162
|
+
return sourceSessionFile ?? "<memory-session>";
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Hold a state copy until PI starts the forked session. */
|
|
166
|
+
export function setPendingSessionCapabilityFork(
|
|
167
|
+
sourceSessionFile: string | undefined,
|
|
168
|
+
state: SessionCapabilityState,
|
|
169
|
+
): void {
|
|
170
|
+
const decoded = decodeSessionCapabilities(state);
|
|
171
|
+
if (decoded) getForkMap().set(forkKey(sourceSessionFile), decoded);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Take the state copy for one fork. The copy is used once. */
|
|
175
|
+
export function readPendingSessionCapabilityFork(
|
|
176
|
+
sourceSessionFile: string | undefined,
|
|
177
|
+
): SessionCapabilityState | undefined {
|
|
178
|
+
const forks = getForkMap();
|
|
179
|
+
const key = forkKey(sourceSessionFile);
|
|
180
|
+
const state = forks.get(key);
|
|
181
|
+
forks.delete(key);
|
|
182
|
+
return state ? decodeSessionCapabilities(state) : undefined;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Clear pending fork copies after a cancelled or unrelated transition. */
|
|
186
|
+
export function clearPendingSessionCapabilityForks(): void {
|
|
187
|
+
getForkMap().clear();
|
|
188
|
+
}
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
// supi-core session domain — session utilities and registries.
|
|
2
2
|
|
|
3
3
|
export { createRegistry, createSessionStateRegistry } from "./registry-utils.ts";
|
|
4
|
+
export type {
|
|
5
|
+
SessionCapabilitySkill,
|
|
6
|
+
SessionCapabilitySkillProvider,
|
|
7
|
+
SessionCapabilityState,
|
|
8
|
+
} from "./session-capabilities.ts";
|
|
9
|
+
export {
|
|
10
|
+
clearPendingSessionCapabilityForks,
|
|
11
|
+
createEmptySessionCapabilityState,
|
|
12
|
+
decodeSessionCapabilities,
|
|
13
|
+
findSessionCapabilities,
|
|
14
|
+
getSessionCapabilitySkillProvider,
|
|
15
|
+
readPendingSessionCapabilityFork,
|
|
16
|
+
registerSessionCapabilitySkillProvider,
|
|
17
|
+
SESSION_CAPABILITIES_ENTRY,
|
|
18
|
+
sessionCapabilityState,
|
|
19
|
+
setPendingSessionCapabilityFork,
|
|
20
|
+
} from "./session-capabilities.ts";
|
|
4
21
|
export type { SessionNameTrackerHost } from "./session-utils.ts";
|
|
5
22
|
export {
|
|
6
23
|
createSessionNameTracker,
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
type SelectItem,
|
|
4
|
+
SelectList,
|
|
5
|
+
type TuiMouseEvent,
|
|
6
|
+
type TuiMouseEventResult,
|
|
7
|
+
truncateToWidth,
|
|
8
|
+
visibleWidth,
|
|
9
|
+
wrapTextWithAnsi,
|
|
10
|
+
} from "@earendil-works/pi-tui";
|
|
11
|
+
|
|
12
|
+
/** The theme methods used by the shared TUI list renderers. */
|
|
13
|
+
export type TuiTheme = Pick<Theme, "fg" | "bold">;
|
|
14
|
+
|
|
15
|
+
/** Settings for one selectable row in a themed list. */
|
|
16
|
+
export interface SelectableRowOptions {
|
|
17
|
+
/** The row label. */
|
|
18
|
+
label: string;
|
|
19
|
+
/** The value shown beside the label. */
|
|
20
|
+
value: string;
|
|
21
|
+
/** The row indent in terminal columns. */
|
|
22
|
+
indent: number;
|
|
23
|
+
/** The largest indent used by the list. */
|
|
24
|
+
maxIndent: number;
|
|
25
|
+
/** The label column width. */
|
|
26
|
+
maxLabelWidth: number;
|
|
27
|
+
/** The row width in terminal columns. */
|
|
28
|
+
width: number;
|
|
29
|
+
/** True when this row is selected. */
|
|
30
|
+
selected: boolean;
|
|
31
|
+
/** Theme used for row colors. */
|
|
32
|
+
theme: TuiTheme;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Settings for a shared action menu. */
|
|
36
|
+
export interface SelectListMenuOptions {
|
|
37
|
+
/** The title shown above the choices. */
|
|
38
|
+
title: string;
|
|
39
|
+
/** The choices shown in the menu. */
|
|
40
|
+
items: SelectItem[];
|
|
41
|
+
/** Theme used for menu colors. */
|
|
42
|
+
theme: TuiTheme;
|
|
43
|
+
/** Called when the user selects a choice. */
|
|
44
|
+
onSelect: (item: SelectItem) => void;
|
|
45
|
+
/** Called when the user closes the menu without a choice. */
|
|
46
|
+
onCancel: () => void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Component methods for a shared action menu. */
|
|
50
|
+
export interface SelectListMenuComponent {
|
|
51
|
+
render(width: number): string[];
|
|
52
|
+
invalidate(): void;
|
|
53
|
+
handleInput(data: string): void;
|
|
54
|
+
handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Build a title line with optional right-side tabs in the shared TUI style. */
|
|
58
|
+
export function formatTuiTitleLine(title: string, theme: TuiTheme, trailing = ""): string {
|
|
59
|
+
const titleText = theme.fg("accent", theme.bold(title));
|
|
60
|
+
return ` ${titleText}${trailing ? ` ${trailing}` : ""}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Render one row with a selected marker and an aligned value column. */
|
|
64
|
+
export function renderSelectableRow(options: SelectableRowOptions): string {
|
|
65
|
+
const indent = Math.max(0, options.indent);
|
|
66
|
+
const maxIndent = Math.max(indent, options.maxIndent);
|
|
67
|
+
const maxLabelWidth = Math.max(0, options.maxLabelWidth);
|
|
68
|
+
const width = Math.max(0, options.width);
|
|
69
|
+
const label = truncateToWidth(options.label, maxLabelWidth, "");
|
|
70
|
+
const labelWidth = visibleWidth(label);
|
|
71
|
+
const prefix = options.selected
|
|
72
|
+
? `${" ".repeat(Math.max(0, indent - 2))}${options.theme.fg("accent", "→ ")}`
|
|
73
|
+
: " ".repeat(indent);
|
|
74
|
+
const labelPadding = " ".repeat(maxIndent - indent + maxLabelWidth - labelWidth);
|
|
75
|
+
const valueWidth = Math.max(0, width - maxIndent - maxLabelWidth - 4);
|
|
76
|
+
const value = truncateToWidth(options.value, valueWidth, "");
|
|
77
|
+
const labelText = options.theme.fg(options.selected ? "accent" : "text", label + labelPadding);
|
|
78
|
+
const valueText = options.theme.fg(options.selected ? "accent" : "muted", value);
|
|
79
|
+
|
|
80
|
+
return truncateToWidth(`${prefix}${labelText} ${valueText}`, width);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Render a fixed-height, four-line description preview for a selected row. */
|
|
84
|
+
export function renderDescriptionViewport(
|
|
85
|
+
description: string | undefined,
|
|
86
|
+
width: number,
|
|
87
|
+
): string[] {
|
|
88
|
+
const height = 4;
|
|
89
|
+
const indent = " ";
|
|
90
|
+
const contentWidth = Math.max(1, width - 4);
|
|
91
|
+
const wrapped = description ? wrapTextWithAnsi(description, contentWidth) : [];
|
|
92
|
+
const visible = wrapped.slice(0, height);
|
|
93
|
+
|
|
94
|
+
if (wrapped.length > height) {
|
|
95
|
+
const lastIndex = height - 1;
|
|
96
|
+
visible[lastIndex] = truncateToWidth(`${visible[lastIndex] ?? ""}…`, contentWidth, "…");
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
while (visible.length < height) visible.push("");
|
|
100
|
+
return visible.map((line) => (line ? `${indent}${line}` : ""));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Render a dimmed hint line with the shared separator and truncation rules. */
|
|
104
|
+
export function renderTuiHintLine(hints: string[], theme: TuiTheme, width: number): string {
|
|
105
|
+
return truncateToWidth(theme.fg("dim", hints.join(" · ")), width);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Build the shared title, choices, and key hints for an action menu. */
|
|
109
|
+
export function createSelectListMenu(options: SelectListMenuOptions): SelectListMenuComponent {
|
|
110
|
+
const { items, onSelect, onCancel, theme, title } = options;
|
|
111
|
+
const selectList = new SelectList(items, Math.min(items.length + 2, 15), {
|
|
112
|
+
selectedPrefix: (text) => theme.fg("accent", text),
|
|
113
|
+
selectedText: (text) => theme.fg("accent", text),
|
|
114
|
+
description: (text) => theme.fg("muted", text),
|
|
115
|
+
scrollInfo: (text) => theme.fg("dim", text),
|
|
116
|
+
noMatch: (text) => theme.fg("warning", text),
|
|
117
|
+
});
|
|
118
|
+
selectList.onSelect = onSelect;
|
|
119
|
+
selectList.onCancel = onCancel;
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
render(width) {
|
|
123
|
+
return [
|
|
124
|
+
truncateToWidth(theme.fg("accent", ` ${title}`), width),
|
|
125
|
+
...selectList.render(width),
|
|
126
|
+
"",
|
|
127
|
+
renderTuiHintLine([" ↑↓ navigate", "Enter select", "Esc cancel"], theme, width),
|
|
128
|
+
];
|
|
129
|
+
},
|
|
130
|
+
invalidate() {
|
|
131
|
+
selectList.invalidate();
|
|
132
|
+
},
|
|
133
|
+
handleInput(data) {
|
|
134
|
+
selectList.handleInput(data);
|
|
135
|
+
},
|
|
136
|
+
handleMouse(event) {
|
|
137
|
+
if (event.y < 1) return undefined;
|
|
138
|
+
return selectList.handleMouse({ ...event, y: event.y - 1 });
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mrclrchtr/supi-extras",
|
|
3
|
-
"version": "7.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "7.3.1",
|
|
4
|
+
"description": "Session capability controls, prompt stash, shortcuts, and activity indicators",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"clipboardy": "^5.3.1",
|
|
36
|
-
"@mrclrchtr/supi-core": "7.
|
|
36
|
+
"@mrclrchtr/supi-core": "7.3.1"
|
|
37
37
|
},
|
|
38
38
|
"bundledDependencies": [
|
|
39
39
|
"@mrclrchtr/supi-core"
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import cloneSession from "./clone-session.ts";
|
|
|
3
3
|
import copyPrompt from "./copy-prompt.ts";
|
|
4
4
|
import gitEditor from "./git-editor.ts";
|
|
5
5
|
import promptStash from "./prompt-stash.ts";
|
|
6
|
+
import sessionCapabilities from "./session-capabilities.ts";
|
|
6
7
|
import supiFooter from "./supi-footer.ts";
|
|
7
8
|
import tabSpinner from "./tab-spinner.ts";
|
|
8
9
|
|
|
@@ -13,5 +14,6 @@ export default function (pi: Parameters<typeof tabSpinner>[0]) {
|
|
|
13
14
|
cloneSession(pi);
|
|
14
15
|
gitEditor(pi);
|
|
15
16
|
aliases(pi);
|
|
17
|
+
sessionCapabilities(pi);
|
|
16
18
|
supiFooter(pi);
|
|
17
19
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ExtensionAPI, ToolInfo } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import {
|
|
3
|
+
createEmptySessionCapabilityState,
|
|
4
|
+
type SessionCapabilityState,
|
|
5
|
+
} from "@mrclrchtr/supi-core/session";
|
|
6
|
+
|
|
7
|
+
/** Startup tool names that the session selector may change. */
|
|
8
|
+
export interface ToolBaseline {
|
|
9
|
+
eligibleToolNames: string[];
|
|
10
|
+
initiallyInactiveToolNames: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Return true when PI reports a non-built-in tool source. */
|
|
14
|
+
export function isExtensionTool(tool: ToolInfo): boolean {
|
|
15
|
+
return tool.sourceInfo.source !== "builtin" && tool.sourceInfo.source !== "sdk";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Capture the PI tool set before session overrides run. */
|
|
19
|
+
export function captureToolBaseline(pi: ExtensionAPI): ToolBaseline {
|
|
20
|
+
const tools = pi.getAllTools().filter(isExtensionTool);
|
|
21
|
+
const activeNames = new Set(pi.getActiveTools());
|
|
22
|
+
const eligibleToolNames = tools
|
|
23
|
+
.filter((tool) => activeNames.has(tool.name))
|
|
24
|
+
.map((tool) => tool.name);
|
|
25
|
+
const eligible = new Set(eligibleToolNames);
|
|
26
|
+
return {
|
|
27
|
+
eligibleToolNames,
|
|
28
|
+
initiallyInactiveToolNames: tools
|
|
29
|
+
.filter((tool) => !eligible.has(tool.name))
|
|
30
|
+
.map((tool) => tool.name),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Copy the startup baseline from one saved session state. */
|
|
35
|
+
export function baselineFromState(state: SessionCapabilityState): ToolBaseline {
|
|
36
|
+
return {
|
|
37
|
+
eligibleToolNames: [...state.eligibleToolNames],
|
|
38
|
+
initiallyInactiveToolNames: [...state.initiallyInactiveToolNames],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Add new active tools but keep the startup allowlist boundary. */
|
|
43
|
+
export function addActiveToolsToBaseline(pi: ExtensionAPI, baseline: ToolBaseline): void {
|
|
44
|
+
const eligible = new Set(baseline.eligibleToolNames);
|
|
45
|
+
const initiallyInactive = new Set(baseline.initiallyInactiveToolNames);
|
|
46
|
+
const active = new Set(pi.getActiveTools());
|
|
47
|
+
for (const tool of pi.getAllTools().filter(isExtensionTool)) {
|
|
48
|
+
if (active.has(tool.name) && !initiallyInactive.has(tool.name)) eligible.add(tool.name);
|
|
49
|
+
}
|
|
50
|
+
baseline.eligibleToolNames = Array.from(eligible);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Build a new session with no tool visibility overrides. */
|
|
54
|
+
export function initialSessionCapabilityState(baseline: ToolBaseline): SessionCapabilityState {
|
|
55
|
+
return {
|
|
56
|
+
...createEmptySessionCapabilityState(),
|
|
57
|
+
eligibleToolNames: [...baseline.eligibleToolNames],
|
|
58
|
+
initiallyInactiveToolNames: [...baseline.initiallyInactiveToolNames],
|
|
59
|
+
};
|
|
60
|
+
}
|