@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
@@ -0,0 +1,33 @@
1
+ import type { ApplyResult, Conversation, ConversationEvent, ConversationSummary, Proposal } from './types.js';
2
+ export interface NextStep {
3
+ command: string;
4
+ why: string;
5
+ }
6
+ /** One line of progress on stderr while the agent works; the user's own messages are not echoed back. */
7
+ export declare function renderEvent(event: ConversationEvent): string | null;
8
+ /**
9
+ * What to do next, for people and coding agents alike; `--output json`
10
+ * carries the same list as `next`.
11
+ */
12
+ export declare function nextSteps(conversation: Conversation): NextStep[];
13
+ /** The conversation as it stands, for the terminal. */
14
+ export declare function renderConversation(conversation: Conversation, options?: {
15
+ steps?: boolean;
16
+ replyShown?: boolean;
17
+ next?: NextStep[];
18
+ }): string;
19
+ export declare function renderProposal(proposal: Proposal, showSteps: boolean): string[];
20
+ export declare function renderApplied(result: ApplyResult): string;
21
+ /**
22
+ * Earlier conversations still waiting for an apply or reject. The agent leaves
23
+ * the tests such a proposal changes alone, so a new plan says so up front.
24
+ */
25
+ export declare function waitingNotes(conversations: ConversationSummary[]): string[];
26
+ export declare function renderConversationList(conversations: ConversationSummary[]): string;
27
+ /**
28
+ * The tests a plan saved, as a pull request's description lists them, so the
29
+ * reviewers of a change see the tests that now guard it. `inLine` is applied
30
+ * to each server value (an id, a title, the link): the terminal passes
31
+ * `terminalSafeLine`, the JSON keeps the values as sent.
32
+ */
33
+ export declare function prSummary(applied: ApplyResult, url: string, inLine?: (value: string) => string): string | null;
@@ -0,0 +1,315 @@
1
+ import { terminalSafe, terminalSafeLine } from '../terminal-text.js';
2
+ import { optionLetter } from './answers.js';
3
+ /** One line of progress on stderr while the agent works; the user's own messages are not echoed back. */
4
+ export function renderEvent(event) {
5
+ switch (event.kind) {
6
+ case 'activity':
7
+ return ` · ${terminalSafeLine(event.text)}`;
8
+ case 'error':
9
+ return ` ! ${terminalSafeLine(event.text)}`;
10
+ case 'message':
11
+ return event.from === 'agent' ? `\n${indent(event.text, ' ')}\n` : null;
12
+ }
13
+ }
14
+ const HEADLINE = {
15
+ working: 'The agent is still working.',
16
+ proposed: 'The agent is waiting for you to apply or reject what it proposed.',
17
+ replied: 'The agent replied.',
18
+ stopped: 'The agent stopped before it finished.',
19
+ ended: 'This conversation has ended.',
20
+ };
21
+ const STOP_REASON = {
22
+ stopped_by_user: 'it was asked to stop',
23
+ discarded: 'its task was discarded',
24
+ out_of_credits: 'the workspace ran out of credits',
25
+ budget_reached: 'it reached the spending limit for one conversation',
26
+ retries_exhausted: 'it hit errors it could not get past',
27
+ refusal: 'it declined the request',
28
+ };
29
+ /**
30
+ * What to do next, for people and coding agents alike; `--output json`
31
+ * carries the same list as `next`.
32
+ */
33
+ export function nextSteps(conversation) {
34
+ const steps = [];
35
+ switch (conversation.state) {
36
+ case 'working':
37
+ steps.push({ command: 'testsprite status --wait', why: 'follow it until it needs you' });
38
+ steps.push({ command: 'testsprite stop', why: 'stop it where it is' });
39
+ break;
40
+ case 'proposed': {
41
+ const proposal = conversation.proposal;
42
+ if (proposal?.kind === 'plan') {
43
+ steps.push({ command: 'testsprite apply', why: 'save the plan to the test suite' });
44
+ const refs = planRefList(proposal);
45
+ if (refs.length > 1) {
46
+ steps.push({
47
+ command: `testsprite apply --exclude ${refs[refs.length - 1]}`,
48
+ why: 'save all of it but the tests you name',
49
+ });
50
+ }
51
+ }
52
+ else if (proposal?.kind === 'run') {
53
+ steps.push({ command: 'testsprite apply', why: 'start the run (it uses credits)' });
54
+ if (proposal.run?.environment) {
55
+ steps.push({
56
+ command: 'testsprite apply --env <name>',
57
+ why: "start it on another of the project's environments",
58
+ });
59
+ }
60
+ }
61
+ else if (proposal?.kind === 'secret') {
62
+ steps.push({
63
+ command: 'testsprite apply',
64
+ why: 'a person types it in a terminal, or pipe it with --secret-stdin, or apply it in the portal',
65
+ });
66
+ }
67
+ else if (proposal?.kind === 'question' && proposal.questions?.length) {
68
+ steps.push({
69
+ command: `testsprite apply ${proposal.questions
70
+ .map((q, i) => `--answer ${i + 1}=${q.multiSelect ? 'a,b' : 'a'}`)
71
+ .join(' ')}`,
72
+ why: 'answer each question by letter; your own words in quotes: --answer 1="…"',
73
+ });
74
+ }
75
+ else {
76
+ steps.push({ command: 'testsprite apply', why: 'go ahead with it' });
77
+ }
78
+ steps.push({ command: 'testsprite reject "<what to change>"', why: 'the agent revises it' });
79
+ break;
80
+ }
81
+ case 'replied':
82
+ steps.push({
83
+ command: 'testsprite reply "<message>"',
84
+ why: 'answer it, or ask for more in the same conversation',
85
+ });
86
+ break;
87
+ case 'stopped':
88
+ if (conversation.stopReason === 'out_of_credits') {
89
+ steps.push({ command: 'testsprite usage', why: "check the workspace's balance" });
90
+ }
91
+ steps.push({
92
+ command: 'testsprite reply "<message>"',
93
+ why: conversation.stopReason === 'discarded' ? 'pick it up again' : 'ask it to go on',
94
+ });
95
+ if (conversation.stopReason === 'discarded') {
96
+ steps.push({
97
+ command: 'testsprite plan "<what to test>"',
98
+ why: 'start a new conversation',
99
+ });
100
+ }
101
+ break;
102
+ case 'ended':
103
+ steps.push({ command: 'testsprite plan "<what to test>"', why: 'start a new conversation' });
104
+ break;
105
+ }
106
+ return steps;
107
+ }
108
+ function planRefList(proposal) {
109
+ const plan = proposal.plan;
110
+ if (!plan)
111
+ return [];
112
+ return [...plan.added, ...plan.changed, ...plan.removed].map(t => t.ref);
113
+ }
114
+ /** The conversation as it stands, for the terminal. */
115
+ export function renderConversation(conversation, options = {}) {
116
+ const lines = [];
117
+ const reason = conversation.stopReason ? STOP_REASON[conversation.stopReason] : undefined;
118
+ const silent = conversation.state === 'replied' && !conversation.reply && !options.replyShown;
119
+ lines.push(reason
120
+ ? `${HEADLINE[conversation.state].slice(0, -1)}: ${reason}.`
121
+ : silent
122
+ ? 'The agent ended its turn without a message.'
123
+ : HEADLINE[conversation.state]);
124
+ if (conversation.reply && !options.replyShown) {
125
+ lines.push('', indent(conversation.reply, ' '));
126
+ }
127
+ if (conversation.proposal) {
128
+ lines.push('', ...renderProposal(conversation.proposal, options.steps ?? false));
129
+ }
130
+ lines.push('', ...renderNext(options.next ?? nextSteps(conversation)));
131
+ lines.push(` ${'Open in the portal'.padEnd(NEXT_WIDTH)}${terminalSafeLine(conversation.url)}`);
132
+ return lines.join('\n');
133
+ }
134
+ const NEXT_WIDTH = 40;
135
+ function renderNext(steps) {
136
+ return [
137
+ 'Next:',
138
+ ...steps.flatMap(s => {
139
+ // A command can name a server ref (`apply --exclude <ref>`): one line, terminal-safe.
140
+ const command = terminalSafeLine(s.command);
141
+ return command.length < NEXT_WIDTH
142
+ ? [` ${command.padEnd(NEXT_WIDTH)}${s.why}`]
143
+ : [` ${command}`, ` ${' '.repeat(NEXT_WIDTH)}${s.why}`];
144
+ }),
145
+ ];
146
+ }
147
+ export function renderProposal(proposal, showSteps) {
148
+ const lines = [`Proposed: ${terminalSafeLine(proposal.summary)}`];
149
+ if (proposal.message)
150
+ lines.push(indent(proposal.message, ' '));
151
+ const plan = proposal.plan;
152
+ if (plan) {
153
+ const width = Math.max(...planRefList(proposal).map(ref => ref.length), 1);
154
+ const under = ' '.repeat(6 + width);
155
+ if (plan.added.length) {
156
+ lines.push('', ' New tests');
157
+ for (const test of plan.added)
158
+ lines.push(...renderTest(test, showSteps, width));
159
+ }
160
+ if (plan.changed.length) {
161
+ lines.push('', ' Changed tests');
162
+ for (const change of plan.changed) {
163
+ const what = [
164
+ change.useCase && `moves to ${terminalSafeLine(change.useCase)}`,
165
+ change.priority && `priority ${terminalSafeLine(change.priority)}`,
166
+ change.description !== undefined && 'new description',
167
+ change.steps && 'new steps',
168
+ ].filter(Boolean);
169
+ lines.push(` ${terminalSafeLine(change.ref).padEnd(width)} ${terminalSafeLine(change.title)}${what.length ? ` (${what.join(', ')})` : ''}`);
170
+ if (change.description)
171
+ lines.push(indent(change.description, under));
172
+ if (showSteps && change.steps)
173
+ lines.push(...renderSteps(change.steps, under));
174
+ }
175
+ }
176
+ if (plan.removed.length) {
177
+ lines.push('', ' Removed tests', ...plan.removed.map(r => ` ${terminalSafeLine(r.ref)}`));
178
+ }
179
+ if (!showSteps && [...plan.added, ...plan.changed].some(t => t.steps?.length)) {
180
+ lines.push('', ' Add --steps to see each test step by step.');
181
+ }
182
+ }
183
+ for (const change of proposal.changes ?? []) {
184
+ lines.push(` ${terminalSafeLine(change.op).padEnd(7)} ${terminalSafeLine(change.name)}${change.detail ? ` ${terminalSafeLine(change.detail)}` : ''}`);
185
+ }
186
+ if (proposal.secret) {
187
+ lines.push('', ` For the ${terminalSafeLine(proposal.secret.environment)} environment. A person types it, or it is piped in with --secret-stdin; it is never passed as a flag.`);
188
+ }
189
+ if (proposal.run) {
190
+ lines.push(proposal.run.tests.length
191
+ ? ` Tests: ${terminalSafeLine(proposal.run.tests.join(', '))}`
192
+ : ' Every test in the project');
193
+ const environment = proposal.run.environment;
194
+ if (environment) {
195
+ lines.push(` On the ${terminalSafeLine(environment.name)} environment${environment.isDefault ? " (the project's default)" : ''}; --env <name> picks another.`);
196
+ }
197
+ }
198
+ if (proposal.questions?.length)
199
+ lines.push(...renderQuestions(proposal.questions));
200
+ if (proposal.problems?.length) {
201
+ lines.push('', " Can't be saved as written:", ...proposal.problems.map(p => ` ${terminalSafeLine(p.path)}: ${terminalSafeLine(p.reason)}`));
202
+ }
203
+ return lines;
204
+ }
205
+ function renderQuestions(questions) {
206
+ const lines = [];
207
+ questions.forEach((q, i) => {
208
+ lines.push('', ` ${i + 1}. ${terminalSafeLine(q.header)} — ${terminalSafeLine(q.question)}${q.multiSelect ? ' (pick several, comma-separated)' : ''}`);
209
+ q.options.forEach((o, j) => {
210
+ lines.push(` ${optionLetter(j)}) ${terminalSafeLine(o.label)}${o.description ? ` — ${terminalSafeLine(o.description)}` : ''}`);
211
+ });
212
+ });
213
+ return lines;
214
+ }
215
+ function renderTest(test, showSteps, width) {
216
+ const under = ' '.repeat(6 + width);
217
+ const lines = [
218
+ ` ${terminalSafeLine(test.ref).padEnd(width)} ${terminalSafeLine(test.useCase)} · ${terminalSafeLine(test.title)} [${terminalSafeLine(test.priority)}]`,
219
+ ];
220
+ if (test.description)
221
+ lines.push(indent(test.description, under));
222
+ if (showSteps)
223
+ lines.push(...renderSteps(test.steps, under));
224
+ return lines;
225
+ }
226
+ function renderSteps(steps, under) {
227
+ return steps.map((step, i) => `${under}${i + 1}. ${step.type === 'assertion' ? 'Check: ' : ''}${terminalSafeLine(step.description)}`);
228
+ }
229
+ export function renderApplied(result) {
230
+ const applied = terminalSafeLine(result.applied);
231
+ const lines = [result.ok ? `Applied: ${applied}` : `Could not apply: ${applied}`];
232
+ for (const saved of result.saved ?? [])
233
+ lines.push(` ✓ ${terminalSafeLine(saved.detail)}`);
234
+ for (const failed of result.failed ?? [])
235
+ lines.push(` ✗ ${terminalSafeLine(failed.path)}: ${terminalSafeLine(failed.error)}`);
236
+ if (result.run) {
237
+ const where = result.run.environment ? ` on ${terminalSafeLine(result.run.environment)}` : '';
238
+ lines.push(` Run started: ${result.run.tests.length} ${result.run.tests.length === 1 ? 'test' : 'tests'}${where} (run ${terminalSafeLine(result.run.runId)}).`);
239
+ }
240
+ if (result.message)
241
+ lines.push(indent(result.message, ' '));
242
+ return lines.join('\n');
243
+ }
244
+ /**
245
+ * Earlier conversations still waiting for an apply or reject. The agent leaves
246
+ * the tests such a proposal changes alone, so a new plan says so up front.
247
+ */
248
+ export function waitingNotes(conversations) {
249
+ const waiting = conversations.filter(c => c.state === 'proposed');
250
+ if (!waiting.length)
251
+ return [];
252
+ const shown = waiting
253
+ .slice(0, 3)
254
+ .map(c => ` testsprite status --conversation ${terminalSafeLine(c.id)}`);
255
+ const who = waiting.length === 1
256
+ ? 'An earlier conversation is still waiting for you to apply or reject what it proposed'
257
+ : `${waiting.length} earlier conversations are still waiting for you to apply or reject what they proposed`;
258
+ return [
259
+ `${who}; the agent leaves what is proposed there alone until then:`,
260
+ ...shown,
261
+ ...(waiting.length > shown.length ? [' testsprite status --list'] : []),
262
+ 'Drop one you no longer need with `testsprite discard --conversation <id>`.',
263
+ ];
264
+ }
265
+ export function renderConversationList(conversations) {
266
+ if (!conversations.length)
267
+ return 'No conversations with the agent on this project yet.';
268
+ return conversations
269
+ .map(c => `${terminalSafeLine(c.id)} ${terminalSafeLine(c.state).padEnd(8)} ${terminalSafeLine(c.lastMessageAt.slice(0, 16).replace('T', ' '))} ${terminalSafeLine(c.title ?? '(untitled)')}`)
270
+ .join('\n');
271
+ }
272
+ /**
273
+ * Server text (a reply, a message, a description) placed under `prefix`. It is
274
+ * made terminal-safe on its own, before it is split, so a sequence in it can
275
+ * reach nothing the CLI wrote around it and a carriage return becomes a line
276
+ * that is indented like the rest.
277
+ */
278
+ function indent(text, prefix) {
279
+ return terminalSafe(text)
280
+ .split('\n')
281
+ .map(line => (line ? `${prefix}${line}` : line))
282
+ .join('\n');
283
+ }
284
+ const PR_VERB = {
285
+ created: 'Added',
286
+ updated: 'Changed',
287
+ deleted: 'Removed',
288
+ };
289
+ /**
290
+ * The tests a plan saved, as a pull request's description lists them, so the
291
+ * reviewers of a change see the tests that now guard it. `inLine` is applied
292
+ * to each server value (an id, a title, the link): the terminal passes
293
+ * `terminalSafeLine`, the JSON keeps the values as sent.
294
+ */
295
+ export function prSummary(applied, url, inLine = value => value) {
296
+ // Only tests belong in a pull request; an environment or schedule is project setup.
297
+ const tests = (applied.saved ?? []).filter(saved => saved.path.startsWith('/test-cases/'));
298
+ const rows = tests.flatMap(saved => {
299
+ const [verb, id] = saved.detail.split(' ');
300
+ const said = PR_VERB[verb ?? ''];
301
+ if (!said || !id)
302
+ return [];
303
+ return [`- ${said} \`${inLine(id)}\`${saved.title ? ` ${inLine(saved.title)}` : ''}`];
304
+ });
305
+ if (!rows.length)
306
+ return null;
307
+ return [
308
+ '### TestSprite',
309
+ 'Tests for this change in the regression suite:',
310
+ ...rows,
311
+ '',
312
+ `Written by the TestSprite agent: ${inLine(url)}`,
313
+ ].join('\n');
314
+ }
315
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1,2 @@
1
+ /** A conversation's name from its first message, the portal's way: its first line, cut at a word. */
2
+ export declare function titleFrom(message: string): string | undefined;
@@ -0,0 +1,18 @@
1
+ /** The longest a conversation's name runs before it is cut at a word, as the portal names one. */
2
+ const TITLE_MAX = 80;
3
+ /** A conversation's name from its first message, the portal's way: its first line, cut at a word. */
4
+ export function titleFrom(message) {
5
+ const line = message
6
+ .split('\n')
7
+ .map(l => l.trim())
8
+ .find(Boolean)
9
+ ?.replace(/\s+/g, ' ') ?? '';
10
+ if (!line)
11
+ return undefined;
12
+ if (line.length <= TITLE_MAX)
13
+ return line;
14
+ const cut = line.slice(0, TITLE_MAX);
15
+ const space = cut.lastIndexOf(' ');
16
+ return `${(space > TITLE_MAX / 2 ? cut.slice(0, space) : cut).replace(/[\s,.;:–-]+$/, '')}…`;
17
+ }
18
+ //# sourceMappingURL=title.js.map
@@ -0,0 +1,156 @@
1
+ /**
2
+ * The agent conversation as `/api/cli/v1/projects/{id}/conversations` returns
3
+ * it: the same conversation the portal shows, read by polling.
4
+ */
5
+ /**
6
+ * - `working`: the agent is at work.
7
+ * - `proposed`: it proposed something (a plan, an environment, a run) and waits for apply or reject.
8
+ * - `replied`: its turn is over; read the reply, then answer it or stop there.
9
+ * - `stopped`: it stopped short (asked to, its task discarded, out of credits, its budget, an
10
+ * error, a refusal); `stopReason` says which.
11
+ * - `ended`: the conversation can't go on; start a new one.
12
+ */
13
+ export type ConversationState = 'working' | 'proposed' | 'replied' | 'stopped' | 'ended';
14
+ export type ConversationEvent = {
15
+ seq: number;
16
+ at: string;
17
+ kind: 'message';
18
+ from: 'agent' | 'user';
19
+ text: string;
20
+ } | {
21
+ seq: number;
22
+ at: string;
23
+ kind: 'activity';
24
+ text: string;
25
+ } | {
26
+ seq: number;
27
+ at: string;
28
+ kind: 'error';
29
+ text: string;
30
+ };
31
+ export interface PlanStep {
32
+ type: 'action' | 'assertion';
33
+ description: string;
34
+ }
35
+ export interface PlanTest {
36
+ ref: string;
37
+ useCase: string;
38
+ title: string;
39
+ priority: string;
40
+ description: string;
41
+ steps: PlanStep[];
42
+ }
43
+ export interface PlanChange {
44
+ ref: string;
45
+ title: string;
46
+ useCase?: string;
47
+ priority?: string;
48
+ description?: string;
49
+ steps?: PlanStep[];
50
+ }
51
+ export interface Proposal {
52
+ /** The card's id: what `apply` and `reject` decide. */
53
+ id: string;
54
+ kind: 'plan' | 'environments' | 'schedules' | 'project' | 'docs' | 'fixtures' | 'run' | 'secret' | 'question' | 'action';
55
+ summary: string;
56
+ /** The agent's one line on what the change does and why. */
57
+ message?: string;
58
+ plan?: {
59
+ added: PlanTest[];
60
+ changed: PlanChange[];
61
+ removed: Array<{
62
+ ref: string;
63
+ }>;
64
+ };
65
+ changes?: Array<{
66
+ op: string;
67
+ name: string;
68
+ detail?: string;
69
+ }>;
70
+ /** A secret card: the secret a person types to apply it, which goes to this environment. */
71
+ secret?: {
72
+ environment: string;
73
+ field: string;
74
+ header?: string;
75
+ };
76
+ /** A run card: the tests, and the environment the run goes to (`apply --env` picks another). */
77
+ run?: {
78
+ tests: string[];
79
+ environment?: RunEnvironment;
80
+ };
81
+ /** A question card: applying it answers each question (`apply --answer`). */
82
+ questions?: Question[];
83
+ problems?: Array<{
84
+ path: string;
85
+ reason: string;
86
+ }>;
87
+ }
88
+ export interface Question {
89
+ question: string;
90
+ /** A few words naming the question, as the portal's card tabs it. */
91
+ header: string;
92
+ options: Array<{
93
+ label: string;
94
+ description: string;
95
+ }>;
96
+ /** Several options may be picked; the answer lists their labels, comma-separated. */
97
+ multiSelect: boolean;
98
+ }
99
+ /** Where a run card's run goes: the environment the agent named, else the project's default. */
100
+ export interface RunEnvironment {
101
+ id: string;
102
+ name: string;
103
+ isDefault: boolean;
104
+ }
105
+ export interface Conversation {
106
+ id: string;
107
+ projectId: string | null;
108
+ title: string | null;
109
+ url: string;
110
+ state: ConversationState;
111
+ stopReason?: string;
112
+ model: string;
113
+ lastSeq: number;
114
+ events: ConversationEvent[];
115
+ proposal: Proposal | null;
116
+ reply: string | null;
117
+ }
118
+ export interface ConversationSummary {
119
+ id: string;
120
+ title: string | null;
121
+ state: ConversationState;
122
+ lastMessageAt: string;
123
+ url: string;
124
+ }
125
+ export interface ApplyResult {
126
+ applied: string;
127
+ ok: boolean;
128
+ saved?: Array<{
129
+ path: string;
130
+ detail: string;
131
+ title?: string;
132
+ }>;
133
+ failed?: Array<{
134
+ path: string;
135
+ error: string;
136
+ }>;
137
+ tests?: string[];
138
+ /** A run the proposal started. `runId` is the wire name of its launch; `environment` names where it runs. */
139
+ run?: {
140
+ runId: string;
141
+ tests: string[];
142
+ environment?: string;
143
+ };
144
+ message?: string;
145
+ }
146
+ /** An {@link ApplyResult} as it is printed: the launch of a run it started is `run.runId`. */
147
+ /** What the CLI tells the agent about who started the conversation and from where. */
148
+ export interface Brief {
149
+ caller: 'agent' | 'person';
150
+ repository?: {
151
+ name?: string;
152
+ branch?: string;
153
+ commit?: string;
154
+ };
155
+ change?: string;
156
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The agent conversation as `/api/cli/v1/projects/{id}/conversations` returns
3
+ * it: the same conversation the portal shows, read by polling.
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=types.js.map
@@ -4,6 +4,7 @@ import { randomUUID } from 'node:crypto';
4
4
  import { homedir } from 'node:os';
5
5
  import { dirname, join } from 'node:path';
6
6
  import { localValidationError } from './errors.js';
7
+ import { readTextFileBomAware } from './text-file.js';
7
8
  export const DEFAULT_PROFILE = 'default';
8
9
  /**
9
10
  * Allowed profile-name characters. A profile name is written verbatim as an
@@ -65,8 +66,33 @@ const CREDENTIALS_LOCK_TRANSIENT_WAIT_MS = 1_000;
65
66
  const CREDENTIALS_LOCK_STALE_MS = 30_000;
66
67
  // How long a transient Windows error on replacing the credentials file is retried.
67
68
  const CREDENTIALS_RENAME_TRANSIENT_WAIT_MS = 2_000;
69
+ /**
70
+ * Section names that are never a profile. Used as a key on an ordinary object,
71
+ * `__proto__` and `constructor` reach the object's prototype and the shared
72
+ * `Object` function instead of naming an entry, so the key/value lines under
73
+ * such a header would be written onto a built-in the whole process shares
74
+ * (for `__proto__`, onto every object). Neither ever worked as a profile name.
75
+ * `prototype` is not among them: an ordinary object has no such member, and a
76
+ * profile by that name has always read and written normally. The parser drops
77
+ * these sections, the serialiser never writes them, and `writeProfile` refuses
78
+ * them, so the three agree on what can be stored.
79
+ */
80
+ const RESERVED_SECTION_NAMES = new Set(['__proto__', 'constructor']);
81
+ /**
82
+ * Look a profile up by name without consulting the prototype chain. A name
83
+ * that comes from the file, a flag or an environment variable can spell an
84
+ * inherited member (`toString`, `hasOwnProperty`, `__proto__`); a plain
85
+ * `file[name]` would then hand back that built-in as if it were a profile.
86
+ */
87
+ function ownProfile(file, profile) {
88
+ return Object.hasOwn(file, profile) ? file[profile] : undefined;
89
+ }
68
90
  export function parseCredentials(content) {
69
- const result = {};
91
+ // Sections are collected on an object with no prototype, so a name read from
92
+ // the file can only ever find a section this loop stored itself. On an
93
+ // ordinary object `[toString]` would find the inherited function and the
94
+ // lines under it would be written onto that shared built-in.
95
+ const sections = Object.create(null);
70
96
  let currentEntry = null;
71
97
  for (const rawLine of content.split('\n')) {
72
98
  const line = rawLine.trim();
@@ -75,13 +101,19 @@ export function parseCredentials(content) {
75
101
  const sectionMatch = /^\[([^\]]+)\]$/.exec(line);
76
102
  if (sectionMatch) {
77
103
  const sectionName = sectionMatch[1].trim();
78
- const existing = result[sectionName];
104
+ if (RESERVED_SECTION_NAMES.has(sectionName)) {
105
+ // Not a profile: leave no current section, so the key/value lines under
106
+ // this header are skipped rather than applied to the section above it.
107
+ currentEntry = null;
108
+ continue;
109
+ }
110
+ const existing = sections[sectionName];
79
111
  if (existing) {
80
112
  currentEntry = existing;
81
113
  }
82
114
  else {
83
115
  const newEntry = {};
84
- result[sectionName] = newEntry;
116
+ sections[sectionName] = newEntry;
85
117
  currentEntry = newEntry;
86
118
  }
87
119
  continue;
@@ -93,14 +125,22 @@ export function parseCredentials(content) {
93
125
  continue;
94
126
  const rawKey = line.slice(0, eqIndex).trim();
95
127
  const rawValue = line.slice(eqIndex + 1).trim();
96
- const field = FILE_KEY_TO_FIELD[rawKey];
128
+ // Own-property lookup: a key such as `constructor` must not match the
129
+ // inherited `Object` function and be taken for a known field.
130
+ const field = Object.hasOwn(FILE_KEY_TO_FIELD, rawKey) ? FILE_KEY_TO_FIELD[rawKey] : undefined;
97
131
  if (field)
98
132
  currentEntry[field] = rawValue;
99
133
  }
100
- return result;
134
+ // Callers and test matchers expect ordinary objects, so hand the sections
135
+ // back on one. `Object.fromEntries` defines each as an own property.
136
+ return Object.fromEntries(Object.entries(sections));
101
137
  }
102
138
  export function serializeCredentials(file) {
103
- const orderedSections = Object.keys(file).sort((a, b) => {
139
+ const orderedSections = Object.keys(file)
140
+ // The parser drops these sections, so writing one would store a profile
141
+ // that can never be read back.
142
+ .filter(section => !RESERVED_SECTION_NAMES.has(section))
143
+ .sort((a, b) => {
104
144
  if (a === DEFAULT_PROFILE)
105
145
  return -1;
106
146
  if (b === DEFAULT_PROFILE)
@@ -115,6 +155,11 @@ export function serializeCredentials(file) {
115
155
  lines.push(`[${section}]`);
116
156
  const fields = Object.keys(entry).sort();
117
157
  for (const field of fields) {
158
+ // Own-property lookup: an entry key the file format does not know has no
159
+ // line to be written as, and one that spells an inherited member
160
+ // (`constructor`) would otherwise print that built-in as the key.
161
+ if (!Object.hasOwn(FIELD_TO_FILE_KEY, field))
162
+ continue;
118
163
  const value = entry[field];
119
164
  if (value === undefined || value === '')
120
165
  continue;
@@ -137,18 +182,26 @@ export function readCredentialsFile(options = {}) {
137
182
  const path = resolvePath(options);
138
183
  if (!existsSync(path))
139
184
  return {};
140
- return parseCredentials(readFileSync(path, 'utf-8'));
185
+ // Shared BOM sniff (UTF-8, UTF-16LE, UTF-16BE). Writes stay UTF-8 with no BOM,
186
+ // so a UTF-16 file is normalised on the next save. The parser is unchanged.
187
+ return parseCredentials(readTextFileBomAware(path));
141
188
  }
142
189
  export function readProfile(profile, options = {}) {
143
190
  assertValidProfileName(profile);
144
- const file = readCredentialsFile(options);
145
- return file[profile];
191
+ return ownProfile(readCredentialsFile(options), profile);
146
192
  }
147
193
  export function writeProfile(profile, entry, options = {}) {
148
194
  assertValidProfileName(profile);
195
+ // Refused before the directory, lock or file is touched: the parser drops a
196
+ // section with one of these names, so the profile could never be read back,
197
+ // and assigning to `__proto__` would swap the file object's prototype
198
+ // instead of adding an entry.
199
+ if (RESERVED_SECTION_NAMES.has(profile)) {
200
+ throw localValidationError('profile', 'must not be __proto__ or constructor (reserved names that cannot be stored)', undefined, 'flag');
201
+ }
149
202
  const path = resolvePath(options);
150
203
  mutateCredentialsFile(path, file => {
151
- file[profile] = { ...file[profile], ...entry };
204
+ file[profile] = { ...ownProfile(file, profile), ...entry };
152
205
  return file;
153
206
  });
154
207
  }
@@ -159,7 +212,10 @@ export function deleteProfile(profile, options = {}) {
159
212
  return false;
160
213
  let removed = false;
161
214
  mutateCredentialsFile(path, file => {
162
- if (!(profile in file))
215
+ // Own-property check: `in` also sees inherited members, so a name such as
216
+ // `__proto__` or `toString` would be reported as removed and the file
217
+ // rewritten although no such profile was ever stored.
218
+ if (!Object.hasOwn(file, profile))
163
219
  return undefined;
164
220
  removed = true;
165
221
  delete file[profile];