Commit Graph
15 Commits
Author SHA1 Message Date
Rusty ShacklefordandWillie 60e19f96d5 feat(project): support a visible skillshare/ project directory (#256) (#258)
* fix(project): refuse to re-init a project that lost its config.yaml

Every project-mode command auto-initializes when .skillshare/config.yaml
is missing. That is right for a repository with no project directory at
all, and for the shared skills repo produced by 'init -p --config local',
which gitignores config.yaml so each developer regenerates their own.

It was wrong for the case in between. A .skillshare/ that already held
skills or agents, whose config.yaml was simply gone, was re-initialized
into an empty config. Every configured target was dropped, the target
symlinks were left behind pointing at a project the config no longer
described, and the command exited 0. Nothing said anything had happened.

Add ensureProjectConfig, which replaces the open-coded auto-init at every
project command entry point. It initializes as before when there is no
project directory, and when config.yaml is gitignored, so both intentional
cases keep working untouched. When the directory holds skills or agents
and its config is neither present nor gitignored, it now returns an error
pointing at version control or an explicit 'skillshare init -p' instead of
writing over the project.

The gitignore check is treated as inconclusive on error, so a repository
that cannot be inspected is guarded rather than overwritten.

* feat(project): support a visible skillshare/ project directory

Project mode is identified only by .skillshare/config.yaml, and trash,
backups, logs and audit-rules.yaml anchor to that same hidden directory.
The sources option (#153) made project content relocatable, but the
marker and operational state stay hidden, so repositories that treat
skills as reviewable content still carry a hidden directory whose only
job is to hold config.yaml.

Resolve the project directory through a new leaf package that checks
.skillshare/config.yaml first and skillshare/config.yaml second, and
derive every config, state, source-default and gitignore path from the
result. The hidden name wins whenever both exist, so an existing project
never moves and no migration is needed. The package imports nothing else
internal because internal/audit cannot import internal/config without a
cycle.

Add init -p --visible to create the visible layout. Default init -p
behaviour and output are unchanged.

Two ambiguities the visible name introduces:

- The global config directory is also called skillshare
  (<config-home>/skillshare), so the two places that infer scope from a
  config path now exclude the global location by full path rather than
  by directory name. TestLogDir_Global asserted a fixture path without
  declaring a config home, which hid this; it now sets XDG_CONFIG_HOME.
- An unrelated directory named skillshare/ must not be adopted as a
  partially initialized project, so the visible name is only claimed
  when it carries a marker of its own: a skills/ or agents/ directory,
  or a .gitignore that ignores config.yaml.

The missing-config guard added in the previous commit is generalized to
resolve through the new package, so it covers both layouts. The
gitignored-config marker matters there too. A repository shared by
'init -p --visible --config local' before any skill was committed clones
with nothing but that .gitignore, because git drops the empty skills/
and agents/ directories; recognizing it keeps the repair pointed at the
visible directory instead of writing a hidden one beside it.

Refs #256

* fix(project): reconcile visible directory support with main

Consolidate the missing-config guard and regression tests already merged in #260. Preserve both directory layouts and document and test resyncing target links after a rename. Follow-up for #258.

---------

Co-authored-by: Willie <egg358358@gmail.com>
2026-09-05 12:07:00 +08:00
Willie 6e86537987 fix(audit): honor enabled:false for synthetic tier and cross-skill findings
Tier and cross-skill findings are generated programmatically rather than
compiled from the rule list, so they bypassed the disabled-ID filter applied
at rule-compile time. Setting enabled:false in audit-rules.yaml marked the
rule disabled in the listing but the scan still fired it at full severity.

Filter synthetic findings against the disabled-ID set in both the skill-scan
and single-file paths, threading the set through the cross-skill call sites
(analyzer, cmd, server). Fixes #204.
2026-06-05 20:51:32 +08:00
Willie 714d5f929d perf(audit): reduce regex scans with conservative prefilters
Add compile-time literal prefilters for audit rules using regexp AST analysis and apply prefilter gating before MatchString in hot scanning loops.

Changes:
- extend compiled rule with prefilter metadata (literal + case-fold flag)
- derive conservative must-match literals via regexp/syntax (fallback to LiteralPrefix)
- apply prefilter checks in unified scanners, legacy ScanContent paths, and markdown link rule checks
- add unit tests for prefilter extraction and case-fold matching

Verification:
- docker compose -f .devcontainer/docker-compose.yml exec -T --user "501:20" skillshare-devcontainer bash -lc 'cd /workspace && GOCACHE=/tmp/go-build go test ./internal/audit -count=1'
- docker compose -f .devcontainer/docker-compose.yml exec -T --user "501:20" skillshare-devcontainer bash -lc 'cd /workspace && GOCACHE=/tmp/go-build go build -o /tmp/skillshare ./cmd/skillshare && SKILLSHARE_TEST_BINARY=/tmp/skillshare GOCACHE=/tmp/go-build go test ./tests/integration -run TestAudit_ -count=1'
2026-03-03 16:08:11 +08:00
Willie 1b284e92b5 feat(audit): add semantic coloring to TUI summary footer
Labels use dim style while values use bold semantic colors, making
counts visually prominent. Threat category breakdown now colors each
category independently (injection=red, exfiltration=orange, etc.)
instead of uniform yellow, so users can distinguish threat types at
a glance.
2026-03-03 16:08:11 +08:00
Willie 1caba253c6 fix(audit): prevent severity-only merge from wiping rules and enable --pattern from ignoring ID-level disables
P1: mergeYAMLRules Phase 2 used full-object replacement for overlays
without Enabled set, causing severity-only entries ({id, severity}) to
wipe regex/pattern/message from the base rule. compileRules then failed
with "empty regex". Now uses field-level merge: only entries with Regex
do full replacement; otherwise Enabled and Severity are patched
individually.

P2: TogglePattern enable only removed pattern-level disable entries,
leaving ID-level {id: "x", enabled: false} untouched — both builtin
and custom rules. Now clearDisableForPattern matches by builtin ID set
OR by r.Pattern == pattern, covering custom rules in the same group.
2026-03-03 16:08:11 +08:00
Willie a97cf9e34e refactor(audit): simplify rules code, fix N+1 I/O, and extract shared helpers
- Remove duplicate readOrCreateRulesFile (use loadUserRules)
- Consolidate severity normalization with shorthand aliases (c/h/m/l/i)
- Merge enable/disable into shared cmdAuditRulesToggle
- Cache builtinYAML() with sync.Once to avoid repeated YAML parsing
- Cache rulesPath/patterns/sevCounts on TUI model, use SetItems over list.New
- Extract execMutation helper, remove dead expandAll/collapseAll/buildTitle
- Fix TestScanContent_InsecureHTTP test pollution via resetForTest()
- Add batch ToggleRules/SetSeverityBatch to eliminate N+1 file I/O
- Extract shared severity helpers to ui/src/lib/severity.ts
- Merge 9 filter() calls into single-pass useMemo in AuditRulesPage
- Add 7 tests for batch toggle and severity operations
2026-03-03 16:08:11 +08:00
Willie dbe759ecfe feat(audit): add CLI rules subcommand, severity override, reset, and redesign Web UI
- Add `audit rules` CLI subcommand with list, enable, disable, severity,
  and reset commands for managing audit rules without editing YAML
- Add SetSeverity/SetPatternSeverity/ResetRules mutations in audit package
- Redesign TUI with severity tabs, two-level pattern→rule navigation,
  inline severity picker (1-5 keys), and reset-all support
- Add compiled rules API endpoints (GET /api/audit/compiled, PATCH toggle)
- Redesign AuditRulesPage with severity-colored stripes, stat cards,
  expand/collapse, toggle switches, and dark-mode-aware CSS variables
- Redesign LogPage with status-colored row stripes, reusable PillButton,
  improved stats cards with left border stripes, default 10 entries/page
- Remove system-writes audit pattern (noisy, low value)
- Fix dark mode contrast across both pages by replacing hardcoded
  design.ts colors with var(--color-*) CSS variable references
2026-03-03 16:08:11 +08:00
Willie 0b3fc11fba feat(audit): add two-level TUI for audit rules browsing and toggling
Implement a full bubbletea TUI with two navigation levels:
- Level 1 (patterns): shows pattern categories with rule count, disabled
  count, and max severity; press Enter to drill in, d to toggle pattern
- Level 2 (rules): shows individual rules with severity and status; detail
  panel shows full ID, regex, message, source; d toggles single rule,
  D toggles entire pattern, Esc returns to Level 1

Also adds audit.ResetGlobalCache() to clear cached rules after YAML
mutations, enabling live-reload within the TUI session.
2026-03-03 16:08:11 +08:00
Willie beb4a1ef8d feat(audit): support pattern-level rules in audit-rules.yaml merge
Extend mergeYAMLRules to handle overlay entries that specify a pattern
but no id — these apply to all base rules sharing that pattern name.

Processing uses two phases:
  1. Pattern-level overlays (bulk disable / severity override)
  2. ID-level overlays (can override pattern-level, e.g. re-enable
     an individual rule after a pattern-level disable)

An explicit enabled:true in an id-level overlay clears a disabled flag
set by a pattern-level overlay.
2026-03-03 16:08:11 +08:00
Willie 885f072d16 feat(audit): add table-driven credential detection and 12 new security rules
Replace hardcoded credential-access YAML rules with a Go data table
(credentials.go) covering 30+ sensitive paths × 5 access methods, with
$HOME variant support, descriptive rule IDs, and an INFO-level heuristic
catch-all for unknown home dotdirs.

Add 12 new detection rules from security gap analysis:
- invisible-payload (CRITICAL): Unicode tag chars U+E0001–E007F
- prompt-injection-4 (CRITICAL): output suppression directives
- hidden-unicode-2 (HIGH): bidi control chars (Trojan Source)
- config-manipulation-0 (HIGH): AI config/memory file poisoning
- hidden-comment-injection-1 (HIGH): markdown reference-link injection
- data-exfiltration-3 (HIGH): DNS exfiltration via dig/nslookup
- self-propagation-0 (HIGH): repository worm instructions
- untrusted-install-0/1 (MEDIUM): npx -y, pip install from URL
- hidden-unicode-3 (MEDIUM): soft hyphens, directional marks

The invisible-payload pattern intentionally bypasses tutorial suppression
so CRITICAL findings are never silenced in educational contexts.
2026-03-03 16:08:11 +08:00
Willie cea26ea7fb feat: add dangling local markdown link detection to audit
Scan .md files in skill directories for broken relative links during
audit. Targets that don't exist on disk produce a LOW severity finding
(pattern: dangling-link). External URLs, anchors, and fragments are
skipped.

Integrated into the existing walk (zero extra IO) and disableable via
audit-rules.yaml (- id: dangling-link / enabled: false). The init-rules
template, built-in skill reference, and website docs are updated.
2026-02-21 21:12:51 +08:00
Willie 9ee5324689 feat: enhance security audit thresholds, logging, and UI 2026-02-13 14:21:36 +08:00
Willie 927bad707e feat: add audit rules Web UI page with create/edit support
Add REST API (GET/PUT/POST /api/audit/rules) for managing custom
audit-rules.yaml through the web dashboard. Extract template and
validation logic from CLI into reusable audit package functions
(ValidateRulesYAML, InitRulesFile, DefaultRulesTemplate). Frontend
provides CodeMirror YAML editor with dirty tracking, file creation
flow, and mode-aware path display. Sidebar nav gains overflow scroll.
2026-02-11 04:36:58 +08:00
Willie fbcec80788 feat: externalize audit rules to YAML with user customization
Move 17 hardcoded audit rules from Go structs to embedded rules.yaml,
enabling community PRs on rule definitions without recompilation.

Add user-customizable audit rules at two levels:
- Global: ~/.config/skillshare/audit-rules.yaml
- Project: .skillshare/audit-rules.yaml

Merge semantics: built-in → global → project. Users can append new
rules, override existing ones by id, or disable them (enabled: false).

Replace hardcoded localhostURL check with generic exclude regex field
on rules. Add --init-rules flag to scaffold a starter rules file.

Public API (ScanSkill, ScanContent, Finding, Result) unchanged —
callers require zero modifications.
2026-02-11 03:40:54 +08:00
Willie 4d17ff5d57 feat: add security audit — scan engine, CLI, install hooks, web UI, and docs
Scan skills for prompt injection, data exfiltration, credential access,
destructive commands, obfuscation, and suspicious URLs. CRITICAL findings
block installation by default; HIGH/MEDIUM shown as warnings.

- Scan engine: internal/audit with regex-based pattern matching
- CLI: `skillshare audit [name]` with per-skill progress and summary
- Install hooks: auto-scan after copy, block on CRITICAL unless --force
- Web UI: AuditPage with run/rescan, InstallForm shows ConfirmDialog
  for audit blocks (force-retry) and warning details
- ConfirmDialog: add `wide` prop, hide cancel when cancelText is empty
- Reduced false positives: rm -rf only flags root/glob, skip localhost
  URLs, exclude `fetch` as English word, hidden-unicode downgraded to HIGH
- README: add audit section, update screenshots, unify image sizes,
  add audit to Why/Comparison/Daily Commands
- Docs: audit command page, install security scanning section, FAQ,
  common errors, daily workflow, sidebar, landing page, intro
- Blog specs: add audit sections to Dev.to and Medium drafts
2026-02-10 01:53:55 +08:00