@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,74 @@
1
+ ## Identity
2
+ - domain: swift
3
+ - type: language
4
+ - confidence: 0.95
5
+
6
+ # Swift — Error Pattern Reference
7
+
8
+ Read the full Xcode error and the associated `note:` context. Swift's compiler is strict but its error messages are detailed — the fix is usually contained in the output.
9
+
10
+ ## Error Code Quick Reference
11
+ - **Fatal error: Unexpectedly found nil while unwrapping an Optional value** — force unwrap `!` on nil.
12
+ - **Value of optional type 'X?' must be unwrapped** — optional used where non-optional expected.
13
+ - **Type 'X' does not conform to protocol 'Y'** — missing protocol requirement.
14
+ - **Sendable warning** — non-Sendable type crossing actor/concurrency boundary.
15
+ - **Expression is 'async' but is not marked with 'await'** — async call without await.
16
+ - **Call to main actor-isolated method in synchronous context** — @MainActor violation.
17
+ - **Capture of 'x' with non-sendable type** — Swift 6 strict concurrency violation.
18
+ - **Retain cycle** — strong reference cycle causing memory leak (detected in Instruments).
19
+
20
+ ## Known Error Patterns
21
+
22
+ ### Pattern: force unwrap crash (! on nil Optional)
23
+
24
+ - **symptom**: `Fatal error: Unexpectedly found nil while unwrapping an Optional value` at a line with `!`
25
+ - **cause**: The `!` force-unwrap operator is used on an `Optional` that is `nil` at runtime. Common sources: IBOutlet not connected, storyboard/nib loading timing, JSON parsing, optional chaining bypassed, `as!` cast failure.
26
+ - **strategy**: 1. Find every `!` at or near the crashing line. 2. Replace force unwrap with safe alternatives: `if let x = optional { }`, `guard let x = optional else { return }`, or `optional ?? defaultValue`. 3. For `as!` casts, use `as?` with a guard: `guard let view = obj as? UIView else { return }`. 4. For IBOutlets, verify the outlet is connected in the storyboard (open IB, check the connection inspector). 5. Use `XCTUnwrap` in tests instead of `!`.
27
+ - **toolSequence**: file_read (crashing line + surrounding context) → grep (`!` usage near the line) → file_edit (replace `!` with guard let or if let)
28
+ - **pitfall**: Do NOT replace `!` with `?` and silently ignore nil — use `guard let` to fail explicitly with context when nil is unexpected.
29
+
30
+ ### Pattern: protocol conformance missing
31
+
32
+ - **symptom**: `Type 'MyClass' does not conform to protocol 'Equatable'` (or `Codable`, `Hashable`, `Identifiable`, etc.)
33
+ - **cause**: A type used in a context requiring a protocol does not implement all required methods/properties. Common for `Equatable` (needs `==`), `Hashable` (needs `hash(into:)`), `Codable` (needs `encode`/`init(from:)` for non-synthesizable types).
34
+ - **strategy**: 1. Read the protocol requirement in the error. 2. For `Equatable`/`Hashable`/`Codable` with simple stored properties, add the protocol to the declaration — Swift synthesizes conformance automatically if all properties conform. 3. For types with custom logic or non-conforming properties, implement the required methods manually. 4. For `Identifiable`, add `var id: SomeHashable { }` property. 5. Use an extension to add conformance cleanly.
35
+ - **toolSequence**: grep (protocol name + requirements) → file_read (type definition) → file_edit (add protocol conformance or implement requirements)
36
+ - **pitfall**: Do NOT add `@unchecked Sendable` to dismiss protocol warnings without verifying thread safety manually.
37
+
38
+ ### Pattern: Sendable warning (concurrency)
39
+
40
+ - **symptom**: `Sending 'x' risks causing data races` or `Type 'Foo' does not conform to 'Sendable'` — Swift 6 strict concurrency or Xcode 15+ warnings
41
+ - **cause**: A value of non-Sendable type is passed across actor boundaries (e.g., from background Task to @MainActor). Swift's concurrency model requires types crossing isolation boundaries to be Sendable (value types or thread-safe classes).
42
+ - **strategy**: 1. Identify the type causing the warning. 2. If it is a struct with value-type properties, it is automatically Sendable — no action needed (compiler should infer). 3. If it is a class, make it `final` and ensure all mutable state is protected by a lock or actor, then add `Sendable` conformance. 4. Use `@MainActor` on types that should always run on main thread. 5. For data flowing into async tasks, capture immutable copies: `let snapshot = mutableData` before the `Task { }`. 6. As a last resort for third-party types, use `@unchecked Sendable` with a `// THREAD-SAFE: reason` comment.
43
+ - **toolSequence**: file_read (type crossing boundary) → file_edit (make Sendable or capture immutable copy before Task)
44
+ - **pitfall**: Do NOT use `@unchecked Sendable` without a comment proving thread safety — it suppresses the warning but not data races.
45
+
46
+ ### Pattern: memory retain cycle (weak/unowned)
47
+
48
+ - **symptom**: Memory grows unboundedly; objects not released after dismissal. Instruments Leaks shows a cycle. Common in closures capturing `self`, delegates, and notification observers.
49
+ - **cause**: Object A holds a strong reference to object B, which holds a strong reference back to A. ARC cannot release either. Common in: closure capturing `self` strongly, delegate properties not marked `weak`, NotificationCenter observers not removed, Timer targets.
50
+ - **strategy**: 1. In closures that reference `self`, use `[weak self]` capture: `{ [weak self] in guard let self else { return } ... }`. 2. Delegate properties: declare as `weak var delegate: MyDelegate?`. 3. NotificationCenter: store the observer token and remove it in `deinit`. 4. Timer: use `[weak self]` in the timer block and invalidate in `deinit`. 5. Use `[unowned self]` only when the closure's lifetime is strictly shorter than `self` — prefer `weak` when in doubt.
51
+ - **toolSequence**: grep (`self\.`) in closure bodies → file_read → file_edit (add `[weak self]` capture list)
52
+ - **pitfall**: Do NOT use `unowned` as a performance optimization for convenience — if the assumption is wrong and `self` is nil when the closure runs, it is an immediate crash.
53
+
54
+ ### Pattern: @MainActor isolation error
55
+
56
+ - **symptom**: `Call to main actor-isolated instance method 'updateUI()' in a synchronous nonisolated context` or `Expression is 'async' but is not marked with 'await'`
57
+ - **cause**: A `@MainActor`-isolated method is called from a non-isolated context (background task, async function without actor annotation). Swift 5.7+ enforces actor isolation at compile time.
58
+ - **strategy**: 1. Identify the caller context — is it inside a `Task`, `DispatchQueue.global()` block, or plain function? 2. Wrap the `@MainActor` call in `await MainActor.run { }` when inside an async context. 3. Mark the calling function `@MainActor` if it logically belongs to the main thread. 4. Use `Task { @MainActor in ... }` to dispatch UI work. 5. For legacy code with `DispatchQueue.main.async`, migrate to `Task { @MainActor in }` for consistency with Swift Concurrency.
59
+ - **toolSequence**: file_read (calling function) → file_edit (add `await MainActor.run { }` or `@MainActor` annotation)
60
+ - **pitfall**: Do NOT use `DispatchQueue.main.async` to bypass `@MainActor` errors in new code — it defeats Swift's compile-time isolation checks and can still cause data races.
61
+
62
+ ## Verification
63
+ Run: `xcodebuild -scheme <scheme> build` or `swift build`
64
+ - For warnings as errors: `xcodebuild -scheme <scheme> build SWIFT_TREAT_WARNINGS_AS_ERRORS=YES`
65
+ - For tests: `xcodebuild test -scheme <scheme>`
66
+
67
+ ## Validation Checklist
68
+ - [ ] No force unwrap `!` without a `// SAFE: reason` comment proving non-nil
69
+ - [ ] All closures capturing `self` use `[weak self]` unless lifetime is provably shorter
70
+ - [ ] Delegate properties declared as `weak var`
71
+ - [ ] NotificationCenter observers removed in `deinit`
72
+ - [ ] `@MainActor` isolation errors resolved with `await MainActor.run` or actor annotation
73
+ - [ ] Sendable violations resolved without `@unchecked Sendable` unless thread safety is documented
74
+ - [ ] `xcodebuild build` exits 0 with no errors
@@ -0,0 +1,80 @@
1
+ ## Identity
2
+ - domain: terraform
3
+ - type: language
4
+ - confidence: 0.90
5
+
6
+ # Terraform — Error Pattern Reference
7
+
8
+ Read the full error message including the resource address and provider error detail. Terraform errors are often split across a plan error and an apply error — both matter.
9
+
10
+ ## Error Code Quick Reference
11
+ - **"Error: Error acquiring the state lock"** — Another operation holds the state lock.
12
+ - **"Error: Reference to undeclared resource"** — Resource name typo or not yet defined.
13
+ - **"Error: Provider configuration not present"** — Provider block missing or alias mismatch.
14
+ - **"Error: Unsupported argument"** — Attribute not valid for the resource type/version.
15
+ - **"Error: Cycle"** — Circular dependency between resources.
16
+ - **"Error: Invalid value for variable"** — Variable validation constraint failed.
17
+ - **"Warning: Deprecated attribute"** — Attribute removed in newer provider version.
18
+ - **"Error: Backend configuration changed"** — Backend config changed without `terraform init -reconfigure`.
19
+
20
+ ## Known Error Patterns
21
+
22
+ ### State Lock Timeout — Backend Locking
23
+ - **Symptom**: `Error: Error acquiring the state lock` with a lock ID and holder info; plan/apply hangs indefinitely.
24
+ - **Cause**: A previous `terraform apply` or `plan` was interrupted (Ctrl-C, CI timeout, crash) without releasing the state lock. The backend (S3+DynamoDB, GCS, Terraform Cloud) still holds the lock from the dead operation.
25
+ - **Strategy**: 1. Read the error output fully — it includes the lock ID and the operation that holds it. 2. Verify that no legitimate Terraform operation is running (check CI jobs, team members). 3. If confirmed stale, force-unlock: `terraform force-unlock <LOCK_ID>`. 4. For DynamoDB-backed state, you can also delete the lock item directly via AWS Console as a last resort. 5. Prevent future stale locks: use CI jobs with proper timeout handling and signal trapping.
26
+ - **Tool sequence**: shell_exec (`terraform force-unlock <ID>`) → shell_exec (`terraform plan` to verify state is clean)
27
+ - **Pitfall**: Do NOT force-unlock while another legitimate apply is running — you will corrupt the state. Confirm no other operations are active first.
28
+
29
+ ### Plan/Apply Diff Surprise — lifecycle ignore_changes
30
+ - **Symptom**: `terraform plan` shows unexpected changes to a resource that was not modified in code; resource would be destroyed and recreated on every apply.
31
+ - **Cause**: External systems (autoscalers, deployment tools, human edits) modified attributes that Terraform tracks. Without `lifecycle { ignore_changes = [...] }`, Terraform wants to revert these changes. Alternatively, a `for_each` or `count` index change can cause full resource replacement.
32
+ - **Strategy**: 1. Run `terraform plan -out=tfplan` and read the diff carefully — identify which attribute is changing. 2. If the attribute is legitimately managed externally (e.g., `desired_count` on an ECS service managed by an autoscaler), add `lifecycle { ignore_changes = [desired_count] }`. 3. If it is a `for_each` index issue, check that the map keys are stable identifiers, not positional indices. 4. Never use `ignore_changes = all` — it makes Terraform blind to all drift.
33
+ - **Tool sequence**: shell_exec (`terraform plan`) → file_read (resource definition) → file_edit (add lifecycle ignore_changes for specific attributes)
34
+ - **Pitfall**: Do NOT add `ignore_changes` reflexively to stop a noisy plan — understand WHY the attribute is drifting and fix the root cause if it is your code making the unintended change.
35
+
36
+ ### Provider Version Constraint Missing — Breaking Changes
37
+ - **Symptom**: `terraform init` installs a newer provider version that removes or renames attributes; existing configurations break after `terraform init -upgrade`.
38
+ - **Cause**: `required_providers` block either has no version constraint or uses `~>` incorrectly, allowing major version upgrades that introduce breaking changes.
39
+ - **Strategy**: 1. Read the `required_providers` block in `versions.tf` or the root module. 2. Pin to a compatible version range: `version = "~> 5.0"` (allows 5.x but not 6.0). 3. Review provider changelogs when intentionally upgrading. 4. Commit the `.terraform.lock.hcl` file to version control — it pins exact provider versions for reproducible builds. 5. Use `terraform providers lock` to regenerate the lock file after intentional upgrades.
40
+ - **Tool sequence**: file_read (versions.tf) → file_edit (add or tighten version constraints) → shell_exec (`terraform init`) → shell_exec (git add .terraform.lock.hcl)
41
+ - **Pitfall**: Do NOT delete `.terraform.lock.hcl` to "fix" provider issues — it is a security and reproducibility artifact. Regenerate it properly with `terraform providers lock`.
42
+
43
+ ### Sensitive Value in Output — Secret Exposure
44
+ - **Symptom**: `terraform output` prints database passwords, API keys, or private keys in plaintext; CI logs expose secrets; state file contains secrets in plaintext.
45
+ - **Cause**: An `output` block exposes a sensitive resource attribute (e.g., `aws_db_instance.password`, `tls_private_key.private_key_pem`) without `sensitive = true`. Even with `sensitive = true`, the value is still stored in plaintext in the Terraform state file.
46
+ - **Strategy**: 1. Grep all `output` blocks for sensitive attributes. 2. Add `sensitive = true` to outputs that expose secrets — this prevents them from printing in logs. 3. Audit the state backend: ensure state storage (S3 bucket, GCS bucket) has encryption at rest and access logging enabled. 4. For truly sensitive values, use a secrets manager (AWS Secrets Manager, HashiCorp Vault) instead of outputting them via Terraform. 5. Never commit state files to version control.
47
+ - **Tool sequence**: grep (`output "`) → file_read → file_edit (add sensitive = true) → shell_exec (verify state backend encryption config)
48
+ - **Pitfall**: Do NOT think `sensitive = true` removes the secret from state — it only hides it in plan/apply output. The state file still contains it in plaintext.
49
+
50
+ ### Circular Dependency Between Resources
51
+ - **Symptom**: `Error: Cycle: <resource_a> → <resource_b> → <resource_a>`; Terraform cannot determine apply order.
52
+ - **Cause**: Resource A references an attribute of Resource B (creating A→B dependency), and Resource B references an attribute of Resource A (creating B→A dependency). This can happen through `depends_on`, data source references, or implicit attribute references.
53
+ - **Strategy**: 1. Read the error — Terraform prints the full cycle chain. 2. Map out WHY each reference exists. 3. Break the cycle by: (a) extracting a shared resource that both depend on, (b) using a `null_resource` or `terraform_data` with `triggers` to decouple, (c) restructuring so one resource passes a value that does not itself depend on the other. 4. Avoid using `depends_on` on entire modules — use it only on specific resources.
54
+ - **Tool sequence**: file_read (both resource definitions) → grep (cross-references between them) → file_edit (extract shared resource or remove circular reference)
55
+ - **Pitfall**: Do NOT use `depends_on = []` to remove declared dependencies without understanding what ordering those dependencies enforced — you may create race conditions in provisioning.
56
+
57
+ ### Resource Replaced on Rename — State Orphan
58
+ - **Symptom**: `terraform plan` shows a resource being destroyed and a new one created when you only renamed it in code; infrastructure is unnecessarily replaced.
59
+ - **Cause**: Terraform tracks resources by their address (type + name). Renaming `aws_s3_bucket.old_name` to `aws_s3_bucket.new_name` looks like a deletion + creation.
60
+ - **Strategy**: 1. Use `terraform state mv <old_address> <new_address>` to rename the resource in state without destroying it. 2. Then update the `.tf` file with the new name. 3. Run `terraform plan` — it should show no changes. 4. For module renames, use `terraform state mv module.old module.new`.
61
+ - **Tool sequence**: shell_exec (`terraform state list`) → shell_exec (`terraform state mv <old> <new>`) → file_edit (rename in .tf) → shell_exec (`terraform plan`)
62
+ - **Pitfall**: Do NOT apply before running `terraform state mv` — the apply will destroy existing infrastructure to "create" the renamed resource.
63
+
64
+ ## Verification
65
+ Run: `terraform validate` then `terraform plan`
66
+ - `terraform validate` must exit 0 with "Success! The configuration is valid."
67
+ - `terraform plan` should show only the expected changes — read every `+`, `-`, and `~` carefully.
68
+ - Run `tflint` for additional style and provider-specific checks.
69
+
70
+ ## Validation Checklist
71
+ - [ ] `required_providers` has version constraints for all providers
72
+ - [ ] `.terraform.lock.hcl` is committed to version control
73
+ - [ ] All sensitive outputs have `sensitive = true`
74
+ - [ ] No secrets stored in `.tfvars` files committed to version control
75
+ - [ ] State backend uses encrypted storage with access logging
76
+ - [ ] `terraform validate` exits 0
77
+ - [ ] No `depends_on = [<entire_module>]` without justification
78
+ - [ ] All `lifecycle` blocks are justified with a comment explaining why
79
+ - [ ] Resource names use stable identifiers (not positional indices) in `for_each`
80
+ - [ ] `tflint` passes with no errors
@@ -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,80 @@
1
+ ## Identity
2
+ - domain: verilog
3
+ - type: language
4
+ - confidence: 0.88
5
+
6
+ # Verilog/SystemVerilog — Error Pattern Reference
7
+
8
+ Read the exact synthesis or simulation tool message including the file, line, and severity level. HDL errors split into simulation errors (behavioral bugs) and synthesis errors (hardware mapping failures) — both must be resolved separately.
9
+
10
+ ## Error Code Quick Reference
11
+ - **"Multiple drivers on net 'x'"** — Wire driven from more than one always block or assignment.
12
+ - **"Latch inferred for 'x'"** — Incomplete sensitivity list or missing else/default branch.
13
+ - **"Sensitivity list may not be complete"** — Missing signal in always block sensitivity.
14
+ - **"Width mismatch in assignment"** — Left and right side bit widths differ.
15
+ - **"Undefined variable 'x'"** — Wire/reg not declared before use.
16
+ - **"Non-blocking assignment in combinational logic"** — `<=` used in `always @(*)` block.
17
+ - **"Blocking assignment in sequential logic"** — `=` used in `always @(posedge clk)` block.
18
+ - **"Undeclared port in module instantiation"** — Port name not found in the module definition.
19
+
20
+ ## Known Error Patterns
21
+
22
+ ### Blocking vs Non-Blocking Assignment — always Block Confusion
23
+ - **Symptom**: Simulation produces correct results but synthesis behavior differs; waveforms show immediate vs delayed value updates; Synopsys/Vivado warns about mixed assignment types.
24
+ - **Cause**: In `always @(posedge clk)` (sequential/flip-flop) blocks, non-blocking assignments (`<=`) should be used — they model register behavior with all updates applied simultaneously at the end of the time step. In `always @(*)` (combinational) blocks, blocking assignments (`=`) should be used — they model wire behavior with immediate evaluation. Mixing them causes simulation-synthesis mismatch.
25
+ - **Strategy**: 1. Grep all `always @(posedge` blocks and verify every assignment uses `<=`. 2. Grep all `always @(*)` blocks and verify every assignment uses `=`. 3. Never mix `=` and `<=` in the same `always` block. 4. For `always @(posedge clk or posedge rst)` reset blocks, use `<=` for both the reset assignment and the normal operation.
26
+ - **Tool sequence**: grep (`always @(posedge`, `always @(*`, `always @\(`) → file_read → file_edit (fix assignment operators)
27
+ - **Pitfall**: Do NOT use blocking assignments in sequential logic to "optimize" simulation speed — it causes race conditions in simulation and simulation-synthesis mismatch that only appears on real hardware.
28
+
29
+ ### Multiple Drivers on Wire — Synthesis Error
30
+ - **Symptom**: `Error: Multiple drivers on net 'bus_data'`; tool refuses to synthesize; simulation shows X (unknown) values on the wire.
31
+ - **Cause**: In Verilog, a `wire` can only have one driver. If two `always` blocks both assign to the same `wire` or `reg`, or if two module instantiations both drive the same net, the result is undefined. Common in bus architectures where multiple modules share a data bus.
32
+ - **Strategy**: 1. Grep the signal name to find all assignment locations (`assign`, `always` blocks, module output ports). 2. For bus sharing, use a mux: only one driver is active at a time based on a select signal. 3. For tri-state buses, use `wire` with `assign bus = enable ? data : 1'bz`. 4. For `reg` types, ensure only one `always` block drives each register. 5. Use SystemVerilog `logic` type which provides better error detection for multiple drivers.
33
+ - **Tool sequence**: grep (signal name across all files) → file_read → file_edit (add mux or tri-state logic, remove duplicate drivers)
34
+ - **Pitfall**: Do NOT use `wire` with multiple `assign` statements hoping the synthesis tool will "figure it out" — multiple drivers on a wire is a hardware short circuit.
35
+
36
+ ### Latch Inferred — Incomplete Case or Missing Else
37
+ - **Symptom**: Synthesis warning `Latch inferred for signal 'x' in process`; FPGA resource usage shows unexpected latches instead of flip-flops; behavior differs between simulation and synthesis.
38
+ - **Cause**: In combinational `always @(*)` blocks, if not all possible input combinations assign a value to an output, the synthesizer infers a latch to "hold" the previous value. This happens with: incomplete `if-else` (missing `else`), incomplete `case` (missing `default`), or a signal only assigned in some branches.
39
+ - **Strategy**: 1. Grep all `always @(*)` blocks. 2. For every `if` statement, ensure there is a matching `else` that assigns all outputs. 3. For every `case` statement, ensure there is a `default` branch that assigns all outputs. 4. As a defensive pattern, assign default values to all outputs at the top of the combinational block before the `if`/`case`, then override in branches. 5. If a latch is intentionally needed, use a `reg` in a sequential block instead.
40
+ - **Tool sequence**: grep (`always @(\*)`) → file_read → file_edit (add default assignments at top or add else/default branch)
41
+ - **Pitfall**: Do NOT suppress latch inference warnings — latches are timing hazards and usually indicate a bug. Investigate every latch warning.
42
+
43
+ ### Clock Domain Crossing Metastability
44
+ - **Symptom**: Intermittent failures only on actual FPGA hardware; simulation passes; timing analysis shows paths crossing clock domains; MTBF (mean time between failures) calculation fails.
45
+ - **Cause**: Signals passing from one clock domain to another can arrive at a flip-flop near its setup/hold time window. The flip-flop enters a metastable state that randomly resolves to 0 or 1. A single flip-flop synchronizer does not provide sufficient metastability resolution time.
46
+ - **Strategy**: 1. Identify all signals that cross clock domains — look for signals driven in one `always @(posedge clk_a)` block and read in another `always @(posedge clk_b)` block. 2. For single-bit signals, use a 2-flip-flop synchronizer: two cascaded FFs in the destination clock domain. 3. For multi-bit data, use a FIFO with separate read/write clock ports (Gray code counter or vendor-provided async FIFO). 4. For control signals, use handshake protocols (req/ack). 5. Use CDC analysis tools (Synopsys SpyGlass, Cadence JasperGold CDC).
47
+ - **Tool sequence**: grep (signals used across multiple clock domains) → file_read → file_edit (add synchronizer FFs or async FIFO)
48
+ - **Pitfall**: Do NOT use a simple `assign` to cross clock domains — even a single combinational wire crossing clock domains is a CDC violation that will cause intermittent failures.
49
+
50
+ ### Simulation vs Synthesis Mismatch — Initial Blocks and Delays
51
+ - **Symptom**: Simulation shows correct behavior with `#delay` timing; synthesis produces incorrect functionality; `initial` block values don't reflect on FPGA startup.
52
+ - **Cause**: (1) `#delay` timing constructs are ignored by synthesis tools — they are simulation-only. (2) `initial` blocks are not synthesizable in most target technologies (exception: FPGA block RAMs with initial values). (3) Simulation starts with `x` values which combine operations may mask; synthesis optimizes based on don't-care.
53
+ - **Strategy**: 1. Grep all `#` delay statements — remove them from synthesizable RTL and document they are testbench-only constructs. 2. Grep all `initial` blocks — if they are in RTL (not testbench), replace register initialization with a reset signal. 3. Use synchronous reset `always @(posedge clk) if (rst) out <= 0;` instead of `initial begin out = 0; end`. 4. Maintain separate testbench files (`*_tb.v`) with clear naming to avoid mixing simulation and RTL constructs.
54
+ - **Tool sequence**: grep (`#[0-9]`, `initial begin`) → file_read → file_edit (remove #delays, replace initial with reset logic)
55
+ - **Pitfall**: Do NOT use `#1` delays in RTL to "fix" simulation race conditions — the correct fix is proper use of non-blocking assignments, not delays.
56
+
57
+ ### Width Mismatch — Truncation or Zero-Extension Bug
58
+ - **Symptom**: Tool warns `Width mismatch: assigning 32-bit value to 8-bit net`; runtime shows truncated or zero-extended values; arithmetic produces unexpected results.
59
+ - **Cause**: Verilog implicitly truncates or zero-extends values when widths don't match. Assigning a 32-bit result to an 8-bit register silently discards the upper 24 bits. Integer literals default to 32 bits.
60
+ - **Strategy**: 1. Enable all synthesis and simulation warnings — treat width mismatch warnings as errors. 2. Explicitly size all literals: `8'd255` not `255`. 3. Use explicit width casts: `result[7:0]` to select specific bits. 4. For addition with carry, declare the result one bit wider than the operands: `wire [8:0] sum = {1'b0, a} + {1'b0, b}; wire carry = sum[8];`. 5. Use SystemVerilog `logic [N-1:0]` with explicit width declarations everywhere.
61
+ - **Tool sequence**: file_read (signals and assignments) → file_edit (add explicit bit widths to literals and widen result registers)
62
+ - **Pitfall**: Do NOT treat implicit truncation as intentional bit selection — use explicit `[N-1:0]` slice notation to document intent.
63
+
64
+ ## Verification
65
+ Run simulation: `vvp a.out` (Icarus) or ModelSim `vsim`
66
+ - All assertions must pass; waveform matches expected behavior.
67
+ - Run synthesis: Vivado `synth_design` or Quartus — zero errors, zero latch warnings.
68
+ - Run static timing analysis (STA) — all timing paths must meet constraints (WNS > 0).
69
+
70
+ ## Validation Checklist
71
+ - [ ] All `always @(posedge clk)` blocks use non-blocking assignments (`<=`)
72
+ - [ ] All `always @(*)` blocks use blocking assignments (`=`)
73
+ - [ ] No `#delay` constructs in RTL (only in testbenches)
74
+ - [ ] No `initial` blocks in synthesizable RTL (use reset logic instead)
75
+ - [ ] All `case` statements have a `default` branch
76
+ - [ ] All `if` statements have a matching `else` branch (or default assignment at block top)
77
+ - [ ] No multiple drivers on any single net
78
+ - [ ] All CDC paths use 2-FF synchronizers or async FIFOs
79
+ - [ ] All signal widths explicitly declared — no implicit width mismatches
80
+ - [ ] Synthesis timing analysis passes with positive WNS on all critical paths
@@ -0,0 +1,73 @@
1
+ ## Identity
2
+ - domain: vue
3
+ - type: language
4
+ - confidence: 0.92
5
+
6
+ # Vue.js — Error Pattern Reference
7
+
8
+ Read the full Vue warning in the browser console. Vue warnings include the component name and the exact issue. Options API and Composition API have different error patterns — identify which is in use first.
9
+
10
+ ## Quick Reference
11
+ - **[Vue warn]: Property or method "x" is not defined** — Options API scope issue.
12
+ - **[Vue warn]: Missing required prop** — Parent did not pass a required prop.
13
+ - **[Vue warn]: Extraneous non-emits event listeners** — Event name mismatch between `$emit` and `emits`.
14
+ - **[Vue warn]: Component emitted event "x" but it is not declared** — Add to `emits` option.
15
+ - **[Vue warn]: Failed to mount component** — Template or render error during initial mount.
16
+
17
+ ## Known Error Patterns
18
+
19
+ ### Property or Method Not Defined on Instance
20
+ - **Symptom**: `[Vue warn]: Property or method "foo" is not defined on the instance but referenced during render.`
21
+ - **Cause**: In Options API, a property used in the template is not declared in `data()`, `computed`, `methods`, or `props`. Common causes: typo in property name, forgetting to add to `data()`, using a local variable instead of reactive data.
22
+ - **Strategy**: 1. Read the component's `data()` function and `methods` object. 2. Verify the property name matches exactly (case-sensitive). 3. If the property should be reactive, add it to `data()` with an initial value. 4. If it is a computed value, add it to `computed`. 5. If it is read-only input, add it to `props`.
23
+ - **Tool sequence**: file_read (component data/methods) → grep (property name in template) → file_edit (add to data or methods)
24
+ - **Pitfall**: Do NOT add a property directly to `this` outside of `data()` (e.g., in `created`). Vue 2 cannot make it reactive retroactively; use `this.$set` or declare it in `data()` with an initial value.
25
+
26
+ ### Reactive Data Mutation — Direct Array Index Set
27
+ - **Symptom**: Array is modified but the UI does not update. No Vue warning. `console.log` shows the correct value.
28
+ - **Cause**: In Vue 2, direct index assignment (`this.items[0] = newValue`) and `length` mutation are not reactive. Vue 2's reactivity cannot track these. In Vue 3, `reactive()` arrays do support index assignment, but replacing a `ref`'d array element requires reassignment.
29
+ - **Strategy**: Vue 2: Use `this.$set(this.items, 0, newValue)` or `this.items.splice(0, 1, newValue)`. Vue 3 with `reactive`: direct assignment works. Vue 3 with `ref`: replace the whole array `items.value = [...items.value.slice(0, 0), newValue, ...items.value.slice(1)]` or use splice on `items.value`.
30
+ - **Tool sequence**: file_read (mutation code) → file_edit (replace index assignment with $set/splice or reassignment)
31
+ - **Pitfall**: Do NOT use `Vue.set` in Vue 3 — it does not exist. Only needed in Vue 2.
32
+
33
+ ### v-for Without :key
34
+ - **Symptom**: `[Vue warn]: Elements in iteration expect to have a 'v-key' directive`. List re-renders incorrectly: items swap, animations are wrong, component state is misattributed.
35
+ - **Cause**: `v-for` without a unique `:key` forces Vue to use positional diffing, which is incorrect when the list can be reordered, filtered, or have items added/removed.
36
+ - **Strategy**: 1. Add `:key` to every `v-for` element with a stable, unique identifier from the data (e.g., `:key="item.id"`). 2. Do NOT use the loop index as key when items can be reordered or deleted. 3. Use index as key only for truly static lists that never change order.
37
+ - **Tool sequence**: grep (`v-for`) → file_read (template) → file_edit (add `:key="item.id"`)
38
+ - **Pitfall**: Do NOT use `Math.random()` as a key — it regenerates on every render, destroying component state.
39
+
40
+ ### Composition API Reactive Destructure Loss
41
+ - **Symptom**: Destructured value from `reactive()` is not reactive — does not update when the original object changes.
42
+ - **Cause**: `const { foo } = reactive({ foo: 1 })` creates a plain (non-reactive) copy of the value. Reactivity requires keeping the reference to the reactive object.
43
+ - **Strategy**: 1. Use `toRefs()` to preserve reactivity when destructuring: `const { foo } = toRefs(state)`. Then access as `foo.value`. 2. Alternatively, do not destructure — access as `state.foo` throughout. 3. For Composable return values, always return `toRefs(state)` or individual `ref`s so callers can destructure safely.
44
+ - **Tool sequence**: grep (`reactive`) → file_read (destructure site) → file_edit (wrap in `toRefs` or access via object)
45
+ - **Pitfall**: `toRef(state, 'foo')` creates a single ref linked to one property. Use `toRefs(state)` to convert the whole object.
46
+
47
+ ### async setup Without Suspense
48
+ - **Symptom**: Component renders blank or throws. Parent shows no loading state. Vue warning: `async setup() is used without a parent <Suspense>`.
49
+ - **Cause**: In Vue 3, a component with `async setup()` (or `await` at the top level of `<script setup>`) must be wrapped by a `<Suspense>` component. Without it, async setup is not awaited before render.
50
+ - **Strategy**: 1. Wrap the async component with `<Suspense>` in the parent: `<Suspense><AsyncComponent /></Suspense>`. 2. Provide a `#fallback` slot for the loading state. 3. If Suspense is not suitable, move async data fetching to `onMounted` and manage loading state with a `ref<boolean>`.
51
+ - **Tool sequence**: file_read (async component) → file_read (parent template) → file_edit (add Suspense wrapper or move await to onMounted)
52
+ - **Pitfall**: Do NOT silence the warning by removing `async` from `setup` — this breaks the `await`. Fix by adding Suspense or refactoring to `onMounted`.
53
+
54
+ ### Watchers Not Triggering on Nested Object Change
55
+ - **Symptom**: `watch` callback does not fire when a nested property of a reactive object changes.
56
+ - **Cause**: By default, `watch` in Vue 3 is not deep. It only detects top-level reference changes. Mutating a nested property does not trigger the watcher.
57
+ - **Strategy**: 1. Add `{ deep: true }` to the watch options: `watch(state, callback, { deep: true })`. 2. Alternatively, watch the specific nested property: `watch(() => state.nested.value, callback)`. 3. The targeted approach (option 2) is preferred for performance.
58
+ - **Tool sequence**: file_read (watch definition) → file_edit (add `{ deep: true }` or narrow watch target)
59
+ - **Pitfall**: `{ deep: true }` traverses the entire object tree on every change. Use targeted watches for deeply nested or large objects.
60
+
61
+ ## Verification
62
+ Run: `vue-tsc --noEmit` (if using TypeScript with Vue), or `vite build` for full compilation.
63
+ - Browser console must show zero `[Vue warn]` messages in development.
64
+
65
+ ## Validation Checklist
66
+ - [ ] All `v-for` elements have `:key` bound to a stable unique ID (not index for dynamic lists)
67
+ - [ ] All reactive data mutations use Vue-compatible methods (not index assignment in Vue 2)
68
+ - [ ] All `reactive()` destructures use `toRefs()`
69
+ - [ ] All `async setup()` components are wrapped in `<Suspense>`
70
+ - [ ] Vue console shows zero `[Vue warn]` messages in development build
71
+ - [ ] Watchers on nested object properties use `{ deep: true }` or targeted arrow function
72
+ - [ ] `emits` option declared for all events emitted by the component
73
+ - [ ] `props` declared with types and required flag for all parent-to-child data
@@ -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