Skip to main content

Syntax

Description

The sync command manages data flow between sudocode’s 3-layer storage system: Markdown FilesJSONL FilesSQLite Database Use sync to:
  • Synchronize after git pull (update local database)
  • Sync after manual markdown edits
  • Force a specific sync direction
  • Watch for changes and auto-sync
  • Troubleshoot sync issues
Most commands automatically sync when needed. Use manual sync after external changes (git pull, manual file edits) or when troubleshooting.

Storage Architecture

sudocode uses a 3-layer storage system:
1

Layer 1: Markdown Files

Human-readable spec and issue files in .sudocode/specs/ and .sudocode/issues/Purpose: Version control, human editing, readability
2

Layer 2: JSONL Files

Line-delimited JSON in .sudocode/specs.jsonl and .sudocode/issues.jsonlPurpose: Git-friendly structured data, source of truth
3

Layer 3: SQLite Database

Local database .sudocode/sudocode.dbPurpose: Fast queries, relationships, views
Data flow:
  • User edits markdown → Sync to JSONL → Import to database
  • CLI updates database → Export to JSONL → Sync to markdown

Options

--watch
boolean
Watch for file changes and auto-syncExample: --watchStarts a file watcher that automatically syncs when files change. Press Ctrl+C to stop.Debounce: 2000ms (2 seconds) delay to batch rapid changes
--from-markdown
boolean
Force sync FROM markdown TO databaseExample: --from-markdownAlways syncs in this direction, regardless of file modification times.Use after: Manual markdown edits, git pull with markdown changes
--to-markdown
boolean
Force sync FROM database TO markdownExample: --to-markdownAlways syncs in this direction, regardless of file modification times.Use after: CLI operations that updated database only

Examples

Automatic Direction Detection

Let sudocode determine sync direction:

After Git Pull

Sync database with pulled changes:

Force Sync from Markdown

After manually editing markdown files:

Force Sync to Markdown

Regenerate markdown from database:

Watch Mode

Auto-sync on file changes:
Press Ctrl+C to stop the watcher.

JSON Output

Get machine-readable output:

How Sync Direction is Determined

When you run sync without flags, it automatically detects the correct direction:
1

Compare file modification times

For both specs and issues:
  • Get most recent markdown file modification time
  • Get JSONL file modification time
2

Determine direction for each type

  • If markdown is newer → sync FROM markdown
  • If JSONL is newer → sync TO markdown
  • If timestamps match → no sync needed
3

Handle conflicts

If specs and issues want different directions:
  • Prefer FROM markdown (preserves user edits)
  • Reason: User edits in markdown take precedence

Decision Matrix

Common Workflows

Daily Development

1

Start work

Pull latest changes:
2

Make changes

Edit specs or issues via CLI or markdown:
3

Sync before commit

After Manual Markdown Edits

1

Edit markdown

2

Sync to database

3

Verify changes

Troubleshoot Sync Issues

1

Force resync from JSONL

2

Check for errors

Look for sync errors in output
3

Manually inspect

Development with Watch Mode

For active development:

Understanding Sync Behavior

Auto-Sync in Commands

Most commands auto-sync as needed:
  • Creating entities: Database → JSONL → Markdown
  • Updating entities: Database → JSONL → Markdown
  • After operations: JSONL export triggered automatically
When manual sync is needed:
  • After git pull (external changes)
  • After manual markdown edits
  • Troubleshooting inconsistencies

Sync Operations

From Markdown:
1

Read markdown files

Parse frontmatter and content from .sudocode/specs/ and .sudocode/issues/
2

Update database

Insert or update records in SQLite database
3

Export to JSONL

Write updated data to specs.jsonl and issues.jsonl
To Markdown:
1

Read from database

Query all specs and issues from SQLite
2

Generate markdown

Create markdown files with frontmatter and content
3

Write files

Save to .sudocode/specs/ and .sudocode/issues/

Watch Mode Details

Watch mode monitors file changes and auto-syncs: Configuration:
  • Debounce delay: 2000ms (2 seconds)
    • Waits 2 seconds after last change before syncing
    • Prevents excessive syncs during rapid edits
  • Watched directories:
    • .sudocode/specs/
    • .sudocode/issues/
    • .sudocode/*.jsonl
Events detected:
  • File creation
  • File modification
  • File deletion
Graceful shutdown:
  • Press Ctrl+C to stop
  • Ensures clean exit

Common Questions

Manual sync is needed when:
  • After git pull (pulled JSONL changes)
  • After editing markdown files directly
  • Troubleshooting sync inconsistencies
  • Regenerating markdown from database
Most CLI operations auto-sync automatically.
  • sync: Bidirectional, auto-detects direction, handles markdown ↔ database
  • export: Database → JSONL only
  • import: JSONL → Database only
Use sync for normal operations, export/import for manual data migration.
Generally no, but:
  • Syncing FROM markdown overwrites database changes
  • Syncing TO markdown overwrites markdown edits
  • Always commit to git before major sync operations
  • JSONL files are the source of truth - never deleted
User edits in markdown are considered intentional and take precedence over database state. This protects manual work.
Use git:
Or restore from JSONL:
Not directly. Sync operates on all files. For selective updates, use specific commands:

Troubleshooting

Cause: Modification times are equal despite content differencesSolution: Force specific direction:
Cause: Invalid markdown format or corrupted dataSolution:
  1. Check file format:
  2. Fix frontmatter issues
  3. Resync:
Cause: File system watcher issues or editor behaviorSolution:
  1. Restart watch mode
  2. Use manual sync instead
  3. Check editor settings (some use atomic writes that may not trigger watchers)
Cause: Large number of filesSolution: Normal for large projects. Consider:
  • Archiving old entities
  • Splitting into multiple projects
  • Using watch mode instead of manual sync
Cause: Merge conflict in JSONL filesSolution:
  1. Resolve JSONL conflicts in git
  2. Force import from JSONL:

export

Export to JSONL

import

Import from JSONL

status

Check sync status

Next Steps

1

Pull latest changes

2

Sync database

3

Verify sync

4

Start work

Use CLI commands normally - auto-sync handles the rest

Storage Model

Learn more about sudocode’s 3-layer storage architecture