@pentoshi/clai 3.8.20 → 3.8.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/dist/agent/confirm-port.d.ts +5 -2
- package/dist/agent/confirm-port.js +11 -5
- package/dist/agent/confirm-port.js.map +1 -1
- package/dist/agent/context-breakdown.d.ts +37 -0
- package/dist/agent/context-breakdown.js +145 -0
- package/dist/agent/context-breakdown.js.map +1 -0
- package/dist/agent/plan-decision.js +7 -3
- package/dist/agent/plan-decision.js.map +1 -1
- package/dist/agent/plan-tool.js +63 -20
- package/dist/agent/plan-tool.js.map +1 -1
- package/dist/agent/progress-pause-policy.d.ts +21 -0
- package/dist/agent/progress-pause-policy.js +28 -0
- package/dist/agent/progress-pause-policy.js.map +1 -0
- package/dist/agent/reliability-policy.d.ts +85 -0
- package/dist/agent/reliability-policy.js +158 -0
- package/dist/agent/reliability-policy.js.map +1 -0
- package/dist/agent/runner.js +352 -164
- package/dist/agent/runner.js.map +1 -1
- package/dist/agent/session-state.d.ts +11 -1
- package/dist/agent/session-state.js +22 -15
- package/dist/agent/session-state.js.map +1 -1
- package/dist/agent/stop-summary.js +3 -1
- package/dist/agent/stop-summary.js.map +1 -1
- package/dist/agent/task-evidence.js +13 -0
- package/dist/agent/task-evidence.js.map +1 -1
- package/dist/agent/tool-history.d.ts +12 -0
- package/dist/agent/tool-history.js +159 -0
- package/dist/agent/tool-history.js.map +1 -1
- package/dist/agent/tool-output-formatting.d.ts +4 -0
- package/dist/agent/tool-output-formatting.js +29 -4
- package/dist/agent/tool-output-formatting.js.map +1 -1
- package/dist/app/controllers/session-controller.d.ts +6 -0
- package/dist/app/controllers/session-controller.js +21 -1
- package/dist/app/controllers/session-controller.js.map +1 -1
- package/dist/app/ports/confirm-port.d.ts +1 -1
- package/dist/commands/providers.js +57 -26
- package/dist/commands/providers.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/llm/gemini.js +4 -1
- package/dist/llm/gemini.js.map +1 -1
- package/dist/llm/key-rotation.d.ts +52 -0
- package/dist/llm/key-rotation.js +122 -0
- package/dist/llm/key-rotation.js.map +1 -0
- package/dist/llm/provider.d.ts +2 -0
- package/dist/llm/provider.js +8 -0
- package/dist/llm/provider.js.map +1 -1
- package/dist/llm/router.d.ts +15 -2
- package/dist/llm/router.js +318 -125
- package/dist/llm/router.js.map +1 -1
- package/dist/prompts/embedded.js +1 -1
- package/dist/prompts/embedded.js.map +1 -1
- package/dist/prompts/index.d.ts +25 -0
- package/dist/prompts/index.js +61 -7
- package/dist/prompts/index.js.map +1 -1
- package/dist/prompts/system.agent.md +3 -1
- package/dist/repl/slash-commands.js +14 -8
- package/dist/repl/slash-commands.js.map +1 -1
- package/dist/repl.d.ts +4 -1
- package/dist/repl.js +12 -2
- package/dist/repl.js.map +1 -1
- package/dist/store/config.d.ts +18 -0
- package/dist/store/config.js +9 -0
- package/dist/store/config.js.map +1 -1
- package/dist/store/history.d.ts +8 -0
- package/dist/store/history.js +38 -0
- package/dist/store/history.js.map +1 -1
- package/dist/store/keys.d.ts +55 -0
- package/dist/store/keys.js +226 -21
- package/dist/store/keys.js.map +1 -1
- package/dist/store/logs.js +35 -12
- package/dist/store/logs.js.map +1 -1
- package/dist/store/paths.d.ts +13 -0
- package/dist/store/paths.js +23 -1
- package/dist/store/paths.js.map +1 -1
- package/dist/store/session-workspace.d.ts +79 -0
- package/dist/store/session-workspace.js +199 -0
- package/dist/store/session-workspace.js.map +1 -0
- package/dist/tools/definitions.js +9 -1
- package/dist/tools/definitions.js.map +1 -1
- package/dist/tools/http.d.ts +8 -0
- package/dist/tools/http.js +86 -2
- package/dist/tools/http.js.map +1 -1
- package/dist/tools/pentest-workflows.js +38 -19
- package/dist/tools/pentest-workflows.js.map +1 -1
- package/dist/tools/registry.js +25 -2
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/shell.d.ts +1 -1
- package/dist/tools/web/search.js +22 -3
- package/dist/tools/web/search.js.map +1 -1
- package/dist/tui/format-keys.js +29 -6
- package/dist/tui/format-keys.js.map +1 -1
- package/dist/tui-v2/app/command-handlers.js +1 -2
- package/dist/tui-v2/app/command-handlers.js.map +1 -1
- package/dist/tui-v2/app/commands/config-commands.d.ts +1 -2
- package/dist/tui-v2/app/commands/config-commands.js +1 -11
- package/dist/tui-v2/app/commands/config-commands.js.map +1 -1
- package/dist/tui-v2/app/commands/key-commands.d.ts +1 -1
- package/dist/tui-v2/app/commands/key-commands.js +148 -63
- package/dist/tui-v2/app/commands/key-commands.js.map +1 -1
- package/dist/tui-v2/app/commands/picker-commands.js +6 -0
- package/dist/tui-v2/app/commands/picker-commands.js.map +1 -1
- package/dist/tui-v2/bootstrap/composition-root.js +8 -5
- package/dist/tui-v2/bootstrap/composition-root.js.map +1 -1
- package/dist/tui-v2/bootstrap/overlay-ports.js +7 -2
- package/dist/tui-v2/bootstrap/overlay-ports.js.map +1 -1
- package/dist/tui-v2/components/modal/keys-modal.d.ts +19 -0
- package/dist/tui-v2/components/modal/keys-modal.js +203 -0
- package/dist/tui-v2/components/modal/keys-modal.js.map +1 -0
- package/dist/tui-v2/components/overlay/overlay-host.js +6 -2
- package/dist/tui-v2/components/overlay/overlay-host.js.map +1 -1
- package/dist/tui-v2/components/pager/pager-line.js +5 -2
- package/dist/tui-v2/components/pager/pager-line.js.map +1 -1
- package/dist/tui-v2/components/pager/pager.js +6 -3
- package/dist/tui-v2/components/pager/pager.js.map +1 -1
- package/dist/tui-v2/components/plan/use-pane-presence.d.ts +6 -4
- package/dist/tui-v2/components/plan/use-pane-presence.js +8 -45
- package/dist/tui-v2/components/plan/use-pane-presence.js.map +1 -1
- package/dist/tui-v2/components/transcript/assistant-message.js +4 -1
- package/dist/tui-v2/components/transcript/assistant-message.js.map +1 -1
- package/dist/tui-v2/components/transcript/compacted-row.js +1 -1
- package/dist/tui-v2/components/transcript/compacted-row.js.map +1 -1
- package/dist/tui-v2/components/transcript/file-diff-card.js +3 -23
- package/dist/tui-v2/components/transcript/file-diff-card.js.map +1 -1
- package/dist/tui-v2/components/transcript/linkable-text.js +9 -2
- package/dist/tui-v2/components/transcript/linkable-text.js.map +1 -1
- package/dist/tui-v2/components/transcript/selectable-line.d.ts +22 -0
- package/dist/tui-v2/components/transcript/selectable-line.js +24 -0
- package/dist/tui-v2/components/transcript/selectable-line.js.map +1 -0
- package/dist/tui-v2/components/transcript/thinking-block.js +3 -1
- package/dist/tui-v2/components/transcript/thinking-block.js.map +1 -1
- package/dist/tui-v2/components/transcript/tool-card.d.ts +5 -3
- package/dist/tui-v2/components/transcript/tool-card.js +39 -33
- package/dist/tui-v2/components/transcript/tool-card.js.map +1 -1
- package/dist/tui-v2/components/transcript/use-click-without-drag.js +4 -1
- package/dist/tui-v2/components/transcript/use-click-without-drag.js.map +1 -1
- package/dist/tui-v2/components/transcript/user-message.js +1 -1
- package/dist/tui-v2/components/transcript/user-message.js.map +1 -1
- package/dist/tui-v2/controllers/overlay-controller.d.ts +36 -0
- package/dist/tui-v2/controllers/overlay-controller.js +28 -0
- package/dist/tui-v2/controllers/overlay-controller.js.map +1 -1
- package/dist/tui-v2/rendering/batch-sections.d.ts +15 -4
- package/dist/tui-v2/rendering/batch-sections.js +157 -64
- package/dist/tui-v2/rendering/batch-sections.js.map +1 -1
- package/dist/tui-v2/rendering/format-help.js +1 -1
- package/dist/tui-v2/rendering/format-help.js.map +1 -1
- package/dist/tui-v2/rendering/open-tool-output.js +10 -7
- package/dist/tui-v2/rendering/open-tool-output.js.map +1 -1
- package/dist/tui-v2/rendering/pager-markdown.d.ts +9 -0
- package/dist/tui-v2/rendering/pager-markdown.js +46 -0
- package/dist/tui-v2/rendering/pager-markdown.js.map +1 -1
- package/dist/tui-v2/rendering/pager-view-policy.d.ts +6 -3
- package/dist/tui-v2/rendering/pager-view-policy.js +9 -13
- package/dist/tui-v2/rendering/pager-view-policy.js.map +1 -1
- package/dist/tui-v2/rendering/sanitize-display.js +3 -1
- package/dist/tui-v2/rendering/sanitize-display.js.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/version.generated.d.ts +2 -2
- package/dist/version.generated.js +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the progress governor recommends `paused_budget`, decide how the runner
|
|
3
|
+
* should react.
|
|
4
|
+
*
|
|
5
|
+
* - coding/build sessions: never hard-stop mid-turn (no "type continue" UX).
|
|
6
|
+
* - pentest / general: pause only after an interactive continue/stop confirm.
|
|
7
|
+
* - autoConfirm (-y): keep going without a prompt.
|
|
8
|
+
*/
|
|
9
|
+
export type ProgressPauseMode = "never" | "confirm";
|
|
10
|
+
export declare function progressPauseMode(input: {
|
|
11
|
+
/** Build / feature / coding work (including coding plans). */
|
|
12
|
+
codingSession: boolean;
|
|
13
|
+
/** CLI -y / non-interactive. */
|
|
14
|
+
autoConfirm: boolean;
|
|
15
|
+
}): ProgressPauseMode;
|
|
16
|
+
/** True when tool output is a protocol-repair placeholder, not live work. */
|
|
17
|
+
export declare function isProtocolPlaceholderOutput(output: string | undefined): boolean;
|
|
18
|
+
export declare function codingSessionFromContext(input: {
|
|
19
|
+
buildLike: boolean;
|
|
20
|
+
planKind?: string | undefined;
|
|
21
|
+
}): boolean;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* When the progress governor recommends `paused_budget`, decide how the runner
|
|
3
|
+
* should react.
|
|
4
|
+
*
|
|
5
|
+
* - coding/build sessions: never hard-stop mid-turn (no "type continue" UX).
|
|
6
|
+
* - pentest / general: pause only after an interactive continue/stop confirm.
|
|
7
|
+
* - autoConfirm (-y): keep going without a prompt.
|
|
8
|
+
*/
|
|
9
|
+
export function progressPauseMode(input) {
|
|
10
|
+
if (input.codingSession)
|
|
11
|
+
return "never";
|
|
12
|
+
if (input.autoConfirm)
|
|
13
|
+
return "never";
|
|
14
|
+
return "confirm";
|
|
15
|
+
}
|
|
16
|
+
/** True when tool output is a protocol-repair placeholder, not live work. */
|
|
17
|
+
export function isProtocolPlaceholderOutput(output) {
|
|
18
|
+
if (!output)
|
|
19
|
+
return false;
|
|
20
|
+
return (output.includes("[protocol] closed incomplete") ||
|
|
21
|
+
output.includes("history-repair") ||
|
|
22
|
+
/^\[protocol\]/i.test(output.trim()));
|
|
23
|
+
}
|
|
24
|
+
export function codingSessionFromContext(input) {
|
|
25
|
+
const kind = (input.planKind ?? "").toLowerCase();
|
|
26
|
+
return input.buildLike || kind === "coding";
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=progress-pause-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"progress-pause-policy.js","sourceRoot":"","sources":["../../src/agent/progress-pause-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,UAAU,iBAAiB,CAAC,KAKjC;IACC,IAAI,KAAK,CAAC,aAAa;QAAE,OAAO,OAAO,CAAC;IACxC,IAAI,KAAK,CAAC,WAAW;QAAE,OAAO,OAAO,CAAC;IACtC,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,2BAA2B,CAAC,MAA0B;IACpE,IAAI,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC1B,OAAO,CACL,MAAM,CAAC,QAAQ,CAAC,8BAA8B,CAAC;QAC/C,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC;QACjC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CACrC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,KAGxC;IACC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;IAClD,OAAO,KAAK,CAAC,SAAS,IAAI,IAAI,KAAK,QAAQ,CAAC;AAC9C,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reliability experiments from the architecture audit (E1–E6).
|
|
3
|
+
*
|
|
4
|
+
* Defaults are capability-preserving: they reduce unnecessary context / fragile
|
|
5
|
+
* free-tier overload without hard-truncating critical evidence or blocking free
|
|
6
|
+
* users. Every knob is config-backed and can be disabled independently.
|
|
7
|
+
*/
|
|
8
|
+
import type { ProviderId } from "../types.js";
|
|
9
|
+
/** Hard auto-compact ceiling — never raise soft past this. */
|
|
10
|
+
export declare const HARD_COMPACT_TOKEN_BUDGET = 100000;
|
|
11
|
+
/** E1 default: start compact earlier than the hard ceiling. */
|
|
12
|
+
export declare const DEFAULT_SOFT_COMPACT_TOKEN_BUDGET = 70000;
|
|
13
|
+
/** E2 default fs passthrough (was 400k). Full body always on disk when truncated. */
|
|
14
|
+
export declare const DEFAULT_FS_PASSTHROUGH_CAP_CHARS = 64000;
|
|
15
|
+
/** E4: warn when free-cloud context is this large. */
|
|
16
|
+
export declare const DEFAULT_FREE_TIER_WARN_TOKENS = 40000;
|
|
17
|
+
/** E4: stronger notice after this many consecutive free-tier stream failures. */
|
|
18
|
+
export declare const DEFAULT_FREE_TIER_FAIL_THRESHOLD = 2;
|
|
19
|
+
/** E3 floors — large enough for fs.write / salvage, lower than prior 32k default. */
|
|
20
|
+
export declare const ADAPTIVE_MAX_TOKENS_TOOL_STEP = 24576;
|
|
21
|
+
export declare const ADAPTIVE_MAX_TOKENS_LIGHT = 12288;
|
|
22
|
+
export declare const ADAPTIVE_MAX_TOKENS_FLOOR = 8192;
|
|
23
|
+
export declare const LEGACY_MAX_TOKENS = 32768;
|
|
24
|
+
export interface ReliabilityPolicy {
|
|
25
|
+
readonly softEarlyCompact: boolean;
|
|
26
|
+
readonly softCompactTokenBudget: number;
|
|
27
|
+
readonly hardCompactTokenBudget: number;
|
|
28
|
+
readonly fsPassthroughCapChars: number;
|
|
29
|
+
readonly adaptiveMaxTokens: boolean;
|
|
30
|
+
readonly freeTierContextGuard: boolean;
|
|
31
|
+
readonly freeTierWarnTokens: number;
|
|
32
|
+
readonly freeTierFailThreshold: number;
|
|
33
|
+
readonly toolResultDedup: boolean;
|
|
34
|
+
readonly slimNativePrompt: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** Resolve effective policy from config + optional env overrides. */
|
|
37
|
+
export declare function getReliabilityPolicy(): ReliabilityPolicy;
|
|
38
|
+
/**
|
|
39
|
+
* E1: token threshold that triggers auto-compact.
|
|
40
|
+
* Soft path fires earlier; hard budget is always the ceiling used when soft is off.
|
|
41
|
+
*/
|
|
42
|
+
export declare function autoCompactTriggerTokens(policy?: ReliabilityPolicy): number;
|
|
43
|
+
/**
|
|
44
|
+
* E3: max completion tokens for a model step.
|
|
45
|
+
* Tool-heavy steps keep room for large writes; light steps use a lower cap.
|
|
46
|
+
* Never goes below {@link ADAPTIVE_MAX_TOKENS_FLOOR}.
|
|
47
|
+
*/
|
|
48
|
+
export declare function resolveStepMaxTokens(input: {
|
|
49
|
+
nativeToolsActive: boolean;
|
|
50
|
+
toolsAttached: boolean;
|
|
51
|
+
recoveryNudge?: boolean | undefined;
|
|
52
|
+
policy?: ReliabilityPolicy | undefined;
|
|
53
|
+
}): number;
|
|
54
|
+
export declare function isFreeCloudProvider(provider: ProviderId): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* E4: advisory notices for free-tier + large context / repeated failures.
|
|
57
|
+
* Never blocks the request.
|
|
58
|
+
*/
|
|
59
|
+
export declare function freeTierGuardNotices(input: {
|
|
60
|
+
provider: ProviderId;
|
|
61
|
+
estimatedInputTokens: number;
|
|
62
|
+
consecutiveFailures: number;
|
|
63
|
+
policy?: ReliabilityPolicy | undefined;
|
|
64
|
+
}): string[];
|
|
65
|
+
/** Stable hash for E5 tool-result dedup (content only). */
|
|
66
|
+
export declare function hashToolResultContent(content: string): string;
|
|
67
|
+
/**
|
|
68
|
+
* E5: if identical tool output already appeared this turn, replace with a
|
|
69
|
+
* pointer so history does not grow with duplicate dumps. Full text remains
|
|
70
|
+
* available via artifact path when present.
|
|
71
|
+
*/
|
|
72
|
+
export declare function dedupeToolContextOutput(input: {
|
|
73
|
+
content: string;
|
|
74
|
+
toolName: string;
|
|
75
|
+
artifactPath?: string | undefined;
|
|
76
|
+
seenHashes: Map<string, {
|
|
77
|
+
toolName: string;
|
|
78
|
+
count: number;
|
|
79
|
+
}>;
|
|
80
|
+
policy?: ReliabilityPolicy | undefined;
|
|
81
|
+
}): {
|
|
82
|
+
content: string;
|
|
83
|
+
deduped: boolean;
|
|
84
|
+
hash: string;
|
|
85
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reliability experiments from the architecture audit (E1–E6).
|
|
3
|
+
*
|
|
4
|
+
* Defaults are capability-preserving: they reduce unnecessary context / fragile
|
|
5
|
+
* free-tier overload without hard-truncating critical evidence or blocking free
|
|
6
|
+
* users. Every knob is config-backed and can be disabled independently.
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { getConfig, providerCategory } from "../store/config.js";
|
|
10
|
+
import { AUTO_COMPACT_TOKEN_BUDGET } from "./context-manager.js";
|
|
11
|
+
/** Hard auto-compact ceiling — never raise soft past this. */
|
|
12
|
+
export const HARD_COMPACT_TOKEN_BUDGET = AUTO_COMPACT_TOKEN_BUDGET;
|
|
13
|
+
/** E1 default: start compact earlier than the hard ceiling. */
|
|
14
|
+
export const DEFAULT_SOFT_COMPACT_TOKEN_BUDGET = 70_000;
|
|
15
|
+
/** E2 default fs passthrough (was 400k). Full body always on disk when truncated. */
|
|
16
|
+
export const DEFAULT_FS_PASSTHROUGH_CAP_CHARS = 64_000;
|
|
17
|
+
/** E4: warn when free-cloud context is this large. */
|
|
18
|
+
export const DEFAULT_FREE_TIER_WARN_TOKENS = 40_000;
|
|
19
|
+
/** E4: stronger notice after this many consecutive free-tier stream failures. */
|
|
20
|
+
export const DEFAULT_FREE_TIER_FAIL_THRESHOLD = 2;
|
|
21
|
+
/** E3 floors — large enough for fs.write / salvage, lower than prior 32k default. */
|
|
22
|
+
export const ADAPTIVE_MAX_TOKENS_TOOL_STEP = 24_576;
|
|
23
|
+
export const ADAPTIVE_MAX_TOKENS_LIGHT = 12_288;
|
|
24
|
+
export const ADAPTIVE_MAX_TOKENS_FLOOR = 8_192;
|
|
25
|
+
export const LEGACY_MAX_TOKENS = 32_768;
|
|
26
|
+
function boolEnv(name) {
|
|
27
|
+
const v = process.env[name]?.trim().toLowerCase();
|
|
28
|
+
if (v === undefined || v === "")
|
|
29
|
+
return undefined;
|
|
30
|
+
if (v === "1" || v === "true" || v === "yes" || v === "on")
|
|
31
|
+
return true;
|
|
32
|
+
if (v === "0" || v === "false" || v === "no" || v === "off")
|
|
33
|
+
return false;
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
function intEnv(name) {
|
|
37
|
+
const v = process.env[name]?.trim();
|
|
38
|
+
if (!v)
|
|
39
|
+
return undefined;
|
|
40
|
+
const n = Number.parseInt(v, 10);
|
|
41
|
+
return Number.isFinite(n) ? n : undefined;
|
|
42
|
+
}
|
|
43
|
+
/** Resolve effective policy from config + optional env overrides. */
|
|
44
|
+
export function getReliabilityPolicy() {
|
|
45
|
+
const cfg = getConfig();
|
|
46
|
+
const softEarly = boolEnv("CLAI_SOFT_EARLY_COMPACT") ?? cfg.softEarlyCompact ?? true;
|
|
47
|
+
let softBudget = intEnv("CLAI_SOFT_COMPACT_TOKENS") ??
|
|
48
|
+
cfg.softCompactTokenBudget ??
|
|
49
|
+
DEFAULT_SOFT_COMPACT_TOKEN_BUDGET;
|
|
50
|
+
softBudget = Math.max(20_000, Math.min(softBudget, HARD_COMPACT_TOKEN_BUDGET));
|
|
51
|
+
let fsCap = intEnv("CLAI_FS_PASSTHROUGH_CHARS") ??
|
|
52
|
+
cfg.fsPassthroughCapChars ??
|
|
53
|
+
DEFAULT_FS_PASSTHROUGH_CAP_CHARS;
|
|
54
|
+
fsCap = Math.max(8_000, Math.min(fsCap, 400_000));
|
|
55
|
+
return {
|
|
56
|
+
softEarlyCompact: softEarly,
|
|
57
|
+
softCompactTokenBudget: softBudget,
|
|
58
|
+
hardCompactTokenBudget: HARD_COMPACT_TOKEN_BUDGET,
|
|
59
|
+
fsPassthroughCapChars: fsCap,
|
|
60
|
+
adaptiveMaxTokens: boolEnv("CLAI_ADAPTIVE_MAX_TOKENS") ?? cfg.adaptiveMaxTokens ?? true,
|
|
61
|
+
freeTierContextGuard: boolEnv("CLAI_FREE_TIER_GUARD") ?? cfg.freeTierContextGuard ?? true,
|
|
62
|
+
freeTierWarnTokens: intEnv("CLAI_FREE_TIER_WARN_TOKENS") ??
|
|
63
|
+
cfg.freeTierWarnTokens ??
|
|
64
|
+
DEFAULT_FREE_TIER_WARN_TOKENS,
|
|
65
|
+
freeTierFailThreshold: intEnv("CLAI_FREE_TIER_FAIL_THRESHOLD") ??
|
|
66
|
+
cfg.freeTierFailThreshold ??
|
|
67
|
+
DEFAULT_FREE_TIER_FAIL_THRESHOLD,
|
|
68
|
+
toolResultDedup: boolEnv("CLAI_TOOL_RESULT_DEDUP") ?? cfg.toolResultDedup ?? true,
|
|
69
|
+
slimNativePrompt: boolEnv("CLAI_SLIM_NATIVE_PROMPT") ?? cfg.slimNativePrompt ?? true,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* E1: token threshold that triggers auto-compact.
|
|
74
|
+
* Soft path fires earlier; hard budget is always the ceiling used when soft is off.
|
|
75
|
+
*/
|
|
76
|
+
export function autoCompactTriggerTokens(policy = getReliabilityPolicy()) {
|
|
77
|
+
if (!policy.softEarlyCompact)
|
|
78
|
+
return policy.hardCompactTokenBudget;
|
|
79
|
+
return Math.min(policy.softCompactTokenBudget, policy.hardCompactTokenBudget);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* E3: max completion tokens for a model step.
|
|
83
|
+
* Tool-heavy steps keep room for large writes; light steps use a lower cap.
|
|
84
|
+
* Never goes below {@link ADAPTIVE_MAX_TOKENS_FLOOR}.
|
|
85
|
+
*/
|
|
86
|
+
export function resolveStepMaxTokens(input) {
|
|
87
|
+
const policy = input.policy ?? getReliabilityPolicy();
|
|
88
|
+
if (!policy.adaptiveMaxTokens)
|
|
89
|
+
return LEGACY_MAX_TOKENS;
|
|
90
|
+
if (input.recoveryNudge) {
|
|
91
|
+
return Math.max(ADAPTIVE_MAX_TOKENS_FLOOR, ADAPTIVE_MAX_TOKENS_LIGHT);
|
|
92
|
+
}
|
|
93
|
+
if (input.toolsAttached || input.nativeToolsActive) {
|
|
94
|
+
return ADAPTIVE_MAX_TOKENS_TOOL_STEP;
|
|
95
|
+
}
|
|
96
|
+
return ADAPTIVE_MAX_TOKENS_LIGHT;
|
|
97
|
+
}
|
|
98
|
+
export function isFreeCloudProvider(provider) {
|
|
99
|
+
return providerCategory[provider] === "free-cloud";
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* E4: advisory notices for free-tier + large context / repeated failures.
|
|
103
|
+
* Never blocks the request.
|
|
104
|
+
*/
|
|
105
|
+
export function freeTierGuardNotices(input) {
|
|
106
|
+
const policy = input.policy ?? getReliabilityPolicy();
|
|
107
|
+
if (!policy.freeTierContextGuard)
|
|
108
|
+
return [];
|
|
109
|
+
if (!isFreeCloudProvider(input.provider))
|
|
110
|
+
return [];
|
|
111
|
+
const notices = [];
|
|
112
|
+
if (input.estimatedInputTokens >= policy.freeTierWarnTokens) {
|
|
113
|
+
notices.push(`Large context (~${input.estimatedInputTokens.toLocaleString()} tokens) on free-cloud model — disconnects and empty admissions are more common. Prefer /compact, a paid/local model, or shorter turns if this fails.`);
|
|
114
|
+
}
|
|
115
|
+
if (input.consecutiveFailures >= policy.freeTierFailThreshold) {
|
|
116
|
+
notices.push(`Free-cloud model failed ${input.consecutiveFailures} time(s) this turn. Switch with /model or /provider, or enable providerFallback for automatic recovery.`);
|
|
117
|
+
}
|
|
118
|
+
return notices;
|
|
119
|
+
}
|
|
120
|
+
/** Stable hash for E5 tool-result dedup (content only). */
|
|
121
|
+
export function hashToolResultContent(content) {
|
|
122
|
+
return createHash("sha256").update(content).digest("hex").slice(0, 16);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* E5: if identical tool output already appeared this turn, replace with a
|
|
126
|
+
* pointer so history does not grow with duplicate dumps. Full text remains
|
|
127
|
+
* available via artifact path when present.
|
|
128
|
+
*/
|
|
129
|
+
export function dedupeToolContextOutput(input) {
|
|
130
|
+
const policy = input.policy ?? getReliabilityPolicy();
|
|
131
|
+
const hash = hashToolResultContent(input.content);
|
|
132
|
+
if (!policy.toolResultDedup) {
|
|
133
|
+
return { content: input.content, deduped: false, hash };
|
|
134
|
+
}
|
|
135
|
+
// Tiny results are not worth pointer indirection.
|
|
136
|
+
if (input.content.length < 400) {
|
|
137
|
+
input.seenHashes.set(hash, {
|
|
138
|
+
toolName: input.toolName,
|
|
139
|
+
count: (input.seenHashes.get(hash)?.count ?? 0) + 1,
|
|
140
|
+
});
|
|
141
|
+
return { content: input.content, deduped: false, hash };
|
|
142
|
+
}
|
|
143
|
+
const prior = input.seenHashes.get(hash);
|
|
144
|
+
if (!prior) {
|
|
145
|
+
input.seenHashes.set(hash, { toolName: input.toolName, count: 1 });
|
|
146
|
+
return { content: input.content, deduped: false, hash };
|
|
147
|
+
}
|
|
148
|
+
prior.count += 1;
|
|
149
|
+
const artifact = input.artifactPath
|
|
150
|
+
? ` Full output: ${input.artifactPath}`
|
|
151
|
+
: "";
|
|
152
|
+
const head = input.content.slice(0, 200).replace(/\s+/g, " ").trim();
|
|
153
|
+
const content = `[duplicate tool output — identical to earlier ${prior.toolName} this turn; hash=${hash}]${artifact}\n` +
|
|
154
|
+
`Preview: ${head}${input.content.length > 200 ? "…" : ""}\n` +
|
|
155
|
+
`Re-read the prior tool result or artifact if you need the full body; do not assume it changed.`;
|
|
156
|
+
return { content, deduped: true, hash };
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=reliability-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|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