70 lines
2.8 KiB
Markdown
70 lines
2.8 KiB
Markdown
# Implementation Plan: InBox → Gantt Nightly Sync
|
|
|
|
## Source of Truth
|
|
- Spec: `.omx/specs/deep-interview-scheduled-task-git-sync-gant.md`
|
|
- Context: `.omx/context/scheduled-task-git-sync-gant-20260429T161523Z.md`
|
|
|
|
## Architecture
|
|
|
|
```
|
|
Windows Task Scheduler (22:30 daily)
|
|
└─ powershell.exe -ExecutionPolicy Bypass -File "sync-inbox-to-gantt.ps1"
|
|
├─ 1. Git sync (pull, add, commit, push)
|
|
├─ 2. Gantt bidirectional mirror (InBox ↔ Gantt "待看:*" tasks)
|
|
└─ 3. Notifications (push failure toast)
|
|
```
|
|
|
|
## Files to Create
|
|
|
|
| File | Path | Purpose |
|
|
|------|------|---------|
|
|
| Sync script | `C:\Users\Zane\Desktop\Gantt App\sync-inbox-to-gantt.ps1` | Main nightly script |
|
|
| Setup script | `C:\app\unity_project\obsidian-notes\.omx\setup-task.ps1` | One-shot Task Scheduler registration |
|
|
|
|
## Algorithm
|
|
|
|
### Phase A — Git Sync
|
|
1. `cd C:\app\unity_project\obsidian-notes`
|
|
2. `git pull` — if conflict → `git merge --abort` → exit git phase
|
|
3. `git add PARA/ InBox/`
|
|
4. `git diff --cached --quiet` → if no changes, skip commit
|
|
5. `git commit -m "auto nightly sync"`
|
|
6. `git push` — if failure → Show-Toast "Git push failed" → continue
|
|
|
|
### Phase B — Gantt Mirror
|
|
1. Call `gantt-app.exe --cli list-tasks` → parse JSON
|
|
- If Gantt not running (process error / non-zero exit) → skip phase B
|
|
2. Extract `"待看:*"` tasks → set `{baseName}` from task name
|
|
3. Scan `InBox\*.md` → set `{baseName}` from filename (strip .md)
|
|
4. **Add**: For each InBox file NOT in Gantt → `add-task --name "待看:{baseName}" --start {today} --end "" --progress 0`
|
|
5. **Delete**: For each Gantt "待看:*" NOT in InBox → `delete-task --id {id}`
|
|
6. **Existing matches**: No-op (already correct)
|
|
|
|
### Error Handling Matrix
|
|
|
|
| Failure | Behavior |
|
|
|---------|----------|
|
|
| Git pull conflict | `git merge --abort`, skip rest of git phase |
|
|
| Git push fails | PowerShell toast notification, continue to Gantt phase |
|
|
| Gantt CLI not found | Write-Error, exit 1 |
|
|
| Gantt not running | Skip Gantt phase silently |
|
|
| Gantt add/delete fails | Write-Error for that item, continue |
|
|
| Script not in gantt dir | Resolve gantt dir from script location dynamically |
|
|
|
|
## Task Scheduler Registration
|
|
|
|
```powershell
|
|
$action = New-ScheduledTaskAction -Execute "powershell.exe" `
|
|
-Argument "-ExecutionPolicy Bypass -File `"C:\Users\Zane\Desktop\Gantt App\sync-inbox-to-gantt.ps1`""
|
|
$trigger = New-ScheduledTaskTrigger -Daily -At 22:30
|
|
Register-ScheduledTask -TaskName "InBox-Gantt-Nightly-Sync" `
|
|
-Action $action -Trigger $trigger -RunLevel Highest `
|
|
-Description "Nightly sync Obsidian InBox to Gantt tasks with git auto-commit"
|
|
```
|
|
|
|
## Implementation Tasks
|
|
|
|
1. **Create sync-inbox-to-gantt.ps1** — the main sync script with all logic
|
|
2. **Create setup-task.ps1** — registers the scheduled task
|
|
3. **Manual dry-run test** — run script manually, verify Gantt tasks created
|