Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix: adopt never echoes a secret-shaped record key; finalize rerun re-previews after a change

garrytan765c515afda1
diff --git a/docs/guides/storage-manifest.md b/docs/guides/storage-manifest.md
index 5528fc8753..9c73ffbdad 100644
--- a/docs/guides/storage-manifest.md
+++ b/docs/guides/storage-manifest.md
@@ -61,8 +61,8 @@ Agents that archived before the shelf existed often kept interim pages: `type: s
3. `gbrain storage adopt --finalize` previews soft-deleting the tagged originals; its `--expect <plan_hash>` run deletes
them (restorable for 72 hours with `gbrain restore`), only when every adopted card is on the shelf and matches its
original's mapped card. A restore recorded with `storage-update` since adoption is not a difference. The preview
- names any `##` section of an original other than `## Record` (notes the card does not carry, which go with the
- page) and flags an original longer than the 64 KiB it reads, so you read the rest first. The plan_hash binds each
+ names any `##` section in an original's body other than `## Record` (notes the card does not carry, which go with
+ the page; a timeline section gbrain stores apart from the body is not listed) and flags an original longer than the 64 KiB it reads, so you read the rest first. The plan_hash binds each
original's whole content, checked again just before each delete, so an original edited after the preview refuses
`preview_changed`.
diff --git a/src/core/storage-manifest/adopt.ts b/src/core/storage-manifest/adopt.ts
index 3a08663d56..37477230de 100644
--- a/src/core/storage-manifest/adopt.ts
+++ b/src/core/storage-manifest/adopt.ts
@@ -128,12 +128,14 @@ function strip(value: unknown, path: string, refused: RefusedField[]): unknown {
return out;
}
-/** The first string value with a credential shape, by dotted path; the value itself is never returned. */
+/** The first string value or object key with a credential shape, by dotted path; the value or key itself is never returned. */
function credentialAt(value: unknown, path: string): { field: string; shape: string } | null {
if (typeof value === 'string') { const shape = credentialShape(value); return shape ? { field: path || '(record)', shape } : null; }
if (!value || typeof value !== 'object') return null;
const items: Array<readonly [string, unknown]> = Array.isArray(value) ? value.map((item, i) => [String(i), item] as const) : Object.entries(value);
for (const [key, item] of items) {
+ const keyShape = Array.isArray(value) ? null : credentialShape(key);
+ if (keyShape) return { field: `${path || '(record)'} (a key)`, shape: keyShape };
const found = credentialAt(item, path ? `${path}.${key}` : key);
if (found) return found;
}
@@ -154,7 +156,7 @@ export function mapInterimPage(row: Pick<InterimRow, 'slug' | 'title' | 'frontma
const refused: RefusedField[] = [];
const stripped = strip(record, '', refused) as Record<string, unknown>;
const secret = credentialAt(record, '');
- if (secret) return { card: null, refused, problem: { code: 'storage_record_secret', reason: secret.shape, message: `field ${secret.field} has a credential shape (${secret.shape}); the value is not shown` } };
+ if (secret) return { card: null, refused: [], problem: { code: 'storage_record_secret', reason: secret.shape, message: `field ${secret.field} has a credential shape (${secret.shape}); the value is not shown` } };
const frontmatter = (typeof row.frontmatter === 'string' ? JSON.parse(row.frontmatter) : row.frontmatter ?? {}) as Record<string, unknown>;
const aliases = Array.isArray(frontmatter.aliases) ? frontmatter.aliases.filter((a): a is string => typeof a === 'string') : [];
const mapped = { ...stripped, id: stripped.id ?? row.slug.slice(prefix.length).replace(/\//g, '-'), title: stripped.title ?? row.title, aliases: stripped.aliases ?? aliases };
@@ -333,5 +335,5 @@ export async function applyFinalize(ctx: OperationContext, opts: AdoptOptions &
return { action: 'finalize', dry_run: false, source_id: opts.sourceId, prefix: opts.prefix, plan_hash: plan.plan_hash,
side_effects: failure ? (deleted.length ? 'partial' : 'none') : deleted.length ? 'complete' : 'none', deleted,
skipped: plan.entries.filter((e) => e.state !== 'delete').map((e) => e.slug),
- ...(failure ? { failure, rerun: [...adoptArgv(opts), '--finalize', '--expect', plan.plan_hash] } : {}) };
+ ...(failure ? { failure, rerun: failure.code === 'preview_changed' ? previewFix(opts, true).argv! : [...adoptArgv(opts), '--finalize', '--expect', plan.plan_hash] } : {}) };
}
diff --git a/test/storage-manifest-adopt.test.ts b/test/storage-manifest-adopt.test.ts
index ebbdb2ae88..e10f39fcf3 100644
--- a/test/storage-manifest-adopt.test.ts
+++ b/test/storage-manifest-adopt.test.ts
@@ -5,7 +5,7 @@
* - the apply needs the preview's plan_hash (a stale one refuses preview_changed) and each refused field named with
* --drop-field (storage_adopt_field_refused otherwise); it registers each card with origin adopt and tags the
* original storage-manifest-adopted, and never soft-deletes anything;
- * - a credential-shaped value refuses storage_record_secret whatever else is dropped, without echoing the value;
+ * - a credential-shaped value or record key refuses storage_record_secret whatever else is dropped, without echoing it;
* - idempotent: a card already on the shelf that matches is tagged only, a rerun writes nothing, and the plan_hash a
* half-finished run printed still applies; a differing card is a conflict, never overwritten, its original untagged;
* - finalize previews, then soft-deletes only the tagged originals whose card matches (storage_adopt_unverified when
@@ -134,6 +134,11 @@ describe('storage adopt on a repo-less brain', () => {
expect(refused!.message).not.toContain('fake-key-value');
expect(JSON.stringify(plan)).not.toContain('fake-key-value');
expect(await engine.executeRaw("SELECT 1 FROM sources WHERE id='storage'")).toEqual([]);
+
+ await interim('storage-manifest/dataset-k', { ...record('dataset-k'), AKIAIOSFODNN7EXAMPLE: 'x' });
+ const keyed = (await previewAdopt(ctx(), opts)).entries.find((e) => e.slug === 'storage-manifest/dataset-k')!;
+ expect(keyed).toMatchObject({ state: 'blocked', refused: [], problem: { code: 'storage_record_secret', reason: 'secret_scanner' } });
+ expect(JSON.stringify(await previewAdopt(ctx(), opts))).not.toContain('AKIAIOSFODNN7EXAMPLE');
}, 60_000);
test('an unreadable record and a duplicate card id block the apply', async () => {