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,103 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
compareVersions,
|
|
4
|
+
PLUGIN_UPDATE,
|
|
5
|
+
pluginLines,
|
|
6
|
+
type PluginFacts,
|
|
7
|
+
} from "./doctor-plugin.ts";
|
|
8
|
+
|
|
9
|
+
const HEAD = "Claude Code plugin (carries the skills and the hooks)";
|
|
10
|
+
const facts = (over: Partial<PluginFacts> = {}): PluginFacts => ({
|
|
11
|
+
state: { enabled: true, version: "1.2.0" },
|
|
12
|
+
installed: "1.2.0",
|
|
13
|
+
oldLinks: [],
|
|
14
|
+
oldHooks: [],
|
|
15
|
+
...over,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("compareVersions", () => {
|
|
19
|
+
it("orders by the dotted numbers, missing parts as 0, a pre-release tag ignored", () => {
|
|
20
|
+
expect([
|
|
21
|
+
compareVersions("1.2.0", "1.2.0"),
|
|
22
|
+
compareVersions("1.2.0", "1.10.0"),
|
|
23
|
+
compareVersions("2.0", "1.9.9"),
|
|
24
|
+
compareVersions("1.2.0-beta.1", "1.2"),
|
|
25
|
+
compareVersions("x", "0.0.0"),
|
|
26
|
+
]).toEqual([0, -1, 1, 0, 0]);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe("pluginLines — declared, not installed", () => {
|
|
31
|
+
it("declared but not installed: one line, and init's links are not called doubled — nothing loads the plugin", () => {
|
|
32
|
+
expect(
|
|
33
|
+
pluginLines(
|
|
34
|
+
facts({
|
|
35
|
+
state: { enabled: true, version: null },
|
|
36
|
+
oldLinks: ["a"],
|
|
37
|
+
oldHooks: ["h"],
|
|
38
|
+
}),
|
|
39
|
+
),
|
|
40
|
+
).toEqual([
|
|
41
|
+
HEAD,
|
|
42
|
+
" · declared in the settings, not installed — the skills and hooks below are init's links and commands until `npx paperlint init --plugin` runs where `claude` is on PATH",
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe("pluginLines", () => {
|
|
48
|
+
it("on and matching, with nothing of init's left: one line", () => {
|
|
49
|
+
expect(pluginLines(facts())).toEqual([
|
|
50
|
+
HEAD,
|
|
51
|
+
" ✓ on for this project, version 1.2.0",
|
|
52
|
+
]);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("off: one line naming --plugin", () => {
|
|
56
|
+
expect(
|
|
57
|
+
pluginLines(
|
|
58
|
+
facts({ state: { enabled: false, version: null }, oldLinks: ["a"] }),
|
|
59
|
+
),
|
|
60
|
+
).toEqual([
|
|
61
|
+
HEAD,
|
|
62
|
+
" · not on for this project — the skills and hooks below are init's links and commands. `npx paperlint init --plugin` turns it on",
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("init's links or hooks beside it: named, with the one command that removes them", () => {
|
|
67
|
+
const remedy =
|
|
68
|
+
" `npx paperlint init --plugin` removes the old ones and keeps the plugin";
|
|
69
|
+
expect([
|
|
70
|
+
pluginLines(facts({ oldLinks: ["a", "b"] })).slice(2),
|
|
71
|
+
pluginLines(facts({ oldHooks: ["h"] })).slice(2),
|
|
72
|
+
]).toEqual([
|
|
73
|
+
[
|
|
74
|
+
" ⚠ init's own skill links (a, b) are still here beside the plugin — each such skill is listed twice, each such hook runs twice",
|
|
75
|
+
remedy,
|
|
76
|
+
],
|
|
77
|
+
[
|
|
78
|
+
" ⚠ init's own hook commands (h) are still here beside the plugin — each such skill is listed twice, each such hook runs twice",
|
|
79
|
+
remedy,
|
|
80
|
+
],
|
|
81
|
+
]);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("a version that is not the installed one: which side is behind, and its command; unknown, nothing", () => {
|
|
85
|
+
const behind = pluginLines(facts({ installed: "1.3.0" })).slice(2);
|
|
86
|
+
const ahead = pluginLines(facts({ installed: "1.1.0" })).slice(2);
|
|
87
|
+
expect([
|
|
88
|
+
behind,
|
|
89
|
+
ahead,
|
|
90
|
+
pluginLines(facts({ installed: null })).slice(2),
|
|
91
|
+
]).toEqual([
|
|
92
|
+
[
|
|
93
|
+
" ⚠ the plugin is 1.2.0, the installed paperlint is 1.3.0 — its skills and hooks describe another version",
|
|
94
|
+
` \`${PLUGIN_UPDATE}\` brings the plugin to the newest release`,
|
|
95
|
+
],
|
|
96
|
+
[
|
|
97
|
+
" ⚠ the plugin is 1.2.0, the installed paperlint is 1.1.0 — its skills and hooks describe another version",
|
|
98
|
+
" the package is behind: install paperlint@1.2.0 in this project",
|
|
99
|
+
],
|
|
100
|
+
[],
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `paperlint doctor`'s plugin section. Once the Claude Code plugin is on it carries the skills and the
|
|
3
|
+
* hooks, so a project without init's links and hook commands is complete — and one that has BOTH lists
|
|
4
|
+
* every skill twice and runs every hook twice, which is the first thing this section warns about. The
|
|
5
|
+
* second is a plugin whose version is not the installed package's: the plugin's skills and hooks then
|
|
6
|
+
* describe a different paperlint than the one `npx paperlint` runs.
|
|
7
|
+
*/
|
|
8
|
+
import type { PluginState } from "./ports/claude-code.ts";
|
|
9
|
+
|
|
10
|
+
export const PLUGIN_UPDATE =
|
|
11
|
+
"claude plugin update paperlint@paperlint --scope project";
|
|
12
|
+
|
|
13
|
+
/** -1, 0 or 1 by the dotted numbers of two versions; a pre-release tag is ignored. */
|
|
14
|
+
export function compareVersions(a: string, b: string): number {
|
|
15
|
+
// A missing part reads as "undefined", which parses to NaN, which counts as 0.
|
|
16
|
+
const part = (v: string, k: number): number =>
|
|
17
|
+
Number.parseInt(String(v.split("-", 1).join("").split(".")[k]), 10) || 0;
|
|
18
|
+
return (
|
|
19
|
+
[0, 1, 2]
|
|
20
|
+
.map((k) => Math.sign(part(a, k) - part(b, k)))
|
|
21
|
+
.find((d) => d !== 0) ?? 0
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface PluginFacts {
|
|
26
|
+
readonly state: PluginState;
|
|
27
|
+
/** The paperlint this doctor is, as installed in the project; null when unknown. */
|
|
28
|
+
readonly installed: string | null;
|
|
29
|
+
/** init's skill links still in `.claude/skills/`. */
|
|
30
|
+
readonly oldLinks: readonly string[];
|
|
31
|
+
/** The hooks init's own commands still run from `.claude/settings.json`. */
|
|
32
|
+
readonly oldHooks: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const versionLine = (
|
|
36
|
+
plugin: string,
|
|
37
|
+
installed: string | null,
|
|
38
|
+
): readonly string[] => {
|
|
39
|
+
if (installed === null) return [];
|
|
40
|
+
const order = compareVersions(plugin, installed);
|
|
41
|
+
if (order === 0) return [];
|
|
42
|
+
return [
|
|
43
|
+
` ⚠ the plugin is ${plugin}, the installed paperlint is ${installed} — its skills and hooks describe another version`,
|
|
44
|
+
order < 0
|
|
45
|
+
? ` \`${PLUGIN_UPDATE}\` brings the plugin to the newest release`
|
|
46
|
+
: ` the package is behind: install paperlint@${plugin} in this project`,
|
|
47
|
+
];
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const doubled = (f: PluginFacts): readonly string[] => {
|
|
51
|
+
const what = [
|
|
52
|
+
f.oldLinks.length > 0 ? `skill links (${f.oldLinks.join(", ")})` : null,
|
|
53
|
+
f.oldHooks.length > 0 ? `hook commands (${f.oldHooks.join(", ")})` : null,
|
|
54
|
+
].filter((w): w is string => w !== null);
|
|
55
|
+
return what.length === 0
|
|
56
|
+
? []
|
|
57
|
+
: [
|
|
58
|
+
` ⚠ init's own ${what.join(" and ")} are still here beside the plugin — each such skill is listed twice, each such hook runs twice`,
|
|
59
|
+
` \`npx paperlint init --plugin\` removes the old ones and keeps the plugin`,
|
|
60
|
+
];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** The section: a header and its lines. */
|
|
64
|
+
export function pluginLines(f: PluginFacts): readonly string[] {
|
|
65
|
+
const head = "Claude Code plugin (carries the skills and the hooks)";
|
|
66
|
+
if (!f.state.enabled)
|
|
67
|
+
return [
|
|
68
|
+
head,
|
|
69
|
+
" · not on for this project — the skills and hooks below are init's links and commands. `npx paperlint init --plugin` turns it on",
|
|
70
|
+
];
|
|
71
|
+
// Declared but not installed: the keys alone load nothing, so init's links are not doubled.
|
|
72
|
+
if (f.state.version === null)
|
|
73
|
+
return [
|
|
74
|
+
head,
|
|
75
|
+
" · declared in the settings, not installed — the skills and hooks below are init's links and commands until `npx paperlint init --plugin` runs where `claude` is on PATH",
|
|
76
|
+
];
|
|
77
|
+
return [
|
|
78
|
+
head,
|
|
79
|
+
` ✓ on for this project, version ${f.state.version}`,
|
|
80
|
+
...doubled(f),
|
|
81
|
+
...versionLine(f.state.version, f.installed),
|
|
82
|
+
];
|
|
83
|
+
}
|
package/src/doctor.test.ts
CHANGED
|
@@ -14,8 +14,8 @@ import {
|
|
|
14
14
|
import { tmpdir } from "node:os";
|
|
15
15
|
import { join } from "node:path";
|
|
16
16
|
import { test } from "vitest";
|
|
17
|
-
import { detectPapers, doctor } from "./doctor.ts";
|
|
18
|
-
import { shippedWiring } from "./hooks-settings.ts";
|
|
17
|
+
import { detectPapers, doctor, type DoctorOptions } from "./doctor.ts";
|
|
18
|
+
import { MANAGED_BY, shippedWiring } from "./hooks-settings.ts";
|
|
19
19
|
|
|
20
20
|
const project = (): string =>
|
|
21
21
|
realpathSync(mkdtempSync(join(tmpdir(), "doctor-")));
|
|
@@ -104,6 +104,115 @@ test("doctor exits non-zero when the hooks are only partly wired", () => {
|
|
|
104
104
|
assert.equal(exitWithHooks([hookCommand("paper-edit-guard")]), 2);
|
|
105
105
|
});
|
|
106
106
|
|
|
107
|
+
/** Doctor's output for a project with one of init's hook commands and one present skill link. */
|
|
108
|
+
const withPlugin = (plugin: NonNullable<DoctorOptions["plugin"]> | null) => {
|
|
109
|
+
const root = project();
|
|
110
|
+
writeFileSync(join(root, "paperlint.json"), "{}\n");
|
|
111
|
+
mkdirSync(join(root, ".claude"), { recursive: true });
|
|
112
|
+
const ours = `node ${MANAGED_BY} hook ${allHooks[0] ?? ""}`;
|
|
113
|
+
writeFileSync(
|
|
114
|
+
join(root, ".claude", "settings.json"),
|
|
115
|
+
JSON.stringify({
|
|
116
|
+
hooks: {
|
|
117
|
+
PreToolUse: [
|
|
118
|
+
{ matcher: "Bash", hooks: [{ type: "command", command: ours }] },
|
|
119
|
+
],
|
|
120
|
+
},
|
|
121
|
+
}),
|
|
122
|
+
);
|
|
123
|
+
const lines: string[] = [];
|
|
124
|
+
const code = doctor({
|
|
125
|
+
cwd: root,
|
|
126
|
+
log: (s: string) => lines.push(s),
|
|
127
|
+
run: () => ({ status: 0 }),
|
|
128
|
+
cliPapers: join(root, "papers"),
|
|
129
|
+
plugin,
|
|
130
|
+
installed: "1.0.0",
|
|
131
|
+
skillLinks: () => ({
|
|
132
|
+
ok: true,
|
|
133
|
+
home: join(root, ".claude", "skills"),
|
|
134
|
+
example: null,
|
|
135
|
+
links: [{ name: "paper-pipeline", status: "present" }],
|
|
136
|
+
}),
|
|
137
|
+
});
|
|
138
|
+
return { code, out: lines.join("\n").split("\n") };
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
test("doctor and the plugin: on, it carries the skills and hooks and names init's leftovers; off, it says so; no Claude Code, no section", () => {
|
|
142
|
+
const on = withPlugin({ enabled: true, version: "1.0.0" });
|
|
143
|
+
const off = withPlugin({ enabled: false, version: null });
|
|
144
|
+
const none = withPlugin(null);
|
|
145
|
+
const head = "Claude Code plugin (carries the skills and the hooks)";
|
|
146
|
+
// A partly wired set fails the run without the plugin, and not with it: the plugin carries the hooks.
|
|
147
|
+
assert.deepEqual([on.code, off.code, none.code], [0, 2, 2]);
|
|
148
|
+
assert.deepEqual(
|
|
149
|
+
on.out.slice(on.out.indexOf(head), on.out.indexOf(head) + 4),
|
|
150
|
+
[
|
|
151
|
+
head,
|
|
152
|
+
" ✓ on for this project, version 1.0.0",
|
|
153
|
+
` ⚠ init's own skill links (paper-pipeline) and hook commands (${allHooks[0] ?? ""}) are still here beside the plugin — each such skill is listed twice, each such hook runs twice`,
|
|
154
|
+
" `npx paperlint init --plugin` removes the old ones and keeps the plugin",
|
|
155
|
+
],
|
|
156
|
+
);
|
|
157
|
+
assert.equal(
|
|
158
|
+
on.out.filter((l) => l === " ✓ carried by the plugin").length,
|
|
159
|
+
2,
|
|
160
|
+
);
|
|
161
|
+
assert.deepEqual(
|
|
162
|
+
[off.out.includes(head), none.out.includes(head)],
|
|
163
|
+
[true, false],
|
|
164
|
+
);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
test("doctor with the plugin declared but not installed: the hooks are checked as without it", () => {
|
|
168
|
+
const declared = withPlugin({ enabled: true, version: null });
|
|
169
|
+
const off = withPlugin({ enabled: false, version: null });
|
|
170
|
+
// The keys alone load nothing: a partly wired set fails the run, and nothing is "carried".
|
|
171
|
+
assert.deepEqual(
|
|
172
|
+
[
|
|
173
|
+
declared.code,
|
|
174
|
+
declared.out.filter((l) => l === " ✓ carried by the plugin").length,
|
|
175
|
+
],
|
|
176
|
+
[off.code, 0],
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test("doctor with the plugin on and settings that do not parse, or cannot be read: no leftovers named, the run not failed", () => {
|
|
181
|
+
const onWith = (settings: (root: string) => void) => {
|
|
182
|
+
const root = project();
|
|
183
|
+
writeFileSync(join(root, "paperlint.json"), "{}\n");
|
|
184
|
+
mkdirSync(join(root, ".claude"), { recursive: true });
|
|
185
|
+
settings(root);
|
|
186
|
+
const lines: string[] = [];
|
|
187
|
+
const code = doctor({
|
|
188
|
+
cwd: root,
|
|
189
|
+
log: (s: string) => lines.push(s),
|
|
190
|
+
run: () => ({ status: 0 }),
|
|
191
|
+
cliPapers: join(root, "papers"),
|
|
192
|
+
plugin: { enabled: true, version: "1.0.0" },
|
|
193
|
+
skillLinks: () => ({ ok: false, error: "not resolved" }),
|
|
194
|
+
});
|
|
195
|
+
const out = lines.join("\n").split("\n");
|
|
196
|
+
const at = out.indexOf(
|
|
197
|
+
"Claude Code plugin (carries the skills and the hooks)",
|
|
198
|
+
);
|
|
199
|
+
return [code, out.slice(at + 1, at + 3)];
|
|
200
|
+
};
|
|
201
|
+
const quiet = [0, [" ✓ on for this project, version 1.0.0", ""]];
|
|
202
|
+
assert.deepEqual(
|
|
203
|
+
[
|
|
204
|
+
onWith((root) => {
|
|
205
|
+
writeFileSync(join(root, ".claude", "settings.json"), "{ nope");
|
|
206
|
+
}),
|
|
207
|
+
// A DIRECTORY where the file should be: reading it throws EISDIR.
|
|
208
|
+
onWith((root) => {
|
|
209
|
+
mkdirSync(join(root, ".claude", "settings.json"));
|
|
210
|
+
}),
|
|
211
|
+
],
|
|
212
|
+
[quiet, quiet],
|
|
213
|
+
);
|
|
214
|
+
});
|
|
215
|
+
|
|
107
216
|
test("doctor exits non-zero when a hook is wired twice", () => {
|
|
108
217
|
const commands = [
|
|
109
218
|
...allHooks.map(hookCommand),
|
package/src/doctor.ts
CHANGED
|
@@ -35,7 +35,10 @@ import {
|
|
|
35
35
|
} from "../hooks/paper-edit-guard.hook.mjs";
|
|
36
36
|
import { PAPER_MARKERS } from "./build.ts";
|
|
37
37
|
import { linkSkills, SKILLS_HOME, type LinkReport } from "./link-skills.ts";
|
|
38
|
-
import { doctorHooks } from "./hooks-settings.ts";
|
|
38
|
+
import { doctorHooks, initWiredHooks } from "./hooks-settings.ts";
|
|
39
|
+
import { pluginLines } from "./doctor-plugin.ts";
|
|
40
|
+
import { installedPluginVersion } from "./plugin-offer.ts";
|
|
41
|
+
import type { PluginState } from "./ports/claude-code.ts";
|
|
39
42
|
import { messageOf } from "./domain/text.ts";
|
|
40
43
|
import { fieldOf } from "./domain/record.ts";
|
|
41
44
|
|
|
@@ -240,6 +243,61 @@ function papersVerdict(
|
|
|
240
243
|
return { lines: out, bad };
|
|
241
244
|
}
|
|
242
245
|
|
|
246
|
+
/** The hooks init's own commands run; none when they cannot be read (the plugin carries them anyway). */
|
|
247
|
+
function oldHooksOf(root: string): readonly string[] {
|
|
248
|
+
try {
|
|
249
|
+
return initWiredHooks(root);
|
|
250
|
+
} catch {
|
|
251
|
+
return [];
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/** init's skill links that lead to the shipped skill. */
|
|
256
|
+
const presentLinks = (links: LinkReport): readonly string[] =>
|
|
257
|
+
links.ok
|
|
258
|
+
? links.links.filter((l) => l.status === "present").map((l) => l.name)
|
|
259
|
+
: [];
|
|
260
|
+
|
|
261
|
+
/** The skills section; the plugin, when it is on, carries them. */
|
|
262
|
+
function skillsLines(links: LinkReport, on: boolean): readonly string[] {
|
|
263
|
+
const head = `skills (Claude Code finds project skills only in ${SKILLS_HOME}/)`;
|
|
264
|
+
if (on) return [head, ` ✓ carried by the plugin`];
|
|
265
|
+
if (!links.ok) return [head, ` ⚠ not checked — ${links.error}`];
|
|
266
|
+
const gaps = links.links.filter((l) => l.status !== "present");
|
|
267
|
+
const total = String(links.links.length);
|
|
268
|
+
const as = join(SKILLS_HOME, "<name>");
|
|
269
|
+
return gaps.length === 0
|
|
270
|
+
? [head, ` ✓ all ${total} shipped skills are reachable as ${as}`]
|
|
271
|
+
: [
|
|
272
|
+
head,
|
|
273
|
+
` ⚠ ${String(gaps.length)} of ${total} shipped skills are NOT reachable as ${as}:`,
|
|
274
|
+
...gaps.map(
|
|
275
|
+
(g) =>
|
|
276
|
+
` ${g.name} — ${g.status === "missing" ? "not linked" : `${g.reason ?? "occupied"}, not the shipped skill`}`,
|
|
277
|
+
),
|
|
278
|
+
` \`npx paperlint init\` links the missing ones; it never replaces an entry it did not make`,
|
|
279
|
+
];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 🔴 THE HOOKS ARE READ FROM THE FILE THAT CARRIES THEM. Until `init` wrote them into
|
|
284
|
+
* `.claude/settings.json`, the only carrier was a plugin and this section said "cannot be checked
|
|
285
|
+
* from a terminal". Hooks wired NOT AT ALL are advisory, like the skills: `--no-hooks` is a choice,
|
|
286
|
+
* not a fault. Partly wired, or wired twice, is a fault and fails the run — unless the plugin is on,
|
|
287
|
+
* which carries them.
|
|
288
|
+
*/
|
|
289
|
+
function hooksSection(
|
|
290
|
+
root: string,
|
|
291
|
+
on: boolean,
|
|
292
|
+
): { readonly lines: readonly string[]; readonly bad: number } {
|
|
293
|
+
if (on) return { lines: [`hooks`, ` ✓ carried by the plugin`], bad: 0 };
|
|
294
|
+
try {
|
|
295
|
+
return doctorHooks(root);
|
|
296
|
+
} catch (e) {
|
|
297
|
+
return { lines: [`hooks`, ` ⚠ not checked — ${messageOf(e)}`], bad: 0 };
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
243
301
|
export interface DoctorOptions {
|
|
244
302
|
log?: typeof console.log;
|
|
245
303
|
cwd?: string;
|
|
@@ -250,6 +308,10 @@ export interface DoctorOptions {
|
|
|
250
308
|
cliPapers?: string | null;
|
|
251
309
|
/** Reads the skill links without writing any. Injected only so a test can fake the install. */
|
|
252
310
|
skillLinks?: (root: string) => LinkReport;
|
|
311
|
+
/** The Claude Code plugin in this project, as the CLI read it; null where Claude Code is not. */
|
|
312
|
+
plugin?: PluginState | null;
|
|
313
|
+
/** The installed paperlint's version, compared with the plugin's; null skips the comparison. */
|
|
314
|
+
installed?: string | null;
|
|
253
315
|
}
|
|
254
316
|
|
|
255
317
|
/**
|
|
@@ -267,6 +329,8 @@ export function doctor({
|
|
|
267
329
|
run = spawnSync,
|
|
268
330
|
cliPapers = null,
|
|
269
331
|
skillLinks = (r: string) => linkSkills(r, { write: false }),
|
|
332
|
+
plugin = null,
|
|
333
|
+
installed = null,
|
|
270
334
|
}: DoctorOptions = {}): number {
|
|
271
335
|
const root = projectDir ?? cwd;
|
|
272
336
|
const configPath = join(root, CONFIG_FILE);
|
|
@@ -301,32 +365,24 @@ export function doctor({
|
|
|
301
365
|
// work without it, and an entry of the same name that `init` refused to replace is the
|
|
302
366
|
// consumer's own decision. What this section removes is the silence — before it, a consumer
|
|
303
367
|
// without links had no `/paper-pipeline` and nothing anywhere said so.
|
|
368
|
+
const links = skillLinks(root);
|
|
369
|
+
// Without Claude Code there is no plugin to speak of, so no section at all.
|
|
370
|
+
const on = installedPluginVersion(plugin ?? null) !== null;
|
|
304
371
|
out.push(
|
|
372
|
+
...(plugin
|
|
373
|
+
? [
|
|
374
|
+
"",
|
|
375
|
+
...pluginLines({
|
|
376
|
+
state: plugin,
|
|
377
|
+
installed,
|
|
378
|
+
oldLinks: presentLinks(links),
|
|
379
|
+
oldHooks: on ? oldHooksOf(root) : [],
|
|
380
|
+
}),
|
|
381
|
+
]
|
|
382
|
+
: []),
|
|
305
383
|
"",
|
|
306
|
-
|
|
384
|
+
...skillsLines(links, on),
|
|
307
385
|
);
|
|
308
|
-
const links = skillLinks(root);
|
|
309
|
-
if (!links.ok) out.push(` ⚠ not checked — ${links.error}`);
|
|
310
|
-
else {
|
|
311
|
-
const gaps = links.links.filter((l) => l.status !== "present");
|
|
312
|
-
const total = String(links.links.length);
|
|
313
|
-
if (gaps.length === 0)
|
|
314
|
-
out.push(
|
|
315
|
-
` ✓ all ${total} shipped skills are reachable as ${join(SKILLS_HOME, "<name>")}`,
|
|
316
|
-
);
|
|
317
|
-
else {
|
|
318
|
-
out.push(
|
|
319
|
-
` ⚠ ${String(gaps.length)} of ${total} shipped skills are NOT reachable as ${join(SKILLS_HOME, "<name>")}:`,
|
|
320
|
-
);
|
|
321
|
-
for (const g of gaps)
|
|
322
|
-
out.push(
|
|
323
|
-
` ${g.name} — ${g.status === "missing" ? "not linked" : `${g.reason ?? "occupied"}, not the shipped skill`}`,
|
|
324
|
-
);
|
|
325
|
-
out.push(
|
|
326
|
-
` \`npx paperlint init\` links the missing ones; it never replaces an entry it did not make`,
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
386
|
|
|
331
387
|
out.push(
|
|
332
388
|
"",
|
|
@@ -344,14 +400,9 @@ export function doctor({
|
|
|
344
400
|
// `.claude/settings.json`, the only carrier was a plugin and this section said "cannot be
|
|
345
401
|
// checked from a terminal". Hooks wired NOT AT ALL are advisory, like the skills: `--no-hooks`
|
|
346
402
|
// is a choice, not a fault. Partly wired, or wired twice, is a fault and fails the run.
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
out.push(...hooks.lines);
|
|
351
|
-
bad += hooks.bad;
|
|
352
|
-
} catch (e) {
|
|
353
|
-
out.push(`hooks`, ` ⚠ not checked — ${messageOf(e)}`);
|
|
354
|
-
}
|
|
403
|
+
const hooks = hooksSection(root, on);
|
|
404
|
+
out.push("", ...hooks.lines);
|
|
405
|
+
bad += hooks.bad;
|
|
355
406
|
out.push("");
|
|
356
407
|
log(out.join("\n"));
|
|
357
408
|
return bad > 0 ? 2 : 0;
|
package/src/hooks-notice.test.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
noticeText,
|
|
22
22
|
} from "./hooks-notice.ts";
|
|
23
23
|
import { WIRING_FILE } from "./hooks-settings.ts";
|
|
24
|
+
import type { ClaudeCode } from "./ports/claude-code.ts";
|
|
24
25
|
|
|
25
26
|
const root = useTempDir("hooks-notice-");
|
|
26
27
|
|
|
@@ -65,6 +66,25 @@ function project(name: string, settings: string | null, long = false): string {
|
|
|
65
66
|
return dir;
|
|
66
67
|
}
|
|
67
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Claude Code with the plugin off, whatever the machine running the tests has: the default reads the
|
|
71
|
+
* user's own settings, and a developer with the plugin on would see every notice go quiet.
|
|
72
|
+
*/
|
|
73
|
+
const PLUGIN_OFF: ClaudeCode = {
|
|
74
|
+
present: () => true,
|
|
75
|
+
plugin: () => ({ enabled: false, version: null }),
|
|
76
|
+
enable: () => ({ ok: false, reason: "not in this test" }),
|
|
77
|
+
};
|
|
78
|
+
const PLUGIN_ON: ClaudeCode = {
|
|
79
|
+
...PLUGIN_OFF,
|
|
80
|
+
plugin: () => ({ enabled: true, version: "9.9.9" }),
|
|
81
|
+
};
|
|
82
|
+
/** Declared in the settings, never installed: the keys alone load nothing. */
|
|
83
|
+
const PLUGIN_DECLARED: ClaudeCode = {
|
|
84
|
+
...PLUGIN_OFF,
|
|
85
|
+
plugin: () => ({ enabled: true, version: null }),
|
|
86
|
+
};
|
|
87
|
+
|
|
68
88
|
/** `paperlint hook <name>` in-process on an Edit of `file`. */
|
|
69
89
|
// eslint-disable-next-line max-params -- a test helper: the hook, the project, the edit and the version
|
|
70
90
|
async function hook(
|
|
@@ -90,6 +110,7 @@ async function hook(
|
|
|
90
110
|
err.push(m);
|
|
91
111
|
},
|
|
92
112
|
projectDir: dir,
|
|
113
|
+
claude: PLUGIN_OFF,
|
|
93
114
|
version,
|
|
94
115
|
...(skillLinks === undefined ? {} : { skillLinks }),
|
|
95
116
|
});
|
|
@@ -229,6 +250,7 @@ test("paperlint lint: one stderr line naming the missing hooks when partly wired
|
|
|
229
250
|
log: () => undefined,
|
|
230
251
|
err: (...a: unknown[]) => err.push(a.join(" ")),
|
|
231
252
|
cwd: dir,
|
|
253
|
+
claude: PLUGIN_OFF,
|
|
232
254
|
});
|
|
233
255
|
return { code, err: err.filter((l) => /not wired|unwired/.test(l)) };
|
|
234
256
|
};
|
|
@@ -259,6 +281,7 @@ test("a spawned PostToolUse hook: its stdout is captured and merged, its payload
|
|
|
259
281
|
out.push(t);
|
|
260
282
|
},
|
|
261
283
|
projectDir: dir,
|
|
284
|
+
claude: PLUGIN_OFF,
|
|
262
285
|
version: "9.9.9",
|
|
263
286
|
run: (_f, _a, o) => {
|
|
264
287
|
seen.push(o);
|
|
@@ -342,6 +365,7 @@ test("the check that cannot run, and a payload that cannot be read, leave the ho
|
|
|
342
365
|
out: () => undefined,
|
|
343
366
|
err: (m: string) => void said.push(m),
|
|
344
367
|
projectDir: dir,
|
|
368
|
+
claude: PLUGIN_OFF,
|
|
345
369
|
version: "9.9.9",
|
|
346
370
|
});
|
|
347
371
|
assert.equal(garbled, 0);
|
|
@@ -358,6 +382,7 @@ test("the check that cannot run, and a payload that cannot be read, leave the ho
|
|
|
358
382
|
out: () => undefined,
|
|
359
383
|
err: (m: string) => void thrown.push(m),
|
|
360
384
|
projectDir: dir,
|
|
385
|
+
claude: PLUGIN_OFF,
|
|
361
386
|
version: "9.9.9",
|
|
362
387
|
});
|
|
363
388
|
assert.equal(unread, 0);
|
|
@@ -411,11 +436,13 @@ test("paperlint lint: a settings file it cannot read is no second finding — th
|
|
|
411
436
|
log: () => undefined,
|
|
412
437
|
err: (...a: unknown[]) => void err.push(a.join(" ")),
|
|
413
438
|
cwd: dir,
|
|
439
|
+
claude: PLUGIN_OFF,
|
|
414
440
|
});
|
|
415
441
|
const clean = await run(["lint"], {
|
|
416
442
|
log: () => undefined,
|
|
417
443
|
err: () => undefined,
|
|
418
444
|
cwd: project("lint-unreadable-control", null),
|
|
445
|
+
claude: PLUGIN_OFF,
|
|
419
446
|
});
|
|
420
447
|
assert.equal(code, clean);
|
|
421
448
|
assert.deepEqual(
|
|
@@ -511,6 +538,7 @@ test("paperlint lint: one stderr line names the unlinked skills, and none when t
|
|
|
511
538
|
log: () => undefined,
|
|
512
539
|
err: (...a: unknown[]) => err.push(a.join(" ")),
|
|
513
540
|
cwd: dir,
|
|
541
|
+
claude: PLUGIN_OFF,
|
|
514
542
|
skillLinks,
|
|
515
543
|
});
|
|
516
544
|
return { code, err: err.filter((l) => /not linked|not wired/.test(l)) };
|
|
@@ -547,3 +575,57 @@ test("lintLine and noticeText word skills beside hooks", () => {
|
|
|
547
575
|
/skills that are not linked into \.claude\/skills\/: a\./,
|
|
548
576
|
);
|
|
549
577
|
});
|
|
578
|
+
|
|
579
|
+
test("the plugin on: a partly wired project with unlinked skills hears nothing, from the hook or from lint", async () => {
|
|
580
|
+
const dir = project("plugin-on", wiringWithout(["lint-edited"]));
|
|
581
|
+
const unlinked = linked(["rewrite-unclear", "missing"]);
|
|
582
|
+
// The hook speaks once per version, so the declared plugin gets a project of its own.
|
|
583
|
+
const declaredDir = project(
|
|
584
|
+
"plugin-declared",
|
|
585
|
+
wiringWithout(["lint-edited"]),
|
|
586
|
+
);
|
|
587
|
+
const hooked = async (claude: ClaudeCode, at = dir) => {
|
|
588
|
+
const out: string[] = [];
|
|
589
|
+
await runHook("lint-edited", {
|
|
590
|
+
stdin: () =>
|
|
591
|
+
JSON.stringify({
|
|
592
|
+
tool_name: "Edit",
|
|
593
|
+
tool_input: {
|
|
594
|
+
file_path: join(at, "papers/p/paper.tex"),
|
|
595
|
+
new_string: "Fine.",
|
|
596
|
+
},
|
|
597
|
+
}),
|
|
598
|
+
out: (t) => void out.push(t),
|
|
599
|
+
err: () => undefined,
|
|
600
|
+
projectDir: at,
|
|
601
|
+
version: "7.7.7",
|
|
602
|
+
skillLinks: unlinked,
|
|
603
|
+
claude,
|
|
604
|
+
});
|
|
605
|
+
return out.join("").includes("additionalContext");
|
|
606
|
+
};
|
|
607
|
+
const linted = async (claude: ClaudeCode) => {
|
|
608
|
+
const err: string[] = [];
|
|
609
|
+
await run(["lint"], {
|
|
610
|
+
log: () => undefined,
|
|
611
|
+
err: (...a: unknown[]) => err.push(a.join(" ")),
|
|
612
|
+
cwd: dir,
|
|
613
|
+
skillLinks: unlinked,
|
|
614
|
+
claude,
|
|
615
|
+
});
|
|
616
|
+
return err.filter((l) => l.includes("npx paperlint init"));
|
|
617
|
+
};
|
|
618
|
+
// Both halves: the same project with the plugin off speaks, so the silence is the plugin's.
|
|
619
|
+
// A plugin only declared carries nothing, so it speaks as off does.
|
|
620
|
+
assert.deepEqual(
|
|
621
|
+
[
|
|
622
|
+
await hooked(PLUGIN_ON),
|
|
623
|
+
await linted(PLUGIN_ON),
|
|
624
|
+
await hooked(PLUGIN_OFF),
|
|
625
|
+
(await linted(PLUGIN_OFF)).length,
|
|
626
|
+
await hooked(PLUGIN_DECLARED, declaredDir),
|
|
627
|
+
(await linted(PLUGIN_DECLARED)).length,
|
|
628
|
+
],
|
|
629
|
+
[false, [], true, 1, true, 1],
|
|
630
|
+
);
|
|
631
|
+
});
|
package/src/hooks-settings.ts
CHANGED
|
@@ -321,6 +321,55 @@ export function wireHooks(
|
|
|
321
321
|
return { status: "written", path, names: wiring.names };
|
|
322
322
|
}
|
|
323
323
|
|
|
324
|
+
/**
|
|
325
|
+
* Removes the hook commands `init` wrote (the MANAGED_BY spelling) once the Claude Code plugin carries
|
|
326
|
+
* the hooks; the project's own commands stay. vigiles' merge does it: measured 2026-11-22, a merge
|
|
327
|
+
* whose map names each event with no entries drops exactly the managed commands of those events.
|
|
328
|
+
*/
|
|
329
|
+
export function unwireHooks(
|
|
330
|
+
root: string,
|
|
331
|
+
merge: Merge,
|
|
332
|
+
wiring: Wiring = shippedWiring(),
|
|
333
|
+
):
|
|
334
|
+
| {
|
|
335
|
+
readonly status: "removed";
|
|
336
|
+
readonly path: string;
|
|
337
|
+
readonly names: readonly string[];
|
|
338
|
+
}
|
|
339
|
+
| { readonly status: "none" }
|
|
340
|
+
| {
|
|
341
|
+
readonly status: "unparsable";
|
|
342
|
+
readonly path: string;
|
|
343
|
+
readonly reason: string;
|
|
344
|
+
} {
|
|
345
|
+
const read = readSettings(root);
|
|
346
|
+
if (read.status === "unparsable") return read;
|
|
347
|
+
const names = initWiredHooks(root, wiring);
|
|
348
|
+
if (names.length === 0) return { status: "none" };
|
|
349
|
+
const none = Object.fromEntries(
|
|
350
|
+
Object.keys(wiring.compiled).map((event) => [event, []]),
|
|
351
|
+
);
|
|
352
|
+
writeFileSync(
|
|
353
|
+
read.path,
|
|
354
|
+
`${JSON.stringify(merge(read.settings, none, MANAGED_BY), null, 2)}\n`,
|
|
355
|
+
"utf8",
|
|
356
|
+
);
|
|
357
|
+
return { status: "removed", path: read.path, names };
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** The hooks a command of init's own spelling runs; none when the settings file cannot be read. */
|
|
361
|
+
export function initWiredHooks(
|
|
362
|
+
root: string,
|
|
363
|
+
wiring: Wiring = shippedWiring(),
|
|
364
|
+
): readonly string[] {
|
|
365
|
+
const read = readSettings(root);
|
|
366
|
+
return read.status === "unparsable"
|
|
367
|
+
? []
|
|
368
|
+
: wiredCounts(read.settings, wiring.names)
|
|
369
|
+
.filter((c) => c.ours > 0)
|
|
370
|
+
.map((c) => c.name);
|
|
371
|
+
}
|
|
372
|
+
|
|
324
373
|
/** The consequence every report of a written hook must carry, in one place. */
|
|
325
374
|
export const FRESH_CLONE_NOTE = `the commands point into node_modules/${PACKAGE_NAME}/ — in a fresh clone they cannot run until \`npm install\` has run there`;
|
|
326
375
|
|