Skip to content

Commit 1bf4fec

Browse files
committed
feat(agent): support --dry-run for all local and remote mutations
1 parent 1d589c5 commit 1bf4fec

11 files changed

Lines changed: 364 additions & 4 deletions

File tree

packages/commands/src/commands/managed-agent/apply.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ export default defineCommand({
5555
const format = detectOutputFormat(settings.output);
5656
const file = flags.file ?? "agents.yaml";
5757

58+
if (settings.dryRun) {
59+
emitResult(
60+
{
61+
would_apply: {
62+
provider: flags.provider ?? "all",
63+
refresh: !flags.noRefresh,
64+
concurrency: flags.concurrency,
65+
},
66+
config_file: file,
67+
hint: "Run `managed-agent plan` to preview the exact resource changes.",
68+
},
69+
format,
70+
);
71+
return;
72+
}
73+
5874
const planned = await withAgentErrors(() =>
5975
withStdoutProtected(async () => {
6076
const runtime = await buildAgentRuntime(ctx, file);

packages/commands/src/commands/managed-agent/destroy.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ export default defineCommand({
4040
const format = detectOutputFormat(settings.output);
4141
const file = flags.file ?? "agents.yaml";
4242

43+
if (settings.dryRun) {
44+
emitResult(
45+
{
46+
would_destroy: { cascade: Boolean(flags.cascade) },
47+
config_file: file,
48+
hint: "Run `managed-agent state list` to see the resources tracked in state.",
49+
},
50+
format,
51+
);
52+
return;
53+
}
54+
4355
const planned = await withAgentErrors(() =>
4456
withStdoutProtected(async () => {
4557
const runtime = await buildAgentRuntime(ctx, file);

packages/commands/src/commands/managed-agent/init.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,29 @@ export default defineCommand({
118118
);
119119
}
120120

121+
const gitignorePath = ".gitignore";
122+
123+
if (settings.dryRun) {
124+
let wouldUpdateGitignore = true;
125+
if (existsSync(gitignorePath)) {
126+
const content = await readFile(gitignorePath, "utf8");
127+
wouldUpdateGitignore = !content.includes("agents.state.json");
128+
}
129+
emitResult(
130+
{
131+
would_create: file,
132+
provider,
133+
agent: agentName,
134+
would_update_gitignore: wouldUpdateGitignore,
135+
},
136+
format,
137+
);
138+
return;
139+
}
140+
121141
const template = buildTemplate({ provider, agentName });
122142
await writeFile(file, template, "utf8");
123143

124-
const gitignorePath = ".gitignore";
125144
if (existsSync(gitignorePath)) {
126145
const content = await readFile(gitignorePath, "utf8");
127146
if (!content.includes("agents.state.json")) {

packages/commands/src/commands/managed-agent/session-create.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,24 @@ export default defineCommand({
5252
const format = detectOutputFormat(settings.output);
5353
const file = flags.file ?? "agents.yaml";
5454

55+
if (settings.dryRun) {
56+
emitResult(
57+
{
58+
would_create_session: {
59+
agent: flags.agent ?? "auto",
60+
provider: flags.provider ?? "auto",
61+
environment: flags.environment,
62+
vault: flags.vault,
63+
memory_stores: parseMemoryStores(flags.memoryStores),
64+
title: flags.title,
65+
},
66+
config_file: file,
67+
},
68+
format,
69+
);
70+
return;
71+
}
72+
5573
const run = await withAgentErrors(() =>
5674
withStdoutProtected(async () => {
5775
const runtime = await buildAgentRuntime(ctx, file);

packages/commands/src/commands/managed-agent/session-delete.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ export default defineCommand({
3636
const format = detectOutputFormat(settings.output);
3737
const file = flags.file ?? "agents.yaml";
3838

39+
if (settings.dryRun) {
40+
emitResult(
41+
{
42+
would_delete_session: flags.sessionId,
43+
provider: flags.provider ?? "auto",
44+
config_file: file,
45+
},
46+
format,
47+
);
48+
return;
49+
}
50+
3951
await withAgentErrors(() =>
4052
withStdoutProtected(async () => {
4153
const runtime = await buildAgentRuntime(ctx, file);

packages/commands/src/commands/managed-agent/session-run.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineCommand, detectOutputFormat, type FlagsDef } from "bailian-cli-core";
2+
import { emitResult } from "bailian-cli-runtime";
23
import { startSessionRun, startSessionRunPolling } from "@openagentpack/sdk";
34
import { buildAgentRuntime, CREDENTIALS_NOTE } from "./_engine/config-loader.ts";
45
import { withStdoutProtected } from "./_engine/console-capture.ts";
@@ -75,6 +76,26 @@ export default defineCommand({
7576
title: flags.title,
7677
};
7778

79+
if (settings.dryRun) {
80+
emitResult(
81+
{
82+
would_run: {
83+
prompt: flags.prompt,
84+
agent: flags.agent ?? "auto",
85+
provider: flags.provider ?? "auto",
86+
environment: flags.environment,
87+
vault: flags.vault,
88+
memory_stores: runOptions.memoryStores,
89+
title: flags.title,
90+
mode: flags.noStream ? "polling" : "streaming",
91+
},
92+
config_file: file,
93+
},
94+
format,
95+
);
96+
return;
97+
}
98+
7899
await withAgentErrors(() =>
79100
withStdoutProtected(async () => {
80101
const runtime = await buildAgentRuntime(ctx, file);

packages/commands/src/commands/managed-agent/session-send.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineCommand, detectOutputFormat, type FlagsDef } from "bailian-cli-core";
2+
import { emitResult } from "bailian-cli-runtime";
23
import { sendSessionMessagePolling, sendSessionMessageStreaming } from "@openagentpack/sdk";
34
import { buildAgentRuntime, CREDENTIALS_NOTE } from "./_engine/config-loader.ts";
45
import { withStdoutProtected } from "./_engine/console-capture.ts";
@@ -47,6 +48,22 @@ export default defineCommand({
4748
const file = flags.file ?? "agents.yaml";
4849
const asJson = format === "json";
4950

51+
if (settings.dryRun) {
52+
emitResult(
53+
{
54+
would_send: {
55+
session_id: flags.sessionId,
56+
message: flags.message,
57+
provider: flags.provider ?? "auto",
58+
mode: flags.noStream ? "polling" : "streaming",
59+
},
60+
config_file: file,
61+
},
62+
format,
63+
);
64+
return;
65+
}
66+
5067
await withAgentErrors(() =>
5168
withStdoutProtected(async () => {
5269
const runtime = await buildAgentRuntime(ctx, file);

packages/commands/src/commands/managed-agent/state-import.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@ export default defineCommand({
4343
const format = detectOutputFormat(settings.output);
4444
const file = flags.file ?? "agents.yaml";
4545

46+
if (settings.dryRun) {
47+
// Validate the address shape locally so dry-run still catches usage errors.
48+
await withAgentErrors(async () => {
49+
parseStateAddress(flags.address, { requireProvider: true });
50+
});
51+
emitResult(
52+
{
53+
would_import: flags.address,
54+
remote_id: flags.remoteId,
55+
resource_version: flags.resourceVersion,
56+
config_file: file,
57+
},
58+
format,
59+
);
60+
return;
61+
}
62+
4663
await withAgentErrors(() =>
4764
withStdoutProtected(async () => {
4865
const runtime = await buildAgentRuntime(ctx, file);

packages/commands/src/commands/managed-agent/state-rm.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ export default defineCommand({
3737
const format = detectOutputFormat(settings.output);
3838
const file = flags.file ?? "agents.yaml";
3939

40+
if (settings.dryRun) {
41+
// Validate the address shape locally so dry-run still catches usage errors.
42+
await withAgentErrors(async () => {
43+
parseStateAddress(flags.address, { requireProvider: false });
44+
});
45+
emitResult({ would_remove: flags.address, config_file: file }, format);
46+
return;
47+
}
48+
4049
await withAgentErrors(() =>
4150
withStdoutProtected(async () => {
4251
const runtime = await buildAgentRuntime(ctx, file);

0 commit comments

Comments
 (0)