paperlint 20.7.0 → 20.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/plugin.json +1 -1
- package/dist/adapters/revision-plan/index.d.ts +17 -0
- package/dist/adapters/revision-plan/index.d.ts.map +1 -0
- package/dist/adapters/revision-plan/index.js +168 -0
- package/dist/adapters/revision-plan/index.js.map +1 -0
- package/dist/domain/paper-layout.d.ts.map +1 -1
- package/dist/domain/paper-layout.js +4 -0
- package/dist/domain/paper-layout.js.map +1 -1
- package/dist/domain/revision-plan.d.ts +121 -0
- package/dist/domain/revision-plan.d.ts.map +1 -0
- package/dist/domain/revision-plan.js +15 -0
- package/dist/domain/revision-plan.js.map +1 -0
- package/dist/ports/revision-plan-codec.d.ts +7 -0
- package/dist/ports/revision-plan-codec.d.ts.map +1 -0
- package/dist/ports/revision-plan-codec.js +2 -0
- package/dist/ports/revision-plan-codec.js.map +1 -0
- package/docs/configuration.md +56 -0
- package/docs/layout.md +1 -0
- package/docs/rules/paper/allowed-files-only.md +1 -0
- package/package.json +2 -1
- package/scripts/revision-plan-schema.test.ts +39 -0
- package/scripts/revision-plan-schema.ts +17 -0
- package/skills/paper-pipeline/revision-plan.schema.json +619 -0
- package/src/adapters/revision-plan/index.test.ts +207 -0
- package/src/adapters/revision-plan/index.ts +236 -0
- package/src/adapters/revision-plan/schema.test.ts +69 -0
- package/src/domain/paper-layout.test.ts +1 -0
- package/src/domain/paper-layout.ts +4 -0
- package/src/domain/revision-plan.ts +127 -0
- package/src/ports/revision-plan-codec.ts +7 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The parser of a paper's `revision-plan.json`: a valid plan becomes the value whole, and each planted
|
|
3
|
+
* defect is one problem at the path of its field.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
6
|
+
import { PLAN, planText } from "../../../test/revision-plan-fixture.ts";
|
|
7
|
+
import { parseRevisionPlan, revisionPlanCodec } from "./index.ts";
|
|
8
|
+
|
|
9
|
+
/** The plan with `fields` set over its own; a field set to undefined is left out. */
|
|
10
|
+
const planWith = (fields: Readonly<Record<string, unknown>>): string =>
|
|
11
|
+
planText({ ...PLAN, ...fields });
|
|
12
|
+
|
|
13
|
+
/** The plan with row `i` replaced by `row`. */
|
|
14
|
+
const withRow = (i: number, row: Readonly<Record<string, unknown>>): string =>
|
|
15
|
+
planWith({ remaining: PLAN.remaining.map((r, k) => (k === i ? row : r)) });
|
|
16
|
+
|
|
17
|
+
const problems = (text: string) => {
|
|
18
|
+
const parsed = parseRevisionPlan(text);
|
|
19
|
+
return parsed.ok ? [] : parsed.problems;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const [R1, R2, R3, R4] = PLAN.remaining;
|
|
23
|
+
const ENOUGH = { kind: "enough", since: "2026-12-01" };
|
|
24
|
+
|
|
25
|
+
/** Plans the shape accepts beside the fixture: each other bar, measurement, state and finding id. */
|
|
26
|
+
const VALID: readonly (readonly [string, string])[] = [
|
|
27
|
+
[
|
|
28
|
+
"a corpus bar",
|
|
29
|
+
planWith({
|
|
30
|
+
bar: { kind: "corpus", series: "usenix-sec", editions: [2024, 2025] },
|
|
31
|
+
}),
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
"a proxy bar",
|
|
35
|
+
planWith({
|
|
36
|
+
bar: { kind: "proxy", series: "agent", stands_in_for: "a first edition" },
|
|
37
|
+
}),
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
"enough measured",
|
|
41
|
+
planWith({
|
|
42
|
+
measurement: { ...ENOUGH, evidence: "research/2026-12-01-bar.md" },
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
["a row being done", withRow(1, { ...R2, state: "doing" })],
|
|
46
|
+
[
|
|
47
|
+
"a finding named by its id",
|
|
48
|
+
withRow(1, {
|
|
49
|
+
...R2,
|
|
50
|
+
from: { kind: "finding", file: "reviews/a.md", finding: "M2" },
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
/** One planted defect each, and the path it is reported at. */
|
|
56
|
+
const DEFECTS: readonly (readonly [string, string, readonly unknown[]])[] = [
|
|
57
|
+
[
|
|
58
|
+
"a misspelt key, at the key",
|
|
59
|
+
planWith({ writen: "2026-11-25" }),
|
|
60
|
+
["writen"],
|
|
61
|
+
],
|
|
62
|
+
[
|
|
63
|
+
"a corpus bar without its series",
|
|
64
|
+
planWith({ bar: { kind: "corpus", editions: [2025] } }),
|
|
65
|
+
["bar", "series"],
|
|
66
|
+
],
|
|
67
|
+
[
|
|
68
|
+
"a corpus bar with no edition",
|
|
69
|
+
planWith({ bar: { kind: "corpus", series: "agent", editions: [] } }),
|
|
70
|
+
// The first edition is the one missing: `editions` is a tuple with a rest element.
|
|
71
|
+
["bar", "editions", 0],
|
|
72
|
+
],
|
|
73
|
+
["no bar, without why", planWith({ bar: { kind: "none" } }), ["bar", "why"]],
|
|
74
|
+
[
|
|
75
|
+
"a bar of no kind the shape names",
|
|
76
|
+
planWith({ bar: { kind: "measured" } }),
|
|
77
|
+
["bar", "kind"],
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
"enough measured, without the file that decided it",
|
|
81
|
+
planWith({ measurement: ENOUGH }),
|
|
82
|
+
["measurement", "evidence"],
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
"evidence above the paper folder",
|
|
86
|
+
planWith({ measurement: { ...ENOUGH, evidence: "../other/notes.md" } }),
|
|
87
|
+
["measurement", "evidence"],
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
"an absolute evidence path",
|
|
91
|
+
planWith({ measurement: { ...ENOUGH, evidence: "/home/notes.md" } }),
|
|
92
|
+
["measurement", "evidence"],
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
"a drive-qualified evidence path",
|
|
96
|
+
planWith({ measurement: { ...ENOUGH, evidence: "C:/outside/notes.md" } }),
|
|
97
|
+
["measurement", "evidence"],
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
"a finding file with a drive letter",
|
|
101
|
+
withRow(1, {
|
|
102
|
+
...R2,
|
|
103
|
+
from: { kind: "finding", file: "C:/reviews/a.md", finding: 3 },
|
|
104
|
+
}),
|
|
105
|
+
["remaining", 1, "from", "file"],
|
|
106
|
+
],
|
|
107
|
+
[
|
|
108
|
+
"a finding file with a backslash",
|
|
109
|
+
withRow(1, {
|
|
110
|
+
...R2,
|
|
111
|
+
from: { kind: "finding", file: "reviews\\a.md", finding: 3 },
|
|
112
|
+
}),
|
|
113
|
+
["remaining", 1, "from", "file"],
|
|
114
|
+
],
|
|
115
|
+
[
|
|
116
|
+
"a done row without evidence",
|
|
117
|
+
withRow(2, { ...R3, evidence: undefined }),
|
|
118
|
+
["remaining", 2, "evidence"],
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
"a dropped row without its kind",
|
|
122
|
+
withRow(3, { ...R4, kind: undefined }),
|
|
123
|
+
["remaining", 3, "kind"],
|
|
124
|
+
],
|
|
125
|
+
[
|
|
126
|
+
"a row with no origin",
|
|
127
|
+
withRow(1, { ...R2, from: undefined }),
|
|
128
|
+
["remaining", 1, "from"],
|
|
129
|
+
],
|
|
130
|
+
[
|
|
131
|
+
"a row with no date it was added",
|
|
132
|
+
withRow(1, { ...R2, added: "soon" }),
|
|
133
|
+
["remaining", 1, "added"],
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
"a row of no state the shape names",
|
|
137
|
+
withRow(1, { ...R2, state: "blocked" }),
|
|
138
|
+
["remaining", 1, "state"],
|
|
139
|
+
],
|
|
140
|
+
[
|
|
141
|
+
"a by-rule row naming no rule id",
|
|
142
|
+
withRow(0, { ...R1, rule: "required-section" }),
|
|
143
|
+
["remaining", 0, "rule"],
|
|
144
|
+
],
|
|
145
|
+
[
|
|
146
|
+
"a row id that is not R and a number",
|
|
147
|
+
withRow(1, { ...R2, id: "row-2" }),
|
|
148
|
+
["remaining", 1, "id"],
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
"a cycle that is no cycle id",
|
|
152
|
+
planWith({ cycle: "LangCode 2027" }),
|
|
153
|
+
["cycle"],
|
|
154
|
+
],
|
|
155
|
+
[
|
|
156
|
+
"a whitespace-only reason",
|
|
157
|
+
withRow(3, { ...R4, reason: " " }),
|
|
158
|
+
["remaining", 3, "reason"],
|
|
159
|
+
],
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
describe("parseRevisionPlan: a valid plan", () => {
|
|
163
|
+
it("🔴 parses into the whole value, every field kept", () => {
|
|
164
|
+
expect(revisionPlanCodec.parse(planText())).toEqual({
|
|
165
|
+
ok: true,
|
|
166
|
+
plan: PLAN,
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it.each(VALID)("%s parses", (_name, text) => {
|
|
171
|
+
expect(problems(text)).toEqual([]);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("parseRevisionPlan: each defect at its field", () => {
|
|
176
|
+
it.each(DEFECTS)("%s", (_name, text, path) => {
|
|
177
|
+
expect(problems(text).map((p) => p.path)).toEqual([path]);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it("🔴 two rows with one id: the second, naming the first", () => {
|
|
181
|
+
expect(problems(withRow(1, { ...R2, id: "R1" }))).toEqual([
|
|
182
|
+
{
|
|
183
|
+
path: ["remaining", 1, "id"],
|
|
184
|
+
message: '"R1" is the id of row 1 too: each row has its own',
|
|
185
|
+
},
|
|
186
|
+
]);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("a tag of no kind names the kinds it takes", () => {
|
|
190
|
+
expect(problems(planWith({ bar: { kind: "measured" } }))).toEqual([
|
|
191
|
+
{
|
|
192
|
+
path: ["bar", "kind"],
|
|
193
|
+
message: '"kind" is one of "corpus", "proxy", "none"',
|
|
194
|
+
},
|
|
195
|
+
]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("a field left out is missing, at its own path", () => {
|
|
199
|
+
expect(problems(planWith({ bar: { kind: "none" } }))).toEqual([
|
|
200
|
+
{ path: ["bar", "why"], message: "missing: the shape requires it here" },
|
|
201
|
+
]);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it("text that is not JSON: one problem at the top", () => {
|
|
205
|
+
expect(problems("{ cycle: ")).toEqual([{ path: [], message: "not JSON" }]);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The schema of a paper's `revision-plan.json` — the one place its shape is checked
|
|
3
|
+
* (src/domain/revision-plan.ts). The text is parsed once, here, into the domain's `RevisionPlan`;
|
|
4
|
+
* whatever reads a plan after it never re-validates. The venue corpus's pattern
|
|
5
|
+
* (`src/adapters/venue-corpus/`): every object strict, each problem at the path of its field, and the
|
|
6
|
+
* JSON Schema generated from this parser rather than written beside it.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { CYCLE_ID_PATTERN, cycleId } from "../../domain/cycle.ts";
|
|
10
|
+
import { SERIES_ID } from "../../domain/edition.ts";
|
|
11
|
+
import { isInside } from "../../domain/study-registry.ts";
|
|
12
|
+
import {
|
|
13
|
+
DROP_KINDS,
|
|
14
|
+
ROW_ID_PATTERN,
|
|
15
|
+
ROW_STATES,
|
|
16
|
+
RULE_ID_PATTERN,
|
|
17
|
+
type ParsedPlan,
|
|
18
|
+
type PlanProblem,
|
|
19
|
+
type RevisionPlan,
|
|
20
|
+
} from "../../domain/revision-plan.ts";
|
|
21
|
+
import type { RevisionPlanCodec } from "../../ports/revision-plan-codec.ts";
|
|
22
|
+
|
|
23
|
+
const words = z.string().trim().min(1, "a non-empty text");
|
|
24
|
+
const date = z.iso.date();
|
|
25
|
+
|
|
26
|
+
// The pattern first, so the JSON Schema carries it; then the id, minted by the cycle's own function.
|
|
27
|
+
const cycle = z
|
|
28
|
+
.string()
|
|
29
|
+
.regex(
|
|
30
|
+
new RegExp(`^${CYCLE_ID_PATTERN}$`, "u"),
|
|
31
|
+
"a cycle id: lowercase words and digits joined by hyphens, as in `langcode-2027`",
|
|
32
|
+
)
|
|
33
|
+
.transform(cycleId);
|
|
34
|
+
|
|
35
|
+
const series = z
|
|
36
|
+
.string()
|
|
37
|
+
.regex(
|
|
38
|
+
SERIES_ID,
|
|
39
|
+
"a venue corpus's series: its folder under venues/, as in `usenix-sec`",
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
/** A file of the paper, relative to its folder: never absolute (`/…`, `C:…`) and never above it. */
|
|
43
|
+
const paperFile = z
|
|
44
|
+
.string()
|
|
45
|
+
.min(1, "a path relative to the paper folder")
|
|
46
|
+
.refine(
|
|
47
|
+
isInside,
|
|
48
|
+
"a path inside the paper folder: relative, with `/` between its parts, never above it",
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
/** A discriminated union whose unknown or missing tag names the tags it takes. */
|
|
52
|
+
const oneOf = <
|
|
53
|
+
const K extends string,
|
|
54
|
+
const O extends readonly [
|
|
55
|
+
z.core.$ZodTypeDiscriminable,
|
|
56
|
+
...z.core.$ZodTypeDiscriminable[],
|
|
57
|
+
],
|
|
58
|
+
>(
|
|
59
|
+
key: K,
|
|
60
|
+
tags: readonly string[],
|
|
61
|
+
options: O,
|
|
62
|
+
) =>
|
|
63
|
+
z.discriminatedUnion(key, options, {
|
|
64
|
+
error: `"${key}" is one of ${tags.map((t) => `"${t}"`).join(", ")}`,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/** A year a venue corpus covers. */
|
|
68
|
+
const edition = z.int().min(1900).max(2999);
|
|
69
|
+
|
|
70
|
+
const bar = oneOf(
|
|
71
|
+
"kind",
|
|
72
|
+
["corpus", "proxy", "none"],
|
|
73
|
+
[
|
|
74
|
+
z.strictObject({
|
|
75
|
+
kind: z.literal("corpus"),
|
|
76
|
+
series,
|
|
77
|
+
// A tuple with a rest element, not `.array().nonempty()`: zod 4 infers the latter as
|
|
78
|
+
// `number[]`, which the domain's `[number, ...number[]]` refuses.
|
|
79
|
+
editions: z.tuple([edition], edition, {
|
|
80
|
+
error: "at least one edition the corpus covers",
|
|
81
|
+
}),
|
|
82
|
+
}),
|
|
83
|
+
z.strictObject({
|
|
84
|
+
kind: z.literal("proxy"),
|
|
85
|
+
series,
|
|
86
|
+
stands_in_for: words,
|
|
87
|
+
}),
|
|
88
|
+
z.strictObject({ kind: z.literal("none"), why: words }),
|
|
89
|
+
],
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const measurement = oneOf(
|
|
93
|
+
"kind",
|
|
94
|
+
["open", "enough"],
|
|
95
|
+
[
|
|
96
|
+
z.strictObject({ kind: z.literal("open") }),
|
|
97
|
+
z.strictObject({
|
|
98
|
+
kind: z.literal("enough"),
|
|
99
|
+
since: date,
|
|
100
|
+
evidence: paperFile,
|
|
101
|
+
}),
|
|
102
|
+
],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
const source = oneOf(
|
|
106
|
+
"kind",
|
|
107
|
+
["author", "venue", "finding", "prior-reviews"],
|
|
108
|
+
[
|
|
109
|
+
z.strictObject({ kind: z.literal("author") }),
|
|
110
|
+
z.strictObject({ kind: z.literal("venue") }),
|
|
111
|
+
z.strictObject({
|
|
112
|
+
kind: z.literal("finding"),
|
|
113
|
+
file: paperFile,
|
|
114
|
+
finding: z.union([words, z.int().min(1)]),
|
|
115
|
+
}),
|
|
116
|
+
z.strictObject({ kind: z.literal("prior-reviews"), cycle }),
|
|
117
|
+
],
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const base = {
|
|
121
|
+
id: z.string().regex(ROW_ID_PATTERN, "a row id: R and a number, as in `R3`"),
|
|
122
|
+
what: words,
|
|
123
|
+
from: source,
|
|
124
|
+
added: date,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const row = oneOf("state", ROW_STATES, [
|
|
128
|
+
z.strictObject({ ...base, state: z.enum(["todo", "doing"]) }),
|
|
129
|
+
z.strictObject({ ...base, state: z.literal("done"), evidence: words }),
|
|
130
|
+
z.strictObject({
|
|
131
|
+
...base,
|
|
132
|
+
state: z.literal("dropped"),
|
|
133
|
+
reason: words,
|
|
134
|
+
kind: z.enum(DROP_KINDS),
|
|
135
|
+
}),
|
|
136
|
+
z.strictObject({
|
|
137
|
+
...base,
|
|
138
|
+
state: z.literal("by-rule"),
|
|
139
|
+
rule: z
|
|
140
|
+
.string()
|
|
141
|
+
.regex(
|
|
142
|
+
RULE_ID_PATTERN,
|
|
143
|
+
"a rule id as `paperlint lint` reports it, as in `tex/required-section`",
|
|
144
|
+
),
|
|
145
|
+
}),
|
|
146
|
+
]);
|
|
147
|
+
|
|
148
|
+
/** The index of each id that occurs earlier in `ids`, with the index of its first. */
|
|
149
|
+
const repeats = (
|
|
150
|
+
ids: readonly string[],
|
|
151
|
+
): readonly (readonly [number, number])[] =>
|
|
152
|
+
ids.flatMap((v, i) => {
|
|
153
|
+
const first = ids.indexOf(v);
|
|
154
|
+
return first === i ? [] : [[i, first] as const];
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
const plan = z
|
|
158
|
+
.strictObject({
|
|
159
|
+
cycle,
|
|
160
|
+
written: date,
|
|
161
|
+
bar,
|
|
162
|
+
measurement,
|
|
163
|
+
remaining: z.array(row),
|
|
164
|
+
})
|
|
165
|
+
.superRefine((p, ctx) => {
|
|
166
|
+
repeats(p.remaining.map((r) => r.id)).forEach(([i, first]) => {
|
|
167
|
+
ctx.addIssue({
|
|
168
|
+
code: "custom",
|
|
169
|
+
path: ["remaining", i, "id"],
|
|
170
|
+
message: `"${String(p.remaining[i]?.id)}" is the id of row ${String(first + 1)} too: each row has its own`,
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
/** The JSON `text` holds, or undefined when it is not JSON. */
|
|
176
|
+
function jsonOf(text: string): unknown {
|
|
177
|
+
try {
|
|
178
|
+
return JSON.parse(text);
|
|
179
|
+
} catch {
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* One zod issue as a problem. A misspelt key's path ends at the key (the first, when there are
|
|
186
|
+
* several), so a reader of the file lands on it rather than on the object holding it.
|
|
187
|
+
*/
|
|
188
|
+
const problemOf = (i: z.core.$ZodIssue): PlanProblem => ({
|
|
189
|
+
path: [
|
|
190
|
+
...i.path.filter((s) => typeof s !== "symbol"),
|
|
191
|
+
...(i.code === "unrecognized_keys" ? i.keys.slice(0, 1) : []),
|
|
192
|
+
],
|
|
193
|
+
message: i.message,
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
/** A `revision-plan.json`'s text, parsed once at the boundary: the plan, or every reason it is not one. */
|
|
197
|
+
export function parseRevisionPlan(text: string): ParsedPlan {
|
|
198
|
+
const json = jsonOf(text);
|
|
199
|
+
if (json === undefined)
|
|
200
|
+
return { ok: false, problems: [{ path: [], message: "not JSON" }] };
|
|
201
|
+
// A field left out is "missing", not zod's "expected string, received undefined".
|
|
202
|
+
const parsed = plan.safeParse(json, {
|
|
203
|
+
error: (i) =>
|
|
204
|
+
i.code === "invalid_type" && i.input === undefined
|
|
205
|
+
? "missing: the shape requires it here"
|
|
206
|
+
: undefined,
|
|
207
|
+
});
|
|
208
|
+
if (!parsed.success)
|
|
209
|
+
return { ok: false, problems: parsed.error.issues.map(problemOf) };
|
|
210
|
+
const value: RevisionPlan = parsed.data;
|
|
211
|
+
return { ok: true, plan: value };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export const revisionPlanCodec: RevisionPlanCodec = {
|
|
215
|
+
parse: parseRevisionPlan,
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/** Where the shipped JSON Schema of the plan sits, below the package root: in the skill that writes it. */
|
|
219
|
+
export const SCHEMA_FILE = "skills/paper-pipeline/revision-plan.schema.json";
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The JSON Schema of a `revision-plan.json`, generated from the parser's own shape: what an editor
|
|
223
|
+
* completes and a skill reads instead of a hand-written table. Shipped as `SCHEMA_FILE`; a test holds
|
|
224
|
+
* the file to this. A schema cannot say that each row's id is unique or that a path stays inside the paper
|
|
225
|
+
* folder: `revision-plan/record` does.
|
|
226
|
+
*/
|
|
227
|
+
export const revisionPlanJsonSchema = (): unknown => ({
|
|
228
|
+
...z.toJSONSchema(plan, { io: "input", unrepresentable: "any" }),
|
|
229
|
+
title: "A paper's revision-plan.json",
|
|
230
|
+
description:
|
|
231
|
+
"The paper's revision plan for its current cycle: the accepted papers it is held against (bar), whether evidence is still being gathered (measurement), and the closed list of what remains (remaining). This schema lists the fields; it cannot express that each row's id is unique or that a path stays inside the paper folder, which the lint rule revision-plan/record checks with the rest.",
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/** The shipped file's text: the schema, indented, with a closing newline. */
|
|
235
|
+
export const revisionPlanSchemaText = (): string =>
|
|
236
|
+
`${JSON.stringify(revisionPlanJsonSchema(), null, 2)}\n`;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSON Schema `paper-pipeline` ships for `revision-plan.json`: generated from the parser, so the
|
|
3
|
+
* fields an editor or a skill reads are the ones the plan is judged by.
|
|
4
|
+
*/
|
|
5
|
+
import Ajv from "ajv";
|
|
6
|
+
import { omit } from "remeda";
|
|
7
|
+
import { readFileSync } from "node:fs";
|
|
8
|
+
import { dirname, join } from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
import { PLAN } from "../../../test/revision-plan-fixture.ts";
|
|
13
|
+
import {
|
|
14
|
+
revisionPlanJsonSchema,
|
|
15
|
+
revisionPlanSchemaText,
|
|
16
|
+
SCHEMA_FILE,
|
|
17
|
+
} from "./index.ts";
|
|
18
|
+
|
|
19
|
+
describe("revisionPlanJsonSchema — the shipped schema file", () => {
|
|
20
|
+
const SHIPPED = join(
|
|
21
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
22
|
+
"../../../",
|
|
23
|
+
SCHEMA_FILE,
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
it("🔴 is the generated schema, byte for byte", () => {
|
|
27
|
+
// Guards: the schema the skill points at never drifts from the parser that judges the plan.
|
|
28
|
+
expect(
|
|
29
|
+
readFileSync(SHIPPED, "utf8"),
|
|
30
|
+
`${SCHEMA_FILE} is stale: regenerate it with \`npm run schema:revision-plan\``,
|
|
31
|
+
).toBe(revisionPlanSchemaText());
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("🔴 says the rule checks what a schema cannot, and names the plan's fields", () => {
|
|
35
|
+
const schema = z
|
|
36
|
+
.looseObject({
|
|
37
|
+
description: z.string(),
|
|
38
|
+
properties: z.looseObject({}),
|
|
39
|
+
})
|
|
40
|
+
.parse(revisionPlanJsonSchema());
|
|
41
|
+
expect(schema.description).toContain("revision-plan/record");
|
|
42
|
+
expect(Object.keys(schema.properties)).toEqual([
|
|
43
|
+
"cycle",
|
|
44
|
+
"written",
|
|
45
|
+
"bar",
|
|
46
|
+
"measurement",
|
|
47
|
+
"remaining",
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* ajv 6 reads draft-07, so the 2020-12 `$schema` is left out, as an editor's draft-07 validator would
|
|
54
|
+
* read the file; every keyword the generated schema uses means the same in both.
|
|
55
|
+
*/
|
|
56
|
+
const schemaAccepts = (plan: unknown): boolean => {
|
|
57
|
+
const schema = omit(
|
|
58
|
+
z.looseObject({ $schema: z.string() }).parse(revisionPlanJsonSchema()),
|
|
59
|
+
["$schema"],
|
|
60
|
+
);
|
|
61
|
+
return new Ajv({ allErrors: true }).validate(schema, plan) === true;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
describe("revisionPlanJsonSchema — validates the valid plan", () => {
|
|
65
|
+
it("accepts the fixture plan", () => {
|
|
66
|
+
// Guards: the schema an editor reads never refuses a plan the parser takes.
|
|
67
|
+
expect(schemaAccepts(PLAN)).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -90,6 +90,10 @@ export const ROOT_FILE_NOTES: readonly Noted[] = [
|
|
|
90
90
|
name: "SUBMIT-CHECKLIST.md",
|
|
91
91
|
note: "the venue's format and submission mechanics",
|
|
92
92
|
},
|
|
93
|
+
{
|
|
94
|
+
name: "revision-plan.json",
|
|
95
|
+
note: "the current cycle's bar and the closed list of what remains",
|
|
96
|
+
},
|
|
93
97
|
{ name: ".gitignore", note: "keeps the build's byproducts out of git" },
|
|
94
98
|
{ name: "paper.pdf", note: "the built PDF" },
|
|
95
99
|
];
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A PAPER'S REVISION PLAN — `<paper>/revision-plan.json` (#502): for the current cycle, which accepted
|
|
3
|
+
* papers the paper is held against, whether new evidence is still being gathered, and the closed list
|
|
4
|
+
* of what remains before it is submitted. "Done" is the list, not a reader's or a skill's bar: a
|
|
5
|
+
* review finding outside it is a proposal until the author adds a row.
|
|
6
|
+
*
|
|
7
|
+
* The text is checked once, where it enters: `RevisionPlanCodec` (`src/ports/revision-plan-codec.ts`),
|
|
8
|
+
* whose adapter holds the zod schema of this shape. Only the codec mints a `RevisionPlan`, so a value
|
|
9
|
+
* built by hand can hold what the schema refuses (a `done` row with no evidence, two rows with one id).
|
|
10
|
+
* Every object is strict: a misspelt key is a finding, not a field nobody reads.
|
|
11
|
+
*
|
|
12
|
+
* What the shape cannot hold, by construction:
|
|
13
|
+
* - a `done` row without `evidence`, a `dropped` row without `reason` and `kind`;
|
|
14
|
+
* - a bar that claims to be measured without naming the corpus and at least one edition;
|
|
15
|
+
* - "no bar" without saying why; a `proxy` without what it stands in for;
|
|
16
|
+
* - `enough` measured without a date and the file that decided it;
|
|
17
|
+
* - a row with no origin, or no date it was added.
|
|
18
|
+
* What needs the disk or the settings (the cycle is the current one, the corpus and each named file
|
|
19
|
+
* exist, a finding exists in its review, a rule id is shipped) is a rule's, not this type's.
|
|
20
|
+
*/
|
|
21
|
+
import type { CycleId } from "./cycle.ts";
|
|
22
|
+
|
|
23
|
+
export const REVISION_PLAN = "revision-plan.json";
|
|
24
|
+
|
|
25
|
+
/** A row's id, `R1`, `R2`, …: unique in the file, so a review finding can name it. */
|
|
26
|
+
export const ROW_ID_PATTERN = /^R[1-9][0-9]*$/u;
|
|
27
|
+
|
|
28
|
+
/** A rule's id as `paperlint lint` reports it: `<plugin>/<rule>`. */
|
|
29
|
+
export const RULE_ID_PATTERN = /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]*$/u;
|
|
30
|
+
|
|
31
|
+
/** Which accepted papers the paper is held against. A measured bar IS a corpus: there is no `measured: true`. */
|
|
32
|
+
export type Bar =
|
|
33
|
+
| {
|
|
34
|
+
readonly kind: "corpus";
|
|
35
|
+
/** The venue corpus's series: its folder under `<papers-root>/venues/`. */
|
|
36
|
+
readonly series: string;
|
|
37
|
+
readonly editions: readonly [number, ...number[]];
|
|
38
|
+
}
|
|
39
|
+
| {
|
|
40
|
+
/** Another venue's corpus, labelled as a stand-in. */
|
|
41
|
+
readonly kind: "proxy";
|
|
42
|
+
readonly series: string;
|
|
43
|
+
readonly stands_in_for: string;
|
|
44
|
+
}
|
|
45
|
+
| { readonly kind: "none"; readonly why: string };
|
|
46
|
+
|
|
47
|
+
/** Whether new evidence is still being gathered. `enough` closes the evidence, not the text (#504). */
|
|
48
|
+
export type Measurement =
|
|
49
|
+
| { readonly kind: "open" }
|
|
50
|
+
| {
|
|
51
|
+
readonly kind: "enough";
|
|
52
|
+
readonly since: string;
|
|
53
|
+
/** The paper's file, relative to the paper folder, whose reading decided it. */
|
|
54
|
+
readonly evidence: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Where a row came from: one closed set, so a row cannot arrive from nowhere. */
|
|
58
|
+
export type RowSource =
|
|
59
|
+
| { readonly kind: "author" }
|
|
60
|
+
/** A fact of the venue's preset: its template, a required section. */
|
|
61
|
+
| { readonly kind: "venue" }
|
|
62
|
+
/** A finding of a review file, relative to the paper folder (`reviews/*.md`), by its id. */
|
|
63
|
+
| {
|
|
64
|
+
readonly kind: "finding";
|
|
65
|
+
readonly file: string;
|
|
66
|
+
readonly finding: string | number;
|
|
67
|
+
}
|
|
68
|
+
/** The points of a reviewed rejection, from that cycle. */
|
|
69
|
+
| { readonly kind: "prior-reviews"; readonly cycle: CycleId };
|
|
70
|
+
|
|
71
|
+
/** Why a dropped row is not done: decided against, or a known cost the paper is submitted with. */
|
|
72
|
+
export const DROP_KINDS = ["not-doing", "accepted-cap"] as const;
|
|
73
|
+
export type DropKind = (typeof DROP_KINDS)[number];
|
|
74
|
+
|
|
75
|
+
/** What every row carries. */
|
|
76
|
+
interface RowBase {
|
|
77
|
+
readonly id: string;
|
|
78
|
+
readonly what: string;
|
|
79
|
+
readonly from: RowSource;
|
|
80
|
+
/** The day the row was added: a row added after `written` is growth the plan's reader sees. */
|
|
81
|
+
readonly added: string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** How a row stands: open, closed with evidence, dropped with a reason, or closed when a rule falls silent. */
|
|
85
|
+
export type Row = RowBase &
|
|
86
|
+
(
|
|
87
|
+
| { readonly state: "todo" | "doing" }
|
|
88
|
+
| { readonly state: "done"; readonly evidence: string }
|
|
89
|
+
| {
|
|
90
|
+
readonly state: "dropped";
|
|
91
|
+
readonly reason: string;
|
|
92
|
+
readonly kind: DropKind;
|
|
93
|
+
}
|
|
94
|
+
| { readonly state: "by-rule"; readonly rule: string }
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
export const ROW_STATES = [
|
|
98
|
+
"todo",
|
|
99
|
+
"doing",
|
|
100
|
+
"done",
|
|
101
|
+
"dropped",
|
|
102
|
+
"by-rule",
|
|
103
|
+
] as const satisfies readonly Row["state"][];
|
|
104
|
+
|
|
105
|
+
export interface RevisionPlan {
|
|
106
|
+
/** The cycle the plan is for (`cycles[].id` in the paper's `paperlint.json`). */
|
|
107
|
+
readonly cycle: CycleId;
|
|
108
|
+
/** The day the plan was written. */
|
|
109
|
+
readonly written: string;
|
|
110
|
+
readonly bar: Bar;
|
|
111
|
+
readonly measurement: Measurement;
|
|
112
|
+
/** The closed list: a row is added only by an edit to this file. */
|
|
113
|
+
readonly remaining: readonly Row[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** A field of the plan, as the path of keys and indexes from its top. */
|
|
117
|
+
export type PlanPath = readonly (string | number)[];
|
|
118
|
+
|
|
119
|
+
/** Why the text is not a plan, at the field the reason is about. */
|
|
120
|
+
export interface PlanProblem {
|
|
121
|
+
readonly path: PlanPath;
|
|
122
|
+
readonly message: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export type ParsedPlan =
|
|
126
|
+
| { readonly ok: true; readonly plan: RevisionPlan }
|
|
127
|
+
| { readonly ok: false; readonly problems: readonly PlanProblem[] };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** How a revision plan's text becomes a plan: parsed once, at the boundary (src/domain/revision-plan.ts). */
|
|
2
|
+
import type { ParsedPlan } from "../domain/revision-plan.ts";
|
|
3
|
+
|
|
4
|
+
export interface RevisionPlanCodec {
|
|
5
|
+
/** `revision-plan.json`'s text → the plan, or every reason it is not one, each at its field. */
|
|
6
|
+
readonly parse: (text: string) => ParsedPlan;
|
|
7
|
+
}
|