chapterhouse 0.3.18 → 0.3.20

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.
@@ -1,6 +1,40 @@
1
1
  const FRONTMATTER_RE = /^---\s*\n([\s\S]*?)\n---\s*\n?/;
2
2
  const SUMMARY_MARKDOWN_RE = /(\*\*|__|[_*`~]|^\s*#+\s|\[[^\]]+\]\([^)]+\)|!\[[^\]]*\]\([^)]+\)|^\s*>)/m;
3
3
  const FRONTMATTER_TEMPLATE = `---\ntitle: <title>\nsummary: <plain-text one-line summary, max 200 chars>\nupdated: YYYY-MM-DD\ntags: []\nrelated: []\n---`;
4
+ const PROJECT_RULES_HARD_DEFAULTS = {
5
+ auto_pr: true,
6
+ require_worktree: false,
7
+ pr_draft_default: false,
8
+ default_branch: "main",
9
+ commit_co_author: "Copilot <223556219+Copilot@users.noreply.github.com>",
10
+ test_command: "",
11
+ build_command: "",
12
+ lint_command: "",
13
+ require_clean_worktree: false,
14
+ };
15
+ const KNOWN_WIKI_FRONTMATTER_FIELDS = new Set([
16
+ "title",
17
+ "summary",
18
+ "updated",
19
+ "tags",
20
+ "autostub",
21
+ "confidence",
22
+ "contested",
23
+ "contradictions",
24
+ "related",
25
+ ]);
26
+ const PROJECT_RULE_HARD_FIELDS = [
27
+ "auto_pr",
28
+ "require_worktree",
29
+ "pr_draft_default",
30
+ "default_branch",
31
+ "commit_co_author",
32
+ "test_command",
33
+ "build_command",
34
+ "lint_command",
35
+ "require_clean_worktree",
36
+ ];
37
+ const KNOWN_PROJECT_RULE_FIELDS = new Set(PROJECT_RULE_HARD_FIELDS);
4
38
  export function parseWikiFrontmatter(content) {
5
39
  const match = content.match(FRONTMATTER_RE);
6
40
  if (!match) {
@@ -41,6 +75,15 @@ export function parseWikiFrontmatter(content) {
41
75
  else
42
76
  parsed.metadata[key] = value;
43
77
  break;
78
+ case "auto_pr":
79
+ case "require_worktree":
80
+ case "pr_draft_default":
81
+ case "require_clean_worktree":
82
+ if (typeof value === "boolean")
83
+ parsed[key] = value;
84
+ else
85
+ parsed.metadata[key] = value;
86
+ break;
44
87
  case "confidence":
45
88
  if (value === "high" || value === "medium" || value === "low") {
46
89
  parsed.confidence = value;
@@ -49,6 +92,16 @@ export function parseWikiFrontmatter(content) {
49
92
  parsed.metadata[key] = value;
50
93
  }
51
94
  break;
95
+ case "default_branch":
96
+ case "commit_co_author":
97
+ case "test_command":
98
+ case "build_command":
99
+ case "lint_command":
100
+ if (typeof value === "string")
101
+ parsed[key] = value;
102
+ else
103
+ parsed.metadata[key] = value;
104
+ break;
52
105
  default:
53
106
  parsed.metadata[key] = value;
54
107
  break;
@@ -59,6 +112,17 @@ export function parseWikiFrontmatter(content) {
59
112
  body: content.slice(match[0].length),
60
113
  };
61
114
  }
115
+ export function parseProjectRulesFrontmatter(content) {
116
+ const { parsed, body } = parseWikiFrontmatter(content);
117
+ return {
118
+ parsed: {
119
+ ...parsed,
120
+ hardRules: materializeProjectRulesHardFields(parsed),
121
+ },
122
+ body,
123
+ warnings: collectUnknownProjectRuleWarnings(parsed.metadata),
124
+ };
125
+ }
62
126
  export function hasWikiFrontmatter(content) {
63
127
  return FRONTMATTER_RE.test(content);
64
128
  }
@@ -125,6 +189,25 @@ export function validateWikiFrontmatter(content, options = {}) {
125
189
  errors,
126
190
  };
127
191
  }
192
+ export function validateProjectRulesFrontmatter(content, options = {}) {
193
+ const base = validateWikiFrontmatter(content, options);
194
+ const { parsed, warnings } = parseProjectRulesFrontmatter(content);
195
+ const errors = [...base.errors];
196
+ for (const field of PROJECT_RULE_HARD_FIELDS) {
197
+ if (field in parsed.metadata) {
198
+ errors.push({
199
+ rule: "invalid-field-type",
200
+ field,
201
+ message: formatFrontmatterMessage(`invalid '${field}' type`),
202
+ });
203
+ }
204
+ }
205
+ return {
206
+ valid: errors.length === 0,
207
+ errors,
208
+ warnings,
209
+ };
210
+ }
128
211
  function formatFrontmatterMessage(reason) {
129
212
  return `Wiki page frontmatter violates the required shape: ${reason}. Use:\n${FRONTMATTER_TEMPLATE}`;
130
213
  }
@@ -145,4 +228,26 @@ function parseValue(rawValue) {
145
228
  function stripQuotes(value) {
146
229
  return value.replace(/^['"]|['"]$/g, "");
147
230
  }
231
+ function materializeProjectRulesHardFields(parsed) {
232
+ return {
233
+ auto_pr: parsed.auto_pr ?? PROJECT_RULES_HARD_DEFAULTS.auto_pr,
234
+ require_worktree: parsed.require_worktree ?? PROJECT_RULES_HARD_DEFAULTS.require_worktree,
235
+ pr_draft_default: parsed.pr_draft_default ?? PROJECT_RULES_HARD_DEFAULTS.pr_draft_default,
236
+ default_branch: parsed.default_branch ?? PROJECT_RULES_HARD_DEFAULTS.default_branch,
237
+ commit_co_author: parsed.commit_co_author ?? PROJECT_RULES_HARD_DEFAULTS.commit_co_author,
238
+ test_command: parsed.test_command ?? PROJECT_RULES_HARD_DEFAULTS.test_command,
239
+ build_command: parsed.build_command ?? PROJECT_RULES_HARD_DEFAULTS.build_command,
240
+ lint_command: parsed.lint_command ?? PROJECT_RULES_HARD_DEFAULTS.lint_command,
241
+ require_clean_worktree: parsed.require_clean_worktree ?? PROJECT_RULES_HARD_DEFAULTS.require_clean_worktree,
242
+ };
243
+ }
244
+ function collectUnknownProjectRuleWarnings(metadata) {
245
+ return Object.keys(metadata)
246
+ .filter((field) => !KNOWN_WIKI_FRONTMATTER_FIELDS.has(field) && !KNOWN_PROJECT_RULE_FIELDS.has(field))
247
+ .map((field) => ({
248
+ rule: "unknown-project-rule-key",
249
+ field,
250
+ message: `Project rules frontmatter includes unknown key '${field}'.`,
251
+ }));
252
+ }
148
253
  //# sourceMappingURL=frontmatter.js.map
@@ -106,4 +106,124 @@ tags: [engineering, made-up-tag]
106
106
  assert.deepEqual(result.errors.map((error) => error.rule), ["unknown-tag"]);
107
107
  assert.match(result.errors[0]?.message ?? "", /Add it to `pages\/_meta\/taxonomy\.md` first\./);
108
108
  });
109
+ test("parseProjectRulesFrontmatter parses typed hard-rule fields and flags unknown keys", async () => {
110
+ const { parseProjectRulesFrontmatter } = await loadFrontmatterModule();
111
+ const result = parseProjectRulesFrontmatter(`---
112
+ title: Project rules for chapterhouse
113
+ summary: Project-specific operating rules for Chapterhouse itself.
114
+ updated: 2026-05-12
115
+ tags: [engineering, workflow]
116
+ related: []
117
+ auto_pr: false
118
+ require_worktree: true
119
+ pr_draft_default: true
120
+ default_branch: trunk
121
+ commit_co_author: Jane Doe <jane@example.com>
122
+ test_command: npm test
123
+ build_command: npm run build
124
+ lint_command: npm run lint
125
+ require_clean_worktree: true
126
+ custom_rule: preserve-me
127
+ ---
128
+
129
+ ## Soft Rules
130
+ `);
131
+ assert.deepEqual(result, {
132
+ parsed: {
133
+ title: "Project rules for chapterhouse",
134
+ summary: "Project-specific operating rules for Chapterhouse itself.",
135
+ updated: "2026-05-12",
136
+ tags: ["engineering", "workflow"],
137
+ related: [],
138
+ auto_pr: false,
139
+ require_worktree: true,
140
+ pr_draft_default: true,
141
+ default_branch: "trunk",
142
+ commit_co_author: "Jane Doe <jane@example.com>",
143
+ test_command: "npm test",
144
+ build_command: "npm run build",
145
+ lint_command: "npm run lint",
146
+ require_clean_worktree: true,
147
+ metadata: {
148
+ custom_rule: "preserve-me",
149
+ },
150
+ hardRules: {
151
+ auto_pr: false,
152
+ require_worktree: true,
153
+ pr_draft_default: true,
154
+ default_branch: "trunk",
155
+ commit_co_author: "Jane Doe <jane@example.com>",
156
+ test_command: "npm test",
157
+ build_command: "npm run build",
158
+ lint_command: "npm run lint",
159
+ require_clean_worktree: true,
160
+ },
161
+ },
162
+ body: "## Soft Rules\n",
163
+ warnings: [
164
+ {
165
+ rule: "unknown-project-rule-key",
166
+ field: "custom_rule",
167
+ message: "Project rules frontmatter includes unknown key 'custom_rule'.",
168
+ },
169
+ ],
170
+ });
171
+ });
172
+ test("parseProjectRulesFrontmatter materializes defaults for omitted hard-rule fields", async () => {
173
+ const { parseProjectRulesFrontmatter } = await loadFrontmatterModule();
174
+ const result = parseProjectRulesFrontmatter(`---
175
+ title: Project rules for chapterhouse
176
+ summary: Project-specific operating rules for Chapterhouse itself.
177
+ ---
178
+
179
+ ## Soft Rules
180
+ `);
181
+ assert.deepEqual(result.parsed.hardRules, {
182
+ auto_pr: true,
183
+ require_worktree: false,
184
+ pr_draft_default: false,
185
+ default_branch: "main",
186
+ commit_co_author: "Copilot <223556219+Copilot@users.noreply.github.com>",
187
+ test_command: "",
188
+ build_command: "",
189
+ lint_command: "",
190
+ require_clean_worktree: false,
191
+ });
192
+ assert.deepEqual(result.warnings, []);
193
+ });
194
+ test("validateProjectRulesFrontmatter rejects invalid hard-rule field types and warns on unknown keys", async () => {
195
+ const { validateProjectRulesFrontmatter } = await loadFrontmatterModule();
196
+ const result = validateProjectRulesFrontmatter(`---
197
+ title: Project rules for chapterhouse
198
+ summary: Project-specific operating rules for Chapterhouse itself.
199
+ auto_pr: nope
200
+ default_branch: [main]
201
+ test_command: [npm test]
202
+ require_clean_worktree: "yes"
203
+ custom_rule: preserve-me
204
+ ---
205
+
206
+ ## Soft Rules
207
+ `);
208
+ assert.equal(result.valid, false);
209
+ assert.deepEqual(result.errors.map((error) => error.rule), [
210
+ "invalid-field-type",
211
+ "invalid-field-type",
212
+ "invalid-field-type",
213
+ "invalid-field-type",
214
+ ]);
215
+ assert.deepEqual(result.errors.map((error) => error.field), [
216
+ "auto_pr",
217
+ "default_branch",
218
+ "test_command",
219
+ "require_clean_worktree",
220
+ ]);
221
+ assert.deepEqual(result.warnings, [
222
+ {
223
+ rule: "unknown-project-rule-key",
224
+ field: "custom_rule",
225
+ message: "Project rules frontmatter includes unknown key 'custom_rule'.",
226
+ },
227
+ ]);
228
+ });
109
229
  //# sourceMappingURL=frontmatter.test.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chapterhouse",
3
- "version": "0.3.18",
3
+ "version": "0.3.20",
4
4
  "description": "Chapterhouse — a team-level AI assistant for engineering teams, built on the GitHub Copilot SDK. Web UI only.",
5
5
  "bin": {
6
6
  "chapterhouse": "dist/cli.js"