fix: raw SQL from db export -o {data} envelope; warn when create silently relinks directory
What was broken
Two frictions reported in the same feedback:
-
db export --format sql -o file.sqlwrote a JSON envelope. The backend can wrap the export payload as{format, data, tables}, butsrc/commands/db/export.tsonly unwrapped the{format, content, tables}shape — anydata-keyed response fell through to the raw-text branch and the.sqlfile ended up containing the JSON envelope instead of usable SQL. -
insforge createsilently relinked the working directory. Creating a blank project overwrites.insforge/project.jsonin cwd with no notice when the directory was already linked to a different project — subsequentdb query/db exportcommands then hit the wrong project unnoticed (the reporter's prod verification queries silently ran against staging).
What changed
src/commands/db/export.ts: new exportedextractExportContent()accepts a stringcontentordatakey when unwrapping the export envelope, so-o file.sqlwrites raw SQL/JSON. Non-envelope responses still pass through verbatim.src/commands/create.ts: new exporteddetectRelink()checks the existing project link beforesaveProjectConfigoverwrites it. On a relink, interactive mode prints a prominentLINK CHANGED: this directory was linked to "<old>" ... and now points to "<new>"warning viaclack.log.warn, and--jsonoutput gains alinkChanged: {previousProjectId, previousProjectName}field. Template projects link inside a freshly created subdirectory, so they're unaffected (correctly no warning).
No flags, defaults, or documented output shapes changed, so no agent-skills update is needed — the fix makes -o behave as the skill already documents.
Verification
- New
src/commands/db/export.test.ts: drives the realdb exportcommand with a mockedossFetch—{format, data}envelope → raw SQL written;{format, content}envelope still unwrapped; non-envelope response passes through verbatim; plus unit cases forextractExportContent. - New
detectRelinkcases insrc/commands/create.test.ts: different project → previous link returned; unlinked dir → null; same project → null. - Full suite:
npx vitest run→ 646 passed / 13 skipped.npm run lint→ 0 errors (1 pre-existing warning in unrelatedapify.test.ts).
Addresses user feedback 4b503324-b3a5-4479-9b0d-7616c97a6dd4 (cli): CORRECTION: db export works — real issue is silently relinking + JSON envelope in -o output
🤖 Generated with Claude Code
Summary by cubic
Fixes db export to unwrap {content|data} envelopes so -o writes raw SQL/JSON and ensures --json includes the exported content. Also warns when create would relink the current directory to a different project and adds linkChanged to --json; addresses Linear feedback 4b503324.
- Bug Fixes
- db export: unwraps {format, content|data, tables}; non-envelope responses pass through; -o now writes raw SQL/JSON.
- db export: --json now preserves content by returning { format, tables, content }.
- create: detects relink before saving and warns in interactive mode; --json includes linkChanged with previous project info.
[!NOTE]
Fix db export to unwrap data envelope and warn on silent relink in create
db export now correctly handles backend responses that wrap the SQL payload in either a content or data JSON field via the new extractExportContent helper in export.ts; previously only content was handled, so -o would write the raw JSON wrapper instead of SQL.
create now detects when a directory was previously linked to a different project via the new detectRelink function in create.ts, logging a warning in interactive mode or including a linkChanged object in JSON output.
- Behavioral Change:
db export -o with a data-enveloped response now writes raw SQL instead of the JSON envelope.
Macroscope summarized 47c6f1c.