From b82427d7a5a25786eb71a756e4c9a3da8c5941c6 Mon Sep 17 00:00:00 2001 From: Jakob Heuser Date: Tue, 1 Dec 2026 23:35:13 -0800 Subject: [PATCH 1/3] feat(init): name the ignore entries a project's formatter and linters need After init, a detected prettier, eslint, biome, oxlint, ruff or black is told which entries keep it off .taskless/ (and, for prettier, the skill stubs), in its own syntax. Printed, never written; carried on --json as ignores. A tool whose config already mentions .taskless is left out. Refs #732 --- .changeset/init-tool-ignores.md | 5 + .../changes/init-tool-ignores/proposal.md | 17 ++ .../init-tool-ignores/specs/cli-init/spec.md | 36 +++ openspec/changes/init-tool-ignores/tasks.md | 10 + packages/cli/src/agent/init.md | 22 +- packages/cli/src/commands/init.ts | 17 ++ packages/cli/src/install/tool-ignores.ts | 243 ++++++++++++++++++ packages/cli/src/wizard/index.ts | 7 + packages/cli/test/tool-ignores.test.ts | 171 ++++++++++++ 9 files changed, 527 insertions(+), 1 deletion(-) create mode 100644 .changeset/init-tool-ignores.md create mode 100644 openspec/changes/init-tool-ignores/proposal.md create mode 100644 openspec/changes/init-tool-ignores/specs/cli-init/spec.md create mode 100644 openspec/changes/init-tool-ignores/tasks.md create mode 100644 packages/cli/src/install/tool-ignores.ts create mode 100644 packages/cli/test/tool-ignores.test.ts diff --git a/.changeset/init-tool-ignores.md b/.changeset/init-tool-ignores.md new file mode 100644 index 000000000..8574a0997 --- /dev/null +++ b/.changeset/init-tool-ignores.md @@ -0,0 +1,5 @@ +--- +"@taskless/cli": patch +--- + +`init` now tells you which ignore entries your formatter and linters need for Taskless's files. A formatter used to rewrite the files `init` owns (`.taskless/bin/cli.mjs`, `taskless.json`, the skill file), and a type-aware linter failed on rule fixtures, until each was excluded by hand. For each of prettier, eslint, biome, oxlint, ruff and black that it detects, `init` prints the file to edit and a snippet in that tool's syntax, and `init --json` carries the same list as `ignores`. It never edits those files itself, and a tool whose config already mentions `.taskless` is not named again. diff --git a/openspec/changes/init-tool-ignores/proposal.md b/openspec/changes/init-tool-ignores/proposal.md new file mode 100644 index 000000000..010976af8 --- /dev/null +++ b/openspec/changes/init-tool-ignores/proposal.md @@ -0,0 +1,17 @@ +## Why + +Issue #732, the first of its "two smaller things". After `taskless init`, a project's formatter (prettier) and type-aware linter (typescript-eslint) failed on files Taskless installed: `.taskless/bin/cli.mjs`, `cli.lock.json`, `taskless.json`, the skill file, and the rule fixtures under `.taskless/rules`. The person had to find and exclude each one by hand. A formatter that rewrites an installer-owned file also churns, because the next `init` writes it back; a fixture is code meant to trip a rule, outside any `tsconfig`, so a type-aware linter cannot parse it at all. + +## What Changes + +- `init` (batch and wizard) names, for each formatter or linter `detect` already recognises that walks the whole tree (prettier, eslint, biome, oxlint, ruff, black), the ignore entries it needs: `.taskless/` for every one, plus each tool directory's Taskless skill stub for prettier, which formats markdown. Each entry carries the file it goes in and a snippet in that tool's syntax. +- A tool is left out once its root config or ignore file mentions `.taskless` (for black, the escaped `\.taskless` its regex needs), so the notice disappears once the project has dealt with it and is not a permanent line in every `init`. +- `init --json` carries the same list as `ignores`, always present. The `init` recipe tells an agent to offer the edit, in the same commit as the install, and to make it only when the user agrees. +- `init` prints and never writes. These are the person's configs; several are code (`eslint.config.js`, `oxlint.config.ts`) or JSON with comments, none is a file `init` owns, and `init`'s only writes outside `.taskless/` are its own skill stubs and permission rules. +- `detect` is unchanged: it runs before anything is installed, so there is nothing yet to ignore and no stub paths to name. + +Not breaking. The bump is `patch`. + +## Delivery shape + +**Single PR.** One module, its call sites in `init` and the wizard, the recipe text and tests; the spec, implementation, and archive land together. diff --git a/openspec/changes/init-tool-ignores/specs/cli-init/spec.md b/openspec/changes/init-tool-ignores/specs/cli-init/spec.md new file mode 100644 index 000000000..a0d4e77b0 --- /dev/null +++ b/openspec/changes/init-tool-ignores/specs/cli-init/spec.md @@ -0,0 +1,36 @@ +## ADDED Requirements + +### Requirement: Init names the ignore entries a project's formatter and linters need + +After a successful install, `init` and the wizard SHALL report, for each of prettier, eslint, biome, oxlint, ruff and black that repository detection finds, the ignore entries that keep that tool off Taskless's files. Every such tool SHALL be given `.taskless/`; prettier SHALL also be given each reference target's Taskless skill directory. Each entry SHALL name the file the entries go in and SHALL render them in that tool's own syntax. + +A tool SHALL be left out when any of its root config or ignore files already contains `.taskless`, or for black the escaped form `\.taskless`. `init` SHALL NOT write any of these files. + +The batch install SHALL print the entries above the uncommitted-install notice, and the onboarding trailer SHALL stay the final line. Under `--json` the envelope SHALL carry them as `ignores`, always present and empty when none is needed, and stdout SHALL remain the envelope alone. + +#### Scenario: A detected formatter and linter are named + +- **WHEN** a user runs `taskless init` with `.claude/` selected in a project that has a `.prettierrc` and an `eslint.config.js` +- **THEN** `init` SHALL print `.taskless/` and `.claude/skills/taskless/` for `.prettierignore` +- **AND** SHALL print `{ ignores: [".taskless/"] }` for `eslint.config.js` + +#### Scenario: A tool that already ignores Taskless is left out + +- **WHEN** the project's `.prettierignore` already contains `.taskless/` +- **THEN** `init` SHALL NOT name prettier + +#### Scenario: Another tool's entry in a shared file does not count + +- **WHEN** `pyproject.toml` excludes `.taskless` under `[tool.ruff]` and configures `[tool.black]` without it +- **THEN** `init` SHALL name black and SHALL NOT name ruff + +#### Scenario: The envelope carries the entries + +- **WHEN** a user runs `taskless init --json` in a project with a detected prettier +- **THEN** the envelope's `ignores` SHALL hold a `prettier` entry with the patterns to add + +#### Scenario: No detected tool is silent + +- **WHEN** a user runs `taskless init` in a project with no detected formatter or linter +- **THEN** no ignore entries SHALL be printed +- **AND** the envelope's `ignores` SHALL be empty diff --git a/openspec/changes/init-tool-ignores/tasks.md b/openspec/changes/init-tool-ignores/tasks.md new file mode 100644 index 000000000..f4da2d421 --- /dev/null +++ b/openspec/changes/init-tool-ignores/tasks.md @@ -0,0 +1,10 @@ +## 1. Ignore entries + +- [x] 1.1 Add `packages/cli/src/install/tool-ignores.ts`: the entries each detected formatter and linter still needs, and their human rendering. +- [x] 1.2 Print them from batch `init` above the commit notice and from the wizard before its commit offer; add `ignores` to the `init --json` envelope. +- [x] 1.3 Describe `ignores` and the offer to apply it in `packages/cli/src/agent/init.md`. + +## 2. Tests and checks + +- [x] 2.1 Test detection, the already-handled skip (including ruff's entry not counting for black), the printed notice, and the envelope field. +- [x] 2.2 Run `pnpm typecheck`, `pnpm lint`, and the test suite; add a patch changeset. diff --git a/packages/cli/src/agent/init.md b/packages/cli/src/agent/init.md index 126b8c33e..45144690c 100644 --- a/packages/cli/src/agent/init.md +++ b/packages/cli/src/agent/init.md @@ -46,6 +46,13 @@ first step, not the whole job. so the user can include them in the commit they choose. Do not stage or commit on your own; the git operations are theirs. + When `ignores` is non-empty, the project's formatter or linters will + reach Taskless's files: a formatter rewrites what `init` owns, and a + type-aware linter fails on rule fixtures. Offer to add each entry's + `patterns` to its `file`, so the change can go in the same commit. + These are the user's configs: edit them only when they agree, and + keep every entry already there. + 3. **Offer the `pinnedCli` changes.** Go by each entry's `reason`: - `dependency`: Taskless runs through the project launcher, not as a project dependency. Offer to remove the dependency, point anything @@ -142,6 +149,11 @@ first step, not the whole job. "launcher": { "path": ".taskless/bin/cli.mjs", "state": "unchanged" }, "lockfile": { "path": ".taskless/bin/cli.lock.json", "state": "unchanged" }, "retired": [], + "ignores": [ + { "tool": "prettier", "file": ".prettierignore", + "patterns": [".taskless/", ".claude/skills/taskless/"], + "snippet": ".taskless/\n.claude/skills/taskless/" } + ], "telemetry": { "enabled": true } } ``` @@ -152,7 +164,8 @@ lines (or `SKIPPED:` with the reason), a `SKIPPED (global):` line for each missing or stale global trust entry, then a trailer naming the directories that changed and, after a version move, pointing at `update`, then a notice naming each -`pinnedCli` entry and what to do with it, and, when telemetry is on, a +`pinnedCli` entry and what to do with it, a notice naming each +`ignores` entry with the snippet to add, and, when telemetry is on, a notice naming its opt-outs. @@ -229,6 +242,13 @@ notice naming its opt-outs. here, along with the nightly's recorded version (its cached build is pruned) and its rules in `permissions[].removed`. The deletions are changes to commit. +- `ignores` is always present, empty when none is needed. Each entry is + a formatter or linter `detect` found (prettier, eslint, biome, oxlint, + ruff, black) whose root config does not mention `.taskless` yet: + `file` is where the entries go, `patterns` the entries in that tool's + syntax, and `snippet` the same as text to paste. Every tool gets + `.taskless/`; prettier, which formats markdown, also gets each tool + directory's Taskless skill stub. `init` never writes these files. ## For a person at a terminal diff --git a/packages/cli/src/commands/init.ts b/packages/cli/src/commands/init.ts index d8235e6c9..e3319d1e3 100644 --- a/packages/cli/src/commands/init.ts +++ b/packages/cli/src/commands/init.ts @@ -38,6 +38,11 @@ import { } from "../install/global-trust"; import { readInstallState } from "../install/state"; import { getUncommittedInstallNotice } from "../install/uncommitted"; +import { + describeToolIgnores, + findToolIgnores, + type ToolIgnore, +} from "../install/tool-ignores"; import { getTelemetry, isTelemetryEnabled, @@ -171,6 +176,9 @@ export const initCommand = defineCommand({ // Another package's launcher files this run removed: a release // install retires the nightly's. Always present, empty when none. retired: result.retired, + // The ignore entries each detected formatter and linter still needs + // for Taskless's files. Always present, empty when none. + ignores: result.ignores, // Always present, so the agent can tell the user telemetry is on // and how to turn it off; the human path prints the notice instead. telemetry: { enabled: telemetryEnabled }, @@ -242,6 +250,12 @@ export const initCommand = defineCommand({ ) { console.log(getWizardHint(getCliPrefix())); } + // Above the commit notice: an ignore entry added now goes in the same + // commit as the install. + const ignoreNotice = describeToolIgnores(result.ignores); + if (ignoreNotice !== undefined) { + console.log(ignoreNotice); + } if (telemetryEnabled) { console.log(TELEMETRY_NOTICE); } @@ -477,6 +491,8 @@ async function runNonInteractive( globalTrust: GlobalTrustOutcome[]; /** Whether the rules need `update --rules`, read after any stamp. */ rules: ReconcileStatus; + /** Ignore entries the project's formatter and linters still need. */ + ignores: ToolIgnore[]; }> { // Under `--json`, stdout carries only the envelope printed by the caller. // This per-target summary is not on that envelope (it is finer-grained than @@ -653,6 +669,7 @@ async function runNonInteractive( versionMoved({ previousCliVersion, cliVersion }), pinnedCli: await findCliPins(cwd, cliVersion, { migrated }), rules, + ignores: await findToolIgnores(cwd, plan), }; } diff --git a/packages/cli/src/install/tool-ignores.ts b/packages/cli/src/install/tool-ignores.ts new file mode 100644 index 000000000..b9a8eff4d --- /dev/null +++ b/packages/cli/src/install/tool-ignores.ts @@ -0,0 +1,243 @@ +import { readFile } from "node:fs/promises"; +import { join } from "node:path"; + +import { ESLINT_CONFIG_FILES } from "../detect/custom-rules"; +import { detectRepository } from "../detect/scan"; +import { CANONICAL_DIR, type InstallPlan } from "./install"; + +/** + * The ignore entries a project's own formatter and linters need once Taskless + * is installed (taskless/cli#732). + * + * `.taskless/` holds files the installer owns and rewrites on every `init` (the + * launcher, its lockfile, `taskless.json`, the canonical skills) and the rule + * fixtures, which are code that is meant to trip a rule and sits outside any + * `tsconfig`. A formatter that walks the tree rewrites the first kind, so the + * next `init` moves them back; a type-aware linter fails on the second kind + * outright. Each reference stub is also an installer-owned file, in a tool + * directory, and a markdown formatter reaches it. + * + * The CLI says what to add and does not write it: these are the person's + * configs, several are code (`eslint.config.js`, `oxlint.config.ts`) or JSON + * with comments, and none is a file `init` owns. + */ +export interface ToolIgnore { + /** The tool, as `detect` names it. */ + tool: string; + /** Where the entries go, as a person would look for it. */ + file: string; + /** The patterns to add, in the tool's own syntax. */ + patterns: string[]; + /** The same patterns as one copyable snippet for `file`. */ + snippet: string; +} + +interface IgnoreTarget { + tool: string; + /** + * Root files that hold this tool's ignores. Any of them mentioning + * {@link IgnoreTarget.needle} means the project already handled Taskless, + * and the tool is left out of the report. + */ + files: readonly string[]; + /** The text whose presence counts as handled. */ + needle: string; + /** Whether the tool formats markdown, and so reaches reference stubs. */ + markdown: boolean; + /** Where to put the entries, given the first of `files` that exists. */ + location: (found: string | undefined) => string; + render: (patterns: readonly string[]) => { + patterns: string[]; + snippet: string; + }; +} + +const quoted = (patterns: readonly string[]): string => + patterns.map((pattern) => JSON.stringify(pattern)).join(", "); + +const PYPROJECT = "pyproject.toml"; + +/** + * The formatters and linters that walk the whole tree and so reach + * `.taskless/`. A tool that reads only what a config names (stylelint reads + * CSS, which Taskless installs none of) is left out. + */ +const TARGETS: readonly IgnoreTarget[] = [ + { + tool: "prettier", + files: [".prettierignore"], + needle: ".taskless", + markdown: true, + location: () => ".prettierignore", + render: (patterns) => ({ + patterns: [...patterns], + snippet: patterns.join("\n"), + }), + }, + { + tool: "eslint", + files: [...ESLINT_CONFIG_FILES, ".eslintignore"], + needle: ".taskless", + markdown: false, + location: (found) => + found === undefined || found === ".eslintignore" + ? "your ESLint config" + : found, + render: (patterns) => ({ + patterns: [...patterns], + // A config object holding only `ignores` is a global ignore in a flat + // config, which is what keeps typescript-eslint from type-checking a + // fixture no tsconfig includes. + snippet: `{ ignores: [${quoted(patterns)}] }`, + }), + }, + { + tool: "biome", + files: ["biome.json", "biome.jsonc"], + needle: ".taskless", + markdown: false, + location: (found) => found ?? "biome.json", + render: (patterns) => { + const negated = patterns.map( + (pattern) => `!**/${pattern.replace(/\/$/, "")}/**` + ); + return { + patterns: negated, + snippet: `"files": { "includes": [..., ${quoted(negated)}] }`, + }; + }, + }, + { + tool: "oxlint", + files: [ + ".oxlintrc.json", + ".oxlintrc.jsonc", + "oxlint.config.ts", + "oxlint.config.mts", + ], + needle: ".taskless", + markdown: false, + location: (found) => found ?? ".oxlintrc.json", + render: (patterns) => { + const globbed = patterns.map((pattern) => `${pattern}**`); + return { + patterns: globbed, + snippet: `"ignorePatterns": [${quoted(globbed)}]`, + }; + }, + }, + { + tool: "ruff", + files: ["ruff.toml", ".ruff.toml", PYPROJECT], + needle: ".taskless", + markdown: false, + location: (found) => + found === undefined || found === PYPROJECT + ? `${PYPROJECT}, under [tool.ruff]` + : found, + render: (patterns) => { + const bare = patterns.map((pattern) => pattern.replace(/\/$/, "")); + return { + patterns: bare, + snippet: `extend-exclude = [${quoted(bare)}]`, + }; + }, + }, + { + tool: "black", + files: [PYPROJECT], + // black takes a regular expression, so its entry is the escaped form. + // ruff's plain `.taskless` in the same file does not count for black. + needle: String.raw`\.taskless`, + markdown: false, + location: () => `${PYPROJECT}, under [tool.black]`, + render: (patterns) => { + const expression = `/(${patterns + .map((pattern) => + pattern.replace(/\/$/, "").replaceAll(".", String.raw`\.`) + ) + .join("|")})/`; + return { + patterns: [expression], + snippet: `extend-exclude = '${expression}'`, + }; + }, + }, +]; + +async function readText(path: string): Promise { + try { + return await readFile(path, "utf8"); + } catch { + return undefined; + } +} + +/** + * The ignore entries each detected formatter and linter still needs, in the + * order {@link TARGETS} lists them. Empty when no such tool is detected, or + * when every one of them already mentions `.taskless` in its root config. + * + * "Mentions" is deliberately loose: a project that wrote any `.taskless` entry + * has made its own decision about the directory, and repeating the notice on + * every `init` after that would only teach people to skip it. + */ +export async function findToolIgnores( + cwd: string, + plan: InstallPlan +): Promise { + const { linters } = await detectRepository(cwd); + const detected = new Set(linters.map((linter) => linter.name)); + + const base = [`${CANONICAL_DIR}/`]; + const stubs = plan.targets + .filter((target) => target.mode === "reference") + .flatMap((target) => + target.skills.map((skill) => `${target.dir}/skills/${skill.name}/`) + ); + + const ignores: ToolIgnore[] = []; + for (const target of TARGETS) { + if (!detected.has(target.tool)) continue; + let found: string | undefined; + let handled = false; + for (const file of target.files) { + const text = await readText(join(cwd, file)); + if (text === undefined) continue; + found ??= file; + if (text.includes(target.needle)) { + handled = true; + break; + } + } + if (handled) continue; + const rendered = target.render( + target.markdown ? [...base, ...stubs] : base + ); + ignores.push({ + tool: target.tool, + file: target.location(found), + ...rendered, + }); + } + return ignores; +} + +/** + * The human form of {@link findToolIgnores}: one heading, then each tool with + * where its entries go and the snippet to paste. `undefined` when there is + * nothing to add. + */ +export function describeToolIgnores( + ignores: readonly ToolIgnore[] +): string | undefined { + if (ignores.length === 0) return undefined; + const lines = [ + "Exclude Taskless's files from your formatter and linters: init rewrites what is in .taskless/, and its rule fixtures are meant to fail. Add:", + ]; + for (const ignore of ignores) { + lines.push(` ${ignore.tool}, in ${ignore.file}:`); + for (const line of ignore.snippet.split("\n")) lines.push(` ${line}`); + } + return lines.join("\n"); +} diff --git a/packages/cli/src/wizard/index.ts b/packages/cli/src/wizard/index.ts index a46282253..cef524f9a 100644 --- a/packages/cli/src/wizard/index.ts +++ b/packages/cli/src/wizard/index.ts @@ -27,6 +27,7 @@ import { findCliPins, getPinnedCliNotice } from "../install/pinned-cli"; import { getReloadNotice } from "../install/reload-notice"; import { computeInstallDiff, readInstallState } from "../install/state"; import { findUncommitted, installedPaths } from "../install/uncommitted"; +import { describeToolIgnores, findToolIgnores } from "../install/tool-ignores"; import { getTelemetry, isTelemetryEnabled, @@ -202,6 +203,12 @@ export async function runWizard( ); } + // Before the commit offer, so an entry added now can go in that commit. + const ignoreNotice = describeToolIgnores( + await findToolIgnores(options.cwd, plan) + ); + if (ignoreNotice !== undefined) log.info(ignoreNotice); + if (await isTelemetryEnabled(options.cwd)) { log.info(`${TELEMETRY_NOTICE_TITLE}\n${TELEMETRY_NOTICE}`); } diff --git a/packages/cli/test/tool-ignores.test.ts b/packages/cli/test/tool-ignores.test.ts new file mode 100644 index 000000000..e1adf677f --- /dev/null +++ b/packages/cli/test/tool-ignores.test.ts @@ -0,0 +1,171 @@ +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; + +import { buildInstallPlan } from "../src/install/install"; +import { + describeToolIgnores, + findToolIgnores, +} from "../src/install/tool-ignores"; + +vi.mock("../src/telemetry", () => ({ + getTelemetry: () => + Promise.resolve({ capture: () => {}, shutdown: () => Promise.resolve() }), + isTelemetryEnabled: () => Promise.resolve(false), + TELEMETRY_NOTICE: "", + shutdownTelemetry: () => Promise.resolve(), +})); + +const { initCommand } = await import("../src/commands/init"); + +interface RunnableCommand { + run: (context: { + args: Record; + rawArgs: string[]; + }) => Promise; +} + +const skill = { name: "taskless", content: "", metadata: {} } as never; + +describe("findToolIgnores", () => { + let cwd: string; + + beforeEach(async () => { + cwd = await mkdtemp(join(tmpdir(), "taskless-tool-ignores-")); + }); + + afterEach(async () => { + await rm(cwd, { recursive: true, force: true }); + }); + + it("is empty when no formatter or linter is detected", async () => { + const plan = buildInstallPlan([".claude"], [skill]); + expect(await findToolIgnores(cwd, plan)).toEqual([]); + expect(describeToolIgnores([])).toBeUndefined(); + }); + + it("names .taskless/ for each detected tool, and the stubs for prettier", async () => { + await writeFile(join(cwd, ".prettierrc"), "{}\n"); + await writeFile(join(cwd, "eslint.config.js"), "export default [];\n"); + await writeFile(join(cwd, "ruff.toml"), "line-length = 100\n"); + const plan = buildInstallPlan([".claude"], [skill]); + + const ignores = await findToolIgnores(cwd, plan); + + expect(ignores).toEqual([ + { + tool: "prettier", + file: ".prettierignore", + patterns: [".taskless/", ".claude/skills/taskless/"], + snippet: ".taskless/\n.claude/skills/taskless/", + }, + { + tool: "eslint", + file: "eslint.config.js", + patterns: [".taskless/"], + snippet: '{ ignores: [".taskless/"] }', + }, + { + tool: "ruff", + file: "ruff.toml", + patterns: [".taskless"], + snippet: 'extend-exclude = [".taskless"]', + }, + ]); + }); + + it("leaves out a tool whose config already mentions .taskless", async () => { + await writeFile(join(cwd, ".prettierrc"), "{}\n"); + await writeFile(join(cwd, ".prettierignore"), "dist\n.taskless/\n"); + await writeFile( + join(cwd, "eslint.config.js"), + 'export default [{ ignores: [".taskless/**"] }];\n' + ); + const plan = buildInstallPlan([], [skill]); + + expect(await findToolIgnores(cwd, plan)).toEqual([]); + }); + + it("does not count ruff's entry as black's", async () => { + await writeFile( + join(cwd, "pyproject.toml"), + '[tool.ruff]\nextend-exclude = [".taskless"]\n\n[tool.black]\nline-length = 100\n' + ); + const plan = buildInstallPlan([], [skill]); + + const ignores = await findToolIgnores(cwd, plan); + + expect(ignores.map((ignore) => ignore.tool)).toEqual(["black"]); + expect(ignores[0]?.snippet).toBe( + String.raw`extend-exclude = '/(\.taskless)/'` + ); + }); +}); + +describe("init reports the ignore entries", () => { + let cwd: string; + let home: string; + let output: string[]; + + beforeEach(async () => { + cwd = await mkdtemp(join(tmpdir(), "taskless-init-ignores-")); + home = await mkdtemp(join(tmpdir(), "taskless-init-ignores-home-")); + vi.stubEnv("HOME", home); + await mkdir(join(cwd, ".claude")); + await writeFile(join(cwd, ".prettierrc"), "{}\n"); + output = []; + vi.spyOn(console, "log").mockImplementation((line: unknown) => { + output.push(String(line)); + }); + vi.spyOn(console, "error").mockImplementation(() => {}); + }); + + afterEach(async () => { + vi.restoreAllMocks(); + vi.unstubAllEnvs(); + await rm(cwd, { recursive: true, force: true }); + await rm(home, { recursive: true, force: true }); + }); + + function init(json: boolean) { + return (initCommand as unknown as RunnableCommand).run({ + args: { dir: cwd, json, anonymous: false }, + rawArgs: [], + }); + } + + it("prints the patterns to add", async () => { + await init(false); + + const notice = output.find((line) => + line.startsWith("Exclude Taskless's files") + ); + expect(notice).toContain(" prettier, in .prettierignore:"); + expect(notice).toContain(" .taskless/"); + expect(notice).toContain(" .claude/skills/taskless/"); + }); + + it("carries them on the --json envelope", async () => { + await init(true); + + const envelope = JSON.parse(output.at(-1) ?? "") as { + ignores: Array<{ tool: string; patterns: string[] }>; + }; + expect(envelope.ignores).toEqual([ + expect.objectContaining({ + tool: "prettier", + patterns: [".taskless/", ".claude/skills/taskless/"], + }), + ]); + }); + + it("says nothing once the project ignores .taskless", async () => { + await writeFile(join(cwd, ".prettierignore"), ".taskless/\n.claude/\n"); + await init(false); + + expect( + output.some((line) => line.startsWith("Exclude Taskless's files")) + ).toBe(false); + }); +}); From 2a945b4e3761c7580abe3a657e5c79c4578e8819 Mon Sep 17 00:00:00 2001 From: Jakob Heuser Date: Tue, 1 Dec 2026 23:35:18 -0800 Subject: [PATCH 2/3] chore(openspec): archive init-tool-ignores --- .../2026-12-01-init-tool-ignores}/proposal.md | 0 .../specs/cli-init/spec.md | 0 .../2026-12-01-init-tool-ignores}/tasks.md | 0 openspec/specs/cli-init/spec.md | 35 +++++++++++++++++++ 4 files changed, 35 insertions(+) rename openspec/changes/{init-tool-ignores => archive/2026-12-01-init-tool-ignores}/proposal.md (100%) rename openspec/changes/{init-tool-ignores => archive/2026-12-01-init-tool-ignores}/specs/cli-init/spec.md (100%) rename openspec/changes/{init-tool-ignores => archive/2026-12-01-init-tool-ignores}/tasks.md (100%) diff --git a/openspec/changes/init-tool-ignores/proposal.md b/openspec/changes/archive/2026-12-01-init-tool-ignores/proposal.md similarity index 100% rename from openspec/changes/init-tool-ignores/proposal.md rename to openspec/changes/archive/2026-12-01-init-tool-ignores/proposal.md diff --git a/openspec/changes/init-tool-ignores/specs/cli-init/spec.md b/openspec/changes/archive/2026-12-01-init-tool-ignores/specs/cli-init/spec.md similarity index 100% rename from openspec/changes/init-tool-ignores/specs/cli-init/spec.md rename to openspec/changes/archive/2026-12-01-init-tool-ignores/specs/cli-init/spec.md diff --git a/openspec/changes/init-tool-ignores/tasks.md b/openspec/changes/archive/2026-12-01-init-tool-ignores/tasks.md similarity index 100% rename from openspec/changes/init-tool-ignores/tasks.md rename to openspec/changes/archive/2026-12-01-init-tool-ignores/tasks.md diff --git a/openspec/specs/cli-init/spec.md b/openspec/specs/cli-init/spec.md index fa9ce1145..81b82af57 100644 --- a/openspec/specs/cli-init/spec.md +++ b/openspec/specs/cli-init/spec.md @@ -1452,3 +1452,38 @@ An install that finds a stub whose recovery instruction lacks this sentence SHAL - **WHEN** an install finds a stub whose recovery instruction names a restore command but not the launchers - **THEN** the install SHALL rewrite that stub - **AND** a subsequent install SHALL leave it untouched + +### Requirement: Init names the ignore entries a project's formatter and linters need + +After a successful install, `init` and the wizard SHALL report, for each of prettier, eslint, biome, oxlint, ruff and black that repository detection finds, the ignore entries that keep that tool off Taskless's files. Every such tool SHALL be given `.taskless/`; prettier SHALL also be given each reference target's Taskless skill directory. Each entry SHALL name the file the entries go in and SHALL render them in that tool's own syntax. + +A tool SHALL be left out when any of its root config or ignore files already contains `.taskless`, or for black the escaped form `\.taskless`. `init` SHALL NOT write any of these files. + +The batch install SHALL print the entries above the uncommitted-install notice, and the onboarding trailer SHALL stay the final line. Under `--json` the envelope SHALL carry them as `ignores`, always present and empty when none is needed, and stdout SHALL remain the envelope alone. + +#### Scenario: A detected formatter and linter are named + +- **WHEN** a user runs `taskless init` with `.claude/` selected in a project that has a `.prettierrc` and an `eslint.config.js` +- **THEN** `init` SHALL print `.taskless/` and `.claude/skills/taskless/` for `.prettierignore` +- **AND** SHALL print `{ ignores: [".taskless/"] }` for `eslint.config.js` + +#### Scenario: A tool that already ignores Taskless is left out + +- **WHEN** the project's `.prettierignore` already contains `.taskless/` +- **THEN** `init` SHALL NOT name prettier + +#### Scenario: Another tool's entry in a shared file does not count + +- **WHEN** `pyproject.toml` excludes `.taskless` under `[tool.ruff]` and configures `[tool.black]` without it +- **THEN** `init` SHALL name black and SHALL NOT name ruff + +#### Scenario: The envelope carries the entries + +- **WHEN** a user runs `taskless init --json` in a project with a detected prettier +- **THEN** the envelope's `ignores` SHALL hold a `prettier` entry with the patterns to add + +#### Scenario: No detected tool is silent + +- **WHEN** a user runs `taskless init` in a project with no detected formatter or linter +- **THEN** no ignore entries SHALL be printed +- **AND** the envelope's `ignores` SHALL be empty From cc86297d8ac3d6a8b9aef2ee0655acceab3847f0 Mon Sep 17 00:00:00 2001 From: Jakob Heuser Date: Tue, 1 Dec 2026 23:42:05 -0800 Subject: [PATCH 3/3] fix(init): point legacy ESLint at .eslintignore, and keep black's entry from counting for ruff Review findings on #735. --- .../specs/cli-init/spec.md | 14 +++- openspec/specs/cli-init/spec.md | 14 +++- packages/cli/src/install/tool-ignores.ts | 75 ++++++++++++++----- packages/cli/test/tool-ignores.test.ts | 37 +++++++++ 4 files changed, 118 insertions(+), 22 deletions(-) diff --git a/openspec/changes/archive/2026-12-01-init-tool-ignores/specs/cli-init/spec.md b/openspec/changes/archive/2026-12-01-init-tool-ignores/specs/cli-init/spec.md index a0d4e77b0..1799a10ed 100644 --- a/openspec/changes/archive/2026-12-01-init-tool-ignores/specs/cli-init/spec.md +++ b/openspec/changes/archive/2026-12-01-init-tool-ignores/specs/cli-init/spec.md @@ -4,7 +4,9 @@ After a successful install, `init` and the wizard SHALL report, for each of prettier, eslint, biome, oxlint, ruff and black that repository detection finds, the ignore entries that keep that tool off Taskless's files. Every such tool SHALL be given `.taskless/`; prettier SHALL also be given each reference target's Taskless skill directory. Each entry SHALL name the file the entries go in and SHALL render them in that tool's own syntax. -A tool SHALL be left out when any of its root config or ignore files already contains `.taskless`, or for black the escaped form `\.taskless`. `init` SHALL NOT write any of these files. +For eslint, the entries SHALL be a flat-config `ignores` object when the project has a flat config, or has no ESLint config file at all, and SHALL be `.eslintignore` lines when it has only a legacy `.eslintrc*` or `.eslintignore`. + +A tool SHALL be left out when any of its root config or ignore files already contains `.taskless` as a path, or for black the escaped form `\.taskless`. Black's escaped entry SHALL NOT count as another tool's. `init` SHALL NOT write any of these files. The batch install SHALL print the entries above the uncommitted-install notice, and the onboarding trailer SHALL stay the final line. Under `--json` the envelope SHALL carry them as `ignores`, always present and empty when none is needed, and stdout SHALL remain the envelope alone. @@ -24,6 +26,16 @@ The batch install SHALL print the entries above the uncommitted-install notice, - **WHEN** `pyproject.toml` excludes `.taskless` under `[tool.ruff]` and configures `[tool.black]` without it - **THEN** `init` SHALL name black and SHALL NOT name ruff +#### Scenario: Black's entry does not count as ruff's + +- **WHEN** `pyproject.toml` excludes `\.taskless` under `[tool.black]` and configures `[tool.ruff]` without it +- **THEN** `init` SHALL name ruff and SHALL NOT name black + +#### Scenario: A legacy ESLint config is pointed at .eslintignore + +- **WHEN** the project's only ESLint config is `.eslintrc.json` +- **THEN** `init` SHALL print `.taskless/` for `.eslintignore` + #### Scenario: The envelope carries the entries - **WHEN** a user runs `taskless init --json` in a project with a detected prettier diff --git a/openspec/specs/cli-init/spec.md b/openspec/specs/cli-init/spec.md index 81b82af57..e1b478197 100644 --- a/openspec/specs/cli-init/spec.md +++ b/openspec/specs/cli-init/spec.md @@ -1457,7 +1457,9 @@ An install that finds a stub whose recovery instruction lacks this sentence SHAL After a successful install, `init` and the wizard SHALL report, for each of prettier, eslint, biome, oxlint, ruff and black that repository detection finds, the ignore entries that keep that tool off Taskless's files. Every such tool SHALL be given `.taskless/`; prettier SHALL also be given each reference target's Taskless skill directory. Each entry SHALL name the file the entries go in and SHALL render them in that tool's own syntax. -A tool SHALL be left out when any of its root config or ignore files already contains `.taskless`, or for black the escaped form `\.taskless`. `init` SHALL NOT write any of these files. +For eslint, the entries SHALL be a flat-config `ignores` object when the project has a flat config, or has no ESLint config file at all, and SHALL be `.eslintignore` lines when it has only a legacy `.eslintrc*` or `.eslintignore`. + +A tool SHALL be left out when any of its root config or ignore files already contains `.taskless` as a path, or for black the escaped form `\.taskless`. Black's escaped entry SHALL NOT count as another tool's. `init` SHALL NOT write any of these files. The batch install SHALL print the entries above the uncommitted-install notice, and the onboarding trailer SHALL stay the final line. Under `--json` the envelope SHALL carry them as `ignores`, always present and empty when none is needed, and stdout SHALL remain the envelope alone. @@ -1477,6 +1479,16 @@ The batch install SHALL print the entries above the uncommitted-install notice, - **WHEN** `pyproject.toml` excludes `.taskless` under `[tool.ruff]` and configures `[tool.black]` without it - **THEN** `init` SHALL name black and SHALL NOT name ruff +#### Scenario: Black's entry does not count as ruff's + +- **WHEN** `pyproject.toml` excludes `\.taskless` under `[tool.black]` and configures `[tool.ruff]` without it +- **THEN** `init` SHALL name ruff and SHALL NOT name black + +#### Scenario: A legacy ESLint config is pointed at .eslintignore + +- **WHEN** the project's only ESLint config is `.eslintrc.json` +- **THEN** `init` SHALL print `.taskless/` for `.eslintignore` + #### Scenario: The envelope carries the entries - **WHEN** a user runs `taskless init --json` in a project with a detected prettier diff --git a/packages/cli/src/install/tool-ignores.ts b/packages/cli/src/install/tool-ignores.ts index b9a8eff4d..fd7203d00 100644 --- a/packages/cli/src/install/tool-ignores.ts +++ b/packages/cli/src/install/tool-ignores.ts @@ -37,16 +37,20 @@ interface IgnoreTarget { /** * Root files that hold this tool's ignores. Any of them mentioning * {@link IgnoreTarget.needle} means the project already handled Taskless, - * and the tool is left out of the report. + * and the tool is left out of the report. The first that exists is the one + * the report names, so they are listed in the order to prefer. */ files: readonly string[]; - /** The text whose presence counts as handled. */ - needle: string; + /** The entry whose presence counts as handled. */ + needle: RegExp; /** Whether the tool formats markdown, and so reaches reference stubs. */ markdown: boolean; /** Where to put the entries, given the first of `files` that exists. */ location: (found: string | undefined) => string; - render: (patterns: readonly string[]) => { + render: ( + patterns: readonly string[], + found: string | undefined + ) => { patterns: string[]; snippet: string; }; @@ -57,6 +61,25 @@ const quoted = (patterns: readonly string[]): string => const PYPROJECT = "pyproject.toml"; +/** + * `.taskless` as a path, not as black's escaped `\.taskless`. A shared + * `pyproject.toml` can hold black's entry and no ruff one, and a substring + * match would read the first as the second. + */ +const PLAIN = /(? + file.startsWith("eslint.config.") +); + +/** + * A project on legacy ESLint config: a `.eslintrc*` (or `.eslintignore`) and + * no flat config. Its ignores go in `.eslintignore`, since an `.eslintrc*` has + * no `ignores` key and a flat-config object pasted into one does nothing. + */ +const legacyEslint = (found: string | undefined): boolean => + found !== undefined && !FLAT_ESLINT_CONFIGS.includes(found); + /** * The formatters and linters that walk the whole tree and so reach * `.taskless/`. A tool that reads only what a config names (stylelint reads @@ -66,7 +89,7 @@ const TARGETS: readonly IgnoreTarget[] = [ { tool: "prettier", files: [".prettierignore"], - needle: ".taskless", + needle: PLAIN, markdown: true, location: () => ".prettierignore", render: (patterns) => ({ @@ -76,25 +99,36 @@ const TARGETS: readonly IgnoreTarget[] = [ }, { tool: "eslint", - files: [...ESLINT_CONFIG_FILES, ".eslintignore"], - needle: ".taskless", + // Flat configs first, so a project mid-migration with both is told the + // flat form, which is the one ESLint 9 reads. + files: [ + ...FLAT_ESLINT_CONFIGS, + ...ESLINT_CONFIG_FILES.filter( + (file) => !FLAT_ESLINT_CONFIGS.includes(file) + ), + ".eslintignore", + ], + needle: PLAIN, markdown: false, - location: (found) => - found === undefined || found === ".eslintignore" - ? "your ESLint config" - : found, - render: (patterns) => ({ + location: (found) => { + if (legacyEslint(found)) return ".eslintignore"; + return found ?? "your ESLint config"; + }, + render: (patterns, found) => ({ patterns: [...patterns], // A config object holding only `ignores` is a global ignore in a flat // config, which is what keeps typescript-eslint from type-checking a - // fixture no tsconfig includes. - snippet: `{ ignores: [${quoted(patterns)}] }`, + // fixture no tsconfig includes. With no config file found (only the + // dependency), the flat form is ESLint 9's default. + snippet: legacyEslint(found) + ? patterns.join("\n") + : `{ ignores: [${quoted(patterns)}] }`, }), }, { tool: "biome", files: ["biome.json", "biome.jsonc"], - needle: ".taskless", + needle: PLAIN, markdown: false, location: (found) => found ?? "biome.json", render: (patterns) => { @@ -115,7 +149,7 @@ const TARGETS: readonly IgnoreTarget[] = [ "oxlint.config.ts", "oxlint.config.mts", ], - needle: ".taskless", + needle: PLAIN, markdown: false, location: (found) => found ?? ".oxlintrc.json", render: (patterns) => { @@ -129,7 +163,7 @@ const TARGETS: readonly IgnoreTarget[] = [ { tool: "ruff", files: ["ruff.toml", ".ruff.toml", PYPROJECT], - needle: ".taskless", + needle: PLAIN, markdown: false, location: (found) => found === undefined || found === PYPROJECT @@ -148,7 +182,7 @@ const TARGETS: readonly IgnoreTarget[] = [ files: [PYPROJECT], // black takes a regular expression, so its entry is the escaped form. // ruff's plain `.taskless` in the same file does not count for black. - needle: String.raw`\.taskless`, + needle: /\\\.taskless/, markdown: false, location: () => `${PYPROJECT}, under [tool.black]`, render: (patterns) => { @@ -205,14 +239,15 @@ export async function findToolIgnores( const text = await readText(join(cwd, file)); if (text === undefined) continue; found ??= file; - if (text.includes(target.needle)) { + if (target.needle.test(text)) { handled = true; break; } } if (handled) continue; const rendered = target.render( - target.markdown ? [...base, ...stubs] : base + target.markdown ? [...base, ...stubs] : base, + found ); ignores.push({ tool: target.tool, diff --git a/packages/cli/test/tool-ignores.test.ts b/packages/cli/test/tool-ignores.test.ts index e1adf677f..4efdfec5a 100644 --- a/packages/cli/test/tool-ignores.test.ts +++ b/packages/cli/test/tool-ignores.test.ts @@ -87,6 +87,43 @@ describe("findToolIgnores", () => { expect(await findToolIgnores(cwd, plan)).toEqual([]); }); + it("does not count black's entry as ruff's", async () => { + await writeFile( + join(cwd, "pyproject.toml"), + "[tool.ruff]\nline-length = 100\n\n[tool.black]\nextend-exclude = '/(\\.taskless)/'\n" + ); + const plan = buildInstallPlan([], [skill]); + + const ignores = await findToolIgnores(cwd, plan); + + expect(ignores.map((ignore) => ignore.tool)).toEqual(["ruff"]); + }); + + it("points a legacy ESLint config at .eslintignore", async () => { + await writeFile(join(cwd, ".eslintrc.json"), "{}\n"); + const plan = buildInstallPlan([], [skill]); + + expect(await findToolIgnores(cwd, plan)).toEqual([ + { + tool: "eslint", + file: ".eslintignore", + patterns: [".taskless/"], + snippet: ".taskless/", + }, + ]); + }); + + it("prefers the flat config when both are present", async () => { + await writeFile(join(cwd, ".eslintrc.json"), "{}\n"); + await writeFile(join(cwd, "eslint.config.mjs"), "export default [];\n"); + const plan = buildInstallPlan([], [skill]); + + const [eslint] = await findToolIgnores(cwd, plan); + + expect(eslint?.file).toBe("eslint.config.mjs"); + expect(eslint?.snippet).toBe('{ ignores: [".taskless/"] }'); + }); + it("does not count ruff's entry as black's", async () => { await writeFile( join(cwd, "pyproject.toml"),