fisi-dock 0.0.0-stage → 0.3.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/CHANGELOG.md +71 -0
- package/LICENSE +21 -0
- package/README.md +225 -2
- package/docs/reference.md +116 -0
- package/extensions/fisi-dock.ts +1031 -0
- package/lib/ci.ts +208 -0
- package/lib/dock-state.ts +49 -0
- package/lib/entrance.ts +68 -0
- package/lib/header.ts +86 -0
- package/lib/heads-up.ts +223 -0
- package/lib/label-wave.ts +113 -0
- package/lib/live-data.ts +430 -0
- package/lib/live-store.ts +227 -0
- package/lib/loaded-box.ts +315 -0
- package/lib/logo.ts +97 -0
- package/lib/mcp.ts +83 -0
- package/lib/memory.ts +45 -0
- package/lib/odd-detail.ts +243 -0
- package/lib/odd-inference.ts +248 -0
- package/lib/odd-timeline.ts +274 -0
- package/lib/orbs.ts +181 -0
- package/lib/palette.ts +84 -0
- package/lib/panel-model.ts +216 -0
- package/lib/panel.ts +872 -0
- package/lib/pricing.ts +121 -0
- package/lib/profile.ts +39 -0
- package/lib/prompt-box.ts +382 -0
- package/lib/prompt-line.ts +90 -0
- package/lib/rdd-detail.ts +163 -0
- package/lib/rdd-mode.ts +185 -0
- package/lib/rdd.ts +120 -0
- package/lib/slot.ts +85 -0
- package/lib/strip.ts +63 -0
- package/lib/subagents.ts +443 -0
- package/lib/text.ts +108 -0
- package/lib/user-frame.ts +102 -0
- package/lib/welcome-card.ts +91 -0
- package/package.json +63 -4
- package/themes/Fisi-Dock.json +90 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// The working label's color wave in the prompt box (S90). Gentle Shell moves its
|
|
2
|
+
// wave one step per render, so it races while text streams and nearly stops during
|
|
3
|
+
// a quiet tool run. The box repaints the same words by the clock instead, with the
|
|
4
|
+
// same shape: the head and its two neighbors in the theme's accent, its
|
|
5
|
+
// softer tone one further out, muted elsewhere; both tones vivid (vivid labels S3).
|
|
6
|
+
// Only while Gentle Shell itself scans, in quality and performance (S93: there
|
|
7
|
+
// Gentle Shell steps its wave once a second).
|
|
8
|
+
// The petal before the label turns on the same clock (S97).
|
|
9
|
+
import type { OrbMotion } from "./orbs.ts";
|
|
10
|
+
import { bold, fg, palette, vivid } from "./palette.ts";
|
|
11
|
+
|
|
12
|
+
export const WAVE_STEP_MS = 120;
|
|
13
|
+
const WAVE_HEAD = vivid(palette.pink);
|
|
14
|
+
const WAVE_SOFT = vivid(palette.lilac);
|
|
15
|
+
/** Gentle Shell's wave enters three columns before the label; a short label rests between sweeps. */
|
|
16
|
+
const ENTRY_STEPS = 3;
|
|
17
|
+
const MIN_STEPS = 15;
|
|
18
|
+
/** Gentle Shell repaints a silent working phase once a second, so a frame always arrives within this while the editor is drawn. */
|
|
19
|
+
const FRAME_WINDOW_MS = 2000;
|
|
20
|
+
|
|
21
|
+
/** `label` with the wave at the moment `now`. */
|
|
22
|
+
export function waveLabel(label: string, now: number): string {
|
|
23
|
+
const chars = Array.from(label);
|
|
24
|
+
const steps = Math.max(MIN_STEPS, chars.length + ENTRY_STEPS * 2);
|
|
25
|
+
const head = (Math.floor(now / WAVE_STEP_MS) % steps) - ENTRY_STEPS;
|
|
26
|
+
return chars
|
|
27
|
+
.map((char, index) => {
|
|
28
|
+
const distance = Math.abs(head - index);
|
|
29
|
+
return fg(distance <= 1 ? WAVE_HEAD : distance === 2 ? WAVE_SOFT : palette.muted, char);
|
|
30
|
+
})
|
|
31
|
+
.join("");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Gentle Shell's working petal (lib/shell-prompt.ts PETAL_FRAMES): four flowers, one column each. */
|
|
35
|
+
const PETAL_FRAMES = ["✿", "❀", "❁", "✾"] as const;
|
|
36
|
+
/** Its tones (PETAL_TONE_FRAMES: mdQuoteBorder, thinkingHigh, accent, borderAccent, accent, thinkingHigh, mdQuoteBorder twice) in the Fisi-Dock theme's vivid colors. */
|
|
37
|
+
const PETAL_TONES = [palette.deepPink, palette.lilac, palette.pink, palette.pink, palette.pink, palette.lilac, palette.deepPink, palette.deepPink].map(vivid);
|
|
38
|
+
|
|
39
|
+
/** Gentle Shell's working petal at the moment `now`. Gentle Shell turns the petal and the wave on one tick, so one frame per wave step. */
|
|
40
|
+
export function wavePetal(now: number): string {
|
|
41
|
+
const step = Math.floor(now / WAVE_STEP_MS);
|
|
42
|
+
return fg(PETAL_TONES[step % PETAL_TONES.length], bold(PETAL_FRAMES[step % PETAL_FRAMES.length]));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface WaveClockOptions {
|
|
46
|
+
now(): number;
|
|
47
|
+
motion(): OrbMotion;
|
|
48
|
+
requestRender(): void;
|
|
49
|
+
setInterval?(tick: () => void, ms: number): unknown;
|
|
50
|
+
clearInterval?(handle: unknown): void;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface WaveClock {
|
|
54
|
+
/** The moment to paint the wave at; undefined leaves Gentle Shell's own label (potato). */
|
|
55
|
+
at(): number | undefined;
|
|
56
|
+
/** After each frame: whether its label scans. Starts and stops the timer. */
|
|
57
|
+
report(scanning: boolean): void;
|
|
58
|
+
dispose(): void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A timer only while a scanning label is drawn, never in potato motion. The
|
|
63
|
+
* motion setting is a file, so it is read when a scan starts, never per frame.
|
|
64
|
+
* When no frame reports for FRAME_WINDOW_MS (the editor is not being drawn) it stops
|
|
65
|
+
* asking for frames; the next reported scan starts it again.
|
|
66
|
+
*/
|
|
67
|
+
export function createWaveClock(options: WaveClockOptions): WaveClock {
|
|
68
|
+
const startTimer = options.setInterval ?? ((tick: () => void, ms: number) => {
|
|
69
|
+
const handle = setInterval(tick, ms);
|
|
70
|
+
(handle as { unref?(): void }).unref?.();
|
|
71
|
+
return handle;
|
|
72
|
+
});
|
|
73
|
+
const stopTimer = options.clearInterval ?? ((handle: unknown) => clearInterval(handle as ReturnType<typeof setInterval>));
|
|
74
|
+
const readMotion = (): OrbMotion => {
|
|
75
|
+
try {
|
|
76
|
+
return options.motion();
|
|
77
|
+
} catch {
|
|
78
|
+
return "quality";
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
let motion = readMotion();
|
|
82
|
+
let timer: unknown;
|
|
83
|
+
let scanning = false;
|
|
84
|
+
let lastFrame = 0;
|
|
85
|
+
let disposed = false;
|
|
86
|
+
const stop = () => {
|
|
87
|
+
if (timer !== undefined) stopTimer(timer);
|
|
88
|
+
timer = undefined;
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
at: () => (motion === "potato" ? undefined : options.now()),
|
|
92
|
+
report(next) {
|
|
93
|
+
if (disposed) return;
|
|
94
|
+
if (!next) {
|
|
95
|
+
scanning = false;
|
|
96
|
+
stop();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
lastFrame = options.now();
|
|
100
|
+
if (!scanning) motion = readMotion();
|
|
101
|
+
scanning = true;
|
|
102
|
+
if (timer !== undefined || motion === "potato") return;
|
|
103
|
+
timer = startTimer(() => {
|
|
104
|
+
if (options.now() - lastFrame > FRAME_WINDOW_MS) return stop();
|
|
105
|
+
options.requestRender();
|
|
106
|
+
}, WAVE_STEP_MS);
|
|
107
|
+
},
|
|
108
|
+
dispose() {
|
|
109
|
+
disposed = true;
|
|
110
|
+
stop();
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
package/lib/live-data.ts
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { ciRunning, ciView, type CiRuns } from "./ci.ts";
|
|
2
|
+
import { entranceSteps } from "./entrance.ts";
|
|
3
|
+
import { headsUpWarnings, type PlanInfo } from "./heads-up.ts";
|
|
4
|
+
import { SHIMMER_STEP_MS } from "./orbs.ts";
|
|
5
|
+
import type { AgentInfo, ChangeInfo, McpServerInfo, MemoryInfo, OddInfo, PanelModel, SessionInfo, TodoInfo, TodoTask } from "./panel-model.ts";
|
|
6
|
+
import { rddLabel } from "./panel.ts";
|
|
7
|
+
import { rddLive, rddView, type RddRow } from "./rdd.ts";
|
|
8
|
+
|
|
9
|
+
// Pure mappers from the sources Fisi Dock reads (Pi context, session entries,
|
|
10
|
+
// Gentle Shell's pi.events payloads, git output) to the panel model. Gentle
|
|
11
|
+
// Shell's shapes are restated here, never imported: an update that changes them
|
|
12
|
+
// only makes a mapper return nothing, it cannot break module loading.
|
|
13
|
+
|
|
14
|
+
const record = (value: unknown): Record<string, unknown> | undefined =>
|
|
15
|
+
value !== null && typeof value === "object" && !Array.isArray(value) ? (value as Record<string, unknown>) : undefined;
|
|
16
|
+
|
|
17
|
+
const count = (value: unknown): number | undefined => (typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : undefined);
|
|
18
|
+
|
|
19
|
+
// --- session ---------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
export function projectName(cwd: string): string {
|
|
22
|
+
const parts = cwd.split(/[\\/]+/).filter(Boolean);
|
|
23
|
+
return parts.at(-1) ?? "";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** `git rev-parse --abbrev-ref HEAD` output; a detached HEAD has no branch. */
|
|
27
|
+
export function parseBranch(stdout: string | undefined): string | undefined {
|
|
28
|
+
const name = stdout?.trim();
|
|
29
|
+
return name && name !== "HEAD" ? name : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** `git rev-list --count @{upstream}..HEAD` output; anything but a count means no upstream. */
|
|
33
|
+
export function parseAhead(stdout: string | undefined): number | undefined {
|
|
34
|
+
const text = stdout?.trim() ?? "";
|
|
35
|
+
return /^\d+$/.test(text) ? Number(text) : undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Pi's ContextUsage: tokens and percent are null right after compaction. */
|
|
39
|
+
export function sessionUsage(usage: { tokens: number | null; contextWindow: number; percent: number | null } | undefined): Pick<SessionInfo, "contextPercent" | "tokensUsed" | "tokensMax"> {
|
|
40
|
+
const value = record(usage);
|
|
41
|
+
const percent = count(value?.percent);
|
|
42
|
+
const tokens = count(value?.tokens);
|
|
43
|
+
const window = count(value?.contextWindow);
|
|
44
|
+
if (percent === undefined) return {};
|
|
45
|
+
return { contextPercent: percent, ...(tokens !== undefined && window ? { tokensUsed: tokens, tokensMax: window } : {}) };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Same rule as Gentle Shell's sessionCost: the sum of assistant message costs. */
|
|
49
|
+
export function sessionCost(entries: readonly unknown[]): number {
|
|
50
|
+
let total = 0;
|
|
51
|
+
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
52
|
+
const message = record(record(entry)?.message);
|
|
53
|
+
if (record(entry)?.type !== "message" || message?.role !== "assistant") continue;
|
|
54
|
+
total += count(record(record(message.usage)?.cost)?.total) ?? 0;
|
|
55
|
+
}
|
|
56
|
+
// Float sums drift (0.0125 + 0.002); the footer shows three decimals anyway.
|
|
57
|
+
return Math.round(total * 1e9) / 1e9;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Tokens of the same assistant messages (S37): usage.totalTokens, else its four parts. */
|
|
61
|
+
export function sessionTokens(entries: readonly unknown[]): number {
|
|
62
|
+
let total = 0;
|
|
63
|
+
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
64
|
+
const message = record(record(entry)?.message);
|
|
65
|
+
if (record(entry)?.type !== "message" || message?.role !== "assistant") continue;
|
|
66
|
+
const usage = record(message.usage);
|
|
67
|
+
total += count(usage?.totalTokens) ?? ["input", "output", "cacheRead", "cacheWrite"].reduce((sum, key) => sum + (count(usage?.[key]) ?? 0), 0);
|
|
68
|
+
}
|
|
69
|
+
return total;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// --- todo ------------------------------------------------------------------
|
|
73
|
+
|
|
74
|
+
export interface TodoTaskLike {
|
|
75
|
+
id?: number;
|
|
76
|
+
title: string;
|
|
77
|
+
status: string;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface TodoStateLike {
|
|
81
|
+
tasks: TodoTaskLike[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const TODO_TOOL = "todo";
|
|
85
|
+
const TODO_DETAILS_KEY = "gentleTodo";
|
|
86
|
+
|
|
87
|
+
function todoState(value: unknown): TodoStateLike | undefined {
|
|
88
|
+
const tasks = record(value)?.tasks;
|
|
89
|
+
return Array.isArray(tasks) ? { tasks: tasks as TodoTaskLike[] } : undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Gentle Todo's replay rule: the last successful `todo` tool result on the branch. */
|
|
93
|
+
export function todoStateFromEntries(entries: readonly unknown[]): TodoStateLike | undefined {
|
|
94
|
+
let state: TodoStateLike | undefined;
|
|
95
|
+
for (const entry of Array.isArray(entries) ? entries : []) {
|
|
96
|
+
const message = record(record(entry)?.message);
|
|
97
|
+
if (record(entry)?.type !== "message" || message?.role !== "toolResult" || message.toolName !== TODO_TOOL || message.isError === true) continue;
|
|
98
|
+
state = todoState(record(message.details)?.[TODO_DETAILS_KEY]) ?? state;
|
|
99
|
+
}
|
|
100
|
+
return state;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Pi's tool_execution_end for Gentle Todo carries the full snapshot in details. */
|
|
104
|
+
export function todoStateFromToolEnd(event: { toolName?: string; isError?: boolean; result?: unknown }): TodoStateLike | undefined {
|
|
105
|
+
if (event?.toolName !== TODO_TOOL || event.isError) return undefined;
|
|
106
|
+
return todoState(record(record(event.result)?.details)?.[TODO_DETAILS_KEY]);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const TASK_STATES: Record<string, TodoTask["state"]> = { done: "done", in_progress: "active", blocked: "blocked", dropped: "dropped" };
|
|
110
|
+
|
|
111
|
+
export function todoFromState(state: TodoStateLike | undefined): TodoInfo | undefined {
|
|
112
|
+
const tasks = (todoState(state)?.tasks ?? []).filter((task) => record(task) && typeof task.title === "string");
|
|
113
|
+
if (tasks.length === 0) return undefined;
|
|
114
|
+
const done = tasks.filter((task) => task.status === "done").length;
|
|
115
|
+
const open = tasks.filter((task) => task.status !== "done" && task.status !== "dropped").length;
|
|
116
|
+
const active = tasks.find((task) => task.status === "in_progress")?.title;
|
|
117
|
+
const next = tasks.find((task) => task.status === "pending")?.title;
|
|
118
|
+
const shown = (active !== undefined ? 1 : 0) + (next !== undefined ? 1 : 0);
|
|
119
|
+
const list = tasks.map((task) => ({ title: task.title, state: (Object.hasOwn(TASK_STATES, task.status) && TASK_STATES[task.status]) || "pending" }));
|
|
120
|
+
return { done, total: tasks.length, ...(active !== undefined ? { active } : {}), ...(next !== undefined ? { next } : {}), more: Math.max(0, open - shown), tasks: list };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Gentle Todo's progress event ({ sessionId, done, total, current }) arrives
|
|
125
|
+
* before the tool result. It moves the counts and the active task right away;
|
|
126
|
+
* the full snapshot from the tool result follows. Other sessions and malformed
|
|
127
|
+
* payloads leave `previous` as it is. The event has no titles: the task list
|
|
128
|
+
* stays only while its counts and active task still match, never guessed.
|
|
129
|
+
*/
|
|
130
|
+
export function todoFromProgress(event: unknown, sessionId: string, previous: TodoInfo | undefined): TodoInfo | undefined {
|
|
131
|
+
const value = record(event);
|
|
132
|
+
const done = count(value?.done);
|
|
133
|
+
const total = count(value?.total);
|
|
134
|
+
if (!value || value.sessionId !== sessionId || done === undefined || total === undefined) return previous;
|
|
135
|
+
if (total === 0) return undefined;
|
|
136
|
+
const active = typeof value.current === "string" && value.current ? value.current : undefined;
|
|
137
|
+
const next = previous?.next !== undefined && previous.next !== active ? previous.next : undefined;
|
|
138
|
+
const shown = (active !== undefined ? 1 : 0) + (next !== undefined ? 1 : 0);
|
|
139
|
+
const list = previous?.tasks;
|
|
140
|
+
const same = list !== undefined && list.length === total && list.filter((task) => task.state === "done").length === done && list.find((task) => task.state === "active")?.title === active;
|
|
141
|
+
return { done, total, ...(active !== undefined ? { active } : {}), ...(next !== undefined ? { next } : {}), more: Math.max(0, total - done - shown), ...(same ? { tasks: list } : {}) };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// --- Gentle Shell events -----------------------------------------------------
|
|
145
|
+
|
|
146
|
+
function forSession(event: unknown, sessionId: string): Record<string, unknown> | undefined {
|
|
147
|
+
const value = record(event);
|
|
148
|
+
return value && value.sessionId === sessionId ? record(value.snapshot) : undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* `gentle-ai:jobs-sidebar` ({ sessionId, snapshot: { jobs } }) to agent rows.
|
|
153
|
+
* Undefined means "not for us or malformed": keep what is shown.
|
|
154
|
+
*/
|
|
155
|
+
export function agentsFromJobs(event: unknown, sessionId: string): AgentInfo[] | undefined {
|
|
156
|
+
const jobs = forSession(event, sessionId)?.jobs;
|
|
157
|
+
if (!Array.isArray(jobs)) return undefined;
|
|
158
|
+
const valid = jobs.every((job) => {
|
|
159
|
+
const value = record(job);
|
|
160
|
+
return value && typeof value.id === "string" && value.id.length > 0 && typeof value.label === "string";
|
|
161
|
+
});
|
|
162
|
+
if (!valid) return undefined;
|
|
163
|
+
return jobs.map((job: { id: string; label: string; startedAt?: unknown; status?: unknown }) => ({
|
|
164
|
+
name: job.id,
|
|
165
|
+
task: job.label,
|
|
166
|
+
// 4.5.0 adds finished tails: exited/stopped are done, failed is failed.
|
|
167
|
+
state: job.status === undefined ? "running" : job.status === "failed" ? "failed" : "done",
|
|
168
|
+
...(typeof job.startedAt === "number" && Number.isFinite(job.startedAt) ? { startedAt: job.startedAt } : {}),
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Gentle Shell's REVIEW_SIDEBAR_LABELS (lib/review-sidebar-state.ts), minus
|
|
173
|
+
// "unknown", which says nothing worth a footer slot.
|
|
174
|
+
const REVIEW_LABELS: Record<string, string> = {
|
|
175
|
+
reviewing: "Reviewers running…",
|
|
176
|
+
in_review: "Review in progress",
|
|
177
|
+
checking: "Updating…",
|
|
178
|
+
approved: "Approved · finalizing…",
|
|
179
|
+
closed: "✓ Approved",
|
|
180
|
+
correction: "Fixing findings…",
|
|
181
|
+
declined: "Skipped for this change",
|
|
182
|
+
invalidated: "Outdated · code changed",
|
|
183
|
+
unavailable: "Review unavailable",
|
|
184
|
+
ready: "Not reviewed yet",
|
|
185
|
+
consent: "Needs your consent",
|
|
186
|
+
forecast: "Preparing reviewers…",
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* `gentle-ai:review-sidebar` to footer text. Undefined: not for this session,
|
|
191
|
+
* keep the current text. Null: ours, but nothing to show.
|
|
192
|
+
*/
|
|
193
|
+
export function reviewText(event: unknown, sessionId: string): string | null | undefined {
|
|
194
|
+
const snapshot = forSession(event, sessionId);
|
|
195
|
+
if (!snapshot) return undefined;
|
|
196
|
+
const state = snapshot.state;
|
|
197
|
+
return typeof state === "string" && Object.hasOwn(REVIEW_LABELS, state) ? REVIEW_LABELS[state] : null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// --- git -------------------------------------------------------------------
|
|
201
|
+
|
|
202
|
+
function changeStatus(code: string): ChangeInfo["status"] | undefined {
|
|
203
|
+
if (code === "??") return "?";
|
|
204
|
+
if (code === "!!") return undefined;
|
|
205
|
+
if (code.includes("R")) return "R";
|
|
206
|
+
if (code.includes("D")) return "D";
|
|
207
|
+
if (code[0] === "A" || code[0] === "C") return "A";
|
|
208
|
+
return "M";
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* `git status --porcelain=v1 -z` and `git diff --numstat -z HEAD` to changes.
|
|
213
|
+
* The -z forms keep spaces and non-ASCII in paths unquoted. Untracked and
|
|
214
|
+
* binary files count 0 lines.
|
|
215
|
+
*/
|
|
216
|
+
export function parseGitChanges(status: string, numstat: string): ChangeInfo[] {
|
|
217
|
+
const lines = new Map<string, { added: number; removed: number }>();
|
|
218
|
+
const stats = numstat.split("\0");
|
|
219
|
+
for (let index = 0; index < stats.length; index++) {
|
|
220
|
+
const match = /^(-|\d+)\t(-|\d+)\t(.*)$/s.exec(stats[index]);
|
|
221
|
+
if (!match) continue;
|
|
222
|
+
let path = match[3];
|
|
223
|
+
// A rename leaves the path empty and lists old then new as the next fields.
|
|
224
|
+
if (path === "") {
|
|
225
|
+
path = stats[index + 2] ?? "";
|
|
226
|
+
index += 2;
|
|
227
|
+
}
|
|
228
|
+
const added = match[1] === "-" ? 0 : Number(match[1]);
|
|
229
|
+
const removed = match[2] === "-" ? 0 : Number(match[2]);
|
|
230
|
+
if (path) lines.set(path, { added, removed });
|
|
231
|
+
}
|
|
232
|
+
const changes: ChangeInfo[] = [];
|
|
233
|
+
const fields = status.split("\0");
|
|
234
|
+
for (let index = 0; index < fields.length; index++) {
|
|
235
|
+
const field = fields[index];
|
|
236
|
+
if (field.length < 4) continue;
|
|
237
|
+
const code = field.slice(0, 2);
|
|
238
|
+
const path = field.slice(3);
|
|
239
|
+
// Renames and copies carry the original path as the next field.
|
|
240
|
+
if (code.includes("R") || code.includes("C")) index++;
|
|
241
|
+
const kind = changeStatus(code);
|
|
242
|
+
if (!kind) continue;
|
|
243
|
+
changes.push({ status: kind, path, ...(lines.get(path) ?? { added: 0, removed: 0 }) });
|
|
244
|
+
}
|
|
245
|
+
return changes;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// --- model -----------------------------------------------------------------
|
|
249
|
+
|
|
250
|
+
export interface LiveParts {
|
|
251
|
+
project: string;
|
|
252
|
+
/** The RDD switch for the session folder (S85), from `gentle-ai review mode status`; undefined until read. */
|
|
253
|
+
rdd?: "on" | "off";
|
|
254
|
+
branch?: string;
|
|
255
|
+
ahead?: number;
|
|
256
|
+
usage?: Pick<SessionInfo, "contextPercent" | "tokensUsed" | "tokensMax">;
|
|
257
|
+
/** Gentle Shell's agent-model profile label (S99), from lib/profile.ts readSessionProfile. */
|
|
258
|
+
profile?: string;
|
|
259
|
+
todo?: TodoInfo;
|
|
260
|
+
odd?: OddInfo;
|
|
261
|
+
agents?: AgentInfo[];
|
|
262
|
+
changes?: ChangeInfo[];
|
|
263
|
+
/** Heads-up sources (S14). */
|
|
264
|
+
worktrees?: string[];
|
|
265
|
+
unmerged?: string[];
|
|
266
|
+
plans?: PlanInfo[];
|
|
267
|
+
/** True from agent_settled until the next request starts. */
|
|
268
|
+
runSettled?: boolean;
|
|
269
|
+
/** Undefined until the session entries were read once. */
|
|
270
|
+
cost?: number;
|
|
271
|
+
/** Session tokens and their API-price estimate (S37), shown while the cost is 0. */
|
|
272
|
+
tokens?: number;
|
|
273
|
+
estimate?: number;
|
|
274
|
+
review?: string;
|
|
275
|
+
/** The session's RDD reviews (S50), from lib/rdd.ts reduceReviews. */
|
|
276
|
+
reviews?: RddRow[];
|
|
277
|
+
/** CI runs of the branch's last pushed commit (S64), from lib/ci.ts readCi; undefined: no section. */
|
|
278
|
+
ci?: CiRuns;
|
|
279
|
+
/** Configured MCP servers and their state (S32); [] without MCP config, undefined until the config was read. */
|
|
280
|
+
mcp?: McpServerInfo[];
|
|
281
|
+
/** Engram from gentle-engram's mem_* tools and calls (lib/memory.ts); undefined while Pi's tool list cannot be read. */
|
|
282
|
+
memory?: MemoryInfo;
|
|
283
|
+
/** The running spinner's frame from the wall clock (S31); drawn only while something runs. */
|
|
284
|
+
spinner?: number;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* True while the panel draws a running spinner (S31): a running agent, an
|
|
289
|
+
* active todo task while a run is active, or a review that runs or waits for
|
|
290
|
+
* the user (S50; its m:ss ticks with the spinner), or a running CI check
|
|
291
|
+
* (S64, the same). A task left in progress after the run settled shows the
|
|
292
|
+
* still frame (L61).
|
|
293
|
+
*/
|
|
294
|
+
export function runsSpinner(model: PanelModel, runActive = true): boolean {
|
|
295
|
+
const todo = model.todo;
|
|
296
|
+
const activeTask = runActive && todo !== undefined && todo.total > 0 && (todo.active !== undefined || (todo.tasks?.some((task) => task.state === "active") ?? false));
|
|
297
|
+
return activeTask || (model.agents?.some((agent) => agent.state === "running") ?? false) || rddLive(model.rdd) || ciRunning(model.ci);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// --- row entrance (S54) -----------------------------------------------------
|
|
301
|
+
|
|
302
|
+
/** A row that plays the entrance when it appears: its identity, the text the shine crosses and, for agents, its start. */
|
|
303
|
+
export interface EntranceRow {
|
|
304
|
+
key: string;
|
|
305
|
+
text: string;
|
|
306
|
+
startedAt?: number;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** The agents card pads names to this many cells (panel.ts AGENT_NAME_CAP), so the shine crosses the padding too. */
|
|
310
|
+
const AGENT_NAME_CELLS = 12;
|
|
311
|
+
|
|
312
|
+
const agentRow = (key: string, agent: AgentInfo): EntranceRow => ({
|
|
313
|
+
key,
|
|
314
|
+
text: `${agent.name.padEnd(AGENT_NAME_CELLS)} ${agent.task}`,
|
|
315
|
+
...(agent.startedAt !== undefined ? { startedAt: agent.startedAt } : {}),
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
const oddKey = (odd: OddInfo, index: number) => `odd:${Math.max(0, Math.floor(odd.earlier ?? 0)) + index}:${odd.steps[index].phase}`;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Rows that enter when they appear (S54): running agents (jobs by name, as
|
|
322
|
+
* their start times), the active todo task, the active ODD step and every RDD
|
|
323
|
+
* review. Changes, heads-up, the strip and the header never do.
|
|
324
|
+
*/
|
|
325
|
+
export function entranceRows(parts: LiveParts): EntranceRow[] {
|
|
326
|
+
const rows: EntranceRow[] = [];
|
|
327
|
+
for (const agent of parts.agents ?? []) if (agent.state === "running") rows.push(agentRow(`job:${agent.id ?? agent.name}`, agent));
|
|
328
|
+
if (parts.todo?.active !== undefined) rows.push({ key: `todo:${parts.todo.active}`, text: parts.todo.active });
|
|
329
|
+
const odd = parts.odd;
|
|
330
|
+
odd?.steps.forEach((step, index) => {
|
|
331
|
+
if (step.state === "active" && !odd.settled) rows.push({ key: oddKey(odd, index), text: step.phase });
|
|
332
|
+
});
|
|
333
|
+
(parts.reviews ?? []).forEach((review, index) => rows.push({ key: `rdd:${index}:${review.startedAt}`, text: `${review.scope} ${rddLabel(review.status)}` }));
|
|
334
|
+
return rows;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** The entrance step at `now` of a row that appeared at `at`; undefined once it is over. */
|
|
338
|
+
function entranceAt(at: number | undefined, text: string, now: number): number | undefined {
|
|
339
|
+
if (at === undefined || !Number.isFinite(at)) return undefined;
|
|
340
|
+
const step = Math.max(0, Math.floor((now - at) / SHIMMER_STEP_MS));
|
|
341
|
+
return step < entranceSteps(text) ? step : undefined;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** True while any row plays its entrance: a clock keeps repainting at the entrance step. */
|
|
345
|
+
export function hasEntrance(model: PanelModel): boolean {
|
|
346
|
+
return (
|
|
347
|
+
model.todo?.entrance !== undefined ||
|
|
348
|
+
(model.agents?.some((agent) => agent.entrance !== undefined) ?? false) ||
|
|
349
|
+
(model.odd?.steps.some((step) => step.entrance !== undefined) ?? false) ||
|
|
350
|
+
(model.rdd?.reviews.some((review) => review.entrance !== undefined) ?? false)
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** `parts` with each entering row's step at `now`, from when it appeared (`appeared`, by entranceRows key). */
|
|
355
|
+
function withEntrances(parts: LiveParts, now: number, appeared: ReadonlyMap<string, number>): LiveParts {
|
|
356
|
+
if (appeared.size === 0) return parts;
|
|
357
|
+
const step = (row: EntranceRow) => entranceAt(appeared.get(row.key), row.text, now);
|
|
358
|
+
const agents = <T extends AgentInfo & { id?: string }>(list: T[] | undefined, key: (agent: T) => string): T[] | undefined =>
|
|
359
|
+
list?.map((agent) => {
|
|
360
|
+
const at = agent.state === "running" ? step(agentRow(key(agent), agent)) : undefined;
|
|
361
|
+
return at === undefined ? agent : { ...agent, entrance: at };
|
|
362
|
+
});
|
|
363
|
+
const todoStep = parts.todo?.active !== undefined ? step({ key: `todo:${parts.todo.active}`, text: parts.todo.active }) : undefined;
|
|
364
|
+
const odd = parts.odd;
|
|
365
|
+
return {
|
|
366
|
+
...parts,
|
|
367
|
+
agents: agents(parts.agents, (agent) => `job:${agent.id ?? agent.name}`),
|
|
368
|
+
todo: todoStep === undefined ? parts.todo : { ...parts.todo!, entrance: todoStep },
|
|
369
|
+
odd: odd && {
|
|
370
|
+
...odd,
|
|
371
|
+
steps: odd.steps.map((entry, index) => {
|
|
372
|
+
const at = entry.state === "active" && !odd.settled ? step({ key: oddKey(odd, index), text: entry.phase }) : undefined;
|
|
373
|
+
return at === undefined ? entry : { ...entry, entrance: at };
|
|
374
|
+
}),
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* The panel model for the live parts; `now` times the running reviews and the
|
|
381
|
+
* entrances of the rows in `appeared` (S54: entranceRows key -> epoch ms it appeared).
|
|
382
|
+
*/
|
|
383
|
+
export function sessionSnapshot(parts: LiveParts, now: number = Date.now(), appeared: ReadonlyMap<string, number> = new Map()): PanelModel {
|
|
384
|
+
const model = snapshotOf(withEntrances(parts, now, appeared), now);
|
|
385
|
+
if (!model.rdd || appeared.size === 0) return model;
|
|
386
|
+
const reviews = model.rdd.reviews.map((review, index) => {
|
|
387
|
+
const row = parts.reviews![index];
|
|
388
|
+
const at = entranceAt(appeared.get(`rdd:${index}:${row.startedAt}`), `${row.scope} ${rddLabel(row.status)}`, now);
|
|
389
|
+
return at === undefined ? review : { ...review, entrance: at };
|
|
390
|
+
});
|
|
391
|
+
return { ...model, rdd: { reviews } };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function snapshotOf(parts: LiveParts, now: number): PanelModel {
|
|
395
|
+
const session: SessionInfo = {
|
|
396
|
+
project: parts.project,
|
|
397
|
+
...(parts.branch !== undefined ? { branch: parts.branch } : {}),
|
|
398
|
+
...(parts.ahead !== undefined ? { ahead: parts.ahead } : {}),
|
|
399
|
+
...parts.usage,
|
|
400
|
+
...(parts.profile ? { profile: parts.profile } : {}),
|
|
401
|
+
...(parts.mcp ? { mcp: parts.mcp } : {}),
|
|
402
|
+
...(parts.memory ? { memory: parts.memory } : {}),
|
|
403
|
+
};
|
|
404
|
+
const todo = parts.todo;
|
|
405
|
+
const openTodo = todo ? todo.more + (todo.active !== undefined ? 1 : 0) + (todo.next !== undefined ? 1 : 0) : 0;
|
|
406
|
+
const headsUp = headsUpWarnings({
|
|
407
|
+
worktrees: parts.worktrees,
|
|
408
|
+
todoLeft: parts.runSettled ? openTodo : 0,
|
|
409
|
+
ahead: parts.ahead,
|
|
410
|
+
unmerged: parts.unmerged,
|
|
411
|
+
plans: parts.plans,
|
|
412
|
+
});
|
|
413
|
+
// Gentle Shell's background jobs; the renderer caps the rows.
|
|
414
|
+
const agents = parts.agents;
|
|
415
|
+
const rdd = rddView(parts.reviews, now);
|
|
416
|
+
const ci = ciView(parts.ci, now);
|
|
417
|
+
const model: PanelModel = {
|
|
418
|
+
session,
|
|
419
|
+
...(headsUp.length > 0 ? { headsUp } : {}),
|
|
420
|
+
...(parts.todo ? { todo: parts.todo } : {}),
|
|
421
|
+
...(parts.odd && parts.odd.steps.length > 0 ? { odd: parts.odd } : {}),
|
|
422
|
+
...(agents ? { agents } : {}),
|
|
423
|
+
...(parts.changes ? { changes: parts.changes } : {}),
|
|
424
|
+
...(rdd ? { rdd } : {}),
|
|
425
|
+
...(ci ? { ci } : {}),
|
|
426
|
+
...(parts.cost !== undefined ? { footer: { cost: parts.cost, ...(parts.tokens ? { tokens: parts.tokens } : {}), ...(parts.tokens && parts.estimate !== undefined ? { estimate: parts.estimate } : {}), ...(parts.review ? { review: parts.review } : {}), ...(parts.rdd ? { rdd: parts.rdd } : {}) } } : {}),
|
|
427
|
+
};
|
|
428
|
+
// Only a drawn spinner carries its frame, so an idle panel's digest never ticks.
|
|
429
|
+
return parts.spinner !== undefined && runsSpinner(model, parts.runSettled === false) ? { ...model, spinner: parts.spinner } : model;
|
|
430
|
+
}
|