querysub 0.241.0 → 0.243.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.243.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,
@@ -92,15 +97,10 @@ export async function streamScreenOutput(config: {
92
97
 
93
98
  return (async () => {
94
99
  try {
95
- const captureCommand = `${prefix}tmux capture-pane -p -S -2000 -t ${screenName}`;
96
- // Initial data
97
- const initialContent = await runPromise(captureCommand, { quiet: true });
98
- if (initialContent) {
99
- await onDataWrapped(initialContent);
100
- }
100
+ const pipeFile = `${root}${screenName}/pipe.txt`;
101
101
 
102
- childProcess = spawn(`${prefix}tmux pipe-pane -t ${screenName} 'cat'`, {
103
- shell: true,
102
+ // Use tail -f to follow the pipe file
103
+ childProcess = spawn(`tail`, ["-f", pipeFile, "--retry", "--lines", "1000"], {
104
104
  stdio: "pipe",
105
105
  });
106
106
 
@@ -292,6 +292,31 @@ ${config.command}
292
292
  `;
293
293
  await fs.promises.writeFile(config.folder + "../command.sh", command);
294
294
  await runPromise(`${prefix}tmux send-keys -t ${screenName} 'bash ../command.sh' Enter`);
295
+
296
+ // Setup pipe-pane as well
297
+
298
+ let pipeFile = path.resolve(config.folder + "../pipe.txt");
299
+ let pipeScript = path.resolve(config.folder + "../pipe.sh");
300
+ await fs.promises.writeFile(pipeScript, `#!/bin/bash
301
+ line_count=0
302
+ while IFS= read -r line; do
303
+ echo "$line" >> "${pipeFile}"
304
+ ((line_count++))
305
+
306
+ # Check file size every 100 lines to avoid too much overhead
307
+ if (( line_count % ${PIPE_FILE_LINE_LIMIT} == 0 )); then
308
+ if [ -f "${pipeFile}" ]; then
309
+ # Get file size (works on both Linux and macOS)
310
+ filesize=$(stat -f%z "${pipeFile}" 2>/dev/null || stat -c%s "${pipeFile}" 2>/dev/null || echo 0)
311
+ if [ "$filesize" -gt 1048576 ]; then
312
+ # Keep only the last 1000 lines when file gets too big
313
+ tail -n ${PIPE_FILE_LINE_LIMIT} "${pipeFile}" > "${pipeFile}.tmp" && mv "${pipeFile}.tmp" "${pipeFile}"
314
+ fi
315
+ fi
316
+ fi
317
+ done`);
318
+ await runPromise(`chmod +x ${pipeScript}`);
319
+ await runPromise(`${prefix}tmux pipe-pane -t ${screenName} 'bash ${pipeScript}'`);
295
320
  });
296
321
  const killScreen = measureWrap(async function killScreen(config: {
297
322
  screenName: string;
@@ -340,7 +365,7 @@ async function quickIsOutdated() {
340
365
  let screen = screens.find(x => x.screenName === screenName);
341
366
  if (!screen) return true;
342
367
 
343
- let folder = root + config.parameters.key + "-" + i + "/";
368
+ let folder = root + screenName + "/";
344
369
  let parameterPath = folder + "/parameters.json";
345
370
  if (!fs.existsSync(parameterPath)) return true;
346
371
  let prevParameters = await fs.promises.readFile(parameterPath, "utf8");
@@ -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