claude-code-infinite 1.0.11 → 1.0.16
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 +214 -47
- package/dist/cc-request.d.ts +94 -0
- package/dist/cc-request.d.ts.map +1 -0
- package/dist/cc-request.js +194 -0
- package/dist/cc-request.js.map +1 -0
- package/dist/claude-env.d.ts +30 -0
- package/dist/claude-env.d.ts.map +1 -0
- package/dist/claude-env.js +55 -0
- package/dist/claude-env.js.map +1 -0
- package/dist/cli-args.d.ts +32 -0
- package/dist/cli-args.d.ts.map +1 -0
- package/dist/cli-args.js +72 -0
- package/dist/cli-args.js.map +1 -0
- package/dist/cli-lifecycle.d.ts +17 -0
- package/dist/cli-lifecycle.d.ts.map +1 -0
- package/dist/cli-lifecycle.js +30 -0
- package/dist/cli-lifecycle.js.map +1 -0
- package/dist/cli-main.d.ts +15 -0
- package/dist/cli-main.d.ts.map +1 -0
- package/dist/cli-main.js +464 -0
- package/dist/cli-main.js.map +1 -0
- package/dist/cli.js +13 -178
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +3 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +29 -3
- package/dist/config.js.map +1 -1
- package/dist/count-tokens.d.ts +78 -0
- package/dist/count-tokens.d.ts.map +1 -0
- package/dist/count-tokens.js +277 -0
- package/dist/count-tokens.js.map +1 -0
- package/dist/final-index.d.ts +10 -0
- package/dist/final-index.d.ts.map +1 -0
- package/dist/final-index.js +37 -0
- package/dist/final-index.js.map +1 -0
- package/dist/hooks.d.ts +239 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +618 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/memtree-fetch.d.ts +24 -0
- package/dist/memtree-fetch.d.ts.map +1 -0
- package/dist/memtree-fetch.js +121 -0
- package/dist/memtree-fetch.js.map +1 -0
- package/dist/memtree-finder.d.ts +99 -0
- package/dist/memtree-finder.d.ts.map +1 -0
- package/dist/memtree-finder.js +235 -0
- package/dist/memtree-finder.js.map +1 -0
- package/dist/memtree-links.d.ts +16 -0
- package/dist/memtree-links.d.ts.map +1 -0
- package/dist/memtree-links.js +66 -0
- package/dist/memtree-links.js.map +1 -0
- package/dist/memtree-mcp-config.d.ts +28 -0
- package/dist/memtree-mcp-config.d.ts.map +1 -0
- package/dist/memtree-mcp-config.js +121 -0
- package/dist/memtree-mcp-config.js.map +1 -0
- package/dist/memtree-mcp.d.ts +265 -0
- package/dist/memtree-mcp.d.ts.map +1 -0
- package/dist/memtree-mcp.js +667 -0
- package/dist/memtree-mcp.js.map +1 -0
- package/dist/memtree-newest.d.ts +74 -0
- package/dist/memtree-newest.d.ts.map +1 -0
- package/dist/memtree-newest.js +217 -0
- package/dist/memtree-newest.js.map +1 -0
- package/dist/memtree-tools.d.ts +105 -0
- package/dist/memtree-tools.d.ts.map +1 -0
- package/dist/memtree-tools.js +408 -0
- package/dist/memtree-tools.js.map +1 -0
- package/dist/memtree.d.ts +430 -0
- package/dist/memtree.d.ts.map +1 -0
- package/dist/memtree.js +1286 -0
- package/dist/memtree.js.map +1 -0
- package/dist/notices.d.ts +177 -0
- package/dist/notices.d.ts.map +1 -0
- package/dist/notices.js +469 -0
- package/dist/notices.js.map +1 -0
- package/dist/payment-gate.d.ts +53 -0
- package/dist/payment-gate.d.ts.map +1 -0
- package/dist/payment-gate.js +97 -0
- package/dist/payment-gate.js.map +1 -0
- package/dist/project-meta.d.ts +15 -0
- package/dist/project-meta.d.ts.map +1 -0
- package/dist/project-meta.js +80 -0
- package/dist/project-meta.js.map +1 -0
- package/dist/prompt-accounting.d.ts +12 -0
- package/dist/prompt-accounting.d.ts.map +1 -0
- package/dist/prompt-accounting.js +70 -0
- package/dist/prompt-accounting.js.map +1 -0
- package/dist/proxy.d.ts +204 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +4299 -0
- package/dist/proxy.js.map +1 -0
- package/dist/reqlog.d.ts +427 -0
- package/dist/reqlog.d.ts.map +1 -0
- package/dist/reqlog.js +146 -0
- package/dist/reqlog.js.map +1 -0
- package/dist/request-sizing.d.ts +74 -0
- package/dist/request-sizing.d.ts.map +1 -0
- package/dist/request-sizing.js +121 -0
- package/dist/request-sizing.js.map +1 -0
- package/dist/resume-repair-file.d.ts +17 -0
- package/dist/resume-repair-file.d.ts.map +1 -0
- package/dist/resume-repair-file.js +100 -0
- package/dist/resume-repair-file.js.map +1 -0
- package/dist/resume-repair.d.ts +27 -0
- package/dist/resume-repair.d.ts.map +1 -0
- package/dist/resume-repair.js +198 -0
- package/dist/resume-repair.js.map +1 -0
- package/dist/route-cache.d.ts +5 -0
- package/dist/route-cache.d.ts.map +1 -0
- package/dist/route-cache.js +63 -0
- package/dist/route-cache.js.map +1 -0
- package/dist/route-fallback.d.ts +67 -0
- package/dist/route-fallback.d.ts.map +1 -0
- package/dist/route-fallback.js +126 -0
- package/dist/route-fallback.js.map +1 -0
- package/dist/route-identity.d.ts +6 -0
- package/dist/route-identity.d.ts.map +1 -0
- package/dist/route-identity.js +100 -0
- package/dist/route-identity.js.map +1 -0
- package/dist/transcript-usage.d.ts +57 -0
- package/dist/transcript-usage.d.ts.map +1 -0
- package/dist/transcript-usage.js +570 -0
- package/dist/transcript-usage.js.map +1 -0
- package/dist/turns.d.ts +77 -0
- package/dist/turns.d.ts.map +1 -0
- package/dist/turns.js +330 -0
- package/dist/turns.js.map +1 -0
- package/dist/update-check.d.ts +38 -0
- package/dist/update-check.d.ts.map +1 -0
- package/dist/update-check.js +67 -0
- package/dist/update-check.js.map +1 -0
- package/package.json +6 -2
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** After attempting compression at the soft budget, forward input that fits
|
|
2
|
+
* the model's native context together with its output reservation (the full
|
|
3
|
+
* max_tokens, or a floor on Claude 4.5+: see outputReservation). */
|
|
4
|
+
export declare function fitsFallbackBudget(inputTokens: number, outputTokens: number, budgetTokens: number, contextTokens: number, model?: string): boolean;
|
|
5
|
+
export interface RouteFallbackError {
|
|
6
|
+
status: 503 | 400;
|
|
7
|
+
attempt: number;
|
|
8
|
+
headers: Record<string, string>;
|
|
9
|
+
body: {
|
|
10
|
+
type: "error";
|
|
11
|
+
error: {
|
|
12
|
+
type: string;
|
|
13
|
+
message: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/** How long a lane may wait for MemTree to finish indexing before refusing. */
|
|
18
|
+
export declare const INDEX_WAIT_DEADLINE_MS: number;
|
|
19
|
+
/** Seconds Claude Code waits between retries while the index catches up. */
|
|
20
|
+
export declare const INDEX_WAIT_RETRY_AFTER_SECONDS = 30;
|
|
21
|
+
export declare const FINAL_REFUSAL_MESSAGE: string;
|
|
22
|
+
export interface FallbackFailureContext {
|
|
23
|
+
/**
|
|
24
|
+
* This request's compress result did not fit only because MemTree's index
|
|
25
|
+
* is behind the conversation (most of it still verbatim). Retries then wait
|
|
26
|
+
* for indexing instead of spending the strike budget.
|
|
27
|
+
*/
|
|
28
|
+
awaitingIndex?: boolean;
|
|
29
|
+
now?: number;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Claude Code 2.1.288 retries 503 itself, even with SDK maxRetries=0.
|
|
33
|
+
* 529 has extra overload handling (including indefinite watchdog retries).
|
|
34
|
+
* Use ordinary 503 retries and bound the episode in the proxy itself.
|
|
35
|
+
* Successful delivery ends an episode; hook events and elapsed time do not.
|
|
36
|
+
* An episode waiting on the index is bounded by wall clock instead of strikes.
|
|
37
|
+
*/
|
|
38
|
+
export declare class RouteFallbackFailures {
|
|
39
|
+
private readonly capacity;
|
|
40
|
+
private readonly indexWaitMs;
|
|
41
|
+
private readonly failures;
|
|
42
|
+
/** Lane -> when its index wait began (its deadline is fixed from then). */
|
|
43
|
+
private readonly indexWaits;
|
|
44
|
+
constructor(capacity?: number, indexWaitMs?: number);
|
|
45
|
+
fail(lane: string, context?: FallbackFailureContext): RouteFallbackError;
|
|
46
|
+
succeeded(lane: string): void;
|
|
47
|
+
/** The bounded three-strike episode: 503, 503, then 400 until delivery. */
|
|
48
|
+
private strike;
|
|
49
|
+
/**
|
|
50
|
+
* A 503 while the lane's wait is within its deadline; a 400 once it passes.
|
|
51
|
+
* The deadline is fixed when the wait starts and only a delivery clears it:
|
|
52
|
+
* an expired wait becomes a terminal strike state, and an active wait is
|
|
53
|
+
* never evicted. A lane already refused, or arriving while every wait slot
|
|
54
|
+
* is active, gets no wait (undefined) and falls back to the strikes.
|
|
55
|
+
*/
|
|
56
|
+
private waitForIndex;
|
|
57
|
+
private indexWaitError;
|
|
58
|
+
/** Free the slots of waits past their deadline, keeping them refused. */
|
|
59
|
+
private retireExpiredWaits;
|
|
60
|
+
/**
|
|
61
|
+
* An expired wait's lane moves to the terminal strike state. If the strike
|
|
62
|
+
* table is full the wait keeps its slot instead (still expired, still
|
|
63
|
+
* refused), so no lane can be re-admitted with a fresh deadline.
|
|
64
|
+
*/
|
|
65
|
+
private retire;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=route-fallback.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-fallback.d.ts","sourceRoot":"","sources":["../src/route-fallback.ts"],"names":[],"mappings":"AAGA;;oEAEoE;AACpE,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAKT;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,GAAG,GAAG,GAAG,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE;QAAE,IAAI,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CACnE;AAED,+EAA+E;AAC/E,eAAO,MAAM,sBAAsB,QAAc,CAAC;AAClD,4EAA4E;AAC5E,eAAO,MAAM,8BAA8B,KAAK,CAAC;AAEjD,eAAO,MAAM,qBAAqB,QAI+B,CAAC;AAElE,MAAM,WAAW,sBAAsB;IACrC;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;GAMG;AACH,qBAAa,qBAAqB;IAM9B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAN9B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,2EAA2E;IAC3E,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA6B;gBAGrC,QAAQ,SAAM,EACd,WAAW,SAAyB;IAGvD,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,sBAA2B,GAAG,kBAAkB;IAQ5E,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IAK7B,2EAA2E;IAC3E,OAAO,CAAC,MAAM;IAYd;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAcpB,OAAO,CAAC,cAAc;IAKtB,yEAAyE;IACzE,OAAO,CAAC,kBAAkB;IAM1B;;;;OAIG;IACH,OAAO,CAAC,MAAM;CAKf"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { fitsNative, outputReservation } from "./request-sizing.js";
|
|
2
|
+
import { MEMTREE_COMPACT_COMMAND, MEMTREE_VIEW_COMMAND, SESSION_PLUGIN_NAME } from "./hooks.js";
|
|
3
|
+
/** After attempting compression at the soft budget, forward input that fits
|
|
4
|
+
* the model's native context together with its output reservation (the full
|
|
5
|
+
* max_tokens, or a floor on Claude 4.5+: see outputReservation). */
|
|
6
|
+
export function fitsFallbackBudget(inputTokens, outputTokens, budgetTokens, contextTokens, model) {
|
|
7
|
+
return [inputTokens, outputTokens, budgetTokens, contextTokens].every((value) => Number.isFinite(value) && value >= 0) && fitsNative(inputTokens, { budget: budgetTokens, context: contextTokens,
|
|
8
|
+
output: outputReservation(model, outputTokens) });
|
|
9
|
+
}
|
|
10
|
+
/** How long a lane may wait for MemTree to finish indexing before refusing. */
|
|
11
|
+
export const INDEX_WAIT_DEADLINE_MS = 10 * 60_000;
|
|
12
|
+
/** Seconds Claude Code waits between retries while the index catches up. */
|
|
13
|
+
export const INDEX_WAIT_RETRY_AFTER_SECONDS = 30;
|
|
14
|
+
export const FINAL_REFUSAL_MESSAGE = "MemTree couldn't fit this request in the model's context window. If MemTree is " +
|
|
15
|
+
`still indexing a recent change (see the session link from /${SESSION_PLUGIN_NAME}:` +
|
|
16
|
+
`${MEMTREE_VIEW_COMMAND}), wait a minute and retry; otherwise run ` +
|
|
17
|
+
`/${SESSION_PLUGIN_NAME}:${MEMTREE_COMPACT_COMMAND} or /clear.`;
|
|
18
|
+
/**
|
|
19
|
+
* Claude Code 2.1.288 retries 503 itself, even with SDK maxRetries=0.
|
|
20
|
+
* 529 has extra overload handling (including indefinite watchdog retries).
|
|
21
|
+
* Use ordinary 503 retries and bound the episode in the proxy itself.
|
|
22
|
+
* Successful delivery ends an episode; hook events and elapsed time do not.
|
|
23
|
+
* An episode waiting on the index is bounded by wall clock instead of strikes.
|
|
24
|
+
*/
|
|
25
|
+
export class RouteFallbackFailures {
|
|
26
|
+
capacity;
|
|
27
|
+
indexWaitMs;
|
|
28
|
+
failures = new Map();
|
|
29
|
+
/** Lane -> when its index wait began (its deadline is fixed from then). */
|
|
30
|
+
indexWaits = new Map();
|
|
31
|
+
constructor(capacity = 128, indexWaitMs = INDEX_WAIT_DEADLINE_MS) {
|
|
32
|
+
this.capacity = capacity;
|
|
33
|
+
this.indexWaitMs = indexWaitMs;
|
|
34
|
+
}
|
|
35
|
+
fail(lane, context = {}) {
|
|
36
|
+
if (context.awaitingIndex) {
|
|
37
|
+
const waiting = this.waitForIndex(lane, context.now ?? Date.now());
|
|
38
|
+
if (waiting)
|
|
39
|
+
return waiting;
|
|
40
|
+
}
|
|
41
|
+
return this.strike(lane);
|
|
42
|
+
}
|
|
43
|
+
succeeded(lane) {
|
|
44
|
+
this.failures.delete(lane);
|
|
45
|
+
this.indexWaits.delete(lane);
|
|
46
|
+
}
|
|
47
|
+
/** The bounded three-strike episode: 503, 503, then 400 until delivery. */
|
|
48
|
+
strike(lane) {
|
|
49
|
+
const previous = this.failures.get(lane);
|
|
50
|
+
// Fail closed when full rather than evicting a lane and granting it
|
|
51
|
+
// another retry budget. A successful lane frees its slot.
|
|
52
|
+
const attempt = previous === undefined && this.failures.size >= this.capacity
|
|
53
|
+
? 3 : Math.min((previous ?? 0) + 1, 3);
|
|
54
|
+
if (previous !== undefined || this.failures.size < this.capacity) {
|
|
55
|
+
this.failures.set(lane, attempt);
|
|
56
|
+
}
|
|
57
|
+
return attempt <= 2 ? retryError(attempt, "1", RETRY_MESSAGE) : refusal(attempt);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A 503 while the lane's wait is within its deadline; a 400 once it passes.
|
|
61
|
+
* The deadline is fixed when the wait starts and only a delivery clears it:
|
|
62
|
+
* an expired wait becomes a terminal strike state, and an active wait is
|
|
63
|
+
* never evicted. A lane already refused, or arriving while every wait slot
|
|
64
|
+
* is active, gets no wait (undefined) and falls back to the strikes.
|
|
65
|
+
*/
|
|
66
|
+
waitForIndex(lane, now) {
|
|
67
|
+
const wait = this.indexWaits.get(lane);
|
|
68
|
+
if (wait === undefined) {
|
|
69
|
+
if ((this.failures.get(lane) ?? 0) >= 3)
|
|
70
|
+
return undefined;
|
|
71
|
+
this.retireExpiredWaits(now);
|
|
72
|
+
if (this.indexWaits.size >= this.capacity)
|
|
73
|
+
return undefined;
|
|
74
|
+
this.indexWaits.set(lane, now);
|
|
75
|
+
return this.indexWaitError(lane);
|
|
76
|
+
}
|
|
77
|
+
if (now - wait < this.indexWaitMs)
|
|
78
|
+
return this.indexWaitError(lane);
|
|
79
|
+
this.retire(lane);
|
|
80
|
+
return refusal(3);
|
|
81
|
+
}
|
|
82
|
+
indexWaitError(lane) {
|
|
83
|
+
return retryError(this.failures.get(lane) ?? 0, String(INDEX_WAIT_RETRY_AFTER_SECONDS), INDEX_WAIT_MESSAGE);
|
|
84
|
+
}
|
|
85
|
+
/** Free the slots of waits past their deadline, keeping them refused. */
|
|
86
|
+
retireExpiredWaits(now) {
|
|
87
|
+
for (const [lane, started] of this.indexWaits) {
|
|
88
|
+
if (now - started >= this.indexWaitMs)
|
|
89
|
+
this.retire(lane);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* An expired wait's lane moves to the terminal strike state. If the strike
|
|
94
|
+
* table is full the wait keeps its slot instead (still expired, still
|
|
95
|
+
* refused), so no lane can be re-admitted with a fresh deadline.
|
|
96
|
+
*/
|
|
97
|
+
retire(lane) {
|
|
98
|
+
if (!this.failures.has(lane) && this.failures.size >= this.capacity)
|
|
99
|
+
return;
|
|
100
|
+
this.failures.set(lane, 3);
|
|
101
|
+
this.indexWaits.delete(lane);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const RETRY_MESSAGE = "MemTree could not produce a usable compressed request; retrying within a bounded limit.";
|
|
105
|
+
const INDEX_WAIT_MESSAGE = "MemTree is still indexing this conversation, so it does not fit the model's context " +
|
|
106
|
+
"window yet; retrying once indexing catches up.";
|
|
107
|
+
function retryError(attempt, retryAfter, message) {
|
|
108
|
+
return {
|
|
109
|
+
status: 503,
|
|
110
|
+
attempt,
|
|
111
|
+
headers: { "retry-after": retryAfter, "x-should-retry": "true" },
|
|
112
|
+
body: { type: "error", error: { type: "api_error", message } },
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
function refusal(attempt) {
|
|
116
|
+
return {
|
|
117
|
+
status: 400,
|
|
118
|
+
attempt,
|
|
119
|
+
headers: { "x-should-retry": "false" },
|
|
120
|
+
body: {
|
|
121
|
+
type: "error",
|
|
122
|
+
error: { type: "invalid_request_error", message: FINAL_REFUSAL_MESSAGE },
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=route-fallback.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-fallback.js","sourceRoot":"","sources":["../src/route-fallback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEhG;;oEAEoE;AACpE,MAAM,UAAU,kBAAkB,CAChC,WAAmB,EACnB,YAAoB,EACpB,YAAoB,EACpB,aAAqB,EACrB,KAAc;IAEd,OAAO,CAAC,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC,KAAK,CACnE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAChD,IAAI,UAAU,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,aAAa;QACzE,MAAM,EAAE,iBAAiB,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,CAAC,CAAC;AACtD,CAAC;AASD,+EAA+E;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,GAAG,MAAM,CAAC;AAClD,4EAA4E;AAC5E,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAC;AAEjD,MAAM,CAAC,MAAM,qBAAqB,GAChC,iFAAiF;IACjF,8DAA8D,mBAAmB,GAAG;IACpF,GAAG,oBAAoB,4CAA4C;IACnE,IAAI,mBAAmB,IAAI,uBAAuB,aAAa,CAAC;AAYlE;;;;;;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E;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Message } from "./turns.js";
|
|
2
|
+
/** Hash each incoming message once, then reuse it across route candidates/checks. */
|
|
3
|
+
export declare function routeMessageHash(message: Message): string;
|
|
4
|
+
/** Stable prefixes span turns in which Claude can omit earlier thinking blocks. */
|
|
5
|
+
export declare function stablePrefixMessageHash(message: Message): string;
|
|
6
|
+
//# sourceMappingURL=route-identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-identity.d.ts","sourceRoot":"","sources":["../src/route-identity.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAOnE,qFAAqF;AACrF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAEzD;AAED,mFAAmF;AACnF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAKhE"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { stripSystemReminderText } from "./turns.js";
|
|
3
|
+
// Request messages are immutable snapshots. Weak keys retain no completed request.
|
|
4
|
+
// Route installation stores these digests, not the original megabytes of history.
|
|
5
|
+
const routeHashes = new WeakMap();
|
|
6
|
+
const stableHashes = new WeakMap();
|
|
7
|
+
/** Hash each incoming message once, then reuse it across route candidates/checks. */
|
|
8
|
+
export function routeMessageHash(message) {
|
|
9
|
+
return messageHash(message, false);
|
|
10
|
+
}
|
|
11
|
+
/** Stable prefixes span turns in which Claude can omit earlier thinking blocks. */
|
|
12
|
+
export function stablePrefixMessageHash(message) {
|
|
13
|
+
if (message.role !== "assistant" || !Array.isArray(message.content)) {
|
|
14
|
+
return routeMessageHash(message);
|
|
15
|
+
}
|
|
16
|
+
return messageHash(message, true);
|
|
17
|
+
}
|
|
18
|
+
function messageHash(message, stable) {
|
|
19
|
+
const cache = stable ? stableHashes : routeHashes;
|
|
20
|
+
const cached = cache.get(message);
|
|
21
|
+
if (cached !== undefined)
|
|
22
|
+
return cached;
|
|
23
|
+
let content = message.content;
|
|
24
|
+
if (stable && Array.isArray(content)) {
|
|
25
|
+
content = content.filter((part) => part?.type !== "thinking" && part?.type !== "redacted_thinking");
|
|
26
|
+
}
|
|
27
|
+
const blocks = typeof content === "string" ? [{ type: "text", text: content }] : content;
|
|
28
|
+
const normalized = { ...message, content: stripBlockCache(normalizeReminders(blocks)) };
|
|
29
|
+
const hash = createHash("sha256");
|
|
30
|
+
updateCanonical(hash, normalized);
|
|
31
|
+
const digest = hash.digest("hex");
|
|
32
|
+
cache.set(message, digest);
|
|
33
|
+
return digest;
|
|
34
|
+
}
|
|
35
|
+
/** Same transform for stored and incoming messages, including nested tool results. */
|
|
36
|
+
function normalizeReminders(content) {
|
|
37
|
+
if (typeof content === "string")
|
|
38
|
+
return stripSystemReminderText(content);
|
|
39
|
+
if (!Array.isArray(content))
|
|
40
|
+
return content;
|
|
41
|
+
return content.map((part) => {
|
|
42
|
+
if (typeof part === "string")
|
|
43
|
+
return stripSystemReminderText(part);
|
|
44
|
+
if (!part || typeof part !== "object")
|
|
45
|
+
return part;
|
|
46
|
+
if (part.type === "text" && typeof part.text === "string") {
|
|
47
|
+
return { ...part, text: stripSystemReminderText(part.text) };
|
|
48
|
+
}
|
|
49
|
+
if (part.type === "tool_result") {
|
|
50
|
+
return { ...part, content: normalizeReminders(part.content) };
|
|
51
|
+
}
|
|
52
|
+
return part;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** Cache metadata on blocks is incidental; identically named tool input keys aren't. */
|
|
56
|
+
function stripBlockCache(content) {
|
|
57
|
+
if (Array.isArray(content))
|
|
58
|
+
return content.map(stripBlockCache);
|
|
59
|
+
if (!content || typeof content !== "object")
|
|
60
|
+
return content;
|
|
61
|
+
const { cache_control: _ignored, ...block } = content;
|
|
62
|
+
return block;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Typed, length-framed canonical encoding avoids serializing large strings twice.
|
|
66
|
+
* UTF-16 preserves lone surrogates too; UTF-8 would equate them with U+FFFD.
|
|
67
|
+
* This is a process-local identity digest, not a wire-format hash.
|
|
68
|
+
*/
|
|
69
|
+
function updateCanonical(hash, value) {
|
|
70
|
+
if (value === null || value === undefined) {
|
|
71
|
+
hash.update("n");
|
|
72
|
+
}
|
|
73
|
+
else if (typeof value === "string") {
|
|
74
|
+
hash.update(`s${value.length}:`).update(value, "utf16le");
|
|
75
|
+
}
|
|
76
|
+
else if (typeof value === "number") {
|
|
77
|
+
hash.update(Number.isFinite(value) ? `d${String(value)};` : "n");
|
|
78
|
+
}
|
|
79
|
+
else if (typeof value === "boolean") {
|
|
80
|
+
hash.update(value ? "t" : "f");
|
|
81
|
+
}
|
|
82
|
+
else if (Array.isArray(value)) {
|
|
83
|
+
hash.update(`a${value.length}:`);
|
|
84
|
+
for (const item of value)
|
|
85
|
+
updateCanonical(hash, item);
|
|
86
|
+
}
|
|
87
|
+
else if (typeof value === "object") {
|
|
88
|
+
const object = value;
|
|
89
|
+
const keys = Object.keys(object).filter((key) => object[key] !== undefined).sort();
|
|
90
|
+
hash.update(`o${keys.length}:`);
|
|
91
|
+
for (const key of keys) {
|
|
92
|
+
updateCanonical(hash, key);
|
|
93
|
+
updateCanonical(hash, object[key]);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
throw new TypeError("Route identity requires JSON message data");
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=route-identity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"route-identity.js","sourceRoot":"","sources":["../src/route-identity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAgB,MAAM,YAAY,CAAC;AAEnE,mFAAmF;AACnF,kFAAkF;AAClF,MAA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eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC;SAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,KAAgC,CAAC;QAChD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC;QACnF,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAChC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,eAAe,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YAC3B,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,SAAS,CAAC,2CAA2C,CAAC,CAAC;IACnE,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { Message } from "./turns.js";
|
|
2
|
+
export interface ResponseUsage {
|
|
3
|
+
output_tokens: number;
|
|
4
|
+
thinking_tokens: number;
|
|
5
|
+
input_tokens?: number;
|
|
6
|
+
cache_read_input_tokens?: number;
|
|
7
|
+
cache_creation_input_tokens?: number;
|
|
8
|
+
}
|
|
9
|
+
/** Keyed by the assistant message's position in the list sent to MemTree. */
|
|
10
|
+
export type MessageUsage = Record<string, ResponseUsage>;
|
|
11
|
+
/** ISO 8601 time of each message the transcript knows, keyed like MessageUsage. */
|
|
12
|
+
export type MessageTimes = Record<string, string>;
|
|
13
|
+
export interface TranscriptUsageSource {
|
|
14
|
+
/** Usage for each assistant message in `messages` that the transcript knows. */
|
|
15
|
+
usageFor(sessionId: string, messages: Message[], agentId?: string): MessageUsage;
|
|
16
|
+
/**
|
|
17
|
+
* When Claude Code wrote each message in `messages` that the transcript
|
|
18
|
+
* knows; a subagent's (`agentId`) from its own transcript.
|
|
19
|
+
*/
|
|
20
|
+
timesFor?(sessionId: string, messages: Message[], agentId?: string): MessageTimes;
|
|
21
|
+
/**
|
|
22
|
+
* The session's last assistant reply when it made no tool call (the answer
|
|
23
|
+
* a turn ended with), as a message; read to the transcript's end.
|
|
24
|
+
*/
|
|
25
|
+
finalReply?(sessionId: string): Message | undefined;
|
|
26
|
+
finalReplyAsync?(sessionId: string, signal?: AbortSignal): Promise<Message | undefined>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Reads transcripts incrementally: each session's file is opened once and
|
|
30
|
+
* only the bytes appended since the last call are parsed.
|
|
31
|
+
*/
|
|
32
|
+
export declare class ClaudeTranscriptUsage implements TranscriptUsageSource {
|
|
33
|
+
private readonly projectsDir;
|
|
34
|
+
private readonly sessions;
|
|
35
|
+
constructor(projectsDir?: string);
|
|
36
|
+
usageFor(sessionId: string, messages: Message[], agentId?: string): MessageUsage;
|
|
37
|
+
/**
|
|
38
|
+
* Reads a session's transcript to its end now, off the request path. A
|
|
39
|
+
* lookup reads one bounded chunk, so without this the first requests after
|
|
40
|
+
* resuming a long session see only its oldest responses and undercount the
|
|
41
|
+
* thinking MemTree's budget check relies on. Best effort: never throws.
|
|
42
|
+
*/
|
|
43
|
+
catchUp(sessionId: string): void;
|
|
44
|
+
timesFor(sessionId: string, messages: Message[], agentId?: string): MessageTimes;
|
|
45
|
+
finalReply(sessionId: string): Message | undefined;
|
|
46
|
+
finalReplyAsync(sessionId: string, signal?: AbortSignal): Promise<Message | undefined>;
|
|
47
|
+
private indexFor;
|
|
48
|
+
}
|
|
49
|
+
/** `$CLAUDE_CONFIG_DIR/projects`, else `~/.claude/projects`. */
|
|
50
|
+
export declare function defaultProjectsDir(env?: NodeJS.ProcessEnv): string;
|
|
51
|
+
/**
|
|
52
|
+
* The session's transcript in whichever project directory holds it, or with
|
|
53
|
+
* `agentId`, that subagent's. The id is accepted with or without its `agent-`
|
|
54
|
+
* file prefix.
|
|
55
|
+
*/
|
|
56
|
+
export declare function findTranscript(projectsDir: string, sessionId: string, agentId?: string): string | undefined;
|
|
57
|
+
//# sourceMappingURL=transcript-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transcript-usage.d.ts","sourceRoot":"","sources":["../src/transcript-usage.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,2BAA2B,CAAC,EAAE,MAAM,CAAC;CACtC;AAED,6EAA6E;AAC7E,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;AAKzD,mFAAmF;AACnF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAYlD,MAAM,WAAW,qBAAqB;IACpC,gFAAgF;IAChF,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IACjF;;;OAGG;IACH,QAAQ,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAClF;;;OAGG;IACH,UAAU,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAAC;IACpD,eAAe,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;CACzF;AAED;;;GAGG;AACH,qBAAa,qBAAsB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