@xmoon76/dsh-pi-tui 0.5.4 → 0.5.5

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.
Files changed (46) hide show
  1. package/README.en.md +28 -7
  2. package/README.md +25 -6
  3. package/dist/application-runtime-CbBO4bY-.mjs +6860 -0
  4. package/dist/bootstrap-DLOydLLj.mjs +108410 -0
  5. package/dist/builtins.mjs +2 -3
  6. package/dist/client-bootstrap-DwSFzcTW.mjs +872 -0
  7. package/dist/context-summary-Bz0AGXa1.mjs +12027 -0
  8. package/dist/{context-summary-DAisTA_7.mjs → context-summary-D9mhxPXL.mjs} +1468 -10
  9. package/dist/custom-items-CKrOBCox.mjs +655 -0
  10. package/dist/disposal-BYBbEpVY.mjs +54 -0
  11. package/dist/dispose-cause-BzcXo4hu.mjs +123 -0
  12. package/dist/dist-C7QMk0ws.mjs +15431 -0
  13. package/dist/{entry-control-DvSrndWd.mjs → entry-control-DnduyDiw.mjs} +12 -31
  14. package/dist/{extensions-CcuMY4n2.mjs → extensions-pcFiH7Qe.mjs} +758 -68
  15. package/dist/extensions.mjs +1 -1
  16. package/dist/host-bootstrap-CKdfLkNS.mjs +188 -0
  17. package/dist/host-foundation-probe-CYHsbAw6.mjs +143 -0
  18. package/dist/host-prerequisites-9JBTtVNu.mjs +36 -0
  19. package/dist/host-runtime.d.mts +26 -0
  20. package/dist/host-runtime.mjs +450 -0
  21. package/dist/index.d.mts +8 -1
  22. package/dist/index.mjs +5192 -2118
  23. package/dist/local-client.mjs +1681 -188
  24. package/dist/local-discovery-CXnLT4GF.mjs +755 -0
  25. package/dist/local-discovery-DVFFpfBG.mjs +2 -0
  26. package/dist/local-host.mjs +927 -78
  27. package/dist/local-transport-C9aonplC.mjs +513 -0
  28. package/dist/performance-host.d.mts +2 -2
  29. package/dist/performance-host.mjs +258 -1
  30. package/dist/pi-tui-remote-contribution-DRk6Tl3J.mjs +78 -0
  31. package/dist/pi-tui-terminal-progress-contract-CdBH9j78.mjs +70 -0
  32. package/dist/pi-tui-terminal-progress-contract-XTQKj-WW.mjs +905 -0
  33. package/dist/{runtime-vc4mdr-R.mjs → runtime-Bh5OsftD.mjs} +655 -675
  34. package/dist/runtime-C5ROZqFj.mjs +2 -0
  35. package/dist/{session-tdJHLnJR.mjs → session-4keoXjk0.mjs} +2341 -217
  36. package/dist/session-B2zqv4wr.mjs +10869 -0
  37. package/dist/{startup-JaVZoTIl.mjs → startup-Ct2UUjUL.mjs} +7 -6
  38. package/dist/startup.d.mts +1 -1
  39. package/dist/startup.mjs +1 -1
  40. package/dist/{client-bootstrap-F5DHFI9t.mjs → terminal-progress-source-BhufrZ74.mjs} +3431 -3007
  41. package/dist/terminal-progress-source-CsBinCJ_.mjs +965 -0
  42. package/package.json +125 -116
  43. package/dist/host-bootstrap-DAgKknbY.mjs +0 -119
  44. package/dist/performance-host-CcDJjjVA.mjs +0 -266
  45. package/dist/rolldown-runtime-8H4AJuhK.mjs +0 -14
  46. package/dist/terminal-progress-source-xor3vakJ.mjs +0 -2256
@@ -1,3 +1,5 @@
1
+ import { bt as parseFooterLayout, ht as visibleWidth, xt as resolveCommandFooterFallback, yt as isFooterLayout } from "./extensions-pcFiH7Qe.mjs";
2
+ import { a as customItemId, d as parseFooterCustomItems, o as customItemName, u as parseFooterCustomItem } from "./custom-items-CKrOBCox.mjs";
1
3
  import { i as StepUsageAccumulator, s as totalTokens } from "./performance-view-CfGvLZyD.mjs";
2
4
  import { B as humanFacingVisualResult, I as CHART_TOOL_NAME, L as PRESENT_VISUAL_TOOL_NAME, R as SVG_TOOL_NAME, V as isVisualToolName } from "./runtime-status-0lp9CM0V.mjs";
3
5
  import { normalize } from "node:path";
@@ -4920,7 +4922,7 @@ var TranscriptFolder = class TranscriptFolder {
4920
4922
  const blocks = event.data.content;
4921
4923
  const text = textWithAttachmentMarkers(blocks);
4922
4924
  const sourcePresentation = contextPresentation(event.data.source);
4923
- const isWorkingToolJobsNotice = wasClaimedFromNextStep === true && claimedIdentity !== void 0 && claimedIdentity.insertionTurn === this.currentTurn && sourcePresentation.sourceKind === "tool-jobs" && sourcePresentation.form === "notice";
4925
+ const sameTurnNextStepDelivery = wasClaimedFromNextStep === true && claimedIdentity !== void 0 && claimedIdentity.insertionTurn === this.currentTurn && (sourcePresentation.sourceKind === "tool-jobs" && sourcePresentation.form === "notice" || sourcePresentation.sourceKind === "agent-message" && sourcePresentation.form === "relay");
4924
4926
  if (sourcePresentation.sourceKind === "user") {
4925
4927
  if (!userBlocksVisibleNow(blocks)) break;
4926
4928
  const activity = this.activityFor(this.currentTurn);
@@ -4950,7 +4952,7 @@ var TranscriptFolder = class TranscriptFolder {
4950
4952
  ...summary === null ? {} : { summary },
4951
4953
  icon: contextIconSemantic(event.data.source),
4952
4954
  context: true,
4953
- contextPresentation: isWorkingToolJobsNotice ? {
4955
+ contextPresentation: sameTurnNextStepDelivery ? {
4954
4956
  ...sourcePresentation,
4955
4957
  sameTurnNextStep: true
4956
4958
  } : sourcePresentation
@@ -5448,6 +5450,111 @@ function runSyncDisposalStepsWithPrimary(label, primary, steps) {
5448
5450
  throw new AggregateError([primary, ...failures], label);
5449
5451
  }
5450
5452
  //#endregion
5453
+ //#region src/domain/footer/tsp-native-config.ts
5454
+ /**
5455
+ * TSP-7 PR-D: the one-shot read-only TSP native footer config projection.
5456
+ *
5457
+ * A PURE domain decision: given the merged TUI settings document, the config
5458
+ * readiness and the USER-layer custom-item parse result, it answers WHICH
5459
+ * native footer presentation the TSP renderer mounts — and nothing else. It
5460
+ * reads no runtime port, executes nothing, persists nothing and never
5461
+ * rewrites the settings document: the persisted footer mode/layout/items stay
5462
+ * byte-for-byte what they were (the incompatible facts surface as bounded
5463
+ * notices instead of being silently "fixed").
5464
+ *
5465
+ * Unsupported capabilities are EXPLICIT_UNAVAILABLE by design: whole-footer
5466
+ * `command`, custom command items and extension items are never executed in
5467
+ * TSP; the resolver routes them to a native mode plus a notice, never to a
5468
+ * fabricated value. Which layout refs are actually renderable is decided by
5469
+ * the renderer against the REAL registry (no second builtin id list here).
5470
+ * @module @xmoon76/dsh-pi-tui/domain/footer/tsp-native-config
5471
+ */
5472
+ /** The fixed user-facing notice strings (the renderer only orders and enqueues them). */
5473
+ const TSP_FOOTER_NOTICES = {
5474
+ notCurrent: "Footer settings are not current; TSP is showing its default footer.",
5475
+ invalidLayout: "Invalid footer layout; TSP is showing its default footer.",
5476
+ commandFallback: "TSP cannot run command footer; saved native fallback shown.",
5477
+ unavailableItems: "Some footer items are unavailable in TSP; settings were preserved.",
5478
+ unsupportedSeparator: "Custom footer separators are not supported in TSP; settings were preserved.",
5479
+ invalidCustomItems: "Invalid custom footer items were skipped."
5480
+ };
5481
+ /**
5482
+ * Resolve the TSP native footer config. The algorithm is fixed by the PR-D
5483
+ * plan §3.2 — do not "improve" it into a second settings authority:
5484
+ *
5485
+ * 1. `readiness !== 'ready'` fails closed to the fixed default with ONE
5486
+ * not-current notice; the USER-layer items must not be read in that state
5487
+ * (the caller passes an empty parse result — this function never reads a
5488
+ * port itself).
5489
+ * 2. `compact` keeps its fixed single native row (the plan's own preset — the
5490
+ * PiTui compact layout is NOT reused).
5491
+ * 3. `custom` parses `footerLayout`: valid → custom + layout; invalid → the
5492
+ * fixed default + ONE invalid-layout notice (the persisted raw value is
5493
+ * preserved untouched).
5494
+ * 4. `command` never executes: the EXISTING `resolveCommandFooterFallback`
5495
+ * decides the persisted native fallback and ONE command notice is added.
5496
+ * An invalid custom fallback degrades to the default AND keeps the
5497
+ * invalid-layout notice.
5498
+ * 5. `default`/`full`/unknown values keep the fixed default; `footerLayout`
5499
+ * is deliberately not read so a stale layout cannot pollute it.
5500
+ */
5501
+ function resolveTspNativeFooterConfig(input) {
5502
+ const notices = [];
5503
+ const pushNotice = (text) => {
5504
+ if (!notices.includes(text)) notices.push(text);
5505
+ };
5506
+ if (input.readiness !== "ready") {
5507
+ pushNotice(TSP_FOOTER_NOTICES.notCurrent);
5508
+ return {
5509
+ mode: "default",
5510
+ userTextItems: [],
5511
+ userCommandIds: /* @__PURE__ */ new Set(),
5512
+ notices
5513
+ };
5514
+ }
5515
+ const userTextItems = input.userItems.items.filter((item) => item.kind === "text");
5516
+ const userCommandIds = new Set(input.userItems.items.filter((item) => item.kind === "command").map((item) => item.id));
5517
+ if (input.userItems.invalidCount > 0) pushNotice(TSP_FOOTER_NOTICES.invalidCustomItems);
5518
+ let mode = "default";
5519
+ let layout;
5520
+ switch (input.doc.footer) {
5521
+ case "compact":
5522
+ mode = "compact";
5523
+ break;
5524
+ case "custom": {
5525
+ const parsed = parseFooterLayout(input.doc.footerLayout);
5526
+ if (isFooterLayout(parsed)) {
5527
+ mode = "custom";
5528
+ layout = parsed;
5529
+ } else pushNotice(TSP_FOOTER_NOTICES.invalidLayout);
5530
+ break;
5531
+ }
5532
+ case "command": {
5533
+ const fallback = resolveCommandFooterFallback(input.doc);
5534
+ if (fallback.mode === "compact") mode = "compact";
5535
+ else if (fallback.mode === "custom" && fallback.layout !== void 0) {
5536
+ mode = "custom";
5537
+ layout = fallback.layout;
5538
+ } else if (fallback.mode === "custom") pushNotice(TSP_FOOTER_NOTICES.invalidLayout);
5539
+ pushNotice(TSP_FOOTER_NOTICES.commandFallback);
5540
+ break;
5541
+ }
5542
+ }
5543
+ if (layout !== void 0) {
5544
+ for (const row of layout.rows) if (row.separator?.text !== void 0 && row.separator.text !== " ") {
5545
+ pushNotice(TSP_FOOTER_NOTICES.unsupportedSeparator);
5546
+ break;
5547
+ }
5548
+ }
5549
+ return {
5550
+ mode,
5551
+ ...layout === void 0 ? {} : { layout },
5552
+ userTextItems,
5553
+ userCommandIds,
5554
+ notices
5555
+ };
5556
+ }
5557
+ //#endregion
5451
5558
  //#region src/domain/media/format.ts
5452
5559
  /**
5453
5560
  * Human byte-size formatting for media limit messages (1024-based).
@@ -6123,6 +6230,348 @@ function formatHintKeys(keys) {
6123
6230
  return part.replace(core, lowered);
6124
6231
  }).join("/");
6125
6232
  }
6233
+ //#endregion
6234
+ //#region src/tui/footer/custom-item-catalog.ts
6235
+ /** Compile one validated custom definition into the ordinary footer item
6236
+ * contract. */
6237
+ function compileCustomTextItem(settings) {
6238
+ const tone = settings.tone === void 0 || settings.tone === "auto" ? void 0 : settings.tone;
6239
+ return {
6240
+ id: settings.id,
6241
+ label: customItemName(settings.id),
6242
+ description: "A user-defined text value.",
6243
+ defaultZone: "left",
6244
+ defaultImportance: 50,
6245
+ formats: ["plain"],
6246
+ defaultFormat: "plain",
6247
+ render: () => ({ spans: [{
6248
+ text: settings.text,
6249
+ ...tone === void 0 ? {} : { tone }
6250
+ }] })
6251
+ };
6252
+ }
6253
+ /** Compile one validated command definition. The render reads ONLY the
6254
+ * value source: no cache → null (item unavailable); a preview placeholder
6255
+ * → the dim `[command]` marker (the configurator's draft source); a cached
6256
+ * value → one span in the definition tone. */
6257
+ function compileCustomCommandItem(settings, source) {
6258
+ const tone = settings.tone === void 0 || settings.tone === "auto" ? void 0 : settings.tone;
6259
+ return {
6260
+ id: settings.id,
6261
+ label: customItemName(settings.id),
6262
+ description: "A user-defined command output.",
6263
+ defaultZone: "left",
6264
+ defaultImportance: 50,
6265
+ formats: ["plain"],
6266
+ defaultFormat: "plain",
6267
+ render: () => {
6268
+ const value = source?.value(settings.id);
6269
+ if (value === void 0) return null;
6270
+ if (value.kind === "placeholder") return { spans: [{
6271
+ text: "[command]",
6272
+ tone: "textDim"
6273
+ }] };
6274
+ if (value.text === "") return null;
6275
+ return { spans: [{
6276
+ text: value.text,
6277
+ ...tone === void 0 ? {} : { tone }
6278
+ }] };
6279
+ }
6280
+ };
6281
+ }
6282
+ /** The mutable, local catalog used by the app and by an unsaved configurator
6283
+ * draft. Its source is attached to FooterItemRegistry, so the composer never
6284
+ * needs a custom-item branch. */
6285
+ var FooterCustomItemCatalog = class {
6286
+ items = [];
6287
+ definitions = /* @__PURE__ */ new Map();
6288
+ commandValueSource;
6289
+ constructor(initial = void 0) {
6290
+ this.replace(initial);
6291
+ }
6292
+ /** Attach the synchronous command cache read (the app's live cache, or a
6293
+ * draft source that gates on definition equality). Without a source,
6294
+ * command items render unavailable (null) — fail-soft. */
6295
+ setCommandValueSource(source) {
6296
+ this.commandValueSource = source;
6297
+ for (const item of this.items) if (item.kind === "command") this.definitions.set(item.id, compileCustomCommandItem(item, source));
6298
+ }
6299
+ /** Replace the catalog from persisted/raw data and return the number of
6300
+ * skipped invalid or duplicate entries. */
6301
+ replace(input) {
6302
+ const parsed = parseFooterCustomItems(input);
6303
+ this.items = parsed.items.map((item) => ({ ...item }));
6304
+ this.definitions = new Map(this.items.map((item) => [item.id, this.compile(item)]));
6305
+ return parsed.invalidCount;
6306
+ }
6307
+ /** Return a detached copy suitable for a settings document or a draft. */
6308
+ snapshot() {
6309
+ return this.items.map((item) => ({ ...item }));
6310
+ }
6311
+ ids() {
6312
+ return this.items.map((item) => item.id);
6313
+ }
6314
+ definition(id) {
6315
+ return this.definitions.get(id);
6316
+ }
6317
+ /** Return one detached persisted definition for editor inspection. */
6318
+ get(id) {
6319
+ const item = this.items.find((candidate) => candidate.id === id);
6320
+ return item === void 0 ? void 0 : { ...item };
6321
+ }
6322
+ has(id) {
6323
+ return this.definitions.has(id);
6324
+ }
6325
+ /** Create one definition from the three fields in the editor. */
6326
+ create(name, text, tone) {
6327
+ const id = customItemId(name);
6328
+ if (id === void 0) return { error: "Name must be non-empty, visible, and contain no colon." };
6329
+ if (this.has(id)) return { error: `A footer item named "${customItemName(id)}" already exists.` };
6330
+ const parsed = parseFooterCustomItem({
6331
+ schemaVersion: 1,
6332
+ id,
6333
+ kind: "text",
6334
+ text,
6335
+ tone
6336
+ });
6337
+ if (parsed === void 0) return { error: "Text must be non-empty, visible, and at most 256 characters." };
6338
+ this.items.push(parsed);
6339
+ this.definitions.set(parsed.id, this.compile(parsed));
6340
+ return { item: { ...parsed } };
6341
+ }
6342
+ /** Create one command definition (PR D): the command string plus the
6343
+ * explicit refresh/timeout the user picked (the dirty comparator and the
6344
+ * runtime use the EFFECTIVE values, so an explicit default never reads as
6345
+ * a change). */
6346
+ createCommand(name, command, refreshIntervalMs, timeoutMs, tone) {
6347
+ const id = customItemId(name);
6348
+ if (id === void 0) return { error: "Name must be non-empty, visible, and contain no colon." };
6349
+ if (this.has(id)) return { error: `A footer item named "${customItemName(id)}" already exists.` };
6350
+ const parsed = parseFooterCustomItem({
6351
+ schemaVersion: 1,
6352
+ id,
6353
+ kind: "command",
6354
+ command,
6355
+ refreshIntervalMs,
6356
+ timeoutMs,
6357
+ tone
6358
+ });
6359
+ if (parsed === void 0) return { error: "Command must be non-empty and contain no control characters." };
6360
+ this.items.push(parsed);
6361
+ this.definitions.set(parsed.id, this.compile(parsed));
6362
+ return { item: { ...parsed } };
6363
+ }
6364
+ updateText(id, text) {
6365
+ const current = this.items.find((item) => item.id === id);
6366
+ if (current === void 0) return {
6367
+ ok: false,
6368
+ error: "Footer item no longer exists."
6369
+ };
6370
+ if (current.kind !== "text") return {
6371
+ ok: false,
6372
+ error: "Footer item is not a text item."
6373
+ };
6374
+ const parsed = parseFooterCustomItem({
6375
+ ...current,
6376
+ text
6377
+ });
6378
+ if (parsed === void 0) return {
6379
+ ok: false,
6380
+ error: "Text must be non-empty, visible, and at most 256 characters."
6381
+ };
6382
+ this.replaceItem(parsed);
6383
+ return { ok: true };
6384
+ }
6385
+ /** Replace a command definition's command string (PR D). */
6386
+ updateCommand(id, command) {
6387
+ const current = this.items.find((item) => item.id === id);
6388
+ if (current === void 0) return {
6389
+ ok: false,
6390
+ error: "Footer item no longer exists."
6391
+ };
6392
+ if (current.kind !== "command") return {
6393
+ ok: false,
6394
+ error: "Footer item is not a command."
6395
+ };
6396
+ const parsed = parseFooterCustomItem({
6397
+ ...current,
6398
+ command
6399
+ });
6400
+ if (parsed === void 0) return {
6401
+ ok: false,
6402
+ error: "Command must be non-empty and contain no control characters."
6403
+ };
6404
+ this.replaceItem(parsed);
6405
+ return { ok: true };
6406
+ }
6407
+ /** Replace a command definition's refresh interval (PR D). */
6408
+ updateRefresh(id, refreshIntervalMs) {
6409
+ const current = this.items.find((item) => item.id === id);
6410
+ if (current === void 0) return {
6411
+ ok: false,
6412
+ error: "Footer item no longer exists."
6413
+ };
6414
+ if (current.kind !== "command") return {
6415
+ ok: false,
6416
+ error: "Footer item is not a command."
6417
+ };
6418
+ const parsed = parseFooterCustomItem({
6419
+ ...current,
6420
+ refreshIntervalMs
6421
+ });
6422
+ if (parsed === void 0) return {
6423
+ ok: false,
6424
+ error: "Refresh must be a finite number of milliseconds."
6425
+ };
6426
+ this.replaceItem(parsed);
6427
+ return { ok: true };
6428
+ }
6429
+ /** Replace a command definition's timeout (PR D). */
6430
+ updateTimeout(id, timeoutMs) {
6431
+ const current = this.items.find((item) => item.id === id);
6432
+ if (current === void 0) return {
6433
+ ok: false,
6434
+ error: "Footer item no longer exists."
6435
+ };
6436
+ if (current.kind !== "command") return {
6437
+ ok: false,
6438
+ error: "Footer item is not a command."
6439
+ };
6440
+ const parsed = parseFooterCustomItem({
6441
+ ...current,
6442
+ timeoutMs
6443
+ });
6444
+ if (parsed === void 0) return {
6445
+ ok: false,
6446
+ error: "Timeout must be a finite number of milliseconds."
6447
+ };
6448
+ this.replaceItem(parsed);
6449
+ return { ok: true };
6450
+ }
6451
+ updateTone(id, tone) {
6452
+ const current = this.items.find((item) => item.id === id);
6453
+ if (current === void 0) return {
6454
+ ok: false,
6455
+ error: "Footer item no longer exists."
6456
+ };
6457
+ const parsed = parseFooterCustomItem({
6458
+ ...current,
6459
+ tone
6460
+ });
6461
+ if (parsed === void 0) return {
6462
+ ok: false,
6463
+ error: "The selected tone is invalid."
6464
+ };
6465
+ this.replaceItem(parsed);
6466
+ return { ok: true };
6467
+ }
6468
+ rename(id, name) {
6469
+ const current = this.items.find((item) => item.id === id);
6470
+ if (current === void 0) return { error: "Footer item no longer exists." };
6471
+ const nextId = customItemId(name);
6472
+ if (nextId === void 0) return { error: "Name must be non-empty, visible, and contain no colon." };
6473
+ if (nextId !== id && this.has(nextId)) return { error: `A footer item named "${customItemName(nextId)}" already exists.` };
6474
+ if (nextId === id) return { newId: id };
6475
+ const parsed = parseFooterCustomItem({
6476
+ ...current,
6477
+ id: nextId
6478
+ });
6479
+ if (parsed === void 0) return { error: "The new name is invalid." };
6480
+ const index = this.items.findIndex((item) => item.id === id);
6481
+ this.items[index] = parsed;
6482
+ this.definitions.delete(id);
6483
+ this.definitions.set(nextId, this.compile(parsed));
6484
+ return { newId: nextId };
6485
+ }
6486
+ remove(id) {
6487
+ const index = this.items.findIndex((item) => item.id === id);
6488
+ if (index < 0) return false;
6489
+ this.items.splice(index, 1);
6490
+ this.definitions.delete(id);
6491
+ return true;
6492
+ }
6493
+ compile(item) {
6494
+ return item.kind === "text" ? compileCustomTextItem(item) : compileCustomCommandItem(item, this.commandValueSource);
6495
+ }
6496
+ replaceItem(item) {
6497
+ const index = this.items.findIndex((candidate) => candidate.id === item.id);
6498
+ if (index < 0) return;
6499
+ this.items[index] = item;
6500
+ this.definitions.set(item.id, this.compile(item));
6501
+ }
6502
+ };
6503
+ //#endregion
6504
+ //#region src/tui/footer/item-registry.ts
6505
+ const USER_ITEM_PREFIX = "user:";
6506
+ /** The builtin item registry. */
6507
+ var FooterItemRegistry = class {
6508
+ items = /* @__PURE__ */ new Map();
6509
+ external;
6510
+ custom;
6511
+ base;
6512
+ /** Create a registry optionally layered over another registry. A layered
6513
+ * registry is used by the unsaved footer editor: it sees the live builtin /
6514
+ * extension catalog while keeping its custom-definition draft isolated from
6515
+ * the active footer. */
6516
+ constructor(base) {
6517
+ this.base = base;
6518
+ }
6519
+ /** Register one builtin item; a duplicate id is an explicit error. */
6520
+ register(definition) {
6521
+ if (definition.id.startsWith(USER_ITEM_PREFIX)) throw new Error(`footer item id "${definition.id}" is reserved for custom items`);
6522
+ if (this.items.has(definition.id)) throw new Error(`duplicate footer item id "${definition.id}"`);
6523
+ this.items.set(definition.id, definition);
6524
+ }
6525
+ /** M4: attach the live external source (extension footer items). The
6526
+ * source's ids join the catalog; its definitions resolve on demand. */
6527
+ setExternalSource(source) {
6528
+ this.external = source;
6529
+ }
6530
+ /** Attach user-owned definitions as a separate live source. This keeps
6531
+ * custom definitions in the ordinary registry/composer path without
6532
+ * exposing their settings model to extension consumers. */
6533
+ setCustomSource(source) {
6534
+ this.custom = source;
6535
+ }
6536
+ /** Look up one item by id; undefined for unknown ids. Local draft sources
6537
+ * take precedence over the base registry so an editor can safely preview a
6538
+ * renamed or edited custom definition. */
6539
+ get(id) {
6540
+ const local = this.items.get(id);
6541
+ if (local !== void 0) return local;
6542
+ if (id.startsWith(USER_ITEM_PREFIX) && this.hasNonCustomDefinition(id)) return this.nonCustomDefinition(id);
6543
+ if (this.custom !== void 0 && id.startsWith(USER_ITEM_PREFIX)) return this.custom.definition(id);
6544
+ return this.custom?.definition(id) ?? this.external?.definition(id) ?? this.base?.get(id);
6545
+ }
6546
+ /** Every registered id (builtin + live external + custom), in stable
6547
+ * catalog order. Layered registries de-duplicate ids exposed by the base. */
6548
+ ids() {
6549
+ const baseIds = this.base?.ids() ?? [];
6550
+ const visibleBaseIds = this.custom === void 0 ? baseIds : baseIds.filter((id) => !id.startsWith(USER_ITEM_PREFIX) || this.hasNonCustomDefinition(id));
6551
+ const customIds = (this.custom?.ids() ?? []).filter((id) => !this.hasNonCustomDefinition(id));
6552
+ const ids = [
6553
+ ...this.items.keys(),
6554
+ ...this.external?.ids() ?? [],
6555
+ ...customIds,
6556
+ ...visibleBaseIds
6557
+ ];
6558
+ return [...new Set(ids)];
6559
+ }
6560
+ /** Resolve only builtin/extension layers, skipping every custom source. */
6561
+ nonCustomDefinition(id) {
6562
+ const local = this.items.get(id);
6563
+ if (local !== void 0) return local;
6564
+ return this.external?.definition(id) ?? this.base?.nonCustomDefinition(id);
6565
+ }
6566
+ /** Whether a non-custom layer claims this id. IDs are used rather than
6567
+ * calling definition() so a live source that is temporarily unavailable
6568
+ * still cannot be shadowed by a custom source. */
6569
+ hasNonCustomDefinition(id) {
6570
+ if (this.items.has(id)) return true;
6571
+ if (this.external?.ids().includes(id) === true) return true;
6572
+ return this.base?.hasNonCustomDefinition(id) ?? false;
6573
+ }
6574
+ };
6126
6575
  /** Canonicalize one user query for both metadata matching and Host search. */
6127
6576
  function sanitizeSessionSearchInput(value) {
6128
6577
  const trimmed = value.replace(/\0/g, "").trim();
@@ -6292,6 +6741,22 @@ function findSessionMatch(rows, query) {
6292
6741
  return rows.find((row) => row.id === query || row.id.startsWith(`session-${bare}`) || shortSessionId(row.id).startsWith(bare));
6293
6742
  }
6294
6743
  //#endregion
6744
+ //#region src/tui/graphics/image-protocol-preference.ts
6745
+ /** Parse the one startup image-protocol override; throw on an unknown value. */
6746
+ function imageProtocolPreference(environment = process.env) {
6747
+ const raw = environment.PI_IMAGE_PROTOCOL;
6748
+ switch ((raw ?? "").trim().toLowerCase()) {
6749
+ case "":
6750
+ case "auto": return "auto";
6751
+ case "kitty": return "kitty";
6752
+ case "sixel": return "sixel";
6753
+ case "iterm2": return "iterm2";
6754
+ case "none":
6755
+ case "0": return "none";
6756
+ default: throw new Error(`Invalid PI_IMAGE_PROTOCOL: ${JSON.stringify(raw)}; expected auto, kitty, sixel, iterm2, none, 0`);
6757
+ }
6758
+ }
6759
+ //#endregion
6295
6760
  //#region src/domain/media/file-summary.ts
6296
6761
  /**
6297
6762
  * Transport/UI-neutral textual summary of a durable file attachment (TS8-D
@@ -7696,6 +8161,981 @@ function subagentModelDisplay(name, argsRaw) {
7696
8161
  return parts.length === 0 ? void 0 : parts.join(" · ");
7697
8162
  }
7698
8163
  //#endregion
8164
+ //#region src/tui/token-format.ts
8165
+ /**
8166
+ * Compact terminal token-count FORMATTING (TS8-D): the pi.s footer
8167
+ * abbreviation vocabulary shared by the footer stats line, the Focus per-turn
8168
+ * token segment and the About token rows. This is presentation-only — the
8169
+ * token semantic/accounting authority is
8170
+ * `src/domain/transcript/usage.ts`.
8171
+ * @module @xmoon76/dsh-pi-tui/tui/token-format
8172
+ */
8173
+ /** Format a token count with pi.s footer rules: 1.5k, 190k, 1.0M, 86M. */
8174
+ function formatTokens(count) {
8175
+ if (count < 1e3) return String(count);
8176
+ if (count < 1e4) return `${(count / 1e3).toFixed(1)}k`;
8177
+ if (count < 1e6) return `${Math.round(count / 1e3)}k`;
8178
+ if (count < 1e7) return `${(count / 1e6).toFixed(1)}M`;
8179
+ return `${Math.round(count / 1e6)}M`;
8180
+ }
8181
+ //#endregion
8182
+ //#region src/tui/footer/formatters.ts
8183
+ /**
8184
+ * Footer formatters (plan §4.9/§7): the DISPLAY words for the structured
8185
+ * status facts. The StatusSnapshot never carries preformatted strings —
8186
+ * every presentation lives here, so a custom layout can pick a finite
8187
+ * formatter per item.
8188
+ * @module @xmoon76/dsh-pi-tui/tui/footer/formatters
8189
+ */
8190
+ /** Whether cwd uses Windows path syntax rather than a POSIX filename with
8191
+ * a literal backslash. Drive paths and UNC paths are unambiguous; every other
8192
+ * path keeps POSIX's slash-only separator semantics. */
8193
+ function isWindowsStyleCwd(cwd) {
8194
+ return /^[A-Za-z]:[\\/]/u.test(cwd) || /^\\\\/u.test(cwd);
8195
+ }
8196
+ /** Split cwd using only the separators valid for its detected path syntax. */
8197
+ function cwdParts(cwd) {
8198
+ const separator = isWindowsStyleCwd(cwd) ? /[\\/]+/u : "/";
8199
+ return cwd.split(separator).filter(Boolean);
8200
+ }
8201
+ /** Whether a path is a filesystem root whose separator must be retained. */
8202
+ function isRootCwd(cwd) {
8203
+ if (/^\/+$/u.test(cwd) || /^[A-Za-z]:[\\/]+$/u.test(cwd)) return true;
8204
+ return /^\\\\/u.test(cwd) && cwdParts(cwd).length === 2;
8205
+ }
8206
+ /** Short cwd for the footer: last two path segments (idempotent). */
8207
+ function shortCwd(cwd) {
8208
+ if (isRootCwd(cwd)) return cwd;
8209
+ return cwdParts(cwd).slice(-2).join("/") || cwd;
8210
+ }
8211
+ /** One decimal place, dropping a redundant ".0". */
8212
+ function trimDecimal(value) {
8213
+ const text = value.toFixed(1);
8214
+ return text.endsWith(".0") ? text.slice(0, -2) : text;
8215
+ }
8216
+ /** Format milliseconds as seconds with one decimal ("8.1s"). */
8217
+ function formatSeconds(ms) {
8218
+ return `${trimDecimal(ms / 1e3)}s`;
8219
+ }
8220
+ /** Format a model according to the builtin style vocabulary. */
8221
+ function formatModel(provider, id, reasoningEffort, format) {
8222
+ const label = `${provider === void 0 ? "" : `${provider}/`}${id}` + (reasoningEffort === void 0 ? "" : ` @${reasoningEffort}`);
8223
+ switch (format) {
8224
+ case "plain": return label;
8225
+ case "compact": return id;
8226
+ default: return `[${label}]`;
8227
+ }
8228
+ }
8229
+ const PERMISSION_LABELS = {
8230
+ "danger-full-access": "yolo",
8231
+ "read-only": "read-only",
8232
+ "workspace-write": "workspace-write",
8233
+ auto: "auto",
8234
+ custom: "custom"
8235
+ };
8236
+ /** Format the known permission preset ids. Unknown ids are unavailable to
8237
+ * the builtin item, preserving the legacy fail-soft behavior. */
8238
+ function formatPermissionPreset(id, format) {
8239
+ const label = PERMISSION_LABELS[id];
8240
+ if (label === void 0) return void 0;
8241
+ switch (format) {
8242
+ case "plain": return label;
8243
+ case "compact": return id === "read-only" ? "ro" : id === "workspace-write" ? "ww" : label;
8244
+ default: return `[${label}]`;
8245
+ }
8246
+ }
8247
+ /** Format the plan state as a badge or a plain status label. */
8248
+ function formatPlanState(effective, pending, format) {
8249
+ const state = pending !== void 0 ? "plan pending" : effective ? "plan" : void 0;
8250
+ if (state === void 0) return void 0;
8251
+ return format === "plain" ? state : `[${state}]`;
8252
+ }
8253
+ /** Format a working directory using the finite builtin style vocabulary. */
8254
+ function formatWorkingDirectory(cwd, format) {
8255
+ switch (format) {
8256
+ case "basename":
8257
+ if (isRootCwd(cwd)) return cwd;
8258
+ return cwdParts(cwd).at(-1) ?? cwd;
8259
+ case "full": return cwd;
8260
+ default: return shortCwd(cwd);
8261
+ }
8262
+ }
8263
+ /** Format a branch name either plainly or with a visible label. */
8264
+ function formatGitBranch(branch, format) {
8265
+ return format === "label" ? `branch: ${branch}` : branch;
8266
+ }
8267
+ /** Context pressure, full form: `160.0K/1.0M (16%)`. */
8268
+ function formatContextFull(used, window, percent) {
8269
+ return `${formatTokens(used)}/${formatTokens(window)} (${percent}%)`;
8270
+ }
8271
+ /** Context pressure, percent form: `ctx 31%`. */
8272
+ function formatContextPercent(percent) {
8273
+ return `ctx ${percent}%`;
8274
+ }
8275
+ /** Cache-hit share, pi vocabulary: `CH93.9%`. */
8276
+ function formatCacheHitPi(pct) {
8277
+ return `CH${pct.toFixed(1)}%`;
8278
+ }
8279
+ /** Cache-hit share: `C 91.9%`. */
8280
+ function formatCacheHit(pct) {
8281
+ return `C ${pct.toFixed(1)}%`;
8282
+ }
8283
+ /** Cache-hit share without the item marker: `91.9%`. */
8284
+ function formatCacheHitCompact(pct) {
8285
+ return `${pct.toFixed(1)}%`;
8286
+ }
8287
+ /** Token usage, io form: `2579/5507` (input/output). */
8288
+ function formatTokenUsageIo(input, output) {
8289
+ return `${input}/${output}`;
8290
+ }
8291
+ /** Token usage, pi vocabulary: `↑34k ↓8.1k R520k W12k` — the session
8292
+ * cumulative usage; the cache-read/write terms hide while zero. */
8293
+ function formatTokenUsagePi(input, output, cacheRead, cacheWrite) {
8294
+ return [
8295
+ `↑${formatTokens(input)}`,
8296
+ `↓${formatTokens(output)}`,
8297
+ cacheRead > 0 ? `R${formatTokens(cacheRead)}` : "",
8298
+ cacheWrite > 0 ? `W${formatTokens(cacheWrite)}` : ""
8299
+ ].filter((part) => part !== "").join(" ");
8300
+ }
8301
+ /** Token usage, pi vocabulary under width pressure: `↑34k ↓8.1k` — the
8302
+ * cumulative input/output pair survives, the cache detail drops. */
8303
+ function formatTokenUsagePiCompact(input, output) {
8304
+ return `↑${formatTokens(input)} ↓${formatTokens(output)}`;
8305
+ }
8306
+ /** Token usage, total form: `8.1k tokens` (all billed token classes). */
8307
+ function formatTokenUsageTotal(input, output, cacheRead, cacheWrite) {
8308
+ return `${formatTokens(input + output + cacheRead + cacheWrite)} tokens`;
8309
+ }
8310
+ /** Token usage, compact total form: `8.1k` (all billed token classes). */
8311
+ function formatTokenUsageCompact(input, output, cacheRead, cacheWrite) {
8312
+ return formatTokens(input + output + cacheRead + cacheWrite);
8313
+ }
8314
+ /** Performance, full form (legacy composite): `TTFB 2.6s · R5 116 tok/s` —
8315
+ * the average time-to-first-token beside the RECENT (R5) model-request
8316
+ * output rate. The lifetime `LLM` wall is not a footer fact (it still
8317
+ * accumulates in SessionStats.llmMs for /status and session analysis), and
8318
+ * this form deliberately stays TTFB+R5: the whole-Session ("All") rate is
8319
+ * its own format (`speed-all`) and the default pair (`speed-both`). */
8320
+ function formatPerformanceFull(firstTokenMs, tokensPerSec) {
8321
+ return `${formatPerformanceLatency(firstTokenMs)} · ${formatPerformanceR5(tokensPerSec)}`;
8322
+ }
8323
+ /** Performance, full compact pressure form: `2.6s R5 116t/s` — the full
8324
+ * form's facts with the shortened unit. */
8325
+ function formatPerformanceCompact(firstTokenMs, tokensPerSec) {
8326
+ return `${formatPerformanceLatencyCompact(firstTokenMs)} ${formatPerformanceR5Compact(tokensPerSec)}`;
8327
+ }
8328
+ /** Performance, R5 (the last five eligible steps of the current route
8329
+ * generation): `R5 116 tok/s`. The value already carries the domain's ONE
8330
+ * display precision policy (`derivePerformance` → `displayRate`), so this
8331
+ * formatter never re-rounds. */
8332
+ function formatPerformanceR5(tokensPerSec) {
8333
+ return `R5 ${tokensPerSec} tok/s`;
8334
+ }
8335
+ /** Performance, R5 compact form: `R5 116t/s`. */
8336
+ function formatPerformanceR5Compact(tokensPerSec) {
8337
+ return `R5 ${tokensPerSec}t/s`;
8338
+ }
8339
+ /** Performance, All (every eligible step of the Session): `All 44 tok/s`. */
8340
+ function formatPerformanceAll(tokensPerSec) {
8341
+ return `All ${tokensPerSec} tok/s`;
8342
+ }
8343
+ /** Performance, All compact form: `All 44t/s`. */
8344
+ function formatPerformanceAllCompact(tokensPerSec) {
8345
+ return `All ${tokensPerSec}t/s`;
8346
+ }
8347
+ /** Performance, the DEFAULT combined speed form: `R5 116 · All 44 tok/s` —
8348
+ * ONE unit for the pair, never an orphan separator or a doubled `tok/s`. */
8349
+ function formatPerformanceBoth(r5PerSec, allPerSec) {
8350
+ return `R5 ${r5PerSec} · All ${allPerSec} tok/s`;
8351
+ }
8352
+ /** Performance, latency-only form: `TTFB 2.6s` — the recent average
8353
+ * time-to-first-token. */
8354
+ function formatPerformanceLatency(firstTokenMs) {
8355
+ return `TTFB ${formatSeconds(firstTokenMs)}`;
8356
+ }
8357
+ /** Performance, latency-only compact form: `2.6s`. */
8358
+ function formatPerformanceLatencyCompact(firstTokenMs) {
8359
+ return formatSeconds(firstTokenMs);
8360
+ }
8361
+ /** Turn/step counters: `t3/s7`, `t3`, or `s7`. */
8362
+ function formatTurnsSteps(turns, steps, format = "both") {
8363
+ switch (format) {
8364
+ case "turns": return `t${turns}`;
8365
+ case "steps": return `s${steps}`;
8366
+ default: return `t${turns}/s${steps}`;
8367
+ }
8368
+ }
8369
+ /** The pi-vocabulary FOOTER stats line (the legacy line-2 format), derived
8370
+ * from the STRUCTURED usage facts: `↑34k ↓8.1k R520k CH93.9% | TTFB 2.6s ·
8371
+ * 51 tok/s`. The performance tail carries the RECENT metrics only — the
8372
+ * lifetime `LLM` wall left the footer so a composite never mixes lifetime
8373
+ * and recent windows. This is a SEPARATE presentation contract from the
8374
+ * About report rows (`domain/status/about.ts`, which keep the labeled lifetime
8375
+ * `LLM ...` term beside the recent metrics) — footer chrome vs Settings/About
8376
+ * detail surface, never forced into string equality. */
8377
+ function formatStatsLine(usage) {
8378
+ const tokens = usage.tokens;
8379
+ const piParts = tokens === void 0 ? [] : [
8380
+ `↑${formatTokens(tokens.input)}`,
8381
+ `↓${formatTokens(tokens.output)}`,
8382
+ tokens.cacheRead > 0 ? `R${formatTokens(tokens.cacheRead)}` : "",
8383
+ tokens.cacheWrite > 0 ? `W${formatTokens(tokens.cacheWrite)}` : "",
8384
+ tokens.cacheRead > 0 || tokens.cacheWrite > 0 ? `CH${(usage.cacheHitPct ?? 0).toFixed(1)}%` : ""
8385
+ ].filter((part) => part !== "");
8386
+ const performance = [usage.performance.firstTokenMs === void 0 ? "" : `TTFB ${formatSeconds(usage.performance.firstTokenMs)}`, usage.performance.tokensPerSec === void 0 ? "" : `${usage.performance.tokensPerSec} tok/s`].filter((part) => part !== "").join(" · ");
8387
+ if (piParts.length === 0) return performance;
8388
+ return performance === "" ? piParts.join(" ") : `${piParts.join(" ")} | ${performance}`;
8389
+ }
8390
+ /** The pi-vocabulary stats line, compact pressure form:
8391
+ * `↑34k ↓8.1k · TTFB 2.6s · 659t/s` — input/output, ONE (recent) time
8392
+ * indicator and the (recent) throughput survive; the cache (R/W/CH)
8393
+ * facts are omitted under width pressure. The structured UsageStatus is
8394
+ * untouched and the legacy formatStatsLine contract is unchanged. */
8395
+ function formatStatsLineCompact(usage) {
8396
+ const tokens = usage.tokens;
8397
+ const piParts = tokens === void 0 ? [] : [`↑${formatTokens(tokens.input)}`, `↓${formatTokens(tokens.output)}`];
8398
+ const performance = [usage.performance.firstTokenMs === void 0 ? "" : `TTFB ${formatSeconds(usage.performance.firstTokenMs)}`, usage.performance.tokensPerSec === void 0 ? "" : `${usage.performance.tokensPerSec}t/s`].filter((part) => part !== "").join(" · ");
8399
+ if (piParts.length === 0) return performance;
8400
+ return performance === "" ? piParts.join(" · ") : `${piParts.join(" ")} · ${performance}`;
8401
+ }
8402
+ /** The sandbox mode compact codes: `ro`, `ww`, `yolo`. An unknown future
8403
+ * mode keeps its original value (fail-soft — never an invented
8404
+ * abbreviation). */
8405
+ function formatSandboxModeCompact(mode) {
8406
+ switch (mode) {
8407
+ case "read-only": return "ro";
8408
+ case "workspace-write": return "ww";
8409
+ case "danger-full-access": return "yolo";
8410
+ default: return mode;
8411
+ }
8412
+ }
8413
+ /** The run-phase compact codes for the CURRENT RunPhase union (idle is
8414
+ * never rendered by the item). An unknown future phase keeps its original
8415
+ * value (fail-soft — never an invented abbreviation). */
8416
+ function formatRunPhaseCompact(phase) {
8417
+ switch (phase) {
8418
+ case "working": return "work";
8419
+ case "waiting-approval": return "w-approval";
8420
+ case "waiting-question": return "w-question";
8421
+ case "compacting": return "compact";
8422
+ case "applying-compaction": return "apply-compact";
8423
+ default: return phase;
8424
+ }
8425
+ }
8426
+ /** Version formatters: `tui` → `v0.4.0-alpha.1`, `dsh` → `dsh-0.1.2-alpha.2`,
8427
+ * `both` → `dsh-0.1.2-alpha.2/tui-0.4.0-alpha.1`. */
8428
+ function formatVersion(dshVersion, tuiVersion, format) {
8429
+ switch (format) {
8430
+ case "dsh": return dshVersion === void 0 ? "" : `dsh-${dshVersion}`;
8431
+ case "both": return dshVersion === void 0 ? `tui-${tuiVersion}` : `dsh-${dshVersion}/tui-${tuiVersion}`;
8432
+ default: return `v${tuiVersion}`;
8433
+ }
8434
+ }
8435
+ //#endregion
8436
+ //#region src/tui/footer/builtin-items.ts
8437
+ /** The legacy permission badge mapping (M1 parity — the plan's §14.4 tone
8438
+ * refinements apply to M2 custom layouts, never the default preset). */
8439
+ const permissionPresetItem = {
8440
+ id: "permission-preset",
8441
+ label: "Permission preset",
8442
+ description: "The effective permission preset as a badge, plain label, or compact code.",
8443
+ defaultZone: "left",
8444
+ defaultImportance: 110,
8445
+ formats: [
8446
+ "badge",
8447
+ "plain",
8448
+ "compact"
8449
+ ],
8450
+ defaultFormat: "badge",
8451
+ render(snapshot, ref, density) {
8452
+ const preset = snapshot.access.permissionPreset;
8453
+ if (preset === void 0) return null;
8454
+ const format = density === "compact" ? "compact" : ref.format ?? "badge";
8455
+ const text = formatPermissionPreset(preset.id, format);
8456
+ if (text === void 0) return null;
8457
+ return { spans: [{
8458
+ text,
8459
+ tone: preset.id === "danger-full-access" || preset.id === "custom" ? "warning" : preset.id === "read-only" ? "textMuted" : "text"
8460
+ }] };
8461
+ }
8462
+ };
8463
+ /** The plan styles: a badge or a plain status label. Pending enter and
8464
+ * pending exit both keep the pending state visible (plan §4.3). */
8465
+ const planStateItem = {
8466
+ id: "plan-state",
8467
+ label: "Plan state",
8468
+ description: "The plan-mode badge or plain status label.",
8469
+ defaultZone: "left",
8470
+ defaultImportance: 115,
8471
+ formats: ["badge", "plain"],
8472
+ defaultFormat: "badge",
8473
+ render(snapshot, ref, density) {
8474
+ if (snapshot.view.subject.kind !== "main") return null;
8475
+ const format = density === "compact" ? "plain" : ref.format ?? "badge";
8476
+ const text = formatPlanState(snapshot.collaboration.plan.effective, snapshot.collaboration.plan.pending, format);
8477
+ return text === void 0 ? null : { spans: [{
8478
+ text,
8479
+ tone: "warning"
8480
+ }] };
8481
+ }
8482
+ };
8483
+ /** The model styles: badge, provider/model plain text, or model id only. */
8484
+ const modelItem = {
8485
+ id: "model",
8486
+ label: "Model",
8487
+ description: "The provider/model identity as a badge, plain label, or model id.",
8488
+ defaultZone: "left",
8489
+ defaultImportance: 100,
8490
+ formats: [
8491
+ "badge",
8492
+ "plain",
8493
+ "compact"
8494
+ ],
8495
+ defaultFormat: "badge",
8496
+ render(snapshot, ref, density) {
8497
+ const model = snapshot.composition.model;
8498
+ if (model === void 0) return null;
8499
+ const format = density === "compact" ? "compact" : ref.format ?? "badge";
8500
+ return { spans: [{ text: sanitizedPhysicalLine(formatModel(model.provider, model.id, model.reasoningEffort, format)) }] };
8501
+ }
8502
+ };
8503
+ /**
8504
+ * The Task Center badge. Legacy snapshots (which predate totals) retain the
8505
+ * old wording for embedders; the runtime-backed snapshot uses independent
8506
+ * active/tracked job and agent counts and a persistent failure marker.
8507
+ */
8508
+ const tasksItem = {
8509
+ id: "tasks",
8510
+ label: "Tasks",
8511
+ description: "The Task Center active/tracked badge with failure attention, parked human Question attention and the ↓ view hint.",
8512
+ defaultZone: "left",
8513
+ defaultImportance: 85,
8514
+ formats: ["badge"],
8515
+ defaultFormat: "badge",
8516
+ render(snapshot, _ref, density, context) {
8517
+ if (snapshot.view.subject.kind !== "main") return null;
8518
+ const tasks = snapshot.activity.taskCount;
8519
+ const agents = snapshot.activity.childAgentCount;
8520
+ const failed = snapshot.activity.failedTaskCount ?? 0;
8521
+ const human = snapshot.activity.questionAttentionCount ?? 0;
8522
+ if (!(snapshot.activity.taskTotalCount !== void 0 || snapshot.activity.childAgentTotalCount !== void 0 || snapshot.activity.failedTaskCount !== void 0 || human > 0)) {
8523
+ if (tasks <= 0 && agents <= 0) return null;
8524
+ const hint = context.taskBrowserAvailable ? " · ↓ view" : "";
8525
+ if (density === "compact") {
8526
+ const parts = [];
8527
+ if (tasks > 0) parts.push(`${tasks}t`);
8528
+ if (agents > 0) parts.push(`${agents}a`);
8529
+ if (context.taskBrowserAvailable) parts.push("↓");
8530
+ return { spans: [{
8531
+ text: `[${parts.join("·")}]`,
8532
+ tone: "primary"
8533
+ }] };
8534
+ }
8535
+ const parts = [];
8536
+ if (tasks > 0) parts.push(`${tasks} task${tasks === 1 ? "" : "s"} running`);
8537
+ if (agents > 0) parts.push(`${agents} agent${agents === 1 ? "" : "s"}`);
8538
+ return { spans: [{
8539
+ text: `[${parts.join(" · ")}${hint}]`,
8540
+ tone: "primary"
8541
+ }] };
8542
+ }
8543
+ const totalJobs = snapshot.activity.taskTotalCount ?? tasks;
8544
+ const totalAgents = snapshot.activity.childAgentTotalCount ?? agents;
8545
+ if (tasks <= 0 && agents <= 0 && failed <= 0 && human <= 0) return null;
8546
+ const hint = context.taskBrowserAvailable ? " · ↓ view" : "";
8547
+ const tone = failed > 0 ? "warning" : "primary";
8548
+ if (density === "compact") {
8549
+ const parts = [];
8550
+ if (failed > 0) parts.push(`!${failed}`);
8551
+ if (tasks > 0 && agents > 0) {
8552
+ parts.push(`●${agents}/${totalAgents}a`);
8553
+ parts.push(`${tasks}/${totalJobs}j`);
8554
+ } else if (agents > 0) parts.push(`●${agents}/${totalAgents}a`);
8555
+ else if (tasks > 0) parts.push(`${tasks}/${totalJobs}j`);
8556
+ if (human > 0) parts.push(`?${human}`);
8557
+ if (context.taskBrowserAvailable) parts.push("↓");
8558
+ return { spans: [{
8559
+ text: `[${parts.join("·")}]`,
8560
+ tone
8561
+ }] };
8562
+ }
8563
+ const parts = [];
8564
+ if (failed > 0) parts.push(`! ${failed} failed`);
8565
+ if (tasks > 0 && agents > 0) {
8566
+ parts.push(`● ${agents}/${totalAgents} agents`);
8567
+ parts.push(`${tasks}/${totalJobs} tracked jobs`);
8568
+ } else if (agents > 0) parts.push(`● ${agents}/${totalAgents} agents`);
8569
+ else if (tasks > 0) parts.push(`● ${tasks}/${totalJobs} tracked jobs`);
8570
+ if (human > 0) parts.push(`? ${human} awaiting`);
8571
+ return { spans: [{
8572
+ text: `[${parts.join(" · ")}${hint}]`,
8573
+ tone
8574
+ }] };
8575
+ }
8576
+ };
8577
+ /** The working directory (short, basename, or full path). */
8578
+ const cwdItem = {
8579
+ id: "cwd",
8580
+ label: "Working directory",
8581
+ description: "The display subject's workspace in short, basename, or full form.",
8582
+ defaultZone: "left",
8583
+ defaultImportance: 80,
8584
+ formats: [
8585
+ "short",
8586
+ "basename",
8587
+ "full"
8588
+ ],
8589
+ defaultFormat: "short",
8590
+ render(snapshot, ref, density) {
8591
+ const cwd = snapshot.workspace.cwd;
8592
+ if (cwd === "") {
8593
+ if (snapshot.workspace.cwdUnavailable === true) return { spans: [{
8594
+ text: "Unavailable",
8595
+ emphasis: "dim"
8596
+ }] };
8597
+ return null;
8598
+ }
8599
+ return { spans: [{ text: sanitizedPhysicalLine(formatWorkingDirectory(cwd, density === "compact" ? "basename" : ref.format ?? "short")) }] };
8600
+ }
8601
+ };
8602
+ /** The git branch, either plainly or with a visible label. */
8603
+ const gitBranchItem = {
8604
+ id: "git-branch",
8605
+ label: "Git branch",
8606
+ description: "The display subject's git branch, plainly or with a label.",
8607
+ defaultZone: "left",
8608
+ defaultImportance: 70,
8609
+ formats: ["plain", "label"],
8610
+ defaultFormat: "plain",
8611
+ render(snapshot, ref, density) {
8612
+ const branch = snapshot.workspace.branch;
8613
+ if (branch === void 0 || branch === "") return null;
8614
+ return { spans: [{ text: sanitizedPhysicalLine(formatGitBranch(branch, density === "compact" ? "plain" : ref.format ?? "plain")) }] };
8615
+ }
8616
+ };
8617
+ /** The context pressure styles: legacy bar, percent, or full
8618
+ * used/window output. */
8619
+ const contextItem = {
8620
+ id: "context",
8621
+ label: "Context",
8622
+ description: "Context pressure: a progress bar, percent, or used/window value.",
8623
+ defaultZone: "left",
8624
+ defaultImportance: 100,
8625
+ formats: [
8626
+ "bar",
8627
+ "percent",
8628
+ "full"
8629
+ ],
8630
+ defaultFormat: "bar",
8631
+ render(snapshot, ref, density) {
8632
+ const context = snapshot.usage.context;
8633
+ if (context === void 0 || context.windowTokens === void 0 || context.windowTokens <= 0) return null;
8634
+ const used = context.usedTokens ?? 0;
8635
+ const window = context.windowTokens;
8636
+ const percent = context.percent ?? Math.min(100, Math.max(0, Math.ceil(used * 100 / window)));
8637
+ if (density === "compact") return { spans: [{
8638
+ text: formatContextPercent(percent),
8639
+ tone: "primary"
8640
+ }] };
8641
+ const format = ref.format ?? "bar";
8642
+ if (format === "full") return { spans: [{
8643
+ text: formatContextFull(used, window, percent),
8644
+ tone: "primary"
8645
+ }] };
8646
+ if (format === "percent") return { spans: [{
8647
+ text: formatContextPercent(percent),
8648
+ tone: "primary"
8649
+ }] };
8650
+ const ratio = Math.min(1, Math.max(0, used / window));
8651
+ const filled = Math.round(ratio * CONTEXT_BAR_WIDTH);
8652
+ const barPercent = Math.min(100, Math.max(0, Math.ceil(ratio * 100)));
8653
+ return { spans: [{
8654
+ text: `[${"█".repeat(filled) + "░".repeat(CONTEXT_BAR_WIDTH - filled)}]`,
8655
+ tone: "primary"
8656
+ }, { text: ` ${barPercent}%` }] };
8657
+ }
8658
+ };
8659
+ /** The legacy bar width (moved from tui-app.ts). */
8660
+ const CONTEXT_BAR_WIDTH = 12;
8661
+ /** The turn/step counters: both counters, turns only, or steps only
8662
+ * (host-native since M1 — the first-party builtin extension segment was
8663
+ * removed; the host core state no longer depends on plugin loading). */
8664
+ const turnsStepsItem = {
8665
+ id: "turns-steps",
8666
+ label: "Turns/steps",
8667
+ description: "The completed turn/step counters, together or separately.",
8668
+ defaultZone: "left",
8669
+ defaultImportance: 45,
8670
+ formats: [
8671
+ "both",
8672
+ "turns",
8673
+ "steps"
8674
+ ],
8675
+ defaultFormat: "both",
8676
+ render(snapshot, ref) {
8677
+ return { spans: [{ text: formatTurnsSteps(snapshot.usage.turns, snapshot.usage.steps, ref.format ?? "both") }] };
8678
+ }
8679
+ };
8680
+ /** The pi-vocabulary stats line (the legacy line-2), derived from the
8681
+ * STRUCTURED usage facts. Kept registered for existing custom layouts;
8682
+ * the default preset composes its stats row from real semantic items. */
8683
+ const statsLineItem = {
8684
+ id: "stats-line",
8685
+ label: "Stats line",
8686
+ description: "The pi-vocabulary usage line (tokens, cache, recent TTFB, throughput).",
8687
+ defaultZone: "left",
8688
+ defaultImportance: 10,
8689
+ formats: ["pi"],
8690
+ defaultFormat: "pi",
8691
+ render(snapshot, _ref, density) {
8692
+ return { spans: [{ text: density === "compact" ? formatStatsLineCompact(snapshot.usage) : formatStatsLine(snapshot.usage) }] };
8693
+ }
8694
+ };
8695
+ /** The RETIRED viewer identity block (legacy form): the child
8696
+ * label/activity identity now lives in the header-adjacent viewer subject
8697
+ * bar, so this item renders nothing. It stays REGISTERED and parseable
8698
+ * (existing user custom layouts that reference `view-scope` load, edit and
8699
+ * save unchanged — the placement is inert), but it is no longer offered by
8700
+ * the configurator's Add picker. */
8701
+ const viewScopeItem = {
8702
+ id: "view-scope",
8703
+ label: "View scope",
8704
+ description: "Retired: the viewer identity now renders in the subject bar.",
8705
+ defaultZone: "left",
8706
+ defaultImportance: 115,
8707
+ formats: ["legacy"],
8708
+ defaultFormat: "legacy",
8709
+ render() {
8710
+ return null;
8711
+ }
8712
+ };
8713
+ /** The legacy extension-segment bridge: `ext:*` renders the extension
8714
+ * host's baked footer segments (the chrome.footer.status slot). */
8715
+ const extensionItemsItem = {
8716
+ id: "ext:*",
8717
+ label: "Extension items",
8718
+ description: "The legacy chrome.footer.status extension segments (synthetic bridge).",
8719
+ defaultZone: "left",
8720
+ defaultImportance: 0,
8721
+ formats: ["bridge"],
8722
+ defaultFormat: "bridge",
8723
+ render(snapshot, _ref, _density, context) {
8724
+ if (snapshot.view.subject.kind !== "main") return null;
8725
+ if (context.extensionFooterText === "") return null;
8726
+ return { spans: [{ text: context.extensionFooterText }] };
8727
+ }
8728
+ };
8729
+ /** Register every M1 builtin item on a registry. */
8730
+ function registerBuiltinFooterItems(registry) {
8731
+ registry.register(permissionPresetItem);
8732
+ registry.register(planStateItem);
8733
+ registry.register(modelItem);
8734
+ registry.register(tasksItem);
8735
+ registry.register(cwdItem);
8736
+ registry.register(gitBranchItem);
8737
+ registry.register(contextItem);
8738
+ registry.register(turnsStepsItem);
8739
+ registry.register(statsLineItem);
8740
+ registry.register(viewScopeItem);
8741
+ registry.register(extensionItemsItem);
8742
+ registry.register(agentPresetItem);
8743
+ registry.register(reasoningItem);
8744
+ registry.register(sandboxModeItem);
8745
+ registry.register(approvalPolicyItem);
8746
+ registry.register(focusModeItem);
8747
+ registry.register(displayPresetItem);
8748
+ registry.register(focusedSeatItem);
8749
+ registry.register(projectItem);
8750
+ registry.register(runStateItem);
8751
+ registry.register(queueItem);
8752
+ registry.register(agentsItem);
8753
+ registry.register(todoItem);
8754
+ registry.register(cacheHitItem);
8755
+ registry.register(tokenUsageItem);
8756
+ registry.register(performanceItem);
8757
+ registry.register(versionItem);
8758
+ }
8759
+ /** The agent-preset badge: `[CM]`-style from the composition preset
8760
+ * (shortLabel when provided — the state layer never hardcodes it). */
8761
+ const agentPresetItem = {
8762
+ id: "agent-preset",
8763
+ label: "Agent preset",
8764
+ description: "The agent composition preset badge or compact short label.",
8765
+ defaultZone: "left",
8766
+ defaultImportance: 90,
8767
+ formats: ["badge", "compact"],
8768
+ defaultFormat: "badge",
8769
+ render(snapshot, ref, density) {
8770
+ const preset = snapshot.composition.agentPreset;
8771
+ if (preset === void 0) return null;
8772
+ return { spans: [{
8773
+ text: `[${sanitizedPhysicalLine((density === "compact" || ref.format === "compact") && preset.shortLabel !== void 0 ? preset.shortLabel : preset.label)}]`,
8774
+ tone: "accent"
8775
+ }] };
8776
+ }
8777
+ };
8778
+ /** The reasoning effort: `@high` (the model item already folds it in). */
8779
+ const reasoningItem = {
8780
+ id: "reasoning",
8781
+ label: "Reasoning effort",
8782
+ description: "The model reasoning effort.",
8783
+ defaultZone: "left",
8784
+ defaultImportance: 50,
8785
+ formats: ["plain"],
8786
+ defaultFormat: "plain",
8787
+ render(snapshot) {
8788
+ if (snapshot.view.subject.kind !== "main") return null;
8789
+ const effort = snapshot.composition.model?.reasoningEffort;
8790
+ if (effort === void 0) return null;
8791
+ return { spans: [{
8792
+ text: `@${sanitizedPhysicalLine(effort)}`,
8793
+ tone: "textMuted"
8794
+ }] };
8795
+ }
8796
+ };
8797
+ /** The sandbox mode (independent of the preset name). */
8798
+ const sandboxModeItem = {
8799
+ id: "sandbox-mode",
8800
+ label: "Sandbox mode",
8801
+ description: "The effective sandbox mode.",
8802
+ defaultZone: "left",
8803
+ defaultImportance: 80,
8804
+ formats: ["plain"],
8805
+ defaultFormat: "plain",
8806
+ render(snapshot, _ref, density) {
8807
+ if (snapshot.view.subject.kind !== "main") return null;
8808
+ const mode = snapshot.access.sandbox?.mode;
8809
+ if (mode === void 0) return null;
8810
+ const tone = mode === "danger-full-access" ? "warning" : mode === "read-only" ? "textMuted" : "text";
8811
+ return { spans: [{
8812
+ text: density === "compact" ? formatSandboxModeCompact(mode) : mode,
8813
+ tone
8814
+ }] };
8815
+ }
8816
+ };
8817
+ /** The approval policy. */
8818
+ const approvalPolicyItem = {
8819
+ id: "approval-policy",
8820
+ label: "Approval policy",
8821
+ description: "The effective approval policy.",
8822
+ defaultZone: "left",
8823
+ defaultImportance: 70,
8824
+ formats: ["plain"],
8825
+ defaultFormat: "plain",
8826
+ render(snapshot) {
8827
+ if (snapshot.view.subject.kind !== "main") return null;
8828
+ const policy = snapshot.access.approval?.policy;
8829
+ if (policy === void 0) return null;
8830
+ return { spans: [{
8831
+ text: policy,
8832
+ tone: policy === "never" ? "warning" : "text"
8833
+ }] };
8834
+ }
8835
+ };
8836
+ /** Focus Mode (the TUI's own presentation policy — never the keyboard
8837
+ * focus). */
8838
+ const focusModeItem = {
8839
+ id: "focus-mode",
8840
+ label: "Focus mode",
8841
+ description: "Legacy Focus Mode indicator.",
8842
+ defaultZone: "right",
8843
+ defaultImportance: 120,
8844
+ formats: ["plain"],
8845
+ defaultFormat: "plain",
8846
+ render(snapshot) {
8847
+ if (snapshot.interaction.displayPreset !== "focus") return null;
8848
+ return { spans: [{
8849
+ text: "focus",
8850
+ tone: "textMuted"
8851
+ }] };
8852
+ }
8853
+ };
8854
+ /** The canonical display preset indicator for new Footer layouts. */
8855
+ const displayPresetItem = {
8856
+ id: "display-preset",
8857
+ label: "Display",
8858
+ description: "The active transcript display preset.",
8859
+ defaultZone: "right",
8860
+ defaultImportance: 120,
8861
+ formats: ["plain"],
8862
+ defaultFormat: "plain",
8863
+ render(snapshot) {
8864
+ return { spans: [{
8865
+ text: snapshot.interaction.displayPreset,
8866
+ tone: "textMuted"
8867
+ }] };
8868
+ }
8869
+ };
8870
+ /** The UI keyboard focus seat (distinct from Focus Mode). */
8871
+ const focusedSeatItem = {
8872
+ id: "focused-seat",
8873
+ label: "Focused seat",
8874
+ description: "The UI keyboard focus seat.",
8875
+ defaultZone: "right",
8876
+ defaultImportance: 30,
8877
+ formats: ["plain"],
8878
+ defaultFormat: "plain",
8879
+ render(snapshot) {
8880
+ return { spans: [{
8881
+ text: snapshot.surface.focusedSeat,
8882
+ tone: "textMuted"
8883
+ }] };
8884
+ }
8885
+ };
8886
+ /** The project directory name (distinct from the cwd item). */
8887
+ const projectItem = {
8888
+ id: "project",
8889
+ label: "Project",
8890
+ description: "The workspace project directory name.",
8891
+ defaultZone: "left",
8892
+ defaultImportance: 80,
8893
+ formats: ["plain"],
8894
+ defaultFormat: "plain",
8895
+ render(snapshot) {
8896
+ const project = snapshot.workspace.project;
8897
+ if (project === void 0 || project === "") return null;
8898
+ return { spans: [{
8899
+ text: sanitizedPhysicalLine(project),
8900
+ tone: "primary"
8901
+ }] };
8902
+ }
8903
+ };
8904
+ /** The run phase (the pure derive's output — never re-derived here). */
8905
+ const runStateItem = {
8906
+ id: "run-state",
8907
+ label: "Run state",
8908
+ description: "The machine run phase.",
8909
+ defaultZone: "right",
8910
+ defaultImportance: 95,
8911
+ formats: ["plain"],
8912
+ defaultFormat: "plain",
8913
+ render(snapshot, _ref, density) {
8914
+ if (snapshot.view.subject.kind !== "main") return null;
8915
+ const phase = snapshot.activity.phase;
8916
+ if (phase === "idle") return null;
8917
+ const tone = phase === "working" ? "primary" : "warning";
8918
+ return { spans: [{
8919
+ text: density === "compact" ? formatRunPhaseCompact(phase) : phase,
8920
+ tone
8921
+ }] };
8922
+ }
8923
+ };
8924
+ /** The queued-input count. */
8925
+ const queueItem = {
8926
+ id: "queue",
8927
+ label: "Queue",
8928
+ description: "The queued-input count.",
8929
+ defaultZone: "left",
8930
+ defaultImportance: 85,
8931
+ formats: ["plain"],
8932
+ defaultFormat: "plain",
8933
+ render(snapshot, _ref, density) {
8934
+ if (snapshot.view.subject.kind !== "main") return null;
8935
+ const count = snapshot.activity.queuedCount;
8936
+ if (count <= 0) return null;
8937
+ return { spans: [{
8938
+ text: density === "compact" ? `q${count}` : `${count} queued`,
8939
+ tone: "textDim"
8940
+ }] };
8941
+ }
8942
+ };
8943
+ /** The live child-subagent count. */
8944
+ const agentsItem = {
8945
+ id: "agents",
8946
+ label: "Agents",
8947
+ description: "The live child-subagent count.",
8948
+ defaultZone: "left",
8949
+ defaultImportance: 85,
8950
+ formats: ["plain"],
8951
+ defaultFormat: "plain",
8952
+ render(snapshot, _ref, density) {
8953
+ if (snapshot.view.subject.kind !== "main") return null;
8954
+ const count = snapshot.activity.childAgentCount;
8955
+ if (count <= 0) return null;
8956
+ return { spans: [{
8957
+ text: density === "compact" ? `a${count}` : `${count} agents`,
8958
+ tone: "textDim"
8959
+ }] };
8960
+ }
8961
+ };
8962
+ /** The todo count. */
8963
+ const todoItem = {
8964
+ id: "todo",
8965
+ label: "Todo",
8966
+ description: "The active todo count.",
8967
+ defaultZone: "left",
8968
+ defaultImportance: 60,
8969
+ formats: ["plain"],
8970
+ defaultFormat: "plain",
8971
+ render(snapshot, _ref, density) {
8972
+ const count = snapshot.activity.todoCount;
8973
+ if (count <= 0) return null;
8974
+ return { spans: [{
8975
+ text: density === "compact" ? `td${count}` : `${count} todo`,
8976
+ tone: "textDim"
8977
+ }] };
8978
+ }
8979
+ };
8980
+ /** The cache-hit share: pi `CH91.9%`, full `C 91.9%`, or compact `91.9%`.
8981
+ * Absent cache facts (no billed input yet) render nothing — the composer
8982
+ * eliminates the leftover separator. */
8983
+ const cacheHitItem = {
8984
+ id: "cache-hit",
8985
+ label: "Cache hit",
8986
+ description: "The cache-hit share of billed input tokens, pi, full, or compact.",
8987
+ defaultZone: "left",
8988
+ defaultImportance: 55,
8989
+ formats: [
8990
+ "pi",
8991
+ "full",
8992
+ "compact"
8993
+ ],
8994
+ defaultFormat: "full",
8995
+ render(snapshot, ref, density) {
8996
+ const pct = snapshot.usage.cacheHitPct;
8997
+ if (pct === void 0) return null;
8998
+ if (ref.format === "pi") return { spans: [{
8999
+ text: density === "compact" ? formatCacheHitCompact(pct) : formatCacheHitPi(pct),
9000
+ tone: "success"
9001
+ }] };
9002
+ return { spans: [{
9003
+ text: density === "compact" || ref.format === "compact" ? formatCacheHitCompact(pct) : formatCacheHit(pct),
9004
+ tone: "success"
9005
+ }] };
9006
+ }
9007
+ };
9008
+ /** The token usage: pi vocabulary, input/output, all billed tokens, or
9009
+ * compact total. */
9010
+ const tokenUsageItem = {
9011
+ id: "token-usage",
9012
+ label: "Token usage",
9013
+ description: "The pi input/output vocabulary, the io totals, billed total, or compact total.",
9014
+ defaultZone: "left",
9015
+ defaultImportance: 50,
9016
+ formats: [
9017
+ "pi",
9018
+ "io",
9019
+ "total",
9020
+ "compact"
9021
+ ],
9022
+ defaultFormat: "io",
9023
+ render(snapshot, ref, density) {
9024
+ const tokens = snapshot.usage.tokens;
9025
+ if (tokens === void 0) return null;
9026
+ if (ref.format === "pi") return { spans: [{
9027
+ text: density === "compact" ? formatTokenUsagePiCompact(tokens.input, tokens.output) : formatTokenUsagePi(tokens.input, tokens.output, tokens.cacheRead, tokens.cacheWrite),
9028
+ tone: "success"
9029
+ }] };
9030
+ const preferred = ref.format === "total" ? formatTokenUsageTotal(tokens.input, tokens.output, tokens.cacheRead, tokens.cacheWrite) : ref.format === "compact" ? formatTokenUsageCompact(tokens.input, tokens.output, tokens.cacheRead, tokens.cacheWrite) : formatTokenUsageIo(tokens.input, tokens.output);
9031
+ if (density !== "compact") return { spans: [{
9032
+ text: preferred,
9033
+ tone: "success"
9034
+ }] };
9035
+ const compact = formatTokenUsageCompact(tokens.input, tokens.output, tokens.cacheRead, tokens.cacheWrite);
9036
+ return { spans: [{
9037
+ text: visibleWidth(compact) < visibleWidth(preferred) ? compact : preferred,
9038
+ tone: "success"
9039
+ }] };
9040
+ }
9041
+ };
9042
+ /** The model performance facts (TPS plan PR-3): full
9043
+ * `TTFB 2.6s · R5 116 tok/s` (the legacy composite stays TTFB + the RECENT
9044
+ * rate), R5-only `R5 116 tok/s`, All-only `All 44 tok/s`, the DEFAULT
9045
+ * combined `R5 116 · All 44 tok/s`, or latency-only `TTFB 2.6s`. The
9046
+ * definition may be PLACED TWICE (latency + speed) — the default preset does
9047
+ * exactly that, with `speed-both`. Every format reads the structured
9048
+ * `usage.performance` facts only: the Client never folds Host events. */
9049
+ const performanceItem = {
9050
+ id: "performance",
9051
+ label: "Performance",
9052
+ description: "Model performance: average TTFB and the model-request throughput — recent (R5), whole Session (All), both, or latency only.",
9053
+ defaultZone: "left",
9054
+ defaultImportance: 40,
9055
+ formats: [
9056
+ "full",
9057
+ "speed",
9058
+ "speed-all",
9059
+ "speed-both",
9060
+ "latency"
9061
+ ],
9062
+ defaultFormat: "full",
9063
+ render(snapshot, ref, density) {
9064
+ const performance = snapshot.usage.performance;
9065
+ const compact = density === "compact";
9066
+ const segment = (text) => ({ spans: [{
9067
+ text,
9068
+ tone: "textMuted"
9069
+ }] });
9070
+ switch (ref.format) {
9071
+ case "latency": {
9072
+ const latency = performance.firstTokenMs;
9073
+ if (latency === void 0) return null;
9074
+ return segment(compact ? formatPerformanceLatencyCompact(latency) : formatPerformanceLatency(latency));
9075
+ }
9076
+ case "speed": {
9077
+ const r5 = performance.tokensPerSec;
9078
+ if (r5 === void 0) return null;
9079
+ return segment(compact ? formatPerformanceR5Compact(r5) : formatPerformanceR5(r5));
9080
+ }
9081
+ case "speed-all": {
9082
+ const all = performance.sessionTokensPerSec;
9083
+ if (all === void 0) return null;
9084
+ return segment(compact ? formatPerformanceAllCompact(all) : formatPerformanceAll(all));
9085
+ }
9086
+ case "speed-both": {
9087
+ const r5 = performance.tokensPerSec;
9088
+ const all = performance.sessionTokensPerSec;
9089
+ if (compact) {
9090
+ if (r5 !== void 0) return segment(formatPerformanceR5Compact(r5));
9091
+ if (all !== void 0) return segment(formatPerformanceAllCompact(all));
9092
+ return null;
9093
+ }
9094
+ if (r5 !== void 0 && all !== void 0) return segment(formatPerformanceBoth(r5, all));
9095
+ if (r5 !== void 0) return segment(formatPerformanceR5(r5));
9096
+ if (all !== void 0) return segment(formatPerformanceAll(all));
9097
+ return null;
9098
+ }
9099
+ default: {
9100
+ const latency = performance.firstTokenMs;
9101
+ const r5 = performance.tokensPerSec;
9102
+ if (latency !== void 0 && r5 !== void 0) return segment(compact ? formatPerformanceCompact(latency, r5) : formatPerformanceFull(latency, r5));
9103
+ if (latency !== void 0) return segment(compact ? formatPerformanceLatencyCompact(latency) : formatPerformanceLatency(latency));
9104
+ if (r5 !== void 0) return segment(compact ? formatPerformanceR5Compact(r5) : formatPerformanceR5(r5));
9105
+ return null;
9106
+ }
9107
+ }
9108
+ }
9109
+ };
9110
+ /** The host version: `v0.4.0-alpha.1` (tui), `dsh-0.1.2-alpha.2` (dsh), or both. */
9111
+ const versionItem = {
9112
+ id: "version",
9113
+ label: "Version",
9114
+ description: "The dsh/bundle versions.",
9115
+ defaultZone: "left",
9116
+ defaultImportance: 10,
9117
+ formats: [
9118
+ "tui",
9119
+ "dsh",
9120
+ "both"
9121
+ ],
9122
+ defaultFormat: "tui",
9123
+ render(snapshot, ref) {
9124
+ const text = sanitizedPhysicalLine(formatVersion(snapshot.host.dshVersion, snapshot.host.tuiVersion, ref.format ?? "tui"));
9125
+ if (text === "") return null;
9126
+ return { spans: [{
9127
+ text,
9128
+ tone: "textMuted"
9129
+ }] };
9130
+ }
9131
+ };
9132
+ /** A fresh registry with every builtin item registered. */
9133
+ function createBuiltinFooterRegistry() {
9134
+ const registry = new FooterItemRegistry();
9135
+ registerBuiltinFooterItems(registry);
9136
+ return registry;
9137
+ }
9138
+ //#endregion
7699
9139
  //#region src/domain/visual/presentation.ts
7700
9140
  const presentations = /* @__PURE__ */ new WeakMap();
7701
9141
  function sameKey(left, right) {
@@ -8223,11 +9663,12 @@ function clusterAdjacentAmbientContext(messages) {
8223
9663
  *
8224
9664
  * A Work span may CARRY a foldable Context row as a structural part without
8225
9665
  * making it Process: the row keeps its Context semantics, its source bytes and
8226
- * its own disclosure, but no longer splits one turn's Activity/Thought. Two
9666
+ * its own disclosure, but no longer splits one turn's Activity/Thought. Three
8227
9667
  * narrow forms qualify: a `form:'snapshot'` singleton / snapshot-only raw
8228
- * cluster, and a `tool-jobs` Notice with durable same-turn `next-step`
8229
- * delivery evidence. A mixed `instructions`/`catalog`/`snapshot` cluster and
8230
- * every other Notice form stay independent Context boundaries.
9668
+ * cluster, a `tool-jobs` Notice with durable same-turn `next-step` delivery
9669
+ * evidence, and an `agent-message` relay with the same durable same-turn
9670
+ * next-step evidence. A mixed `instructions`/`catalog`/`snapshot` cluster and
9671
+ * every other Notice/relay form stay independent Context boundaries.
8231
9672
  *
8232
9673
  * The projector is a single forward pass plus the linear ambient-clustering
8233
9674
  * pass (O(n)); wrappers are freshly allocated each call, but their
@@ -8310,13 +9751,30 @@ function isWorkingToolJobsNotice(message) {
8310
9751
  return presentation !== void 0 && presentation.sameTurnNextStep === true && presentation.form === "notice" && presentation.sourceKind === "tool-jobs";
8311
9752
  }
8312
9753
  /**
9754
+ * Whether one row is a same-turn delivered Agent relay (`agent-message` +
9755
+ * `relay`) with durable next-step delivery evidence.
9756
+ *
9757
+ * This is the narrow sibling of {@link isWorkingToolJobsNotice}: the
9758
+ * producer-declared `sourceKind === 'agent-message'` AND `form === 'relay'`
9759
+ * are both required, plus the fold's presentation-only `sameTurnNextStep`
9760
+ * flag derived from the durable `agent/inbox/spliced` insert/claim identity
9761
+ * chain. A `next-turn` wakeup, a foreign/legacy log, a crossed source/form
9762
+ * pair or a missing claim carries no flag and therefore stays an independent
9763
+ * Context boundary.
9764
+ */
9765
+ function isWorkingAgentRelay(message) {
9766
+ if (!isSurfacedContext(message)) return false;
9767
+ const presentation = message.contextPresentation;
9768
+ return presentation !== void 0 && presentation.sameTurnNextStep === true && presentation.sourceKind === "agent-message" && presentation.form === "relay";
9769
+ }
9770
+ /**
8313
9771
  * The complete narrow display-layer eligibility: may this Context row be
8314
9772
  * carried by the same-turn Work/Thought instead of ending it? Only a foldable
8315
- * Snapshot or a proven Working `tool-jobs` Notice qualifies; every other
8316
- * surfaced Context remains a boundary.
9773
+ * Snapshot, a proven Working `tool-jobs` Notice or a proven same-turn Agent
9774
+ * relay qualifies; every other surfaced Context remains a boundary.
8317
9775
  */
8318
9776
  function isFoldableWorkContext(message, clusterByMember) {
8319
- return isFoldableSnapshotContext(message, clusterByMember) || isWorkingToolJobsNotice(message);
9777
+ return isFoldableSnapshotContext(message, clusterByMember) || isWorkingToolJobsNotice(message) || isWorkingAgentRelay(message);
8320
9778
  }
8321
9779
  /**
8322
9780
  * Segment one raw transcript window into canonical structural blocks.
@@ -8554,4 +10012,4 @@ function contextClusterSummaryParts(cluster) {
8554
10012
  return parts;
8555
10013
  }
8556
10014
  //#endregion
8557
- export { sessionPickerItem as $, contextFormOf as $t, parseCallPreview as A, sanitizeDisplaySegment as At, systemContextBody as B, assistantPresentationRevision as Bt, foldedCallPreview as C, effortChoicesOf as Ct, goalResultSummary as D, sanitizedPhysicalLine as Dt, goalResultLines as E, projectModelDirectory as Et, readFoldedPreview as F, TranscriptFolder as Ft, toolTitle as G, transcriptTimingOf as Gt, toolIconSemantic as H, childOwnEvents as Ht, relativizeToCwd as I, activeSubCallsOf as It, fileAttachmentSummary as J, transcriptSearchSourceKey as Jt, webCardLines as K, TranscriptWindowController as Kt, resultTextLines as L, assistantBlocksVisibleNow as Lt, parseReadEnvelopes as M, formatBytes as Mt, parseSkillEnvelope as N, runSyncDisposalSteps as Nt, imageFoldedPreview as O, singlePhysicalLine as Ot, parseWriteEnvelope as P, runSyncDisposalStepsWithPrimary as Pt, sessionLabelParts as Q, recentTurnThreshold as Qt, skillFoldedPreview as R, assistantCommittedBeforeSteer as Rt, focusToolDisplay as S, PROVIDER_DEFAULT as St, genericRawInputLines as T, modelIdentity as Tt, toolPresenterFrom as U, subCallDisplayStatus as Ut, toolCardHeader as V, assistantStepOf as Vt, toolSummaryKeys as W, textOf as Wt, formatSessionAge as X, workflowPhaseKey as Xt, findSessionMatch as Y, WorkflowProjection as Yt, sanitizeTerminalText as Z, workflowReadablePhase as Zt, askAnswersLines as _, formatKeyId as _t, projectTranscriptStructure as a, displayFailureText as an, sanitizeSessionSearchInput as at, compactToolPresentation as b, isBuiltInPresetRow as bt, contextPresentationKind as c, textWithAttachmentMarkers as cn, HISTORY_CHORDS as ct, assistantVisualPresentation as d, SVG_VIEWER_SCROLL_LABEL as dt, isPostTurnReplayEvidence as en, sessionSearchItem as et, assistantVisualPresentationRevision as f, TSP_CONTINUED_INSPECTION_LABEL as ft, GOAL_TOOL_NAMES as g, formatHintKeys as gt, FOLDED_JSON_RESULT_TOOLS as h, TSP_VISUAL_SELECT_LABEL as ht, isTranscriptWorkMember as i, latestLine as in, sameWorkspace as it, parseImageEnvelope as j, sanitizeDisplayText as jt, isCompactActionTool as k, sanitizeDisplayLog as kt, isNoticeContext as l, userBlocksVisibleNow as ln, JOB_LOCAL_KEYS as lt, setAssistantVisualPresentation as m, TSP_VISUAL_COPY_LABEL as mt, clusterByMemberOf as n, isSurfacedInteractionTool as nn, workspaceKey as nt, workByMemberOf as o, finalizedBlockFallbackText as on, sessionRowMatchesQuery as ot, clearAssistantVisualPresentation as p, TSP_VISUAL_CHORDS as pt, writeFoldedPreview as q, transcriptSearchMatchKey as qt, isFoldableWorkContext as r, isSurfacedInteractionToolName as rn, buildSessionTree as rt, clusterAdjacentAmbientContext as s, openOpaqueBlockFallbackText as sn, DELIVERED_FILES_CHORDS as st, contextClusterSummaryParts as t, isSurfacedContext as tn, shortSessionId as tt, planVisualPlacement as u, SVG_VIEWER_CHORDS as ut, askAnswersSummary as v, formatLeaderSequence as vt, foldedResultSummaryFor as w, initialEffortOf as wt, firstLine as x, presetDisplayText as xt, compactToolExpandedLines as y, matchesKeyId as yt, subagentModelDisplay as z, assistantLatestStepOf as zt };
10015
+ export { imageProtocolPreference as $, textOf as $t, goalResultLines as A, effortChoicesOf as At, relativizeToCwd as B, TSP_FOOTER_NOTICES as Bt, compactToolExpandedLines as C, formatHintKeys as Ct, foldedCallPreview as D, isBuiltInPresetRow as Dt, focusToolDisplay as E, matchesKeyId as Et, parseImageEnvelope as F, singlePhysicalLine as Ft, toolCardHeader as G, activeSubCallsOf as Gt, skillFoldedPreview as H, runSyncDisposalSteps as Ht, parseReadEnvelopes as I, sanitizeDisplayLog as It, toolSummaryKeys as J, assistantLatestStepOf as Jt, toolIconSemantic as K, assistantBlocksVisibleNow as Kt, parseSkillEnvelope as L, sanitizeDisplaySegment as Lt, imageFoldedPreview as M, modelIdentity as Mt, isCompactActionTool as N, projectModelDirectory as Nt, foldedResultSummaryFor as O, presetDisplayText as Ot, parseCallPreview as P, sanitizedPhysicalLine as Pt, fileAttachmentSummary as Q, subCallDisplayStatus as Qt, parseWriteEnvelope as R, sanitizeDisplayText as Rt, askAnswersSummary as S, TSP_VISUAL_SELECT_LABEL as St, firstLine as T, formatLeaderSequence as Tt, subagentModelDisplay as U, runSyncDisposalStepsWithPrimary as Ut, resultTextLines as V, resolveTspNativeFooterConfig as Vt, systemContextBody as W, TranscriptFolder as Wt, webCardLines as X, assistantStepOf as Xt, toolTitle as Y, assistantPresentationRevision as Yt, writeFoldedPreview as Z, childOwnEvents as Zt, shortCwd as _, textWithAttachmentMarkers as _n, SVG_VIEWER_CHORDS as _t, isWorkingAgentRelay as a, workflowPhaseKey as an, sessionSearchItem as at, GOAL_TOOL_NAMES as b, TSP_VISUAL_CHORDS as bt, clusterAdjacentAmbientContext as c, contextFormOf as cn, buildSessionTree as ct, planVisualPlacement as d, isSurfacedInteractionTool as dn, sessionRowMatchesQuery as dt, transcriptTimingOf as en, findSessionMatch as et, assistantVisualPresentation as f, isSurfacedInteractionToolName as fn, FooterItemRegistry as ft, createBuiltinFooterRegistry as g, openOpaqueBlockFallbackText as gn, JOB_LOCAL_KEYS as gt, setAssistantVisualPresentation as h, finalizedBlockFallbackText as hn, HISTORY_CHORDS as ht, isTranscriptWorkMember as i, WorkflowProjection as in, sessionPickerItem as it, goalResultSummary as j, initialEffortOf as jt, genericRawInputLines as k, PROVIDER_DEFAULT as kt, contextPresentationKind as l, isPostTurnReplayEvidence as ln, sameWorkspace as lt, clearAssistantVisualPresentation as m, displayFailureText as mn, DELIVERED_FILES_CHORDS as mt, clusterByMemberOf as n, transcriptSearchMatchKey as nn, sanitizeTerminalText as nt, projectTranscriptStructure as o, workflowReadablePhase as on, shortSessionId as ot, assistantVisualPresentationRevision as p, latestLine as pn, FooterCustomItemCatalog as pt, toolPresenterFrom as q, assistantCommittedBeforeSteer as qt, isFoldableWorkContext as r, transcriptSearchSourceKey as rn, sessionLabelParts as rt, workByMemberOf as s, recentTurnThreshold as sn, workspaceKey as st, contextClusterSummaryParts as t, TranscriptWindowController as tn, formatSessionAge as tt, isNoticeContext as u, isSurfacedContext as un, sanitizeSessionSearchInput as ut, formatTokens as v, userBlocksVisibleNow as vn, SVG_VIEWER_SCROLL_LABEL as vt, compactToolPresentation as w, formatKeyId as wt, askAnswersLines as x, TSP_VISUAL_COPY_LABEL as xt, FOLDED_JSON_RESULT_TOOLS as y, TSP_CONTINUED_INSPECTION_LABEL as yt, readFoldedPreview as z, formatBytes as zt };