Commit Graph
15 Commits
Author SHA1 Message Date
macbookpro 7a8db3bdb5 fix(skillignore): strip \r so CRLF files match
ReadMatcher splits on "\n" and parseRule/Compile only trimmed " \t", so a
.skillignore saved with CRLF line endings compiled every rule with a
trailing \r that could never equal a path segment. status still reported
the patterns as loaded, so the file silently ignored nothing. The same
trim in write.go made HasPattern miss existing entries, AddPattern
duplicate them and RemovePattern fail to find them.

The pre-Matcher ReadPatterns used TrimSpace and handled CRLF; this
regressed in 4214cb10 (v0.17.4). Trim \r alongside the existing
whitespace, matching how git reads CRLF .gitignore files.

Refs #275
2026-09-05 11:37:20 +08:00
jnhu 6b8923d260 replace em dash with colon in test message to avoid Unicode warning 2026-06-04 20:28:12 +08:00
jnhu 4b9d04aa80 optimize skillignore globstar memoization 2026-06-04 20:28:12 +08:00
jnhu 872a6ada8c fix(skillignore): memoize matchSegments to prevent exponential backtracking
Repeated ** segments caused O(N^K) recursive backtracking where K is
the number of consecutive globstars. Convert to index-based recursion
with (patternIndex, pathIndex) memoization, reducing to O(P*N).

The change is intended to preserve existing matching behavior while
avoiding repeated evaluation of the same (patternIndex, pathIndex)
states. Existing tests pass, and additional globstar semantics tests
were added to guard the core behavior.

Fixes exponential hang on patterns like **/**/**/**/0 with 150+ segment
paths (previously >2s, now ~60ms).
2026-06-04 20:28:12 +08:00
Willie 12f8c52a11 feat: add .agentignore support and agent file validation
Add ReadAgentIgnoreMatcher() in skillignore package to read .agentignore
and .agentignore.local files using the same gitignore-style pattern
format as .skillignore.

Integrate .agentignore filtering into AgentKind.Discover() with both
directory-level CanSkipDir() and file-level Match() checks.

Add agent validation in internal/validate/:
- AgentFile(): extension check, filename restrictions (no spaces/special
  chars), file size warning (>100KB), existence and type checks
- AgentName(): name format validation (alphanumeric + hyphens/underscores)

9 new tests across resource and validate packages.
2026-04-07 18:05:40 +08:00
Willie e0d0313b0d refactor: simplify enable/disable after code review
- AddPattern returns (bool, error) — single file read, no TOCTOU
- Remove external HasPattern guard in CLI (AddPattern handles it)
- Merge handleDisableSkill/handleEnableSkill into handleToggleSkill
- Fix locking: RLock for discovery, Lock only for file write
- Handle errors from AddPattern/RemovePattern in TUI toggle
- Only write oplog when changes actually occurred
- Inline capitalizeFirst with strings.ToUpper
2026-03-29 04:59:23 +08:00
Willie 14c2b9e97e feat(skillignore): add AddPattern/RemovePattern/HasPattern helpers
File-level write operations for .skillignore. Creates file if missing,
prevents duplicates, preserves comments and blank lines.
2026-03-29 04:59:23 +08:00
Willie 6b3858620f feat(skillignore): add .skillignore.local for local pattern overrides
Allow users to override shared .skillignore patterns without modifying
the committed file. ReadMatcher transparently merges .skillignore +
.skillignore.local (local appended last so !negation rules win).

- Matcher.HasLocal flag tracks .local presence for CLI reporting
- IgnoreStats gains RootLocalFile, RepoLocalFiles, HasLocal() method
- sync/status/doctor show ".local active" indicator
- 6 unit tests + 2 integration tests
- Docs: file-structure, sync, status, doctor, best-practices, creating-skills, org-sharing
2026-03-18 22:35:02 +08:00
Willie af143a3330 fix(doctor): add CLI text output for skillignore check
checkSkillignore only wrote to the JSON result but never printed
to the terminal, so skillignore status was invisible in CLI output.
2026-03-18 00:19:30 +08:00
Willie b2f5592cdb refactor(discovery): extract shared walk, add DiscoverSourceSkillsWithStats
Unify ~160 lines of duplicated walk logic from DiscoverSourceSkills and
DiscoverSourceSkillsLite into a single discoverSourceSkillsInternal
function controlled by discoverOptions (parseFrontmatter, collectIgnored,
collectTracked).

Add DiscoverSourceSkillsWithStats which returns IgnoreStats populated
with root/repo .skillignore file paths, active patterns, and ignored
skill relPaths. When collectIgnored is true, CanSkipDir is bypassed so
the file-level Match check can record every ignored SKILL.md path.

Add Patterns() method to skillignore.Matcher to expose the original
pattern strings stored during Compile().
2026-03-18 00:19:30 +08:00
Willie 2e9547a8de feat(skillignore): add IgnoreStats struct with Active/PatternCount/IgnoredCount 2026-03-18 00:19:30 +08:00
Willie 4214cb1038 feat(skillignore): upgrade to full gitignore-compatible syntax
Replace the naive string matcher (~40 lines) with a proper gitignore
implementation (~200 lines, no external deps) supporting **, ?, [abc],
!negation, /anchored, pattern/ (dir-only), and \#/\! escapes.

New Matcher API (Compile, ReadMatcher, Match, CanSkipDir, HasRules)
replaces the old Match/ReadPatterns functions (kept as deprecated
wrappers). Call sites in sync.go and install_discovery.go updated.
Also fixes isDir=true for install discovery (skill paths are dirs).

100% test coverage on skillignore package (~150 table-driven cases).
Added 7 sync discovery tests and 5 install integration tests covering
**, !negation, pattern/, [Tt] char class, and combined patterns.
2026-03-18 00:19:30 +08:00
Willie ad3b60067e fix(skillignore): strip trailing slash from patterns to fix directory matching
Patterns like "demo/" failed to match because Match() compared
"demo" == "demo/" (false) and HasPrefix("demo", "demo//") (false).
Now ReadPatterns strips trailing slashes at parse time.

Fixes #83
2026-03-18 00:19:30 +08:00
Willie 6e89577948 refactor(discovery): extract isSkillIgnored helper, unify tracked repo detection
- Extract duplicate .skillignore filtering block into isSkillIgnored()
- Use utils.IsTrackedRepoDir consistently in DiscoverSourceSkillsLite
- Fix unchecked os.WriteFile in skillignore test
2026-03-18 00:19:30 +08:00
Willie d925bf4e58 fix(discovery): respect .skillignore in source discovery (#83)
DiscoverSourceSkills and DiscoverSourceSkillsLite now load .skillignore
from tracked repos and skip matching paths during walk. This prevents
false warnings in doctor/status/list for vendored SKILL.md files
(e.g. .venv/ inside a tracked repo).

Extract shared skillignore package from internal/install so both
install-time and source discovery use the same filtering logic.
2026-03-18 00:19:30 +08:00