soigne-ci 0.0.0-stage → 1.0.1

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 (170) hide show
  1. package/README.md +140 -2
  2. package/bin/soigne.js +223 -0
  3. package/git_heal_be/README.md +242 -0
  4. package/git_heal_be/package.json +41 -0
  5. package/git_heal_be/prisma/migrations/20261025152401_first_migration/migration.sql +127 -0
  6. package/git_heal_be/prisma/migrations/migration_lock.toml +3 -0
  7. package/git_heal_be/prisma/schema.prisma +151 -0
  8. package/git_heal_be/prisma7.config.ts +14 -0
  9. package/git_heal_be/src/core/ai/gemini.ts +129 -0
  10. package/git_heal_be/src/core/db/index.ts +1 -0
  11. package/git_heal_be/src/core/db/prisma.ts +38 -0
  12. package/git_heal_be/src/core/events/sseManager.ts +86 -0
  13. package/git_heal_be/src/core/security/crypto.ts +82 -0
  14. package/git_heal_be/src/features/agents/patchAgents.ts +1001 -0
  15. package/git_heal_be/src/features/github/githubService.ts +375 -0
  16. package/git_heal_be/src/features/repos/routes.ts +138 -0
  17. package/git_heal_be/src/features/runs/routes.ts +346 -0
  18. package/git_heal_be/src/features/runs/runService.ts +233 -0
  19. package/git_heal_be/src/features/runs/scraper.ts +223 -0
  20. package/git_heal_be/src/features/runs/terminalLogger.ts +51 -0
  21. package/git_heal_be/src/features/sandbox/workspaceManager.ts +165 -0
  22. package/git_heal_be/src/features/sandbox/workspaceTools.ts +62 -0
  23. package/git_heal_be/src/features/settings/routes.ts +183 -0
  24. package/git_heal_be/src/features/usage/routes.ts +181 -0
  25. package/git_heal_be/src/features/webhooks/routes.ts +50 -0
  26. package/git_heal_be/src/features/webhooks/types.ts +47 -0
  27. package/git_heal_be/src/features/webhooks/verifySignature.ts +50 -0
  28. package/git_heal_be/src/features/webhooks/webHookHandler.ts +235 -0
  29. package/git_heal_be/src/generated/src/prisma/client/browser.ts +49 -0
  30. package/git_heal_be/src/generated/src/prisma/client/client.ts +71 -0
  31. package/git_heal_be/src/generated/src/prisma/client/commonInputTypes.ts +664 -0
  32. package/git_heal_be/src/generated/src/prisma/client/enums.ts +53 -0
  33. package/git_heal_be/src/generated/src/prisma/client/internal/class.ts +254 -0
  34. package/git_heal_be/src/generated/src/prisma/client/internal/prismaNamespace.ts +1418 -0
  35. package/git_heal_be/src/generated/src/prisma/client/internal/prismaNamespaceBrowser.ts +215 -0
  36. package/git_heal_be/src/generated/src/prisma/client/models/Repository.ts +1745 -0
  37. package/git_heal_be/src/generated/src/prisma/client/models/Run.ts +2066 -0
  38. package/git_heal_be/src/generated/src/prisma/client/models/RunStep.ts +1516 -0
  39. package/git_heal_be/src/generated/src/prisma/client/models/TokenUsage.ts +1516 -0
  40. package/git_heal_be/src/generated/src/prisma/client/models/User.ts +1367 -0
  41. package/git_heal_be/src/generated/src/prisma/client/models/UserSettings.ts +1458 -0
  42. package/git_heal_be/src/generated/src/prisma/client/models.ts +17 -0
  43. package/git_heal_be/src/index.ts +39 -0
  44. package/git_heal_be/tsconfig.json +37 -0
  45. package/git_heal_fe/README.md +242 -0
  46. package/git_heal_fe/index.html +20 -0
  47. package/git_heal_fe/package.json +39 -0
  48. package/git_heal_fe/public/GitHeal_AI_Health_Logo.png +0 -0
  49. package/git_heal_fe/public/apple-touch-icon.png +0 -0
  50. package/git_heal_fe/public/favicon-16x16.png +0 -0
  51. package/git_heal_fe/public/favicon-32x32.png +0 -0
  52. package/git_heal_fe/public/favicon.ico +0 -0
  53. package/git_heal_fe/public/favicon.png +0 -0
  54. package/git_heal_fe/public/favicon.svg +1 -0
  55. package/git_heal_fe/public/github_login_teddy_assets/README.txt +11 -0
  56. package/git_heal_fe/public/github_login_teddy_assets/bottom-agents/mini-bear-boba.png +0 -0
  57. package/git_heal_fe/public/github_login_teddy_assets/bottom-agents/mini-bear-branch-card.png +0 -0
  58. package/git_heal_fe/public/github_login_teddy_assets/bottom-agents/mini-bear-code-card.png +0 -0
  59. package/git_heal_fe/public/github_login_teddy_assets/bottom-agents/mini-bear-headphones-coding.png +0 -0
  60. package/git_heal_fe/public/github_login_teddy_assets/bottom-agents/mini-robot-coding.png +0 -0
  61. package/git_heal_fe/public/github_login_teddy_assets/bottom-agents/mini-robot-running.png +0 -0
  62. package/git_heal_fe/public/github_login_teddy_assets/bottom-agents/mini-robot-star.png +0 -0
  63. package/git_heal_fe/public/github_login_teddy_assets/full-mockup.png +0 -0
  64. package/git_heal_fe/public/github_login_teddy_assets/main-bears/bear-raising-pull-request-jwt.png +0 -0
  65. package/git_heal_fe/public/github_login_teddy_assets/main-bears/bear-raising-pull-request.png +0 -0
  66. package/git_heal_fe/public/github_login_teddy_assets/main-bears/bear-reading-repositories.png +0 -0
  67. package/git_heal_fe/public/github_login_teddy_assets/main-bears/bear-repo-eating.png +0 -0
  68. package/git_heal_fe/public/github_login_teddy_assets/ui-elements/github-book.png +0 -0
  69. package/git_heal_fe/public/github_login_teddy_assets/ui-elements/pull-request-card.png +0 -0
  70. package/git_heal_fe/public/github_login_teddy_assets/ui-elements/repository-card.png +0 -0
  71. package/git_heal_fe/public/icons.svg +24 -0
  72. package/git_heal_fe/src/App.css +184 -0
  73. package/git_heal_fe/src/App.tsx +145 -0
  74. package/git_heal_fe/src/assets/hero.png +0 -0
  75. package/git_heal_fe/src/assets/react.svg +1 -0
  76. package/git_heal_fe/src/assets/vite.svg +1 -0
  77. package/git_heal_fe/src/components/BearAnimation.tsx +124 -0
  78. package/git_heal_fe/src/components/DiffPreview.tsx +81 -0
  79. package/git_heal_fe/src/components/GitFlowGraph.css +341 -0
  80. package/git_heal_fe/src/components/GitFlowGraph.tsx +216 -0
  81. package/git_heal_fe/src/components/GitHubLoginPage.css +1097 -0
  82. package/git_heal_fe/src/components/GitHubLoginPage.tsx +171 -0
  83. package/git_heal_fe/src/components/PipelinePreview.tsx +156 -0
  84. package/git_heal_fe/src/components/auth/AuthCallbackPage.tsx +46 -0
  85. package/git_heal_fe/src/components/auth/ProtectedRoute.tsx +68 -0
  86. package/git_heal_fe/src/components/common/AppShell.css +154 -0
  87. package/git_heal_fe/src/components/common/AppShell.tsx +57 -0
  88. package/git_heal_fe/src/components/common/AvatarMenu.css +142 -0
  89. package/git_heal_fe/src/components/common/AvatarMenu.tsx +122 -0
  90. package/git_heal_fe/src/components/common/Breadcrumb.css +58 -0
  91. package/git_heal_fe/src/components/common/Breadcrumb.tsx +59 -0
  92. package/git_heal_fe/src/components/common/ConfirmDialog.css +108 -0
  93. package/git_heal_fe/src/components/common/ConfirmDialog.tsx +82 -0
  94. package/git_heal_fe/src/components/common/DiffCard.css +122 -0
  95. package/git_heal_fe/src/components/common/DiffCard.tsx +76 -0
  96. package/git_heal_fe/src/components/common/FloatingSidebar.css +487 -0
  97. package/git_heal_fe/src/components/common/FloatingSidebar.tsx +228 -0
  98. package/git_heal_fe/src/components/common/LimitBanner.css +65 -0
  99. package/git_heal_fe/src/components/common/LimitBanner.tsx +72 -0
  100. package/git_heal_fe/src/components/common/PageHeader.css +47 -0
  101. package/git_heal_fe/src/components/common/PageHeader.tsx +33 -0
  102. package/git_heal_fe/src/components/common/Skeleton.css +26 -0
  103. package/git_heal_fe/src/components/common/Skeleton.tsx +30 -0
  104. package/git_heal_fe/src/components/common/StatusPill.css +122 -0
  105. package/git_heal_fe/src/components/common/StatusPill.tsx +84 -0
  106. package/git_heal_fe/src/components/common/TokenMeter.css +150 -0
  107. package/git_heal_fe/src/components/common/TokenMeter.tsx +154 -0
  108. package/git_heal_fe/src/components/common/TokenPopover.css +375 -0
  109. package/git_heal_fe/src/components/common/TokenPopover.tsx +366 -0
  110. package/git_heal_fe/src/components/dashboard/DashboardPage.css +588 -0
  111. package/git_heal_fe/src/components/dashboard/DashboardPage.tsx +346 -0
  112. package/git_heal_fe/src/components/dashboard/HealingVelocityChart.css +255 -0
  113. package/git_heal_fe/src/components/dashboard/HealingVelocityChart.tsx +286 -0
  114. package/git_heal_fe/src/components/dashboard/LatestPrSpotlight.css +213 -0
  115. package/git_heal_fe/src/components/dashboard/LatestPrSpotlight.tsx +124 -0
  116. package/git_heal_fe/src/components/dashboard/RepoHealthWidget.css +142 -0
  117. package/git_heal_fe/src/components/dashboard/RepoHealthWidget.tsx +67 -0
  118. package/git_heal_fe/src/components/dashboard/RootCauseWidget.css +103 -0
  119. package/git_heal_fe/src/components/dashboard/RootCauseWidget.tsx +114 -0
  120. package/git_heal_fe/src/components/dashboard/RunRow.css +153 -0
  121. package/git_heal_fe/src/components/dashboard/RunRow.tsx +56 -0
  122. package/git_heal_fe/src/components/dashboard/SandboxFleetWidget.css +138 -0
  123. package/git_heal_fe/src/components/dashboard/SandboxFleetWidget.tsx +67 -0
  124. package/git_heal_fe/src/components/dashboard/StatCard.css +57 -0
  125. package/git_heal_fe/src/components/dashboard/StatCard.tsx +22 -0
  126. package/git_heal_fe/src/components/dashboard/UsageCard.css +65 -0
  127. package/git_heal_fe/src/components/dashboard/UsageCard.tsx +71 -0
  128. package/git_heal_fe/src/components/onboarding/OnboardingPage.css +921 -0
  129. package/git_heal_fe/src/components/onboarding/OnboardingPage.tsx +661 -0
  130. package/git_heal_fe/src/components/prs/HealedPrsPage.css +514 -0
  131. package/git_heal_fe/src/components/prs/HealedPrsPage.tsx +276 -0
  132. package/git_heal_fe/src/components/repos/RepoSettingsPage.css +774 -0
  133. package/git_heal_fe/src/components/repos/RepoSettingsPage.tsx +624 -0
  134. package/git_heal_fe/src/components/repos/RepositoriesPage.css +708 -0
  135. package/git_heal_fe/src/components/repos/RepositoriesPage.tsx +448 -0
  136. package/git_heal_fe/src/components/runs/PipelineTimeline.css +186 -0
  137. package/git_heal_fe/src/components/runs/PipelineTimeline.tsx +84 -0
  138. package/git_heal_fe/src/components/runs/RunDetailPage.css +727 -0
  139. package/git_heal_fe/src/components/runs/RunDetailPage.tsx +556 -0
  140. package/git_heal_fe/src/components/runs/TerminalStream.css +312 -0
  141. package/git_heal_fe/src/components/runs/TerminalStream.tsx +130 -0
  142. package/git_heal_fe/src/components/settings/SettingsPage.css +628 -0
  143. package/git_heal_fe/src/components/settings/SettingsPage.tsx +673 -0
  144. package/git_heal_fe/src/components/settings/ThemeCustomizer.css +379 -0
  145. package/git_heal_fe/src/components/settings/ThemeCustomizer.tsx +286 -0
  146. package/git_heal_fe/src/components/settings/TypedConfirmDialog.css +118 -0
  147. package/git_heal_fe/src/components/settings/TypedConfirmDialog.tsx +92 -0
  148. package/git_heal_fe/src/components/usage/StageBreakdown.css +116 -0
  149. package/git_heal_fe/src/components/usage/StageBreakdown.tsx +113 -0
  150. package/git_heal_fe/src/components/usage/UsageChart.css +129 -0
  151. package/git_heal_fe/src/components/usage/UsageChart.tsx +194 -0
  152. package/git_heal_fe/src/components/usage/UsagePage.css +655 -0
  153. package/git_heal_fe/src/components/usage/UsagePage.tsx +446 -0
  154. package/git_heal_fe/src/context/AuthContext.tsx +94 -0
  155. package/git_heal_fe/src/hooks/useRunPolling.ts +54 -0
  156. package/git_heal_fe/src/hooks/useSSE.ts +131 -0
  157. package/git_heal_fe/src/index.css +29 -0
  158. package/git_heal_fe/src/main.tsx +13 -0
  159. package/git_heal_fe/src/services/api.ts +593 -0
  160. package/git_heal_fe/src/test/guardsAndUtils.test.ts +100 -0
  161. package/git_heal_fe/src/test/stageD_tokenAndShell.test.ts +129 -0
  162. package/git_heal_fe/src/types/index.ts +183 -0
  163. package/git_heal_fe/src/utils/themeManager.ts +134 -0
  164. package/git_heal_fe/src/utils/tokenUtils.ts +110 -0
  165. package/git_heal_fe/tsconfig.app.json +26 -0
  166. package/git_heal_fe/tsconfig.json +7 -0
  167. package/git_heal_fe/tsconfig.node.json +23 -0
  168. package/git_heal_fe/vite.config.ts +24 -0
  169. package/package.json +33 -4
  170. package/soigne.config.json +11 -0
package/README.md CHANGED
@@ -1,3 +1,141 @@
1
- # Temporary Holding Version
1
+ # Soigné (`soigne-ci`) 🩺✨
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **Self-Hosted Autonomous CI/CD Self-Healing Appliance for GitHub Actions**
4
+ > 🌐 **Homepage:** [https://soigne-dev.github.io/home/](https://soigne-dev.github.io/home/)
5
+
6
+ Soigné sits alongside GitHub Actions at your organization or repository level. When a CI build fails, Soigné intercepts the webhook, isolates the failing files and stack trace, synthesizes a surgical patch using **Google Gemini (BYOK)**, verifies the fix inside a network-isolated **Docker sandbox**, and opens a **verified Draft Pull Request**—without your source code ever leaving your own infrastructure.
7
+
8
+ ---
9
+
10
+ ## ✨ Key Features
11
+
12
+ * **Org-Wide, Zero Per-Repo YAML:** Install once at the GitHub Organization level—no need to maintain CI-healing scripts in every repository.
13
+ * **Google Gemini BYOK + Auto-Failover:** Bring your own Google AI Studio key (encrypted at rest with **AES-256-GCM** in PostgreSQL). Includes live model discovery (`GET /v1beta/models`), automatic failover on `429` / `503` / `404` errors, and `usage_metadata` token analytics.
14
+ * **Isolated Docker Sandboxes:** Candidate patches are verified inside `--network none`, `512m` memory-capped Docker containers with up to 3 compiler-feedback retries before raising a PR.
15
+ * **Safety Guardrails:**
16
+ * **Loop Prevention Guard:** Ignores runs on `soigne/fix-*` branches or bot commits so repairs never recurse.
17
+ * **Staleness Gatekeeper:** Compares the failing commit SHA against remote branch `HEAD` and aborts superseded runs before spending tokens.
18
+ * **Draft PRs Only:** Never pushes directly to `main` or protected branches.
19
+ * **Live SSE Terminal & Dashboard:** Real-time Server-Sent Events stream every file read, edit, compiler check, and unified diff to the React dashboard.
20
+
21
+ ---
22
+
23
+ ## 📋 Prerequisites
24
+
25
+ Before running `soigne-ci`, make sure you have:
26
+
27
+ 1. **Node.js 20+**
28
+ 2. **PostgreSQL 16+** (running locally or accessible via `DATABASE_URL`)
29
+ 3. **Docker** (running, used for `--network none` patch verification sandboxes)
30
+ 4. **A GitHub App** (with `Workflow runs` webhook & Pull Request permissions)
31
+ 5. **A Google Gemini API Key** (added and encrypted inside the Settings UI after launch)
32
+
33
+ ---
34
+
35
+ ## 🚀 Quickstart via npm
36
+
37
+ ### Step 1: Initialize Configuration
38
+ In any directory where you want to store your Soigné config, run:
39
+
40
+ ```bash
41
+ npx soigne-ci init
42
+ ```
43
+
44
+ This creates a starter `soigne.config.json` in your current folder with an auto-generated `encryptionKey`:
45
+
46
+ ```json
47
+ {
48
+ "uiPort": 5173,
49
+ "apiPort": 3001,
50
+ "apiUrl": "http://localhost:3001/api",
51
+ "databaseUrl": "postgresql://postgres:postgres@localhost:5432/soigne_db?schema=public",
52
+ "encryptionKey": "<auto-generated-64-char-hex-key>",
53
+ "githubAppId": "",
54
+ "githubPrivateKey": "",
55
+ "githubWebhookSecret": ""
56
+ }
57
+ ```
58
+
59
+ Edit `databaseUrl` and your GitHub App credentials in `soigne.config.json`.
60
+
61
+ ### Step 2: Start Soigné
62
+ ```bash
63
+ npx soigne-ci
64
+ ```
65
+
66
+ On the first run, Soigné automatically:
67
+ 1. Installs backend (`git_heal_be`) and frontend (`git_heal_fe`) dependencies separately.
68
+ 2. Runs `prisma generate` and `prisma db push` against your PostgreSQL database.
69
+ 3. Starts the backend API on `apiPort` (`3001`) and the frontend dashboard on `uiPort` (`5173`).
70
+
71
+ Open **`http://localhost:5173`**, go to **Settings**, and add your **Google Gemini API Key** (it will be encrypted with AES-256-GCM before storage).
72
+
73
+ ---
74
+
75
+ ## 🛠️ CLI Commands & Options
76
+
77
+ ```text
78
+ Usage:
79
+ soigne [command] [options]
80
+
81
+ Commands:
82
+ init Create a starter soigne.config.json in the current folder
83
+ (default) Start Soigné backend and frontend
84
+
85
+ Options:
86
+ --config <path> Path to a custom soigne.config.json
87
+ --ui-port <port> Frontend port (default: 5173)
88
+ --api-port <port> Backend API port (default: 3001)
89
+ --api-url <url> API URL passed to frontend (default: http://localhost:<apiPort>/api)
90
+ --db <url> PostgreSQL connection string
91
+ --skip-db Skip prisma generate & db push on startup
92
+ --force Overwrite existing soigne.config.json when running init
93
+ -h, --help Show this help message
94
+ ```
95
+
96
+ ### Examples
97
+
98
+ Use custom ports:
99
+ ```bash
100
+ npx soigne-ci --ui-port 8080 --api-port 4000
101
+ ```
102
+
103
+ Run behind a production reverse proxy domain:
104
+ ```bash
105
+ npx soigne-ci --ui-port 5173 --api-port 3001 --api-url https://soigne.company.com/api
106
+ ```
107
+
108
+ Use a specific config file and skip DB sync on restart:
109
+ ```bash
110
+ npx soigne-ci --config ./prod.config.json --skip-db
111
+ ```
112
+
113
+ ---
114
+
115
+ ## 🌐 Supported Languages & Verification
116
+
117
+ Soigné automatically runs static syntax checks by default, and supports per-repository `testCommand` overrides in the dashboard:
118
+
119
+ | Language / Stack | Extensions | Default Sandbox Check | Recommended `testCommand` |
120
+ | :--- | :--- | :--- | :--- |
121
+ | **JavaScript / TypeScript** | `.js`, `.jsx`, `.ts`, `.tsx`, `.mjs` | `node --check` | `npm test -- --bail` |
122
+ | **Python** | `.py` | `python -m py_compile` | `pytest -x` |
123
+ | **Go** | `.go` | `go vet` | `go test ./... -failfast` |
124
+ | **Rust** | `.rs` | `cargo check` | `cargo test` |
125
+ | **Java** | `.java` | `javac` | `mvn test` |
126
+
127
+ ---
128
+
129
+ ## 🔗 Connecting GitHub Webhooks
130
+
131
+ * **Production (behind your domain):** Set your GitHub App / repo webhook URL to `https://your-domain.com/api/webhooks/github` (`application/json`, event: **Workflow runs**).
132
+ * **Local testing:** Forward GitHub webhooks to your local backend with [Smee.io](https://smee.io/):
133
+ ```bash
134
+ npx smee-client --url https://smee.io/YOUR_CHANNEL --target http://localhost:3001/api/webhooks/github
135
+ ```
136
+
137
+ ---
138
+
139
+ ## 📄 License
140
+
141
+ MIT License — see [https://soigne-dev.github.io/home/](https://soigne-dev.github.io/home/) for more details.
package/bin/soigne.js ADDED
@@ -0,0 +1,223 @@
1
+ #!/usr/bin/env node
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import crypto from 'node:crypto';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { spawn, spawnSync } from 'node:child_process';
7
+ import { parseArgs } from 'node:util';
8
+
9
+ const __filename = fileURLToPath(import.meta.url);
10
+ const __dirname = path.dirname(__filename);
11
+ const PKG_ROOT = path.resolve(__dirname, '..');
12
+ const BE_DIR = path.join(PKG_ROOT, 'git_heal_be');
13
+ const FE_DIR = path.join(PKG_ROOT, 'git_heal_fe');
14
+
15
+ function printHelp() {
16
+ console.log(`
17
+ Soigné — Self-Hosted Autonomous CI/CD Healing Appliance
18
+
19
+ Usage:
20
+ soigne [command] [options]
21
+
22
+ Commands:
23
+ init Create a starter soigne.config.json in the current folder
24
+ (default) Start Soigné backend and frontend
25
+
26
+ Options:
27
+ --config <path> Path to a custom soigne.config.json
28
+ --ui-port <port> Frontend port (default: 5173)
29
+ --api-port <port> Backend API port (default: 3001)
30
+ --api-url <url> API URL passed to frontend (default: http://localhost:<apiPort>/api)
31
+ --db <url> PostgreSQL connection string
32
+ --skip-db Skip prisma generate & db push on startup
33
+ --force Overwrite existing soigne.config.json when running init
34
+ -h, --help Show this help message
35
+ `);
36
+ }
37
+
38
+ function readJsonIfExists(filePath) {
39
+ if (!filePath || !fs.existsSync(filePath)) return {};
40
+ try {
41
+ return JSON.parse(fs.readFileSync(filePath, 'utf8'));
42
+ } catch (err) {
43
+ console.error(`[soigne] Failed to parse config file ${filePath}:`, err.message);
44
+ process.exit(1);
45
+ }
46
+ }
47
+
48
+ function resolveBin(name, searchDirs) {
49
+ const isWin = process.platform === 'win32';
50
+ const binName = isWin ? `${name}.cmd` : name;
51
+ for (const dir of searchDirs) {
52
+ const candidate = path.join(dir, 'node_modules', '.bin', binName);
53
+ if (fs.existsSync(candidate)) return candidate;
54
+ }
55
+ return binName;
56
+ }
57
+
58
+ function ensureInstalled(dir, label) {
59
+ if (fs.existsSync(path.join(dir, 'node_modules'))) return;
60
+ console.log(`[soigne] Installing ${label} dependencies...`);
61
+ const isWin = process.platform === 'win32';
62
+ const res = spawnSync(isWin ? 'npm.cmd' : 'npm', ['install'], {
63
+ cwd: dir,
64
+ stdio: 'inherit',
65
+ shell: isWin,
66
+ });
67
+ if (res.status !== 0) {
68
+ console.error(`[soigne] Failed to install ${label} dependencies.`);
69
+ process.exit(res.status || 1);
70
+ }
71
+ }
72
+
73
+ const { values, positionals } = parseArgs({
74
+ options: {
75
+ config: { type: 'string' },
76
+ 'ui-port': { type: 'string' },
77
+ 'api-port': { type: 'string' },
78
+ 'api-url': { type: 'string' },
79
+ db: { type: 'string' },
80
+ 'skip-db': { type: 'boolean', default: false },
81
+ force: { type: 'boolean', default: false },
82
+ help: { type: 'boolean', short: 'h', default: false },
83
+ },
84
+ allowPositionals: true,
85
+ });
86
+
87
+ if (values.help) {
88
+ printHelp();
89
+ process.exit(0);
90
+ }
91
+
92
+ if (positionals[0] === 'init') {
93
+ const targetPath = path.join(process.cwd(), 'soigne.config.json');
94
+ if (fs.existsSync(targetPath) && !values.force) {
95
+ console.error(`[soigne] ${targetPath} already exists. Use --force to overwrite.`);
96
+ process.exit(1);
97
+ }
98
+ const starterConfig = {
99
+ uiPort: 5173,
100
+ apiPort: 3001,
101
+ apiUrl: 'http://localhost:3001/api',
102
+ databaseUrl: 'postgresql://postgres:postgres@localhost:5432/soigne_db?schema=public',
103
+ encryptionKey: crypto.randomBytes(32).toString('hex'),
104
+ githubAppId: '',
105
+ githubPrivateKey: '',
106
+ githubWebhookSecret: '',
107
+ };
108
+ fs.writeFileSync(targetPath, JSON.stringify(starterConfig, null, 2) + '\n', 'utf8');
109
+ console.log(`[soigne] Created ${targetPath}`);
110
+ console.log('[soigne] Edit databaseUrl and GitHub App fields if needed, then run: soigne');
111
+ process.exit(0);
112
+ }
113
+
114
+ const defaultConfig = readJsonIfExists(path.join(PKG_ROOT, 'soigne.config.json'));
115
+ const cwdConfigPath = values.config
116
+ ? path.resolve(process.cwd(), values.config)
117
+ : path.join(process.cwd(), 'soigne.config.json');
118
+ const userConfig = cwdConfigPath !== path.join(PKG_ROOT, 'soigne.config.json')
119
+ ? readJsonIfExists(cwdConfigPath)
120
+ : {};
121
+
122
+ const config = { ...defaultConfig, ...userConfig };
123
+
124
+ if (values['ui-port']) config.uiPort = Number(values['ui-port']);
125
+ if (values['api-port']) {
126
+ config.apiPort = Number(values['api-port']);
127
+ if (!values['api-url'] && !userConfig.apiUrl) {
128
+ config.apiUrl = `http://localhost:${config.apiPort}/api`;
129
+ }
130
+ }
131
+ if (values['api-url']) config.apiUrl = values['api-url'];
132
+ if (values.db) config.databaseUrl = values.db;
133
+
134
+ const beEnv = {
135
+ ...process.env,
136
+ PORT: String(config.apiPort || 3001),
137
+ ...(config.databaseUrl ? { DATABASE_URL: config.databaseUrl } : {}),
138
+ ...(config.encryptionKey ? { ENCRYPTION_KEY: config.encryptionKey } : {}),
139
+ ...(config.geminiApiKey ? { GEMINI_API_KEY: config.geminiApiKey } : {}),
140
+ ...(config.githubAppId ? { GITHUB_APP_ID: config.githubAppId } : {}),
141
+ ...(config.githubPrivateKey ? { GITHUB_PRIVATE_KEY: config.githubPrivateKey } : {}),
142
+ ...(config.githubWebhookSecret ? { GITHUB_WEBHOOK_SECRET: config.githubWebhookSecret } : {}),
143
+ };
144
+
145
+ const feEnv = {
146
+ ...process.env,
147
+ VITE_API_BASE_URL: config.apiUrl,
148
+ VITE_API_URL: config.apiUrl,
149
+ };
150
+
151
+ const isWin = process.platform === 'win32';
152
+
153
+ ensureInstalled(BE_DIR, 'backend');
154
+ ensureInstalled(FE_DIR, 'frontend');
155
+
156
+ if (!values['skip-db']) {
157
+ console.log('[soigne] Generating Prisma client...');
158
+ const prismaBin = resolveBin('prisma', [BE_DIR, PKG_ROOT]);
159
+ const gen = spawnSync(prismaBin, ['generate', '--config', 'prisma7.config.ts'], {
160
+ cwd: BE_DIR,
161
+ env: beEnv,
162
+ stdio: 'inherit',
163
+ shell: isWin,
164
+ });
165
+ if (gen.status !== 0) {
166
+ console.warn('[soigne] prisma generate exited with non-zero status; continuing...');
167
+ }
168
+
169
+ console.log('[soigne] Pushing database schema...');
170
+ const push = spawnSync(prismaBin, ['db', 'push', '--config', 'prisma7.config.ts'], {
171
+ cwd: BE_DIR,
172
+ env: beEnv,
173
+ stdio: 'inherit',
174
+ shell: isWin,
175
+ });
176
+ if (push.status !== 0) {
177
+ console.warn('[soigne] prisma db push failed (is PostgreSQL running?). Continuing startup...');
178
+ }
179
+ }
180
+
181
+ console.log(`[soigne] Starting backend on port ${beEnv.PORT}...`);
182
+ const tsxBin = resolveBin('tsx', [BE_DIR, PKG_ROOT]);
183
+ const beProc = spawn(tsxBin, ['src/index.ts'], {
184
+ cwd: BE_DIR,
185
+ env: beEnv,
186
+ stdio: 'inherit',
187
+ shell: isWin,
188
+ });
189
+
190
+ console.log(`[soigne] Starting frontend on port ${config.uiPort} -> ${config.apiUrl}...`);
191
+ const viteBin = resolveBin('vite', [FE_DIR, PKG_ROOT]);
192
+ const feProc = spawn(viteBin, ['--port', String(config.uiPort), '--host'], {
193
+ cwd: FE_DIR,
194
+ env: feEnv,
195
+ stdio: 'inherit',
196
+ shell: isWin,
197
+ });
198
+
199
+ function shutdown(signal) {
200
+ console.log(`\n[soigne] Received ${signal}, shutting down...`);
201
+ if (!beProc.killed) beProc.kill('SIGTERM');
202
+ if (!feProc.killed) feProc.kill('SIGTERM');
203
+ process.exit(0);
204
+ }
205
+
206
+ process.on('SIGINT', () => shutdown('SIGINT'));
207
+ process.on('SIGTERM', () => shutdown('SIGTERM'));
208
+
209
+ beProc.on('exit', (code) => {
210
+ if (code !== 0 && code !== null) {
211
+ console.error(`[soigne] Backend exited with code ${code}`);
212
+ if (!feProc.killed) feProc.kill('SIGTERM');
213
+ process.exit(code);
214
+ }
215
+ });
216
+
217
+ feProc.on('exit', (code) => {
218
+ if (code !== 0 && code !== null) {
219
+ console.error(`[soigne] Frontend exited with code ${code}`);
220
+ if (!beProc.killed) beProc.kill('SIGTERM');
221
+ process.exit(code);
222
+ }
223
+ });
@@ -0,0 +1,242 @@
1
+ # Soigné 🩺✨
2
+
3
+ > **The Autonomous Self-Healing CI/CD Engine for GitHub**
4
+ > When your GitHub Actions pipeline fails, Soigné intercepts the build, isolates the regression, synthesizes a surgical fix with Google Gemini BYOK, verifies the patch inside an isolated sandbox, and delivers a verified Pull Request—in under 45 seconds.
5
+
6
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.0+-3178C6?style=flat&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
7
+ [![Node.js](https://img.shields.io/badge/Node.js-20+-339933?style=flat&logo=node.js&logoColor=white)](https://nodejs.org/)
8
+ [![React](https://img.shields.io/badge/React-18-61DAFB?style=flat&logo=react&logoColor=black)](https://react.dev/)
9
+ [![PostgreSQL](https://img.shields.io/badge/PostgreSQL-16+-4169E1?style=flat&logo=postgresql&logoColor=white)](https://www.postgresql.org/)
10
+ [![Prisma](https://img.shields.io/badge/Prisma-7.0+-2D3748?style=flat&logo=prisma&logoColor=white)](https://www.prisma.io/)
11
+ [![Docker](https://img.shields.io/badge/Docker-Sandbox-2496ED?style=flat&logo=docker&logoColor=white)](https://www.docker.com/)
12
+ [![Gemini](https://img.shields.io/badge/Google%20Gemini-BYOK-8E75C2?style=flat&logo=google-gemini&logoColor=white)](https://ai.google.dev/)
13
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
14
+
15
+ ---
16
+
17
+ ## 📖 The Story of Soigné
18
+
19
+ In French, **soigné** describes something crafted with meticulous attention to detail, elegance, and thoroughness.
20
+
21
+ In modern software development, Continuous Integration was meant to give teams velocity and confidence. Instead, developers spend hours every week dealing with **CI fatigue**:
22
+ * A missing bracket or dangling semicolon breaks a 15-minute test run.
23
+ * A subtle type mismatch prevents a pull request from merging late in the sprint.
24
+ * Developers context-switch away from high-leverage feature work just to wade through thousands of lines of raw terminal logs.
25
+
26
+ We asked a simple question:
27
+ **What if your CI pipeline didn't just notify you when a build broke, but actively diagnosed the failure, tested a surgical fix in isolation, and prepared the solution for you?**
28
+
29
+ That is **Soigné**. It acts as an autonomous on-call engineer sitting between GitHub Actions and your repository: always vigilant, never guessing, and never submitting code that hasn't passed local compiler and test validation first.
30
+
31
+ ---
32
+
33
+ ## 🛑 The Problem Soigné Solves
34
+
35
+ Traditional CI/CD systems are entirely **passive**:
36
+
37
+ ```
38
+ Developer pushes code ➔ GitHub Actions runs ➔ Build fails (❌) ➔ Developer context-switches
39
+ ➔ Digs through 2,000 lines of logs ➔ Finds typo on line 42 ➔ Fixes manually ➔ Pushes again
40
+ ```
41
+
42
+ This passive feedback loop leads to:
43
+ 1. **Wasted Engineering Hours:** Engineers spending 20–30% of their time babysitting broken builds.
44
+ 2. **Context Switching Costs:** Losing flow state to fix trivial syntax, import, or assertion errors.
45
+ 3. **Flaky & Blind AI Commits:** Existing "AI fix" tools often push unverified code straight to branches, causing secondary pipeline breaks.
46
+
47
+ ---
48
+
49
+ ## 💡 The Solution: How Soigné Works
50
+
51
+ Soigné introduces a closed-loop, deterministic healing pipeline that takes a broken workflow run and delivers a verified fix in under 45 seconds:
52
+
53
+ ```
54
+ [ GitHub Actions Build Fails ]
55
+ │
56
+ ▼ (Webhook)
57
+ [ 1. Guardrails & Staleness ]
58
+ ├── Stale commit? ──► Skip (0 tokens wasted)
59
+ └── Self-branch? ──► Stop (No recursive loops)
60
+ │
61
+ ▼
62
+ [ 2. Matrix Log Scraper ]
63
+ └── Extracts failure type, target file, & stack trace
64
+ │
65
+ ▼
66
+ [ 3. Ephemeral Workspace ]
67
+ └── Clones clean repository commit into isolation
68
+ │
69
+ ▼
70
+ [ 4. Gemini BYOK Agent ]
71
+ └── Surgical patch generation (reads & edits code)
72
+ └── Dynamic failover on 429 / 503 / 404
73
+ │
74
+ ▼
75
+ [ 5. Sandbox Verification ]
76
+ └── Runs `testCommand` / language compiler
77
+ ├── Fails? ──► Feed compiler error back (Up to 3 retries)
78
+ └── Passes!
79
+ │
80
+ ▼
81
+ [ 6. Autonomous Delivery ]
82
+ └── Opens GitHub Pull Request (or Draft PR)
83
+ │
84
+ ▼
85
+ [ 7. Live SSE Stream ]
86
+ └── Real-time terminal log displayed on dashboard
87
+ ```
88
+
89
+ ---
90
+
91
+ ## 🌐 Supported Tech Stacks & Languages
92
+
93
+ Soigné is built to be language-agnostic. Out of the box, it inspects your repository, extracts failure diagnostics from test runners, and verifies patches before pushing code.
94
+
95
+ ### Supported Language Matrix
96
+
97
+ | Language / Stack | File Extensions | Default Sandbox Verification | Recommended `testCommand` Override | Popular Frameworks Supported |
98
+ | :--- | :--- | :--- | :--- | :--- |
99
+ | **JavaScript / TypeScript** | `.js`, `.jsx`, `.ts`, `.tsx`, `.mjs` | `node --check`, AST integrity | `npm test -- --bail` or `pnpm test` | Vitest, Jest, Mocha, Bun, Node Test Runner |
100
+ | **Python** | `.py` | `python -m py_compile "<file>"` | `pytest -x` or `python -m unittest` | Pytest, Unittest, Poetry, Pipenv, Flake8 |
101
+ | **Java** | `.java` | `javac "<file>"` | `mvn test -DfailIfNoTests=false` | JUnit 5, TestNG, Maven, Gradle |
102
+ | **Go** | `.go` | `go vet "<file>"` | `go test ./... -v -failfast` | Go Test, Ginkgo, Testify |
103
+ | **Rust** | `.rs` | `cargo check` | `cargo test` | Cargo Test, Tokio, Rust standard tests |
104
+
105
+ ### How the Sandbox Test Command Override Works
106
+ Under **Repo Settings $\rightarrow$ Sandbox Test Command Override**, developers can define the exact command executed inside the isolated workspace container:
107
+ * Enter `npm test -- --bail` for fast-failing Node.js projects.
108
+ * Enter `pytest -x` for Python projects to stop immediately upon first error.
109
+ * Enter `go test ./...` for Go modules.
110
+
111
+ If the command exits with code `0`, Soigné considers the repair verified and raises the Pull Request.
112
+
113
+ ---
114
+
115
+ ## 🧠 Google Gemini BYOK (Bring Your Own Key)
116
+
117
+ Soigné relies on **Google Gemini** for high-speed, deep-reasoning code repair:
118
+
119
+ ### 1. Zero Vendor Lock-in (BYOK)
120
+ You bring your own Google AI Studio API key. Your key is encrypted with **AES-256-GCM** before being stored in your local PostgreSQL database.
121
+
122
+ ### 2. Live Model Discovery
123
+ Soigné dynamically queries `GET /v1beta/models` using your key to discover which models are active and available in your tier (e.g. `gemini-2.5-flash`, `gemini-2.5-pro`, `gemini-1.5-flash`).
124
+
125
+ ### 3. Automatic Zero-Downtime Failover
126
+ If Google returns:
127
+ * `429 (Resource Exhausted / Rate Quota)`
128
+ * `503 (Model Overloaded)`
129
+ * `404 (Model Not Found / Deprecated)`
130
+
131
+ Soigné dynamically fails over to the next best available model in real time without failing the run.
132
+
133
+ ### 4. Transparent Token Tracking
134
+ Token counts are extracted directly from API response metadata (`usage_metadata`) and recorded in PostgreSQL. You can view your exact prompt, candidate, and total token usage in the **Token Analytics** dashboard.
135
+
136
+ ---
137
+
138
+ ## 🚀 How to Use Soigné (Developer Walkthrough)
139
+
140
+ ### Step 1: Clone and Install Dependencies
141
+
142
+ ```bash
143
+ git clone https://github.com/priyanshnihalani/soigne.git
144
+ cd soigne
145
+
146
+ # Install backend dependencies
147
+ cd git_heal_be
148
+ npm install
149
+
150
+ # Install frontend dependencies
151
+ cd ../git_heal_fe
152
+ npm install
153
+ ```
154
+
155
+ ### Step 2: Configure Environment Variables
156
+
157
+ Create `.env` in `git_heal_be`:
158
+ ```env
159
+ PORT=3001
160
+ DATABASE_URL="postgresql://postgres:postgres@localhost:5432/soigne_db?schema=public"
161
+ ENCRYPTION_KEY="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
162
+ GITHUB_APP_ID="your-github-app-id"
163
+ GITHUB_PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\n..."
164
+ GITHUB_WEBHOOK_SECRET="your-webhook-secret"
165
+ GEMINI_API_KEY="AIzaSy..."
166
+ ```
167
+
168
+ Create `.env` in `git_heal_fe`:
169
+ ```env
170
+ VITE_API_BASE_URL="http://localhost:3001/api"
171
+ ```
172
+
173
+ ### Step 3: Run Database Migrations
174
+
175
+ ```bash
176
+ cd git_heal_be
177
+ npx prisma db push
178
+ ```
179
+
180
+ ### Step 4: Start the Platform
181
+
182
+ In terminal 1 (Backend):
183
+ ```bash
184
+ cd git_heal_be
185
+ npm run dev
186
+ # Server running at http://localhost:3001
187
+ ```
188
+
189
+ In terminal 2 (Frontend):
190
+ ```bash
191
+ cd git_heal_fe
192
+ npm run dev
193
+ # Dashboard running at http://localhost:5173
194
+ ```
195
+
196
+ ### Step 5: Connect GitHub Webhooks
197
+
198
+ To forward GitHub Actions failure events to your local instance, use a webhook forwarder such as [Smee.io](https://smee.io/):
199
+
200
+ ```bash
201
+ npx smee-client --url https://smee.io/YOUR_SMEE_CHANNEL --target http://localhost:3001/api/webhooks/github
202
+ ```
203
+
204
+ In your GitHub repository:
205
+ 1. Navigate to **Settings $\rightarrow$ Webhooks $\rightarrow$ Add webhook**.
206
+ 2. **Payload URL:** Your Smee channel URL.
207
+ 3. **Content type:** `application/json`.
208
+ 4. **Events:** Check **Workflow runs** (`workflow_run`).
209
+
210
+ ### Step 6: Experience Autonomous Self-Healing
211
+
212
+ 1. Make a typo or break a test assertion on your repository branch and push to GitHub.
213
+ 2. GitHub Actions runs and fails.
214
+ 3. Open `http://localhost:5173`:
215
+ - Watch the **Live Streaming Terminal** output the log scrape, reasoning phase, and sandbox verification.
216
+ - Within seconds, Soigné opens a verified Pull Request on GitHub with the exact diff and diagnostic explanation.
217
+
218
+ ---
219
+
220
+ ## 🖥️ Live Streaming Terminal & Dashboard
221
+
222
+ The frontend dashboard provides full transparency into the autonomous agent:
223
+ * **Live Terminal Stream:** Color-coded Server-Sent Events (SSE) streaming every file read, edit, compiler output, and git operation live.
224
+ * **Root Cause Tab:** Displays extracted error lines with code highlights and actionable recommendations.
225
+ * **Proposed Patch Tab:** Unified color-coded git diff (`+` additions, `-` deletions).
226
+ * **Sandbox Results Tab:** Execution times, compiler status, and verified test suites.
227
+ * **Agent Reasoning Tab:** Step-by-step breakdown of agent hypotheses and repair decisions.
228
+
229
+ ---
230
+
231
+ ## 🛡️ Guardrails & Safety Architecture
232
+
233
+ * **Loop Prevention Guard:** Rejects any runs triggered on branches prefixed with `soigne/fix-*` or authored by bots, preventing infinite CI loops.
234
+ * **Staleness Gatekeeper:** Inspects the current branch `HEAD` SHA. If the commit is superseded by a newer push, healing is safely aborted to save tokens and prevent merge conflicts.
235
+ * **Isolated Ephemeral Workspaces:** All patch experiments are conducted in isolated directories (`.workspaces/${runId}`) and cleaned up immediately after verification.
236
+ * **Protected Branch Security:** Soigné never pushes directly to protected branches; fixes are exclusively delivered as Pull Requests.
237
+
238
+ ---
239
+
240
+ ## 📄 License
241
+
242
+ This project is open-source software licensed under the MIT License. See [LICENSE](LICENSE) for terms.
@@ -0,0 +1,41 @@
1
+ {
2
+ "devDependencies": {
3
+ "@types/cors": "^2.8.19",
4
+ "@types/dotenv": "^6.1.1",
5
+ "@types/express": "^5.0.6",
6
+ "@types/node": "^26.6.5",
7
+ "prisma": "^7.10.1",
8
+ "tsx": "^4.23.15",
9
+ "typescript": "^7.0.2"
10
+ },
11
+ "dependencies": {
12
+ "@langchain/core": "^1.2.17",
13
+ "@langchain/google-genai": "^2.3.2",
14
+ "@langchain/langgraph": "^1.5.0",
15
+ "@prisma/adapter-pg": "^7.10.1",
16
+ "@prisma/client": "^7.10.1",
17
+ "cors": "^2.8.6",
18
+ "dotenv": "^18.0.7",
19
+ "express": "^5.3.0",
20
+ "jsonwebtoken": "^9.0.3",
21
+ "langchain": "^1.5.16",
22
+ "pg": "^8.23.1"
23
+ },
24
+ "name": "soigne_be",
25
+ "version": "1.0.0",
26
+ "description": "Soigné - Autonomous Self-Healing CI/CD Agent Backend",
27
+ "main": "index.js",
28
+ "scripts": {
29
+ "dev": "tsx watch src/index.ts",
30
+ "build": "tsc",
31
+ "start": "node dist/index.js",
32
+ "db:generate": "prisma generate",
33
+ "db:push": "prisma db push",
34
+ "db:migrate": "prisma migrate dev --config prisma7.config.ts",
35
+ "db:studio": "prisma studio --config prisma7.config.ts"
36
+ },
37
+ "keywords": [],
38
+ "author": "",
39
+ "license": "ISC",
40
+ "type": "module"
41
+ }