@cortexkit/opencode-magic-context 0.13.1 → 0.14.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 (84) hide show
  1. package/README.md +13 -7
  2. package/dist/cli/doctor.d.ts.map +1 -1
  3. package/dist/cli.js +59 -3
  4. package/dist/config/index.d.ts.map +1 -1
  5. package/dist/config/schema/magic-context.d.ts +61 -22
  6. package/dist/config/schema/magic-context.d.ts.map +1 -1
  7. package/dist/features/magic-context/compartment-storage.d.ts.map +1 -1
  8. package/dist/features/magic-context/git-commits/git-log-reader.d.ts +57 -0
  9. package/dist/features/magic-context/git-commits/git-log-reader.d.ts.map +1 -0
  10. package/dist/features/magic-context/git-commits/index.d.ts +7 -0
  11. package/dist/features/magic-context/git-commits/index.d.ts.map +1 -0
  12. package/dist/features/magic-context/git-commits/indexer.d.ts +44 -0
  13. package/dist/features/magic-context/git-commits/indexer.d.ts.map +1 -0
  14. package/dist/features/magic-context/git-commits/search-git-commits.d.ts +32 -0
  15. package/dist/features/magic-context/git-commits/search-git-commits.d.ts.map +1 -0
  16. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts +18 -0
  17. package/dist/features/magic-context/git-commits/storage-git-commit-embeddings.d.ts.map +1 -0
  18. package/dist/features/magic-context/git-commits/storage-git-commits.d.ts +47 -0
  19. package/dist/features/magic-context/git-commits/storage-git-commits.d.ts.map +1 -0
  20. package/dist/features/magic-context/memory/embedding-local.d.ts +2 -2
  21. package/dist/features/magic-context/memory/embedding-local.d.ts.map +1 -1
  22. package/dist/features/magic-context/memory/embedding-openai.d.ts +25 -2
  23. package/dist/features/magic-context/memory/embedding-openai.d.ts.map +1 -1
  24. package/dist/features/magic-context/memory/embedding-provider.d.ts +8 -2
  25. package/dist/features/magic-context/memory/embedding-provider.d.ts.map +1 -1
  26. package/dist/features/magic-context/memory/embedding.d.ts +23 -4
  27. package/dist/features/magic-context/memory/embedding.d.ts.map +1 -1
  28. package/dist/features/magic-context/migrations.d.ts.map +1 -1
  29. package/dist/features/magic-context/overflow-detection.d.ts +51 -0
  30. package/dist/features/magic-context/overflow-detection.d.ts.map +1 -0
  31. package/dist/features/magic-context/search.d.ts +40 -9
  32. package/dist/features/magic-context/search.d.ts.map +1 -1
  33. package/dist/features/magic-context/storage-db.d.ts.map +1 -1
  34. package/dist/features/magic-context/storage-meta-persisted.d.ts +40 -0
  35. package/dist/features/magic-context/storage-meta-persisted.d.ts.map +1 -1
  36. package/dist/features/magic-context/storage-meta.d.ts +1 -1
  37. package/dist/features/magic-context/storage-meta.d.ts.map +1 -1
  38. package/dist/features/magic-context/storage.d.ts +1 -1
  39. package/dist/features/magic-context/storage.d.ts.map +1 -1
  40. package/dist/hooks/magic-context/auto-search-hint.d.ts +34 -0
  41. package/dist/hooks/magic-context/auto-search-hint.d.ts.map +1 -0
  42. package/dist/hooks/magic-context/auto-search-runner.d.ts +51 -0
  43. package/dist/hooks/magic-context/auto-search-runner.d.ts.map +1 -0
  44. package/dist/hooks/magic-context/compartment-runner-compressor.d.ts +36 -16
  45. package/dist/hooks/magic-context/compartment-runner-compressor.d.ts.map +1 -1
  46. package/dist/hooks/magic-context/compartment-runner-incremental.d.ts.map +1 -1
  47. package/dist/hooks/magic-context/event-handler.d.ts.map +1 -1
  48. package/dist/hooks/magic-context/event-payloads.d.ts +15 -1
  49. package/dist/hooks/magic-context/event-payloads.d.ts.map +1 -1
  50. package/dist/hooks/magic-context/event-resolvers.d.ts +20 -1
  51. package/dist/hooks/magic-context/event-resolvers.d.ts.map +1 -1
  52. package/dist/hooks/magic-context/hook-handlers.d.ts +5 -0
  53. package/dist/hooks/magic-context/hook-handlers.d.ts.map +1 -1
  54. package/dist/hooks/magic-context/hook.d.ts +14 -6
  55. package/dist/hooks/magic-context/hook.d.ts.map +1 -1
  56. package/dist/hooks/magic-context/inject-compartments.d.ts +12 -0
  57. package/dist/hooks/magic-context/inject-compartments.d.ts.map +1 -1
  58. package/dist/hooks/magic-context/note-nudger.d.ts.map +1 -1
  59. package/dist/hooks/magic-context/reasoning-capability.d.ts +23 -0
  60. package/dist/hooks/magic-context/reasoning-capability.d.ts.map +1 -0
  61. package/dist/hooks/magic-context/strip-content.d.ts +3 -3
  62. package/dist/hooks/magic-context/strip-content.d.ts.map +1 -1
  63. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts +22 -1
  64. package/dist/hooks/magic-context/transform-postprocess-phase.d.ts.map +1 -1
  65. package/dist/hooks/magic-context/transform.d.ts +12 -0
  66. package/dist/hooks/magic-context/transform.d.ts.map +1 -1
  67. package/dist/index.d.ts.map +1 -1
  68. package/dist/index.js +2161 -618
  69. package/dist/plugin/dream-timer.d.ts +24 -7
  70. package/dist/plugin/dream-timer.d.ts.map +1 -1
  71. package/dist/plugin/hooks/create-session-hooks.d.ts +4 -0
  72. package/dist/plugin/hooks/create-session-hooks.d.ts.map +1 -1
  73. package/dist/plugin/tool-registry.d.ts.map +1 -1
  74. package/dist/shared/models-dev-cache.d.ts +20 -6
  75. package/dist/shared/models-dev-cache.d.ts.map +1 -1
  76. package/dist/tools/ctx-note/tools.d.ts.map +1 -1
  77. package/dist/tools/ctx-search/constants.d.ts +1 -1
  78. package/dist/tools/ctx-search/constants.d.ts.map +1 -1
  79. package/dist/tools/ctx-search/tools.d.ts.map +1 -1
  80. package/dist/tools/ctx-search/types.d.ts +8 -0
  81. package/dist/tools/ctx-search/types.d.ts.map +1 -1
  82. package/package.json +1 -1
  83. package/src/shared/models-dev-cache.test.ts +57 -6
  84. package/src/shared/models-dev-cache.ts +119 -38
@@ -1 +1 @@
1
- {"version":3,"file":"embedding-openai.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/memory/embedding-openai.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,UAAU,wCAAwC;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CA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AAC,YAAY,CAAgB;IACpC,OAAO,CAAC,gBAAgB,CAAK;IAC7B,OAAO,CAAC,UAAU,CAAS;IAC3B;;sDAEkD;IAClD,OAAO,CAAC,qBAAqB,CAAS;gBAE1B,OAAO,EAAE,wCAAwC;IAOvD,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAc9B,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAKvE,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,CAAC;IAqHnF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAI9B,QAAQ,IAAI,OAAO;IAInB;;;;;;;;OAQG;IACH,OAAO,CAAC,wBAAwB;IAsBhC,OAAO,CAAC,aAAa;IAiCrB,OAAO,CAAC,aAAa;IAUrB,gBAAgB,IAAI,YAAY;IAQhC,gBAAgB,IAAI,MAAM;IAG1B,aAAa,IAAI,IAAI;CAMxB"}
@@ -1,8 +1,14 @@
1
1
  export interface EmbeddingProvider {
2
2
  readonly modelId: string;
3
3
  initialize(): Promise<boolean>;
4
- embed(text: string): Promise<Float32Array | null>;
5
- embedBatch(texts: string[]): Promise<(Float32Array | null)[]>;
4
+ /** Embed a single text. `signal` lets callers abort the underlying network
5
+ * request (or long-running local inference) before the provider's internal
6
+ * timeout fires — used by transform-hot-path callers that have their own
7
+ * sub-timeout (e.g. 3s auto-search wants to cancel the 30s embed fetch). */
8
+ embed(text: string, signal?: AbortSignal): Promise<Float32Array | null>;
9
+ /** Batch variant of `embed`. Same signal semantics: aborting cancels the
10
+ * whole batch request (including the underlying HTTP call for remote providers). */
11
+ embedBatch(texts: string[], signal?: AbortSignal): Promise<(Float32Array | null)[]>;
6
12
  dispose(): Promise<void>;
7
13
  isLoaded(): boolean;
8
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"embedding-provider.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/memory/embedding-provider.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAClD,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,QAAQ,IAAI,OAAO,CAAC;CACvB"}
1
+ {"version":3,"file":"embedding-provider.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/memory/embedding-provider.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/B;;;iFAG6E;IAC7E,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IACxE;yFACqF;IACrF,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IACpF,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,QAAQ,IAAI,OAAO,CAAC;CACvB"}
@@ -4,14 +4,33 @@ import { cosineSimilarity } from "./cosine-similarity";
4
4
  export declare function initializeEmbedding(config: EmbeddingConfig): void;
5
5
  export declare function isEmbeddingEnabled(): boolean;
6
6
  export declare function ensureEmbeddingModel(): Promise<boolean>;
7
- export declare function embedText(text: string): Promise<Float32Array | null>;
8
- export declare function embedBatch(texts: string[]): Promise<(Float32Array | null)[]>;
7
+ export declare function embedText(text: string, signal?: AbortSignal): Promise<Float32Array | null>;
8
+ export declare function embedBatch(texts: string[], signal?: AbortSignal): Promise<(Float32Array | null)[]>;
9
9
  export declare function embedUnembeddedMemories(db: Database, projectPath: string, config: EmbeddingConfig, batchSize?: number): Promise<number>;
10
10
  /**
11
- * Sweep ALL projects for unembedded memories, not just one project.
12
- * Used by the dream timer to ensure cross-project embedding coverage.
11
+ * Sweep ALL projects for unembedded memories, draining each fully before
12
+ * moving to the next. Projects are ordered by most-recent memory activity
13
+ * (MAX(updated_at)), so the project you're actively working in gets
14
+ * embedded first after a provider switch.
15
+ *
16
+ * Within one invocation:
17
+ * - Each project is drained in batches of `batchSize` until `embedUnembeddedMemoriesForProject`
18
+ * returns 0 (nothing left, or a batch failure).
19
+ * - Wall-clock deadline + consecutive-empty fail-safe prevent runaway
20
+ * or infinite looping when the provider is unhealthy.
21
+ *
22
+ * Between invocations:
23
+ * - The module-level `sweepInProgress` flag guards against parallel runs
24
+ * from the same process. If a sweep is still running when the next
25
+ * 15-min tick fires, that tick is a no-op.
26
+ *
27
+ * Used by the dream timer for proactive embedding coverage. After a
28
+ * provider change wipes embeddings, this path drains the full backlog on
29
+ * a single tick (bounded by wall clock) instead of trickling 10/15min.
13
30
  */
14
31
  export declare function embedAllUnembeddedMemories(db: Database, config: EmbeddingConfig, batchSize?: number): Promise<number>;
32
+ /** Test-only: reset the in-progress guard. */
33
+ export declare function _resetEmbeddingSweepGuard(): void;
15
34
  export declare function getEmbeddingModelId(): string;
16
35
  export { cosineSimilarity };
17
36
  export declare function disposeEmbeddingModel(): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../../../../src/features/magic-context/memory/embedding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAA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E,eAAe,GAAG,IAAI,CAmBjE;AAED,wBAAgB,kBAAkB,IAAI,OAAO,CAE5C;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC,CAO7D;AAED,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAWhG;AAED,wBAAsB,UAAU,CAC5B,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,EAAE,CAAC,CAelC;AAED,wBAAsB,uBAAuB,CACzC,EAAE,EAAE,QAAQ,EACZ,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,eAAe,EACvB,SAAS,SAAK,GACf,OAAO,CAAC,MAAM,CAAC,CAEjB;AAgBD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,0BAA0B,CAC5C,EAAE,EAAE,QAAQ,EACZ,MAAM,EAAE,eAAe,EACvB,SAAS,SAAK,GACf,OAAO,CAAC,MAAM,CAAC,CAsEjB;AAED,8CAA8C;AAC9C,wBAAgB,yBAAyB,IAAI,IAAI,CAEhD;AAmDD,wBAAgB,mBAAmB,IAAI,MAAM,CAE5C;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAS3D"}
@@ -1 +1 @@
1
- {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAsL3C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAkChD"}
1
+ {"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/migrations.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AA8O3C;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAkChD"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Provider-agnostic context-overflow error detection.
3
+ *
4
+ * When a provider rejects a request because the prompt exceeds its context
5
+ * window, we want to react:
6
+ * 1. Trigger emergency recovery (historian + aggressive drops) so the next
7
+ * turn fits.
8
+ * 2. If the error message reveals the real context limit, persist it as a
9
+ * session-specific override so pressure math is accurate going forward.
10
+ *
11
+ * Pattern list adapted from OpenCode's `packages/opencode/src/provider/error.ts`
12
+ * (BSD-licensed). We keep our own copy rather than importing OpenCode internals
13
+ * so the plugin stays decoupled from OpenCode versioning.
14
+ *
15
+ * References:
16
+ * - OpenCode overflow detection (origin of patterns):
17
+ * https://github.com/sst/opencode/blob/main/packages/opencode/src/provider/error.ts
18
+ * - Adapted originally from:
19
+ * https://github.com/badlogic/pi-mono/blob/main/packages/ai/src/utils/overflow.ts
20
+ */
21
+ /**
22
+ * Regexes that match provider-reported context-overflow errors. Keep in sync
23
+ * with upstream OpenCode patterns — new providers can be added here as they
24
+ * emerge.
25
+ */
26
+ export declare const OVERFLOW_PATTERNS: ReadonlyArray<RegExp>;
27
+ export interface OverflowDetection {
28
+ /** True if the error message matches a known overflow pattern. */
29
+ isOverflow: boolean;
30
+ /** Reported context limit in tokens, if extractable from the message. */
31
+ reportedLimit?: number;
32
+ /** The pattern that matched, useful for logging/diagnostics. */
33
+ matchedPattern?: string;
34
+ }
35
+ /**
36
+ * Extract an error message from any reasonable shape. Events from OpenCode can
37
+ * deliver errors as strings, Error instances, or plain objects with `message`.
38
+ */
39
+ export declare function extractErrorMessage(error: unknown): string;
40
+ /**
41
+ * Detect whether an error represents a provider-side context-overflow
42
+ * rejection, and optionally extract the reported limit.
43
+ */
44
+ export declare function detectOverflow(error: unknown): OverflowDetection;
45
+ /**
46
+ * Extract the reported context-limit (in tokens) from an error message if one
47
+ * of the known patterns matches. Returns undefined when no plausible number
48
+ * can be extracted. Guards against false matches via plausibility clamp.
49
+ */
50
+ export declare function parseReportedLimit(message: string): number | undefined;
51
+ //# sourceMappingURL=overflow-detection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overflow-detection.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/overflow-detection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,MAAM,CAqBnD,CAAC;AA8BF,MAAM,WAAW,iBAAiB;IAC9B,kEAAkE;IAClE,UAAU,EAAE,OAAO,CAAC;IACpB,yEAAyE;IACzE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,gEAAgE;IAChE,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA6B1D;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,CA8BhE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAatE"}
@@ -1,14 +1,42 @@
1
1
  import type { Database } from "bun:sqlite";
2
2
  import type { RawMessage } from "../../hooks/magic-context/read-session-raw";
3
+ export type SearchSource = "memory" | "message" | "git_commit";
3
4
  export interface UnifiedSearchOptions {
4
5
  limit?: number;
5
6
  memoryEnabled?: boolean;
6
7
  embeddingEnabled?: boolean;
7
8
  readMessages?: (sessionId: string) => RawMessage[];
8
- embedQuery?: (text: string) => Promise<Float32Array | null>;
9
+ embedQuery?: (text: string, signal?: AbortSignal) => Promise<Float32Array | null>;
9
10
  isEmbeddingRuntimeEnabled?: () => boolean;
10
11
  /** Only return message-history hits with ordinal ≤ this value (e.g. last compartment end). -1 or omit to search all. */
11
12
  maxMessageOrdinal?: number;
13
+ /** Include indexed git commits in the result set. Default false — the
14
+ * feature is gated behind experimental.git_commit_indexing config. */
15
+ gitCommitsEnabled?: boolean;
16
+ /** Restrict results to these sources. Omit or pass undefined to search all
17
+ * enabled sources. Empty array is treated as "no sources enabled" → [].
18
+ * Facts are NOT a source — they're already always rendered in the
19
+ * <session-history> block injected into message[0]. */
20
+ sources?: SearchSource[];
21
+ /** Hard-filter memories already rendered in <session-history>. The agent
22
+ * can see them in message[0] — surfacing them via ctx_search wastes
23
+ * tokens and crowds out high-signal raw-history hits. Pass null or omit
24
+ * to disable filtering (for callers outside the transform context that
25
+ * can't resolve the visible set). */
26
+ visibleMemoryIds?: Set<number> | null;
27
+ /** Abort signal — if provided, cancels in-flight embedding requests
28
+ * (and any downstream HTTP calls) when the caller gives up. Used by
29
+ * transform-hot-path callers like auto-search whose own 3s timeout
30
+ * needs to cancel the 30s embedding fetch. */
31
+ signal?: AbortSignal;
32
+ /** When true (default), increment retrieval_count on memory hits. Explicit
33
+ * `ctx_search` tool calls from the agent SHOULD count — the agent asked
34
+ * for the memory, saw it, and used it. Plugin-internal automatic surfacing
35
+ * (e.g. auto-search hints appended to every user prompt) should NOT count
36
+ * because the agent may never actually consume the hint, and even if they
37
+ * do, automatic surfacing doesn't indicate usefulness. Mis-counting drives
38
+ * spurious retrieval-count-based memory promotion decisions. */
39
+ countRetrievals?: boolean;
12
40
  }
13
41
  export interface MemorySearchResult {
14
42
  source: "memory";
@@ -18,13 +46,6 @@ export interface MemorySearchResult {
18
46
  category: string;
19
47
  matchType: "semantic" | "fts" | "hybrid";
20
48
  }
21
- export interface FactSearchResult {
22
- source: "fact";
23
- content: string;
24
- score: number;
25
- factId: number;
26
- factCategory: string;
27
- }
28
49
  export interface MessageSearchResult {
29
50
  source: "message";
30
51
  content: string;
@@ -33,6 +54,16 @@ export interface MessageSearchResult {
33
54
  messageId: string;
34
55
  role: string;
35
56
  }
36
- export type UnifiedSearchResult = MemorySearchResult | FactSearchResult | MessageSearchResult;
57
+ export interface GitCommitSearchResult {
58
+ source: "git_commit";
59
+ content: string;
60
+ score: number;
61
+ sha: string;
62
+ shortSha: string;
63
+ author: string | null;
64
+ committedAtMs: number;
65
+ matchType: "semantic" | "fts" | "hybrid";
66
+ }
67
+ export type UnifiedSearchResult = MemorySearchResult | MessageSearchResult | GitCommitSearchResult;
37
68
  export declare function unifiedSearch(db: Database, sessionId: string, projectPath: string, query: string, options?: UnifiedSearchOptions): Promise<UnifiedSearchResult[]>;
38
69
  //# sourceMappingURL=search.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAuC7E,MAAM,WAAW,oBAAoB;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,UAAU,EAAE,CAAC;IACnD,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC;IAC5D,yBAAyB,CAAC,EAAE,MAAM,OAAO,CAAC;IAC1C,wHAAwH;IACxH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,kBAAkB;IAC/B,MAAM,EAAE,QAAQ,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,UAAU,GAAG,KAAK,GAAG,QAAQ,CAAC;CAC5C;AAED,MAAM,WAA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AG,mBAAmB,GAAG,qBAAqB,CAAC;AA+anG,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,CAmFhC"}
@@ -1 +1 @@
1
- {"version":3,"file":"storage-db.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAkBtC,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CAuTrD;AA6FD,wBAAgB,YAAY,IAAI,QAAQ,CAsCvC;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"}
1
+ {"version":3,"file":"storage-db.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAkBtC,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI,CA6UrD;AAsHD,wBAAgB,YAAY,IAAI,QAAQ,CAsCvC;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"}
@@ -21,6 +21,15 @@ export declare function loadPersistedUsage(db: Database, sessionId: string): {
21
21
  } | null;
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
+ /**
25
+ * Reset the persisted reasoning watermark for a session.
26
+ *
27
+ * The watermark is model-specific because non-interleaved models may safely
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.
31
+ */
32
+ export declare function clearPersistedReasoningWatermark(db: Database, sessionId: string): void;
24
33
  export declare function getPersistedNudgePlacement(db: Database, sessionId: string): {
25
34
  messageId: string;
26
35
  nudgeText: string;
@@ -35,9 +44,40 @@ export declare function setPersistedNoteNudgeTrigger(db: Database, sessionId: st
35
44
  export declare function setPersistedNoteNudgeTriggerMessageId(db: Database, sessionId: string, triggerMessageId: string): void;
36
45
  export declare function setPersistedDeliveredNoteNudge(db: Database, sessionId: string, text: string, messageId?: string): void;
37
46
  export declare function clearPersistedNoteNudge(db: Database, sessionId: string): void;
47
+ /**
48
+ * Return the timestamp of the most recent ctx_note(read) call for this session,
49
+ * or 0 when the session has never called it. Used by note-nudger to suppress
50
+ * reminders when the agent has already seen notes in recent context.
51
+ */
52
+ export declare function getNoteLastReadAt(db: Database, sessionId: string): number;
53
+ /**
54
+ * Record that ctx_note(read) was just called for this session. The watermark is
55
+ * compared against note updated_at / created_at on each nudge decision.
56
+ */
57
+ export declare function setNoteLastReadAt(db: Database, sessionId: string, at?: number): void;
38
58
  export declare function getHistorianFailureState(db: Database, sessionId: string): PersistedHistorianFailureState;
39
59
  export declare function incrementHistorianFailure(db: Database, sessionId: string, error: string): void;
40
60
  export declare function clearHistorianFailureState(db: Database, sessionId: string): void;
61
+ export interface PersistedOverflowState {
62
+ /** Provider-reported context limit from the overflow error; 0 means none detected. */
63
+ detectedContextLimit: number;
64
+ /** True while recovery is still required after an overflow. */
65
+ needsEmergencyRecovery: boolean;
66
+ }
67
+ export declare function getOverflowState(db: Database, sessionId: string): PersistedOverflowState;
68
+ /**
69
+ * Record that a provider reported an overflow. Sets the recovery flag
70
+ * unconditionally; also persists the real limit if one was extracted from the
71
+ * error message. Transactional so the two fields always agree.
72
+ */
73
+ export declare function recordOverflowDetected(db: Database, sessionId: string, reportedLimit: number | undefined): void;
74
+ /** Clear the recovery flag. Keeps the detected limit (valuable even after recovery). */
75
+ export declare function clearEmergencyRecovery(db: Database, sessionId: string): void;
76
+ /**
77
+ * Clear the detected limit. Called when the session switches to a different
78
+ * model — the old limit is no longer relevant.
79
+ */
80
+ export declare function clearDetectedContextLimit(db: Database, sessionId: string): void;
41
81
  export interface PersistedCompactionMarkerState {
42
82
  boundaryMessageId: string;
43
83
  summaryMessageId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"storage-meta-persisted.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-meta-persisted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,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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,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"}
1
+ {"version":3,"file":"storage-meta-persisted.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-meta-persisted.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,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;;;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,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"}
@@ -1,3 +1,3 @@
1
- export { clearHistorianFailureState, clearPersistedNoteNudge, clearPersistedNudgePlacement, clearPersistedStickyTurnReminder, getHistorianFailureState, getPersistedNoteNudge, getPersistedNudgePlacement, getPersistedReasoningWatermark, getPersistedStickyTurnReminder, getStrippedPlaceholderIds, incrementHistorianFailure, loadPersistedUsage, removeStrippedPlaceholderId, setPersistedNudgePlacement, setPersistedReasoningWatermark, setPersistedStickyTurnReminder, setStrippedPlaceholderIds, } from "./storage-meta-persisted";
1
+ export { clearDetectedContextLimit, clearEmergencyRecovery, clearHistorianFailureState, clearPersistedNoteNudge, clearPersistedNudgePlacement, clearPersistedReasoningWatermark, clearPersistedStickyTurnReminder, getHistorianFailureState, getNoteLastReadAt, getOverflowState, getPersistedNoteNudge, getPersistedNudgePlacement, getPersistedReasoningWatermark, getPersistedStickyTurnReminder, getStrippedPlaceholderIds, incrementHistorianFailure, loadPersistedUsage, type PersistedOverflowState, recordOverflowDetected, removeStrippedPlaceholderId, setNoteLastReadAt, setPersistedNudgePlacement, setPersistedReasoningWatermark, setPersistedStickyTurnReminder, setStrippedPlaceholderIds, } from "./storage-meta-persisted";
2
2
  export { clearSession, getOrCreateSessionMeta, updateSessionMeta, } from "./storage-meta-session";
3
3
  //# sourceMappingURL=storage-meta.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"storage-meta.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-meta.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,0BAA0B,EAC1B,uBAAuB,EACvB,4BAA4B,EAC5B,gCAAgC,EAChC,wBAAwB,EACxB,qBAAqB,EACrB,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,GAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACH,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,GACpB,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"storage-meta.d.ts","sourceRoot":"","sources":["../../../src/features/magic-context/storage-meta.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,yBAAyB,EACzB,sBAAsB,EACtB,0BAA0B,EAC1B,uBAAuB,EACvB,4BAA4B,EAC5B,gCAAgC,EAChC,gCAAgC,EAChC,wBAAwB,EACxB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACrB,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EAClB,KAAK,sBAAsB,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,iBAAiB,EACjB,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,GAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACH,YAAY,EACZ,sBAAsB,EACtB,iBAAiB,GACpB,MAAM,wBAAwB,CAAC"}
@@ -2,7 +2,7 @@ export { buildCompartmentBlock, escapeXmlAttr, escapeXmlContent, getCompartments
2
2
  export { clearCompressionDepth, getAverageCompressionDepth, getMaxCompressionDepth, incrementCompressionDepth, } from "./compression-depth-storage";
3
3
  export { clearIndexedMessages, deleteIndexedMessage, } from "./message-index";
4
4
  export { type ContextDatabase, closeDatabase, getDatabasePersistenceError, isDatabasePersisted, openDatabase, } from "./storage-db";
5
- export { clearHistorianFailureState, clearPersistedNoteNudge, clearPersistedNudgePlacement, clearPersistedStickyTurnReminder, clearSession, getHistorianFailureState, getOrCreateSessionMeta, getPersistedNoteNudge, getPersistedNudgePlacement, getPersistedReasoningWatermark, getPersistedStickyTurnReminder, getStrippedPlaceholderIds, incrementHistorianFailure, loadPersistedUsage, removeStrippedPlaceholderId, setPersistedNudgePlacement, setPersistedReasoningWatermark, setPersistedStickyTurnReminder, setStrippedPlaceholderIds, updateSessionMeta, } from "./storage-meta";
5
+ export { clearDetectedContextLimit, clearEmergencyRecovery, clearHistorianFailureState, clearPersistedNoteNudge, clearPersistedNudgePlacement, clearPersistedReasoningWatermark, clearPersistedStickyTurnReminder, clearSession, getHistorianFailureState, getNoteLastReadAt, getOrCreateSessionMeta, getOverflowState, getPersistedNoteNudge, getPersistedNudgePlacement, getPersistedReasoningWatermark, getPersistedStickyTurnReminder, getStrippedPlaceholderIds, incrementHistorianFailure, loadPersistedUsage, type PersistedOverflowState, recordOverflowDetected, removeStrippedPlaceholderId, setNoteLastReadAt, setPersistedNudgePlacement, setPersistedReasoningWatermark, setPersistedStickyTurnReminder, setStrippedPlaceholderIds, updateSessionMeta, } from "./storage-meta";
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";
@@ -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,0BAA0B,EAC1B,uBAAuB,EACvB,4BAA4B,EAC5B,gCAAgC,EAChC,YAAY,EACZ,wBAAwB,EACxB,sBAAsB,EACtB,qBAAqB,EACrB,0BAA0B,EAC1B,8BAA8B,EAC9B,8BAA8B,EAC9B,yBAAyB,EACzB,yBAAyB,EACzB,kBAAkB,EAClB,2BAA2B,EAC3B,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,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,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,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,GAClB,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Build a compact "you may recall something related" hint from unified search
3
+ * results, ready to append to a user message.
4
+ *
5
+ * The hint intentionally compresses fragments so they feel like vague recall
6
+ * rather than a drop-in answer — the goal is to nudge the agent to run
7
+ * ctx_search for full context, not to provide the answer itself.
8
+ *
9
+ * Compression strategy per source:
10
+ * - memory → caveman-ultra via `cavemanCompress()` (token-dense)
11
+ * - git_commit → raw commit subject (already terse); prefixed with SHA + age
12
+ * - message → caveman-ultra, role tag
13
+ *
14
+ * Guardrails:
15
+ * - Per-fragment token cap (~20 tokens, ~80 chars) with ellipsis truncation
16
+ * - Skip fragments whose source is already present in visible session-history
17
+ * (caller handles) — this module only knows about search results
18
+ * - Hard-caps total output at ~200 tokens so misconfigured thresholds can't
19
+ * balloon the user message
20
+ */
21
+ import type { UnifiedSearchResult } from "../../features/magic-context/search";
22
+ export interface AutoSearchHintOptions {
23
+ maxFragments?: number;
24
+ fragmentCharCap?: number;
25
+ }
26
+ /**
27
+ * Build the hint text. Returns null when `results` is empty, when no fragment
28
+ * has meaningful content after compression, or when limits zero out the budget.
29
+ *
30
+ * This function does NOT enforce score thresholds or message-length rules —
31
+ * callers (the transform-time auto-search wiring) apply those gates first.
32
+ */
33
+ export declare function buildAutoSearchHint(results: UnifiedSearchResult[], options?: AutoSearchHintOptions): string | null;
34
+ //# sourceMappingURL=auto-search-hint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-search-hint.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/auto-search-hint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qCAAqC,CAAC;AAQ/E,MAAM,WAAW,qBAAqB;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AA2CD;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,mBAAmB,EAAE,EAC9B,OAAO,GAAE,qBAA0B,GACpC,MAAM,GAAG,IAAI,CA+Bf"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Transform-time auto-search hint runner.
3
+ *
4
+ * When a new user message arrives, optionally run ctx_search against the user's
5
+ * prompt and append a caveman-compressed "vague recall" fragment hint to that
6
+ * message. The hint nudges the agent to run ctx_search for full context rather
7
+ * than injecting the content directly.
8
+ *
9
+ * Cache safety:
10
+ * - Attaches to the latest user message (the message that triggered the turn),
11
+ * never to message[0] or to any assistant message. Appending to the current
12
+ * user message happens BEFORE it reaches Anthropic's cache because this
13
+ * transform runs on the prompt path — same property as note nudges.
14
+ * - Idempotent via in-memory turn cache + `.includes()` guard in
15
+ * appendReminderToUserMessageById. On defer passes we re-append the same
16
+ * text; `.includes()` makes that a no-op.
17
+ * - New user turn (different message id) → compute fresh hint, new append.
18
+ * - Process restart → cache cleared; next pass will recompute but the user
19
+ * message is a fresh turn anyway, no provider cache to preserve yet.
20
+ */
21
+ import type { Database } from "bun:sqlite";
22
+ import type { MessageLike } from "./transform-operations";
23
+ export interface AutoSearchRunnerOptions {
24
+ enabled: boolean;
25
+ scoreThreshold: number;
26
+ minPromptChars: number;
27
+ projectPath: string;
28
+ memoryEnabled: boolean;
29
+ embeddingEnabled: boolean;
30
+ gitCommitsEnabled: boolean;
31
+ /** Memory ids already rendered in the injected <session-history> block —
32
+ * skip fragments that just duplicate visible memories. */
33
+ visibleMemoryIds?: Set<number>;
34
+ }
35
+ /**
36
+ * Entry point. Called from transform post-processing. No-op when disabled,
37
+ * when there is no meaningful user message, when prompt is too short, when
38
+ * search returns nothing strong enough, or when the hint has already been
39
+ * appended for this turn.
40
+ */
41
+ export declare function runAutoSearchHint(args: {
42
+ sessionId: string;
43
+ db: Database;
44
+ messages: MessageLike[];
45
+ options: AutoSearchRunnerOptions;
46
+ }): Promise<void>;
47
+ /** Test hook — wipe the per-turn cache. */
48
+ export declare function _resetAutoSearchCache(): void;
49
+ /** Session cleanup hook — call on session.deleted. */
50
+ export declare function clearAutoSearchForSession(sessionId: string): void;
51
+ //# sourceMappingURL=auto-search-runner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auto-search-runner.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/auto-search-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAS3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAmD1D,MAAM,WAAW,uBAAuB;IACpC,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,iBAAiB,EAAE,OAAO,CAAC;IAC3B;+DAC2D;IAC3D,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAClC;AAsED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,QAAQ,CAAC;IACb,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,OAAO,EAAE,uBAAuB,CAAC;CACpC,GAAG,OAAO,CAAC,IAAI,CAAC,CAuGhB;AAED,2CAA2C;AAC3C,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED,sDAAsD;AACtD,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAEjE"}
@@ -22,7 +22,6 @@ interface ScoredCompartment {
22
22
  index: number;
23
23
  tokenEstimate: number;
24
24
  averageDepth: number;
25
- score: number;
26
25
  }
27
26
  /**
28
27
  * Check if the compartment block exceeds the history budget and run a compression pass if needed.
@@ -40,23 +39,44 @@ interface SelectionConstraints {
40
39
  floorHeadroom: number;
41
40
  }
42
41
  /**
43
- * Find the oldest contiguous band of compartments that share the same rounded depth.
42
+ * Pick a contiguous same-depth band of compartments to compress next.
44
43
  *
45
- * Strategy: scan oldest→newest (low index first). Skip compartments at max depth,
46
- * and skip the newest `graceCompartments` (grace period). Within the remaining
47
- * scope, find the oldest run of 2+ consecutive compartments with the SAME rounded
48
- * averageDepth. This keeps per-pass work uniform (same LLM prompt tier for all
49
- * inputs) and naturally progresses: depth 0 bands get compressed first, producing
50
- * depth 1 bands, which compress next, etc.
44
+ * Strategy (depth-first, oldest-within-tier):
45
+ * 1. Eligible scope = [0, scored.length - graceCompartments).
46
+ * Newest `graceCompartments` are never compressed (protects just-published
47
+ * historian output).
48
+ * 2. Within eligible scope, ignore compartments whose rounded depth is
49
+ * already at `maxMergeDepth` they're done.
50
+ * 3. Find the **minimum** depth tier that still exists in scope.
51
+ * 4. Anchor on the **oldest** compartment at that minimum depth (lowest
52
+ * index). Extend forward while the next compartment has the same rounded
53
+ * depth, stopping at maxPickable / floorHeadroom / scope end.
54
+ * 5. Require runLen ≥ 2. If the oldest minimum-depth compartment can't form
55
+ * a run (neighbor has a different depth), the algorithm would stall —
56
+ * so fall back to finding the *next* oldest compartment at minDepth and
57
+ * retry. This preserves the old "skip singleton and move on" safety
58
+ * without abandoning the min-depth invariant.
51
59
  *
52
- * Constraints:
53
- * - Skip compartments with averageDepth >= maxMergeDepth (already maxed out).
54
- * - Skip the newest graceCompartments (never compress fresh work).
55
- * - Cap picks at maxPickable to avoid huge LLM inputs.
56
- * - Cap picks at floorHeadroom to avoid violating min-compartment floor. Each
57
- * merge reduces count by (input - output), so limiting picks to floorHeadroom
58
- * guarantees we can't fall below floor even in the worst case (output = 1).
60
+ * Why this shape:
61
+ * The previous algorithm was oldest-first regardless of depth. After the
62
+ * first pass compressed seq 0-14 to depth 1, the next pass picked seq 0-X
63
+ * AGAIN because they were still the oldest. The cascade ran depth 0→1→2→
64
+ * 3→4→5 on the same range within hours, crushing early compartments to
65
+ * empty title-only shells while the rest of history stayed at depth 0.
66
+ *
67
+ * Depth-first selection means: once seq 0-14 reach depth 1, the next pass
68
+ * prefers any depth-0 band elsewhere (seq 15+) before touching seq 0-14
69
+ * again. Old→new gets pushed down one tier at a time, producing a smooth
70
+ * depth gradient (old = deeper, recent = shallower) like memory decay.
71
+ *
72
+ * Grace window still protects the newest N from compression entirely so
73
+ * freshly-published historian output has time to settle.
74
+ */
75
+ export declare function selectCompressionBand(scored: ScoredCompartment[], constraints: SelectionConstraints): ScoredCompartment[];
76
+ /**
77
+ * @deprecated Use {@link selectCompressionBand}. Kept as an export for the
78
+ * existing test suite that targets the older naming; semantics are identical.
59
79
  */
60
- export declare function findOldestContiguousSameDepthBand(scored: ScoredCompartment[], constraints: SelectionConstraints): ScoredCompartment[];
80
+ export declare const findOldestContiguousSameDepthBand: typeof selectCompressionBand;
61
81
  export {};
62
82
  //# sourceMappingURL=compartment-runner-compressor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compartment-runner-compressor.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-compressor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAS3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAC;AAQpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAaxD,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,EAAE,EAAE,QAAQ,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,wEAAwE;IACxE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,2EAA2E;IAC3E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mEAAmE;IACnE,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,wEAAwE;IACxE,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAaD,UAAU,iBAAiB;IACvB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAqKvF;AAoCD,UAAU,oBAAoB;IAC1B,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,aAAa,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,uFAAuF;IACvF,aAAa,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iCAAiC,CAC7C,MAAM,EAAE,iBAAiB,EAAE,EAC3B,WAAW,EAAE,oBAAoB,GAClC,iBAAiB,EAAE,CA6CrB"}
1
+ {"version":3,"file":"compartment-runner-compressor.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-compressor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAS3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAC;AAQpF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAkBxD,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,EAAE,EAAE,QAAQ,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,wEAAwE;IACxE,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,2EAA2E;IAC3E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mEAAmE;IACnE,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,wEAAwE;IACxE,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAaD,UAAU,iBAAiB;IACvB,WAAW,EAAE,WAAW,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAyLvF;AAiCD,UAAU,oBAAoB;IAC1B,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,aAAa,EAAE,MAAM,CAAC;IACtB,oEAAoE;IACpE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,uFAAuF;IACvF,aAAa,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,qBAAqB,CACjC,MAAM,EAAE,iBAAiB,EAAE,EAC3B,WAAW,EAAE,oBAAoB,GAClC,iBAAiB,EAAE,CA4DrB;AAED;;;GAGG;AACH,eAAO,MAAM,iCAAiC,8BAAwB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"compartment-runner-incremental.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-incremental.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAoBxE,+DAA+D;AAC/D,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAEhE;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+NpF"}
1
+ {"version":3,"file":"compartment-runner-incremental.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/compartment-runner-incremental.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAoBxE,+DAA+D;AAC/D,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAEhE;AAED,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqOpF"}
@@ -1 +1 @@
1
- {"version":3,"file":"event-handler.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/event-handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,yCAAyC,CAAC;AAqBvF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY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AM,GAAG;YAAE,OAAO,EAAE,MAAM,CAAC;YAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;SAAE,CAAC;QACxF,wBAAwB,CAAC,EAAE;YAAE,OAAO,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;SAAE,CAAC;QACxF,SAAS,EAAE,cAAc,CAAC;QAC1B,sBAAsB,CAAC,EAAE;YAAE,OAAO,EAAE,OAAO,CAAC;YAAC,YAAY,EAAE,MAAM,CAAA;SAAE,CAAC;KACvE,CAAC;IACF,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,UAAU,CAAC,cAAc,sCAAsC,EAAE,YAAY,CAAC,CAAC;CACtF;AAqGD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,gBAAgB,IACvC,OAAO;IAAE,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,KAAG,OAAO,CAAC,IAAI,CAAC,CAoWzF"}
@@ -1,4 +1,4 @@
1
- export type MagicContextEventType = "session.created" | "message.updated" | "message.removed" | "session.compacted" | "session.deleted";
1
+ export type MagicContextEventType = "session.created" | "session.error" | "message.updated" | "message.removed" | "session.compacted" | "session.deleted";
2
2
  export type MagicContextEvent = {
3
3
  type: MagicContextEventType;
4
4
  properties?: unknown;
@@ -25,6 +25,13 @@ export interface MessageUpdatedAssistantInfo {
25
25
  write?: number;
26
26
  };
27
27
  };
28
+ /** Error attached to the assistant message, if any. OpenCode attaches
29
+ * context-overflow errors here in addition to emitting session.error. */
30
+ error?: unknown;
31
+ }
32
+ export interface SessionErrorInfo {
33
+ sessionID: string;
34
+ error: unknown;
28
35
  }
29
36
  export interface MessageRemovedInfo {
30
37
  sessionID: string;
@@ -36,5 +43,12 @@ export declare function getSessionProperties(properties: unknown): {
36
43
  } | undefined;
37
44
  export declare function getSessionCreatedInfo(properties: unknown): SessionCreatedInfo | null;
38
45
  export declare function getMessageUpdatedAssistantInfo(properties: unknown): MessageUpdatedAssistantInfo | null;
46
+ /**
47
+ * Extract `session.error` event payload. The event carries `{ sessionID, error }`
48
+ * at the top level (no `info` wrapper). We intentionally keep `error` as
49
+ * `unknown` — the plugin does not depend on OpenCode's NamedError shape, the
50
+ * overflow detector accepts strings, Errors, or objects with `message`.
51
+ */
52
+ export declare function getSessionErrorInfo(properties: unknown): SessionErrorInfo | null;
39
53
  export declare function getMessageRemovedInfo(properties: unknown): MessageRemovedInfo | null;
40
54
  //# sourceMappingURL=event-payloads.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"event-payloads.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/event-payloads.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,qBAAqB,GAC3B,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,mBAAmB,GACnB,iBAAiB,CAAC;AAExB,MAAM,MAAM,iBAAiB,GAAG;IAC5B,IAAI,EAAE,qBAAqB,CAAC;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,WAAW,kBAAkB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,2BAA2B;IACxC,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB;wEACoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE;YACJ,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;KACL,CAAC;CACL;AAED,MAAM,WAAW,kBAAkB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,oBAAoB,CAChC,UAAU,EAAE,OAAO,GACpB;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAUpD;AAED,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAiBpF;AAED,wBAAgB,8BAA8B,CAC1C,UAAU,EAAE,OAAO,GACpB,2BAA2B,GAAG,IAAI,CA6BpC;AAED,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAapF"}
1
+ {"version":3,"file":"event-payloads.d.ts","sourceRoot":"","sources":["../../../src/hooks/magic-context/event-payloads.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,qBAAqB,GAC3B,iBAAiB,GACjB,eAAe,GACf,iBAAiB,GACjB,iBAAiB,GACjB,mBAAmB,GACnB,iBAAiB,CAAC;AAExB,MAAM,MAAM,iBAAiB,GAAG;IAC5B,IAAI,EAAE,qBAAqB,CAAC;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,WAAW,kBAAkB;IAC/B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,2BAA2B;IACxC,IAAI,EAAE,WAAW,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB;wEACoE;IACpE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE;QACL,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,KAAK,CAAC,EAAE;YACJ,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,KAAK,CAAC,EAAE,MAAM,CAAC;SAClB,CAAC;KACL,CAAC;IACF;8EAC0E;IAC1E,KAAK,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,kBAAkB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,oBAAoB,CAChC,UAAU,EAAE,OAAO,GACpB;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAUpD;AAED,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAiBpF;AAED,wBAAgB,8BAA8B,CAC1C,UAAU,EAAE,OAAO,GACpB,2BAA2B,GAAG,IAAI,CA8BpC;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,OAAO,GAAG,gBAAgB,GAAG,IAAI,CAMhF;AAED,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,OAAO,GAAG,kBAAkB,GAAG,IAAI,CAapF"}
@@ -1,5 +1,24 @@
1
+ import type { ContextDatabase } from "../../features/magic-context/storage";
1
2
  type CacheTtlConfig = string | Record<string, string>;
2
- export declare function resolveContextLimit(providerID: string | undefined, modelID: string | undefined): number;
3
+ /**
4
+ * Resolve the effective context limit for a (providerID, modelID) pair.
5
+ *
6
+ * Resolution order:
7
+ * 1. Detected limit from a prior overflow error, when smaller than the
8
+ * configured/cache limit. Providers report the REAL limit in the error
9
+ * message, which is authoritative for the current deployment.
10
+ * 2. OpenCode's models.dev cache (overlaid with user's
11
+ * `provider.*.models.*.limit.context`).
12
+ * 3. Conservative default (128k).
13
+ *
14
+ * The session context (db + sessionID) is optional — callers that operate
15
+ * outside a specific session (e.g. warm-up, status-bar summaries) can omit it
16
+ * and fall back to the global cache/default.
17
+ */
18
+ export declare function resolveContextLimit(providerID: string | undefined, modelID: string | undefined, ctx?: {
19
+ db?: ContextDatabase;
20
+ sessionID?: string;
21
+ }): number;
3
22
  export declare function resolveCacheTtl(cacheTtl: CacheTtlConfig, modelKey: string | undefined): string;
4
23
  type ExecuteThresholdConfig = number | {
5
24
  default: number;