diff --git a/README.md b/README.md index cf2a104f..b904fa8e 100644 --- a/README.md +++ b/README.md @@ -393,8 +393,9 @@ Managed queues are a special kind of instance. Pass the instance ID directly or | `cloud tinker` | Tinker in your Laravel Cloud environment | | `cloud skills:install` | Install Laravel Cloud CLI agent skills | | `cloud completions` | Generate and install shell completions | +| `cloud feedback` | Tell the Cloud team what got in your way | -`cloud tinker` runs code against an environment, either interactively or via `--code=` for scripting (`--timeout=` caps how long to wait for output, default 60s). `cloud skills:install` installs the CLI's agent skills for supported coding agents; use `--global` or `--project` to choose the location and `--agent=` (repeatable) to pick specific agents. +`cloud tinker` runs code against an environment, either interactively or via `--code=` for scripting (`--timeout=` caps how long to wait for output, default 60s). `cloud skills:install` installs the CLI's agent skills for supported coding agents; use `--global` or `--project` to choose the location and `--agent=` (repeatable) to pick specific agents. `cloud feedback ""` sends the Cloud team a wrong result, a confusing error, a docs gap, or a missing endpoint; pass `--type=question` for a question the docs could not answer, and `--tool=` or `--environment=` to say what it is about. Each organization and each user can send 20 a day. ## Configuration diff --git a/app/Client/Requests/SubmitFeedbackRequestData.php b/app/Client/Requests/SubmitFeedbackRequestData.php new file mode 100644 index 00000000..09a3bf59 --- /dev/null +++ b/app/Client/Requests/SubmitFeedbackRequestData.php @@ -0,0 +1,25 @@ +filter([ + 'type' => $this->type, + 'message' => $this->message, + 'tool' => $this->tool, + 'environment_id' => $this->environmentId, + ]); + } +} diff --git a/app/Client/Resources/Meta/SubmitFeedbackRequest.php b/app/Client/Resources/Meta/SubmitFeedbackRequest.php new file mode 100644 index 00000000..bd2e3fe3 --- /dev/null +++ b/app/Client/Resources/Meta/SubmitFeedbackRequest.php @@ -0,0 +1,32 @@ +data->toRequestData(); + } +} diff --git a/app/Client/Resources/MetaResource.php b/app/Client/Resources/MetaResource.php index 9f91f0b9..173f8453 100644 --- a/app/Client/Resources/MetaResource.php +++ b/app/Client/Resources/MetaResource.php @@ -2,9 +2,11 @@ namespace App\Client\Resources; +use App\Client\Requests\SubmitFeedbackRequestData; use App\Client\Resources\Meta\GetOrganizationRequest; use App\Client\Resources\Meta\ListIpAddressesRequest; use App\Client\Resources\Meta\ListRegionsRequest; +use App\Client\Resources\Meta\SubmitFeedbackRequest; use App\Dto\Organization; class MetaResource extends Resource @@ -31,4 +33,11 @@ public function ipAddresses(): array return $response->json(); } + + public function submitFeedback(SubmitFeedbackRequestData $data): array + { + $response = $this->send(new SubmitFeedbackRequest($data)); + + return $response->json() ?: []; + } } diff --git a/app/Commands/Feedback.php b/app/Commands/Feedback.php new file mode 100644 index 00000000..b54a5b0a --- /dev/null +++ b/app/Commands/Feedback.php @@ -0,0 +1,103 @@ +ensureClient(); + + intro('Feedback'); + + $response = $this->loopUntilValid(fn () => $this->submit()); + + $this->outputJsonIfWanted(['sent' => true, ...$response]); + + success('Thanks! Your feedback was sent to the Laravel Cloud team.'); + } + + protected function submit(): array + { + $this->form()->prompt( + 'type', + fn ($resolver) => $resolver + ->fromInput(fn (?string $value) => select( + label: 'What kind of feedback is this?', + options: [ + 'feedback' => 'Something got in the way', + 'question' => 'A question the docs and CLI could not answer', + ], + default: $value ?? 'feedback', + info: fn ($value) => match ($value) { + 'feedback' => 'Wrong result, confusing error, docs gap, missing endpoint', + default => '', + }, + )) + ->nonInteractively(fn () => 'feedback'), + ); + + if (! in_array($this->form()->get('type'), ['feedback', 'question'], true)) { + $this->failAndExit('--type must be feedback or question.'); + } + + $this->form()->prompt( + 'message', + fn ($resolver) => $resolver->fromInput(fn (?string $value) => textarea( + label: $this->form()->get('type') === 'question' ? 'What is your question?' : 'What got in the way?', + default: $value ?? '', + required: true, + validate: fn (string $value) => mb_strlen($value) > 4000 ? 'Keep it under 4,000 characters.' : null, + )), + ); + + $this->form()->prompt( + 'tool', + fn ($resolver) => $resolver + ->fromInput(fn (?string $value) => text( + label: 'Which command is it about?', + placeholder: 'deploy:monitor', + default: $value ?? '', + hint: 'Optional. A CLI command, API endpoint, or MCP tool.', + )) + ->nonInteractively(fn () => ''), + ); + + try { + return spin( + fn () => $this->client->meta()->submitFeedback(new SubmitFeedbackRequestData( + type: $this->form()->get('type'), + message: $this->form()->get('message'), + tool: $this->form()->get('tool') ?: null, + environmentId: $this->option('environment') ?: null, + )), + 'Sending feedback...', + ); + } catch (TooManyRequestsException $e) { + $seconds = (int) $e->getResponse()->header('Retry-After'); + + $this->failAndExit( + 'Feedback is limited to 20 submissions a day for each organization and each user, and that limit has been reached.' + .($seconds > 0 ? ' Try again in '.CarbonInterval::seconds($seconds)->cascade()->forHumans(['parts' => 2]).'.' : ' Try again tomorrow.'), + ); + } + } +} diff --git a/skills/deploying-to-cloud/SKILL.md b/skills/deploying-to-cloud/SKILL.md index 07023154..e62d7b8f 100644 --- a/skills/deploying-to-cloud/SKILL.md +++ b/skills/deploying-to-cloud/SKILL.md @@ -135,6 +135,8 @@ For multi-step operations, see [reference/checklists.md](reference/checklists.md 4. Fix the issue and rerun the command. 5. If the same error occurs after one fix, stop and ask the user rather than repeating the operation. +When the CLI, API, or docs got in the way (a wrong result, a confusing error, a docs gap, a missing command or endpoint), tell the Cloud team with `cloud feedback "" --tool= -n`. For a question the docs could not answer, add `--type=question`. Tell the user what you are sending first, and leave out secrets, environment variable values, and customer data. Keep it to one short note per problem; each organization and each user can send 20 a day. + Always run `cloud deploy:monitor -n` after every deploy. If it fails, run `cloud deployment:logs {deploymentId} --json -n` to find the build or deploy step with `"status": "failed"` and read its `output`. Show the user what went wrong before attempting a fix. ### Subagent Delegation diff --git a/tests/Feature/FeedbackTest.php b/tests/Feature/FeedbackTest.php new file mode 100644 index 00000000..2a054089 --- /dev/null +++ b/tests/Feature/FeedbackTest.php @@ -0,0 +1,137 @@ +mockConfig = Mockery::mock(ConfigRepository::class); + $this->mockConfig->shouldReceive('apiTokens')->andReturn(collect(['test-api-token'])); + $this->app->instance(ConfigRepository::class, $this->mockConfig); +}); + +afterEach(function () { + MockClient::destroyGlobal(); +}); + +/** + * @return Closure(): stdClass the feedback request that was sent, if any + */ +function setupFeedbackMocks(?MockResponse $response = null): Closure +{ + $sent = new stdClass; + + MockClient::global([ + GetOrganizationRequest::class => MockResponse::make(organizationResponse(), 200), + SubmitFeedbackRequest::class => function (PendingRequest $request) use ($sent, $response) { + $sent->url = $request->getUrl(); + $sent->body = $request->body()?->all(); + + return $response ?? MockResponse::make([], 200); + }, + ]); + + return fn () => $sent; +} + +it('sends feedback with only a message, defaulting the type to feedback', function () { + $sent = setupFeedbackMocks(); + + $this->artisan('feedback', ['message' => 'The logs were empty.', '--no-interaction' => true]) + ->assertSuccessful(); + + expect($sent()->url)->toEndWith('/feedback'); + expect($sent()->body)->toBe(['type' => 'feedback', 'message' => 'The logs were empty.']); +}); + +it('sends a question about a tool and an environment', function () { + $sent = setupFeedbackMocks(); + + $this->artisan('feedback', [ + 'message' => 'How do I rotate a bucket key?', + '--type' => 'question', + '--tool' => 'bucket-key:update', + '--environment' => 'env-1', + '--no-interaction' => true, + ])->assertSuccessful(); + + expect($sent()->body)->toBe([ + 'type' => 'question', + 'message' => 'How do I rotate a bucket key?', + 'tool' => 'bucket-key:update', + 'environment_id' => 'env-1', + ]); +}); + +it('refuses an unknown type', function () { + $sent = setupFeedbackMocks(); + + $this->artisan('feedback', ['message' => 'Hi', '--type' => 'bug', '--no-interaction' => true]) + ->assertFailed(); + + expect($sent()->url ?? null)->toBeNull(); +}); + +it('requires a message when run non-interactively', function () { + $sent = setupFeedbackMocks(); + + $this->artisan('feedback', ['--no-interaction' => true])->assertFailed(); + + expect($sent()->url ?? null)->toBeNull(); +}); + +function runInteractiveFeedback(): PendingCommand +{ + Artisan::registerCommand(new InteractiveFeedbackCommand); + + // Accept the default type, then leave the optional command blank. + Prompt::fake([Key::ENTER, Key::ENTER]); + + return test()->artisan('test:interactive-feedback', ['message' => 'Hi']); +} + +it('explains the daily limit and when to try again', function () { + setupFeedbackMocks(MockResponse::make(['message' => 'Too Many Attempts.'], 429, ['Retry-After' => '7260'])); + + $suppressed = Renderer::$suppressOutput; + + try { + runInteractiveFeedback() + // The error box wraps the message and is one write, which only one expectation can claim. + ->expectsOutputToContain('Try again in 2 hours 1') + ->assertFailed(); + } finally { + Renderer::$suppressOutput = $suppressed; + } +}); + +it('says to try again tomorrow when the limit response has no Retry-After', function () { + setupFeedbackMocks(MockResponse::make(['message' => 'Too Many Attempts.'], 429)); + + $suppressed = Renderer::$suppressOutput; + + try { + runInteractiveFeedback() + ->expectsOutputToContain('Try again tomorrow.') + ->assertFailed(); + } finally { + Renderer::$suppressOutput = $suppressed; + } +}); + +it('outputs JSON', function () { + setupFeedbackMocks(); + + Artisan::call('feedback', ['message' => 'Hi', '--json' => true]); + + expect(json_decode(Artisan::output(), true))->toBe(['sent' => true]); +}); diff --git a/tests/Fixtures/InteractiveFeedbackCommand.php b/tests/Fixtures/InteractiveFeedbackCommand.php new file mode 100644 index 00000000..21d797cb --- /dev/null +++ b/tests/Fixtures/InteractiveFeedbackCommand.php @@ -0,0 +1,37 @@ +signature = preg_replace('/^feedback/', 'test:interactive-feedback', $this->signature); + $this->aliases = []; + + parent::__construct(); + } + + protected function isInteractive(): bool + { + return true; + } + + protected function configurePrompts(InputInterface $input): void + { + // The test runner can look like an agent or CI, which hides the human output under test. + Renderer::$suppressOutput = false; + + parent::configurePrompts($input); + + Prompt::interactive(true); + } +}