screw-bugs 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +906 -2
- package/bin/screw-bugs.js +29 -0
- package/dist/browser-playwright/annotate.d.ts +9 -0
- package/dist/browser-playwright/annotate.js +86 -0
- package/dist/browser-playwright/capture.d.ts +232 -0
- package/dist/browser-playwright/capture.js +1049 -0
- package/dist/browser-playwright/frames.d.ts +77 -0
- package/dist/browser-playwright/frames.js +191 -0
- package/dist/browser-playwright/index.d.ts +2 -0
- package/dist/browser-playwright/index.js +2 -0
- package/dist/browser-playwright/input.d.ts +44 -0
- package/dist/browser-playwright/input.js +116 -0
- package/dist/browser-playwright/launch.d.ts +21 -0
- package/dist/browser-playwright/launch.js +86 -0
- package/dist/browser-playwright/page.d.ts +387 -0
- package/dist/browser-playwright/page.js +1930 -0
- package/dist/build-info.json +5 -0
- package/dist/cli/app.d.ts +19 -0
- package/dist/cli/app.js +70 -0
- package/dist/cli/build-info.d.ts +52 -0
- package/dist/cli/build-info.js +82 -0
- package/dist/cli/commands.d.ts +14 -0
- package/dist/cli/commands.js +308 -0
- package/dist/cli/config.d.ts +16 -0
- package/dist/cli/config.js +71 -0
- package/dist/cli/doctor.d.ts +19 -0
- package/dist/cli/doctor.js +113 -0
- package/dist/cli/environment.d.ts +20 -0
- package/dist/cli/environment.js +34 -0
- package/dist/cli/exit-codes.d.ts +29 -0
- package/dist/cli/exit-codes.js +28 -0
- package/dist/cli/failure.d.ts +20 -0
- package/dist/cli/failure.js +15 -0
- package/dist/cli/index.d.ts +6 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli/install-method.d.ts +96 -0
- package/dist/cli/install-method.js +148 -0
- package/dist/cli/main.d.ts +1 -0
- package/dist/cli/main.js +10 -0
- package/dist/cli/mcp.d.ts +30 -0
- package/dist/cli/mcp.js +309 -0
- package/dist/cli/node-version.d.ts +3 -0
- package/dist/cli/node-version.js +22 -0
- package/dist/cli/operations.d.ts +127 -0
- package/dist/cli/operations.js +337 -0
- package/dist/cli/package-info.d.ts +22 -0
- package/dist/cli/package-info.js +25 -0
- package/dist/cli/report-server.d.ts +170 -0
- package/dist/cli/report-server.js +387 -0
- package/dist/cli/signals.d.ts +37 -0
- package/dist/cli/signals.js +61 -0
- package/dist/cli/stamp-build.d.ts +1 -0
- package/dist/cli/stamp-build.js +9 -0
- package/dist/cli/update-check.d.ts +140 -0
- package/dist/cli/update-check.js +316 -0
- package/dist/cli/uploads.d.ts +16 -0
- package/dist/cli/uploads.js +80 -0
- package/dist/core/css.d.ts +95 -0
- package/dist/core/css.js +436 -0
- package/dist/core/engine.d.ts +65 -0
- package/dist/core/engine.js +436 -0
- package/dist/core/errors.d.ts +66 -0
- package/dist/core/errors.js +30 -0
- package/dist/core/evidence.d.ts +14 -0
- package/dist/core/evidence.js +127 -0
- package/dist/core/index.d.ts +12 -0
- package/dist/core/index.js +12 -0
- package/dist/core/labels.d.ts +47 -0
- package/dist/core/labels.js +199 -0
- package/dist/core/liveness.d.ts +45 -0
- package/dist/core/liveness.js +64 -0
- package/dist/core/marks.d.ts +63 -0
- package/dist/core/marks.js +410 -0
- package/dist/core/services.d.ts +444 -0
- package/dist/core/services.js +22 -0
- package/dist/core/steps.d.ts +96 -0
- package/dist/core/steps.js +656 -0
- package/dist/core/uploads.d.ts +49 -0
- package/dist/core/uploads.js +133 -0
- package/dist/core/video.d.ts +16 -0
- package/dist/core/video.js +101 -0
- package/dist/core/viewport.d.ts +28 -0
- package/dist/core/viewport.js +50 -0
- package/dist/report/html.d.ts +37 -0
- package/dist/report/html.js +762 -0
- package/dist/report/index.d.ts +5 -0
- package/dist/report/index.js +5 -0
- package/dist/report/markup.d.ts +27 -0
- package/dist/report/markup.js +75 -0
- package/dist/report/pr-summary.d.ts +11 -0
- package/dist/report/pr-summary.js +110 -0
- package/dist/report/sha256.d.ts +9 -0
- package/dist/report/sha256.js +97 -0
- package/dist/report/styles.d.ts +1 -0
- package/dist/report/styles.js +328 -0
- package/dist/report/view.d.ts +141 -0
- package/dist/report/view.js +368 -0
- package/dist/report/walkthrough.d.ts +75 -0
- package/dist/report/walkthrough.js +458 -0
- package/dist/schema/config.d.ts +7 -0
- package/dist/schema/config.js +6 -0
- package/dist/schema/doctor.d.ts +46 -0
- package/dist/schema/doctor.js +23 -0
- package/dist/schema/evidence.d.ts +994 -0
- package/dist/schema/evidence.js +521 -0
- package/dist/schema/findings.d.ts +159 -0
- package/dist/schema/findings.js +80 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/index.js +7 -0
- package/dist/schema/job.d.ts +1724 -0
- package/dist/schema/job.js +505 -0
- package/dist/schema/ledger.d.ts +951 -0
- package/dist/schema/ledger.js +193 -0
- package/dist/schema/status.d.ts +7 -0
- package/dist/schema/status.js +11 -0
- package/dist/store-local/accounts.d.ts +7 -0
- package/dist/store-local/accounts.js +9 -0
- package/dist/store-local/index.d.ts +3 -0
- package/dist/store-local/index.js +3 -0
- package/dist/store-local/paths.d.ts +10 -0
- package/dist/store-local/paths.js +17 -0
- package/dist/store-local/storage.d.ts +20 -0
- package/dist/store-local/storage.js +170 -0
- package/package.json +73 -4
package/dist/cli/mcp.js
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
3
|
+
import { Effect, Option, Path, Schema } from 'effect';
|
|
4
|
+
import { LEDGER_FILE } from '../store-local/index.js';
|
|
5
|
+
import { CaseSpec, Device, Findings, REASON_MAX, } from '../schema/index.js';
|
|
6
|
+
import { MAX_WAIT_SECONDS, Operations } from './operations.js';
|
|
7
|
+
import { PackageInfo } from './package-info.js';
|
|
8
|
+
import { ReportServer } from './report-server.js';
|
|
9
|
+
import { UpdateCheck } from './update-check.js';
|
|
10
|
+
/*
|
|
11
|
+
* Replies are one or two plain sentences plus file paths. Never page snapshots, DOM or logs: the
|
|
12
|
+
* caller is a coding agent with a limited context window, and the details live in the run folder.
|
|
13
|
+
* Two exceptions. run_status for an ended run gives a compact evidence pack: per case its status
|
|
14
|
+
* and reason, screenshot IDs, timecodes and a few page facts (see `formatEvidence`), capped and
|
|
15
|
+
* one line per field; the full pack is evidence.json. start_run whose upload files are missing or
|
|
16
|
+
* unusable starts nothing and lists the files needed, one line each (`formatFilesNeeded`), then
|
|
17
|
+
* one sentence asking the agent to create them, then the project folder.
|
|
18
|
+
* Wherever a report path is given, its http://127.0.0.1 URL follows on the next line (see
|
|
19
|
+
* `ReportServer`), for browsers built into coding tools, which cannot open file:// pages; then the
|
|
20
|
+
* run's walkthrough (`walkthrough.html`), when it has one, and its URL, the same way.
|
|
21
|
+
*/
|
|
22
|
+
const input = (schema) => Schema.toStandardJSONSchemaV1(Schema.toStandardSchemaV1(schema));
|
|
23
|
+
const reply = (text, paths = []) => ({
|
|
24
|
+
content: [{ type: 'text', text: [text, ...paths].join('\n') }],
|
|
25
|
+
});
|
|
26
|
+
const replyFailure = (failure) => ({
|
|
27
|
+
...reply(failure.message, failure.paths),
|
|
28
|
+
isError: true,
|
|
29
|
+
});
|
|
30
|
+
const trimPeriod = (text) => text.replace(/\.$/, '');
|
|
31
|
+
const fixesOf = (checks) => checks
|
|
32
|
+
.flatMap((c) => (c.fix ? [c.fix] : []))
|
|
33
|
+
.map((f) => `${f.command ? `run \`${f.command}\`` : trimPeriod(f.action)} (${trimPeriod(f.why)})`)
|
|
34
|
+
.join('; ');
|
|
35
|
+
const problemsOf = (checks) => checks.map((c) => trimPeriod(c.detail)).join('; ');
|
|
36
|
+
export const formatDoctor = (report) => {
|
|
37
|
+
const failing = report.checks.filter((c) => !c.ok);
|
|
38
|
+
if (!report.ok)
|
|
39
|
+
return `Not ready: ${problemsOf(failing)}. To fix: ${fixesOf(failing)}.`;
|
|
40
|
+
const ready = `Ready: ${report.checks
|
|
41
|
+
.filter((c) => c.ok)
|
|
42
|
+
.map((c) => c.detail)
|
|
43
|
+
.join(', ')}.`;
|
|
44
|
+
// Only warnings are left: say what is missing and how to fix it, in one more sentence.
|
|
45
|
+
return failing.length === 0
|
|
46
|
+
? ready
|
|
47
|
+
: `${ready} Warning: ${problemsOf(failing)}; to fix, ${fixesOf(failing)}.`;
|
|
48
|
+
};
|
|
49
|
+
export const formatLedger = (ledger) => {
|
|
50
|
+
const count = (status) => ledger.cases.filter((c) => c.status === status).length;
|
|
51
|
+
return (`Job ${ledger.jobId} is ${ledger.state.replaceAll('_', ' ')}: ${count('passed')} passed, ` +
|
|
52
|
+
`${count('failed')} failed, ${count('blocked')} blocked, ${count('not_verified')} not verified.`);
|
|
53
|
+
};
|
|
54
|
+
/** A run counts as passed only when it finished and every case passed. */
|
|
55
|
+
export const allPassed = (ledger) => ledger.state === 'finished' && ledger.cases.every((c) => c.status === 'passed');
|
|
56
|
+
/** A status reply lists at most this many cases, those that did not pass first; the rest are counted. */
|
|
57
|
+
export const LISTED_CASES = 10;
|
|
58
|
+
/** Screenshot IDs and timecodes listed per case; evidence.json has them all. */
|
|
59
|
+
export const SHOTS_LISTED = 8;
|
|
60
|
+
export const TIMECODES_LISTED = 12;
|
|
61
|
+
/** Free text on one line, cut to `max` characters. */
|
|
62
|
+
const oneLine = (text, max) => {
|
|
63
|
+
const flat = text.replace(/\s+/g, ' ').trim();
|
|
64
|
+
return flat.length <= max ? flat : `${flat.slice(0, max - 1).trimEnd()}…`;
|
|
65
|
+
};
|
|
66
|
+
const capped = (values, max) => values.length > max
|
|
67
|
+
? `${values.slice(0, max).join(' ')} +${values.length - max}`
|
|
68
|
+
: values.join(' ');
|
|
69
|
+
const isOver = (ledger) => ledger.state === 'finished' || ledger.state === 'errored';
|
|
70
|
+
/** The first line of a listed case: `- <id> (<status>): <reason>`. */
|
|
71
|
+
const caseLine = (c) => `- ${c.id} (${c.status.replace('_', ' ')})` +
|
|
72
|
+
(c.status !== 'passed' && c.reason?.trim() ? `: ${oneLine(c.reason, REASON_MAX)}` : '');
|
|
73
|
+
/**
|
|
74
|
+
* The second line of a listed case: what an agent needs to write it up and the IDs its findings
|
|
75
|
+
* may use. Short fields, each capped: the deciding step and when, screenshot IDs, timecodes (ms
|
|
76
|
+
* into the session video), where the page was, HTTP errors and (for a case that did not pass)
|
|
77
|
+
* visible text near where it stopped and the start of the first visible frame's text, and how
|
|
78
|
+
* many images and links the page showed (evidence.json lists them).
|
|
79
|
+
*/
|
|
80
|
+
const detailLine = (c) => {
|
|
81
|
+
const decided = c.steps.find((s) => s.state === 'decided');
|
|
82
|
+
const facts = c.facts;
|
|
83
|
+
const fields = [
|
|
84
|
+
decided?.startMs !== undefined ? `step ${decided.index} at ${decided.startMs} ms` : undefined,
|
|
85
|
+
c.shots.length > 0
|
|
86
|
+
? `shots ${capped(c.shots.map((s) => s.id), SHOTS_LISTED)}`
|
|
87
|
+
: undefined,
|
|
88
|
+
c.timecodes.length > 0 ? `timecodes ${capped(c.timecodes, TIMECODES_LISTED)}` : undefined,
|
|
89
|
+
facts ? `url ${oneLine(facts.url, 100)}` : undefined,
|
|
90
|
+
facts && facts.httpErrors.length > 0
|
|
91
|
+
? `http ${facts.httpErrors
|
|
92
|
+
.slice(0, 2)
|
|
93
|
+
.map((e) => `${e.status} ${oneLine(e.url, 60)}`)
|
|
94
|
+
.join(', ')}`
|
|
95
|
+
: undefined,
|
|
96
|
+
facts?.text && c.status !== 'passed' ? `text "${oneLine(facts.text, 100)}"` : undefined,
|
|
97
|
+
facts?.frames?.[0]?.text && c.status !== 'passed'
|
|
98
|
+
? `frame "${oneLine(facts.frames[0].text, 100)}"`
|
|
99
|
+
: undefined,
|
|
100
|
+
facts?.images !== undefined || facts?.links !== undefined
|
|
101
|
+
? `${facts.images?.length ?? 0} images, ${facts.links?.length ?? 0} links in evidence.json`
|
|
102
|
+
: undefined,
|
|
103
|
+
].filter((field) => field !== undefined);
|
|
104
|
+
return fields.length > 0 ? ` ${fields.join('; ')}` : undefined;
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* After the counts of an ended run, the compact evidence pack: two lines per case (cases that did
|
|
108
|
+
* not pass first), at most `LISTED_CASES`, then how many more there are, and a line for a video
|
|
109
|
+
* that is missing or incomplete.
|
|
110
|
+
*/
|
|
111
|
+
export const formatEvidence = (ledger, pack) => {
|
|
112
|
+
if (!isOver(ledger))
|
|
113
|
+
return [];
|
|
114
|
+
const ordered = [
|
|
115
|
+
...pack.cases.filter((c) => c.status !== 'passed'),
|
|
116
|
+
...pack.cases.filter((c) => c.status === 'passed'),
|
|
117
|
+
];
|
|
118
|
+
const lines = ordered
|
|
119
|
+
.slice(0, LISTED_CASES)
|
|
120
|
+
.flatMap((c) => [caseLine(c), detailLine(c)])
|
|
121
|
+
.filter((line) => line !== undefined);
|
|
122
|
+
const more = ordered.length - LISTED_CASES;
|
|
123
|
+
const videos = pack.videos.flatMap((v) => v.problem ? [`Video missing or incomplete: ${oneLine(v.problem, REASON_MAX)}`] : []);
|
|
124
|
+
return [...lines, ...(more > 0 ? [`- and ${more} more; see evidence.json.`] : []), ...videos];
|
|
125
|
+
};
|
|
126
|
+
/** One line per case that did not pass, for a run without an evidence pack. */
|
|
127
|
+
export const formatNotPassing = (ledger) => {
|
|
128
|
+
if (!isOver(ledger))
|
|
129
|
+
return [];
|
|
130
|
+
const notPassing = ledger.cases.filter((c) => c.status !== 'passed');
|
|
131
|
+
const lines = notPassing.slice(0, LISTED_CASES).map(caseLine);
|
|
132
|
+
const more = notPassing.length - LISTED_CASES;
|
|
133
|
+
return more > 0 ? [...lines, `- and ${more} more; see ledger.json.`] : lines;
|
|
134
|
+
};
|
|
135
|
+
/** A status reply: the counts, then the evidence pack (see `formatEvidence`). */
|
|
136
|
+
export const formatStatus = (ledger, pack) => [formatLedger(ledger), ...(pack ? formatEvidence(ledger, pack) : formatNotPassing(ledger))].join('\n');
|
|
137
|
+
/** Highlights that could not be drawn, for the agent to name better and submit again. */
|
|
138
|
+
const unplacedLine = (marks) => {
|
|
139
|
+
const all = Object.entries(marks).flatMap(([shot, placed]) => placed.map((mark) => ({ shot, mark })));
|
|
140
|
+
const missed = all.filter(({ mark }) => mark.box === undefined);
|
|
141
|
+
if (missed.length === 0)
|
|
142
|
+
return undefined;
|
|
143
|
+
const listed = missed
|
|
144
|
+
.slice(0, 3)
|
|
145
|
+
.map(({ shot, mark }) => `${shot} ${mark.target}: ${mark.problem ?? 'not found'}`)
|
|
146
|
+
.join('; ');
|
|
147
|
+
return (`${missed.length} of ${all.length} highlights could not be drawn (${oneLine(listed, 300)}` +
|
|
148
|
+
`${missed.length > 3 ? '; …' : ''}); the report says so in words.`);
|
|
149
|
+
};
|
|
150
|
+
/** The reply to saved findings: one sentence, maybe one about highlights, then the paths. */
|
|
151
|
+
export const formatFindings = (result) => [
|
|
152
|
+
`Findings saved for job ${result.jobId}; ${result.reportPath ? 'the report now shows them.' : 'the report shows them once it is written.'}`,
|
|
153
|
+
unplacedLine(result.marks),
|
|
154
|
+
]
|
|
155
|
+
.filter((line) => line !== undefined)
|
|
156
|
+
.join('\n');
|
|
157
|
+
const StartRunInput = Schema.Struct({
|
|
158
|
+
url: Schema.NonEmptyString.annotate({
|
|
159
|
+
description: 'http or https URL of the app to test; relative goto URLs resolve against it.',
|
|
160
|
+
}),
|
|
161
|
+
summary: Schema.String.annotate({
|
|
162
|
+
description: 'Your high-level summary of what these cases test and why, for a human reader; not steps. ' +
|
|
163
|
+
'Example: "New users can sign up, and a taken email gets a clear error."',
|
|
164
|
+
}).check(Schema.makeFilter((text) => (text.trim() ? undefined : 'Must not be blank'))),
|
|
165
|
+
instructions: Schema.optionalKey(Schema.String.annotate({
|
|
166
|
+
description: "The user's request in their own words; pass it verbatim if there was one. " +
|
|
167
|
+
'Example: "make sure signup still works after my refactor".',
|
|
168
|
+
})),
|
|
169
|
+
cases: Schema.optionalKey(Schema.Array(CaseSpec).annotate({
|
|
170
|
+
description: 'Cases to run in order, one after another in one browser session (cookies and storage ' +
|
|
171
|
+
'carry over), recorded as one video. Give each a "success" sentence saying what success ' +
|
|
172
|
+
'looks like. Every case starts at the job URL (or its first goto), unless it has ' +
|
|
173
|
+
'"continue":true: then it starts on the page the case before it ended on, such as a page ' +
|
|
174
|
+
'an earlier case generated, so each check can be a case of its own (not on the first case). ' +
|
|
175
|
+
'Omit for one "page loads" case ' +
|
|
176
|
+
'(loads the URL, passes without an HTTP error, takes a screenshot). Step examples: ' +
|
|
177
|
+
'{"action":"goto","url":"/login"}, ' +
|
|
178
|
+
'{"action":"fill","target":{"label":"Email"},"value":"a@b.co"}, ' +
|
|
179
|
+
'{"action":"click","target":{"role":"button","name":"Sign in"}}, ' +
|
|
180
|
+
'{"action":"press","key":"Enter"}, {"action":"expectText","text":"Welcome"}, ' +
|
|
181
|
+
'{"action":"expectNoText","text":"Acme"} (passes when it does not show as text, image ' +
|
|
182
|
+
'alt text or ARIA label, in the page and its frames, or with frame or target only there), ' +
|
|
183
|
+
'{"action":"expectUrl","includes":"/dashboard"}, {"action":"screenshot","name":"home"}, ' +
|
|
184
|
+
'{"action":"reload"}, ' +
|
|
185
|
+
'{"action":"upload","target":{"role":"button","name":"Upload"},"files":[{"path":"fixtures/resume.pdf","about":"A 2-page PDF résumé of a fictional designer"}]}, ' +
|
|
186
|
+
'{"action":"waitFor","target":{"css":".restyling"},"state":"detached"} (state visible, ' +
|
|
187
|
+
'hidden, attached or detached; default visible), ' +
|
|
188
|
+
'{"action":"scroll","to":"bottom"} (exactly one of target, to "top"/"bottom", or by ' +
|
|
189
|
+
'pixels; then a screenshot of what is in view), ' +
|
|
190
|
+
'{"action":"expectLink","target":{"role":"link","name":"LinkedIn"},"href":"linkedin.com/in/"} ' +
|
|
191
|
+
'(match contains, the default, or exact; the link is not followed). Targets: role (with ' +
|
|
192
|
+
'name), text, label, alt (an image\'s alt text, such as {"alt":"Acme logo"}) or css. ' +
|
|
193
|
+
'Inside an <iframe>, give the frame like a target: ' +
|
|
194
|
+
'{"action":"click","target":{"frame":{"css":"iframe.preview"},"text":"Contact"}}, ' +
|
|
195
|
+
'{"action":"expectText","frame":{"css":"iframe.preview"},"text":"Hi, I\'m Nadia"}, ' +
|
|
196
|
+
'{"action":"scroll","frame":{"css":"iframe.preview"},"by":800}; frames inside frames ' +
|
|
197
|
+
'as a list, outermost first. ' +
|
|
198
|
+
'Steps that wait (all but screenshot) take ' +
|
|
199
|
+
'timeoutMs (100-180000; default 5000 for elements and text, 15000 for page loads), such as ' +
|
|
200
|
+
'{"action":"expectText","text":"Your portfolio is ready","timeoutMs":120000} for slow work. ' +
|
|
201
|
+
'Upload paths are relative to the project this server runs in; you create those files ' +
|
|
202
|
+
'yourself (such as in fixtures/), with synthetic content and no real personal data, and ' +
|
|
203
|
+
'they are sent to the site under test. Each must match its extension (a real PDF for ' +
|
|
204
|
+
'.pdf); to test an invalid file on purpose, give {"path":"fixtures/fake.pdf",' +
|
|
205
|
+
'"allowMismatch":true}. ' +
|
|
206
|
+
'A case is failed when an expectation does not hold, blocked when a step cannot run. ' +
|
|
207
|
+
'Expectations must prove the behavior: assert what only shows when it worked (or failed), ' +
|
|
208
|
+
'such as the exact success or error message or a URL change, never text that is always ' +
|
|
209
|
+
'on the page. Good, after clicking "Create account": ' +
|
|
210
|
+
'{"action":"expectText","text":"Welcome, Ada! Your account is ready."}. ' +
|
|
211
|
+
'Bad: {"action":"expectText","text":"Email"} (a field label, there before and after).',
|
|
212
|
+
})),
|
|
213
|
+
device: Schema.optionalKey(Device),
|
|
214
|
+
});
|
|
215
|
+
const RunStatusInput = Schema.Struct({
|
|
216
|
+
jobId: Schema.NonEmptyString,
|
|
217
|
+
waitSeconds: Schema.optionalKey(Schema.Int.check(Schema.isBetween({ minimum: 0, maximum: MAX_WAIT_SECONDS })).annotate({
|
|
218
|
+
description: `0-${MAX_WAIT_SECONDS}, default 0. If the run is still queued or running, wait up to this ` +
|
|
219
|
+
'many seconds for it to end before replying, instead of polling run_status yourself.',
|
|
220
|
+
})),
|
|
221
|
+
});
|
|
222
|
+
const SubmitFindingsInput = Schema.Struct({
|
|
223
|
+
jobId: Schema.NonEmptyString,
|
|
224
|
+
findings: Findings.annotate({
|
|
225
|
+
description: 'Your write-up, from run_status: a one-sentence headline, fixes (most important first, by ' +
|
|
226
|
+
'case ID), per case what you did, what worked and what did not, highlights (an element on ' +
|
|
227
|
+
'one of its screenshot IDs, named like a step target, red for a problem, green for as ' +
|
|
228
|
+
'expected) and key moments (its timecodes), what you did not test and why (notTested: ' +
|
|
229
|
+
'what and why; a passing run covers only what its cases did), and next tests. Short ' +
|
|
230
|
+
'texts and capped lists; see the field limits. Use only IDs and timecodes ' +
|
|
231
|
+
'from run_status. Statuses are decided by the run; you cannot change them.',
|
|
232
|
+
}),
|
|
233
|
+
});
|
|
234
|
+
const AnswerQuestionInput = Schema.Struct({
|
|
235
|
+
jobId: Schema.NonEmptyString,
|
|
236
|
+
questionId: Schema.NonEmptyString,
|
|
237
|
+
answer: Schema.String,
|
|
238
|
+
});
|
|
239
|
+
/** The MCP server: exactly five tools, each a thin call into `Operations`. */
|
|
240
|
+
export const makeMcpServer = Effect.gen(function* () {
|
|
241
|
+
const ops = yield* Operations;
|
|
242
|
+
const path = yield* Path.Path;
|
|
243
|
+
const { name, version } = yield* PackageInfo;
|
|
244
|
+
const reportServer = yield* Effect.serviceOption(ReportServer);
|
|
245
|
+
const updateCheck = yield* Effect.serviceOption(UpdateCheck);
|
|
246
|
+
// Sent once, when a session connects: only a newer version already known from the cache.
|
|
247
|
+
const instructions = Option.isSome(updateCheck) ? yield* updateCheck.value.notice : undefined;
|
|
248
|
+
/** A page's path, then its URL on the local report server (for in-tool browsers). */
|
|
249
|
+
const pageLinks = (file) => file === undefined
|
|
250
|
+
? Effect.succeed([])
|
|
251
|
+
: Option.match(reportServer, {
|
|
252
|
+
onNone: () => Effect.succeed([file]),
|
|
253
|
+
onSome: (server) => server.urlOf(file).pipe(Effect.map((url) => (url ? [file, url] : [file]))),
|
|
254
|
+
});
|
|
255
|
+
/** The report's links, then the walkthrough's. */
|
|
256
|
+
const reportLinks = (paths) => Effect.all([pageLinks(paths.reportPath), pageLinks(paths.walkthroughPath)]).pipe(Effect.map(([report, walkthrough]) => [...report, ...walkthrough]));
|
|
257
|
+
// Boundary: the MCP SDK calls tools through promises. Each call runs with the services this
|
|
258
|
+
// server was made with (clock, config, logger), not a fresh default runtime.
|
|
259
|
+
const runPromise = Effect.runPromiseWith(yield* Effect.context());
|
|
260
|
+
const run = (effect, onSuccess) => runPromise(effect.pipe(Effect.match({ onFailure: replyFailure, onSuccess })));
|
|
261
|
+
const server = new McpServer({ name, version }, instructions ? { instructions } : undefined);
|
|
262
|
+
server.registerTool('doctor', {
|
|
263
|
+
description: 'Check this machine can run screw-bugs: Node, a browser, disk space and updates.',
|
|
264
|
+
}, () => run(ops.doctor, (report) => reply(formatDoctor(report))));
|
|
265
|
+
server.registerTool('start_run', {
|
|
266
|
+
description: 'Run your QA cases (structured steps) in a headless browser; returns a job ID immediately. Upload files are yours to create in the project (such as fixtures/), with synthetic content.',
|
|
267
|
+
inputSchema: input(StartRunInput),
|
|
268
|
+
}, (args) => run(ops.startRun({ spec: args }, { requireConfig: false }), ({ jobId, runDir }) => reply(`Started job ${jobId}; check it with run_status.`, [runDir])));
|
|
269
|
+
server.registerTool('run_status', {
|
|
270
|
+
description: 'Get the state and case results of a run by job ID.',
|
|
271
|
+
inputSchema: input(RunStatusInput),
|
|
272
|
+
}, ({ jobId, waitSeconds }) => run(ops
|
|
273
|
+
.runStatus(jobId, { waitSeconds })
|
|
274
|
+
.pipe(Effect.flatMap((status) => reportLinks(status).pipe(Effect.map((report) => ({ ...status, report }))))), ({ ledger, runDir, report, evidence, evidencePath }) => reply(formatStatus(ledger, evidence), [
|
|
275
|
+
runDir,
|
|
276
|
+
path.join(runDir, LEDGER_FILE),
|
|
277
|
+
...(evidencePath ? [evidencePath] : []),
|
|
278
|
+
...evidence.videos.flatMap((v) => v.path !== undefined && isOver(ledger) ? [path.join(runDir, v.path)] : []),
|
|
279
|
+
...report,
|
|
280
|
+
])));
|
|
281
|
+
server.registerTool('submit_findings', {
|
|
282
|
+
description: 'Submit your write-up of an ended run; screw-bugs checks it and re-renders the report.',
|
|
283
|
+
inputSchema: input(SubmitFindingsInput),
|
|
284
|
+
}, ({ jobId, findings }) => run(ops
|
|
285
|
+
.submitFindings(jobId, findings)
|
|
286
|
+
.pipe(Effect.flatMap((result) => reportLinks(result).pipe(Effect.map((report) => ({ result, report }))))), ({ result, report }) => reply(formatFindings(result), [result.path, ...report, ...result.annotated])));
|
|
287
|
+
server.registerTool('answer_question', {
|
|
288
|
+
description: 'Answer a question a waiting run has asked.',
|
|
289
|
+
inputSchema: input(AnswerQuestionInput),
|
|
290
|
+
}, ({ jobId, questionId, answer }) => run(ops.answer({ jobId, questionId, text: answer }), () => reply(`Answer sent; job ${jobId} will continue.`)));
|
|
291
|
+
return server;
|
|
292
|
+
});
|
|
293
|
+
/** Serves MCP over stdio until the client disconnects. Nothing else may write to stdout. */
|
|
294
|
+
export const serveMcp = Effect.gen(function* () {
|
|
295
|
+
const server = yield* makeMcpServer;
|
|
296
|
+
// In the background for as long as the server runs: a check now if one is due, then daily.
|
|
297
|
+
// Not started at all when the check is off or has no cache folder.
|
|
298
|
+
const updateCheck = yield* Effect.serviceOption(UpdateCheck);
|
|
299
|
+
if (Option.isSome(updateCheck) && updateCheck.value.active) {
|
|
300
|
+
yield* Effect.forkChild(updateCheck.value.serverLoop);
|
|
301
|
+
}
|
|
302
|
+
// Boundary: the SDK's connect and close are promises; this waits for the client to hang up,
|
|
303
|
+
// and closes the server when interrupted (Ctrl+C, SIGTERM).
|
|
304
|
+
yield* Effect.callback((resume) => {
|
|
305
|
+
server.server.onclose = () => resume(Effect.void);
|
|
306
|
+
server.connect(new StdioServerTransport()).catch((error) => resume(Effect.die(error)));
|
|
307
|
+
return Effect.promise(() => server.close());
|
|
308
|
+
});
|
|
309
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const parse = (version) => {
|
|
2
|
+
const match = /(\d+)\.(\d+)\.(\d+)/.exec(version);
|
|
3
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : undefined;
|
|
4
|
+
};
|
|
5
|
+
/** The minimum from an `engines.node` range of the form `>=X.Y.Z`. */
|
|
6
|
+
export const minimumNode = (range) => {
|
|
7
|
+
const parsed = parse(range);
|
|
8
|
+
if (!parsed)
|
|
9
|
+
throw new Error(`Unsupported engines.node range: ${range}`);
|
|
10
|
+
return parsed.join('.');
|
|
11
|
+
};
|
|
12
|
+
export const isAtLeast = (current, minimum) => {
|
|
13
|
+
const a = parse(current);
|
|
14
|
+
const b = parse(minimum);
|
|
15
|
+
if (!a || !b)
|
|
16
|
+
return false;
|
|
17
|
+
for (let i = 0; i < 3; i++) {
|
|
18
|
+
if (a[i] !== b[i])
|
|
19
|
+
return a[i] > b[i];
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Context, Effect, FileSystem, Layer, Path } from 'effect';
|
|
2
|
+
import { Browser, Engine, type RunSummary, Storage } from '../core/index.js';
|
|
3
|
+
import { type CaseLedger, type Device, type DoctorReport, type EvidencePack, JobId, type JobRecord, type PlacedMark, type ReportBundle } from '../schema/index.js';
|
|
4
|
+
import { Failure } from './failure.js';
|
|
5
|
+
import { PackageInfo } from './package-info.js';
|
|
6
|
+
/** How often a status call that waits rereads the ledger. */
|
|
7
|
+
export declare const STATUS_POLL_MS = 500;
|
|
8
|
+
/** The longest a status call may wait for a run to end. */
|
|
9
|
+
export declare const MAX_WAIT_SECONDS = 60;
|
|
10
|
+
export interface StartRunInput {
|
|
11
|
+
/** A JobSpec, or part of one, as parsed JSON (from `--spec` or the MCP tool input). */
|
|
12
|
+
readonly spec?: unknown;
|
|
13
|
+
/** Overrides the spec's URL. */
|
|
14
|
+
readonly url?: string | undefined;
|
|
15
|
+
readonly device?: Device | undefined;
|
|
16
|
+
/** Overrides the spec's instructions. */
|
|
17
|
+
readonly instructions?: string | undefined;
|
|
18
|
+
/** Overrides the spec's summary. */
|
|
19
|
+
readonly summary?: string | undefined;
|
|
20
|
+
}
|
|
21
|
+
export interface AnswerInput {
|
|
22
|
+
readonly jobId: string;
|
|
23
|
+
readonly questionId: string;
|
|
24
|
+
readonly text: string;
|
|
25
|
+
}
|
|
26
|
+
export interface InitInput {
|
|
27
|
+
readonly baseUrl?: string | undefined;
|
|
28
|
+
/** Overwrite an existing screw-bugs.json. */
|
|
29
|
+
readonly force: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface FindingsResult {
|
|
32
|
+
readonly jobId: JobId;
|
|
33
|
+
/** Absolute path of `findings.json`. */
|
|
34
|
+
readonly path: string;
|
|
35
|
+
/** The report rewritten with the findings; undefined when the run may not get one yet. */
|
|
36
|
+
readonly reportPath: string | undefined;
|
|
37
|
+
/** The walkthrough rewritten with the report, when it was. */
|
|
38
|
+
readonly walkthroughPath: string | undefined;
|
|
39
|
+
/** Every highlight as placed, by screenshot ID. */
|
|
40
|
+
readonly marks: Readonly<Record<string, ReadonlyArray<PlacedMark>>>;
|
|
41
|
+
/** Absolute paths of the screenshots with the highlights drawn in. */
|
|
42
|
+
readonly annotated: ReadonlyArray<string>;
|
|
43
|
+
}
|
|
44
|
+
export interface RunResult {
|
|
45
|
+
readonly ledger: CaseLedger;
|
|
46
|
+
readonly runDir: string;
|
|
47
|
+
/**
|
|
48
|
+
* Once the run has ended: its `report.html`, or else its `report-interrupted.html` (see
|
|
49
|
+
* `Storage.findReport`), if either was written.
|
|
50
|
+
*/
|
|
51
|
+
readonly reportPath: string | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Once the run has ended: its `walkthrough.html`, if one was written with its `report.html`
|
|
54
|
+
* (never for an interrupted run's report).
|
|
55
|
+
*/
|
|
56
|
+
readonly walkthroughPath: string | undefined;
|
|
57
|
+
}
|
|
58
|
+
declare const Operations_base: Context.ServiceClass<Operations, "screw-bugs/Operations", {
|
|
59
|
+
readonly doctor: Effect.Effect<DoctorReport>;
|
|
60
|
+
readonly init: (input: InitInput) => Effect.Effect<{
|
|
61
|
+
readonly path: string;
|
|
62
|
+
}, Failure>;
|
|
63
|
+
readonly startRun: (input: StartRunInput, options: {
|
|
64
|
+
readonly requireConfig: boolean;
|
|
65
|
+
}) => Effect.Effect<{
|
|
66
|
+
readonly jobId: JobId;
|
|
67
|
+
readonly runDir: string;
|
|
68
|
+
}, Failure>;
|
|
69
|
+
/** Waits for a run started by this process to end. */
|
|
70
|
+
readonly awaitRun: (jobId: JobId) => Effect.Effect<RunResult, Failure>;
|
|
71
|
+
/** Stops a run started by this process and waits for its final report and ledger. */
|
|
72
|
+
readonly stopRun: (jobId: JobId) => Effect.Effect<RunResult, Failure>;
|
|
73
|
+
/**
|
|
74
|
+
* The ledger, plus the job record for what was asked (such as its summary and instructions).
|
|
75
|
+
* With `waitSeconds`, a queued or running run is given up to that long to end first; it works
|
|
76
|
+
* for runs of any process, since it rereads the ledger.
|
|
77
|
+
*/
|
|
78
|
+
readonly runStatus: (jobId: string, options?: {
|
|
79
|
+
readonly waitSeconds?: number | undefined;
|
|
80
|
+
}) => Effect.Effect<RunResult & {
|
|
81
|
+
readonly job: JobRecord;
|
|
82
|
+
/** The evidence pack, built from the job and ledger as they are now. */
|
|
83
|
+
readonly evidence: EvidencePack;
|
|
84
|
+
/** Absolute path of `evidence.json`, once the run wrote it. */
|
|
85
|
+
readonly evidencePath: string | undefined;
|
|
86
|
+
}, Failure>;
|
|
87
|
+
/**
|
|
88
|
+
* (Re)writes a run's report from its ledger as it is now: `report.html` for a run that ended,
|
|
89
|
+
* `report-interrupted.html` for one whose process has been gone for `REPORT_STALE_MS`, and
|
|
90
|
+
* returns the report that takes precedence. Fails for a run still going or gone for less.
|
|
91
|
+
*/
|
|
92
|
+
readonly report: (jobId: string) => Effect.Effect<{
|
|
93
|
+
readonly path: string;
|
|
94
|
+
readonly bundle: ReportBundle;
|
|
95
|
+
/** The walkthrough written with it, when it was the run's own report. */
|
|
96
|
+
readonly walkthroughPath: string | undefined;
|
|
97
|
+
}, Failure>;
|
|
98
|
+
/**
|
|
99
|
+
* (Re)writes a run's report as `report` does, and with it its walkthrough; returns the
|
|
100
|
+
* walkthrough's path. Fails for a run whose report is an interrupted one, which gets none.
|
|
101
|
+
*/
|
|
102
|
+
readonly walkthrough: (jobId: string) => Effect.Effect<{
|
|
103
|
+
readonly path: string;
|
|
104
|
+
readonly reportPath: string;
|
|
105
|
+
}, Failure>;
|
|
106
|
+
readonly listRuns: (limit: number) => Effect.Effect<ReadonlyArray<RunSummary>, Failure>;
|
|
107
|
+
/**
|
|
108
|
+
* Checks an agent's findings (parsed JSON) against an ended run and saves them, draws their
|
|
109
|
+
* highlights onto copies of the screenshots, then rewrites the run's report as `report` does,
|
|
110
|
+
* so it shows them. Invalid findings save nothing and fail with `InvalidFindings`.
|
|
111
|
+
*/
|
|
112
|
+
readonly submitFindings: (jobId: string, findings: unknown) => Effect.Effect<FindingsResult, Failure>;
|
|
113
|
+
readonly answer: (input: AnswerInput) => Effect.Effect<void, Failure>;
|
|
114
|
+
}>;
|
|
115
|
+
/**
|
|
116
|
+
* Everything the CLI and the MCP server can do. Both are thin front ends over these, so the MCP
|
|
117
|
+
* server has no logic of its own.
|
|
118
|
+
*/
|
|
119
|
+
export declare class Operations extends Operations_base {
|
|
120
|
+
static readonly layer: (projectRoot: string) => Layer.Layer<Operations, never, Browser | Engine | FileSystem.FileSystem | PackageInfo | Path.Path | Storage>;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* A Schema error message as one line per problem, in the form `checkFindings` uses:
|
|
124
|
+
* `fixes[0].severity: Expected "high" | "medium" | "low"`.
|
|
125
|
+
*/
|
|
126
|
+
export declare const schemaProblems: (message: string) => ReadonlyArray<string>;
|
|
127
|
+
export {};
|