claude-code-infinite 1.0.27 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +63 -29
  2. package/dist/auto-update.d.ts +2 -0
  3. package/dist/auto-update.d.ts.map +1 -1
  4. package/dist/auto-update.js +4 -0
  5. package/dist/auto-update.js.map +1 -1
  6. package/dist/claude-auth.d.ts +27 -2
  7. package/dist/claude-auth.d.ts.map +1 -1
  8. package/dist/claude-auth.js +76 -4
  9. package/dist/claude-auth.js.map +1 -1
  10. package/dist/claude-install.d.ts +73 -0
  11. package/dist/claude-install.d.ts.map +1 -0
  12. package/dist/claude-install.js +142 -0
  13. package/dist/claude-install.js.map +1 -0
  14. package/dist/claude-plan-warning.d.ts +70 -7
  15. package/dist/claude-plan-warning.d.ts.map +1 -1
  16. package/dist/claude-plan-warning.js +152 -8
  17. package/dist/claude-plan-warning.js.map +1 -1
  18. package/dist/cli-args.d.ts +5 -0
  19. package/dist/cli-args.d.ts.map +1 -1
  20. package/dist/cli-args.js +9 -0
  21. package/dist/cli-args.js.map +1 -1
  22. package/dist/cli-main.js +222 -84
  23. package/dist/cli-main.js.map +1 -1
  24. package/dist/diagnostics-schema.d.ts +4 -0
  25. package/dist/diagnostics-schema.d.ts.map +1 -1
  26. package/dist/diagnostics-schema.js +20 -0
  27. package/dist/diagnostics-schema.js.map +1 -1
  28. package/dist/diagnostics.d.ts +24 -1
  29. package/dist/diagnostics.d.ts.map +1 -1
  30. package/dist/diagnostics.js +68 -4
  31. package/dist/diagnostics.js.map +1 -1
  32. package/dist/hooks.d.ts +8 -0
  33. package/dist/hooks.d.ts.map +1 -1
  34. package/dist/hooks.js +57 -25
  35. package/dist/hooks.js.map +1 -1
  36. package/dist/install-ping.d.ts +54 -0
  37. package/dist/install-ping.d.ts.map +1 -0
  38. package/dist/install-ping.js +177 -0
  39. package/dist/install-ping.js.map +1 -0
  40. package/dist/key-page.d.ts +17 -0
  41. package/dist/key-page.d.ts.map +1 -0
  42. package/dist/key-page.js +32 -0
  43. package/dist/key-page.js.map +1 -0
  44. package/dist/key-status.d.ts +79 -0
  45. package/dist/key-status.d.ts.map +1 -0
  46. package/dist/key-status.js +143 -0
  47. package/dist/key-status.js.map +1 -0
  48. package/dist/memtree-finder.d.ts +2 -1
  49. package/dist/memtree-finder.d.ts.map +1 -1
  50. package/dist/memtree-finder.js +4 -5
  51. package/dist/memtree-finder.js.map +1 -1
  52. package/dist/memtree-mcp.d.ts.map +1 -1
  53. package/dist/memtree-mcp.js +17 -7
  54. package/dist/memtree-mcp.js.map +1 -1
  55. package/dist/memtree-times.d.ts +35 -0
  56. package/dist/memtree-times.d.ts.map +1 -0
  57. package/dist/memtree-times.js +166 -0
  58. package/dist/memtree-times.js.map +1 -0
  59. package/dist/memtree-tools.d.ts +12 -0
  60. package/dist/memtree-tools.d.ts.map +1 -1
  61. package/dist/memtree-tools.js +63 -7
  62. package/dist/memtree-tools.js.map +1 -1
  63. package/dist/memtree.d.ts +23 -0
  64. package/dist/memtree.d.ts.map +1 -1
  65. package/dist/memtree.js +39 -3
  66. package/dist/memtree.js.map +1 -1
  67. package/dist/notices.d.ts +5 -0
  68. package/dist/notices.d.ts.map +1 -1
  69. package/dist/notices.js +13 -0
  70. package/dist/notices.js.map +1 -1
  71. package/dist/paused-session.d.ts +29 -0
  72. package/dist/paused-session.d.ts.map +1 -0
  73. package/dist/paused-session.js +148 -0
  74. package/dist/paused-session.js.map +1 -0
  75. package/dist/payment-gate.d.ts +44 -13
  76. package/dist/payment-gate.d.ts.map +1 -1
  77. package/dist/payment-gate.js +82 -23
  78. package/dist/payment-gate.js.map +1 -1
  79. package/dist/payment-link.d.ts +68 -0
  80. package/dist/payment-link.d.ts.map +1 -0
  81. package/dist/payment-link.js +123 -0
  82. package/dist/payment-link.js.map +1 -0
  83. package/dist/postinstall.d.ts +2 -0
  84. package/dist/postinstall.d.ts.map +1 -0
  85. package/dist/postinstall.js +4 -0
  86. package/dist/postinstall.js.map +1 -0
  87. package/dist/project-trees.d.ts +100 -0
  88. package/dist/project-trees.d.ts.map +1 -0
  89. package/dist/project-trees.js +196 -0
  90. package/dist/project-trees.js.map +1 -0
  91. package/dist/proxy.d.ts +29 -8
  92. package/dist/proxy.d.ts.map +1 -1
  93. package/dist/proxy.js +167 -25
  94. package/dist/proxy.js.map +1 -1
  95. package/dist/rate-limit.d.ts +64 -0
  96. package/dist/rate-limit.d.ts.map +1 -0
  97. package/dist/rate-limit.js +126 -0
  98. package/dist/rate-limit.js.map +1 -0
  99. package/dist/reqlog.d.ts +13 -2
  100. package/dist/reqlog.d.ts.map +1 -1
  101. package/dist/reqlog.js.map +1 -1
  102. package/package.json +2 -1
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Earlier MemTree sessions in this project, named to the model when a session
3
+ * starts, so earlier decisions and fixes are one lookup away.
4
+ *
5
+ * The server answers `GET /v1/memtree/project_trees?project=&limit=` (polychat
6
+ * routes/memtree_project_trees.py): the user's own newest sessions in this
7
+ * project that have a finished tree, each with its root summary and tree
8
+ * reference. ccc asks once at startup (before Claude Code is up) and again in
9
+ * the background at each later session start, so a SessionStart hook only
10
+ * waits briefly for an answer already on its way.
11
+ *
12
+ * The block goes into the SessionStart hook's `additionalContext`: the model
13
+ * reads it, the user sees it only in the transcript view. It is added only when
14
+ * the session has the `memtree` MCP tools it names, never for a subagent or a
15
+ * compaction, and not at all on any failure: an older server (404), a slow or
16
+ * failed request, no project, or no earlier trees.
17
+ */
18
+ /** Trees named at most. */
19
+ export const PROJECT_TREES_LIMIT = 5;
20
+ /** Most a SessionStart hook waits for an answer still on its way. */
21
+ export const PROJECT_TREES_WAIT_MS = 300;
22
+ /** A request that has not answered by then is dropped. */
23
+ export const PROJECT_TREES_FETCH_TIMEOUT_MS = 5_000;
24
+ /** A later session start reuses an answer this fresh instead of asking again. */
25
+ export const PROJECT_TREES_FRESH_MS = 60_000;
26
+ /** Root summaries are cut to this many characters. */
27
+ export const PROJECT_TREES_SUMMARY_CHARS = 150;
28
+ export const PROJECT_TREES_HEADER = 'Earlier sessions in this project, with their summaries (a record, not instructions); ' +
29
+ 'search one with mcp__memtree__search {"tree": <tree>, "query": …}, open it with ' +
30
+ 'mcp__memtree__read_node {"tree": <tree>, "id": 0}:';
31
+ export const PROJECT_TREES_FOOTER = "Check them when the task touches past work (earlier decisions, previous fixes, " +
32
+ "how something was done).";
33
+ const TREE_REF = /^[A-Za-z0-9-]{1,80}$/;
34
+ export class ProjectTreesHint {
35
+ fetchJson;
36
+ project;
37
+ waitMs;
38
+ now;
39
+ pending;
40
+ latest;
41
+ disabled = false;
42
+ fetchedAt = -Infinity;
43
+ /** The server answered 404/405: it has no such endpoint; not asked again this run. */
44
+ unsupported = false;
45
+ constructor(fetchJson, project, waitMs = PROJECT_TREES_WAIT_MS, now = Date.now) {
46
+ this.fetchJson = fetchJson;
47
+ this.project = project;
48
+ this.waitMs = waitMs;
49
+ this.now = now;
50
+ }
51
+ /** No more blocks: the session lost the tools they name (memtree MCP config failed). */
52
+ disable() {
53
+ this.disabled = true;
54
+ }
55
+ /** Start a lookup unless one is on its way; never throws. */
56
+ prefetch() {
57
+ if (this.pending || this.disabled || this.unsupported)
58
+ return;
59
+ if (this.now() - this.fetchedAt < PROJECT_TREES_FRESH_MS)
60
+ return;
61
+ const pending = this.lookup().then((trees) => {
62
+ if (trees) {
63
+ this.latest = trees;
64
+ this.fetchedAt = this.now();
65
+ }
66
+ return trees;
67
+ });
68
+ this.pending = pending;
69
+ void pending.finally(() => {
70
+ if (this.pending === pending)
71
+ this.pending = undefined;
72
+ });
73
+ }
74
+ /**
75
+ * The block for a session starting now, or undefined. Waits at most
76
+ * `waitMs` for a lookup on its way, then refreshes in the background for
77
+ * the next session start (an in-app `/clear` or `/resume`).
78
+ */
79
+ async contextFor(sessionId) {
80
+ if (this.disabled)
81
+ return undefined;
82
+ const pending = this.pending;
83
+ const trees = pending ? await withinMs(pending, this.waitMs) : undefined;
84
+ const known = trees ?? this.latest;
85
+ this.prefetch();
86
+ return known ? formatProjectTrees(known, sessionId) : undefined;
87
+ }
88
+ async lookup() {
89
+ const query = new URLSearchParams({
90
+ project: this.project,
91
+ // One more, so leaving out the current session still names five.
92
+ limit: String(PROJECT_TREES_LIMIT + 1),
93
+ });
94
+ try {
95
+ const response = await this.fetchJson(`/v1/memtree/project_trees?${query.toString()}`, AbortSignal.timeout(PROJECT_TREES_FETCH_TIMEOUT_MS));
96
+ if (response.status === 404 || response.status === 405)
97
+ this.unsupported = true;
98
+ if (response.status !== 200)
99
+ return undefined;
100
+ return parseProjectTrees(JSON.parse(response.body.toString("utf-8")));
101
+ }
102
+ catch {
103
+ return undefined;
104
+ }
105
+ }
106
+ }
107
+ /**
108
+ * The project name the server matches: the `owner/repo` of the `origin`
109
+ * remote. A directory name alone ("app", "src") would also match unrelated
110
+ * directories and repos of that name, so without a remote there is no hint.
111
+ */
112
+ export function projectIdentity(meta) {
113
+ return meta?.git_repo || undefined;
114
+ }
115
+ /** The server's `trees`, keeping only well-formed entries. */
116
+ export function parseProjectTrees(body) {
117
+ const trees = body?.trees;
118
+ if (!Array.isArray(trees))
119
+ return undefined;
120
+ const parsed = [];
121
+ for (const item of trees) {
122
+ const tree = parseTree(item);
123
+ if (tree)
124
+ parsed.push(tree);
125
+ }
126
+ return parsed;
127
+ }
128
+ /** The context block, or undefined when no tree but the current session's is left. */
129
+ export function formatProjectTrees(trees, currentSessionId) {
130
+ const shown = trees
131
+ .filter((tree) => !currentSessionId || tree.session_id !== currentSessionId)
132
+ .slice(0, PROJECT_TREES_LIMIT);
133
+ if (!shown.length)
134
+ return undefined;
135
+ const lines = shown.map((tree) => {
136
+ const date = /^\d{4}-\d{2}-\d{2}/.exec(tree.last_at ?? "")?.[0];
137
+ const summary = shorten(tree.title, PROJECT_TREES_SUMMARY_CHARS);
138
+ return `- ${date ? `${date}: ` : ""}${summary} (tree ${tree.ref})`;
139
+ });
140
+ return [PROJECT_TREES_HEADER, ...lines, PROJECT_TREES_FOOTER].join("\n");
141
+ }
142
+ function parseTree(item) {
143
+ if (!item || typeof item !== "object")
144
+ return undefined;
145
+ const raw = item;
146
+ const tree = raw.tree;
147
+ const ref = typeof tree?.ref === "string" ? tree.ref : tree?.request_id;
148
+ if (typeof ref !== "string" || !TREE_REF.test(ref))
149
+ return undefined;
150
+ if (typeof raw.title !== "string" || !raw.title.trim())
151
+ return undefined;
152
+ return {
153
+ session_id: typeof raw.session_id === "string" ? raw.session_id : null,
154
+ last_at: typeof raw.last_at === "string" ? raw.last_at : null,
155
+ title: raw.title,
156
+ ref,
157
+ };
158
+ }
159
+ function shorten(text, limit) {
160
+ // One line: a summary is model-written and must not add lines of its own.
161
+ const flat = text.replace(/\s+/g, " ").trim();
162
+ return flat.length <= limit ? flat : `${flat.slice(0, limit - 1).trimEnd()}…`;
163
+ }
164
+ /** `promise`'s value, or undefined if it takes longer than `ms`. */
165
+ async function withinMs(promise, ms) {
166
+ let timer;
167
+ const timeout = new Promise((resolve) => {
168
+ timer = setTimeout(() => resolve(undefined), ms);
169
+ timer.unref?.();
170
+ });
171
+ try {
172
+ return await Promise.race([promise, timeout]);
173
+ }
174
+ finally {
175
+ if (timer)
176
+ clearTimeout(timer);
177
+ }
178
+ }
179
+ /**
180
+ * The hint for this run, or undefined: interactive sessions only (print runs
181
+ * keep Claude Code's output as it is) with MemTree on (a valid key, not
182
+ * continued past the payment gate: the lookup could only fail), with both
183
+ * `search` and `read_node` (the block names them), a known project, and not
184
+ * `CCC_PROJECT_TREES=0`.
185
+ */
186
+ export function projectTreesHintFor(s) {
187
+ if (!s.interactive || s.env.CCC_PROJECT_TREES === "0")
188
+ return undefined;
189
+ if (s.keyCheck === "invalid" || s.memtreeOff)
190
+ return undefined;
191
+ if (!s.tools.includes("search") || !s.tools.includes("read_node"))
192
+ return undefined;
193
+ const project = projectIdentity(s.meta);
194
+ return project ? new ProjectTreesHint(s.fetchJson, project) : undefined;
195
+ }
196
+ //# sourceMapp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CAAC,CAAC,CAAC;IAChD,CAAC;YAAS,CAAC;QACT,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC;AACH,CAAC;AAeD;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB,CAAC,CAAsB;IACxD,IAAI,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,GAAG,CAAC,iBAAiB,KAAK,GAAG;QAAE,OAAO,SAAS,CAAC;IACxE,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,UAAU;QAAE,OAAO,SAAS,CAAC;IAC/D,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC;QAAE,OAAO,SAAS,CAAC;IACpF,MAAM,OAAO,GAAG,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,gBAAgB,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1E,CAAC"}
package/dist/proxy.d.ts CHANGED
@@ -48,6 +48,7 @@ import type { StablePrefixStore } from "./prefix-store.js";
48
48
  import type { NewestTreeLookup } from "./memtree-newest.js";
49
49
  import type { TranscriptUsageSource } from "./transcript-usage.js";
50
50
  import type { ProjectMeta } from "./project-meta.js";
51
+ import type { ProjectTreesHint } from "./project-trees.js";
51
52
  import type { DiagnosticsRecorder } from "./diagnostics.js";
52
53
  import { type MessagesRecord, type RequestLogSink } from "./reqlog.js";
53
54
  export interface ProxyOptions {
@@ -185,6 +186,16 @@ export interface ProxyOptions {
185
186
  * provider decides how often it has something to say.
186
187
  */
187
188
  sessionStartNotice?: () => string | undefined;
189
+ /**
190
+ * A line to show as the user submits a main-session prompt (UserPromptSubmit),
191
+ * e.g. a rate limit Anthropic answered with (rate-limit.ts). Called once per prompt.
192
+ */
193
+ promptSubmitNotice?: () => string | undefined;
194
+ /**
195
+ * Earlier MemTree sessions in this project, added to a main session's
196
+ * SessionStart as model context (project-trees.ts). Omitted means none.
197
+ */
198
+ projectTrees?: ProjectTreesHint;
188
199
  /**
189
200
  * Client diagnostics (diagnostics.ts): session starts, paused notices shown,
190
201
  * and refusals, as allowlisted enums and numbers. Never content.
@@ -224,22 +235,32 @@ export interface RunningProxy {
224
235
  mainSessionId: () => string | undefined;
225
236
  }
226
237
  /**
227
- * Budget fallback until the server reports `model_budget_tokens`: this share
228
- * of the model's context window. 0.8 by default; NEAR_WINDOW_FALLBACK_RATIO
229
- * (900k of 1M) for the 1M-window models the server budgets at 900k for ccc
230
- * (NEAR_WINDOW_MODEL_RE). Plain Claude Code 2.1.302 auto-compacts a 1M window
231
- * at 967k, so MemTree compresses no earlier than ~70k before it would; ccc
232
- * lifts Claude Code's own 977k refusal (claude-env.ts) so a tool turn that
238
+ * Budget fallback until the server reports `model_budget_tokens`, mirroring the
239
+ * server's ccc policy (polychat index_budget.py): every Claude model compresses
240
+ * near its window, NEAR_WINDOW_FALLBACK_RATIO of it but no later than Claude
241
+ * Code's own auto-compact point (window - CLAUDE_CODE_AUTOCOMPACT_RESERVE_TOKENS)
242
+ * and never below FALLBACK_BUDGET_WINDOW_RATIO: 900k of 1M, 167k of 200k; at
243
+ * most a Sonnet's usable-context ceiling (SONNET_CEILINGS). Other models get
244
+ * FALLBACK_BUDGET_WINDOW_RATIO. Plain Claude Code 2.1.302 auto-compacts a 1M
245
+ * window at 967k, so MemTree compresses no earlier than ~70k before it would;
246
+ * ccc lifts Claude Code's own 977k refusal (claude-env.ts) so a tool turn that
233
247
  * jumps past the budget reaches the proxy and is compressed here.
234
248
  */
235
249
  export declare const FALLBACK_BUDGET_WINDOW_RATIO = 0.8;
236
250
  export declare const NEAR_WINDOW_FALLBACK_RATIO = 0.9;
237
- /** The fallback share of the window for `model` (see FALLBACK_BUDGET_WINDOW_RATIO). */
238
- export declare function fallbackBudgetRatio(model: unknown, modelContextLimit: number): number;
251
+ /** The fallback whole-request budget for `model` on this window (see above). */
252
+ export declare function fallbackBudgetTokens(model: unknown, modelContextLimit: number): number;
239
253
  export declare function startProxy(opts: ProxyOptions): Promise<RunningProxy>;
240
254
  /** The page id in a server-stamped link (`…/m/<id>` or `…/usage/memtree/<id>`). */
241
255
  export declare function memtreePageId(pageUrl: string): string | undefined;
256
+ /**
257
+ * The SessionStart hook's answer: the banner line for the user
258
+ * (`systemMessage`), model context (`additionalContext`), or both.
259
+ */
260
+ export declare function sessionStartOutput(line: string | undefined, context: string | undefined): Record<string, unknown>;
242
261
  export declare const MEMTREE_COMPACT_MIN_TOKENS = 20000;
262
+ /** How long a paused turn waits for the short checkout link before its notice (once). */
263
+ export declare const PAYMENT_LINK_NOTICE_WAIT_MS = 1000;
243
264
  export declare const SUBAGENT_VIEW_NOTE = "(main session's page; subagent pages aren't linked yet)";
244
265
  export declare const SUBAGENT_COMPACT_REPLY = "MemTree compact applies to the main session only.";
245
266
  /** "50k", "50000", "1.5m" → tokens; undefined when not a positive count. */
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","sourceRoot":"","sources":["../src/proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAUvD,OAAO,EAAiB,qBAAqB,EACD,MAAM,qBAAqB,CAAC;AAiBxE,OAAO,EAKL,aAAa,EAMd,MAAM,cAAc,CAAC;AAwBtB,OAAO,EAYL,KAAK,cAAc,EAGpB,MAAM,YAAY,CAAC;AAKpB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAA8B,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,KAAK,EAAkB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3E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