fix: make config sync directories configurable via config.yaml#15
Closed
LLQWQ wants to merge 3 commits into
Closed
fix: make config sync directories configurable via config.yaml#15LLQWQ wants to merge 3 commits into
LLQWQ wants to merge 3 commits into
Conversation
Config files (.obsidian/*, .agents/*, etc.) should only be synced via SettingSync protocol, not FileSync. This fixes three issues: 1. _initial_sync(): only call file_sync.request_sync() when sync_files is true, not when sync_config is true 2. _push_all_files(): skip config files entirely, let _push_all_settings handle them via SettingSync 3. file_sync._collect_local_files(): always skip dot-prefixed directories, regardless of sync_config setting Previously, config files were uploaded to both file DB and setting DB, causing conflicts and plugin loss during sync.
Config directories (.obsidian, .agents, etc.) are managed by SettingSync protocol, not FolderSync. This prevents accidental deletion of the entire .obsidian directory when the server sends FolderSyncDelete after config records are removed from the file database. The fix adds checks in all three FolderSync handlers: - _on_sync_modify: skip creating dot-prefixed dirs - _on_sync_delete: skip deleting dot-prefixed dirs (CRITICAL) - _on_sync_rename: skip renaming dot-prefixed dirs
Reviewer's GuideAligns FileSync, SettingSync, FolderSync, and SyncEngine so that .obsidian and .agents are always treated as config directories, other dot-prefixed directories follow sync_config, and file sync never uploads config directories while folder events for dot-dirs are ignored, preventing accidental deletion or desync of custom config dirs. Sequence diagram for handling config directory files during syncsequenceDiagram
actor User
participant SyncEngine
participant FileSync
participant SettingSync
participant FolderSync
participant Server
User->>SyncEngine: start_sync()
SyncEngine->>SettingSync: request_sync()
SettingSync-->>SyncEngine: settings_sync_started
SyncEngine->>FileSync: request_sync()
FileSync-->>SyncEngine: file_sync_started
rect rgb(235, 245, 255)
note over SettingSync,Server: Upload config file in .agents
SettingSync->>Server: upload(.agents/agent.json)
Server-->>SettingSync: ack
end
rect rgb(245, 235, 255)
note over Server,FolderSync: Folder event for .agents directory
Server-->>FolderSync: FolderSyncModify .agents
FolderSync->>FolderSync: inspect rel_path
FolderSync->>FolderSync: first startswith dot
FolderSync-->>Server: ignore config dir event
end
rect rgb(235, 255, 235)
note over SyncEngine,FileSync: Decide whether to upload file
SyncEngine->>SyncEngine: _is_config(.agents/agent.json)
SyncEngine-->>FileSync: is_config = True
FileSync->>FileSync: _collect_local_files()
FileSync->>FileSync: skip config file
FileSync-->>SyncEngine: no upload for .agents
end
SyncEngine-->>User: sync_complete
Class diagram for updated sync components config handlingclassDiagram
class SyncConfig {
bool sync_files
bool sync_config
}
class SyncEngine {
+SyncConfig config
+FileSync file_sync
+SettingSync setting_sync
+Path vault_path
+bool _is_note(rel_path)
+bool _is_config(rel_path)
+bool _should_sync_file(rel_path)
+async _initial_sync()
+async _push_all_files()
+bool is_excluded(rel_path)
}
class FileSync {
+SyncEngine engine
+SyncConfig config
+list _collect_local_files()
+async request_sync()
+async push_upload(rel_path)
}
class SettingSync {
+SyncConfig config
+async request_sync()
+async handle_message(msg_data)
}
class FolderSync {
+Path vault_path
+async _on_sync_modify(msg)
+async _on_sync_delete(msg)
+async _on_sync_rename(msg)
}
class SettingSyncHelpers {
+dict _extract_inner(msg_data)
+bool _is_config_path(rel, custom_dirs)
}
SyncEngine --> SyncConfig : uses
FileSync --> SyncEngine : uses
FileSync --> SyncConfig : uses
SettingSync --> SyncConfig : uses
SyncEngine --> FileSync : coordinates
SyncEngine --> SettingSync : coordinates
SyncEngine --> FolderSync : coordinates
SettingSync --> SettingSyncHelpers : uses
note for SyncEngine "_is_config(rel_path):\n- if first segment not dot-prefixed -> False\n- if first is .obsidian or .agents -> True\n- else -> config.sync.sync_config"
note for FileSync "_collect_local_files():\n- skip dot-prefixed dirs only when config.sync.sync_config is True\n- never upload config files\n- upload only when config.sync.sync_files is True"
note for SettingSyncHelpers "_is_config_path(rel, custom_dirs):\n- non dot-prefixed -> False\n- .obsidian or .agents -> True\n- custom_dirs entries -> True\n- all other dot-prefixed dirs -> True (backward compatible)"
note for FolderSync "_on_sync_modify/delete/rename():\n- ignore events whose first path segment is dot-prefixed\n- prevents folder operations on config dirs"
Flow diagram for determining config vs file sync handlingflowchart TD
A["Start with relative path rel"] --> B["first = first path segment"]
B --> C{first startswith dot?}
C -->|No| D["Config: False in SyncEngine._is_config\nSettingSync._is_config_path: False"]
C -->|Yes| E{first is .obsidian or .agents?}
E -->|Yes| F["Config: True in SyncEngine._is_config\nAlways handled as config"]
E -->|No| G{Context}
G -->|SyncEngine / FileSync| H{config.sync.sync_config?}
H -->|Yes| I["Config: True\nDot-prefixed dir treated as config"]
H -->|No| J["Config: False\nDot-prefixed dir treated as normal file"]
G -->|SettingSync| K{first in custom_dirs?}
K -->|Yes| L["Config: True\nCustom config dir"]
K -->|No| M["Config: True\nAll other dot dirs treated as config (backward compatible)"]
subgraph FileSync_behavior
I --> N["_collect_local_files: skip when config.sync.sync_config is True"]
F --> N
M --> N
J --> O["Normal file: considered for upload when config.sync.sync_files is True"]
D --> O
end
subgraph FolderSync_behavior
C -->|Yes| P["Ignore FolderSyncModify/Delete/Rename\nfor dot-prefixed directories"]
C -->|No| Q["Apply folder operation"]
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new FolderSync filters (
_on_sync_modify/delete/rename) treat all dot-prefixed directories as config regardless ofsync_config, which is more aggressive than_is_config; consider reusing the same helper/logic so future changes to config-dir semantics don’t diverge between components. - Config-directory detection is now implemented in several places (
SyncEngine._is_config,SettingSync._is_config_path, FolderSync handlers,FileSync._collect_local_files) with slightly different rules; centralizing this into a shared helper would reduce the risk of subtle inconsistencies over time.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new FolderSync filters (`_on_sync_modify/delete/rename`) treat all dot-prefixed directories as config regardless of `sync_config`, which is more aggressive than `_is_config`; consider reusing the same helper/logic so future changes to config-dir semantics don’t diverge between components.
- Config-directory detection is now implemented in several places (`SyncEngine._is_config`, `SettingSync._is_config_path`, FolderSync handlers, `FileSync._collect_local_files`) with slightly different rules; centralizing this into a shared helper would reduce the risk of subtle inconsistencies over time.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Previously, FileSync and SettingSync had inconsistent hardcoded handling
of dot-prefixed directories. This caused custom config directories like
.agents to not be properly synchronized.
Changes:
- config.py: add config_sync_dirs field to SyncConfig (default: [.obsidian, .agents])
- sync_engine.py: use config_sync_dirs from config instead of hardcoded list
- setting_sync.py: pass config_sync_dirs to _is_config_path()
- file_sync.py: skip dot-prefixed dirs only when sync_config is enabled
- config.yaml: add config_sync_dirs example configuration
Users can now customize which dot-prefixed directories are treated as config
by editing config.yaml:
config_sync_dirs:
- .obsidian
- .agents
- .my-custom-config
Fixes: custom config directories (.agents) not being synced by CLI
1e60a06 to
b12b7b8
Compare
| token: "your_api_token" | ||
| vault: "defaultVault" | ||
| api: "http://127.0.0.1:9000" | ||
| token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEsIm5pY2tuYW1lIjoiaHViaW4iLCJpcCI6IjE4MC4xNTIuNjUuOTkiLCJpc3MiOiJmYXN0LW5vdGUtc3luYy1zZXJ2aWNlIiwic3ViIjoidXNlci10b2tlbiIsImV4cCI6MTgwNzQxMzM0MCwibmJmIjoxNzc1ODc3MzQwLCJpYXQiOjE3NzU4NzczNDAsImp0aSI6IjEifQ.OgUOJXHrxxdNF9pv0tY0j5_qhBMsZsyaD_ByHqAgVtw" |
There was a problem hiding this comment.
security (jwt): Uncovered a JSON Web Token, which may lead to unauthorized access to web applications and sensitive user data.
Source: betterleaks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug Description
CLI's
FileSyncandSettingSynchave inconsistent handling of dot-prefixed directories like.agents:FileSync._collect_local_files()skips ALL dot-prefixed directoriesSettingSyncuses_is_config_path()which treats ALL dot-prefixed dirs as configSyncEngine._is_config()also treats ALL dot-prefixed dirs as configThis causes problems when syncing custom config directories:
.agents/exists on Obsidian but not on CLI vault, CLI won't send it to server.agents/filesImpact
.agents,.my-config, etc.) are not properly synchronizedSteps to Reproduce
.agentsin configSyncOtherDirs.agents/directory in Obsidian.agents/directory).agents/files are not synced to CLI.agents/files may be deletedRoot Cause
In
file_sync.py:In
sync_engine.py:Proposed Fix
Make config directory handling explicit:
.obsidianand.agentsas config directoriessync_configsettingsync_config=True(so they go through SettingSync)
See PR for implementation.
Environment