Skip to content

Commit 67ae182

Browse files
committed
feat(managed-agent): require confirmation for removals
1 parent 676b6c2 commit 67ae182

5 files changed

Lines changed: 70 additions & 11 deletions

File tree

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,16 @@ const SESSION_DELETE_FLAGS = {
3030
export default defineCommand({
3131
description: { "en-US": "Delete a session", "zh-CN": "删除 Session" },
3232
auth: "apiKey",
33+
risk: {
34+
level: "high",
35+
message: {
36+
"en-US": "This deletes the specified remote managed Agent Session.",
37+
"zh-CN": "该操作会删除指定的远端托管 Agent Session。",
38+
},
39+
},
3340
usageArgs: "--session-id <id> [--provider <name>] [--file <path>]",
3441
flags: SESSION_DELETE_FLAGS,
35-
exampleArgs: ["--session-id sess_abc123"],
42+
exampleArgs: ["--session-id sess_abc123 --yes"],
3643
notes: CREDENTIALS_NOTE,
3744
async run(ctx) {
3845
const { settings, flags } = ctx;

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@ export default defineCommand({
3737
"zh-CN": "从 State 中移除资源,但不销毁远端资源",
3838
},
3939
auth: "none",
40+
risk: {
41+
level: "high",
42+
message: {
43+
"en-US":
44+
"This removes the resource from local state without deleting it remotely, so this project will no longer track it.",
45+
"zh-CN": "该操作会从本地 State 中移除资源但不会删除远端资源,此项目将不再跟踪该资源。",
46+
},
47+
},
4048
usageArgs: "--address <provider.type.name> [--file <path>]",
4149
flags: STATE_RM_FLAGS,
42-
exampleArgs: ["--address bailian.agent.assistant"],
50+
exampleArgs: ["--address bailian.agent.assistant --yes"],
4351
notes: OFFLINE_NOTE,
4452
async run(ctx) {
4553
const { settings, flags } = ctx;

packages/commands/tests/e2e/managed-agent.e2e.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,38 @@ describe("e2e: managed-agent", () => {
149149
});
150150
});
151151

152+
test.each([
153+
["state rm", ["state", "rm"]],
154+
["session delete", ["session", "delete"]],
155+
])("managed-agent %s --help 展示 runtime 注入的 --yes", async (_commandName, commandPath) => {
156+
const { stderr, exitCode } = await runCommandE2e(MANAGED_AGENT_ROUTES, [
157+
"managed-agent",
158+
...commandPath,
159+
"--help",
160+
]);
161+
expect(exitCode, stderr).toBe(0);
162+
expect(stderr).toMatch(/--yes/i);
163+
});
164+
165+
test.each([
166+
["state rm", ["state", "rm", "--address", "bailian.agent.assistant"]],
167+
[
168+
"session delete",
169+
["session", "delete", "--session-id", "sess_e2e", "--api-key", "e2e-dummy-key"],
170+
],
171+
])("managed-agent %s 无 --yes 返回确认请求 (7)", async (_commandName, commandArgs) => {
172+
const { stderr, exitCode } = await runCommandE2e(MANAGED_AGENT_ROUTES, [
173+
"managed-agent",
174+
...commandArgs,
175+
"--output",
176+
"json",
177+
]);
178+
expect(exitCode).toBe(7);
179+
expect(JSON.parse(stderr)).toMatchObject({
180+
error: { code: 7, type: "requires_confirmation" },
181+
});
182+
});
183+
152184
test("managed-agent session delete 缺少 --session-id 时退出为用法错误 (2)", async () => {
153185
const { stderr, exitCode } = await runCommandE2e(MANAGED_AGENT_ROUTES, [
154186
"managed-agent",

skills/bailian-managed-agent/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ description: >-
2626
2. Ask the user to confirm the exact action and scope shown in the plan.
2727
3. Only then run `apply` / `destroy` with `--yes`; a changed plan requires confirmation again.
2828

29-
`session delete` and future `risk: high` commands follow the shared protocol.
29+
`state rm`, `session delete`, and future `risk: high` commands follow the shared protocol.
3030

3131
## IaC lifecycle
3232

skills/bailian-managed-agent/reference/managed-agent.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ bl managed-agent session create --agent assistant --title 'debug run'
237237
| **Description** | Delete a session |
238238
| **Authentication** | API Key |
239239
| **Usage** | `bl managed-agent session delete --session-id <id> [--provider <name>] [--file <path>]` |
240+
| **Risk** | `high` |
241+
| **Risk message** | This deletes the specified remote managed Agent Session. |
242+
243+
> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope.
240244
241245
#### Flags
242246

@@ -245,6 +249,7 @@ bl managed-agent session create --agent assistant --title 'debug run'
245249
| `--session-id <id>` | string | yes | Session ID (required) |
246250
| `--file <path>` | string | no | Config file path (default: agents.yaml) |
247251
| `--provider <name>` | string | no | Target provider |
252+
| `--yes` | switch | no | Confirm this high-risk operation |
248253
| `--api-key <key>` | string | no | API key |
249254
| `--base-url <url>` | string | no | API base URL |
250255

@@ -257,7 +262,8 @@ bl managed-agent session create --agent assistant --title 'debug run'
257262
#### Examples
258263

259264
```bash
260-
bl managed-agent session delete --session-id sess_abc123
265+
# Only after explicit user confirmation:
266+
bl managed-agent session delete --session-id sess_abc123 --yes
261267
```
262268

263269
### `bl managed-agent session events`
@@ -552,19 +558,24 @@ bl managed-agent state list --file agents.yaml
552558

553559
### `bl managed-agent state rm`
554560

555-
| Field | Value |
556-
| ------------------ | -------------------------------------------------------------------------- |
557-
| **Name** | `managed-agent state rm` |
558-
| **Description** | Remove a resource from state without destroying it remotely |
559-
| **Authentication** | No Auth |
560-
| **Usage** | `bl managed-agent state rm --address <provider.type.name> [--file <path>]` |
561+
| Field | Value |
562+
| ------------------ | ----------------------------------------------------------------------------------------------------------------- |
563+
| **Name** | `managed-agent state rm` |
564+
| **Description** | Remove a resource from state without destroying it remotely |
565+
| **Authentication** | No Auth |
566+
| **Usage** | `bl managed-agent state rm --address <provider.type.name> [--file <path>]` |
567+
| **Risk** | `high` |
568+
| **Risk message** | This removes the resource from local state without deleting it remotely, so this project will no longer track it. |
569+
570+
> **Agent safety:** Never add `--yes` automatically. On `type="requires_confirmation"`, stop and ask for explicit user confirmation of the same action and scope.
561571
562572
#### Flags
563573

564574
| Flag | Type | Required | Description |
565575
| -------------------------------- | ------ | -------- | --------------------------------------- |
566576
| `--address <provider.type.name>` | string | yes | Resource state address (required) |
567577
| `--file <path>` | string | no | Config file path (default: agents.yaml) |
578+
| `--yes` | switch | no | Confirm this high-risk operation |
568579

569580
#### Notes
570581

@@ -573,7 +584,8 @@ bl managed-agent state list --file agents.yaml
573584
#### Examples
574585

575586
```bash
576-
bl managed-agent state rm --address bailian.agent.assistant
587+
# Only after explicit user confirmation:
588+
bl managed-agent state rm --address bailian.agent.assistant --yes
577589
```
578590

579591
### `bl managed-agent state show`

0 commit comments

Comments
 (0)