paperlint 18.5.0 → 18.7.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/CLAUDE.md +3 -3
- package/CONTRIBUTING.md +5 -2
- package/README.md +6 -6
- package/dist/adapters/clack/index.d.ts +3 -0
- package/dist/adapters/clack/index.d.ts.map +1 -0
- package/dist/adapters/clack/index.js +3 -0
- package/dist/adapters/clack/index.js.map +1 -0
- package/dist/adapters/clack/prompts.io.d.ts +8 -0
- package/dist/adapters/clack/prompts.io.d.ts.map +1 -0
- package/dist/adapters/clack/prompts.io.js +20 -0
- package/dist/adapters/clack/prompts.io.js.map +1 -0
- package/dist/adapters/hotcrp/portal.io.d.ts.map +1 -1
- package/dist/adapters/hotcrp/portal.io.js +1 -0
- package/dist/adapters/hotcrp/portal.io.js.map +1 -1
- package/dist/adapters/hotcrp/response.d.ts.map +1 -1
- package/dist/adapters/hotcrp/response.js +15 -0
- package/dist/adapters/hotcrp/response.js.map +1 -1
- package/dist/adapters/package-manager/index.d.ts +4 -0
- package/dist/adapters/package-manager/index.d.ts.map +1 -0
- package/dist/adapters/package-manager/index.js +4 -0
- package/dist/adapters/package-manager/index.js.map +1 -0
- package/dist/adapters/package-manager/install.io.d.ts +3 -0
- package/dist/adapters/package-manager/install.io.d.ts.map +1 -0
- package/dist/adapters/package-manager/install.io.js +23 -0
- package/dist/adapters/package-manager/install.io.js.map +1 -0
- package/dist/adapters/package-manager/manager.d.ts +13 -0
- package/dist/adapters/package-manager/manager.d.ts.map +1 -0
- package/dist/adapters/package-manager/manager.js +22 -0
- package/dist/adapters/package-manager/manager.js.map +1 -0
- package/dist/adapters/study-registry/index.d.ts +2 -2
- package/dist/cli.d.ts +4 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +47 -9
- package/dist/cli.js.map +1 -1
- package/dist/domain/submission.d.ts +4 -0
- package/dist/domain/submission.d.ts.map +1 -1
- package/dist/domain/submission.js.map +1 -1
- package/dist/init.d.ts +38 -15
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +99 -39
- package/dist/init.js.map +1 -1
- package/dist/ports/project-install.d.ts +19 -0
- package/dist/ports/project-install.d.ts.map +1 -0
- package/dist/ports/project-install.js +2 -0
- package/dist/ports/project-install.js.map +1 -0
- package/dist/ports/prompts.d.ts +31 -0
- package/dist/ports/prompts.d.ts.map +1 -0
- package/dist/ports/prompts.js +2 -0
- package/dist/ports/prompts.js.map +1 -0
- package/dist/self-install.d.ts +65 -0
- package/dist/self-install.d.ts.map +1 -0
- package/dist/self-install.js +145 -0
- package/dist/self-install.js.map +1 -0
- package/dist/skill-chunks/chunk-65X5HVIJ.js +26462 -0
- package/dist/skill-chunks/chunk-6NU6CXUS.js +258 -0
- package/dist/skill-chunks/chunk-GRSXIWYF.js +352 -0
- package/dist/skill-chunks/chunk-IREAROCV.js +84 -0
- package/dist/skill-chunks/chunk-KWK6RT4T.js +24267 -0
- package/dist/skill-chunks/chunk-NPQVDEE4.js +19681 -0
- package/dist/skill-chunks/chunk-PJ4KNV4J.js +45 -0
- package/dist/skill-chunks/dist-UPCJMLBM.js +385 -0
- package/dist/skill-chunks/pdfjs-LUMEFOH2.js +39518 -0
- package/dist/submission.d.ts +19 -2
- package/dist/submission.d.ts.map +1 -1
- package/dist/submission.js +121 -17
- package/dist/submission.js.map +1 -1
- package/docs/e2e.md +10 -0
- package/docs/install.md +27 -16
- package/docs/prior-art/README.md +2 -0
- package/docs/prior-art/one-command-install.md +33 -0
- package/docs/prior-art/prompt-libraries.md +32 -0
- package/docs/submission.md +19 -4
- package/eslint.config.mjs +1 -0
- package/lib/skill-checks.mjs +17 -9
- package/lib/skill-checks.test.mjs +28 -15
- package/lib/skill-corpus.mjs +5 -2
- package/package.json +5 -3
- package/scripts/bundle-skills.test.ts +226 -0
- package/scripts/bundle-skills.ts +304 -0
- package/skills/argument-arc/SKILL.md +2 -2
- package/skills/argument-arc/SKILL.md.spec.ts +1 -1
- package/skills/argument-arc/scripts/headings.js +57 -13
- package/skills/build-label-page/scripts/label-page.js +2005 -93
- package/skills/cold-read-diff/scripts/cold-read.js +221 -14
- package/skills/label-agent-runs/scripts/labels.js +272 -348
- package/skills/paper-pipeline/scripts/extract-ref-facts.js +304 -0
- package/skills/pc-panel-review/scripts/prior-reviews.js +7244 -12
- package/skills/run-agent-grid/scripts/grid-guard.js +562 -627
- package/skills/verify-citations/SKILL.md +9 -9
- package/skills/verify-citations/SKILL.md.spec.ts +8 -8
- package/skills/verify-citations/scripts/bib-authors.js +228 -0
- package/skills/verify-citations/scripts/verify-cites.js +816 -0
- package/src/adapters/clack/index.ts +2 -0
- package/src/adapters/clack/prompts.io.ts +35 -0
- package/src/adapters/clack/prompts.test.ts +58 -0
- package/src/adapters/hotcrp/portal.io.ts +1 -0
- package/src/adapters/hotcrp/portal.test.ts +43 -2
- package/src/adapters/hotcrp/response.ts +21 -0
- package/src/adapters/package-manager/index.test.ts +67 -0
- package/src/adapters/package-manager/index.ts +3 -0
- package/src/adapters/package-manager/install.io.ts +27 -0
- package/src/adapters/package-manager/manager.ts +33 -0
- package/src/cli.harness.mjs +41 -26
- package/src/cli.test.ts +93 -2
- package/src/cli.ts +80 -7
- package/src/domain/submission.ts +4 -0
- package/src/init.test.ts +138 -27
- package/src/init.ts +128 -72
- package/src/ports/project-install.ts +18 -0
- package/src/ports/prompts.ts +27 -0
- package/src/self-install.test.ts +267 -0
- package/src/self-install.ts +224 -0
- package/src/submission-fields-run.test.ts +1 -0
- package/src/submission-prior-reviews.test.ts +9 -1
- package/src/submission-show.test.ts +81 -0
- package/src/submission-update.test.ts +164 -6
- package/src/submission.ts +208 -24
package/src/init.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* only place Claude Code looks for project skills (`link-skills.ts`). An
|
|
20
20
|
* entry of the same name that paperlint did not make is reported, never replaced.
|
|
21
21
|
* hooks WRITTEN into `.claude/settings.json` by vigiles' merge (`hooks-settings.ts`);
|
|
22
|
-
* asked
|
|
22
|
+
* asked of a human (Yes preselected), YES without one — the guard is what the package is
|
|
23
23
|
* for, and the edit is idempotent and visible in `git diff`. `--no-hooks` skips.
|
|
24
24
|
* CI workflow ASKED, because writing a file into `.github/` is not guessable and not
|
|
25
25
|
* cheap to undo. Prior art: Playwright's initializer asks exactly this.
|
|
@@ -75,11 +75,43 @@ import {
|
|
|
75
75
|
import { messageOf } from "./domain/text.ts";
|
|
76
76
|
import { isRecord } from "./domain/record.ts";
|
|
77
77
|
import type { NamedVenue } from "./domain/venue-name.ts";
|
|
78
|
+
import type { Answer, Prompts } from "./ports/prompts.ts";
|
|
78
79
|
|
|
79
80
|
/** How the papers directory was arrived at. Printed, because a guess must not read as a fact. */
|
|
80
81
|
export type PapersHow =
|
|
81
82
|
"detected" | "chosen" | "not-asked" | "no-answer" | "guessed";
|
|
82
83
|
|
|
84
|
+
/**
|
|
85
|
+
* 🔴 CTRL+C AT A QUESTION STOPS init THERE. Measured 2026-11-22 on a pseudo-terminal: the readline
|
|
86
|
+
* questions this replaced took Ctrl+C as "no answer", so each took its default and init went on — a
|
|
87
|
+
* Ctrl+C at "wire the hooks? [Y/n]" WIRED them, and the run exited 0. A cancel now writes nothing
|
|
88
|
+
* after the question and exits with the shell's code for an interrupt.
|
|
89
|
+
*/
|
|
90
|
+
export const CANCELLED_CODE = 130;
|
|
91
|
+
|
|
92
|
+
/** The line a cancelled run ends with. */
|
|
93
|
+
export const CANCELLED_LINE = ` ✗ cancelled — init stopped at this question, and nothing after it was written. \`npx paperlint init\` starts again`;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* One question, asked through the port. A prompt that FAILS (a stream that ended) is `null`, and
|
|
97
|
+
* its default is taken and said — the rule `askOrDefault` keeps for readline. A cancel passes through.
|
|
98
|
+
*/
|
|
99
|
+
export async function askOrNull<T>(
|
|
100
|
+
ask: () => Promise<Answer<T>>,
|
|
101
|
+
): Promise<Answer<T> | null> {
|
|
102
|
+
try {
|
|
103
|
+
return await ask();
|
|
104
|
+
} catch {
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The value answered, or `fallback` when the prompt failed. */
|
|
110
|
+
const valueOr = <T>(a: Answer<T> | null, fallback: T): T =>
|
|
111
|
+
a?.kind === "answer" ? a.value : fallback;
|
|
112
|
+
|
|
113
|
+
const cancelled = (a: Answer<unknown> | null): boolean => a?.kind === "cancel";
|
|
114
|
+
|
|
83
115
|
/**
|
|
84
116
|
* 🔴 A QUESTION CAN FAIL, AND ITS FAILURE MUST NOT BE THE COMMAND'S. Measured 2026-09-18 on a
|
|
85
117
|
* real pseudo-terminal: `readline`'s `question()` REJECTS with `AbortError: Aborted with Ctrl+D`
|
|
@@ -161,30 +193,30 @@ export interface PapersChoice {
|
|
|
161
193
|
export async function choosePapers(
|
|
162
194
|
root: string,
|
|
163
195
|
{
|
|
164
|
-
|
|
196
|
+
prompts,
|
|
165
197
|
interactive,
|
|
166
|
-
}: {
|
|
167
|
-
): Promise<PapersChoice> {
|
|
198
|
+
}: { prompts?: Prompts | undefined; interactive: boolean },
|
|
199
|
+
): Promise<PapersChoice | "cancelled"> {
|
|
168
200
|
const candidates = detectPapers(root);
|
|
169
201
|
const first = candidates[0];
|
|
170
202
|
if (first === undefined)
|
|
171
203
|
return { papers: DEFAULT_PAPERS_ROOT, how: "guessed", candidates };
|
|
172
204
|
if (candidates.length === 1)
|
|
173
205
|
return { papers: first, how: "detected", candidates };
|
|
174
|
-
if (!interactive || !
|
|
206
|
+
if (!interactive || !prompts)
|
|
175
207
|
return { papers: first, how: "not-asked", candidates };
|
|
176
208
|
|
|
177
|
-
const
|
|
178
|
-
.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
209
|
+
const answer = await askOrNull(() =>
|
|
210
|
+
prompts.select({
|
|
211
|
+
message: "several directories look like papers roots — which one?",
|
|
212
|
+
options: candidates,
|
|
213
|
+
initial: first,
|
|
214
|
+
}),
|
|
183
215
|
);
|
|
184
|
-
|
|
185
|
-
return
|
|
216
|
+
if (cancelled(answer)) return "cancelled";
|
|
217
|
+
return answer === null
|
|
186
218
|
? { papers: first, how: "no-answer", candidates }
|
|
187
|
-
: { papers:
|
|
219
|
+
: { papers: valueOr(answer, first), how: "chosen", candidates };
|
|
188
220
|
}
|
|
189
221
|
|
|
190
222
|
export type DeclarationResult =
|
|
@@ -212,7 +244,8 @@ export type DeclarationResult =
|
|
|
212
244
|
readonly status: "unparsable";
|
|
213
245
|
readonly path: string;
|
|
214
246
|
readonly reason: string;
|
|
215
|
-
}
|
|
247
|
+
}
|
|
248
|
+
| { readonly status: "cancelled"; readonly path: string };
|
|
216
249
|
|
|
217
250
|
/**
|
|
218
251
|
* Declares the papers directory in the root `paperlint.json` — the one file the hooks, the rules
|
|
@@ -225,7 +258,7 @@ export type DeclarationResult =
|
|
|
225
258
|
*/
|
|
226
259
|
export async function declarePapers(
|
|
227
260
|
root: string,
|
|
228
|
-
choose: () => Promise<PapersChoice>,
|
|
261
|
+
choose: () => Promise<PapersChoice | "cancelled">,
|
|
229
262
|
): Promise<DeclarationResult> {
|
|
230
263
|
const path = join(root, CONFIG_FILE);
|
|
231
264
|
const raw = existsSync(path) ? readFileSync(path, "utf8") : null;
|
|
@@ -247,6 +280,7 @@ export async function declarePapers(
|
|
|
247
280
|
// 🔴 ONLY NOW is the directory measured (or asked about). A declared one is the answer, and a
|
|
248
281
|
// candidate measured beside it is a decision nobody takes.
|
|
249
282
|
const choice = await choose();
|
|
283
|
+
if (choice === "cancelled") return { status: "cancelled", path };
|
|
250
284
|
if (choice.papers === DEFAULT_PAPERS_ROOT)
|
|
251
285
|
return { status: "default", path, papers: choice.papers, choice };
|
|
252
286
|
// Two-space indent and the file's own trailing newline: a declaration is not a licence to
|
|
@@ -296,31 +330,28 @@ export function workflowYaml(): string {
|
|
|
296
330
|
].join("\n");
|
|
297
331
|
}
|
|
298
332
|
|
|
299
|
-
export type WorkflowResult =
|
|
333
|
+
export type WorkflowResult =
|
|
334
|
+
"written" | "kept" | "declined" | "not-asked" | "cancelled";
|
|
300
335
|
|
|
301
336
|
export async function offerWorkflow(
|
|
302
337
|
root: string,
|
|
303
338
|
{
|
|
304
|
-
|
|
339
|
+
prompts,
|
|
305
340
|
interactive,
|
|
306
|
-
}: {
|
|
307
|
-
ask?: (q: string) => Promise<string>;
|
|
308
|
-
interactive: boolean;
|
|
309
|
-
},
|
|
341
|
+
}: { prompts?: Prompts | undefined; interactive: boolean },
|
|
310
342
|
): Promise<WorkflowResult> {
|
|
311
343
|
const path = join(root, WORKFLOW_PATH);
|
|
312
344
|
if (existsSync(path)) return "kept";
|
|
313
|
-
if (!interactive || !
|
|
314
|
-
const answer = (
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
)
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
if (answer !== "y" && answer !== "yes") return "declined";
|
|
345
|
+
if (!interactive || !prompts) return "not-asked";
|
|
346
|
+
const answer = await askOrNull(() =>
|
|
347
|
+
prompts.confirm({
|
|
348
|
+
message: "add a GitHub Actions workflow that runs this in CI?",
|
|
349
|
+
initial: false,
|
|
350
|
+
}),
|
|
351
|
+
);
|
|
352
|
+
if (cancelled(answer)) return "cancelled";
|
|
353
|
+
// No answer — a stream that ended — is the safe default, which is "no file".
|
|
354
|
+
if (!valueOr(answer, false)) return "declined";
|
|
324
355
|
mkdirSync(dirname(path), { recursive: true });
|
|
325
356
|
writeFileSync(path, workflowYaml(), "utf8");
|
|
326
357
|
return "written";
|
|
@@ -338,6 +369,7 @@ export function reportWorkflow(
|
|
|
338
369
|
` ✓ ${WORKFLOW_PATH} is already there — kept, nothing overwritten`,
|
|
339
370
|
);
|
|
340
371
|
else if (wf === "declined") out.push(` · declined — nothing written`);
|
|
372
|
+
else if (wf === "cancelled") return [CANCELLED_LINE];
|
|
341
373
|
else
|
|
342
374
|
out.push(
|
|
343
375
|
` · ${why}, so nothing was asked. Default taken: NO file written.`,
|
|
@@ -391,6 +423,7 @@ export type HooksOutcome =
|
|
|
391
423
|
| WireResult
|
|
392
424
|
| { readonly status: "skipped" }
|
|
393
425
|
| { readonly status: "declined" }
|
|
426
|
+
| { readonly status: "cancelled" }
|
|
394
427
|
| { readonly status: "failed"; readonly reason: string };
|
|
395
428
|
|
|
396
429
|
/**
|
|
@@ -404,27 +437,26 @@ export async function offerHooks(
|
|
|
404
437
|
{
|
|
405
438
|
hooks,
|
|
406
439
|
interactive,
|
|
407
|
-
|
|
440
|
+
prompts,
|
|
408
441
|
merge,
|
|
409
442
|
}: {
|
|
410
443
|
hooks: boolean;
|
|
411
444
|
interactive: boolean;
|
|
412
|
-
|
|
445
|
+
prompts?: Prompts | undefined;
|
|
413
446
|
merge?: Merge | undefined;
|
|
414
447
|
},
|
|
415
448
|
): Promise<HooksOutcome> {
|
|
416
449
|
if (!hooks) return { status: "skipped" };
|
|
417
|
-
if (interactive &&
|
|
418
|
-
const answer = (
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
)
|
|
423
|
-
)
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
if (answer === "n" || answer === "no") return { status: "declined" };
|
|
450
|
+
if (interactive && prompts) {
|
|
451
|
+
const answer = await askOrNull(() =>
|
|
452
|
+
prompts.confirm({
|
|
453
|
+
message: `wire the paper hooks into ${SETTINGS_PATH} (committed, shared with every clone)?`,
|
|
454
|
+
initial: true,
|
|
455
|
+
}),
|
|
456
|
+
);
|
|
457
|
+
if (cancelled(answer)) return { status: "cancelled" };
|
|
458
|
+
// A stream that ended is the stated default, which here is YES.
|
|
459
|
+
if (!valueOr(answer, true)) return { status: "declined" };
|
|
428
460
|
}
|
|
429
461
|
try {
|
|
430
462
|
// Called THROUGH the protocol object rather than as a detached method: the port is an
|
|
@@ -456,6 +488,7 @@ export function reportHooks(
|
|
|
456
488
|
out.push(` · --no-hooks — nothing written`);
|
|
457
489
|
return out;
|
|
458
490
|
}
|
|
491
|
+
if (outcome.status === "cancelled") return [CANCELLED_LINE];
|
|
459
492
|
if (outcome.status === "declined") {
|
|
460
493
|
out.push(
|
|
461
494
|
` · declined — nothing written. \`npx paperlint init\` again wires them later`,
|
|
@@ -552,8 +585,11 @@ export interface InitOptions {
|
|
|
552
585
|
log?: typeof console.log;
|
|
553
586
|
err?: typeof console.error;
|
|
554
587
|
cwd?: string;
|
|
555
|
-
/**
|
|
556
|
-
|
|
588
|
+
/**
|
|
589
|
+
* The questions, drawn by the CLI's clack adapter (`src/adapters/clack/`). Injected so each one is
|
|
590
|
+
* assertable without a pseudo-terminal; without it nothing is asked.
|
|
591
|
+
*/
|
|
592
|
+
prompts?: Prompts;
|
|
557
593
|
/**
|
|
558
594
|
* Whether a human is at the other end. Defaults to `interactivity()` over this process: stdin
|
|
559
595
|
* AND stdout are terminals, `CI` is unset, and no `--yes`.
|
|
@@ -592,7 +628,7 @@ export interface InitOptions {
|
|
|
592
628
|
tex?: { readonly installed: () => boolean; readonly install?: () => number };
|
|
593
629
|
}
|
|
594
630
|
|
|
595
|
-
/** Reads one line from a real terminal
|
|
631
|
+
/** Reads one line from a real terminal, for `paperlint new` and the build; init asks through `Prompts`. */
|
|
596
632
|
export async function askOnTerminal(question: string): Promise<string> {
|
|
597
633
|
// eslint-disable-next-line boundaries/dependencies -- legacy I/O, moves behind a port in #76
|
|
598
634
|
const { createInterface } = await import("node:readline/promises");
|
|
@@ -609,7 +645,12 @@ export async function askOnTerminal(question: string): Promise<string> {
|
|
|
609
645
|
export const TOOLCHAIN_COST = "~270 MB, ~3 min, once";
|
|
610
646
|
|
|
611
647
|
export type TexOutcome =
|
|
612
|
-
|
|
648
|
+
| "installed"
|
|
649
|
+
| "was-installed"
|
|
650
|
+
| "failed"
|
|
651
|
+
| "declined"
|
|
652
|
+
| "not-asked"
|
|
653
|
+
| "cancelled";
|
|
613
654
|
|
|
614
655
|
/**
|
|
615
656
|
* TeX Live, for `paperlint build` — `paperlint lint` needs none. OFFERED to a human with its cost
|
|
@@ -619,21 +660,20 @@ export type TexOutcome =
|
|
|
619
660
|
export async function offerTexLive(
|
|
620
661
|
tex: InitOptions["tex"],
|
|
621
662
|
{
|
|
622
|
-
|
|
663
|
+
prompts,
|
|
623
664
|
interactive,
|
|
624
|
-
}: {
|
|
665
|
+
}: { prompts?: Prompts | undefined; interactive: boolean },
|
|
625
666
|
): Promise<TexOutcome> {
|
|
626
667
|
if (tex?.installed()) return "was-installed";
|
|
627
|
-
if (!interactive || !
|
|
628
|
-
const answer = (
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
)
|
|
633
|
-
)
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
if (answer !== "y" && answer !== "yes") return "declined";
|
|
668
|
+
if (!interactive || !prompts || !tex?.install) return "not-asked";
|
|
669
|
+
const answer = await askOrNull(() =>
|
|
670
|
+
prompts.confirm({
|
|
671
|
+
message: `install TeX Live now, for \`paperlint build\`? (${TOOLCHAIN_COST})`,
|
|
672
|
+
initial: false,
|
|
673
|
+
}),
|
|
674
|
+
);
|
|
675
|
+
if (cancelled(answer)) return "cancelled";
|
|
676
|
+
if (!valueOr(answer, false)) return "declined";
|
|
637
677
|
return tex.install() === 0 ? "installed" : "failed";
|
|
638
678
|
}
|
|
639
679
|
|
|
@@ -642,6 +682,7 @@ export function reportTexLive(t: TexOutcome, why: string): string[] {
|
|
|
642
682
|
const cmd = `npx paperlint toolchain # ${TOOLCHAIN_COST}`;
|
|
643
683
|
if (t === "was-installed") return [` ✓ paperlint's TeX Live is installed`];
|
|
644
684
|
if (t === "installed") return [` ✓ installed`];
|
|
685
|
+
if (t === "cancelled") return [CANCELLED_LINE];
|
|
645
686
|
if (t === "failed")
|
|
646
687
|
return [
|
|
647
688
|
` ✗ the install failed — see above. Run it again:`,
|
|
@@ -691,6 +732,12 @@ function papersLines(decl: DeclarationResult, why: string): string[] {
|
|
|
691
732
|
];
|
|
692
733
|
}
|
|
693
734
|
|
|
735
|
+
/** A question was cancelled: say so, and stop. */
|
|
736
|
+
const stop = (log: typeof console.log): number => (
|
|
737
|
+
log(CANCELLED_LINE),
|
|
738
|
+
CANCELLED_CODE
|
|
739
|
+
);
|
|
740
|
+
|
|
694
741
|
// Documented in README.md#-getting-started and docs/install.md — update them when this changes.
|
|
695
742
|
export async function init(
|
|
696
743
|
dir: string,
|
|
@@ -701,7 +748,7 @@ export async function init(
|
|
|
701
748
|
err = console.error,
|
|
702
749
|
// eslint-disable-next-line no-restricted-globals -- legacy I/O, moves behind a port in #76
|
|
703
750
|
cwd = process.cwd(),
|
|
704
|
-
|
|
751
|
+
prompts,
|
|
705
752
|
yes = false,
|
|
706
753
|
hooks = true,
|
|
707
754
|
merge,
|
|
@@ -731,8 +778,9 @@ export async function init(
|
|
|
731
778
|
// ── 1. where the papers are, and 2. the declaration, in paperlint.json when not the default ─
|
|
732
779
|
// The declaration is read FIRST: the directory is measured only when none is declared.
|
|
733
780
|
const decl = await declarePapers(root, () =>
|
|
734
|
-
choosePapers(root, {
|
|
781
|
+
choosePapers(root, { prompts, interactive }),
|
|
735
782
|
);
|
|
783
|
+
if (decl.status === "cancelled") return stop(log);
|
|
736
784
|
for (const line of papersLines(decl, why)) log(line);
|
|
737
785
|
log(``);
|
|
738
786
|
log(`settings`);
|
|
@@ -780,7 +828,7 @@ export async function init(
|
|
|
780
828
|
log(
|
|
781
829
|
`hooks (Claude Code runs them from ${SETTINGS_PATH} — committed, shared with every clone)`,
|
|
782
830
|
);
|
|
783
|
-
const hooked = await offerHooks(root, { hooks, interactive,
|
|
831
|
+
const hooked = await offerHooks(root, { hooks, interactive, prompts, merge });
|
|
784
832
|
for (const line of reportHooks(hooked, {
|
|
785
833
|
here,
|
|
786
834
|
how: interactive
|
|
@@ -788,12 +836,14 @@ export async function init(
|
|
|
788
836
|
: `default taken: YES — ${why}, so nothing was asked. \`--no-hooks\` skips this`,
|
|
789
837
|
}))
|
|
790
838
|
log(line);
|
|
839
|
+
if (hooked.status === "cancelled") return CANCELLED_CODE;
|
|
791
840
|
|
|
792
841
|
// ── 5. the one expensive, unguessable thing ───────────────────────────────────────────
|
|
793
842
|
log(``);
|
|
794
843
|
log(`CI`);
|
|
795
|
-
const wf = await offerWorkflow(root, {
|
|
844
|
+
const wf = await offerWorkflow(root, { prompts, interactive });
|
|
796
845
|
for (const line of reportWorkflow(wf, { why })) log(line);
|
|
846
|
+
if (wf === "cancelled") return CANCELLED_CODE;
|
|
797
847
|
|
|
798
848
|
// ── 6. a first paper — offered only where there is none, and only to a human ──────────
|
|
799
849
|
log(``);
|
|
@@ -804,11 +854,16 @@ export async function init(
|
|
|
804
854
|
// A paper that was asked for and not delivered decides the exit code (below): the doctor's
|
|
805
855
|
// code can be 0, and automation would read an unfulfilled `--paper` as done.
|
|
806
856
|
let paperCode = 0;
|
|
807
|
-
if (wanted === null && !hasPaper && interactive && createPaper) {
|
|
808
|
-
const answer = (
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
857
|
+
if (wanted === null && !hasPaper && interactive && prompts && createPaper) {
|
|
858
|
+
const answer = await askOrNull(() =>
|
|
859
|
+
prompts.text({
|
|
860
|
+
message: "create a first paper? its name (an empty line skips):",
|
|
861
|
+
placeholder: "skip",
|
|
862
|
+
}),
|
|
863
|
+
);
|
|
864
|
+
if (cancelled(answer)) return stop(log);
|
|
865
|
+
const name = valueOr(answer, "").trim();
|
|
866
|
+
wanted = name ? name : null;
|
|
812
867
|
}
|
|
813
868
|
if (wanted !== null && createPaper) {
|
|
814
869
|
const problem = nameProblem(wanted, venues);
|
|
@@ -831,8 +886,9 @@ export async function init(
|
|
|
831
886
|
// ── 7. TeX Live — offered to a human with its cost, never installed unasked ─────────────
|
|
832
887
|
log(``);
|
|
833
888
|
log(`TeX Live (for \`paperlint build\`; \`paperlint lint\` needs none)`);
|
|
834
|
-
const texOutcome = await offerTexLive(opts.tex, {
|
|
889
|
+
const texOutcome = await offerTexLive(opts.tex, { prompts, interactive });
|
|
835
890
|
for (const line of reportTexLive(texOutcome, why)) log(line);
|
|
891
|
+
if (texOutcome === "cancelled") return CANCELLED_CODE;
|
|
836
892
|
|
|
837
893
|
// ── 8. the other programs are reported, never installed ────────────────────────────────
|
|
838
894
|
log(``);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adding a package to the project's devDependencies, with the package manager the project already
|
|
3
|
+
* uses — what `paperlint init` needs to add paperlint itself (`src/self-install.ts`).
|
|
4
|
+
*/
|
|
5
|
+
import type { AbsolutePath } from "../domain/paths.ts";
|
|
6
|
+
|
|
7
|
+
/** A program and its arguments; never empty. */
|
|
8
|
+
export type Argv = readonly [string, ...string[]];
|
|
9
|
+
|
|
10
|
+
export interface ProjectInstall {
|
|
11
|
+
/** The command, as a person would type it, that adds `spec` to `root`'s devDependencies, saved exact. */
|
|
12
|
+
readonly command: (root: AbsolutePath, spec: string) => Argv;
|
|
13
|
+
/** Runs `argv` in `root` with its output on the terminal. */
|
|
14
|
+
readonly run: (
|
|
15
|
+
root: AbsolutePath,
|
|
16
|
+
argv: Argv,
|
|
17
|
+
) => { readonly ok: true } | { readonly ok: false; readonly reason: string };
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The questions `paperlint init` asks a human, shaped by what init needs: a yes/no with a default,
|
|
3
|
+
* one choice out of a list, and a line of text. Nothing here knows which library draws them
|
|
4
|
+
* (`src/adapters/clack/`), so a test answers them without a pseudo-terminal.
|
|
5
|
+
*
|
|
6
|
+
* A cancelled question (Ctrl+C, Esc) is `cancel`, never an answer: init stops at once rather than
|
|
7
|
+
* taking a default the person was trying to refuse.
|
|
8
|
+
*/
|
|
9
|
+
export type Answer<T> =
|
|
10
|
+
{ readonly kind: "answer"; readonly value: T } | { readonly kind: "cancel" };
|
|
11
|
+
|
|
12
|
+
export interface Prompts {
|
|
13
|
+
readonly confirm: (q: {
|
|
14
|
+
readonly message: string;
|
|
15
|
+
readonly initial: boolean;
|
|
16
|
+
}) => Promise<Answer<boolean>>;
|
|
17
|
+
readonly select: (q: {
|
|
18
|
+
readonly message: string;
|
|
19
|
+
readonly options: readonly string[];
|
|
20
|
+
readonly initial: string;
|
|
21
|
+
}) => Promise<Answer<string>>;
|
|
22
|
+
/** An empty line is the answer `""`. */
|
|
23
|
+
readonly text: (q: {
|
|
24
|
+
readonly message: string;
|
|
25
|
+
readonly placeholder: string;
|
|
26
|
+
}) => Promise<Answer<string>>;
|
|
27
|
+
}
|