sapper-iq 1.2.2 → 1.2.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sapper-iq",
3
- "version": "1.2.2",
3
+ "version": "1.2.4",
4
4
  "description": "AI-powered development assistant that executes commands and builds projects",
5
5
  "main": "sapper.mjs",
6
6
  "bin": {
package/sapper-ui.mjs CHANGED
@@ -2839,8 +2839,33 @@ function startStatsPoll() {
2839
2839
 
2840
2840
  // ─── Launch ──────────────────────────────────────────────────────
2841
2841
 
2842
- server.listen(PORT, () => {
2843
- const url = `http://localhost:${PORT}`;
2842
+ const PORT_RETRY_LIMIT = parseInt(process.env.SAPPER_UI_PORT_RETRIES || '20', 10);
2843
+ const portExplicit = !!process.env.SAPPER_UI_PORT;
2844
+ let portAttempt = 0;
2845
+ let activePort = PORT;
2846
+
2847
+ function tryListen(port) {
2848
+ activePort = port;
2849
+ server.listen(port);
2850
+ }
2851
+
2852
+ server.on('error', (err) => {
2853
+ if (err && err.code === 'EADDRINUSE' && portAttempt < PORT_RETRY_LIMIT) {
2854
+ portAttempt++;
2855
+ const next = activePort + 1;
2856
+ const reason = portExplicit
2857
+ ? `port ${activePort} (from SAPPER_UI_PORT) is in use`
2858
+ : `port ${activePort} is in use`;
2859
+ console.log(` \x1b[33m⚠\x1b[0m ${reason}, trying ${next}…`);
2860
+ setTimeout(() => tryListen(next), 50);
2861
+ return;
2862
+ }
2863
+ console.error(`\n \x1b[31m✖ Sapper Web failed to start:\x1b[0m ${err && err.message ? err.message : err}`);
2864
+ process.exit(1);
2865
+ });
2866
+
2867
+ server.on('listening', () => {
2868
+ const url = `http://localhost:${activePort}`;
2844
2869
  console.log(`\n \x1b[36m⚡ Sapper Web\x1b[0m running at \x1b[1m${url}\x1b[0m`);
2845
2870
  console.log(` Working dir: ${workingDir}\n`);
2846
2871
  startWatcher();
@@ -2864,5 +2889,7 @@ server.listen(PORT, () => {
2864
2889
  }
2865
2890
  });
2866
2891
 
2892
+ tryListen(PORT);
2893
+
2867
2894
  process.on('SIGINT', () => { console.log('\nShutting down…'); try { watcher && watcher.close(); } catch {} process.exit(0); });
2868
2895
  process.on('SIGTERM', () => process.exit(0));
package/sapper.mjs CHANGED
@@ -1016,6 +1016,9 @@ project/
1016
1016
  // Global flag — set after model selection, read in buildSystemPrompt
1017
1017
  let _useNativeToolsFlag = false;
1018
1018
 
1019
+ // Models known to reject `think:true` (populated lazily on first failure).
1020
+ const modelsWithoutThinking = new Set();
1021
+
1019
1022
  function buildSystemPrompt(agentContent = null, skillContents = []) {
1020
1023
  const now = new Date();
1021
1024
  const dateStr = now.toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
@@ -8621,8 +8624,9 @@ async function runSapper() {
8621
8624
  }
8622
8625
  return { result, success: true };
8623
8626
  }
8624
- const turnThinkingEnabled = shouldUseThinkingForInput(input);
8625
-
8627
+ let turnThinkingEnabled = shouldUseThinkingForInput(input);
8628
+ if (modelsWithoutThinking.has(selectedModel)) turnThinkingEnabled = false;
8629
+
8626
8630
  let active = true;
8627
8631
  while (active) {
8628
8632
  if (stepMode) await safeQuestion(chalk.gray(promptLabel('questions.stepContinue', '[STEP] Press Enter to let AI think...')));
@@ -8637,7 +8641,7 @@ async function runSapper() {
8637
8641
  chatOpts.options = { num_ctx: effectiveContextLength() };
8638
8642
  }
8639
8643
  // Thinking can be forced on, forced off, or auto-disabled for simple prompts.
8640
- chatOpts.think = turnThinkingEnabled;
8644
+ if (turnThinkingEnabled) chatOpts.think = true;
8641
8645
  if (useNativeTools) {
8642
8646
  // Filter tool defs by agent restrictions if any
8643
8647
  if (currentAgentTools) {
@@ -8657,11 +8661,28 @@ async function runSapper() {
8657
8661
  }
8658
8662
  response = await ollama.chat(chatOpts);
8659
8663
  } catch (ollamaError) {
8660
- spinner.stop();
8661
- console.error(chalk.red('\n❌ Ollama error:'), ollamaError.message);
8662
- logEntry('error', { message: `Ollama error: ${ollamaError.message}` });
8663
- active = false;
8664
- continue;
8664
+ const errMsg = ollamaError && ollamaError.message ? ollamaError.message : String(ollamaError);
8665
+ if (/does not support thinking/i.test(errMsg) && chatOpts.think) {
8666
+ modelsWithoutThinking.add(selectedModel);
8667
+ turnThinkingEnabled = false;
8668
+ delete chatOpts.think;
8669
+ console.log(chalk.yellow(` ⚠ "${selectedModel}" doesn't support thinking — retrying without it.`));
8670
+ try {
8671
+ response = await ollama.chat(chatOpts);
8672
+ } catch (retryErr) {
8673
+ spinner.stop();
8674
+ console.error(chalk.red('\n❌ Ollama error:'), retryErr.message);
8675
+ logEntry('error', { message: `Ollama error: ${retryErr.message}` });
8676
+ active = false;
8677
+ continue;
8678
+ }
8679
+ } else {
8680
+ spinner.stop();
8681
+ console.error(chalk.red('\n❌ Ollama error:'), errMsg);
8682
+ logEntry('error', { message: `Ollama error: ${errMsg}` });
8683
+ active = false;
8684
+ continue;
8685
+ }
8665
8686
  }
8666
8687
  spinner.stop();
8667
8688