@psiclawops/hypercompositor 0.9.1 → 0.9.3
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/dist/index.d.ts +208 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3474 -0
- package/package.json +4 -2
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* hypermem Context Engine Plugin
|
|
3
|
+
*
|
|
4
|
+
* Implements OpenClaw's ContextEngine interface backed by hypermem's
|
|
5
|
+
* four-layer memory architecture:
|
|
6
|
+
*
|
|
7
|
+
* L1 Cache — SQLite `:memory:` hot session working memory
|
|
8
|
+
* L2 Messages — per-agent conversation history (SQLite)
|
|
9
|
+
* L3 Vectors — semantic + keyword search (KNN + FTS5)
|
|
10
|
+
* L4 Library — facts, knowledge, episodes, preferences
|
|
11
|
+
*
|
|
12
|
+
* Lifecycle mapping:
|
|
13
|
+
* ingest() → record each message into messages.db
|
|
14
|
+
* assemble() → compositor builds context from all four layers
|
|
15
|
+
* compact() → delegate to runtime (ownsCompaction: false)
|
|
16
|
+
* afterTurn() → trigger background indexer (fire-and-forget)
|
|
17
|
+
* bootstrap() → warm hot-cache session, register agent in fleet
|
|
18
|
+
* dispose() → close hypermem connections
|
|
19
|
+
*
|
|
20
|
+
* Session key format expected: "agent:<agentId>:<channel>:<name>"
|
|
21
|
+
*/
|
|
22
|
+
import type { NeutralMessage, NeutralToolCall, NeutralToolResult, ComposeRequest, ComposeResult } from '@psiclawops/hypermem';
|
|
23
|
+
import { resolveTrimBudgets } from '@psiclawops/hypermem';
|
|
24
|
+
export type { NeutralMessage, NeutralToolCall, NeutralToolResult, ComposeRequest, ComposeResult };
|
|
25
|
+
type TrimTelemetryPath = 'assemble.normal' | 'assemble.toolLoop' | 'assemble.subagent' | 'reshape' | 'compact.nuclear' | 'compact.history' | 'compact.history2' | 'afterTurn.secondary' | 'warmstart';
|
|
26
|
+
type DegradationTelemetryPath = 'compose' | 'toolLoop';
|
|
27
|
+
interface DegradationTelemetryFields {
|
|
28
|
+
agentId: string;
|
|
29
|
+
sessionKey: string;
|
|
30
|
+
turnId: string;
|
|
31
|
+
path: DegradationTelemetryPath;
|
|
32
|
+
toolChainCoEjections?: number;
|
|
33
|
+
toolChainStubReplacements?: number;
|
|
34
|
+
artifactDegradations?: number;
|
|
35
|
+
artifactOversizeThresholdTokens?: number;
|
|
36
|
+
replayState?: 'entering' | 'stabilizing' | 'exited';
|
|
37
|
+
replayReason?: string;
|
|
38
|
+
}
|
|
39
|
+
declare function trimTelemetry(fields: {
|
|
40
|
+
path: TrimTelemetryPath;
|
|
41
|
+
agentId: string;
|
|
42
|
+
sessionKey: string;
|
|
43
|
+
preTokens: number;
|
|
44
|
+
postTokens: number;
|
|
45
|
+
removed: number;
|
|
46
|
+
cacheInvalidated: boolean;
|
|
47
|
+
reason: string;
|
|
48
|
+
}): void;
|
|
49
|
+
declare function assembleTrace(fields: {
|
|
50
|
+
agentId: string;
|
|
51
|
+
sessionKey: string;
|
|
52
|
+
turnId: string;
|
|
53
|
+
path: 'cold' | 'replay' | 'subagent';
|
|
54
|
+
toolLoop: boolean;
|
|
55
|
+
msgCount: number;
|
|
56
|
+
prefixChanged?: boolean;
|
|
57
|
+
prefixHash?: string;
|
|
58
|
+
rerankerStatus?: string;
|
|
59
|
+
rerankerCandidates?: number;
|
|
60
|
+
rerankerProvider?: string | null;
|
|
61
|
+
slotSpans?: Record<string, {
|
|
62
|
+
allocated: number;
|
|
63
|
+
filled: number;
|
|
64
|
+
overflow: boolean;
|
|
65
|
+
}>;
|
|
66
|
+
compactionEligibleCount?: number;
|
|
67
|
+
compactionEligibleRatio?: number;
|
|
68
|
+
compactionProcessedCount?: number;
|
|
69
|
+
composeTopicSource?: 'request-topic-id' | 'session-topic-map' | 'none';
|
|
70
|
+
composeTopicState?: 'no-active-topic' | 'active-topic-ready' | 'active-topic-missing-stamped-history' | 'history-disabled';
|
|
71
|
+
composeTopicMessageCount?: number;
|
|
72
|
+
composeTopicStampedMessageCount?: number;
|
|
73
|
+
composeTopicTelemetryStatus?: 'emitted' | 'intentionally-omitted';
|
|
74
|
+
}): void;
|
|
75
|
+
declare function degradationTelemetry(fields: DegradationTelemetryFields): void;
|
|
76
|
+
declare function lifecyclePolicyTelemetry(fields: {
|
|
77
|
+
path: 'compose.eviction' | 'compose.preRecall' | 'afterTurn.gradient';
|
|
78
|
+
agentId: string;
|
|
79
|
+
sessionKey: string;
|
|
80
|
+
band: string;
|
|
81
|
+
pressurePct?: number;
|
|
82
|
+
topicShiftConfidence?: number;
|
|
83
|
+
trimSoftTarget?: number;
|
|
84
|
+
reasons?: string[];
|
|
85
|
+
}): void;
|
|
86
|
+
declare function nextTurnId(): string;
|
|
87
|
+
declare const GUARD_TELEMETRY_REASONS: readonly ["warmstart-pressure-demoted", "reshape-downshift-demoted", "duplicate-claim-suppressed", "afterturn-secondary-demoted", "window-within-budget-skip", "pressure-accounting-anomaly"];
|
|
88
|
+
type GuardTelemetryReason = typeof GUARD_TELEMETRY_REASONS[number];
|
|
89
|
+
declare function beginTrimOwnerTurn(sessionKey: string, turnId: string): void;
|
|
90
|
+
declare function endTrimOwnerTurn(sessionKey: string, turnId: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Claim the steady-state trim owner slot for the current turn.
|
|
93
|
+
*
|
|
94
|
+
* Behavior:
|
|
95
|
+
* - compact.* paths are exception-only and pass through without claiming.
|
|
96
|
+
* - Non-steady paths (warmstart, reshape, afterTurn.secondary) also pass
|
|
97
|
+
* through without claiming. Demoted/no-op sites should normally emit
|
|
98
|
+
* via guardTelemetry() instead so they stay visible without contending
|
|
99
|
+
* for ownership (sub-tasks 2.2 and 2.3 wire this in).
|
|
100
|
+
* - Steady-state paths (assemble.normal, assemble.subagent,
|
|
101
|
+
* assemble.toolLoop) claim the single owner slot for the current turn.
|
|
102
|
+
* The first such claim succeeds. A second steady-state claim against the
|
|
103
|
+
* same turn is a duplicate-turn violation: it throws loudly under
|
|
104
|
+
* NODE_ENV='development' and warns in other environments (returning
|
|
105
|
+
* false so non-dev runtimes keep working).
|
|
106
|
+
*
|
|
107
|
+
* Callers should invoke this immediately before the real
|
|
108
|
+
* trimHistoryToTokenBudget() call. Guard telemetry does NOT route through
|
|
109
|
+
* this helper — it is explicitly excluded from the steady-state invariant.
|
|
110
|
+
*
|
|
111
|
+
* Returns true when the claim succeeds (or is exempt); false on a swallowed
|
|
112
|
+
* duplicate claim in non-development. In development the duplicate throws
|
|
113
|
+
* before returning.
|
|
114
|
+
*/
|
|
115
|
+
declare function claimTrimOwner(sessionKey: string, turnId: string, path: TrimTelemetryPath): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Non-counting guard / noop telemetry.
|
|
118
|
+
*
|
|
119
|
+
* Emits a `trim-guard` record on the same JSONL channel as trimTelemetry()
|
|
120
|
+
* but with a distinct event name so per-turn reporting (scripts/trim-report.mjs,
|
|
121
|
+
* future ownership dashboards) can keep it out of `trimCount`. Used by
|
|
122
|
+
* demoted/no-op call sites in 2.2 and 2.3 so their path labels stay visible
|
|
123
|
+
* in telemetry without consuming a steady-state owner slot.
|
|
124
|
+
*
|
|
125
|
+
* Zero-cost when telemetry is off. Never throws.
|
|
126
|
+
*/
|
|
127
|
+
declare function guardTelemetry(fields: {
|
|
128
|
+
path: TrimTelemetryPath;
|
|
129
|
+
agentId: string;
|
|
130
|
+
sessionKey: string;
|
|
131
|
+
reason: GuardTelemetryReason;
|
|
132
|
+
}): void;
|
|
133
|
+
export declare const __telemetryForTests: {
|
|
134
|
+
trimTelemetry: typeof trimTelemetry;
|
|
135
|
+
assembleTrace: typeof assembleTrace;
|
|
136
|
+
degradationTelemetry: typeof degradationTelemetry;
|
|
137
|
+
guardTelemetry: typeof guardTelemetry;
|
|
138
|
+
lifecyclePolicyTelemetry: typeof lifecyclePolicyTelemetry;
|
|
139
|
+
nextTurnId: typeof nextTurnId;
|
|
140
|
+
beginTrimOwnerTurn: typeof beginTrimOwnerTurn;
|
|
141
|
+
endTrimOwnerTurn: typeof endTrimOwnerTurn;
|
|
142
|
+
claimTrimOwner: typeof claimTrimOwner;
|
|
143
|
+
TRIM_SOFT_TARGET: number;
|
|
144
|
+
TRIM_GROWTH_THRESHOLD: number;
|
|
145
|
+
TRIM_HEADROOM_FRACTION: number;
|
|
146
|
+
resolveTrimBudgets: typeof resolveTrimBudgets;
|
|
147
|
+
reset(): void;
|
|
148
|
+
};
|
|
149
|
+
export declare const CONTEXT_WINDOW_OVERRIDE_KEY_REGEX: RegExp;
|
|
150
|
+
export type ContextWindowOverride = {
|
|
151
|
+
contextTokens?: number;
|
|
152
|
+
contextWindow?: number;
|
|
153
|
+
};
|
|
154
|
+
export declare function sanitizeContextWindowOverrides(raw: unknown): {
|
|
155
|
+
value: Record<string, ContextWindowOverride>;
|
|
156
|
+
warnings: string[];
|
|
157
|
+
};
|
|
158
|
+
export declare function resolveEffectiveBudget(args: {
|
|
159
|
+
tokenBudget?: number;
|
|
160
|
+
model?: string;
|
|
161
|
+
contextWindowSize: number;
|
|
162
|
+
contextWindowReserve: number;
|
|
163
|
+
contextWindowOverrides?: Record<string, ContextWindowOverride>;
|
|
164
|
+
}): {
|
|
165
|
+
budget: number;
|
|
166
|
+
source: string;
|
|
167
|
+
};
|
|
168
|
+
export interface ModelIdentity {
|
|
169
|
+
rawModel: string | null;
|
|
170
|
+
modelKey: string | null;
|
|
171
|
+
provider: string | null;
|
|
172
|
+
modelId: string | null;
|
|
173
|
+
}
|
|
174
|
+
export declare function resolveModelIdentity(model?: string): ModelIdentity;
|
|
175
|
+
export declare function diffModelState(previous: {
|
|
176
|
+
model?: string;
|
|
177
|
+
modelKey?: string | null;
|
|
178
|
+
provider?: string | null;
|
|
179
|
+
modelId?: string | null;
|
|
180
|
+
tokenBudget?: number;
|
|
181
|
+
} | null | undefined, current: {
|
|
182
|
+
model?: string;
|
|
183
|
+
tokenBudget?: number;
|
|
184
|
+
}): {
|
|
185
|
+
previousIdentity: ModelIdentity;
|
|
186
|
+
currentIdentity: ModelIdentity;
|
|
187
|
+
modelChanged: boolean;
|
|
188
|
+
providerChanged: boolean;
|
|
189
|
+
modelIdChanged: boolean;
|
|
190
|
+
budgetChanged: boolean;
|
|
191
|
+
budgetDownshift: boolean;
|
|
192
|
+
budgetUplift: boolean;
|
|
193
|
+
};
|
|
194
|
+
/**
|
|
195
|
+
* Bust the assembly cache for a specific agent+session.
|
|
196
|
+
* Call this after writing to identity files (SOUL.md, IDENTITY.md, TOOLS.md,
|
|
197
|
+
* USER.md) to ensure the next assemble() runs full compositor, not a replay.
|
|
198
|
+
*/
|
|
199
|
+
export declare function bustAssemblyCache(agentId: string, sessionKey: string): Promise<void>;
|
|
200
|
+
declare const _default: {
|
|
201
|
+
id: string;
|
|
202
|
+
name: string;
|
|
203
|
+
description: string;
|
|
204
|
+
configSchema: import("openclaw/plugin-sdk").OpenClawPluginConfigSchema;
|
|
205
|
+
register: NonNullable<import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginDefinition["register"]>;
|
|
206
|
+
} & Pick<import("openclaw/plugin-sdk/plugin-entry").OpenClawPluginDefinition, "kind" | "reload" | "nodeHostCommands" | "securityAuditCollectors">;
|
|
207
|
+
export default _default;
|
|
208
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAaH,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,cAAc,EACd,aAAa,EAId,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAUL,kBAAkB,EASnB,MAAM,sBAAsB,CAAC;AAW9B,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC;AAYlG,KAAK,iBAAiB,GAClB,iBAAiB,GACjB,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