fix: raw SQL from db export -o {data} envelope; warn when create silently relinks directory

AG
3mo ago
+205-5

What was broken

Two frictions reported in the same feedback:

  1. db export --format sql -o file.sql wrote a JSON envelope. The backend can wrap the export payload as {format, data, tables}, but src/commands/db/export.ts only unwrapped the {format, content, tables} shape — any data-keyed response fell through to the raw-text branch and the .sql file ended up containing the JSON envelope instead of usable SQL.

  2. insforge create silently relinked the working directory. Creating a blank project overwrites .insforge/project.json in cwd with no notice when the directory was already linked to a different project — subsequent db query/db export commands then hit the wrong project unnoticed (the reporter's prod verification queries silently ran against staging).

What changed

  • src/commands/db/export.ts: new exported extractExportContent() accepts a string content or data key when unwrapping the export envelope, so -o file.sql writes raw SQL/JSON. Non-envelope responses still pass through verbatim.
  • src/commands/create.ts: new exported detectRelink() checks the existing project link before saveProjectConfig overwrites it. On a relink, interactive mode prints a prominent LINK CHANGED: this directory was linked to "<old>" ... and now points to "<new>" warning via clack.log.warn, and --json output gains a linkChanged: {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 real db export command with a mocked ossFetch — {format, data} envelope → raw SQL written; {format, content} envelope still unwrapped; non-envelope response passes through verbatim; plus unit cases for extractExportContent.
  • New detectRelink cases in src/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 unrelated apify.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.