diff --git a/.github/workflows/learning-loop.yml b/.github/workflows/learning-loop.yml index 5366f58d..245dcfc4 100644 --- a/.github/workflows/learning-loop.yml +++ b/.github/workflows/learning-loop.yml @@ -40,14 +40,6 @@ jobs: echo "🧠 Generating rule proposals from observed patterns..." bash fleet-coordinator.sh generate-rules - - name: Upload rule proposals - if: always() - uses: actions/upload-artifact@v7.0.2 - with: - name: rule-proposals - path: shared-context/learning/rule-proposals/*.lgt - if-no-files-found: ignore - - name: Show learning summary run: | echo "## Learning Loop Summary" >> $GITHUB_STEP_SUMMARY @@ -59,19 +51,6 @@ jobs: echo "- No observations yet" >> $GITHUB_STEP_SUMMARY fi - if [ -d shared-context/learning/rule-proposals ]; then - PROPOSALS=$(find shared-context/learning/rule-proposals -name "*.lgt" | wc -l) - echo "- Rule proposals: $PROPOSALS" >> $GITHUB_STEP_SUMMARY - - if [ $PROPOSALS -gt 0 ]; then - echo "" >> $GITHUB_STEP_SUMMARY - echo "### Proposed Rules" >> $GITHUB_STEP_SUMMARY - for rule in shared-context/learning/rule-proposals/*.lgt; do - [ -f "$rule" ] && echo "- $(basename "$rule")" >> $GITHUB_STEP_SUMMARY - done - fi - fi - deploy-approved-rules: name: Deploy Approved Rules to Hypatia runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index ab5733ef..1ea4a3a6 100644 --- a/.gitignore +++ b/.gitignore @@ -154,7 +154,6 @@ pnpm-lock.yaml .editorconfig .env.* /exports/*.json -/exports/*.lgt /logs/ ai-cli-crash-capture/ composer/*.beam diff --git a/.machine_readable/descriptiles/NEUROSYM.a2ml b/.machine_readable/descriptiles/NEUROSYM.a2ml index f53641dc..a11b6a58 100644 --- a/.machine_readable/descriptiles/NEUROSYM.a2ml +++ b/.machine_readable/descriptiles/NEUROSYM.a2ml @@ -11,7 +11,6 @@ last-updated = "2026-04-11" [hypatia-config] scan-enabled = true scan-depth = "standard" # quick | standard | deep -report-format = "logtalk" [symbolic-rules] # Custom symbolic rules for this project diff --git a/audits/directive-census-2026-09-26/REPORT.md b/audits/directive-census-2026-09-26/REPORT.md index 2cda8ec4..ee61d4cb 100644 --- a/audits/directive-census-2026-09-26/REPORT.md +++ b/audits/directive-census-2026-09-26/REPORT.md @@ -64,9 +64,9 @@ Remote snapshots are pinned individually, not a simultaneous estate-wide snapsho ### 3. Hypatia's local instructions conflict with the fleet's old learning output -[Hypatia AGENTIC](https://github.com/hyperpolymath/hypatia/blob/9f2f62f5c9463c79b33a5ebf54372166ce56f349/.machine_readable/descriptiles/AGENTIC.a2ml) explicitly prohibits Logtalk, says rules are pure Elixir, and prohibits emitting JSON from its tooling. It requires evidence, reruns and behavioral tests, and declares automation rate/confidence constraints. +[Hypatia AGENTIC](https://github.com/hyperpolymath/hypatia/blob/9f2f62f5c9463c79b33a5ebf54372166ce56f349/.machine_readable/descriptiles/AGENTIC.a2ml) explicitly prohibits the retired rule language, says rules are pure Elixir, and prohibits emitting JSON from its tooling. It requires evidence, reruns and behavioral tests, and declares automation rate/confidence constraints. -The audited fleet coordinator still generates Logtalk `.lgt` proposals and has a publication path to Hypatia. Its local quarantine now blocks that route; the census did not deploy that block. +The audited fleet coordinator still generated rule-file proposals (the generator has since been removed) and had a publication path to Hypatia. Its local quarantine now blocks that route; the census did not deploy that block. The same AGENTIC file references retired `6a2` locations while acknowledging the newer `descriptiles` convention. **Do not automatically resolve this by deleting the local constraints or regenerating the file.** Separate the obsolete location reference from still-binding substantive prohibitions. diff --git a/audits/fleet-wiring-2026-09-26.md b/audits/fleet-wiring-2026-09-26.md index 3521c378..b89adb3b 100644 --- a/audits/fleet-wiring-2026-09-26.md +++ b/audits/fleet-wiring-2026-09-26.md @@ -89,7 +89,7 @@ No centralized repository-policy reconciliation across all these entry points wa `tests/e2e.sh` describes and primarily checks repository structure, shell syntax and required configuration. A passing β€œE2E Tests” run is not proof of dispatch β†’ bot execution β†’ changed target β†’ verification β†’ published check/PR. -The learning workflow explicitly disables `deploy-approved-rules`; the coordinator's generic generated Logtalk detector contains a TODO and an unconditional `fail`. Generated proposals are not necessarily functioning new detectors. +The learning workflow explicitly disables `deploy-approved-rules`; the coordinator's generic generated detector contained a TODO and an unconditional `fail`. Generated proposals are not necessarily functioning new detectors. ## Live GitHub observations and limits diff --git a/bots/finishingbot/ROADMAP.adoc b/bots/finishingbot/ROADMAP.adoc index 0f478ad9..7a8991a1 100644 --- a/bots/finishingbot/ROADMAP.adoc +++ b/bots/finishingbot/ROADMAP.adoc @@ -91,7 +91,7 @@ This roadmap outlines the development plan for finishing-bot, the release readin **Target:** 2026-Q3 === Hypatia Integration -* Logtalk rule-based validation +* Rule-based validation (Hypatia rules) * Formal verification of release criteria * Proof-carrying code validation * Rule synthesis from validation history diff --git a/bots/glambot/bot-integration/src/glambot_findings.lgt b/bots/glambot/bot-integration/src/glambot_findings.lgt deleted file mode 100644 index 178b95da..00000000 --- a/bots/glambot/bot-integration/src/glambot_findings.lgt +++ /dev/null @@ -1,148 +0,0 @@ -%% SPDX-License-Identifier: MPL-2.0 -%% Glambot findings bridge for the Hypatia neurosymbolic learning loop -%% -%% Transforms glambot presentation findings into Logtalk facts consumable -%% by the Hypatia rules engine, enabling pattern detection across repos. -%% -%% Finding categories: -%% presentation/visual - VIS-* (badges, formatting, layout) -%% presentation/accessibility - ACC-* (WCAG, ARIA, contrast) -%% presentation/seo - SEO-* (metadata, descriptions, topics) -%% presentation/machine-readability - MACH-* (structured data, schema.org) -%% presentation/git-seo - GS-* (repo topics, description, URL) - -:- object(glambot_findings, - implements(bot_integration)). - - :- info([ - version is 1:'0':'0', - author is 'glambot', - date is 2026-02-08, - comment is 'Glambot presentation findings bridge for Hypatia learning loop' - ]). - - %% ============================================================ - %% FINDING FACT GENERATION - %% ============================================================ - - %% glambot_finding(Repo, File, RuleId, Category, Severity, Fixable) - :- public(glambot_finding/6). - :- dynamic(glambot_finding/6). - - %% Parse JSON findings into Logtalk facts - :- public(ingest_findings/2). - ingest_findings(Repo, FindingsJson) :- - json_to_findings(FindingsJson, Findings), - forall( - member(Finding, Findings), - assert_finding(Repo, Finding) - ). - - assert_finding(Repo, Finding) :- - get_field(Finding, rule_id, RuleId), - get_field(Finding, file, File), - get_field(Finding, category, Category), - get_field(Finding, severity, Severity), - get_field(Finding, fixable, Fixable), - assertz(glambot_finding(Repo, File, RuleId, Category, Severity, Fixable)). - - %% ============================================================ - %% PATTERN DETECTION PREDICATES - %% ============================================================ - - %% Detect repos with recurring presentation issues - :- public(presentation_debt/2). - presentation_debt(Repo, Count) :- - findall(RuleId, glambot_finding(Repo, _, RuleId, _, _, _), Findings), - length(Findings, Count), - Count > 5. - - %% Detect cross-repo patterns (same rule firing in 3+ repos) - :- public(fleet_wide_pattern/2). - fleet_wide_pattern(RuleId, Repos) :- - findall(Repo, - glambot_finding(Repo, _, RuleId, _, _, _), - AllRepos), - sort(AllRepos, Repos), - length(Repos, N), - N >= 3. - - %% Detect unfixed fixable issues (low-hanging fruit) - :- public(low_hanging_fruit/3). - low_hanging_fruit(Repo, RuleId, File) :- - glambot_finding(Repo, File, RuleId, _, _, true). - - %% Accessibility regression detection - :- public(accessibility_regression/2). - accessibility_regression(Repo, Count) :- - findall(RuleId, - glambot_finding(Repo, _, RuleId, 'presentation/accessibility', error, _), - Findings), - length(Findings, Count), - Count > 0. - - %% SEO coverage gaps - :- public(seo_coverage_gap/2). - seo_coverage_gap(Repo, Missing) :- - findall(RuleId, - glambot_finding(Repo, _, RuleId, 'presentation/seo', _, _), - Findings), - length(Findings, Missing), - Missing > 0. - - %% ============================================================ - %% FLEET DISPATCH TRIGGERS - %% ============================================================ - - %% Generate sustainabot alert for repos with high presentation debt - :- public(sustainabot_alert/2). - sustainabot_alert(Repo, Alert) :- - presentation_debt(Repo, Count), - Count > 10, - format(atom(Alert), - 'Repo ~w has ~d presentation issues (high visual debt)', - [Repo, Count]). - - %% Generate finishbot trigger when glambot finds release blockers - :- public(finishbot_trigger/2). - finishbot_trigger(Repo, Trigger) :- - glambot_finding(Repo, _, RuleId, _, error, _), - format(atom(Trigger), - 'Glambot error ~w blocks release for ~w', - [RuleId, Repo]). - - %% ============================================================ - %% LEARNING LOOP FEEDBACK - %% ============================================================ - - %% Record fix outcome for learning engine - :- public(record_fix_outcome/4). - :- dynamic(fix_outcome/4). - record_fix_outcome(Repo, RuleId, Success, Timestamp) :- - assertz(fix_outcome(Repo, RuleId, Success, Timestamp)). - - %% Calculate fix success rate for a rule - :- public(fix_success_rate/2). - fix_success_rate(RuleId, Rate) :- - findall(1, fix_outcome(_, RuleId, true, _), Successes), - findall(1, fix_outcome(_, RuleId, _, _), All), - length(Successes, S), - length(All, A), - A > 0, - Rate is S / A. - - %% ============================================================ - %% HELPERS - %% ============================================================ - - %% Placeholder for JSON parsing (actual implementation via FFI) - json_to_findings(_, []) :- - write('JSON parsing requires FFI integration'), nl. - - get_field(Finding, Key, Value) :- - ( is_list(Finding) -> - member(Key=Value, Finding) - ; arg(Key, Finding, Value) - ). - -:- end_object. diff --git a/docs/BOT-OPERATIONS.adoc b/docs/BOT-OPERATIONS.adoc index 4fb8acc3..bd251809 100644 --- a/docs/BOT-OPERATIONS.adoc +++ b/docs/BOT-OPERATIONS.adoc @@ -72,7 +72,7 @@ coordination layer: |`+process-findings+` |Process `+findings//latest.json+`, dispatch auto-fixes, trigger learning -|`+generate-rules+` |Analyze pattern frequency, propose Logtalk rules at +|`+generate-rules+` |Analyze pattern frequency, (retired) rule proposals at threshold (5+ observations) |`+deploy-bots+` |Generate deployment status JSON @@ -84,7 +84,7 @@ threshold (5+ observations) .... Findings β†’ observed-patterns.jsonl β†’ threshold (5+) β†’ propose_new_rule() - β†’ Logtalk rule in learning/rule-proposals/ β†’ create_rule_approval_pr() + β†’ (retired: rule proposal and approval PR) β†’ Human reviews PR β†’ Approved rule deployed to hypatia .... @@ -366,7 +366,7 @@ license/placeholder - Integration tests |*Purpose* |Neurosymbolic CI/CD intelligence platform |*Repo* |`+hyperpolymath/hypatia+` |*Path* |`+$REPOS_DIR/hypatia/+` -|*Tech* |Rust + Haskell + Logtalk/Prolog + Ada/SPARK +|*Tech* |Rust + Haskell + Ada/SPARK |*Tier* |0 (Engine) |*Completion* |*70%* |*Dependencies* |None (coordinates everything) @@ -374,7 +374,7 @@ license/placeholder - Integration tests *Components*: - *CLI* (Rust) - 7 commands: scan, deposit, withdraw, search, batch, fleet, hooks - *Registry* (Haskell) - Type-safe ruleset -DSL, property-based testing - *Engine* (Logtalk) - Declarative rule +DSL, property-based testing - *Engine* - Declarative rule execution, distillation - *Adapters* (Rust) - GitHub, GitLab, Bitbucket, Codeberg (SourceHut/Radicle pending) - *Data* (Rust) - ArangoDB graph DB, Dragonfly cache - *Fixer* (Rust) - Error catalog parser, issue @@ -461,7 +461,7 @@ git-dispatcher (Central Coordination Hub) β”‚ └── shared-context (Rust coordination library) β”‚ β”œβ”€β”€ hypatia (Rules Engine, Engine tier) - β”‚ β”œβ”€β”€ Logtalk rules (symbolic reasoning) + β”‚ β”œβ”€β”€ Elixir rules (symbolic reasoning) β”‚ β”œβ”€β”€ Haskell registry (type-safe verification) β”‚ └── ArangoDB + Dragonfly (graph DB + cache) β”‚ diff --git a/docs/archive/DOGFOODING-ANALYSIS.adoc b/docs/archive/DOGFOODING-ANALYSIS.adoc index de0f0e37..9aa684dc 100644 --- a/docs/archive/DOGFOODING-ANALYSIS.adoc +++ b/docs/archive/DOGFOODING-ANALYSIS.adoc @@ -52,7 +52,7 @@ public for transparency 3. Publish findings after patches deployed |=== |Repo |Language |Unsafe Patterns Found |Severity |Can Self-Fix? |*hypatia* |Rust |27 unwrap calls |Medium |βœ… YES -|*gitbot-fleet* |Shell/Logtalk |3 getExn, 3 Obj.magic |Low |βœ… YES +|*gitbot-fleet* |Shell |3 getExn, 3 Obj.magic |Low |βœ… YES |*rhodibot* |Rust |0 issues |None |βœ… CLEAN |*echidnabot* |Rust |6 unwrap calls |Medium |βœ… YES |*glambot* |Rust |1 unwrap call |Low |βœ… YES @@ -88,9 +88,6 @@ review before merging * [ ] *Add hypatia self-scan to CI/CD* ** Workflow: `+.github/workflows/hypatia-self-scan.yml+` ** Block merges if critical issues found -* [ ] *Document all Logtalk predicates* -** Many predicates in `+engine/scanner.lgt+` lack comments -** Add usage examples for each rule in `+code-safety-lessons.lgt+` * [ ] *Test suite for learning engine* ** Test observation thresholds (5 for proposal, 10 for auto-approve) ** Test fix outcome tracking @@ -101,9 +98,6 @@ review before merging * [ ] *Create proper Rust library crate* ** Current structure mixes CLI, adapters, fixer, scanner ** Separate: `+hypatia-core+`, `+hypatia-cli+`, `+hypatia-adapters+` -* [ ] *Add SWI-Prolog installation to CI* -** Currently using bash POC scanner -** Full Logtalk validation requires SWI-Prolog * [ ] *Implement rule versioning* ** Track which hypatia version generated each rule ** Support rule deprecation and migration diff --git a/docs/archive/NEW-PATTERNS-DEPLOYMENT-2026-02-06.adoc b/docs/archive/NEW-PATTERNS-DEPLOYMENT-2026-02-06.adoc index 3ad3a369..8d70cc91 100644 --- a/docs/archive/NEW-PATTERNS-DEPLOYMENT-2026-02-06.adoc +++ b/docs/archive/NEW-PATTERNS-DEPLOYMENT-2026-02-06.adoc @@ -137,7 +137,7 @@ reached for new patterns ==== Immediate (Ready Now) [arabic] -. βœ… Generate Logtalk rule proposals for 3 new patterns +. βœ… Generate rule proposals for 3 new patterns . βœ… Submit for ECHIDNA validation . βœ… Human review and approval diff --git a/fleet-coordinator.sh b/fleet-coordinator.sh index c46742ec..c34a578a 100755 --- a/fleet-coordinator.sh +++ b/fleet-coordinator.sh @@ -36,11 +36,11 @@ COMMANDS: run-scan Run full scan on repository scan-supervised Run hypatia scan across supervised repos inventory process-findings Process pending findings and coordinate fixes - generate-rules Generate new rules from observed patterns + generate-rules Retired: rule proposals are no longer generated (always blocked) status Show fleet status deploy-bots Deploy all bots to their positions -BOT EXECUTION ORDER (from bot_integration.lgt): +BOT EXECUTION ORDER: 1. rhodibot (Verifier - structure, policy, licensing) 2. echidnabot (Verifier - verification, fuzzing) 3. sustainabot (Verifier - sustainability) @@ -446,299 +446,15 @@ learn_from_findings() { jq -r '.findings[] | select(.severity == "critical" or .severity == "high") | "\(.type)|\(.location.file // "unknown")|\(.id)"' "$findings_file" | while IFS='|' read -r type file finding_id; do - # Record pattern observation (feeds learning_engine.lgt) + # Record pattern observation # Use jq to safely construct JSON (prevents injection via type/file/repo_name) jq -n --arg type "$type" --arg file "$file" --arg repo "$repo_name" \ --arg observed "$(date -Iseconds)" \ '{type: $type, file: $file, repo: $repo, observed: $observed}' \ >> "$SHARED_CONTEXT/learning/observed-patterns.jsonl" - - # Check if we should generate new rule - local pattern_count=$(grep -c "\"$type\"" "$SHARED_CONTEXT/learning/observed-patterns.jsonl" 2>/dev/null || echo 0) - - if [[ $pattern_count -ge 5 ]]; then - log_bot "hypatia" " β†’ Pattern threshold reached for '$type' ($pattern_count observations)" - - # Generate rule proposal - propose_new_rule "$type" "$file" "$pattern_count" - fi done } -propose_new_rule() { - local type="$1" - local pattern="$2" - local observations="$3" - - mkdir -p "$SHARED_CONTEXT/learning/rule-proposals" - - # Sanitize filename - local safe_type="${type//[^a-zA-Z0-9_]/_}" - local proposal_file="$SHARED_CONTEXT/learning/rule-proposals/${safe_type}.lgt" - - if [[ -f "$proposal_file" ]]; then - log_bot "hypatia" " Rule proposal already exists: $safe_type" - return 0 - fi - - # Generate context-aware Logtalk rule based on issue type - case "$type" in - unpinned_action) - cat > "$proposal_file" << 'RULE_EOF' -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect unpinned GitHub Actions -% Generated: $(date -Iseconds) -% Observations: $observations across $repos repos - -:- object(unpinned_action_detector, - extends(code_pattern_detector)). - - % Detect uses: action@version (not SHA) - has_workflow_issue(Path, unpinned_action(Action, Line)) :- - workflow_file(Path), - read_file_line(Path, LineNum, Line), - atom_contains(Line, 'uses:'), - extract_action_ref(Line, Action, Ref), - \+ is_sha_pinned(Ref). - - extract_action_ref(Line, Action, Ref) :- - sub_atom(Line, AfterUses, _, 0, Rest), - atom_concat('uses:', Rest, Line), - split_string(Rest, "@", " \t", [ActionStr, RefStr]), - atom_string(Action, ActionStr), - atom_string(Ref, RefStr). - - is_sha_pinned(Ref) :- - atom_length(Ref, 40), % SHA is 40 characters - atom_codes(Ref, Codes), - forall(member(C, Codes), is_hex_digit(C)). - - is_hex_digit(C) :- - (C >= 0'0, C =< 0'9) ; (C >= 0'a, C =< 0'f'). - - classify_severity(unpinned_action(_, _), high). - - suggest_fix(unpinned_action(Action, _), Fix) :- - format(atom(Fix), 'Pin ~w to SHA for supply chain security', [Action]). - - auto_fixable(unpinned_action(_, _), true). - - fix_script(unpinned_action(_, _), 'scripts/fix-unpinned-actions.sh'). - -:- end_object. -RULE_EOF - ;; - - missing_permissions) - cat > "$proposal_file" << 'RULE_EOF' -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect missing permissions declarations -% Generated: $(date -Iseconds) -% Observations: $observations across $repos repos - -:- object(missing_permissions_detector, - extends(code_pattern_detector)). - - has_workflow_issue(Path, missing_permissions(Line)) :- - workflow_file(Path), - \+ has_permissions_declaration(Path). - - has_permissions_declaration(Path) :- - read_file_line(Path, _, Line), - atom_contains(Line, 'permissions:'). - - classify_severity(missing_permissions(_), medium). - - suggest_fix(missing_permissions(_), - 'Add permissions: read-all at workflow level'). - - auto_fixable(missing_permissions(_), true). - - fix_script(missing_permissions(_), 'scripts/fix-workflow-permissions.sh'). - -:- end_object. -RULE_EOF - ;; - - missing_spdx) - cat > "$proposal_file" << 'RULE_EOF' -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect missing SPDX headers -% Generated: $(date -Iseconds) -% Observations: $observations across $repos repos - -:- object(missing_spdx_detector, - extends(code_pattern_detector)). - - has_file_issue(Path, missing_spdx(FileType)) :- - source_file(Path), - file_type(Path, FileType), - \+ has_spdx_header(Path). - - has_spdx_header(Path) :- - read_file_lines(Path, 3, Lines), - member(Line, Lines), - atom_contains(Line, 'SPDX-License-Identifier'). - - file_type(Path, 'workflow') :- atom_contains(Path, '.github/workflows/'). - file_type(Path, 'script') :- atom_contains(Path, '.sh'). - file_type(Path, 'source') :- true. - - classify_severity(missing_spdx(_), low). - - suggest_fix(missing_spdx(FileType), Fix) :- - format(atom(Fix), 'Add SPDX header to ~w file', [FileType]). - - auto_fixable(missing_spdx(_), true). - - fix_script(missing_spdx(_), 'scripts/fix-missing-spdx.sh'). - -:- end_object. -RULE_EOF - ;; - - *) - # Generic rule template for unknown types - cat > "$proposal_file" << EOF -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect ${type} issues -% Generated: $(date -Iseconds) -% Observations: $observations - -:- object(${safe_type}_detector, - extends(code_pattern_detector)). - - % TODO: Implement detection logic for ${type} - has_issue(Path, ${safe_type}(Location)) :- - source_file(Path), - % Add specific detection logic here - fail. % Replace with actual implementation - - classify_severity(${safe_type}(_), medium). - - suggest_fix(${safe_type}(_), 'Manual review required for ${type}'). - - auto_fixable(${safe_type}(_), false). - -:- end_object. -EOF - ;; - esac - - log_bot "hypatia" " βœ“ Rule proposal created: $proposal_file" - log_info " Review at: $proposal_file" - - # Create approval PR if in CI environment - if [[ -n "${GITHUB_ACTIONS:-}" ]]; then - create_rule_approval_pr "$proposal_file" "$type" "$observations" - fi -} - -create_rule_approval_pr() ( - local rule_file="$1" - local rule_type="$2" - local observations="$3" - - log_bot "hypatia" "Creating rule approval PR for $rule_type..." - - # Clone hypatia repo to temp directory - local hypatia_dir - hypatia_dir="$(mktemp -d)" - trap 'rm -rf "$hypatia_dir"' EXIT - git clone https://github.com/hyperpolymath/hypatia.git "$hypatia_dir" 2>/dev/null - - cd "$hypatia_dir" - - # Create branch for rule - local branch_name="auto-rule/${rule_type}-$(date +%Y%m%d)" - git checkout -b "$branch_name" - - # Copy rule to hypatia's rules directory - local target_dir="engine/rules/auto-learned" - mkdir -p "$target_dir" - cp "$rule_file" "$target_dir/$(basename "$rule_file")" - - # Commit and push - git add "$target_dir" - git config user.name "Hypatia Learning Engine" - git config user.email "hypatia@reposystem.dev" - - git commit -m "$(cat < -COMMIT_EOF -)" - - git push origin "$branch_name" 2>/dev/null || { - log_warn "Failed to push rule PR branch" - cd - > /dev/null - return 1 - } - - # Create PR using gh CLI if available - if command -v gh &> /dev/null; then - gh pr create \ - --title "Auto-learned rule: ${rule_type}" \ - --body "$(cat </dev/null && { - log_bot "hypatia" " βœ“ Rule approval PR created" - # Enable auto-merge β€” PR merges automatically when CI passes - gh pr merge --auto --squash --repo hyperpolymath/hypatia 2>/dev/null && { - log_bot "hypatia" " βœ“ Auto-merge enabled (squash on CI pass)" - } || { - log_bot "hypatia" " ⚠ Auto-merge not available (repo setting may be off)" - } - } - fi - - cd - > /dev/null -) - deploy_bots() { log_error "BLOCKED: deployment readiness is not verified; deployment is quarantined. See docs/AUTOMATION-QUARANTINE.adoc." return 78 @@ -773,59 +489,9 @@ EOF } generate_rules() { - # This path can publish rule PRs and enable auto-merge in CI. + # Rule generation and publication are retired; the command stays blocked. log_error "BLOCKED: repository directive enforcement is not qualified; rule generation/publication is quarantined. See docs/AUTOMATION-QUARANTINE.adoc." return 78 - - log_info "Analyzing observed patterns for rule generation..." - - local patterns_file="$SHARED_CONTEXT/learning/observed-patterns.jsonl" - - if [[ ! -f "$patterns_file" ]]; then - log_info "No observed patterns yet" - return 0 - fi - - # Analyze pattern frequency - log_info "Pattern frequency analysis:" - - # Group by type and count occurrences - local pattern_types=$(jq -r '.type' "$patterns_file" | sort | uniq) - - for pattern_type in $pattern_types; do - local count=$(grep "\"$pattern_type\"" "$patterns_file" | wc -l) - - log_info " ${pattern_type}: $count observations" - - # Threshold for rule generation (configurable) - local threshold="${RULE_THRESHOLD:-5}" - - if [[ $count -ge $threshold ]]; then - log_bot "hypatia" " β†’ Threshold reached for '$pattern_type' ($count >= $threshold)" - - # Extract unique repos that observed this pattern - local repos=$(grep "\"$pattern_type\"" "$patterns_file" | jq -r '.repo' | sort -u | wc -l) - - # Generate rule proposal - propose_new_rule "$pattern_type" "$pattern_type" "$count ($repos repos)" - fi - done - - # Summary - local total_patterns=$(wc -l < "$patterns_file") - local unique_types=$(echo "$pattern_types" | wc -l) - local proposals=$(find "$SHARED_CONTEXT/learning/rule-proposals" -name "*.lgt" 2>/dev/null | wc -l) - - log_info "" - log_info "Learning Summary:" - log_info " Total observations: $total_patterns" - log_info " Unique pattern types: $unique_types" - log_info " Rule proposals generated: $proposals" - - if [[ $proposals -gt 0 ]]; then - log_info "" - log_info "Review rule proposals at: $SHARED_CONTEXT/learning/rule-proposals/" - fi } show_status() { diff --git a/learning-monitor.sh b/learning-monitor.sh index e292cdc9..760aebd1 100755 --- a/learning-monitor.sh +++ b/learning-monitor.sh @@ -42,34 +42,6 @@ else echo -e " ${RED}No observations yet${NC}" fi -echo "" -echo -e "${CYAN}🧠 Rule Proposals${NC}" -if [[ -d "$LEARNING_DIR/rule-proposals" ]]; then - proposal_count=$(find "$LEARNING_DIR/rule-proposals" -name "*.lgt" 2>/dev/null | wc -l) - echo -e " Total proposals: ${GREEN}$proposal_count${NC}" - - if [[ $proposal_count -gt 0 ]]; then - echo "" - echo -e " ${YELLOW}Generated rules:${NC}" - for rule in "$LEARNING_DIR/rule-proposals"/*.lgt; do - rule_name=$(basename "$rule" .lgt) - observations=$(grep "% Observations:" "$rule" | awk '{print $3}') - generated=$(grep "% Generated:" "$rule" | cut -d' ' -f3-) - - # Check if rule is approved (moved to hypatia engine) - if [[ -f "$FLEET_DIR/../hypatia/engine/rules/auto-learned/$(basename "$rule")" ]]; then - status="${GREEN}βœ“ APPROVED${NC}" - else - status="${YELLOW}⏳ PENDING${NC}" - fi - - printf " %-30s %s observations %b\n" "$rule_name" "$observations" "$status" - done - fi -else - echo -e " ${RED}No proposals yet${NC}" -fi - echo "" echo -e "${CYAN}πŸ”§ Auto-Fix Outcomes${NC}" if [[ -f "$LEARNING_DIR/fix-outcomes.jsonl" ]]; then @@ -132,16 +104,4 @@ if [[ $unprocessed -gt 0 ]]; then echo -e " β€’ Process $unprocessed pending findings: ${YELLOW}./fleet-coordinator.sh process-findings${NC}" fi -if [[ -f "$LEARNING_DIR/observed-patterns.jsonl" ]]; then - patterns_ready=$(jq -r '.type' "$LEARNING_DIR/observed-patterns.jsonl" | \ - sort | uniq -c | awk '$1 >= 5 {print $2}' | wc -l) - if [[ $patterns_ready -gt 0 ]]; then - echo -e " β€’ Generate rules for $patterns_ready patterns: ${YELLOW}./fleet-coordinator.sh generate-rules${NC}" - fi -fi - -if [[ -d "$LEARNING_DIR/rule-proposals" ]] && [[ $proposal_count -gt 0 ]]; then - echo -e " β€’ Review rule proposals in: ${CYAN}$LEARNING_DIR/rule-proposals/${NC}" -fi - echo "" diff --git a/robot-repo-automaton/.machine_readable/6a2/NEUROSYM.a2ml b/robot-repo-automaton/.machine_readable/6a2/NEUROSYM.a2ml index f53641dc..a11b6a58 100644 --- a/robot-repo-automaton/.machine_readable/6a2/NEUROSYM.a2ml +++ b/robot-repo-automaton/.machine_readable/6a2/NEUROSYM.a2ml @@ -11,7 +11,6 @@ last-updated = "2026-04-11" [hypatia-config] scan-enabled = true scan-depth = "standard" # quick | standard | deep -report-format = "logtalk" [symbolic-rules] # Custom symbolic rules for this project diff --git a/robot-repo-automaton/templates/skeleton/.machine_readable/descriptiles/NEUROSYM.a2ml b/robot-repo-automaton/templates/skeleton/.machine_readable/descriptiles/NEUROSYM.a2ml index 1acf7a30..47121f5d 100644 --- a/robot-repo-automaton/templates/skeleton/.machine_readable/descriptiles/NEUROSYM.a2ml +++ b/robot-repo-automaton/templates/skeleton/.machine_readable/descriptiles/NEUROSYM.a2ml @@ -11,7 +11,6 @@ last-updated = "2026-04-11" [hypatia-config] scan-enabled = true scan-depth = "standard" # quick | standard | deep -report-format = "logtalk" [symbolic-rules] # Custom symbolic rules for this project diff --git a/shared-context/findings/security-audit-20260125.md b/shared-context/findings/security-audit-20260125.md index 46db4527..bed56378 100644 --- a/shared-context/findings/security-audit-20260125.md +++ b/shared-context/findings/security-audit-20260125.md @@ -22,7 +22,7 @@ User question: "why do the svalinn, vordr, cerro-torre, selur, and verified-cont 3. No CI/CD integration running scans **Fixed in this session:** -- βœ… Implemented actual scanning logic in `hypatia/engine/scanner.lgt` +- βœ… Implemented actual scanning logic in the Hypatia scanner - βœ… Created execution layer `gitbot-fleet/fleet-coordinator.sh` - βœ… Added autonomous learning system to auto-generate rules - βœ… Fixed all critical production code issues @@ -110,7 +110,7 @@ These are acceptable per security policy. 1. **getexn_on_external_data** (unsafe_crash) - Observations: 9 - Status: Auto-generated rule proposal βœ… - - File: `shared-context/learning/rule-proposals/getexn_on_external_data.lgt` + - File: (rule proposal file, since removed) 2. **obj_magic_bypass** (type_safety_bypass) - Observations: 5 @@ -160,7 +160,7 @@ Success rate: 100% (9/9 attempted fixes succeeded) ### Immediate 1. βœ… Deploy hypatia-scan.yml to all repos 2. βœ… Add pre-commit hooks to block unsafe patterns -3. Review auto-generated rule proposal: `getexn_on_external_data.lgt` +3. Review auto-generated rule proposal: `getexn_on_external_data` ### Short-term 1. Monitor learning engine for new pattern proposals @@ -168,9 +168,8 @@ Success rate: 100% (9/9 attempted fixes succeeded) 3. Consider adding fuzzing to vordr (critical runtime) ### Long-term -1. Install SWI-Prolog for full Logtalk rule validation -2. Extend patterns to cover more languages (Python, Go if any remain) -3. Integrate learning feedback from production telemetry +1. Extend patterns to cover more languages (Python, Go if any remain) +2. Integrate learning feedback from production telemetry --- diff --git a/shared-context/learning/ECHIDNA-VALIDATION-SUMMARY.adoc b/shared-context/learning/ECHIDNA-VALIDATION-SUMMARY.adoc index 3ddf8e1e..85a27a2d 100644 --- a/shared-context/learning/ECHIDNA-VALIDATION-SUMMARY.adoc +++ b/shared-context/learning/ECHIDNA-VALIDATION-SUMMARY.adoc @@ -14,7 +14,7 @@ Framework v1.0 *Rules Validated:* 3 ==== 1. Structural Validation βœ… -* All rules have valid Logtalk syntax +* All rules have valid syntax * SPDX headers present * Objects properly declared and closed * Info metadata included diff --git a/shared-context/learning/RETIRED-LOGTALK-RULES.adoc b/shared-context/learning/RETIRED-LOGTALK-RULES.adoc new file mode 100644 index 00000000..d41e5711 --- /dev/null +++ b/shared-context/learning/RETIRED-LOGTALK-RULES.adoc @@ -0,0 +1,160 @@ +// SPDX-License-Identifier: CC-BY-SA-4.0 += Retired learning-loop rules: what they detected and where that went +:toc: + +== Status + +The rule files of the learning loop were written in a rule language that the +estate has retired. They were removed in the change that added this record. +Hypatia's rule system is pure Elixir (`lib/rules/*.ex` in +`hyperpolymath/hypatia`), so no rule here was ported as a new rule file; this +record states, for each one, what it matched and which Hypatia rule covers it +today. It is a record, not a source of rules: do not translate it back into a +rule file. + +The removed files are recoverable from git history. Last commit that carried +them: `dec1e7ce36dfa62ea121b530108de04cc8321e69` (gitbot-fleet `main`). +Hypatia coverage was read from Hypatia `main` at `6f3f16f` on 2026-11-17 by +reading `lib/rules/code_safety.ex`, `lib/rules/cicd_rules.ex` and +`lib/rules/honest_completion.ex`. No rule was run to check it. + +Nothing consumed these files except the generator and report code removed in +the same change. The only publication path (opening rule PRs in Hypatia and +enabling auto-merge) sat behind the quarantine in +`docs/AUTOMATION-QUARANTINE.adoc`, and the workflow job that would have +deployed approved rules (`deploy-approved-rules`) is disabled with `if: false`. + +== Approved rules (three) + +All three were approved on 2026-02-06 with a validation score of 92% and +recorded in `rule-deployment-status.json`. Each carried the same detector +shape: a `has_issue` check, a severity, a fix suggestion and an +`auto_fixable` flag set to false. + +[cols="1,3,3",options="header"] +|=== +|Rule (object name) |What it matched and flagged |Hypatia coverage + +|`eval_usage` (`eval_usage_detector`); 7 observations; CWE-95 +|In `.js`, `.jsx`, `.res`, `.mjs` and `.cjs` files, outside `//` comments and +double-quoted strings: a call to `eval(`; `Function(` or `new Function(`; and +`setTimeout(` or `setInterval(` with a double-quoted string argument. +Severity critical in production code, high in test code (paths with `/test/`, +`/tests/`, `/__tests__/`, `.test.js`, `.spec.js`); tool paths (`/scripts/`, +`/tools/`, `/build/`, `webpack.config`, `rollup.config`) did not count as +production. Also suggested a Content-Security-Policy header +(`script-src 'self'; object-src 'none'`) when no CSP protection was found. +|*Partial.* `js_eval` in `lib/rules/code_safety.ex` (critical, CWE-94, pattern +`\beval\s*\(`) covers direct `eval(`. *No Hypatia rule* covers the `Function` +constructor or string arguments to `setTimeout`/`setInterval`, the +test/production severity split, or the CSP recommendation. + +|`technical_debt` (`technical_debt_detector`); 196 observations; CWE-1057 +|In any source file, the markers `TODO:`, `FIXME:`, `HACK:`, `XXX:` and `BUG:` +with the text after the marker. Severity info. Triage priority by marker: BUG +critical, FIXME high, HACK medium, TODO and XXX low. A repository with more +than 50 markers was flagged as excessive debt. The suggested fix was to open a +GitHub issue carrying the priority and message. +|*Partial.* `lib/rules/honest_completion.ex` counts `TODO` and `FIXME` +repository-wide and reports when TODOs exceed 50 or FIXMEs exceed 20. +`baseline_health.ex` BH002 flags a deferred-migration TODO in a manifest. *No +Hypatia rule* matches `HACK:`, `XXX:` or `BUG:`, emits a finding per marker, +or assigns the per-marker priority. + +|`unsafe_without_doc` (`unsafe_without_doc_detector`); 19 observations; +CWE-1188 +|In `.rs` files, an `unsafe` token followed by `{` on the same line, with no +safety comment one or two lines above. A safety comment was a `//` line +containing `SAFETY:`, `Safety:`, `safe because`, `invariant`, `guarantee`, +`rationale` or `reason` (or their capitalised forms). Severity high, critical +in production code (not under `/test/`, `/tests/`, or `_test.rs`). Suggested +adding a `// SAFETY:` comment. +|*Covered.* `unsafe_block` in `lib/rules/code_safety.ex` (medium, CWE-676, +pattern `unsafe\s*\{`) with `reject_excused_unsafe`, which drops a match that +has a `SAFETY:` comment directly above it or sits inside a string. Differences: +Hypatia's severity is medium with no production escalation, and it accepts only +a `SAFETY:` comment, not the looser keywords the retired rule accepted. +|=== + +The approval metadata beside each approved rule (`status: approved`, +`approved_by: ECHIDNA Semantic Validation v1.0`, `validation_score: 92%`, +`production_ready: true`, with the observation count and the dates +2026-02-06) was removed with it. The same facts are in +`rule-deployment-status.json`, which is kept. + +== Proposals that were never approved (seven files, four distinct rules) + +* `eval_usage`, `technical_debt` and `unsafe_without_doc`: byte-identical to the + approved rules above. +* `getexn_on_external_data` (6 observations, 2026-01-25): a draft that matched a + line containing the literal text `getexn_on_external_data` and rated it high. + It was malformed (a bare `LineNum` goal) and carried a TODO to merge it into a + rule file that is not in this repository. The intent, ReScript `getExn` on + external data, is covered by `getexn_on_external` in + `lib/rules/code_safety.ex` (critical, CWE-754, pattern `getExn`). +* `type_safety_bypass` (5 observations), `unsafe_crash` (8) and `unsafe_panic` + (15): generic stubs generated 2026-02-06. Each had a detection clause that + ended in `fail`, so none could ever report anything, plus a medium severity + and a "manual review required" suggestion. *There is no detection content to + port.* They record only that these three pattern types were observed. + +`rule-deployment-status.json` lists `unsafe_panic`, `type_safety_bypass`, +`unsafe_crash` and `cors_misconfiguration` as approved with quality `template` +or `auto-fix`. The first three are the stubs above. No rule file for +`cors_misconfiguration` existed in the tree. + +== Rule templates in the generator + +`fleet-coordinator.sh` wrote one of four templates for a pattern type seen five +or more times. The generator has been removed (its entry point stays blocked). + +[cols="1,3,3",options="header"] +|=== +|Template |What it matched |Hypatia coverage + +|`unpinned_action` +|A workflow `uses:` line whose reference is not a 40-character hex SHA. High +severity, auto-fixable by `scripts/fix-unpinned-actions.sh`. +|*Covered.* `unpinned_action` in `lib/rules/cicd_rules.ex`, whose canonical +detection is WH004 in `lib/rules/workflow_hardening.ex`. + +|`missing_permissions` +|A workflow with no `permissions:` line. Medium, auto-fixable by +`scripts/fix-workflow-permissions.sh`. +|*Covered.* `missing_permissions` in `lib/rules/cicd_rules.ex`. + +|`missing_spdx` +|A source file with no `SPDX-License-Identifier` in its first three lines. Low, +auto-fixable by `scripts/fix-missing-spdx.sh`. Licence and SPDX findings are +flag-only estate-wide, so the auto-fixable flag does not stand. +|*Covered.* `missing_spdx` in `lib/rules/cicd_rules.ex`. + +|Any other type +|A stub with a detection clause ending in `fail`. +|Nothing to port. +|=== + +== Glambot findings bridge + +The glambot findings bridge (`bots/glambot/bot-integration/src/glambot_findings`, removed; +nothing loaded it) was a design for turning glambot presentation findings into +facts. Its JSON ingestion was a placeholder that printed "JSON parsing requires +FFI integration" and returned no findings, so it never ran against real data. +Finding categories: visual (`VIS-*`), accessibility (`ACC-*`), SEO (`SEO-*`), +machine-readability (`MACH-*`) and git-SEO (`GS-*`). + +Its derived checks, none of which has a Hypatia rule: + +* presentation debt: a repository with more than 5 findings; a sustainabot + alert when it has more than 10; +* fleet-wide pattern: the same rule id firing in 3 or more repositories; +* low-hanging fruit: findings marked fixable; +* accessibility regression: any accessibility finding of severity error; +* SEO coverage gap: any SEO finding; +* finishbot trigger: any glambot finding of severity error, "blocks release"; +* fix success rate per rule id: successes divided by recorded outcomes. + +Hypatia has no glambot or presentation rule (a search of `lib/` for +`glambot`, `presentation` and `accessib` found none in `lib/rules/`). +glambot's own findings still reach the fleet through the Rust +`shared-context` library; only this aggregation layer is retired. diff --git a/shared-context/learning/RULE-PROPOSALS-2026-02-06.adoc b/shared-context/learning/RULE-PROPOSALS-2026-02-06.adoc index 1f8f7ce7..e2f2baee 100644 --- a/shared-context/learning/RULE-PROPOSALS-2026-02-06.adoc +++ b/shared-context/learning/RULE-PROPOSALS-2026-02-06.adoc @@ -2,14 +2,14 @@ === Summary -Generated 3 Logtalk rule proposals from patterns that crossed the +Generated 3 rule proposals from patterns that crossed the 5-observation threshold during fleet deployment. === Proposed Rules ==== 1. technical_debt_detector -* *File:* `+rule-proposals/technical_debt.lgt+` +* *Rule:* `+technical_debt+` (proposal file since removed) * *Observations:* 196 (39x threshold) * *Severity:* INFO * *CWE:* CWE-1057 @@ -33,7 +33,7 @@ accumulation. Not a bug, but essential for maintenance planning. ==== 2. unsafe_without_doc_detector -* *File:* `+rule-proposals/unsafe_without_doc.lgt+` +* *Rule:* `+unsafe_without_doc+` (proposal file since removed) * *Observations:* 19 (3.8x threshold) * *Severity:* HIGH (CRITICAL in production) * *CWE:* CWE-1188 @@ -59,7 +59,7 @@ Critical for Rust’s safety guarantees. ==== 3. eval_usage_detector -* *File:* `+rule-proposals/eval_usage.lgt+` +* *Rule:* `+eval_usage+` (proposal file since removed) * *Observations:* 7 (1.4x threshold) * *Severity:* CRITICAL * *CWE:* CWE-95 (Code Injection) @@ -93,7 +93,7 @@ Metadata for tracking and auditing ==== Validation Status -*Static Analysis:* βœ… PASS - Valid Logtalk syntax - Extends +*Static Analysis:* βœ… PASS - Valid syntax - Extends code_pattern_detector protocol - Implements required predicates - SPDX headers present @@ -166,7 +166,7 @@ format) ==== Phase 1: Validation (Current) -* [x] Generate Logtalk rule proposals +* [x] Generate rule proposals * [ ] Run ECHIDNA semantic validation * [ ] Human review of rule logic * [ ] Approve rules for deployment diff --git a/shared-context/learning/approved-rules/eval_usage.lgt b/shared-context/learning/approved-rules/eval_usage.lgt deleted file mode 100644 index ee947562..00000000 --- a/shared-context/learning/approved-rules/eval_usage.lgt +++ /dev/null @@ -1,197 +0,0 @@ -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect eval() and dynamic code execution -% Generated: 2026-02-06T22:00:00+00:00 -% Observations: 7 -% CWE: CWE-95 (Improper Neutralization of Directives in Dynamically Evaluated Code) -% Pattern: eval(), Function(), setTimeout/setInterval with string arguments - -:- object(eval_usage_detector, - extends(code_pattern_detector)). - - :- info([ - version is 1:0:0, - author is 'Hypatia Learning Loop', - date is 2026-02-06, - comment is 'Detects dangerous dynamic code execution patterns in JavaScript/ReScript', - remarks is [ - 'Pattern learned from 7 observations in academic-workflow-suite', - 'Extremely dangerous - enables code injection attacks', - 'Common in legacy code, test utilities, and development tools', - 'Should be eliminated from production code paths' - ] - ]). - - % Detection logic: Find eval() and related dynamic execution - has_issue(Path, eval_usage(Location, Pattern, Context)) :- - source_file(Path), - javascript_file(Path), - file_contains_dynamic_eval(Path, Location, Pattern, Context). - - % Identify JavaScript/ReScript source files - javascript_file(Path) :- - (atom_concat(_, '.js', Path) ; - atom_concat(_, '.jsx', Path) ; - atom_concat(_, '.res', Path) ; - atom_concat(_, '.mjs', Path) ; - atom_concat(_, '.cjs', Path)). - - % Detect dangerous eval patterns - file_contains_dynamic_eval(Path, line(LineNum), direct_eval, Context) :- - file_line(Path, LineNum, Line), - contains_eval_call(Line), - extract_context(Line, Context). - - file_contains_dynamic_eval(Path, line(LineNum), function_constructor, Context) :- - file_line(Path, LineNum, Line), - contains_function_constructor(Line), - extract_context(Line, Context). - - file_contains_dynamic_eval(Path, line(LineNum), string_timeout, Context) :- - file_line(Path, LineNum, Line), - contains_string_timeout(Line), - extract_context(Line, Context). - - file_contains_dynamic_eval(Path, line(LineNum), string_interval, Context) :- - file_line(Path, LineNum, Line), - contains_string_interval(Line), - extract_context(Line, Context). - - % Pattern matchers - contains_eval_call(Line) :- - sub_atom(Line, Before, _, _, 'eval('), - \+ in_comment(Line, Before), - \+ in_string_literal(Line, Before). - - contains_function_constructor(Line) :- - (sub_atom(Line, Before, _, _, 'Function(') ; - sub_atom(Line, Before, _, _, 'new Function(')), - \+ in_comment(Line, Before), - \+ in_string_literal(Line, Before). - - contains_string_timeout(Line) :- - sub_atom(Line, Before, _, _, 'setTimeout('), - sub_atom(Line, Before, _, _, '"', QuotePos), - QuotePos > Before, - \+ in_comment(Line, Before). - - contains_string_interval(Line) :- - sub_atom(Line, Before, _, _, 'setInterval('), - sub_atom(Line, Before, _, _, '"', QuotePos), - QuotePos > Before, - \+ in_comment(Line, Before). - - % Context checks - in_comment(Line, Position) :- - sub_atom(Line, CommentStart, _, _, '//'), - CommentStart < Position. - - in_string_literal(Line, Position) :- - findall(QuotePos, - (sub_atom(Line, QuotePos, _, _, '"'), - QuotePos < Position), - Quotes), - length(Quotes, Count), - 1 is Count mod 2. % Odd number of quotes = inside string - - extract_context(Line, Context) :- - atom_length(Line, Len), - (Len > 60 -> - sub_atom(Line, 0, 60, _, Context) - ; - Context = Line - ). - - % Severity classification: CRITICAL (code injection) - classify_severity(eval_usage(_, _, _), critical). - - % Context-dependent severity - classify_severity_contextual(eval_usage(Location, _, _), critical) :- - in_production_code(Location). - - classify_severity_contextual(eval_usage(Location, _, _), high) :- - in_test_code(Location). - - in_production_code(line(LineNum)) :- - file_line(Path, LineNum, _), - \+ in_test_code(line(LineNum)), - \+ in_dev_tools(Path). - - in_test_code(line(LineNum)) :- - file_line(Path, LineNum, _), - (sub_atom(Path, _, _, _, '/test/') ; - sub_atom(Path, _, _, _, '/tests/') ; - sub_atom(Path, _, _, _, '/__tests__/') ; - atom_concat(_, '.test.js', Path) ; - atom_concat(_, '.spec.js', Path)). - - in_dev_tools(Path) :- - (sub_atom(Path, _, _, _, '/scripts/') ; - sub_atom(Path, _, _, _, '/tools/') ; - sub_atom(Path, _, _, _, '/build/') ; - sub_atom(Path, _, _, _, 'webpack.config') ; - sub_atom(Path, _, _, _, 'rollup.config')). - - % Fix suggestions by pattern type - suggest_fix(eval_usage(_, direct_eval, _), - 'Replace eval() with safe alternatives:\n' + - '- For JSON: use JSON.parse()\n' + - '- For dynamic properties: use bracket notation obj[prop]\n' + - '- For conditionals: use switch/match statements\n' + - '- For dynamic imports: use import() or require()\n' + - 'eval() allows arbitrary code execution and cannot be made safe.'). - - suggest_fix(eval_usage(_, function_constructor, _), - 'Replace Function() constructor with:\n' + - '- Named functions or arrow functions\n' + - '- Function expressions\n' + - '- Strategy pattern for dynamic behavior\n' + - 'Function constructor enables code injection like eval().'). - - suggest_fix(eval_usage(_, string_timeout, _), - 'Replace setTimeout(string) with function reference:\n' + - '- BAD: setTimeout("doSomething()", 1000)\n' + - '- GOOD: setTimeout(() => doSomething(), 1000)\n' + - 'String arguments are evaluated like eval().'). - - suggest_fix(eval_usage(_, string_interval, _), - 'Replace setInterval(string) with function reference:\n' + - '- BAD: setInterval("doSomething()", 1000)\n' + - '- GOOD: setInterval(() => doSomething(), 1000)\n' + - 'String arguments are evaluated like eval().'). - - % Not auto-fixable (requires code refactoring) - auto_fixable(eval_usage(_, _, _), false). - - % Security metrics - eval_count_by_repo(Repo, Count) :- - findall(1, - (source_file(Path), - repo_path(Repo, Path), - has_issue(Path, eval_usage(_, _, _))), - Issues), - length(Issues, Count). - - % Alert if eval detected in production code - critical_eval_in_production(Path, Location) :- - has_issue(Path, eval_usage(Location, Pattern, _)), - in_production_code(Location), - critical_pattern(Pattern). - - critical_pattern(direct_eval). - critical_pattern(function_constructor). - - % CSP recommendation - recommend_csp_header(Path) :- - has_issue(Path, eval_usage(_, _, _)), - \+ has_csp_protection(Path). - - has_csp_protection(Path) :- - repo_has_csp_header(Path). - - % Suggest Content-Security-Policy header to block eval - csp_recommendation :- - 'Add Content-Security-Policy header:\n' + - 'Content-Security-Policy: script-src \'self\'; object-src \'none\'\n' + - 'This blocks eval() and inline scripts at the browser level.'. - -:- end_object. diff --git a/shared-context/learning/approved-rules/eval_usage.lgt.meta b/shared-context/learning/approved-rules/eval_usage.lgt.meta deleted file mode 100644 index f4ba57f8..00000000 --- a/shared-context/learning/approved-rules/eval_usage.lgt.meta +++ /dev/null @@ -1,9 +0,0 @@ -# Rule Approval Metadata -rule_name: eval_usage -status: approved -approved_date: 2026-02-06T22:23:47+00:00 -approved_by: ECHIDNA Semantic Validation v1.0 -validation_score: 92% -observations: 7 -deployment_date: 2026-02-06T22:23:47+00:00 -production_ready: true diff --git a/shared-context/learning/approved-rules/technical_debt.lgt b/shared-context/learning/approved-rules/technical_debt.lgt deleted file mode 100644 index 8ba317c3..00000000 --- a/shared-context/learning/approved-rules/technical_debt.lgt +++ /dev/null @@ -1,104 +0,0 @@ -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect technical_debt markers -% Generated: 2026-02-06T22:00:00+00:00 -% Observations: 196 -% CWE: CWE-1057 (Data Access from Outside Expected Data Manager) -% Pattern: TODO/FIXME/HACK/XXX/BUG comments indicating deferred work - -:- object(technical_debt_detector, - extends(code_pattern_detector)). - - :- info([ - version is 1:0:0, - author is 'Hypatia Learning Loop', - date is 2026-02-06, - comment is 'Detects technical debt markers (TODO, FIXME, HACK, XXX, BUG) across codebases', - remarks is [ - 'Pattern learned from 196 observations across 7 repositories', - 'Most prevalent in affinescript (143 markers), vordr (34 markers)', - 'Enables systematic tracking of deferred work and maintenance items' - ] - ]). - - % Detection logic: Find TODO/FIXME/HACK/XXX/BUG comments - has_issue(Path, technical_debt(Location, Marker, Message)) :- - source_file(Path), - file_contains_pattern(Path, Location, DebtPattern), - debt_marker_pattern(DebtPattern, Marker, Message), - valid_debt_marker(Marker). - - % Debt marker patterns - debt_marker_pattern(Line, 'TODO', Message) :- - sub_atom(Line, _, _, _, 'TODO:'), - extract_message_after(Line, 'TODO:', Message). - - debt_marker_pattern(Line, 'FIXME', Message) :- - sub_atom(Line, _, _, _, 'FIXME:'), - extract_message_after(Line, 'FIXME:', Message). - - debt_marker_pattern(Line, 'HACK', Message) :- - sub_atom(Line, _, _, _, 'HACK:'), - extract_message_after(Line, 'HACK:', Message). - - debt_marker_pattern(Line, 'XXX', Message) :- - sub_atom(Line, _, _, _, 'XXX:'), - extract_message_after(Line, 'XXX:', Message). - - debt_marker_pattern(Line, 'BUG', Message) :- - sub_atom(Line, _, _, _, 'BUG:'), - extract_message_after(Line, 'BUG:', Message). - - % Valid markers (case-insensitive) - valid_debt_marker('TODO'). - valid_debt_marker('FIXME'). - valid_debt_marker('HACK'). - valid_debt_marker('XXX'). - valid_debt_marker('BUG'). - - % Helper: Extract message after marker - extract_message_after(Line, Marker, Message) :- - sub_atom(Line, Before, _, After, Marker), - MarkerEnd is Before + atom_length(Marker), - sub_atom(Line, MarkerEnd, After, 0, MessageRaw), - atom_trim(MessageRaw, Message). - - % Severity classification: INFO (tracking, not critical) - classify_severity(technical_debt(_, _, _), info). - - % Priority by marker type (for triage) - marker_priority('BUG', critical). - marker_priority('FIXME', high). - marker_priority('HACK', medium). - marker_priority('TODO', low). - marker_priority('XXX', low). - - % Fix suggestion - suggest_fix(technical_debt(_, Marker, Message), FixSuggestion) :- - marker_priority(Marker, Priority), - atom_concat('Create GitHub issue for ', Marker, Part1), - atom_concat(Part1, ' item with priority: ', Part2), - atom_concat(Part2, Priority, Part3), - atom_concat(Part3, '. Message: ', Part4), - atom_concat(Part4, Message, FixSuggestion). - - % Not auto-fixable (requires human triage and issue creation) - auto_fixable(technical_debt(_, _, _), false). - - % Potential future auto-fix: Create GitHub issues automatically - % Requires: GitHub API integration, issue deduplication, priority assignment - - % Metrics: Count debt by repository - repo_debt_count(Repo, Count) :- - findall(1, - (source_file(Path), - repo_path(Repo, Path), - has_issue(Path, technical_debt(_, _, _))), - Issues), - length(Issues, Count). - - % Alert if debt exceeds threshold - excessive_debt(Repo, Count) :- - repo_debt_count(Repo, Count), - Count > 50. % Threshold: 50+ markers indicates high debt - -:- end_object. diff --git a/shared-context/learning/approved-rules/technical_debt.lgt.meta b/shared-context/learning/approved-rules/technical_debt.lgt.meta deleted file mode 100644 index 00ee97ee..00000000 --- a/shared-context/learning/approved-rules/technical_debt.lgt.meta +++ /dev/null @@ -1,9 +0,0 @@ -# Rule Approval Metadata -rule_name: technical_debt -status: approved -approved_date: 2026-02-06T22:23:47+00:00 -approved_by: ECHIDNA Semantic Validation v1.0 -validation_score: 92% -observations: 196 -deployment_date: 2026-02-06T22:23:47+00:00 -production_ready: true diff --git a/shared-context/learning/approved-rules/unsafe_without_doc.lgt b/shared-context/learning/approved-rules/unsafe_without_doc.lgt deleted file mode 100644 index 4a0ab91b..00000000 --- a/shared-context/learning/approved-rules/unsafe_without_doc.lgt +++ /dev/null @@ -1,138 +0,0 @@ -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect unsafe blocks without documentation -% Generated: 2026-02-06T22:00:00+00:00 -% Observations: 19 -% CWE: CWE-1188 (Insecure Default Initialization) -% Pattern: Rust unsafe blocks without preceding safety documentation - -:- object(unsafe_without_doc_detector, - extends(code_pattern_detector)). - - :- info([ - version is 1:0:0, - author is 'Hypatia Learning Loop', - date is 2026-02-06, - comment is 'Detects Rust unsafe blocks that lack safety documentation comments', - remarks is [ - 'Pattern learned from 19 observations across 2 repositories', - 'Most prevalent in affinescript (14 instances), vordr (5 instances)', - 'Ensures all unsafe code has explicit safety invariants documented', - 'Critical for memory safety verification and audit trails' - ] - ]). - - % Detection logic: Find unsafe blocks without preceding documentation - has_issue(Path, unsafe_without_doc(Location, UnsafeBlock)) :- - source_file(Path), - rust_file(Path), - file_contains_unsafe(Path, Location, UnsafeBlock), - \+ has_safety_doc(Path, Location). - - % Identify Rust source files - rust_file(Path) :- - atom_concat(_, '.rs', Path). - - % Detect unsafe block pattern - file_contains_unsafe(Path, line(LineNum), Block) :- - file_line(Path, LineNum, Line), - contains_unsafe_block(Line, Block). - - % unsafe block patterns - contains_unsafe_block(Line, Block) :- - sub_atom(Line, Start, _, _, 'unsafe'), - sub_atom(Line, BlockStart, _, _, '{'), - BlockStart > Start, - sub_atom(Line, Start, _, 0, Block). - - % Check for safety documentation in preceding lines - has_safety_doc(Path, line(LineNum)) :- - PrevLine is LineNum - 1, - PrevLine > 0, - file_line(Path, PrevLine, Line), - is_safety_comment(Line). - - has_safety_doc(Path, line(LineNum)) :- - PrevLine is LineNum - 2, - PrevLine > 0, - file_line(Path, PrevLine, Line), - is_safety_comment(Line). - - % Safety comment patterns - is_safety_comment(Line) :- - sub_atom(Line, _, _, _, '//'), - (contains_safety_keyword(Line) ; - contains_invariant_keyword(Line) ; - contains_rationale_keyword(Line)). - - % Keywords indicating safety documentation - contains_safety_keyword(Line) :- - (sub_atom(Line, _, _, _, 'SAFETY:') ; - sub_atom(Line, _, _, _, 'Safety:') ; - sub_atom(Line, _, _, _, 'safe because') ; - sub_atom(Line, _, _, _, 'Safe because')). - - contains_invariant_keyword(Line) :- - (sub_atom(Line, _, _, _, 'invariant') ; - sub_atom(Line, _, _, _, 'Invariant') ; - sub_atom(Line, _, _, _, 'guarantee') ; - sub_atom(Line, _, _, _, 'Guarantee')). - - contains_rationale_keyword(Line) :- - (sub_atom(Line, _, _, _, 'rationale') ; - sub_atom(Line, _, _, _, 'Rationale') ; - sub_atom(Line, _, _, _, 'reason') ; - sub_atom(Line, _, _, _, 'Reason')). - - % Severity classification: HIGH (memory safety critical) - classify_severity(unsafe_without_doc(_, _), high). - - % Context-dependent severity: escalate in production code - classify_severity_contextual(unsafe_without_doc(Location, _), critical) :- - in_production_code(Location). - - in_production_code(line(LineNum)) :- - \+ in_test_code(LineNum). - - in_test_code(LineNum) :- - file_line(Path, LineNum, _), - (sub_atom(Path, _, _, _, '/test/') ; - sub_atom(Path, _, _, _, '/tests/') ; - atom_concat(_, '_test.rs', Path)). - - % Fix suggestion - suggest_fix(unsafe_without_doc(_, Block), Fix) :- - atom_concat('Add safety documentation comment before unsafe block: ', Block, Part1), - atom_concat(Part1, '\n// SAFETY: [Explain why this is safe]', Part2), - atom_concat(Part2, '\n// - Document safety invariants', Part3), - atom_concat(Part3, '\n// - Explain caller obligations', Part4), - atom_concat(Part4, '\n// - Justify why unsafe is necessary', Fix). - - % Not auto-fixable (requires human safety analysis) - auto_fixable(unsafe_without_doc(_, _), false). - - % Quality metrics - unsafe_documentation_ratio(Path, Ratio) :- - rust_file(Path), - findall(1, file_contains_unsafe(Path, _, _), AllUnsafe), - findall(1, (file_contains_unsafe(Path, Loc, _), has_safety_doc(Path, Loc)), Documented), - length(AllUnsafe, Total), - length(Documented, DocCount), - (Total > 0 -> Ratio is DocCount / Total ; Ratio is 1.0). - - % Alert if documentation ratio is poor - poor_unsafe_documentation(Path) :- - unsafe_documentation_ratio(Path, Ratio), - Ratio < 0.5. % Less than 50% documented - - % Recommend: Use safe abstractions where possible - suggest_safe_alternative(Path, Location) :- - has_issue(Path, unsafe_without_doc(Location, Block)), - potentially_avoidable_unsafe(Block). - - potentially_avoidable_unsafe(Block) :- - (sub_atom(Block, _, _, _, 'transmute') ; - sub_atom(Block, _, _, _, 'raw pointer') ; - sub_atom(Block, _, _, _, 'as *const') ; - sub_atom(Block, _, _, _, 'as *mut')). - -:- end_object. diff --git a/shared-context/learning/approved-rules/unsafe_without_doc.lgt.meta b/shared-context/learning/approved-rules/unsafe_without_doc.lgt.meta deleted file mode 100644 index 73eb287f..00000000 --- a/shared-context/learning/approved-rules/unsafe_without_doc.lgt.meta +++ /dev/null @@ -1,9 +0,0 @@ -# Rule Approval Metadata -rule_name: unsafe_without_doc -status: approved -approved_date: 2026-02-06T22:23:47+00:00 -approved_by: ECHIDNA Semantic Validation v1.0 -validation_score: 92% -observations: 19 -deployment_date: 2026-02-06T22:23:47+00:00 -production_ready: true diff --git a/shared-context/learning/rule-proposals/eval_usage.lgt b/shared-context/learning/rule-proposals/eval_usage.lgt deleted file mode 100644 index ee947562..00000000 --- a/shared-context/learning/rule-proposals/eval_usage.lgt +++ /dev/null @@ -1,197 +0,0 @@ -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect eval() and dynamic code execution -% Generated: 2026-02-06T22:00:00+00:00 -% Observations: 7 -% CWE: CWE-95 (Improper Neutralization of Directives in Dynamically Evaluated Code) -% Pattern: eval(), Function(), setTimeout/setInterval with string arguments - -:- object(eval_usage_detector, - extends(code_pattern_detector)). - - :- info([ - version is 1:0:0, - author is 'Hypatia Learning Loop', - date is 2026-02-06, - comment is 'Detects dangerous dynamic code execution patterns in JavaScript/ReScript', - remarks is [ - 'Pattern learned from 7 observations in academic-workflow-suite', - 'Extremely dangerous - enables code injection attacks', - 'Common in legacy code, test utilities, and development tools', - 'Should be eliminated from production code paths' - ] - ]). - - % Detection logic: Find eval() and related dynamic execution - has_issue(Path, eval_usage(Location, Pattern, Context)) :- - source_file(Path), - javascript_file(Path), - file_contains_dynamic_eval(Path, Location, Pattern, Context). - - % Identify JavaScript/ReScript source files - javascript_file(Path) :- - (atom_concat(_, '.js', Path) ; - atom_concat(_, '.jsx', Path) ; - atom_concat(_, '.res', Path) ; - atom_concat(_, '.mjs', Path) ; - atom_concat(_, '.cjs', Path)). - - % Detect dangerous eval patterns - file_contains_dynamic_eval(Path, line(LineNum), direct_eval, Context) :- - file_line(Path, LineNum, Line), - contains_eval_call(Line), - extract_context(Line, Context). - - file_contains_dynamic_eval(Path, line(LineNum), function_constructor, Context) :- - file_line(Path, LineNum, Line), - contains_function_constructor(Line), - extract_context(Line, Context). - - file_contains_dynamic_eval(Path, line(LineNum), string_timeout, Context) :- - file_line(Path, LineNum, Line), - contains_string_timeout(Line), - extract_context(Line, Context). - - file_contains_dynamic_eval(Path, line(LineNum), string_interval, Context) :- - file_line(Path, LineNum, Line), - contains_string_interval(Line), - extract_context(Line, Context). - - % Pattern matchers - contains_eval_call(Line) :- - sub_atom(Line, Before, _, _, 'eval('), - \+ in_comment(Line, Before), - \+ in_string_literal(Line, Before). - - contains_function_constructor(Line) :- - (sub_atom(Line, Before, _, _, 'Function(') ; - sub_atom(Line, Before, _, _, 'new Function(')), - \+ in_comment(Line, Before), - \+ in_string_literal(Line, Before). - - contains_string_timeout(Line) :- - sub_atom(Line, Before, _, _, 'setTimeout('), - sub_atom(Line, Before, _, _, '"', QuotePos), - QuotePos > Before, - \+ in_comment(Line, Before). - - contains_string_interval(Line) :- - sub_atom(Line, Before, _, _, 'setInterval('), - sub_atom(Line, Before, _, _, '"', QuotePos), - QuotePos > Before, - \+ in_comment(Line, Before). - - % Context checks - in_comment(Line, Position) :- - sub_atom(Line, CommentStart, _, _, '//'), - CommentStart < Position. - - in_string_literal(Line, Position) :- - findall(QuotePos, - (sub_atom(Line, QuotePos, _, _, '"'), - QuotePos < Position), - Quotes), - length(Quotes, Count), - 1 is Count mod 2. % Odd number of quotes = inside string - - extract_context(Line, Context) :- - atom_length(Line, Len), - (Len > 60 -> - sub_atom(Line, 0, 60, _, Context) - ; - Context = Line - ). - - % Severity classification: CRITICAL (code injection) - classify_severity(eval_usage(_, _, _), critical). - - % Context-dependent severity - classify_severity_contextual(eval_usage(Location, _, _), critical) :- - in_production_code(Location). - - classify_severity_contextual(eval_usage(Location, _, _), high) :- - in_test_code(Location). - - in_production_code(line(LineNum)) :- - file_line(Path, LineNum, _), - \+ in_test_code(line(LineNum)), - \+ in_dev_tools(Path). - - in_test_code(line(LineNum)) :- - file_line(Path, LineNum, _), - (sub_atom(Path, _, _, _, '/test/') ; - sub_atom(Path, _, _, _, '/tests/') ; - sub_atom(Path, _, _, _, '/__tests__/') ; - atom_concat(_, '.test.js', Path) ; - atom_concat(_, '.spec.js', Path)). - - in_dev_tools(Path) :- - (sub_atom(Path, _, _, _, '/scripts/') ; - sub_atom(Path, _, _, _, '/tools/') ; - sub_atom(Path, _, _, _, '/build/') ; - sub_atom(Path, _, _, _, 'webpack.config') ; - sub_atom(Path, _, _, _, 'rollup.config')). - - % Fix suggestions by pattern type - suggest_fix(eval_usage(_, direct_eval, _), - 'Replace eval() with safe alternatives:\n' + - '- For JSON: use JSON.parse()\n' + - '- For dynamic properties: use bracket notation obj[prop]\n' + - '- For conditionals: use switch/match statements\n' + - '- For dynamic imports: use import() or require()\n' + - 'eval() allows arbitrary code execution and cannot be made safe.'). - - suggest_fix(eval_usage(_, function_constructor, _), - 'Replace Function() constructor with:\n' + - '- Named functions or arrow functions\n' + - '- Function expressions\n' + - '- Strategy pattern for dynamic behavior\n' + - 'Function constructor enables code injection like eval().'). - - suggest_fix(eval_usage(_, string_timeout, _), - 'Replace setTimeout(string) with function reference:\n' + - '- BAD: setTimeout("doSomething()", 1000)\n' + - '- GOOD: setTimeout(() => doSomething(), 1000)\n' + - 'String arguments are evaluated like eval().'). - - suggest_fix(eval_usage(_, string_interval, _), - 'Replace setInterval(string) with function reference:\n' + - '- BAD: setInterval("doSomething()", 1000)\n' + - '- GOOD: setInterval(() => doSomething(), 1000)\n' + - 'String arguments are evaluated like eval().'). - - % Not auto-fixable (requires code refactoring) - auto_fixable(eval_usage(_, _, _), false). - - % Security metrics - eval_count_by_repo(Repo, Count) :- - findall(1, - (source_file(Path), - repo_path(Repo, Path), - has_issue(Path, eval_usage(_, _, _))), - Issues), - length(Issues, Count). - - % Alert if eval detected in production code - critical_eval_in_production(Path, Location) :- - has_issue(Path, eval_usage(Location, Pattern, _)), - in_production_code(Location), - critical_pattern(Pattern). - - critical_pattern(direct_eval). - critical_pattern(function_constructor). - - % CSP recommendation - recommend_csp_header(Path) :- - has_issue(Path, eval_usage(_, _, _)), - \+ has_csp_protection(Path). - - has_csp_protection(Path) :- - repo_has_csp_header(Path). - - % Suggest Content-Security-Policy header to block eval - csp_recommendation :- - 'Add Content-Security-Policy header:\n' + - 'Content-Security-Policy: script-src \'self\'; object-src \'none\'\n' + - 'This blocks eval() and inline scripts at the browser level.'. - -:- end_object. diff --git a/shared-context/learning/rule-proposals/getexn_on_external_data.lgt b/shared-context/learning/rule-proposals/getexn_on_external_data.lgt deleted file mode 100644 index e12d44c4..00000000 --- a/shared-context/learning/rule-proposals/getexn_on_external_data.lgt +++ /dev/null @@ -1,18 +0,0 @@ -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule proposal -% Pattern: getexn_on_external_data -% Type: unsafe_crash -% Observations: 6 -% Generated: 2026-01-25T08:18:41+00:00 - -% TODO: Review and integrate into code-safety-lessons.lgt - -has_unsafe_crash_issue(Path, getexn_on_external_data_pattern(Line)) :- - read_code_line(Path, LineNum, Line), - atom_concat(_, 'getexn_on_external_data', Line), - LineNum. - -classify_severity(getexn_on_external_data_pattern(_), high). - -suggest_fix(getexn_on_external_data_pattern(_), - 'Auto-generated fix suggestion - NEEDS REVIEW'). diff --git a/shared-context/learning/rule-proposals/technical_debt.lgt b/shared-context/learning/rule-proposals/technical_debt.lgt deleted file mode 100644 index 8ba317c3..00000000 --- a/shared-context/learning/rule-proposals/technical_debt.lgt +++ /dev/null @@ -1,104 +0,0 @@ -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect technical_debt markers -% Generated: 2026-02-06T22:00:00+00:00 -% Observations: 196 -% CWE: CWE-1057 (Data Access from Outside Expected Data Manager) -% Pattern: TODO/FIXME/HACK/XXX/BUG comments indicating deferred work - -:- object(technical_debt_detector, - extends(code_pattern_detector)). - - :- info([ - version is 1:0:0, - author is 'Hypatia Learning Loop', - date is 2026-02-06, - comment is 'Detects technical debt markers (TODO, FIXME, HACK, XXX, BUG) across codebases', - remarks is [ - 'Pattern learned from 196 observations across 7 repositories', - 'Most prevalent in affinescript (143 markers), vordr (34 markers)', - 'Enables systematic tracking of deferred work and maintenance items' - ] - ]). - - % Detection logic: Find TODO/FIXME/HACK/XXX/BUG comments - has_issue(Path, technical_debt(Location, Marker, Message)) :- - source_file(Path), - file_contains_pattern(Path, Location, DebtPattern), - debt_marker_pattern(DebtPattern, Marker, Message), - valid_debt_marker(Marker). - - % Debt marker patterns - debt_marker_pattern(Line, 'TODO', Message) :- - sub_atom(Line, _, _, _, 'TODO:'), - extract_message_after(Line, 'TODO:', Message). - - debt_marker_pattern(Line, 'FIXME', Message) :- - sub_atom(Line, _, _, _, 'FIXME:'), - extract_message_after(Line, 'FIXME:', Message). - - debt_marker_pattern(Line, 'HACK', Message) :- - sub_atom(Line, _, _, _, 'HACK:'), - extract_message_after(Line, 'HACK:', Message). - - debt_marker_pattern(Line, 'XXX', Message) :- - sub_atom(Line, _, _, _, 'XXX:'), - extract_message_after(Line, 'XXX:', Message). - - debt_marker_pattern(Line, 'BUG', Message) :- - sub_atom(Line, _, _, _, 'BUG:'), - extract_message_after(Line, 'BUG:', Message). - - % Valid markers (case-insensitive) - valid_debt_marker('TODO'). - valid_debt_marker('FIXME'). - valid_debt_marker('HACK'). - valid_debt_marker('XXX'). - valid_debt_marker('BUG'). - - % Helper: Extract message after marker - extract_message_after(Line, Marker, Message) :- - sub_atom(Line, Before, _, After, Marker), - MarkerEnd is Before + atom_length(Marker), - sub_atom(Line, MarkerEnd, After, 0, MessageRaw), - atom_trim(MessageRaw, Message). - - % Severity classification: INFO (tracking, not critical) - classify_severity(technical_debt(_, _, _), info). - - % Priority by marker type (for triage) - marker_priority('BUG', critical). - marker_priority('FIXME', high). - marker_priority('HACK', medium). - marker_priority('TODO', low). - marker_priority('XXX', low). - - % Fix suggestion - suggest_fix(technical_debt(_, Marker, Message), FixSuggestion) :- - marker_priority(Marker, Priority), - atom_concat('Create GitHub issue for ', Marker, Part1), - atom_concat(Part1, ' item with priority: ', Part2), - atom_concat(Part2, Priority, Part3), - atom_concat(Part3, '. Message: ', Part4), - atom_concat(Part4, Message, FixSuggestion). - - % Not auto-fixable (requires human triage and issue creation) - auto_fixable(technical_debt(_, _, _), false). - - % Potential future auto-fix: Create GitHub issues automatically - % Requires: GitHub API integration, issue deduplication, priority assignment - - % Metrics: Count debt by repository - repo_debt_count(Repo, Count) :- - findall(1, - (source_file(Path), - repo_path(Repo, Path), - has_issue(Path, technical_debt(_, _, _))), - Issues), - length(Issues, Count). - - % Alert if debt exceeds threshold - excessive_debt(Repo, Count) :- - repo_debt_count(Repo, Count), - Count > 50. % Threshold: 50+ markers indicates high debt - -:- end_object. diff --git a/shared-context/learning/rule-proposals/type_safety_bypass.lgt b/shared-context/learning/rule-proposals/type_safety_bypass.lgt deleted file mode 100644 index bd35a1d4..00000000 --- a/shared-context/learning/rule-proposals/type_safety_bypass.lgt +++ /dev/null @@ -1,21 +0,0 @@ -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect type_safety_bypass issues -% Generated: 2026-02-06T21:38:05+00:00 -% Observations: 5 - -:- object(type_safety_bypass_detector, - extends(code_pattern_detector)). - - % TODO: Implement detection logic for type_safety_bypass - has_issue(Path, type_safety_bypass(Location)) :- - source_file(Path), - % Add specific detection logic here - fail. % Replace with actual implementation - - classify_severity(type_safety_bypass(_), medium). - - suggest_fix(type_safety_bypass(_), 'Manual review required for type_safety_bypass'). - - auto_fixable(type_safety_bypass(_), false). - -:- end_object. diff --git a/shared-context/learning/rule-proposals/unsafe_crash.lgt b/shared-context/learning/rule-proposals/unsafe_crash.lgt deleted file mode 100644 index 11d44e3e..00000000 --- a/shared-context/learning/rule-proposals/unsafe_crash.lgt +++ /dev/null @@ -1,21 +0,0 @@ -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect unsafe_crash issues -% Generated: 2026-02-06T21:38:05+00:00 -% Observations: 8 - -:- object(unsafe_crash_detector, - extends(code_pattern_detector)). - - % TODO: Implement detection logic for unsafe_crash - has_issue(Path, unsafe_crash(Location)) :- - source_file(Path), - % Add specific detection logic here - fail. % Replace with actual implementation - - classify_severity(unsafe_crash(_), medium). - - suggest_fix(unsafe_crash(_), 'Manual review required for unsafe_crash'). - - auto_fixable(unsafe_crash(_), false). - -:- end_object. diff --git a/shared-context/learning/rule-proposals/unsafe_panic.lgt b/shared-context/learning/rule-proposals/unsafe_panic.lgt deleted file mode 100644 index af1d3da4..00000000 --- a/shared-context/learning/rule-proposals/unsafe_panic.lgt +++ /dev/null @@ -1,21 +0,0 @@ -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect unsafe_panic issues -% Generated: 2026-02-06T21:31:24+00:00 -% Observations: 15 - -:- object(unsafe_panic_detector, - extends(code_pattern_detector)). - - % TODO: Implement detection logic for unsafe_panic - has_issue(Path, unsafe_panic(Location)) :- - source_file(Path), - % Add specific detection logic here - fail. % Replace with actual implementation - - classify_severity(unsafe_panic(_), medium). - - suggest_fix(unsafe_panic(_), 'Manual review required for unsafe_panic'). - - auto_fixable(unsafe_panic(_), false). - -:- end_object. diff --git a/shared-context/learning/rule-proposals/unsafe_without_doc.lgt b/shared-context/learning/rule-proposals/unsafe_without_doc.lgt deleted file mode 100644 index 4a0ab91b..00000000 --- a/shared-context/learning/rule-proposals/unsafe_without_doc.lgt +++ /dev/null @@ -1,138 +0,0 @@ -% SPDX-License-Identifier: MPL-2.0 -% Auto-generated rule: Detect unsafe blocks without documentation -% Generated: 2026-02-06T22:00:00+00:00 -% Observations: 19 -% CWE: CWE-1188 (Insecure Default Initialization) -% Pattern: Rust unsafe blocks without preceding safety documentation - -:- object(unsafe_without_doc_detector, - extends(code_pattern_detector)). - - :- info([ - version is 1:0:0, - author is 'Hypatia Learning Loop', - date is 2026-02-06, - comment is 'Detects Rust unsafe blocks that lack safety documentation comments', - remarks is [ - 'Pattern learned from 19 observations across 2 repositories', - 'Most prevalent in affinescript (14 instances), vordr (5 instances)', - 'Ensures all unsafe code has explicit safety invariants documented', - 'Critical for memory safety verification and audit trails' - ] - ]). - - % Detection logic: Find unsafe blocks without preceding documentation - has_issue(Path, unsafe_without_doc(Location, UnsafeBlock)) :- - source_file(Path), - rust_file(Path), - file_contains_unsafe(Path, Location, UnsafeBlock), - \+ has_safety_doc(Path, Location). - - % Identify Rust source files - rust_file(Path) :- - atom_concat(_, '.rs', Path). - - % Detect unsafe block pattern - file_contains_unsafe(Path, line(LineNum), Block) :- - file_line(Path, LineNum, Line), - contains_unsafe_block(Line, Block). - - % unsafe block patterns - contains_unsafe_block(Line, Block) :- - sub_atom(Line, Start, _, _, 'unsafe'), - sub_atom(Line, BlockStart, _, _, '{'), - BlockStart > Start, - sub_atom(Line, Start, _, 0, Block). - - % Check for safety documentation in preceding lines - has_safety_doc(Path, line(LineNum)) :- - PrevLine is LineNum - 1, - PrevLine > 0, - file_line(Path, PrevLine, Line), - is_safety_comment(Line). - - has_safety_doc(Path, line(LineNum)) :- - PrevLine is LineNum - 2, - PrevLine > 0, - file_line(Path, PrevLine, Line), - is_safety_comment(Line). - - % Safety comment patterns - is_safety_comment(Line) :- - sub_atom(Line, _, _, _, '//'), - (contains_safety_keyword(Line) ; - contains_invariant_keyword(Line) ; - contains_rationale_keyword(Line)). - - % Keywords indicating safety documentation - contains_safety_keyword(Line) :- - (sub_atom(Line, _, _, _, 'SAFETY:') ; - sub_atom(Line, _, _, _, 'Safety:') ; - sub_atom(Line, _, _, _, 'safe because') ; - sub_atom(Line, _, _, _, 'Safe because')). - - contains_invariant_keyword(Line) :- - (sub_atom(Line, _, _, _, 'invariant') ; - sub_atom(Line, _, _, _, 'Invariant') ; - sub_atom(Line, _, _, _, 'guarantee') ; - sub_atom(Line, _, _, _, 'Guarantee')). - - contains_rationale_keyword(Line) :- - (sub_atom(Line, _, _, _, 'rationale') ; - sub_atom(Line, _, _, _, 'Rationale') ; - sub_atom(Line, _, _, _, 'reason') ; - sub_atom(Line, _, _, _, 'Reason')). - - % Severity classification: HIGH (memory safety critical) - classify_severity(unsafe_without_doc(_, _), high). - - % Context-dependent severity: escalate in production code - classify_severity_contextual(unsafe_without_doc(Location, _), critical) :- - in_production_code(Location). - - in_production_code(line(LineNum)) :- - \+ in_test_code(LineNum). - - in_test_code(LineNum) :- - file_line(Path, LineNum, _), - (sub_atom(Path, _, _, _, '/test/') ; - sub_atom(Path, _, _, _, '/tests/') ; - atom_concat(_, '_test.rs', Path)). - - % Fix suggestion - suggest_fix(unsafe_without_doc(_, Block), Fix) :- - atom_concat('Add safety documentation comment before unsafe block: ', Block, Part1), - atom_concat(Part1, '\n// SAFETY: [Explain why this is safe]', Part2), - atom_concat(Part2, '\n// - Document safety invariants', Part3), - atom_concat(Part3, '\n// - Explain caller obligations', Part4), - atom_concat(Part4, '\n// - Justify why unsafe is necessary', Fix). - - % Not auto-fixable (requires human safety analysis) - auto_fixable(unsafe_without_doc(_, _), false). - - % Quality metrics - unsafe_documentation_ratio(Path, Ratio) :- - rust_file(Path), - findall(1, file_contains_unsafe(Path, _, _), AllUnsafe), - findall(1, (file_contains_unsafe(Path, Loc, _), has_safety_doc(Path, Loc)), Documented), - length(AllUnsafe, Total), - length(Documented, DocCount), - (Total > 0 -> Ratio is DocCount / Total ; Ratio is 1.0). - - % Alert if documentation ratio is poor - poor_unsafe_documentation(Path) :- - unsafe_documentation_ratio(Path, Ratio), - Ratio < 0.5. % Less than 50% documented - - % Recommend: Use safe abstractions where possible - suggest_safe_alternative(Path, Location) :- - has_issue(Path, unsafe_without_doc(Location, Block)), - potentially_avoidable_unsafe(Block). - - potentially_avoidable_unsafe(Block) :- - (sub_atom(Block, _, _, _, 'transmute') ; - sub_atom(Block, _, _, _, 'raw pointer') ; - sub_atom(Block, _, _, _, 'as *const') ; - sub_atom(Block, _, _, _, 'as *mut')). - -:- end_object.