querysub 0.241.0 → 0.242.0

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": "querysub",
3
- "version": "0.241.0",
3
+ "version": "0.242.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "note1": "note on node-forge fork, see https://github.com/digitalbazaar/forge/issues/744 for details",
@@ -23,6 +23,9 @@ import { blue, green, magenta, red } from "socket-function/src/formatting/logCol
23
23
  import { shutdown } from "../diagnostics/periodic";
24
24
  import { onServiceConfigChange } from "./machineController";
25
25
  import { PromiseObj } from "../promise";
26
+ import path from "path";
27
+
28
+ const PIPE_FILE_LINE_LIMIT = 10;
26
29
 
27
30
  const getLiveMachineInfo = measureWrap(async function getLiveMachineInfo() {
28
31
  let machineInfo: MachineInfo = {
@@ -51,6 +54,8 @@ export async function streamScreenOutput(config: {
51
54
  index: number;
52
55
  onData: (data: string) => Promise<void>;
53
56
  }) {
57
+ // Find the pipe file for this screen
58
+ const root = os.homedir() + "/" + SERVICE_FOLDER;
54
59
  let screenName = getScreenName({
55
60
  serviceKey: config.key,
56
61
  index: config.index,
@@ -99,8 +104,10 @@ export async function streamScreenOutput(config: {
99
104
  await onDataWrapped(initialContent);
100
105
  }
101
106
 
102
- childProcess = spawn(`${prefix}tmux pipe-pane -t ${screenName} 'cat'`, {
103
- shell: true,
107
+ const pipeFile = `${root}${screenName}/pipe.txt`;
108
+
109
+ // Use tail -f to follow the pipe file
110
+ childProcess = spawn(`tail`, ["-F", pipeFile], {
104
111
  stdio: "pipe",
105
112
  });
106
113
 
@@ -292,6 +299,31 @@ ${config.command}
292
299
  `;
293
300
  await fs.promises.writeFile(config.folder + "../command.sh", command);
294
301
  await runPromise(`${prefix}tmux send-keys -t ${screenName} 'bash ../command.sh' Enter`);
302
+
303
+ // Setup pipe-pane as well
304
+
305
+ let pipeFile = path.resolve(config.folder + "../pipe.txt");
306
+ let pipeScript = path.resolve(config.folder + "../pipe.sh");
307
+ await fs.promises.writeFile(pipeScript, `#!/bin/bash
308
+ line_count=0
309
+ while IFS= read -r line; do
310
+ echo "$line" >> "${pipeFile}"
311
+ ((line_count++))
312
+
313
+ # Check file size every 100 lines to avoid too much overhead
314
+ if (( line_count % ${PIPE_FILE_LINE_LIMIT} == 0 )); then
315
+ if [ -f "${pipeFile}" ]; then
316
+ # Get file size (works on both Linux and macOS)
317
+ filesize=$(stat -f%z "${pipeFile}" 2>/dev/null || stat -c%s "${pipeFile}" 2>/dev/null || echo 0)
318
+ if [ "$filesize" -gt 1048576 ]; then
319
+ # Keep only the last 1000 lines when file gets too big
320
+ tail -n ${PIPE_FILE_LINE_LIMIT} "${pipeFile}" > "${pipeFile}.tmp" && mv "${pipeFile}.tmp" "${pipeFile}"
321
+ fi
322
+ fi
323
+ fi
324
+ done`);
325
+ await runPromise(`chmod +x ${pipeScript}`);
326
+ await runPromise(`${prefix}tmux pipe-pane -t ${screenName} 'bash ${pipeScript}'`);
295
327
  });
296
328
  const killScreen = measureWrap(async function killScreen(config: {
297
329
  screenName: string;
@@ -5,7 +5,9 @@ Syncing isn't updating?
5
5
  - Buttons per key + index, which we can figure out clientside. Stream results under the button, and we can stream multiple at once?
6
6
  - OH, just for superusers, so the browser can connect directly!
7
7
 
8
- OH! I think if something is scrollable, and is scrolled down, it'll stick to the bottom. We just need it to start scrollable!
8
+ 2) Verify when the file is truncated it still works
9
+
10
+ 3) OH! I think if something is scrollable, and is scrolled down, it'll stick to the bottom. We just need it to start scrollable!
9
11
 
10
12
  4) Destroy our testing digital ocean server
11
13