@restranger/repi-lib 0.0.0-stage → 0.0.1-ca9b82c
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 +90 -2
- package/package.json +26 -5
- package/src/completion.ts +61 -0
- package/src/config.ts +109 -0
- package/src/contracts/index.ts +4 -0
- package/src/contracts/modes.ts +31 -0
- package/src/contracts/permissions.ts +225 -0
- package/src/contracts/subagents.ts +18 -0
- package/src/contracts/ui.ts +25 -0
- package/src/contracts.ts +39 -0
- package/src/disposable.ts +29 -0
- package/src/index.ts +13 -0
- package/src/model-scoring.ts +46 -0
- package/src/overlay.ts +207 -0
- package/src/pi.ts +272 -0
- package/src/seam.ts +205 -0
- package/src/session.ts +28 -0
- package/src/shimmer.ts +275 -0
- package/src/text.ts +344 -0
- package/src/view.ts +142 -0
package/src/seam.ts
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { type ContractId, READY_CHANNEL, type ReadyEvent, isReadyEvent } from "./contracts.js";
|
|
2
|
+
import { type Disposable, toDisposable } from "./disposable.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Process-global service registry.
|
|
6
|
+
*
|
|
7
|
+
* `Symbol.for` and `globalThis` are process-global by spec, so they survive Pi's per-extension
|
|
8
|
+
* module isolation (jiti with `moduleCache: false`). A normal module-level singleton would not:
|
|
9
|
+
* every extension would get its own copy and discovery would silently fail.
|
|
10
|
+
*/
|
|
11
|
+
const REGISTRY_KEY = Symbol.for("repi.services.v1");
|
|
12
|
+
|
|
13
|
+
interface ServiceEntry {
|
|
14
|
+
readonly owner: string;
|
|
15
|
+
readonly impl: unknown;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type SessionServices = Map<string, ServiceEntry>;
|
|
19
|
+
type Registry = Map<ContractId, SessionServices>;
|
|
20
|
+
|
|
21
|
+
function registry(): Registry {
|
|
22
|
+
const store = globalThis as Record<PropertyKey, unknown>;
|
|
23
|
+
let current = store[REGISTRY_KEY] as Registry | undefined;
|
|
24
|
+
if (!current) {
|
|
25
|
+
current = new Map();
|
|
26
|
+
store[REGISTRY_KEY] = current;
|
|
27
|
+
}
|
|
28
|
+
return current;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function assertNonEmpty(value: string, name: string): void {
|
|
32
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
33
|
+
throw new TypeError(`${name} must be a non-empty string.`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface PublishServiceOptions<T> {
|
|
38
|
+
/** Contract id including its major version, e.g. `re:permissions@1`. */
|
|
39
|
+
readonly contract: ContractId;
|
|
40
|
+
/** Session node that owns this implementation. */
|
|
41
|
+
readonly sessionId: string;
|
|
42
|
+
/** Stable plugin id. Used to distinguish a reload from a conflicting provider. */
|
|
43
|
+
readonly owner: string;
|
|
44
|
+
readonly impl: T;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Publish a service for one contract + session.
|
|
49
|
+
*
|
|
50
|
+
* The same owner may replace its own service (reload / new generation). A different owner is a
|
|
51
|
+
* conflict: two plugins claiming the same contract for the same session is a configuration error,
|
|
52
|
+
* not something to resolve silently by load order.
|
|
53
|
+
*/
|
|
54
|
+
export function publishService<T>(options: PublishServiceOptions<T>): Disposable {
|
|
55
|
+
const { contract, sessionId, owner, impl } = options;
|
|
56
|
+
assertNonEmpty(contract, "contract");
|
|
57
|
+
assertNonEmpty(sessionId, "sessionId");
|
|
58
|
+
assertNonEmpty(owner, "owner");
|
|
59
|
+
|
|
60
|
+
const reg = registry();
|
|
61
|
+
let services = reg.get(contract);
|
|
62
|
+
if (!services) {
|
|
63
|
+
services = new Map();
|
|
64
|
+
reg.set(contract, services);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const existing = services.get(sessionId);
|
|
68
|
+
if (existing && existing.owner !== owner) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Contract "${contract}" for session "${sessionId}" is already provided by "${existing.owner}"; ` +
|
|
71
|
+
`"${owner}" cannot replace it.`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const entry: ServiceEntry = { owner, impl };
|
|
76
|
+
services.set(sessionId, entry);
|
|
77
|
+
|
|
78
|
+
return toDisposable(() => {
|
|
79
|
+
if (services.get(sessionId) === entry) {
|
|
80
|
+
services.delete(sessionId);
|
|
81
|
+
if (services.size === 0) {
|
|
82
|
+
reg.delete(contract);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Resolve the service for a contract + session, or `undefined` when that node has none. */
|
|
89
|
+
export function getService<T>(contract: ContractId, sessionId: string): T | undefined {
|
|
90
|
+
return registry().get(contract)?.get(sessionId)?.impl as T | undefined;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function hasService(contract: ContractId, sessionId: string): boolean {
|
|
94
|
+
return registry().get(contract)?.has(sessionId) ?? false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface ServiceDescriptor {
|
|
98
|
+
readonly contract: ContractId;
|
|
99
|
+
readonly sessionId: string;
|
|
100
|
+
readonly owner: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Snapshot for diagnostics. Sorted so output is deterministic. */
|
|
104
|
+
export function listServices(): readonly ServiceDescriptor[] {
|
|
105
|
+
const result: ServiceDescriptor[] = [];
|
|
106
|
+
for (const [contract, sessions] of registry()) {
|
|
107
|
+
for (const [sessionId, entry] of sessions) {
|
|
108
|
+
result.push({ contract, sessionId, owner: entry.owner });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return result.sort((left, right) =>
|
|
112
|
+
left.contract < right.contract
|
|
113
|
+
? -1
|
|
114
|
+
: left.contract > right.contract
|
|
115
|
+
? 1
|
|
116
|
+
: left.sessionId < right.sessionId
|
|
117
|
+
? -1
|
|
118
|
+
: left.sessionId > right.sessionId
|
|
119
|
+
? 1
|
|
120
|
+
: 0,
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The subset of Pi's event bus this library needs. Kept structural so `lib` stays host-agnostic. */
|
|
125
|
+
export interface EventBus {
|
|
126
|
+
on(event: string, handler: (data: unknown) => void): () => void;
|
|
127
|
+
emit(event: string, data?: unknown): void;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Announce a ready event. The payload is data; the service stays in the seam. */
|
|
131
|
+
export function announceReady(bus: EventBus, event: ReadyEvent): void {
|
|
132
|
+
bus.emit(READY_CHANNEL, event);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Subscribe to ready announcements for one contract.
|
|
137
|
+
*
|
|
138
|
+
* A throwing consumer cannot break the provider or other consumers. The returned disposable is
|
|
139
|
+
* idempotent.
|
|
140
|
+
*/
|
|
141
|
+
/** An `async` handler must not surface as a process-level unhandled rejection. */
|
|
142
|
+
function swallowRejection(result: unknown): void {
|
|
143
|
+
const maybePromise = result as PromiseLike<unknown> | undefined;
|
|
144
|
+
if (maybePromise && typeof maybePromise.then === "function") {
|
|
145
|
+
void Promise.resolve(maybePromise).catch(() => undefined);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function onReady(bus: EventBus, contract: ContractId, handler: (event: ReadyEvent) => unknown): Disposable {
|
|
150
|
+
const off = bus.on(READY_CHANNEL, (data) => {
|
|
151
|
+
if (!isReadyEvent(data) || data.contract !== contract) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
swallowRejection(handler(data));
|
|
156
|
+
} catch {
|
|
157
|
+
// The bus is a broadcast channel; one broken listener must not take down the rest.
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return toDisposable(off);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Pull + push integration in one call: invoke `handler` with the current service if it already
|
|
165
|
+
* exists, then again whenever a matching ready event arrives. Re-announcing the same service does
|
|
166
|
+
* not invoke the handler twice.
|
|
167
|
+
*/
|
|
168
|
+
export function onService<T>(
|
|
169
|
+
bus: EventBus,
|
|
170
|
+
contract: ContractId,
|
|
171
|
+
sessionId: string,
|
|
172
|
+
handler: (service: T, event?: ReadyEvent) => unknown,
|
|
173
|
+
): Disposable {
|
|
174
|
+
let disposed = false;
|
|
175
|
+
let last: T | undefined;
|
|
176
|
+
|
|
177
|
+
const deliver = (event?: ReadyEvent): void => {
|
|
178
|
+
if (disposed) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const service = getService<T>(contract, sessionId);
|
|
182
|
+
if (service === undefined || service === last) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
last = service;
|
|
186
|
+
try {
|
|
187
|
+
swallowRejection(handler(service, event));
|
|
188
|
+
} catch {
|
|
189
|
+
// Keep the subscription alive; the next generation may be healthy.
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const off = onReady(bus, contract, (event) => {
|
|
194
|
+
if (event.sessionId === sessionId) {
|
|
195
|
+
deliver(event);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
// Subscribe first, then pull: a publish between the two is still observed.
|
|
199
|
+
deliver();
|
|
200
|
+
|
|
201
|
+
return toDisposable(() => {
|
|
202
|
+
disposed = true;
|
|
203
|
+
off.dispose();
|
|
204
|
+
});
|
|
205
|
+
}
|
package/src/session.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The smallest shape needed to resolve a session id. Both direct `sessionId` fields and Pi's
|
|
3
|
+
* `sessionManager.getSessionId()` are accepted so the helper works across host contexts.
|
|
4
|
+
*/
|
|
5
|
+
export interface SessionContextLike {
|
|
6
|
+
readonly sessionId?: string;
|
|
7
|
+
readonly sessionManager?: {
|
|
8
|
+
getSessionId?(): string | undefined;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Resolve the current session id.
|
|
14
|
+
*
|
|
15
|
+
* A missing id falls back to `default` so a plugin still works on a host without session support.
|
|
16
|
+
* Multi-session integration degrades in that case; standalone behavior does not.
|
|
17
|
+
*/
|
|
18
|
+
export function getSessionId(ctx: SessionContextLike, fallback = "default"): string {
|
|
19
|
+
const direct = ctx.sessionId;
|
|
20
|
+
if (typeof direct === "string" && direct.length > 0) {
|
|
21
|
+
return direct;
|
|
22
|
+
}
|
|
23
|
+
const managed = ctx.sessionManager?.getSessionId?.();
|
|
24
|
+
if (typeof managed === "string" && managed.length > 0) {
|
|
25
|
+
return managed;
|
|
26
|
+
}
|
|
27
|
+
return fallback;
|
|
28
|
+
}
|
package/src/shimmer.ts
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import type { PiUiCustomTheme } from "./pi.js";
|
|
2
|
+
|
|
3
|
+
/** Stock default working label (`defaultWorkingMessage`). */
|
|
4
|
+
export const WORKING_LABEL = "Working";
|
|
5
|
+
|
|
6
|
+
/** Matches the stock spinner cadence (`Loader.DEFAULT_INTERVAL_MS`). */
|
|
7
|
+
export const SHIMMER_INTERVAL_MS = 80;
|
|
8
|
+
|
|
9
|
+
/** Characters covered by the highlight window. */
|
|
10
|
+
export const HIGHLIGHT_WIDTH = 3;
|
|
11
|
+
|
|
12
|
+
export const DEFAULT_COMPACTION_LABEL = "Compacting context...";
|
|
13
|
+
|
|
14
|
+
export const WORKING_LABEL_LENGTH = Array.from(WORKING_LABEL).length;
|
|
15
|
+
|
|
16
|
+
export interface StatusIndicatorLike {
|
|
17
|
+
kind?: string;
|
|
18
|
+
message?: string;
|
|
19
|
+
setMessage?(message: string): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ParsedCompactionLabel {
|
|
23
|
+
readonly baseLabel: string;
|
|
24
|
+
readonly cancelHint: string | undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getHighlightWidth(labelLength: number): number {
|
|
28
|
+
return Math.max(1, Math.min(HIGHLIGHT_WIDTH, labelLength));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function getSweepWindow(
|
|
32
|
+
labelLength: number,
|
|
33
|
+
step: number,
|
|
34
|
+
): {
|
|
35
|
+
start: number;
|
|
36
|
+
end: number;
|
|
37
|
+
} {
|
|
38
|
+
const highlightWidth = getHighlightWidth(labelLength);
|
|
39
|
+
const cycleLength = labelLength + highlightWidth;
|
|
40
|
+
const start = (step % cycleLength) - highlightWidth;
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
start,
|
|
44
|
+
end: start + highlightWidth,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const pad2 = (value: number): string => String(value).padStart(2, "0");
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Elapsed working time as a suffix, one unit pair at a time: `12s`, `1m05s`,
|
|
52
|
+
* `1h00m`, `2d03h`, `3w01d`. Each step carries its remainder down, so a day
|
|
53
|
+
* never shows as `24h00m` and 60 minutes is exactly `1h00m`. Returns
|
|
54
|
+
* `undefined` below one second so the first frames read exactly like the
|
|
55
|
+
* stock label.
|
|
56
|
+
*/
|
|
57
|
+
export function formatElapsedDuration(elapsedMs: number): string | undefined {
|
|
58
|
+
if (!Number.isFinite(elapsedMs) || elapsedMs < 1000) return undefined;
|
|
59
|
+
|
|
60
|
+
let value = Math.floor(elapsedMs / 1000);
|
|
61
|
+
if (value < 60) return `${value}s`;
|
|
62
|
+
|
|
63
|
+
const seconds = value % 60;
|
|
64
|
+
value = Math.floor(value / 60);
|
|
65
|
+
if (value < 60) return `${value}m${pad2(seconds)}s`;
|
|
66
|
+
|
|
67
|
+
const minutes = value % 60;
|
|
68
|
+
value = Math.floor(value / 60);
|
|
69
|
+
if (value < 24) return `${value}h${pad2(minutes)}m`;
|
|
70
|
+
|
|
71
|
+
const hours = value % 24;
|
|
72
|
+
value = Math.floor(value / 24);
|
|
73
|
+
if (value < 7) return `${value}d${pad2(hours)}h`;
|
|
74
|
+
|
|
75
|
+
return `${Math.floor(value / 7)}w${pad2(value % 7)}d`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Renders a label with a highlight window sweeping across it. Only the
|
|
80
|
+
* window is styled: the rest of the label stays unstyled so the color function
|
|
81
|
+
* wrapping the message keeps applying to it.
|
|
82
|
+
*/
|
|
83
|
+
export function renderShimmerLabel(
|
|
84
|
+
theme: PiUiCustomTheme | { bold(text: string): string } | undefined,
|
|
85
|
+
label: string,
|
|
86
|
+
step: number,
|
|
87
|
+
): string {
|
|
88
|
+
const characters = Array.from(label);
|
|
89
|
+
if (characters.length === 0) return "";
|
|
90
|
+
|
|
91
|
+
const { start, end } = getSweepWindow(characters.length, step);
|
|
92
|
+
const from = Math.max(0, start);
|
|
93
|
+
const to = Math.min(characters.length, end);
|
|
94
|
+
if (to <= from) {
|
|
95
|
+
return label;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const before = characters.slice(0, from).join("");
|
|
99
|
+
const highlighted = characters.slice(from, to).join("");
|
|
100
|
+
const after = characters.slice(to).join("");
|
|
101
|
+
|
|
102
|
+
let boldText = "";
|
|
103
|
+
if (theme && typeof (theme as { bold?: unknown }).bold === "function") {
|
|
104
|
+
try {
|
|
105
|
+
const styled = (theme as { bold(t: string): string }).bold(highlighted);
|
|
106
|
+
if (styled !== highlighted) {
|
|
107
|
+
boldText = styled;
|
|
108
|
+
}
|
|
109
|
+
} catch {
|
|
110
|
+
// Ignore theme errors
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!boldText) {
|
|
114
|
+
boldText = `\x1b[1m${highlighted}\x1b[22m`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return before + boldText + after;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Stock label plus shimmer window plus elapsed-time suffix. The suffix is
|
|
122
|
+
* parenthesized, mirroring stock's `Working (esc to interrupt)`, and stays
|
|
123
|
+
* unstyled so the color function stock wraps the whole message with keeps
|
|
124
|
+
* applying to it.
|
|
125
|
+
*/
|
|
126
|
+
export function renderWorkingMessage(
|
|
127
|
+
theme: PiUiCustomTheme | { bold(text: string): string } | undefined,
|
|
128
|
+
label: string,
|
|
129
|
+
step: number,
|
|
130
|
+
elapsedMs: number,
|
|
131
|
+
): string {
|
|
132
|
+
const elapsed = formatElapsedDuration(elapsedMs);
|
|
133
|
+
const fullText = elapsed === undefined ? label : `${label} (${elapsed})`;
|
|
134
|
+
|
|
135
|
+
return renderShimmerLabel(theme, fullText, step);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Parses a compaction status message into base label and optional cancel hint suffix.
|
|
140
|
+
* e.g. "Compacting context... (escape to cancel)" -> { baseLabel: "Compacting context...", cancelHint: "(escape to cancel)" }
|
|
141
|
+
*/
|
|
142
|
+
export function parseCompactionMessage(message: string | undefined): ParsedCompactionLabel {
|
|
143
|
+
if (!message) {
|
|
144
|
+
return { baseLabel: DEFAULT_COMPACTION_LABEL, cancelHint: "(escape to cancel)" };
|
|
145
|
+
}
|
|
146
|
+
const match = message.match(/^(.*?)(?:\s+(\([^)]+\)))?$/);
|
|
147
|
+
const baseLabel = match?.[1] ? match[1].trim() : DEFAULT_COMPACTION_LABEL;
|
|
148
|
+
const cancelHint = match?.[2] ? match[2].trim() : undefined;
|
|
149
|
+
return { baseLabel, cancelHint };
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Compaction label plus shimmer window plus elapsed-time suffix plus cancel hint.
|
|
154
|
+
*/
|
|
155
|
+
export function renderCompactionMessage(
|
|
156
|
+
theme: PiUiCustomTheme | { bold(text: string): string } | undefined,
|
|
157
|
+
baseLabel: string,
|
|
158
|
+
cancelHint: string | undefined,
|
|
159
|
+
step: number,
|
|
160
|
+
elapsedMs: number,
|
|
161
|
+
): string {
|
|
162
|
+
const elapsed = formatElapsedDuration(elapsedMs);
|
|
163
|
+
let fullText = baseLabel;
|
|
164
|
+
if (elapsed !== undefined) {
|
|
165
|
+
fullText += ` (${elapsed})`;
|
|
166
|
+
}
|
|
167
|
+
if (cancelHint !== undefined) {
|
|
168
|
+
fullText += ` ${cancelHint}`;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return renderShimmerLabel(theme, fullText, step);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function isStatusIndicatorLike(node: unknown): node is StatusIndicatorLike {
|
|
175
|
+
if (!node || typeof node !== "object") return false;
|
|
176
|
+
const record = node as Record<string, unknown>;
|
|
177
|
+
return record.kind === "compaction" && typeof record.setMessage === "function";
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Searches the TUI component tree for an active compaction StatusIndicator.
|
|
182
|
+
* Handles:
|
|
183
|
+
* - Direct StatusIndicator instances
|
|
184
|
+
* - CustomEditor embedded mode (`workingStatusIndicator`)
|
|
185
|
+
* - Rounded/custom editor modes (`embeddedStatusIndicator`, `workingStatusIndicator`)
|
|
186
|
+
* - Generic container properties (`activeStatusIndicator`, `statusIndicator`, etc.)
|
|
187
|
+
* - Generic recursive inspection of children arrays (`children`)
|
|
188
|
+
* - Fullscreen alt-screen layout roots (`layoutRoot`)
|
|
189
|
+
* - Stack entries (`entries[].component`)
|
|
190
|
+
*/
|
|
191
|
+
export function findCompactionIndicator(
|
|
192
|
+
node: unknown,
|
|
193
|
+
depth = 0,
|
|
194
|
+
seen = new Set<unknown>(),
|
|
195
|
+
): StatusIndicatorLike | undefined {
|
|
196
|
+
if (!node || typeof node !== "object" || depth > 8 || seen.has(node)) {
|
|
197
|
+
return undefined;
|
|
198
|
+
}
|
|
199
|
+
seen.add(node);
|
|
200
|
+
|
|
201
|
+
if (isStatusIndicatorLike(node)) {
|
|
202
|
+
return node;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const record = node as Record<string, unknown>;
|
|
206
|
+
|
|
207
|
+
// Check known indicator property names directly first
|
|
208
|
+
const knownFields = ["workingStatusIndicator", "embeddedStatusIndicator", "activeStatusIndicator", "statusIndicator"];
|
|
209
|
+
for (const field of knownFields) {
|
|
210
|
+
try {
|
|
211
|
+
const val = record[field];
|
|
212
|
+
if (isStatusIndicatorLike(val)) return val;
|
|
213
|
+
} catch {
|
|
214
|
+
// Ignore getter errors
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// Check immediate children first to prioritize editor and status containers
|
|
219
|
+
if (Array.isArray(record.children)) {
|
|
220
|
+
for (const child of record.children) {
|
|
221
|
+
if (!child || typeof child !== "object") continue;
|
|
222
|
+
if (isStatusIndicatorLike(child)) return child;
|
|
223
|
+
const childRecord = child as Record<string, unknown>;
|
|
224
|
+
for (const field of knownFields) {
|
|
225
|
+
try {
|
|
226
|
+
const val = childRecord[field];
|
|
227
|
+
if (isStatusIndicatorLike(val)) return val;
|
|
228
|
+
} catch {
|
|
229
|
+
// Ignore getter errors
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Check one more level for container -> editor -> workingStatusIndicator
|
|
233
|
+
if (Array.isArray(childRecord.children)) {
|
|
234
|
+
for (const grandChild of childRecord.children) {
|
|
235
|
+
if (!grandChild || typeof grandChild !== "object") continue;
|
|
236
|
+
if (isStatusIndicatorLike(grandChild)) return grandChild;
|
|
237
|
+
const grandRecord = grandChild as Record<string, unknown>;
|
|
238
|
+
for (const field of knownFields) {
|
|
239
|
+
try {
|
|
240
|
+
const val = grandRecord[field];
|
|
241
|
+
if (isStatusIndicatorLike(val)) return val;
|
|
242
|
+
} catch {
|
|
243
|
+
// Ignore getter errors
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// Recurse into children array
|
|
251
|
+
for (const child of record.children) {
|
|
252
|
+
const found = findCompactionIndicator(child, depth + 1, seen);
|
|
253
|
+
if (found) return found;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// Recurse into layoutRoot (fullscreen ViewportTUI)
|
|
258
|
+
if (record.layoutRoot && typeof record.layoutRoot === "object") {
|
|
259
|
+
const found = findCompactionIndicator(record.layoutRoot, depth + 1, seen);
|
|
260
|
+
if (found) return found;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Recurse into stack entries (VStack / HStack)
|
|
264
|
+
if (Array.isArray(record.entries)) {
|
|
265
|
+
for (const entry of record.entries) {
|
|
266
|
+
if (entry && typeof entry === "object") {
|
|
267
|
+
const comp = (entry as Record<string, unknown>).component ?? entry;
|
|
268
|
+
const found = findCompactionIndicator(comp, depth + 1, seen);
|
|
269
|
+
if (found) return found;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return undefined;
|
|
275
|
+
}
|