@codepulse-oss/github 0.0.0-stage → 3.0.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/dist/__tests__/attribution.test.d.ts +2 -0
- package/dist/__tests__/attribution.test.d.ts.map +1 -0
- package/dist/__tests__/attribution.test.js +34 -0
- package/dist/__tests__/attribution.test.js.map +1 -0
- package/dist/__tests__/device-flow.test.d.ts +2 -0
- package/dist/__tests__/device-flow.test.d.ts.map +1 -0
- package/dist/__tests__/device-flow.test.js +94 -0
- package/dist/__tests__/device-flow.test.js.map +1 -0
- package/dist/__tests__/phase3.test.d.ts +2 -0
- package/dist/__tests__/phase3.test.d.ts.map +1 -0
- package/dist/__tests__/phase3.test.js +203 -0
- package/dist/__tests__/phase3.test.js.map +1 -0
- package/dist/__tests__/v2-providers.test.d.ts +2 -0
- package/dist/__tests__/v2-providers.test.d.ts.map +1 -0
- package/dist/__tests__/v2-providers.test.js +54 -0
- package/dist/__tests__/v2-providers.test.js.map +1 -0
- package/dist/__tests__/v3-check-runs.test.d.ts +2 -0
- package/dist/__tests__/v3-check-runs.test.d.ts.map +1 -0
- package/dist/__tests__/v3-check-runs.test.js +43 -0
- package/dist/__tests__/v3-check-runs.test.js.map +1 -0
- package/dist/app-manifest.d.ts +38 -0
- package/dist/app-manifest.d.ts.map +1 -0
- package/dist/app-manifest.js +138 -0
- package/dist/app-manifest.js.map +1 -0
- package/dist/auth.d.ts +18 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +54 -0
- package/dist/auth.js.map +1 -0
- package/dist/babysitter.d.ts +25 -0
- package/dist/babysitter.d.ts.map +1 -0
- package/dist/babysitter.js +94 -0
- package/dist/babysitter.js.map +1 -0
- package/dist/check-runs.d.ts +44 -0
- package/dist/check-runs.d.ts.map +1 -0
- package/dist/check-runs.js +105 -0
- package/dist/check-runs.js.map +1 -0
- package/dist/commands.d.ts +27 -0
- package/dist/commands.d.ts.map +1 -0
- package/dist/commands.js +125 -0
- package/dist/commands.js.map +1 -0
- package/dist/commit-fix.d.ts +22 -0
- package/dist/commit-fix.d.ts.map +1 -0
- package/dist/commit-fix.js +67 -0
- package/dist/commit-fix.js.map +1 -0
- package/dist/device-flow.d.ts +64 -0
- package/dist/device-flow.d.ts.map +1 -0
- package/dist/device-flow.js +127 -0
- package/dist/device-flow.js.map +1 -0
- package/dist/hunk-mapper.d.ts +58 -0
- package/dist/hunk-mapper.d.ts.map +1 -0
- package/dist/hunk-mapper.js +239 -0
- package/dist/hunk-mapper.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/poller.d.ts +47 -0
- package/dist/poller.d.ts.map +1 -0
- package/dist/poller.js +174 -0
- package/dist/poller.js.map +1 -0
- package/dist/providers/bitbucket.d.ts +29 -0
- package/dist/providers/bitbucket.d.ts.map +1 -0
- package/dist/providers/bitbucket.js +63 -0
- package/dist/providers/bitbucket.js.map +1 -0
- package/dist/providers/gitlab.d.ts +29 -0
- package/dist/providers/gitlab.d.ts.map +1 -0
- package/dist/providers/gitlab.js +67 -0
- package/dist/providers/gitlab.js.map +1 -0
- package/dist/repo-cache.d.ts +15 -0
- package/dist/repo-cache.d.ts.map +1 -0
- package/dist/repo-cache.js +59 -0
- package/dist/repo-cache.js.map +1 -0
- package/dist/stacked-pr.d.ts +18 -0
- package/dist/stacked-pr.d.ts.map +1 -0
- package/dist/stacked-pr.js +22 -0
- package/dist/stacked-pr.js.map +1 -0
- package/package.json +35 -4
- package/README.md +0 -3
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import { writeFileAtomic } from '@codepulse-oss/core';
|
|
5
|
+
/**
|
|
6
|
+
* Build the official GitHub App Manifest payload requesting minimal permissions
|
|
7
|
+
* (`pull_requests: write`, `checks: write`, `contents: read`, `issues: write`, `metadata: read`)
|
|
8
|
+
* and PR/comment webhook events.
|
|
9
|
+
*/
|
|
10
|
+
export function buildGitHubAppManifest(options) {
|
|
11
|
+
const baseUrl = options.baseUrl.replace(/\/$/, '');
|
|
12
|
+
const webhookUrl = options.webhookUrl ?? `${baseUrl}/api/webhooks/github`;
|
|
13
|
+
return {
|
|
14
|
+
name: options.appName ?? `CodePulse Bot (${crypto.randomBytes(2).toString('hex')})`,
|
|
15
|
+
url: 'https://github.com/ymorningstar/CodePulse',
|
|
16
|
+
hook_attributes: {
|
|
17
|
+
url: webhookUrl,
|
|
18
|
+
active: true
|
|
19
|
+
},
|
|
20
|
+
redirect_url: `${baseUrl}/api/github/app-callback`,
|
|
21
|
+
callback_urls: [`${baseUrl}/api/github/app-callback`],
|
|
22
|
+
public: false,
|
|
23
|
+
default_events: ['pull_request', 'issue_comment', 'pull_request_review_comment'],
|
|
24
|
+
default_permissions: {
|
|
25
|
+
pull_requests: 'write',
|
|
26
|
+
checks: 'write',
|
|
27
|
+
contents: 'read',
|
|
28
|
+
issues: 'write',
|
|
29
|
+
metadata: 'read'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Build an auto-submitting HTML page that redirects the user cleanly to
|
|
35
|
+
* `https://github.com/settings/apps/new` with the JSON manifest payload.
|
|
36
|
+
*/
|
|
37
|
+
export function renderGitHubManifestRedirectHtml(options) {
|
|
38
|
+
const manifestJson = JSON.stringify(buildGitHubAppManifest(options));
|
|
39
|
+
const actionUrl = options.org
|
|
40
|
+
? `https://github.com/organizations/${encodeURIComponent(options.org)}/settings/apps/new`
|
|
41
|
+
: 'https://github.com/settings/apps/new';
|
|
42
|
+
const escapedJson = manifestJson
|
|
43
|
+
.replace(/&/g, '&')
|
|
44
|
+
.replace(/"/g, '"')
|
|
45
|
+
.replace(/</g, '<')
|
|
46
|
+
.replace(/>/g, '>');
|
|
47
|
+
return `<!DOCTYPE html>
|
|
48
|
+
<html lang="en">
|
|
49
|
+
<head><meta charset="utf-8" /><title>Connect CodePulse GitHub App</title></head>
|
|
50
|
+
<body style="background:#0b0f17;color:#e6edf7;font-family:system-ui,sans-serif;padding:40px;">
|
|
51
|
+
<h2>Redirecting to GitHub App Manifest Setup...</h2>
|
|
52
|
+
<form id="manifestForm" method="post" action="${actionUrl}">
|
|
53
|
+
<input type="hidden" name="manifest" value="${escapedJson}" />
|
|
54
|
+
<button type="submit" style="padding:10px 18px;background:#3b82f6;color:#fff;border:0;border-radius:6px;cursor:pointer;">
|
|
55
|
+
Create CodePulse GitHub App
|
|
56
|
+
</button>
|
|
57
|
+
</form>
|
|
58
|
+
<script>document.getElementById('manifestForm').submit();</script>
|
|
59
|
+
</body>
|
|
60
|
+
</html>`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Exchange the temporary `code` from GitHub App Manifest callback for permanent
|
|
64
|
+
* App ID, Webhook Secret, and PEM Private Key.
|
|
65
|
+
*/
|
|
66
|
+
export async function exchangeGitHubAppManifestCode(code, fetchImpl = globalThis.fetch) {
|
|
67
|
+
const res = await fetchImpl(`https://api.github.com/app-manifests/${encodeURIComponent(code)}/conversions`, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: {
|
|
70
|
+
Accept: 'application/vnd.github+json',
|
|
71
|
+
'User-Agent': 'CodePulse-App-Setup'
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (!res.ok) {
|
|
75
|
+
const errText = await res.text().catch(() => '');
|
|
76
|
+
throw new Error(`GitHub App Manifest exchange failed (${res.status}): ${errText.slice(0, 300)}`);
|
|
77
|
+
}
|
|
78
|
+
const data = (await res.json());
|
|
79
|
+
if (!data.id || !data.pem) {
|
|
80
|
+
throw new Error('GitHub App Manifest response missing App ID or PEM private key.');
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
appId: String(data.id),
|
|
84
|
+
slug: data.slug,
|
|
85
|
+
webhookSecret: data.webhook_secret ?? '',
|
|
86
|
+
privateKey: data.pem,
|
|
87
|
+
htmlUrl: data.html_url
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Persist exchanged GitHub App credentials locally in `.env` ONLY (never SQLite or git).
|
|
92
|
+
*/
|
|
93
|
+
export async function persistGitHubAppCredentialsToEnv(envFilePath, creds) {
|
|
94
|
+
const absPath = path.resolve(envFilePath);
|
|
95
|
+
const existing = await fs.readFile(absPath, 'utf8').catch(() => '');
|
|
96
|
+
const escapedPem = creds.privateKey.replace(/\r?\n/g, '\\n');
|
|
97
|
+
const updates = {
|
|
98
|
+
GITHUB_APP_ID: creds.appId,
|
|
99
|
+
GITHUB_WEBHOOK_SECRET: creds.webhookSecret,
|
|
100
|
+
GITHUB_APP_PRIVATE_KEY: `"${escapedPem}"`
|
|
101
|
+
};
|
|
102
|
+
const lines = existing ? existing.split(/\r?\n/) : [];
|
|
103
|
+
const seen = new Set();
|
|
104
|
+
const outLines = lines.map((line) => {
|
|
105
|
+
const m = /^([A-Za-z0-9_]+)\s*=/.exec(line);
|
|
106
|
+
if (m && m[1] && m[1] in updates) {
|
|
107
|
+
seen.add(m[1]);
|
|
108
|
+
return `${m[1]}=${updates[m[1]]}`;
|
|
109
|
+
}
|
|
110
|
+
return line;
|
|
111
|
+
});
|
|
112
|
+
for (const [k, v] of Object.entries(updates)) {
|
|
113
|
+
if (!seen.has(k)) {
|
|
114
|
+
outLines.push(`${k}=${v}`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Also keep process.env live for the running server
|
|
118
|
+
process.env.GITHUB_APP_ID = creds.appId;
|
|
119
|
+
process.env.GITHUB_WEBHOOK_SECRET = creds.webhookSecret;
|
|
120
|
+
process.env.GITHUB_APP_PRIVATE_KEY = creds.privateKey;
|
|
121
|
+
await writeFileAtomic(absPath, outLines.filter((l, idx, arr) => idx < arr.length - 1 || l !== '').join('\n') + '\n');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Strict timing-safe HMAC-SHA256 verification for GitHub `X-Hub-Signature-256`.
|
|
125
|
+
*/
|
|
126
|
+
export function verifyGitHubWebhookSignature(secret, rawPayload, signatureHeader) {
|
|
127
|
+
if (!secret || !signatureHeader || !signatureHeader.startsWith('sha256=')) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
const expected = 'sha256=' + crypto.createHmac('sha256', secret).update(rawPayload).digest('hex');
|
|
131
|
+
const actualBuf = Buffer.from(signatureHeader, 'utf8');
|
|
132
|
+
const expectedBuf = Buffer.from(expected, 'utf8');
|
|
133
|
+
if (actualBuf.length !== expectedBuf.length) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
return crypto.timingSafeEqual(actualBuf, expectedBuf);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=app-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app-manifest.js","sourceRoot":"","sources":["../src/app-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAiBtD;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAiC;IACtE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACnD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,GAAG,OAAO,sBAAsB,CAAC;IAE1E,OAAO;QACL,IAAI,EAAE,OAAO,CAAC,OAAO,IAAI,kBAAkB,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG;QACnF,GAAG,EAAE,2CAA2C;QAChD,eAAe,EAAE;YACf,GAAG,EAAE,UAAU;YACf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C,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;AACvH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,4BAA4B,CAC1C,MAAc,EACd,UAA2B,EAC3B,eAAmC;IAEnC,IAAI,CAAC,MAAM,IAAI,CAAC,eAAe,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1E,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,QAAQ,GACZ,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACnF,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;IACvD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IAClD,IAAI,SAAS,CAAC,MAAM,KAAK,WAAW,CAAC,MAAM,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,MAAM,CAAC,eAAe,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;AACxD,CAAC"}
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Octokit } from '@octokit/rest';
|
|
2
|
+
export interface GitHubAuthConfig {
|
|
3
|
+
mode: 'pat' | 'github_app' | 'gh_cli';
|
|
4
|
+
token?: string;
|
|
5
|
+
appId?: string;
|
|
6
|
+
privateKey?: string;
|
|
7
|
+
installationId?: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Resolve GitHub authentication from explicit config, environment variables,
|
|
11
|
+
* or the local `gh` CLI (`gh auth token`) for zero-config Windows desktop usage.
|
|
12
|
+
*/
|
|
13
|
+
export declare function resolveGitHubAuth(overrides?: Partial<GitHubAuthConfig>): Promise<GitHubAuthConfig | null>;
|
|
14
|
+
/**
|
|
15
|
+
* Create an authenticated Octokit client for either PAT/gh-CLI or GitHub App installation.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createOctokitClient(auth: GitHubAuthConfig): Promise<Octokit>;
|
|
18
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,GAAG,YAAY,GAAG,QAAQ,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,GAAE,OAAO,CAAC,gBAAgB,CAAM,GACxC,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC,CA+BlC;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC,CAelF"}
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { App } from '@octokit/app';
|
|
2
|
+
import { Octokit } from '@octokit/rest';
|
|
3
|
+
import { commandExists, runCommand } from '@codepulse-oss/core';
|
|
4
|
+
/**
|
|
5
|
+
* Resolve GitHub authentication from explicit config, environment variables,
|
|
6
|
+
* or the local `gh` CLI (`gh auth token`) for zero-config Windows desktop usage.
|
|
7
|
+
*/
|
|
8
|
+
export async function resolveGitHubAuth(overrides = {}) {
|
|
9
|
+
const appId = overrides.appId ?? process.env.GITHUB_APP_ID;
|
|
10
|
+
const privateKey = overrides.privateKey ?? process.env.GITHUB_APP_PRIVATE_KEY;
|
|
11
|
+
if (appId && privateKey) {
|
|
12
|
+
return {
|
|
13
|
+
mode: 'github_app',
|
|
14
|
+
appId,
|
|
15
|
+
privateKey: privateKey.replace(/\\n/g, '\n'),
|
|
16
|
+
installationId: overrides.installationId
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const pat = overrides.token ?? process.env.GITHUB_TOKEN;
|
|
20
|
+
if (pat && pat.trim().length > 0) {
|
|
21
|
+
return { mode: 'pat', token: pat.trim() };
|
|
22
|
+
}
|
|
23
|
+
// Fallback to GitHub CLI (`gh auth token`) on local dev machines
|
|
24
|
+
if (await commandExists('gh')) {
|
|
25
|
+
try {
|
|
26
|
+
const res = await runCommand('gh', ['auth', 'token'], { timeoutMs: 5000 });
|
|
27
|
+
if (res.exitCode === 0 && res.stdout.trim().length > 0) {
|
|
28
|
+
return { mode: 'gh_cli', token: res.stdout.trim() };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// ignore
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create an authenticated Octokit client for either PAT/gh-CLI or GitHub App installation.
|
|
39
|
+
*/
|
|
40
|
+
export async function createOctokitClient(auth) {
|
|
41
|
+
if (auth.mode === 'github_app' && auth.appId && auth.privateKey && auth.installationId) {
|
|
42
|
+
const app = new App({
|
|
43
|
+
appId: auth.appId,
|
|
44
|
+
privateKey: auth.privateKey
|
|
45
|
+
});
|
|
46
|
+
const instOctokit = await app.getInstallationOctokit(auth.installationId);
|
|
47
|
+
return instOctokit;
|
|
48
|
+
}
|
|
49
|
+
if (!auth.token) {
|
|
50
|
+
throw new Error('No GitHub token or GitHub App installation credentials available.');
|
|
51
|
+
}
|
|
52
|
+
return new Octokit({ auth: auth.token });
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAUhE;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,YAAuC,EAAE;IAEzC,MAAM,KAAK,GAAG,SAAS,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAC3D,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC;IAE9E,IAAI,KAAK,IAAI,UAAU,EAAE,CAAC;QACxB,OAAO;YACL,IAAI,EAAE,YAAY;YAClB,KAAK;YACL,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC;YAC5C,cAAc,EAAE,SAAS,CAAC,cAAc;SACzC,CAAC;IACJ,CAAC;IAED,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;IACxD,IAAI,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC;IAC5C,CAAC;IAED,iEAAiE;IACjE,IAAI,MAAM,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3E,IAAI,GAAG,CAAC,QAAQ,KAAK,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACvD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;YACtD,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,IAAsB;IAC9D,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;QACvF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC;YAClB,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC,CAAC;QACH,MAAM,WAAW,GAAG,MAAM,GAAG,CAAC,sBAAsB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC1E,OAAO,WAAiC,CAAC;IAC3C,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Octokit } from '@octokit/rest';
|
|
2
|
+
import { type CodePulseDatabase, type ReviewOutput } from '@codepulse-oss/core';
|
|
3
|
+
export interface BabysitResult {
|
|
4
|
+
checkedThreads: number;
|
|
5
|
+
resolvedThreads: string[];
|
|
6
|
+
stillOpenThreads: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* PR Thread Babysitter (`babysit-pr` pattern from `review-skills`):
|
|
10
|
+
* Tracks open review threads across PR commit rounds, verifies whether new commits
|
|
11
|
+
* actually resolved each finding in the latest review, posts evidence-backed replies
|
|
12
|
+
* citing the commit SHA, and updates `pr_threads`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function babysitPrThreads(options: {
|
|
15
|
+
db: CodePulseDatabase;
|
|
16
|
+
octokit?: Octokit;
|
|
17
|
+
repoId: string;
|
|
18
|
+
owner: string;
|
|
19
|
+
repo: string;
|
|
20
|
+
prNumber: number;
|
|
21
|
+
headSha: string;
|
|
22
|
+
latestReview: ReviewOutput;
|
|
23
|
+
prDiffText: string;
|
|
24
|
+
}): Promise<BabysitResult>;
|
|
25
|
+
//# sourceMappingURL=babysitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"babysitter.d.ts","sourceRoot":"","sources":["../src/babysitter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAIL,KAAK,iBAAiB,EAEtB,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,aAAa;IAC5B,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,gBAAgB,EAAE,MAAM,EAAE,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,EAAE,EAAE,iBAAiB,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,YAAY,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;CACpB,GAAG,OAAO,CAAC,aAAa,CAAC,CAmGzB"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { maskSecrets, parseUnifiedDiff, toPosixPath } from '@codepulse-oss/core';
|
|
2
|
+
/**
|
|
3
|
+
* PR Thread Babysitter (`babysit-pr` pattern from `review-skills`):
|
|
4
|
+
* Tracks open review threads across PR commit rounds, verifies whether new commits
|
|
5
|
+
* actually resolved each finding in the latest review, posts evidence-backed replies
|
|
6
|
+
* citing the commit SHA, and updates `pr_threads`.
|
|
7
|
+
*/
|
|
8
|
+
export async function babysitPrThreads(options) {
|
|
9
|
+
const { db, octokit, repoId, owner, repo, prNumber, headSha, latestReview, prDiffText } = options;
|
|
10
|
+
const existingThreads = db.listPrThreads(repoId, prNumber);
|
|
11
|
+
const diffFiles = parseUnifiedDiff(prDiffText);
|
|
12
|
+
const diffByFile = new Map(diffFiles.map((f) => [toPosixPath(f.newPath), f]));
|
|
13
|
+
const activeFindingsByKey = new Set(latestReview.findings
|
|
14
|
+
.filter((f) => f.status !== 'verified_fixed' && f.status !== 'dismissed')
|
|
15
|
+
.map((f) => `${toPosixPath(f.file)}:${f.rule_id ?? f.title.toLowerCase()}`));
|
|
16
|
+
const resolvedThreads = [];
|
|
17
|
+
const stillOpenThreads = [];
|
|
18
|
+
for (const thread of existingThreads) {
|
|
19
|
+
if (thread.status === 'resolved')
|
|
20
|
+
continue;
|
|
21
|
+
const linkedFinding = thread.findingId ? db.getFinding(thread.findingId) : null;
|
|
22
|
+
const key = linkedFinding
|
|
23
|
+
? `${toPosixPath(linkedFinding.file)}:${linkedFinding.rule_id ?? linkedFinding.title.toLowerCase()}`
|
|
24
|
+
: null;
|
|
25
|
+
const fileChangedInLatestDiff = diffByFile.has(toPosixPath(thread.file));
|
|
26
|
+
const stillPresentInLatestReview = (key && activeFindingsByKey.has(key)) ||
|
|
27
|
+
latestReview.findings.some((f) => toPosixPath(f.file) === toPosixPath(thread.file) &&
|
|
28
|
+
Math.abs(f.line_start - thread.line) <= 5 &&
|
|
29
|
+
f.status !== 'verified_fixed');
|
|
30
|
+
if (!stillPresentInLatestReview && (fileChangedInLatestDiff || linkedFinding)) {
|
|
31
|
+
db.upsertPrThread({
|
|
32
|
+
...thread,
|
|
33
|
+
status: 'resolved',
|
|
34
|
+
lastCommitSha: headSha,
|
|
35
|
+
roundNumber: thread.roundNumber + 1
|
|
36
|
+
});
|
|
37
|
+
if (thread.findingId) {
|
|
38
|
+
db.updateFindingStatus(thread.findingId, 'verified_fixed');
|
|
39
|
+
}
|
|
40
|
+
resolvedThreads.push(thread.id);
|
|
41
|
+
if (octokit && thread.githubCommentId && /^\d+$/.test(thread.githubCommentId)) {
|
|
42
|
+
try {
|
|
43
|
+
await octokit.pulls.createReplyForReviewComment({
|
|
44
|
+
owner,
|
|
45
|
+
repo,
|
|
46
|
+
pull_number: prNumber,
|
|
47
|
+
comment_id: Number(thread.githubCommentId),
|
|
48
|
+
body: maskSecrets(`Verified resolved on commit \`${headSha.slice(0, 7)}\`. The finding at \`${thread.file}:${thread.line}\` no longer reproduces in the latest scan.`)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Best-effort reply
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
db.upsertPrThread({
|
|
58
|
+
...thread,
|
|
59
|
+
status: 'still_open',
|
|
60
|
+
lastCommitSha: headSha,
|
|
61
|
+
roundNumber: thread.roundNumber + 1
|
|
62
|
+
});
|
|
63
|
+
stillOpenThreads.push(thread.id);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Register any newly opened findings into pr_threads for future rounds
|
|
67
|
+
for (const finding of latestReview.findings) {
|
|
68
|
+
if (finding.status === 'verified_fixed' || finding.status === 'dismissed')
|
|
69
|
+
continue;
|
|
70
|
+
const threadId = `${repoId}:pr${prNumber}:${finding.id}`;
|
|
71
|
+
const alreadyTracked = existingThreads.some((t) => t.id === threadId || t.findingId === finding.id);
|
|
72
|
+
if (!alreadyTracked) {
|
|
73
|
+
const record = {
|
|
74
|
+
id: threadId,
|
|
75
|
+
repoId,
|
|
76
|
+
prNumber,
|
|
77
|
+
githubCommentId: null,
|
|
78
|
+
file: toPosixPath(finding.file),
|
|
79
|
+
line: finding.line_start,
|
|
80
|
+
findingId: finding.id,
|
|
81
|
+
status: 'open',
|
|
82
|
+
lastCommitSha: headSha,
|
|
83
|
+
roundNumber: 1
|
|
84
|
+
};
|
|
85
|
+
db.upsertPrThread(record);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
checkedThreads: existingThreads.length,
|
|
90
|
+
resolvedThreads,
|
|
91
|
+
stillOpenThreads
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=babysitter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"babysitter.js","sourceRoot":"","sources":["../src/babysitter.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,WAAW,EAIZ,MAAM,qBAAqB,CAAC;AAQ7B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAUtC;IACC,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAElG,MAAM,eAAe,GAAG,EAAE,CAAC,aAAa,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC3D,MAAM,SAAS,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,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OnReachableCritical?: boolean;
|
|
4
|
+
failOnSecrets?: boolean;
|
|
5
|
+
minPatchCoverage?: number;
|
|
6
|
+
failOnBlockers?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface PostCheckRunOptions {
|
|
9
|
+
owner: string;
|
|
10
|
+
repo: string;
|
|
11
|
+
headSha: string;
|
|
12
|
+
token: string;
|
|
13
|
+
output: ReviewOutput;
|
|
14
|
+
name?: string;
|
|
15
|
+
detailsUrl?: string;
|
|
16
|
+
policy?: CheckRunPolicy;
|
|
17
|
+
apiBaseUrl?: string;
|
|
18
|
+
fetchImpl?: typeof fetch;
|
|
19
|
+
}
|
|
20
|
+
export interface GitHubCheckRunAnnotation {
|
|
21
|
+
path: string;
|
|
22
|
+
start_line: number;
|
|
23
|
+
end_line: number;
|
|
24
|
+
annotation_level: 'failure' | 'warning' | 'notice';
|
|
25
|
+
title: string;
|
|
26
|
+
message: string;
|
|
27
|
+
}
|
|
28
|
+
export interface PostCheckRunResult {
|
|
29
|
+
checkRunId?: number;
|
|
30
|
+
htmlUrl?: string;
|
|
31
|
+
conclusion: 'success' | 'failure' | 'neutral';
|
|
32
|
+
reason: string;
|
|
33
|
+
annotationsPosted: number;
|
|
34
|
+
}
|
|
35
|
+
export declare function evaluateMergeGatePolicy(output: ReviewOutput, policy?: CheckRunPolicy): {
|
|
36
|
+
passed: boolean;
|
|
37
|
+
reason: string;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Post a real GitHub Check Run (`CodePulse Security & Audit Gate`) with line-level inline annotations
|
|
41
|
+
* directly into GitHub's Files Changed tab and enforce configurable merge policy gates.
|
|
42
|
+
*/
|
|
43
|
+
export declare function postGitHubCheckRun(options: PostCheckRunOptions): Promise<PostCheckRunResult>;
|
|
44
|
+
//# sourceMappingURL=check-runs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-runs.d.ts","sourceRoot":"","sources":["../src/check-runs.ts"],"names":[],"mappings":"A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AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAoElG"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { maskSecrets, toPosixPath } from '@codepulse-oss/core';
|
|
2
|
+
export function evaluateMergeGatePolicy(output, policy = {}) {
|
|
3
|
+
const active = output.findings.filter((f) => f.status !== 'dismissed' && f.status !== 'verified_fixed');
|
|
4
|
+
if (policy.failOnReachableCritical !== false) {
|
|
5
|
+
const reachableCrit = active.filter((f) => f.severity === 'critical' && (f.reachability === 'external_reachable' || !f.reachability));
|
|
6
|
+
if (reachableCrit.length > 0) {
|
|
7
|
+
return {
|
|
8
|
+
passed: false,
|
|
9
|
+
reason: `${reachableCrit.length} critical/reachable vulnerability finding(s) violate failOnReachableCritical gate.`
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
if (policy.failOnSecrets !== false) {
|
|
14
|
+
const secrets = active.filter((f) => /secret|key|credential|token/i.test(`${f.rule_id ?? ''} ${f.title}`) && f.severity !== 'low');
|
|
15
|
+
if (secrets.length > 0) {
|
|
16
|
+
return {
|
|
17
|
+
passed: false,
|
|
18
|
+
reason: `${secrets.length} exposed secret finding(s) violate failOnSecrets gate.`
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (typeof policy.minPatchCoverage === 'number' && output.coverageSummary?.detected) {
|
|
23
|
+
if (output.coverageSummary.patchCoveragePercent < policy.minPatchCoverage) {
|
|
24
|
+
return {
|
|
25
|
+
passed: false,
|
|
26
|
+
reason: `Patch test coverage ${output.coverageSummary.patchCoveragePercent}% is below required ${policy.minPatchCoverage}% minimum.`
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (policy.failOnBlockers && !output.merge_gate.passed) {
|
|
31
|
+
return {
|
|
32
|
+
passed: false,
|
|
33
|
+
reason: output.merge_gate.reason
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
passed: true,
|
|
38
|
+
reason: 'All CodePulse merge gate checks passed.'
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
function findingToAnnotationLevel(f) {
|
|
42
|
+
if (f.severity === 'critical' || f.severity === 'high')
|
|
43
|
+
return 'failure';
|
|
44
|
+
if (f.severity === 'medium')
|
|
45
|
+
return 'warning';
|
|
46
|
+
return 'notice';
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Post a real GitHub Check Run (`CodePulse Security & Audit Gate`) with line-level inline annotations
|
|
50
|
+
* directly into GitHub's Files Changed tab and enforce configurable merge policy gates.
|
|
51
|
+
*/
|
|
52
|
+
export async function postGitHubCheckRun(options) {
|
|
53
|
+
const { owner, repo, headSha, token, output, name = 'CodePulse Security & Audit Gate', detailsUrl, policy = {}, apiBaseUrl = 'https://api.github.com', fetchImpl = globalThis.fetch } = options;
|
|
54
|
+
const gate = evaluateMergeGatePolicy(output, policy);
|
|
55
|
+
const conclusion = gate.passed ? 'success' : 'failure';
|
|
56
|
+
const active = output.findings.filter((f) => f.status !== 'dismissed' && f.status !== 'verified_fixed');
|
|
57
|
+
const annotations = active.slice(0, 50).map((f) => {
|
|
58
|
+
const start = Math.max(1, f.line_start);
|
|
59
|
+
const end = Math.max(start, f.line_end);
|
|
60
|
+
return {
|
|
61
|
+
path: toPosixPath(f.file).replace(/^\/+/, ''),
|
|
62
|
+
start_line: start,
|
|
63
|
+
end_line: end,
|
|
64
|
+
annotation_level: findingToAnnotationLevel(f),
|
|
65
|
+
title: maskSecrets(`[${f.severity.toUpperCase()}] ${f.title}`).slice(0, 250),
|
|
66
|
+
message: maskSecrets(`${f.body}\n\nFix: ${f.recommendation}`).slice(0, 2000)
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
const url = `${apiBaseUrl.replace(/\/$/, '')}/repos/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/check-runs`;
|
|
70
|
+
const res = await fetchImpl(url, {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: {
|
|
73
|
+
Authorization: `Bearer ${token}`,
|
|
74
|
+
Accept: 'application/vnd.github+json',
|
|
75
|
+
'X-GitHub-Api-Version': '2022-11-28',
|
|
76
|
+
'Content-Type': 'application/json',
|
|
77
|
+
'User-Agent': 'CodePulse-CheckRuns/3.0'
|
|
78
|
+
},
|
|
79
|
+
body: JSON.stringify({
|
|
80
|
+
name,
|
|
81
|
+
head_sha: headSha,
|
|
82
|
+
status: 'completed',
|
|
83
|
+
conclusion,
|
|
84
|
+
...(detailsUrl ? { details_url: detailsUrl } : {}),
|
|
85
|
+
output: {
|
|
86
|
+
title: gate.passed ? `CodePulse Gate Passed (${active.length} info/open)` : `CodePulse Gate Blocked: ${gate.reason}`,
|
|
87
|
+
summary: `${output.summary}\n\n**Gate Decision:** ${gate.passed ? 'PASS ✅' : 'BLOCK ❌'} — ${gate.reason}`,
|
|
88
|
+
annotations
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
if (!res.ok) {
|
|
93
|
+
const body = maskSecrets(await res.text().catch(() => ''));
|
|
94
|
+
throw new Error(`GitHub Check Run API error (${res.status}): ${body.slice(0, 300)}`);
|
|
95
|
+
}
|
|
96
|
+
const json = (await res.json());
|
|
97
|
+
return {
|
|
98
|
+
checkRunId: json.id,
|
|
99
|
+
htmlUrl: json.html_url,
|
|
100
|
+
conclusion,
|
|
101
|
+
reason: gate.reason,
|
|
102
|
+
annotationsPosted: annotations.length
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=check-runs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-runs.js","sourceRoot":"","sources":["../src/check-runs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAyC,MAAM,qBAAqB,CAAC;AAuCtG,MAAM,UAAU,uBAAuB,CACrC,MAAoB,EACpB,S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CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type AstNodeRecord, type ByokAiClient } from '@codepulse-oss/core';
|
|
2
|
+
export type SlashCommandName = 'review' | 'comprehensive' | 'ultrareview' | 'deep-review' | 'debate' | 'adversarial' | 'security' | 'scan-main' | 'docs' | 'describe' | 'add_docs' | 'test' | 'improve' | 'autofix' | 'commit-fix' | 'revalidate' | 'explain' | 'question';
|
|
3
|
+
export interface ParsedPrCommand {
|
|
4
|
+
command: SlashCommandName;
|
|
5
|
+
args: string;
|
|
6
|
+
rawText: string;
|
|
7
|
+
isMentioned: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Parse a GitHub PR comment (slash command or Arabic/English natural language question
|
|
11
|
+
* mentioning `@codepulse` or `/codepulse`).
|
|
12
|
+
*/
|
|
13
|
+
export declare function parsePrCommentCommand(body: string): ParsedPrCommand | null;
|
|
14
|
+
/**
|
|
15
|
+
* Answer a free-form developer question in a PR thread (in Arabic or English)
|
|
16
|
+
* grounded strictly in the local AST graph and file context.
|
|
17
|
+
*/
|
|
18
|
+
export declare function answerNaturalLanguagePrQuestion(options: {
|
|
19
|
+
question: string;
|
|
20
|
+
fileContext?: {
|
|
21
|
+
file: string;
|
|
22
|
+
snippet: string;
|
|
23
|
+
};
|
|
24
|
+
astNodes: AstNodeRecord[];
|
|
25
|
+
aiClient?: ByokAiClient;
|
|
26
|
+
}): Promise<string>;
|
|
27
|
+
//# sourceMappingURL=commands.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.d.ts","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEzF,MAAM,MAAM,gBAAgB,GACxB,QAAQ,GACR,eAAe,GACf,aAAa,GACb,aAAa,GACb,QAAQ,GACR,aAAa,GACb,UAAU,GACV,WAAW,GACX,MAAM,GACN,UAAU,GACV,UAAU,GACV,MAAM,GACN,SAAS,GACT,SAAS,GACT,YAAY,GACZ,YAAY,GACZ,SAAS,GACT,UAAU,CAAC;AAEf,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,gBAAgB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;CACtB;AA8CD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CA0C1E;AAED;;;GAGG;AACH,wBAAsB,+BAA+B,CAAC,OAAO,EAAE;IAC7D,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAChD,QAAQ,EAAE,aAAa,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,YAAY,CAAC;CACzB,GAAG,OAAO,CAAC,MAAM,CAAC,CAuClB"}
|