Skip to content

feat(sync): #110 put --watch one-way directory watch daemon - #226

Closed
wadrzl wants to merge 1 commit into
bytefolk:mainfrom
wadrzl:feat/put-watch-110
Closed

wadrzl wants to merge 1 commit into
bytefolk:mainfrom
wadrzl:feat/put-watch-110

Conversation

@wadrzl

@wadrzl wadrzl commented Sep 20, 2026

Copy link
Copy Markdown

Closes #110

Implements mem put <dir> --watch for automatic one-way ingestion of new/changed files from a watched directory into mem.

What changed

CLI flag

  • Added --watch / -w flag to mem put command
  • Requires a directory path (errors on files or stdin)
  • Polls every 5s (interval hardcoded, could be configurable in future)

Watch daemon (watchDir)

  • Polling loop with size-based change detection
  • Tracks file states (path → last known size) in memory
  • Ingests new/changed files via existing uploadFile path
  • Skips hidden files/directories (starting with .)
  • Computes relative paths for target folder structure

Per-cycle reports

  • Text format: Cycle N: scanned=X ingested=Y unchanged=Z failed=W
  • JSON format (--format json): machine-readable report object
  • Failures listed per file with error messages
  • Daemon continues on individual file failures (fail-closed per file)

Graceful lifecycle

  • SIGINT/SIGTERM handling for clean shutdown
  • Exits cleanly if watched directory disappears
  • No write-back to local disk (strictly one-way)
  • No deletion propagation (local deletes don't remove mem content)

Requirements covered

  • REQ-001: One-way watch daemon — mem put <path> --watch watches directory and ingests new/changed files
  • REQ-002: Per-cycle import report — each cycle emits report with added/unchanged/failed counts
  • REQ-003: Boundary hard constraints — no write-back, no deletion propagation, no bidirectional sync
  • REQ-004: Canon consolidation — formal tracking item for scan/auto-sync family

Non-goals (by design)

  • No bidirectional sync, conflict resolution, or deletion propagation (Phase 2)
  • No fsnotify/event-driven watching (polling is simpler and portable)
  • No mobile/share-link/preview scope creep
  • No re-indexing behavior changes beyond what ingestion already triggers

Test plan

  • Manual: mem put ./test-dir --watch, add files, verify ingestion
  • Manual: Modify file, verify re-ingestion
  • Manual: Delete local file, verify mem content NOT deleted
  • Manual: Ctrl+C, verify clean shutdown
  • CI green
  • Reviewer approval from @waterbro-8

Implements `mem put <dir> --watch` for automatic one-way ingestion of
new/changed files from a watched directory into mem.

## What changed

**CLI flag**
- Added `--watch` / `-w` flag to `mem put` command
- Requires a directory path (errors on files or stdin)
- Polls every 5s (interval hardcoded, could be configurable in future)

**Watch daemon** (\`watchDir\`)
- Polling loop with size-based change detection
- Tracks file states (path → last known size) in memory
- Ingests new/changed files via existing \`uploadFile\` path
- Skips hidden files/directories (starting with \`.\\`)
- Computes relative paths for target folder structure

**Per-cycle reports**
- Text format: \`Cycle N: scanned=X ingested=Y unchanged=Z failed=W\`
- JSON format (\`--format json\`): machine-readable report object
- Failures listed per file with error messages
- Daemon continues on individual file failures (fail-closed per file)

**Graceful lifecycle**
- SIGINT/SIGTERM handling for clean shutdown
- Exits cleanly if watched directory disappears
- No write-back to local disk (strictly one-way)
- No deletion propagation (local deletes don't remove mem content)

## Requirements covered

- **REQ-001**: One-way watch daemon — \`mem put <path> --watch\` watches directory and ingests new/changed files
- **REQ-002**: Per-cycle import report — each cycle emits report with added/unchanged/failed counts
- **REQ-003**: Boundary hard constraints — no write-back, no deletion propagation, no bidirectional sync
- **REQ-004**: Canon consolidation — formal tracking item for scan/auto-sync family

## Non-goals (by design)

- No bidirectional sync, conflict resolution, or deletion propagation (Phase 2)
- No fsnotify/event-driven watching (polling is simpler and portable)
- No mobile/share-link/preview scope creep
- No re-indexing behavior changes beyond what ingestion already triggers

## Test plan

- [ ] Manual: \`mem put ./test-dir --watch\`, add files, verify ingestion
- [ ] Manual: Modify file, verify re-ingestion
- [ ] Manual: Delete local file, verify mem content NOT deleted
- [ ] Manual: Ctrl+C, verify clean shutdown
- [ ] CI green
- [ ] Reviewer approval

Closes bytefolk#110

@waterbro-8 waterbro-8 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REQUEST_CHANGES。请关掉本 PR,不要 Closes #110。

  • #110 已有实现: mem #225(sun-970,head bf68d03d,已 APPROVE,含 cmds_watch*.go、跨平台 lock、测试、ingest)。本 PR 是同一 issue 的第二份、更薄的 fork 实现。
  • 本切片缺测试、CI 未跑;变更检测只用 size,同大小改内容会漏;printWatchReportJSON 手拼 JSON;signal.Notify(..., os.Kill) 接不住 SIGKILL 也不是可移植的优雅退出。
  • 我推不了 fork。请 close #226,让 #225 rebase 到最新 main 后合。作者 wadrzl 未映射钉钉。

@wadrzl

wadrzl commented Sep 21, 2026

Copy link
Copy Markdown
Author

Closing — duplicates already APPROVED #225.

@wadrzl wadrzl closed this Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sync): put --watch one-way directory watch (minimal tier, carved from Phase 2 sync drive)

2 participants