Skip to content

feat: filter rules - #160

Open
miaobuao wants to merge 12 commits into
nutstore:mainfrom
miaobuao:fix/sync-speed
Open

feat: filter rules#160
miaobuao wants to merge 12 commits into
nutstore:mainfrom
miaobuao:fix/sync-speed

Conversation

@miaobuao

Copy link
Copy Markdown
Contributor

No description provided.

Replace the split exclusion/inclusion lists with a single ordered rule list where every rule carries an explicit include/exclude type and the last match wins, matching gitignore semantics.

### What
- Drop the transitive glob-to-regexp dependency for a hand-written gitignore-compatible matcher (gitignore-pattern.ts), verified against a 208-case corpus generated from Git itself.
- Persist filterRules as one ordered { rules } list; migrate legacy exclusionRules/inclusionRules shapes on load.
- Update the settings UI to a single rule editor with per-rule type select, case toggle, and up/down ordering.
- Re-anchor bookmarks config-dir sync to re-include the parent dir first so a later child include is not pruned.
- Document the compatibility contract in docs/filter-rules.md.

### Why
Separate whitelist/blacklist lists had inherent priority ambiguity and did not support ordering. Treating rules as an ordered gitignore-style sequence removes that ambiguity, and pruning excluded parents protects against accidental reinclusion of files under ignored directories.

### Key changes
- src/utils/gitignore-pattern.ts: gitignore-aware glob compiler (anchoring, ** positions, bracket classes, escaping).
- src/utils/filter-rules.ts: compileFilterRules, migrateLegacyFilterRules, isPathIncluded (last-match-wins over every ancestor).
- config-dir-rules: system hard-exclusions appended last so they always win.
Replace slow structure-based isEqual with arrayBufferEquals (size short-circuit + 32-bit word compares) in content comparison and conflict resolution, and skip blob/file reads when local size differs from the recorded size.
### What
- Expose a whitelist of plugin sync settings as the virtual, editable file /.config/nutstore-sync/settings.json (mounted into the bash/apply_patch filesystem). Reads reflect live settings; every write is validated and applied on the spot; unknown keys and credentials (account, credential, OAuth, AI provider keys) are rejected so secrets can never be touched.
- Add a 'settings' permission request type: SettingsFs gates writes before applying, and the permission modal shows a human-readable summary of the setting changes.
- Refactor the reversible-op recorder onto the mountable virtual filesystem (vault, /tmp, /.agents, settings) via a generic ReversibleFs snapshot wrapper, so undo/recall works uniformly across mounts.
- Add the top-level dot-dir mount (/.config/nutstore-sync) alongside the existing /.agents mount, and reuse VAULT_MOUNT_POINT (/vault) instead of a hardcoded literal; normalize persisted reversible-op paths on session load (legacy /vault/... records are rewritten to vault-relative on rehydration).
- apply_patch now targets the virtual filesystem; bash and apply_patch share settings read/write. Update system prompts, the built-in guide (new settings.md reference), and i18n (including settings summaries and clarified copy, en+zh).

### Why
- Previously the AI ChatBox could not adjust plugin sync settings directly; users had to change them by hand. This lets the agent read and change supported settings through its existing file/bash tools, with validation and user confirmation.
- The recorder refactor is needed because reversible tracking previously lived inside the vault/adapter FS classes; generalizing it to state transitions keeps one mechanism for all mounts including the new virtual settings file.

### Key changes
- src/ai/tools/settings-whitelist.ts / settings-fs.ts: whitelist schema, parse/serialize/validate, patch application, permission summary
- src/ai/tools/bash/fs.ts: ReversibleOpRecorder rewritten around begin/endCapture + recordVirtualTransition, replacing per-FS recordCreate/Update/Delete; getNetOperations emits create/delete/update and also delete+create when a path's kind changes (dir<->file) so recall can restore the original tree
- src/ai/tools/bash/reversible-fs.ts: IFileSystem wrapper that snapshots before/after each mutation
- src/ai/chat/messages/reversible-op-utils.ts / session-store.ts: path normalization + change-flag propagation for session persistence rewrite
- src/ai/tools/vault-filesystem.ts (+ apply-patch.ts, bash/tool.ts, runtime.ts): settings mount and shared settings IO deps wired through ToolExecutor/AgentRunner/ChatService
- src/ai/tools/bash/mount-points.ts: AGENTS_MOUNT_POINT /.agents, SETTINGS_MOUNT_POINT /.config/nutstore-sync; src/ai/tools/bash/adapter-fs.ts reuses VAULT_MOUNT_POINT instead of a literal
- src/services/settings.service.ts: applySettingsPatch() reuses the reload side-effect chain (i18n, chat handleSettingsChanged, conflict refresh, schedule update, tab rerender)
Filter rules gain a disabled flag; disabled rules are skipped during matching and are toggleable in the filter editor and via the AI settings file.

Sync all now detects when a user rule prunes the config directory itself, highlights the offending rule in the confirm modal, and re-warns on manual sync.

Default filter rules replace the catch-all hidden-path rule with an explicit list so the config directory can sync in all mode (affects new installs only).

Fix config-dir sync modals so dismissing via mask or X restores the dropdown instead of leaving the UI showing an unconfirmed mode.
@miaobuao
miaobuao force-pushed the fix/sync-speed branch 2 times, most recently from 24386f8 to 34f6aa3 Compare August 14, 2026 09:37
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.

1 participant