Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
"ignore": [
"scripts/*.ts",
"tests/**/*.ts",
"src/shared/telemetry/event-catalog.ts"
"src/shared/telemetry/event-catalog.ts",
"src/shared/workers/stacks/**"
],
"ignoreBinaries": [
"nx",
Expand Down
2 changes: 2 additions & 0 deletions apps/cli/src/legacy/cli/root.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { legacyStorageCommand } from "../commands/storage/storage.command.ts";
import { legacyTestCommand } from "../commands/test/test.command.ts";
import { legacyTelemetryCommand } from "../commands/telemetry/telemetry.command.ts";
import { legacyUnlinkCommand } from "../commands/unlink/unlink.command.ts";
import { legacyWorkersCommand } from "../commands/workers/workers.command.ts";
import { legacyVanitySubdomainsCommand } from "../commands/vanity-subdomains/vanity-subdomains.command.ts";
import { OutputFormatFlag } from "../../shared/cli/global-flags.ts";
import { outputLayerFor } from "../../shared/output/output.layer.ts";
Expand Down Expand Up @@ -70,6 +71,7 @@ export const legacyRoot = Command.make("supabase").pipe(
legacyDomainsCommand,
legacyEncryptionCommand,
legacyFunctionsCommand,
legacyWorkersCommand,
legacyGenCommand,
legacyInitCommand,
legacyInspectCommand,
Expand Down
64 changes: 64 additions & 0 deletions apps/cli/src/legacy/commands/workers/new/SIDE_EFFECTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# `supabase workers new [name]`

> **Local-disk only.** Nothing is deployed and no Management API route is
> called; `workers push` is what talks to the platform.

## Files Read

| Path | Format | When |
| ---------------------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------- |
| `<workdir>/supabase/config.toml` | TOML | always, to refuse a worker that is already recorded |
| `<destination>/` | dir | always, to refuse a destination that is not empty |
| `<SUPABASE_HOME or ~/.supabase>/profile` | plain text | when neither `--profile` nor `SUPABASE_PROFILE` is set — names the profile, defaulting to `supabase` |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the telemetry state read

Every handler exit runs telemetryState.flush, whose loadOrCreateLegacyTelemetryState checks and reads <SUPABASE_HOME or ~/.supabase>/telemetry.json when it exists before rewriting it (legacy-telemetry-state.layer.ts:438-478). The Files Read table omits that path even though prior contents determine the retained device, session, consent, and identity state; add the conditional read to keep the command's compatibility checklist complete.

AGENTS.md reference: apps/cli/AGENTS.md:L359-L366

Useful? React with 👍 / 👎.

| `<SUPABASE_PROFILE>` (YAML) | YAML | when `SUPABASE_PROFILE` is a filesystem path rather than a built-in name; a read failure aborts the command |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document profile files selected through --profile

When --profile names a profile YAML file, resolveProfile passes that explicit flag value to legacyLoadProfile, which reads the file and aborts the command if it is unreadable or malformed. This row documents only the equivalent SUPABASE_PROFILE path, so the compatibility checklist omits a flag-driven file read that can prevent any scaffold from being written; include both selectors in the path and condition.

AGENTS.md reference: apps/cli/AGENTS.md:L359-L366

Useful? React with 👍 / 👎.


## Files Written

| Path | Format | When |
| ----------------------------------------------- | ------ | ------------------------------------------------------------------------- |
| `<workdir>/supabase/config.toml` | TOML | always — appends/updates `[workers.<name>]` in place, preserving comments |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the checklist for append-only worker creation

The append-only refactor now rejects every worker already present in the decoded config, so this command never updates an existing table, yet the compatibility checklist still says it “appends/updates” one. The same document consequently retains obsolete statements about resolving a recorded source and failing only when an entry cannot be edited safely; update these descriptions to reflect the unconditional existing-worker refusal because this file is the primary E2E compatibility input.

AGENTS.md reference: apps/cli/AGENTS.md:L359-L366

Useful? React with 👍 / 👎.

| `<workdir>/supabase/workers/<name>/*` | varies | always, unless `--source` names another directory |
| `<workdir>/<source>/*` | varies | when `--source` is given |
Comment thread
johnstonmatt marked this conversation as resolved.
| `<SUPABASE_HOME or ~/.supabase>/telemetry.json` | JSON | always — flushed on success and on failure |

Nothing at the destination is ever removed or overwritten: a destination that
exists and is not empty is refused, and clearing it is left to the user.
`--source` is refused when it resolves to the project root, `supabase/`,
`supabase/functions/`, `supabase/migrations/`, or outside the project. Symlinks
are resolved first, so a path inside the project that points outside it is
refused too. A relative `--source` is resolved against the directory the command
was run in; a `source` recorded in `config.toml` is resolved against the project
root.

## API Routes

| Method | Path | Auth | Request body | Response (used fields) |
| ------ | ---- | ---- | ------------ | ---------------------- |
| — | — | — | — | — |

## Exit Codes

| Code | Condition |
| ---- | --------------------------------------------------------------------- |
| `0` | success |
| `1` | invalid or reserved worker name, unknown runtime/size, bad `--source` |
| `1` | destination exists and is not empty |
| `1` | `config.toml` records a worker in a form that cannot be edited safely |

## Environment Variables

| Variable | Purpose | Required? |
| ----------------------- | ---------------------------------------------------- | ------------------------------------------------------- |
| `SUPABASE_ACCESS_TOKEN` | auth token (bypasses credential file/keyring lookup) | no (falls back to keyring → `~/.supabase/access-token`) |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the nonexistent credential fallback

This local command's runtime builds legacyCliConfigLayer, which consumes SUPABASE_ACCESS_TOKEN but does not build the credentials layer or read either the keyring or ~/.supabase/access-token. Claiming that the variable falls back through those stores makes the compatibility checklist report secret access that never occurs; document it as optional and unused by this local operation, or omit it from the consumed-variable table.

AGENTS.md reference: apps/cli/AGENTS.md:L359-L366

Useful? React with 👍 / 👎.

| `SUPABASE_PROFILE` | built-in profile name or YAML file path | no (falls back to `~/.supabase/profile` -> `supabase`) |
| `SUPABASE_WORKDIR` | project directory the command acts on | no (falls back to `--workdir`, then the ancestor walk) |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge List SUPABASE_PROJECT_ID in the environment table

The command's provided legacyCliConfigLayer reads process.env["SUPABASE_PROJECT_ID"] on every invocation (legacy-cli-config.layer.ts:166-170), even though the resulting project ID is unused by this local operation. Add it to this table and state that it is resolved but unused so the compatibility checklist covers every environment variable the command consumes.

AGENTS.md reference: apps/cli/AGENTS.md:L359-L366

Useful? React with 👍 / 👎.

| `SUPABASE_HOME` | directory holding `telemetry.json` | no (falls back to `~/.supabase`) |

## Telemetry Events Fired

| Event | When | Notable properties / groups |
| ---------------------- | ------------------------------------------ | ----------------------------------- |
| `cli_command_executed` | post-run, success or failure (via wrapper) | `exit_code`, `duration_ms`, `flags` |

No custom events — only the `cli_command_executed` that the instrumentation
wrapper emits for every command.
74 changes: 74 additions & 0 deletions apps/cli/src/legacy/commands/workers/new/new.command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { Layer } from "effect";
import { Argument, Command, Flag } from "effect/unstable/cli";
import type * as CliCommand from "effect/unstable/cli/Command";
import { withJsonErrorHandling } from "../../../../shared/output/json-error-handling.ts";
import { commandRuntimeLayer } from "../../../../shared/runtime/command-runtime.layer.ts";
import { WORKER_RUNTIMES, WORKER_SIZES } from "../../../../shared/workers/worker-runtimes.ts";
import { legacyCliConfigLayer } from "../../../config/legacy-cli-config.layer.ts";
import { legacyDebugLoggerLayer } from "../../../shared/legacy-debug-logger.layer.ts";
import { legacyTelemetryStateLayer } from "../../../telemetry/legacy-telemetry-state.layer.ts";
import { withLegacyCommandInstrumentation } from "../../../telemetry/legacy-command-instrumentation.ts";
import { legacyWorkersNew } from "./new.handler.ts";

const config = {
name: Argument.string("name").pipe(
Argument.withDescription("Worker name. Doubles as its directory, and its hostname."),
),
runtime: Flag.choice("runtime", WORKER_RUNTIMES).pipe(
Comment thread
johnstonmatt marked this conversation as resolved.
Flag.withDescription(
"Runtime to scaffold and record in supabase/config.toml. Prompted when omitted.",
),
Flag.optional,
),
size: Flag.choice("size", WORKER_SIZES).pipe(
Flag.withDescription(
"Instance size to record in supabase/config.toml. Each size implies its own vCPU count, so there is no separate --cpu. Prompted when omitted.",
),
Flag.optional,
),
source: Flag.string("source").pipe(
Flag.withDescription(
"Scaffold the worker here instead of the default workers directory, recorded as `source` in supabase/config.toml.",
),
Flag.optional,
),
} as const;

export type LegacyWorkersNewFlags = CliCommand.Command.Config.Infer<typeof config>;

const cliConfig = legacyCliConfigLayer.pipe(Layer.provide(legacyDebugLoggerLayer));

/** Local-disk only: no Management API, so no platform stack is built. */
const legacyWorkersNewRuntimeLayer = Layer.mergeAll(
cliConfig,
legacyTelemetryStateLayer,
commandRuntimeLayer(["workers", "new"]),
);

export const legacyWorkersNewCommand = Command.make("new", config).pipe(
Command.withDescription(
"Scaffold a worker directory from a runtime's starter files and record the choice in supabase/config.toml. Nothing is deployed.",
),
Command.withShortDescription("Scaffold a worker locally"),
Command.withExamples([
{
command: "supabase workers new",
description: "Scaffold a worker, prompting for runtime and size",
Comment on lines +55 to +56

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include the required worker name in the example

This advertised example cannot run because name is now a required Argument.string rather than an optional argument. Users copying supabase workers new receive a missing-argument parse error before the runtime and size prompts described here; add a worker name to the example.

Useful? React with 👍 / 👎.

},
{
command: "supabase workers new api --runtime node",
description: "Scaffold supabase/workers/api on the node runtime",
},
{
command: "supabase workers new api --source packages/api",
description: "Scaffold the worker outside the workers directory",
},
]),
Command.withHandler((flags) =>
legacyWorkersNew(flags).pipe(
withLegacyCommandInstrumentation({ flags, config }),
withJsonErrorHandling,
),
),
Command.provide(legacyWorkersNewRuntimeLayer),
);
Loading
Loading