omp-superagent 0.1.6 → 0.1.8
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/DESIGN.md +36 -20
- package/README.ko.md +140 -33
- package/README.md +165 -41
- package/THIRD_PARTY_NOTICES.md +9 -7
- package/config.example.json +3 -1
- package/docs/OPERATIONS.md +395 -157
- package/docs/design/execution.md +156 -22
- package/docs/design/messaging.md +258 -52
- package/docs/discord-voice.md +8 -4
- package/docs/releases/0.1.7.md +25 -0
- package/docs/releases/0.1.8.md +21 -0
- package/gateway/bin/omp-gateway-darwin-arm64 +0 -0
- package/gateway/bin/omp-gateway-darwin-x64 +0 -0
- package/gateway/bin/omp-gateway-linux-arm64 +0 -0
- package/gateway/bin/omp-gateway-linux-x64 +0 -0
- package/host-owner/bin/omp-host-owner-darwin-arm64 +0 -0
- package/host-owner/bin/omp-host-owner-darwin-x64 +0 -0
- package/host-owner/bin/omp-host-owner-linux-arm64 +0 -0
- package/host-owner/bin/omp-host-owner-linux-x64 +0 -0
- package/package.json +9 -9
- package/scripts/ci.ts +4 -4
- package/scripts/test-omp.sh +2 -1
- package/skills/head/SKILL.md +26 -5
- package/skills/head/references/routing.md +68 -33
- package/skills/head/references/supervision.md +20 -4
- package/skills/lane/references/workflow.md +16 -7
- package/src/board.ts +5 -3
- package/src/cli.ts +161 -19
- package/src/config.ts +21 -1
- package/src/contracts.ts +63 -8
- package/src/cron-jobs.ts +443 -19
- package/src/cron-pr-intake.ts +257 -0
- package/src/discord-markdown.ts +350 -123
- package/src/extension.ts +78 -13
- package/src/gateway-client.ts +8 -2
- package/src/head-quota.ts +80 -0
- package/src/head-recovery.ts +40 -1
- package/src/host-extension.ts +122 -4
- package/src/host-inventory-manifest.ts +2 -2
- package/src/host-protocol.ts +11 -0
- package/src/host-sdk-helper.ts +121 -12
- package/src/host.ts +175 -57
- package/src/installed-omp.ts +116 -4
- package/src/lane-rows.ts +44 -4
- package/src/lane-watch.ts +339 -0
- package/src/managed-memory-helper.ts +13 -10
- package/src/managed-memory.ts +62 -27
- package/src/managed-ulw-probe.ts +75 -20
- package/src/managed-ulw.ts +174 -21
- package/src/messenger-command-catalog.json +2 -2
- package/src/native-launch-profile.ts +4 -2
- package/src/native-presets.ts +32 -5
- package/src/native-sessions.ts +3 -1
- package/src/native-settings.ts +47 -9
- package/src/observation-request.ts +23 -0
- package/src/omp-usage.ts +254 -36
- package/src/pr-github-schema.ts +5 -1
- package/src/pr-github.ts +68 -19
- package/src/pr-intake-automation.ts +316 -0
- package/src/pr-intake-comment.ts +226 -0
- package/src/pr-intake-fix.ts +233 -0
- package/src/pr-intake-github.ts +480 -0
- package/src/pr-intake-material.ts +230 -0
- package/src/pr-intake-mode.ts +59 -0
- package/src/pr-intake-review.ts +397 -0
- package/src/pr-intake-tree.ts +69 -0
- package/src/pr-intake-work.ts +29 -0
- package/src/pr-watch.ts +91 -32
- package/src/runtime.ts +2702 -391
- package/src/setup-judge.ts +1 -1
- package/src/setup.ts +12 -16
- package/src/store.ts +429 -86
- package/src/topic-history.ts +243 -47
- package/src/worker-checkout.ts +106 -0
- package/src/worker-destination.ts +10 -0
- package/src/worker-doctor.ts +66 -0
- package/src/worker-enrollment.ts +165 -0
- package/src/worker-host.ts +180 -0
- package/src/worker-ledger.ts +188 -0
- package/src/worker-placement.ts +78 -0
- package/src/worker-profile.ts +274 -0
- package/src/worker-registration.ts +288 -0
- package/src/worker-repository.ts +233 -0
- package/src/worker-request.ts +74 -0
- package/src/worker-service.ts +230 -0
- package/src/worker-stdio.ts +61 -0
- package/src/worker-trust.ts +36 -0
- package/src/worker-wire.ts +204 -0
- package/src/workflow.ts +81 -32
- package/src/setup-memory.ts +0 -21
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { Type, type Static } from "@sinclair/typebox/type";
|
|
2
|
+
import { parsePrRef } from "./pr-github";
|
|
3
|
+
import { loginSchema, parseWire, PrReadError } from "./pr-github-schema";
|
|
4
|
+
import { openIntakeGitHubSession, type IntakeRepositoryIdentity } from "./pr-intake-github";
|
|
5
|
+
import { openIntakeTree, readIntakeBlob } from "./pr-intake-tree";
|
|
6
|
+
|
|
7
|
+
const maxFiles = 32;
|
|
8
|
+
const maxPatchBytes = 16 * 1024;
|
|
9
|
+
const maxMaterialBytes = 64 * 1024;
|
|
10
|
+
const maxReviewBlobBytes = 96 * 1024;
|
|
11
|
+
export const intakeEvidenceDeadlineMs = 90_000;
|
|
12
|
+
const count = Type.Integer({ minimum: 0, maximum: Number.MAX_SAFE_INTEGER });
|
|
13
|
+
const id = Type.Integer({ minimum: 1, maximum: Number.MAX_SAFE_INTEGER });
|
|
14
|
+
const sha = Type.String({ pattern: "^[0-9a-f]{40}$" });
|
|
15
|
+
const login = loginSchema.properties.login;
|
|
16
|
+
const actor = Type.Object({ id, login, type: Type.Literal("User") });
|
|
17
|
+
const repo = Type.Object({ id, full_name: Type.String({ minLength: 3, maxLength: 140 }), owner: Type.Object({ id, login }) });
|
|
18
|
+
const ref = Type.Object({ ref: Type.String({ minLength: 1, maxLength: 255, pattern: "^[^\\x00-\\x20\\x7f]+$" }), sha });
|
|
19
|
+
const pullSchema = Type.Object({
|
|
20
|
+
number: id, state: Type.Literal("open"), merged: Type.Literal(false), draft: Type.Boolean(),
|
|
21
|
+
title: Type.String({ maxLength: 1024 }),
|
|
22
|
+
user: Type.Object({ id, login: Type.String({ pattern: "^[a-zA-Z0-9][a-zA-Z0-9-]*(\\[bot\\])?$", maxLength: 100 }) }),
|
|
23
|
+
changed_files: count, additions: count, deletions: count,
|
|
24
|
+
base: Type.Composite([ref, Type.Object({ repo })]),
|
|
25
|
+
head: Type.Composite([ref, Type.Object({ repo })]),
|
|
26
|
+
});
|
|
27
|
+
const fileSchema = Type.Object({
|
|
28
|
+
filename: Type.String({ minLength: 1, maxLength: 1024 }),
|
|
29
|
+
previous_filename: Type.Optional(Type.String({ minLength: 1, maxLength: 1024 })),
|
|
30
|
+
status: Type.String(), sha, additions: count, deletions: count, changes: count,
|
|
31
|
+
patch: Type.Optional(Type.String()),
|
|
32
|
+
});
|
|
33
|
+
const filePage = Type.Array(fileSchema, { maxItems: maxFiles });
|
|
34
|
+
const commit = Type.Object({ sha });
|
|
35
|
+
const comparison = Type.Object({
|
|
36
|
+
status: Type.Union([Type.Literal("ahead"), Type.Literal("diverged")]),
|
|
37
|
+
base_commit: commit, merge_base_commit: commit, total_commits: count, commits: Type.Array(commit),
|
|
38
|
+
files: Type.Optional(filePage),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export class IntakeMaterialError extends Error {
|
|
42
|
+
constructor(message: string) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.name = "IntakeMaterialError";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type Session = Awaited<ReturnType<typeof openIntakeGitHubSession>>;
|
|
49
|
+
export type IntakeMaterialTarget = {
|
|
50
|
+
readonly number: number;
|
|
51
|
+
readonly head: string;
|
|
52
|
+
readonly identity: IntakeRepositoryIdentity;
|
|
53
|
+
};
|
|
54
|
+
type Pull = Static<typeof pullSchema>;
|
|
55
|
+
type FileRow = Static<typeof fileSchema>;
|
|
56
|
+
type ReviewedFile = Readonly<Omit<FileRow, "patch"> & { patch: string }>;
|
|
57
|
+
|
|
58
|
+
export async function readIntakePullIdentity(session: Session, target: IntakeMaterialTarget): Promise<Pull> {
|
|
59
|
+
parsePrRef(`${session.repository}#${target.number}`);
|
|
60
|
+
parseWire(sha, JSON.stringify(target.head));
|
|
61
|
+
const [self] = await session.get("user", Type.Tuple([actor]));
|
|
62
|
+
if (self.login.toLowerCase() !== session.owner || self.id !== target.identity.ownerId)
|
|
63
|
+
throw new IntakeMaterialError("GitHub authenticated user does not match the enrolled owner.");
|
|
64
|
+
const [repository] = await session.get(session.root, Type.Tuple([repo]));
|
|
65
|
+
const [pull] = await session.get(`${session.root}/pulls/${target.number}`, Type.Tuple([pullSchema]));
|
|
66
|
+
const matchesEnrollment = (candidate: Static<typeof repo>) =>
|
|
67
|
+
candidate.id === target.identity.repositoryId && candidate.full_name.toLowerCase() === session.repository
|
|
68
|
+
&& candidate.owner.id === self.id && candidate.owner.login.toLowerCase() === session.owner;
|
|
69
|
+
if (pull.number !== target.number || !matchesEnrollment(repository) || !matchesEnrollment(pull.base.repo))
|
|
70
|
+
throw new IntakeMaterialError("GitHub repository or pull request does not match enrollment.");
|
|
71
|
+
if (pull.user.id === self.id || pull.user.login.toLowerCase() === session.owner)
|
|
72
|
+
throw new IntakeMaterialError("GitHub does not establish independent pull request authorship.");
|
|
73
|
+
return pull;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function normalizePull(pull: Pull) {
|
|
77
|
+
const branch = ({ repo, ref, sha }: Pull["base"]) => ({
|
|
78
|
+
name: repo.full_name.toLowerCase(), repositoryId: repo.id, owner: repo.owner.login.toLowerCase(),
|
|
79
|
+
ownerId: repo.owner.id, ref, sha,
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
number: pull.number, author: { id: pull.user.id, login: pull.user.login.toLowerCase() },
|
|
83
|
+
title: pull.title, draft: pull.draft, changedFiles: pull.changed_files,
|
|
84
|
+
additions: pull.additions, deletions: pull.deletions, base: branch(pull.base), head: branch(pull.head),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Prove the patch describes the entire change between the immutable Git blobs. */
|
|
89
|
+
function completePatch(row: ReviewedFile, before: string, after: string): boolean {
|
|
90
|
+
const source = before.match(/[^\n]*\n|[^\n]+$/g) ?? [];
|
|
91
|
+
const result = after.match(/[^\n]*\n|[^\n]+$/g) ?? [];
|
|
92
|
+
const patch = row.patch.replace(/\n$/, "").split("\n");
|
|
93
|
+
let added = 0, removed = 0, oldLines = 0, newLines = 0, hunks = 0;
|
|
94
|
+
let oldPosition = 0, newPosition = 0;
|
|
95
|
+
let previousWasLine = false;
|
|
96
|
+
for (const [index, line] of patch.entries()) {
|
|
97
|
+
const header = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(?: .*)?$/.exec(line);
|
|
98
|
+
if (header) {
|
|
99
|
+
if (oldLines !== 0 || newLines !== 0) return false;
|
|
100
|
+
oldLines = Number(header[2] ?? 1);
|
|
101
|
+
newLines = Number(header[4] ?? 1);
|
|
102
|
+
const oldOffset = Number(header[1]) - Number(oldLines > 0);
|
|
103
|
+
const newOffset = Number(header[3]) - Number(newLines > 0);
|
|
104
|
+
if (oldOffset < oldPosition || newOffset < newPosition || oldOffset + oldLines > source.length
|
|
105
|
+
|| newOffset + newLines > result.length || (oldLines === 0 && newLines === 0)
|
|
106
|
+
|| source.slice(oldPosition, oldOffset).join("") !== result.slice(newPosition, newOffset).join("")) return false;
|
|
107
|
+
oldPosition = oldOffset;
|
|
108
|
+
newPosition = newOffset;
|
|
109
|
+
hunks++;
|
|
110
|
+
previousWasLine = false;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (line === "\" && previousWasLine) {
|
|
114
|
+
previousWasLine = false;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const sign = line[0];
|
|
118
|
+
if (hunks === 0 || (sign !== " " && sign !== "+" && sign !== "-")) return false;
|
|
119
|
+
const payload = line.slice(1) + (patch[index + 1] === "\" ? "" : "\n");
|
|
120
|
+
if (sign !== "+") {
|
|
121
|
+
if (--oldLines < 0 || source[oldPosition++] !== payload) return false;
|
|
122
|
+
}
|
|
123
|
+
if (sign !== "-") {
|
|
124
|
+
if (--newLines < 0 || result[newPosition++] !== payload) return false;
|
|
125
|
+
}
|
|
126
|
+
if (sign === "+") added++;
|
|
127
|
+
if (sign === "-") removed++;
|
|
128
|
+
previousWasLine = true;
|
|
129
|
+
}
|
|
130
|
+
return hunks > 0 && oldLines === 0 && newLines === 0 && added + removed > 0
|
|
131
|
+
&& added === row.additions && removed === row.deletions && added + removed === row.changes
|
|
132
|
+
&& source.slice(oldPosition).join("") === result.slice(newPosition).join("");
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function parseFiles(rows: readonly FileRow[], pull: Pull): readonly ReviewedFile[] {
|
|
136
|
+
if (rows.length !== pull.changed_files || new Set(rows.map(row => row.filename)).size !== rows.length
|
|
137
|
+
|| rows.reduce((sum, row) => sum + row.additions, 0) !== pull.additions
|
|
138
|
+
|| rows.reduce((sum, row) => sum + row.deletions, 0) !== pull.deletions)
|
|
139
|
+
throw new IntakeMaterialError("GitHub returned an incomplete or inconsistent changed-file list.");
|
|
140
|
+
return rows.map(({ filename, previous_filename, status, sha, additions, deletions, changes, patch }) => {
|
|
141
|
+
if (!["added", "modified", "removed", "renamed"].includes(status)
|
|
142
|
+
|| (status === "renamed") !== (previous_filename !== undefined))
|
|
143
|
+
throw new IntakeMaterialError("GitHub reported an unsupported file change.");
|
|
144
|
+
if (patch === undefined)
|
|
145
|
+
throw new IntakeMaterialError("GitHub omitted a file patch (binary, unsupported or too large).");
|
|
146
|
+
if (Buffer.byteLength(patch) > maxPatchBytes)
|
|
147
|
+
throw new IntakeMaterialError("A GitHub file patch exceeds the review size limit.");
|
|
148
|
+
return { filename, previous_filename, status, sha, additions, deletions, changes, patch };
|
|
149
|
+
}).sort((a, b) => a.filename < b.filename ? -1 : a.filename > b.filename ? 1 : 0);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
async function verifyPatches(
|
|
153
|
+
session: Session, revision: { readonly base: string; readonly head: string }, files: readonly ReviewedFile[],
|
|
154
|
+
) {
|
|
155
|
+
if (files.reduce((sum, file) => sum + Buffer.byteLength(file.patch), 0) > maxMaterialBytes)
|
|
156
|
+
throw new IntakeMaterialError("GitHub review material exceeds the total size limit.");
|
|
157
|
+
const oldTree = await openIntakeTree(session, revision.base);
|
|
158
|
+
const newTree = await openIntakeTree(session, revision.head);
|
|
159
|
+
const verified = [];
|
|
160
|
+
for (const row of files) {
|
|
161
|
+
const before = await oldTree(row.previous_filename ?? row.filename);
|
|
162
|
+
const after = await newTree(row.filename);
|
|
163
|
+
if ((before === null) !== (row.status === "added") || (after === null) !== (row.status === "removed")
|
|
164
|
+
|| (after ?? before)?.sha !== row.sha)
|
|
165
|
+
throw new IntakeMaterialError("GitHub file identities do not match the immutable comparison trees.");
|
|
166
|
+
const oldText = before ? await readIntakeBlob(session, before.sha, maxReviewBlobBytes) : "";
|
|
167
|
+
const newText = after ? await readIntakeBlob(session, after.sha, maxReviewBlobBytes) : "";
|
|
168
|
+
if (!completePatch(row, oldText, newText))
|
|
169
|
+
throw new IntakeMaterialError("GitHub returned an unsupported, incomplete or truncated file patch.");
|
|
170
|
+
verified.push({ ...row, beforeMode: before?.mode ?? null, afterMode: after?.mode ?? null });
|
|
171
|
+
}
|
|
172
|
+
return verified;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export async function readIntakeDiff(session: Session, target: IntakeMaterialTarget) {
|
|
176
|
+
try {
|
|
177
|
+
const start = await readIntakePullIdentity(session, target);
|
|
178
|
+
if (start.head.sha !== target.head) throw new IntakeMaterialError("GitHub PR head does not match the requested SHA.");
|
|
179
|
+
if (start.changed_files < 1 || start.changed_files > maxFiles)
|
|
180
|
+
throw new IntakeMaterialError(`Static review requires 1–${maxFiles} changed files.`);
|
|
181
|
+
// Verify the mutable PR files view against the immutable base/head comparison.
|
|
182
|
+
const [pullFiles] = await session.get(`${session.root}/pulls/${target.number}/files?per_page=100`, Type.Tuple([filePage]));
|
|
183
|
+
const [first, ...later] = await session.get(`${session.root}/compare/${start.base.sha}...${target.head}?per_page=100`,
|
|
184
|
+
Type.Array(comparison, { minItems: 1 }));
|
|
185
|
+
if (!first?.files) throw new IntakeMaterialError("GitHub did not supply the immutable comparison file list.");
|
|
186
|
+
const comparisons = [first, ...later];
|
|
187
|
+
const commits = comparisons.flatMap(page => page.commits);
|
|
188
|
+
if (later.some(page => page.files?.length) || comparisons.some(page =>
|
|
189
|
+
page.base_commit.sha !== start.base.sha || page.merge_base_commit.sha !== first.merge_base_commit.sha
|
|
190
|
+
|| page.status !== first.status || page.total_commits !== first.total_commits)
|
|
191
|
+
|| commits.length !== first.total_commits || new Set(commits.map(row => row.sha)).size !== commits.length
|
|
192
|
+
|| !commits.some(row => row.sha === target.head))
|
|
193
|
+
throw new IntakeMaterialError("GitHub comparison does not establish the exact base and head.");
|
|
194
|
+
const files = parseFiles(pullFiles, start);
|
|
195
|
+
if (JSON.stringify(files) !== JSON.stringify(parseFiles(first.files, start)))
|
|
196
|
+
throw new IntakeMaterialError("GitHub PR patches differ from the immutable base/head comparison.");
|
|
197
|
+
const verified = await verifyPatches(session, { base: first.merge_base_commit.sha, head: target.head }, files);
|
|
198
|
+
const pull = normalizePull(start);
|
|
199
|
+
if (JSON.stringify(pull) !== JSON.stringify(normalizePull(await readIntakePullIdentity(session, target))))
|
|
200
|
+
throw new IntakeMaterialError("GitHub PR identity, branch or revision changed while reading the patches.");
|
|
201
|
+
return { pull, mergeBase: first.merge_base_commit.sha, files: verified };
|
|
202
|
+
} catch (error) {
|
|
203
|
+
if (error instanceof PrReadError)
|
|
204
|
+
throw new IntakeMaterialError(`Static review unavailable: ${error.message}.`);
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export function serializeIntakeDiff(snapshot: Awaited<ReturnType<typeof readIntakeDiff>>): string {
|
|
210
|
+
// Preserve the exact data while keeping invisible direction/line controls out of the serialized prompt.
|
|
211
|
+
const material = JSON.stringify(snapshot).replace(/[\x7f-\x9f\p{Cf}\p{Zl}\p{Zp}]/gu, char =>
|
|
212
|
+
char.split("").map(unit => `\\u${unit.charCodeAt(0).toString(16).padStart(4, "0")}`).join(""));
|
|
213
|
+
if (Buffer.byteLength(material) > maxMaterialBytes)
|
|
214
|
+
throw new IntakeMaterialError("GitHub review material exceeds the total size limit.");
|
|
215
|
+
return material;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export function readIntakeMaterialTarget(material: string) {
|
|
219
|
+
const branch = Type.Object({ ref: ref.properties.ref, sha });
|
|
220
|
+
const { pull } = parseWire(Type.Object({ pull: Type.Object({ base: branch, head: branch }) }), material);
|
|
221
|
+
return { baseRef: pull.base.ref, baseSha: pull.base.sha, headRef: pull.head.ref };
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export async function readIntakeMaterial(
|
|
225
|
+
repository: string, number: number, head: string, signal: AbortSignal, identity: IntakeRepositoryIdentity,
|
|
226
|
+
): Promise<string> {
|
|
227
|
+
const deadline = AbortSignal.any([signal, AbortSignal.timeout(intakeEvidenceDeadlineMs)]);
|
|
228
|
+
const session = await openIntakeGitHubSession(repository, deadline);
|
|
229
|
+
return serializeIntakeDiff(await readIntakeDiff(session, { number, head, identity }));
|
|
230
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { normalizeIntakeRepository } from "./cron-pr-intake";
|
|
2
|
+
|
|
3
|
+
export const prModeEffects = {
|
|
4
|
+
review: "static review and a bounded GitHub PR comment",
|
|
5
|
+
fix: "static review, a bounded GitHub PR comment, and an eligible safe fix commit",
|
|
6
|
+
merge: "static review, a bounded GitHub PR comment, an eligible safe fix commit, and a verified final re-review, CI check, and merge",
|
|
7
|
+
} as const;
|
|
8
|
+
|
|
9
|
+
export type PrIntakeMode = keyof typeof prModeEffects;
|
|
10
|
+
|
|
11
|
+
type ModeCommand = { readonly target: string | null; readonly mode: PrIntakeMode };
|
|
12
|
+
|
|
13
|
+
const naturalModes: readonly (readonly [RegExp, PrIntakeMode])[] = [
|
|
14
|
+
[/^(?:무인|자동)으로[ \t]*리뷰[ \t]*만$/u, "review"],
|
|
15
|
+
[/^(?:무인|자동)으로[ \t]*리뷰[ \t]*후[ \t]*수정[ \t]*커밋[ \t]*까지$/u, "fix"],
|
|
16
|
+
[/^(?:무인|자동)으로[ \t]*수정[ \t]*커밋[ \t]*후[ \t]*(?:머지|병합)[ \t]*까지$/u, "merge"],
|
|
17
|
+
];
|
|
18
|
+
const beforeRepo = /^([A-Za-z0-9-]+\/[A-Za-z0-9_.-]+)(?:[ \t]*(?:저장소(?:는|에서)|는|은|를|을|에서|에[ \t]+대해))?[ \t]+/u;
|
|
19
|
+
const afterRepo = /[ \t]+(?:\(([A-Za-z0-9-]+\/[A-Za-z0-9_.-]+)\)|([A-Za-z0-9-]+\/[A-Za-z0-9_.-]+))$/u;
|
|
20
|
+
const future = /^앞으로(?:는)?[ \t]+/u;
|
|
21
|
+
const ending = /[ \t]+(?:(?:진행|설정|하도록|하게)[ \t]*)?해(?:[ \t]*(?:줘(?:요)?|주세요))?$/u;
|
|
22
|
+
const lineBreak = /[\r\n\u2028\u2029]/u;
|
|
23
|
+
const jobId = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/iu;
|
|
24
|
+
|
|
25
|
+
export function parsePrModeControl(argument: string): ModeCommand | null {
|
|
26
|
+
if (lineBreak.test(argument)) return null;
|
|
27
|
+
const match = /^pr-mode[ \t]+(?:(\S+)[ \t]+)?(review|fix|merge)$/u.exec(argument.trim());
|
|
28
|
+
const [, selector, mode] = match ?? [];
|
|
29
|
+
if (mode !== "review" && mode !== "fix" && mode !== "merge") return null;
|
|
30
|
+
if (selector === undefined) return { target: null, mode };
|
|
31
|
+
const target = jobId.test(selector) ? selector.toLowerCase() : normalizeIntakeRepository(selector);
|
|
32
|
+
return target ? { target, mode } : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Only a complete direct instruction can become a controller command. */
|
|
36
|
+
export function prModeArgument(text: string): string | null {
|
|
37
|
+
if (lineBreak.test(text)) return null;
|
|
38
|
+
const command = text.trim();
|
|
39
|
+
const slash = /^\/cron[ \t]+(.+)$/u.exec(command)?.[1];
|
|
40
|
+
if (slash !== undefined) {
|
|
41
|
+
const parsed = parsePrModeControl(slash);
|
|
42
|
+
return parsed?.target ? `pr-mode ${parsed.target} ${parsed.mode}` : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const sentence = command.replace(/[.!]$/u, "").replace(future, "");
|
|
46
|
+
const prefix = beforeRepo.exec(sentence);
|
|
47
|
+
const remainder = prefix ? sentence.slice(prefix[0].length).replace(future, "") : sentence;
|
|
48
|
+
const suffix = afterRepo.exec(remainder);
|
|
49
|
+
if (prefix && suffix) return null;
|
|
50
|
+
const repository = prefix?.[1] ?? suffix?.[1] ?? suffix?.[2];
|
|
51
|
+
const target = repository === undefined ? null : normalizeIntakeRepository(repository);
|
|
52
|
+
if (repository !== undefined && !target) return null;
|
|
53
|
+
const instruction = suffix ? remainder.slice(0, suffix.index) : remainder;
|
|
54
|
+
const body = instruction.replace(ending, "");
|
|
55
|
+
const level = /^PR[ \t]*자동화(?:[ \t]*모드)?(?:를|는)?[ \t]+([123])[ \t]*단계로[ \t]*(?:바꿔|변경해|설정해)(?:[ \t]*(?:줘(?:요)?|주세요))?$/iu.exec(instruction)?.[1];
|
|
56
|
+
const mode = level === "1" ? "review" : level === "2" ? "fix" : level === "3" ? "merge"
|
|
57
|
+
: naturalModes.find(([pattern]) => pattern.test(body))?.[1];
|
|
58
|
+
return mode ? `pr-mode ${target ? `${target} ` : ""}${mode}` : null;
|
|
59
|
+
}
|