pi-para 0.5.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.
- package/CHANGELOG.md +214 -0
- package/README.md +305 -0
- package/SETUP.md +171 -0
- package/dist/capture.d.ts +34 -0
- package/dist/capture.d.ts.map +1 -0
- package/dist/capture.js +461 -0
- package/dist/capture.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +405 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands.d.ts +15 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +786 -0
- package/dist/commands.js.map +1 -0
- package/dist/context.d.ts +61 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +289 -0
- package/dist/context.js.map +1 -0
- package/dist/daemon.d.ts +49 -0
- package/dist/daemon.d.ts.map +1 -0
- package/dist/daemon.js +226 -0
- package/dist/daemon.js.map +1 -0
- package/dist/frontmatter.d.ts +59 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +170 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/gepa/dataset.d.ts +36 -0
- package/dist/gepa/dataset.d.ts.map +1 -0
- package/dist/gepa/dataset.js +148 -0
- package/dist/gepa/dataset.js.map +1 -0
- package/dist/gepa/evaluator.d.ts +51 -0
- package/dist/gepa/evaluator.d.ts.map +1 -0
- package/dist/gepa/evaluator.js +317 -0
- package/dist/gepa/evaluator.js.map +1 -0
- package/dist/gepa/index.d.ts +66 -0
- package/dist/gepa/index.d.ts.map +1 -0
- package/dist/gepa/index.js +240 -0
- package/dist/gepa/index.js.map +1 -0
- package/dist/gepa/llm.d.ts +35 -0
- package/dist/gepa/llm.d.ts.map +1 -0
- package/dist/gepa/llm.js +268 -0
- package/dist/gepa/llm.js.map +1 -0
- package/dist/gepa/optimized/capture-prompt.txt +65 -0
- package/dist/gepa/optimizer.d.ts +29 -0
- package/dist/gepa/optimizer.d.ts.map +1 -0
- package/dist/gepa/optimizer.js +249 -0
- package/dist/gepa/optimizer.js.map +1 -0
- package/dist/gepa/targets.d.ts +39 -0
- package/dist/gepa/targets.d.ts.map +1 -0
- package/dist/gepa/targets.js +326 -0
- package/dist/gepa/targets.js.map +1 -0
- package/dist/gepa/types.d.ts +168 -0
- package/dist/gepa/types.d.ts.map +1 -0
- package/dist/gepa/types.js +124 -0
- package/dist/gepa/types.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +294 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest.d.ts +88 -0
- package/dist/ingest.d.ts.map +1 -0
- package/dist/ingest.js +105 -0
- package/dist/ingest.js.map +1 -0
- package/dist/link-discovery.d.ts +40 -0
- package/dist/link-discovery.d.ts.map +1 -0
- package/dist/link-discovery.js +122 -0
- package/dist/link-discovery.js.map +1 -0
- package/dist/link-utils.d.ts +30 -0
- package/dist/link-utils.d.ts.map +1 -0
- package/dist/link-utils.js +145 -0
- package/dist/link-utils.js.map +1 -0
- package/dist/lint.d.ts +39 -0
- package/dist/lint.d.ts.map +1 -0
- package/dist/lint.js +827 -0
- package/dist/lint.js.map +1 -0
- package/dist/maintainer.d.ts +24 -0
- package/dist/maintainer.d.ts.map +1 -0
- package/dist/maintainer.js +358 -0
- package/dist/maintainer.js.map +1 -0
- package/dist/processor.d.ts +14 -0
- package/dist/processor.d.ts.map +1 -0
- package/dist/processor.js +361 -0
- package/dist/processor.js.map +1 -0
- package/dist/query.d.ts +69 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +107 -0
- package/dist/query.js.map +1 -0
- package/dist/raw.d.ts +57 -0
- package/dist/raw.d.ts.map +1 -0
- package/dist/raw.js +219 -0
- package/dist/raw.js.map +1 -0
- package/dist/redact.d.ts +21 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +143 -0
- package/dist/redact.js.map +1 -0
- package/dist/scope.d.ts +54 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +161 -0
- package/dist/scope.js.map +1 -0
- package/dist/scripts/bulk-link-fix.d.ts +9 -0
- package/dist/scripts/bulk-link-fix.d.ts.map +1 -0
- package/dist/scripts/bulk-link-fix.js +106 -0
- package/dist/scripts/bulk-link-fix.js.map +1 -0
- package/dist/session-tools.d.ts +33 -0
- package/dist/session-tools.d.ts.map +1 -0
- package/dist/session-tools.js +211 -0
- package/dist/session-tools.js.map +1 -0
- package/dist/state.d.ts +54 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +176 -0
- package/dist/state.js.map +1 -0
- package/dist/store.d.ts +56 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +227 -0
- package/dist/store.js.map +1 -0
- package/dist/summarize.d.ts +56 -0
- package/dist/summarize.d.ts.map +1 -0
- package/dist/summarize.js +231 -0
- package/dist/summarize.js.map +1 -0
- package/dist/tag-registry.d.ts +56 -0
- package/dist/tag-registry.d.ts.map +1 -0
- package/dist/tag-registry.js +146 -0
- package/dist/tag-registry.js.map +1 -0
- package/dist/templates/prompts.d.ts +63 -0
- package/dist/templates/prompts.d.ts.map +1 -0
- package/dist/templates/prompts.js +260 -0
- package/dist/templates/prompts.js.map +1 -0
- package/dist/tools.d.ts +26 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +1033 -0
- package/dist/tools.js.map +1 -0
- package/dist/watcher.d.ts +25 -0
- package/dist/watcher.d.ts.map +1 -0
- package/dist/watcher.js +84 -0
- package/dist/watcher.js.map +1 -0
- package/dist/webui/client/dist/index.html +1885 -0
- package/dist/webui/server.d.ts +31 -0
- package/dist/webui/server.d.ts.map +1 -0
- package/dist/webui/server.js +566 -0
- package/dist/webui/server.js.map +1 -0
- package/dist/wiki.d.ts +103 -0
- package/dist/wiki.d.ts.map +1 -0
- package/dist/wiki.js +428 -0
- package/dist/wiki.js.map +1 -0
- package/package.json +142 -0
- package/scripts/gepa/__pycache__/dataset.cpython-313.pyc +0 -0
- package/scripts/gepa/__pycache__/lm_providers.cpython-313.pyc +0 -0
- package/scripts/gepa/__pycache__/metric.cpython-313.pyc +0 -0
- package/scripts/gepa/__pycache__/program.cpython-313.pyc +0 -0
- package/scripts/gepa/__pycache__/wiki_reader.cpython-313.pyc +0 -0
- package/scripts/gepa/dataset.py +192 -0
- package/scripts/gepa/lm_providers.py +472 -0
- package/scripts/gepa/metric.py +279 -0
- package/scripts/gepa/optimize.py +367 -0
- package/scripts/gepa/program.py +99 -0
- package/scripts/gepa/pyproject.toml +19 -0
- package/scripts/gepa/run-all.sh +53 -0
- package/scripts/gepa/uv.lock +2241 -0
- package/scripts/gepa/wiki_reader.py +113 -0
- package/skills/para/SKILL.md +77 -0
- package/skills/setup/SKILL.md +20 -0
- package/src/capture.ts +563 -0
- package/src/cli.ts +416 -0
- package/src/commands.ts +878 -0
- package/src/context.ts +390 -0
- package/src/daemon.ts +288 -0
- package/src/frontmatter.ts +219 -0
- package/src/gepa/index.ts +287 -0
- package/src/gepa/optimized/capture-prompt.txt +65 -0
- package/src/index.ts +384 -0
- package/src/ingest.ts +177 -0
- package/src/link-discovery.ts +170 -0
- package/src/link-utils.ts +169 -0
- package/src/lint.ts +1018 -0
- package/src/maintainer.ts +404 -0
- package/src/processor.ts +415 -0
- package/src/python/__pycache__/minimax_lm.cpython-312.pyc +0 -0
- package/src/python/minimax_lm.py +198 -0
- package/src/python/rlm_capture.py +215 -0
- package/src/query.ts +148 -0
- package/src/raw.ts +276 -0
- package/src/redact.ts +159 -0
- package/src/scope.ts +214 -0
- package/src/scripts/bulk-link-fix.ts +126 -0
- package/src/session-tools.ts +260 -0
- package/src/state.ts +271 -0
- package/src/store.ts +288 -0
- package/src/summarize.ts +273 -0
- package/src/tag-registry.ts +157 -0
- package/src/templates/index.md +17 -0
- package/src/templates/prompts.ts +274 -0
- package/src/templates/schema.md +116 -0
- package/src/tools.ts +1293 -0
- package/src/watcher.ts +101 -0
- package/src/webui/client/dist/index.html +1885 -0
- package/src/webui/server.ts +765 -0
- package/src/wiki.ts +550 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#!/usr/bin/env tsx
|
|
2
|
+
/**
|
|
3
|
+
* One-time bulk fix: auto-link slugs, normalize tags, sync frontmatter.links
|
|
4
|
+
* across all wiki pages.
|
|
5
|
+
*
|
|
6
|
+
* Usage: npx tsx src/scripts/bulk-link-fix.ts [--dry-run]
|
|
7
|
+
*/
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { homedir } from "node:os";
|
|
10
|
+
import { listPages, readPage, writePage, } from "../wiki.js";
|
|
11
|
+
import { autoLinkSlugs, syncFrontmatterLinks } from "../link-utils.js";
|
|
12
|
+
import { normalizeTags, normalizeScopes } from "../tag-registry.js";
|
|
13
|
+
const WIKI_DIR = join(homedir(), ".pi", "wiki");
|
|
14
|
+
const dryRun = process.argv.includes("--dry-run");
|
|
15
|
+
async function main() {
|
|
16
|
+
console.log(`\n📚 Bulk Wiki Fix — ${dryRun ? "DRY RUN" : "LIVE"}`);
|
|
17
|
+
console.log(` Wiki: ${WIKI_DIR}\n`);
|
|
18
|
+
// Load all pages
|
|
19
|
+
const refs = await listPages(WIKI_DIR);
|
|
20
|
+
const pages = [];
|
|
21
|
+
for (const ref of refs) {
|
|
22
|
+
const page = await readPage(WIKI_DIR, ref.category, ref.slug);
|
|
23
|
+
if (page)
|
|
24
|
+
pages.push(page);
|
|
25
|
+
}
|
|
26
|
+
const allSlugs = new Set(pages.map(p => p.slug));
|
|
27
|
+
console.log(` Found ${pages.length} pages, ${allSlugs.size} unique slugs\n`);
|
|
28
|
+
let linksAdded = 0;
|
|
29
|
+
let tagsNormalized = 0;
|
|
30
|
+
let frontmatterSynced = 0;
|
|
31
|
+
let pagesChanged = 0;
|
|
32
|
+
for (const page of pages) {
|
|
33
|
+
const originalBody = page.body;
|
|
34
|
+
const originalTags = [...page.frontmatter.tags];
|
|
35
|
+
const originalLinks = [...page.frontmatter.links];
|
|
36
|
+
const originalScope = [...page.frontmatter.scope];
|
|
37
|
+
// 1. Normalize scopes first (tags depend on scope)
|
|
38
|
+
const newScope = normalizeScopes(page.frontmatter.scope);
|
|
39
|
+
// 2. Auto-link slug mentions in body
|
|
40
|
+
let newBody = autoLinkSlugs(originalBody, allSlugs, page.slug);
|
|
41
|
+
// 3. Sync frontmatter.links from body [[wikilinks]]
|
|
42
|
+
const newLinks = syncFrontmatterLinks(newBody);
|
|
43
|
+
// 4. Normalize tags (using normalized scope for dedup)
|
|
44
|
+
const newTags = normalizeTags(page.frontmatter.tags, newScope);
|
|
45
|
+
// Check what changed
|
|
46
|
+
const bodyChanged = newBody !== originalBody;
|
|
47
|
+
const linksChanged = JSON.stringify(newLinks.sort()) !== JSON.stringify(originalLinks.sort());
|
|
48
|
+
const tagsChanged = JSON.stringify(newTags) !== JSON.stringify(originalTags.sort());
|
|
49
|
+
const scopeChanged = JSON.stringify(newScope) !== JSON.stringify(originalScope.sort());
|
|
50
|
+
if (!bodyChanged && !linksChanged && !tagsChanged && !scopeChanged)
|
|
51
|
+
continue;
|
|
52
|
+
pagesChanged++;
|
|
53
|
+
const addedLinksCount = newLinks.filter(l => !originalLinks.includes(l)).length;
|
|
54
|
+
linksAdded += addedLinksCount;
|
|
55
|
+
if (tagsChanged)
|
|
56
|
+
tagsNormalized++;
|
|
57
|
+
if (linksChanged)
|
|
58
|
+
frontmatterSynced++;
|
|
59
|
+
// Report
|
|
60
|
+
const changes = [];
|
|
61
|
+
if (scopeChanged) {
|
|
62
|
+
changes.push(`scope: [${originalScope.join(", ")}] → [${newScope.join(", ")}]`);
|
|
63
|
+
}
|
|
64
|
+
if (bodyChanged) {
|
|
65
|
+
const addedLinks = newLinks.filter(l => !originalLinks.includes(l));
|
|
66
|
+
changes.push(`+${addedLinks.length} wikilinks: ${addedLinks.join(", ")}`);
|
|
67
|
+
}
|
|
68
|
+
if (tagsChanged) {
|
|
69
|
+
changes.push(`tags: [${originalTags.join(", ")}] → [${newTags.join(", ")}]`);
|
|
70
|
+
}
|
|
71
|
+
if (linksChanged && !bodyChanged) {
|
|
72
|
+
changes.push(`frontmatter.links synced`);
|
|
73
|
+
}
|
|
74
|
+
console.log(` ${dryRun ? "WOULD FIX" : "FIXED"} ${page.category}/${page.slug}`);
|
|
75
|
+
for (const c of changes) {
|
|
76
|
+
console.log(` → ${c}`);
|
|
77
|
+
}
|
|
78
|
+
if (!dryRun) {
|
|
79
|
+
const updatedPage = {
|
|
80
|
+
...page,
|
|
81
|
+
body: newBody,
|
|
82
|
+
frontmatter: {
|
|
83
|
+
...page.frontmatter,
|
|
84
|
+
scope: newScope,
|
|
85
|
+
tags: newTags,
|
|
86
|
+
links: newLinks,
|
|
87
|
+
updated: new Date().toISOString(),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
await writePage(WIKI_DIR, updatedPage);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
console.log(`\n━━━ Summary ━━━`);
|
|
94
|
+
console.log(` Pages changed: ${pagesChanged} / ${pages.length}`);
|
|
95
|
+
console.log(` Wikilinks added: ${linksAdded}`);
|
|
96
|
+
console.log(` Tags normalized: ${tagsNormalized}`);
|
|
97
|
+
console.log(` Frontmatter synced: ${frontmatterSynced}`);
|
|
98
|
+
if (dryRun)
|
|
99
|
+
console.log(`\n (dry run — no files modified, re-run without --dry-run to apply)`);
|
|
100
|
+
console.log();
|
|
101
|
+
}
|
|
102
|
+
main().catch(err => {
|
|
103
|
+
console.error("Error:", err);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
});
|
|
106
|
+
//# sourceMappingURL=bulk-link-fix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bulk-link-fix.js","sourceRoot":"","sources":["../../src/scripts/bulk-link-fix.ts"],"names":[],"mappings":";AACA;;;;;GAKG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EACL,SAAS,EAC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
|
|
|
1
|
+
/**
|
|
2
|
+
* Session exploration tools for the Agent.
|
|
3
|
+
*
|
|
4
|
+
* These tools give the Agent the ability to explore a session file
|
|
5
|
+
* without loading the entire thing into the prompt — the TypeScript
|
|
6
|
+
* equivalent of RLM's REPL-based exploration.
|
|
7
|
+
*/
|
|
8
|
+
import type { AgentTool } from "@mariozechner/pi-agent-core";
|
|
9
|
+
interface SessionMessage {
|
|
10
|
+
role: string;
|
|
11
|
+
text: string;
|
|
12
|
+
toolCalls: string[];
|
|
13
|
+
charOffset: number;
|
|
14
|
+
}
|
|
15
|
+
export interface LoadedSession {
|
|
16
|
+
messages: SessionMessage[];
|
|
17
|
+
serialized: string;
|
|
18
|
+
stats: {
|
|
19
|
+
totalMessages: number;
|
|
20
|
+
userMessages: number;
|
|
21
|
+
assistantMessages: number;
|
|
22
|
+
toolResults: number;
|
|
23
|
+
toolCalls: number;
|
|
24
|
+
totalChars: number;
|
|
25
|
+
compactionSummaries: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/** Load and pre-process a session JSONL file. */
|
|
29
|
+
export declare function loadSession(sessionPath: string): LoadedSession;
|
|
30
|
+
/** Create session exploration tools bound to a loaded session. */
|
|
31
|
+
export declare function createSessionTools(session: LoadedSession): AgentTool[];
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=session-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-tools.d.ts","sourceRoot":"","sources":["../src/session-tools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAmB,MAAM,6BAA6B,CAAC;AAI9E,UAAU,cAAc;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE;QACL,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;QACrB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,UAAU,EAAE,MAAM,CAAC;QACnB,mBAAmB,EAAE,MAAM,CAAC;KAC7B,CAAC;CACH;AAED,iDAAiD;AACjD,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CAyF9D;AAgBD,kEAAkE;AAClE,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,aAAa,GAAG,SAAS,EAAE,CAqHtE"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session exploration tools for the Agent.
|
|
3
|
+
*
|
|
4
|
+
* These tools give the Agent the ability to explore a session file
|
|
5
|
+
* without loading the entire thing into the prompt — the TypeScript
|
|
6
|
+
* equivalent of RLM's REPL-based exploration.
|
|
7
|
+
*/
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { Type } from "typebox";
|
|
10
|
+
/** Load and pre-process a session JSONL file. */
|
|
11
|
+
export function loadSession(sessionPath) {
|
|
12
|
+
const raw = readFileSync(sessionPath, "utf-8");
|
|
13
|
+
const lines = raw.split("\n").filter((l) => l.trim());
|
|
14
|
+
const messages = [];
|
|
15
|
+
const parts = [];
|
|
16
|
+
let charOffset = 0;
|
|
17
|
+
let compactionSummaries = 0;
|
|
18
|
+
let toolCallCount = 0;
|
|
19
|
+
for (const line of lines) {
|
|
20
|
+
let entry;
|
|
21
|
+
try {
|
|
22
|
+
entry = JSON.parse(line);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (entry.type === "compaction" && typeof entry.summary === "string") {
|
|
28
|
+
const text = `[Compaction Summary]:\n${entry.summary}`;
|
|
29
|
+
parts.push(text);
|
|
30
|
+
messages.push({ role: "compaction", text, toolCalls: [], charOffset });
|
|
31
|
+
charOffset += text.length + 2;
|
|
32
|
+
compactionSummaries++;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (entry.type !== "message")
|
|
36
|
+
continue;
|
|
37
|
+
const msg = entry.message;
|
|
38
|
+
if (!msg)
|
|
39
|
+
continue;
|
|
40
|
+
const role = msg.role;
|
|
41
|
+
if (!["user", "assistant", "toolResult"].includes(role))
|
|
42
|
+
continue;
|
|
43
|
+
const content = msg.content;
|
|
44
|
+
let text = "";
|
|
45
|
+
const toolCalls = [];
|
|
46
|
+
if (typeof content === "string") {
|
|
47
|
+
text = content;
|
|
48
|
+
}
|
|
49
|
+
else if (Array.isArray(content)) {
|
|
50
|
+
const textParts = [];
|
|
51
|
+
for (const block of content) {
|
|
52
|
+
if (typeof block !== "object" || block === null)
|
|
53
|
+
continue;
|
|
54
|
+
const b = block;
|
|
55
|
+
if (b.type === "text" && typeof b.text === "string") {
|
|
56
|
+
textParts.push(b.text);
|
|
57
|
+
}
|
|
58
|
+
else if (b.type === "toolCall" && typeof b.name === "string") {
|
|
59
|
+
const argsStr = JSON.stringify(b.arguments ?? {});
|
|
60
|
+
toolCalls.push(`${b.name}(${argsStr.length > 300 ? argsStr.slice(0, 300) + "..." : argsStr})`);
|
|
61
|
+
toolCallCount++;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
text = textParts.join("\n");
|
|
65
|
+
if (toolCalls.length > 0) {
|
|
66
|
+
text += `\n[Tools]: ${toolCalls.join("; ")}`;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (!text.trim())
|
|
70
|
+
continue;
|
|
71
|
+
// Truncate tool results
|
|
72
|
+
if (role === "toolResult" && text.length > 1000) {
|
|
73
|
+
text = text.slice(0, 1000) + "\n[truncated]";
|
|
74
|
+
}
|
|
75
|
+
const label = { user: "User", assistant: "Assistant", toolResult: "Tool" }[role] ?? role;
|
|
76
|
+
const formatted = `[${label}]: ${text}`;
|
|
77
|
+
parts.push(formatted);
|
|
78
|
+
messages.push({ role, text: formatted, toolCalls, charOffset });
|
|
79
|
+
charOffset += formatted.length + 2;
|
|
80
|
+
}
|
|
81
|
+
const serialized = parts.join("\n\n");
|
|
82
|
+
return {
|
|
83
|
+
messages,
|
|
84
|
+
serialized,
|
|
85
|
+
stats: {
|
|
86
|
+
totalMessages: messages.length,
|
|
87
|
+
userMessages: messages.filter((m) => m.role === "user").length,
|
|
88
|
+
assistantMessages: messages.filter((m) => m.role === "assistant").length,
|
|
89
|
+
toolResults: messages.filter((m) => m.role === "toolResult").length,
|
|
90
|
+
toolCalls: toolCallCount,
|
|
91
|
+
totalChars: serialized.length,
|
|
92
|
+
compactionSummaries,
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
// -- Tool definitions --------------------------------------------------------
|
|
97
|
+
const SliceParams = Type.Object({
|
|
98
|
+
start: Type.Number({ description: "Start character offset" }),
|
|
99
|
+
end: Type.Number({ description: "End character offset" }),
|
|
100
|
+
});
|
|
101
|
+
const SearchParams = Type.Object({
|
|
102
|
+
query: Type.String({ description: "Text to search for (case-insensitive)" }),
|
|
103
|
+
maxResults: Type.Optional(Type.Number({ description: "Max results (default 10)" })),
|
|
104
|
+
});
|
|
105
|
+
const StatsParams = Type.Object({});
|
|
106
|
+
/** Create session exploration tools bound to a loaded session. */
|
|
107
|
+
export function createSessionTools(session) {
|
|
108
|
+
const sessionSlice = {
|
|
109
|
+
name: "session_slice",
|
|
110
|
+
label: "Session Slice",
|
|
111
|
+
description: `Read a slice of the session text (${session.stats.totalChars} chars total). Use to explore specific sections.`,
|
|
112
|
+
parameters: SliceParams,
|
|
113
|
+
execute: async (_id, params) => {
|
|
114
|
+
const start = Math.max(0, params.start);
|
|
115
|
+
const end = Math.min(session.serialized.length, params.end);
|
|
116
|
+
const slice = session.serialized.slice(start, end);
|
|
117
|
+
return {
|
|
118
|
+
content: [
|
|
119
|
+
{
|
|
120
|
+
type: "text",
|
|
121
|
+
text: `[chars ${start}-${end} of ${session.serialized.length}]\n\n${slice}`,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
details: { start, end, length: slice.length },
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
const sessionSearch = {
|
|
129
|
+
name: "session_search",
|
|
130
|
+
label: "Session Search",
|
|
131
|
+
description: "Search the session for a keyword. Returns matching sections with character offsets.",
|
|
132
|
+
parameters: SearchParams,
|
|
133
|
+
execute: async (_id, params) => {
|
|
134
|
+
const query = params.query.toLowerCase();
|
|
135
|
+
const maxResults = params.maxResults ?? 10;
|
|
136
|
+
const matches = [];
|
|
137
|
+
const text = session.serialized.toLowerCase();
|
|
138
|
+
let pos = 0;
|
|
139
|
+
while (matches.length < maxResults) {
|
|
140
|
+
const idx = text.indexOf(query, pos);
|
|
141
|
+
if (idx === -1)
|
|
142
|
+
break;
|
|
143
|
+
// Extract context around match
|
|
144
|
+
const contextStart = Math.max(0, idx - 200);
|
|
145
|
+
const contextEnd = Math.min(session.serialized.length, idx + query.length + 200);
|
|
146
|
+
matches.push({
|
|
147
|
+
offset: idx,
|
|
148
|
+
context: session.serialized.slice(contextStart, contextEnd),
|
|
149
|
+
});
|
|
150
|
+
pos = idx + query.length;
|
|
151
|
+
}
|
|
152
|
+
if (matches.length === 0) {
|
|
153
|
+
return {
|
|
154
|
+
content: [{ type: "text", text: `No matches for "${params.query}"` }],
|
|
155
|
+
details: { matchCount: 0 },
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
const resultText = matches
|
|
159
|
+
.map((m, i) => `Match ${i + 1} (offset ${m.offset}):\n${m.context}\n`)
|
|
160
|
+
.join("\n---\n");
|
|
161
|
+
return {
|
|
162
|
+
content: [
|
|
163
|
+
{
|
|
164
|
+
type: "text",
|
|
165
|
+
text: `Found ${matches.length} match(es) for "${params.query}":\n\n${resultText}`,
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
details: { matchCount: matches.length },
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
const sessionStats = {
|
|
173
|
+
name: "session_stats",
|
|
174
|
+
label: "Session Stats",
|
|
175
|
+
description: "Get session overview: message counts, size, topics.",
|
|
176
|
+
parameters: StatsParams,
|
|
177
|
+
execute: async () => {
|
|
178
|
+
const s = session.stats;
|
|
179
|
+
// Extract user message topics (first 100 chars of each, cap at 50)
|
|
180
|
+
const allUserMsgs = session.messages.filter((m) => m.role === "user");
|
|
181
|
+
const displayLimit = 50;
|
|
182
|
+
const userTopics = allUserMsgs
|
|
183
|
+
.slice(0, displayLimit)
|
|
184
|
+
.map((m) => m.text.replace(/^\[User\]: /, "").slice(0, 100))
|
|
185
|
+
.map((t, i) => ` ${i + 1}. ${t}`);
|
|
186
|
+
if (allUserMsgs.length > displayLimit) {
|
|
187
|
+
userTopics.push(` ... and ${allUserMsgs.length - displayLimit} more user messages. Use session_search to find specific topics.`);
|
|
188
|
+
}
|
|
189
|
+
const sizeLabel = s.totalChars > 1_000_000 ? `${(s.totalChars / 1_000_000).toFixed(1)}M`
|
|
190
|
+
: s.totalChars > 1_000 ? `${(s.totalChars / 1_000).toFixed(0)}K`
|
|
191
|
+
: `${s.totalChars}`;
|
|
192
|
+
const text = [
|
|
193
|
+
`Session: ${sizeLabel} chars, ${s.totalMessages} messages`,
|
|
194
|
+
` User: ${s.userMessages}, Assistant: ${s.assistantMessages}, Tool results: ${s.toolResults}`,
|
|
195
|
+
` Tool calls: ${s.toolCalls}, Compaction summaries: ${s.compactionSummaries}`,
|
|
196
|
+
"",
|
|
197
|
+
"Strategy: Use session_search to find topics, then session_slice to read details.",
|
|
198
|
+
`Valid slice range: 0 to ${s.totalChars}`,
|
|
199
|
+
"",
|
|
200
|
+
"User messages (topics):",
|
|
201
|
+
...userTopics,
|
|
202
|
+
].join("\n");
|
|
203
|
+
return {
|
|
204
|
+
content: [{ type: "text", text }],
|
|
205
|
+
details: s,
|
|
206
|
+
};
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
return [sessionSlice, sessionSearch, sessionStats];
|
|
210
|
+
}
|
|
211
|
+
//# sourceMappingURL=session-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-tools.js","sourceRoot":"","sources":["../src/session-tools.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAe,MAAM,SAAS,CAAC;AA0B5C,iDAAiD;AACjD,MAAM,UAAU,WAAW,CAAC,WAAmB;IAC7C,MAAM,GAAG,GAAG,YAAY,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IAEtD,MAAM,QAAQ,GAAqB,EAAE,CAAC;IACtC,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,IAAI,UAAU,GAAG,CAAC,CAAC;IACnB,IAAI,mBAAmB,GAAG,CAAC,CAAC;IAC5B,IAAI,aAAa,GAAG,CAAC,CAAC;IAEtB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,KAA8B,CAAC;QACnC,IAAI,CAAC;YACH,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;QAED,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YACrE,MAAM,IAAI,GAAG,0BAA0B,KAAK,CAAC,OAAO,EAAE,CAAC;YACvD,KAAK,CAAC,IAAI,CAAC,IAAI,C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C,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;gBACtF,CAAC,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG;oBAChE,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,CAAC;YAEtB,MAAM,IAAI,GAAG;gBACX,YAAY,SAAS,WAAW,CAAC,CAAC,aAAa,WAAW;gBAC1D,WAAW,CAAC,CAAC,YAAY,gBAAgB,CAAC,CAAC,iBAAiB,mBAAmB,CAAC,CAAC,WAAW,EAAE;gBAC9F,iBAAiB,CAAC,CAAC,SAAS,2BAA2B,CAAC,CAAC,mBAAmB,EAAE;gBAC9E,EAAE;gBACF,kFAAkF;gBAClF,2BAA2B,CAAC,CAAC,UAAU,EAAE;gBACzC,EAAE;gBACF,yBAAyB;gBACzB,GAAG,UAAU;aACd,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEb,OAAO;gBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;gBACjC,OAAO,EAAE,CAAC;aACX,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,OAAO,CAAC,YAAY,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC;AACrD,CAAC"}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite state management for processed sessions.
|
|
3
|
+
* Tracks which sessions have been processed, their content hash,
|
|
4
|
+
* and what pages were created/updated.
|
|
5
|
+
*/
|
|
6
|
+
export interface PageSummary {
|
|
7
|
+
slug: string;
|
|
8
|
+
category: string;
|
|
9
|
+
scope: string[];
|
|
10
|
+
tags: string[];
|
|
11
|
+
firstParagraph: string;
|
|
12
|
+
updatedAt: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ProcessedSession {
|
|
15
|
+
sessionPath: string;
|
|
16
|
+
contentHash: string;
|
|
17
|
+
processedAt: string;
|
|
18
|
+
scope: string;
|
|
19
|
+
pagesCreated: string[];
|
|
20
|
+
pagesUpdated: string[];
|
|
21
|
+
error: string | null;
|
|
22
|
+
}
|
|
23
|
+
export declare class StateDB {
|
|
24
|
+
private db;
|
|
25
|
+
constructor(wikiDir: string);
|
|
26
|
+
private migrate;
|
|
27
|
+
/** Check if a session file has already been processed with the same content. */
|
|
28
|
+
isProcessed(sessionPath: string): boolean;
|
|
29
|
+
/** Get the stored hash for a session (or null if not processed). */
|
|
30
|
+
getHash(sessionPath: string): string | null;
|
|
31
|
+
/** Record a successfully processed session. */
|
|
32
|
+
recordSuccess(sessionPath: string, scope: string, pagesCreated: string[], pagesUpdated: string[]): void;
|
|
33
|
+
/** Record a failed processing attempt. */
|
|
34
|
+
recordFailure(sessionPath: string, scope: string, error: string): void;
|
|
35
|
+
/** Get all failed sessions for retry. */
|
|
36
|
+
getFailed(): ProcessedSession[];
|
|
37
|
+
/** Get processing history, optionally filtered by scope. */
|
|
38
|
+
getHistory(scope?: string, limit?: number): ProcessedSession[];
|
|
39
|
+
/** Get/set daemon state values. */
|
|
40
|
+
getState(key: string): string | null;
|
|
41
|
+
setState(key: string, value: string): void;
|
|
42
|
+
/** Upsert a page summary in the cache. */
|
|
43
|
+
upsertPageSummary(slug: string, category: string, scope: string[], tags: string[], firstParagraph: string, updatedAt: string): void;
|
|
44
|
+
/** Get all page summaries, optionally filtered by scope. */
|
|
45
|
+
getPageSummaries(scope?: {
|
|
46
|
+
name: string;
|
|
47
|
+
include: string[];
|
|
48
|
+
exclude: string[];
|
|
49
|
+
}): PageSummary[];
|
|
50
|
+
/** Delete a page summary from the cache. */
|
|
51
|
+
deletePageSummary(slug: string): void;
|
|
52
|
+
close(): void;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
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AAmC;IACnC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAOpC,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAM1C,0CAA0C;IAC1C,iBAAiB,CACf,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,MAAM,EAAE,EACf,IAAI,EAAE,MAAM,EAAE,EACd,cAAc,EAAE,MAAM,EACtB,SAAS,EAAE,MAAM,GAChB,IAAI;IAiBP,4DAA4D;IAC5D,gBAAgB,CAAC,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,WAAW,EAAE;IAoC/F,4CAA4C;IAC5C,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAMrC,KAAK,IAAI,IAAI;CAGd"}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite state management for processed sessions.
|
|
3
|
+
* Tracks which sessions have been processed, their content hash,
|
|
4
|
+
* and what pages were created/updated.
|
|
5
|
+
*/
|
|
6
|
+
import Database from "better-sqlite3";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { readFileSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
export class StateDB {
|
|
11
|
+
db;
|
|
12
|
+
constructor(wikiDir) {
|
|
13
|
+
const dbPath = join(wikiDir, ".daemon.sqlite");
|
|
14
|
+
this.db = new Database(dbPath);
|
|
15
|
+
this.db.pragma("journal_mode = WAL");
|
|
16
|
+
this.migrate();
|
|
17
|
+
}
|
|
18
|
+
migrate() {
|
|
19
|
+
this.db.exec(`
|
|
20
|
+
CREATE TABLE IF NOT EXISTS processed_sessions (
|
|
21
|
+
session_path TEXT PRIMARY KEY,
|
|
22
|
+
content_hash TEXT NOT NULL,
|
|
23
|
+
processed_at TEXT NOT NULL,
|
|
24
|
+
scope TEXT,
|
|
25
|
+
pages_created TEXT DEFAULT '[]',
|
|
26
|
+
pages_updated TEXT DEFAULT '[]',
|
|
27
|
+
error TEXT
|
|
28
|
+
);
|
|
29
|
+
CREATE TABLE IF NOT EXISTS daemon_state (
|
|
30
|
+
key TEXT PRIMARY KEY,
|
|
31
|
+
value TEXT
|
|
32
|
+
);
|
|
33
|
+
CREATE TABLE IF NOT EXISTS page_summaries (
|
|
34
|
+
slug TEXT PRIMARY KEY,
|
|
35
|
+
category TEXT NOT NULL,
|
|
36
|
+
scope_json TEXT NOT NULL DEFAULT '[]',
|
|
37
|
+
tags_json TEXT NOT NULL DEFAULT '[]',
|
|
38
|
+
first_paragraph TEXT NOT NULL DEFAULT '',
|
|
39
|
+
updated_at TEXT NOT NULL
|
|
40
|
+
);
|
|
41
|
+
`);
|
|
42
|
+
}
|
|
43
|
+
/** Check if a session file has already been processed with the same content. */
|
|
44
|
+
isProcessed(sessionPath) {
|
|
45
|
+
const row = this.db
|
|
46
|
+
.prepare("SELECT content_hash FROM processed_sessions WHERE session_path = ?")
|
|
47
|
+
.get(sessionPath);
|
|
48
|
+
if (!row)
|
|
49
|
+
return false;
|
|
50
|
+
const currentHash = hashFile(sessionPath);
|
|
51
|
+
return row.content_hash === currentHash;
|
|
52
|
+
}
|
|
53
|
+
/** Get the stored hash for a session (or null if not processed). */
|
|
54
|
+
getHash(sessionPath) {
|
|
55
|
+
const row = this.db
|
|
56
|
+
.prepare("SELECT content_hash FROM processed_sessions WHERE session_path = ?")
|
|
57
|
+
.get(sessionPath);
|
|
58
|
+
return row?.content_hash ?? null;
|
|
59
|
+
}
|
|
60
|
+
/** Record a successfully processed session. */
|
|
61
|
+
recordSuccess(sessionPath, scope, pagesCreated, pagesUpdated) {
|
|
62
|
+
const hash = hashFile(sessionPath);
|
|
63
|
+
this.db
|
|
64
|
+
.prepare(`
|
|
65
|
+
INSERT OR REPLACE INTO processed_sessions
|
|
66
|
+
(session_path, content_hash, processed_at, scope, pages_created, pages_updated, error)
|
|
67
|
+
VALUES (?, ?, ?, ?, ?, ?, NULL)
|
|
68
|
+
`)
|
|
69
|
+
.run(sessionPath, hash, new Date().toISOString(), scope, JSON.stringify(pagesCreated), JSON.stringify(pagesUpdated));
|
|
70
|
+
}
|
|
71
|
+
/** Record a failed processing attempt. */
|
|
72
|
+
recordFailure(sessionPath, scope, error) {
|
|
73
|
+
const hash = hashFile(sessionPath);
|
|
74
|
+
this.db
|
|
75
|
+
.prepare(`
|
|
76
|
+
INSERT OR REPLACE INTO processed_sessions
|
|
77
|
+
(session_path, content_hash, processed_at, scope, pages_created, pages_updated, error)
|
|
78
|
+
VALUES (?, ?, ?, ?, '[]', '[]', ?)
|
|
79
|
+
`)
|
|
80
|
+
.run(sessionPath, hash, new Date().toISOString(), scope, error);
|
|
81
|
+
}
|
|
82
|
+
/** Get all failed sessions for retry. */
|
|
83
|
+
getFailed() {
|
|
84
|
+
const rows = this.db
|
|
85
|
+
.prepare("SELECT * FROM processed_sessions WHERE error IS NOT NULL")
|
|
86
|
+
.all();
|
|
87
|
+
return rows.map(rowToSession);
|
|
88
|
+
}
|
|
89
|
+
/** Get processing history, optionally filtered by scope. */
|
|
90
|
+
getHistory(scope, limit = 20) {
|
|
91
|
+
const sql = scope
|
|
92
|
+
? "SELECT * FROM processed_sessions WHERE scope = ? ORDER BY processed_at DESC LIMIT ?"
|
|
93
|
+
: "SELECT * FROM processed_sessions ORDER BY processed_at DESC LIMIT ?";
|
|
94
|
+
const params = scope ? [scope, limit] : [limit];
|
|
95
|
+
const rows = this.db.prepare(sql).all(...params);
|
|
96
|
+
return rows.map(rowToSession);
|
|
97
|
+
}
|
|
98
|
+
/** Get/set daemon state values. */
|
|
99
|
+
getState(key) {
|
|
100
|
+
const row = this.db
|
|
101
|
+
.prepare("SELECT value FROM daemon_state WHERE key = ?")
|
|
102
|
+
.get(key);
|
|
103
|
+
return row?.value ?? null;
|
|
104
|
+
}
|
|
105
|
+
setState(key, value) {
|
|
106
|
+
this.db
|
|
107
|
+
.prepare("INSERT OR REPLACE INTO daemon_state (key, value) VALUES (?, ?)")
|
|
108
|
+
.run(key, value);
|
|
109
|
+
}
|
|
110
|
+
/** Upsert a page summary in the cache. */
|
|
111
|
+
upsertPageSummary(slug, category, scope, tags, firstParagraph, updatedAt) {
|
|
112
|
+
this.db
|
|
113
|
+
.prepare(`
|
|
114
|
+
INSERT OR REPLACE INTO page_summaries
|
|
115
|
+
(slug, category, scope_json, tags_json, first_paragraph, updated_at)
|
|
116
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
117
|
+
`)
|
|
118
|
+
.run(slug, category, JSON.stringify(scope), JSON.stringify(tags), firstParagraph, updatedAt);
|
|
119
|
+
}
|
|
120
|
+
/** Get all page summaries, optionally filtered by scope. */
|
|
121
|
+
getPageSummaries(scope) {
|
|
122
|
+
const rows = this.db
|
|
123
|
+
.prepare("SELECT * FROM page_summaries ORDER BY updated_at DESC")
|
|
124
|
+
.all();
|
|
125
|
+
const summaries = rows.map((row) => ({
|
|
126
|
+
slug: row.slug,
|
|
127
|
+
category: row.category,
|
|
128
|
+
scope: JSON.parse(row.scope_json || "[]"),
|
|
129
|
+
tags: JSON.parse(row.tags_json || "[]"),
|
|
130
|
+
firstParagraph: row.first_paragraph,
|
|
131
|
+
updatedAt: row.updated_at,
|
|
132
|
+
}));
|
|
133
|
+
if (!scope)
|
|
134
|
+
return summaries;
|
|
135
|
+
// Filter by scope: include global + matching, exclude excluded
|
|
136
|
+
return summaries.filter((s) => {
|
|
137
|
+
if (scope.exclude.length > 0 &&
|
|
138
|
+
s.scope.some((tag) => scope.exclude.includes(tag))) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
if (s.scope.includes("global"))
|
|
142
|
+
return true;
|
|
143
|
+
return s.scope.some((tag) => scope.include.includes(tag));
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/** Delete a page summary from the cache. */
|
|
147
|
+
deletePageSummary(slug) {
|
|
148
|
+
this.db
|
|
149
|
+
.prepare("DELETE FROM page_summaries WHERE slug = ?")
|
|
150
|
+
.run(slug);
|
|
151
|
+
}
|
|
152
|
+
close() {
|
|
153
|
+
this.db.close();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function hashFile(filePath) {
|
|
157
|
+
try {
|
|
158
|
+
const content = readFileSync(filePath);
|
|
159
|
+
return createHash("sha256").update(content).digest("hex");
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
return "missing";
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function rowToSession(row) {
|
|
166
|
+
return {
|
|
167
|
+
sessionPath: row.session_path,
|
|
168
|
+
contentHash: row.content_hash,
|
|
169
|
+
processedAt: row.processed_at,
|
|
170
|
+
scope: row.scope ?? "",
|
|
171
|
+
pagesCreated: JSON.parse(row.pages_created || "[]"),
|
|
172
|
+
pagesUpdated: JSON.parse(row.pages_updated || "[]"),
|
|
173
|
+
error: row.error,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAqBjC,MAAM,OAAO,OAAO;IACV,EAAE,CAAoB;IAE9B,YAAY,OAAe;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAC/C,IAAI,CAAC,EAAE,GAAG,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;QA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