@indigoai-us/hq-cli 5.345.253 → 5.345.254
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/CHANGELOG.md +32 -0
- package/contracts/host-canary-release.json +11 -5
- package/dist/command-catalog.generated.d.ts +61 -0
- package/dist/command-catalog.generated.js +75 -0
- package/dist/commands/ci-intake.d.ts +17 -0
- package/dist/commands/ci-intake.js +43 -1
- package/dist/commands/ci-priorities.d.ts +56 -0
- package/dist/commands/ci-priorities.js +144 -0
- package/dist/commands/ci.js +2 -1
- package/dist/commands/cloud.d.ts +11 -0
- package/dist/commands/cloud.js +76 -0
- package/dist/lib/daemon/verified-jq.d.ts +6 -0
- package/dist/lib/daemon/verified-jq.js +17 -5
- package/dist/lib/hook-engine/fleet-registration.d.ts +4 -0
- package/dist/lib/hook-engine/fleet-registration.js +25 -3
- package/dist/lib/smart-ci/priorities.d.ts +331 -0
- package/dist/lib/smart-ci/priorities.js +964 -0
- package/dist/lib/smart-ci/priority-refresh.d.ts +192 -0
- package/dist/lib/smart-ci/priority-refresh.js +366 -0
- package/dist/lib/smart-ci/priority-snapshots.d.ts +88 -0
- package/dist/lib/smart-ci/priority-snapshots.js +233 -0
- package/dist/lib/smart-ci/sources.d.ts +294 -0
- package/dist/lib/smart-ci/sources.js +659 -0
- package/dist/lib/smart-ci/text.d.ts +24 -0
- package/dist/lib/smart-ci/text.js +83 -0
- package/dist/lib/smart-ci/work-in-flight.d.ts +68 -0
- package/dist/lib/smart-ci/work-in-flight.js +154 -0
- package/dist/lib/sync/cli-manifest-reconcile.d.ts +20 -0
- package/dist/lib/sync/cli-manifest-reconcile.js +170 -0
- package/dist/utils/host-registration.d.ts +1 -0
- package/dist/utils/host-registration.js +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,964 @@
|
|
|
1
|
+
import { RECORD_KIND_WORDS } from "./sources.js";
|
|
2
|
+
import { clip, hasPriorityCue, isoDay, slugTerms, textTerms } from "./text.js";
|
|
3
|
+
import { listWorkInFlight } from "./work-in-flight.js";
|
|
4
|
+
export const PRIORITY_MAP_SCHEMA = "hq-smart-ci.priority-map.v1";
|
|
5
|
+
export const DEFAULT_WEIGHTS = { standup: 0.4, "work-mesh": 0.25, session: 0.2, ontology: 0.15 };
|
|
6
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
7
|
+
/** A project with no thread, story or board change in this many days does not name current work. */
|
|
8
|
+
const PROJECT_ACTIVE_DAYS = 30;
|
|
9
|
+
/** A term carried by more than this share of the work items names nothing (a product prefix, for example). */
|
|
10
|
+
const COMMON_TERM_SHARE = 0.2;
|
|
11
|
+
const MAX_DISTINCTIVENESS = Math.log(100);
|
|
12
|
+
/** Two terms are one priority when they share at least this much of the smaller one's evidence. */
|
|
13
|
+
export const MERGE_THRESHOLD = 0.5;
|
|
14
|
+
/** The same-sentences rule also needs this many shared utterances, so two terms said once together do not merge. */
|
|
15
|
+
export const MERGE_MIN_SHARED_SENTENCES = 3;
|
|
16
|
+
function sharedCount(a, b) {
|
|
17
|
+
let n = 0;
|
|
18
|
+
for (const x of a)
|
|
19
|
+
if (b.has(x))
|
|
20
|
+
n += 1;
|
|
21
|
+
return n;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The merge rule. Two terms are the same priority when their evidence
|
|
25
|
+
* overlaps:
|
|
26
|
+
*
|
|
27
|
+
* - shared work: the projects, repos and sessions both terms name are at
|
|
28
|
+
* least MERGE_THRESHOLD (half) of the smaller term's work; or
|
|
29
|
+
* - same sentences: the standup utterances that say both terms are at least
|
|
30
|
+
* MERGE_THRESHOLD (half) of the utterances of the term said less often, and
|
|
31
|
+
* there are at least MERGE_MIN_SHARED_SENTENCES of them.
|
|
32
|
+
*
|
|
33
|
+
* Returns which rule holds and by how much, or null when the terms stay
|
|
34
|
+
* apart. The rule knows no topic: it only counts overlap.
|
|
35
|
+
*/
|
|
36
|
+
export function mergeReason(a, b) {
|
|
37
|
+
const work = sharedCount(a.work, b.work);
|
|
38
|
+
const smallerWork = Math.min(a.work.size, b.work.size);
|
|
39
|
+
if (work > 0 && work / smallerWork >= MERGE_THRESHOLD)
|
|
40
|
+
return { rule: "shared-work", shared: work, share: round(work / smallerWork) };
|
|
41
|
+
const sentences = sharedCount(a.sentences, b.sentences);
|
|
42
|
+
const smallerSentences = Math.min(a.sentences.size, b.sentences.size);
|
|
43
|
+
if (sentences >= MERGE_MIN_SHARED_SENTENCES && sentences / smallerSentences >= MERGE_THRESHOLD) {
|
|
44
|
+
return { rule: "same-sentences", shared: sentences, share: round(sentences / smallerSentences) };
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
function bump(map, key, by = 1) {
|
|
49
|
+
map.set(key, (map.get(key) ?? 0) + by);
|
|
50
|
+
}
|
|
51
|
+
function top(map) {
|
|
52
|
+
let best;
|
|
53
|
+
let bestCount = -1;
|
|
54
|
+
for (const [k, v] of map) {
|
|
55
|
+
if (v > bestCount) {
|
|
56
|
+
best = k;
|
|
57
|
+
bestCount = v;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return best;
|
|
61
|
+
}
|
|
62
|
+
function ms(timestamp) {
|
|
63
|
+
const v = Date.parse(timestamp);
|
|
64
|
+
return Number.isNaN(v) ? 0 : v;
|
|
65
|
+
}
|
|
66
|
+
function shortRepo(repo) {
|
|
67
|
+
return (repo.includes("/") ? repo.slice(repo.lastIndexOf("/") + 1) : repo).toLowerCase();
|
|
68
|
+
}
|
|
69
|
+
/** A project name as the ontology brief prints it, turned into the slug form project ids use. */
|
|
70
|
+
function slugify(name) {
|
|
71
|
+
return name
|
|
72
|
+
.toLowerCase()
|
|
73
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
74
|
+
.replace(/^-+|-+$/g, "");
|
|
75
|
+
}
|
|
76
|
+
function distinctiveness(count, standupUtterances, backgroundCount, background) {
|
|
77
|
+
if (background.utterances === 0 || standupUtterances === 0)
|
|
78
|
+
return 1;
|
|
79
|
+
const inStandups = count / standupUtterances;
|
|
80
|
+
const elsewhere = (backgroundCount + 1) / (background.utterances + 1);
|
|
81
|
+
return Math.min(MAX_DISTINCTIVENESS, Math.max(0, Math.log(inStandups / elsewhere)));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The base forms an -ing or -ed word may come from: "syncing" and "synced"
|
|
85
|
+
* from "sync", "shipping" from "ship", "rolled" from "roll", "based" from
|
|
86
|
+
* "base". The candidates are only looked up in the work vocabulary, so a word
|
|
87
|
+
* is folded onto a base only when the base is itself a term that names work.
|
|
88
|
+
*/
|
|
89
|
+
export function inflectionBases(word) {
|
|
90
|
+
const out = [];
|
|
91
|
+
const add = (base) => {
|
|
92
|
+
if (base.length < 2)
|
|
93
|
+
return;
|
|
94
|
+
out.push(base, `${base}e`);
|
|
95
|
+
const last = base.at(-1) ?? "";
|
|
96
|
+
if (base.length >= 3 && last === base.at(-2) && !"aeiou".includes(last))
|
|
97
|
+
out.push(base.slice(0, -1));
|
|
98
|
+
};
|
|
99
|
+
if (word.length > 5 && word.endsWith("ing"))
|
|
100
|
+
add(word.slice(0, -3));
|
|
101
|
+
if (word.length > 4 && word.endsWith("ied"))
|
|
102
|
+
out.push(`${word.slice(0, -3)}y`);
|
|
103
|
+
else if (word.length > 4 && word.endsWith("ed"))
|
|
104
|
+
add(word.slice(0, -2));
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
function round(n) {
|
|
108
|
+
return Math.round(n * 1000) / 1000;
|
|
109
|
+
}
|
|
110
|
+
/** Build the map. See the file header for the method. */
|
|
111
|
+
export function buildPriorityMap(input, opts = {}) {
|
|
112
|
+
const weights = { ...DEFAULT_WEIGHTS, ...opts.weights };
|
|
113
|
+
const topCount = opts.topCount ?? 5;
|
|
114
|
+
const keep = opts.keep ?? 15;
|
|
115
|
+
const fromMs = ms(input.window.from);
|
|
116
|
+
const toMs = ms(input.window.to);
|
|
117
|
+
const threads = input.mesh?.threads ?? [];
|
|
118
|
+
const projects = input.mesh?.projects ?? [];
|
|
119
|
+
const sessions = (input.sessions?.sessions ?? []).filter((s) => ms(s.lastTurnAt) >= fromMs);
|
|
120
|
+
const names = { ...(input.sessions?.names ?? {}), ...(input.mesh?.names ?? {}) };
|
|
121
|
+
const nameOf = (uid) => names[uid] ?? uid;
|
|
122
|
+
const entities = input.ontology?.entities ?? {};
|
|
123
|
+
const projectById = new Map(projects.map((p) => [p.projectId, p]));
|
|
124
|
+
// ---- the work vocabulary: which terms name which work.
|
|
125
|
+
const lastActivity = new Map();
|
|
126
|
+
for (const t of threads) {
|
|
127
|
+
if (t.projectId !== "")
|
|
128
|
+
lastActivity.set(t.projectId, Math.max(lastActivity.get(t.projectId) ?? 0, ms(t.lastActivityAt)));
|
|
129
|
+
}
|
|
130
|
+
for (const p of projects)
|
|
131
|
+
lastActivity.set(p.projectId, Math.max(lastActivity.get(p.projectId) ?? 0, ms(p.updatedAt)));
|
|
132
|
+
const activeSince = toMs - PROJECT_ACTIVE_DAYS * DAY_MS;
|
|
133
|
+
const activeProjects = [...lastActivity.entries()].filter(([, at]) => at >= activeSince).map(([id]) => id);
|
|
134
|
+
const ontologyProjects = (input.ontology?.activeProjects ?? []).map(slugify).filter((s) => s !== "");
|
|
135
|
+
const sessionRepos = [...new Set(sessions.map((s) => shortRepo(s.repo)).filter((r) => r !== ""))];
|
|
136
|
+
// The company's own name is on its work everywhere and names none of it.
|
|
137
|
+
const companyTerms = new Set(slugTerms(input.company));
|
|
138
|
+
// Words of the names of the repos the company works in ("cli" of hq-cli). Every session sits in a repo and the
|
|
139
|
+
// ontology lists projects named for their repo, so for these words a session or an ontology entry says where work
|
|
140
|
+
// is, not what it is about: they are scored on standup and Work Mesh evidence only.
|
|
141
|
+
const repoWords = new Set([...sessionRepos, ...(input.pullRequests ?? []).map((pr) => shortRepo(pr.repo))].flatMap((r) => slugTerms(r)).filter((t) => !companyTerms.has(t)));
|
|
142
|
+
const termsOfItem = new Map();
|
|
143
|
+
const itemTerms = (key, texts) => {
|
|
144
|
+
termsOfItem.set(key, [...new Set(texts.flatMap((t) => slugTerms(t)))].filter((t) => !RECORD_KIND_WORDS.has(t) && !companyTerms.has(t)));
|
|
145
|
+
};
|
|
146
|
+
for (const id of activeProjects)
|
|
147
|
+
itemTerms(`project:${id}`, [id, projectById.get(id)?.name ?? ""]);
|
|
148
|
+
for (const slug of ontologyProjects)
|
|
149
|
+
if (!termsOfItem.has(`project:${slug}`))
|
|
150
|
+
itemTerms(`project:${slug}`, [slug]);
|
|
151
|
+
for (const repo of sessionRepos)
|
|
152
|
+
itemTerms(`repo:${repo}`, [repo]);
|
|
153
|
+
const itemCount = termsOfItem.size;
|
|
154
|
+
const termItems = new Map();
|
|
155
|
+
for (const terms of termsOfItem.values())
|
|
156
|
+
for (const t of terms)
|
|
157
|
+
bump(termItems, t);
|
|
158
|
+
const stats = new Map();
|
|
159
|
+
const statsOf = (term) => {
|
|
160
|
+
let s = stats.get(term);
|
|
161
|
+
if (!s) {
|
|
162
|
+
s = {
|
|
163
|
+
term,
|
|
164
|
+
projects: new Set(),
|
|
165
|
+
repos: new Set(),
|
|
166
|
+
standup: 0,
|
|
167
|
+
mesh: 0,
|
|
168
|
+
session: 0,
|
|
169
|
+
ontology: 0,
|
|
170
|
+
utterances: 0,
|
|
171
|
+
cueUtterances: 0,
|
|
172
|
+
speakers: new Map(),
|
|
173
|
+
perStandup: new Map(),
|
|
174
|
+
meshEvidence: [],
|
|
175
|
+
sessionEvidence: [],
|
|
176
|
+
ontologyEvidence: [],
|
|
177
|
+
sessionIds: new Set(),
|
|
178
|
+
sentences: new Set(),
|
|
179
|
+
};
|
|
180
|
+
stats.set(term, s);
|
|
181
|
+
}
|
|
182
|
+
return s;
|
|
183
|
+
};
|
|
184
|
+
for (const [key, terms] of termsOfItem) {
|
|
185
|
+
for (const term of terms) {
|
|
186
|
+
if (itemCount >= 10 && (termItems.get(term) ?? 0) / itemCount > COMMON_TERM_SHARE)
|
|
187
|
+
continue;
|
|
188
|
+
const s = statsOf(term);
|
|
189
|
+
if (key.startsWith("project:"))
|
|
190
|
+
s.projects.add(key.slice("project:".length));
|
|
191
|
+
else
|
|
192
|
+
s.repos.add(key.slice("repo:".length));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
/** Projects listed under their own id because no word of their slug is a name. */
|
|
196
|
+
const wholeProjects = new Set();
|
|
197
|
+
const termsOfProject = (projectId) => (termsOfItem.get(`project:${projectId}`) ?? []).filter((t) => stats.has(t));
|
|
198
|
+
// ---- standups.
|
|
199
|
+
const standups = input.standups?.standups ?? [];
|
|
200
|
+
const background = input.standups?.background ?? { utterances: 0, termUtterances: {}, transcripts: 0 };
|
|
201
|
+
const standupUtterances = standups.reduce((n, s) => n + s.utterances.length, 0);
|
|
202
|
+
/** The work term a word of talk counts for: itself, or the base of its -ing or -ed form (see inflectionBases). */
|
|
203
|
+
const workTermOf = (word) => (stats.has(word) ? word : inflectionBases(word).find((b) => stats.has(b)));
|
|
204
|
+
const workTermsOf = (text) => {
|
|
205
|
+
const out = new Set();
|
|
206
|
+
for (const word of textTerms(text)) {
|
|
207
|
+
const term = workTermOf(word);
|
|
208
|
+
if (term !== undefined)
|
|
209
|
+
out.add(term);
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
};
|
|
213
|
+
// Background counts per work term, inflected forms included, counted the same way as in standups.
|
|
214
|
+
const backgroundOf = new Map();
|
|
215
|
+
for (const [word, n] of Object.entries(background.termUtterances)) {
|
|
216
|
+
const term = workTermOf(word);
|
|
217
|
+
if (term !== undefined)
|
|
218
|
+
bump(backgroundOf, term, n);
|
|
219
|
+
}
|
|
220
|
+
for (const standup of standups) {
|
|
221
|
+
const ageDays = Math.max(0, (toMs - ms(standup.startedAt)) / DAY_MS);
|
|
222
|
+
const recency = Math.pow(0.5, ageDays / 7);
|
|
223
|
+
for (const [index, u] of standup.utterances.entries()) {
|
|
224
|
+
const cue = hasPriorityCue(u.text);
|
|
225
|
+
for (const term of workTermsOf(u.text)) {
|
|
226
|
+
const s = stats.get(term);
|
|
227
|
+
if (!s)
|
|
228
|
+
continue;
|
|
229
|
+
s.utterances += 1;
|
|
230
|
+
s.sentences.add(`${standup.id}#${index}`);
|
|
231
|
+
if (cue)
|
|
232
|
+
s.cueUtterances += 1;
|
|
233
|
+
s.standup += recency * (cue ? 2 : 1);
|
|
234
|
+
bump(s.speakers, u.speaker);
|
|
235
|
+
let per = s.perStandup.get(standup.id);
|
|
236
|
+
if (!per) {
|
|
237
|
+
per = { standup, count: 0, cues: 0, speakers: new Map(), sample: "", sampleCue: false };
|
|
238
|
+
s.perStandup.set(standup.id, per);
|
|
239
|
+
}
|
|
240
|
+
per.count += 1;
|
|
241
|
+
if (cue)
|
|
242
|
+
per.cues += 1;
|
|
243
|
+
bump(per.speakers, u.speaker);
|
|
244
|
+
if (per.sample === "" || (cue && !per.sampleCue)) {
|
|
245
|
+
per.sample = u.text;
|
|
246
|
+
per.sampleCue = cue;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
for (const s of stats.values()) {
|
|
252
|
+
s.standup = s.utterances < 2 ? 0 : s.standup * distinctiveness(s.utterances, standupUtterances, backgroundOf.get(s.term) ?? 0, background);
|
|
253
|
+
}
|
|
254
|
+
// ---- names and fragments (see the file header). A slug word stays a term only when the
|
|
255
|
+
// company uses it as a name. A project left with no term is listed under its own id.
|
|
256
|
+
const wholeNames = new Set();
|
|
257
|
+
for (const terms of termsOfItem.values())
|
|
258
|
+
if (terms.length === 1)
|
|
259
|
+
wholeNames.add(terms[0]);
|
|
260
|
+
for (const s of [...stats.values()]) {
|
|
261
|
+
const isName = wholeNames.has(s.term) || (termItems.get(s.term) ?? 0) >= 2 || s.standup > 0;
|
|
262
|
+
if (!isName)
|
|
263
|
+
stats.delete(s.term);
|
|
264
|
+
}
|
|
265
|
+
for (const [key, terms] of termsOfItem) {
|
|
266
|
+
if (!key.startsWith("project:") || terms.some((t) => stats.has(t)))
|
|
267
|
+
continue;
|
|
268
|
+
const projectId = key.slice("project:".length);
|
|
269
|
+
statsOf(projectId).projects.add(projectId);
|
|
270
|
+
wholeProjects.add(projectId);
|
|
271
|
+
termsOfItem.set(key, [...terms, projectId]);
|
|
272
|
+
}
|
|
273
|
+
// ---- Work Mesh.
|
|
274
|
+
const threadsByProject = new Map();
|
|
275
|
+
for (const t of threads) {
|
|
276
|
+
if (t.projectId === "" || ms(t.lastActivityAt) < fromMs)
|
|
277
|
+
continue;
|
|
278
|
+
const list = threadsByProject.get(t.projectId) ?? [];
|
|
279
|
+
list.push(t);
|
|
280
|
+
threadsByProject.set(t.projectId, list);
|
|
281
|
+
}
|
|
282
|
+
for (const projectId of activeProjects) {
|
|
283
|
+
const project = projectById.get(projectId);
|
|
284
|
+
const active = threadsByProject.get(projectId) ?? [];
|
|
285
|
+
const inProgress = (project?.stories ?? []).filter((st) => st.status === "in_progress");
|
|
286
|
+
const boardChanged = project !== undefined && ms(project.updatedAt) >= fromMs;
|
|
287
|
+
const activity = active.length + active.filter((t) => t.priority === "high").length + inProgress.length + (boardChanged ? 1 : 0);
|
|
288
|
+
if (activity === 0)
|
|
289
|
+
continue;
|
|
290
|
+
const newest = [...active].sort((a, b) => b.lastActivityAt.localeCompare(a.lastActivityAt))[0];
|
|
291
|
+
const owner = newest ? nameOf(newest.ownerUid) : (inProgress[0]?.assignee ?? "");
|
|
292
|
+
const evidence = {
|
|
293
|
+
source: "work-mesh",
|
|
294
|
+
date: isoDay(new Date(lastActivity.get(projectId) ?? 0).toISOString()),
|
|
295
|
+
owner,
|
|
296
|
+
ref: `work-mesh project ${projectId}`,
|
|
297
|
+
detail: `${active.length} thread${active.length === 1 ? "" : "s"} active in the window, ${inProgress.length} stor${inProgress.length === 1 ? "y" : "ies"} in progress`,
|
|
298
|
+
term: "",
|
|
299
|
+
};
|
|
300
|
+
for (const term of termsOfProject(projectId)) {
|
|
301
|
+
const s = statsOf(term);
|
|
302
|
+
s.mesh += activity;
|
|
303
|
+
s.meshEvidence.push({ ...evidence, term });
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// ---- sessions.
|
|
307
|
+
const projectOfSession = new Map();
|
|
308
|
+
for (const t of threads)
|
|
309
|
+
if (t.sessionId !== "" && t.projectId !== "")
|
|
310
|
+
projectOfSession.set(t.sessionId, t.projectId);
|
|
311
|
+
const sessionOwners = new Map();
|
|
312
|
+
for (const session of sessions) {
|
|
313
|
+
const bound = projectOfSession.get(session.sessionId) ?? "";
|
|
314
|
+
const terms = new Set([...slugTerms(shortRepo(session.repo)), ...slugTerms(session.branch), ...(bound === "" ? [] : slugTerms(bound))]);
|
|
315
|
+
for (const projectId of wholeProjects) {
|
|
316
|
+
if (bound === projectId || wholeWord(session.branch.toLowerCase(), projectId.toLowerCase()))
|
|
317
|
+
terms.add(projectId);
|
|
318
|
+
}
|
|
319
|
+
const weight = (session.ownerType === "agent" ? 0.5 : 1) * (session.status === "active" ? 2 : 1);
|
|
320
|
+
for (const term of terms) {
|
|
321
|
+
const known = stats.get(term);
|
|
322
|
+
if (!known)
|
|
323
|
+
continue;
|
|
324
|
+
known.sessionIds.add(session.sessionId);
|
|
325
|
+
const owners = sessionOwners.get(term) ?? new Map();
|
|
326
|
+
const seen = owners.get(session.owner);
|
|
327
|
+
if (!seen || weight > seen.weight || (weight === seen.weight && session.lastTurnAt > seen.session.lastTurnAt))
|
|
328
|
+
owners.set(session.owner, { session, weight });
|
|
329
|
+
sessionOwners.set(term, owners);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
for (const [term, owners] of sessionOwners) {
|
|
333
|
+
const s = statsOf(term);
|
|
334
|
+
for (const { session, weight } of owners.values()) {
|
|
335
|
+
s.session += weight;
|
|
336
|
+
const bound = projectOfSession.get(session.sessionId);
|
|
337
|
+
s.sessionEvidence.push({
|
|
338
|
+
source: "session",
|
|
339
|
+
date: isoDay(session.lastTurnAt),
|
|
340
|
+
owner: session.owner,
|
|
341
|
+
ref: `session ${session.sessionId}`,
|
|
342
|
+
detail: `${session.status} on ${session.repo || "no repo"}${session.branch ? `@${session.branch}` : ""}${bound ? `, bound to project ${bound}` : ""}`,
|
|
343
|
+
term,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// ---- ontology.
|
|
348
|
+
ontologyProjects.forEach((slug, index) => {
|
|
349
|
+
const share = (ontologyProjects.length - index) / ontologyProjects.length;
|
|
350
|
+
const entity = entities[slug];
|
|
351
|
+
const evidence = {
|
|
352
|
+
source: "ontology",
|
|
353
|
+
date: entity?.date || isoDay(input.now),
|
|
354
|
+
owner: entity?.owner ?? "",
|
|
355
|
+
ref: entity?.id || `ontology brief: ${slug}`,
|
|
356
|
+
detail: `number ${index + 1} of ${ontologyProjects.length} most recently active projects in the ontology brief${entity?.status ? `; status ${entity.status}` : ""}`,
|
|
357
|
+
term: "",
|
|
358
|
+
};
|
|
359
|
+
for (const term of termsOfProject(slug)) {
|
|
360
|
+
const s = statsOf(term);
|
|
361
|
+
if (share > s.ontology)
|
|
362
|
+
s.ontology = share;
|
|
363
|
+
s.ontologyEvidence.push({ ...evidence, term });
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
// ---- rank.
|
|
367
|
+
const max = { standup: 0, mesh: 0, session: 0, ontology: 0 };
|
|
368
|
+
for (const s of stats.values()) {
|
|
369
|
+
max.standup = Math.max(max.standup, s.standup);
|
|
370
|
+
max.mesh = Math.max(max.mesh, s.mesh);
|
|
371
|
+
max.session = Math.max(max.session, s.session);
|
|
372
|
+
max.ontology = Math.max(max.ontology, s.ontology);
|
|
373
|
+
}
|
|
374
|
+
const share = (v, m) => (m > 0 ? v / m : 0);
|
|
375
|
+
const weighted = (scores) => scores.standup * weights.standup + scores["work-mesh"] * weights["work-mesh"] + scores.session * weights.session + scores.ontology * weights.ontology;
|
|
376
|
+
const ranked = [];
|
|
377
|
+
for (const s of stats.values()) {
|
|
378
|
+
if (s.standup <= 0 && s.mesh <= 0)
|
|
379
|
+
continue;
|
|
380
|
+
const place = repoWords.has(s.term);
|
|
381
|
+
const scores = {
|
|
382
|
+
standup: share(s.standup, max.standup),
|
|
383
|
+
"work-mesh": share(s.mesh, max.mesh),
|
|
384
|
+
session: place ? 0 : share(s.session, max.session),
|
|
385
|
+
ontology: place ? 0 : share(s.ontology, max.ontology),
|
|
386
|
+
};
|
|
387
|
+
ranked.push({ s, scores, total: weighted(scores) });
|
|
388
|
+
}
|
|
389
|
+
const byScore = (a, b) => b.total - a.total || a.lead.localeCompare(b.lead);
|
|
390
|
+
ranked.sort((a, b) => byScore({ total: a.total, lead: a.s.term }, { total: b.total, lead: b.s.term }));
|
|
391
|
+
// ---- merge terms whose evidence overlaps into one priority (see mergeReason).
|
|
392
|
+
// Terms are taken strongest first. Each is compared with the lead term of every
|
|
393
|
+
// priority formed so far, never with terms already merged in or with the work they
|
|
394
|
+
// brought, so merges do not chain: if A overlaps B and B overlaps C, C does not join
|
|
395
|
+
// A through B.
|
|
396
|
+
const mergeEvidence = (s) => ({
|
|
397
|
+
work: new Set([...s.projects, ...[...s.repos].map((x) => `repo:${x}`), ...[...s.sessionIds].map((x) => `session:${x}`)]),
|
|
398
|
+
sentences: s.sentences,
|
|
399
|
+
});
|
|
400
|
+
const groups = [];
|
|
401
|
+
for (const r of ranked) {
|
|
402
|
+
const own = mergeEvidence(r.s);
|
|
403
|
+
let joined = false;
|
|
404
|
+
for (const group of groups) {
|
|
405
|
+
const why = mergeReason(group.leadEvidence, own);
|
|
406
|
+
if (!why)
|
|
407
|
+
continue;
|
|
408
|
+
group.members.push({ r, why: { term: r.s.term, ...why } });
|
|
409
|
+
joined = true;
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
if (!joined)
|
|
413
|
+
groups.push({ lead: r, leadEvidence: own, members: [] });
|
|
414
|
+
}
|
|
415
|
+
// A merged priority scores, per source, as its strongest member does: shared evidence is not counted twice.
|
|
416
|
+
const scored = groups
|
|
417
|
+
.map((group) => {
|
|
418
|
+
const all = [group.lead, ...group.members.map((m) => m.r)];
|
|
419
|
+
const scores = {
|
|
420
|
+
standup: Math.max(...all.map((r) => r.scores.standup)),
|
|
421
|
+
"work-mesh": Math.max(...all.map((r) => r.scores["work-mesh"])),
|
|
422
|
+
session: Math.max(...all.map((r) => r.scores.session)),
|
|
423
|
+
ontology: Math.max(...all.map((r) => r.scores.ontology)),
|
|
424
|
+
};
|
|
425
|
+
return { group, all, scores, total: weighted(scores), lead: group.lead.s.term };
|
|
426
|
+
})
|
|
427
|
+
.sort(byScore)
|
|
428
|
+
.slice(0, keep);
|
|
429
|
+
const byDate = (a, b) => b.date.localeCompare(a.date) || a.ref.localeCompare(b.ref);
|
|
430
|
+
/** One term's evidence, owner and work. */
|
|
431
|
+
const describe = (s) => {
|
|
432
|
+
const evidence = [];
|
|
433
|
+
const perStandup = [...s.perStandup.values()].sort((a, b) => b.standup.startedAt.localeCompare(a.standup.startedAt));
|
|
434
|
+
for (const per of perStandup.slice(0, 3)) {
|
|
435
|
+
evidence.push({
|
|
436
|
+
source: "standup",
|
|
437
|
+
date: per.standup.date,
|
|
438
|
+
owner: top(per.speakers) ?? "",
|
|
439
|
+
ref: per.standup.file,
|
|
440
|
+
detail: `"${s.term}" said in ${per.count} utterance${per.count === 1 ? "" : "s"} (${per.cues} with priority wording) of "${per.standup.title || "untitled meeting"}", e.g. "${clip(per.sample, 140)}"`,
|
|
441
|
+
term: s.term,
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
evidence.push(...[...s.meshEvidence].sort(byDate).slice(0, 3), ...[...s.sessionEvidence].sort(byDate).slice(0, 3), ...[...s.ontologyEvidence].sort(byDate).slice(0, 2));
|
|
445
|
+
const projectList = [...s.projects].sort((a, b) => (lastActivity.get(b) ?? 0) - (lastActivity.get(a) ?? 0) || a.localeCompare(b));
|
|
446
|
+
const ontologyOwner = projectList.map((p) => entities[p]).find((e) => e && e.owner !== "");
|
|
447
|
+
const meshOwner = [...s.meshEvidence].sort(byDate).find((e) => e.owner !== "");
|
|
448
|
+
const speaker = top(s.speakers);
|
|
449
|
+
let name = "unknown";
|
|
450
|
+
let basis = "no source names an owner";
|
|
451
|
+
if (ontologyOwner) {
|
|
452
|
+
name = ontologyOwner.owner;
|
|
453
|
+
basis = `ontology owned_by on ${ontologyOwner.id} (${ontologyOwner.ownerSource || "no source given"})`;
|
|
454
|
+
}
|
|
455
|
+
else if (meshOwner) {
|
|
456
|
+
name = meshOwner.owner;
|
|
457
|
+
basis = `owner of the latest thread on ${meshOwner.ref}`;
|
|
458
|
+
}
|
|
459
|
+
else if (speaker) {
|
|
460
|
+
name = speaker;
|
|
461
|
+
basis = "raised it most in the standups";
|
|
462
|
+
}
|
|
463
|
+
else if (s.sessionEvidence[0]) {
|
|
464
|
+
name = s.sessionEvidence[0].owner;
|
|
465
|
+
basis = `has an open session (${s.sessionEvidence[0].ref})`;
|
|
466
|
+
}
|
|
467
|
+
return { evidence, owner: { term: s.term, name, basis }, projects: projectList };
|
|
468
|
+
};
|
|
469
|
+
const priorities = scored.map((entry, index) => {
|
|
470
|
+
const parts = entry.all.map((r) => describe(r.s));
|
|
471
|
+
// Every member's evidence is kept. The same project, session or entity named by two members is listed once.
|
|
472
|
+
const evidence = [];
|
|
473
|
+
const seen = new Set();
|
|
474
|
+
for (const part of parts) {
|
|
475
|
+
for (const e of part.evidence) {
|
|
476
|
+
const key = e.source === "standup" ? `${e.source}\n${e.ref}\n${e.term}` : `${e.source}\n${e.ref}`;
|
|
477
|
+
if (seen.has(key))
|
|
478
|
+
continue;
|
|
479
|
+
seen.add(key);
|
|
480
|
+
evidence.push(e);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
const sources = ["standup", "work-mesh", "session", "ontology"].filter((k) => evidence.some((e) => e.source === k));
|
|
484
|
+
const projectList = [...new Set(parts.flatMap((p) => p.projects))].sort((a, b) => (lastActivity.get(b) ?? 0) - (lastActivity.get(a) ?? 0) || a.localeCompare(b));
|
|
485
|
+
const repos = new Set(entry.all.flatMap((r) => [...r.s.repos]));
|
|
486
|
+
for (const p of projectList) {
|
|
487
|
+
const repo = projectById.get(p)?.repos[0] || entities[p]?.repo || "";
|
|
488
|
+
if (repo !== "")
|
|
489
|
+
repos.add(shortRepo(repo));
|
|
490
|
+
}
|
|
491
|
+
const terms = entry.all.map((r) => r.s.term);
|
|
492
|
+
return {
|
|
493
|
+
id: entry.lead,
|
|
494
|
+
rank: index + 1,
|
|
495
|
+
tier: index < topCount ? "top" : "active",
|
|
496
|
+
score: round(entry.total),
|
|
497
|
+
sourceScores: { standup: round(entry.scores.standup), "work-mesh": round(entry.scores["work-mesh"]), session: round(entry.scores.session), ontology: round(entry.scores.ontology) },
|
|
498
|
+
terms,
|
|
499
|
+
alsoSaid: terms.slice(1).sort(),
|
|
500
|
+
names: terms.filter((t) => t === entry.lead || wholeNames.has(t)),
|
|
501
|
+
merged: entry.group.members.map((m) => m.why),
|
|
502
|
+
projects: projectList,
|
|
503
|
+
repos: [...repos].sort(),
|
|
504
|
+
owner: parts[0].owner.name,
|
|
505
|
+
ownerBasis: parts[0].owner.basis,
|
|
506
|
+
owners: parts.map((p) => p.owner),
|
|
507
|
+
date: evidence.map((e) => e.date).sort().at(-1) ?? isoDay(input.now),
|
|
508
|
+
sources,
|
|
509
|
+
evidence,
|
|
510
|
+
};
|
|
511
|
+
});
|
|
512
|
+
// ---- pull requests and work in flight.
|
|
513
|
+
const topPriorities = priorities.filter((p) => p.tier === "top");
|
|
514
|
+
const context = {
|
|
515
|
+
priorities: topPriorities,
|
|
516
|
+
sessions,
|
|
517
|
+
projectOfSession,
|
|
518
|
+
customers: input.ontology?.customers ?? [],
|
|
519
|
+
projectPaths: projectPaths(priorities, input.projectPlans ?? {}),
|
|
520
|
+
};
|
|
521
|
+
const pullRequests = (input.pullRequests ?? []).map((pr) => matchPullRequest(pr, context));
|
|
522
|
+
const priorityOfProject = (projectId) => topPriorities.find((p) => p.projects.includes(projectId))?.id ?? "";
|
|
523
|
+
const priorityOfText = (text) => {
|
|
524
|
+
const terms = new Set(slugTerms(text));
|
|
525
|
+
return topPriorities.find((p) => p.names.some((t) => terms.has(t)))?.id ?? "";
|
|
526
|
+
};
|
|
527
|
+
const workInFlight = listWorkInFlight({
|
|
528
|
+
sinceMs: fromMs,
|
|
529
|
+
sessions,
|
|
530
|
+
threads,
|
|
531
|
+
projects,
|
|
532
|
+
entities,
|
|
533
|
+
pullRequests: input.pullRequests,
|
|
534
|
+
names,
|
|
535
|
+
priorityOfProject,
|
|
536
|
+
priorityOfText,
|
|
537
|
+
});
|
|
538
|
+
const gaps = [...(input.standups?.gaps ?? []), ...(input.ontology?.gaps ?? [])];
|
|
539
|
+
if (input.standups && input.standups.skippedOtherCompany > 0) {
|
|
540
|
+
gaps.push(`${input.standups.skippedOtherCompany} transcript(s) in the meetings folder name another company and were not read.`);
|
|
541
|
+
}
|
|
542
|
+
return {
|
|
543
|
+
schema: PRIORITY_MAP_SCHEMA,
|
|
544
|
+
company: input.company,
|
|
545
|
+
builtAt: input.now,
|
|
546
|
+
window: input.window,
|
|
547
|
+
degraded: input.sources.some((s) => s.status === "down"),
|
|
548
|
+
priorities,
|
|
549
|
+
pullRequests,
|
|
550
|
+
workInFlight,
|
|
551
|
+
sources: input.sources,
|
|
552
|
+
gaps,
|
|
553
|
+
standupIds: standups.map((s) => s.id).sort(),
|
|
554
|
+
method: { weights, topCount },
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
/** The folders a listed path sits in, from two levels deep down ("crates/hook", "crates/hook/src"). */
|
|
558
|
+
function foldersOf(path) {
|
|
559
|
+
const parts = path.split("/");
|
|
560
|
+
const out = [];
|
|
561
|
+
for (let depth = 2; depth < parts.length; depth += 1)
|
|
562
|
+
out.push(parts.slice(0, depth).join("/"));
|
|
563
|
+
return out;
|
|
564
|
+
}
|
|
565
|
+
/** A folder is one of a plan's own when at least this share of the plan's listed files, and at least PLAN_FOLDER_MIN_FILES, are under it. */
|
|
566
|
+
export const PLAN_FOLDER_SHARE = 0.1;
|
|
567
|
+
export const PLAN_FOLDER_MIN_FILES = 3;
|
|
568
|
+
/**
|
|
569
|
+
* What one plan claims: every file it lists, and the folders its listed files
|
|
570
|
+
* concentrate in, each with how many of the plan's files it holds. A folder
|
|
571
|
+
* that holds only a file or two of a long plan (the repo's shared utilities
|
|
572
|
+
* folder, say) is not the project's folder.
|
|
573
|
+
*/
|
|
574
|
+
function planClaims(plan) {
|
|
575
|
+
const perFolder = new Map();
|
|
576
|
+
for (const file of plan.files)
|
|
577
|
+
for (const folder of foldersOf(file))
|
|
578
|
+
bump(perFolder, folder);
|
|
579
|
+
const out = new Map();
|
|
580
|
+
for (const file of plan.files)
|
|
581
|
+
out.set(file, 1);
|
|
582
|
+
for (const [folder, n] of perFolder)
|
|
583
|
+
if (n >= PLAN_FOLDER_MIN_FILES && n / plan.files.length >= PLAN_FOLDER_SHARE)
|
|
584
|
+
out.set(folder, n);
|
|
585
|
+
return out;
|
|
586
|
+
}
|
|
587
|
+
/** A path listed by more than one priority counts for the one whose plans list at least this many times as many files under it as any other. */
|
|
588
|
+
export const PLAN_CLAIM_LEAD = 2;
|
|
589
|
+
/**
|
|
590
|
+
* Turn project plans into path evidence per priority. A project's plan lists
|
|
591
|
+
* the files its stories change. Those files, and the folders (two or more
|
|
592
|
+
* levels deep) they concentrate in (see planClaims), count for a priority
|
|
593
|
+
* when no other priority's projects claim them, or when its plans list at
|
|
594
|
+
* least PLAN_CLAIM_LEAD (twice) as many files under the path as any other
|
|
595
|
+
* priority's do (a project held by two priorities counts for the higher
|
|
596
|
+
* ranked one). A folder that several priorities work in about equally, such
|
|
597
|
+
* as a repo's main source folder, says nothing about which one a change
|
|
598
|
+
* belongs to; a single file listed by two priorities counts for neither.
|
|
599
|
+
*/
|
|
600
|
+
export function projectPaths(priorities, plans) {
|
|
601
|
+
// claim key "<repo>\n<path>" -> priority ids that list it, with the first project of each and the files listed under it.
|
|
602
|
+
const claimedBy = new Map();
|
|
603
|
+
const out = new Map();
|
|
604
|
+
// A project that two priorities hold counts for the higher ranked one, so its own folders do not cancel out.
|
|
605
|
+
const taken = new Set();
|
|
606
|
+
for (const priority of [...priorities].sort((a, b) => a.rank - b.rank)) {
|
|
607
|
+
const paths = { byRepo: new Map(), branches: new Map() };
|
|
608
|
+
out.set(priority.id, paths);
|
|
609
|
+
for (const projectId of priority.projects) {
|
|
610
|
+
const plan = plans[projectId];
|
|
611
|
+
if (!plan || taken.has(projectId))
|
|
612
|
+
continue;
|
|
613
|
+
taken.add(projectId);
|
|
614
|
+
if (plan.branch !== "" && !DEFAULT_BRANCH_NAMES.has(plan.branch))
|
|
615
|
+
paths.branches.set(plan.branch.toLowerCase(), projectId);
|
|
616
|
+
if (plan.repo === "")
|
|
617
|
+
continue;
|
|
618
|
+
for (const [claim, files] of planClaims(plan)) {
|
|
619
|
+
const key = `${plan.repo}\n${claim}`;
|
|
620
|
+
const owners = claimedBy.get(key) ?? new Map();
|
|
621
|
+
const seen = owners.get(priority.id);
|
|
622
|
+
if (seen)
|
|
623
|
+
seen.files += files;
|
|
624
|
+
else
|
|
625
|
+
owners.set(priority.id, { project: projectId, files });
|
|
626
|
+
claimedBy.set(key, owners);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
for (const [key, owners] of claimedBy) {
|
|
631
|
+
const ordered = [...owners.entries()].sort((a, b) => b[1].files - a[1].files);
|
|
632
|
+
const [priorityId, { project: projectId, files: lead }] = ordered[0];
|
|
633
|
+
if (ordered.length > 1 && lead < PLAN_CLAIM_LEAD * ordered[1][1].files)
|
|
634
|
+
continue;
|
|
635
|
+
const [repo, claim] = key.split("\n");
|
|
636
|
+
const paths = out.get(priorityId);
|
|
637
|
+
if (!paths)
|
|
638
|
+
continue;
|
|
639
|
+
const entry = paths.byRepo.get(repo) ?? { folders: [], files: new Set(), project: new Map() };
|
|
640
|
+
entry.files.add(claim);
|
|
641
|
+
entry.folders.push(claim);
|
|
642
|
+
entry.project.set(claim, projectId);
|
|
643
|
+
paths.byRepo.set(repo, entry);
|
|
644
|
+
}
|
|
645
|
+
return out;
|
|
646
|
+
}
|
|
647
|
+
const DEFAULT_BRANCH_NAMES = new Set(["main", "master", "develop", "trunk"]);
|
|
648
|
+
/** The listed folder or file a changed path falls under, or "". */
|
|
649
|
+
function underListed(path, entry) {
|
|
650
|
+
if (entry.files.has(path))
|
|
651
|
+
return path;
|
|
652
|
+
let best = "";
|
|
653
|
+
for (const folder of entry.folders) {
|
|
654
|
+
if (path.startsWith(`${folder}/`) && folder.length > best.length)
|
|
655
|
+
best = folder;
|
|
656
|
+
}
|
|
657
|
+
return best;
|
|
658
|
+
}
|
|
659
|
+
/** Conventional-commit types that mark a fix. */
|
|
660
|
+
const FIX_TYPES = new Set(["fix", "hotfix", "bugfix", "revert"]);
|
|
661
|
+
/** A reference to one feedback record, as HQ writes its ids. */
|
|
662
|
+
const FEEDBACK_RECORD = /\bfeedback_[0-9a-f]{6,}\b/i;
|
|
663
|
+
function wholeWord(haystack, needle) {
|
|
664
|
+
if (needle.length < 4)
|
|
665
|
+
return false;
|
|
666
|
+
for (let at = haystack.indexOf(needle); at >= 0; at = haystack.indexOf(needle, at + 1)) {
|
|
667
|
+
const before = at === 0 ? "" : haystack[at - 1];
|
|
668
|
+
const after = haystack[at + needle.length] ?? "";
|
|
669
|
+
if (!/[a-z0-9]/.test(before) && !/[a-z0-9]/.test(after))
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
return false;
|
|
673
|
+
}
|
|
674
|
+
/** A story id as HQ boards write them: "US-030", "OCG-2". */
|
|
675
|
+
const STORY_ID = /\b[A-Z]{2,6}-\d{1,4}\b/;
|
|
676
|
+
/**
|
|
677
|
+
* True when a description refers to the project as tracked work: a line
|
|
678
|
+
* names the project id together with a story id ("usage-next US-030"), or the
|
|
679
|
+
* text gives the project's folder ("projects/<id>/"). A bare mention in prose
|
|
680
|
+
* or inside a file path is not a reference: project ids are often repo names.
|
|
681
|
+
*/
|
|
682
|
+
export function refersToProject(description, projectId) {
|
|
683
|
+
const id = projectId.toLowerCase();
|
|
684
|
+
const text = description.toLowerCase();
|
|
685
|
+
if (text.includes(`projects/${id}/`))
|
|
686
|
+
return true;
|
|
687
|
+
return description.split(/\r?\n/).some((line) => STORY_ID.test(line) && wholeWord(line.toLowerCase(), id));
|
|
688
|
+
}
|
|
689
|
+
/** The type and scopes of a conventional-commit title ("fix(ci, sync)!: ..."), or null when the title is not one. */
|
|
690
|
+
export function conventionalTitle(title) {
|
|
691
|
+
const m = /^([a-z]+)(?:\(([^)]*)\))?!?:\s/i.exec(title.trim());
|
|
692
|
+
if (!m)
|
|
693
|
+
return null;
|
|
694
|
+
return {
|
|
695
|
+
type: m[1].toLowerCase(),
|
|
696
|
+
scopes: (m[2] ?? "")
|
|
697
|
+
.toLowerCase()
|
|
698
|
+
.split(/[\s,/]+/)
|
|
699
|
+
.filter((x) => x !== ""),
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
/** The type prefix of a branch ("fix/…", "ci/…"), or "". */
|
|
703
|
+
function branchType(branch) {
|
|
704
|
+
return /^([a-z]+)\//.exec(branch.toLowerCase())?.[1] ?? "";
|
|
705
|
+
}
|
|
706
|
+
/** A file that is part of CI itself: under .github/workflows or .github/actions, or inside a folder named ci. */
|
|
707
|
+
export function isCiPath(path) {
|
|
708
|
+
const parts = path.toLowerCase().split("/");
|
|
709
|
+
if (parts[0] === ".github" && (parts[1] === "workflows" || parts[1] === "actions"))
|
|
710
|
+
return true;
|
|
711
|
+
return parts.slice(0, -1).includes("ci");
|
|
712
|
+
}
|
|
713
|
+
/** How strong a priority match is. A stronger kind always wins over a weaker one. */
|
|
714
|
+
const STRENGTH = { strong: 4, scope: 3, name: 2, paths: 1 };
|
|
715
|
+
/**
|
|
716
|
+
* Match one open pull request. Order: a company priority first, then a
|
|
717
|
+
* customer-facing fix, then a change to CI itself; anything else is routine.
|
|
718
|
+
*
|
|
719
|
+
* Priority evidence, strongest first:
|
|
720
|
+
* - strong: the branch or title carries the id of one of the priority's
|
|
721
|
+
* projects (a multi-word id, matched as a whole), the description refers to
|
|
722
|
+
* one (see refersToProject), or a session on the pull request's branch is
|
|
723
|
+
* bound to one of its projects;
|
|
724
|
+
* - scope: the title's conventional-commit type or scope is the priority's name;
|
|
725
|
+
* - name: the priority's name is in both the branch and the title;
|
|
726
|
+
* - paths: at least half of the changed files are in folders or files that
|
|
727
|
+
* only this priority's projects list in their plans, in the plan's repo.
|
|
728
|
+
* This is the weakest kind, so reading the changed paths never changes a
|
|
729
|
+
* match the cheaper evidence already made; the refresh reads paths only for
|
|
730
|
+
* pull requests nothing else matched.
|
|
731
|
+
* A branch that a project's plan names (or a branch under it) is strong
|
|
732
|
+
* evidence as well.
|
|
733
|
+
* The strongest kind wins. Within a kind, a priority whose own name is part of
|
|
734
|
+
* the project id found wins over one that holds the project through a merged
|
|
735
|
+
* term; then more evidence wins, then the higher ranked priority.
|
|
736
|
+
*
|
|
737
|
+
* A customer-facing fix is a fix (by conventional-commit type, branch prefix
|
|
738
|
+
* or label) with a customer label, the name of a customer the ontology lists,
|
|
739
|
+
* or a reference to a feedback record. A CI change has the conventional-commit
|
|
740
|
+
* type or scope "ci", a ci/ branch, the label "ci", or changes mostly CI files
|
|
741
|
+
* when the changed paths are given. Words in a title are not evidence: a pull
|
|
742
|
+
* request with none of the above is routine.
|
|
743
|
+
*
|
|
744
|
+
* The "ci-speedup" group holds every change to CI itself. Nothing in a pull
|
|
745
|
+
* request's metadata says whether a CI change makes CI faster, so the map does
|
|
746
|
+
* not claim that it does.
|
|
747
|
+
*/
|
|
748
|
+
export function matchPullRequest(pr, ctx) {
|
|
749
|
+
const base = {
|
|
750
|
+
repo: pr.repo,
|
|
751
|
+
number: pr.number,
|
|
752
|
+
title: pr.title,
|
|
753
|
+
branch: pr.branch,
|
|
754
|
+
author: pr.author,
|
|
755
|
+
draft: pr.draft,
|
|
756
|
+
url: pr.url,
|
|
757
|
+
headSha: pr.headSha ?? "",
|
|
758
|
+
...(pr.paths ? { paths: pr.paths } : {}),
|
|
759
|
+
};
|
|
760
|
+
const branch = pr.branch.toLowerCase();
|
|
761
|
+
const title = pr.title.toLowerCase();
|
|
762
|
+
const branchTerms = new Set(slugTerms(pr.branch));
|
|
763
|
+
const titleTerms = textTerms(pr.title);
|
|
764
|
+
const conventional = conventionalTitle(pr.title);
|
|
765
|
+
const scopeTerms = new Set(conventional ? [conventional.type, ...conventional.scopes].flatMap((x) => [x, ...slugTerms(x)]) : []);
|
|
766
|
+
const repo = shortRepo(pr.repo);
|
|
767
|
+
const onBranch = ctx.sessions.filter((s) => shortRepo(s.repo) === repo && s.branch === pr.branch && pr.branch !== "");
|
|
768
|
+
const counted = pr.paths ?? [];
|
|
769
|
+
let best = null;
|
|
770
|
+
for (const priority of ctx.priorities) {
|
|
771
|
+
const evidence = [];
|
|
772
|
+
let strength = 0;
|
|
773
|
+
// Strong evidence names the tracked work itself. A one-word project id is a name, not an id, and is handled below.
|
|
774
|
+
const ids = priority.projects.filter((p) => p.includes("-"));
|
|
775
|
+
const names = priority.names;
|
|
776
|
+
const inBranch = ids.find((p) => wholeWord(branch, p.toLowerCase()));
|
|
777
|
+
const inTitle = ids.find((p) => wholeWord(title, p.toLowerCase()));
|
|
778
|
+
const inBody = ids.find((p) => refersToProject(pr.body, p));
|
|
779
|
+
if (inBranch)
|
|
780
|
+
evidence.push({ kind: "branch", detail: `branch ${pr.branch} carries project ${inBranch}` });
|
|
781
|
+
if (inTitle)
|
|
782
|
+
evidence.push({ kind: "title", detail: `title names project ${inTitle}` });
|
|
783
|
+
if (inBody)
|
|
784
|
+
evidence.push({ kind: "work-mesh-link", detail: `description refers to Work Mesh project ${inBody}` });
|
|
785
|
+
for (const s of onBranch) {
|
|
786
|
+
const bound = ctx.projectOfSession.get(s.sessionId) ?? "";
|
|
787
|
+
if (bound !== "" && priority.projects.includes(bound)) {
|
|
788
|
+
evidence.push({ kind: "session", detail: `session ${s.sessionId} (${s.owner}) is on this branch and bound to project ${bound}` });
|
|
789
|
+
break;
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
const planned = ctx.projectPaths?.get(priority.id);
|
|
793
|
+
if (planned && !inBranch) {
|
|
794
|
+
for (const [planBranch, projectId] of planned.branches) {
|
|
795
|
+
if (branch === planBranch || branch.startsWith(`${planBranch}-`) || branch.startsWith(`${planBranch}/`)) {
|
|
796
|
+
evidence.push({ kind: "branch", detail: `branch ${pr.branch} is the branch project ${projectId} names in its plan` });
|
|
797
|
+
break;
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
if (evidence.length > 0)
|
|
802
|
+
strength = STRENGTH.strong;
|
|
803
|
+
const scoped = names.find((t) => scopeTerms.has(t));
|
|
804
|
+
if (scoped) {
|
|
805
|
+
evidence.push({ kind: "title", detail: `title has the conventional-commit type or scope "${scoped}"` });
|
|
806
|
+
strength = Math.max(strength, STRENGTH.scope);
|
|
807
|
+
}
|
|
808
|
+
const named = names.find((t) => branchTerms.has(t) && titleTerms.has(t));
|
|
809
|
+
if (named) {
|
|
810
|
+
if (!inBranch)
|
|
811
|
+
evidence.push({ kind: "branch", detail: `branch ${pr.branch} names "${named}"` });
|
|
812
|
+
if (!inTitle && !scoped)
|
|
813
|
+
evidence.push({ kind: "title", detail: `title names "${named}"` });
|
|
814
|
+
strength = Math.max(strength, STRENGTH.name);
|
|
815
|
+
}
|
|
816
|
+
const listed = planned?.byRepo.get(repo);
|
|
817
|
+
if (listed && counted.length > 0) {
|
|
818
|
+
const hits = counted.map((path) => underListed(path, listed)).filter((hit) => hit !== "");
|
|
819
|
+
if (hits.length * 2 >= counted.length) {
|
|
820
|
+
const counts = new Map();
|
|
821
|
+
for (const hit of hits)
|
|
822
|
+
bump(counts, hit);
|
|
823
|
+
const where = top(counts) ?? hits[0];
|
|
824
|
+
evidence.push({
|
|
825
|
+
kind: "paths",
|
|
826
|
+
detail: `${hits.length} of ${counted.length} changed files are under paths only this priority's projects list (most under ${where}, listed by project ${listed.project.get(where) ?? ""})`,
|
|
827
|
+
});
|
|
828
|
+
strength = Math.max(strength, STRENGTH.paths);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (strength === 0)
|
|
832
|
+
continue;
|
|
833
|
+
const direct = [inBranch, inTitle, inBody].some((p) => p !== undefined && (p === priority.id || slugTerms(p).includes(priority.id)));
|
|
834
|
+
const better = !best ||
|
|
835
|
+
strength > best.strength ||
|
|
836
|
+
(strength === best.strength && direct && !best.direct) ||
|
|
837
|
+
(strength === best.strength && direct === best.direct && evidence.length > best.evidence.length);
|
|
838
|
+
if (better)
|
|
839
|
+
best = { priority, evidence, strength, direct };
|
|
840
|
+
}
|
|
841
|
+
if (best) {
|
|
842
|
+
const session = onBranch[0];
|
|
843
|
+
if (session && !best.evidence.some((e) => e.kind === "session")) {
|
|
844
|
+
best.evidence.push({ kind: "session", detail: `session ${session.sessionId} (${session.owner}) is on this branch` });
|
|
845
|
+
}
|
|
846
|
+
return { ...base, category: "priority", priorityId: best.priority.id, evidence: best.evidence };
|
|
847
|
+
}
|
|
848
|
+
const labelTerms = new Map(pr.labels.map((l) => [l, new Set(slugTerms(l))]));
|
|
849
|
+
const fixEvidence = [];
|
|
850
|
+
const fixLabel = pr.labels.find((l) => /^(bug|hotfix)$/i.test(l));
|
|
851
|
+
const isFix = (conventional !== null && FIX_TYPES.has(conventional.type)) || FIX_TYPES.has(branchType(pr.branch)) || fixLabel !== undefined;
|
|
852
|
+
if (isFix) {
|
|
853
|
+
const label = pr.labels.find((l) => {
|
|
854
|
+
const terms = labelTerms.get(l);
|
|
855
|
+
return /^(sev-?\d|p[01])$/i.test(l) || (terms !== undefined && (terms.has("customer") || terms.has("support") || terms.has("incident")));
|
|
856
|
+
});
|
|
857
|
+
if (label)
|
|
858
|
+
fixEvidence.push({ kind: "label", detail: `a fix with the label ${label}` });
|
|
859
|
+
const customer = ctx.customers.find((c) => c.length >= 4 && (wholeWord(title, c.toLowerCase()) || wholeWord(pr.body.toLowerCase(), c.toLowerCase())));
|
|
860
|
+
if (customer)
|
|
861
|
+
fixEvidence.push({ kind: "reference", detail: `a fix that names customer ${customer}, whom the ontology lists` });
|
|
862
|
+
const record = FEEDBACK_RECORD.exec(pr.title) ?? FEEDBACK_RECORD.exec(pr.body);
|
|
863
|
+
if (record)
|
|
864
|
+
fixEvidence.push({ kind: "reference", detail: `a fix that cites feedback record ${record[0]}` });
|
|
865
|
+
}
|
|
866
|
+
if (fixEvidence.length > 0)
|
|
867
|
+
return { ...base, category: "customer-fix", priorityId: "", evidence: fixEvidence };
|
|
868
|
+
const ciEvidence = [];
|
|
869
|
+
if (branchType(pr.branch) === "ci")
|
|
870
|
+
ciEvidence.push({ kind: "branch", detail: `branch ${pr.branch} is a ci/ branch` });
|
|
871
|
+
if (conventional && (conventional.type === "ci" || conventional.scopes.includes("ci"))) {
|
|
872
|
+
ciEvidence.push({ kind: "title", detail: `title has the conventional-commit ${conventional.type === "ci" ? "type" : "scope"} "ci"` });
|
|
873
|
+
}
|
|
874
|
+
// The label "ci", alone or under a key ("area: ci"). A label such as "ci-windows" asks CI to do something; it does not say the change is to CI.
|
|
875
|
+
const ciLabel = pr.labels.find((l) => /^(?:[a-z-]+\s*[:/]\s*)?ci$/i.test(l.trim()));
|
|
876
|
+
if (ciLabel)
|
|
877
|
+
ciEvidence.push({ kind: "label", detail: `label ${ciLabel}` });
|
|
878
|
+
const paths = counted;
|
|
879
|
+
const ciPaths = paths.filter(isCiPath);
|
|
880
|
+
if (paths.length > 0 && ciPaths.length * 2 > paths.length) {
|
|
881
|
+
ciEvidence.push({ kind: "paths", detail: `${ciPaths.length} of ${paths.length} changed files are CI files (e.g. ${ciPaths[0]})` });
|
|
882
|
+
}
|
|
883
|
+
if (ciEvidence.length > 0)
|
|
884
|
+
return { ...base, category: "ci-speedup", priorityId: "", evidence: ciEvidence };
|
|
885
|
+
return {
|
|
886
|
+
...base,
|
|
887
|
+
category: "routine",
|
|
888
|
+
priorityId: "",
|
|
889
|
+
evidence: [{ kind: "title", detail: "no project id, bound session, conventional-commit scope, label, reference or changed path ties it to a priority, a customer or CI" }],
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
// ------------------------------------------------------------------ rendering
|
|
893
|
+
const CATEGORY_TITLE = {
|
|
894
|
+
priority: "Matched to a priority",
|
|
895
|
+
"customer-fix": "Customer-facing fixes",
|
|
896
|
+
"ci-speedup": "Changes to CI itself",
|
|
897
|
+
routine: "Routine",
|
|
898
|
+
};
|
|
899
|
+
/** The map in plain language, with the source of every line that states a fact. */
|
|
900
|
+
export function renderPriorityMap(map, opts = {}) {
|
|
901
|
+
const prLimit = opts.pullRequestLimit ?? 15;
|
|
902
|
+
const workLimit = opts.workLimit ?? 8;
|
|
903
|
+
const lines = [];
|
|
904
|
+
lines.push(`Priority map for ${map.company}`);
|
|
905
|
+
lines.push(`Built ${map.builtAt} from standups, Work Mesh, open sessions and the ontology, ${isoDay(map.window.from)} to ${isoDay(map.window.to)}.`);
|
|
906
|
+
if (map.degraded)
|
|
907
|
+
lines.push("Built while a source was down; see Sources.");
|
|
908
|
+
lines.push("");
|
|
909
|
+
lines.push("Priorities");
|
|
910
|
+
if (map.priorities.length === 0)
|
|
911
|
+
lines.push(" None found.");
|
|
912
|
+
for (const p of map.priorities) {
|
|
913
|
+
const work = p.projects.length > 0 ? `projects ${p.projects.slice(0, 4).join(", ")}${p.projects.length > 4 ? ` and ${p.projects.length - 4} more` : ""}` : p.repos.length > 0 ? `repos ${p.repos.join(", ")}` : "no tracked project";
|
|
914
|
+
lines.push(`${p.rank}. ${p.id}${p.tier === "top" ? "" : " (active, not a top priority)"}: ${work}`);
|
|
915
|
+
lines.push(` Owner: ${p.owner} (${p.ownerBasis}). Latest evidence: ${p.date}. Score ${p.score}.`);
|
|
916
|
+
for (const m of p.merged) {
|
|
917
|
+
const what = m.rule === "shared-work" ? "projects, repos or sessions" : "standup utterances";
|
|
918
|
+
const other = p.owners.find((o) => o.term === m.term);
|
|
919
|
+
lines.push(` Includes "${m.term}": shares ${m.shared} ${what} with "${p.id}" (${Math.round(m.share * 100)}% of the smaller set).${other && other.name !== p.owner ? ` Its owner: ${other.name} (${other.basis}).` : ""}`);
|
|
920
|
+
}
|
|
921
|
+
for (const e of p.evidence) {
|
|
922
|
+
lines.push(` - ${e.source}, ${e.date}${e.owner ? `, ${e.owner}` : ""}: ${e.detail} [${e.ref}]`);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
lines.push("");
|
|
926
|
+
lines.push(`Open pull requests (${map.pullRequests.length})`);
|
|
927
|
+
for (const category of ["priority", "customer-fix", "ci-speedup", "routine"]) {
|
|
928
|
+
const group = map.pullRequests.filter((pr) => pr.category === category);
|
|
929
|
+
lines.push(` ${CATEGORY_TITLE[category]}: ${group.length}`);
|
|
930
|
+
for (const pr of group.slice(0, prLimit)) {
|
|
931
|
+
const why = pr.evidence.map((e) => `${e.kind}: ${e.detail}`).join("; ");
|
|
932
|
+
lines.push(` ${pr.repo}#${pr.number}${pr.draft ? " (draft)" : ""}${pr.priorityId ? ` -> ${pr.priorityId}` : ""}: ${clip(pr.title, 90)}`);
|
|
933
|
+
if (category !== "routine")
|
|
934
|
+
lines.push(` Evidence: ${why}`);
|
|
935
|
+
}
|
|
936
|
+
if (group.length > prLimit)
|
|
937
|
+
lines.push(` and ${group.length - prLimit} more.`);
|
|
938
|
+
}
|
|
939
|
+
lines.push("");
|
|
940
|
+
lines.push("Work in flight with no pull request yet");
|
|
941
|
+
if (map.workInFlight.length === 0)
|
|
942
|
+
lines.push(" None found.");
|
|
943
|
+
for (const repo of map.workInFlight) {
|
|
944
|
+
lines.push(` ${repo.repo}: ${repo.count} (${repo.priorityCount} on a top priority)`);
|
|
945
|
+
for (const item of repo.items.slice(0, workLimit)) {
|
|
946
|
+
const what = [item.project && `project ${item.project}`, item.branch && `branch ${item.branch}`].filter(Boolean).join(", ");
|
|
947
|
+
lines.push(` ${item.kind} ${item.ref}, ${item.owner || "no owner"}${what ? `, ${what}` : ""}, last active ${isoDay(item.lastActivityAt)}${item.covers.length > 0 ? `, same work as ${item.covers.join(", ")}` : ""}${item.priorityId ? ` -> ${item.priorityId}` : ""}`);
|
|
948
|
+
}
|
|
949
|
+
if (repo.items.length > workLimit)
|
|
950
|
+
lines.push(` and ${repo.items.length - workLimit} more.`);
|
|
951
|
+
}
|
|
952
|
+
lines.push("");
|
|
953
|
+
lines.push("Sources");
|
|
954
|
+
for (const s of map.sources)
|
|
955
|
+
lines.push(` ${s.source}: ${s.status}, read ${s.readAt}. ${s.detail}`);
|
|
956
|
+
if (map.gaps.length > 0) {
|
|
957
|
+
lines.push("");
|
|
958
|
+
lines.push("Gaps");
|
|
959
|
+
for (const g of map.gaps)
|
|
960
|
+
lines.push(` - ${g}`);
|
|
961
|
+
}
|
|
962
|
+
return `${lines.join("\n")}\n`;
|
|
963
|
+
}
|
|
964
|
+
//# sourceMappingURL=priorities.js.map
|