



















@@ -60,6 +60,7 @@ type ReadTruncationDetails = {
6060const OFFSET_BEYOND_EOF_RE = /^Offset \d+ is beyond end of file \(\d+ lines total\)$/;
6161const READ_CONTINUATION_NOTICE_RE =
6262/\n\n\[(?:Showing lines [^\]]*?Use offset=\d+ to continue\.|\d+ more lines in file\. Use offset=\d+ to continue\.)\]\s*$/;
63+const DAILY_MEMORY_PATH_RE = /^memory\/\d{4}-\d{2}-\d{2}\.md$/;
63646465function clamp(value: number, min: number, max: number): number {
6566return Math.max(min, Math.min(max, value));
@@ -218,6 +219,40 @@ function emptyReadResult(): AgentToolResult<unknown> {
218219return { content: [textBlock], details: undefined };
219220}
220221222+function missingDailyMemoryReadResult(relativePath: string): AgentToolResult<unknown> {
223+return {
224+content: [
225+{
226+type: "text",
227+text: `No daily memory file exists yet at ${relativePath}.`,
228+},
229+],
230+details: {
231+status: "not_found",
232+path: relativePath,
233+optional: true,
234+},
235+};
236+}
237+238+function normalizeDailyMemoryReadPath(value: unknown): string | undefined {
239+if (typeof value !== "string") {
240+return undefined;
241+}
242+const normalized = value.trim().replace(/\\/g, "/").replace(/^\.\/+/, "");
243+return DAILY_MEMORY_PATH_RE.test(normalized) ? normalized : undefined;
244+}
245+246+function isNotFoundError(error: unknown): boolean {
247+if (typeof (error as NodeJS.ErrnoException | undefined)?.code === "string") {
248+return (error as NodeJS.ErrnoException).code === "ENOENT";
249+}
250+if (!(error instanceof Error)) {
251+return false;
252+}
253+return /\bENOENT\b|no such file or directory|file not found/i.test(error.message);
254+}
255+221256async function executeReadPage(params: {
222257base: AnyAgentTool;
223258toolCallId: string;
@@ -230,6 +265,10 @@ async function executeReadPage(params: {
230265if (isOffsetBeyondEof(error, params.args)) {
231266return emptyReadResult();
232267}
268+const missingDailyMemoryPath = normalizeDailyMemoryReadPath(params.args.path);
269+if (missingDailyMemoryPath && isNotFoundError(error)) {
270+return missingDailyMemoryReadResult(missingDailyMemoryPath);
271+}
233272throw error;
234273}
235274}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。