@fungi.computer/issues 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +68 -2
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/issue-schema.d.ts +99 -0
- package/dist/issue-schema.js +102 -0
- package/dist/validator.d.ts +67 -0
- package/dist/validator.js +289 -0
- package/package.json +32 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jamstack Consulting LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Issues
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
`inspectIssueTree(files)` validates a complete `issues/` tree supplied as a
|
|
4
|
+
record of relative paths and Markdown text. It returns typed diagnostics,
|
|
5
|
+
summaries, the unblocked frontier, and metadata-only records. Any invalid ticket
|
|
6
|
+
makes `records` empty; callers can retain their previous valid projection.
|
|
7
|
+
Filesystem discovery, Git access, commit identity and persistence belong to the
|
|
8
|
+
caller. Repository tooling supplies the local filesystem adapter.
|
|
9
|
+
|
|
10
|
+
The single frontmatter contract lives in `src/issue-schema.ts`. VFile Matter
|
|
11
|
+
owns YAML extraction, Effect validates JSON values, @cfworker/json-schema
|
|
12
|
+
applies the contract (no code generation, so it runs in Workers and under a
|
|
13
|
+
strict CSP), and remark parses Markdown headings. Heading comparisons retain
|
|
14
|
+
literal inline Markdown; fenced code does not supply required sections. The
|
|
15
|
+
blocker walk is iterative, so dependency depth does not consume the JavaScript
|
|
16
|
+
call stack.
|
|
17
|
+
|
|
18
|
+
This recovers the validator and projection from
|
|
19
|
+
`c83b1098c06c90e6ab9a74c0f11bcefab6b15ae4` with current parser and Effect
|
|
20
|
+
dependencies. Queued immutable-commit reads, last-good persistence and Grove
|
|
21
|
+
indexing remain separate tracker work.
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import { inspectIssueTree } from "@fungi.computer/issues";
|
|
25
|
+
|
|
26
|
+
const { records, diagnostics } = inspectIssueTree({});
|
|
27
|
+
// An empty tree has no records or diagnostics.
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Packed consumer readiness
|
|
31
|
+
|
|
32
|
+
Run `pnpm run build`, `pnpm run pack` and `pnpm run stranger` in this package.
|
|
33
|
+
The maintained stranger proof installs only package tarballs into a fresh npm
|
|
34
|
+
consumer, checks the exact shipped files, runs the public runtime fixture and
|
|
35
|
+
compiles every JavaScript entrypoint with strict NodeNext and no library-check
|
|
36
|
+
skip. This qualification does not publish npm releases or push a repository
|
|
37
|
+
split.
|
|
38
|
+
|
|
39
|
+
See [LICENSE](LICENSE) for the license and the package manifest for its public
|
|
40
|
+
repository destination.
|
|
41
|
+
|
|
42
|
+
## Quick start
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { inspectIssueTree } from "@fungi.computer/issues";
|
|
46
|
+
|
|
47
|
+
const { records, diagnostics } = inspectIssueTree({});
|
|
48
|
+
console.log({ records, diagnostics });
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Core concepts
|
|
52
|
+
|
|
53
|
+
The caller supplies a complete tree snapshot. Invalid tickets produce
|
|
54
|
+
diagnostics and no accepted records; filesystem discovery and persistence remain
|
|
55
|
+
with the caller.
|
|
56
|
+
|
|
57
|
+
## Examples and checks
|
|
58
|
+
|
|
59
|
+
The packed runtime fixture at `test/stranger/runtime.mjs` exercises the public
|
|
60
|
+
API in a fresh consumer. Run `pnpm run stranger` after building the package.
|
|
61
|
+
|
|
62
|
+
## Install
|
|
63
|
+
|
|
64
|
+
Install the package tarball with npm. The manifest pins its runtime
|
|
65
|
+
dependencies.
|
|
66
|
+
|
|
67
|
+
## Contribute and license
|
|
68
|
+
|
|
69
|
+
See [LICENSE](LICENSE) for the MIT terms.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { inspectIssueTree } from "./validator.js";
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
declare const issueFrontmatterSchema: {
|
|
2
|
+
$schema: string;
|
|
3
|
+
$id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
type: "object";
|
|
6
|
+
additionalProperties: false;
|
|
7
|
+
required: string[];
|
|
8
|
+
properties: {
|
|
9
|
+
id: {
|
|
10
|
+
type: "string";
|
|
11
|
+
pattern: string;
|
|
12
|
+
};
|
|
13
|
+
title: {
|
|
14
|
+
type: "string";
|
|
15
|
+
minLength: number;
|
|
16
|
+
maxLength: number;
|
|
17
|
+
};
|
|
18
|
+
type: {
|
|
19
|
+
enum: string[];
|
|
20
|
+
};
|
|
21
|
+
status: {
|
|
22
|
+
enum: string[];
|
|
23
|
+
};
|
|
24
|
+
priority: {
|
|
25
|
+
enum: string[];
|
|
26
|
+
};
|
|
27
|
+
created: {
|
|
28
|
+
type: "string";
|
|
29
|
+
pattern: string;
|
|
30
|
+
};
|
|
31
|
+
assignee: {
|
|
32
|
+
oneOf: ({
|
|
33
|
+
type: "null";
|
|
34
|
+
minLength?: never;
|
|
35
|
+
maxLength?: never;
|
|
36
|
+
} | {
|
|
37
|
+
type: "string";
|
|
38
|
+
minLength: number;
|
|
39
|
+
maxLength: number;
|
|
40
|
+
})[];
|
|
41
|
+
};
|
|
42
|
+
areas: {
|
|
43
|
+
type: "array";
|
|
44
|
+
minItems: number;
|
|
45
|
+
maxItems: number;
|
|
46
|
+
uniqueItems: true;
|
|
47
|
+
items: {
|
|
48
|
+
type: "string";
|
|
49
|
+
pattern: string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
blocked_by: {
|
|
53
|
+
type: "array";
|
|
54
|
+
uniqueItems: true;
|
|
55
|
+
items: {
|
|
56
|
+
type: "string";
|
|
57
|
+
pattern: string;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
allOf: ({
|
|
62
|
+
anyOf: ({
|
|
63
|
+
not: {
|
|
64
|
+
properties: {
|
|
65
|
+
status: {
|
|
66
|
+
const: string;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
properties?: never;
|
|
71
|
+
} | {
|
|
72
|
+
properties: {
|
|
73
|
+
assignee: {
|
|
74
|
+
type: "string";
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
not?: never;
|
|
78
|
+
})[];
|
|
79
|
+
} | {
|
|
80
|
+
anyOf: ({
|
|
81
|
+
not: {
|
|
82
|
+
properties: {
|
|
83
|
+
status: {
|
|
84
|
+
enum: string[];
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
properties?: never;
|
|
89
|
+
} | {
|
|
90
|
+
properties: {
|
|
91
|
+
assignee: {
|
|
92
|
+
type: "null";
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
not?: never;
|
|
96
|
+
})[];
|
|
97
|
+
})[];
|
|
98
|
+
};
|
|
99
|
+
export default issueFrontmatterSchema;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
const issueFrontmatterSchema = {
|
|
2
|
+
$schema: "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
$id: "https://fungi.computer/schemas/local-issue-frontmatter-v1.json",
|
|
4
|
+
title: "Botanical local issue frontmatter",
|
|
5
|
+
type: "object",
|
|
6
|
+
additionalProperties: false,
|
|
7
|
+
required: [
|
|
8
|
+
"id",
|
|
9
|
+
"title",
|
|
10
|
+
"type",
|
|
11
|
+
"status",
|
|
12
|
+
"priority",
|
|
13
|
+
"created",
|
|
14
|
+
"assignee",
|
|
15
|
+
"areas",
|
|
16
|
+
"blocked_by",
|
|
17
|
+
],
|
|
18
|
+
properties: {
|
|
19
|
+
id: {
|
|
20
|
+
type: "string",
|
|
21
|
+
pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*-[0-9]{2}[a-z]?$",
|
|
22
|
+
},
|
|
23
|
+
title: {
|
|
24
|
+
type: "string",
|
|
25
|
+
minLength: 1,
|
|
26
|
+
maxLength: 160,
|
|
27
|
+
},
|
|
28
|
+
type: {
|
|
29
|
+
enum: ["bug", "enhancement", "task", "research", "prototype", "decision"],
|
|
30
|
+
},
|
|
31
|
+
status: {
|
|
32
|
+
enum: [
|
|
33
|
+
"needs-triage",
|
|
34
|
+
"needs-info",
|
|
35
|
+
"ready-for-agent",
|
|
36
|
+
"ready-for-human",
|
|
37
|
+
"in-progress",
|
|
38
|
+
"resolved",
|
|
39
|
+
"wontfix",
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
priority: {
|
|
43
|
+
enum: ["p0", "p1", "p2", "p3"],
|
|
44
|
+
},
|
|
45
|
+
created: {
|
|
46
|
+
type: "string",
|
|
47
|
+
pattern: "^[0-9]{4}-[0-9]{2}-[0-9]{2}$",
|
|
48
|
+
},
|
|
49
|
+
assignee: {
|
|
50
|
+
oneOf: [
|
|
51
|
+
{ type: "null" },
|
|
52
|
+
{ type: "string", minLength: 1, maxLength: 100 },
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
areas: {
|
|
56
|
+
type: "array",
|
|
57
|
+
minItems: 1,
|
|
58
|
+
maxItems: 16,
|
|
59
|
+
uniqueItems: true,
|
|
60
|
+
items: {
|
|
61
|
+
type: "string",
|
|
62
|
+
pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
blocked_by: {
|
|
66
|
+
type: "array",
|
|
67
|
+
uniqueItems: true,
|
|
68
|
+
items: {
|
|
69
|
+
type: "string",
|
|
70
|
+
pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*-[0-9]{2}[a-z]?$",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
allOf: [
|
|
75
|
+
{
|
|
76
|
+
anyOf: [
|
|
77
|
+
{ not: { properties: { status: { const: "in-progress" } } } },
|
|
78
|
+
{ properties: { assignee: { type: "string" } } },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
anyOf: [
|
|
83
|
+
{
|
|
84
|
+
not: {
|
|
85
|
+
properties: {
|
|
86
|
+
status: {
|
|
87
|
+
enum: [
|
|
88
|
+
"needs-triage",
|
|
89
|
+
"needs-info",
|
|
90
|
+
"ready-for-agent",
|
|
91
|
+
"ready-for-human",
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
{ properties: { assignee: { type: "null" } } },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
export default issueFrontmatterSchema;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Canonical triage state stored in ticket frontmatter. */
|
|
2
|
+
export type IssueStatus = "needs-triage" | "needs-info" | "ready-for-agent" | "ready-for-human" | "in-progress" | "resolved" | "wontfix";
|
|
3
|
+
/** Ticket metadata accepted by the local issue frontmatter schema. */
|
|
4
|
+
export type IssueFrontmatter = {
|
|
5
|
+
/** Stable effort-and-number identifier, independent of the ticket slug. */
|
|
6
|
+
readonly id: string;
|
|
7
|
+
/** Ticket title, which must match the body's first Markdown heading. */
|
|
8
|
+
readonly title: string;
|
|
9
|
+
/** Ticket kind selecting the required body sections. */
|
|
10
|
+
readonly type: "bug" | "enhancement" | "task" | "research" | "prototype" | "decision";
|
|
11
|
+
/** Triage state; blocking is derived separately from dependency edges. */
|
|
12
|
+
readonly status: IssueStatus;
|
|
13
|
+
/** Priority code, independent of triage state and blocking. */
|
|
14
|
+
readonly priority: "p0" | "p1" | "p2" | "p3";
|
|
15
|
+
/** Creation date written as YYYY-MM-DD. */
|
|
16
|
+
readonly created: string;
|
|
17
|
+
/** Claimed owner, or null while the ticket is unassigned. */
|
|
18
|
+
readonly assignee: string | null;
|
|
19
|
+
/** Searchable area slugs from the governing Wiki's domain language. */
|
|
20
|
+
readonly areas: readonly string[];
|
|
21
|
+
/** Stable ticket IDs that must be resolved or wontfix to settle blockers. */
|
|
22
|
+
readonly blocked_by: readonly string[];
|
|
23
|
+
};
|
|
24
|
+
/** A path, content or dependency rule violation in the supplied issue tree. */
|
|
25
|
+
export type IssueDiagnostic = {
|
|
26
|
+
/** Input file key identifying the ticket that needs correction. */
|
|
27
|
+
readonly path: string;
|
|
28
|
+
/** Machine-readable rule violated by the ticket or its dependency graph. */
|
|
29
|
+
readonly code: "invalid-ticket-path" | "invalid-frontmatter" | "id-path-mismatch" | "duplicate-id" | "title-mismatch" | "missing-section" | "unknown-blocker" | "self-blocker" | "blocker-cycle";
|
|
30
|
+
/** Human-readable explanation of the failed rule. */
|
|
31
|
+
readonly detail: string;
|
|
32
|
+
};
|
|
33
|
+
/** Ticket identity and dependency state used to assemble the ready frontier. */
|
|
34
|
+
export type IssueSummary = {
|
|
35
|
+
/** Stable ticket identifier from its parsed frontmatter. */
|
|
36
|
+
readonly id: string;
|
|
37
|
+
/** Ticket path relative to the supplied issue tree. */
|
|
38
|
+
readonly path: string;
|
|
39
|
+
/** Current triage state, without a synthetic blocked state. */
|
|
40
|
+
readonly status: IssueStatus;
|
|
41
|
+
/** Whether a declared blocker is absent or outside resolved and wontfix. */
|
|
42
|
+
readonly blocked: boolean;
|
|
43
|
+
};
|
|
44
|
+
/** The validated frontmatter fields Grove reads from the Team issue index. */
|
|
45
|
+
export type IssueIndexRecord = Readonly<Pick<IssueFrontmatter, "id" | "title" | "status" | "priority" | "assignee" | "areas" | "blocked_by"> & {
|
|
46
|
+
/** Ticket path relative to the supplied issue tree. */
|
|
47
|
+
path: string;
|
|
48
|
+
/** Whether any declared blocker remains unsettled. */
|
|
49
|
+
blocked: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
/** Validation result and index projections for one complete issue tree. */
|
|
52
|
+
export type IssueTrackerReport = {
|
|
53
|
+
/** Version of this report representation, currently 1. */
|
|
54
|
+
readonly schemaVersion: 1;
|
|
55
|
+
/** Pass only when the complete tree has no diagnostics. */
|
|
56
|
+
readonly status: "pass" | "fail";
|
|
57
|
+
/** Parsed graph summaries, retained even when validation fails. */
|
|
58
|
+
readonly issues: readonly IssueSummary[];
|
|
59
|
+
/** Validated index records; empty if any diagnostic exists. */
|
|
60
|
+
readonly records: readonly IssueIndexRecord[];
|
|
61
|
+
/** Unassigned ready ticket IDs with all declared blockers settled. */
|
|
62
|
+
readonly frontier: readonly string[];
|
|
63
|
+
/** Rule violations sorted by input path and diagnostic code. */
|
|
64
|
+
readonly diagnostics: readonly IssueDiagnostic[];
|
|
65
|
+
};
|
|
66
|
+
/** Validate one pushed `issues/` tree as a schema and dependency graph. */
|
|
67
|
+
export declare function inspectIssueTree(files: Readonly<Record<string, string>>): IssueTrackerReport;
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
import { Validator } from "@cfworker/json-schema";
|
|
2
|
+
import { Schema } from "effect";
|
|
3
|
+
import remarkParse from "remark-parse";
|
|
4
|
+
import { unified } from "unified";
|
|
5
|
+
import { VFile } from "vfile";
|
|
6
|
+
import { matter } from "vfile-matter";
|
|
7
|
+
import issueFrontmatterSchema from "./issue-schema.js";
|
|
8
|
+
const ISSUE_PATH = /^(?<effort>[a-z0-9]+(?:-[a-z0-9]+)*)\/(?<number>[0-9]{2}[a-z]?)-[a-z0-9]+(?:-[a-z0-9]+)*\.md$/u;
|
|
9
|
+
const TERMINAL_STATUSES = new Set(["resolved", "wontfix"]);
|
|
10
|
+
const FRONTIER_STATUSES = new Set([
|
|
11
|
+
"ready-for-agent",
|
|
12
|
+
"ready-for-human",
|
|
13
|
+
]);
|
|
14
|
+
function isTrackerRecord(path) {
|
|
15
|
+
return (path !== "README.md" &&
|
|
16
|
+
!path.startsWith("templates/") &&
|
|
17
|
+
path !== "spec.md" &&
|
|
18
|
+
!path.endsWith("/spec.md") &&
|
|
19
|
+
path !== "map.md" &&
|
|
20
|
+
!path.endsWith("/map.md"));
|
|
21
|
+
}
|
|
22
|
+
const markdown = unified().use(remarkParse);
|
|
23
|
+
/** Preserve the literal inline Markdown compared by the issue title contract. */
|
|
24
|
+
function headingSource(body, heading) {
|
|
25
|
+
if (heading.children.length === 0)
|
|
26
|
+
return "";
|
|
27
|
+
const start = heading.children.at(0)?.position?.start.offset;
|
|
28
|
+
const end = heading.children.at(-1)?.position?.end.offset;
|
|
29
|
+
if (start === undefined || end === undefined)
|
|
30
|
+
throw new Error("Markdown parser omitted heading source positions");
|
|
31
|
+
return body.slice(start, end);
|
|
32
|
+
}
|
|
33
|
+
function schemaDetail(errors) {
|
|
34
|
+
return errors
|
|
35
|
+
.filter((error) => error.keyword !== "properties")
|
|
36
|
+
.map((error) => `${error.instanceLocation.replace(/^#/u, "") || "/"} ${error.error}`)
|
|
37
|
+
.join("; ");
|
|
38
|
+
}
|
|
39
|
+
function frontmatterCheck() {
|
|
40
|
+
const validator = new Validator(issueFrontmatterSchema, "2020-12", false);
|
|
41
|
+
let last = [];
|
|
42
|
+
return {
|
|
43
|
+
accepts: (value) => {
|
|
44
|
+
const result = validator.validate(value);
|
|
45
|
+
last = result.errors;
|
|
46
|
+
return result.valid;
|
|
47
|
+
},
|
|
48
|
+
errors: () => last,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function requiredSections(frontmatter) {
|
|
52
|
+
const sections = [
|
|
53
|
+
frontmatter.type === "research" ||
|
|
54
|
+
frontmatter.type === "decision" ||
|
|
55
|
+
frontmatter.type === "prototype"
|
|
56
|
+
? "Question"
|
|
57
|
+
: "Outcome",
|
|
58
|
+
"Context",
|
|
59
|
+
"Acceptance criteria",
|
|
60
|
+
"Verification",
|
|
61
|
+
];
|
|
62
|
+
if (frontmatter.type === "bug")
|
|
63
|
+
sections.splice(1, 0, "Reproduction");
|
|
64
|
+
if (frontmatter.type === "research" || frontmatter.type === "decision")
|
|
65
|
+
sections.splice(1, 0, "Answer");
|
|
66
|
+
if (TERMINAL_STATUSES.has(frontmatter.status))
|
|
67
|
+
sections.push("Resolution");
|
|
68
|
+
return sections;
|
|
69
|
+
}
|
|
70
|
+
function validateBody(path, body, frontmatter) {
|
|
71
|
+
const diagnostics = [];
|
|
72
|
+
const headings = markdown
|
|
73
|
+
.parse(body)
|
|
74
|
+
.children.filter((node) => node.type === "heading");
|
|
75
|
+
const titleHeading = headings.find((heading) => heading.depth === 1);
|
|
76
|
+
const title = titleHeading === undefined ? undefined : headingSource(body, titleHeading);
|
|
77
|
+
if (title !== frontmatter.title)
|
|
78
|
+
diagnostics.push({
|
|
79
|
+
path,
|
|
80
|
+
code: "title-mismatch",
|
|
81
|
+
detail: `H1 must exactly match frontmatter title ${JSON.stringify(frontmatter.title)}`,
|
|
82
|
+
});
|
|
83
|
+
const sections = new Set(headings
|
|
84
|
+
.filter((heading) => heading.depth === 2)
|
|
85
|
+
.map((heading) => headingSource(body, heading)));
|
|
86
|
+
for (const section of requiredSections(frontmatter)) {
|
|
87
|
+
if (!sections.has(section))
|
|
88
|
+
diagnostics.push({
|
|
89
|
+
path,
|
|
90
|
+
code: "missing-section",
|
|
91
|
+
detail: `missing required section ## ${section}`,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return diagnostics;
|
|
95
|
+
}
|
|
96
|
+
function parseIssue(path, source, validator, diagnostics) {
|
|
97
|
+
const pathMatch = ISSUE_PATH.exec(path);
|
|
98
|
+
if (pathMatch === null) {
|
|
99
|
+
diagnostics.push({
|
|
100
|
+
path,
|
|
101
|
+
code: "invalid-ticket-path",
|
|
102
|
+
detail: "ticket path must be issues/<effort>/<NN[a-z]>-<slug>.md",
|
|
103
|
+
});
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
const file = new VFile(source);
|
|
107
|
+
let value;
|
|
108
|
+
try {
|
|
109
|
+
matter(file, { strip: true });
|
|
110
|
+
value = Schema.decodeUnknownSync(Schema.Json)(file.data.matter);
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
diagnostics.push({
|
|
114
|
+
path,
|
|
115
|
+
code: "invalid-frontmatter",
|
|
116
|
+
detail: error instanceof Error ? error.message : "YAML parsing failed",
|
|
117
|
+
});
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
if (!validator.accepts(value)) {
|
|
121
|
+
diagnostics.push({
|
|
122
|
+
path,
|
|
123
|
+
code: "invalid-frontmatter",
|
|
124
|
+
detail: schemaDetail(validator.errors()),
|
|
125
|
+
});
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
const expectedId = `${pathMatch.groups?.effort ?? ""}-${pathMatch.groups?.number ?? ""}`;
|
|
129
|
+
if (value.id !== expectedId)
|
|
130
|
+
diagnostics.push({
|
|
131
|
+
path,
|
|
132
|
+
code: "id-path-mismatch",
|
|
133
|
+
detail: `frontmatter id must be ${expectedId}`,
|
|
134
|
+
});
|
|
135
|
+
diagnostics.push(...validateBody(path, file.toString(), value));
|
|
136
|
+
return { path, frontmatter: value };
|
|
137
|
+
}
|
|
138
|
+
function addGraphDiagnostics(records, diagnostics) {
|
|
139
|
+
const byId = new Map();
|
|
140
|
+
for (const record of records) {
|
|
141
|
+
const existing = byId.get(record.frontmatter.id);
|
|
142
|
+
if (existing !== undefined) {
|
|
143
|
+
diagnostics.push({
|
|
144
|
+
path: record.path,
|
|
145
|
+
code: "duplicate-id",
|
|
146
|
+
detail: `issue id duplicates ${existing.path}`,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
else
|
|
150
|
+
byId.set(record.frontmatter.id, record);
|
|
151
|
+
}
|
|
152
|
+
for (const record of records) {
|
|
153
|
+
for (const blocker of record.frontmatter.blocked_by) {
|
|
154
|
+
if (blocker === record.frontmatter.id)
|
|
155
|
+
diagnostics.push({
|
|
156
|
+
path: record.path,
|
|
157
|
+
code: "self-blocker",
|
|
158
|
+
detail: "an issue cannot block itself",
|
|
159
|
+
});
|
|
160
|
+
else if (!byId.has(blocker))
|
|
161
|
+
diagnostics.push({
|
|
162
|
+
path: record.path,
|
|
163
|
+
code: "unknown-blocker",
|
|
164
|
+
detail: `blocked_by references unknown issue ${blocker}`,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
addCycleDiagnostics(byId, diagnostics);
|
|
169
|
+
return byId;
|
|
170
|
+
}
|
|
171
|
+
function addCycleDiagnostics(records, diagnostics) {
|
|
172
|
+
const state = new Map();
|
|
173
|
+
const stack = [];
|
|
174
|
+
const reported = new Set();
|
|
175
|
+
for (const root of records.values()) {
|
|
176
|
+
const rootId = root.frontmatter.id;
|
|
177
|
+
if (state.has(rootId))
|
|
178
|
+
continue;
|
|
179
|
+
const frames = [
|
|
180
|
+
{ record: root, blockers: root.frontmatter.blocked_by.values() },
|
|
181
|
+
];
|
|
182
|
+
state.set(rootId, "visiting");
|
|
183
|
+
stack.push(rootId);
|
|
184
|
+
while (frames.length > 0) {
|
|
185
|
+
const frame = frames.at(-1);
|
|
186
|
+
if (frame === undefined)
|
|
187
|
+
throw new Error("Issue graph traversal lost its active frame");
|
|
188
|
+
const next = frame.blockers.next();
|
|
189
|
+
if (next.done) {
|
|
190
|
+
state.set(frame.record.frontmatter.id, "visited");
|
|
191
|
+
frames.pop();
|
|
192
|
+
stack.pop();
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
const blocker = next.value;
|
|
196
|
+
const record = records.get(blocker);
|
|
197
|
+
if (record === undefined)
|
|
198
|
+
continue;
|
|
199
|
+
if (state.get(blocker) === "visiting") {
|
|
200
|
+
const start = stack.indexOf(blocker);
|
|
201
|
+
const cycle = [...stack.slice(start), blocker];
|
|
202
|
+
const key = [...new Set(cycle)].sort().join("|");
|
|
203
|
+
if (!reported.has(key)) {
|
|
204
|
+
reported.add(key);
|
|
205
|
+
diagnostics.push({
|
|
206
|
+
path: frame.record.path,
|
|
207
|
+
code: "blocker-cycle",
|
|
208
|
+
detail: `blocker cycle: ${cycle.join(" -> ")}`,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else if (!state.has(blocker)) {
|
|
213
|
+
state.set(blocker, "visiting");
|
|
214
|
+
stack.push(blocker);
|
|
215
|
+
frames.push({
|
|
216
|
+
record,
|
|
217
|
+
blockers: record.frontmatter.blocked_by.values(),
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
function issueSummaries(records) {
|
|
224
|
+
return [...records.values()]
|
|
225
|
+
.sort((left, right) => left.path.localeCompare(right.path))
|
|
226
|
+
.map((record) => ({
|
|
227
|
+
id: record.frontmatter.id,
|
|
228
|
+
path: record.path,
|
|
229
|
+
status: record.frontmatter.status,
|
|
230
|
+
blocked: record.frontmatter.blocked_by.some((blocker) => {
|
|
231
|
+
const blockingRecord = records.get(blocker);
|
|
232
|
+
return (blockingRecord === undefined ||
|
|
233
|
+
!TERMINAL_STATUSES.has(blockingRecord.frontmatter.status));
|
|
234
|
+
}),
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
/** Validate one pushed `issues/` tree as a schema and dependency graph. */
|
|
238
|
+
export function inspectIssueTree(files) {
|
|
239
|
+
const validator = frontmatterCheck();
|
|
240
|
+
const diagnostics = [];
|
|
241
|
+
const records = [];
|
|
242
|
+
for (const [path, source] of Object.entries(files).sort(([left], [right]) => left.localeCompare(right))) {
|
|
243
|
+
if (!path.endsWith(".md"))
|
|
244
|
+
continue;
|
|
245
|
+
if (!isTrackerRecord(path))
|
|
246
|
+
continue;
|
|
247
|
+
const parsed = parseIssue(path, source, validator, diagnostics);
|
|
248
|
+
if (parsed !== null)
|
|
249
|
+
records.push(parsed);
|
|
250
|
+
}
|
|
251
|
+
const recordsById = addGraphDiagnostics(records, diagnostics);
|
|
252
|
+
const issues = issueSummaries(recordsById);
|
|
253
|
+
const issueById = new Map(issues.map((issue) => [issue.id, issue]));
|
|
254
|
+
const valid = diagnostics.length === 0;
|
|
255
|
+
const indexedRecords = valid
|
|
256
|
+
? [...recordsById.values()]
|
|
257
|
+
.sort((left, right) => left.path.localeCompare(right.path))
|
|
258
|
+
.map((record) => {
|
|
259
|
+
const summary = issueById.get(record.frontmatter.id);
|
|
260
|
+
if (summary === undefined)
|
|
261
|
+
throw new Error("Validated issue record has no summary");
|
|
262
|
+
const { id, title, status, priority, assignee, areas, blocked_by } = record.frontmatter;
|
|
263
|
+
return {
|
|
264
|
+
id,
|
|
265
|
+
title,
|
|
266
|
+
status,
|
|
267
|
+
priority,
|
|
268
|
+
assignee,
|
|
269
|
+
areas,
|
|
270
|
+
blocked_by,
|
|
271
|
+
path: record.path,
|
|
272
|
+
blocked: summary.blocked,
|
|
273
|
+
};
|
|
274
|
+
})
|
|
275
|
+
: [];
|
|
276
|
+
return {
|
|
277
|
+
schemaVersion: 1,
|
|
278
|
+
status: valid ? "pass" : "fail",
|
|
279
|
+
issues,
|
|
280
|
+
records: indexedRecords,
|
|
281
|
+
frontier: issues
|
|
282
|
+
.filter((issue) => !issue.blocked &&
|
|
283
|
+
FRONTIER_STATUSES.has(issue.status) &&
|
|
284
|
+
recordsById.get(issue.id)?.frontmatter.assignee === null)
|
|
285
|
+
.map((issue) => issue.id),
|
|
286
|
+
diagnostics: diagnostics.sort((left, right) => left.path.localeCompare(right.path) ||
|
|
287
|
+
left.code.localeCompare(right.code)),
|
|
288
|
+
};
|
|
289
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fungi.computer/issues",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"author": "Levi <levi@technomancy.dev>",
|
|
5
|
+
"private": false,
|
|
6
|
+
"description": "Pure validation and metadata projection for a complete issue tree",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@cfworker/json-schema": "4.1.1",
|
|
24
|
+
"effect": "4.0.2",
|
|
25
|
+
"remark-parse": "11.0.0",
|
|
26
|
+
"unified": "11.0.5",
|
|
27
|
+
"vfile": "6.0.3",
|
|
28
|
+
"vfile-matter": "5.0.1"
|
|
29
|
+
},
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/fungi-computer/issues.git"
|
|
34
|
+
}
|
|
6
35
|
}
|