paperlint 18.7.0 → 18.9.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 +5 -6
- 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 +44 -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 +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/docs/website.md +11 -9
- package/hooks/CLAUDE.md +2 -2
- package/hooks/CLAUDE.md.spec.ts +1 -1
- package/lib/skill-checks.mjs +6 -7
- package/package.json +5 -2
- 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 +67 -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.ts +225 -64
- package/src/link-skills.test.ts +34 -1
- package/src/link-skills.ts +34 -0
- package/src/lint-edited-site-example.test.ts +95 -0
- package/src/paper-includes.test.ts +7 -1
- 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,233 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { absolutePath } from "../../domain/paths.ts";
|
|
5
|
+
import { useTempDir, writeTree } from "../../../test/support.ts";
|
|
6
|
+
import {
|
|
7
|
+
ENABLE_COMMANDS,
|
|
8
|
+
PLUGIN_ID,
|
|
9
|
+
claudeCode,
|
|
10
|
+
configDirOf,
|
|
11
|
+
enabledBy,
|
|
12
|
+
installedVersion,
|
|
13
|
+
onPath,
|
|
14
|
+
runInherit,
|
|
15
|
+
} from "./index.ts";
|
|
16
|
+
|
|
17
|
+
const on = { enabledPlugins: { "paperlint@paperlint": true } };
|
|
18
|
+
const off = { enabledPlugins: { "paperlint@paperlint": false } };
|
|
19
|
+
|
|
20
|
+
describe("what Claude Code's files say about the plugin", () => {
|
|
21
|
+
it("the most specific file that names it decides; none is off", () => {
|
|
22
|
+
expect([
|
|
23
|
+
enabledBy([undefined, on, off]),
|
|
24
|
+
enabledBy([off, on]),
|
|
25
|
+
enabledBy([{ enabledPlugins: { other: true } }, undefined]),
|
|
26
|
+
enabledBy([]),
|
|
27
|
+
]).toEqual([true, false, false, false]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("the installed version: this project's entry, else a user one, else none", () => {
|
|
31
|
+
const json = (entries: unknown) => ({
|
|
32
|
+
plugins: { "paperlint@paperlint": entries },
|
|
33
|
+
});
|
|
34
|
+
expect([
|
|
35
|
+
installedVersion(
|
|
36
|
+
json([
|
|
37
|
+
{ scope: "user", version: "1.0.0" },
|
|
38
|
+
{ scope: "project", projectPath: "/p", version: "2.0.0" },
|
|
39
|
+
]),
|
|
40
|
+
"/p",
|
|
41
|
+
),
|
|
42
|
+
installedVersion(json([{ scope: "user", version: "1.0.0" }]), "/p"),
|
|
43
|
+
installedVersion(json([{ scope: "project", projectPath: "/q" }]), "/p"),
|
|
44
|
+
installedVersion(json("not a list"), "/p"),
|
|
45
|
+
installedVersion(undefined, "/p"),
|
|
46
|
+
]).toEqual(["2.0.0", "1.0.0", null, null, null]);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const setup = (tree: Record<string, string>, hasClaude: boolean) => {
|
|
51
|
+
const dir = useTempDir("paperlint-claude-");
|
|
52
|
+
writeTree(dir, tree);
|
|
53
|
+
const ran: string[] = [];
|
|
54
|
+
const cc = claudeCode({
|
|
55
|
+
configDir: join(dir, "home", ".claude"),
|
|
56
|
+
hasClaude: () => hasClaude,
|
|
57
|
+
run: (argv, cwd) => (ran.push(`${cwd}: ${argv.join(" ")}`), 0),
|
|
58
|
+
});
|
|
59
|
+
return { root: absolutePath(join(dir, "p")), cc, ran };
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
describe("claudeCode — reading the disk", () => {
|
|
63
|
+
it("present: a .claude folder, or claude on PATH", () => {
|
|
64
|
+
const a = setup({ "p/.claude/x": "" }, false);
|
|
65
|
+
const b = setup({ "p/x": "" }, true);
|
|
66
|
+
const c = setup({ "p/x": "" }, false);
|
|
67
|
+
expect([
|
|
68
|
+
a.cc.present(a.root),
|
|
69
|
+
b.cc.present(b.root),
|
|
70
|
+
c.cc.present(c.root),
|
|
71
|
+
]).toEqual([true, true, false]);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("the plugin's state, from the project, the local file, the user's settings and the install record", () => {
|
|
75
|
+
const s = setup(
|
|
76
|
+
{
|
|
77
|
+
"p/.claude/settings.json": JSON.stringify(on),
|
|
78
|
+
"home/.claude/plugins/installed_plugins.json": "{ not json",
|
|
79
|
+
},
|
|
80
|
+
false,
|
|
81
|
+
);
|
|
82
|
+
expect(s.cc.plugin(s.root)).toEqual({ enabled: true, version: null });
|
|
83
|
+
const u = setup(
|
|
84
|
+
{
|
|
85
|
+
"p/.claude/settings.local.json": JSON.stringify(off),
|
|
86
|
+
"home/.claude/settings.json": JSON.stringify(on),
|
|
87
|
+
},
|
|
88
|
+
false,
|
|
89
|
+
);
|
|
90
|
+
expect(u.cc.plugin(u.root)).toEqual({ enabled: false, version: null });
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("where Claude Code keeps the user's settings and plugins", () => {
|
|
95
|
+
it("CLAUDE_CONFIG_DIR when it is set, else ~/.claude", () => {
|
|
96
|
+
expect([
|
|
97
|
+
configDirOf({ CLAUDE_CONFIG_DIR: "/profiles/work" }, "/home/a"),
|
|
98
|
+
configDirOf({}, "/home/a"),
|
|
99
|
+
configDirOf({ CLAUDE_CONFIG_DIR: "" }, "/home/a"),
|
|
100
|
+
]).toEqual([
|
|
101
|
+
"/profiles/work",
|
|
102
|
+
join("/home/a", ".claude"),
|
|
103
|
+
join("/home/a", ".claude"),
|
|
104
|
+
]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("a profile in its own folder: the user's settings and the install record are read from it", () => {
|
|
108
|
+
const dir = useTempDir("paperlint-claude-");
|
|
109
|
+
const root = join(dir, "p");
|
|
110
|
+
writeTree(dir, {
|
|
111
|
+
"p/x": "",
|
|
112
|
+
"profile/settings.json": JSON.stringify(on),
|
|
113
|
+
"profile/plugins/installed_plugins.json": JSON.stringify({
|
|
114
|
+
plugins: {
|
|
115
|
+
[PLUGIN_ID]: [
|
|
116
|
+
{ scope: "project", projectPath: root, version: "2.0.0" },
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
const cc = claudeCode({
|
|
122
|
+
configDir: join(dir, "profile"),
|
|
123
|
+
hasClaude: () => false,
|
|
124
|
+
run: () => 0,
|
|
125
|
+
});
|
|
126
|
+
expect(cc.plugin(absolutePath(root))).toEqual({
|
|
127
|
+
enabled: true,
|
|
128
|
+
version: "2.0.0",
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("claudeCode — turning the plugin on", () => {
|
|
134
|
+
it("claude on PATH: its two commands run in the project, in order", () => {
|
|
135
|
+
const s = setup({ "p/x": "" }, true);
|
|
136
|
+
expect([s.cc.enable(s.root), s.ran]).toEqual([
|
|
137
|
+
{ ok: true, ran: ENABLE_COMMANDS.map((c) => c.join(" ")) },
|
|
138
|
+
ENABLE_COMMANDS.map((c) => `${s.root}: ${c.join(" ")}`),
|
|
139
|
+
]);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("a command that fails stops there, named", () => {
|
|
143
|
+
const dir = useTempDir("paperlint-claude-");
|
|
144
|
+
const cc = claudeCode({
|
|
145
|
+
configDir: join(dir, ".claude"),
|
|
146
|
+
hasClaude: () => true,
|
|
147
|
+
run: () => 1,
|
|
148
|
+
});
|
|
149
|
+
expect(cc.enable(absolutePath(dir))).toEqual({
|
|
150
|
+
ok: false,
|
|
151
|
+
reason:
|
|
152
|
+
"`claude plugin marketplace add zernie/paperlint --scope project` failed",
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("no claude: the keys are written beside the project's own settings", () => {
|
|
157
|
+
const s = setup(
|
|
158
|
+
{ "p/.claude/settings.json": '{"permissions":{"allow":["Bash(ls)"]}}' },
|
|
159
|
+
false,
|
|
160
|
+
);
|
|
161
|
+
const path = join(s.root, ".claude", "settings.json");
|
|
162
|
+
expect([
|
|
163
|
+
s.cc.enable(s.root),
|
|
164
|
+
JSON.parse(readFileSync(path, "utf8")),
|
|
165
|
+
]).toEqual([
|
|
166
|
+
{ ok: true, wrote: path, owed: ENABLE_COMMANDS.map((c) => c.join(" ")) },
|
|
167
|
+
{
|
|
168
|
+
permissions: { allow: ["Bash(ls)"] },
|
|
169
|
+
extraKnownMarketplaces: {
|
|
170
|
+
paperlint: { source: { source: "github", repo: "zernie/paperlint" } },
|
|
171
|
+
},
|
|
172
|
+
enabledPlugins: { "paperlint@paperlint": true },
|
|
173
|
+
},
|
|
174
|
+
]);
|
|
175
|
+
const fresh = setup({ "p/x": "" }, false);
|
|
176
|
+
expect(fresh.cc.enable(fresh.root)).toEqual({
|
|
177
|
+
ok: true,
|
|
178
|
+
wrote: join(fresh.root, ".claude", "settings.json"),
|
|
179
|
+
owed: ENABLE_COMMANDS.map((c) => c.join(" ")),
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("claudeCode — the keys, without claude", () => {
|
|
185
|
+
it("no claude: another plugin and marketplace already declared are kept", () => {
|
|
186
|
+
const s = setup(
|
|
187
|
+
{
|
|
188
|
+
"p/.claude/settings.json": JSON.stringify({
|
|
189
|
+
enabledPlugins: { "other@x": false },
|
|
190
|
+
extraKnownMarketplaces: { x: { source: { source: "git" } } },
|
|
191
|
+
}),
|
|
192
|
+
},
|
|
193
|
+
false,
|
|
194
|
+
);
|
|
195
|
+
s.cc.enable(s.root);
|
|
196
|
+
expect(
|
|
197
|
+
JSON.parse(
|
|
198
|
+
readFileSync(join(s.root, ".claude", "settings.json"), "utf8"),
|
|
199
|
+
),
|
|
200
|
+
).toEqual({
|
|
201
|
+
enabledPlugins: { "other@x": false, "paperlint@paperlint": true },
|
|
202
|
+
extraKnownMarketplaces: {
|
|
203
|
+
x: { source: { source: "git" } },
|
|
204
|
+
paperlint: { source: { source: "github", repo: "zernie/paperlint" } },
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("no claude, and a settings file that is not an object: nothing written, the reason", () => {
|
|
210
|
+
const s = setup({ "p/.claude/settings.json": "[1]" }, false);
|
|
211
|
+
const path = join(s.root, ".claude", "settings.json");
|
|
212
|
+
expect([s.cc.enable(s.root), readFileSync(path, "utf8")]).toEqual([
|
|
213
|
+
{ ok: false, reason: `${path} is not a JSON object` },
|
|
214
|
+
"[1]",
|
|
215
|
+
]);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe("claudeCode — its defaults", () => {
|
|
220
|
+
it("the real defaults: claudeCode() answers, onPath and runInherit run programs", () => {
|
|
221
|
+
const dir = useTempDir("paperlint-claude-");
|
|
222
|
+
writeTree(dir, { ".claude/x": "" });
|
|
223
|
+
const bare = useTempDir("paperlint-claude-bare-");
|
|
224
|
+
expect([
|
|
225
|
+
claudeCode().present(absolutePath(dir)),
|
|
226
|
+
// No `.claude/` here: the answer is whether `claude` runs on this machine.
|
|
227
|
+
claudeCode().present(absolutePath(bare)) === onPath("claude"),
|
|
228
|
+
onPath(process.execPath),
|
|
229
|
+
onPath("paperlint-no-such-program"),
|
|
230
|
+
runInherit([process.execPath, "-e", "process.exit(4)"], dir),
|
|
231
|
+
]).toEqual([true, true, true, false, 4]);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Claude Code: whether it is here, and the paperlint plugin's state in it, as the `ClaudeCode` port. */
|
|
2
|
+
export { claudeCode, onPath, runInherit } from "./claude.io.ts";
|
|
3
|
+
export {
|
|
4
|
+
ENABLE_COMMANDS,
|
|
5
|
+
MARKETPLACE_REPO,
|
|
6
|
+
PLUGIN_ID,
|
|
7
|
+
configDirOf,
|
|
8
|
+
enabledBy,
|
|
9
|
+
installedVersion,
|
|
10
|
+
withPlugin,
|
|
11
|
+
} from "./plugin.ts";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What Claude Code's own files say about the paperlint plugin, read without touching them. Measured
|
|
3
|
+
* 2026-11-22 with Claude Code 2.1.330 (docs/prior-art/plugin-bundle-measurements.md):
|
|
4
|
+
* `claude plugin marketplace add <source> --scope project` writes `extraKnownMarketplaces.paperlint`
|
|
5
|
+
* into `.claude/settings.json`; `claude plugin install paperlint@paperlint --scope project` adds
|
|
6
|
+
* `enabledPlugins["paperlint@paperlint"]: true` there, and records the install in
|
|
7
|
+
* `~/.claude/plugins/installed_plugins.json` with its `scope`, `version` and `projectPath`.
|
|
8
|
+
*/
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { fieldOf, isRecord } from "../../domain/record.ts";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The folder Claude Code keeps the user's settings and plugins in: `CLAUDE_CONFIG_DIR` when it is
|
|
14
|
+
* set (a second profile, for one), else `~/.claude`. Both the user settings and the install record
|
|
15
|
+
* live there, so both are read from the one answer.
|
|
16
|
+
*/
|
|
17
|
+
export const configDirOf = (
|
|
18
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
19
|
+
home: string,
|
|
20
|
+
): string => {
|
|
21
|
+
const set = env["CLAUDE_CONFIG_DIR"];
|
|
22
|
+
return set === undefined || set === "" ? join(home, ".claude") : set;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** `<plugin>@<marketplace>`: both are named `paperlint`. */
|
|
26
|
+
export const PLUGIN_ID = "paperlint@paperlint";
|
|
27
|
+
|
|
28
|
+
/** The marketplace is this repository: `.claude-plugin/marketplace.json`. */
|
|
29
|
+
export const MARKETPLACE_REPO = "zernie/paperlint";
|
|
30
|
+
|
|
31
|
+
/** The two commands that turn the plugin on for a project, in order. */
|
|
32
|
+
export const ENABLE_COMMANDS: readonly (readonly [string, ...string[]])[] = [
|
|
33
|
+
[
|
|
34
|
+
"claude",
|
|
35
|
+
"plugin",
|
|
36
|
+
"marketplace",
|
|
37
|
+
"add",
|
|
38
|
+
MARKETPLACE_REPO,
|
|
39
|
+
"--scope",
|
|
40
|
+
"project",
|
|
41
|
+
],
|
|
42
|
+
["claude", "plugin", "install", PLUGIN_ID, "--scope", "project"],
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
/** What one settings file says: on, off, or nothing. */
|
|
46
|
+
const says = (settings: unknown): boolean | undefined => {
|
|
47
|
+
const v = fieldOf(fieldOf(settings, "enabledPlugins"), PLUGIN_ID);
|
|
48
|
+
return typeof v === "boolean" ? v : undefined;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** The most specific file that names the plugin decides; `files` are ordered most specific first. */
|
|
52
|
+
export const enabledBy = (files: readonly unknown[]): boolean =>
|
|
53
|
+
files.map(says).find((v) => v !== undefined) ?? false;
|
|
54
|
+
|
|
55
|
+
/** The version installed for `root`: an entry for this project, else a user-scope one. */
|
|
56
|
+
export function installedVersion(json: unknown, root: string): string | null {
|
|
57
|
+
const entries = fieldOf(fieldOf(json, "plugins"), PLUGIN_ID);
|
|
58
|
+
const list: readonly unknown[] = Array.isArray(entries) ? entries : [];
|
|
59
|
+
const entry =
|
|
60
|
+
list.find((e) => fieldOf(e, "projectPath") === root) ??
|
|
61
|
+
list.find((e) => fieldOf(e, "scope") === "user");
|
|
62
|
+
const version = fieldOf(entry, "version");
|
|
63
|
+
return typeof version === "string" ? version : null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const recordOf = (v: unknown): Readonly<Record<string, unknown>> =>
|
|
67
|
+
isRecord(v) ? v : {};
|
|
68
|
+
|
|
69
|
+
/** The settings with the marketplace declared and the plugin turned on; everything else kept. */
|
|
70
|
+
export const withPlugin = (
|
|
71
|
+
settings: Readonly<Record<string, unknown>>,
|
|
72
|
+
): Readonly<Record<string, unknown>> => ({
|
|
73
|
+
...settings,
|
|
74
|
+
extraKnownMarketplaces: {
|
|
75
|
+
...recordOf(settings["extraKnownMarketplaces"]),
|
|
76
|
+
paperlint: { source: { source: "github", repo: MARKETPLACE_REPO } },
|
|
77
|
+
},
|
|
78
|
+
enabledPlugins: {
|
|
79
|
+
...recordOf(settings["enabledPlugins"]),
|
|
80
|
+
[PLUGIN_ID]: true,
|
|
81
|
+
},
|
|
82
|
+
});
|
package/src/cli.harness.mjs
CHANGED
|
@@ -94,6 +94,12 @@ async function cli(args, cwd) {
|
|
|
94
94
|
command: (_r, spec) => ["npm", spec],
|
|
95
95
|
run: () => ({ ok: true }),
|
|
96
96
|
},
|
|
97
|
+
// …nor finds Claude Code: the plugin offer has its own tests.
|
|
98
|
+
claude: {
|
|
99
|
+
present: () => false,
|
|
100
|
+
plugin: () => ({ enabled: false, version: null }),
|
|
101
|
+
enable: () => ({ ok: false, reason: "the harness turns nothing on" }),
|
|
102
|
+
},
|
|
97
103
|
});
|
|
98
104
|
return {
|
|
99
105
|
code,
|
package/src/cli.test.ts
CHANGED
|
@@ -38,9 +38,16 @@ import {
|
|
|
38
38
|
toolchainTex,
|
|
39
39
|
} from "./cli.ts";
|
|
40
40
|
import { texInputsDir } from "./package-dirs.ts";
|
|
41
|
+
import type { ClaudeCode } from "./ports/claude-code.ts";
|
|
41
42
|
|
|
42
43
|
const root = useTempDir("cli-test-");
|
|
43
44
|
|
|
45
|
+
const NO_CLAUDE: ClaudeCode = {
|
|
46
|
+
present: () => false,
|
|
47
|
+
plugin: () => ({ enabled: false, version: null }),
|
|
48
|
+
enable: () => assert.fail("no test here turns the plugin on for real"),
|
|
49
|
+
};
|
|
50
|
+
|
|
44
51
|
/**
|
|
45
52
|
* `run(argv)` from `cwd`, the output as one string per stream. Its clock stands still, so `lint`'s
|
|
46
53
|
* «linted N file(s) in 0.0 s» is the same however long the run took: under a loaded
|
|
@@ -51,7 +58,7 @@ async function cli(
|
|
|
51
58
|
cwd: string,
|
|
52
59
|
deps: Pick<
|
|
53
60
|
NonNullable<Parameters<typeof run>[1]>,
|
|
54
|
-
"loadTexLanguage" | "install"
|
|
61
|
+
"loadTexLanguage" | "claude" | "install"
|
|
55
62
|
> = {},
|
|
56
63
|
) {
|
|
57
64
|
const out: string[] = [];
|
|
@@ -66,6 +73,8 @@ async function cli(
|
|
|
66
73
|
command: (_root, spec) => ["npm", spec],
|
|
67
74
|
run: () => ({ ok: true }),
|
|
68
75
|
},
|
|
76
|
+
// …nor finds Claude Code, unless a test hands one: the offer itself is `src/plugin-offer.test.ts`'s.
|
|
77
|
+
claude: NO_CLAUDE,
|
|
69
78
|
...deps,
|
|
70
79
|
});
|
|
71
80
|
return { code, out: out.join("\n"), err: err.join("\n") };
|
|
@@ -492,6 +501,28 @@ test("chooseVenue: a preset by path (inside and outside the paper), by prefixed
|
|
|
492
501
|
);
|
|
493
502
|
});
|
|
494
503
|
|
|
504
|
+
test("doctor reads the plugin where Claude Code is, and says nothing of it where it is not", async () => {
|
|
505
|
+
const dir = join(root, "doctor-plugin");
|
|
506
|
+
writeTree(dir, { "paperlint.json": "{}" });
|
|
507
|
+
const read: string[] = [];
|
|
508
|
+
const claude: ClaudeCode = {
|
|
509
|
+
...NO_CLAUDE,
|
|
510
|
+
present: () => true,
|
|
511
|
+
plugin: (at) => (read.push(at), { enabled: true, version: "1.0.0" }),
|
|
512
|
+
};
|
|
513
|
+
const head = "Claude Code plugin (carries the skills and the hooks)";
|
|
514
|
+
const on = (await cli(["doctor"], dir, { claude })).out.split("\n");
|
|
515
|
+
const absent = (await cli(["doctor"], dir)).out.split("\n");
|
|
516
|
+
assert.deepEqual(
|
|
517
|
+
[
|
|
518
|
+
on.slice(on.indexOf(head), on.indexOf(head) + 2),
|
|
519
|
+
read,
|
|
520
|
+
absent.includes(head),
|
|
521
|
+
],
|
|
522
|
+
[[head, " ✓ on for this project, version 1.0.0"], [dir], false],
|
|
523
|
+
);
|
|
524
|
+
});
|
|
525
|
+
|
|
495
526
|
test("doctor reads a broken config as 'the CLI would lint nothing' instead of stopping", async () => {
|
|
496
527
|
const dir = join(root, "doctor-broken");
|
|
497
528
|
writeTree(dir, { "paperlint.json": "{ not json" });
|
|
@@ -753,6 +784,61 @@ test("init with no path sets up the current directory, and its first paper is pa
|
|
|
753
784
|
assert.equal(made.includes("main.tex"), false);
|
|
754
785
|
});
|
|
755
786
|
|
|
787
|
+
test("init --plugin turns the plugin on without a terminal; --no-plugin never asks; neither, one line", async () => {
|
|
788
|
+
const on: string[] = [];
|
|
789
|
+
const claude: ClaudeCode = {
|
|
790
|
+
present: () => true,
|
|
791
|
+
// Installed once both commands ran, as Claude Code then reads it.
|
|
792
|
+
plugin: (at) =>
|
|
793
|
+
on.includes(at)
|
|
794
|
+
? { enabled: true, version: "1.0.0" }
|
|
795
|
+
: { enabled: false, version: null },
|
|
796
|
+
enable: (at) => (on.push(at), { ok: true, ran: ["claude x"] }),
|
|
797
|
+
};
|
|
798
|
+
const run = async (flag: string[]) => {
|
|
799
|
+
const dir = writeTree(join(root, `offer${flag.join("")}`), {
|
|
800
|
+
"package.json": "{}",
|
|
801
|
+
});
|
|
802
|
+
const out = (await cli(["init", "--yes", ...flag], dir, { claude })).out;
|
|
803
|
+
return out
|
|
804
|
+
.split("\n")
|
|
805
|
+
.filter(
|
|
806
|
+
(l) =>
|
|
807
|
+
l.startsWith("Claude Code plugin") ||
|
|
808
|
+
l.startsWith(" · --no-plugin") ||
|
|
809
|
+
l.startsWith("skills and hooks (") ||
|
|
810
|
+
l === " ✓ ran claude x",
|
|
811
|
+
);
|
|
812
|
+
};
|
|
813
|
+
// Each run ends with init's own doctor check, which reads the plugin as `paperlint doctor` does.
|
|
814
|
+
assert.deepEqual(
|
|
815
|
+
[
|
|
816
|
+
await run(["--plugin"]),
|
|
817
|
+
await run(["--no-plugin"]),
|
|
818
|
+
await run([]),
|
|
819
|
+
on.length,
|
|
820
|
+
],
|
|
821
|
+
[
|
|
822
|
+
[
|
|
823
|
+
"Claude Code plugin (the skills and hooks, updated with paperlint)",
|
|
824
|
+
" ✓ ran claude x",
|
|
825
|
+
"skills and hooks (the plugin carries them now)",
|
|
826
|
+
"Claude Code plugin (carries the skills and the hooks)",
|
|
827
|
+
],
|
|
828
|
+
[
|
|
829
|
+
"Claude Code plugin (the skills and hooks, updated with paperlint)",
|
|
830
|
+
" · --no-plugin — nothing asked, nothing turned on",
|
|
831
|
+
"Claude Code plugin (carries the skills and the hooks)",
|
|
832
|
+
],
|
|
833
|
+
[
|
|
834
|
+
"Claude Code plugin: not turned on — --yes was given, so nothing was asked. To turn it on: npx paperlint init --plugin",
|
|
835
|
+
"Claude Code plugin (carries the skills and the hooks)",
|
|
836
|
+
],
|
|
837
|
+
1,
|
|
838
|
+
],
|
|
839
|
+
);
|
|
840
|
+
});
|
|
841
|
+
|
|
756
842
|
test("init's step 0 that fails stops the run with 2: init itself never starts", async () => {
|
|
757
843
|
const dir = writeTree(join(root, "self-failed"), { "package.json": "{}" });
|
|
758
844
|
const r = await cli(["init", "--yes", "--no-hooks"], dir, {
|
package/src/cli.ts
CHANGED
|
@@ -159,6 +159,7 @@ import {
|
|
|
159
159
|
type TexRequirements,
|
|
160
160
|
} from "./tex-requirements.ts";
|
|
161
161
|
import { doctor } from "./doctor.ts";
|
|
162
|
+
import { installedPluginVersion } from "./plugin-offer.ts";
|
|
162
163
|
import {
|
|
163
164
|
askOnTerminal,
|
|
164
165
|
askOrDefault,
|
|
@@ -250,6 +251,8 @@ import {
|
|
|
250
251
|
} from "./link-skills.ts";
|
|
251
252
|
import { projectInstall } from "./adapters/package-manager/index.ts";
|
|
252
253
|
import type { ProjectInstall } from "./ports/project-install.ts";
|
|
254
|
+
import { claudeCode } from "./adapters/claude-code/index.ts";
|
|
255
|
+
import type { ClaudeCode } from "./ports/claude-code.ts";
|
|
253
256
|
import {
|
|
254
257
|
selfInstallStep,
|
|
255
258
|
versionOf,
|
|
@@ -381,6 +384,10 @@ init:
|
|
|
381
384
|
--yes, -y ask nothing, take every default. Without a terminal on stdin AND stdout,
|
|
382
385
|
or with CI set, nothing is asked either
|
|
383
386
|
--no-hooks do not wire the hooks (the default without a human is to wire them)
|
|
387
|
+
--plugin turn on the Claude Code plugin (the skills and hooks) without asking, with
|
|
388
|
+
or without a terminal. Without a human and without this flag, init turns
|
|
389
|
+
nothing on and prints one line saying so
|
|
390
|
+
--no-plugin never ask about the plugin, never turn it on
|
|
384
391
|
--paper <name> create this paper too (without a human, the only way init creates one)
|
|
385
392
|
|
|
386
393
|
new:
|
|
@@ -1206,6 +1213,8 @@ export function parseArgs(argv: readonly string[]): Args {
|
|
|
1206
1213
|
check: false,
|
|
1207
1214
|
yes: false,
|
|
1208
1215
|
noHooks: false,
|
|
1216
|
+
plugin: false,
|
|
1217
|
+
noPlugin: false,
|
|
1209
1218
|
allowVenueName: false,
|
|
1210
1219
|
paper: null,
|
|
1211
1220
|
venue: null,
|
|
@@ -1291,6 +1300,8 @@ const SWITCHES: ReadonlyMap<
|
|
|
1291
1300
|
| "check"
|
|
1292
1301
|
| "yes"
|
|
1293
1302
|
| "noHooks"
|
|
1303
|
+
| "plugin"
|
|
1304
|
+
| "noPlugin"
|
|
1294
1305
|
| "allowVenueName"
|
|
1295
1306
|
| "submit"
|
|
1296
1307
|
| "save"
|
|
@@ -1303,6 +1314,8 @@ const SWITCHES: ReadonlyMap<
|
|
|
1303
1314
|
["--yes", "yes"],
|
|
1304
1315
|
["-y", "yes"],
|
|
1305
1316
|
["--no-hooks", "noHooks"],
|
|
1317
|
+
["--plugin", "plugin"],
|
|
1318
|
+
["--no-plugin", "noPlugin"],
|
|
1306
1319
|
["--allow-venue-name", "allowVenueName"],
|
|
1307
1320
|
["--submit", "submit"],
|
|
1308
1321
|
["--save", "save"],
|
|
@@ -1593,6 +1606,8 @@ interface HookOptions {
|
|
|
1593
1606
|
readonly version?: string;
|
|
1594
1607
|
/** What `paperlint doctor` reads to find unlinked skills; the disk by default. */
|
|
1595
1608
|
readonly skillLinks?: (root: string) => LinkReport;
|
|
1609
|
+
/** Whether the Claude Code plugin is on; the disk by default. */
|
|
1610
|
+
readonly claude?: ClaudeCode;
|
|
1596
1611
|
}
|
|
1597
1612
|
|
|
1598
1613
|
const readSkillLinks = (root: string): LinkReport =>
|
|
@@ -1633,6 +1648,25 @@ const packageVersion = (): string =>
|
|
|
1633
1648
|
),
|
|
1634
1649
|
).version;
|
|
1635
1650
|
|
|
1651
|
+
/**
|
|
1652
|
+
* What the project still owes of the hooks and skills — nothing once the Claude Code plugin is on: the
|
|
1653
|
+
* plugin carries both, so a project without init's links and hook entries is complete.
|
|
1654
|
+
*/
|
|
1655
|
+
function owed(
|
|
1656
|
+
root: string,
|
|
1657
|
+
skillLinks: (root: string) => LinkReport,
|
|
1658
|
+
claude: ClaudeCode,
|
|
1659
|
+
): {
|
|
1660
|
+
readonly missing: readonly string[];
|
|
1661
|
+
readonly byHand: boolean;
|
|
1662
|
+
readonly skills: readonly string[];
|
|
1663
|
+
} {
|
|
1664
|
+
if (installedPluginVersion(claude.plugin(absolutePath(root))) !== null)
|
|
1665
|
+
return { missing: [], byHand: false, skills: [] };
|
|
1666
|
+
const { missing, byHand } = unwiredHooks(root);
|
|
1667
|
+
return { missing, byHand, skills: unlinkedSkills(skillLinks(root)) };
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1636
1670
|
interface Pending {
|
|
1637
1671
|
readonly text: string;
|
|
1638
1672
|
readonly root: string;
|
|
@@ -1646,8 +1680,11 @@ interface Pending {
|
|
|
1646
1680
|
function pendingNotice(io: ResolvedHookOptions): Pending | null {
|
|
1647
1681
|
try {
|
|
1648
1682
|
const root = hookRoot(io);
|
|
1649
|
-
const { missing, byHand } =
|
|
1650
|
-
|
|
1683
|
+
const { missing, byHand, skills } = owed(
|
|
1684
|
+
root,
|
|
1685
|
+
io.skillLinks ?? readSkillLinks,
|
|
1686
|
+
io.claude ?? claudeCode(),
|
|
1687
|
+
);
|
|
1651
1688
|
const version = io.version ?? packageVersion();
|
|
1652
1689
|
return (missing.length === 0 && skills.length === 0) ||
|
|
1653
1690
|
!notYetTold(nodeFiles, root, version)
|
|
@@ -1676,10 +1713,10 @@ function hooksLine(
|
|
|
1676
1713
|
root: string,
|
|
1677
1714
|
err: typeof console.error,
|
|
1678
1715
|
skillLinks: (root: string) => LinkReport,
|
|
1716
|
+
claude: ClaudeCode,
|
|
1679
1717
|
): void {
|
|
1680
1718
|
try {
|
|
1681
|
-
const { missing } =
|
|
1682
|
-
const skills = unlinkedSkills(skillLinks(root));
|
|
1719
|
+
const { missing, skills } = owed(root, skillLinks, claude);
|
|
1683
1720
|
if (missing.length > 0 || skills.length > 0)
|
|
1684
1721
|
err(lintLine(packageVersion(), missing, skills));
|
|
1685
1722
|
} catch {
|
|
@@ -2403,11 +2440,13 @@ async function runInit(
|
|
|
2403
2440
|
err,
|
|
2404
2441
|
cwd,
|
|
2405
2442
|
install,
|
|
2443
|
+
claude,
|
|
2406
2444
|
}: {
|
|
2407
2445
|
log: typeof console.log;
|
|
2408
2446
|
err: typeof console.error;
|
|
2409
2447
|
cwd: string;
|
|
2410
2448
|
install: ProjectInstall;
|
|
2449
|
+
claude: ClaudeCode;
|
|
2411
2450
|
},
|
|
2412
2451
|
): Promise<number> {
|
|
2413
2452
|
// Deferred, not implemented: named and refused, rather than read as the directory argument.
|
|
@@ -2436,6 +2475,8 @@ async function runInit(
|
|
|
2436
2475
|
prompts,
|
|
2437
2476
|
yes: a.yes,
|
|
2438
2477
|
hooks: !a.noHooks,
|
|
2478
|
+
claude,
|
|
2479
|
+
pluginFlag: a.plugin ? "plugin" : a.noPlugin ? "no-plugin" : null,
|
|
2439
2480
|
paper: a.paper,
|
|
2440
2481
|
createPaper: (papersRoot, name) =>
|
|
2441
2482
|
createPaperAt(papersRoot, name, { log, err, cwd }),
|
|
@@ -2490,12 +2531,15 @@ export async function run(
|
|
|
2490
2531
|
loadTexLanguage = loadLatexLanguage,
|
|
2491
2532
|
skillLinks = readSkillLinks,
|
|
2492
2533
|
install = projectInstall,
|
|
2534
|
+
claude = claudeCode(),
|
|
2493
2535
|
}: {
|
|
2494
2536
|
log?: typeof console.log;
|
|
2495
2537
|
err?: typeof console.error;
|
|
2496
2538
|
cwd?: string;
|
|
2497
2539
|
/** How `init` adds paperlint to a project: the package manager by default; a test hands a fake. */
|
|
2498
2540
|
install?: ProjectInstall;
|
|
2541
|
+
/** Claude Code as `init` and `doctor` see it: the disk and `claude` by default; a test hands a fake. */
|
|
2542
|
+
claude?: ClaudeCode;
|
|
2499
2543
|
/** The clock `lint` times itself with, in milliseconds; a test hands one that answers fixed values. */
|
|
2500
2544
|
now?: () => number;
|
|
2501
2545
|
/**
|
|
@@ -2537,17 +2581,22 @@ export async function run(
|
|
|
2537
2581
|
// `init` asks the CLI's OWN reader what it would lint, so the two sides `doctor` compares are
|
|
2538
2582
|
// not two implementations of the same question. A second resolver here is the defect the
|
|
2539
2583
|
// comparison exists to catch.
|
|
2540
|
-
if (a.cmd === "init")
|
|
2584
|
+
if (a.cmd === "init")
|
|
2585
|
+
return await runInit(a, { log, err, cwd, install, claude });
|
|
2541
2586
|
// `doctor` reads the config but must NOT die on a broken one — reporting that the config is
|
|
2542
2587
|
// broken is precisely its job. So a failed read becomes "the CLI would lint nothing", which is
|
|
2543
2588
|
// what it prints, rather than an early exit that tells the reader nothing about the hooks.
|
|
2544
2589
|
if (a.cmd === "doctor") {
|
|
2545
2590
|
const papers = cliPapers(a, cwd);
|
|
2591
|
+
const projectDir = process.env["CLAUDE_PROJECT_DIR"] ?? cwd;
|
|
2592
|
+
const at = absolutePath(resolve(cwd, projectDir));
|
|
2546
2593
|
return doctor({
|
|
2547
2594
|
log,
|
|
2548
2595
|
cwd,
|
|
2549
|
-
projectDir
|
|
2596
|
+
projectDir,
|
|
2550
2597
|
cliPapers: papers,
|
|
2598
|
+
plugin: claude.present(at) ? claude.plugin(at) : null,
|
|
2599
|
+
installed: packageVersion(),
|
|
2551
2600
|
});
|
|
2552
2601
|
}
|
|
2553
2602
|
const simple = SIMPLE[a.cmd];
|
|
@@ -2665,7 +2714,7 @@ export async function run(
|
|
|
2665
2714
|
.filter((f) => existsSync(f)),
|
|
2666
2715
|
bodies,
|
|
2667
2716
|
});
|
|
2668
|
-
hooksLine(root, err, skillLinks);
|
|
2717
|
+
hooksLine(root, err, skillLinks, claude);
|
|
2669
2718
|
// On stderr, so `--json` leaves stdout a clean array.
|
|
2670
2719
|
timingLines({
|
|
2671
2720
|
files: results.length,
|
|
@@ -2872,6 +2921,10 @@ export async function lintText(
|
|
|
2872
2921
|
/** The formatter `paperlint lint` prints with. */
|
|
2873
2922
|
const LINT_FORMAT = "stylish";
|
|
2874
2923
|
|
|
2924
|
+
/** Printed under a clean `lint`, the README's disclaimer in one line. */
|
|
2925
|
+
const CLEAN_RUN_REMINDER =
|
|
2926
|
+
"Check the venue's own call before you submit: a call can change between editions, and a check can miss a case.";
|
|
2927
|
+
|
|
2875
2928
|
/**
|
|
2876
2929
|
* The end of `paperlint lint`: refuse an optional rule that reached no paper, print the findings, and
|
|
2877
2930
|
* decide the exit code. Pulled out of `run` so each question has its own function.
|
|
@@ -2929,12 +2982,16 @@ async function reportLint(
|
|
|
2929
2982
|
// short. The reverse order would read as "all clean — oh, and also this".
|
|
2930
2983
|
if (structure.length > 0) log(formatStructure(structure));
|
|
2931
2984
|
const out = await (await eslint.loadFormatter(LINT_FORMAT)).format(results);
|
|
2985
|
+
const clean = out.trim() === "" && structure.length === 0;
|
|
2932
2986
|
log(
|
|
2933
2987
|
out.trim() ||
|
|
2934
|
-
(
|
|
2935
|
-
?
|
|
2936
|
-
:
|
|
2988
|
+
(clean
|
|
2989
|
+
? `✓ ${String(results.length)} file(s) checked, no findings`
|
|
2990
|
+
: ""),
|
|
2937
2991
|
);
|
|
2992
|
+
// A clean run is the one result a reader could take as a guarantee, so it, and only it,
|
|
2993
|
+
// carries the README's reminder. Findings speak for themselves; --json is for machines.
|
|
2994
|
+
if (clean) log(` ${CLEAN_RUN_REMINDER}`);
|
|
2938
2995
|
}
|
|
2939
2996
|
if (structure.length > 0 || results.some((r) => r.errorCount > 0)) return 1;
|
|
2940
2997
|
// Warnings fail the run only when the threshold is named EXPLICITLY. A negative threshold means
|