@securecoms/agent-bridge 0.28.1 → 0.29.0

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.
Files changed (33) hide show
  1. package/README.md +192 -79
  2. package/dist/bin.js +2841 -169
  3. package/dist/bridge-agent.d.ts +190 -1
  4. package/dist/config.d.ts +2 -0
  5. package/dist/embedder.js +2 -1
  6. package/dist/index.js +2815 -143
  7. package/dist/memory/embedder/client.d.ts +20 -0
  8. package/dist/memory/embedder/protocol.d.ts +5 -0
  9. package/dist/memory/note-frames.d.ts +1 -1
  10. package/dist/memory/recall/recall-book.d.ts +12 -2
  11. package/dist/memory/unified/chunk.d.ts +12 -0
  12. package/dist/memory/unified/config.d.ts +7 -0
  13. package/dist/memory/unified/consumer-unified.d.ts +21 -0
  14. package/dist/memory/unified/escape.d.ts +23 -0
  15. package/dist/memory/unified/index-key.d.ts +8 -0
  16. package/dist/memory/unified/item-book.d.ts +70 -0
  17. package/dist/memory/unified/item-reembed.d.ts +20 -0
  18. package/dist/memory/unified/migrate.d.ts +68 -0
  19. package/dist/memory/unified/owner-scope.d.ts +48 -0
  20. package/dist/memory/unified/pin-rules.d.ts +18 -0
  21. package/dist/memory/unified/ranking-client.d.ts +48 -0
  22. package/dist/memory/unified/ranking-core-constants.d.ts +8 -0
  23. package/dist/memory/unified/ranking-core.d.ts +117 -0
  24. package/dist/memory/unified/ranking-inprocess.d.ts +3 -0
  25. package/dist/memory/unified/ranking-worker.d.ts +1 -0
  26. package/dist/memory/unified/read-book.d.ts +80 -0
  27. package/dist/memory/unified/switch.d.ts +8 -0
  28. package/dist/memory/unified/text.d.ts +15 -0
  29. package/dist/memory/unified/worker-protocol.d.ts +102 -0
  30. package/dist/memory-worker.js +583 -0
  31. package/dist/version.d.ts +1 -1
  32. package/dist/ws-server.d.ts +3 -1
  33. package/package.json +1 -1
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Unified memory (spec section 8.1; H-4, U11, U15): the per-turn read. The capture is taken first (U11); pinned facts come
3
+ * from a cache keyed by the owner-DM scope id (never per agent, H-A) and filled from the worker under the memory mutex;
4
+ * the search runs on the worker; everything shares the turn kind's one deadline (600 ms typed, 250 ms voice). Past it:
5
+ * pinned facts only (from a current cache). Nothing attaches late. Delivery re-checks the capture and the owner scope.
6
+ * No SQL here (T-33): the constants come from the import-free ranking-core-constants.ts, never ranking-core.ts.
7
+ */
8
+ import { type SqliteMlsStateStore } from "@agentvault/connect-mls-store";
9
+ import type { Embedder } from "../embedder/client.js";
10
+ import type { RankingClient } from "./ranking-client.js";
11
+ export interface UnifiedFrameItem {
12
+ block: "pinned" | "owner" | "reference";
13
+ id: number;
14
+ source: string;
15
+ at: number;
16
+ text: string;
17
+ }
18
+ /** The runtime's parseUnified limits (connect-agent-runtime memory-unified.ts): one item over them blanks the whole block there. */
19
+ export declare const FRAME_ITEMS_MAX = 210;
20
+ export declare const FRAME_TEXT_MAX = 1000;
21
+ export declare class UnifiedReadBook {
22
+ private readonly d;
23
+ private readonly entries;
24
+ private readonly pinCache;
25
+ /**
26
+ * Plan audit M-6: the texts DELIVERED with each message, kept until ack/nack/retire (`drop`), so a forget that follows
27
+ * a pin in the same message (the pin's dropChannelLocked empties `entries`) still finds its text for the Forgot: line.
28
+ * Cleared by a clear (dropAllLocked) and an owner-scope purge (dropScopeLocked), never by a channel cache refresh.
29
+ */
30
+ private readonly shown;
31
+ private reads;
32
+ /** Fix round 1: turns whose read missed its deadline (a local late, or a pins/query answer late or failed); one per turn. */
33
+ private misses;
34
+ /**
35
+ * Fix round 1 (ruling): bumped by every drop*Locked and by bumpGeneration (Task 28: a pin insert). Taken before the
36
+ * pins request and compared at install and before the entry is kept, so a drop during an await is never undone.
37
+ */
38
+ private gen;
39
+ /** Fix round 2: reads thrown away because the generation moved (a drop, a pin insert); not deadline misses. */
40
+ private discarded;
41
+ constructor(d: {
42
+ store: Pick<SqliteMlsStateStore, "itemCapture">;
43
+ ranking: Pick<RankingClient, "query" | "pins">;
44
+ embedder: Embedder;
45
+ embedOn: () => boolean;
46
+ indexKey: Uint8Array;
47
+ exclusive: <T>(fn: () => Promise<T>) => Promise<T>;
48
+ now?: () => number;
49
+ });
50
+ /** The health key memory_reads: owner-DM reads started since boot. */
51
+ readsAttempted(): number;
52
+ /** The health key memory_deadline_misses: owner-DM turns that got no search result in time (U15). */
53
+ deadlineMisses(): number;
54
+ /** The health key memory_reads_discarded: reads not kept because a drop or pin insert moved the generation during them. */
55
+ readsDiscarded(): number;
56
+ /** Invalidates the pin cache and every read in flight (Task 28 calls it, under the memory mutex, when a pin is inserted). */
57
+ bumpGeneration(): void;
58
+ prepare(p: {
59
+ messageId: string;
60
+ channelId: string;
61
+ scopeId: string;
62
+ text: string;
63
+ kind: "text" | "voice";
64
+ }): Promise<void>;
65
+ /** ws flush (synchronous): the entry's own channel and owner scope, its capture still current (H-4, U11). */
66
+ deliverable(messageId: string, channelId: string, scopeIdNow: string): {
67
+ items: UnifiedFrameItem[];
68
+ pinnedMore: number;
69
+ } | undefined;
70
+ /** Section 7.4 step 3: texts of owner-trust TYPED items shown with this delivery (never owner_voice, never reference). */
71
+ coverageTexts(messageId: string, shown: ReadonlySet<number>): string[];
72
+ /** M-6: what was DELIVERED with this message (kept until ack), not the prepare-time entry a cache refresh can drop. */
73
+ shownText(messageId: string, itemId: number): string | undefined;
74
+ /** Task 29 fix round 1: a forgotten item's delivered text leaves the shown map at once (not only at ack). */
75
+ forgetShown(messageId: string, itemId: number): void;
76
+ drop(messageId: string): void;
77
+ dropAllLocked(): void;
78
+ dropChannelLocked(channelId: string): void;
79
+ dropScopeLocked(scopeId: string): void;
80
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Unified agent memory, part 1 (spec 2026-10-10 §18, R-U25): a compiled literal, default off, flipped only by the
3
+ * release task after the Mac mini live check. A backend flag is not used: it would let the server widen cross-scope
4
+ * reads. While false the bridge behaves as 0.28.2 on every memory path.
5
+ */
6
+ export declare const UNIFIED_MEMORY_PART1 = true;
7
+ /** `injected` is the test seam (the bridge agent's deps field for this switch); production never passes it (switch.arch.test.ts). */
8
+ export declare function unifiedPart1On(injected?: boolean): boolean;
@@ -0,0 +1,15 @@
1
+ export declare function foldText(s: string): string;
2
+ export declare function tokens(s: string): string[];
3
+ /** H-1, H-2: English cardinals and ordinals count as digit-bearing (65 words, frozen). */
4
+ export declare const NUMBER_WORDS: ReadonlySet<string>;
5
+ /** A canonical Roman numeral (lower case after foldText). Note: "i", "v", "x" and "mix" match; Task 35 measures the effect. */
6
+ export declare function isRomanNumeral(t: string): boolean;
7
+ export declare function isDigitBearing(t: string): boolean;
8
+ /** §11.5: a fixed English stop-word list (126 words: the NLTK English list without its contractions), never indexed. */
9
+ export declare const STOP_WORDS: ReadonlySet<string>;
10
+ /** L-3: the fixed English suffix set for query-side expansion (the plan enumerates it, spec §11.5). y↔ies is added below. */
11
+ export declare const QUERY_SUFFIXES: readonly string[];
12
+ /** §11.5: an item's exact, de-duplicated tokens, stop words dropped. No stems. */
13
+ export declare function indexTokens(text: string): string[];
14
+ /** L-3: the token, the token plus each suffix, the token minus each suffix it ends with (never below 3 characters), and y↔ies. */
15
+ export declare function queryExpansions(t: string): string[];
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Unified memory (spec section 8.5, H-7, T-33): the messages between the bridge and its ranking worker. Only ids, scores and
3
+ * the opened texts of the items selected for a turn cross back. No message type FROM the worker carries a vector or a
4
+ * raw sealed buffer (worker-protocol.arch.test.ts, Task 14). The query vector goes TO the worker.
5
+ */
6
+ import type { ItemKind, ItemSource, ItemTrust, ScopeKind } from "@agentvault/connect-mls-store/memory-items";
7
+ export interface WorkerInit {
8
+ dbPath: string;
9
+ identityId: string;
10
+ storeKey: Uint8Array;
11
+ modelId: string;
12
+ threshold: number;
13
+ warm: boolean;
14
+ /** Plan Task 35, the recall eval only: replaces OWNER_SCOPE_PRIOR / RECENCY_SLOPE (0.05 since U1-G). Production never sets them (worker-protocol.arch.test.ts). */
15
+ priorOverride?: number;
16
+ recencySlopeOverride?: number;
17
+ }
18
+ export interface RankQuery {
19
+ scopes: string[];
20
+ ownerScope: string | null;
21
+ vec: Float32Array | null;
22
+ macs: Uint8Array[];
23
+ historyConversation: string;
24
+ currentMessageId: string;
25
+ maxItems: number;
26
+ maxChars: number;
27
+ nowMs: number;
28
+ excludeOriginIds: string[];
29
+ }
30
+ export interface OpenedItem {
31
+ itemId: number;
32
+ scopeKind: ScopeKind;
33
+ scopeId: string;
34
+ channelId: string;
35
+ kind: ItemKind;
36
+ originId: string;
37
+ originAt: number;
38
+ source: ItemSource;
39
+ trust: ItemTrust;
40
+ text: string;
41
+ }
42
+ export type ToWorker = {
43
+ type: "query";
44
+ id: number;
45
+ q: RankQuery;
46
+ } | {
47
+ type: "pins";
48
+ id: number;
49
+ scopeId: string;
50
+ maxChars: number;
51
+ } | {
52
+ type: "pending";
53
+ id: number;
54
+ limit: number;
55
+ } | {
56
+ type: "added";
57
+ itemIds: number[];
58
+ } | {
59
+ type: "removed";
60
+ itemIds: number[];
61
+ } | {
62
+ type: "reset";
63
+ };
64
+ export type FromWorker = {
65
+ type: "ready";
66
+ hot: number;
67
+ hotBytes: number;
68
+ } | {
69
+ type: "result";
70
+ id: number;
71
+ items: OpenedItem[];
72
+ openFailed: number;
73
+ } | {
74
+ type: "pins";
75
+ id: number;
76
+ pins: OpenedItem[];
77
+ more: number;
78
+ openFailed: number;
79
+ } | {
80
+ type: "pending";
81
+ id: number;
82
+ rows: Array<{
83
+ itemId: number;
84
+ channelId: string;
85
+ scopeKind: ScopeKind;
86
+ scopeId: string;
87
+ originId: string;
88
+ chunkIndex: number;
89
+ text: string;
90
+ }>;
91
+ } | {
92
+ type: "stats";
93
+ hot: number;
94
+ hotBytes: number;
95
+ }
96
+ /** Final review bridge M-4: a request whose handler threw; the client answers it `failed` (a miss), the worker lives on. */
97
+ | {
98
+ type: "failed";
99
+ id: number;
100
+ } | {
101
+ type: "fatal";
102
+ };