@iola_adm/iola-cli 0.1.51 → 0.1.53

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 +37 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iola_adm/iola-cli",
3
- "version": "0.1.51",
3
+ "version": "0.1.53",
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
@@ -793,7 +793,7 @@ async function startAgentReadline() {
793
793
  }
794
794
 
795
795
  async function startAgentRawInput() {
796
- const state = { history: [], buffer: "", selected: 0, slashOpen: false, running: false, renderedInputLines: 0 };
796
+ const state = { history: [], buffer: "", selected: 0, slashOpen: false, running: false, renderedInputLines: 0, rawMode: true, pendingOutput: "" };
797
797
  emitKeypressEvents(input);
798
798
  const wasRaw = input.isRaw;
799
799
  input.setRawMode(true);
@@ -847,10 +847,14 @@ async function startAgentRawInput() {
847
847
  continue;
848
848
  }
849
849
  output.write(`> ${line}\n`);
850
+ const stopActivity = line.startsWith("/") ? () => {} : startActivityIndicator("работаю");
850
851
  try {
851
852
  const shouldExit = await handleAgentLine(line, state);
853
+ stopActivity();
854
+ flushPendingAgentOutput(state);
852
855
  if (shouldExit) break;
853
856
  } catch (error) {
857
+ stopActivity();
854
858
  console.error(error instanceof Error ? error.message : String(error));
855
859
  }
856
860
  render();
@@ -870,9 +874,10 @@ async function startAgentRawInput() {
870
874
 
871
875
  async function handleAgentLine(line, state) {
872
876
  if (!line.startsWith("/")) {
873
- const answer = await aiAsk([line], { history: state.history });
877
+ const answer = await aiAsk(state.rawMode ? [line, "--quiet"] : [line], { history: state.history });
874
878
  state.history.push({ role: "user", content: line });
875
879
  state.history.push({ role: "assistant", content: answer });
880
+ if (state.rawMode) state.pendingOutput = answer;
876
881
  return false;
877
882
  }
878
883
 
@@ -922,8 +927,9 @@ async function handleAgentLine(line, state) {
922
927
  console.log("Нет предыдущего вопроса для повтора.");
923
928
  return false;
924
929
  }
925
- const answer = await aiAsk([lastUser.content], { history: state.history.slice(0, -2) });
930
+ const answer = await aiAsk(state.rawMode ? [lastUser.content, "--quiet"] : [lastUser.content], { history: state.history.slice(0, -2) });
926
931
  state.history.push({ role: "assistant", content: answer });
932
+ if (state.rawMode) state.pendingOutput = answer;
927
933
  return false;
928
934
  }
929
935
 
@@ -1336,6 +1342,34 @@ function clearAgentInputArea(state = null) {
1336
1342
  if (state) state.renderedInputLines = 0;
1337
1343
  }
1338
1344
 
1345
+ function startActivityIndicator(label = "работаю") {
1346
+ if (!output.isTTY || process.env.NO_COLOR === "1") {
1347
+ output.write(`${label}...\n`);
1348
+ return () => {};
1349
+ }
1350
+ const frames = ["|", "/", "-", "\\"];
1351
+ const started = Date.now();
1352
+ let index = 0;
1353
+ const render = () => {
1354
+ const seconds = ((Date.now() - started) / 1000).toFixed(1);
1355
+ output.write(`\r\x1b[2K${colorMuted(`${frames[index % frames.length]} ${label} ${seconds}s`)}`);
1356
+ index += 1;
1357
+ };
1358
+ render();
1359
+ const timer = setInterval(render, 120);
1360
+ return () => {
1361
+ clearInterval(timer);
1362
+ output.write("\r\x1b[2K");
1363
+ };
1364
+ }
1365
+
1366
+ function flushPendingAgentOutput(state) {
1367
+ const text = state.pendingOutput;
1368
+ state.pendingOutput = "";
1369
+ if (!text) return;
1370
+ console.log(text);
1371
+ }
1372
+
1339
1373
  function colorSlashSelection(row) {
1340
1374
  if (!output.isTTY || process.env.NO_COLOR === "1") return row;
1341
1375
  return `\x1b[38;5;213m${row}\x1b[0m`;