@revoengine/cli 1.0.22 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -3
- package/dist/src/cli.js +1 -1
- package/dist/src/client.d.ts +4 -2
- package/dist/src/client.js +13 -3
- package/dist/src/commands/component.js +37 -2
- package/dist/src/commands/migrate.js +5 -1
- package/dist/src/commands/terminal.d.ts +2 -0
- package/dist/src/commands/terminal.js +106 -31
- package/dist/src/migration.d.ts +2 -0
- package/dist/src/migration.js +12 -1
- package/dist/src/resource-syncs/endpoint-sync.js +16 -4
- package/dist/src/reviewed-plan.d.ts +2 -0
- package/dist/src/reviewed-plan.js +25 -0
- package/dist/src/types.d.ts +6 -0
- package/dist/src/workspace-prune.d.ts +8 -0
- package/dist/src/workspace-prune.js +12 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -82,6 +82,8 @@ revo terminal connect --workspace "$HOME/projects/my-project" --name "Work Mac"
|
|
|
82
82
|
revo terminal status
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
+
For an existing registration, `connect --terminal-id <uuid> --realtime-url <url>` overrides its Realtime endpoint for that invocation without pairing again or changing the saved registration. The URL is normalized to the runner WebSocket route; remote endpoints require TLS.
|
|
86
|
+
|
|
85
87
|
An approved terminal can run as a per-user background service on macOS or Linux. The service uses the active project at installation, or an explicit `--project <name>`; use the same project when uninstalling after a switch.
|
|
86
88
|
|
|
87
89
|
```bash
|
|
@@ -90,7 +92,9 @@ revo terminal service uninstall --workspace "$HOME/projects/my-project" --name "
|
|
|
90
92
|
revo terminal disconnect --workspace "$HOME/projects/my-project" --name "Work Mac"
|
|
91
93
|
```
|
|
92
94
|
|
|
93
|
-
Stop the foreground runner before installing its service. The service starts at login, reconnects automatically, and pins the selected terminal UUID and project profile at installation. Multiple terminals can share one machine and workspace when they have distinct names; pass the same `--name` to `connect`, `service install|uninstall`, and `disconnect`. Without `--name`, the CLI uses the machine hostname. If two registrations have the same name, the CLI refuses an ambiguous choice; use `revo terminal status` to find the UUID and pass `--terminal-id <uuid>`. A legacy workspace service must be uninstalled before installing a terminal-specific service. Uninstall stops the selected service but keeps its grant and local registration. `disconnect`
|
|
95
|
+
Stop the foreground runner before installing its service. The service starts at login, reconnects automatically, and pins the selected terminal UUID and project profile at installation. Multiple terminals can share one machine and workspace when they have distinct names; pass the same `--name` to `connect`, `service install|uninstall`, and `disconnect`. Without `--name`, the CLI uses the machine hostname. If two registrations have the same name, the CLI refuses an ambiguous choice; use `revo terminal status` to find the UUID and pass `--terminal-id <uuid>`. A legacy workspace service must be uninstalled before installing a terminal-specific service. Uninstall stops the selected service but keeps its grant and local registration. `disconnect` stops/removes the selected terminal-specific service, revokes its grant and removes its local credential. Uninstall a legacy workspace service first so it cannot affect a different terminal. On macOS, service logs are in `~/Library/Logs/RevoEngine/`. On Linux, inspect them with `journalctl --user -u <unit-name>`; `install` prints the unit name. Linux user services normally stop after logout unless an administrator enables user lingering.
|
|
96
|
+
|
|
97
|
+
The runner retries temporary API startup failures and WebSocket outages without a retry-count limit, using exponential backoff capped at 30 seconds with jitter. Startup reads have a 30-second request deadline; pairing and other writes are not automatically repeated. Ctrl+C or SIGTERM interrupts both a pending API request and a reconnect wait. Realtime restarts and Cloud Run connection timeouts renew transport without revoking the device. A newly supported ACL-change renewal immediately stops work under the old connection and reconnects against the current approved grant; it never extends the old command permission. Older runners stop on that change and need restarting. Actual grant/account/API-key revocation, expiration or invalid frames stop the runner; background services do not restart these deliberate security cutoffs. Availability has no fixed 30-day runner expiry, but depends on the machine, network, valid credentials and supervisor remaining available. An outage longer than the three-minute recovery window stops existing processes and Browser sessions; the runner continues reconnecting afterward.
|
|
94
98
|
|
|
95
99
|
Runner credentials are stored in `runner.json` beside the CLI configuration. Each executed shell command writes raw output to a private `runner-logs/<executionId>.log` there, capped at 10 MB per file. Logs older than 24 hours are removed when the next command starts; a runner left idle does not perform timed cleanup. Optional CLI HTTP tracing writes sanitized request metadata under the project `.revoengine/logs/http-trace/`. These are separate from the Assistant's server-side tool history and do not form a complete local transcript. Treat runner logs as sensitive because command output may contain secrets.
|
|
96
100
|
|
|
@@ -327,9 +331,9 @@ The planner lists exact target IDs, names and Stable Keys in deletion order. Dup
|
|
|
327
331
|
|
|
328
332
|
All other deletions run after upserts and their readback verification, allowing a retained Job Template or Endpoint to move to a replacement Component. Pruning removes obsolete consumers before dependencies. API errors or failed readback stop further deletes; a failed early delete prevents upserts, and a failed upsert prevents the remaining prune. Early deletions can remain applied if a later write fails, so review both deletion phases before approval. The owning APIs retain their existing permission and reference guards and soft-delete semantics, including the table subtree lifecycle and view automation deactivation. Root deletion is blocked by any retained or unmanaged partition. No arbitrary implicit consumer cleanup is performed.
|
|
329
333
|
|
|
330
|
-
`plan --out <file>` saves the plan without mutation or lock changes. `deploy --reviewed-plan <file>` requires `--prune` and
|
|
334
|
+
`plan --out <file>` saves the plan without mutation or lock changes. `deploy --reviewed-plan <file>` requires `--prune` and fences the whole reviewed deployment: desired and target definition hashes for every tracked family (including noops), managed target identities, versions and activation, authenticated instance, policy, tracked scope, and the deletion list with its timing (`beforeUpserts: true` where required). Drift or an older artifact without `reviewedPlanVersion: 1` blocks all writes and requires a fresh reviewed plan. The same comparison runs again after confirmation. Component writes retain the reviewed target identity, hash and version through execution: metadata and element saves obtain API mutation reviews and send their tokens in `x-revo-mutation-review`. A later version change, unavailable review route, or malformed review stops the deployment instead of refreshing the expected version or forcing the write. Regenerate reviewed plans saved by older CLI versions for replacements that now require early deletion. Each early deletion rechecks the remaining Job Template/Event/Schedule graph. Upserts are followed by another live comparison of the remaining prune plan. Each deletion rechecks identity and definition, verifies disappearance from the active catalog and clears only the selected target baseline; verified partition deletion retains its lock tombstone. Cascading table/view operations additionally recheck the remaining dependency graph. Deployment remains a sequence of API operations, not one server-side transaction: concurrent edits can cause a guarded rejection after earlier verified writes. Metadata and elements are separate guarded writes; the elements expect only the version increment made by this deployment. Readback verifies the accepted result but never authorizes overwriting newer target changes. A fresh plan is required after target drift or a failed partial deployment.
|
|
331
335
|
|
|
332
|
-
`deploy` always shows the plan before interactive confirmation; `--yes` supplies noninteractive approval. Ordinary resource rows, field names, dependency hints and metadata use one line per item. Field/value diffs, list changes and code/SQL diffs retain multiline Git-style formatting. `revo version --json` advertises `workspacePrune` and `
|
|
336
|
+
`deploy` always shows the plan before interactive confirmation; `--yes` supplies noninteractive approval. Ordinary resource rows, field names, dependency hints and metadata use one line per item. Field/value diffs, list changes and code/SQL diffs retain multiline Git-style formatting. `revo version --json` advertises `workspacePrune`, `reviewedPrunePlan`, `reviewedDeploymentPlan` and `componentMutationReview` so CI can reject older releases that ignore unknown flags. Without `--prune`, repository deployment remains upsert-only.
|
|
333
337
|
|
|
334
338
|
Component-only reconciliation remains available through `revo component plan --all --prune` and `revo component push --all --prune --yes`; interactive confirmation is also supported. This matches the configured identity, rechecks local reappearance and live target drift, verifies deletion and clears only the selected environment baseline. `--force` is not required for explicit Component pruning. Named `migrate` and legacy `env apply` retain their existing scope and confirmation rules; `migrate --prune` is rejected.
|
|
335
339
|
|
|
@@ -458,6 +462,8 @@ revo database-tables push 'Sales/Orders#1234abcd' --project target --yes
|
|
|
458
462
|
revo database-views push 'Sales/Revenue#1234abcd' --project target --yes
|
|
459
463
|
```
|
|
460
464
|
|
|
465
|
+
Endpoint route uniqueness applies to live resources, matching the API. Soft-deleted endpoints with other Stable Keys do not reserve routes. Exact-key restore also checks the endpoint's old route during planning and again immediately before restoration, even when the desired path changes. The backend remains the final authority for concurrent route changes.
|
|
466
|
+
|
|
461
467
|
Database View plans show a line diff for changed RAW_SQL queries, including unchanged context and red/green removed and added lines in color terminals.
|
|
462
468
|
|
|
463
469
|
Preview failures use `validation-failed`, preserve the definition diff, and show the backend message, HTTP status, definition mode, and timeout information. RAW_SQL failures also suggest checking whether the instance enables RAW SQL Database Views. They block deployment of the affected view even with `--force`; `database-views push` continues with independent views but exits unsuccessfully if validation failed. An unchanged view skips planning preview only when its target hash and source-table dependency fingerprint match the environment lock; old locks still require preview. Pull and verified push update this fingerprint, while plan remains fileless. Creates and updates always revalidate immediately before writing.
|
package/dist/src/cli.js
CHANGED
|
@@ -198,7 +198,7 @@ async function runMain(args, argv) {
|
|
|
198
198
|
const command = args._[0];
|
|
199
199
|
const noPositionals = args._.length === 0;
|
|
200
200
|
if (command === 'version' || ((args.version !== undefined || args.V !== undefined) && noPositionals)) {
|
|
201
|
-
print(args.json ? { version: packageVersion, capabilities: { workspacePrune: true, reviewedPrunePlan: true } } : packageVersion);
|
|
201
|
+
print(args.json ? { version: packageVersion, capabilities: { workspacePrune: true, reviewedPrunePlan: true, reviewedDeploymentPlan: true, componentMutationReview: true } } : packageVersion);
|
|
202
202
|
return;
|
|
203
203
|
}
|
|
204
204
|
if (command === 'info' || ((args.i === true || args.info === true) && noPositionals)) {
|
package/dist/src/client.d.ts
CHANGED
|
@@ -445,7 +445,8 @@ export declare class RevoClient {
|
|
|
445
445
|
}>;
|
|
446
446
|
getComponent(componentId: string, options?: Pick<RequestOptions, 'timeoutMs'>): Promise<unknown>;
|
|
447
447
|
createComponent(body: unknown): Promise<unknown>;
|
|
448
|
-
|
|
448
|
+
reviewComponent(componentId: string, body: unknown): Promise<unknown>;
|
|
449
|
+
updateComponent(componentId: string, body: unknown, expectedToken?: string): Promise<unknown>;
|
|
449
450
|
deleteComponent(componentId: string): Promise<ApiResponse<unknown>>;
|
|
450
451
|
deleteWorkspaceResource(resource: TrackableResourceType, id: string): Promise<unknown>;
|
|
451
452
|
private accountForSync;
|
|
@@ -522,7 +523,8 @@ export declare class RevoClient {
|
|
|
522
523
|
deleteRoleGroup(roleGroupId: string): Promise<ApiResponse<unknown>>;
|
|
523
524
|
listSystemRoles(): Promise<unknown>;
|
|
524
525
|
listAllSystemRoles(): Promise<SystemRoleRecord[]>;
|
|
525
|
-
|
|
526
|
+
reviewComponentElements(componentId: string, body: unknown): Promise<unknown>;
|
|
527
|
+
saveComponentElements(componentId: string, body: unknown, expectedToken?: string): Promise<ApiResponse<unknown>>;
|
|
526
528
|
}
|
|
527
529
|
export { COMPONENT_LIST_PAGE_SIZE };
|
|
528
530
|
export { buildUrl, normalizeToken };
|
package/dist/src/client.js
CHANGED
|
@@ -1175,9 +1175,13 @@ export class RevoClient {
|
|
|
1175
1175
|
spinnerLabel: 'Creating component',
|
|
1176
1176
|
});
|
|
1177
1177
|
}
|
|
1178
|
-
async
|
|
1178
|
+
async reviewComponent(componentId, body) {
|
|
1179
|
+
return this.requestData('POST', `/api/v1/component/${componentId}/review`, { body });
|
|
1180
|
+
}
|
|
1181
|
+
async updateComponent(componentId, body, expectedToken) {
|
|
1179
1182
|
return this.requestData('PUT', `/api/v1/component/${componentId}`, {
|
|
1180
1183
|
body,
|
|
1184
|
+
...(expectedToken ? { headers: { 'x-revo-mutation-review': expectedToken } } : {}),
|
|
1181
1185
|
spinnerLabel: 'Updating component',
|
|
1182
1186
|
});
|
|
1183
1187
|
}
|
|
@@ -1654,8 +1658,14 @@ export class RevoClient {
|
|
|
1654
1658
|
async listAllSystemRoles() {
|
|
1655
1659
|
return unwrapList(await this.listSystemRoles()).filter(isRecord);
|
|
1656
1660
|
}
|
|
1657
|
-
async
|
|
1658
|
-
return this.
|
|
1661
|
+
async reviewComponentElements(componentId, body) {
|
|
1662
|
+
return this.requestData('POST', `/api/v1/component/${componentId}/save/review`, { body });
|
|
1663
|
+
}
|
|
1664
|
+
async saveComponentElements(componentId, body, expectedToken) {
|
|
1665
|
+
return this.request('POST', `/api/v1/component/${componentId}/save`, {
|
|
1666
|
+
body,
|
|
1667
|
+
...(expectedToken ? { headers: { 'x-revo-mutation-review': expectedToken } } : {}),
|
|
1668
|
+
});
|
|
1659
1669
|
}
|
|
1660
1670
|
}
|
|
1661
1671
|
export { COMPONENT_LIST_PAGE_SIZE };
|
|
@@ -438,6 +438,16 @@ function componentSourceHash(component, identity) {
|
|
|
438
438
|
? hashPortableComponentSource(component)
|
|
439
439
|
: hashComponentSource(component);
|
|
440
440
|
}
|
|
441
|
+
function componentReviewToken(response, componentId, expectedVersion, targetPath) {
|
|
442
|
+
const review = isRecord(response) && isRecord(response.data) ? response.data : response;
|
|
443
|
+
if (!isRecord(review) || review.kind !== 'mutation_review' || review.schemaVersion !== 1
|
|
444
|
+
|| !isRecord(review.target) || review.target.refId !== componentId || review.target.refType !== 'COMPONENTS'
|
|
445
|
+
|| !Number.isSafeInteger(expectedVersion) || review.baseVersion !== expectedVersion
|
|
446
|
+
|| typeof review.token !== 'string' || !review.token) {
|
|
447
|
+
throw new Error(`Cannot push ${targetPath}: target changed since the reviewed version or the API lacks mutation review support; run plan again.`);
|
|
448
|
+
}
|
|
449
|
+
return review.token;
|
|
450
|
+
}
|
|
441
451
|
function writeComponentPushVerificationLog(input) {
|
|
442
452
|
const outputDir = path.join(input.cwd, '.revoengine', 'logs', 'component-push');
|
|
443
453
|
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
@@ -1165,6 +1175,15 @@ async function pushSingleComponent(context, manifestPath, remoteCatalog) {
|
|
|
1165
1175
|
}
|
|
1166
1176
|
try {
|
|
1167
1177
|
const remote = await resolveRemoteComponentForLocal(context, component, identity, resolvedRemoteCatalog);
|
|
1178
|
+
if (context.componentReview) {
|
|
1179
|
+
const reviewed = context.componentReview.get(identityKey);
|
|
1180
|
+
if (!reviewed || componentSourceHash(component, identity) !== reviewed.localHash
|
|
1181
|
+
|| (remote ? componentSourceHash(remote, identity) : null) !== reviewed.remoteHash
|
|
1182
|
+
|| (remote ? componentIdOf(remote) : undefined) !== reviewed.remoteComponentId
|
|
1183
|
+
|| (remote ? componentVersion(remote) : null) !== reviewed.remoteVersion) {
|
|
1184
|
+
throw new Error(`Cannot push ${targetPath}: component changed after the deployment plan was reviewed; run plan again.`);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1168
1187
|
if (!remote) {
|
|
1169
1188
|
if (identity.mode === 'stableKey') {
|
|
1170
1189
|
const created = unwrapComponent(await client.createComponent(buildComponentCreatePayload(component, identity)));
|
|
@@ -1294,12 +1313,22 @@ async function pushSingleComponent(context, manifestPath, remoteCatalog) {
|
|
|
1294
1313
|
return result;
|
|
1295
1314
|
}
|
|
1296
1315
|
let configurationChanged = false;
|
|
1316
|
+
let expectedSaveVersion = componentVersion(remote);
|
|
1297
1317
|
const operations = {};
|
|
1298
1318
|
let errorOperationId;
|
|
1299
1319
|
if (portableDiff.configurationFields.length > 0) {
|
|
1300
1320
|
try {
|
|
1301
|
-
|
|
1321
|
+
const body = buildPortableComponentUpdatePayload(component, remote, portableDiff.configurationFields);
|
|
1322
|
+
if (context.componentReview) {
|
|
1323
|
+
const token = componentReviewToken(await client.reviewComponent(remoteComponentId, body), remoteComponentId, expectedSaveVersion, targetPath);
|
|
1324
|
+
await client.updateComponent(remoteComponentId, body, token);
|
|
1325
|
+
}
|
|
1326
|
+
else {
|
|
1327
|
+
await client.updateComponent(remoteComponentId, body);
|
|
1328
|
+
}
|
|
1302
1329
|
configurationChanged = true;
|
|
1330
|
+
if (expectedSaveVersion !== null)
|
|
1331
|
+
expectedSaveVersion += 1;
|
|
1303
1332
|
operations.configurationUpdate = { outcome: 'accepted' };
|
|
1304
1333
|
}
|
|
1305
1334
|
catch (error) {
|
|
@@ -1326,7 +1355,13 @@ async function pushSingleComponent(context, manifestPath, remoteCatalog) {
|
|
|
1326
1355
|
if (portableDiff.elementsChanged) {
|
|
1327
1356
|
try {
|
|
1328
1357
|
const elements = buildPushElements(component, remote, identity);
|
|
1329
|
-
|
|
1358
|
+
let expectedToken;
|
|
1359
|
+
if (context.componentReview) {
|
|
1360
|
+
expectedToken = componentReviewToken(await client.reviewComponentElements(remoteComponentId, elements), remoteComponentId, expectedSaveVersion, targetPath);
|
|
1361
|
+
}
|
|
1362
|
+
const response = expectedToken
|
|
1363
|
+
? await client.saveComponentElements(remoteComponentId, elements, expectedToken)
|
|
1364
|
+
: await client.saveComponentElements(remoteComponentId, elements);
|
|
1330
1365
|
elementsChanged = response.status !== 304;
|
|
1331
1366
|
const operationId = readRevoOperationId(response.headers);
|
|
1332
1367
|
errorOperationId = operationId || errorOperationId;
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { normalizeStableKeyValue } from "../resource-metadata.js";
|
|
4
4
|
import { samePrunePlan } from "../workspace-prune.js";
|
|
5
|
+
import { sameReviewedPlan } from "../reviewed-plan.js";
|
|
5
6
|
import { schemaItemAction, viewItemAction, componentItemAction, jobTemplateItemAction, endpointItemAction, scheduleItemAction, eventItemAction, groupItemAction, roleGroupItemAction, } from "../migration-actions.js";
|
|
6
7
|
import { DEFAULT_ENV_NAME } from "../config.js";
|
|
7
8
|
import { buildMigrationPlan, pullResourcesToWorkspace, runMigration, } from "../migration.js";
|
|
@@ -568,6 +569,9 @@ export async function handleDeployCommand(context) {
|
|
|
568
569
|
|| !samePrunePlan(reviewed.prune, preview.prune)) {
|
|
569
570
|
throw new Error('Reviewed deletion plan does not match this instance, resource scope or live target; run plan again.');
|
|
570
571
|
}
|
|
572
|
+
if (!sameReviewedPlan(reviewed, preview)) {
|
|
573
|
+
throw new Error('Reviewed deployment plan does not match the workspace or live target; run plan again and review it before deploying.');
|
|
574
|
+
}
|
|
571
575
|
}
|
|
572
576
|
// Interactive confirmation must always expose the plan, including JSON mode.
|
|
573
577
|
if (!readBoolFlag(context.args, ['json']))
|
|
@@ -578,7 +582,7 @@ export async function handleDeployCommand(context) {
|
|
|
578
582
|
throw new Error(`Deployment plan is blocked by ${preview.blockers.length} issue(s).`);
|
|
579
583
|
await confirmDeploy(context);
|
|
580
584
|
const startedAt = Date.now();
|
|
581
|
-
const result = await runMigration({ ...input, reviewedPrune: preview.prune });
|
|
585
|
+
const result = await runMigration({ ...input, reviewedPrune: preview.prune, reviewedPlan: preview });
|
|
582
586
|
if (readBoolFlag(context.args, ['json'])) {
|
|
583
587
|
context.print({ ...result, command: 'deploy' });
|
|
584
588
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ChildProcess } from 'node:child_process';
|
|
2
2
|
import { type TerminalNetworkAccess, type TerminalSandbox } from './terminal-sandbox.ts';
|
|
3
|
+
/** Equal jitter avoids synchronized reconnect storms while retaining a bounded delay. */
|
|
4
|
+
export declare function terminalReconnectDelay(backoffMs: number, random?: number): number;
|
|
3
5
|
type TerminalGrant = {
|
|
4
6
|
agentTerminalId: string;
|
|
5
7
|
name?: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
2
3
|
import os from 'node:os';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { fileURLToPath } from 'node:url';
|
|
@@ -18,6 +19,12 @@ import { TerminalOperationalLog } from "./terminal-operational-log.js";
|
|
|
18
19
|
import { createSecureBrowserIdentity, decryptSecureBrowserInput } from "./terminal-secure-browser.js";
|
|
19
20
|
class TerminalRunnerFatalError extends Error {
|
|
20
21
|
}
|
|
22
|
+
class TerminalApiTransientError extends Error {
|
|
23
|
+
}
|
|
24
|
+
/** Equal jitter avoids synchronized reconnect storms while retaining a bounded delay. */
|
|
25
|
+
export function terminalReconnectDelay(backoffMs, random = Math.random()) {
|
|
26
|
+
return Math.round(backoffMs * (0.5 + random * 0.5));
|
|
27
|
+
}
|
|
21
28
|
export function selectRegisteredTerminal(devices, grants, name, terminalId) {
|
|
22
29
|
const matching = devices.filter(device => terminalId
|
|
23
30
|
? device.agentTerminalId === terminalId : device.name === name);
|
|
@@ -279,22 +286,60 @@ function apiUrl(profile, route) {
|
|
|
279
286
|
return `${base}/api/v1${route}`;
|
|
280
287
|
}
|
|
281
288
|
async function api(profile, method, route, body) {
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
289
|
+
const url = apiUrl(profile, route);
|
|
290
|
+
let backoffMs = 1_000;
|
|
291
|
+
for (;;) {
|
|
292
|
+
profile.signal?.throwIfAborted();
|
|
293
|
+
try {
|
|
294
|
+
let response;
|
|
295
|
+
try {
|
|
296
|
+
response = await fetch(url, {
|
|
297
|
+
method, redirect: 'manual',
|
|
298
|
+
signal: AbortSignal.any([AbortSignal.timeout(30_000), ...(profile.signal ? [profile.signal] : [])]),
|
|
299
|
+
headers: { Authorization: `Bearer ${profile.token}`,
|
|
300
|
+
...(profile.instance ? { instance: profile.instance } : {}),
|
|
301
|
+
...(body ? { 'Content-Type': 'application/json' } : {}) },
|
|
302
|
+
...(body ? { body: JSON.stringify(body) } : {}),
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
catch {
|
|
306
|
+
throw new TerminalApiTransientError('Terminal API transport unavailable.');
|
|
307
|
+
}
|
|
308
|
+
if (response.status >= 300 && response.status < 400) {
|
|
309
|
+
await response.body?.cancel();
|
|
310
|
+
throw new Error(`Revo API ${method} ${route} redirected; refusing to forward credentials.`);
|
|
311
|
+
}
|
|
312
|
+
if ([401, 403].includes(response.status)) {
|
|
313
|
+
await response.body?.cancel();
|
|
314
|
+
throw new TerminalRunnerFatalError('Terminal authentication or authorization was rejected. Renew the CLI credentials or grant before connecting.');
|
|
315
|
+
}
|
|
316
|
+
if ([408, 429].includes(response.status) || response.status >= 500) {
|
|
317
|
+
await response.body?.cancel();
|
|
318
|
+
throw new TerminalApiTransientError(`Terminal API temporarily unavailable (${response.status}).`);
|
|
319
|
+
}
|
|
320
|
+
let value;
|
|
321
|
+
try {
|
|
322
|
+
value = await response.json();
|
|
323
|
+
}
|
|
324
|
+
catch {
|
|
325
|
+
if (!response.ok)
|
|
326
|
+
throw new Error(`Revo API ${method} ${route} returned ${response.status}.`);
|
|
327
|
+
throw new TerminalApiTransientError('Terminal API returned an incomplete response.');
|
|
328
|
+
}
|
|
329
|
+
if (!response.ok)
|
|
330
|
+
throw new Error(`Revo API ${method} ${route} returned ${response.status}: ${String(value?.message || 'request failed')}`);
|
|
331
|
+
return (value?.data ?? value);
|
|
332
|
+
}
|
|
333
|
+
catch (error) {
|
|
334
|
+
profile.signal?.throwIfAborted();
|
|
335
|
+
// Only connect's reads are repeatable. Never replay pairing, revocation or other mutations.
|
|
336
|
+
if (!profile.retryReads || method !== 'GET' || !(error instanceof TerminalApiTransientError))
|
|
337
|
+
throw error;
|
|
338
|
+
console.error('Terminal API unavailable; connection setup will retry.');
|
|
339
|
+
await delay(terminalReconnectDelay(backoffMs), undefined, { signal: profile.signal });
|
|
340
|
+
backoffMs = Math.min(backoffMs * 2, 30_000);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
298
343
|
}
|
|
299
344
|
function realtimeUrl(value) {
|
|
300
345
|
const url = new URL(value);
|
|
@@ -533,11 +578,18 @@ export function runWorkspacePatch(input, onDone) {
|
|
|
533
578
|
throw new Error('terminal_policy_expired');
|
|
534
579
|
const workerJs = fileURLToPath(new URL('./terminal-patch-worker.js', import.meta.url));
|
|
535
580
|
const worker = fs.existsSync(workerJs) ? workerJs : fileURLToPath(new URL('./terminal-patch-worker.ts', import.meta.url));
|
|
536
|
-
const scratch = fs.mkdtempSync(path.join(os.tmpdir(), 'revo-terminal-patch-'));
|
|
581
|
+
const scratch = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'revo-terminal-patch-')));
|
|
537
582
|
let launch;
|
|
538
583
|
try {
|
|
539
|
-
|
|
540
|
-
|
|
584
|
+
// Run the fixed helper files from their own package scope. Node's loader must
|
|
585
|
+
// not traverse a CLI installation outside this command's readable workspace.
|
|
586
|
+
const isolatedWorker = path.join(scratch, path.basename(worker));
|
|
587
|
+
const helperName = `terminal-patch${path.extname(worker)}`;
|
|
588
|
+
fs.copyFileSync(worker, isolatedWorker);
|
|
589
|
+
fs.copyFileSync(path.join(path.dirname(worker), helperName), path.join(scratch, helperName));
|
|
590
|
+
fs.writeFileSync(path.join(scratch, 'package.json'), JSON.stringify({ type: 'module' }), { mode: 0o600 });
|
|
591
|
+
const command = [process.execPath, isolatedWorker, input.workspace, String(input.allowDelete)].map(shellQuote).join(' ');
|
|
592
|
+
launch = sandboxCommand(input.workspace, input.workspace, command, 'workspace', process.platform, scratch, [], 'none');
|
|
541
593
|
}
|
|
542
594
|
catch (error) {
|
|
543
595
|
fs.rmSync(scratch, { recursive: true, force: true });
|
|
@@ -693,7 +745,7 @@ async function connect(profile, device) {
|
|
|
693
745
|
reconnectGrace.clear();
|
|
694
746
|
});
|
|
695
747
|
socket.on('open', () => send(socket, { type: 'hello', protocol: 1, agentTerminalId: device.agentTerminalId,
|
|
696
|
-
secret: device.secret, capabilities: ['workspace_sandbox_v1', 'workspace_network_v1', 'network_policy_v1',
|
|
748
|
+
secret: device.secret, capabilities: ['grant_refresh_v1', 'workspace_sandbox_v1', 'workspace_network_v1', 'network_policy_v1',
|
|
697
749
|
'terminal_policy_v2', 'terminal_policy_selective_v1', 'background_shell_v1', 'terminal_thread_scope_v1',
|
|
698
750
|
'apply_patch_v1', 'stdin_v1', 'pty_v1', 'browser_v1', 'browser_session_v1', 'browser_forms_v1',
|
|
699
751
|
'browser_local_v1', 'browser_once_v1', 'browser_secure_input_v1', 'browser_tabs_v1', 'save_image_v1',
|
|
@@ -1158,10 +1210,13 @@ async function connect(profile, device) {
|
|
|
1158
1210
|
if (activeSocket === socket)
|
|
1159
1211
|
activeConnectionId = '';
|
|
1160
1212
|
resumed.clear();
|
|
1161
|
-
|
|
1213
|
+
const grantChanged = code === 1012 && reason.toString() === 'grant_changed';
|
|
1214
|
+
if (grantChanged || code === 1008 && reason.toString() !== 'heartbeat_timeout') {
|
|
1162
1215
|
reconnectGrace.clear();
|
|
1163
|
-
for (const child of children
|
|
1216
|
+
for (const [executionId, child] of children) {
|
|
1217
|
+
cancelledExecutions.add(executionId);
|
|
1164
1218
|
child.terminate();
|
|
1219
|
+
}
|
|
1165
1220
|
void closeBrowserSessions();
|
|
1166
1221
|
}
|
|
1167
1222
|
else if (!stopping)
|
|
@@ -1199,8 +1254,9 @@ async function connect(profile, device) {
|
|
|
1199
1254
|
}
|
|
1200
1255
|
if (stopping)
|
|
1201
1256
|
break;
|
|
1202
|
-
|
|
1203
|
-
|
|
1257
|
+
const reconnectDelayMs = terminalReconnectDelay(backoffMs);
|
|
1258
|
+
operationalLog.write('INFO', {}, 'runner.reconnect_wait', { milliseconds: reconnectDelayMs });
|
|
1259
|
+
await delay(reconnectDelayMs, undefined, { signal: profile.signal });
|
|
1204
1260
|
backoffMs = Math.min(backoffMs * 2, 30_000);
|
|
1205
1261
|
}
|
|
1206
1262
|
}
|
|
@@ -1210,7 +1266,7 @@ async function connect(profile, device) {
|
|
|
1210
1266
|
process.off('SIGTERM', stop);
|
|
1211
1267
|
}
|
|
1212
1268
|
}
|
|
1213
|
-
async function runTerminalCommand(argv) {
|
|
1269
|
+
async function runTerminalCommand(argv, signal) {
|
|
1214
1270
|
const command = argv[0] || 'help';
|
|
1215
1271
|
if (command === 'help' || argv.includes('--help')) {
|
|
1216
1272
|
console.log('revo terminal connect|status|disconnect [--project NAME] [--workspace PATH] [--name NAME|--terminal-id UUID] [--url URL] [--realtime-url URL]\nrevo terminal service install|uninstall --workspace PATH [--project NAME] [--name NAME|--terminal-id UUID]');
|
|
@@ -1287,7 +1343,7 @@ async function runTerminalCommand(argv) {
|
|
|
1287
1343
|
: `Terminal service already installed (${result.label}).`);
|
|
1288
1344
|
return;
|
|
1289
1345
|
}
|
|
1290
|
-
const profile = resolveProfile(argv);
|
|
1346
|
+
const profile = { ...resolveProfile(argv), retryReads: command === 'connect', signal };
|
|
1291
1347
|
let me;
|
|
1292
1348
|
if (!profile.instance) {
|
|
1293
1349
|
const currentUser = await api(profile, 'GET', '/me');
|
|
@@ -1326,9 +1382,12 @@ async function runTerminalCommand(argv) {
|
|
|
1326
1382
|
throw new Error(`Multiple removed terminals match ${name} (${matchingDevices.map(item => item.agentTerminalId).join(', ')}). Select one with --terminal-id.`);
|
|
1327
1383
|
selectedDevice = matchingDevices[0];
|
|
1328
1384
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
throw new Error('Uninstall the
|
|
1385
|
+
const envName = selectedProject(argv) || getActiveEnvironmentName();
|
|
1386
|
+
if (terminalServiceInstalled(selectedDevice.workspace, envName))
|
|
1387
|
+
throw new Error('Uninstall the legacy workspace service before revoking its grant.');
|
|
1388
|
+
if (terminalServiceInstalled(selectedDevice.workspace, envName, selectedDevice.agentTerminalId))
|
|
1389
|
+
uninstallTerminalService({ workspace: selectedDevice.workspace, envName, terminalId: selectedDevice.agentTerminalId,
|
|
1390
|
+
configHome: process.env.XDG_CONFIG_HOME });
|
|
1332
1391
|
if (listing.devices.some(item => item.agentTerminalId === selectedDevice.agentTerminalId))
|
|
1333
1392
|
await api(profile, 'POST', `/agents/terminals/${selectedDevice.agentTerminalId}/revoke`);
|
|
1334
1393
|
await updateStore(current => {
|
|
@@ -1391,6 +1450,8 @@ async function runTerminalCommand(argv) {
|
|
|
1391
1450
|
}
|
|
1392
1451
|
console.log(`Pending approval in AI Agents → Terminals: ${device.name} (${device.agentTerminalId}).`);
|
|
1393
1452
|
}
|
|
1453
|
+
if (profile.realtimeUrl)
|
|
1454
|
+
device = { ...device, realtimeUrl: realtimeUrl(profile.realtimeUrl) };
|
|
1394
1455
|
if (device.workspace !== workspace) {
|
|
1395
1456
|
await api(profile, 'POST', `/agents/terminals/${device.agentTerminalId}/workspaces/register`, { path: workspace, name: path.basename(workspace) });
|
|
1396
1457
|
await updateStore(current => {
|
|
@@ -1407,7 +1468,7 @@ async function runTerminalCommand(argv) {
|
|
|
1407
1468
|
break;
|
|
1408
1469
|
if (!grant || grant.status === 'revoked')
|
|
1409
1470
|
throw new TerminalRunnerFatalError('Terminal grant revoked or missing.');
|
|
1410
|
-
await
|
|
1471
|
+
await delay(2_000, undefined, { signal: profile.signal });
|
|
1411
1472
|
}
|
|
1412
1473
|
let releaseRunnerLock;
|
|
1413
1474
|
try {
|
|
@@ -1429,14 +1490,28 @@ async function runTerminalCommand(argv) {
|
|
|
1429
1490
|
}
|
|
1430
1491
|
/** Supervisors retry crashes, but a revoked grant or 401/403 needs a human credential/grant change. */
|
|
1431
1492
|
export async function handleTerminalCommand(argv) {
|
|
1493
|
+
const controller = argv[0] === 'connect' ? new AbortController() : undefined;
|
|
1494
|
+
const stopSetup = () => controller?.abort();
|
|
1495
|
+
if (controller) {
|
|
1496
|
+
process.on('SIGINT', stopSetup);
|
|
1497
|
+
process.on('SIGTERM', stopSetup);
|
|
1498
|
+
}
|
|
1432
1499
|
try {
|
|
1433
|
-
await runTerminalCommand(argv);
|
|
1500
|
+
await runTerminalCommand(argv, controller?.signal);
|
|
1434
1501
|
}
|
|
1435
1502
|
catch (error) {
|
|
1503
|
+
if (controller?.signal.aborted)
|
|
1504
|
+
return;
|
|
1436
1505
|
if (argv.includes('--service-runner') && error instanceof TerminalRunnerFatalError) {
|
|
1437
1506
|
console.error(error.message);
|
|
1438
1507
|
return;
|
|
1439
1508
|
}
|
|
1440
1509
|
throw error;
|
|
1441
1510
|
}
|
|
1511
|
+
finally {
|
|
1512
|
+
if (controller) {
|
|
1513
|
+
process.off('SIGINT', stopSetup);
|
|
1514
|
+
process.off('SIGTERM', stopSetup);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1442
1517
|
}
|
package/dist/src/migration.d.ts
CHANGED
|
@@ -41,6 +41,7 @@ export type MigrationSourcePullSummary = {
|
|
|
41
41
|
};
|
|
42
42
|
export type MigrationPlan = {
|
|
43
43
|
schemaVersion: 2;
|
|
44
|
+
reviewedPlanVersion?: 1;
|
|
44
45
|
command: 'plan';
|
|
45
46
|
from: string;
|
|
46
47
|
to: string;
|
|
@@ -114,6 +115,7 @@ type MigrationInputBase = {
|
|
|
114
115
|
detailedDiff?: boolean;
|
|
115
116
|
prune?: boolean;
|
|
116
117
|
reviewedPrune?: WorkspacePrunePlan;
|
|
118
|
+
reviewedPlan?: MigrationPlan;
|
|
117
119
|
};
|
|
118
120
|
export type MigrationInput = MigrationInputBase & ({
|
|
119
121
|
sourceMode: 'workspace';
|
package/dist/src/migration.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AGENT_LAYOUT, buildAgentsPlan, pullAgentsToWorkspace, pushAgents } from "./resource-syncs/agent-sync.js";
|
|
2
2
|
import { projectRepositoryItems, migrationItemOperation, BLOCKING_SCHEMA_STATUSES, schemaItemAction, viewItemIsBlocked, viewItemAction, componentItemAction, jobTemplateItemAction, endpointItemAction, scheduleItemAction, eventItemAction, groupItemAction, roleGroupItemAction, serviceAccountItemAction, } from "./migration-actions.js";
|
|
3
3
|
import fs from 'node:fs';
|
|
4
|
+
import { sameReviewedPlan } from "./reviewed-plan.js";
|
|
4
5
|
import { applyWorkspacePrune, buildWorkspacePrunePlan, samePrunePlan } from "./workspace-prune.js";
|
|
5
6
|
import { planIdentityMigration } from "./resource-syncs/identity-migration.js";
|
|
6
7
|
import { SERVICE_ACCOUNTS_DIRECTORY, buildServiceAccountsPlan, pullServiceAccountsToWorkspace, pushServiceAccounts } from "./resource-syncs/service-account-sync.js";
|
|
@@ -821,6 +822,9 @@ function componentCommandContext(input) {
|
|
|
821
822
|
client: input.client,
|
|
822
823
|
componentEnvironment: input.envName,
|
|
823
824
|
componentIdentity: migrationComponentIdentity(input.cwd),
|
|
825
|
+
...(input.reviewedComponents ? { componentReview: new Map(input.reviewedComponents.map(item => [item.identityKey || item.stableKey || item.componentId, { ...item,
|
|
826
|
+
remoteComponentId: item.remoteHash === null ? undefined : item.remoteComponentId,
|
|
827
|
+
remoteVersion: item.remoteHash === null ? null : item.remoteVersion }])) } : {}),
|
|
824
828
|
cwd: input.cwd,
|
|
825
829
|
packageVersion: 'migration',
|
|
826
830
|
print: () => undefined,
|
|
@@ -1082,7 +1086,7 @@ async function planWorkspace(input) {
|
|
|
1082
1086
|
const identities = await planIdentityMigration({ client, cwd: input.cwd, stableKeyName, resources });
|
|
1083
1087
|
if (input.prune && input.sourceMode !== 'workspace')
|
|
1084
1088
|
throw new Error('Prune requires repository plan/deploy; named migration remains upsert-only.');
|
|
1085
|
-
const prune = input.prune ? await buildWorkspacePrunePlan({ cwd: input.cwd, client, resources }) : undefined;
|
|
1089
|
+
const prune = input.prune ? await buildWorkspacePrunePlan({ cwd: input.cwd, client, resources, captureTargets: true }) : undefined;
|
|
1086
1090
|
const serviceAccounts = resources.includes('service-account')
|
|
1087
1091
|
? await runMigrationStage('target plan', 'service-account', environmentLabel, () => buildServiceAccountsPlan({ client, cwd: input.cwd, envName: environmentKey, stableKeyName,
|
|
1088
1092
|
projectedIdentities: identities?.projection })) : undefined;
|
|
@@ -1182,6 +1186,7 @@ async function planWorkspace(input) {
|
|
|
1182
1186
|
agentPlugins,
|
|
1183
1187
|
agents,
|
|
1184
1188
|
});
|
|
1189
|
+
combined.reviewedPlanVersion = 1;
|
|
1185
1190
|
if (identities) {
|
|
1186
1191
|
combined.identityOrder = identities.ordered.map(({ resource, stableKey }) => ({ resource, stableKey }));
|
|
1187
1192
|
}
|
|
@@ -1273,6 +1278,11 @@ export async function runMigration(input) {
|
|
|
1273
1278
|
initialPlan.readyToMigrate = false;
|
|
1274
1279
|
initialPlan.verdict = 'blocked';
|
|
1275
1280
|
}
|
|
1281
|
+
if (input.reviewedPlan && !sameReviewedPlan(input.reviewedPlan, initialPlan)) {
|
|
1282
|
+
initialPlan.blockers.push('Deployment state changed after confirmation; run plan again before deploying.');
|
|
1283
|
+
initialPlan.readyToMigrate = false;
|
|
1284
|
+
initialPlan.verdict = 'blocked';
|
|
1285
|
+
}
|
|
1276
1286
|
const base = {
|
|
1277
1287
|
schemaVersion: 2,
|
|
1278
1288
|
command: 'run',
|
|
@@ -1393,6 +1403,7 @@ export async function runMigration(input) {
|
|
|
1393
1403
|
envName: componentTargetEnvironment(input),
|
|
1394
1404
|
client: targetClient,
|
|
1395
1405
|
operation: 'push',
|
|
1406
|
+
...(input.reviewedPlan ? { reviewedComponents: initialPlan.components?.items } : {}),
|
|
1396
1407
|
}), { force: true, yes: true });
|
|
1397
1408
|
phaseResults.component = componentResults;
|
|
1398
1409
|
results.push(...componentResults);
|
|
@@ -810,13 +810,14 @@ export async function buildEndpointsPlan(input) {
|
|
|
810
810
|
for (const record of targetEndpoints) {
|
|
811
811
|
const stableKey = readConfiguredResourceMetadataStableKey(record, input.stableKeyName);
|
|
812
812
|
const routeKey = endpointRecordRouteKey(record);
|
|
813
|
-
|
|
813
|
+
// Soft-deleted records do not own live routes. Keep them in the identity
|
|
814
|
+
// inventory for exact-key restores, matching the API's live-only uniqueness.
|
|
815
|
+
if (routeKey && !record.deletedAt && !record.deletedBy) {
|
|
814
816
|
targetRouteOwners.set(routeKey, [
|
|
815
817
|
...(targetRouteOwners.get(routeKey) || []),
|
|
816
818
|
{
|
|
817
819
|
...(stableKey ? { stableKey } : {}),
|
|
818
820
|
name: endpointLabel(record, 'unknown'),
|
|
819
|
-
deleted: Boolean(record.deletedAt || record.deletedBy),
|
|
820
821
|
},
|
|
821
822
|
]);
|
|
822
823
|
}
|
|
@@ -898,8 +899,7 @@ export async function buildEndpointsPlan(input) {
|
|
|
898
899
|
}
|
|
899
900
|
for (const stableKey of stableKeys) {
|
|
900
901
|
const collisions = (targetRouteOwners.get(routeKey) || []).filter((owner) => owner.stableKey !== stableKey);
|
|
901
|
-
const movingOwners = collisions.filter((owner) => (
|
|
902
|
-
&& owner.stableKey
|
|
902
|
+
const movingOwners = collisions.filter((owner) => (owner.stableKey
|
|
903
903
|
&& desiredRoutesByStableKey.has(owner.stableKey)
|
|
904
904
|
&& desiredRoutesByStableKey.get(owner.stableKey) !== routeKey));
|
|
905
905
|
for (const owner of movingOwners) {
|
|
@@ -992,6 +992,13 @@ export async function buildEndpointsPlan(input) {
|
|
|
992
992
|
record: deletedTargets[0],
|
|
993
993
|
componentsById,
|
|
994
994
|
});
|
|
995
|
+
// Restore happens before configuration update, so the old physical route
|
|
996
|
+
// must also be available even when the desired manifest changes its path.
|
|
997
|
+
const oldRoute = endpointRecordRouteKey(deletedTargets[0]);
|
|
998
|
+
const oldRouteOwners = oldRoute ? targetRouteOwners.get(oldRoute) || [] : [];
|
|
999
|
+
if (oldRouteOwners.length > 0) {
|
|
1000
|
+
restoreSafety.push(`old route ${oldRoute} is owned by ${oldRouteOwners.map(owner => owner.stableKey || owner.name).sort().join(', ')}`);
|
|
1001
|
+
}
|
|
995
1002
|
if (restoreSafety.length > 0) {
|
|
996
1003
|
blockers.push(...restoreSafety.map((reason) => `Cannot restore Endpoint "${stableKey}": ${reason}.`));
|
|
997
1004
|
}
|
|
@@ -1515,6 +1522,11 @@ export async function pushEndpoints(input) {
|
|
|
1515
1522
|
if (restoreBlockers.length > 0) {
|
|
1516
1523
|
throw new Error(`restore safety changed after planning: ${restoreBlockers.join('; ')}`);
|
|
1517
1524
|
}
|
|
1525
|
+
const oldRoute = endpointRecordRouteKey(target);
|
|
1526
|
+
if (oldRoute && liveEndpoints.some(record => !record.deletedAt && !record.deletedBy
|
|
1527
|
+
&& endpointRecordRouteKey(record) === oldRoute)) {
|
|
1528
|
+
throw new Error(`restore safety changed after planning: old route ${oldRoute} is now owned by a live endpoint`);
|
|
1529
|
+
}
|
|
1518
1530
|
await input.client.restoreEndpoint(targetId);
|
|
1519
1531
|
const restored = unwrapData(await input.client.getEndpoint(targetId));
|
|
1520
1532
|
const restoredStableKey = readConfiguredResourceMetadataStableKey(restored, input.stableKeyName);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { hashStable } from "./component-lock.js";
|
|
2
|
+
const families = ['databaseSchemas', 'databaseViews', 'components', 'jobTemplates', 'endpoints',
|
|
3
|
+
'schedules', 'events', 'groups', 'roleGroups', 'serviceAccounts', 'agentPlugins', 'agents'];
|
|
4
|
+
// Compare authoring state and intended writes, independent of paths, timestamps,
|
|
5
|
+
// presentation diffs and lock adoption bookkeeping in separate CI checkouts.
|
|
6
|
+
function reviewState(plan) {
|
|
7
|
+
return {
|
|
8
|
+
target: plan.pruneTargetKey,
|
|
9
|
+
resources: plan.resources,
|
|
10
|
+
policy: plan.policy,
|
|
11
|
+
identityOrder: plan.identityOrder,
|
|
12
|
+
targets: plan.prune?.targetState,
|
|
13
|
+
families: families.map(family => ({ family, items: (plan[family]?.items || []).map(item => {
|
|
14
|
+
const value = item;
|
|
15
|
+
return Object.fromEntries(['stableKey', 'identityKey', 'componentId', 'remoteComponentId', 'remoteVersion',
|
|
16
|
+
'desiredHash', 'localHash', 'currentHash', 'remoteHash', 'operation', 'desiredActive', 'currentActive',
|
|
17
|
+
'targetRevisionHash', 'componentDesiredHash'].filter(key => value[key] !== undefined).map(key => [key, value[key]]));
|
|
18
|
+
}).sort((left, right) => hashStable(left).localeCompare(hashStable(right))) })),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export function sameReviewedPlan(reviewed, live) {
|
|
22
|
+
return reviewed.reviewedPlanVersion === 1 && live.reviewedPlanVersion === 1
|
|
23
|
+
&& reviewed.readyToMigrate && live.readyToMigrate
|
|
24
|
+
&& hashStable(reviewState(reviewed)) === hashStable(reviewState(live));
|
|
25
|
+
}
|
package/dist/src/types.d.ts
CHANGED
|
@@ -9,6 +9,12 @@ export type CommandContext = {
|
|
|
9
9
|
client: RevoClient;
|
|
10
10
|
componentEnvironment?: string;
|
|
11
11
|
componentIdentity?: ComponentIdentityConfig;
|
|
12
|
+
componentReview?: Map<string, {
|
|
13
|
+
localHash: string | null;
|
|
14
|
+
remoteHash: string | null;
|
|
15
|
+
remoteComponentId?: string;
|
|
16
|
+
remoteVersion: number | null;
|
|
17
|
+
}>;
|
|
12
18
|
cwd: string;
|
|
13
19
|
packageVersion: string;
|
|
14
20
|
print: (value: unknown) => void;
|
|
@@ -14,6 +14,13 @@ export type WorkspacePruneItem = {
|
|
|
14
14
|
export type WorkspacePrunePlan = {
|
|
15
15
|
items: WorkspacePruneItem[];
|
|
16
16
|
blockers: string[];
|
|
17
|
+
targetState?: Array<{
|
|
18
|
+
resource: TrackableResourceType;
|
|
19
|
+
stableKey: string;
|
|
20
|
+
targetId: string;
|
|
21
|
+
version: number | null;
|
|
22
|
+
active: unknown;
|
|
23
|
+
}>;
|
|
17
24
|
};
|
|
18
25
|
type Inventory = Partial<Record<TrackableResourceType, ResourceRecord[]>>;
|
|
19
26
|
type LocalManifests = Partial<Record<TrackableResourceType, Map<string, Record<string, unknown>>>>;
|
|
@@ -29,6 +36,7 @@ export declare function buildWorkspacePrunePlan(input: {
|
|
|
29
36
|
cwd: string;
|
|
30
37
|
client: RevoClient;
|
|
31
38
|
resources: readonly TrackableResourceType[];
|
|
39
|
+
captureTargets?: boolean;
|
|
32
40
|
}): Promise<WorkspacePrunePlan>;
|
|
33
41
|
export declare function samePrunePlan(left: WorkspacePrunePlan, right: WorkspacePrunePlan): boolean;
|
|
34
42
|
export declare function applyWorkspacePrune(input: {
|
|
@@ -390,10 +390,20 @@ export async function buildWorkspacePrunePlan(input) {
|
|
|
390
390
|
const profile = isRecord(me) && isRecord(me.data) ? me.data : me;
|
|
391
391
|
const actorId = isRecord(profile) && isRecord(profile.user) ? String(profile.user.userId || '')
|
|
392
392
|
: isRecord(profile) ? String(profile.userId || '') : undefined;
|
|
393
|
-
|
|
393
|
+
const stableKeyName = readProjectStableKeyName(input.cwd);
|
|
394
|
+
const plan = planWorkspacePrune({ resources: input.resources, local, inventory, stableKeyName, actorId });
|
|
395
|
+
if (input.captureTargets) {
|
|
396
|
+
plan.targetState = input.resources.flatMap(resource => (inventory[resource] || []).filter(active).flatMap(record => {
|
|
397
|
+
const stableKey = readConfiguredResourceMetadataStableKey(record, stableKeyName);
|
|
398
|
+
return stableKey ? [{ resource, stableKey: normalizeStableKeyValue(stableKey), targetId: resourceIdOf(record),
|
|
399
|
+
version: typeof record.version === 'number' ? record.version : null, active: record.active ?? null }] : [];
|
|
400
|
+
})).sort((left, right) => key(left.resource, left.stableKey).localeCompare(key(right.resource, right.stableKey))
|
|
401
|
+
|| left.targetId.localeCompare(right.targetId));
|
|
402
|
+
}
|
|
403
|
+
return plan;
|
|
394
404
|
}
|
|
395
405
|
export function samePrunePlan(left, right) {
|
|
396
|
-
return hashStable(left) === hashStable(right);
|
|
406
|
+
return hashStable({ items: left.items, blockers: left.blockers }) === hashStable({ items: right.items, blockers: right.blockers });
|
|
397
407
|
}
|
|
398
408
|
function clearPruneBaseline(cwd, envName, item) {
|
|
399
409
|
const { projectRoot } = requireProjectLayout(cwd, 'Workspace prune');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revoengine/cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"description": "CLI package for the RevoEngine Platform API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
13
13
|
"clean": "node --input-type=module -e \"import fs from 'node:fs'; fs.rmSync('dist', { recursive: true, force: true });\"",
|
|
14
|
-
"check": "node --input-type=module -e \"await import('./src/config.ts'); await import('./src/legacy.ts'); await import('./src/http-trace.ts'); await import('./src/request-queue.ts'); await import('./src/client.ts'); await import('./src/component-lock.ts'); await import('./src/component-contract.ts'); await import('./src/database-indexes.ts'); await import('./src/diff-details.ts'); await import('./src/resource-metadata.ts'); await import('./src/tracked-resources.ts'); await import('./src/resource-inventory.ts'); await import('./src/metadata-backfill.ts'); await import('./src/workspace-component.ts'); await import('./src/workspace-resource.ts'); await import('./src/database-table-artifacts.ts'); await import('./src/project.ts'); await import('./src/prompt.ts'); await import('./src/runtime-view.ts'); await import('./src/spinner.ts'); await import('./src/types.ts'); await import('./src/utils.ts'); await import('./src/resource-syncs/util.ts'); await import('./src/resource-syncs/agent-sync.ts'); await import('./src/resource-syncs/database-table-sync.ts'); await import('./src/resource-syncs/database-view-sync.ts'); await import('./src/resource-syncs/endpoint-sync.ts'); await import('./src/resource-syncs/group-sync.ts'); await import('./src/resource-syncs/role-group-sync.ts'); await import('./src/resource-syncs/job-template-sync.ts'); await import('./src/resource-syncs/schedule-sync.ts'); await import('./src/resource-syncs/event-sync.ts'); await import('./src/resource-syncs/account-principal.ts'); await import('./src/resource-syncs/identity-migration.ts'); await import('./src/resource-syncs/service-account-sync.ts'); await import('./src/commands/service-accounts.ts'); await import('./src/commands/agents.ts'); await import('./src/migration-actions.ts'); await import('./src/migration.ts'); await import('./src/workspace-diff.ts'); await import('./src/workspace-prune.ts'); await import('./src/sync-output.ts'); await import('./src/ui.ts'); await import('./src/update-notifier.ts'); await import('./src/env-sync.ts'); await import('./src/commands/auth.ts'); await import('./src/commands/component.ts'); await import('./src/commands/database-tables.ts'); await import('./src/commands/database-views.ts'); await import('./src/commands/endpoints.ts'); await import('./src/commands/env.ts'); await import('./src/commands/events.ts'); await import('./src/commands/groups.ts'); await import('./src/commands/info.ts'); await import('./src/commands/job-templates.ts'); await import('./src/commands/metadata.ts'); await import('./src/commands/migrate.ts'); await import('./src/commands/request.ts'); await import('./src/commands/role-groups.ts'); await import('./src/commands/search.ts'); await import('./src/commands/schedules.ts'); await import('./src/commands/terminal-service.ts'); await import('./src/commands/terminal-browser.ts'); await import('./src/commands/terminal-image.ts'); await import('./src/commands/terminal-sandbox.ts'); await import('./src/commands/terminal-patch.ts'); await import('./src/commands/terminal-patch-worker.ts'); await import('./src/commands/terminal.ts'); await import('./src/cli.ts'); await import('./src/index.ts'); await import('./bin/revo.ts'); await import('./scripts/dev.ts')\"",
|
|
14
|
+
"check": "node --input-type=module -e \"await import('./src/config.ts'); await import('./src/legacy.ts'); await import('./src/http-trace.ts'); await import('./src/request-queue.ts'); await import('./src/client.ts'); await import('./src/component-lock.ts'); await import('./src/component-contract.ts'); await import('./src/database-indexes.ts'); await import('./src/diff-details.ts'); await import('./src/resource-metadata.ts'); await import('./src/tracked-resources.ts'); await import('./src/resource-inventory.ts'); await import('./src/metadata-backfill.ts'); await import('./src/workspace-component.ts'); await import('./src/workspace-resource.ts'); await import('./src/database-table-artifacts.ts'); await import('./src/project.ts'); await import('./src/prompt.ts'); await import('./src/runtime-view.ts'); await import('./src/spinner.ts'); await import('./src/types.ts'); await import('./src/utils.ts'); await import('./src/resource-syncs/util.ts'); await import('./src/resource-syncs/agent-sync.ts'); await import('./src/resource-syncs/database-table-sync.ts'); await import('./src/resource-syncs/database-view-sync.ts'); await import('./src/resource-syncs/endpoint-sync.ts'); await import('./src/resource-syncs/group-sync.ts'); await import('./src/resource-syncs/role-group-sync.ts'); await import('./src/resource-syncs/job-template-sync.ts'); await import('./src/resource-syncs/schedule-sync.ts'); await import('./src/resource-syncs/event-sync.ts'); await import('./src/resource-syncs/account-principal.ts'); await import('./src/resource-syncs/identity-migration.ts'); await import('./src/resource-syncs/service-account-sync.ts'); await import('./src/commands/service-accounts.ts'); await import('./src/commands/agents.ts'); await import('./src/migration-actions.ts'); await import('./src/reviewed-plan.ts'); await import('./src/migration.ts'); await import('./src/workspace-diff.ts'); await import('./src/workspace-prune.ts'); await import('./src/sync-output.ts'); await import('./src/ui.ts'); await import('./src/update-notifier.ts'); await import('./src/env-sync.ts'); await import('./src/commands/auth.ts'); await import('./src/commands/component.ts'); await import('./src/commands/database-tables.ts'); await import('./src/commands/database-views.ts'); await import('./src/commands/endpoints.ts'); await import('./src/commands/env.ts'); await import('./src/commands/events.ts'); await import('./src/commands/groups.ts'); await import('./src/commands/info.ts'); await import('./src/commands/job-templates.ts'); await import('./src/commands/metadata.ts'); await import('./src/commands/migrate.ts'); await import('./src/commands/request.ts'); await import('./src/commands/role-groups.ts'); await import('./src/commands/search.ts'); await import('./src/commands/schedules.ts'); await import('./src/commands/terminal-service.ts'); await import('./src/commands/terminal-browser.ts'); await import('./src/commands/terminal-image.ts'); await import('./src/commands/terminal-sandbox.ts'); await import('./src/commands/terminal-patch.ts'); await import('./src/commands/terminal-patch-worker.ts'); await import('./src/commands/terminal.ts'); await import('./src/cli.ts'); await import('./src/index.ts'); await import('./bin/revo.ts'); await import('./scripts/dev.ts')\"",
|
|
15
15
|
"dev": "node ./scripts/dev.ts",
|
|
16
16
|
"prepack": "npm run build",
|
|
17
17
|
"test": "node --test ./test/*.test.ts",
|