@link-assistant/hive-mind 1.7.2 → 1.9.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # @link-assistant/hive-mind
2
2
 
3
+ ## 1.9.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e15f307: Add bidirectional translation between --think and --thinking-budget options for Claude Code
8
+
9
+ **Changes:**
10
+ - Add 'off' option to --think values: ['off', 'low', 'medium', 'high', 'max']
11
+ - Add --thinking-budget-claude-minimum-version option (default: 2.1.12)
12
+ - For Claude Code >= 2.1.12: translate --think to --thinking-budget (off→0, low→8000, medium→16000, high→24000, max→31999)
13
+ - For Claude Code < 2.1.12: translate --thinking-budget back to --think thinking keywords
14
+ - Both options now coexist and support all Claude Code versions
15
+
16
+ **Rationale:**
17
+ Claude Code v2.1.12+ no longer responds to thinking keywords (think, think hard, ultrathink) because extended thinking is enabled by default. The only way to control thinking budget programmatically is via MAX_THINKING_TOKENS environment variable.
18
+
19
+ Fixes #1146
20
+
21
+ ## 1.8.0
22
+
23
+ ### Minor Changes
24
+
25
+ - 53e1686: Add experimental /merge command to hive-telegram-bot for sequential PR merging
26
+ - New `/merge <repository-url>` command to process merge queues
27
+ - Automatically checks/creates 'ready' label in repository
28
+ - Merges PRs with 'ready' label sequentially (oldest first)
29
+ - Waits for CI/CD completion between each merge
30
+ - Includes `/merge_cancel` and `/merge_status` helper commands
31
+ - Supports linking issues to PRs (uses minimum creation date for ordering)
32
+
3
33
  ## 1.7.2
4
34
 
5
35
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@link-assistant/hive-mind",
3
- "version": "1.7.2",
3
+ "version": "1.9.0",
4
4
  "description": "AI-powered issue solver and hive mind for collaborative problem solving",
5
5
  "main": "src/hive.mjs",
6
6
  "type": "module",
@@ -68,7 +68,8 @@
68
68
  "@sentry/node": "^10.15.0",
69
69
  "@sentry/profiling-node": "^10.15.0",
70
70
  "dayjs": "^1.11.19",
71
- "secretlint": "^11.2.5"
71
+ "secretlint": "^11.2.5",
72
+ "semver": "^7.7.3"
72
73
  },
73
74
  "lint-staged": {
74
75
  "*.{js,mjs,json,md}": [
@@ -10,7 +10,7 @@ const path = (await use('path')).default;
10
10
  // Import log from general lib
11
11
  import { log } from './lib.mjs';
12
12
  import { reportError } from './sentry.lib.mjs';
13
- import { timeouts, retryLimits, claudeCode, getClaudeEnv } from './config.lib.mjs';
13
+ import { timeouts, retryLimits, claudeCode, getClaudeEnv, getThinkingLevelToTokens, getTokensToThinkingLevel, supportsThinkingBudget, DEFAULT_MAX_THINKING_BUDGET } from './config.lib.mjs';
14
14
  import { detectUsageLimit, formatUsageLimitMessage } from './usage-limit.lib.mjs';
15
15
  import { createInteractiveHandler } from './interactive-mode.lib.mjs';
16
16
  import { displayBudgetStats } from './claude.budget-stats.lib.mjs';
@@ -68,6 +68,8 @@ export const validateClaudeConnection = async (model = 'haiku-3') => {
68
68
  const versionResult = await $`timeout ${Math.floor(timeouts.claudeCli / 6000)} claude --version`;
69
69
  if (versionResult.code === 0) {
70
70
  const version = versionResult.stdout?.toString().trim();
71
+ // Store the version for thinking settings translation (issue #1146)
72
+ detectedClaudeVersion = version;
71
73
  if (retryCount === 0) {
72
74
  await log(`📦 Claude CLI version: ${version}`);
73
75
  }
@@ -219,6 +221,76 @@ export const validateClaudeConnection = async (model = 'haiku-3') => {
219
221
  // handleClaudeRuntimeSwitch is imported from ./claude.runtime-switch.lib.mjs (see issue #1141)
220
222
  // Re-export it for backwards compatibility
221
223
  export { handleClaudeRuntimeSwitch };
224
+
225
+ // Store Claude Code version globally (set during validation)
226
+ let detectedClaudeVersion = null;
227
+
228
+ /**
229
+ * Get the detected Claude Code version
230
+ * @returns {string|null} The detected version or null if not yet detected
231
+ */
232
+ export const getClaudeVersion = () => detectedClaudeVersion;
233
+
234
+ /**
235
+ * Set the detected Claude Code version (called during validation)
236
+ * @param {string} version - The detected version string
237
+ */
238
+ export const setClaudeVersion = version => {
239
+ detectedClaudeVersion = version;
240
+ };
241
+
242
+ /**
243
+ * Resolve thinking settings based on --think and --thinking-budget options
244
+ * Handles translation between thinking levels and token budgets based on Claude Code version
245
+ * @param {Object} argv - Command line arguments
246
+ * @param {Function} log - Logging function
247
+ * @returns {Object} { thinkingBudget, thinkLevel, translation, maxBudget } - Resolved settings
248
+ */
249
+ export const resolveThinkingSettings = async (argv, log) => {
250
+ const minVersion = argv.thinkingBudgetClaudeMinimumVersion || '2.1.12';
251
+ const version = detectedClaudeVersion || '0.0.0'; // Assume old version if not detected
252
+ const isNewVersion = supportsThinkingBudget(version, minVersion);
253
+
254
+ // Get max thinking budget from argv or use default (see issue #1146)
255
+ const maxBudget = argv.maxThinkingBudget ?? DEFAULT_MAX_THINKING_BUDGET;
256
+
257
+ // Get thinking level mappings calculated from maxBudget
258
+ const thinkingLevelToTokens = getThinkingLevelToTokens(maxBudget);
259
+ const tokensToThinkingLevel = getTokensToThinkingLevel(maxBudget);
260
+
261
+ let thinkingBudget = argv.thinkingBudget;
262
+ let thinkLevel = argv.think;
263
+ let translation = null;
264
+
265
+ if (isNewVersion) {
266
+ // Claude Code >= 2.1.12: translate --think to --thinking-budget
267
+ if (thinkLevel !== undefined && thinkingBudget === undefined) {
268
+ thinkingBudget = thinkingLevelToTokens[thinkLevel];
269
+ translation = `--think ${thinkLevel} → --thinking-budget ${thinkingBudget}`;
270
+ if (argv.verbose) {
271
+ await log(`📊 Translating for Claude Code ${version} (>= ${minVersion}):`, { verbose: true });
272
+ await log(` ${translation}`, { verbose: true });
273
+ if (maxBudget !== DEFAULT_MAX_THINKING_BUDGET) {
274
+ await log(` Using custom --max-thinking-budget: ${maxBudget}`, { verbose: true });
275
+ }
276
+ }
277
+ }
278
+ } else {
279
+ // Claude Code < 2.1.12: translate --thinking-budget to --think keywords
280
+ if (thinkingBudget !== undefined && thinkLevel === undefined) {
281
+ thinkLevel = tokensToThinkingLevel(thinkingBudget);
282
+ translation = `--thinking-budget ${thinkingBudget} → --think ${thinkLevel}`;
283
+ if (argv.verbose) {
284
+ await log(`📊 Translating for Claude Code ${version} (< ${minVersion}):`, { verbose: true });
285
+ await log(` ${translation}`, { verbose: true });
286
+ }
287
+ // Clear thinkingBudget since old versions don't support it
288
+ thinkingBudget = undefined;
289
+ }
290
+ }
291
+
292
+ return { thinkingBudget, thinkLevel, translation, isNewVersion, maxBudget };
293
+ };
222
294
  /**
223
295
  * Check if Playwright MCP is available and connected to Claude
224
296
  * @returns {Promise<boolean>} True if Playwright MCP is available, false otherwise
@@ -805,8 +877,20 @@ export const executeClaudeCommand = async params => {
805
877
  await log('', { verbose: true });
806
878
  }
807
879
  try {
808
- const claudeEnv = getClaudeEnv(); // Set CLAUDE_CODE_MAX_OUTPUT_TOKENS (see issue #1076)
880
+ // Resolve thinking settings (handles translation between --think and --thinking-budget based on Claude version)
881
+ // See issue #1146 for details on thinking budget translation
882
+ const { thinkingBudget: resolvedThinkingBudget, thinkLevel, isNewVersion } = await resolveThinkingSettings(argv, log);
883
+
884
+ // Set CLAUDE_CODE_MAX_OUTPUT_TOKENS (see issue #1076) and optionally MAX_THINKING_TOKENS (see issue #1146)
885
+ const claudeEnv = getClaudeEnv({ thinkingBudget: resolvedThinkingBudget });
809
886
  if (argv.verbose) await log(`📊 CLAUDE_CODE_MAX_OUTPUT_TOKENS: ${claudeCode.maxOutputTokens}`, { verbose: true });
887
+ if (resolvedThinkingBudget !== undefined) {
888
+ await log(`📊 MAX_THINKING_TOKENS: ${resolvedThinkingBudget}`, { verbose: true });
889
+ }
890
+ // Log thinking level for older Claude Code versions that use thinking keywords
891
+ if (!isNewVersion && thinkLevel) {
892
+ await log(`📊 Thinking level (via keywords): ${thinkLevel}`, { verbose: true });
893
+ }
810
894
  if (argv.resume) {
811
895
  // When resuming, pass prompt directly with -p flag. Escape double quotes for shell.
812
896
  const simpleEscapedPrompt = prompt.replace(/"/g, '\\"');
@@ -1351,4 +1435,7 @@ export default {
1351
1435
  executeClaudeCommand,
1352
1436
  checkForUncommittedChanges,
1353
1437
  calculateSessionTokens,
1438
+ getClaudeVersion,
1439
+ setClaudeVersion,
1440
+ resolveThinkingSettings,
1354
1441
  };
@@ -63,7 +63,10 @@ export const buildUserPrompt = params => {
63
63
  promptLines.push('');
64
64
  }
65
65
 
66
- // Add thinking instruction based on --think level
66
+ // Note: --think keywords are deprecated for Claude Code >= 2.1.12
67
+ // Thinking is now enabled by default with 31,999 token budget
68
+ // Use --thinking-budget to control MAX_THINKING_TOKENS instead
69
+ // Keeping keywords for backward compatibility with older Claude Code versions
67
70
  if (argv && argv.think) {
68
71
  const thinkMessages = {
69
72
  low: 'Think.',
@@ -89,7 +92,10 @@ export const buildUserPrompt = params => {
89
92
  export const buildSystemPrompt = params => {
90
93
  const { owner, repo, issueNumber, prNumber, branchName, workspaceTmpDir, argv } = params;
91
94
 
92
- // Build thinking instruction based on --think level
95
+ // Note: --think keywords are deprecated for Claude Code >= 2.1.12
96
+ // Thinking is now enabled by default with 31,999 token budget
97
+ // Use --thinking-budget to control MAX_THINKING_TOKENS instead
98
+ // Keeping keywords for backward compatibility with older Claude Code versions
93
99
  let thinkLine = '';
94
100
  if (argv && argv.think) {
95
101
  const thinkMessages = {
@@ -20,6 +20,9 @@ if (typeof globalThis.use === 'undefined') {
20
20
 
21
21
  const getenv = await use('getenv');
22
22
 
23
+ // Use semver package for version comparison (see issue #1146)
24
+ import semver from 'semver';
25
+
23
26
  // Import lino for parsing Links Notation format
24
27
  const { lino } = await import('./lino.lib.mjs');
25
28
 
@@ -89,8 +92,80 @@ export const claudeCode = {
89
92
  maxOutputTokens: parseIntWithDefault('CLAUDE_CODE_MAX_OUTPUT_TOKENS', parseIntWithDefault('HIVE_MIND_CLAUDE_CODE_MAX_OUTPUT_TOKENS', 64000)),
90
93
  };
91
94
 
95
+ // Default max thinking budget for Claude Code (see issue #1146)
96
+ // This is the default value used by Claude Code when extended thinking is enabled
97
+ // Can be overridden via --max-thinking-budget option
98
+ export const DEFAULT_MAX_THINKING_BUDGET = 31999;
99
+
100
+ /**
101
+ * Get thinking level token values calculated from max budget
102
+ * Values are evenly distributed: off=0, low=max/4, medium=max/2, high=max*3/4, max=max
103
+ * @param {number} maxBudget - Maximum thinking budget (default: 31999)
104
+ * @returns {Object} Mapping of thinking levels to token values
105
+ */
106
+ export const getThinkingLevelToTokens = (maxBudget = DEFAULT_MAX_THINKING_BUDGET) => ({
107
+ off: 0,
108
+ low: Math.floor(maxBudget / 4), // ~8000 for default 31999
109
+ medium: Math.floor(maxBudget / 2), // ~16000 for default 31999
110
+ high: Math.floor((maxBudget * 3) / 4), // ~24000 for default 31999
111
+ max: maxBudget, // 31999 by default
112
+ });
113
+
114
+ // Default thinking level to tokens mapping (using default max budget)
115
+ export const thinkingLevelToTokens = getThinkingLevelToTokens(DEFAULT_MAX_THINKING_BUDGET);
116
+
117
+ /**
118
+ * Get tokens to thinking level mapping function with configurable max budget
119
+ * Uses midpoint ranges to determine the level
120
+ * @param {number} maxBudget - Maximum thinking budget (default: 31999)
121
+ * @returns {Function} Function that converts tokens to thinking level
122
+ */
123
+ export const getTokensToThinkingLevel = (maxBudget = DEFAULT_MAX_THINKING_BUDGET) => {
124
+ const levels = getThinkingLevelToTokens(maxBudget);
125
+ // Calculate midpoints between levels for range determination
126
+ const lowMediumMidpoint = Math.floor((levels.low + levels.medium) / 2);
127
+ const mediumHighMidpoint = Math.floor((levels.medium + levels.high) / 2);
128
+ const highMaxMidpoint = Math.floor((levels.high + levels.max) / 2);
129
+
130
+ return tokens => {
131
+ if (tokens === 0) return 'off';
132
+ if (tokens <= lowMediumMidpoint) return 'low';
133
+ if (tokens <= mediumHighMidpoint) return 'medium';
134
+ if (tokens <= highMaxMidpoint) return 'high';
135
+ return 'max';
136
+ };
137
+ };
138
+
139
+ // Default tokens to thinking level function (using default max budget)
140
+ export const tokensToThinkingLevel = getTokensToThinkingLevel(DEFAULT_MAX_THINKING_BUDGET);
141
+
142
+ // Check if a version supports thinking budget (>= minimum version)
143
+ // Uses semver npm package for reliable version comparison (see issue #1146)
144
+ export const supportsThinkingBudget = (version, minVersion = '2.1.12') => {
145
+ // Clean the version string (remove any leading 'v' and extra text)
146
+ const cleanVersion = semver.clean(version) || semver.coerce(version)?.version;
147
+ const cleanMinVersion = semver.clean(minVersion) || semver.coerce(minVersion)?.version;
148
+
149
+ if (!cleanVersion || !cleanMinVersion) {
150
+ // If versions can't be parsed, assume old version (doesn't support budget)
151
+ return false;
152
+ }
153
+
154
+ return semver.gte(cleanVersion, cleanMinVersion);
155
+ };
156
+
92
157
  // Helper function to get Claude CLI environment with CLAUDE_CODE_MAX_OUTPUT_TOKENS set
93
- export const getClaudeEnv = () => ({ ...process.env, CLAUDE_CODE_MAX_OUTPUT_TOKENS: String(claudeCode.maxOutputTokens) });
158
+ // Optionally sets MAX_THINKING_TOKENS when thinkingBudget is provided (see issue #1146)
159
+ export const getClaudeEnv = (options = {}) => {
160
+ const env = { ...process.env, CLAUDE_CODE_MAX_OUTPUT_TOKENS: String(claudeCode.maxOutputTokens) };
161
+ // Set MAX_THINKING_TOKENS if thinkingBudget is provided
162
+ // This controls Claude Code's extended thinking feature (Claude Code >= 2.1.12)
163
+ // Default is 31999, set to 0 to disable thinking, max is 63999 for 64K output models
164
+ if (options.thinkingBudget !== undefined) {
165
+ env.MAX_THINKING_TOKENS = String(options.thinkingBudget);
166
+ }
167
+ return env;
168
+ };
94
169
 
95
170
  // Cache TTL configurations (in milliseconds)
96
171
  // The Usage API (Claude limits) has stricter rate limiting than regular APIs
@@ -168,6 +243,23 @@ export const version = {
168
243
  default: getenv('HIVE_MIND_VERSION_DEFAULT', '0.14.3'),
169
244
  };
170
245
 
246
+ // Merge queue configurations
247
+ // See: https://github.com/link-assistant/hive-mind/issues/1143
248
+ export const mergeQueue = {
249
+ // Maximum PRs to process in one merge session
250
+ // Default: 10 PRs per session
251
+ maxPrsPerSession: parseIntWithDefault('HIVE_MIND_MERGE_QUEUE_MAX_PRS', 10),
252
+ // CI/CD polling interval in milliseconds
253
+ // Default: 5 minutes (300000ms) - checks CI status every 5 minutes
254
+ ciPollIntervalMs: parseIntWithDefault('HIVE_MIND_MERGE_QUEUE_CI_POLL_INTERVAL_MS', 5 * 60 * 1000),
255
+ // CI/CD timeout in milliseconds
256
+ // Default: 7 hours (25200000ms) - maximum wait time for CI to complete
257
+ ciTimeoutMs: parseIntWithDefault('HIVE_MIND_MERGE_QUEUE_CI_TIMEOUT_MS', 7 * 60 * 60 * 1000),
258
+ // Wait time after merge before processing next PR
259
+ // Default: 1 minute (60000ms) - allows CI to stabilize
260
+ postMergeWaitMs: parseIntWithDefault('HIVE_MIND_MERGE_QUEUE_POST_MERGE_WAIT_MS', 60 * 1000),
261
+ };
262
+
171
263
  // Helper function to validate configuration values
172
264
  export function validateConfig() {
173
265
  // Ensure all numeric values are valid
@@ -213,6 +305,7 @@ export function getAllConfigurations() {
213
305
  externalUrls,
214
306
  modelConfig,
215
307
  version,
308
+ mergeQueue,
216
309
  };
217
310
  }
218
311