@testsprite/testsprite-cli 0.15.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 (207) hide show
  1. package/README.md +53 -141
  2. package/dist/commands/agent.d.ts +12 -4
  3. package/dist/commands/agent.js +55 -65
  4. package/dist/commands/auth.d.ts +6 -10
  5. package/dist/commands/auth.js +44 -56
  6. package/dist/commands/ci.d.ts +23 -100
  7. package/dist/commands/ci.js +297 -489
  8. package/dist/commands/completion.js +2 -1
  9. package/dist/commands/conversation.d.ts +27 -0
  10. package/dist/commands/conversation.js +702 -0
  11. package/dist/commands/doctor.d.ts +5 -1
  12. package/dist/commands/doctor.js +130 -34
  13. package/dist/commands/init.d.ts +4 -45
  14. package/dist/commands/init.js +116 -68
  15. package/dist/commands/project-env.d.ts +62 -2
  16. package/dist/commands/project-env.js +426 -53
  17. package/dist/commands/project-sign-in.d.ts +0 -48
  18. package/dist/commands/project-sign-in.js +1 -224
  19. package/dist/commands/project.d.ts +15 -186
  20. package/dist/commands/project.js +93 -921
  21. package/dist/commands/result.d.ts +10 -0
  22. package/dist/commands/result.js +215 -0
  23. package/dist/commands/schedule.d.ts +0 -29
  24. package/dist/commands/schedule.js +47 -97
  25. package/dist/commands/test.d.ts +315 -1824
  26. package/dist/commands/test.js +1962 -13733
  27. package/dist/commands/testlist.d.ts +128 -5
  28. package/dist/commands/testlist.js +269 -329
  29. package/dist/commands/tunnel.d.ts +2 -2
  30. package/dist/commands/tunnel.js +43 -41
  31. package/dist/commands/usage.d.ts +12 -45
  32. package/dist/commands/usage.js +51 -131
  33. package/dist/index.js +189 -108
  34. package/dist/lib/agent-detect.js +9 -5
  35. package/dist/lib/agent-targets.d.ts +21 -2
  36. package/dist/lib/agent-targets.js +88 -11
  37. package/dist/lib/args.d.ts +13 -0
  38. package/dist/lib/args.js +49 -0
  39. package/dist/lib/basic-auth.d.ts +3 -0
  40. package/dist/lib/basic-auth.js +15 -0
  41. package/dist/lib/billing-refusal.js +4 -3
  42. package/dist/lib/ci-linkage.d.ts +4 -82
  43. package/dist/lib/ci-linkage.js +4 -157
  44. package/dist/lib/ci-run.js +1 -1
  45. package/dist/lib/client-factory.d.ts +10 -2
  46. package/dist/lib/client-factory.js +38 -26
  47. package/dist/lib/commit-signal.d.ts +65 -0
  48. package/dist/lib/commit-signal.js +305 -0
  49. package/dist/lib/concurrency-limiter.d.ts +6 -0
  50. package/dist/lib/concurrency-limiter.js +29 -0
  51. package/dist/lib/config.js +10 -5
  52. package/dist/lib/conflict-reason.d.ts +31 -4
  53. package/dist/lib/conflict-reason.js +38 -4
  54. package/dist/lib/conversation/answers.d.ts +9 -0
  55. package/dist/lib/conversation/answers.js +49 -0
  56. package/dist/lib/conversation/api.d.ts +71 -0
  57. package/dist/lib/conversation/api.js +150 -0
  58. package/dist/lib/conversation/change.d.ts +31 -0
  59. package/dist/lib/conversation/change.js +124 -0
  60. package/dist/lib/conversation/context.d.ts +19 -0
  61. package/dist/lib/conversation/context.js +70 -0
  62. package/dist/lib/conversation/environment.d.ts +15 -0
  63. package/dist/lib/conversation/environment.js +33 -0
  64. package/dist/lib/conversation/follow.d.ts +24 -0
  65. package/dist/lib/conversation/follow.js +42 -0
  66. package/dist/lib/conversation/render.d.ts +33 -0
  67. package/dist/lib/conversation/render.js +315 -0
  68. package/dist/lib/conversation/title.d.ts +2 -0
  69. package/dist/lib/conversation/title.js +18 -0
  70. package/dist/lib/conversation/types.d.ts +156 -0
  71. package/dist/lib/conversation/types.js +6 -0
  72. package/dist/lib/credentials.js +67 -11
  73. package/dist/lib/cron.d.ts +1 -1
  74. package/dist/lib/cron.js +2 -2
  75. package/dist/lib/dispatch-stop.d.ts +20 -0
  76. package/dist/lib/dispatch-stop.js +30 -0
  77. package/dist/lib/download.d.ts +71 -0
  78. package/dist/lib/download.js +274 -0
  79. package/dist/lib/dry-run/fetch.d.ts +10 -0
  80. package/dist/lib/dry-run/fetch.js +20 -0
  81. package/dist/lib/dry-run/samples.d.ts +6 -34
  82. package/dist/lib/dry-run/samples.js +389 -751
  83. package/dist/lib/environment-tunnel.d.ts +16 -26
  84. package/dist/lib/environment-tunnel.js +161 -157
  85. package/dist/lib/errors.d.ts +20 -4
  86. package/dist/lib/errors.js +36 -16
  87. package/dist/lib/facade.d.ts +7 -29
  88. package/dist/lib/facade.js +7 -36
  89. package/dist/lib/failing-fe-resolver.d.ts +13 -58
  90. package/dist/lib/failing-fe-resolver.js +47 -132
  91. package/dist/lib/first-suite-hint.d.ts +16 -22
  92. package/dist/lib/first-suite-hint.js +38 -47
  93. package/dist/lib/gh-output.d.ts +76 -21
  94. package/dist/lib/gh-output.js +171 -90
  95. package/dist/lib/git-utils.d.ts +56 -0
  96. package/dist/lib/git-utils.js +212 -0
  97. package/dist/lib/github-context.d.ts +2 -0
  98. package/dist/lib/github-context.js +40 -8
  99. package/dist/lib/history-retention.d.ts +6 -2
  100. package/dist/lib/history-retention.js +10 -7
  101. package/dist/lib/http.d.ts +58 -134
  102. package/dist/lib/http.js +352 -271
  103. package/dist/lib/interrupt.d.ts +14 -8
  104. package/dist/lib/interrupt.js +28 -10
  105. package/dist/lib/junit-report.d.ts +60 -4
  106. package/dist/lib/junit-report.js +209 -32
  107. package/dist/lib/local-target.d.ts +3 -3
  108. package/dist/lib/local-target.js +3 -3
  109. package/dist/lib/output.d.ts +0 -29
  110. package/dist/lib/output.js +10 -33
  111. package/dist/lib/pagination.d.ts +2 -5
  112. package/dist/lib/pagination.js +2 -5
  113. package/dist/lib/presigned-url.d.ts +22 -0
  114. package/dist/lib/presigned-url.js +90 -0
  115. package/dist/lib/prompt.js +36 -2
  116. package/dist/lib/proxy.js +2 -1
  117. package/dist/lib/redact.d.ts +2 -2
  118. package/dist/lib/redact.js +3 -4
  119. package/dist/lib/removed-commands.d.ts +18 -0
  120. package/dist/lib/removed-commands.js +154 -0
  121. package/dist/lib/render-error.d.ts +31 -6
  122. package/dist/lib/render-error.js +88 -25
  123. package/dist/lib/response-schemas.d.ts +38 -30
  124. package/dist/lib/response-schemas.js +210 -207
  125. package/dist/lib/result/api.d.ts +24 -0
  126. package/dist/lib/result/api.js +28 -0
  127. package/dist/lib/result/evidence.d.ts +71 -0
  128. package/dist/lib/result/evidence.js +420 -0
  129. package/dist/lib/result/render.d.ts +20 -0
  130. package/dist/lib/result/render.js +194 -0
  131. package/dist/lib/result/types.d.ts +122 -0
  132. package/dist/lib/result/types.js +19 -0
  133. package/dist/lib/run-output.d.ts +275 -0
  134. package/dist/lib/run-output.js +227 -0
  135. package/dist/lib/run-render.d.ts +101 -0
  136. package/dist/lib/run-render.js +183 -0
  137. package/dist/lib/run-wait.d.ts +192 -0
  138. package/dist/lib/run-wait.js +452 -0
  139. package/dist/lib/runs.types.d.ts +134 -367
  140. package/dist/lib/runs.types.js +0 -14
  141. package/dist/lib/secret-file.d.ts +1 -1
  142. package/dist/lib/secret-file.js +11 -2
  143. package/dist/lib/skill-nudge.d.ts +7 -27
  144. package/dist/lib/skill-nudge.js +9 -37
  145. package/dist/lib/target-path.d.ts +15 -0
  146. package/dist/lib/target-path.js +35 -0
  147. package/dist/lib/target-url-advisory.d.ts +19 -0
  148. package/dist/lib/target-url-advisory.js +31 -0
  149. package/dist/lib/target-url-preflight.d.ts +9 -0
  150. package/dist/lib/target-url-preflight.js +214 -106
  151. package/dist/lib/target-url.d.ts +1 -1
  152. package/dist/lib/target-url.js +6 -16
  153. package/dist/lib/telemetry.d.ts +32 -12
  154. package/dist/lib/telemetry.js +39 -8
  155. package/dist/lib/terminal-text.d.ts +41 -0
  156. package/dist/lib/terminal-text.js +127 -0
  157. package/dist/lib/testlist.types.d.ts +16 -8
  158. package/dist/lib/testlist.types.js +1 -1
  159. package/dist/lib/text-equality.d.ts +2 -0
  160. package/dist/lib/text-equality.js +5 -0
  161. package/dist/lib/text-file.d.ts +16 -0
  162. package/dist/lib/text-file.js +41 -0
  163. package/dist/lib/text-table.d.ts +46 -0
  164. package/dist/lib/text-table.js +72 -4
  165. package/dist/lib/ticker.d.ts +9 -2
  166. package/dist/lib/ticker.js +16 -3
  167. package/dist/lib/transport-failure.d.ts +22 -0
  168. package/dist/lib/transport-failure.js +126 -0
  169. package/dist/lib/tunnel-session.d.ts +7 -1
  170. package/dist/lib/tunnel-session.js +22 -9
  171. package/dist/lib/update-check.js +3 -2
  172. package/dist/lib/url-template.d.ts +43 -0
  173. package/dist/lib/url-template.js +151 -0
  174. package/dist/lib/validate.d.ts +0 -64
  175. package/dist/lib/validate.js +2 -131
  176. package/dist/lib/version-notice.js +4 -3
  177. package/dist/lib/wait-exit.d.ts +37 -2
  178. package/dist/lib/wait-exit.js +88 -30
  179. package/dist/lib/workspace-status.js +10 -2
  180. package/dist/version.d.ts +1 -1
  181. package/dist/version.js +1 -1
  182. package/package.json +3 -4
  183. package/skills/testsprite-ci.skill.md +48 -18
  184. package/skills/testsprite-onboard.skill.md +66 -151
  185. package/skills/testsprite-verify.codex.md +54 -56
  186. package/skills/testsprite-verify.skill.md +194 -358
  187. package/dist/lib/browser.d.ts +0 -6
  188. package/dist/lib/browser.js +0 -54
  189. package/dist/lib/bundle.d.ts +0 -234
  190. package/dist/lib/bundle.js +0 -781
  191. package/dist/lib/deprecate.d.ts +0 -10
  192. package/dist/lib/deprecate.js +0 -13
  193. package/dist/lib/flaky.d.ts +0 -91
  194. package/dist/lib/flaky.js +0 -71
  195. package/dist/lib/plan-poll.d.ts +0 -171
  196. package/dist/lib/plan-poll.js +0 -441
  197. package/dist/lib/plans.types.d.ts +0 -130
  198. package/dist/lib/plans.types.js +0 -31
  199. package/dist/lib/poll.d.ts +0 -100
  200. package/dist/lib/poll.js +0 -290
  201. package/dist/lib/rate-throttle.d.ts +0 -49
  202. package/dist/lib/rate-throttle.js +0 -75
  203. package/dist/lib/run-progress.d.ts +0 -41
  204. package/dist/lib/run-progress.js +0 -56
  205. package/dist/lib/v3-advisory.d.ts +0 -55
  206. package/dist/lib/v3-advisory.js +0 -74
  207. package/schemas/plan.schema.json +0 -61
@@ -0,0 +1,24 @@
1
+ import { type ConversationApi } from './api.js';
2
+ import type { Conversation, ConversationEvent } from './types.js';
3
+ export interface FollowOptions {
4
+ afterSeq: number;
5
+ /** Stop following after this long and report the agent still working; null follows until it stops. */
6
+ timeoutMs: number | null;
7
+ onEvent: (event: ConversationEvent) => void;
8
+ signal?: AbortSignal;
9
+ now?: () => number;
10
+ sleep?: (ms: number) => Promise<void>;
11
+ }
12
+ export interface FollowResult {
13
+ conversation: Conversation;
14
+ /** Every event seen while following, oldest first. */
15
+ events: ConversationEvent[];
16
+ /** The deadline passed while the agent was still working. */
17
+ timedOut: boolean;
18
+ }
19
+ /**
20
+ * Follow a conversation until the agent needs someone: it proposed something,
21
+ * replied, stopped, or the conversation ended. Each request is held by the
22
+ * server until something happens, so progress shows as it comes.
23
+ */
24
+ export declare function followConversation(api: ConversationApi, projectId: string, id: string, options: FollowOptions): Promise<FollowResult>;
@@ -0,0 +1,42 @@
1
+ import { MAX_WAIT_SECONDS } from './api.js';
2
+ /** How long to pause when the server answers at once with nothing new, so a busy agent isn't polled hot. */
3
+ const IDLE_POLL_MS = 1_000;
4
+ /**
5
+ * Follow a conversation until the agent needs someone: it proposed something,
6
+ * replied, stopped, or the conversation ended. Each request is held by the
7
+ * server until something happens, so progress shows as it comes.
8
+ */
9
+ export async function followConversation(api, projectId, id, options) {
10
+ const now = options.now ?? Date.now;
11
+ const sleep = options.sleep ?? defaultSleep;
12
+ const deadline = options.timeoutMs === null ? null : now() + options.timeoutMs;
13
+ const events = [];
14
+ let afterSeq = options.afterSeq;
15
+ for (;;) {
16
+ const left = deadline === null ? Infinity : deadline - now();
17
+ const waitSeconds = Math.max(0, Math.min(MAX_WAIT_SECONDS, Math.floor(left / 1000)));
18
+ const started = now();
19
+ const conversation = await api.get(projectId, id, {
20
+ afterSeq,
21
+ waitSeconds,
22
+ signal: options.signal,
23
+ });
24
+ for (const event of conversation.events) {
25
+ events.push(event);
26
+ options.onEvent(event);
27
+ }
28
+ afterSeq = conversation.lastSeq;
29
+ if (conversation.state !== 'working')
30
+ return { conversation, events, timedOut: false };
31
+ if (deadline !== null && now() >= deadline)
32
+ return { conversation, events, timedOut: true };
33
+ const answeredAtOnce = now() - started < IDLE_POLL_MS;
34
+ if (conversation.events.length === 0 && answeredAtOnce) {
35
+ await sleep(Math.min(IDLE_POLL_MS, deadline === null ? IDLE_POLL_MS : deadline - now()));
36
+ }
37
+ }
38
+ }
39
+ function defaultSleep(ms) {
40
+ return new Promise(resolve => setTimeout(resolve, Math.max(0, ms)));
41
+ }
42
+ //# sourceMappingURL=follow.js.map
@@ -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