@testsprite/testsprite-cli 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  <a href="https://www.testsprite.com">
4
4
  <picture>
5
- <source media="(prefers-color-scheme: dark)" srcset="assets/testsprite-logo-dark.svg">
6
- <source media="(prefers-color-scheme: light)" srcset="assets/testsprite-logo-light.svg">
7
- <img src="assets/testsprite-logo-dark.svg" alt="TestSprite" width="420">
5
+ <source media="(prefers-color-scheme: dark)" srcset="assets/testsprite-logo-dark.png">
6
+ <source media="(prefers-color-scheme: light)" srcset="assets/testsprite-logo-light.png">
7
+ <img src="assets/testsprite-logo-light.png" alt="TestSprite" width="420">
8
8
  </picture>
9
9
  </a>
10
10
 
@@ -34,9 +34,9 @@ AI ships code in minutes — verifying it hasn't. `testsprite` opens your live a
34
34
 
35
35
  </div>
36
36
 
37
- https://github.com/user-attachments/assets/ab3105d5-4d5c-4a7b-b639-610f80fddc0e
37
+ <video src="https://github.com/user-attachments/assets/eca90a91-93ef-49f6-8d13-86b4eb25f4cf" controls muted></video>
38
38
 
39
- <p align="center"><sub><b>▶ Watch the launch video</b> — the three hard limits every coding agent hits, and the loop that breaks them (4 min).</sub></p>
39
+ <p align="center"><sub><b><a href="https://github.com/user-attachments/assets/eca90a91-93ef-49f6-8d13-86b4eb25f4cf">▶ Watch the launch video</a></b> — the three hard limits every coding agent hits, and the loop that breaks them (4 min).</sub></p>
40
40
 
41
41
  ---
42
42
 
@@ -58,15 +58,17 @@ Requires **Node.js ≥ 20**. (No global install? `npx @testsprite/testsprite-cli
58
58
 
59
59
  ```bash
60
60
  npm install -g @testsprite/testsprite-cli
61
- testsprite init
61
+ testsprite setup
62
62
  ```
63
63
 
64
- `testsprite init` prompts for your [API key](https://www.testsprite.com), verifies it, and installs the verification-loop skill for your coding agent (`claude`, `cursor`, `cline`, `antigravity`, `codex`, etc.). Non-interactive (CI / onboarding scripts):
64
+ `testsprite setup` prompts for your [API key](https://www.testsprite.com), verifies it, and installs the verification-loop skill for your coding agent (`claude`, `cursor`, `cline`, `antigravity`, `codex`, etc.) — one command, so your agent is wired to verify its own work. Non-interactive (CI / onboarding scripts):
65
65
 
66
66
  ```bash
67
- TESTSPRITE_API_KEY=sk-... testsprite init --from-env --yes --agent claude
67
+ TESTSPRITE_API_KEY=sk-... testsprite setup --from-env --yes --agent claude
68
68
  ```
69
69
 
70
+ > **Pointing a coding agent (Claude Code, Cursor, Codex, Cline, …) at TestSprite?** Have it run `testsprite setup` first — that installs the verification skill, so the agent knows how to create, run, and triage tests on its own (instead of guessing from this README). New here? Start with the **[getting-started overview](https://docs.testsprite.com/cli/getting-started/overview)**.
71
+
70
72
  From there, the loop runs on its own — an example session, typed by the coding agent:
71
73
 
72
74
  ```bash
@@ -89,10 +91,9 @@ Prefer to configure each step by hand (or learn the surface offline with `--dry-
89
91
 
90
92
  | Group | Command | What it does |
91
93
  | --------- | --------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
92
- | **Init** | `init` | One-shot onboarding: auth configure + whoami + agent install |
93
- | **Auth** | `auth configure` | Store an API key at `~/.testsprite/credentials` |
94
- | | `auth whoami` _(alias `status`)_ | Resolve the active profile to its user, key, env, and scopes |
95
- | | `auth logout` | Remove the active profile from the credentials file |
94
+ | **Setup** | `setup` | **Start here** — one command: configure your API key, verify it, and install the agent verification skill |
95
+ | **Auth** | `auth status` | Resolve the active profile to its user, key, env, and scopes |
96
+ | | `auth remove` | Remove the active profile from the credentials file |
96
97
  | **Read** | `project list` / `project get` | List projects / fetch one by id |
97
98
  | | `test list` / `test get` | List tests under a project / fetch one by id |
98
99
  | | `test code get` | Print (or write) the generated test source |
@@ -109,7 +110,9 @@ Prefer to configure each step by hand (or learn the surface offline with `--dry-
109
110
  | | `test rerun` | Cheap replay of one/many tests (FE verbatim; BE with deps); `--all --project <id>` reruns all tests |
110
111
  | | `test wait` | Block on a `runId` until terminal |
111
112
  | | `test artifact get` | Download the failure bundle for a specific `runId` |
112
- | **Agent** | `agent install` / `agent list` | Onboard a coding agent (pure-local); targets: `claude`, `codex`, `cursor`, `cline`, `antigravity` |
113
+ | **Agent** | `agent install` / `agent list` | Add or list coding-agent targets (pure-local): `claude`, `codex`, `cursor`, `cline`, `antigravity` |
114
+
115
+ > The earlier command names — `init`, `auth configure`, `auth whoami`, `auth logout` — still work as hidden, deprecated aliases (each prints a one-line notice pointing at the new name), so existing scripts keep running. `auth configure` now runs the full `setup` (it also installs the skill).
113
116
 
114
117
  📚 **Full reference — every command, flag, and example:** [DOCUMENTATION.md](./DOCUMENTATION.md), including [configuration & profiles](./DOCUMENTATION.md#configuration), [scripting](./DOCUMENTATION.md#output--scripting), and [exit codes](./DOCUMENTATION.md#exit-codes).
115
118
 
@@ -26,6 +26,16 @@ export interface AuthDeps {
26
26
  stdout?: (line: string) => void;
27
27
  stderr?: (line: string) => void;
28
28
  preludeWrite?: (chunk: string) => void;
29
+ /**
30
+ * Identifies the higher-level command that invoked `runConfigure`. When set,
31
+ * it is sent as the `X-CLI-Command` request header on the key-validation
32
+ * `GET /me` so the backend can attribute the call for product analytics —
33
+ * e.g. `init` is counted as `cli.initialized` instead of the generic
34
+ * `cli.session_started`. `auth configure` run directly leaves it unset.
35
+ * Advisory only: it never changes behavior, and the backend honors only a
36
+ * known allowlist value.
37
+ */
38
+ commandTag?: string;
29
39
  }
30
40
  type CommonOptions = FactoryCommonOptions;
31
41
  interface ConfigureOptions extends CommonOptions {
@@ -5,6 +5,7 @@ import { facadeBaseUrl } from '../lib/facade.js';
5
5
  import { HttpClient } from '../lib/http.js';
6
6
  import { defaultCredentialsPath, deleteProfile, readProfile, writeProfile, } from '../lib/credentials.js';
7
7
  import { loadConfig } from '../lib/config.js';
8
+ import { emitDeprecationNotice } from '../lib/deprecate.js';
8
9
  import { GLOBAL_OPTS_HINT, Output } from '../lib/output.js';
9
10
  import { promptSecret } from '../lib/prompt.js';
10
11
  const DEFAULT_API_URL = 'https://api.testsprite.com';
@@ -80,7 +81,11 @@ export async function runConfigure(opts, deps = {}) {
80
81
  fetchImpl: deps.fetchImpl,
81
82
  });
82
83
  try {
83
- await pingClient.get('/me');
84
+ // Tag the validation call with the originating command (when provided) so
85
+ // the backend attributes it for product analytics — e.g. `init` → the
86
+ // cli.initialized event instead of the generic cli.session_started. The
87
+ // header is advisory; omitting it changes nothing.
88
+ await pingClient.get('/me', deps.commandTag ? { headers: { 'x-cli-command': deps.commandTag } } : {});
84
89
  }
85
90
  catch (err) {
86
91
  const message = err instanceof Error ? err.message : String(err);
@@ -96,12 +101,10 @@ export async function runConfigure(opts, deps = {}) {
96
101
  const d = data;
97
102
  return `Profile "${d.profile}" configured. Endpoint: ${d.apiUrl}`;
98
103
  });
99
- // Self-bootstrap: nudge the user toward wiring their coding agent to TestSprite.
100
- // stderr + text-only + real-run-only so JSON consumers and dry-run previews stay clean.
101
- if (opts.output === 'text' && !opts.dryRun) {
102
- stderr('Tip: run `testsprite agent install --target=claude` to let your coding ' +
103
- 'agent run TestSprite tests automatically (also: cursor, cline, antigravity).');
104
- }
104
+ // Note: the old "run `testsprite agent install`" self-bootstrap tip was
105
+ // removed with the setup consolidation. `runConfigure` now only runs as part
106
+ // of `setup` (the sole credential-writing path), which installs the skill
107
+ // itself (unless --no-agent) — so the tip would be redundant or misleading.
105
108
  }
106
109
  export async function runWhoami(opts, deps = {}) {
107
110
  const out = makeOutput(opts.output, deps);
@@ -179,29 +182,40 @@ export async function runLogout(opts, deps = {}) {
179
182
  }
180
183
  export function createAuthCommand(deps = {}) {
181
184
  const auth = new Command('auth').description('Manage TestSprite credentials');
185
+ // `status` (primary; formerly `whoami`). Credential WRITES no longer live
186
+ // here — `auth configure` is a hidden, deprecated alias for `setup` (attached
187
+ // in index.ts), and `setup` is the only command that writes credentials.
182
188
  auth
183
- .command('configure')
184
- .description('Configure an API key for the active profile')
185
- .option('--from-env', 'Read TESTSPRITE_API_KEY (and optionally TESTSPRITE_API_URL) from the environment instead of prompting', false)
189
+ .command('status')
190
+ .description('Show the user, API key, env, and scopes bound to the active profile')
186
191
  .addHelpText('after', GLOBAL_OPTS_HINT)
187
- .action(async (cmdOpts, command) => {
188
- await runConfigure({ ...resolveCommonOptions(command), fromEnv: Boolean(cmdOpts.fromEnv) }, deps);
192
+ .action(async (_cmdOpts, command) => {
193
+ await runWhoami(resolveCommonOptions(command), deps);
189
194
  });
195
+ // `whoami` — hidden, deprecated alias for `status` (kept so scripts/agents
196
+ // on the old name keep working; invisible to --help).
190
197
  auth
191
- .command('whoami')
192
- .alias('status') // muscle-memory alias; `auth status` resolves to `auth whoami` (dogfood L1802)
193
- .description('Show the user, API key, and scopes bound to the active profile')
198
+ .command('whoami', { hidden: true })
194
199
  .addHelpText('after', GLOBAL_OPTS_HINT)
195
200
  .action(async (_cmdOpts, command) => {
201
+ emitDeprecationNotice('auth whoami', 'auth status', deps.stderr);
196
202
  await runWhoami(resolveCommonOptions(command), deps);
197
203
  });
198
204
  auth
199
- .command('logout')
205
+ .command('remove')
200
206
  .description('Remove credentials for the active profile')
201
207
  .addHelpText('after', GLOBAL_OPTS_HINT)
202
208
  .action(async (_cmdOpts, command) => {
203
209
  await runLogout(resolveCommonOptions(command), deps);
204
210
  });
211
+ // `logout` — hidden, deprecated alias for `remove`.
212
+ auth
213
+ .command('logout', { hidden: true })
214
+ .addHelpText('after', GLOBAL_OPTS_HINT)
215
+ .action(async (_cmdOpts, command) => {
216
+ emitDeprecationNotice('auth logout', 'auth remove', deps.stderr);
217
+ await runLogout(resolveCommonOptions(command), deps);
218
+ });
205
219
  return auth;
206
220
  }
207
221
  function resolveCommonOptions(command) {
@@ -59,5 +59,19 @@ export interface InitSummary {
59
59
  status: 'initialized';
60
60
  }
61
61
  export declare function runInit(opts: InitOptions, deps?: InitDeps): Promise<void>;
62
- export declare function createInitCommand(deps?: InitDeps): Command;
62
+ export declare function createSetupCommand(deps?: InitDeps): Command;
63
+ /**
64
+ * Hidden, deprecated `init` alias → runs `setup`. Kept so existing scripts and
65
+ * agents trained on the old command keep working; registered with
66
+ * `{ hidden: true }` in index.ts (invisible to `--help`) and prints a
67
+ * deprecation notice. (Setup consolidation.)
68
+ */
69
+ export declare function createDeprecatedInitCommand(deps?: InitDeps): Command;
70
+ /**
71
+ * Entry for the hidden, deprecated `auth configure` alias. Per the setup
72
+ * consolidation, `auth configure` now runs FULL setup (configure + install)
73
+ * so an agent that reaches for the old command still ends up with the skill.
74
+ * `setup` is the ONLY path that writes credentials.
75
+ */
76
+ export declare function runConfigureViaSetup(command: Command, deps: InitDeps, fromEnv: boolean): Promise<void>;
63
77
  export {};
@@ -10,6 +10,7 @@
10
10
  * Hard constraint: orchestrate existing exported primitives; never fork them.
11
11
  */
12
12
  import { Command } from 'commander';
13
+ import { emitDeprecationNotice } from '../lib/deprecate.js';
13
14
  import { CLIError } from '../lib/errors.js';
14
15
  import { GLOBAL_OPTS_HINT, Output } from '../lib/output.js';
15
16
  import { runConfigure, runWhoami } from './auth.js';
@@ -47,7 +48,7 @@ function resolveReportedEndpoint(opts, deps) {
47
48
  * and runWhoami's identity block are replaced by the init summary.
48
49
  * stderr (advisory messages, errors) flows through.
49
50
  */
50
- function toAuthDeps(deps, apiKey) {
51
+ function toAuthDeps(deps, apiKey, commandTag) {
51
52
  return {
52
53
  env: deps.env,
53
54
  credentialsPath: deps.credentialsPath,
@@ -61,6 +62,10 @@ function toAuthDeps(deps, apiKey) {
61
62
  // If an explicit API key was provided, override the prompt so configure
62
63
  // never actually prompts the user.
63
64
  prompt: apiKey ? { secret: async (_q) => apiKey } : deps.prompt,
65
+ // Telemetry attribution for the configure-validate GET /me. Passed only for
66
+ // the configure step (see runInit) — never whoami — so each init run emits
67
+ // exactly one cli.initialized event on the backend.
68
+ commandTag,
64
69
  };
65
70
  }
66
71
  /**
@@ -147,7 +152,11 @@ export async function runInit(opts, deps = {}) {
147
152
  // --api-key takes precedence over --from-env: when an explicit key is supplied,
148
153
  // force fromEnv=false so runConfigure uses the injected key (toAuthDeps wires it
149
154
  // as the prompt) instead of reading TESTSPRITE_API_KEY from the environment (codex).
150
- await runConfigure({ ...opts, fromEnv: opts.apiKey ? false : opts.fromEnv }, toAuthDeps(deps, opts.apiKey));
155
+ await runConfigure({ ...opts, fromEnv: opts.apiKey ? false : opts.fromEnv },
156
+ // commandTag:'init' tags ONLY this configure-validate GET /me with
157
+ // `X-CLI-Command: init` → counted as cli.initialized. The whoami banner call
158
+ // below builds deps WITHOUT a tag, so init emits exactly one cli.initialized.
159
+ toAuthDeps(deps, opts.apiKey, 'init'));
151
160
  // -------------------------------------------------------------------------
152
161
  // Step 2: Whoami banner — for identity display only; not used for validation
153
162
  // -------------------------------------------------------------------------
@@ -289,62 +298,96 @@ function parseRequestTimeoutFlag(raw) {
289
298
  return undefined;
290
299
  return Math.round(n * 1000);
291
300
  }
292
- export function createInitCommand(deps = {}) {
293
- const validTargets = Object.keys(TARGETS);
294
- const defaultAgent = 'claude';
295
- const cmd = new Command('init')
296
- .description('One-shot onboarding: configure an API key and install the coding-agent skill')
301
+ const SETUP_DESCRIPTION = 'Set up TestSprite: configure your API key and install the verification skill for your coding agent';
302
+ /** Attach the onboarding flags shared by `setup` and the `init` alias. */
303
+ function addSetupOptions(cmd, validTargets, defaultAgent) {
304
+ return cmd
297
305
  .option('--api-key <key>', 'API key to configure (skips the interactive prompt)')
298
306
  .option('--from-env', 'Read TESTSPRITE_API_KEY from the environment instead of prompting', false)
299
307
  .option('--agent <target>', `Coding-agent target to install: ${validTargets.join(', ')} (default: ${defaultAgent})`, defaultAgent)
300
308
  .option('--no-agent', 'Skip the agent skill install (configure credentials only)')
301
309
  .option('--force', 'Overwrite an existing skill file (a .bak backup is kept)')
302
310
  .option('--dir <path>', 'Project root for the skill install (default: current directory)')
303
- .option('-y, --yes', 'Non-interactive: accept all defaults, never prompt')
311
+ .option('-y, --yes', 'Non-interactive: accept all defaults, never prompt');
312
+ }
313
+ /** Build {@link InitOptions} from raw Commander opts + globals. */
314
+ function buildSetupOptions(cmdOpts, command, defaultAgent) {
315
+ const common = resolveCommonOptions(command);
316
+ // Commander sets `agent: false` (boolean) when `--no-agent` is passed,
317
+ // because `--no-agent` is the negation of `--agent <target>`. Guard against
318
+ // this: if agent is falsy (false or empty string) default to the CLI default
319
+ // so runInstall never receives a non-string target.
320
+ const resolvedAgent = cmdOpts.agent && typeof cmdOpts.agent === 'string' ? cmdOpts.agent : defaultAgent;
321
+ const isNoAgent = cmdOpts.noAgent === true || cmdOpts.agent === false;
322
+ // Detect conflict when both --no-agent and --agent <target> appear in the raw
323
+ // args. Commander only populates `rawArgs` on the ROOT command passed to
324
+ // parseAsync; subcommands have an empty array. Walk up to the root so we
325
+ // always inspect the full argv.
326
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
327
+ let root = command;
328
+ while (root.parent)
329
+ root = root.parent;
330
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
331
+ const rawArgs = root.rawArgs ?? process.argv;
332
+ const rawArgConflict = rawArgs.some((a) => a === '--no-agent') &&
333
+ rawArgs.some((a) => a === '--agent' || a.startsWith('--agent='));
334
+ return {
335
+ ...common,
336
+ apiKey: cmdOpts.apiKey,
337
+ fromEnv: Boolean(cmdOpts.fromEnv),
338
+ agent: resolvedAgent,
339
+ noAgent: isNoAgent,
340
+ force: Boolean(cmdOpts.force),
341
+ dir: cmdOpts.dir,
342
+ yes: Boolean(cmdOpts.yes),
343
+ rawArgConflict,
344
+ };
345
+ }
346
+ /** Shared action for `setup` and the deprecated `init` alias. */
347
+ async function runSetupAction(cmdOpts, command, deps, defaultAgent) {
348
+ const opts = buildSetupOptions(cmdOpts, command, defaultAgent);
349
+ // When --yes is supplied without a key source, force isTTY=false so runInit
350
+ // emits exit 5 with a clear message rather than hanging on a prompt in a
351
+ // headless CI environment where a TTY fd happens to be open.
352
+ const effectiveDeps = {
353
+ ...deps,
354
+ ...(opts.yes && !opts.apiKey && !opts.fromEnv ? { isTTY: false } : {}),
355
+ };
356
+ await runInit(opts, effectiveDeps);
357
+ }
358
+ export function createSetupCommand(deps = {}) {
359
+ const validTargets = Object.keys(TARGETS);
360
+ const defaultAgent = 'claude';
361
+ return addSetupOptions(new Command('setup'), validTargets, defaultAgent)
362
+ .description(SETUP_DESCRIPTION)
304
363
  .addHelpText('after', GLOBAL_OPTS_HINT)
305
364
  .action(async (cmdOpts, command) => {
306
- const common = resolveCommonOptions(command);
307
- // Commander sets `agent: false` (boolean) when `--no-agent` is passed,
308
- // because `--no-agent` is the negation of `--agent <target>`. Guard
309
- // against this: if agent is falsy (false or empty string) default to
310
- // the CLI default so runInstall never receives a non-string target.
311
- const resolvedAgent = cmdOpts.agent && typeof cmdOpts.agent === 'string' ? cmdOpts.agent : defaultAgent;
312
- const isNoAgent = cmdOpts.noAgent === true || cmdOpts.agent === false;
313
- // Fix 5: detect conflict when both --no-agent and --agent <target> appear
314
- // in the raw args. Thread the flag into runInit so it can emit the [warn]
315
- // via deps.stderr (testable) instead of process.stderr directly.
316
- //
317
- // Commander only populates `rawArgs` on the ROOT command passed to
318
- // parseAsync; subcommands have an empty array. Walk up to the root
319
- // so we always inspect the full argv.
320
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
321
- let root = command;
322
- while (root.parent)
323
- root = root.parent;
324
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
325
- const rawArgs = root.rawArgs ?? process.argv;
326
- const rawArgConflict = rawArgs.some((a) => a === '--no-agent') &&
327
- rawArgs.some((a) => a === '--agent' || a.startsWith('--agent='));
328
- const opts = {
329
- ...common,
330
- apiKey: cmdOpts.apiKey,
331
- fromEnv: Boolean(cmdOpts.fromEnv),
332
- agent: resolvedAgent,
333
- noAgent: isNoAgent,
334
- force: Boolean(cmdOpts.force),
335
- dir: cmdOpts.dir,
336
- yes: Boolean(cmdOpts.yes),
337
- rawArgConflict,
338
- };
339
- // When --yes is supplied without a key source, force isTTY=false so
340
- // runInit emits exit 5 with a clear message rather than hanging on a
341
- // prompt in a headless CI environment where a TTY fd happens to be open.
342
- const effectiveDeps = {
343
- ...deps,
344
- ...(opts.yes && !opts.apiKey && !opts.fromEnv ? { isTTY: false } : {}),
345
- };
346
- await runInit(opts, effectiveDeps);
365
+ await runSetupAction(cmdOpts, command, deps, defaultAgent);
347
366
  });
348
- return cmd;
367
+ }
368
+ /**
369
+ * Hidden, deprecated `init` alias → runs `setup`. Kept so existing scripts and
370
+ * agents trained on the old command keep working; registered with
371
+ * `{ hidden: true }` in index.ts (invisible to `--help`) and prints a
372
+ * deprecation notice. (Setup consolidation.)
373
+ */
374
+ export function createDeprecatedInitCommand(deps = {}) {
375
+ const validTargets = Object.keys(TARGETS);
376
+ const defaultAgent = 'claude';
377
+ return addSetupOptions(new Command('init'), validTargets, defaultAgent)
378
+ .description('(deprecated) alias for `setup`')
379
+ .action(async (cmdOpts, command) => {
380
+ emitDeprecationNotice('init', 'setup', deps.stderr);
381
+ await runSetupAction(cmdOpts, command, deps, defaultAgent);
382
+ });
383
+ }
384
+ /**
385
+ * Entry for the hidden, deprecated `auth configure` alias. Per the setup
386
+ * consolidation, `auth configure` now runs FULL setup (configure + install)
387
+ * so an agent that reaches for the old command still ends up with the skill.
388
+ * `setup` is the ONLY path that writes credentials.
389
+ */
390
+ export async function runConfigureViaSetup(command, deps, fromEnv) {
391
+ await runSetupAction({ agent: 'claude', fromEnv }, command, deps, 'claude');
349
392
  }
350
393
  //# sourceMappingURL=init.js.map
package/dist/index.js CHANGED
@@ -2,13 +2,14 @@
2
2
  import { Command, CommanderError } from 'commander';
3
3
  import { createAgentCommand } from './commands/agent.js';
4
4
  import { createAuthCommand } from './commands/auth.js';
5
- import { createInitCommand } from './commands/init.js';
5
+ import { createDeprecatedInitCommand, createSetupCommand, runConfigureViaSetup, } from './commands/init.js';
6
6
  import { createProjectCommand } from './commands/project.js';
7
7
  import { createTestCommand } from './commands/test.js';
8
8
  import { createUsageCommand } from './commands/usage.js';
9
9
  import { ApiError, CLIError, RequestTimeoutError } from './lib/errors.js';
10
10
  import { Output, isOutputMode } from './lib/output.js';
11
11
  import { rephraseUnknownOption } from './lib/render-error.js';
12
+ import { maybeEmitSkillNudge } from './lib/skill-nudge.js';
12
13
  import { VERSION } from './version.js';
13
14
  const program = new Command();
14
15
  // exitOverride() causes Commander to throw CommanderError instead of calling
@@ -28,11 +29,27 @@ program
28
29
  .option('--request-timeout <seconds>', 'Client-side per-request timeout in seconds (default: 120). Aborts any single fetch that does not complete within this deadline. ' +
29
30
  'Override via TESTSPRITE_REQUEST_TIMEOUT_MS env var (milliseconds). ' +
30
31
  'Range: 1–600. Does not affect the --timeout polling ceiling for `test run/wait`.');
31
- program.addCommand(createAgentCommand({}));
32
- program.addCommand(createAuthCommand());
33
- program.addCommand(createInitCommand({}));
32
+ // `setup` is the primary onboarding command, listed FIRST in --help so a coding
33
+ // agent reaches it before anything else. `init` is kept as a hidden, deprecated
34
+ // alias (invisible to --help; still works for existing scripts/agents).
35
+ program.addCommand(createSetupCommand({}));
36
+ program.addCommand(createDeprecatedInitCommand({}), { hidden: true });
37
+ // `auth configure` is a hidden, deprecated alias that runs FULL `setup`
38
+ // (configure + skill install), so an agent reaching for the old command still
39
+ // ends up with the skill. `setup` remains the ONLY path that writes credentials.
40
+ const authCommand = createAuthCommand();
41
+ authCommand
42
+ .command('configure', { hidden: true })
43
+ .option('--from-env', 'Read TESTSPRITE_API_KEY (and optionally TESTSPRITE_API_URL) from the environment instead of prompting', false)
44
+ .action(async (cmdOpts, command) => {
45
+ process.stderr.write('[deprecated] `testsprite auth configure` now runs full setup (configure + skill install) — ' +
46
+ 'use `testsprite setup` (add --no-agent to skip the skill).\n');
47
+ await runConfigureViaSetup(command, {}, Boolean(cmdOpts.fromEnv));
48
+ });
49
+ program.addCommand(authCommand);
34
50
  program.addCommand(createProjectCommand({}));
35
51
  program.addCommand(createTestCommand());
52
+ program.addCommand(createAgentCommand({}));
36
53
  program.addCommand(createUsageCommand());
37
54
  // Propagate exitOverride to every subcommand in the tree.
38
55
  // Commander's addCommand() does NOT inherit exitOverride from the parent,
@@ -53,6 +70,35 @@ program.configureOutput({
53
70
  write(rephrased !== null ? `${rephrased}\n` : str);
54
71
  },
55
72
  });
73
+ /**
74
+ * Render a leaf command's full path (group + leaf), e.g. `test run` /
75
+ * `auth whoami`, by walking parents up to (but not including) the root program.
76
+ */
77
+ function commandPathOf(cmd) {
78
+ const names = [];
79
+ let cur = cmd;
80
+ while (cur && cur.parent) {
81
+ names.unshift(cur.name());
82
+ cur = cur.parent;
83
+ }
84
+ return names.join(' ');
85
+ }
86
+ // Best-effort onboarding nudge (see lib/skill-nudge.ts): when a configured
87
+ // caller drives a verify-loop command in a project with no installed skill,
88
+ // point it at `testsprite setup`. A preAction hook runs before every leaf
89
+ // action; the helper self-gates (text-only, non-dry-run, a small command
90
+ // allowlist, opt-out via TESTSPRITE_NO_SKILL_WARNING) and never throws.
91
+ program.hook('preAction', (_thisCommand, actionCommand) => {
92
+ const globals = actionCommand.optsWithGlobals();
93
+ maybeEmitSkillNudge({
94
+ commandPath: commandPathOf(actionCommand),
95
+ output: isOutputMode(globals.output) ? globals.output : 'text',
96
+ dryRun: globals.dryRun ?? false,
97
+ profile: globals.profile ?? 'default',
98
+ cwd: process.cwd(),
99
+ env: process.env,
100
+ });
101
+ });
56
102
  try {
57
103
  await program.parseAsync(process.argv);
58
104
  }
@@ -24,9 +24,11 @@ export declare const MANAGED_SECTION_BEGIN = "<!-- BEGIN TESTSPRITE AGENT SECTIO
24
24
  export declare const MANAGED_SECTION_END = "<!-- END TESTSPRITE AGENT SECTION -->";
25
25
  type ReadFn = (url: URL) => string;
26
26
  /**
27
- * Load the canonical skill body. `../assets/...` resolves to `src/assets/...`
28
- * under vitest (source) and `dist/assets/...` in the built binary — postbuild
29
- * copies the tree so both paths exist.
27
+ * Load the canonical skill body. `../../skills/...` resolves to the repo-root
28
+ * `skills/` directory in BOTH source (vitest: `src/lib/` → `../../skills`) and
29
+ * the built/published package (`dist/lib/` → `../../skills` = package root). The
30
+ * directory ships verbatim via package.json `files`, so no build-time copy step
31
+ * is needed (unlike the old `src/assets` → `dist/assets` mirror).
30
32
  *
31
33
  * Injectable `read` fn keeps unit tests off disk.
32
34
  */
@@ -64,21 +64,23 @@ export const MANAGED_SECTION_BEGIN = '<!-- BEGIN TESTSPRITE AGENT SECTION (tests
64
64
  export const MANAGED_SECTION_END = '<!-- END TESTSPRITE AGENT SECTION -->';
65
65
  const defaultRead = (url) => readFileSync(url, 'utf8');
66
66
  /**
67
- * Load the canonical skill body. `../assets/...` resolves to `src/assets/...`
68
- * under vitest (source) and `dist/assets/...` in the built binary — postbuild
69
- * copies the tree so both paths exist.
67
+ * Load the canonical skill body. `../../skills/...` resolves to the repo-root
68
+ * `skills/` directory in BOTH source (vitest: `src/lib/` → `../../skills`) and
69
+ * the built/published package (`dist/lib/` → `../../skills` = package root). The
70
+ * directory ships verbatim via package.json `files`, so no build-time copy step
71
+ * is needed (unlike the old `src/assets` → `dist/assets` mirror).
70
72
  *
71
73
  * Injectable `read` fn keeps unit tests off disk.
72
74
  */
73
75
  export function loadSkillBody(read = defaultRead) {
74
- return read(new URL('../assets/agent-skill/testsprite-verify.skill.md', import.meta.url));
76
+ return read(new URL('../../skills/testsprite-verify.skill.md', import.meta.url));
75
77
  }
76
78
  /**
77
79
  * Load the trimmed codex skill body (plain Markdown, no frontmatter).
78
80
  * Designed for AGENTS.md managed-section injection.
79
81
  */
80
82
  export function loadCodexSkillBody(read = defaultRead) {
81
- return read(new URL('../assets/agent-skill/testsprite-verify.codex.md', import.meta.url));
83
+ return read(new URL('../../skills/testsprite-verify.codex.md', import.meta.url));
82
84
  }
83
85
  /**
84
86
  * Convenience for piece-2: returns the exact bytes to write for a target.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Shared helper for the hidden, deprecated command aliases introduced by the
3
+ * setup consolidation (`init`/`auth configure`/`auth whoami`/`auth logout`).
4
+ *
5
+ * The aliases are hidden from `--help` (so a coding agent never sees the old
6
+ * names) but still work (so existing scripts and any agent trained on the old
7
+ * commands keep running). When invoked, they print this one-line notice to
8
+ * stderr — stdout stays clean so JSON pipelines are unaffected.
9
+ */
10
+ export declare function emitDeprecationNotice(oldCmd: string, newCmd: string, stderr?: (line: string) => void): void;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Shared helper for the hidden, deprecated command aliases introduced by the
3
+ * setup consolidation (`init`/`auth configure`/`auth whoami`/`auth logout`).
4
+ *
5
+ * The aliases are hidden from `--help` (so a coding agent never sees the old
6
+ * names) but still work (so existing scripts and any agent trained on the old
7
+ * commands keep running). When invoked, they print this one-line notice to
8
+ * stderr — stdout stays clean so JSON pipelines are unaffected.
9
+ */
10
+ export function emitDeprecationNotice(oldCmd, newCmd, stderr = (line) => process.stderr.write(`${line}\n`)) {
11
+ stderr(`[deprecated] \`testsprite ${oldCmd}\` is deprecated — use \`testsprite ${newCmd}\`.`);
12
+ }
13
+ //# sourceMappingURL=deprecate.js.map
@@ -174,8 +174,8 @@ export class ApiError extends CLIError {
174
174
  return new ApiError({
175
175
  code: 'AUTH_REQUIRED',
176
176
  message: 'Authentication is required.',
177
- nextAction: 'Run `testsprite auth configure` (interactive — prompts for your API key),' +
178
- ' or set TESTSPRITE_API_KEY and run `testsprite auth configure --from-env` for non-interactive flows.',
177
+ nextAction: 'Run `testsprite setup` (interactive — prompts for your API key and installs the verification skill),' +
178
+ ' or set TESTSPRITE_API_KEY and run `testsprite setup --from-env` for non-interactive flows.',
179
179
  requestId,
180
180
  details: {},
181
181
  });
@@ -335,7 +335,7 @@ function parseEnvelopeBody(raw, httpStatus, apiUrl) {
335
335
  ? `${message} — endpoint not available on the current backend deployment.`
336
336
  : message,
337
337
  nextAction: isRouteMissing404
338
- ? 'Verify the CLI is targeting the right environment (check `testsprite auth whoami` for `env`), and confirm the backend has the corresponding M3.3 piece deployed.'
338
+ ? 'Verify the CLI is targeting the right environment (check `testsprite auth status` for `env`), and confirm the backend has the corresponding M3.3 piece deployed.'
339
339
  : '',
340
340
  requestId: 'unknown',
341
341
  details: { statusCode: obj.statusCode },
package/dist/lib/http.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from 'node:crypto';
2
2
  import { ApiError, RequestTimeoutError, TransportError } from './errors.js';
3
+ import { VERSION } from '../version.js';
3
4
  /**
4
5
  * Default per-request timeout (120s). Comfortably covers every metadata/read
5
6
  * request and every <=25s long-poll request (`?waitSeconds` is capped at 25
@@ -423,7 +424,7 @@ export class HttpClient {
423
424
  const headers = {
424
425
  'x-request-id': requestId,
425
426
  accept: 'application/json',
426
- 'user-agent': 'testsprite-cli',
427
+ 'user-agent': `testsprite-cli/${VERSION}`,
427
428
  };
428
429
  // The CLI v1 facade authenticates via `x-api-key`.
429
430
  // (securitySchemes.ApiKeyAuth). Sending only Authorization Bearer would be
@@ -0,0 +1,73 @@
1
+ import type { OutputMode } from './output.js';
2
+ /**
3
+ * Full command paths (group + leaf) that signal the caller is actively driving
4
+ * the verification loop — running or authoring tests, or checking auth in
5
+ * preflight. The skill nudge fires ONLY for these.
6
+ *
7
+ * Deliberately excluded:
8
+ * - `setup` / `init` / `agent install` — they ARE the fix; nudging is circular.
9
+ * - read-only inspection (`test list/get/result/...`, `project list/get`) —
10
+ * keeps an agent that is merely browsing from being nagged.
11
+ * - `auth configure` / `auth remove` (and the deprecated `auth logout`) —
12
+ * credential management, not the loop.
13
+ *
14
+ * Match the strings emitted by `commandPathOf` in `src/index.ts`. `auth status`
15
+ * is the primary identity command; `auth whoami` is its deprecated alias and is
16
+ * listed too so the warning fires regardless of which name the caller uses.
17
+ */
18
+ export declare const SKILL_NUDGE_COMMANDS: ReadonlySet<string>;
19
+ /**
20
+ * Env var that silences the warning. For CI, or users who deliberately drive
21
+ * the CLI by hand without wiring a coding agent.
22
+ */
23
+ export declare const SKILL_NUDGE_OPT_OUT_ENV = "TESTSPRITE_NO_SKILL_WARNING";
24
+ export interface SkillPresenceDeps {
25
+ existsSync?: (p: string) => boolean;
26
+ readFileSync?: (p: string) => string;
27
+ }
28
+ /**
29
+ * True if the `testsprite-verify` skill is installed for ANY supported agent in
30
+ * `dir`. own-file targets (claude/cursor/cline/antigravity): the landing file
31
+ * exists. managed-section target (codex / AGENTS.md): the file exists AND
32
+ * carries our BEGIN sentinel — a user-authored AGENTS.md without the sentinel
33
+ * does NOT count as our skill.
34
+ *
35
+ * The TARGETS table is the single source of truth for landing paths, so this
36
+ * stays in lockstep with `agent install` without re-listing paths. Best-effort:
37
+ * a per-target read error is swallowed (that target is treated as absent).
38
+ */
39
+ export declare function isVerifySkillInstalled(dir: string, deps?: SkillPresenceDeps): boolean;
40
+ export interface SkillNudgeContext {
41
+ /** Full command path, e.g. "test run" / "auth whoami". */
42
+ commandPath: string;
43
+ output: OutputMode;
44
+ dryRun: boolean;
45
+ profile: string;
46
+ cwd: string;
47
+ env: NodeJS.ProcessEnv;
48
+ /** Override the credentials file location (tests). */
49
+ credentialsPath?: string;
50
+ /** Override the profile lookup (tests); defaults to the real `readProfile`. */
51
+ readProfileImpl?: (profile: string, opts: {
52
+ path: string;
53
+ }) => {
54
+ apiKey?: string;
55
+ } | undefined;
56
+ /** Sink for the hint line; defaults to `process.stderr`. */
57
+ stderr?: (line: string) => void;
58
+ existsSync?: (p: string) => boolean;
59
+ readFileSync?: (p: string) => string;
60
+ }
61
+ /**
62
+ * Best-effort onboarding warning. When a configured caller drives a verify-loop
63
+ * command in a project that has NO installed skill, print a one-line `[warn]`
64
+ * line to stderr pointing at `testsprite setup`. Reaches a coding agent at the
65
+ * exact moment it uses the CLI without the skill wired up.
66
+ *
67
+ * Gates (all must pass to emit): text output (never pollutes `--output json`),
68
+ * not `--dry-run`, the command is in {@link SKILL_NUDGE_COMMANDS}, the opt-out
69
+ * env is unset, the active profile has an api key (un-configured callers hit an
70
+ * auth error that already points at setup), and the skill is not already
71
+ * installed. Never throws and never blocks the command — any error is swallowed.
72
+ */
73
+ export declare function maybeEmitSkillNudge(ctx: SkillNudgeContext): void;
@@ -0,0 +1,115 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { MANAGED_SECTION_BEGIN, TARGETS } from './agent-targets.js';
4
+ import { defaultCredentialsPath, readProfile } from './credentials.js';
5
+ /**
6
+ * Full command paths (group + leaf) that signal the caller is actively driving
7
+ * the verification loop — running or authoring tests, or checking auth in
8
+ * preflight. The skill nudge fires ONLY for these.
9
+ *
10
+ * Deliberately excluded:
11
+ * - `setup` / `init` / `agent install` — they ARE the fix; nudging is circular.
12
+ * - read-only inspection (`test list/get/result/...`, `project list/get`) —
13
+ * keeps an agent that is merely browsing from being nagged.
14
+ * - `auth configure` / `auth remove` (and the deprecated `auth logout`) —
15
+ * credential management, not the loop.
16
+ *
17
+ * Match the strings emitted by `commandPathOf` in `src/index.ts`. `auth status`
18
+ * is the primary identity command; `auth whoami` is its deprecated alias and is
19
+ * listed too so the warning fires regardless of which name the caller uses.
20
+ */
21
+ export const SKILL_NUDGE_COMMANDS = new Set([
22
+ 'test run',
23
+ 'test rerun',
24
+ 'test create',
25
+ 'test create-batch',
26
+ 'auth status',
27
+ 'auth whoami',
28
+ ]);
29
+ /**
30
+ * Env var that silences the warning. For CI, or users who deliberately drive
31
+ * the CLI by hand without wiring a coding agent.
32
+ */
33
+ export const SKILL_NUDGE_OPT_OUT_ENV = 'TESTSPRITE_NO_SKILL_WARNING';
34
+ /**
35
+ * True if the `testsprite-verify` skill is installed for ANY supported agent in
36
+ * `dir`. own-file targets (claude/cursor/cline/antigravity): the landing file
37
+ * exists. managed-section target (codex / AGENTS.md): the file exists AND
38
+ * carries our BEGIN sentinel — a user-authored AGENTS.md without the sentinel
39
+ * does NOT count as our skill.
40
+ *
41
+ * The TARGETS table is the single source of truth for landing paths, so this
42
+ * stays in lockstep with `agent install` without re-listing paths. Best-effort:
43
+ * a per-target read error is swallowed (that target is treated as absent).
44
+ */
45
+ export function isVerifySkillInstalled(dir, deps = {}) {
46
+ const exists = deps.existsSync ?? existsSync;
47
+ const read = deps.readFileSync ?? ((p) => readFileSync(p, 'utf8'));
48
+ for (const spec of Object.values(TARGETS)) {
49
+ const full = join(dir, spec.path);
50
+ if (!exists(full))
51
+ continue;
52
+ if (spec.mode === 'managed-section') {
53
+ try {
54
+ if (read(full).includes(MANAGED_SECTION_BEGIN))
55
+ return true;
56
+ }
57
+ catch {
58
+ // unreadable AGENTS.md → treat this target as absent, keep checking
59
+ }
60
+ continue;
61
+ }
62
+ return true; // own-file landing file present
63
+ }
64
+ return false;
65
+ }
66
+ /**
67
+ * Best-effort onboarding warning. When a configured caller drives a verify-loop
68
+ * command in a project that has NO installed skill, print a one-line `[warn]`
69
+ * line to stderr pointing at `testsprite setup`. Reaches a coding agent at the
70
+ * exact moment it uses the CLI without the skill wired up.
71
+ *
72
+ * Gates (all must pass to emit): text output (never pollutes `--output json`),
73
+ * not `--dry-run`, the command is in {@link SKILL_NUDGE_COMMANDS}, the opt-out
74
+ * env is unset, the active profile has an api key (un-configured callers hit an
75
+ * auth error that already points at setup), and the skill is not already
76
+ * installed. Never throws and never blocks the command — any error is swallowed.
77
+ */
78
+ export function maybeEmitSkillNudge(ctx) {
79
+ try {
80
+ if (ctx.output !== 'text')
81
+ return;
82
+ if (ctx.dryRun)
83
+ return;
84
+ if (isTruthyEnv(ctx.env[SKILL_NUDGE_OPT_OUT_ENV]))
85
+ return;
86
+ if (!SKILL_NUDGE_COMMANDS.has(ctx.commandPath))
87
+ return;
88
+ const credsPath = ctx.credentialsPath ?? defaultCredentialsPath();
89
+ const lookup = ctx.readProfileImpl ?? readProfile;
90
+ const profile = lookup(ctx.profile, { path: credsPath });
91
+ if (!profile?.apiKey)
92
+ return;
93
+ if (isVerifySkillInstalled(ctx.cwd, {
94
+ existsSync: ctx.existsSync,
95
+ readFileSync: ctx.readFileSync,
96
+ })) {
97
+ return;
98
+ }
99
+ const write = ctx.stderr ?? ((line) => process.stderr.write(`${line}\n`));
100
+ write('[warn] No TestSprite verification skill is installed in this project — your coding ' +
101
+ 'agent will not verify its changes against TestSprite. Run `testsprite setup` (or ' +
102
+ `\`testsprite agent install\`) to set it up. Silence: ${SKILL_NUDGE_OPT_OUT_ENV}=1`);
103
+ }
104
+ catch {
105
+ // A nudge must never break, delay, or alter the exit status of a real
106
+ // command. Swallow everything (missing creds file, fs races, etc.).
107
+ }
108
+ }
109
+ function isTruthyEnv(v) {
110
+ if (v === undefined)
111
+ return false;
112
+ const s = v.trim().toLowerCase();
113
+ return s !== '' && s !== '0' && s !== 'false' && s !== 'no';
114
+ }
115
+ //# sourceMappingURL=skill-nudge.js.map
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.1.0";
1
+ export declare const VERSION = "0.1.2";
package/dist/version.js CHANGED
@@ -1,2 +1,4 @@
1
- export const VERSION = '0.1.0';
1
+ // AUTO-GENERATED by scripts/generate-version.mjs — do not edit by hand.
2
+ // Run `npm run build` (or `npm run generate:version`) to regenerate.
3
+ export const VERSION = '0.1.2';
2
4
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@testsprite/testsprite-cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Official TestSprite command-line interface",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -9,9 +9,12 @@
9
9
  },
10
10
  "files": [
11
11
  "dist",
12
+ "skills",
12
13
  "!dist/**/*.map"
13
14
  ],
14
15
  "scripts": {
16
+ "generate:version": "node scripts/generate-version.mjs",
17
+ "prebuild": "node scripts/generate-version.mjs",
15
18
  "build": "tsc -p tsconfig.build.json && node scripts/postbuild.mjs",
16
19
  "clean": "rm -rf dist coverage",
17
20
  "lint": "eslint .",
@@ -113,7 +113,7 @@ testsprite test create --plan-from plan.json --dry-run --output json
113
113
 
114
114
  ```bash
115
115
  npm install -g @testsprite/testsprite-cli
116
- testsprite init # configure + verify + install agent skill in one shot
116
+ testsprite setup # configure + verify + install agent skill in one shot
117
117
  ```
118
118
 
119
- Or step-by-step: `testsprite auth configure` → `testsprite auth whoami`.
119
+ Verify your setup anytime: `testsprite auth status`.