@hassangameryt/freeflow 0.7.2 → 0.8.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 (267) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/.codex-plugin/plugin.json +1 -1
  4. package/.cursor-plugin/plugin.json +1 -1
  5. package/NOTICE +14 -0
  6. package/README.md +151 -136
  7. package/capabilities/cognitive-routing/SKILL.md +110 -96
  8. package/capabilities/cognitive-routing/references/both-mode.md +36 -0
  9. package/capabilities/cognitive-routing/references/executor-mode.md +48 -0
  10. package/capabilities/cognitive-routing/references/helper-mode.md +47 -0
  11. package/capabilities/compaction/SKILL.md +49 -0
  12. package/capabilities/compaction/references/summary-format.md +239 -0
  13. package/command-surface.json +4 -0
  14. package/gemini-extension.json +1 -1
  15. package/hooks/shared/runtime-context.mjs +28 -30
  16. package/licenses/Apache-2.0.txt +55 -0
  17. package/package.json +22 -9
  18. package/pi-extension/README.md +41 -0
  19. package/pi-extension/dist/cognitive-routing/assembler.js +393 -0
  20. package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/config.js +40 -21
  21. package/pi-extension/dist/cognitive-routing/economics.js +45 -0
  22. package/pi-extension/dist/cognitive-routing/event-schema.js +388 -0
  23. package/pi-extension/dist/cognitive-routing/event-store.js +280 -0
  24. package/pi-extension/dist/cognitive-routing/gate.js +241 -0
  25. package/pi-extension/dist/cognitive-routing/handlers.js +899 -0
  26. package/pi-extension/dist/cognitive-routing/handoffs.js +350 -0
  27. package/pi-extension/dist/cognitive-routing/model-control.js +467 -0
  28. package/pi-extension/dist/cognitive-routing/projection.js +503 -0
  29. package/pi-extension/dist/cognitive-routing/provenance.js +81 -0
  30. package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/render.js +31 -10
  31. package/pi-extension/dist/cognitive-routing/runtime.js +396 -0
  32. package/pi-extension/dist/cognitive-routing/schemas.js +209 -0
  33. package/pi-extension/dist/cognitive-routing/session.js +221 -0
  34. package/pi-extension/dist/cognitive-routing/sources.js +291 -0
  35. package/pi-extension/dist/cognitive-routing/state.js +487 -0
  36. package/pi-extension/dist/cognitive-routing/status.js +80 -0
  37. package/pi-extension/dist/cognitive-routing/tools.js +60 -0
  38. package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/types.js +10 -12
  39. package/pi-extension/dist/compaction/carry.js +191 -0
  40. package/pi-extension/dist/compaction/config.js +22 -0
  41. package/pi-extension/dist/compaction/controller.js +471 -0
  42. package/pi-extension/dist/compaction/harness.js +77 -0
  43. package/pi-extension/dist/compaction/results.js +158 -0
  44. package/pi-extension/dist/compaction/thresholds.js +35 -0
  45. package/pi-extension/dist/compaction/tool.js +57 -0
  46. package/pi-extension/dist/host/branch.js +13 -0
  47. package/pi-extension/dist/host/canonical.js +12 -0
  48. package/pi-extension/dist/host/catalog.js +77 -0
  49. package/pi-extension/dist/host/config.js +374 -0
  50. package/pi-extension/dist/host/projection-tags.js +60 -0
  51. package/pi-extension/dist/host/prompts.js +82 -0
  52. package/pi-extension/dist/{session-sources → host}/read-only-session.js +112 -1
  53. package/pi-extension/dist/host/request-history.js +298 -0
  54. package/pi-extension/dist/host/runtime-state.js +189 -0
  55. package/pi-extension/dist/host/settings/freeflow-command.js +1570 -0
  56. package/pi-extension/dist/{settings/settings-tui.js → host/settings/settings-view.js} +186 -73
  57. package/pi-extension/dist/host/staging.js +28 -0
  58. package/pi-extension/dist/host/status.js +101 -0
  59. package/pi-extension/dist/index.js +441 -170
  60. package/pi-extension/dist/provider-support/cache/anchor.js +21 -0
  61. package/pi-extension/dist/provider-support/cache/anthropic.js +102 -0
  62. package/pi-extension/dist/provider-support/cache/health.js +73 -0
  63. package/pi-extension/dist/provider-support/cache/index.js +58 -0
  64. package/pi-extension/dist/provider-support/cache/keepalive.js +210 -0
  65. package/pi-extension/dist/provider-support/cache/monitor.js +17 -0
  66. package/pi-extension/dist/provider-support/cache/openai-responses.js +48 -0
  67. package/pi-extension/dist/provider-support/effort.js +13 -0
  68. package/pi-extension/dist/provider-support/index.js +45 -0
  69. package/pi-extension/dist/provider-support/openai/adapter.js +127 -0
  70. package/pi-extension/dist/provider-support/openai/history.js +127 -0
  71. package/pi-extension/dist/provider-support/openai/index.js +15 -0
  72. package/pi-extension/dist/provider-support/openai/session-state.js +105 -0
  73. package/pi-extension/dist/provider-support/routes.js +17 -0
  74. package/pi-extension/dist/tool-execution/apply-patch/grammar.js +23 -0
  75. package/pi-extension/dist/tool-execution/apply-patch/match.js +38 -0
  76. package/pi-extension/dist/tool-execution/apply-patch/parser.js +177 -0
  77. package/pi-extension/dist/tool-execution/apply-patch/plan.js +201 -0
  78. package/pi-extension/dist/tool-execution/apply-patch/tool.js +84 -0
  79. package/pi-extension/dist/tool-execution/background.js +238 -0
  80. package/pi-extension/dist/tool-execution/bash-guard.js +23 -0
  81. package/pi-extension/dist/tool-execution/config.js +22 -0
  82. package/pi-extension/dist/tool-execution/edit-messages.js +120 -0
  83. package/pi-extension/dist/tool-execution/file-state.js +138 -0
  84. package/pi-extension/dist/tool-execution/file-tracking.js +143 -0
  85. package/pi-extension/dist/tool-execution/prompt.js +54 -0
  86. package/pi-extension/dist/tool-execution/tools.js +16 -0
  87. package/pi-extension/freeflow/README.md +9 -0
  88. package/plugin.json +1 -1
  89. package/runtime/prompts/cognitive-routing.md +4 -4
  90. package/runtime/prompts/core.md +22 -75
  91. package/runtime/prompts/interaction-contract.md +15 -8
  92. package/runtime/prompts/tool-execution.md +38 -0
  93. package/runtime/prompts/working-method.md +108 -0
  94. package/skills/action-selection/SKILL.md +39 -47
  95. package/skills/action-selection/references/trajectory-stalls.md +2 -0
  96. package/skills/bypass/SKILL.md +2 -2
  97. package/skills/commit-work/SKILL.md +31 -83
  98. package/skills/commit-work/references/git-state-edges.md +1 -1
  99. package/skills/commit-work/references/simple-push.md +2 -0
  100. package/skills/commit-work/references/staging-decisions.md +1 -1
  101. package/skills/decision-gate/SKILL.md +31 -50
  102. package/skills/design-for-depth/SKILL.md +44 -53
  103. package/skills/design-for-depth/references/design-pressure-signals.md +46 -144
  104. package/skills/design-for-depth/references/implementation-decisions.md +4 -4
  105. package/skills/design-for-depth/references/interface-design-loop.md +5 -36
  106. package/skills/design-for-depth/references/module-and-dependency-design.md +2 -32
  107. package/skills/design-for-depth/references/state-and-failure-boundaries.md +2 -13
  108. package/skills/diagnose-failure/SKILL.md +39 -24
  109. package/skills/diagnose-failure/references/diagnostic-loop-catalog.md +2 -0
  110. package/skills/diagnose-failure/references/flaky-and-performance-diagnosis.md +2 -2
  111. package/skills/discuss/SKILL.md +37 -13
  112. package/skills/discuss/references/discussion-continuity.md +7 -27
  113. package/skills/evaluate-skill/SKILL.md +49 -80
  114. package/skills/evaluate-skill/references/evaluation-definition-schema.md +35 -5
  115. package/skills/evaluate-skill/references/evaluation-design.md +14 -14
  116. package/skills/evaluate-skill/references/execution-and-evidence.md +26 -5
  117. package/skills/evaluate-skill/references/review-and-revision.md +3 -1
  118. package/skills/evaluate-skill/scripts/lib/definitions.mjs +49 -8
  119. package/skills/evaluate-skill/scripts/lib/pi.mjs +14 -7
  120. package/skills/evaluate-skill/scripts/lib/review.mjs +196 -0
  121. package/skills/evaluate-skill/scripts/lib/runner.mjs +45 -8
  122. package/skills/evaluate-skill/scripts/lib/sandbox.mjs +2 -0
  123. package/skills/evaluate-skill/scripts/lib/trials.mjs +103 -0
  124. package/skills/evaluate-skill/scripts/lib/view.mjs +67 -1
  125. package/skills/evaluate-skill/scripts/pi-command-tool.mjs +144 -0
  126. package/skills/evaluate-skill/scripts/pi-guard.mjs +30 -13
  127. package/skills/evaluate-skill/scripts/skill-eval.mjs +114 -34
  128. package/skills/execute-work/SKILL.md +41 -9
  129. package/skills/execute-work/references/code-practices.md +2 -0
  130. package/skills/execute-work/references/execute-work-edges.md +11 -1
  131. package/skills/handoff/SKILL.md +1 -1
  132. package/skills/handoff/references/handoff-templates.md +1 -1
  133. package/skills/review-artifact/SKILL.md +42 -41
  134. package/skills/review-artifact/references/adjudicate-artifact-review.md +1 -1
  135. package/skills/review-artifact/references/independent-artifact-reviewer-contract.md +1 -1
  136. package/skills/review-work/SKILL.md +38 -32
  137. package/skills/review-work/references/adjudicate-work-review.md +1 -1
  138. package/skills/review-work/references/independent-work-reviewer-contract.md +1 -1
  139. package/skills/review-work/references/security-risk-lens.md +2 -4
  140. package/skills/setup-freeflow/SKILL.md +3 -1
  141. package/skills/setup-freeflow/references/activation-contract.md +7 -13
  142. package/skills/setup-freeflow/references/host-setup.md +3 -3
  143. package/skills/track-work/SKILL.md +113 -161
  144. package/skills/track-work/references/working-record-format.md +189 -350
  145. package/skills/track-work/scripts/lib/document.mjs +62 -6
  146. package/skills/track-work/scripts/lib/format.mjs +16 -1
  147. package/skills/track-work/scripts/lib/store.mjs +9 -8
  148. package/skills/track-work/scripts/lib/transitions.mjs +79 -4
  149. package/skills/track-work/scripts/working-record.mjs +34 -12
  150. package/skills/verify-work/SKILL.md +29 -20
  151. package/skills/verify-work/references/browser-runtime-evidence.md +1 -5
  152. package/skills/verify-work/references/integration-evidence.md +2 -0
  153. package/skills/verify-work/references/performance-evidence.md +3 -1
  154. package/skills/verify-work/references/test-design.md +3 -1
  155. package/skills/workflow/SKILL.md +65 -21
  156. package/skills/workflow/references/domain-skill-composition.md +5 -3
  157. package/skills/write-docs/SKILL.md +83 -0
  158. package/skills/write-docs/references/documentation-shapes.md +119 -0
  159. package/skills/write-docs/scripts/docs-check.mjs +139 -0
  160. package/skills/write-plan/SKILL.md +40 -40
  161. package/skills/write-plan/references/plan-shapes.md +1 -1
  162. package/skills/write-skill/SKILL.md +107 -147
  163. package/skills/write-skill/references/activation-boundaries.md +2 -0
  164. package/skills/write-skill/references/agent-first-instructions.md +22 -10
  165. package/skills/write-skill/references/progressive-disclosure.md +4 -2
  166. package/skills/write-skill/references/skill-dependency-graphs.md +2 -0
  167. package/skills/write-skill/scripts/lib/similarity.mjs +56 -0
  168. package/skills/write-skill/scripts/skill-author.mjs +18 -2
  169. package/skills/write-spec/SKILL.md +34 -41
  170. package/skills/write-spec/references/artifact-standards.md +1 -1
  171. package/skills/write-spec/references/decision-records.md +2 -0
  172. package/skills/write-spec/references/spec-shapes.md +1 -1
  173. package/capabilities/context-virtualization/SKILL.md +0 -103
  174. package/capabilities/conversation-history/SKILL.md +0 -53
  175. package/hooks/tests/check-host-adapters.test.mjs +0 -82
  176. package/hooks/tests/check-runtime-context-hook.sh +0 -212
  177. package/pi-extension/dist/cognitive-routing-v2/projection.js +0 -321
  178. package/pi-extension/dist/cognitive-routing-v2/runtime.js +0 -1585
  179. package/pi-extension/dist/cognitive-routing-v2/schemas.js +0 -107
  180. package/pi-extension/dist/cognitive-routing-v2/state.js +0 -612
  181. package/pi-extension/dist/cognitive-routing-v2/tools.js +0 -91
  182. package/pi-extension/dist/context-virtualization/commands.js +0 -89
  183. package/pi-extension/dist/context-virtualization/projector.js +0 -42
  184. package/pi-extension/dist/context-virtualization/runtime.js +0 -356
  185. package/pi-extension/dist/context-virtualization/state.js +0 -57
  186. package/pi-extension/dist/context-virtualization/types.js +0 -10
  187. package/pi-extension/dist/conversation-history/passages.js +0 -66
  188. package/pi-extension/dist/conversation-history/ranking.js +0 -105
  189. package/pi-extension/dist/conversation-history/runtime.js +0 -226
  190. package/pi-extension/dist/conversation-history/search.js +0 -56
  191. package/pi-extension/dist/conversation-history/types.js +0 -1
  192. package/pi-extension/dist/freeflow-context/resolver.js +0 -120
  193. package/pi-extension/dist/freeflow-context/runtime.js +0 -80
  194. package/pi-extension/dist/freeflow-context/source-projector.js +0 -95
  195. package/pi-extension/dist/freeflow-context/tool.js +0 -313
  196. package/pi-extension/dist/freeflow-context/types.js +0 -12
  197. package/pi-extension/dist/freeflow-context/visibility.js +0 -28
  198. package/pi-extension/dist/integrations/mcp-config.js +0 -29
  199. package/pi-extension/dist/runtime/runtime-context.js +0 -735
  200. package/pi-extension/dist/runtime/runtime-identity.js +0 -5
  201. package/pi-extension/dist/session-sources/events.js +0 -195
  202. package/pi-extension/dist/session-sources/sources.js +0 -233
  203. package/pi-extension/dist/settings/settings-ui.js +0 -1160
  204. package/pi-extension/dist/ui/text-component.js +0 -57
  205. package/pi-extension/src/cognitive-routing-v2/budget.ts +0 -42
  206. package/pi-extension/src/cognitive-routing-v2/config.ts +0 -143
  207. package/pi-extension/src/cognitive-routing-v2/projection.ts +0 -365
  208. package/pi-extension/src/cognitive-routing-v2/render.ts +0 -256
  209. package/pi-extension/src/cognitive-routing-v2/runtime.ts +0 -1634
  210. package/pi-extension/src/cognitive-routing-v2/schemas.ts +0 -109
  211. package/pi-extension/src/cognitive-routing-v2/state.ts +0 -622
  212. package/pi-extension/src/cognitive-routing-v2/tools.ts +0 -93
  213. package/pi-extension/src/cognitive-routing-v2/types.ts +0 -222
  214. package/pi-extension/src/context-virtualization/commands.ts +0 -111
  215. package/pi-extension/src/context-virtualization/projector.ts +0 -62
  216. package/pi-extension/src/context-virtualization/runtime.ts +0 -406
  217. package/pi-extension/src/context-virtualization/state.ts +0 -79
  218. package/pi-extension/src/context-virtualization/types.ts +0 -92
  219. package/pi-extension/src/conversation-history/passages.ts +0 -81
  220. package/pi-extension/src/conversation-history/ranking.ts +0 -155
  221. package/pi-extension/src/conversation-history/runtime.ts +0 -250
  222. package/pi-extension/src/conversation-history/search.ts +0 -79
  223. package/pi-extension/src/conversation-history/types.ts +0 -31
  224. package/pi-extension/src/freeflow-context/resolver.ts +0 -139
  225. package/pi-extension/src/freeflow-context/runtime.ts +0 -100
  226. package/pi-extension/src/freeflow-context/source-projector.ts +0 -106
  227. package/pi-extension/src/freeflow-context/tool.ts +0 -365
  228. package/pi-extension/src/freeflow-context/types.ts +0 -70
  229. package/pi-extension/src/freeflow-context/visibility.ts +0 -53
  230. package/pi-extension/src/index.ts +0 -368
  231. package/pi-extension/src/integrations/mcp-config.ts +0 -32
  232. package/pi-extension/src/runtime/runtime-context.ts +0 -838
  233. package/pi-extension/src/runtime/runtime-identity.ts +0 -8
  234. package/pi-extension/src/session-sources/events.ts +0 -208
  235. package/pi-extension/src/session-sources/read-only-session.ts +0 -170
  236. package/pi-extension/src/session-sources/sources.ts +0 -263
  237. package/pi-extension/src/settings/settings-tui.ts +0 -501
  238. package/pi-extension/src/settings/settings-ui.ts +0 -1422
  239. package/pi-extension/src/ui/text-component.ts +0 -66
  240. package/pi-extension/tests/cognitive-routing-v2/communication.test.js +0 -484
  241. package/pi-extension/tests/cognitive-routing-v2/compaction-input.test.js +0 -183
  242. package/pi-extension/tests/cognitive-routing-v2/native.test.js +0 -441
  243. package/pi-extension/tests/cognitive-routing-v2/performance.test.js +0 -87
  244. package/pi-extension/tests/cognitive-routing-v2/persistence.test.js +0 -245
  245. package/pi-extension/tests/cognitive-routing-v2/projection.test.js +0 -241
  246. package/pi-extension/tests/cognitive-routing-v2/recovery.test.js +0 -236
  247. package/pi-extension/tests/cognitive-routing-v2/render.test.js +0 -230
  248. package/pi-extension/tests/cognitive-routing-v2/runtime.test.js +0 -153
  249. package/pi-extension/tests/cognitive-routing-v2/stabilization.test.js +0 -521
  250. package/pi-extension/tests/cognitive-routing-v2/state.test.js +0 -275
  251. package/pi-extension/tests/context-virtualization/extension.test.js +0 -765
  252. package/pi-extension/tests/context-virtualization/projector.test.js +0 -110
  253. package/pi-extension/tests/context-virtualization/runtime.test.js +0 -216
  254. package/pi-extension/tests/conversation-history/runtime.test.js +0 -98
  255. package/pi-extension/tests/conversation-history/search.test.js +0 -97
  256. package/pi-extension/tests/fixtures/pi-host.js +0 -4
  257. package/pi-extension/tests/fixtures/routing-native.js +0 -188
  258. package/pi-extension/tests/integration/mode-free-core.test.js +0 -219
  259. package/pi-extension/tests/integration/pi-extension.test.js +0 -968
  260. package/pi-extension/tests/integration/prompt-architecture.test.js +0 -431
  261. package/pi-extension/tests/integration/unaffected-regressions.test.js +0 -478
  262. package/pi-extension/tests/settings/settings-tui.test.js +0 -243
  263. package/pi-extension/tsconfig.json +0 -16
  264. package/runtime/prompts/context-virtualization.md +0 -3
  265. package/runtime/prompts/conversation-history.md +0 -3
  266. package/skills/design-for-depth/references/software-design-philosophy.md +0 -202
  267. /package/pi-extension/dist/{cognitive-routing-v2 → cognitive-routing}/budget.js +0 -0
@@ -1,765 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
3
- import { join } from "node:path";
4
- import { tmpdir } from "node:os";
5
- import test from "node:test";
6
-
7
- import freeflowExtension from "../../dist/index.js";
8
-
9
- function createHarness(cwd, contextEntries, activeContextEntries = contextEntries) {
10
- const handlers = new Map();
11
- const tools = [];
12
- const commands = [];
13
- const entries = contextEntries;
14
- let activeToolNames;
15
- let nextId = 1;
16
- const notifications = [];
17
- const statuses = [];
18
- const pi = {
19
- registerTool(tool) {
20
- const index = tools.findIndex((existing) => existing.name === tool.name);
21
- if (index >= 0) tools[index] = tool;
22
- else tools.push(tool);
23
- },
24
- registerCommand(name, definition) {
25
- commands.push({ name, definition });
26
- },
27
- on(event, handler) {
28
- handlers.set(event, handler);
29
- },
30
- appendEntry(customType, data) {
31
- entries.push({
32
- type: "custom",
33
- id: `journal-${nextId++}`,
34
- parentId: entries.at(-1)?.id ?? null,
35
- customType,
36
- data,
37
- });
38
- },
39
- getAllTools() {
40
- return tools.map((tool) => ({ name: tool.name }));
41
- },
42
- getActiveTools() {
43
- return activeToolNames ?? tools.map((tool) => tool.name);
44
- },
45
- setActiveTools(names) {
46
- activeToolNames = [...names];
47
- },
48
- };
49
- const ctx = {
50
- cwd,
51
- mode: "tui",
52
- hasUI: true,
53
- isIdle: () => true,
54
- sessionManager: {
55
- getSessionId: () => "session-1",
56
- getLeafId: () => entries.at(-1)?.id ?? null,
57
- getBranch: () => entries,
58
- buildContextEntries: () => activeContextEntries,
59
- },
60
- ui: {
61
- notify(message, level) {
62
- notifications.push({ message, level });
63
- },
64
- setStatus(name, value) {
65
- statuses.push({ name, value });
66
- },
67
- },
68
- async reload() {},
69
- };
70
- freeflowExtension(pi);
71
- return {
72
- handlers,
73
- tools,
74
- commands,
75
- entries,
76
- pi,
77
- ctx,
78
- notifications,
79
- statuses,
80
- activeToolNames: () => activeToolNames,
81
- };
82
- }
83
-
84
- function toolResultEntry() {
85
- return {
86
- type: "message",
87
- id: "tool-1",
88
- parentId: null,
89
- message: {
90
- role: "toolResult",
91
- toolCallId: "call-1",
92
- toolName: "read",
93
- content: [{ type: "text", text: "raw result" }],
94
- isError: false,
95
- },
96
- };
97
- }
98
-
99
- function untouchedToolResultEntry() {
100
- return {
101
- type: "message",
102
- id: "tool-2",
103
- parentId: "tool-1",
104
- message: {
105
- role: "toolResult",
106
- toolCallId: "call-2",
107
- toolName: "bash",
108
- content: [{ type: "text", text: "untouched result" }],
109
- isError: false,
110
- },
111
- };
112
- }
113
-
114
- function userEntry(id, text, parentId = null) {
115
- return {
116
- type: "message",
117
- id,
118
- parentId,
119
- message: { role: "user", content: [{ type: "text", text }] },
120
- };
121
- }
122
-
123
- function historyToolResultEntry(id, text, toolName = "bash", parentId = null) {
124
- return {
125
- type: "message",
126
- id,
127
- parentId,
128
- message: {
129
- role: "toolResult",
130
- toolCallId: `call-${id}`,
131
- toolName,
132
- content: [{ type: "text", text }],
133
- isError: true,
134
- },
135
- };
136
- }
137
-
138
- function assistantEntry(id, content, parentId = null) {
139
- return {
140
- type: "message",
141
- id,
142
- parentId,
143
- message: { role: "assistant", content },
144
- };
145
- }
146
-
147
- async function writeConfig(cwd, config) {
148
- await mkdir(join(cwd, ".freeflow"), { recursive: true });
149
- const value = typeof config === "boolean" ? { contextVirtualization: config } : config;
150
- await writeFile(join(cwd, ".freeflow/config.json"), JSON.stringify(value, null, 2), "utf8");
151
- }
152
-
153
- const testTheme = {
154
- fg(_color, text) {
155
- return text;
156
- },
157
- bold(text) {
158
- return text;
159
- },
160
- dim(text) {
161
- return text;
162
- },
163
- italic(text) {
164
- return text;
165
- },
166
- };
167
-
168
- function renderComponent(component) {
169
- return component.render(120).join("\\n");
170
- }
171
-
172
- test("disabled Freeflow Context does not publish an empty oneOf schema", async () => {
173
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-context-disabled-schema-"));
174
- try {
175
- await writeConfig(cwd, {});
176
- const harness = createHarness(cwd, []);
177
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
178
-
179
- const contextTool = harness.tools.find((tool) => tool.name === "freeflow_context");
180
- assert.ok(contextTool);
181
- assert.deepEqual(contextTool.parameters.properties, {});
182
- assert.equal(Object.hasOwn(contextTool.parameters, "oneOf"), false);
183
- } finally {
184
- await rm(cwd, { recursive: true, force: true });
185
- }
186
- });
187
-
188
- test("enabled Context Virtualization registers, projects, archives, restores, and reports through commands", async () => {
189
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-context-extension-"));
190
- try {
191
- await writeConfig(cwd, true);
192
- const harness = createHarness(cwd, [toolResultEntry(), untouchedToolResultEntry()]);
193
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
194
-
195
- assert.ok(harness.activeToolNames().includes("freeflow_context"));
196
- const before = await harness.handlers.get("before_agent_start")({ systemPrompt: "base" }, harness.ctx);
197
- assert.match(before.systemPrompt, /## Context Virtualization Cue/);
198
- assert.doesNotMatch(before.systemPrompt, /# Context Virtualization$/m);
199
-
200
- const contextResult = await harness.handlers.get("context")(
201
- { messages: [harness.entries[0].message] },
202
- harness.ctx,
203
- );
204
- assert.match(contextResult.messages[0].content.at(-1).text, /ctx:tool-1/);
205
-
206
- const contextTool = harness.tools.find((tool) => tool.name === "freeflow_context");
207
- assert.ok(contextTool);
208
- assert.doesNotMatch(contextTool.description, /conversation history/i);
209
- const staleSearch = await contextTool.execute(
210
- "context-stale-search",
211
- { operation: "search", query: "not enabled" },
212
- undefined,
213
- undefined,
214
- harness.ctx,
215
- );
216
- assert.equal(staleSearch.details.result.status, "rejected");
217
- assert.equal(staleSearch.details.result.reason, "operation_disabled");
218
- assert.equal(staleSearch.details.result.message, undefined);
219
- const staleCompact = contextTool.renderResult(staleSearch, { expanded: false, isPartial: false }, testTheme, {
220
- args: { operation: "search", query: "not enabled" },
221
- });
222
- assert.match(renderComponent(staleCompact), /operation_disabled/);
223
- const archived = await contextTool.execute(
224
- "context-archive",
225
- {
226
- operation: "archive",
227
- targets: [{ ref: "ctx:tool-1", retained: "The result is needed only as a failure summary." }],
228
- },
229
- undefined,
230
- undefined,
231
- harness.ctx,
232
- );
233
- assert.equal(archived.details.result.status, "ok");
234
- const archiveCompact = contextTool.renderResult(archived, { expanded: false, isPartial: false }, testTheme, {
235
- args: { operation: "archive", targets: [{ ref: "ctx:tool-1" }] },
236
- });
237
- assert.match(renderComponent(archiveCompact), /archive · ok · 1 changed/);
238
- assert.match(renderComponent(archiveCompact), /Archived 1 tool result/);
239
- assert.deepEqual(archived.details.result.retained, {
240
- "ctx:tool-1": "The result is needed only as a failure summary.",
241
- });
242
- assert.equal(
243
- archived.content[0].text,
244
- [
245
- "Context Virtualization: archive",
246
- "Status: ok",
247
- "Changed: ctx:tool-1",
248
- "Message: Archived 1 tool result from future context projections.",
249
- "Retained meaning:",
250
- " ctx:tool-1: The result is needed only as a failure summary.",
251
- ].join("\n"),
252
- );
253
-
254
- const archivedContext = await harness.handlers.get("context")(
255
- { messages: [harness.entries[0].message] },
256
- harness.ctx,
257
- );
258
- assert.match(archivedContext.messages[0].content[0].text, /context archived: ctx:tool-1/);
259
- assert.match(archivedContext.messages[0].content[0].text, /failure summary/);
260
-
261
- await harness.commands
262
- .find((command) => command.name === "freeflow")
263
- .definition.handler("context list", harness.ctx);
264
- const listMessage = harness.notifications.at(-1).message;
265
- assert.match(listMessage, /^Context Virtualization: archived projections/);
266
- assert.match(listMessage, /Ref: ctx:tool-1/);
267
- assert.match(listMessage, /Tool: read/);
268
- assert.match(listMessage, /State: retained/);
269
- assert.doesNotMatch(listMessage, /ctx:tool-2/);
270
- assert.doesNotMatch(listMessage, /\|/);
271
-
272
- await harness.commands
273
- .find((command) => command.name === "freeflow")
274
- .definition.handler("context restore ctx:tool-1", harness.ctx);
275
- assert.equal(harness.notifications.at(-1).message, "Restored 1 projection to full content.");
276
- const restoredContext = await harness.handlers.get("context")(
277
- { messages: [harness.entries[0].message] },
278
- harness.ctx,
279
- );
280
- assert.match(restoredContext.messages[0].content.at(-1).text, /ctx:tool-1/);
281
-
282
- await harness.commands
283
- .find((command) => command.name === "freeflow")
284
- .definition.handler("context list", harness.ctx);
285
- assert.equal(
286
- harness.notifications.at(-1).message,
287
- "Context Virtualization: no archived projections in the active session branch.",
288
- );
289
- } finally {
290
- await rm(cwd, { recursive: true, force: true });
291
- }
292
- });
293
-
294
- test("enabled Conversation History exposes only search and retrieve operations", async () => {
295
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-conversation-history-extension-"));
296
- try {
297
- await writeConfig(cwd, { conversationHistory: true });
298
- const harness = createHarness(cwd, [toolResultEntry()]);
299
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
300
-
301
- assert.ok(harness.activeToolNames().includes("freeflow_context"));
302
- const contextTool = harness.tools.find((tool) => tool.name === "freeflow_context");
303
- assert.ok(contextTool);
304
- assert.deepEqual(
305
- contextTool.parameters.oneOf.map((variant) => variant.properties.operation.const),
306
- ["search", "retrieve"],
307
- );
308
- assert.equal(typeof contextTool.renderCall, "function");
309
- assert.equal(typeof contextTool.renderResult, "function");
310
- const renderContext = {
311
- args: { operation: "search", query: "database timeout" },
312
- state: {},
313
- toolCallId: "render-test",
314
- cwd,
315
- executionStarted: true,
316
- argsComplete: true,
317
- isPartial: false,
318
- expanded: false,
319
- showImages: false,
320
- isError: false,
321
- invalidate() {},
322
- lastComponent: undefined,
323
- };
324
- const compactCall = contextTool.renderCall(renderContext.args, testTheme, renderContext);
325
- assert.match(renderComponent(compactCall), /search/i);
326
- assert.match(renderComponent(compactCall), /database timeout/i);
327
- const renderResult = {
328
- content: [{ type: "text", text: "raw full result" }],
329
- details: {
330
- result: {
331
- status: "ok",
332
- operation: "search",
333
- query: "database timeout",
334
- coverage: "complete",
335
- returned: 1,
336
- truncated: false,
337
- hits: [
338
- {
339
- ref: "ctx:render-source",
340
- kind: "toolResult",
341
- timestamp: "2026-01-01T00:00:00.000Z",
342
- snippet: "The database timeout was recovered.",
343
- match: { type: "exact-phrase", matchedTerms: ["database", "timeout"], queryTermCount: 2 },
344
- },
345
- ],
346
- },
347
- },
348
- };
349
- const compactResult = contextTool.renderResult(
350
- renderResult,
351
- { expanded: false, isPartial: false },
352
- testTheme,
353
- renderContext,
354
- );
355
- assert.match(renderComponent(compactResult), /1/);
356
- assert.match(renderComponent(compactResult), /top exact-phrase/);
357
- assert.doesNotMatch(
358
- renderComponent(compactResult),
359
- /database timeout|raw full result|database timeout was recovered/i,
360
- );
361
- const expandedResult = contextTool.renderResult(renderResult, { expanded: true, isPartial: false }, testTheme, {
362
- ...renderContext,
363
- expanded: true,
364
- });
365
- assert.match(renderComponent(expandedResult), /ctx:render-source/);
366
- assert.match(renderComponent(expandedResult), /database timeout was recovered/);
367
- assert.match(contextTool.description, /hidden conversation history/i);
368
- assert.doesNotMatch(contextTool.description, /future context projections/i);
369
- const before = await harness.handlers.get("before_agent_start")({ systemPrompt: "base" }, harness.ctx);
370
- assert.match(before.systemPrompt, /## Conversation History Cue/);
371
- assert.doesNotMatch(before.systemPrompt, /# Conversation History$/m);
372
- } finally {
373
- await rm(cwd, { recursive: true, force: true });
374
- }
375
- });
376
-
377
- test("Freeflow Context exposes both operation families when both features are enabled", async () => {
378
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-context-both-features-"));
379
- try {
380
- await writeConfig(cwd, { contextVirtualization: true, conversationHistory: true });
381
- const harness = createHarness(cwd, [toolResultEntry()]);
382
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
383
- const contextTool = harness.tools.find((tool) => tool.name === "freeflow_context");
384
- assert.deepEqual(
385
- contextTool.parameters.oneOf.map((variant) => variant.properties.operation.const),
386
- ["archive", "restore", "search", "retrieve"],
387
- );
388
- assert.ok(harness.activeToolNames().includes("freeflow_context"));
389
- } finally {
390
- await rm(cwd, { recursive: true, force: true });
391
- }
392
- });
393
-
394
- test("Conversation History searches hidden active-branch entries and retrieves selected content", async () => {
395
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-conversation-history-runtime-"));
396
- try {
397
- await writeConfig(cwd, { conversationHistory: true });
398
- const visible = userEntry("visible", "Current visible question");
399
- const hidden = historyToolResultEntry(
400
- "hidden",
401
- "Authentication failed because the database timeout expired.",
402
- "bash",
403
- "visible",
404
- );
405
- const excluded = historyToolResultEntry(
406
- "freeflow-result",
407
- "Authentication failed because the database timeout expired.",
408
- " freeflow_context ",
409
- "hidden",
410
- );
411
- const harness = createHarness(cwd, [visible, hidden, excluded], [visible]);
412
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
413
- await harness.handlers.get("context")({ messages: [visible.message] }, harness.ctx);
414
- await harness.commands
415
- .find((command) => command.name === "freeflow")
416
- .definition.handler("context status", harness.ctx);
417
- assert.match(harness.notifications.at(-1).message, /^Freeflow Context: available/);
418
- assert.match(harness.notifications.at(-1).message, /Conversation History: enabled/);
419
-
420
- const contextTool = harness.tools.find((tool) => tool.name === "freeflow_context");
421
- const search = await contextTool.execute(
422
- "context-search",
423
- { operation: "search", query: "database timeout", limit: 8 },
424
- undefined,
425
- undefined,
426
- harness.ctx,
427
- );
428
- assert.equal(search.details.result.status, "ok");
429
- assert.deepEqual(
430
- search.details.result.hits.map((hit) => hit.ref),
431
- ["ctx:hidden"],
432
- );
433
- assert.match(search.content[0].text, /^Conversation History: search/);
434
- assert.match(search.content[0].text, /Query: database timeout/);
435
- assert.match(search.content[0].text, /Match: exact-phrase/);
436
- assert.match(search.content[0].text, /Term coverage: 2\/2/);
437
- assert.match(search.content[0].text, /Tools: bash/);
438
- assert.match(search.content[0].text, /Error: yes/);
439
- assert.doesNotMatch(search.content[0].text, /ctx:visible|ctx:freeflow-result/);
440
-
441
- const filteredSearch = await contextTool.execute(
442
- "context-search-trimmed-tool-filter",
443
- { operation: "search", query: "database timeout", toolNames: [" BASH "] },
444
- undefined,
445
- undefined,
446
- harness.ctx,
447
- );
448
- assert.equal(filteredSearch.details.result.status, "ok");
449
- assert.deepEqual(
450
- filteredSearch.details.result.hits.map((hit) => hit.ref),
451
- ["ctx:hidden"],
452
- );
453
-
454
- const retrieve = await contextTool.execute(
455
- "context-retrieve",
456
- { operation: "retrieve", refs: ["ctx:hidden"] },
457
- undefined,
458
- undefined,
459
- harness.ctx,
460
- );
461
- assert.equal(retrieve.details.result.status, "ok");
462
- assert.equal(retrieve.details.result.items[0].ref, "ctx:hidden");
463
- assert.match(retrieve.content[0].text, /Source characters:/);
464
- assert.match(retrieve.content[0].text, /Returned characters:/);
465
- assert.match(retrieve.details.result.items[0].content, /database timeout/);
466
- } finally {
467
- await rm(cwd, { recursive: true, force: true });
468
- }
469
- });
470
-
471
- test("mixed assistant sources retain ordinary content and exclude Freeflow tool calls", async () => {
472
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-conversation-history-mixed-assistant-"));
473
- try {
474
- await writeConfig(cwd, { conversationHistory: true });
475
- const assistant = assistantEntry("mixed-assistant", [
476
- { type: "text", text: "The ordinary answer explains the database timeout." },
477
- { type: "toolCall", name: "freeflow_context", arguments: { secret: "administrative detail" } },
478
- { type: "toolCall", name: "bash", arguments: { command: "printf database" } },
479
- ]);
480
- assistant.timestamp = "not-a-timestamp";
481
- const harness = createHarness(cwd, [assistant], []);
482
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
483
- await harness.handlers.get("context")({ messages: [] }, harness.ctx);
484
- const contextTool = harness.tools.find((tool) => tool.name === "freeflow_context");
485
-
486
- const search = await contextTool.execute(
487
- "context-search-mixed-assistant",
488
- { operation: "search", query: "ordinary answer" },
489
- undefined,
490
- undefined,
491
- harness.ctx,
492
- );
493
- assert.equal(search.details.result.status, "ok");
494
- assert.deepEqual(
495
- search.details.result.hits.map((hit) => hit.ref),
496
- ["ctx:mixed-assistant"],
497
- );
498
- assert.deepEqual(search.details.result.hits[0].toolNames, ["bash"]);
499
-
500
- const retrieve = await contextTool.execute(
501
- "context-retrieve-mixed-assistant",
502
- { operation: "retrieve", refs: ["ctx:mixed-assistant"] },
503
- undefined,
504
- undefined,
505
- harness.ctx,
506
- );
507
- assert.equal(retrieve.details.result.status, "ok");
508
- assert.equal(retrieve.details.result.items[0].timestamp, "1970-01-01T00:00:00.000Z");
509
- assert.match(retrieve.details.result.items[0].content, /ordinary answer/);
510
- assert.match(retrieve.details.result.items[0].content, /printf database/);
511
- assert.doesNotMatch(retrieve.details.result.items[0].content, /administrative detail/);
512
- } finally {
513
- await rm(cwd, { recursive: true, force: true });
514
- }
515
- });
516
-
517
- test("archived Context Virtualization sources return to hidden Conversation History", async () => {
518
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-conversation-history-archived-source-"));
519
- try {
520
- await writeConfig(cwd, { contextVirtualization: true, conversationHistory: true });
521
- const source = historyToolResultEntry("archived-source", "The archived database timeout is recoverable.");
522
- const harness = createHarness(cwd, [source], [source]);
523
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
524
- await harness.handlers.get("context")({ messages: [source.message] }, harness.ctx);
525
-
526
- const contextTool = harness.tools.find((tool) => tool.name === "freeflow_context");
527
- const archived = await contextTool.execute(
528
- "context-archive-source",
529
- { operation: "archive", targets: [{ ref: "ctx:archived-source" }] },
530
- undefined,
531
- undefined,
532
- harness.ctx,
533
- );
534
- assert.equal(archived.details.result.status, "ok");
535
-
536
- await harness.handlers.get("context")({ messages: [source.message] }, harness.ctx);
537
- const search = await contextTool.execute(
538
- "context-search-archived-source",
539
- { operation: "search", query: "database timeout" },
540
- undefined,
541
- undefined,
542
- harness.ctx,
543
- );
544
- assert.equal(search.details.result.status, "ok");
545
- assert.deepEqual(
546
- search.details.result.hits.map((hit) => hit.ref),
547
- ["ctx:archived-source"],
548
- );
549
- } finally {
550
- await rm(cwd, { recursive: true, force: true });
551
- }
552
- });
553
-
554
- test("visible retrieved sources are excluded until the retrieval result is archived", async () => {
555
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-conversation-history-materialization-"));
556
- try {
557
- await writeConfig(cwd, { conversationHistory: true, contextVirtualization: true });
558
- const source = historyToolResultEntry("materialized-source", "The original database timeout evidence.");
559
- const retrievalResult = historyToolResultEntry(
560
- "retrieval-result",
561
- "Ref ctx:materialized-source\nThe original database timeout evidence.",
562
- "freeflow_context",
563
- );
564
- retrievalResult.message.details = {
565
- result: {
566
- status: "ok",
567
- operation: "retrieve",
568
- items: [{ ref: "ctx:materialized-source", kind: "toolResult", content: source.message.content[0].text }],
569
- },
570
- };
571
- const harness = createHarness(cwd, [source, retrievalResult], [retrievalResult]);
572
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
573
- await harness.handlers.get("context")({ messages: [retrievalResult.message] }, harness.ctx);
574
- const contextTool = harness.tools.find((tool) => tool.name === "freeflow_context");
575
-
576
- const hiddenSearch = await contextTool.execute(
577
- "context-search-materialized-source",
578
- { operation: "search", query: "database timeout" },
579
- undefined,
580
- undefined,
581
- harness.ctx,
582
- );
583
- assert.equal(hiddenSearch.details.result.status, "rejected");
584
- assert.equal(hiddenSearch.details.result.reason, "no_hidden_conversation_history");
585
-
586
- const archive = await contextTool.execute(
587
- "context-archive-retrieval-result",
588
- { operation: "archive", targets: [{ ref: "ctx:retrieval-result" }] },
589
- undefined,
590
- undefined,
591
- harness.ctx,
592
- );
593
- assert.equal(archive.details.result.status, "ok");
594
-
595
- await writeConfig(cwd, { conversationHistory: true });
596
- await harness.handlers.get("session_tree")({}, harness.ctx);
597
- await harness.handlers.get("context")({ messages: [retrievalResult.message] }, harness.ctx);
598
- const stillMaterialized = await contextTool.execute(
599
- "context-search-while-virtualization-disabled",
600
- { operation: "search", query: "database timeout" },
601
- undefined,
602
- undefined,
603
- harness.ctx,
604
- );
605
- assert.equal(stillMaterialized.details.result.status, "rejected");
606
- assert.equal(stillMaterialized.details.result.reason, "no_hidden_conversation_history");
607
-
608
- await writeConfig(cwd, { conversationHistory: true, contextVirtualization: true });
609
- await harness.handlers.get("session_tree")({}, harness.ctx);
610
- await harness.handlers.get("context")({ messages: [retrievalResult.message] }, harness.ctx);
611
-
612
- const searchableAgain = await contextTool.execute(
613
- "context-search-after-archive",
614
- { operation: "search", query: "database timeout" },
615
- undefined,
616
- undefined,
617
- harness.ctx,
618
- );
619
- assert.equal(searchableAgain.details.result.status, "ok");
620
- assert.deepEqual(
621
- searchableAgain.details.result.hits.map((hit) => hit.ref),
622
- ["ctx:materialized-source"],
623
- );
624
- } finally {
625
- await rm(cwd, { recursive: true, force: true });
626
- }
627
- });
628
-
629
- test("Conversation History rejects visible-only searches and bounds oversized retrieval", async () => {
630
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-conversation-history-bounds-"));
631
- try {
632
- await writeConfig(cwd, { conversationHistory: true });
633
- const visible = userEntry("visible", "Everything needed is visible now");
634
- const visibleHarness = createHarness(cwd, [visible], [visible]);
635
- await visibleHarness.handlers.get("session_start")({ reason: "startup" }, visibleHarness.ctx);
636
- await visibleHarness.handlers.get("context")({ messages: [visible.message] }, visibleHarness.ctx);
637
- const visibleTool = visibleHarness.tools.find((tool) => tool.name === "freeflow_context");
638
- const emptySearch = await visibleTool.execute(
639
- "context-empty-search",
640
- { operation: "search", query: "anything hidden" },
641
- undefined,
642
- undefined,
643
- visibleHarness.ctx,
644
- );
645
- assert.equal(emptySearch.details.result.status, "rejected");
646
- assert.equal(emptySearch.details.result.reason, "no_hidden_conversation_history");
647
- assert.match(emptySearch.content[0].text, /Reason: no_hidden_conversation_history/);
648
-
649
- const oversizedText = `${"database context\n".repeat(700)}${"unrelated output\n".repeat(100)}${"database timeout\n".repeat(10)}${"more output\n".repeat(700)}`;
650
- const oversized = historyToolResultEntry("oversized", oversizedText);
651
- const hiddenHarness = createHarness(cwd, [oversized], []);
652
- await hiddenHarness.handlers.get("session_start")({ reason: "startup" }, hiddenHarness.ctx);
653
- await hiddenHarness.handlers.get("context")({ messages: [] }, hiddenHarness.ctx);
654
- const hiddenTool = hiddenHarness.tools.find((tool) => tool.name === "freeflow_context");
655
- const zeroSearch = await hiddenTool.execute(
656
- "context-zero-search",
657
- { operation: "search", query: "term that is absent" },
658
- undefined,
659
- undefined,
660
- hiddenHarness.ctx,
661
- );
662
- assert.equal(zeroSearch.details.result.status, "ok");
663
- assert.equal(zeroSearch.details.result.returned, 0);
664
- assert.match(zeroSearch.content[0].text, /No lexical matches were found in hidden active-branch history/);
665
-
666
- const duplicateRef = await hiddenTool.execute(
667
- "context-duplicate-normalized-ref",
668
- { operation: "retrieve", refs: ["ctx:oversized", "ctx:oversized "], focus: "database timeout" },
669
- undefined,
670
- undefined,
671
- hiddenHarness.ctx,
672
- );
673
- assert.equal(duplicateRef.details.result.status, "rejected");
674
- assert.equal(duplicateRef.details.result.reason, "duplicate_ref");
675
-
676
- const retrieve = await hiddenTool.execute(
677
- "context-oversized-retrieve",
678
- { operation: "retrieve", refs: ["ctx:oversized"], focus: "database timeout" },
679
- undefined,
680
- undefined,
681
- hiddenHarness.ctx,
682
- );
683
- assert.equal(retrieve.details.result.status, "ok");
684
- assert.equal(retrieve.details.result.items[0].completeness, "partial");
685
- assert.ok(retrieve.details.result.items[0].returnedCharacters <= 8000);
686
- const focusedContent = retrieve.details.result.items[0].content;
687
- const focusedStart = oversizedText.indexOf(focusedContent);
688
- assert.ok(focusedStart === 0 || oversizedText[focusedStart - 1] === "\n");
689
- assert.ok(focusedStart + focusedContent.length >= oversizedText.length || focusedContent.endsWith("\n"));
690
- assert.match(focusedContent, /database timeout/);
691
- } finally {
692
- await rm(cwd, { recursive: true, force: true });
693
- }
694
- });
695
-
696
- test("Conversation History reports partial coverage for invalid eligible sources", async () => {
697
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-conversation-history-partial-coverage-"));
698
- try {
699
- await writeConfig(cwd, { conversationHistory: true });
700
- const invalid = historyToolResultEntry("invalid-source", "An invalid tool name should not become searchable.");
701
- invalid.message.toolName = "x".repeat(129);
702
- const harness = createHarness(cwd, [invalid], []);
703
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
704
- await harness.handlers.get("context")({ messages: [] }, harness.ctx);
705
- const contextTool = harness.tools.find((tool) => tool.name === "freeflow_context");
706
- const search = await contextTool.execute(
707
- "context-partial-coverage",
708
- { operation: "search", query: "invalid tool" },
709
- undefined,
710
- undefined,
711
- harness.ctx,
712
- );
713
- assert.equal(search.details.result.status, "ok");
714
- assert.equal(search.details.result.coverage, "partial");
715
- assert.equal(search.details.result.skippedEntries, 1);
716
- assert.equal(search.details.result.returned, 0);
717
- assert.match(search.content[0].text, /Skipped entries: 1/);
718
- } finally {
719
- await rm(cwd, { recursive: true, force: true });
720
- }
721
- });
722
-
723
- test("visible invalid sources do not make an empty hidden corpus partial", async () => {
724
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-conversation-history-visible-invalid-"));
725
- try {
726
- await writeConfig(cwd, { conversationHistory: true });
727
- const invalid = historyToolResultEntry("visible-invalid", "This visible source has an invalid tool name.");
728
- invalid.message.toolName = "x".repeat(129);
729
- const harness = createHarness(cwd, [invalid], [invalid]);
730
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
731
- await harness.handlers.get("context")({ messages: [invalid.message] }, harness.ctx);
732
- const contextTool = harness.tools.find((tool) => tool.name === "freeflow_context");
733
- const search = await contextTool.execute(
734
- "context-visible-invalid",
735
- { operation: "search", query: "invalid source" },
736
- undefined,
737
- undefined,
738
- harness.ctx,
739
- );
740
- assert.equal(search.details.result.status, "rejected");
741
- assert.equal(search.details.result.reason, "no_hidden_conversation_history");
742
- } finally {
743
- await rm(cwd, { recursive: true, force: true });
744
- }
745
- });
746
-
747
- test("disabled Context Virtualization hides the tool and leaves tool results unchanged", async () => {
748
- const cwd = await mkdtemp(join(tmpdir(), "freeflow-context-disabled-"));
749
- try {
750
- await writeConfig(cwd, false);
751
- const harness = createHarness(cwd, [toolResultEntry()]);
752
- await harness.handlers.get("session_start")({ reason: "startup" }, harness.ctx);
753
-
754
- assert.ok(!harness.activeToolNames().includes("freeflow_context"));
755
- const contextResult = await harness.handlers.get("context")(
756
- { messages: [harness.entries[0].message] },
757
- harness.ctx,
758
- );
759
- assert.ok(contextResult);
760
- assert.deepEqual(contextResult.messages[0], harness.entries[0].message);
761
- assert.equal(contextResult.messages.at(-1).customType, "freeflow-runtime-state");
762
- } finally {
763
- await rm(cwd, { recursive: true, force: true });
764
- }
765
- });