chat-recall 0.7.36 → 0.7.38
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/channel-detect.d.ts.map +1 -1
- package/dist/channel-detect.js +9 -0
- package/dist/channel-detect.js.map +1 -1
- package/dist/channel-state.d.ts.map +1 -1
- package/dist/channel-state.js +16 -2
- package/dist/channel-state.js.map +1 -1
- package/dist/cli.js +75 -6
- package/dist/mcp-relay.js +11 -1
- package/dist/mcp.js +1477 -612
- package/dist/message-hook.js +16 -4
- package/dist/sync-client.d.ts +17 -1
- package/dist/sync-client.d.ts.map +1 -1
- package/dist/sync-client.js +75 -3
- package/dist/sync-client.js.map +1 -1
- package/dist/walk-budget.d.ts +52 -0
- package/dist/walk-budget.d.ts.map +1 -0
- package/dist/walk-budget.js +68 -0
- package/dist/walk-budget.js.map +1 -0
- package/dist/watch.js +85 -8
- package/package.json +1 -1
package/dist/message-hook.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createRequire as __cr } from 'module'; const require = __cr(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// src/message-hook.ts
|
|
4
|
-
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
5
5
|
import { mkdirSync as mkdirSync3, readFileSync as readFileSync7, readdirSync as readdirSync2, statSync as statSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync3 } from "node:fs";
|
|
6
6
|
import { join as join6 } from "node:path";
|
|
7
7
|
|
|
@@ -267,7 +267,7 @@ try {
|
|
|
267
267
|
CLI_VERSION = JSON.parse(readFileSync5(new URL("../package.json", import.meta.url), "utf-8")).version || CLI_VERSION;
|
|
268
268
|
} catch {
|
|
269
269
|
try {
|
|
270
|
-
if (true) CLI_VERSION = "0.7.
|
|
270
|
+
if (true) CLI_VERSION = "0.7.38";
|
|
271
271
|
} catch {
|
|
272
272
|
}
|
|
273
273
|
}
|
|
@@ -284,6 +284,7 @@ function fetchWithTimeout(url, init = {}, ms = 15e3) {
|
|
|
284
284
|
}
|
|
285
285
|
|
|
286
286
|
// src/channel-state.ts
|
|
287
|
+
import { execFileSync } from "node:child_process";
|
|
287
288
|
import { mkdirSync as mkdirSync2, readFileSync as readFileSync6, readdirSync, statSync, unlinkSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
288
289
|
import { join as join5 } from "node:path";
|
|
289
290
|
var CHANNEL_GONE_MS = 12e4;
|
|
@@ -308,7 +309,18 @@ function startTimeOf(pid) {
|
|
|
308
309
|
const stat = readFileSync6(`/proc/${pid}/stat`, "utf-8");
|
|
309
310
|
const rest = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
310
311
|
const started = rest[19];
|
|
311
|
-
|
|
312
|
+
if (started && /^\d+$/.test(started)) return started;
|
|
313
|
+
} catch {
|
|
314
|
+
}
|
|
315
|
+
if (process.platform === "win32") return null;
|
|
316
|
+
try {
|
|
317
|
+
const out = execFileSync("ps", ["-o", "lstart=", "-p", String(pid)], {
|
|
318
|
+
encoding: "utf8",
|
|
319
|
+
timeout: 2e3,
|
|
320
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
321
|
+
}).trim();
|
|
322
|
+
const ms = out ? Date.parse(out) : NaN;
|
|
323
|
+
return Number.isFinite(ms) ? String(ms) : null;
|
|
312
324
|
} catch {
|
|
313
325
|
return null;
|
|
314
326
|
}
|
|
@@ -750,7 +762,7 @@ function ancestors() {
|
|
|
750
762
|
} catch {
|
|
751
763
|
if (process.platform === "win32") return out;
|
|
752
764
|
try {
|
|
753
|
-
const ppid = Number(
|
|
765
|
+
const ppid = Number(execFileSync2("ps", ["-o", "ppid=", "-p", String(process.ppid)], { encoding: "utf8", timeout: 2e3, stdio: ["ignore", "pipe", "ignore"] }).trim());
|
|
754
766
|
if (ppid > 1) out.push(ppid);
|
|
755
767
|
} catch {
|
|
756
768
|
}
|
package/dist/sync-client.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type SessionRef } from '@chat-recall/engine/core/tool-backend.js';
|
|
|
5
5
|
export declare function classedError(errorClass: FailureClass, message: string): Error;
|
|
6
6
|
/** True when this error must not be retried. Exported for the tests. */
|
|
7
7
|
export declare function isStandingFailure(err: unknown): boolean;
|
|
8
|
-
export type FailureClass = 'rate_limited' | 'payment_required' | 'auth' | 'timeout' | 'refused' | 'dns' | 'network' | 'insecure_transport' | 'server_error' | 'other';
|
|
8
|
+
export type FailureClass = 'rate_limited' | 'payload_too_large' | 'payment_required' | 'auth' | 'timeout' | 'refused' | 'dns' | 'network' | 'insecure_transport' | 'server_error' | 'other';
|
|
9
9
|
/**
|
|
10
10
|
* Reduce an error message to a bounded CLASS.
|
|
11
11
|
*
|
|
@@ -16,6 +16,17 @@ export type FailureClass = 'rate_limited' | 'payment_required' | 'auth' | 'timeo
|
|
|
16
16
|
* A tag from the throw site always wins. The message tests remain for errors
|
|
17
17
|
* thrown by fetch itself, and by code that predates the tag.
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* Does a failed walk count against the target's circuit breaker?
|
|
21
|
+
*
|
|
22
|
+
* A server that answers 429 (busy, Retry-After) or 413 (this body is above the
|
|
23
|
+
* limit) is not broken. The in-walk retry already honoured Retry-After, and the
|
|
24
|
+
* body limit is a fact about one session. Counting either would open the
|
|
25
|
+
* breaker for 1–15 minutes and silence a healthy collector exactly while the
|
|
26
|
+
* server recovers (issue #16: the collector sat in cooldown on 502s and on
|
|
27
|
+
* rate limits while the pods were restarting).
|
|
28
|
+
*/
|
|
29
|
+
export declare function countsForBreaker(cls: FailureClass): boolean;
|
|
19
30
|
export declare function classifyError(msg: string, err?: unknown): FailureClass;
|
|
20
31
|
import { type ArchiveFile } from './raw-archive-parts.js';
|
|
21
32
|
import '@chat-recall/engine/core/backends/index.js';
|
|
@@ -122,6 +133,11 @@ export interface ReconcileResult {
|
|
|
122
133
|
absent: number;
|
|
123
134
|
}>;
|
|
124
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* When did a walk last succeed (0 = never on this machine)?
|
|
138
|
+
* The daemon uses this to decide 'changed' or 'full' after a restart.
|
|
139
|
+
*/
|
|
140
|
+
export declare function lastSuccessfulWalkAt(serverUrl?: string): number;
|
|
125
141
|
/**
|
|
126
142
|
* Manual entrypoint (CLI `reconcile`): reconcile derived fields for ALL targets.
|
|
127
143
|
* Normal `sync` already runs reconciliation each pass; this is the explicit
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-client.d.ts","sourceRoot":"","sources":["../src/sync-client.ts"],"names":[],"mappings":"AAmCA,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAQzF,OAAO,EAAoF,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-client.d.ts","sourceRoot":"","sources":["../src/sync-client.ts"],"names":[],"mappings":"AAmCA,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,0CAA0C,CAAC;AAQzF,OAAO,EAAoF,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAYrL,OAAO,EAA+B,KAAK,UAAU,EAAE,MAAM,0CAA0C,CAAC;AA2ExG,yDAAyD;AACzD,wBAAgB,YAAY,CAAC,UAAU,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,GAAG,KAAK,CAI7E;AAgBD,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGvD;AAED,MAAM,MAAM,YAAY,GACpB,cAAc,GAAG,mBAAmB,GAAG,kBAAkB,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAC1F,KAAK,GAAG,SAAS,GAAG,oBAAoB,GAAG,cAAc,GAAG,OAAO,CAAC;AAExE;;;;;;;;;GASG;AACH;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAE3D;AAED,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C;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAAC,CAyFlJ;AAED;;;;;;GAMG;AACH;;;;;;;;GAQG;AACH;;;;yCAIyC;AACzC,MAAM,WAAW,QAAQ;IAAG,OAAO,EAAE,gBAAgB,GAAG,QAAQ,GAAG,WAAW,CAAA;CAAE;AAEhF,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,GAAG,QAAQ,GAAG,CAAC,IAAI,QAAQ,CAElE;AAED,wBAAsB,eAAe,CAAC,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;CAAO,GAAG,OAAO,CAAC,UAAU,GAAG,QAAQ,CAAC,CA4C/G"}
|
package/dist/sync-client.js
CHANGED
|
@@ -46,6 +46,7 @@ import { isInternalToolPrompt } from '@chat-recall/engine/core/internal-prompts.
|
|
|
46
46
|
import { dropFuzzyFindings } from '@chat-recall/engine/core/secret-precision.js';
|
|
47
47
|
import { loadSettings, saveSettings, isProjectSyncable } from '@chat-recall/engine/core/settings.js';
|
|
48
48
|
import { getDataDir } from '@chat-recall/engine/core/paths.js';
|
|
49
|
+
import { walkSessionLimit, orderRefsForWalk } from './walk-budget.js';
|
|
49
50
|
import { listAvailableBackends } from '@chat-recall/engine/core/tool-backend.js';
|
|
50
51
|
import { parseTranscript, trimTranscriptForSync, TRANSCRIPT_VERSION, gzipContainer, redactContainer, buildRawContainer, containerSrcHash, parseTranscriptFromContainer, updateShadow, shadowUncompressedBytes } from '@chat-recall/engine/transcript/index.js';
|
|
51
52
|
import { parseClaudeTranscriptText } from '@chat-recall/engine/transcript/claude.js';
|
|
@@ -155,6 +156,19 @@ export function isStandingFailure(err) {
|
|
|
155
156
|
* A tag from the throw site always wins. The message tests remain for errors
|
|
156
157
|
* thrown by fetch itself, and by code that predates the tag.
|
|
157
158
|
*/
|
|
159
|
+
/**
|
|
160
|
+
* Does a failed walk count against the target's circuit breaker?
|
|
161
|
+
*
|
|
162
|
+
* A server that answers 429 (busy, Retry-After) or 413 (this body is above the
|
|
163
|
+
* limit) is not broken. The in-walk retry already honoured Retry-After, and the
|
|
164
|
+
* body limit is a fact about one session. Counting either would open the
|
|
165
|
+
* breaker for 1–15 minutes and silence a healthy collector exactly while the
|
|
166
|
+
* server recovers (issue #16: the collector sat in cooldown on 502s and on
|
|
167
|
+
* rate limits while the pods were restarting).
|
|
168
|
+
*/
|
|
169
|
+
export function countsForBreaker(cls) {
|
|
170
|
+
return cls !== 'rate_limited' && cls !== 'payload_too_large';
|
|
171
|
+
}
|
|
158
172
|
export function classifyError(msg, err) {
|
|
159
173
|
const tagged = taggedClass(err);
|
|
160
174
|
if (tagged)
|
|
@@ -162,6 +176,11 @@ export function classifyError(msg, err) {
|
|
|
162
176
|
const m = msg.toLowerCase();
|
|
163
177
|
if (m.includes('429'))
|
|
164
178
|
return 'rate_limited';
|
|
179
|
+
// The server refused the SIZE of one body (413 with code body_too_large, or a
|
|
180
|
+
// parser limit). It is a fact about that session, not a broken target: the
|
|
181
|
+
// walk must keep its cooldown out of it (see countsForBreaker).
|
|
182
|
+
if (m.includes('body_too_large') || m.includes('payload too large') || m.includes('entity too large'))
|
|
183
|
+
return 'payload_too_large';
|
|
165
184
|
if (m.includes('402'))
|
|
166
185
|
return 'payment_required';
|
|
167
186
|
if (m.includes('401') || m.includes('403') || m.includes('token'))
|
|
@@ -593,7 +612,16 @@ export async function syncSessions(opts = {}) {
|
|
|
593
612
|
// delivered thousands of rows and then failed reads as "never synced".
|
|
594
613
|
perTarget[cred.serverUrl] = { ok: false, error: msg, accepted: acceptedUploads.get(cred.serverUrl) ?? 0 };
|
|
595
614
|
// Report the NEXT attempt in the same breath as the failure, so the log
|
|
596
|
-
// says what will happen rather than leaving the user to infer it.
|
|
615
|
+
// says what will happen rather than leaving the user to infer it. A 429
|
|
616
|
+
// or a 413 is the server asking for a pause, or a fact about ONE session:
|
|
617
|
+
// it is reported, but it does not count against the cooldown, because a
|
|
618
|
+
// collector in cooldown cannot use the moment the server recovers.
|
|
619
|
+
const cls = classifyError(msg, e);
|
|
620
|
+
if (!countsForBreaker(cls)) {
|
|
621
|
+
console.error(`[sync] ${cred.serverUrl}: ${cls === 'rate_limited' ? 'asked to slow down' : 'refused one oversized body'}; the target stays out of cooldown and the next walk retries`);
|
|
622
|
+
record({ kind: 'target_throttled', failures: 0, retryInMs: 0, errorClass: cls, local: isLocalHost(cred.serverUrl) ? 1 : 0 });
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
597
625
|
const next = noteTargetFailure(cred.serverUrl, msg);
|
|
598
626
|
const notice = breakerNotice(cred.serverUrl, next);
|
|
599
627
|
if (notice)
|
|
@@ -609,7 +637,7 @@ export async function syncSessions(opts = {}) {
|
|
|
609
637
|
kind: next.tripped ? 'breaker_trip' : 'target_failure',
|
|
610
638
|
failures: next.failures,
|
|
611
639
|
retryInMs: next.retryInMs,
|
|
612
|
-
errorClass:
|
|
640
|
+
errorClass: cls,
|
|
613
641
|
local: isLocalHost(cred.serverUrl) ? 1 : 0,
|
|
614
642
|
});
|
|
615
643
|
}
|
|
@@ -645,6 +673,14 @@ export async function syncSessions(opts = {}) {
|
|
|
645
673
|
rssPeakMb: Math.round(process.memoryUsage().rss / 1048576),
|
|
646
674
|
});
|
|
647
675
|
}
|
|
676
|
+
// A successful target gets a timestamp, so the next daemon start can walk
|
|
677
|
+
// 'changed' instead of listing all 12,224 sessions again (issue #16).
|
|
678
|
+
if (agg) {
|
|
679
|
+
for (const t of targets) {
|
|
680
|
+
if (!errors.some((e) => e.startsWith(`${t.serverUrl}:`)))
|
|
681
|
+
noteWalkSuccess(t.serverUrl);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
648
684
|
// After the walk: the connection is warm and the numbers are final. Never
|
|
649
685
|
// awaited into the caller's error path — telemetry must not fail a sync.
|
|
650
686
|
void flush().catch(() => { });
|
|
@@ -656,6 +692,36 @@ export async function syncSessions(opts = {}) {
|
|
|
656
692
|
// to infer one target's fate from the sum of all of them.
|
|
657
693
|
return { ...agg, perTarget };
|
|
658
694
|
}
|
|
695
|
+
/** File that holds the last successful walk per target (see noteWalkSuccess). */
|
|
696
|
+
function walkStatePath() { return join(getDataDir(), 'walk-state.json'); }
|
|
697
|
+
function readWalkState() {
|
|
698
|
+
try {
|
|
699
|
+
const raw = JSON.parse(readFileSync(walkStatePath(), 'utf-8'));
|
|
700
|
+
return raw && typeof raw === 'object' ? raw : {};
|
|
701
|
+
}
|
|
702
|
+
catch {
|
|
703
|
+
return {};
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
function noteWalkSuccess(serverUrl) {
|
|
707
|
+
try {
|
|
708
|
+
const state = readWalkState();
|
|
709
|
+
state[serverUrl.replace(/\/+$/, '')] = Date.now();
|
|
710
|
+
mkdirSync(getDataDir(), { recursive: true });
|
|
711
|
+
writeFileSync(walkStatePath(), JSON.stringify(state));
|
|
712
|
+
}
|
|
713
|
+
catch { /* the stamp only tunes the NEXT walk, so it must never fail a sync */ }
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* When did a walk last succeed (0 = never on this machine)?
|
|
717
|
+
* The daemon uses this to decide 'changed' or 'full' after a restart.
|
|
718
|
+
*/
|
|
719
|
+
export function lastSuccessfulWalkAt(serverUrl) {
|
|
720
|
+
const state = readWalkState();
|
|
721
|
+
const key = serverUrl?.replace(/\/+$/, '');
|
|
722
|
+
const stamps = key ? [state[key]] : Object.values(state);
|
|
723
|
+
return stamps.reduce((max, v) => Math.max(max, typeof v === 'number' ? v : 0), 0);
|
|
724
|
+
}
|
|
659
725
|
/** POST one derived-field batch, retrying the ingest gate's 429 (honoring
|
|
660
726
|
* Retry-After) and transient 5xx. */
|
|
661
727
|
async function postFieldBatch(base, token, rows) {
|
|
@@ -1640,7 +1706,13 @@ async function syncToTargetInScope(cred, opts = {}) {
|
|
|
1640
1706
|
}
|
|
1641
1707
|
};
|
|
1642
1708
|
let scanMs = 0, scanned = 0; // secret-scan metrics
|
|
1643
|
-
|
|
1709
|
+
// ONE walk is bounded (issue #16). Sessions the ledger has not acknowledged
|
|
1710
|
+
// go first, so a large corpus moves forward in bounded steps instead of one
|
|
1711
|
+
// unbounded pass that a restart repeats from the first session. An explicit
|
|
1712
|
+
// `opts.limit` from the caller still wins.
|
|
1713
|
+
const walkMax = opts.limit ?? walkSessionLimit();
|
|
1714
|
+
const ordered = walkMax > 0 ? orderRefsForWalk(refs, (id) => Boolean(ledger?.get(id))) : refs;
|
|
1715
|
+
const slice = walkMax > 0 ? ordered.slice(0, walkMax) : ordered;
|
|
1644
1716
|
// CHAT_RECALL_SYNC_TRACE=1: phase + progress markers with heap usage, to
|
|
1645
1717
|
// stderr. This is how the 2026-07-03 walk OOM was localized — keep it.
|
|
1646
1718
|
const trace = process.env.CHAT_RECALL_SYNC_TRACE === '1'
|