@ultimat3/manifest 31.33.0 → 31.35.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/manifest",
3
- "version": "31.33.0",
3
+ "version": "31.35.0",
4
4
  "description": "x.manifest.json: deterministic generated facts, contract diff, AGENTS.md budget",
5
5
  "keywords": [
6
6
  "ultimate",
@@ -43,12 +43,12 @@
43
43
  "test": "bun test"
44
44
  },
45
45
  "dependencies": {
46
- "@ultimat3/action": "31.33.0",
47
- "@ultimat3/core": "31.33.0",
48
- "@ultimat3/entity": "31.33.0",
49
- "@ultimat3/jobs": "31.33.0",
50
- "@ultimat3/query": "31.33.0",
51
- "@ultimat3/realtime": "31.33.0",
52
- "@ultimat3/schema": "31.33.0"
46
+ "@ultimat3/action": "31.35.0",
47
+ "@ultimat3/core": "31.35.0",
48
+ "@ultimat3/entity": "31.35.0",
49
+ "@ultimat3/jobs": "31.35.0",
50
+ "@ultimat3/query": "31.35.0",
51
+ "@ultimat3/realtime": "31.35.0",
52
+ "@ultimat3/schema": "31.35.0"
53
53
  }
54
54
  }
package/src/docs-wiki.ts CHANGED
@@ -28,7 +28,90 @@ export interface WikiHeading {
28
28
  readonly line: number;
29
29
  }
30
30
 
31
- const HEADING = /^ {0,3}(#{1,6})[ \t]+(.*?)(?:[ \t]+#+)?[ \t]*$/;
31
+ // Linear by construction, every reader below (CodeQL js/polynomial-redos, sweep 8b-3): the regexes
32
+ // they replace answered the same strings and retried a run from each of its characters —
33
+ // `/^ {0,3}(#{1,6})[ \t]+(.*?)(?:[ \t]+#+)?[ \t]*$/` took over 15 s on a CRLF heading of 10k
34
+ // spaces, the link pattern over 15 s on 100k `![`, the tag pattern 4.3 s on 100k `<`.
35
+
36
+ const isBlank = (char: string | undefined): boolean => char === ' ' || char === '\t';
37
+ /** What `.` refuses to match without the `s` flag: a heading line holding one is no heading. */
38
+ const LINE_TERMINATOR = /[\n\r\u2028\u2029]/;
39
+
40
+ /**
41
+ * An ATX heading, `#` to `######`: up to three spaces, the marks, a blank, then the text without
42
+ * its closing `#` run (only when a blank precedes it) and without trailing blanks.
43
+ */
44
+ function atxHeading(
45
+ text: string,
46
+ ): { readonly level: number; readonly heading: string } | undefined {
47
+ let at = 0;
48
+ while (at < 3 && text[at] === ' ') at += 1;
49
+ let marks = at;
50
+ while (text[marks] === '#') marks += 1;
51
+ const level = marks - at;
52
+ if (level < 1 || level > 6) return undefined;
53
+ let start = marks;
54
+ while (isBlank(text[start])) start += 1;
55
+ if (start === marks) return undefined;
56
+ const rest = text.slice(start);
57
+ if (LINE_TERMINATOR.test(rest)) return undefined;
58
+ let end = rest.length;
59
+ while (end > 0 && isBlank(rest[end - 1])) end -= 1;
60
+ let closing = end;
61
+ while (closing > 0 && rest[closing - 1] === '#') closing -= 1;
62
+ if (closing === end || closing === 0 || !isBlank(rest[closing - 1])) {
63
+ return { level, heading: rest.slice(0, end) };
64
+ }
65
+ while (isBlank(rest[closing - 1])) closing -= 1;
66
+ return { level, heading: rest.slice(0, closing) };
67
+ }
68
+
69
+ /**
70
+ * `text.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')`, as one forward walk: a `[` is closed by the
71
+ * first `]` after it, which must be followed by `(` and then a `)`. Every `[` before that `]` shares
72
+ * it, so a failed one skips past it; with no `]` or no `)` left, no later link can close either.
73
+ * An image's `!` stays behind, and the slug's character filter drops it like any other `!`.
74
+ */
75
+ function linksAsText(text: string): string {
76
+ let out = '';
77
+ let kept = 0;
78
+ let from = 0;
79
+ for (;;) {
80
+ const open = text.indexOf('[', from);
81
+ const close = open === -1 ? -1 : text.indexOf(']', open + 1);
82
+ if (close === -1) break;
83
+ if (text[close + 1] !== '(') {
84
+ from = close + 1;
85
+ continue;
86
+ }
87
+ const end = text.indexOf(')', close + 2);
88
+ if (end === -1) break;
89
+ out += text.slice(kept, open) + text.slice(open + 1, close);
90
+ kept = end + 1;
91
+ from = kept;
92
+ }
93
+ return out + text.slice(kept);
94
+ }
95
+
96
+ /** `text.replace(/<[^>]+>/g, '')`, as one forward walk: `<` to the next `>`, never `<>` itself. */
97
+ function withoutTags(text: string): string {
98
+ let out = '';
99
+ let kept = 0;
100
+ let from = 0;
101
+ for (;;) {
102
+ const open = text.indexOf('<', from);
103
+ const close = open === -1 ? -1 : text.indexOf('>', open + 1);
104
+ if (close === -1) break;
105
+ if (close === open + 1) {
106
+ from = close;
107
+ continue;
108
+ }
109
+ out += text.slice(kept, open);
110
+ kept = close + 1;
111
+ from = kept;
112
+ }
113
+ return out + text.slice(kept);
114
+ }
32
115
 
33
116
  /**
34
117
  * GitHub's heading slug: links become their text, tags and backticks drop, then every character
@@ -36,9 +119,7 @@ const HEADING = /^ {0,3}(#{1,6})[ \t]+(.*?)(?:[ \t]+#+)?[ \t]*$/;
36
119
  * rule `scripts/wiki-anchors.ts` holds every wiki link to — the one copy, which it imports.
37
120
  */
38
121
  export const githubSlug = (heading: string): string =>
39
- heading
40
- .replace(/!?\[([^\]]*)\]\([^)]*\)/g, '$1')
41
- .replace(/<[^>]+>/g, '')
122
+ withoutTags(linksAsText(heading))
42
123
  .replaceAll('`', '')
43
124
  .toLowerCase()
44
125
  .replace(/[^\p{L}\p{M}\p{N}\p{Pc} -]/gu, '')
@@ -55,14 +136,14 @@ export function wikiHeadings(markdown: string): readonly WikiHeading[] {
55
136
  return;
56
137
  }
57
138
  if (fenced) return;
58
- const match = HEADING.exec(text);
59
- if (match === null) return;
60
- const heading = match[2] ?? '';
139
+ const match = atxHeading(text);
140
+ if (match === undefined) return;
141
+ const { heading, level } = match;
61
142
  const base = githubSlug(heading);
62
143
  const count = seen.get(base) ?? 0;
63
144
  seen.set(base, count + 1);
64
145
  out.push({
65
- level: (match[1] ?? '#').length,
146
+ level,
66
147
  heading,
67
148
  anchor: count === 0 ? base : `${base}-${count}`,
68
149
  line,
@@ -135,9 +216,17 @@ export function wikiSection(markdown: string, anchor: string): string | undefine
135
216
  }
136
217
 
137
218
  /**
138
- * Every page in a shipped `wiki/` directory. `Error-Codes.md` is never read: `x errors explain` is
139
- * the one way to a code, and indexing 400 rows of it would bury every other answer. A directory that
140
- * is not there is no pages, not a throw — the caller decides whether that is a broken install.
219
+ * The error reference's page set: the index `Error-Codes` and one `Error-Codes-<owner>` per owner.
220
+ * The one predicate `x docs` and its section reader both exclude by — `x errors explain` is the one
221
+ * way to a code, and indexing a thousand rows would bury every other answer.
222
+ */
223
+ export const isErrorCodesPage = (page: string): boolean =>
224
+ page === 'Error-Codes' || page.startsWith('Error-Codes-');
225
+
226
+ /**
227
+ * Every page in a shipped `wiki/` directory but the error reference (`isErrorCodesPage`). A
228
+ * directory that is not there is no pages, not a throw — the caller decides whether that is a
229
+ * broken install.
141
230
  */
142
231
  export async function scanWikiDocs(dir: string, origin: WikiOrigin): Promise<readonly DocEntry[]> {
143
232
  let files: readonly string[];
@@ -149,7 +238,7 @@ export async function scanWikiDocs(dir: string, origin: WikiOrigin): Promise<rea
149
238
  const pages = [...files]
150
239
  .sort()
151
240
  .map(wikiPageOf)
152
- .filter((page): page is string => page !== undefined && page !== 'Error-Codes');
241
+ .filter((page): page is string => page !== undefined && !isErrorCodesPage(page));
153
242
  const perPage = await Promise.all(
154
243
  pages.map(async (page) => {
155
244
  // A listed page can vanish or turn unreadable before it is read — `bun update` rewrites the
package/src/index.ts CHANGED
@@ -19,7 +19,13 @@ export type { DocHit } from './docs-search';
19
19
  export { nearestTopics, searchDocs } from './docs-search';
20
20
  export { tokenize } from './docs-tokens';
21
21
  export type { WikiHeading, WikiOrigin } from './docs-wiki';
22
- export { githubSlug, scanWikiDocs, wikiHeadings, wikiSection } from './docs-wiki';
22
+ export {
23
+ githubSlug,
24
+ isErrorCodesPage,
25
+ scanWikiDocs,
26
+ wikiHeadings,
27
+ wikiSection,
28
+ } from './docs-wiki';
23
29
  export type { EmitInput, EmitResult } from './emit';
24
30
  export {
25
31
  assertNoDrift,