grada-run 0.41.5 → 0.43.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +18 -8
- package/package.json +1 -1
- package/src/commands/add.js +93 -11
- package/src/commands/alerts.js +69 -31
- package/src/commands/apply.js +62 -10
- package/src/commands/db/backup.js +1 -2
- package/src/commands/db/connect.js +27 -14
- package/src/commands/db/enable-vector.js +19 -6
- package/src/commands/db/import.js +114 -22
- package/src/commands/db/migrate.js +77 -73
- package/src/commands/db/restore.js +38 -6
- package/src/commands/destroy.js +68 -6
- package/src/commands/diagnose.js +57 -32
- package/src/commands/doctor.js +5 -3
- package/src/commands/domain.js +55 -7
- package/src/commands/drift.js +2 -1
- package/src/commands/eject.js +13 -2
- package/src/commands/exec.js +9 -4
- package/src/commands/gc.js +135 -6
- package/src/commands/init.js +75 -9
- package/src/commands/logs.js +127 -38
- package/src/commands/mcp.js +3 -2
- package/src/commands/rollback.js +230 -74
- package/src/commands/secrets.js +251 -61
- package/src/commands/status.js +17 -8
- package/src/commands/sync-ai.js +4 -3
- package/src/commands/wake.js +45 -1
- package/src/data/action-pins.js +26 -0
- package/src/utils/addons.js +9 -6
- package/src/utils/ai-rules.js +3 -2
- package/src/utils/backup.js +16 -2
- package/src/utils/command.js +20 -0
- package/src/utils/db-tunnel.js +15 -5
- package/src/utils/detector.js +8 -0
- package/src/utils/ecs-runner.js +16 -3
- package/src/utils/frameworks.js +14 -2
- package/src/utils/generator.js +33 -16
- package/src/utils/prompts.js +20 -4
- package/src/utils/resolvers.js +74 -11
- package/src/utils/revision-discovery.js +19 -7
- package/templates/docker/nestjs.Dockerfile +2 -2
- package/templates/docker/nextjs.Dockerfile +3 -3
- package/templates/docker/node.Dockerfile +2 -2
- package/templates/docker/nuxt.Dockerfile +2 -2
- package/templates/docker/static.Dockerfile +1 -1
- package/templates/docker/svelte.Dockerfile +2 -2
- package/templates/github/deploy-lambda.yml +73 -11
- package/templates/github/deploy-static.yml +4 -3
- package/templates/github/deploy.yml +114 -12
- package/templates/github/drift.yml +74 -5
- package/templates/github/preview-lambda.yml +143 -13
- package/templates/github/preview.yml +141 -13
- package/templates/github/teardown.yml +77 -12
- package/templates/terraform/addons/bedrock.tf +6 -2
- package/templates/terraform/addons/s3.tf +33 -0
- package/templates/terraform/backend.tf +7 -0
- package/templates/terraform/cloudfront-lambda.tf +125 -6
- package/templates/terraform/cloudfront.tf +137 -10
- package/templates/terraform/database-mysql.tf +5 -1
- package/templates/terraform/database.tf +5 -1
- package/templates/terraform/main.tf +36 -1
- package/templates/terraform/network.tf +5 -2
- package/templates/terraform/oidc.tf +3 -2
- package/templates/terraform/secrets.tf +6 -4
- package/templates/terraform/worker.tf +7 -0
package/src/commands/gc.js
CHANGED
|
@@ -6,6 +6,7 @@ import { CloudWatchLogsClient, DescribeLogGroupsCommand, DeleteLogGroupCommand }
|
|
|
6
6
|
import { ECSClient, ListClustersCommand, ListServicesCommand, DescribeServicesCommand } from '@aws-sdk/client-ecs';
|
|
7
7
|
import { EC2Client, DescribeAddressesCommand, ReleaseAddressCommand, DescribeVpcsCommand, DescribeSubnetsCommand } from '@aws-sdk/client-ec2';
|
|
8
8
|
import { SecretsManagerClient, ListSecretsCommand } from '@aws-sdk/client-secrets-manager';
|
|
9
|
+
import { RDSClient, DescribeDBSnapshotsCommand, DescribeDBClusterSnapshotsCommand, DeleteDBSnapshotCommand, DeleteDBClusterSnapshotCommand } from '@aws-sdk/client-rds';
|
|
9
10
|
import color from 'picocolors';
|
|
10
11
|
import { intro, outro, confirm, spinner, cancel } from '@clack/prompts';
|
|
11
12
|
import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
@@ -14,16 +15,23 @@ import { resolveRegion, resolveProjectName, resolveCwd, isComputeTarget, readRes
|
|
|
14
15
|
import { resolveClient } from '../utils/aws.js';
|
|
15
16
|
import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseIfNonInteractive, refuseUnknownFlags, shouldAutoApprove } from '../utils/command.js';
|
|
16
17
|
import { parseStateBucketBackend } from '../utils/terraform-metadata.js';
|
|
18
|
+
import { resolveDbIdentifier, resolveDbClusterIdentifier } from '../utils/rds.js';
|
|
17
19
|
|
|
18
20
|
export const CONFIRM_MESSAGE = 'Are you sure you want to permanently delete these orphaned resources? (y/N)';
|
|
19
21
|
|
|
22
|
+
// Pre-destroy manual snapshots younger than this are never proposed:
|
|
23
|
+
// recent destroys stay restorable until the threshold passes.
|
|
24
|
+
export const DEFAULT_SNAPSHOT_MAX_AGE_DAYS = 30;
|
|
25
|
+
|
|
20
26
|
export function parseGcArgs(argv = []) {
|
|
21
27
|
const args = normalizeArgv(argv);
|
|
22
28
|
if (args[0] === 'gc') args.shift();
|
|
23
29
|
// --yes auto-confirms the delete prompt (explicit opt-in; the default
|
|
24
30
|
// path still prompts). --deep adds the report-only deep scan.
|
|
31
|
+
// --snapshot-max-age-days retires pre-destroy manual snapshots older
|
|
32
|
+
// than N days (default 30).
|
|
25
33
|
const { options, unknown } = parseFlags(args, {
|
|
26
|
-
string: ['region', 'project-name'],
|
|
34
|
+
string: ['region', 'project-name', { name: 'snapshot-max-age-days', key: 'snapshotMaxAgeDays' }],
|
|
27
35
|
boolean: ['deep', 'yes', 'headless'],
|
|
28
36
|
});
|
|
29
37
|
if (unknown.length > 0) options.unknownFlags = unknown;
|
|
@@ -263,6 +271,50 @@ async function discoverUnattachedEips({ ec2Client, projectName }) {
|
|
|
263
271
|
return unattachedEips;
|
|
264
272
|
}
|
|
265
273
|
|
|
274
|
+
// Standard target discovery: pre-destroy manual snapshots older than
|
|
275
|
+
// the age threshold. Scoped by the exact `<db>-manual-<stamp>` naming
|
|
276
|
+
// pattern destroy writes (instance AND cluster snapshots) — foreign,
|
|
277
|
+
// automated, non-available, and young snapshots are never proposed.
|
|
278
|
+
// Tolerant of missing clients/identifiers (programmatic callers without
|
|
279
|
+
// RDS context discover nothing instead of throwing).
|
|
280
|
+
async function discoverOldManualSnapshots({ rdsClient, dbIdentifier, dbClusterIdentifier, snapshotMaxAgeDays } = {}) {
|
|
281
|
+
if (!rdsClient || (!dbIdentifier && !dbClusterIdentifier)) return [];
|
|
282
|
+
const maxAgeDays = Number(snapshotMaxAgeDays ?? DEFAULT_SNAPSHOT_MAX_AGE_DAYS);
|
|
283
|
+
const cutoffMs = Date.now() - (Number.isFinite(maxAgeDays) ? maxAgeDays : DEFAULT_SNAPSHOT_MAX_AGE_DAYS) * 86400000;
|
|
284
|
+
const patterns = [dbIdentifier, dbClusterIdentifier]
|
|
285
|
+
.filter((id) => typeof id === 'string' && id.trim())
|
|
286
|
+
.map((id) => new RegExp(`^${escapeRegExp(id.trim().toLowerCase())}-manual-\\d{8}-\\d{6}$`));
|
|
287
|
+
if (patterns.length === 0) return [];
|
|
288
|
+
const isRetirable = (snapshotId, status, type, createTime) => {
|
|
289
|
+
if (status !== 'available' || type !== 'manual') return false;
|
|
290
|
+
const createdMs = createTime ? new Date(createTime).getTime() : NaN;
|
|
291
|
+
if (!Number.isFinite(createdMs) || createdMs > cutoffMs) return false;
|
|
292
|
+
return patterns.some((pattern) => pattern.test(String(snapshotId).toLowerCase()));
|
|
293
|
+
};
|
|
294
|
+
const snapshots = [];
|
|
295
|
+
let marker;
|
|
296
|
+
do {
|
|
297
|
+
const resp = await rdsClient.send(new DescribeDBSnapshotsCommand({ Marker: marker, MaxRecords: 100 }));
|
|
298
|
+
for (const snap of resp.DBSnapshots || []) {
|
|
299
|
+
if (isRetirable(snap.DBSnapshotIdentifier, snap.Status, snap.SnapshotType, snap.SnapshotCreateTime)) {
|
|
300
|
+
snapshots.push({ id: snap.DBSnapshotIdentifier, kind: 'instance', createTime: snap.SnapshotCreateTime });
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
marker = resp.Marker;
|
|
304
|
+
} while (marker);
|
|
305
|
+
marker = undefined;
|
|
306
|
+
do {
|
|
307
|
+
const resp = await rdsClient.send(new DescribeDBClusterSnapshotsCommand({ Marker: marker, MaxRecords: 100 }));
|
|
308
|
+
for (const snap of resp.DBClusterSnapshots || []) {
|
|
309
|
+
if (isRetirable(snap.DBClusterSnapshotIdentifier, snap.Status, snap.SnapshotType, snap.SnapshotCreateTime)) {
|
|
310
|
+
snapshots.push({ id: snap.DBClusterSnapshotIdentifier, kind: 'cluster', createTime: snap.SnapshotCreateTime });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
marker = resp.Marker;
|
|
314
|
+
} while (marker);
|
|
315
|
+
return snapshots;
|
|
316
|
+
}
|
|
317
|
+
|
|
266
318
|
// Deep target discovery: VPCs partitioned by the STRICT deletion
|
|
267
319
|
// predicate — exact project tag only, minus live networks. Foreign and
|
|
268
320
|
// untagged VPCs land in reportOnly, never in deletable, so prefix
|
|
@@ -406,6 +458,13 @@ export const GC_TARGETS = [
|
|
|
406
458
|
format: (eip) => eip.PublicIp || eip.AllocationId,
|
|
407
459
|
listCap: Infinity,
|
|
408
460
|
},
|
|
461
|
+
{
|
|
462
|
+
id: 'db-snapshots', label: 'Old manual DB snapshots', scope: 'standard',
|
|
463
|
+
field: 'oldManualSnapshots', summary: 'deletedSnapshots',
|
|
464
|
+
discover: discoverOldManualSnapshots, remove: removeOldManualSnapshots,
|
|
465
|
+
format: (snap) => snap.id,
|
|
466
|
+
listCap: 10,
|
|
467
|
+
},
|
|
409
468
|
{
|
|
410
469
|
id: 'vpcs', label: 'VPCs', kind: 'vpc', scope: 'deep',
|
|
411
470
|
discover: discoverDeepVpcs, remove: null,
|
|
@@ -465,8 +524,12 @@ async function removeUntaggedImages({ ecrClient }, images) {
|
|
|
465
524
|
}
|
|
466
525
|
for (const [repositoryName, imageIds] of byRepo) {
|
|
467
526
|
for (const batch of chunkArray(imageIds, ECR_BATCH_DELETE_LIMIT)) {
|
|
468
|
-
await ecrClient.send(new BatchDeleteImageCommand({ repositoryName, imageIds: batch }));
|
|
469
|
-
|
|
527
|
+
const resp = await ecrClient.send(new BatchDeleteImageCommand({ repositoryName, imageIds: batch }));
|
|
528
|
+
const failed = resp?.failures?.length ?? 0;
|
|
529
|
+
if (failed > 0) {
|
|
530
|
+
console.log(color.yellow(`⚠ ${failed} of ${batch.length} image(s) in ${repositoryName} failed to delete (${resp.failures[0]?.failureCode || 'unknown'}).`));
|
|
531
|
+
}
|
|
532
|
+
deletedImages += batch.length - failed;
|
|
470
533
|
}
|
|
471
534
|
}
|
|
472
535
|
return deletedImages;
|
|
@@ -490,10 +553,37 @@ async function releaseUnattachedEips({ ec2Client }, eips) {
|
|
|
490
553
|
return releasedEips;
|
|
491
554
|
}
|
|
492
555
|
|
|
556
|
+
async function removeOldManualSnapshots({ rdsClient }, snapshots) {
|
|
557
|
+
let deletedSnapshots = 0;
|
|
558
|
+
for (const snap of snapshots || []) {
|
|
559
|
+
if (snap.kind === 'cluster') {
|
|
560
|
+
await rdsClient.send(new DeleteDBClusterSnapshotCommand({ DBClusterSnapshotIdentifier: snap.id }));
|
|
561
|
+
} else {
|
|
562
|
+
await rdsClient.send(new DeleteDBSnapshotCommand({ DBSnapshotIdentifier: snap.id }));
|
|
563
|
+
}
|
|
564
|
+
deletedSnapshots += 1;
|
|
565
|
+
}
|
|
566
|
+
return deletedSnapshots;
|
|
567
|
+
}
|
|
568
|
+
|
|
493
569
|
export async function deleteDiscoveredResources(clients, discovered) {
|
|
494
570
|
const summary = {};
|
|
571
|
+
const errors = [];
|
|
495
572
|
for (const target of GC_TARGETS.filter((entry) => entry.scope === 'standard' && typeof entry.remove === 'function')) {
|
|
496
|
-
|
|
573
|
+
try {
|
|
574
|
+
summary[target.summary] = await target.remove(clients, discovered[target.field] || []);
|
|
575
|
+
} catch (error) {
|
|
576
|
+
// One target's API failure must not strand the rest (BUG-105):
|
|
577
|
+
// record it, zero its count, and keep deleting.
|
|
578
|
+
errors.push({ target: target.summary, error });
|
|
579
|
+
summary[target.summary] = 0;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
if (errors.length > 0) {
|
|
583
|
+
const failure = new Error(`gc deletion partially failed: ${errors.map(({ target, error }) => `${target} (${error?.message || error})`).join('; ')}`);
|
|
584
|
+
failure.partialSummary = summary;
|
|
585
|
+
failure.failures = errors;
|
|
586
|
+
throw failure;
|
|
497
587
|
}
|
|
498
588
|
return summary;
|
|
499
589
|
}
|
|
@@ -570,8 +660,26 @@ async function runGcMain(input = {}) {
|
|
|
570
660
|
const ec2Client = resolveClient(options.ec2Client, EC2Client, { region });
|
|
571
661
|
const ecsClient = resolveClient(options.ecsClient, ECSClient, { region });
|
|
572
662
|
const secretsClient = resolveClient(options.secretsClient, SecretsManagerClient, { region });
|
|
663
|
+
const rdsClient = resolveClient(options.rdsClient, RDSClient, { region });
|
|
573
664
|
const deep = options.deep === true || options.deep === 'true';
|
|
574
665
|
|
|
666
|
+
let snapshotMaxAgeDays = DEFAULT_SNAPSHOT_MAX_AGE_DAYS;
|
|
667
|
+
if (options.snapshotMaxAgeDays !== undefined && options.snapshotMaxAgeDays !== null && String(options.snapshotMaxAgeDays).trim() !== '') {
|
|
668
|
+
const parsed = Number(options.snapshotMaxAgeDays);
|
|
669
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
670
|
+
return failCommand({
|
|
671
|
+
noExit: isProgrammaticCall(options),
|
|
672
|
+
message: `\n✖ Invalid --snapshot-max-age-days "${options.snapshotMaxAgeDays}". Use a non-negative number of days (default ${DEFAULT_SNAPSHOT_MAX_AGE_DAYS}).\n`,
|
|
673
|
+
event: 'gc_run',
|
|
674
|
+
telemetry: { projectName },
|
|
675
|
+
errorCode: 'INVALID_SNAPSHOT_MAX_AGE_DAYS',
|
|
676
|
+
reason: 'invalid-snapshot-max-age-days',
|
|
677
|
+
resultExtra: { projectName, region },
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
snapshotMaxAgeDays = parsed;
|
|
681
|
+
}
|
|
682
|
+
|
|
575
683
|
intro(color.bgCyan(color.black(' grada gc 🧹 ')));
|
|
576
684
|
|
|
577
685
|
const s = spinner();
|
|
@@ -582,6 +690,9 @@ async function runGcMain(input = {}) {
|
|
|
582
690
|
let previewClusterServices = null;
|
|
583
691
|
try {
|
|
584
692
|
const isLambda = isComputeTarget(cwd, 'lambda');
|
|
693
|
+
// Static projects cannot have a database: snapshot discovery is
|
|
694
|
+
// skipped entirely (no identifiers, no RDS calls).
|
|
695
|
+
const isStatic = isComputeTarget(cwd, 'static');
|
|
585
696
|
const suffix = readResourceSuffix(cwd);
|
|
586
697
|
// One cluster-service enumeration shared by the log-group and
|
|
587
698
|
// (deep) VPC liveness consumers — fetched once, not per scan.
|
|
@@ -602,7 +713,11 @@ async function runGcMain(input = {}) {
|
|
|
602
713
|
ecrClient,
|
|
603
714
|
logsClient,
|
|
604
715
|
ec2Client,
|
|
716
|
+
rdsClient,
|
|
605
717
|
projectName,
|
|
718
|
+
dbIdentifier: isStatic ? undefined : resolveDbIdentifier(options, cwd),
|
|
719
|
+
dbClusterIdentifier: isStatic ? undefined : resolveDbClusterIdentifier(options, cwd),
|
|
720
|
+
snapshotMaxAgeDays,
|
|
606
721
|
resourceSuffix: suffix,
|
|
607
722
|
isLambda,
|
|
608
723
|
logGroupPrefix: isLambda ? `/aws/lambda/${projectName}-` : undefined,
|
|
@@ -718,10 +833,24 @@ async function runGcMain(input = {}) {
|
|
|
718
833
|
|
|
719
834
|
const del = spinner();
|
|
720
835
|
del.start('Deleting orphaned resources...');
|
|
721
|
-
|
|
836
|
+
let summary;
|
|
837
|
+
try {
|
|
838
|
+
summary = await deleteDiscoveredResources({ ecrClient, logsClient, ec2Client, rdsClient }, discovered);
|
|
839
|
+
} catch (error) {
|
|
840
|
+
del.stop(color.red('❌ Deletion partially failed.'));
|
|
841
|
+
const partial = (error && typeof error === 'object' && error.partialSummary) || {};
|
|
842
|
+
return failCommand({
|
|
843
|
+
message: `\n✖ ${error?.message || error}\n`,
|
|
844
|
+
hint: ' Completed targets stay deleted; fix the cause and re-run to finish the rest.\n',
|
|
845
|
+
event: 'gc_run',
|
|
846
|
+
telemetry: { projectName, error_code: 'GC_PARTIAL_DELETE_FAILED', ...partial },
|
|
847
|
+
reason: 'gc-partial-delete-failed',
|
|
848
|
+
resultExtra: { ...partial },
|
|
849
|
+
});
|
|
850
|
+
}
|
|
722
851
|
del.stop('Deletion complete.');
|
|
723
852
|
|
|
724
|
-
outro(color.green(`Deleted ${summary.deletedImages} image(s), ${summary.deletedLogGroups} log group(s), released ${summary.releasedEips} Elastic IP(s). ✅`));
|
|
853
|
+
outro(color.green(`Deleted ${summary.deletedImages} image(s), ${summary.deletedLogGroups} log group(s), released ${summary.releasedEips} Elastic IP(s), deleted ${summary.deletedSnapshots} snapshot(s). ✅`));
|
|
725
854
|
await trackSuccess('gc_run', { projectName, deleted: true, ...summary, total: discovered.totalCount });
|
|
726
855
|
return { ...discovered, ...summary, deleted: true, confirmed: true };
|
|
727
856
|
}
|
package/src/commands/init.js
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
SUPPORTED_FRAMEWORKS
|
|
22
22
|
} from '../utils/detector.js';
|
|
23
23
|
import { detectProjectCapabilities } from '../utils/capabilities.js';
|
|
24
|
-
import { ADDON_REGISTRY } from '../utils/addons.js';
|
|
24
|
+
import { ADDON_REGISTRY, addonTargetDisposition, addonSupportedTargets } from '../utils/addons.js';
|
|
25
25
|
import { validateAddonFlags, resolveAddonOptions, scaffoldAddon, DEFAULT_BEDROCK_MODEL } from './add.js';
|
|
26
26
|
import { injectMigrationGate, injectPreviewMigrationGate } from './db/migrate.js';
|
|
27
27
|
import { scaffoldDriftWorkflow } from './drift.js';
|
|
@@ -38,7 +38,7 @@ import { getTargetDirectory, getProjectConfig, promptWorkerCommand, promptGitHub
|
|
|
38
38
|
import { resolveDjangoWsgi, handleRailsCI } from '../utils/frameworks.js';
|
|
39
39
|
import { parseDockerCompose, selectComposeWebService } from '../utils/dockerCompose.js';
|
|
40
40
|
import { getBaseRules, getCursorRules, injectManagedBlock } from '../utils/ai-rules.js';
|
|
41
|
-
import { readFileSafe, COMPUTE_TARGETS, resolveHeadless, resolveInitSuffix, readTerraformProjectName, readTerraformOidcTrust } from '../utils/resolvers.js';
|
|
41
|
+
import { readFileSafe, COMPUTE_TARGETS, resolveHeadless, resolveInitSuffix, readTerraformProjectName, readTerraformOidcTrust, guardComputeTarget } from '../utils/resolvers.js';
|
|
42
42
|
import { readGitHubRepoFromRemote, isValidGitHubRepoSlug } from '../utils/git.js';
|
|
43
43
|
import { parseDomainTf } from '../utils/domains.js';
|
|
44
44
|
import { PLACEHOLDER_ACCOUNT_ID } from '../utils/reconcile.js';
|
|
@@ -53,15 +53,16 @@ export const OFFLINE_ACCOUNT_PLACEHOLDER = PLACEHOLDER_ACCOUNT_ID;
|
|
|
53
53
|
// so it lands in CI logs as well as terminals. Mirrors every call
|
|
54
54
|
// provisionStateBucket makes (create + tag + versioning), including its
|
|
55
55
|
// us-east-1 LocationConstraint exception.
|
|
56
|
-
export function printOfflineChecklist({ bucket, region }) {
|
|
56
|
+
export function printOfflineChecklist({ bucket, region, workflows = ['deploy', 'preview', 'teardown', 'drift'] }) {
|
|
57
57
|
const locationArg = region === 'us-east-1' ? '' : ` --create-bucket-configuration LocationConstraint=${region}`;
|
|
58
|
+
const rendered = Array.isArray(workflows) && workflows.length > 0 ? workflows : ['deploy'];
|
|
58
59
|
console.log('');
|
|
59
60
|
console.log(color.yellow('⚠️ Offline scaffold: no AWS resources were created. Reconcile before applying:'));
|
|
60
61
|
console.log(` 1. Create the state bucket (replace ${OFFLINE_ACCOUNT_PLACEHOLDER} with yours):`);
|
|
61
62
|
console.log(color.cyan(` aws s3api create-bucket --bucket ${bucket} --region ${region}${locationArg}`));
|
|
62
63
|
console.log(color.cyan(` aws s3api put-bucket-tagging --bucket ${bucket} --tagging 'TagSet=[{Key=ManagedBy,Value=grada}]'`));
|
|
63
64
|
console.log(color.cyan(` aws s3api put-bucket-versioning --bucket ${bucket} --versioning-configuration Status=Enabled`));
|
|
64
|
-
console.log(` 2. Replace every ${OFFLINE_ACCOUNT_PLACEHOLDER} with your account ID: the bucket name in terraform/backend.tf plus every role-to-assume ARN in .github/workflows/*.yml (
|
|
65
|
+
console.log(` 2. Replace every ${OFFLINE_ACCOUNT_PLACEHOLDER} with your account ID: the bucket name in terraform/backend.tf plus every role-to-assume ARN in .github/workflows/*.yml (${rendered.join(', ')}).`);
|
|
65
66
|
console.log(` 3. Run ${color.cyan('terraform init')} in terraform/, then ${color.cyan('grada apply')}.`);
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -394,6 +395,30 @@ async function mainStackMain(input = {}) {
|
|
|
394
395
|
target = targetAnswer;
|
|
395
396
|
}
|
|
396
397
|
|
|
398
|
+
// Capability-vs-target policy for --with (BUG-157): refuse fast when
|
|
399
|
+
// the requested capability cannot render on this target (static has
|
|
400
|
+
// no task role or VPC), before any prompt/AWS call/write. Interactive
|
|
401
|
+
// multiselect offers only compatible targets' caps; this covers --with.
|
|
402
|
+
for (const cap of withList) {
|
|
403
|
+
if (!ADDON_REGISTRY[cap]) continue;
|
|
404
|
+
if (addonTargetDisposition(cap, target) === 'refuse') {
|
|
405
|
+
const targetGuard = guardComputeTarget({
|
|
406
|
+
actual: target,
|
|
407
|
+
command: `init --with ${cap}`,
|
|
408
|
+
supported: addonSupportedTargets(cap),
|
|
409
|
+
hint: 'Static sites run no containers — this capability needs a compute target (--target ecs or lambda).',
|
|
410
|
+
});
|
|
411
|
+
return failCommand({
|
|
412
|
+
message: targetGuard.message,
|
|
413
|
+
hint: targetGuard.hint,
|
|
414
|
+
event: 'cli-error',
|
|
415
|
+
telemetry: { step: 'init_validation', error_code: targetGuard.errorCode },
|
|
416
|
+
reason: targetGuard.reason,
|
|
417
|
+
resultExtra: { capability: cap },
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
397
422
|
const detectedFramework = detectFramework(dirConfig.targetDir);
|
|
398
423
|
const procfile = parseProcfile(dirConfig.targetDir);
|
|
399
424
|
const vercelRules = parseVercelConfig(dirConfig.targetDir);
|
|
@@ -446,7 +471,7 @@ async function mainStackMain(input = {}) {
|
|
|
446
471
|
config.dbEngine = 'postgres';
|
|
447
472
|
}
|
|
448
473
|
const djangoWsgi = await resolveDjangoWsgi(dirConfig.targetDir, procfile, config.framework, isHeadless);
|
|
449
|
-
const disableDefaultCI = await handleRailsCI(dirConfig.targetDir, config.framework, isHeadless);
|
|
474
|
+
const disableDefaultCI = await handleRailsCI(dirConfig.targetDir, config.framework, isHeadless, { force: initOptions.force === true });
|
|
450
475
|
|
|
451
476
|
// 3b. Dependency-aware composition (worker, migration gate, addons).
|
|
452
477
|
// Everything here resolves before backups, AWS calls, or file writes.
|
|
@@ -503,6 +528,14 @@ async function mainStackMain(input = {}) {
|
|
|
503
528
|
workerCommandHcl = `command = ${toHclStringArray(splitProcfileCommand(workerAnswer.trim()))}`;
|
|
504
529
|
}
|
|
505
530
|
}
|
|
531
|
+
if (!isInteractive && !isStaticSite && target !== 'lambda' && target !== 'static' && !procfile?.worker && capabilities.worker.detected) {
|
|
532
|
+
// The suggested command is an npm shim (broken on stripped
|
|
533
|
+
// runners), so headless never scaffolds it blindly — but the
|
|
534
|
+
// detection must not vanish silently either.
|
|
535
|
+
const evidence = (capabilities.worker.evidence || []).join(', ') || 'worker signals';
|
|
536
|
+
const suggested = capabilities.worker.suggestedCommand || 'none';
|
|
537
|
+
log.warn(color.yellow(`⚠️ Skipping the background worker: detection found ${evidence} but no Procfile worker process, and the suggested command ("${suggested}") needs interactive confirmation. Re-run init interactively to configure the worker command.`));
|
|
538
|
+
}
|
|
506
539
|
if (target === 'lambda' && (procfile?.worker || capabilities.worker.detected)) {
|
|
507
540
|
log.warn(color.yellow('⚠️ Skipping the background worker: Lambda targets run a single scale-to-zero function with no ECS worker service.'));
|
|
508
541
|
}
|
|
@@ -547,14 +580,14 @@ async function mainStackMain(input = {}) {
|
|
|
547
580
|
if (!isInteractive) {
|
|
548
581
|
return failCommand({
|
|
549
582
|
message: `\n✖ Refusing to wire the pre-deploy migration gate with "${migrationCmd}": the generated ${config.framework} Dockerfile strips npm/npx from the runner image, so this command would fail with "command not found" on every deploy.\n`,
|
|
550
|
-
hint: ' Re-run with an explicit node-based command, e.g. `--setup-ci-migrate="node ./dist/migrate.cjs"`, or wire the gate later with `grada db migrate --cmd "node ./dist/migrate.cjs" --setup-ci
|
|
583
|
+
hint: ' Re-run with an explicit node-based command, e.g. `--setup-ci-migrate="node ./dist/migrate.cjs"`, or wire the gate later with `grada db migrate --cmd "node ./dist/migrate.cjs" --setup-ci`. Ensure your Dockerfile builds the bundle and copies it into the runner image.\n',
|
|
551
584
|
event: 'cli-error',
|
|
552
585
|
telemetry: { step: 'init_setup', cmd_source: migrationCmdSource, error_code: 'NPM_CMD_STRIPPED_RUNNER' },
|
|
553
586
|
errorCode: 'NPM_CMD_STRIPPED_RUNNER',
|
|
554
587
|
reason: 'npm-cmd-stripped-runner',
|
|
555
588
|
});
|
|
556
589
|
}
|
|
557
|
-
console.log(color.yellow(`⚠️ The ${migrationCmdSource} migration command ("${migrationCmd}") starts with npm/npx but the generated ${config.framework} Dockerfile strips those binaries from the runner image — the gate will fail unless you switch to a node-based command (e.g. "node ./dist/migrate.cjs").`));
|
|
590
|
+
console.log(color.yellow(`⚠️ The ${migrationCmdSource} migration command ("${migrationCmd}") starts with npm/npx but the generated ${config.framework} Dockerfile strips those binaries from the runner image — the gate will fail unless you switch to a node-based command (e.g. "node ./dist/migrate.cjs"). Ensure your Dockerfile builds the bundle and copies it into the runner image.`));
|
|
558
591
|
trackEvent('npm_cmd_stripped_runner', { projectName: dirConfig.actualProjectName, cmd_source: migrationCmdSource, ci_setup: true });
|
|
559
592
|
}
|
|
560
593
|
|
|
@@ -680,6 +713,22 @@ async function mainStackMain(input = {}) {
|
|
|
680
713
|
log.warn(color.yellow(`⚠️ vercel.json redirects were detected, but ${target === 'static' ? 'static' : 'Lambda'} targets have no ALB listener rules to translate them into. ${remedy}`));
|
|
681
714
|
}
|
|
682
715
|
|
|
716
|
+
// Headers/rewrites have no translator on any target — name the dropped
|
|
717
|
+
// counts loudly, or the "Migrating edge network rules" success line
|
|
718
|
+
// reads as if everything migrated.
|
|
719
|
+
{
|
|
720
|
+
const migratedRedirects = (target === 'lambda' || target === 'static') ? 0 : (vercelRules?.redirects?.length || 0);
|
|
721
|
+
const droppedHeaders = vercelRules?.headers?.length || 0;
|
|
722
|
+
const droppedRewrites = vercelRules?.rewrites?.length || 0;
|
|
723
|
+
if (droppedHeaders > 0 || droppedRewrites > 0) {
|
|
724
|
+
const dropped = [
|
|
725
|
+
droppedHeaders > 0 ? `${droppedHeaders} header rule${droppedHeaders === 1 ? '' : 's'}` : null,
|
|
726
|
+
droppedRewrites > 0 ? `${droppedRewrites} rewrite${droppedRewrites === 1 ? '' : 's'}` : null,
|
|
727
|
+
].filter(Boolean).join(' and ');
|
|
728
|
+
log.warn(color.yellow(`⚠️ vercel.json ${dropped} were detected but are not migrated (only redirects translate to ALB listener rules — ${migratedRedirects} migrated). Recreate them as CloudFront Functions or ALB listener rules after provisioning.`));
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
683
732
|
if (config.framework === 'nestjs') {
|
|
684
733
|
const nestAnalysis = analyzeNestApp(dirConfig.targetDir);
|
|
685
734
|
if (nestAnalysis.hasMain && !nestAnalysis.listensOnAllInterfaces) {
|
|
@@ -871,9 +920,14 @@ async function mainStackMain(input = {}) {
|
|
|
871
920
|
}
|
|
872
921
|
|
|
873
922
|
if (driftEnabled) {
|
|
923
|
+
// drift.yml rides the manifest + backup like deploy.yml now
|
|
924
|
+
// (BUG-158): re-init backs the old file up and regenerates fresh
|
|
925
|
+
// (current role ARN) instead of silently keeping a stale copy.
|
|
926
|
+
// Hand edits trip refuse-dirty before this point; --force regenerates.
|
|
874
927
|
const drifted = scaffoldDriftWorkflow(dirConfig.targetDir, {
|
|
875
928
|
region: config.region,
|
|
876
929
|
roleArn: `arn:aws:iam::${awsAccountId}:role/${dirConfig.actualProjectName}${resourceSuffix}-github-actions-role`,
|
|
930
|
+
force: initOptions.force,
|
|
877
931
|
});
|
|
878
932
|
if (drifted.ok) {
|
|
879
933
|
console.log(color.green('✅ Scaffolded .github/workflows/drift.yml (scheduled IaC drift detection)'));
|
|
@@ -1033,7 +1087,9 @@ async function mainStackMain(input = {}) {
|
|
|
1033
1087
|
if (upcoming.vector) {
|
|
1034
1088
|
console.log(color.dim(' 💡 Vector-search dependencies detected: managed pgvector support is coming soon.'));
|
|
1035
1089
|
}
|
|
1036
|
-
|
|
1090
|
+
// Static targets refuse `add cron` (no compute) — don't send
|
|
1091
|
+
// static users down a dead end (BUG-157).
|
|
1092
|
+
if (upcoming.cron && target !== 'static') {
|
|
1037
1093
|
console.log(color.dim(' 💡 Scheduled-task dependencies detected: scaffold a schedule with "grada add cron".'));
|
|
1038
1094
|
}
|
|
1039
1095
|
if (upcoming.mysql) {
|
|
@@ -1065,7 +1121,17 @@ async function mainStackMain(input = {}) {
|
|
|
1065
1121
|
if (offlineScaffold) {
|
|
1066
1122
|
// Pass the exact backend bucket (suffix included) — recomputing
|
|
1067
1123
|
// from the bare project name prints a bucket terraform never uses.
|
|
1068
|
-
|
|
1124
|
+
// Step 2 names only emitted workflows: preview/teardown render
|
|
1125
|
+
// with PR previews, drift only when enabled.
|
|
1126
|
+
printOfflineChecklist({
|
|
1127
|
+
bucket: stateBucketName,
|
|
1128
|
+
region: config.region,
|
|
1129
|
+
workflows: [
|
|
1130
|
+
'deploy',
|
|
1131
|
+
...(config.enablePrPreviews ? ['preview', 'teardown'] : []),
|
|
1132
|
+
...(driftEnabled ? ['drift'] : []),
|
|
1133
|
+
],
|
|
1134
|
+
});
|
|
1069
1135
|
}
|
|
1070
1136
|
|
|
1071
1137
|
await flushTelemetry();
|
package/src/commands/logs.js
CHANGED
|
@@ -3,7 +3,7 @@ import color from 'picocolors';
|
|
|
3
3
|
import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveCommandName, resetActiveCommandName } from '../core/telemetry.js';
|
|
4
4
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
5
5
|
import { isAuthError, handleAuthErrorBranch, resolveClient } from '../utils/aws.js';
|
|
6
|
-
import { resolveRegion, resolveProjectName, resolveLogGroup, resolveCwd, isComputeTarget } from '../utils/resolvers.js';
|
|
6
|
+
import { resolveRegion, resolveProjectName, resolveLogGroup, resolveCwd, isComputeTarget, withWorkspaceNamespace } from '../utils/resolvers.js';
|
|
7
7
|
import { failCommand, failProjectNotInitialized, isProgrammaticCall, refuseUnknownFlags } from '../utils/command.js';
|
|
8
8
|
import { sleep } from '../utils/system.js';
|
|
9
9
|
|
|
@@ -40,6 +40,18 @@ export function normalizeTailLines(value) {
|
|
|
40
40
|
return n;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
function isValidTailLines(value) {
|
|
44
|
+
if (typeof value === 'number') return Number.isInteger(value) && value >= 1;
|
|
45
|
+
if (typeof value === 'string') return /^\d+$/.test(value.trim()) && parseInt(value, 10) >= 1;
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function isValidSinceDuration(value) {
|
|
50
|
+
if (typeof value === 'number') return Number.isFinite(value);
|
|
51
|
+
if (typeof value === 'string') return SINCE_RE.test(value.trim());
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
export function parseSinceDuration(input) {
|
|
44
56
|
if (input === undefined || input === null || input === '') return UNIT_MS.h;
|
|
45
57
|
if (typeof input === 'number' && Number.isFinite(input)) return Math.max(0, input * 1000);
|
|
@@ -86,7 +98,7 @@ export function parseLogsArgs(argv = []) {
|
|
|
86
98
|
const args = normalizeArgv(argv);
|
|
87
99
|
if (args[0] === 'logs') args.shift();
|
|
88
100
|
const { options, rest, unknown } = parseFlags(args, {
|
|
89
|
-
string: ['since', 'region'],
|
|
101
|
+
string: ['since', 'region', 'workspace'],
|
|
90
102
|
number: ['tail'],
|
|
91
103
|
boolean: ['headless'],
|
|
92
104
|
bareBoolean: ['follow', 'error'],
|
|
@@ -103,6 +115,44 @@ function eventKey(event) {
|
|
|
103
115
|
return `${event.timestamp}:${event.message}`;
|
|
104
116
|
}
|
|
105
117
|
|
|
118
|
+
// Fetches the most recent matching events from a log group.
|
|
119
|
+
// FilterLogEvents pages oldest-first, so slicing the first page shows the
|
|
120
|
+
// OLDEST N on groups larger than one page (BUG-87). This probes with a
|
|
121
|
+
// small page (cheap when the group fits), and only multi-page groups pay
|
|
122
|
+
// for a wide-page scan to the live edge; a rolling window keeps memory
|
|
123
|
+
// O(tail). Returns `{ events, nextToken }` — the trailing window plus the
|
|
124
|
+
// last valid page token (for follow-mode continuation).
|
|
125
|
+
export async function fetchLatestEvents(logsClient, baseInput = {}, { tail = DEFAULT_TAIL_LINES, onlyErrors = false } = {}) {
|
|
126
|
+
const want = Math.max(1, tail);
|
|
127
|
+
const probeSize = Math.min(want, 10000);
|
|
128
|
+
const first = await logsClient.send(new FilterLogEventsCommand({ ...baseInput, limit: probeSize }));
|
|
129
|
+
if (!first.nextToken) {
|
|
130
|
+
const events = first.events || [];
|
|
131
|
+
return {
|
|
132
|
+
events: (onlyErrors ? events.filter((e) => isErrorLine(e.message)) : events).slice(-want),
|
|
133
|
+
nextToken: undefined,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
const window = [];
|
|
137
|
+
let nextToken;
|
|
138
|
+
let lastToken;
|
|
139
|
+
do {
|
|
140
|
+
const resp = await logsClient.send(new FilterLogEventsCommand({
|
|
141
|
+
...baseInput,
|
|
142
|
+
limit: 10000,
|
|
143
|
+
...(nextToken ? { nextToken } : {}),
|
|
144
|
+
}));
|
|
145
|
+
const events = onlyErrors ? (resp.events || []).filter((e) => isErrorLine(e.message)) : (resp.events || []);
|
|
146
|
+
for (const event of events) {
|
|
147
|
+
window.push(event);
|
|
148
|
+
if (window.length > want) window.shift();
|
|
149
|
+
}
|
|
150
|
+
if (resp.nextToken) lastToken = resp.nextToken;
|
|
151
|
+
nextToken = resp.nextToken;
|
|
152
|
+
} while (nextToken);
|
|
153
|
+
return { events: window, nextToken: lastToken };
|
|
154
|
+
}
|
|
155
|
+
|
|
106
156
|
export function isNotFoundError(error) {
|
|
107
157
|
return error && (
|
|
108
158
|
error.name === 'ResourceNotFoundException' ||
|
|
@@ -145,8 +195,12 @@ async function runLogsMain(input = {}) {
|
|
|
145
195
|
try {
|
|
146
196
|
cwd = resolveCwd(options);
|
|
147
197
|
region = resolveRegion(options, cwd);
|
|
148
|
-
|
|
149
|
-
|
|
198
|
+
// Workspace-namespaced resources (BUG-90): --workspace (or the
|
|
199
|
+
// local .terraform/environment) targets a preview stack like
|
|
200
|
+
// rollback and db do. Explicit flags/env keep winning.
|
|
201
|
+
const namespacedOptions = withWorkspaceNamespace(options, cwd);
|
|
202
|
+
service = resolveServiceName(namespacedOptions, cwd);
|
|
203
|
+
logGroup = resolveLogGroup(namespacedOptions, cwd);
|
|
150
204
|
} catch {
|
|
151
205
|
return failProjectNotInitialized({ event: 'logs_streamed' });
|
|
152
206
|
}
|
|
@@ -158,7 +212,35 @@ async function runLogsMain(input = {}) {
|
|
|
158
212
|
const isLambda = isComputeTarget(cwd, 'lambda');
|
|
159
213
|
const explicitService = hasExplicitService(options) && !isLambda;
|
|
160
214
|
|
|
161
|
-
|
|
215
|
+
// Explicit garbage fails loud (BUG-107): silently substituting defaults
|
|
216
|
+
// for a mistyped --tail/--since shows logs the user never asked for.
|
|
217
|
+
// Absent flags still default via the normalizers below.
|
|
218
|
+
const rawTail = options.tail ?? options.tailLines ?? options.lines;
|
|
219
|
+
if (rawTail !== undefined && !isValidTailLines(rawTail)) {
|
|
220
|
+
return failCommand({
|
|
221
|
+
noExit: isProgrammaticCall(options),
|
|
222
|
+
message: `\n✖ Invalid --tail "${rawTail}". Pass a positive integer (line count).\n`,
|
|
223
|
+
event: 'logs_streamed',
|
|
224
|
+
telemetry: { projectName: resolveProjectName(options, cwd) },
|
|
225
|
+
errorCode: 'INVALID_TAIL',
|
|
226
|
+
reason: 'invalid-tail',
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const rawSince = options.since ?? options.sinceDuration;
|
|
230
|
+
if (rawSince !== undefined && !isValidSinceDuration(rawSince)) {
|
|
231
|
+
return failCommand({
|
|
232
|
+
noExit: isProgrammaticCall(options),
|
|
233
|
+
message: `\n✖ Invalid --since "${rawSince}". Pass a duration like 30s, 5m, 1h, or 7d.\n`,
|
|
234
|
+
event: 'logs_streamed',
|
|
235
|
+
telemetry: { projectName: resolveProjectName(options, cwd) },
|
|
236
|
+
errorCode: 'INVALID_SINCE',
|
|
237
|
+
reason: 'invalid-since',
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// Follow defaults to the same bounded window: an unbounded initial
|
|
242
|
+
// scan walks every page of history before printing the live edge.
|
|
243
|
+
const sinceRaw = options.since ?? options.sinceDuration ?? DEFAULT_SINCE;
|
|
162
244
|
const startTime = sinceRaw === undefined ? undefined : Date.now() - parseSinceDuration(sinceRaw);
|
|
163
245
|
|
|
164
246
|
const pollIntervalMs = options.pollIntervalMs ?? FOLLOW_POLL_INTERVAL_MS;
|
|
@@ -194,40 +276,47 @@ async function runLogsMain(input = {}) {
|
|
|
194
276
|
|
|
195
277
|
const seen = new Set();
|
|
196
278
|
const collected = [];
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
279
|
+
const dedupe = (e) => {
|
|
280
|
+
const key = eventKey(e);
|
|
281
|
+
if (seen.has(key)) return false;
|
|
282
|
+
seen.add(key);
|
|
283
|
+
return true;
|
|
284
|
+
};
|
|
285
|
+
const baseInput = { logGroupName: logGroup };
|
|
286
|
+
if (startTime !== undefined) baseInput.startTime = startTime;
|
|
287
|
+
if (explicitService) baseInput.logStreamNamePrefix = service;
|
|
288
|
+
|
|
289
|
+
// First poll starts at the live edge (see fetchLatestEvents):
|
|
290
|
+
// slicing an unscanned first page would show the OLDEST N.
|
|
291
|
+
const edge = await fetchLatestEvents(logsClient, baseInput, { tail, onlyErrors });
|
|
292
|
+
let nextToken = edge.nextToken;
|
|
293
|
+
let polls = 1;
|
|
294
|
+
for (const event of edge.events.filter(dedupe)) {
|
|
295
|
+
console.log(formatLogLine(event));
|
|
296
|
+
collected.push(String(event.message ?? ''));
|
|
297
|
+
}
|
|
298
|
+
if (follow && !stopped && polls < maxPolls) {
|
|
299
|
+
do {
|
|
300
|
+
await sleep(pollIntervalMs);
|
|
301
|
+
const input = { ...baseInput, limit: Math.min(Math.max(tail, 1), 10000) };
|
|
302
|
+
if (nextToken) input.nextToken = nextToken;
|
|
303
|
+
|
|
304
|
+
const resp = await logsClient.send(new FilterLogEventsCommand(input));
|
|
305
|
+
if (resp.nextToken) nextToken = resp.nextToken;
|
|
306
|
+
|
|
307
|
+
if (seen.size > 5000) seen.clear();
|
|
225
308
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
309
|
+
let fresh = (resp.events || []).filter(dedupe);
|
|
310
|
+
if (onlyErrors) fresh = fresh.filter((e) => isErrorLine(e.message));
|
|
311
|
+
|
|
312
|
+
for (const event of fresh) {
|
|
313
|
+
console.log(formatLogLine(event));
|
|
314
|
+
collected.push(String(event.message ?? ''));
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
polls += 1;
|
|
318
|
+
} while (!stopped && polls < maxPolls);
|
|
319
|
+
}
|
|
231
320
|
|
|
232
321
|
if (collected.length === 0) {
|
|
233
322
|
console.log(color.cyan(`\nℹ Waiting for logs...`));
|
package/src/commands/mcp.js
CHANGED
|
@@ -8,6 +8,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
8
8
|
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
9
9
|
import { z } from 'zod';
|
|
10
10
|
import { getCliVersion, trackSuccess, setActiveCommandName, resetActiveCommandName, rotateRunId } from '../core/telemetry.js';
|
|
11
|
+
import { atomicWriteFileSync } from '../utils/atomic-write.js';
|
|
11
12
|
import { safeHomedir } from '../core/homedir.js';
|
|
12
13
|
import { parseFlags, normalizeOptions, normalizeArgv } from '../utils/args.js';
|
|
13
14
|
import { failCommand, refuseUnknownFlags } from '../utils/command.js';
|
|
@@ -452,7 +453,7 @@ export function resolveMcpTransport(input = {}) {
|
|
|
452
453
|
// every OS layout from one machine.
|
|
453
454
|
export const MCP_INSTALL_EDITORS = ['windsurf', 'zed', 'cursor', 'vscode', 'claude-desktop', 'gemini-cli'];
|
|
454
455
|
|
|
455
|
-
export const MCP_SERVER_CONFIG = { command: 'npx', args: ['grada-run', 'mcp'] };
|
|
456
|
+
export const MCP_SERVER_CONFIG = { command: 'npx', args: ['--yes', 'grada-run', 'mcp'] };
|
|
456
457
|
|
|
457
458
|
export function mcpInstallTarget(editor, homeDir = safeHomedir(), platform = os.platform()) {
|
|
458
459
|
// No home, no target: null reads as "unresolvable" like an unknown
|
|
@@ -629,7 +630,7 @@ export function installMcpConfig(editor, { homeDir = safeHomedir(), platform = o
|
|
|
629
630
|
}
|
|
630
631
|
try {
|
|
631
632
|
fsSync.mkdirSync(path.dirname(target.path), { recursive: true });
|
|
632
|
-
|
|
633
|
+
atomicWriteFileSync(
|
|
633
634
|
target.path,
|
|
634
635
|
`${JSON.stringify({ ...existing, [target.key]: { ...servers, grada: { ...MCP_SERVER_CONFIG, args: [...MCP_SERVER_CONFIG.args] } } }, null, 4)}\n`,
|
|
635
636
|
'utf-8'
|