ai-foreman 1.7.9 → 1.7.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/claude.d.ts +4 -2
- package/dist/adapters/claude.js +18 -4
- package/dist/adapters/codex.d.ts +4 -2
- package/dist/adapters/codex.js +10 -1
- package/dist/adapters/recovering.d.ts +3 -2
- package/dist/adapters/recovering.js +1 -0
- package/dist/adapters/types.d.ts +14 -1
- package/dist/branch/currentGuard.d.ts +3 -2
- package/dist/branch/currentGuard.js +1 -0
- package/dist/cli/start.js +6 -1
- package/dist/continuity.d.ts +3 -2
- package/dist/continuity.js +1 -0
- package/dist/sessionLifecycle.d.ts +3 -0
- package/dist/sessionLifecycle.js +14 -1
- package/dist/statusReporter.d.ts +3 -2
- package/dist/statusReporter.js +1 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SDKSessionInfo, PermissionResult } from "@anthropic-ai/claude-agent-sdk";
|
|
2
2
|
/** Lazy-load the Claude Agent SDK. Throws an actionable error if not installed. */
|
|
3
3
|
export declare function requireClaudeSDK(): Promise<typeof import("@anthropic-ai/claude-agent-sdk")>;
|
|
4
|
-
import type { BuilderAdapter, BuilderAdapterOptions, BuilderEvent, NativeCompaction, CompactResult, ContextUsage, PermissionDecision, ProviderSettingSwitch, ProviderSessionUsage, TurnResult } from "./types.js";
|
|
4
|
+
import type { BuilderAdapter, BuilderAdapterOptions, BuilderEvent, NativeCompaction, NativeAutoCompactionPolicy, CompactResult, ContextUsage, PermissionDecision, ProviderSettingSwitch, ProviderSessionUsage, TurnResult } from "./types.js";
|
|
5
5
|
import type { ProviderSessionRefV1, SessionAvailabilityV1 } from "rafi-spec";
|
|
6
6
|
/**
|
|
7
7
|
* Pure function: build the `options` object passed to `query()`.
|
|
@@ -57,6 +57,7 @@ export declare class ClaudeAdapter implements BuilderAdapter {
|
|
|
57
57
|
private compactResult?;
|
|
58
58
|
private autoCompactionPrepared;
|
|
59
59
|
private preparedAutoCompactThreshold?;
|
|
60
|
+
private preparedAutoCompactionPolicy?;
|
|
60
61
|
private manualCompactionInFlight;
|
|
61
62
|
private nativeCompactions;
|
|
62
63
|
private nativeCompactionSequence;
|
|
@@ -78,7 +79,8 @@ export declare class ClaudeAdapter implements BuilderAdapter {
|
|
|
78
79
|
adoptSessionRef(ref: ProviderSessionRefV1): void;
|
|
79
80
|
validateSession(): Promise<SessionAvailabilityV1>;
|
|
80
81
|
compact(): Promise<CompactResult>;
|
|
81
|
-
prepareAutoCompaction(thresholdPercent?: number | undefined): Promise<void>;
|
|
82
|
+
prepareAutoCompaction(thresholdPercent?: number | undefined): Promise<NativeAutoCompactionPolicy | void>;
|
|
83
|
+
autoCompactionPolicy(): NativeAutoCompactionPolicy | undefined;
|
|
82
84
|
drainNativeCompactions(): NativeCompaction[];
|
|
83
85
|
restoreNativeCompactions(compactions: NativeCompaction[]): void;
|
|
84
86
|
contextUsage(): Promise<ContextUsage | undefined>;
|
package/dist/adapters/claude.js
CHANGED
|
@@ -154,6 +154,7 @@ export class ClaudeAdapter {
|
|
|
154
154
|
compactResult;
|
|
155
155
|
autoCompactionPrepared = false;
|
|
156
156
|
preparedAutoCompactThreshold;
|
|
157
|
+
preparedAutoCompactionPolicy;
|
|
157
158
|
manualCompactionInFlight = false;
|
|
158
159
|
nativeCompactions = [];
|
|
159
160
|
nativeCompactionSequence = 0;
|
|
@@ -450,7 +451,7 @@ export class ClaudeAdapter {
|
|
|
450
451
|
return;
|
|
451
452
|
const threshold = validThreshold(thresholdPercent);
|
|
452
453
|
if (this.autoCompactionPrepared && this.preparedAutoCompactThreshold === threshold)
|
|
453
|
-
return;
|
|
454
|
+
return this.preparedAutoCompactionPolicy;
|
|
454
455
|
this.opts.autoCompactThresholdPercent = threshold;
|
|
455
456
|
await this.query.initializationResult();
|
|
456
457
|
await this.query.applyFlagSettings({ autoCompactEnabled: true });
|
|
@@ -469,13 +470,26 @@ export class ClaudeAdapter {
|
|
|
469
470
|
const requestedWindow = tokenLimit(baseline.maxTokens, threshold) + reserve;
|
|
470
471
|
await this.query.applyFlagSettings({ autoCompactEnabled: true, autoCompactWindow: requestedWindow });
|
|
471
472
|
const installed = await this.query.getContextUsage();
|
|
472
|
-
if (!installed.isAutoCompactEnabled || installed.
|
|
473
|
-
|| installed.autoCompactThreshold
|
|
474
|
-
throw new Error("Claude did not
|
|
473
|
+
if (!installed.isAutoCompactEnabled || !Number.isFinite(installed.maxTokens) || installed.maxTokens <= 0
|
|
474
|
+
|| !Number.isFinite(installed.autoCompactThreshold) || installed.autoCompactThreshold === undefined) {
|
|
475
|
+
throw new Error("Claude did not expose an enabled native automatic-compaction threshold after configuration");
|
|
475
476
|
}
|
|
477
|
+
// `applyFlagSettings` can legitimately clamp autoCompactWindow. The
|
|
478
|
+
// provider's reported trigger is authoritative; rejecting the entire run
|
|
479
|
+
// merely because a configured value is below that minimum made defaults
|
|
480
|
+
// unusable. Lifecycle code consumes this verified effective ceiling.
|
|
481
|
+
const effectiveThresholdPercent = Math.max(1, Math.min(99, Math.floor(installed.autoCompactThreshold / installed.maxTokens * 100)));
|
|
482
|
+
this.preparedAutoCompactionPolicy = {
|
|
483
|
+
requestedThresholdPercent: threshold,
|
|
484
|
+
effectiveThresholdPercent,
|
|
485
|
+
modelContextWindow: installed.maxTokens,
|
|
486
|
+
triggerTokens: installed.autoCompactThreshold,
|
|
487
|
+
};
|
|
476
488
|
this.autoCompactionPrepared = true;
|
|
477
489
|
this.preparedAutoCompactThreshold = threshold;
|
|
490
|
+
return this.preparedAutoCompactionPolicy;
|
|
478
491
|
}
|
|
492
|
+
autoCompactionPolicy() { return this.preparedAutoCompactionPolicy; }
|
|
479
493
|
drainNativeCompactions() {
|
|
480
494
|
const pending = this.nativeCompactions;
|
|
481
495
|
this.nativeCompactions = [];
|
package/dist/adapters/codex.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BuilderAdapter, BuilderAdapterOptions, BuilderEvent, CompactResult, ContextUsage, NativeCompaction, ProviderSessionUsage, ProviderSettingSwitch, TurnResult } from "./types.js";
|
|
1
|
+
import type { BuilderAdapter, BuilderAdapterOptions, BuilderEvent, CompactResult, ContextUsage, NativeAutoCompactionPolicy, NativeCompaction, ProviderSessionUsage, ProviderSettingSwitch, TurnResult } from "./types.js";
|
|
2
2
|
import type { ProviderSessionRefV1, SessionAvailabilityV1 } from "rafi-spec";
|
|
3
3
|
export interface CodexLineResult {
|
|
4
4
|
events: BuilderEvent[];
|
|
@@ -30,6 +30,7 @@ export declare class CodexAdapter implements BuilderAdapter {
|
|
|
30
30
|
private nativeAutoCompactTokenLimit?;
|
|
31
31
|
private autoCompactionPrepared;
|
|
32
32
|
private preparedAutoCompactThreshold?;
|
|
33
|
+
private preparedAutoCompactionPolicy?;
|
|
33
34
|
private nativeCompactions;
|
|
34
35
|
private nativeCompactionSequence;
|
|
35
36
|
private manualCompactionInFlight;
|
|
@@ -42,7 +43,8 @@ export declare class CodexAdapter implements BuilderAdapter {
|
|
|
42
43
|
sendTurn(instruction: string): Promise<TurnResult>;
|
|
43
44
|
private sendTurnInternal;
|
|
44
45
|
compact(): Promise<CompactResult>;
|
|
45
|
-
prepareAutoCompaction(thresholdPercent?: number | undefined): Promise<void>;
|
|
46
|
+
prepareAutoCompaction(thresholdPercent?: number | undefined): Promise<NativeAutoCompactionPolicy | void>;
|
|
47
|
+
autoCompactionPolicy(): NativeAutoCompactionPolicy | undefined;
|
|
46
48
|
drainNativeCompactions(): NativeCompaction[];
|
|
47
49
|
restoreNativeCompactions(compactions: NativeCompaction[]): void;
|
|
48
50
|
contextUsage(): Promise<ContextUsage | undefined>;
|
package/dist/adapters/codex.js
CHANGED
|
@@ -46,6 +46,7 @@ export class CodexAdapter {
|
|
|
46
46
|
nativeAutoCompactTokenLimit;
|
|
47
47
|
autoCompactionPrepared = false;
|
|
48
48
|
preparedAutoCompactThreshold;
|
|
49
|
+
preparedAutoCompactionPolicy;
|
|
49
50
|
nativeCompactions = [];
|
|
50
51
|
nativeCompactionSequence = 0;
|
|
51
52
|
manualCompactionInFlight = false;
|
|
@@ -181,7 +182,7 @@ export class CodexAdapter {
|
|
|
181
182
|
return;
|
|
182
183
|
const threshold = validThreshold(thresholdPercent);
|
|
183
184
|
if (this.autoCompactionPrepared && this.preparedAutoCompactThreshold === threshold)
|
|
184
|
-
return;
|
|
185
|
+
return this.preparedAutoCompactionPolicy;
|
|
185
186
|
this.opts.autoCompactThresholdPercent = threshold;
|
|
186
187
|
await this.ensureThread();
|
|
187
188
|
// Codex reports its model context window in token-usage notifications, not
|
|
@@ -205,7 +206,15 @@ export class CodexAdapter {
|
|
|
205
206
|
await this.ensureThread();
|
|
206
207
|
this.autoCompactionPrepared = true;
|
|
207
208
|
this.preparedAutoCompactThreshold = threshold;
|
|
209
|
+
this.preparedAutoCompactionPolicy = {
|
|
210
|
+
requestedThresholdPercent: threshold,
|
|
211
|
+
effectiveThresholdPercent: threshold,
|
|
212
|
+
modelContextWindow: maximum,
|
|
213
|
+
triggerTokens: this.nativeAutoCompactTokenLimit,
|
|
214
|
+
};
|
|
215
|
+
return this.preparedAutoCompactionPolicy;
|
|
208
216
|
}
|
|
217
|
+
autoCompactionPolicy() { return this.preparedAutoCompactionPolicy; }
|
|
209
218
|
drainNativeCompactions() {
|
|
210
219
|
const pending = this.nativeCompactions;
|
|
211
220
|
this.nativeCompactions = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AgentRuntime } from "../runtimeAuth.js";
|
|
2
|
-
import type { BuilderAdapter, BuilderEvent, CompactResult, ContextUsage, NativeCompaction, ProviderSessionUsage, TurnResult } from "./types.js";
|
|
2
|
+
import type { BuilderAdapter, BuilderEvent, CompactResult, ContextUsage, NativeAutoCompactionPolicy, NativeCompaction, ProviderSessionUsage, TurnResult } from "./types.js";
|
|
3
3
|
import type { ProviderSessionRefV1, SessionAvailabilityV1 } from "rafi-spec";
|
|
4
4
|
export type TurnRecoveryChoice = "retry" | "switch" | "cancel";
|
|
5
5
|
export interface RecoveringAdapterOptions {
|
|
@@ -29,7 +29,8 @@ export declare class RecoveringAdapter implements BuilderAdapter {
|
|
|
29
29
|
adoptSessionRef(ref: ProviderSessionRefV1): void;
|
|
30
30
|
validateSession(): Promise<SessionAvailabilityV1>;
|
|
31
31
|
compact(): Promise<CompactResult>;
|
|
32
|
-
prepareAutoCompaction(thresholdPercent?: number): Promise<void>;
|
|
32
|
+
prepareAutoCompaction(thresholdPercent?: number): Promise<NativeAutoCompactionPolicy | void>;
|
|
33
|
+
autoCompactionPolicy(): NativeAutoCompactionPolicy | undefined;
|
|
33
34
|
drainNativeCompactions(): import("./types.js").NativeCompaction[];
|
|
34
35
|
restoreNativeCompactions(compactions: NativeCompaction[]): void;
|
|
35
36
|
contextUsageAfterNativeCompaction(compaction: NativeCompaction): Promise<ContextUsage | undefined>;
|
|
@@ -68,6 +68,7 @@ export class RecoveringAdapter {
|
|
|
68
68
|
}
|
|
69
69
|
compact() { return this.adapter.compact?.() ?? Promise.resolve({ ok: false, error: "native compaction unavailable" }); }
|
|
70
70
|
prepareAutoCompaction(thresholdPercent) { return this.adapter.prepareAutoCompaction?.(thresholdPercent) ?? Promise.resolve(); }
|
|
71
|
+
autoCompactionPolicy() { return this.adapter.autoCompactionPolicy?.(); }
|
|
71
72
|
drainNativeCompactions() { return this.adapter.drainNativeCompactions?.() ?? []; }
|
|
72
73
|
restoreNativeCompactions(compactions) { this.adapter.restoreNativeCompactions?.(compactions); }
|
|
73
74
|
contextUsageAfterNativeCompaction(compaction) { return this.adapter.contextUsageAfterNativeCompaction?.(compaction) ?? Promise.resolve(undefined); }
|
package/dist/adapters/types.d.ts
CHANGED
|
@@ -108,6 +108,17 @@ export interface ContextUsage {
|
|
|
108
108
|
observedAt?: string;
|
|
109
109
|
source?: "provider-event" | "provider-query" | "post-compact";
|
|
110
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* The provider-native automatic-compaction policy that was actually installed.
|
|
113
|
+
* Providers may clamp a requested ceiling to a model- or runtime-specific
|
|
114
|
+
* minimum, so lifecycle enforcement must consume the effective value.
|
|
115
|
+
*/
|
|
116
|
+
export interface NativeAutoCompactionPolicy {
|
|
117
|
+
requestedThresholdPercent: number;
|
|
118
|
+
effectiveThresholdPercent: number;
|
|
119
|
+
modelContextWindow?: number;
|
|
120
|
+
triggerTokens?: number;
|
|
121
|
+
}
|
|
111
122
|
export interface ProviderSessionUsage {
|
|
112
123
|
inputTokens?: number;
|
|
113
124
|
outputTokens?: number;
|
|
@@ -194,7 +205,9 @@ export interface BuilderAdapter {
|
|
|
194
205
|
* dispatched. This intentionally happens outside a work turn so a long,
|
|
195
206
|
* tool-heavy first turn is protected too.
|
|
196
207
|
*/
|
|
197
|
-
prepareAutoCompaction?(thresholdPercent?: number): Promise<void>;
|
|
208
|
+
prepareAutoCompaction?(thresholdPercent?: number): Promise<NativeAutoCompactionPolicy | void>;
|
|
209
|
+
/** The last provider-native automatic-compaction policy verified on this transport. */
|
|
210
|
+
autoCompactionPolicy?(): NativeAutoCompactionPolicy | undefined;
|
|
198
211
|
/** Consume provider-native compactions observed since the prior drain. */
|
|
199
212
|
drainNativeCompactions?(): NativeCompaction[];
|
|
200
213
|
/** Return a drained batch to the adapter when durable receipt failed. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BuilderAdapter, BuilderEvent, CompactResult, ContextUsage, NativeCompaction, ProviderSessionUsage, ProviderSettingSwitch, TurnResult } from "../adapters/types.js";
|
|
1
|
+
import type { BuilderAdapter, BuilderEvent, CompactResult, ContextUsage, NativeAutoCompactionPolicy, NativeCompaction, ProviderSessionUsage, ProviderSettingSwitch, TurnResult } from "../adapters/types.js";
|
|
2
2
|
import type { ProviderSessionRefV1, SessionAvailabilityV1 } from "rafi-spec";
|
|
3
3
|
export interface CurrentWorkflowIdentity {
|
|
4
4
|
worktree: string;
|
|
@@ -26,7 +26,8 @@ export declare class CurrentWorkflowGuardAdapter implements BuilderAdapter {
|
|
|
26
26
|
adoptSessionRef(ref: ProviderSessionRefV1): void;
|
|
27
27
|
validateSession(): Promise<SessionAvailabilityV1>;
|
|
28
28
|
compact(): Promise<CompactResult>;
|
|
29
|
-
prepareAutoCompaction(thresholdPercent?: number): Promise<void>;
|
|
29
|
+
prepareAutoCompaction(thresholdPercent?: number): Promise<NativeAutoCompactionPolicy | void>;
|
|
30
|
+
autoCompactionPolicy(): NativeAutoCompactionPolicy | undefined;
|
|
30
31
|
drainNativeCompactions(): import("../adapters/types.js").NativeCompaction[];
|
|
31
32
|
restoreNativeCompactions(compactions: NativeCompaction[]): void;
|
|
32
33
|
contextUsageAfterNativeCompaction(compaction: NativeCompaction): Promise<ContextUsage | undefined>;
|
|
@@ -49,6 +49,7 @@ export class CurrentWorkflowGuardAdapter {
|
|
|
49
49
|
validateSession() { assertCurrentWorkflowIdentity(this.cwd, this.expected); return this.adapter.validateSession?.() ?? Promise.resolve({ version: 1, status: "unknown", checkedAt: new Date().toISOString(), reason: "legacy-unscoped" }); }
|
|
50
50
|
async compact() { assertCurrentWorkflowIdentity(this.cwd, this.expected); const result = await (this.adapter.compact?.() ?? Promise.resolve({ ok: false, error: "native compaction unavailable" })); assertCurrentWorkflowIdentity(this.cwd, this.expected); return result; }
|
|
51
51
|
prepareAutoCompaction(thresholdPercent) { return this.adapter.prepareAutoCompaction?.(thresholdPercent) ?? Promise.resolve(); }
|
|
52
|
+
autoCompactionPolicy() { return this.adapter.autoCompactionPolicy?.(); }
|
|
52
53
|
drainNativeCompactions() { return this.adapter.drainNativeCompactions?.() ?? []; }
|
|
53
54
|
restoreNativeCompactions(compactions) { this.adapter.restoreNativeCompactions?.(compactions); }
|
|
54
55
|
contextUsageAfterNativeCompaction(compaction) { return this.adapter.contextUsageAfterNativeCompaction?.(compaction) ?? Promise.resolve(undefined); }
|
package/dist/cli/start.js
CHANGED
|
@@ -1959,7 +1959,12 @@ async function prepareNativeAutoCompaction(adapter) {
|
|
|
1959
1959
|
throw new Error(`${adapter.agent} does not support provider-native automatic compaction`);
|
|
1960
1960
|
}
|
|
1961
1961
|
try {
|
|
1962
|
-
await adapter.prepareAutoCompaction();
|
|
1962
|
+
const policy = await adapter.prepareAutoCompaction();
|
|
1963
|
+
if (policy && policy.effectiveThresholdPercent !== policy.requestedThresholdPercent) {
|
|
1964
|
+
console.log(`foreman: ${adapter.agent} applied automatic compaction at ${policy.effectiveThresholdPercent}% `
|
|
1965
|
+
+ `(configured ${policy.requestedThresholdPercent}%; provider minimum or clamp). `
|
|
1966
|
+
+ "Use `rafi agents .` to update the Builder or QA saved threshold interactively.");
|
|
1967
|
+
}
|
|
1963
1968
|
}
|
|
1964
1969
|
catch (error) {
|
|
1965
1970
|
await adapter.close().catch(() => { });
|
package/dist/continuity.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ContinuityDelta, ResolvedAgentSettings } from "rafi-spec";
|
|
2
|
-
import type { BuilderAdapter, CompactResult, ContextUsage, NativeCompaction, ProviderSessionUsage, ProviderSettingSwitch, RuntimeFailure, TurnResult } from "./adapters/types.js";
|
|
2
|
+
import type { BuilderAdapter, CompactResult, ContextUsage, NativeAutoCompactionPolicy, NativeCompaction, ProviderSessionUsage, ProviderSettingSwitch, RuntimeFailure, TurnResult } from "./adapters/types.js";
|
|
3
3
|
export declare const CONTINUITY_MARKER = "RAFI_CONTINUITY_DELTA:";
|
|
4
4
|
export declare class ContinuityValidationError extends Error {
|
|
5
5
|
readonly problems: string[];
|
|
@@ -70,7 +70,8 @@ export declare class ContinuityAdapter implements BuilderAdapter {
|
|
|
70
70
|
adoptSessionRef(ref: import("rafi-spec").ProviderSessionRefV1): void;
|
|
71
71
|
validateSession(): Promise<import("rafi-spec").SessionAvailabilityV1>;
|
|
72
72
|
compact(): Promise<CompactResult>;
|
|
73
|
-
prepareAutoCompaction(thresholdPercent?: number): Promise<void>;
|
|
73
|
+
prepareAutoCompaction(thresholdPercent?: number): Promise<NativeAutoCompactionPolicy | void>;
|
|
74
|
+
autoCompactionPolicy(): NativeAutoCompactionPolicy | undefined;
|
|
74
75
|
drainNativeCompactions(): import("./adapters/types.js").NativeCompaction[];
|
|
75
76
|
restoreNativeCompactions(compactions: NativeCompaction[]): void;
|
|
76
77
|
contextUsageAfterNativeCompaction(compaction: NativeCompaction): Promise<ContextUsage | undefined>;
|
package/dist/continuity.js
CHANGED
|
@@ -233,6 +233,7 @@ export class ContinuityAdapter {
|
|
|
233
233
|
validateSession() { return this.adapter.validateSession?.() ?? Promise.resolve({ version: 1, status: "unknown", checkedAt: new Date().toISOString(), reason: "legacy-unscoped" }); }
|
|
234
234
|
compact() { return this.adapter.compact ? this.adapter.compact() : Promise.resolve({ ok: false, error: "provider adapter does not expose native compaction" }); }
|
|
235
235
|
prepareAutoCompaction(thresholdPercent) { return this.adapter.prepareAutoCompaction?.(thresholdPercent) ?? Promise.resolve(); }
|
|
236
|
+
autoCompactionPolicy() { return this.adapter.autoCompactionPolicy?.(); }
|
|
236
237
|
drainNativeCompactions() { return this.adapter.drainNativeCompactions?.() ?? []; }
|
|
237
238
|
restoreNativeCompactions(compactions) { this.adapter.restoreNativeCompactions?.(compactions); }
|
|
238
239
|
contextUsageAfterNativeCompaction(compaction) { return this.adapter.contextUsageAfterNativeCompaction?.(compaction) ?? Promise.resolve(undefined); }
|
|
@@ -118,6 +118,8 @@ export declare class ThresholdCompactionController {
|
|
|
118
118
|
private crossing;
|
|
119
119
|
private readonly seenSessions;
|
|
120
120
|
private runOnlyThreshold?;
|
|
121
|
+
/** Verified provider ceiling. It may be higher than configured when the provider clamps. */
|
|
122
|
+
private providerEffectiveThreshold?;
|
|
121
123
|
private bootstrapScheduled;
|
|
122
124
|
private bootstrapRecoveryDepth;
|
|
123
125
|
private historicalCountUncertain;
|
|
@@ -136,6 +138,7 @@ export declare class ThresholdCompactionController {
|
|
|
136
138
|
private sampleFromUsage;
|
|
137
139
|
private compactionCount;
|
|
138
140
|
private handoffGeneration;
|
|
141
|
+
private syncProviderEffectiveThreshold;
|
|
139
142
|
private threshold;
|
|
140
143
|
private now;
|
|
141
144
|
}
|
package/dist/sessionLifecycle.js
CHANGED
|
@@ -310,6 +310,8 @@ export class ThresholdCompactionController {
|
|
|
310
310
|
crossing = 0;
|
|
311
311
|
seenSessions = new Set();
|
|
312
312
|
runOnlyThreshold;
|
|
313
|
+
/** Verified provider ceiling. It may be higher than configured when the provider clamps. */
|
|
314
|
+
providerEffectiveThreshold;
|
|
313
315
|
bootstrapScheduled = false;
|
|
314
316
|
bootstrapRecoveryDepth = 0;
|
|
315
317
|
historicalCountUncertain;
|
|
@@ -320,6 +322,7 @@ export class ThresholdCompactionController {
|
|
|
320
322
|
}
|
|
321
323
|
async atSafeBoundary(adapter, frozenAction) {
|
|
322
324
|
adapter = await this.adoptSettings(adapter, frozenAction);
|
|
325
|
+
this.syncProviderEffectiveThreshold(adapter);
|
|
323
326
|
if (!adapter.sessionId() && !this.bootstrapScheduled) {
|
|
324
327
|
this.bootstrapScheduled = true;
|
|
325
328
|
const sample = {
|
|
@@ -376,6 +379,7 @@ export class ThresholdCompactionController {
|
|
|
376
379
|
const revisionBeforeSettle = this.settings.settings_revision;
|
|
377
380
|
const sessionBeforeSettle = adapterSessionKey(adapter);
|
|
378
381
|
adapter = await this.adoptSettings(adapter, frozenAction);
|
|
382
|
+
this.syncProviderEffectiveThreshold(adapter);
|
|
379
383
|
if (this.settings.settings_revision !== revisionBeforeSettle || adapterSessionKey(adapter) !== sessionBeforeSettle) {
|
|
380
384
|
sample = await this.measure(adapter, "provider-query");
|
|
381
385
|
session = adapter.sessionRef?.() ?? adapter.sessionId();
|
|
@@ -403,6 +407,7 @@ export class ThresholdCompactionController {
|
|
|
403
407
|
/** Apply the configured ordinary work-session boundary without bypassing handoff or compaction accounting. */
|
|
404
408
|
async atWorkSessionBoundary(adapter, frozenAction, strategy = this.settings.session_strategy) {
|
|
405
409
|
adapter = await this.adoptSettings(adapter, frozenAction);
|
|
410
|
+
this.syncProviderEffectiveThreshold(adapter);
|
|
406
411
|
const nativeCount = await this.observeNativeCompactions(adapter);
|
|
407
412
|
const sample = await this.measure(adapter, "provider-query");
|
|
408
413
|
const db = new WorkflowDb(this.options.projectDir);
|
|
@@ -657,6 +662,7 @@ export class ThresholdCompactionController {
|
|
|
657
662
|
}
|
|
658
663
|
this.settings = next;
|
|
659
664
|
this.runOnlyThreshold = undefined;
|
|
665
|
+
this.syncProviderEffectiveThreshold(adoptedAdapter);
|
|
660
666
|
const db = new WorkflowDb(this.options.projectDir);
|
|
661
667
|
try {
|
|
662
668
|
const ref = adoptedAdapter.sessionRef?.();
|
|
@@ -718,7 +724,14 @@ export class ThresholdCompactionController {
|
|
|
718
724
|
db.close();
|
|
719
725
|
}
|
|
720
726
|
}
|
|
721
|
-
|
|
727
|
+
syncProviderEffectiveThreshold(adapter) {
|
|
728
|
+
const policy = adapter.autoCompactionPolicy?.();
|
|
729
|
+
const effective = policy?.effectiveThresholdPercent;
|
|
730
|
+
this.providerEffectiveThreshold = effective !== undefined && Number.isInteger(effective) && effective >= 1 && effective <= 99
|
|
731
|
+
? effective
|
|
732
|
+
: undefined;
|
|
733
|
+
}
|
|
734
|
+
threshold() { return this.runOnlyThreshold ?? this.providerEffectiveThreshold ?? this.settings.auto_compact_threshold_percent ?? 50; }
|
|
722
735
|
now() { return this.options.now?.() ?? new Date(); }
|
|
723
736
|
}
|
|
724
737
|
function normalizeContextSettings(settings) {
|
package/dist/statusReporter.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ContextSample, SessionUsageSample } from "rafi-spec";
|
|
2
|
-
import type { BuilderAdapter, BuilderEvent, CompactResult, ContextUsage, NativeCompaction, ProviderSessionUsage, ProviderSettingSwitch, TurnResult } from "./adapters/types.js";
|
|
2
|
+
import type { BuilderAdapter, BuilderEvent, CompactResult, ContextUsage, NativeAutoCompactionPolicy, NativeCompaction, ProviderSessionUsage, ProviderSettingSwitch, TurnResult } from "./adapters/types.js";
|
|
3
3
|
export interface AgentStatusSnapshot {
|
|
4
4
|
role: "builder" | "qa";
|
|
5
5
|
provider: "claude" | "codex";
|
|
@@ -82,7 +82,8 @@ export declare class RoleStatusAdapter implements BuilderAdapter {
|
|
|
82
82
|
adoptSessionRef(ref: import("rafi-spec").ProviderSessionRefV1): void;
|
|
83
83
|
validateSession(): Promise<import("rafi-spec").SessionAvailabilityV1>;
|
|
84
84
|
compact(): Promise<CompactResult>;
|
|
85
|
-
prepareAutoCompaction(thresholdPercent?: number): Promise<void>;
|
|
85
|
+
prepareAutoCompaction(thresholdPercent?: number): Promise<NativeAutoCompactionPolicy | void>;
|
|
86
|
+
autoCompactionPolicy(): NativeAutoCompactionPolicy | undefined;
|
|
86
87
|
drainNativeCompactions(): import("./adapters/types.js").NativeCompaction[];
|
|
87
88
|
restoreNativeCompactions(compactions: NativeCompaction[]): void;
|
|
88
89
|
contextUsageAfterNativeCompaction(compaction: NativeCompaction): Promise<ContextUsage | undefined>;
|
package/dist/statusReporter.js
CHANGED
|
@@ -178,6 +178,7 @@ export class RoleStatusAdapter {
|
|
|
178
178
|
validateSession() { return this.adapter.validateSession?.() ?? Promise.resolve({ version: 1, status: "unknown", checkedAt: new Date().toISOString(), reason: "legacy-unscoped" }); }
|
|
179
179
|
compact() { this.onActive(this.adapter); return this.adapter.compact?.() ?? Promise.resolve({ ok: false, error: "native compaction unavailable" }); }
|
|
180
180
|
prepareAutoCompaction(thresholdPercent) { return this.adapter.prepareAutoCompaction?.(thresholdPercent) ?? Promise.resolve(); }
|
|
181
|
+
autoCompactionPolicy() { return this.adapter.autoCompactionPolicy?.(); }
|
|
181
182
|
drainNativeCompactions() { return this.adapter.drainNativeCompactions?.() ?? []; }
|
|
182
183
|
restoreNativeCompactions(compactions) { this.adapter.restoreNativeCompactions?.(compactions); }
|
|
183
184
|
contextUsageAfterNativeCompaction(compaction) { return this.adapter.contextUsageAfterNativeCompaction?.(compaction) ?? Promise.resolve(undefined); }
|
package/package.json
CHANGED