pi-cc-extensions 0.8.9 → 0.8.11
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 +3 -2
- package/extensions/agent-autocomplete.ts +11 -16
- package/extensions/ask-user-question/ask-user-question.ts +29 -7
- package/extensions/ask-user-question/config.ts +6 -2
- package/extensions/ask-user-question/index.ts +8 -8
- package/extensions/ask-user-question/rpc-fallback.ts +16 -4
- package/extensions/ask-user-question/state/build-questionnaire.ts +16 -5
- package/extensions/ask-user-question/state/key-router.ts +29 -7
- package/extensions/ask-user-question/state/questionnaire-session.ts +1 -4
- package/extensions/ask-user-question/state/selectors/projections.ts +4 -1
- package/extensions/ask-user-question/state/state-reducer.ts +24 -7
- package/extensions/ask-user-question/tool/response-envelope.ts +4 -1
- package/extensions/ask-user-question/tool/types.ts +5 -1
- package/extensions/ask-user-question/tool/validate-questionnaire.ts +10 -2
- package/extensions/ask-user-question/view/components/inline-input.ts +15 -2
- package/extensions/ask-user-question/view/components/multi-select-view.ts +11 -4
- package/extensions/ask-user-question/view/components/option-list-view.ts +14 -5
- package/extensions/ask-user-question/view/components/preview/preview-block-renderer.ts +13 -7
- package/extensions/ask-user-question/view/components/preview/preview-layout-decider.ts +16 -4
- package/extensions/ask-user-question/view/components/preview/preview-pane.ts +5 -1
- package/extensions/ask-user-question/view/components/submit-picker.ts +3 -1
- package/extensions/ask-user-question/view/components/wrapping-select.ts +20 -4
- package/extensions/ask-user-question/view/dialog-builder.ts +27 -7
- package/extensions/ask-user-question/view/tab-content-strategy.ts +23 -8
- package/extensions/claude-code-style.ts +1722 -1485
- package/extensions/compact-style.ts +120 -43
- package/extensions/context.ts +502 -394
- package/extensions/session-reference-core.ts +8 -3
- package/extensions/session-reference.ts +475 -448
- package/extensions/tool-diff/ATTRIBUTION.md +28 -0
- package/extensions/tool-diff/ansi-utils.ts +113 -0
- package/extensions/tool-diff/diff-presentation.ts +70 -0
- package/extensions/tool-diff/diff-renderer.ts +2827 -0
- package/extensions/tool-diff/index.ts +106 -0
- package/extensions/tool-diff/line-width-safety.ts +91 -0
- package/extensions/tool-diff/render-utils.ts +5 -0
- package/extensions/tool-diff/types.ts +20 -0
- package/extensions/tool-diff/write-display-utils.ts +29 -0
- package/extensions/tool-diff/write-execution.ts +113 -0
- package/extensions/tool-result-sanitize.ts +4 -4
- package/package.json +64 -61
- package/themes/github-dark-default.json +91 -91
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Attribution
|
|
2
|
+
|
|
3
|
+
The rich diff renderer in this directory is adapted from
|
|
4
|
+
[MasuRii/pi-tool-display](https://github.com/MasuRii/pi-tool-display) at commit
|
|
5
|
+
`91cef7580078371f8dc49a8607222807ad6a424d`.
|
|
6
|
+
|
|
7
|
+
Copyright (c) MasuRii and pi-tool-display contributors. Used under the MIT
|
|
8
|
+
License. The upstream license text is reproduced below.
|
|
9
|
+
|
|
10
|
+
> MIT License
|
|
11
|
+
>
|
|
12
|
+
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
> of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
> in the Software without restriction, including without limitation the rights
|
|
15
|
+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
> copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
> furnished to do so, subject to the following conditions:
|
|
18
|
+
>
|
|
19
|
+
> The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
> copies or substantial portions of the Software.
|
|
21
|
+
>
|
|
22
|
+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
> SOFTWARE.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const ANSI_SGR_PATTERN = /\x1b\[([0-9;]*)m/g;
|
|
2
|
+
const STYLE_RESET_PARAMS = [39, 22, 23, 24, 25, 27, 28, 29, 59] as const;
|
|
3
|
+
|
|
4
|
+
export { ANSI_SGR_PATTERN, STYLE_RESET_PARAMS };
|
|
5
|
+
|
|
6
|
+
export function expandSgrReset(param: number): readonly number[] | undefined {
|
|
7
|
+
return param === 0 ? STYLE_RESET_PARAMS : undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function toSgrParams(rawParams: string): number[] {
|
|
11
|
+
if (!rawParams.trim()) {
|
|
12
|
+
return [0];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const parsed = rawParams
|
|
16
|
+
.split(";")
|
|
17
|
+
.map((token) => Number.parseInt(token, 10))
|
|
18
|
+
.filter((value) => Number.isFinite(value));
|
|
19
|
+
|
|
20
|
+
return parsed.length > 0 ? parsed : [];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function isFiniteSgrParam(value: number | undefined): value is number {
|
|
24
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function readSgrColorSequence(params: number[], index: number): number[] | undefined {
|
|
28
|
+
const param = params[index];
|
|
29
|
+
if (param !== 38 && param !== 48) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const colorMode = params[index + 1];
|
|
34
|
+
if (colorMode === 5) {
|
|
35
|
+
const colorValue = params[index + 2];
|
|
36
|
+
return isFiniteSgrParam(colorValue) ? [param, colorMode, colorValue] : undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (colorMode === 2) {
|
|
40
|
+
const red = params[index + 2];
|
|
41
|
+
const green = params[index + 3];
|
|
42
|
+
const blue = params[index + 4];
|
|
43
|
+
return isFiniteSgrParam(red) && isFiniteSgrParam(green) && isFiniteSgrParam(blue)
|
|
44
|
+
? [param, colorMode, red, green, blue]
|
|
45
|
+
: undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function stripBackgroundSgrParams(params: readonly number[]): number[] {
|
|
52
|
+
const sanitized: number[] = [];
|
|
53
|
+
|
|
54
|
+
for (let index = 0; index < params.length; index++) {
|
|
55
|
+
const param = params[index] ?? 0;
|
|
56
|
+
|
|
57
|
+
if (param === 0) {
|
|
58
|
+
sanitized.push(...expandSgrReset(param)!);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (param === 49 || (param >= 40 && param <= 47) || (param >= 100 && param <= 107)) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (param === 38 || param === 48) {
|
|
67
|
+
const sequence = readSgrColorSequence(params as number[], index);
|
|
68
|
+
if (sequence) {
|
|
69
|
+
if (param === 38) {
|
|
70
|
+
sanitized.push(...sequence);
|
|
71
|
+
}
|
|
72
|
+
index += sequence.length - 1;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const advance = params[index + 1] === 5 ? 2 : params[index + 1] === 2 ? 4 : 0;
|
|
76
|
+
if (advance > 0) {
|
|
77
|
+
index += advance;
|
|
78
|
+
if (param === 38) {
|
|
79
|
+
sanitized.push(param);
|
|
80
|
+
}
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
sanitized.push(param);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return sanitized;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function filterSgrSequences(text: string, filter: (params: number[]) => number[]): string {
|
|
92
|
+
if (!text || !text.includes("\x1b[")) {
|
|
93
|
+
return text;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return text.replace(ANSI_SGR_PATTERN, (_sequence, rawParams: string) => {
|
|
97
|
+
const parsed = toSgrParams(rawParams);
|
|
98
|
+
if (parsed.length === 0) {
|
|
99
|
+
return "";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const sanitized = filter(parsed);
|
|
103
|
+
if (sanitized.length === 0) {
|
|
104
|
+
return "";
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return `\x1b[${sanitized.join(";")}m`;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function sanitizeAnsiForThemedOutput(text: string): string {
|
|
112
|
+
return filterSgrSequences(text, stripBackgroundSgrParams);
|
|
113
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
import { pluralize } from "./render-utils.ts";
|
|
3
|
+
import type { ToolDisplayConfig } from "./types.ts";
|
|
4
|
+
|
|
5
|
+
export interface DiffSummaryStats {
|
|
6
|
+
added: number;
|
|
7
|
+
removed: number;
|
|
8
|
+
hunks: number;
|
|
9
|
+
files: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type DiffPresentationMode = "split" | "unified" | "compact" | "summary";
|
|
13
|
+
|
|
14
|
+
const MIN_COMPACT_DIFF_WIDTH = 8;
|
|
15
|
+
const MIN_UNIFIED_DIFF_WIDTH = 18;
|
|
16
|
+
|
|
17
|
+
export function normalizeDiffRenderWidth(width: number): number {
|
|
18
|
+
if (!Number.isFinite(width)) {
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
return Math.max(0, Math.floor(width));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function resolveDiffPresentationMode(
|
|
25
|
+
config: Pick<ToolDisplayConfig, "diffViewMode" | "diffSplitMinWidth">,
|
|
26
|
+
width: number,
|
|
27
|
+
canRenderSplitLayout: boolean,
|
|
28
|
+
): DiffPresentationMode {
|
|
29
|
+
const safeWidth = normalizeDiffRenderWidth(width);
|
|
30
|
+
if (safeWidth < MIN_COMPACT_DIFF_WIDTH) {
|
|
31
|
+
return "summary";
|
|
32
|
+
}
|
|
33
|
+
if (safeWidth < MIN_UNIFIED_DIFF_WIDTH) {
|
|
34
|
+
return "compact";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
switch (config.diffViewMode) {
|
|
38
|
+
case "split":
|
|
39
|
+
return canRenderSplitLayout ? "split" : "unified";
|
|
40
|
+
case "unified":
|
|
41
|
+
return "unified";
|
|
42
|
+
case "auto":
|
|
43
|
+
default:
|
|
44
|
+
return safeWidth >= config.diffSplitMinWidth && canRenderSplitLayout ? "split" : "unified";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function buildDiffSummaryText(stats: DiffSummaryStats, width: number): string {
|
|
49
|
+
const safeWidth = normalizeDiffRenderWidth(width);
|
|
50
|
+
if (safeWidth === 0) {
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const summaryCandidates = [
|
|
55
|
+
`↳ diff +${stats.added} -${stats.removed} • ${stats.hunks} ${pluralize(stats.hunks, "hunk")} • ${stats.files} ${pluralize(stats.files, "file")}`,
|
|
56
|
+
`↳ diff +${stats.added} -${stats.removed} • ${stats.hunks}h • ${stats.files}f`,
|
|
57
|
+
`↳ diff +${stats.added} -${stats.removed}`,
|
|
58
|
+
`+${stats.added} -${stats.removed}`,
|
|
59
|
+
"diff",
|
|
60
|
+
"…",
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
for (const candidate of summaryCandidates) {
|
|
64
|
+
if (visibleWidth(candidate) <= safeWidth) {
|
|
65
|
+
return candidate;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return truncateToWidth(summaryCandidates[summaryCandidates.length - 1] ?? "", safeWidth, "");
|
|
70
|
+
}
|