paperlint 18.6.0 → 18.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +11 -0
- package/.claude-plugin/plugin.json +7 -0
- package/CLAUDE.md +3 -3
- package/CONTRIBUTING.md +5 -2
- package/README.md +6 -6
- package/dist/adapters/clack/index.d.ts +3 -0
- package/dist/adapters/clack/index.d.ts.map +1 -0
- package/dist/adapters/clack/index.js +3 -0
- package/dist/adapters/clack/index.js.map +1 -0
- package/dist/adapters/clack/prompts.io.d.ts +8 -0
- package/dist/adapters/clack/prompts.io.d.ts.map +1 -0
- package/dist/adapters/clack/prompts.io.js +20 -0
- package/dist/adapters/clack/prompts.io.js.map +1 -0
- package/dist/adapters/claude-code/claude.io.d.ts +13 -0
- package/dist/adapters/claude-code/claude.io.d.ts.map +1 -0
- package/dist/adapters/claude-code/claude.io.js +68 -0
- package/dist/adapters/claude-code/claude.io.js.map +1 -0
- package/dist/adapters/claude-code/index.d.ts +4 -0
- package/dist/adapters/claude-code/index.d.ts.map +1 -0
- package/dist/adapters/claude-code/index.js +4 -0
- package/dist/adapters/claude-code/index.js.map +1 -0
- package/dist/adapters/claude-code/plugin.d.ts +19 -0
- package/dist/adapters/claude-code/plugin.d.ts.map +1 -0
- package/dist/adapters/claude-code/plugin.js +66 -0
- package/dist/adapters/claude-code/plugin.js.map +1 -0
- package/dist/adapters/package-manager/index.d.ts +4 -0
- package/dist/adapters/package-manager/index.d.ts.map +1 -0
- package/dist/adapters/package-manager/index.js +4 -0
- package/dist/adapters/package-manager/index.js.map +1 -0
- package/dist/adapters/package-manager/install.io.d.ts +3 -0
- package/dist/adapters/package-manager/install.io.d.ts.map +1 -0
- package/dist/adapters/package-manager/install.io.js +23 -0
- package/dist/adapters/package-manager/install.io.js.map +1 -0
- package/dist/adapters/package-manager/manager.d.ts +13 -0
- package/dist/adapters/package-manager/manager.d.ts.map +1 -0
- package/dist/adapters/package-manager/manager.js +22 -0
- package/dist/adapters/package-manager/manager.js.map +1 -0
- package/dist/adapters/study-registry/index.d.ts +2 -2
- package/dist/cli.d.ts +9 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +73 -13
- package/dist/cli.js.map +1 -1
- package/dist/doctor-plugin.d.ts +23 -0
- package/dist/doctor-plugin.d.ts.map +1 -0
- package/dist/doctor-plugin.js +56 -0
- package/dist/doctor-plugin.js.map +1 -0
- package/dist/doctor.d.ts +6 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +69 -26
- package/dist/doctor.js.map +1 -1
- package/dist/hooks-settings.d.ts +18 -0
- package/dist/hooks-settings.d.ts.map +1 -1
- package/dist/hooks-settings.js +25 -0
- package/dist/hooks-settings.js.map +1 -1
- package/dist/init.d.ts +47 -16
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +231 -86
- package/dist/init.js.map +1 -1
- package/dist/link-skills.d.ts +15 -0
- package/dist/link-skills.d.ts.map +1 -1
- package/dist/link-skills.js +18 -1
- package/dist/link-skills.js.map +1 -1
- package/dist/plugin-offer.d.ts +73 -0
- package/dist/plugin-offer.d.ts.map +1 -0
- package/dist/plugin-offer.js +96 -0
- package/dist/plugin-offer.js.map +1 -0
- package/dist/ports/claude-code.d.ts +31 -0
- package/dist/ports/claude-code.d.ts.map +1 -0
- package/dist/ports/claude-code.js +2 -0
- package/dist/ports/claude-code.js.map +1 -0
- package/dist/ports/project-install.d.ts +19 -0
- package/dist/ports/project-install.d.ts.map +1 -0
- package/dist/ports/project-install.js +2 -0
- package/dist/ports/project-install.js.map +1 -0
- package/dist/ports/prompts.d.ts +31 -0
- package/dist/ports/prompts.d.ts.map +1 -0
- package/dist/ports/prompts.js +2 -0
- package/dist/ports/prompts.js.map +1 -0
- package/dist/self-install.d.ts +65 -0
- package/dist/self-install.d.ts.map +1 -0
- package/dist/self-install.js +145 -0
- package/dist/self-install.js.map +1 -0
- package/dist/skill-chunks/chunk-65X5HVIJ.js +26462 -0
- package/dist/skill-chunks/chunk-6NU6CXUS.js +258 -0
- package/dist/skill-chunks/chunk-GRSXIWYF.js +352 -0
- package/dist/skill-chunks/chunk-IREAROCV.js +84 -0
- package/dist/skill-chunks/chunk-KWK6RT4T.js +24267 -0
- package/dist/skill-chunks/chunk-NPQVDEE4.js +19681 -0
- package/dist/skill-chunks/chunk-PJ4KNV4J.js +45 -0
- package/dist/skill-chunks/dist-UPCJMLBM.js +385 -0
- package/dist/skill-chunks/pdfjs-LUMEFOH2.js +39518 -0
- package/dist/types.d.ts +4 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/e2e.md +10 -0
- package/docs/install.md +88 -29
- package/docs/prior-art/README.md +2 -0
- package/docs/prior-art/one-command-install.md +33 -0
- package/docs/prior-art/prompt-libraries.md +32 -0
- package/eslint.config.mjs +1 -0
- package/hooks/CLAUDE.md +2 -2
- package/hooks/CLAUDE.md.spec.ts +1 -1
- package/lib/skill-checks.mjs +13 -6
- package/lib/skill-checks.test.mjs +28 -15
- package/lib/skill-corpus.mjs +5 -2
- package/package.json +8 -3
- package/plugin/CLAUDE.md +22 -14
- package/plugin/CLAUDE.md.spec.ts +20 -12
- package/scripts/bundle-skills.test.ts +226 -0
- package/scripts/bundle-skills.ts +304 -0
- package/scripts/plugin-version.test.ts +80 -0
- package/scripts/plugin-version.ts +58 -0
- package/skills/CLAUDE.md +2 -2
- package/skills/CLAUDE.md.spec.ts +1 -1
- package/skills/argument-arc/SKILL.md +2 -2
- package/skills/argument-arc/SKILL.md.spec.ts +1 -1
- package/skills/argument-arc/scripts/headings.js +57 -13
- package/skills/build-label-page/scripts/label-page.js +2005 -93
- package/skills/cold-read-diff/scripts/cold-read.js +221 -14
- package/skills/label-agent-runs/scripts/labels.js +272 -348
- package/skills/paper-pipeline/references/anonymization.md +4 -3
- package/skills/paper-pipeline/scripts/extract-ref-facts.js +304 -0
- package/skills/pc-panel-review/scripts/prior-reviews.js +7244 -12
- package/skills/run-agent-grid/scripts/grid-guard.js +562 -627
- package/skills/submit-paper/SKILL.md +5 -4
- package/skills/submit-paper/SKILL.md.spec.ts +4 -3
- package/skills/submit-paper/check-deanon.sh +17 -2
- package/skills/submit-paper/check-deanon.test.ts +141 -0
- package/skills/verify-citations/SKILL.md +9 -9
- package/skills/verify-citations/SKILL.md.spec.ts +8 -8
- package/skills/verify-citations/scripts/bib-authors.js +228 -0
- package/skills/verify-citations/scripts/verify-cites.js +816 -0
- package/src/adapters/clack/index.ts +2 -0
- package/src/adapters/clack/prompts.io.ts +35 -0
- package/src/adapters/clack/prompts.test.ts +58 -0
- package/src/adapters/claude-code/claude.io.ts +103 -0
- package/src/adapters/claude-code/index.test.ts +233 -0
- package/src/adapters/claude-code/index.ts +11 -0
- package/src/adapters/claude-code/plugin.ts +82 -0
- package/src/adapters/package-manager/index.test.ts +67 -0
- package/src/adapters/package-manager/index.ts +3 -0
- package/src/adapters/package-manager/install.io.ts +27 -0
- package/src/adapters/package-manager/manager.ts +33 -0
- package/src/cli.harness.mjs +47 -26
- package/src/cli.test.ts +179 -2
- package/src/cli.ts +130 -10
- package/src/doctor-plugin.test.ts +103 -0
- package/src/doctor-plugin.ts +83 -0
- package/src/doctor.test.ts +111 -2
- package/src/doctor.ts +83 -32
- package/src/hooks-notice.test.ts +82 -0
- package/src/hooks-settings.ts +49 -0
- package/src/init-plugin.test.ts +178 -0
- package/src/init.test.ts +138 -27
- package/src/init.ts +341 -124
- package/src/link-skills.test.ts +34 -1
- package/src/link-skills.ts +34 -0
- package/src/parse-args.test.ts +2 -0
- package/src/plugin-offer.test.ts +276 -0
- package/src/plugin-offer.ts +160 -0
- package/src/ports/claude-code.ts +30 -0
- package/src/ports/project-install.ts +18 -0
- package/src/ports/prompts.ts +27 -0
- package/src/self-install.test.ts +267 -0
- package/src/self-install.ts +224 -0
- package/src/types.ts +4 -0
package/src/link-skills.test.ts
CHANGED
|
@@ -8,14 +8,21 @@ import assert from "node:assert/strict";
|
|
|
8
8
|
import {
|
|
9
9
|
lstatSync,
|
|
10
10
|
mkdirSync,
|
|
11
|
+
readdirSync,
|
|
11
12
|
readlinkSync,
|
|
12
13
|
realpathSync,
|
|
14
|
+
rmSync,
|
|
13
15
|
symlinkSync,
|
|
14
16
|
} from "node:fs";
|
|
15
17
|
import { join } from "node:path";
|
|
16
18
|
import { test } from "vitest";
|
|
17
19
|
import { useTempDir, writeTree } from "../test/support.ts";
|
|
18
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
linkSkills,
|
|
22
|
+
locatePackage,
|
|
23
|
+
unlinkSkills,
|
|
24
|
+
type LinkFs,
|
|
25
|
+
} from "./link-skills.ts";
|
|
19
26
|
|
|
20
27
|
const root = useTempDir("paperlint-link-skills-");
|
|
21
28
|
const realFs: LinkFs = { lstatSync, realpathSync, readlinkSync, symlinkSync };
|
|
@@ -103,3 +110,29 @@ test("entries that are someone else's: a plain file, one that cannot be resolved
|
|
|
103
110
|
},
|
|
104
111
|
]);
|
|
105
112
|
});
|
|
113
|
+
|
|
114
|
+
test("unlinkSkills: removes init's links, leaves the project's own directory and other names, names a package that does not resolve", () => {
|
|
115
|
+
const shipped = pkg("unlink", ["a", "b", "own"]);
|
|
116
|
+
const project = join(root, "unlink-project");
|
|
117
|
+
assert.ok(linkSkills(project, { locate: at(shipped) }).ok);
|
|
118
|
+
rmSync(join(project, ".claude", "skills", "own"));
|
|
119
|
+
writeTree(project, {
|
|
120
|
+
".claude/skills/own/SKILL.md": "# mine\n",
|
|
121
|
+
".claude/skills/other/SKILL.md": "# mine\n",
|
|
122
|
+
});
|
|
123
|
+
assert.deepEqual(
|
|
124
|
+
[
|
|
125
|
+
unlinkSkills(project, { locate: at(shipped) }),
|
|
126
|
+
readdirSync(join(project, ".claude", "skills")).sort(),
|
|
127
|
+
unlinkSkills(project, { locate: () => ({ error: "ENOENT" }) }),
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
{ ok: true, removed: ["a", "b"] },
|
|
131
|
+
["other", "own"],
|
|
132
|
+
{
|
|
133
|
+
ok: false,
|
|
134
|
+
error: `paperlint does not resolve from ${project} (ENOENT)`,
|
|
135
|
+
},
|
|
136
|
+
],
|
|
137
|
+
);
|
|
138
|
+
});
|
package/src/link-skills.ts
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
readlinkSync,
|
|
35
35
|
realpathSync,
|
|
36
36
|
symlinkSync,
|
|
37
|
+
unlinkSync,
|
|
37
38
|
} from "node:fs";
|
|
38
39
|
/* eslint-enable boundaries/dependencies */
|
|
39
40
|
import { createRequire } from "node:module";
|
|
@@ -269,6 +270,39 @@ export function linkSkills(
|
|
|
269
270
|
};
|
|
270
271
|
}
|
|
271
272
|
|
|
273
|
+
/**
|
|
274
|
+
* Removes the links `init` made — each entry that is a link and leads to the shipped skill — once the
|
|
275
|
+
* Claude Code plugin carries the skills. Anything else of the same name is the project's, and stays.
|
|
276
|
+
*/
|
|
277
|
+
export function unlinkSkills(
|
|
278
|
+
project: string,
|
|
279
|
+
{
|
|
280
|
+
locate = locatePackage,
|
|
281
|
+
fs = nodeLinkFs,
|
|
282
|
+
remove = unlinkSync,
|
|
283
|
+
}: {
|
|
284
|
+
readonly locate?: (p: string) => Located;
|
|
285
|
+
readonly fs?: LinkFs;
|
|
286
|
+
readonly remove?: (path: string) => void;
|
|
287
|
+
} = {},
|
|
288
|
+
):
|
|
289
|
+
| { readonly ok: true; readonly removed: readonly string[] }
|
|
290
|
+
| { readonly ok: false; readonly error: string } {
|
|
291
|
+
const report = linkSkills(project, { write: false, locate, fs });
|
|
292
|
+
if (!report.ok) return report;
|
|
293
|
+
const removed = report.links
|
|
294
|
+
.filter(
|
|
295
|
+
(l) =>
|
|
296
|
+
l.status === "present" &&
|
|
297
|
+
fs.lstatSync(join(report.home, l.name)).isSymbolicLink(),
|
|
298
|
+
)
|
|
299
|
+
.map((l) => l.name);
|
|
300
|
+
removed.forEach((name) => {
|
|
301
|
+
remove(join(report.home, name));
|
|
302
|
+
});
|
|
303
|
+
return { ok: true, removed };
|
|
304
|
+
}
|
|
305
|
+
|
|
272
306
|
/** Every shipped skill's link, and the first one's target as the report's example. */
|
|
273
307
|
function linkAll(
|
|
274
308
|
shipped: { readonly skillsDir: string; readonly names: readonly string[] },
|
package/src/parse-args.test.ts
CHANGED
|
@@ -44,6 +44,8 @@ describe("parseArgs — the switches, each turning one field on", () => {
|
|
|
44
44
|
["--yes", "yes"],
|
|
45
45
|
["-y", "yes"],
|
|
46
46
|
["--no-hooks", "noHooks"],
|
|
47
|
+
["--plugin", "plugin"],
|
|
48
|
+
["--no-plugin", "noPlugin"],
|
|
47
49
|
["--allow-venue-name", "allowVenueName"],
|
|
48
50
|
] as const)("%s → %s", (flag, key) => {
|
|
49
51
|
const off = parseArgs(["new", "x"]);
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { scriptedPrompts, type Reply } from "../test/support.ts";
|
|
3
|
+
import { absolutePath } from "./domain/paths.ts";
|
|
4
|
+
import {
|
|
5
|
+
offerPlugin,
|
|
6
|
+
PLUGIN_QUESTION,
|
|
7
|
+
pluginOn,
|
|
8
|
+
reportPlugin,
|
|
9
|
+
STILL_OFF,
|
|
10
|
+
type PluginAsking,
|
|
11
|
+
type PluginOutcome,
|
|
12
|
+
} from "./plugin-offer.ts";
|
|
13
|
+
import type {
|
|
14
|
+
ClaudeCode,
|
|
15
|
+
EnableResult,
|
|
16
|
+
PluginState,
|
|
17
|
+
} from "./ports/claude-code.ts";
|
|
18
|
+
|
|
19
|
+
const ROOT = absolutePath("/project");
|
|
20
|
+
const RAN: EnableResult = { ok: true, ran: ["claude a", "claude b"] };
|
|
21
|
+
|
|
22
|
+
/** A Claude Code that records every `enable`, with the state and answer a test gives it. */
|
|
23
|
+
/** Installed, as Claude Code reads it once both commands ran. */
|
|
24
|
+
const INSTALLED: PluginState = { enabled: true, version: "1.0.0" };
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* A Claude Code whose state is `state` until `enable` runs, then `after` (installed, unless the
|
|
28
|
+
* test says what Claude Code reads instead, such as a local setting that keeps it off).
|
|
29
|
+
*/
|
|
30
|
+
function fakeClaude({
|
|
31
|
+
present = true,
|
|
32
|
+
state = { enabled: false, version: null },
|
|
33
|
+
enables = RAN,
|
|
34
|
+
after = INSTALLED,
|
|
35
|
+
}: {
|
|
36
|
+
readonly present?: boolean;
|
|
37
|
+
readonly state?: PluginState;
|
|
38
|
+
readonly enables?: EnableResult;
|
|
39
|
+
readonly after?: PluginState;
|
|
40
|
+
} = {}): ClaudeCode & { readonly enabled: string[] } {
|
|
41
|
+
const enabled: string[] = [];
|
|
42
|
+
return {
|
|
43
|
+
enabled,
|
|
44
|
+
present: () => present,
|
|
45
|
+
plugin: () => (enabled.length > 0 ? after : state),
|
|
46
|
+
enable: (root) => (enabled.push(root), enables),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const asking = (
|
|
51
|
+
over: Partial<PluginAsking> & { readonly reply?: Reply } = {},
|
|
52
|
+
): PluginAsking & { readonly asked: string[] } => {
|
|
53
|
+
const prompts = scriptedPrompts(() => over.reply);
|
|
54
|
+
return {
|
|
55
|
+
flag: null,
|
|
56
|
+
interactive: true,
|
|
57
|
+
why: "a terminal on both ends",
|
|
58
|
+
prompts,
|
|
59
|
+
asked: prompts.asked,
|
|
60
|
+
...over,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
describe("offerPlugin — the four paths the author named", () => {
|
|
65
|
+
it("a human, Yes (Enter takes the preselected Yes): asked once, turned on", async () => {
|
|
66
|
+
const claude = fakeClaude();
|
|
67
|
+
const a = asking();
|
|
68
|
+
expect([
|
|
69
|
+
await offerPlugin(ROOT, claude, a),
|
|
70
|
+
a.asked,
|
|
71
|
+
claude.enabled,
|
|
72
|
+
]).toEqual([{ kind: "enabled", how: RAN }, [PLUGIN_QUESTION], [ROOT]]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("both commands ran, yet a more specific setting keeps it off: not turned on, and said why", async () => {
|
|
76
|
+
// `--scope project` writes .claude/settings.json; .claude/settings.local.json outranks it.
|
|
77
|
+
const claude = fakeClaude({ after: { enabled: false, version: "1.0.0" } });
|
|
78
|
+
const out = await offerPlugin(ROOT, claude, asking({ flag: "plugin" }));
|
|
79
|
+
expect([out, pluginOn(out), claude.enabled]).toEqual([
|
|
80
|
+
{ kind: "failed", reason: STILL_OFF },
|
|
81
|
+
false,
|
|
82
|
+
[ROOT],
|
|
83
|
+
]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("a human, No: asked once, nothing turned on", async () => {
|
|
87
|
+
const claude = fakeClaude();
|
|
88
|
+
const a = asking({ reply: false });
|
|
89
|
+
expect([
|
|
90
|
+
await offerPlugin(ROOT, claude, a),
|
|
91
|
+
a.asked,
|
|
92
|
+
claude.enabled,
|
|
93
|
+
]).toEqual([{ kind: "declined" }, [PLUGIN_QUESTION], []]);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("no human, --plugin: nothing asked, turned on", async () => {
|
|
97
|
+
const claude = fakeClaude();
|
|
98
|
+
const a = asking({ interactive: false, flag: "plugin" });
|
|
99
|
+
expect([
|
|
100
|
+
await offerPlugin(ROOT, claude, a),
|
|
101
|
+
a.asked,
|
|
102
|
+
claude.enabled,
|
|
103
|
+
]).toEqual([{ kind: "enabled", how: RAN }, [], [ROOT]]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("no human, no flag: nothing asked, nothing turned on, the reason kept", async () => {
|
|
107
|
+
const claude = fakeClaude();
|
|
108
|
+
const a = asking({ interactive: false, why: "stdout is not a terminal" });
|
|
109
|
+
expect([
|
|
110
|
+
await offerPlugin(ROOT, claude, a),
|
|
111
|
+
a.asked,
|
|
112
|
+
claude.enabled,
|
|
113
|
+
]).toEqual([
|
|
114
|
+
{ kind: "not-asked", why: "stdout is not a terminal" },
|
|
115
|
+
[],
|
|
116
|
+
[],
|
|
117
|
+
]);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
describe("offerPlugin — --no-plugin", () => {
|
|
122
|
+
it("--no-plugin: nothing asked, nothing turned on; an installed plugin stays on", async () => {
|
|
123
|
+
const off = fakeClaude();
|
|
124
|
+
const installed = fakeClaude({
|
|
125
|
+
state: { enabled: true, version: "1.2.3" },
|
|
126
|
+
});
|
|
127
|
+
const a = asking({ flag: "no-plugin" });
|
|
128
|
+
// Skipping the offer is not turning the plugin off: init must not re-create links beside it.
|
|
129
|
+
expect([
|
|
130
|
+
await offerPlugin(ROOT, off, a),
|
|
131
|
+
await offerPlugin(ROOT, installed, a),
|
|
132
|
+
a.asked,
|
|
133
|
+
off.enabled,
|
|
134
|
+
installed.enabled,
|
|
135
|
+
]).toEqual([
|
|
136
|
+
{ kind: "no-plugin-flag" },
|
|
137
|
+
{ kind: "already", version: "1.2.3" },
|
|
138
|
+
[],
|
|
139
|
+
[],
|
|
140
|
+
[],
|
|
141
|
+
]);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
describe("offerPlugin — the other ways it ends", () => {
|
|
146
|
+
it("no Claude Code: silence; --plugin turns it on all the same", async () => {
|
|
147
|
+
const absent = fakeClaude({ present: false });
|
|
148
|
+
expect([
|
|
149
|
+
await offerPlugin(ROOT, absent, asking()),
|
|
150
|
+
await offerPlugin(ROOT, undefined, asking({ flag: "plugin" })),
|
|
151
|
+
await offerPlugin(ROOT, absent, asking({ flag: "plugin" })),
|
|
152
|
+
]).toEqual([
|
|
153
|
+
{ kind: "no-claude" },
|
|
154
|
+
{ kind: "no-claude" },
|
|
155
|
+
{ kind: "enabled", how: RAN },
|
|
156
|
+
]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("already on: nothing asked, its version kept", async () => {
|
|
160
|
+
const claude = fakeClaude({ state: { enabled: true, version: "1.2.3" } });
|
|
161
|
+
const a = asking();
|
|
162
|
+
expect([
|
|
163
|
+
await offerPlugin(ROOT, claude, a),
|
|
164
|
+
a.asked,
|
|
165
|
+
claude.enabled,
|
|
166
|
+
]).toEqual([{ kind: "already", version: "1.2.3" }, [], []]);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("Ctrl+C at the question, a prompt that fails, a missing prompts port, an enable that fails", async () => {
|
|
170
|
+
const failing = fakeClaude({ enables: { ok: false, reason: "boom" } });
|
|
171
|
+
expect([
|
|
172
|
+
await offerPlugin(ROOT, fakeClaude(), asking({ reply: "cancel" })),
|
|
173
|
+
await offerPlugin(
|
|
174
|
+
ROOT,
|
|
175
|
+
fakeClaude(),
|
|
176
|
+
asking({ reply: new Error("tty") }),
|
|
177
|
+
),
|
|
178
|
+
await offerPlugin(ROOT, fakeClaude(), asking({ prompts: undefined })),
|
|
179
|
+
await offerPlugin(ROOT, failing, asking({ flag: "plugin" })),
|
|
180
|
+
]).toEqual([
|
|
181
|
+
{ kind: "cancelled" },
|
|
182
|
+
{ kind: "enabled", how: RAN },
|
|
183
|
+
{ kind: "not-asked", why: "a terminal on both ends" },
|
|
184
|
+
{ kind: "failed", reason: "boom" },
|
|
185
|
+
]);
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe("offerPlugin — declared, not installed", () => {
|
|
190
|
+
it("declared in settings but not installed: nothing asked, the install runs again", async () => {
|
|
191
|
+
// The keys say yes, but Claude Code has no install on record: the settings alone load nothing.
|
|
192
|
+
const declared = { enabled: true, version: null } as const;
|
|
193
|
+
const human = fakeClaude({ state: declared });
|
|
194
|
+
const noHuman = fakeClaude({ state: declared });
|
|
195
|
+
const a = asking({ reply: false });
|
|
196
|
+
expect([
|
|
197
|
+
await offerPlugin(ROOT, human, a),
|
|
198
|
+
a.asked,
|
|
199
|
+
human.enabled,
|
|
200
|
+
await offerPlugin(ROOT, noHuman, asking({ interactive: false })),
|
|
201
|
+
noHuman.enabled,
|
|
202
|
+
]).toEqual([
|
|
203
|
+
{ kind: "enabled", how: RAN },
|
|
204
|
+
[],
|
|
205
|
+
["/project"],
|
|
206
|
+
{ kind: "enabled", how: RAN },
|
|
207
|
+
["/project"],
|
|
208
|
+
]);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const HEAD = [
|
|
213
|
+
"",
|
|
214
|
+
"Claude Code plugin (the skills and hooks, updated with paperlint)",
|
|
215
|
+
];
|
|
216
|
+
const outcomes: readonly PluginOutcome[] = [
|
|
217
|
+
{ kind: "no-claude" },
|
|
218
|
+
{ kind: "cancelled" },
|
|
219
|
+
{ kind: "not-asked", why: "CI is set" },
|
|
220
|
+
{ kind: "no-plugin-flag" },
|
|
221
|
+
{ kind: "declined" },
|
|
222
|
+
{ kind: "failed", reason: "boom" },
|
|
223
|
+
{ kind: "already", version: "1.2.3" },
|
|
224
|
+
{ kind: "enabled", how: RAN },
|
|
225
|
+
{
|
|
226
|
+
kind: "enabled",
|
|
227
|
+
how: {
|
|
228
|
+
ok: true,
|
|
229
|
+
wrote: "/project/.claude/settings.json",
|
|
230
|
+
owed: ["c1", "c2"],
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
];
|
|
234
|
+
|
|
235
|
+
describe("pluginOn and reportPlugin", () => {
|
|
236
|
+
it("on only once installed: already on, or turned on by running claude — written keys are not on", () => {
|
|
237
|
+
expect(outcomes.map(pluginOn)).toEqual([
|
|
238
|
+
false,
|
|
239
|
+
false,
|
|
240
|
+
false,
|
|
241
|
+
false,
|
|
242
|
+
false,
|
|
243
|
+
false,
|
|
244
|
+
true,
|
|
245
|
+
true,
|
|
246
|
+
false,
|
|
247
|
+
]);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("each outcome's lines; without a human, exactly one line after the blank", () => {
|
|
251
|
+
expect(outcomes.map(reportPlugin)).toEqual([
|
|
252
|
+
[],
|
|
253
|
+
[],
|
|
254
|
+
[
|
|
255
|
+
"",
|
|
256
|
+
"Claude Code plugin: not turned on — CI is set, so nothing was asked. To turn it on: npx paperlint init --plugin",
|
|
257
|
+
],
|
|
258
|
+
[...HEAD, " · --no-plugin — nothing asked, nothing turned on"],
|
|
259
|
+
[
|
|
260
|
+
...HEAD,
|
|
261
|
+
" · declined — `npx paperlint init --plugin` turns it on later",
|
|
262
|
+
],
|
|
263
|
+
[
|
|
264
|
+
...HEAD,
|
|
265
|
+
" ✗ not turned on — boom. `npx paperlint init --plugin` tries again",
|
|
266
|
+
],
|
|
267
|
+
[...HEAD, " ✓ already on for this project, version 1.2.3"],
|
|
268
|
+
[...HEAD, " ✓ ran claude a", " ✓ ran claude b"],
|
|
269
|
+
[
|
|
270
|
+
...HEAD,
|
|
271
|
+
" ✓ declared in /project/.claude/settings.json — `claude` is not on PATH, and these keys alone load nothing.",
|
|
272
|
+
" once, where `claude` runs: c1 && c2",
|
|
273
|
+
],
|
|
274
|
+
]);
|
|
275
|
+
});
|
|
276
|
+
});
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `paperlint init` offers the Claude Code plugin, which carries the skills and the hooks and is
|
|
3
|
+
* updated with paperlint (decided 2026-11-22; replaces "link no skills unless asked", #510).
|
|
4
|
+
*
|
|
5
|
+
* ── THE DECISIONS ─────────────────────────────────────────────────────────────
|
|
6
|
+
* who is offered only a project where Claude Code is: a `.claude/` folder, or `claude` on PATH.
|
|
7
|
+
* Anywhere else, silence.
|
|
8
|
+
* a human asked once, Yes preselected; No is respected.
|
|
9
|
+
* no human (--yes, CI, stdin or stdout not a terminal — Claude Code running init is this
|
|
10
|
+
* case) nothing is turned on, and ONE line names why and `--plugin`, so an
|
|
11
|
+
* agent can ask its user.
|
|
12
|
+
* --plugin on, without asking, with or without a terminal.
|
|
13
|
+
* --no-plugin never asked, never on.
|
|
14
|
+
* once it is on init removes the skill links and hook entries IT made: kept beside the
|
|
15
|
+
* plugin, every skill would be listed twice and every hook would run twice.
|
|
16
|
+
* "On" means installed. Keys written without `claude` are only declared: the
|
|
17
|
+
* old wiring stays, and the next init completes the install without asking.
|
|
18
|
+
*/
|
|
19
|
+
import type { AbsolutePath } from "./domain/paths.ts";
|
|
20
|
+
import type {
|
|
21
|
+
ClaudeCode,
|
|
22
|
+
EnableResult,
|
|
23
|
+
PluginState,
|
|
24
|
+
} from "./ports/claude-code.ts";
|
|
25
|
+
import type { Answer, Prompts } from "./ports/prompts.ts";
|
|
26
|
+
|
|
27
|
+
/** `--plugin`, `--no-plugin`, or neither. */
|
|
28
|
+
export type PluginFlag = "plugin" | "no-plugin" | null;
|
|
29
|
+
|
|
30
|
+
export type PluginOutcome =
|
|
31
|
+
| { readonly kind: "no-claude" }
|
|
32
|
+
| { readonly kind: "no-plugin-flag" }
|
|
33
|
+
/** Declared AND installed: Claude Code has an install of this version on record. */
|
|
34
|
+
| { readonly kind: "already"; readonly version: string }
|
|
35
|
+
| {
|
|
36
|
+
readonly kind: "enabled";
|
|
37
|
+
readonly how: Exclude<EnableResult, { readonly ok: false }>;
|
|
38
|
+
}
|
|
39
|
+
| { readonly kind: "failed"; readonly reason: string }
|
|
40
|
+
| { readonly kind: "declined" }
|
|
41
|
+
| { readonly kind: "not-asked"; readonly why: string }
|
|
42
|
+
| { readonly kind: "cancelled" };
|
|
43
|
+
|
|
44
|
+
export interface PluginAsking {
|
|
45
|
+
readonly flag: PluginFlag;
|
|
46
|
+
readonly interactive: boolean;
|
|
47
|
+
/** Why nothing is asked, as `interactivity()` says it. */
|
|
48
|
+
readonly why: string;
|
|
49
|
+
readonly prompts?: Prompts | undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const PLUGIN_QUESTION =
|
|
53
|
+
"Turn on the paperlint plugin for Claude Code? (the skills and hooks, updated with paperlint)";
|
|
54
|
+
|
|
55
|
+
const ask = async (prompts: Prompts): Promise<Answer<boolean>> => {
|
|
56
|
+
try {
|
|
57
|
+
return await prompts.confirm({ message: PLUGIN_QUESTION, initial: true });
|
|
58
|
+
} catch {
|
|
59
|
+
return { kind: "answer", value: true };
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Whether to go ahead: the flag, else a human's answer; an outcome when it stops here. */
|
|
64
|
+
async function decided(asking: PluginAsking): Promise<PluginOutcome | null> {
|
|
65
|
+
if (asking.flag === "plugin") return null;
|
|
66
|
+
if (!asking.interactive || !asking.prompts)
|
|
67
|
+
return { kind: "not-asked", why: asking.why };
|
|
68
|
+
const answer = await ask(asking.prompts);
|
|
69
|
+
if (answer.kind === "cancel") return { kind: "cancelled" };
|
|
70
|
+
return answer.value ? null : { kind: "declined" };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The plugin's version once Claude Code has installed it, else null. The settings keys alone load
|
|
75
|
+
* nothing (they are written where `claude` is not on PATH too), so every reader that drops the old
|
|
76
|
+
* wiring asks this, never `enabled` by itself.
|
|
77
|
+
*/
|
|
78
|
+
export const installedPluginVersion = (
|
|
79
|
+
state: PluginState | null,
|
|
80
|
+
): string | null => (state?.enabled ? state.version : null);
|
|
81
|
+
|
|
82
|
+
/** The plugin's state where Claude Code runs in this project, else null. */
|
|
83
|
+
const stateIn = (
|
|
84
|
+
root: AbsolutePath,
|
|
85
|
+
claude: ClaudeCode | undefined,
|
|
86
|
+
): PluginState | null => (claude?.present(root) ? claude.plugin(root) : null);
|
|
87
|
+
|
|
88
|
+
export async function offerPlugin(
|
|
89
|
+
root: AbsolutePath,
|
|
90
|
+
claude: ClaudeCode | undefined,
|
|
91
|
+
asking: PluginAsking,
|
|
92
|
+
): Promise<PluginOutcome> {
|
|
93
|
+
// `--no-plugin` skips the offer; it does not turn an installed plugin off, so that is read first.
|
|
94
|
+
const state = stateIn(root, claude);
|
|
95
|
+
const version = installedPluginVersion(state);
|
|
96
|
+
if (version !== null) return { kind: "already", version };
|
|
97
|
+
if (asking.flag === "no-plugin") return { kind: "no-plugin-flag" };
|
|
98
|
+
if (!claude || (!state && asking.flag !== "plugin"))
|
|
99
|
+
return { kind: "no-claude" };
|
|
100
|
+
// Declared but not installed (the keys were written where `claude` was not on PATH): the project
|
|
101
|
+
// already said yes, so nothing is asked again; enabling now completes the install.
|
|
102
|
+
const stop = state?.enabled ? null : await decided(asking);
|
|
103
|
+
if (stop !== null) return stop;
|
|
104
|
+
return enableNow(root, claude);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Why the plugin is off although both commands ran. */
|
|
108
|
+
export const STILL_OFF =
|
|
109
|
+
"both commands ran, but Claude Code still reads it as off here: a more specific settings file, such as .claude/settings.local.json, turns paperlint@paperlint off. Remove that entry";
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Runs the commands, then reads what Claude Code reads: they write the project's settings, and a
|
|
113
|
+
* more specific file can still say off. Only an install that reads as on counts as on.
|
|
114
|
+
*/
|
|
115
|
+
function enableNow(root: AbsolutePath, claude: ClaudeCode): PluginOutcome {
|
|
116
|
+
const how = claude.enable(root);
|
|
117
|
+
if (!how.ok) return { kind: "failed", reason: how.reason };
|
|
118
|
+
if ("ran" in how && installedPluginVersion(claude.plugin(root)) === null)
|
|
119
|
+
return { kind: "failed", reason: STILL_OFF };
|
|
120
|
+
return { kind: "enabled", how };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The plugin is on once Claude Code has installed it: the old links and hook entries then go. Keys
|
|
125
|
+
* written without `claude` load nothing, so until the owed commands run the old wiring stays.
|
|
126
|
+
*/
|
|
127
|
+
export const pluginOn = (o: PluginOutcome): boolean =>
|
|
128
|
+
o.kind === "already" || (o.kind === "enabled" && "ran" in o.how);
|
|
129
|
+
|
|
130
|
+
const AGAIN = "`npx paperlint init --plugin`";
|
|
131
|
+
|
|
132
|
+
/** The plugin section of init's report: a header and its lines, or nothing at all. */
|
|
133
|
+
export function reportPlugin(o: PluginOutcome): readonly string[] {
|
|
134
|
+
if (o.kind === "no-claude" || o.kind === "cancelled") return [];
|
|
135
|
+
// ONE line without a human: an agent that ran init reads it and can ask its user.
|
|
136
|
+
if (o.kind === "not-asked")
|
|
137
|
+
return [
|
|
138
|
+
``,
|
|
139
|
+
`Claude Code plugin: not turned on — ${o.why}, so nothing was asked. To turn it on: npx paperlint init --plugin`,
|
|
140
|
+
];
|
|
141
|
+
const head = [
|
|
142
|
+
``,
|
|
143
|
+
`Claude Code plugin (the skills and hooks, updated with paperlint)`,
|
|
144
|
+
];
|
|
145
|
+
if (o.kind === "no-plugin-flag")
|
|
146
|
+
return [...head, ` · --no-plugin — nothing asked, nothing turned on`];
|
|
147
|
+
if (o.kind === "declined")
|
|
148
|
+
return [...head, ` · declined — ${AGAIN} turns it on later`];
|
|
149
|
+
if (o.kind === "failed")
|
|
150
|
+
return [...head, ` ✗ not turned on — ${o.reason}. ${AGAIN} tries again`];
|
|
151
|
+
if (o.kind === "already")
|
|
152
|
+
return [...head, ` ✓ already on for this project, version ${o.version}`];
|
|
153
|
+
return "ran" in o.how
|
|
154
|
+
? [...head, ...o.how.ran.map((c) => ` ✓ ran ${c}`)]
|
|
155
|
+
: [
|
|
156
|
+
...head,
|
|
157
|
+
` ✓ declared in ${o.how.wrote} — \`claude\` is not on PATH, and these keys alone load nothing.`,
|
|
158
|
+
` once, where \`claude\` runs: ${o.how.owed.join(" && ")}`,
|
|
159
|
+
];
|
|
160
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Claude Code, as `paperlint init`, `doctor` and the in-session notice need it: is it here, is the
|
|
3
|
+
* paperlint plugin turned on for this project (and at which version), and turning it on.
|
|
4
|
+
*/
|
|
5
|
+
import type { AbsolutePath } from "../domain/paths.ts";
|
|
6
|
+
|
|
7
|
+
export interface PluginState {
|
|
8
|
+
/** Turned on for the project, by the most specific settings file that names it. */
|
|
9
|
+
readonly enabled: boolean;
|
|
10
|
+
/** The version Claude Code installed for this project, or null when it has none on record. */
|
|
11
|
+
readonly version: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** How the plugin was turned on, in the commands or files that did it. */
|
|
15
|
+
export type EnableResult =
|
|
16
|
+
| { readonly ok: true; readonly ran: readonly string[] }
|
|
17
|
+
| {
|
|
18
|
+
readonly ok: true;
|
|
19
|
+
readonly wrote: string;
|
|
20
|
+
/** The commands still owed where `claude` runs: the keys alone load nothing. */
|
|
21
|
+
readonly owed: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
| { readonly ok: false; readonly reason: string };
|
|
24
|
+
|
|
25
|
+
export interface ClaudeCode {
|
|
26
|
+
/** A `.claude/` folder in the project, or `claude` on PATH. */
|
|
27
|
+
readonly present: (root: AbsolutePath) => boolean;
|
|
28
|
+
readonly plugin: (root: AbsolutePath) => PluginState;
|
|
29
|
+
readonly enable: (root: AbsolutePath) => EnableResult;
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adding a package to the project's devDependencies, with the package manager the project already
|
|
3
|
+
* uses — what `paperlint init` needs to add paperlint itself (`src/self-install.ts`).
|
|
4
|
+
*/
|
|
5
|
+
import type { AbsolutePath } from "../domain/paths.ts";
|
|
6
|
+
|
|
7
|
+
/** A program and its arguments; never empty. */
|
|
8
|
+
export type Argv = readonly [string, ...string[]];
|
|
9
|
+
|
|
10
|
+
export interface ProjectInstall {
|
|
11
|
+
/** The command, as a person would type it, that adds `spec` to `root`'s devDependencies, saved exact. */
|
|
12
|
+
readonly command: (root: AbsolutePath, spec: string) => Argv;
|
|
13
|
+
/** Runs `argv` in `root` with its output on the terminal. */
|
|
14
|
+
readonly run: (
|
|
15
|
+
root: AbsolutePath,
|
|
16
|
+
argv: Argv,
|
|
17
|
+
) => { readonly ok: true } | { readonly ok: false; readonly reason: string };
|
|
18
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The questions `paperlint init` asks a human, shaped by what init needs: a yes/no with a default,
|
|
3
|
+
* one choice out of a list, and a line of text. Nothing here knows which library draws them
|
|
4
|
+
* (`src/adapters/clack/`), so a test answers them without a pseudo-terminal.
|
|
5
|
+
*
|
|
6
|
+
* A cancelled question (Ctrl+C, Esc) is `cancel`, never an answer: init stops at once rather than
|
|
7
|
+
* taking a default the person was trying to refuse.
|
|
8
|
+
*/
|
|
9
|
+
export type Answer<T> =
|
|
10
|
+
{ readonly kind: "answer"; readonly value: T } | { readonly kind: "cancel" };
|
|
11
|
+
|
|
12
|
+
export interface Prompts {
|
|
13
|
+
readonly confirm: (q: {
|
|
14
|
+
readonly message: string;
|
|
15
|
+
readonly initial: boolean;
|
|
16
|
+
}) => Promise<Answer<boolean>>;
|
|
17
|
+
readonly select: (q: {
|
|
18
|
+
readonly message: string;
|
|
19
|
+
readonly options: readonly string[];
|
|
20
|
+
readonly initial: string;
|
|
21
|
+
}) => Promise<Answer<string>>;
|
|
22
|
+
/** An empty line is the answer `""`. */
|
|
23
|
+
readonly text: (q: {
|
|
24
|
+
readonly message: string;
|
|
25
|
+
readonly placeholder: string;
|
|
26
|
+
}) => Promise<Answer<string>>;
|
|
27
|
+
}
|