paperlint 18.6.0 → 18.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +11 -0
- package/.claude-plugin/plugin.json +7 -0
- package/CLAUDE.md +3 -3
- package/CONTRIBUTING.md +5 -2
- package/README.md +6 -6
- package/dist/adapters/clack/index.d.ts +3 -0
- package/dist/adapters/clack/index.d.ts.map +1 -0
- package/dist/adapters/clack/index.js +3 -0
- package/dist/adapters/clack/index.js.map +1 -0
- package/dist/adapters/clack/prompts.io.d.ts +8 -0
- package/dist/adapters/clack/prompts.io.d.ts.map +1 -0
- package/dist/adapters/clack/prompts.io.js +20 -0
- package/dist/adapters/clack/prompts.io.js.map +1 -0
- package/dist/adapters/claude-code/claude.io.d.ts +13 -0
- package/dist/adapters/claude-code/claude.io.d.ts.map +1 -0
- package/dist/adapters/claude-code/claude.io.js +68 -0
- package/dist/adapters/claude-code/claude.io.js.map +1 -0
- package/dist/adapters/claude-code/index.d.ts +4 -0
- package/dist/adapters/claude-code/index.d.ts.map +1 -0
- package/dist/adapters/claude-code/index.js +4 -0
- package/dist/adapters/claude-code/index.js.map +1 -0
- package/dist/adapters/claude-code/plugin.d.ts +19 -0
- package/dist/adapters/claude-code/plugin.d.ts.map +1 -0
- package/dist/adapters/claude-code/plugin.js +66 -0
- package/dist/adapters/claude-code/plugin.js.map +1 -0
- package/dist/adapters/package-manager/index.d.ts +4 -0
- package/dist/adapters/package-manager/index.d.ts.map +1 -0
- package/dist/adapters/package-manager/index.js +4 -0
- package/dist/adapters/package-manager/index.js.map +1 -0
- package/dist/adapters/package-manager/install.io.d.ts +3 -0
- package/dist/adapters/package-manager/install.io.d.ts.map +1 -0
- package/dist/adapters/package-manager/install.io.js +23 -0
- package/dist/adapters/package-manager/install.io.js.map +1 -0
- package/dist/adapters/package-manager/manager.d.ts +13 -0
- package/dist/adapters/package-manager/manager.d.ts.map +1 -0
- package/dist/adapters/package-manager/manager.js +22 -0
- package/dist/adapters/package-manager/manager.js.map +1 -0
- package/dist/adapters/study-registry/index.d.ts +2 -2
- package/dist/cli.d.ts +9 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +73 -13
- package/dist/cli.js.map +1 -1
- package/dist/doctor-plugin.d.ts +23 -0
- package/dist/doctor-plugin.d.ts.map +1 -0
- package/dist/doctor-plugin.js +56 -0
- package/dist/doctor-plugin.js.map +1 -0
- package/dist/doctor.d.ts +6 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +69 -26
- package/dist/doctor.js.map +1 -1
- package/dist/hooks-settings.d.ts +18 -0
- package/dist/hooks-settings.d.ts.map +1 -1
- package/dist/hooks-settings.js +25 -0
- package/dist/hooks-settings.js.map +1 -1
- package/dist/init.d.ts +47 -16
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +231 -86
- package/dist/init.js.map +1 -1
- package/dist/link-skills.d.ts +15 -0
- package/dist/link-skills.d.ts.map +1 -1
- package/dist/link-skills.js +18 -1
- package/dist/link-skills.js.map +1 -1
- package/dist/plugin-offer.d.ts +73 -0
- package/dist/plugin-offer.d.ts.map +1 -0
- package/dist/plugin-offer.js +96 -0
- package/dist/plugin-offer.js.map +1 -0
- package/dist/ports/claude-code.d.ts +31 -0
- package/dist/ports/claude-code.d.ts.map +1 -0
- package/dist/ports/claude-code.js +2 -0
- package/dist/ports/claude-code.js.map +1 -0
- package/dist/ports/project-install.d.ts +19 -0
- package/dist/ports/project-install.d.ts.map +1 -0
- package/dist/ports/project-install.js +2 -0
- package/dist/ports/project-install.js.map +1 -0
- package/dist/ports/prompts.d.ts +31 -0
- package/dist/ports/prompts.d.ts.map +1 -0
- package/dist/ports/prompts.js +2 -0
- package/dist/ports/prompts.js.map +1 -0
- package/dist/self-install.d.ts +65 -0
- package/dist/self-install.d.ts.map +1 -0
- package/dist/self-install.js +145 -0
- package/dist/self-install.js.map +1 -0
- package/dist/skill-chunks/chunk-65X5HVIJ.js +26462 -0
- package/dist/skill-chunks/chunk-6NU6CXUS.js +258 -0
- package/dist/skill-chunks/chunk-GRSXIWYF.js +352 -0
- package/dist/skill-chunks/chunk-IREAROCV.js +84 -0
- package/dist/skill-chunks/chunk-KWK6RT4T.js +24267 -0
- package/dist/skill-chunks/chunk-NPQVDEE4.js +19681 -0
- package/dist/skill-chunks/chunk-PJ4KNV4J.js +45 -0
- package/dist/skill-chunks/dist-UPCJMLBM.js +385 -0
- package/dist/skill-chunks/pdfjs-LUMEFOH2.js +39518 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/e2e.md +10 -0
- package/docs/install.md +88 -29
- package/docs/prior-art/README.md +2 -0
- package/docs/prior-art/one-command-install.md +33 -0
- package/docs/prior-art/prompt-libraries.md +32 -0
- package/eslint.config.mjs +1 -0
- package/hooks/CLAUDE.md +2 -2
- package/hooks/CLAUDE.md.spec.ts +1 -1
- package/lib/skill-checks.mjs +13 -6
- package/lib/skill-checks.test.mjs +28 -15
- package/lib/skill-corpus.mjs +5 -2
- package/package.json +8 -3
- package/plugin/CLAUDE.md +22 -14
- package/plugin/CLAUDE.md.spec.ts +20 -12
- package/scripts/bundle-skills.test.ts +226 -0
- package/scripts/bundle-skills.ts +304 -0
- package/scripts/plugin-version.test.ts +80 -0
- package/scripts/plugin-version.ts +58 -0
- package/skills/CLAUDE.md +2 -2
- package/skills/CLAUDE.md.spec.ts +1 -1
- package/skills/argument-arc/SKILL.md +2 -2
- package/skills/argument-arc/SKILL.md.spec.ts +1 -1
- package/skills/argument-arc/scripts/headings.js +57 -13
- package/skills/build-label-page/scripts/label-page.js +2005 -93
- package/skills/cold-read-diff/scripts/cold-read.js +221 -14
- package/skills/label-agent-runs/scripts/labels.js +272 -348
- package/skills/paper-pipeline/references/anonymization.md +4 -3
- package/skills/paper-pipeline/scripts/extract-ref-facts.js +304 -0
- package/skills/pc-panel-review/scripts/prior-reviews.js +7244 -12
- package/skills/run-agent-grid/scripts/grid-guard.js +562 -627
- package/skills/submit-paper/SKILL.md +5 -4
- package/skills/submit-paper/SKILL.md.spec.ts +4 -3
- package/skills/submit-paper/check-deanon.sh +17 -2
- package/skills/submit-paper/check-deanon.test.ts +141 -0
- package/skills/verify-citations/SKILL.md +9 -9
- package/skills/verify-citations/SKILL.md.spec.ts +8 -8
- package/skills/verify-citations/scripts/bib-authors.js +228 -0
- package/skills/verify-citations/scripts/verify-cites.js +816 -0
- package/src/adapters/clack/index.ts +2 -0
- package/src/adapters/clack/prompts.io.ts +35 -0
- package/src/adapters/clack/prompts.test.ts +58 -0
- package/src/adapters/claude-code/claude.io.ts +103 -0
- package/src/adapters/claude-code/index.test.ts +233 -0
- package/src/adapters/claude-code/index.ts +11 -0
- package/src/adapters/claude-code/plugin.ts +82 -0
- package/src/adapters/package-manager/index.test.ts +67 -0
- package/src/adapters/package-manager/index.ts +3 -0
- package/src/adapters/package-manager/install.io.ts +27 -0
- package/src/adapters/package-manager/manager.ts +33 -0
- package/src/cli.harness.mjs +47 -26
- package/src/cli.test.ts +179 -2
- package/src/cli.ts +130 -10
- package/src/doctor-plugin.test.ts +103 -0
- package/src/doctor-plugin.ts +83 -0
- package/src/doctor.test.ts +111 -2
- package/src/doctor.ts +83 -32
- package/src/hooks-notice.test.ts +82 -0
- package/src/hooks-settings.ts +49 -0
- package/src/init-plugin.test.ts +178 -0
- package/src/init.test.ts +138 -27
- package/src/init.ts +341 -124
- package/src/link-skills.test.ts +34 -1
- package/src/link-skills.ts +34 -0
- package/src/parse-args.test.ts +2 -0
- package/src/plugin-offer.test.ts +276 -0
- package/src/plugin-offer.ts +160 -0
- package/src/ports/claude-code.ts +30 -0
- package/src/ports/project-install.ts +18 -0
- package/src/ports/prompts.ts +27 -0
- package/src/self-install.test.ts +267 -0
- package/src/self-install.ts +224 -0
- package/src/types.ts +4 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Prompts` port drawn by @clack/prompts, the one prompt library of this package (chosen on
|
|
3
|
+
* 2026-11-22: `docs/prior-art/prompt-libraries.md`). Clack's cancel (Ctrl+C, Esc) is a symbol;
|
|
4
|
+
* it becomes the port's `cancel`, so nothing outside this folder knows the symbol exists.
|
|
5
|
+
*/
|
|
6
|
+
import { confirm, select, text } from "@clack/prompts";
|
|
7
|
+
import type { Readable, Writable } from "node:stream";
|
|
8
|
+
import type { Answer, Prompts } from "../../ports/prompts.ts";
|
|
9
|
+
|
|
10
|
+
/** Clack answers with the value or with its one symbol, the cancel (`isCancel` tests the same). */
|
|
11
|
+
const answer = <T extends string | boolean>(value: T | symbol): Answer<T> =>
|
|
12
|
+
typeof value === "symbol" ? { kind: "cancel" } : { kind: "answer", value };
|
|
13
|
+
|
|
14
|
+
/** The terminal's streams by default; a test passes its own. */
|
|
15
|
+
export const clackPrompts = (
|
|
16
|
+
streams: { readonly input?: Readable; readonly output?: Writable } = {},
|
|
17
|
+
): Prompts => ({
|
|
18
|
+
confirm: async ({ message, initial }) =>
|
|
19
|
+
answer<boolean>(
|
|
20
|
+
await confirm({ ...streams, message, initialValue: initial }),
|
|
21
|
+
),
|
|
22
|
+
select: async ({ message, options, initial }) =>
|
|
23
|
+
answer<string>(
|
|
24
|
+
await select({
|
|
25
|
+
...streams,
|
|
26
|
+
message,
|
|
27
|
+
options: options.map((value) => ({ value, label: value })),
|
|
28
|
+
initialValue: initial,
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
text: async ({ message, placeholder }) =>
|
|
32
|
+
answer<string>(
|
|
33
|
+
await text({ ...streams, message, placeholder, defaultValue: "" }),
|
|
34
|
+
),
|
|
35
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PassThrough } from "node:stream";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { clackPrompts } from "./index.ts";
|
|
4
|
+
|
|
5
|
+
/** Clack over in-memory streams: the keys are typed once the prompt has drawn itself. */
|
|
6
|
+
const typed = (...keys: readonly string[]) => {
|
|
7
|
+
const input = new PassThrough();
|
|
8
|
+
const output = new PassThrough();
|
|
9
|
+
Object.assign(input, { isTTY: true, setRawMode: () => input });
|
|
10
|
+
output.on("data", () => undefined);
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
for (const k of keys) input.write(k);
|
|
13
|
+
}, 20);
|
|
14
|
+
return clackPrompts({ input, output });
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const ENTER = "\r";
|
|
18
|
+
const DOWN = "\u001b[B";
|
|
19
|
+
const CTRL_C = "\u0003";
|
|
20
|
+
|
|
21
|
+
describe("clackPrompts — the Prompts port over @clack/prompts", () => {
|
|
22
|
+
it("confirm: Enter takes the initial value, `n` answers no", async () => {
|
|
23
|
+
expect(
|
|
24
|
+
await typed(ENTER).confirm({ message: "q?", initial: true }),
|
|
25
|
+
).toEqual({ kind: "answer", value: true });
|
|
26
|
+
expect(
|
|
27
|
+
await typed("n", ENTER).confirm({ message: "q?", initial: true }),
|
|
28
|
+
).toEqual({ kind: "answer", value: false });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("select: the arrow moves off the initial option", async () => {
|
|
32
|
+
expect(
|
|
33
|
+
await typed(DOWN, ENTER).select({
|
|
34
|
+
message: "which?",
|
|
35
|
+
options: ["a", "b", "c"],
|
|
36
|
+
initial: "a",
|
|
37
|
+
}),
|
|
38
|
+
).toEqual({ kind: "answer", value: "b" });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("text: what was typed; an empty line is the empty string", async () => {
|
|
42
|
+
expect(
|
|
43
|
+
await typed("draft", ENTER).text({
|
|
44
|
+
message: "name?",
|
|
45
|
+
placeholder: "skip",
|
|
46
|
+
}),
|
|
47
|
+
).toEqual({ kind: "answer", value: "draft" });
|
|
48
|
+
expect(
|
|
49
|
+
await typed(ENTER).text({ message: "name?", placeholder: "skip" }),
|
|
50
|
+
).toEqual({ kind: "answer", value: "" });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("🔴 Ctrl+C is a cancel, never an answer", async () => {
|
|
54
|
+
expect(
|
|
55
|
+
await typed(CTRL_C).confirm({ message: "q?", initial: true }),
|
|
56
|
+
).toEqual({ kind: "cancel" });
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ClaudeCode` over the disk and the `claude` program.
|
|
3
|
+
*
|
|
4
|
+
* 🔴 TURNING THE PLUGIN ON IS `claude`'S OWN TWO COMMANDS WHEN `claude` IS ON PATH. Measured
|
|
5
|
+
* 2026-11-22 (Claude Code 2.1.330, a throwaway HOME): the settings keys alone
|
|
6
|
+
* (`extraKnownMarketplaces` + `enabledPlugins`, written by hand) leave `claude plugin list` empty, and
|
|
7
|
+
* a later `claude plugin install paperlint@paperlint --scope project` then fails with "Plugin
|
|
8
|
+
* \"paperlint\" not found in marketplace \"paperlint\"": the marketplace was never fetched. So with
|
|
9
|
+
* `claude` on PATH the commands run (they write the same keys). Without it the keys are written, so
|
|
10
|
+
* the project declares the plugin for every clone, and the report names the commands still owed.
|
|
11
|
+
*/
|
|
12
|
+
import { spawnSync } from "node:child_process";
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { dirname, join } from "node:path";
|
|
16
|
+
import type { ClaudeCode, EnableResult } from "../../ports/claude-code.ts";
|
|
17
|
+
import { isRecord } from "../../domain/record.ts";
|
|
18
|
+
import {
|
|
19
|
+
configDirOf,
|
|
20
|
+
ENABLE_COMMANDS,
|
|
21
|
+
enabledBy,
|
|
22
|
+
installedVersion,
|
|
23
|
+
withPlugin,
|
|
24
|
+
} from "./plugin.ts";
|
|
25
|
+
|
|
26
|
+
/** A JSON file's value; undefined when it is missing or does not parse. */
|
|
27
|
+
function readJson(path: string): unknown {
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
30
|
+
} catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether `file --version` runs and exits 0. */
|
|
36
|
+
export const onPath = (file: string): boolean =>
|
|
37
|
+
spawnSync(file, ["--version"], { stdio: "ignore" }).status === 0;
|
|
38
|
+
|
|
39
|
+
/** Runs `argv` in `cwd` with the terminal's streams; its exit status, null when it did not run. */
|
|
40
|
+
export const runInherit = (
|
|
41
|
+
[file, ...args]: readonly [string, ...string[]],
|
|
42
|
+
cwd: string,
|
|
43
|
+
): number | null => spawnSync(file, args, { cwd, stdio: "inherit" }).status;
|
|
44
|
+
|
|
45
|
+
export interface ClaudeDeps {
|
|
46
|
+
/** Where Claude Code keeps the user's settings and plugins (`configDirOf`). */
|
|
47
|
+
readonly configDir: string;
|
|
48
|
+
readonly hasClaude: () => boolean;
|
|
49
|
+
readonly run: typeof runInherit;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const settingsFile = (root: string) => join(root, ".claude", "settings.json");
|
|
53
|
+
|
|
54
|
+
const COMMANDS = ENABLE_COMMANDS.map((c) => c.join(" "));
|
|
55
|
+
|
|
56
|
+
/** Writes the plugin keys into the project's settings; the reason when the file is not JSON. */
|
|
57
|
+
function writeKeys(root: string): string | null {
|
|
58
|
+
const path = settingsFile(root);
|
|
59
|
+
const raw = existsSync(path) ? readJson(path) : {};
|
|
60
|
+
if (!isRecord(raw)) return `${path} is not a JSON object`;
|
|
61
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
62
|
+
writeFileSync(path, `${JSON.stringify(withPlugin(raw), null, 2)}\n`);
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const claudeCode = ({
|
|
67
|
+
configDir = configDirOf(process.env, homedir()),
|
|
68
|
+
hasClaude = () => onPath("claude"),
|
|
69
|
+
run = runInherit,
|
|
70
|
+
}: Partial<ClaudeDeps> = {}): ClaudeCode => ({
|
|
71
|
+
present: (root) => existsSync(join(root, ".claude")) || hasClaude(),
|
|
72
|
+
plugin: (root) => ({
|
|
73
|
+
enabled: enabledBy(
|
|
74
|
+
[
|
|
75
|
+
join(root, ".claude", "settings.local.json"),
|
|
76
|
+
settingsFile(root),
|
|
77
|
+
join(configDir, "settings.json"),
|
|
78
|
+
].map(readJson),
|
|
79
|
+
),
|
|
80
|
+
version: installedVersion(
|
|
81
|
+
readJson(join(configDir, "plugins", "installed_plugins.json")),
|
|
82
|
+
root,
|
|
83
|
+
),
|
|
84
|
+
}),
|
|
85
|
+
enable: (root) => enable(root, { hasClaude, run }),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
/** `claude`'s two commands when it is on PATH; otherwise the keys, and the commands still owed. */
|
|
89
|
+
function enable(
|
|
90
|
+
root: string,
|
|
91
|
+
{ hasClaude, run }: Pick<ClaudeDeps, "hasClaude" | "run">,
|
|
92
|
+
): EnableResult {
|
|
93
|
+
if (!hasClaude()) {
|
|
94
|
+
const bad = writeKeys(root);
|
|
95
|
+
return bad === null
|
|
96
|
+
? { ok: true, wrote: settingsFile(root), owed: COMMANDS }
|
|
97
|
+
: { ok: false, reason: bad };
|
|
98
|
+
}
|
|
99
|
+
const failed = ENABLE_COMMANDS.find((argv) => run(argv, root) !== 0);
|
|
100
|
+
return failed === undefined
|
|
101
|
+
? { ok: true, ran: COMMANDS }
|
|
102
|
+
: { ok: false, reason: `\`${failed.join(" ")}\` failed` };
|
|
103
|
+
}
|
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { writeFileSync } 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 } from "../../../test/support.ts";
|
|
6
|
+
import { addCommand, managerOf, projectInstall } from "./index.ts";
|
|
7
|
+
|
|
8
|
+
describe("the package manager, read from the lockfile", () => {
|
|
9
|
+
it("each lockfile names its manager; none is npm", () => {
|
|
10
|
+
const of = (file: string) => managerOf((f) => f === file);
|
|
11
|
+
expect([
|
|
12
|
+
of("package-lock.json"),
|
|
13
|
+
of("pnpm-lock.yaml"),
|
|
14
|
+
of("yarn.lock"),
|
|
15
|
+
of("bun.lock"),
|
|
16
|
+
of("bun.lockb"),
|
|
17
|
+
of("nothing"),
|
|
18
|
+
]).toEqual(["npm", "pnpm", "yarn", "bun", "bun", "npm"]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("each manager adds a devDependency saved exact", () => {
|
|
22
|
+
expect(
|
|
23
|
+
(["npm", "pnpm", "yarn", "bun"] as const).map((m) =>
|
|
24
|
+
addCommand(m, "paperlint@1.2.3").join(" "),
|
|
25
|
+
),
|
|
26
|
+
).toEqual([
|
|
27
|
+
"npm install --save-dev --save-exact paperlint@1.2.3",
|
|
28
|
+
"pnpm add --save-dev --save-exact paperlint@1.2.3",
|
|
29
|
+
"yarn add --dev --exact paperlint@1.2.3",
|
|
30
|
+
"bun add --dev --exact paperlint@1.2.3",
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("projectInstall — the disk and the manager's program", () => {
|
|
36
|
+
it("the command follows the lockfile in the project root", () => {
|
|
37
|
+
const root = useTempDir("paperlint-pm-");
|
|
38
|
+
writeFileSync(join(root, "pnpm-lock.yaml"), "");
|
|
39
|
+
expect(projectInstall.command(absolutePath(root), "x@1")).toEqual([
|
|
40
|
+
"pnpm",
|
|
41
|
+
"add",
|
|
42
|
+
"--save-dev",
|
|
43
|
+
"--save-exact",
|
|
44
|
+
"x@1",
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("runs in the root: exit 0 is ok, any other exit and a missing program are failures", () => {
|
|
49
|
+
const root = absolutePath(useTempDir("paperlint-pm-"));
|
|
50
|
+
const node = process.execPath;
|
|
51
|
+
expect([
|
|
52
|
+
projectInstall.run(root, [node, "-e", "process.exit(0)"]),
|
|
53
|
+
projectInstall.run(root, [node, "-e", "process.exit(3)"]),
|
|
54
|
+
projectInstall.run(root, [
|
|
55
|
+
node,
|
|
56
|
+
"-e",
|
|
57
|
+
"process.kill(process.pid, 'SIGTERM')",
|
|
58
|
+
]),
|
|
59
|
+
projectInstall.run(root, ["paperlint-no-such-program"]),
|
|
60
|
+
]).toEqual([
|
|
61
|
+
{ ok: true },
|
|
62
|
+
{ ok: false, reason: "exited 3" },
|
|
63
|
+
{ ok: false, reason: "killed by SIGTERM" },
|
|
64
|
+
{ ok: false, reason: "spawnSync paperlint-no-such-program ENOENT" },
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ProjectInstall` over the disk and the package manager's own program: the lockfiles are looked
|
|
3
|
+
* for in the project root, and the command runs there with the terminal's streams, so its progress
|
|
4
|
+
* and its errors reach the person who ran `paperlint init`.
|
|
5
|
+
*/
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import type { ProjectInstall } from "../../ports/project-install.ts";
|
|
10
|
+
import { addCommand, managerOf } from "./manager.ts";
|
|
11
|
+
|
|
12
|
+
export const projectInstall: ProjectInstall = {
|
|
13
|
+
command: (root, spec) =>
|
|
14
|
+
addCommand(
|
|
15
|
+
managerOf((file) => existsSync(join(root, file))),
|
|
16
|
+
spec,
|
|
17
|
+
),
|
|
18
|
+
run: (root, [file, ...args]) => {
|
|
19
|
+
const r = spawnSync(file, args, { cwd: root, stdio: "inherit" });
|
|
20
|
+
if (r.error) return { ok: false, reason: r.error.message };
|
|
21
|
+
if (r.signal !== null)
|
|
22
|
+
return { ok: false, reason: `killed by ${r.signal}` };
|
|
23
|
+
return r.status === 0
|
|
24
|
+
? { ok: true }
|
|
25
|
+
: { ok: false, reason: `exited ${String(r.status)}` };
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which package manager a project uses, read from its lockfile, and how that manager adds a
|
|
3
|
+
* devDependency saved at an exact version. npm when no lockfile is there: it ships with Node.
|
|
4
|
+
*/
|
|
5
|
+
import type { Argv } from "../../ports/project-install.ts";
|
|
6
|
+
|
|
7
|
+
export type Manager = "npm" | "pnpm" | "yarn" | "bun";
|
|
8
|
+
|
|
9
|
+
/** Each lockfile and its manager, in the order they are looked for. */
|
|
10
|
+
export const LOCKFILES: readonly (readonly [string, Manager])[] = [
|
|
11
|
+
["package-lock.json", "npm"],
|
|
12
|
+
["pnpm-lock.yaml", "pnpm"],
|
|
13
|
+
["yarn.lock", "yarn"],
|
|
14
|
+
["bun.lock", "bun"],
|
|
15
|
+
["bun.lockb", "bun"],
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
/** The manager of the first lockfile `present` says is there; npm when none is. */
|
|
19
|
+
export const managerOf = (present: (file: string) => boolean): Manager =>
|
|
20
|
+
LOCKFILES.find(([file]) => present(file))?.[1] ?? "npm";
|
|
21
|
+
|
|
22
|
+
const ADD: Readonly<Record<Manager, Argv>> = {
|
|
23
|
+
npm: ["npm", "install", "--save-dev", "--save-exact"],
|
|
24
|
+
pnpm: ["pnpm", "add", "--save-dev", "--save-exact"],
|
|
25
|
+
yarn: ["yarn", "add", "--dev", "--exact"],
|
|
26
|
+
bun: ["bun", "add", "--dev", "--exact"],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** The command that adds `spec` to devDependencies with `manager`. */
|
|
30
|
+
export const addCommand = (manager: Manager, spec: string): Argv => {
|
|
31
|
+
const [file, ...flags] = ADD[manager];
|
|
32
|
+
return [file, ...flags, spec];
|
|
33
|
+
};
|