paperlint 18.7.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 +2 -2
- package/README.md +2 -2
- 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/cli.d.ts +6 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +34 -10
- 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 +9 -1
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +144 -59
- 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/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/install.md +62 -14
- package/hooks/CLAUDE.md +2 -2
- package/hooks/CLAUDE.md.spec.ts +1 -1
- package/lib/skill-checks.mjs +6 -7
- package/package.json +4 -1
- package/plugin/CLAUDE.md +22 -14
- package/plugin/CLAUDE.md.spec.ts +20 -12
- 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/paper-pipeline/references/anonymization.md +4 -3
- 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/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/cli.harness.mjs +6 -0
- package/src/cli.test.ts +87 -1
- package/src/cli.ts +56 -7
- 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.ts +225 -64
- 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/types.ts +4 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `paperlint init` with the Claude Code plugin: the offer's place in the run, and what init does to
|
|
3
|
+
* the skill links and hook commands it made before the plugin carried them. The offer's own
|
|
4
|
+
* branches are `plugin-offer.test.ts`'s.
|
|
5
|
+
*/
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { describe, expect, it } from "vitest";
|
|
9
|
+
import { scriptedPrompts, useTempDir, writeTree } from "../test/support.ts";
|
|
10
|
+
import {
|
|
11
|
+
readSettings,
|
|
12
|
+
shippedWiring,
|
|
13
|
+
wiredCounts,
|
|
14
|
+
type Settings,
|
|
15
|
+
} from "./hooks-settings.ts";
|
|
16
|
+
import { CANCELLED_CODE, init } from "./init.ts";
|
|
17
|
+
import { PLUGIN_QUESTION } from "./plugin-offer.ts";
|
|
18
|
+
import type { ClaudeCode } from "./ports/claude-code.ts";
|
|
19
|
+
|
|
20
|
+
const dir = useTempDir("paperlint-init-plugin-");
|
|
21
|
+
|
|
22
|
+
/** A Claude Code that is present, off (or installed at 1.0.0), and turns on by running two commands. */
|
|
23
|
+
const claude = (enabled = false): ClaudeCode & { readonly on: string[] } => {
|
|
24
|
+
const on: string[] = [];
|
|
25
|
+
return {
|
|
26
|
+
on,
|
|
27
|
+
present: () => true,
|
|
28
|
+
// Installed once both commands ran, as Claude Code then reads it.
|
|
29
|
+
plugin: (root) =>
|
|
30
|
+
enabled || on.includes(root)
|
|
31
|
+
? { enabled: true, version: "1.0.0" }
|
|
32
|
+
: { enabled: false, version: null },
|
|
33
|
+
enable: (root) => (on.push(root), { ok: true, ran: ["claude x"] }),
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
async function initRun(
|
|
38
|
+
root: string,
|
|
39
|
+
opts: Parameters<typeof init>[1] = {},
|
|
40
|
+
): Promise<{ readonly code: number; readonly out: readonly string[] }> {
|
|
41
|
+
const out: string[] = [];
|
|
42
|
+
const code = await init(root, {
|
|
43
|
+
cwd: root,
|
|
44
|
+
log: (s: string) => out.push(s),
|
|
45
|
+
err: (s: string) => out.push(s),
|
|
46
|
+
interactive: false,
|
|
47
|
+
hooks: true,
|
|
48
|
+
run: () => ({ status: 0 }),
|
|
49
|
+
link: () => ({ ok: false, error: "not linked in this test" }),
|
|
50
|
+
unlink: () => ({ ok: true, removed: [] }),
|
|
51
|
+
...opts,
|
|
52
|
+
});
|
|
53
|
+
return { code, out };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const settingsOf = (root: string): Settings => {
|
|
57
|
+
const read = readSettings(root);
|
|
58
|
+
return read.status === "unparsable" ? {} : read.settings;
|
|
59
|
+
};
|
|
60
|
+
const oursWired = (root: string): number =>
|
|
61
|
+
wiredCounts(settingsOf(root), shippedWiring().names).reduce(
|
|
62
|
+
(n, c) => n + c.ours,
|
|
63
|
+
0,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
describe("init and the plugin", () => {
|
|
67
|
+
it("no plugin (no human, no flag): the one line, and the hooks wired as before", async () => {
|
|
68
|
+
const root = join(dir, "a");
|
|
69
|
+
writeTree(root, { "x.txt": "" });
|
|
70
|
+
const r = await initRun(root, { claude: claude() });
|
|
71
|
+
expect(r.out).toContain(
|
|
72
|
+
"Claude Code plugin: not turned on — stdin is not a terminal, so nothing was asked. To turn it on: npx paperlint init --plugin",
|
|
73
|
+
);
|
|
74
|
+
expect(oursWired(root)).toBe(shippedWiring().names.length);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("an existing project, re-run with --plugin: init's hook commands and links go, the project's own settings stay", async () => {
|
|
78
|
+
const root = join(dir, "b");
|
|
79
|
+
writeTree(root, {
|
|
80
|
+
".claude/settings.json": '{ "permissions": { "allow": ["Bash(ls)"] } }',
|
|
81
|
+
});
|
|
82
|
+
await initRun(root);
|
|
83
|
+
expect(oursWired(root)).toBe(shippedWiring().names.length);
|
|
84
|
+
const cc = claude();
|
|
85
|
+
const r = await initRun(root, {
|
|
86
|
+
claude: cc,
|
|
87
|
+
pluginFlag: "plugin",
|
|
88
|
+
unlink: () => ({ ok: true, removed: ["paper-pipeline"] }),
|
|
89
|
+
});
|
|
90
|
+
expect([
|
|
91
|
+
r.code,
|
|
92
|
+
cc.on,
|
|
93
|
+
oursWired(root),
|
|
94
|
+
settingsOf(root)["permissions"],
|
|
95
|
+
]).toEqual([0, [root], 0, { allow: ["Bash(ls)"] }]);
|
|
96
|
+
expect(r.out).toEqual(
|
|
97
|
+
expect.arrayContaining([
|
|
98
|
+
"skills and hooks (the plugin carries them now)",
|
|
99
|
+
" ✓ removed the skill links init made: paper-pipeline",
|
|
100
|
+
` ✓ removed the hook commands init wrote into ${join(".claude", "settings.json")}: ${shippedWiring().names.join(", ")}`,
|
|
101
|
+
]),
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
describe("init's own doctor check sees the plugin", () => {
|
|
107
|
+
it("plugin on: the closing doctor says the plugin carries the skills and hooks, and passes", async () => {
|
|
108
|
+
const root = join(dir, "doctor-on");
|
|
109
|
+
writeTree(root, { "x.txt": "" });
|
|
110
|
+
const r = await initRun(root, { claude: claude(true) });
|
|
111
|
+
// The same project checked by `paperlint doctor` reads the plugin; init's own check must too.
|
|
112
|
+
expect([
|
|
113
|
+
r.code,
|
|
114
|
+
r.out
|
|
115
|
+
.flatMap((l) => l.split("\n"))
|
|
116
|
+
.filter((l) => l === " ✓ carried by the plugin").length,
|
|
117
|
+
]).toEqual([0, 2]);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("init and the plugin — the edges", () => {
|
|
122
|
+
it("already on, nothing of init's left: both said; a links check that cannot run is named", async () => {
|
|
123
|
+
const root = join(dir, "c");
|
|
124
|
+
writeTree(root, { "x.txt": "" });
|
|
125
|
+
const r = await initRun(root, {
|
|
126
|
+
claude: claude(true),
|
|
127
|
+
unlink: () => ({ ok: false, error: "paperlint does not resolve" }),
|
|
128
|
+
});
|
|
129
|
+
expect(r.out).toEqual(
|
|
130
|
+
expect.arrayContaining([
|
|
131
|
+
" ✓ already on for this project, version 1.0.0",
|
|
132
|
+
" ⚠ skill links not checked — paperlint does not resolve",
|
|
133
|
+
" ✓ no hook commands of init's to remove",
|
|
134
|
+
]),
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("a settings file that does not parse, or a merge that throws: the hooks are named not checked", async () => {
|
|
139
|
+
const root = join(dir, "d");
|
|
140
|
+
writeTree(root, { ".claude/settings.json": "{ nope" });
|
|
141
|
+
const bad = await initRun(root, { claude: claude(true) });
|
|
142
|
+
const wired = join(dir, "e");
|
|
143
|
+
writeTree(wired, { "x.txt": "" });
|
|
144
|
+
await initRun(wired);
|
|
145
|
+
const thrown = await initRun(wired, {
|
|
146
|
+
claude: claude(true),
|
|
147
|
+
merge: () => {
|
|
148
|
+
throw new Error("merge exploded");
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
expect([
|
|
152
|
+
bad.out.find((l) => l.startsWith(" ⚠ hook commands")),
|
|
153
|
+
thrown.out.find((l) => l.startsWith(" ⚠ hook commands")),
|
|
154
|
+
readFileSync(join(root, ".claude", "settings.json"), "utf8"),
|
|
155
|
+
]).toEqual([
|
|
156
|
+
expect.stringContaining(" ⚠ hook commands not checked — "),
|
|
157
|
+
" ⚠ hook commands not checked — merge exploded",
|
|
158
|
+
"{ nope",
|
|
159
|
+
]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("a human: asked once; Ctrl+C at the question stops init with its code", async () => {
|
|
163
|
+
const root = join(dir, "f");
|
|
164
|
+
writeTree(root, { "x.txt": "" });
|
|
165
|
+
const prompts = scriptedPrompts((m) =>
|
|
166
|
+
m === PLUGIN_QUESTION ? "cancel" : undefined,
|
|
167
|
+
);
|
|
168
|
+
const r = await initRun(root, {
|
|
169
|
+
claude: claude(),
|
|
170
|
+
interactive: true,
|
|
171
|
+
prompts,
|
|
172
|
+
});
|
|
173
|
+
expect([
|
|
174
|
+
r.code,
|
|
175
|
+
prompts.asked.filter((m) => m === PLUGIN_QUESTION),
|
|
176
|
+
]).toEqual([CANCELLED_CODE, [PLUGIN_QUESTION]]);
|
|
177
|
+
});
|
|
178
|
+
});
|
package/src/init.ts
CHANGED
|
@@ -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,
|
|
@@ -76,6 +82,14 @@ import { messageOf } from "./domain/text.ts";
|
|
|
76
82
|
import { isRecord } from "./domain/record.ts";
|
|
77
83
|
import type { NamedVenue } from "./domain/venue-name.ts";
|
|
78
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";
|
|
79
93
|
|
|
80
94
|
/** How the papers directory was arrived at. Printed, because a guess must not read as a fact. */
|
|
81
95
|
export type PapersHow =
|
|
@@ -459,25 +473,110 @@ export async function offerHooks(
|
|
|
459
473
|
if (!valueOr(answer, true)) return { status: "declined" };
|
|
460
474
|
}
|
|
461
475
|
try {
|
|
462
|
-
|
|
463
|
-
// object, and an implementation that one day reads `this` must not break here.
|
|
464
|
-
let m = merge;
|
|
465
|
-
if (!m) {
|
|
466
|
-
// eslint-disable-next-line boundaries/dependencies -- legacy layer, moves behind a port in #76
|
|
467
|
-
const { claudeCodeHookProtocol } = await import("vigiles/claude-code");
|
|
468
|
-
m = (existing, compiled, managedBy) =>
|
|
469
|
-
claudeCodeHookProtocol.mergeRegistrations(
|
|
470
|
-
existing,
|
|
471
|
-
compiled,
|
|
472
|
-
managedBy,
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
return wireHooks(root, m, shippedWiring());
|
|
476
|
+
return wireHooks(root, await loadMerge(merge), shippedWiring());
|
|
476
477
|
} catch (e) {
|
|
477
478
|
return { status: "failed", reason: messageOf(e) };
|
|
478
479
|
}
|
|
479
480
|
}
|
|
480
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
|
+
|
|
481
580
|
/** The hooks section of init's report. Every default names the flag that changes it. */
|
|
482
581
|
export function reportHooks(
|
|
483
582
|
outcome: HooksOutcome,
|
|
@@ -626,6 +725,12 @@ export interface InitOptions {
|
|
|
626
725
|
* it (`paperlint toolchain`). Passed in by the CLI; without them the step only names the command.
|
|
627
726
|
*/
|
|
628
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>;
|
|
629
734
|
}
|
|
630
735
|
|
|
631
736
|
/** Reads one line from a real terminal, for `paperlint new` and the build; init asks through `Prompts`. */
|
|
@@ -732,6 +837,70 @@ function papersLines(decl: DeclarationResult, why: string): string[] {
|
|
|
732
837
|
];
|
|
733
838
|
}
|
|
734
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
|
+
|
|
735
904
|
/** A question was cancelled: say so, and stop. */
|
|
736
905
|
const stop = (log: typeof console.log): number => (
|
|
737
906
|
log(CANCELLED_LINE),
|
|
@@ -758,6 +927,7 @@ export async function init(
|
|
|
758
927
|
run = spawnSync,
|
|
759
928
|
resolveCliPapers,
|
|
760
929
|
link = (r: string) => linkSkills(r),
|
|
930
|
+
unlink = (r: string) => unlinkSkills(r),
|
|
761
931
|
} = opts;
|
|
762
932
|
// An injected `interactive` is a test standing in for a terminal; its reason is the classic one.
|
|
763
933
|
const { interactive, why } =
|
|
@@ -820,23 +990,28 @@ export async function init(
|
|
|
820
990
|
return 2;
|
|
821
991
|
}
|
|
822
992
|
|
|
823
|
-
// ── 3. the
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
);
|
|
831
|
-
|
|
832
|
-
for (const line of reportHooks(hooked, {
|
|
833
|
-
here,
|
|
834
|
-
how: interactive
|
|
835
|
-
? `you were asked; \`--no-hooks\` skips this next time`
|
|
836
|
-
: `default taken: YES — ${why}, so nothing was asked. \`--no-hooks\` skips this`,
|
|
837
|
-
}))
|
|
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) => {
|
|
838
1002
|
log(line);
|
|
839
|
-
|
|
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;
|
|
840
1015
|
|
|
841
1016
|
// ── 5. the one expensive, unguessable thing ───────────────────────────────────────────
|
|
842
1017
|
log(``);
|
|
@@ -848,40 +1023,17 @@ export async function init(
|
|
|
848
1023
|
// ── 6. a first paper — offered only where there is none, and only to a human ──────────
|
|
849
1024
|
log(``);
|
|
850
1025
|
log(`first paper`);
|
|
851
|
-
const papersAbs = resolve(root, papersDir);
|
|
852
|
-
const hasPaper = papersIn(papersAbs).length > 0;
|
|
853
|
-
let wanted: string | null = paper;
|
|
854
1026
|
// A paper that was asked for and not delivered decides the exit code (below): the doctor's
|
|
855
1027
|
// code can be 0, and automation would read an unfulfilled `--paper` as done.
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
const name = valueOr(answer, "").trim();
|
|
866
|
-
wanted = name ? name : null;
|
|
867
|
-
}
|
|
868
|
-
if (wanted !== null && createPaper) {
|
|
869
|
-
const problem = nameProblem(wanted, venues);
|
|
870
|
-
if (problem) {
|
|
871
|
-
log(` ✗ no paper created — ${problem}`);
|
|
872
|
-
paperCode = 2;
|
|
873
|
-
} else {
|
|
874
|
-
const code = await createPaper(papersAbs, wanted);
|
|
875
|
-
if (code !== 0) {
|
|
876
|
-
log(` ⚠ the new paper's lint exited ${String(code)} — see above`);
|
|
877
|
-
paperCode = code;
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
} else if (hasPaper) log(` ✓ ${papersDir} already holds a paper`);
|
|
881
|
-
else
|
|
882
|
-
log(
|
|
883
|
-
` · none yet${interactive ? "" : ` — ${why}, so nothing was asked`}. \`npx paperlint new <name>\` or \`--paper <name>\` creates one`,
|
|
884
|
-
);
|
|
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);
|
|
885
1037
|
|
|
886
1038
|
// ── 7. TeX Live — offered to a human with its cost, never installed unasked ─────────────
|
|
887
1039
|
log(``);
|
|
@@ -927,7 +1079,16 @@ export async function init(
|
|
|
927
1079
|
// ── 9. the install states its own condition ───────────────────────────────────────────
|
|
928
1080
|
log(`── paperlint doctor ${"─".repeat(56)}`);
|
|
929
1081
|
const cliPapers = resolveCliPapers ? resolveCliPapers(root) : papersDir;
|
|
930
|
-
|
|
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
|
+
});
|
|
931
1092
|
if (code !== 0)
|
|
932
1093
|
log(
|
|
933
1094
|
`doctor exits ${String(code)} — the install is NOT finished. The lines marked ✗ above say what is\n` +
|
package/src/link-skills.test.ts
CHANGED
|
@@ -8,14 +8,21 @@ import assert from "node:assert/strict";
|
|
|
8
8
|
import {
|
|
9
9
|
lstatSync,
|
|
10
10
|
mkdirSync,
|
|
11
|
+
readdirSync,
|
|
11
12
|
readlinkSync,
|
|
12
13
|
realpathSync,
|
|
14
|
+
rmSync,
|
|
13
15
|
symlinkSync,
|
|
14
16
|
} from "node:fs";
|
|
15
17
|
import { join } from "node:path";
|
|
16
18
|
import { test } from "vitest";
|
|
17
19
|
import { useTempDir, writeTree } from "../test/support.ts";
|
|
18
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
linkSkills,
|
|
22
|
+
locatePackage,
|
|
23
|
+
unlinkSkills,
|
|
24
|
+
type LinkFs,
|
|
25
|
+
} from "./link-skills.ts";
|
|
19
26
|
|
|
20
27
|
const root = useTempDir("paperlint-link-skills-");
|
|
21
28
|
const realFs: LinkFs = { lstatSync, realpathSync, readlinkSync, symlinkSync };
|
|
@@ -103,3 +110,29 @@ test("entries that are someone else's: a plain file, one that cannot be resolved
|
|
|
103
110
|
},
|
|
104
111
|
]);
|
|
105
112
|
});
|
|
113
|
+
|
|
114
|
+
test("unlinkSkills: removes init's links, leaves the project's own directory and other names, names a package that does not resolve", () => {
|
|
115
|
+
const shipped = pkg("unlink", ["a", "b", "own"]);
|
|
116
|
+
const project = join(root, "unlink-project");
|
|
117
|
+
assert.ok(linkSkills(project, { locate: at(shipped) }).ok);
|
|
118
|
+
rmSync(join(project, ".claude", "skills", "own"));
|
|
119
|
+
writeTree(project, {
|
|
120
|
+
".claude/skills/own/SKILL.md": "# mine\n",
|
|
121
|
+
".claude/skills/other/SKILL.md": "# mine\n",
|
|
122
|
+
});
|
|
123
|
+
assert.deepEqual(
|
|
124
|
+
[
|
|
125
|
+
unlinkSkills(project, { locate: at(shipped) }),
|
|
126
|
+
readdirSync(join(project, ".claude", "skills")).sort(),
|
|
127
|
+
unlinkSkills(project, { locate: () => ({ error: "ENOENT" }) }),
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
{ ok: true, removed: ["a", "b"] },
|
|
131
|
+
["other", "own"],
|
|
132
|
+
{
|
|
133
|
+
ok: false,
|
|
134
|
+
error: `paperlint does not resolve from ${project} (ENOENT)`,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
);
|
|
138
|
+
});
|
package/src/link-skills.ts
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
readlinkSync,
|
|
35
35
|
realpathSync,
|
|
36
36
|
symlinkSync,
|
|
37
|
+
unlinkSync,
|
|
37
38
|
} from "node:fs";
|
|
38
39
|
/* eslint-enable boundaries/dependencies */
|
|
39
40
|
import { createRequire } from "node:module";
|
|
@@ -269,6 +270,39 @@ export function linkSkills(
|
|
|
269
270
|
};
|
|
270
271
|
}
|
|
271
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Removes the links `init` made — each entry that is a link and leads to the shipped skill — once the
|
|
275
|
+
* Claude Code plugin carries the skills. Anything else of the same name is the project's, and stays.
|
|
276
|
+
*/
|
|
277
|
+
export function unlinkSkills(
|
|
278
|
+
project: string,
|
|
279
|
+
{
|
|
280
|
+
locate = locatePackage,
|
|
281
|
+
fs = nodeLinkFs,
|
|
282
|
+
remove = unlinkSync,
|
|
283
|
+
}: {
|
|
284
|
+
readonly locate?: (p: string) => Located;
|
|
285
|
+
readonly fs?: LinkFs;
|
|
286
|
+
readonly remove?: (path: string) => void;
|
|
287
|
+
} = {},
|
|
288
|
+
):
|
|
289
|
+
| { readonly ok: true; readonly removed: readonly string[] }
|
|
290
|
+
| { readonly ok: false; readonly error: string } {
|
|
291
|
+
const report = linkSkills(project, { write: false, locate, fs });
|
|
292
|
+
if (!report.ok) return report;
|
|
293
|
+
const removed = report.links
|
|
294
|
+
.filter(
|
|
295
|
+
(l) =>
|
|
296
|
+
l.status === "present" &&
|
|
297
|
+
fs.lstatSync(join(report.home, l.name)).isSymbolicLink(),
|
|
298
|
+
)
|
|
299
|
+
.map((l) => l.name);
|
|
300
|
+
removed.forEach((name) => {
|
|
301
|
+
remove(join(report.home, name));
|
|
302
|
+
});
|
|
303
|
+
return { ok: true, removed };
|
|
304
|
+
}
|
|
305
|
+
|
|
272
306
|
/** Every shipped skill's link, and the first one's target as the report's example. */
|
|
273
307
|
function linkAll(
|
|
274
308
|
shipped: { readonly skillsDir: string; readonly names: readonly string[] },
|
package/src/parse-args.test.ts
CHANGED
|
@@ -44,6 +44,8 @@ describe("parseArgs — the switches, each turning one field on", () => {
|
|
|
44
44
|
["--yes", "yes"],
|
|
45
45
|
["-y", "yes"],
|
|
46
46
|
["--no-hooks", "noHooks"],
|
|
47
|
+
["--plugin", "plugin"],
|
|
48
|
+
["--no-plugin", "noPlugin"],
|
|
47
49
|
["--allow-venue-name", "allowVenueName"],
|
|
48
50
|
] as const)("%s → %s", (flag, key) => {
|
|
49
51
|
const off = parseArgs(["new", "x"]);
|