@pi-unipi/compactor 0.2.3 → 2.0.1

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.
@@ -1,109 +0,0 @@
1
- /**
2
- * Unified search across ContentStore + SessionDB events
3
- * Supports timeline (chronological) and relevance sorting
4
- * (from context-mode src/search/unified.ts)
5
- */
6
-
7
- import type { ContentStore } from "./index.js";
8
- import type { SessionDB } from "../session/db.js";
9
- import type { SearchResult } from "../types.js";
10
-
11
- export interface UnifiedSearchResult {
12
- title: string;
13
- content: string;
14
- source: string;
15
- origin: "current-session" | "prior-session";
16
- timestamp: string;
17
- rank: number;
18
- matchLayer: string;
19
- contentType: "prose" | "code";
20
- }
21
-
22
- export interface UnifiedSearchOptions {
23
- query: string;
24
- limit?: number;
25
- sort?: "relevance" | "timeline";
26
- source?: string;
27
- contentType?: string;
28
- projectDir?: string;
29
- }
30
-
31
- /**
32
- * Search across multiple sources and optionally sort chronologically.
33
- * - relevance: ContentStore only, ranked by RRF
34
- * - timeline: ContentStore + SessionDB events, sorted by timestamp
35
- */
36
- export async function searchAllSources(
37
- store: ContentStore,
38
- sessionDB: SessionDB | null,
39
- opts: UnifiedSearchOptions,
40
- ): Promise<UnifiedSearchResult[]> {
41
- const limit = opts.limit ?? 10;
42
- const sort = opts.sort ?? "relevance";
43
- const sessionStartTime = new Date().toISOString();
44
-
45
- const results: UnifiedSearchResult[] = [];
46
-
47
- // Source 1: ContentStore (always, both modes)
48
- try {
49
- const storeResults = await store.search(opts.query, { limit });
50
- results.push(
51
- ...storeResults.map((r) => ({
52
- title: r.title,
53
- content: r.content,
54
- source: r.source,
55
- origin: "current-session" as const,
56
- timestamp: sessionStartTime, // ContentStore doesn't track per-result timestamps yet
57
- rank: r.rank,
58
- matchLayer: r.matchLayer ?? "porter",
59
- contentType: r.contentType,
60
- })),
61
- );
62
- } catch {
63
- // ContentStore search failed — continue with other sources
64
- }
65
-
66
- // Source 2: SessionDB events (timeline mode only)
67
- if (sort === "timeline" && sessionDB) {
68
- try {
69
- const sessionId = opts.projectDir ?? "";
70
- const events = sessionDB.getEvents(sessionId, { limit: 100 });
71
- const queryLower = opts.query.toLowerCase();
72
- const matchingEvents = events.filter((e) => {
73
- const data = String(e.data ?? "").toLowerCase();
74
- const type = String(e.type ?? "").toLowerCase();
75
- const category = String(e.category ?? "").toLowerCase();
76
- return data.includes(queryLower) || type.includes(queryLower) || category.includes(queryLower);
77
- });
78
-
79
- results.push(
80
- ...matchingEvents.slice(0, limit).map((e) => ({
81
- title: `[${e.category}] ${e.type}`,
82
- content: String(e.data ?? "").slice(0, 500),
83
- source: "prior-session",
84
- origin: "prior-session" as const,
85
- timestamp: e.created_at ?? sessionStartTime,
86
- rank: 0,
87
- matchLayer: "event",
88
- contentType: "prose" as const,
89
- })),
90
- );
91
- } catch {
92
- // SessionDB search failed — continue
93
- }
94
- }
95
-
96
- // Normalize SQLite datetime format to ISO 8601
97
- for (const r of results) {
98
- if (r.timestamp && !r.timestamp.includes("T")) {
99
- r.timestamp = r.timestamp.replace(" ", "T") + "Z";
100
- }
101
- }
102
-
103
- // Sort: timeline = chronological, relevance = by rank
104
- if (sort === "timeline") {
105
- results.sort((a, b) => (a.timestamp || "").localeCompare(b.timestamp || ""));
106
- }
107
-
108
- return results.slice(0, limit);
109
- }
@@ -1,32 +0,0 @@
1
- /**
2
- * ctx_fetch_and_index tool — fetch URL → markdown → index
3
- */
4
-
5
- import type { ContentStore } from "../store/index.js";
6
- import type { IndexResult } from "../types.js";
7
-
8
- export interface CtxFetchAndIndexInput {
9
- url: string;
10
- label?: string;
11
- chunkSize?: number;
12
- }
13
-
14
- export async function ctxFetchAndIndex(store: ContentStore, input: CtxFetchAndIndexInput): Promise<IndexResult> {
15
- const label = input.label ?? input.url;
16
-
17
- const response = await fetch(input.url, {
18
- headers: { "User-Agent": "pi-unipi-compactor/0.1.0" },
19
- });
20
-
21
- if (!response.ok) {
22
- throw new Error(`Fetch failed: ${response.status} ${response.statusText}`);
23
- }
24
-
25
- const text = await response.text();
26
-
27
- return store.index(label, text, {
28
- contentType: "plain",
29
- source: input.url,
30
- chunkSize: input.chunkSize,
31
- });
32
- }
@@ -1,36 +0,0 @@
1
- /**
2
- * ctx_index tool — chunk content → index into FTS5
3
- */
4
-
5
- import type { ContentStore } from "../store/index.js";
6
- import type { IndexResult } from "../types.js";
7
- import { readFileSync } from "node:fs";
8
-
9
- export interface CtxIndexInput {
10
- label: string;
11
- content?: string;
12
- filePath?: string;
13
- contentType?: "markdown" | "json" | "plain";
14
- chunkSize?: number;
15
- }
16
-
17
- export async function ctxIndex(store: ContentStore, input: CtxIndexInput): Promise<IndexResult> {
18
- let text: string;
19
- let source: string;
20
-
21
- if (input.filePath) {
22
- text = readFileSync(input.filePath, "utf-8");
23
- source = input.filePath;
24
- } else if (input.content) {
25
- text = input.content;
26
- source = input.label;
27
- } else {
28
- throw new Error("Either content or filePath must be provided");
29
- }
30
-
31
- return store.index(input.label, text, {
32
- contentType: input.contentType ?? "plain",
33
- source,
34
- chunkSize: input.chunkSize,
35
- });
36
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * ctx_search tool — query indexed content
3
- */
4
-
5
- import type { ContentStore } from "../store/index.js";
6
- import type { SearchResult } from "../types.js";
7
-
8
- export interface CtxSearchInput {
9
- query: string;
10
- limit?: number;
11
- offset?: number;
12
- }
13
-
14
- export async function ctxSearch(store: ContentStore, input: CtxSearchInput): Promise<SearchResult[]> {
15
- return store.search(input.query, {
16
- limit: input.limit ?? 10,
17
- offset: input.offset ?? 0,
18
- });
19
- }