Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(sync): plain-directory sync skips reserved skill-bundle paths (#8620)
garrytan76914b526f3b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c10b78f628..1bc1821bd3 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,18 @@ credits are retained; no result has been reassigned to another provider. Originaidentifiers and attribution are available in the pre-removal Git revision`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).+## [Unreleased]++**A database-only source exported by the 0.53.0 migration now syncs. The export installs the shared memory pack (`skillpack.json` and `skills/*/SKILL.md`) into the new plain directory, and `gbrain sync` used to refuse each pack file with `skill_bundle_required`, so the source stayed `blocked_by_failures` and doctor's `sync_freshness` failed for good (#8620).**++| Situation | Before | Now |+|---|---|---|+| `gbrain sync --source <id>` on a plain-directory source of a managed brain that holds the pack | three `skill_bundle_required` refusals, `blocked_by_failures`, no successful sync ever recorded | reserved skill paths stay with the shared skill publisher, as in managed Git sync; the source syncs and records `last_sync_at` |+| `--dry-run` on that source | counted the pack's files as "would be imported" | leaves them out of the count |+| Shared skills activated before the DB-only export | the v0.53.0.0 checklist didn't say the new root needs the activation again | the checklist says to rerun the `--shared-skills` activation after the export binds the root, then resume the export |++The importer still refuses skill paths handed to it directly; classic (unmanaged) brains import a plain directory exactly as before.+## [0.60.575.0] - 2026-11-04**Train R, seven pull requests in one release. Searches that name a page by an identifier (`#412`, `INV-2026-00417`) or a handle (`dan-example`) now find it. New `gbrain find` / `find_pages` finds a page by name, path prefix or glob, and `gbrain stats --by source,type` counts pages by kind. `query --explain-target --json` carries its diagnosis. There's an opt-in keyword phrase factor (off by default), an advisory harness check on pull requests, new docs, and guardrails for the embedded core.**diff --git a/skills/migrations/v0.53.0.0.md b/skills/migrations/v0.53.0.0.mdindex fd238d3a23..28660a9369 100644--- a/skills/migrations/v0.53.0.0.md+++ b/skills/migrations/v0.53.0.0.md@@ -107,7 +107,17 @@ The flag records operator testimony; it does not create or verify a backup.Export validates Markdown round trips and raw-data sidecar hashes, retains thedatabase, checkpoints the staging/root identity, binds the canonical owner,-activates the current skill writer protocol, and installs the default pack.+activates the skill writer protocol if step 2 has not, and installs the default pack.++If you activated shared skills in step 2, the root the export binds has no+protocol-2 writer row yet, and the export stops with `writer_not_quiesced`+("The canonical owner capability changed after shared publication was+activated"). After the root is bound, run the step 2 `--shared-skills`+activation again (dry run, review fresh status, then apply with its new+`--expected-state`); it now counts the new root. Then resume the same export.++Plain-directory sync of the exported root leaves `skillpack.json` and+`skills/` to the shared skill publisher, as managed Git sync does.It is bounded to 5,000 active pages per source, 5 MB per Markdown page, and64 MiB per source. Unsafe/colliding paths, non-round-trippable data, facts/takesmissing from canonical fences, changed files, or changed DB content blockdiff --git a/skills/skills.lock.json b/skills/skills.lock.jsonindex 4e0caa8f17..62dfbd664f 100644--- a/skills/skills.lock.json+++ b/skills/skills.lock.json@@ -146,7 +146,7 @@"migrations/v0.51.8.0.md": "16af7c14f4ee12029b87ee2f07446a6355216ddf6109f54c2fcc0adbd558b09a","migrations/v0.52.1.0.md": "7b54ff2e4e881658020d725aa1709f10b34e118974e1899c4c46aca3712409a1","migrations/v0.52.2.0.md": "07568b099264e56f909f46eb417c4a512788e893e8ae6080423ad6ae06918076",- "migrations/v0.53.0.0.md": "14440e9aa189d2f751fcd7aa0077b95156d85b145ba04111520d69bf4b9f76e4",+ "migrations/v0.53.0.0.md": "d5c2f5dfbd2a6ba66aac4ac917cf48bf580f2d93dd488fe98e09a3a68d643f57","migrations/v0.54.1.0.md": "ceee87cfc7bb28036e9cadb5b70b7ec9eabcce6d445e259f3ee410a95fe69603","migrations/v0.56.2.0.md": "e88f04a5deaef82ebb8bd194aec931f26e69e87687098eb64b94666931b5e319","migrations/v0.58.0.0.md": "a6ee3d3125ff1be612df776c7b8d6dfcaeb57ca073255793a67dff78a23c51cc",diff --git a/src/commands/import.ts b/src/commands/import.tsindex 4af7c2eb99..22db94499f 100644--- a/src/commands/import.ts+++ b/src/commands/import.ts@@ -269,7 +269,7 @@ export async function runImport(strategy?: SyncStrategy;sourceId?: string;managedBookmark?: boolean;- /** #5988: paths the caller already held this run; they are skipped without importing (not failures). */+ /** Paths the caller keeps out of this run (#5988 holds, #8620 reserved skill paths); skipped without importing, not failures. */heldPaths?: ReadonlySet<string>;/** #5988: each file's outcome (a throw arrives as `{ status: 'error', error }`); `'held'` = the caller held it, not a failure. */onFileResult?: ImportFileResultCallback;diff --git a/src/commands/sync/plain-directory.ts b/src/commands/sync/plain-directory.tsindex f694dce2a3..2d0402a800 100644--- a/src/commands/sync/plain-directory.ts+++ b/src/commands/sync/plain-directory.ts@@ -11,6 +11,7 @@ import { loadConfig } from '../../core/config.ts';import { serr, slog } from '../../core/console-prefix.ts';import { matchesAnyGlob, readMetafilePagesMode } from '../../core/sync.ts';import { isAnchorOwnedSyncPath } from '../../core/sync-anchor.ts';+import { isReservedSkillBundlePath } from '../../core/skill-reserved-paths.ts';import { syncExcludePatterns } from '../../core/persistence/sync-discovery.ts';import { maintenanceAttribution } from '../../core/persistence/attribution.ts';import { withCoordinatedWrite } from '../../core/persistence/context.ts';@@ -57,22 +58,30 @@ export async function plainDirectorySyncRoot(engine: BrainEngine, opts: SyncOptsreturn root;}-/** Sync a plain-directory source by importing its files; a dry run counts them and writes nothing. */+/**+ * Sync a plain-directory source by importing its files; a dry run counts them and writes nothing. #8620: on a managed+ * brain, reserved skill-bundle paths (the pack the 0.53.0 export installs) stay with the shared skill publisher, as in+ * managed Git sync discovery, so the importer never refuses them and blocks the source.+ */export async function performPlainDirectorySync(engine: BrainEngine, opts: SyncOpts, root: string, managed: boolean): Promise<SyncResult> {const sourceId = opts.sourceId ?? 'default';const exclude = await syncExcludePatterns(engine, opts.exclude);const empty = { fromCommit: null, toCommit: '', modified: 0, deleted: 0, renamed: 0, chunksCreated: 0, embedded: 0, pagesAffected: [] };serr(`[sync] ${root} is a plain directory, not a Git checkout, so sync imports its files into source ${sourceId}; a file removed from it keeps its page.`);const { runImport, collectSyncableFiles } = await import('../import.ts');+ const files = opts.dryRun || managed+ ? collectSyncableFiles(root, { strategy: opts.strategy ?? 'markdown', includeHidden: opts.includeHidden, metafilePages: await readMetafilePagesMode(engine) })+ .map(abs => relative(root, abs)).filter(path => !matchesAnyGlob(path, exclude))+ : [];+ const reserved = new Set(managed ? files.filter(isReservedSkillBundlePath) : []);if (opts.dryRun) {- const files = collectSyncableFiles(root, { strategy: opts.strategy ?? 'markdown', includeHidden: opts.includeHidden, metafilePages: await readMetafilePagesMode(engine) })- .filter(abs => !matchesAnyGlob(relative(root, abs), exclude));- slog(`Plain-directory dry run: ${files.length} file(s) would be imported from ${root}.`);- return { ...empty, status: 'dry_run', added: files.length };+ slog(`Plain-directory dry run: ${files.length - reserved.size} file(s) would be imported from ${root}.`);+ return { ...empty, status: 'dry_run', added: files.length - reserved.size };}+ if (reserved.size) serr(`[sync] Left ${reserved.size} reserved skill file(s) (skills/, skillpack.json) to the shared skill publisher; import never publishes skills.`);const keyless = loadConfig()?.embedding_disabled === true || (await engine.getConfig('embedding_disabled')) === 'true';const result = await runImport(engine, [root, ...(opts.noEmbed || keyless ? ['--no-embed'] : [])],- { signal: opts.signal, sourceId, strategy: opts.strategy, exclude, includeHidden: opts.includeHidden });+ { signal: opts.signal, sourceId, strategy: opts.strategy, exclude, includeHidden: opts.includeHidden, heldPaths: reserved });if (result.errors > 0) return { ...empty, status: 'blocked_by_failures', added: result.imported, chunksCreated: result.chunksCreated, failedFiles: result.errors };// A managed brain fences source checkpoints to coordinated writers; the classic import stamps last_sync_at itself.if (managed) {diff --git a/test/sync-plain-directory-skillpack-8620.test.ts b/test/sync-plain-directory-skillpack-8620.test.tsnew file mode 100644index 0000000000..293d77e883--- /dev/null+++ b/test/sync-plain-directory-skillpack-8620.test.ts@@ -0,0 +1,58 @@+/**+ * #8620: the 0.53.0 DB-only export binds a plain directory and installs the shared memory pack into it (skillpack.json+ * plus skills/<name>/SKILL.md). Plain-directory sync must leave those reserved paths to the shared skill publisher, the+ * way managed Git sync discovery does, instead of handing them to the importer, which refuses each one with+ * skill_bundle_required and blocks the source for good.+ * Fails when: the sync after the export ends blocked_by_failures, the dry run counts the pack's files, or the sync+ * writes the pack into pages or the shared skill catalog.+ */+import { afterAll, beforeAll, expect, test } from 'bun:test';+import { existsSync, mkdtempSync, rmSync } from 'node:fs';+import { join } from 'node:path';+import { tmpdir } from 'node:os';+import { PGLiteEngine } from '../src/core/pglite-engine.ts';+import type { OperationContext } from '../src/core/ops/contract.ts';+import { exportDatabaseContent } from '../src/core/shared-skills/migration-export.ts';+import { performSync } from '../src/commands/sync.ts';+import { withEnv } from './helpers/with-env.ts';++const catalogTables = ['shared_skill_packs', 'shared_skill_members', 'shared_skill_heads', 'shared_skill_revisions', 'shared_skill_state', 'shared_skill_policies'];+let engine: PGLiteEngine;++beforeAll(async () => {+ engine = new PGLiteEngine();+ await engine.connect({});+ await engine.initSchema();+});+afterAll(async () => {+ await engine.disconnect();+});++async function catalog(): Promise<Record<string, unknown[]>> {+ const rows: Record<string, unknown[]> = {};+ for (const table of catalogTables) rows[table] = await engine.executeRaw(`SELECT * FROM ${table} ORDER BY 1`);+ return rows;+}++test('a plain directory holding the exported memory pack syncs, and the dry run leaves the pack out', async () => {+ const home = mkdtempSync(join(tmpdir(), 'gbrain-plain-skillpack-'));+ try {+ await withEnv({ GBRAIN_HOME: home, DATABASE_URL: undefined, GBRAIN_DATABASE_URL: undefined }, async () => {+ await engine.putPage('notes/example', { type: 'note', title: 'Example', compiled_truth: 'A saved observation.', timeline: '' }, { sourceId: 'default' });+ const ctx: OperationContext = { engine, config: { engine: 'pglite', mcp: { publish_skills: false } }, remote: false, dryRun: false, sourceId: 'default', logger: { info() {}, warn() {}, error() {} } };+ const root = join(home, 'content');+ expect((await exportDatabaseContent(ctx, { sourceId: 'default', root, confirmQuiesced: true, backup: 'operator_verified' })).status).toBe('complete');+ for (const path of ['skillpack.json', 'skills/brain-router/SKILL.md', 'skills/memory-recall/SKILL.md', 'skills/memory-care/SKILL.md']) expect(existsSync(join(root, path))).toBe(true);+ const before = await catalog();++ expect(await performSync(engine, { sourceId: 'default', noPull: true, noEmbed: true, dryRun: true })).toMatchObject({ status: 'dry_run', added: 1 });+ const synced = await performSync(engine, { sourceId: 'default', noPull: true, noEmbed: true });+ expect(synced.status).toBe('synced');+ expect(synced.failedFiles ?? 0).toBe(0);+ const [source] = await engine.executeRaw<{ last_sync_at: unknown }>("SELECT last_sync_at FROM sources WHERE id='default'");+ expect(source?.last_sync_at).not.toBeNull();+ expect(await engine.executeRaw("SELECT slug FROM pages WHERE source_id='default' AND (slug ILIKE 'skills/%' OR slug ILIKE 'skillpack%')")).toEqual([]);+ expect(await catalog()).toEqual(before);+ });+ } finally { rmSync(home, { recursive: true, force: true }); }+}, 180_000);