@theholocron/cli 5.0.0-alpha.49 → 5.0.0-alpha.490
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/README.md +607 -107
- package/dist/cli.mjs +31410 -8202
- package/dist/cli.mjs.map +1 -1
- package/dist/config-system-BzncySAC.mjs +839 -0
- package/dist/index-BmhgIDmN.d.mts +4912 -0
- package/dist/index.d.mts +615 -622
- package/dist/index.mjs +869 -346
- package/dist/plugin/capabilities.d.mts +2 -807
- package/dist/plugin/capabilities.mjs +59 -4
- package/dist/presets.d.mts +224 -0
- package/dist/presets.mjs +441 -0
- package/package.json +49 -36
package/dist/index.mjs
CHANGED
|
@@ -1,119 +1,654 @@
|
|
|
1
|
-
import { CARDINALITY, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, isMulti } from "./plugin/capabilities.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { createEnvLookup } from "@theholocron/env-utils";
|
|
1
|
+
import { CARDINALITY, ElevationRequiredError, MissingTokenError, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, isMulti } from "./plugin/capabilities.mjs";
|
|
2
|
+
import { a as placeAreas, c as ConfigError, d as resolveEntry, f as resolvePluginPackage, g as layerEnvironment, h as isEnvironmentLayer, i as loadConfig, l as credentialsEnvironment, m as ENVIRONMENT_LAYERS, n as compose, o as HOLOCRON_AREAS, p as repoSlug, r as defineConfig, s as SHARED_AREAS, t as ConfigFileError, u as resolveConfig } from "./config-system-BzncySAC.mjs";
|
|
4
3
|
import { Entry, findCredentials } from "@napi-rs/keyring";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
4
|
+
import { AuthError, createFeatureResolver as createFeatureResolver$1, createKeyring, createResolveToken as createResolveToken$1, resolveValue } from "@theholocron/kyber/secrets";
|
|
5
|
+
import { DOCUMENTATION_FLAG, codecovFlagNames, readWorkspacePackages } from "@theholocron/astromech";
|
|
6
|
+
import { describeError, style } from "@theholocron/kyber/ui";
|
|
7
|
+
import { errorMessage } from "@theholocron/misc-utils";
|
|
8
|
+
import { createRestClient } from "@theholocron/http-client";
|
|
9
|
+
import { connectionProbe as connectionProbe$1 } from "@theholocron/kyber/checks";
|
|
10
|
+
import { dirname, join, resolve } from "node:path";
|
|
11
|
+
import { readPackageJson } from "@theholocron/pkg-utils";
|
|
12
|
+
import { fstatSync, mkdirSync } from "node:fs";
|
|
13
|
+
// src/auth/auth.ts
|
|
12
14
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
+
* The CLI's credentials: the OS keyring every plugin's bootstrap token lives in, and the two token resolvers built on
|
|
16
|
+
* it. Both are public, so a plugin's `src/auth.ts` is a one-line call.
|
|
17
|
+
*
|
|
18
|
+
* The keyring itself, with its best-effort failure model and its per-process cache, is `createKeyring` in
|
|
19
|
+
* `@theholocron/kyber/secrets`; this file only names the service. Managed via `holocron check token` subcommands and consulted
|
|
20
|
+
* last in every plugin's precedence chain (after --token / HOLOCRON_<X>_TOKEN / <native>_TOKEN). See
|
|
21
|
+
* `docs/wiki/specifications/tech-auth-bootstrap.spec.md`.
|
|
22
|
+
*/
|
|
23
|
+
/**
|
|
24
|
+
* The holocron keyring: `get` answers `null` for "not stored" and for "keyring unavailable" alike, so callers fall
|
|
25
|
+
* through to env-var precedence, and remembers the answer for the process (`clearCache` forgets it); `set` and `delete`
|
|
26
|
+
* answer whether they did anything; `list` names the stored providers; `isAvailable` tells an outage from an empty keyring.
|
|
27
|
+
*/
|
|
28
|
+
const keyring = createKeyring({
|
|
29
|
+
service: "com.theholocron.cli",
|
|
30
|
+
binding: {
|
|
31
|
+
Entry,
|
|
32
|
+
findCredentials
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Kyber's `createResolveToken` with the keyring, the `HOLOCRON_ORG` variable and the `token` description
|
|
37
|
+
* `holocron doctor secrets --verify` reads filled in, so a plugin stays at a one-liner call site. The chain is the flag, the
|
|
38
|
+
* plugin's variable, the vendor's variable, the `credentials` providers' variables, the keyring.
|
|
15
39
|
*/
|
|
16
|
-
function
|
|
17
|
-
return
|
|
40
|
+
function createResolveToken(config) {
|
|
41
|
+
return Object.assign(createResolveToken$1({
|
|
42
|
+
...config,
|
|
43
|
+
keyring: keyring.get,
|
|
44
|
+
orgEnvName: "HOLOCRON_ORG"
|
|
45
|
+
}), { token: {
|
|
46
|
+
envName: config.envName,
|
|
47
|
+
vendorEnvName: config.vendorEnvName,
|
|
48
|
+
keyringKey: config.keyringService
|
|
49
|
+
} });
|
|
18
50
|
}
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/auth/keyring.ts
|
|
21
51
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
52
|
+
* Kyber's `createFeatureResolver` for a strict, single-feature token: the flag, the feature's variable, the
|
|
53
|
+
* `credentials` providers' variable of that name, the keyring. No broad-token fallback; if the feature's token is absent
|
|
54
|
+
* the operation fails with a message naming the exact variable to set and `holocron new token`.
|
|
55
|
+
*/
|
|
56
|
+
function createFeatureResolver(config) {
|
|
57
|
+
return Object.assign(createFeatureResolver$1({
|
|
58
|
+
...config,
|
|
59
|
+
vendor: config.vendor ?? "GitHub",
|
|
60
|
+
setCommand: (key) => `holocron new token ${key} <token>`,
|
|
61
|
+
keyring: keyring.get
|
|
62
|
+
}), { token: {
|
|
63
|
+
envName: config.envName,
|
|
64
|
+
keyringKey: config.keyringKey
|
|
65
|
+
} });
|
|
66
|
+
}
|
|
67
|
+
// src/commands/coverage-expectations/coverage-expectations.ts
|
|
68
|
+
/**
|
|
69
|
+
* The flags and components `holocron sync` writes to `codecov.yml` for the workspace at `repoRoot`: the same
|
|
70
|
+
* functions the generator uses, so a coverage provider's `checkRepo()` compares with exactly what is written. A flag per
|
|
71
|
+
* package (none for `docs`), plus `documentation` when `docsCoverage` is `warn` or `required`; a component per package.
|
|
72
|
+
* Both lists are sorted. Plugins call this instead of importing the task runner.
|
|
73
|
+
*/
|
|
74
|
+
function coverageExpectations(repoRoot, docsCoverage = "off") {
|
|
75
|
+
const packages = readWorkspacePackages(repoRoot);
|
|
76
|
+
const flags = codecovFlagNames(packages);
|
|
77
|
+
if (docsCoverage !== "off") flags.push(DOCUMENTATION_FLAG);
|
|
78
|
+
return {
|
|
79
|
+
flags: [...new Set(flags)].sort(),
|
|
80
|
+
components: packages.map((pkg) => pkg.slug).sort()
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// src/plugin/issues-provider/order-keys/order-keys.ts
|
|
84
|
+
/**
|
|
85
|
+
* Puts issue keys in creation order without asking the tracker: issue numbers (`#12`, `ENG-12`) rise with creation inside
|
|
86
|
+
* one repository or team, so the trailing number is the order. `oldest` is ascending, `newest` descending; keys with the
|
|
87
|
+
* same number keep their place. A key with no trailing number is an error, because nothing can be said of its age.
|
|
88
|
+
*/
|
|
89
|
+
function orderKeys(keys, order) {
|
|
90
|
+
const numbered = keys.map((key, index) => {
|
|
91
|
+
const match = /(\d+)\s*$/.exec(key);
|
|
92
|
+
if (!match) throw new Error(`Cannot order "${key}" by creation: it has no issue number.`);
|
|
93
|
+
return {
|
|
94
|
+
key,
|
|
95
|
+
index,
|
|
96
|
+
n: Number(match[1])
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
const sign = order === "newest" ? -1 : 1;
|
|
100
|
+
return numbered.sort((a, b) => sign * (a.n - b.n) || a.index - b.index).map((e) => e.key);
|
|
101
|
+
}
|
|
102
|
+
// src/plugin/issues-provider/pick-by-creation/pick-by-creation.ts
|
|
103
|
+
/**
|
|
104
|
+
* Keeps the first or last `limit` of a listing by creation time, returned oldest first. `createdAt` reads an item's
|
|
105
|
+
* ISO timestamp; items created in the same instant keep their listed order. The cut happens on what the listing already
|
|
106
|
+
* holds, so no request is spent on an item that is dropped.
|
|
107
|
+
*/
|
|
108
|
+
function pickByCreation(items, createdAt, order, limit) {
|
|
109
|
+
const ascending = items.map((item, index) => ({
|
|
110
|
+
item,
|
|
111
|
+
index,
|
|
112
|
+
at: Date.parse(createdAt(item))
|
|
113
|
+
})).sort((a, b) => a.at - b.at || a.index - b.index).map((e) => e.item);
|
|
114
|
+
return order === "newest" ? ascending.slice(Math.max(ascending.length - limit, 0)) : ascending.slice(0, limit);
|
|
115
|
+
}
|
|
116
|
+
// src/plugin/issues-provider/read-keys-limited/read-keys-limited.ts
|
|
117
|
+
/**
|
|
118
|
+
* Reads an explicit list of issues in creation order until `limit` of them are kept. The keys are sorted by number first
|
|
119
|
+
* (see {@link orderKeys}), then fetched in small steps of at most `concurrency`, each step no bigger than the places
|
|
120
|
+
* still open, so an issue that is later skipped (a pull request, a closed one) is replaced by the next key and nothing
|
|
121
|
+
* beyond the budget is fetched unless a skip made room. Within a step the fetches run together; the results keep the key
|
|
122
|
+
* order. The kept items come back oldest first, whichever end was chosen.
|
|
123
|
+
*/
|
|
124
|
+
async function readKeysLimited(input) {
|
|
125
|
+
const { keys, order, limit, concurrency, fetch, keep } = input;
|
|
126
|
+
const ordered = orderKeys(keys, order);
|
|
127
|
+
const kept = [];
|
|
128
|
+
let next = 0;
|
|
129
|
+
while (kept.length < limit && next < ordered.length) {
|
|
130
|
+
const step = ordered.slice(next, next + Math.min(concurrency, limit - kept.length));
|
|
131
|
+
next += step.length;
|
|
132
|
+
const fetched = await Promise.all(step.map((key) => fetch(key)));
|
|
133
|
+
for (const item of fetched) if (keep(item)) kept.push(item);
|
|
134
|
+
}
|
|
135
|
+
return order === "newest" ? kept.reverse() : kept;
|
|
136
|
+
}
|
|
137
|
+
// src/plugin/issues-provider/report-progress/report-progress.ts
|
|
138
|
+
/**
|
|
139
|
+
* Calls a provider's optional `onProgress` hook with how many items are done of how many. A hook that throws is
|
|
140
|
+
* ignored, because a progress counter must never change or stop the read or write it reports on.
|
|
31
141
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* here catches and returns a null/empty result rather than propagating
|
|
36
|
-
* — the plugin's precedence chain then falls through to
|
|
37
|
-
* env-var-only paths, which is exactly how CI is meant to work.
|
|
142
|
+
* @param onProgress - The hook from `ExportInfo` or `ImportOptions`; nothing happens when it is not given.
|
|
143
|
+
* @param done - How many items are finished.
|
|
144
|
+
* @param total - How many items there are.
|
|
38
145
|
*/
|
|
39
|
-
|
|
146
|
+
function reportProgress(onProgress, done, total) {
|
|
147
|
+
try {
|
|
148
|
+
onProgress?.(done, total);
|
|
149
|
+
} catch {}
|
|
150
|
+
}
|
|
151
|
+
// src/plugin/probes/connection-probe/connection-probe.ts
|
|
40
152
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
153
|
+
* The `connection` probe every provider offers, for telling a network problem from a credential problem. The checks are
|
|
154
|
+
* kyber's `connectionProbe`; this types the result as the plugin system's {@link Probe} and `verify` as `VerifyTokenResult`.
|
|
43
155
|
*/
|
|
44
|
-
function
|
|
156
|
+
function connectionProbe(input) {
|
|
157
|
+
return connectionProbe$1(input);
|
|
158
|
+
}
|
|
159
|
+
// src/commands/notifications-sync-roles/links.ts
|
|
160
|
+
const EMPTY_LINKS = {
|
|
161
|
+
version: 1,
|
|
162
|
+
links: []
|
|
163
|
+
};
|
|
164
|
+
const DIGITS = /^\d{1,20}$/;
|
|
165
|
+
/** Reads the file's text. Throws with a plain reason on anything that is not a links file, so a damaged one is never treated as empty. */
|
|
166
|
+
function parseLinks(text) {
|
|
167
|
+
let raw;
|
|
45
168
|
try {
|
|
46
|
-
|
|
47
|
-
return true;
|
|
169
|
+
raw = JSON.parse(text);
|
|
48
170
|
} catch {
|
|
49
|
-
|
|
171
|
+
throw new Error("the links file is not valid JSON");
|
|
50
172
|
}
|
|
173
|
+
const file = raw;
|
|
174
|
+
if (file.version !== 1) throw new Error(`the links file has version ${JSON.stringify(file.version)}; expected 1`);
|
|
175
|
+
if (!Array.isArray(file.links)) throw new Error("the links file has no `links` list");
|
|
176
|
+
const links = file.links.map((entry, i) => {
|
|
177
|
+
const e = entry;
|
|
178
|
+
if (typeof e.github !== "string" || !DIGITS.test(e.github)) throw new Error(`links[${i}]: \`github\` must be a numeric user id string`);
|
|
179
|
+
if (typeof e.member !== "string" || !DIGITS.test(e.member)) throw new Error(`links[${i}]: \`member\` must be a numeric id string`);
|
|
180
|
+
if (typeof e.login !== "string") throw new Error(`links[${i}]: \`login\` must be a string`);
|
|
181
|
+
return {
|
|
182
|
+
github: e.github,
|
|
183
|
+
login: e.login,
|
|
184
|
+
member: e.member
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
for (const key of ["github", "member"]) {
|
|
188
|
+
const seen = /* @__PURE__ */ new Set();
|
|
189
|
+
for (const [i, link] of links.entries()) {
|
|
190
|
+
if (seen.has(link[key])) throw new Error(`links[${i}]: \`${key}\` ${link[key]} appears more than once`);
|
|
191
|
+
seen.add(link[key]);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
version: 1,
|
|
196
|
+
links
|
|
197
|
+
};
|
|
51
198
|
}
|
|
199
|
+
/** Where the links file is: the layout's `links`, else `<org>/.github-private` and `notifications/<provider>-links.json`. */
|
|
200
|
+
function linksLocation(layout, org, provider) {
|
|
201
|
+
const repo = layout.links?.repo ?? (org ? `${org}/.github-private` : void 0);
|
|
202
|
+
if (!repo) throw new Error("no org to find the links file under — set `layout.links.repo` or `org` in holocron.config.ts");
|
|
203
|
+
return {
|
|
204
|
+
repo,
|
|
205
|
+
path: layout.links?.path ?? `notifications/${provider.toLowerCase()}-links.json`
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
// src/commands/notifications-sync-roles/plan.ts
|
|
52
209
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
210
|
+
* What it takes to make a role's holders equal a team, given who is linked to whom. Pure: it decides, the
|
|
211
|
+
* caller acts. A holder is removed only when a link says they are a person who left the team; a holder
|
|
212
|
+
* nobody has linked is reported, never removed, so an empty or missing links file cannot strip the role from
|
|
213
|
+
* everyone.
|
|
56
214
|
*/
|
|
57
|
-
function
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
215
|
+
function planRoleSync(input) {
|
|
216
|
+
const byGithub = new Map(input.links.map((l) => [l.github, l]));
|
|
217
|
+
const byMember = new Map(input.links.map((l) => [l.member, l]));
|
|
218
|
+
const onTeam = new Set(input.team.map((m) => m.id));
|
|
219
|
+
const holding = new Set(input.holders.map((h) => h.id));
|
|
220
|
+
const plan = {
|
|
221
|
+
add: [],
|
|
222
|
+
remove: [],
|
|
223
|
+
unlinked: [],
|
|
224
|
+
unknownHolders: [],
|
|
225
|
+
inSync: 0
|
|
226
|
+
};
|
|
227
|
+
for (const person of input.team) {
|
|
228
|
+
const link = byGithub.get(person.id);
|
|
229
|
+
if (!link) plan.unlinked.push(person);
|
|
230
|
+
else if (holding.has(link.member)) plan.inSync++;
|
|
231
|
+
else plan.add.push({
|
|
232
|
+
member: link.member,
|
|
233
|
+
login: person.login
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
for (const holder of input.holders) {
|
|
237
|
+
const link = byMember.get(holder.id);
|
|
238
|
+
if (!link) plan.unknownHolders.push({
|
|
239
|
+
member: holder.id,
|
|
240
|
+
...holder.name ? { name: holder.name } : {}
|
|
241
|
+
});
|
|
242
|
+
else if (!onTeam.has(link.github)) plan.remove.push({
|
|
243
|
+
member: holder.id,
|
|
244
|
+
login: link.login
|
|
245
|
+
});
|
|
62
246
|
}
|
|
247
|
+
return plan;
|
|
63
248
|
}
|
|
64
249
|
/**
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
* Distinguishing the two cases isn't worth the surface area — the
|
|
68
|
-
* command output makes the situation clear either way.
|
|
250
|
+
* The first role the layout declares for two different teams, or undefined. Names compare ignoring case, as
|
|
251
|
+
* the server does; the role would be synced against one team and then the other, so the last would win.
|
|
69
252
|
*/
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
253
|
+
function roleTeamProblem(layout) {
|
|
254
|
+
const seen = /* @__PURE__ */ new Map();
|
|
255
|
+
for (const role of layout.roles ?? []) {
|
|
256
|
+
if (!role.team) continue;
|
|
257
|
+
const key = role.name.toLowerCase();
|
|
258
|
+
const earlier = seen.get(key);
|
|
259
|
+
if (earlier !== void 0 && earlier.toLowerCase() !== role.team.toLowerCase()) return `role \`${role.name}\` is declared for two teams (\`${earlier}\` and \`${role.team}\`); a role follows one team`;
|
|
260
|
+
seen.set(key, role.team);
|
|
75
261
|
}
|
|
76
262
|
}
|
|
263
|
+
// src/commands/notifications-sync-roles/sync-roles.ts
|
|
264
|
+
/** Reads the team and the role's holders and works out what has to change. */
|
|
265
|
+
async function planForRole(args) {
|
|
266
|
+
const [team, holders] = await Promise.all([args.source.teamMembers(args.team, args.org), args.notifications.roleMembers(args.role)]);
|
|
267
|
+
return planRoleSync({
|
|
268
|
+
team,
|
|
269
|
+
links: args.links.links,
|
|
270
|
+
holders
|
|
271
|
+
});
|
|
272
|
+
}
|
|
77
273
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
274
|
+
* Makes each role's holders equal its team, one role after another. This is the sync itself, with no setup in
|
|
275
|
+
* front of it: the caller has already picked the providers, read the links and checked the layout. `holocron
|
|
276
|
+
* sync roles` and Sentinel's role sync are two callers of it. A step that fails is recorded and the
|
|
277
|
+
* run goes on; nothing here throws for a provider error. Idempotent: a role that already matches changes nothing.
|
|
278
|
+
* Lines go to `input.print` when it is given, and nowhere otherwise.
|
|
81
279
|
*/
|
|
82
|
-
function
|
|
280
|
+
async function syncRoles(input) {
|
|
281
|
+
const print = input.print ?? (() => {});
|
|
282
|
+
const { notifications, source, links, dryRun, keep } = input;
|
|
283
|
+
const result = {
|
|
284
|
+
roles: [],
|
|
285
|
+
failures: [],
|
|
286
|
+
ok: 0,
|
|
287
|
+
skipped: 0
|
|
288
|
+
};
|
|
289
|
+
for (const role of input.roles) {
|
|
290
|
+
print(`\n${style.header(`${role.name} ← team ${role.team}`)}`);
|
|
291
|
+
const step = `role ${role.name}`;
|
|
292
|
+
let plan;
|
|
293
|
+
try {
|
|
294
|
+
plan = await planForRole({
|
|
295
|
+
notifications,
|
|
296
|
+
source,
|
|
297
|
+
role: role.name,
|
|
298
|
+
team: role.team,
|
|
299
|
+
...input.org ? { org: input.org } : {},
|
|
300
|
+
links
|
|
301
|
+
});
|
|
302
|
+
} catch (err) {
|
|
303
|
+
const message = describeError(err);
|
|
304
|
+
print(` ${style.fail(`${step}: ${message}`)}`);
|
|
305
|
+
result.failures.push({
|
|
306
|
+
step,
|
|
307
|
+
message
|
|
308
|
+
});
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const outcome = {
|
|
312
|
+
role: role.name,
|
|
313
|
+
team: role.team,
|
|
314
|
+
plan,
|
|
315
|
+
added: [],
|
|
316
|
+
removed: []
|
|
317
|
+
};
|
|
318
|
+
result.roles.push(outcome);
|
|
319
|
+
result.skipped += plan.inSync;
|
|
320
|
+
if (plan.inSync > 0) print(` ${style.skip(`${plan.inSync} already have it`)}`);
|
|
321
|
+
const act = async (verb, who) => {
|
|
322
|
+
const label = `${verb === "add" ? "gave" : "took"} ${role.name} ${verb === "add" ? "to" : "from"} ${who.login} (${who.member})`;
|
|
323
|
+
if (dryRun || verb === "remove" && keep) {
|
|
324
|
+
print(` ${style.skip(`would ${verb === "add" ? "give" : "take"} ${role.name} ${verb === "add" ? "to" : "from"} ${who.login} (${who.member})${keep && verb === "remove" ? " (kept: --keep)" : ""}`)}`);
|
|
325
|
+
result.skipped++;
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
try {
|
|
329
|
+
if (verb === "add") await notifications.addRoleMember(role.name, who.member);
|
|
330
|
+
else await notifications.removeRoleMember(role.name, who.member);
|
|
331
|
+
(verb === "add" ? outcome.added : outcome.removed).push(who.member);
|
|
332
|
+
print(` ${style.success(label)}`);
|
|
333
|
+
result.ok++;
|
|
334
|
+
} catch (err) {
|
|
335
|
+
const message = describeError(err);
|
|
336
|
+
print(` ${style.fail(`${step}: ${verb} ${who.login}: ${message}`)}`);
|
|
337
|
+
result.failures.push({
|
|
338
|
+
step: `${step} ${verb} ${who.login}`,
|
|
339
|
+
message
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
for (const who of plan.add) await act("add", who);
|
|
344
|
+
for (const who of plan.remove) await act("remove", who);
|
|
345
|
+
for (const person of plan.unlinked) {
|
|
346
|
+
print(` ${style.skip(`${person.login} is on the team but has not linked their account`)}`);
|
|
347
|
+
result.skipped++;
|
|
348
|
+
}
|
|
349
|
+
for (const holder of plan.unknownHolders) {
|
|
350
|
+
print(` ${style.skip(`${holder.name ?? holder.member} holds ${role.name} but is not linked to anyone: left alone`)}`);
|
|
351
|
+
result.skipped++;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
// src/commands/notifications-sync-roles/notifications-sync-roles.ts
|
|
357
|
+
/** What a source provider needs to be able to do to feed a role sync, or the reason it cannot. */
|
|
358
|
+
function sourceProblem(source) {
|
|
359
|
+
if (!source) return "no `source` provider is available to read the team and the links file";
|
|
360
|
+
if (!source.teamMembers) return `the \`${source.providerName}\` provider cannot list team members`;
|
|
361
|
+
if (!source.readFile) return `the \`${source.providerName}\` provider cannot read the links file`;
|
|
362
|
+
}
|
|
363
|
+
/** Reads the links file; a file that does not exist yet is an empty one, a damaged one throws. */
|
|
364
|
+
async function readLinks(source, layout, org, provider) {
|
|
365
|
+
const { repo, path } = linksLocation(layout, org, provider);
|
|
366
|
+
const file = await source.readFile(path, repo);
|
|
367
|
+
if (!file) return EMPTY_LINKS;
|
|
83
368
|
try {
|
|
84
|
-
return
|
|
85
|
-
} catch {
|
|
86
|
-
|
|
369
|
+
return parseLinks(file.content);
|
|
370
|
+
} catch (err) {
|
|
371
|
+
throw new Error(`${repo}/${path}: ${errorMessage(err)}`, { cause: err });
|
|
87
372
|
}
|
|
88
373
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
374
|
+
// src/commands/project/plan-pull-request-status/plan-pull-request-status.ts
|
|
375
|
+
/**
|
|
376
|
+
* Decide the status an item's linked pull requests ask for (spec `tech-board-status-automation`, #2388). Pure: it reads
|
|
377
|
+
* one item and the template and touches nothing; status only, never priority or any other field.
|
|
378
|
+
*
|
|
379
|
+
* - an open linked pull request (a draft counts) puts the item in `active`;
|
|
380
|
+
* - an open one whose aggregate check is `success` puts it in `review`;
|
|
381
|
+
* - when the item is in `review` and no open pull request is green, a `failure` moves it back to `active`, while
|
|
382
|
+
* `pending` and `none` leave it, so a re-run after a push does not flicker the board;
|
|
383
|
+
* - no open pull request: no change (closed and merged ones are `planReconcile()`'s, through the closed issue).
|
|
384
|
+
*
|
|
385
|
+
* Left to `planReconcile()`, which runs first: a closed item, an item with an open blocker or in `blocked`, and an
|
|
386
|
+
* item with no status (reported there, not set). An item in `done` is left alone. Where the template has no status of
|
|
387
|
+
* the wanted category the rule comes back as `unresolved` and nothing is guessed; where a category has several statuses
|
|
388
|
+
* the first in template order is used. Applying the change and planning again gives no change.
|
|
389
|
+
*/
|
|
390
|
+
function planPullRequestStatus(item, template) {
|
|
391
|
+
if (!item.open || item.status === void 0 || item.blockedBy.length > 0) return void 0;
|
|
392
|
+
const category = template.statuses.find((s) => s.name === item.status)?.category ?? item.category;
|
|
393
|
+
if (category === "blocked" || category === "done") return void 0;
|
|
394
|
+
const open = (item.pullRequests ?? []).filter((pr) => pr.state === "open");
|
|
395
|
+
if (open.length === 0) return void 0;
|
|
396
|
+
let want;
|
|
397
|
+
let reason;
|
|
398
|
+
if (open.some((pr) => pr.checks === "success")) {
|
|
399
|
+
if (category !== "review") [want, reason] = ["review", "checks-green"];
|
|
400
|
+
} else if (category === "review") {
|
|
401
|
+
if (open.some((pr) => pr.checks === "failure")) [want, reason] = ["active", "checks-failed"];
|
|
402
|
+
} else if (category !== "active") [want, reason] = ["active", "pull-request-open"];
|
|
403
|
+
if (want === void 0 || reason === void 0) return void 0;
|
|
404
|
+
const to = template.statuses.find((s) => s.category === want)?.name;
|
|
405
|
+
if (to === void 0) return {
|
|
406
|
+
kind: "unresolved",
|
|
407
|
+
unresolved: {
|
|
408
|
+
key: item.key,
|
|
409
|
+
title: item.title,
|
|
410
|
+
category: want,
|
|
411
|
+
reason
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
return {
|
|
415
|
+
kind: "change",
|
|
416
|
+
change: {
|
|
417
|
+
key: item.key,
|
|
418
|
+
title: item.title,
|
|
419
|
+
from: item.status,
|
|
420
|
+
to,
|
|
421
|
+
category: want,
|
|
422
|
+
reason
|
|
423
|
+
}
|
|
424
|
+
};
|
|
98
425
|
}
|
|
426
|
+
// src/commands/project/plan-reconcile/plan-reconcile.ts
|
|
99
427
|
/**
|
|
100
|
-
*
|
|
428
|
+
* Decide the status changes that keep a board true (spec `command-project`, "Keeping a board true"). Pure: it reads
|
|
429
|
+
* the items and the template and touches nothing. Status only, never priority or any other field.
|
|
430
|
+
*
|
|
431
|
+
* - closed or merged, not in a `done` status: set to `done` (whatever the blockers say);
|
|
432
|
+
* - open with no status: not changed, listed in `unset` (it needs a decision, not a rule; this holds even when it has a
|
|
433
|
+
* blocker);
|
|
434
|
+
* - open with an open blocker, not in a `blocked` status: set to `blocked`;
|
|
435
|
+
* - open, in a `blocked` status, with no open blocker: set to `planned` (the status it held before is unknown).
|
|
101
436
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
437
|
+
* Where a category has several statuses the first in template order is used; where it has none the item is listed in
|
|
438
|
+
* `unresolved` and nothing is guessed. An item's category is read from the template by its status name, falling back
|
|
439
|
+
* to the one the provider reports. Applying the changes and planning again gives no change.
|
|
105
440
|
*/
|
|
106
|
-
function
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
441
|
+
function planReconcile(items, template) {
|
|
442
|
+
const target = (category) => template.statuses.find((s) => s.category === category)?.name;
|
|
443
|
+
const plan = {
|
|
444
|
+
changes: [],
|
|
445
|
+
unset: [],
|
|
446
|
+
unresolved: []
|
|
447
|
+
};
|
|
448
|
+
for (const item of items) {
|
|
449
|
+
const category = item.status === void 0 ? void 0 : template.statuses.find((s) => s.name === item.status)?.category ?? item.category;
|
|
450
|
+
let want;
|
|
451
|
+
let reason;
|
|
452
|
+
if (!item.open) {
|
|
453
|
+
if (category !== "done") [want, reason] = ["done", "closed"];
|
|
454
|
+
} else if (item.status === void 0) {
|
|
455
|
+
plan.unset.push(item);
|
|
456
|
+
continue;
|
|
457
|
+
} else if (item.blockedBy.length > 0) {
|
|
458
|
+
if (category !== "blocked") [want, reason] = ["blocked", "blocked"];
|
|
459
|
+
} else if (category === "blocked") [want, reason] = ["planned", "unblocked"];
|
|
460
|
+
if (want === void 0 || reason === void 0) continue;
|
|
461
|
+
const to = target(want);
|
|
462
|
+
if (to === void 0) {
|
|
463
|
+
plan.unresolved.push({
|
|
464
|
+
key: item.key,
|
|
465
|
+
title: item.title,
|
|
466
|
+
category: want,
|
|
467
|
+
reason
|
|
468
|
+
});
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
plan.changes.push({
|
|
472
|
+
key: item.key,
|
|
473
|
+
title: item.title,
|
|
474
|
+
...item.status !== void 0 ? { from: item.status } : {},
|
|
475
|
+
to,
|
|
476
|
+
category: want,
|
|
477
|
+
reason
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
return plan;
|
|
481
|
+
}
|
|
482
|
+
// src/commands/project/project-options/project-options.ts
|
|
483
|
+
/** Where a repo's own template files live unless the `templates` option says otherwise. */
|
|
484
|
+
const DEFAULT_TEMPLATES_DIR = ".holocron/projects";
|
|
485
|
+
/**
|
|
486
|
+
* Read the options of `providers.projects`: `org` (the owner, defaulting to `fallbackOwner`, the config's org), `boards`
|
|
487
|
+
* (a list of `{ template, name }`, nothing else about a board is written in the config) and `templates` (the directory
|
|
488
|
+
* of template files). Every problem is listed at once, and two boards with the same name are one.
|
|
489
|
+
*/
|
|
490
|
+
function resolveProjectOptions(options, fallbackOwner) {
|
|
491
|
+
const problems = [];
|
|
492
|
+
const org = options.org;
|
|
493
|
+
if (org !== void 0 && (typeof org !== "string" || org.trim() === "")) problems.push("org must be text");
|
|
494
|
+
const owner = typeof org === "string" && org.trim() !== "" ? org : fallbackOwner;
|
|
495
|
+
const dir = options.templates;
|
|
496
|
+
if (dir !== void 0 && (typeof dir !== "string" || dir.trim() === "")) problems.push("templates must be the path of a directory");
|
|
497
|
+
const boards = [];
|
|
498
|
+
if (options.boards !== void 0) {
|
|
499
|
+
if (!Array.isArray(options.boards)) problems.push("boards must be a list of { template, name }");
|
|
500
|
+
else {
|
|
501
|
+
const seen = /* @__PURE__ */ new Set();
|
|
502
|
+
options.boards.forEach((entry, i) => {
|
|
503
|
+
const where = `boards[${i}]`;
|
|
504
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) {
|
|
505
|
+
problems.push(`${where} must be { template, name }`);
|
|
506
|
+
return;
|
|
507
|
+
}
|
|
508
|
+
const { template, name } = entry;
|
|
509
|
+
if (typeof template !== "string" || template.trim() === "") problems.push(`${where} needs a template`);
|
|
510
|
+
if (typeof name !== "string" || name.trim() === "") problems.push(`${where} needs a name`);
|
|
511
|
+
if (typeof template !== "string" || typeof name !== "string" || !template.trim() || !name.trim()) return;
|
|
512
|
+
if (seen.has(name)) problems.push(`${where}: the board name "${name}" is used twice`);
|
|
513
|
+
seen.add(name);
|
|
514
|
+
boards.push({
|
|
515
|
+
template,
|
|
516
|
+
name
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if (problems.length > 0) return {
|
|
522
|
+
ok: false,
|
|
523
|
+
problems
|
|
524
|
+
};
|
|
525
|
+
return {
|
|
526
|
+
ok: true,
|
|
527
|
+
options: {
|
|
528
|
+
owner,
|
|
529
|
+
boards,
|
|
530
|
+
templatesDir: typeof dir === "string" ? dir : DEFAULT_TEMPLATES_DIR
|
|
531
|
+
}
|
|
113
532
|
};
|
|
114
533
|
}
|
|
115
|
-
|
|
116
|
-
|
|
534
|
+
// src/commands/project/templates/builtin-templates/builtin-templates.ts
|
|
535
|
+
/** The templates that ship in `@theholocron/cli`, by name. A repo's own template with the same name replaces one. */
|
|
536
|
+
const BUILTIN_TEMPLATES = {
|
|
537
|
+
roadmap: {
|
|
538
|
+
name: "roadmap",
|
|
539
|
+
statuses: [
|
|
540
|
+
{
|
|
541
|
+
name: "Someday",
|
|
542
|
+
category: "backlog",
|
|
543
|
+
color: "GRAY",
|
|
544
|
+
description: "Idea or future consideration, not yet planned"
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
name: "Todo",
|
|
548
|
+
category: "planned",
|
|
549
|
+
color: "BLUE",
|
|
550
|
+
description: "Planned and ready to be worked on"
|
|
551
|
+
},
|
|
552
|
+
{
|
|
553
|
+
name: "In Progress",
|
|
554
|
+
category: "active",
|
|
555
|
+
color: "YELLOW",
|
|
556
|
+
description: "Currently being worked on"
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
name: "In Review",
|
|
560
|
+
category: "review",
|
|
561
|
+
color: "ORANGE",
|
|
562
|
+
description: "Pull request is green and waiting on review"
|
|
563
|
+
},
|
|
564
|
+
{
|
|
565
|
+
name: "Blocked",
|
|
566
|
+
category: "blocked",
|
|
567
|
+
color: "RED",
|
|
568
|
+
description: "Waiting on another issue or an outside change"
|
|
569
|
+
},
|
|
570
|
+
{
|
|
571
|
+
name: "Done",
|
|
572
|
+
category: "done",
|
|
573
|
+
color: "GREEN",
|
|
574
|
+
description: "Completed"
|
|
575
|
+
}
|
|
576
|
+
],
|
|
577
|
+
fields: [{
|
|
578
|
+
name: "Priority",
|
|
579
|
+
type: "single_select",
|
|
580
|
+
options: [
|
|
581
|
+
"1 · Now",
|
|
582
|
+
"2 · Next",
|
|
583
|
+
"3 · Process"
|
|
584
|
+
]
|
|
585
|
+
}],
|
|
586
|
+
views: [
|
|
587
|
+
{
|
|
588
|
+
name: "Active",
|
|
589
|
+
layout: "board",
|
|
590
|
+
filter: "-status:Someday -status:Done",
|
|
591
|
+
default: true
|
|
592
|
+
},
|
|
593
|
+
{
|
|
594
|
+
name: "Backlog",
|
|
595
|
+
layout: "board",
|
|
596
|
+
filter: "status:Someday"
|
|
597
|
+
},
|
|
598
|
+
{
|
|
599
|
+
name: "Done",
|
|
600
|
+
layout: "table",
|
|
601
|
+
filter: "status:Done"
|
|
602
|
+
}
|
|
603
|
+
],
|
|
604
|
+
rules: ["Auto-add sub-issues to project"]
|
|
605
|
+
},
|
|
606
|
+
sprint: {
|
|
607
|
+
name: "sprint",
|
|
608
|
+
statuses: [
|
|
609
|
+
{
|
|
610
|
+
name: "Todo",
|
|
611
|
+
category: "planned",
|
|
612
|
+
color: "BLUE"
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
name: "In Progress",
|
|
616
|
+
category: "active",
|
|
617
|
+
color: "YELLOW"
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
name: "In Review",
|
|
621
|
+
category: "review",
|
|
622
|
+
color: "ORANGE"
|
|
623
|
+
},
|
|
624
|
+
{
|
|
625
|
+
name: "Blocked",
|
|
626
|
+
category: "blocked",
|
|
627
|
+
color: "RED"
|
|
628
|
+
},
|
|
629
|
+
{
|
|
630
|
+
name: "Done",
|
|
631
|
+
category: "done",
|
|
632
|
+
color: "GREEN"
|
|
633
|
+
}
|
|
634
|
+
],
|
|
635
|
+
fields: [{
|
|
636
|
+
name: "Sprint",
|
|
637
|
+
type: "text"
|
|
638
|
+
}],
|
|
639
|
+
views: [{
|
|
640
|
+
name: "Active",
|
|
641
|
+
layout: "table",
|
|
642
|
+
filter: "-status:Done",
|
|
643
|
+
default: true
|
|
644
|
+
}, {
|
|
645
|
+
name: "Done",
|
|
646
|
+
layout: "table",
|
|
647
|
+
filter: "status:Done"
|
|
648
|
+
}]
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
// src/commands/setup/derived-properties/derived-properties.ts
|
|
117
652
|
/**
|
|
118
653
|
* Repo archetype, in priority order:
|
|
119
654
|
* 1. `*-template` repo name → `template` (independent of package shape).
|
|
@@ -153,6 +688,7 @@ function deriveProfile(input) {
|
|
|
153
688
|
if (pkg?.private) return "app";
|
|
154
689
|
return "library";
|
|
155
690
|
}
|
|
691
|
+
/** The framework and build-tool names `deriveStack()` can detect, in the order it lists them; `StackName` is derived from it. */
|
|
156
692
|
const KNOWN_STACK_DEPS = [
|
|
157
693
|
"next",
|
|
158
694
|
"vite",
|
|
@@ -192,6 +728,7 @@ function deriveCapabilities(providers) {
|
|
|
192
728
|
* a Phase B (GitHub App) refinement once it can post *why* on a check run.
|
|
193
729
|
*/
|
|
194
730
|
const REQUIRED_BASELINE = ["source", "ci"];
|
|
731
|
+
/** Whether a repo's capabilities include the required baseline (`source` and `ci`); `non-compliant` means drift. */
|
|
195
732
|
function deriveCompliance(capabilities) {
|
|
196
733
|
return REQUIRED_BASELINE.every((key) => capabilities.includes(key)) ? "compliant" : "non-compliant";
|
|
197
734
|
}
|
|
@@ -213,287 +750,273 @@ function missingCapabilities(capabilities) {
|
|
|
213
750
|
*/
|
|
214
751
|
async function readWorkspacePackageJsons(repoRoot, workspacePackages) {
|
|
215
752
|
const results = [];
|
|
216
|
-
for (const { slug, dir = "packages" } of workspacePackages)
|
|
217
|
-
const
|
|
218
|
-
results.push(
|
|
219
|
-
}
|
|
753
|
+
for (const { slug, dir = "packages", path } of workspacePackages) {
|
|
754
|
+
const pkg = await readPackageJson(join(repoRoot, path ?? join(dir, slug)));
|
|
755
|
+
if (pkg) results.push(pkg);
|
|
756
|
+
}
|
|
220
757
|
return results;
|
|
221
758
|
}
|
|
222
|
-
|
|
223
|
-
//#region src/config/config.ts
|
|
224
|
-
var ConfigError = class extends Error {
|
|
225
|
-
name = "ConfigError";
|
|
226
|
-
};
|
|
227
|
-
const PLUGIN_PREFIX = "@theholocron/holocron-plugin-";
|
|
228
|
-
const COMMUNITY_PREFIX = "holocron-plugin-";
|
|
759
|
+
// src/commands/setup/labels.ts
|
|
229
760
|
/**
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* is how third-party plugins published outside the org work.
|
|
761
|
+
* The labels every repository gets from `setup`, with their GitHub colours (hex, no `#`) and descriptions. A
|
|
762
|
+
* plugin that makes labels of its own, such as Linear's setup, takes the colour of the one with the same name.
|
|
233
763
|
*/
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
764
|
+
const CANONICAL_LABELS = [
|
|
765
|
+
{
|
|
766
|
+
name: "bug",
|
|
767
|
+
color: "d73a4a",
|
|
768
|
+
description: "Something isn't working"
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
name: "chore",
|
|
772
|
+
color: "ededed",
|
|
773
|
+
description: "Maintenance, no user-facing change"
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
name: "ci",
|
|
777
|
+
color: "0075ca",
|
|
778
|
+
description: "CI/CD pipeline changes"
|
|
779
|
+
},
|
|
780
|
+
{
|
|
781
|
+
name: "dependencies",
|
|
782
|
+
color: "0366d6",
|
|
783
|
+
description: "Dependency update"
|
|
784
|
+
},
|
|
785
|
+
{
|
|
786
|
+
name: "documentation",
|
|
787
|
+
color: "0075ca",
|
|
788
|
+
description: "Documentation only"
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
name: "duplicate",
|
|
792
|
+
color: "cfd3d7",
|
|
793
|
+
description: "Already reported"
|
|
794
|
+
},
|
|
795
|
+
{
|
|
796
|
+
name: "enhancement",
|
|
797
|
+
color: "a2eeef",
|
|
798
|
+
description: "New feature or request"
|
|
799
|
+
},
|
|
800
|
+
{
|
|
801
|
+
name: "good first issue",
|
|
802
|
+
color: "7057ff",
|
|
803
|
+
description: "Good for newcomers"
|
|
804
|
+
},
|
|
805
|
+
{
|
|
806
|
+
name: "help wanted",
|
|
807
|
+
color: "008672",
|
|
808
|
+
description: "Extra attention needed"
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
name: "invalid",
|
|
812
|
+
color: "e4e669",
|
|
813
|
+
description: "Doesn't seem right"
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
name: "performance",
|
|
817
|
+
color: "fbca04",
|
|
818
|
+
description: "Performance improvement"
|
|
819
|
+
},
|
|
820
|
+
{
|
|
821
|
+
name: "question",
|
|
822
|
+
color: "d876e3",
|
|
823
|
+
description: "Further information requested"
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
name: "refactor",
|
|
827
|
+
color: "cfd3d7",
|
|
828
|
+
description: "Code restructuring"
|
|
829
|
+
},
|
|
830
|
+
{
|
|
831
|
+
name: "released",
|
|
832
|
+
color: "ededed",
|
|
833
|
+
description: "Included in a release"
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
name: "test",
|
|
837
|
+
color: "bfd4f2",
|
|
838
|
+
description: "Test-related changes"
|
|
839
|
+
},
|
|
840
|
+
{
|
|
841
|
+
name: "triage",
|
|
842
|
+
color: "e4e669",
|
|
843
|
+
description: "Needs investigation"
|
|
844
|
+
},
|
|
845
|
+
{
|
|
846
|
+
name: "wontfix",
|
|
847
|
+
color: "ffffff",
|
|
848
|
+
description: "Won't be addressed"
|
|
270
849
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
if (cardinality === "single") throw new ConfigError(`\`${key}\` accepts exactly one provider; got a multi-provider list with ${raw.length} entries`);
|
|
283
|
-
return {
|
|
284
|
-
cardinality: "many",
|
|
285
|
-
tuples: raw.map((entry, idx) => {
|
|
286
|
-
if (typeof entry === "string") return normalizeEntry(entry);
|
|
287
|
-
if (isOptionsTuple(entry)) return normalizeEntry(entry);
|
|
288
|
-
throw new ConfigError(`\`${key}[${idx}]\` must be a provider string or [provider, options] tuple`);
|
|
289
|
-
})
|
|
290
|
-
};
|
|
850
|
+
];
|
|
851
|
+
// src/commands/token-rotation/token-rotation.ts
|
|
852
|
+
/** The rotation policy of a token that declares none: a token is due after 90 days, and an expiry is flagged 14 days ahead. */
|
|
853
|
+
const DEFAULT_TOKEN_ROTATION = {
|
|
854
|
+
maxAgeDays: 90,
|
|
855
|
+
warnDays: 14
|
|
856
|
+
};
|
|
857
|
+
const DAY_MS = 864e5;
|
|
858
|
+
/** The whole days from `from` to `to`, rounded down (negative once `to` is past). */
|
|
859
|
+
function daysBetween(from, to) {
|
|
860
|
+
return Math.floor((to.getTime() - from.getTime()) / DAY_MS);
|
|
291
861
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
for (const required of REQUIRED_CAPABILITIES) if (!providers[required]) throw new ConfigError(`required capability \`${required}\` is missing from providers`);
|
|
301
|
-
let docs;
|
|
302
|
-
if (raw.docs !== void 0) {
|
|
303
|
-
if (!raw.docs.build) throw new ConfigError("`docs.build` is required when `docs` is set");
|
|
304
|
-
docs = raw.docs;
|
|
305
|
-
}
|
|
306
|
-
const homepage = raw.homepage ?? (docs?.domain ? `https://${docs.domain}/` : void 0);
|
|
307
|
-
return {
|
|
308
|
-
name: raw.name,
|
|
309
|
-
description: raw.description,
|
|
310
|
-
homepage,
|
|
311
|
-
org: raw.org,
|
|
312
|
-
domain: raw.domain,
|
|
313
|
-
repo: raw.repo,
|
|
314
|
-
tasks: raw.tasks,
|
|
315
|
-
syncScripts: raw.syncScripts,
|
|
316
|
-
holocronScript: raw.holocronScript,
|
|
317
|
-
extraRequiredChecks: raw.extraRequiredChecks,
|
|
318
|
-
hooks: raw.hooks,
|
|
319
|
-
providers,
|
|
320
|
-
apps: raw.apps ?? [],
|
|
321
|
-
doctor: raw.doctor ?? {},
|
|
322
|
-
agent: raw.agent,
|
|
323
|
-
skills: raw.skills,
|
|
324
|
-
docs,
|
|
325
|
-
env: raw.env,
|
|
326
|
-
log: raw.log,
|
|
327
|
-
telemetry: raw.telemetry
|
|
328
|
-
};
|
|
862
|
+
/** `2026-11-13` of a valid date. */
|
|
863
|
+
const day = (d) => d.toISOString().slice(0, 10);
|
|
864
|
+
/** A valid `Date` of an ISO string, or `undefined` when there is none or it does not parse. */
|
|
865
|
+
function parse(value) {
|
|
866
|
+
if (value === void 0) return void 0;
|
|
867
|
+
const date = new Date(value);
|
|
868
|
+
return Number.isNaN(date.getTime()) ? void 0 : date;
|
|
329
869
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
870
|
+
/**
|
|
871
|
+
* Rows saying whether a token is due for rotation, from what its provider exposes. Provider-neutral: a token probe reads
|
|
872
|
+
* the lifetime however its provider offers it and hands it here, with the layer's `rotation` from `tokenExpectations()`.
|
|
873
|
+
* `lifetime` is `undefined` when the provider exposes nothing (the row says so rather than passing), and a date the
|
|
874
|
+
* provider gave that does not parse is an `info` row, never a pass. An expired or near-expiry token fails, and so does
|
|
875
|
+
* one older than `maxAgeDays`. Only dates are printed, never the token.
|
|
876
|
+
*/
|
|
877
|
+
function tokenRotationRows(lifetime, rotation, now) {
|
|
878
|
+
if (!lifetime) return [{
|
|
879
|
+
status: "info",
|
|
880
|
+
label: "rotation",
|
|
881
|
+
detail: `the provider does not expose this token's age or expiry; rotate it by hand every ${rotation.maxAgeDays} days`
|
|
882
|
+
}];
|
|
883
|
+
const rows = [];
|
|
884
|
+
const expires = parse(lifetime.expiresAt);
|
|
885
|
+
if (lifetime.expiresAt !== void 0 && !expires) rows.push({
|
|
886
|
+
status: "info",
|
|
887
|
+
label: "expiry",
|
|
888
|
+
detail: "the provider's expiry date could not be read"
|
|
889
|
+
});
|
|
890
|
+
else if (expires) {
|
|
891
|
+
const left = daysBetween(now, expires);
|
|
892
|
+
if (expires.getTime() <= now.getTime()) rows.push({
|
|
893
|
+
status: "fail",
|
|
894
|
+
label: "expiry",
|
|
895
|
+
detail: `expired on ${day(expires)}`
|
|
896
|
+
});
|
|
897
|
+
else if (left < rotation.warnDays) rows.push({
|
|
898
|
+
status: "fail",
|
|
899
|
+
label: "expiry",
|
|
900
|
+
detail: `expires on ${day(expires)} (${left} days left, warns under ${rotation.warnDays}); rotate it`
|
|
901
|
+
});
|
|
902
|
+
else rows.push({
|
|
903
|
+
status: "ok",
|
|
904
|
+
label: "expiry",
|
|
905
|
+
detail: `expires on ${day(expires)} (${left} days left)`
|
|
906
|
+
});
|
|
907
|
+
} else rows.push({
|
|
908
|
+
status: "info",
|
|
909
|
+
label: "expiry",
|
|
910
|
+
detail: "the token has no expiry"
|
|
911
|
+
});
|
|
912
|
+
const created = parse(lifetime.createdAt);
|
|
913
|
+
if (lifetime.createdAt !== void 0 && !created) rows.push({
|
|
914
|
+
status: "info",
|
|
915
|
+
label: "age",
|
|
916
|
+
detail: "the provider's creation date could not be read"
|
|
917
|
+
});
|
|
918
|
+
else if (created) {
|
|
919
|
+
const age = daysBetween(created, now);
|
|
920
|
+
const due = age > rotation.maxAgeDays;
|
|
921
|
+
rows.push({
|
|
922
|
+
status: due ? "fail" : "ok",
|
|
923
|
+
label: "age",
|
|
924
|
+
detail: due ? `${age} days old since ${day(created)}, over the ${rotation.maxAgeDays} days allowed; rotate it` : `${age} days old since ${day(created)} (rotate after ${rotation.maxAgeDays})`
|
|
925
|
+
});
|
|
926
|
+
} else rows.push({
|
|
927
|
+
status: "info",
|
|
928
|
+
label: "age",
|
|
929
|
+
detail: "the provider does not say when the token was made"
|
|
930
|
+
});
|
|
931
|
+
return rows;
|
|
334
932
|
}
|
|
933
|
+
// src/commands/token-expectations/token-expectations.ts
|
|
335
934
|
/**
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*
|
|
339
|
-
* - Accepts individual capabilities or nested arrays (for bundle presets).
|
|
340
|
-
* - Deduplicates by `id` — when the same ID appears more than once, the last
|
|
341
|
-
* occurrence wins. This lets callers override bundle defaults by listing an
|
|
342
|
-
* explicit capability after the bundle.
|
|
343
|
-
* - Validates all `requires` at call time and throws `ConfigError` if any are
|
|
344
|
-
* unmet, listing every missing dependency in a single message.
|
|
345
|
-
*
|
|
346
|
-
* @example
|
|
347
|
-
* // docs-only site — no typecheck
|
|
348
|
-
* const preset = compose(node(), docs());
|
|
349
|
-
*
|
|
350
|
-
* // library with docs
|
|
351
|
-
* const preset = compose(node(), typecheck(), docs());
|
|
352
|
-
*
|
|
353
|
-
* // nextjs() is a bundle that returns Capability[]
|
|
354
|
-
* const preset = compose(node(), nextjs());
|
|
935
|
+
* Reads what a plugin's tokens declare (`PluginToken.expect`) as one entry per token and layer that holds it, in the
|
|
936
|
+
* order of `ENVIRONMENT_LAYERS`. The one reader the token probes, the doctor and the docs check share, so none of them
|
|
937
|
+
* walks the declaration itself. A token with no `expect` yields nothing; a layer no token holds is never listed.
|
|
355
938
|
*/
|
|
356
|
-
function
|
|
357
|
-
const
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
let repo = {};
|
|
379
|
-
for (const cap of caps) {
|
|
380
|
-
if (!cap.repo) continue;
|
|
381
|
-
const { properties, topics, teams, ...scalars } = cap.repo;
|
|
382
|
-
repo = {
|
|
383
|
-
...repo,
|
|
384
|
-
...scalars
|
|
385
|
-
};
|
|
386
|
-
if (properties) repo.properties = {
|
|
387
|
-
...repo.properties,
|
|
388
|
-
...properties
|
|
389
|
-
};
|
|
390
|
-
if (topics) {
|
|
391
|
-
const merged = /* @__PURE__ */ new Set([...repo.topics ?? [], ...topics]);
|
|
392
|
-
repo.topics = [...merged];
|
|
393
|
-
}
|
|
394
|
-
if (teams) {
|
|
395
|
-
const teamMap = new Map((repo.teams ?? []).map((t) => [typeof t === "string" ? t : t.slug, t]));
|
|
396
|
-
for (const t of teams) teamMap.set(typeof t === "string" ? t : t.slug, t);
|
|
397
|
-
repo.teams = [...teamMap.values()];
|
|
939
|
+
function tokenExpectations(tokens, filter = {}) {
|
|
940
|
+
const found = [];
|
|
941
|
+
for (const token of tokens) {
|
|
942
|
+
if (!token.expect || filter.envName !== void 0 && token.envName !== filter.envName) continue;
|
|
943
|
+
const { layers = [], permissions = {} } = token.expect;
|
|
944
|
+
for (const layer of ENVIRONMENT_LAYERS) {
|
|
945
|
+
if (filter.layer !== void 0 && filter.layer !== layer) continue;
|
|
946
|
+
const rules = permissions[layer];
|
|
947
|
+
if (!rules && !layers.includes(layer)) continue;
|
|
948
|
+
const entries = Object.entries(rules ?? {});
|
|
949
|
+
found.push({
|
|
950
|
+
envName: token.envName,
|
|
951
|
+
layer,
|
|
952
|
+
rules: rules ?? {},
|
|
953
|
+
required: entries.filter(([, rule]) => rule === "required").map(([name]) => name),
|
|
954
|
+
absent: entries.filter(([, rule]) => rule === "absent").map(([name]) => name),
|
|
955
|
+
rotation: {
|
|
956
|
+
...DEFAULT_TOKEN_ROTATION,
|
|
957
|
+
...token.expect.rotation
|
|
958
|
+
}
|
|
959
|
+
});
|
|
398
960
|
}
|
|
399
961
|
}
|
|
400
|
-
|
|
401
|
-
let domain;
|
|
402
|
-
let docs;
|
|
403
|
-
for (const cap of caps) {
|
|
404
|
-
if (cap.org !== void 0) org = cap.org;
|
|
405
|
-
if (cap.domain !== void 0) domain = cap.domain;
|
|
406
|
-
if (cap.docs !== void 0) docs = cap.docs;
|
|
407
|
-
}
|
|
408
|
-
return {
|
|
409
|
-
tasks: [...taskMap.values()],
|
|
410
|
-
providers,
|
|
411
|
-
repo,
|
|
412
|
-
extraRequiredChecks,
|
|
413
|
-
...org !== void 0 ? { org } : {},
|
|
414
|
-
...domain !== void 0 ? { domain } : {},
|
|
415
|
-
...docs !== void 0 ? { docs } : {}
|
|
416
|
-
};
|
|
962
|
+
return found;
|
|
417
963
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
964
|
+
// src/commands/auth-export/stdout-kind/stdout-kind.ts
|
|
965
|
+
/**
|
|
966
|
+
* What file descriptor `fd` (stdout) is, for deciding where tokens may go: a `terminal`, a `pipe` (a FIFO, or the
|
|
967
|
+
* socket some shells and runners use for one), or `other` (a regular file, a device, or anything that cannot be
|
|
968
|
+
* inspected). Only a pipe is safe to write the lines to, so anything unknown is `other`.
|
|
969
|
+
*/
|
|
970
|
+
function stdoutKind(isTerminal, fd = 1, stat = fstatSync) {
|
|
971
|
+
if (isTerminal) return "terminal";
|
|
972
|
+
try {
|
|
973
|
+
const s = stat(fd);
|
|
974
|
+
return s.isFIFO() || s.isSocket() ? "pipe" : "other";
|
|
975
|
+
} catch {
|
|
976
|
+
return "other";
|
|
977
|
+
}
|
|
422
978
|
}
|
|
423
|
-
|
|
424
|
-
//#region src/config/load-config.ts
|
|
979
|
+
// src/commands/secrets-sync/resolve-environment-id/resolve-environment-id.ts
|
|
425
980
|
/**
|
|
426
|
-
* `holocron.
|
|
427
|
-
*
|
|
428
|
-
*
|
|
429
|
-
*
|
|
430
|
-
* holocron-specific parts: filling `name` / `repo.name` defaults and
|
|
431
|
-
* running the config through `resolveConfig`.
|
|
981
|
+
* The vault Environment `holocron sync secrets --env <environment>` reads. A layer word (`local`, `dev`, `ci`, `prod`) is the
|
|
982
|
+
* Environment of that layer of this repository, `<org/repo> - <layer>`; any other text is a literal Environment name.
|
|
983
|
+
* A literal name wins only when it is not exactly a layer word, so an Environment that is itself called `prod` cannot be
|
|
984
|
+
* addressed by that name (spec `tech-environment-layers`, #2069).
|
|
432
985
|
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
986
|
+
* @param id - The `--env` value the user gave.
|
|
987
|
+
* @param input - Where the repository is (its `origin` remote is read there), and optionally how to read it.
|
|
988
|
+
* @throws {ConfigError} For a layer word when the remote cannot be read (the message names the `environment` option).
|
|
435
989
|
*/
|
|
436
|
-
|
|
990
|
+
async function resolveEnvironmentId(id, input) {
|
|
991
|
+
if (!isEnvironmentLayer(id)) return id;
|
|
992
|
+
return layerEnvironment(await repoSlug(input.repoRoot, input.gitExec), id);
|
|
993
|
+
}
|
|
994
|
+
// src/private-dir/ignore-advice/ignore-advice.ts
|
|
995
|
+
/** The line that says how to fix a credentials path the version control ignore rules do not cover. */
|
|
996
|
+
function ignoreAdvice(isDefault, choose) {
|
|
997
|
+
return isDefault ? "the private directory's ignore rule is missing: run `holocron sync` to add it" : `add it to .gitignore, or ${choose}`;
|
|
998
|
+
}
|
|
999
|
+
/** The file `export tokens` and `new github-app` write by default, relative to the repository root. */
|
|
1000
|
+
const PRIVATE_CREDENTIALS_FILE = `.holocron/.private/.credentials`;
|
|
1001
|
+
// src/private-dir/resolve-credentials-file/resolve-credentials-file.ts
|
|
437
1002
|
/**
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
1003
|
+
* The credentials file for a command: `file` (relative to `base`) when given, else `.holocron/.private/.credentials`
|
|
1004
|
+
* under `base`. The default's directory is created when missing (owner-only), because the ignore check can only ask
|
|
1005
|
+
* about a path whose directory exists and the file cannot be written without it.
|
|
441
1006
|
*/
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
1007
|
+
function resolveCredentialsFile(base, file, makeDir = (dir) => void mkdirSync(dir, {
|
|
1008
|
+
recursive: true,
|
|
1009
|
+
mode: 448
|
|
1010
|
+
})) {
|
|
1011
|
+
if (file) return {
|
|
1012
|
+
path: resolve(base, file),
|
|
1013
|
+
isDefault: false
|
|
1014
|
+
};
|
|
1015
|
+
const path = resolve(base, PRIVATE_CREDENTIALS_FILE);
|
|
1016
|
+
makeDir(dirname(path));
|
|
448
1017
|
return {
|
|
449
|
-
|
|
450
|
-
|
|
1018
|
+
path,
|
|
1019
|
+
isDefault: true
|
|
451
1020
|
};
|
|
452
1021
|
}
|
|
453
|
-
|
|
454
|
-
const result = { ...raw };
|
|
455
|
-
if (!result.name) result.name = await readPackageJsonName(configDir) ?? basename(configDir);
|
|
456
|
-
if (result.repo && !result.repo.name) {
|
|
457
|
-
const repoName = await readGitRemote(configDir);
|
|
458
|
-
if (repoName) result.repo = {
|
|
459
|
-
...result.repo,
|
|
460
|
-
name: repoName
|
|
461
|
-
};
|
|
462
|
-
}
|
|
463
|
-
const manifest = await loadTasksConfig(configDir);
|
|
464
|
-
if (manifest.tasks) result.tasks = manifest.tasks;
|
|
465
|
-
if (manifest.syncScripts !== void 0) result.syncScripts = manifest.syncScripts;
|
|
466
|
-
if (manifest.holocronScript !== void 0) result.holocronScript = manifest.holocronScript;
|
|
467
|
-
if (manifest.hooks !== void 0) result.hooks = manifest.hooks;
|
|
468
|
-
if (manifest.extraRequiredChecks) result.extraRequiredChecks = [...result.extraRequiredChecks ?? [], ...manifest.extraRequiredChecks];
|
|
469
|
-
return result;
|
|
470
|
-
}
|
|
471
|
-
async function readPackageJsonName(dir) {
|
|
472
|
-
try {
|
|
473
|
-
const content = await readFile(join(dir, "package.json"), "utf8");
|
|
474
|
-
const pkg = JSON.parse(content);
|
|
475
|
-
return typeof pkg.name === "string" ? pkg.name.replace(/^@[^/]+\//, "") : void 0;
|
|
476
|
-
} catch {
|
|
477
|
-
return;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
async function readGitRemote(dir) {
|
|
481
|
-
try {
|
|
482
|
-
const { stdout } = await execFileAsync("git", [
|
|
483
|
-
"remote",
|
|
484
|
-
"get-url",
|
|
485
|
-
"origin"
|
|
486
|
-
], { cwd: dir });
|
|
487
|
-
return parseGitRemoteUrl(stdout.trim());
|
|
488
|
-
} catch {
|
|
489
|
-
return;
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
function parseGitRemoteUrl(url) {
|
|
493
|
-
const httpsMatch = url.match(/github\.com\/([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
494
|
-
if (httpsMatch) return httpsMatch[1];
|
|
495
|
-
const sshMatch = url.match(/github\.com:([^/]+\/[^/]+?)(?:\.git)?$/);
|
|
496
|
-
if (sshMatch) return sshMatch[1];
|
|
497
|
-
}
|
|
498
|
-
//#endregion
|
|
499
|
-
export { AuthError, CARDINALITY, ConfigError, ConfigFileError, ProviderApiError, REQUIRED_CAPABILITIES, WebhookVerificationError, compose, createFeatureResolver, createResolveToken, createRestClient, defineConfig, deleteToken, deriveCapabilities, deriveCompliance, deriveProfile, deriveStack, getToken, isMulti, listStoredProviders, loadConfig, missingCapabilities, readWorkspacePackageJsons, resolveConfig, resolveEntry, resolvePluginPackage, setToken };
|
|
1022
|
+
export { AuthError, BUILTIN_TEMPLATES, CANONICAL_LABELS, CARDINALITY, ConfigError, ConfigFileError, DEFAULT_TEMPLATES_DIR, DEFAULT_TOKEN_ROTATION, ElevationRequiredError, HOLOCRON_AREAS, KNOWN_STACK_DEPS, MissingTokenError, PRIVATE_CREDENTIALS_FILE, ProviderApiError, REQUIRED_CAPABILITIES, SHARED_AREAS, WebhookVerificationError, compose, connectionProbe, coverageExpectations, createFeatureResolver, createResolveToken, createRestClient, credentialsEnvironment, defineConfig, deriveCapabilities, deriveCompliance, deriveProfile, deriveStack, ignoreAdvice, isMulti, keyring, loadConfig, missingCapabilities, orderKeys, pickByCreation, placeAreas, planPullRequestStatus, planReconcile, readKeysLimited, readLinks, readWorkspacePackageJsons, reportProgress, resolveConfig, resolveCredentialsFile, resolveEntry, resolveEnvironmentId, resolvePluginPackage, resolveProjectOptions, resolveValue, roleTeamProblem, sourceProblem, stdoutKind, syncRoles, tokenExpectations, tokenRotationRows };
|