@testsprite/testsprite-cli 0.16.0 → 0.17.0

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.
Files changed (206) hide show
  1. package/README.md +51 -147
  2. package/dist/commands/agent.d.ts +12 -4
  3. package/dist/commands/agent.js +48 -63
  4. package/dist/commands/auth.d.ts +6 -10
  5. package/dist/commands/auth.js +38 -54
  6. package/dist/commands/ci.d.ts +23 -100
  7. package/dist/commands/ci.js +293 -487
  8. package/dist/commands/conversation.d.ts +27 -0
  9. package/dist/commands/conversation.js +702 -0
  10. package/dist/commands/doctor.d.ts +5 -1
  11. package/dist/commands/doctor.js +129 -34
  12. package/dist/commands/init.d.ts +4 -45
  13. package/dist/commands/init.js +108 -66
  14. package/dist/commands/project-env.d.ts +62 -2
  15. package/dist/commands/project-env.js +388 -37
  16. package/dist/commands/project-sign-in.d.ts +0 -48
  17. package/dist/commands/project-sign-in.js +1 -229
  18. package/dist/commands/project.d.ts +15 -186
  19. package/dist/commands/project.js +89 -924
  20. package/dist/commands/result.d.ts +10 -0
  21. package/dist/commands/result.js +215 -0
  22. package/dist/commands/schedule.d.ts +0 -29
  23. package/dist/commands/schedule.js +28 -87
  24. package/dist/commands/test.d.ts +301 -1816
  25. package/dist/commands/test.js +1951 -13902
  26. package/dist/commands/testlist.d.ts +128 -5
  27. package/dist/commands/testlist.js +269 -339
  28. package/dist/commands/tunnel.d.ts +2 -2
  29. package/dist/commands/tunnel.js +23 -19
  30. package/dist/commands/usage.d.ts +12 -45
  31. package/dist/commands/usage.js +50 -131
  32. package/dist/index.js +182 -104
  33. package/dist/lib/agent-detect.js +9 -5
  34. package/dist/lib/agent-targets.d.ts +21 -2
  35. package/dist/lib/agent-targets.js +88 -11
  36. package/dist/lib/args.d.ts +13 -0
  37. package/dist/lib/args.js +49 -0
  38. package/dist/lib/basic-auth.d.ts +3 -0
  39. package/dist/lib/basic-auth.js +15 -0
  40. package/dist/lib/billing-refusal.js +4 -3
  41. package/dist/lib/ci-linkage.d.ts +4 -82
  42. package/dist/lib/ci-linkage.js +4 -157
  43. package/dist/lib/ci-run.js +1 -1
  44. package/dist/lib/client-factory.d.ts +10 -2
  45. package/dist/lib/client-factory.js +38 -26
  46. package/dist/lib/commit-signal.d.ts +65 -0
  47. package/dist/lib/commit-signal.js +305 -0
  48. package/dist/lib/concurrency-limiter.d.ts +6 -0
  49. package/dist/lib/concurrency-limiter.js +29 -0
  50. package/dist/lib/config.js +10 -5
  51. package/dist/lib/conflict-reason.d.ts +9 -3
  52. package/dist/lib/conflict-reason.js +6 -3
  53. package/dist/lib/conversation/answers.d.ts +9 -0
  54. package/dist/lib/conversation/answers.js +49 -0
  55. package/dist/lib/conversation/api.d.ts +71 -0
  56. package/dist/lib/conversation/api.js +150 -0
  57. package/dist/lib/conversation/change.d.ts +31 -0
  58. package/dist/lib/conversation/change.js +124 -0
  59. package/dist/lib/conversation/context.d.ts +19 -0
  60. package/dist/lib/conversation/context.js +70 -0
  61. package/dist/lib/conversation/environment.d.ts +15 -0
  62. package/dist/lib/conversation/environment.js +33 -0
  63. package/dist/lib/conversation/follow.d.ts +24 -0
  64. package/dist/lib/conversation/follow.js +42 -0
  65. package/dist/lib/conversation/render.d.ts +33 -0
  66. package/dist/lib/conversation/render.js +315 -0
  67. package/dist/lib/conversation/title.d.ts +2 -0
  68. package/dist/lib/conversation/title.js +18 -0
  69. package/dist/lib/conversation/types.d.ts +156 -0
  70. package/dist/lib/conversation/types.js +6 -0
  71. package/dist/lib/credentials.js +67 -11
  72. package/dist/lib/cron.d.ts +1 -1
  73. package/dist/lib/cron.js +2 -2
  74. package/dist/lib/dispatch-stop.d.ts +20 -0
  75. package/dist/lib/dispatch-stop.js +30 -0
  76. package/dist/lib/download.d.ts +71 -0
  77. package/dist/lib/download.js +274 -0
  78. package/dist/lib/dry-run/fetch.d.ts +10 -0
  79. package/dist/lib/dry-run/fetch.js +20 -0
  80. package/dist/lib/dry-run/samples.d.ts +6 -34
  81. package/dist/lib/dry-run/samples.js +375 -747
  82. package/dist/lib/environment-tunnel.d.ts +16 -27
  83. package/dist/lib/environment-tunnel.js +161 -154
  84. package/dist/lib/errors.d.ts +20 -4
  85. package/dist/lib/errors.js +36 -16
  86. package/dist/lib/facade.d.ts +7 -29
  87. package/dist/lib/facade.js +7 -36
  88. package/dist/lib/failing-fe-resolver.d.ts +13 -58
  89. package/dist/lib/failing-fe-resolver.js +47 -132
  90. package/dist/lib/first-suite-hint.d.ts +16 -22
  91. package/dist/lib/first-suite-hint.js +38 -47
  92. package/dist/lib/gh-output.d.ts +76 -21
  93. package/dist/lib/gh-output.js +171 -90
  94. package/dist/lib/git-utils.d.ts +56 -0
  95. package/dist/lib/git-utils.js +212 -0
  96. package/dist/lib/github-context.d.ts +2 -0
  97. package/dist/lib/github-context.js +40 -8
  98. package/dist/lib/history-retention.d.ts +6 -2
  99. package/dist/lib/history-retention.js +10 -7
  100. package/dist/lib/http.d.ts +58 -134
  101. package/dist/lib/http.js +352 -289
  102. package/dist/lib/interrupt.d.ts +14 -8
  103. package/dist/lib/interrupt.js +28 -10
  104. package/dist/lib/junit-report.d.ts +57 -4
  105. package/dist/lib/junit-report.js +202 -32
  106. package/dist/lib/local-target.d.ts +3 -3
  107. package/dist/lib/local-target.js +3 -3
  108. package/dist/lib/output.d.ts +1 -40
  109. package/dist/lib/output.js +11 -49
  110. package/dist/lib/pagination.d.ts +2 -5
  111. package/dist/lib/pagination.js +2 -5
  112. package/dist/lib/presigned-url.d.ts +22 -0
  113. package/dist/lib/presigned-url.js +90 -0
  114. package/dist/lib/prompt.js +36 -2
  115. package/dist/lib/proxy.js +2 -1
  116. package/dist/lib/redact.d.ts +2 -2
  117. package/dist/lib/redact.js +3 -4
  118. package/dist/lib/removed-commands.d.ts +18 -0
  119. package/dist/lib/removed-commands.js +154 -0
  120. package/dist/lib/render-error.d.ts +31 -6
  121. package/dist/lib/render-error.js +88 -25
  122. package/dist/lib/response-schemas.d.ts +38 -30
  123. package/dist/lib/response-schemas.js +207 -207
  124. package/dist/lib/result/api.d.ts +24 -0
  125. package/dist/lib/result/api.js +28 -0
  126. package/dist/lib/result/evidence.d.ts +71 -0
  127. package/dist/lib/result/evidence.js +420 -0
  128. package/dist/lib/result/render.d.ts +20 -0
  129. package/dist/lib/result/render.js +194 -0
  130. package/dist/lib/result/types.d.ts +122 -0
  131. package/dist/lib/result/types.js +19 -0
  132. package/dist/lib/run-output.d.ts +275 -0
  133. package/dist/lib/run-output.js +227 -0
  134. package/dist/lib/run-render.d.ts +101 -0
  135. package/dist/lib/run-render.js +183 -0
  136. package/dist/lib/run-wait.d.ts +192 -0
  137. package/dist/lib/run-wait.js +452 -0
  138. package/dist/lib/runs.types.d.ts +118 -367
  139. package/dist/lib/runs.types.js +0 -14
  140. package/dist/lib/secret-file.d.ts +1 -1
  141. package/dist/lib/secret-file.js +11 -2
  142. package/dist/lib/skill-nudge.d.ts +7 -27
  143. package/dist/lib/skill-nudge.js +9 -37
  144. package/dist/lib/target-path.d.ts +15 -0
  145. package/dist/lib/target-path.js +35 -0
  146. package/dist/lib/target-url-advisory.d.ts +19 -0
  147. package/dist/lib/target-url-advisory.js +31 -0
  148. package/dist/lib/target-url-preflight.d.ts +9 -0
  149. package/dist/lib/target-url-preflight.js +214 -106
  150. package/dist/lib/target-url.d.ts +1 -1
  151. package/dist/lib/target-url.js +6 -16
  152. package/dist/lib/telemetry.d.ts +31 -11
  153. package/dist/lib/telemetry.js +37 -8
  154. package/dist/lib/terminal-text.d.ts +41 -0
  155. package/dist/lib/terminal-text.js +127 -0
  156. package/dist/lib/testlist.types.d.ts +16 -8
  157. package/dist/lib/testlist.types.js +1 -1
  158. package/dist/lib/text-equality.d.ts +2 -0
  159. package/dist/lib/text-equality.js +5 -0
  160. package/dist/lib/text-file.d.ts +16 -0
  161. package/dist/lib/text-file.js +41 -0
  162. package/dist/lib/text-table.d.ts +46 -0
  163. package/dist/lib/text-table.js +72 -4
  164. package/dist/lib/ticker.d.ts +9 -2
  165. package/dist/lib/ticker.js +16 -3
  166. package/dist/lib/transport-failure.d.ts +22 -0
  167. package/dist/lib/transport-failure.js +126 -0
  168. package/dist/lib/tunnel-session.d.ts +7 -1
  169. package/dist/lib/tunnel-session.js +22 -9
  170. package/dist/lib/update-check.js +3 -2
  171. package/dist/lib/url-template.d.ts +43 -0
  172. package/dist/lib/url-template.js +151 -0
  173. package/dist/lib/validate.d.ts +0 -64
  174. package/dist/lib/validate.js +2 -131
  175. package/dist/lib/version-notice.js +4 -3
  176. package/dist/lib/wait-exit.d.ts +37 -2
  177. package/dist/lib/wait-exit.js +88 -30
  178. package/dist/lib/workspace-status.js +10 -2
  179. package/dist/version.d.ts +1 -1
  180. package/dist/version.js +1 -1
  181. package/package.json +2 -3
  182. package/skills/testsprite-ci.skill.md +48 -18
  183. package/skills/testsprite-onboard.skill.md +66 -151
  184. package/skills/testsprite-verify.codex.md +50 -52
  185. package/skills/testsprite-verify.skill.md +184 -351
  186. package/dist/lib/browser.d.ts +0 -6
  187. package/dist/lib/browser.js +0 -54
  188. package/dist/lib/bundle.d.ts +0 -234
  189. package/dist/lib/bundle.js +0 -781
  190. package/dist/lib/deprecate.d.ts +0 -32
  191. package/dist/lib/deprecate.js +0 -39
  192. package/dist/lib/flaky.d.ts +0 -91
  193. package/dist/lib/flaky.js +0 -71
  194. package/dist/lib/plan-poll.d.ts +0 -171
  195. package/dist/lib/plan-poll.js +0 -441
  196. package/dist/lib/plans.types.d.ts +0 -130
  197. package/dist/lib/plans.types.js +0 -31
  198. package/dist/lib/poll.d.ts +0 -100
  199. package/dist/lib/poll.js +0 -290
  200. package/dist/lib/rate-throttle.d.ts +0 -49
  201. package/dist/lib/rate-throttle.js +0 -75
  202. package/dist/lib/run-progress.d.ts +0 -41
  203. package/dist/lib/run-progress.js +0 -56
  204. package/dist/lib/v3-advisory.d.ts +0 -55
  205. package/dist/lib/v3-advisory.js +0 -74
  206. package/schemas/plan.schema.json +0 -61
package/README.md CHANGED
@@ -44,7 +44,7 @@ AI ships code in minutes — verifying it hasn't. `testsprite` opens your live a
44
44
 
45
45
  [TestSprite](https://www.testsprite.com) is the AI testing platform 100,000+ teams use to test their software, frontend and backend — in the cloud, against the live product, not mocks. This repo is its official CLI.
46
46
 
47
- It puts that platform in your coding agent's hands: the agent verifies every behavior it ships, and what broke comes back as **one self-consistent bundle** it can act on — no dashboard scraping. Humans drive the same surface from a terminal or CI.
47
+ It puts that platform in your coding agent's hands: the agent verifies every behavior it ships, and what broke comes back as **one result** — the failed step, its cause and a fix — it can act on, with no dashboard scraping. Humans drive the same surface from a terminal or CI.
48
48
 
49
49
  ## ⭐️ Star the Repository
50
50
 
@@ -54,187 +54,91 @@ If you find `testsprite` useful, a GitHub Star ⭐️ would be greatly appreciat
54
54
 
55
55
  ## Quickstart
56
56
 
57
- Requires **Node.js 20.19+**, **22.13+**, or **24+**. (No global install? `npx @testsprite/testsprite-cli` works too.)
57
+ You need Node.js 20.19+ on the 20.x line, 22.13+ on 22.x, or 24 or later. [Using 0.16? Read its command reference.](https://github.com/TestSprite/testsprite-cli/blob/v0.16.0/DOCUMENTATION.md)
58
+
59
+ From your app's repository, install the CLI and run setup. It prompts for your [workspace API key](https://www.testsprite.com/dashboard-v3/settings/apikey) and installs the skills for the coding agents it detects.
58
60
 
59
61
  ```bash
60
62
  npm install -g @testsprite/testsprite-cli
63
+ testsprite --version
61
64
  testsprite setup
65
+ testsprite auth status
62
66
  ```
63
67
 
64
- `testsprite setup` prompts for your [API key](https://www.testsprite.com/dashboard/settings/apikey), verifies it, and installs the verification-loop skill for the coding agents this project uses — one command, so your agent is wired to verify its own work.
65
-
66
- **Which agent it installs for.** Each of the eight supported targets — `claude`, `cursor`, `cline`, `windsurf`, `antigravity`, `kiro`, `copilot`, `codex` — lands its skill in a different place, so `setup` works out which you use: the agent calling it, if it identifies itself, together with every agent whose config is already in the project. It installs for all of them and prints what it found — in a terminal it shows you that list first, so you can accept it or narrow it before anything is written. If nothing identifies an agent, it installs for `claude` and says so — that is the one case where you want `--agent <target>` to name one yourself. Check the result any time with `testsprite agent status`.
67
-
68
- Non-interactive (CI / onboarding scripts):
68
+ **Choose your project and target.** Run `testsprite project list` to find an existing project. For a new frontend project, create it and add the URL where your app is running. Replace the URL below with yours and set `PROJECT_ID` to the ID printed by `project create`.
69
69
 
70
70
  ```bash
71
- TESTSPRITE_API_KEY=sk-... testsprite setup --from-env --yes
71
+ testsprite project create --type frontend --name "Checkout"
72
+ PROJECT_ID=your-project-id
73
+ testsprite project env create "$PROJECT_ID" --name staging --url https://staging.example.com
72
74
  ```
73
75
 
74
- > **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). `setup` reports which agents it installed for; add `--agent <target>` if that list is not the one you wanted. New here? Start with the **[getting-started overview](https://docs.testsprite.com/cli/getting-started/overview)**.
75
-
76
- > **Privacy note:** interactive runs check the npm registry at most once per 24 h to offer a "new version available" notice — package name only, never your key or data; `TESTSPRITE_NO_UPDATE_NOTIFIER=1` disables it. The backend also advertises its minimum supported CLI version — a below-floor CLI prints a one-line upgrade advisory on stderr, and a too-old client may be rejected with exit 14 (`CLIENT_TOO_OLD`). Details in [DOCUMENTATION.md → Update notice](./DOCUMENTATION.md#update-notice).
77
-
78
- From there, the loop runs on its own — an example session, typed by the coding agent:
76
+ **Get your first test.** Ask the project's agent to propose coverage. If it asks a question in a text message, answer with `testsprite reply "your answer"`. Review the proposed steps in the terminal and apply the plan when they match what you want to verify. For a backend project, attach the API specification with `--file ./openapi.yaml`.
79
77
 
80
78
  ```bash
81
- # 1 — describe the behavior you want to guarantee, run it, wait
82
- testsprite test create --project proj_8f0f6 --type frontend \
83
- --plan-from ./checkout-flow.plan.json --run --wait --output json
84
- # → exits 1: the run failed
85
-
86
- # 2 — pull ONE self-consistent failure bundle
87
- testsprite test failure get test_3a9f21c7 --out ./.testsprite/failure
88
-
89
- # 3 — the agent reads the bundle, fixes the code, then replays
90
- testsprite test run test_3a9f21c7 --wait --output json
91
- # → exits 0: passed. The test now lives in your durable suite.
79
+ testsprite plan "Verify that a guest can place an order with a test card" --project "$PROJECT_ID" --steps
92
80
  ```
93
81
 
94
- `./checkout-flow.plan.json` (the `--plan-from` argument above) is a JSON file describing the test in plain language — no browser code required. This is the exact, byte-identical output of `testsprite test create --plan-template` (also embedded verbatim in `test create --help`):
95
-
96
- ```json
97
- {
98
- "$schema": "https://raw.githubusercontent.com/TestSprite/testsprite-cli/v0.4.0/schemas/plan.schema.json",
99
- "projectId": "prj_abc123",
100
- "type": "frontend",
101
- "name": "Login rejects an empty password",
102
- "planSteps": [
103
- {
104
- "type": "action",
105
- "description": "Navigate to /login and submit the form with an empty password"
106
- },
107
- {
108
- "type": "assertion",
109
- "description": "Verify an inline error says the password is required"
110
- }
111
- ]
112
- }
82
+ ```bash
83
+ testsprite apply
84
+ testsprite test list --project "$PROJECT_ID"
113
85
  ```
114
86
 
115
- Get this exact skeleton without hand-copying it (and without the risk of it drifting from your installed version — see below): `testsprite test create --plan-template`. Full field reference (including the `{{...}}`-placeholder caveat, size caps, and the `$schema` hook for live editor validation): [Plan file format](./DOCUMENTATION.md#plan-file-format).
116
-
117
- > The `$schema` URL above is pinned to the CLI version that generated this doc (`v0.4.0`) — `--plan-template`'s live output always pins to **your installed version** instead, which is what actually resolves. If you're reading this on a later release, run the command yourself rather than trusting this snippet verbatim.
118
-
119
- **Don't want to write the first tests yourself?** For a deployed target, ask TestSprite to propose them. Local projects use the authored-plan flow below. `testsprite test plan generate --project <id>` explores your app (or reads the API spec you uploaded with `project docs upload`), drafts test cases, and stages them for review — nothing is written to your disk. You read the printed table and keep what you want:
87
+ **Run and inspect.** A project run waits for the suite when you pass `--wait`. Exit 0 means it passed. On exit 1, look for a failed or blocked row in `results[]` and copy its `resultId` to inspect the error and available evidence. If no row failed, check `runFailures` for an execution-level error such as cancellation. Without `--output json`, each run also prints a `Dashboard:` link that opens it in the Portal.
120
88
 
121
89
  ```bash
122
- testsprite test plan generate --project proj_8f0f6 # stages proposals for review
123
- testsprite test plan accept --project proj_8f0f6 # → real tests
124
- testsprite test plan accept --project proj_8f0f6 --only prop_2 prop_5 # or just these
90
+ testsprite run --project "$PROJECT_ID" --wait --output json
125
91
  ```
126
92
 
127
- It only runs what the project is still missing, so a second call picks up where the first left off. Generation spends workspace credits per stage that actually runs (the result line reports the spend), and a PRD uploaded with `project docs upload --role prd` bills 0.5 credits for its embedding — an API spec is free. Full walkthrough, including what happens on Ctrl-C and every precondition error: [Generate commands](./DOCUMENTATION.md#generate-commands).
93
+ ```bash
94
+ RESULT_ID=your-result-id
95
+ testsprite result get "$RESULT_ID" --out ".testsprite/results/$RESULT_ID"
96
+ ```
128
97
 
129
- Prefer to configure each step by hand (or learn the surface offline with `--dry-run` first)? See [Manual setup](./DOCUMENTATION.md#manual-setup) and [Install & verify](./DOCUMENTATION.md#install--verify).
98
+ After deploying a fix, run the affected test again with `testsprite run "$TEST_ID" --wait`, using its ID from `test list`. To resume waiting for a run you already started, use its **run ID** with `testsprite run wait "$RUN_ID"`. The [scripting example](./DOCUMENTATION.md#output--scripting) shows how to extract both IDs and preserve the verdict in CI.
130
99
 
131
100
  ## Testing an environment on your machine
132
101
 
133
- Frontend tests can reach your running app through a TestSprite tunnel, including on the Free plan (ordinary run credits apply).
134
- Use an API key with `run:tunnel`; the CLI names the missing scope if the key cannot open a tunnel. Existing keys receive this scope on backend v0.18.0 or later unless deliberately narrowed.
102
+ Start your frontend app on port 3000. To run the project's saved tests against the app on this machine, supply the port. The CLI opens a tunnel and waits for the cloud runner.
135
103
 
136
104
  ```bash
137
- testsprite project create --type frontend --name "My local app" --local 3000
138
- testsprite test create --plan-from ./checkout.plan.json --project <project-id>
139
- testsprite test run <test-id> # the saved loopback URL opens a tunnel and waits
140
- testsprite test run <id> <id> --max-concurrency 5
141
- testsprite test run --all --project <project-id>
142
- # Or keep one tunnel open in terminal A (no port argument)
143
- testsprite tunnel start --ttl 3600
144
- # Terminal B: borrow the clientId printed above; keep terminal A running
145
- testsprite test run <test-id> --tunnel-client <client-uuid>
146
- testsprite tunnel list
147
- testsprite tunnel stop <client-uuid>
148
- # Stop every live tunnel on this account only when you intend to revoke them all
149
- testsprite tunnel stop --all --confirm
105
+ testsprite run --project "$PROJECT_ID" --local 3000
150
106
  ```
151
107
 
152
- Run several local frontend tests in one invocation to share one tunnel binding. The batch runs up to 5 tests at once by default; `--max-concurrency` accepts 1–10. `--all --local` skips backend tests. An owned batch cancels unfinished runs on Ctrl-C or tunnel loss; JSON output lists every requested test in input order, including tests that did not start. The minted client id is printed before the tunnel connects.
153
- Hit the tunnel limit? Run `testsprite tunnel list`, then `testsprite tunnel stop <client-uuid>` for an unused binding, or `testsprite tunnel stop --all --confirm` to revoke them all. An older server without listing returns exit 4; a key without `run:tunnel` returns exit 3.
154
- A second `tunnel start` or process using the same credential takes over, and the first exits **10**.
155
- An environment is one origin (scheme, host and port) plus its sign-in configuration. Frontend runs automatically open a tunnel for a saved `localhost`, `127.0.0.1` or `[::1]` URL: `test run`, `test create --run`, `test create-batch --run` and `testlist run` use this behavior. `--env <name>` selects the environment; omit it for the project default. `--no-wait` disables automatic tunnels; drop it to run through one. If environment reads are unavailable, the command keeps the previous server behavior. Several fresh-run IDs require a tunnel; public targets retain the exit-5 refusal. A named public environment used against a local origin prints a sign-in advisory on stderr. Test-list runs share one timeout including capacity waits and require the server to confirm tunnel support; an older server triggers a cancellation attempt and a clear error.
156
-
157
- `--local <port>` saves new project and environment URLs as `http://localhost:<port>`. Use `--url http://127.0.0.1:<port>` or `--url http://[::1]:<port>` when the host matters (`--local-host` is deprecated). Dev servers can be slow through a tunnel, so for heavy apps test a production build (`npm run build` plus your framework's preview or start command).
158
-
159
- The tunnel uses verified TLS. On a network that re-signs TLS, set `NODE_EXTRA_CA_CERTS=/path/to/ca.pem` to your organisation's root CA. If the tunnel keeps failing to connect for 60 seconds, the command exits **10**, and an owned run is cancelled and refunded.
160
-
161
- On an owned tunnel, Ctrl-C or a timeout cancels unfinished runs by default, and a run cancelled before it finishes is refunded. A run on a borrowed `--tunnel-client` detaches on Ctrl-C instead. Local projects skip plan generation, so write plans with `test create --plan-from`. Portal runs stay blocked, at no charge, until the project has a public URL. See [the local-testing reference](./DOCUMENTATION.md#local-frontend-testing-and-tunnels) for the details.
108
+ For a local-only project, you can save the port as its first environment with `testsprite project env create "$PROJECT_ID" --name local --local 3000`. Give the project's agent a Git diff or a spec so it can propose tests without browsing localhost. Review and apply the test plan, then run with `--env local`. An ordinary Ctrl-C detaches a public run. With a tunnel this command opened, Ctrl-C cancels unfinished work by default and closes the tunnel. [Local frontend testing and tunnels](./DOCUMENTATION.md#local-frontend-testing-and-tunnels)
162
109
 
163
110
  ## Commands
164
111
 
165
- | Group | Command | What it does |
166
- | -------------- | --------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
167
- | **Setup** | `setup` | **Start here** — one command: configure your API key, verify it, and install the agent verification skill |
168
- | | `doctor` | Environment diagnostic — CLI/Node versions, profile, endpoint, credentials, connectivity, agent skill; exits non-zero on failure |
169
- | | `completion` | Print a shell completion script (bash, zsh, fish) |
170
- | **Auth** | `auth status` | Resolve the active profile to its user, key, env, and scopes |
171
- | | `auth remove` | Remove the active profile from the credentials file |
172
- | | `usage` (alias `credits`) | Account pre-flight: identity, plus credit balance / plan info when the backend supplies them |
173
- | **Read** | `project list` / `project get` | List projects / fetch one by id, including the default environment and environment count when the server reports them |
174
- | | `test list` / `test get` | List tests under a project / fetch one by id; `test list --env <name>` selects frontend status and the ENV column names its source |
175
- | | `test code get` | Print (or write) the generated test source |
176
- | | `test steps` | List the latest run's steps with screenshot / DOM pointers |
177
- | | `test result` | Latest result; `--history` lists a test's prior runs (ENV column; `--env <name>` filters by environment) |
178
- | | `test failure get` | The agent entry point: one self-contained latest-failure bundle |
179
- | | `test failure summary` | One-screen triage card (no media download) |
180
- | | `test diff` | Compare two runs — verdict, failure kind, per-step status flips, code-version drift |
181
- | | `test open` | Open a test in the dashboard (`--no-browser` prints the URL only) |
182
- | **Write** | `test scaffold` / `test lint` | Author plans locally: emit a schema-correct starter, validate plan files offline — no network, no credentials |
183
- | | `test create` / `test create-batch` | Create a test (or bulk-create from a plan file); `--step-timeout <ms>` sets a per-test timeout; dependency flags wire BE metadata |
184
- | | `test update` / `test delete` / `test delete-batch` | Edit metadata, set/clear the step timeout (`--step-timeout` / `--clear-step-timeout`), or permanently delete (`--confirm` required) |
185
- | | `test code put` | Replace generated code (etag-guarded) |
186
- | | `test plan put` | Replace a frontend test's plan-steps |
187
- | | `project create` / `project update` / `project delete` | Manage projects; `--test-id-attributes <list>` registers the app's own test-hook attributes (priority order) for exported locators, `--clear-test-id-attributes` reverts; `delete` removes a project and everything under it (`--confirm` required, no restore window) |
188
- | | `project credential` / `project auto-auth` | Configure backend-test auth: a static injected credential, or auto-refresh login (Pro) |
189
- | | `project env list` / `get` / `create` / `update` / `delete` / `set-default` | Manage a project's named URL + login bundles. `get` shows safe login details and variables; `create` / `update` accept repeatable `--var KEY=VALUE` (plain text — not for secrets, use `--username`/`--password`), and `update --clear-credentials` disables account login. Use `--url http://localhost:<port>` or `--local <port>` for an app on this machine; runs open its tunnel automatically. `delete` refuses the default environment. |
190
- | | `project sign-in get` / `set` | Inspect or change an environment's app sign-in mode; choose OTP with `project env create --sign-in otp`. SSO selection requires the per-account manual-login feature flag; capture the session in the Portal. |
191
- | **Generate** | `test plan generate` | Ask TestSprite to propose test cases for a project — proposals are staged server-side for review, never written to disk; only the stages the project is missing actually run |
192
- | | `test plan accept` | Turn staged proposals into real tests — all of them, or a subset with `--only` |
193
- | | `project docs upload` | Upload an API spec or PRD as a project source, so generation has something to read |
194
- | **Run** | `test run` | Trigger a fresh run; saved loopback environments open a tunnel and wait automatically; `--wait` blocks until terminal; several ids or `--all --project <id>` run a batch in wave order (`--status`/`--filter` narrow `--all`; `--skip-dependencies` for backend); `--env <name>` runs against a named environment. |
195
- | | `test rerun` | **Deprecated** — use `test run` (same flags; several ids and `--all --status` are supported there). Removed in 0.17.0. |
196
- | | `test flaky` | **Deprecated** — no replacement; run `test run <id>` again to sample a test. Removed in 0.17.0. |
197
- | | `test wait` | Block on one or more `runId`s until terminal |
198
- | | `test cancel` | Cancel one or more in-flight runs (Ctrl-C during `--wait` only detaches, `cancel` is the real stop — except a run with an owned tunnel, which Ctrl-C cancels by default) |
199
- | | `test artifact get` | Download the failure bundle for a specific `runId` |
200
- | **Test lists** | `testlist list` / `testlist get` | Inspect saved test lists — named, cross-project collections with per-project environment pins (V3-only) |
201
- | | `testlist create` / `update` / `add` / `remove` / `delete` | Manage a list and its cases; `--project-env <id>:<env>` pins environments; `delete` requires `--confirm` |
202
- | | `testlist run` | Run every case (or a `--case` subset) through its pinned environment; loopback environments open a tunnel automatically; `--wait` polls all runs, `--report junit` writes a CI sidecar |
203
- | **Schedule** | `schedule list` / `schedule get` | List schedules visible to the key / fetch one by id, including a project schedule's pinned or inherited environment (status is `ENABLED`, `PAUSED`, or `AUTO_PAUSED` after repeated failures) |
204
- | | `schedule create` | Run a project or test list on a 5-field cron; `--env <name>` pins a project schedule, while omission inherits the live default; states frequency and estimated cost |
205
- | | `schedule update` | Retime or rename a schedule, change recipients, pin a project schedule with `--env <name>`, or `--pause` / `--resume` it |
206
- | | `schedule delete` | Remove a schedule and its run history, stopping future triggers (`--confirm` required, no restore window) |
207
- | | `schedule run list` | A schedule's past runs, with per-run pass / fail / blocked counts |
208
- | **CI** | `ci init github` | Write a GitHub Actions PR gate that runs `ci run` against each pull request's preview deployment — one placeholder step to fill in: your platform deploys every PR (`on: deployment_status`) or the workflow deploys |
209
- | | `ci run` | The CI gate in one command: every project test (or `--filter`) against `--target-url`, signed in as `--env`, in a temporary `github-pr-<N>` environment, one execution; waits and exits with the verdict. Job summary = the execution report (the GitHub App comment); `--summary-file`, `--report junit`, step outputs |
210
- | **Agent** | `agent install` / `agent list` / `agent status` | Add, list, or health-check coding-agent skills (pure-local): `claude`, `codex`, `cursor`, `cline`, `antigravity`, `kiro`, `windsurf`, `copilot` |
211
- | **CI** | `ci init github` | Write a GitHub Actions workflow that runs your tests |
212
- | | `ci doctor` | Check that deployment events reach this repo |
213
- | | `ci connect` | Link your deploy platform (Vercel) to this repo |
214
- | **Tunnel** | `tunnel start` / `list` / `status` / `stop` | Hold one tunnel open for several `--local` runs; list, check, or stop tunnels |
215
-
216
- > 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).
217
-
218
- 📚 **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).
219
-
220
- Exit codes: `0` success, `1` failure (including a run that did not pass), `7` timeout, `12` insufficient credits, `13` feature gated, `14` CLI too old; the rest are in [DOCUMENTATION.md](./DOCUMENTATION.md#exit-codes).
112
+ | Task | Command |
113
+ | ------------------------------------------------ | -------------------------------------------------------------------------------------- |
114
+ | Check credentials or install coding-agent skills | `auth status`, `setup`, `agent status` |
115
+ | Manage a project and its targets | `project list`, `project create`, `project env` |
116
+ | Propose tests, review them and save them | `plan`, `status`, `reply`, `reject`, `apply` |
117
+ | Find the ID or steps of a saved test | `test list --project <id>`, `test get <test-id>` |
118
+ | Launch a project, named tests or a saved list | `run --project <id>`, `run <test-id...>`, `run --testlist <list-id>` |
119
+ | Follow or cancel an execution | `run wait <run-id...>`, `run cancel <run-id...>` |
120
+ | Read results and download evidence | `result list --run <run-id>`, `result list --test <test-id>`, `result get <result-id>` |
121
+ | Automate scheduled tests or a pull-request gate | `schedule`, `ci init github`, `ci run` |
122
+
123
+ For test lists, tunnel management, usage, diagnostics, profiles and exit codes, see the [command reference](./DOCUMENTATION.md#command-reference). To migrate shell scripts or previously installed agent skills from 0.16, see [Upgrading from 0.16](./DOCUMENTATION.md#upgrading-from-016).
221
124
 
222
125
  ## Why a CLI for coding agents?
223
126
 
224
127
  - 🧪 **Tests like a real user.** Runs against a live browser or API in the cloud — real clicks, real navigation, real assertions. Not a mock.
225
- - 🤖 **Agent-shaped output.** `test failure get` returns **one bundle** — the failing step, its neighbors, screenshots, DOM snapshots, the test source, a root-cause hypothesis, and a recommended fix target — all sharing a single `snapshotId`. The CLI _refuses_ to stitch data from two different runs, so an agent never reasons over a frankenstein context.
226
- - ♻️ **A loop, not a one-shot.** `create → run → failure get → fix → run` — every pass is banked, not thrown away.
227
- - 📐 **Scriptable & deterministic.** Stable `--output json` contract, predictable [exit codes](./DOCUMENTATION.md#exit-codes), and a `--dry-run` that exercises the full code path offline with canned data.
228
- - 🚦 **CI-native.** `testsprite ci init github` writes a PR gate; `testsprite ci run --env <name> --target-url "$PREVIEW_URL"` tests each pull request's preview deployment as one execution and exits with the verdict. The job summary is the execution report — the same content as the GitHub App's PR comment — plus `::error::` annotations on the checks tab, step outputs, `--summary-file` for a machine summary and `--report junit` for a JUnit sidecar. In any other CI, `testsprite ci run --project <id> --env <name> --target-url <url>` still runs the suite as one execution and makes the exit code the verdict — the pull-request context, draft skip and job summary are GitHub Actions only. [Details →](./DOCUMENTATION.md#continuous-integration)
128
+ - 🤖 **Agent-shaped output.** `run` names the run (`runId`) and each test's result in it (`resultId`). `result get <result-id>` returns that one result — the verdict, the error, its cause and fix, the failed step with its screenshot, a backend test's traceback and output, and every step — and `--out <dir>` downloads its video and each step's screenshot and page. The agent reads the run it just started, never an older one.
129
+ - **Whole-run results.** Every selector and `run wait` use the same JSON: `runs[]` describes executions, `results[]` lists individual results, and `summary` counts outcomes when waiting. A complete run can fail. Only a timeout or interruption that leaves work unfinished adds `partial: true`. A cancelled execution fails even if its existing results passed. Read detailed evidence with `result get <result-id>`.
130
+ - ♻️ **A loop, not a one-shot.** `plan → apply → run → result get → fix → run` — every pass is banked, not thrown away.
131
+ - 📐 **Scriptable & deterministic.** Stable `--output json` contract, predictable [exit codes](./DOCUMENTATION.md#exit-codes), and a `--dry-run` for previewing commands. A credentialed run preview can read environment metadata to determine whether it would open a tunnel.
132
+ - 🚦 **CI-native.** `testsprite ci init github` writes a PR gate; `testsprite ci run --project "$PROJECT_ID" --env <name> --target-url "$PREVIEW_URL"` tests each pull request's preview deployment as one run and exits with the verdict. The job summary is the execution report — the same content as the GitHub App's PR comment — plus `::error::` annotations on the checks tab, step outputs, `--summary-file` for a machine summary and `--report junit` for a JUnit sidecar. In any other CI, `testsprite ci run --project <id> --env <name> --target-url <url>` still runs the suite as one run and makes the exit code the verdict — the pull-request context, draft skip and job summary are GitHub Actions only. [Details →](./DOCUMENTATION.md#continuous-integration)
229
133
  - 🔌 **One command to onboard your agent.** `testsprite setup` drops ready-made skill files into your repo — for the agents it detects you using — so your coding agent knows how to drive the loop on its own.
230
134
 
231
135
  ## How it works
232
136
 
233
137
  Every time your agent changes code, it asks one question: **is this behavior already covered by the suite?**
234
138
 
235
- - **Not yet covered** → `testsprite test create` — describe the new behavior, run it.
236
- - **Already covered** → `testsprite test run --all` — run the existing tests, so nothing that used to work breaks silently.
237
- - **Something fails** → `testsprite test failure get` — one self-consistent bundle; the agent fixes the code and runs again.
139
+ - **Not yet covered** → `testsprite plan` — the project's agent writes a test for the new behavior; `testsprite apply` saves it, then run it.
140
+ - **Already covered** → `testsprite run --project <project-id> --wait` — run the existing tests, so nothing that used to work breaks silently.
141
+ - **Something fails** → `testsprite result get <result-id>` — the failed step, its cause and a fix; the agent fixes the code and runs again.
238
142
 
239
143
  Every pass is banked into a durable suite, so coverage compounds as the project grows — a lasting record of every requirement it has ever gotten right, far bigger than any context window.
240
144
 
@@ -242,20 +146,20 @@ Every pass is banked into a durable suite, so coverage compounds as the project
242
146
  flowchart TD
243
147
  A["🤖 Your coding agent<br/>Claude Code · Codex · Antigravity · Kimi · Cursor · Trae …"]
244
148
  D{"behavior already<br/>covered by the suite?"}
245
- B["<b>testsprite test create</b><br/>new behavior → new test"]
246
- R["<b>testsprite test run --all</b><br/>run the existing tests"]
149
+ B["<b>testsprite plan → apply</b><br/>the project's agent writes a test<br/>for the new behavior"]
150
+ R["<b>testsprite run --project &lt;project-id&gt; --wait</b><br/>run the existing tests"]
247
151
  C{{"☁️ TestSprite testing agent<br/>runs the test like a real user against<br/>real browsers & real APIs on Cloud"}}
248
- F["<b>testsprite test failure get</b><br/>ONE self-consistent bundle:<br/>failing step · screenshots · DOM ·<br/>root-cause · recommended fix"]
152
+ F["<b>testsprite result get</b><br/>one test's result in the run:<br/>failed step · screenshots · video ·<br/>cause · fix"]
249
153
  S[("📚 Durable integration suite<br/>grows with every pass")]
250
154
 
251
155
  A -->|"writes / changes code"| D
252
156
  D -->|"no — new behavior"| B
253
157
  D -->|"yes"| R
254
- B --> C
158
+ B --> R
255
159
  R --> C
256
160
  C -->|"pass ✅"| S
257
161
  C -->|"fail ❌"| F
258
- F -->|"agent reads the bundle<br/>& fixes the code"| A
162
+ F -->|"agent reads the result<br/>& fixes the code"| A
259
163
  S -.->|"defines what's covered"| D
260
164
  ```
261
165
 
@@ -272,7 +176,7 @@ That's the point of all of this: you no longer need the biggest, most expensive
272
176
  - 📚 **CLI reference** — [DOCUMENTATION.md](./DOCUMENTATION.md)
273
177
  - 🌐 **Platform docs** — [docs.testsprite.com](https://docs.testsprite.com)
274
178
  - 🐛 **Issues & feature requests** — [GitHub issues](https://github.com/TestSprite/testsprite-cli/issues)
275
- - 💬 **Quick questions** — [Discord](https://discord.gg/GXWFjCe4an), or `testsprite --help` / `testsprite test run --help` right in your terminal
179
+ - 💬 **Quick questions** — [Discord](https://discord.gg/GXWFjCe4an), or `testsprite --help` / `testsprite run --help` right in your terminal
276
180
  - 📝 **Changelog** — [CHANGELOG.md](./CHANGELOG.md)
277
181
 
278
182
  ## Contributing
@@ -71,10 +71,12 @@ export declare function runList(opts: CommonOptions, deps?: AgentDeps): Promise<
71
71
  * - 'unmarked' : artifact present but carries no testsprite-skill marker
72
72
  * (installed before markers existed), or the landing path is
73
73
  * occupied by a non-regular file (never followed).
74
- * - 'stale' : marker present, but its hash differs from the current
75
- * canonical body: a re-install would change the content. Edits
76
- * on top of an OLD install also read stale (older renders
77
- * cannot be reproduced); the remedy is the same re-install.
74
+ * - 'stale' : marker present, but either its hash differs from the current
75
+ * canonical body, or the bytes are exactly a legacy (v0.15.0)
76
+ * render of that body: a re-install would change the content
77
+ * and repair it without --force. Edits on top of an OLD install
78
+ * also read stale (older renders cannot be reproduced); the
79
+ * remedy is the same re-install.
78
80
  * - 'modified' : marker hash matches the current body, but the artifact bytes
79
81
  * differ from the canonical render carrying that same marker
80
82
  * line: the user edited the artifact after install.
@@ -101,6 +103,12 @@ interface StatusOptions extends CommonOptions {
101
103
  * (exit 0) when every row is 'ok' or 'absent'; throws CLIError exit 1 when any
102
104
  * row is stale/modified/unmarked/corrupt, so the command can gate CI.
103
105
  */
106
+ /**
107
+ * Each target's state for each default skill under `root`: what `agent
108
+ * status` prints and `doctor` reads. Absent artifacts never touch the skill
109
+ * assets.
110
+ */
111
+ export declare function skillStates(root: string, agentFs?: AgentFs): Promise<StatusResult[]>;
104
112
  export declare function runStatus(opts: StatusOptions, deps?: AgentDeps): Promise<void>;
105
113
  export declare function createAgentCommand(deps?: AgentDeps): Command;
106
114
  export {};
@@ -1,12 +1,15 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'node:fs/promises';
3
3
  import { Command } from 'commander';
4
+ import { equalIgnoringCrlf } from '../lib/text-equality.js';
4
5
  import { resolveProfileName } from '../lib/config.js';
5
6
  import { CLIError, localValidationError } from '../lib/errors.js';
6
7
  import { GLOBAL_OPTS_HINT, Output, resolveOutputMode } from '../lib/output.js';
8
+ import { inspectTargetPath } from '../lib/target-path.js';
7
9
  import { promptText } from '../lib/prompt.js';
8
10
  import { FALLBACK_TARGET, resolveAgentTargets } from '../lib/agent-detect.js';
9
- import { TARGETS, SKILLS, DEFAULT_SKILLS, MARKER_SKILL_SEPARATOR, pathFor, ownFileBodyFor, bodyHash12, buildCodexAggregate, buildSkillMarker, parseSkillMarker, renderForTarget, renderOwnFileWithMarker, MANAGED_SECTION_BEGIN, MANAGED_SECTION_END, } from '../lib/agent-targets.js';
11
+ import { TARGETS, SKILLS, DEFAULT_SKILLS, MARKER_SKILL_SEPARATOR, pathFor, ownFileBodyFor, bodyHash12, buildCodexAggregate, buildSkillMarker, parseSkillMarker, renderForTarget, renderOwnFileWithMarker, isLegacyOwnFileRender, MANAGED_SECTION_BEGIN, MANAGED_SECTION_END, } from '../lib/agent-targets.js';
12
+ import { terminalSafeWriter } from '../lib/terminal-text.js';
10
13
  // ---------------------------------------------------------------------------
11
14
  // Constants
12
15
  // ---------------------------------------------------------------------------
@@ -43,44 +46,6 @@ const defaultAgentFs = {
43
46
  // ---------------------------------------------------------------------------
44
47
  // Path safety
45
48
  // ---------------------------------------------------------------------------
46
- /**
47
- * Walk each component of `relPath` beneath `root`, refusing to traverse or
48
- * write through a symlink. `fs.mkdir`/`writeFile` follow symlinks, so a planted
49
- * symlink at any existing path component (e.g. `.claude` -> /etc, or the final
50
- * `SKILL.md` -> ~/.bashrc) could place or clobber files outside `--dir`. The
51
- * lexical containment guard in `runInstall` is a string compare and cannot see
52
- * this; only an `lstat`-per-component walk can. Fail-closed: any symlink is
53
- * rejected (exit 5).
54
- *
55
- * Returns the target's `{ isFile }` when it already exists, or `null` when it
56
- * (or any ancestor) does not yet exist — in which case the missing tail is
57
- * created fresh and cannot be a pre-planted symlink. A small TOCTOU window
58
- * remains between this check and the write; that is acceptable for a local,
59
- * single-user CLI and avoids non-portable O_NOFOLLOW / rename gymnastics.
60
- */
61
- async function inspectTargetPath(agentFs, root, relPath) {
62
- const segments = relPath.split(/[/\\]+/).filter(Boolean);
63
- let current = root;
64
- let finalIsFile = false;
65
- for (const [i, seg] of segments.entries()) {
66
- current = path.join(current, seg);
67
- const ls = await agentFs.lstat(current);
68
- if (ls === null) {
69
- // This component and everything below it does not exist yet.
70
- return null;
71
- }
72
- if (ls.isSymbolicLink) {
73
- const shown = segments.slice(0, i + 1).join('/');
74
- throw new CLIError(`refusing to write through a symlink: "${shown}" — installing here could place files outside --dir. Remove the symlink or choose a different --dir.`, 5);
75
- }
76
- if (i < segments.length - 1 && ls.isFile) {
77
- const shown = segments.slice(0, i + 1).join('/');
78
- throw new CLIError(`cannot create ${relPath}: "${shown}" exists and is not a directory.`, 5);
79
- }
80
- finalIsFile = ls.isFile;
81
- }
82
- return { isFile: finalIsFile };
83
- }
84
49
  /**
85
50
  * Back up the current bytes at `abs` next to it without clobbering any existing
86
51
  * backup or writing through a symlink. Exclusive create (`wx`) fails with
@@ -192,7 +157,7 @@ function classifySection(existing, section) {
192
157
  const before = existing.slice(0, beginByteIdx);
193
158
  const after = existing.slice(endOfEndByte + trailingNewline);
194
159
  const currentSection = existing.slice(beginByteIdx, endOfEndByte + trailingNewline);
195
- if (currentSection === section) {
160
+ if (equalIgnoringCrlf(currentSection, section)) {
196
161
  return { kind: 'unchanged' };
197
162
  }
198
163
  return { kind: 'replace', existing, before, after };
@@ -255,7 +220,7 @@ function makeOwnFileBodyResolver() {
255
220
  // ---------------------------------------------------------------------------
256
221
  export async function runInstall(opts, deps = {}) {
257
222
  const agentFs = deps.fs ?? defaultAgentFs;
258
- const stderrFn = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
223
+ const stderrFn = terminalSafeWriter(deps.stderr);
259
224
  const out = makeOutput(opts.output, deps);
260
225
  // 1. Parse targets
261
226
  const rawTargets = opts.target
@@ -564,24 +529,30 @@ export async function runInstall(opts, deps = {}) {
564
529
  }
565
530
  else {
566
531
  const existing = await agentFs.readFile(abs);
567
- if (existing === content) {
532
+ // A v0.15.0 render whose canonical body is unchanged is a stale
533
+ // install, not a user edit: repair it without --force.
534
+ const legacyRender = isLegacyOwnFileRender(t, skill, existing);
535
+ if (equalIgnoringCrlf(existing, content)) {
568
536
  // Byte-identical — skip
569
537
  results.push({ target: t, path: relPath, action: 'skipped', skills: [skill] });
570
538
  }
571
- else if (!opts.force) {
539
+ else if (!opts.force && !legacyRender) {
572
540
  // Differs and no --force → blocked
573
541
  results.push({ target: t, path: relPath, action: 'blocked', skills: [skill] });
574
542
  }
575
543
  else {
576
- // Differs and --force → back up the current bytes to a fresh slot
577
- // (never clobbering an existing backup or following a symlink), then
578
- // overwrite. The overwrite itself can follow a symlink swapped in after
579
- // the check — an accepted TOCTOU residual for a local, single-user CLI.
580
- const backupPath = await writeBackup(agentFs, abs, existing);
581
- await agentFs.writeFile(abs, content);
582
- if (opts.output === 'text') {
583
- stderrFn(`backed up ${relPath} to ${path.relative(root, backupPath)}`);
544
+ // Overwrite. With --force, back up the current bytes to a fresh slot
545
+ // (never clobbering an existing backup or following a symlink) first;
546
+ // a legacy render needs no backup because nothing of the user's is
547
+ // lost. The overwrite itself can follow a symlink swapped in after the
548
+ // check — an accepted TOCTOU residual for a local, single-user CLI.
549
+ if (opts.force) {
550
+ const backupPath = await writeBackup(agentFs, abs, existing);
551
+ if (opts.output === 'text') {
552
+ stderrFn(`backed up ${relPath} to ${path.relative(root, backupPath)}`);
553
+ }
584
554
  }
555
+ await agentFs.writeFile(abs, content);
585
556
  results.push({ target: t, path: relPath, action: 'updated', skills: [skill] });
586
557
  }
587
558
  }
@@ -635,7 +606,7 @@ function agentDisplayName(target, status) {
635
606
  }
636
607
  export async function runList(opts, deps = {}) {
637
608
  const out = makeOutput(opts.output, deps);
638
- const stderrFn = deps.stderr ?? ((line) => process.stderr.write(`${line}\n`));
609
+ const stderrFn = terminalSafeWriter(deps.stderr);
639
610
  // One row per (target × default skill). Own-file targets land each skill at a
640
611
  // distinct path; the codex managed-section target merges all skills into the
641
612
  // single AGENTS.md (so every codex row shares that path — truthful, since both
@@ -699,7 +670,13 @@ async function classifyOwnFileState(agentFs, abs, target, skill, canonicalBody)
699
670
  // render carrying its own marker line, so a marker whose version string lags
700
671
  // behind an unchanged body still reads ok.
701
672
  const reRender = renderOwnFileWithMarker(target, skill, marker.line, body);
702
- return existing === reRender ? 'ok' : 'modified';
673
+ if (equalIgnoringCrlf(existing, reRender))
674
+ return 'ok';
675
+ // v0.15.0 wrote the same body with an unquoted frontmatter description; that
676
+ // is a stale install a plain re-install repairs, not a user edit.
677
+ if (isLegacyOwnFileRender(target, skill, existing, body))
678
+ return 'stale';
679
+ return 'modified';
703
680
  }
704
681
  /**
705
682
  * Classify the codex managed section per skill. The section is ONE artifact
@@ -765,16 +742,12 @@ async function classifyManagedSectionStates(agentFs, abs) {
765
742
  * (exit 0) when every row is 'ok' or 'absent'; throws CLIError exit 1 when any
766
743
  * row is stale/modified/unmarked/corrupt, so the command can gate CI.
767
744
  */
768
- export async function runStatus(opts, deps = {}) {
769
- const agentFs = deps.fs ?? defaultAgentFs;
770
- const out = makeOutput(opts.output, deps);
771
- // An explicit but empty --dir must not silently resolve to cwd
772
- // (path.resolve('') === cwd).
773
- if (opts.dir !== undefined && opts.dir.trim() === '') {
774
- throw localValidationError('dir', 'must not be empty');
775
- }
776
- const dir = opts.dir !== undefined ? opts.dir.trim() : (deps.cwd ?? process.cwd());
777
- const root = path.resolve(dir);
745
+ /**
746
+ * Each target's state for each default skill under `root`: what `agent
747
+ * status` prints and `doctor` reads. Absent artifacts never touch the skill
748
+ * assets.
749
+ */
750
+ export async function skillStates(root, agentFs = defaultAgentFs) {
778
751
  // The SAME resolver the installer stamps its marker hashes from — a
779
752
  // separate copy here is exactly how install and status end up disagreeing.
780
753
  const ownFileBodyFor = makeOwnFileBodyResolver();
@@ -800,6 +773,18 @@ export async function runStatus(opts, deps = {}) {
800
773
  });
801
774
  }
802
775
  }
776
+ return results;
777
+ }
778
+ export async function runStatus(opts, deps = {}) {
779
+ const agentFs = deps.fs ?? defaultAgentFs;
780
+ const out = makeOutput(opts.output, deps);
781
+ // An explicit but empty --dir must not silently resolve to cwd
782
+ // (path.resolve('') === cwd).
783
+ if (opts.dir !== undefined && opts.dir.trim() === '') {
784
+ throw localValidationError('dir', 'must not be empty');
785
+ }
786
+ const dir = opts.dir !== undefined ? opts.dir.trim() : (deps.cwd ?? process.cwd());
787
+ const results = await skillStates(path.resolve(dir), agentFs);
803
788
  out.print(results, data => {
804
789
  const items = data;
805
790
  const header = `${'TARGET'.padEnd(14)} ${'SKILL'.padEnd(20)} ${'STATE'.padEnd(10)} PATH`;
@@ -20,21 +20,17 @@ export interface MeResponse {
20
20
  /** Human-readable display name for the bound account. Absent-safe (dogfood L1866). */
21
21
  displayName?: string;
22
22
  /**
23
- * Authoritative per-user V3 routing bit. Absent-safe: older backends omit it,
24
- * so it is only rendered when present.
25
- */
26
- v3Enabled?: boolean;
27
- /**
28
- * Legacy per-user billing projections. Absent-safe; superseded by
29
- * `activeOrg` when both are present. Declared so shared fixtures typed as
30
- * `MeResponse` can carry them (the `usage` command has its own richer view).
23
+ * The org wallet flattened (`credits` = `activeOrg.remaining`, `subPlan` =
24
+ * `activeOrg.plan`); present iff `activeOrg` is. Declared so shared fixtures
25
+ * typed as `MeResponse` can carry them (the `usage` command renders the
26
+ * wallet from `activeOrg`).
31
27
  */
32
28
  credits?: number;
33
29
  subPlan?: string;
34
30
  creditsPerRun?: number;
35
31
  /**
36
32
  * The caller's organization (org-based billing subject). Absent-safe:
37
- * rendered as a single `org:` line when present (V3-routed callers only).
33
+ * rendered as a single `org:` line when present.
38
34
  */
39
35
  activeOrg?: {
40
36
  id: string;
@@ -80,7 +76,7 @@ export interface AuthDeps {
80
76
  * it is sent as the `X-CLI-Command` request header on the key-validation
81
77
  * `GET /me` so the backend can attribute the call for product analytics —
82
78
  * e.g. `init` is counted as `cli.initialized` instead of the generic
83
- * `cli.session_started`. `auth configure` run directly leaves it unset.
79
+ * `cli.session_started`. Left unset, no header is sent.
84
80
  * Advisory only: it never changes behavior, and the backend honors only a
85
81
  * known allowlist value.
86
82
  */