@yuaone/core 0.8.4 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/README.md +73 -2
  2. package/dist/agent-loop.d.ts +8 -0
  3. package/dist/agent-loop.d.ts.map +1 -1
  4. package/dist/agent-loop.js +34 -0
  5. package/dist/agent-loop.js.map +1 -1
  6. package/dist/dag-orchestrator.d.ts +3 -0
  7. package/dist/dag-orchestrator.d.ts.map +1 -1
  8. package/dist/dag-orchestrator.js +1 -0
  9. package/dist/dag-orchestrator.js.map +1 -1
  10. package/dist/execution-engine.d.ts.map +1 -1
  11. package/dist/execution-engine.js +1 -0
  12. package/dist/execution-engine.js.map +1 -1
  13. package/dist/index.d.ts +5 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +7 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/language-detector.d.ts.map +1 -1
  18. package/dist/language-detector.js +43 -122
  19. package/dist/language-detector.js.map +1 -1
  20. package/dist/language-registry.d.ts +45 -0
  21. package/dist/language-registry.d.ts.map +1 -0
  22. package/dist/language-registry.js +893 -0
  23. package/dist/language-registry.js.map +1 -0
  24. package/dist/llm-client.d.ts +7 -0
  25. package/dist/llm-client.d.ts.map +1 -1
  26. package/dist/llm-client.js +58 -8
  27. package/dist/llm-client.js.map +1 -1
  28. package/dist/skill-loader.d.ts +9 -16
  29. package/dist/skill-loader.d.ts.map +1 -1
  30. package/dist/skill-loader.js +116 -52
  31. package/dist/skill-loader.js.map +1 -1
  32. package/dist/skill-mode-bridge.d.ts +17 -0
  33. package/dist/skill-mode-bridge.d.ts.map +1 -0
  34. package/dist/skill-mode-bridge.js +27 -0
  35. package/dist/skill-mode-bridge.js.map +1 -0
  36. package/dist/skills/code-review.md +58 -0
  37. package/dist/skills/debug.md +45 -0
  38. package/dist/skills/languages/python.md +89 -0
  39. package/dist/skills/languages/react.md +86 -0
  40. package/dist/skills/languages/typescript.md +110 -0
  41. package/dist/skills/plan.md +49 -0
  42. package/dist/skills/refactor.md +46 -0
  43. package/dist/skills/security-scan.md +59 -0
  44. package/dist/skills/skills/code-review.md +58 -0
  45. package/dist/skills/skills/debug.md +45 -0
  46. package/dist/skills/skills/languages/bash.md +74 -0
  47. package/dist/skills/skills/languages/c.md +76 -0
  48. package/dist/skills/skills/languages/cpp.md +75 -0
  49. package/dist/skills/skills/languages/csharp.md +77 -0
  50. package/dist/skills/skills/languages/cuda.md +80 -0
  51. package/dist/skills/skills/languages/dart.md +75 -0
  52. package/dist/skills/skills/languages/docker.md +80 -0
  53. package/dist/skills/skills/languages/elixir.md +80 -0
  54. package/dist/skills/skills/languages/gdscript.md +80 -0
  55. package/dist/skills/skills/languages/go.md +77 -0
  56. package/dist/skills/skills/languages/haskell.md +80 -0
  57. package/dist/skills/skills/languages/java.md +77 -0
  58. package/dist/skills/skills/languages/javascript.md +73 -0
  59. package/dist/skills/skills/languages/kotlin.md +75 -0
  60. package/dist/skills/skills/languages/lua.md +79 -0
  61. package/dist/skills/skills/languages/php.md +73 -0
  62. package/dist/skills/skills/languages/python.md +89 -0
  63. package/dist/skills/skills/languages/r.md +80 -0
  64. package/dist/skills/skills/languages/react.md +86 -0
  65. package/dist/skills/skills/languages/ruby.md +78 -0
  66. package/dist/skills/skills/languages/rust.md +77 -0
  67. package/dist/skills/skills/languages/solidity.md +81 -0
  68. package/dist/skills/skills/languages/sql.md +74 -0
  69. package/dist/skills/skills/languages/svelte.md +74 -0
  70. package/dist/skills/skills/languages/swift.md +74 -0
  71. package/dist/skills/skills/languages/terraform.md +80 -0
  72. package/dist/skills/skills/languages/typescript.md +110 -0
  73. package/dist/skills/skills/languages/verilog.md +80 -0
  74. package/dist/skills/skills/languages/vue.md +73 -0
  75. package/dist/skills/skills/plan.md +49 -0
  76. package/dist/skills/skills/refactor.md +46 -0
  77. package/dist/skills/skills/security-scan.md +59 -0
  78. package/dist/skills/skills/test-driven.md +51 -0
  79. package/dist/skills/test-driven.md +51 -0
  80. package/dist/strategy-selector.d.ts +11 -0
  81. package/dist/strategy-selector.d.ts.map +1 -0
  82. package/dist/strategy-selector.js +85 -0
  83. package/dist/strategy-selector.js.map +1 -0
  84. package/dist/sub-agent.d.ts +3 -0
  85. package/dist/sub-agent.d.ts.map +1 -1
  86. package/dist/sub-agent.js +10 -0
  87. package/dist/sub-agent.js.map +1 -1
  88. package/dist/system-prompt.d.ts +2 -0
  89. package/dist/system-prompt.d.ts.map +1 -1
  90. package/dist/system-prompt.js +469 -94
  91. package/dist/system-prompt.js.map +1 -1
  92. package/dist/types.d.ts +3 -0
  93. package/dist/types.d.ts.map +1 -1
  94. package/dist/types.js.map +1 -1
  95. package/package.json +2 -2
@@ -0,0 +1,110 @@
1
+ ## Identity
2
+ - domain: typescript
3
+ - type: language
4
+ - confidence: 0.95
5
+
6
+ # TypeScript — Error Pattern Reference
7
+
8
+ Read the exact error code first. Each TS error has a precise meaning — do not guess from the message alone.
9
+
10
+ ## Error Code Quick Reference
11
+ - **TS2345** — Argument type mismatch. Read the function signature.
12
+ - **TS2322** — Assignment type mismatch. Read the variable declaration.
13
+ - **TS2304** — Cannot find name. Missing import or typo.
14
+ - **TS2339** — Property does not exist on type. Wrong type assumption.
15
+ - **TS2307** — Cannot find module. Missing package or wrong path.
16
+ - **TS7006** — Parameter implicitly has 'any'. Add explicit type.
17
+ - **TS2531** — Object is possibly null. Add null check.
18
+ - **TS2532** — Object is possibly undefined. Add undefined check.
19
+ - **TS2769** — No overload matches. Read all overload signatures.
20
+ - **TS1005** — Syntax error. Read the exact line and column.
21
+ - **TS2741** — Missing required properties in object literal.
22
+ - **TS2366** — Function lacks ending return statement.
23
+ - **TS2411** — Index signature incompatible.
24
+ - **TS4023** — Exported expression refers to unexported type.
25
+
26
+ ## Known Error Patterns
27
+
28
+ ### TS2345 — Wrong Argument Type
29
+ - **Symptom**: `Argument of type 'X' is not assignable to parameter of type 'Y'`
30
+ - **Cause**: Passing wrong type to function. Common cases: string where number expected, union type wider than parameter, optional field passed as required.
31
+ - **Strategy**: 1. Read the exact function signature by grepping the function name and reading its definition. 2. Identify which parameter is mismatched. 3. Fix the call site by passing the correct type or narrowing the value. Only add a type assertion if you have verified the runtime type is correct.
32
+ - **Tool sequence**: grep (function name) → file_read (definition) → file_edit (fix call site)
33
+ - **Pitfall**: Do NOT cast to `any` as a first resort. Read the actual expected type before touching the call site.
34
+
35
+ ### TS2322 — Wrong Assignment Type
36
+ - **Symptom**: `Type 'X' is not assignable to type 'Y'`
37
+ - **Cause**: Assigning a value to a variable whose declared type does not accept it. Often: number assigned to string, wider union assigned to narrower union, optional assigned to required.
38
+ - **Strategy**: 1. Find the variable declaration (grep or file_read). 2. Decide whether the declaration is wrong (widen it) or the assigned value is wrong (narrow/convert it). 3. Fix the narrower of the two.
39
+ - **Tool sequence**: grep (variable name) → file_read (declaration) → file_edit
40
+ - **Pitfall**: Do NOT widen the type to `any` or `unknown` unless the variable genuinely needs to hold arbitrary values.
41
+
42
+ ### TS2339 — Property Does Not Exist
43
+ - **Symptom**: `Property 'x' does not exist on type 'Y'`
44
+ - **Cause**: Accessing a property that is not in the type definition. Common after API response parsing, JSON.parse, or accessing a subtype's property on a base type.
45
+ - **Strategy**: 1. Grep the interface or type definition. 2. Check if the property exists but on a subtype — use type narrowing (`if ('x' in obj)` or `instanceof`). 3. If the property should exist, add it to the interface. 4. If it is conditional, make it optional (`x?: T`).
46
+ - **Tool sequence**: grep (interface name or type name) → file_read → file_edit
47
+ - **Pitfall**: Do NOT extend the interface blindly. Confirm the property actually exists at runtime before adding it to the type.
48
+
49
+ ### TS2531 / TS2532 — Possibly Null or Undefined
50
+ - **Symptom**: `Object is possibly 'null'` or `Object is possibly 'undefined'`
51
+ - **Cause**: Using a value that TypeScript knows might be null or undefined without a guard.
52
+ - **Strategy**: Add an explicit check: `if (x !== null && x !== undefined)`, or use nullish coalescing `x ?? defaultValue`, or optional chaining `x?.property`. For function returns, add a null return guard at the top.
53
+ - **Tool sequence**: file_read (lines around error) → file_edit (add null check or optional chain)
54
+ - **Pitfall**: Do NOT use the non-null assertion operator `!` unless you can read code that guarantees non-null at that exact point. Using `!` without proof creates silent runtime crashes.
55
+
56
+ ### TS2307 — Cannot Find Module
57
+ - **Symptom**: `Cannot find module './path' or its corresponding type declarations`
58
+ - **Cause**: Import path wrong, package not installed, missing `@types/` package, or tsconfig path alias not resolving.
59
+ - **Strategy**: 1. Verify the file exists at the import path using shell_exec. 2. Check tsconfig.json for path aliases that might apply. 3. Check package.json for the package. 4. If the package exists but lacks types, install `@types/<package>` or add a `.d.ts` declaration stub.
60
+ - **Tool sequence**: shell_exec (`ls <path>`) → file_read (tsconfig.json) → file_read (package.json) → shell_exec (pnpm add @types/package)
61
+ - **Pitfall**: Do NOT assume the import path is wrong — check tsconfig path aliases before renaming imports.
62
+
63
+ ### TS7006 — Implicit Any on Parameter
64
+ - **Symptom**: `Parameter 'x' implicitly has an 'any' type`
65
+ - **Cause**: Function parameter has no type annotation and TypeScript cannot infer it from context.
66
+ - **Strategy**: Read how the function is called (grep call sites) to determine what type is actually passed. Add that type as an explicit annotation. If multiple types are possible, use a union type.
67
+ - **Tool sequence**: grep (function name call sites) → file_read (definition) → file_edit (add annotation)
68
+ - **Pitfall**: Do NOT write `: any` to satisfy the compiler. Infer the real type from the call sites.
69
+
70
+ ### TS2769 — No Overload Matches
71
+ - **Symptom**: `No overload matches this call` with a list of overload candidates
72
+ - **Cause**: Calling a function with arguments that do not satisfy any of its overload signatures.
73
+ - **Strategy**: 1. Read ALL listed overload signatures in the error output. 2. Identify which argument is causing the mismatch (the error lists which overload got closest). 3. Fix the argument type or add the correct overload if you own the function.
74
+ - **Tool sequence**: file_read (error output fully) → grep (function definition) → file_read → file_edit
75
+ - **Pitfall**: Do NOT add a new overload signature as a first resort if you do not own the library. Fix the call site argument.
76
+
77
+ ### TS2741 — Missing Required Properties
78
+ - **Symptom**: `Type 'X' is missing the following properties from type 'Y': a, b, c`
79
+ - **Cause**: Object literal or variable missing required fields for the target interface.
80
+ - **Strategy**: 1. Read the target interface definition. 2. Add all missing required properties. 3. If a property should be optional, make it optional in the interface (if you own it).
81
+ - **Tool sequence**: grep (interface name) → file_read → file_edit (add missing fields)
82
+ - **Pitfall**: Do NOT make all fields optional to silence the error. Required fields exist for a reason.
83
+
84
+ ### Type Narrowing Failure
85
+ - **Symptom**: TypeScript still shows a union type inside a conditional block that should have narrowed it
86
+ - **Cause**: The narrowing condition uses a pattern TypeScript does not recognize, or a type guard function is not declared with a type predicate.
87
+ - **Strategy**: Use `typeof x === "string"`, `x instanceof ClassName`, discriminant property check (`x.kind === "foo"`), or a type predicate function `(x): x is SpecificType`. Ensure the check is directly in the condition — TypeScript does not follow complex indirect narrowing.
88
+ - **Tool sequence**: file_read (narrowing block) → file_edit (replace condition with recognized narrowing pattern)
89
+ - **Pitfall**: Do NOT use `x as SpecificType` inside the block to work around failed narrowing. Fix the condition.
90
+
91
+ ### Circular Type Reference
92
+ - **Symptom**: `Type alias 'X' circularly references itself` or extremely slow tsc
93
+ - **Cause**: Type A references Type B which references Type A directly.
94
+ - **Strategy**: Break the cycle by introducing an intermediate interface or by using `interface` instead of `type` alias (interfaces handle some recursive cases). Extract shared fields into a base interface.
95
+ - **Tool sequence**: grep (type name references) → file_read → file_edit (introduce base interface)
96
+ - **Pitfall**: Do NOT wrap in `any` to break the cycle. The circular reference usually signals a design issue.
97
+
98
+ ## Verification
99
+ Run: `tsc --noEmit`
100
+ - Exit 0 with no output = success.
101
+ - Any line starting with `error TS` = failure. The format is `file(line,col): error TSxxxx: message`.
102
+ - Always read the full error line including file path and column number before acting.
103
+
104
+ ## Validation Checklist
105
+ - [ ] `tsc --noEmit` exits 0
106
+ - [ ] No `as any` added without a comment explaining the runtime guarantee
107
+ - [ ] No non-null assertions `!` added without a comment citing the proof
108
+ - [ ] All new interfaces have required fields marked optional only if they can genuinely be absent
109
+ - [ ] No `@ts-ignore` or `@ts-expect-error` added to suppress errors without comment
110
+ - [ ] Import paths verified to exist on disk or in tsconfig aliases
@@ -0,0 +1,49 @@
1
+ ## Identity
2
+ - domain: general
3
+ - type: plan
4
+ - confidence: 0.8
5
+
6
+ # Plan — Decompose, Sequence, Risk
7
+
8
+ Break the goal into tasks that can be executed independently. The plan is wrong if any task requires knowing the output of a parallel task.
9
+
10
+ ## Workflow
11
+ 1. **Understand** — Read relevant files. Do not plan from assumptions.
12
+ 2. **Decompose** — Break goal into tasks. Each task = one logical change.
13
+ 3. **Sequence** — Order by dependencies. What must be done before what?
14
+ 4. **Assign** — Which files does each task touch? (No two tasks touch the same file.)
15
+ 5. **Risk** — What can go wrong? What is the rollback?
16
+
17
+ ## Task Format
18
+ Each task must specify:
19
+ - Goal (one sentence)
20
+ - Files to create/modify
21
+ - Dependencies (which tasks must complete first)
22
+ - Verification (how to confirm it worked)
23
+
24
+ ## Known Error Patterns
25
+
26
+ ### Over-decomposed Tasks
27
+ - **Symptom**: 20+ tasks for what should be a 3-task change
28
+ - **Cause**: Planning at line-level instead of logical-change level
29
+ - **Strategy**: Merge tasks that always change together into one task
30
+ - **Pitfall**: Do NOT create a task for each file if they are all part of one logical change.
31
+
32
+ ### Under-specified Verification
33
+ - **Symptom**: Task says "done" but it is unclear what "done" means
34
+ - **Cause**: No concrete verification step defined
35
+ - **Strategy**: Every task needs: run X command, see Y output
36
+ - **Pitfall**: Do NOT write "test it works" — write the exact command and expected output.
37
+
38
+ ### Missing Rollback
39
+ - **Symptom**: Mid-way through plan, something breaks and there is no way back
40
+ - **Cause**: No checkpoint or rollback strategy
41
+ - **Strategy**: For any plan with 4+ tasks, define a rollback point (git stash, feature flag, etc.)
42
+ - **Pitfall**: Do NOT start a multi-file refactor without a rollback strategy.
43
+
44
+ ## Validation Checklist
45
+ - [ ] Each task has a single clear goal
46
+ - [ ] No two parallel tasks modify the same file
47
+ - [ ] Dependencies between tasks are explicit
48
+ - [ ] Each task has a concrete verification step
49
+ - [ ] Rollback strategy defined for 4+ task plans
@@ -0,0 +1,46 @@
1
+ ## Identity
2
+ - domain: general
3
+ - type: refactor
4
+ - confidence: 0.85
5
+
6
+ # Refactor — Preserve Behavior, Improve Structure
7
+
8
+ Behavior must be identical before and after. Tests are your proof.
9
+
10
+ ## Workflow
11
+ 1. **Baseline** — Run test suite. All tests must pass. Record the result.
12
+ 2. **Impact map** — Grep for all usages of what you are changing. List every file.
13
+ 3. **One change** — Make one structural change at a time.
14
+ 4. **Verify** — Run tests. Must still pass.
15
+ 5. **Repeat** — Next structural change.
16
+ 6. **Commit** — Each logical refactor is its own commit.
17
+
18
+ ## Known Error Patterns
19
+
20
+ ### Partial Rename
21
+ - **Symptom**: Build error or runtime failure after renaming a function/variable
22
+ - **Cause**: Some call sites not updated
23
+ - **Strategy**: grep ALL usages before renaming. Update every occurrence.
24
+ - **Tool sequence**: grep (exact name) → file_read (each result) → file_edit (all occurrences) → shell_exec (build)
25
+ - **Pitfall**: Do NOT rename without grepping first. IDEs miss dynamic usages.
26
+
27
+ ### Changed Interface, Missed Consumers
28
+ - **Symptom**: Tests pass for the changed file, but integration tests fail
29
+ - **Cause**: Callers of the changed interface not updated
30
+ - **Strategy**: 1. grep for import of the changed module 2. Read each consumer 3. Update to new interface
31
+ - **Tool sequence**: grep (from.*moduleName, require.*moduleName) → file_read → file_edit
32
+ - **Pitfall**: Do NOT update the implementation without updating all consumers.
33
+
34
+ ### Behavior Change During Refactor
35
+ - **Symptom**: Tests that were passing now fail after "only structural" changes
36
+ - **Cause**: Subtle logic change introduced during structural refactor
37
+ - **Strategy**: 1. Stop. 2. git diff the changes. 3. Identify which line changed behavior. 4. Revert behavior, keep structure.
38
+ - **Tool sequence**: shell_exec (git diff) → file_read → file_edit (revert behavior change only)
39
+ - **Pitfall**: Do NOT proceed with failing tests. Fix the regression immediately.
40
+
41
+ ## Validation Checklist
42
+ - [ ] Test suite passes before refactor starts (baseline)
43
+ - [ ] All usages of changed symbols grepped and listed
44
+ - [ ] Test suite passes after each individual change
45
+ - [ ] No behavior changes (same inputs produce same outputs)
46
+ - [ ] Build passes
@@ -0,0 +1,59 @@
1
+ ## Identity
2
+ - domain: security
3
+ - type: scan
4
+ - confidence: 0.9
5
+
6
+ # Security Scan — OWASP Top 10 Patterns
7
+
8
+ Scan for vulnerabilities before they reach production. Each pattern below is a real-world attack vector.
9
+
10
+ ## Scan Order
11
+ 1. Injection (SQL, shell, LDAP, XML)
12
+ 2. Secrets and credentials in code
13
+ 3. Authentication and authorization gaps
14
+ 4. Insecure deserialization
15
+ 5. Sensitive data exposure
16
+
17
+ ## Known Error Patterns
18
+
19
+ ### SQL Injection
20
+ - **Symptom**: User input concatenated directly into SQL string
21
+ - **Cause**: String interpolation used instead of parameterized queries
22
+ - **Strategy**: 1. Grep for string concatenation with SQL keywords 2. Replace with parameterized queries or ORM methods
23
+ - **Tool sequence**: grep (SELECT.*+) → file_read → file_edit
24
+ - **Pitfall**: Do NOT use string replacement as a sanitization method. Use parameterized queries only.
25
+
26
+ ### Shell Injection
27
+ - **Symptom**: User input passed to shell command execution
28
+ - **Cause**: exec(userInput), shell=True with dynamic input, template string in subprocess
29
+ - **Strategy**: 1. Grep for shell=True, exec(, subprocess with dynamic args 2. Replace with argument arrays, never shell strings
30
+ - **Tool sequence**: grep (shell=True) → file_read → file_edit
31
+ - **Pitfall**: Do NOT use shell=True with any user-controlled input, ever.
32
+
33
+ ### Hardcoded Secrets
34
+ - **Symptom**: API keys, passwords, tokens in source code
35
+ - **Cause**: Developer committed credentials directly
36
+ - **Strategy**: 1. Grep for common secret patterns 2. Move to environment variables 3. Add to .gitignore
37
+ - **Tool sequence**: grep (password=, api_key=, secret=, sk-, Bearer) → file_read → file_edit
38
+ - **Pitfall**: Do NOT just delete the secret — rotate it first, then remove from code.
39
+
40
+ ### Path Traversal
41
+ - **Symptom**: User-supplied file path used without validation
42
+ - **Cause**: open(userPath), readFile(req.params.filename) without sanitization
43
+ - **Strategy**: 1. Validate path is within allowed directory 2. Use path.resolve() and check it starts with allowed base
44
+ - **Tool sequence**: grep (readFile, open(, fs.) → file_read → file_edit
45
+ - **Pitfall**: Do NOT use path.basename() alone — it does not prevent traversal through symlinks.
46
+
47
+ ### Insecure Direct Object Reference
48
+ - **Symptom**: Resource ID from request used directly without ownership check
49
+ - **Cause**: db.find({ id: req.params.id }) without checking userId matches session
50
+ - **Strategy**: Always check that the authenticated user owns the requested resource
51
+ - **Tool sequence**: grep (req.params, req.query) → file_read → file_edit
52
+ - **Pitfall**: Do NOT assume frontend-only authorization is sufficient.
53
+
54
+ ## Validation Checklist
55
+ - [ ] No user input in SQL/shell/LDAP strings
56
+ - [ ] No secrets in source code
57
+ - [ ] All file paths validated against base directory
58
+ - [ ] All resource access checks ownership
59
+ - [ ] Dependencies scanned for known vulnerabilities
@@ -0,0 +1,58 @@
1
+ ## Identity
2
+ - domain: general
3
+ - type: review
4
+ - confidence: 0.95
5
+
6
+ # Code Review — Correctness, Security, Performance
7
+
8
+ Review in priority order: Correctness → Security → Performance → Style.
9
+ Style comments without correctness/security concerns are noise.
10
+
11
+ ## Severity Levels
12
+ - **CRITICAL** — Will cause data loss, security breach, or crash in production. Must fix before merge.
13
+ - **HIGH** — Likely bug under realistic conditions. Fix before merge.
14
+ - **MEDIUM** — Potential issue under edge cases. Fix recommended.
15
+ - **LOW** — Style, readability, minor improvement. Optional.
16
+
17
+ ## Review Checklist
18
+
19
+ ### Correctness
20
+ - [ ] Does the logic match the intended behavior?
21
+ - [ ] Are all edge cases handled (null, empty, boundary)?
22
+ - [ ] Are error conditions handled or explicitly ignored?
23
+ - [ ] Are async operations awaited where needed?
24
+ - [ ] Are race conditions possible?
25
+
26
+ ### Security
27
+ - [ ] User input validated and sanitized before use?
28
+ - [ ] No string interpolation into SQL/shell/HTML?
29
+ - [ ] No secrets, API keys, or credentials in code?
30
+ - [ ] File paths validated to prevent traversal?
31
+ - [ ] Permissions checked before operations?
32
+
33
+ ### Performance
34
+ - [ ] No N+1 queries in loops?
35
+ - [ ] No unbounded operations on user-controlled input size?
36
+ - [ ] Expensive operations cached where appropriate?
37
+
38
+ ## Known Error Patterns
39
+
40
+ ### Logic Bug — Off By One
41
+ - **Symptom**: Array access, loop bounds, or range checks produce wrong results at edges
42
+ - **Cause**: < vs <=, 0 vs 1 as start index, missing last element
43
+ - **Strategy**: Test with length=0, length=1, and at-boundary inputs
44
+ - **Tool sequence**: file_read → grep (similar patterns) → file_edit
45
+ - **Pitfall**: Do NOT approve logic that was not tested at its boundaries.
46
+
47
+ ### Silent Failure
48
+ - **Symptom**: Function catches error and returns undefined/null/false without logging
49
+ - **Cause**: catch block swallows errors
50
+ - **Strategy**: Flag all catch blocks that do not log or rethrow
51
+ - **Tool sequence**: grep (catch) → file_read → comment
52
+ - **Pitfall**: Do NOT approve silent error suppression in production code paths.
53
+
54
+ ## Validation Checklist
55
+ - [ ] All CRITICAL issues flagged
56
+ - [ ] All HIGH issues flagged
57
+ - [ ] Security review completed
58
+ - [ ] Review output formatted as severity-labeled list
@@ -0,0 +1,45 @@
1
+ ## Identity
2
+ - domain: general
3
+ - type: debug
4
+ - confidence: 0.9
5
+
6
+ # Debug — Reproduce, Trace, Fix, Verify
7
+
8
+ Always reproduce the bug before touching any code. A fix you can't verify didn't happen.
9
+
10
+ ## Workflow
11
+ 1. **Reproduce** — Write a minimal script or test that triggers the bug. Run it. Confirm it fails.
12
+ 2. **Trace** — Read the error message completely. Find the deepest frame in YOUR code (not library internals). Read that file.
13
+ 3. **Localize** — Grep for the function/symbol in the error. Read 3 levels of call hierarchy.
14
+ 4. **Fix** — Smallest change that resolves the root cause. Not the symptom.
15
+ 5. **Verify** — Rerun the reproduction script. Run full test suite. Confirm no regressions.
16
+
17
+ ## Known Error Patterns
18
+
19
+ ### Fixing the Wrong Location
20
+ - **Symptom**: Fix applied, error persists or appears elsewhere
21
+ - **Cause**: Patched a caller when the bug is in the callee, or patched a copy/subclass instead of the source
22
+ - **Strategy**: 1. Grep all files containing the error pattern 2. Read the deepest implementation, not the surface call 3. Fix the source, not the symptom
23
+ - **Tool sequence**: grep → file_read (implementation) → file_edit → shell_exec (reproduce)
24
+ - **Pitfall**: Do NOT assume the first grep result is the right location. Read at least 2 candidates.
25
+
26
+ ### Same Error Repeating After Fix
27
+ - **Symptom**: Retried same fix 2+ times, error unchanged
28
+ - **Cause**: Mental model of the bug is wrong
29
+ - **Strategy**: 1. Stop retrying 2. Read the full error message again from scratch 3. Search for the exact error string in the codebase 4. Try a structurally different approach
30
+ - **Tool sequence**: grep (exact error string) → file_read → re-analyze
31
+ - **Pitfall**: Do NOT make a third attempt with the same approach. The model of the problem is broken.
32
+
33
+ ### Test Passes But Bug Persists
34
+ - **Symptom**: Test green, but reported behavior still broken
35
+ - **Cause**: Test does not cover the actual failure path
36
+ - **Strategy**: 1. Read the bug report carefully 2. Write a reproduction that exactly matches the reported flow 3. If test passes, the reproduction is wrong — fix the test first
37
+ - **Tool sequence**: file_read (test) → write_file (reproduction) → shell_exec
38
+ - **Pitfall**: Do NOT declare fixed based on passing tests alone. Run the exact reported scenario.
39
+
40
+ ## Validation Checklist
41
+ - [ ] Reproduction script confirms the bug exists before fix
42
+ - [ ] Reproduction script confirms the bug is gone after fix
43
+ - [ ] Full test suite passes (no regressions)
44
+ - [ ] Root cause addressed, not just symptom
45
+ - [ ] No unrelated code changed
@@ -0,0 +1,74 @@
1
+ ## Identity
2
+ - domain: bash
3
+ - type: language
4
+ - confidence: 0.90
5
+
6
+ # Bash/Shell — Error Pattern Reference
7
+
8
+ Always start scripts with `#!/usr/bin/env bash` and `set -euo pipefail`. Most Bash bugs are invisible without these settings. Use `shellcheck` for static analysis.
9
+
10
+ ## Quick Reference
11
+ - **exit code 127** — Command not found.
12
+ - **exit code 126** — Command found but not executable (permission issue).
13
+ - **exit code 1** — General error; check the command's stderr.
14
+ - **unbound variable** — `set -u` is active and an unset variable was used.
15
+ - **broken pipe** — Consumer of a pipeline exited before producer finished.
16
+
17
+ ## Known Error Patterns
18
+
19
+ ### Unbound Variable (set -u)
20
+ - **Symptom**: `bash: FOO: unbound variable` — script exits immediately.
21
+ - **Cause**: `set -u` (nounset) is active and a variable is referenced before being assigned. Common with optional variables, unset environment variables, or array out-of-bounds access.
22
+ - **Strategy**: 1. Identify the variable. 2. Provide a default: `${FOO:-default_value}`. Use `${FOO:-}` (empty default) if an empty string is acceptable. 3. For required variables, add an explicit check before use: `if [[ -z "${FOO:-}" ]]; then echo "FOO is required" >&2; exit 1; fi`.
23
+ - **Tool sequence**: file_read (script lines around error) → file_edit (add `${VAR:-default}` or explicit check)
24
+ - **Pitfall**: Do NOT remove `set -u` to silence the error. The unbound variable is the real bug.
25
+
26
+ ### Word Splitting on Unquoted Variable
27
+ - **Symptom**: Script fails or behaves wrong when a variable contains spaces or glob characters. A filename like `my file.txt` becomes two arguments.
28
+ - **Cause**: Unquoted variable expansion in Bash: `$var` undergoes word splitting and pathname expansion. `"$var"` does not.
29
+ - **Strategy**: 1. Quote all variable expansions: `"$var"`, `"$@"`, `"${array[@]}"`. 2. Run `shellcheck <script>` — it flags all unquoted variables. 3. For arrays, always use `"${arr[@]}"` not `${arr[*]}`.
30
+ - **Tool sequence**: shell_exec (`shellcheck <script>`) → file_read (flagged lines) → file_edit (add quotes)
31
+ - **Pitfall**: Do NOT use single quotes `'$var'` — that prevents expansion entirely. Use double quotes `"$var"`.
32
+
33
+ ### Missing pipefail (set -eo pipefail)
34
+ - **Symptom**: Script reports success even when a command in a pipeline fails. E.g., `false | tee output.txt` exits 0 without `pipefail`.
35
+ - **Cause**: Without `set -o pipefail`, a pipeline's exit code is only the last command's exit code. Failures in earlier pipeline stages are silently ignored.
36
+ - **Strategy**: 1. Add `set -euo pipefail` at the top of every script (after the shebang). 2. For individual pipelines where partial failure is expected, use `set +o pipefail` around that block and restore it after.
37
+ - **Tool sequence**: file_read (top of script) → file_edit (add `set -euo pipefail` after shebang)
38
+ - **Pitfall**: `set -e` alone is not enough for pipelines. Always pair it with `set -o pipefail`.
39
+
40
+ ### Command Not Found in PATH
41
+ - **Symptom**: `command not found: foo` — exit code 127.
42
+ - **Cause**: The command is not in any directory listed in `$PATH`. Common when running scripts as a different user (cron, sudo), in Docker containers with minimal PATH, or when a tool is installed in a non-standard location.
43
+ - **Strategy**: 1. Run `which foo` or `type foo` to verify presence in the current shell. 2. For cron and CI, always use absolute paths: `/usr/bin/foo` or `/usr/local/bin/foo`. 3. If the tool is optional, check before use: `if ! command -v foo &>/dev/null; then echo "foo not installed" >&2; exit 1; fi`. 4. Source the correct profile/environment if the tool is installed via a version manager (nvm, rbenv, pyenv).
44
+ - **Tool sequence**: shell_exec (`which foo`) → shell_exec (`echo $PATH`) → file_edit (use absolute path or add PATH setup)
45
+ - **Pitfall**: Do NOT hardcode `/usr/bin/foo` if the tool may be in `/usr/local/bin` on some systems. Use `command -v` to find it dynamically when portability matters.
46
+
47
+ ### Wrong or Missing Shebang
48
+ - **Symptom**: Script runs with the wrong interpreter (e.g., `sh` instead of `bash`), causing `[[`, arrays, or `local` to fail with syntax errors. Or: permission denied / bad interpreter.
49
+ - **Cause**: Shebang (`#!`) is missing, wrong (`#!/bin/sh` when bashisms are used), or the path is wrong for the target system.
50
+ - **Strategy**: 1. Use `#!/usr/bin/env bash` for portability — `env` finds bash in PATH. 2. Use `#!/bin/sh` only if the script is strictly POSIX sh. 3. If using `[[`, arrays, `local`, `$((...))`, `declare`, or `source`, the shebang must be `bash`. 4. Ensure the file has execute permission: `chmod +x script.sh`.
51
+ - **Tool sequence**: file_read (first line of script) → file_edit (fix shebang) → shell_exec (`chmod +x`)
52
+ - **Pitfall**: On some systems (Alpine Linux, minimal Docker), `/bin/bash` does not exist. Use `#!/usr/bin/env bash` instead.
53
+
54
+ ### Arithmetic — Unintended Glob Expansion
55
+ - **Symptom**: Script exits unexpectedly, or `*` in an expression matches files instead of meaning multiplication.
56
+ - **Cause**: In `[[ ]]` or `$(( ))`, operators like `*`, `?`, `[` have special meanings. Outside these contexts they trigger pathname expansion.
57
+ - **Strategy**: 1. Always use `$(( expr ))` for arithmetic, never `expr` or `let` in new scripts. 2. Quote file patterns that should be treated as literals. 3. Use `[[ ]]` instead of `[ ]` for conditionals — `[[ ]]` does not perform pathname or word splitting.
58
+ - **Tool sequence**: file_read (expression line) → file_edit (replace `[ ]` with `[[ ]]`, wrap arithmetic in `$(( ))`)
59
+ - **Pitfall**: `(( ))` arithmetic returns exit code 1 when the result is 0, which triggers `set -e`. Use `(( expr )) || true` or wrap in an `if`.
60
+
61
+ ## Verification
62
+ Run: `shellcheck <script>` — address all SC#### warnings before deployment.
63
+ - For syntax check only: `bash -n <script>`.
64
+ - Test with edge-case inputs: empty strings, paths with spaces, special characters.
65
+
66
+ ## Validation Checklist
67
+ - [ ] `#!/usr/bin/env bash` on first line
68
+ - [ ] `set -euo pipefail` on second line
69
+ - [ ] `shellcheck` reports zero warnings
70
+ - [ ] All variable expansions quoted: `"$var"`, `"${arr[@]}"`
71
+ - [ ] All external commands referenced by absolute path in cron/CI contexts
72
+ - [ ] `command -v` used to check optional tools before use
73
+ - [ ] No `[ ]` — replaced with `[[ ]]` for conditionals
74
+ - [ ] Arithmetic done in `$(( ))` not with `expr`
@@ -0,0 +1,76 @@
1
+ ## Identity
2
+ - domain: c
3
+ - type: language
4
+ - confidence: 0.93
5
+
6
+ # C — Error Pattern Reference
7
+
8
+ Compile with warnings enabled: `-Wall -Wextra -Werror`. Many C bugs are silent at compile time but fatal at runtime. Always use a sanitizer (`-fsanitize=address,undefined`) during development.
9
+
10
+ ## Compiler Warning Quick Reference
11
+ - **-Wimplicit-function-declaration** — Calling a function without a prototype.
12
+ - **-Wuninitialized** — Variable used before assignment.
13
+ - **-Wformat** — printf/scanf format string mismatch.
14
+ - **-Wreturn-type** — Missing return in non-void function.
15
+ - **-Warray-bounds** — Array index out of declared bounds (static analysis only).
16
+ - **-Wconversion** — Implicit narrowing conversion.
17
+ - **-Wnull-dereference** — Pointer that may be NULL is dereferenced.
18
+
19
+ ## Known Error Patterns
20
+
21
+ ### Segmentation Fault — Null Pointer Dereference
22
+ - **Symptom**: Program crashes with `Segmentation fault (core dumped)`. GDB shows crash at a pointer dereference.
23
+ - **Cause**: Dereferencing a pointer that is NULL, uninitialized, or has been freed. Common after `malloc` failure (returns NULL), a function returning NULL on error, or using a pointer before assignment.
24
+ - **Strategy**: 1. Run under GDB: `gdb ./program core` then `bt` for backtrace. 2. Identify the faulting line. 3. Add a NULL check before every pointer dereference. 4. For `malloc`: always check `if (ptr == NULL) { /* handle */ }` immediately after allocation. 5. Run with AddressSanitizer: `gcc -fsanitize=address -g` for detailed diagnostics.
25
+ - **Tool sequence**: shell_exec (`gcc -g -fsanitize=address`) → shell_exec (run program) → file_read (faulting line) → file_edit (add NULL check)
26
+ - **Pitfall**: Do NOT assume `malloc` always succeeds. Check the return value every time.
27
+
28
+ ### Buffer Overflow — strcpy / gets / sprintf
29
+ - **Symptom**: Program writes garbage data, crashes unpredictably, or behaves differently between debug and release builds. ASan reports `heap-buffer-overflow` or `stack-buffer-overflow`.
30
+ - **Cause**: `strcpy`, `gets`, `sprintf`, or manual loop writes beyond the allocated buffer. `gets` has no length argument and is inherently unsafe.
31
+ - **Strategy**: 1. Replace `gets` with `fgets(buf, sizeof(buf), stdin)`. 2. Replace `strcpy(dst, src)` with `strncpy(dst, src, sizeof(dst) - 1); dst[sizeof(dst)-1] = '\0';` or use `strlcpy` if available. 3. Replace `sprintf` with `snprintf(buf, sizeof(buf), fmt, ...)`. 4. Audit every buffer write in the file for bound checks.
32
+ - **Tool sequence**: grep (`strcpy\|gets\|sprintf`) → file_read → file_edit (replace with safe variants)
33
+ - **Pitfall**: `strncpy` does NOT null-terminate if the source is longer than n. Always manually set `dst[n-1] = '\0'`.
34
+
35
+ ### Memory Leak — malloc Without free
36
+ - **Symptom**: Program memory usage grows unboundedly. Valgrind reports `definitely lost` or `indirectly lost` blocks.
37
+ - **Cause**: Memory allocated with `malloc`/`calloc`/`realloc` is not freed on all code paths, especially error paths.
38
+ - **Strategy**: 1. Run with Valgrind: `valgrind --leak-check=full ./program`. 2. For each allocation, trace all code paths and confirm `free` is called. 3. Use a consistent pattern: allocate near the start of a scope, free at the end via a cleanup label (`goto cleanup`). 4. Ensure error paths also reach the cleanup label.
39
+ - **Tool sequence**: shell_exec (`valgrind --leak-check=full`) → grep (`malloc\|calloc`) → file_read (all exit paths) → file_edit (add free on all paths)
40
+ - **Pitfall**: Do NOT free a pointer and then use it. Set it to NULL after freeing: `free(p); p = NULL;`.
41
+
42
+ ### Undefined Behavior — Signed Integer Overflow
43
+ - **Symptom**: Unexpected values or crashes only in optimized builds (`-O2`). UBSan reports `signed integer overflow`.
44
+ - **Cause**: Signed integer overflow is undefined behavior in C. Compilers exploit this for optimization, leading to code elimination or wrong values. Common in loop counters, hash functions, and arithmetic.
45
+ - **Strategy**: 1. Compile with `-fsanitize=undefined` to detect overflows. 2. For arithmetic that may overflow, use unsigned types or check before the operation: `if (a > INT_MAX - b) { /* overflow */ }`. 3. Do NOT rely on signed wrap-around behavior.
46
+ - **Tool sequence**: shell_exec (`gcc -fsanitize=undefined -g`) → file_read (arithmetic code) → file_edit (add overflow check or use unsigned)
47
+ - **Pitfall**: Do NOT use `(int)(a + b)` cast to suppress the warning. The overflow happens before the cast.
48
+
49
+ ### Implicit Function Declaration
50
+ - **Symptom**: Compiler warning: `implicit declaration of function 'foo'`; in C99 and later this is an error.
51
+ - **Cause**: Calling a function before its prototype is declared. Missing `#include` for a library function, or a function defined later in the file without a forward declaration.
52
+ - **Strategy**: 1. For standard library functions, identify and add the correct `#include`. 2. For project-internal functions, add a forward declaration at the top of the file or move the definition above the call site. 3. Always compile with `-Wimplicit-function-declaration -Werror`.
53
+ - **Tool sequence**: grep (`#include`) → file_read (function call line) → shell_exec (`man <function>` for required header) → file_edit (add include or forward declaration)
54
+ - **Pitfall**: Do NOT add an implicit `int` return type declaration manually — add the full correct prototype.
55
+
56
+ ### Use of Uninitialized Variable
57
+ - **Symptom**: Garbage values read, random behavior, or UBSan reports `use of uninitialized value`.
58
+ - **Cause**: Local variable declared but not assigned before first read. Conditional initialization that misses a code path.
59
+ - **Strategy**: 1. Compile with `-Wuninitialized`. 2. Initialize all local variables at declaration: `int count = 0;`, `char *p = NULL;`. 3. For structs, use `= {0}` to zero-initialize: `struct Foo f = {0};`.
60
+ - **Tool sequence**: shell_exec (`gcc -Wall -Wuninitialized`) → file_read (variable declaration) → file_edit (add initializer)
61
+ - **Pitfall**: Do NOT rely on global/static variables being zero-initialized to justify skipping local initialization. Be explicit.
62
+
63
+ ## Verification
64
+ Compile command: `gcc -Wall -Wextra -Werror -g -fsanitize=address,undefined -o program main.c`
65
+ - Fix all warnings before proceeding — `-Werror` enforces this.
66
+ - Run Valgrind for memory checks in CI: `valgrind --error-exitcode=1 ./program`
67
+
68
+ ## Validation Checklist
69
+ - [ ] `gcc -Wall -Wextra -Werror` produces zero warnings
70
+ - [ ] Every `malloc`/`calloc`/`realloc` return value checked for NULL
71
+ - [ ] Every `free` followed by setting pointer to NULL
72
+ - [ ] No `gets`, `strcpy`, or unbounded `sprintf` in codebase
73
+ - [ ] All local variables initialized at declaration
74
+ - [ ] No signed integer arithmetic that can overflow without a guard
75
+ - [ ] All functions declared before first use (via include or forward declaration)
76
+ - [ ] Tested with `-fsanitize=address,undefined` during development
@@ -0,0 +1,75 @@
1
+ ## Identity
2
+ - domain: cpp
3
+ - type: language
4
+ - confidence: 0.93
5
+
6
+ # C++ — Error Pattern Reference
7
+
8
+ Compile with `-Wall -Wextra -Werror -std=c++17` (or `c++20`). Use sanitizers (`-fsanitize=address,undefined`) and run under Valgrind. Prefer RAII and smart pointers to manual memory management.
9
+
10
+ ## Compiler Warning Quick Reference
11
+ - **-Wdelete-non-virtual-dtor** — Deleting through base pointer without virtual destructor.
12
+ - **-Wunused-variable / -Wunused-parameter** — Declared but never used.
13
+ - **-Wreorder** — Member initializer order does not match declaration order.
14
+ - **-Wshadow** — Local variable shadows outer scope variable.
15
+ - **-Wreturn-type** — Non-void function missing return.
16
+ - **-Wnull-dereference** — Pointer that may be null is dereferenced.
17
+
18
+ ## Known Error Patterns
19
+
20
+ ### Use-After-Free — Dangling Pointer
21
+ - **Symptom**: ASan reports `heap-use-after-free`. Program crashes with random values or corrupt behavior.
22
+ - **Cause**: A raw pointer is used after `delete` (or `delete[]`) has been called on it. Common after ownership transfer without setting the old pointer to `nullptr`, or returning a reference to a local variable.
23
+ - **Strategy**: 1. Run with ASan: `g++ -fsanitize=address -g`. 2. Identify the delete and the subsequent access. 3. After deleting a raw pointer, set it to `nullptr`. 4. Prefer `std::unique_ptr` or `std::shared_ptr` — they prevent use-after-free by tying lifetime to scope. 5. Never return a reference or pointer to a local variable.
24
+ - **Tool sequence**: shell_exec (`g++ -fsanitize=address -g && ./program`) → file_read (reported lines) → file_edit (replace raw pointer with smart pointer or add nullptr assignment)
25
+ - **Pitfall**: Do NOT check `if (ptr != nullptr)` after use-after-free — once freed, the pointer is invalid even if not null.
26
+
27
+ ### Double Free
28
+ - **Symptom**: ASan reports `double-free`. `glibc` detected "double free or corruption". Crash in heap management code.
29
+ - **Cause**: `delete` or `free` called twice on the same pointer. Happens when multiple owners hold raw pointers to the same allocation, or a copy constructor/assignment is missing (Rule of Three/Five).
30
+ - **Strategy**: 1. Grep for `delete` and `free` on the affected pointer. 2. Ensure only one owner calls delete. 3. Use `std::unique_ptr` to enforce single ownership. 4. If a class manages memory, implement the Rule of Five (destructor, copy ctor, copy assign, move ctor, move assign) or use `= delete` for copy.
31
+ - **Tool sequence**: grep (`delete\|free`) → file_read (class definition) → file_edit (add Rule of Five or use smart pointer)
32
+ - **Pitfall**: Setting pointer to `nullptr` after delete prevents double-free on the same pointer variable, but does NOT help if the pointer was copied first.
33
+
34
+ ### ODR Violation — Multiple Definitions
35
+ - **Symptom**: Linker error: `multiple definition of 'foo'`; or subtle wrong-behavior bugs with no error (when violations occur across translation units with different definitions).
36
+ - **Cause**: A function or non-inline variable defined (not just declared) in a header file that is included in multiple translation units. Or the same name defined twice in different `.cpp` files.
37
+ - **Strategy**: 1. For functions defined in headers, mark them `inline` or move the definition to a `.cpp` file. 2. For variables in headers, use `inline` variable (C++17): `inline int g_count = 0;` or declare `extern` in header and define in one `.cpp`. 3. For templates, definitions in headers are allowed and do not violate ODR as long as they are identical.
38
+ - **Tool sequence**: grep (function/variable name across headers) → file_read → file_edit (add `inline` or move to .cpp)
39
+ - **Pitfall**: Do NOT add `static` to a header function to suppress the linker error — this gives each TU its own copy, which is a different bug.
40
+
41
+ ### std::vector Iterator Invalidation
42
+ - **Symptom**: Crash or undefined behavior after modifying a `std::vector` while iterating it. Sanitizers may report heap-use-after-free.
43
+ - **Cause**: `push_back`, `insert`, `erase`, or `resize` may reallocate the vector's internal buffer, invalidating all iterators, references, and pointers into the vector. Continuing to use old iterators causes UB.
44
+ - **Strategy**: 1. Identify any modification to the vector inside a loop that iterates it. 2. For `erase`: use the erase-remove idiom or capture the returned iterator: `it = vec.erase(it)`. 3. For `push_back` during iteration: collect new elements in a separate vector and append after the loop. 4. If indices are used instead of iterators, re-read the index from the start after mutation.
45
+ - **Tool sequence**: grep (`push_back\|erase\|insert`) → file_read (enclosing loop) → file_edit (fix iteration pattern)
46
+ - **Pitfall**: Do NOT cache `vec.end()` before a loop that modifies the vector — recompute it or use index-based iteration.
47
+
48
+ ### Template Instantiation Error
49
+ - **Symptom**: Long compiler error message starting with "note: required from here" with a chain of template instantiations. The actual error is at the bottom of the chain.
50
+ - **Cause**: A template is instantiated with a type that does not satisfy the template's requirements (missing method, wrong type, etc.). Concept violations (C++20) or SFINAE failures.
51
+ - **Strategy**: 1. Read the error from the BOTTOM UP — the root cause is at the last "error:" line. 2. Identify the type being substituted. 3. Check what operations the template body performs on `T` and confirm the substituted type supports them. 4. In C++20, use concepts to get clearer error messages.
52
+ - **Tool sequence**: file_read (full error output, bottom first) → grep (template definition) → file_read → file_edit (constrain template or fix calling type)
53
+ - **Pitfall**: Do NOT add template specializations to paper over a type mismatch. Fix the type or add proper constraints.
54
+
55
+ ### Missing Virtual Destructor
56
+ - **Symptom**: Valgrind reports memory leaks for derived class members. Objects deleted through base pointer only partially destroy the object.
57
+ - **Cause**: A base class with virtual methods lacks a virtual destructor. Deleting a derived object through a base pointer calls only the base destructor, skipping derived class cleanup.
58
+ - **Strategy**: 1. Grep all base classes (classes with virtual methods). 2. Check if they have `virtual ~ClassName() = default;` or a defined virtual destructor. 3. Add it if missing.
59
+ - **Tool sequence**: grep (`virtual`) → file_read (class definitions) → file_edit (add `virtual ~ClassName() = default;`)
60
+ - **Pitfall**: Do NOT make a class non-polymorphic just to avoid the destructor — if it has any virtual methods, it needs a virtual destructor.
61
+
62
+ ## Verification
63
+ Compile: `g++ -std=c++17 -Wall -Wextra -Werror -g -fsanitize=address,undefined -o program *.cpp`
64
+ - Run Valgrind in CI: `valgrind --error-exitcode=1 --leak-check=full ./program`
65
+ - For large projects: integrate with `clang-tidy` and `cppcheck`.
66
+
67
+ ## Validation Checklist
68
+ - [ ] All base classes with virtual methods have a virtual destructor
69
+ - [ ] No raw `new`/`delete` — prefer `std::make_unique`/`std::make_shared`
70
+ - [ ] No iterator or pointer used after vector/container modification
71
+ - [ ] No function or variable defined (not declared) in a header without `inline`
72
+ - [ ] Rule of Five implemented for any class that manages a resource
73
+ - [ ] Template errors read from bottom up before attempting a fix
74
+ - [ ] `-fsanitize=address,undefined` run during development
75
+ - [ ] No dangling references returned from functions (local variable reference)