pi-freeflow 1.1.8 → 1.1.9
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/extensions/index.ts +36 -2
- package/package.json +1 -1
package/extensions/index.ts
CHANGED
|
@@ -735,13 +735,37 @@ const LOG_MAX_BYTES = 5 * 1024 * 1024;
|
|
|
735
735
|
const LOG_MAX_FILES = 3;
|
|
736
736
|
const DEBUG_STATE_FILE = path.join(homedir(), ".pi", "agent", "pi-freeflow-debug.json");
|
|
737
737
|
interface DebugState { debug: boolean; level?: LogLevel }
|
|
738
|
+
let cachedDebugState: DebugState | null | undefined = undefined;
|
|
739
|
+
let cachedDebugMtime = 0;
|
|
740
|
+
let cachedDebugAt = 0;
|
|
738
741
|
function loadDebugState(): DebugState | null {
|
|
742
|
+
const now = Date.now();
|
|
743
|
+
// cache for 1s to avoid per-chunk FS hit in hot pipe path
|
|
744
|
+
if (cachedDebugState !== undefined && now - cachedDebugAt < 1000) {
|
|
745
|
+
return cachedDebugState;
|
|
746
|
+
}
|
|
739
747
|
try {
|
|
740
|
-
if (!fs.existsSync(DEBUG_STATE_FILE))
|
|
748
|
+
if (!fs.existsSync(DEBUG_STATE_FILE)) {
|
|
749
|
+
cachedDebugState = null;
|
|
750
|
+
cachedDebugAt = now;
|
|
751
|
+
return null;
|
|
752
|
+
}
|
|
753
|
+
const stat = fs.statSync(DEBUG_STATE_FILE);
|
|
754
|
+
if (stat.mtimeMs === cachedDebugMtime && cachedDebugState !== undefined) {
|
|
755
|
+
cachedDebugAt = now;
|
|
756
|
+
return cachedDebugState;
|
|
757
|
+
}
|
|
741
758
|
const raw = fs.readFileSync(DEBUG_STATE_FILE, "utf8");
|
|
742
759
|
const d = JSON.parse(raw) as DebugState;
|
|
743
|
-
if (typeof d.debug === "boolean")
|
|
760
|
+
if (typeof d.debug === "boolean") {
|
|
761
|
+
cachedDebugState = d;
|
|
762
|
+
cachedDebugMtime = stat.mtimeMs;
|
|
763
|
+
cachedDebugAt = now;
|
|
764
|
+
return d;
|
|
765
|
+
}
|
|
744
766
|
} catch {}
|
|
767
|
+
cachedDebugState = null;
|
|
768
|
+
cachedDebugAt = now;
|
|
745
769
|
return null;
|
|
746
770
|
}
|
|
747
771
|
function saveDebugState(s: DebugState): void {
|
|
@@ -751,6 +775,16 @@ function saveDebugState(s: DebugState): void {
|
|
|
751
775
|
const tmp = `${DEBUG_STATE_FILE}.${randomUUID()}.tmp`;
|
|
752
776
|
fs.writeFileSync(tmp, JSON.stringify(s, null, 2), "utf8");
|
|
753
777
|
fs.renameSync(tmp, DEBUG_STATE_FILE);
|
|
778
|
+
// update cache
|
|
779
|
+
try {
|
|
780
|
+
const stat = fs.statSync(DEBUG_STATE_FILE);
|
|
781
|
+
cachedDebugState = s;
|
|
782
|
+
cachedDebugMtime = stat.mtimeMs;
|
|
783
|
+
cachedDebugAt = Date.now();
|
|
784
|
+
} catch {
|
|
785
|
+
cachedDebugState = s;
|
|
786
|
+
cachedDebugAt = Date.now();
|
|
787
|
+
}
|
|
754
788
|
} catch {}
|
|
755
789
|
}
|
|
756
790
|
function getMinLogLevel(): number {
|