@0xkahi/pi-qol 1.3.0 → 1.4.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 +24 -10
- package/assets/config.schema.json +5 -0
- package/package.json +4 -4
- package/src/extensions/context-view/capture.ts +74 -35
- package/src/extensions/context-view/codemap.md +24 -16
- package/src/extensions/context-view/constants.ts +3 -0
- package/src/extensions/context-view/context-view-controller.ts +47 -13
- package/src/extensions/context-view/index.ts +25 -9
- package/src/extensions/context-view/measure.ts +2 -1
- package/src/extensions/context-view/model.ts +44 -3
- package/src/extensions/context-view/presentation.ts +6 -0
- package/src/extensions/context-view/prompt-additions.ts +5 -3
- package/src/extensions/context-view/ui/codemap.md +60 -93
- package/src/extensions/context-view/ui/context-view-dialog.ts +14 -7
- package/src/extensions/context-view/ui/copy.ts +42 -0
- package/src/extensions/context-view/ui/highlight.ts +91 -0
- package/src/extensions/context-view/ui/injections-model.ts +52 -0
- package/src/extensions/context-view/ui/injections-view.ts +124 -27
- package/src/extensions/context-view/ui/search.ts +28 -0
- package/src/extensions/context-view/ui/searchable-preview.ts +175 -0
- package/src/extensions/context-view/ui/usage-block-layer.ts +18 -7
- package/src/extensions/context-view/ui/usage-view.ts +57 -24
- package/src/extensions/custom-footer/footer-component.ts +1 -1
- package/src/extensions/model-select/codemap.md +1 -1
- package/src/libs/modal/README.md +13 -6
- package/src/libs/modal/codemap.md +6 -6
- package/src/libs/modal/index.ts +1 -1
- package/src/libs/modal/modal-dialog.ts +44 -3
- package/src/libs/modal/preview-layer.ts +3 -3
- package/src/libs/modal/sectioned-modal.ts +3 -3
- package/src/libs/modal/types.ts +11 -0
- package/src/libs/subscription-usage/codemap.md +4 -3
- package/src/libs/subscription-usage/credential-resolver.ts +12 -4
- package/src/libs/subscription-usage/index.ts +1 -0
- package/src/libs/subscription-usage/provider-color.ts +1 -0
- package/src/libs/subscription-usage/strategy/opencode-go-usage.strategy.ts +45 -0
- package/src/libs/subscription-usage/subscription-usage-api.util.ts +4 -1
- package/src/libs/subscription-usage/subscription-usage-cache.ts +11 -1
- package/src/schemas/context-view.config.schema.ts +2 -0
- package/src/extensions/context-view/ui/wheel-preview-layer.ts +0 -104
- package/src/extensions/context-view/ui/wheel.ts +0 -66
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import { formatResetDescription } from './pace';
|
|
2
2
|
import { AnthropicOauthUsageStrategy } from './strategy/anthropic-oauth-usage.strategy';
|
|
3
3
|
import { OpenAiCodexUsageStrategy } from './strategy/openai-codex-usage.strategy';
|
|
4
|
+
import { OpenCodeGoUsageStrategy } from './strategy/opencode-go-usage.strategy';
|
|
4
5
|
import {
|
|
5
6
|
type RateWindow,
|
|
6
7
|
SUBSCRIPTION_USAGE_TTL_MS,
|
|
7
8
|
type SubscriptionProvider,
|
|
8
9
|
SubscriptionUsageApi,
|
|
9
10
|
type SubscriptionUsageApiLike,
|
|
11
|
+
type SubscriptionUsageStrategy,
|
|
10
12
|
type UsageResult,
|
|
11
13
|
} from './subscription-usage-api.util';
|
|
12
14
|
|
|
15
|
+
const STRATEGIES: Record<SubscriptionProvider, SubscriptionUsageStrategy> = {
|
|
16
|
+
anthropic: new AnthropicOauthUsageStrategy(),
|
|
17
|
+
'openai-codex': new OpenAiCodexUsageStrategy(),
|
|
18
|
+
'opencode-go': new OpenCodeGoUsageStrategy(),
|
|
19
|
+
};
|
|
20
|
+
|
|
13
21
|
export type UsageCacheEntry = { result?: UsageResult; lastSuccess?: { windows: RateWindow[]; fetchedAt: number }; inFlight: boolean };
|
|
14
22
|
|
|
15
23
|
export function resolveSupportedProvider(provider?: string): SubscriptionProvider | undefined {
|
|
16
24
|
switch (provider?.toLowerCase()) {
|
|
25
|
+
case 'opencode-go':
|
|
26
|
+
return 'opencode-go';
|
|
17
27
|
case 'anthropic':
|
|
18
28
|
return 'anthropic';
|
|
19
29
|
case 'openai-codex':
|
|
@@ -64,7 +74,7 @@ export class SubscriptionUsageCache {
|
|
|
64
74
|
const entry: UsageCacheEntry = { ...this.get(provider), inFlight: true };
|
|
65
75
|
this.entries.set(provider, entry);
|
|
66
76
|
this.lastAttemptAt.set(provider, this.now());
|
|
67
|
-
const strategy = provider
|
|
77
|
+
const strategy = STRATEGIES[provider];
|
|
68
78
|
void Promise.resolve()
|
|
69
79
|
.then(() => this.api.fetchUsage(strategy))
|
|
70
80
|
.catch((): UsageResult => ({ status: 'network', label: strategy.label }))
|
|
@@ -5,6 +5,7 @@ export type ContextViewLayout = z.infer<typeof ContextViewLayoutSchema>;
|
|
|
5
5
|
|
|
6
6
|
export const ContextViewConfigSchema = z.object({
|
|
7
7
|
enabled: z.boolean().default(false),
|
|
8
|
+
auto_probing: z.boolean().default(true),
|
|
8
9
|
layout: ContextViewLayoutSchema.default('inline'),
|
|
9
10
|
});
|
|
10
11
|
export type ContextViewConfig = z.infer<typeof ContextViewConfigSchema>;
|
|
@@ -13,6 +14,7 @@ export const DEFAULT_CONTEXT_VIEW_CONFIG = ContextViewConfigSchema.parse({});
|
|
|
13
14
|
|
|
14
15
|
export const PartialContextViewConfigSchema = z.object({
|
|
15
16
|
enabled: z.boolean().optional(),
|
|
17
|
+
auto_probing: z.boolean().optional(),
|
|
16
18
|
layout: ContextViewLayoutSchema.optional(),
|
|
17
19
|
});
|
|
18
20
|
export type PartialContextViewConfig = z.infer<typeof PartialContextViewConfigSchema>;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Context View preview layer with mouse-wheel support.
|
|
3
|
-
*
|
|
4
|
-
* The shared modal `PreviewLayer` is scroll-only through semantic navigation
|
|
5
|
-
* actions; the Context View adds opt-in wheel scrolling on top, since pi
|
|
6
|
-
* forwards wheel reports only to a focused overlay and never consumes them
|
|
7
|
-
* itself. This layer mirrors the shared preview frame while stepping its own
|
|
8
|
-
* `PreviewScroller` on a wheel notch.
|
|
9
|
-
*/
|
|
10
|
-
import type { Theme } from '@earendil-works/pi-coding-agent';
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
BODY_INDENT,
|
|
14
|
-
calculateViewport,
|
|
15
|
-
fitLine,
|
|
16
|
-
type Hint,
|
|
17
|
-
type ModalLayer,
|
|
18
|
-
type NavigationAction,
|
|
19
|
-
PreviewScroller,
|
|
20
|
-
spreadLine,
|
|
21
|
-
} from '../../../libs/modal';
|
|
22
|
-
import { DEFAULT_WHEEL_SCROLL_LINES, parseWheelDirection } from './wheel';
|
|
23
|
-
|
|
24
|
-
export interface WheelPreviewLayerOptions {
|
|
25
|
-
/** Styled title rendered on the left of the header line. */
|
|
26
|
-
title: string | (() => string);
|
|
27
|
-
/** Muted metadata rendered right-aligned beside the title. */
|
|
28
|
-
meta?: string | (() => string);
|
|
29
|
-
/** Body lines for the given width; wrapping is the caller's concern. */
|
|
30
|
-
body: (width: number) => string[];
|
|
31
|
-
/** Optional fixed description lines pinned below the body, given the layer's width and height. */
|
|
32
|
-
description?: (width: number, height: number | undefined) => string[];
|
|
33
|
-
/** Layer-specific hints appended after the navigation scheme's hints. */
|
|
34
|
-
hints?: () => Hint[];
|
|
35
|
-
/** Lines one wheel notch scrolls; defaults to the project fallback. */
|
|
36
|
-
wheelScrollLines?: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class WheelPreviewLayer implements ModalLayer {
|
|
40
|
-
private readonly scroller = new PreviewScroller();
|
|
41
|
-
|
|
42
|
-
public constructor(
|
|
43
|
-
private readonly theme: Theme,
|
|
44
|
-
private readonly options: WheelPreviewLayerOptions,
|
|
45
|
-
) {}
|
|
46
|
-
|
|
47
|
-
public hints(): Hint[] {
|
|
48
|
-
return this.options.hints?.() ?? [];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Scroll one wheel notch; every other raw key is ignored by the preview. */
|
|
52
|
-
public handleInput(data: string): void {
|
|
53
|
-
const wheel = parseWheelDirection(data);
|
|
54
|
-
if (wheel === undefined) return;
|
|
55
|
-
this.scroller.scrollBy(wheel * (this.options.wheelScrollLines ?? DEFAULT_WHEEL_SCROLL_LINES));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
public handleNavigation(action: NavigationAction): void {
|
|
59
|
-
switch (action) {
|
|
60
|
-
case 'step-back':
|
|
61
|
-
this.scroller.scrollBy(-1);
|
|
62
|
-
break;
|
|
63
|
-
case 'step-forward':
|
|
64
|
-
this.scroller.scrollBy(1);
|
|
65
|
-
break;
|
|
66
|
-
case 'page-back':
|
|
67
|
-
this.scroller.page(-1);
|
|
68
|
-
break;
|
|
69
|
-
case 'page-forward':
|
|
70
|
-
this.scroller.page(1);
|
|
71
|
-
break;
|
|
72
|
-
case 'first':
|
|
73
|
-
this.scroller.scrollTo(0);
|
|
74
|
-
break;
|
|
75
|
-
case 'last':
|
|
76
|
-
this.scroller.scrollTo(this.scroller.maxOffset);
|
|
77
|
-
break;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
public render(width: number, height: number | undefined): string[] {
|
|
82
|
-
const body = this.options.body(width);
|
|
83
|
-
const description = this.options.description?.(width, height) ?? [];
|
|
84
|
-
// title + blank, plus blank + description when present
|
|
85
|
-
const fixedLineCount = 2 + (description.length > 0 ? description.length + 1 : 0);
|
|
86
|
-
const viewport = calculateViewport(body.length, height ?? body.length + fixedLineCount, fixedLineCount);
|
|
87
|
-
this.scroller.setExtent(body.length, viewport.visibleCount);
|
|
88
|
-
|
|
89
|
-
const title = typeof this.options.title === 'function' ? this.options.title() : this.options.title;
|
|
90
|
-
const metaOption = this.options.meta;
|
|
91
|
-
const meta = typeof metaOption === 'function' ? metaOption() : (metaOption ?? '');
|
|
92
|
-
|
|
93
|
-
const lines: string[] = [spreadLine(title, meta, width), ''];
|
|
94
|
-
const start = this.scroller.offset;
|
|
95
|
-
for (let index = start; index < start + viewport.visibleCount; index++) {
|
|
96
|
-
lines.push(body[index] ?? '');
|
|
97
|
-
}
|
|
98
|
-
if (viewport.showScroll) {
|
|
99
|
-
lines.push(fitLine(this.theme.fg('dim', `${BODY_INDENT}(${this.scroller.visibleEnd}/${body.length})`), width));
|
|
100
|
-
}
|
|
101
|
-
if (description.length > 0) lines.push('', ...description);
|
|
102
|
-
return lines;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mouse-wheel input shared by the Usage and Injections views.
|
|
3
|
-
*
|
|
4
|
-
* Pi enables mouse reporting only in fullscreen (alt-screen) mode, where its
|
|
5
|
-
* viewport forwards wheel reports to the focused overlay instead of consuming
|
|
6
|
-
* them. In regular mode the terminal keeps the wheel for its own scrollback and
|
|
7
|
-
* no report ever reaches a view, so the parser simply never matches there.
|
|
8
|
-
*/
|
|
9
|
-
import type { TUI } from '@earendil-works/pi-tui';
|
|
10
|
-
|
|
11
|
-
/** Lines one notch scrolls when the TUI exposes no step of its own. */
|
|
12
|
-
export const DEFAULT_WHEEL_SCROLL_LINES = 3;
|
|
13
|
-
|
|
14
|
-
/** SGR wheel report: `ESC [ < button ; column ; row` closed by `M` or `m`. */
|
|
15
|
-
// biome-ignore lint/suspicious/noControlCharactersInRegex: wheel reports begin with the escape byte.
|
|
16
|
-
const SGR_WHEEL_PATTERN = /^\x1b\[<(\d+);\d+;\d+[Mm]$/;
|
|
17
|
-
|
|
18
|
-
/** Legacy X10 wheel report: `ESC [ M` plus offset-encoded button, column, and row bytes. */
|
|
19
|
-
const X10_PREFIX = '\x1b[M';
|
|
20
|
-
const X10_LENGTH = 6;
|
|
21
|
-
const X10_BUTTON_INDEX = 3;
|
|
22
|
-
const X10_BYTE_OFFSET = 32;
|
|
23
|
-
|
|
24
|
-
/** Wheel reports set this button bit; the low two bits then carry axis and direction. */
|
|
25
|
-
const WHEEL_BUTTON_BIT = 64;
|
|
26
|
-
const DIRECTION_MASK = 3;
|
|
27
|
-
|
|
28
|
-
/** One notch backwards (up) or forwards (down). */
|
|
29
|
-
export type WheelDirection = -1 | 1;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Vertical wheel direction encoded in one input chunk, or undefined for every
|
|
33
|
-
* other input, including horizontal notches. Modifier bits are ignored, so a
|
|
34
|
-
* modified notch scrolls like a plain one, as it does in pi's own viewport.
|
|
35
|
-
*/
|
|
36
|
-
export function parseWheelDirection(data: string): WheelDirection | undefined {
|
|
37
|
-
const sgrButton = SGR_WHEEL_PATTERN.exec(data)?.[1];
|
|
38
|
-
if (sgrButton !== undefined) return decodeWheelButton(Number.parseInt(sgrButton, 10));
|
|
39
|
-
if (data.length === X10_LENGTH && data.startsWith(X10_PREFIX)) {
|
|
40
|
-
return decodeWheelButton(data.charCodeAt(X10_BUTTON_INDEX) - X10_BYTE_OFFSET);
|
|
41
|
-
}
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Lines one notch scrolls in the surrounding TUI.
|
|
47
|
-
*
|
|
48
|
-
* `TuiAltScreen` keeps its `wheelScrollLines` option private and pi never
|
|
49
|
-
* surfaces it, so read it defensively: honoring the real step keeps previews
|
|
50
|
-
* consistent with the transcript viewport, while any pi that hides, renames, or
|
|
51
|
-
* never had the field falls back to the default instead of a contradicting step.
|
|
52
|
-
*/
|
|
53
|
-
export function readWheelScrollLines(tui: TUI): number {
|
|
54
|
-
const lines = (tui as { readonly wheelScrollLines?: unknown }).wheelScrollLines;
|
|
55
|
-
if (typeof lines !== 'number' || !Number.isFinite(lines)) return DEFAULT_WHEEL_SCROLL_LINES;
|
|
56
|
-
return Math.max(1, Math.floor(lines));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** Decode one button code, rejecting non-wheel buttons and the horizontal axis. */
|
|
60
|
-
function decodeWheelButton(button: number): WheelDirection | undefined {
|
|
61
|
-
if ((button & WHEEL_BUTTON_BIT) === 0) return undefined;
|
|
62
|
-
const direction = button & DIRECTION_MASK;
|
|
63
|
-
if (direction === 0) return -1;
|
|
64
|
-
if (direction === 1) return 1;
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|