@ftrdotdev/pi-tui 0.2.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/LICENSE +21 -0
- package/README.md +63 -0
- package/package.json +80 -0
- package/src/autocomplete-contract.test.ts +126 -0
- package/src/autocomplete-contract.ts +91 -0
- package/src/commands/git-execution.test.ts +69 -0
- package/src/commands/git-execution.ts +198 -0
- package/src/commands/git-status.test.ts +379 -0
- package/src/commands/git-status.ts +320 -0
- package/src/components/bordered-box.test.ts +136 -0
- package/src/components/bordered-box.ts +106 -0
- package/src/components/define-component.ts +33 -0
- package/src/components/index.ts +35 -0
- package/src/config.test.ts +469 -0
- package/src/config.ts +307 -0
- package/src/frame/box-frame.test.ts +44 -0
- package/src/frame/box-frame.ts +160 -0
- package/src/icons.ts +203 -0
- package/src/index.ts +359 -0
- package/src/runtime.ts +256 -0
- package/src/session-lifecycle.ts +41 -0
- package/src/state.test.ts +7 -0
- package/src/state.ts +90 -0
- package/src/telemetry.ts +301 -0
- package/src/ui/editor-tint.test.ts +70 -0
- package/src/ui/editor-tint.ts +78 -0
- package/src/ui/editor.ts +403 -0
- package/src/ui/footer.test.ts +350 -0
- package/src/ui/footer.ts +225 -0
- package/src/ui/header.test.ts +260 -0
- package/src/ui/header.ts +165 -0
- package/src/ui/preview.test.ts +639 -0
- package/src/ui/preview.ts +374 -0
- package/src/ui/render-helpers.ts +275 -0
- package/src/ui/settings-command.test.ts +218 -0
- package/src/ui/settings-command.ts +390 -0
- package/src/utils.ts +448 -0
- package/src/vim/editor-close-autocomplete.ts +26 -0
- package/src/vim/editor-host.test.ts +340 -0
- package/src/vim/editor-state.test.ts +385 -0
- package/src/vim/editor-state.ts +314 -0
- package/src/vim/mode-indicator.test.ts +27 -0
- package/src/vim/mode-indicator.ts +44 -0
- package/src/vim/selection-render.test.ts +77 -0
- package/src/vim/selection-render.ts +85 -0
- package/src/vim/text-model.test.ts +85 -0
- package/src/vim/text-model.ts +75 -0
- package/src/vim/vim-router.test.ts +50 -0
- package/src/vim/vim-router.ts +55 -0
- package/src/vim/word-motion.ts +96 -0
package/src/icons.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
export type IconMode = "auto" | "nerd" | "ascii";
|
|
2
|
+
|
|
3
|
+
export interface IconGlyphs {
|
|
4
|
+
cwd: string;
|
|
5
|
+
git: string;
|
|
6
|
+
working: string;
|
|
7
|
+
done: string;
|
|
8
|
+
context: string;
|
|
9
|
+
model: string;
|
|
10
|
+
thinking: string;
|
|
11
|
+
input: string;
|
|
12
|
+
output: string;
|
|
13
|
+
cacheHit: string;
|
|
14
|
+
cost: string;
|
|
15
|
+
speed: string;
|
|
16
|
+
latency: string;
|
|
17
|
+
stall: string;
|
|
18
|
+
extensions: string;
|
|
19
|
+
ahead: string;
|
|
20
|
+
behind: string;
|
|
21
|
+
diverged: string;
|
|
22
|
+
conflicted: string;
|
|
23
|
+
stashed: string;
|
|
24
|
+
modified: string;
|
|
25
|
+
staged: string;
|
|
26
|
+
untracked: string;
|
|
27
|
+
renamed: string;
|
|
28
|
+
deleted: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const NERD_GLYPHS: IconGlyphs = {
|
|
32
|
+
cwd: "",
|
|
33
|
+
git: "",
|
|
34
|
+
working: "",
|
|
35
|
+
done: "",
|
|
36
|
+
context: "",
|
|
37
|
+
model: "",
|
|
38
|
+
thinking: "",
|
|
39
|
+
// client network view: input = upload to API, output = download from API
|
|
40
|
+
input: "",
|
|
41
|
+
output: "",
|
|
42
|
+
cacheHit: "",
|
|
43
|
+
cost: "",
|
|
44
|
+
speed: "",
|
|
45
|
+
latency: "",
|
|
46
|
+
stall: "",
|
|
47
|
+
extensions: "",
|
|
48
|
+
ahead: "↑",
|
|
49
|
+
behind: "↓",
|
|
50
|
+
diverged: "⇕",
|
|
51
|
+
conflicted: "=",
|
|
52
|
+
stashed: "$",
|
|
53
|
+
modified: "!",
|
|
54
|
+
staged: "+",
|
|
55
|
+
untracked: "?",
|
|
56
|
+
renamed: "»",
|
|
57
|
+
deleted: "✘",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// the footer's icon-like feel on non-Nerd-Font terminals. Symbols chosen to
|
|
61
|
+
// avoid collisions with the git-status set {= S ! A ? r x ^ v}.
|
|
62
|
+
const ASCII_GLYPHS: IconGlyphs = {
|
|
63
|
+
cwd: "@",
|
|
64
|
+
git: "*",
|
|
65
|
+
working: "o",
|
|
66
|
+
done: "+",
|
|
67
|
+
context: "%",
|
|
68
|
+
model: "M",
|
|
69
|
+
thinking: "~",
|
|
70
|
+
input: "↑",
|
|
71
|
+
output: "↓",
|
|
72
|
+
cacheHit: "c",
|
|
73
|
+
cost: "$",
|
|
74
|
+
speed: ">",
|
|
75
|
+
latency: "~",
|
|
76
|
+
stall: "!",
|
|
77
|
+
extensions: "&",
|
|
78
|
+
ahead: "^",
|
|
79
|
+
behind: "v",
|
|
80
|
+
diverged: "^v",
|
|
81
|
+
conflicted: "=",
|
|
82
|
+
stashed: "S",
|
|
83
|
+
modified: "!",
|
|
84
|
+
staged: "A",
|
|
85
|
+
untracked: "?",
|
|
86
|
+
renamed: "r",
|
|
87
|
+
deleted: "x",
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const NERD_FONT_TERMINALS = new Set([
|
|
91
|
+
"iTerm.app",
|
|
92
|
+
"Ghostty",
|
|
93
|
+
"WezTerm",
|
|
94
|
+
"kitty",
|
|
95
|
+
"rio",
|
|
96
|
+
"tabby",
|
|
97
|
+
"WindowsTerminal",
|
|
98
|
+
"vscode",
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
export function detectNerdFont(): boolean {
|
|
102
|
+
const termProgram = process.env.TERM_PROGRAM;
|
|
103
|
+
if (termProgram && NERD_FONT_TERMINALS.has(termProgram)) return true;
|
|
104
|
+
|
|
105
|
+
const lcTerminal = process.env.LC_TERMINAL;
|
|
106
|
+
if (lcTerminal && NERD_FONT_TERMINALS.has(lcTerminal)) return true;
|
|
107
|
+
|
|
108
|
+
if (process.env.TERM === "xterm-kitty") return true;
|
|
109
|
+
|
|
110
|
+
// Windows Terminal sets WT_SESSION (not TERM_PROGRAM)
|
|
111
|
+
if (process.env.WT_SESSION) return true;
|
|
112
|
+
|
|
113
|
+
// VS Code integrated terminal
|
|
114
|
+
if (process.env.TERM_PROGRAM === "vscode") return true;
|
|
115
|
+
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function resolveIconMode(mode: IconMode): "nerd" | "ascii" {
|
|
120
|
+
if (mode === "nerd") return "nerd";
|
|
121
|
+
if (mode === "ascii") return "ascii";
|
|
122
|
+
return detectNerdFont() ? "nerd" : "ascii";
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function resolveGlyphs(mode: IconMode): IconGlyphs {
|
|
126
|
+
const resolved = resolveIconMode(mode);
|
|
127
|
+
return resolved === "nerd" ? NERD_GLYPHS : ASCII_GLYPHS;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const RUNTIME_SYMBOLS: Record<string, string> = {
|
|
131
|
+
nodejs: "\uE718",
|
|
132
|
+
rust: "\uE7A8",
|
|
133
|
+
go: "\uE626",
|
|
134
|
+
python: "\uE73C",
|
|
135
|
+
ruby: "\uE739",
|
|
136
|
+
java: "\uE256",
|
|
137
|
+
cpp: "\uE61D",
|
|
138
|
+
c: "\uE61E",
|
|
139
|
+
swift: "\uE755",
|
|
140
|
+
kotlin: "\uE634",
|
|
141
|
+
deno: "\uE7FB",
|
|
142
|
+
bun: "\uE6FB",
|
|
143
|
+
php: "\uE73D",
|
|
144
|
+
haskell: "\uE777",
|
|
145
|
+
julia: "\uE624",
|
|
146
|
+
lua: "\uE620",
|
|
147
|
+
elixir: "\uE62B",
|
|
148
|
+
erlang: "\uE7B1",
|
|
149
|
+
gleam: "\uE6B4",
|
|
150
|
+
crystal: "\uE62F",
|
|
151
|
+
dart: "\uE7C0",
|
|
152
|
+
nim: "\uE677",
|
|
153
|
+
zig: "\uE6A9",
|
|
154
|
+
ocaml: "\uE67A",
|
|
155
|
+
clojure: "\uE76A",
|
|
156
|
+
scala: "\uE747",
|
|
157
|
+
perl: "\uE769",
|
|
158
|
+
r: "\uE68A",
|
|
159
|
+
elm: "\uE62C",
|
|
160
|
+
haxe: "\uE7B7",
|
|
161
|
+
vagrant: "\uE21A",
|
|
162
|
+
terraform: "\uE1A5",
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const RUNTIME_ASCII_SYMBOLS: Record<string, string> = {
|
|
166
|
+
nodejs: "node",
|
|
167
|
+
rust: "rs",
|
|
168
|
+
go: "go",
|
|
169
|
+
python: "py",
|
|
170
|
+
ruby: "rb",
|
|
171
|
+
java: "java",
|
|
172
|
+
swift: "swift",
|
|
173
|
+
kotlin: "kt",
|
|
174
|
+
cpp: "c++",
|
|
175
|
+
c: "c",
|
|
176
|
+
deno: "deno",
|
|
177
|
+
bun: "bun",
|
|
178
|
+
php: "php",
|
|
179
|
+
haskell: "hs",
|
|
180
|
+
julia: "jl",
|
|
181
|
+
lua: "lua",
|
|
182
|
+
elixir: "ex",
|
|
183
|
+
erlang: "erl",
|
|
184
|
+
gleam: "gleam",
|
|
185
|
+
crystal: "cr",
|
|
186
|
+
dart: "dart",
|
|
187
|
+
nim: "nim",
|
|
188
|
+
zig: "zig",
|
|
189
|
+
ocaml: "ml",
|
|
190
|
+
clojure: "clj",
|
|
191
|
+
scala: "scala",
|
|
192
|
+
perl: "pl",
|
|
193
|
+
r: "R",
|
|
194
|
+
elm: "elm",
|
|
195
|
+
haxe: "hx",
|
|
196
|
+
vagrant: "vag",
|
|
197
|
+
terraform: "tf",
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export function runtimeSymbol(name: string, mode: IconMode): string {
|
|
201
|
+
if (resolveIconMode(mode) === "ascii") return RUNTIME_ASCII_SYMBOLS[name] ?? name;
|
|
202
|
+
return RUNTIME_SYMBOLS[name] ?? "";
|
|
203
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { homedir } from "node:os";
|
|
2
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { type TuiConfig, DEFAULT_CONFIG, TuiConfigService } from "./config.ts";
|
|
4
|
+
import { installEditor } from "./ui/editor.ts";
|
|
5
|
+
import { installFooter } from "./ui/footer.ts";
|
|
6
|
+
import { installHeader } from "./ui/header.ts";
|
|
7
|
+
import { GitStatus, GitStatusService } from "./commands/git-status.ts";
|
|
8
|
+
import { GitExecutionService } from "./commands/git-execution.ts";
|
|
9
|
+
import { readRuntimeInfo } from "./runtime.ts";
|
|
10
|
+
import { SessionLifecycle } from "./session-lifecycle.ts";
|
|
11
|
+
import { PreviewService, registerPreview } from "./ui/preview.ts";
|
|
12
|
+
import { registerSettingsCommand } from "./ui/settings-command.ts";
|
|
13
|
+
import { formatTurnTelemetry, TurnTelemetryTracker } from "./telemetry.ts";
|
|
14
|
+
import {
|
|
15
|
+
createInitialState,
|
|
16
|
+
getModelMeta,
|
|
17
|
+
invalidateUsageCache,
|
|
18
|
+
type FooterState,
|
|
19
|
+
} from "./state.ts";
|
|
20
|
+
|
|
21
|
+
import { Effect, Layer } from "effect";
|
|
22
|
+
import { NodeServices } from "@effect/platform-node";
|
|
23
|
+
import { VimRouter } from "./vim/vim-router.ts";
|
|
24
|
+
import { EditorTintService, EditorTintServiceDefault } from "./ui/editor-tint.ts";
|
|
25
|
+
|
|
26
|
+
function isInteractiveLaunch(): boolean {
|
|
27
|
+
if (!process.stdout.isTTY) return false;
|
|
28
|
+
const args = process.argv.slice(2);
|
|
29
|
+
const nonInteractiveFlags = [
|
|
30
|
+
"-p",
|
|
31
|
+
"--print",
|
|
32
|
+
"--help",
|
|
33
|
+
"-h",
|
|
34
|
+
"--version",
|
|
35
|
+
"-v",
|
|
36
|
+
"--list-models",
|
|
37
|
+
"--export",
|
|
38
|
+
];
|
|
39
|
+
for (const arg of args) {
|
|
40
|
+
if (nonInteractiveFlags.includes(arg)) return false;
|
|
41
|
+
if (arg.startsWith("--mode")) return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function clearVisibleScreen(): void {
|
|
47
|
+
if (process.stdout.isTTY) {
|
|
48
|
+
process.stdout.write("\x1b[2J\x1b[H");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function isTuiContext(ctx: ExtensionContext): boolean {
|
|
53
|
+
try {
|
|
54
|
+
const mode = (ctx as ExtensionContext & { mode?: string }).mode;
|
|
55
|
+
return ctx.hasUI && (mode === undefined || mode === "tui");
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const main = Effect.fn("tui/main")(function* (pi: ExtensionAPI) {
|
|
62
|
+
const effectContext = yield* Effect.context<
|
|
63
|
+
GitExecutionService | GitStatusService | PreviewService
|
|
64
|
+
>();
|
|
65
|
+
|
|
66
|
+
const sessionLifecycle = new SessionLifecycle();
|
|
67
|
+
const state: FooterState = createInitialState();
|
|
68
|
+
const turnTelemetry = new TurnTelemetryTracker();
|
|
69
|
+
|
|
70
|
+
const conf = yield* TuiConfigService;
|
|
71
|
+
const tint = yield* EditorTintService;
|
|
72
|
+
|
|
73
|
+
let config: TuiConfig = structuredClone(DEFAULT_CONFIG);
|
|
74
|
+
let active = false;
|
|
75
|
+
let lastCtx: ExtensionContext | undefined;
|
|
76
|
+
let requestFooterRender: (() => void) | undefined;
|
|
77
|
+
let workingTimer: ReturnType<typeof setInterval> | undefined;
|
|
78
|
+
// TODO: configure
|
|
79
|
+
let cleanupHeader: (() => void) | undefined;
|
|
80
|
+
let cleanupFooter: (() => void) | undefined;
|
|
81
|
+
let cleanupEditor: (() => void) | undefined;
|
|
82
|
+
|
|
83
|
+
const getThinkingLevel = () => (sessionLifecycle.isCurrent() ? pi.getThinkingLevel() : "off");
|
|
84
|
+
|
|
85
|
+
const applyUi = (ctx: ExtensionContext) => {
|
|
86
|
+
if (!isTuiContext(ctx)) return;
|
|
87
|
+
if (!config.enabled) {
|
|
88
|
+
uninstallUi(ctx);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!active) {
|
|
92
|
+
cleanupHeader = installHeader(pi, ctx);
|
|
93
|
+
cleanupFooter = installFooter(
|
|
94
|
+
ctx,
|
|
95
|
+
() => state,
|
|
96
|
+
() => config,
|
|
97
|
+
() => getModelMeta(ctx, getThinkingLevel),
|
|
98
|
+
{
|
|
99
|
+
setRequestRender: (fn) => {
|
|
100
|
+
requestFooterRender = fn ?? undefined;
|
|
101
|
+
},
|
|
102
|
+
scheduleGitRefresh: () => {
|
|
103
|
+
void scheduleGitRefresh(ctx);
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
);
|
|
107
|
+
cleanupEditor = installEditor(pi, ctx, { getVimEnabled: () => config.vim, tint });
|
|
108
|
+
active = true;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const uninstallUi = (ctx: ExtensionContext) => {
|
|
113
|
+
if (!isTuiContext(ctx)) return;
|
|
114
|
+
if (active) {
|
|
115
|
+
cleanupHeader?.();
|
|
116
|
+
cleanupFooter?.();
|
|
117
|
+
cleanupEditor?.();
|
|
118
|
+
cleanupHeader = undefined;
|
|
119
|
+
cleanupFooter = undefined;
|
|
120
|
+
cleanupEditor = undefined;
|
|
121
|
+
requestFooterRender = undefined;
|
|
122
|
+
active = false;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const scheduleGitRefresh = async (ctx: ExtensionContext) => {
|
|
127
|
+
if (!sessionLifecycle.isCurrent()) return;
|
|
128
|
+
const generation = sessionLifecycle.currentGeneration();
|
|
129
|
+
const cwd = ctx.cwd;
|
|
130
|
+
const git = await Effect.runPromiseWith(effectContext)(
|
|
131
|
+
Effect.gen(function* () {
|
|
132
|
+
const svc = yield* GitStatusService;
|
|
133
|
+
return yield* svc.read(cwd, { readTag: config.footerSegments.gitCommit });
|
|
134
|
+
}).pipe(
|
|
135
|
+
Effect.catchTags({
|
|
136
|
+
GitSpawnError: (err) =>
|
|
137
|
+
Effect.logWarning(`git status spawn failed: ${err.message}`).pipe(
|
|
138
|
+
Effect.as(GitStatus.empty()),
|
|
139
|
+
),
|
|
140
|
+
GitTimeoutError: (err) =>
|
|
141
|
+
Effect.logWarning(
|
|
142
|
+
`git status timed out after ${err.durationMillis}ms (${err.command})`,
|
|
143
|
+
).pipe(Effect.as(GitStatus.empty())),
|
|
144
|
+
GitStatusError: (err) =>
|
|
145
|
+
Effect.logWarning(`git status unexpected output: ${err.stdout}`).pipe(
|
|
146
|
+
Effect.as(GitStatus.empty()),
|
|
147
|
+
),
|
|
148
|
+
}),
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
if (!sessionLifecycle.isCurrent(generation)) return;
|
|
152
|
+
state.git = git;
|
|
153
|
+
requestFooterRender?.();
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const refreshRuntime = async (ctx: ExtensionContext) => {
|
|
157
|
+
if (!sessionLifecycle.isCurrent()) return;
|
|
158
|
+
const generation = sessionLifecycle.currentGeneration();
|
|
159
|
+
const cwd = ctx.cwd;
|
|
160
|
+
const runtime = await readRuntimeInfo(cwd);
|
|
161
|
+
if (!sessionLifecycle.isCurrent(generation)) return;
|
|
162
|
+
state.runtime = runtime;
|
|
163
|
+
requestFooterRender?.();
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const refreshInteractiveState = (ctx: ExtensionContext, project = false) => {
|
|
167
|
+
if (!sessionLifecycle.isCurrent() || !ctx.hasUI) return;
|
|
168
|
+
if (project) {
|
|
169
|
+
void scheduleGitRefresh(ctx);
|
|
170
|
+
void refreshRuntime(ctx);
|
|
171
|
+
}
|
|
172
|
+
requestFooterRender?.();
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
const startWorkingTimer = () => {
|
|
176
|
+
stopWorkingTimer();
|
|
177
|
+
const tick = () => {
|
|
178
|
+
if (!sessionLifecycle.isCurrent() || !active) return;
|
|
179
|
+
requestFooterRender?.();
|
|
180
|
+
};
|
|
181
|
+
tick();
|
|
182
|
+
workingTimer = setInterval(tick, 250);
|
|
183
|
+
workingTimer.unref?.();
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const stopWorkingTimer = () => {
|
|
187
|
+
if (workingTimer) {
|
|
188
|
+
clearInterval(workingTimer);
|
|
189
|
+
workingTimer = undefined;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
pi.on("session_start", async (_event, ctx) =>
|
|
194
|
+
Effect.runPromiseWith(effectContext)(
|
|
195
|
+
Effect.gen(function* () {
|
|
196
|
+
sessionLifecycle.start();
|
|
197
|
+
lastCtx = ctx;
|
|
198
|
+
state.sessionStartEpoch = Date.now();
|
|
199
|
+
state.workingSince = undefined;
|
|
200
|
+
state.lastDoneIn = undefined;
|
|
201
|
+
invalidateUsageCache();
|
|
202
|
+
|
|
203
|
+
config = yield* conf.load.pipe(Effect.mapError((e) => ctx.ui.notify(e.message, "error")));
|
|
204
|
+
|
|
205
|
+
if (isInteractiveLaunch() && config.enabled) {
|
|
206
|
+
clearVisibleScreen();
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
applyUi(ctx);
|
|
210
|
+
|
|
211
|
+
refreshInteractiveState(ctx, true);
|
|
212
|
+
}),
|
|
213
|
+
),
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
pi.on("session_shutdown", async (_event, ctx) => {
|
|
217
|
+
sessionLifecycle.shutdown();
|
|
218
|
+
stopWorkingTimer();
|
|
219
|
+
if (active) {
|
|
220
|
+
uninstallUi(ctx);
|
|
221
|
+
}
|
|
222
|
+
lastCtx = undefined;
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
pi.on("agent_start", (event, _ctx) => {
|
|
226
|
+
turnTelemetry.handle(event);
|
|
227
|
+
if (!sessionLifecycle.isCurrent()) return;
|
|
228
|
+
state.workingSince = Date.now();
|
|
229
|
+
state.lastDoneIn = undefined;
|
|
230
|
+
startWorkingTimer();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
pi.on("agent_end", (_event, _ctx) => {
|
|
234
|
+
if (!sessionLifecycle.isCurrent()) return;
|
|
235
|
+
stopWorkingTimer();
|
|
236
|
+
if (state.workingSince !== undefined) {
|
|
237
|
+
state.lastDoneIn = Date.now() - state.workingSince;
|
|
238
|
+
state.workingSince = undefined;
|
|
239
|
+
}
|
|
240
|
+
requestFooterRender?.();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
pi.on("turn_start", (event) => {
|
|
244
|
+
turnTelemetry.handle(event);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
pi.on("message_start", (event) => {
|
|
248
|
+
turnTelemetry.handle(event);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
pi.on("message_update", (event) => {
|
|
252
|
+
turnTelemetry.handle(event);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
pi.on("tool_execution_start", (event) => {
|
|
256
|
+
turnTelemetry.handle(event);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
pi.on("turn_end", (event) => {
|
|
260
|
+
turnTelemetry.handle(event);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
pi.on("agent_settled", (event, ctx) => {
|
|
264
|
+
const telemetry = turnTelemetry.handle(event);
|
|
265
|
+
if (telemetry && config.enabled && config.telemetry.enabled && isTuiContext(ctx)) {
|
|
266
|
+
const message = formatTurnTelemetry(
|
|
267
|
+
telemetry,
|
|
268
|
+
ctx.ui.theme,
|
|
269
|
+
config.telemetry,
|
|
270
|
+
config.icons.mode,
|
|
271
|
+
);
|
|
272
|
+
if (message) ctx.ui.notify(message, "info");
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
pi.on("model_select", (_event, ctx) => {
|
|
277
|
+
refreshInteractiveState(ctx);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
pi.on("thinking_level_select", (_event, ctx) => {
|
|
281
|
+
refreshInteractiveState(ctx);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
pi.on("message_end", (event, ctx) => {
|
|
285
|
+
turnTelemetry.handle(event);
|
|
286
|
+
if (!sessionLifecycle.isCurrent()) return;
|
|
287
|
+
invalidateUsageCache();
|
|
288
|
+
refreshInteractiveState(ctx);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
pi.on("tool_execution_end", (_event, ctx) => {
|
|
292
|
+
refreshInteractiveState(ctx);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
pi.on("session_compact", (_event, ctx) => {
|
|
296
|
+
if (!sessionLifecycle.isCurrent()) return;
|
|
297
|
+
invalidateUsageCache();
|
|
298
|
+
refreshInteractiveState(ctx);
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
pi.on("session_tree", (_event, ctx) => {
|
|
302
|
+
if (!sessionLifecycle.isCurrent()) return;
|
|
303
|
+
invalidateUsageCache();
|
|
304
|
+
refreshInteractiveState(ctx);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
registerPreview(pi, effectContext);
|
|
308
|
+
|
|
309
|
+
// The settings UI injects an always-true gate for its own router instance
|
|
310
|
+
// (per-consumer gate injection): its h/j/k/l stay unconditional with or
|
|
311
|
+
// without the vim toggle. Every other surface gates on the live config.
|
|
312
|
+
// The layer is synchronous (Layer.succeed), so it yields directly here.
|
|
313
|
+
const settingsRouter = yield* Effect.service(VimRouter).pipe(
|
|
314
|
+
Effect.provide(VimRouter.make(() => true)),
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
registerSettingsCommand(
|
|
318
|
+
pi,
|
|
319
|
+
{
|
|
320
|
+
getConfig: () => config,
|
|
321
|
+
onConfigChanged: (newConfig) =>
|
|
322
|
+
// The save performs real file I/O (async FileSystem node layer), so it
|
|
323
|
+
// must run asynchronously; runSync would die on the async boundary.
|
|
324
|
+
Effect.runPromiseWith(effectContext)(
|
|
325
|
+
Effect.gen(function* () {
|
|
326
|
+
{
|
|
327
|
+
const wasEnabled = config.enabled;
|
|
328
|
+
yield* conf.save(newConfig);
|
|
329
|
+
config = newConfig;
|
|
330
|
+
if (lastCtx && wasEnabled !== newConfig.enabled) {
|
|
331
|
+
if (newConfig.enabled) {
|
|
332
|
+
applyUi(lastCtx);
|
|
333
|
+
} else {
|
|
334
|
+
uninstallUi(lastCtx);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
requestFooterRender?.();
|
|
338
|
+
}
|
|
339
|
+
}),
|
|
340
|
+
),
|
|
341
|
+
},
|
|
342
|
+
settingsRouter,
|
|
343
|
+
);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
export default function (pi: ExtensionAPI) {
|
|
347
|
+
const program = main(pi).pipe(
|
|
348
|
+
Effect.provide(
|
|
349
|
+
Layer.mergeAll(
|
|
350
|
+
TuiConfigService.layer,
|
|
351
|
+
GitStatusService.layer,
|
|
352
|
+
PreviewService.make(homedir),
|
|
353
|
+
EditorTintServiceDefault,
|
|
354
|
+
).pipe(Layer.provideMerge(GitExecutionService.layer), Layer.provideMerge(NodeServices.layer)),
|
|
355
|
+
),
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
Effect.runSync(program);
|
|
359
|
+
}
|