@firstdraft.com/cli 0.9.0 → 0.11.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/README.md +10 -8
- package/docs/README.md +1 -1
- package/docs/commands.md +659 -132
- package/docs/errors.md +227 -73
- package/package.json +7 -1
- package/src/agent-sentences.js +210 -0
- package/src/api-authentication.js +25 -6
- package/src/api-response.js +110 -6
- package/src/cli.js +3143 -912
- package/src/commands/account.js +97 -0
- package/src/commands/compilation.js +57 -5
- package/src/commands/login.js +246 -42
- package/src/commands/maintain.js +662 -0
- package/src/commands/note.js +204 -0
- package/src/commands/plan-compile.js +44 -77
- package/src/commands/plan-init.js +14 -1
- package/src/commands/plan-push.js +26 -12
- package/src/commands/plan-status.js +1 -1
- package/src/commands/report.js +469 -0
- package/src/commands/sketches.js +388 -0
- package/src/commands/start.js +52 -0
- package/src/compilation-artifact.js +39 -4
- package/src/credentials.js +145 -7
- package/src/oauth.js +33 -25
- package/src/plan-compile-progress.js +8 -81
- package/src/plan-state.js +325 -5
- package/src/root-output.js +13 -1
- package/src/service-client.js +513 -0
- package/src/sketch-capture.js +449 -0
- package/src/commands/plan-publish.js +0 -1146
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { STAGING_API_URL } from "./api-authentication.js";
|
|
2
|
+
|
|
3
|
+
// The plain sentences the CLI prints for an agent, kept here so they are
|
|
4
|
+
// written once. `firstdraft start` and the two steps of the agent's device
|
|
5
|
+
// login print only these, besides the update line every command shares
|
|
6
|
+
// (src/service-client.js), and `firstdraft maintain` prints one of them
|
|
7
|
+
// beside its JSON. A First Draft answer only chooses among them, and
|
|
8
|
+
// the only values they carry are an origin, versions, a token variable's
|
|
9
|
+
// name, and a device login's validated link, user code, and expiry.
|
|
10
|
+
// docs/commands.md quotes them and the Skill copies them, so a change here is
|
|
11
|
+
// a change to both.
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A command the agent can run as printed. A staging origin adds the flag that
|
|
15
|
+
* selects it; a custom origin keeps coming from FIRSTDRAFT_API_URL.
|
|
16
|
+
*
|
|
17
|
+
* @param {string} origin
|
|
18
|
+
* @param {string} command
|
|
19
|
+
*/
|
|
20
|
+
export function commandLine(origin, command) {
|
|
21
|
+
return `'firstdraft ${command}${origin === STAGING_API_URL ? " --staging" : ""}'`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @param {{cli: string, plugin: string | null}} versions */
|
|
25
|
+
export function versionLine({ cli, plugin }) {
|
|
26
|
+
return plugin === null
|
|
27
|
+
? `First Draft CLI ${cli}.`
|
|
28
|
+
: `First Draft CLI ${cli} with plugin ${plugin}.`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether a token for `origin` is saved on this computer or set in the
|
|
33
|
+
* environment, which takes precedence.
|
|
34
|
+
*
|
|
35
|
+
* @param {{origin: string, saved: boolean, environmentVariable: string | null}} login
|
|
36
|
+
*/
|
|
37
|
+
export function loginLines({ origin, saved, environmentVariable }) {
|
|
38
|
+
return [
|
|
39
|
+
saved
|
|
40
|
+
? `This computer has a saved login for ${origin}.`
|
|
41
|
+
: `This computer has no saved login for ${origin}.`,
|
|
42
|
+
...(environmentVariable === null
|
|
43
|
+
? []
|
|
44
|
+
: [
|
|
45
|
+
`${environmentVariable} is set, so the CLI uses that token in place of any saved login for ${origin}, and no login is needed.`,
|
|
46
|
+
]),
|
|
47
|
+
];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** @param {string} origin */
|
|
51
|
+
export function loginSteps(origin) {
|
|
52
|
+
return [
|
|
53
|
+
`To log in, run ${commandLine(origin, "login --no-wait")}. It prints a link and a code: show both to the person and ask them to approve the login in their browser.`,
|
|
54
|
+
`When the person says they approved, run ${commandLine(origin, "login --finish")}, then run ${commandLine(origin, "start")} again.`,
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** @param {string | null} environmentVariable */
|
|
59
|
+
export function readyLine(environmentVariable) {
|
|
60
|
+
return environmentVariable === null
|
|
61
|
+
? "Ready: First Draft accepted this computer's login."
|
|
62
|
+
: `Ready: First Draft accepted ${environmentVariable}.`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {string} origin
|
|
67
|
+
* @param {string | null} environmentVariable
|
|
68
|
+
*/
|
|
69
|
+
export function rejectedLoginLines(origin, environmentVariable) {
|
|
70
|
+
return environmentVariable === null
|
|
71
|
+
? [
|
|
72
|
+
`Not logged in: First Draft did not accept the saved login for ${origin}.`,
|
|
73
|
+
...loginSteps(origin),
|
|
74
|
+
]
|
|
75
|
+
: [
|
|
76
|
+
`Not logged in: First Draft did not accept ${environmentVariable}. Ask the person to replace it or unset it; while it is set, the CLI uses no saved login.`,
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Printed when the person said yes to reports, and only then: the agent of a
|
|
82
|
+
* person who said no hears nothing about reports or notes. One yes covers
|
|
83
|
+
* both, so any command that tells the agent about reports prints these same
|
|
84
|
+
* sentences, followed by NOTES_ON_LINES.
|
|
85
|
+
*/
|
|
86
|
+
export const REPORTS_ON_LINES = Object.freeze([
|
|
87
|
+
"Reports are on: this person agreed that you send First Draft progress and failure reports about the code it generates, and notes about problems with First Draft itself.",
|
|
88
|
+
"Progress: run 'firstdraft report progress --step <step>' when bin/setup finishes (setup), when the first spec run finishes (specs_first_run), when every item under the README's Behavior to write is written (behavior_written), when the specs pass (specs_passing), and when the preview starts (preview_started). Add the counts you have; 'firstdraft report progress --help' lists them.",
|
|
89
|
+
"Failure: when generated code fails in a way the README does not list, run 'firstdraft report failure --kind <kind>' once you have fixed it or stopped trying, where <kind> is setup_failure, spec_failure, boot_error, or lint_failure; 'firstdraft report failure --help' lists the other fields.",
|
|
90
|
+
"Each report names the Compilation that the CLI last recorded for this Project when 'firstdraft plan compile' or 'firstdraft compilation download' wrote its code; to name a different one, put its compilation.id right after 'report progress' or 'report failure'.",
|
|
91
|
+
"Run each report and note command from the generated application's root, or from the Project's directory before the code is written or after --output. Each prints what it sends: pass only text that may leave this computer, never secrets or the person's data.",
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
/** The notes half of what REPORTS_ON_LINES introduces, printed right after it. */
|
|
95
|
+
export const NOTES_ON_LINES = Object.freeze([
|
|
96
|
+
"Notes: send a note only when a problem with First Draft cost you a real detour and is likely to happen again, never for routine debugging, and only after the Plan has been pushed once with 'firstdraft plan push' or 'firstdraft plan compile'.",
|
|
97
|
+
"Unstated request: when the person asked for something the Plan could not state, run 'firstdraft note unstated_request --request <text>', adding --workaround <text> for what you wrote in the Plan instead or left for later.",
|
|
98
|
+
"Unclear guidance: when a Skill page or a diagnostic was unclear, run 'firstdraft note unclear_guidance --page <page> --unclear <text>', where <page> is the page's path inside the Skill, such as SKILL.md or references/plan/policies.md; for a diagnostic code or a CLI error value, give --code <code> in place of or beside --page, and add --workaround <text> for what you did instead.",
|
|
99
|
+
"Wrong output: when analysis or generated code was wrong, run 'firstdraft note wrong_output --source <source> --expected <text> --actual <text>', where <source> is analysis or generated_code; a note about generated code names the recorded Compilation as a report does, and 'firstdraft note wrong_output --help' lists --code, --file, and --workaround.",
|
|
100
|
+
"Write each note in your own plain words, at most 300 characters a field: never secrets, credentials, personal data, or code from the person's project.",
|
|
101
|
+
]);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* What `firstdraft maintain` prints on standard error when the person said
|
|
105
|
+
* yes to reports, and only then. An item's evidence can hold end users' text,
|
|
106
|
+
* so the report carries none of it.
|
|
107
|
+
*/
|
|
108
|
+
export const MAINTAIN_REPORTS_ON_LINE =
|
|
109
|
+
"Reports are on: after you resolve an error item, one titled with its exception class or Message rather than a check, GitHub, Core, or host item, with --cause generated_code, run 'firstdraft report failure --kind deployed_error --item <item-id>' from the directory where you ran 'firstdraft maintain', adding --error-class from the item's title, --rerun for the spec you wrote, --frame for each place you fixed, and --fix-summary; never put anything from the item's evidence in a report or a note, because it can hold end users' text.";
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* What a maintain command prints on standard error when it found no Project
|
|
113
|
+
* state and read the Project from the
|
|
114
|
+
* application's .firstdraft/gaps.json, as in a fresh clone. That file holds
|
|
115
|
+
* no origin, so the line says which origin it used. It says nothing about
|
|
116
|
+
* reports, which the agent of a person who said no never hears about.
|
|
117
|
+
*
|
|
118
|
+
* @param {string} origin
|
|
119
|
+
*/
|
|
120
|
+
export function applicationProjectLine(origin) {
|
|
121
|
+
return `No First Draft planning folder is here, so the CLI read the Project from .firstdraft/gaps.json and used ${origin}: if the Project is on another First Draft origin, add --staging or set FIRSTDRAFT_API_URL.`;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @typedef {object} DeviceLoginLink
|
|
126
|
+
* @property {string} origin
|
|
127
|
+
* @property {string} userCode
|
|
128
|
+
* @property {string} verificationUri
|
|
129
|
+
* @property {string | undefined} verificationUriComplete
|
|
130
|
+
* @property {number} expiresAt epoch milliseconds
|
|
131
|
+
*/
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* What `login --no-wait` prints. The device code is a credential and never
|
|
135
|
+
* appears; the link and the user code are for the person.
|
|
136
|
+
*
|
|
137
|
+
* @param {DeviceLoginLink & {expiresIn: number}} login
|
|
138
|
+
*/
|
|
139
|
+
export function deviceLoginStartedLines(login) {
|
|
140
|
+
const minutes = Math.max(1, Math.floor(login.expiresIn / 60));
|
|
141
|
+
return [
|
|
142
|
+
...linkLines(login),
|
|
143
|
+
`The link and the code expire in ${minutes} ${minutes === 1 ? "minute" : "minutes"}, at ${utcTime(login.expiresAt)}.`,
|
|
144
|
+
`When the person says they approved, run ${commandLine(login.origin, "login --finish")}.`,
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** @param {string} origin */
|
|
149
|
+
export function deviceLoginFinishedLines(origin) {
|
|
150
|
+
return [
|
|
151
|
+
`Logged in: this computer is now logged in to ${origin}.`,
|
|
152
|
+
`Run ${commandLine(origin, "start")} again.`,
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** @param {DeviceLoginLink} login */
|
|
157
|
+
export function deviceLoginPendingLines(login) {
|
|
158
|
+
return [
|
|
159
|
+
"Still waiting: First Draft has not confirmed that the person approved the login.",
|
|
160
|
+
...linkLines(login),
|
|
161
|
+
`The link and the code expire at ${utcTime(login.expiresAt)}. When the person says they approved, run ${commandLine(login.origin, "login --finish")} again.`,
|
|
162
|
+
];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** @param {string} origin */
|
|
166
|
+
export function deviceLoginExpiredLines(origin) {
|
|
167
|
+
return [
|
|
168
|
+
`Expired: the link and the code expired before this computer finished the login, so no new login was saved for ${origin}.`,
|
|
169
|
+
`To try again, run ${commandLine(origin, "login --no-wait")}.`,
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** @param {string} origin */
|
|
174
|
+
export function deviceLoginRefusedLines(origin) {
|
|
175
|
+
return [
|
|
176
|
+
`Refused: the person denied this login, so no new login was saved for ${origin}.`,
|
|
177
|
+
`Ask the person before you start another login with ${commandLine(origin, "login --no-wait")}.`,
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** @param {string} origin */
|
|
182
|
+
export function deviceLoginNotStartedLines(origin) {
|
|
183
|
+
return [
|
|
184
|
+
`No login is waiting: this computer has no device login for ${origin} that has not ended.`,
|
|
185
|
+
`Run ${commandLine(origin, "start")} to see whether this computer is logged in.`,
|
|
186
|
+
];
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** @param {DeviceLoginLink} login */
|
|
190
|
+
function linkLines({
|
|
191
|
+
origin,
|
|
192
|
+
userCode,
|
|
193
|
+
verificationUri,
|
|
194
|
+
verificationUriComplete,
|
|
195
|
+
}) {
|
|
196
|
+
return verificationUriComplete === undefined
|
|
197
|
+
? [
|
|
198
|
+
`To log in to ${origin}, ask the person to open this link in a browser, enter the code ${userCode}, and approve:`,
|
|
199
|
+
verificationUri,
|
|
200
|
+
]
|
|
201
|
+
: [
|
|
202
|
+
`To log in to ${origin}, ask the person to open this link in a browser, check that the page shows the code ${userCode}, and approve:`,
|
|
203
|
+
verificationUriComplete,
|
|
204
|
+
];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** @param {number} milliseconds */
|
|
208
|
+
function utcTime(milliseconds) {
|
|
209
|
+
return new Date(milliseconds).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
210
|
+
}
|
|
@@ -35,6 +35,13 @@ export function environmentTokenFor(origin, { apiToken, stagingApiToken }) {
|
|
|
35
35
|
return hasToken(token) ? token : undefined;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** The variable that holds the environment token for an origin. @param {string} origin */
|
|
39
|
+
export function environmentTokenVariable(origin) {
|
|
40
|
+
return origin === STAGING_API_URL
|
|
41
|
+
? "FIRSTDRAFT_STAGING_API_TOKEN"
|
|
42
|
+
: "FIRSTDRAFT_API_TOKEN";
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
/**
|
|
39
46
|
* @param {object} options
|
|
40
47
|
* @param {typeof globalThis.fetch} [options.fetchFunction]
|
|
@@ -66,6 +73,10 @@ export function authenticateApiCommand({
|
|
|
66
73
|
|
|
67
74
|
let selectedOrigin = staging ? STAGING_API_URL : undefined;
|
|
68
75
|
const request = fetchFunction ?? globalThis.fetch;
|
|
76
|
+
/** @param {string} origin */
|
|
77
|
+
const tokenFor = (origin) =>
|
|
78
|
+
environmentTokenFor(origin, { apiToken, stagingApiToken }) ??
|
|
79
|
+
storedTokenFor(readStoredTokens(), origin);
|
|
69
80
|
/** @type {typeof globalThis.fetch} */
|
|
70
81
|
const authorizedFetch = (input, init) => {
|
|
71
82
|
const endpoint = new URL(input instanceof Request ? input.url : input);
|
|
@@ -74,9 +85,7 @@ export function authenticateApiCommand({
|
|
|
74
85
|
"The requested API environment does not match the Project origin. No request was made.",
|
|
75
86
|
);
|
|
76
87
|
}
|
|
77
|
-
const token =
|
|
78
|
-
environmentTokenFor(endpoint.origin, { apiToken, stagingApiToken }) ??
|
|
79
|
-
storedToken(readStoredTokens(), endpoint.origin);
|
|
88
|
+
const token = tokenFor(endpoint.origin);
|
|
80
89
|
if (token === undefined) throw new ApiAuthenticationRequiredError();
|
|
81
90
|
selectedOrigin = endpoint.origin;
|
|
82
91
|
return request(input, {
|
|
@@ -87,11 +96,21 @@ export function authenticateApiCommand({
|
|
|
87
96
|
},
|
|
88
97
|
});
|
|
89
98
|
};
|
|
90
|
-
return {
|
|
99
|
+
return {
|
|
100
|
+
apiUrl: configured,
|
|
101
|
+
fetchFunction: authorizedFetch,
|
|
102
|
+
/** Whether a request to `origin` would carry a token. @param {string} origin */
|
|
103
|
+
hasTokenFor: (origin) => tokenFor(origin) !== undefined,
|
|
104
|
+
};
|
|
91
105
|
}
|
|
92
106
|
|
|
93
|
-
/**
|
|
94
|
-
|
|
107
|
+
/**
|
|
108
|
+
* The token a saved login holds for exactly this origin, if any.
|
|
109
|
+
*
|
|
110
|
+
* @param {Readonly<Record<string, string>>} tokens
|
|
111
|
+
* @param {string} origin
|
|
112
|
+
*/
|
|
113
|
+
export function storedTokenFor(tokens, origin) {
|
|
95
114
|
const token = Object.hasOwn(tokens, origin) ? tokens[origin] : undefined;
|
|
96
115
|
return hasToken(token) ? token : undefined;
|
|
97
116
|
}
|
package/src/api-response.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiAuthenticationRequiredError } from "./api-authentication.js";
|
|
2
|
-
import { PlanStateConfigurationError } from "./plan-state.js";
|
|
2
|
+
import { isUuidV7, PlanStateConfigurationError } from "./plan-state.js";
|
|
3
3
|
|
|
4
4
|
const MAX_RESPONSE_BYTES = 2 * 1024 * 1024;
|
|
5
5
|
|
|
@@ -27,6 +27,11 @@ export class FirstDraftProtocolError extends Error {
|
|
|
27
27
|
* has one row for each, and test/service-endpoints.test.js compares the two.
|
|
28
28
|
*/
|
|
29
29
|
export const SERVICE_ROUTES = {
|
|
30
|
+
startProject: { method: "PUT", path: "/v1/projects/{project_id}" },
|
|
31
|
+
publishSketches: {
|
|
32
|
+
method: "PUT",
|
|
33
|
+
path: "/v1/projects/{project_id}/sketch-reviews/{revision_id}",
|
|
34
|
+
},
|
|
30
35
|
pushPlan: {
|
|
31
36
|
method: "PUT",
|
|
32
37
|
path: "/v1/projects/{project_id}/foundation-plan",
|
|
@@ -51,13 +56,41 @@ export const SERVICE_ROUTES = {
|
|
|
51
56
|
method: "GET",
|
|
52
57
|
path: "/v1/projects/{project_id}/compilations/{compilation_id}/artifact",
|
|
53
58
|
},
|
|
54
|
-
|
|
55
|
-
method: "
|
|
56
|
-
path: "/v1/
|
|
59
|
+
readAccount: {
|
|
60
|
+
method: "GET",
|
|
61
|
+
path: "/v1/account",
|
|
62
|
+
},
|
|
63
|
+
sendProgressReport: {
|
|
64
|
+
method: "POST",
|
|
65
|
+
path: "/v1/projects/{project_id}/compilations/{compilation_id}/progress-reports",
|
|
66
|
+
},
|
|
67
|
+
sendFailureReport: {
|
|
68
|
+
method: "POST",
|
|
69
|
+
path: "/v1/projects/{project_id}/compilations/{compilation_id}/failure-reports",
|
|
70
|
+
},
|
|
71
|
+
sendNote: {
|
|
72
|
+
method: "POST",
|
|
73
|
+
path: "/v1/projects/{project_id}/notes",
|
|
74
|
+
},
|
|
75
|
+
listMaintenanceItems: {
|
|
76
|
+
method: "GET",
|
|
77
|
+
path: "/v1/projects/{project_id}/environments/{environment_name}/items",
|
|
57
78
|
},
|
|
58
|
-
|
|
79
|
+
readMaintenanceItem: {
|
|
59
80
|
method: "GET",
|
|
60
|
-
path: "/v1/projects/{project_id}/
|
|
81
|
+
path: "/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}",
|
|
82
|
+
},
|
|
83
|
+
resolveMaintenanceItem: {
|
|
84
|
+
method: "POST",
|
|
85
|
+
path: "/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}/resolution",
|
|
86
|
+
},
|
|
87
|
+
deferMaintenanceItem: {
|
|
88
|
+
method: "POST",
|
|
89
|
+
path: "/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}/deferral",
|
|
90
|
+
},
|
|
91
|
+
askMaintenanceOwner: {
|
|
92
|
+
method: "POST",
|
|
93
|
+
path: "/v1/projects/{project_id}/environments/{environment_name}/items/{item_id}/owner-question",
|
|
61
94
|
},
|
|
62
95
|
requestOAuthToken: {
|
|
63
96
|
method: "POST",
|
|
@@ -164,6 +197,77 @@ export function isProblemBody(response, body) {
|
|
|
164
197
|
);
|
|
165
198
|
}
|
|
166
199
|
|
|
200
|
+
/** @param {Response} response @param {unknown} body */
|
|
201
|
+
export function reviewConflict(response, body) {
|
|
202
|
+
if (
|
|
203
|
+
responseMediaType(response) !== "application/problem+json" ||
|
|
204
|
+
!isRecord(body) ||
|
|
205
|
+
body.status !== response.status ||
|
|
206
|
+
typeof body.detail !== "string"
|
|
207
|
+
)
|
|
208
|
+
return null;
|
|
209
|
+
if (!(
|
|
210
|
+
(body.code === "sketch_review_changed" && body.status === 412) ||
|
|
211
|
+
(body.code === "sketch_review_conflict" && body.status === 409)
|
|
212
|
+
))
|
|
213
|
+
return null;
|
|
214
|
+
const review = body.current_review;
|
|
215
|
+
const head = body.head_sha256;
|
|
216
|
+
if (
|
|
217
|
+
head !== null &&
|
|
218
|
+
(typeof head !== "string" || !/^[a-f0-9]{64}$/.test(head))
|
|
219
|
+
)
|
|
220
|
+
return null;
|
|
221
|
+
if (
|
|
222
|
+
review !== null &&
|
|
223
|
+
!(
|
|
224
|
+
isRecord(review) &&
|
|
225
|
+
isUuidV7(review.id) &&
|
|
226
|
+
typeof review.plan_sha256 === "string" &&
|
|
227
|
+
/^[a-f0-9]{64}$/.test(review.plan_sha256)
|
|
228
|
+
)
|
|
229
|
+
)
|
|
230
|
+
return null;
|
|
231
|
+
return {
|
|
232
|
+
...(validGraphVersion(body.head_graph_version)
|
|
233
|
+
? { head_graph_version: body.head_graph_version }
|
|
234
|
+
: {}),
|
|
235
|
+
code: body.code,
|
|
236
|
+
status: body.status,
|
|
237
|
+
detail: body.detail,
|
|
238
|
+
current_review: review && {
|
|
239
|
+
...(validGraphVersion(review.graph_version)
|
|
240
|
+
? { graph_version: review.graph_version }
|
|
241
|
+
: {}),
|
|
242
|
+
id: review.id,
|
|
243
|
+
plan_sha256: review.plan_sha256,
|
|
244
|
+
},
|
|
245
|
+
head_sha256: head,
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** @param {unknown} value @returns {value is number} */
|
|
250
|
+
function validGraphVersion(value) {
|
|
251
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The fields of a problem that isProblemBody accepted, and nothing else.
|
|
256
|
+
*
|
|
257
|
+
* @param {unknown} body
|
|
258
|
+
*/
|
|
259
|
+
export function problemProjection(body) {
|
|
260
|
+
const problem = /** @type {Record<string, unknown>} */ (body);
|
|
261
|
+
|
|
262
|
+
return {
|
|
263
|
+
...(problem.type === "about:blank" ? { type: problem.type } : {}),
|
|
264
|
+
title: problem.title,
|
|
265
|
+
status: problem.status,
|
|
266
|
+
code: problem.code,
|
|
267
|
+
detail: problem.detail,
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
167
271
|
/**
|
|
168
272
|
* @param {unknown} value
|
|
169
273
|
* @returns {value is Record<string, unknown> & {severity: "error" | "warning"}}
|