@testsprite/testsprite-cli 0.16.0 → 0.18.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 +52 -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 +40 -56
  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 +741 -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 +434 -43
  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 +19 -186
  19. package/dist/commands/project.js +108 -926
  20. package/dist/commands/result.d.ts +10 -0
  21. package/dist/commands/result.js +216 -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 -1838
  25. package/dist/commands/test.js +1880 -13917
  26. package/dist/commands/testlist.d.ts +130 -5
  27. package/dist/commands/testlist.js +300 -342
  28. package/dist/commands/tunnel.d.ts +3 -3
  29. package/dist/commands/tunnel.js +23 -20
  30. package/dist/commands/usage.d.ts +12 -45
  31. package/dist/commands/usage.js +50 -131
  32. package/dist/index.js +191 -110
  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 +12 -4
  45. package/dist/lib/client-factory.js +41 -30
  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 +75 -0
  56. package/dist/lib/conversation/api.js +151 -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 +29 -0
  60. package/dist/lib/conversation/context.js +82 -0
  61. package/dist/lib/conversation/environment.d.ts +16 -0
  62. package/dist/lib/conversation/environment.js +21 -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 +318 -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 +158 -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 +100 -0
  77. package/dist/lib/download.js +408 -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 +19 -30
  83. package/dist/lib/environment-tunnel.js +168 -202
  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 +20 -30
  91. package/dist/lib/first-suite-hint.js +57 -72
  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 +354 -291
  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 +8 -7
  107. package/dist/lib/local-target.js +14 -13
  108. package/dist/lib/output.d.ts +2 -41
  109. package/dist/lib/output.js +13 -51
  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 +170 -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 +73 -0
  127. package/dist/lib/result/evidence.js +422 -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 +8 -8
  151. package/dist/lib/target-url.js +14 -24
  152. package/dist/lib/telemetry.d.ts +35 -15
  153. package/dist/lib/telemetry.js +38 -9
  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 +8 -2
  169. package/dist/lib/tunnel-session.js +24 -11
  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 +52 -23
  183. package/skills/testsprite-onboard.skill.md +70 -153
  184. package/skills/testsprite-verify.codex.md +54 -58
  185. package/skills/testsprite-verify.skill.md +189 -358
  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,318 @@
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
+ if (plan.environment) {
183
+ lines.push('', ` Explored on the ${terminalSafeLine(plan.environment.name)} environment${plan.environment.isDefault ? " (the project's default)" : ''}.`);
184
+ }
185
+ }
186
+ for (const change of proposal.changes ?? []) {
187
+ lines.push(` ${terminalSafeLine(change.op).padEnd(7)} ${terminalSafeLine(change.name)}${change.detail ? ` ${terminalSafeLine(change.detail)}` : ''}`);
188
+ }
189
+ if (proposal.secret) {
190
+ 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.`);
191
+ }
192
+ if (proposal.run) {
193
+ lines.push(proposal.run.tests.length
194
+ ? ` Tests: ${terminalSafeLine(proposal.run.tests.join(', '))}`
195
+ : ' Every test in the project');
196
+ const environment = proposal.run.environment;
197
+ if (environment) {
198
+ lines.push(` On the ${terminalSafeLine(environment.name)} environment${environment.isDefault ? " (the project's default)" : ''}; --env <name> picks another.`);
199
+ }
200
+ }
201
+ if (proposal.questions?.length)
202
+ lines.push(...renderQuestions(proposal.questions));
203
+ if (proposal.problems?.length) {
204
+ lines.push('', " Can't be saved as written:", ...proposal.problems.map(p => ` ${terminalSafeLine(p.path)}: ${terminalSafeLine(p.reason)}`));
205
+ }
206
+ return lines;
207
+ }
208
+ function renderQuestions(questions) {
209
+ const lines = [];
210
+ questions.forEach((q, i) => {
211
+ lines.push('', ` ${i + 1}. ${terminalSafeLine(q.header)} — ${terminalSafeLine(q.question)}${q.multiSelect ? ' (pick several, comma-separated)' : ''}`);
212
+ q.options.forEach((o, j) => {
213
+ lines.push(` ${optionLetter(j)}) ${terminalSafeLine(o.label)}${o.description ? ` — ${terminalSafeLine(o.description)}` : ''}`);
214
+ });
215
+ });
216
+ return lines;
217
+ }
218
+ function renderTest(test, showSteps, width) {
219
+ const under = ' '.repeat(6 + width);
220
+ const lines = [
221
+ ` ${terminalSafeLine(test.ref).padEnd(width)} ${terminalSafeLine(test.useCase)} · ${terminalSafeLine(test.title)} [${terminalSafeLine(test.priority)}]`,
222
+ ];
223
+ if (test.description)
224
+ lines.push(indent(test.description, under));
225
+ if (showSteps)
226
+ lines.push(...renderSteps(test.steps, under));
227
+ return lines;
228
+ }
229
+ function renderSteps(steps, under) {
230
+ return steps.map((step, i) => `${under}${i + 1}. ${step.type === 'assertion' ? 'Check: ' : ''}${terminalSafeLine(step.description)}`);
231
+ }
232
+ export function renderApplied(result) {
233
+ const applied = terminalSafeLine(result.applied);
234
+ const lines = [result.ok ? `Applied: ${applied}` : `Could not apply: ${applied}`];
235
+ for (const saved of result.saved ?? [])
236
+ lines.push(` ✓ ${terminalSafeLine(saved.detail)}`);
237
+ for (const failed of result.failed ?? [])
238
+ lines.push(` ✗ ${terminalSafeLine(failed.path)}: ${terminalSafeLine(failed.error)}`);
239
+ if (result.run) {
240
+ const where = result.run.environment ? ` on ${terminalSafeLine(result.run.environment)}` : '';
241
+ lines.push(` Run started: ${result.run.tests.length} ${result.run.tests.length === 1 ? 'test' : 'tests'}${where} (run ${terminalSafeLine(result.run.runId)}).`);
242
+ }
243
+ if (result.message)
244
+ lines.push(indent(result.message, ' '));
245
+ return lines.join('\n');
246
+ }
247
+ /**
248
+ * Earlier conversations still waiting for an apply or reject. The agent leaves
249
+ * the tests such a proposal changes alone, so a new plan says so up front.
250
+ */
251
+ export function waitingNotes(conversations) {
252
+ const waiting = conversations.filter(c => c.state === 'proposed');
253
+ if (!waiting.length)
254
+ return [];
255
+ const shown = waiting
256
+ .slice(0, 3)
257
+ .map(c => ` testsprite status --conversation ${terminalSafeLine(c.id)}`);
258
+ const who = waiting.length === 1
259
+ ? 'An earlier conversation is still waiting for you to apply or reject what it proposed'
260
+ : `${waiting.length} earlier conversations are still waiting for you to apply or reject what they proposed`;
261
+ return [
262
+ `${who}; the agent leaves what is proposed there alone until then:`,
263
+ ...shown,
264
+ ...(waiting.length > shown.length ? [' testsprite status --list'] : []),
265
+ 'Drop one you no longer need with `testsprite discard --conversation <id>`.',
266
+ ];
267
+ }
268
+ export function renderConversationList(conversations) {
269
+ if (!conversations.length)
270
+ return 'No conversations with the agent on this project yet.';
271
+ return conversations
272
+ .map(c => `${terminalSafeLine(c.id)} ${terminalSafeLine(c.state).padEnd(8)} ${terminalSafeLine(c.lastMessageAt.slice(0, 16).replace('T', ' '))} ${terminalSafeLine(c.title ?? '(untitled)')}`)
273
+ .join('\n');
274
+ }
275
+ /**
276
+ * Server text (a reply, a message, a description) placed under `prefix`. It is
277
+ * made terminal-safe on its own, before it is split, so a sequence in it can
278
+ * reach nothing the CLI wrote around it and a carriage return becomes a line
279
+ * that is indented like the rest.
280
+ */
281
+ function indent(text, prefix) {
282
+ return terminalSafe(text)
283
+ .split('\n')
284
+ .map(line => (line ? `${prefix}${line}` : line))
285
+ .join('\n');
286
+ }
287
+ const PR_VERB = {
288
+ created: 'Added',
289
+ updated: 'Changed',
290
+ deleted: 'Removed',
291
+ };
292
+ /**
293
+ * The tests a plan saved, as a pull request's description lists them, so the
294
+ * reviewers of a change see the tests that now guard it. `inLine` is applied
295
+ * to each server value (an id, a title, the link): the terminal passes
296
+ * `terminalSafeLine`, the JSON keeps the values as sent.
297
+ */
298
+ export function prSummary(applied, url, inLine = value => value) {
299
+ // Only tests belong in a pull request; an environment or schedule is project setup.
300
+ const tests = (applied.saved ?? []).filter(saved => saved.path.startsWith('/test-cases/'));
301
+ const rows = tests.flatMap(saved => {
302
+ const [verb, id] = saved.detail.split(' ');
303
+ const said = PR_VERB[verb ?? ''];
304
+ if (!said || !id)
305
+ return [];
306
+ return [`- ${said} \`${inLine(id)}\`${saved.title ? ` ${inLine(saved.title)}` : ''}`];
307
+ });
308
+ if (!rows.length)
309
+ return null;
310
+ return [
311
+ '### TestSprite',
312
+ 'Tests for this change in the regression suite:',
313
+ ...rows,
314
+ '',
315
+ `Written by the TestSprite agent: ${inLine(url)}`,
316
+ ].join('\n');
317
+ }
318
+ //# 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,158 @@
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
+ /** The environment the agent explored these tests on, when it named one: where to run them. */
65
+ environment?: RunEnvironment;
66
+ };
67
+ changes?: Array<{
68
+ op: string;
69
+ name: string;
70
+ detail?: string;
71
+ }>;
72
+ /** A secret card: the secret a person types to apply it, which goes to this environment. */
73
+ secret?: {
74
+ environment: string;
75
+ field: string;
76
+ header?: string;
77
+ };
78
+ /** A run card: the tests, and the environment the run goes to (`apply --env` picks another). */
79
+ run?: {
80
+ tests: string[];
81
+ environment?: RunEnvironment;
82
+ };
83
+ /** A question card: applying it answers each question (`apply --answer`). */
84
+ questions?: Question[];
85
+ problems?: Array<{
86
+ path: string;
87
+ reason: string;
88
+ }>;
89
+ }
90
+ export interface Question {
91
+ question: string;
92
+ /** A few words naming the question, as the portal's card tabs it. */
93
+ header: string;
94
+ options: Array<{
95
+ label: string;
96
+ description: string;
97
+ }>;
98
+ /** Several options may be picked; the answer lists their labels, comma-separated. */
99
+ multiSelect: boolean;
100
+ }
101
+ /** Where a run card's run goes: the environment the agent named, else the project's default. */
102
+ export interface RunEnvironment {
103
+ id: string;
104
+ name: string;
105
+ isDefault: boolean;
106
+ }
107
+ export interface Conversation {
108
+ id: string;
109
+ projectId: string | null;
110
+ title: string | null;
111
+ url: string;
112
+ state: ConversationState;
113
+ stopReason?: string;
114
+ model: string;
115
+ lastSeq: number;
116
+ events: ConversationEvent[];
117
+ proposal: Proposal | null;
118
+ reply: string | null;
119
+ }
120
+ export interface ConversationSummary {
121
+ id: string;
122
+ title: string | null;
123
+ state: ConversationState;
124
+ lastMessageAt: string;
125
+ url: string;
126
+ }
127
+ export interface ApplyResult {
128
+ applied: string;
129
+ ok: boolean;
130
+ saved?: Array<{
131
+ path: string;
132
+ detail: string;
133
+ title?: string;
134
+ }>;
135
+ failed?: Array<{
136
+ path: string;
137
+ error: string;
138
+ }>;
139
+ tests?: string[];
140
+ /** A run the proposal started. `runId` is the wire name of its launch; `environment` names where it runs. */
141
+ run?: {
142
+ runId: string;
143
+ tests: string[];
144
+ environment?: string;
145
+ };
146
+ message?: string;
147
+ }
148
+ /** An {@link ApplyResult} as it is printed: the launch of a run it started is `run.runId`. */
149
+ /** What the CLI tells the agent about who started the conversation and from where. */
150
+ export interface Brief {
151
+ caller: 'agent' | 'person';
152
+ repository?: {
153
+ name?: string;
154
+ branch?: string;
155
+ commit?: string;
156
+ };
157
+ change?: string;
158
+ }
@@ -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