@installagent/sdk 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-check.d.ts +32 -0
- package/dist/access-check.js +339 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/portal-admin.d.ts +26 -0
- package/dist/portal-admin.js +24 -0
- package/dist/portal-sync-builds.d.ts +157 -0
- package/dist/portal-sync-builds.js +424 -0
- package/dist/pr-open.d.ts +3 -1
- package/dist/pr-open.js +9 -0
- package/dist/template-sync.js +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ExecFileFn } from "./exec.js";
|
|
2
|
+
import { type PlatformInfo } from "./platform.js";
|
|
3
|
+
export type AccessService = "google-service-account" | "google-oauth" | "google-oauth-client" | "slack" | "github";
|
|
4
|
+
export type AccessStatus = "valid" | "rejected" | "unverified" | "skipped";
|
|
5
|
+
export interface AccessCheckItem {
|
|
6
|
+
/** The vault item's title — a name, never a value. */
|
|
7
|
+
title: string;
|
|
8
|
+
service: AccessService | null;
|
|
9
|
+
status: AccessStatus;
|
|
10
|
+
detail: string;
|
|
11
|
+
}
|
|
12
|
+
export interface AccessCheckResult {
|
|
13
|
+
slug: string;
|
|
14
|
+
vault: string;
|
|
15
|
+
items: AccessCheckItem[];
|
|
16
|
+
counts: Record<AccessStatus, number>;
|
|
17
|
+
}
|
|
18
|
+
export interface AccessCheckOptions {
|
|
19
|
+
workspaceDir?: string;
|
|
20
|
+
/** Test this vault instead of the one in CLIENT.md (use when CLIENT.md names a vault that does not exist). */
|
|
21
|
+
vault?: string;
|
|
22
|
+
execFileImpl?: ExecFileFn;
|
|
23
|
+
fetchImpl?: typeof fetch;
|
|
24
|
+
now?: () => number;
|
|
25
|
+
platform?: PlatformInfo;
|
|
26
|
+
}
|
|
27
|
+
/** The vault named in the client's CLIENT.md, else the portal's default name. */
|
|
28
|
+
export declare function clientVaultFor(slug: string, workspaceDir: string): string;
|
|
29
|
+
/** What a key is, from the shape of its value. Null when no probe exists for it. */
|
|
30
|
+
export declare function classifyKey(value: string): AccessService | null;
|
|
31
|
+
/** Test every API-key item in the client's vault. Logins and unknown keys are listed, never read or tested. */
|
|
32
|
+
export declare function accessCheck(slug: string, options?: AccessCheckOptions): Promise<AccessCheckResult>;
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
import { readManifestKey } from "./client-manifest.js";
|
|
4
|
+
import { findWorkspaceRoot } from "./env-file.js";
|
|
5
|
+
import { execFailureDetail, execFileAsync } from "./exec.js";
|
|
6
|
+
import { GoogleServiceAccountAuthError, getServiceAccountAccessToken, } from "./google-service-account.js";
|
|
7
|
+
import { SLUG_PATTERN } from "./new-client.js";
|
|
8
|
+
import { opReachable } from "./op-cli.js";
|
|
9
|
+
import { detectPlatformInfo } from "./platform.js";
|
|
10
|
+
// `ia access check <slug>`: does each key the client handed over still work?
|
|
11
|
+
// The access tracker says HAVE from a person's word; nothing tested it, so a
|
|
12
|
+
// token that expired or was revoked still read HAVE. This runs ONE read-only
|
|
13
|
+
// call per key in the client's 1Password vault (the same idea as the live
|
|
14
|
+
// checks in `ia doctor`) and reports valid, rejected or unverified.
|
|
15
|
+
//
|
|
16
|
+
// Secret handling: only the vault's item list (titles, ids, categories) is
|
|
17
|
+
// read in bulk. The `credential` field is read from API-key items, and a small
|
|
18
|
+
// .json file from Document items (where `ia secrets mint` stores a Google
|
|
19
|
+
// key). A value is kept in a local variable, sent to its own service, and
|
|
20
|
+
// dropped. A result holds
|
|
21
|
+
// fixed words and, at most, a workspace name or an expiry date. Logins
|
|
22
|
+
// (username + password) are never read: no safe test exists for them.
|
|
23
|
+
const CHECK_TIMEOUT_MS = 5000;
|
|
24
|
+
// A service-account key file is about 2.4 KB; anything past this is not one.
|
|
25
|
+
const KEY_FILE_MAX_BYTES = 16 * 1024;
|
|
26
|
+
const GOOGLE_TOKEN_URL = "https://oauth2.googleapis.com/token";
|
|
27
|
+
// The narrowest scope that still mints a token. A service account may ask for
|
|
28
|
+
// any scope for itself (no delegation), so this proves the key and nothing more.
|
|
29
|
+
const GOOGLE_PROBE_SCOPE = "https://www.googleapis.com/auth/userinfo.email";
|
|
30
|
+
/** `op item list --format json` reports "API_CREDENTIAL"; the SDK names it "ApiCredentials". */
|
|
31
|
+
const categoryKey = (category) => category.replace(/[^a-z]/gi, "").toUpperCase();
|
|
32
|
+
/** The vault named in the client's CLIENT.md, else the portal's default name. */
|
|
33
|
+
export function clientVaultFor(slug, workspaceDir) {
|
|
34
|
+
const clientMd = join(workspaceDir, "clients", `client-${slug}`, "CLIENT.md");
|
|
35
|
+
const declared = existsSync(clientMd)
|
|
36
|
+
? readManifestKey(readFileSync(clientMd, "utf8"), "onepassword_vault")
|
|
37
|
+
: undefined;
|
|
38
|
+
// Real CLIENT.md lines carry a note after the name: "client-x # convention", "client-x (created …)".
|
|
39
|
+
const name = declared?.split(/\s+(?:#|\(|—|–)/)[0].trim();
|
|
40
|
+
const usable = name && !/^<.*>$/.test(name) && !name.includes("_HERE");
|
|
41
|
+
return usable && name.toLowerCase() !== "none" ? name : `client-${slug}`;
|
|
42
|
+
}
|
|
43
|
+
/** What a key is, from the shape of its value. Null when no probe exists for it. */
|
|
44
|
+
export function classifyKey(value) {
|
|
45
|
+
const text = value.trim();
|
|
46
|
+
if (text.startsWith("{")) {
|
|
47
|
+
try {
|
|
48
|
+
const json = JSON.parse(text);
|
|
49
|
+
if (json.type === "service_account" && json.client_email && json.private_key) {
|
|
50
|
+
return "google-service-account";
|
|
51
|
+
}
|
|
52
|
+
if (json.client_id && json.client_secret && json.refresh_token)
|
|
53
|
+
return "google-oauth";
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
// The portal intake stores an OAuth client as username = client id, credential = secret.
|
|
61
|
+
if (/^GOCSPX-/.test(text))
|
|
62
|
+
return "google-oauth-client";
|
|
63
|
+
if (/^xox[abp]-/.test(text))
|
|
64
|
+
return "slack";
|
|
65
|
+
if (/^(ghp_|gho_|ghu_|ghs_|github_pat_)/.test(text))
|
|
66
|
+
return "github";
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const unverified = (detail) => ({ status: "unverified", detail });
|
|
70
|
+
async function probeSlack(token, fetchImpl) {
|
|
71
|
+
const res = await fetchImpl("https://slack.com/api/auth.test", {
|
|
72
|
+
method: "POST",
|
|
73
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
74
|
+
signal: AbortSignal.timeout(CHECK_TIMEOUT_MS),
|
|
75
|
+
});
|
|
76
|
+
if (res.status === 429)
|
|
77
|
+
return unverified("Slack is rate limiting; try again in a minute");
|
|
78
|
+
const body = (await res.json());
|
|
79
|
+
if (body.ok)
|
|
80
|
+
return {
|
|
81
|
+
status: "valid",
|
|
82
|
+
detail: `Slack accepts it${body.team ? ` (workspace ${body.team})` : ""}`,
|
|
83
|
+
};
|
|
84
|
+
const dead = ["invalid_auth", "token_revoked", "token_expired", "account_inactive", "not_authed"];
|
|
85
|
+
if (body.error && dead.includes(body.error)) {
|
|
86
|
+
return {
|
|
87
|
+
status: "rejected",
|
|
88
|
+
detail: `Slack rejected it (${body.error}); ask the client for a new token`,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
return unverified(`Slack gave an answer this check does not know (${body.error ?? `HTTP ${res.status}`})`);
|
|
92
|
+
}
|
|
93
|
+
async function probeGithub(token, fetchImpl) {
|
|
94
|
+
// /rate_limit works for every kind of token and needs no scope. It answers
|
|
95
|
+
// 200 with NO token too, so the 401 is the signal and the header is the proof.
|
|
96
|
+
const res = await fetchImpl("https://api.github.com/rate_limit", {
|
|
97
|
+
headers: {
|
|
98
|
+
Authorization: `Bearer ${token}`,
|
|
99
|
+
Accept: "application/vnd.github+json",
|
|
100
|
+
"User-Agent": "ia-access-check",
|
|
101
|
+
},
|
|
102
|
+
signal: AbortSignal.timeout(CHECK_TIMEOUT_MS),
|
|
103
|
+
});
|
|
104
|
+
if (res.status === 401) {
|
|
105
|
+
return {
|
|
106
|
+
status: "rejected",
|
|
107
|
+
detail: "GitHub rejected it (HTTP 401); the token expired or was revoked",
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
if (!res.ok)
|
|
111
|
+
return unverified(`GitHub gave HTTP ${res.status}`);
|
|
112
|
+
const expiry = res.headers.get("github-authentication-token-expiration");
|
|
113
|
+
return {
|
|
114
|
+
status: "valid",
|
|
115
|
+
detail: `GitHub accepts it${expiry ? ` (expires ${expiry.slice(0, 10)})` : " (no expiry date)"}`,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async function probeGoogleServiceAccount(raw, fetchImpl, now) {
|
|
119
|
+
try {
|
|
120
|
+
await getServiceAccountAccessToken(raw, GOOGLE_PROBE_SCOPE, fetchImpl, now);
|
|
121
|
+
return { status: "valid", detail: "Google accepts the service-account key" };
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (error instanceof GoogleServiceAccountAuthError) {
|
|
125
|
+
const http = /HTTP (\d{3})/.exec(error.message)?.[1];
|
|
126
|
+
if (http && (http.startsWith("5") || http === "429"))
|
|
127
|
+
return unverified(`Google gave HTTP ${http}`);
|
|
128
|
+
return {
|
|
129
|
+
status: "rejected",
|
|
130
|
+
detail: `Google rejected the service-account key${http ? ` (HTTP ${http})` : ""}; the key was deleted or disabled`,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// Name only: a message can echo request data.
|
|
134
|
+
return unverified(`could not finish the check (${error instanceof Error ? error.name : "error"})`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Tests the OAuth client pair, not a refresh token (the vault rarely holds one;
|
|
139
|
+
* n8n does). A refresh request with a dummy token answers `invalid_grant` when
|
|
140
|
+
* Google accepts the client id and secret, and `invalid_client` when it does not.
|
|
141
|
+
*/
|
|
142
|
+
async function probeGoogleOauthClient(clientId, clientSecret, fetchImpl) {
|
|
143
|
+
const res = await fetchImpl(GOOGLE_TOKEN_URL, {
|
|
144
|
+
method: "POST",
|
|
145
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
146
|
+
body: new URLSearchParams({
|
|
147
|
+
grant_type: "refresh_token",
|
|
148
|
+
client_id: clientId,
|
|
149
|
+
client_secret: clientSecret,
|
|
150
|
+
refresh_token: "ia-access-check",
|
|
151
|
+
}),
|
|
152
|
+
signal: AbortSignal.timeout(CHECK_TIMEOUT_MS),
|
|
153
|
+
});
|
|
154
|
+
const body = (await res.json().catch(() => ({})));
|
|
155
|
+
if (body.error === "invalid_grant") {
|
|
156
|
+
return {
|
|
157
|
+
status: "valid",
|
|
158
|
+
detail: "Google accepts the OAuth client id and secret. The refresh token lives in n8n and is not tested here",
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (body.error === "invalid_client") {
|
|
162
|
+
return {
|
|
163
|
+
status: "rejected",
|
|
164
|
+
detail: "Google rejected the OAuth client id or secret (invalid_client); the secret was reset or the client deleted",
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
return unverified(`Google gave an answer this check does not know (${body.error ?? `HTTP ${res.status}`})`);
|
|
168
|
+
}
|
|
169
|
+
async function probeGoogleOauth(raw, fetchImpl) {
|
|
170
|
+
const json = JSON.parse(raw);
|
|
171
|
+
const res = await fetchImpl(GOOGLE_TOKEN_URL, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
174
|
+
body: new URLSearchParams({
|
|
175
|
+
grant_type: "refresh_token",
|
|
176
|
+
client_id: json.client_id,
|
|
177
|
+
client_secret: json.client_secret,
|
|
178
|
+
refresh_token: json.refresh_token,
|
|
179
|
+
}),
|
|
180
|
+
signal: AbortSignal.timeout(CHECK_TIMEOUT_MS),
|
|
181
|
+
});
|
|
182
|
+
if (res.ok)
|
|
183
|
+
return { status: "valid", detail: "Google accepts the refresh token" };
|
|
184
|
+
const body = (await res.json().catch(() => ({})));
|
|
185
|
+
if (body.error === "invalid_grant") {
|
|
186
|
+
return {
|
|
187
|
+
status: "rejected",
|
|
188
|
+
detail: "Google rejected the refresh token (invalid_grant): it expired or was revoked. " +
|
|
189
|
+
"An OAuth consent screen in Testing status expires it after 7 days",
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if (body.error === "invalid_client") {
|
|
193
|
+
return {
|
|
194
|
+
status: "rejected",
|
|
195
|
+
detail: "Google rejected the OAuth client id or secret (invalid_client)",
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return unverified(`Google gave an answer this check does not know (${body.error ?? `HTTP ${res.status}`})`);
|
|
199
|
+
}
|
|
200
|
+
/** Test every API-key item in the client's vault. Logins and unknown keys are listed, never read or tested. */
|
|
201
|
+
export async function accessCheck(slug, options = {}) {
|
|
202
|
+
if (!SLUG_PATTERN.test(slug))
|
|
203
|
+
throw new Error(`"${slug}" is not a client slug (lowercase letters, digits, hyphens)`);
|
|
204
|
+
const workspaceDir = resolve(options.workspaceDir ?? findWorkspaceRoot() ?? ".");
|
|
205
|
+
const execFileImpl = options.execFileImpl ?? execFileAsync;
|
|
206
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
207
|
+
const now = options.now ?? Date.now;
|
|
208
|
+
const vault = options.vault?.trim() || clientVaultFor(slug, workspaceDir);
|
|
209
|
+
if (!/^[^\n/]{1,100}$/.test(vault))
|
|
210
|
+
throw new Error("the vault name must be one line, at most 100 characters, with no slash");
|
|
211
|
+
const reachable = await opReachable(execFileImpl, options.platform ?? detectPlatformInfo());
|
|
212
|
+
if (reachable !== true)
|
|
213
|
+
throw new Error(`1Password is not usable: ${reachable}`);
|
|
214
|
+
let listed;
|
|
215
|
+
try {
|
|
216
|
+
const { stdout } = await execFileImpl("op", [
|
|
217
|
+
"item",
|
|
218
|
+
"list",
|
|
219
|
+
"--vault",
|
|
220
|
+
vault,
|
|
221
|
+
"--format",
|
|
222
|
+
"json",
|
|
223
|
+
]);
|
|
224
|
+
listed = JSON.parse(stdout);
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
throw new Error(`could not list the 1Password vault "${vault}": ${execFailureDetail(error).detail}`);
|
|
228
|
+
}
|
|
229
|
+
const items = [];
|
|
230
|
+
for (const item of listed) {
|
|
231
|
+
const base = { title: item.title, service: null };
|
|
232
|
+
const kind = categoryKey(item.category ?? "");
|
|
233
|
+
if (kind === "LOGIN" || kind === "PASSWORD") {
|
|
234
|
+
items.push({
|
|
235
|
+
...base,
|
|
236
|
+
status: "skipped",
|
|
237
|
+
detail: "login or password: no safe test; confirm it by hand",
|
|
238
|
+
});
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
if (kind !== "APICREDENTIAL" && kind !== "DOCUMENT") {
|
|
242
|
+
items.push({
|
|
243
|
+
...base,
|
|
244
|
+
status: "skipped",
|
|
245
|
+
detail: "not an API-key or key-file item; this check does not read it",
|
|
246
|
+
});
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
let value;
|
|
250
|
+
try {
|
|
251
|
+
if (kind === "DOCUMENT") {
|
|
252
|
+
// `ia secrets mint gcp-service-account-key --to-op` stores the key as a
|
|
253
|
+
// Document. Look at the file list first (metadata only); read the file
|
|
254
|
+
// only when it is a small .json, so no contract or PDF is ever pulled in.
|
|
255
|
+
const { stdout: meta } = await execFileImpl("op", [
|
|
256
|
+
"item",
|
|
257
|
+
"get",
|
|
258
|
+
item.id,
|
|
259
|
+
"--vault",
|
|
260
|
+
vault,
|
|
261
|
+
"--format",
|
|
262
|
+
"json",
|
|
263
|
+
]);
|
|
264
|
+
const files = JSON.parse(meta).files ?? [];
|
|
265
|
+
const keyFile = files.find((file) => /\.json$/i.test(file.name ?? "") && (file.size ?? 0) <= KEY_FILE_MAX_BYTES);
|
|
266
|
+
if (!keyFile) {
|
|
267
|
+
items.push({
|
|
268
|
+
...base,
|
|
269
|
+
status: "skipped",
|
|
270
|
+
detail: "a document, but not a small .json key file",
|
|
271
|
+
});
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const { stdout } = await execFileImpl("op", ["document", "get", item.id, "--vault", vault]);
|
|
275
|
+
value = stdout.trim();
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
const { stdout } = await execFileImpl("op", [
|
|
279
|
+
"read",
|
|
280
|
+
`op://${vault}/${item.id}/credential`,
|
|
281
|
+
]);
|
|
282
|
+
value = stdout.trim();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
items.push({
|
|
287
|
+
...base,
|
|
288
|
+
status: "unverified",
|
|
289
|
+
detail: "could not read the key from 1Password",
|
|
290
|
+
});
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const service = classifyKey(value);
|
|
294
|
+
if (!service) {
|
|
295
|
+
items.push({ ...base, status: "skipped", detail: "no test exists for this kind of key" });
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
let clientId = "";
|
|
299
|
+
if (service === "google-oauth-client") {
|
|
300
|
+
try {
|
|
301
|
+
const { stdout } = await execFileImpl("op", ["read", `op://${vault}/${item.id}/username`]);
|
|
302
|
+
clientId = stdout.trim();
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
// falls through to the skip below
|
|
306
|
+
}
|
|
307
|
+
if (!clientId.endsWith(".apps.googleusercontent.com")) {
|
|
308
|
+
items.push({
|
|
309
|
+
title: item.title,
|
|
310
|
+
service,
|
|
311
|
+
status: "skipped",
|
|
312
|
+
detail: "an OAuth client secret with no client id in the username field",
|
|
313
|
+
});
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
let verdict;
|
|
318
|
+
try {
|
|
319
|
+
verdict =
|
|
320
|
+
service === "google-oauth-client"
|
|
321
|
+
? await probeGoogleOauthClient(clientId, value, fetchImpl)
|
|
322
|
+
: service === "slack"
|
|
323
|
+
? await probeSlack(value, fetchImpl)
|
|
324
|
+
: service === "github"
|
|
325
|
+
? await probeGithub(value, fetchImpl)
|
|
326
|
+
: service === "google-service-account"
|
|
327
|
+
? await probeGoogleServiceAccount(value, fetchImpl, now)
|
|
328
|
+
: await probeGoogleOauth(value, fetchImpl);
|
|
329
|
+
}
|
|
330
|
+
catch (error) {
|
|
331
|
+
verdict = unverified(`could not reach the service (${error instanceof Error ? error.name : "error"})`);
|
|
332
|
+
}
|
|
333
|
+
items.push({ title: item.title, service, ...verdict });
|
|
334
|
+
}
|
|
335
|
+
const counts = { valid: 0, rejected: 0, unverified: 0, skipped: 0 };
|
|
336
|
+
for (const item of items)
|
|
337
|
+
counts[item.status] += 1;
|
|
338
|
+
return { slug, vault, items, counts };
|
|
339
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { type AccessCheckItem, type AccessCheckOptions, type AccessCheckResult, type AccessService, type AccessStatus, accessCheck, classifyKey, clientVaultFor, } from "./access-check.js";
|
|
1
2
|
export { type AgentMirrorOptions, type AgentMirrorResult, checkAgentMirror, type MirrorRow, type MirrorState, type MirrorSummary, } from "./agent-mirror.js";
|
|
2
3
|
export { type AgentBankOptions, type AgentTemplateInfo, type AgentTemplateMatch, type CreateFromTemplateInput, type CreateFromTemplateResult, createFromAgentTemplate, type ListAgentTemplatesResult, listAgentTemplates, N8N_API_KEY_ENV, N8N_API_URL_ENV, N8nAuthError, type SanitizedWorkflow, type SaveAgentTemplateInput, type SaveAgentTemplateOptions, type SaveAgentTemplateResult, type SearchAgentTemplatesOptions, type SearchAgentTemplatesResult, type SopState, type StrippedCredential, sanitizeN8nWorkflow, saveAgentTemplate, searchAgentTemplates, } from "./agent-templates.js";
|
|
3
4
|
export { CLAUDE_CONFIG_DIR_ENV, type ClaudeHoursExportOptions, type ClaudeHoursExportResult, type ClaudeHoursSummaryRow, compactClaudeHoursExport, type DeliverClaudeHoursExportOptions, type DeliverClaudeHoursExportResult, deliverClaudeHoursExport, exportClaudeHours, HOURS_EXPORT_DIR, HOURS_EXPORT_SCHEMA, HOURS_EXPORT_SECRET_ENV, HOURS_EXPORT_SECRET_HEADER, HOURS_EXPORT_WEBHOOK_URL, PROMPT_WINDOW_MINUTES, parseLedgerDate, parseMinuteIso, type SaveClaudeHoursExportOptions, type SendClaudeHoursExportOptions, saveClaudeHoursExport, sendClaudeHoursExport, TOOL_INPUT_PATH_KEYS, UNATTRIBUTED_SLUG, } from "./claude-hours.js";
|
|
@@ -37,7 +38,8 @@ export { opInstallCommand, opInstallFix, opIntegrationFix } from "./op-cli.js";
|
|
|
37
38
|
export { defaultOpTitle, type MintImpls, type MintToOpOptions, type MintToOpRequest, type MintToOpResult, mintToOnePassword, } from "./op-store.js";
|
|
38
39
|
export { type PingResult, ping } from "./ping.js";
|
|
39
40
|
export { detectPlatform, detectPlatformInfo, detectShell, opNeedsAnotherShell, type Platform, type PlatformInfo, type Shell, } from "./platform.js";
|
|
40
|
-
export { DEFAULT_PORTAL_URL, PORTAL_ADMIN_SECRET_ENV, PORTAL_BUILD_TYPES, PORTAL_PASSWORD_WARNING, PORTAL_SYNC_MAX_DAYS, PORTAL_URL_ENV, type PortalAddUserInput, type PortalAddUserResult, PortalAdminAuthError, type PortalAdminOptions, type PortalAgent, type PortalAgentSyncRow, type PortalBuild, type PortalBuildType, type PortalCreateAgentInput, type PortalCreateBuildInput, type PortalCreateOrgInput, type PortalCreateOrgResult, type PortalListAgentsResult, type PortalListBuildsResult, type PortalListOrgsResult, type PortalOrg, type PortalOrgUser, PortalRequestError, type PortalSetAgentNameInput, type PortalSetAgentNameResult, type PortalSetAgentStatusInput, type PortalSetAgentStatusResult, type PortalSetAgentTriageResult, type PortalSetAgentWorkflowInput, type PortalSetAgentWorkflowResult, type PortalSetBuildStatusInput, type PortalSetDriveFolderResult, type PortalSetPasswordResult, type PortalSetUserInput, type PortalSetUserResult, type PortalSyncRunsResult, type PortalTriageBackfillResult, type PortalTriageProvider, type PortalTriageRecordsPage, portalAddUser, portalBackfillTriageRecords, portalBuildType, portalBuildWorkflowId, portalCreateAgent, portalCreateBuild, portalCreateOrg, portalListAgents, portalListBuilds, portalListOrgs, portalReadTriageRecords, portalSetAgentName, portalSetAgentStatus, portalSetAgentTriage, portalSetAgentWorkflow, portalSetBuildName, portalSetBuildStatus, portalSetBuildTriage, portalSetBuildWorkflow, portalSetDriveFolder, portalSetOrgSlackChannel, portalSetPassword, portalSetUser, portalSyncRuns, validatePortalBuildFields, } from "./portal-admin.js";
|
|
41
|
+
export { DEFAULT_PORTAL_URL, PORTAL_ADMIN_SECRET_ENV, PORTAL_BUILD_TYPES, PORTAL_PASSWORD_WARNING, PORTAL_SYNC_MAX_DAYS, PORTAL_URL_ENV, type PortalAddUserInput, type PortalAddUserResult, PortalAdminAuthError, type PortalAdminOptions, type PortalAgent, type PortalAgentSyncRow, type PortalBuild, type PortalBuildType, type PortalCreateAgentInput, type PortalCreateBuildInput, type PortalCreateOrgInput, type PortalCreateOrgResult, type PortalListAgentsResult, type PortalListBuildsResult, type PortalListOrgsResult, type PortalOrg, type PortalOrgUser, PortalRequestError, type PortalSetAgentNameInput, type PortalSetAgentNameResult, type PortalSetAgentStatusInput, type PortalSetAgentStatusResult, type PortalSetAgentTriageResult, type PortalSetAgentWorkflowInput, type PortalSetAgentWorkflowResult, type PortalSetBuildDetailsInput, type PortalSetBuildDetailsResult, type PortalSetBuildStatusInput, type PortalSetDriveFolderResult, type PortalSetPasswordResult, type PortalSetUserInput, type PortalSetUserResult, type PortalSyncRunsResult, type PortalTriageBackfillResult, type PortalTriageProvider, type PortalTriageRecordsPage, portalAddUser, portalBackfillTriageRecords, portalBuildType, portalBuildWorkflowId, portalCreateAgent, portalCreateBuild, portalCreateOrg, portalListAgents, portalListBuilds, portalListOrgs, portalReadTriageRecords, portalSetAgentName, portalSetAgentStatus, portalSetAgentTriage, portalSetAgentWorkflow, portalSetBuildDetails, portalSetBuildName, portalSetBuildStatus, portalSetBuildTriage, portalSetBuildWorkflow, portalSetDriveFolder, portalSetOrgSlackChannel, portalSetPassword, portalSetUser, portalSyncRuns, validatePortalBuildFields, } from "./portal-admin.js";
|
|
42
|
+
export { BUILD_DESCRIPTION_MAX, BUILD_NAME_MAX, BUILDS_MANIFEST_END, BUILDS_MANIFEST_START, type BuildsManifest, type BuildsManifestSource, type BuildsManifestState, type BuildsSyncAction, type BuildsSyncActionResult, type BuildsSyncOptions, type BuildsSyncOrgResult, type BuildsSyncPlan, type BuildsSyncResult, type ManifestBuild, type ManifestBuildStatus, parseBuildsManifest, planBuildsSync, type RemoteClientMdReader, syncBuilds, } from "./portal-sync-builds.js";
|
|
41
43
|
export { expectedGithubAccount, type PrOpenOptions, type PrOpenResult, parseGithubRemote, prOpen, } from "./pr-open.js";
|
|
42
44
|
export { type StandupCallPrep, type StandupCallPrepStatus, type StandupGitState, type StandupIssueRef, type StandupLinear, type StandupOptions, type StandupRepo, type StandupRepoLint, type StandupResult, type StandupStaleTodo, standup, } from "./standup.js";
|
|
43
45
|
export { type SyncRepoResult, type SyncRepoStatus, type SyncReposOptions, type SyncReposResult, syncRepos, workspaceRepoNames, } from "./sync-repos.js";
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @installagent/sdk — the only place with real logic. apps/cli and
|
|
2
2
|
// apps/mcp are thin adapters over these exports; every operation here must be
|
|
3
3
|
// reachable from both. See ../../docs/spec.md.
|
|
4
|
+
export { accessCheck, classifyKey, clientVaultFor, } from "./access-check.js";
|
|
4
5
|
export { checkAgentMirror, } from "./agent-mirror.js";
|
|
5
6
|
export { createFromAgentTemplate, listAgentTemplates, N8N_API_KEY_ENV, N8N_API_URL_ENV, N8nAuthError, sanitizeN8nWorkflow, saveAgentTemplate, searchAgentTemplates, } from "./agent-templates.js";
|
|
6
7
|
export { CLAUDE_CONFIG_DIR_ENV, compactClaudeHoursExport, deliverClaudeHoursExport, exportClaudeHours, HOURS_EXPORT_DIR, HOURS_EXPORT_SCHEMA, HOURS_EXPORT_SECRET_ENV, HOURS_EXPORT_SECRET_HEADER, HOURS_EXPORT_WEBHOOK_URL, PROMPT_WINDOW_MINUTES, parseLedgerDate, parseMinuteIso, saveClaudeHoursExport, sendClaudeHoursExport, TOOL_INPUT_PATH_KEYS, UNATTRIBUTED_SLUG, } from "./claude-hours.js";
|
|
@@ -40,7 +41,8 @@ export { opInstallCommand, opInstallFix, opIntegrationFix } from "./op-cli.js";
|
|
|
40
41
|
export { defaultOpTitle, mintToOnePassword, } from "./op-store.js";
|
|
41
42
|
export { ping } from "./ping.js";
|
|
42
43
|
export { detectPlatform, detectPlatformInfo, detectShell, opNeedsAnotherShell, } from "./platform.js";
|
|
43
|
-
export { DEFAULT_PORTAL_URL, PORTAL_ADMIN_SECRET_ENV, PORTAL_BUILD_TYPES, PORTAL_PASSWORD_WARNING, PORTAL_SYNC_MAX_DAYS, PORTAL_URL_ENV, PortalAdminAuthError, PortalRequestError, portalAddUser, portalBackfillTriageRecords, portalBuildType, portalBuildWorkflowId, portalCreateAgent, portalCreateBuild, portalCreateOrg, portalListAgents, portalListBuilds, portalListOrgs, portalReadTriageRecords, portalSetAgentName, portalSetAgentStatus, portalSetAgentTriage, portalSetAgentWorkflow, portalSetBuildName, portalSetBuildStatus, portalSetBuildTriage, portalSetBuildWorkflow, portalSetDriveFolder, portalSetOrgSlackChannel, portalSetPassword, portalSetUser, portalSyncRuns, validatePortalBuildFields, } from "./portal-admin.js";
|
|
44
|
+
export { DEFAULT_PORTAL_URL, PORTAL_ADMIN_SECRET_ENV, PORTAL_BUILD_TYPES, PORTAL_PASSWORD_WARNING, PORTAL_SYNC_MAX_DAYS, PORTAL_URL_ENV, PortalAdminAuthError, PortalRequestError, portalAddUser, portalBackfillTriageRecords, portalBuildType, portalBuildWorkflowId, portalCreateAgent, portalCreateBuild, portalCreateOrg, portalListAgents, portalListBuilds, portalListOrgs, portalReadTriageRecords, portalSetAgentName, portalSetAgentStatus, portalSetAgentTriage, portalSetAgentWorkflow, portalSetBuildDetails, portalSetBuildName, portalSetBuildStatus, portalSetBuildTriage, portalSetBuildWorkflow, portalSetDriveFolder, portalSetOrgSlackChannel, portalSetPassword, portalSetUser, portalSyncRuns, validatePortalBuildFields, } from "./portal-admin.js";
|
|
45
|
+
export { BUILD_DESCRIPTION_MAX, BUILD_NAME_MAX, BUILDS_MANIFEST_END, BUILDS_MANIFEST_START, parseBuildsManifest, planBuildsSync, syncBuilds, } from "./portal-sync-builds.js";
|
|
44
46
|
export { expectedGithubAccount, parseGithubRemote, prOpen, } from "./pr-open.js";
|
|
45
47
|
export { standup, } from "./standup.js";
|
|
46
48
|
export { syncRepos, workspaceRepoNames, } from "./sync-repos.js";
|
package/dist/portal-admin.d.ts
CHANGED
|
@@ -265,6 +265,32 @@ export declare function portalSetBuildName(input: {
|
|
|
265
265
|
}, options?: PortalAdminOptions): Promise<PortalSetAgentNameResult>;
|
|
266
266
|
/** Old name of `portalSetBuildName`. */
|
|
267
267
|
export declare function portalSetAgentName(input: PortalSetAgentNameInput, options?: PortalAdminOptions): Promise<PortalSetAgentNameResult>;
|
|
268
|
+
export interface PortalSetBuildDetailsInput {
|
|
269
|
+
slug: string;
|
|
270
|
+
build: string;
|
|
271
|
+
/** Omit to leave as is. */
|
|
272
|
+
description?: string;
|
|
273
|
+
/** Omit to leave as is; null clears the Open link. https only. */
|
|
274
|
+
url?: string | null;
|
|
275
|
+
}
|
|
276
|
+
export interface PortalSetBuildDetailsResult {
|
|
277
|
+
org: string;
|
|
278
|
+
agent: string;
|
|
279
|
+
previous: {
|
|
280
|
+
description: string;
|
|
281
|
+
url: string | null;
|
|
282
|
+
};
|
|
283
|
+
description: string;
|
|
284
|
+
url: string | null;
|
|
285
|
+
/** False when nothing differed — the call is idempotent. */
|
|
286
|
+
changed: boolean;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Change the card text under a build's name: its description and/or its url
|
|
290
|
+
* (an app's Open link). Before this route (team-web, 2026-10-31) only the
|
|
291
|
+
* create could set either. A portal without the route answers 404.
|
|
292
|
+
*/
|
|
293
|
+
export declare function portalSetBuildDetails(input: PortalSetBuildDetailsInput, options?: PortalAdminOptions): Promise<PortalSetBuildDetailsResult>;
|
|
268
294
|
/**
|
|
269
295
|
* Repoint an agent build at a different n8n workflow — for a version bump (v2
|
|
270
296
|
* replacing a retired v1), which is the same agent from the client's side.
|
package/dist/portal-admin.js
CHANGED
|
@@ -239,6 +239,30 @@ export async function portalSetBuildName(input, options = {}) {
|
|
|
239
239
|
export async function portalSetAgentName(input, options = {}) {
|
|
240
240
|
return portalSetBuildName({ slug: input.slug, build: input.agent, name: input.name }, options);
|
|
241
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Change the card text under a build's name: its description and/or its url
|
|
244
|
+
* (an app's Open link). Before this route (team-web, 2026-10-31) only the
|
|
245
|
+
* create could set either. A portal without the route answers 404.
|
|
246
|
+
*/
|
|
247
|
+
export async function portalSetBuildDetails(input, options = {}) {
|
|
248
|
+
const slug = normalizeSlug(input.slug, "org");
|
|
249
|
+
const build = normalizeSlug(input.build, "build");
|
|
250
|
+
const description = input.description?.trim();
|
|
251
|
+
if (input.description !== undefined && !description)
|
|
252
|
+
throw new Error("description is empty");
|
|
253
|
+
const url = input.url === null ? null : input.url?.trim();
|
|
254
|
+
if (url && !isHttpsUrl(url))
|
|
255
|
+
throw new Error(`url must be an https:// address (got "${url}")`);
|
|
256
|
+
if (description === undefined && url === undefined) {
|
|
257
|
+
throw new Error("give a description and/or a url to change");
|
|
258
|
+
}
|
|
259
|
+
return portalRequest("POST", `${BUILDS_PATH}/details`, options, {
|
|
260
|
+
slug,
|
|
261
|
+
agent: build,
|
|
262
|
+
...(description !== undefined ? { description } : {}),
|
|
263
|
+
...(url !== undefined ? { url: url || null } : {}),
|
|
264
|
+
});
|
|
265
|
+
}
|
|
242
266
|
/**
|
|
243
267
|
* Repoint an agent build at a different n8n workflow — for a version bump (v2
|
|
244
268
|
* replacing a retired v1), which is the same agent from the client's side.
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { ExecFileFn } from "./exec.js";
|
|
2
|
+
import { type PortalAdminOptions, type PortalBuild, type PortalTriageProvider } from "./portal-admin.js";
|
|
3
|
+
export declare const BUILDS_MANIFEST_START = "<!-- BUILDS:START -->";
|
|
4
|
+
export declare const BUILDS_MANIFEST_END = "<!-- BUILDS:END -->";
|
|
5
|
+
export declare const BUILD_NAME_MAX = 120;
|
|
6
|
+
export declare const BUILD_DESCRIPTION_MAX = 140;
|
|
7
|
+
declare const STATUSES: readonly ["active", "paused", "retired"];
|
|
8
|
+
export type ManifestBuildStatus = (typeof STATUSES)[number];
|
|
9
|
+
export interface ManifestBuild {
|
|
10
|
+
/** The build slug (the portal's `agent` field); never changes once registered. */
|
|
11
|
+
build: string;
|
|
12
|
+
type: "agent" | "app";
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
/** The n8n workflow id; agents only. */
|
|
16
|
+
workflowId: string | null;
|
|
17
|
+
/** The Open link; apps only, https or null. */
|
|
18
|
+
url: string | null;
|
|
19
|
+
status: ManifestBuildStatus;
|
|
20
|
+
/** Absent = not managed here; null = explicitly not a triage agent. */
|
|
21
|
+
triage?: PortalTriageProvider | null;
|
|
22
|
+
}
|
|
23
|
+
export type BuildsManifestState =
|
|
24
|
+
/** No markers: the repo predates the manifest. Skipped. */
|
|
25
|
+
"missing"
|
|
26
|
+
/** The template's REPLACE_WITH_* placeholder is still there. Skipped. */
|
|
27
|
+
| "placeholder"
|
|
28
|
+
/** Parsed and every row is valid. */
|
|
29
|
+
| "ok"
|
|
30
|
+
/** At least one error: the org is not synced until it is fixed. */
|
|
31
|
+
| "invalid";
|
|
32
|
+
export interface BuildsManifest {
|
|
33
|
+
state: BuildsManifestState;
|
|
34
|
+
rows: ManifestBuild[];
|
|
35
|
+
errors: string[];
|
|
36
|
+
}
|
|
37
|
+
/** Reads and validates the `## Builds` block of a CLIENT.md. Pure. */
|
|
38
|
+
export declare function parseBuildsManifest(clientMd: string): BuildsManifest;
|
|
39
|
+
export type BuildsSyncAction = {
|
|
40
|
+
kind: "create";
|
|
41
|
+
build: string;
|
|
42
|
+
type: "agent" | "app";
|
|
43
|
+
name: string;
|
|
44
|
+
description: string;
|
|
45
|
+
workflowId: string | null;
|
|
46
|
+
url: string | null;
|
|
47
|
+
status: ManifestBuildStatus;
|
|
48
|
+
triage: PortalTriageProvider | null;
|
|
49
|
+
} | {
|
|
50
|
+
kind: "repoint";
|
|
51
|
+
build: string;
|
|
52
|
+
from: string | null;
|
|
53
|
+
to: string;
|
|
54
|
+
} | {
|
|
55
|
+
kind: "rename";
|
|
56
|
+
build: string;
|
|
57
|
+
from: string;
|
|
58
|
+
to: string;
|
|
59
|
+
} | {
|
|
60
|
+
kind: "details";
|
|
61
|
+
build: string;
|
|
62
|
+
description?: {
|
|
63
|
+
from: string;
|
|
64
|
+
to: string;
|
|
65
|
+
};
|
|
66
|
+
url?: {
|
|
67
|
+
from: string | null;
|
|
68
|
+
to: string | null;
|
|
69
|
+
};
|
|
70
|
+
} | {
|
|
71
|
+
kind: "status";
|
|
72
|
+
build: string;
|
|
73
|
+
from: string;
|
|
74
|
+
to: ManifestBuildStatus;
|
|
75
|
+
} | {
|
|
76
|
+
kind: "triage";
|
|
77
|
+
build: string;
|
|
78
|
+
from: PortalTriageProvider | null;
|
|
79
|
+
to: PortalTriageProvider | null;
|
|
80
|
+
};
|
|
81
|
+
export interface BuildsSyncPlan {
|
|
82
|
+
/** In the order apply runs them. */
|
|
83
|
+
actions: BuildsSyncAction[];
|
|
84
|
+
/** Registry builds of this org the manifest does not name. Never changed. */
|
|
85
|
+
registryOnly: {
|
|
86
|
+
build: string;
|
|
87
|
+
type: "agent" | "app";
|
|
88
|
+
name: string;
|
|
89
|
+
status: string;
|
|
90
|
+
}[];
|
|
91
|
+
/** Manifest rows that cannot be synced as written. Nothing is done for them. */
|
|
92
|
+
conflicts: string[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Plans one org. Pure: `registry` is every build in the registry (all orgs),
|
|
96
|
+
* because an n8n workflow id is unique across the whole registry.
|
|
97
|
+
*
|
|
98
|
+
* Match rule: an agent matches by workflow id; an app by its build slug. An
|
|
99
|
+
* agent row whose workflow id is new but whose slug is a registered agent is a
|
|
100
|
+
* REPOINT (a v2 keeps the card), never a second card.
|
|
101
|
+
*/
|
|
102
|
+
export declare function planBuildsSync(org: string, manifest: ManifestBuild[], registry: PortalBuild[]): BuildsSyncPlan;
|
|
103
|
+
export type BuildsManifestSource = "workspace" | "github" | "none";
|
|
104
|
+
export interface BuildsSyncActionResult {
|
|
105
|
+
action: BuildsSyncAction;
|
|
106
|
+
/** Set only with apply: "done", or the error the portal gave. */
|
|
107
|
+
outcome?: "done" | {
|
|
108
|
+
error: string;
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export interface BuildsSyncOrgResult {
|
|
112
|
+
org: string;
|
|
113
|
+
/** Where CLIENT.md was read from; "none" = no repo found. */
|
|
114
|
+
source: BuildsManifestSource;
|
|
115
|
+
manifest: BuildsManifestState | "no-repo";
|
|
116
|
+
errors: string[];
|
|
117
|
+
actions: BuildsSyncActionResult[];
|
|
118
|
+
registryOnly: BuildsSyncPlan["registryOnly"];
|
|
119
|
+
conflicts: string[];
|
|
120
|
+
}
|
|
121
|
+
export interface BuildsSyncResult {
|
|
122
|
+
applied: boolean;
|
|
123
|
+
orgs: BuildsSyncOrgResult[];
|
|
124
|
+
/** Orgs left out on purpose (Install Agent's own). */
|
|
125
|
+
skippedOrgs: string[];
|
|
126
|
+
/** Actions planned (dry run) or attempted (apply), across all orgs. */
|
|
127
|
+
actionCount: number;
|
|
128
|
+
/** Apply only: actions the portal refused. */
|
|
129
|
+
failedCount: number;
|
|
130
|
+
}
|
|
131
|
+
/** Reads `clients/client-<slug>/CLIENT.md` from GitHub when the repo is not cloned. Null = not there. */
|
|
132
|
+
export type RemoteClientMdReader = (slug: string) => Promise<string | null>;
|
|
133
|
+
export interface BuildsSyncOptions {
|
|
134
|
+
/** The installagent/ workspace root (the dir that contains clients/). */
|
|
135
|
+
workspaceDir: string;
|
|
136
|
+
/** One org only. */
|
|
137
|
+
slug?: string;
|
|
138
|
+
/** Write to the portal. Default false: plan and report only. */
|
|
139
|
+
apply?: boolean;
|
|
140
|
+
/** Portal admin options (secret, base URL, fetch). */
|
|
141
|
+
portal?: PortalAdminOptions;
|
|
142
|
+
/** Fallback for an org with no local repo; defaults to the GitHub contents API. */
|
|
143
|
+
readRemoteClientMd?: RemoteClientMdReader;
|
|
144
|
+
/** GitHub token for the default fallback; defaults to $GITHUB_API_TOKEN, then `gh auth token`. */
|
|
145
|
+
githubToken?: string;
|
|
146
|
+
execFileImpl?: ExecFileFn;
|
|
147
|
+
githubFetchImpl?: typeof fetch;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Compares every client repo's `## Builds` manifest with the portal's builds
|
|
151
|
+
* registry and, with `apply`, moves the registry to match: create, rename,
|
|
152
|
+
* description/url, status, triage, repoint. Never deletes, never touches
|
|
153
|
+
* Install Agent's own org, never writes a client repo. A second run after an
|
|
154
|
+
* apply plans nothing.
|
|
155
|
+
*/
|
|
156
|
+
export declare function syncBuilds(options: BuildsSyncOptions): Promise<BuildsSyncResult>;
|
|
157
|
+
export {};
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readdir, readFile } from "node:fs/promises";
|
|
3
|
+
import { join, resolve } from "node:path";
|
|
4
|
+
import { GITHUB_TOKEN_FIX, resolveGithubToken } from "./github-token.js";
|
|
5
|
+
import { portalBuildType, portalBuildWorkflowId, portalCreateBuild, portalListBuilds, portalListOrgs, portalSetBuildDetails, portalSetBuildName, portalSetBuildStatus, portalSetBuildTriage, portalSetBuildWorkflow, } from "./portal-admin.js";
|
|
6
|
+
// ─── The manifest: the `## Builds` block of a client repo's CLIENT.md ───────
|
|
7
|
+
//
|
|
8
|
+
// One fenced JSON array between these two markers. The client repo is the
|
|
9
|
+
// source of truth for which builds a client sees on the portal; this module
|
|
10
|
+
// reads it, compares it with the portal's builds registry, and (with apply)
|
|
11
|
+
// moves the registry to match. It never deletes: a registry build the
|
|
12
|
+
// manifest does not name is reported, not changed.
|
|
13
|
+
//
|
|
14
|
+
// The validator below has a twin in client-template (`ci/builds-manifest.mjs`,
|
|
15
|
+
// repo-lint rule 11). The repos never import each other, so a rule change
|
|
16
|
+
// lands in both files in the same piece of work.
|
|
17
|
+
export const BUILDS_MANIFEST_START = "<!-- BUILDS:START -->";
|
|
18
|
+
export const BUILDS_MANIFEST_END = "<!-- BUILDS:END -->";
|
|
19
|
+
export const BUILD_NAME_MAX = 120;
|
|
20
|
+
export const BUILD_DESCRIPTION_MAX = 140;
|
|
21
|
+
const BUILD_SLUG = /^[a-z0-9][a-z0-9-]*$/;
|
|
22
|
+
const STATUSES = ["active", "paused", "retired"];
|
|
23
|
+
const ROW_KEYS = new Set([
|
|
24
|
+
"build",
|
|
25
|
+
"type",
|
|
26
|
+
"name",
|
|
27
|
+
"description",
|
|
28
|
+
"workflow_id",
|
|
29
|
+
"url",
|
|
30
|
+
"status",
|
|
31
|
+
"triage",
|
|
32
|
+
]);
|
|
33
|
+
function isHttps(value) {
|
|
34
|
+
try {
|
|
35
|
+
return new URL(value).protocol === "https:" && value.startsWith("https://");
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Validates one parsed row; pushes its errors (prefixed with its place) and returns it when valid. */
|
|
42
|
+
function readRow(raw, index, errors) {
|
|
43
|
+
const where = `row ${index + 1}`;
|
|
44
|
+
if (typeof raw !== "object" || raw === null || Array.isArray(raw)) {
|
|
45
|
+
errors.push(`${where}: must be an object`);
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const row = raw;
|
|
49
|
+
const label = typeof row.build === "string" && row.build ? `${where} (${row.build})` : where;
|
|
50
|
+
const before = errors.length;
|
|
51
|
+
const fail = (message) => errors.push(`${label}: ${message}`);
|
|
52
|
+
for (const key of Object.keys(row))
|
|
53
|
+
if (!ROW_KEYS.has(key))
|
|
54
|
+
fail(`unknown field "${key}"`);
|
|
55
|
+
if (typeof row.build !== "string" || !BUILD_SLUG.test(row.build))
|
|
56
|
+
fail("build must be a kebab-case slug");
|
|
57
|
+
if (row.type !== "agent" && row.type !== "app")
|
|
58
|
+
fail("type must be agent|app");
|
|
59
|
+
const name = typeof row.name === "string" ? row.name.trim() : "";
|
|
60
|
+
if (!name)
|
|
61
|
+
fail("name required");
|
|
62
|
+
else if (name.length > BUILD_NAME_MAX)
|
|
63
|
+
fail(`name must be ${BUILD_NAME_MAX} characters or fewer`);
|
|
64
|
+
else if (/\bINS-\d+\b/i.test(name) || /\bn8n\b/i.test(name))
|
|
65
|
+
fail("name is client-facing: no ticket numbers, no tool names");
|
|
66
|
+
const description = typeof row.description === "string" ? row.description.trim() : "";
|
|
67
|
+
if (!description)
|
|
68
|
+
fail("description required");
|
|
69
|
+
else if (description.length > BUILD_DESCRIPTION_MAX)
|
|
70
|
+
fail(`description must be ${BUILD_DESCRIPTION_MAX} characters or fewer`);
|
|
71
|
+
const workflowId = typeof row.workflow_id === "string" && row.workflow_id.trim() ? row.workflow_id.trim() : null;
|
|
72
|
+
if (row.workflow_id !== undefined && row.workflow_id !== null && workflowId === null)
|
|
73
|
+
fail("workflow_id must be a non-empty string");
|
|
74
|
+
const url = typeof row.url === "string" && row.url.trim() ? row.url.trim() : null;
|
|
75
|
+
if (row.url !== undefined && row.url !== null && typeof row.url !== "string")
|
|
76
|
+
fail("url must be a string or null");
|
|
77
|
+
if (url && !isHttps(url))
|
|
78
|
+
fail("url must be a full https:// address");
|
|
79
|
+
if (row.type === "agent") {
|
|
80
|
+
if (!workflowId)
|
|
81
|
+
fail("an agent needs its workflow_id");
|
|
82
|
+
if (url)
|
|
83
|
+
fail("an agent has no url (only an app has an Open link)");
|
|
84
|
+
}
|
|
85
|
+
if (row.type === "app") {
|
|
86
|
+
if (workflowId)
|
|
87
|
+
fail("an app has no workflow_id");
|
|
88
|
+
if (row.triage !== undefined && row.triage !== null)
|
|
89
|
+
fail("an app cannot be a triage agent");
|
|
90
|
+
}
|
|
91
|
+
if (!STATUSES.includes(row.status))
|
|
92
|
+
fail(`status must be ${STATUSES.join("|")}`);
|
|
93
|
+
if (row.triage !== undefined &&
|
|
94
|
+
row.triage !== null &&
|
|
95
|
+
row.triage !== "gmail" &&
|
|
96
|
+
row.triage !== "outlook")
|
|
97
|
+
fail("triage must be gmail|outlook (or null)");
|
|
98
|
+
if (errors.length > before)
|
|
99
|
+
return null;
|
|
100
|
+
return {
|
|
101
|
+
build: row.build,
|
|
102
|
+
type: row.type,
|
|
103
|
+
name,
|
|
104
|
+
description,
|
|
105
|
+
workflowId,
|
|
106
|
+
url,
|
|
107
|
+
status: row.status,
|
|
108
|
+
...(row.triage !== undefined ? { triage: row.triage } : {}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
/** Reads and validates the `## Builds` block of a CLIENT.md. Pure. */
|
|
112
|
+
export function parseBuildsManifest(clientMd) {
|
|
113
|
+
const start = clientMd.indexOf(BUILDS_MANIFEST_START);
|
|
114
|
+
const end = clientMd.indexOf(BUILDS_MANIFEST_END);
|
|
115
|
+
if (start === -1 && end === -1)
|
|
116
|
+
return { state: "missing", rows: [], errors: [] };
|
|
117
|
+
if (start === -1 || end === -1 || end < start) {
|
|
118
|
+
return {
|
|
119
|
+
state: "invalid",
|
|
120
|
+
rows: [],
|
|
121
|
+
errors: [`need both ${BUILDS_MANIFEST_START} and ${BUILDS_MANIFEST_END}, in that order`],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
const block = clientMd.slice(start + BUILDS_MANIFEST_START.length, end);
|
|
125
|
+
if (block.includes("REPLACE_WITH_"))
|
|
126
|
+
return { state: "placeholder", rows: [], errors: [] };
|
|
127
|
+
const fence = block.match(/```json\s*\n([\s\S]*?)\n\s*```/);
|
|
128
|
+
if (!fence) {
|
|
129
|
+
return { state: "invalid", rows: [], errors: ["the block needs one ```json fenced array"] };
|
|
130
|
+
}
|
|
131
|
+
let parsed;
|
|
132
|
+
try {
|
|
133
|
+
parsed = JSON.parse(fence[1]);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
return {
|
|
137
|
+
state: "invalid",
|
|
138
|
+
rows: [],
|
|
139
|
+
errors: [`the JSON does not parse: ${error instanceof Error ? error.message : error}`],
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (!Array.isArray(parsed)) {
|
|
143
|
+
return { state: "invalid", rows: [], errors: ["the JSON must be an array of builds"] };
|
|
144
|
+
}
|
|
145
|
+
const errors = [];
|
|
146
|
+
const rows = [];
|
|
147
|
+
parsed.forEach((raw, index) => {
|
|
148
|
+
const row = readRow(raw, index, errors);
|
|
149
|
+
if (row)
|
|
150
|
+
rows.push(row);
|
|
151
|
+
});
|
|
152
|
+
const seenSlugs = new Set();
|
|
153
|
+
const seenWorkflows = new Set();
|
|
154
|
+
for (const row of rows) {
|
|
155
|
+
if (seenSlugs.has(row.build))
|
|
156
|
+
errors.push(`build "${row.build}" is listed twice`);
|
|
157
|
+
seenSlugs.add(row.build);
|
|
158
|
+
if (row.workflowId) {
|
|
159
|
+
if (seenWorkflows.has(row.workflowId))
|
|
160
|
+
errors.push(`workflow_id ${row.workflowId} is listed twice`);
|
|
161
|
+
seenWorkflows.add(row.workflowId);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return errors.length > 0 ? { state: "invalid", rows: [], errors } : { state: "ok", rows, errors };
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Plans one org. Pure: `registry` is every build in the registry (all orgs),
|
|
168
|
+
* because an n8n workflow id is unique across the whole registry.
|
|
169
|
+
*
|
|
170
|
+
* Match rule: an agent matches by workflow id; an app by its build slug. An
|
|
171
|
+
* agent row whose workflow id is new but whose slug is a registered agent is a
|
|
172
|
+
* REPOINT (a v2 keeps the card), never a second card.
|
|
173
|
+
*/
|
|
174
|
+
export function planBuildsSync(org, manifest, registry) {
|
|
175
|
+
const orgBuilds = registry.filter((build) => build.org === org);
|
|
176
|
+
const matched = new Set();
|
|
177
|
+
const actions = [];
|
|
178
|
+
const followUps = [];
|
|
179
|
+
const conflicts = [];
|
|
180
|
+
for (const row of manifest) {
|
|
181
|
+
const bySlug = orgBuilds.find((build) => build.slug === row.build);
|
|
182
|
+
let current;
|
|
183
|
+
if (row.type === "agent" && row.workflowId) {
|
|
184
|
+
const holder = registry.find((build) => portalBuildWorkflowId(build) === row.workflowId);
|
|
185
|
+
if (holder && holder.org !== org) {
|
|
186
|
+
conflicts.push(`${row.build}: workflow ${row.workflowId} is registered to ${holder.org}/${holder.slug}`);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
if (holder && holder.slug !== row.build) {
|
|
190
|
+
conflicts.push(`${row.build}: workflow ${row.workflowId} is registered here as "${holder.slug}" — ` +
|
|
191
|
+
"a build slug never changes, so use that slug in the manifest");
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
if (holder)
|
|
195
|
+
current = holder;
|
|
196
|
+
else if (bySlug && portalBuildType(bySlug) === "agent") {
|
|
197
|
+
current = bySlug;
|
|
198
|
+
actions.push({
|
|
199
|
+
kind: "repoint",
|
|
200
|
+
build: row.build,
|
|
201
|
+
from: portalBuildWorkflowId(bySlug),
|
|
202
|
+
to: row.workflowId,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else if (bySlug) {
|
|
207
|
+
current = bySlug;
|
|
208
|
+
}
|
|
209
|
+
if (bySlug && portalBuildType(bySlug) !== row.type) {
|
|
210
|
+
conflicts.push(`${row.build}: the manifest says ${row.type}, the portal has an ${portalBuildType(bySlug)} ` +
|
|
211
|
+
"with that slug — a build's type never changes, pick another slug");
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (!current) {
|
|
215
|
+
actions.push({
|
|
216
|
+
kind: "create",
|
|
217
|
+
build: row.build,
|
|
218
|
+
type: row.type,
|
|
219
|
+
name: row.name,
|
|
220
|
+
description: row.description,
|
|
221
|
+
workflowId: row.workflowId,
|
|
222
|
+
url: row.url,
|
|
223
|
+
status: row.status,
|
|
224
|
+
triage: row.triage ?? null,
|
|
225
|
+
});
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
matched.add(current.slug);
|
|
229
|
+
if (current.name.trim() !== row.name) {
|
|
230
|
+
followUps.push({ kind: "rename", build: row.build, from: current.name, to: row.name });
|
|
231
|
+
}
|
|
232
|
+
const details = {
|
|
233
|
+
kind: "details",
|
|
234
|
+
build: row.build,
|
|
235
|
+
};
|
|
236
|
+
if (current.description.trim() !== row.description) {
|
|
237
|
+
details.description = { from: current.description, to: row.description };
|
|
238
|
+
}
|
|
239
|
+
const currentUrl = current.url ?? null;
|
|
240
|
+
if (row.type === "app" && currentUrl !== row.url) {
|
|
241
|
+
details.url = { from: currentUrl, to: row.url };
|
|
242
|
+
}
|
|
243
|
+
if (details.description || details.url)
|
|
244
|
+
followUps.push(details);
|
|
245
|
+
if (current.status !== row.status) {
|
|
246
|
+
followUps.push({ kind: "status", build: row.build, from: current.status, to: row.status });
|
|
247
|
+
}
|
|
248
|
+
const currentTriage = current.triageProvider ?? null;
|
|
249
|
+
if (row.triage !== undefined && currentTriage !== row.triage) {
|
|
250
|
+
followUps.push({ kind: "triage", build: row.build, from: currentTriage, to: row.triage });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
// A row in conflict leaves its registry build unmatched, so it shows here
|
|
254
|
+
// too: nothing is synced for it until the manifest is fixed.
|
|
255
|
+
const registryOnly = orgBuilds
|
|
256
|
+
.filter((build) => !matched.has(build.slug))
|
|
257
|
+
.map((build) => ({
|
|
258
|
+
build: build.slug,
|
|
259
|
+
type: portalBuildType(build),
|
|
260
|
+
name: build.name,
|
|
261
|
+
status: build.status,
|
|
262
|
+
}));
|
|
263
|
+
return { actions: [...actions, ...followUps], registryOnly, conflicts };
|
|
264
|
+
}
|
|
265
|
+
function githubClientMdReader(options) {
|
|
266
|
+
return async (slug) => {
|
|
267
|
+
const resolved = await resolveGithubToken({
|
|
268
|
+
token: options.githubToken,
|
|
269
|
+
execFileImpl: options.execFileImpl,
|
|
270
|
+
});
|
|
271
|
+
if (!resolved)
|
|
272
|
+
throw new Error(`GitHub auth required to read client-${slug} — ${GITHUB_TOKEN_FIX}`);
|
|
273
|
+
const res = await (options.githubFetchImpl ?? fetch)(`https://api.github.com/repos/InstallAgent/client-${slug}/contents/CLIENT.md`, {
|
|
274
|
+
headers: {
|
|
275
|
+
Authorization: `Bearer ${resolved.token}`,
|
|
276
|
+
Accept: "application/vnd.github.raw+json",
|
|
277
|
+
"X-GitHub-Api-Version": "2022-11-28",
|
|
278
|
+
},
|
|
279
|
+
});
|
|
280
|
+
if (res.status === 404)
|
|
281
|
+
return null;
|
|
282
|
+
if (!res.ok)
|
|
283
|
+
throw new Error(`GitHub read of client-${slug}/CLIENT.md failed: HTTP ${res.status}`);
|
|
284
|
+
return res.text();
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
async function localClientSlugs(workspaceDir) {
|
|
288
|
+
const clientsDir = join(workspaceDir, "clients");
|
|
289
|
+
if (!existsSync(clientsDir))
|
|
290
|
+
return [];
|
|
291
|
+
const entries = await readdir(clientsDir, { withFileTypes: true });
|
|
292
|
+
return entries
|
|
293
|
+
.filter((entry) => entry.isDirectory() && entry.name.startsWith("client-") && entry.name !== "client-template")
|
|
294
|
+
.map((entry) => entry.name.slice("client-".length))
|
|
295
|
+
.filter((slug) => existsSync(join(clientsDir, `client-${slug}`, "CLIENT.md")));
|
|
296
|
+
}
|
|
297
|
+
async function applyAction(action, org, portal) {
|
|
298
|
+
const ref = { slug: org, build: action.build };
|
|
299
|
+
switch (action.kind) {
|
|
300
|
+
case "create":
|
|
301
|
+
await portalCreateBuild({
|
|
302
|
+
...ref,
|
|
303
|
+
name: action.name,
|
|
304
|
+
description: action.description,
|
|
305
|
+
buildType: action.type,
|
|
306
|
+
...(action.workflowId ? { workflowId: action.workflowId } : {}),
|
|
307
|
+
...(action.url ? { url: action.url } : {}),
|
|
308
|
+
}, portal);
|
|
309
|
+
// A create always lands active and not a triage agent.
|
|
310
|
+
if (action.status !== "active")
|
|
311
|
+
await portalSetBuildStatus({ ...ref, status: action.status }, portal);
|
|
312
|
+
if (action.triage)
|
|
313
|
+
await portalSetBuildTriage({ ...ref, provider: action.triage }, portal);
|
|
314
|
+
return;
|
|
315
|
+
case "repoint":
|
|
316
|
+
await portalSetBuildWorkflow({ ...ref, workflowId: action.to }, portal);
|
|
317
|
+
return;
|
|
318
|
+
case "rename":
|
|
319
|
+
await portalSetBuildName({ ...ref, name: action.to }, portal);
|
|
320
|
+
return;
|
|
321
|
+
case "details":
|
|
322
|
+
await portalSetBuildDetails({
|
|
323
|
+
...ref,
|
|
324
|
+
...(action.description ? { description: action.description.to } : {}),
|
|
325
|
+
...(action.url ? { url: action.url.to } : {}),
|
|
326
|
+
}, portal);
|
|
327
|
+
return;
|
|
328
|
+
case "status":
|
|
329
|
+
await portalSetBuildStatus({ ...ref, status: action.to }, portal);
|
|
330
|
+
return;
|
|
331
|
+
case "triage":
|
|
332
|
+
await portalSetBuildTriage({ ...ref, provider: action.to }, portal);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Compares every client repo's `## Builds` manifest with the portal's builds
|
|
338
|
+
* registry and, with `apply`, moves the registry to match: create, rename,
|
|
339
|
+
* description/url, status, triage, repoint. Never deletes, never touches
|
|
340
|
+
* Install Agent's own org, never writes a client repo. A second run after an
|
|
341
|
+
* apply plans nothing.
|
|
342
|
+
*/
|
|
343
|
+
export async function syncBuilds(options) {
|
|
344
|
+
const workspaceDir = resolve(options.workspaceDir);
|
|
345
|
+
const portal = options.portal ?? {};
|
|
346
|
+
const apply = options.apply ?? false;
|
|
347
|
+
const readRemote = options.readRemoteClientMd ?? githubClientMdReader(options);
|
|
348
|
+
const [{ orgs: portalOrgs }, { agents: registry }] = await Promise.all([
|
|
349
|
+
portalListOrgs(portal),
|
|
350
|
+
portalListBuilds({}, portal),
|
|
351
|
+
]);
|
|
352
|
+
const internal = new Set(portalOrgs.filter((o) => o.kind === "internal").map((o) => o.slug));
|
|
353
|
+
const local = await localClientSlugs(workspaceDir);
|
|
354
|
+
let slugs = [...new Set([...local, ...portalOrgs.map((o) => o.slug)])].sort();
|
|
355
|
+
if (options.slug) {
|
|
356
|
+
slugs = [options.slug.toLowerCase().replace(/^client-/, "")];
|
|
357
|
+
}
|
|
358
|
+
const skippedOrgs = slugs.filter((slug) => internal.has(slug));
|
|
359
|
+
const orgs = [];
|
|
360
|
+
for (const org of slugs.filter((slug) => !internal.has(slug))) {
|
|
361
|
+
let source = "none";
|
|
362
|
+
let clientMd = null;
|
|
363
|
+
const errors = [];
|
|
364
|
+
if (local.includes(org)) {
|
|
365
|
+
source = "workspace";
|
|
366
|
+
clientMd = await readFile(join(workspaceDir, "clients", `client-${org}`, "CLIENT.md"), "utf8");
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
try {
|
|
370
|
+
clientMd = await readRemote(org);
|
|
371
|
+
if (clientMd !== null)
|
|
372
|
+
source = "github";
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
errors.push(error instanceof Error ? error.message : String(error));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const empty = { actions: [], registryOnly: [], conflicts: [] };
|
|
379
|
+
if (clientMd === null) {
|
|
380
|
+
orgs.push({ org, source, manifest: "no-repo", errors, ...empty });
|
|
381
|
+
continue;
|
|
382
|
+
}
|
|
383
|
+
const manifest = parseBuildsManifest(clientMd);
|
|
384
|
+
if (manifest.state !== "ok") {
|
|
385
|
+
orgs.push({ org, source, manifest: manifest.state, errors: manifest.errors, ...empty });
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
const plan = planBuildsSync(org, manifest.rows, registry);
|
|
389
|
+
const actions = [];
|
|
390
|
+
for (const action of plan.actions) {
|
|
391
|
+
if (!apply) {
|
|
392
|
+
actions.push({ action });
|
|
393
|
+
continue;
|
|
394
|
+
}
|
|
395
|
+
try {
|
|
396
|
+
await applyAction(action, org, portal);
|
|
397
|
+
actions.push({ action, outcome: "done" });
|
|
398
|
+
}
|
|
399
|
+
catch (error) {
|
|
400
|
+
actions.push({
|
|
401
|
+
action,
|
|
402
|
+
outcome: { error: error instanceof Error ? error.message : String(error) },
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
orgs.push({
|
|
407
|
+
org,
|
|
408
|
+
source,
|
|
409
|
+
manifest: "ok",
|
|
410
|
+
errors,
|
|
411
|
+
actions,
|
|
412
|
+
registryOnly: plan.registryOnly,
|
|
413
|
+
conflicts: plan.conflicts,
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
const all = orgs.flatMap((org) => org.actions);
|
|
417
|
+
return {
|
|
418
|
+
applied: apply,
|
|
419
|
+
orgs,
|
|
420
|
+
skippedOrgs,
|
|
421
|
+
actionCount: all.length,
|
|
422
|
+
failedCount: all.filter((a) => typeof a.outcome === "object").length,
|
|
423
|
+
};
|
|
424
|
+
}
|
package/dist/pr-open.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ExecFileFn } from "./exec.js";
|
|
2
2
|
/**
|
|
3
3
|
* `ia pr open` — push the current branch and open a DRAFT pull request, with
|
|
4
|
-
* the
|
|
4
|
+
* the checks that the Slack Merge button made necessary:
|
|
5
5
|
*
|
|
6
6
|
* 1. The gh account is the workspace's work account (`.github-account` at the
|
|
7
7
|
* workspace root). A PR under a personal account lands on the wrong identity
|
|
@@ -11,6 +11,8 @@ import { type ExecFileFn } from "./exec.js";
|
|
|
11
11
|
* same branch was silently lost (6 incidents in 20 days, Oct 2026).
|
|
12
12
|
* 3. The branch has no OPEN pull request. More commits on an open PR is the
|
|
13
13
|
* same trap one click later: open a new PR per slice.
|
|
14
|
+
* 4. The branch has at least one commit ahead of the base. An empty branch
|
|
15
|
+
* pushes fine and leaves a dead remote branch behind.
|
|
14
16
|
*
|
|
15
17
|
* The PR opens as a draft, so no Slack card (and no Merge button) exists until
|
|
16
18
|
* someone marks it ready on purpose.
|
package/dist/pr-open.js
CHANGED
|
@@ -69,6 +69,15 @@ export async function prOpen(options = {}) {
|
|
|
69
69
|
throw new Error(`PR #${open.number} from ${branch} is still open (${open.url}). Do not add commits to it: ` +
|
|
70
70
|
"the Merge button squashes the head as it is. Open a new branch for the next slice.");
|
|
71
71
|
}
|
|
72
|
+
// 4. The branch has commits of its own. An empty branch pushes fine, then
|
|
73
|
+
// `gh pr create` has nothing to open. Compare with origin/<base> when the
|
|
74
|
+
// checkout has it, else the local base branch.
|
|
75
|
+
const hasRemoteBase = await git("rev-parse", "--verify", "--quiet", `origin/${base}`).then(() => true, () => false);
|
|
76
|
+
const baseRef = hasRemoteBase ? `origin/${base}` : base;
|
|
77
|
+
if (Number(await git("rev-list", "--count", `${baseRef}..HEAD`)) === 0) {
|
|
78
|
+
throw new Error(`${branch} has no commits ahead of ${baseRef}. Commit your changes on this branch first, ` +
|
|
79
|
+
"then re-run `ia pr open`.");
|
|
80
|
+
}
|
|
72
81
|
const result = {
|
|
73
82
|
repo,
|
|
74
83
|
branch,
|
package/dist/template-sync.js
CHANGED
|
@@ -38,6 +38,17 @@ export const TEMPLATE_SYNCED_FILES = [
|
|
|
38
38
|
"CADENCE.md",
|
|
39
39
|
"ci/repo-lint.mjs",
|
|
40
40
|
"ci/repo-lint.test.mjs",
|
|
41
|
+
// repo-lint imports log-progress (rule 9), so the two always travel together.
|
|
42
|
+
"ci/log-progress.mjs",
|
|
43
|
+
"ci/log-progress.test.mjs",
|
|
44
|
+
// repo-lint also imports roadmap (rule 10): the Roadmap tab + client roadmap
|
|
45
|
+
// are generated from docs/06-roadmap.md.
|
|
46
|
+
"ci/roadmap.mjs",
|
|
47
|
+
"ci/roadmap.test.mjs",
|
|
48
|
+
// repo-lint also imports builds-manifest (rule 11): the `## Builds` block
|
|
49
|
+
// of CLIENT.md, the source of `ia portal sync-builds`.
|
|
50
|
+
"ci/builds-manifest.mjs",
|
|
51
|
+
"ci/builds-manifest.test.mjs",
|
|
41
52
|
"lefthook.yml",
|
|
42
53
|
".github/workflows/repo-lint.yml",
|
|
43
54
|
".github/workflows/pr-to-slack.yml",
|
package/package.json
CHANGED