From efb1edb6cac061aee58d2398bd9ccc947a6f3a18 Mon Sep 17 00:00:00 2001 From: Jakob Heuser Date: Sun, 29 Nov 2026 14:09:28 -0800 Subject: [PATCH] fix(init): point at the wizard from a terminal, and say when CI is why it did not start --- .changeset/wizard-pointer.md | 5 ++ .../2026-11-29-wizard-pointer/.openspec.yaml | 2 + .../2026-11-29-wizard-pointer/design.md | 9 +++ .../2026-11-29-wizard-pointer/proposal.md | 21 +++++++ .../specs/cli-init/spec.md | 31 ++++++++++ .../2026-11-29-wizard-pointer/tasks.md | 10 ++++ openspec/specs/cli-init/spec.md | 30 ++++++++++ packages/cli/src/commands/init.ts | 12 ++++ packages/cli/src/index.ts | 29 +++++---- packages/cli/src/util/interactive.ts | 56 ++++++++++++++++-- packages/cli/test/cli.test.ts | 11 ++++ packages/cli/test/init-no-interactive.test.ts | 13 ++++ packages/cli/test/interactive.test.ts | 59 ++++++++++++++++++- 13 files changed, 271 insertions(+), 17 deletions(-) create mode 100644 .changeset/wizard-pointer.md create mode 100644 openspec/changes/archive/2026-11-29-wizard-pointer/.openspec.yaml create mode 100644 openspec/changes/archive/2026-11-29-wizard-pointer/design.md create mode 100644 openspec/changes/archive/2026-11-29-wizard-pointer/proposal.md create mode 100644 openspec/changes/archive/2026-11-29-wizard-pointer/specs/cli-init/spec.md create mode 100644 openspec/changes/archive/2026-11-29-wizard-pointer/tasks.md diff --git a/.changeset/wizard-pointer.md b/.changeset/wizard-pointer.md new file mode 100644 index 000000000..a37e432cf --- /dev/null +++ b/.changeset/wizard-pointer.md @@ -0,0 +1,5 @@ +--- +"@taskless/cli": patch +--- + +`taskless init` run from a terminal now says it installs without asking and names the command that opens the setup wizard (`npx @taskless/cli` with no arguments), so running `init` to get the wizard back no longer leaves you guessing. Agents, scripts, CI, and `--json` don't see the line. A bare `npx @taskless/cli` in a terminal with `CI` set now says `CI` is why the wizard didn't start, where it used to tell you to run from a terminal you were already in. diff --git a/openspec/changes/archive/2026-11-29-wizard-pointer/.openspec.yaml b/openspec/changes/archive/2026-11-29-wizard-pointer/.openspec.yaml new file mode 100644 index 000000000..992733754 --- /dev/null +++ b/openspec/changes/archive/2026-11-29-wizard-pointer/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-29 diff --git a/openspec/changes/archive/2026-11-29-wizard-pointer/design.md b/openspec/changes/archive/2026-11-29-wizard-pointer/design.md new file mode 100644 index 000000000..953ede6bd --- /dev/null +++ b/openspec/changes/archive/2026-11-29-wizard-pointer/design.md @@ -0,0 +1,9 @@ +## Decisions + +**One guard, read once.** `shouldLaunchWizard` becomes `wizardBlocker(...) === undefined`, and the preamble and `init` both read the same context (`stdout.isTTY`, `stdin.isTTY`, `CI`). `CI` is checked first, matching the launch guard, so a pseudo-terminal with `CI` set is reported as CI. + +**The preamble keeps its first line.** `Taskless CLI — non-interactive context detected.` stays the same in every case, so anything matching it still matches; only the second line varies with the reason. + +**The `init` hint sits above the telemetry notice.** The uncommitted-files notice must stay directly above the onboarding trailer, and the trailer must stay last, so the hint goes before both. + +**The pure functions carry the text.** A spawned CLI is never on a TTY, so the TTY half of the `init` hint cannot be exercised end to end in a test. The text is unit-tested, a spawned `init` asserts the hint is absent, and a spawned bare run with `CI=true` asserts the CI wording. diff --git a/openspec/changes/archive/2026-11-29-wizard-pointer/proposal.md b/openspec/changes/archive/2026-11-29-wizard-pointer/proposal.md new file mode 100644 index 000000000..3564ab887 --- /dev/null +++ b/openspec/changes/archive/2026-11-29-wizard-pointer/proposal.md @@ -0,0 +1,21 @@ +## Why + +Issue #708: a design partner ran `npx @taskless/cli` in a second project, saw what looked like nothing, then ran `npx @taskless/cli init` expecting the wizard back. `init` never prompts, so it did not bring the wizard back, and nothing said which command would. + +On 0.13.8 a bare run starts the wizard in a fresh directory, a fresh git repository, and an already-initialized project, and a cancelled wizard already names the bare command, so the "nothing happened" report does not reproduce. Two gaps remain: + +- `init` run from a terminal installs without saying the wizard exists or how to reach it. +- A bare run in a terminal with `CI` set skips the wizard and tells the person to "run from a terminal", which they already did. + +The reporter's other question, whether `init` and then the onboarding prompt reach the same place, already has an answer in the output: `init` ends with the onboarding prompt, the same one the wizard ends with. + +## What Changes + +- `init`, when it runs where the wizard could have run (both streams a TTY, `CI` not set) and without `--json`, prints one line naming the bare command that opens the wizard. Agents, scripts, and CI never see it. +- The non-interactive preamble of a bare run says when `CI` is the reason the wizard did not start, naming the value, instead of telling the person to use a terminal. + +Not breaking. The bump is `patch`. + +## Delivery shape + +**Single PR.** The change is two messages and their tests; the spec, implementation, and archive land together. diff --git a/openspec/changes/archive/2026-11-29-wizard-pointer/specs/cli-init/spec.md b/openspec/changes/archive/2026-11-29-wizard-pointer/specs/cli-init/spec.md new file mode 100644 index 000000000..f899a9dc9 --- /dev/null +++ b/openspec/changes/archive/2026-11-29-wizard-pointer/specs/cli-init/spec.md @@ -0,0 +1,31 @@ +## ADDED Requirements + +### Requirement: Init in a terminal names the command that opens the wizard + +When `taskless init` completes without `--json` and both stdout and stdin are TTYs and `CI` is not `true` or `1`, the output SHALL include one line saying that `init` installs without asking and naming the bare invocation, with the CLI's launcher-aware prefix, as the command that opens the interactive wizard. The line SHALL be printed before the telemetry notice, so that the uncommitted-install notice and the onboarding trailer keep their places at the end of the output. When any of those conditions fails, the line SHALL NOT be printed. + +#### Scenario: Init from a terminal points at the wizard + +- **WHEN** a user runs `taskless init` with both streams on a TTY and `CI` unset +- **THEN** the output SHALL include a line naming the bare invocation as the way to open the wizard +- **AND** the onboarding trailer SHALL still end the output + +#### Scenario: Init from an agent or script does not + +- **WHEN** `taskless init` runs with stdout or stdin not a TTY, or with `CI` set to `true` or `1`, or with `--json` +- **THEN** the output SHALL NOT include the wizard line + +### Requirement: The non-interactive preamble says why the wizard did not start + +When a bare invocation does not launch the wizard, the first line of its preamble SHALL be `Taskless CLI — non-interactive context detected.` in every case. When `CI` is `true` or `1`, the preamble SHALL say that the wizard does not start while `CI` is set, naming its value, and SHALL NOT tell the user to run from a terminal. Otherwise the preamble SHALL tell the user to run from a terminal for an interactive install. + +#### Scenario: CI set in a terminal + +- **WHEN** `taskless` is invoked with no subcommand, both streams on a TTY, and `CI=true` +- **THEN** the preamble SHALL say the wizard does not start while `CI=true` is set +- **AND** SHALL NOT say to run from a terminal + +#### Scenario: Piped without CI + +- **WHEN** `taskless` is invoked with no subcommand, stdout not a TTY, and `CI` unset +- **THEN** the preamble SHALL say to run from a terminal for an interactive install diff --git a/openspec/changes/archive/2026-11-29-wizard-pointer/tasks.md b/openspec/changes/archive/2026-11-29-wizard-pointer/tasks.md new file mode 100644 index 000000000..db6524c5e --- /dev/null +++ b/openspec/changes/archive/2026-11-29-wizard-pointer/tasks.md @@ -0,0 +1,10 @@ +## 1. Messages + +- [x] 1.1 Add `wizardBlocker`, `nonInteractivePreamble`, and `getWizardHint` to `packages/cli/src/util/interactive.ts`, and express `shouldLaunchWizard` through `wizardBlocker`. +- [x] 1.2 Print the preamble from `nonInteractivePreamble` in the bare invocation path of `packages/cli/src/index.ts`. +- [x] 1.3 Print `getWizardHint` from `init` when the wizard could have run, above the telemetry notice. + +## 2. Tests and checks + +- [x] 2.1 Unit-test the blocker, preamble, and hint; assert a spawned bare run under `CI=true` names CI; assert a spawned `init` prints no hint. +- [x] 2.2 Run `pnpm typecheck`, `pnpm lint`, and the test suite; add a patch changeset. diff --git a/openspec/specs/cli-init/spec.md b/openspec/specs/cli-init/spec.md index b6fcc9345..5c125e890 100644 --- a/openspec/specs/cli-init/spec.md +++ b/openspec/specs/cli-init/spec.md @@ -1405,3 +1405,33 @@ The manifest SHALL record, under `install.permissions`, each file Taskless wrote - **WHEN** the manifest records `Bash(./.taskless/bin/cli-nightly.mjs *)` in `.claude/settings.json` and the nightly's `init` runs with `.claude/` no longer selected - **THEN** that rule SHALL be removed with the nightly's other Taskless rules - **AND** `Bash(./.taskless/bin/cli.mjs *)` SHALL remain + +### Requirement: Init in a terminal names the command that opens the wizard + +When `taskless init` completes without `--json` and both stdout and stdin are TTYs and `CI` is not `true` or `1`, the output SHALL include one line saying that `init` installs without asking and naming the bare invocation, with the CLI's launcher-aware prefix, as the command that opens the interactive wizard. The line SHALL be printed before the telemetry notice, so that the uncommitted-install notice and the onboarding trailer keep their places at the end of the output. When any of those conditions fails, the line SHALL NOT be printed. + +#### Scenario: Init from a terminal points at the wizard + +- **WHEN** a user runs `taskless init` with both streams on a TTY and `CI` unset +- **THEN** the output SHALL include a line naming the bare invocation as the way to open the wizard +- **AND** the onboarding trailer SHALL still end the output + +#### Scenario: Init from an agent or script does not + +- **WHEN** `taskless init` runs with stdout or stdin not a TTY, or with `CI` set to `true` or `1`, or with `--json` +- **THEN** the output SHALL NOT include the wizard line + +### Requirement: The non-interactive preamble says why the wizard did not start + +When a bare invocation does not launch the wizard, the first line of its preamble SHALL be `Taskless CLI — non-interactive context detected.` in every case. When `CI` is `true` or `1`, the preamble SHALL say that the wizard does not start while `CI` is set, naming its value, and SHALL NOT tell the user to run from a terminal. Otherwise the preamble SHALL tell the user to run from a terminal for an interactive install. + +#### Scenario: CI set in a terminal + +- **WHEN** `taskless` is invoked with no subcommand, both streams on a TTY, and `CI=true` +- **THEN** the preamble SHALL say the wizard does not start while `CI=true` is set +- **AND** SHALL NOT say to run from a terminal + +#### Scenario: Piped without CI + +- **WHEN** `taskless` is invoked with no subcommand, stdout not a TTY, and `CI` unset +- **THEN** the preamble SHALL say to run from a terminal for an interactive install diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index 1a31fdb56..d8235e6c9 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -67,6 +67,7 @@ import { } from "../rules/reconcile-status"; 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 { makeErrorEnvelope } from "../types/errors"; @@ -230,6 +231,17 @@ export const initCommand = defineCommand({ if (result.reloadNotice !== undefined) { console.log(result.reloadNotice); } + // Only where the wizard could have run: `init` never prompts, and a + // person who ran it from a terminal may have wanted the wizard back. + if ( + shouldLaunchWizard({ + stdoutIsTTY: process.stdout.isTTY, + stdinIsTTY: process.stdin.isTTY, + ci: process.env.CI, + }) + ) { + console.log(getWizardHint(getCliPrefix())); + } if (telemetryEnabled) { console.log(TELEMETRY_NOTICE); } diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 79da05ed1..e686a6ef4 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -33,7 +33,11 @@ import { joinDirectoryValues, splitRawArguments, } from "./util/argv"; -import { shouldLaunchWizard } from "./util/interactive"; +import { + nonInteractivePreamble, + shouldLaunchWizard, + wizardBlocker, +} from "./util/interactive"; import { showResolvedUsage } from "./util/help"; import { getCliPrefix } from "./util/package-manager"; import { CLIError } from "./util/cli-error"; @@ -141,13 +145,12 @@ const main = defineCommand({ // prompts, and it calls the wizard rather than `init`. The guard carries // the `CI` check `init` used to apply, since a pseudo-terminal in CI is // still nobody to answer a prompt. - if ( - shouldLaunchWizard({ - stdoutIsTTY: process.stdout.isTTY, - stdinIsTTY: process.stdin.isTTY, - ci: process.env.CI, - }) - ) { + const context = { + stdoutIsTTY: process.stdout.isTTY, + stdinIsTTY: process.stdin.isTTY, + ci: process.env.CI, + }; + if (shouldLaunchWizard(context)) { const result = await runWizard({ cwd: resolveCwd(rawArgs) }); if (result.status === "cancelled") { process.exitCode = 1; @@ -164,10 +167,12 @@ const main = defineCommand({ ? launcher : prefix; console.error( - "Taskless CLI — non-interactive context detected.\n" + - " For interactive install, run from a terminal.\n" + - ` For scripted install, run \`${prefix} init\`.\n` + - ` For agent recipes, run \`${recipes} agent\` (no args) for the topic index.\n` + nonInteractivePreamble({ + blocker: wizardBlocker(context) ?? "no-tty", + ci: context.ci, + prefix, + recipes, + }) ); // Forward the parent's rawArgs (e.g. `-d `) so the agent command // doesn't mis-parse them as positional topic names. diff --git a/packages/cli/src/util/interactive.ts b/packages/cli/src/util/interactive.ts index b8e661256..02b6083d4 100644 --- a/packages/cli/src/util/interactive.ts +++ b/packages/cli/src/util/interactive.ts @@ -12,13 +12,61 @@ * Pure so it can be tested: a spawned CLI is never on a TTY, which is exactly * the case this guard does not decide. */ -export function shouldLaunchWizard(input: { +export function shouldLaunchWizard(input: WizardContext): boolean { + return wizardBlocker(input) === undefined; +} + +export interface WizardContext { stdoutIsTTY: boolean | undefined; stdinIsTTY: boolean | undefined; ci: string | undefined; -}): boolean { - if (isCiEnvironment(input.ci)) return false; - return input.stdoutIsTTY === true && input.stdinIsTTY === true; +} + +/** + * Why a bare invocation will not launch the wizard, or `undefined` when it + * will. `ci` is checked first, matching the order `shouldLaunchWizard` gives + * it, so a terminal with `CI` set is told about `CI` rather than told to "run + * from a terminal" it is already in. + */ +export function wizardBlocker( + input: WizardContext +): "ci" | "no-tty" | undefined { + if (isCiEnvironment(input.ci)) return "ci"; + if (input.stdoutIsTTY !== true || input.stdinIsTTY !== true) return "no-tty"; + return undefined; +} + +/** + * The preamble a bare invocation prints when it does not launch the wizard, + * before the agent topic index. The first line is the same in every case; + * the second says why the wizard did not start, so a person who expected it + * is not left guessing. + */ +export function nonInteractivePreamble(options: { + blocker: "ci" | "no-tty"; + ci: string | undefined; + prefix: string; + recipes: string; +}): string { + const why = + options.blocker === "ci" + ? ` The setup wizard does not start while \`CI=${options.ci ?? ""}\` is set. Unset it to use the wizard from a terminal.\n` + : " For interactive install, run from a terminal.\n"; + return ( + "Taskless CLI — non-interactive context detected.\n" + + why + + ` For scripted install, run \`${options.prefix} init\`.\n` + + ` For agent recipes, run \`${options.recipes} agent\` (no args) for the topic index.\n` + ); +} + +/** + * The line `init` prints when it ran where the wizard could have: `init` + * never prompts, so a person who ran it hoping to get the wizard back is + * told which command opens it. + */ +export function getWizardHint(prefix: string): string { + return `\`init\` installs without asking. To choose which tools to install for and review settings edits before they are written, run \`${prefix}\` with no arguments.`; } /** diff --git a/packages/cli/test/cli.test.ts b/packages/cli/test/cli.test.ts index b12d3e07e..cc2c0b9c1 100644 --- a/packages/cli/test/cli.test.ts +++ b/packages/cli/test/cli.test.ts @@ -111,6 +111,17 @@ describe("cli", () => { } ); + it("says CI is why a bare run skipped the wizard", async () => { + const { stderr } = await execFileAsync( + "node", + [binPath, "-d", temporaryDirectory], + { env: { ...process.env, CI: "true" } } + ); + expect(stderr).toContain("non-interactive context detected"); + expect(stderr).toContain("`CI=true`"); + expect(stderr).not.toContain("run from a terminal"); + }); + it("sends recipes to the project launcher when the project has one", async () => { await mkdir(join(temporaryDirectory, ".taskless", "bin"), { recursive: true, diff --git a/packages/cli/test/init-no-interactive.test.ts b/packages/cli/test/init-no-interactive.test.ts index 67b90feba..d24f1d7c5 100644 --- a/packages/cli/test/init-no-interactive.test.ts +++ b/packages/cli/test/init-no-interactive.test.ts @@ -223,6 +223,19 @@ describe("taskless init (the batch install)", () => { expect(stdout).not.toMatch(/@taskless\/cli@latest onboard/); }); + it("does not point at the wizard when it could not have run", async () => { + // A spawned CLI is never on a TTY, so this is the agent and script case: + // the wizard hint is for a person at a terminal only. + const { stdout } = await execFileAsync("node", [ + binPath, + "init", + "-d", + cwd, + ]); + + expect(stdout).not.toContain("with no arguments"); + }); + it("prints the same skill-only trailer when no commands were installed", async () => { // .agents/ fallback receives no commands; the trailer is the same. const { stdout } = await execFileAsync("node", [ diff --git a/packages/cli/test/interactive.test.ts b/packages/cli/test/interactive.test.ts index 08e2aec6f..843678742 100644 --- a/packages/cli/test/interactive.test.ts +++ b/packages/cli/test/interactive.test.ts @@ -1,6 +1,11 @@ import { describe, expect, it } from "vitest"; -import { shouldLaunchWizard } from "../src/util/interactive"; +import { + getWizardHint, + nonInteractivePreamble, + shouldLaunchWizard, + wizardBlocker, +} from "../src/util/interactive"; describe("shouldLaunchWizard", () => { const tty = { stdoutIsTTY: true, stdinIsTTY: true }; @@ -34,3 +39,55 @@ describe("shouldLaunchWizard", () => { expect(shouldLaunchWizard({ ...tty, ci })).toBe(true); }); }); + +describe("wizardBlocker", () => { + it("names CI before the TTYs, so a terminal with CI set is told about CI", () => { + expect( + wizardBlocker({ stdoutIsTTY: true, stdinIsTTY: true, ci: "true" }) + ).toBe("ci"); + expect( + wizardBlocker({ stdoutIsTTY: false, stdinIsTTY: false, ci: "1" }) + ).toBe("ci"); + }); + + it("names a missing TTY when CI is not set", () => { + expect( + wizardBlocker({ stdoutIsTTY: true, stdinIsTTY: false, ci: undefined }) + ).toBe("no-tty"); + }); + + it("is undefined exactly when the wizard launches", () => { + expect( + wizardBlocker({ stdoutIsTTY: true, stdinIsTTY: true, ci: undefined }) + ).toBeUndefined(); + }); +}); + +describe("nonInteractivePreamble", () => { + const base = { prefix: "npx @taskless/cli", recipes: "npx @taskless/cli" }; + + it("tells a CI run that CI is why the wizard did not start", () => { + const text = nonInteractivePreamble({ ...base, blocker: "ci", ci: "1" }); + expect(text).toContain("non-interactive context detected"); + expect(text).toContain("`CI=1`"); + expect(text).not.toContain("run from a terminal"); + }); + + it("tells a piped run to use a terminal", () => { + const text = nonInteractivePreamble({ + ...base, + blocker: "no-tty", + ci: undefined, + }); + expect(text).toContain("For interactive install, run from a terminal."); + expect(text).toContain("`npx @taskless/cli init`"); + }); +}); + +describe("getWizardHint", () => { + it("names the bare command that opens the wizard", () => { + expect(getWizardHint("npx @taskless/cli")).toContain( + "run `npx @taskless/cli` with no arguments" + ); + }); +});