@kozou/core 0.2.0 → 0.2.1
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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseCommentTags.d.ts","sourceRoot":"","sources":["../src/parseCommentTags.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parseCommentTags.d.ts","sourceRoot":"","sources":["../src/parseCommentTags.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAyBrD,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,YAAY,EAAE,CAAC;CAC1B,CAAC;AAaF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,aAAa,CAsGtE"}
|
package/dist/parseCommentTags.js
CHANGED
|
@@ -2,14 +2,18 @@
|
|
|
2
2
|
// `@policy:`, `@example:`). See Kozou v0.1 design spec §10.1 for the
|
|
3
3
|
// tag vocabulary and §7.3.6 for the `exampleQueries` MCP surface.
|
|
4
4
|
//
|
|
5
|
-
// `@example:`
|
|
6
|
-
// carries the
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
5
|
+
// `@ai:`, `@policy:`, and `@example:` are multi-line: the tag line
|
|
6
|
+
// carries the first value (may be empty), and indented continuation
|
|
7
|
+
// lines extend it. A blank line, a non-indented line, or the next
|
|
8
|
+
// `@tag:` terminates the block.
|
|
9
|
+
// - `@ai:` / `@policy:` capture the whole block (first line plus
|
|
10
|
+
// trimmed continuation lines, joined) as a single entry, so a
|
|
11
|
+
// multi-line note is not truncated to its first line. The lines
|
|
12
|
+
// stay in `body` too (forward compat, like a single-line tag).
|
|
13
|
+
// - `@example:` collects indented continuation lines as the SQL body;
|
|
14
|
+
// the shared leading indent is stripped so `sql` reads as written,
|
|
15
|
+
// and the block is lifted out of `body` because it is surfaced
|
|
16
|
+
// separately via `examples`.
|
|
13
17
|
const KNOWN_WIDGETS = new Set([
|
|
14
18
|
'text',
|
|
15
19
|
'textarea',
|
|
@@ -25,7 +29,11 @@ const KNOWN_WIDGETS = new Set([
|
|
|
25
29
|
'currency',
|
|
26
30
|
]);
|
|
27
31
|
const KNOWN_TAGS = new Set(['ai', 'widget', 'policy', 'example']);
|
|
28
|
-
|
|
32
|
+
// Note: no `\s*` after the `:` — the captured value is `.trim()`ed in
|
|
33
|
+
// code, and a `\s*` directly before `(.*)` makes this a polynomial-ReDoS
|
|
34
|
+
// shape (both match spaces) that CodeQL flags. Leading/intra whitespace
|
|
35
|
+
// uses single, non-overlapping `\s*` groups, so matching stays linear.
|
|
36
|
+
const TAG_RE = /^\s*@([a-zA-Z_][a-zA-Z0-9_]*)\s*:(.*)$/;
|
|
29
37
|
const INDENT_RE = /^[ \t]/;
|
|
30
38
|
function isWidgetType(value) {
|
|
31
39
|
return KNOWN_WIDGETS.has(value);
|
|
@@ -46,25 +54,45 @@ export function parseCommentTags(comment) {
|
|
|
46
54
|
function flushPending() {
|
|
47
55
|
if (pending === null)
|
|
48
56
|
return;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
57
|
+
if (pending.kind === 'example') {
|
|
58
|
+
result.examples.push({
|
|
59
|
+
description: pending.description,
|
|
60
|
+
sql: dedent(pending.sqlLines).trimEnd(),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
const text = pending.lines.join('\n').trim();
|
|
65
|
+
if (pending.kind === 'ai')
|
|
66
|
+
result.ai.push(text);
|
|
67
|
+
else
|
|
68
|
+
result.policy.push(text);
|
|
69
|
+
}
|
|
53
70
|
pending = null;
|
|
54
71
|
}
|
|
55
72
|
for (const line of lines) {
|
|
56
|
-
//
|
|
57
|
-
// SQL body. An empty line is treated as part of the SQL paragraph
|
|
58
|
-
// so callers can include blank separators inside multi-statement
|
|
59
|
-
// examples.
|
|
73
|
+
// Continue an open block before treating the line as body / a tag.
|
|
60
74
|
if (pending !== null) {
|
|
61
|
-
if (
|
|
62
|
-
|
|
75
|
+
if (pending.kind === 'example') {
|
|
76
|
+
// Indented (or blank) lines extend the SQL body. A blank line is
|
|
77
|
+
// kept so multi-statement examples can include separators.
|
|
78
|
+
if (line.length === 0 || INDENT_RE.test(line)) {
|
|
79
|
+
pending.sqlLines.push(line);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else if (
|
|
84
|
+
// `@ai:` / `@policy:` continue onto indented, non-blank lines
|
|
85
|
+
// (up to the next tag, a blank line, or a non-indented line).
|
|
86
|
+
// Continuation lines stay in `body` too, like the tag line.
|
|
87
|
+
line.trim().length > 0 &&
|
|
88
|
+
INDENT_RE.test(line) &&
|
|
89
|
+
!TAG_RE.test(line)) {
|
|
90
|
+
pending.lines.push(line.trim());
|
|
91
|
+
bodyLines.push(line);
|
|
63
92
|
continue;
|
|
64
93
|
}
|
|
65
|
-
//
|
|
94
|
+
// Anything else ends the block; re-process this line below.
|
|
66
95
|
flushPending();
|
|
67
|
-
// Fall through to handle this line normally.
|
|
68
96
|
}
|
|
69
97
|
const match = TAG_RE.exec(line);
|
|
70
98
|
if (!match) {
|
|
@@ -74,8 +102,8 @@ export function parseCommentTags(comment) {
|
|
|
74
102
|
const tag = match[1].toLowerCase();
|
|
75
103
|
const value = match[2].trim();
|
|
76
104
|
if (tag === 'ai') {
|
|
77
|
-
result.ai.push(value);
|
|
78
105
|
bodyLines.push(line);
|
|
106
|
+
pending = { kind: 'ai', lines: [value] };
|
|
79
107
|
continue;
|
|
80
108
|
}
|
|
81
109
|
if (tag === 'widget') {
|
|
@@ -89,15 +117,15 @@ export function parseCommentTags(comment) {
|
|
|
89
117
|
continue;
|
|
90
118
|
}
|
|
91
119
|
if (tag === 'policy') {
|
|
92
|
-
result.policy.push(value);
|
|
93
120
|
bodyLines.push(line);
|
|
121
|
+
pending = { kind: 'policy', lines: [value] };
|
|
94
122
|
continue;
|
|
95
123
|
}
|
|
96
124
|
if (tag === 'example') {
|
|
97
125
|
// Open an example block. The continuation collector above keeps
|
|
98
126
|
// pushing indented lines into `sqlLines` until the next non-
|
|
99
127
|
// indented line, the next tag, or the end of the comment.
|
|
100
|
-
pending = { description: value, sqlLines: [] };
|
|
128
|
+
pending = { kind: 'example', description: value, sqlLines: [] };
|
|
101
129
|
continue;
|
|
102
130
|
}
|
|
103
131
|
if (!KNOWN_TAGS.has(tag)) {
|
|
@@ -106,7 +134,7 @@ export function parseCommentTags(comment) {
|
|
|
106
134
|
}
|
|
107
135
|
}
|
|
108
136
|
flushPending();
|
|
109
|
-
result.body = bodyLines.join('\n').
|
|
137
|
+
result.body = bodyLines.join('\n').trimEnd();
|
|
110
138
|
return result;
|
|
111
139
|
}
|
|
112
140
|
/** Strip the longest common leading whitespace from every non-empty
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseCommentTags.js","sourceRoot":"","sources":["../src/parseCommentTags.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,qEAAqE;AACrE,kEAAkE;AAClE,EAAE;AACF,kEAAkE;AAClE
|
|
1
|
+
{"version":3,"file":"parseCommentTags.js","sourceRoot":"","sources":["../src/parseCommentTags.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,qEAAqE;AACrE,kEAAkE;AAClE,EAAE;AACF,mEAAmE;AACnE,oEAAoE;AACpE,kEAAkE;AAClE,gCAAgC;AAChC,mEAAmE;AACnE,kEAAkE;AAClE,oEAAoE;AAC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