@apmantza/greedysearch-pi 1.9.0 → 1.9.2

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.
@@ -4,11 +4,7 @@
4
4
  */
5
5
 
6
6
  import { formatAgreementLevel } from "../utils/helpers.js";
7
- import {
8
- formatSourceLine,
9
- pickSources,
10
- renderSourceEvidence,
11
- } from "./sources.js";
7
+ import { formatSourceLine, pickSources } from "./sources.js";
12
8
 
13
9
  /**
14
10
  * Render synthesis data (answer, consensus, differences, caveats, claims, sources)
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // Extracted from search.mjs.
4
4
 
5
- import { mkdirSync, writeFileSync } from "node:fs";
5
+ import { mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
6
6
  import { join } from "node:path";
7
7
 
8
8
  const __dir =
@@ -17,9 +17,31 @@ export function slugify(query) {
17
17
  .slice(0, 60);
18
18
  }
19
19
 
20
+ const RESULTS_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
21
+ const RESULTS_MIN_KEEP = 10;
22
+
23
+ function purgeOldResults(dir) {
24
+ try {
25
+ const files = readdirSync(dir)
26
+ .filter((f) => f.endsWith(".json") || f.endsWith(".md"))
27
+ .map((f) => ({ f, mtime: statSync(join(dir, f)).mtimeMs }))
28
+ .sort((a, b) => b.mtime - a.mtime);
29
+
30
+ const cutoff = Date.now() - RESULTS_MAX_AGE_MS;
31
+ for (let i = RESULTS_MIN_KEEP; i < files.length; i++) {
32
+ if (files[i].mtime < cutoff) {
33
+ rmSync(join(dir, files[i].f), { force: true });
34
+ }
35
+ }
36
+ } catch {
37
+ // best-effort
38
+ }
39
+ }
40
+
20
41
  export function resultsDir() {
21
42
  const dir = join(__dir, "..", "..", "results");
22
43
  mkdirSync(dir, { recursive: true });
44
+ purgeOldResults(dir);
23
45
  return dir;
24
46
  }
25
47