-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat(init): rewrite wizard client for Vercel Workflow + Sandbox server #850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
betegon
wants to merge
4
commits into
main
Choose a base branch
from
feat/init-vercel-workflow-client
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
c4d6eec
feat(init): rewrite wizard client for Vercel Workflow + Sandbox server
betegon 5c0bf2b
feat(init): defer feature picking to the agent's tailored multiselect
betegon 33a8892
chore: regenerate docs
github-actions[bot] 7499355
feat(init): preflight project context and harden stream reconnection
betegon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,39 @@ | ||
| export const MASTRA_API_URL = | ||
| process.env.MASTRA_API_URL ?? | ||
| "https://sentry-init-agent.getsentry.workers.dev"; | ||
| export const INIT_API_URL = | ||
| process.env.SENTRY_INIT_API_URL ?? | ||
| process.env.INIT_API_URL ?? | ||
| "https://sentry-init-agent.vercel.app"; | ||
|
|
||
| export const WORKFLOW_ID = "sentry-wizard"; | ||
| /** | ||
| * Initial-handshake timeout for `GET /api/init/:runId/stream` and | ||
| * `GET /api/init/:runId` (status). The stream body is a long-lived | ||
| * NDJSON pipe that idles for minutes between events; the runner | ||
| * handles that via the `handleStreamClosure` -> status check -> | ||
| * `resumeRun` loop, so this only protects the request *connect* phase. | ||
| */ | ||
| export const STREAM_CONNECT_TIMEOUT_MS = 30_000; | ||
|
|
||
| /** | ||
| * Maximum consecutive failures of `GET /api/init/:runId` (the status | ||
| * endpoint) before we give up. Stream drops themselves are normal and | ||
| * NOT counted: they flow into `handleStreamClosure` which fetches | ||
| * status, branches on running/completed/failed/cancelled, and | ||
| * reconnects when appropriate. Mirrors birthday-card-generator's | ||
| * `maxConsecutiveErrors: 5` on `WorkflowChatTransport`. | ||
| */ | ||
| export const MAX_STATUS_FAILURES = 5; | ||
|
|
||
| /** | ||
| * Cap exponential backoff between status-failure reconnect attempts so | ||
| * we don't sleep for minutes after a flake. | ||
| */ | ||
| export const MAX_RECONNECT_DELAY_MS = 30_000; | ||
|
|
||
| export const SENTRY_DOCS_URL = "https://docs.sentry.io/platforms/"; | ||
|
|
||
| export const MAX_FILE_BYTES = 262_144; // 256KB per file | ||
| export const MAX_OUTPUT_BYTES = 65_536; // 64KB stdout/stderr truncation | ||
| export const DEFAULT_COMMAND_TIMEOUT_MS = 120_000; // 2 minutes | ||
| export const API_TIMEOUT_MS = 120_000; // 2 minutes timeout for Mastra API calls | ||
|
|
||
| // Exit codes returned by the remote workflow | ||
| export const EXIT_PLATFORM_NOT_DETECTED = 20; | ||
| export const EXIT_DEPENDENCY_INSTALL_FAILED = 30; | ||
| export const EXIT_VERIFICATION_FAILED = 50; | ||
|
|
||
| // Step ID used in dry-run special-case logic | ||
| export const VERIFY_CHANGES_STEP = "verify-changes"; | ||
| export const API_TIMEOUT_MS = 120_000; // 2 minutes timeout for API calls | ||
|
|
||
| // The feature that is always included in every setup | ||
| export const REQUIRED_FEATURE = "errorMonitoring"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| /** | ||
| * Ensure a Sentry project + DSN exist before the workflow starts. | ||
| * | ||
| * Mirrors the legacy server-side `create-sentry-project` tool, but | ||
| * runs entirely in CLI preflight so the workflow input is complete | ||
| * by the time we POST `/api/init`. The agent never has to ask the | ||
| * user to pick an org/team/project mid-run. | ||
| */ | ||
|
|
||
| import { log } from "@clack/prompts"; | ||
| import { createProjectWithDsn } from "../api-client.js"; | ||
| import { ApiError, WizardError } from "../errors.js"; | ||
| import { resolveOrCreateTeam } from "../resolve-team.js"; | ||
| import { slugify } from "../utils.js"; | ||
| import { tryGetExistingProjectData } from "./existing-project.js"; | ||
| import type { ExistingProjectData, ResolvedInitContext } from "./types.js"; | ||
|
|
||
| /** Default platform slug used to create new projects from `sentry init`. */ | ||
| const DEFAULT_CREATE_PLATFORM = "javascript"; | ||
|
|
||
| export type EnsuredProject = { | ||
| orgSlug: string; | ||
| teamSlug?: string; | ||
| projectSlug: string; | ||
| projectId: string; | ||
| dsn: string; | ||
| url: string; | ||
| /** True if the project existed before this run. */ | ||
| preExisting: boolean; | ||
| }; | ||
|
|
||
| export async function ensureSentryProject( | ||
| ctx: ResolvedInitContext | ||
| ): Promise<EnsuredProject> { | ||
| const explicit = ctx.existingProject; | ||
| if (explicit) { | ||
| return projectFromExisting(explicit, ctx.team, true); | ||
| } | ||
|
|
||
| const projectName = ctx.project ?? deriveProjectName(ctx.directory); | ||
| const slug = slugify(projectName); | ||
| if (!slug) { | ||
| throw new WizardError( | ||
| `Cannot create project: "${projectName}" produces an empty slug.` | ||
| ); | ||
| } | ||
|
|
||
| // First check if it already exists under the resolved org. | ||
| try { | ||
| const existing = await tryGetExistingProjectData(ctx.org, slug); | ||
| if (existing) { | ||
| return projectFromExisting(existing, ctx.team, true); | ||
| } | ||
| } catch (err) { | ||
| if (!(err instanceof ApiError && err.status === 404)) { | ||
| throw err; | ||
| } | ||
| } | ||
|
|
||
| if (ctx.dryRun) { | ||
| return { | ||
| orgSlug: ctx.org, | ||
| teamSlug: ctx.team, | ||
| projectSlug: slug, | ||
| projectId: "(dry-run)", | ||
| dsn: "https://key@o0.ingest.sentry.io/0", | ||
| url: "https://sentry.io/dry-run", | ||
| preExisting: false, | ||
| }; | ||
| } | ||
|
|
||
| // Create the project. Resolve the team if it wasn't already. | ||
| const teamSlug = ctx.team | ||
| ? ctx.team | ||
| : ( | ||
| await resolveOrCreateTeam(ctx.org, { | ||
| autoCreateSlug: slug, | ||
| usageHint: "sentry init", | ||
| dryRun: ctx.dryRun, | ||
| }) | ||
| ).slug; | ||
|
|
||
| log.info(`Creating Sentry project '${slug}' in ${ctx.org}/${teamSlug}...`); | ||
|
|
||
| const { project, dsn, url } = await createProjectWithDsn(ctx.org, teamSlug, { | ||
| name: projectName, | ||
| platform: DEFAULT_CREATE_PLATFORM, | ||
| }); | ||
|
|
||
| if (!dsn) { | ||
| throw new WizardError( | ||
| `Project '${project.slug}' created in ${ctx.org} but no DSN was issued.` | ||
| ); | ||
| } | ||
|
|
||
| return { | ||
| orgSlug: ctx.org, | ||
| teamSlug, | ||
| projectSlug: project.slug, | ||
| projectId: project.id, | ||
| dsn, | ||
| url, | ||
| preExisting: false, | ||
| }; | ||
| } | ||
|
|
||
| function projectFromExisting( | ||
| existing: ExistingProjectData, | ||
| team: string | undefined, | ||
| preExisting: boolean | ||
| ): EnsuredProject { | ||
| if (!existing.dsn) { | ||
| throw new WizardError( | ||
| `Existing project '${existing.projectSlug}' has no DSN configured.` | ||
| ); | ||
| } | ||
| return { | ||
| orgSlug: existing.orgSlug, | ||
| teamSlug: team, | ||
| projectSlug: existing.projectSlug, | ||
| projectId: existing.projectId, | ||
| dsn: existing.dsn, | ||
| url: existing.url, | ||
| preExisting, | ||
| }; | ||
| } | ||
|
|
||
| function deriveProjectName(directory: string): string { | ||
| // Last non-empty path segment. `path.basename` works on Posix and Windows. | ||
| const parts = directory | ||
| .replaceAll("\\", "/") | ||
| .split("/") | ||
| .filter((p) => p.length > 0); | ||
| return parts.at(-1) ?? "sentry-project"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary formatter uses stale feature label map
Medium Severity
formatters.tsimportsfeatureLabelfromclack-utils.ts, which uses the oldFEATURE_INFOmap. That map lacks the new canonicaltracingID introduced byselect-features.ts. If the workflow summary includestracingin its features list, the final output renders the raw string "tracing" instead of "Performance Monitoring (Tracing)". The interactive prompt ininteractive.tsalready switched toFEATURE_LABELSfromselect-features.ts, creating an inconsistency between the picker and the summary.Reviewed by Cursor Bugbot for commit 33a8892. Configure here.