@jonathan0823/pi-sonarqube 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jonathan0823
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # @jonathan0823/pi-sonarqube
2
+
3
+ A Pi extension to run local SonarQube analysis and browse the resulting issues — all from within Pi.
4
+
5
+ ## Requirements
6
+
7
+ - [Pi](https://github.com/earendil-works/pi-coding-agent) installed
8
+ - A running SonarQube server (e.g. `http://localhost:9000`)
9
+ - `sonar-scanner` available in `$PATH`
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pi install npm:@jonathan0823/pi-sonarqube
15
+ ```
16
+
17
+ Or add it to your `settings.json`:
18
+
19
+ ```json
20
+ {
21
+ "packages": ["npm:@jonathan0823/pi-sonarqube"]
22
+ }
23
+ ```
24
+
25
+ Then `/reload` in Pi.
26
+
27
+ ## Quick start
28
+
29
+ ### 1. Init project config
30
+
31
+ Inside a project directory, run:
32
+
33
+ ```
34
+ /sonarqube init
35
+ ```
36
+
37
+ For monorepos, you can add a user-defined alias and optional path:
38
+
39
+ ```
40
+ /sonarqube init fe apps/web
41
+ /sonarqube init be apps/api
42
+ ```
43
+
44
+ Pi will ask you for:
45
+ - **SonarQube server URL** (prefilled with `http://localhost:9000`)
46
+ - **Project key** (default: derived from directory name)
47
+ - **Token** (optional, used when your server requires auth)
48
+
49
+ The config is saved to `<project>/.pi/sonarqube.json`. Alias mappings live in the repo root `.pi/sonarqube.workspaces.json`.
50
+
51
+ ### 2. Run analysis
52
+
53
+ ```
54
+ /sonarqube analyze
55
+ /sonarqube analyze fe
56
+ /sonarqube analyze apps/web
57
+ ```
58
+
59
+ Pi will:
60
+ 1. Run `sonar-scanner` against your server
61
+ 2. Wait for the analysis to complete
62
+ 3. Fetch the latest issues
63
+ 4. Return a concise summary
64
+
65
+ ### 3. Browse issues
66
+
67
+ ```
68
+ /sonarqube issues
69
+ /sonarqube issues fe
70
+ ```
71
+
72
+ Use **Up/Down** to move, **Enter** to preview the affected source code, and **Esc** to close.
73
+
74
+ ### 4. Open a specific issue
75
+
76
+ ```
77
+ /sonarqube open 3
78
+ /sonarqube open fe 3
79
+ ```
80
+
81
+ ## Commands
82
+
83
+ | Command | Description |
84
+ |---------|-------------|
85
+ | `/sonarqube init [alias] [path]` | Set up project config and optional alias |
86
+ | `/sonarqube analyze [target]` | Run analysis for an alias or path |
87
+ | `/sonarqube issues [target]` | Browse the latest analysis results for a target |
88
+ | `/sonarqube open [target] <n>` | Preview source at issue #n |
89
+
90
+ ## Tool (for the LLM)
91
+
92
+ The extension also registers a `sonarqube` tool that the LLM can call with actions:
93
+ - `analyze` — run analysis
94
+ - `issues` — list issues
95
+ - `open` — open an issue with its index
96
+
97
+ Targets can be an alias like `fe` or a path like `apps/web`.
98
+
99
+ ## Configuration sources (precedence order)
100
+
101
+ 1. **Environment variables** (highest)
102
+ - `SONARQUBE_URL` / `SONAR_HOST_URL`
103
+ - `SONARQUBE_TOKEN` / `SONAR_TOKEN`
104
+ - `SONAR_PROJECT_KEY`
105
+ 2. **Project config** — `.pi/sonarqube.json` (set via `/sonarqube init`)
106
+ 3. **Scan properties** — `sonar-project.properties`
107
+ 4. **Defaults** — `http://localhost:9000`, project key from directory slug
108
+
109
+ ## Publishing
110
+
111
+ ### Prerequisites
112
+
113
+ - An [npm](https://www.npmjs.com/) account
114
+ - The npm scope `@jonathan0823` assigned to your npm user
115
+
116
+ ### Publish
117
+
118
+ ```bash
119
+ cd packages/pi-sonarqube
120
+
121
+ # Login if needed
122
+ npm login
123
+
124
+ # Publish (builds automatically via prepack)
125
+ npm publish
126
+ ```
127
+
128
+ ### Publish a new version
129
+
130
+ ```bash
131
+ # Update version in package.json
132
+ npm version patch # or minor / major
133
+
134
+ # Publish
135
+ npm publish
136
+ ```
137
+
138
+ ### Test locally before publishing
139
+
140
+ ```bash
141
+ cd packages/pi-sonarqube
142
+
143
+ # Create a tarball
144
+ npm pack
145
+
146
+ # Install it in a test project
147
+ cd /tmp/test-project
148
+ npm install /path/to/pi-sonarqube-0.1.0.tgz
149
+ ```
150
+
151
+ ## Manual via `pi install`
152
+
153
+ You can also install directly from a local path:
154
+
155
+ ```bash
156
+ pi install /path/to/packages/pi-sonarqube
157
+ ```
158
+
159
+ ## Project structure
160
+
161
+ ```
162
+ packages/pi-sonarqube/
163
+ ├── src/
164
+ │ └── index.ts # Extension source + init command + config
165
+ ├── dist/
166
+ │ ├── index.js # Compiled output
167
+ │ ├── index.d.ts # Type declarations
168
+ │ └── index.js.map # Source map
169
+ ├── fixtures/
170
+ │ ├── issue-project/ # Test project with known issues
171
+ │ └── clean-project/ # Test project with no issues
172
+ ├── README.md
173
+ ├── LICENSE
174
+ ├── package.json
175
+ └── tsconfig.json
176
+ ```
177
+
178
+ ## License
179
+
180
+ MIT
@@ -0,0 +1,50 @@
1
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
2
+ export type SonarAction = "analyze" | "issues" | "open" | "init";
3
+ export interface SonarIssue {
4
+ key: string;
5
+ rule: string;
6
+ ruleName?: string;
7
+ severity: string;
8
+ message: string;
9
+ filePath: string;
10
+ line: number | null;
11
+ status?: string;
12
+ }
13
+ export interface SonarAnalysisState {
14
+ version: 1;
15
+ analyzedAt: string;
16
+ baseDir: string;
17
+ serverUrl: string;
18
+ projectKey: string;
19
+ dashboardUrl?: string;
20
+ ceTaskUrl?: string;
21
+ analysisId?: string;
22
+ totalIssues: number;
23
+ issues: SonarIssue[];
24
+ }
25
+ export interface SonarProjectConfig {
26
+ baseDir: string;
27
+ serverUrl: string;
28
+ projectKey: string;
29
+ token?: string;
30
+ hasProperties: boolean;
31
+ }
32
+ export interface SonarInitConfig {
33
+ serverUrl: string;
34
+ projectKey: string;
35
+ token?: string;
36
+ }
37
+ declare function projectConfigPath(baseDir: string): string;
38
+ declare function sonarqubeConfigDir(baseDir: string): string;
39
+ /**
40
+ * Load project-local config from `.pi/sonarqube.json`.
41
+ * Returns undefined when the file doesn't exist or is invalid.
42
+ */
43
+ declare function loadProjectConfig(baseDir: string): Promise<SonarInitConfig | undefined>;
44
+ /**
45
+ * Save project-local config to `.pi/sonarqube.json`.
46
+ */
47
+ declare function saveProjectConfig(baseDir: string, config: SonarInitConfig): Promise<void>;
48
+ export { projectConfigPath, loadProjectConfig, saveProjectConfig, sonarqubeConfigDir };
49
+ export default function sonarqube(pi: ExtensionAPI): void;
50
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EAIb,MAAM,iCAAiC,CAAC;AASzC,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,QAAQ,GAAG,MAAM,GAAG,M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