@hassangameryt/freeflow 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +2 -1
  3. package/.codex-plugin/plugin.json +2 -1
  4. package/README.md +150 -155
  5. package/capabilities/cognitive-routing/SKILL.md +229 -0
  6. package/capabilities/context-virtualization/SKILL.md +103 -0
  7. package/capabilities/conversation-history/SKILL.md +53 -0
  8. package/command-surface.json +17 -13
  9. package/hooks/freeflow-runtime-context.mjs +393 -159
  10. package/hooks/hooks.json +26 -1
  11. package/hooks/tests/check-runtime-context-hook.sh +223 -54
  12. package/package.json +25 -16
  13. package/pi-extension/dist/cognitive-routing/commands.js +96 -0
  14. package/pi-extension/dist/cognitive-routing/config.js +236 -0
  15. package/pi-extension/dist/cognitive-routing/controller.js +862 -0
  16. package/pi-extension/dist/cognitive-routing/history.js +439 -0
  17. package/pi-extension/dist/cognitive-routing/host.js +126 -0
  18. package/pi-extension/dist/cognitive-routing/runtime.js +43 -0
  19. package/pi-extension/dist/cognitive-routing/tool.js +211 -0
  20. package/pi-extension/dist/cognitive-routing/types.js +6 -0
  21. package/pi-extension/dist/context-virtualization/commands.js +89 -0
  22. package/pi-extension/dist/context-virtualization/projector.js +42 -0
  23. package/pi-extension/dist/context-virtualization/runtime.js +356 -0
  24. package/pi-extension/dist/context-virtualization/state.js +57 -0
  25. package/pi-extension/dist/context-virtualization/types.js +10 -0
  26. package/pi-extension/dist/conversation-history/passages.js +66 -0
  27. package/pi-extension/dist/conversation-history/ranking.js +105 -0
  28. package/pi-extension/dist/conversation-history/runtime.js +226 -0
  29. package/pi-extension/dist/conversation-history/search.js +56 -0
  30. package/pi-extension/dist/conversation-history/types.js +1 -0
  31. package/pi-extension/dist/freeflow-context/resolver.js +120 -0
  32. package/pi-extension/dist/freeflow-context/runtime.js +80 -0
  33. package/pi-extension/dist/freeflow-context/source-projector.js +95 -0
  34. package/pi-extension/dist/freeflow-context/tool.js +308 -0
  35. package/pi-extension/dist/freeflow-context/types.js +12 -0
  36. package/pi-extension/dist/freeflow-context/visibility.js +28 -0
  37. package/pi-extension/dist/index.js +516 -98
  38. package/pi-extension/dist/runtime/runtime-context.js +318 -271
  39. package/pi-extension/dist/runtime/runtime-identity.js +5 -0
  40. package/pi-extension/dist/settings/settings-tui.js +78 -0
  41. package/pi-extension/dist/settings/settings-ui.js +593 -563
  42. package/pi-extension/dist/ui/text-component.js +57 -0
  43. package/pi-extension/src/cognitive-routing/commands.ts +119 -0
  44. package/pi-extension/src/cognitive-routing/config.ts +307 -0
  45. package/pi-extension/src/cognitive-routing/controller.ts +1118 -0
  46. package/pi-extension/src/cognitive-routing/history.ts +638 -0
  47. package/pi-extension/src/cognitive-routing/host.ts +172 -0
  48. package/pi-extension/src/cognitive-routing/runtime.ts +57 -0
  49. package/pi-extension/src/cognitive-routing/tool.ts +272 -0
  50. package/pi-extension/src/cognitive-routing/types.ts +89 -0
  51. package/pi-extension/src/context-virtualization/commands.ts +111 -0
  52. package/pi-extension/src/context-virtualization/projector.ts +62 -0
  53. package/pi-extension/src/context-virtualization/runtime.ts +406 -0
  54. package/pi-extension/src/context-virtualization/state.ts +79 -0
  55. package/pi-extension/src/context-virtualization/types.ts +92 -0
  56. package/pi-extension/src/conversation-history/passages.ts +81 -0
  57. package/pi-extension/src/conversation-history/ranking.ts +155 -0
  58. package/pi-extension/src/conversation-history/runtime.ts +250 -0
  59. package/pi-extension/src/conversation-history/search.ts +79 -0
  60. package/pi-extension/src/conversation-history/types.ts +31 -0
  61. package/pi-extension/src/freeflow-context/resolver.ts +139 -0
  62. package/pi-extension/src/freeflow-context/runtime.ts +100 -0
  63. package/pi-extension/src/freeflow-context/source-projector.ts +106 -0
  64. package/pi-extension/src/freeflow-context/tool.ts +360 -0
  65. package/pi-extension/src/freeflow-context/types.ts +70 -0
  66. package/pi-extension/src/freeflow-context/visibility.ts +53 -0
  67. package/pi-extension/src/index.ts +553 -101
  68. package/pi-extension/src/runtime/runtime-context.ts +339 -281
  69. package/pi-extension/src/runtime/runtime-identity.ts +8 -0
  70. package/pi-extension/src/settings/settings-tui.ts +93 -0
  71. package/pi-extension/src/settings/settings-ui.ts +700 -613
  72. package/pi-extension/src/ui/text-component.ts +66 -0
  73. package/pi-extension/tests/cognitive-routing/commands.test.js +134 -0
  74. package/pi-extension/tests/cognitive-routing/controller.test.js +1099 -0
  75. package/pi-extension/tests/cognitive-routing/extension-lifecycle.test.js +1071 -0
  76. package/pi-extension/tests/cognitive-routing/history.test.js +274 -0
  77. package/pi-extension/tests/cognitive-routing/host-fixture.js +4 -0
  78. package/pi-extension/tests/cognitive-routing/host-identity.test.js +63 -0
  79. package/pi-extension/tests/cognitive-routing/profile-resolution.test.js +236 -0
  80. package/pi-extension/tests/cognitive-routing/tool.test.js +230 -0
  81. package/pi-extension/tests/context-virtualization/extension.test.js +749 -0
  82. package/pi-extension/tests/context-virtualization/projector.test.js +110 -0
  83. package/pi-extension/tests/context-virtualization/runtime.test.js +216 -0
  84. package/pi-extension/tests/conversation-history/runtime.test.js +98 -0
  85. package/pi-extension/tests/conversation-history/search.test.js +97 -0
  86. package/pi-extension/tests/integration/pi-extension.test.js +928 -2047
  87. package/pi-extension/tests/integration/prompt-architecture.test.js +305 -0
  88. package/runtime/prompts/cognitive-routing.md +9 -0
  89. package/runtime/prompts/context-virtualization.md +3 -0
  90. package/runtime/prompts/conversation-history.md +3 -0
  91. package/runtime/prompts/core.md +13 -0
  92. package/runtime/prompts/interaction-contract.md +7 -0
  93. package/runtime/prompts/skills.md +65 -0
  94. package/skills/action-selection/SKILL.md +91 -0
  95. package/skills/bypass/SKILL.md +3 -2
  96. package/skills/commit-work/SKILL.md +1 -1
  97. package/skills/commit-work/references/staging-decisions.md +1 -1
  98. package/skills/decision-gate/SKILL.md +1 -1
  99. package/skills/design-for-depth/SKILL.md +14 -33
  100. package/skills/design-for-depth/references/design-pressure-signals.md +1 -1
  101. package/skills/design-for-depth/references/interface-design-loop.md +1 -1
  102. package/skills/design-for-depth/references/software-design-philosophy.md +1 -1
  103. package/skills/diagnose-failure/SKILL.md +20 -14
  104. package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +1 -3
  105. package/skills/diagnose-failure/references/{flaky-and-performance.md → flaky-and-performance-diagnosis.md} +1 -1
  106. package/skills/discuss/SKILL.md +34 -22
  107. package/skills/discuss/references/discussion-continuity.md +71 -0
  108. package/skills/evaluate-skill/SKILL.md +5 -5
  109. package/skills/evaluate-skill/references/{definition-schema.md → evaluation-definition-schema.md} +42 -2
  110. package/skills/evaluate-skill/references/execution-and-evidence.md +8 -3
  111. package/skills/evaluate-skill/scripts/lib/definitions.mjs +114 -3
  112. package/skills/evaluate-skill/scripts/lib/grade-interaction.mjs +156 -1
  113. package/skills/evaluate-skill/scripts/lib/grade.mjs +9 -1
  114. package/skills/evaluate-skill/scripts/lib/pi.mjs +147 -32
  115. package/skills/evaluate-skill/scripts/lib/rpc.mjs +4 -4
  116. package/skills/evaluate-skill/scripts/lib/runner.mjs +36 -14
  117. package/skills/evaluate-skill/scripts/lib/sandbox.mjs +92 -0
  118. package/skills/evaluate-skill/scripts/pi-guard.mjs +1 -1
  119. package/skills/evaluate-skill/scripts/pi-observer.mjs +66 -0
  120. package/skills/evaluate-skill/scripts/skill-eval.mjs +6 -5
  121. package/skills/execute-work/SKILL.md +18 -15
  122. package/skills/execute-work/references/code-practices.md +1 -1
  123. package/skills/execute-work/references/execute-work-edges.md +42 -0
  124. package/skills/finish-branch/SKILL.md +2 -2
  125. package/skills/finish-branch/references/integration-options.md +1 -1
  126. package/skills/handoff/SKILL.md +3 -3
  127. package/skills/launch-work/SKILL.md +1 -1
  128. package/skills/launch-work/references/launch-readiness.md +2 -2
  129. package/skills/migration-work/SKILL.md +2 -2
  130. package/skills/migration-work/references/migration-lifecycle.md +1 -1
  131. package/skills/mode-contract/SKILL.md +32 -10
  132. package/skills/release-work/SKILL.md +1 -1
  133. package/skills/release-work/references/release-evidence.md +1 -1
  134. package/skills/review-artifact/SKILL.md +28 -26
  135. package/skills/review-work/SKILL.md +28 -26
  136. package/skills/review-work/references/{reviewer-prompt.md → independent-work-reviewer-contract.md} +1 -1
  137. package/skills/review-work/references/security-risk-lens.md +1 -1
  138. package/skills/setup-freeflow/SKILL.md +6 -10
  139. package/skills/setup-freeflow/references/activation-contract.md +5 -10
  140. package/skills/setup-freeflow/references/host-setup.md +3 -7
  141. package/skills/simplify-code/SKILL.md +1 -1
  142. package/skills/simplify-code/references/simplification-patterns.md +1 -1
  143. package/skills/tdd/SKILL.md +18 -38
  144. package/skills/tdd/references/test-design.md +2 -2
  145. package/skills/track-work/SKILL.md +362 -58
  146. package/skills/track-work/scripts/lib/codec.mjs +570 -0
  147. package/skills/track-work/scripts/lib/commands.mjs +568 -0
  148. package/skills/track-work/scripts/lib/contract.mjs +303 -0
  149. package/skills/track-work/scripts/lib/model.mjs +506 -0
  150. package/skills/track-work/scripts/lib/operations.mjs +965 -0
  151. package/skills/track-work/scripts/lib/record-store.mjs +264 -0
  152. package/skills/track-work/scripts/lib/result.mjs +37 -0
  153. package/skills/track-work/scripts/lib/rewrites.mjs +740 -0
  154. package/skills/track-work/scripts/lib/schema.mjs +277 -0
  155. package/skills/track-work/scripts/lib/source-inventory.mjs +162 -0
  156. package/skills/track-work/scripts/lib/views.mjs +443 -0
  157. package/skills/track-work/scripts/lib/workspace.mjs +134 -0
  158. package/skills/track-work/scripts/working-record.mjs +122 -0
  159. package/skills/verify-work/SKILL.md +14 -2
  160. package/skills/verify-work/references/browser-runtime-evidence.md +1 -1
  161. package/skills/verify-work/references/integration-evidence.md +1 -1
  162. package/skills/verify-work/references/performance-evidence.md +1 -1
  163. package/skills/workflow/SKILL.md +105 -53
  164. package/skills/workflow/references/domain-skill-composition.md +22 -42
  165. package/skills/write-plan/SKILL.md +1 -1
  166. package/skills/write-skill/SKILL.md +3 -2
  167. package/skills/write-skill/references/progressive-disclosure.md +17 -3
  168. package/pi-extension/dist/output-router/host-producer-identification.js +0 -232
  169. package/pi-extension/dist/output-router/native-safety-net.js +0 -216
  170. package/pi-extension/dist/output-router/observed-tool-routing.js +0 -122
  171. package/pi-extension/dist/output-router/renderers.js +0 -1023
  172. package/pi-extension/dist/output-router/router-tools.js +0 -554
  173. package/pi-extension/dist/output-router/schemas.js +0 -383
  174. package/pi-extension/dist/output-router/status.js +0 -744
  175. package/pi-extension/dist/output-router/utils.js +0 -502
  176. package/pi-extension/src/output-router/host-producer-identification.ts +0 -256
  177. package/pi-extension/src/output-router/native-safety-net.ts +0 -248
  178. package/pi-extension/src/output-router/observed-tool-routing.ts +0 -134
  179. package/pi-extension/src/output-router/renderers.ts +0 -1108
  180. package/pi-extension/src/output-router/router-tools.ts +0 -579
  181. package/pi-extension/src/output-router/schemas.ts +0 -387
  182. package/pi-extension/src/output-router/status.ts +0 -791
  183. package/pi-extension/src/output-router/utils.ts +0 -554
  184. package/pi-extension/tests/output-router/observed-producers.test.js +0 -132
  185. package/pi-extension/tests/output-router/search.test.js +0 -722
  186. package/router/dist/benchmarks/benchmark-harness.d.ts +0 -35
  187. package/router/dist/benchmarks/benchmark-harness.js +0 -92
  188. package/router/dist/benchmarks/benchmarks.d.ts +0 -109
  189. package/router/dist/benchmarks/benchmarks.js +0 -979
  190. package/router/dist/benchmarks/codex-qa-benchmarks.d.ts +0 -95
  191. package/router/dist/benchmarks/codex-qa-benchmarks.js +0 -500
  192. package/router/dist/benchmarks/command-benchmarks.d.ts +0 -143
  193. package/router/dist/benchmarks/command-benchmarks.js +0 -698
  194. package/router/dist/benchmarks/context-mode-normalized-benchmarks.d.ts +0 -82
  195. package/router/dist/benchmarks/context-mode-normalized-benchmarks.js +0 -773
  196. package/router/dist/benchmarks/context-mode-real-deep-benchmark.d.ts +0 -132
  197. package/router/dist/benchmarks/context-mode-real-deep-benchmark.js +0 -1380
  198. package/router/dist/benchmarks/context-saving-baseline.d.ts +0 -60
  199. package/router/dist/benchmarks/context-saving-baseline.js +0 -470
  200. package/router/dist/benchmarks/index-benchmarks.d.ts +0 -103
  201. package/router/dist/benchmarks/index-benchmarks.js +0 -862
  202. package/router/dist/benchmarks/storage-policy-benchmarks.d.ts +0 -101
  203. package/router/dist/benchmarks/storage-policy-benchmarks.js +0 -618
  204. package/router/dist/benchmarks/vault-index-benchmarks.d.ts +0 -56
  205. package/router/dist/benchmarks/vault-index-benchmarks.js +0 -322
  206. package/router/dist/config/config.d.ts +0 -103
  207. package/router/dist/config/config.js +0 -632
  208. package/router/dist/config/router-contract.d.ts +0 -10
  209. package/router/dist/config/router-contract.js +0 -54
  210. package/router/dist/config/schema.d.ts +0 -27
  211. package/router/dist/config/schema.js +0 -648
  212. package/router/dist/config/types.d.ts +0 -573
  213. package/router/dist/config/types.js +0 -41
  214. package/router/dist/evidence/bounded-evidence.d.ts +0 -40
  215. package/router/dist/evidence/bounded-evidence.js +0 -323
  216. package/router/dist/evidence/evidence-range-selector.d.ts +0 -24
  217. package/router/dist/evidence/evidence-range-selector.js +0 -232
  218. package/router/dist/evidence/evidence-search.d.ts +0 -27
  219. package/router/dist/evidence/evidence-search.js +0 -490
  220. package/router/dist/evidence/evidence.d.ts +0 -38
  221. package/router/dist/evidence/evidence.js +0 -200
  222. package/router/dist/evidence/failure-contracts.d.ts +0 -37
  223. package/router/dist/evidence/failure-contracts.js +0 -166
  224. package/router/dist/evidence/line-ranges.d.ts +0 -24
  225. package/router/dist/evidence/line-ranges.js +0 -22
  226. package/router/dist/experiments/local-index.d.ts +0 -64
  227. package/router/dist/experiments/local-index.js +0 -581
  228. package/router/dist/index.d.ts +0 -30
  229. package/router/dist/index.js +0 -32
  230. package/router/dist/local/local-traversal.d.ts +0 -18
  231. package/router/dist/local/local-traversal.js +0 -334
  232. package/router/dist/processing/engine.d.ts +0 -132
  233. package/router/dist/processing/engine.js +0 -533
  234. package/router/dist/processing/reducers.d.ts +0 -280
  235. package/router/dist/processing/reducers.js +0 -1673
  236. package/router/dist/processing/renderers.d.ts +0 -31
  237. package/router/dist/processing/renderers.js +0 -195
  238. package/router/dist/processing/scripts.d.ts +0 -91
  239. package/router/dist/processing/scripts.js +0 -386
  240. package/router/dist/repo/repo-traversal.d.ts +0 -18
  241. package/router/dist/repo/repo-traversal.js +0 -245
  242. package/router/dist/routing/observed-reducers.d.ts +0 -41
  243. package/router/dist/routing/observed-reducers.js +0 -661
  244. package/router/dist/routing/observed-routing.d.ts +0 -26
  245. package/router/dist/routing/observed-routing.js +0 -378
  246. package/router/dist/routing/parsers.d.ts +0 -16
  247. package/router/dist/routing/parsers.js +0 -521
  248. package/router/dist/routing/run-filters.d.ts +0 -60
  249. package/router/dist/routing/run-filters.js +0 -238
  250. package/router/dist/routing/run-reducers.d.ts +0 -49
  251. package/router/dist/routing/run-reducers.js +0 -122
  252. package/router/dist/sandbox/adapter-roots.d.ts +0 -46
  253. package/router/dist/sandbox/adapter-roots.js +0 -66
  254. package/router/dist/sandbox/eryx-python-adapter.d.ts +0 -13
  255. package/router/dist/sandbox/eryx-python-adapter.js +0 -868
  256. package/router/dist/sandbox/jq-wasm-adapter.d.ts +0 -9
  257. package/router/dist/sandbox/jq-wasm-adapter.js +0 -429
  258. package/router/dist/sandbox/quickjs-wasi-adapter.d.ts +0 -13
  259. package/router/dist/sandbox/quickjs-wasi-adapter.js +0 -384
  260. package/router/dist/sandbox/script-sandbox.d.ts +0 -134
  261. package/router/dist/sandbox/script-sandbox.js +0 -337
  262. package/router/dist/setup/script-transform-adapters.d.ts +0 -32
  263. package/router/dist/setup/script-transform-adapters.js +0 -278
  264. package/router/dist/tools/batch.d.ts +0 -33
  265. package/router/dist/tools/batch.js +0 -586
  266. package/router/dist/tools/run.d.ts +0 -62
  267. package/router/dist/tools/run.js +0 -1304
  268. package/router/dist/tools/search.d.ts +0 -66
  269. package/router/dist/tools/search.js +0 -1364
  270. package/router/dist/transform/engine.d.ts +0 -168
  271. package/router/dist/transform/engine.js +0 -2072
  272. package/router/dist/vault/vault-index.d.ts +0 -125
  273. package/router/dist/vault/vault-index.js +0 -416
  274. package/router/dist/vault/vault.d.ts +0 -138
  275. package/router/dist/vault/vault.js +0 -630
  276. package/runtime/interaction-contract.md +0 -16
  277. package/skills/discuss/references/checkpoints.md +0 -66
  278. package/skills/execute-work/references/execution-loop.md +0 -77
  279. package/skills/output-router/SKILL.md +0 -206
  280. package/skills/output-router/references/safety-policy.md +0 -40
  281. package/skills/setup-freeflow/references/output-router-setup.md +0 -110
  282. package/skills/track-work/references/working-record-schema.md +0 -378
  283. package/skills/workflow/references/workflow-loop.md +0 -92
  284. /package/skills/handoff/references/{templates.md → handoff-templates.md} +0 -0
  285. /package/skills/review-artifact/references/{reviewer-prompt.md → independent-artifact-reviewer-contract.md} +0 -0
@@ -1,1108 +0,0 @@
1
- import {
2
- extractTextContent,
3
- formatStatus,
4
- oneLine,
5
- shortenMiddle,
6
- splitLines,
7
- statusIcon,
8
- textComponent,
9
- themeBold,
10
- themeFg,
11
- truncateText,
12
- } from "./utils.js";
13
-
14
- export function commandLabel(command) {
15
- if (Array.isArray(command)) {
16
- return truncateText(command.join(" "), 120);
17
- }
18
- return truncateText(command ?? "...", 120);
19
- }
20
-
21
- function runProducerLabel(args) {
22
- if (args?.script?.language) {
23
- const label = args.script.label ? ` ${args.script.label}` : "";
24
- return `script:${args.script.language}${label}`;
25
- }
26
- return `$ ${commandLabel(args?.command)}`;
27
- }
28
-
29
- function retrieveSourceLabel(source) {
30
- if (!source || source.kind === "repo") {
31
- return `repo ${shortenMiddle(source?.path ?? ".", 80)}`;
32
- }
33
- if (source.kind === "local") {
34
- const path = source.path ? `:${source.path}` : "";
35
- return `local ${shortenMiddle(source.root ?? ".", 60)}${shortenMiddle(path, 50)}`;
36
- }
37
- if (source.kind === "vault") {
38
- const stream = source.stream ? `:${source.stream}` : "";
39
- return `vault ${shortenMiddle(source.outputId ?? "...", 48)}${stream}`;
40
- }
41
- return oneLine(source.kind ?? "source");
42
- }
43
-
44
- function evidenceLabel(evidence) {
45
- if (!evidence) {
46
- return "no evidence";
47
- }
48
- const source = evidence.source;
49
- const path =
50
- evidence.path ??
51
- (source?.kind === "repo"
52
- ? source.path
53
- : source?.kind === "local"
54
- ? source.path
55
- : source?.kind === "vault"
56
- ? source.outputId
57
- : "evidence");
58
- const lines = evidence.lines ? `:${evidence.lines}` : "";
59
- return `${shortenMiddle(path, 90)}${lines}`;
60
- }
61
-
62
- function excerptLines(theme, excerpt, indent = " ", maxLines = 8) {
63
- const lines = splitLines(String(excerpt ?? ""));
64
- const shown = lines
65
- .slice(0, maxLines)
66
- .map((line) => `${indent}${themeFg(theme, "toolOutput", truncateText(line, 140))}`);
67
- const omitted = lines.length - shown.length;
68
- if (omitted > 0) {
69
- shown.push(`${indent}${themeFg(theme, "dim", `… ${omitted} more line(s)`)}`);
70
- }
71
- return shown;
72
- }
73
-
74
- function routeSummaryLine(theme, result) {
75
- const route = result?.routing?.status ?? "unknown";
76
- const preserve = result?.preserve ? ` • preserve: ${result.preserve}` : "";
77
- return `${themeFg(theme, "muted", "routing:")} ${formatStatus(theme, route)}${themeFg(theme, "dim", preserve)}`;
78
- }
79
-
80
- function evidenceSourceSummary(source) {
81
- if (!source || typeof source !== "object") {
82
- return "unknown";
83
- }
84
- if (source.kind === "repo") {
85
- return `repo ${source.path ?? "."}`;
86
- }
87
- if (source.kind === "local") {
88
- const path = source.path ? `:${source.path}` : "";
89
- return `local ${source.root ?? "."}${path}`;
90
- }
91
- if (source.kind === "vault") {
92
- const stream = source.stream ? `:${source.stream}` : "";
93
- return `vault ${source.outputId ?? "..."}${stream}`;
94
- }
95
- return oneLine(source.kind ?? "source");
96
- }
97
-
98
- function runFilterLabel(filters) {
99
- if (!filters || typeof filters !== "object") {
100
- return "";
101
- }
102
- const parts = [`stream=${filters.stream ?? "selected"}`];
103
- if (Array.isArray(filters.include) && filters.include.length > 0) {
104
- parts.push(`include=${filters.include.join("|")}`);
105
- }
106
- if (Array.isArray(filters.exclude) && filters.exclude.length > 0) {
107
- parts.push(`exclude=${filters.exclude.join("|")}`);
108
- }
109
- if (filters.flags) {
110
- parts.push(`flags=${filters.flags}`);
111
- }
112
- for (const key of ["head", "tail", "maxLines", "maxBytes"] as const) {
113
- if (filters[key] !== undefined) {
114
- parts.push(`${key}=${filters[key]}`);
115
- }
116
- }
117
- if (filters.selectedLines !== undefined && filters.sourceLines !== undefined) {
118
- parts.push(`selected=${filters.selectedLines}/${filters.sourceLines}`);
119
- }
120
- if (filters.fallbackPreservedFailureEvidence) {
121
- parts.push("fallback=failure-evidence");
122
- }
123
- return parts.join(" ");
124
- }
125
-
126
- function runScriptProducerLabel(scriptProducer) {
127
- if (!scriptProducer || typeof scriptProducer !== "object") {
128
- return "";
129
- }
130
- const parts = [
131
- `${scriptProducer.language ?? "script"}:${scriptProducer.status ?? "unknown"}`,
132
- `policy=${scriptProducer.policy ?? "sandboxed"}`,
133
- ];
134
- if (scriptProducer.label) {
135
- parts.push(`label=${scriptProducer.label}`);
136
- }
137
- if (scriptProducer.adapterId) {
138
- parts.push(`adapter=${scriptProducer.adapterId}`);
139
- }
140
- if (scriptProducer.codeSha256) {
141
- parts.push(`code=${scriptProducer.codeSha256}`);
142
- }
143
- if (scriptProducer.stdoutBytes !== undefined || scriptProducer.stderrBytes !== undefined) {
144
- parts.push(`bytes=${scriptProducer.stdoutBytes ?? 0}/${scriptProducer.stderrBytes ?? 0}`);
145
- }
146
- if (scriptProducer.failure?.kind) {
147
- parts.push(`failure=${scriptProducer.failure.kind}`);
148
- }
149
- return parts.join(" ");
150
- }
151
-
152
- function runScriptFilterLabel(scriptFilter) {
153
- if (!scriptFilter || typeof scriptFilter !== "object") {
154
- return "";
155
- }
156
- const parts = [`${scriptFilter.language ?? "script"}:${scriptFilter.status ?? "unknown"}`];
157
- if (scriptFilter.label) {
158
- parts.push(`label=${scriptFilter.label}`);
159
- }
160
- if (scriptFilter.outputId) {
161
- parts.push(`transformed=${scriptFilter.outputId}`);
162
- }
163
- if (scriptFilter.failure?.kind) {
164
- parts.push(`failure=${scriptFilter.failure.kind}`);
165
- }
166
- return parts.join(" ");
167
- }
168
-
169
- function appendStorageSection(lines, theme, routed, outputId, title = "Storage") {
170
- const persistence = routed?.persistence;
171
- const recoveryOutputId = persistence?.recoveryOutputId ?? persistence?.outputId ?? routed?.recovery?.outputId;
172
- const hasStorage = routed?.decisionId || outputId || routed?.recordId || persistence?.status || recoveryOutputId;
173
- if (!hasStorage) {
174
- return;
175
- }
176
-
177
- lines.push("", themeFg(theme, "toolTitle", title));
178
- if (routed?.decisionId) {
179
- lines.push(` ${themeFg(theme, "muted", "decisionId:")} ${themeFg(theme, "accent", routed.decisionId)}`);
180
- }
181
- if (outputId) {
182
- lines.push(` ${themeFg(theme, "muted", "outputId:")} ${themeFg(theme, "accent", outputId)}`);
183
- }
184
- if (routed?.recordId) {
185
- lines.push(` ${themeFg(theme, "muted", "recordId:")} ${themeFg(theme, "accent", routed.recordId)}`);
186
- }
187
- if (persistence?.status) {
188
- lines.push(
189
- ` ${themeFg(theme, "muted", "persistence:")} ${persistence.status} / ${persistence.recoverability ?? "unknown"}`,
190
- );
191
- }
192
- if (recoveryOutputId && recoveryOutputId !== outputId) {
193
- lines.push(` ${themeFg(theme, "muted", "recoveryOutputId:")} ${themeFg(theme, "accent", recoveryOutputId)}`);
194
- }
195
- }
196
-
197
- function exactRetrieveHintFromEvidence(packet) {
198
- if (!packet?.lines) {
199
- return "";
200
- }
201
- const source = packet.source;
202
- if (source?.kind === "vault" && source.outputId) {
203
- return `action=retrieve source.kind=vault lineRange=${packet.lines} stream=${source.stream ?? "raw"} outputId=${source.outputId}`;
204
- }
205
- if (source?.kind === "local") {
206
- const path = packet.path ?? source.path;
207
- return path ? `action=retrieve source.kind=local lineRange=${packet.lines} root=${source.root} path=${path}` : "";
208
- }
209
- const path = packet.path ?? (source?.kind === "repo" ? source.path : undefined);
210
- if (path && source?.kind !== "vault") {
211
- return `action=retrieve source.kind=repo lineRange=${packet.lines} path=${path}`;
212
- }
213
- return "";
214
- }
215
-
216
- function firstExactRetrieveHintFromEvidence(evidence) {
217
- if (!Array.isArray(evidence)) {
218
- return "";
219
- }
220
- for (const packet of evidence) {
221
- const hint = exactRetrieveHintFromEvidence(packet);
222
- if (hint) {
223
- return hint;
224
- }
225
- }
226
- return "";
227
- }
228
-
229
- function exactRetrieveHintFromImportantLines(outputId, importantLines) {
230
- if (!outputId || !Array.isArray(importantLines)) {
231
- return "";
232
- }
233
- const firstSpan = importantLines.find((line) => line?.lines);
234
- if (!firstSpan) {
235
- return "";
236
- }
237
- return `action=retrieve source.kind=vault lineRange=${firstSpan.lines} stream=${firstSpan.stream ?? "combined"} outputId=${outputId}`;
238
- }
239
-
240
- function recoveryStartingPoint(outputId) {
241
- return outputId
242
- ? `freeflow_search source.kind=vault outputId=${outputId} (choose stream + lineRange, or query/expand)`
243
- : "";
244
- }
245
-
246
- function routerResultFromToolResult(result) {
247
- return result?.details?.result;
248
- }
249
-
250
- function fallbackResultText(result) {
251
- const text = extractTextContent(result?.content);
252
- return text ? truncateText(text, 200) : "No Freeflow result details available.";
253
- }
254
-
255
- export function renderFreeflowSearchCall(args, theme) {
256
- const title = themeFg(theme, "toolTitle", themeBold(theme, "freeflow_search"));
257
- const action = themeFg(theme, "muted", args?.action ?? "query");
258
- const source = themeFg(theme, "accent", retrieveSourceLabel(args?.source));
259
- const query = args?.query ? ` ${themeFg(theme, "dim", `\"${truncateText(args.query, 70)}\"`)}` : "";
260
- return textComponent(`${title} ${action} ${source}${query}`);
261
- }
262
-
263
- export function renderFreeflowRetrieveCall(args, theme) {
264
- const title = themeFg(theme, "toolTitle", themeBold(theme, "freeflow_search"));
265
- const action = themeFg(theme, "muted", args?.action ?? "query");
266
- const source = themeFg(theme, "accent", retrieveSourceLabel(args?.source));
267
- const query = args?.query ? ` ${themeFg(theme, "dim", `\"${truncateText(args.query, 70)}\"`)}` : "";
268
- return textComponent(`${title} ${action} ${source}${query}`);
269
- }
270
-
271
- export function renderFreeflowRunCall(args, theme) {
272
- const title = themeFg(theme, "toolTitle", themeBold(theme, "freeflow_run"));
273
- const command = themeFg(theme, "accent", runProducerLabel(args));
274
- const extras = [];
275
- if (args?.preserve) {
276
- extras.push(`preserve=${args.preserve}`);
277
- }
278
- if (args?.timeoutMs !== undefined) {
279
- extras.push(`timeout=${args.timeoutMs}ms`);
280
- }
281
- if (args?.script?.language) {
282
- extras.push(`producer=${args.script.language}`);
283
- }
284
- if (args?.scriptFilter?.language) {
285
- extras.push(`scriptFilter=${args.scriptFilter.language}`);
286
- }
287
- const suffix = extras.length > 0 ? ` ${themeFg(theme, "dim", `(${extras.join(", ")})`)}` : "";
288
- return textComponent(`${title} ${command}${suffix}`);
289
- }
290
-
291
- function transformOperationLabel(operation) {
292
- if (!operation || typeof operation !== "object") {
293
- return "operation";
294
- }
295
- return String(operation.kind ?? "operation");
296
- }
297
-
298
- export function renderFreeflowTransformCall(args, theme) {
299
- const title = themeFg(theme, "toolTitle", themeBold(theme, "freeflow_search action=transform"));
300
- const operation = themeFg(theme, "accent", transformOperationLabel(args?.operation));
301
- const source = themeFg(theme, "muted", retrieveSourceLabel(args?.source));
302
- const preserve = args?.preserve ? ` ${themeFg(theme, "dim", `(preserve=${args.preserve})`)}` : "";
303
- return textComponent(`${title} ${operation} ${source}${preserve}`);
304
- }
305
-
306
- export function renderFreeflowBatchCall(args, theme) {
307
- const title = themeFg(theme, "toolTitle", themeBold(theme, "freeflow_batch"));
308
- const steps = Array.isArray(args?.steps) ? args.steps : [];
309
- const kinds = steps
310
- .slice(0, 4)
311
- .map((step) => step?.kind ?? "step")
312
- .join(", ");
313
- const more = steps.length > 4 ? ` +${steps.length - 4}` : "";
314
- const concurrency = args?.concurrency ? ` ${themeFg(theme, "dim", `(concurrency=${args.concurrency})`)}` : "";
315
- return textComponent(
316
- `${title} ${themeFg(theme, "accent", `${steps.length} step(s)`)} ${themeFg(theme, "muted", kinds + more)}${concurrency}`,
317
- );
318
- }
319
-
320
- export function renderFreeflowBatchResult(result, { expanded }: any = {}, theme) {
321
- const routed = routerResultFromToolResult(result);
322
- if (!routed) {
323
- return textComponent(fallbackResultText(result));
324
- }
325
-
326
- const failed = routed.failedCount ?? 0;
327
- const icon = failed > 0 || routed.toolStatus === "error" ? "✗" : statusIcon(routed.toolStatus);
328
- const steps = Array.isArray(routed.steps) ? routed.steps : [];
329
- const lines = [
330
- `${themeFg(theme, failed > 0 ? "warning" : "success", icon)} ${themeFg(theme, "toolTitle", "freeflow_batch")} ${themeFg(theme, "muted", `${routed.okCount ?? 0}/${routed.stepCount ?? steps.length} ok`)} • ${routeSummaryLine(theme, routed)}`,
331
- ];
332
- if (routed.summary) {
333
- lines.push(themeFg(theme, "muted", truncateText(routed.summary, 160)));
334
- }
335
- const queryAnswers = Array.isArray(routed.queries) ? routed.queries : [];
336
- if (queryAnswers.length > 0) {
337
- lines.push(
338
- themeFg(
339
- theme,
340
- "dim",
341
- `${queryAnswers.filter((answer) => answer?.status === "answered").length}/${queryAnswers.length} query answer(s) from child evidence handles`,
342
- ),
343
- );
344
- for (const answer of queryAnswers.slice(0, 3)) {
345
- lines.push(themeFg(theme, "muted", truncateText(answer?.summary ?? answer?.query ?? "query", 180)));
346
- }
347
- }
348
- lines.push(
349
- themeFg(
350
- theme,
351
- "dim",
352
- `concurrency=${routed.concurrency ?? "?"} • child outputs suppressed; full child results in details.result.steps`,
353
- ),
354
- );
355
-
356
- if (!expanded) {
357
- lines.push(themeFg(theme, "dim", "ctrl+o to expand child step statuses and recovery pointers"));
358
- return textComponent(lines.join("\n"));
359
- }
360
-
361
- if (queryAnswers.length > 0) {
362
- lines.push("", themeFg(theme, "toolTitle", "Query answers"));
363
- queryAnswers.forEach((answer, index) => {
364
- lines.push(
365
- ` ${themeFg(theme, answer?.status === "answered" ? "accent" : "warning", `#${index + 1} ${answer?.status ?? "unknown"}`)} ${truncateText(answer?.query ?? "query", 120)}`,
366
- );
367
- if (answer?.summary) {
368
- lines.push(` ${truncateText(answer.summary, 220)}`);
369
- }
370
- const matches = Array.isArray(answer?.matches) ? answer.matches : [];
371
- matches.slice(0, 3).forEach((match) => {
372
- lines.push(
373
- ` ${themeFg(theme, "muted", `${match.stepId ?? "step"}:`)} ${truncateText(match.excerpt ?? "", 180)}`,
374
- );
375
- });
376
- });
377
- }
378
-
379
- lines.push("", themeFg(theme, "toolTitle", "Steps"));
380
- if (steps.length === 0) {
381
- lines.push(` ${themeFg(theme, "dim", "No steps returned.")}`);
382
- } else {
383
- steps.forEach((step) => {
384
- const child = step.result;
385
- const outputId = child?.outputId ?? child?.recovery?.outputId;
386
- const status = step.status ?? child?.toolStatus ?? "unknown";
387
- const pieces = [`${step.kind}`, `status=${status}`, `${step.durationMs ?? 0}ms`];
388
- if (child?.routing?.status) {
389
- pieces.push(`routing=${child.routing.status}`);
390
- }
391
- if (child?.execution?.status) {
392
- pieces.push(`execution=${child.execution.status}`);
393
- }
394
- if (outputId) {
395
- pieces.push(`outputId=${outputId}`);
396
- }
397
- if (Array.isArray(child?.evidence)) {
398
- pieces.push(`evidence=${child.evidence.length}`);
399
- }
400
- if (Array.isArray(child?.importantLines)) {
401
- pieces.push(`spans=${child.importantLines.length}`);
402
- }
403
- lines.push(
404
- ` ${themeFg(theme, status === "failed" ? "warning" : "accent", `#${step.index + 1} ${step.id}`)} ${themeFg(theme, "muted", pieces.join(" • "))}`,
405
- );
406
- const message = step.error ?? child?.failure?.message ?? child?.summary ?? child?.routing?.reason;
407
- if (message) {
408
- lines.push(` ${truncateText(message, 180)}`);
409
- }
410
- if (outputId) {
411
- lines.push(` ${themeFg(theme, "muted", "recovery starting point:")} ${recoveryStartingPoint(outputId)}`);
412
- }
413
- });
414
- }
415
-
416
- lines.push("", themeFg(theme, "toolTitle", "Batch recovery"));
417
- if (routed.recovery?.how) {
418
- lines.push(` ${truncateText(routed.recovery.how, 220)}`);
419
- }
420
- lines.push(
421
- ` ${themeFg(theme, "dim", "Use details.result.steps for complete child routed results; model-visible output intentionally omits child excerpts.")}`,
422
- );
423
- return textComponent(lines.join("\n"));
424
- }
425
-
426
- export function renderFreeflowStatusCall(args, theme) {
427
- const title = themeFg(theme, "toolTitle", themeBold(theme, "freeflow_status"));
428
- const action = themeFg(theme, "accent", args?.action ?? "status");
429
- return textComponent(`${title} ${action}`);
430
- }
431
-
432
- export function renderFreeflowStatusResult(result, { expanded }: any = {}, theme) {
433
- const report = routerResultFromToolResult(result);
434
- if (!report) {
435
- return textComponent(fallbackResultText(result));
436
- }
437
-
438
- const warnings = Array.isArray(report.configWarnings) ? report.configWarnings : [];
439
- const localWarnings = Array.isArray(report.localConfigWarnings) ? report.localConfigWarnings : [];
440
- const allWarnings = [...warnings, ...localWarnings];
441
- const recommendations = Array.isArray(report.migration?.recommendations) ? report.migration.recommendations : [];
442
- const core = report.effectiveConfig ?? {};
443
- const sources = report.configuration?.sources ?? core.sources ?? {};
444
- const router = core.outputRouter ?? {};
445
- const observedRouting = report.observedRouting ?? core.observedRouting ?? {};
446
- const unsafeProcessing = report.processing?.unsafeUnsandboxed?.enabled === true;
447
- const modeActive = report.mode?.active === true;
448
- const resolvedMode = report.mode?.resolvedMode ?? report.mode?.effectiveMode ?? "workflow";
449
- const displayedMode = modeActive ? resolvedMode : `dormant (${resolvedMode})`;
450
- const icon = statusIcon(report.toolStatus);
451
- const lines = [
452
- `${themeFg(theme, "success", icon)} ${themeFg(theme, "toolTitle", "freeflow_status")} ${themeFg(theme, "muted", report.action ?? "status")} • freeflow ${formatStatus(theme, core.enabled ? "ok" : "off")} • mode ${themeFg(theme, modeActive ? "accent" : "dim", displayedMode)} • router ${formatStatus(theme, router.enabled === false ? "off" : "ok")}`,
453
- `${themeFg(theme, "muted", "vault:")} ${themeFg(theme, "accent", shortenMiddle(report.vault?.root ?? "unknown", 80))} ${themeFg(theme, "dim", report.vault?.writability?.status ?? "unknown")}`,
454
- `${themeFg(theme, "muted", "routing:")} observed=${observedRouting.enabled ? "on" : "off"} • processing=${unsafeProcessing ? "unsafe/unsandboxed" : "safe-default"} • warnings=${allWarnings.length} • migrations=${recommendations.length}`,
455
- ];
456
-
457
- if (!expanded) {
458
- lines.push(
459
- themeFg(
460
- theme,
461
- "dim",
462
- "ctrl+o to expand configuration sources, effective state, routing, warnings, and migrations",
463
- ),
464
- );
465
- return textComponent(lines.join("\n"));
466
- }
467
-
468
- const repository = report.configuration?.repository ?? {};
469
- const personal = report.configuration?.personal ?? {};
470
- lines.push("", themeFg(theme, "toolTitle", "Configuration"));
471
- lines.push(
472
- ` ${themeFg(theme, "muted", "repository:")} ${repository.exists ? (repository.valid ? "valid" : themeFg(theme, "warning", "invalid")) : "missing"} ${themeFg(theme, "dim", shortenMiddle(repository.path ?? report.configPath ?? ".freeflow/config.json", 90))}`,
473
- );
474
- lines.push(
475
- ` ${themeFg(theme, "muted", "personal:")} ${personal.exists ? (personal.valid ? "valid" : themeFg(theme, "warning", "invalid")) : "not set"} ${themeFg(theme, "dim", shortenMiddle(personal.path ?? report.localConfigPath ?? ".freeflow/local.json", 90))}`,
476
- );
477
- lines.push(
478
- ` ${themeFg(theme, "muted", "enabled:")} ${String(Boolean(core.enabled))} ${themeFg(theme, "dim", `(${sources.enabled ?? "builtin"})`)}`,
479
- );
480
- lines.push(
481
- ` ${themeFg(theme, "muted", "interactionContract:")} ${String(Boolean(core.interactionContract?.enabled))} ${themeFg(theme, "dim", `(${sources.interactionContract ?? "builtin"})`)}`,
482
- );
483
- lines.push(
484
- ` ${themeFg(theme, "muted", "skills:")} ${String(Boolean(core.skills?.enabled))} ${themeFg(theme, "dim", `(${sources.skillsEnabled ?? "builtin"})`)}`,
485
- );
486
-
487
- lines.push("", themeFg(theme, "toolTitle", "Mode"));
488
- lines.push(` ${themeFg(theme, "muted", "active:")} ${String(modeActive)}`);
489
- lines.push(` ${themeFg(theme, "muted", "effective:")} ${report.mode?.effectiveMode ?? "none"}`);
490
- lines.push(` ${themeFg(theme, "muted", "resolved:")} ${resolvedMode}`);
491
- lines.push(
492
- ` ${themeFg(theme, "muted", "repository default:")} ${report.mode?.repositoryDefaultMode ?? "workflow"} ${themeFg(theme, "dim", `(${report.mode?.repositoryDefaultModeSource ?? "builtin"})`)}`,
493
- );
494
- lines.push(
495
- ` ${themeFg(theme, "muted", "personal default override:")} ${report.mode?.personalDefaultMode ?? "none"}`,
496
- );
497
- lines.push(
498
- ` ${themeFg(theme, "muted", "configured default:")} ${report.mode?.defaultMode ?? "workflow"} ${themeFg(theme, "dim", `(${report.mode?.defaultModeSource ?? sources.defaultMode ?? "builtin"})`)}`,
499
- );
500
- lines.push(
501
- ` ${themeFg(theme, "muted", "session override:")} ${report.mode?.sessionMode ?? report.mode?.currentMode ?? "none"}`,
502
- );
503
-
504
- lines.push("", themeFg(theme, "toolTitle", "Router"));
505
- lines.push(` ${themeFg(theme, "muted", "enabled:")} ${String(router.enabled !== false)}`);
506
- lines.push(` ${themeFg(theme, "muted", "profile:")} ${router.profile ?? "standard"}`);
507
- lines.push(` ${themeFg(theme, "muted", "postToolRouting:")} ${router.postToolRouting ?? "off"}`);
508
- lines.push(` ${themeFg(theme, "muted", "storagePolicy:")} ${router.storagePolicy ?? "hybrid-dedupe"}`);
509
- if (router.thresholds) {
510
- lines.push(` ${themeFg(theme, "muted", "thresholds:")} ${JSON.stringify(router.thresholds)}`);
511
- }
512
-
513
- const vaultIndex = report.vaultIndex;
514
- if (vaultIndex) {
515
- lines.push("", themeFg(theme, "toolTitle", "Vault index"));
516
- lines.push(` ${themeFg(theme, "muted", "engine:")} ${vaultIndex.engine ?? "local-json-sidecar"}`);
517
- lines.push(
518
- ` ${themeFg(theme, "muted", "available:")} ${String(Boolean(vaultIndex.available))} degraded=${String(Boolean(vaultIndex.degraded))} stale=${String(Boolean(vaultIndex.stale))} rebuildRecommended=${String(Boolean(vaultIndex.rebuildRecommended))}`,
519
- );
520
- lines.push(
521
- ` ${themeFg(theme, "muted", "entries:")} ${vaultIndex.entryCount ?? 0} text=${vaultIndex.textEntryCount ?? 0} metadata=${vaultIndex.metadataOnlyEntryCount ?? 0}`,
522
- );
523
- if (vaultIndex.lastError) {
524
- lines.push(` ${themeFg(theme, "warning", `lastError: ${truncateText(vaultIndex.lastError, 160)}`)}`);
525
- }
526
- }
527
-
528
- const scriptTransform = report.scriptTransform;
529
- if (scriptTransform) {
530
- lines.push("", themeFg(theme, "toolTitle", "Script transform"));
531
- lines.push(` ${themeFg(theme, "muted", "enabled:")} ${String(Boolean(scriptTransform.enabled))}`);
532
- lines.push(` ${themeFg(theme, "muted", "adapter:")} ${scriptTransform.adapterStatus ?? "unavailable"}`);
533
- lines.push(
534
- ` ${themeFg(theme, "muted", "languages:")} ${(scriptTransform.configuredLanguages ?? []).join(", ") || "none"}`,
535
- );
536
- lines.push(` ${themeFg(theme, "muted", "network:")} ${scriptTransform.network ?? "off"}`);
537
- lines.push(
538
- ` ${themeFg(theme, "muted", "rawScriptPersistence:")} ${scriptTransform.rawScriptPersistence ?? "disabled"}`,
539
- );
540
- if (scriptTransform.adapterHome) {
541
- lines.push(` ${themeFg(theme, "muted", "adapterHome:")} ${shortenMiddle(scriptTransform.adapterHome, 90)}`);
542
- }
543
- if (scriptTransform.setupCommand && scriptTransform.adapterStatus !== "available") {
544
- lines.push(` ${themeFg(theme, "muted", "setup:")} ${truncateText(scriptTransform.setupCommand, 140)}`);
545
- }
546
- }
547
-
548
- const processing = report.processing?.unsafeUnsandboxed;
549
- if (processing) {
550
- lines.push("", themeFg(theme, "toolTitle", "Processing"));
551
- lines.push(
552
- ` ${themeFg(theme, "muted", "unsafeUnsandboxed:")} ${processing.enabled ? themeFg(theme, "warning", "enabled unsafe/unsandboxed") : "disabled"}`,
553
- );
554
- lines.push(` ${themeFg(theme, "muted", "source:")} ${processing.source ?? ".freeflow/local.json"}`);
555
- const notes = Array.isArray(processing.notes) ? processing.notes : [];
556
- notes
557
- .slice(0, 2)
558
- .forEach((note) =>
559
- lines.push(` ${themeFg(theme, processing.enabled ? "warning" : "dim", truncateText(note, 180))}`),
560
- );
561
- }
562
-
563
- lines.push("", themeFg(theme, "toolTitle", "Observed routing"));
564
- lines.push(` ${themeFg(theme, "muted", "enabled:")} ${String(Boolean(observedRouting.enabled))}`);
565
- lines.push(` ${themeFg(theme, "muted", "onRoutingFailure:")} ${observedRouting.onRoutingFailure ?? "fail-open"}`);
566
- lines.push(
567
- ` ${themeFg(theme, "muted", "host:")} ${observedRouting.host?.name ?? "pi"} outputReplacement=${observedRouting.host?.outputReplacement ?? "available"}`,
568
- );
569
- lines.push(` ${themeFg(theme, "muted", "mcp servers:")} ${observedRouting.mcp?.configuredServerCount ?? 0}`);
570
- if (observedRouting.web || observedRouting.fetch || observedRouting.codeSearch) {
571
- lines.push(
572
- ` ${themeFg(theme, "muted", "web/fetch/codeSearch:")} web=${observedRouting.web?.enabled ? "on" : "off"} fetch=${observedRouting.fetch?.enabled ? "on" : "off"} codeSearch=${observedRouting.codeSearch?.enabled ? "on" : "off"}`,
573
- );
574
- }
575
-
576
- if (allWarnings.length > 0) {
577
- lines.push("", themeFg(theme, "toolTitle", "Warnings"));
578
- allWarnings
579
- .slice(0, 8)
580
- .forEach((warning) => lines.push(` ${themeFg(theme, "warning", truncateText(warning, 180))}`));
581
- }
582
-
583
- if (recommendations.length > 0) {
584
- lines.push("", themeFg(theme, "toolTitle", "Migration recommendations"));
585
- recommendations
586
- .slice(0, 8)
587
- .forEach((item) =>
588
- lines.push(
589
- ` ${themeFg(theme, "accent", item.path)} ${themeFg(theme, "muted", item.action)} — ${truncateText(item.message, 160)}`,
590
- ),
591
- );
592
- lines.push(
593
- ` ${themeFg(theme, "dim", "No config was rewritten; confirmation is required before applying recommendations.")}`,
594
- );
595
- }
596
-
597
- return textComponent(lines.join("\n"));
598
- }
599
-
600
- export function renderFreeflowSearchResult(result, options: any = {}, theme) {
601
- const routed = routerResultFromToolResult(result);
602
- if (routed?.implementation === "processing-engine-skeleton-v1") {
603
- return renderFreeflowProcessingResult(result, options, theme);
604
- }
605
- if (routed?.routing?.route === "transform") {
606
- return renderFreeflowTransformResult(result, options, theme, "freeflow_search");
607
- }
608
- return renderFreeflowRetrieveResult(result, options, theme, "freeflow_search");
609
- }
610
-
611
- function renderFreeflowProcessingResult(result, { expanded }: any = {}, theme) {
612
- const routed = routerResultFromToolResult(result);
613
- if (!routed) {
614
- return textComponent(fallbackResultText(result));
615
- }
616
- const icon = routed.status === "ok" ? "✓" : routed.status === "blocked" ? "✗" : "!";
617
- const unsafe = routed.script && "policy" in routed.script && routed.script.policy === "unsafe-unsandboxed";
618
- const lines = [
619
- `${themeFg(theme, unsafe ? "warning" : routed.status === "ok" ? "success" : "warning", icon)} ${themeFg(theme, "toolTitle", "freeflow_search")} ${themeFg(theme, "muted", "transform")} • ${formatStatus(theme, routed.status ?? "unknown")}${unsafe ? themeFg(theme, "warning", " • unsafe/unsandboxed") : ""}`,
620
- ];
621
- const visibleLines = splitLines(String(routed.visibleText ?? ""));
622
- visibleLines
623
- .slice(0, expanded ? 20 : 4)
624
- .forEach((line) =>
625
- lines.push(
626
- themeFg(
627
- theme,
628
- unsafe && line.includes("unsafe/unsandboxed") ? "warning" : "toolOutput",
629
- truncateText(line, 160),
630
- ),
631
- ),
632
- );
633
- if (visibleLines.length > (expanded ? 20 : 4)) {
634
- lines.push(themeFg(theme, "dim", `… ${visibleLines.length - (expanded ? 20 : 4)} more line(s)`));
635
- }
636
- if (!expanded) {
637
- lines.push(themeFg(theme, "dim", "ctrl+o to expand transform details and recovery"));
638
- return textComponent(lines.join("\n"));
639
- }
640
- lines.push("", themeFg(theme, "toolTitle", "Source"));
641
- lines.push(` ${themeFg(theme, "accent", routed.source?.displayPath ?? "source")}`);
642
- if (routed.stats) {
643
- lines.push(` ${themeFg(theme, "muted", "stats:")} ${routed.stats.bytes} bytes • ${routed.stats.lines} lines`);
644
- }
645
- if (routed.reducer?.status) {
646
- lines.push("", themeFg(theme, "toolTitle", "Reducer"));
647
- lines.push(` ${routed.reducer.status}${routed.reducer.selected?.name ? ` ${routed.reducer.selected.name}` : ""}`);
648
- }
649
- if (routed.script?.status) {
650
- lines.push("", themeFg(theme, "toolTitle", "Script"));
651
- lines.push(` ${themeFg(theme, "muted", "status:")} ${routed.script.status}`);
652
- if (routed.script.policy) lines.push(` ${themeFg(theme, "muted", "policy:")} ${routed.script.policy}`);
653
- if (routed.script.unsafeUnsandboxed) lines.push(` ${themeFg(theme, "warning", "unsafe/unsandboxed local-yolo")}`);
654
- }
655
- if (routed.recovery?.how) {
656
- lines.push("", themeFg(theme, "toolTitle", "Recovery"));
657
- lines.push(` ${truncateText(routed.recovery.how, 180)}`);
658
- if (routed.recovery.outputId)
659
- lines.push(` ${themeFg(theme, "muted", "outputId:")} ${themeFg(theme, "accent", routed.recovery.outputId)}`);
660
- }
661
- return textComponent(lines.join("\n"));
662
- }
663
-
664
- export function renderFreeflowRetrieveResult(result, { expanded }: any = {}, theme, toolTitle = "freeflow_search") {
665
- const routed = routerResultFromToolResult(result);
666
- if (!routed) {
667
- return textComponent(fallbackResultText(result));
668
- }
669
-
670
- const evidence = Array.isArray(routed.evidence) ? routed.evidence : [];
671
- const firstEvidence = evidence[0];
672
- const icon = statusIcon(routed.toolStatus);
673
- const lines = [
674
- `${themeFg(theme, "success", icon)} ${themeFg(theme, "toolTitle", toolTitle)} ${themeFg(theme, "muted", `${evidence.length} evidence packet(s)`)} • ${routeSummaryLine(theme, routed)}`,
675
- ];
676
-
677
- if (firstEvidence) {
678
- lines.push(
679
- `${themeFg(theme, "accent", evidenceLabel(firstEvidence))}${firstEvidence.expandable ? themeFg(theme, "dim", " • expandable") : ""}`,
680
- );
681
- } else {
682
- lines.push(
683
- themeFg(theme, "warning", truncateText(routed.routing?.reason ?? "No matching evidence returned.", 140)),
684
- );
685
- }
686
-
687
- if (!expanded) {
688
- lines.push(themeFg(theme, "dim", "ctrl+o to expand evidence and recovery details"));
689
- return textComponent(lines.join("\n"));
690
- }
691
-
692
- lines.push("", themeFg(theme, "toolTitle", "Source"));
693
- lines.push(` ${themeFg(theme, "accent", retrieveSourceLabel(routed.source))}`);
694
- if (routed.preserve) {
695
- lines.push(` ${themeFg(theme, "muted", "preserve:")} ${routed.preserve}`);
696
- }
697
-
698
- appendStorageSection(lines, theme, routed, routed.outputId || routed.recovery?.outputId);
699
-
700
- lines.push("", themeFg(theme, "toolTitle", "Routing"));
701
- lines.push(` ${themeFg(theme, "muted", "toolStatus:")} ${formatStatus(theme, routed.toolStatus)}`);
702
- lines.push(` ${themeFg(theme, "muted", "routing.status:")} ${formatStatus(theme, routed.routing?.status)}`);
703
- lines.push(` ${themeFg(theme, "muted", "route:")} ${routed.routing?.route ?? "retrieve"}`);
704
- if (routed.routing?.reason) {
705
- lines.push(` ${themeFg(theme, "muted", "reason:")} ${truncateText(routed.routing.reason, 160)}`);
706
- }
707
-
708
- lines.push("", themeFg(theme, "toolTitle", "Evidence"));
709
- if (evidence.length === 0) {
710
- lines.push(` ${themeFg(theme, "dim", "No evidence packets returned.")}`);
711
- } else {
712
- evidence.forEach((packet, index) => {
713
- lines.push(
714
- ` ${themeFg(theme, "accent", `#${index + 1} ${evidenceLabel(packet)}`)} ${themeFg(theme, "dim", `window=${packet.window}`)}`,
715
- );
716
- if (packet.id) {
717
- lines.push(` ${themeFg(theme, "muted", "evidenceId:")} ${themeFg(theme, "accent", packet.id)}`);
718
- }
719
- if (packet.source) {
720
- lines.push(` ${themeFg(theme, "muted", "source:")} ${evidenceSourceSummary(packet.source)}`);
721
- }
722
- if (packet.expandable !== undefined) {
723
- lines.push(` ${themeFg(theme, "muted", "expandable:")} ${String(Boolean(packet.expandable))}`);
724
- }
725
- const exactHint = exactRetrieveHintFromEvidence(packet);
726
- if (exactHint) {
727
- lines.push(` ${themeFg(theme, "muted", "exact search:")} ${exactHint}`);
728
- }
729
- if (packet.why) {
730
- lines.push(` ${themeFg(theme, "muted", "why:")} ${truncateText(packet.why, 160)}`);
731
- }
732
- lines.push(...excerptLines(theme, packet.excerpt, " ", 8));
733
- });
734
- }
735
-
736
- if (routed.recovery?.how) {
737
- lines.push("", themeFg(theme, "toolTitle", "Recovery"));
738
- lines.push(` ${truncateText(routed.recovery.how, 180)}`);
739
- if (routed.recovery.outputId) {
740
- lines.push(` ${themeFg(theme, "muted", "outputId:")} ${themeFg(theme, "accent", routed.recovery.outputId)}`);
741
- }
742
- const exactHint = firstExactRetrieveHintFromEvidence(evidence);
743
- if (exactHint) {
744
- lines.push(` ${themeFg(theme, "muted", "exact search:")} ${exactHint}`);
745
- } else if (routed.recovery.outputId) {
746
- lines.push(
747
- ` ${themeFg(theme, "muted", "recovery starting point:")} ${recoveryStartingPoint(routed.recovery.outputId)}`,
748
- );
749
- }
750
- if (routed.recovery.evidenceId) {
751
- lines.push(` ${themeFg(theme, "muted", "evidenceId:")} ${themeFg(theme, "accent", routed.recovery.evidenceId)}`);
752
- lines.push(
753
- ` ${themeFg(theme, "muted", "expand hint:")} freeflow_search action=expand evidenceId=${routed.recovery.evidenceId}`,
754
- );
755
- }
756
- }
757
-
758
- return textComponent(lines.join("\n"));
759
- }
760
-
761
- export function renderFreeflowRunResult(result, { expanded }: any = {}, theme, context: any = {}) {
762
- const routed = routerResultFromToolResult(result);
763
- if (!routed) {
764
- return textComponent(fallbackResultText(result));
765
- }
766
-
767
- const executionStatus = routed.execution?.status ?? routed.toolStatus;
768
- const outputId = routed.outputId;
769
- const exactRecoveryOutputId = routed.persistence?.recoverability === "exact" ? outputId : routed.recovery?.outputId;
770
- const icon = statusIcon(executionStatus);
771
- const importantLines = Array.isArray(routed.importantLines) ? routed.importantLines : [];
772
- const lines = [
773
- `${themeFg(theme, executionStatus === "failed" ? "error" : "success", icon)} ${themeFg(theme, "toolTitle", "freeflow_run")} ${themeFg(theme, "muted", "execution:")} ${formatStatus(theme, executionStatus)} • ${routeSummaryLine(theme, routed)}`,
774
- ];
775
-
776
- const statusParts = [];
777
- if (routed.execution?.exitCode !== undefined && routed.execution?.exitCode !== null) {
778
- statusParts.push(`exit ${routed.execution.exitCode}`);
779
- }
780
- if (routed.execution?.durationMs !== undefined) {
781
- statusParts.push(`${routed.execution.durationMs}ms`);
782
- }
783
- if (outputId) {
784
- statusParts.push(
785
- `${routed.persistence?.recoverability === "metadata_only" ? "metadataId" : "outputId"} ${outputId}`,
786
- );
787
- }
788
- if (exactRecoveryOutputId && exactRecoveryOutputId !== outputId) {
789
- statusParts.push(`exact ${exactRecoveryOutputId}`);
790
- }
791
- if (routed.scriptFilter?.outputId) {
792
- statusParts.push(`transformed ${routed.scriptFilter.outputId}`);
793
- }
794
- if (routed.reducer?.outputId) {
795
- statusParts.push(`reduced ${routed.reducer.outputId}`);
796
- }
797
- if (routed.parser?.name) {
798
- statusParts.push(`parser ${routed.parser.name} ${Number(routed.parser.confidence ?? 0).toFixed(2)}`);
799
- }
800
- if (statusParts.length > 0) {
801
- lines.push(themeFg(theme, "accent", statusParts.join(" • ")));
802
- }
803
- if (routed.summary) {
804
- lines.push(themeFg(theme, "muted", truncateText(routed.summary, 140)));
805
- }
806
- lines.push(
807
- themeFg(
808
- theme,
809
- "dim",
810
- `${importantLines.length} important span(s) • ${exactRecoveryOutputId ? (routed.scriptFilter?.outputId ? "raw and script output recoverable from vault" : routed.reducer?.outputId ? "raw and reducer output recoverable from vault" : "raw output recoverable from vault") : "metadata-only record; exact raw output not vaulted"}`,
811
- ),
812
- );
813
-
814
- if (!expanded) {
815
- lines.push(themeFg(theme, "dim", "ctrl+o to expand status, evidence, and vault recovery"));
816
- return textComponent(lines.join("\n"));
817
- }
818
-
819
- lines.push("", themeFg(theme, "toolTitle", context.args?.script ? "Producer script" : "Command"));
820
- lines.push(` ${themeFg(theme, "accent", runProducerLabel(context.args))}`);
821
-
822
- lines.push("", themeFg(theme, "toolTitle", "Status"));
823
- lines.push(` ${themeFg(theme, "muted", "toolStatus:")} ${formatStatus(theme, routed.toolStatus)}`);
824
- lines.push(` ${themeFg(theme, "muted", "execution.status:")} ${formatStatus(theme, routed.execution?.status)}`);
825
- lines.push(` ${themeFg(theme, "muted", "routing.status:")} ${formatStatus(theme, routed.routing?.status)}`);
826
- if (routed.execution?.exitCode !== undefined) {
827
- lines.push(` ${themeFg(theme, "muted", "exitCode:")} ${routed.execution.exitCode}`);
828
- }
829
- if (routed.execution?.durationMs !== undefined) {
830
- lines.push(` ${themeFg(theme, "muted", "durationMs:")} ${routed.execution.durationMs}`);
831
- }
832
-
833
- appendStorageSection(lines, theme, routed, outputId);
834
-
835
- if (routed.routing?.reason || routed.summary) {
836
- lines.push("", themeFg(theme, "toolTitle", "Routing"));
837
- if (routed.summary) {
838
- lines.push(` ${themeFg(theme, "muted", "summary:")} ${truncateText(routed.summary, 160)}`);
839
- }
840
- if (routed.routing?.reason) {
841
- lines.push(` ${themeFg(theme, "muted", "reason:")} ${truncateText(routed.routing.reason, 180)}`);
842
- }
843
- }
844
-
845
- if (routed.filters) {
846
- lines.push("", themeFg(theme, "toolTitle", "Filters"));
847
- lines.push(` ${truncateText(runFilterLabel(routed.filters), 220)}`);
848
- }
849
-
850
- if (routed.scriptProducer) {
851
- lines.push("", themeFg(theme, "toolTitle", "Script producer"));
852
- lines.push(` ${truncateText(runScriptProducerLabel(routed.scriptProducer), 220)}`);
853
- if (routed.scriptProducer.operation) {
854
- lines.push(
855
- ` ${themeFg(theme, "muted", "operation:")} ${truncateText(JSON.stringify(routed.scriptProducer.operation), 180)}`,
856
- );
857
- }
858
- if (routed.scriptProducer.failure?.message) {
859
- lines.push(` ${themeFg(theme, "warning", truncateText(routed.scriptProducer.failure.message, 180))}`);
860
- }
861
- }
862
-
863
- if (routed.reducer) {
864
- lines.push("", themeFg(theme, "toolTitle", "Reducer"));
865
- lines.push(
866
- ` ${routed.reducer.name}@${routed.reducer.version} confidence=${Number(routed.reducer.confidence ?? 0).toFixed(2)} status=${routed.reducer.status}`,
867
- );
868
- if (routed.reducer.rawOutputId) {
869
- lines.push(
870
- ` ${themeFg(theme, "muted", "rawOutputId:")} ${themeFg(theme, "accent", routed.reducer.rawOutputId)}`,
871
- );
872
- }
873
- if (routed.reducer.outputId) {
874
- lines.push(` ${themeFg(theme, "muted", "outputId:")} ${themeFg(theme, "accent", routed.reducer.outputId)}`);
875
- }
876
- if (Array.isArray(routed.reducer.facts) && routed.reducer.facts.length > 0) {
877
- lines.push(` ${themeFg(theme, "muted", "facts:")} ${truncateText(JSON.stringify(routed.reducer.facts), 220)}`);
878
- }
879
- }
880
-
881
- if (routed.scriptFilter) {
882
- lines.push("", themeFg(theme, "toolTitle", "Script filter"));
883
- lines.push(` ${truncateText(runScriptFilterLabel(routed.scriptFilter), 220)}`);
884
- if (routed.scriptFilter.rawOutputId) {
885
- lines.push(
886
- ` ${themeFg(theme, "muted", "rawOutputId:")} ${themeFg(theme, "accent", routed.scriptFilter.rawOutputId)}`,
887
- );
888
- }
889
- if (Array.isArray(routed.scriptFilter.sourceAliases)) {
890
- lines.push(` ${themeFg(theme, "muted", "sources:")} ${routed.scriptFilter.sourceAliases.join(", ")}`);
891
- }
892
- if (routed.scriptFilter.operation) {
893
- lines.push(
894
- ` ${themeFg(theme, "muted", "operation:")} ${truncateText(JSON.stringify(routed.scriptFilter.operation), 180)}`,
895
- );
896
- }
897
- if (routed.scriptFilter.failure?.message) {
898
- lines.push(` ${themeFg(theme, "warning", truncateText(routed.scriptFilter.failure.message, 180))}`);
899
- }
900
- }
901
-
902
- if (routed.parser?.name) {
903
- lines.push("", themeFg(theme, "toolTitle", "Parser"));
904
- lines.push(` ${themeFg(theme, "muted", "name:")} ${routed.parser.name}`);
905
- lines.push(` ${themeFg(theme, "muted", "confidence:")} ${Number(routed.parser.confidence ?? 0).toFixed(2)}`);
906
- lines.push(` ${themeFg(theme, "muted", "fidelity:")} ${routed.parser.fidelity ?? "exact"}`);
907
- lines.push(` ${themeFg(theme, "muted", "compressed:")} ${String(Boolean(routed.parser.compressed))}`);
908
- if (routed.parser.counts && Object.keys(routed.parser.counts).length > 0) {
909
- lines.push(` ${themeFg(theme, "muted", "counts:")} ${truncateText(JSON.stringify(routed.parser.counts), 160)}`);
910
- }
911
- if (Array.isArray(routed.parser.references) && routed.parser.references.length > 0) {
912
- const refs = routed.parser.references
913
- .slice(0, 3)
914
- .map(
915
- (ref) =>
916
- `${ref.path}${ref.line ? `:${ref.line}${ref.column ? `:${ref.column}` : ""}` : ""}${ref.code ? ` ${ref.code}` : ""}`,
917
- );
918
- lines.push(` ${themeFg(theme, "muted", "references:")} ${truncateText(refs.join(", "), 180)}`);
919
- }
920
- }
921
-
922
- lines.push("", themeFg(theme, "toolTitle", "Evidence"));
923
- if (importantLines.length === 0) {
924
- lines.push(` ${themeFg(theme, "dim", "No important lines selected.")}`);
925
- } else {
926
- importantLines.forEach((line, index) => {
927
- lines.push(` ${themeFg(theme, "accent", `#${index + 1} ${line.stream} lines ${line.lines}`)}`);
928
- lines.push(...excerptLines(theme, line.excerpt, " ", 8));
929
- });
930
- }
931
-
932
- if (routed.recovery?.how || outputId) {
933
- lines.push("", themeFg(theme, "toolTitle", "Vault recovery"));
934
- if (outputId) {
935
- lines.push(` ${themeFg(theme, "muted", "outputId:")} ${themeFg(theme, "accent", outputId)}`);
936
- }
937
- if (routed.recovery?.how) {
938
- lines.push(` ${truncateText(routed.recovery.how, 180)}`);
939
- }
940
- const evidenceOutputId = routed.scriptFilter?.outputId ?? routed.reducer?.outputId ?? exactRecoveryOutputId;
941
- const exactHint = exactRetrieveHintFromImportantLines(evidenceOutputId, importantLines);
942
- if (exactHint) {
943
- const hint =
944
- routed.scriptFilter?.outputId || routed.reducer?.outputId
945
- ? exactHint.replace(/stream=(stdout|stderr|combined)/, "stream=raw")
946
- : exactHint;
947
- lines.push(` ${themeFg(theme, "muted", "exact search:")} ${hint}`);
948
- if ((routed.scriptFilter?.outputId || routed.reducer?.outputId) && outputId) {
949
- lines.push(` ${themeFg(theme, "muted", "raw command starting point:")} ${recoveryStartingPoint(outputId)}`);
950
- }
951
- } else if (exactRecoveryOutputId) {
952
- lines.push(
953
- ` ${themeFg(theme, "muted", "recovery starting point:")} ${recoveryStartingPoint(exactRecoveryOutputId)}`,
954
- );
955
- }
956
- lines.push(` ${themeFg(theme, "dim", "Full structured result remains available in details.result.")}`);
957
- }
958
-
959
- return textComponent(lines.join("\n"));
960
- }
961
-
962
- export function renderFreeflowTransformResult(
963
- result,
964
- { expanded }: any = {},
965
- theme,
966
- toolTitle = "freeflow_search action=transform",
967
- ) {
968
- const routed = routerResultFromToolResult(result);
969
- if (!routed) {
970
- return textComponent(fallbackResultText(result));
971
- }
972
-
973
- const outputId = routed.outputId || routed.recovery?.outputId;
974
- const operation = transformOperationLabel(routed.operation ?? { kind: routed.producer?.name });
975
- const failed = routed.failure || routed.toolStatus === "error" || routed.routing?.status === "failed";
976
- const icon = failed ? "✗" : statusIcon(routed.toolStatus);
977
- const evidence = Array.isArray(routed.evidence) ? routed.evidence : [];
978
- const sourceLabel = retrieveSourceLabel(routed.source);
979
- const lines = [
980
- `${themeFg(theme, failed ? "error" : "success", icon)} ${themeFg(theme, "toolTitle", toolTitle)} ${themeFg(theme, "accent", operation)} • ${routeSummaryLine(theme, routed)}`,
981
- ];
982
-
983
- const statusParts = [];
984
- if (outputId) {
985
- statusParts.push(`outputId ${outputId}`);
986
- }
987
- if (routed.recordId) {
988
- statusParts.push(`recordId ${routed.recordId}`);
989
- }
990
- if (routed.persistence?.status) {
991
- statusParts.push(`persistence ${routed.persistence.status}/${routed.persistence.recoverability}`);
992
- }
993
- if (routed.source?.outputId) {
994
- statusParts.push(`source ${routed.source.outputId}${routed.source.stream ? `:${routed.source.stream}` : ""}`);
995
- }
996
- if (statusParts.length > 0) {
997
- lines.push(themeFg(theme, "accent", statusParts.join(" • ")));
998
- }
999
-
1000
- if (routed.failure?.message) {
1001
- lines.push(themeFg(theme, "warning", `${routed.failure.kind}: ${truncateText(routed.failure.message, 140)}`));
1002
- } else if (routed.summary) {
1003
- lines.push(themeFg(theme, "muted", truncateText(routed.summary, 140)));
1004
- }
1005
- lines.push(
1006
- themeFg(
1007
- theme,
1008
- "dim",
1009
- `${evidence.length} evidence packet(s)${outputId ? " • transformed output recoverable from vault" : ""}`,
1010
- ),
1011
- );
1012
-
1013
- if (!expanded) {
1014
- lines.push(themeFg(theme, "dim", "ctrl+o to expand source, operation, lineage, evidence, and recovery details"));
1015
- return textComponent(lines.join("\n"));
1016
- }
1017
-
1018
- lines.push("", themeFg(theme, "toolTitle", "Status"));
1019
- lines.push(` ${themeFg(theme, "muted", "toolStatus:")} ${formatStatus(theme, routed.toolStatus)}`);
1020
- if (routed.transformExecution?.status) {
1021
- lines.push(
1022
- ` ${themeFg(theme, "muted", "transformExecution.status:")} ${formatStatus(theme, routed.transformExecution.status)}`,
1023
- );
1024
- }
1025
- lines.push(` ${themeFg(theme, "muted", "routing.status:")} ${formatStatus(theme, routed.routing?.status)}`);
1026
- if (routed.persistence?.status) {
1027
- lines.push(
1028
- ` ${themeFg(theme, "muted", "persistence:")} ${routed.persistence.status} / ${routed.persistence.recoverability}`,
1029
- );
1030
- }
1031
- if (routed.routing?.reason) {
1032
- lines.push(` ${themeFg(theme, "muted", "reason:")} ${truncateText(routed.routing.reason, 180)}`);
1033
- }
1034
-
1035
- appendStorageSection(lines, theme, routed, outputId);
1036
-
1037
- lines.push("", themeFg(theme, "toolTitle", "Source"));
1038
- lines.push(` ${themeFg(theme, "accent", sourceLabel)}`);
1039
-
1040
- lines.push("", themeFg(theme, "toolTitle", "Operation"));
1041
- if (routed.operation) {
1042
- lines.push(` ${truncateText(JSON.stringify(routed.operation), 220)}`);
1043
- } else {
1044
- lines.push(` ${themeFg(theme, "dim", operation)}`);
1045
- }
1046
-
1047
- if (routed.lineage) {
1048
- lines.push("", themeFg(theme, "toolTitle", "Lineage"));
1049
- if (Array.isArray(routed.lineage.sourceOutputIds)) {
1050
- lines.push(` ${themeFg(theme, "muted", "sourceOutputIds:")} ${routed.lineage.sourceOutputIds.join(", ")}`);
1051
- }
1052
- if (Array.isArray(routed.lineage.sourceRecordIds)) {
1053
- lines.push(` ${themeFg(theme, "muted", "sourceRecordIds:")} ${routed.lineage.sourceRecordIds.join(", ")}`);
1054
- }
1055
- if (routed.lineage.operation) {
1056
- lines.push(` ${themeFg(theme, "muted", "operation:")} ${routed.lineage.operation}`);
1057
- }
1058
- if (routed.lineage.operationHash) {
1059
- lines.push(` ${themeFg(theme, "muted", "operationHash:")} ${shortenMiddle(routed.lineage.operationHash, 80)}`);
1060
- }
1061
- }
1062
-
1063
- lines.push("", themeFg(theme, "toolTitle", "Evidence"));
1064
- if (evidence.length === 0) {
1065
- lines.push(` ${themeFg(theme, "dim", "No evidence packets returned.")}`);
1066
- } else {
1067
- evidence.forEach((packet, index) => {
1068
- lines.push(
1069
- ` ${themeFg(theme, "accent", `#${index + 1} ${evidenceLabel(packet)}`)} ${themeFg(theme, "dim", `window=${packet.window}`)}`,
1070
- );
1071
- if (packet.id) {
1072
- lines.push(` ${themeFg(theme, "muted", "evidenceId:")} ${themeFg(theme, "accent", packet.id)}`);
1073
- }
1074
- if (packet.source) {
1075
- lines.push(` ${themeFg(theme, "muted", "source:")} ${evidenceSourceSummary(packet.source)}`);
1076
- }
1077
- if (packet.expandable !== undefined) {
1078
- lines.push(` ${themeFg(theme, "muted", "expandable:")} ${String(Boolean(packet.expandable))}`);
1079
- }
1080
- const exactHint = exactRetrieveHintFromEvidence(packet);
1081
- if (exactHint) {
1082
- lines.push(` ${themeFg(theme, "muted", "exact search:")} ${exactHint}`);
1083
- }
1084
- if (packet.why) {
1085
- lines.push(` ${themeFg(theme, "muted", "why:")} ${truncateText(packet.why, 160)}`);
1086
- }
1087
- lines.push(...excerptLines(theme, packet.excerpt, " ", 8));
1088
- });
1089
- }
1090
-
1091
- if (routed.recovery?.how || outputId) {
1092
- lines.push("", themeFg(theme, "toolTitle", "Recovery"));
1093
- if (outputId) {
1094
- lines.push(` ${themeFg(theme, "muted", "outputId:")} ${themeFg(theme, "accent", outputId)}`);
1095
- }
1096
- if (routed.recovery?.how) {
1097
- lines.push(` ${truncateText(routed.recovery.how, 180)}`);
1098
- }
1099
- const exactHint = firstExactRetrieveHintFromEvidence(evidence);
1100
- if (exactHint) {
1101
- lines.push(` ${themeFg(theme, "muted", "exact search:")} ${exactHint}`);
1102
- } else if (outputId) {
1103
- lines.push(` ${themeFg(theme, "muted", "recovery starting point:")} ${recoveryStartingPoint(outputId)}`);
1104
- }
1105
- }
1106
-
1107
- return textComponent(lines.join("\n"));
1108
- }