@hassangameryt/freeflow 0.7.1 → 0.7.3

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 (147) 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/README.md +153 -128
  6. package/capabilities/cognitive-routing/SKILL.md +126 -274
  7. package/command-surface.json +7 -1
  8. package/gemini-extension.json +1 -1
  9. package/package.json +4 -4
  10. package/pi-extension/dist/cognitive-routing-v2/budget.js +42 -0
  11. package/pi-extension/dist/cognitive-routing-v2/config.js +136 -0
  12. package/pi-extension/dist/cognitive-routing-v2/projection.js +330 -0
  13. package/pi-extension/dist/cognitive-routing-v2/render.js +252 -0
  14. package/pi-extension/dist/cognitive-routing-v2/runtime.js +2181 -0
  15. package/pi-extension/dist/cognitive-routing-v2/schemas.js +173 -0
  16. package/pi-extension/dist/cognitive-routing-v2/state.js +828 -0
  17. package/pi-extension/dist/cognitive-routing-v2/tools.js +60 -0
  18. package/pi-extension/dist/cognitive-routing-v2/types.js +48 -0
  19. package/pi-extension/dist/context-virtualization/runtime.js +29 -7
  20. package/pi-extension/dist/freeflow-context/tool.js +12 -6
  21. package/pi-extension/dist/index.js +302 -626
  22. package/pi-extension/dist/provider-support/astra/adapter.js +110 -0
  23. package/pi-extension/dist/provider-support/astra/history.js +125 -0
  24. package/pi-extension/dist/provider-support/astra/index.js +11 -0
  25. package/pi-extension/dist/provider-support/astra/session-state.js +114 -0
  26. package/pi-extension/dist/provider-support/index.js +4 -0
  27. package/pi-extension/dist/runtime/request-history.js +216 -0
  28. package/pi-extension/dist/runtime/runtime-context.js +85 -16
  29. package/pi-extension/dist/session-sources/events.js +217 -0
  30. package/pi-extension/dist/session-sources/provenance.js +32 -0
  31. package/pi-extension/dist/session-sources/read-only-session.js +148 -0
  32. package/pi-extension/dist/session-sources/sources.js +277 -0
  33. package/pi-extension/dist/settings/settings-ui.js +274 -147
  34. package/pi-extension/src/cognitive-routing-v2/budget.ts +42 -0
  35. package/pi-extension/src/cognitive-routing-v2/config.ts +173 -0
  36. package/pi-extension/src/cognitive-routing-v2/projection.ts +375 -0
  37. package/pi-extension/src/cognitive-routing-v2/render.ts +277 -0
  38. package/pi-extension/src/cognitive-routing-v2/runtime.ts +2241 -0
  39. package/pi-extension/src/cognitive-routing-v2/schemas.ts +180 -0
  40. package/pi-extension/src/cognitive-routing-v2/state.ts +839 -0
  41. package/pi-extension/src/cognitive-routing-v2/tools.ts +62 -0
  42. package/pi-extension/src/cognitive-routing-v2/types.ts +254 -0
  43. package/pi-extension/src/context-virtualization/runtime.ts +30 -8
  44. package/pi-extension/src/freeflow-context/tool.ts +12 -6
  45. package/pi-extension/src/index.ts +308 -675
  46. package/pi-extension/src/provider-support/astra/adapter.ts +108 -0
  47. package/pi-extension/src/provider-support/astra/history.ts +145 -0
  48. package/pi-extension/src/provider-support/astra/index.ts +12 -0
  49. package/pi-extension/src/provider-support/astra/session-state.ts +113 -0
  50. package/pi-extension/src/provider-support/index.ts +5 -0
  51. package/pi-extension/src/runtime/request-history.ts +243 -0
  52. package/pi-extension/src/runtime/runtime-context.ts +100 -17
  53. package/pi-extension/src/session-sources/events.ts +230 -0
  54. package/pi-extension/src/session-sources/provenance.ts +39 -0
  55. package/pi-extension/src/session-sources/read-only-session.ts +170 -0
  56. package/pi-extension/src/session-sources/sources.ts +334 -0
  57. package/pi-extension/src/settings/settings-ui.ts +311 -158
  58. package/pi-extension/tests/cache-reuse/history.test.js +117 -0
  59. package/pi-extension/tests/cache-reuse/native.test.js +91 -0
  60. package/pi-extension/tests/cache-reuse/settings.test.js +211 -0
  61. package/pi-extension/tests/cognitive-routing-v2/communication.test.js +577 -0
  62. package/pi-extension/tests/cognitive-routing-v2/compaction-input.test.js +183 -0
  63. package/pi-extension/tests/cognitive-routing-v2/delegation.test.js +557 -0
  64. package/pi-extension/tests/cognitive-routing-v2/native.test.js +474 -0
  65. package/pi-extension/tests/cognitive-routing-v2/performance.test.js +87 -0
  66. package/pi-extension/tests/cognitive-routing-v2/persistence.test.js +300 -0
  67. package/pi-extension/tests/cognitive-routing-v2/projection.test.js +241 -0
  68. package/pi-extension/tests/cognitive-routing-v2/recovery.test.js +1034 -0
  69. package/pi-extension/tests/cognitive-routing-v2/render.test.js +244 -0
  70. package/pi-extension/tests/cognitive-routing-v2/runtime.test.js +423 -0
  71. package/pi-extension/tests/cognitive-routing-v2/stabilization.test.js +521 -0
  72. package/pi-extension/tests/cognitive-routing-v2/state.test.js +586 -0
  73. package/pi-extension/tests/context-virtualization/extension.test.js +33 -7
  74. package/pi-extension/tests/context-virtualization/runtime.test.js +17 -3
  75. package/pi-extension/tests/fixtures/routing-native.js +191 -0
  76. package/pi-extension/tests/integration/mode-free-core.test.js +6 -4
  77. package/pi-extension/tests/integration/pi-extension.test.js +655 -59
  78. package/pi-extension/tests/integration/prompt-architecture.test.js +127 -30
  79. package/pi-extension/tests/integration/unaffected-regressions.test.js +78 -11
  80. package/pi-extension/tests/provider-support/astra-boundaries.test.js +75 -0
  81. package/pi-extension/tests/provider-support/astra.test.js +306 -0
  82. package/pi-extension/tests/provider-support/cli.test.js +92 -0
  83. package/pi-extension/tests/provider-support/native.test.js +183 -0
  84. package/plugin.json +1 -1
  85. package/runtime/prompts/cognitive-routing.md +4 -5
  86. package/runtime/prompts/core.md +51 -45
  87. package/runtime/prompts/interaction-contract.md +5 -5
  88. package/skills/action-selection/SKILL.md +57 -97
  89. package/skills/design-for-depth/SKILL.md +58 -193
  90. package/skills/design-for-depth/references/implementation-decisions.md +76 -0
  91. package/skills/diagnose-failure/SKILL.md +64 -196
  92. package/skills/discuss/SKILL.md +64 -123
  93. package/skills/discuss/references/discussion-continuity.md +7 -3
  94. package/skills/execute-work/SKILL.md +69 -88
  95. package/skills/execute-work/references/execute-work-edges.md +9 -3
  96. package/skills/handoff/SKILL.md +44 -54
  97. package/skills/handoff/references/handoff-templates.md +15 -6
  98. package/skills/review-artifact/SKILL.md +80 -127
  99. package/skills/review-artifact/references/independent-artifact-reviewer-contract.md +1 -1
  100. package/skills/review-work/SKILL.md +65 -115
  101. package/skills/review-work/references/independent-work-reviewer-contract.md +1 -1
  102. package/skills/simplify-code/SKILL.md +47 -100
  103. package/skills/track-work/SKILL.md +128 -119
  104. package/skills/track-work/references/working-record-format.md +14 -2
  105. package/skills/verify-work/SKILL.md +58 -62
  106. package/skills/verify-work/references/integration-evidence.md +4 -2
  107. package/skills/verify-work/references/test-design.md +89 -0
  108. package/skills/workflow/SKILL.md +73 -119
  109. package/skills/write-plan/SKILL.md +46 -77
  110. package/skills/write-plan/references/plan-shapes.md +5 -5
  111. package/skills/write-spec/SKILL.md +51 -63
  112. package/skills/write-spec/references/artifact-standards.md +2 -2
  113. package/skills/write-spec/references/decision-records.md +3 -2
  114. package/skills/write-spec/references/spec-shapes.md +15 -0
  115. package/pi-extension/dist/cognitive-routing/commands.js +0 -96
  116. package/pi-extension/dist/cognitive-routing/config.js +0 -232
  117. package/pi-extension/dist/cognitive-routing/controller.js +0 -1292
  118. package/pi-extension/dist/cognitive-routing/history.js +0 -451
  119. package/pi-extension/dist/cognitive-routing/host.js +0 -188
  120. package/pi-extension/dist/cognitive-routing/pi-routing-session.js +0 -414
  121. package/pi-extension/dist/cognitive-routing/pi-session-control.js +0 -320
  122. package/pi-extension/dist/cognitive-routing/runtime.js +0 -43
  123. package/pi-extension/dist/cognitive-routing/tool.js +0 -212
  124. package/pi-extension/dist/cognitive-routing/types.js +0 -6
  125. package/pi-extension/src/cognitive-routing/commands.ts +0 -129
  126. package/pi-extension/src/cognitive-routing/config.ts +0 -303
  127. package/pi-extension/src/cognitive-routing/controller.ts +0 -1628
  128. package/pi-extension/src/cognitive-routing/history.ts +0 -650
  129. package/pi-extension/src/cognitive-routing/host.ts +0 -266
  130. package/pi-extension/src/cognitive-routing/pi-routing-session.ts +0 -538
  131. package/pi-extension/src/cognitive-routing/pi-session-control.ts +0 -444
  132. package/pi-extension/src/cognitive-routing/runtime.ts +0 -57
  133. package/pi-extension/src/cognitive-routing/tool.ts +0 -273
  134. package/pi-extension/src/cognitive-routing/types.ts +0 -89
  135. package/pi-extension/tests/cognitive-routing/commands.test.js +0 -134
  136. package/pi-extension/tests/cognitive-routing/controller.test.js +0 -1128
  137. package/pi-extension/tests/cognitive-routing/extension-lifecycle.test.js +0 -1142
  138. package/pi-extension/tests/cognitive-routing/history.test.js +0 -274
  139. package/pi-extension/tests/cognitive-routing/host-identity.test.js +0 -63
  140. package/pi-extension/tests/cognitive-routing/pi-normal-lifecycle.test.js +0 -434
  141. package/pi-extension/tests/cognitive-routing/pi-session-control.test.js +0 -174
  142. package/pi-extension/tests/cognitive-routing/pi-session-history.test.js +0 -91
  143. package/pi-extension/tests/cognitive-routing/profile-resolution.test.js +0 -279
  144. package/pi-extension/tests/cognitive-routing/tool.test.js +0 -230
  145. package/skills/tdd/SKILL.md +0 -143
  146. package/skills/tdd/references/test-design.md +0 -96
  147. /package/pi-extension/tests/{cognitive-routing/host-fixture.js → fixtures/pi-host.js} +0 -0
@@ -1,273 +0,0 @@
1
- import type { CognitiveRoutingController, CognitiveRoutingSwitchResult } from "./controller.js";
2
- import { textComponent } from "../ui/text-component.js";
3
- import type { CognitiveRoutingHistoryOptions, CognitiveRoutingHistoryResult } from "./history.js";
4
- import type { CognitiveRoutingProfileName } from "./types.js";
5
-
6
- export const COGNITIVE_ROUTING_SWITCH_TOOL_NAME = "freeflow_switch_profile";
7
- export const COGNITIVE_ROUTING_HISTORY_TOOL_NAME = "freeflow_cognitive_routing_history";
8
-
9
- export const COGNITIVE_ROUTING_HISTORY_PARAMETERS = {
10
- type: "object",
11
- additionalProperties: false,
12
- properties: {
13
- scope: {
14
- type: "string",
15
- enum: ["session", "active-branch"],
16
- description: "History scope to read.",
17
- },
18
- anomaliesOnly: {
19
- type: "boolean",
20
- description: "Return only events whose integrity is anomaly.",
21
- },
22
- limit: {
23
- type: "integer",
24
- minimum: 1,
25
- maximum: 100,
26
- description: "Maximum number of newest events to return.",
27
- },
28
- },
29
- required: [],
30
- };
31
-
32
- export const COGNITIVE_ROUTING_SWITCH_PARAMETERS = {
33
- type: "object",
34
- additionalProperties: false,
35
- properties: {
36
- target: {
37
- type: "string",
38
- enum: ["standard", "reasoning"],
39
- description: "The configured Cognitive Routing profile to activate.",
40
- },
41
- reason: {
42
- type: "string",
43
- minLength: 1,
44
- maxLength: 160,
45
- description: "A concise one-line reason for the profile transition.",
46
- },
47
- },
48
- required: ["target", "reason"],
49
- };
50
-
51
- type HistoryToolParams = {
52
- scope?: unknown;
53
- anomaliesOnly?: unknown;
54
- limit?: unknown;
55
- };
56
-
57
- type HistoryReader = (
58
- options: CognitiveRoutingHistoryOptions,
59
- context?: unknown,
60
- ) => CognitiveRoutingHistoryResult | Promise<CognitiveRoutingHistoryResult>;
61
-
62
- type SwitchToolParams = {
63
- target?: unknown;
64
- reason?: unknown;
65
- };
66
-
67
- type RenderedSwitchResult =
68
- | {
69
- status: "active";
70
- profile: CognitiveRoutingProfileName;
71
- changed?: boolean;
72
- from?: CognitiveRoutingProfileName;
73
- to?: CognitiveRoutingProfileName;
74
- }
75
- | { status: "blocked" | "inactive"; reason: string };
76
-
77
- function resultText(result: CognitiveRoutingSwitchResult): string {
78
- if (result.status === "active") {
79
- const fields = [COGNITIVE_ROUTING_SWITCH_TOOL_NAME + "|active", `profile|${result.profile}`];
80
- if (result.changed !== undefined) fields.push(`changed|${result.changed}`);
81
- if (result.from) fields.push(`from|${result.from}`);
82
- if (result.to) fields.push(`to|${result.to}`);
83
- return fields.join("\n");
84
- }
85
- return `${COGNITIVE_ROUTING_SWITCH_TOOL_NAME}|${result.status}\nreason|${result.reason}`;
86
- }
87
-
88
- function blocked(reason: string): CognitiveRoutingSwitchResult {
89
- return { status: "blocked", reason };
90
- }
91
-
92
- function renderNothing() {
93
- return {
94
- render() {
95
- return [];
96
- },
97
- invalidate() {},
98
- };
99
- }
100
-
101
- function renderTransition(text: string, theme: any) {
102
- return textComponent(theme?.fg ? theme.fg("accent", text) : text);
103
- }
104
-
105
- function isProfileName(value: unknown): value is CognitiveRoutingProfileName {
106
- return value === "standard" || value === "reasoning";
107
- }
108
-
109
- function resultFromPayload(payload: any): RenderedSwitchResult | undefined {
110
- const details = payload?.details?.result ?? payload?.result ?? payload?.details;
111
- if (details && (details.status === "active" || details.status === "blocked" || details.status === "inactive")) {
112
- if (details.status !== "active") return details as CognitiveRoutingSwitchResult;
113
- if (!isProfileName(details.profile)) return undefined;
114
- return {
115
- status: "active",
116
- profile: details.profile,
117
- ...(typeof details.changed === "boolean" ? { changed: details.changed } : {}),
118
- ...(isProfileName(details.from) ? { from: details.from } : {}),
119
- ...(isProfileName(details.to) ? { to: details.to } : {}),
120
- };
121
- }
122
-
123
- const text = Array.isArray(payload?.content)
124
- ? payload.content.find((part: any) => part?.type === "text")?.text
125
- : undefined;
126
- if (typeof text !== "string") return undefined;
127
- const fields = new Map<string, string>();
128
- for (const line of text.split("\\n")) {
129
- const separator = line.indexOf("|");
130
- if (separator <= 0) continue;
131
- fields.set(line.slice(0, separator), line.slice(separator + 1));
132
- }
133
- const status = fields.get(COGNITIVE_ROUTING_SWITCH_TOOL_NAME);
134
- if (status === "active") {
135
- const profile = fields.get("profile");
136
- if (!isProfileName(profile)) return undefined;
137
- const changed = fields.get("changed");
138
- const from = fields.get("from");
139
- const to = fields.get("to");
140
- return {
141
- status,
142
- profile,
143
- ...(changed === "true" || changed === "false" ? { changed: changed === "true" } : {}),
144
- ...(isProfileName(from) ? { from } : {}),
145
- ...(isProfileName(to) ? { to } : {}),
146
- };
147
- }
148
- if (status === "blocked" || status === "inactive") {
149
- const reason = fields.get("reason");
150
- return reason ? { status, reason } : undefined;
151
- }
152
- return undefined;
153
- }
154
-
155
- function historyOptions(params: HistoryToolParams): CognitiveRoutingHistoryOptions {
156
- return {
157
- ...(params.scope === "active-branch" ? { scope: "active-branch" as const } : {}),
158
- ...(params.anomaliesOnly === true ? { anomaliesOnly: true } : {}),
159
- ...(Number.isInteger(params.limit) ? { limit: Math.max(1, Math.min(100, params.limit as number)) } : {}),
160
- };
161
- }
162
-
163
- function validateParams(
164
- params: SwitchToolParams,
165
- ): { status: "valid"; target: CognitiveRoutingProfileName; reason: string } | { status: "invalid"; reason: string } {
166
- if (params.target !== "standard" && params.target !== "reasoning") {
167
- return { status: "invalid", reason: "target_must_be_standard_or_reasoning" };
168
- }
169
- if (typeof params.reason !== "string") {
170
- return { status: "invalid", reason: "reason_required" };
171
- }
172
- const reason = params.reason.trim();
173
- if (!reason) return { status: "invalid", reason: "reason_required" };
174
- if (reason.includes("\n") || reason.includes("\r"))
175
- return { status: "invalid", reason: "reason_must_be_single_line" };
176
- if (reason.length > 160) return { status: "invalid", reason: "reason_too_long" };
177
- return { status: "valid", target: params.target, reason };
178
- }
179
-
180
- export function registerCognitiveRoutingTool(
181
- pi: {
182
- registerTool(tool: Record<string, unknown>): void;
183
- },
184
- getController: () => CognitiveRoutingController | undefined,
185
- ) {
186
- pi.registerTool({
187
- name: COGNITIVE_ROUTING_SWITCH_TOOL_NAME,
188
- label: "Switch Cognitive Profile",
189
- description: "Request one bounded Cognitive Routing profile transition while automatic control is active.",
190
- promptSnippet: "Switch between the configured standard and reasoning profiles when the current task needs it.",
191
- promptGuidelines: [
192
- "Use only when the current task needs a different reasoning profile.",
193
- "Give one concise sentence as the reason and make this the only tool call in the response.",
194
- "Do not call this tool while a deterministic manual profile hold is active.",
195
- ],
196
- parameters: COGNITIVE_ROUTING_SWITCH_PARAMETERS,
197
- executionMode: "sequential",
198
- async execute(_toolCallId: string, params: SwitchToolParams, _signal: unknown, _onUpdate: unknown, _ctx: unknown) {
199
- const controller = getController();
200
- const input = validateParams(params ?? {});
201
- let result: CognitiveRoutingSwitchResult;
202
- if (input.status === "invalid") {
203
- result = blocked(input.reason);
204
- } else if (!controller) {
205
- result = blocked("not_available");
206
- } else if (!controller.state().effective) {
207
- result = blocked("not_active");
208
- } else if (controller.state().controlMode === "automatic") {
209
- result = await controller.switchAutomaticProfile(input.target, input.reason);
210
- } else {
211
- result = blocked("manual_hold");
212
- }
213
- return {
214
- content: [{ type: "text", text: resultText(result) }],
215
- details: { result },
216
- };
217
- },
218
- renderCall(_args: SwitchToolParams, _theme: any) {
219
- return renderNothing();
220
- },
221
- renderResult(result: any, _options: any, theme: any) {
222
- const outcome = resultFromPayload(result);
223
- if (outcome?.status === "active") {
224
- if (outcome.changed === true && outcome.from && outcome.to) {
225
- return renderTransition(`Cognitive Routing: ${outcome.from} → ${outcome.to}`, theme);
226
- }
227
- if (outcome.changed === false && outcome.to) {
228
- return renderTransition(`Cognitive Routing: ${outcome.to} (already active)`, theme);
229
- }
230
- return renderTransition(`Cognitive Routing: active · ${outcome.profile}`, theme);
231
- }
232
- if (outcome) {
233
- return renderTransition(`Cognitive Routing: ${outcome.status} · ${outcome.reason}`, theme);
234
- }
235
- return renderTransition(`Cognitive Routing: ${result?.isError ? "error" : "result unavailable"}`, theme);
236
- },
237
- });
238
- }
239
-
240
- export function registerCognitiveRoutingHistoryTool(
241
- pi: {
242
- registerTool(tool: Record<string, unknown>): void;
243
- },
244
- readHistory: HistoryReader,
245
- ) {
246
- pi.registerTool({
247
- name: COGNITIVE_ROUTING_HISTORY_TOOL_NAME,
248
- label: "Read Cognitive Routing History",
249
- description:
250
- "Read the deterministic Cognitive Routing transition history without changing routing or session state.",
251
- promptSnippet: "Inspect Cognitive Routing transition history when debugging or monitoring profile behavior.",
252
- promptGuidelines: [
253
- "Use only when debugging or monitoring Cognitive Routing is requested.",
254
- "This tool is read-only and does not change profile, control, branch, or session state.",
255
- "Use scope=active-branch to inspect only the current branch ancestry.",
256
- "Use anomaliesOnly=true to inspect only integrity anomalies.",
257
- ],
258
- parameters: COGNITIVE_ROUTING_HISTORY_PARAMETERS,
259
- async execute(
260
- _toolCallId: string,
261
- params: HistoryToolParams,
262
- _signal: unknown,
263
- _onUpdate: unknown,
264
- context: unknown,
265
- ) {
266
- const result = await readHistory(historyOptions(params ?? {}), context);
267
- return {
268
- content: [{ type: "text", text: `Cognitive Routing history\n${JSON.stringify(result)}` }],
269
- details: { result },
270
- };
271
- },
272
- });
273
- }
@@ -1,89 +0,0 @@
1
- export const COGNITIVE_ROUTING_PROFILE_NAMES = ["standard", "reasoning"] as const;
2
- export const COGNITIVE_ROUTING_SESSION_START_CONTROLS = ["automatic", "manual"] as const;
3
-
4
- export type CognitiveRoutingProfileName = (typeof COGNITIVE_ROUTING_PROFILE_NAMES)[number];
5
- export type CognitiveRoutingSessionStartControl = (typeof COGNITIVE_ROUTING_SESSION_START_CONTROLS)[number];
6
- export type CognitiveRoutingThinkingLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max";
7
- export type CognitiveRoutingConfigSource = "default" | "repository" | "personal";
8
-
9
- export interface CognitiveRoutingSessionStart {
10
- control: CognitiveRoutingSessionStartControl;
11
- profile: CognitiveRoutingProfileName;
12
- }
13
-
14
- export const DEFAULT_COGNITIVE_ROUTING_SESSION_START = {
15
- control: "automatic",
16
- profile: "reasoning",
17
- } as const satisfies CognitiveRoutingSessionStart;
18
-
19
- export interface CognitiveRoutingProfile {
20
- provider: string;
21
- model: string;
22
- thinkingLevel: CognitiveRoutingThinkingLevel;
23
- }
24
-
25
- export interface CognitiveRoutingConfigError {
26
- code:
27
- | "invalid_block"
28
- | "invalid_enabled"
29
- | "invalid_profiles"
30
- | "invalid_profile"
31
- | "invalid_session_start"
32
- | "unsupported_key";
33
- message: string;
34
- profile?: CognitiveRoutingProfileName;
35
- source: "repository" | "personal";
36
- }
37
-
38
- export interface CognitiveRoutingConfigResolution {
39
- configured: boolean;
40
- valid: boolean;
41
- enabled: boolean;
42
- enabledSource: CognitiveRoutingConfigSource;
43
- profiles: Partial<Record<CognitiveRoutingProfileName, CognitiveRoutingProfile>>;
44
- profileSources: Partial<Record<CognitiveRoutingProfileName, CognitiveRoutingConfigSource>>;
45
- sessionStart: CognitiveRoutingSessionStart;
46
- sessionStartSources: {
47
- control: CognitiveRoutingConfigSource;
48
- profile: CognitiveRoutingConfigSource;
49
- };
50
- error?: CognitiveRoutingConfigError;
51
- }
52
-
53
- export type CognitiveRoutingBlockCode =
54
- | "disabled"
55
- | "config_invalid"
56
- | "host_unsupported"
57
- | "profile_missing"
58
- | "profile_unavailable"
59
- | "profile_unauthenticated"
60
- | "profile_clamped"
61
- | "profiles_identical"
62
- | "runtime_disabled";
63
-
64
- export interface CognitiveRoutingBlockingReason {
65
- code: CognitiveRoutingBlockCode;
66
- message: string;
67
- profile?: CognitiveRoutingProfileName;
68
- }
69
-
70
- export interface CognitiveRoutingResolvedProfile extends CognitiveRoutingProfile {
71
- effectiveThinkingLevel: CognitiveRoutingThinkingLevel;
72
- }
73
-
74
- export interface CognitiveRoutingCapabilityState {
75
- configured: boolean;
76
- configValid: boolean;
77
- enabled: boolean;
78
- effective: boolean;
79
- enabledSource: CognitiveRoutingConfigSource;
80
- profiles: Partial<Record<CognitiveRoutingProfileName, CognitiveRoutingProfile>>;
81
- profileSources: Partial<Record<CognitiveRoutingProfileName, CognitiveRoutingConfigSource>>;
82
- sessionStart: CognitiveRoutingSessionStart;
83
- sessionStartSources: {
84
- control: CognitiveRoutingConfigSource;
85
- profile: CognitiveRoutingConfigSource;
86
- };
87
- resolvedProfiles: Partial<Record<CognitiveRoutingProfileName, CognitiveRoutingResolvedProfile>>;
88
- blockingReason: CognitiveRoutingBlockingReason;
89
- }
@@ -1,134 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import {
4
- cognitiveRoutingProfileCompletions,
5
- handleCognitiveRoutingProfileCommand,
6
- } from "../../dist/cognitive-routing/commands.js";
7
-
8
- function createContext() {
9
- const notifications = [];
10
- return {
11
- notifications,
12
- ui: {
13
- notify(message, level) {
14
- notifications.push({ message, level });
15
- },
16
- },
17
- };
18
- }
19
-
20
- test("completes profile controls and read-only history views", () => {
21
- assert.deepEqual(
22
- cognitiveRoutingProfileCompletions("").map(({ value }) => value),
23
- ["standard", "reasoning", "auto", "history", "history active", "history anomalies"],
24
- );
25
- assert.deepEqual(
26
- cognitiveRoutingProfileCompletions("rea").map(({ value }) => value),
27
- ["reasoning"],
28
- );
29
- assert.deepEqual(
30
- cognitiveRoutingProfileCompletions("history ").map(({ value }) => value),
31
- ["history active", "history anomalies"],
32
- );
33
- });
34
-
35
- test("reads history without requiring an idle Pi or mutating the controller", async () => {
36
- const context = createContext();
37
- context.isIdle = () => false;
38
- const calls = [];
39
- context.history = async (options) => {
40
- calls.push(options);
41
- return {
42
- current: { control: "automatic", profile: "standard" },
43
- summary: { unresolvedCount: 0, anomalyCount: 0 },
44
- events: [],
45
- };
46
- };
47
-
48
- assert.equal(await handleCognitiveRoutingProfileCommand("profile history active", context, undefined), true);
49
- assert.deepEqual(calls, [{ scope: "active-branch" }]);
50
- assert.match(context.notifications[0].message, /Cognitive Routing history/);
51
- assert.equal(context.notifications[0].level, "info");
52
- });
53
-
54
- test("routes standard and reasoning to manual controller ownership", async () => {
55
- const calls = [];
56
- const controller = {
57
- async setManualProfile(profile) {
58
- calls.push(["manual", profile]);
59
- return { status: "active", profile };
60
- },
61
- async setAutomaticControl() {
62
- calls.push(["automatic"]);
63
- return { status: "automatic" };
64
- },
65
- };
66
- const context = createContext();
67
-
68
- assert.equal(await handleCognitiveRoutingProfileCommand("profile standard", context, controller), true);
69
- assert.equal(await handleCognitiveRoutingProfileCommand("profile reasoning", context, controller), true);
70
- assert.deepEqual(calls, [
71
- ["manual", "standard"],
72
- ["manual", "reasoning"],
73
- ]);
74
- assert.equal(context.notifications.length, 2);
75
- });
76
-
77
- test("releases manual ownership through auto without a model transition", async () => {
78
- let calls = 0;
79
- const controller = {
80
- async setManualProfile() {
81
- throw new Error("must not set a profile");
82
- },
83
- async setAutomaticControl() {
84
- calls += 1;
85
- return { status: "automatic" };
86
- },
87
- };
88
- const context = createContext();
89
-
90
- assert.equal(await handleCognitiveRoutingProfileCommand("profile auto", context, controller), true);
91
- assert.equal(calls, 1);
92
- assert.match(context.notifications[0].message, /automatic Reasoning control is active/);
93
- });
94
-
95
- test("rejects manual profile changes while Pi is running", async () => {
96
- const context = createContext();
97
- context.isIdle = () => false;
98
- let calls = 0;
99
- const controller = {
100
- async setManualProfile() {
101
- calls += 1;
102
- return { status: "active", profile: "standard" };
103
- },
104
- async setAutomaticControl() {
105
- calls += 1;
106
- return { status: "automatic" };
107
- },
108
- };
109
-
110
- assert.equal(await handleCognitiveRoutingProfileCommand("profile reasoning", context, controller), true);
111
- assert.equal(calls, 0);
112
- assert.match(context.notifications[0].message, /only while Pi is idle/);
113
- });
114
-
115
- test("does not turn conversational or malformed input into a control", async () => {
116
- const context = createContext();
117
- let calls = 0;
118
- const controller = {
119
- async setManualProfile() {
120
- calls += 1;
121
- return { status: "active", profile: "standard" };
122
- },
123
- async setAutomaticControl() {
124
- calls += 1;
125
- return { status: "automatic" };
126
- },
127
- };
128
-
129
- assert.equal(await handleCognitiveRoutingProfileCommand("hello", context, controller), false);
130
- assert.equal(await handleCognitiveRoutingProfileCommand("profile maybe", context, controller), true);
131
- assert.equal(await handleCognitiveRoutingProfileCommand("profile", context, controller), true);
132
- assert.equal(calls, 0);
133
- assert.equal(context.notifications.length, 2);
134
- });