@narumitw/pi-starship 0.55.1 → 0.56.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/README.md +2 -0
- package/dist/chunks/{chunk-UX6PBXVK.js → chunk-SD7TUSSU.js} +113 -113
- package/dist/chunks/chunk-SD7TUSSU.js.map +7 -0
- package/dist/chunks/{chunk-P4XMFSQW.js → chunk-YWY5RIDQ.js} +3 -7
- package/dist/chunks/chunk-YWY5RIDQ.js.map +7 -0
- package/dist/chunks/{chunk-EOGXAMTA.js → chunk-ZQZSXXPI.js} +1 -1
- package/dist/chunks/chunk-ZQZSXXPI.js.map +7 -0
- package/dist/chunks/{cloud-BKHYWCTA.js → cloud-C4VU3TX3.js} +7 -14
- package/dist/chunks/cloud-C4VU3TX3.js.map +7 -0
- package/dist/chunks/{commands-53ZO2JUK.js → commands-MJCAK6JL.js} +18 -42
- package/dist/chunks/commands-MJCAK6JL.js.map +7 -0
- package/dist/chunks/{deployment-RKKOEQQ2.js → deployment-FMNTYRBW.js} +6 -21
- package/dist/chunks/deployment-FMNTYRBW.js.map +7 -0
- package/dist/chunks/{development-BERD42HW.js → development-OUYXDPBS.js} +4 -8
- package/dist/chunks/development-OUYXDPBS.js.map +7 -0
- package/dist/chunks/{execution-42JTEY3N.js → execution-HJOGLMWD.js} +3 -3
- package/dist/chunks/execution-HJOGLMWD.js.map +7 -0
- package/dist/chunks/{languages-RMP6DW7H.js → languages-WXMF4GOF.js} +6 -22
- package/dist/chunks/languages-WXMF4GOF.js.map +7 -0
- package/dist/chunks/{package-LG5H7BBM.js → package-YXRZQAOV.js} +5 -14
- package/dist/chunks/package-YXRZQAOV.js.map +7 -0
- package/dist/index.ts +20 -55
- package/dist/index.ts.map +2 -2
- package/package.json +60 -61
- package/skills/configuring-pi-starship/SKILL.md +18 -4
- package/skills/configuring-pi-starship/references/configuration.md +70 -2
- package/skills/configuring-pi-starship/references/module-catalog.md +21 -0
- package/skills/configuring-pi-starship/references/modules.md +2 -0
- package/skills/configuring-pi-starship/scripts/apply.mjs +48 -47
- package/skills/configuring-pi-starship/scripts/backup.mjs +118 -0
- package/skills/configuring-pi-starship/scripts/config-path.mjs +3 -3
- package/skills/configuring-pi-starship/scripts/script-support.mjs +6 -6
- package/skills/configuring-pi-starship/scripts/validate.mjs +18 -18
- package/src/command-configuration.ts +267 -286
- package/src/command-contract.ts +6 -6
- package/src/command-inspector.ts +27 -27
- package/src/command-preset-picker.ts +45 -50
- package/src/command-preview.ts +153 -166
- package/src/commands.ts +590 -618
- package/src/config.ts +635 -660
- package/src/effective-config.ts +49 -48
- package/src/format/formatter.ts +211 -227
- package/src/format/style.ts +205 -216
- package/src/modules/activity.ts +74 -74
- package/src/modules/brand.ts +9 -9
- package/src/modules/cache.ts +18 -18
- package/src/modules/catalog.ts +79 -83
- package/src/modules/cloud.ts +54 -54
- package/src/modules/context.ts +27 -27
- package/src/modules/cost.ts +23 -23
- package/src/modules/deployment.ts +45 -45
- package/src/modules/development.ts +80 -81
- package/src/modules/directory.ts +89 -113
- package/src/modules/display.ts +9 -9
- package/src/modules/execution.ts +62 -69
- package/src/modules/extension-status.ts +59 -64
- package/src/modules/fill.ts +10 -10
- package/src/modules/git/branch.ts +26 -26
- package/src/modules/git/commit.ts +21 -23
- package/src/modules/git/metrics.ts +22 -22
- package/src/modules/git/runtime.ts +299 -334
- package/src/modules/git/state.ts +17 -17
- package/src/modules/git/status.ts +77 -79
- package/src/modules/git/worktree.ts +10 -12
- package/src/modules/github-pr.ts +20 -20
- package/src/modules/helpers.ts +3 -3
- package/src/modules/index.ts +21 -21
- package/src/modules/inspection.ts +105 -108
- package/src/modules/languages.ts +52 -59
- package/src/modules/model.ts +61 -67
- package/src/modules/package.ts +12 -12
- package/src/modules/provider.ts +25 -24
- package/src/modules/render.ts +131 -141
- package/src/modules/style-rules.ts +21 -0
- package/src/modules/thinking.ts +31 -26
- package/src/modules/time.ts +10 -13
- package/src/modules/tokens.ts +13 -13
- package/src/modules/truncation.ts +14 -17
- package/src/modules/turn.ts +9 -9
- package/src/modules/types.ts +133 -132
- package/src/modules/workspace-helpers.ts +4 -7
- package/src/pi-starship.ts +567 -603
- package/src/presets/catalog.ts +113 -113
- package/src/runtime/cloud.ts +122 -150
- package/src/runtime/command.ts +106 -108
- package/src/runtime/deployment.ts +150 -179
- package/src/runtime/development.ts +107 -124
- package/src/runtime/execution.ts +110 -124
- package/src/runtime/github-pr.ts +223 -252
- package/src/runtime/helpers.ts +186 -199
- package/src/runtime/languages.ts +149 -180
- package/src/runtime/package.ts +74 -87
- package/src/runtime/refresh-controller.ts +82 -86
- package/src/runtime/types.ts +38 -38
- package/src/runtime/workspace.ts +108 -116
- package/src/usage.ts +40 -40
- package/dist/chunks/chunk-EOGXAMTA.js.map +0 -7
- package/dist/chunks/chunk-P4XMFSQW.js.map +0 -7
- package/dist/chunks/chunk-UX6PBXVK.js.map +0 -7
- package/dist/chunks/cloud-BKHYWCTA.js.map +0 -7
- package/dist/chunks/commands-53ZO2JUK.js.map +0 -7
- package/dist/chunks/deployment-RKKOEQQ2.js.map +0 -7
- package/dist/chunks/development-BERD42HW.js.map +0 -7
- package/dist/chunks/execution-42JTEY3N.js.map +0 -7
- package/dist/chunks/languages-RMP6DW7H.js.map +0 -7
- package/dist/chunks/package-LG5H7BBM.js.map +0 -7
package/src/modules/render.ts
CHANGED
|
@@ -1,167 +1,157 @@
|
|
|
1
1
|
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
2
2
|
import { activePalette, type ModuleConfig, type StarshipConfig } from "../config.js";
|
|
3
3
|
import { type FormatValue, formatVariables, renderFormat } from "../format/formatter.js";
|
|
4
|
-
import {
|
|
5
|
-
isFillChunk,
|
|
6
|
-
type LayoutChunk,
|
|
7
|
-
renderChunksToAnsi,
|
|
8
|
-
type StyledChunk,
|
|
9
|
-
} from "../format/style.js";
|
|
4
|
+
import { isFillChunk, type LayoutChunk, renderChunksToAnsi, type StyledChunk } from "../format/style.js";
|
|
10
5
|
import { MODULE_DEFINITIONS, MODULE_NAMES, type ModuleName } from "./catalog.js";
|
|
11
|
-
import
|
|
6
|
+
import { resolveStyleRule } from "./style-rules.js";
|
|
7
|
+
import type { ModuleStyleContext, ModuleValueContext, RenderedStatusline, StarshipRuntimeSnapshot } from "./types.js";
|
|
12
8
|
|
|
13
9
|
export function renderStatusline(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
config: StarshipConfig,
|
|
11
|
+
runtime: StarshipRuntimeSnapshot,
|
|
12
|
+
width = 80,
|
|
13
|
+
trueColor = true,
|
|
18
14
|
): RenderedStatusline<ModuleName> {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
15
|
+
const palette = activePalette(config);
|
|
16
|
+
const modules = {} as Record<ModuleName, StyledChunk[]>;
|
|
17
|
+
const layoutModules = {} as Record<ModuleName, LayoutChunk[]>;
|
|
18
|
+
for (const name of MODULE_NAMES) {
|
|
19
|
+
modules[name] = [];
|
|
20
|
+
layoutModules[name] = [];
|
|
21
|
+
}
|
|
22
|
+
for (const definition of MODULE_DEFINITIONS) {
|
|
23
|
+
const name = definition.name;
|
|
24
|
+
const module = config.modules[name];
|
|
25
|
+
const values = definition.values(valueContext(config, name, runtime));
|
|
26
|
+
if (!values) continue;
|
|
27
|
+
const styleContext: ModuleStyleContext = {
|
|
28
|
+
runtime,
|
|
29
|
+
values,
|
|
30
|
+
style: module.style,
|
|
31
|
+
styles: module.styles,
|
|
32
|
+
display: module.display,
|
|
33
|
+
};
|
|
34
|
+
const baseStyleVariables = definition.resolveStyleVariables
|
|
35
|
+
? definition.resolveStyleVariables(styleContext)
|
|
36
|
+
: { style: module.style };
|
|
37
|
+
if (!baseStyleVariables) continue;
|
|
38
|
+
const ruleStyle = definition.styleRuleSelectors
|
|
39
|
+
? resolveStyleRule(module.styleRules, definition.styleRuleSelectors, styleContext)
|
|
40
|
+
: undefined;
|
|
41
|
+
const styleVariables = ruleStyle === undefined ? baseStyleVariables : { ...baseStyleVariables, style: ruleStyle };
|
|
42
|
+
const contentValues = Object.fromEntries(
|
|
43
|
+
definition.variables.flatMap((variable) =>
|
|
44
|
+
variable !== "symbol" && Object.hasOwn(values, variable) ? [[variable, values[variable]]] : [],
|
|
45
|
+
),
|
|
46
|
+
);
|
|
47
|
+
const rendered = renderModule(module, contentValues, styleVariables, palette);
|
|
48
|
+
modules[name] = rendered;
|
|
49
|
+
layoutModules[name] =
|
|
50
|
+
definition.layout === "fill" && !module.disabled ? [{ type: "fill", pattern: rendered }] : rendered;
|
|
51
|
+
}
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
53
|
+
const explicitModules = formatVariables(config.formatAst);
|
|
54
|
+
const all = MODULE_NAMES.flatMap((name) =>
|
|
55
|
+
explicitModules.has(name) || config.modules[name].disabled ? [] : layoutModules[name],
|
|
56
|
+
);
|
|
57
|
+
const rootVariables: Record<string, FormatValue> = { all };
|
|
58
|
+
for (const name of MODULE_NAMES) rootVariables[name] = layoutModules[name];
|
|
59
|
+
const layout = renderFormat(config.formatAst, { variables: rootVariables, palette });
|
|
60
|
+
const chunks = resolveFillLayout(layout, width);
|
|
61
|
+
return {
|
|
62
|
+
ansi: renderChunksToAnsi(chunks, trueColor),
|
|
63
|
+
chunks,
|
|
64
|
+
modules,
|
|
65
|
+
};
|
|
69
66
|
}
|
|
70
67
|
|
|
71
|
-
function valueContext(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
symbol: config.modules[name].symbol,
|
|
79
|
-
options: config.modules[name].options,
|
|
80
|
-
extensionStatus: config.extensionStatus,
|
|
81
|
-
};
|
|
68
|
+
function valueContext(config: StarshipConfig, name: ModuleName, runtime: StarshipRuntimeSnapshot): ModuleValueContext {
|
|
69
|
+
return {
|
|
70
|
+
runtime,
|
|
71
|
+
symbol: config.modules[name].symbol,
|
|
72
|
+
options: config.modules[name].options,
|
|
73
|
+
extensionStatus: config.extensionStatus,
|
|
74
|
+
};
|
|
82
75
|
}
|
|
83
76
|
|
|
84
77
|
function renderModule(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
78
|
+
module: ModuleConfig,
|
|
79
|
+
values: Readonly<Record<string, FormatValue>>,
|
|
80
|
+
styleVariables: Readonly<Record<string, string>>,
|
|
81
|
+
palette: Readonly<Record<string, string>>,
|
|
89
82
|
): StyledChunk[] {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
83
|
+
if (module.disabled) return [];
|
|
84
|
+
return renderFormat(module.formatAst, {
|
|
85
|
+
variables: { symbol: module.symbol, ...values },
|
|
86
|
+
styleVariables,
|
|
87
|
+
palette,
|
|
88
|
+
}).filter((chunk): chunk is StyledChunk => !isFillChunk(chunk));
|
|
96
89
|
}
|
|
97
90
|
|
|
98
|
-
export function reachableModuleRequirements(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
return requirements;
|
|
91
|
+
export function reachableModuleRequirements(config: StarshipConfig): ReadonlyMap<ModuleName, ReadonlySet<string>> {
|
|
92
|
+
const rootVariables = formatVariables(config.formatAst);
|
|
93
|
+
const includeAll = rootVariables.has("all");
|
|
94
|
+
const requirements = new Map<ModuleName, ReadonlySet<string>>();
|
|
95
|
+
for (const definition of MODULE_DEFINITIONS) {
|
|
96
|
+
if (config.modules[definition.name].disabled) continue;
|
|
97
|
+
if (!includeAll && !rootVariables.has(definition.name)) continue;
|
|
98
|
+
requirements.set(definition.name, formatVariables(config.modules[definition.name].formatAst));
|
|
99
|
+
}
|
|
100
|
+
return requirements;
|
|
110
101
|
}
|
|
111
102
|
|
|
112
103
|
function resolveFillLayout(layout: readonly LayoutChunk[], width: number): StyledChunk[] {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
return resolved;
|
|
104
|
+
const lines = splitLogicalLines(layout);
|
|
105
|
+
const resolved: StyledChunk[] = [];
|
|
106
|
+
for (const [lineIndex, line] of lines.entries()) {
|
|
107
|
+
const fills = line.filter(isFillChunk);
|
|
108
|
+
const fixedWidth = line.reduce(
|
|
109
|
+
(total, chunk) => total + (isFillChunk(chunk) ? 0 : visibleWidth(renderChunksToAnsi([chunk]))),
|
|
110
|
+
0,
|
|
111
|
+
);
|
|
112
|
+
const remaining = Math.max(0, width - fixedWidth);
|
|
113
|
+
const base = fills.length > 0 ? Math.floor(remaining / fills.length) : 0;
|
|
114
|
+
let remainder = fills.length > 0 ? remaining % fills.length : 0;
|
|
115
|
+
for (const chunk of line) {
|
|
116
|
+
if (!isFillChunk(chunk)) {
|
|
117
|
+
resolved.push(chunk);
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const allocation = base + (remainder > 0 ? 1 : 0);
|
|
121
|
+
if (remainder > 0) remainder -= 1;
|
|
122
|
+
resolved.push(...expandFill(chunk.pattern, allocation));
|
|
123
|
+
}
|
|
124
|
+
if (lineIndex < lines.length - 1) resolved.push({ text: "\n" });
|
|
125
|
+
}
|
|
126
|
+
return resolved;
|
|
137
127
|
}
|
|
138
128
|
|
|
139
129
|
function splitLogicalLines(layout: readonly LayoutChunk[]): LayoutChunk[][] {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
130
|
+
const lines: LayoutChunk[][] = [[]];
|
|
131
|
+
for (const chunk of layout) {
|
|
132
|
+
if (isFillChunk(chunk)) {
|
|
133
|
+
lines.at(-1)?.push(chunk);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
const parts = chunk.text.split("\n");
|
|
137
|
+
for (const [index, text] of parts.entries()) {
|
|
138
|
+
if (text) lines.at(-1)?.push({ ...chunk, text });
|
|
139
|
+
if (index < parts.length - 1) lines.push([]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return lines;
|
|
153
143
|
}
|
|
154
144
|
|
|
155
145
|
function expandFill(pattern: readonly StyledChunk[], width: number): StyledChunk[] {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
146
|
+
if (width <= 0) return [];
|
|
147
|
+
const patternWidth = visibleWidth(renderChunksToAnsi(pattern));
|
|
148
|
+
if (patternWidth <= 0) return [{ text: " ".repeat(width), style: pattern[0]?.style }];
|
|
149
|
+
const repetitions = Math.floor(width / patternWidth);
|
|
150
|
+
const result: StyledChunk[] = [];
|
|
151
|
+
for (let index = 0; index < repetitions; index += 1) {
|
|
152
|
+
result.push(...pattern.map((chunk) => ({ ...chunk })));
|
|
153
|
+
}
|
|
154
|
+
const remainder = width - repetitions * patternWidth;
|
|
155
|
+
if (remainder > 0) result.push({ text: " ".repeat(remainder), style: pattern.at(-1)?.style });
|
|
156
|
+
return result;
|
|
167
157
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ModuleStyleContext, ModuleStyleRule, ModuleStyleSelector } from "./types.js";
|
|
2
|
+
|
|
3
|
+
export function resolveStyleRule(
|
|
4
|
+
rules: readonly ModuleStyleRule[],
|
|
5
|
+
selectors: Readonly<Record<string, ModuleStyleSelector>>,
|
|
6
|
+
context: ModuleStyleContext,
|
|
7
|
+
): string | undefined {
|
|
8
|
+
for (const rule of rules) {
|
|
9
|
+
let matches = true;
|
|
10
|
+
for (const name in rule.selectors) {
|
|
11
|
+
if (!Object.hasOwn(rule.selectors, name)) continue;
|
|
12
|
+
const selector = Object.hasOwn(selectors, name) ? selectors[name] : undefined;
|
|
13
|
+
if (!selector || selector(context) !== rule.selectors[name]) {
|
|
14
|
+
matches = false;
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
if (matches) return rule.style;
|
|
19
|
+
}
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
package/src/modules/thinking.ts
CHANGED
|
@@ -2,36 +2,41 @@ import type { ThinkingLevel } from "@earendil-works/pi-agent-core";
|
|
|
2
2
|
import { defineModule } from "./types.js";
|
|
3
3
|
|
|
4
4
|
const THINKING_LEVELS = [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
"off",
|
|
6
|
+
"minimal",
|
|
7
|
+
"low",
|
|
8
|
+
"medium",
|
|
9
|
+
"high",
|
|
10
|
+
"xhigh",
|
|
11
|
+
"max",
|
|
12
12
|
] as const satisfies readonly ThinkingLevel[];
|
|
13
13
|
|
|
14
14
|
function thinkingLevelOf(value: string): ThinkingLevel | undefined {
|
|
15
|
-
|
|
15
|
+
return THINKING_LEVELS.find((level) => level === value);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export const thinkingModule = defineModule({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
19
|
+
name: "thinking",
|
|
20
|
+
variables: ["symbol", "level"],
|
|
21
|
+
defaults: {
|
|
22
|
+
format: "[$symbol $level ]($style)",
|
|
23
|
+
symbol: "🧠",
|
|
24
|
+
style: "bold purple",
|
|
25
|
+
disabled: false,
|
|
26
|
+
},
|
|
27
|
+
styleDefaults: Object.fromEntries(THINKING_LEVELS.map((level) => [`style_${level}`, ""])) as Record<
|
|
28
|
+
`style_${ThinkingLevel}`,
|
|
29
|
+
string
|
|
30
|
+
>,
|
|
31
|
+
fallbackStyle: true,
|
|
32
|
+
styleVariables: ["style"],
|
|
33
|
+
styleRuleSelectors: {
|
|
34
|
+
provider: ({ runtime }) => runtime.model?.provider,
|
|
35
|
+
level: ({ runtime }) => runtime.thinkingLevel,
|
|
36
|
+
},
|
|
37
|
+
resolveStyleVariables: ({ runtime, styles, style }) => {
|
|
38
|
+
const level = thinkingLevelOf(runtime.thinkingLevel);
|
|
39
|
+
return { style: (level && styles[`style_${level}`]) || style };
|
|
40
|
+
},
|
|
41
|
+
values: ({ runtime }) => ({ level: runtime.thinkingLevel }),
|
|
37
42
|
});
|
package/src/modules/time.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
import { defineModule } from "./types.js";
|
|
2
2
|
|
|
3
3
|
export const timeModule = defineModule({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
name: "time",
|
|
5
|
+
variables: ["symbol", "time"],
|
|
6
|
+
defaults: {
|
|
7
|
+
format: "[$symbol $time ]($style)",
|
|
8
|
+
symbol: "🕒",
|
|
9
|
+
style: "bold yellow",
|
|
10
|
+
disabled: false,
|
|
11
|
+
},
|
|
12
|
+
values: ({ runtime }) => ({ time: formatTime(runtime.now) }),
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
function formatTime(now: Date): string {
|
|
16
|
-
|
|
17
|
-
.getMinutes()
|
|
18
|
-
.toString()
|
|
19
|
-
.padStart(2, "0")}`;
|
|
16
|
+
return `${now.getHours().toString().padStart(2, "0")}:${now.getMinutes().toString().padStart(2, "0")}`;
|
|
20
17
|
}
|
package/src/modules/tokens.ts
CHANGED
|
@@ -2,17 +2,17 @@ import { formatCount } from "./helpers.js";
|
|
|
2
2
|
import { defineModule } from "./types.js";
|
|
3
3
|
|
|
4
4
|
export const tokensModule = defineModule({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
5
|
+
name: "tokens",
|
|
6
|
+
variables: ["symbol", "input", "output", "total"],
|
|
7
|
+
defaults: {
|
|
8
|
+
format: "[$symbol ↑$input ↓$output ]($style)",
|
|
9
|
+
symbol: "🔢",
|
|
10
|
+
style: "bold cyan",
|
|
11
|
+
disabled: false,
|
|
12
|
+
},
|
|
13
|
+
values: ({ runtime }) => ({
|
|
14
|
+
input: formatCount(runtime.tokenTotals.input),
|
|
15
|
+
output: formatCount(runtime.tokenTotals.output),
|
|
16
|
+
total: formatCount(runtime.tokenTotals.input + runtime.tokenTotals.output),
|
|
17
|
+
}),
|
|
18
18
|
});
|
|
@@ -3,35 +3,32 @@ import { sep } from "node:path";
|
|
|
3
3
|
const graphemeSegmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
4
4
|
|
|
5
5
|
export function graphemes(value: string): string[] {
|
|
6
|
-
|
|
6
|
+
return [...graphemeSegmenter.segment(value)].map(({ segment }) => segment);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export function firstGrapheme(value: string): string {
|
|
10
|
-
|
|
10
|
+
return graphemes(value)[0] ?? "";
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function truncateLeadingGraphemes(value: string, length: number, symbol: string): string {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
if (length <= 0) return value;
|
|
15
|
+
const parts = graphemes(value);
|
|
16
|
+
if (parts.length <= length) return value;
|
|
17
|
+
return `${parts.slice(0, length).join("")}${firstGrapheme(symbol)}`;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export function toSlashPath(value: string): string {
|
|
21
|
-
|
|
21
|
+
return sep === "\\" ? value.replaceAll("\\", "/") : value;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function truncatePathComponents(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const components = normalized.split("/").filter((component) => component.length > 0);
|
|
31
|
-
if (components.length <= length) return { value: normalized, truncated: false };
|
|
32
|
-
return { value: components.slice(-length).join("/"), truncated: true };
|
|
24
|
+
export function truncatePathComponents(value: string, length: number): { value: string; truncated: boolean } {
|
|
25
|
+
if (length <= 0) return { value, truncated: false };
|
|
26
|
+
const normalized = toSlashPath(value);
|
|
27
|
+
const components = normalized.split("/").filter((component) => component.length > 0);
|
|
28
|
+
if (components.length <= length) return { value: normalized, truncated: false };
|
|
29
|
+
return { value: components.slice(-length).join("/"), truncated: true };
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
export function useNativePathSeparator(value: string): string {
|
|
36
|
-
|
|
33
|
+
return sep === "/" ? value : value.replaceAll("/", sep);
|
|
37
34
|
}
|
package/src/modules/turn.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { defineModule } from "./types.js";
|
|
2
2
|
|
|
3
3
|
export const turnModule = defineModule({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
name: "turn",
|
|
5
|
+
variables: ["symbol", "count"],
|
|
6
|
+
defaults: {
|
|
7
|
+
format: "[$symbol #$count ]($style)",
|
|
8
|
+
symbol: "🔁",
|
|
9
|
+
style: "bold purple",
|
|
10
|
+
disabled: false,
|
|
11
|
+
},
|
|
12
|
+
values: ({ runtime }) => ({ count: `${runtime.turnCount}` }),
|
|
13
13
|
});
|