@installagent/sdk 0.8.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/index.d.ts +2 -1
- package/dist/index.js +2 -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/template-sync.js +8 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -38,7 +38,8 @@ export { opInstallCommand, opInstallFix, opIntegrationFix } from "./op-cli.js";
|
|
|
38
38
|
export { defaultOpTitle, type MintImpls, type MintToOpOptions, type MintToOpRequest, type MintToOpResult, mintToOnePassword, } from "./op-store.js";
|
|
39
39
|
export { type PingResult, ping } from "./ping.js";
|
|
40
40
|
export { detectPlatform, detectPlatformInfo, detectShell, opNeedsAnotherShell, type Platform, type PlatformInfo, type Shell, } from "./platform.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 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";
|
|
42
43
|
export { expectedGithubAccount, type PrOpenOptions, type PrOpenResult, parseGithubRemote, prOpen, } from "./pr-open.js";
|
|
43
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";
|
|
44
45
|
export { type SyncRepoResult, type SyncRepoStatus, type SyncReposOptions, type SyncReposResult, syncRepos, workspaceRepoNames, } from "./sync-repos.js";
|
package/dist/index.js
CHANGED
|
@@ -41,7 +41,8 @@ export { opInstallCommand, opInstallFix, opIntegrationFix } from "./op-cli.js";
|
|
|
41
41
|
export { defaultOpTitle, mintToOnePassword, } from "./op-store.js";
|
|
42
42
|
export { ping } from "./ping.js";
|
|
43
43
|
export { detectPlatform, detectPlatformInfo, detectShell, opNeedsAnotherShell, } from "./platform.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, 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";
|
|
45
46
|
export { expectedGithubAccount, parseGithubRemote, prOpen, } from "./pr-open.js";
|
|
46
47
|
export { standup, } from "./standup.js";
|
|
47
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/template-sync.js
CHANGED
|
@@ -41,6 +41,14 @@ export const TEMPLATE_SYNCED_FILES = [
|
|
|
41
41
|
// repo-lint imports log-progress (rule 9), so the two always travel together.
|
|
42
42
|
"ci/log-progress.mjs",
|
|
43
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",
|
|
44
52
|
"lefthook.yml",
|
|
45
53
|
".github/workflows/repo-lint.yml",
|
|
46
54
|
".github/workflows/pr-to-slack.yml",
|
package/package.json
CHANGED