Skip to content

Commit 11a5257

Browse files
Neo auto-approve switch (#22950)
## Summary Adds the Neo TUI affordances for the cloud's approval / permission modes and fixes the stuck-prompt bug that fell out of the first slice. - `--approval-mode` (`manual` / `balanced` / `auto`) and `--permission-mode` (`default` / `read-only`) flags on `pulumi neo`, hot-toggleable mid-session via Ctrl+A and Ctrl+R; status-bar chips reflect any non-default value. Mid-session toggles PATCH the live task so the cloud `ApprovalHandler` picks up the change without restarting. - Wires the synthetic `user_confirmation` event the cloud emits on auto-resolve through `forwardUserInputToUI` → a new `UIApprovalResolved` event. The TUI now clears its pending question/approval prompt and commits an `Auto-approved` / `Auto-answered` / `Auto-denied` breadcrumb to scrollback. The manual path already clears state locally on Enter, so echoes of our own confirmation no-op. Fixes pulumi/pulumi-service#41318 Fixes pulumi/pulumi-service#41323 ## Test plan - [x] Added appropriate unit tests - For all changes - [ ] Added a test in `pkg/engine/lifecycletest` - For all engine/protocol changes - [ ] Added a conformance test in `pkg/testing/pulumi-test-language` - For language protocol changes - [ ] Added a golden test in `pkg/backend/display` - For changes to the output renderers New tests cover: `UpdateNeoTask` PATCH shape, parser validation for both new flags, Ctrl+A / Ctrl+R cycling pre- and post-message, `outboundEvent.update` routing in the dispatcher, the new `UIApprovalResolved` wire-routing path (including unknown-type drop and denied case), the `blockApprovalAuto` handler (auto-approved / question / denied / echo-noop / mismatched-id), and the renderer verb variants. ## Validation - [x] `make lint` — clean - [x] `make test_fast` — `pkg/cmd/pulumi/neo/...` and `pkg/backend/httpstate/client/...` clean (full sweep blocked locally by a Go toolchain cache mismatch unrelated to this PR; verified on focused packages after `go clean -cache`) - [ ] `make tidy_fix` — clean - [x] `make format` — clean - [ ] Relevant SDK tests pass (if SDK changes) - [ ] `make check_proto` — clean (if proto changes) ## Changelog - [x] Changelog entry added — `changelog/pending/20260507--cli-neo--surface-approval-and-permission-modes.yaml`. ## Risk CLI-only change, gated behind the experimental `pulumi neo` command. The mode plumbing reuses the existing `apitype.CreateAgentTaskRequest` / `apitype.UpdateTaskRequest` wire shapes — empty mode fields are `omitempty` so existing call sites are unaffected. The new `forwardUserInputToUI` discriminator drops unknown user-input subtypes silently, matching the previous "empty content" behaviour, so no other inbound paths regress. --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
1 parent 3dd972c commit 11a5257

11 files changed

Lines changed: 1427 additions & 82 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
changes:
2+
- type: feat
3+
scope: cli/neo
4+
description: Add `--approval-mode` and `--permission-mode` flags to `pulumi neo`, with Ctrl+A and Ctrl+R hotkeys to switch modes mid-session

‎pkg/backend/httpstate/client/client.go‎

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,15 @@ const (
5858
)
5959

6060
// NeoApprovalMode controls whether the agent requires user approval before executing tools.
61+
// Mirrors apitype.NeoApprovalMode in pulumi-service; the wire values must stay in sync.
6162
type NeoApprovalMode string
6263

6364
const (
6465
// NeoApprovalModeManual requires the agent to request user approval for each tool call.
6566
NeoApprovalModeManual NeoApprovalMode = "manual"
67+
// NeoApprovalModeBalanced auto-approves low-risk tool calls and prompts only on
68+
// destructive operations. The cloud ApprovalHandler decides which calls qualify.
69+
NeoApprovalModeBalanced NeoApprovalMode = "balanced"
6670
// NeoApprovalModeAuto allows the agent to execute tools without user approval.
6771
NeoApprovalModeAuto NeoApprovalMode = "auto"
6872
)
@@ -75,6 +79,19 @@ const (
7579
NeoTaskSourceCLI NeoTaskSource = "cli"
7680
)
7781

82+
// NeoPermissionMode caps the capabilities granted to an agent task. Mirrors
83+
// apitype.NeoPermissionMode in pulumi-service; the wire values must stay in sync.
84+
type NeoPermissionMode string
85+
86+
const (
87+
// NeoPermissionModeDefault grants the agent the full set of capabilities permitted
88+
// by the user's role. This is the server's default when the field is omitted.
89+
NeoPermissionModeDefault NeoPermissionMode = "default"
90+
// NeoPermissionModeReadOnly restricts the agent to read-only operations: no
91+
// `pulumi up`, no PR creation, no state mutations.
92+
NeoPermissionModeReadOnly NeoPermissionMode = "read-only"
93+
)
94+
7895
// NeoTaskRequest represents a request to create a Neo task. This is a thin client-side
7996
// shape that the server deserializes into apitype.CreateAgentTaskRequest, so the JSON
8097
// field names must match the IDL-generated tags exactly.
@@ -89,6 +106,9 @@ type NeoTaskRequest struct {
89106
// ApprovalMode controls whether the agent requires user approval before executing tools.
90107
// JSON tag is camelCase to match apitype.CreateAgentTaskRequest from pulumi-service.
91108
ApprovalMode NeoApprovalMode `json:"approvalMode,omitempty"`
109+
// PermissionMode caps the agent's capabilities (default vs read-only). Empty means
110+
// inherit the org / server default. JSON tag is camelCase to match the service IDL.
111+
PermissionMode NeoPermissionMode `json:"permissionMode,omitempty"`
92112
// PlanMode, when true, creates the task in plan mode: the agent explores and asks
93113
// questions but must not write files, run `pulumi up`, or open PRs. The server enforces
94114
// this by activating PlanModeTracker for the task and gating the exit on an approved
@@ -1712,17 +1732,16 @@ func (pc *Client) ExplainPreviewWithNeo(
17121732
}
17131733

17141734
// CreateNeoTaskOptions bundles the optional knobs on CreateNeoTask. The zero value
1715-
// corresponds to the defaults used by `--neo-task-on-failure`: cloud tool execution,
1716-
// server-default approval policy, and plan mode off.
1735+
// accepts the server-side defaults for every field.
17171736
type CreateNeoTaskOptions struct {
17181737
ToolExecutionMode string
17191738
ApprovalMode NeoApprovalMode
1739+
PermissionMode NeoPermissionMode
17201740
PlanMode bool
17211741
}
17221742

17231743
// CreateNeoTask creates a new Neo agent task via the Neo Tasks API. See
1724-
// CreateNeoTaskOptions for the available knobs; pass a zero-value struct to accept
1725-
// server defaults (the `--neo-task-on-failure` path).
1744+
// CreateNeoTaskOptions for the available knobs.
17261745
func (pc *Client) CreateNeoTask(
17271746
ctx context.Context,
17281747
orgName string,
@@ -1742,6 +1761,7 @@ func (pc *Client) CreateNeoTask(
17421761
},
17431762
ToolExecutionMode: opts.ToolExecutionMode,
17441763
ApprovalMode: opts.ApprovalMode,
1764+
PermissionMode: opts.PermissionMode,
17451765
PlanMode: opts.PlanMode,
17461766
Source: NeoTaskSourceCLI,
17471767
}
@@ -1764,6 +1784,31 @@ func (pc *Client) CreateNeoTask(
17641784
return &resp, nil
17651785
}
17661786

1787+
// UpdateNeoTaskOptions bundles the fields a CLI session can change on a live task.
1788+
// Pointer fields let callers update one axis without resetting the other — matches
1789+
// the apitype.UpdateTaskRequest shape on the cloud side.
1790+
type UpdateNeoTaskOptions struct {
1791+
ApprovalMode *NeoApprovalMode `json:"approvalMode,omitempty"`
1792+
PermissionMode *NeoPermissionMode `json:"permissionMode,omitempty"`
1793+
}
1794+
1795+
// UpdateNeoTask PATCHes an existing Neo task with new approval / permission mode
1796+
// values. Used by the TUI's mid-session toggles (Ctrl+A / Ctrl+R) so the cloud
1797+
// ApprovalHandler picks up the change immediately. Fields left nil in opts are
1798+
// not sent — the server preserves the existing value.
1799+
func (pc *Client) UpdateNeoTask(
1800+
ctx context.Context, orgName, taskID string, opts UpdateNeoTaskOptions,
1801+
) error {
1802+
ctx, cancel := context.WithTimeout(ctx, NeoRequestTimeout)
1803+
defer cancel()
1804+
1805+
path := fmt.Sprintf("/api/preview/agents/%s/tasks/%s", orgName, taskID)
1806+
if err := pc.restCall(ctx, http.MethodPatch, path, nil, opts, nil); err != nil {
1807+
return fmt.Errorf("updating Neo task: %w", err)
1808+
}
1809+
return nil
1810+
}
1811+
17671812
// NeoStreamEvent is one item from a Neo task Server-Sent Events (SSE) stream. Exactly
17681813
// one of Data or Err is populated: Data carries an event payload, Err carries a terminal
17691814
// stream error (after which no further values are sent before the channel closes).

‎pkg/backend/httpstate/client/client_test.go‎

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,124 @@ func TestCreateNeoTask(t *testing.T) {
10641064

10651065
assert.NotContains(t, gotBody, "planMode", "planMode must be omitted when false")
10661066
})
1067+
1068+
t.Run("PermissionModeReadOnlySerializes", func(t *testing.T) {
1069+
t.Parallel()
1070+
1071+
// permissionMode is per-task and the cloud caps OBO token scopes when it
1072+
// reads "read-only". The wire tag is camelCase to match apitype.
1073+
var gotBody map[string]any
1074+
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
1075+
require.NoError(t, json.NewDecoder(req.Body).Decode(&gotBody))
1076+
rw.WriteHeader(http.StatusCreated)
1077+
_, _ = rw.Write([]byte(`{"taskId":"t_5"}`))
1078+
}))
1079+
defer server.Close()
1080+
1081+
client := newMockClient(server)
1082+
_, err := client.CreateNeoTask(t.Context(), "my-org", "hi", "stack", "proj", CreateNeoTaskOptions{
1083+
ToolExecutionMode: "cli",
1084+
PermissionMode: NeoPermissionModeReadOnly,
1085+
})
1086+
require.NoError(t, err)
1087+
1088+
assert.Equal(t, "read-only", gotBody["permissionMode"])
1089+
})
1090+
1091+
t.Run("PermissionModeOmittedWhenEmpty", func(t *testing.T) {
1092+
t.Parallel()
1093+
1094+
// An empty PermissionMode must not appear in the body so the server
1095+
// falls back to the org default rather than seeing an invalid value.
1096+
var gotBody map[string]any
1097+
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
1098+
require.NoError(t, json.NewDecoder(req.Body).Decode(&gotBody))
1099+
rw.WriteHeader(http.StatusCreated)
1100+
_, _ = rw.Write([]byte(`{"taskId":"t_6"}`))
1101+
}))
1102+
defer server.Close()
1103+
1104+
client := newMockClient(server)
1105+
_, err := client.CreateNeoTask(t.Context(), "my-org", "hi", "", "proj", CreateNeoTaskOptions{})
1106+
require.NoError(t, err)
1107+
1108+
assert.NotContains(t, gotBody, "permissionMode")
1109+
})
1110+
}
1111+
1112+
func TestUpdateNeoTask(t *testing.T) {
1113+
t.Parallel()
1114+
1115+
// UpdateNeoTask is the CLI's mid-session toggle path: it PATCHes /tasks/{id}
1116+
// with whichever mode fields the user just toggled. The pointer fields on
1117+
// UpdateNeoTaskOptions ensure that a single-axis toggle doesn't reset the
1118+
// other axis on the server side.
1119+
1120+
t.Run("ApprovalModeUpdate", func(t *testing.T) {
1121+
t.Parallel()
1122+
1123+
var (
1124+
gotPath string
1125+
gotMethod string
1126+
gotBody map[string]any
1127+
)
1128+
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
1129+
gotPath = req.URL.Path
1130+
gotMethod = req.Method
1131+
require.NoError(t, json.NewDecoder(req.Body).Decode(&gotBody))
1132+
rw.WriteHeader(http.StatusOK)
1133+
}))
1134+
defer server.Close()
1135+
1136+
c := newMockClient(server)
1137+
mode := NeoApprovalModeBalanced
1138+
err := c.UpdateNeoTask(t.Context(), "my-org", "task_1", UpdateNeoTaskOptions{
1139+
ApprovalMode: &mode,
1140+
})
1141+
require.NoError(t, err)
1142+
1143+
assert.Equal(t, http.MethodPatch, gotMethod)
1144+
assert.Equal(t, "/api/preview/agents/my-org/tasks/task_1", gotPath)
1145+
assert.Equal(t, "balanced", gotBody["approvalMode"])
1146+
assert.NotContains(t, gotBody, "permissionMode",
1147+
"a single-axis toggle must not send the untouched axis")
1148+
})
1149+
1150+
t.Run("PermissionModeUpdate", func(t *testing.T) {
1151+
t.Parallel()
1152+
1153+
var gotBody map[string]any
1154+
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
1155+
require.NoError(t, json.NewDecoder(req.Body).Decode(&gotBody))
1156+
rw.WriteHeader(http.StatusOK)
1157+
}))
1158+
defer server.Close()
1159+
1160+
c := newMockClient(server)
1161+
perm := NeoPermissionModeReadOnly
1162+
err := c.UpdateNeoTask(t.Context(), "my-org", "task_2", UpdateNeoTaskOptions{
1163+
PermissionMode: &perm,
1164+
})
1165+
require.NoError(t, err)
1166+
1167+
assert.Equal(t, "read-only", gotBody["permissionMode"])
1168+
assert.NotContains(t, gotBody, "approvalMode")
1169+
})
1170+
1171+
t.Run("Error", func(t *testing.T) {
1172+
t.Parallel()
1173+
1174+
errorServer := newMockServer(http.StatusBadRequest, `{"message": "bad"}`)
1175+
defer errorServer.Close()
1176+
1177+
c := newMockClient(errorServer)
1178+
mode := NeoApprovalModeAuto
1179+
err := c.UpdateNeoTask(t.Context(), "my-org", "task_x", UpdateNeoTaskOptions{
1180+
ApprovalMode: &mode,
1181+
})
1182+
require.Error(t, err)
1183+
assert.Contains(t, err.Error(), "updating Neo task")
1184+
})
10671185
}
10681186

10691187
func TestPostNeoTaskUserEvent(t *testing.T) {

0 commit comments

Comments
 (0)