@indigoai-us/hq-cli 5.345.252 → 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 +73 -0
- package/contracts/host-canary-release.json +11 -5
- package/dist/command-catalog.generated.d.ts +209 -0
- package/dist/command-catalog.generated.js +257 -0
- package/dist/command-registration-plan.d.ts +6 -0
- package/dist/command-registration-plan.js +1 -0
- package/dist/commands/ci-intake.d.ts +32 -0
- package/dist/commands/ci-intake.js +294 -0
- package/dist/commands/ci-metrics.d.ts +8 -0
- package/dist/commands/ci-metrics.js +55 -0
- package/dist/commands/ci-priorities.d.ts +56 -0
- package/dist/commands/ci-priorities.js +144 -0
- package/dist/commands/ci.d.ts +13 -0
- package/dist/commands/ci.js +11 -0
- package/dist/commands/cloud.d.ts +11 -0
- package/dist/commands/cloud.js +76 -0
- package/dist/commands/files.d.ts +62 -0
- package/dist/commands/files.js +249 -8
- package/dist/lib/bot/fleet-cron.d.ts +15 -0
- package/dist/lib/bot/fleet-cron.js +119 -20
- package/dist/lib/daemon/run.js +4 -3
- package/dist/lib/daemon/verified-jq.d.ts +6 -0
- package/dist/lib/daemon/verified-jq.js +17 -5
- package/dist/lib/delivery/migrations.d.ts +32 -1
- package/dist/lib/delivery/migrations.js +69 -8
- package/dist/lib/hook-engine/adapter-core-pin.d.ts +2 -1
- package/dist/lib/hook-engine/adapter-core-pin.js +2 -1
- package/dist/lib/hook-engine/coverage.d.ts +15 -0
- package/dist/lib/hook-engine/coverage.js +62 -1
- 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/cost.d.ts +72 -0
- package/dist/lib/smart-ci/cost.js +120 -0
- package/dist/lib/smart-ci/github.d.ts +112 -0
- package/dist/lib/smart-ci/github.js +267 -0
- package/dist/lib/smart-ci/intake.d.ts +288 -0
- package/dist/lib/smart-ci/intake.js +1078 -0
- package/dist/lib/smart-ci/ledger.d.ts +218 -0
- package/dist/lib/smart-ci/ledger.js +527 -0
- package/dist/lib/smart-ci/metrics.d.ts +137 -0
- package/dist/lib/smart-ci/metrics.js +249 -0
- 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/records.d.ts +265 -0
- package/dist/lib/smart-ci/records.js +281 -0
- package/dist/lib/smart-ci/reducer.d.ts +67 -0
- package/dist/lib/smart-ci/reducer.js +261 -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/lib/sync-core/engine-holds.d.ts +14 -0
- package/dist/lib/sync-core/engine-holds.js +78 -11
- package/dist/lib/sync-core/hand-back.d.ts +1 -0
- package/dist/lib/sync-core/hand-back.js +7 -2
- package/dist/lib/sync-core/reconcile.js +10 -2
- package/dist/utils/host-registration.d.ts +1 -0
- package/dist/utils/host-registration.js +1 -1
- package/package.json +9 -7
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Text helpers for the Smart CI priority map (smart-ci US-002).
|
|
3
|
+
*
|
|
4
|
+
* Nothing here names a company, a project or a topic. The priority map gets
|
|
5
|
+
* its topic vocabulary from the company's own work (Work Mesh project ids,
|
|
6
|
+
* ontology project names, session repos); these helpers only split text into
|
|
7
|
+
* comparable terms and spot generic priority wording.
|
|
8
|
+
*/
|
|
9
|
+
/** Common English words that carry no topic. Slugs often contain them ("on", "new", "fix"). */
|
|
10
|
+
const STOPWORDS = new Set(("a an and are as at be but by for from had has have he her his i if in into is it its me my no not of on or our " +
|
|
11
|
+
"she so than that the their them then there these they this to up us was we were what when which who will with " +
|
|
12
|
+
"you your all any can do does did done get got go going just like make more most much new now off one only out " +
|
|
13
|
+
"over own same some such too very via yes also about after again before being both each few how other should " +
|
|
14
|
+
"use used using add added fix fixes fixed update updates updated move moved test v1 v2 v3 pr prs work working").split(" "));
|
|
15
|
+
/** Lower-case word tokens. Keeps inner dots, plus and hash ("node.js", "c++"); drops punctuation. */
|
|
16
|
+
export function tokenize(text) {
|
|
17
|
+
return text.toLowerCase().match(/[a-z][a-z0-9+#.-]*[a-z0-9]|[a-z]/g) ?? [];
|
|
18
|
+
}
|
|
19
|
+
/** Fold a plural onto its singular ("runners" and "runner" are one term). */
|
|
20
|
+
export function stem(word) {
|
|
21
|
+
if (word.length > 3 && word.endsWith("s") && !word.endsWith("ss") && !word.endsWith("us") && !word.endsWith("is")) {
|
|
22
|
+
return word.slice(0, -1);
|
|
23
|
+
}
|
|
24
|
+
return word;
|
|
25
|
+
}
|
|
26
|
+
/** True for a term that can name a topic: not a stopword, not a number, not a hash. */
|
|
27
|
+
export function isTopicTerm(term) {
|
|
28
|
+
if (term.length < 2 || STOPWORDS.has(term))
|
|
29
|
+
return false;
|
|
30
|
+
if (/^\d+$/.test(term))
|
|
31
|
+
return false;
|
|
32
|
+
// Slug suffixes such as "8c8711986479": long, hex only, with a digit.
|
|
33
|
+
if (term.length >= 8 && /^[0-9a-f]+$/.test(term) && /\d/.test(term))
|
|
34
|
+
return false;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
/** Topic terms of a slug, repo or branch name, split on anything that is not a letter or digit. */
|
|
38
|
+
export function slugTerms(slug) {
|
|
39
|
+
const out = new Set();
|
|
40
|
+
for (const part of slug.toLowerCase().split(/[^a-z0-9]+/)) {
|
|
41
|
+
if (part === "")
|
|
42
|
+
continue;
|
|
43
|
+
const term = stem(part);
|
|
44
|
+
if (isTopicTerm(term) && isTopicTerm(part))
|
|
45
|
+
out.add(term);
|
|
46
|
+
}
|
|
47
|
+
return [...out];
|
|
48
|
+
}
|
|
49
|
+
/** Distinct stemmed terms of free text (an utterance, a title). */
|
|
50
|
+
export function textTerms(text) {
|
|
51
|
+
const out = new Set();
|
|
52
|
+
for (const word of tokenize(text)) {
|
|
53
|
+
for (const part of word.split(/[^a-z0-9]+/)) {
|
|
54
|
+
if (part === "")
|
|
55
|
+
continue;
|
|
56
|
+
const term = stem(part);
|
|
57
|
+
if (isTopicTerm(term))
|
|
58
|
+
out.add(term);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Wording people use when they say something matters or is next. Generic
|
|
65
|
+
* English; it raises the weight of an utterance and never names a topic.
|
|
66
|
+
*/
|
|
67
|
+
const PRIORITY_CUES = /\b(priorit\w*|important|urgent|critical|blocker|blocking|blocked|focus\w*|this week|need to|needs to|have to|must|asap|first|biggest|bottleneck|ship\w*|roll\w* out|rollout|launch\w*|deadline)\b/i;
|
|
68
|
+
export function hasPriorityCue(text) {
|
|
69
|
+
return PRIORITY_CUES.test(text);
|
|
70
|
+
}
|
|
71
|
+
/** One line, trimmed to `max` characters with an ellipsis. */
|
|
72
|
+
export function clip(text, max) {
|
|
73
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
74
|
+
return flat.length <= max ? flat : `${flat.slice(0, Math.max(0, max - 1)).trimEnd()}…`;
|
|
75
|
+
}
|
|
76
|
+
/** The calendar day (YYYY-MM-DD, UTC) of an ISO timestamp, or "" when it does not parse. */
|
|
77
|
+
export function isoDay(timestamp) {
|
|
78
|
+
if (typeof timestamp !== "string")
|
|
79
|
+
return "";
|
|
80
|
+
const ms = Date.parse(timestamp);
|
|
81
|
+
return Number.isNaN(ms) ? "" : new Date(ms).toISOString().slice(0, 10);
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=text.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work in flight that has no pull request yet, per repo (smart-ci US-002).
|
|
3
|
+
*
|
|
4
|
+
* This is the input to demand forecasting: sessions on a feature branch,
|
|
5
|
+
* Work Mesh stories in progress and running lanes are work that is likely to
|
|
6
|
+
* open a pull request soon. Pure: it only reads the inputs it is given.
|
|
7
|
+
*
|
|
8
|
+
* Counting. An item is one piece of work, not one record:
|
|
9
|
+
*
|
|
10
|
+
* - A lane that belongs to a listed session is that session's work. It is
|
|
11
|
+
* named in the session's `covers` and not counted again.
|
|
12
|
+
* - Inside one project, the sessions and lanes are the people and agents doing
|
|
13
|
+
* its stories in progress. They are paired, most recent first: each session
|
|
14
|
+
* or lane covers one story, and only stories beyond that are counted on
|
|
15
|
+
* their own. A project with one session, its lane and its story is 1 item.
|
|
16
|
+
* - An open pull request accounts for one piece of work, never for a whole
|
|
17
|
+
* project. A pull request is on a project when its branch carries the
|
|
18
|
+
* project id as a whole word and it is in the project's repo (any repo when
|
|
19
|
+
* the project names none), or when its branch is the branch of a session
|
|
20
|
+
* bound to the project. If the branch or title names a story id, that story
|
|
21
|
+
* is the one it accounts for; otherwise it accounts for the project's most
|
|
22
|
+
* recently active story or lane that no session is doing.
|
|
23
|
+
*
|
|
24
|
+
* Repo. A project's repo is the one the board gives, else the ontology's,
|
|
25
|
+
* else the repo of a session bound to the project; "unknown" only when none
|
|
26
|
+
* of the three names one.
|
|
27
|
+
*/
|
|
28
|
+
import type { LiveSession, MeshProject, MeshThread, OntologyEntity, PullRequest } from "./sources.js";
|
|
29
|
+
export type WorkInFlightKind = "session" | "story" | "lane";
|
|
30
|
+
export interface WorkInFlightItem {
|
|
31
|
+
kind: WorkInFlightKind;
|
|
32
|
+
/** Session id, `<project>/<story>` or thread id. */
|
|
33
|
+
ref: string;
|
|
34
|
+
owner: string;
|
|
35
|
+
project: string;
|
|
36
|
+
branch: string;
|
|
37
|
+
lastActivityAt: string;
|
|
38
|
+
/** The priority this work belongs to, or "" for none. */
|
|
39
|
+
priorityId: string;
|
|
40
|
+
/** Records counted as this same piece of work: the session's lane (a thread id) and the story it is doing (`<project>/<story>`). */
|
|
41
|
+
covers: string[];
|
|
42
|
+
}
|
|
43
|
+
export interface RepoWorkInFlight {
|
|
44
|
+
/** Repo name without the owner, or "unknown" when the work names no repo. */
|
|
45
|
+
repo: string;
|
|
46
|
+
count: number;
|
|
47
|
+
priorityCount: number;
|
|
48
|
+
items: WorkInFlightItem[];
|
|
49
|
+
}
|
|
50
|
+
export interface WorkInFlightInputs {
|
|
51
|
+
/** Work with no activity since this time (epoch milliseconds) is left out. */
|
|
52
|
+
sinceMs: number;
|
|
53
|
+
sessions: LiveSession[];
|
|
54
|
+
threads: MeshThread[];
|
|
55
|
+
projects: MeshProject[];
|
|
56
|
+
/** Ontology entities keyed by project id, for the repo of a project the board does not give one for. */
|
|
57
|
+
entities: Record<string, OntologyEntity>;
|
|
58
|
+
/** Open pull requests, or null when they could not be read (nothing can then be ruled out). */
|
|
59
|
+
pullRequests: PullRequest[] | null;
|
|
60
|
+
/** Uid to display name. */
|
|
61
|
+
names: Record<string, string>;
|
|
62
|
+
/** Which priority a project belongs to. */
|
|
63
|
+
priorityOfProject: (projectId: string) => string;
|
|
64
|
+
/** Which priority a session's repo and branch point at, when it is bound to no project. */
|
|
65
|
+
priorityOfText: (text: string) => string;
|
|
66
|
+
}
|
|
67
|
+
export declare function listWorkInFlight(input: WorkInFlightInputs): RepoWorkInFlight[];
|
|
68
|
+
//# sourceMappingURL=work-in-flight.d.ts.map
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
const DEFAULT_BRANCHES = new Set(["", "main", "master", "develop", "trunk", "HEAD"]);
|
|
2
|
+
function shortRepo(repo) {
|
|
3
|
+
const name = repo.includes("/") ? repo.slice(repo.lastIndexOf("/") + 1) : repo;
|
|
4
|
+
return name.toLowerCase();
|
|
5
|
+
}
|
|
6
|
+
function fresh(timestamp, sinceMs) {
|
|
7
|
+
const ms = Date.parse(timestamp);
|
|
8
|
+
return !Number.isNaN(ms) && ms >= sinceMs;
|
|
9
|
+
}
|
|
10
|
+
/** `needle` in `haystack` with no letter or digit on either side. Both lower-case. */
|
|
11
|
+
function carries(haystack, needle) {
|
|
12
|
+
if (needle === "")
|
|
13
|
+
return false;
|
|
14
|
+
for (let at = haystack.indexOf(needle); at >= 0; at = haystack.indexOf(needle, at + 1)) {
|
|
15
|
+
const before = at === 0 ? "" : haystack[at - 1];
|
|
16
|
+
const after = haystack[at + needle.length] ?? "";
|
|
17
|
+
if (!/[a-z0-9]/.test(before) && !/[a-z0-9]/.test(after))
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
export function listWorkInFlight(input) {
|
|
23
|
+
const prs = input.pullRequests ?? [];
|
|
24
|
+
const prBranches = new Set(prs.map((p) => `${shortRepo(p.repo)}\n${p.branch}`));
|
|
25
|
+
const projectOfSession = new Map();
|
|
26
|
+
for (const t of input.threads) {
|
|
27
|
+
if (t.sessionId !== "" && t.projectId !== "")
|
|
28
|
+
projectOfSession.set(t.sessionId, t.projectId);
|
|
29
|
+
}
|
|
30
|
+
const projects = new Map(input.projects.map((p) => [p.projectId, p]));
|
|
31
|
+
const sessionRepoOfProject = new Map();
|
|
32
|
+
for (const s of [...input.sessions].sort((a, b) => b.lastTurnAt.localeCompare(a.lastTurnAt))) {
|
|
33
|
+
const project = projectOfSession.get(s.sessionId) ?? "";
|
|
34
|
+
if (project !== "" && s.repo !== "" && !sessionRepoOfProject.has(project))
|
|
35
|
+
sessionRepoOfProject.set(project, s.repo);
|
|
36
|
+
}
|
|
37
|
+
const repoOfProject = (projectId) => {
|
|
38
|
+
const repo = projects.get(projectId)?.repos[0] || input.entities[projectId]?.repo || sessionRepoOfProject.get(projectId) || "";
|
|
39
|
+
return repo === "" ? "unknown" : shortRepo(repo);
|
|
40
|
+
};
|
|
41
|
+
// ---- sessions on a feature branch with no pull request.
|
|
42
|
+
const items = [];
|
|
43
|
+
const listedSessions = new Map();
|
|
44
|
+
for (const s of input.sessions) {
|
|
45
|
+
if (!fresh(s.lastTurnAt, input.sinceMs) || s.repo === "" || DEFAULT_BRANCHES.has(s.branch))
|
|
46
|
+
continue;
|
|
47
|
+
const repo = shortRepo(s.repo);
|
|
48
|
+
if (prBranches.has(`${repo}\n${s.branch}`))
|
|
49
|
+
continue;
|
|
50
|
+
if (listedSessions.has(s.sessionId))
|
|
51
|
+
continue;
|
|
52
|
+
const project = projectOfSession.get(s.sessionId) ?? "";
|
|
53
|
+
const item = {
|
|
54
|
+
repo,
|
|
55
|
+
kind: "session",
|
|
56
|
+
ref: s.sessionId,
|
|
57
|
+
owner: s.owner,
|
|
58
|
+
project,
|
|
59
|
+
branch: s.branch,
|
|
60
|
+
lastActivityAt: s.lastTurnAt,
|
|
61
|
+
priorityId: (project !== "" ? input.priorityOfProject(project) : "") || input.priorityOfText(`${s.repo} ${s.branch}`),
|
|
62
|
+
covers: [],
|
|
63
|
+
};
|
|
64
|
+
listedSessions.set(s.sessionId, item);
|
|
65
|
+
items.push(item);
|
|
66
|
+
}
|
|
67
|
+
// ---- lanes. A lane of a listed session is that session's work.
|
|
68
|
+
const lanes = [];
|
|
69
|
+
for (const t of input.threads) {
|
|
70
|
+
if (t.kind !== "lane" || t.projectId === "" || !fresh(t.lastActivityAt, input.sinceMs))
|
|
71
|
+
continue;
|
|
72
|
+
if (!["open", "in-progress", "blocked"].includes(t.status))
|
|
73
|
+
continue;
|
|
74
|
+
const session = t.sessionId === "" ? undefined : listedSessions.get(t.sessionId);
|
|
75
|
+
if (session) {
|
|
76
|
+
session.covers.push(t.threadId);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
lanes.push({
|
|
80
|
+
repo: repoOfProject(t.projectId),
|
|
81
|
+
kind: "lane",
|
|
82
|
+
ref: t.threadId,
|
|
83
|
+
owner: input.names[t.ownerUid] ?? t.ownerUid,
|
|
84
|
+
project: t.projectId,
|
|
85
|
+
branch: "",
|
|
86
|
+
lastActivityAt: t.lastActivityAt,
|
|
87
|
+
priorityId: input.priorityOfProject(t.projectId),
|
|
88
|
+
covers: [],
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
// ---- per project: pull requests, then sessions and lanes paired with stories in progress.
|
|
92
|
+
const recent = (a, b) => b.lastActivityAt.localeCompare(a.lastActivityAt) || a.ref.localeCompare(b.ref);
|
|
93
|
+
const projectIds = new Set([...input.projects.map((p) => p.projectId), ...lanes.map((l) => l.project)]);
|
|
94
|
+
for (const projectId of projectIds) {
|
|
95
|
+
const project = projects.get(projectId);
|
|
96
|
+
const repo = repoOfProject(projectId);
|
|
97
|
+
const id = projectId.toLowerCase();
|
|
98
|
+
const boundBranches = new Set(input.sessions.filter((s) => projectOfSession.get(s.sessionId) === projectId && !DEFAULT_BRANCHES.has(s.branch)).map((s) => `${shortRepo(s.repo)}\n${s.branch}`));
|
|
99
|
+
const onProject = prs.filter((p) => {
|
|
100
|
+
const prRepo = shortRepo(p.repo);
|
|
101
|
+
if (boundBranches.has(`${prRepo}\n${p.branch}`))
|
|
102
|
+
return true;
|
|
103
|
+
return (repo === "unknown" || prRepo === repo) && carries(p.branch.toLowerCase(), id);
|
|
104
|
+
});
|
|
105
|
+
let stories = (project?.stories ?? [])
|
|
106
|
+
.filter((st) => st.status === "in_progress" && fresh(st.updatedAt || project.updatedAt, input.sinceMs))
|
|
107
|
+
.map((st) => ({ id: st.id, ref: `${projectId}/${st.id}`, owner: st.assignee, lastActivityAt: st.updatedAt || project.updatedAt }))
|
|
108
|
+
.sort(recent);
|
|
109
|
+
let projectLanes = lanes.filter((l) => l.project === projectId).sort(recent);
|
|
110
|
+
// A pull request that names a story accounts for that story. One that names none accounts for one unnamed piece of work.
|
|
111
|
+
let unnamed = 0;
|
|
112
|
+
for (const pr of onProject) {
|
|
113
|
+
const text = `${pr.branch} ${pr.title}`.toLowerCase();
|
|
114
|
+
const named = (project?.stories ?? []).filter((st) => carries(text, st.id.toLowerCase())).map((st) => st.id);
|
|
115
|
+
if (named.length === 0)
|
|
116
|
+
unnamed += 1;
|
|
117
|
+
else
|
|
118
|
+
stories = stories.filter((st) => !named.includes(st.id));
|
|
119
|
+
}
|
|
120
|
+
// Sessions and lanes are the work on the stories: each covers one, most recent first.
|
|
121
|
+
const workers = [...items.filter((i) => i.project === projectId), ...projectLanes].sort(recent);
|
|
122
|
+
const covered = stories.slice(0, workers.length);
|
|
123
|
+
covered.forEach((st, i) => workers[i].covers.push(st.ref));
|
|
124
|
+
let extraStories = stories.slice(workers.length);
|
|
125
|
+
// Pull requests that name no story: each accounts for the most recent story or lane no session is doing.
|
|
126
|
+
for (; unnamed > 0; unnamed -= 1) {
|
|
127
|
+
const story = extraStories[0];
|
|
128
|
+
const lane = projectLanes[0];
|
|
129
|
+
if (story && (!lane || story.lastActivityAt >= lane.lastActivityAt))
|
|
130
|
+
extraStories = extraStories.slice(1);
|
|
131
|
+
else if (lane)
|
|
132
|
+
projectLanes = projectLanes.slice(1);
|
|
133
|
+
else
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
items.push(...projectLanes);
|
|
137
|
+
for (const st of extraStories) {
|
|
138
|
+
items.push({ repo, kind: "story", ref: st.ref, owner: st.owner, project: projectId, branch: "", lastActivityAt: st.lastActivityAt, priorityId: input.priorityOfProject(projectId), covers: [] });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const byRepo = new Map();
|
|
142
|
+
for (const { repo, ...item } of items) {
|
|
143
|
+
const list = byRepo.get(repo) ?? [];
|
|
144
|
+
list.push(item);
|
|
145
|
+
byRepo.set(repo, list);
|
|
146
|
+
}
|
|
147
|
+
return [...byRepo.entries()]
|
|
148
|
+
.map(([repo, list]) => {
|
|
149
|
+
list.sort(recent);
|
|
150
|
+
return { repo, count: list.length, priorityCount: list.filter((i) => i.priorityId !== "").length, items: list };
|
|
151
|
+
})
|
|
152
|
+
.sort((a, b) => b.count - a.count || a.repo.localeCompare(b.repo));
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=work-in-flight.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface CliManifestTarget {
|
|
2
|
+
slug: string;
|
|
3
|
+
uid: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
bucketName?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CliManifestReconcileResult {
|
|
8
|
+
written: boolean;
|
|
9
|
+
added: string[];
|
|
10
|
+
updated: string[];
|
|
11
|
+
skipped: string[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Merge successfully pulled company targets into an existing
|
|
15
|
+
* `companies/manifest.yaml`. Targets without a local company directory, or
|
|
16
|
+
* with an unsafe slug, are skipped. A missing or unreadable manifest is a
|
|
17
|
+
* no-op (this never creates the file).
|
|
18
|
+
*/
|
|
19
|
+
export declare function reconcileCliPullManifest(hqRoot: string, targets: readonly CliManifestTarget[]): CliManifestReconcileResult;
|
|
20
|
+
//# sourceMappingURL=cli-manifest-reconcile.d.ts.map
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Restore companies/manifest.yaml entries after a CLI `hq sync pull`.
|
|
3
|
+
*
|
|
4
|
+
* The menubar hq-sync-runner already reconciles after a `--companies` fanout.
|
|
5
|
+
* `hq sync pull` (and `hq sync pull --all`) never did, so a joiner could pull
|
|
6
|
+
* every company file and still be unable to bind: the local manifest stayed
|
|
7
|
+
* the empty template (feedback_cff52592).
|
|
8
|
+
*
|
|
9
|
+
* This is the CLI-side write path. It only fills `cloud_uid` / `name` /
|
|
10
|
+
* `bucket_name` on an existing manifest. It never creates the file, never
|
|
11
|
+
* deletes entries, and never writes unless the serialized document changes.
|
|
12
|
+
*/
|
|
13
|
+
import { randomUUID } from "node:crypto";
|
|
14
|
+
import * as fs from "node:fs";
|
|
15
|
+
import * as path from "node:path";
|
|
16
|
+
import yaml from "js-yaml";
|
|
17
|
+
const UNSAFE_SLUG_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
18
|
+
function isRecord(value) {
|
|
19
|
+
if (value === null || typeof value !== "object")
|
|
20
|
+
return false;
|
|
21
|
+
const proto = Object.getPrototypeOf(value);
|
|
22
|
+
return proto === Object.prototype || proto === null;
|
|
23
|
+
}
|
|
24
|
+
function ownEntry(companies, slug) {
|
|
25
|
+
return Object.prototype.hasOwnProperty.call(companies, slug)
|
|
26
|
+
? companies[slug]
|
|
27
|
+
: undefined;
|
|
28
|
+
}
|
|
29
|
+
function setEntry(companies, slug, value) {
|
|
30
|
+
Object.defineProperty(companies, slug, {
|
|
31
|
+
value,
|
|
32
|
+
enumerable: true,
|
|
33
|
+
writable: true,
|
|
34
|
+
configurable: true,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function optionalField(value) {
|
|
38
|
+
return typeof value === "string" && value.length > 0 ? value : undefined;
|
|
39
|
+
}
|
|
40
|
+
function isSafeCompanySlug(companiesDir, slug) {
|
|
41
|
+
if (slug.length === 0)
|
|
42
|
+
return false;
|
|
43
|
+
if (slug.includes("/") || slug.includes("\\"))
|
|
44
|
+
return false;
|
|
45
|
+
if (slug === "." || slug === "..")
|
|
46
|
+
return false;
|
|
47
|
+
if (UNSAFE_SLUG_KEYS.has(slug))
|
|
48
|
+
return false;
|
|
49
|
+
const resolvedCompaniesDir = path.resolve(companiesDir);
|
|
50
|
+
const companyDir = path.resolve(resolvedCompaniesDir, slug);
|
|
51
|
+
return path.dirname(companyDir) === resolvedCompaniesDir;
|
|
52
|
+
}
|
|
53
|
+
function hasCompanyDirectory(companiesDir, slug) {
|
|
54
|
+
if (!isSafeCompanySlug(companiesDir, slug))
|
|
55
|
+
return false;
|
|
56
|
+
try {
|
|
57
|
+
return fs.statSync(path.resolve(companiesDir, slug)).isDirectory();
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function loadManifest(manifestPath) {
|
|
64
|
+
try {
|
|
65
|
+
const parsed = yaml.load(fs.readFileSync(manifestPath, "utf8"));
|
|
66
|
+
return isRecord(parsed) ? parsed : null;
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function serializeManifest(document) {
|
|
73
|
+
return yaml.dump(document, { lineWidth: -1 });
|
|
74
|
+
}
|
|
75
|
+
function writeManifestAtomically(manifestPath, serialized) {
|
|
76
|
+
const temporaryPath = path.join(path.dirname(manifestPath), `.manifest-${process.pid}-${randomUUID()}.yaml`);
|
|
77
|
+
try {
|
|
78
|
+
fs.writeFileSync(temporaryPath, serialized, "utf8");
|
|
79
|
+
fs.renameSync(temporaryPath, manifestPath);
|
|
80
|
+
}
|
|
81
|
+
finally {
|
|
82
|
+
try {
|
|
83
|
+
fs.rmSync(temporaryPath, { force: true });
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Best effort — never mask the original error.
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function emptyResult(skipped = []) {
|
|
91
|
+
return { written: false, added: [], updated: [], skipped };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Merge successfully pulled company targets into an existing
|
|
95
|
+
* `companies/manifest.yaml`. Targets without a local company directory, or
|
|
96
|
+
* with an unsafe slug, are skipped. A missing or unreadable manifest is a
|
|
97
|
+
* no-op (this never creates the file).
|
|
98
|
+
*/
|
|
99
|
+
export function reconcileCliPullManifest(hqRoot, targets) {
|
|
100
|
+
const companiesDir = path.join(hqRoot, "companies");
|
|
101
|
+
const skipped = [];
|
|
102
|
+
const eligibleBySlug = new Map();
|
|
103
|
+
for (const target of targets) {
|
|
104
|
+
if (!hasCompanyDirectory(companiesDir, target.slug)) {
|
|
105
|
+
skipped.push(target.slug);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
eligibleBySlug.set(target.slug, target);
|
|
109
|
+
}
|
|
110
|
+
if (eligibleBySlug.size === 0)
|
|
111
|
+
return emptyResult(skipped);
|
|
112
|
+
const manifestPath = path.join(companiesDir, "manifest.yaml");
|
|
113
|
+
const document = loadManifest(manifestPath);
|
|
114
|
+
if (!document)
|
|
115
|
+
return emptyResult(skipped);
|
|
116
|
+
const before = serializeManifest(document);
|
|
117
|
+
let companies;
|
|
118
|
+
if (document.companies === undefined || document.companies === null) {
|
|
119
|
+
companies = {};
|
|
120
|
+
document.companies = companies;
|
|
121
|
+
}
|
|
122
|
+
else if (isRecord(document.companies)) {
|
|
123
|
+
companies = document.companies;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return emptyResult(skipped);
|
|
127
|
+
}
|
|
128
|
+
const pending = [];
|
|
129
|
+
for (const target of eligibleBySlug.values()) {
|
|
130
|
+
const existing = ownEntry(companies, target.slug);
|
|
131
|
+
if (existing !== undefined && !isRecord(existing)) {
|
|
132
|
+
skipped.push(target.slug);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
const desired = { cloud_uid: target.uid };
|
|
136
|
+
const name = optionalField(target.name);
|
|
137
|
+
if (name !== undefined)
|
|
138
|
+
desired.name = name;
|
|
139
|
+
const bucketName = optionalField(target.bucketName);
|
|
140
|
+
if (bucketName !== undefined)
|
|
141
|
+
desired.bucket_name = bucketName;
|
|
142
|
+
if (existing === undefined) {
|
|
143
|
+
pending.push({ slug: target.slug, entry: desired, isNew: true });
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
const drifted = Object.keys(desired).some((key) => existing[key] !== desired[key]);
|
|
147
|
+
if (!drifted)
|
|
148
|
+
continue;
|
|
149
|
+
pending.push({
|
|
150
|
+
slug: target.slug,
|
|
151
|
+
entry: { ...existing, ...desired },
|
|
152
|
+
isNew: false,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
if (pending.length === 0)
|
|
156
|
+
return emptyResult(skipped);
|
|
157
|
+
for (const change of pending)
|
|
158
|
+
setEntry(companies, change.slug, change.entry);
|
|
159
|
+
const serialized = serializeManifest(document);
|
|
160
|
+
if (serialized === before)
|
|
161
|
+
return emptyResult(skipped);
|
|
162
|
+
writeManifestAtomically(manifestPath, serialized);
|
|
163
|
+
return {
|
|
164
|
+
written: true,
|
|
165
|
+
added: pending.filter((change) => change.isNew).map((change) => change.slug),
|
|
166
|
+
updated: pending.filter((change) => !change.isNew).map((change) => change.slug),
|
|
167
|
+
skipped,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=cli-manifest-reconcile.js.map
|
|
@@ -26,6 +26,20 @@ export declare function writeHandbackKeep(home: string, vault: {
|
|
|
26
26
|
beforeRename?: (attempt: number) => void): void;
|
|
27
27
|
export declare function engineHoldFile(engineHome: string, vaultUid: string): string;
|
|
28
28
|
export declare function readEngineHoldKinds(engineHome: string, vaultUid: string): string[];
|
|
29
|
+
export declare const ENGINE_HOLD_DIRECTIONS: readonly ["delete_local", "delete_remote", "overwrite_local", "overwrite_remote", "merge", "undecided", "not_approvable"];
|
|
30
|
+
export interface EngineHeldLocalBody {
|
|
31
|
+
path: string;
|
|
32
|
+
direction: string;
|
|
33
|
+
}
|
|
34
|
+
export interface EngineHeldLocalBodies {
|
|
35
|
+
holdId?: string;
|
|
36
|
+
count: number;
|
|
37
|
+
paths: EngineHeldLocalBody[];
|
|
38
|
+
directions: string[];
|
|
39
|
+
readFailed?: true;
|
|
40
|
+
}
|
|
29
41
|
export declare function readEngineHeldDeletes(engineHome: string, vaultUid: string, warn?: (line: string) => void): EngineHeldDeletes | "unreadable" | null;
|
|
42
|
+
export declare function readEngineHeldLocalBodies(engineHome: string, vaultUid: string): EngineHeldLocalBodies | null;
|
|
43
|
+
export declare function heldLocalBodiesHandoverLine(vaultUid: string, held: EngineHeldLocalBodies): string;
|
|
30
44
|
export declare function heldDeletesHandoverLine(vaultUid: string, held: EngineHeldDeletes | "unreadable", engineHome: string, home: string): string;
|
|
31
45
|
//# sourceMappingURL=engine-holds.d.ts.map
|
|
@@ -104,7 +104,17 @@ export function readEngineHoldKinds(engineHome, vaultUid) {
|
|
|
104
104
|
return [];
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
|
-
export
|
|
107
|
+
export const ENGINE_HOLD_DIRECTIONS = [
|
|
108
|
+
"delete_local",
|
|
109
|
+
"delete_remote",
|
|
110
|
+
"overwrite_local",
|
|
111
|
+
"overwrite_remote",
|
|
112
|
+
"merge",
|
|
113
|
+
"undecided",
|
|
114
|
+
"not_approvable",
|
|
115
|
+
];
|
|
116
|
+
const LOCAL_BODY_DIRECTIONS = new Set(["overwrite_remote", "merge", "undecided", "not_approvable"]);
|
|
117
|
+
function readEngineHold(engineHome, vaultUid) {
|
|
108
118
|
let text;
|
|
109
119
|
try {
|
|
110
120
|
const file = engineHoldFile(engineHome, vaultUid);
|
|
@@ -114,7 +124,7 @@ export function readEngineHeldDeletes(engineHome, vaultUid, warn = () => { }) {
|
|
|
114
124
|
text = fs.readFileSync(file, "utf8");
|
|
115
125
|
}
|
|
116
126
|
catch (error) {
|
|
117
|
-
return error.code === "ENOENT" ? null : "
|
|
127
|
+
return error.code === "ENOENT" ? null : "read-failed";
|
|
118
128
|
}
|
|
119
129
|
let hold;
|
|
120
130
|
try {
|
|
@@ -125,6 +135,21 @@ export function readEngineHeldDeletes(engineHome, vaultUid, warn = () => { }) {
|
|
|
125
135
|
}
|
|
126
136
|
if (!hold || !Array.isArray(hold.groups))
|
|
127
137
|
return "unreadable";
|
|
138
|
+
return hold;
|
|
139
|
+
}
|
|
140
|
+
function groupPaths(group) {
|
|
141
|
+
return Array.isArray(group.paths) ? group.paths.filter((p) => typeof p === "string") : [];
|
|
142
|
+
}
|
|
143
|
+
function groupCount(group, paths) {
|
|
144
|
+
const declared = typeof group.count === "number" && Number.isSafeInteger(group.count) && group.count >= 0 ? group.count : 0;
|
|
145
|
+
return Math.max(paths.length, declared);
|
|
146
|
+
}
|
|
147
|
+
export function readEngineHeldDeletes(engineHome, vaultUid, warn = () => { }) {
|
|
148
|
+
const hold = readEngineHold(engineHome, vaultUid);
|
|
149
|
+
if (hold === null)
|
|
150
|
+
return null;
|
|
151
|
+
if (hold === "unreadable" || hold === "read-failed")
|
|
152
|
+
return "unreadable";
|
|
128
153
|
const deletes = [];
|
|
129
154
|
const unknown = new Set();
|
|
130
155
|
let count = 0;
|
|
@@ -132,25 +157,67 @@ export function readEngineHeldDeletes(engineHome, vaultUid, warn = () => { }) {
|
|
|
132
157
|
const group = record(value);
|
|
133
158
|
if (!group || typeof group.direction !== "string")
|
|
134
159
|
return "unreadable";
|
|
135
|
-
|
|
160
|
+
const direction = group.direction;
|
|
161
|
+
if (direction === "overwrite_local" || LOCAL_BODY_DIRECTIONS.has(direction))
|
|
136
162
|
continue;
|
|
137
|
-
if (
|
|
138
|
-
if (!unknown.has(
|
|
139
|
-
unknown.add(
|
|
140
|
-
warn(`${vaultUid}: the new sync engine's hold file ${engineHoldFile(engineHome, vaultUid)} has a kind of hold this hq does not know (direction ${
|
|
163
|
+
if (direction !== "delete_local" && direction !== "delete_remote") {
|
|
164
|
+
if (!unknown.has(direction) && groupCount(group, groupPaths(group)) > 0) {
|
|
165
|
+
unknown.add(direction);
|
|
166
|
+
warn(`${vaultUid}: the new sync engine's hold file ${engineHoldFile(engineHome, vaultUid)} has a kind of hold this hq does not know (direction ${printable(direction.slice(0, 64))}); the vault is not handed to the current sync while it is held, so its local copies stay as they are`);
|
|
141
167
|
}
|
|
142
168
|
continue;
|
|
143
169
|
}
|
|
144
|
-
const paths =
|
|
145
|
-
|
|
146
|
-
count += Math.max(paths.length, declared);
|
|
170
|
+
const paths = groupPaths(group);
|
|
171
|
+
count += groupCount(group, paths);
|
|
147
172
|
for (const p of paths)
|
|
148
|
-
deletes.push({ path: p, direction
|
|
173
|
+
deletes.push({ path: p, direction });
|
|
149
174
|
}
|
|
150
175
|
if (count === 0)
|
|
151
176
|
return null;
|
|
152
177
|
return { ...(typeof hold.holdId === "string" && hold.holdId ? { holdId: hold.holdId } : {}), count, deletes };
|
|
153
178
|
}
|
|
179
|
+
export function readEngineHeldLocalBodies(engineHome, vaultUid) {
|
|
180
|
+
const hold = readEngineHold(engineHome, vaultUid);
|
|
181
|
+
if (hold === null || hold === "unreadable")
|
|
182
|
+
return null;
|
|
183
|
+
if (hold === "read-failed")
|
|
184
|
+
return { count: 0, paths: [], directions: [], readFailed: true };
|
|
185
|
+
const paths = [];
|
|
186
|
+
const directions = new Set();
|
|
187
|
+
let count = 0;
|
|
188
|
+
for (const value of hold.groups) {
|
|
189
|
+
const group = record(value) ?? {};
|
|
190
|
+
const direction = typeof group.direction === "string" ? group.direction : "unknown";
|
|
191
|
+
if (direction === "delete_local" || direction === "delete_remote" || direction === "overwrite_local")
|
|
192
|
+
continue;
|
|
193
|
+
const held = groupPaths(group);
|
|
194
|
+
const n = typeof group.direction === "string" ? groupCount(group, held) : Math.max(1, groupCount(group, held));
|
|
195
|
+
if (n === 0)
|
|
196
|
+
continue;
|
|
197
|
+
count += n;
|
|
198
|
+
directions.add(direction);
|
|
199
|
+
for (const p of held)
|
|
200
|
+
paths.push({ path: p, direction });
|
|
201
|
+
}
|
|
202
|
+
if (count === 0)
|
|
203
|
+
return null;
|
|
204
|
+
return {
|
|
205
|
+
...(typeof hold.holdId === "string" && hold.holdId ? { holdId: hold.holdId } : {}),
|
|
206
|
+
count,
|
|
207
|
+
paths,
|
|
208
|
+
directions: [...directions].sort(),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
export function heldLocalBodiesHandoverLine(vaultUid, held) {
|
|
212
|
+
if (held.readFailed) {
|
|
213
|
+
return `${vaultUid}: not handed back to the current sync yet: the new sync engine's hold file could not be read just now, so it may hold local copies the current sync would replace; the vault stays off both syncs until the file can be read`;
|
|
214
|
+
}
|
|
215
|
+
const shown = held.paths.slice(0, HELD_DELETE_LOG_LIMIT).map((entry) => printable(entry.path));
|
|
216
|
+
const more = held.count > shown.length ? `; and ${held.count - shown.length} more` : "";
|
|
217
|
+
const id = held.holdId ? ` (hold ${/^[A-Za-z0-9_-]{1,64}$/.test(held.holdId) ? held.holdId : printable(held.holdId)})` : "";
|
|
218
|
+
const kinds = held.directions.map((direction) => printable(direction.slice(0, 64))).join(", ");
|
|
219
|
+
return `${vaultUid}: not handed back to the current sync yet: the new sync engine held ${held.count} change${held.count === 1 ? "" : "s"} that keep this device's copy (${kinds})${id}, and the current sync would replace those local copies with the vault's; the local copies stay as they are and the vault stays off both syncs until the new sync engine can run this vault again and the hold is decided: ${shown.join(", ")}${more}`;
|
|
220
|
+
}
|
|
154
221
|
function printable(value) {
|
|
155
222
|
return JSON.stringify(value);
|
|
156
223
|
}
|
|
@@ -7,6 +7,7 @@ export interface HandBackVault {
|
|
|
7
7
|
legacyAlreadyOff?: boolean;
|
|
8
8
|
}
|
|
9
9
|
export declare function engineOwnsVault(home: string, uid: string): boolean;
|
|
10
|
+
export declare function engineHoldBlocksHandBack(home: string, uid: string): boolean;
|
|
10
11
|
/**
|
|
11
12
|
* Returns vaults whose engine has stopped to the current sync: turns the
|
|
12
13
|
* old-sync switch back on (not for a vault the user had off before the move),
|