@ftrdotdev/pi-tracker 0.5.1 → 0.6.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.
@@ -0,0 +1,259 @@
1
+ import { assert, it } from "@effect/vitest";
2
+ import { Effect, Option, PlatformError } from "effect";
3
+ import * as FileSystem from "effect/FileSystem";
4
+ import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
5
+ import { fileURLToPath } from "node:url";
6
+ import {
7
+ CLASSIFIER_KEY,
8
+ DEFAULT_MAX_CANDIDATES,
9
+ ENABLED_KEY,
10
+ KEEP_CONTEXT_MIN_CONFIDENCE_KEY,
11
+ KEEP_CONTEXT_THRESHOLD_KEY,
12
+ MAX_CANDIDATES_KEY,
13
+ SMART_COMPACTION_KEY,
14
+ SmartCompactionSettingsService,
15
+ parseClassifierIdentity,
16
+ type SmartCompactionSettings,
17
+ } from "./settings.ts";
18
+ import { DEFAULT_KEEP_CONTEXT_MIN_CONFIDENCE, DEFAULT_KEEP_CONTEXT_THRESHOLD } from "./classifier.ts";
19
+
20
+ const TEST_PATH = "/tmp/tracker-settings-test/tui.json";
21
+ const FIXTURE_PATH = fileURLToPath(
22
+ new URL("../../test-fixtures/tui-config.contract.json", import.meta.url),
23
+ );
24
+
25
+ /** Read the shared contract fixture through the FileSystem service. */
26
+ const readFixture: Effect.Effect<string, PlatformError.PlatformError> = Effect.gen(function* () {
27
+ const fs = yield* FileSystem.FileSystem;
28
+ return yield* fs.readFileString(FIXTURE_PATH);
29
+ }).pipe(Effect.provide(NodeFileSystem.layer));
30
+
31
+ interface MemFs {
32
+ readonly fs: Partial<FileSystem.FileSystem>;
33
+ readonly files: Map<string, string>;
34
+ readonly writes: string[];
35
+ }
36
+
37
+ function makeMemFs(init: Record<string, string> = {}): MemFs {
38
+ const files = new Map<string, string>(Object.entries(init));
39
+ const writes: string[] = [];
40
+
41
+ const fs: Partial<FileSystem.FileSystem> = {
42
+ readFileString: (path) =>
43
+ files.has(path)
44
+ ? Effect.succeed(files.get(path)!)
45
+ : Effect.fail(
46
+ PlatformError.systemError({
47
+ _tag: "NotFound",
48
+ module: "FileSystem",
49
+ method: "readFileString",
50
+ pathOrDescriptor: path,
51
+ description: "No such file",
52
+ }),
53
+ ),
54
+ writeFileString: (path, data) =>
55
+ Effect.sync(() => {
56
+ writes.push(path);
57
+ files.set(path, data);
58
+ }),
59
+ };
60
+
61
+ return { fs, files, writes };
62
+ }
63
+
64
+ const load = (): Effect.Effect<
65
+ SmartCompactionSettings,
66
+ never,
67
+ SmartCompactionSettingsService
68
+ > =>
69
+ Effect.gen(function* () {
70
+ const service = yield* SmartCompactionSettingsService;
71
+ return yield* service.load;
72
+ });
73
+
74
+ const runWithMem = <A, E>(
75
+ mem: MemFs,
76
+ program: Effect.Effect<A, E, SmartCompactionSettingsService>,
77
+ ): Effect.Effect<A, E> =>
78
+ program.pipe(Effect.provide(SmartCompactionSettingsService.layerTest(TEST_PATH, mem.fs)));
79
+
80
+ it.effect("load returns the fail-open defaults when the file is missing", () =>
81
+ Effect.gen(function* () {
82
+ const mem = makeMemFs();
83
+ const settings = yield* runWithMem(mem, load());
84
+ assert.strictEqual(settings.enabled, true);
85
+ assert.strictEqual(Option.isNone(settings.chosen), true);
86
+ assert.strictEqual(settings.keepContextThreshold, DEFAULT_KEEP_CONTEXT_THRESHOLD);
87
+ }),
88
+ );
89
+
90
+ it.effect("load returns the fail-open defaults when the file is not JSON", () =>
91
+ Effect.gen(function* () {
92
+ const mem = makeMemFs({ [TEST_PATH]: "not json" });
93
+ const settings = yield* runWithMem(mem, load());
94
+ assert.strictEqual(settings.enabled, true);
95
+ assert.strictEqual(Option.isNone(settings.chosen), true);
96
+ assert.strictEqual(settings.keepContextThreshold, DEFAULT_KEEP_CONTEXT_THRESHOLD);
97
+ }),
98
+ );
99
+
100
+ it.effect("load returns the fail-open defaults when the section has the wrong shape", () =>
101
+ Effect.gen(function* () {
102
+ const mem = makeMemFs({ [TEST_PATH]: JSON.stringify({ smartCompaction: "on" }) });
103
+ const settings = yield* runWithMem(mem, load());
104
+ assert.strictEqual(settings.enabled, true);
105
+ assert.strictEqual(Option.isNone(settings.chosen), true);
106
+ assert.strictEqual(settings.keepContextThreshold, DEFAULT_KEEP_CONTEXT_THRESHOLD);
107
+ }),
108
+ );
109
+
110
+ it.effect("load ignores an unrecognized enabled value and keeps a valid chosen classifier", () =>
111
+ Effect.gen(function* () {
112
+ const mem = makeMemFs({
113
+ [TEST_PATH]: JSON.stringify({
114
+ smartCompaction: { enabled: "yes", classifier: "typesafe/jev-latest" },
115
+ }),
116
+ });
117
+ const settings = yield* runWithMem(mem, load());
118
+ assert.strictEqual(settings.enabled, true);
119
+ assert.deepStrictEqual(Option.getOrThrow(settings.chosen), {
120
+ provider: "typesafe",
121
+ modelId: "jev-latest",
122
+ });
123
+ assert.strictEqual(settings.keepContextThreshold, DEFAULT_KEEP_CONTEXT_THRESHOLD);
124
+ }),
125
+ );
126
+
127
+ it.effect("load reads a valid keep-context threshold from the section", () =>
128
+ Effect.gen(function* () {
129
+ const mem = makeMemFs({
130
+ [TEST_PATH]: JSON.stringify({ smartCompaction: { keepContextThreshold: 0.72 } }),
131
+ });
132
+ const settings = yield* runWithMem(mem, load());
133
+ assert.strictEqual(settings.keepContextThreshold, 0.72);
134
+ }),
135
+ );
136
+
137
+ it.effect("load falls back alone when a threshold is outside the open unit interval", () =>
138
+ Effect.gen(function* () {
139
+ for (const invalid of [0, 1, -0.1, 1.5, "0.5"]) {
140
+ const mem = makeMemFs({
141
+ [TEST_PATH]: JSON.stringify({
142
+ smartCompaction: { enabled: false, keepContextThreshold: invalid },
143
+ }),
144
+ });
145
+ const settings = yield* runWithMem(mem, load());
146
+ assert.strictEqual(settings.keepContextThreshold, DEFAULT_KEEP_CONTEXT_THRESHOLD);
147
+ // The bad value must not discard the rest of the section.
148
+ assert.strictEqual(settings.enabled, false);
149
+ }
150
+ }),
151
+ );
152
+
153
+ it.effect("load reads a valid keep-context min confidence from the section", () =>
154
+ Effect.gen(function* () {
155
+ const mem = makeMemFs({
156
+ [TEST_PATH]: JSON.stringify({ smartCompaction: { keepContextMinConfidence: 0.72 } }),
157
+ });
158
+ const settings = yield* runWithMem(mem, load());
159
+ assert.strictEqual(settings.keepContextMinConfidence, 0.72);
160
+ }),
161
+ );
162
+
163
+ it.effect("load falls back alone when the min confidence is outside the open unit interval", () =>
164
+ Effect.gen(function* () {
165
+ for (const invalid of [0, 1, -0.1, 1.5, "0.5"]) {
166
+ const mem = makeMemFs({
167
+ [TEST_PATH]: JSON.stringify({
168
+ smartCompaction: { enabled: false, keepContextMinConfidence: invalid },
169
+ }),
170
+ });
171
+ const settings = yield* runWithMem(mem, load());
172
+ assert.strictEqual(settings.keepContextMinConfidence, DEFAULT_KEEP_CONTEXT_MIN_CONFIDENCE);
173
+ // The bad value must not discard the rest of the section.
174
+ assert.strictEqual(settings.enabled, false);
175
+ }
176
+ }),
177
+ );
178
+
179
+ it.effect("load reads a valid max-candidates cap from the section", () =>
180
+ Effect.gen(function* () {
181
+ const mem = makeMemFs({
182
+ [TEST_PATH]: JSON.stringify({ smartCompaction: { maxCandidates: 3 } }),
183
+ });
184
+ const settings = yield* runWithMem(mem, load());
185
+ assert.strictEqual(settings.maxCandidates, 3);
186
+ }),
187
+ );
188
+
189
+ it.effect("load falls back alone when the cap is not an integer in range", () =>
190
+ Effect.gen(function* () {
191
+ for (const invalid of [0, 21, 5.5, "8", null]) {
192
+ const mem = makeMemFs({
193
+ [TEST_PATH]: JSON.stringify({
194
+ smartCompaction: { enabled: false, maxCandidates: invalid },
195
+ }),
196
+ });
197
+ const settings = yield* runWithMem(mem, load());
198
+ assert.strictEqual(settings.maxCandidates, DEFAULT_MAX_CANDIDATES);
199
+ assert.strictEqual(settings.enabled, false);
200
+ }
201
+ }),
202
+ );
203
+
204
+ it.effect("load resolves every value from the shared contract fixture", () =>
205
+ Effect.gen(function* () {
206
+ const mem = makeMemFs({ [TEST_PATH]: yield* readFixture });
207
+ const settings = yield* runWithMem(mem, load());
208
+ assert.strictEqual(settings.enabled, true);
209
+ assert.deepStrictEqual(Option.getOrThrow(settings.chosen), {
210
+ provider: "typesafe",
211
+ modelId: "jev-latest",
212
+ });
213
+ assert.strictEqual(settings.keepContextThreshold, 0.5);
214
+ assert.strictEqual(settings.keepContextMinConfidence, 0.5);
215
+ assert.strictEqual(settings.maxCandidates, 8);
216
+ }),
217
+ );
218
+
219
+ it.effect("load reads the enabled, classifier, and threshold keys the contract names", () =>
220
+ Effect.gen(function* () {
221
+ const parsed = JSON.parse(yield* readFixture) as {
222
+ smartCompaction: Record<string, unknown>;
223
+ };
224
+ assert.strictEqual(SMART_COMPACTION_KEY in parsed, true);
225
+ assert.strictEqual(ENABLED_KEY in parsed.smartCompaction, true);
226
+ assert.strictEqual(CLASSIFIER_KEY in parsed.smartCompaction, true);
227
+ assert.strictEqual(KEEP_CONTEXT_THRESHOLD_KEY in parsed.smartCompaction, true);
228
+ assert.strictEqual(KEEP_CONTEXT_MIN_CONFIDENCE_KEY in parsed.smartCompaction, true);
229
+ assert.strictEqual(MAX_CANDIDATES_KEY in parsed.smartCompaction, true);
230
+ assert.strictEqual(parsed.smartCompaction[ENABLED_KEY], true);
231
+ assert.strictEqual(parsed.smartCompaction[CLASSIFIER_KEY], "typesafe/jev-latest");
232
+ assert.strictEqual(parsed.smartCompaction[KEEP_CONTEXT_THRESHOLD_KEY], 0.5);
233
+ assert.strictEqual(parsed.smartCompaction[KEEP_CONTEXT_MIN_CONFIDENCE_KEY], 0.5);
234
+ assert.strictEqual(parsed.smartCompaction[MAX_CANDIDATES_KEY], 8);
235
+ }),
236
+ );
237
+
238
+ it("parseClassifierIdentity splits provider and model id at the first slash", () => {
239
+ const identity = parseClassifierIdentity("cloudflare-workers-ai/@cf/cloudflare/clef-flash");
240
+ assert.deepStrictEqual(Option.getOrThrow(identity), {
241
+ provider: "cloudflare-workers-ai",
242
+ modelId: "@cf/cloudflare/clef-flash",
243
+ });
244
+ });
245
+
246
+ it("parseClassifierIdentity rejects a value with no provider or no model id", () => {
247
+ assert.strictEqual(Option.isNone(parseClassifierIdentity("jev-latest")), true);
248
+ assert.strictEqual(Option.isNone(parseClassifierIdentity("typesafe/")), true);
249
+ });
250
+
251
+ it.effect("load never writes to the config file", () =>
252
+ Effect.gen(function* () {
253
+ const mem = makeMemFs({ [TEST_PATH]: yield* readFixture });
254
+ const before = mem.files.get(TEST_PATH);
255
+ yield* runWithMem(mem, load());
256
+ assert.deepStrictEqual(mem.writes, []);
257
+ assert.strictEqual(mem.files.get(TEST_PATH), before);
258
+ }),
259
+ );
@@ -0,0 +1,163 @@
1
+ import { Context, Effect, Layer, Option, Predicate, Schema } from "effect";
2
+ import * as FileSystem from "effect/FileSystem";
3
+ import {
4
+ DEFAULT_KEEP_CONTEXT_MIN_CONFIDENCE,
5
+ DEFAULT_KEEP_CONTEXT_THRESHOLD,
6
+ type ClassifierIdentity,
7
+ } from "./classifier.ts";
8
+
9
+ /**
10
+ * The tracker's reader of the shared TUI settings file. It owns the
11
+ * interpretation of the three keys that smart compaction uses, and it fails open
12
+ * on every read, parse, or shape problem: the feature is active by default, the
13
+ * classifier preference order applies when no identity is chosen, and the
14
+ * default threshold applies when the value is missing or invalid.
15
+ *
16
+ * Co-owned with `packages/tui/src/config.ts`; the key names and value shapes
17
+ * are pinned by `test-fixtures/tui-config.contract.json`, read by both suites.
18
+ */
19
+ export const SMART_COMPACTION_CONFIG_FILE = "tui.json";
20
+ export const SMART_COMPACTION_KEY = "smartCompaction";
21
+ export const ENABLED_KEY = "enabled";
22
+ export const CLASSIFIER_KEY = "classifier";
23
+ export const KEEP_CONTEXT_THRESHOLD_KEY = "keepContextThreshold";
24
+ export const KEEP_CONTEXT_MIN_CONFIDENCE_KEY = "keepContextMinConfidence";
25
+ export const MAX_CANDIDATES_KEY = "maxCandidates";
26
+
27
+ /** Default number of ready items one classification judges. */
28
+ export const DEFAULT_MAX_CANDIDATES = 8;
29
+ /** Upper bound for the configured cap; a larger value falls back to the default. */
30
+ export const MAX_CANDIDATES_LIMIT = 20;
31
+
32
+ const FileSchema = Schema.fromJsonString(Schema.Unknown);
33
+ const EnabledSchema = Schema.Boolean;
34
+ const ClassifierSchema = Schema.NullOr(Schema.String);
35
+ const KeepContextThresholdSchema = Schema.Finite;
36
+ const KeepContextMinConfidenceSchema = Schema.Finite;
37
+ const MaxCandidatesSchema = Schema.Int;
38
+
39
+ export interface SmartCompactionSettings {
40
+ readonly enabled: boolean;
41
+ readonly chosen: Option.Option<ClassifierIdentity>;
42
+ readonly keepContextThreshold: number;
43
+ readonly keepContextMinConfidence: number;
44
+ readonly maxCandidates: number;
45
+ }
46
+
47
+ export const defaultSmartCompactionSettings = (): SmartCompactionSettings => ({
48
+ enabled: true,
49
+ chosen: Option.none(),
50
+ keepContextThreshold: DEFAULT_KEEP_CONTEXT_THRESHOLD,
51
+ keepContextMinConfidence: DEFAULT_KEEP_CONTEXT_MIN_CONFIDENCE,
52
+ maxCandidates: DEFAULT_MAX_CANDIDATES,
53
+ });
54
+
55
+ /**
56
+ * Split a `"provider/modelId"` value at the first slash, so a model id that
57
+ * itself contains slashes — the Cloudflare id `@cf/cloudflare/clef-flash` —
58
+ * stays whole. A value without both parts is not an identity.
59
+ */
60
+ export const parseClassifierIdentity = (value: string): Option.Option<ClassifierIdentity> => {
61
+ const slash = value.indexOf("/");
62
+ if (slash <= 0 || slash === value.length - 1) return Option.none();
63
+ return Option.some({ provider: value.slice(0, slash), modelId: value.slice(slash + 1) });
64
+ };
65
+
66
+ /** The `smartCompaction` object, when the parsed file has one of that shape. */
67
+ const smartSection = (parsed: unknown): Record<string, unknown> | undefined => {
68
+ if (!Predicate.isObject(parsed)) return undefined;
69
+ if (!Predicate.hasProperty(SMART_COMPACTION_KEY)(parsed)) return undefined;
70
+ const section = parsed[SMART_COMPACTION_KEY];
71
+ return Predicate.isObject(section) ? section : undefined;
72
+ };
73
+
74
+ export class SmartCompactionSettingsService extends Context.Service<
75
+ SmartCompactionSettingsService,
76
+ {
77
+ readonly path: string;
78
+ /** Never fails: every read, parse, or shape problem yields the defaults. */
79
+ readonly load: Effect.Effect<SmartCompactionSettings>;
80
+ }
81
+ >()("tracker/SmartCompactionSettings") {
82
+ static make(
83
+ path: string,
84
+ ): Layer.Layer<SmartCompactionSettingsService, never, FileSystem.FileSystem> {
85
+ return Layer.effect(
86
+ SmartCompactionSettingsService,
87
+ Effect.gen(function* () {
88
+ const fs = yield* FileSystem.FileSystem;
89
+ const load = Effect.gen(function* () {
90
+ const raw = yield* fs.readFileString(path);
91
+ // `Schema.Unknown` accepts any JSON value; the guards below narrow it.
92
+ const parsed = yield* Schema.decodeEffect(FileSchema)(raw);
93
+ const section = smartSection(parsed);
94
+ // Each key decodes independently, so an unrecognized value falls back
95
+ // alone instead of discarding the rest of the section.
96
+ const enabled = Option.getOrElse(
97
+ Schema.decodeUnknownOption(EnabledSchema)(
98
+ section === undefined ? undefined : section[ENABLED_KEY],
99
+ ),
100
+ () => true,
101
+ );
102
+ const chosen = Option.flatMap(
103
+ Schema.decodeUnknownOption(ClassifierSchema)(
104
+ section === undefined ? undefined : section[CLASSIFIER_KEY],
105
+ ),
106
+ (value) => (value === null ? Option.none() : parseClassifierIdentity(value)),
107
+ );
108
+ // A threshold must stay strictly inside (0, 1); anything else falls
109
+ // back alone, so a bad value cannot disable the whole feature.
110
+ const keepContextThreshold = Option.getOrElse(
111
+ Option.filter(
112
+ Schema.decodeUnknownOption(KeepContextThresholdSchema)(
113
+ section === undefined ? undefined : section[KEEP_CONTEXT_THRESHOLD_KEY],
114
+ ),
115
+ (value) => value > 0 && value < 1,
116
+ ),
117
+ () => DEFAULT_KEEP_CONTEXT_THRESHOLD,
118
+ );
119
+ const keepContextMinConfidence = Option.getOrElse(
120
+ Option.filter(
121
+ Schema.decodeUnknownOption(KeepContextMinConfidenceSchema)(
122
+ section === undefined ? undefined : section[KEEP_CONTEXT_MIN_CONFIDENCE_KEY],
123
+ ),
124
+ (value) => value > 0 && value < 1,
125
+ ),
126
+ () => DEFAULT_KEEP_CONTEXT_MIN_CONFIDENCE,
127
+ );
128
+ // The cap must be an integer in [1, MAX_CANDIDATES_LIMIT]; anything
129
+ // else falls back alone.
130
+ const maxCandidates = Option.getOrElse(
131
+ Option.filter(
132
+ Schema.decodeUnknownOption(MaxCandidatesSchema)(
133
+ section === undefined ? undefined : section[MAX_CANDIDATES_KEY],
134
+ ),
135
+ (value) => value >= 1 && value <= MAX_CANDIDATES_LIMIT,
136
+ ),
137
+ () => DEFAULT_MAX_CANDIDATES,
138
+ );
139
+ return {
140
+ enabled,
141
+ chosen,
142
+ keepContextThreshold,
143
+ keepContextMinConfidence,
144
+ maxCandidates,
145
+ } satisfies SmartCompactionSettings;
146
+ }).pipe(
147
+ Effect.catchCause(() =>
148
+ Effect.logWarning("tracker: smart-compaction settings unreadable, using defaults").pipe(
149
+ Effect.as(defaultSmartCompactionSettings()),
150
+ ),
151
+ ),
152
+ );
153
+ return SmartCompactionSettingsService.of({ path, load });
154
+ }),
155
+ );
156
+ }
157
+
158
+ static readonly layerTest = (
159
+ path: string,
160
+ fileSystem: Partial<FileSystem.FileSystem>,
161
+ ): Layer.Layer<SmartCompactionSettingsService> =>
162
+ SmartCompactionSettingsService.make(path).pipe(Layer.provide(FileSystem.layerNoop(fileSystem)));
163
+ }
@@ -0,0 +1,94 @@
1
+ import { Context, Effect, Layer, Option } from "effect";
2
+ import { ClassifierGateway, type ClassifierRegistry } from "./classifier.ts";
3
+ import { selectCandidates } from "./candidate.ts";
4
+ import { CompletionObserver } from "./completion.ts";
5
+ import { buildDigests, compactQuestions } from "./digest.ts";
6
+ import { resumePointer } from "./pointer.ts";
7
+ import { SmartCompactionSettingsService } from "./settings.ts";
8
+
9
+ /** How the run that just reached the settle boundary ended. */
10
+ export type SettleOutcome = "completed" | "aborted" | "error";
11
+
12
+ const SETTLE_DECISION = {
13
+ keep: { kind: "keep" },
14
+ compact: (pointer: string) => ({
15
+ kind: "compact",
16
+ pointer,
17
+ }),
18
+ } as const;
19
+
20
+ /** What the bridge should do with the run's context. */
21
+ export type SettleDecision =
22
+ | (typeof SETTLE_DECISION)["keep"]
23
+ | ReturnType<(typeof SETTLE_DECISION)["compact"]>;
24
+
25
+ /**
26
+ * The settle decision. It consumes the completion record first, so every
27
+ * terminal path clears it and one completion set yields at most one decision,
28
+ * then requires a completed run before it classifies anything. It judges the
29
+ * whole ready frontier and never fails: every failure path keeps the context.
30
+ */
31
+ export class SettleDecider extends Context.Service<
32
+ SettleDecider,
33
+ {
34
+ readonly decide: (input: {
35
+ readonly registry: ClassifierRegistry;
36
+ readonly outcome: SettleOutcome;
37
+ readonly signal?: AbortSignal | undefined;
38
+ }) => Effect.Effect<SettleDecision>;
39
+ }
40
+ >()("tracker/SettleDecider") {
41
+ static readonly layer: Layer.Layer<
42
+ SettleDecider,
43
+ never,
44
+ CompletionObserver | SmartCompactionSettingsService | ClassifierGateway
45
+ > = Layer.effect(
46
+ SettleDecider,
47
+ Effect.gen(function* () {
48
+ const pending = yield* CompletionObserver;
49
+ const settings = yield* SmartCompactionSettingsService;
50
+ const gateway = yield* ClassifierGateway;
51
+
52
+ const decide = Effect.fn("SettleDecider.decide")(
53
+ function* (input: {
54
+ readonly registry: ClassifierRegistry;
55
+ readonly outcome: SettleOutcome;
56
+ readonly signal?: AbortSignal | undefined;
57
+ }) {
58
+ // Consume first: nothing below may run twice for one completion, and
59
+ // every path from here clears the record.
60
+ const recorded = yield* pending.consume;
61
+ if (Option.isNone(recorded)) return SETTLE_DECISION.keep;
62
+ // An aborted or errored run compacts nothing and produces no pointer.
63
+ if (input.outcome !== "completed") return SETTLE_DECISION.keep;
64
+ const values = yield* settings.load;
65
+ // The whole ready frontier is judged, capped by the setting. The
66
+ // first entry is the pointer target; the array is empty when nothing
67
+ // is ready.
68
+ const candidates = selectCandidates(recorded.value, values.maxCandidates);
69
+ if (candidates.length === 0) return SETTLE_DECISION.keep;
70
+ const verdict = yield* gateway.verdict({
71
+ registry: input.registry,
72
+ enabled: values.enabled,
73
+ chosen: values.chosen,
74
+ keepContextThreshold: values.keepContextThreshold,
75
+ keepContextMinConfidence: values.keepContextMinConfidence,
76
+ digest: buildDigests(candidates),
77
+ questions: compactQuestions(candidates),
78
+ signal: input.signal,
79
+ });
80
+ return verdict.kind === "compact"
81
+ ? SETTLE_DECISION.compact(resumePointer(candidates[0]!))
82
+ : SETTLE_DECISION.keep;
83
+ },
84
+ Effect.catchCause(() =>
85
+ Effect.logWarning("tracker: smart-compaction decision failed, keeping context").pipe(
86
+ Effect.as(SETTLE_DECISION.keep),
87
+ ),
88
+ ),
89
+ );
90
+
91
+ return SettleDecider.of({ decide });
92
+ }),
93
+ );
94
+ }