@lzhzzzzwill/cofos 1.1.14 → 1.1.15

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/bin/cofos.js +26 -25
  2. package/package.json +1 -1
package/bin/cofos.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawn, spawnSync } from "node:child_process";
3
- import { createInterface, emitKeypressEvents } from "node:readline";
3
+ import { clearLine, createInterface, cursorTo } from "node:readline";
4
4
  import { existsSync, readFileSync } from "node:fs";
5
5
  import { dirname, join, resolve } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -114,7 +114,7 @@ function slashMatches(line) {
114
114
  function slashCompletions(line) {
115
115
  if (!line.startsWith("/")) return [[], line];
116
116
  const hits = slashMatches(line).map(({ cmd }) => cmd);
117
- return [hits.length ? hits : SLASH_COMMANDS.map(({ cmd }) => cmd), line];
117
+ return [hits, line];
118
118
  }
119
119
 
120
120
  function slashHint(line = "/") {
@@ -254,32 +254,33 @@ function main() {
254
254
  prompt: mainPrompt,
255
255
  completer: slashCompletions,
256
256
  });
257
- let lastSlashHint = "";
258
257
  rl.on("line", (l) => {
259
- lastSlashHint = "";
260
258
  if (!ready || generating) inputQ.push(l);
261
259
  else if (!handle(l)) ask();
262
260
  });
263
- if (process.stdin.isTTY) {
264
- emitKeypressEvents(process.stdin, rl);
265
- process.stdin.on("keypress", () => {
266
- if (!ready || generating || closed) return;
267
- const line = rl.line || "";
268
- if (!line.startsWith("/")) {
269
- lastSlashHint = "";
270
- return;
271
- }
272
- const key = line.trim();
273
- if (key && key !== lastSlashHint) {
274
- lastSlashHint = key;
275
- rl.output.write(slashHint(line));
276
- rl.prompt(true);
277
- }
278
- });
261
+
262
+ function preserveInputWrite(stream, chunk) {
263
+ const data = String(chunk);
264
+ if (!rl.terminal || closed) {
265
+ stream.write(data);
266
+ return;
267
+ }
268
+ const activeInput = !generating;
269
+ if (activeInput) {
270
+ clearLine(rl.output, 0);
271
+ cursorTo(rl.output, 0);
272
+ }
273
+ stream.write(data);
274
+ if (activeInput) rl.prompt(true);
279
275
  }
280
276
 
281
- // Forward Python stderr (status / progress messages) to our stderr.
282
- proc.stderr.on("data", (chunk) => { process.stderr.write(chunk); });
277
+ // Let users type while the Python backend is still loading. Submitted lines
278
+ // are queued until READY, while status logs are written above and the input
279
+ // line is restored afterward.
280
+ ask();
281
+
282
+ // Forward Python stderr (status / progress messages) without destroying the input line.
283
+ proc.stderr.on("data", (chunk) => { preserveInputWrite(process.stderr, chunk); });
283
284
 
284
285
  proc.stdout.on("data", (chunk) => {
285
286
  buf += chunk;
@@ -314,19 +315,19 @@ function main() {
314
315
  const di = buf.indexOf(DONE);
315
316
  if (di !== -1) {
316
317
  const pre = buf.slice(0, di);
317
- if (pre) process.stdout.write(pre);
318
+ if (pre) preserveInputWrite(process.stdout, pre);
318
319
  buf = buf.slice(di + DONE.length);
319
320
  if (buf[0] === "\n") buf = buf.slice(1);
320
321
  generating = false;
321
322
  responseOpen = false;
322
- console.log("");
323
+ preserveInputWrite(process.stdout, "\n");
323
324
  drain();
324
325
  } else {
325
326
  // Stream buffered content, keeping enough tail to catch a partial DONE marker.
326
327
  const keep = DONE.length - 1;
327
328
  if (buf.length > keep) {
328
329
  const out = buf.slice(0, -keep);
329
- if (out) process.stdout.write(out);
330
+ if (out) preserveInputWrite(process.stdout, out);
330
331
  buf = buf.slice(-keep);
331
332
  }
332
333
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lzhzzzzwill/cofos",
3
- "version": "1.1.14",
3
+ "version": "1.1.15",
4
4
  "description": "COFOS 9B + RAG chat CLI with optional local PDF ingestion.",
5
5
  "type": "module",
6
6
  "bin": {