agl 42.2.2 → 43.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +24 -0
- package/dist_serve/bundle.js +6697 -5287
- package/dist_serve/bundle.js.map +2 -2
- package/dist_serve/bundle.js.third-party-notices.json +29 -29
- package/dist_serve/bundle.js.third-party-notices.txt +29 -29
- package/dist_serve/third-party-notices.md +597 -8
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/aglapi/aglapisurface.document.js +114 -16
- package/dist_ts/aglapi/interfaces.d.ts +30 -0
- package/dist_ts/aglapi/interfaces.js +7 -1
- package/dist_ts/classes.authstore.d.ts +7 -0
- package/dist_ts/classes.authstore.js +12 -1
- package/dist_ts/classes.browserpainttransport.d.ts +2 -2
- package/dist_ts/classes.browserpainttransport.js +9 -8
- package/dist_ts/classes.browserresourcehost.js +30 -20
- package/dist_ts/classes.cli.js +10 -1
- package/dist_ts/classes.controller.d.ts +41 -11
- package/dist_ts/classes.controller.js +232 -52
- package/dist_ts/classes.harnessoperationmanager.d.ts +44 -0
- package/dist_ts/classes.harnessoperationmanager.js +15 -10
- package/dist_ts/classes.mcpclient.d.ts +5 -0
- package/dist_ts/classes.mcpclient.js +15 -3
- package/dist_ts/classes.mcpcontrollerhost.d.ts +3 -0
- package/dist_ts/classes.mcpcontrollerhost.js +17 -3
- package/dist_ts/classes.mcptools.d.ts +4 -3
- package/dist_ts/classes.mcptools.js +20 -1
- package/dist_ts/classes.mcpvalidation.js +4 -1
- package/dist_ts/classes.ticketstore.d.ts +71 -3
- package/dist_ts/classes.ticketstore.js +299 -12
- package/dist_ts/classes.validation.d.ts +2 -0
- package/dist_ts/classes.validation.js +27 -5
- package/dist_ts/driver/classes.directreports.d.ts +23 -3
- package/dist_ts/driver/classes.directreports.js +59 -2
- package/dist_ts/driver/classes.drivereventrelay.js +3 -2
- package/dist_ts/driver/functions.driverinstructions.d.ts +1 -1
- package/dist_ts/driver/functions.driverinstructions.js +12 -3
- package/dist_ts/driver/functions.drivertools.d.ts +4 -0
- package/dist_ts/driver/functions.drivertools.js +8 -2
- package/dist_ts/fleet/classes.boardpump.d.ts +53 -3
- package/dist_ts/fleet/classes.boardpump.js +237 -32
- package/dist_ts/fleet/classes.claudeworkers.d.ts +10 -3
- package/dist_ts/fleet/classes.claudeworkers.js +43 -19
- package/dist_ts/fleet/classes.codexworkers.d.ts +5 -3
- package/dist_ts/fleet/classes.codexworkers.js +26 -9
- package/dist_ts/fleet/classes.deploymonitor.d.ts +253 -0
- package/dist_ts/fleet/classes.deploymonitor.js +821 -0
- package/dist_ts/fleet/classes.gitfacts.d.ts +61 -0
- package/dist_ts/fleet/classes.gitfacts.js +125 -0
- package/dist_ts/fleet/classes.releasereconciler.d.ts +51 -0
- package/dist_ts/fleet/classes.releasereconciler.js +101 -0
- package/dist_ts/fleet/classes.service.d.ts +13 -1
- package/dist_ts/fleet/classes.service.js +76 -7
- package/dist_ts/fleet/classes.ticketeffects.d.ts +13 -0
- package/dist_ts/fleet/classes.ticketeffects.js +42 -8
- package/dist_ts/fleet/classes.workers.d.ts +10 -3
- package/dist_ts/fleet/classes.workers.js +18 -3
- package/dist_ts/fleet/functions.controllerbuild.d.ts +23 -0
- package/dist_ts/fleet/functions.controllerbuild.js +75 -0
- package/dist_ts/fleet/functions.deployprobes.d.ts +39 -0
- package/dist_ts/fleet/functions.deployprobes.js +82 -0
- package/dist_ts/fleet/functions.deployvalidation.d.ts +27 -0
- package/dist_ts/fleet/functions.deployvalidation.js +43 -0
- package/dist_ts/fleet/functions.release.d.ts +2 -1
- package/dist_ts/fleet/functions.release.js +32 -5
- package/dist_ts/fleet/functions.releasefacts.d.ts +42 -0
- package/dist_ts/fleet/functions.releasefacts.js +46 -0
- package/dist_ts/fleet/functions.validation.d.ts +3 -3
- package/dist_ts/fleet/functions.validation.js +4 -7
- package/dist_ts/fleet/functions.watchprobes.js +7 -9
- package/dist_ts/fleet/functions.workervalidation.js +4 -3
- package/dist_ts/fleet/interfaces.workers.d.ts +30 -3
- package/dist_ts/fleet/interfaces.workers.js +14 -1
- package/dist_ts/functions.deploycli.d.ts +36 -0
- package/dist_ts/functions.deploycli.js +157 -0
- package/dist_ts/functions.mcpdeploytools.d.ts +13 -0
- package/dist_ts/functions.mcpdeploytools.js +16 -0
- package/dist_ts/functions.mcptickettools.d.ts +54 -0
- package/dist_ts/functions.mcptickettools.js +8 -7
- package/dist_ts/functions.ticketautolabels.d.ts +2 -0
- package/dist_ts/functions.ticketautolabels.js +9 -3
- package/dist_ts/functions.ticketcli.d.ts +16 -2
- package/dist_ts/functions.ticketcli.js +105 -27
- package/dist_ts/functions.ticketvalidation.d.ts +55 -0
- package/dist_ts/functions.ticketvalidation.js +26 -8
- package/dist_ts_interfaces/deployments.d.ts +241 -0
- package/dist_ts_interfaces/deployments.js +5 -6
- package/dist_ts_interfaces/fleet.d.ts +12 -0
- package/dist_ts_interfaces/fleetworkers.d.ts +21 -1
- package/dist_ts_interfaces/functions.fleetversion.d.ts +4 -0
- package/dist_ts_interfaces/functions.fleetversion.js +25 -0
- package/dist_ts_interfaces/interfaces.d.ts +4 -2
- package/dist_ts_interfaces/interfaces.js +4 -2
- package/dist_ts_interfaces/mcprequests.d.ts +3 -2
- package/dist_ts_interfaces/mcprequests.js +3 -1
- package/dist_ts_interfaces/requests.d.ts +3 -2
- package/dist_ts_interfaces/requests.directreports.d.ts +58 -6
- package/dist_ts_interfaces/requests.js +1 -1
- package/dist_ts_interfaces/requests.tickets.d.ts +25 -5
- package/dist_ts_interfaces/requests.tickets.js +2 -2
- package/dist_ts_interfaces/tickets.d.ts +71 -6
- package/dist_ts_interfaces/tickets.js +34 -6
- package/dist_ts_migration/classes.documentmigrationrunner.d.ts +7 -0
- package/dist_ts_migration/classes.documentmigrationrunner.js +14 -1
- package/dist_ts_migration/index.d.ts +2 -0
- package/dist_ts_migration/index.js +3 -1
- package/dist_ts_migration/v41_ticketclosedcolumn.d.ts +20 -0
- package/dist_ts_migration/v41_ticketclosedcolumn.js +118 -0
- package/dist_ts_migration/v41_ticketlinkrepos.d.ts +24 -0
- package/dist_ts_migration/v41_ticketlinkrepos.js +101 -0
- package/package.json +6 -2
- package/readme.md +308 -36
- package/third-party-notices.md +597 -8
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/aglapi/aglapisurface.document.ts +113 -15
- package/ts/aglapi/interfaces.ts +6 -0
- package/ts/classes.authstore.ts +13 -0
- package/ts/classes.browserpainttransport.ts +8 -7
- package/ts/classes.browserresourcehost.ts +38 -14
- package/ts/classes.cli.ts +9 -0
- package/ts/classes.controller.ts +244 -61
- package/ts/classes.harnessoperationmanager.ts +20 -14
- package/ts/classes.mcpclient.ts +17 -2
- package/ts/classes.mcpcontrollerhost.ts +18 -2
- package/ts/classes.mcptools.ts +21 -2
- package/ts/classes.mcpvalidation.ts +2 -0
- package/ts/classes.ticketstore.ts +312 -13
- package/ts/classes.validation.ts +28 -4
- package/ts/driver/classes.directreports.ts +58 -3
- package/ts/driver/classes.drivereventrelay.ts +2 -1
- package/ts/driver/functions.driverinstructions.ts +11 -2
- package/ts/driver/functions.drivertools.ts +10 -2
- package/ts/fleet/classes.boardpump.ts +235 -28
- package/ts/fleet/classes.claudeworkers.ts +36 -15
- package/ts/fleet/classes.codexworkers.ts +24 -7
- package/ts/fleet/classes.deploymonitor.ts +854 -0
- package/ts/fleet/classes.gitfacts.ts +135 -0
- package/ts/fleet/classes.releasereconciler.ts +103 -0
- package/ts/fleet/classes.service.ts +81 -8
- package/ts/fleet/classes.ticketeffects.ts +38 -6
- package/ts/fleet/classes.workers.ts +19 -5
- package/ts/fleet/functions.controllerbuild.ts +84 -0
- package/ts/fleet/functions.deployprobes.ts +84 -0
- package/ts/fleet/functions.deployvalidation.ts +50 -0
- package/ts/fleet/functions.release.ts +32 -3
- package/ts/fleet/functions.releasefacts.ts +74 -0
- package/ts/fleet/functions.validation.ts +3 -6
- package/ts/fleet/functions.watchprobes.ts +6 -8
- package/ts/fleet/functions.workervalidation.ts +3 -2
- package/ts/fleet/interfaces.workers.ts +23 -3
- package/ts/functions.deploycli.ts +156 -0
- package/ts/functions.mcpdeploytools.ts +18 -0
- package/ts/functions.mcptickettools.ts +7 -6
- package/ts/functions.ticketautolabels.ts +10 -2
- package/ts/functions.ticketcli.ts +100 -24
- package/ts/functions.ticketvalidation.ts +26 -7
- package/ts_interfaces/deployments.ts +194 -0
- package/ts_interfaces/fleet.ts +17 -2
- package/ts_interfaces/fleetworkers.ts +20 -0
- package/ts_interfaces/functions.fleetversion.ts +20 -0
- package/ts_interfaces/interfaces.ts +3 -1
- package/ts_interfaces/mcprequests.ts +3 -0
- package/ts_interfaces/requests.directreports.ts +52 -8
- package/ts_interfaces/requests.tickets.ts +20 -4
- package/ts_interfaces/requests.ts +6 -1
- package/ts_interfaces/tickets.ts +53 -6
- package/ts_migration/classes.documentmigrationrunner.ts +15 -0
- package/ts_migration/index.ts +2 -0
- package/ts_migration/v41_ticketclosedcolumn.ts +106 -0
- package/ts_migration/v41_ticketlinkrepos.ts +91 -0
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/elements.deployments.ts +1066 -0
- package/ts_web/elements.directreport.ts +2 -2
- package/ts_web/elements.directreportsession.ts +5 -5
- package/ts_web/elements.harnesscontrollerapp.ts +179 -13
- package/ts_web/elements.makedirectreport.ts +444 -0
- package/ts_web/elements.nativesession.ts +29 -1
- package/ts_web/elements.ticketboard.ts +74 -18
- package/ts_web/functions.deployments.ts +231 -0
- package/ts_web/functions.sessionchat.ts +2 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { TFleetDeployProbe } from '../../ts_interfaces/deployments.js';
|
|
2
|
+
import { fleetVersion } from './functions.releasefacts.js';
|
|
3
|
+
|
|
4
|
+
/** How an HTTP probe reaches its URL: `fetch` for tests, a timeout and the caller's signal. */
|
|
5
|
+
export interface IFleetHttpProbeOptions {
|
|
6
|
+
signal: AbortSignal;
|
|
7
|
+
timeoutMs: number;
|
|
8
|
+
fetch?: typeof fetch;
|
|
9
|
+
}
|
|
10
|
+
/** What an HTTP GET answered: its status and, when asked, its JSON body (undefined when it is none). */
|
|
11
|
+
export interface IFleetHttpAnswer { status: number; json?: unknown }
|
|
12
|
+
|
|
13
|
+
/** A probe failure as one line, with its cause (a refused connection, a DNS failure). */
|
|
14
|
+
export const fleetProbeErrorText = (errorArg: unknown): string => {
|
|
15
|
+
const cause = errorArg instanceof Error && errorArg.cause instanceof Error ? `: ${errorArg.cause.message}` : '';
|
|
16
|
+
return errorArg instanceof Error ? `${errorArg.message}${cause}` : String(errorArg);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** A JSON answer is read up to this size; a version endpoint answers a few hundred bytes. */
|
|
20
|
+
const maximumJsonBytes = 64 * 1024;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* One HTTP GET, shared by `fleet watch --site` and the deploy probes. `json` reads the body as JSON (bounded); otherwise
|
|
24
|
+
* the body is dropped. `redirect: 'manual'` reports a redirect's own status. Throws when nothing answered.
|
|
25
|
+
*/
|
|
26
|
+
export const fetchFleetProbe = async (urlArg: string, optionsArg: IFleetHttpProbeOptions,
|
|
27
|
+
readArg: { json?: boolean; redirect?: 'manual' | 'follow' | 'error' } = {}): Promise<IFleetHttpAnswer> => {
|
|
28
|
+
const response = await (optionsArg.fetch ?? fetch)(urlArg, { redirect: readArg.redirect ?? 'follow',
|
|
29
|
+
headers: readArg.json ? { accept: 'application/json' } : {},
|
|
30
|
+
signal: AbortSignal.any([optionsArg.signal, AbortSignal.timeout(optionsArg.timeoutMs)]) });
|
|
31
|
+
if (!readArg.json || response.status >= 400 || !response.body) {
|
|
32
|
+
await response.body?.cancel();
|
|
33
|
+
return { status: response.status };
|
|
34
|
+
}
|
|
35
|
+
const reader = response.body.getReader();
|
|
36
|
+
const chunks: Uint8Array[] = [];
|
|
37
|
+
let size = 0;
|
|
38
|
+
while (true) {
|
|
39
|
+
const { done, value } = await reader.read();
|
|
40
|
+
if (done) break;
|
|
41
|
+
size += value.byteLength;
|
|
42
|
+
if (size > maximumJsonBytes) { await reader.cancel(); return { status: response.status }; }
|
|
43
|
+
chunks.push(value);
|
|
44
|
+
}
|
|
45
|
+
try { return { status: response.status, json: JSON.parse(Buffer.concat(chunks).toString('utf8')) as unknown }; }
|
|
46
|
+
catch { return { status: response.status }; }
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** The value an RFC 6901 JSON pointer names, or undefined. */
|
|
50
|
+
export const readJsonPointer = (valueArg: unknown, pointerArg: string): unknown => {
|
|
51
|
+
if (pointerArg === '') return valueArg;
|
|
52
|
+
let current = valueArg;
|
|
53
|
+
for (const token of pointerArg.slice(1).split('/').map((partArg) => partArg.replaceAll('~1', '/').replaceAll('~0', '~'))) {
|
|
54
|
+
if (Array.isArray(current) && /^(?:0|[1-9][0-9]*)$/u.test(token)) current = current[Number(token)];
|
|
55
|
+
else if (current !== null && typeof current === 'object' && Object.hasOwn(current, token)) current = (current as Record<string, unknown>)[token];
|
|
56
|
+
else return undefined;
|
|
57
|
+
}
|
|
58
|
+
return current;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type TFleetDeployProbeResult = { state: 'up'; version: string; sha?: string } | { state: 'down'; error: string };
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Asks an HTTP target what it runs: a GET of its URL, the version at `versionPointer` (default `/version`) and the commit
|
|
65
|
+
* at `shaPointer`. An error status, an answer that is no JSON or holds no semantic version is down, with the reason.
|
|
66
|
+
*/
|
|
67
|
+
export const probeFleetHttpTarget = async (probeArg: Extract<TFleetDeployProbe, { kind: 'http' }>,
|
|
68
|
+
optionsArg: IFleetHttpProbeOptions): Promise<TFleetDeployProbeResult> => {
|
|
69
|
+
let answer: IFleetHttpAnswer;
|
|
70
|
+
// A deploy probe follows no redirect: one to another host or to plain http would answer for something else.
|
|
71
|
+
try { answer = await fetchFleetProbe(probeArg.url, optionsArg, { json: true, redirect: 'error' }); }
|
|
72
|
+
catch (errorArg) {
|
|
73
|
+
optionsArg.signal.throwIfAborted();
|
|
74
|
+
return { state: 'down', error: fleetProbeErrorText(errorArg).slice(0, 1024) };
|
|
75
|
+
}
|
|
76
|
+
if (answer.status >= 400) return { state: 'down', error: `HTTP ${answer.status}` };
|
|
77
|
+
const pointer = probeArg.versionPointer ?? '/version';
|
|
78
|
+
const rawVersion = readJsonPointer(answer.json, pointer);
|
|
79
|
+
const version = typeof rawVersion === 'string' ? fleetVersion(rawVersion) : undefined;
|
|
80
|
+
if (!version) return { state: 'down', error: `HTTP ${answer.status} without a version at ${pointer}` };
|
|
81
|
+
const rawSha = probeArg.shaPointer === undefined ? undefined : readJsonPointer(answer.json, probeArg.shaPointer);
|
|
82
|
+
const sha = typeof rawSha === 'string' && /^[a-f0-9]{7,64}$/u.test(rawSha) ? rawSha : undefined;
|
|
83
|
+
return { state: 'up', version, ...(sha ? { sha } : {}) };
|
|
84
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as plugins from '../plugins.js';
|
|
2
|
+
import {
|
|
3
|
+
fleetDeployOperations, fleetDeployTargetIdPattern, type IFleetDeployOperations, type TControllerMcpDeployMethod, type TFleetDeployOperation,
|
|
4
|
+
} from '../../ts_interfaces/deployments.js';
|
|
5
|
+
|
|
6
|
+
const targetId = plugins.z.string().regex(fleetDeployTargetIdPattern);
|
|
7
|
+
/** The request of each deploy operation, as the browser, `agl deploy` and the driver send it. */
|
|
8
|
+
export const fleetDeployRequestSchemas = {
|
|
9
|
+
status: plugins.z.object({ targetId: targetId.optional() }).strict(),
|
|
10
|
+
history: plugins.z.object({ targetId, limit: plugins.z.number().int().min(1).max(200).optional() }).strict(),
|
|
11
|
+
probe: plugins.z.object({ targetId }).strict(),
|
|
12
|
+
release: plugins.z.object({ repo: plugins.z.string().min(1).max(1024).refine((valueArg) => !/[\0\r\n]/u.test(valueArg)).optional() }).strict(),
|
|
13
|
+
ticket: plugins.z.object({ ticketKey: plugins.z.string().regex(/^AGL-[1-9][0-9]*$/u) }).strict(),
|
|
14
|
+
} as const satisfies Record<TFleetDeployOperation, plugins.z.ZodType>;
|
|
15
|
+
|
|
16
|
+
export const assertFleetDeployRequest = <TOperation extends TFleetDeployOperation>(
|
|
17
|
+
operationArg: TOperation, valueArg: unknown,
|
|
18
|
+
): IFleetDeployOperations[TOperation]['request'] => fleetDeployRequestSchemas[operationArg].parse(valueArg) as IFleetDeployOperations[TOperation]['request'];
|
|
19
|
+
|
|
20
|
+
export const fleetDeployOperation = (methodArg: string): TFleetDeployOperation => {
|
|
21
|
+
const operation = methodArg.split('.').at(-1) as TFleetDeployOperation;
|
|
22
|
+
if (!(fleetDeployOperations as readonly string[]).includes(operation)) throw new Error('Invalid deploy operation.');
|
|
23
|
+
return operation;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** A private-channel deploy request: the local owner capability, then the operation's own fields. */
|
|
27
|
+
export const assertFleetDeployWireRequest = (methodArg: TControllerMcpDeployMethod | string, valueArg: unknown): Record<string, unknown> => {
|
|
28
|
+
const value = plugins.z.object({ ownerToken: plugins.z.string().min(1).max(1024) }).passthrough().parse(valueArg);
|
|
29
|
+
const { ownerToken, ...request } = value;
|
|
30
|
+
return { ownerToken, ...assertFleetDeployRequest(fleetDeployOperation(methodArg), request) };
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/** A deploy answer as `agl deploy` prints it: its shape, not every field. */
|
|
34
|
+
export const assertFleetDeployResponse = (methodArg: string, valueArg: unknown): void => {
|
|
35
|
+
const operation = fleetDeployOperation(methodArg);
|
|
36
|
+
const target = plugins.z.object({ target: plugins.z.object({ id: targetId, repo: plugins.z.string() }).passthrough(),
|
|
37
|
+
probe: plugins.z.object({ state: plugins.z.enum(['up', 'down', 'unknown']) }).passthrough() }).passthrough();
|
|
38
|
+
const schemas = {
|
|
39
|
+
status: plugins.z.object({ checkedAt: plugins.z.string(), targets: plugins.z.array(target),
|
|
40
|
+
windows: plugins.z.array(plugins.z.object({ key: plugins.z.string(), from: plugins.z.string(), to: plugins.z.string() }).passthrough()) }).strict(),
|
|
41
|
+
history: plugins.z.object({ targetId, observations: plugins.z.array(plugins.z.object({ targetId, version: plugins.z.string(),
|
|
42
|
+
observedAt: plugins.z.string() }).passthrough()) }).strict(),
|
|
43
|
+
probe: target,
|
|
44
|
+
release: plugins.z.object({ checkedAt: plugins.z.string(), repositories: plugins.z.array(plugins.z.object({ repo: plugins.z.string(),
|
|
45
|
+
id: plugins.z.string() }).passthrough()) }).strict(),
|
|
46
|
+
ticket: plugins.z.object({ ticketKey: plugins.z.string(), landed: plugins.z.array(plugins.z.unknown()), runs: plugins.z.array(plugins.z.unknown()),
|
|
47
|
+
foundIn: plugins.z.array(plugins.z.unknown()) }).passthrough(),
|
|
48
|
+
};
|
|
49
|
+
schemas[operation].parse(valueArg);
|
|
50
|
+
};
|
|
@@ -4,6 +4,7 @@ import type { IFleetRuntime } from './interfaces.js';
|
|
|
4
4
|
import { restoreFleetLockIntegrity } from './functions.rebase.js';
|
|
5
5
|
import { parseFleetTestCount } from './classes.runtime.js';
|
|
6
6
|
import { parseFleetToolingSpec } from './functions.validation.js';
|
|
7
|
+
import { fleetRepositorySlug, type IFleetReleaseGuard } from './functions.releasefacts.js';
|
|
7
8
|
|
|
8
9
|
interface IFleetManifest {
|
|
9
10
|
packageManager?: string;
|
|
@@ -225,6 +226,18 @@ const assertRemoteTip = async (runtime: IFleetRuntime, repo: IFleetRepository, s
|
|
|
225
226
|
}
|
|
226
227
|
};
|
|
227
228
|
|
|
229
|
+
/**
|
|
230
|
+
* The commit the remote's tag `v<version>` names, peeled to its commit; undefined while the remote has no such tag. A
|
|
231
|
+
* release is the remote's tag (AGL-909): a tag that a release config which pushes no git left in the checkout is none.
|
|
232
|
+
*/
|
|
233
|
+
const remoteTagSha = async (runtime: IFleetRuntime, repo: IFleetRepository, versionArg: string): Promise<string | undefined> => {
|
|
234
|
+
const tag = `refs/tags/v${versionArg}`;
|
|
235
|
+
const listed = await runtime.git(repo.path, ['ls-remote', '--tags', repo.remote, tag, `${tag}^{}`]);
|
|
236
|
+
const refs = new Map(listed.split('\n').map((lineArg) => lineArg.trim().split(/\s+/u)).filter((partsArg) => partsArg.length === 2)
|
|
237
|
+
.map(([sha, ref]) => [ref!, sha!]));
|
|
238
|
+
return refs.get(`${tag}^{}`) ?? refs.get(tag);
|
|
239
|
+
};
|
|
240
|
+
|
|
228
241
|
export interface IFleetToolingSelection {
|
|
229
242
|
/** The pnpm version to pin; defaults to the newest one the effective minimum-release-age admits. */
|
|
230
243
|
pnpm?: string;
|
|
@@ -419,16 +432,30 @@ export const toolingFleetRepository = async (runtime: IFleetRuntime, repo: IFlee
|
|
|
419
432
|
|
|
420
433
|
/** The service owns the FIFO queue and interprocess repository lock for this whole operation. */
|
|
421
434
|
export const releaseFleetRepository = async (
|
|
422
|
-
runtime: IFleetRuntime, repo: IFleetRepository, request: IFleetReleaseRequest, timing: IFleetReleaseTiming = {},
|
|
435
|
+
runtime: IFleetRuntime, repo: IFleetRepository, request: IFleetReleaseRequest, timing: IFleetReleaseTiming = {}, guard: IFleetReleaseGuard = {},
|
|
423
436
|
): Promise<IFleetReleaseResult> => {
|
|
424
437
|
const environment = environmentFor(repo);
|
|
438
|
+
// The plan checks run first: `gitzone release --plan` is a read, so a release the plans refuse commits no tooling and
|
|
439
|
+
// runs no tests. They run again once the tooling commit is in.
|
|
440
|
+
const check = (planArg: IFleetReleasePlan) => {
|
|
441
|
+
if (request.plan !== undefined && request.plan.trim() !== `${planArg.from} -> ${planArg.version}`) {
|
|
442
|
+
throw new Error(`Release plan mismatch: expected ${request.plan}, got ${planArg.from} -> ${planArg.version}.`);
|
|
443
|
+
}
|
|
444
|
+
guard.plan?.(planArg);
|
|
445
|
+
};
|
|
446
|
+
await runtime.fetch(repo);
|
|
447
|
+
await runtime.clean(repo.path);
|
|
448
|
+
await runtime.assertMain(repo);
|
|
449
|
+
check(readReleasePlan(await runtime.checked('gitzone', ['release', '--plan'], repo.path, environment)));
|
|
425
450
|
const { toolingCommit, checks } = await updateFleetTooling(runtime, repo, environment);
|
|
426
451
|
await runtime.clean(repo.path);
|
|
427
452
|
const releaseBase = await runtime.assertMain(repo);
|
|
428
453
|
const plan = readReleasePlan(await runtime.checked('gitzone', ['release', '--plan'], repo.path, environment));
|
|
429
|
-
|
|
454
|
+
check(plan);
|
|
430
455
|
assertSet(repo.publishedPackages, plan.packages, 'publishedPackages');
|
|
431
456
|
assertSet(repo.registries, plan.registries, 'registries');
|
|
457
|
+
// What the release ships is known before it publishes: gitzone adds only its own release commit to the release base.
|
|
458
|
+
const contained = guard.ship ? await guard.ship(releaseBase, plan) : [];
|
|
432
459
|
await assertRemoteTip(runtime, repo, releaseBase);
|
|
433
460
|
await runtime.clean(repo.path);
|
|
434
461
|
if ((await runtime.git(repo.path, ['rev-parse', 'HEAD'])).trim() !== releaseBase) throw new Error('Canonical main moved after release planning.');
|
|
@@ -453,6 +480,8 @@ export const releaseFleetRepository = async (
|
|
|
453
480
|
checks.push({ name: `registry ${name}@${plan.version} ${registry}`, passed: 1, total: 1 });
|
|
454
481
|
}
|
|
455
482
|
}
|
|
483
|
+
const tagged = await remoteTagSha(runtime, repo, plan.version) === sha;
|
|
456
484
|
await runtime.clean(repo.path);
|
|
457
|
-
return { operation: 'release', repo: repo.id, sha, version: plan.version, toolingCommit, checks,
|
|
485
|
+
return { operation: 'release', repo: repo.id, repository: fleetRepositorySlug(repo), sha, version: plan.version, tagged, toolingCommit, checks,
|
|
486
|
+
packages: plan.packages, registries: plan.registries, ...(contained.length ? { contained } : {}) };
|
|
458
487
|
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { compareFleetVersions, fleetVersion } from '../../ts_interfaces/functions.fleetversion.js';
|
|
2
|
+
import * as plugins from '../plugins.js';
|
|
3
|
+
import type { IFleetRepository } from '../../ts_interfaces/fleet.js';
|
|
4
|
+
import type { TTicketData, TTicketLink } from '../../ts_interfaces/tickets.js';
|
|
5
|
+
|
|
6
|
+
/** What gitzone plans for a release: the version it moves from, and the one it releases. */
|
|
7
|
+
export interface IFleetPlannedRelease {
|
|
8
|
+
from: string;
|
|
9
|
+
version: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* What a release checks besides its own checks (AGL-909): `plan` refuses a version a ticket's release plan contradicts,
|
|
14
|
+
* before the tooling step and again before publishing; `ship` checks the commit the release is cut from and answers the
|
|
15
|
+
* landed tickets it ships, before anything is published.
|
|
16
|
+
*/
|
|
17
|
+
export interface IFleetReleaseGuard {
|
|
18
|
+
plan?(planArg: IFleetPlannedRelease): void;
|
|
19
|
+
ship?(releaseBaseArg: string, planArg: IFleetPlannedRelease): Promise<string[]>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A repository as `org/name`: its checkout's parent directory and its own name, as the board's plans and deploy targets
|
|
24
|
+
* name it (`modelprofile.com/agl`). The fleet id is the directory name alone unless another checkout shares it.
|
|
25
|
+
*/
|
|
26
|
+
export const fleetRepositorySlug = (repoArg: Pick<IFleetRepository, 'path'>): string => (
|
|
27
|
+
`${plugins.path.basename(plugins.path.dirname(repoArg.path))}/${plugins.path.basename(repoArg.path)}`
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
const realPaths = new Map<string, string>();
|
|
31
|
+
/** A checkout path through its symlinks, as discovery records it; a path that does not exist stays as it resolves. */
|
|
32
|
+
const realPath = (pathArg: string): string => {
|
|
33
|
+
const resolved = plugins.path.resolve(pathArg);
|
|
34
|
+
let real = realPaths.get(resolved);
|
|
35
|
+
if (real === undefined) {
|
|
36
|
+
try { real = plugins.fs.realpathSync(resolved); } catch { real = resolved; }
|
|
37
|
+
if (realPaths.size >= 4096) realPaths.clear();
|
|
38
|
+
realPaths.set(resolved, real);
|
|
39
|
+
}
|
|
40
|
+
return real;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Whether a repository name a link, plan or target carries names this repository: its fleet id, its `org/name` or its
|
|
45
|
+
* checkout's path, through symlinks as discovery resolves it. Hand-made links use all three. This and
|
|
46
|
+
* `findFleetRepository` are the one way every caller resolves a repository: the fleet service, release plans and
|
|
47
|
+
* `affects` links, the release plan guard, the board pump and the deploy monitor.
|
|
48
|
+
*/
|
|
49
|
+
export const fleetRepositoryMatches = (repoArg: Pick<IFleetRepository, 'id' | 'path'>, valueArg: string): boolean => (
|
|
50
|
+
valueArg === repoArg.id || valueArg === fleetRepositorySlug(repoArg)
|
|
51
|
+
|| plugins.path.isAbsolute(valueArg) && realPath(valueArg) === realPath(repoArg.path)
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
/** The one discovered repository a name matches, or undefined when none or several do. */
|
|
55
|
+
export const findFleetRepository = <TRepo extends Pick<IFleetRepository, 'id' | 'path'>>(repositoriesArg: TRepo[], valueArg: string): TRepo | undefined => {
|
|
56
|
+
const matches = repositoriesArg.filter((repoArg) => fleetRepositoryMatches(repoArg, valueArg));
|
|
57
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type TFleetGitRunner = (commandArg: string, argsArg: string[], cwdArg: string) => Promise<{ code: number; stdout: string; stderr: string }>;
|
|
61
|
+
|
|
62
|
+
export { compareFleetVersions, fleetVersion } from '../../ts_interfaces/functions.fleetversion.js';
|
|
63
|
+
|
|
64
|
+
/** Whether a release link names this repository: by its repository when it carries one, else by a package the repository publishes. */
|
|
65
|
+
export const fleetReleaseLinkMatches = (
|
|
66
|
+
linkArg: Extract<TTicketLink, { kind: 'release' }>, repoArg: Pick<IFleetRepository, 'id' | 'path' | 'publishedPackages'>,
|
|
67
|
+
): boolean => linkArg.repo !== undefined ? fleetRepositoryMatches(repoArg, linkArg.repo)
|
|
68
|
+
: linkArg.package !== undefined && (repoArg.publishedPackages ?? []).includes(linkArg.package);
|
|
69
|
+
|
|
70
|
+
/** The newest version a ticket was released as in this repository, from its release links. */
|
|
71
|
+
export const ticketReleasedVersion = (ticketArg: Pick<TTicketData, 'links'>, repoArg: Pick<IFleetRepository, 'id' | 'path' | 'publishedPackages'>): string | undefined => (
|
|
72
|
+
ticketArg.links.flatMap((linkArg) => linkArg.kind === 'release' && fleetReleaseLinkMatches(linkArg, repoArg) && fleetVersion(linkArg.version)
|
|
73
|
+
? [fleetVersion(linkArg.version)!] : []).sort(compareFleetVersions).at(-1)
|
|
74
|
+
);
|
|
@@ -140,14 +140,11 @@ const validateFleetDeployTargets = (input: unknown): void => {
|
|
|
140
140
|
};
|
|
141
141
|
/**
|
|
142
142
|
* Validates the Configuration master's `fleet` section. `save` checks a document being saved, which may be stricter
|
|
143
|
-
* than one being read: a field
|
|
144
|
-
*
|
|
143
|
+
* than one being read: a field one release reads but only the next one writes is refused on save in the first, so a
|
|
144
|
+
* rollback to it never meets a master it cannot run. Every field here is saved as it is read.
|
|
145
145
|
*/
|
|
146
|
-
export const validateFleetConfiguration = (input: unknown,
|
|
146
|
+
export const validateFleetConfiguration = (input: unknown, _optionsArg: { save?: boolean } = {}): IFleetConfiguration => {
|
|
147
147
|
const config = object(input); keys(config, [], ['environment', 'workerProfiles', 'driver', 'boardPump', 'deployTargets']);
|
|
148
|
-
if (optionsArg.save && config.deployTargets !== undefined) {
|
|
149
|
-
throw new Error('fleet.deployTargets is read by this AGL release and saved by the next one; upgrade AGL to configure deploy targets.');
|
|
150
|
-
}
|
|
151
148
|
if (config.environment !== undefined) validateEnvironment(config.environment);
|
|
152
149
|
if (config.workerProfiles !== undefined) validateFleetWorkerProfiles(config.workerProfiles);
|
|
153
150
|
if (config.driver !== undefined) validateFleetDriver(config.driver);
|
|
@@ -2,6 +2,7 @@ import * as plugins from '../plugins.js';
|
|
|
2
2
|
import type { IFleetEvent, IFleetWatchResult } from '../../ts_interfaces/fleetworkers.js';
|
|
3
3
|
import { fleetReportMarker } from './interfaces.workers.js';
|
|
4
4
|
import type { IFleetWatchDisconnection } from '../functions.fleetworkercli.js';
|
|
5
|
+
import { fetchFleetProbe, fleetProbeErrorText } from './functions.deployprobes.js';
|
|
5
6
|
|
|
6
7
|
/** A site the watch probes with an HTTP GET; a status below 400 is up. */
|
|
7
8
|
export interface IFleetWatchSite { name: string; url: string }
|
|
@@ -21,10 +22,7 @@ export interface IFleetWatchProbeOptions {
|
|
|
21
22
|
}
|
|
22
23
|
interface IProbeState { state: string; detail?: string }
|
|
23
24
|
|
|
24
|
-
const errorText =
|
|
25
|
-
const cause = error instanceof Error && error.cause instanceof Error ? `: ${error.cause.message}` : '';
|
|
26
|
-
return error instanceof Error ? `${error.message}${cause}` : String(error);
|
|
27
|
-
};
|
|
25
|
+
const errorText = fleetProbeErrorText;
|
|
28
26
|
/** `NAME=URL`, the URL http or https. */
|
|
29
27
|
export const parseFleetWatchSite = (value: string): IFleetWatchSite => {
|
|
30
28
|
const separator = value.indexOf('='), name = value.slice(0, separator), url = value.slice(separator + 1);
|
|
@@ -40,9 +38,8 @@ export const parseFleetWatchCi = (value: string): IFleetWatchCi => {
|
|
|
40
38
|
|
|
41
39
|
const probeSite = async (site: IFleetWatchSite, options: IFleetWatchProbeOptions): Promise<IProbeState> => {
|
|
42
40
|
try {
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
return { state: `${response.status < 400 ? 'up' : 'down'} ${response.status}` };
|
|
41
|
+
const { status } = await fetchFleetProbe(site.url, options, { redirect: 'manual' });
|
|
42
|
+
return { state: `${status < 400 ? 'up' : 'down'} ${status}` };
|
|
46
43
|
} catch (error) {
|
|
47
44
|
options.signal.throwIfAborted();
|
|
48
45
|
return { state: 'down', detail: errorText(error) };
|
|
@@ -103,7 +100,8 @@ const reportLine = (text: string): string => {
|
|
|
103
100
|
};
|
|
104
101
|
const eventLine = (event: IFleetEvent): string | undefined => {
|
|
105
102
|
if (event.kind === 'host.load') return undefined;
|
|
106
|
-
const subject = event.workerName ? `worker ${event.workerName}` : event.
|
|
103
|
+
const subject = event.workerName ? `worker ${event.workerName}` : event.target ? `deploy ${event.target}`
|
|
104
|
+
: event.repo ? `${event.kind.split('.')[0]} ${event.repo}` : event.ticketKey ? `ticket ${event.ticketKey}` : 'fleet';
|
|
107
105
|
const summary = event.kind === 'worker.report.mid_turn' ? `report: ${reportLine(event.text ?? '')}`
|
|
108
106
|
: event.kind === 'worker.turn.ended' ? `turn ended${event.status ? ` (${event.status})` : ''}`
|
|
109
107
|
: event.kind === 'worker.changed' ? `now ${event.status ?? 'unknown'}${event.error ? `: ${oneLine(event.error)}` : ''}`
|
|
@@ -116,12 +116,13 @@ const job = plugins.z.object({ id: text, action: plugins.z.enum(['start', 'adopt
|
|
|
116
116
|
});
|
|
117
117
|
const event = plugins.z.object({ id: plugins.z.number().int().positive(),
|
|
118
118
|
kind: plugins.z.enum(['worker.changed', 'worker.turn.ended', 'worker.report.mid_turn', 'worker.reaped', 'worker.credential.failed', 'worker.observation.failed', 'release.finished', 'release.failed', 'ticket.applied', 'ticket.failed', 'ticket.unknown',
|
|
119
|
-
'ticket.changed', 'ticket.notified', 'ticket.notification.failed', 'ticket.stalled', 'harness.release.discovered', '
|
|
119
|
+
'ticket.changed', 'ticket.notified', 'ticket.notification.failed', 'ticket.stalled', 'harness.release.discovered', 'deploy.observed',
|
|
120
|
+
'deploy.probe.failed', 'deploy.probe.recovered', 'host.load']),
|
|
120
121
|
occurredAt: text, workerId: text.optional(), workerName: name.optional(), sessionId: text.optional(), reportId: text.optional(), commentId: text.optional(), turnId: text.optional(), status: text.optional(),
|
|
121
122
|
ticketKey: ticketKey.optional(),
|
|
122
123
|
ticketSync: ticketSync.optional(),
|
|
123
124
|
text: plugins.z.string().max(64 * 1024).optional(), truncated: plugins.z.boolean().optional(), error: plugins.z.string().max(4096).optional(),
|
|
124
|
-
repo: text.optional(), operationId: text.optional(), version: text.optional(), metrics: plugins.z.record(plugins.z.string(), plugins.z.unknown()).optional() }).strict();
|
|
125
|
+
repo: text.optional(), operationId: text.optional(), version: text.optional(), target: text.optional(), metrics: plugins.z.record(plugins.z.string(), plugins.z.unknown()).optional() }).strict();
|
|
125
126
|
export const assertFleetWorkerResponse = <T extends TFleetWorkerAction>(action: T, input: unknown): TFleetWorkerResponse<T> => {
|
|
126
127
|
const schema = action === 'list' ? plugins.z.object({ workers: plugins.z.array(fleetWorkerSchema).max(1024) }).strict()
|
|
127
128
|
: action === 'watch' ? plugins.z.object({ cursor: fleetWorkerRequestSchemas.watch.shape.cursor.unwrap(), reset: plugins.z.boolean(), events: plugins.z.array(event).max(64) }).strict()
|
|
@@ -1,10 +1,25 @@
|
|
|
1
1
|
import * as plugins from '../plugins.js';
|
|
2
|
-
import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetWorkerAbsenceProof, IFleetWorkerSessionProof, IFleetWorkerRebindProof } from '../../ts_interfaces/fleetworkers.js';
|
|
2
|
+
import type { IFleetWorker, IFleetWorkerProfile, IFleetWorkerReport, IFleetRelaunchBlocker, IFleetWorkerAbsenceProof, IFleetWorkerSessionProof, IFleetWorkerRebindProof } from '../../ts_interfaces/fleetworkers.js';
|
|
3
3
|
import type { IControllerMessageBundle, IControllerPermission, IControllerQuestion, TControllerPermissionReply } from '../../ts_interfaces/index.js';
|
|
4
4
|
|
|
5
5
|
export class FleetDispatchError extends Error {
|
|
6
6
|
constructor(message: string, public readonly dispatched: boolean, options?: ErrorOptions) { super(message, options); this.name = 'FleetDispatchError'; }
|
|
7
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* A native send refused before anything reached the session: its running turn is not the one the sender read
|
|
10
|
+
* (`concurrent_change`), the expected turn ended (`turn_ended`), or another client's turn was to be steered without
|
|
11
|
+
* naming it (`delivery_unsupported`).
|
|
12
|
+
*/
|
|
13
|
+
export class FleetNativeTurnError extends Error {
|
|
14
|
+
constructor(public readonly code: 'concurrent_change' | 'turn_ended' | 'delivery_unsupported', message: string) { super(message); this.name = 'FleetNativeTurnError'; }
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* How a native send treats the turn the session runs. With `expectedTurnId` the text steers only that running turn. An
|
|
18
|
+
* `agentMessage` steers a turn another client runs only when `expectedTurnId` names it, as an agent message must.
|
|
19
|
+
*/
|
|
20
|
+
export interface IFleetNativeSendTurn { expectedTurnId?: string; agentMessage?: boolean }
|
|
21
|
+
/** Whether a native send steered the running turn or started the next one, and that turn's id when known. */
|
|
22
|
+
export interface IFleetNativeSendReceipt { steered: boolean; turnId?: string }
|
|
8
23
|
export interface IFleetNativeEvent {
|
|
9
24
|
nativeId: string; kind: 'worker.turn.ended' | 'worker.report.mid_turn' | 'worker.reaped' | 'worker.credential.failed'; turnId?: string; status?: string;
|
|
10
25
|
text?: string; reportId?: string; truncated?: boolean; error?: string;
|
|
@@ -49,6 +64,8 @@ export interface IFleetWorkerBackend {
|
|
|
49
64
|
* control with `prompt`, and binds the session that continues it. Refuses while that session still runs; never stops it.
|
|
50
65
|
*/
|
|
51
66
|
relaunch?(worker: IFleetWorker, profile: IFleetWorkerProfile, nativeId: string, prompt: string, bind: (nativeId: string) => Promise<void>): Promise<void>;
|
|
67
|
+
/** Why `relaunch` of `nativeId` as a worker in `cwd` would refuse now, by the same checks, read-only; `undefined` when none does. */
|
|
68
|
+
relaunchBlocker?(cwd: string, profile: IFleetWorkerProfile, nativeId: string): Promise<IFleetRelaunchBlocker | undefined>;
|
|
52
69
|
poll(worker: IFleetWorker, profile: IFleetWorkerProfile): Promise<IFleetNativeEvent[]>;
|
|
53
70
|
observe(worker: IFleetWorker, profile: IFleetWorkerProfile): Promise<IFleetWorkerReport>;
|
|
54
71
|
send(messages: Array<{ worker: IFleetWorker; profile: IFleetWorkerProfile; text: string }>): Promise<void>;
|
|
@@ -61,9 +78,12 @@ export interface IFleetWorkerBackend {
|
|
|
61
78
|
nativeHistory?(session: IFleetNativeSession, limit: number, before?: string): Promise<IFleetNativePage>;
|
|
62
79
|
/**
|
|
63
80
|
* Sends `text` to a native session through the server that owns it. Resolves once the server took it; `settled` runs
|
|
64
|
-
* once the turn that took it ended, and never when the backend cannot prove that.
|
|
81
|
+
* once the turn that took it ended, and never when the backend cannot prove that. `turn` guards which running turn
|
|
82
|
+
* takes it; a refusal throws `FleetNativeTurnError` before anything was sent.
|
|
65
83
|
*/
|
|
66
|
-
nativeSend?(session: IFleetNativeSession, text: string, settled: () => void): Promise<
|
|
84
|
+
nativeSend?(session: IFleetNativeSession, text: string, settled: () => void, turn?: IFleetNativeSendTurn): Promise<IFleetNativeSendReceipt>;
|
|
85
|
+
/** The id of the turn a native session runs now, read-only; `undefined` while it runs none. */
|
|
86
|
+
nativeTurn?(session: IFleetNativeSession): Promise<string | undefined>;
|
|
67
87
|
/** The requests of turns the backend runs in a native session that wait for an answer. */
|
|
68
88
|
nativeAttention?(session: IFleetNativeSession): Promise<{ permissions: IControllerPermission[]; questions: IControllerQuestion[] }>;
|
|
69
89
|
nativeReply?(session: IFleetNativeSession, requestId: string, reply: { permission: TControllerPermissionReply } | { answers: string[][] | null }): Promise<void>;
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { ControllerMcpClient, type IControllerMcpClientOptions } from './classes.mcpclient.js';
|
|
2
|
+
import { withLocalConfigurationOwner } from './functions.configurationowner.js';
|
|
3
|
+
import { withCliDiagnostics } from './functions.clidiagnostics.js';
|
|
4
|
+
import { defaultControllerPort } from './classes.config.js';
|
|
5
|
+
import { assertFleetDeployRequest } from './fleet/functions.deployvalidation.js';
|
|
6
|
+
import type {
|
|
7
|
+
IFleetDeployObservation, IFleetDeployOperations, IFleetDeployPlan, IFleetDeployStatus, IFleetDeployTargetStatus, IFleetDeployWindow, IFleetReleaseStatus,
|
|
8
|
+
TFleetDeployOperation,
|
|
9
|
+
} from '../ts_interfaces/deployments.js';
|
|
10
|
+
|
|
11
|
+
export const deployCliHelp = `Usage: agl deploy status [TARGET] [--json]
|
|
12
|
+
agl deploy history TARGET [--limit N] [--json]
|
|
13
|
+
agl deploy probe TARGET [--json]
|
|
14
|
+
agl release status [REPO] [--json]
|
|
15
|
+
All commands accept --port PORT and require the running controller's local-owner capability.
|
|
16
|
+
What runs where is observed: every five minutes the controller asks each deploy target what it runs (the AGL
|
|
17
|
+
controller answers for itself; a target in the Configuration master's fleet.deployTargets is asked over HTTP) and
|
|
18
|
+
records a version whenever it changes. A release is the repository's tag v<version>.
|
|
19
|
+
status each target: the version it runs, its commit and since when, the probe state, the newest release, what
|
|
20
|
+
does not run there yet, the open bugs on the running version, when it may be deployed (any time, inside
|
|
21
|
+
a maintenance window, or for the AGL controller when no session is busy) and its deploy plans with the
|
|
22
|
+
owner's go; then the maintenance windows.
|
|
23
|
+
Plans are tickets: agl ticket create|update --deploy-plan TARGET@VERSION asks the owner whether to deploy (now,
|
|
24
|
+
in the next window, or hold), and --window FROM/TO --window-targets A,B plans a maintenance window (ISO 8601).
|
|
25
|
+
history the versions a target ran, newest first; a newer version before an older one is a rollback.
|
|
26
|
+
probe asks a target now and prints its status. Deploy scripts call it after a deploy; it claims nothing.
|
|
27
|
+
release a repository's newest release tag, its release plans and the landed tickets the next release would ship;
|
|
28
|
+
without REPO, every repository a target runs, a ticket plans or a landed ticket names.
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
export type TDeployCliArguments = { port: number; json: boolean } & (
|
|
32
|
+
| { operation: 'status'; request: IFleetDeployOperations['status']['request'] }
|
|
33
|
+
| { operation: 'history'; request: IFleetDeployOperations['history']['request'] }
|
|
34
|
+
| { operation: 'probe'; request: IFleetDeployOperations['probe']['request'] }
|
|
35
|
+
| { operation: 'release'; request: IFleetDeployOperations['release']['request'] }
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
/** `agl deploy …` (`commandArg` = 'deploy') or `agl release status …` (`commandArg` = 'release'). */
|
|
39
|
+
export const parseDeployCliArguments = (commandArg: 'deploy' | 'release', argsArg: string[]): TDeployCliArguments => {
|
|
40
|
+
const rest = [...argsArg], action = rest.shift();
|
|
41
|
+
const operation: TFleetDeployOperation | undefined = commandArg === 'release' ? (action === 'status' ? 'release' : undefined)
|
|
42
|
+
: action === 'status' || action === 'history' || action === 'probe' ? action : undefined;
|
|
43
|
+
if (!operation) throw new Error(deployCliHelp);
|
|
44
|
+
const subject = rest[0] !== undefined && !rest[0].startsWith('--') ? rest.shift() : undefined;
|
|
45
|
+
let port = defaultControllerPort, json = false, limit: number | undefined;
|
|
46
|
+
const seen = new Set<string>();
|
|
47
|
+
for (let index = 0; index < rest.length; index++) {
|
|
48
|
+
const flag = rest[index]!;
|
|
49
|
+
if (seen.has(flag)) throw new Error(`Duplicate deploy option: ${flag}.`);
|
|
50
|
+
seen.add(flag);
|
|
51
|
+
if (flag === '--json') { json = true; continue; }
|
|
52
|
+
const value = rest[++index];
|
|
53
|
+
if (value === undefined || value.startsWith('--')) throw new Error(`${flag} requires a value.`);
|
|
54
|
+
if (flag === '--port') { port = Number(value); continue; }
|
|
55
|
+
if (flag === '--limit' && operation === 'history') { limit = Number(value); continue; }
|
|
56
|
+
throw new Error(`Unknown deploy option: ${flag}.`);
|
|
57
|
+
}
|
|
58
|
+
if (!Number.isSafeInteger(port) || port < 1 || port > 65535) throw new Error('Invalid controller port.');
|
|
59
|
+
if ((operation === 'history' || operation === 'probe') && subject === undefined) throw new Error(`agl deploy ${operation} requires TARGET.`);
|
|
60
|
+
const base = { port, json };
|
|
61
|
+
if (operation === 'status') return { ...base, operation, request: assertFleetDeployRequest('status', subject === undefined ? {} : { targetId: subject }) };
|
|
62
|
+
if (operation === 'history') return { ...base, operation, request: assertFleetDeployRequest('history', { targetId: subject, ...(limit === undefined ? {} : { limit }) }) };
|
|
63
|
+
if (operation === 'probe') return { ...base, operation, request: assertFleetDeployRequest('probe', { targetId: subject }) };
|
|
64
|
+
return { ...base, operation, request: assertFleetDeployRequest('release', subject === undefined ? {} : { repo: subject }) };
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** `2026-10-25 10:05Z`. */
|
|
68
|
+
const minute = (isoArg: string | undefined): string => isoArg ? `${isoArg.slice(0, 10)} ${isoArg.slice(11, 16)}Z` : '';
|
|
69
|
+
const short = (shaArg: string | undefined): string => shaArg ? shaArg.slice(0, 7) : '';
|
|
70
|
+
const table = (rowsArg: string[][]): string[] => {
|
|
71
|
+
const widths = rowsArg[0]!.map((_cell, columnArg) => Math.max(...rowsArg.map((rowArg) => rowArg[columnArg]!.length)));
|
|
72
|
+
return rowsArg.map((rowArg) => rowArg.map((cellArg, columnArg) => columnArg === rowArg.length - 1 ? cellArg : cellArg.padEnd(widths[columnArg]! + 2)).join('').trimEnd());
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/** What a target does not run yet, in a few words. */
|
|
76
|
+
export const deployNotRunningText = (statusArg: IFleetDeployTargetStatus): string => {
|
|
77
|
+
if (!statusArg.running) return 'not observed yet';
|
|
78
|
+
const { releases, tickets } = statusArg.notRunning;
|
|
79
|
+
const rollback = statusArg.running.rolledBack ? `rolled back from ${statusArg.running.previousVersion}` : '';
|
|
80
|
+
const behind = releases.length ? `${releases.length} release${releases.length === 1 ? '' : 's'} · ${tickets.length} ticket${tickets.length === 1 ? '' : 's'}` : '';
|
|
81
|
+
return [rollback, behind].filter(Boolean).join(', ') || (statusArg.latest ? 'current' : 'no release tag');
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** When a target may be deployed, in a few words: any time, in a window (the next one), or when no session is busy. */
|
|
85
|
+
export const deployWhenText = (statusArg: IFleetDeployTargetStatus): string => {
|
|
86
|
+
if (statusArg.deployWhen === 'idle') return statusArg.busySessions ? `when idle (${statusArg.busySessions} busy)` : 'when idle (now)';
|
|
87
|
+
if (statusArg.deployWhen === 'anytime') return 'any time';
|
|
88
|
+
const window = statusArg.windows.find((windowArg) => windowArg.go === 'given');
|
|
89
|
+
const waiting = statusArg.windows.find((windowArg) => windowArg.go === 'waiting');
|
|
90
|
+
return window ? (window.state === 'active' ? `in window ${window.key} (open until ${minute(window.to)})` : `in window ${window.key} (${minute(window.from)})`)
|
|
91
|
+
: waiting ? `in a window (${waiting.key} waits on the owner's go)` : 'in a window (none planned)';
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** A deploy plan and the owner's go, in a few words. */
|
|
95
|
+
export const deployPlanText = (planArg: IFleetDeployPlan): string => `${planArg.key} ${planArg.version} ${
|
|
96
|
+
planArg.go === 'waiting' ? 'waits on the owner\'s go' : planArg.go === 'now' ? 'go: deploy now' : planArg.go === 'idle' ? 'go: when no session is busy'
|
|
97
|
+
: planArg.go === 'hold' ? 'held' : planArg.window ? `go: in window ${planArg.window.key}` : 'go: in the next window (none planned)'}`;
|
|
98
|
+
|
|
99
|
+
const windowGoText: Record<IFleetDeployWindow['go'], string> = { given: 'given', waiting: 'waits on the owner', declined: 'declined' };
|
|
100
|
+
const windowLines = (windowsArg: IFleetDeployWindow[]): string[] => windowsArg.length ? ['', ...table([['WINDOW', 'FROM', 'TO', 'TARGETS', 'STATE', 'GO', 'TITLE'],
|
|
101
|
+
...windowsArg.map((windowArg) => [windowArg.key, minute(windowArg.from), minute(windowArg.to), windowArg.targets.join(', '), windowArg.state,
|
|
102
|
+
windowGoText[windowArg.go], windowArg.title])])] : [];
|
|
103
|
+
|
|
104
|
+
export const deployStatusLines = (statusArg: IFleetDeployStatus): string[] => [...table([
|
|
105
|
+
['TARGET', 'RUNNING', 'SINCE', 'PROBE', 'LATEST', 'NOT RUNNING YET', 'BUGS', 'DEPLOYS', 'PLAN'],
|
|
106
|
+
...statusArg.targets.map((targetArg) => [
|
|
107
|
+
targetArg.target.id,
|
|
108
|
+
targetArg.running ? `${targetArg.running.version} ${short(targetArg.running.sha)}${targetArg.running.untagged ? ' untagged' : ''}`.trim() : '-',
|
|
109
|
+
minute(targetArg.running?.since) || '-',
|
|
110
|
+
targetArg.probe.state === 'down' ? `down since ${minute(targetArg.probe.downSince)}` : targetArg.probe.state,
|
|
111
|
+
targetArg.latest?.version ?? '-',
|
|
112
|
+
deployNotRunningText(targetArg),
|
|
113
|
+
targetArg.openBugs.length ? `${targetArg.openBugs.length} ${targetArg.openBugs.map((bugArg) => bugArg.key).join(', ')}` : '0',
|
|
114
|
+
deployWhenText(targetArg),
|
|
115
|
+
targetArg.deployPlans.map(deployPlanText).join('; ') || '-',
|
|
116
|
+
]),
|
|
117
|
+
]), ...windowLines(statusArg.windows)];
|
|
118
|
+
|
|
119
|
+
export const deployHistoryLines = (historyArg: { targetId: string; observations: IFleetDeployObservation[] }): string[] => (
|
|
120
|
+
historyArg.observations.length ? historyArg.observations.map((observationArg) => [minute(observationArg.observedAt), observationArg.version,
|
|
121
|
+
short(observationArg.sha), observationArg.previousVersion ? `(was ${observationArg.previousVersion})` : '(first observation)']
|
|
122
|
+
.filter(Boolean).join(' ')) : [`${historyArg.targetId}: no observation yet.`]
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
export const releaseStatusLines = (statusArg: IFleetReleaseStatus): string[] => statusArg.repositories.flatMap((repoArg) => [
|
|
126
|
+
`${repoArg.repo}${repoArg.targets.length ? ` (runs on ${repoArg.targets.join(', ')})` : ''}`,
|
|
127
|
+
` latest tag ${repoArg.latest ? `v${repoArg.latest.version} ${short(repoArg.latest.sha)} ${minute(repoArg.latest.taggedAt)}`.trimEnd() : 'none'}`,
|
|
128
|
+
...repoArg.plans.map((planArg) => ` plan ${planArg.key} ${planArg.plannedVersion ?? 'next'} ${planArg.priority === 'urgent' ? 'hotfix ' : ''}${planArg.title}`),
|
|
129
|
+
repoArg.landedAfterLatest.length ? ` landed after ${repoArg.latest ? `v${repoArg.latest.version}` : 'no release'}, would ship next` : ' nothing landed after the latest tag',
|
|
130
|
+
...repoArg.landedAfterLatest.map((ticketArg) => ` ${ticketArg.key} ${ticketArg.title}`),
|
|
131
|
+
]);
|
|
132
|
+
|
|
133
|
+
/** Fleet discovery, Git reads and joined probes can outlast the general 30-second private request budget. */
|
|
134
|
+
export const createDeployCliClient = (
|
|
135
|
+
optionsArg: Pick<IControllerMcpClientOptions, 'controllerPort' | 'paths'>,
|
|
136
|
+
): ControllerMcpClient => new ControllerMcpClient({ ...optionsArg, requestTimeoutMs: 120_000 });
|
|
137
|
+
|
|
138
|
+
export const runDeployCli = async (commandArg: 'deploy' | 'release', argsArg: string[]): Promise<void> => {
|
|
139
|
+
if (argsArg.includes('--help') || argsArg.includes('-h')) { process.stdout.write(deployCliHelp); return; }
|
|
140
|
+
try {
|
|
141
|
+
const parsed = parseDeployCliArguments(commandArg, argsArg), client = createDeployCliClient({ controllerPort: parsed.port });
|
|
142
|
+
await withCliDiagnostics(async () => withLocalConfigurationOwner(client, parsed.port, async (ownerToken) => {
|
|
143
|
+
const result = await client.deploy(parsed.operation, { ...parsed.request, ownerToken } as never);
|
|
144
|
+
if (parsed.json) { process.stdout.write(`${JSON.stringify(result)}\n`); return; }
|
|
145
|
+
const lines = parsed.operation === 'status' ? deployStatusLines(result as IFleetDeployStatus)
|
|
146
|
+
: parsed.operation === 'probe' ? deployStatusLines({ checkedAt: new Date().toISOString(), targets: [result as IFleetDeployTargetStatus], windows: [] })
|
|
147
|
+
: parsed.operation === 'history' ? deployHistoryLines(result as IFleetDeployOperations['history']['response'])
|
|
148
|
+
: releaseStatusLines(result as IFleetReleaseStatus);
|
|
149
|
+
process.stdout.write(lines.map((lineArg) => `${lineArg}\n`).join(''));
|
|
150
|
+
}));
|
|
151
|
+
} catch (errorArg) {
|
|
152
|
+
if (!argsArg.includes('--json')) throw errorArg;
|
|
153
|
+
process.stdout.write(`${JSON.stringify({ error: errorArg instanceof Error ? errorArg.message : 'Deploy command failed.' })}\n`);
|
|
154
|
+
process.exitCode = 1;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { fleetDeployRequestSchemas } from './fleet/functions.deployvalidation.js';
|
|
2
|
+
import type { TFleetDeployOperation } from '../ts_interfaces/deployments.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The deploy tools (AGL-911): what runs where, observed by each target's probe, and the release state computed from the
|
|
6
|
+
* repositories' tags and the board. The AGL MCP server offers them to the local owner, the driver as its own tools.
|
|
7
|
+
*/
|
|
8
|
+
export const deployToolDefinitions: readonly { name: string; operation: TFleetDeployOperation; description: string;
|
|
9
|
+
inputSchema: (typeof fleetDeployRequestSchemas)[TFleetDeployOperation]; readOnly: boolean }[] = [
|
|
10
|
+
{ name: 'deploy_status', operation: 'status', readOnly: true, inputSchema: fleetDeployRequestSchemas.status,
|
|
11
|
+
description: 'What each deploy target runs, as its probe observed it: the running version, its commit and since when, the probe state, the newest release, the releases and tickets that do not run there yet, the landed tickets the next release would ship, open bugs found in the running version whose fix does not run, and the release plans. What runs where is this answer, never notes or memory. targetId narrows it to one target; the AGL controller is the built-in target agl-controller.' },
|
|
12
|
+
{ name: 'deploy_history', operation: 'history', readOnly: true, inputSchema: fleetDeployRequestSchemas.history,
|
|
13
|
+
description: 'The versions a deploy target ran, newest first: one observation each time its probe answered another version, with the version before it (a newer one means a rollback).' },
|
|
14
|
+
{ name: 'deploy_probe', operation: 'probe', readOnly: false, inputSchema: fleetDeployRequestSchemas.probe,
|
|
15
|
+
description: 'Probe one deploy target now and answer its status. Run it after any deploy; it records what the target answers and claims nothing itself.' },
|
|
16
|
+
{ name: 'release_status', operation: 'release', readOnly: true, inputSchema: fleetDeployRequestSchemas.release,
|
|
17
|
+
description: 'The release state of a repository (repo as org/name, fleet id or checkout path), or of every repository a deploy target runs, a ticket plans or a landed ticket names: its newest release tag, the tickets planning its next release, and the landed tickets the newest release does not hold.' },
|
|
18
|
+
];
|