mslxdff 0.1.10 → 0.1.11
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/bin/mslxdff.js +36 -29
- package/package.json +1 -1
package/bin/mslxdff.js
CHANGED
|
@@ -711,9 +711,10 @@ function fmtEvent(e) {
|
|
|
711
711
|
async function liveDebug() {
|
|
712
712
|
const file = eventsFile();
|
|
713
713
|
// ensure the event file exists so watch() doesn't fail on a fresh daemon dir
|
|
714
|
+
const dir = dirname(file);
|
|
714
715
|
if (!existsSync(file)) {
|
|
715
716
|
try {
|
|
716
|
-
mkdirSync(
|
|
717
|
+
mkdirSync(dir, { recursive: true });
|
|
717
718
|
closeSync(openSync(file, "a"));
|
|
718
719
|
} catch {
|
|
719
720
|
console.error(`cannot create event file: ${file}`);
|
|
@@ -726,48 +727,54 @@ async function liveDebug() {
|
|
|
726
727
|
for (const e of recent) console.log(fmtEvent(e));
|
|
727
728
|
}
|
|
728
729
|
console.log("--- live (Ctrl+C to exit) ---");
|
|
730
|
+
console.log(`watching: ${file}`);
|
|
729
731
|
if (!existsSync(file)) console.log("(no events yet — trigger a chat request to see the flow)");
|
|
730
732
|
|
|
731
733
|
let pos = existsSync(file) ? statSync(file).size : 0;
|
|
732
734
|
let buf = "";
|
|
733
735
|
const pump = () => {
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
736
|
+
try {
|
|
737
|
+
if (!existsSync(file)) {
|
|
738
|
+
pos = 0;
|
|
739
|
+
buf = "";
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
const size = statSync(file).size;
|
|
743
|
+
if (size < pos) {
|
|
744
|
+
pos = 0; // file trimmed/rewritten: re-follow from the start of what remains
|
|
745
|
+
buf = "";
|
|
746
|
+
}
|
|
747
|
+
if (size === pos) return;
|
|
748
|
+
buf += readFileSync(file, "utf8").slice(pos);
|
|
749
|
+
pos = size;
|
|
750
|
+
const lines = buf.split("\n");
|
|
751
|
+
buf = lines.pop() || "";
|
|
752
|
+
for (const l of lines) {
|
|
753
|
+
if (!l.trim()) continue;
|
|
754
|
+
try {
|
|
755
|
+
console.log(fmtEvent(JSON.parse(l)));
|
|
756
|
+
} catch {
|
|
757
|
+
// partial/corrupt line while trimming — skip
|
|
758
|
+
}
|
|
755
759
|
}
|
|
760
|
+
} catch (err) {
|
|
761
|
+
console.error(`[debug] poll error: ${err.message}`);
|
|
756
762
|
}
|
|
757
763
|
};
|
|
764
|
+
// fs.watch is unreliable across platforms for freshly-created/rotated files,
|
|
765
|
+
// so polling is the source of truth (200ms); the directory watch just adds
|
|
766
|
+
// low-latency wake-ups and silently degrades when it misbehaves.
|
|
758
767
|
try {
|
|
759
|
-
mkdirSync(
|
|
760
|
-
watch(
|
|
768
|
+
mkdirSync(dir, { recursive: true });
|
|
769
|
+
watch(dir, (_evt, filename) => {
|
|
761
770
|
if (!filename || basename(String(filename)) !== basename(file)) return;
|
|
762
771
|
pump();
|
|
763
772
|
});
|
|
764
773
|
} catch {
|
|
765
|
-
console.error(`cannot watch event dir: ${
|
|
766
|
-
process.exit(1);
|
|
774
|
+
console.error(`cannot watch event dir: ${dir} (falling back to polling only)`);
|
|
767
775
|
}
|
|
768
|
-
//
|
|
769
|
-
|
|
770
|
-
setInterval(pump, 250);
|
|
776
|
+
// Poll is the source of truth; 200ms keeps human-perceived latency negligible.
|
|
777
|
+
setInterval(pump, 200);
|
|
771
778
|
pump();
|
|
772
779
|
await new Promise(() => {}); // run until Ctrl+C
|
|
773
780
|
}
|