@iola_adm/iola-cli 0.1.52 → 0.1.54

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 +23 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iola_adm/iola-cli",
3
- "version": "0.1.52",
3
+ "version": "0.1.54",
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,11 @@ async function startAgentRawInput() {
847
847
  continue;
848
848
  }
849
849
  output.write(`> ${line}\n`);
850
- const stopActivity = startActivityIndicator("работаю");
850
+ const stopActivity = line.startsWith("/") ? () => {} : startActivityIndicator("работаю");
851
851
  try {
852
852
  const shouldExit = await handleAgentLine(line, state);
853
853
  stopActivity();
854
+ flushPendingAgentOutput(state);
854
855
  if (shouldExit) break;
855
856
  } catch (error) {
856
857
  stopActivity();
@@ -873,9 +874,10 @@ async function startAgentRawInput() {
873
874
 
874
875
  async function handleAgentLine(line, state) {
875
876
  if (!line.startsWith("/")) {
876
- const answer = await aiAsk([line], { history: state.history });
877
+ const answer = await aiAsk(state.rawMode ? [line, "--quiet"] : [line], { history: state.history });
877
878
  state.history.push({ role: "user", content: line });
878
879
  state.history.push({ role: "assistant", content: answer });
880
+ if (state.rawMode) state.pendingOutput = answer;
879
881
  return false;
880
882
  }
881
883
 
@@ -925,8 +927,9 @@ async function handleAgentLine(line, state) {
925
927
  console.log("Нет предыдущего вопроса для повтора.");
926
928
  return false;
927
929
  }
928
- 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) });
929
931
  state.history.push({ role: "assistant", content: answer });
932
+ if (state.rawMode) state.pendingOutput = answer;
930
933
  return false;
931
934
  }
932
935
 
@@ -1340,26 +1343,36 @@ function clearAgentInputArea(state = null) {
1340
1343
  }
1341
1344
 
1342
1345
  function startActivityIndicator(label = "работаю") {
1346
+ const doneLabel = "готово";
1343
1347
  if (!output.isTTY || process.env.NO_COLOR === "1") {
1344
1348
  output.write(`${label}...\n`);
1345
- return () => {};
1349
+ const started = Date.now();
1350
+ return () => {
1351
+ const seconds = ((Date.now() - started) / 1000).toFixed(1);
1352
+ output.write(`- ${doneLabel} ${seconds}s\n`);
1353
+ };
1346
1354
  }
1347
- const frames = ["|", "/", "-", "\\"];
1348
1355
  const started = Date.now();
1349
- let index = 0;
1350
1356
  const render = () => {
1351
1357
  const seconds = ((Date.now() - started) / 1000).toFixed(1);
1352
- output.write(`\r\x1b[2K${colorMuted(`${frames[index % frames.length]} ${label} ${seconds}s`)}`);
1353
- index += 1;
1358
+ output.write(`\r\x1b[2K${colorMuted(`─ ${label} ${seconds}s`)}`);
1354
1359
  };
1355
1360
  render();
1356
1361
  const timer = setInterval(render, 120);
1357
1362
  return () => {
1358
1363
  clearInterval(timer);
1359
- output.write("\r\x1b[2K");
1364
+ const seconds = ((Date.now() - started) / 1000).toFixed(1);
1365
+ output.write(`\r\x1b[2K${colorMuted(`─ ${doneLabel} ${seconds}s`)}\n`);
1360
1366
  };
1361
1367
  }
1362
1368
 
1369
+ function flushPendingAgentOutput(state) {
1370
+ const text = state.pendingOutput;
1371
+ state.pendingOutput = "";
1372
+ if (!text) return;
1373
+ console.log(text);
1374
+ }
1375
+
1363
1376
  function colorSlashSelection(row) {
1364
1377
  if (!output.isTTY || process.env.NO_COLOR === "1") return row;
1365
1378
  return `\x1b[38;5;213m${row}\x1b[0m`;