@picassohq/cli 1.0.3 → 1.0.4

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 (40) hide show
  1. package/dist/build-info.json +1 -1
  2. package/dist/index.js +1591 -1251
  3. package/package.json +1 -1
  4. package/runtime/engine-manifest.json +22 -11
  5. package/runtime/packages/picasso-compaction/cordis.patch.yml +4 -0
  6. package/runtime/packages/picasso-compaction/index.js +623 -0
  7. package/runtime/packages/picasso-compaction/package.json +27 -0
  8. package/runtime/packages/picasso-lean-context/argument-repair.js +422 -0
  9. package/runtime/packages/picasso-lean-context/index.js +23 -2
  10. package/runtime/packages/picasso-model-router/connections.js +49 -3
  11. package/runtime/packages/picasso-model-router/index.js +32 -1
  12. package/runtime/packages/picasso-model-router/package.json +3 -1
  13. package/runtime/packages/picasso-model-router/thinking-default.js +212 -0
  14. package/runtime/packages/picasso-web-search/backends.js +245 -195
  15. package/runtime/packages/picasso-web-search/config.js +75 -27
  16. package/runtime/packages/picasso-web-search/cordis.patch.yml +2 -1
  17. package/runtime/packages/picasso-web-search/failure.js +7 -1
  18. package/runtime/packages/picasso-web-search/index.js +7 -5
  19. package/runtime/packages/picasso-web-search/package.json +6 -0
  20. package/runtime/packages/picasso-web-search/requests.js +339 -0
  21. package/runtime/packages/picasso-web-search/router.js +17 -12
  22. package/runtime/plugins/picasso-compaction/index.js +623 -0
  23. package/runtime/plugins/picasso-compaction/package.json +27 -0
  24. package/runtime/plugins/picasso-lean-context/argument-repair.js +422 -0
  25. package/runtime/plugins/picasso-lean-context/index.js +23 -2
  26. package/runtime/plugins/picasso-model-router/connections.js +49 -3
  27. package/runtime/plugins/picasso-model-router/index.js +32 -1
  28. package/runtime/plugins/picasso-model-router/package.json +3 -1
  29. package/runtime/plugins/picasso-model-router/thinking-default.js +212 -0
  30. package/runtime/plugins/picasso-provider-models/index.js +236 -4
  31. package/runtime/plugins/picasso-web-search/backends.js +245 -195
  32. package/runtime/plugins/picasso-web-search/config.js +75 -27
  33. package/runtime/plugins/picasso-web-search/failure.js +7 -1
  34. package/runtime/plugins/picasso-web-search/index.js +7 -5
  35. package/runtime/plugins/picasso-web-search/package.json +6 -0
  36. package/runtime/plugins/picasso-web-search/requests.js +339 -0
  37. package/runtime/plugins/picasso-web-search/router.js +17 -12
  38. package/runtime/relay/main.mjs +2776 -1494
  39. package/runtime/relay/model-listing.mjs +337 -26
  40. package/runtime/relay/versions-routes.mjs +65 -3
@@ -0,0 +1,212 @@
1
+ // A request for a model that cannot run with thinking off never leaves without a thinking level.
2
+ //
3
+ // The clients choose a level before they send (the TUI's `launchEffortOption`, the Mac's `ModelReasoning.swift`), but a
4
+ // request can reach the engine with none: a headless `picasso run`, a subagent, a schedule, a thread created by another
5
+ // client. For a model whose provider refuses "no thinking" the adapter then sends thinking disabled and the provider
6
+ // answers 400 (Z.ai code 1210: "This model always engages in thinking and cannot be disabled; please use low, high, or
7
+ // max"). `agent/pre-step` (index.js) therefore fills the step's level in the engine, on both surfaces.
8
+ //
9
+ // The rule is the one both clients follow (`@picasso/shared-home/model-reasoning`, `resolveReasoningLevel`), for the
10
+ // case with no pick in this chat:
11
+ //
12
+ // a model always thinks when the person's shared file lists it (`alwaysThinks`, learned from a provider 400), or
13
+ // its id is a known family (FAMILIES), or the levels the engine reports leave out off
14
+ // its level is the level saved for this model (`efforts["<route>/<model>"]`), else the default for every
15
+ // model (`defaultEffort`), each moved to the nearest level the model offers; else the
16
+ // model's own default; else the lowest level it offers; `high` when nothing is known
17
+ //
18
+ // A model that can run without thinking is left exactly as it was sent (no level stays no level), so this adds nothing
19
+ // to any request that worked before.
20
+ //
21
+ // A level the model does not offer is never sent either (owner 2026-11-17: a level saved for one connection's model,
22
+ // carried onto the managed route's model of the same name, failed every prompt with `does not support reasoning
23
+ // effort "max"`). When the engine reports the model's levels, a level it lacks moves to the nearest one it offers, and
24
+ // a model with no levels at all gets none (`supportedThinkingLevel`). A model the engine cannot describe keeps what
25
+ // was sent. OFF_LEVELS, LEVEL_ORDER and FAMILIES restate
26
+ // `packages/shared-home/src/model-reasoning.json`; test/thinking-default.test.mjs fails when they drift from it.
27
+
28
+ export const OFF_LEVELS = Object.freeze(['off', 'none', 'disabled', 'minimal-off']);
29
+ export const LEVEL_ORDER = Object.freeze(['minimal', 'low', 'medium', 'high', 'xhigh', 'max']);
30
+ export const FAMILIES = Object.freeze([
31
+ Object.freeze({ id: 'zai-glm-5.3', model: '(?:^|[^a-z0-9])glm-5[.p-]3(?![0-9])' }),
32
+ Object.freeze({ id: 'gemini-pro', model: '(?:^|[^a-z0-9])gemini-(?:2\\.5|[3-9](?:\\.[0-9]+)?)-pro(?![a-z0-9])|(?:^|[^a-z0-9])gemini-pro-latest(?![a-z0-9])' }),
33
+ Object.freeze({ id: 'minimax-m3.1-flash', model: '(?:^|[^a-z0-9])minimax-m3[.p]1-flash(?![a-z0-9])' }),
34
+ ]);
35
+
36
+ const familyPatterns = FAMILIES.map((family) => new RegExp(family.model, 'iu'));
37
+ const nonEmpty = (value) => typeof value === 'string' && value.length > 0;
38
+ const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
39
+
40
+ /** Words that mean "no thinking". */
41
+ export const isOffLevel = (level) => nonEmpty(level) && OFF_LEVELS.includes(level.toLowerCase());
42
+
43
+ /**
44
+ * Whether a model must never run with thinking off. `offered`: the levels the engine reports (undefined = unknown,
45
+ * [] = the model has no reasoning); `learned`: the shared file's `alwaysThinks` refs.
46
+ */
47
+ export function modelAlwaysThinks({ provider, model, offered, learned }) {
48
+ if (Array.isArray(learned) && learned.includes(`${provider}/${model}`)) return true;
49
+ if (familyPatterns.some((pattern) => pattern.test(model))) return true;
50
+ return Array.isArray(offered) && offered.length > 0 && !offered.some(isOffLevel);
51
+ }
52
+
53
+ const rank = (level) => LEVEL_ORDER.indexOf(level.toLowerCase());
54
+
55
+ /** The offered thinking level nearest `level` (exact first, then by level order; ties go to the higher one). */
56
+ function nearest(level, offered) {
57
+ if (isOffLevel(level)) return undefined;
58
+ if (offered === undefined) return level;
59
+ const allowed = offered.filter((id) => !isOffLevel(id));
60
+ const exact = allowed.find((id) => id.toLowerCase() === level.toLowerCase());
61
+ if (exact !== undefined) return exact;
62
+ const wanted = rank(level);
63
+ if (wanted < 0) return undefined;
64
+ let best;
65
+ for (const id of allowed) {
66
+ const at = rank(id);
67
+ if (at < 0) continue;
68
+ const distance = Math.abs(at - wanted);
69
+ if (best === undefined || distance < best.distance || (distance === best.distance && at > best.rank)) best = { id, distance, rank: at };
70
+ }
71
+ return best?.id;
72
+ }
73
+
74
+ /**
75
+ * What an explicit `level` becomes on a model that offers `offered` (the engine's levels; undefined = unknown):
76
+ * undefined = send it as it is, a string = send that level instead (the nearest one offered, ties up), null = send no
77
+ * level (the model has no reasoning, or nothing near it). An off word on a model that offers no off word is left to
78
+ * `requiredThinkingLevel` (the model always thinks).
79
+ */
80
+ export function supportedThinkingLevel(level, offered) {
81
+ if (!nonEmpty(level) || !Array.isArray(offered)) return undefined;
82
+ if (offered.length === 0) return null;
83
+ const exact = offered.find((id) => id.toLowerCase() === level.toLowerCase());
84
+ if (exact !== undefined) return exact === level ? undefined : exact;
85
+ if (isOffLevel(level)) return offered.find(isOffLevel);
86
+ return nearest(level, offered) ?? null;
87
+ }
88
+
89
+ /**
90
+ * The level a request with no usable level must carry, or undefined when it needs none (the model can run without
91
+ * thinking, or has no reasoning at all). `settings`: the shared model-connections document (`efforts`, `defaultEffort`,
92
+ * `alwaysThinks`); `catalogueDefault`: the model's own default level as the engine reports it.
93
+ */
94
+ export function requiredThinkingLevel({ provider, model, offered, catalogueDefault, settings }) {
95
+ if (!nonEmpty(provider) || !nonEmpty(model)) return undefined;
96
+ if (Array.isArray(offered) && offered.length === 0) return undefined;
97
+ const saved = isRecord(settings) ? settings : {};
98
+ if (!modelAlwaysThinks({ provider, model, offered, learned: saved.alwaysThinks })) return undefined;
99
+ const perModel = isRecord(saved.efforts) ? saved.efforts[`${provider}/${model}`] : undefined;
100
+ for (const level of [perModel, saved.defaultEffort]) {
101
+ if (!nonEmpty(level)) continue;
102
+ const usable = nearest(level, offered);
103
+ if (usable !== undefined) return usable;
104
+ }
105
+ if (nonEmpty(catalogueDefault) && !isOffLevel(catalogueDefault) && (offered === undefined || offered.includes(catalogueDefault))) return catalogueDefault;
106
+ if (offered !== undefined) return offered.find((id) => !isOffLevel(id));
107
+ return 'high';
108
+ }
109
+
110
+ /**
111
+ * The `agent/pre-step` guard. `deps`: `{ llm: () => registry | undefined, settings: () => document, log }`. The levels
112
+ * a model offers are asked of the engine once per model (`resolveModelInfo`); a model the engine cannot describe is
113
+ * decided by the shared file and the known families alone.
114
+ */
115
+ export function createThinkingGuard({ llm, settings, log = () => {} }) {
116
+ const known = new Map();
117
+ /** `<route>/<model>/<level>` corrections already logged (once each, not every step). */
118
+ const corrected = new Set();
119
+
120
+ async function describe(provider, model) {
121
+ const ref = `${provider}/${model}`;
122
+ if (known.has(ref)) return known.get(ref);
123
+ let described;
124
+ try {
125
+ const registry = llm();
126
+ if (registry !== undefined && registry !== null && typeof registry.resolveModelInfo === 'function') {
127
+ const info = await registry.resolveModelInfo(provider, model);
128
+ const efforts = Array.isArray(info?.reasoning?.efforts) ? info.reasoning.efforts.map((effort) => effort?.id).filter(nonEmpty) : [];
129
+ const fallback = info?.reasoning?.defaultEffort;
130
+ described = { offered: efforts, ...(nonEmpty(fallback) ? { catalogueDefault: fallback } : {}) };
131
+ known.set(ref, described);
132
+ }
133
+ } catch {
134
+ described = undefined; // not cached: the engine may be able to describe it on a later step
135
+ }
136
+ return described;
137
+ }
138
+
139
+ return {
140
+ /** The level this step's selection needs and does not have; undefined when it is fine as it is. */
141
+ async levelFor(selection) {
142
+ if (!isRecord(selection) || !nonEmpty(selection.provider) || !nonEmpty(selection.model)) return undefined;
143
+ if (nonEmpty(selection.reasoningEffort) && !isOffLevel(selection.reasoningEffort)) return undefined;
144
+ const described = await describe(selection.provider, selection.model);
145
+ let saved;
146
+ try {
147
+ saved = settings();
148
+ } catch {
149
+ saved = undefined;
150
+ }
151
+ return requiredThinkingLevel({
152
+ provider: selection.provider,
153
+ model: selection.model,
154
+ ...(described === undefined ? {} : { offered: described.offered }),
155
+ ...(described?.catalogueDefault === undefined ? {} : { catalogueDefault: described.catalogueDefault }),
156
+ settings: saved,
157
+ });
158
+ },
159
+
160
+ /**
161
+ * The step's explicit level checked against the levels the engine reports for its model (see
162
+ * `supportedThinkingLevel`); undefined when there is nothing to change.
163
+ */
164
+ async correctionFor(selection) {
165
+ if (!isRecord(selection) || !nonEmpty(selection.provider) || !nonEmpty(selection.model) || !nonEmpty(selection.reasoningEffort)) return undefined;
166
+ const described = await describe(selection.provider, selection.model);
167
+ return supportedThinkingLevel(selection.reasoningEffort, described?.offered);
168
+ },
169
+
170
+ /** Sets the level on the step's own selection object (what the engine sends this step). True when it changed. */
171
+ async apply(selection) {
172
+ const correction = await this.correctionFor(selection);
173
+ if (correction !== undefined) {
174
+ const was = selection.reasoningEffort;
175
+ try {
176
+ if (correction === null) delete selection.reasoningEffort;
177
+ else selection.reasoningEffort = correction;
178
+ } catch (error) {
179
+ log(`picasso-model-router: the thinking level for ${selection.provider}/${selection.model} could not be corrected (${error instanceof Error ? error.message : String(error)}).`);
180
+ return false;
181
+ }
182
+ if (selection.reasoningEffort === was) return false;
183
+ const ref = `${selection.provider}/${selection.model}/${was}`;
184
+ if (!corrected.has(ref)) {
185
+ corrected.add(ref);
186
+ log(`picasso-model-router: ${selection.provider}/${selection.model} does not offer thinking level "${was}"; ${correction === null ? 'sending none' : `sending "${correction}"`}.`);
187
+ }
188
+ // A model that always thinks still gets a level when the correction left it with none.
189
+ if (correction === null) {
190
+ const required = await this.levelFor(selection);
191
+ if (required !== undefined) {
192
+ try {
193
+ selection.reasoningEffort = required;
194
+ } catch {
195
+ // left with none: the model's own default
196
+ }
197
+ }
198
+ }
199
+ return true;
200
+ }
201
+ const level = await this.levelFor(selection);
202
+ if (level === undefined) return false;
203
+ try {
204
+ selection.reasoningEffort = level;
205
+ } catch (error) {
206
+ log(`picasso-model-router: the thinking level for ${selection.provider}/${selection.model} could not be set (${error instanceof Error ? error.message : String(error)}).`);
207
+ return false;
208
+ }
209
+ return selection.reasoningEffort === level;
210
+ },
211
+ };
212
+ }