paperlint 18.6.0 → 18.8.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-plugin/marketplace.json +11 -0
- package/.claude-plugin/plugin.json +7 -0
- 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/claude-code/claude.io.d.ts +13 -0
- package/dist/adapters/claude-code/claude.io.d.ts.map +1 -0
- package/dist/adapters/claude-code/claude.io.js +68 -0
- package/dist/adapters/claude-code/claude.io.js.map +1 -0
- package/dist/adapters/claude-code/index.d.ts +4 -0
- package/dist/adapters/claude-code/index.d.ts.map +1 -0
- package/dist/adapters/claude-code/index.js +4 -0
- package/dist/adapters/claude-code/index.js.map +1 -0
- package/dist/adapters/claude-code/plugin.d.ts +19 -0
- package/dist/adapters/claude-code/plugin.d.ts.map +1 -0
- package/dist/adapters/claude-code/plugin.js +66 -0
- package/dist/adapters/claude-code/plugin.js.map +1 -0
- 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 +9 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +73 -13
- package/dist/cli.js.map +1 -1
- package/dist/doctor-plugin.d.ts +23 -0
- package/dist/doctor-plugin.d.ts.map +1 -0
- package/dist/doctor-plugin.js +56 -0
- package/dist/doctor-plugin.js.map +1 -0
- package/dist/doctor.d.ts +6 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +69 -26
- package/dist/doctor.js.map +1 -1
- package/dist/hooks-settings.d.ts +18 -0
- package/dist/hooks-settings.d.ts.map +1 -1
- package/dist/hooks-settings.js +25 -0
- package/dist/hooks-settings.js.map +1 -1
- package/dist/init.d.ts +47 -16
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +231 -86
- package/dist/init.js.map +1 -1
- package/dist/link-skills.d.ts +15 -0
- package/dist/link-skills.d.ts.map +1 -1
- package/dist/link-skills.js +18 -1
- package/dist/link-skills.js.map +1 -1
- package/dist/plugin-offer.d.ts +73 -0
- package/dist/plugin-offer.d.ts.map +1 -0
- package/dist/plugin-offer.js +96 -0
- package/dist/plugin-offer.js.map +1 -0
- package/dist/ports/claude-code.d.ts +31 -0
- package/dist/ports/claude-code.d.ts.map +1 -0
- package/dist/ports/claude-code.js +2 -0
- package/dist/ports/claude-code.js.map +1 -0
- 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/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/e2e.md +10 -0
- package/docs/install.md +88 -29
- 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/eslint.config.mjs +1 -0
- package/hooks/CLAUDE.md +2 -2
- package/hooks/CLAUDE.md.spec.ts +1 -1
- package/lib/skill-checks.mjs +13 -6
- package/lib/skill-checks.test.mjs +28 -15
- package/lib/skill-corpus.mjs +5 -2
- package/package.json +8 -3
- package/plugin/CLAUDE.md +22 -14
- package/plugin/CLAUDE.md.spec.ts +20 -12
- package/scripts/bundle-skills.test.ts +226 -0
- package/scripts/bundle-skills.ts +304 -0
- package/scripts/plugin-version.test.ts +80 -0
- package/scripts/plugin-version.ts +58 -0
- package/skills/CLAUDE.md +2 -2
- package/skills/CLAUDE.md.spec.ts +1 -1
- 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/references/anonymization.md +4 -3
- 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/submit-paper/SKILL.md +5 -4
- package/skills/submit-paper/SKILL.md.spec.ts +4 -3
- package/skills/submit-paper/check-deanon.sh +17 -2
- package/skills/submit-paper/check-deanon.test.ts +141 -0
- 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/claude-code/claude.io.ts +103 -0
- package/src/adapters/claude-code/index.test.ts +233 -0
- package/src/adapters/claude-code/index.ts +11 -0
- package/src/adapters/claude-code/plugin.ts +82 -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 +47 -26
- package/src/cli.test.ts +179 -2
- package/src/cli.ts +130 -10
- package/src/doctor-plugin.test.ts +103 -0
- package/src/doctor-plugin.ts +83 -0
- package/src/doctor.test.ts +111 -2
- package/src/doctor.ts +83 -32
- package/src/hooks-notice.test.ts +82 -0
- package/src/hooks-settings.ts +49 -0
- package/src/init-plugin.test.ts +178 -0
- package/src/init.test.ts +138 -27
- package/src/init.ts +341 -124
- package/src/link-skills.test.ts +34 -1
- package/src/link-skills.ts +34 -0
- package/src/parse-args.test.ts +2 -0
- package/src/plugin-offer.test.ts +276 -0
- package/src/plugin-offer.ts +160 -0
- package/src/ports/claude-code.ts +30 -0
- 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/types.ts +4 -0
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.
|
|
@@ -54,11 +54,17 @@ import {
|
|
|
54
54
|
type ProgramProbe,
|
|
55
55
|
} from "./doctor.ts";
|
|
56
56
|
import { PAPER_MARKERS, papersIn } from "./build.ts";
|
|
57
|
-
import {
|
|
57
|
+
import {
|
|
58
|
+
linkSkills,
|
|
59
|
+
SKILLS_HOME,
|
|
60
|
+
unlinkSkills,
|
|
61
|
+
type LinkReport,
|
|
62
|
+
} from "./link-skills.ts";
|
|
58
63
|
import {
|
|
59
64
|
FRESH_CLONE_NOTE,
|
|
60
65
|
SETTINGS_PATH,
|
|
61
66
|
shippedWiring,
|
|
67
|
+
unwireHooks,
|
|
62
68
|
wireHooks,
|
|
63
69
|
type Merge,
|
|
64
70
|
type WireResult,
|
|
@@ -75,11 +81,51 @@ import {
|
|
|
75
81
|
import { messageOf } from "./domain/text.ts";
|
|
76
82
|
import { isRecord } from "./domain/record.ts";
|
|
77
83
|
import type { NamedVenue } from "./domain/venue-name.ts";
|
|
84
|
+
import type { Answer, Prompts } from "./ports/prompts.ts";
|
|
85
|
+
import type { ClaudeCode } from "./ports/claude-code.ts";
|
|
86
|
+
import { absolutePath } from "./domain/paths.ts";
|
|
87
|
+
import {
|
|
88
|
+
offerPlugin,
|
|
89
|
+
pluginOn,
|
|
90
|
+
reportPlugin,
|
|
91
|
+
type PluginFlag,
|
|
92
|
+
} from "./plugin-offer.ts";
|
|
78
93
|
|
|
79
94
|
/** How the papers directory was arrived at. Printed, because a guess must not read as a fact. */
|
|
80
95
|
export type PapersHow =
|
|
81
96
|
"detected" | "chosen" | "not-asked" | "no-answer" | "guessed";
|
|
82
97
|
|
|
98
|
+
/**
|
|
99
|
+
* 🔴 CTRL+C AT A QUESTION STOPS init THERE. Measured 2026-11-22 on a pseudo-terminal: the readline
|
|
100
|
+
* questions this replaced took Ctrl+C as "no answer", so each took its default and init went on — a
|
|
101
|
+
* Ctrl+C at "wire the hooks? [Y/n]" WIRED them, and the run exited 0. A cancel now writes nothing
|
|
102
|
+
* after the question and exits with the shell's code for an interrupt.
|
|
103
|
+
*/
|
|
104
|
+
export const CANCELLED_CODE = 130;
|
|
105
|
+
|
|
106
|
+
/** The line a cancelled run ends with. */
|
|
107
|
+
export const CANCELLED_LINE = ` ✗ cancelled — init stopped at this question, and nothing after it was written. \`npx paperlint init\` starts again`;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* One question, asked through the port. A prompt that FAILS (a stream that ended) is `null`, and
|
|
111
|
+
* its default is taken and said — the rule `askOrDefault` keeps for readline. A cancel passes through.
|
|
112
|
+
*/
|
|
113
|
+
export async function askOrNull<T>(
|
|
114
|
+
ask: () => Promise<Answer<T>>,
|
|
115
|
+
): Promise<Answer<T> | null> {
|
|
116
|
+
try {
|
|
117
|
+
return await ask();
|
|
118
|
+
} catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** The value answered, or `fallback` when the prompt failed. */
|
|
124
|
+
const valueOr = <T>(a: Answer<T> | null, fallback: T): T =>
|
|
125
|
+
a?.kind === "answer" ? a.value : fallback;
|
|
126
|
+
|
|
127
|
+
const cancelled = (a: Answer<unknown> | null): boolean => a?.kind === "cancel";
|
|
128
|
+
|
|
83
129
|
/**
|
|
84
130
|
* 🔴 A QUESTION CAN FAIL, AND ITS FAILURE MUST NOT BE THE COMMAND'S. Measured 2026-09-18 on a
|
|
85
131
|
* real pseudo-terminal: `readline`'s `question()` REJECTS with `AbortError: Aborted with Ctrl+D`
|
|
@@ -161,30 +207,30 @@ export interface PapersChoice {
|
|
|
161
207
|
export async function choosePapers(
|
|
162
208
|
root: string,
|
|
163
209
|
{
|
|
164
|
-
|
|
210
|
+
prompts,
|
|
165
211
|
interactive,
|
|
166
|
-
}: {
|
|
167
|
-
): Promise<PapersChoice> {
|
|
212
|
+
}: { prompts?: Prompts | undefined; interactive: boolean },
|
|
213
|
+
): Promise<PapersChoice | "cancelled"> {
|
|
168
214
|
const candidates = detectPapers(root);
|
|
169
215
|
const first = candidates[0];
|
|
170
216
|
if (first === undefined)
|
|
171
217
|
return { papers: DEFAULT_PAPERS_ROOT, how: "guessed", candidates };
|
|
172
218
|
if (candidates.length === 1)
|
|
173
219
|
return { papers: first, how: "detected", candidates };
|
|
174
|
-
if (!interactive || !
|
|
220
|
+
if (!interactive || !prompts)
|
|
175
221
|
return { papers: first, how: "not-asked", candidates };
|
|
176
222
|
|
|
177
|
-
const
|
|
178
|
-
.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
223
|
+
const answer = await askOrNull(() =>
|
|
224
|
+
prompts.select({
|
|
225
|
+
message: "several directories look like papers roots — which one?",
|
|
226
|
+
options: candidates,
|
|
227
|
+
initial: first,
|
|
228
|
+
}),
|
|
183
229
|
);
|
|
184
|
-
|
|
185
|
-
return
|
|
230
|
+
if (cancelled(answer)) return "cancelled";
|
|
231
|
+
return answer === null
|
|
186
232
|
? { papers: first, how: "no-answer", candidates }
|
|
187
|
-
: { papers:
|
|
233
|
+
: { papers: valueOr(answer, first), how: "chosen", candidates };
|
|
188
234
|
}
|
|
189
235
|
|
|
190
236
|
export type DeclarationResult =
|
|
@@ -212,7 +258,8 @@ export type DeclarationResult =
|
|
|
212
258
|
readonly status: "unparsable";
|
|
213
259
|
readonly path: string;
|
|
214
260
|
readonly reason: string;
|
|
215
|
-
}
|
|
261
|
+
}
|
|
262
|
+
| { readonly status: "cancelled"; readonly path: string };
|
|
216
263
|
|
|
217
264
|
/**
|
|
218
265
|
* Declares the papers directory in the root `paperlint.json` — the one file the hooks, the rules
|
|
@@ -225,7 +272,7 @@ export type DeclarationResult =
|
|
|
225
272
|
*/
|
|
226
273
|
export async function declarePapers(
|
|
227
274
|
root: string,
|
|
228
|
-
choose: () => Promise<PapersChoice>,
|
|
275
|
+
choose: () => Promise<PapersChoice | "cancelled">,
|
|
229
276
|
): Promise<DeclarationResult> {
|
|
230
277
|
const path = join(root, CONFIG_FILE);
|
|
231
278
|
const raw = existsSync(path) ? readFileSync(path, "utf8") : null;
|
|
@@ -247,6 +294,7 @@ export async function declarePapers(
|
|
|
247
294
|
// 🔴 ONLY NOW is the directory measured (or asked about). A declared one is the answer, and a
|
|
248
295
|
// candidate measured beside it is a decision nobody takes.
|
|
249
296
|
const choice = await choose();
|
|
297
|
+
if (choice === "cancelled") return { status: "cancelled", path };
|
|
250
298
|
if (choice.papers === DEFAULT_PAPERS_ROOT)
|
|
251
299
|
return { status: "default", path, papers: choice.papers, choice };
|
|
252
300
|
// Two-space indent and the file's own trailing newline: a declaration is not a licence to
|
|
@@ -296,31 +344,28 @@ export function workflowYaml(): string {
|
|
|
296
344
|
].join("\n");
|
|
297
345
|
}
|
|
298
346
|
|
|
299
|
-
export type WorkflowResult =
|
|
347
|
+
export type WorkflowResult =
|
|
348
|
+
"written" | "kept" | "declined" | "not-asked" | "cancelled";
|
|
300
349
|
|
|
301
350
|
export async function offerWorkflow(
|
|
302
351
|
root: string,
|
|
303
352
|
{
|
|
304
|
-
|
|
353
|
+
prompts,
|
|
305
354
|
interactive,
|
|
306
|
-
}: {
|
|
307
|
-
ask?: (q: string) => Promise<string>;
|
|
308
|
-
interactive: boolean;
|
|
309
|
-
},
|
|
355
|
+
}: { prompts?: Prompts | undefined; interactive: boolean },
|
|
310
356
|
): Promise<WorkflowResult> {
|
|
311
357
|
const path = join(root, WORKFLOW_PATH);
|
|
312
358
|
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";
|
|
359
|
+
if (!interactive || !prompts) return "not-asked";
|
|
360
|
+
const answer = await askOrNull(() =>
|
|
361
|
+
prompts.confirm({
|
|
362
|
+
message: "add a GitHub Actions workflow that runs this in CI?",
|
|
363
|
+
initial: false,
|
|
364
|
+
}),
|
|
365
|
+
);
|
|
366
|
+
if (cancelled(answer)) return "cancelled";
|
|
367
|
+
// No answer — a stream that ended — is the safe default, which is "no file".
|
|
368
|
+
if (!valueOr(answer, false)) return "declined";
|
|
324
369
|
mkdirSync(dirname(path), { recursive: true });
|
|
325
370
|
writeFileSync(path, workflowYaml(), "utf8");
|
|
326
371
|
return "written";
|
|
@@ -338,6 +383,7 @@ export function reportWorkflow(
|
|
|
338
383
|
` ✓ ${WORKFLOW_PATH} is already there — kept, nothing overwritten`,
|
|
339
384
|
);
|
|
340
385
|
else if (wf === "declined") out.push(` · declined — nothing written`);
|
|
386
|
+
else if (wf === "cancelled") return [CANCELLED_LINE];
|
|
341
387
|
else
|
|
342
388
|
out.push(
|
|
343
389
|
` · ${why}, so nothing was asked. Default taken: NO file written.`,
|
|
@@ -391,6 +437,7 @@ export type HooksOutcome =
|
|
|
391
437
|
| WireResult
|
|
392
438
|
| { readonly status: "skipped" }
|
|
393
439
|
| { readonly status: "declined" }
|
|
440
|
+
| { readonly status: "cancelled" }
|
|
394
441
|
| { readonly status: "failed"; readonly reason: string };
|
|
395
442
|
|
|
396
443
|
/**
|
|
@@ -404,48 +451,132 @@ export async function offerHooks(
|
|
|
404
451
|
{
|
|
405
452
|
hooks,
|
|
406
453
|
interactive,
|
|
407
|
-
|
|
454
|
+
prompts,
|
|
408
455
|
merge,
|
|
409
456
|
}: {
|
|
410
457
|
hooks: boolean;
|
|
411
458
|
interactive: boolean;
|
|
412
|
-
|
|
459
|
+
prompts?: Prompts | undefined;
|
|
413
460
|
merge?: Merge | undefined;
|
|
414
461
|
},
|
|
415
462
|
): Promise<HooksOutcome> {
|
|
416
463
|
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" };
|
|
464
|
+
if (interactive && prompts) {
|
|
465
|
+
const answer = await askOrNull(() =>
|
|
466
|
+
prompts.confirm({
|
|
467
|
+
message: `wire the paper hooks into ${SETTINGS_PATH} (committed, shared with every clone)?`,
|
|
468
|
+
initial: true,
|
|
469
|
+
}),
|
|
470
|
+
);
|
|
471
|
+
if (cancelled(answer)) return { status: "cancelled" };
|
|
472
|
+
// A stream that ended is the stated default, which here is YES.
|
|
473
|
+
if (!valueOr(answer, true)) return { status: "declined" };
|
|
428
474
|
}
|
|
429
475
|
try {
|
|
430
|
-
|
|
431
|
-
// object, and an implementation that one day reads `this` must not break here.
|
|
432
|
-
let m = merge;
|
|
433
|
-
if (!m) {
|
|
434
|
-
// eslint-disable-next-line boundaries/dependencies -- legacy layer, moves behind a port in #76
|
|
435
|
-
const { claudeCodeHookProtocol } = await import("vigiles/claude-code");
|
|
436
|
-
m = (existing, compiled, managedBy) =>
|
|
437
|
-
claudeCodeHookProtocol.mergeRegistrations(
|
|
438
|
-
existing,
|
|
439
|
-
compiled,
|
|
440
|
-
managedBy,
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
return wireHooks(root, m, shippedWiring());
|
|
476
|
+
return wireHooks(root, await loadMerge(merge), shippedWiring());
|
|
444
477
|
} catch (e) {
|
|
445
478
|
return { status: "failed", reason: messageOf(e) };
|
|
446
479
|
}
|
|
447
480
|
}
|
|
448
481
|
|
|
482
|
+
/** vigiles' merge: the injected one, or the real one, loaded only when init needs it. */
|
|
483
|
+
async function loadMerge(merge: Merge | undefined): Promise<Merge> {
|
|
484
|
+
if (merge) return merge;
|
|
485
|
+
// eslint-disable-next-line boundaries/dependencies -- legacy layer, moves behind a port in #76
|
|
486
|
+
const { claudeCodeHookProtocol } = await import("vigiles/claude-code");
|
|
487
|
+
// Called THROUGH the protocol object rather than as a detached method: the port is an
|
|
488
|
+
// object, and an implementation that one day reads `this` must not break here.
|
|
489
|
+
return (existing, compiled, managedBy) =>
|
|
490
|
+
claudeCodeHookProtocol.mergeRegistrations(existing, compiled, managedBy);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/** Without the plugin: each skill linked into `.claude/skills/`, the hooks wired into settings. */
|
|
494
|
+
async function linkAndWire(
|
|
495
|
+
root: string,
|
|
496
|
+
{
|
|
497
|
+
link,
|
|
498
|
+
asking,
|
|
499
|
+
here,
|
|
500
|
+
log,
|
|
501
|
+
}: {
|
|
502
|
+
readonly link: (root: string) => LinkReport;
|
|
503
|
+
readonly asking: Parameters<typeof offerHooks>[1] & {
|
|
504
|
+
readonly why: string;
|
|
505
|
+
};
|
|
506
|
+
readonly here: (p: string) => string;
|
|
507
|
+
readonly log: (line: string) => void;
|
|
508
|
+
},
|
|
509
|
+
): Promise<"cancelled" | "done"> {
|
|
510
|
+
reportSkillLinks(link(root), here).forEach((line) => {
|
|
511
|
+
log(line);
|
|
512
|
+
});
|
|
513
|
+
log(``);
|
|
514
|
+
log(
|
|
515
|
+
`hooks (Claude Code runs them from ${SETTINGS_PATH} — committed, shared with every clone)`,
|
|
516
|
+
);
|
|
517
|
+
const hooked = await offerHooks(root, asking);
|
|
518
|
+
reportHooks(hooked, {
|
|
519
|
+
here,
|
|
520
|
+
how: asking.interactive
|
|
521
|
+
? `you were asked; \`--no-hooks\` skips this next time`
|
|
522
|
+
: `default taken: YES — ${asking.why}, so nothing was asked. \`--no-hooks\` skips this`,
|
|
523
|
+
}).forEach((line) => {
|
|
524
|
+
log(line);
|
|
525
|
+
});
|
|
526
|
+
return hooked.status === "cancelled" ? "cancelled" : "done";
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* The plugin is on: the skill links and hook commands init made earlier go, so nothing is listed or
|
|
531
|
+
* run twice. What the project made itself stays, and doctor names it.
|
|
532
|
+
*/
|
|
533
|
+
async function retireOld(
|
|
534
|
+
root: string,
|
|
535
|
+
{
|
|
536
|
+
unlink,
|
|
537
|
+
merge,
|
|
538
|
+
here,
|
|
539
|
+
log,
|
|
540
|
+
}: {
|
|
541
|
+
readonly unlink: (root: string) => ReturnType<typeof unlinkSkills>;
|
|
542
|
+
readonly merge?: Merge | undefined;
|
|
543
|
+
readonly here: (p: string) => string;
|
|
544
|
+
readonly log: (line: string) => void;
|
|
545
|
+
},
|
|
546
|
+
): Promise<"done"> {
|
|
547
|
+
const skills = unlink(root);
|
|
548
|
+
const hooks = await loadMerge(merge)
|
|
549
|
+
.then((m) => unwireHooks(root, m))
|
|
550
|
+
.catch((e: unknown) => ({
|
|
551
|
+
status: "failed" as const,
|
|
552
|
+
reason: messageOf(e),
|
|
553
|
+
}));
|
|
554
|
+
const hookLine = {
|
|
555
|
+
removed: (h: {
|
|
556
|
+
readonly path: string;
|
|
557
|
+
readonly names: readonly string[];
|
|
558
|
+
}) =>
|
|
559
|
+
` ✓ removed the hook commands init wrote into ${here(h.path)}: ${h.names.join(", ")}`,
|
|
560
|
+
none: () => ` ✓ no hook commands of init's to remove`,
|
|
561
|
+
other: (reason: string) => ` ⚠ hook commands not checked — ${reason}`,
|
|
562
|
+
};
|
|
563
|
+
[
|
|
564
|
+
``,
|
|
565
|
+
`skills and hooks (the plugin carries them now)`,
|
|
566
|
+
skills.ok
|
|
567
|
+
? ` ✓ ${skills.removed.length === 0 ? "no skill links of init's to remove" : `removed the skill links init made: ${skills.removed.join(", ")}`}`
|
|
568
|
+
: ` ⚠ skill links not checked — ${skills.error}`,
|
|
569
|
+
hooks.status === "removed"
|
|
570
|
+
? hookLine.removed(hooks)
|
|
571
|
+
: hooks.status === "none"
|
|
572
|
+
? hookLine.none()
|
|
573
|
+
: hookLine.other(hooks.reason),
|
|
574
|
+
].forEach((line) => {
|
|
575
|
+
log(line);
|
|
576
|
+
});
|
|
577
|
+
return "done";
|
|
578
|
+
}
|
|
579
|
+
|
|
449
580
|
/** The hooks section of init's report. Every default names the flag that changes it. */
|
|
450
581
|
export function reportHooks(
|
|
451
582
|
outcome: HooksOutcome,
|
|
@@ -456,6 +587,7 @@ export function reportHooks(
|
|
|
456
587
|
out.push(` · --no-hooks — nothing written`);
|
|
457
588
|
return out;
|
|
458
589
|
}
|
|
590
|
+
if (outcome.status === "cancelled") return [CANCELLED_LINE];
|
|
459
591
|
if (outcome.status === "declined") {
|
|
460
592
|
out.push(
|
|
461
593
|
` · declined — nothing written. \`npx paperlint init\` again wires them later`,
|
|
@@ -552,8 +684,11 @@ export interface InitOptions {
|
|
|
552
684
|
log?: typeof console.log;
|
|
553
685
|
err?: typeof console.error;
|
|
554
686
|
cwd?: string;
|
|
555
|
-
/**
|
|
556
|
-
|
|
687
|
+
/**
|
|
688
|
+
* The questions, drawn by the CLI's clack adapter (`src/adapters/clack/`). Injected so each one is
|
|
689
|
+
* assertable without a pseudo-terminal; without it nothing is asked.
|
|
690
|
+
*/
|
|
691
|
+
prompts?: Prompts;
|
|
557
692
|
/**
|
|
558
693
|
* Whether a human is at the other end. Defaults to `interactivity()` over this process: stdin
|
|
559
694
|
* AND stdout are terminals, `CI` is unset, and no `--yes`.
|
|
@@ -590,9 +725,15 @@ export interface InitOptions {
|
|
|
590
725
|
* it (`paperlint toolchain`). Passed in by the CLI; without them the step only names the command.
|
|
591
726
|
*/
|
|
592
727
|
tex?: { readonly installed: () => boolean; readonly install?: () => number };
|
|
728
|
+
/** Claude Code, for the plugin offer. Passed in by the CLI; without it nothing is offered. */
|
|
729
|
+
claude?: ClaudeCode;
|
|
730
|
+
/** `--plugin` or `--no-plugin`. */
|
|
731
|
+
pluginFlag?: PluginFlag;
|
|
732
|
+
/** Removes the skill links init made; injected only so a test can stand in for the package. */
|
|
733
|
+
unlink?: (root: string) => ReturnType<typeof unlinkSkills>;
|
|
593
734
|
}
|
|
594
735
|
|
|
595
|
-
/** Reads one line from a real terminal
|
|
736
|
+
/** Reads one line from a real terminal, for `paperlint new` and the build; init asks through `Prompts`. */
|
|
596
737
|
export async function askOnTerminal(question: string): Promise<string> {
|
|
597
738
|
// eslint-disable-next-line boundaries/dependencies -- legacy I/O, moves behind a port in #76
|
|
598
739
|
const { createInterface } = await import("node:readline/promises");
|
|
@@ -609,7 +750,12 @@ export async function askOnTerminal(question: string): Promise<string> {
|
|
|
609
750
|
export const TOOLCHAIN_COST = "~270 MB, ~3 min, once";
|
|
610
751
|
|
|
611
752
|
export type TexOutcome =
|
|
612
|
-
|
|
753
|
+
| "installed"
|
|
754
|
+
| "was-installed"
|
|
755
|
+
| "failed"
|
|
756
|
+
| "declined"
|
|
757
|
+
| "not-asked"
|
|
758
|
+
| "cancelled";
|
|
613
759
|
|
|
614
760
|
/**
|
|
615
761
|
* TeX Live, for `paperlint build` — `paperlint lint` needs none. OFFERED to a human with its cost
|
|
@@ -619,21 +765,20 @@ export type TexOutcome =
|
|
|
619
765
|
export async function offerTexLive(
|
|
620
766
|
tex: InitOptions["tex"],
|
|
621
767
|
{
|
|
622
|
-
|
|
768
|
+
prompts,
|
|
623
769
|
interactive,
|
|
624
|
-
}: {
|
|
770
|
+
}: { prompts?: Prompts | undefined; interactive: boolean },
|
|
625
771
|
): Promise<TexOutcome> {
|
|
626
772
|
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";
|
|
773
|
+
if (!interactive || !prompts || !tex?.install) return "not-asked";
|
|
774
|
+
const answer = await askOrNull(() =>
|
|
775
|
+
prompts.confirm({
|
|
776
|
+
message: `install TeX Live now, for \`paperlint build\`? (${TOOLCHAIN_COST})`,
|
|
777
|
+
initial: false,
|
|
778
|
+
}),
|
|
779
|
+
);
|
|
780
|
+
if (cancelled(answer)) return "cancelled";
|
|
781
|
+
if (!valueOr(answer, false)) return "declined";
|
|
637
782
|
return tex.install() === 0 ? "installed" : "failed";
|
|
638
783
|
}
|
|
639
784
|
|
|
@@ -642,6 +787,7 @@ export function reportTexLive(t: TexOutcome, why: string): string[] {
|
|
|
642
787
|
const cmd = `npx paperlint toolchain # ${TOOLCHAIN_COST}`;
|
|
643
788
|
if (t === "was-installed") return [` ✓ paperlint's TeX Live is installed`];
|
|
644
789
|
if (t === "installed") return [` ✓ installed`];
|
|
790
|
+
if (t === "cancelled") return [CANCELLED_LINE];
|
|
645
791
|
if (t === "failed")
|
|
646
792
|
return [
|
|
647
793
|
` ✗ the install failed — see above. Run it again:`,
|
|
@@ -691,6 +837,76 @@ function papersLines(decl: DeclarationResult, why: string): string[] {
|
|
|
691
837
|
];
|
|
692
838
|
}
|
|
693
839
|
|
|
840
|
+
/** The name of the first paper: `--paper`, else asked of a human when there is none yet. */
|
|
841
|
+
async function wantedPaper(
|
|
842
|
+
hasPaper: boolean,
|
|
843
|
+
{
|
|
844
|
+
paper,
|
|
845
|
+
asking: { prompts, interactive },
|
|
846
|
+
createPaper,
|
|
847
|
+
}: Readonly<FirstPaperDeps>,
|
|
848
|
+
): Promise<Answer<string | null>> {
|
|
849
|
+
if (paper !== null || hasPaper || !interactive || !prompts || !createPaper)
|
|
850
|
+
return { kind: "answer", value: paper };
|
|
851
|
+
const answer = await askOrNull(() =>
|
|
852
|
+
prompts.text({
|
|
853
|
+
message: "create a first paper? its name (an empty line skips):",
|
|
854
|
+
placeholder: "skip",
|
|
855
|
+
}),
|
|
856
|
+
);
|
|
857
|
+
if (cancelled(answer)) return { kind: "cancel" };
|
|
858
|
+
return { kind: "answer", value: valueOr(answer, "").trim() || null };
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
interface FirstPaperDeps {
|
|
862
|
+
readonly papersDir: string;
|
|
863
|
+
readonly paper: string | null;
|
|
864
|
+
readonly asking: {
|
|
865
|
+
readonly prompts?: Prompts | undefined;
|
|
866
|
+
readonly interactive: boolean;
|
|
867
|
+
readonly why: string;
|
|
868
|
+
};
|
|
869
|
+
readonly createPaper?:
|
|
870
|
+
((papersRoot: string, name: string) => Promise<number>) | undefined;
|
|
871
|
+
readonly venues: readonly NamedVenue[];
|
|
872
|
+
readonly log: (line: string) => void;
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
/** Step 6, a first paper: the exit code it owes (0 when none was asked for), or a cancel. */
|
|
876
|
+
async function firstPaper(
|
|
877
|
+
papersAbs: string,
|
|
878
|
+
deps: Readonly<FirstPaperDeps>,
|
|
879
|
+
): Promise<number | "cancelled"> {
|
|
880
|
+
const { papersDir, asking, createPaper, venues, log } = deps;
|
|
881
|
+
const hasPaper = papersIn(papersAbs).length > 0;
|
|
882
|
+
const asked = await wantedPaper(hasPaper, deps);
|
|
883
|
+
if (asked.kind === "cancel") return "cancelled";
|
|
884
|
+
const wanted = asked.value;
|
|
885
|
+
if (wanted === null || !createPaper) {
|
|
886
|
+
log(
|
|
887
|
+
hasPaper
|
|
888
|
+
? ` ✓ ${papersDir} already holds a paper`
|
|
889
|
+
: ` · none yet${asking.interactive ? "" : ` — ${asking.why}, so nothing was asked`}. \`npx paperlint new <name>\` or \`--paper <name>\` creates one`,
|
|
890
|
+
);
|
|
891
|
+
return 0;
|
|
892
|
+
}
|
|
893
|
+
const problem = nameProblem(wanted, venues);
|
|
894
|
+
if (problem) {
|
|
895
|
+
log(` ✗ no paper created — ${problem}`);
|
|
896
|
+
return 2;
|
|
897
|
+
}
|
|
898
|
+
const code = await createPaper(papersAbs, wanted);
|
|
899
|
+
if (code !== 0)
|
|
900
|
+
log(` ⚠ the new paper's lint exited ${String(code)} — see above`);
|
|
901
|
+
return code;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
/** A question was cancelled: say so, and stop. */
|
|
905
|
+
const stop = (log: typeof console.log): number => (
|
|
906
|
+
log(CANCELLED_LINE),
|
|
907
|
+
CANCELLED_CODE
|
|
908
|
+
);
|
|
909
|
+
|
|
694
910
|
// Documented in README.md#-getting-started and docs/install.md — update them when this changes.
|
|
695
911
|
export async function init(
|
|
696
912
|
dir: string,
|
|
@@ -701,7 +917,7 @@ export async function init(
|
|
|
701
917
|
err = console.error,
|
|
702
918
|
// eslint-disable-next-line no-restricted-globals -- legacy I/O, moves behind a port in #76
|
|
703
919
|
cwd = process.cwd(),
|
|
704
|
-
|
|
920
|
+
prompts,
|
|
705
921
|
yes = false,
|
|
706
922
|
hooks = true,
|
|
707
923
|
merge,
|
|
@@ -711,6 +927,7 @@ export async function init(
|
|
|
711
927
|
run = spawnSync,
|
|
712
928
|
resolveCliPapers,
|
|
713
929
|
link = (r: string) => linkSkills(r),
|
|
930
|
+
unlink = (r: string) => unlinkSkills(r),
|
|
714
931
|
} = opts;
|
|
715
932
|
// An injected `interactive` is a test standing in for a terminal; its reason is the classic one.
|
|
716
933
|
const { interactive, why } =
|
|
@@ -731,8 +948,9 @@ export async function init(
|
|
|
731
948
|
// ── 1. where the papers are, and 2. the declaration, in paperlint.json when not the default ─
|
|
732
949
|
// The declaration is read FIRST: the directory is measured only when none is declared.
|
|
733
950
|
const decl = await declarePapers(root, () =>
|
|
734
|
-
choosePapers(root, {
|
|
951
|
+
choosePapers(root, { prompts, interactive }),
|
|
735
952
|
);
|
|
953
|
+
if (decl.status === "cancelled") return stop(log);
|
|
736
954
|
for (const line of papersLines(decl, why)) log(line);
|
|
737
955
|
log(``);
|
|
738
956
|
log(`settings`);
|
|
@@ -772,67 +990,57 @@ export async function init(
|
|
|
772
990
|
return 2;
|
|
773
991
|
}
|
|
774
992
|
|
|
775
|
-
// ── 3. the
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
);
|
|
783
|
-
|
|
784
|
-
for (const line of reportHooks(hooked, {
|
|
785
|
-
here,
|
|
786
|
-
how: interactive
|
|
787
|
-
? `you were asked; \`--no-hooks\` skips this next time`
|
|
788
|
-
: `default taken: YES — ${why}, so nothing was asked. \`--no-hooks\` skips this`,
|
|
789
|
-
}))
|
|
993
|
+
// ── 3. the Claude Code plugin, which carries the skills and the hooks ──────────────────
|
|
994
|
+
const plugin = await offerPlugin(absolutePath(root), opts.claude, {
|
|
995
|
+
flag: opts.pluginFlag ?? null,
|
|
996
|
+
interactive,
|
|
997
|
+
why,
|
|
998
|
+
prompts,
|
|
999
|
+
});
|
|
1000
|
+
if (plugin.kind === "cancelled") return stop(log);
|
|
1001
|
+
reportPlugin(plugin).forEach((line) => {
|
|
790
1002
|
log(line);
|
|
1003
|
+
});
|
|
1004
|
+
|
|
1005
|
+
// ── 4. without the plugin: the skills linked, the hooks wired; with it, init's old ones gone ─
|
|
1006
|
+
const wired = pluginOn(plugin)
|
|
1007
|
+
? await retireOld(root, { unlink, merge, here, log })
|
|
1008
|
+
: await linkAndWire(root, {
|
|
1009
|
+
link,
|
|
1010
|
+
asking: { hooks, interactive, prompts, merge, why },
|
|
1011
|
+
here,
|
|
1012
|
+
log,
|
|
1013
|
+
});
|
|
1014
|
+
if (wired === "cancelled") return CANCELLED_CODE;
|
|
791
1015
|
|
|
792
1016
|
// ── 5. the one expensive, unguessable thing ───────────────────────────────────────────
|
|
793
1017
|
log(``);
|
|
794
1018
|
log(`CI`);
|
|
795
|
-
const wf = await offerWorkflow(root, {
|
|
1019
|
+
const wf = await offerWorkflow(root, { prompts, interactive });
|
|
796
1020
|
for (const line of reportWorkflow(wf, { why })) log(line);
|
|
1021
|
+
if (wf === "cancelled") return CANCELLED_CODE;
|
|
797
1022
|
|
|
798
1023
|
// ── 6. a first paper — offered only where there is none, and only to a human ──────────
|
|
799
1024
|
log(``);
|
|
800
1025
|
log(`first paper`);
|
|
801
|
-
const papersAbs = resolve(root, papersDir);
|
|
802
|
-
const hasPaper = papersIn(papersAbs).length > 0;
|
|
803
|
-
let wanted: string | null = paper;
|
|
804
1026
|
// A paper that was asked for and not delivered decides the exit code (below): the doctor's
|
|
805
1027
|
// code can be 0, and automation would read an unfulfilled `--paper` as done.
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
if (problem) {
|
|
816
|
-
log(` ✗ no paper created — ${problem}`);
|
|
817
|
-
paperCode = 2;
|
|
818
|
-
} else {
|
|
819
|
-
const code = await createPaper(papersAbs, wanted);
|
|
820
|
-
if (code !== 0) {
|
|
821
|
-
log(` ⚠ the new paper's lint exited ${String(code)} — see above`);
|
|
822
|
-
paperCode = code;
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
} else if (hasPaper) log(` ✓ ${papersDir} already holds a paper`);
|
|
826
|
-
else
|
|
827
|
-
log(
|
|
828
|
-
` · none yet${interactive ? "" : ` — ${why}, so nothing was asked`}. \`npx paperlint new <name>\` or \`--paper <name>\` creates one`,
|
|
829
|
-
);
|
|
1028
|
+
const paperCode = await firstPaper(resolve(root, papersDir), {
|
|
1029
|
+
papersDir,
|
|
1030
|
+
paper,
|
|
1031
|
+
asking: { prompts, interactive, why },
|
|
1032
|
+
createPaper,
|
|
1033
|
+
venues,
|
|
1034
|
+
log,
|
|
1035
|
+
});
|
|
1036
|
+
if (paperCode === "cancelled") return stop(log);
|
|
830
1037
|
|
|
831
1038
|
// ── 7. TeX Live — offered to a human with its cost, never installed unasked ─────────────
|
|
832
1039
|
log(``);
|
|
833
1040
|
log(`TeX Live (for \`paperlint build\`; \`paperlint lint\` needs none)`);
|
|
834
|
-
const texOutcome = await offerTexLive(opts.tex, {
|
|
1041
|
+
const texOutcome = await offerTexLive(opts.tex, { prompts, interactive });
|
|
835
1042
|
for (const line of reportTexLive(texOutcome, why)) log(line);
|
|
1043
|
+
if (texOutcome === "cancelled") return CANCELLED_CODE;
|
|
836
1044
|
|
|
837
1045
|
// ── 8. the other programs are reported, never installed ────────────────────────────────
|
|
838
1046
|
log(``);
|
|
@@ -871,7 +1079,16 @@ export async function init(
|
|
|
871
1079
|
// ── 9. the install states its own condition ───────────────────────────────────────────
|
|
872
1080
|
log(`── paperlint doctor ${"─".repeat(56)}`);
|
|
873
1081
|
const cliPapers = resolveCliPapers ? resolveCliPapers(root) : papersDir;
|
|
874
|
-
|
|
1082
|
+
// Read after step 3, as `paperlint doctor` reads it: the plugin carries the skills and hooks now.
|
|
1083
|
+
const at = absolutePath(root);
|
|
1084
|
+
const code = doctor({
|
|
1085
|
+
log,
|
|
1086
|
+
cwd: root,
|
|
1087
|
+
projectDir: root,
|
|
1088
|
+
run,
|
|
1089
|
+
cliPapers,
|
|
1090
|
+
plugin: opts.claude?.present(at) ? opts.claude.plugin(at) : null,
|
|
1091
|
+
});
|
|
875
1092
|
if (code !== 0)
|
|
876
1093
|
log(
|
|
877
1094
|
`doctor exits ${String(code)} — the install is NOT finished. The lines marked ✗ above say what is\n` +
|