@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,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
|
|
@@ -51,6 +51,7 @@ export interface EngineCapabilities {
|
|
|
51
51
|
events: Record<string, string[]>;
|
|
52
52
|
/** The old dispatcher's hooks the engine does in full, per event; empty for an engine that does not say. */
|
|
53
53
|
covers?: Record<string, string[]>;
|
|
54
|
+
handBackQuery?: string;
|
|
54
55
|
}
|
|
55
56
|
/** Evaluators `event` needs that `caps` lacks; null when the event has no switch rule. */
|
|
56
57
|
export declare function missingEvaluators(caps: EngineCapabilities, event: string): string[] | null;
|
|
@@ -152,7 +152,7 @@ export function probeEngine(engine) {
|
|
|
152
152
|
covers[event] = Array.isArray(ids) ? ids.filter((id) => typeof id === 'string') : [];
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
return { version: version.slice('hq-hook '.length), events, covers, registrationHosts: doc.registration_hosts };
|
|
155
|
+
return { version: version.slice('hq-hook '.length), events, covers, registrationHosts: doc.registration_hosts, ...(typeof doc.hand_back_query === 'string' ? { handBackQuery: doc.hand_back_query } : {}) };
|
|
156
156
|
}
|
|
157
157
|
/**
|
|
158
158
|
* Check that the stable path resolves to the pinned engine before a
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@indigoai-us/hq-cli",
|
|
3
|
-
"version": "5.345.
|
|
3
|
+
"version": "5.345.254",
|
|
4
4
|
"description": "HQ by Indigo management CLI — modules and cloud sync",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -128,11 +128,11 @@
|
|
|
128
128
|
"*.{ts,tsx,mts,cts,js,jsx,mjs,cjs}": "eslint --cache --no-error-on-unmatched-pattern"
|
|
129
129
|
},
|
|
130
130
|
"optionalDependencies": {
|
|
131
|
-
"@indigoai-us/hq-hook-win32-x64": "5.345.
|
|
132
|
-
"@indigoai-us/hq-hook-win32-arm64": "5.345.
|
|
133
|
-
"@indigoai-us/hq-hook-darwin-x64": "5.345.
|
|
134
|
-
"@indigoai-us/hq-hook-darwin-arm64": "5.345.
|
|
135
|
-
"@indigoai-us/hq-hook-linux-x64": "5.345.
|
|
136
|
-
"@indigoai-us/hq-hook-linux-arm64": "5.345.
|
|
131
|
+
"@indigoai-us/hq-hook-win32-x64": "5.345.254",
|
|
132
|
+
"@indigoai-us/hq-hook-win32-arm64": "5.345.254",
|
|
133
|
+
"@indigoai-us/hq-hook-darwin-x64": "5.345.254",
|
|
134
|
+
"@indigoai-us/hq-hook-darwin-arm64": "5.345.254",
|
|
135
|
+
"@indigoai-us/hq-hook-linux-x64": "5.345.254",
|
|
136
|
+
"@indigoai-us/hq-hook-linux-arm64": "5.345.254"
|
|
137
137
|
}
|
|
138
138
|
}
|