@codepulse-oss/github 0.0.0-stage → 2.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.
- 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/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/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 +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -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
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.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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,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAE9E,MAAM,mBAAmB,GAAG,IAAI,GAAG,CACjC,YAAY,CAAC,QAAQ;SAClB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,C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CAAC;IACH,CAAC;IAED,uEAAuE;IACvE,KAAK,MAAM,OAAO,IAAI,YAAY,CAAC,QAAQ,EAAE,CAAC;QAC5C,IAAI,OAAO,CAAC,MAAM,KAAK,gBAAgB,IAAI,OAAO,CAAC,MAAM,KAAK,WAAW;YAAE,SAAS;QACpF,MAAM,QAAQ,GAAG,GAAG,MAAM,MAAM,QAAQ,IAAI,OAAO,CAAC,EAAE,EAAE,CAAC;QACzD,MAAM,cAAc,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,IAAI,CAAC,CAAC,SAAS,KAAK,OAAO,CAAC,EAAE,CAAC,CAAC;QACpG,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,MAAM,MAAM,GAAsC;gBAChD,EAAE,EAAE,QAAQ;gBACZ,MAAM;gBACN,QAAQ;gBACR,eAAe,EAAE,IAAI;gBACrB,IAAI,EAAE,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC;gBAC/B,IAAI,EAAE,OAAO,CAAC,UAAU;gBACxB,SAAS,EAAE,OAAO,CAAC,EAAE;gBACrB,MAAM,EAAE,MAAM;gBACd,aAAa,EAAE,OAAO;gBACtB,WAAW,EAAE,CAAC;aACf,CAAC;YACF,EAAE,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,OAAO;QACL,cAAc,EAAE,eAAe,CAAC,MAAM;QACtC,eAAe;QACf,gBAAgB;KACjB,CAAC;AACJ,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"}
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { maskSecrets } from '@codepulse-oss/core';
|
|
2
|
+
const SLASH_ALIASES = {
|
|
3
|
+
'/codepulse review': 'review',
|
|
4
|
+
'/review': 'review',
|
|
5
|
+
'/comprehensive': 'comprehensive',
|
|
6
|
+
'/codepulse comprehensive': 'comprehensive',
|
|
7
|
+
'/full-audit': 'comprehensive',
|
|
8
|
+
'/codepulse full-audit': 'comprehensive',
|
|
9
|
+
'/ultrareview': 'ultrareview',
|
|
10
|
+
'/codepulse ultrareview': 'ultrareview',
|
|
11
|
+
'/deep-review': 'deep-review',
|
|
12
|
+
'/codepulse deep-review': 'deep-review',
|
|
13
|
+
'/debate': 'debate',
|
|
14
|
+
'/codepulse debate': 'debate',
|
|
15
|
+
'/adversarial': 'adversarial',
|
|
16
|
+
'/codepulse adversarial': 'adversarial',
|
|
17
|
+
'/security': 'security',
|
|
18
|
+
'/codepulse security': 'security',
|
|
19
|
+
'/scan-main': 'scan-main',
|
|
20
|
+
'/codepulse scan-main': 'scan-main',
|
|
21
|
+
'/docs': 'docs',
|
|
22
|
+
'/codepulse docs': 'docs',
|
|
23
|
+
'/describe': 'describe',
|
|
24
|
+
'/codepulse describe': 'describe',
|
|
25
|
+
'/add_docs': 'add_docs',
|
|
26
|
+
'/codepulse add_docs': 'add_docs',
|
|
27
|
+
'/add-docs': 'add_docs',
|
|
28
|
+
'/codepulse add-docs': 'add_docs',
|
|
29
|
+
'/test': 'test',
|
|
30
|
+
'/codepulse test': 'test',
|
|
31
|
+
'/add_tests': 'test',
|
|
32
|
+
'/codepulse add_tests': 'test',
|
|
33
|
+
'/add-tests': 'test',
|
|
34
|
+
'/improve': 'improve',
|
|
35
|
+
'/codepulse improve': 'improve',
|
|
36
|
+
'/autofix': 'autofix',
|
|
37
|
+
'/codepulse autofix': 'autofix',
|
|
38
|
+
'/commit-fix': 'commit-fix',
|
|
39
|
+
'/codepulse commit-fix': 'commit-fix',
|
|
40
|
+
'/revalidate': 'revalidate',
|
|
41
|
+
'/codepulse revalidate': 'revalidate',
|
|
42
|
+
'/explain': 'explain',
|
|
43
|
+
'/codepulse explain': 'explain'
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Parse a GitHub PR comment (slash command or Arabic/English natural language question
|
|
47
|
+
* mentioning `@codepulse` or `/codepulse`).
|
|
48
|
+
*/
|
|
49
|
+
export function parsePrCommentCommand(body) {
|
|
50
|
+
const trimmed = body.trim();
|
|
51
|
+
if (!trimmed)
|
|
52
|
+
return null;
|
|
53
|
+
// Ignore comments authored by CodePulse itself
|
|
54
|
+
if (trimmed.includes('<!-- codepulse-summary -->') || trimmed.includes('CodePulse Finding ID:')) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
const lower = trimmed.toLowerCase();
|
|
58
|
+
for (const [prefix, cmd] of Object.entries(SLASH_ALIASES)) {
|
|
59
|
+
if (lower === prefix || lower.startsWith(`${prefix} `) || lower.startsWith(`${prefix}\n`)) {
|
|
60
|
+
return {
|
|
61
|
+
command: cmd,
|
|
62
|
+
args: trimmed.slice(prefix.length).trim(),
|
|
63
|
+
rawText: trimmed,
|
|
64
|
+
isMentioned: true
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (lower.startsWith('/codepulse')) {
|
|
69
|
+
const rest = trimmed.slice('/codepulse'.length).trim();
|
|
70
|
+
return {
|
|
71
|
+
command: rest ? 'question' : 'review',
|
|
72
|
+
args: rest,
|
|
73
|
+
rawText: trimmed,
|
|
74
|
+
isMentioned: true
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (/@codepulse\b/i.test(trimmed)) {
|
|
78
|
+
const questionText = trimmed.replace(/@codepulse/gi, '').trim();
|
|
79
|
+
return {
|
|
80
|
+
command: 'question',
|
|
81
|
+
args: questionText,
|
|
82
|
+
rawText: trimmed,
|
|
83
|
+
isMentioned: true
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Answer a free-form developer question in a PR thread (in Arabic or English)
|
|
90
|
+
* grounded strictly in the local AST graph and file context.
|
|
91
|
+
*/
|
|
92
|
+
export async function answerNaturalLanguagePrQuestion(options) {
|
|
93
|
+
const { question, fileContext, astNodes, aiClient } = options;
|
|
94
|
+
const isArabic = /[\u0600-\u06FF]/.test(question);
|
|
95
|
+
const relevantSymbols = fileContext
|
|
96
|
+
? astNodes.filter((n) => n.file === fileContext.file).slice(0, 15)
|
|
97
|
+
: astNodes.slice(0, 20);
|
|
98
|
+
if (!aiClient?.isConfigured()) {
|
|
99
|
+
const symList = relevantSymbols.map((s) => `- \`${s.file}:${s.lineStart}\` (\`${s.kind} ${s.name}\`)`).join('\n');
|
|
100
|
+
return isArabic
|
|
101
|
+
? `تم استلام سؤالك عبر CodePulse. الرموز المرتبطة في الرسم البياني للكود (AST):\n${symList || '- لا توجد رموز مفهرسة بعد.'}\n\n*(فعّل مفتاح AI API للحصول على شرح تفصيلي مباشر).*`
|
|
102
|
+
: `CodePulse received your question. Relevant AST symbols:\n${symList || '- No indexed symbols yet.'}\n\n*(Configure an AI API key for full conversational answers).*`;
|
|
103
|
+
}
|
|
104
|
+
const systemPrompt = `You are CodePulse, a senior security & architecture assistant replying inside a GitHub Pull Request thread.
|
|
105
|
+
Answer in the EXACT same language as the user's question (${isArabic ? 'Arabic' : 'English'}).
|
|
106
|
+
Cite only verified file paths, line numbers, and symbols provided in the AST/snippet context. Never invent paths or secrets.`;
|
|
107
|
+
const userPrompt = maskSecrets(JSON.stringify({
|
|
108
|
+
question,
|
|
109
|
+
file: fileContext?.file,
|
|
110
|
+
code_snippet: fileContext?.snippet?.slice(0, 6000),
|
|
111
|
+
ast_symbols: relevantSymbols.map((s) => ({
|
|
112
|
+
file: s.file,
|
|
113
|
+
kind: s.kind,
|
|
114
|
+
name: s.name,
|
|
115
|
+
lines: `${s.lineStart}-${s.lineEnd}`
|
|
116
|
+
}))
|
|
117
|
+
}));
|
|
118
|
+
const res = await aiClient.complete({
|
|
119
|
+
systemPrompt,
|
|
120
|
+
userPrompt,
|
|
121
|
+
temperature: 0.2
|
|
122
|
+
});
|
|
123
|
+
return maskSecrets(res.text);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=commands.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAyC,MAAM,qBAAqB,CAAC;AA6BzF,MAAM,aAAa,GAAqC;IACtD,mBAAmB,EAAE,QAAQ;IAC7B,SAAS,EAAE,QAAQ;IACnB,gBAAgB,EAAE,eAAe;IACjC,0BAA0B,EAAE,eAAe;IAC3C,aAAa,EAAE,eAAe;IAC9B,uBAAuB,EAAE,eAAe;IACxC,cAAc,EAAE,aAAa;IAC7B,wBAAwB,EAAE,aAAa;IACvC,cAAc,EAAE,aAAa;IAC7B,wBAAwB,EAAE,aAAa;IACvC,SAAS,EAAE,QAAQ;IACnB,mBAAmB,EAAE,QAAQ;IAC7B,cAAc,EAAE,aAAa;IAC7B,wBAAwB,EAAE,aAAa;IACvC,WAAW,EAAE,UAAU;IACvB,qBAAqB,EAAE,UAAU;IACjC,YAAY,EAAE,WAAW;IACzB,sBAAs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E,GAAG;KACjB,CAAC,CAAC;IACH,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface GuardedCommitFixOptions {
|
|
2
|
+
repoPath: string;
|
|
3
|
+
headRef: string;
|
|
4
|
+
defaultBranch?: string;
|
|
5
|
+
findingId: string;
|
|
6
|
+
commitMessage?: string;
|
|
7
|
+
optInPush: boolean;
|
|
8
|
+
remoteName?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface GuardedCommitFixResult {
|
|
11
|
+
allowed: boolean;
|
|
12
|
+
committed: boolean;
|
|
13
|
+
pushed: boolean;
|
|
14
|
+
commitSha?: string;
|
|
15
|
+
reason: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Guarded `/commit-fix`: refuses protected branches (`main`/`master`),
|
|
19
|
+
* requires explicit `optInPush: true`, and pushes ONLY to an active PR head branch.
|
|
20
|
+
*/
|
|
21
|
+
export declare function pushGuardedCommitFixToPrBranch(options: GuardedCommitFixOptions): Promise<GuardedCommitFixResult>;
|
|
22
|
+
//# sourceMappingURL=commit-fix.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-fix.d.ts","sourceRoot":"","sources":["../src/commit-fix.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAID;;;GAGG;AACH,wBAAsB,8BAA8B,CAClD,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,sBAAsB,CAAC,CAiEjC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { runCommand, resolveSafeDirectory } from '@codepulse-oss/core';
|
|
2
|
+
const PROTECTED_BRANCHES = new Set(['main', 'master', 'production', 'prod', 'release']);
|
|
3
|
+
/**
|
|
4
|
+
* Guarded `/commit-fix`: refuses protected branches (`main`/`master`),
|
|
5
|
+
* requires explicit `optInPush: true`, and pushes ONLY to an active PR head branch.
|
|
6
|
+
*/
|
|
7
|
+
export async function pushGuardedCommitFixToPrBranch(options) {
|
|
8
|
+
const safeRoot = resolveSafeDirectory(options.repoPath);
|
|
9
|
+
const head = options.headRef.trim();
|
|
10
|
+
const def = (options.defaultBranch ?? 'main').trim();
|
|
11
|
+
if (!head || PROTECTED_BRANCHES.has(head.toLowerCase()) || head === def) {
|
|
12
|
+
return {
|
|
13
|
+
allowed: false,
|
|
14
|
+
committed: false,
|
|
15
|
+
pushed: false,
|
|
16
|
+
reason: `Blocked guarded /commit-fix: refusing to commit or push to protected branch "${head}".`
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
if (!options.optInPush) {
|
|
20
|
+
return {
|
|
21
|
+
allowed: false,
|
|
22
|
+
committed: false,
|
|
23
|
+
pushed: false,
|
|
24
|
+
reason: 'Guarded /commit-fix requires explicit opt-in (`optInPush: true`).'
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const statusRes = await runCommand('git', ['status', '--porcelain'], { cwd: safeRoot });
|
|
28
|
+
if (!statusRes.stdout.trim()) {
|
|
29
|
+
return {
|
|
30
|
+
allowed: true,
|
|
31
|
+
committed: false,
|
|
32
|
+
pushed: false,
|
|
33
|
+
reason: 'No uncommitted fix diff present to commit.'
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
await runCommand('git', ['checkout', head], { cwd: safeRoot });
|
|
37
|
+
await runCommand('git', ['add', '-A'], { cwd: safeRoot });
|
|
38
|
+
const msg = options.commitMessage ?? `fix(codepulse): resolve finding ${options.findingId}`;
|
|
39
|
+
const commitRes = await runCommand('git', ['commit', '-m', msg], { cwd: safeRoot });
|
|
40
|
+
if (commitRes.exitCode !== 0) {
|
|
41
|
+
return {
|
|
42
|
+
allowed: true,
|
|
43
|
+
committed: false,
|
|
44
|
+
pushed: false,
|
|
45
|
+
reason: `git commit failed: ${commitRes.stderr || commitRes.stdout}`
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const shaRes = await runCommand('git', ['rev-parse', '--short', 'HEAD'], { cwd: safeRoot });
|
|
49
|
+
const pushRes = await runCommand('git', ['push', options.remoteName ?? 'origin', head], { cwd: safeRoot });
|
|
50
|
+
if (pushRes.exitCode !== 0) {
|
|
51
|
+
return {
|
|
52
|
+
allowed: true,
|
|
53
|
+
committed: true,
|
|
54
|
+
pushed: false,
|
|
55
|
+
commitSha: shaRes.stdout.trim(),
|
|
56
|
+
reason: `Committed ${shaRes.stdout.trim()}, push failed: ${pushRes.stderr || pushRes.stdout}`
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
allowed: true,
|
|
61
|
+
committed: true,
|
|
62
|
+
pushed: true,
|
|
63
|
+
commitSha: shaRes.stdout.trim(),
|
|
64
|
+
reason: `Committed and pushed verified fix (${shaRes.stdout.trim()}) to PR branch "${head}".`
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=commit-fix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commit-fix.js","sourceRoot":"","sources":["../src/commit-fix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAoBvE,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAA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AAM,EAAE;SAC9F,CAAC;IACJ,CAAC;IAED,OAAO;QACL,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;QACf,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QAC/B,MAAM,EAAE,sCAAsC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,mBAAmB,IAAI,IAAI;KAC9F,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Octokit } from '@octokit/rest';
|
|
2
|
+
export declare const DEFAULT_GITHUB_DEVICE_CLIENT_ID: string;
|
|
3
|
+
export interface DeviceFlowStartResult {
|
|
4
|
+
deviceCode: string;
|
|
5
|
+
userCode: string;
|
|
6
|
+
verificationUri: string;
|
|
7
|
+
expiresIn: number;
|
|
8
|
+
interval: number;
|
|
9
|
+
}
|
|
10
|
+
export interface DeviceFlowPollResult {
|
|
11
|
+
status: 'pending' | 'slow_down' | 'authorized' | 'expired' | 'denied' | 'error';
|
|
12
|
+
accessToken?: string;
|
|
13
|
+
tokenType?: string;
|
|
14
|
+
scope?: string;
|
|
15
|
+
interval?: number;
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface GitHubRepoSummary {
|
|
19
|
+
id: number;
|
|
20
|
+
fullName: string;
|
|
21
|
+
owner: string;
|
|
22
|
+
name: string;
|
|
23
|
+
private: boolean;
|
|
24
|
+
defaultBranch: string;
|
|
25
|
+
description: string;
|
|
26
|
+
updatedAt: string;
|
|
27
|
+
htmlUrl: string;
|
|
28
|
+
}
|
|
29
|
+
export interface GitHubPullSummary {
|
|
30
|
+
number: number;
|
|
31
|
+
title: string;
|
|
32
|
+
author: string;
|
|
33
|
+
headRef: string;
|
|
34
|
+
headSha: string;
|
|
35
|
+
baseRef: string;
|
|
36
|
+
updatedAt: string;
|
|
37
|
+
htmlUrl: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Start GitHub OAuth Device Flow (`https://github.com/login/device/code`)
|
|
41
|
+
* using the public CodePulsebot Client ID (no client_secret embedded).
|
|
42
|
+
*/
|
|
43
|
+
export declare function startGitHubDeviceFlow(options?: {
|
|
44
|
+
clientId?: string;
|
|
45
|
+
scope?: string;
|
|
46
|
+
fetchImpl?: typeof fetch;
|
|
47
|
+
}): Promise<DeviceFlowStartResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Poll GitHub Device Flow access token endpoint once.
|
|
50
|
+
*/
|
|
51
|
+
export declare function pollGitHubDeviceFlow(options: {
|
|
52
|
+
deviceCode: string;
|
|
53
|
+
clientId?: string;
|
|
54
|
+
fetchImpl?: typeof fetch;
|
|
55
|
+
}): Promise<DeviceFlowPollResult>;
|
|
56
|
+
/**
|
|
57
|
+
* List all accessible Public & Private repositories for the authenticated GitHub user.
|
|
58
|
+
*/
|
|
59
|
+
export declare function listAccessibleGitHubRepos(octokit: Octokit, page?: number): Promise<GitHubRepoSummary[]>;
|
|
60
|
+
/**
|
|
61
|
+
* List open Pull Requests for a repository.
|
|
62
|
+
*/
|
|
63
|
+
export declare function listOpenPullRequests(octokit: Octokit, owner: string, repo: string): Promise<GitHubPullSummary[]>;
|
|
64
|
+
//# sourceMappingURL=device-flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"device-flow.d.ts","sourceRoot":"","sources":["../src/device-flow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C,eAAO,MAAM,+BAA+B,QACkB,CAAC;AAE/D,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,SAAS,GAAG,WAAW,GA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