prism-pr 1.0.0-alpha.65 → 1.0.0-alpha.67

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 (221) hide show
  1. package/README.md +339 -120
  2. package/bin/run.js +16 -16
  3. package/dist/ai/adapters/model-provider-llm-adapter.d.ts +21 -0
  4. package/dist/ai/adapters/model-provider-llm-adapter.d.ts.map +1 -0
  5. package/dist/ai/adapters/model-provider-llm-adapter.js +58 -0
  6. package/dist/ai/adapters/model-provider-llm-adapter.js.map +1 -0
  7. package/dist/ai/agents/prompts/architecture-reviewer.txt +39 -39
  8. package/dist/ai/agents/prompts/config-reviewer.txt +47 -47
  9. package/dist/ai/agents/prompts/csharp-reviewer.txt +39 -39
  10. package/dist/ai/agents/prompts/css-reviewer.txt +41 -41
  11. package/dist/ai/agents/prompts/html-reviewer.txt +43 -43
  12. package/dist/ai/agents/prompts/performance-reviewer.txt +38 -38
  13. package/dist/ai/agents/prompts/security-reviewer.txt +36 -36
  14. package/dist/ai/agents/prompts/sql-reviewer.txt +43 -43
  15. package/dist/ai/agents/prompts/testing-reviewer.txt +38 -38
  16. package/dist/ai/agents/prompts/ux-text-reviewer.txt +68 -68
  17. package/dist/ai/providers/anthropic-provider.js +1 -1
  18. package/dist/ai/providers/anthropic-provider.js.map +1 -1
  19. package/dist/commands/guard/check.d.ts +3 -0
  20. package/dist/commands/guard/check.d.ts.map +1 -1
  21. package/dist/commands/guard/check.js +205 -24
  22. package/dist/commands/guard/check.js.map +1 -1
  23. package/dist/commands/review/start.d.ts +1 -0
  24. package/dist/commands/review/start.d.ts.map +1 -1
  25. package/dist/commands/review/start.js +38 -3
  26. package/dist/commands/review/start.js.map +1 -1
  27. package/dist/commands/rules/bootstrap.d.ts.map +1 -1
  28. package/dist/commands/rules/bootstrap.js +33 -0
  29. package/dist/commands/rules/bootstrap.js.map +1 -1
  30. package/dist/commands/rules/push.d.ts.map +1 -1
  31. package/dist/commands/rules/push.js +1 -1
  32. package/dist/commands/rules/push.js.map +1 -1
  33. package/dist/commands/rules/sync.d.ts.map +1 -1
  34. package/dist/commands/rules/sync.js +1 -1
  35. package/dist/commands/rules/sync.js.map +1 -1
  36. package/dist/config/config-manager.js +1 -1
  37. package/dist/config/config-manager.js.map +1 -1
  38. package/dist/core/review-workflow.d.ts +2 -0
  39. package/dist/core/review-workflow.d.ts.map +1 -1
  40. package/dist/core/review-workflow.js.map +1 -1
  41. package/dist/core/workflow-engine.d.ts +2 -0
  42. package/dist/core/workflow-engine.d.ts.map +1 -1
  43. package/dist/core/workflow-engine.js +2 -0
  44. package/dist/core/workflow-engine.js.map +1 -1
  45. package/dist/guard/auto-bootstrap.d.ts +18 -0
  46. package/dist/guard/auto-bootstrap.d.ts.map +1 -0
  47. package/dist/guard/auto-bootstrap.js +19 -0
  48. package/dist/guard/auto-bootstrap.js.map +1 -0
  49. package/dist/guard/feedback-service.d.ts +34 -0
  50. package/dist/guard/feedback-service.d.ts.map +1 -0
  51. package/dist/guard/feedback-service.js +82 -0
  52. package/dist/guard/feedback-service.js.map +1 -0
  53. package/dist/guard/guard-match-aggregator.d.ts +16 -0
  54. package/dist/guard/guard-match-aggregator.d.ts.map +1 -0
  55. package/dist/guard/guard-match-aggregator.js +79 -0
  56. package/dist/guard/guard-match-aggregator.js.map +1 -0
  57. package/dist/guard/patterns-loader.js +1 -1
  58. package/dist/guard/patterns-loader.js.map +1 -1
  59. package/dist/guard/review-findings-aggregator.d.ts +38 -0
  60. package/dist/guard/review-findings-aggregator.d.ts.map +1 -0
  61. package/dist/guard/review-findings-aggregator.js +114 -0
  62. package/dist/guard/review-findings-aggregator.js.map +1 -0
  63. package/dist/guard/types.d.ts +1 -1
  64. package/dist/guard/types.d.ts.map +1 -1
  65. package/dist/persistence/database.js +4 -4
  66. package/dist/persistence/migrations/0001_phase3a_schema.sql +15 -15
  67. package/dist/persistence/migrations/0004_review_memory.sql +24 -24
  68. package/dist/persistence/migrations/0005_pattern_feedback.sql +16 -0
  69. package/dist/persistence/migrations/20260401141055_peaceful_blur/migration.sql +66 -66
  70. package/dist/persistence/migrations/20260401141055_peaceful_blur/snapshot.json +467 -467
  71. package/dist/persistence/migrations/meta/0000_snapshot.json +467 -467
  72. package/dist/persistence/migrations/meta/_journal.json +7 -0
  73. package/dist/persistence/pattern-feedback-repository.d.ts +59 -0
  74. package/dist/persistence/pattern-feedback-repository.d.ts.map +1 -0
  75. package/dist/persistence/pattern-feedback-repository.js +116 -0
  76. package/dist/persistence/pattern-feedback-repository.js.map +1 -0
  77. package/dist/persistence/schema.d.ts +199 -0
  78. package/dist/persistence/schema.d.ts.map +1 -1
  79. package/dist/persistence/schema.js +17 -0
  80. package/dist/persistence/schema.js.map +1 -1
  81. package/dist/rule-catalog/ag-grid/base.d.ts.map +1 -1
  82. package/dist/rule-catalog/ag-grid/base.js +1 -0
  83. package/dist/rule-catalog/ag-grid/base.js.map +1 -1
  84. package/dist/rule-catalog/ag-grid/v32.d.ts.map +1 -1
  85. package/dist/rule-catalog/ag-grid/v32.js +1 -0
  86. package/dist/rule-catalog/ag-grid/v32.js.map +1 -1
  87. package/dist/rule-catalog/angular/base.d.ts.map +1 -1
  88. package/dist/rule-catalog/angular/base.js +1 -0
  89. package/dist/rule-catalog/angular/base.js.map +1 -1
  90. package/dist/rule-catalog/angular/v17.d.ts.map +1 -1
  91. package/dist/rule-catalog/angular/v17.js +1 -0
  92. package/dist/rule-catalog/angular/v17.js.map +1 -1
  93. package/dist/rule-catalog/nestjs/base.d.ts.map +1 -1
  94. package/dist/rule-catalog/nestjs/base.js +1 -0
  95. package/dist/rule-catalog/nestjs/base.js.map +1 -1
  96. package/dist/rule-catalog/react/base.d.ts.map +1 -1
  97. package/dist/rule-catalog/react/base.js +1 -0
  98. package/dist/rule-catalog/react/base.js.map +1 -1
  99. package/dist/rule-catalog/shared/general.d.ts.map +1 -1
  100. package/dist/rule-catalog/shared/general.js +1 -0
  101. package/dist/rule-catalog/shared/general.js.map +1 -1
  102. package/dist/rule-catalog/shared/security.d.ts.map +1 -1
  103. package/dist/rule-catalog/shared/security.js +1 -0
  104. package/dist/rule-catalog/shared/security.js.map +1 -1
  105. package/dist/rule-catalog/shared/typescript.d.ts.map +1 -1
  106. package/dist/rule-catalog/shared/typescript.js +1 -0
  107. package/dist/rule-catalog/shared/typescript.js.map +1 -1
  108. package/dist/rule-catalog/types.d.ts +1 -0
  109. package/dist/rule-catalog/types.d.ts.map +1 -1
  110. package/dist/rules-engine/pattern-generator.d.ts +22 -1
  111. package/dist/rules-engine/pattern-generator.d.ts.map +1 -1
  112. package/dist/rules-engine/pattern-generator.js +26 -8
  113. package/dist/rules-engine/pattern-generator.js.map +1 -1
  114. package/dist/rules-repo/constants.d.ts +14 -0
  115. package/dist/rules-repo/constants.d.ts.map +1 -0
  116. package/dist/rules-repo/constants.js +16 -0
  117. package/dist/rules-repo/constants.js.map +1 -0
  118. package/dist/rules-repo/manifest-refresh.d.ts +45 -0
  119. package/dist/rules-repo/manifest-refresh.d.ts.map +1 -0
  120. package/dist/rules-repo/manifest-refresh.js +123 -0
  121. package/dist/rules-repo/manifest-refresh.js.map +1 -0
  122. package/dist/rules-repo/manifest-resolver.d.ts +2 -1
  123. package/dist/rules-repo/manifest-resolver.d.ts.map +1 -1
  124. package/dist/rules-repo/manifest-resolver.js +8 -5
  125. package/dist/rules-repo/manifest-resolver.js.map +1 -1
  126. package/dist/rules-repo/manifest-types.d.ts +41 -1
  127. package/dist/rules-repo/manifest-types.d.ts.map +1 -1
  128. package/dist/rules-repo/manifest-types.js +26 -1
  129. package/dist/rules-repo/manifest-types.js.map +1 -1
  130. package/dist/rules-repo/rules-cache.d.ts +13 -1
  131. package/dist/rules-repo/rules-cache.d.ts.map +1 -1
  132. package/dist/rules-repo/rules-cache.js +75 -0
  133. package/dist/rules-repo/rules-cache.js.map +1 -1
  134. package/dist/rules-repo/rules-repo-client.d.ts +33 -2
  135. package/dist/rules-repo/rules-repo-client.d.ts.map +1 -1
  136. package/dist/rules-repo/rules-repo-client.js +127 -3
  137. package/dist/rules-repo/rules-repo-client.js.map +1 -1
  138. package/dist/rules-repo/types.d.ts +3 -0
  139. package/dist/rules-repo/types.d.ts.map +1 -1
  140. package/dist/rules-repo/types.js.map +1 -1
  141. package/dist/tui/components/app-header.js +2 -2
  142. package/dist/tui/components/searchable-list.d.ts +2 -1
  143. package/dist/tui/components/searchable-list.d.ts.map +1 -1
  144. package/dist/tui/components/searchable-list.js +3 -1
  145. package/dist/tui/components/searchable-list.js.map +1 -1
  146. package/dist/tui/deps-context.d.ts +6 -0
  147. package/dist/tui/deps-context.d.ts.map +1 -1
  148. package/dist/tui/deps-context.js.map +1 -1
  149. package/dist/tui/hooks/use-session.d.ts +4 -4
  150. package/dist/tui/hooks/use-suggest-rules.d.ts +30 -0
  151. package/dist/tui/hooks/use-suggest-rules.d.ts.map +1 -0
  152. package/dist/tui/hooks/use-suggest-rules.js +81 -0
  153. package/dist/tui/hooks/use-suggest-rules.js.map +1 -0
  154. package/dist/tui/screen-router.d.ts.map +1 -1
  155. package/dist/tui/screen-router.js +6 -0
  156. package/dist/tui/screen-router.js.map +1 -1
  157. package/dist/tui/screens/bootstrap-running.d.ts +3 -0
  158. package/dist/tui/screens/bootstrap-running.d.ts.map +1 -0
  159. package/dist/tui/screens/bootstrap-running.js +180 -0
  160. package/dist/tui/screens/bootstrap-running.js.map +1 -0
  161. package/dist/tui/screens/finding-detail.d.ts.map +1 -1
  162. package/dist/tui/screens/finding-detail.js +17 -0
  163. package/dist/tui/screens/finding-detail.js.map +1 -1
  164. package/dist/tui/screens/findings-list.d.ts.map +1 -1
  165. package/dist/tui/screens/findings-list.js +28 -2
  166. package/dist/tui/screens/findings-list.js.map +1 -1
  167. package/dist/tui/screens/guard-detail.d.ts.map +1 -1
  168. package/dist/tui/screens/guard-detail.js +48 -4
  169. package/dist/tui/screens/guard-detail.js.map +1 -1
  170. package/dist/tui/screens/guard-home.d.ts.map +1 -1
  171. package/dist/tui/screens/guard-home.js +28 -8
  172. package/dist/tui/screens/guard-home.js.map +1 -1
  173. package/dist/tui/screens/guard-results.d.ts.map +1 -1
  174. package/dist/tui/screens/guard-results.js +133 -4
  175. package/dist/tui/screens/guard-results.js.map +1 -1
  176. package/dist/tui/screens/guard-running.d.ts.map +1 -1
  177. package/dist/tui/screens/guard-running.js +116 -5
  178. package/dist/tui/screens/guard-running.js.map +1 -1
  179. package/dist/tui/screens/home.d.ts.map +1 -1
  180. package/dist/tui/screens/home.js +27 -2
  181. package/dist/tui/screens/home.js.map +1 -1
  182. package/dist/tui/screens/repo-select.d.ts.map +1 -1
  183. package/dist/tui/screens/repo-select.js +3 -0
  184. package/dist/tui/screens/repo-select.js.map +1 -1
  185. package/dist/tui/screens/review-running.js +1 -1
  186. package/dist/tui/screens/review-running.js.map +1 -1
  187. package/dist/tui/screens/rule-suggestions.d.ts +3 -0
  188. package/dist/tui/screens/rule-suggestions.d.ts.map +1 -0
  189. package/dist/tui/screens/rule-suggestions.js +107 -0
  190. package/dist/tui/screens/rule-suggestions.js.map +1 -0
  191. package/dist/tui/state/router-reducer.d.ts +1 -1
  192. package/dist/tui/state/router-reducer.d.ts.map +1 -1
  193. package/dist/tui/state/router-reducer.js.map +1 -1
  194. package/dist/tui/state/tui-reducer.d.ts +66 -3
  195. package/dist/tui/state/tui-reducer.d.ts.map +1 -1
  196. package/dist/tui/state/tui-reducer.js +98 -0
  197. package/dist/tui/state/tui-reducer.js.map +1 -1
  198. package/dist/tui/types/bootstrap-options.d.ts +10 -0
  199. package/dist/tui/types/bootstrap-options.d.ts.map +1 -0
  200. package/dist/tui/types/bootstrap-options.js +19 -0
  201. package/dist/tui/types/bootstrap-options.js.map +1 -0
  202. package/dist/tui/types/guard-options.d.ts +17 -0
  203. package/dist/tui/types/guard-options.d.ts.map +1 -0
  204. package/dist/tui/types/guard-options.js +36 -0
  205. package/dist/tui/types/guard-options.js.map +1 -0
  206. package/dist/types/repo-config.d.ts +8 -8
  207. package/oclif.manifest.json +28 -3
  208. package/package.json +118 -96
  209. package/dist/memory/engram-client.d.ts +0 -15
  210. package/dist/memory/engram-client.d.ts.map +0 -1
  211. package/dist/memory/engram-client.js +0 -167
  212. package/dist/memory/engram-client.js.map +0 -1
  213. package/dist/persistence/migrations/0000_peaceful_blur.sql +0 -66
  214. package/dist/tui/components/status-bar.d.ts +0 -10
  215. package/dist/tui/components/status-bar.d.ts.map +0 -1
  216. package/dist/tui/components/status-bar.js +0 -7
  217. package/dist/tui/components/status-bar.js.map +0 -1
  218. package/dist/types/engram.d.ts +0 -29
  219. package/dist/types/engram.d.ts.map +0 -1
  220. package/dist/types/engram.js +0 -2
  221. package/dist/types/engram.js.map +0 -1
package/README.md CHANGED
@@ -1,120 +1,339 @@
1
- # PRISM-PR
2
-
3
- Intelligent Pull Request review orchestrator for Bitbucket. AI-powered code review with pattern-based pre-checks using ast-grep structural matching.
4
-
5
- ## Install
6
-
7
- ```bash
8
- npm i -g prism-pr
9
- ```
10
-
11
- ## Setup
12
-
13
- ```bash
14
- # Login with your Bitbucket app password
15
- prism login
16
- ```
17
-
18
- Your Bitbucket app password needs these permissions:
19
- - Repositories: **Read** + **Write**
20
- - Pull requests: **Read**
21
-
22
- ## Guard — Instant PR Pattern Check
23
-
24
- Guard checks your PR against learned patterns from past reviews. Zero LLM calls, under 2 seconds.
25
-
26
- ### Check a PR (CLI)
27
-
28
- ```bash
29
- # Basic check
30
- prism guard check -w <workspace> -r <repo> -p <pr-id> --verbose
31
-
32
- # Filter by severity
33
- prism guard check -w <workspace> -r <repo> -p <pr-id> --min-severity high --verbose
34
-
35
- # JSON output (for CI/CD)
36
- prism guard check -w <workspace> -r <repo> -p <pr-id> --json
37
-
38
- # Use remote rules (shared team patterns)
39
- prism guard check -w <workspace> -r <repo> -p <pr-id> --remote --verbose
40
- ```
41
-
42
- ### Interactive TUI
43
-
44
- ```bash
45
- prism guard
46
- ```
47
-
48
- Launches the full interactive experience: select workspace, repo, PR, and browse results with keyboard navigation.
49
-
50
- ### Exit codes
51
-
52
- - `0` — No matches found (all clear)
53
- - `1` — Matches found
54
-
55
- Use in CI: `prism guard check -w acme -r app -p $PR_ID --min-severity high || exit 1`
56
-
57
- ## Rules — Generate and Share Patterns
58
-
59
- Rules are generated from your review history and shared via a remote repository.
60
-
61
- ### Generate patterns
62
-
63
- ```bash
64
- # Generate .prism-patterns.json from past reviews
65
- prism rules sync -w <workspace> -r <repo> --verbose
66
-
67
- # Skip AI rule generation (faster, keyword-only)
68
- prism rules sync -w <workspace> -r <repo> --skip-rules
69
- ```
70
-
71
- ### Share with your team
72
-
73
- ```bash
74
- # Push patterns to remote rules repo
75
- prism rules push -w <workspace> -r <repo>
76
- ```
77
-
78
- Your team then uses `--remote` flag on guard check to fetch shared rules automatically.
79
-
80
- ### View stats
81
-
82
- ```bash
83
- prism rules stats -w <workspace> -r <repo>
84
- ```
85
-
86
- ## AI Review — Full PR Analysis
87
-
88
- ```bash
89
- # Launch interactive TUI for full AI review
90
- prism
91
-
92
- # Or start directly
93
- prism review start -w <workspace> -r <repo> -p <pr-id>
94
- ```
95
-
96
- The AI review uses specialized agents (TypeScript, PHP, CSS, Security, Architecture, Performance, etc.) to analyze your PR and generate findings with inline suggestions.
97
-
98
- ## Commands
99
-
100
- | Command | Description |
101
- |---------|-------------|
102
- | `prism` | Launch interactive TUI |
103
- | `prism login` | Authenticate with Bitbucket |
104
- | `prism logout` | Remove stored credentials |
105
- | `prism guard` | Guard TUI (pattern check) |
106
- | `prism guard check` | Guard CLI (non-interactive) |
107
- | `prism rules sync` | Generate patterns from review history |
108
- | `prism rules push` | Push patterns to remote repo |
109
- | `prism rules stats` | Show pattern statistics |
110
- | `prism review start` | Start AI review for a PR |
111
-
112
- ## Requirements
113
-
114
- - Node.js 20+
115
- - Bitbucket Cloud account with app password
116
- - Claude Code CLI (for AI review and rule generation)
117
-
118
- ## License
119
-
120
- Private
1
+ # PRISM-PR
2
+
3
+ > **Alpha** this package is in active development (`1.0.0-alpha`). APIs and commands may change between releases.
4
+
5
+ Intelligent Pull Request review orchestrator for Bitbucket. AI-powered code review plus pattern-based pre-checks using ast-grep structural matching, a shared team rules repository, and a self-evolving rule system that learns from your feedback.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm i -g prism-pr
11
+ ```
12
+
13
+ ## Requirements
14
+
15
+ - Node.js **>= 22.5.0** (SQLite is loaded via the native `node:sqlite` module)
16
+ - Bitbucket Cloud account with an Atlassian API token
17
+ - AI provider (one of):
18
+ - `ANTHROPIC_API_KEY` environment variable (preferred), or
19
+ - [Claude Code CLI](https://docs.anthropic.com/en/docs/claude-code) installed and authenticated
20
+
21
+ ## Setup
22
+
23
+ ```bash
24
+ prism login
25
+ ```
26
+
27
+ Your Bitbucket app password / API token needs these permissions:
28
+
29
+ - Repositories: **Read** + **Write**
30
+ - Pull requests: **Read** + **Write**
31
+
32
+ ## Discoverability always available
33
+
34
+ Every command documents itself via `--help`. If something in this README is stale, trust `--help`:
35
+
36
+ ```bash
37
+ prism --help # full command tree
38
+ prism rules --help # subcommands under `rules`
39
+ prism guard --help # subcommands under `guard`
40
+ prism rules bootstrap --help # flags + examples for a specific command
41
+ prism guard check --help
42
+ prism review start --help
43
+ ```
44
+
45
+ ---
46
+
47
+ ## Quick start — zero config
48
+
49
+ PRISM auto-detects your stack and bootstraps rules on the first run. No setup needed.
50
+
51
+ ```bash
52
+ cd your-bitbucket-repo
53
+ prism guard check
54
+ ```
55
+
56
+ That's it. On first run, PRISM will:
57
+
58
+ 1. Detect workspace/repo from your git remote
59
+ 2. Fetch `package.json` via Bitbucket API to detect your stack (TypeScript, Angular, React, NestJS, AG Grid, …)
60
+ 3. Generate a manifest with the matching rulesets
61
+ 4. Push everything to the shared rules repository
62
+ 5. Resolve patterns and check your PR
63
+
64
+ ### Manual bootstrap (optional)
65
+
66
+ If you prefer explicit control:
67
+
68
+ ```bash
69
+ # Detect stack and push manifest + rulesets to the shared rules repo
70
+ prism rules bootstrap
71
+
72
+ # Preview without pushing
73
+ prism rules bootstrap --dry-run
74
+
75
+ # JSON output (CI-friendly)
76
+ prism rules bootstrap --dry-run --json
77
+
78
+ # Explicit workspace/repo/branch
79
+ prism rules bootstrap --workspace acme --repo my-repo --branch develop
80
+ ```
81
+
82
+ ### Check a PR
83
+
84
+ ```bash
85
+ # Interactive PR picker (auto-detects workspace/repo from git origin)
86
+ prism guard check
87
+
88
+ # Pick a PR by ID
89
+ prism guard check --pr 42
90
+
91
+ # Full output with code snippets and suggestions
92
+ prism guard check --pr 42 --verbose
93
+
94
+ # Filter by severity
95
+ prism guard check --pr 42 --min-severity high --verbose
96
+
97
+ # JSON output for CI
98
+ prism guard check --pr 42 --json
99
+ ```
100
+
101
+ **`--verbose` gates the snippet and suggestion.** Without it, matches show severity badge + title + file:line only. With `--verbose`, you get diff context with a pointer on the exact line, plus the fix suggestion.
102
+
103
+ ---
104
+
105
+ ## Living Rules self-evolving rule system
106
+
107
+ PRISM's rules aren't static. They learn, adapt, and grow with your codebase.
108
+
109
+ ### Auto-Refresh
110
+
111
+ Manifests detect when your stack changes. If you add a new framework (e.g. NestJS) to your project, the next guard check automatically updates the manifest with the new rulesets. Default staleness threshold: 7 days.
112
+
113
+ ### Versioned Catalog
114
+
115
+ Rulesets are published as immutable versioned artifacts:
116
+
117
+ ```
118
+ catalog/
119
+ shared/security/1.0.0.json # immutable, infinite cache
120
+ shared/general/1.0.0.json
121
+ angular/v17/1.0.0.json
122
+ ...
123
+ catalog/index.json # lists all rulesets + latest versions
124
+ ```
125
+
126
+ Manifests can pin versions: `"shared/security@1.2.0"`. Unversioned includes resolve to latest. A 3-level fallback chain ensures resilience: versioned remote → unversioned remote → static builtin catalog.
127
+
128
+ ### Feedback Loop & Auto-Tune
129
+
130
+ Mark findings as false positives. After enough feedback, PRISM auto-excludes noisy patterns.
131
+
132
+ ```bash
133
+ # CLI: mark specific pattern IDs as false positive
134
+ prism guard check --pr 42 --mark-fp "security--xss--innerHTML-usage,general--debug--console-log"
135
+
136
+ # CLI: auto-exclude patterns with 3+ false positives
137
+ prism guard check --pr 42 --auto-tune
138
+ ```
139
+
140
+ In the TUI, press `[f]` on any finding to mark it as a false positive. Press `[t]` in the results screen to apply auto-tune.
141
+
142
+ ### AI Rule Suggestion
143
+
144
+ PRISM can analyze findings from any review and generate new ast-grep rules automatically. Rule suggestions are a **post-review** action — you see the findings first, then decide which patterns should become permanent rules.
145
+
146
+ ```bash
147
+ # CLI: generate rules from guard findings
148
+ prism guard check --pr 42 --suggest-rules
149
+
150
+ # CLI: generate rules from AI review findings
151
+ prism review start --workspace acme --repo app --pr 42 --suggest-rules
152
+ ```
153
+
154
+ PRISM uses the same AI provider configured for reviews (auto-detects from `ANTHROPIC_API_KEY` or falls back to Claude Code CLI).
155
+
156
+ In the TUI, press `[g]` on any results screen (guard results or AI review findings) to generate rule suggestions on demand. Review, accept/reject, and apply to the manifest.
157
+
158
+ ---
159
+
160
+ ## Interactive TUI
161
+
162
+ ```bash
163
+ prism # main TUI (review + navigation)
164
+ prism guard # guard-focused TUI
165
+ ```
166
+
167
+ Launches a full Ink-based terminal UI with keyboard navigation.
168
+
169
+ ### Guardian Angel section
170
+
171
+ - **Guard Check** — select workspace → repo → PR → run check
172
+ - **Guard Check (auto-detect)** — detects workspace/repo from git origin, skips manual selection
173
+ - **Rules Bootstrap** — detect stack and push manifest (dry-run toggle, branch override)
174
+
175
+ ### Guard options (toggleable in guard-home)
176
+
177
+ | Key | Option | Description |
178
+ |-----|--------|-------------|
179
+ | `v` | Verbose | Show context lines and suggestions |
180
+ | `s` | Severity | Cycle minimum severity filter |
181
+ | `a` | AST | Toggle ast-grep matching on/off |
182
+
183
+ ### Guard results actions
184
+
185
+ | Key | Action | Description |
186
+ |-----|--------|-------------|
187
+ | `↑↓` | Navigate | Browse findings |
188
+ | `Enter` | Detail | View finding detail with context |
189
+ | `f` | False positive | Mark finding as FP (in detail view) |
190
+ | `j` | Export JSON | Export results to `prism-guard-results.json` |
191
+ | `t` | Auto-tune | Batch-exclude patterns with enough FP feedback |
192
+ | `g` | AI suggestions | Generate and review AI-suggested rules (on demand) |
193
+ | `Esc` | Back | Return to previous screen |
194
+
195
+ ### AI Review findings actions
196
+
197
+ | Key | Action | Description |
198
+ |-----|--------|-------------|
199
+ | `↑↓` | Navigate | Browse findings |
200
+ | `Enter` | Detail | View finding detail |
201
+ | `g` | AI suggestions | Generate rules from review findings (on demand) |
202
+ | `p` | Publish | Publish findings to Bitbucket PR |
203
+ | `Esc` | Back | Return to previous screen |
204
+
205
+ ---
206
+
207
+ ## AI Review — full PR analysis (LLM-powered)
208
+
209
+ ```bash
210
+ prism review start --workspace acme --repo app --pr 42
211
+
212
+ # Verbose logging
213
+ prism review start --workspace acme --repo app --pr 42 --verbose
214
+
215
+ # Pick a provider explicitly
216
+ prism review start --workspace acme --repo app --pr 42 --provider anthropic
217
+ prism review start --workspace acme --repo app --pr 42 --provider claude-code
218
+
219
+ # Generate rule suggestions from findings
220
+ prism review start --workspace acme --repo app --pr 42 --suggest-rules
221
+ ```
222
+
223
+ > **Note:** `review start` requires `--workspace` and `--repo` explicitly (no auto-detect from git origin). `guard check` auto-detects both.
224
+
225
+ The AI review runs specialized agents (TypeScript, PHP, CSS, Security, Architecture, Performance, …) and produces findings with inline suggestions. Findings are stored in a local SQLite database for review memory and pattern generation.
226
+
227
+ ---
228
+
229
+ ## Commands
230
+
231
+ | Command | Purpose |
232
+ |---------|---------|
233
+ | `prism` | Launch main interactive TUI |
234
+ | `prism login` | Authenticate with Bitbucket |
235
+ | `prism logout` | Remove stored credentials |
236
+ | `prism guard` | Guard Check TUI |
237
+ | `prism guard check` | Non-interactive pattern check (manifest v3) |
238
+ | `prism rules bootstrap` | Detect stack, generate manifest, push to rules repo |
239
+ | `prism rules sync` | ~~Legacy v2.~~ Generate `.prism-patterns.json` from local review history (deprecated) |
240
+ | `prism rules push` | ~~Legacy v2.~~ Push a local `.prism-patterns.json` to the rules repo (deprecated) |
241
+ | `prism rules stats` | Show aggregated finding patterns from local review history |
242
+ | `prism review start` | Run an AI code review on a PR |
243
+
244
+ ### guard check flags
245
+
246
+ | Flag | Description |
247
+ |------|-------------|
248
+ | `--workspace, -w` | Bitbucket workspace (auto-detected from git origin) |
249
+ | `--repo, -r` | Repository slug (auto-detected from git origin) |
250
+ | `--pr, -p` | Pull request ID (interactive picker if omitted) |
251
+ | `--verbose` | Show diff context and suggestions |
252
+ | `--min-severity` | Filter: `critical`, `high`, `medium`, `low`, `info` |
253
+ | `--json` | Structured JSON output (CI-friendly) |
254
+ | `--skip-ast` | Skip ast-grep, keyword-only matching |
255
+ | `--auto-tune` | Auto-exclude patterns with repeated false positives |
256
+ | `--suggest-rules` | Generate AI rules from recurring findings |
257
+ | `--mark-fp` | Mark pattern IDs as false positive (comma-separated) |
258
+ | `--patterns` | Path to local patterns file (bypasses manifest) |
259
+ | `--remote` | **Deprecated.** Use v2 remote fetch path |
260
+
261
+ ### Exit codes (guard check)
262
+
263
+ - `0` — no matches found
264
+ - `1` — matches found (or error)
265
+
266
+ Useful in CI:
267
+
268
+ ```bash
269
+ prism guard check --pr "$PR_ID" --min-severity high --json > findings.json
270
+ ```
271
+
272
+ ---
273
+
274
+ ## Concepts
275
+
276
+ ### Manifest v3
277
+
278
+ A `ProjectManifest` lives at `projects/<workspace>/<repo>.json` in the shared rules repo. It references rulesets by id instead of inlining patterns:
279
+
280
+ ```json
281
+ {
282
+ "version": 3,
283
+ "generatedAt": "2026-04-13T21:00:00.000Z",
284
+ "stack": {
285
+ "languages": ["typescript"],
286
+ "frameworks": [{ "name": "angular", "version": "17.3.0" }],
287
+ "detectedAt": "2026-04-13T21:00:00.000Z"
288
+ },
289
+ "includes": ["angular/base", "angular/v17", "shared/typescript", "shared/security@1.0.0"],
290
+ "excludes": ["general--debug--console-log"],
291
+ "patterns": []
292
+ }
293
+ ```
294
+
295
+ - `includes` — ruleset IDs to pull in (supports `@version` pinning)
296
+ - `excludes` — pattern IDs to skip (auto-tune populates this)
297
+ - `patterns` — project-specific custom patterns (AI suggestions land here)
298
+
299
+ ### Rulesets
300
+
301
+ Built-in rulesets today (9 rulesets, 30+ ast-grep patterns):
302
+
303
+ - `shared/general`, `shared/security`, `shared/typescript`
304
+ - `angular/base`, `angular/v17`
305
+ - `react/base`
306
+ - `nestjs/base`
307
+ - `ag-grid/base`, `ag-grid/v32`
308
+
309
+ ### Remote catalog structure
310
+
311
+ All teams share a single Bitbucket rules repository that hosts manifests and versioned rulesets. The default shared repo is `walzate1/prism-rules`:
312
+
313
+ ```
314
+ {rules-repo} (Bitbucket)
315
+ ├── projects/{workspace}/{repo}.json # per-project manifest
316
+ ├── rulesets/{id}.json # unversioned rulesets (backward compat)
317
+ └── catalog/
318
+ ├── index.json # catalog index (all rulesets + versions)
319
+ └── {id}/{version}.json # immutable versioned rulesets
320
+ ```
321
+
322
+ ### Severity levels
323
+
324
+ `critical` · `high` · `medium` · `low` · `info`
325
+
326
+ ### Pattern resolution flow
327
+
328
+ 1. `--patterns <file>` explicitly set → use local file (bypasses manifest)
329
+ 2. Fetch manifest from `projects/<ws>/<repo>.json`
330
+ 3. If no manifest → **auto-bootstrap** (detect stack → generate → push → continue)
331
+ 4. If manifest is stale (>7 days) → **auto-refresh** (re-detect stack → smart merge → push)
332
+ 5. Resolve includes via 3-level fallback (versioned → unversioned → static builtin)
333
+ 6. Apply excludes → merge custom patterns → run guard
334
+
335
+ ---
336
+
337
+ ## License
338
+
339
+ UNLICENSED — All rights reserved.
package/bin/run.js CHANGED
@@ -1,17 +1,17 @@
1
1
  #!/usr/bin/env node
2
-
3
- // Suppress node:sqlite ExperimentalWarning
4
- const _origEmit = process.emit.bind(process);
5
- process.emit = function (event, ...args) {
6
- if (event === 'warning' && args[0]?.name === 'ExperimentalWarning') return false;
7
- return _origEmit(event, ...args);
8
- };
9
-
10
- import { execute } from '@oclif/core';
11
-
12
- // If no command specified, default to interactive TUI
13
- if (process.argv.length === 2) {
14
- process.argv.push('interactive');
15
- }
16
-
17
- await execute({ dir: import.meta.url });
2
+
3
+ // Suppress node:sqlite ExperimentalWarning
4
+ const _origEmit = process.emit.bind(process);
5
+ process.emit = function (event, ...args) {
6
+ if (event === 'warning' && args[0]?.name === 'ExperimentalWarning') return false;
7
+ return _origEmit(event, ...args);
8
+ };
9
+
10
+ import { execute } from '@oclif/core';
11
+
12
+ // If no command specified, default to interactive TUI
13
+ if (process.argv.length === 2) {
14
+ process.argv.push('interactive');
15
+ }
16
+
17
+ await execute({ dir: import.meta.url });
@@ -0,0 +1,21 @@
1
+ import type { ModelProvider } from '../../types/provider.js';
2
+ import type { LLMProvider } from '../../rules-engine/pattern-generator.js';
3
+ /**
4
+ * Adapter that bridges ModelProvider (tool_use, returns AnalyzeResult) →
5
+ * LLMProvider (string-in / string-out) required by PatternGenerator.
6
+ *
7
+ * Strategy:
8
+ * 1. Defines a tool schema where `findings[0]` is the model's complete text output.
9
+ * 2. Calls ModelProvider.analyze() with this schema.
10
+ * 3. Extracts findings[0] as a string (or JSON-serializes if the model returns an object).
11
+ * 4. Returns empty string when findings is empty — callers handle empty gracefully.
12
+ */
13
+ export declare class ModelProviderLLMAdapter implements LLMProvider {
14
+ private readonly provider;
15
+ constructor(provider: ModelProvider);
16
+ analyze(systemPrompt: string, userContent: string, options?: {
17
+ toolName?: string;
18
+ maxTokens?: number;
19
+ }): Promise<string>;
20
+ }
21
+ //# sourceMappingURL=model-provider-llm-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-provider-llm-adapter.d.ts","sourceRoot":"","sources":["../../../src/ai/adapters/model-provider-llm-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AAwB3E;;;;;;;;;GASG;AACH,qBAAa,uBAAwB,YAAW,WAAW;IAC7C,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,aAAa;IAE9C,OAAO,CACX,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAClD,OAAO,CAAC,MAAM,CAAC;CAwBnB"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Tool schema designed to work with AnthropicProvider's extraction logic.
3
+ *
4
+ * AnthropicProvider always extracts `toolUseBlock.input.findings` from the tool call response.
5
+ * So the schema MUST use `findings` as the key — the model places its response in `findings[0]`.
6
+ *
7
+ * With this schema the model is instructed to return an array with exactly one element:
8
+ * the complete JSON response. AnthropicProvider's existing extraction code
9
+ * (`input.findings ?? []`) captures it, and we return `findings[0]`.
10
+ */
11
+ const TEXT_CAPTURE_TOOL_SCHEMA = {
12
+ type: 'object',
13
+ properties: {
14
+ findings: {
15
+ type: 'array',
16
+ items: { type: 'string' },
17
+ description: 'Array with exactly one element: the complete JSON response. No markdown fences.',
18
+ },
19
+ },
20
+ required: ['findings'],
21
+ };
22
+ /**
23
+ * Adapter that bridges ModelProvider (tool_use, returns AnalyzeResult) →
24
+ * LLMProvider (string-in / string-out) required by PatternGenerator.
25
+ *
26
+ * Strategy:
27
+ * 1. Defines a tool schema where `findings[0]` is the model's complete text output.
28
+ * 2. Calls ModelProvider.analyze() with this schema.
29
+ * 3. Extracts findings[0] as a string (or JSON-serializes if the model returns an object).
30
+ * 4. Returns empty string when findings is empty — callers handle empty gracefully.
31
+ */
32
+ export class ModelProviderLLMAdapter {
33
+ provider;
34
+ constructor(provider) {
35
+ this.provider = provider;
36
+ }
37
+ async analyze(systemPrompt, userContent, options) {
38
+ const toolName = options?.toolName ?? 'generate_ast_grep_rule';
39
+ const maxTokens = options?.maxTokens ?? 1024;
40
+ const result = await this.provider.analyze({
41
+ systemPrompt,
42
+ userContent,
43
+ toolName,
44
+ toolSchema: TEXT_CAPTURE_TOOL_SCHEMA,
45
+ maxTokens,
46
+ });
47
+ if (result.findings.length === 0) {
48
+ return '';
49
+ }
50
+ const first = result.findings[0];
51
+ if (typeof first === 'string') {
52
+ return first;
53
+ }
54
+ // Object findings — JSON-serialize for parseGeneratedRule to handle
55
+ return JSON.stringify(first);
56
+ }
57
+ }
58
+ //# sourceMappingURL=model-provider-llm-adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model-provider-llm-adapter.js","sourceRoot":"","sources":["../../../src/ai/adapters/model-provider-llm-adapter.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,MAAM,wBAAwB,GAAG;IAC/B,IAAI,EAAE,QAAiB;IACvB,UAAU,EAAE;QACV,QAAQ,EAAE;YACR,IAAI,EAAE,OAAgB;YACtB,KAAK,EAAE,EAAE,IAAI,EAAE,QAAiB,EAAE;YAClC,WAAW,EAAE,iFAAiF;SAC/F;KACF;IACD,QAAQ,EAAE,CAAC,UAAU,CAAU;CAChC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,OAAO,uBAAuB;IACL;IAA7B,YAA6B,QAAuB;QAAvB,aAAQ,GAAR,QAAQ,CAAe;IAAG,CAAC;IAExD,KAAK,CAAC,OAAO,CACX,YAAoB,EACpB,WAAmB,EACnB,OAAmD;QAEnD,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,wBAAwB,CAAC;QAC/D,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,IAAI,IAAI,CAAC;QAE7C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;YACzC,YAAY;YACZ,WAAW;YACX,QAAQ;YACR,UAAU,EAAE,wBAAwB;YACpC,SAAS;SACV,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,oEAAoE;QACpE,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;CACF"}
@@ -1,39 +1,39 @@
1
- You are a senior software architect reviewing a pull request for structural and design issues. Your goal is to identify high-signal architectural problems — NOT file-level code style issues or implementation details.
2
-
3
- ## Focus Areas
4
-
5
- Review the entire diff holistically and report findings for:
6
-
7
- 1. **Circular dependencies** — modules or packages that import each other directly or transitively, creating tight coupling that prevents independent testing or deployment
8
- 2. **Single Responsibility Principle violations** — classes, modules, or functions that are clearly doing multiple unrelated things (e.g., a data model that also handles HTTP calls; a service that mixes business logic with persistence)
9
- 3. **Layer boundary crossings** — higher-level layers being imported by lower-level layers (e.g., UI components importing directly from database models; infrastructure code importing domain entities incorrectly)
10
- 4. **Inappropriate coupling** — components that know too much about each other's internals; tight coupling that makes changes in one place require changes in many others
11
- 5. **Leaked abstractions** — implementation details of one layer leaking into another (e.g., SQL-specific types in business logic; HTTP status codes in domain services)
12
-
13
- ## Critical Output Constraint
14
-
15
- Produce between 0 and 3 findings MAXIMUM. This is a hard limit.
16
-
17
- Focus only on `critical` or `high` severity architectural issues. Do NOT report:
18
- - `medium`, `low`, or `info` severity findings
19
- - File-level implementation details
20
- - Naming conventions or code style
21
- - Issues that affect a single file without cross-component impact
22
- - Theoretical violations without clear evidence in the diff
23
-
24
- If no high-signal architectural issues exist, return an empty findings array. Do NOT manufacture findings to appear thorough.
25
-
26
- ## Output Instructions
27
-
28
- You MUST call the `report_findings` tool to submit your findings. Do not write findings as plain text — the tool call is required.
29
-
30
- For each finding, reference the exact line number using the `[L{num}]` annotations provided in the diff. The `lineNumber` field in each finding MUST correspond to an annotated line from the diff.
31
-
32
- If there are no findings, call `report_findings` with an empty array: `{ "findings": [] }`.
33
-
34
- ## Severity Criteria
35
-
36
- | Severity | When to use |
37
- |----------|-------------|
38
- | `critical` | Circular dependency or layer violation that will break builds or prevent testability |
39
- | `high` | SRP violation or coupling issue that will cause cascading changes and increase defect rate |
1
+ You are a senior software architect reviewing a pull request for structural and design issues. Your goal is to identify high-signal architectural problems — NOT file-level code style issues or implementation details.
2
+
3
+ ## Focus Areas
4
+
5
+ Review the entire diff holistically and report findings for:
6
+
7
+ 1. **Circular dependencies** — modules or packages that import each other directly or transitively, creating tight coupling that prevents independent testing or deployment
8
+ 2. **Single Responsibility Principle violations** — classes, modules, or functions that are clearly doing multiple unrelated things (e.g., a data model that also handles HTTP calls; a service that mixes business logic with persistence)
9
+ 3. **Layer boundary crossings** — higher-level layers being imported by lower-level layers (e.g., UI components importing directly from database models; infrastructure code importing domain entities incorrectly)
10
+ 4. **Inappropriate coupling** — components that know too much about each other's internals; tight coupling that makes changes in one place require changes in many others
11
+ 5. **Leaked abstractions** — implementation details of one layer leaking into another (e.g., SQL-specific types in business logic; HTTP status codes in domain services)
12
+
13
+ ## Critical Output Constraint
14
+
15
+ Produce between 0 and 3 findings MAXIMUM. This is a hard limit.
16
+
17
+ Focus only on `critical` or `high` severity architectural issues. Do NOT report:
18
+ - `medium`, `low`, or `info` severity findings
19
+ - File-level implementation details
20
+ - Naming conventions or code style
21
+ - Issues that affect a single file without cross-component impact
22
+ - Theoretical violations without clear evidence in the diff
23
+
24
+ If no high-signal architectural issues exist, return an empty findings array. Do NOT manufacture findings to appear thorough.
25
+
26
+ ## Output Instructions
27
+
28
+ You MUST call the `report_findings` tool to submit your findings. Do not write findings as plain text — the tool call is required.
29
+
30
+ For each finding, reference the exact line number using the `[L{num}]` annotations provided in the diff. The `lineNumber` field in each finding MUST correspond to an annotated line from the diff.
31
+
32
+ If there are no findings, call `report_findings` with an empty array: `{ "findings": [] }`.
33
+
34
+ ## Severity Criteria
35
+
36
+ | Severity | When to use |
37
+ |----------|-------------|
38
+ | `critical` | Circular dependency or layer violation that will break builds or prevent testability |
39
+ | `high` | SRP violation or coupling issue that will cause cascading changes and increase defect rate |