@cortexkit/opencode-magic-context 0.16.3 → 0.17.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.
- package/README.md +1 -1
- package/dist/features/magic-context/message-index-async.d.ts +12 -0
- package/dist/features/magic-context/message-index-async.d.ts.map +1 -0
- package/dist/features/magic-context/message-index.d.ts +4 -0
- package/dist/features/magic-context/message-index.d.ts.map +1 -1
- package/dist/features/magic-context/migrations.d.ts +7 -0
- package/dist/features/magic-context/migrations.d.ts.map +1 -1
- package/dist/features/magic-context/search.d.ts +2 -2
- package/dist/features/magic-context/search.d.ts.map +1 -1
- package/dist/features/magic-context/storage-db.d.ts.map +1 -1
- package/dist/features/magic-context/storage-meta-persisted.d.ts +3 -6
- package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
- package/dist/features/magic-context/storage-tags.d.ts +163 -1
- package/dist/features/magic-context/storage-tags.d.ts.map +1 -1
- package/dist/features/magic-context/storage.d.ts +1 -1
- package/dist/features/magic-context/storage.d.ts.map +1 -1
- package/dist/features/magic-context/tagger.d.ts +52 -2
- package/dist/features/magic-context/tagger.d.ts.map +1 -1
- package/dist/features/magic-context/tool-definition-tokens.d.ts +26 -3
- package/dist/features/magic-context/tool-definition-tokens.d.ts.map +1 -1
- package/dist/features/magic-context/tool-owner-backfill.d.ts +90 -0
- package/dist/features/magic-context/tool-owner-backfill.d.ts.map +1 -0
- package/dist/features/magic-context/types.d.ts +17 -0
- package/dist/features/magic-context/types.d.ts.map +1 -1
- package/dist/hooks/auto-update-checker/index.d.ts +29 -1
- package/dist/hooks/auto-update-checker/index.d.ts.map +1 -1
- package/dist/hooks/auto-update-checker/types.d.ts +19 -0
- package/dist/hooks/auto-update-checker/types.d.ts.map +1 -1
- package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -1
- package/dist/hooks/magic-context/compartment-runner-drop-queue.d.ts +23 -0
- package/dist/hooks/magic-context/compartment-runner-drop-queue.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
- package/dist/hooks/magic-context/event-payloads.d.ts +8 -0
- package/dist/hooks/magic-context/event-payloads.d.ts.map +1 -1
- package/dist/hooks/magic-context/heuristic-cleanup.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
- package/dist/hooks/magic-context/hook.d.ts.map +1 -1
- package/dist/hooks/magic-context/inject-compartments.d.ts +16 -0
- package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
- package/dist/hooks/magic-context/nudger.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts +24 -1
- package/dist/hooks/magic-context/read-session-chunk.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-db.d.ts +1 -0
- package/dist/hooks/magic-context/read-session-db.d.ts.map +1 -1
- package/dist/hooks/magic-context/read-session-raw.d.ts +1 -0
- package/dist/hooks/magic-context/read-session-raw.d.ts.map +1 -1
- package/dist/hooks/magic-context/sentinel.d.ts +60 -11
- package/dist/hooks/magic-context/sentinel.d.ts.map +1 -1
- package/dist/hooks/magic-context/strip-content.d.ts +12 -9
- package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts +1 -1
- package/dist/hooks/magic-context/tag-messages.d.ts.map +1 -1
- package/dist/hooks/magic-context/tool-drop-target.d.ts +16 -1
- package/dist/hooks/magic-context/tool-drop-target.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +7 -11
- package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
- package/dist/hooks/magic-context/transform.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3215 -1413
- package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
- package/dist/plugin/rpc-handlers.d.ts +3 -0
- package/dist/plugin/rpc-handlers.d.ts.map +1 -1
- package/dist/shared/models-dev-cache.d.ts +3 -10
- package/dist/shared/models-dev-cache.d.ts.map +1 -1
- package/dist/shared/tag-transcript.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/shared/models-dev-cache.test.ts +64 -57
- package/src/shared/models-dev-cache.ts +49 -68
- package/src/shared/tag-transcript.ts +137 -126
- package/src/tui/types/opencode-plugin-tui.d.ts +1 -1
- package/dist/hooks/magic-context/reasoning-capability.d.ts +0 -23
- package/dist/hooks/magic-context/reasoning-capability.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -386,7 +386,7 @@ On startup, Magic Context checks for common configuration problems — OpenCode'
|
|
|
386
386
|
A companion desktop app for browsing and managing Magic Context state outside of OpenCode.
|
|
387
387
|
|
|
388
388
|
<p align="center">
|
|
389
|
-
<a href="https://github.com/cortexkit/magic-context/releases/tag/dashboard-v0.4.
|
|
389
|
+
<a href="https://github.com/cortexkit/magic-context/releases/tag/dashboard-v0.4.2"><strong>⬇️ Download for macOS · Windows · Linux</strong></a></p>
|
|
390
390
|
|
|
391
391
|
**Features:**
|
|
392
392
|
- **Memory Browser** — search, filter, and edit project memories with category and project filtering
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RawMessage } from "../../hooks/magic-context/read-session-raw";
|
|
2
|
+
import type { Database } from "../../shared/sqlite";
|
|
3
|
+
type ReadMessages = (sessionId: string) => RawMessage[];
|
|
4
|
+
type ReadSingleMessage = (sessionId: string, messageId: string) => RawMessage | null;
|
|
5
|
+
export declare function scheduleReconciliation(db: Database, sessionId: string, readMessages: ReadMessages): void;
|
|
6
|
+
export declare function scheduleIncrementalIndex(db: Database, sessionId: string, messageId: string, readSingleMessage: ReadSingleMessage): void;
|
|
7
|
+
export declare function scheduleClearAndReindex(db: Database, sessionId: string, readMessages: ReadMessages): void;
|
|
8
|
+
export declare function isSessionReconciled(sessionId: string): boolean;
|
|
9
|
+
export declare function clearSessionTracking(sessionId: string): void;
|
|
10
|
+
export declare function __resetMessageIndexAsyncForTests(): void;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=message-index-async.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-index-async.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/message-index-async.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAsEpD,KAAK,YAAY,GAAG,CAAC,SAAS,EAAE,MAAM,KAAK,UAAU,EAAE,CAAC;AACxD,KAAK,iBAAiB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,UAAU,GAAG,IAAI,CAAC;AA8ErF,wBAAgB,sBAAsB,CAClC,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,YAAY,GAC3B,IAAI,CAYN;AAED,wBAAgB,wBAAwB,CACpC,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,iBAAiB,EAAE,iBAAiB,GACrC,IAAI,CAyBN;AAED,wBAAgB,uBAAuB,CACnC,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,YAAY,GAC3B,IAAI,CAcN;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE9D;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAkB5D;AAED,wBAAgB,gCAAgC,IAAI,IAAI,CASvD"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { RawMessage } from "../../hooks/magic-context/read-session-raw";
|
|
2
2
|
import type { Database } from "../../shared/sqlite";
|
|
3
|
+
export declare function getLastIndexedOrdinal(db: Database, sessionId: string): number;
|
|
3
4
|
export declare function deleteIndexedMessage(db: Database, sessionId: string, messageId: string): number;
|
|
4
5
|
export declare function clearIndexedMessages(db: Database, sessionId: string): void;
|
|
6
|
+
export declare function getIndexableContent(role: string, parts: unknown[]): string;
|
|
7
|
+
export declare function indexSingleMessage(db: Database, sessionId: string, message: RawMessage): boolean;
|
|
8
|
+
export declare function indexMessagesAfterOrdinal(db: Database, sessionId: string, messages: RawMessage[], lastIndexedOrdinal: number, finalWatermark?: number): number;
|
|
5
9
|
export declare function ensureMessagesIndexed(db: Database, sessionId: string, readMessages: (sessionId: string) => RawMessage[]): void;
|
|
6
10
|
//# sourceMappingURL=message-index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-index.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/message-index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"message-index.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/message-index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAE7E,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,qBAAqB,CAAC;AAqFpF,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAG7E;AAiBD,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAU/F;AAED,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAM1E;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,MAAM,CAsB1E;AAmCD,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,GAAG,OAAO,CAIhG;AAED,wBAAgB,yBAAyB,CACrC,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,UAAU,EAAE,EACtB,kBAAkB,EAAE,MAAM,EAC1B,cAAc,GAAE,MAAwB,GACzC,MAAM,CAiDR;AAED,wBAAgB,qBAAqB,CACjC,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,UAAU,EAAE,GAClD,IAAI,CAmBN"}
|
|
@@ -3,6 +3,13 @@ import type { Database } from "../../shared/sqlite";
|
|
|
3
3
|
* Run all pending migrations sequentially.
|
|
4
4
|
* Each migration runs in its own transaction — if it fails, only that migration rolls back.
|
|
5
5
|
* Already-applied migrations are skipped.
|
|
6
|
+
*
|
|
7
|
+
* Multi-instance race tolerance: when two plugin processes start against
|
|
8
|
+
* the same shared DB, both can read the same MAX(version) before either
|
|
9
|
+
* commits. The first wins; the second's INSERT into schema_migrations
|
|
10
|
+
* fails with a PRIMARY KEY conflict. We catch that specific case and
|
|
11
|
+
* resume from the next pending migration. All other migration errors
|
|
12
|
+
* still fail-close per the existing contract.
|
|
6
13
|
*/
|
|
7
14
|
export declare function runMigrations(db: Database): void;
|
|
8
15
|
//# sourceMappingURL=migrations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/migrations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/migrations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAwdpD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAgEhD"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { RawMessage } from "../../hooks/magic-context/read-session-raw";
|
|
2
1
|
import type { Database } from "../../shared/sqlite";
|
|
3
2
|
export type SearchSource = "memory" | "message" | "git_commit";
|
|
4
3
|
export interface UnifiedSearchOptions {
|
|
5
4
|
limit?: number;
|
|
6
5
|
memoryEnabled?: boolean;
|
|
7
6
|
embeddingEnabled?: boolean;
|
|
8
|
-
|
|
7
|
+
/** Deprecated: message search no longer reads raw messages on the hot path. */
|
|
8
|
+
readMessages?: (sessionId: string) => unknown[];
|
|
9
9
|
embedQuery?: (text: string, signal?: AbortSignal) => Promise<Float32Array | null>;
|
|
10
10
|
isEmbeddingRuntimeEnabled?: () => boolean;
|
|
11
11
|
/** Only return message-history hits with ordinal ≤ this value (e.g. last compartment end). -1 or omit to search all. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/search.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,qBAAqB,CAAC;AA0CpF,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,SAAS,GAAG,YAAY,CAAC;AAE/D,MAAM,WAAW,oBAAoB;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,+EAA+E;IAC/E,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,EAAE,CAAC;IAChD,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;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,GAAG,qBAAqB,CAAC;AAyZnG,wBAAsB,aAAa,CAC/B,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,oBAAyB,GACnC,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAyHhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-db.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-db.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"storage-db.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-db.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAwE/C,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CA6WrD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAIrD;AAyGD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,IAAI,QAAQ,CAuDvC;AAED,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAEzD;AAED,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI,CAEvE;AAED,wBAAgB,aAAa,IAAI,IAAI,CAUpC;AAED,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC"}
|
|
@@ -22,12 +22,9 @@ export declare function loadPersistedUsage(db: Database, sessionId: string): {
|
|
|
22
22
|
export declare function getPersistedReasoningWatermark(db: Database, sessionId: string): number;
|
|
23
23
|
export declare function setPersistedReasoningWatermark(db: Database, sessionId: string, tagNumber: number): void;
|
|
24
24
|
/**
|
|
25
|
-
* Reset the persisted reasoning watermark for a session.
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* rewrite/remove typed reasoning parts while providers that expose
|
|
29
|
-
* `capabilities.interleaved.field` need those same parts to survive until
|
|
30
|
-
* OpenCode's provider transform serializes them onto the wire.
|
|
25
|
+
* Reset the persisted reasoning watermark for a session. Used during model
|
|
26
|
+
* switches to make sure stale reasoning state from the previous model does
|
|
27
|
+
* not leak into pressure or replay decisions for the new one.
|
|
31
28
|
*/
|
|
32
29
|
export declare function clearPersistedReasoningWatermark(db: Database, sessionId: string): void;
|
|
33
30
|
export declare function getPersistedNudgePlacement(db: Database, sessionId: string): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-meta-persisted.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-meta-persisted.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAmC5C,MAAM,WAAW,2BAA2B;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IAC/B,cAAc,EAAE,OAAO,CAAC;IACxB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,8BAA8B;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAuED,wBAAgB,kBAAkB,CAC9B,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,GAClB;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAqBnD;AAED,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAMtF;AAED,wBAAgB,8BAA8B,CAC1C,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAClB,IAAI,CAKN;AAED
|
|
1
|
+
{"version":3,"file":"storage-meta-persisted.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-meta-persisted.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAmC5C,MAAM,WAAW,2BAA2B;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IAC/B,cAAc,EAAE,OAAO,CAAC;IACxB,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,8BAA8B;IAC3C,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAuED,wBAAgB,kBAAkB,CAC9B,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,GAClB;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAqBnD;AAED,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAMtF;AAED,wBAAgB,8BAA8B,CAC1C,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,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AE,MAAM,GAAG,IAAI,CAO5E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAO/E;AAID,MAAM,WAAW,8BAA8B;IAC3C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,eAAe,EAAE,MAAM,CAAC;CAC3B;AAED,wBAAgB,iCAAiC,CAC7C,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,GAClB,8BAA8B,GAAG,IAAI,CAuBvC;AAED,wBAAgB,iCAAiC,CAC7C,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,8BAA8B,GAAG,IAAI,GAC7C,IAAI,CAON;AAID,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CActF;AAED,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAOjG;AAED,wBAAgB,2BAA2B,CACvC,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAClB,OAAO,CAQT"}
|
|
@@ -16,7 +16,7 @@ export declare function updateTagByteSize(db: Database, sessionId: string, tagNu
|
|
|
16
16
|
* orderings).
|
|
17
17
|
*/
|
|
18
18
|
export declare function updateTagInputByteSize(db: Database, sessionId: string, tagNumber: number, newInputByteSize: number): void;
|
|
19
|
-
export declare function insertTag(db: Database, sessionId: string, messageId: string, type: TagEntry["type"], byteSize: number, tagNumber: number, reasoningByteSize?: number, toolName?: string | null, inputByteSize?: number): number;
|
|
19
|
+
export declare function insertTag(db: Database, sessionId: string, messageId: string, type: TagEntry["type"], byteSize: number, tagNumber: number, reasoningByteSize?: number, toolName?: string | null, inputByteSize?: number, toolOwnerMessageId?: string | null): number;
|
|
20
20
|
export declare function updateTagStatus(db: Database, sessionId: string, tagId: number, status: TagEntry["status"]): void;
|
|
21
21
|
export declare function updateTagDropMode(db: Database, sessionId: string, tagNumber: number, dropMode: TagEntry["dropMode"]): void;
|
|
22
22
|
/**
|
|
@@ -28,6 +28,26 @@ export declare function updateTagDropMode(db: Database, sessionId: string, tagNu
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function updateCavemanDepth(db: Database, sessionId: string, tagNumber: number, depth: number): void;
|
|
30
30
|
export declare function updateTagMessageId(db: Database, sessionId: string, tagId: number, messageId: string): void;
|
|
31
|
+
/**
|
|
32
|
+
* Delete every tag whose source content lives on `messageId`. This is
|
|
33
|
+
* the `message.removed` event handler's primary cleanup path.
|
|
34
|
+
*
|
|
35
|
+
* What gets deleted:
|
|
36
|
+
* - Message tags: `messageId == <removed-msg-id>` (text parts).
|
|
37
|
+
* - File tags: `messageId LIKE <removed-msg-id>:p%` /
|
|
38
|
+
* `<removed-msg-id>:file%`.
|
|
39
|
+
* - Tool tags owned by the removed message:
|
|
40
|
+
* `tool_owner_message_id == <removed-msg-id>` (v3.3.1 Layer C).
|
|
41
|
+
*
|
|
42
|
+
* Pre-v10 semantics: tool tags used `messageId = callId`, so a removed
|
|
43
|
+
* assistant message would not match any tool tag's `messageId` field
|
|
44
|
+
* (the message id was never written there for tool tags). The fix:
|
|
45
|
+
* include tool tags by composite-owner identity so an assistant
|
|
46
|
+
* message removal correctly cascades to the tool tags it hosted.
|
|
47
|
+
*
|
|
48
|
+
* Returns the tag numbers that were deleted (used by the event handler
|
|
49
|
+
* to re-anchor reasoning watermarks and audit logs).
|
|
50
|
+
*/
|
|
31
51
|
export declare function deleteTagsByMessageId(db: Database, sessionId: string, messageId: string): number[];
|
|
32
52
|
export declare function getMaxTagNumberBySession(db: Database, sessionId: string): number;
|
|
33
53
|
/**
|
|
@@ -39,6 +59,148 @@ export declare function getMaxTagNumberBySession(db: Database, sessionId: string
|
|
|
39
59
|
*/
|
|
40
60
|
export declare function getTagNumberByMessageId(db: Database, sessionId: string, messageId: string): number | null;
|
|
41
61
|
export declare function getTagsBySession(db: Database, sessionId: string): TagEntry[];
|
|
62
|
+
/**
|
|
63
|
+
* Return only the tags whose status is 'active' for this session.
|
|
64
|
+
*
|
|
65
|
+
* Backed by the partial index `idx_tags_active_session_tag_number` so the
|
|
66
|
+
* scan touches only active rows instead of every tag in the session.
|
|
67
|
+
*
|
|
68
|
+
* Use this in: heuristic cleanup, nudger, caveman replay scope, anywhere
|
|
69
|
+
* that filters `tags.filter(t => t.status === "active")` on the result of
|
|
70
|
+
* `getTagsBySession`.
|
|
71
|
+
*
|
|
72
|
+
* The returned shape matches `TagEntry` exactly so callers can swap with
|
|
73
|
+
* no behavior change beyond seeing fewer (active-only) rows.
|
|
74
|
+
*/
|
|
75
|
+
export declare function getActiveTagsBySession(db: Database, sessionId: string): TagEntry[];
|
|
76
|
+
/**
|
|
77
|
+
* Return the tags whose tag_number is in `tagNumbers` for this session.
|
|
78
|
+
*
|
|
79
|
+
* Used by `applyFlushedStatuses` (and similar replay loops) to fetch the
|
|
80
|
+
* subset of tags that match the current pass's visible target set rather
|
|
81
|
+
* than scanning every tag in the session.
|
|
82
|
+
*
|
|
83
|
+
* The IN-list is built dynamically because SQLite caches prepared
|
|
84
|
+
* statements per query string, but we still get prepared-statement reuse
|
|
85
|
+
* for any given list size that happens twice in a row (which is the
|
|
86
|
+
* common case during long sessions).
|
|
87
|
+
*
|
|
88
|
+
* Returns an empty array when `tagNumbers` is empty (avoids generating
|
|
89
|
+
* `IN ()` which is an SQL syntax error).
|
|
90
|
+
*/
|
|
91
|
+
export declare function getTagsByNumbers(db: Database, sessionId: string, tagNumbers: readonly number[]): TagEntry[];
|
|
92
|
+
/**
|
|
93
|
+
* Return the maximum tag_number among tags whose status is 'dropped' for
|
|
94
|
+
* this session, or 0 if no dropped tags exist.
|
|
95
|
+
*
|
|
96
|
+
* Replaces the full-array iteration `for (tag of tags) if (dropped &&
|
|
97
|
+
* tag_number > max) max = tag_number` with a single SQL aggregate.
|
|
98
|
+
* Backed by the partial index `idx_tags_dropped_session_tag_number` so
|
|
99
|
+
* SQLite resolves the MAX with a backward index seek (O(log N)).
|
|
100
|
+
*/
|
|
101
|
+
export declare function getMaxDroppedTagNumber(db: Database, sessionId: string): number;
|
|
42
102
|
export declare function getTagById(db: Database, sessionId: string, tagId: number): TagEntry | null;
|
|
43
103
|
export declare function getTopNBySize(db: Database, sessionId: string, n: number): TagEntry[];
|
|
104
|
+
/**
|
|
105
|
+
* Look up the tag_number for a specific composite tool identity.
|
|
106
|
+
*
|
|
107
|
+
* Returns null when no tag exists for `(sessionId, callId, ownerMsgId)`.
|
|
108
|
+
* This is the fast path for the runtime tagger after a tagger restart
|
|
109
|
+
* or cache eviction.
|
|
110
|
+
*/
|
|
111
|
+
export declare function getToolTagNumberByOwner(db: Database, sessionId: string, callId: string, ownerMsgId: string): number | null;
|
|
112
|
+
/**
|
|
113
|
+
* Find a NULL-owner tool tag row for `(sessionId, callId)`.
|
|
114
|
+
*
|
|
115
|
+
* Used by the lazy-adoption fast path: when the runtime tagger sees a
|
|
116
|
+
* tool with composite key `(ownerMsgId, callId)` that has no
|
|
117
|
+
* corresponding row in `assignments`, but the underlying callId already
|
|
118
|
+
* exists in DB with NULL owner (legacy pre-v10 row), we want to adopt
|
|
119
|
+
* the orphan rather than allocate a fresh tag. This preserves
|
|
120
|
+
* cache-stable tag numbers across the v9 → v10 upgrade.
|
|
121
|
+
*
|
|
122
|
+
* Returns the lowest-numbered NULL-owner row deterministically. The
|
|
123
|
+
* caller is expected to follow up with `adoptNullOwnerToolTag` to
|
|
124
|
+
* atomically claim ownership; if that returns false, another writer
|
|
125
|
+
* adopted first and the caller must re-check the composite-key fast
|
|
126
|
+
* path or allocate a fresh tag.
|
|
127
|
+
*/
|
|
128
|
+
export declare function getNullOwnerToolTag(db: Database, sessionId: string, callId: string): {
|
|
129
|
+
id: number;
|
|
130
|
+
tagNumber: number;
|
|
131
|
+
} | null;
|
|
132
|
+
/**
|
|
133
|
+
* Atomically adopt a NULL-owner tool tag row by setting
|
|
134
|
+
* `tool_owner_message_id = ownerMsgId`. Returns true if exactly one
|
|
135
|
+
* row was updated (we won the race), false if zero (someone else
|
|
136
|
+
* adopted between our SELECT and UPDATE).
|
|
137
|
+
*
|
|
138
|
+
* The NULL guard makes this concurrent-safe with both the backfill
|
|
139
|
+
* pass and concurrent runtime adoptions in other plugin processes.
|
|
140
|
+
*/
|
|
141
|
+
export declare function adoptNullOwnerToolTag(db: Database, rowId: number, ownerMsgId: string): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Returns the candidate tool-tag owner ids for `(sessionId, callId)` —
|
|
144
|
+
* every tag with a non-NULL owner. Used by the result-only-window
|
|
145
|
+
* fallback in `tag-messages.ts`: the caller resolves wall-clock times
|
|
146
|
+
* for every candidate against the OpenCode DB (via
|
|
147
|
+
* `getMessageTimesFromOpenCodeDb`) and picks the most recent one whose
|
|
148
|
+
* `time_created` precedes the current result message.
|
|
149
|
+
*
|
|
150
|
+
* The picking logic lives in the caller because resolving message times
|
|
151
|
+
* requires the OpenCode read-only DB handle, which lives in the hooks
|
|
152
|
+
* tree. Keeping that import one-way (hooks → features) avoids what
|
|
153
|
+
* would otherwise be a cycle through the storage barrel.
|
|
154
|
+
*
|
|
155
|
+
* Returns an empty array when no candidates exist; the caller falls back
|
|
156
|
+
* to `messageId` (the result's own id) in that case so the runtime
|
|
157
|
+
* still allocates a stable composite key.
|
|
158
|
+
*/
|
|
159
|
+
export declare function getCandidateToolOwners(db: Database, sessionId: string, callId: string): string[];
|
|
160
|
+
/**
|
|
161
|
+
* Pick the most recent (by OpenCode `time_created`) candidate owner
|
|
162
|
+
* whose message strictly precedes `currentMessageId`. Tie-break on
|
|
163
|
+
* lexicographic id, matching the legacy single-statement ordering
|
|
164
|
+
* (`ORDER BY time_created DESC, id DESC` limited to rows where
|
|
165
|
+
* `time_created < currentTime`).
|
|
166
|
+
*
|
|
167
|
+
* Returns null when:
|
|
168
|
+
* - The candidate list is empty
|
|
169
|
+
* - `currentMessageId` is not present in `times`
|
|
170
|
+
* - No candidate predates `currentMessageId` in OC time
|
|
171
|
+
*
|
|
172
|
+
* This helper is independent of any DB handle — the caller resolves the
|
|
173
|
+
* `times` map (typically via `getMessageTimesFromOpenCodeDb`) and passes
|
|
174
|
+
* it in. Splitting the lookup from the picking keeps `storage-tags.ts`
|
|
175
|
+
* free of any OpenCode-DB import.
|
|
176
|
+
*/
|
|
177
|
+
export declare function pickNearestPriorOwner(candidates: readonly string[], currentMessageId: string, times: ReadonlyMap<string, number>): string | null;
|
|
178
|
+
/**
|
|
179
|
+
* Legacy alias kept for the rare runtime call site that hasn't been
|
|
180
|
+
* migrated to the split lookup-then-pick form. Always returns null
|
|
181
|
+
* (no message-time data available without a DB handle the function
|
|
182
|
+
* itself can't reach). New call sites should use `getCandidateToolOwners`
|
|
183
|
+
* + `getMessageTimesFromOpenCodeDb` + `pickNearestPriorOwner` directly.
|
|
184
|
+
*
|
|
185
|
+
* Why we keep this name: the v3.3.1 plan documents this as the public
|
|
186
|
+
* entry point for the result-only-window fallback. Removing it would
|
|
187
|
+
* require touching `.alfonso/plans/tag-owner-fix-plan.md` and migrating
|
|
188
|
+
* the test fixtures that exercise it. Leaving the symbol present with
|
|
189
|
+
* a noop body keeps existing test scaffolds working while the actual
|
|
190
|
+
* pick happens in the hooks-tree caller.
|
|
191
|
+
*/
|
|
192
|
+
export declare function getPersistedToolOwnerNearestPrior(_db: Database, _sessionId: string, _callId: string, _currentMessageId: string): string | null;
|
|
193
|
+
/**
|
|
194
|
+
* Delete every tool tag owned by `ownerMsgId` in the session. Used by
|
|
195
|
+
* `message.removed` cleanup to scope the deletion correctly: pre-v10
|
|
196
|
+
* a removed assistant message would `deleteTagsByMessageId(messageId)`
|
|
197
|
+
* which only matched `message_id = messageId` (the contentId for text
|
|
198
|
+
* parts), missing tool tags whose `message_id` is the callID. Post-v10
|
|
199
|
+
* the owner column gives us the right scope.
|
|
200
|
+
*
|
|
201
|
+
* Returns the number of rows deleted. NULL-owner legacy rows are not
|
|
202
|
+
* matched by this helper — they remain reachable via `message_id`-only
|
|
203
|
+
* deletion paths until adopted or backfilled.
|
|
204
|
+
*/
|
|
205
|
+
export declare function deleteToolTagsByOwner(db: Database, sessionId: string, ownerMsgId: string): number;
|
|
44
206
|
//# sourceMappingURL=storage-tags.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-tags.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-tags.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,qBAAqB,CAAC;AACpF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AA+DxC;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC7B,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GACpB,IAAI,CAEN;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAClC,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,gBAAgB,EAAE,MAAM,GACzB,IAAI,CAEN;
|
|
1
|
+
{"version":3,"file":"storage-tags.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-tags.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,qBAAqB,CAAC;AACpF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AA+DxC;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC7B,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,SA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;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAC/B,EAAE,EAAE,QAAQ,EACZ,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,GACf;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAI1C;AAmBD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAG9F;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAYhG;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACjC,UAAU,EAAE,SAAS,MAAM,EAAE,EAC7B,gBAAgB,EAAE,MAAM,EACxB,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GACnC,MAAM,GAAG,IAAI,CAef;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iCAAiC,CAC7C,GAAG,EAAE,QAAQ,EACb,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,iBAAiB,EAAE,MAAM,GAC1B,MAAM,GAAG,IAAI,CAEf;AAgBD;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAGjG"}
|
|
@@ -6,5 +6,5 @@ export { clearDetectedContextLimit, clearEmergencyRecovery, clearHistorianFailur
|
|
|
6
6
|
export { addNote, deleteNote, dismissNote, getNotes, getPendingSmartNotes, getReadySmartNotes, getSessionNotes, getSmartNotes, markNoteChecked, markNoteReady, type Note, type NoteStatus, type NoteType, replaceAllSessionNotes, updateNote, } from "./storage-notes";
|
|
7
7
|
export { clearPendingOps, getPendingOps, queuePendingOp, removePendingOp, } from "./storage-ops";
|
|
8
8
|
export { getSourceContents, replaceSourceContent, saveSourceContent, } from "./storage-source";
|
|
9
|
-
export { deleteTagsByMessageId, getMaxTagNumberBySession, getTagById, getTagsBySession, getTopNBySize, insertTag, updateCavemanDepth, updateTagDropMode, updateTagMessageId, updateTagStatus, } from "./storage-tags";
|
|
9
|
+
export { deleteTagsByMessageId, getActiveTagsBySession, getMaxDroppedTagNumber, getMaxTagNumberBySession, getTagById, getTagsByNumbers, getTagsBySession, getTopNBySize, insertTag, updateCavemanDepth, updateTagDropMode, updateTagMessageId, updateTagStatus, } from "./storage-tags";
|
|
10
10
|
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,qBAAqB,EACrB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,KAAK,WAAW,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACH,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,yBAAyB,GAC5B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACH,oBAAoB,EACpB,oBAAoB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACH,KAAK,eAAe,EACpB,aAAa,EACb,2BAA2B,EAC3B,mBAAmB,EACnB,YAAY,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,4BAA4B,EAC5B,gCAAgC,EAChC,gCAAgC,EAChC,YAAY,EACZ,wBAAwB,EACxB,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,qBAAqB,EACrB,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EAClB,KAAK,sBAAsB,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,EACjB,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,EACzB,iBAAiB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACH,OAAO,EACP,UAAU,EACV,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,eAAe,EACf,aAAa,EACb,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,sBAAsB,EACtB,UAAU,GACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACd,eAAe,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EACH,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACH,qBAAqB,EACrB,wBAAwB,EACxB,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAClB,MAAM,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,qBAAqB,EACrB,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,0BAA0B,EAC1B,KAAK,WAAW,GACnB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACH,qBAAqB,EACrB,0BAA0B,EAC1B,sBAAsB,EACtB,yBAAyB,GAC5B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACH,oBAAoB,EACpB,oBAAoB,GACvB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACH,KAAK,eAAe,EACpB,aAAa,EACb,2BAA2B,EAC3B,mBAAmB,EACnB,YAAY,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EACH,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,4BAA4B,EAC5B,gCAAgC,EAChC,gCAAgC,EAChC,YAAY,EACZ,wBAAwB,EACxB,iBAAiB,EACjB,sBAAsB,EACtB,gBAAgB,EAChB,qBAAqB,EACrB,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EAClB,KAAK,sBAAsB,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,EACjB,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,EACzB,iBAAiB,GACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACH,OAAO,EACP,UAAU,EACV,WAAW,EACX,QAAQ,EACR,oBAAoB,EACpB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,eAAe,EACf,aAAa,EACb,KAAK,IAAI,EACT,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,sBAAsB,EACtB,UAAU,GACb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACH,eAAe,EACf,aAAa,EACb,cAAc,EACd,eAAe,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EACH,iBAAiB,EACjB,oBAAoB,EACpB,iBAAiB,GACpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACH,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACxB,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAClB,MAAM,gBAAgB,CAAC"}
|
|
@@ -1,9 +1,58 @@
|
|
|
1
1
|
import type { Database } from "../../shared/sqlite";
|
|
2
2
|
import type { TagEntry } from "./types";
|
|
3
|
+
export declare function makeToolCompositeKey(ownerMsgId: string, callId: string): string;
|
|
4
|
+
/**
|
|
5
|
+
* Narrowed type for non-tool tag operations. The compile-time exclusion
|
|
6
|
+
* of `"tool"` here is the v3.3.1 Layer C contract: every tool path MUST
|
|
7
|
+
* use `assignToolTag`/`getToolTag` so composite identity propagates.
|
|
8
|
+
*
|
|
9
|
+
* Any caller passing `"tool"` to `assignTag` or `getTag` triggers a TS
|
|
10
|
+
* compile error at the call site. Defense-in-depth: the runtime body
|
|
11
|
+
* also throws if it ever sees a "tool" type at runtime (caught by
|
|
12
|
+
* `as any` casts in legacy code).
|
|
13
|
+
*/
|
|
14
|
+
type NonToolTagType = Exclude<TagEntry["type"], "tool">;
|
|
3
15
|
export interface Tagger {
|
|
4
|
-
|
|
5
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Assign a tag for a non-tool entity (message text or file part).
|
|
18
|
+
*
|
|
19
|
+
* Tool tags MUST use {@link assignToolTag}; the `type` parameter
|
|
20
|
+
* here is narrowed at compile time to forbid `"tool"`.
|
|
21
|
+
*/
|
|
22
|
+
assignTag(sessionId: string, messageId: string, type: NonToolTagType, byteSize: number, db: Database, reasoningByteSize?: number, toolName?: string | null, inputByteSize?: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Look up the tag number for a non-tool entity.
|
|
25
|
+
*
|
|
26
|
+
* The `type` parameter is required (and narrowed to non-tool) so a
|
|
27
|
+
* future tool-tag lookup can't accidentally fall through here. Use
|
|
28
|
+
* {@link getToolTag} for tool lookups.
|
|
29
|
+
*/
|
|
30
|
+
getTag(sessionId: string, messageId: string, type: NonToolTagType): number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Assign a tag for a tool invocation. Composite identity
|
|
33
|
+
* `(sessionId, callId, ownerMsgId)` is mandatory — pre-v3.3.1 the
|
|
34
|
+
* tagger keyed tool tags by bare callId, and two assistant turns
|
|
35
|
+
* reusing the same callId would silently bind to the same tag,
|
|
36
|
+
* inheriting the older tag's drop status.
|
|
37
|
+
*
|
|
38
|
+
* `ownerMsgId` is the assistant message id that hosts the tool
|
|
39
|
+
* invocation. For Pi parallel-tool-calls without `part.id`, callers
|
|
40
|
+
* pass a synthetic locator equal to the contentId (owner == callId)
|
|
41
|
+
* to satisfy the contract while preserving the legacy "each part
|
|
42
|
+
* gets its own tag" behavior.
|
|
43
|
+
*/
|
|
44
|
+
assignToolTag(sessionId: string, callId: string, ownerMsgId: string, byteSize: number, db: Database, reasoningByteSize?: number, toolName?: string | null, inputByteSize?: number): number;
|
|
45
|
+
/**
|
|
46
|
+
* Look up the tag number for a tool invocation by composite
|
|
47
|
+
* identity.
|
|
48
|
+
*/
|
|
49
|
+
getToolTag(sessionId: string, callId: string, ownerMsgId: string): number | undefined;
|
|
6
50
|
bindTag(sessionId: string, messageId: string, tagNumber: number): void;
|
|
51
|
+
/**
|
|
52
|
+
* Bind a tool tag by composite key. The in-memory map keys this as
|
|
53
|
+
* `${ownerMsgId}\x00${callId}`.
|
|
54
|
+
*/
|
|
55
|
+
bindToolTag(sessionId: string, callId: string, ownerMsgId: string, tagNumber: number): void;
|
|
7
56
|
getAssignments(sessionId: string): ReadonlyMap<string, number>;
|
|
8
57
|
resetCounter(sessionId: string, db: Database): void;
|
|
9
58
|
getCounter(sessionId: string): number;
|
|
@@ -11,4 +60,5 @@ export interface Tagger {
|
|
|
11
60
|
cleanup(sessionId: string): void;
|
|
12
61
|
}
|
|
13
62
|
export declare function createTagger(): Tagger;
|
|
63
|
+
export {};
|
|
14
64
|
//# sourceMappingURL=tagger.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tagger.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/tagger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAkC,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"tagger.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/tagger.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAk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WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5F,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/D,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,IAAI,CAAC;IACpD,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;IACtC,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,GAAG,IAAI,CAAC;IAClD,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC;AAmJD,wBAAgB,YAAY,IAAI,MAAM,CAycrC"}
|
|
@@ -18,10 +18,33 @@
|
|
|
18
18
|
* agentName)`. Returns `undefined` when the key has never been measured — the
|
|
19
19
|
* caller is expected to fall back to residual math or show zero.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
21
|
+
* Persistence (v9+): measurements are also written to SQLite so that a
|
|
22
|
+
* plugin restart can repopulate the in-memory map without waiting for the
|
|
23
|
+
* next chat.message → tool.definition hook chain. The in-memory Map remains
|
|
24
|
+
* the hot read path; SQLite is a write-through mirror that backs cold starts.
|
|
25
|
+
* If `setDatabase()` hasn't been called yet (cold path before openDatabase
|
|
26
|
+
* completes), `recordToolDefinition` still updates the in-memory map and
|
|
27
|
+
* silently skips persistence — first measurement after init lands both.
|
|
24
28
|
*/
|
|
29
|
+
import type { Database } from "../../shared/sqlite";
|
|
30
|
+
/**
|
|
31
|
+
* Register the database used to persist measurements. Called by
|
|
32
|
+
* openDatabase() after runMigrations() has ensured the
|
|
33
|
+
* `tool_definition_measurements` table exists. Subsequent
|
|
34
|
+
* recordToolDefinition() calls will write through to SQLite.
|
|
35
|
+
*/
|
|
36
|
+
export declare function setDatabase(db: Database): void;
|
|
37
|
+
/**
|
|
38
|
+
* Populate the in-memory measurements map from the
|
|
39
|
+
* `tool_definition_measurements` table. Called once at startup after
|
|
40
|
+
* setDatabase(), before the first sidebar snapshot or status query, so the
|
|
41
|
+
* sidebar's "Tool Defs" segment shows the correct value immediately on
|
|
42
|
+
* restart instead of 0.
|
|
43
|
+
*
|
|
44
|
+
* Idempotent: re-running over the same DB reapplies the same values; the
|
|
45
|
+
* inner-map key (toolID) ensures duplicates overwrite rather than accumulate.
|
|
46
|
+
*/
|
|
47
|
+
export declare function loadToolDefinitionMeasurements(db: Database): void;
|
|
25
48
|
/**
|
|
26
49
|
* Tokenize a single tool's schema and store it under the given key. Called
|
|
27
50
|
* from the `tool.definition` plugin hook once per tool per flight. Same
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-definition-tokens.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/tool-definition-tokens.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"tool-definition-tokens.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/tool-definition-tokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAiBpD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAE9C;AAED;;;;;;;;;GASG;AACH,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CA4BjE;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAChC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,OAAO,GACpB,IAAI,CAgDN;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC3C,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,GAAG,SAAS,GAC9B,MAAM,GAAG,SAAS,CAOpB;AAED,sEAAsE;AACtE,wBAAgB,iCAAiC,IAAI,IAAI,CAGxD;AAED,+EAA+E;AAC/E,wBAAgB,yBAAyB,IAAI,KAAK,CAAC;IAC/C,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;CACrB,CAAC,CAMD"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool-owner backfill (plan v3.3.1, Layer B).
|
|
3
|
+
*
|
|
4
|
+
* Migration v10 added `tool_owner_message_id` to the tags table. The
|
|
5
|
+
* runtime carries every new tool tag with a non-NULL owner, but the
|
|
6
|
+
* 185k+ existing rows in user DBs need their owner column populated to
|
|
7
|
+
* make the v10 fix fully effective. The backfill pass iterates each
|
|
8
|
+
* session that has tool tags with NULL owner, queries the OpenCode DB
|
|
9
|
+
* for the temporally-earliest assistant message that invoked each
|
|
10
|
+
* callID, and writes the owner via a NULL-guarded UPDATE so the
|
|
11
|
+
* runtime can lazily adopt rows the backfill couldn't see (e.g. Pi
|
|
12
|
+
* sessions, deleted OC sessions, transient OC-DB-unavailable cases).
|
|
13
|
+
*
|
|
14
|
+
* Concurrency model:
|
|
15
|
+
* - Per-session advisory lease via `tool_owner_backfill_state`.
|
|
16
|
+
* - 5-minute lease, renewed every 60s during chunked execution.
|
|
17
|
+
* - Sibling instances skip sessions whose lease is held and active.
|
|
18
|
+
* - Process-death cleanup falls out for free: better-sqlite3 + WAL
|
|
19
|
+
* drops all locks at process exit, and the `lease_expires_at`
|
|
20
|
+
* column is the only durable state. A crashed process's session
|
|
21
|
+
* becomes claimable as soon as the lease wall-clock expires.
|
|
22
|
+
* - NULL-guarded UPDATE: backfill never clobbers a row already
|
|
23
|
+
* adopted at runtime.
|
|
24
|
+
*
|
|
25
|
+
* Skip vs fail semantics:
|
|
26
|
+
* - When OpenCode DB is missing (e.g. Pi-only install), every
|
|
27
|
+
* session gets marked 'skipped' in the state table. Lazy adoption
|
|
28
|
+
* handles the orphans at runtime.
|
|
29
|
+
* - When OpenCode DB exists but a specific session is missing or
|
|
30
|
+
* yields zero matches, that session is marked 'skipped' too.
|
|
31
|
+
* Same lazy-adoption fallback covers it.
|
|
32
|
+
* - A session error during backfill (SQLITE_BUSY, malformed JSON,
|
|
33
|
+
* anything) is logged and the session is left in 'pending'/
|
|
34
|
+
* 'running' for a retry on next plugin start. Backfill never
|
|
35
|
+
* fail-closes the plugin — it's defense-in-depth on top of
|
|
36
|
+
* Layer C lazy adoption.
|
|
37
|
+
*
|
|
38
|
+
* Idempotency:
|
|
39
|
+
* - The NULL guard makes UPDATE idempotent: re-running against an
|
|
40
|
+
* already-backfilled row matches zero rows and moves on.
|
|
41
|
+
* - The state table makes session bookkeeping idempotent: a
|
|
42
|
+
* completed session is never re-processed.
|
|
43
|
+
*/
|
|
44
|
+
import type { Database } from "../../shared/sqlite";
|
|
45
|
+
interface BackfillStateRow {
|
|
46
|
+
session_id: string;
|
|
47
|
+
status: string;
|
|
48
|
+
started_at: number | null;
|
|
49
|
+
lease_expires_at: number | null;
|
|
50
|
+
completed_at: number | null;
|
|
51
|
+
last_error: string | null;
|
|
52
|
+
}
|
|
53
|
+
interface BackfillResult {
|
|
54
|
+
sessionsProcessed: number;
|
|
55
|
+
sessionsSkippedNoOcDb: number;
|
|
56
|
+
sessionsSkippedNoMatches: number;
|
|
57
|
+
sessionsCompleted: number;
|
|
58
|
+
sessionsBlockedByLease: number;
|
|
59
|
+
sessionsErrored: number;
|
|
60
|
+
rowsUpdated: number;
|
|
61
|
+
rowsLeftNull: number;
|
|
62
|
+
durationMs: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Top-level entry point. Called from `openDatabase()` after
|
|
66
|
+
* `runMigrations()` returns. Synchronous; runs to completion before
|
|
67
|
+
* returning so the first transform pass on a fresh upgrade sees a
|
|
68
|
+
* mostly-backfilled DB.
|
|
69
|
+
*
|
|
70
|
+
* Worst-case runtime on the user's playground DB (3,276 sessions,
|
|
71
|
+
* 185,716 tool tags): ~25 seconds. Well under the 60-second budget.
|
|
72
|
+
*/
|
|
73
|
+
export declare function runToolOwnerBackfill(db: Database): BackfillResult;
|
|
74
|
+
/**
|
|
75
|
+
* Returns true when at least one tool tag exists with NULL owner that
|
|
76
|
+
* isn't already marked completed/skipped in the state table.
|
|
77
|
+
*
|
|
78
|
+
* Treating "no NULL-owner tags" as "no work" lets us short-circuit on
|
|
79
|
+
* fresh DBs (every row is born with a non-NULL owner) and on already-
|
|
80
|
+
* backfilled DBs (re-running is a no-op).
|
|
81
|
+
*/
|
|
82
|
+
export declare function isToolOwnerBackfillNeeded(db: Database): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Test-only: read the backfill state for a session. Exposed via the
|
|
85
|
+
* normal export but namespaced by underscore so it doesn't show up in
|
|
86
|
+
* the public surface area outside tests.
|
|
87
|
+
*/
|
|
88
|
+
export declare function _getBackfillState(db: Database, sessionId: string): BackfillStateRow | null;
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=tool-owner-backfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-owner-backfill.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/tool-owner-backfill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAMH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAiBpD,UAAU,gBAAgB;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED,UAAU,cAAc;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,wBAAwB,EAAE,MAAM,CAAC;IACjC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACtB;AA2BD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,QAAQ,GAAG,cAAc,CAqDjE;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,QAAQ,GAAG,OAAO,CAkB/D;AA6SD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,GAAG,gBAAgB,GAAG,IAAI,CAO1F"}
|
|
@@ -17,6 +17,23 @@ export interface TagEntry {
|
|
|
17
17
|
* target depth for its age band.
|
|
18
18
|
*/
|
|
19
19
|
cavemanDepth: number;
|
|
20
|
+
/**
|
|
21
|
+
* For `type: "tool"` tags: the assistant message id where the
|
|
22
|
+
* underlying tool call was invoked. Identity for a tool tag is the
|
|
23
|
+
* triple `(sessionId, messageId/callID, toolOwnerMessageId)` —
|
|
24
|
+
* including this field disambiguates collisions when OpenCode's
|
|
25
|
+
* per-turn callID counter produces the same id across turns.
|
|
26
|
+
*
|
|
27
|
+
* NULL on:
|
|
28
|
+
* - all `type: "message"` and `type: "file"` tags (not applicable)
|
|
29
|
+
* - legacy tool tags written before plugin v0.16.x (the
|
|
30
|
+
* tag-owner-fix migration v10). The runtime lazily adopts these
|
|
31
|
+
* orphan rows on first observation; backfill populates them at
|
|
32
|
+
* plugin startup against the OpenCode DB.
|
|
33
|
+
*
|
|
34
|
+
* See plan v3.3.1 in `.alfonso/plans/tag-owner-fix-plan.md`.
|
|
35
|
+
*/
|
|
36
|
+
toolOwnerMessageId: string | null;
|
|
20
37
|
}
|
|
21
38
|
export interface PendingOp {
|
|
22
39
|
id: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC;IAC3C,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC;IAC/B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,YAAY,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,QAAQ;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClC,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC;IAC3C,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC;IAC/B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;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