@infituit/opencode-acp 0.0.0-stage → 2.0.0-alpha.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.
Files changed (194) hide show
  1. package/LICENSE +622 -0
  2. package/NOTICE +29 -0
  3. package/README.md +537 -2
  4. package/dist/index.d.ts +3 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +14433 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/lib/auth.d.ts +4 -0
  9. package/dist/lib/auth.d.ts.map +1 -0
  10. package/dist/lib/bili-proxy.d.ts +64 -0
  11. package/dist/lib/bili-proxy.d.ts.map +1 -0
  12. package/dist/lib/commands/compression-targets.d.ts +13 -0
  13. package/dist/lib/commands/compression-targets.d.ts.map +1 -0
  14. package/dist/lib/commands/context.d.ts +52 -0
  15. package/dist/lib/commands/context.d.ts.map +1 -0
  16. package/dist/lib/commands/export.d.ts +56 -0
  17. package/dist/lib/commands/export.d.ts.map +1 -0
  18. package/dist/lib/commands/index.d.ts +4 -0
  19. package/dist/lib/commands/index.d.ts.map +1 -0
  20. package/dist/lib/commands/stats.d.ts +19 -0
  21. package/dist/lib/commands/stats.d.ts.map +1 -0
  22. package/dist/lib/compress/decompress-logic.d.ts +62 -0
  23. package/dist/lib/compress/decompress-logic.d.ts.map +1 -0
  24. package/dist/lib/compress/decompress.d.ts +4 -0
  25. package/dist/lib/compress/decompress.d.ts.map +1 -0
  26. package/dist/lib/compress/hide-consumed.d.ts +15 -0
  27. package/dist/lib/compress/hide-consumed.d.ts.map +1 -0
  28. package/dist/lib/compress/hide-failed.d.ts +3 -0
  29. package/dist/lib/compress/hide-failed.d.ts.map +1 -0
  30. package/dist/lib/compress/image-archive.d.ts +43 -0
  31. package/dist/lib/compress/image-archive.d.ts.map +1 -0
  32. package/dist/lib/compress/index.d.ts +9 -0
  33. package/dist/lib/compress/index.d.ts.map +1 -0
  34. package/dist/lib/compress/keep-markers.d.ts +11 -0
  35. package/dist/lib/compress/keep-markers.d.ts.map +1 -0
  36. package/dist/lib/compress/parts.d.ts +4 -0
  37. package/dist/lib/compress/parts.d.ts.map +1 -0
  38. package/dist/lib/compress/pipeline.d.ts +141 -0
  39. package/dist/lib/compress/pipeline.d.ts.map +1 -0
  40. package/dist/lib/compress/protected-content.d.ts +12 -0
  41. package/dist/lib/compress/protected-content.d.ts.map +1 -0
  42. package/dist/lib/compress/quality-gate/algorithms/index.d.ts +3 -0
  43. package/dist/lib/compress/quality-gate/algorithms/index.d.ts.map +1 -0
  44. package/dist/lib/compress/quality-gate/evaluate.d.ts +21 -0
  45. package/dist/lib/compress/quality-gate/evaluate.d.ts.map +1 -0
  46. package/dist/lib/compress/quality-gate/index.d.ts +7 -0
  47. package/dist/lib/compress/quality-gate/index.d.ts.map +1 -0
  48. package/dist/lib/compress/quality-gate/registry.d.ts +6 -0
  49. package/dist/lib/compress/quality-gate/registry.d.ts.map +1 -0
  50. package/dist/lib/compress/quality-gate/rejection.d.ts +18 -0
  51. package/dist/lib/compress/quality-gate/rejection.d.ts.map +1 -0
  52. package/dist/lib/compress/quality-gate/types.d.ts +51 -0
  53. package/dist/lib/compress/quality-gate/types.d.ts.map +1 -0
  54. package/dist/lib/compress/range-utils.d.ts +28 -0
  55. package/dist/lib/compress/range-utils.d.ts.map +1 -0
  56. package/dist/lib/compress/range.d.ts +8 -0
  57. package/dist/lib/compress/range.d.ts.map +1 -0
  58. package/dist/lib/compress/recap.d.ts +4 -0
  59. package/dist/lib/compress/recap.d.ts.map +1 -0
  60. package/dist/lib/compress/search.d.ts +17 -0
  61. package/dist/lib/compress/search.d.ts.map +1 -0
  62. package/dist/lib/compress/smart-plan.d.ts +28 -0
  63. package/dist/lib/compress/smart-plan.d.ts.map +1 -0
  64. package/dist/lib/compress/state.d.ts +10 -0
  65. package/dist/lib/compress/state.d.ts.map +1 -0
  66. package/dist/lib/compress/status.d.ts +19 -0
  67. package/dist/lib/compress/status.d.ts.map +1 -0
  68. package/dist/lib/compress/timing.d.ts +17 -0
  69. package/dist/lib/compress/timing.d.ts.map +1 -0
  70. package/dist/lib/compress/types.d.ts +120 -0
  71. package/dist/lib/compress/types.d.ts.map +1 -0
  72. package/dist/lib/compress-permission.d.ts +6 -0
  73. package/dist/lib/compress-permission.d.ts.map +1 -0
  74. package/dist/lib/config-validation.d.ts +13 -0
  75. package/dist/lib/config-validation.d.ts.map +1 -0
  76. package/dist/lib/config.d.ts +248 -0
  77. package/dist/lib/config.d.ts.map +1 -0
  78. package/dist/lib/gc/merge.d.ts +17 -0
  79. package/dist/lib/gc/merge.d.ts.map +1 -0
  80. package/dist/lib/hooks.d.ts +41 -0
  81. package/dist/lib/hooks.d.ts.map +1 -0
  82. package/dist/lib/host-permissions.d.ts +31 -0
  83. package/dist/lib/host-permissions.d.ts.map +1 -0
  84. package/dist/lib/logger.d.ts +48 -0
  85. package/dist/lib/logger.d.ts.map +1 -0
  86. package/dist/lib/message-ids.d.ts +27 -0
  87. package/dist/lib/message-ids.d.ts.map +1 -0
  88. package/dist/lib/messages/enforce-budget.d.ts +65 -0
  89. package/dist/lib/messages/enforce-budget.d.ts.map +1 -0
  90. package/dist/lib/messages/filter/apply.d.ts +14 -0
  91. package/dist/lib/messages/filter/apply.d.ts.map +1 -0
  92. package/dist/lib/messages/filter/builtin/index.d.ts +2 -0
  93. package/dist/lib/messages/filter/builtin/index.d.ts.map +1 -0
  94. package/dist/lib/messages/filter/builtin/omo-context.d.ts +4 -0
  95. package/dist/lib/messages/filter/builtin/omo-context.d.ts.map +1 -0
  96. package/dist/lib/messages/filter/builtin/omo-mode-injection.d.ts +4 -0
  97. package/dist/lib/messages/filter/builtin/omo-mode-injection.d.ts.map +1 -0
  98. package/dist/lib/messages/filter/builtin/omo-system-reminder.d.ts +4 -0
  99. package/dist/lib/messages/filter/builtin/omo-system-reminder.d.ts.map +1 -0
  100. package/dist/lib/messages/filter/builtin/omo-task-directive.d.ts +4 -0
  101. package/dist/lib/messages/filter/builtin/omo-task-directive.d.ts.map +1 -0
  102. package/dist/lib/messages/filter/builtin/omo-todo-continuation.d.ts +4 -0
  103. package/dist/lib/messages/filter/builtin/omo-todo-continuation.d.ts.map +1 -0
  104. package/dist/lib/messages/filter/index.d.ts +6 -0
  105. package/dist/lib/messages/filter/index.d.ts.map +1 -0
  106. package/dist/lib/messages/filter/registry.d.ts +6 -0
  107. package/dist/lib/messages/filter/registry.d.ts.map +1 -0
  108. package/dist/lib/messages/filter/types.d.ts +95 -0
  109. package/dist/lib/messages/filter/types.d.ts.map +1 -0
  110. package/dist/lib/messages/index.d.ts +9 -0
  111. package/dist/lib/messages/index.d.ts.map +1 -0
  112. package/dist/lib/messages/inject/candidates.d.ts +30 -0
  113. package/dist/lib/messages/inject/candidates.d.ts.map +1 -0
  114. package/dist/lib/messages/inject/inject.d.ts +26 -0
  115. package/dist/lib/messages/inject/inject.d.ts.map +1 -0
  116. package/dist/lib/messages/inject/policy/index.d.ts +5 -0
  117. package/dist/lib/messages/inject/policy/index.d.ts.map +1 -0
  118. package/dist/lib/messages/inject/policy/registry.d.ts +8 -0
  119. package/dist/lib/messages/inject/policy/registry.d.ts.map +1 -0
  120. package/dist/lib/messages/inject/policy/types.d.ts +2 -0
  121. package/dist/lib/messages/inject/policy/types.d.ts.map +1 -0
  122. package/dist/lib/messages/inject/utils.d.ts +235 -0
  123. package/dist/lib/messages/inject/utils.d.ts.map +1 -0
  124. package/dist/lib/messages/priority.d.ts +13 -0
  125. package/dist/lib/messages/priority.d.ts.map +1 -0
  126. package/dist/lib/messages/prune.d.ts +5 -0
  127. package/dist/lib/messages/prune.d.ts.map +1 -0
  128. package/dist/lib/messages/query.d.ts +36 -0
  129. package/dist/lib/messages/query.d.ts.map +1 -0
  130. package/dist/lib/messages/reasoning-strip.d.ts +32 -0
  131. package/dist/lib/messages/reasoning-strip.d.ts.map +1 -0
  132. package/dist/lib/messages/shape.d.ts +5 -0
  133. package/dist/lib/messages/shape.d.ts.map +1 -0
  134. package/dist/lib/messages/sticky-truncation.d.ts +55 -0
  135. package/dist/lib/messages/sticky-truncation.d.ts.map +1 -0
  136. package/dist/lib/messages/sync.d.ts +4 -0
  137. package/dist/lib/messages/sync.d.ts.map +1 -0
  138. package/dist/lib/messages/truncate-tools.d.ts +12 -0
  139. package/dist/lib/messages/truncate-tools.d.ts.map +1 -0
  140. package/dist/lib/messages/utils.d.ts +30 -0
  141. package/dist/lib/messages/utils.d.ts.map +1 -0
  142. package/dist/lib/prompts/compress-range.d.ts +10 -0
  143. package/dist/lib/prompts/compress-range.d.ts.map +1 -0
  144. package/dist/lib/prompts/context-limit-nudge.d.ts +8 -0
  145. package/dist/lib/prompts/context-limit-nudge.d.ts.map +1 -0
  146. package/dist/lib/prompts/extensions/nudge.d.ts +16 -0
  147. package/dist/lib/prompts/extensions/nudge.d.ts.map +1 -0
  148. package/dist/lib/prompts/extensions/system.d.ts +4 -0
  149. package/dist/lib/prompts/extensions/system.d.ts.map +1 -0
  150. package/dist/lib/prompts/extensions/tool.d.ts +3 -0
  151. package/dist/lib/prompts/extensions/tool.d.ts.map +1 -0
  152. package/dist/lib/prompts/index.d.ts +4 -0
  153. package/dist/lib/prompts/index.d.ts.map +1 -0
  154. package/dist/lib/prompts/iteration-nudge.d.ts +7 -0
  155. package/dist/lib/prompts/iteration-nudge.d.ts.map +1 -0
  156. package/dist/lib/prompts/store.d.ts +25 -0
  157. package/dist/lib/prompts/store.d.ts.map +1 -0
  158. package/dist/lib/prompts/system.d.ts +11 -0
  159. package/dist/lib/prompts/system.d.ts.map +1 -0
  160. package/dist/lib/prompts/turn-nudge.d.ts +7 -0
  161. package/dist/lib/prompts/turn-nudge.d.ts.map +1 -0
  162. package/dist/lib/protected-patterns.d.ts +5 -0
  163. package/dist/lib/protected-patterns.d.ts.map +1 -0
  164. package/dist/lib/state/index.d.ts +6 -0
  165. package/dist/lib/state/index.d.ts.map +1 -0
  166. package/dist/lib/state/message-types.d.ts +90 -0
  167. package/dist/lib/state/message-types.d.ts.map +1 -0
  168. package/dist/lib/state/model-limits.d.ts +27 -0
  169. package/dist/lib/state/model-limits.d.ts.map +1 -0
  170. package/dist/lib/state/persistence.d.ts +93 -0
  171. package/dist/lib/state/persistence.d.ts.map +1 -0
  172. package/dist/lib/state/rebuild.d.ts +40 -0
  173. package/dist/lib/state/rebuild.d.ts.map +1 -0
  174. package/dist/lib/state/state.d.ts +36 -0
  175. package/dist/lib/state/state.d.ts.map +1 -0
  176. package/dist/lib/state/tool-cache.d.ts +13 -0
  177. package/dist/lib/state/tool-cache.d.ts.map +1 -0
  178. package/dist/lib/state/types.d.ts +221 -0
  179. package/dist/lib/state/types.d.ts.map +1 -0
  180. package/dist/lib/state/utils.d.ts +57 -0
  181. package/dist/lib/state/utils.d.ts.map +1 -0
  182. package/dist/lib/token-utils.d.ts +42 -0
  183. package/dist/lib/token-utils.d.ts.map +1 -0
  184. package/dist/lib/ui/notification.d.ts +13 -0
  185. package/dist/lib/ui/notification.d.ts.map +1 -0
  186. package/dist/lib/ui/utils.d.ts +6 -0
  187. package/dist/lib/ui/utils.d.ts.map +1 -0
  188. package/dist/lib/update.d.ts +24 -0
  189. package/dist/lib/update.d.ts.map +1 -0
  190. package/dist/lib/v2/messages.d.ts +7 -0
  191. package/dist/lib/v2/messages.d.ts.map +1 -0
  192. package/dist/lib/v2/plugin.d.ts +3 -0
  193. package/dist/lib/v2/plugin.d.ts.map +1 -0
  194. package/package.json +76 -5
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Message Filter — pluggable system for stripping/deduplicating third-party
3
+ * plugin injections (OMO system-reminders, background task notifications, etc.)
4
+ * from the visible context before ACP processes them.
5
+ *
6
+ * Filters run BEFORE assignMessageRefs, so filtered content never gets message
7
+ * refs and is never counted toward context usage or compression triggers.
8
+ */
9
+ /**
10
+ * Context passed to each registered filter for a single text part.
11
+ */
12
+ export interface MessageFilterContext {
13
+ /** The text content of this part. */
14
+ text: string;
15
+ /** Role of the containing message ("user" | "assistant" | "system"). */
16
+ role: string;
17
+ /** Session ID (may be empty for ephemeral state). */
18
+ sessionId: string;
19
+ /** Whether this is a subagent session. */
20
+ isSubAgent: boolean;
21
+ /** 0-based index of this message in the visible messages array. */
22
+ messageIndex: number;
23
+ /** Total number of visible messages. */
24
+ totalMessages: number;
25
+ /** Tool name if this part is a tool call (e.g. "bash", "read"). */
26
+ toolName?: string;
27
+ /** Model context limit (for threshold-based filtering). */
28
+ modelContextLimit?: number;
29
+ }
30
+ /**
31
+ * Result returned by a filter for a single text part.
32
+ */
33
+ export interface FilterResult {
34
+ /** What to do with this text part. */
35
+ action: "keep" | "modify" | "drop";
36
+ /** Replacement text when action is "modify". Ignored for "keep" and "drop". */
37
+ text?: string;
38
+ /** Human-readable reason for logging/auditing. */
39
+ reason?: string;
40
+ }
41
+ /**
42
+ * A pluggable message filter. Filters are registered via {@link registerMessageFilter}
43
+ * and called by {@link applyMessageFilters} during the message transform pipeline.
44
+ *
45
+ * Filters MUST be pure and side-effect-free: they receive a snapshot of the
46
+ * text and return a decision. They MUST NOT mutate the input context.
47
+ *
48
+ * If a filter returns "drop", the text part is emptied (set to ""). If ALL
49
+ * text parts in a message become empty after filtering, the message itself
50
+ * is not removed (ACP's existing dropEmptyMessages handles that downstream).
51
+ */
52
+ export interface MessageFilter {
53
+ /** Unique name (used in config to enable/disable). */
54
+ name: string;
55
+ /** Semver version (for breaking-change detection). */
56
+ version: string;
57
+ /** Human-readable description. */
58
+ description: string;
59
+ /**
60
+ * Evaluate whether to keep, modify, or drop this text part.
61
+ * Called once per text part per message.
62
+ */
63
+ filter(ctx: MessageFilterContext): FilterResult;
64
+ /**
65
+ * When true, applyMessageFilters keeps only the most recent N matching
66
+ * messages and drops all earlier matches. Useful for repeating directives
67
+ * (e.g., TODO CONTINUATION) where only the latest is relevant.
68
+ * The filter() function still runs per-part to identify matches;
69
+ * the dedup pass then empties earlier occurrences.
70
+ */
71
+ keepLastOnly?: boolean;
72
+ /**
73
+ * How many of the most recent matches to keep when keepLastOnly is true.
74
+ * Default: 1. Set to 2+ to preserve recent notifications (e.g., background
75
+ * task results) while still cleaning up historical accumulation.
76
+ */
77
+ keepLast?: number;
78
+ }
79
+ /**
80
+ * Per-filter configuration: whether the filter is enabled.
81
+ */
82
+ export type MessageFilterConfig = Record<string, {
83
+ enabled: boolean;
84
+ keepLast?: number;
85
+ }>;
86
+ /**
87
+ * Top-level configuration for the message filter subsystem.
88
+ */
89
+ export interface MessageFiltersConfig {
90
+ /** Master switch. When false, no filters run. */
91
+ enabled: boolean;
92
+ /** Per-filter enable/disable. Keys are filter names. */
93
+ filters: MessageFilterConfig;
94
+ }
95
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../lib/messages/filter/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,qCAAqC;IACrC,IAAI,EAAE,MAAM,CAAA;IACZ,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAA;IACZ,qDAAqD;IACrD,SAAS,EAAE,MAAM,CAAA;IACjB,0CAA0C;IAC1C,UAAU,EAAE,OAAO,CAAA;IACnB,mEAAmE;IACnE,YAAY,EAAE,MAAM,CAAA;IACpB,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAA;IACrB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,2DAA2D;IAC3D,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IACzB,sCAAsC;IACtC,MAAM,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAA;IAClC,+EAA+E;IAC/E,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa;IAC1B,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAA;IACZ,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAA;IACf,kCAAkC;IAClC,WAAW,EAAE,MAAM,CAAA;IACnB;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,oBAAoB,GAAG,YAAY,CAAA;IAC/C;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAA;AAEzF;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,iDAAiD;IACjD,OAAO,EAAE,OAAO,CAAA;IAChB,wDAAwD;IACxD,OAAO,EAAE,mBAAmB,CAAA;CAC/B"}
@@ -0,0 +1,9 @@
1
+ export { prune } from "./prune";
2
+ export { syncCompressionBlocks } from "./sync";
3
+ export { injectCompressNudges } from "./inject/inject";
4
+ export { computeInputBudget } from "./inject/utils";
5
+ export { injectMessageIds } from "./inject/inject";
6
+ export { stripStaleMetadata, dropCompressReasoning } from "./reasoning-strip";
7
+ export { buildPriorityMap } from "./priority";
8
+ export { buildToolIdList, stripHallucinations, stripHallucinationsFromString, stripLeakedTrailingRefs, hasContent, dropEmptyMessages, } from "./utils";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/messages/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAA;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAC7E,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EACH,eAAe,EACf,mBAAmB,EACnB,6BAA6B,EAC7B,uBAAuB,EACvB,UAAU,EACV,iBAAiB,GACpB,MAAM,SAAS,CAAA"}
@@ -0,0 +1,30 @@
1
+ import type { PluginConfig } from "../../config";
2
+ import type { SessionState, WithParts } from "../../state";
3
+ export type CompressionCandidateKind = "micro" | "episode";
4
+ export type CandidateOmissionReason = "missing-reference" | "synthetic-or-ignored" | "active-compression" | "protected-tool-or-file" | "recent-protection" | "below-minimum" | "executor-selection-drift" | "executor-rejected";
5
+ export interface CompressionCandidate {
6
+ kind: CompressionCandidateKind;
7
+ startRef: string;
8
+ endRef: string;
9
+ messageCount: number;
10
+ retainedChars: number;
11
+ estimatedTokens: number;
12
+ toolPct: number;
13
+ textPct: number;
14
+ label: string;
15
+ sourceMessageIds: string[];
16
+ }
17
+ export interface CandidateOmission {
18
+ kind: CompressionCandidateKind;
19
+ startRef?: string;
20
+ endRef?: string;
21
+ reason: CandidateOmissionReason;
22
+ }
23
+ export interface CompressionCandidatePlan {
24
+ candidates: CompressionCandidate[];
25
+ omitted: CandidateOmission[];
26
+ truncatedCount: number;
27
+ }
28
+ export declare function planCompressionCandidates(messages: WithParts[], state: SessionState, config: PluginConfig): CompressionCandidatePlan;
29
+ export declare function formatCompressionCandidates(plan: CompressionCandidatePlan): string;
30
+ //# sourceMappingURL=candidates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"candidates.d.ts","sourceRoot":"","sources":["../../../../lib/messages/inject/candidates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAGhD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAS1D,MAAM,MAAM,wBAAwB,GAAG,OAAO,GAAG,SAAS,CAAA;AAE1D,MAAM,MAAM,uBAAuB,GAC7B,mBAAmB,GACnB,sBAAsB,GACtB,oBAAoB,GACpB,wBAAwB,GACxB,mBAAmB,GACnB,eAAe,GACf,0BAA0B,GAC1B,mBAAmB,CAAA;AAEzB,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,wBAAwB,CAAA;IAC9B,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,gBAAgB,EAAE,MAAM,EAAE,CAAA;CAC7B;AAED,MAAM,WAAW,iBAAiB;IAC9B,IAAI,EAAE,wBAAwB,CAAA;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,EAAE,uBAAuB,CAAA;CAClC;AAED,MAAM,WAAW,wBAAwB;IACrC,UAAU,EAAE,oBAAoB,EAAE,CAAA;IAClC,OAAO,EAAE,iBAAiB,EAAE,CAAA;IAC5B,cAAc,EAAE,MAAM,CAAA;CACzB;AAiaD,wBAAgB,yBAAyB,CACrC,QAAQ,EAAE,SAAS,EAAE,EACrB,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,YAAY,GACrB,wBAAwB,CAgF1B;AAED,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,wBAAwB,GAAG,MAAM,CAgBlF"}
@@ -0,0 +1,26 @@
1
+ import type { SessionState, WithParts } from "../../state";
2
+ import type { Logger } from "../../logger";
3
+ import type { PluginConfig } from "../../config";
4
+ import type { RuntimePrompts } from "../../prompts/store";
5
+ import type { CompressionPriorityMap } from "../priority";
6
+ export declare const injectCompressNudges: (state: SessionState, config: PluginConfig, logger: Logger, messages: WithParts[], prompts: RuntimePrompts, compressionPriorities?: CompressionPriorityMap, debugNotify?: (text: string) => void, preCompressTokens?: number, candidateMessages?: WithParts[]) => void;
7
+ export interface VisibleSegment {
8
+ startRef: string;
9
+ endRef: string;
10
+ count: number;
11
+ tokens: number;
12
+ hasTool: boolean;
13
+ }
14
+ /**
15
+ * Build disjoint visible-id segments from the surviving messages.
16
+ *
17
+ * Each segment is a maximal run of contiguous refs (e.g. m00003–m00007).
18
+ * Holes between segments correspond to messages already consumed by a
19
+ * compression block — those refs are NOT safe to target. Surfacing the
20
+ * segments (instead of a single `first–last` span) stops the model from
21
+ * picking a ref that lives inside a compressed hole.
22
+ */
23
+ export declare function buildVisibleSegments(state: SessionState, messages: WithParts[]): VisibleSegment[];
24
+ export declare function formatVisibleGuidance(segments: VisibleSegment[], maxSegs: number): string;
25
+ export declare const injectMessageIds: (state: SessionState, config: PluginConfig, messages: WithParts[], compressionPriorities?: CompressionPriorityMap) => void;
26
+ //# sourceMappingURL=inject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../../../../lib/messages/inject/inject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEzD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAkFzD,eAAO,MAAM,oBAAoB,GAC7B,OAAO,YAAY,EACnB,QAAQ,YAAY,EACpB,QAAQ,MAAM,EACd,UAAU,SAAS,EAAE,EACrB,SAAS,cAAc,EACvB,wBAAwB,sBAAsB,EAC9C,cAAc,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,EACpC,oBAAoB,MAAM,EAC1B,oBAAoB,SAAS,EAAE,KAChC,IA0zBF,CAAA;AAgBD,MAAM,WAAW,cAAc;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,OAAO,CAAA;CACnB;AAOD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,cAAc,EAAE,CA6CjG;AAMD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAwBzF;AAuBD,eAAO,MAAM,gBAAgB,GACzB,OAAO,YAAY,EACnB,QAAQ,YAAY,EACpB,UAAU,SAAS,EAAE,EACrB,wBAAwB,sBAAsB,KAC/C,IAiEF,CAAA"}
@@ -0,0 +1,5 @@
1
+ export declare function ensureBuiltinTriggerPolicyRegistered(): void;
2
+ export type { TipsVariant, NudgeDecision, NudgeDecisionInput, CompressionTriggerPolicy, } from "./types";
3
+ export { registerTriggerPolicy, getTriggerPolicy, listTriggerPolicies, getDefaultTriggerPolicy, setDefaultTriggerPolicy, clearTriggerPolicyRegistryForTests, } from "./registry";
4
+ export { defaultTriggerPolicy } from "context-compress-algorithms/trigger";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../lib/messages/inject/policy/index.ts"],"names":[],"mappings":"AAGA,wBAAgB,oCAAoC,IAAI,IAAI,CAE3D;AAED,YAAY,EACR,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,wBAAwB,GAC3B,MAAM,SAAS,CAAA;AAChB,OAAO,EACH,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,kCAAkC,GACrC,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { CompressionTriggerPolicy } from "./types";
2
+ export declare function registerTriggerPolicy(policy: CompressionTriggerPolicy): void;
3
+ export declare function getTriggerPolicy(name: string): CompressionTriggerPolicy | undefined;
4
+ export declare function listTriggerPolicies(): string[];
5
+ export declare function getDefaultTriggerPolicy(): CompressionTriggerPolicy | null;
6
+ export declare function setDefaultTriggerPolicy(name: string): boolean;
7
+ export declare function clearTriggerPolicyRegistryForTests(): void;
8
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../../../../lib/messages/inject/policy/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAkD,MAAM,SAAS,CAAA;AAKvG,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,CAQ5E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAEnF;AAED,wBAAgB,mBAAmB,IAAI,MAAM,EAAE,CAE9C;AAED,wBAAgB,uBAAuB,IAAI,wBAAwB,GAAG,IAAI,CAEzE;AAED,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAK7D;AAED,wBAAgB,kCAAkC,IAAI,IAAI,CAGzD"}
@@ -0,0 +1,2 @@
1
+ export type { TipsVariant, NudgeDecision, NudgeDecisionInput, CompressionTriggerPolicy, } from "context-compress-algorithms/trigger";
2
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../lib/messages/inject/policy/types.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,wBAAwB,GAC3B,MAAM,qCAAqC,CAAA"}
@@ -0,0 +1,235 @@
1
+ import type { SessionState, WithParts } from "../../state";
2
+ import type { PluginConfig, CompressModelOverrides } from "../../config";
3
+ import type { RuntimePrompts } from "../../prompts/store";
4
+ import { type CompressionPriorityMap } from "../priority";
5
+ export interface LastUserModelContext {
6
+ providerId: string | undefined;
7
+ modelId: string | undefined;
8
+ }
9
+ export interface LastNonIgnoredMessage {
10
+ message: WithParts;
11
+ index: number;
12
+ }
13
+ interface ModelLimit {
14
+ context: number;
15
+ input?: number;
16
+ output?: number;
17
+ }
18
+ export declare function computeInputBudget(limit: ModelLimit): number | undefined;
19
+ export declare function getNudgeFrequency(config: PluginConfig): number;
20
+ export declare function getIterationNudgeThreshold(config: PluginConfig): number;
21
+ export declare function findLastNonIgnoredMessage(messages: WithParts[]): LastNonIgnoredMessage | null;
22
+ export declare function countMessagesAfterIndex(messages: WithParts[], index: number): number;
23
+ export declare function getModelInfo(messages: WithParts[]): LastUserModelContext;
24
+ export declare function resolveContextTokenLimit(config: PluginConfig, state: SessionState, providerId: string | undefined, modelId: string | undefined, threshold: "max" | "min"): number | undefined;
25
+ export declare function isContextOverLimits(config: PluginConfig, state: SessionState, providerId: string | undefined, modelId: string | undefined, messages: WithParts[]): {
26
+ overMaxLimit: boolean;
27
+ overMinLimit: boolean;
28
+ currentTokens: number;
29
+ modelContextLimit: number | undefined;
30
+ };
31
+ export type TipsVariant = "maxLimit" | "minLimit" | "normal";
32
+ export interface NudgeDecision {
33
+ shouldNudge: boolean;
34
+ tipsVariant: TipsVariant | null;
35
+ }
36
+ export declare function computeShouldNudge(params: {
37
+ currentTokens: number | undefined;
38
+ modelContextLimit: number | undefined;
39
+ overMinLimit: boolean;
40
+ overMaxLimit: boolean;
41
+ lastNudgeTokens: number | undefined;
42
+ /** Passed through to the trigger policy (currently ignored by it). The growth-nudge floor derived from this field is computed separately in inject.ts (minNudgeContextPercent × model context). */
43
+ minNudgeContextPercent: number;
44
+ nudgeGrowthTokens: number;
45
+ }): NudgeDecision;
46
+ export declare const DEFAULT_NUDGE_GROWTH_TOKENS = 50000;
47
+ /** Default growth-nudge floor percent when unset everywhere (#343: deliberately low — see inject.ts rationale). */
48
+ export declare const DEFAULT_MIN_NUDGE_CONTEXT_PERCENT = 5;
49
+ /**
50
+ * Resolve the effective growth-nudge floor percent for the active model,
51
+ * cascading field-by-field:
52
+ *
53
+ * compress.providers[providerId].models[modelId].minNudgeContextPercent
54
+ * → compress.providers[providerId].minNudgeContextPercent
55
+ * → compress.minNudgeContextPercent
56
+ *
57
+ * - Deeper levels only override when the field is explicitly set; unset
58
+ * fields never clear shallower values.
59
+ * - 0 is an explicit "disable the floor" value, not "unset".
60
+ * - Unknown provider/model ids fall back up the cascade.
61
+ * - Returns undefined only when the field is unset everywhere (callers apply
62
+ * DEFAULT_MIN_NUDGE_CONTEXT_PERCENT).
63
+ */
64
+ /**
65
+ * Resolve the full per-model / per-provider override set for the active
66
+ * provider/model, merged field-by-field: model-level fields win over
67
+ * provider-level fields. Unset fields are simply absent from the result —
68
+ * they never clear the global value. `0` / `false`-style explicit values are
69
+ * honored as set (only `undefined` means "unset"). Unknown provider/model
70
+ * ids resolve to an empty override set (global values apply).
71
+ *
72
+ * The `models` sub-map of a provider entry is structural and never leaks
73
+ * into the merged result.
74
+ */
75
+ export declare function resolveCompressOverrides(config: PluginConfig, providerId?: string, modelId?: string): CompressModelOverrides;
76
+ export declare function resolveMinNudgeContextPercent(config: PluginConfig, providerId?: string, modelId?: string): number | undefined;
77
+ /**
78
+ * Convert the resolved floor percent to absolute tokens against the active
79
+ * model's context window. The percent is clamped to 0–100 (mirroring
80
+ * resolveContextTokenLimit) and rounded. Returns undefined when the model
81
+ * context limit is unknown — whichever level set the percent, the floor then
82
+ * stays open (growth-only behavior, #343).
83
+ */
84
+ export declare function resolveMinNudgeFloorTokens(config: PluginConfig, modelContextLimit: number | undefined, providerId?: string, modelId?: string): number | undefined;
85
+ /**
86
+ * Build the effective PluginConfig for the active provider/model: a shallow
87
+ * clone whose `compress` section has every nested override (model > provider)
88
+ * applied field-by-field on top of the global values. Callers pass the result
89
+ * down instead of the raw config, so every `config.compress.X` read in the
90
+ * pipeline picks up the cascade automatically. No override set → returns the
91
+ * input unchanged (identity, zero allocation).
92
+ */
93
+ export declare function applyCompressOverrides(config: PluginConfig, providerId?: string, modelId?: string): PluginConfig;
94
+ export declare function addAnchor(anchorMessageIds: Set<string>, anchorMessageId: string, anchorMessageIndex: number, messages: WithParts[], interval: number): boolean;
95
+ export declare function applyAnchoredNudges(state: SessionState, config: PluginConfig, messages: WithParts[], prompts: RuntimePrompts, compressionPriorities?: CompressionPriorityMap, currentTokens?: number, modelContextLimit?: number, suffixMessage?: WithParts | null): void;
96
+ export interface ContextComposition {
97
+ toolTokens: number;
98
+ codeTokens: number;
99
+ summaryTokens: number;
100
+ messageTokens: number;
101
+ textTokens: number;
102
+ systemTokens: number;
103
+ protectedTokens: number;
104
+ reasoningTokens: number;
105
+ total: number;
106
+ largestRanges: {
107
+ ref: string;
108
+ tokens: number;
109
+ }[];
110
+ largestToolRanges: {
111
+ ref: string;
112
+ tokens: number;
113
+ tool?: string;
114
+ }[];
115
+ largestCodeRanges: {
116
+ ref: string;
117
+ tokens: number;
118
+ }[];
119
+ largestMessageRanges: {
120
+ ref: string;
121
+ tokens: number;
122
+ }[];
123
+ toolTypeBreakdown: {
124
+ tool: string;
125
+ tokens: number;
126
+ }[];
127
+ }
128
+ export declare function estimateContextComposition(messages: WithParts[], state?: SessionState, protectedTools?: string[], protectedFilePatterns?: string[]): ContextComposition;
129
+ export interface CompressibleRange {
130
+ startRef: string;
131
+ endRef: string;
132
+ count: number;
133
+ tokens: number;
134
+ /**
135
+ * Tokens that would actually survive the compress pipeline's soft
136
+ * filters (last-user-message, no-meaningful-content). The pipeline
137
+ * silently drops those messages from plans, so `tokens` overstates
138
+ * what a compression would free. Recommendations and displays use
139
+ * this field to stay honest (phantom-loop fix, issue #37 session
140
+ * ses_7fb5cbc8: ranges shown as "10.8K compressible" resolved to
141
+ * 3066 chars in the pipeline → min-size rejection → retry loop).
142
+ */
143
+ effectiveTokens: number;
144
+ toolPct: number;
145
+ textPct: number;
146
+ dangerous?: boolean;
147
+ }
148
+ export interface ProtectedRange {
149
+ startRef: string;
150
+ endRef: string;
151
+ count: number;
152
+ tokens: number;
153
+ tools: string[];
154
+ }
155
+ export interface ContextRanges {
156
+ compressible: CompressibleRange[];
157
+ protected: ProtectedRange[];
158
+ }
159
+ export declare function buildCompressibleRanges(messages: WithParts[], state: SessionState, protectedTools?: string[], protectedFilePatterns?: string[], protectedZoneRefs?: Set<string>): ContextRanges;
160
+ export interface RangeFilterOptions {
161
+ logger?: {
162
+ debug: (msg: string, data?: any) => void;
163
+ };
164
+ minEffectiveTokens?: number;
165
+ }
166
+ /**
167
+ * DEFAULT token floor for a range to stay in the recommendation list, aligned
168
+ * with the compress pipeline's default minCompressRange (5000 chars ÷ 4
169
+ * chars/token). The actual floor is derived from the configured
170
+ * `compress.minCompressRange` via `resolveEffectiveFloor` so the recommendation
171
+ * tracks the pipeline's real rejection threshold. Ranges whose effective
172
+ * compressible content falls below the floor would be rejected by the
173
+ * pipeline's minimum-size check, so recommending them only invites
174
+ * guaranteed-failed compress calls (the retry loop observed in issue #37
175
+ * session ses_7fb5cbc8: displayed "10.8K compressible" resolved to 3066 chars
176
+ * in the pipeline → rejected → model retried ×10).
177
+ */
178
+ export declare const EFFECTIVE_MIN_COMPRESSIBLE_TOKENS = 1250;
179
+ /**
180
+ * Derive the effective-token recommendation floor from the pipeline's
181
+ * char-based `compress.minCompressRange` (÷ 4 chars/token). When
182
+ * minCompressRange is 0 the pipeline's size check is disabled, so the floor
183
+ * is 0 — but the universal phantom guard (`effective > 0`) still applies in
184
+ * filterRecommendedRanges: a range whose every message is soft-filtered
185
+ * produces a phantom plan the pipeline always rejects.
186
+ */
187
+ export declare function resolveEffectiveFloor(config: {
188
+ compress?: {
189
+ minCompressRange?: number;
190
+ };
191
+ }): number;
192
+ /**
193
+ * Filter compressible ranges for the recommendation list.
194
+ *
195
+ * Ranges whose effective compressible content (after the pipeline's soft
196
+ * filters: last-user-message, no-meaningful-content) falls below
197
+ * EFFECTIVE_MIN_COMPRESSIBLE_TOKENS are dropped — the pipeline's
198
+ * minCompressRange check would reject them anyway. The last surviving
199
+ * segment is marked `dangerous: true` (it may still be in active use).
200
+ *
201
+ * Issue #251: Previously this function used `growthThreshold` (5% of context
202
+ * window = 50K at 1M) as an aggregate gate — if "effective compressible"
203
+ * was below the threshold, ALL ranges were suppressed and the nudge was
204
+ * hidden. At large context windows, individual ranges rarely exceeded this
205
+ * threshold, so compression was permanently blocked. The aggregate gate
206
+ * has been removed. The per-range effective floor below is 1250 tokens —
207
+ * far below #251's 50K, and matched to the pipeline's own acceptance
208
+ * criteria rather than the context size.
209
+ */
210
+ export declare function filterRecommendedRanges(compressible: CompressibleRange[], _protectedRanges: ProtectedRange[], options: RangeFilterOptions): CompressibleRange[];
211
+ export declare function formatCompressibleRanges(ranges: CompressibleRange[], protectedRanges?: ProtectedRange[]): string;
212
+ /**
213
+ * Compute the set of protected message refs (mNNNNN) that should be excluded
214
+ * from compression recommendations. Combines two rules:
215
+ * 1. Last N messages (preserveRecentMessages, default 5)
216
+ * 2. Last N tokens expanding backward (preserveRecentTokens, default 5000)
217
+ *
218
+ * Note: preserveLastUserMessage is no longer handled here (moved to soft
219
+ * filtering in the compress pipeline — see filterLastUserMessage). The last
220
+ * user message is filtered from the compress plan instead of causing a hard
221
+ * rejection.
222
+ *
223
+ * Only considers visible, non-synthetic, non-pruned messages.
224
+ */
225
+ export declare function computeProtectedRefs(messages: WithParts[], state: SessionState, compress: PluginConfig["compress"]): Set<string>;
226
+ /**
227
+ * Filter compressible ranges to exclude those overlapping the protected zone.
228
+ * Since the protected zone is always at the tail of the conversation, a range
229
+ * whose startRef or endRef is protected is partially or fully within the zone.
230
+ * Compressing such a range would either be rejected by the enforcement check
231
+ * or waste model effort — exclude it preemptively.
232
+ */
233
+ export declare function excludeProtectedRanges(ranges: CompressibleRange[], protectedRefs: Set<string>): CompressibleRange[];
234
+ export {};
235
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../lib/messages/inject/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAkB,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAYxF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEzD,OAAO,EACH,KAAK,sBAAsB,EAG9B,MAAM,aAAa,CAAA;AAepB,MAAM,WAAW,oBAAoB;IACjC,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;CAC9B;AAED,MAAM,WAAW,qBAAqB;IAClC,OAAO,EAAE,SAAS,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;CAChB;AAED,UAAU,UAAU;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAMxE;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAE9D;AAED,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAEvE;AAED,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,qBAAqB,GAAG,IAAI,CAa7F;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAYpF;AAED,wBAAgB,YAAY,CAAC,QAAQ,EAAE,SAAS,EAA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AAa,EAAE,GAAG,CAAC,MAAM,CAAC,GAC3B,iBAAiB,EAAE,CAGrB"}
@@ -0,0 +1,13 @@
1
+ import type { PluginConfig } from "../config";
2
+ import type { SessionState, WithParts } from "../state";
3
+ export type MessagePriority = "low" | "medium" | "high";
4
+ export interface CompressionPriorityEntry {
5
+ ref: string;
6
+ tokenCount: number;
7
+ priority: MessagePriority;
8
+ }
9
+ export type CompressionPriorityMap = Map<string, CompressionPriorityEntry>;
10
+ export declare function buildPriorityMap(_config: PluginConfig, _state: SessionState, _messages: WithParts[]): CompressionPriorityMap;
11
+ export declare function classifyMessagePriority(tokenCount: number): MessagePriority;
12
+ export declare function listPriorityRefsBeforeIndex(messages: WithParts[], priorities: CompressionPriorityMap, anchorIndex: number, priority: MessagePriority): string[];
13
+ //# sourceMappingURL=priority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"priority.d.ts","sourceRoot":"","sources":["../../../lib/messages/priority.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAKvD,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAA;AAEvD,MAAM,WAAW,wBAAwB;IACrC,GAAG,EAAE,MAAM,CAAA;IACX,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,eAAe,CAAA;CAC5B;AAED,MAAM,MAAM,sBAAsB,GAAG,GAAG,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAA;AAE1E,wBAAgB,gBAAgB,CAC5B,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,SAAS,EAAE,GACvB,sBAAsB,CAExB;AAED,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,CAU3E;AAED,wBAAgB,2BAA2B,CACvC,QAAQ,EAAE,SAAS,EAAE,EACrB,UAAU,EAAE,sBAAsB,EAClC,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,eAAe,GAC1B,MAAM,EAAE,CAqBV"}
@@ -0,0 +1,5 @@
1
+ import type { SessionState, WithParts } from "../state";
2
+ import type { Logger } from "../logger";
3
+ import type { PluginConfig } from "../config";
4
+ export declare const prune: (state: SessionState, logger: Logger, config: PluginConfig, messages: WithParts[]) => void;
5
+ //# sourceMappingURL=prune.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prune.d.ts","sourceRoot":"","sources":["../../../lib/messages/prune.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAE7C,eAAO,MAAM,KAAK,GACd,OAAO,YAAY,EACnB,QAAQ,MAAM,EACd,QAAQ,YAAY,EACpB,UAAU,SAAS,EAAE,KACtB,IAGF,CAAA"}
@@ -0,0 +1,36 @@
1
+ import type { PluginConfig } from "../config";
2
+ import type { WithParts } from "../state";
3
+ export declare function isSyntheticMessage(message: WithParts): boolean;
4
+ export declare const getLastUserMessage: (messages: WithParts[], startIndex?: number) => WithParts | null;
5
+ export declare const messageHasCompress: (message: WithParts) => boolean;
6
+ /**
7
+ * Detects ANY compress tool call — including failed/rejected ones.
8
+ *
9
+ * Used for nudge state management: a failed compress attempt means the model
10
+ * DID respond to the nudge (it tried to compress), so the pending-nudge state
11
+ * should be cleared. Without this, the threshold stays permanently halved
12
+ * after a rejected compress, creating a self-accelerating nudge loop.
13
+ *
14
+ * For priority/state queries that only care about SUCCESSFUL compressions
15
+ * (e.g. message priority classification), use `messageHasCompress` instead.
16
+ */
17
+ export declare const messageHasCompressAttempt: (message: WithParts) => boolean;
18
+ /**
19
+ * Classifies a compress tool call by its range boundaries to detect whether it is
20
+ * a raw-message capture (T1) or a summary distillation/condensation (T2/T3).
21
+ *
22
+ * Returns `true` ONLY when the call is positively identified as a T1 capture: at
23
+ * least one range boundary is present and NONE of them is a block ref (`bN`). A
24
+ * block-ref boundary means the call consumes existing summaries (T2/T3); those
25
+ * must keep resetting the tier cadence baselines to prevent re-trigger loops
26
+ * (issue #235). A pure message capture (`mNNNNN` boundaries) only ADDS tier-1
27
+ * summaries, so resetting the baselines after every capture is what starves T2
28
+ * distillation (issue #364 P1) — callers skip the reset for these.
29
+ *
30
+ * Returns `false` when any boundary is a block ref OR when no parsable boundary
31
+ * is found (conservative: preserve the loop-prevention reset).
32
+ */
33
+ export declare const isCaptureOnlyCompress: (message: WithParts | undefined) => boolean;
34
+ export declare const isIgnoredUserMessage: (message: WithParts) => boolean;
35
+ export declare function isProtectedUserMessage(_config: PluginConfig, message: WithParts): boolean;
36
+ //# sourceMappingURL=query.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../lib/messages/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,SAAS,GAAG,OAAO,CAQ9D;AAED,eAAO,MAAM,kBAAkB,GAC3B,UAAU,SAAS,EAAE,EACrB,aAAa,MAAM,KACpB,SAAS,GAAG,IAYd,CAAA;AAED,eAAO,MAAM,kBAAkB,GAAI,SAAS,SAAS,KAAG,OAgBvD,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,GAAI,SAAS,SAAS,KAAG,OAW9D,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,GAAI,SAAS,SAAS,GAAG,SAAS,KAAG,OAuBtE,CAAA;AAqCD,eAAO,MAAM,oBAAoB,GAAI,SAAS,SAAS,KAAG,OAqBzD,CAAA;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,SAAS,GAAG,OAAO,CAMzF"}
@@ -0,0 +1,32 @@
1
+ import type { WithParts } from "../state";
2
+ /**
3
+ * Mirrors opencode's differentModel handling by preserving part content while
4
+ * dropping provider metadata on assistant parts that came from a different
5
+ * model/provider than the current turn's user message.
6
+ */
7
+ export declare function stripStaleMetadata(messages: WithParts[]): void;
8
+ /**
9
+ * Drop `reasoning` parts from HISTORICAL `compress` tool-call messages (#368).
10
+ *
11
+ * `compress` tool-call messages are hard-excluded from every compression
12
+ * selection (Bug 39) and therefore re-sent every request, with their
13
+ * `reasoning` riding along — a monotonically growing floor that compression
14
+ * can never reclaim. This request-time pass removes ONLY the `reasoning`
15
+ * parts from such messages when BOTH gates hold:
16
+ *
17
+ * 1. turn-closure: the message is strictly before the last genuine user
18
+ * message. The current, possibly-open round is never touched — providers
19
+ * may require replaying the active round's thinking.
20
+ * 2. per-message size: the message's total reasoning length EXCEEDS
21
+ * `threshold` chars (owner decision: single-thinking size — small
22
+ * thinkings are left alone; only oversized ones are dropped; not
23
+ * accumulated). `threshold: 0` drops unconditionally.
24
+ *
25
+ * The tool call and every non-reasoning part are preserved. Only messages
26
+ * carrying a `compress` tool part are selected (NOT other protected tools).
27
+ * No state/DB writes; deterministic (prefix-cache-stable within a turn).
28
+ *
29
+ * @returns the number of `reasoning` parts removed.
30
+ */
31
+ export declare function dropCompressReasoning(messages: WithParts[], threshold: number): number;
32
+ //# sourceMappingURL=reasoning-strip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reasoning-strip.d.ts","sourceRoot":"","sources":["../../../lib/messages/reasoning-strip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAGzC;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAkC9D;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAiDtF"}
@@ -0,0 +1,5 @@
1
+ import type { WithParts } from "../state";
2
+ export declare function isMessageWithInfo(message: unknown): message is WithParts;
3
+ export declare function filterMessages(messages: unknown): WithParts[];
4
+ export declare function filterMessagesInPlace(messages: unknown): WithParts[];
5
+ //# sourceMappingURL=shape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shape.d.ts","sourceRoot":"","sources":["../../../lib/messages/shape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEzC,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,IAAI,SAAS,CAsBxE;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,CAM7D;AAED,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,EAAE,CAepE"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * [Issue #485] Sticky emergency truncation.
3
+ *
4
+ * The emergency guards (`truncateLargeToolOutputs` + `enforceContextBudget`)
5
+ * operate on a fresh pristine copy of `output.messages` every request and
6
+ * gate on the LAST assistant's reported usage — which reflects the
7
+ * *truncated* request, not the pristine one. A session hovering at the guard
8
+ * threshold therefore oscillates: truncate (A→B) → smaller usage → no
9
+ * truncation next request (full A restored) → cache miss → over budget
10
+ * again. Every flip invalidates the provider prefix cache from that message
11
+ * onward, and with opencode auto-retrying on a busy backend the churn can
12
+ * take down the serving cluster.
13
+ *
14
+ * Stickiness makes the guard decision one-way: the first time a guard
15
+ * truncates (or clears) a tool output, the result is frozen in
16
+ * `state.stickyTruncations` keyed by tool call ID and replayed verbatim on
17
+ * every later request BEFORE the guards run. A→B→B→B — the truncated form
18
+ * never grows back. The full content stays in the session store (and on
19
+ * disk), so nothing is lost; the wire view is simply stable.
20
+ */
21
+ import type { Logger } from "../logger";
22
+ import type { SessionState, WithParts } from "../state";
23
+ /**
24
+ * Replay frozen truncations onto the request copy, and prune entries whose
25
+ * call no longer exists in the projected view.
26
+ *
27
+ * [#485 review] Prune-on-vanish is intentionally coarse: a call absent from
28
+ * ONE request's projected view (content-based filter, mid-abort partial
29
+ * fetch) is treated like a deleted call and unfrozen. That is self-healing —
30
+ * if the call reappears pristine and a guard truncates it again, the new
31
+ * form is re-frozen — at the cost of a single pristine flip in that rare
32
+ * window.
33
+ *
34
+ * [#485 review] Replayed values are wire-only. If a provider legitimately
35
+ * reuses a callID for genuinely new output (not observed), the replay would
36
+ * mask the new content on the wire until the entry is pruned; the session
37
+ * store always keeps the authoritative full output.
38
+ */
39
+ export declare function applyStickyTruncations(state: SessionState, messages: WithParts[], logger: Logger): void;
40
+ /**
41
+ * Snapshot callID → output for every completed tool part. Non-string
42
+ * outputs are stringified via `extractCompletedToolOutput` — the same
43
+ * normalization the guards use before truncating — so a guard turning an
44
+ * object output into a truncated string is detected as a change and frozen.
45
+ */
46
+ export declare function snapshotToolOutputs(messages: WithParts[]): Map<string, string>;
47
+ /**
48
+ * Freeze any output the guards changed since `before`: a changed output is
49
+ * either a fresh truncation or a phase-2 clear — both must stick. Returns
50
+ * the number of entries frozen so the caller can persist immediately
51
+ * (every other save trigger in the transform hook fires EARLIER, so a quiet
52
+ * session would otherwise reach disk only via an unrelated later save).
53
+ */
54
+ export declare function recordStickyTruncations(state: SessionState, messages: WithParts[], before: Map<string, string>, logger: Logger): number;
55
+ //# sourceMappingURL=sticky-truncation.d.ts.map