@revoengine/cli 1.0.10 → 1.0.12
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 +314 -239
- package/dist/src/cli.js +126 -9
- package/dist/src/client.d.ts +373 -6
- package/dist/src/client.js +1005 -53
- package/dist/src/commands/auth.js +4 -2
- package/dist/src/commands/component.d.ts +67 -0
- package/dist/src/commands/component.js +555 -164
- package/dist/src/commands/database-tables.d.ts +2 -0
- package/dist/src/commands/database-tables.js +169 -0
- package/dist/src/commands/database-views.d.ts +2 -0
- package/dist/src/commands/database-views.js +126 -0
- package/dist/src/commands/endpoints.js +124 -0
- package/dist/src/commands/env.js +44 -24
- package/dist/src/commands/events.d.ts +2 -0
- package/dist/src/commands/events.js +144 -0
- package/dist/src/commands/groups.d.ts +2 -0
- package/dist/src/commands/groups.js +160 -0
- package/dist/src/commands/index.d.ts +9 -0
- package/dist/src/commands/index.js +9 -0
- package/dist/src/commands/job-templates.d.ts +2 -0
- package/dist/src/commands/job-templates.js +107 -0
- package/dist/src/commands/metadata.js +75 -10
- package/dist/src/commands/migrate.d.ts +6 -0
- package/dist/src/commands/migrate.js +658 -0
- package/dist/src/commands/project.js +10 -3
- package/dist/src/commands/role-groups.d.ts +2 -0
- package/dist/src/commands/role-groups.js +141 -0
- package/dist/src/commands/schedules.d.ts +2 -0
- package/dist/src/commands/schedules.js +140 -0
- package/dist/src/commands/terminal-browser.d.ts +16 -0
- package/dist/src/commands/terminal-browser.js +92 -0
- package/dist/src/commands/terminal-image.d.ts +7 -0
- package/dist/src/commands/terminal-image.js +40 -0
- package/dist/src/commands/terminal-patch-worker.d.ts +1 -0
- package/dist/src/commands/terminal-patch-worker.js +24 -0
- package/dist/src/commands/terminal-patch.d.ts +2 -0
- package/dist/src/commands/terminal-patch.js +156 -0
- package/dist/src/commands/terminal-sandbox.d.ts +8 -0
- package/dist/src/commands/terminal-sandbox.js +87 -0
- package/dist/src/commands/terminal-service.d.ts +38 -0
- package/dist/src/commands/terminal-service.js +210 -0
- package/dist/src/commands/terminal.d.ts +49 -0
- package/dist/src/commands/terminal.js +826 -0
- package/dist/src/component-lock.d.ts +111 -3
- package/dist/src/component-lock.js +363 -15
- package/dist/src/config.d.ts +10 -2
- package/dist/src/config.js +49 -14
- package/dist/src/database-table-artifacts.d.ts +7 -0
- package/dist/src/database-table-artifacts.js +8 -0
- package/dist/src/diff-details.d.ts +8 -0
- package/dist/src/diff-details.js +152 -0
- package/dist/src/env-sync.d.ts +0 -3
- package/dist/src/env-sync.js +11 -25
- package/dist/src/http-trace.d.ts +94 -0
- package/dist/src/http-trace.js +226 -0
- package/dist/src/metadata-backfill.d.ts +18 -7
- package/dist/src/metadata-backfill.js +1002 -27
- package/dist/src/migration.d.ts +141 -0
- package/dist/src/migration.js +1632 -0
- package/dist/src/project.d.ts +2 -0
- package/dist/src/project.js +4 -17
- package/dist/src/prompt.js +10 -18
- package/dist/src/resource-inventory.d.ts +28 -0
- package/dist/src/resource-inventory.js +85 -0
- package/dist/src/resource-metadata.d.ts +1 -0
- package/dist/src/resource-metadata.js +3 -0
- package/dist/src/resource-syncs/database-table-sync.d.ts +127 -0
- package/dist/src/resource-syncs/database-table-sync.js +2374 -0
- package/dist/src/resource-syncs/database-view-sync.d.ts +146 -0
- package/dist/src/resource-syncs/database-view-sync.js +1405 -0
- package/dist/src/resource-syncs/endpoint-sync.d.ts +123 -0
- package/dist/src/resource-syncs/endpoint-sync.js +1563 -0
- package/dist/src/resource-syncs/event-sync.d.ts +126 -0
- package/dist/src/resource-syncs/event-sync.js +1046 -0
- package/dist/src/resource-syncs/group-sync.d.ts +93 -0
- package/dist/src/resource-syncs/group-sync.js +928 -0
- package/dist/src/resource-syncs/job-template-sync.d.ts +106 -0
- package/dist/src/resource-syncs/job-template-sync.js +843 -0
- package/dist/src/resource-syncs/role-group-sync.d.ts +90 -0
- package/dist/src/resource-syncs/role-group-sync.js +635 -0
- package/dist/src/resource-syncs/schedule-sync.d.ts +140 -0
- package/dist/src/resource-syncs/schedule-sync.js +1396 -0
- package/dist/src/resource-syncs/util.d.ts +22 -0
- package/dist/src/resource-syncs/util.js +118 -0
- package/dist/src/resource-target.d.ts +11 -0
- package/dist/src/resource-target.js +48 -0
- package/dist/src/runtime-view.d.ts +1 -0
- package/dist/src/runtime-view.js +6 -1
- package/dist/src/sync-output.d.ts +66 -0
- package/dist/src/sync-output.js +268 -0
- package/dist/src/tracked-resources.d.ts +1 -1
- package/dist/src/tracked-resources.js +28 -2
- package/dist/src/types.d.ts +227 -0
- package/dist/src/ui.d.ts +3 -0
- package/dist/src/ui.js +76 -18
- package/dist/src/utils.d.ts +4 -0
- package/dist/src/utils.js +81 -0
- package/dist/src/workspace-component.d.ts +2 -0
- package/dist/src/workspace-component.js +34 -0
- package/dist/src/workspace-diff.d.ts +25 -0
- package/dist/src/workspace-diff.js +75 -0
- package/dist/src/workspace-resource.d.ts +2 -0
- package/dist/src/workspace-resource.js +52 -0
- package/package.json +12 -4
|
@@ -4,7 +4,7 @@ import { applyMetadataBackfillPlan, buildMetadataBackfillPlan, } from "../metada
|
|
|
4
4
|
import { buildProjectSyncState, buildEditorTypesUrl, extractSandboxEndpoint, extractEditorTypesBundle, readProjectComponentIdentity, readProjectMetadata, readProjectStableKeyName, readProjectTrackedResources, resolveProjectInvocation, resolveProjectTarget, syncProjectFiles, } from "../project.js";
|
|
5
5
|
import { promptText } from "../prompt.js";
|
|
6
6
|
import { DEFAULT_COMPONENT_IDENTITY, DEFAULT_STABLE_KEY_NAME, normalizeComponentIdentityConfig, normalizeComponentIdentityMode, normalizeStableKeyName, } from "../resource-metadata.js";
|
|
7
|
-
import { formatTrackedResources, normalizeTrackedResources, } from "../tracked-resources.js";
|
|
7
|
+
import { formatTrackedResources, normalizeTrackedResources, shouldTrackResource, TRACKABLE_RESOURCE_TYPES, } from "../tracked-resources.js";
|
|
8
8
|
function printSyncSummary(println, projectRoot, workspaceRoot, result, prefix) {
|
|
9
9
|
const workspaceDirectory = path.relative(projectRoot, workspaceRoot) || '.';
|
|
10
10
|
println(`${prefix} ${projectRoot}`);
|
|
@@ -75,11 +75,14 @@ async function resolveComponentIdentity(invocation, projectRoot) {
|
|
|
75
75
|
return normalizeComponentIdentityConfig({ mode, metadataProperty }, DEFAULT_COMPONENT_IDENTITY);
|
|
76
76
|
}
|
|
77
77
|
async function backfillStableKeyMetadata(context, stableKeyName, trackedResources) {
|
|
78
|
+
const automaticResources = trackedResources.includes('all')
|
|
79
|
+
? TRACKABLE_RESOURCE_TYPES.filter((resource) => resource !== 'database-table')
|
|
80
|
+
: trackedResources.filter((resource) => resource !== 'database-table');
|
|
78
81
|
const plan = await buildMetadataBackfillPlan({
|
|
79
82
|
client: context.client,
|
|
80
|
-
envName: 'default',
|
|
83
|
+
envName: context.componentEnvironment || 'default',
|
|
81
84
|
stableKeyName,
|
|
82
|
-
trackedResources,
|
|
85
|
+
trackedResources: automaticResources,
|
|
83
86
|
});
|
|
84
87
|
if (plan.counts.update === 0) {
|
|
85
88
|
return;
|
|
@@ -106,6 +109,7 @@ export async function handleProjectCommand(context) {
|
|
|
106
109
|
}
|
|
107
110
|
const layout = resolveProjectTarget(cwd, invocation.targetArg);
|
|
108
111
|
const syncInput = await resolveProjectSyncInput(context);
|
|
112
|
+
syncInput.authProfile = context.componentEnvironment || 'default';
|
|
109
113
|
syncInput.componentIdentity = await resolveComponentIdentity(invocation, layout.projectRoot);
|
|
110
114
|
syncInput.trackedResources = await resolveTrackedResources(invocation, layout.projectRoot);
|
|
111
115
|
const result = syncProjectFiles(layout, syncInput);
|
|
@@ -115,4 +119,7 @@ export async function handleProjectCommand(context) {
|
|
|
115
119
|
&& context.args['metadata-backfill'] !== false) {
|
|
116
120
|
await backfillStableKeyMetadata(context, syncInput.componentIdentity.metadataProperty || DEFAULT_STABLE_KEY_NAME, syncInput.trackedResources);
|
|
117
121
|
}
|
|
122
|
+
if (invocation.action === 'init' && shouldTrackResource(syncInput.trackedResources, 'database-table')) {
|
|
123
|
+
context.println('Database Table Stable Keys require an explicit review: revo metadata plan --resources database-table --project <source>');
|
|
124
|
+
}
|
|
118
125
|
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { resolveProjectRoot, readProjectStableKeyName } from "../project.js";
|
|
4
|
+
import { resolveResourceTarget } from "../resource-target.js";
|
|
5
|
+
import { buildRoleGroupsPlan, pullRoleGroupsToWorkspace, pushRoleGroups } from "../resource-syncs/role-group-sync.js";
|
|
6
|
+
import { isInteractiveTerminal, promptConfirm } from "../prompt.js";
|
|
7
|
+
import { planListChanges, printSyncPlan, printSyncStatus, printSyncSummary } from "../sync-output.js";
|
|
8
|
+
import { readBoolFlag } from "../utils.js";
|
|
9
|
+
function warnAboutExperimentalState(context) {
|
|
10
|
+
const projectRoot = resolveProjectRoot(context.cwd) || path.resolve(context.cwd);
|
|
11
|
+
const legacyPaths = [
|
|
12
|
+
path.join(projectRoot, '.revoengine', 'resources'),
|
|
13
|
+
path.join(projectRoot, '.revoengine', 'resources.lock.json'),
|
|
14
|
+
path.join(projectRoot, '.revoengine', 'plans'),
|
|
15
|
+
].filter((candidate) => fs.existsSync(candidate));
|
|
16
|
+
if (legacyPaths.length > 0) {
|
|
17
|
+
const warning = `Ignoring experimental ${legacyPaths.map((candidate) => path.relative(projectRoot, candidate)).join(', ')}; role-groups use workspace/RoleGroups and .revoengine/revo.lock.json.`;
|
|
18
|
+
if (readBoolFlag(context.args, ['json']))
|
|
19
|
+
(context.warn || context.error)(warning);
|
|
20
|
+
else
|
|
21
|
+
context.println(warning);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async function handlePull(context) {
|
|
25
|
+
if (!readBoolFlag(context.args, ['all', 'a'])) {
|
|
26
|
+
throw new Error('Role-group pull currently requires --all.');
|
|
27
|
+
}
|
|
28
|
+
const { client, envName } = await resolveResourceTarget(context, { resource: 'Role-group', allowDefaultProfile: true });
|
|
29
|
+
const startedAt = Date.now();
|
|
30
|
+
const result = await pullRoleGroupsToWorkspace({
|
|
31
|
+
client,
|
|
32
|
+
cwd: context.cwd,
|
|
33
|
+
envName,
|
|
34
|
+
stableKeyName: readProjectStableKeyName(context.cwd),
|
|
35
|
+
force: readBoolFlag(context.args, ['force', 'f']),
|
|
36
|
+
});
|
|
37
|
+
if (readBoolFlag(context.args, ['json'])) {
|
|
38
|
+
context.print(result);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const outputResults = [];
|
|
42
|
+
for (const pulled of result.pulled) {
|
|
43
|
+
printSyncStatus(context.println, { status: 'Pulled', direction: 'pull', targetPath: pulled.targetPath });
|
|
44
|
+
outputResults.push({ status: 'pulled', targetPath: pulled.targetPath });
|
|
45
|
+
}
|
|
46
|
+
for (const skipped of result.skipped) {
|
|
47
|
+
printSyncStatus(context.println, { status: 'Skipped', direction: 'pull', targetPath: skipped.targetPath, reason: skipped.reason });
|
|
48
|
+
outputResults.push({ status: 'skipped', targetPath: skipped.targetPath, reason: skipped.reason });
|
|
49
|
+
}
|
|
50
|
+
printSyncSummary(context.println, 'Pulled', outputResults, Date.now() - startedAt);
|
|
51
|
+
}
|
|
52
|
+
async function handlePlan(context) {
|
|
53
|
+
if (!readBoolFlag(context.args, ['all', 'a']))
|
|
54
|
+
throw new Error('Role-group plan currently requires --all.');
|
|
55
|
+
if (readBoolFlag(context.args, ['prune'])) {
|
|
56
|
+
throw new Error('Role-group prune is disabled until the backend soft-delete contract is confirmed.');
|
|
57
|
+
}
|
|
58
|
+
const { client, envName, displayName } = await resolveResourceTarget(context, { resource: 'Role-group', allowDefaultProfile: true });
|
|
59
|
+
const plan = await buildRoleGroupsPlan({
|
|
60
|
+
client,
|
|
61
|
+
cwd: context.cwd,
|
|
62
|
+
envName,
|
|
63
|
+
stableKeyName: readProjectStableKeyName(context.cwd),
|
|
64
|
+
});
|
|
65
|
+
if (readBoolFlag(context.args, ['json']))
|
|
66
|
+
context.print(plan);
|
|
67
|
+
else
|
|
68
|
+
printSyncPlan(context.println, {
|
|
69
|
+
title: 'Role-group',
|
|
70
|
+
environment: displayName,
|
|
71
|
+
counts: plan.counts,
|
|
72
|
+
showHints: readBoolFlag(context.args, ['hints']),
|
|
73
|
+
items: plan.items.map((item) => ({
|
|
74
|
+
...item,
|
|
75
|
+
details: planListChanges('roles', item.rolesToRemove, item.rolesToAdd),
|
|
76
|
+
})),
|
|
77
|
+
blockers: plan.blockers,
|
|
78
|
+
});
|
|
79
|
+
if (readBoolFlag(context.args, ['strict'])) {
|
|
80
|
+
const drift = plan.items.filter((item) => !['clean', 'orphan', 'skipped'].includes(item.status));
|
|
81
|
+
if (plan.blockers.length > 0 || drift.length > 0) {
|
|
82
|
+
throw new Error(`Role-group plan is not clean: ${drift.length} drift item(s), ${plan.blockers.length} blocker(s).`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
async function handlePush(context) {
|
|
87
|
+
if (!readBoolFlag(context.args, ['all', 'a']))
|
|
88
|
+
throw new Error('Role-group push currently requires --all.');
|
|
89
|
+
if (readBoolFlag(context.args, ['prune'])) {
|
|
90
|
+
throw new Error('Role-group prune is disabled until the backend soft-delete contract is confirmed.');
|
|
91
|
+
}
|
|
92
|
+
const { client, envName, displayName } = await resolveResourceTarget(context, { resource: 'Role-group', allowDefaultProfile: true });
|
|
93
|
+
if (!readBoolFlag(context.args, ['yes', 'y'])) {
|
|
94
|
+
if (!isInteractiveTerminal() || !await promptConfirm(`Push role-groups to "${displayName}"?`, false)) {
|
|
95
|
+
throw new Error('Role-group push requires confirmation. Re-run with --yes or use an interactive terminal.');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const startedAt = Date.now();
|
|
99
|
+
const result = await pushRoleGroups({
|
|
100
|
+
client,
|
|
101
|
+
cwd: context.cwd,
|
|
102
|
+
envName,
|
|
103
|
+
stableKeyName: readProjectStableKeyName(context.cwd),
|
|
104
|
+
force: readBoolFlag(context.args, ['force', 'f']),
|
|
105
|
+
});
|
|
106
|
+
if (readBoolFlag(context.args, ['json'])) {
|
|
107
|
+
context.print(result);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
for (const item of result.results) {
|
|
111
|
+
const label = item.status === 'deployed' ? 'Deployed' : item.status === 'failed' ? 'Failed' : 'Skipped';
|
|
112
|
+
printSyncStatus(context.println, {
|
|
113
|
+
status: label,
|
|
114
|
+
direction: 'push',
|
|
115
|
+
targetPath: item.targetPath,
|
|
116
|
+
reason: item.error || item.reason,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
printSyncSummary(context.println, 'Deployed', result.results, Date.now() - startedAt);
|
|
120
|
+
}
|
|
121
|
+
const failed = result.results.filter((item) => item.status === 'failed');
|
|
122
|
+
if (failed.length > 0)
|
|
123
|
+
throw new Error(`Role-group push finished with ${failed.length} failure(s).`);
|
|
124
|
+
}
|
|
125
|
+
export async function handleRoleGroupsCommand(context) {
|
|
126
|
+
warnAboutExperimentalState(context);
|
|
127
|
+
const subcommand = context.args._[1] || '';
|
|
128
|
+
if (subcommand === 'pull') {
|
|
129
|
+
await handlePull(context);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (subcommand === 'plan') {
|
|
133
|
+
await handlePlan(context);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (subcommand === 'push') {
|
|
137
|
+
await handlePush(context);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
throw new Error('Unknown role-groups command. Usage: revo role-groups <pull|plan|push> --all [--env <name>]');
|
|
141
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { isInteractiveTerminal, promptConfirm } from "../prompt.js";
|
|
2
|
+
import { readProjectStableKeyName } from "../project.js";
|
|
3
|
+
import { resolveResourceTarget } from "../resource-target.js";
|
|
4
|
+
import { activateVerifiedSchedules, buildSchedulesPlan, pullSchedulesToWorkspace, pushSchedules } from "../resource-syncs/schedule-sync.js";
|
|
5
|
+
import { planDependencyHints, printSyncNotice, printSyncPlan, printSyncStatus, printSyncSummary } from "../sync-output.js";
|
|
6
|
+
import { readBoolFlag } from "../utils.js";
|
|
7
|
+
export async function handleSchedulesCommand(context) {
|
|
8
|
+
const subcommand = context.args._[1] || '';
|
|
9
|
+
if (!['pull', 'plan', 'push'].includes(subcommand)) {
|
|
10
|
+
throw new Error('Unknown schedules command. Usage: revo schedules <pull|plan|push> --all [--env <name>]');
|
|
11
|
+
}
|
|
12
|
+
if (!readBoolFlag(context.args, ['all', 'a'])) {
|
|
13
|
+
throw new Error('Schedule sync currently requires --all.');
|
|
14
|
+
}
|
|
15
|
+
const { client, envName, displayName } = await resolveResourceTarget(context, { resource: 'Schedule' });
|
|
16
|
+
const activate = readBoolFlag(context.args, ['activate']);
|
|
17
|
+
if (activate && subcommand !== 'push') {
|
|
18
|
+
throw new Error('--activate is available only with schedules push.');
|
|
19
|
+
}
|
|
20
|
+
if (subcommand === 'push') {
|
|
21
|
+
const yes = readBoolFlag(context.args, ['yes', 'y']);
|
|
22
|
+
if (activate && !yes && !isInteractiveTerminal()) {
|
|
23
|
+
throw new Error('Schedule activation in non-interactive mode requires --yes --activate.');
|
|
24
|
+
}
|
|
25
|
+
if (!yes) {
|
|
26
|
+
if (!isInteractiveTerminal() || !await promptConfirm(`Push Schedules to "${displayName}"?`, false)) {
|
|
27
|
+
throw new Error('Schedule push requires confirmation. Re-run with --yes or use an interactive terminal.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const startedAt = Date.now();
|
|
31
|
+
const pushed = await pushSchedules({
|
|
32
|
+
client,
|
|
33
|
+
cwd: context.cwd,
|
|
34
|
+
envName,
|
|
35
|
+
stableKeyName: readProjectStableKeyName(context.cwd),
|
|
36
|
+
force: readBoolFlag(context.args, ['force', 'f']),
|
|
37
|
+
});
|
|
38
|
+
const results = [...pushed.results];
|
|
39
|
+
let activation;
|
|
40
|
+
if (activate) {
|
|
41
|
+
const candidateCount = pushed.verifiedActivationCandidates.length;
|
|
42
|
+
const confirmed = !isInteractiveTerminal() || await promptConfirm(`Activate ${candidateCount} verified Schedule(s) on "${displayName}"?`, false);
|
|
43
|
+
if (confirmed) {
|
|
44
|
+
const activationResults = await activateVerifiedSchedules({
|
|
45
|
+
client,
|
|
46
|
+
candidates: pushed.verifiedActivationCandidates,
|
|
47
|
+
});
|
|
48
|
+
results.push(...activationResults);
|
|
49
|
+
activation = { candidateCount, results: activationResults };
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
activation = { candidateCount, results: [], skipped: 'activation not confirmed' };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (readBoolFlag(context.args, ['json'])) {
|
|
56
|
+
context.print({
|
|
57
|
+
plan: pushed.plan,
|
|
58
|
+
results,
|
|
59
|
+
...(activation ? { activation } : {}),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
for (const item of results) {
|
|
64
|
+
const label = item.status === 'deployed' ? 'Deployed' : item.status === 'failed' ? 'Failed' : 'Skipped';
|
|
65
|
+
printSyncStatus(context.println, {
|
|
66
|
+
status: label,
|
|
67
|
+
direction: 'push',
|
|
68
|
+
targetPath: item.targetPath,
|
|
69
|
+
reason: item.error || item.reason,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (activation?.skipped) {
|
|
73
|
+
printSyncNotice(context.println, `${activation.candidateCount} verified Schedule activation candidate(s): ${activation.skipped}`);
|
|
74
|
+
}
|
|
75
|
+
printSyncSummary(context.println, 'Deployed', results, Date.now() - startedAt);
|
|
76
|
+
}
|
|
77
|
+
const failed = results.filter((item) => item.status === 'failed');
|
|
78
|
+
if (failed.length > 0) {
|
|
79
|
+
throw new Error(`Schedule push finished with ${failed.length} failure(s).`);
|
|
80
|
+
}
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
if (subcommand === 'plan') {
|
|
84
|
+
const plan = await buildSchedulesPlan({
|
|
85
|
+
client,
|
|
86
|
+
cwd: context.cwd,
|
|
87
|
+
envName,
|
|
88
|
+
stableKeyName: readProjectStableKeyName(context.cwd),
|
|
89
|
+
});
|
|
90
|
+
if (readBoolFlag(context.args, ['json'])) {
|
|
91
|
+
context.print(plan);
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
printSyncPlan(context.println, {
|
|
95
|
+
title: 'Schedule',
|
|
96
|
+
environment: displayName,
|
|
97
|
+
counts: plan.counts,
|
|
98
|
+
showHints: readBoolFlag(context.args, ['hints']),
|
|
99
|
+
items: plan.items.map((item) => ({
|
|
100
|
+
...item,
|
|
101
|
+
hints: item.dependency ? planDependencyHints(item.dependency) : undefined,
|
|
102
|
+
})),
|
|
103
|
+
warnings: [...plan.warnings, ...plan.exclusions],
|
|
104
|
+
blockers: plan.blockers,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
if (readBoolFlag(context.args, ['strict'])) {
|
|
108
|
+
const drift = plan.items.filter((item) => !['clean', 'orphan', 'skipped'].includes(item.status));
|
|
109
|
+
if (plan.blockers.length > 0 || plan.exclusions.length > 0 || drift.length > 0) {
|
|
110
|
+
throw new Error(`Schedule strict plan is not converged: ${drift.length} drift item(s), ${plan.blockers.length} blocker(s), ${plan.exclusions.length} exclusion(s).`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const startedAt = Date.now();
|
|
116
|
+
const result = await pullSchedulesToWorkspace({
|
|
117
|
+
client,
|
|
118
|
+
cwd: context.cwd,
|
|
119
|
+
envName,
|
|
120
|
+
stableKeyName: readProjectStableKeyName(context.cwd),
|
|
121
|
+
force: readBoolFlag(context.args, ['force', 'f']),
|
|
122
|
+
});
|
|
123
|
+
if (readBoolFlag(context.args, ['json'])) {
|
|
124
|
+
context.print(result);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const output = [];
|
|
128
|
+
for (const pulled of result.pulled) {
|
|
129
|
+
printSyncStatus(context.println, { status: 'Pulled', direction: 'pull', targetPath: pulled.targetPath });
|
|
130
|
+
output.push({ status: 'pulled', targetPath: pulled.targetPath });
|
|
131
|
+
}
|
|
132
|
+
for (const pruned of result.pruned) {
|
|
133
|
+
printSyncStatus(context.println, { status: 'Pruned', direction: 'pull', targetPath: pruned.targetPath });
|
|
134
|
+
output.push({ status: 'pruned', targetPath: pruned.targetPath });
|
|
135
|
+
}
|
|
136
|
+
for (const warning of result.warnings) {
|
|
137
|
+
printSyncNotice(context.println, `${warning.stableKey}: ${warning.reason}`);
|
|
138
|
+
}
|
|
139
|
+
printSyncSummary(context.println, 'Pulled', output, Date.now() - startedAt);
|
|
140
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type BrowserAction = 'navigate' | 'dom' | 'screenshot';
|
|
2
|
+
export declare function browserUrl(value: string): string;
|
|
3
|
+
export declare function localBrowserUrl(value: string): string;
|
|
4
|
+
export declare function runBrowserAction(input: {
|
|
5
|
+
url: string;
|
|
6
|
+
action: BrowserAction;
|
|
7
|
+
workspace: string;
|
|
8
|
+
selector?: string | null;
|
|
9
|
+
width?: number;
|
|
10
|
+
height?: number;
|
|
11
|
+
localOnly?: boolean;
|
|
12
|
+
signal?: AbortSignal;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
dom: string;
|
|
15
|
+
screenshotPath?: string;
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import { chromium } from 'playwright-core';
|
|
5
|
+
export function browserUrl(value) {
|
|
6
|
+
const parsed = new URL(value);
|
|
7
|
+
if (!['http:', 'https:'].includes(parsed.protocol) || parsed.username || parsed.password)
|
|
8
|
+
throw new Error('browser_url_not_allowed');
|
|
9
|
+
return parsed.toString();
|
|
10
|
+
}
|
|
11
|
+
export function localBrowserUrl(value) {
|
|
12
|
+
const parsed = new URL(browserUrl(value));
|
|
13
|
+
if (!['localhost', '127.0.0.1', '[::1]'].includes(parsed.hostname.toLowerCase()))
|
|
14
|
+
throw new Error('browser_localhost_only');
|
|
15
|
+
return parsed.toString();
|
|
16
|
+
}
|
|
17
|
+
export async function runBrowserAction(input) {
|
|
18
|
+
const url = input.localOnly ? localBrowserUrl(input.url) : browserUrl(input.url);
|
|
19
|
+
if (!['navigate', 'dom', 'screenshot'].includes(input.action))
|
|
20
|
+
throw new Error('invalid_browser_action');
|
|
21
|
+
const width = input.width ?? 1440;
|
|
22
|
+
const height = input.height ?? 900;
|
|
23
|
+
if (!Number.isInteger(width) || width < 320 || width > 1920
|
|
24
|
+
|| !Number.isInteger(height) || height < 240 || height > 1080)
|
|
25
|
+
throw new Error('invalid_browser_viewport');
|
|
26
|
+
if (input.selector && (input.selector.length > 500 || input.action === 'navigate'))
|
|
27
|
+
throw new Error('invalid_browser_selector');
|
|
28
|
+
const browser = await chromium.launch({ headless: true,
|
|
29
|
+
args: input.localOnly ? ['--disable-background-networking',
|
|
30
|
+
'--host-resolver-rules=MAP localhost 127.0.0.1'] : [] }).catch(error => {
|
|
31
|
+
if (error instanceof Error && error.message.includes("Executable doesn't exist at"))
|
|
32
|
+
throw new Error('browser_binary_unavailable');
|
|
33
|
+
throw error;
|
|
34
|
+
});
|
|
35
|
+
const onAbort = () => { void browser.close(); };
|
|
36
|
+
input.signal?.addEventListener('abort', onAbort, { once: true });
|
|
37
|
+
try {
|
|
38
|
+
if (input.signal?.aborted)
|
|
39
|
+
throw new Error('browser_cancelled');
|
|
40
|
+
const context = await browser.newContext({ viewport: { width, height }, acceptDownloads: false,
|
|
41
|
+
serviceWorkers: 'block' });
|
|
42
|
+
await context.route('**/*', route => {
|
|
43
|
+
try {
|
|
44
|
+
(input.localOnly ? localBrowserUrl : browserUrl)(route.request().url());
|
|
45
|
+
return route.continue();
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return route.abort();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
if (input.localOnly)
|
|
52
|
+
await context.routeWebSocket('**/*', socket => {
|
|
53
|
+
try {
|
|
54
|
+
const parsed = new URL(socket.url());
|
|
55
|
+
const httpUrl = parsed.protocol === 'wss:' ? `https://${parsed.host}${parsed.pathname}`
|
|
56
|
+
: parsed.protocol === 'ws:' ? `http://${parsed.host}${parsed.pathname}` : '';
|
|
57
|
+
localBrowserUrl(httpUrl);
|
|
58
|
+
socket.connectToServer();
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
socket.close();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const page = await context.newPage();
|
|
65
|
+
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 30_000 });
|
|
66
|
+
(input.localOnly ? localBrowserUrl : browserUrl)(page.url());
|
|
67
|
+
const target = input.selector ? page.locator(input.selector).first() : page.locator('body');
|
|
68
|
+
const dom = (await target.innerText({ timeout: 10_000 })).slice(0, 30_000);
|
|
69
|
+
if (input.action !== 'screenshot')
|
|
70
|
+
return { dom };
|
|
71
|
+
const root = fs.realpathSync(input.workspace);
|
|
72
|
+
const privateDirectory = path.join(root, '.revo');
|
|
73
|
+
fs.mkdirSync(privateDirectory, { recursive: true, mode: 0o700 });
|
|
74
|
+
if (fs.realpathSync(privateDirectory) !== privateDirectory)
|
|
75
|
+
throw new Error('browser_output_outside_workspace');
|
|
76
|
+
const directory = path.join(privateDirectory, 'browser-screenshots');
|
|
77
|
+
fs.mkdirSync(directory, { recursive: true, mode: 0o700 });
|
|
78
|
+
if (fs.realpathSync(directory) !== directory)
|
|
79
|
+
throw new Error('browser_output_outside_workspace');
|
|
80
|
+
const screenshotPath = path.join(directory, `${randomUUID()}.png`);
|
|
81
|
+
await (input.selector ? target : page).screenshot({ path: screenshotPath, timeout: 20_000 });
|
|
82
|
+
if (fs.statSync(screenshotPath).size > 30 * 1024 * 1024) {
|
|
83
|
+
fs.rmSync(screenshotPath, { force: true });
|
|
84
|
+
throw new Error('browser_screenshot_too_large');
|
|
85
|
+
}
|
|
86
|
+
return { dom, screenshotPath };
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
input.signal?.removeEventListener('abort', onAbort);
|
|
90
|
+
await browser.close();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type ImageUpload = {
|
|
2
|
+
path: string;
|
|
3
|
+
uploadUrl: string;
|
|
4
|
+
contentType: 'image/png' | 'image/jpeg' | 'image/webp';
|
|
5
|
+
};
|
|
6
|
+
export declare function resolveWorkspaceImage(workspace: string, file: string): string;
|
|
7
|
+
export declare function uploadWorkspaceImages(workspace: string, files: ImageUpload[], signal?: AbortSignal): Promise<number>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
const MAX_IMAGE_BYTES = 30 * 1024 * 1024;
|
|
4
|
+
const MAX_IMAGE_BATCH_BYTES = 240 * 1024 * 1024;
|
|
5
|
+
export function resolveWorkspaceImage(workspace, file) {
|
|
6
|
+
const root = fs.realpathSync(workspace);
|
|
7
|
+
const resolved = fs.realpathSync(file);
|
|
8
|
+
const relative = path.relative(root, resolved);
|
|
9
|
+
if (!relative || relative.startsWith('..') || path.isAbsolute(relative) || !fs.statSync(resolved).isFile())
|
|
10
|
+
throw new Error('image_outside_workspace');
|
|
11
|
+
const size = fs.statSync(resolved).size;
|
|
12
|
+
if (size < 1 || size > MAX_IMAGE_BYTES)
|
|
13
|
+
throw new Error('image_size_invalid');
|
|
14
|
+
return resolved;
|
|
15
|
+
}
|
|
16
|
+
export async function uploadWorkspaceImages(workspace, files, signal) {
|
|
17
|
+
if (!Array.isArray(files) || !files.length || files.length > 32)
|
|
18
|
+
throw new Error('invalid_image_batch');
|
|
19
|
+
const checked = files.map(file => ({ file, resolved: resolveWorkspaceImage(workspace, file.path) }));
|
|
20
|
+
if (checked.reduce((total, item) => total + fs.statSync(item.resolved).size, 0) > MAX_IMAGE_BATCH_BYTES)
|
|
21
|
+
throw new Error('image_batch_too_large');
|
|
22
|
+
for (const { file, resolved } of checked) {
|
|
23
|
+
const url = new URL(file.uploadUrl);
|
|
24
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.port
|
|
25
|
+
|| !/(^|\.)storage\.googleapis\.com$/iu.test(url.hostname))
|
|
26
|
+
throw new Error('image_upload_destination_invalid');
|
|
27
|
+
const data = fs.readFileSync(resolved);
|
|
28
|
+
const png = data.subarray(0, 8).equals(Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]));
|
|
29
|
+
const jpeg = data.subarray(0, 3).equals(Buffer.from([255, 216, 255]));
|
|
30
|
+
const webp = data.toString('ascii', 0, 4) === 'RIFF' && data.toString('ascii', 8, 12) === 'WEBP';
|
|
31
|
+
if (!((file.contentType === 'image/png' && png) || (file.contentType === 'image/jpeg' && jpeg)
|
|
32
|
+
|| (file.contentType === 'image/webp' && webp)))
|
|
33
|
+
throw new Error('image_content_mismatch');
|
|
34
|
+
const response = await fetch(url, { method: 'PUT', headers: { 'Content-Type': file.contentType },
|
|
35
|
+
body: data, signal: signal || AbortSignal.timeout(120_000), redirect: 'error' });
|
|
36
|
+
if (!response.ok)
|
|
37
|
+
throw new Error(`image_upload_failed_${response.status}`);
|
|
38
|
+
}
|
|
39
|
+
return files.length;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
import { applyWorkspacePatch } from "./terminal-patch.js";
|
|
3
|
+
async function main() {
|
|
4
|
+
const workspace = process.argv[2];
|
|
5
|
+
const allowDelete = process.argv[3] === 'true';
|
|
6
|
+
if (!workspace)
|
|
7
|
+
throw new Error('Workspace is required.');
|
|
8
|
+
const chunks = [];
|
|
9
|
+
let bytes = 0;
|
|
10
|
+
for await (const chunk of process.stdin) {
|
|
11
|
+
const data = Buffer.from(chunk);
|
|
12
|
+
bytes += data.length;
|
|
13
|
+
if (bytes > 64_000)
|
|
14
|
+
throw new Error('Patch exceeds 64 KB.');
|
|
15
|
+
chunks.push(data);
|
|
16
|
+
}
|
|
17
|
+
process.stdout.write(applyWorkspacePatch(Buffer.concat(chunks).toString('utf8'), workspace, allowDelete));
|
|
18
|
+
}
|
|
19
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
20
|
+
void main().catch(error => {
|
|
21
|
+
process.stderr.write(error instanceof Error ? error.message : String(error));
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
});
|
|
24
|
+
}
|