Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions app/docs/src/reference/si-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,93 @@ si change-set list
None


### change-set review

Review all component changes in a change set.

Displays a comprehensive view of all attribute changes, including what values changed and where they come from (subscriptions, static values, or prototypes). This command provides a clean, filtered view of changes without noise from internal fields or empty defaults.

> Syntax

```bash
si change-set review <change-set-id-or-name> [OPTIONS]
```

#### Parameters

| Name | Type | Required | Description | Default |
| --------------------- | ------ | -------- | ------------------------------------------------ | ------- |
| change-set-id-or-name | string | true | Change set ID or name | - |
| --include-resource-diff | flag | false | Include resource code diffs (CloudFormation/Terraform) | false |

#### Output

The command displays:
- Summary of total changes (added, modified, removed components)
- Each component with changes, showing:
- Component name and schema
- Diff status (Added, Modified, Removed)
- All changed attributes with their paths
- Values and their sources (subscriptions, static values, or prototypes)

**Change indicators:**
- `+` - Attribute added
- `~` - Attribute modified
- `-` - Attribute removed

**Source formats:**
- Static value: `"value"`
- Subscription: `$source: component-name -> /path`
- Prototype: `$source: FunctionName()`

#### Examples

```bash
# Review a change set by name
si change-set review my-change-set

# Review a change set by ID
si change-set review 01H9ZQD35JPMBGHH69BT0Q79AA

# Include CloudFormation/Terraform code diffs
si change-set review my-change-set --include-resource-diff
```

#### Sample Output

```
✨ info si Found 2 component(s) with changes: 2 added, 0 modified, 0 removed

✨ info si Component: my-vpc (AWS::EC2::VPC)
✨ info si Status: Added
✨ info si All attributes are new:
✨ info si + "/domain/cidrBlock"
✨ info si Value: "10.0.0.0/16"
✨ info si + "/domain/extra/Region"
✨ info si Value: "$source: region-1 -> /domain/region"
✨ info si + "/si/name"
✨ info si Value: "my-vpc"

✨ info si Component: existing-subnet (AWS::EC2::Subnet)
✨ info si Status: Modified
✨ info si ~ "/domain/availabilityZone"
✨ info si Old:
✨ info si Value: "us-east-1a"
✨ info si New:
✨ info si Value: "us-east-1b"

✨ info si Summary: 2 added, 0 modified, 0 removed
```

#### Behavior

- Returns a filtered view (excludes internal fields like `/si/type`, `/si/color` and empty defaults)
- Shows subscription sources with component names for clarity
- If review data is still being generated (MVs not ready), displays a message to retry in a few seconds
- Cannot be used on HEAD change set (HEAD has no diffs to review)

---

## ai-agent

Manages the SI AI Agent (MCP server).
Expand Down
2 changes: 1 addition & 1 deletion bin/si/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@std/path": "jsr:@std/path@^1.1.2",
"@std/ulid": "jsr:@std/ulid@^1.0.0",
"@std/yaml": "jsr:@std/yaml@^1.0.5",
"@systeminit/api-client": "jsr:@systeminit/api-client@^1.14.0",
"@systeminit/api-client": "jsr:@systeminit/api-client@^1.15.0",
"@types/node": "npm:@types/node@^24.10.1",
"axios": "npm:axios@^1.13.1",
"ejs": "npm:ejs@^3.1.10",
Expand Down
2 changes: 1 addition & 1 deletion bin/si/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

192 changes: 192 additions & 0 deletions bin/si/src/change-set/review.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
/**
* Change Set Review Module - Review all changes in a change set
*
* This module provides functionality to review all component changes in a
* change set, showing attribute diffs and subscription sources.
*
* @module
*/

import { ChangeSetsApi } from "@systeminit/api-client";
import { Context } from "../context.ts";
import { resolveChangeSet } from "./utils.ts";
import type { ChangeSetReviewOptions } from "./types.ts";

export type { ChangeSetReviewOptions };

/**
* Main entry point for the change-set review command
*/
export async function callChangeSetReview(
options: ChangeSetReviewOptions,
): Promise<void> {
const ctx = Context.instance();

try {
const apiConfig = Context.apiConfig();
const workspaceId = Context.workspaceId();

ctx.logger.info("Fetching change set review...");

// Resolve change set ID from name or ID
const changeSetId = await resolveChangeSet(
workspaceId,
options.changeSetIdOrName,
);

const changeSetsApi = new ChangeSetsApi(apiConfig);

const response = await changeSetsApi.reviewChangeSet({
workspaceId,
changeSetId,
includeResourceDiff: options.includeResourceDiff || false,
});

const reviewData = response.data;

// Handle building response (202) - check for status field
if ("status" in reviewData && reviewData.status === "building") {
const buildingData = reviewData as unknown as {
status: string;
message: string;
retryAfterSeconds: number;
estimatedCompletionSeconds: number;
};

ctx.logger.warn(
"Change set review data is still being generated. Please retry in a few seconds.",
);
ctx.logger.info(
`Retry in ${buildingData.retryAfterSeconds} seconds (estimated completion: ${buildingData.estimatedCompletionSeconds}s)`,
);
Deno.exit(0);
}

// Type guard for successful response
if (!("components" in reviewData)) {
ctx.logger.error("Unexpected response format from API");
Deno.exit(1);
}

const { components, summary } = reviewData;

// Display summary
if (components.length === 0) {
ctx.logger.info("No components have changes in this change set");
return;
}

ctx.logger.info(
`Found ${summary.totalComponents} component(s) with changes: ${summary.added} added, ${summary.modified} modified, ${summary.removed} removed`,
);
ctx.logger.info("");

// Display each component's changes
for (const component of components) {
ctx.logger.info(
`Component: ${component.componentName} (${component.schemaName})`,
);
ctx.logger.info(`Status: ${component.diffStatus}`);

const attributeDiffs = Object.entries(component.attributeDiffs || {});

if (component.diffStatus === "Added") {
ctx.logger.info("All attributes are new:");
}

for (const [path, diff] of attributeDiffs) {
if (diff.changeType === "added") {
ctx.logger.info(` + "${path}"`);
displayAttributeValue(" ", diff, "new");
} else if (diff.changeType === "modified") {
ctx.logger.info(` ~ "${path}"`);
ctx.logger.info(" Old:");
displayAttributeValue(" ", diff, "old");
ctx.logger.info(" New:");
displayAttributeValue(" ", diff, "new");
} else if (diff.changeType === "removed") {
ctx.logger.info(` - "${path}"`);
displayAttributeValue(" ", diff, "old");
}
}

ctx.logger.info("");
}

// Display summary again at the end
ctx.logger.info(
`Summary: ${summary.added} added, ${summary.modified} modified, ${summary.removed} removed`,
);
Comment on lines +117 to +119
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature seems very useful! I just feel like we should do a raw string output for the check instead of using the logger, since that' output and not execution logs, and should be printed even if logging is set to silent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire CLI output is behind the logger - if our plan is this then we need to rethink how we deal with the logger ingeneral - my thoughts here is that this isn't something we should take on at this time

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with Victor, but I also agree that there are many locations that we really shouldn't be using the logger to talk to the user.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... another PR would be the right move to gut it all atomically.


ctx.analytics.trackEvent("change set review", {
changeSetId,
componentsChanged: summary.totalComponents,
added: summary.added,
modified: summary.modified,
removed: summary.removed,
});
} catch (error: unknown) {
// Handle 400 error for HEAD change set
if (
error &&
typeof error === "object" &&
"response" in error &&
error.response &&
typeof error.response === "object" &&
"status" in error.response &&
error.response.status === 400
) {
ctx.logger.error(
"Cannot review HEAD change set - HEAD has no diffs to review",
);
Deno.exit(1);
}

ctx.logger.error(`Failed to review change set: ${error}`);
Deno.exit(1);
}
}

/**
* Display a single attribute value with proper formatting
*/
function displayAttributeValue(
indent: string,
// deno-lint-ignore no-explicit-any
diff: any,
type: "old" | "new",
): void {
const ctx = Context.instance();

const value = type === "new" ? diff.newValue : diff.oldValue;
const sourceType = type === "new" ? diff.newSourceType : diff.oldSourceType;

if (sourceType === "subscription") {
const componentName = type === "new"
? diff.newSourceComponentName
: diff.oldSourceComponentName;
const sourcePath = type === "new" ? diff.newSourcePath : diff.oldSourcePath;

if (componentName) {
ctx.logger.info(
`${indent}Value: "$source: ${componentName} -> ${sourcePath}"`,
);
} else {
ctx.logger.info(`${indent}Value: "$source: -> ${sourcePath}"`);
}
} else if (sourceType === "prototype") {
const prototype = type === "new"
? diff.newSourcePrototype
: diff.oldSourcePrototype;
ctx.logger.info(`${indent}Value: "$source: ${prototype}"`);
} else {
// Static value
if (typeof value === "string") {
ctx.logger.info(`${indent}Value: "${value}"`);
} else if (value === null || value === undefined) {
ctx.logger.info(`${indent}Value: ${value}`);
} else {
ctx.logger.info(`${indent}Value: ${JSON.stringify(value)}`);
}
}
}
5 changes: 5 additions & 0 deletions bin/si/src/change-set/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ export interface ChangeSetApplyOptions extends ChangeSetByIdOrNameOptions {
/** Don't wait for actions to complete, return immediately after applying */
detach?: boolean;
}

export interface ChangeSetReviewOptions extends ChangeSetByIdOrNameOptions {
/** Include resource code diffs (CloudFormation/Terraform) */
includeResourceDiff?: boolean;
}
20 changes: 20 additions & 0 deletions bin/si/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ import {
callChangeSetOpen,
type ChangeSetOpenOptions,
} from "./change-set/open.ts";
import {
callChangeSetReview,
type ChangeSetReviewOptions,
} from "./change-set/review.ts";
import { doLogin } from "./cli/login.ts";
import {
getCurrentUser,
Expand Down Expand Up @@ -1618,6 +1622,22 @@ function buildChangeSetCommand() {
.action(async (options) => {
await callChangeSetList(options as ChangeSetListOptions);
}),
)
.command(
"review",
createSubCommand(true)
.description("Review all changes in a change set")
.arguments("<change-set-id-or-name:string>")
.option(
"--include-resource-diff",
"Include resource code diffs (CloudFormation/Terraform)",
)
.action(async (options, changeSetIdOrName) => {
await callChangeSetReview({
...options,
changeSetIdOrName: changeSetIdOrName as string,
} as ChangeSetReviewOptions);
}),
);
}

Expand Down