super-productivity/packages/plugin-dev/sync-md
Johannes Millan f9fd8454cc fix(sync-md): prevent crash when adding subtasks to markdown file directly
Fixes #6021

When users manually added subtasks to markdown files that referenced
non-existent parent tasks, the plugin would crash due to unsafe null
assertions and missing validation. This made the plugin permanently
disabled and required creating a new markdown file to recover.

Changes:
- Added parent ID validation before creating operations
- Orphaned subtasks are now converted to root tasks with warnings
- Added comprehensive error handling with user notifications
- Plugin stays enabled even after sync errors
- Added 15 new tests (689 lines) for orphaned subtask scenarios
- Fixed all existing tests to support new error notifications

The fix implements defense-in-depth:
1. Validation layer: Check parent IDs exist before operations
2. Error handling: Catch and report errors without crashing
3. User feedback: Clear notifications about issues
4. Data preservation: No data loss, orphans become root tasks
2026-01-16 13:28:05 +01:00
..
docs feat(sync-md): new approach and make it work better 2025-07-07 18:39:14 +02:00
scripts fix: all console errors 2025-07-22 20:34:12 +02:00
src fix(sync-md): prevent crash when adding subtasks to markdown file directly 2026-01-16 13:28:05 +01:00
.gitignore feat(sync-md): new approach and make it work better 2025-07-07 18:39:14 +02:00
.prettierrc.json feat(syncMd): add comprehensive test suite and development configuration 2025-07-10 14:56:19 +02:00
eslint.config.js chore(deps): upgrade ESLint to v9 with flat config 2026-01-10 16:08:11 +01:00
jest.config.cjs feat(syncMd): add comprehensive test suite and development configuration 2025-07-10 14:56:19 +02:00
jest.config.js.bak fix(sync-md): fix failing tests after parser changes 2025-07-10 19:17:41 +02:00
package-lock.json feat(effects): consolidate task update actions in PluginHooksEffects 2026-01-04 13:03:28 +01:00
package.json build: update vite dep 2025-10-28 11:07:52 +01:00
README.md feat(sync-md): new approach and make it work better 2025-07-07 18:39:14 +02:00
tsconfig.json feat(sync-md): new approach and make it work better 2025-07-07 18:39:14 +02:00
vite.config.ts feat(sync-md): new approach and make it work better 2025-07-07 18:39:14 +02:00

Sync-MD Plugin v2.0.0

A SuperProductivity plugin that enables bidirectional synchronization between markdown files and project tasks.

Features

  • Bidirectional Sync: Keep markdown files and SuperProductivity tasks in sync
  • Batch API Integration: Efficient bulk operations for better performance
  • Smart Debouncing: 10-second delays prevent conflicts during active editing
  • Real-time Monitoring: File system watching with automatic sync triggers
  • Task Hierarchy: Preserves parent-child relationships in markdown
  • Modern Architecture: Built with Solid.js UI and modular TypeScript

Quick Start

# Install dependencies
npm install

# Development mode with hot reload
npm run dev:watch

# Build for production
npm run build

# Package as plugin
npm run package

Architecture

Core Components

  • src/fileWatcherBatch.ts - Main sync engine with batch API support
  • src/background.ts - Plugin lifecycle and message handling
  • src/App.tsx - Solid.js UI for configuration
  • src/utils/ - Reusable utilities (parser, debouncer, file ops)

Build System

  • build-proper.js - Main build script
  • build-plugin.js - Package as distributable ZIP
  • watch-and-build.js - Development with auto-rebuild

Configuration

{
  projectId: "project-uuid",
  filePath: "/path/to/tasks.md",
  syncDirection: "fileToProject" | "projectToFile" | "bidirectional"
}

Markdown Format

- [ ] Parent task
  - [x] <!-- sp:task-id --> Completed subtask
  - [ ] Pending subtask

Tasks are linked using HTML comments containing unique IDs.

Testing

# Run all tests
npm test

# Watch mode
npm run test:watch

# Coverage report
npm run test:coverage

Documentation

For detailed documentation, see:

Cleanup

To remove old/unnecessary files after updating:

chmod +x cleanup.sh
./cleanup.sh