zidane 4.1.6 → 4.1.7

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/dist/tui.d.ts CHANGED
@@ -1,355 +1,8 @@
1
- import { D as SessionRun, Et as SessionTurn, H as Provider, It as TurnUsage, Mt as ToolResultContent, O as SessionStore } from "./agent-BAoqUvwA.js";
2
- import { P as Preset } from "./index-B8-yNSsk.js";
3
- import { OAuthCredentials, OAuthProviderInterface } from "@mariozechner/pi-ai/oauth";
4
- import { SyntaxStyle } from "@opentui/core";
1
+ import { F as Picked, G as ModelInfo, L as SessionMeta, R as Settings, V as ProviderAuth, _ as ChatOptions, a as Theme, d as ApprovalRequest, u as ApprovalDecision, y as ResolvedConfig, z as StreamEvent } from "./theme-BlXO6yHe.js";
5
2
  import * as _$react from "react";
6
- import { Dispatch, ReactNode, SetStateAction } from "react";
3
+ import { ReactNode } from "react";
4
+ import { SyntaxStyle } from "@opentui/core";
7
5
 
8
- //#region src/tui/providers.d.ts
9
- /**
10
- * Structural model metadata — compatible with pi-ai's `Model` interface but
11
- * not coupled to it, so hosts can pass either pi-ai-shaped objects or a
12
- * custom registry of their own.
13
- *
14
- * Deliberately a structural duplicate of pi-ai's `Model` rather than a
15
- * re-export: keeps the public API stable when pi-ai bumps shape, and lets
16
- * hosts implement their own registry without depending on pi-ai's types.
17
- *
18
- * Lives here (rather than `./config`) because `ProviderDescriptor.models`
19
- * needs it — pushing it to `config.tsx` created an import cycle.
20
- */
21
- interface ModelInfo {
22
- id: string;
23
- name?: string;
24
- contextWindow: number;
25
- maxTokens?: number;
26
- reasoning?: boolean;
27
- input?: readonly ('text' | 'image')[];
28
- cost?: {
29
- input: number;
30
- output: number;
31
- cacheRead?: number;
32
- cacheWrite?: number;
33
- };
34
- provider?: string;
35
- }
36
- interface ProviderDescriptor {
37
- /**
38
- * Unique identifier. Used as the registry key, persisted in `state.json`
39
- * as the resumed provider, and (by default) as the credential-file key.
40
- */
41
- key: string;
42
- /** Display name shown in the TUI's provider picker and labels. */
43
- label: string;
44
- /**
45
- * Factory that builds a fresh `Provider` instance. Called on every session
46
- * activation. Some factories (e.g. zidane's built-in `anthropic`) eagerly
47
- * resolve credentials at construction time and throw when none are
48
- * configured — set {@link defaultModel} on the descriptor to avoid the TUI
49
- * calling the factory before the user has picked + authed a provider.
50
- */
51
- factory: () => Provider;
52
- /**
53
- * Default model id to seed the picker with. When omitted, the TUI falls
54
- * back to `descriptor.factory().meta.defaultModel`, which constructs the
55
- * provider — fine for lazy-credential factories, but breaks for factories
56
- * that throw on missing credentials before the wizard runs. Setting this
57
- * eagerly lets the TUI render the auth wizard without ever instantiating
58
- * the provider.
59
- */
60
- defaultModel?: string;
61
- /**
62
- * Env var checked when detecting whether the user has an API key
63
- * configured for this provider. Optional — set to `undefined` when the
64
- * provider only supports OAuth (or only credentials via a custom path).
65
- */
66
- envKey?: string;
67
- /**
68
- * Key under which credentials live in `credentials.json`. Defaults to
69
- * `key`. The only built-in that overrides this is OpenAI Codex
70
- * (`openai` → `openai-codex`) to stay compatible with the harness
71
- * provider's existing lookup.
72
- */
73
- credentialFileKey?: string;
74
- /** Placeholder shown in the wizard's API-key input. */
75
- apiKeyPlaceholder?: string;
76
- /**
77
- * pi-ai (or compat) OAuth provider. When present, the wizard offers an
78
- * OAuth option in addition to API key.
79
- */
80
- oauthProvider?: OAuthProviderInterface;
81
- /**
82
- * Optional copy appended to the wizard's "OAuth" method description.
83
- * Use to communicate why a user might pick OAuth (e.g. subscription tier,
84
- * org-wide SSO). Shown after `browser-based sign-in`. Skip the leading
85
- * space — the wizard adds it. Example: `'Claude Pro/Max subscription'`.
86
- */
87
- oauthHint?: string;
88
- /**
89
- * pi-ai provider id used to look up models in pi-ai's built-in registry.
90
- * Defaults to `key`. Only Codex differs (`openai` → `openai-codex`).
91
- */
92
- piProviderId?: string;
93
- /**
94
- * Override the model list returned for this provider's picker. When set,
95
- * skips pi-ai's registry entirely. Useful for hosts maintaining their
96
- * own model catalogue or for custom providers pi-ai doesn't know about.
97
- */
98
- models?: readonly ModelInfo[];
99
- }
100
- /** Convenience accessor — returns `credentialFileKey ?? key`. */
101
- declare function credKeyOf(desc: ProviderDescriptor): string;
102
- /** Convenience accessor — returns `piProviderId ?? key`. */
103
- declare function piIdOf(desc: ProviderDescriptor): string;
104
- declare const anthropicDescriptor: ProviderDescriptor;
105
- declare const openaiDescriptor: ProviderDescriptor;
106
- declare const openrouterDescriptor: ProviderDescriptor;
107
- declare const cerebrasDescriptor: ProviderDescriptor;
108
- /**
109
- * Default provider registry. Passed verbatim when `runTui` is invoked without
110
- * an explicit `providers` option. Hosts that want to override per-provider
111
- * metadata can spread this and replace specific entries:
112
- *
113
- * ```ts
114
- * runTui({ providers: { ...BUILTIN_PROVIDERS, anthropic: myOwnAnthropicDescriptor } })
115
- * ```
116
- */
117
- declare const BUILTIN_PROVIDERS: Readonly<Record<string, ProviderDescriptor>>;
118
- /**
119
- * Resolve the model list for a given provider. Honors `descriptor.models`
120
- * when set; otherwise queries pi-ai via `descriptor.piProviderId`. Returns
121
- * `[]` for descriptors with no known mapping (custom providers without a
122
- * model list) — callers should hide the model picker in that case.
123
- */
124
- declare function modelsForDescriptor(descriptor: ProviderDescriptor): readonly ModelInfo[];
125
- /**
126
- * Look up the model's max context window via the descriptor's model source.
127
- * Returns `null` when the model isn't known (custom slugs, providers without
128
- * a registry); callers should hide the context indicator in that case.
129
- */
130
- declare function getContextWindow(descriptor: ProviderDescriptor, modelId: string): number | null;
131
- //#endregion
132
- //#region src/tui/auth.d.ts
133
- /**
134
- * Provider identifier as known to the TUI. Built-in keys are `anthropic`,
135
- * `openai`, `openrouter`, `cerebras`, but hosts can register additional
136
- * keys via {@link ProviderDescriptor} — so the type is open.
137
- */
138
- type ProviderKey = string;
139
- interface AuthMethod {
140
- source: 'env' | 'oauth' | 'apikey';
141
- /** Human-readable detail (env var name, expiry timestamp, …). */
142
- detail: string;
143
- }
144
- interface ProviderAuth {
145
- key: ProviderKey;
146
- label: string;
147
- /** True when at least one credential source is present. */
148
- available: boolean;
149
- methods: AuthMethod[];
150
- }
151
- /**
152
- * Detect available auth for every registered provider.
153
- *
154
- * Resolution order per provider (a method appears in `methods` for each
155
- * layer that has a credential — the agent itself resolves them in the same
156
- * order via its provider factories):
157
- *
158
- * 1. `kind: 'apikey'` from `credentials.json` (injected into env at TUI launch)
159
- * 2. explicit env var (descriptor's `envKey`)
160
- * 3. `kind: 'oauth'` from `credentials.json` (or legacy `cwd/.credentials.json`)
161
- *
162
- * Pure read — never refreshes or rewrites the credentials file.
163
- */
164
- declare function detectAuth(dataDir: string, registry: Readonly<Record<string, ProviderDescriptor>>, env?: Record<string, string | undefined>): ProviderAuth[];
165
- //#endregion
166
- //#region src/tui/types.d.ts
167
- type Screen = 'auth' | 'sessions' | 'chat';
168
- /** Identifies the agent that produced a streaming event. */
169
- type Owner = 'parent' | string;
170
- interface StreamEvent {
171
- kind: 'thinking' | 'tool' | 'tool-result' | 'error' | 'info' | 'separator' | 'markdown' | 'spawn-start' | 'spawn-end';
172
- text: string;
173
- /**
174
- * For `markdown` events: true while the block is still receiving deltas.
175
- * The renderer applies `md4x.heal()` and keeps OpenTUI's markdown parser in
176
- * streaming mode while this is true. Flipped to false on `turn:after`.
177
- */
178
- streaming?: boolean;
179
- /** Subagent that produced this event. Absent / 'parent' = top-level agent. */
180
- childId?: string;
181
- /** Nesting depth — 0 = parent, ≥ 1 = subagent (matches zidane's spawn depth). */
182
- depth?: number;
183
- /**
184
- * Canonical tool name for `tool` / `tool-result` events. Lets the renderer
185
- * filter by tool — e.g. hide the parent's `spawn` tool-result when
186
- * `hideSubagentOutput` is on, since the spawn-end marker already shows the
187
- * same stats. Absent for non-tool events.
188
- */
189
- tool?: string;
190
- }
191
- interface Picked {
192
- provider: ProviderAuth;
193
- model: string;
194
- }
195
- interface SessionMeta {
196
- id: string;
197
- title: string;
198
- turnCount: number;
199
- updatedAt: number;
200
- }
201
- /** Persisted, user-toggleable transcript filters and modes. */
202
- interface Settings {
203
- showThinking: boolean;
204
- showToolCalls: boolean;
205
- showToolResults: boolean;
206
- /**
207
- * Safe mode — when enabled, every tool call requires explicit user
208
- * approval unless it's covered by the project safelist (`projects.json`)
209
- * or the implicit read-only allow-list. Default: on.
210
- */
211
- safeMode: boolean;
212
- /**
213
- * Hide a subagent's internal events (its streamed markdown, thinking,
214
- * tool calls, and tool results) from the transcript. The `🌱` start and
215
- * `✓` end markers stay visible so the user still sees that a subagent
216
- * is working and when it finished. Default: on — subagent runs are
217
- * usually noisy and the parent's final response already summarizes them.
218
- *
219
- * When off, those events are visible and wrapped in a dim bordered box
220
- * for clear visual hierarchy.
221
- */
222
- hideSubagentOutput: boolean;
223
- }
224
- //#endregion
225
- //#region src/tui/store.d.ts
226
- declare function createTuiStore(dbPath: string): SessionStore;
227
- interface TuiState {
228
- lastProvider?: ProviderKey;
229
- lastSessionId?: string;
230
- /** Per-provider last-used model id. */
231
- lastModelByProvider?: Partial<Record<ProviderKey, string>>;
232
- /** User-toggled transcript filters. Persisted so they outlive a launch. */
233
- settings?: Partial<Settings>;
234
- }
235
- interface StateStoreApi {
236
- load: () => TuiState;
237
- save: (state: TuiState) => void;
238
- }
239
- declare function createStateStore(path: string): StateStoreApi;
240
- declare function loadState(path: string): TuiState;
241
- declare function saveState(path: string, state: TuiState): void;
242
- /**
243
- * Load every session and project it to the compact `SessionMeta` shape used by
244
- * the picker. Sorted by recency via the underlying store's `list()` contract
245
- * (sqlite store returns by `updated_at DESC`).
246
- */
247
- declare function listSessionMeta(store: SessionStore): Promise<SessionMeta[]>;
248
- /** Derive a short title from the first user message — returns null when empty. */
249
- declare function titleFromTurns(turns: SessionTurn[]): string | null;
250
- /**
251
- * Replay persisted turns as a viewable transcript. Mirrors the event shape
252
- * produced live by the agent hooks so loaded and streaming history render
253
- * identically — including subagent ancestry when `runs` is supplied.
254
- *
255
- * Subagent reconstruction:
256
- * - Every turn carries a `runId`. We look that up in `runs` to get the
257
- * run's `depth` and tag the resulting events with `{ depth, childId }`
258
- * — the same shape the live `child:*` bubble hooks produce.
259
- * - We synthesize `spawn-start` / `spawn-end` markers at each child-run
260
- * boundary so the transcript reads the same as a live run did
261
- * (`🌱 [run-id] task` … child events … `🌳 [run-id] done · tokens`).
262
- * - For child runs (`depth > 0`), the user-role "task" text is suppressed
263
- * because `spawn-start` already shows it.
264
- *
265
- * Without `runs` (legacy callers / tests), the function falls back to the
266
- * old behavior: depth-0 events with no subagent grouping.
267
- */
268
- declare function eventsFromTurns(turns: SessionTurn[], runs?: readonly SessionRun[]): StreamEvent[];
269
- /** Shared formatter for the `↳ name(args)` line shown on tool calls. */
270
- declare function toolCallPreview(name: string, input: Record<string, unknown>): string;
271
- /** Render tool output as plain text, whether it's a string or structured content. */
272
- declare function toolResultText(output: string | ToolResultContent[]): string;
273
- /** Effective context size of the most recent assistant turn — drives the footer indicator. */
274
- declare function lastContextSizeFromTurns(turns: SessionTurn[]): number;
275
- //#endregion
276
- //#region src/tui/config.d.ts
277
- /**
278
- * Provider registry — a map keyed by `descriptor.key`. Passed verbatim to the
279
- * TUI; there is no implicit merge with built-ins. Hosts that want the four
280
- * default providers spread {@link BUILTIN_PROVIDERS}; hosts that only want
281
- * their own pass exactly their own.
282
- */
283
- type ProviderRegistry = Readonly<Record<string, ProviderDescriptor>>;
284
- /**
285
- * Options accepted by `runTui()` and `resolveConfig()`. Every field is optional
286
- * — defaults boot a working chat against the built-in providers with sessions
287
- * stored under `~/.zidane/`.
288
- */
289
- interface TuiOptions {
290
- /**
291
- * Directory name used under `storageDir` for sessions + state.
292
- * Default: `'.zidane'` → `~/.zidane/sessions.db` + `~/.zidane/state.json`.
293
- * Pass e.g. `'.myapp'` for `~/.myapp/...`, or `'myapp'` for a visible dir.
294
- */
295
- prefix?: string;
296
- /**
297
- * Storage root. Defaults to the user's home directory. Combined with
298
- * `prefix` to form the data directory.
299
- */
300
- storageDir?: string;
301
- /**
302
- * Provider registry. Each value is a {@link ProviderDescriptor} carrying
303
- * label + factory + credential metadata. **No automatic merge** — hosts
304
- * pass exactly what they want.
305
- *
306
- * - Omitted → {@link BUILTIN_PROVIDERS} (anthropic + openai + openrouter + cerebras).
307
- * - `providers: BUILTIN_PROVIDERS` → same as omitted, but explicit.
308
- * - `providers: { anthropic: anthropicDescriptor }` → only Anthropic.
309
- * - `providers: { ...BUILTIN_PROVIDERS, mine: customDescriptor }` → built-ins + custom.
310
- * - `providers: { mine: customDescriptor }` → custom-only, **no built-ins**.
311
- */
312
- providers?: ProviderRegistry;
313
- /**
314
- * Agent preset (tools, system prompt, behavior). Default: `basic`.
315
- */
316
- preset?: Preset;
317
- /**
318
- * Bring your own session store. Default: a SQLite store at
319
- * `<storageDir>/<prefix>/sessions.db`.
320
- */
321
- store?: SessionStore;
322
- }
323
- interface ResolvedConfig {
324
- prefix: string;
325
- storageDir: string;
326
- paths: {
327
- dir: string;
328
- db: string;
329
- state: string;
330
- };
331
- providers: ProviderRegistry;
332
- preset: Preset;
333
- store: SessionStore;
334
- stateStore: StateStoreApi;
335
- /** Lookup by `ProviderKey` returning the available models for the picker. */
336
- modelsFor: (key: ProviderKey) => readonly ModelInfo[];
337
- initialState: TuiState;
338
- initialSettings: Partial<Settings>;
339
- resumeProvider: ProviderAuth | null;
340
- initialPicked: Picked | null;
341
- }
342
- /** Resolve user options into a fully-bound runtime config. Pure aside from disk reads. */
343
- declare function resolveConfig(options?: TuiOptions): ResolvedConfig;
344
- declare function ConfigProvider({
345
- config,
346
- children
347
- }: {
348
- config: ResolvedConfig;
349
- children: ReactNode;
350
- }): ReactNode;
351
- declare function useConfig(): ResolvedConfig;
352
- //#endregion
353
6
  //#region src/tui/app.d.ts
354
7
  /**
355
8
  * Top-level TUI component. Accepts a fully-resolved `ResolvedConfig` and wires
@@ -402,6 +55,20 @@ declare function Transcript({
402
55
  events: StreamEvent[];
403
56
  settings: Settings;
404
57
  }): _$react.ReactNode;
58
+ /**
59
+ * Per-event visibility — filters honor user toggles and the
60
+ * `hideSubagentOutput` setting. When subagent output is hidden:
61
+ * - Child-agent events are filtered down to the `spawn-start` /
62
+ * `spawn-end` markers so the user still sees "🌱 working… 🌳 done".
63
+ * - The parent's `tool-result` for `spawn` is hidden too. Its body
64
+ * duplicates `spawn-end`'s stats line *and* the parent's next markdown
65
+ * turn ("Here's what the sub-agent found: …"). Showing it again
66
+ * produced an extra `┃ [sub-agent child-1] Completed …` block that
67
+ * the user just wanted gone.
68
+ *
69
+ * Exported so the visibility matrix can be unit-tested without rendering.
70
+ */
71
+ declare function isVisible(event: StreamEvent, settings: Settings): boolean;
405
72
  /**
406
73
  * Resolve the top margin for an event given the one rendered just before it.
407
74
  *
@@ -422,74 +89,6 @@ declare function Transcript({
422
89
  */
423
90
  declare function marginTopFor(event: StreamEvent, previous: StreamEvent | undefined): number;
424
91
  //#endregion
425
- //#region src/tui/credentials.d.ts
426
- interface ApiKeyCredential {
427
- kind: 'apikey';
428
- value: string;
429
- }
430
- interface OAuthCredential {
431
- kind: 'oauth';
432
- access: string;
433
- refresh?: string;
434
- expires?: number;
435
- /** Provider-specific extras (e.g. OpenAI Codex `accountId`). */
436
- [extra: string]: unknown;
437
- }
438
- type ProviderCredential = ApiKeyCredential | OAuthCredential;
439
- /** Top-level shape of `credentials.json` — keys are credential-file keys. */
440
- type CredentialsFile = Record<string, ProviderCredential>;
441
- /**
442
- * Resolve the credentials file path given the resolved TUI data directory
443
- * (typically `~/.zidane`, i.e. `config.paths.dir`).
444
- *
445
- * Matches the convention used elsewhere in the TUI (sessions.db, state.json)
446
- * so a single `ZIDANE_STORAGE_DIR` override moves the entire data root.
447
- */
448
- declare function credentialsPath(dataDir: string): string;
449
- /**
450
- * Read credentials from disk.
451
- *
452
- * Returns `{}` when the file is missing or corrupt (last-ditch tolerance —
453
- * a hand-edit gone wrong shouldn't lock the user out of re-authing). On first
454
- * call with no file present, attempts a migration from `cwd/.credentials.json`
455
- * (the legacy location used by `bun run auth`).
456
- */
457
- declare function readCredentials(dataDir: string): CredentialsFile;
458
- /** Read a single provider's credential (translating via the descriptor). */
459
- declare function readProviderCredential(dataDir: string, descriptor: ProviderDescriptor): ProviderCredential | undefined;
460
- /**
461
- * Write credentials atomically (write-then-rename) with mode 0o600.
462
- *
463
- * Atomic on the same filesystem — readers either see the previous file or the
464
- * new one, never a half-written intermediate. Creates the parent dir if needed
465
- * (first launch on a fresh machine: `~/.zidane/` may not exist yet).
466
- */
467
- declare function writeCredentials(dataDir: string, creds: CredentialsFile): void;
468
- declare function setProviderCredential(dataDir: string, descriptor: ProviderDescriptor, cred: ProviderCredential): void;
469
- declare function removeProviderCredential(dataDir: string, descriptor: ProviderDescriptor): void;
470
- /**
471
- * Inject API-key credentials into `process.env` so the harness providers pick
472
- * them up via their existing env-var resolution. Called once at TUI launch
473
- * after the credentials file has been resolved. OAuth credentials are NOT
474
- * injected — those reach providers via `ZIDANE_CREDENTIALS_PATH` + the file
475
- * reader in `src/providers/oauth.ts`.
476
- *
477
- * Does not overwrite env vars that are already set — explicit user-provided
478
- * env values win over stored API keys.
479
- *
480
- * Descriptors without an `envKey` (OAuth-only providers, custom providers
481
- * that bypass env-var resolution) are skipped silently.
482
- */
483
- declare function applyApiKeyEnv(dataDir: string, registry: Readonly<Record<string, ProviderDescriptor>>): void;
484
- //#endregion
485
- //#region src/tui/format.d.ts
486
- /** Compact token formatter — 12_415 → "12.4k", 1_234_567 → "1.23M". */
487
- declare function fmtTokens(n: number): string;
488
- /** Compact relative-time formatter — "just now / 5m / 3h / 2d". */
489
- declare function ageString(ts: number, now?: number): string;
490
- /** Six-char short form of a session id for headers and lists. */
491
- declare function shortId(id: string): string;
492
- //#endregion
493
92
  //#region src/tui/modal.d.ts
494
93
  interface ModalApi {
495
94
  open: (node: ReactNode) => void;
@@ -562,134 +161,6 @@ declare function ModelPickerModal({
562
161
  onPick: (modelId: string) => void;
563
162
  }): _$react.ReactNode;
564
163
  //#endregion
565
- //#region src/tui/oauth.d.ts
566
- declare function supportsOAuth(descriptor: ProviderDescriptor): boolean;
567
- interface OAuthFlowOptions {
568
- /** Called when the provider emits its login URL — typically right after the callback server starts. */
569
- onUrl: (url: string, instructions?: string) => void;
570
- /** Called when the provider needs a code entered manually (rare; only when callback server fails). */
571
- onCodeRequest?: () => Promise<string>;
572
- /** Called with each progress message from the OAuth flow (token exchange, etc.). */
573
- onProgress?: (message: string) => void;
574
- /** Abort the in-flight login (e.g. user pressed esc). */
575
- signal?: AbortSignal;
576
- }
577
- /**
578
- * Run the OAuth login flow for a provider.
579
- *
580
- * Returns the OAuth credentials on success; caller persists them via
581
- * `setProviderCredential(dataDir, descriptor, { kind: 'oauth', ...credentials })`.
582
- * Throws when the descriptor has no `oauthProvider` configured.
583
- */
584
- declare function runOAuthLogin(descriptor: ProviderDescriptor, options: OAuthFlowOptions): Promise<OAuthCredentials>;
585
- //#endregion
586
- //#region src/tui/safe-mode.d.ts
587
- /**
588
- * Safe-mode storage + matching for the TUI.
589
- *
590
- * Lives at `<dataDir>/projects.json` (default `~/.zidane/projects.json`). Each
591
- * top-level key is an absolute project directory; the value carries that
592
- * project's persisted tool-call `safelist`.
593
- *
594
- * ```json
595
- * {
596
- * "/Users/me/proj-a": { "safelist": ["read_file", "shell:git:*"] }
597
- * }
598
- * ```
599
- *
600
- * Two granularities for safelist entries:
601
- * - **bare tool name** — `"read_file"` matches every `read_file` call.
602
- * - **tool + first-arg token + wildcard** — `"shell:git:*"` matches `shell`
603
- * calls whose primary string argument starts with the token `git`
604
- * (followed by whitespace or end-of-string). Modelled on Claude Code's
605
- * `Bash(git:*)` syntax.
606
- *
607
- * A short list of read-only tools is **implicitly safe** without being
608
- * persisted — see {@link IMPLICITLY_SAFE_TOOLS}.
609
- */
610
- interface ProjectEntry {
611
- safelist?: string[];
612
- }
613
- type ProjectsFile = Record<string, ProjectEntry>;
614
- /** Resolve `projects.json`'s on-disk path given the TUI data directory. */
615
- declare function projectsFilePath(dataDir: string): string;
616
- declare function readProjects(dataDir: string): ProjectsFile;
617
- /** Atomic write — tmp + rename so a crash never leaves a half-file. */
618
- declare function writeProjects(dataDir: string, file: ProjectsFile): void;
619
- /**
620
- * Append `entry` to the safelist for `projectDir`, dedup-aware. Returns the
621
- * updated entry list (post-write) so callers can render it without re-reading.
622
- */
623
- declare function addToSafelist(dataDir: string, projectDir: string, entry: string): readonly string[];
624
- /** Read the safelist for one project. Returns `[]` for unknown projects. */
625
- declare function getSafelist(dataDir: string, projectDir: string): readonly string[];
626
- /**
627
- * Tools that always pass without prompting — pure file/dir reads with no
628
- * side effects. Users who want to gate them must disable safe-mode entirely
629
- * (or fork this list in their own embedding).
630
- */
631
- declare const IMPLICITLY_SAFE_TOOLS: readonly string[];
632
- /**
633
- * Test whether a `{ tool, input }` pair is covered by one safelist entry.
634
- *
635
- * Supported entry shapes:
636
- * - `"<tool>"` — broad match on tool name. For `shell` this still requires
637
- * a single-program command (compound forms always prompt).
638
- * - `"<tool>:<token>:*"` — match when the primary arg's first token equals
639
- * `<token>`. For `shell`, also requires the command to be free of
640
- * metacharacters (`;`, `&&`, `||`, `|`, `$(`, backticks, `>`, `<`,
641
- * newlines, subshells) — otherwise a `shell:git:*` entry would silently
642
- * greenlight `git status && rm -rf /`.
643
- *
644
- * Entries that don't fit either shape are ignored (forward-compat for future
645
- * pattern syntax — readers shouldn't choke on entries written by a newer
646
- * version of the TUI).
647
- */
648
- declare function matchesSafelistEntry(entry: string, tool: string, input: Record<string, unknown>): boolean;
649
- /** True when a call matches ANY entry in the project's safelist (or is implicitly safe). */
650
- declare function isOnSafelist(entries: readonly string[], tool: string, input: Record<string, unknown>): boolean;
651
- /**
652
- * Suggest the safelist entry to write when the user picks "accept and
653
- * remember" for a `{ tool, input }`. Heuristic:
654
- *
655
- * - `shell` → scope by first command token (`shell:git:*`).
656
- * - anything else → bare tool name (broad).
657
- *
658
- * Returning a string ensures the UI always has a concrete entry to display
659
- * as the button label.
660
- */
661
- declare function suggestSafelistEntry(tool: string, input: Record<string, unknown>): string;
662
- //#endregion
663
- //#region src/tui/safe-mode-context.d.ts
664
- type ApprovalDecision = 'accept-once' | 'accept-safelist' | 'deny';
665
- interface ApprovalRequest {
666
- id: string;
667
- tool: string;
668
- input: Record<string, unknown>;
669
- resolve: (decision: ApprovalDecision) => void;
670
- }
671
- /** Function signature consumed by `tool:gate` handlers + the child-tool wrap. */
672
- type RequestApproval = (tool: string, input: Record<string, unknown>) => Promise<ApprovalDecision>;
673
- interface SafeModeActions {
674
- /** Request a decision; resolves once the user picks. */
675
- requestApproval: RequestApproval;
676
- /** Resolve the head and shift the queue forward. */
677
- resolveHead: (decision: ApprovalDecision) => void;
678
- /** Resolve all pending with `deny`. Used on abort / hard exit. */
679
- denyAll: () => void;
680
- }
681
- /**
682
- * Owns the queue + actions. Splits the value across two contexts so a queue
683
- * change doesn't invalidate every callback memo that closes over the actions.
684
- */
685
- declare function SafeModeProvider({
686
- children
687
- }: {
688
- children: ReactNode;
689
- }): ReactNode;
690
- declare function useSafeModeQueue(): readonly ApprovalRequest[];
691
- declare function useSafeModeActions(): SafeModeActions;
692
- //#endregion
693
164
  //#region src/tui/screens.d.ts
694
165
  declare function AuthScreen({
695
166
  onPick
@@ -725,22 +196,7 @@ declare function ChatScreen({
725
196
  onApproval: (decision: ApprovalDecision) => void;
726
197
  }): ReactNode;
727
198
  //#endregion
728
- //#region src/tui/settings.d.ts
729
- declare const DEFAULT_SETTINGS: Settings;
730
- interface SettingsContextValue {
731
- settings: Settings;
732
- toggle: (key: keyof Settings) => void;
733
- }
734
- declare function SettingsProvider({
735
- initial,
736
- onChange,
737
- children
738
- }: {
739
- initial: Settings;
740
- onChange?: (settings: Settings) => void;
741
- children: ReactNode;
742
- }): ReactNode;
743
- declare function useSettings(): SettingsContextValue;
199
+ //#region src/tui/settings-modal.d.ts
744
200
  interface SettingsActions {
745
201
  /**
746
202
  * Re-open the auth screen so the user can switch providers or run the
@@ -753,83 +209,24 @@ declare function SettingsModal({
753
209
  actions
754
210
  }?: {
755
211
  actions?: SettingsActions;
756
- }): ReactNode;
757
- //#endregion
758
- //#region src/tui/streaming.d.ts
759
- /** Flip any trailing streaming markdown blocks (any owner) to finalized. */
760
- declare function finalizeStreamingMarkdown(events: StreamEvent[]): StreamEvent[];
761
- /** Flip the trailing streaming markdown block for one specific owner. */
762
- declare function finalizeStreamingMarkdownForOwner(events: StreamEvent[], owner: Owner): StreamEvent[];
763
- /**
764
- * Effective context size for a single turn.
765
- *
766
- * `usage.input` is misleading on its own when prompt caching is active: providers
767
- * (Anthropic, OpenRouter→Anthropic, Gemini) report `input` as the *new uncached*
768
- * tokens only — the cached prefix shows up in `cacheRead`, and newly-cached
769
- * tokens in `cacheCreation`. The model still saw all three buckets, so the real
770
- * context-window utilization is their sum.
771
- *
772
- * Non-caching providers leave `cacheRead`/`cacheCreation` undefined, so this
773
- * collapses to plain `input` for them.
774
- */
775
- declare function turnContextSize(usage: TurnUsage | undefined): number;
776
- interface StreamSource {
777
- /** Pass `undefined` / omit for parent-agent events. */
778
- childId?: string;
779
- /** Nesting depth — 0 for parent, ≥ 1 for subagents. */
780
- depth?: number;
781
- }
782
- interface StreamBuffer {
783
- /** Queue a streaming delta for the next flush tick. */
784
- queueStreamDelta: (kind: 'markdown' | 'thinking', delta: string, source?: StreamSource) => void;
785
- /** Drain pending deltas immediately, then append a non-streaming event. */
786
- appendImmediate: (evt: StreamEvent) => void;
787
- /** Drain pending deltas immediately, then transform the event list. */
788
- flushAndUpdate: (update: (events: StreamEvent[]) => StreamEvent[]) => void;
789
- /** Drain pending deltas without further transformation. */
790
- flush: () => void;
791
- /** Cancel any pending flush and drop buffered deltas (on session teardown). */
792
- reset: () => void;
793
- }
794
- declare function useStreamBuffer(setEvents: Dispatch<SetStateAction<StreamEvent[]>>): StreamBuffer;
212
+ }): _$react.ReactNode;
795
213
  //#endregion
796
214
  //#region src/tui/theme.d.ts
797
215
  /**
798
- * Shared color palette. Kept as plain hex strings so it can be consumed by
799
- * OpenTUI props that accept `string | RGBA`. The names describe role, not
800
- * literal hue, so the theme can be swapped without touching call sites.
801
- */
802
- declare const COLOR: {
803
- readonly brand: "#FFCC00";
804
- readonly accent: "#00FF88";
805
- readonly model: "#88CCFF";
806
- readonly warn: "#FFAA66";
807
- readonly error: "#FF6666";
808
- readonly dim: "#888888";
809
- readonly mute: "#555555";
810
- readonly border: "#333333";
811
- readonly borderActive: "#555555";
812
- };
813
- /**
814
- * Shared select styling — keeps the highlight bar from filling with a
815
- * different background than the surrounding box. The `▶` marker and the
816
- * brand-colored selected text carry the focus affordance.
216
+ * Convert the renderer-agnostic `Theme.syntax` map (hex strings + plain
217
+ * booleans) into an OpenTUI `SyntaxStyle`. Used both for the markdown
218
+ * structural captures (`markup.heading`, `markup.bold`, …) and the
219
+ * embedded Tree-sitter language tokens (`keyword`, `string`, `function`,
220
+ * …) — OpenTUI's `<markdown>` re-uses the same `SyntaxStyle` for the
221
+ * fenced-code renderable, so one table drives both surfaces.
817
222
  */
818
- declare const SELECT_THEME: {
819
- readonly backgroundColor: "transparent";
820
- readonly focusedBackgroundColor: "transparent";
821
- readonly selectedBackgroundColor: "transparent";
822
- readonly selectedTextColor: "#FFCC00";
823
- readonly textColor: "#888888";
824
- readonly descriptionColor: "#555555";
825
- readonly selectedDescriptionColor: "#888888";
826
- };
223
+ declare function buildMdStyle(theme: Theme): SyntaxStyle;
827
224
  /**
828
- * Theme for markdown token highlighting. Token names map to Tree-sitter highlight
829
- * captures emitted by OpenTUI's markdown parser; the `default` entry is the
830
- * fallback for unstyled text.
225
+ * Active markdown / syntax-highlighting style, memoized per theme. Reading
226
+ * this in a component subscribes it to theme changes a `Settings.theme`
227
+ * flip immediately re-renders the affected `<markdown>` instances.
831
228
  */
832
- declare const MD_STYLE: SyntaxStyle;
229
+ declare function useMdStyle(): SyntaxStyle;
833
230
  //#endregion
834
231
  //#region src/tui/index.d.ts
835
232
  /**
@@ -860,7 +257,8 @@ declare const MD_STYLE: SyntaxStyle;
860
257
  * to `runTui({ storageDir, prefix })`.
861
258
  *
862
259
  * ```ts
863
- * import { BUILTIN_PROVIDERS, runTui } from 'zidane/tui'
260
+ * import { BUILTIN_PROVIDERS } from 'zidane/chat'
261
+ * import { runTui } from 'zidane/tui'
864
262
  * import { createRemoteStore } from 'zidane/session' // for the `store` option
865
263
  *
866
264
  * await runTui() // ~/.zidane/sessions.db + state.json
@@ -870,7 +268,7 @@ declare const MD_STYLE: SyntaxStyle;
870
268
  * await runTui({ store: createRemoteStore({ url: '…' }) })
871
269
  * ```
872
270
  */
873
- declare function runTui(options?: TuiOptions): Promise<never>;
271
+ declare function runTui(options?: ChatOptions): Promise<never>;
874
272
  //#endregion
875
- export { type ApiKeyCredential, App, type ApprovalDecision, type ApprovalRequest, type AuthMethod, AuthScreen, BUILTIN_PROVIDERS, COLOR, ChatScreen, ConfigProvider, type ContextUsage, type CredentialsFile, DEFAULT_SETTINGS, Footer, type Hint, IMPLICITLY_SAFE_TOOLS, MD_STYLE, Modal, type ModalProps, ModalRoot, type ModelInfo, ModelPickerModal, type OAuthCredential, type OAuthFlowOptions, type Owner, type Picked, type ProjectEntry, type ProjectsFile, type ProviderAuth, type ProviderCredential, type ProviderDescriptor, type ProviderKey, type ProviderRegistry, type RequestApproval, type ResolvedConfig, SELECT_THEME, type SafeModeActions, SafeModeProvider, type Screen, type SessionMeta, SessionsScreen, type Settings, SettingsModal, SettingsProvider, Spinner, type StateStoreApi, type StreamBuffer, type StreamEvent, type StreamSource, Transcript, type TuiOptions, type TuiState, addToSafelist, ageString, anthropicDescriptor, applyApiKeyEnv, cerebrasDescriptor, createStateStore, createTuiStore, credKeyOf, credentialsPath, detectAuth, eventsFromTurns, finalizeStreamingMarkdown, finalizeStreamingMarkdownForOwner, fmtTokens, getContextWindow, getSafelist, isOnSafelist, lastContextSizeFromTurns, listSessionMeta, loadState, marginTopFor, matchesSafelistEntry, modelsForDescriptor, onInputSubmit, openaiDescriptor, openrouterDescriptor, piIdOf, projectsFilePath, readCredentials, readProjects, readProviderCredential, removeProviderCredential, resolveConfig, runOAuthLogin, runTui, saveState, setProviderCredential, shortId, suggestSafelistEntry, supportsOAuth, titleFromTurns, toolCallPreview, toolResultText, turnContextSize, useConfig, useModal, useModalAwareFocus, useSafeModeActions, useSafeModeQueue, useSettings, useStreamBuffer, writeCredentials, writeProjects };
273
+ export { App, AuthScreen, ChatScreen, type ContextUsage, Footer, type Hint, Modal, type ModalProps, ModalRoot, ModelPickerModal, SessionsScreen, type SettingsActions, SettingsModal, Spinner, Transcript, buildMdStyle, isVisible, marginTopFor, onInputSubmit, runTui, useMdStyle, useModal, useModalAwareFocus };
876
274
  //# sourceMappingURL=tui.d.ts.map