@lore-co/core 0.2.37 → 0.2.38
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/beta-features.d.ts +29 -0
- package/dist/beta-features.d.ts.map +1 -0
- package/dist/beta-features.js +28 -0
- package/dist/beta-features.js.map +1 -0
- package/dist/in-memory-repository.d.ts +3 -0
- package/dist/in-memory-repository.d.ts.map +1 -1
- package/dist/in-memory-repository.js +8 -0
- package/dist/in-memory-repository.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/package-names.d.ts +10 -0
- package/dist/package-names.d.ts.map +1 -0
- package/dist/package-names.js +22 -0
- package/dist/package-names.js.map +1 -0
- package/dist/package-rules.d.ts +54 -0
- package/dist/package-rules.d.ts.map +1 -0
- package/dist/package-rules.js +132 -0
- package/dist/package-rules.js.map +1 -0
- package/dist/platform-admin-schemas.d.ts +6 -0
- package/dist/platform-admin-schemas.d.ts.map +1 -1
- package/dist/platform-admin-schemas.js +2 -0
- package/dist/platform-admin-schemas.js.map +1 -1
- package/dist/ports.d.ts +2 -0
- package/dist/ports.d.ts.map +1 -1
- package/dist/product-usage.d.ts +22 -1
- package/dist/product-usage.d.ts.map +1 -1
- package/dist/product-usage.js +8 -2
- package/dist/product-usage.js.map +1 -1
- package/dist/public-rule-text.d.ts +10 -0
- package/dist/public-rule-text.d.ts.map +1 -0
- package/dist/public-rule-text.js +24 -0
- package/dist/public-rule-text.js.map +1 -0
- package/dist/public-rules-client.d.ts +75 -0
- package/dist/public-rules-client.d.ts.map +1 -0
- package/dist/public-rules-client.js +273 -0
- package/dist/public-rules-client.js.map +1 -0
- package/dist/public-rules.d.ts +121 -0
- package/dist/public-rules.d.ts.map +1 -0
- package/dist/public-rules.js +159 -0
- package/dist/public-rules.js.map +1 -0
- package/dist/pull-request-rules.d.ts +30 -0
- package/dist/pull-request-rules.d.ts.map +1 -0
- package/dist/pull-request-rules.js +16 -0
- package/dist/pull-request-rules.js.map +1 -0
- package/dist/session-schemas.d.ts +6 -0
- package/dist/session-schemas.d.ts.map +1 -1
- package/dist/session-schemas.js +2 -0
- package/dist/session-schemas.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import { constants } from "node:fs";
|
|
2
|
+
import { lstat, open, readdir, realpath } from "node:fs/promises";
|
|
3
|
+
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
import { escapeLoreContextDelimiters } from "./delivered-text.js";
|
|
5
|
+
import { normalizePackageName, packageLabel } from "./package-names.js";
|
|
6
|
+
import { PUBLIC_RULES_LIMITS, publicRuleLine } from "./public-rule-text.js";
|
|
7
|
+
import { repositoryIdentity } from "./repository-address.js";
|
|
8
|
+
const MAX_MANIFEST_BYTES = 1_000_000;
|
|
9
|
+
const MAX_DEPENDENCIES = 500;
|
|
10
|
+
async function regularFileText(file) {
|
|
11
|
+
// Never follow a link, never wait on a pipe, and skip anything huge.
|
|
12
|
+
const handle = await open(file, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0)).catch(() => undefined);
|
|
13
|
+
if (handle === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
try {
|
|
16
|
+
const info = await handle.stat();
|
|
17
|
+
if (!info.isFile() || info.size > MAX_MANIFEST_BYTES)
|
|
18
|
+
return undefined;
|
|
19
|
+
return await handle.readFile("utf8");
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
finally {
|
|
25
|
+
await handle.close().catch(() => undefined);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function npmDependencies(text) {
|
|
29
|
+
try {
|
|
30
|
+
const manifest = JSON.parse(text);
|
|
31
|
+
return ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"]
|
|
32
|
+
.flatMap(field => typeof manifest[field] === "object" && manifest[field] !== null ? Object.keys(manifest[field]) : []);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return [];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** The leading package name of a PEP 508 requirement such as `requests[socks]>=2; python_version>"3"`. */
|
|
39
|
+
function requirementName(line) {
|
|
40
|
+
const name = /^\s*([A-Za-z0-9][A-Za-z0-9._-]*)/u.exec(line)?.[1];
|
|
41
|
+
return name === undefined || /^(?:python)$/iu.test(name) ? undefined : name;
|
|
42
|
+
}
|
|
43
|
+
/** `[project] dependencies` and Poetry's dependency tables. A small reader for these keys only, not a TOML parser. */
|
|
44
|
+
function pyprojectDependencies(text) {
|
|
45
|
+
const names = [];
|
|
46
|
+
let table = "";
|
|
47
|
+
let inArray = false;
|
|
48
|
+
for (const raw of text.split(/\r?\n/u)) {
|
|
49
|
+
const line = raw.replace(/\s+#.*$/u, "").trim();
|
|
50
|
+
if (inArray) {
|
|
51
|
+
for (const match of line.matchAll(/["']([^"']+)["']/gu)) {
|
|
52
|
+
const name = requirementName(match[1]);
|
|
53
|
+
if (name)
|
|
54
|
+
names.push(name);
|
|
55
|
+
}
|
|
56
|
+
if (line.includes("]"))
|
|
57
|
+
inArray = false;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const header = /^\[([^\]]+)\]$/u.exec(line);
|
|
61
|
+
if (header) {
|
|
62
|
+
table = header[1].trim();
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (table === "project" && /^dependencies\s*=\s*\[/u.test(line)) {
|
|
66
|
+
for (const match of line.matchAll(/["']([^"']+)["']/gu)) {
|
|
67
|
+
const name = requirementName(match[1]);
|
|
68
|
+
if (name)
|
|
69
|
+
names.push(name);
|
|
70
|
+
}
|
|
71
|
+
inArray = !line.includes("]");
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (/^tool\.poetry(?:\.group\.[^.]+)?\.(?:dev-)?dependencies$/u.test(table)) {
|
|
75
|
+
const key = /^["']?([A-Za-z0-9][A-Za-z0-9._-]*)["']?\s*=/u.exec(line)?.[1];
|
|
76
|
+
if (key && key.toLowerCase() !== "python")
|
|
77
|
+
names.push(key);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return names;
|
|
81
|
+
}
|
|
82
|
+
function requirementsDependencies(text) {
|
|
83
|
+
return text.split(/\r?\n/u).flatMap(raw => {
|
|
84
|
+
const line = raw.replace(/\s+#.*$/u, "").trim();
|
|
85
|
+
if (!line || line.startsWith("#") || line.startsWith("-") || /^[a-z]+:\/\//iu.test(line))
|
|
86
|
+
return [];
|
|
87
|
+
const name = requirementName(line);
|
|
88
|
+
return name === undefined ? [] : [name];
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/** The real path of a folder, or of the nearest folder above it that exists. */
|
|
92
|
+
async function existingRealPath(folder) {
|
|
93
|
+
let current = folder;
|
|
94
|
+
while (true) {
|
|
95
|
+
const real = await realpath(current).catch(() => undefined);
|
|
96
|
+
if (real !== undefined)
|
|
97
|
+
return current === folder ? real : join(real, relative(current, folder));
|
|
98
|
+
if (dirname(current) === current)
|
|
99
|
+
return undefined;
|
|
100
|
+
current = dirname(current);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Direct dependencies named in the checkout root and in the nearest package
|
|
105
|
+
* folder from `cwd` up to the root: names only, never versions, lockfiles or
|
|
106
|
+
* registry addresses.
|
|
107
|
+
*/
|
|
108
|
+
export async function readProjectDependencies(root, cwd) {
|
|
109
|
+
const top = await realpath(root).catch(() => resolve(root));
|
|
110
|
+
const folders = [top];
|
|
111
|
+
// A working folder reached through a link out of the checkout is not part of it.
|
|
112
|
+
const real = cwd === undefined ? undefined : await existingRealPath(resolve(cwd));
|
|
113
|
+
if (real !== undefined) {
|
|
114
|
+
let current = real;
|
|
115
|
+
while (current !== top && (current + sep).startsWith(top + sep) && !relative(top, current).startsWith("..")) {
|
|
116
|
+
const entries = await readdir(current).catch(() => []);
|
|
117
|
+
if (entries.some(entry => entry === "package.json" || entry === "pyproject.toml" || /^requirements.*\.txt$/u.test(entry))) {
|
|
118
|
+
folders.push(current);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
current = dirname(current);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const found = new Map();
|
|
125
|
+
const add = (ecosystem, raw) => {
|
|
126
|
+
const name = normalizePackageName(ecosystem, raw);
|
|
127
|
+
if (name !== undefined && found.size < MAX_DEPENDENCIES)
|
|
128
|
+
found.set(`${ecosystem}:${name}`, { ecosystem, name });
|
|
129
|
+
};
|
|
130
|
+
for (const folder of folders) {
|
|
131
|
+
const packageJson = await regularFileText(join(folder, "package.json"));
|
|
132
|
+
if (packageJson !== undefined)
|
|
133
|
+
npmDependencies(packageJson).forEach(name => add("npm", name));
|
|
134
|
+
const pyproject = await regularFileText(join(folder, "pyproject.toml"));
|
|
135
|
+
if (pyproject !== undefined)
|
|
136
|
+
pyprojectDependencies(pyproject).forEach(name => add("pypi", name));
|
|
137
|
+
for (const entry of (await readdir(folder).catch(() => [])).filter(entry => /^requirements.*\.txt$/u.test(entry)).slice(0, 10)) {
|
|
138
|
+
const text = await regularFileText(join(folder, entry));
|
|
139
|
+
if (text !== undefined)
|
|
140
|
+
requirementsDependencies(text).forEach(name => add("pypi", name));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return [...found.values()];
|
|
144
|
+
}
|
|
145
|
+
const SETTING_MS = 60 * 60_000;
|
|
146
|
+
const RETRY_AFTER_FAILURE_MS = 5 * 60_000;
|
|
147
|
+
const INDEX_MS = 24 * 60 * 60_000;
|
|
148
|
+
const RULES_MS = 60 * 60_000;
|
|
149
|
+
const MAX_SUBJECTS = 10;
|
|
150
|
+
const MAX_BLOCK_CHARACTERS = 2_000;
|
|
151
|
+
const subjectKey = (subject) => subject.kind === "repository" ? `repository:${subject.repository}` : `package:${subject.ecosystem}:${subject.name}`;
|
|
152
|
+
/** The subjects on Lore's public list that this checkout is, or depends on, minus the workspace's own. */
|
|
153
|
+
export function matchPublicRules(index, checkout, own) {
|
|
154
|
+
const listed = new Set(index.map(subjectKey));
|
|
155
|
+
const ownKeys = new Set([...own.repositories.map(repository => `repository:${repository}`), ...own.packages.map(item => `package:${item.ecosystem}:${item.name}`)]);
|
|
156
|
+
const identity = checkout.repository === undefined ? undefined : repositoryIdentity(checkout.repository);
|
|
157
|
+
const candidates = [
|
|
158
|
+
...(identity === undefined ? [] : [{ kind: "repository", repository: identity }]),
|
|
159
|
+
...checkout.dependencies.map(item => ({ kind: "package", ecosystem: item.ecosystem, name: item.name })),
|
|
160
|
+
];
|
|
161
|
+
return candidates.filter(subject => listed.has(subjectKey(subject)) && !ownKeys.has(subjectKey(subject))).slice(0, MAX_SUBJECTS);
|
|
162
|
+
}
|
|
163
|
+
/** The block agents get: whole rule lines only, within its budget, framed as another team's rules, never the workspace's own decisions. */
|
|
164
|
+
export function renderPublicRulesBlock(sections) {
|
|
165
|
+
let text = [
|
|
166
|
+
"## Rules from outside your workspace",
|
|
167
|
+
"",
|
|
168
|
+
"The maintainers of this repository and the makers of packages it uses published these rules with Lore. Follow them where they apply; your team's decisions and the user's request come first.",
|
|
169
|
+
"",
|
|
170
|
+
PUBLIC_RULES_LIMITS,
|
|
171
|
+
].join("\n");
|
|
172
|
+
const header = text;
|
|
173
|
+
for (const { subject, rules } of sections) {
|
|
174
|
+
const title = subject.kind === "repository"
|
|
175
|
+
? `\n\n### ${subject.repository.replace(/^github\.com\//u, "")}, from its maintainers`
|
|
176
|
+
: `\n\n### ${packageLabel(subject.ecosystem, subject.name)}, from its makers`;
|
|
177
|
+
let section = title;
|
|
178
|
+
for (const rule of rules) {
|
|
179
|
+
const line = `\n${publicRuleLine(rule)}`;
|
|
180
|
+
if (text.length + section.length + line.length > MAX_BLOCK_CHARACTERS)
|
|
181
|
+
break;
|
|
182
|
+
section += line;
|
|
183
|
+
}
|
|
184
|
+
if (section !== title)
|
|
185
|
+
text += section;
|
|
186
|
+
}
|
|
187
|
+
return text === header ? undefined : escapeLoreContextDelimiters(text);
|
|
188
|
+
}
|
|
189
|
+
async function cached(cache, key, maxAgeMs, now, load) {
|
|
190
|
+
const saved = await cache.read(key).catch(() => undefined);
|
|
191
|
+
if (saved !== undefined && now - saved.writtenAt < maxAgeMs)
|
|
192
|
+
return saved.value;
|
|
193
|
+
// After a failure, wait a few minutes before asking again instead of on every prompt.
|
|
194
|
+
const failed = await cache.read(`${key}:failed`).catch(() => undefined);
|
|
195
|
+
if (failed !== undefined && now - failed.writtenAt < RETRY_AFTER_FAILURE_MS)
|
|
196
|
+
return saved?.value;
|
|
197
|
+
const fresh = await load(saved?.value).catch(() => undefined);
|
|
198
|
+
if (fresh === undefined) {
|
|
199
|
+
await cache.write(`${key}:failed`, true).catch(() => undefined);
|
|
200
|
+
return saved?.value;
|
|
201
|
+
}
|
|
202
|
+
await cache.write(key, fresh).catch(() => undefined);
|
|
203
|
+
return fresh;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* The block of public rules for a checkout, or undefined: off on this machine
|
|
207
|
+
* or for the workspace, nothing matched, or Lore unreachable with nothing
|
|
208
|
+
* cached. Each network call is short and failures fall back to the cache.
|
|
209
|
+
*/
|
|
210
|
+
export async function publicRulesForCheckout(input) {
|
|
211
|
+
const call = input.fetch ?? fetch;
|
|
212
|
+
const now = input.now ?? Date.now();
|
|
213
|
+
const api = input.apiUrl.replace(/\/+$/u, "");
|
|
214
|
+
const timeout = () => AbortSignal.timeout(input.timeoutMs ?? 600);
|
|
215
|
+
const [setting, index] = await Promise.all([
|
|
216
|
+
cached(input.cache, "public-rules-setting", SETTING_MS, now, async () => {
|
|
217
|
+
const response = await call(`${api}/v1/workspace/package-rules`, { headers: { accept: "application/json", authorization: `Bearer ${input.token}` }, signal: timeout() });
|
|
218
|
+
// A connection that may not read the setting, or a server without it, gets nothing.
|
|
219
|
+
if (response.status === 403 || response.status === 404)
|
|
220
|
+
return { enabled: false, own: { repositories: [], packages: [] } };
|
|
221
|
+
return response.ok ? await response.json() : undefined;
|
|
222
|
+
}),
|
|
223
|
+
cached(input.cache, "public-rules-index", INDEX_MS, now, async (previous) => {
|
|
224
|
+
const response = await call(`${api}/public/v1/rules/index`, { headers: { accept: "application/json", ...(previous?.etag ? { "if-none-match": previous.etag } : {}) }, signal: timeout() });
|
|
225
|
+
if (response.status === 304 && previous)
|
|
226
|
+
return previous;
|
|
227
|
+
if (!response.ok)
|
|
228
|
+
return undefined;
|
|
229
|
+
const etag = response.headers.get("etag");
|
|
230
|
+
return { ...(etag ? { etag } : {}), entries: (await response.json()).entries };
|
|
231
|
+
}),
|
|
232
|
+
]);
|
|
233
|
+
// The workspace's choice unknown: nothing, rather than rules an admin may have turned off.
|
|
234
|
+
if (setting?.enabled !== true || !index?.entries.length)
|
|
235
|
+
return undefined;
|
|
236
|
+
const dependencies = input.root === undefined ? [] : await readProjectDependencies(input.root, input.cwd);
|
|
237
|
+
const subjects = matchPublicRules(index.entries, { ...(input.repository && !input.skipRepository ? { repository: input.repository } : {}), dependencies }, setting.own);
|
|
238
|
+
if (subjects.length === 0)
|
|
239
|
+
return undefined;
|
|
240
|
+
const sections = await Promise.all(subjects.map(async (subject) => {
|
|
241
|
+
const rules = await cached(input.cache, `public-rules:${subjectKey(subject)}`, RULES_MS, now, async () => {
|
|
242
|
+
const path = subject.kind === "repository"
|
|
243
|
+
? `/public/v1/rules/${subject.repository.replace(/^github\.com\//u, "")}?channel=lore_context`
|
|
244
|
+
: `/public/v1/packages/${subject.ecosystem}/rules?channel=client&name=${encodeURIComponent(subject.name)}`;
|
|
245
|
+
const response = await call(`${api}${path}`, { headers: { accept: "application/json" }, signal: timeout() });
|
|
246
|
+
if (response.status === 404)
|
|
247
|
+
return [];
|
|
248
|
+
return response.ok ? (await response.json()).rules.map(rule => rule.text) : undefined;
|
|
249
|
+
});
|
|
250
|
+
return { subject, rules: rules ?? [] };
|
|
251
|
+
}));
|
|
252
|
+
return renderPublicRulesBlock(sections);
|
|
253
|
+
}
|
|
254
|
+
/** A cache for a long-running process, such as the MCP server. */
|
|
255
|
+
export function memoryPublicRulesCache() {
|
|
256
|
+
const entries = new Map();
|
|
257
|
+
return {
|
|
258
|
+
async read(key) { return entries.get(key); },
|
|
259
|
+
async write(key, value) { entries.set(key, { writtenAt: Date.now(), value }); },
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/** The Git checkout around a folder: the nearest folder up that holds `.git`. */
|
|
263
|
+
export async function checkoutRoot(cwd) {
|
|
264
|
+
let current = resolve(cwd);
|
|
265
|
+
while (true) {
|
|
266
|
+
if (await lstat(join(current, ".git")).then(() => true, () => false))
|
|
267
|
+
return current;
|
|
268
|
+
if (dirname(current) === current)
|
|
269
|
+
return undefined;
|
|
270
|
+
current = dirname(current);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=public-rules-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-rules-client.js","sourceRoot":"","sources":["../src/public-rules-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAyB,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAU7D,MAAM,kBAAkB,GAAG,SAAS,CAAC;AACrC,MAAM,gBAAgB,G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AC,CAAC,CAAC,CAAC;QAC5C,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;KAChF,CAAC;AACJ,CAAC;AAED,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,GAAW;IAC5C,IAAI,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,OAAO,IAAI,EAAE,CAAC;QACZ,IAAI,MAAM,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC;YAAE,OAAO,OAAO,CAAC;QACrF,IAAI,OAAO,CAAC,OAAO,CAAC,KAAK,OAAO;YAAE,OAAO,SAAS,CAAC;QACnD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Public rules beta: the most rules one repository can publish, and how long each can be. */
|
|
3
|
+
export declare const PUBLIC_RULES_PER_REPOSITORY = 50;
|
|
4
|
+
export declare const PUBLIC_RULE_MAX_LENGTH = 500;
|
|
5
|
+
/** A GitHub owner or repository name as Lore accepts it in a public address: never only dots. */
|
|
6
|
+
export declare const PUBLIC_REPOSITORY_SEGMENT: RegExp;
|
|
7
|
+
export type PublicRuleRefusalKind = "too_long" | "hidden" | "private" | "link" | "command";
|
|
8
|
+
/** Why this text can't be published, and what kind of reason that is, or null when it can. */
|
|
9
|
+
export declare function publicRuleRefusal(content: string): {
|
|
10
|
+
kind: PublicRuleRefusalKind;
|
|
11
|
+
message: string;
|
|
12
|
+
} | null;
|
|
13
|
+
/** Why this text can't be published, or null when it can. Only the text is ever public. */
|
|
14
|
+
export declare function publicRuleProblem(content: string): string | null;
|
|
15
|
+
export declare const VerifyPublicRepositoryRequestSchema: z.ZodObject<{
|
|
16
|
+
repository: z.ZodString;
|
|
17
|
+
githubToken: z.ZodString;
|
|
18
|
+
}, z.core.$strict>;
|
|
19
|
+
export type VerifyPublicRepositoryRequest = z.infer<typeof VerifyPublicRepositoryRequestSchema>;
|
|
20
|
+
export declare const PublicRepositorySchema: z.ZodObject<{
|
|
21
|
+
repository: z.ZodString;
|
|
22
|
+
permission: z.ZodEnum<{
|
|
23
|
+
admin: "admin";
|
|
24
|
+
maintain: "maintain";
|
|
25
|
+
}>;
|
|
26
|
+
verifiedAt: z.ZodISODateTime;
|
|
27
|
+
}, z.core.$strict>;
|
|
28
|
+
export declare const PublicRuleSchema: z.ZodObject<{
|
|
29
|
+
learningId: z.ZodUUID;
|
|
30
|
+
content: z.ZodString;
|
|
31
|
+
repository: z.ZodString;
|
|
32
|
+
publishedAt: z.ZodISODateTime;
|
|
33
|
+
publishedBy: z.ZodNullable<z.ZodString>;
|
|
34
|
+
askedBefore: z.ZodNumber;
|
|
35
|
+
askedSince: z.ZodNumber;
|
|
36
|
+
withheld: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
export type PublicRule = z.infer<typeof PublicRuleSchema>;
|
|
39
|
+
export declare const PublicRulesOverviewSchema: z.ZodObject<{
|
|
40
|
+
repositories: z.ZodArray<z.ZodObject<{
|
|
41
|
+
repository: z.ZodString;
|
|
42
|
+
permission: z.ZodEnum<{
|
|
43
|
+
admin: "admin";
|
|
44
|
+
maintain: "maintain";
|
|
45
|
+
}>;
|
|
46
|
+
verifiedAt: z.ZodISODateTime;
|
|
47
|
+
}, z.core.$strict>>;
|
|
48
|
+
rules: z.ZodArray<z.ZodObject<{
|
|
49
|
+
learningId: z.ZodUUID;
|
|
50
|
+
content: z.ZodString;
|
|
51
|
+
repository: z.ZodString;
|
|
52
|
+
publishedAt: z.ZodISODateTime;
|
|
53
|
+
publishedBy: z.ZodNullable<z.ZodString>;
|
|
54
|
+
askedBefore: z.ZodNumber;
|
|
55
|
+
askedSince: z.ZodNumber;
|
|
56
|
+
withheld: z.ZodOptional<z.ZodString>;
|
|
57
|
+
}, z.core.$strict>>;
|
|
58
|
+
lost: z.ZodArray<z.ZodObject<{
|
|
59
|
+
repository: z.ZodString;
|
|
60
|
+
at: z.ZodISODateTime;
|
|
61
|
+
}, z.core.$strict>>;
|
|
62
|
+
packages: z.ZodArray<z.ZodObject<{
|
|
63
|
+
id: z.ZodUUID;
|
|
64
|
+
ecosystem: z.ZodEnum<{
|
|
65
|
+
npm: "npm";
|
|
66
|
+
pypi: "pypi";
|
|
67
|
+
}>;
|
|
68
|
+
name: z.ZodString;
|
|
69
|
+
repository: z.ZodString;
|
|
70
|
+
verifiedAt: z.ZodISODateTime;
|
|
71
|
+
rules: z.ZodArray<z.ZodObject<{
|
|
72
|
+
learningId: z.ZodUUID;
|
|
73
|
+
content: z.ZodString;
|
|
74
|
+
publishedBy: z.ZodNullable<z.ZodString>;
|
|
75
|
+
withheld: z.ZodOptional<z.ZodString>;
|
|
76
|
+
}, z.core.$strict>>;
|
|
77
|
+
}, z.core.$strict>>;
|
|
78
|
+
}, z.core.$strict>;
|
|
79
|
+
export type PublicRulesOverview = z.infer<typeof PublicRulesOverviewSchema>;
|
|
80
|
+
export declare const PUBLIC_RULES_BLOCK_START = "<!-- BEGIN LORE PUBLIC RULES -->";
|
|
81
|
+
export declare const PUBLIC_RULES_BLOCK_END = "<!-- END LORE PUBLIC RULES -->";
|
|
82
|
+
export declare const AGENT_POINTER_START = "<!-- BEGIN LORE AGENTS.md -->";
|
|
83
|
+
export declare const AGENT_POINTER_END = "<!-- END LORE AGENTS.md -->";
|
|
84
|
+
export declare const PublicRulesBlockSchema: z.ZodObject<{
|
|
85
|
+
repository: z.ZodString;
|
|
86
|
+
pageUrl: z.ZodURL;
|
|
87
|
+
rulesUrl: z.ZodURL;
|
|
88
|
+
block: z.ZodString;
|
|
89
|
+
}, z.core.$strict>;
|
|
90
|
+
export type PublicRulesBlock = z.infer<typeof PublicRulesBlockSchema>;
|
|
91
|
+
/** The block Lore keeps in a repository's AGENTS.md. */
|
|
92
|
+
export declare function renderPublicRulesBlock(input: {
|
|
93
|
+
rules: readonly string[];
|
|
94
|
+
pageUrl: string;
|
|
95
|
+
rulesUrl: string;
|
|
96
|
+
}): string;
|
|
97
|
+
/** The pointer for agents that read their own file and can import AGENTS.md (Claude Code, Gemini CLI). */
|
|
98
|
+
export declare const AGENT_POINTER_BLOCK: string;
|
|
99
|
+
/**
|
|
100
|
+
* The file with Lore's block put in or replaced, leaving everything outside
|
|
101
|
+
* the markers as it was. Throws when the markers are broken or repeated, so
|
|
102
|
+
* nobody's text is overwritten by guesswork.
|
|
103
|
+
*/
|
|
104
|
+
export declare function withManagedBlock(text: string, block: string, start: string, end: string): string;
|
|
105
|
+
/**
|
|
106
|
+
* A repository's public rules as Markdown, for agents that fetch them or call
|
|
107
|
+
* the hosted MCP tool: the rules framed as the maintainers', with a link to
|
|
108
|
+
* their page. Each rule is one cleaned line.
|
|
109
|
+
*/
|
|
110
|
+
export declare function renderPublicRulesMarkdown(input: {
|
|
111
|
+
repository: string;
|
|
112
|
+
rules: readonly {
|
|
113
|
+
text: string;
|
|
114
|
+
askedCount: number;
|
|
115
|
+
}[];
|
|
116
|
+
pageUrl: string;
|
|
117
|
+
selected?: boolean;
|
|
118
|
+
audience?: "repository" | "package";
|
|
119
|
+
}): string;
|
|
120
|
+
export { PUBLIC_RULES_LIMITS, publicRuleLine, visiblePublicRuleText } from "./public-rule-text.js";
|
|
121
|
+
//# sourceMappingURL=public-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-rules.d.ts","sourceRoot":"","sources":["../src/public-rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,8FAA8F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AO,sBAAsB,CAAC,CAAC;AAEtE,wDAAwD;AACxD,wBAAgB,sBAAsB,CAAC,KAAK,EAAE;IAAE,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAerH;AAED,0GAA0G;AAC1G,eAAO,MAAM,mBAAmB,QAAoE,CAAC;AAErG;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAShG;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,SAAS;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,YAAY,GAAG,SAAS,CAAA;CAAE,GAAG,MAAM,CAgBjN;AAED,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PUBLIC_RULES_LIMITS, publicRuleLine, visiblePublicRuleText } from "./public-rule-text.js";
|
|
3
|
+
import { redactSensitiveText } from "./redaction.js";
|
|
4
|
+
import { PublicPackageSchema } from "./package-rules.js";
|
|
5
|
+
/** Public rules beta: the most rules one repository can publish, and how long each can be. */
|
|
6
|
+
export const PUBLIC_RULES_PER_REPOSITORY = 50;
|
|
7
|
+
export const PUBLIC_RULE_MAX_LENGTH = 500;
|
|
8
|
+
/** A GitHub owner or repository name as Lore accepts it in a public address: never only dots. */
|
|
9
|
+
export const PUBLIC_REPOSITORY_SEGMENT = /^(?!\.+$)[A-Za-z0-9_.-]{1,100}$/u;
|
|
10
|
+
// Agents outside the workspace follow public rules, so a rule never carries a link, or a way to
|
|
11
|
+
// fetch, install or run software: a taken-over owner or admin account can't turn it into a payload.
|
|
12
|
+
const PUBLIC_RULE_LINK = [
|
|
13
|
+
/\b[a-z][a-z0-9+.-]*:\/\/|\bwww\./iu,
|
|
14
|
+
// A host with a path, such as example.sh/x, but not a file name such as index.ts/.
|
|
15
|
+
/\b(?:[a-z0-9-]+\.)+(?!(?:[cm]?js|jsx|tsx?|md|py|rb|rs|json|ya?ml|toml|txt|vue|css|lock)\/)[a-z]{2,24}\/\S/iu,
|
|
16
|
+
/\b\d{1,3}(?:\.\d{1,3}){3}\b/u,
|
|
17
|
+
];
|
|
18
|
+
const PUBLIC_RULE_COMMAND = [
|
|
19
|
+
// Piping into a shell or an interpreter.
|
|
20
|
+
/\|\s*(?:sudo\s+)?(?:(?:ba|z|da|k|fi|c|tc)?sh|python[0-9.]*|node|deno|bun|perl|ruby|php|iex|pwsh|powershell)\b/iu,
|
|
21
|
+
// Downloading.
|
|
22
|
+
/\b(?:curl|wget|Invoke-WebRequest|Invoke-RestMethod|Invoke-Expression|iwr|irm|certutil|bitsadmin)\b/iu,
|
|
23
|
+
// Running a package straight from a registry.
|
|
24
|
+
/\b(?:npx|pnpx|bunx|uvx|pipx)\b|\b(?:pnpm|yarn)\s+dlx\b|\bnpm\s+(?:exec|x)\b/iu,
|
|
25
|
+
// Installing packages. A bare `pnpm install` is fine; one followed by a name is not.
|
|
26
|
+
/\b(?:pip[0-9.]*|uv|poetry|pdm|conda|gem|cargo|go|brew|apt(?:-get)?|yum|dnf|apk|choco|winget|scoop)\s+(?:pip\s+)?(?:install|add)\b/iu,
|
|
27
|
+
/\b(?:npm|pnpm|yarn|bun)\s+(?:add\b|(?:install|i)\s+(?!-)[@A-Za-z0-9])/iu,
|
|
28
|
+
// Scripts that run on install, and Git hooks.
|
|
29
|
+
/\b(?:pre|post)install\b|\bcore\.hooksPath\b/iu,
|
|
30
|
+
// Running as root, or deleting recursively.
|
|
31
|
+
/\bsudo\b|\brm\s+-[a-z]*(?:r[a-z]*f|f[a-z]*r)/iu,
|
|
32
|
+
// Decoding something hidden. An encoded blob itself already reads as private.
|
|
33
|
+
/\bbase64\s+(?:-d|-D|--decode)\b|\batob\s*\(|\bFromBase64String\b|-EncodedCommand\b/iu,
|
|
34
|
+
];
|
|
35
|
+
/** Why this text can't be published, and what kind of reason that is, or null when it can. */
|
|
36
|
+
export function publicRuleRefusal(content) {
|
|
37
|
+
if (content.trim().length > PUBLIC_RULE_MAX_LENGTH)
|
|
38
|
+
return { kind: "too_long", message: `Public rules can be at most ${PUBLIC_RULE_MAX_LENGTH} characters. Shorten the learning first.` };
|
|
39
|
+
// Every channel then shows exactly what the owner or admin saw, with nothing hidden.
|
|
40
|
+
if (visiblePublicRuleText(content) !== content)
|
|
41
|
+
return { kind: "hidden", message: "This learning contains hidden characters. Edit it to remove them before publishing." };
|
|
42
|
+
if (redactSensitiveText(content).findings.length > 0)
|
|
43
|
+
return { kind: "private", message: "This learning contains something that looks private. Remove it before publishing." };
|
|
44
|
+
// Full-width and other look-alike letters read the same to an agent.
|
|
45
|
+
const text = content.normalize("NFKC");
|
|
46
|
+
if (PUBLIC_RULE_LINK.some(pattern => pattern.test(text))) {
|
|
47
|
+
return { kind: "link", message: "Public rules can't contain links, because agents outside your workspace follow them. Remove the link before publishing." };
|
|
48
|
+
}
|
|
49
|
+
if (PUBLIC_RULE_COMMAND.some(pattern => pattern.test(text))) {
|
|
50
|
+
return { kind: "command", message: "Public rules can't tell agents to download, install or run software, because agents outside your workspace follow them. Remove the command before publishing." };
|
|
51
|
+
}
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
/** Why this text can't be published, or null when it can. Only the text is ever public. */
|
|
55
|
+
export function publicRuleProblem(content) {
|
|
56
|
+
return publicRuleRefusal(content)?.message ?? null;
|
|
57
|
+
}
|
|
58
|
+
export const VerifyPublicRepositoryRequestSchema = z.object({
|
|
59
|
+
repository: z.string().trim().min(3).max(300),
|
|
60
|
+
/** The person's GitHub token from the repository picker; the API checks it with GitHub and keeps nothing. */
|
|
61
|
+
githubToken: z.string().trim().min(10).max(500),
|
|
62
|
+
}).strict();
|
|
63
|
+
export const PublicRepositorySchema = z.object({
|
|
64
|
+
repository: z.string(),
|
|
65
|
+
permission: z.enum(["admin", "maintain"]),
|
|
66
|
+
verifiedAt: z.iso.datetime({ offset: true }),
|
|
67
|
+
}).strict();
|
|
68
|
+
export const PublicRuleSchema = z.object({
|
|
69
|
+
learningId: z.uuid(),
|
|
70
|
+
content: z.string(),
|
|
71
|
+
repository: z.string(),
|
|
72
|
+
publishedAt: z.iso.datetime({ offset: true }),
|
|
73
|
+
/** The member's name, or email without one; null when nobody is recorded. */
|
|
74
|
+
publishedBy: z.string().nullable(),
|
|
75
|
+
/** Pull requests that asked for it before and since it was published (repeat mode). */
|
|
76
|
+
askedBefore: z.number().int().nonnegative(),
|
|
77
|
+
askedSince: z.number().int().nonnegative(),
|
|
78
|
+
/** Why Lore no longer sends this rule anywhere, when it wouldn't be published today. */
|
|
79
|
+
withheld: z.string().optional(),
|
|
80
|
+
}).strict();
|
|
81
|
+
export const PublicRulesOverviewSchema = z.object({
|
|
82
|
+
repositories: z.array(PublicRepositorySchema),
|
|
83
|
+
rules: z.array(PublicRuleSchema),
|
|
84
|
+
/** Repositories another workspace verified since, which took them over. */
|
|
85
|
+
lost: z.array(z.object({ repository: z.string(), at: z.iso.datetime({ offset: true }) }).strict()),
|
|
86
|
+
/** Packages of the verified repositories, with rules for anyone using them. */
|
|
87
|
+
packages: z.array(PublicPackageSchema),
|
|
88
|
+
}).strict();
|
|
89
|
+
export const PUBLIC_RULES_BLOCK_START = "<!-- BEGIN LORE PUBLIC RULES -->";
|
|
90
|
+
export const PUBLIC_RULES_BLOCK_END = "<!-- END LORE PUBLIC RULES -->";
|
|
91
|
+
export const AGENT_POINTER_START = "<!-- BEGIN LORE AGENTS.md -->";
|
|
92
|
+
export const AGENT_POINTER_END = "<!-- END LORE AGENTS.md -->";
|
|
93
|
+
export const PublicRulesBlockSchema = z.object({
|
|
94
|
+
repository: z.string(),
|
|
95
|
+
pageUrl: z.url(),
|
|
96
|
+
rulesUrl: z.url(),
|
|
97
|
+
block: z.string(),
|
|
98
|
+
}).strict();
|
|
99
|
+
/** The block Lore keeps in a repository's AGENTS.md. */
|
|
100
|
+
export function renderPublicRulesBlock(input) {
|
|
101
|
+
return [
|
|
102
|
+
PUBLIC_RULES_BLOCK_START,
|
|
103
|
+
"<!-- Kept by Lore. Change these rules in Lore, then run `lore github rules` to update this block. -->",
|
|
104
|
+
"## Rules from this project's maintainers",
|
|
105
|
+
"",
|
|
106
|
+
`Agents working in this repository, including contributors' agents: follow these rules. For rules about your task, fetch ${input.rulesUrl}?task= followed by a few words about it.`,
|
|
107
|
+
"",
|
|
108
|
+
PUBLIC_RULES_LIMITS,
|
|
109
|
+
"",
|
|
110
|
+
...input.rules.map(publicRuleLine),
|
|
111
|
+
"",
|
|
112
|
+
`Kept by Lore: ${input.pageUrl}`,
|
|
113
|
+
PUBLIC_RULES_BLOCK_END,
|
|
114
|
+
].join("\n");
|
|
115
|
+
}
|
|
116
|
+
/** The pointer for agents that read their own file and can import AGENTS.md (Claude Code, Gemini CLI). */
|
|
117
|
+
export const AGENT_POINTER_BLOCK = [AGENT_POINTER_START, "@AGENTS.md", AGENT_POINTER_END].join("\n");
|
|
118
|
+
/**
|
|
119
|
+
* The file with Lore's block put in or replaced, leaving everything outside
|
|
120
|
+
* the markers as it was. Throws when the markers are broken or repeated, so
|
|
121
|
+
* nobody's text is overwritten by guesswork.
|
|
122
|
+
*/
|
|
123
|
+
export function withManagedBlock(text, block, start, end) {
|
|
124
|
+
const starts = text.split(start).length - 1;
|
|
125
|
+
const ends = text.split(end).length - 1;
|
|
126
|
+
if (starts !== ends || starts > 1)
|
|
127
|
+
throw new Error(`Lore's markers (${start}) are broken or repeated. Fix them by hand, then run this again.`);
|
|
128
|
+
if (starts === 0)
|
|
129
|
+
return text.trim() === "" ? `${block}\n` : `${text.replace(/\s*$/u, "")}\n\n${block}\n`;
|
|
130
|
+
const from = text.indexOf(start);
|
|
131
|
+
const to = text.indexOf(end) + end.length;
|
|
132
|
+
if (to < from)
|
|
133
|
+
throw new Error(`Lore's markers (${start}) are out of order. Fix them by hand, then run this again.`);
|
|
134
|
+
return `${text.slice(0, from)}${block}${text.slice(to)}`;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* A repository's public rules as Markdown, for agents that fetch them or call
|
|
138
|
+
* the hosted MCP tool: the rules framed as the maintainers', with a link to
|
|
139
|
+
* their page. Each rule is one cleaned line.
|
|
140
|
+
*/
|
|
141
|
+
export function renderPublicRulesMarkdown(input) {
|
|
142
|
+
const who = input.audience === "package"
|
|
143
|
+
? `The makers of ${input.repository} ask everyone using it, and their agents, to follow these rules`
|
|
144
|
+
: `The maintainers of ${input.repository} ask contributors and their agents to follow these rules`;
|
|
145
|
+
return [
|
|
146
|
+
`# Rules for ${input.repository}`,
|
|
147
|
+
"",
|
|
148
|
+
`${who}${input.selected ? ". These are the ones most related to your task" : ""}.`,
|
|
149
|
+
"",
|
|
150
|
+
PUBLIC_RULES_LIMITS,
|
|
151
|
+
"",
|
|
152
|
+
...input.rules.map(rule => `${publicRuleLine(rule.text)}${rule.askedCount > 1 ? ` (asked in ${rule.askedCount} pull requests)` : ""}`),
|
|
153
|
+
"",
|
|
154
|
+
`Kept by Lore: ${input.pageUrl}`,
|
|
155
|
+
"",
|
|
156
|
+
].join("\n");
|
|
157
|
+
}
|
|
158
|
+
export { PUBLIC_RULES_LIMITS, publicRuleLine, visiblePublicRuleText } from "./public-rule-text.js";
|
|
159
|
+
//# sourceMappingURL=public-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"public-rules.js","sourceRoot":"","sources":["../src/public-rules.ts"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CAAC,CAAC,CAAC,gDAAgD,CAAC,CAAC,CAAC,EAAE,GAAG;QAClF,EAAE;QACF,mBAAmB;QACnB,EAAE;QACF,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,IAAI,CAAC,UAAU,iBAAiB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QACtI,EAAE;QACF,iBAAiB,KAAK,CAAC,OAAO,EAAE;QAChC,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC;AAED,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repeat mode for pull request harvest: maintainers' requests become hidden
|
|
3
|
+
* candidate rules, grouped per repository, and a rule is proposed once this
|
|
4
|
+
* many pull requests asked for it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const REPEAT_PROPOSAL_THRESHOLD = 2;
|
|
7
|
+
/** The same rule in different case, spacing or punctuation. */
|
|
8
|
+
export declare function ruleKey(rule: string): string;
|
|
9
|
+
/** `lore github harvest` names each pull request's session `github:<repo>:pull:<number>`. */
|
|
10
|
+
export declare function pullRequestFromSession(sessionId: string | undefined): {
|
|
11
|
+
repository: string;
|
|
12
|
+
number: number;
|
|
13
|
+
} | undefined;
|
|
14
|
+
export interface PullRequestRuleMention {
|
|
15
|
+
/** The group the rule matched, or the id for a group this pull request starts. */
|
|
16
|
+
groupId: string;
|
|
17
|
+
/** Set when this pull request starts the group: the group's wording. */
|
|
18
|
+
newGroupText?: string;
|
|
19
|
+
rule: string;
|
|
20
|
+
evidence: string;
|
|
21
|
+
embedding: number[] | null;
|
|
22
|
+
embeddingModel: string | null;
|
|
23
|
+
}
|
|
24
|
+
export interface PullRequestRuleCapture {
|
|
25
|
+
repository: string;
|
|
26
|
+
prNumber: number;
|
|
27
|
+
merged: boolean;
|
|
28
|
+
mentions: PullRequestRuleMention[];
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=pull-request-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pull-request-rules.d.ts","sourceRoot":"","sources":["../src/pull-request-rules.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C,+DAA+D;AAC/D,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,6FAA6F;AAC7F,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAGxH;AAED,MAAM,WAAW,sBAAsB;IACrC,kFAAkF;IAClF,OAAO,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAC3B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,sBAAsB,EAAE,CAAC;CACpC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repeat mode for pull request harvest: maintainers' requests become hidden
|
|
3
|
+
* candidate rules, grouped per repository, and a rule is proposed once this
|
|
4
|
+
* many pull requests asked for it.
|
|
5
|
+
*/
|
|
6
|
+
export const REPEAT_PROPOSAL_THRESHOLD = 2;
|
|
7
|
+
/** The same rule in different case, spacing or punctuation. */
|
|
8
|
+
export function ruleKey(rule) {
|
|
9
|
+
return rule.normalize("NFKC").toLocaleLowerCase().replace(/[^\p{L}\p{N}]+/gu, " ").trim();
|
|
10
|
+
}
|
|
11
|
+
/** `lore github harvest` names each pull request's session `github:<repo>:pull:<number>`. */
|
|
12
|
+
export function pullRequestFromSession(sessionId) {
|
|
13
|
+
const match = sessionId === undefined ? null : /^github:(.+):pull:(\d{1,9})$/u.exec(sessionId);
|
|
14
|
+
return match ? { repository: match[1], number: Number(match[2]) } : undefined;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=pull-request-rules.js.map
|