acp-kernel 0.0.13 → 0.0.15
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/README.md +1 -2
- package/dist/compress.d.ts.map +1 -1
- package/dist/compression-rules.d.ts +2 -2
- package/dist/compression-rules.d.ts.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +291 -95
- package/dist/index.js.map +1 -1
- package/dist/protected.d.ts +4 -1
- package/dist/protected.d.ts.map +1 -1
- package/dist/search/algorithms/bm25.d.ts +15 -0
- package/dist/search/algorithms/bm25.d.ts.map +1 -0
- package/dist/search/algorithms/fuzzy.d.ts +14 -0
- package/dist/search/algorithms/fuzzy.d.ts.map +1 -0
- package/dist/search/algorithms/hybrid.d.ts +3 -0
- package/dist/search/algorithms/hybrid.d.ts.map +1 -0
- package/dist/search/algorithms/semantic.d.ts +37 -0
- package/dist/search/algorithms/semantic.d.ts.map +1 -0
- package/dist/search/algorithms/substring.d.ts +9 -0
- package/dist/search/algorithms/substring.d.ts.map +1 -0
- package/dist/search/index.d.ts +31 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/registry.d.ts +10 -0
- package/dist/search/registry.d.ts.map +1 -0
- package/dist/search/stemmer.d.ts +11 -0
- package/dist/search/stemmer.d.ts.map +1 -0
- package/dist/search/tokenizer.d.ts +17 -0
- package/dist/search/tokenizer.d.ts.map +1 -0
- package/dist/search/types.d.ts +92 -0
- package/dist/search/types.d.ts.map +1 -0
- package/dist/search.d.ts +5 -24
- package/dist/search.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/keep-markers.d.ts +0 -9
- package/dist/keep-markers.d.ts.map +0 -1
package/dist/protected.d.ts
CHANGED
|
@@ -16,9 +16,12 @@ export declare const ALWAYS_PROTECTED_TOOLS: readonly ["compress"];
|
|
|
16
16
|
* preserveRecent is about not compressing the active working set, not about
|
|
17
17
|
* which tool results are in scope).
|
|
18
18
|
*
|
|
19
|
+
* `search_context` returns large result lists (10 ranked hits with previews).
|
|
20
|
+
* Same reasoning: excluding it from the protected zone keeps it compressible.
|
|
21
|
+
*
|
|
19
22
|
* Note: this only affects the recent-zone computation. Such messages remain
|
|
20
23
|
* fully visible and compressible like any ordinary message. */
|
|
21
|
-
export declare const NEVER_PRESERVE_RECENT_TOOLS: readonly ["decompress"];
|
|
24
|
+
export declare const NEVER_PRESERVE_RECENT_TOOLS: readonly ["decompress", "search_context"];
|
|
22
25
|
/** True for tool-call / tool-result messages whose toolName is in the
|
|
23
26
|
* NEVER_PRESERVE_RECENT_TOOLS list — i.e. tool results (like decompress)
|
|
24
27
|
* that should be excluded from the soft-protected recent zone. */
|
package/dist/protected.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protected.d.ts","sourceRoot":"","sources":["../src/protected.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;kFAIkF;AAClF,eAAO,MAAM,sBAAsB,uBAAwB,CAAC;AAE5D
|
|
1
|
+
{"version":3,"file":"protected.d.ts","sourceRoot":"","sources":["../src/protected.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;kFAIkF;AAClF,eAAO,MAAM,sBAAsB,uBAAwB,CAAC;AAE5D;;;;;;;;;;;;;;;gEAegE;AAChE,eAAO,MAAM,2BAA2B,2CAA4C,CAAC;AAErF;;mEAEmE;AACnE,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAM/D;AAED,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAK3E;AAED,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CAAC,GACzD,OAAO,CAsBT;AAED;;;8DAG8D;AAC9D,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,WAAW,EAAE,EACvB,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CAAC,GACzD,GAAG,CAAC,MAAM,CAAC,CAQb;AAED;iFACiF;AACjF,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,WAAW,EAChB,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CAAC,EAC1D,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,GAC5B,OAAO,CAUT"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SearchAlgorithm } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* BM25 with stemming + CJK bigram tokenization.
|
|
4
|
+
*
|
|
5
|
+
* k1=1.2, b=0.75 (standard IR). IDF down-weights terms common across the
|
|
6
|
+
* corpus; length normalization prevents long summaries from dominating by
|
|
7
|
+
* raw term count. Stemming collapses English morphology
|
|
8
|
+
* (compress/compressed/compression → ~compress).
|
|
9
|
+
*
|
|
10
|
+
* On a 30-block mixed EN/CJK benchmark: MRR 0.812 vs 0.821 for substring
|
|
11
|
+
* alone — not better in isolation, but a strong precision component when
|
|
12
|
+
* combined with fuzzy recall (see hybrid.ts).
|
|
13
|
+
*/
|
|
14
|
+
export declare const bm25Algorithm: SearchAlgorithm;
|
|
15
|
+
//# sourceMappingURL=bm25.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bm25.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/bm25.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAG3E;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,aAAa,EAAE,eAqC3B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SearchAlgorithm } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Fuzzy character-bigram matching (Jaccard-style).
|
|
4
|
+
*
|
|
5
|
+
* Decomposes the query into character bigrams and measures overlap with
|
|
6
|
+
* each doc. Robust to typos (tokan≈token), partial words, and works
|
|
7
|
+
* uniformly across all scripts (CJK benefits most). Only considers query
|
|
8
|
+
* tokens of length >= 4 to avoid noise from short common-character pairs.
|
|
9
|
+
*
|
|
10
|
+
* On benchmark: highest recall@3 (0.913) of any single algorithm — it is
|
|
11
|
+
* the recall boost in the hybrid default.
|
|
12
|
+
*/
|
|
13
|
+
export declare const fuzzyAlgorithm: SearchAlgorithm;
|
|
14
|
+
//# sourceMappingURL=fuzzy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fuzzy.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/fuzzy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAG3E;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,EAAE,eAmB5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hybrid.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/hybrid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAwB3E,eAAO,MAAM,eAAe,EAAE,eAe7B,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OPTIONAL semantic search algorithm (embedding-based).
|
|
3
|
+
*
|
|
4
|
+
* NOT registered by default — acp-kernel stays zero-runtime-deps. This is a
|
|
5
|
+
* reference implementation showing how a host plugs in a heavyweight
|
|
6
|
+
* semantic retriever. It catches the queries lexical algorithms cannot:
|
|
7
|
+
* synonyms (login↔登录), cross-language (cache↔缓存), and paraphrase.
|
|
8
|
+
*
|
|
9
|
+
* score() returns a Promise, so use it via searchBlocksAsync():
|
|
10
|
+
*
|
|
11
|
+
* import { registerSearchAlgorithm, searchBlocksAsync } from "acp-kernel";
|
|
12
|
+
* import { createSemanticAlgorithm } from "acp-kernel/search/algorithms/semantic";
|
|
13
|
+
*
|
|
14
|
+
* registerSearchAlgorithm(createSemanticAlgorithm({
|
|
15
|
+
* embed: async (texts) => embeddingApi.embed(texts), // → number[][]
|
|
16
|
+
* }));
|
|
17
|
+
*
|
|
18
|
+
* const results = await searchBlocksAsync(state, "credentials", { algorithm: "semantic" });
|
|
19
|
+
*
|
|
20
|
+
* The `embed` function is host-supplied — pick any backend:
|
|
21
|
+
* - @huggingface/transformers (local, ~25MB model, offline, ~25ms/query)
|
|
22
|
+
* - OpenAI / Voyage / Cohere embeddings API (remote, needs key)
|
|
23
|
+
* - a local inference server
|
|
24
|
+
*
|
|
25
|
+
* Embeddings are memoized by content hash: docs only re-embed when their
|
|
26
|
+
* summary changes. The query embeds fresh each call.
|
|
27
|
+
*/
|
|
28
|
+
import type { AsyncSearchAlgorithm } from "../types.js";
|
|
29
|
+
export interface EmbedFn {
|
|
30
|
+
(texts: string[]): Promise<number[][]>;
|
|
31
|
+
}
|
|
32
|
+
export interface SemanticOptions {
|
|
33
|
+
embed: EmbedFn;
|
|
34
|
+
name?: string;
|
|
35
|
+
}
|
|
36
|
+
export declare function createSemanticAlgorithm(opts: SemanticOptions): AsyncSearchAlgorithm;
|
|
37
|
+
//# sourceMappingURL=semantic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/semantic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAA0B,MAAM,aAAa,CAAC;AAEhF,MAAM,WAAW,OAAO;IACpB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AA6BD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,eAAe,GAAG,oBAAoB,CAuCnF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SearchAlgorithm } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Substring counting — the original baseline algorithm.
|
|
4
|
+
* Exact, lowercased substring occurrence counts. Predictable but blind to
|
|
5
|
+
* morphology, typos, and CJK word boundaries. Kept for backward compat and
|
|
6
|
+
* as a deterministic reference.
|
|
7
|
+
*/
|
|
8
|
+
export declare const substringAlgorithm: SearchAlgorithm;
|
|
9
|
+
//# sourceMappingURL=substring.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"substring.d.ts","sourceRoot":"","sources":["../../../src/search/algorithms/substring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAA0B,MAAM,aAAa,CAAC;AAE3E;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,EAAE,eAahC,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* searchBlocks — public search entry point.
|
|
3
|
+
*
|
|
4
|
+
* Scores a unified document set (block summaries + historical messages)
|
|
5
|
+
* and returns ranked results. The model uses search to cheaply locate
|
|
6
|
+
* detail that compression folded into summaries, then decompresses the
|
|
7
|
+
* owning block for the full content.
|
|
8
|
+
*
|
|
9
|
+
* Two entry points:
|
|
10
|
+
* - searchBlocks() — sync. Works for all lexical algorithms.
|
|
11
|
+
* - searchBlocksAsync() — async. Also supports embedding-based semantic
|
|
12
|
+
* algorithms whose score() returns a Promise.
|
|
13
|
+
*/
|
|
14
|
+
import type { CompressionState } from "../types.js";
|
|
15
|
+
import type { SearchDoc, MessageInput } from "./types.js";
|
|
16
|
+
import type { SearchResult, SearchOptions } from "./types.js";
|
|
17
|
+
/** Build SearchDoc[] from all blocks (active AND inactive) of the state. */
|
|
18
|
+
export declare function blockDocs(state: CompressionState): SearchDoc[];
|
|
19
|
+
/**
|
|
20
|
+
* Build SearchDoc[] from historical messages supplied by the host. The host
|
|
21
|
+
* (pai-acp) reads these from the append-only session log — they include the
|
|
22
|
+
* original text of messages that compression later folded into block summaries.
|
|
23
|
+
*
|
|
24
|
+
* `ownerOf(ref)` maps a message ref to the block id that compressed it, so a
|
|
25
|
+
* message hit tells the model exactly which block to decompress for detail.
|
|
26
|
+
*/
|
|
27
|
+
export declare function messageDocs(msgs: MessageInput[]): SearchDoc[];
|
|
28
|
+
/** Sync entry — throws for async algorithms. Pass docs from blockDocs() + messageDocs(). */
|
|
29
|
+
export declare function searchBlocks(docs: SearchDoc[], query: string, options?: SearchOptions): SearchResult[];
|
|
30
|
+
export declare function searchBlocksAsync(docs: SearchDoc[], query: string, options?: SearchOptions): Promise<SearchResult[]>;
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/search/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAoB,MAAM,aAAa,CAAC;AAEtE,OAAO,KAAK,EAAE,SAAS,EAAe,YAAY,EAAE,MAAM,YAAY,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAe,MAAM,YAAY,CAAC;AAG3E,4EAA4E;AAC5E,wBAAgB,SAAS,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,EAAE,CAU9D;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,EAAE,GAAG,SAAS,EAAE,CAW7D;AAkED,4FAA4F;AAC5F,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,YAAY,EAAE,CAQ1G;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,CAE9H"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Algorithm registry. Builtins are pre-registered; hosts may register
|
|
3
|
+
* additional algorithms (e.g. an embedding-based semantic provider) via
|
|
4
|
+
* registerSearchAlgorithm and reference them by name in SearchOptions.
|
|
5
|
+
*/
|
|
6
|
+
import type { AnySearchAlgorithm } from "./types.js";
|
|
7
|
+
export declare function registerSearchAlgorithm(algo: AnySearchAlgorithm): void;
|
|
8
|
+
export declare function getSearchAlgorithm(name: string): AnySearchAlgorithm | undefined;
|
|
9
|
+
export declare function listSearchAlgorithms(): AnySearchAlgorithm[];
|
|
10
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/search/registry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAQrD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,kBAAkB,GAAG,IAAI,CAEtE;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAE/E;AAED,wBAAgB,oBAAoB,IAAI,kBAAkB,EAAE,CAE3D"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight English stemmer (suffix stripping, Porter-inspired).
|
|
3
|
+
* Zero dependencies. Good enough for IR morphology normalization:
|
|
4
|
+
* tokens → token, running → runn, compressed → compress,
|
|
5
|
+
* authentication → authentic, handling → handl, subagents → subagent
|
|
6
|
+
*
|
|
7
|
+
* Not a full Porter stemmer — intentionally simpler and faster. CJK is
|
|
8
|
+
* untouched (handled by bigram tokenization, not stemming).
|
|
9
|
+
*/
|
|
10
|
+
export declare function stem(word: string): string;
|
|
11
|
+
//# sourceMappingURL=stemmer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stemmer.d.ts","sourceRoot":"","sources":["../../src/search/stemmer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgBzC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search tokenizer.
|
|
3
|
+
*
|
|
4
|
+
* Handles mixed Latin + CJK content — the single biggest quality lever
|
|
5
|
+
* over plain substring search. Latin is split on non-word boundaries;
|
|
6
|
+
* CJK (no spaces) is decomposed into overlapping bigrams so a query like
|
|
7
|
+
* "身份验证" still scores against doc text "身份验证流程".
|
|
8
|
+
*/
|
|
9
|
+
export interface TokenizeOptions {
|
|
10
|
+
stem?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function tokenize(text: string, opts?: TokenizeOptions): string[];
|
|
13
|
+
/** Character bigrams over arbitrary text — used by fuzzy matching. */
|
|
14
|
+
export declare function charBigrams(text: string): string[];
|
|
15
|
+
/** Term-frequency map. */
|
|
16
|
+
export declare function tfMap(text: string, stem: boolean): Map<string, number>;
|
|
17
|
+
//# sourceMappingURL=tokenizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenizer.d.ts","sourceRoot":"","sources":["../../src/search/tokenizer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,MAAM,WAAW,eAAe;IAC5B,IAAI,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,eAAoB,GAAG,MAAM,EAAE,CAuB3E;AAED,sEAAsE;AACtE,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAOlD;AAED,0BAA0B;AAC1B,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAItE"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search type definitions.
|
|
3
|
+
*
|
|
4
|
+
* Two data sources are searchable:
|
|
5
|
+
* - Compressed blocks (summary text; ref = "b{id}")
|
|
6
|
+
* - Historical messages (original text from the append-only session log;
|
|
7
|
+
* ref = "m{NNNNN}"). These let the model locate detail that compression
|
|
8
|
+
* turned into a short summary — search to pinpoint, then decompress the
|
|
9
|
+
* owning block for the full content.
|
|
10
|
+
*
|
|
11
|
+
* A SearchAlgorithm is a stateless scorer over a unified SearchDoc[]. Roles
|
|
12
|
+
* carry a configurable weight (user intent > assistant reasoning > tool noise).
|
|
13
|
+
*/
|
|
14
|
+
/** Where a searchable document came from. */
|
|
15
|
+
export type SearchDocKind = "block" | "message";
|
|
16
|
+
export type MessageRole = "user" | "assistant" | "tool";
|
|
17
|
+
/** A unified searchable document — either a block summary or a message. */
|
|
18
|
+
export interface SearchDoc {
|
|
19
|
+
kind: SearchDocKind;
|
|
20
|
+
/** Stable ref for decompress: "b3" for a block, "m00350" for a message. */
|
|
21
|
+
ref: string;
|
|
22
|
+
/** Text this doc is scored against (topic+summary for blocks; content for messages). */
|
|
23
|
+
text: string;
|
|
24
|
+
/** For preview/title display. */
|
|
25
|
+
title: string;
|
|
26
|
+
/** Message role (messages only); undefined for blocks. Drives role weighting. */
|
|
27
|
+
role?: MessageRole;
|
|
28
|
+
/** Block owning this doc. For blocks: the block itself. For messages: the block
|
|
29
|
+
* that compressed it (so the model knows which block to decompress for detail). */
|
|
30
|
+
blockId?: string;
|
|
31
|
+
/** Tier of the owning block (display + grouping). */
|
|
32
|
+
tier?: number;
|
|
33
|
+
/** Approx token size (for "how big is this" display). */
|
|
34
|
+
tokens?: number;
|
|
35
|
+
}
|
|
36
|
+
/** Per-role score multipliers. Defaults favor user intent over tool noise. */
|
|
37
|
+
export interface RoleWeights {
|
|
38
|
+
user?: number;
|
|
39
|
+
assistant?: number;
|
|
40
|
+
tool?: number;
|
|
41
|
+
block?: number;
|
|
42
|
+
}
|
|
43
|
+
export declare const DEFAULT_ROLE_WEIGHTS: Required<RoleWeights>;
|
|
44
|
+
export interface ScoredBlock {
|
|
45
|
+
ref: string;
|
|
46
|
+
score: number;
|
|
47
|
+
}
|
|
48
|
+
export interface SearchAlgorithm {
|
|
49
|
+
name: string;
|
|
50
|
+
description: string;
|
|
51
|
+
score(docs: SearchDoc[], query: string): ScoredBlock[];
|
|
52
|
+
}
|
|
53
|
+
export interface AsyncSearchAlgorithm {
|
|
54
|
+
name: string;
|
|
55
|
+
description: string;
|
|
56
|
+
score(docs: SearchDoc[], query: string): Promise<ScoredBlock[]>;
|
|
57
|
+
}
|
|
58
|
+
export type AnySearchAlgorithm = SearchAlgorithm | AsyncSearchAlgorithm;
|
|
59
|
+
export interface SearchResult {
|
|
60
|
+
/** "block" or "message". */
|
|
61
|
+
kind: SearchDocKind;
|
|
62
|
+
/** Ref to pass to decompress: "b3" or "m00350". */
|
|
63
|
+
ref: string;
|
|
64
|
+
/** Owning block id (for messages: the block that compressed it). */
|
|
65
|
+
blockId?: string;
|
|
66
|
+
tier: number;
|
|
67
|
+
score: number;
|
|
68
|
+
title: string;
|
|
69
|
+
preview: string;
|
|
70
|
+
role?: MessageRole;
|
|
71
|
+
tokens?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface SearchOptions {
|
|
74
|
+
algorithm?: string;
|
|
75
|
+
limit?: number;
|
|
76
|
+
previewLength?: number;
|
|
77
|
+
minScore?: number;
|
|
78
|
+
/** Per-role weights (default DEFAULT_ROLE_WEIGHTS). */
|
|
79
|
+
roleWeights?: RoleWeights;
|
|
80
|
+
}
|
|
81
|
+
/** Host-supplied historical message, turned into a message SearchDoc. */
|
|
82
|
+
export interface MessageInput {
|
|
83
|
+
ref: string;
|
|
84
|
+
role: MessageRole;
|
|
85
|
+
text: string;
|
|
86
|
+
tokens?: number;
|
|
87
|
+
/** Block id that compressed this message (undefined if still visible). */
|
|
88
|
+
blockId?: string;
|
|
89
|
+
tier?: number;
|
|
90
|
+
}
|
|
91
|
+
export declare const DEFAULT_ALGORITHM = "hybrid";
|
|
92
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/search/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,6CAA6C;AAC7C,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,SAAS,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAExD,2EAA2E;AAC3E,MAAM,WAAW,SAAS;IACtB,IAAI,EAAE,aAAa,CAAC;IACpB,2EAA2E;IAC3E,GAAG,EAAE,MAAM,CAAC;IACZ,wFAAwF;IACxF,IAAI,EAAE,MAAM,CAAC;IACb,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,iFAAiF;IACjF,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB;wFACoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qDAAqD;IACrD,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,8EAA8E;AAC9E,MAAM,WAAW,WAAW;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,oBAAoB,EAAE,QAAQ,CAAC,WAAW,CAKtD,CAAC;AAEF,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,WAAW,EAAE,CAAC;CAC1D;AAED,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;CACnE;AAED,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG,oBAAoB,CAAC;AAExE,MAAM,WAAW,YAAY;IACzB,4BAA4B;IAC5B,IAAI,EAAE,aAAa,CAAC;IACpB,mDAAmD;IACnD,GAAG,EAAE,MAAM,CAAC;IACZ,oEAAoE;IACpE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,WAAW,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,WAAW,CAAC,EAAE,WAAW,CAAC;CAC7B;AAED,yEAAyE;AACzE,MAAM,WAAW,YAAY;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0EAA0E;IAC1E,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,iBAAiB,WAAW,CAAC"}
|
package/dist/search.d.ts
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* This is the core value of ACP: as conversations grow, most history becomes
|
|
5
|
-
* invisible (compressed into summary blocks). Search is the only way to
|
|
6
|
-
* retrieve specific information from that invisible content.
|
|
7
|
-
*
|
|
8
|
-
* Current implementation: substring counting (simple but effective for
|
|
9
|
-
* dozens of blocks). Future: TF-IDF, fuzzy matching, CJK tokenization,
|
|
10
|
-
* semantic search.
|
|
2
|
+
* Search — re-exports from the modular src/search/ implementation.
|
|
11
3
|
*/
|
|
12
|
-
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
score: number;
|
|
17
|
-
topic: string;
|
|
18
|
-
preview: string;
|
|
19
|
-
block: CompressionBlock;
|
|
20
|
-
}
|
|
21
|
-
export interface SearchOptions {
|
|
22
|
-
limit?: number;
|
|
23
|
-
previewLength?: number;
|
|
24
|
-
minScore?: number;
|
|
25
|
-
}
|
|
26
|
-
export declare function searchBlocks(state: CompressionState, query: string, options?: SearchOptions): SearchResult[];
|
|
4
|
+
export { searchBlocks, searchBlocksAsync, blockDocs, messageDocs } from "./search/index.js";
|
|
5
|
+
export type { SearchResult, SearchOptions, SearchAlgorithm, AsyncSearchAlgorithm, AnySearchAlgorithm, SearchDoc, SearchDocKind, ScoredBlock, MessageRole, RoleWeights, MessageInput, } from "./search/types.js";
|
|
6
|
+
export { DEFAULT_ALGORITHM, DEFAULT_ROLE_WEIGHTS } from "./search/types.js";
|
|
7
|
+
export { registerSearchAlgorithm, getSearchAlgorithm, listSearchAlgorithms } from "./search/registry.js";
|
|
27
8
|
//# sourceMappingURL=search.d.ts.map
|
package/dist/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5F,YAAY,EACR,YAAY,EACZ,aAAa,EACb,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/package.json
CHANGED
package/dist/keep-markers.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { CompressionState, CoreMessage } from "./types.js";
|
|
2
|
-
export interface KeepMarkerResult {
|
|
3
|
-
summary: string;
|
|
4
|
-
expandedCount: number;
|
|
5
|
-
refCount: number;
|
|
6
|
-
unresolvedRefs: string[];
|
|
7
|
-
}
|
|
8
|
-
export declare function resolveKeepMarkers(summary: string, messages: CoreMessage[], state: CompressionState, maxChars?: number): KeepMarkerResult;
|
|
9
|
-
//# sourceMappingURL=keep-markers.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"keep-markers.d.ts","sourceRoot":"","sources":["../src/keep-markers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAKhE,MAAM,WAAW,gBAAgB;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED,wBAAgB,kBAAkB,CAC9B,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,WAAW,EAAE,EACvB,KAAK,EAAE,gBAAgB,EACvB,QAAQ,SAAO,GAChB,gBAAgB,CAkClB"}
|