min-agent 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (169) hide show
  1. package/README.md +18 -18
  2. package/dist/cli.js +538 -12
  3. package/docs/API.md +6 -6
  4. package/package.json +6 -6
  5. package/skills/self-config/SKILL.md +4 -2
  6. package/skills/self-config/reference.md +4 -1
  7. package/dist/agent.js +0 -1388
  8. package/dist/assistant-stream.js +0 -131
  9. package/dist/cli/commands/chat.js +0 -13
  10. package/dist/cli/commands/ctx.js +0 -7
  11. package/dist/cli/commands/exec.js +0 -35
  12. package/dist/cli/commands/history.js +0 -58
  13. package/dist/cli/commands/index.js +0 -249
  14. package/dist/cli/commands/init.js +0 -18
  15. package/dist/cli/commands/mcp.js +0 -173
  16. package/dist/cli/commands/memory.js +0 -87
  17. package/dist/cli/commands/models.js +0 -21
  18. package/dist/cli/commands/permission.js +0 -12
  19. package/dist/cli/commands/rules.js +0 -33
  20. package/dist/cli/commands/sandbox.js +0 -13
  21. package/dist/cli/commands/serve.js +0 -9
  22. package/dist/cli/commands/setup.js +0 -56
  23. package/dist/cli/commands/shared.js +0 -25
  24. package/dist/cli/commands/skills.js +0 -119
  25. package/dist/cli/commands/think.js +0 -12
  26. package/dist/cli/commands/update.js +0 -7
  27. package/dist/cli/commands/write-config.js +0 -52
  28. package/dist/cli/errors.js +0 -36
  29. package/dist/cli/exec-prompt.js +0 -26
  30. package/dist/cli/option-helpers.js +0 -65
  31. package/dist/cli/program.js +0 -223
  32. package/dist/cli/setup/detect.js +0 -17
  33. package/dist/cli/setup/flags.js +0 -12
  34. package/dist/cli/setup/flow.js +0 -108
  35. package/dist/cli/setup/provider-form.js +0 -102
  36. package/dist/cli/setup/ui.js +0 -534
  37. package/dist/clipboard.js +0 -142
  38. package/dist/code-mode.js +0 -184
  39. package/dist/compaction.js +0 -644
  40. package/dist/config.js +0 -363
  41. package/dist/confirm.js +0 -172
  42. package/dist/context-window.js +0 -256
  43. package/dist/ctx-cli.js +0 -30
  44. package/dist/ctx.js +0 -80
  45. package/dist/doom-loop.js +0 -278
  46. package/dist/fetch-timeout.js +0 -152
  47. package/dist/http-approvals.js +0 -60
  48. package/dist/http.js +0 -119
  49. package/dist/instructions.js +0 -196
  50. package/dist/logger.js +0 -95
  51. package/dist/markdown.js +0 -259
  52. package/dist/mcp.js +0 -1036
  53. package/dist/memory-cli.js +0 -33
  54. package/dist/memory.js +0 -295
  55. package/dist/model-catalog.js +0 -285
  56. package/dist/ollama-model.js +0 -234
  57. package/dist/ollama-openai-bridge.js +0 -383
  58. package/dist/output.js +0 -76
  59. package/dist/paste-handler.js +0 -41
  60. package/dist/permission-cli.js +0 -40
  61. package/dist/plugins.js +0 -131
  62. package/dist/pricing.js +0 -119
  63. package/dist/provider.js +0 -63
  64. package/dist/question-format.js +0 -60
  65. package/dist/reasoning-stream.js +0 -158
  66. package/dist/sandbox-cli.js +0 -79
  67. package/dist/sandbox.js +0 -403
  68. package/dist/save-throttle.js +0 -45
  69. package/dist/scope.js +0 -23
  70. package/dist/serve/common.js +0 -425
  71. package/dist/serve/routes-chat.js +0 -367
  72. package/dist/serve/routes-mcp.js +0 -212
  73. package/dist/serve/routes-memory.js +0 -95
  74. package/dist/serve/routes-meta.js +0 -268
  75. package/dist/serve/routes-sessions.js +0 -61
  76. package/dist/serve/routes-skills.js +0 -70
  77. package/dist/serve.js +0 -138
  78. package/dist/sessions.js +0 -265
  79. package/dist/skills.js +0 -599
  80. package/dist/structured-output.js +0 -29
  81. package/dist/synthetic.js +0 -7
  82. package/dist/think-cli.js +0 -36
  83. package/dist/thinking-wire.js +0 -239
  84. package/dist/thinking.js +0 -166
  85. package/dist/title-gen.js +0 -55
  86. package/dist/token-display.js +0 -39
  87. package/dist/tool-display.js +0 -178
  88. package/dist/tool-output.js +0 -126
  89. package/dist/tools/apply_patch.js +0 -265
  90. package/dist/tools/atomic-file.js +0 -35
  91. package/dist/tools/backend.js +0 -61
  92. package/dist/tools/bash.js +0 -231
  93. package/dist/tools/code_search.js +0 -98
  94. package/dist/tools/edit.js +0 -68
  95. package/dist/tools/explore.js +0 -232
  96. package/dist/tools/glob.js +0 -40
  97. package/dist/tools/grep.js +0 -174
  98. package/dist/tools/index.js +0 -34
  99. package/dist/tools/question.js +0 -54
  100. package/dist/tools/read.js +0 -109
  101. package/dist/tools/search-searxng.js +0 -223
  102. package/dist/tools/search-serper.js +0 -189
  103. package/dist/tools/task.js +0 -165
  104. package/dist/tools/todo.js +0 -213
  105. package/dist/tools/web_fetch.js +0 -195
  106. package/dist/tools/web_search.js +0 -228
  107. package/dist/tools/write.js +0 -55
  108. package/dist/tui/App.js +0 -138
  109. package/dist/tui/ConfirmBar.js +0 -66
  110. package/dist/tui/CtxPicker.js +0 -68
  111. package/dist/tui/InputBar.js +0 -618
  112. package/dist/tui/MessageList.js +0 -718
  113. package/dist/tui/ModelPicker.js +0 -113
  114. package/dist/tui/QuestionBar.js +0 -136
  115. package/dist/tui/SessionPicker.js +0 -79
  116. package/dist/tui/Spinner.js +0 -6
  117. package/dist/tui/StatusBar.js +0 -22
  118. package/dist/tui/ThinkPicker.js +0 -75
  119. package/dist/tui/agent-runner.js +0 -223
  120. package/dist/tui/bracketed-paste.js +0 -37
  121. package/dist/tui/caret-pos.js +0 -179
  122. package/dist/tui/caret.js +0 -69
  123. package/dist/tui/click-count.js +0 -13
  124. package/dist/tui/diff-view.js +0 -61
  125. package/dist/tui/drag-state.js +0 -49
  126. package/dist/tui/hydrate.js +0 -129
  127. package/dist/tui/index.js +0 -264
  128. package/dist/tui/input-history.js +0 -125
  129. package/dist/tui/layout.js +0 -105
  130. package/dist/tui/mouse.js +0 -46
  131. package/dist/tui/overlay-input.js +0 -12
  132. package/dist/tui/paste-draft.js +0 -173
  133. package/dist/tui/prompt-queue.js +0 -24
  134. package/dist/tui/selection.js +0 -232
  135. package/dist/tui/session-switch.js +0 -28
  136. package/dist/tui/slash-commands.js +0 -129
  137. package/dist/tui/slash-handler.js +0 -615
  138. package/dist/tui/text-width.js +0 -113
  139. package/dist/tui/theme.js +0 -12
  140. package/dist/tui/token-info.js +0 -7
  141. package/dist/tui/tool-children.js +0 -19
  142. package/dist/tui/types.js +0 -1
  143. package/dist/tui/undo-stack.js +0 -14
  144. package/dist/tui/use-sgr-mouse.js +0 -29
  145. package/dist/tui-chat.js +0 -478
  146. package/dist/updater.js +0 -116
  147. package/dist/xml-search.js +0 -194
  148. package/docs/superpowers/plans/2026-08-16-batch1-tui-improvements.md +0 -1510
  149. package/docs/superpowers/plans/2026-08-16-batch2-cli-tools-api.md +0 -2105
  150. package/docs/superpowers/plans/2026-08-16-batch3-config-engineering.md +0 -1595
  151. package/docs/superpowers/plans/2026-08-16-input-caret.md +0 -782
  152. package/docs/superpowers/plans/2026-08-20-tui-completeness.md +0 -873
  153. package/docs/superpowers/plans/2026-08-20-unified-tui-default.md +0 -631
  154. package/docs/superpowers/plans/2026-08-23-cli-setup.md +0 -501
  155. package/docs/superpowers/plans/2026-08-23-input-paste-attachments.md +0 -475
  156. package/docs/superpowers/plans/2026-08-23-thinking-wire-profile.md +0 -450
  157. package/docs/superpowers/specs/2026-08-16-batch1-tui-improvements-design.md +0 -183
  158. package/docs/superpowers/specs/2026-08-16-batch2-cli-tools-api-design.md +0 -220
  159. package/docs/superpowers/specs/2026-08-16-batch3-config-engineering-design.md +0 -196
  160. package/docs/superpowers/specs/2026-08-16-input-caret-design.md +0 -63
  161. package/docs/superpowers/specs/2026-08-17-mouse-selection-design.md +0 -116
  162. package/docs/superpowers/specs/2026-08-20-config-http-alignment-design.md +0 -47
  163. package/docs/superpowers/specs/2026-08-20-mcp-plugins-alignment-design.md +0 -37
  164. package/docs/superpowers/specs/2026-08-20-sandbox-permissions-design.md +0 -68
  165. package/docs/superpowers/specs/2026-08-20-tui-completeness-design.md +0 -273
  166. package/docs/superpowers/specs/2026-08-20-unified-tui-default-design.md +0 -165
  167. package/docs/superpowers/specs/2026-08-23-cli-setup-design.md +0 -282
  168. package/docs/superpowers/specs/2026-08-23-input-paste-attachments-design.md +0 -174
  169. package/docs/superpowers/specs/2026-08-23-thinking-wire-profile-design.md +0 -140
@@ -1,239 +0,0 @@
1
- import { AsyncLocalStorage } from "async_hooks";
2
- import { readFileSync, mkdirSync, existsSync } from "fs";
3
- import path from "path";
4
- import { getActiveProvider, getConfigDir, getEffectiveConfig } from "./config.js";
5
- import { fetchOllamaNativeChat, readFetchBody } from "./ollama-openai-bridge.js";
6
- import { atomicWriteFileSync } from "./tools/atomic-file.js";
7
- export const thinkingRequestStore = new AsyncLocalStorage();
8
- export const THINKING_WIRE_VERSION = 1;
9
- export const THINKING_WIRE_TTL = 7 * 24 * 60 * 60 * 1000;
10
- export const DEFAULT_THINKING_WIRE = {
11
- version: THINKING_WIRE_VERSION,
12
- thinkingType: "enabled-disabled",
13
- effort: "reasoning_effort",
14
- };
15
- const memoryCache = new Map();
16
- function isRecord(value) {
17
- return Boolean(value) && typeof value === "object" && !Array.isArray(value);
18
- }
19
- function isThinkingTypeMode(value) {
20
- return value === "enabled-disabled" || value === "adaptive-disabled" || value === "omit";
21
- }
22
- function isEffortMode(value) {
23
- return value === "reasoning_effort" || value === "omit";
24
- }
25
- function isProfile(value) {
26
- if (!isRecord(value))
27
- return false;
28
- return (value.version === THINKING_WIRE_VERSION &&
29
- isThinkingTypeMode(value.thinkingType) &&
30
- isEffortMode(value.effort) &&
31
- typeof value.timestamp === "number" &&
32
- Number.isFinite(value.timestamp));
33
- }
34
- function cacheFile() {
35
- return path.join(getConfigDir(), "thinking-wire-cache.json");
36
- }
37
- function loadDiskCache() {
38
- const file = cacheFile();
39
- if (!existsSync(file))
40
- return {};
41
- try {
42
- const parsed = JSON.parse(readFileSync(file, "utf-8"));
43
- if (!isRecord(parsed))
44
- return {};
45
- const out = {};
46
- for (const [key, value] of Object.entries(parsed)) {
47
- if (isProfile(value))
48
- out[key] = value;
49
- }
50
- return out;
51
- }
52
- catch {
53
- return {};
54
- }
55
- }
56
- function saveDiskCache(cache) {
57
- const file = cacheFile();
58
- mkdirSync(path.dirname(file), { recursive: true });
59
- atomicWriteFileSync(file, JSON.stringify(cache));
60
- }
61
- function liveProfile(entry, now) {
62
- if (entry.version !== THINKING_WIRE_VERSION)
63
- return null;
64
- if (now - entry.timestamp > THINKING_WIRE_TTL)
65
- return null;
66
- return entry;
67
- }
68
- export function thinkingWireCacheKey(host, modelId) {
69
- const h = host.trim().toLowerCase();
70
- const m = modelId.trim().toLowerCase();
71
- if (!h)
72
- return m;
73
- if (!m)
74
- return h;
75
- return `${h}::${m}`;
76
- }
77
- export function inferThinkingWire(modelId, host, providerType) {
78
- if (providerType === "ollama") {
79
- return { thinkingType: "omit", effort: "reasoning_effort" };
80
- }
81
- const haystack = `${modelId} ${host}`.toLowerCase();
82
- if (haystack.includes("minimax")) {
83
- return { thinkingType: "adaptive-disabled", effort: "reasoning_effort" };
84
- }
85
- if (providerType === "openai") {
86
- return { thinkingType: "omit", effort: "reasoning_effort" };
87
- }
88
- return { thinkingType: DEFAULT_THINKING_WIRE.thinkingType, effort: DEFAULT_THINKING_WIRE.effort };
89
- }
90
- function readCachedProfile(key, now) {
91
- const memory = memoryCache.get(key);
92
- if (memory) {
93
- const live = liveProfile(memory, now);
94
- if (live)
95
- return live;
96
- memoryCache.delete(key);
97
- }
98
- const disk = loadDiskCache()[key];
99
- if (!disk)
100
- return null;
101
- const live = liveProfile(disk, now);
102
- if (!live)
103
- return null;
104
- memoryCache.set(key, live);
105
- return live;
106
- }
107
- export function resolveThinkingWireProfile(host, modelId, providerType, now = Date.now()) {
108
- const cached = readCachedProfile(thinkingWireCacheKey(host, modelId), now);
109
- if (cached)
110
- return cached;
111
- return {
112
- version: THINKING_WIRE_VERSION,
113
- ...inferThinkingWire(modelId, host, providerType),
114
- timestamp: now,
115
- };
116
- }
117
- export function saveLearnedThinkingWire(host, modelId, profile, now = Date.now()) {
118
- const entry = {
119
- version: THINKING_WIRE_VERSION,
120
- thinkingType: profile.thinkingType,
121
- effort: profile.effort,
122
- timestamp: profile.timestamp ?? now,
123
- };
124
- const key = thinkingWireCacheKey(host, modelId);
125
- memoryCache.set(key, entry);
126
- const cache = loadDiskCache();
127
- cache[key] = entry;
128
- saveDiskCache(cache);
129
- return entry;
130
- }
131
- export function clearThinkingWireCache() {
132
- memoryCache.clear();
133
- }
134
- export function applyThinkingToChatBody(body, spec, profile = DEFAULT_THINKING_WIRE) {
135
- const next = { ...body };
136
- if (profile.effort === "omit")
137
- delete next.reasoning_effort;
138
- else
139
- next.reasoning_effort = spec.reasoningEffort;
140
- if (profile.thinkingType === "omit")
141
- delete next.thinking;
142
- else {
143
- const on = profile.thinkingType === "adaptive-disabled" ? "adaptive" : "enabled";
144
- next.thinking = { type: spec.thinkingEnabled ? on : "disabled" };
145
- }
146
- return next;
147
- }
148
- function splitAllowed(raw) {
149
- return new Set(raw
150
- .split(",")
151
- .map((part) => part
152
- .trim()
153
- .replace(/^['"]|['"]$/g, "")
154
- .toLowerCase())
155
- .filter(Boolean));
156
- }
157
- export function parseThinkingWireHint(text) {
158
- const allowedMatch = text.match(/thinking\.type[\s\S]*?allowed:\s*([^)]+)/i);
159
- if (allowedMatch?.[1]) {
160
- const allowed = splitAllowed(allowedMatch[1]);
161
- if (allowed.has("adaptive") && allowed.has("disabled"))
162
- return { thinkingType: "adaptive-disabled" };
163
- if (allowed.has("enabled") && allowed.has("disabled"))
164
- return { thinkingType: "enabled-disabled" };
165
- }
166
- if (/unknown parameter[:\s]+['"`]?thinking['"`]?(?![\w.])/i.test(text))
167
- return { thinkingType: "omit" };
168
- if (/unknown parameter[:\s]+['"`]?reasoning_effort['"`]?(?![\w.])/i.test(text))
169
- return { effort: "omit" };
170
- return null;
171
- }
172
- function hostnameFromInput(input) {
173
- try {
174
- const raw = typeof input === "string" ? input : input instanceof URL ? input.href : input.url;
175
- return new URL(raw).hostname;
176
- }
177
- catch {
178
- return "";
179
- }
180
- }
181
- function rebuild400(response, text) {
182
- return new Response(text, {
183
- status: 400,
184
- statusText: response.statusText,
185
- headers: response.headers,
186
- });
187
- }
188
- function profileUnchanged(current, next) {
189
- return current.thinkingType === next.thinkingType && current.effort === next.effort;
190
- }
191
- export async function fetchWithThinkingWire(inner, input, init, opts) {
192
- if (!init?.body)
193
- return inner(input, init);
194
- const rawBody = await readFetchBody(init.body);
195
- if (rawBody == null)
196
- return inner(input, init);
197
- let parsed;
198
- try {
199
- parsed = JSON.parse(rawBody);
200
- }
201
- catch {
202
- return inner(input, init);
203
- }
204
- if (!parsed || typeof parsed !== "object" || Array.isArray(parsed))
205
- return inner(input, init);
206
- const spec = thinkingRequestStore.getStore();
207
- const providerType = opts?.providerType ?? getActiveProvider(getEffectiveConfig())?.type;
208
- const body = parsed;
209
- if (providerType === "ollama")
210
- return fetchOllamaNativeChat(inner, input, init, body, spec);
211
- if (!spec)
212
- return inner(input, init);
213
- const host = hostnameFromInput(input);
214
- const modelId = typeof body.model === "string" ? body.model : "";
215
- const profile = resolveThinkingWireProfile(host, modelId, providerType);
216
- const first = await inner(input, {
217
- ...init,
218
- body: JSON.stringify(applyThinkingToChatBody(body, spec, profile)),
219
- });
220
- if (first.status !== 400)
221
- return first;
222
- const text = await first.text();
223
- const hint = parseThinkingWireHint(text);
224
- if (!hint)
225
- return rebuild400(first, text);
226
- const next = {
227
- version: THINKING_WIRE_VERSION,
228
- thinkingType: hint.thinkingType ?? profile.thinkingType,
229
- effort: hint.effort ?? profile.effort,
230
- timestamp: Date.now(),
231
- };
232
- if (profileUnchanged(profile, next))
233
- return rebuild400(first, text);
234
- saveLearnedThinkingWire(host, modelId, next);
235
- return inner(input, {
236
- ...init,
237
- body: JSON.stringify(applyThinkingToChatBody(body, spec, next)),
238
- });
239
- }
package/dist/thinking.js DELETED
@@ -1,166 +0,0 @@
1
- import { getEffectiveConfig, loadConfig, loadProjectConfig, saveConfig, saveProjectConfig, getActiveProvider, parseThinkingEffort, } from "./config.js";
2
- import { getCachedModelCatalog, getModelCatalog } from "./model-catalog.js";
3
- import { getCachedOllamaModel, getOllamaModel, thinkingChoicesFromOllama } from "./ollama-model.js";
4
- import { applyThinkingToChatBody, thinkingRequestStore } from "./thinking-wire.js";
5
- export { parseThinkingEffort, applyThinkingToChatBody, thinkingRequestStore };
6
- export const THINKING_EFFORTS = ["off", "low", "medium", "high", "max"];
7
- export const DEFAULT_THINKING_EFFORT = "medium";
8
- let thinkingOverride;
9
- export function setThinkingOverride(effort) {
10
- thinkingOverride = effort;
11
- }
12
- export function getThinkingOverride() {
13
- return thinkingOverride;
14
- }
15
- export function thinkingEffortLabel(effort) {
16
- return effort;
17
- }
18
- export function thinkingChoiceIndex(effort, choices = THINKING_EFFORTS) {
19
- const list = choices.length > 0 ? choices : THINKING_EFFORTS;
20
- const clamped = clampThinkingEffort(effort, list);
21
- const i = list.indexOf(clamped);
22
- return i >= 0 ? i : 0;
23
- }
24
- export function thinkingChoicesFromReasoning(info) {
25
- const set = new Set();
26
- if (info.toggle || info.efforts.includes("none"))
27
- set.add("off");
28
- for (const raw of info.efforts) {
29
- const mapped = parseThinkingEffort(raw);
30
- if (mapped)
31
- set.add(mapped);
32
- }
33
- const enabled = THINKING_EFFORTS.filter((effort) => effort !== "off" && set.has(effort));
34
- // Toggle-only catalog rows must not collapse the picker to off.
35
- if (enabled.length === 0)
36
- return [...THINKING_EFFORTS];
37
- return THINKING_EFFORTS.filter((effort) => set.has(effort));
38
- }
39
- export function thinkingChoicesForModel(modelId) {
40
- const provider = getActiveProvider(getEffectiveConfig());
41
- if (provider?.type === "ollama") {
42
- if (!modelId)
43
- return [...THINKING_EFFORTS];
44
- const cached = getCachedOllamaModel(modelId, provider.baseURL);
45
- if (!cached)
46
- return [...THINKING_EFFORTS];
47
- return thinkingChoicesFromOllama(cached);
48
- }
49
- if (!modelId)
50
- return [...THINKING_EFFORTS];
51
- const entry = getCachedModelCatalog(modelId);
52
- if (!entry)
53
- return [...THINKING_EFFORTS];
54
- return thinkingChoicesFromReasoning(entry.reasoning);
55
- }
56
- export async function refreshThinkingChoices(modelId, hint) {
57
- const provider = getActiveProvider(getEffectiveConfig());
58
- const type = hint?.type ?? provider?.type;
59
- const baseURL = hint?.baseURL ?? provider?.baseURL;
60
- if (modelId) {
61
- if (type === "ollama")
62
- await getOllamaModel(modelId, baseURL);
63
- else
64
- await getModelCatalog(modelId, baseURL);
65
- }
66
- return thinkingChoicesForModel(modelId);
67
- }
68
- export function clampThinkingEffort(effort, choices = THINKING_EFFORTS) {
69
- if (choices.length === 0 || choices.includes(effort))
70
- return effort;
71
- if (choices.includes("medium"))
72
- return "medium";
73
- if (choices.includes("high"))
74
- return "high";
75
- const enabled = choices.filter((item) => item !== "off");
76
- if (enabled.length > 0)
77
- return enabled[Math.floor((enabled.length - 1) / 2)];
78
- if (choices.includes("off"))
79
- return "off";
80
- return DEFAULT_THINKING_EFFORT;
81
- }
82
- export function thinkingSourceLabel(source) {
83
- if (source === "cli")
84
- return "本次启动参数";
85
- if (source === "project")
86
- return "项目";
87
- if (source === "global")
88
- return "全局";
89
- return "默认";
90
- }
91
- export function resolveThinkingEffort(runOverride, modelId) {
92
- let thinking;
93
- let source;
94
- if (runOverride) {
95
- thinking = runOverride;
96
- source = "cli";
97
- }
98
- else {
99
- const override = getThinkingOverride();
100
- if (override) {
101
- thinking = override;
102
- source = "cli";
103
- }
104
- else {
105
- const snap = getThinkingSnapshot();
106
- thinking = snap.thinking ?? DEFAULT_THINKING_EFFORT;
107
- source = snap.source;
108
- }
109
- }
110
- const id = modelId ?? getActiveProvider(getEffectiveConfig())?.defaultModel;
111
- return { thinking: clampThinkingEffort(thinking, thinkingChoicesForModel(id)), source };
112
- }
113
- export function getThinkingSnapshot() {
114
- const project = parseThinkingEffort(loadProjectConfig().thinking);
115
- if (project !== undefined)
116
- return { thinking: project, source: "project" };
117
- const global = parseThinkingEffort(loadConfig().thinking);
118
- if (global !== undefined)
119
- return { thinking: global, source: "global" };
120
- return { thinking: undefined, source: null };
121
- }
122
- function clearProjectThinking() {
123
- const project = loadProjectConfig();
124
- if (project.thinking === undefined)
125
- return;
126
- const { thinking: _removed, ...rest } = project;
127
- saveProjectConfig(rest);
128
- }
129
- export function setThinkingEffort(effort, scope) {
130
- if (scope === "project") {
131
- saveProjectConfig({ ...loadProjectConfig(), thinking: effort });
132
- return;
133
- }
134
- saveConfig({ ...loadConfig(), thinking: effort });
135
- // A leftover project value (including off) would keep shadowing the global file.
136
- clearProjectThinking();
137
- }
138
- export function thinkingPayload() {
139
- const { thinking, source } = resolveThinkingEffort();
140
- return {
141
- thinking,
142
- source,
143
- label: thinkingEffortLabel(thinking),
144
- };
145
- }
146
- export function toWireEffort(effort, providerType, modelId) {
147
- if (effort === "off")
148
- return "none";
149
- if (effort !== "max")
150
- return effort;
151
- const catalog = modelId ? getCachedModelCatalog(modelId) : undefined;
152
- const supported = catalog?.reasoning.efforts ?? [];
153
- if (supported.includes("max"))
154
- return "max";
155
- if (supported.includes("xhigh") || providerType === "openai")
156
- return "xhigh";
157
- return "max";
158
- }
159
- export function resolveThinkingRequest(opts) {
160
- const { thinking } = resolveThinkingEffort(opts?.runOverride, opts?.modelId);
161
- const providerType = opts?.providerType ?? getActiveProvider(getEffectiveConfig())?.type;
162
- return {
163
- reasoningEffort: toWireEffort(thinking, providerType, opts?.modelId),
164
- thinkingEnabled: thinking !== "off",
165
- };
166
- }
package/dist/title-gen.js DELETED
@@ -1,55 +0,0 @@
1
- import { generateText } from "ai";
2
- /**
3
- * Auto-generate a short title for a conversation session.
4
- *
5
- * Based on opencode's title agent — uses the LLM to produce a concise
6
- * title from the first user message and assistant response.
7
- */
8
- const TITLE_PROMPT = `Generate a very short title (max 50 chars) for this conversation.
9
- Output ONLY the title text, nothing else. No quotes, no prefix.
10
- The title should capture the main topic or intent.`;
11
- export async function generateTitle(model, messages) {
12
- // Need at least one user message
13
- const userMsg = messages.find((m) => m.role === "user");
14
- if (!userMsg)
15
- return null;
16
- const userContent = typeof userMsg.content === "string"
17
- ? userMsg.content
18
- : Array.isArray(userMsg.content)
19
- ? userMsg.content
20
- .filter((p) => "text" in p)
21
- .map((p) => p.text ?? "")
22
- .join(" ")
23
- : "";
24
- if (!userContent.trim())
25
- return null;
26
- // Include first assistant response if available for better context
27
- const assistantMsg = messages.find((m) => m.role === "assistant");
28
- const assistantContent = assistantMsg
29
- ? typeof assistantMsg.content === "string"
30
- ? assistantMsg.content.slice(0, 200)
31
- : ""
32
- : "";
33
- const context = assistantContent
34
- ? `User: ${userContent.slice(0, 300)}\nAssistant: ${assistantContent}`
35
- : `User: ${userContent.slice(0, 300)}`;
36
- try {
37
- const result = await generateText({
38
- model,
39
- messages: [
40
- { role: "system", content: TITLE_PROMPT },
41
- { role: "user", content: context },
42
- ],
43
- temperature: 0.5,
44
- maxOutputTokens: 30,
45
- });
46
- const title = result.text
47
- .trim()
48
- .replace(/^["']|["']$/g, "")
49
- .slice(0, 60);
50
- return title || null;
51
- }
52
- catch {
53
- return null;
54
- }
55
- }
@@ -1,39 +0,0 @@
1
- export function formatTokenCount(n) {
2
- const v = Math.max(0, Math.round(n));
3
- if (v < 1000)
4
- return String(v);
5
- if (v < 100_000)
6
- return `${(v / 1000).toFixed(1).replace(/\.0$/, "")}k`;
7
- if (v < 1_000_000)
8
- return `${Math.round(v / 1000)}k`;
9
- if (v < 10_000_000)
10
- return `${(v / 1_000_000).toFixed(1).replace(/\.0$/, "")}M`;
11
- return `${Math.round(v / 1_000_000)}M`;
12
- }
13
- export function contextUsagePercent(context, contextWindow) {
14
- if (context <= 0 || contextWindow <= 0)
15
- return null;
16
- return Math.round((context / contextWindow) * 100);
17
- }
18
- export function tokenInfoFromTracker(tracker, contextWindow, estimatedContext = 0) {
19
- return {
20
- context: tracker.lastInputTokens > 0 ? tracker.lastInputTokens : estimatedContext,
21
- input: tracker.totalInputTokens,
22
- output: tracker.totalOutputTokens,
23
- contextWindow,
24
- };
25
- }
26
- export function formatTokenStatusLabel(info) {
27
- const pct = contextUsagePercent(info.context, info.contextWindow);
28
- if (pct == null)
29
- return "";
30
- return `${formatTokenCount(info.context)}/${formatTokenCount(info.contextWindow)} ${pct}%`;
31
- }
32
- export function formatModelStatusMeta(thinkingLabel, contextWindow, memoryOn = false) {
33
- const parts = [`思考 ${thinkingLabel}`];
34
- if (memoryOn)
35
- parts.push("记忆 开");
36
- if (contextWindow && contextWindow > 0)
37
- parts.push(`窗口 ${formatTokenCount(contextWindow)}`);
38
- return parts.join(" · ");
39
- }
@@ -1,178 +0,0 @@
1
- /**
2
- * One-line summaries of tool calls and their results, shared by the TUI
3
- * (`⚡ search_web "query" (news)`) and the plain CLI output. Keeping both
4
- * surfaces on this module means a tool only needs a summary rule once.
5
- *
6
- * Summaries are neutral/English because tool names, arguments and paths are.
7
- */
8
- /** Truncate by code point (not UTF-16 unit) so surrogate pairs never split. */
9
- export function truncateDisplay(text, max) {
10
- const chars = Array.from(text);
11
- if (chars.length <= max)
12
- return text;
13
- return chars.slice(0, Math.max(1, max - 1)).join("") + "…";
14
- }
15
- /** Collapse whitespace so a multi-line value stays on one row. */
16
- function oneLine(text) {
17
- return text.replace(/\s+/g, " ").trim();
18
- }
19
- function asRecord(input) {
20
- return typeof input === "object" && input !== null && !Array.isArray(input)
21
- ? input
22
- : null;
23
- }
24
- function str(rec, key) {
25
- const v = rec[key];
26
- return typeof v === "string" ? oneLine(v) : "";
27
- }
28
- /** Shorten a path to its last two segments (`src/tools/web_search.ts` → `tools/web_search.ts`). */
29
- function shortPath(p) {
30
- const parts = p.split("/").filter(Boolean);
31
- return parts.length <= 2 ? p : `…/${parts.slice(-2).join("/")}`;
32
- }
33
- /** Generic `key=value` rendering, used for tools without a specific rule. */
34
- export function formatToolArgs(input, maxValueLen = 60) {
35
- const rec = asRecord(input);
36
- if (!rec)
37
- return "";
38
- const parts = [];
39
- for (const [k, v] of Object.entries(rec)) {
40
- if (v === undefined || v === null)
41
- continue;
42
- const raw = typeof v === "string" ? oneLine(v) : JSON.stringify(v);
43
- if (raw === undefined)
44
- continue;
45
- parts.push(`${k}=${truncateDisplay(raw, maxValueLen)}`);
46
- }
47
- return parts.join(" ");
48
- }
49
- /**
50
- * Summarize a tool call for a single row. `maxLen` bounds the whole summary;
51
- * the caller still truncates to the terminal width.
52
- */
53
- export function summarizeToolCall(toolName, input, maxLen = 120) {
54
- const rec = asRecord(input);
55
- if (!rec)
56
- return "";
57
- const summary = specificCallSummary(toolName, rec);
58
- return truncateDisplay(summary || formatToolArgs(rec, 60), maxLen);
59
- }
60
- function specificCallSummary(toolName, rec) {
61
- switch (toolName) {
62
- case "search_web": {
63
- const query = str(rec, "query");
64
- if (!query)
65
- return "";
66
- const facets = [];
67
- const categories = str(rec, "categories");
68
- if (categories && categories !== "general")
69
- facets.push(categories);
70
- const language = str(rec, "language");
71
- if (language)
72
- facets.push(language);
73
- const range = str(rec, "time_range");
74
- if (range)
75
- facets.push(`past ${range}`);
76
- const engines = str(rec, "engines");
77
- if (engines)
78
- facets.push(`via ${engines}`);
79
- return `"${query}"${facets.length > 0 ? ` (${facets.join(", ")})` : ""}`;
80
- }
81
- case "web_fetch": {
82
- const url = str(rec, "url");
83
- const method = str(rec, "method");
84
- return url ? `${method && method.toUpperCase() !== "GET" ? `${method.toUpperCase()} ` : ""}${url}` : "";
85
- }
86
- case "read": {
87
- const p = str(rec, "filePath");
88
- if (!p)
89
- return "";
90
- const start = rec.startLine;
91
- const end = rec.endLine;
92
- const range = typeof start === "number" || typeof end === "number" ? `:${start ?? 1}-${end ?? ""}` : "";
93
- return `${shortPath(p)}${range}`;
94
- }
95
- case "write":
96
- case "edit":
97
- case "apply_patch": {
98
- const p = str(rec, "filePath") || str(rec, "path");
99
- return p ? shortPath(p) : "";
100
- }
101
- case "bash":
102
- return str(rec, "command");
103
- case "grep": {
104
- const pattern = str(rec, "pattern");
105
- if (!pattern)
106
- return "";
107
- const where = str(rec, "path");
108
- const include = str(rec, "include");
109
- const scope = [where, include].filter(Boolean).join(" ");
110
- return `${pattern}${scope ? ` in ${scope}` : ""}`;
111
- }
112
- case "glob":
113
- return str(rec, "pattern");
114
- case "todo": {
115
- const todos = rec.todos;
116
- return Array.isArray(todos) ? `${todos.length} item${todos.length === 1 ? "" : "s"}` : "";
117
- }
118
- case "skill":
119
- return str(rec, "name");
120
- case "question":
121
- return str(rec, "question");
122
- case "task":
123
- return str(rec, "description");
124
- case "explore":
125
- case "codesearch":
126
- return str(rec, "query");
127
- default:
128
- return "";
129
- }
130
- }
131
- /** Text form of a tool result, for the expanded view. */
132
- export function toolResultText(output) {
133
- if (typeof output === "string")
134
- return output;
135
- if (output === undefined || output === null)
136
- return "";
137
- try {
138
- return JSON.stringify(output, null, 2);
139
- }
140
- catch {
141
- return String(output);
142
- }
143
- }
144
- /**
145
- * One-line result summary. `isError` comes from the tool-error stream event;
146
- * error strings produced by tools themselves are also recognized.
147
- */
148
- export function summarizeToolResult(toolName, output, isError = false, maxLen = 100) {
149
- const text = toolResultText(output).trim();
150
- if (text === "")
151
- return isError ? "error" : "(empty)";
152
- const firstLine = oneLine(text.split("\n", 1)[0] ?? "");
153
- if (isError || /^(error|search error)\b/i.test(firstLine)) {
154
- return truncateDisplay(firstLine.replace(/^Error:\s*/i, ""), maxLen);
155
- }
156
- if (toolName === "search_web") {
157
- const found = /^Found (\d+) results? for /m.exec(text);
158
- if (found)
159
- return `${found[1]} results`;
160
- if (/^No search results found/m.test(text))
161
- return "no results";
162
- const titles = text.match(/^\d+\.\s+Title\s*:/gm);
163
- if (titles && titles.length > 0)
164
- return `${titles.length} results`;
165
- if (/^Search results for /m.test(text))
166
- return "results";
167
- }
168
- if (toolName === "skill") {
169
- const loaded = /^<skill_content name="([^"]*)"/m.exec(text);
170
- if (loaded)
171
- return truncateDisplay(`loaded ${loaded[1]} (${text.split("\n").length} lines)`, maxLen);
172
- return truncateDisplay(firstLine, maxLen);
173
- }
174
- const lineCount = text.split("\n").length;
175
- if (lineCount === 1)
176
- return truncateDisplay(firstLine, maxLen);
177
- return truncateDisplay(`${firstLine} (${lineCount} lines)`, maxLen);
178
- }