Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(#7130): write-through keeps an existing target file; discovery evidence helper under the function-size limit
garrytanea490ed850ac
diff --git a/src/core/persistence/page-prepare.ts b/src/core/persistence/page-prepare.tsindex 96933b4fa8..9872141646 100644--- a/src/core/persistence/page-prepare.ts+++ b/src/core/persistence/page-prepare.ts@@ -297,8 +297,9 @@ export async function prepareFileTarget(engine: BrainEngine, row: Pick<WriteRequ// #7130: a canonical file under a path the checkout's .gitignore excludes would never be committed, so the page would be// file-backed by a file no history holds (and a later sync could read its absence as a deletion). The write publishes// to the database only and binds no file; a declared db_only page keeps its cache file as before. A page that already- // records a file keeps it (and its drift checks): only a person's detach turns it database-only.- if (!snapshot?.page.source_path && !recordedPathFromFileUri(snapshot?.page.source_uri, root) && !isSourceDbOnlySlug(root, row.slug, 'not_db_only') && await gitIgnoresUntracked(root, relative(root, path).split(sep).join('/'))) return undefined;+ // records a file, or whose target file already exists, keeps it (and its drift checks): only a person's detach turns it+ // database-only.+ if (!snapshot?.page.source_path && !recordedPathFromFileUri(snapshot?.page.source_uri, root) && !existsSync(path) && !isSourceDbOnlySlug(root, row.slug, 'not_db_only') && await gitIgnoresUntracked(root, relative(root, path).split(sep).join('/'))) return undefined;if (options.excludeTombstone && snapshot?.page.deleted_at) {const rel = relative(root, path).split(sep).join('/');if (matchesAnyGlob(rel, options.excludeTombstone.patterns)) { options.excludeTombstone.onExcluded(rel); return undefined; }diff --git a/src/core/persistence/sync-discovery.ts b/src/core/persistence/sync-discovery.tsindex 3476f74887..4bc73f86fc 100644--- a/src/core/persistence/sync-discovery.ts+++ b/src/core/persistence/sync-discovery.ts@@ -331,6 +331,20 @@ function cutDiscoveryToSlice(discovered: SyncDiscovery, slicing: Pick<SyncSliceCdiscovered.slice = { phase: cut.phase, after: cut.after, head, target: discovered.target, done: cut.done };if (cut.done && discovered.target === head) delete discovered.stagedHead; else discovered.stagedHead = head;}+/**+ * #7130: the deletions no Git change names (`unproven`: Git path to the path its evidence is read at) that Git never+ * committed are dropped from `entries` and returned: their absence is no evidence the page was deleted.+ */+async function dropUncommittedDeletes(gitRoot: string, tips: Array<string | null | undefined>, unproven: ReadonlyMap<string, string>,+ entries: Map<string, { action: string }>): Promise<string[] | undefined> {+ const deletes = [...unproven.keys()].filter(path => entries.get(path)?.action === 'delete');+ if (!deletes.length) return undefined;+ const evidence = await readOriginEvidence(gitRoot, tips, deletes.map(path => unproven.get(path)!));+ const kept = deletes.filter(path => evidence.get(unproven.get(path)!) !== 'committed');+ for (const path of kept) entries.delete(path);+ return kept;+}+export async function discoverManagedSync(engine: BrainEngine, opts: SyncOpts, context?: ManagedSyncContext,stage?: { target: string; head: string; slice?: Pick<SyncSliceCursor, 'phase' | 'after'> }, walk = false): Promise<SyncDiscovery> {const { binding, root, gitRoot, sourceId, incarnation, source } = context ?? await resolveManagedSyncContext(engine, opts);@@ -464,13 +478,7 @@ export async function discoverManagedSync(engine: BrainEngine, opts: SyncOpts, cif (!present) unproven.set(gitPath, gitPath);}}- let uncommittedKept: string[] | undefined;- const unprovenDeletes = [...unproven.keys()].filter(path => entries.get(path)?.action === 'delete');- if (unprovenDeletes.length && !company) {- const evidence = await readOriginEvidence(gitRoot, [target, source.last_commit], unprovenDeletes.map(path => unproven.get(path)!));- uncommittedKept = unprovenDeletes.filter(path => evidence.get(unproven.get(path)!) !== 'committed');- for (const path of uncommittedKept) entries.delete(path);- }+ const uncommittedKept = company ? undefined : await dropUncommittedDeletes(gitRoot, [target, source.last_commit], unproven, entries);if (company) {entries.clear();renamedFrom.clear();