replicas-engine 0.1.942 → 0.1.944

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2583,6 +2583,7 @@ var WEB_APP_PATHS = {
2583
2583
  home: "/",
2584
2584
  onboarding: "/onboarding",
2585
2585
  workspaces: "/workspace",
2586
+ environmentSetup: "/workspace/setup",
2586
2587
  automations: "/automations",
2587
2588
  environment: "/environment",
2588
2589
  analytics: "/analytics",
@@ -2942,8 +2943,451 @@ var DOCKER_ABILITY = {
2942
2943
  referenceFile: { name: "DOCKER.md", content: REFERENCE2 }
2943
2944
  };
2944
2945
 
2946
+ // ../shared/src/routes/environment-setups.ts
2947
+ import { z as z9 } from "zod";
2948
+
2949
+ // ../shared/src/uuid.ts
2950
+ function createUuidFromHex(value) {
2951
+ return `${value.slice(0, 8)}-${value.slice(8, 12)}-5${value.slice(13, 16)}-${(Number.parseInt(value.slice(16, 17), 16) & 3 | 8).toString(16)}${value.slice(17, 20)}-${value.slice(20, 32)}`;
2952
+ }
2953
+ var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
2954
+
2955
+ // ../shared/src/routes/environment-setups.ts
2956
+ var ENVIRONMENT_SETUP_STEPS = [
2957
+ { key: "understand", label: "Understand the codebase" },
2958
+ { key: "install", label: "Install dependencies and run the app" },
2959
+ { key: "verify", label: "Verify checks and record a walkthrough" },
2960
+ { key: "configure", label: "Draft hooks, system prompt, and automations" },
2961
+ { key: "propose", label: "Propose the configuration for review" }
2962
+ ];
2963
+ var ENVIRONMENT_SETUP_STEP_STATUSES = ["pending", "in_progress", "completed", "skipped"];
2964
+ var ENVIRONMENT_SETUP_RUN_STATUSES = ["running", "proposed", "applied", "failed", "cancelled"];
2965
+ var ENVIRONMENT_SETUP_AUTOMATION_ACTIONS = ["create", "update", "keep", "disable"];
2966
+ var ENVIRONMENT_SETUP_VERIFICATION_STATUSES = ["passed", "failed", "skipped"];
2967
+ var ENVIRONMENT_SETUP_LIMITS = {
2968
+ summaryChars: 600,
2969
+ stackItems: 30,
2970
+ nameChars: 120,
2971
+ descriptionChars: 1e3,
2972
+ systemPromptChars: 2e4,
2973
+ hookChars: 5e4,
2974
+ variables: 50,
2975
+ variableKeyChars: 128,
2976
+ variableDescriptionChars: 500,
2977
+ automations: 8,
2978
+ automationKeyChars: 80,
2979
+ automationPromptChars: 1e4,
2980
+ automationTriggers: 5,
2981
+ automationNoteChars: 300,
2982
+ verificationItems: 8,
2983
+ verificationDetailChars: 300,
2984
+ mediaItems: 8,
2985
+ repositories: 20
2986
+ };
2987
+ var ENVIRONMENT_SETUP_VARIABLE_WAIT = { defaultMs: 5 * 6e4, maxMs: 15 * 6e4, pollMs: 5e3 };
2988
+ var VARIABLE_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
2989
+ var text = (max) => max === void 0 ? z9.string().trim() : z9.string().trim().max(max);
2990
+ var requiredText = (max) => text(max).min(1, "must not be empty");
2991
+ var optionalText = (max) => text(max).nullish().transform((value) => value || null);
2992
+ var clearableText = (max) => text(max).nullish().transform((value) => value === void 0 ? void 0 : value || null);
2993
+ var list = (item, max) => max === void 0 ? z9.array(item) : z9.array(item).max(max);
2994
+ var ENVIRONMENT_SETUP_AUTHORED_TRIGGER_TYPES = ["cron", "github", "gitlab"];
2995
+ function isEnvironmentSetupAuthoredTriggerType(type) {
2996
+ return ENVIRONMENT_SETUP_AUTHORED_TRIGGER_TYPES.some((authored) => authored === type);
2997
+ }
2998
+ var repositoryTriggerConfigSchema = z9.object({
2999
+ event: z9.string(),
3000
+ repository_ids: z9.array(z9.string().regex(UUID_RE, "must be a repository id")).optional(),
3001
+ group_pr_events: z9.boolean().optional(),
3002
+ excluded_actors: z9.array(z9.string()).optional()
3003
+ });
3004
+ var proposalTriggerSchema = z9.discriminatedUnion("type", [
3005
+ z9.object({ type: z9.literal("cron"), config: z9.object({ schedule: z9.string(), timezone: z9.string().optional() }) }),
3006
+ z9.object({ type: z9.literal("github"), config: repositoryTriggerConfigSchema }),
3007
+ z9.object({ type: z9.literal("gitlab"), config: repositoryTriggerConfigSchema })
3008
+ ]);
3009
+ var existingTriggerSchema = z9.custom(
3010
+ (value) => isRecord(value) && typeof value.type === "string" && isRecord(value.config),
3011
+ "must be an automation trigger"
3012
+ );
3013
+ var carriedTriggerSchema = existingTriggerSchema.refine(
3014
+ (trigger) => !isEnvironmentSetupAuthoredTriggerType(trigger.type)
3015
+ );
3016
+ function automationSchema(limits) {
3017
+ const authored = z9.object({
3018
+ name: text(limits.nameChars),
3019
+ description: text(limits.descriptionChars),
3020
+ prompt: text(limits.automationPromptChars),
3021
+ triggers: list(proposalTriggerSchema, limits.automationTriggers)
3022
+ });
3023
+ const updated = authored.extend({ triggers: list(z9.union([proposalTriggerSchema, carriedTriggerSchema]), limits.automationTriggers) });
3024
+ return z9.object({
3025
+ key: requiredText(limits.automationKeyChars),
3026
+ action: z9.enum(ENVIRONMENT_SETUP_AUTOMATION_ACTIONS).default("create"),
3027
+ automation_id: z9.string().regex(UUID_RE, "must be an automation id").nullable().default(null),
3028
+ name: text().default(""),
3029
+ description: optionalText().transform((value) => value ?? ""),
3030
+ prompt: text().default(""),
3031
+ triggers: list(existingTriggerSchema).default([]),
3032
+ note: optionalText(limits.automationNoteChars)
3033
+ }).superRefine((automation, ctx) => {
3034
+ if (automation.action === "create" && automation.automation_id) {
3035
+ ctx.addIssue({ code: "custom", path: ["automation_id"], message: "belongs on an update, keep, or disable entry" });
3036
+ }
3037
+ if (automation.action !== "create" && !automation.automation_id) {
3038
+ ctx.addIssue({ code: "custom", path: ["automation_id"], message: "must be the id of an automation attached to this environment" });
3039
+ }
3040
+ if (automation.action === "create" || automation.action === "update") {
3041
+ if (!automation.name) ctx.addIssue({ code: "custom", path: ["name"], message: "must not be empty" });
3042
+ if (!automation.prompt) ctx.addIssue({ code: "custom", path: ["prompt"], message: "must not be empty" });
3043
+ if (automation.triggers.length === 0) ctx.addIssue({ code: "custom", path: ["triggers"], message: "must not be empty" });
3044
+ }
3045
+ }).transform((automation, ctx) => {
3046
+ if (automation.action === "keep" || automation.action === "disable") return automation;
3047
+ const content = (automation.action === "update" ? updated : authored).safeParse(automation);
3048
+ if (content.success) return { ...automation, ...content.data };
3049
+ for (const issue of content.error.issues) ctx.addIssue({ ...issue, code: "custom" });
3050
+ return z9.NEVER;
3051
+ });
3052
+ }
3053
+ function automationListSchema(limits) {
3054
+ return list(automationSchema(limits)).default([]).superRefine((automations, ctx) => {
3055
+ if (new Set(automations.map((automation) => automation.key)).size !== automations.length) {
3056
+ ctx.addIssue({ code: "custom", message: "must have unique keys" });
3057
+ }
3058
+ const targets = automations.flatMap((automation) => automation.automation_id ?? []);
3059
+ if (new Set(targets).size !== targets.length) {
3060
+ ctx.addIssue({ code: "custom", message: "must mention each existing automation once" });
3061
+ }
3062
+ if (limits.automations !== void 0 && automations.filter((automation) => automation.action === "create").length > limits.automations) {
3063
+ ctx.addIssue({ code: "custom", message: `must create at most ${limits.automations} new automations` });
3064
+ }
3065
+ });
3066
+ }
3067
+ function environmentSchema(limits) {
3068
+ return z9.object({
3069
+ name: optionalText(limits.nameChars).transform((value) => value ?? void 0),
3070
+ description: clearableText(limits.descriptionChars),
3071
+ system_prompt: clearableText(limits.systemPromptChars),
3072
+ start_hook: clearableText(limits.hookChars),
3073
+ warm_hook: clearableText(limits.hookChars)
3074
+ });
3075
+ }
3076
+ function variableSchema(limits, requiredDefault) {
3077
+ return z9.object({
3078
+ key: z9.string().regex(VARIABLE_KEY_RE, "must be a valid environment variable name").max(limits.variableKeyChars ?? Number.POSITIVE_INFINITY),
3079
+ description: optionalText(limits.variableDescriptionChars).transform((value) => value ?? ""),
3080
+ required: z9.boolean().default(requiredDefault)
3081
+ });
3082
+ }
3083
+ function proposalSchema(limits) {
3084
+ return z9.object({
3085
+ summary: requiredText(limits.summaryChars),
3086
+ stack: list(text(), limits.stackItems).default([]).transform((items) => items.filter(Boolean)),
3087
+ environment: environmentSchema(limits),
3088
+ variables: list(variableSchema(limits, false), limits.variables).default([]),
3089
+ automations: automationListSchema(limits),
3090
+ verification: list(z9.object({
3091
+ label: requiredText(limits.nameChars),
3092
+ status: z9.enum(ENVIRONMENT_SETUP_VERIFICATION_STATUSES),
3093
+ detail: optionalText(limits.verificationDetailChars).transform((value) => value ?? void 0)
3094
+ }), limits.verificationItems).default([]),
3095
+ media: list(z9.object({
3096
+ media_id: z9.string().regex(UUID_RE, "must be a media id"),
3097
+ title: requiredText(limits.nameChars)
3098
+ }), limits.mediaItems).default([])
3099
+ });
3100
+ }
3101
+ var environmentSetupProposalSchema = proposalSchema({});
3102
+ var environmentSetupProposalSubmissionSchema = proposalSchema(ENVIRONMENT_SETUP_LIMITS);
3103
+ var environmentSetupVariableRequestSchema = variableSchema({}, false).extend({
3104
+ status: z9.enum(["pending", "provided", "skipped"]),
3105
+ requested_at: z9.string(),
3106
+ resolved_at: z9.string().nullable().default(null)
3107
+ });
3108
+ var environmentSetupRunStateSchema = z9.object({
3109
+ status: z9.enum(ENVIRONMENT_SETUP_RUN_STATUSES),
3110
+ steps: z9.partialRecord(z9.enum(ENVIRONMENT_SETUP_STEPS.map((step) => step.key)), z9.enum(ENVIRONMENT_SETUP_STEP_STATUSES)).default({}),
3111
+ proposal: environmentSetupProposalSchema.nullable().default(null),
3112
+ applied: z9.object({
3113
+ applied_at: z9.string(),
3114
+ automation_ids: z9.array(z9.string())
3115
+ }).nullable().default(null),
3116
+ variable_requests: z9.array(environmentSetupVariableRequestSchema).default([])
3117
+ });
3118
+ var applyEnvironmentSetupRequestSchema = z9.object({
3119
+ environment: environmentSchema(ENVIRONMENT_SETUP_LIMITS).extend({ name: requiredText(ENVIRONMENT_SETUP_LIMITS.nameChars) }),
3120
+ variables: list(z9.object({ key: z9.string().regex(VARIABLE_KEY_RE), value: z9.string() }), ENVIRONMENT_SETUP_LIMITS.variables).default([]).refine((variables) => new Set(variables.map((variable) => variable.key)).size === variables.length, "must have unique keys").transform((variables) => variables.filter((variable) => variable.value.length > 0)),
3121
+ automations: automationListSchema(ENVIRONMENT_SETUP_LIMITS)
3122
+ });
3123
+ var requestEnvironmentSetupVariablesSchema = z9.object({
3124
+ variables: list(variableSchema(ENVIRONMENT_SETUP_LIMITS, true), ENVIRONMENT_SETUP_LIMITS.variables).min(1, "must not be empty")
3125
+ }).superRefine(({ variables }, ctx) => {
3126
+ if (new Set(variables.map((variable) => variable.key)).size !== variables.length) {
3127
+ ctx.addIssue({ code: "custom", path: ["variables"], message: "must have unique keys" });
3128
+ }
3129
+ });
3130
+ var respondEnvironmentSetupVariablesSchema = z9.object({
3131
+ values: z9.record(z9.string().regex(VARIABLE_KEY_RE), z9.string()).default({}),
3132
+ skipped: z9.array(z9.string().regex(VARIABLE_KEY_RE)).default([])
3133
+ });
3134
+
3135
+ // ../shared/src/default-skills/replicas-agent/abilities/environment-setup.ts
3136
+ var SECTION3 = `### Environment setup (agent-led)
3137
+ Explore a codebase, get it running in this workspace, verify it end to end, and propose the Replicas environment configuration (start hook, warm hook, system prompt, variables) plus a few automations for the user to review and save.
3138
+
3139
+ **Reference:** \`references/ENVIRONMENT-SETUP.md\`
3140
+
3141
+ Use this when:
3142
+ - This workspace was started as an environment setup run (\`replicas environment-setup status\` succeeds)
3143
+ - The user asks you to set up, configure, audit, or improve a Replicas environment for a repository
3144
+ - The user asks what should go in a start hook, warm hook, or environment system prompt`;
3145
+ var REFERENCE3 = `# Environment setup (agent-led)
3146
+
3147
+ Use this workflow to make a repository fully usable by Replicas background agents: agents booted from the environment should be able to install, run, test, verify, and demo changes without a human babysitting them. The result of the workflow is a **proposal**, never a direct change: the user reviews, edits, and saves it in the Environment panel next to the chat.
3148
+
3149
+ ## Mental model
3150
+
3151
+ Every Replicas workspace is a remote Linux VM. Repositories are cloned under \`~/workspaces/<repo-name>\`. An **environment** is the org-scoped template a workspace is built from. It binds one repository (or a repository set for monorepos and multi-repo stacks) and carries:
3152
+
3153
+ | Piece | When it runs | Put here |
3154
+ | --- | --- | --- |
3155
+ | **Warm hook** | Once, while Replicas builds the warm-pool snapshot for the environment. Its *filesystem* state is baked into every new workspace; its *processes* are not. Default timeout 60 minutes. | Slow, deterministic setup: dependency installs from the lockfile, toolchain downloads, \`docker pull\`, one-time builds, code generation. |
3156
+ | **Start hook** | On every workspace boot, before the agent starts working. Default timeout 5 minutes. | Fast per-boot reconciliation: start daemons and databases, run migrations against local services, launch dev servers with \`replicas service start\`, health checks. Must be idempotent. |
3157
+ | **System prompt** | Injected into the agent's instructions for every workspace in the environment. | Only what an agent cannot learn from the repository itself: team conventions, review expectations, how to verify, gotchas you hit while setting up. |
3158
+ | **Variables** | Exported into every workspace (and available inside hooks). Values are encrypted. | API keys, tokens, feature flags, local service URLs. |
3159
+ | **Files** | Materialized on the workspace filesystem at boot. | \`.env\` files, dotfiles, config that must not be committed. |
3160
+ | **Automations** | Saved prompts fired by triggers (cron, pull request events, Slack, Sentry, webhooks). Each run creates a workspace in an environment. | Recurring engineering work that fits this repository. |
3161
+
3162
+ Hooks run with \`bash -lc\` from \`~/workspaces\` (the parent of every repository checkout), so start scripts with \`cd ~/workspaces/<repo-name>\`. A repository may also ship its own \`replicas.json\` / \`replicas.yaml\` with \`startHook\`, \`warmHook\`, and \`systemPrompt\`; repository hooks run after the environment hooks. Prefer proposing environment hooks unless the repository already manages its own.
3163
+
3164
+ The Global environment applies to every workspace in the organization; never propose putting repository-specific setup there.
3165
+
3166
+ ## Progress and the setup run
3167
+
3168
+ When this workspace was started as a setup run, the dashboard shows a live checklist next to the chat. Keep it honest with:
3169
+
3170
+ \`\`\`bash
3171
+ replicas environment-setup status
3172
+ replicas environment-setup step <key> <status>
3173
+ replicas environment-setup request-variables -f <path>
3174
+ replicas environment-setup wait-variables [-t 5m]
3175
+ \`\`\`
3176
+
3177
+ \`status\` prints the environment, repositories, current steps, and variable requests. \`request-variables\` returns immediately; \`wait-variables\` blocks until the required values arrive, are skipped, or the time runs out. Step statuses are \`pending\`, \`in_progress\`, \`completed\`, and \`skipped\`. Step keys, in order: \`understand\`, \`install\`, \`verify\`, \`configure\`, \`propose\`. Mark the first step \`in_progress\` before your first tool call, keep exactly one step \`in_progress\`, and mark a step \`completed\` only after its work actually succeeded. Use \`skipped\` when something genuinely cannot run (for example no browser UI to record) and say so in the proposal.
3178
+
3179
+ If \`replicas environment-setup status\` reports that there is no active setup run, the user asked for this in an ordinary workspace. Follow the same discovery and verification steps, then present the configuration in chat; apply it with \`replicas environment ...\` and \`replicas automation ...\` only when the user explicitly asks you to.
3180
+
3181
+ ## 1. Understand the codebase
3182
+
3183
+ Investigate in parallel before changing anything:
3184
+
3185
+ 1. Identify the products and services in the repository. Separate what is required for an end-to-end development flow from what is optional.
3186
+ 2. Read setup entry points: \`README\`, \`CONTRIBUTING\`, \`AGENTS.md\`, \`CLAUDE.md\`, package-manager files, tool-version files (\`.nvmrc\`, \`.tool-versions\`, \`.python-version\`), Makefiles, setup scripts, devcontainer and Docker Compose files, CI workflows.
3187
+ 3. Find the canonical install, dev-server, lint, type-check, test, and build commands. CI workflows and pre-commit hooks encode the checks that matter.
3188
+ 4. Learn the team's conventions from history: \`git log --oneline -50\`, and \`gh pr list --state merged --limit 20\` plus \`gh pr view <n>\` on a few merged pull requests (or the GitLab equivalents). Note branch naming, commit style, review expectations, and recurring chores that could become automations.
3189
+ 5. Identify required secrets, test accounts, databases, queues, browser dependencies, and external services. Check \`.env.example\`, config loaders, and CI secrets for variable names. Never read or print secret values. As soon as you know the names, ask for them (see "Asking for variables") and keep going.
3190
+ 6. Inspect any existing \`replicas.json\` and the current environment (\`replicas environment get <name>\`, \`replicas environment start-hooks get <name>\`, \`replicas environment warm-hooks get <name>\`) so the proposal builds on what exists instead of competing with it. List the organization's automations with \`replicas automation list --owner org\` and read each one attached to this environment with \`replicas automation get <id>\` (the environment id is in \`replicas environment-setup status\`); every one of them needs a decision in the proposal.
3191
+
3192
+ Use subagents for broad, independent analysis when available, but read the files and run the commands yourself before adopting their conclusions.
3193
+
3194
+ ## Asking for variables
3195
+
3196
+ The user may be watching the panel or may have walked away, so ask early and wait late:
3197
+
3198
+ 1. Right after step 1, request every secret you found in one batch. \`required\` means the app cannot run locally without it; leave it \`false\` for anything you can work around.
3199
+
3200
+ \`\`\`bash
3201
+ replicas environment-setup request-variables --file /tmp/variables.json
3202
+ \`\`\`
3203
+
3204
+ \`\`\`json
3205
+ {
3206
+ "variables": [
3207
+ { "key": "DATABASE_URL", "description": "Postgres connection string; a local docker compose database works", "required": false },
3208
+ { "key": "STRIPE_SECRET_KEY", "description": "Stripe test-mode key; checkout cannot run without it", "required": true }
3209
+ ]
3210
+ }
3211
+ \`\`\`
3212
+
3213
+ 2. Keep working on everything that does not need the values. The request appears in the Environment panel next to the chat; the user types values there (stored encrypted on the environment, never in chat) or skips them.
3214
+ 3. At the point you actually need a value, block on it:
3215
+
3216
+ \`\`\`bash
3217
+ replicas environment-setup wait-variables --timeout 5m
3218
+ replicas environment-setup wait-variables --keys STRIPE_SECRET_KEY
3219
+ \`\`\`
3220
+
3221
+ Without \`--keys\` it waits for every pending required key. It returns when the keys are provided or skipped, or when the time runs out, and prints which happened. Provided keys are exported for every new shell; restart anything you started with \`replicas service start\` before that point so it picks them up. Never print the values.
3222
+ 4. For anything skipped or unanswered, use the safest local substitute (local database, mock, documented test value), say so in the verification rows, and list the key as required in the proposal. A key the user skipped is not asked again; do not resend it.
3223
+ 5. Values the user provided are already saved on the environment. Still list those keys in the proposal so the review shows them as set.
3224
+ 6. Requests are only accepted before you propose. Anything still missing after that goes into the proposal as a required variable, which the user fills in at review.
3225
+
3226
+ ## 2. Install and run
3227
+
3228
+ Work from the smallest failing layer, in this workspace:
3229
+
3230
+ 1. Install system dependencies and toolchains the repository pins.
3231
+ 2. Run the install command to completion, then run it a second time to prove idempotence.
3232
+ 3. Start infrastructure and long-running processes with \`replicas service start <name> "<command>"\` so they survive turn boundaries (see \`REPLICAS.md\`). Start the Docker daemon first if Compose is involved (see \`DOCKER.md\`).
3233
+ 4. Run the canonical lint, type-check, test, and build commands for the agreed scope. Record what passed, what failed, and why.
3234
+
3235
+ Use the repository's pinned package manager and lockfile. Do not upgrade dependencies, rewrite lockfiles, or change application code to make setup pass; environment configuration and narrowly necessary fixes to setup scripts are in scope. Do not deploy, publish, or touch production resources.
3236
+
3237
+ When something needs a secret you do not have, request it and run \`wait-variables\` at the point you need it (see "Asking for variables"). If it is skipped or unanswered, use the safest local substitute, keep going, and record the variable as required in the proposal with a clear description. Never invent or paste secret values anywhere.
3238
+
3239
+ ## 3. Verify and record
3240
+
3241
+ Loading a page is not verification. Perform a representative real action through the product: create a record, submit a form, run a CLI command against the running service, call an endpoint and check the response.
3242
+
3243
+ For anything with a UI, record it:
3244
+
3245
+ \`\`\`bash
3246
+ replicas computer record start /tmp/walkthrough.mp4
3247
+ replicas computer launch chrome http://localhost:<port>
3248
+ replicas computer browser-state /tmp/state.png --full
3249
+ replicas computer browser-click "<button that starts the core flow>"
3250
+ replicas computer record stop
3251
+ replicas media upload /tmp/walkthrough.mp4 --name "<Project> walkthrough"
3252
+ \`\`\`
3253
+
3254
+ Keep the recording short (one to three minutes) and focused on the flow that proves the environment works. \`replicas media upload\` prints a chat embed line and a \`View in Replicas\` link ending in \`?media=<media-id>\`; keep both. The media id goes into the proposal, and the embed line goes into your final message. Follow \`MEDIA.md\` for anything shared outside the dashboard.
3255
+
3256
+ Add screenshots of important states (a passing test run, the running app) with \`replicas computer screenshot\` and upload them the same way when they help the user trust the result.
3257
+
3258
+ ## 4. Draft the configuration
3259
+
3260
+ Design from what you verified, not from what the README promises.
3261
+
3262
+ **Warm hook** \u2014 everything slow and deterministic that produced files on disk during step 2: dependency install, toolchain setup, \`docker compose pull\`, one-time builds, code generation. Non-interactive, \`set -euo pipefail\`, safe to rerun.
3263
+
3264
+ **Start hook** \u2014 everything that must be alive when an agent starts: start Docker, start databases and caches, run migrations, launch dev servers with \`replicas service start\`, then wait for readiness (poll a health endpoint) and exit 0. Guard every step so a second run is a no-op. Keep it under a couple of minutes; anything heavier belongs in the warm hook.
3265
+
3266
+ **System prompt** \u2014 short, and only for what is not obvious from the repository. Agents read the README, CONTRIBUTING, AGENTS.md, and CLAUDE.md themselves, so do not repeat what the product is, how the code is organized, or the standard commands. Include what you learned from history and from running the app: commit and pull request style, review expectations, what to run before opening a pull request, how to verify a change (ports, non-secret test accounts), and gotchas that cost you time. Aim for under 200 words. Use \`null\` when the repository docs already cover everything. Never include secrets or anything Replicas already tells the agent.
3267
+
3268
+ **Variables** \u2014 every key the application or hooks need, with a one-line description and whether it is required to run locally. Keys only, never values.
3269
+
3270
+ **Automations** \u2014 the set that should exist for this repository after saving, usually two to four. Each entry has a \`key\` and an \`action\`. \`create\` (the default) adds a new automation and needs a name, one-sentence description, a complete prompt an agent can execute unattended, and triggers. For an automation that already exists, pass its \`automation_id\` and a one-sentence \`note\` the reviewer sees next to it, then choose: \`update\` rewrites it with the full new content (also how you replace it with something better, under a new name if needed), \`keep\` leaves it untouched, \`disable\` turns it off. Every automation already attached to the environment must appear with one of those three; ones you leave out are not shown to the reviewer. Good candidates for new ones: pull request review focused on this codebase's conventions (\`pull_request.opened\` + \`pull_request.synchronize\`), nightly or weekly health checks (cron), documentation sync when code changes, dependency or security review, flaky-test triage. Only propose what the repository evidence supports.
3271
+
3272
+ Trigger shapes:
3273
+
3274
+ \`\`\`json
3275
+ { "type": "github", "config": { "event": "pull_request.opened" } }
3276
+ { "type": "github", "config": { "event": "pull_request.synchronize", "excluded_actors": ["dependabot[bot]"] } }
3277
+ { "type": "gitlab", "config": { "event": "merge_request.opened" } }
3278
+ { "type": "cron", "config": { "schedule": "0 9 * * 1-5", "timezone": "UTC" } }
3279
+ \`\`\`
3280
+
3281
+ GitHub events: \`pull_request.opened\`, \`pull_request.synchronize\`, \`pull_request.merged\`, \`pull_request.closed\`. GitLab events: \`merge_request.opened\`, \`merge_request.updated\`, \`merge_request.merged\`, \`merge_request.closed\`. Use one trigger type family per automation and pick the code host the repositories actually live on.
3282
+
3283
+ Test the hooks before proposing them: run the drafted warm hook and start hook scripts in this workspace (from \`~/workspaces\`) and fix the earliest failure until both exit 0 on a second run.
3284
+
3285
+ ## 5. Propose
3286
+
3287
+ The \`summary\` and \`verification\` fields are read by a person in the Environment panel, so write them for a person:
3288
+
3289
+ - \`summary\`: two or three plain sentences. What the product is, what it takes to run it, and anything notable you found. No command names, file paths, or version numbers; those belong in the system prompt or in verification details.
3290
+ - \`verification\`: three to six rows, one per outcome, in plain words. Group related commands into one row ("Installed and built the app", "Ran the unit and browser tests") and keep each \`detail\` to one sentence with the specifics. Never use a raw command as a label.
3291
+ - Limits, enforced by \`propose\`: \`summary\` ${ENVIRONMENT_SETUP_LIMITS.summaryChars} characters; \`verification\` ${ENVIRONMENT_SETUP_LIMITS.verificationItems} rows with \`detail\` ${ENVIRONMENT_SETUP_LIMITS.verificationDetailChars} characters each; \`stack\` ${ENVIRONMENT_SETUP_LIMITS.stackItems} items; \`variables\` ${ENVIRONMENT_SETUP_LIMITS.variables}, descriptions ${ENVIRONMENT_SETUP_LIMITS.variableDescriptionChars} characters; \`automations\` ${ENVIRONMENT_SETUP_LIMITS.automations} new ones (decisions on existing automations do not count), each with ${ENVIRONMENT_SETUP_LIMITS.automationTriggers} triggers, a ${ENVIRONMENT_SETUP_LIMITS.automationPromptChars}-character prompt, and a ${ENVIRONMENT_SETUP_LIMITS.automationNoteChars}-character note; \`media\` ${ENVIRONMENT_SETUP_LIMITS.mediaItems} items; \`system_prompt\` ${ENVIRONMENT_SETUP_LIMITS.systemPromptChars} characters; each hook ${ENVIRONMENT_SETUP_LIMITS.hookChars} characters; names ${ENVIRONMENT_SETUP_LIMITS.nameChars} and \`description\` ${ENVIRONMENT_SETUP_LIMITS.descriptionChars} characters.
3292
+
3293
+ Write the proposal to a file and submit it:
3294
+
3295
+ \`\`\`bash
3296
+ replicas environment-setup propose --file /tmp/proposal.json
3297
+ \`\`\`
3298
+
3299
+ \`\`\`json
3300
+ {
3301
+ "summary": "An online storefront: a Next.js site backed by a small Bun API and a Postgres database. Everything runs locally with Docker Compose and no external accounts. Payments are optional and stay disabled without a Stripe test key.",
3302
+ "stack": ["Bun", "Next.js", "Postgres", "Docker Compose", "Vitest"],
3303
+ "environment": {
3304
+ "description": "Storefront web app and API",
3305
+ "system_prompt": "Pull requests use conventional commit titles (feat:, fix:, chore:) and need a passing \`bun run check\` before review. Verify UI changes in the browser at http://localhost:3000 with the seeded account listed in docs/testing.md; the API is on port 4000. Database changes go through a migration in db/migrations, never a direct schema edit.",
3306
+ "start_hook": "#!/usr/bin/env bash\\nset -euo pipefail\\n...",
3307
+ "warm_hook": "#!/usr/bin/env bash\\nset -euo pipefail\\n..."
3308
+ },
3309
+ "variables": [
3310
+ { "key": "STRIPE_SECRET_KEY", "description": "Stripe test-mode key used by checkout; omit to run with payments disabled", "required": false }
3311
+ ],
3312
+ "automations": [
3313
+ {
3314
+ "key": "pr-review",
3315
+ "name": "Review pull requests",
3316
+ "description": "Reviews every PR against this repository's conventions and leaves inline comments.",
3317
+ "prompt": "Review this pull request...",
3318
+ "triggers": [
3319
+ { "type": "github", "config": { "event": "pull_request.opened" } },
3320
+ { "type": "github", "config": { "event": "pull_request.synchronize" } }
3321
+ ]
3322
+ }
3323
+ ],
3324
+ "verification": [
3325
+ { "label": "Installed and built the app", "status": "passed", "detail": "A second install made no changes." },
3326
+ { "label": "Ran lint, type checks, and unit tests", "status": "passed", "detail": "142 tests passed, matching CI." },
3327
+ { "label": "Completed a checkout in the browser", "status": "passed", "detail": "Added an item and placed a test order." },
3328
+ { "label": "Payment webhooks", "status": "skipped", "detail": "Needs a Stripe test key." }
3329
+ ],
3330
+ "media": [
3331
+ { "media_id": "<media-id from replicas media upload>", "title": "Checkout walkthrough" }
3332
+ ]
3333
+ }
3334
+ \`\`\`
3335
+
3336
+ When the environment already has automations, their entries look like this:
3337
+
3338
+ \`\`\`json
3339
+ { "key": "nightly-tests", "action": "keep", "automation_id": "<id from replicas automation list>", "note": "Already runs the full suite on the schedule CI uses." },
3340
+ { "key": "pr-review", "action": "update", "automation_id": "<id>", "name": "Review pull requests", "description": "...", "prompt": "...", "triggers": [ ... ], "note": "Adds the migration checklist reviewers keep asking for." },
3341
+ { "key": "docs-sync", "action": "disable", "automation_id": "<id>", "note": "The docs folder it watched was removed in May." }
3342
+ \`\`\`
3343
+
3344
+ Rules:
3345
+ - Omit \`description\`, \`system_prompt\`, \`start_hook\`, or \`warm_hook\` to keep the environment's current value. Set one to \`null\` to remove it when the repository genuinely needs none; explain why in \`summary\` or \`verification\`.
3346
+ - Omit \`environment.name\` unless the current name is misleading.
3347
+ - Every verification row must reflect something you actually ran. Do not list checks you did not run as passed.
3348
+ - A proposal does not change anything. Do not call \`replicas environment edit\`, \`vars set\`, \`files set\`, \`start-hooks save\`, \`warm-hooks save\`, or \`replicas automation create\` during a setup run.
3349
+ - If the user asks for changes after reviewing, revise and run \`propose\` again; the panel shows the latest proposal.
3350
+
3351
+ ## 6. Final message
3352
+
3353
+ After \`propose\` succeeds, mark the \`propose\` step completed and send one message with this shape:
3354
+
3355
+ \`\`\`text
3356
+ <Project> is running and ready to review.
3357
+
3358
+ **What I tested**
3359
+ - <outcome in plain words> \u2014 <one-sentence result>
3360
+ - <outcome in plain words> \u2014 <one-sentence result>
3361
+
3362
+ **What I found**
3363
+ - <two to four findings about the codebase that shaped the configuration, written for a person>
3364
+
3365
+ ![<Project> walkthrough](<chat embed URL printed by replicas media upload>)
3366
+ [View in Canvas](<View in Replicas URL>)
3367
+
3368
+ **Proposed configuration**
3369
+ Review the start hook, warm hook, system prompt, variables, and automations in the Environment panel on the right. Edit anything inline, then select **Save configuration**. Ask me here if you want changes and I will revise the proposal.
3370
+ \`\`\`
3371
+
3372
+ Keep it under 250 words plus the lists. Do not paste the hooks or system prompt into chat; the panel shows them. Never imply the configuration was saved: saving is the user's action.
3373
+
3374
+ ## Safety
3375
+
3376
+ - Never put tokens, passwords, or private keys in hooks, prompts, files, logs, or chat. Values that arrive through \`wait-variables\` are exported to your shell; never echo, cat, or paste them.
3377
+ - Do not weaken network, certificate, or package-integrity settings to make setup pass.
3378
+ - Do not run destructive git operations, force pushes, or anything against production endpoints.
3379
+ - Do not change application code to hide an environment problem. Report it instead.
3380
+ `;
3381
+ var ENVIRONMENT_SETUP_ABILITY = {
3382
+ label: "Environment setup",
3383
+ description: "Explore a codebase, verify it runs, and propose environment hooks, a system prompt, variables, and automations for review.",
3384
+ bullet: "- Setting up, auditing, or improving a Replicas environment for a repository (hooks, system prompt, variables, automations)",
3385
+ section: SECTION3,
3386
+ referenceFile: { name: "ENVIRONMENT-SETUP.md", content: REFERENCE3 }
3387
+ };
3388
+
2945
3389
  // ../shared/src/default-skills/replicas-agent/abilities/github.ts
2946
- var SECTION3 = `### GitHub
3390
+ var SECTION4 = `### GitHub
2947
3391
  Use the pre-authenticated \`gh\` CLI for repository workflows and the workspace-scoped TypeScript SDK for GitHub API calls.
2948
3392
 
2949
3393
  **Reference:** \`references/GITHUB.md\`
@@ -2953,7 +3397,7 @@ Use this when:
2953
3397
  - You need to interact with GitHub issues or actions
2954
3398
  - You need to use the GitHub API for advanced operations
2955
3399
  - You need to include images in PR descriptions`;
2956
- var REFERENCE3 = `# GitHub Integration
3400
+ var REFERENCE4 = `# GitHub Integration
2957
3401
 
2958
3402
  This guide covers how to interact with GitHub from within your Replicas workspace. Prefer \`@replicas/sdk\` for API calls so batching and data processing stay in one TypeScript program. The \`gh\` CLI remains useful for ergonomic pull request and git-adjacent workflows.
2959
3403
 
@@ -3082,12 +3526,12 @@ var GITHUB_ABILITY = {
3082
3526
  label: "GitHub",
3083
3527
  description: "GitHub workflows through gh and API calls through @replicas/sdk.",
3084
3528
  bullet: "- Interacting with GitHub (creating PRs, managing issues, using the API, etc.)",
3085
- section: SECTION3,
3086
- referenceFile: { name: "GITHUB.md", content: REFERENCE3 }
3529
+ section: SECTION4,
3530
+ referenceFile: { name: "GITHUB.md", content: REFERENCE4 }
3087
3531
  };
3088
3532
 
3089
3533
  // ../shared/src/default-skills/replicas-agent/abilities/gitlab.ts
3090
- var SECTION4 = `### GitLab
3534
+ var SECTION5 = `### GitLab
3091
3535
  Use plain git for repository traffic and the workspace-scoped TypeScript SDK for GitLab API operations.
3092
3536
 
3093
3537
  **Reference:** \`references/GITLAB.md\`
@@ -3096,7 +3540,7 @@ Use this when:
3096
3540
  - A repository remote is on gitlab.com or a self-managed GitLab instance
3097
3541
  - You need to open or update a merge request
3098
3542
  - You need GitLab issues, pipelines, comments, or other API data`;
3099
- var REFERENCE4 = `# GitLab Integration
3543
+ var REFERENCE5 = `# GitLab Integration
3100
3544
 
3101
3545
  Git credentials are preconfigured for fetch, pull, and push. Use \`@replicas/sdk\` for API traffic; never inspect \`~/.git-credentials\`, request a token, or send a credential with curl.
3102
3546
 
@@ -3144,12 +3588,12 @@ var GITLAB_ABILITY = {
3144
3588
  label: "GitLab",
3145
3589
  description: "Git for repository traffic and @replicas/sdk for the GitLab API.",
3146
3590
  bullet: "- Interacting with GitLab (pushing to GitLab repos, opening merge requests)",
3147
- section: SECTION4,
3148
- referenceFile: { name: "GITLAB.md", content: REFERENCE4 }
3591
+ section: SECTION5,
3592
+ referenceFile: { name: "GITLAB.md", content: REFERENCE5 }
3149
3593
  };
3150
3594
 
3151
3595
  // ../shared/src/default-skills/replicas-agent/abilities/linear.ts
3152
- var SECTION5 = `### Linear
3596
+ var SECTION6 = `### Linear
3153
3597
  Create tickets, fetch issues, update state, add comments, and search through \`replicas.linear.graphql\` in \`@replicas/sdk\`. This works without a Linear MCP server and refreshes authentication automatically.
3154
3598
 
3155
3599
  **Reference:** \`references/LINEAR.md\`
@@ -3160,7 +3604,7 @@ Use this when:
3160
3604
  - You need to update an issue's state or add a comment
3161
3605
  - You need to search Linear issues
3162
3606
  - A Linear request failed with an authentication error`;
3163
- var REFERENCE5 = `# Linear Integration
3607
+ var REFERENCE6 = `# Linear Integration
3164
3608
 
3165
3609
  Use \`@replicas/sdk\`; never request or handle a Linear OAuth token. Replicas refreshes the organization credential behind the gateway.
3166
3610
 
@@ -3249,12 +3693,12 @@ var LINEAR_ABILITY = {
3249
3693
  label: "Linear",
3250
3694
  description: "Create tickets, fetch issues, comment, and update state through @replicas/sdk.",
3251
3695
  bullet: "- Interacting with Linear (creating tickets, fetching issues, updating state, commenting, or troubleshooting authentication): use replicas.linear.graphql from @replicas/sdk, which refreshes tokens automatically and needs no Linear MCP server. Read references/LINEAR.md before treating a rejected workspace token as a disconnected integration.",
3252
- section: SECTION5,
3253
- referenceFile: { name: "LINEAR.md", content: REFERENCE5 }
3696
+ section: SECTION6,
3697
+ referenceFile: { name: "LINEAR.md", content: REFERENCE6 }
3254
3698
  };
3255
3699
 
3256
3700
  // ../shared/src/default-skills/replicas-agent/abilities/media.ts
3257
- var SECTION6 = `### Media
3701
+ var SECTION7 = `### Media
3258
3702
  Deliver screenshots, screen recordings, generated diagrams, audio clips, and self-contained HTML pages to the Replicas dashboard and, when applicable, inline in the destination workflow.
3259
3703
 
3260
3704
  **Reference:** \`references/MEDIA.md\`
@@ -3265,7 +3709,7 @@ Use this when:
3265
3709
  - You produce a self-contained HTML report that should be linked from a pull request
3266
3710
  - You record video output (browser automation, screen capture) \u2014 including the recommended aspect ratio and FPS
3267
3711
  - You need to embed media in a Slack/Linear/GitHub/GitLab message AND keep a referenceable copy in the Replicas dashboard`;
3268
- var REFERENCE6 = `# Media (Screenshots, Recordings, Audio, HTML)
3712
+ var REFERENCE7 = `# Media (Screenshots, Recordings, Audio, HTML)
3269
3713
 
3270
3714
  This is the single source of truth for delivering screenshots, screen recordings, generated diagrams, audio clips, and self-contained HTML pages through Replicas and external surfaces (Slack, Linear, GitHub, GitLab).
3271
3715
 
@@ -3590,12 +4034,12 @@ var MEDIA_ABILITY = {
3590
4034
  label: "Media",
3591
4035
  description: "Deliver media to Replicas and destination workflows with inline uploads.",
3592
4036
  bullet: "- Producing or showing the user any media \u2014 screenshots, screen recordings, generated images or diagrams, audio clips, or HTML recap pages \u2014 including in your Replicas chat reply, PR descriptions/comments, and other external platforms",
3593
- section: SECTION6,
3594
- referenceFile: { name: "MEDIA.md", content: REFERENCE6 }
4037
+ section: SECTION7,
4038
+ referenceFile: { name: "MEDIA.md", content: REFERENCE7 }
3595
4039
  };
3596
4040
 
3597
4041
  // ../shared/src/memory.ts
3598
- import { z as z9 } from "zod";
4042
+ import { z as z10 } from "zod";
3599
4043
 
3600
4044
  // ../shared/src/sandbox.ts
3601
4045
  var SANDBOX_LIFECYCLE = {
@@ -3619,31 +4063,31 @@ var MEMORY_ROOT = `${SANDBOX_PATHS.REPLICAS_DIR}/memories`;
3619
4063
  var MEMORY_INDEX_FILENAME = "MEMORY.md";
3620
4064
  var MEMORY_BUNDLE_FILENAME = "memory.tar.gz";
3621
4065
  var MEMORY_MARKER_GUIDANCE = `When you decide that a preference, correction, decision, procedure, or lesson is worth remembering for future sessions, say so in your response casually, like a coworker: "Ah, I'll remember that for next time" or "I'll keep that in mind." Keep it natural and never mention the memory feature, memory pipeline, markers, persistence, or that you are saving or adding something to memory. These phrases signal intent to remember; they do not mean anything has already been saved, so do not claim persistence is complete.`;
3622
- var memoryExtractionResultSchema = z9.object({
3623
- seatSummary: z9.string().nullable(),
3624
- organizationSummary: z9.string().nullable()
4066
+ var memoryExtractionResultSchema = z10.object({
4067
+ seatSummary: z10.string().nullable(),
4068
+ organizationSummary: z10.string().nullable()
3625
4069
  });
3626
- var { $schema: _, ...MEMORY_EXTRACTION_SCHEMA } = z9.toJSONSchema(memoryExtractionResultSchema);
3627
- var memoryGenerationManifestSchema = z9.object({
3628
- domainId: z9.string(),
3629
- generation: z9.number().int().nonnegative(),
3630
- previousManifestKey: z9.string().nullable(),
3631
- createdAt: z9.string(),
3632
- promptVersion: z9.string(),
3633
- harness: z9.enum(["claude", "codex", "none"]),
3634
- model: z9.string(),
3635
- bundle: z9.object({
3636
- path: z9.literal(MEMORY_BUNDLE_FILENAME),
3637
- sha256: z9.string().regex(/^[a-f0-9]{64}$/),
3638
- sizeBytes: z9.number().int().positive()
4070
+ var { $schema: _, ...MEMORY_EXTRACTION_SCHEMA } = z10.toJSONSchema(memoryExtractionResultSchema);
4071
+ var memoryGenerationManifestSchema = z10.object({
4072
+ domainId: z10.string(),
4073
+ generation: z10.number().int().nonnegative(),
4074
+ previousManifestKey: z10.string().nullable(),
4075
+ createdAt: z10.string(),
4076
+ promptVersion: z10.string(),
4077
+ harness: z10.enum(["claude", "codex", "none"]),
4078
+ model: z10.string(),
4079
+ bundle: z10.object({
4080
+ path: z10.literal(MEMORY_BUNDLE_FILENAME),
4081
+ sha256: z10.string().regex(/^[a-f0-9]{64}$/),
4082
+ sizeBytes: z10.number().int().positive()
3639
4083
  }).nullable(),
3640
- files: z9.record(z9.string(), z9.string()),
3641
- rollouts: z9.record(z9.string(), z9.string()),
3642
- rolloutSources: z9.record(z9.string(), z9.string()).optional()
4084
+ files: z10.record(z10.string(), z10.string()),
4085
+ rollouts: z10.record(z10.string(), z10.string()),
4086
+ rolloutSources: z10.record(z10.string(), z10.string()).optional()
3643
4087
  });
3644
4088
 
3645
4089
  // ../shared/src/default-skills/replicas-agent/abilities/memory.ts
3646
- var SECTION7 = `### Memory
4090
+ var SECTION8 = `### Memory
3647
4091
  Check relevant long-term memory before substantive work when historical context could improve the result.
3648
4092
 
3649
4093
  **Reference:** \`references/MEMORY.md\`
@@ -3655,7 +4099,7 @@ Use this when:
3655
4099
  - Related work may explain an error or implementation choice
3656
4100
 
3657
4101
  When uncertain whether prior context could help, check memory. If you decide something is worth remembering for future sessions, follow the marker guidance in references/MEMORY.md.`;
3658
- var REFERENCE7 = `# Long-term memory
4102
+ var REFERENCE8 = `# Long-term memory
3659
4103
 
3660
4104
  Replicas memory is installed under \`~/.replicas/memories\`:
3661
4105
 
@@ -3678,13 +4122,13 @@ var MEMORY_ABILITY = {
3678
4122
  label: "Memory",
3679
4123
  description: "Check private and organization memory before substantive work.",
3680
4124
  bullet: "",
3681
- section: SECTION7,
3682
- referenceFile: { name: "MEMORY.md", content: REFERENCE7 },
4125
+ section: SECTION8,
4126
+ referenceFile: { name: "MEMORY.md", content: REFERENCE8 },
3683
4127
  locked: true
3684
4128
  };
3685
4129
 
3686
4130
  // ../shared/src/default-skills/replicas-agent/abilities/previews.ts
3687
- var SECTION8 = `### Previews
4131
+ var SECTION9 = `### Previews
3688
4132
  Expose locally running services (web apps, APIs, databases) as public preview URLs so humans can interact with them directly.
3689
4133
 
3690
4134
  **Reference:** \`references/PREVIEWS.md\`
@@ -3693,7 +4137,7 @@ Use this when:
3693
4137
  - You need to start a service that a human should view or interact with
3694
4138
  - The task involves UI work that benefits from human review
3695
4139
  - You are verifying frontend/backend integrations visually`;
3696
- var REFERENCE8 = `# Preview URLs
4140
+ var REFERENCE9 = `# Preview URLs
3697
4141
 
3698
4142
  When you run services on ports \u2014 such as a web app, API server, or database \u2014 humans may want to interact with them directly. You can expose your locally running services as public preview URLs.
3699
4143
 
@@ -3769,12 +4213,12 @@ var PREVIEWS_ABILITY = {
3769
4213
  label: "Previews",
3770
4214
  description: "Expose locally running services on public preview URLs for humans.",
3771
4215
  bullet: "- Creating preview URLs for locally running services",
3772
- section: SECTION8,
3773
- referenceFile: { name: "PREVIEWS.md", content: REFERENCE8 }
4216
+ section: SECTION9,
4217
+ referenceFile: { name: "PREVIEWS.md", content: REFERENCE9 }
3774
4218
  };
3775
4219
 
3776
4220
  // ../shared/src/default-skills/replicas-agent/abilities/plugins.ts
3777
- var SECTION9 = `### Plugins
4221
+ var SECTION10 = `### Plugins
3778
4222
  Discover and execute installed marketplace tools through the workspace-scoped TypeScript SDK.
3779
4223
 
3780
4224
  **Reference:** \`references/PLUGINS.md\`
@@ -3790,7 +4234,7 @@ Use this when:
3790
4234
  - The user asks to query or update a connected turbopuffer namespace
3791
4235
  - The user asks for PlanetScale organizations, databases, branches, or Insights data
3792
4236
  - The user asks to analyze text with Pangram`;
3793
- var REFERENCE9 = `# Plugins
4237
+ var REFERENCE10 = `# Plugins
3794
4238
 
3795
4239
  Plugins are TypeScript libraries, not MCP servers. Import \`@replicas/sdk\`; Replicas authenticates the workspace and selects the most specific environment the workspace inherits from, then Global. Provider credentials, sessions, and project keys are never exposed.
3796
4240
 
@@ -3961,12 +4405,12 @@ var PLUGINS_ABILITY = {
3961
4405
  label: "Plugins",
3962
4406
  description: "Use installed marketplace tools through @replicas/sdk.",
3963
4407
  bullet: "- Interacting with installed marketplace plugins through TypeScript",
3964
- section: SECTION9,
3965
- referenceFile: { name: "PLUGINS.md", content: REFERENCE9 }
4408
+ section: SECTION10,
4409
+ referenceFile: { name: "PLUGINS.md", content: REFERENCE10 }
3966
4410
  };
3967
4411
 
3968
4412
  // ../shared/src/default-skills/replicas-agent/abilities/replicas.ts
3969
- var SECTION10 = `### Replicas (in-workspace CLI)
4413
+ var SECTION11 = `### Replicas (in-workspace CLI)
3970
4414
  Take action *with* Replicas itself \u2014 manage automations, environments (variables, files), repos, and \`replicas.json\` config \u2014 using the pre-installed, pre-authenticated \`replicas\` CLI.
3971
4415
 
3972
4416
  **Reference:** \`references/REPLICAS.md\`
@@ -3977,7 +4421,7 @@ Use this when:
3977
4421
  - The user asks "what envs / repos / automations do I have?"
3978
4422
  - The user asks you to scaffold a \`replicas.json\` / \`replicas.yaml\` in a repo
3979
4423
  - You need to run a long-lived service (dev server, daemon) \u2014 always use \`replicas service start\` so it survives workspace sleep/wake`;
3980
- var REFERENCE10 = `# Replicas (in-workspace CLI)
4424
+ var REFERENCE11 = `# Replicas (in-workspace CLI)
3981
4425
 
3982
4426
  This guide covers how to take action *with* Replicas itself from inside a Replicas workspace \u2014 managing automations, environments (and their variables/files), repos, previews, and the user's \`replicas.json\` config \u2014 using the pre-installed \`replicas\` CLI.
3983
4427
 
@@ -4015,6 +4459,7 @@ In agent mode the CLI hides commands that don't make sense for in-workspace agen
4015
4459
  | \`replicas repos\` | List repos connected to the org |
4016
4460
  | \`replicas environment ...\` | Manage environments, env vars, env files |
4017
4461
  | \`replicas automation ...\` | Manage automations (cron + GitHub/GitLab event triggers) |
4462
+ | \`replicas environment-setup ...\` | Report progress and propose configuration during an agent-led environment setup run (covered in \`ENVIRONMENT-SETUP.md\`) |
4018
4463
  | \`replicas preview ...\` | Register / list preview URLs (covered in \`PREVIEWS.md\`) |
4019
4464
  | \`replicas service ...\` | Run long-lived services detached so they survive workspace sleep/wake (see below) |
4020
4465
  | \`replicas media ...\` | Upload, list, share, revoke, or delete workspace media; follow \`MEDIA.md\` for destination embedding |
@@ -4208,13 +4653,13 @@ var REPLICAS_ABILITY = {
4208
4653
  description: "Teach the agent about Replicas itself \u2014 automations, environments, the in-workspace CLI.",
4209
4654
  // No bullet — help_instructions covers the `replicas` CLI surface in detail.
4210
4655
  bullet: "",
4211
- section: SECTION10,
4212
- referenceFile: { name: "REPLICAS.md", content: REFERENCE10 },
4656
+ section: SECTION11,
4657
+ referenceFile: { name: "REPLICAS.md", content: REFERENCE11 },
4213
4658
  locked: true
4214
4659
  };
4215
4660
 
4216
4661
  // ../shared/src/default-skills/replicas-agent/abilities/sentry.ts
4217
- var SECTION11 = `### Sentry
4662
+ var SECTION12 = `### Sentry
4218
4663
  Read issues and project data through the workspace-scoped TypeScript SDK.
4219
4664
 
4220
4665
  **Reference:** \`references/SENTRY.md\`
@@ -4222,7 +4667,7 @@ Read issues and project data through the workspace-scoped TypeScript SDK.
4222
4667
  Use this when:
4223
4668
  - You need to inspect Sentry projects or issues
4224
4669
  - A user asks for error-monitoring context outside a webhook-triggered task`;
4225
- var REFERENCE11 = `# Sentry Integration
4670
+ var REFERENCE12 = `# Sentry Integration
4226
4671
 
4227
4672
  Use \`@replicas/sdk\`; never request or read a Sentry token. Sentry access is organization-scoped and read-only.
4228
4673
 
@@ -4240,8 +4685,8 @@ var SENTRY_ABILITY = {
4240
4685
  label: "Sentry",
4241
4686
  description: "Read Sentry projects and issues through @replicas/sdk.",
4242
4687
  bullet: "- Interacting with Sentry (reading projects, issues, and error context)",
4243
- section: SECTION11,
4244
- referenceFile: { name: "SENTRY.md", content: REFERENCE11 }
4688
+ section: SECTION12,
4689
+ referenceFile: { name: "SENTRY.md", content: REFERENCE12 }
4245
4690
  };
4246
4691
 
4247
4692
  // ../shared/src/slack-response-style.ts
@@ -4251,7 +4696,7 @@ var SLACK_BLOCK_KIT_GUIDANCE = "Use Block Kit whenever structure or a link would
4251
4696
  var SLACK_PR_BUTTON_GUIDANCE = 'The first time you share a given pull request or merge request link in a thread \u2014 the message announcing you opened it \u2014 attach a button for it: send `blocks` alongside `text` \u2014 a `section` block holding your message as `mrkdwn`, then an `actions` block with one element per newly shared link, `{"type": "button", "style": "primary", "text": {"type": "plain_text", "text": "View PR"}, "url": "<pr url>", "action_id": "view_pr"}`. Later messages about a pull request you already linked in this thread keep the link in the sentence and get no button, and never re-post a button for a link someone already has. Label it "View MR" for GitLab, and if there are several give each button a unique `action_id` and name its repository in the label ("View PR \xB7 web"). Always keep `text` populated with the same message \u2014 Slack uses it for notifications and fallback \u2014 and keep the link in the sentence too.';
4252
4697
 
4253
4698
  // ../shared/src/default-skills/replicas-agent/abilities/slack.ts
4254
- var SECTION12 = `### Slack
4699
+ var SECTION13 = `### Slack
4255
4700
  Send messages, read threads, search conversations, and transfer files through the workspace-scoped TypeScript SDK.
4256
4701
 
4257
4702
  **Reference:** \`references/SLACK.md\`
@@ -4261,7 +4706,7 @@ Use this when:
4261
4706
  - You need to read or search Slack conversations
4262
4707
  - You need to download a file attached to a Slack message
4263
4708
  - You encounter a Slack message link and need its full thread`;
4264
- var REFERENCE12 = `# Slack Integration
4709
+ var REFERENCE13 = `# Slack Integration
4265
4710
 
4266
4711
  Use \`@replicas/sdk\`; never read or send a Slack token directly. The SDK calls Replicas, which selects only this workspace's organization connection.
4267
4712
 
@@ -4339,8 +4784,8 @@ var SLACK_ABILITY = {
4339
4784
  label: "Slack",
4340
4785
  description: "Send messages, read threads, search, and transfer files through @replicas/sdk.",
4341
4786
  bullet: "- Interacting with Slack (listing channels, sending messages, reading threads, or searching): use replicas.slack.call from @replicas/sdk. Read references/SLACK.md; no Slack MCP server or provider token in the VM is required.",
4342
- section: SECTION12,
4343
- referenceFile: { name: "SLACK.md", content: REFERENCE12 }
4787
+ section: SECTION13,
4788
+ referenceFile: { name: "SLACK.md", content: REFERENCE13 }
4344
4789
  };
4345
4790
 
4346
4791
  // ../shared/src/default-skills/replicas-agent/registry.ts
@@ -4349,6 +4794,7 @@ var REPLICAS_AGENT_ABILITY_REGISTRY = {
4349
4794
  memory: MEMORY_ABILITY,
4350
4795
  computer: COMPUTER_ABILITY,
4351
4796
  docker: DOCKER_ABILITY,
4797
+ environment_setup: ENVIRONMENT_SETUP_ABILITY,
4352
4798
  github: GITHUB_ABILITY,
4353
4799
  gitlab: GITLAB_ABILITY,
4354
4800
  linear: LINEAR_ABILITY,
@@ -7160,12 +7606,6 @@ function parseReplicasConfigString(content, filename) {
7160
7606
  return parseReplicasConfig(parsed, filename);
7161
7607
  }
7162
7608
 
7163
- // ../shared/src/uuid.ts
7164
- function createUuidFromHex(value) {
7165
- return `${value.slice(0, 8)}-${value.slice(8, 12)}-5${value.slice(13, 16)}-${(Number.parseInt(value.slice(16, 17), 16) & 3 | 8).toString(16)}${value.slice(17, 20)}-${value.slice(20, 32)}`;
7166
- }
7167
- var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
7168
-
7169
7609
  // ../shared/src/auth-errors.ts
7170
7610
  var AUTHENTICATION_ERROR_PATTERNS = [
7171
7611
  /unauthorized/,
@@ -7371,7 +7811,7 @@ var CLAUDE_AUTH_ENV_KEYS_BY_METHOD = {
7371
7811
  };
7372
7812
 
7373
7813
  // ../shared/src/routes/command-protection.ts
7374
- import { z as z10 } from "zod";
7814
+ import { z as z11 } from "zod";
7375
7815
 
7376
7816
  // ../shared/src/git-invocations.ts
7377
7817
  var COMMIT_VALUE_OPTIONS = /* @__PURE__ */ new Set(["message", "file", "trailer", "reuse-message", "reedit-message", "fixup", "squash", "template", "author", "date", "cleanup", "pathspec-from-file"]);
@@ -7462,27 +7902,27 @@ function findCheckoutTarget(args) {
7462
7902
  }
7463
7903
 
7464
7904
  // ../shared/src/routes/command-protection.ts
7465
- var commandProtectionRepoStateSchema = z10.object({
7466
- branch: z10.string().nullable(),
7467
- defaultBranch: z10.string().nullable(),
7468
- pushBranch: z10.string().nullable(),
7469
- pushConfig: z10.string().nullable(),
7470
- headMessage: z10.string().nullable(),
7471
- mergeInProgress: z10.boolean().optional()
7905
+ var commandProtectionRepoStateSchema = z11.object({
7906
+ branch: z11.string().nullable(),
7907
+ defaultBranch: z11.string().nullable(),
7908
+ pushBranch: z11.string().nullable(),
7909
+ pushConfig: z11.string().nullable(),
7910
+ headMessage: z11.string().nullable(),
7911
+ mergeInProgress: z11.boolean().optional()
7472
7912
  });
7473
- var commandProtectionEvaluateRequestSchema = z10.object({
7474
- provider: z10.enum(["claude", "codex", "cursor", "opencode", "pi"]),
7475
- source: z10.enum(["claude_pre_tool_use", "codex_approval_request", "cursor_pre_tool_use", "opencode_pre_tool_use", "pi_tool_call"]),
7476
- toolName: z10.string(),
7477
- toolInput: z10.unknown(),
7478
- command: z10.string().nullish(),
7479
- cwd: z10.string().nullish(),
7480
- toolUseId: z10.string().nullish(),
7913
+ var commandProtectionEvaluateRequestSchema = z11.object({
7914
+ provider: z11.enum(["claude", "codex", "cursor", "opencode", "pi"]),
7915
+ source: z11.enum(["claude_pre_tool_use", "codex_approval_request", "cursor_pre_tool_use", "opencode_pre_tool_use", "pi_tool_call"]),
7916
+ toolName: z11.string(),
7917
+ toolInput: z11.unknown(),
7918
+ command: z11.string().nullish(),
7919
+ cwd: z11.string().nullish(),
7920
+ toolUseId: z11.string().nullish(),
7481
7921
  // Read by the engine before the command runs, keyed by absolute path, so the
7482
7922
  // policy can see branches and commit messages the command text only references.
7483
- gitContext: z10.object({
7484
- repos: z10.record(z10.string(), commandProtectionRepoStateSchema),
7485
- messageFiles: z10.record(z10.string(), z10.string())
7923
+ gitContext: z11.object({
7924
+ repos: z11.record(z11.string(), commandProtectionRepoStateSchema),
7925
+ messageFiles: z11.record(z11.string(), z11.string())
7486
7926
  }).optional()
7487
7927
  });
7488
7928
  var COMMAND_PROTECTION_COMMAND_KEYS = ["command", "cmd", "script", "query", "endpoint", "path", "url", "mutation"];
@@ -7679,38 +8119,38 @@ function shouldRefreshPullRequests(toolName, toolInput) {
7679
8119
  }
7680
8120
 
7681
8121
  // ../shared/src/routes/linear.ts
7682
- import { z as z11 } from "zod";
7683
- var linearSessionMetadataSchema = z11.object({
7684
- via_mothership: z11.boolean().optional(),
7685
- issue_id: z11.string(),
7686
- issue_identifier: z11.string(),
7687
- issue_title: z11.string(),
7688
- issue_description: z11.string(),
7689
- issue_url: z11.string(),
7690
- comment_id: z11.string(),
7691
- comment_body: z11.string(),
7692
- triggered_by_id: z11.string().optional(),
7693
- triggered_by_name: z11.string().optional(),
7694
- triggered_by_email: z11.string().optional(),
7695
- linear_workspace_id: z11.string().optional(),
7696
- creator_id: z11.string().optional(),
7697
- creator_name: z11.string().optional(),
7698
- creator_email: z11.string().optional(),
7699
- assignee_id: z11.string().optional(),
7700
- assignee_name: z11.string().optional(),
7701
- assignee_email: z11.string().optional(),
7702
- issue_state: z11.string().optional(),
7703
- parent_issue: z11.object({
7704
- id: z11.string(),
7705
- identifier: z11.string(),
7706
- title: z11.string(),
7707
- description: z11.string().nullable()
8122
+ import { z as z12 } from "zod";
8123
+ var linearSessionMetadataSchema = z12.object({
8124
+ via_mothership: z12.boolean().optional(),
8125
+ issue_id: z12.string(),
8126
+ issue_identifier: z12.string(),
8127
+ issue_title: z12.string(),
8128
+ issue_description: z12.string(),
8129
+ issue_url: z12.string(),
8130
+ comment_id: z12.string(),
8131
+ comment_body: z12.string(),
8132
+ triggered_by_id: z12.string().optional(),
8133
+ triggered_by_name: z12.string().optional(),
8134
+ triggered_by_email: z12.string().optional(),
8135
+ linear_workspace_id: z12.string().optional(),
8136
+ creator_id: z12.string().optional(),
8137
+ creator_name: z12.string().optional(),
8138
+ creator_email: z12.string().optional(),
8139
+ assignee_id: z12.string().optional(),
8140
+ assignee_name: z12.string().optional(),
8141
+ assignee_email: z12.string().optional(),
8142
+ issue_state: z12.string().optional(),
8143
+ parent_issue: z12.object({
8144
+ id: z12.string(),
8145
+ identifier: z12.string(),
8146
+ title: z12.string(),
8147
+ description: z12.string().nullable()
7708
8148
  }).optional(),
7709
- workspace: z11.object({
7710
- id: z11.string(),
7711
- coding_agent: z11.custom((value) => typeof value === "string" && isValidAgentProvider(value)),
7712
- task_description: z11.string(),
7713
- created_at: z11.string()
8149
+ workspace: z12.object({
8150
+ id: z12.string(),
8151
+ coding_agent: z12.custom((value) => typeof value === "string" && isValidAgentProvider(value)),
8152
+ task_description: z12.string(),
8153
+ created_at: z12.string()
7714
8154
  }).optional()
7715
8155
  });
7716
8156
 
@@ -8045,46 +8485,46 @@ var DEFAULT_WORKSPACE_FILTERS = {
8045
8485
  var ONE_DAY_MS = 24 * 60 * 60 * 1e3;
8046
8486
 
8047
8487
  // ../shared/src/routes/workspace-events.ts
8048
- import { z as z12 } from "zod";
8049
- var workspaceChangedEventSchema = z12.discriminatedUnion("type", [
8050
- z12.object({
8051
- type: z12.literal("workspace.changed"),
8052
- workspaceId: z12.string(),
8053
- completion: z12.object({
8054
- workspaceName: z12.string(),
8055
- completedAt: z12.string(),
8056
- processing: z12.boolean().optional()
8488
+ import { z as z13 } from "zod";
8489
+ var workspaceChangedEventSchema = z13.discriminatedUnion("type", [
8490
+ z13.object({
8491
+ type: z13.literal("workspace.changed"),
8492
+ workspaceId: z13.string(),
8493
+ completion: z13.object({
8494
+ workspaceName: z13.string(),
8495
+ completedAt: z13.string(),
8496
+ processing: z13.boolean().optional()
8057
8497
  }).optional(),
8058
- ts: z12.string()
8498
+ ts: z13.string()
8059
8499
  }),
8060
- z12.object({
8061
- type: z12.literal("workspace.chat.changed"),
8062
- workspaceId: z12.string(),
8063
- chatId: z12.string(),
8064
- ts: z12.string()
8500
+ z13.object({
8501
+ type: z13.literal("workspace.chat.changed"),
8502
+ workspaceId: z13.string(),
8503
+ chatId: z13.string(),
8504
+ ts: z13.string()
8065
8505
  }),
8066
- z12.object({ type: z12.literal("presence.changed"), ts: z12.string() }),
8067
- z12.object({
8068
- type: z12.literal("mobile-testing.changed"),
8069
- workspaceId: z12.string(),
8070
- ts: z12.string()
8506
+ z13.object({ type: z13.literal("presence.changed"), ts: z13.string() }),
8507
+ z13.object({
8508
+ type: z13.literal("mobile-testing.changed"),
8509
+ workspaceId: z13.string(),
8510
+ ts: z13.string()
8071
8511
  })
8072
8512
  ]);
8073
8513
 
8074
8514
  // ../shared/src/routes/presence.ts
8075
- import { z as z13 } from "zod";
8076
- var presenceStatusSchema = z13.enum(["online", "typing"]);
8077
- var presenceLocationSchema = z13.object({
8078
- environmentId: z13.string().optional(),
8079
- workspaceId: z13.string().optional()
8515
+ import { z as z14 } from "zod";
8516
+ var presenceStatusSchema = z14.enum(["online", "typing"]);
8517
+ var presenceLocationSchema = z14.object({
8518
+ environmentId: z14.string().optional(),
8519
+ workspaceId: z14.string().optional()
8080
8520
  });
8081
- var presenceEntrySchema = z13.object({
8082
- userId: z13.string(),
8521
+ var presenceEntrySchema = z14.object({
8522
+ userId: z14.string(),
8083
8523
  status: presenceStatusSchema,
8084
8524
  location: presenceLocationSchema,
8085
- ts: z13.string()
8525
+ ts: z14.string()
8086
8526
  });
8087
- var updatePresenceRequestSchema = z13.object({
8527
+ var updatePresenceRequestSchema = z14.object({
8088
8528
  status: presenceStatusSchema,
8089
8529
  location: presenceLocationSchema.optional()
8090
8530
  });
@@ -8427,187 +8867,6 @@ function isSkillRegistryManifest(value) {
8427
8867
  );
8428
8868
  }
8429
8869
 
8430
- // ../shared/src/routes/environment-setups.ts
8431
- import { z as z14 } from "zod";
8432
- var ENVIRONMENT_SETUP_STEPS = [
8433
- { key: "understand", label: "Understand the codebase" },
8434
- { key: "install", label: "Install dependencies and run the app" },
8435
- { key: "verify", label: "Verify checks and record a walkthrough" },
8436
- { key: "configure", label: "Draft hooks, system prompt, and automations" },
8437
- { key: "propose", label: "Propose the configuration for review" }
8438
- ];
8439
- var ENVIRONMENT_SETUP_STEP_STATUSES = ["pending", "in_progress", "completed", "skipped"];
8440
- var ENVIRONMENT_SETUP_RUN_STATUSES = ["running", "proposed", "applied", "failed", "cancelled"];
8441
- var ENVIRONMENT_SETUP_AUTOMATION_ACTIONS = ["create", "update", "keep", "disable"];
8442
- var ENVIRONMENT_SETUP_VERIFICATION_STATUSES = ["passed", "failed", "skipped"];
8443
- var ENVIRONMENT_SETUP_LIMITS = {
8444
- summaryChars: 600,
8445
- stackItems: 30,
8446
- nameChars: 120,
8447
- descriptionChars: 1e3,
8448
- systemPromptChars: 2e4,
8449
- hookChars: 5e4,
8450
- variables: 50,
8451
- variableKeyChars: 128,
8452
- variableDescriptionChars: 500,
8453
- automations: 8,
8454
- automationKeyChars: 80,
8455
- automationPromptChars: 1e4,
8456
- automationTriggers: 5,
8457
- automationNoteChars: 300,
8458
- verificationItems: 8,
8459
- verificationDetailChars: 300,
8460
- mediaItems: 8,
8461
- repositories: 20
8462
- };
8463
- var ENVIRONMENT_SETUP_VARIABLE_WAIT = { defaultMs: 5 * 6e4, maxMs: 15 * 6e4, pollMs: 5e3 };
8464
- var VARIABLE_KEY_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
8465
- var text = (max) => max === void 0 ? z14.string().trim() : z14.string().trim().max(max);
8466
- var requiredText = (max) => text(max).min(1, "must not be empty");
8467
- var optionalText = (max) => text(max).nullish().transform((value) => value || null);
8468
- var clearableText = (max) => text(max).nullish().transform((value) => value === void 0 ? void 0 : value || null);
8469
- var list = (item, max) => max === void 0 ? z14.array(item) : z14.array(item).max(max);
8470
- var ENVIRONMENT_SETUP_AUTHORED_TRIGGER_TYPES = ["cron", "github", "gitlab"];
8471
- function isEnvironmentSetupAuthoredTriggerType(type) {
8472
- return ENVIRONMENT_SETUP_AUTHORED_TRIGGER_TYPES.some((authored) => authored === type);
8473
- }
8474
- var repositoryTriggerConfigSchema = z14.object({
8475
- event: z14.string(),
8476
- repository_ids: z14.array(z14.string().regex(UUID_RE, "must be a repository id")).optional(),
8477
- group_pr_events: z14.boolean().optional(),
8478
- excluded_actors: z14.array(z14.string()).optional()
8479
- });
8480
- var proposalTriggerSchema = z14.discriminatedUnion("type", [
8481
- z14.object({ type: z14.literal("cron"), config: z14.object({ schedule: z14.string(), timezone: z14.string().optional() }) }),
8482
- z14.object({ type: z14.literal("github"), config: repositoryTriggerConfigSchema }),
8483
- z14.object({ type: z14.literal("gitlab"), config: repositoryTriggerConfigSchema })
8484
- ]);
8485
- var existingTriggerSchema = z14.custom(
8486
- (value) => isRecord(value) && typeof value.type === "string" && isRecord(value.config),
8487
- "must be an automation trigger"
8488
- );
8489
- var carriedTriggerSchema = existingTriggerSchema.refine(
8490
- (trigger) => !isEnvironmentSetupAuthoredTriggerType(trigger.type)
8491
- );
8492
- function automationSchema(limits) {
8493
- const authored = z14.object({
8494
- name: text(limits.nameChars),
8495
- description: text(limits.descriptionChars),
8496
- prompt: text(limits.automationPromptChars),
8497
- triggers: list(proposalTriggerSchema, limits.automationTriggers)
8498
- });
8499
- const updated = authored.extend({ triggers: list(z14.union([proposalTriggerSchema, carriedTriggerSchema]), limits.automationTriggers) });
8500
- return z14.object({
8501
- key: requiredText(limits.automationKeyChars),
8502
- action: z14.enum(ENVIRONMENT_SETUP_AUTOMATION_ACTIONS).default("create"),
8503
- automation_id: z14.string().regex(UUID_RE, "must be an automation id").nullable().default(null),
8504
- name: text().default(""),
8505
- description: optionalText().transform((value) => value ?? ""),
8506
- prompt: text().default(""),
8507
- triggers: list(existingTriggerSchema).default([]),
8508
- note: optionalText(limits.automationNoteChars)
8509
- }).superRefine((automation, ctx) => {
8510
- if (automation.action === "create" && automation.automation_id) {
8511
- ctx.addIssue({ code: "custom", path: ["automation_id"], message: "belongs on an update, keep, or disable entry" });
8512
- }
8513
- if (automation.action !== "create" && !automation.automation_id) {
8514
- ctx.addIssue({ code: "custom", path: ["automation_id"], message: "must be the id of an automation attached to this environment" });
8515
- }
8516
- if (automation.action === "create" || automation.action === "update") {
8517
- if (!automation.name) ctx.addIssue({ code: "custom", path: ["name"], message: "must not be empty" });
8518
- if (!automation.prompt) ctx.addIssue({ code: "custom", path: ["prompt"], message: "must not be empty" });
8519
- if (automation.triggers.length === 0) ctx.addIssue({ code: "custom", path: ["triggers"], message: "must not be empty" });
8520
- }
8521
- }).transform((automation, ctx) => {
8522
- if (automation.action === "keep" || automation.action === "disable") return automation;
8523
- const content = (automation.action === "update" ? updated : authored).safeParse(automation);
8524
- if (content.success) return { ...automation, ...content.data };
8525
- for (const issue of content.error.issues) ctx.addIssue({ ...issue, code: "custom" });
8526
- return z14.NEVER;
8527
- });
8528
- }
8529
- function automationListSchema(limits) {
8530
- return list(automationSchema(limits)).default([]).superRefine((automations, ctx) => {
8531
- if (new Set(automations.map((automation) => automation.key)).size !== automations.length) {
8532
- ctx.addIssue({ code: "custom", message: "must have unique keys" });
8533
- }
8534
- const targets = automations.flatMap((automation) => automation.automation_id ?? []);
8535
- if (new Set(targets).size !== targets.length) {
8536
- ctx.addIssue({ code: "custom", message: "must mention each existing automation once" });
8537
- }
8538
- if (limits.automations !== void 0 && automations.filter((automation) => automation.action === "create").length > limits.automations) {
8539
- ctx.addIssue({ code: "custom", message: `must create at most ${limits.automations} new automations` });
8540
- }
8541
- });
8542
- }
8543
- function environmentSchema(limits) {
8544
- return z14.object({
8545
- name: optionalText(limits.nameChars).transform((value) => value ?? void 0),
8546
- description: clearableText(limits.descriptionChars),
8547
- system_prompt: clearableText(limits.systemPromptChars),
8548
- start_hook: clearableText(limits.hookChars),
8549
- warm_hook: clearableText(limits.hookChars)
8550
- });
8551
- }
8552
- function variableSchema(limits, requiredDefault) {
8553
- return z14.object({
8554
- key: z14.string().regex(VARIABLE_KEY_RE, "must be a valid environment variable name").max(limits.variableKeyChars ?? Number.POSITIVE_INFINITY),
8555
- description: optionalText(limits.variableDescriptionChars).transform((value) => value ?? ""),
8556
- required: z14.boolean().default(requiredDefault)
8557
- });
8558
- }
8559
- function proposalSchema(limits) {
8560
- return z14.object({
8561
- summary: requiredText(limits.summaryChars),
8562
- stack: list(text(), limits.stackItems).default([]).transform((items) => items.filter(Boolean)),
8563
- environment: environmentSchema(limits),
8564
- variables: list(variableSchema(limits, false), limits.variables).default([]),
8565
- automations: automationListSchema(limits),
8566
- verification: list(z14.object({
8567
- label: requiredText(limits.nameChars),
8568
- status: z14.enum(ENVIRONMENT_SETUP_VERIFICATION_STATUSES),
8569
- detail: optionalText(limits.verificationDetailChars).transform((value) => value ?? void 0)
8570
- }), limits.verificationItems).default([]),
8571
- media: list(z14.object({
8572
- media_id: z14.string().regex(UUID_RE, "must be a media id"),
8573
- title: requiredText(limits.nameChars)
8574
- }), limits.mediaItems).default([])
8575
- });
8576
- }
8577
- var environmentSetupProposalSchema = proposalSchema({});
8578
- var environmentSetupProposalSubmissionSchema = proposalSchema(ENVIRONMENT_SETUP_LIMITS);
8579
- var environmentSetupVariableRequestSchema = variableSchema({}, false).extend({
8580
- status: z14.enum(["pending", "provided", "skipped"]),
8581
- requested_at: z14.string(),
8582
- resolved_at: z14.string().nullable().default(null)
8583
- });
8584
- var environmentSetupRunStateSchema = z14.object({
8585
- status: z14.enum(ENVIRONMENT_SETUP_RUN_STATUSES),
8586
- steps: z14.partialRecord(z14.enum(ENVIRONMENT_SETUP_STEPS.map((step) => step.key)), z14.enum(ENVIRONMENT_SETUP_STEP_STATUSES)).default({}),
8587
- proposal: environmentSetupProposalSchema.nullable().default(null),
8588
- applied: z14.object({
8589
- applied_at: z14.string(),
8590
- automation_ids: z14.array(z14.string())
8591
- }).nullable().default(null),
8592
- variable_requests: z14.array(environmentSetupVariableRequestSchema).default([])
8593
- });
8594
- var applyEnvironmentSetupRequestSchema = z14.object({
8595
- environment: environmentSchema(ENVIRONMENT_SETUP_LIMITS).extend({ name: requiredText(ENVIRONMENT_SETUP_LIMITS.nameChars) }),
8596
- variables: list(z14.object({ key: z14.string().regex(VARIABLE_KEY_RE), value: z14.string() }), ENVIRONMENT_SETUP_LIMITS.variables).default([]).refine((variables) => new Set(variables.map((variable) => variable.key)).size === variables.length, "must have unique keys").transform((variables) => variables.filter((variable) => variable.value.length > 0)),
8597
- automations: automationListSchema(ENVIRONMENT_SETUP_LIMITS)
8598
- });
8599
- var requestEnvironmentSetupVariablesSchema = z14.object({
8600
- variables: list(variableSchema(ENVIRONMENT_SETUP_LIMITS, true), ENVIRONMENT_SETUP_LIMITS.variables).min(1, "must not be empty")
8601
- }).superRefine(({ variables }, ctx) => {
8602
- if (new Set(variables.map((variable) => variable.key)).size !== variables.length) {
8603
- ctx.addIssue({ code: "custom", path: ["variables"], message: "must have unique keys" });
8604
- }
8605
- });
8606
- var respondEnvironmentSetupVariablesSchema = z14.object({
8607
- values: z14.record(z14.string().regex(VARIABLE_KEY_RE), z14.string()).default({}),
8608
- skipped: z14.array(z14.string().regex(VARIABLE_KEY_RE)).default([])
8609
- });
8610
-
8611
8870
  export {
8612
8871
  isRecord,
8613
8872
  isNonEmptyString,
@@ -8748,6 +9007,7 @@ export {
8748
9007
  parseCodeHostPrUrl,
8749
9008
  decodePathSegments,
8750
9009
  buildCodeHostPrUrl,
9010
+ createUuidFromHex,
8751
9011
  MEMORY_ROOT,
8752
9012
  MEMORY_INDEX_FILENAME,
8753
9013
  MEMORY_MARKER_GUIDANCE,
@@ -8811,7 +9071,6 @@ export {
8811
9071
  resolveWarmHookConfig,
8812
9072
  REPLICAS_CONFIG_FILENAMES,
8813
9073
  parseReplicasConfigString,
8814
- createUuidFromHex,
8815
9074
  RELAY_MCP_SERVER_NAME,
8816
9075
  RELAY_MCP_TOOLS,
8817
9076
  RELAY_MCP_TOOL_NAMES,