diff --git a/.changeset/local-flag.md b/.changeset/local-flag.md new file mode 100644 index 000000000..68f9cb433 --- /dev/null +++ b/.changeset/local-flag.md @@ -0,0 +1,5 @@ +--- +"@taskless/cli": patch +--- + +`--local` is the new name for `--anonymous`. It runs a command in local mode: no Taskless API call, no auth lookup, and only rules that can run without the service. `--anonymous` keeps working as an alias on every command, so existing scripts, CI configs and git hooks need no change, but docs, recipes and the Taskless skill now use `--local`, and messages the CLI prints name it (for example the `check` notice now reads "`--local` was set"). `info --json` still reports `authState: "anonymous"` when the probe is skipped. diff --git a/openspec/changes/archive/2026-12-01-local-flag/.openspec.yaml b/openspec/changes/archive/2026-12-01-local-flag/.openspec.yaml new file mode 100644 index 000000000..785b15074 --- /dev/null +++ b/openspec/changes/archive/2026-12-01-local-flag/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-12-01 diff --git a/openspec/changes/archive/2026-12-01-local-flag/proposal.md b/openspec/changes/archive/2026-12-01-local-flag/proposal.md new file mode 100644 index 000000000..637307a9b --- /dev/null +++ b/openspec/changes/archive/2026-12-01-local-flag/proposal.md @@ -0,0 +1,28 @@ +## Why + +Issue #732 follow-up. `--anonymous` reads as a statement about identity, but what the flag actually selects is a mode: run on this machine, with no Taskless API call, no auth lookup and no verification. A project that chooses to run only local static rules is not trying to be anonymous, it is running locally. `--local` says that. + +## What Changes + +- Every subcommand that accepted `--anonymous` now accepts `--local` with the same per-command behavior. `--local` is the documented name. +- `--anonymous` stays as an alias of `--local`, so existing scripts, CI configs, git hooks and recipes installed by earlier versions keep working unchanged. `--help` lists both, the alias described as `--local`'s original name. +- Text the CLI prints names `--local`: the `check` not-verified notice (`` `--local` was set ``, remedy "run `check` without `--local`"), the `auth login` rejection ("auth commands cannot run in local mode (--local)"), the `rule improve` pointer (`agent improve-rule --local`), `info`'s auth line, and the `agent` topic index. +- The recipes and the Taskless skill use `--local`. The skill notes that `--anonymous` still works. + +Unchanged: `info --json` still reports `authState: "anonymous"` when the probe was skipped, since that value is a machine contract a consumer may match on. The `@taskless/cli/prompts` option `anonymous` and the `.anonymous.md` variant filename are likewise unchanged. They are not user-facing and renaming them would break the export for nothing. + +Requirements elsewhere in the specs that name `--anonymous` stay as they are. The new `cli` requirement makes the two spellings equivalent everywhere, so those requirements hold for `--local` without restating each of them. + +Not breaking: `0.y.z`, nothing is removed. The bump is `patch`. + +## Delivery shape + +**Single PR.** A shared flag definition, its use in each command, the text and recipe updates, the tests and this spec delta are one reviewable change. + +## Impact + +- `packages/cli/src/util/local-flag.ts` (new), `packages/cli/src/commands/{agent,auth,check,info,init,rules}.ts` +- `packages/cli/src/rules/plan-check.ts`, `packages/cli/src/prompts/recipes.ts`, `packages/cli/src/schemas/info.ts` +- `packages/cli/src/agent/*.md`, `skills/taskless/SKILL.md` +- Tests: `local-flag.test.ts` (renamed from `anonymous-flag.test.ts`), `agent-extensions`, `error-envelope`, `runtime-check`, `prompts` +- Specs: `cli`, `cli-auth`, `cli-check` diff --git a/openspec/changes/archive/2026-12-01-local-flag/specs/cli-auth/spec.md b/openspec/changes/archive/2026-12-01-local-flag/specs/cli-auth/spec.md new file mode 100644 index 000000000..0c376ab2e --- /dev/null +++ b/openspec/changes/archive/2026-12-01-local-flag/specs/cli-auth/spec.md @@ -0,0 +1,58 @@ +## MODIFIED Requirements + +### Requirement: Auth login initiates Device Flow + +`taskless auth login` initiates the device-code flow per the existing requirement. The `--local` flag, and its alias `--anonymous` (per the `cli` capability), SHALL NOT be accepted on this command — invocation with either SHALL exit with code 1 and an error message stating "auth commands cannot run in local mode (--local)". + +When a token is already present, `auth login` SHALL decide by where it comes from: + +- A token from `TASKLESS_TOKEN` SHALL be kept without contacting the service, since a saved login would not be used while the variable is set. The CLI SHALL name `TASKLESS_TOKEN` and SHALL NOT direct the user to `auth logout`, which cannot remove it. +- A saved token SHALL be checked with the service. If the service rejects it (`401`), the CLI SHALL run the device-code flow and replace the saved token. If the service accepts it, or cannot be reached, the CLI SHALL keep the token and report that the user is already logged in, since an unreachable service says nothing about the token. + +Keeping a token SHALL NOT be an error: the command exits 0, and under `--json` prints `{ "ok": true, "status": "already_logged_in", "source": "saved" }`, or `"source": "environment"` for `TASKLESS_TOKEN`. + +#### Scenario: Standard login still works + +- **WHEN** a user runs `taskless auth login` +- **THEN** the CLI SHALL initiate the device-code flow per the existing behavior + +#### Scenario: Login rejects --anonymous + +- **WHEN** a user runs `taskless auth login --local` or `taskless auth login --anonymous` +- **THEN** the CLI SHALL exit with code 1 +- **AND** SHALL print "auth commands cannot run in local mode" (or similar) + +#### Scenario: A rejected saved token is replaced + +- **WHEN** `.taskless/.env.local.json` holds a token the service answers with `401`, and `TASKLESS_TOKEN` is not set +- **AND** a user runs `taskless auth login` +- **THEN** the CLI SHALL run the device-code flow +- **AND** on approval SHALL overwrite the saved token with the new one + +#### Scenario: An accepted saved token is kept + +- **WHEN** the saved token is accepted by the service +- **AND** a user runs `taskless auth login` +- **THEN** the CLI SHALL NOT start the device-code flow +- **AND** SHALL report that the user is already logged in and name `auth logout` as the way to re-authenticate + +#### Scenario: An unreachable service keeps the saved token + +- **WHEN** the service cannot be reached to check the saved token +- **AND** a user runs `taskless auth login` +- **THEN** the CLI SHALL keep the saved token and SHALL NOT start the device-code flow + +#### Scenario: A token from TASKLESS_TOKEN is named + +- **WHEN** `TASKLESS_TOKEN` is set +- **AND** a user runs `taskless auth login` +- **THEN** the CLI SHALL NOT contact the service +- **AND** SHALL name `TASKLESS_TOKEN` as the token in use +- **AND** SHALL NOT direct the user to `auth logout` + +#### Scenario: Keeping a token under --json is reported + +- **WHEN** the saved token is accepted by the service +- **AND** a user runs `taskless auth login --json` +- **THEN** stdout SHALL contain `{ "ok": true, "status": "already_logged_in", "source": "saved" }` +- **AND** the exit code SHALL be 0 diff --git a/openspec/changes/archive/2026-12-01-local-flag/specs/cli-check/spec.md b/openspec/changes/archive/2026-12-01-local-flag/specs/cli-check/spec.md new file mode 100644 index 000000000..e3f2bfeed --- /dev/null +++ b/openspec/changes/archive/2026-12-01-local-flag/specs/cli-check/spec.md @@ -0,0 +1,59 @@ +## MODIFIED Requirements + +### Requirement: Check names the remedy when rules run unverified + +Whenever `taskless check` runs rules without verifying them, because `--local` (or its alias `--anonymous`) is set, +no token is available, no GitHub repository URL resolves, or reconciliation cannot complete, +it SHALL emit exactly one notice that says the rules were not verified, states the cause, and +names what would let verification happen. The notice SHALL be emitted whether or not the +project has runtime rules, with one exception: when `--local` is set and the project has no +runtime rules, `check` SHALL emit no not-verified notice, because the person asked for an +unverified run and nothing they wrote was skipped. It SHALL NOT change the exit code. It SHALL be a single line, cause +and remedy together, so that under `--json` it is one entry in the `notices` array; in human +output it SHALL be written to stderr marked as a notice. `--dangerously-run-scripts` is excluded: it carries its own warning. + +The remedy SHALL be specific to the cause: + +- `--local`: run `check` without `--local`. The notice SHALL name `--local` even when the run passed `--anonymous`. +- No token: `taskless auth login`, or a `TASKLESS_TOKEN` where `check` runs in CI. +- No repository URL: which of the three problems applies (not a git repository, no `origin` + remote, or an `origin` that is not GitHub) and the step for that problem. +- A rejected token: re-authenticate with `taskless auth login`, or replace the token. +- `404 organization_not_found`: the same steps `rule create` gives for that code, confirming + the Taskless GitHub App installation covers the repository and re-authenticating with + `taskless auth login`. + +#### Scenario: Logged out with no runtime rules still says so + +- **WHEN** a user runs `taskless check` with no available token in a project with no runtime rules +- **THEN** the CLI SHALL emit one notice that the rules were not verified +- **AND** the notice SHALL name `auth login` +- **AND** the exit code SHALL NOT change because of the notice + +#### Scenario: Anonymous names the flag, not authentication + +- **WHEN** a user runs `taskless check --local` or `taskless check --anonymous` in a project with runtime rules +- **THEN** the notice SHALL name `--local` as the cause and running without it as the remedy +- **AND** the notice SHALL say how many runtime rules did not run + +#### Scenario: Anonymous with no runtime rules prints no notice + +- **WHEN** a user runs `taskless check --local` in a project with no runtime rules +- **THEN** the CLI SHALL emit no not-verified notice, in text output or in the `--json` `notices` array +- **AND** SHALL still scan all local static rules with an unchanged exit code + +#### Scenario: A missing origin is named as such + +- **WHEN** an authenticated `check` runs in a git repository with no `origin` remote +- **THEN** the notice SHALL say the repository has no `origin` remote and how to add one + +#### Scenario: Organization not found carries the installation remedy + +- **WHEN** reconciliation returns `404 organization_not_found` +- **THEN** the notice SHALL name confirming the Taskless GitHub App installation and re-authenticating with `auth login` + +#### Scenario: The notice is a notices entry under --json + +- **WHEN** `taskless check --json` runs unverified +- **THEN** the `notices` array SHALL contain the notice +- **AND** `success`, `results`, and `skipped` SHALL keep their existing meaning diff --git a/openspec/changes/archive/2026-12-01-local-flag/specs/cli/spec.md b/openspec/changes/archive/2026-12-01-local-flag/specs/cli/spec.md new file mode 100644 index 000000000..fb229c288 --- /dev/null +++ b/openspec/changes/archive/2026-12-01-local-flag/specs/cli/spec.md @@ -0,0 +1,59 @@ +## REMOVED Requirements + +### Requirement: CLI accepts global --anonymous flag with per-command behavior + +**Reason**: Renamed to `--local`, which names the mode the flag selects. Replaced by "CLI accepts global --local flag with --anonymous as its alias". + +**Migration**: None needed. `--anonymous` keeps working as an alias of `--local`; new scripts and docs should use `--local`. + +## ADDED Requirements + +### Requirement: CLI accepts global --local flag with --anonymous as its alias + +The CLI SHALL accept a top-level boolean flag `--local` on every subcommand. The flag's behavior SHALL vary by command: + +- `rule create`, `rule improve`: switch to local-only flow (no API calls); SHALL be the only way to reach the local-only path +- `rule delete`, `rule verify`, `rule meta`, `check`, `auth logout`, `init`, `update`: accepted as no-op; SHALL succeed without changing behavior +- `info`: skip the API/auth probe; report local state only (CLI version, skills installed, no auth call) +- `auth login`: SHALL exit with code 1 and an error message stating "auth commands cannot run in local mode" + +The CLI SHALL also accept `--anonymous`, the flag's original name, as an alias of `--local` on every subcommand that accepts `--local`. Passing either spelling, or both, SHALL select exactly the same behavior. Wherever a requirement in any capability names `--anonymous`, it SHALL apply identically when `--local` is passed. + +Text the CLI prints that names the flag (notices, errors, pointers to a recipe, the `agent` topic index) SHALL name `--local`, whichever spelling was passed. `--help` SHALL list both flags, and SHALL NOT render the alias with a single dash. + +The `info --json` `authState` value for a skipped probe SHALL remain `"anonymous"`, since it is a machine contract and not a flag name. + +The flag SHALL be recognized whether placed before or after positional arguments (per `citty` parsing). + +#### Scenario: --local on rule create switches to local flow + +- **WHEN** a user runs `taskless rule create --from req.json --local` +- **THEN** the CLI SHALL execute the local-only branch (no API calls) +- **AND** SHALL produce the same output shape as the API-backed branch + +#### Scenario: --local on check is a no-op + +- **WHEN** a user runs `taskless check --local` +- **THEN** the CLI SHALL execute identically to `taskless check` (no warning, no error) + +#### Scenario: --local on info skips API probe + +- **WHEN** a user runs `taskless info --local` +- **THEN** the CLI SHALL report local state only (CLI version, installed skills, scaffold version) +- **AND** SHALL NOT make any HTTP request to verify auth state + +#### Scenario: --local on auth login is rejected + +- **WHEN** a user runs `taskless auth login --local` +- **THEN** the CLI SHALL exit with code 1 +- **AND** SHALL print an error message stating "auth commands cannot run in local mode" + +#### Scenario: --anonymous still selects local mode + +- **WHEN** a user runs any subcommand with `--anonymous` in place of `--local` +- **THEN** the CLI SHALL behave exactly as it does with `--local` + +#### Scenario: Printed text names --local + +- **WHEN** a user runs `taskless rule improve --anonymous` +- **THEN** the pointer the CLI prints SHALL name `agent improve-rule --local` diff --git a/openspec/changes/archive/2026-12-01-local-flag/tasks.md b/openspec/changes/archive/2026-12-01-local-flag/tasks.md new file mode 100644 index 000000000..5e45479be --- /dev/null +++ b/openspec/changes/archive/2026-12-01-local-flag/tasks.md @@ -0,0 +1,14 @@ +## 1. Flag + +- [x] 1.1 Add `localModeFlags` / `isLocalMode` in `src/util/local-flag.ts`, declaring `--local` and `--anonymous` as separate citty args (citty renders an `alias` with one dash) +- [x] 1.2 Use them in `agent`, `auth login`, `auth logout`, `check`, `info`, `init`, `update`, `rule create`, `rule improve`, `rule meta`, `rule delete` +- [x] 1.3 Name `--local` in the check notice, the auth rejection, the rule pointers, `info`'s auth line, the agent index and the recipe fetch line + +## 2. Docs + +- [x] 2.1 Recipes and `skills/taskless/SKILL.md` use `--local`; the skill notes the alias + +## 3. Tests + +- [x] 3.1 Rename the flag matrix to `local-flag.test.ts` and drive it with `--local` +- [x] 3.2 Cover the `--anonymous` alias for `info`, `auth login`, `rule create`, `rule improve`, `agent`, `check`, and `--help` diff --git a/openspec/specs/cli-auth/spec.md b/openspec/specs/cli-auth/spec.md index 4a2c48c1b..2ac0ec997 100644 --- a/openspec/specs/cli-auth/spec.md +++ b/openspec/specs/cli-auth/spec.md @@ -17,7 +17,7 @@ The CLI SHALL register an `auth` subcommand group with `login` and `logout` as n ### Requirement: Auth login initiates Device Flow -`taskless auth login` initiates the device-code flow per the existing requirement. The new `--anonymous` flag (per the `cli` capability) SHALL NOT be accepted on this command — invocation with `--anonymous` SHALL exit with code 1 and an error message stating "auth commands cannot be anonymous". +`taskless auth login` initiates the device-code flow per the existing requirement. The `--local` flag, and its alias `--anonymous` (per the `cli` capability), SHALL NOT be accepted on this command — invocation with either SHALL exit with code 1 and an error message stating "auth commands cannot run in local mode (--local)". When a token is already present, `auth login` SHALL decide by where it comes from: @@ -33,9 +33,9 @@ Keeping a token SHALL NOT be an error: the command exits 0, and under `--json` p #### Scenario: Login rejects --anonymous -- **WHEN** a user runs `taskless auth login --anonymous` +- **WHEN** a user runs `taskless auth login --local` or `taskless auth login --anonymous` - **THEN** the CLI SHALL exit with code 1 -- **AND** SHALL print "auth commands cannot be anonymous" (or similar) +- **AND** SHALL print "auth commands cannot run in local mode" (or similar) #### Scenario: A rejected saved token is replaced diff --git a/openspec/specs/cli-check/spec.md b/openspec/specs/cli-check/spec.md index c9dc3659b..97cab5705 100644 --- a/openspec/specs/cli-check/spec.md +++ b/openspec/specs/cli-check/spec.md @@ -798,11 +798,11 @@ nothing to report. ### Requirement: Check names the remedy when rules run unverified -Whenever `taskless check` runs rules without verifying them, because `--anonymous` is set, +Whenever `taskless check` runs rules without verifying them, because `--local` (or its alias `--anonymous`) is set, no token is available, no GitHub repository URL resolves, or reconciliation cannot complete, it SHALL emit exactly one notice that says the rules were not verified, states the cause, and names what would let verification happen. The notice SHALL be emitted whether or not the -project has runtime rules, with one exception: when `--anonymous` is set and the project has no +project has runtime rules, with one exception: when `--local` is set and the project has no runtime rules, `check` SHALL emit no not-verified notice, because the person asked for an unverified run and nothing they wrote was skipped. It SHALL NOT change the exit code. It SHALL be a single line, cause and remedy together, so that under `--json` it is one entry in the `notices` array; in human @@ -810,7 +810,7 @@ output it SHALL be written to stderr marked as a notice. `--dangerously-run-scri The remedy SHALL be specific to the cause: -- `--anonymous`: run `check` without `--anonymous`. +- `--local`: run `check` without `--local`. The notice SHALL name `--local` even when the run passed `--anonymous`. - No token: `taskless auth login`, or a `TASKLESS_TOKEN` where `check` runs in CI. - No repository URL: which of the three problems applies (not a git repository, no `origin` remote, or an `origin` that is not GitHub) and the step for that problem. @@ -828,13 +828,13 @@ The remedy SHALL be specific to the cause: #### Scenario: Anonymous names the flag, not authentication -- **WHEN** a user runs `taskless check --anonymous` in a project with runtime rules -- **THEN** the notice SHALL name `--anonymous` as the cause and running without it as the remedy +- **WHEN** a user runs `taskless check --local` or `taskless check --anonymous` in a project with runtime rules +- **THEN** the notice SHALL name `--local` as the cause and running without it as the remedy - **AND** the notice SHALL say how many runtime rules did not run #### Scenario: Anonymous with no runtime rules prints no notice -- **WHEN** a user runs `taskless check --anonymous` in a project with no runtime rules +- **WHEN** a user runs `taskless check --local` in a project with no runtime rules - **THEN** the CLI SHALL emit no not-verified notice, in text output or in the `--json` `notices` array - **AND** SHALL still scan all local static rules with an unchanged exit code diff --git a/openspec/specs/cli/spec.md b/openspec/specs/cli/spec.md index 997c11be9..8f09a37fb 100644 --- a/openspec/specs/cli/spec.md +++ b/openspec/specs/cli/spec.md @@ -345,40 +345,6 @@ The CLI SHALL use `citty` as its sole argument parsing dependency. Each subcomma - **WHEN** inspecting `packages/cli/package.json` - **THEN** `citty` SHALL be listed in `dependencies` -### Requirement: CLI accepts global --anonymous flag with per-command behavior - -The CLI SHALL accept a top-level boolean flag `--anonymous` on every subcommand. The flag's behavior SHALL vary by command: - -- `rule create`, `rule improve`: switch to local-only flow (no API calls); SHALL be the only way to reach the local-only path -- `rule delete`, `rule verify`, `rule meta`, `check`, `auth logout`, `init`, `update`: accepted as no-op; SHALL succeed without changing behavior -- `info`: skip the API/auth probe; report local state only (CLI version, skills installed, no auth call) -- `auth login`: SHALL exit with code 1 and an error message stating "auth commands cannot be anonymous" - -The flag SHALL be recognized whether placed before or after positional arguments (per `citty` parsing). - -#### Scenario: --anonymous on rule create switches to local flow - -- **WHEN** a user runs `taskless rule create --from req.json --anonymous` -- **THEN** the CLI SHALL execute the local-only branch (no API calls) -- **AND** SHALL produce the same output shape as the API-backed branch - -#### Scenario: --anonymous on check is a no-op - -- **WHEN** a user runs `taskless check --anonymous` -- **THEN** the CLI SHALL execute identically to `taskless check` (no warning, no error) - -#### Scenario: --anonymous on info skips API probe - -- **WHEN** a user runs `taskless info --anonymous` -- **THEN** the CLI SHALL report local state only (CLI version, installed skills, scaffold version) -- **AND** SHALL NOT make any HTTP request to verify auth state - -#### Scenario: --anonymous on auth login is rejected - -- **WHEN** a user runs `taskless auth login --anonymous` -- **THEN** the CLI SHALL exit with code 1 -- **AND** SHALL print an error message stating "auth commands cannot be anonymous" - ### Requirement: Error output uses stable codes when --json is set When any CLI command exits with an error AND `--json` was passed, the command SHALL output a JSON envelope with the shape: @@ -713,3 +679,53 @@ The package `bin` SHALL be a separate built file from the CLI entry. It SHALL co - **WHEN** the running Node satisfies `engines.node` - **THEN** the `bin` SHALL run the CLI with every argument unchanged + +### Requirement: CLI accepts global --local flag with --anonymous as its alias + +The CLI SHALL accept a top-level boolean flag `--local` on every subcommand. The flag's behavior SHALL vary by command: + +- `rule create`, `rule improve`: switch to local-only flow (no API calls); SHALL be the only way to reach the local-only path +- `rule delete`, `rule verify`, `rule meta`, `check`, `auth logout`, `init`, `update`: accepted as no-op; SHALL succeed without changing behavior +- `info`: skip the API/auth probe; report local state only (CLI version, skills installed, no auth call) +- `auth login`: SHALL exit with code 1 and an error message stating "auth commands cannot run in local mode" + +The CLI SHALL also accept `--anonymous`, the flag's original name, as an alias of `--local` on every subcommand that accepts `--local`. Passing either spelling, or both, SHALL select exactly the same behavior. Wherever a requirement in any capability names `--anonymous`, it SHALL apply identically when `--local` is passed. + +Text the CLI prints that names the flag (notices, errors, pointers to a recipe, the `agent` topic index) SHALL name `--local`, whichever spelling was passed. `--help` SHALL list both flags, and SHALL NOT render the alias with a single dash. + +The `info --json` `authState` value for a skipped probe SHALL remain `"anonymous"`, since it is a machine contract and not a flag name. + +The flag SHALL be recognized whether placed before or after positional arguments (per `citty` parsing). + +#### Scenario: --local on rule create switches to local flow + +- **WHEN** a user runs `taskless rule create --from req.json --local` +- **THEN** the CLI SHALL execute the local-only branch (no API calls) +- **AND** SHALL produce the same output shape as the API-backed branch + +#### Scenario: --local on check is a no-op + +- **WHEN** a user runs `taskless check --local` +- **THEN** the CLI SHALL execute identically to `taskless check` (no warning, no error) + +#### Scenario: --local on info skips API probe + +- **WHEN** a user runs `taskless info --local` +- **THEN** the CLI SHALL report local state only (CLI version, installed skills, scaffold version) +- **AND** SHALL NOT make any HTTP request to verify auth state + +#### Scenario: --local on auth login is rejected + +- **WHEN** a user runs `taskless auth login --local` +- **THEN** the CLI SHALL exit with code 1 +- **AND** SHALL print an error message stating "auth commands cannot run in local mode" + +#### Scenario: --anonymous still selects local mode + +- **WHEN** a user runs any subcommand with `--anonymous` in place of `--local` +- **THEN** the CLI SHALL behave exactly as it does with `--local` + +#### Scenario: Printed text names --local + +- **WHEN** a user runs `taskless rule improve --anonymous` +- **THEN** the pointer the CLI prints SHALL name `agent improve-rule --local` diff --git a/packages/cli/src/agent/auth.md b/packages/cli/src/agent/auth.md index 7219cf4dc..4c71aeecb 100644 --- a/packages/cli/src/agent/auth.md +++ b/packages/cli/src/agent/auth.md @@ -68,8 +68,8 @@ If the token comes from the `TASKLESS_TOKEN` environment variable, saved login would not be used while the variable is set. Tell the user to replace or unset `TASKLESS_TOKEN`. -The `--anonymous` flag is rejected on `auth login`, it errors with -"auth commands cannot be anonymous". Don't pass it. +The `--local` flag is rejected on `auth login`, it errors with +"auth commands cannot run in local mode (--local)". Don't pass it. ### Logout @@ -111,7 +111,7 @@ report. | code | meaning | fix | |-----------------|--------------------------------------------------------------------------------------|--------------------------------------| -| `INVALID_INPUT` | `--anonymous` passed to `auth login` (rejected: auth commands cannot be anonymous) | Don't pass `--anonymous` | +| `INVALID_INPUT` | `--local` passed to `auth login` (rejected: auth commands cannot run in local mode) | Don't pass `--local` | | `NETWORK_ERROR` | Device flow / token endpoint unreachable. The pending login is kept | Check connectivity; run it again | | `AUTH_EXPIRED` | The code expired before the user approved it | Run it again; show the new URL/code | | `AUTH_REQUIRED` | The user denied the request, or `auth logout` or another login cancelled it | Ask the user; run it again to retry | diff --git a/packages/cli/src/agent/check.md b/packages/cli/src/agent/check.md index ea2e53c12..b0973b99c 100644 --- a/packages/cli/src/agent/check.md +++ b/packages/cli/src/agent/check.md @@ -24,7 +24,7 @@ in CI (diff-only scan), or after rule create/improve to validate. any repository. Use it when the question is "how many", not "where". - `--rule `: run only the named rule (its directory name); repeatable. Works with `--json` and `--summary`. -- `--anonymous`: run only static rules; skip runtime rules. +- `--local`: run only static rules; skip runtime rules. - `--dangerously-run-scripts`: run runtime `check.ts` unverified. - `--timeout `: per-runtime-check wall-clock bound (default 10). - `--preserve-logs` / `-l`: keep this run's directory under @@ -180,12 +180,12 @@ logged in: `check` also exits 1 if the service's answer leaves out a rule it was asked about, or if two engines hold a rule with the same id. -- **Logged out, `--anonymous`, no GitHub remote, or service +- **Logged out, `--local`, no GitHub remote, or service unavailable**: nothing is verified. ast-grep and Vale rules run as they are on disk, runtime rules are **skipped** (reported, never run), and the exit code is unaffected. `check` prints ONE notice saying the rules were not verified and naming the fix: `%(TASKLESS_CLI)s auth login` (or - a `TASKLESS_TOKEN` secret in CI), dropping `--anonymous`, the specific + a `TASKLESS_TOKEN` secret in CI), dropping `--local`, the specific remote problem, or the GitHub App installation. It prints whether or not the project has runtime rules, because the static rules ran unverified either way. Pass the fix on to the user rather than ignoring it. diff --git a/packages/cli/src/agent/ci.md b/packages/cli/src/agent/ci.md index f41bde1da..cf74d5466 100644 --- a/packages/cli/src/agent/ci.md +++ b/packages/cli/src/agent/ci.md @@ -146,7 +146,7 @@ beyond a clean pass, "No rules configured", and findings (step 3): or `entitlement.withheld` under `--json`) → tell the user CI will fail until the organization's plan includes runtime rules. This is not a findings failure and editing the rules will not fix it. Do not - add `--anonymous` or `--dangerously-run-scripts` to the CI command to + add `--local` or `--dangerously-run-scripts` to the CI command to get green; both hide that the rules are not running. - A rule reported as edited (`failures` names it; `integrity` lists it as `unsafe`) → CI will fail until it is put back. Run diff --git a/packages/cli/src/agent/create-sg-rule.md b/packages/cli/src/agent/create-sg-rule.md index 40b7c4bc3..e56b6e86e 100644 --- a/packages/cli/src/agent/create-sg-rule.md +++ b/packages/cli/src/agent/create-sg-rule.md @@ -53,7 +53,7 @@ whole rule. 3. **Check for an existing rule that already covers this.** Scan `.taskless/rules/sg/` and read each rule's `message`, `note`, and `rule` fields. If one overlaps, show the user and ask whether they - would rather improve it, `%(RECIPE_FETCH)simprove-rule --anonymous` + would rather improve it, `%(RECIPE_FETCH)simprove-rule --local` iterates a rule locally. 4. **Author the rule in the canonical shape.** Write the rule to diff --git a/packages/cli/src/agent/hooks.md b/packages/cli/src/agent/hooks.md index 7a8fc16cf..940e12b8a 100644 --- a/packages/cli/src/agent/hooks.md +++ b/packages/cli/src/agent/hooks.md @@ -194,7 +194,7 @@ What the hook runs depends on the developer's login, as for any Logged in, `check` verifies the rules with the Taskless service, a network call on every commit, and runs the runtime rules that pass. Logged out, it runs ast-grep and Vale rules and skips runtime ones. If that -network call makes commits too slow, `--anonymous` skips it, and with +network call makes commits too slow, `--local` skips it, and with it the runtime rules and the edited-rule check; that is the user's call, and CI with a token stays the backstop. Never add `--dangerously-run-scripts`: it executes rule code nobody verified, diff --git a/packages/cli/src/agent/improve-rule.anonymous.md b/packages/cli/src/agent/improve-rule.anonymous.md index f08c191f2..6413c5292 100644 --- a/packages/cli/src/agent/improve-rule.anonymous.md +++ b/packages/cli/src/agent/improve-rule.anonymous.md @@ -1,4 +1,4 @@ -# Topic: improve-rule (anonymous) (CLI v%(CLI_VERSION)s / topic v8) +# Topic: improve-rule (local mode) (CLI v%(CLI_VERSION)s / topic v8) %(ONE_COMMAND_PER_CALL)s @@ -78,10 +78,10 @@ from. ## Important Notes -- Rules created in anonymous mode have no metadata sidecar: that's +- Rules created in local mode have no metadata sidecar: that's fine. This recipe doesn't need or write metadata. - If the rule was originally created via the API path (has metadata), - you can still use this anonymous recipe to iterate locally. The + you can still use this local-mode recipe to iterate locally. The metadata sidecar is preserved untouched. - Do NOT make any HTTP requests to taskless.io. diff --git a/packages/cli/src/agent/improve-rule.md b/packages/cli/src/agent/improve-rule.md index 853d5450a..0cb07cfe0 100644 --- a/packages/cli/src/agent/improve-rule.md +++ b/packages/cli/src/agent/improve-rule.md @@ -10,7 +10,7 @@ is to gather the right rule id + guidance + supporting references and to report the result. If the user wants the local-only flow (no API call), fetch -`%(TASKLESS_CLI)s agent improve-rule --anonymous` instead. +`%(TASKLESS_CLI)s agent improve-rule --local` instead. ## Preconditions - User is logged in. @@ -25,7 +25,7 @@ If the user wants the local-only flow (no API call), fetch (for example `no-eval-3fa9c21b`), which is what the iterate endpoint is addressed by. A rule you wrote locally, or one generated before CLI 0.12.0, is not known to the service: improving it fails with - `RULE_NOT_FOUND`, so fetch the anonymous variant instead. + `RULE_NOT_FOUND`, so fetch the local-mode variant instead. ## Steps @@ -154,7 +154,7 @@ When `--json` is set, failures emit `{ ok: false, code, message }`: | `NO_ORIGIN_REMOTE` | git repository, no `origin` | tell the user; `auth login` cannot fix it | | `UNSUPPORTED_REMOTE_HOST`| `origin` is not GitHub | tell the user; `auth login` cannot fix it | | `INVALID_INPUT` | `--from` JSON failed validation | re-read input schema, fix, retry | -| `RULE_NOT_FOUND` | the service did not issue this rule | re-check the directory name; a local or pre-0.12.0 rule needs the anonymous flow | +| `RULE_NOT_FOUND` | the service did not issue this rule | re-check the directory name; a local or pre-0.12.0 rule needs the local-mode flow | | `NETWORK_ERROR` | API submit/poll failed | the CLI already retried transient failures. If the message names a `--resume` command, run that to keep waiting on the same request; re-running with `--from` submits a NEW request, so confirm with the user first | | `CLI_UPGRADE_REQUIRED` | the service no longer serves this CLI version | tell the user to upgrade with the command in `message`; do not retry | | `RULE_GENERATION_FAILED` | API returned a generation failure | report; suggest enriching guidance/references | @@ -163,6 +163,6 @@ When `--json` is set, failures emit `{ ok: false, code, message }`: ## See Also -- `%(TASKLESS_CLI)s agent improve-rule --anonymous`: local-only flow +- `%(TASKLESS_CLI)s agent improve-rule --local`: local-only flow - `%(TASKLESS_CLI)s agent route`: make a new rule from scratch - `%(TASKLESS_CLI)s agent check`: validate the updated rule diff --git a/packages/cli/src/agent/info.md b/packages/cli/src/agent/info.md index f34ddf90d..145b41b29 100644 --- a/packages/cli/src/agent/info.md +++ b/packages/cli/src/agent/info.md @@ -4,7 +4,7 @@ ## Goal Report local Taskless state: CLI version, installed skill versions -per detected tool, and (unless `--anonymous`) the user's auth state. +per detected tool, and (unless `--local`) the user's auth state. Used as a health check, for staleness detection, and to confirm which version of the CLI/skills the agent is talking to. @@ -18,9 +18,9 @@ which version of the CLI/skills the agent is talking to. %(TASKLESS_CLI)s info --json ``` For an offline/local-only state report (no auth probe), pass - `--anonymous`: + `--local`: ``` - %(TASKLESS_CLI)s info --json --anonymous + %(TASKLESS_CLI)s info --json --local ``` 2. **Parse the response.** Shape: @@ -83,7 +83,7 @@ which version of the CLI/skills the agent is talking to. | `unreachable` | the service could not be reached | the token is unverified, not bad; try again later | | `upgrade_required` | the service no longer supports this CLI version | upgrade the CLI before anything that needs the service | | `none` | no token | not logged in | - | `anonymous` | `--anonymous` skipped the probe | nothing; auth was not checked | + | `anonymous` | `--local` skipped the probe | nothing; auth was not checked | Do not send the user to log in for `unreachable`: their login may be fine, and logging in again cannot fix an outage. diff --git a/packages/cli/src/agent/rule.md b/packages/cli/src/agent/rule.md index bcada3531..deaf46ba8 100644 --- a/packages/cli/src/agent/rule.md +++ b/packages/cli/src/agent/rule.md @@ -25,7 +25,7 @@ takes the rule's id, which is its directory name under names the `create-*-rule` topic that fits, so you do not pick an engine yourself. -For the local-only flow on improve, append `--anonymous`. +For the local-only flow on improve, append `--local`. ## See Also diff --git a/packages/cli/src/commands/agent.ts b/packages/cli/src/commands/agent.ts index 93d590b8b..90a856250 100644 --- a/packages/cli/src/commands/agent.ts +++ b/packages/cli/src/commands/agent.ts @@ -32,6 +32,7 @@ import { processLauncherContext, projectLauncher, } from "../util/package-manager"; +import { isLocalMode, localModeFlags } from "../util/local-flag"; // Recipe-only topics (no backing subcommand) that should still be // discoverable from the `taskless agent` index. The rule-authoring front @@ -127,7 +128,7 @@ const REFUSED_TOOLS = new Map([ "black", "it is a formatter and holds no rules; decide again with `agent route`.", ], - ["anonymous", "pass `--anonymous` for the local-only variant."], + ["anonymous", "pass `--local` for the local-only variant."], ]); export function createAgentCommand(subCommands: SubCommandsDef) { @@ -143,12 +144,9 @@ export function createAgentCommand(subCommands: SubCommandsDef) { description: "Working directory", default: process.cwd(), }, - anonymous: { - type: "boolean", - description: - "Return the local-only recipe variant when the topic has one", - default: false, - }, + ...localModeFlags( + "Return the local-only recipe variant when the topic has one" + ), tool: { type: "string", description: @@ -168,7 +166,7 @@ export function createAgentCommand(subCommands: SubCommandsDef) { }, async run({ args, rawArgs }) { // Extract positional args from rawArgs, skipping flags and their values. - // --dir/-d/--tool/--section take a value; --json/--anonymous/--full are + // --dir/-d/--tool/--section take a value; --json/--local/--anonymous/--full are // boolean and do not. const valueFlagSet = new Set(["--dir", "-d", "--tool", "--section"]); const positionals: string[] = []; @@ -242,7 +240,7 @@ export function createAgentCommand(subCommands: SubCommandsDef) { } console.log( - "\nAppend `--anonymous` to any rule/check command to skip the Taskless API" + "\nAppend `--local` to any rule/check command to skip the Taskless API" ); console.log("and use local-only behavior."); const prefix = getCliPrefix(); @@ -304,7 +302,7 @@ export function createAgentCommand(subCommands: SubCommandsDef) { } // Anonymous variant lookup: prefer .anonymous.md when - // --anonymous is set, fall back to the canonical recipe. The lookup and + // --local (or its alias --anonymous) is set, fall back to the canonical recipe. The lookup and // the render both live in the shared prompts module, so `agent` and the // `@taskless/cli/prompts` export emit the same text. // @@ -320,7 +318,10 @@ export function createAgentCommand(subCommands: SubCommandsDef) { // template is asked (`variables` comes from sprintf's own parse) rather // than a topic name being hardcoded, so the next recipe to use the // mechanism needs no edit here. - const template = getRawRecipe(key, { anonymous: args.anonymous, tool }); + const template = getRawRecipe(key, { + anonymous: isLocalMode(args), + tool, + }); const hostTools = template?.variables.some((name) => HOST_TOOL_VARIABLES.has(name) ) @@ -365,7 +366,7 @@ export function createAgentCommand(subCommands: SubCommandsDef) { const served = getServedRecipe( key, { - anonymous: args.anonymous, + anonymous: isLocalMode(args), tool, invocation, hostTools, diff --git a/packages/cli/src/commands/auth.ts b/packages/cli/src/commands/auth.ts index 09375615e..7863177ec 100644 --- a/packages/cli/src/commands/auth.ts +++ b/packages/cli/src/commands/auth.ts @@ -12,6 +12,7 @@ import { getTelemetry, type TelemetryClient } from "../telemetry"; import { type CLIErrorCode, writeJsonError } from "../types/errors"; import { splitRawArguments } from "../util/argv"; import { getCliPrefix } from "../util/package-manager"; +import { isLocalMode, localModeFlags } from "../util/local-flag"; type FailedLoginStep = Extract< Awaited>, @@ -95,11 +96,7 @@ const loginCommand = defineCommand({ alias: "d", description: "Working directory", }, - anonymous: { - type: "boolean", - description: "Rejected: auth commands cannot be anonymous", - default: false, - }, + ...localModeFlags("Rejected: auth commands cannot run in local mode"), json: { type: "boolean", description: @@ -121,8 +118,11 @@ const loginCommand = defineCommand({ process.exitCode = 1; }; - if (args.anonymous) { - fail("INVALID_INPUT", "auth commands cannot be anonymous."); + if (isLocalMode(args)) { + fail( + "INVALID_INPUT", + "auth commands cannot run in local mode (--local)." + ); return; } @@ -226,11 +226,7 @@ const logoutCommand = defineCommand({ alias: "d", description: "Working directory", }, - anonymous: { - type: "boolean", - description: "Accepted for compatibility; logout is already local", - default: false, - }, + ...localModeFlags("Accepted for compatibility; logout is already local"), json: { type: "boolean", description: diff --git a/packages/cli/src/commands/check.ts b/packages/cli/src/commands/check.ts index 5cd8ea252..d30e789c7 100644 --- a/packages/cli/src/commands/check.ts +++ b/packages/cli/src/commands/check.ts @@ -32,6 +32,7 @@ import { getCliPrefix, processLauncherContext, } from "../util/package-manager"; +import { isLocalMode, localModeFlags } from "../util/local-flag"; import { environmentNotice, environmentSteps, @@ -244,12 +245,9 @@ export const checkCommand = defineCommand({ description: "Output as JSON", default: false, }, - anonymous: { - type: "boolean", - description: - "Run only trusted static rules; skip runtime rules (no reconciliation)", - default: false, - }, + ...localModeFlags( + "Run only trusted static rules; skip runtime rules (no reconciliation)" + ), "dangerously-run-scripts": { type: "boolean", description: @@ -519,7 +517,7 @@ export const checkCommand = defineCommand({ try { const { plan, dispatched, runDirectory } = await scanProject(cwd, { paths: existingPaths, - anonymous: args.anonymous, + anonymous: isLocalMode(args), dangerouslyRunScripts: Boolean(args["dangerously-run-scripts"]), ...(selection === undefined ? {} : { selection }), runtimeTimeoutMs: parseTimeoutMs(args.timeout), diff --git a/packages/cli/src/commands/info.ts b/packages/cli/src/commands/info.ts index 6e143cdba..5551a36a7 100644 --- a/packages/cli/src/commands/info.ts +++ b/packages/cli/src/commands/info.ts @@ -13,6 +13,7 @@ import { } from "../schemas/info"; import { makeErrorEnvelope } from "../types/errors"; import { resolveRepositoryContext } from "../util/git-remote"; +import { isLocalMode, localModeFlags } from "../util/local-flag"; import { readManifest } from "../filesystem/manifest"; import { reconcileReport, reconcileStatus } from "../rules/reconcile-status"; import { TASKLESS_DIRECTORY } from "../rules/vale/formats"; @@ -46,7 +47,7 @@ function describeAuth( return "not logged in"; } case "anonymous": { - return "not checked (--anonymous)"; + return "not checked (--local)"; } } } @@ -67,16 +68,12 @@ export const infoCommand = defineCommand({ description: "Output as JSON", default: false, }, - anonymous: { - type: "boolean", - description: "Skip the API/auth probe and report local state only", - default: false, - }, + ...localModeFlags("Skip the API/auth probe and report local state only"), }, async run({ args }) { const cwd = resolve(args.dir ?? process.cwd()); - // The repository context resolves regardless of `--anonymous`: it comes + // The repository context resolves regardless of `--local`: it comes // from the local git remote, not from the API, so suppressing it would // hide capability state that has nothing to do with the auth probe. const [harnesses, tools, token, repository, manifest, pinnedCli] = @@ -86,7 +83,7 @@ export const infoCommand = defineCommand({ // context, which is the same never-throwing call as `repository` below // and cheap enough not to be worth threading through. detectHostTools(cwd), - args.anonymous ? Promise.resolve() : getToken(cwd), + isLocalMode(args) ? Promise.resolve() : getToken(cwd), resolveRepositoryContext(cwd), // Never fails: an absent or unreadable manifest is an ordinary state for // a project that has not been initialised, and `info` still has plenty @@ -107,7 +104,7 @@ export const infoCommand = defineCommand({ let auth: { user: string; email?: string; orgs: string[] } | undefined; let authState: AuthState; let unreachableReason: string | undefined; - if (args.anonymous) { + if (isLocalMode(args)) { authState = "anonymous"; } else if (token === undefined) { authState = "none"; diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index d8235e6c9..2a5d35eaf 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -69,6 +69,7 @@ import { TASKLESS_DIRECTORY } from "../rules/vale/formats"; import { CLIError } from "../util/cli-error"; import { getWizardHint, shouldLaunchWizard } from "../util/interactive"; import { buildInvocation } from "../util/invocation"; +import { isLocalMode, localModeFlags } from "../util/local-flag"; import { makeErrorEnvelope } from "../types/errors"; export const initCommand = defineCommand({ @@ -88,11 +89,9 @@ export const initCommand = defineCommand({ "Emit the install result as JSON, including what a migration moved", default: false, }, - anonymous: { - type: "boolean", - description: "Accepted for compatibility; init has no auth dependency", - default: false, - }, + ...localModeFlags( + "Accepted for compatibility; init has no auth dependency" + ), }, // `init` is the batch install in every context: an agent, a script, a CI // job, and a person upgrading without prompts all run the same thing. The @@ -295,11 +294,9 @@ export const updateCommand = defineCommand({ "Output as JSON: the recipe plus where the walk starts, or the stamped result with --rules", default: false, }, - anonymous: { - type: "boolean", - description: "Accepted for compatibility; update has no auth dependency", - default: false, - }, + ...localModeFlags( + "Accepted for compatibility; update has no auth dependency" + ), }, async run({ args }) { const cwd = resolve(args.dir ?? process.cwd()); @@ -312,7 +309,7 @@ export const updateCommand = defineCommand({ // The outline `agent update` serves, so the two spellings stay one // text: the walk, then the sections printed on request (taskless/cli#672). const recipe = getServedRecipeText("update", { - anonymous: args.anonymous, + anonymous: isLocalMode(args), invocation: detectCliInvocation(processLauncherContext()), directive: true, }); diff --git a/packages/cli/src/commands/rules.ts b/packages/cli/src/commands/rules.ts index 02a81521d..159f8bfdc 100644 --- a/packages/cli/src/commands/rules.ts +++ b/packages/cli/src/commands/rules.ts @@ -54,6 +54,7 @@ import { CLIError } from "../util/cli-error"; import { formatZodIssues, readJsonInput } from "../util/json-input"; import { type CLIErrorCode, writeJsonError } from "../types/errors"; import { getCliPrefix } from "../util/package-manager"; +import { isLocalMode, localModeFlags } from "../util/local-flag"; /** Why submitting a request or an iteration failed, as a message and a code. */ function describeSubmitFailure( @@ -345,12 +346,9 @@ const createCommand = defineCommand({ description: "Keep waiting on a request a previous run submitted, by the request id it printed, instead of submitting a new one", }, - anonymous: { - type: "boolean", - description: - "Direct the agent to use the local-only recipe (no API call)", - default: false, - }, + ...localModeFlags( + "Direct the agent to use the local-only recipe (no API call)" + ), }, async run({ args }) { const cwd = resolve(args.dir ?? process.cwd()); @@ -370,13 +368,13 @@ const createCommand = defineCommand({ throw new CLIError(message, code, { reported: true }); } - if (args.anonymous) { + if (isLocalMode(args)) { // Anonymous rule creation runs in the agent, not the CLI. Point the // agent at the local-only recipe and exit cleanly. That recipe is // `create-sg-rule`: authoring an ast-grep rule on-device with no service // call is exactly what anonymous mode asks for, so it is the destination - // rather than an `--anonymous` variant of the service recipe. - const message = `Anonymous rule generation runs in the agent. Run \`${getCliPrefix()} agent create-sg-rule\` to fetch the local-only recipe.`; + // rather than a `--local` variant of the service recipe. + const message = `Local-mode rule generation runs in the agent. Run \`${getCliPrefix()} agent create-sg-rule\` to fetch the local-only recipe.`; if (args.json) { writeJsonError("INVALID_INPUT", message); } else { @@ -493,12 +491,9 @@ const improveCommand = defineCommand({ description: "Keep waiting on a request a previous run submitted, by the request id it printed, instead of submitting a new one", }, - anonymous: { - type: "boolean", - description: - "Direct the agent to use the local-only recipe (no API call)", - default: false, - }, + ...localModeFlags( + "Direct the agent to use the local-only recipe (no API call)" + ), }, async run({ args }) { const cwd = resolve(args.dir ?? process.cwd()); @@ -518,8 +513,8 @@ const improveCommand = defineCommand({ throw new CLIError(message, code, { reported: true }); } - if (args.anonymous) { - const message = `Anonymous rule improvement runs in the agent. Run \`${getCliPrefix()} agent improve-rule --anonymous\` to fetch the local-only recipe.`; + if (isLocalMode(args)) { + const message = `Local-mode rule improvement runs in the agent. Run \`${getCliPrefix()} agent improve-rule --local\` to fetch the local-only recipe.`; if (args.json) { writeJsonError("INVALID_INPUT", message); } else { @@ -632,11 +627,7 @@ const metaCommand = defineCommand({ description: "Output as JSON", default: false, }, - anonymous: { - type: "boolean", - description: "Accepted for compatibility; meta is purely local", - default: false, - }, + ...localModeFlags("Accepted for compatibility; meta is purely local"), id: { type: "positional", description: "Rule ID to look up", @@ -711,11 +702,7 @@ const deleteCommand = defineCommand({ alias: "d", description: "Working directory", }, - anonymous: { - type: "boolean", - description: "Accepted for compatibility; delete is purely local", - default: false, - }, + ...localModeFlags("Accepted for compatibility; delete is purely local"), json: { type: "boolean", description: diff --git a/packages/cli/src/prompts/recipes.ts b/packages/cli/src/prompts/recipes.ts index dfb5fb658..e2f913d5e 100644 --- a/packages/cli/src/prompts/recipes.ts +++ b/packages/cli/src/prompts/recipes.ts @@ -1445,7 +1445,7 @@ export function getServedRecipe( options.tool !== undefined && toolMap.get(topic)?.has(options.tool) === true ? ` --tool=${options.tool}` : options.anonymous === true && anonymousMap.has(topic) - ? " --anonymous" + ? " --local" : ""; const topicFetch = `${resolveInvocation(options)} agent ${topic}${variant}`; const fetch = (name: string) => `${topicFetch} --section ${name}`; diff --git a/packages/cli/src/report/draft.ts b/packages/cli/src/report/draft.ts index 8e746d230..3fcd71f30 100644 --- a/packages/cli/src/report/draft.ts +++ b/packages/cli/src/report/draft.ts @@ -218,7 +218,7 @@ function missingFacts(rules: LocalRule[]): string[] { } /** - * Scan the project as `check --anonymous` would and count each rule's matches. + * Scan the project as `check --local` would and count each rule's matches. * * Anonymous keeps the draft offline: no reconcile, so no request. A scan that * throws leaves the report unmeasured rather than failing the draft, since diff --git a/packages/cli/src/rules/inspect.ts b/packages/cli/src/rules/inspect.ts index e10c6e4a0..d627b63dd 100644 --- a/packages/cli/src/rules/inspect.ts +++ b/packages/cli/src/rules/inspect.ts @@ -630,7 +630,7 @@ export async function verifyOneRule( // // Dropping it is strictly more conservative: nothing runs that would not have // run before, and the blessed case that used to run without the flag now - // needs it. It also removes the `--anonymous` question rather than answering + // needs it. It also removes the `--local` question rather than answering // it, since with no network there is nothing to suppress. if (options.dangerouslyRunScripts !== true) { // Neither a pass nor a failure (D2), and the message has to say what would diff --git a/packages/cli/src/rules/plan-check.ts b/packages/cli/src/rules/plan-check.ts index e65062c92..70de7d6d9 100644 --- a/packages/cli/src/rules/plan-check.ts +++ b/packages/cli/src/rules/plan-check.ts @@ -33,7 +33,7 @@ import { applyVerdicts, NOT_IN_PLAN_REASON } from "./verdicts"; * - `--dangerously-run-scripts`: nothing. No reconcile, no signatures, every * rule of every engine runs, runtime included. The flag does only what its * name says. - * - logged out, `--anonymous`, no remote, or a reconcile that cannot complete: + * - logged out, `--local`, no remote, or a reconcile that cannot complete: * static rules run unverified, runtime rules are skipped, and the exit code * is untouched. Tamper detection needs the service; its absence is not a * failure. @@ -136,16 +136,16 @@ export async function planCheck( } if (options.anonymous) { - // `--anonymous` already says "do not verify". With nothing skipped, a + // `--local` already says "do not verify". With nothing skipped, a // notice would only repeat that back on every run (#732). Runtime rules // that did not run are a consequence worth naming, so they keep it. if (discovered.length === 0) { - log.write("unverified run: `--anonymous` was set, no runtime rules"); + log.write("unverified run: `--local` was set, no runtime rules"); return empty; } return unverified(discovered, { - cause: "`--anonymous` was set", - remedy: ["Run `check` without `--anonymous` to verify them."], + cause: "`--local` was set", + remedy: ["Run `check` without `--local` to verify them."], }); } const token = await getToken(cwd, { silent: true }); diff --git a/packages/cli/src/schemas/info.ts b/packages/cli/src/schemas/info.ts index 6c90bf17e..6c54a78cb 100644 --- a/packages/cli/src/schemas/info.ts +++ b/packages/cli/src/schemas/info.ts @@ -115,7 +115,7 @@ export const outputSchema = z.object({ "in again; `unreachable` the service could not be reached or did not " + "answer usably, so the token is unverified and may be fine, try later; " + "`upgrade_required` the service no longer supports this CLI version, " + - "so upgrade it; `none` no token; `anonymous` `--anonymous` skipped the " + + "so upgrade it; `none` no token; `anonymous` `--local` skipped the " + "probe" ), auth: authSchema diff --git a/packages/cli/src/util/local-flag.ts b/packages/cli/src/util/local-flag.ts new file mode 100644 index 000000000..3d2cee1d1 --- /dev/null +++ b/packages/cli/src/util/local-flag.ts @@ -0,0 +1,30 @@ +import type { ArgsDef } from "citty"; + +/** + * `--local` runs a command in local mode: no Taskless API call, no auth + * lookup, and only what can run on this machine without the service. + * `--anonymous` is the flag's original name, kept as an alias so existing + * scripts, CI configs and installed recipes keep working (taskless/cli#732). + * + * The alias is declared as its own argument rather than through citty's + * `alias`, because citty renders every alias in usage with a single dash, so + * `--help` would advertise `-anonymous`, which parses as `-a -n -o …`. + */ +export function localModeFlags(description: string) { + return { + local: { type: "boolean", description, default: false }, + anonymous: { + type: "boolean", + description: "Alias of --local, its original name", + default: false, + }, + } as const satisfies ArgsDef; +} + +/** Whether a command was asked to run in local mode, by either spelling. */ +export function isLocalMode(args: { + local?: boolean; + anonymous?: boolean; +}): boolean { + return args.local === true || args.anonymous === true; +} diff --git a/packages/cli/test/agent-extensions.test.ts b/packages/cli/test/agent-extensions.test.ts index 310c14768..30cc75753 100644 --- a/packages/cli/test/agent-extensions.test.ts +++ b/packages/cli/test/agent-extensions.test.ts @@ -66,9 +66,9 @@ describe("taskless agent (no args)", () => { } }); - it("mentions the --anonymous flag", async () => { + it("mentions the --local flag", async () => { const result = await runCli(["agent", "-d", cwd]); - expect(result.stdout).toContain("--anonymous"); + expect(result.stdout).toContain("--local"); }); it("lists the routing recipe topics under Authoring recipes", async () => { @@ -249,7 +249,7 @@ describe("taskless agent ", () => { }); }); -describe("taskless agent --anonymous (variant lookup)", () => { +describe("taskless agent --local (variant lookup)", () => { let cwd: string; beforeEach(async () => { @@ -260,28 +260,19 @@ describe("taskless agent --anonymous (variant lookup)", () => { await rm(cwd, { recursive: true, force: true }); }); - it("returns the .anonymous variant when one exists (improve-rule)", async () => { - const result = await runCli([ - "agent", - "improve-rule", - "--anonymous", - "-d", - cwd, - ]); - expect(result.exitCode).toBe(0); - // The anonymous recipe declares "(anonymous)" in its header - expect(result.stdout).toContain("(anonymous)"); - }); + it.each(["--local", "--anonymous"])( + "returns the .anonymous variant when one exists (improve-rule, %s)", + async (flag) => { + const result = await runCli(["agent", "improve-rule", flag, "-d", cwd]); + expect(result.exitCode).toBe(0); + // The local-mode recipe declares "(local mode)" in its header + expect(result.stdout).toContain("(local mode)"); + } + ); it("falls back to the canonical recipe when no variant exists (check)", async () => { const canonical = await runCli(["agent", "check", "-d", cwd]); - const anonymous = await runCli([ - "agent", - "check", - "--anonymous", - "-d", - cwd, - ]); + const anonymous = await runCli(["agent", "check", "--local", "-d", cwd]); expect(anonymous.exitCode).toBe(0); // Same body — falls back to check.md since no check.anonymous.md expect(anonymous.stdout).toBe(canonical.stdout); @@ -297,19 +288,19 @@ describe("taskless agent --anonymous (variant lookup)", () => { const anonymous = await runCli([ "agent", "create-remote-rule", - "--anonymous", + "--local", "-d", cwd, ]); expect(anonymous.exitCode).toBe(0); expect(anonymous.stdout).toBe(canonical.stdout); - expect(anonymous.stdout).not.toContain("(anonymous)"); + expect(anonymous.stdout).not.toContain("(local mode)"); }); - it("returns the canonical recipe when --anonymous is omitted", async () => { + it("returns the canonical recipe when --local is omitted", async () => { const result = await runCli(["agent", "improve-rule", "-d", cwd]); expect(result.stdout).toContain("# Topic: improve-rule"); - expect(result.stdout).not.toContain("(anonymous)"); + expect(result.stdout).not.toContain("(local mode)"); }); }); @@ -688,7 +679,7 @@ describe("taskless agent --tool (variant lookup)", () => { ["ast-grep", "agent create-sg-rule"], ["prettier", "agent route"], ["black", "agent route"], - ["anonymous", "--anonymous"], + ["anonymous", "--local"], ])("refuses --tool=%s and names what to use", async (tool, instead) => { const result = await runCli([ "agent", diff --git a/packages/cli/test/error-envelope.test.ts b/packages/cli/test/error-envelope.test.ts index ed2aaa612..6052009de 100644 --- a/packages/cli/test/error-envelope.test.ts +++ b/packages/cli/test/error-envelope.test.ts @@ -249,11 +249,11 @@ describe("standardized error envelope (--json)", () => { }); describe("auth login", () => { - it("emits INVALID_INPUT when --anonymous is set", async () => { + it("emits INVALID_INPUT when --local is set", async () => { const result = await runCli([ "auth", "login", - "--anonymous", + "--local", "--json", "-d", cwd, @@ -261,7 +261,7 @@ describe("standardized error envelope (--json)", () => { expect(result.exitCode).not.toBe(0); const env = parseEnvelope(result.stdout); expect(env.code).toBe("INVALID_INPUT"); - expect(env.message).toContain("anonymous"); + expect(env.message).toContain("local mode"); }); }); diff --git a/packages/cli/test/fixtures/v0-production/.taskless/rules/no-as-any.yml b/packages/cli/test/fixtures/v0-production/.taskless/rules/no-as-any.yml index 215e30410..187e7b964 100644 --- a/packages/cli/test/fixtures/v0-production/.taskless/rules/no-as-any.yml +++ b/packages/cli/test/fixtures/v0-production/.taskless/rules/no-as-any.yml @@ -4,7 +4,7 @@ rule: - not: precedes: kind: comment - regex: '@taskless-ignore' + regex: "@taskless-ignore" id: no-as-any language: TypeScript message: Avoid using 'as any' which disables type checking. diff --git a/packages/cli/test/anonymous-flag.test.ts b/packages/cli/test/local-flag.test.ts similarity index 75% rename from packages/cli/test/anonymous-flag.test.ts rename to packages/cli/test/local-flag.test.ts index a10f42193..2fb5ffc9f 100644 --- a/packages/cli/test/anonymous-flag.test.ts +++ b/packages/cli/test/local-flag.test.ts @@ -37,42 +37,42 @@ async function runCli( } } -describe("--anonymous flag (per-command behavior matrix)", () => { +describe("--local flag (per-command behavior matrix)", () => { let cwd: string; beforeEach(async () => { - cwd = await mkdtemp(join(tmpdir(), "taskless-anon-")); + cwd = await mkdtemp(join(tmpdir(), "taskless-local-")); }); afterEach(async () => { await rm(cwd, { recursive: true, force: true }); }); - describe("info --anonymous", () => { + describe("info --local", () => { it("skips the API/auth probe and reports loggedIn: false", async () => { - const result = await runCli(["info", "--anonymous", "--json", "-d", cwd]); + const result = await runCli(["info", "--local", "--json", "-d", cwd]); expect(result.exitCode).toBe(0); const parsed = JSON.parse(result.stdout) as { loggedIn: boolean; auth?: unknown; }; - // Even if a token were present, --anonymous suppresses the lookup. + // Even if a token were present, --local suppresses the lookup. expect(parsed.loggedIn).toBe(false); expect(parsed.auth).toBeUndefined(); }); }); - describe("auth login --anonymous", () => { - it("rejects with exit 1 and 'auth commands cannot be anonymous'", async () => { - const result = await runCli(["auth", "login", "--anonymous", "-d", cwd]); + describe("auth login --local", () => { + it("rejects with exit 1 and 'auth commands cannot run in local mode'", async () => { + const result = await runCli(["auth", "login", "--local", "-d", cwd]); expect(result.exitCode).not.toBe(0); - expect(result.stderr).toContain("auth commands cannot be anonymous"); + expect(result.stderr).toContain("auth commands cannot run in local mode"); }); }); - describe("auth logout --anonymous", () => { + describe("auth logout --local", () => { it("accepts the flag as no-op (same behavior as plain logout)", async () => { - const result = await runCli(["auth", "logout", "--anonymous", "-d", cwd]); + const result = await runCli(["auth", "logout", "--local", "-d", cwd]); expect(result.exitCode).toBe(0); // Either "Logged out." or "Not logged in." depending on initial state; // both are success. @@ -80,20 +80,20 @@ describe("--anonymous flag (per-command behavior matrix)", () => { }); }); - describe("check --anonymous", () => { + describe("check --local", () => { it("accepts the flag as no-op (same behavior as plain check)", async () => { // No .taskless/ directory → friendly "no rules" message, exit 0 - const result = await runCli(["check", "--anonymous", "-d", cwd]); + const result = await runCli(["check", "--local", "-d", cwd]); expect(result.exitCode).toBe(0); expect(result.stdout).toContain("No rules configured"); }); }); - describe("rule create --anonymous", () => { + describe("rule create --local", () => { it("exits with a pointer to the local-only recipe (does not run generation)", async () => { - // No --from needed; the --anonymous branch short-circuits before + // No --from needed; the --local branch short-circuits before // file validation. - const result = await runCli(["rule", "create", "--anonymous", "-d", cwd]); + const result = await runCli(["rule", "create", "--local", "-d", cwd]); expect(result.exitCode).not.toBe(0); expect(result.stderr).toMatch( /`(?:npx|pnpm dlx) @taskless\/cli@\d[^\s`]* agent create-sg-rule`/ @@ -104,7 +104,7 @@ describe("--anonymous flag (per-command behavior matrix)", () => { const result = await runCli([ "rule", "create", - "--anonymous", + "--local", "--json", "-d", cwd, @@ -116,30 +116,24 @@ describe("--anonymous flag (per-command behavior matrix)", () => { }); }); - describe("rule improve --anonymous", () => { + describe("rule improve --local", () => { it("exits with a pointer to the local-only recipe", async () => { - const result = await runCli([ - "rule", - "improve", - "--anonymous", - "-d", - cwd, - ]); + const result = await runCli(["rule", "improve", "--local", "-d", cwd]); expect(result.exitCode).not.toBe(0); expect(result.stderr).toMatch( - /`(?:npx|pnpm dlx) @taskless\/cli@\d[^\s`]* agent improve-rule --anonymous`/ + /`(?:npx|pnpm dlx) @taskless\/cli@\d[^\s`]* agent improve-rule --local`/ ); }); }); - describe("rule delete --anonymous", () => { + describe("rule delete --local", () => { it("accepts the flag as no-op (same behavior as plain delete)", async () => { - // Rule doesn't exist → exit 1 with "not found", same as without --anonymous + // Rule doesn't exist → exit 1 with "not found", same as without --local const result = await runCli([ "rule", "delete", "nonexistent", - "--anonymous", + "--local", "-d", cwd, ]); @@ -148,9 +142,9 @@ describe("--anonymous flag (per-command behavior matrix)", () => { }); }); - describe("rule meta --anonymous", () => { + describe("rule meta --local", () => { it("accepts the flag as no-op", async () => { - // No sidecar is ever written → RULE_META_UNAVAILABLE, and --anonymous + // No sidecar is ever written → RULE_META_UNAVAILABLE, and --local // changes nothing about that. await mkdir(join(cwd, ".taskless"), { recursive: true }); await writeFile( @@ -161,7 +155,7 @@ describe("--anonymous flag (per-command behavior matrix)", () => { "rule", "meta", "nonexistent", - "--anonymous", + "--local", "--json", "-d", cwd, @@ -172,19 +166,70 @@ describe("--anonymous flag (per-command behavior matrix)", () => { }); }); - describe("init --anonymous", () => { + describe("init --local", () => { it("accepts the flag as no-op", async () => { - const result = await runCli(["init", "--anonymous", "-d", cwd]); + const result = await runCli(["init", "--local", "-d", cwd]); expect(result.exitCode).toBe(0); }); }); }); +/** + * `--anonymous` is the flag's original name (#732). Scripts, CI configs and + * recipes installed by earlier versions still pass it, so every behavior + * `--local` selects must be reachable through the old spelling too. + */ +describe("--anonymous stays an alias of --local", () => { + let cwd: string; + + beforeEach(async () => { + cwd = await mkdtemp(join(tmpdir(), "taskless-anon-alias-")); + }); + + afterEach(async () => { + await rm(cwd, { recursive: true, force: true }); + }); + + it("info --anonymous skips the auth probe", async () => { + const result = await runCli(["info", "--anonymous", "--json", "-d", cwd]); + expect(result.exitCode).toBe(0); + const parsed = JSON.parse(result.stdout) as { + loggedIn: boolean; + }; + expect(parsed.loggedIn).toBe(false); + }); + + it("auth login --anonymous is rejected like --local", async () => { + const result = await runCli(["auth", "login", "--anonymous", "-d", cwd]); + expect(result.exitCode).not.toBe(0); + expect(result.stderr).toContain("auth commands cannot run in local mode"); + }); + + it("rule create --anonymous points at the local-only recipe", async () => { + const result = await runCli(["rule", "create", "--anonymous", "-d", cwd]); + expect(result.exitCode).not.toBe(0); + expect(result.stderr).toContain("agent create-sg-rule"); + }); + + it("rule improve --anonymous points at the --local recipe", async () => { + const result = await runCli(["rule", "improve", "--anonymous", "-d", cwd]); + expect(result.exitCode).not.toBe(0); + expect(result.stderr).toContain("agent improve-rule --local"); + }); + + it("help lists --local and still documents --anonymous", async () => { + const result = await runCli(["check", "--help"]); + expect(result.stdout).toContain("--local"); + expect(result.stdout).toContain("--anonymous"); + expect(result.stdout).not.toMatch(/(^|[^-])-anonymous/); + }); +}); + /** * The half of #179 that is a guarantee rather than a change. * * Remote generation needs a GitHub `origin`; local authoring does not, and - * never did. `rule create --anonymous` returns before identity is resolved, + * never did. `rule create --local` returns before identity is resolved, * and `validate` and `verify` never resolve it at all. That is easy to regress by * hoisting an identity call, and the regression would be invisible to anyone * developing inside a GitHub checkout, so it is pinned here across all three @@ -251,20 +296,11 @@ describe("local authoring needs no GitHub remote", () => { await population.setUp(); }); - it("rule create --anonymous does not hit a GitHub precondition", async () => { + it("rule create --local does not hit a GitHub precondition", async () => { const from = join(cwd, "create.json"); await writeFile(from, JSON.stringify({ prompt: "no eval" })); const result = await runCli( - [ - "rule", - "create", - "--from", - from, - "--anonymous", - "--json", - "-d", - cwd, - ], + ["rule", "create", "--from", from, "--local", "--json", "-d", cwd], withToken ); expect(result.stdout + result.stderr).not.toMatch( @@ -369,8 +405,8 @@ describe("info reports the repository context", () => { expect(info.ghOwner).toBe("[unknown]"); }); - it("resolves the context even under --anonymous", async () => { - // `--anonymous` suppresses the API/auth probe. The repository context is + it("resolves the context even under --local", async () => { + // `--local` suppresses the API/auth probe. The repository context is // local, so it is unaffected: capability state is not auth state. await execFileAsync("git", ["init"], { cwd }); await execFileAsync( @@ -383,7 +419,7 @@ describe("info reports the repository context", () => { ], { cwd } ); - const result = await runCli(["info", "--anonymous", "--json", "-d", cwd]); + const result = await runCli(["info", "--local", "--json", "-d", cwd]); expect(result.exitCode).toBe(0); const info = JSON.parse(result.stdout) as { loggedIn: boolean; diff --git a/packages/cli/test/prompts.test.ts b/packages/cli/test/prompts.test.ts index 33c65adde..8e7b06183 100644 --- a/packages/cli/test/prompts.test.ts +++ b/packages/cli/test/prompts.test.ts @@ -602,7 +602,7 @@ describe("anonymous variants", () => { const anonymous = getRecipe("improve-rule", { anonymous: true }); expect(anonymous).toBeDefined(); expect(anonymous).not.toBe(canonical); - expect(anonymous).toContain("(anonymous)"); + expect(anonymous).toContain("(local mode)"); }); it("falls back to the canonical recipe for a topic without one", () => { @@ -1022,7 +1022,7 @@ describe("fixture sources", () => { it("the anonymous improve-rule carries it, since it adds cases itself", () => { const rendered = getRecipe("improve-rule", { anonymous: true }); - expect(rendered).toContain("(anonymous)"); + expect(rendered).toContain("(local mode)"); expect(rendered).toContain("**Where the cases come from.**"); }); diff --git a/packages/cli/test/runtime-check.test.ts b/packages/cli/test/runtime-check.test.ts index 8364369dc..67f99653a 100644 --- a/packages/cli/test/runtime-check.test.ts +++ b/packages/cli/test/runtime-check.test.ts @@ -374,20 +374,23 @@ describe("check: static vs runtime dispatch", () => { ); }); - it("--anonymous: the notice names dropping --anonymous, not auth login", async () => { - const { stderr } = await runCli(["check", "-d", directory, "--anonymous"]); - expect(stderr).toContain("Rules were not verified: `--anonymous` was set."); - expect(stderr).toContain("without `--anonymous`"); - expect(stderr).toContain("1 runtime rule(s) did not run"); - expect(stderr).not.toContain("auth login"); - }); + it.each(["--local", "--anonymous"])( + "%s: the notice names dropping --local, not auth login", + async (flag) => { + const { stderr } = await runCli(["check", "-d", directory, flag]); + expect(stderr).toContain("Rules were not verified: `--local` was set."); + expect(stderr).toContain("without `--local`"); + expect(stderr).toContain("1 runtime rule(s) did not run"); + expect(stderr).not.toContain("auth login"); + } + ); - it("--anonymous with no runtime rules: no notice, static rules still run (#732)", async () => { + it("--local with no runtime rules: no notice, static rules still run (#732)", async () => { await rm(join(directory, ".taskless", "runtime"), { recursive: true, force: true, }); - const human = await runCli(["check", "-d", directory, "--anonymous"]); + const human = await runCli(["check", "-d", directory, "--local"]); expect(human.stderr).not.toContain("Rules were not verified"); expect(human.stdout).toContain("no-console"); @@ -395,7 +398,7 @@ describe("check: static vs runtime dispatch", () => { "check", "-d", directory, - "--anonymous", + "--local", "--json", ]); const output = parseJson(stdout); @@ -891,10 +894,10 @@ describe("check: static vs runtime dispatch", () => { expect(stderr).toMatch(/Upgrade it: run `npx .+@latest init`/); }); - it("--anonymous with a token: skips runtime and never calls reconcile", async () => { + it("--local with a token: skips runtime and never calls reconcile", async () => { const { stdout, server } = await authedCheck( (request) => ({ statusCode: 200, body: answer(request) }), - ["--json", "--anonymous"] + ["--json", "--local"] ); expect(dataCalls(server)).toHaveLength(0); expect(parseJson(stdout).skipped?.some((s) => s.rule === "demo")).toBe( diff --git a/skills/taskless/SKILL.md b/skills/taskless/SKILL.md index d7c9d64eb..823ecde85 100644 --- a/skills/taskless/SKILL.md +++ b/skills/taskless/SKILL.md @@ -200,13 +200,14 @@ two commands is an error in zsh, which drops the rest of the line, so the second command never runs and nothing says so. A chain also reports only its last command's exit code, and `check` uses its exit code to report results. -## --anonymous +## --local -Any rule/check command accepts `--anonymous` to skip the Taskless API and +Any rule/check command accepts `--local` to skip the Taskless API and use local-only behavior. When the user is offline OR explicitly asks for -anonymous mode, fetch the recipe with -`%(TASKLESS_CLI)s agent --anonymous`, which returns the local-only -flow (when one exists for that topic). +local mode, fetch the recipe with +`%(TASKLESS_CLI)s agent --local`, which returns the local-only +flow (when one exists for that topic). `--anonymous` is the flag's +original name and still works as an alias. ## First-run latency