orquesta-cli 0.2.14 → 0.2.16

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.
@@ -6,6 +6,37 @@ import { LLMError, TokenLimitError, RateLimitError, ContextLengthError, } from '
6
6
  import { logger, isLLMLogEnabled } from '../../utils/logger.js';
7
7
  import { usageTracker } from '../usage-tracker.js';
8
8
  import { getForcedTier, getBatutaSessionId, setLastBatutaRoute } from '../routing-state.js';
9
+ function coerceSyntheticToolCall(content) {
10
+ const trimmed = content.trim();
11
+ if (!trimmed || !trimmed.includes('"tool"'))
12
+ return null;
13
+ const cleaned = trimmed
14
+ .replace(/^```(?:json)?\s*\n?/i, '')
15
+ .replace(/\n?```\s*$/i, '')
16
+ .trim();
17
+ const start = cleaned.indexOf('{');
18
+ const end = cleaned.lastIndexOf('}');
19
+ if (start === -1 || end === -1 || end <= start)
20
+ return null;
21
+ let parsed;
22
+ try {
23
+ parsed = JSON.parse(cleaned.slice(start, end + 1));
24
+ }
25
+ catch {
26
+ return null;
27
+ }
28
+ if (!parsed || typeof parsed !== 'object')
29
+ return null;
30
+ const obj = parsed;
31
+ if (typeof obj.tool !== 'string' || !obj.tool)
32
+ return null;
33
+ const args = obj.arguments && typeof obj.arguments === 'object' ? obj.arguments : {};
34
+ return {
35
+ id: `call_synth_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`,
36
+ type: 'function',
37
+ function: { name: obj.tool, arguments: JSON.stringify(args) },
38
+ };
39
+ }
9
40
  function buildPerRequestHeaders() {
10
41
  const headers = {
11
42
  'X-Batuta-Session-ID': getBatutaSessionId(),
@@ -500,6 +531,17 @@ export class LLMClient {
500
531
  throw new Error('Cannot find choice in response.');
501
532
  }
502
533
  const assistantMessage = choice.message;
534
+ if ((!assistantMessage.tool_calls || assistantMessage.tool_calls.length === 0) &&
535
+ typeof assistantMessage.content === 'string') {
536
+ const coerced = coerceSyntheticToolCall(assistantMessage.content);
537
+ if (coerced) {
538
+ assistantMessage.tool_calls = [coerced];
539
+ assistantMessage.content = '';
540
+ logger.flow('Recovered synthetic tool call from plain-text content', {
541
+ tool: coerced.function.name,
542
+ });
543
+ }
544
+ }
503
545
  workingMessages.push(assistantMessage);
504
546
  if (assistantMessage.tool_calls && assistantMessage.tool_calls.length > 0) {
505
547
  if (assistantMessage.tool_calls.length > 1) {
@@ -23,25 +23,26 @@ async function executeBash(command, cwd, timeout = 30000, explicitEnv) {
23
23
  stderr += data.toString();
24
24
  });
25
25
  child.on('close', (code) => {
26
- if (!killed) {
27
- resolve({
28
- stdout: stdout.trim(),
29
- stderr: stderr.trim(),
30
- exitCode: code ?? 0,
31
- });
32
- }
26
+ clearTimeout(timer);
27
+ resolve({
28
+ stdout: stdout.trim(),
29
+ stderr: stderr.trim(),
30
+ exitCode: code ?? (killed ? 124 : 0),
31
+ timedOut: killed,
32
+ });
33
33
  });
34
34
  child.on('error', (error) => {
35
+ clearTimeout(timer);
35
36
  reject(error);
36
37
  });
37
38
  const timer = setTimeout(() => {
38
39
  killed = true;
39
40
  child.kill('SIGTERM');
40
- reject(new Error(`Command timed out after ${timeout}ms`));
41
+ setTimeout(() => { try {
42
+ child.kill('SIGKILL');
43
+ }
44
+ catch { } }, 2000).unref?.();
41
45
  }, timeout);
42
- child.on('close', () => {
43
- clearTimeout(timer);
44
- });
45
46
  });
46
47
  }
47
48
  const BASH_TOOL_DEFINITION = {
@@ -149,6 +150,14 @@ export const bashTool = {
149
150
  if (output.length > MAX_OUTPUT_LENGTH) {
150
151
  output = output.slice(0, MAX_OUTPUT_LENGTH) + '\n\n... [output truncated]';
151
152
  }
153
+ if (execResult.timedOut) {
154
+ const partial = output ? `\n\nPartial output before timeout:\n${output}` : ' (no output captured)';
155
+ logger.exit('bashTool.execute', { timedOut: true, outputLength: output.length });
156
+ return {
157
+ success: false,
158
+ error: `Command timed out after ${timeout}ms.${partial}`,
159
+ };
160
+ }
152
161
  if (execResult.exitCode !== 0) {
153
162
  output += `\n\n[Exit code: ${execResult.exitCode}]`;
154
163
  }
@@ -36,6 +36,8 @@ import { closeJsonStreamLogger } from '../../utils/json-stream-logger.js';
36
36
  import { configManager } from '../../core/config/config-manager.js';
37
37
  import { logger } from '../../utils/logger.js';
38
38
  import { usageTracker } from '../../core/usage-tracker.js';
39
+ import { UpdateNotification } from '../UpdateNotification.js';
40
+ import { checkForCliUpdate, runCliUpdate } from '../../utils/update-checker.js';
39
41
  import { setToolExecutionCallback, setTellToUserCallback, setToolResponseCallback, setPlanCreatedCallback, setTodoStartCallback, setTodoCompleteCallback, setTodoFailCallback, setCompactCallback, setAssistantResponseCallback, setToolApprovalCallback, setReasoningCallback, } from '../../tools/llm/simple/file-tools.js';
40
42
  import { createRequire } from 'module';
41
43
  const require = createRequire(import.meta.url);
@@ -89,6 +91,10 @@ export const PlanExecuteApp = ({ llmClient: initialLlmClient, modelInfo }) => {
89
91
  const [messages, setMessages] = useState([]);
90
92
  const { input, setInput, handleHistoryPrev, handleHistoryNext, addToHistory } = useInputHistory();
91
93
  const [isProcessing, setIsProcessing] = useState(false);
94
+ const [updatePhase, setUpdatePhase] = useState('hidden');
95
+ const [updateLatest, setUpdateLatest] = useState('');
96
+ const [updateProgress, setUpdateProgress] = useState('');
97
+ const [updateError, setUpdateError] = useState('');
92
98
  const planningMode = 'auto';
93
99
  const [llmClient, setLlmClient] = useState(initialLlmClient);
94
100
  const [activityType, setActivityType] = useState('thinking');
@@ -172,6 +178,16 @@ export const PlanExecuteApp = ({ llmClient: initialLlmClient, modelInfo }) => {
172
178
  logger.exit('PlanExecuteApp', { messageCount: messages.length });
173
179
  };
174
180
  }, []);
181
+ useEffect(() => {
182
+ let cancelled = false;
183
+ checkForCliUpdate(VERSION).then(info => {
184
+ if (!cancelled && info) {
185
+ setUpdateLatest(info.latest);
186
+ setUpdatePhase('available');
187
+ }
188
+ });
189
+ return () => { cancelled = true; };
190
+ }, []);
175
191
  useEffect(() => {
176
192
  setToolExecutionCallback((toolName, reason, args) => {
177
193
  lastToolArgsRef.current = args;
@@ -488,6 +504,32 @@ export const PlanExecuteApp = ({ llmClient: initialLlmClient, modelInfo }) => {
488
504
  logger.debug('Ctrl+C pressed - waiting for double-tap to exit');
489
505
  return;
490
506
  }
507
+ if (updatePhase === 'available' && !isProcessing && input.trim() === '') {
508
+ if (inputChar === 'y' || inputChar === 'Y') {
509
+ setUpdateError('');
510
+ setUpdateProgress('');
511
+ setUpdatePhase('updating');
512
+ runCliUpdate(updateLatest, (line) => setUpdateProgress(line.slice(0, 100)))
513
+ .then(res => {
514
+ if (res.success) {
515
+ setUpdatePhase('done');
516
+ }
517
+ else {
518
+ setUpdateError(res.error || 'Update failed');
519
+ setUpdatePhase('error');
520
+ }
521
+ });
522
+ return;
523
+ }
524
+ if (key.escape || inputChar === 'n' || inputChar === 'N' || inputChar === 's' || inputChar === 'S') {
525
+ setUpdatePhase('hidden');
526
+ return;
527
+ }
528
+ }
529
+ if ((updatePhase === 'done' || updatePhase === 'error') && key.escape) {
530
+ setUpdatePhase('hidden');
531
+ return;
532
+ }
491
533
  if (key.escape && (isProcessing || planExecutionState.isInterrupted)) {
492
534
  logger.flow('ESC pressed');
493
535
  if (llmClient) {
@@ -1260,6 +1302,14 @@ export const PlanExecuteApp = ({ llmClient: initialLlmClient, modelInfo }) => {
1260
1302
  isDocsSearching && (React.createElement(DocsSearchProgress, { logs: docsSearchLogs, isSearching: isDocsSearching })),
1261
1303
  planExecutionState.todos.length > 0 && (React.createElement(Box, { marginTop: 2, marginBottom: 1 },
1262
1304
  React.createElement(TodoPanel, { todos: planExecutionState.todos, currentTodoId: planExecutionState.currentTodoId, isProcessing: isProcessing }))),
1305
+ updatePhase === 'available' && (React.createElement(UpdateNotification, { currentVersion: VERSION, latestVersion: updateLatest })),
1306
+ updatePhase === 'updating' && (React.createElement(UpdateNotification, { currentVersion: VERSION, latestVersion: updateLatest, isUpdating: true, updateProgress: updateProgress })),
1307
+ updatePhase === 'error' && (React.createElement(UpdateNotification, { currentVersion: VERSION, latestVersion: updateLatest, error: updateError })),
1308
+ updatePhase === 'done' && (React.createElement(Box, { borderStyle: "round", borderColor: "green", paddingX: 1, marginY: 1, flexDirection: "column" },
1309
+ React.createElement(Text, { color: "green", bold: true },
1310
+ "\u2705 Updated to orquesta-cli v",
1311
+ updateLatest),
1312
+ React.createElement(Text, { color: "gray" }, "Restart orquesta to use the new version. (Esc to dismiss)"))),
1263
1313
  React.createElement(Box, { borderStyle: "single", borderColor: "gray", paddingX: 1, flexDirection: "column" },
1264
1314
  React.createElement(Box, null,
1265
1315
  React.createElement(Text, { color: "green", bold: true }, "> "),
@@ -20,6 +20,10 @@ export const SLASH_COMMANDS = [
20
20
  name: '/model',
21
21
  description: 'Switch between LLM models',
22
22
  },
23
+ {
24
+ name: '/route',
25
+ description: 'Pin Batuta Auto tier: auto | fast | balanced | premium',
26
+ },
23
27
  {
24
28
  name: '/sync',
25
29
  description: 'Sync LLM configs with Orquesta dashboard',
@@ -0,0 +1,9 @@
1
+ export declare function checkForCliUpdate(currentVersion: string, timeoutMs?: number): Promise<{
2
+ current: string;
3
+ latest: string;
4
+ } | null>;
5
+ export declare function runCliUpdate(version: string, onProgress?: (line: string) => void): Promise<{
6
+ success: boolean;
7
+ error?: string;
8
+ }>;
9
+ //# sourceMappingURL=update-checker.d.ts.map
@@ -0,0 +1,65 @@
1
+ import { spawn } from 'child_process';
2
+ import { logger } from './logger.js';
3
+ const REGISTRY_URL = 'https://registry.npmjs.org/orquesta-cli/latest';
4
+ function isNewer(a, b) {
5
+ const pa = a.split('.').map(n => parseInt(n, 10) || 0);
6
+ const pb = b.split('.').map(n => parseInt(n, 10) || 0);
7
+ for (let i = 0; i < 3; i++) {
8
+ if ((pa[i] || 0) > (pb[i] || 0))
9
+ return true;
10
+ if ((pa[i] || 0) < (pb[i] || 0))
11
+ return false;
12
+ }
13
+ return false;
14
+ }
15
+ export async function checkForCliUpdate(currentVersion, timeoutMs = 3500) {
16
+ try {
17
+ const controller = new AbortController();
18
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
19
+ const res = await fetch(REGISTRY_URL, {
20
+ signal: controller.signal,
21
+ headers: { Accept: 'application/json' },
22
+ });
23
+ clearTimeout(timer);
24
+ if (!res.ok)
25
+ return null;
26
+ const json = (await res.json());
27
+ const latest = json?.version;
28
+ if (!latest || !isNewer(latest, currentVersion))
29
+ return null;
30
+ logger.debug?.('CLI update available', { current: currentVersion, latest });
31
+ return { current: currentVersion, latest };
32
+ }
33
+ catch {
34
+ return null;
35
+ }
36
+ }
37
+ export async function runCliUpdate(version, onProgress) {
38
+ return new Promise((resolve) => {
39
+ const child = spawn('npm', ['install', '-g', `orquesta-cli@${version}`], {
40
+ stdio: ['ignore', 'pipe', 'pipe'],
41
+ });
42
+ let err = '';
43
+ child.stdout?.on('data', (d) => onProgress?.(d.toString().trim()));
44
+ child.stderr?.on('data', (d) => {
45
+ err += d.toString();
46
+ onProgress?.(d.toString().trim());
47
+ });
48
+ child.on('close', (code) => {
49
+ if (code === 0) {
50
+ resolve({ success: true });
51
+ }
52
+ else if (/EACCES|permission denied|not permitted|EPERM/i.test(err)) {
53
+ resolve({
54
+ success: false,
55
+ error: `Permission denied. Run manually: sudo npm install -g orquesta-cli@latest`,
56
+ });
57
+ }
58
+ else {
59
+ resolve({ success: false, error: err.slice(-300).trim() || `npm exited with code ${code}` });
60
+ }
61
+ });
62
+ child.on('error', (e) => resolve({ success: false, error: e.message }));
63
+ });
64
+ }
65
+ //# sourceMappingURL=update-checker.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orquesta-cli",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "Orquesta CLI - AI-powered coding assistant with team collaboration",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",