@iola_adm/iola-cli 0.1.56 → 0.1.58

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +58 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iola_adm/iola-cli",
3
- "version": "0.1.56",
3
+ "version": "0.1.58",
4
4
  "description": "CLI и AI-агент городского округа Йошкар-Ола.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/adm-iola/iola-cli#readme",
package/src/cli.js CHANGED
@@ -794,10 +794,8 @@ async function startAgentReadline() {
794
794
 
795
795
  async function startAgentRawInput() {
796
796
  const state = { history: [], buffer: "", selected: 0, slashOpen: false, running: false, renderedInputLines: 0, rawMode: true, pendingOutput: "" };
797
- emitKeypressEvents(input);
798
797
  const wasRaw = input.isRaw;
799
- input.setRawMode(true);
800
- input.resume();
798
+ activateRawInput(input);
801
799
 
802
800
  const render = () => renderAgentInput(state);
803
801
  render();
@@ -848,13 +846,16 @@ async function startAgentRawInput() {
848
846
  }
849
847
  output.write(`> ${line}\n`);
850
848
  const stopActivity = line.startsWith("/") ? () => {} : startActivityIndicator("работаю");
849
+ const restoreRawInput = line.startsWith("/") ? suspendRawInputForCommand(input) : () => {};
851
850
  try {
852
851
  const shouldExit = await handleAgentLine(line, state);
853
852
  stopActivity();
854
853
  flushPendingAgentOutput(state);
854
+ if (!shouldExit) restoreRawInput();
855
855
  if (shouldExit) break;
856
856
  } catch (error) {
857
857
  stopActivity();
858
+ restoreRawInput();
858
859
  console.error(error instanceof Error ? error.message : String(error));
859
860
  }
860
861
  render();
@@ -1370,6 +1371,22 @@ function startActivityIndicator(label = "работаю") {
1370
1371
  };
1371
1372
  }
1372
1373
 
1374
+ function suspendRawInputForCommand(stream) {
1375
+ if (!stream.isTTY || !stream.isRaw) return () => {};
1376
+ stream.setRawMode(false);
1377
+ stream.pause();
1378
+ return () => {
1379
+ activateRawInput(stream);
1380
+ };
1381
+ }
1382
+
1383
+ function activateRawInput(stream) {
1384
+ if (!stream.isTTY) return;
1385
+ emitKeypressEvents(stream);
1386
+ stream.setRawMode(true);
1387
+ stream.resume();
1388
+ }
1389
+
1373
1390
  function flushPendingAgentOutput(state) {
1374
1391
  const text = state.pendingOutput;
1375
1392
  state.pendingOutput = "";
@@ -5886,27 +5903,29 @@ async function setupOllama(args) {
5886
5903
  const diagnostics = await getLocalDiagnostics();
5887
5904
  const recommendation = recommendOllamaModel(diagnostics);
5888
5905
  const model = options.model || recommendation.model;
5906
+ const ollamaCommand = await resolveOllamaCommand();
5889
5907
 
5890
5908
  printDiagnostics(diagnostics, { ...recommendation, model });
5891
5909
 
5892
- if (!diagnostics.ollama.installed) {
5910
+ if (!ollamaCommand) {
5893
5911
  console.log("");
5894
- console.log("Ollama не найден. Установите Ollama, затем повторите команду:");
5895
- console.log(" iola ai setup ollama");
5912
+ console.log("Ollama не найден или команда пока недоступна в текущем терминале.");
5913
+ console.log("Если Ollama только что установлена, откройте новый PowerShell или повторите после обновления PATH:");
5914
+ console.log(" iola master");
5896
5915
  console.log("");
5897
5916
  console.log("Windows:");
5898
- console.log(" winget install Ollama.Ollama");
5917
+ console.log(" $env:Path += ';' + \"$env:LOCALAPPDATA\\Programs\\Ollama\"");
5899
5918
  console.log("macOS:");
5900
- console.log(" brew install --cask ollama");
5919
+ console.log(" перезапустите терминал после brew install --cask ollama");
5901
5920
  console.log("Linux:");
5902
- console.log(" curl -fsSL https://ollama.com/install.sh | sh");
5921
+ console.log(" проверьте /usr/local/bin/ollama");
5903
5922
  return;
5904
5923
  }
5905
5924
 
5906
5925
  const shouldInstall = options.yes || (await confirm(`Установить модель ${model} через "ollama pull ${model}"? [Y/n] `));
5907
5926
 
5908
5927
  if (shouldInstall) {
5909
- await runCommand("ollama", ["pull", model], { inherit: true });
5928
+ await runCommand(ollamaCommand, ["pull", model], { inherit: true });
5910
5929
  }
5911
5930
 
5912
5931
  const config = await loadConfig();
@@ -6964,8 +6983,8 @@ async function onboard(args = []) {
6964
6983
  else await installBrowserRuntime();
6965
6984
  }
6966
6985
  if (components.includes("gosuslugi")) {
6967
- await handleGosuslugi(["terms"]);
6968
6986
  if (process.stdin.isTTY) await handleGosuslugi(["consent"]);
6987
+ else await handleGosuslugi(["terms"]);
6969
6988
  console.log("Параметры подключения можно указать командой: iola gosuslugi configure --auth-url URL --token-url URL --client-id ID --scope openid");
6970
6989
  }
6971
6990
  if (components.includes("index")) {
@@ -7329,14 +7348,38 @@ async function getWindowsGpu() {
7329
7348
  }
7330
7349
 
7331
7350
  async function getOllamaVersion() {
7351
+ const command = await resolveOllamaCommand();
7352
+ if (!command) return null;
7332
7353
  try {
7333
- const { stdout } = await runCommand("ollama", ["--version"]);
7354
+ const { stdout } = await runCommand(command, ["--version"]);
7334
7355
  return stdout.trim();
7335
7356
  } catch {
7336
7357
  return null;
7337
7358
  }
7338
7359
  }
7339
7360
 
7361
+ async function resolveOllamaCommand() {
7362
+ const candidates = ["ollama"];
7363
+ if (process.platform === "win32") {
7364
+ candidates.push(
7365
+ path.join(os.homedir(), "AppData", "Local", "Programs", "Ollama", "ollama.exe"),
7366
+ path.join(process.env.LOCALAPPDATA || "", "Programs", "Ollama", "ollama.exe"),
7367
+ );
7368
+ } else {
7369
+ candidates.push("/usr/local/bin/ollama", "/opt/homebrew/bin/ollama", "/usr/bin/ollama");
7370
+ }
7371
+ for (const command of [...new Set(candidates.filter(Boolean))]) {
7372
+ try {
7373
+ if (command !== "ollama" && !existsSync(command)) continue;
7374
+ await runCommand(command, ["--version"]);
7375
+ return command;
7376
+ } catch {
7377
+ // Try next candidate.
7378
+ }
7379
+ }
7380
+ return null;
7381
+ }
7382
+
7340
7383
  async function getCommandVersion(command, args) {
7341
7384
  try {
7342
7385
  const { stdout } = await runCommand(command, args);
@@ -7406,6 +7449,9 @@ async function installOllamaIfMissing() {
7406
7449
  return;
7407
7450
  }
7408
7451
  await runCommand("sh", ["-c", "curl -fsSL https://ollama.com/install.sh | sh"], { inherit: true });
7452
+ if (!(await getOllamaVersion())) {
7453
+ console.log("Ollama установлен, но текущий терминал может еще не видеть команду. CLI попробует стандартный путь установки.");
7454
+ }
7409
7455
  }
7410
7456
 
7411
7457
  async function installCodexIfMissing() {