specdx 0.4.0-alpha.9 → 0.5.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 +7 -2
- package/README.md +283 -0
- package/dist/{check-4FSSC6HN.js → check-RH5SCXWW.js} +68 -30
- package/dist/check-RH5SCXWW.js.map +1 -0
- package/dist/{chunk-N77RNV7J.js → chunk-3YXRWQGX.js} +217 -42
- package/dist/chunk-3YXRWQGX.js.map +1 -0
- package/dist/chunk-5WRI5ZAA.js +31 -0
- package/dist/chunk-6EQIDZ4D.js +185 -0
- package/dist/chunk-6EQIDZ4D.js.map +1 -0
- package/dist/chunk-6WFNZH7F.js +2846 -0
- package/dist/chunk-6WFNZH7F.js.map +1 -0
- package/dist/{chunk-AKNPCB37.js → chunk-BMOOLUPG.js} +32 -12
- package/dist/chunk-BMOOLUPG.js.map +1 -0
- package/dist/{chunk-IHTYAW7C.js → chunk-BP3SB35W.js} +111 -7
- package/dist/chunk-BP3SB35W.js.map +1 -0
- package/dist/chunk-CQETLJTZ.js +103 -0
- package/dist/chunk-CQETLJTZ.js.map +1 -0
- package/dist/chunk-DMGABJ6T.js +41 -0
- package/dist/chunk-DMGABJ6T.js.map +1 -0
- package/dist/chunk-NHD44ZYN.js +20 -0
- package/dist/chunk-NHD44ZYN.js.map +1 -0
- package/dist/{chunk-7JXW2GTJ.js → chunk-XRWLPU24.js} +18 -2
- package/dist/chunk-XRWLPU24.js.map +1 -0
- package/dist/chunk-ZIODMXST.js +1146 -0
- package/dist/chunk-ZIODMXST.js.map +1 -0
- package/dist/diff-QO7HMAK3.js +200 -0
- package/dist/diff-QO7HMAK3.js.map +1 -0
- package/dist/{dist-4DIRTBJH.js → dist-JPWHWMV2.js} +88 -26
- package/dist/dist-JPWHWMV2.js.map +1 -0
- package/dist/{dist-RL2DT3ZE.js → dist-ROHCFKYT.js} +3 -2
- package/dist/dist-ROHCFKYT.js.map +1 -0
- package/dist/generate-MS4BM7RU.js +21 -0
- package/dist/generate-MS4BM7RU.js.map +1 -0
- package/dist/{generate-story-EFHGINHA.js → generate-story-OMM322L7.js} +43 -19
- package/dist/generate-story-OMM322L7.js.map +1 -0
- package/dist/{generate-test-plan-BO7444RG.js → generate-test-plan-75W7SZIO.js} +61 -11
- package/dist/generate-test-plan-75W7SZIO.js.map +1 -0
- package/dist/{graph-5XINV7PT.js → graph-QOTMXENE.js} +49 -11
- package/dist/graph-QOTMXENE.js.map +1 -0
- package/dist/index.d.ts +302 -0
- package/dist/index.js +2996 -357
- package/dist/index.js.map +1 -1
- package/dist/lint-LPFLHVO4.js +184 -0
- package/dist/lint-LPFLHVO4.js.map +1 -0
- package/dist/main.js +10 -229
- package/dist/main.js.map +1 -1
- package/dist/mcp-OEC43SPF.js +35 -0
- package/dist/mcp-OEC43SPF.js.map +1 -0
- package/dist/{migrate-4KF6GHLO.js → migrate-CBP2AVLH.js} +21 -9
- package/dist/migrate-CBP2AVLH.js.map +1 -0
- package/dist/{pack-DSOODXAN.js → pack-X6FSWORJ.js} +41 -13
- package/dist/pack-X6FSWORJ.js.map +1 -0
- package/dist/{ready-6DNKIHP6.js → ready-7MJWRGLT.js} +55 -14
- package/dist/ready-7MJWRGLT.js.map +1 -0
- package/dist/skills/{specdx-author-spec.md → core/specdx-author-spec/SKILL.md} +10 -6
- package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-01-frontmatter.md +1 -1
- package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-02-sections.md +41 -0
- package/dist/skills/{specdx-onboard.md → core/specdx-onboard/SKILL.md} +8 -3
- package/dist/skills/{specdx-plan-from-spec.md → core/specdx-plan-from-spec/SKILL.md} +5 -1
- package/dist/skills/{specdx-pre-commit.md → core/specdx-pre-commit/SKILL.md} +16 -2
- package/dist/skills/{specdx-review-spec.md → core/specdx-review-spec/SKILL.md} +5 -1
- package/dist/skills/core/specdx-router/SKILL.md +67 -0
- package/dist/skills/{specdx-sprint-review.md → core/specdx-sprint-review/SKILL.md} +6 -2
- package/dist/skills/{specdx-start-task.md → core/specdx-start-task/SKILL.md} +5 -1
- package/dist/skills/{specdx-check-drift.md → experimental/specdx-check-drift/SKILL.md} +10 -4
- package/dist/skills/{specdx-verify.md → experimental/specdx-verify/SKILL.md} +6 -2
- package/dist/skills-36SRUEMR.js +121 -0
- package/dist/skills-36SRUEMR.js.map +1 -0
- package/dist/{status-WZK247CI.js → status-UUPZYX3J.js} +63 -32
- package/dist/status-UUPZYX3J.js.map +1 -0
- package/dist/{update-JTNSYX3B.js → update-EI7IJRHG.js} +22 -12
- package/dist/update-EI7IJRHG.js.map +1 -0
- package/dist/{validate-LBDYWUDX.js → validate-HTTZLQWI.js} +36 -17
- package/dist/validate-HTTZLQWI.js.map +1 -0
- package/hooks/hooks.json +12 -6
- package/hooks/session-start +35 -3
- package/package.json +28 -13
- package/dist/changelog-XUVHY3QK.js +0 -93
- package/dist/changelog-XUVHY3QK.js.map +0 -1
- package/dist/check-4FSSC6HN.js.map +0 -1
- package/dist/chunk-7JXW2GTJ.js.map +0 -1
- package/dist/chunk-AKNPCB37.js.map +0 -1
- package/dist/chunk-DAZCOUVK.js +0 -496
- package/dist/chunk-DAZCOUVK.js.map +0 -1
- package/dist/chunk-GAM4MXPC.js +0 -15
- package/dist/chunk-GAM4MXPC.js.map +0 -1
- package/dist/chunk-IHTYAW7C.js.map +0 -1
- package/dist/chunk-N77RNV7J.js.map +0 -1
- package/dist/chunk-SRZ33RJP.js +0 -1147
- package/dist/chunk-SRZ33RJP.js.map +0 -1
- package/dist/diff-OXZ34NU4.js +0 -107
- package/dist/diff-OXZ34NU4.js.map +0 -1
- package/dist/dist-4DIRTBJH.js.map +0 -1
- package/dist/explain-QBV3AESQ.js +0 -109
- package/dist/explain-QBV3AESQ.js.map +0 -1
- package/dist/generate-7GNPT2WJ.js +0 -13
- package/dist/generate-7GNPT2WJ.js.map +0 -1
- package/dist/generate-story-EFHGINHA.js.map +0 -1
- package/dist/generate-test-plan-BO7444RG.js.map +0 -1
- package/dist/graph-5XINV7PT.js.map +0 -1
- package/dist/lint-PTMWMLDQ.js +0 -122
- package/dist/lint-PTMWMLDQ.js.map +0 -1
- package/dist/mcp-BGFAPM6G.js +0 -17
- package/dist/mcp-BGFAPM6G.js.map +0 -1
- package/dist/migrate-4KF6GHLO.js.map +0 -1
- package/dist/pack-DSOODXAN.js.map +0 -1
- package/dist/ready-6DNKIHP6.js.map +0 -1
- package/dist/skills-3GBBWZW2.js +0 -93
- package/dist/skills-3GBBWZW2.js.map +0 -1
- package/dist/status-WZK247CI.js.map +0 -1
- package/dist/update-JTNSYX3B.js.map +0 -1
- package/dist/validate-LBDYWUDX.js.map +0 -1
- /package/dist/{dist-RL2DT3ZE.js.map → chunk-5WRI5ZAA.js.map} +0 -0
- /package/dist/skills/{spec-type-reference.md → core/specdx-author-spec/references/spec-type-reference.md} +0 -0
- /package/dist/skills/{specdx-author-spec → core/specdx-author-spec/references}/step-03-finalize.md +0 -0
package/dist/index.js
CHANGED
|
@@ -1,7 +1,1551 @@
|
|
|
1
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/constants.js
|
|
28
|
+
var require_constants = __commonJS({
|
|
29
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/constants.js"(exports, module) {
|
|
30
|
+
"use strict";
|
|
31
|
+
var WIN_SLASH = "\\\\/";
|
|
32
|
+
var WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
33
|
+
var DOT_LITERAL = "\\.";
|
|
34
|
+
var PLUS_LITERAL = "\\+";
|
|
35
|
+
var QMARK_LITERAL = "\\?";
|
|
36
|
+
var SLASH_LITERAL = "\\/";
|
|
37
|
+
var ONE_CHAR = "(?=.)";
|
|
38
|
+
var QMARK = "[^/]";
|
|
39
|
+
var END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
|
|
40
|
+
var START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
|
|
41
|
+
var DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
|
|
42
|
+
var NO_DOT = `(?!${DOT_LITERAL})`;
|
|
43
|
+
var NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
|
|
44
|
+
var NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
|
|
45
|
+
var NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
|
|
46
|
+
var QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
|
|
47
|
+
var STAR = `${QMARK}*?`;
|
|
48
|
+
var SEP = "/";
|
|
49
|
+
var POSIX_CHARS = {
|
|
50
|
+
DOT_LITERAL,
|
|
51
|
+
PLUS_LITERAL,
|
|
52
|
+
QMARK_LITERAL,
|
|
53
|
+
SLASH_LITERAL,
|
|
54
|
+
ONE_CHAR,
|
|
55
|
+
QMARK,
|
|
56
|
+
END_ANCHOR,
|
|
57
|
+
DOTS_SLASH,
|
|
58
|
+
NO_DOT,
|
|
59
|
+
NO_DOTS,
|
|
60
|
+
NO_DOT_SLASH,
|
|
61
|
+
NO_DOTS_SLASH,
|
|
62
|
+
QMARK_NO_DOT,
|
|
63
|
+
STAR,
|
|
64
|
+
START_ANCHOR,
|
|
65
|
+
SEP
|
|
66
|
+
};
|
|
67
|
+
var WINDOWS_CHARS = {
|
|
68
|
+
...POSIX_CHARS,
|
|
69
|
+
SLASH_LITERAL: `[${WIN_SLASH}]`,
|
|
70
|
+
QMARK: WIN_NO_SLASH,
|
|
71
|
+
STAR: `${WIN_NO_SLASH}*?`,
|
|
72
|
+
DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
|
|
73
|
+
NO_DOT: `(?!${DOT_LITERAL})`,
|
|
74
|
+
NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
75
|
+
NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
|
|
76
|
+
NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
|
|
77
|
+
QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
|
|
78
|
+
START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
|
|
79
|
+
END_ANCHOR: `(?:[${WIN_SLASH}]|$)`,
|
|
80
|
+
SEP: "\\"
|
|
81
|
+
};
|
|
82
|
+
var POSIX_REGEX_SOURCE = {
|
|
83
|
+
alnum: "a-zA-Z0-9",
|
|
84
|
+
alpha: "a-zA-Z",
|
|
85
|
+
ascii: "\\x00-\\x7F",
|
|
86
|
+
blank: " \\t",
|
|
87
|
+
cntrl: "\\x00-\\x1F\\x7F",
|
|
88
|
+
digit: "0-9",
|
|
89
|
+
graph: "\\x21-\\x7E",
|
|
90
|
+
lower: "a-z",
|
|
91
|
+
print: "\\x20-\\x7E ",
|
|
92
|
+
punct: "\\-!\"#$%&'()\\*+,./:;<=>?@[\\]^_`{|}~",
|
|
93
|
+
space: " \\t\\r\\n\\v\\f",
|
|
94
|
+
upper: "A-Z",
|
|
95
|
+
word: "A-Za-z0-9_",
|
|
96
|
+
xdigit: "A-Fa-f0-9"
|
|
97
|
+
};
|
|
98
|
+
module.exports = {
|
|
99
|
+
MAX_LENGTH: 1024 * 64,
|
|
100
|
+
POSIX_REGEX_SOURCE,
|
|
101
|
+
// regular expressions
|
|
102
|
+
REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
|
|
103
|
+
REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
|
|
104
|
+
REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
|
|
105
|
+
REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
|
|
106
|
+
REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
|
|
107
|
+
REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
|
|
108
|
+
// Replace globs with equivalent patterns to reduce parsing time.
|
|
109
|
+
REPLACEMENTS: {
|
|
110
|
+
__proto__: null,
|
|
111
|
+
"***": "*",
|
|
112
|
+
"**/**": "**",
|
|
113
|
+
"**/**/**": "**"
|
|
114
|
+
},
|
|
115
|
+
// Digits
|
|
116
|
+
CHAR_0: 48,
|
|
117
|
+
/* 0 */
|
|
118
|
+
CHAR_9: 57,
|
|
119
|
+
/* 9 */
|
|
120
|
+
// Alphabet chars.
|
|
121
|
+
CHAR_UPPERCASE_A: 65,
|
|
122
|
+
/* A */
|
|
123
|
+
CHAR_LOWERCASE_A: 97,
|
|
124
|
+
/* a */
|
|
125
|
+
CHAR_UPPERCASE_Z: 90,
|
|
126
|
+
/* Z */
|
|
127
|
+
CHAR_LOWERCASE_Z: 122,
|
|
128
|
+
/* z */
|
|
129
|
+
CHAR_LEFT_PARENTHESES: 40,
|
|
130
|
+
/* ( */
|
|
131
|
+
CHAR_RIGHT_PARENTHESES: 41,
|
|
132
|
+
/* ) */
|
|
133
|
+
CHAR_ASTERISK: 42,
|
|
134
|
+
/* * */
|
|
135
|
+
// Non-alphabetic chars.
|
|
136
|
+
CHAR_AMPERSAND: 38,
|
|
137
|
+
/* & */
|
|
138
|
+
CHAR_AT: 64,
|
|
139
|
+
/* @ */
|
|
140
|
+
CHAR_BACKWARD_SLASH: 92,
|
|
141
|
+
/* \ */
|
|
142
|
+
CHAR_CARRIAGE_RETURN: 13,
|
|
143
|
+
/* \r */
|
|
144
|
+
CHAR_CIRCUMFLEX_ACCENT: 94,
|
|
145
|
+
/* ^ */
|
|
146
|
+
CHAR_COLON: 58,
|
|
147
|
+
/* : */
|
|
148
|
+
CHAR_COMMA: 44,
|
|
149
|
+
/* , */
|
|
150
|
+
CHAR_DOT: 46,
|
|
151
|
+
/* . */
|
|
152
|
+
CHAR_DOUBLE_QUOTE: 34,
|
|
153
|
+
/* " */
|
|
154
|
+
CHAR_EQUAL: 61,
|
|
155
|
+
/* = */
|
|
156
|
+
CHAR_EXCLAMATION_MARK: 33,
|
|
157
|
+
/* ! */
|
|
158
|
+
CHAR_FORM_FEED: 12,
|
|
159
|
+
/* \f */
|
|
160
|
+
CHAR_FORWARD_SLASH: 47,
|
|
161
|
+
/* / */
|
|
162
|
+
CHAR_GRAVE_ACCENT: 96,
|
|
163
|
+
/* ` */
|
|
164
|
+
CHAR_HASH: 35,
|
|
165
|
+
/* # */
|
|
166
|
+
CHAR_HYPHEN_MINUS: 45,
|
|
167
|
+
/* - */
|
|
168
|
+
CHAR_LEFT_ANGLE_BRACKET: 60,
|
|
169
|
+
/* < */
|
|
170
|
+
CHAR_LEFT_CURLY_BRACE: 123,
|
|
171
|
+
/* { */
|
|
172
|
+
CHAR_LEFT_SQUARE_BRACKET: 91,
|
|
173
|
+
/* [ */
|
|
174
|
+
CHAR_LINE_FEED: 10,
|
|
175
|
+
/* \n */
|
|
176
|
+
CHAR_NO_BREAK_SPACE: 160,
|
|
177
|
+
/* \u00A0 */
|
|
178
|
+
CHAR_PERCENT: 37,
|
|
179
|
+
/* % */
|
|
180
|
+
CHAR_PLUS: 43,
|
|
181
|
+
/* + */
|
|
182
|
+
CHAR_QUESTION_MARK: 63,
|
|
183
|
+
/* ? */
|
|
184
|
+
CHAR_RIGHT_ANGLE_BRACKET: 62,
|
|
185
|
+
/* > */
|
|
186
|
+
CHAR_RIGHT_CURLY_BRACE: 125,
|
|
187
|
+
/* } */
|
|
188
|
+
CHAR_RIGHT_SQUARE_BRACKET: 93,
|
|
189
|
+
/* ] */
|
|
190
|
+
CHAR_SEMICOLON: 59,
|
|
191
|
+
/* ; */
|
|
192
|
+
CHAR_SINGLE_QUOTE: 39,
|
|
193
|
+
/* ' */
|
|
194
|
+
CHAR_SPACE: 32,
|
|
195
|
+
/* */
|
|
196
|
+
CHAR_TAB: 9,
|
|
197
|
+
/* \t */
|
|
198
|
+
CHAR_UNDERSCORE: 95,
|
|
199
|
+
/* _ */
|
|
200
|
+
CHAR_VERTICAL_LINE: 124,
|
|
201
|
+
/* | */
|
|
202
|
+
CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
|
|
203
|
+
/* \uFEFF */
|
|
204
|
+
/**
|
|
205
|
+
* Create EXTGLOB_CHARS
|
|
206
|
+
*/
|
|
207
|
+
extglobChars(chars) {
|
|
208
|
+
return {
|
|
209
|
+
"!": { type: "negate", open: "(?:(?!(?:", close: `))${chars.STAR})` },
|
|
210
|
+
"?": { type: "qmark", open: "(?:", close: ")?" },
|
|
211
|
+
"+": { type: "plus", open: "(?:", close: ")+" },
|
|
212
|
+
"*": { type: "star", open: "(?:", close: ")*" },
|
|
213
|
+
"@": { type: "at", open: "(?:", close: ")" }
|
|
214
|
+
};
|
|
215
|
+
},
|
|
216
|
+
/**
|
|
217
|
+
* Create GLOB_CHARS
|
|
218
|
+
*/
|
|
219
|
+
globChars(win32) {
|
|
220
|
+
return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/utils.js
|
|
227
|
+
var require_utils = __commonJS({
|
|
228
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/utils.js"(exports) {
|
|
229
|
+
"use strict";
|
|
230
|
+
var {
|
|
231
|
+
REGEX_BACKSLASH,
|
|
232
|
+
REGEX_REMOVE_BACKSLASH,
|
|
233
|
+
REGEX_SPECIAL_CHARS,
|
|
234
|
+
REGEX_SPECIAL_CHARS_GLOBAL
|
|
235
|
+
} = require_constants();
|
|
236
|
+
exports.isObject = (val) => val !== null && typeof val === "object" && !Array.isArray(val);
|
|
237
|
+
exports.hasRegexChars = (str) => REGEX_SPECIAL_CHARS.test(str);
|
|
238
|
+
exports.isRegexChar = (str) => str.length === 1 && exports.hasRegexChars(str);
|
|
239
|
+
exports.escapeRegex = (str) => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, "\\$1");
|
|
240
|
+
exports.toPosixSlashes = (str) => str.replace(REGEX_BACKSLASH, "/");
|
|
241
|
+
exports.isWindows = () => {
|
|
242
|
+
if (typeof navigator !== "undefined" && navigator.platform) {
|
|
243
|
+
const platform = navigator.platform.toLowerCase();
|
|
244
|
+
return platform === "win32" || platform === "windows";
|
|
245
|
+
}
|
|
246
|
+
if (typeof process !== "undefined" && process.platform) {
|
|
247
|
+
return process.platform === "win32";
|
|
248
|
+
}
|
|
249
|
+
return false;
|
|
250
|
+
};
|
|
251
|
+
exports.removeBackslashes = (str) => {
|
|
252
|
+
return str.replace(REGEX_REMOVE_BACKSLASH, (match) => {
|
|
253
|
+
return match === "\\" ? "" : match;
|
|
254
|
+
});
|
|
255
|
+
};
|
|
256
|
+
exports.escapeLast = (input, char, lastIdx) => {
|
|
257
|
+
const idx = input.lastIndexOf(char, lastIdx);
|
|
258
|
+
if (idx === -1) return input;
|
|
259
|
+
if (input[idx - 1] === "\\") return exports.escapeLast(input, char, idx - 1);
|
|
260
|
+
return `${input.slice(0, idx)}\\${input.slice(idx)}`;
|
|
261
|
+
};
|
|
262
|
+
exports.removePrefix = (input, state = {}) => {
|
|
263
|
+
let output = input;
|
|
264
|
+
if (output.startsWith("./")) {
|
|
265
|
+
output = output.slice(2);
|
|
266
|
+
state.prefix = "./";
|
|
267
|
+
}
|
|
268
|
+
return output;
|
|
269
|
+
};
|
|
270
|
+
exports.wrapOutput = (input, state = {}, options = {}) => {
|
|
271
|
+
const prepend = options.contains ? "" : "^";
|
|
272
|
+
const append = options.contains ? "" : "$";
|
|
273
|
+
let output = `${prepend}(?:${input})${append}`;
|
|
274
|
+
if (state.negated === true) {
|
|
275
|
+
output = `(?:^(?!${output}).*$)`;
|
|
276
|
+
}
|
|
277
|
+
return output;
|
|
278
|
+
};
|
|
279
|
+
exports.basename = (path, { windows } = {}) => {
|
|
280
|
+
const segs = path.split(windows ? /[\\/]/ : "/");
|
|
281
|
+
const last = segs[segs.length - 1];
|
|
282
|
+
if (last === "") {
|
|
283
|
+
return segs[segs.length - 2];
|
|
284
|
+
}
|
|
285
|
+
return last;
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/scan.js
|
|
291
|
+
var require_scan = __commonJS({
|
|
292
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/scan.js"(exports, module) {
|
|
293
|
+
"use strict";
|
|
294
|
+
var utils = require_utils();
|
|
295
|
+
var {
|
|
296
|
+
CHAR_ASTERISK,
|
|
297
|
+
/* * */
|
|
298
|
+
CHAR_AT,
|
|
299
|
+
/* @ */
|
|
300
|
+
CHAR_BACKWARD_SLASH,
|
|
301
|
+
/* \ */
|
|
302
|
+
CHAR_COMMA,
|
|
303
|
+
/* , */
|
|
304
|
+
CHAR_DOT,
|
|
305
|
+
/* . */
|
|
306
|
+
CHAR_EXCLAMATION_MARK,
|
|
307
|
+
/* ! */
|
|
308
|
+
CHAR_FORWARD_SLASH,
|
|
309
|
+
/* / */
|
|
310
|
+
CHAR_LEFT_CURLY_BRACE,
|
|
311
|
+
/* { */
|
|
312
|
+
CHAR_LEFT_PARENTHESES,
|
|
313
|
+
/* ( */
|
|
314
|
+
CHAR_LEFT_SQUARE_BRACKET,
|
|
315
|
+
/* [ */
|
|
316
|
+
CHAR_PLUS,
|
|
317
|
+
/* + */
|
|
318
|
+
CHAR_QUESTION_MARK,
|
|
319
|
+
/* ? */
|
|
320
|
+
CHAR_RIGHT_CURLY_BRACE,
|
|
321
|
+
/* } */
|
|
322
|
+
CHAR_RIGHT_PARENTHESES,
|
|
323
|
+
/* ) */
|
|
324
|
+
CHAR_RIGHT_SQUARE_BRACKET
|
|
325
|
+
/* ] */
|
|
326
|
+
} = require_constants();
|
|
327
|
+
var isPathSeparator = (code) => {
|
|
328
|
+
return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
|
329
|
+
};
|
|
330
|
+
var depth = (token) => {
|
|
331
|
+
if (token.isPrefix !== true) {
|
|
332
|
+
token.depth = token.isGlobstar ? Infinity : 1;
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
var scan = (input, options) => {
|
|
336
|
+
const opts = options || {};
|
|
337
|
+
const length = input.length - 1;
|
|
338
|
+
const scanToEnd = opts.parts === true || opts.scanToEnd === true;
|
|
339
|
+
const slashes = [];
|
|
340
|
+
const tokens = [];
|
|
341
|
+
const parts = [];
|
|
342
|
+
let str = input;
|
|
343
|
+
let index = -1;
|
|
344
|
+
let start = 0;
|
|
345
|
+
let lastIndex = 0;
|
|
346
|
+
let isBrace = false;
|
|
347
|
+
let isBracket = false;
|
|
348
|
+
let isGlob = false;
|
|
349
|
+
let isExtglob = false;
|
|
350
|
+
let isGlobstar = false;
|
|
351
|
+
let braceEscaped = false;
|
|
352
|
+
let backslashes = false;
|
|
353
|
+
let negated = false;
|
|
354
|
+
let negatedExtglob = false;
|
|
355
|
+
let finished = false;
|
|
356
|
+
let braces = 0;
|
|
357
|
+
let prev;
|
|
358
|
+
let code;
|
|
359
|
+
let token = { value: "", depth: 0, isGlob: false };
|
|
360
|
+
const eos = () => index >= length;
|
|
361
|
+
const peek = () => str.charCodeAt(index + 1);
|
|
362
|
+
const advance = () => {
|
|
363
|
+
prev = code;
|
|
364
|
+
return str.charCodeAt(++index);
|
|
365
|
+
};
|
|
366
|
+
while (index < length) {
|
|
367
|
+
code = advance();
|
|
368
|
+
let next;
|
|
369
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
370
|
+
backslashes = token.backslashes = true;
|
|
371
|
+
code = advance();
|
|
372
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
373
|
+
braceEscaped = true;
|
|
374
|
+
}
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
|
|
378
|
+
braces++;
|
|
379
|
+
while (eos() !== true && (code = advance())) {
|
|
380
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
381
|
+
backslashes = token.backslashes = true;
|
|
382
|
+
advance();
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (code === CHAR_LEFT_CURLY_BRACE) {
|
|
386
|
+
braces++;
|
|
387
|
+
continue;
|
|
388
|
+
}
|
|
389
|
+
if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
|
|
390
|
+
isBrace = token.isBrace = true;
|
|
391
|
+
isGlob = token.isGlob = true;
|
|
392
|
+
finished = true;
|
|
393
|
+
if (scanToEnd === true) {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
break;
|
|
397
|
+
}
|
|
398
|
+
if (braceEscaped !== true && code === CHAR_COMMA) {
|
|
399
|
+
isBrace = token.isBrace = true;
|
|
400
|
+
isGlob = token.isGlob = true;
|
|
401
|
+
finished = true;
|
|
402
|
+
if (scanToEnd === true) {
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
if (code === CHAR_RIGHT_CURLY_BRACE) {
|
|
408
|
+
braces--;
|
|
409
|
+
if (braces === 0) {
|
|
410
|
+
braceEscaped = false;
|
|
411
|
+
isBrace = token.isBrace = true;
|
|
412
|
+
finished = true;
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (scanToEnd === true) {
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
if (code === CHAR_FORWARD_SLASH) {
|
|
423
|
+
slashes.push(index);
|
|
424
|
+
tokens.push(token);
|
|
425
|
+
token = { value: "", depth: 0, isGlob: false };
|
|
426
|
+
if (finished === true) continue;
|
|
427
|
+
if (prev === CHAR_DOT && index === start + 1) {
|
|
428
|
+
start += 2;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
lastIndex = index + 1;
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (opts.noext !== true) {
|
|
435
|
+
const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
|
|
436
|
+
if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
|
|
437
|
+
isGlob = token.isGlob = true;
|
|
438
|
+
isExtglob = token.isExtglob = true;
|
|
439
|
+
finished = true;
|
|
440
|
+
if (code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
441
|
+
negatedExtglob = true;
|
|
442
|
+
}
|
|
443
|
+
if (scanToEnd === true) {
|
|
444
|
+
while (eos() !== true && (code = advance())) {
|
|
445
|
+
if (code === CHAR_BACKWARD_SLASH) {
|
|
446
|
+
backslashes = token.backslashes = true;
|
|
447
|
+
code = advance();
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
451
|
+
isGlob = token.isGlob = true;
|
|
452
|
+
finished = true;
|
|
453
|
+
break;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
continue;
|
|
457
|
+
}
|
|
458
|
+
break;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
if (code === CHAR_ASTERISK) {
|
|
462
|
+
if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
|
|
463
|
+
isGlob = token.isGlob = true;
|
|
464
|
+
finished = true;
|
|
465
|
+
if (scanToEnd === true) {
|
|
466
|
+
continue;
|
|
467
|
+
}
|
|
468
|
+
break;
|
|
469
|
+
}
|
|
470
|
+
if (code === CHAR_QUESTION_MARK) {
|
|
471
|
+
isGlob = token.isGlob = true;
|
|
472
|
+
finished = true;
|
|
473
|
+
if (scanToEnd === true) {
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
break;
|
|
477
|
+
}
|
|
478
|
+
if (code === CHAR_LEFT_SQUARE_BRACKET) {
|
|
479
|
+
while (eos() !== true && (next = advance())) {
|
|
480
|
+
if (next === CHAR_BACKWARD_SLASH) {
|
|
481
|
+
backslashes = token.backslashes = true;
|
|
482
|
+
advance();
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (next === CHAR_RIGHT_SQUARE_BRACKET) {
|
|
486
|
+
isBracket = token.isBracket = true;
|
|
487
|
+
isGlob = token.isGlob = true;
|
|
488
|
+
finished = true;
|
|
489
|
+
break;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (scanToEnd === true) {
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
break;
|
|
496
|
+
}
|
|
497
|
+
if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
|
|
498
|
+
negated = token.negated = true;
|
|
499
|
+
start++;
|
|
500
|
+
continue;
|
|
501
|
+
}
|
|
502
|
+
if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
|
|
503
|
+
isGlob = token.isGlob = true;
|
|
504
|
+
if (scanToEnd === true) {
|
|
505
|
+
while (eos() !== true && (code = advance())) {
|
|
506
|
+
if (code === CHAR_LEFT_PARENTHESES) {
|
|
507
|
+
backslashes = token.backslashes = true;
|
|
508
|
+
code = advance();
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
if (code === CHAR_RIGHT_PARENTHESES) {
|
|
512
|
+
finished = true;
|
|
513
|
+
break;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
continue;
|
|
517
|
+
}
|
|
518
|
+
break;
|
|
519
|
+
}
|
|
520
|
+
if (isGlob === true) {
|
|
521
|
+
finished = true;
|
|
522
|
+
if (scanToEnd === true) {
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (opts.noext === true) {
|
|
529
|
+
isExtglob = false;
|
|
530
|
+
isGlob = false;
|
|
531
|
+
}
|
|
532
|
+
let base = str;
|
|
533
|
+
let prefix = "";
|
|
534
|
+
let glob2 = "";
|
|
535
|
+
if (start > 0) {
|
|
536
|
+
prefix = str.slice(0, start);
|
|
537
|
+
str = str.slice(start);
|
|
538
|
+
lastIndex -= start;
|
|
539
|
+
}
|
|
540
|
+
if (base && isGlob === true && lastIndex > 0) {
|
|
541
|
+
base = str.slice(0, lastIndex);
|
|
542
|
+
glob2 = str.slice(lastIndex);
|
|
543
|
+
} else if (isGlob === true) {
|
|
544
|
+
base = "";
|
|
545
|
+
glob2 = str;
|
|
546
|
+
} else {
|
|
547
|
+
base = str;
|
|
548
|
+
}
|
|
549
|
+
if (base && base !== "" && base !== "/" && base !== str) {
|
|
550
|
+
if (isPathSeparator(base.charCodeAt(base.length - 1))) {
|
|
551
|
+
base = base.slice(0, -1);
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
if (opts.unescape === true) {
|
|
555
|
+
if (glob2) glob2 = utils.removeBackslashes(glob2);
|
|
556
|
+
if (base && backslashes === true) {
|
|
557
|
+
base = utils.removeBackslashes(base);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
const state = {
|
|
561
|
+
prefix,
|
|
562
|
+
input,
|
|
563
|
+
start,
|
|
564
|
+
base,
|
|
565
|
+
glob: glob2,
|
|
566
|
+
isBrace,
|
|
567
|
+
isBracket,
|
|
568
|
+
isGlob,
|
|
569
|
+
isExtglob,
|
|
570
|
+
isGlobstar,
|
|
571
|
+
negated,
|
|
572
|
+
negatedExtglob
|
|
573
|
+
};
|
|
574
|
+
if (opts.tokens === true) {
|
|
575
|
+
state.maxDepth = 0;
|
|
576
|
+
if (!isPathSeparator(code)) {
|
|
577
|
+
tokens.push(token);
|
|
578
|
+
}
|
|
579
|
+
state.tokens = tokens;
|
|
580
|
+
}
|
|
581
|
+
if (opts.parts === true || opts.tokens === true) {
|
|
582
|
+
let prevIndex;
|
|
583
|
+
for (let idx = 0; idx < slashes.length; idx++) {
|
|
584
|
+
const n = prevIndex ? prevIndex + 1 : start;
|
|
585
|
+
const i = slashes[idx];
|
|
586
|
+
const value = input.slice(n, i);
|
|
587
|
+
if (opts.tokens) {
|
|
588
|
+
if (idx === 0 && start !== 0) {
|
|
589
|
+
tokens[idx].isPrefix = true;
|
|
590
|
+
tokens[idx].value = prefix;
|
|
591
|
+
} else {
|
|
592
|
+
tokens[idx].value = value;
|
|
593
|
+
}
|
|
594
|
+
depth(tokens[idx]);
|
|
595
|
+
state.maxDepth += tokens[idx].depth;
|
|
596
|
+
}
|
|
597
|
+
if (idx !== 0 || value !== "") {
|
|
598
|
+
parts.push(value);
|
|
599
|
+
}
|
|
600
|
+
prevIndex = i;
|
|
601
|
+
}
|
|
602
|
+
if (prevIndex && prevIndex + 1 < input.length) {
|
|
603
|
+
const value = input.slice(prevIndex + 1);
|
|
604
|
+
parts.push(value);
|
|
605
|
+
if (opts.tokens) {
|
|
606
|
+
tokens[tokens.length - 1].value = value;
|
|
607
|
+
depth(tokens[tokens.length - 1]);
|
|
608
|
+
state.maxDepth += tokens[tokens.length - 1].depth;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
state.slashes = slashes;
|
|
612
|
+
state.parts = parts;
|
|
613
|
+
}
|
|
614
|
+
return state;
|
|
615
|
+
};
|
|
616
|
+
module.exports = scan;
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/parse.js
|
|
621
|
+
var require_parse = __commonJS({
|
|
622
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/parse.js"(exports, module) {
|
|
623
|
+
"use strict";
|
|
624
|
+
var constants = require_constants();
|
|
625
|
+
var utils = require_utils();
|
|
626
|
+
var {
|
|
627
|
+
MAX_LENGTH,
|
|
628
|
+
POSIX_REGEX_SOURCE,
|
|
629
|
+
REGEX_NON_SPECIAL_CHARS,
|
|
630
|
+
REGEX_SPECIAL_CHARS_BACKREF,
|
|
631
|
+
REPLACEMENTS
|
|
632
|
+
} = constants;
|
|
633
|
+
var expandRange = (args, options) => {
|
|
634
|
+
if (typeof options.expandRange === "function") {
|
|
635
|
+
return options.expandRange(...args, options);
|
|
636
|
+
}
|
|
637
|
+
args.sort();
|
|
638
|
+
const value = `[${args.join("-")}]`;
|
|
639
|
+
try {
|
|
640
|
+
new RegExp(value);
|
|
641
|
+
} catch (ex) {
|
|
642
|
+
return args.map((v) => utils.escapeRegex(v)).join("..");
|
|
643
|
+
}
|
|
644
|
+
return value;
|
|
645
|
+
};
|
|
646
|
+
var syntaxError = (type, char) => {
|
|
647
|
+
return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
|
|
648
|
+
};
|
|
649
|
+
var parse = (input, options) => {
|
|
650
|
+
if (typeof input !== "string") {
|
|
651
|
+
throw new TypeError("Expected a string");
|
|
652
|
+
}
|
|
653
|
+
input = REPLACEMENTS[input] || input;
|
|
654
|
+
const opts = { ...options };
|
|
655
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
656
|
+
let len = input.length;
|
|
657
|
+
if (len > max) {
|
|
658
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
659
|
+
}
|
|
660
|
+
const bos = { type: "bos", value: "", output: opts.prepend || "" };
|
|
661
|
+
const tokens = [bos];
|
|
662
|
+
const capture = opts.capture ? "" : "?:";
|
|
663
|
+
const PLATFORM_CHARS = constants.globChars(opts.windows);
|
|
664
|
+
const EXTGLOB_CHARS = constants.extglobChars(PLATFORM_CHARS);
|
|
665
|
+
const {
|
|
666
|
+
DOT_LITERAL,
|
|
667
|
+
PLUS_LITERAL,
|
|
668
|
+
SLASH_LITERAL,
|
|
669
|
+
ONE_CHAR,
|
|
670
|
+
DOTS_SLASH,
|
|
671
|
+
NO_DOT,
|
|
672
|
+
NO_DOT_SLASH,
|
|
673
|
+
NO_DOTS_SLASH,
|
|
674
|
+
QMARK,
|
|
675
|
+
QMARK_NO_DOT,
|
|
676
|
+
STAR,
|
|
677
|
+
START_ANCHOR
|
|
678
|
+
} = PLATFORM_CHARS;
|
|
679
|
+
const globstar = (opts2) => {
|
|
680
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
681
|
+
};
|
|
682
|
+
const nodot = opts.dot ? "" : NO_DOT;
|
|
683
|
+
const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
|
|
684
|
+
let star = opts.bash === true ? globstar(opts) : STAR;
|
|
685
|
+
if (opts.capture) {
|
|
686
|
+
star = `(${star})`;
|
|
687
|
+
}
|
|
688
|
+
if (typeof opts.noext === "boolean") {
|
|
689
|
+
opts.noextglob = opts.noext;
|
|
690
|
+
}
|
|
691
|
+
const state = {
|
|
692
|
+
input,
|
|
693
|
+
index: -1,
|
|
694
|
+
start: 0,
|
|
695
|
+
dot: opts.dot === true,
|
|
696
|
+
consumed: "",
|
|
697
|
+
output: "",
|
|
698
|
+
prefix: "",
|
|
699
|
+
backtrack: false,
|
|
700
|
+
negated: false,
|
|
701
|
+
brackets: 0,
|
|
702
|
+
braces: 0,
|
|
703
|
+
parens: 0,
|
|
704
|
+
quotes: 0,
|
|
705
|
+
globstar: false,
|
|
706
|
+
tokens
|
|
707
|
+
};
|
|
708
|
+
input = utils.removePrefix(input, state);
|
|
709
|
+
len = input.length;
|
|
710
|
+
const extglobs = [];
|
|
711
|
+
const braces = [];
|
|
712
|
+
const stack = [];
|
|
713
|
+
let prev = bos;
|
|
714
|
+
let value;
|
|
715
|
+
const eos = () => state.index === len - 1;
|
|
716
|
+
const peek = state.peek = (n = 1) => input[state.index + n];
|
|
717
|
+
const advance = state.advance = () => input[++state.index] || "";
|
|
718
|
+
const remaining = () => input.slice(state.index + 1);
|
|
719
|
+
const consume = (value2 = "", num = 0) => {
|
|
720
|
+
state.consumed += value2;
|
|
721
|
+
state.index += num;
|
|
722
|
+
};
|
|
723
|
+
const append = (token) => {
|
|
724
|
+
state.output += token.output != null ? token.output : token.value;
|
|
725
|
+
consume(token.value);
|
|
726
|
+
};
|
|
727
|
+
const negate = () => {
|
|
728
|
+
let count = 1;
|
|
729
|
+
while (peek() === "!" && (peek(2) !== "(" || peek(3) === "?")) {
|
|
730
|
+
advance();
|
|
731
|
+
state.start++;
|
|
732
|
+
count++;
|
|
733
|
+
}
|
|
734
|
+
if (count % 2 === 0) {
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
state.negated = true;
|
|
738
|
+
state.start++;
|
|
739
|
+
return true;
|
|
740
|
+
};
|
|
741
|
+
const increment = (type) => {
|
|
742
|
+
state[type]++;
|
|
743
|
+
stack.push(type);
|
|
744
|
+
};
|
|
745
|
+
const decrement = (type) => {
|
|
746
|
+
state[type]--;
|
|
747
|
+
stack.pop();
|
|
748
|
+
};
|
|
749
|
+
const push = (tok) => {
|
|
750
|
+
if (prev.type === "globstar") {
|
|
751
|
+
const isBrace = state.braces > 0 && (tok.type === "comma" || tok.type === "brace");
|
|
752
|
+
const isExtglob = tok.extglob === true || extglobs.length && (tok.type === "pipe" || tok.type === "paren");
|
|
753
|
+
if (tok.type !== "slash" && tok.type !== "paren" && !isBrace && !isExtglob) {
|
|
754
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
755
|
+
prev.type = "star";
|
|
756
|
+
prev.value = "*";
|
|
757
|
+
prev.output = star;
|
|
758
|
+
state.output += prev.output;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
if (extglobs.length && tok.type !== "paren") {
|
|
762
|
+
extglobs[extglobs.length - 1].inner += tok.value;
|
|
763
|
+
}
|
|
764
|
+
if (tok.value || tok.output) append(tok);
|
|
765
|
+
if (prev && prev.type === "text" && tok.type === "text") {
|
|
766
|
+
prev.output = (prev.output || prev.value) + tok.value;
|
|
767
|
+
prev.value += tok.value;
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
tok.prev = prev;
|
|
771
|
+
tokens.push(tok);
|
|
772
|
+
prev = tok;
|
|
773
|
+
};
|
|
774
|
+
const extglobOpen = (type, value2) => {
|
|
775
|
+
const token = { ...EXTGLOB_CHARS[value2], conditions: 1, inner: "" };
|
|
776
|
+
token.prev = prev;
|
|
777
|
+
token.parens = state.parens;
|
|
778
|
+
token.output = state.output;
|
|
779
|
+
const output = (opts.capture ? "(" : "") + token.open;
|
|
780
|
+
increment("parens");
|
|
781
|
+
push({ type, value: value2, output: state.output ? "" : ONE_CHAR });
|
|
782
|
+
push({ type: "paren", extglob: true, value: advance(), output });
|
|
783
|
+
extglobs.push(token);
|
|
784
|
+
};
|
|
785
|
+
const extglobClose = (token) => {
|
|
786
|
+
let output = token.close + (opts.capture ? ")" : "");
|
|
787
|
+
let rest;
|
|
788
|
+
if (token.type === "negate") {
|
|
789
|
+
let extglobStar = star;
|
|
790
|
+
if (token.inner && token.inner.length > 1 && token.inner.includes("/")) {
|
|
791
|
+
extglobStar = globstar(opts);
|
|
792
|
+
}
|
|
793
|
+
if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
|
|
794
|
+
output = token.close = `)$))${extglobStar}`;
|
|
795
|
+
}
|
|
796
|
+
if (token.inner.includes("*") && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
|
|
797
|
+
const expression = parse(rest, { ...options, fastpaths: false }).output;
|
|
798
|
+
output = token.close = `)${expression})${extglobStar})`;
|
|
799
|
+
}
|
|
800
|
+
if (token.prev.type === "bos") {
|
|
801
|
+
state.negatedExtglob = true;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
push({ type: "paren", extglob: true, value, output });
|
|
805
|
+
decrement("parens");
|
|
806
|
+
};
|
|
807
|
+
if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
|
|
808
|
+
let backslashes = false;
|
|
809
|
+
let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
|
|
810
|
+
if (first === "\\") {
|
|
811
|
+
backslashes = true;
|
|
812
|
+
return m;
|
|
813
|
+
}
|
|
814
|
+
if (first === "?") {
|
|
815
|
+
if (esc) {
|
|
816
|
+
return esc + first + (rest ? QMARK.repeat(rest.length) : "");
|
|
817
|
+
}
|
|
818
|
+
if (index === 0) {
|
|
819
|
+
return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : "");
|
|
820
|
+
}
|
|
821
|
+
return QMARK.repeat(chars.length);
|
|
822
|
+
}
|
|
823
|
+
if (first === ".") {
|
|
824
|
+
return DOT_LITERAL.repeat(chars.length);
|
|
825
|
+
}
|
|
826
|
+
if (first === "*") {
|
|
827
|
+
if (esc) {
|
|
828
|
+
return esc + first + (rest ? star : "");
|
|
829
|
+
}
|
|
830
|
+
return star;
|
|
831
|
+
}
|
|
832
|
+
return esc ? m : `\\${m}`;
|
|
833
|
+
});
|
|
834
|
+
if (backslashes === true) {
|
|
835
|
+
if (opts.unescape === true) {
|
|
836
|
+
output = output.replace(/\\/g, "");
|
|
837
|
+
} else {
|
|
838
|
+
output = output.replace(/\\+/g, (m) => {
|
|
839
|
+
return m.length % 2 === 0 ? "\\\\" : m ? "\\" : "";
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (output === input && opts.contains === true) {
|
|
844
|
+
state.output = input;
|
|
845
|
+
return state;
|
|
846
|
+
}
|
|
847
|
+
state.output = utils.wrapOutput(output, state, options);
|
|
848
|
+
return state;
|
|
849
|
+
}
|
|
850
|
+
while (!eos()) {
|
|
851
|
+
value = advance();
|
|
852
|
+
if (value === "\0") {
|
|
853
|
+
continue;
|
|
854
|
+
}
|
|
855
|
+
if (value === "\\") {
|
|
856
|
+
const next = peek();
|
|
857
|
+
if (next === "/" && opts.bash !== true) {
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
860
|
+
if (next === "." || next === ";") {
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
if (!next) {
|
|
864
|
+
value += "\\";
|
|
865
|
+
push({ type: "text", value });
|
|
866
|
+
continue;
|
|
867
|
+
}
|
|
868
|
+
const match = /^\\+/.exec(remaining());
|
|
869
|
+
let slashes = 0;
|
|
870
|
+
if (match && match[0].length > 2) {
|
|
871
|
+
slashes = match[0].length;
|
|
872
|
+
state.index += slashes;
|
|
873
|
+
if (slashes % 2 !== 0) {
|
|
874
|
+
value += "\\";
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
if (opts.unescape === true) {
|
|
878
|
+
value = advance();
|
|
879
|
+
} else {
|
|
880
|
+
value += advance();
|
|
881
|
+
}
|
|
882
|
+
if (state.brackets === 0) {
|
|
883
|
+
push({ type: "text", value });
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
if (state.brackets > 0 && (value !== "]" || prev.value === "[" || prev.value === "[^")) {
|
|
888
|
+
if (opts.posix !== false && value === ":") {
|
|
889
|
+
const inner = prev.value.slice(1);
|
|
890
|
+
if (inner.includes("[")) {
|
|
891
|
+
prev.posix = true;
|
|
892
|
+
if (inner.includes(":")) {
|
|
893
|
+
const idx = prev.value.lastIndexOf("[");
|
|
894
|
+
const pre = prev.value.slice(0, idx);
|
|
895
|
+
const rest2 = prev.value.slice(idx + 2);
|
|
896
|
+
const posix = POSIX_REGEX_SOURCE[rest2];
|
|
897
|
+
if (posix) {
|
|
898
|
+
prev.value = pre + posix;
|
|
899
|
+
state.backtrack = true;
|
|
900
|
+
advance();
|
|
901
|
+
if (!bos.output && tokens.indexOf(prev) === 1) {
|
|
902
|
+
bos.output = ONE_CHAR;
|
|
903
|
+
}
|
|
904
|
+
continue;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
if (value === "[" && peek() !== ":" || value === "-" && peek() === "]") {
|
|
910
|
+
value = `\\${value}`;
|
|
911
|
+
}
|
|
912
|
+
if (value === "]" && (prev.value === "[" || prev.value === "[^")) {
|
|
913
|
+
value = `\\${value}`;
|
|
914
|
+
}
|
|
915
|
+
if (opts.posix === true && value === "!" && prev.value === "[") {
|
|
916
|
+
value = "^";
|
|
917
|
+
}
|
|
918
|
+
prev.value += value;
|
|
919
|
+
append({ value });
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
if (state.quotes === 1 && value !== '"') {
|
|
923
|
+
value = utils.escapeRegex(value);
|
|
924
|
+
prev.value += value;
|
|
925
|
+
append({ value });
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
if (value === '"') {
|
|
929
|
+
state.quotes = state.quotes === 1 ? 0 : 1;
|
|
930
|
+
if (opts.keepQuotes === true) {
|
|
931
|
+
push({ type: "text", value });
|
|
932
|
+
}
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
if (value === "(") {
|
|
936
|
+
increment("parens");
|
|
937
|
+
push({ type: "paren", value });
|
|
938
|
+
continue;
|
|
939
|
+
}
|
|
940
|
+
if (value === ")") {
|
|
941
|
+
if (state.parens === 0 && opts.strictBrackets === true) {
|
|
942
|
+
throw new SyntaxError(syntaxError("opening", "("));
|
|
943
|
+
}
|
|
944
|
+
const extglob = extglobs[extglobs.length - 1];
|
|
945
|
+
if (extglob && state.parens === extglob.parens + 1) {
|
|
946
|
+
extglobClose(extglobs.pop());
|
|
947
|
+
continue;
|
|
948
|
+
}
|
|
949
|
+
push({ type: "paren", value, output: state.parens ? ")" : "\\)" });
|
|
950
|
+
decrement("parens");
|
|
951
|
+
continue;
|
|
952
|
+
}
|
|
953
|
+
if (value === "[") {
|
|
954
|
+
if (opts.nobracket === true || !remaining().includes("]")) {
|
|
955
|
+
if (opts.nobracket !== true && opts.strictBrackets === true) {
|
|
956
|
+
throw new SyntaxError(syntaxError("closing", "]"));
|
|
957
|
+
}
|
|
958
|
+
value = `\\${value}`;
|
|
959
|
+
} else {
|
|
960
|
+
increment("brackets");
|
|
961
|
+
}
|
|
962
|
+
push({ type: "bracket", value });
|
|
963
|
+
continue;
|
|
964
|
+
}
|
|
965
|
+
if (value === "]") {
|
|
966
|
+
if (opts.nobracket === true || prev && prev.type === "bracket" && prev.value.length === 1) {
|
|
967
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
968
|
+
continue;
|
|
969
|
+
}
|
|
970
|
+
if (state.brackets === 0) {
|
|
971
|
+
if (opts.strictBrackets === true) {
|
|
972
|
+
throw new SyntaxError(syntaxError("opening", "["));
|
|
973
|
+
}
|
|
974
|
+
push({ type: "text", value, output: `\\${value}` });
|
|
975
|
+
continue;
|
|
976
|
+
}
|
|
977
|
+
decrement("brackets");
|
|
978
|
+
const prevValue = prev.value.slice(1);
|
|
979
|
+
if (prev.posix !== true && prevValue[0] === "^" && !prevValue.includes("/")) {
|
|
980
|
+
value = `/${value}`;
|
|
981
|
+
}
|
|
982
|
+
prev.value += value;
|
|
983
|
+
append({ value });
|
|
984
|
+
if (opts.literalBrackets === false || utils.hasRegexChars(prevValue)) {
|
|
985
|
+
continue;
|
|
986
|
+
}
|
|
987
|
+
const escaped = utils.escapeRegex(prev.value);
|
|
988
|
+
state.output = state.output.slice(0, -prev.value.length);
|
|
989
|
+
if (opts.literalBrackets === true) {
|
|
990
|
+
state.output += escaped;
|
|
991
|
+
prev.value = escaped;
|
|
992
|
+
continue;
|
|
993
|
+
}
|
|
994
|
+
prev.value = `(${capture}${escaped}|${prev.value})`;
|
|
995
|
+
state.output += prev.value;
|
|
996
|
+
continue;
|
|
997
|
+
}
|
|
998
|
+
if (value === "{" && opts.nobrace !== true) {
|
|
999
|
+
increment("braces");
|
|
1000
|
+
const open = {
|
|
1001
|
+
type: "brace",
|
|
1002
|
+
value,
|
|
1003
|
+
output: "(",
|
|
1004
|
+
outputIndex: state.output.length,
|
|
1005
|
+
tokensIndex: state.tokens.length
|
|
1006
|
+
};
|
|
1007
|
+
braces.push(open);
|
|
1008
|
+
push(open);
|
|
1009
|
+
continue;
|
|
1010
|
+
}
|
|
1011
|
+
if (value === "}") {
|
|
1012
|
+
const brace = braces[braces.length - 1];
|
|
1013
|
+
if (opts.nobrace === true || !brace) {
|
|
1014
|
+
push({ type: "text", value, output: value });
|
|
1015
|
+
continue;
|
|
1016
|
+
}
|
|
1017
|
+
let output = ")";
|
|
1018
|
+
if (brace.dots === true) {
|
|
1019
|
+
const arr = tokens.slice();
|
|
1020
|
+
const range = [];
|
|
1021
|
+
for (let i = arr.length - 1; i >= 0; i--) {
|
|
1022
|
+
tokens.pop();
|
|
1023
|
+
if (arr[i].type === "brace") {
|
|
1024
|
+
break;
|
|
1025
|
+
}
|
|
1026
|
+
if (arr[i].type !== "dots") {
|
|
1027
|
+
range.unshift(arr[i].value);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
output = expandRange(range, opts);
|
|
1031
|
+
state.backtrack = true;
|
|
1032
|
+
}
|
|
1033
|
+
if (brace.comma !== true && brace.dots !== true) {
|
|
1034
|
+
const out = state.output.slice(0, brace.outputIndex);
|
|
1035
|
+
const toks = state.tokens.slice(brace.tokensIndex);
|
|
1036
|
+
brace.value = brace.output = "\\{";
|
|
1037
|
+
value = output = "\\}";
|
|
1038
|
+
state.output = out;
|
|
1039
|
+
for (const t of toks) {
|
|
1040
|
+
state.output += t.output || t.value;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
push({ type: "brace", value, output });
|
|
1044
|
+
decrement("braces");
|
|
1045
|
+
braces.pop();
|
|
1046
|
+
continue;
|
|
1047
|
+
}
|
|
1048
|
+
if (value === "|") {
|
|
1049
|
+
if (extglobs.length > 0) {
|
|
1050
|
+
extglobs[extglobs.length - 1].conditions++;
|
|
1051
|
+
}
|
|
1052
|
+
push({ type: "text", value });
|
|
1053
|
+
continue;
|
|
1054
|
+
}
|
|
1055
|
+
if (value === ",") {
|
|
1056
|
+
let output = value;
|
|
1057
|
+
const brace = braces[braces.length - 1];
|
|
1058
|
+
if (brace && stack[stack.length - 1] === "braces") {
|
|
1059
|
+
brace.comma = true;
|
|
1060
|
+
output = "|";
|
|
1061
|
+
}
|
|
1062
|
+
push({ type: "comma", value, output });
|
|
1063
|
+
continue;
|
|
1064
|
+
}
|
|
1065
|
+
if (value === "/") {
|
|
1066
|
+
if (prev.type === "dot" && state.index === state.start + 1) {
|
|
1067
|
+
state.start = state.index + 1;
|
|
1068
|
+
state.consumed = "";
|
|
1069
|
+
state.output = "";
|
|
1070
|
+
tokens.pop();
|
|
1071
|
+
prev = bos;
|
|
1072
|
+
continue;
|
|
1073
|
+
}
|
|
1074
|
+
push({ type: "slash", value, output: SLASH_LITERAL });
|
|
1075
|
+
continue;
|
|
1076
|
+
}
|
|
1077
|
+
if (value === ".") {
|
|
1078
|
+
if (state.braces > 0 && prev.type === "dot") {
|
|
1079
|
+
if (prev.value === ".") prev.output = DOT_LITERAL;
|
|
1080
|
+
const brace = braces[braces.length - 1];
|
|
1081
|
+
prev.type = "dots";
|
|
1082
|
+
prev.output += value;
|
|
1083
|
+
prev.value += value;
|
|
1084
|
+
brace.dots = true;
|
|
1085
|
+
continue;
|
|
1086
|
+
}
|
|
1087
|
+
if (state.braces + state.parens === 0 && prev.type !== "bos" && prev.type !== "slash") {
|
|
1088
|
+
push({ type: "text", value, output: DOT_LITERAL });
|
|
1089
|
+
continue;
|
|
1090
|
+
}
|
|
1091
|
+
push({ type: "dot", value, output: DOT_LITERAL });
|
|
1092
|
+
continue;
|
|
1093
|
+
}
|
|
1094
|
+
if (value === "?") {
|
|
1095
|
+
const isGroup = prev && prev.value === "(";
|
|
1096
|
+
if (!isGroup && opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1097
|
+
extglobOpen("qmark", value);
|
|
1098
|
+
continue;
|
|
1099
|
+
}
|
|
1100
|
+
if (prev && prev.type === "paren") {
|
|
1101
|
+
const next = peek();
|
|
1102
|
+
let output = value;
|
|
1103
|
+
if (prev.value === "(" && !/[!=<:]/.test(next) || next === "<" && !/<([!=]|\w+>)/.test(remaining())) {
|
|
1104
|
+
output = `\\${value}`;
|
|
1105
|
+
}
|
|
1106
|
+
push({ type: "text", value, output });
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
if (opts.dot !== true && (prev.type === "slash" || prev.type === "bos")) {
|
|
1110
|
+
push({ type: "qmark", value, output: QMARK_NO_DOT });
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
push({ type: "qmark", value, output: QMARK });
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
if (value === "!") {
|
|
1117
|
+
if (opts.noextglob !== true && peek() === "(") {
|
|
1118
|
+
if (peek(2) !== "?" || !/[!=<:]/.test(peek(3))) {
|
|
1119
|
+
extglobOpen("negate", value);
|
|
1120
|
+
continue;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
if (opts.nonegate !== true && state.index === 0) {
|
|
1124
|
+
negate();
|
|
1125
|
+
continue;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
if (value === "+") {
|
|
1129
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1130
|
+
extglobOpen("plus", value);
|
|
1131
|
+
continue;
|
|
1132
|
+
}
|
|
1133
|
+
if (prev && prev.value === "(" || opts.regex === false) {
|
|
1134
|
+
push({ type: "plus", value, output: PLUS_LITERAL });
|
|
1135
|
+
continue;
|
|
1136
|
+
}
|
|
1137
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren" || prev.type === "brace") || state.parens > 0) {
|
|
1138
|
+
push({ type: "plus", value });
|
|
1139
|
+
continue;
|
|
1140
|
+
}
|
|
1141
|
+
push({ type: "plus", value: PLUS_LITERAL });
|
|
1142
|
+
continue;
|
|
1143
|
+
}
|
|
1144
|
+
if (value === "@") {
|
|
1145
|
+
if (opts.noextglob !== true && peek() === "(" && peek(2) !== "?") {
|
|
1146
|
+
push({ type: "at", extglob: true, value, output: "" });
|
|
1147
|
+
continue;
|
|
1148
|
+
}
|
|
1149
|
+
push({ type: "text", value });
|
|
1150
|
+
continue;
|
|
1151
|
+
}
|
|
1152
|
+
if (value !== "*") {
|
|
1153
|
+
if (value === "$" || value === "^") {
|
|
1154
|
+
value = `\\${value}`;
|
|
1155
|
+
}
|
|
1156
|
+
const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
|
|
1157
|
+
if (match) {
|
|
1158
|
+
value += match[0];
|
|
1159
|
+
state.index += match[0].length;
|
|
1160
|
+
}
|
|
1161
|
+
push({ type: "text", value });
|
|
1162
|
+
continue;
|
|
1163
|
+
}
|
|
1164
|
+
if (prev && (prev.type === "globstar" || prev.star === true)) {
|
|
1165
|
+
prev.type = "star";
|
|
1166
|
+
prev.star = true;
|
|
1167
|
+
prev.value += value;
|
|
1168
|
+
prev.output = star;
|
|
1169
|
+
state.backtrack = true;
|
|
1170
|
+
state.globstar = true;
|
|
1171
|
+
consume(value);
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
let rest = remaining();
|
|
1175
|
+
if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
|
|
1176
|
+
extglobOpen("star", value);
|
|
1177
|
+
continue;
|
|
1178
|
+
}
|
|
1179
|
+
if (prev.type === "star") {
|
|
1180
|
+
if (opts.noglobstar === true) {
|
|
1181
|
+
consume(value);
|
|
1182
|
+
continue;
|
|
1183
|
+
}
|
|
1184
|
+
const prior = prev.prev;
|
|
1185
|
+
const before = prior.prev;
|
|
1186
|
+
const isStart = prior.type === "slash" || prior.type === "bos";
|
|
1187
|
+
const afterStar = before && (before.type === "star" || before.type === "globstar");
|
|
1188
|
+
if (opts.bash === true && (!isStart || rest[0] && rest[0] !== "/")) {
|
|
1189
|
+
push({ type: "star", value, output: "" });
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1192
|
+
const isBrace = state.braces > 0 && (prior.type === "comma" || prior.type === "brace");
|
|
1193
|
+
const isExtglob = extglobs.length && (prior.type === "pipe" || prior.type === "paren");
|
|
1194
|
+
if (!isStart && prior.type !== "paren" && !isBrace && !isExtglob) {
|
|
1195
|
+
push({ type: "star", value, output: "" });
|
|
1196
|
+
continue;
|
|
1197
|
+
}
|
|
1198
|
+
while (rest.slice(0, 3) === "/**") {
|
|
1199
|
+
const after = input[state.index + 4];
|
|
1200
|
+
if (after && after !== "/") {
|
|
1201
|
+
break;
|
|
1202
|
+
}
|
|
1203
|
+
rest = rest.slice(3);
|
|
1204
|
+
consume("/**", 3);
|
|
1205
|
+
}
|
|
1206
|
+
if (prior.type === "bos" && eos()) {
|
|
1207
|
+
prev.type = "globstar";
|
|
1208
|
+
prev.value += value;
|
|
1209
|
+
prev.output = globstar(opts);
|
|
1210
|
+
state.output = prev.output;
|
|
1211
|
+
state.globstar = true;
|
|
1212
|
+
consume(value);
|
|
1213
|
+
continue;
|
|
1214
|
+
}
|
|
1215
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && !afterStar && eos()) {
|
|
1216
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1217
|
+
prior.output = `(?:${prior.output}`;
|
|
1218
|
+
prev.type = "globstar";
|
|
1219
|
+
prev.output = globstar(opts) + (opts.strictSlashes ? ")" : "|$)");
|
|
1220
|
+
prev.value += value;
|
|
1221
|
+
state.globstar = true;
|
|
1222
|
+
state.output += prior.output + prev.output;
|
|
1223
|
+
consume(value);
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
if (prior.type === "slash" && prior.prev.type !== "bos" && rest[0] === "/") {
|
|
1227
|
+
const end = rest[1] !== void 0 ? "|$" : "";
|
|
1228
|
+
state.output = state.output.slice(0, -(prior.output + prev.output).length);
|
|
1229
|
+
prior.output = `(?:${prior.output}`;
|
|
1230
|
+
prev.type = "globstar";
|
|
1231
|
+
prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
|
|
1232
|
+
prev.value += value;
|
|
1233
|
+
state.output += prior.output + prev.output;
|
|
1234
|
+
state.globstar = true;
|
|
1235
|
+
consume(value + advance());
|
|
1236
|
+
push({ type: "slash", value: "/", output: "" });
|
|
1237
|
+
continue;
|
|
1238
|
+
}
|
|
1239
|
+
if (prior.type === "bos" && rest[0] === "/") {
|
|
1240
|
+
prev.type = "globstar";
|
|
1241
|
+
prev.value += value;
|
|
1242
|
+
prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
|
|
1243
|
+
state.output = prev.output;
|
|
1244
|
+
state.globstar = true;
|
|
1245
|
+
consume(value + advance());
|
|
1246
|
+
push({ type: "slash", value: "/", output: "" });
|
|
1247
|
+
continue;
|
|
1248
|
+
}
|
|
1249
|
+
state.output = state.output.slice(0, -prev.output.length);
|
|
1250
|
+
prev.type = "globstar";
|
|
1251
|
+
prev.output = globstar(opts);
|
|
1252
|
+
prev.value += value;
|
|
1253
|
+
state.output += prev.output;
|
|
1254
|
+
state.globstar = true;
|
|
1255
|
+
consume(value);
|
|
1256
|
+
continue;
|
|
1257
|
+
}
|
|
1258
|
+
const token = { type: "star", value, output: star };
|
|
1259
|
+
if (opts.bash === true) {
|
|
1260
|
+
token.output = ".*?";
|
|
1261
|
+
if (prev.type === "bos" || prev.type === "slash") {
|
|
1262
|
+
token.output = nodot + token.output;
|
|
1263
|
+
}
|
|
1264
|
+
push(token);
|
|
1265
|
+
continue;
|
|
1266
|
+
}
|
|
1267
|
+
if (prev && (prev.type === "bracket" || prev.type === "paren") && opts.regex === true) {
|
|
1268
|
+
token.output = value;
|
|
1269
|
+
push(token);
|
|
1270
|
+
continue;
|
|
1271
|
+
}
|
|
1272
|
+
if (state.index === state.start || prev.type === "slash" || prev.type === "dot") {
|
|
1273
|
+
if (prev.type === "dot") {
|
|
1274
|
+
state.output += NO_DOT_SLASH;
|
|
1275
|
+
prev.output += NO_DOT_SLASH;
|
|
1276
|
+
} else if (opts.dot === true) {
|
|
1277
|
+
state.output += NO_DOTS_SLASH;
|
|
1278
|
+
prev.output += NO_DOTS_SLASH;
|
|
1279
|
+
} else {
|
|
1280
|
+
state.output += nodot;
|
|
1281
|
+
prev.output += nodot;
|
|
1282
|
+
}
|
|
1283
|
+
if (peek() !== "*") {
|
|
1284
|
+
state.output += ONE_CHAR;
|
|
1285
|
+
prev.output += ONE_CHAR;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
push(token);
|
|
1289
|
+
}
|
|
1290
|
+
while (state.brackets > 0) {
|
|
1291
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "]"));
|
|
1292
|
+
state.output = utils.escapeLast(state.output, "[");
|
|
1293
|
+
decrement("brackets");
|
|
1294
|
+
}
|
|
1295
|
+
while (state.parens > 0) {
|
|
1296
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", ")"));
|
|
1297
|
+
state.output = utils.escapeLast(state.output, "(");
|
|
1298
|
+
decrement("parens");
|
|
1299
|
+
}
|
|
1300
|
+
while (state.braces > 0) {
|
|
1301
|
+
if (opts.strictBrackets === true) throw new SyntaxError(syntaxError("closing", "}"));
|
|
1302
|
+
state.output = utils.escapeLast(state.output, "{");
|
|
1303
|
+
decrement("braces");
|
|
1304
|
+
}
|
|
1305
|
+
if (opts.strictSlashes !== true && (prev.type === "star" || prev.type === "bracket")) {
|
|
1306
|
+
push({ type: "maybe_slash", value: "", output: `${SLASH_LITERAL}?` });
|
|
1307
|
+
}
|
|
1308
|
+
if (state.backtrack === true) {
|
|
1309
|
+
state.output = "";
|
|
1310
|
+
for (const token of state.tokens) {
|
|
1311
|
+
state.output += token.output != null ? token.output : token.value;
|
|
1312
|
+
if (token.suffix) {
|
|
1313
|
+
state.output += token.suffix;
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
return state;
|
|
1318
|
+
};
|
|
1319
|
+
parse.fastpaths = (input, options) => {
|
|
1320
|
+
const opts = { ...options };
|
|
1321
|
+
const max = typeof opts.maxLength === "number" ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
|
|
1322
|
+
const len = input.length;
|
|
1323
|
+
if (len > max) {
|
|
1324
|
+
throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
|
|
1325
|
+
}
|
|
1326
|
+
input = REPLACEMENTS[input] || input;
|
|
1327
|
+
const {
|
|
1328
|
+
DOT_LITERAL,
|
|
1329
|
+
SLASH_LITERAL,
|
|
1330
|
+
ONE_CHAR,
|
|
1331
|
+
DOTS_SLASH,
|
|
1332
|
+
NO_DOT,
|
|
1333
|
+
NO_DOTS,
|
|
1334
|
+
NO_DOTS_SLASH,
|
|
1335
|
+
STAR,
|
|
1336
|
+
START_ANCHOR
|
|
1337
|
+
} = constants.globChars(opts.windows);
|
|
1338
|
+
const nodot = opts.dot ? NO_DOTS : NO_DOT;
|
|
1339
|
+
const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
|
|
1340
|
+
const capture = opts.capture ? "" : "?:";
|
|
1341
|
+
const state = { negated: false, prefix: "" };
|
|
1342
|
+
let star = opts.bash === true ? ".*?" : STAR;
|
|
1343
|
+
if (opts.capture) {
|
|
1344
|
+
star = `(${star})`;
|
|
1345
|
+
}
|
|
1346
|
+
const globstar = (opts2) => {
|
|
1347
|
+
if (opts2.noglobstar === true) return star;
|
|
1348
|
+
return `(${capture}(?:(?!${START_ANCHOR}${opts2.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
|
|
1349
|
+
};
|
|
1350
|
+
const create = (str) => {
|
|
1351
|
+
switch (str) {
|
|
1352
|
+
case "*":
|
|
1353
|
+
return `${nodot}${ONE_CHAR}${star}`;
|
|
1354
|
+
case ".*":
|
|
1355
|
+
return `${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1356
|
+
case "*.*":
|
|
1357
|
+
return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1358
|
+
case "*/*":
|
|
1359
|
+
return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
|
|
1360
|
+
case "**":
|
|
1361
|
+
return nodot + globstar(opts);
|
|
1362
|
+
case "**/*":
|
|
1363
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
|
|
1364
|
+
case "**/*.*":
|
|
1365
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1366
|
+
case "**/.*":
|
|
1367
|
+
return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
|
|
1368
|
+
default: {
|
|
1369
|
+
const match = /^(.*?)\.(\w+)$/.exec(str);
|
|
1370
|
+
if (!match) return;
|
|
1371
|
+
const source2 = create(match[1]);
|
|
1372
|
+
if (!source2) return;
|
|
1373
|
+
return source2 + DOT_LITERAL + match[2];
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
};
|
|
1377
|
+
const output = utils.removePrefix(input, state);
|
|
1378
|
+
let source = create(output);
|
|
1379
|
+
if (source && opts.strictSlashes !== true) {
|
|
1380
|
+
source += `${SLASH_LITERAL}?`;
|
|
1381
|
+
}
|
|
1382
|
+
return source;
|
|
1383
|
+
};
|
|
1384
|
+
module.exports = parse;
|
|
1385
|
+
}
|
|
1386
|
+
});
|
|
1387
|
+
|
|
1388
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/picomatch.js
|
|
1389
|
+
var require_picomatch = __commonJS({
|
|
1390
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/lib/picomatch.js"(exports, module) {
|
|
1391
|
+
"use strict";
|
|
1392
|
+
var scan = require_scan();
|
|
1393
|
+
var parse = require_parse();
|
|
1394
|
+
var utils = require_utils();
|
|
1395
|
+
var constants = require_constants();
|
|
1396
|
+
var isObject = (val) => val && typeof val === "object" && !Array.isArray(val);
|
|
1397
|
+
var picomatch2 = (glob2, options, returnState = false) => {
|
|
1398
|
+
if (Array.isArray(glob2)) {
|
|
1399
|
+
const fns = glob2.map((input) => picomatch2(input, options, returnState));
|
|
1400
|
+
const arrayMatcher = (str) => {
|
|
1401
|
+
for (const isMatch of fns) {
|
|
1402
|
+
const state2 = isMatch(str);
|
|
1403
|
+
if (state2) return state2;
|
|
1404
|
+
}
|
|
1405
|
+
return false;
|
|
1406
|
+
};
|
|
1407
|
+
return arrayMatcher;
|
|
1408
|
+
}
|
|
1409
|
+
const isState = isObject(glob2) && glob2.tokens && glob2.input;
|
|
1410
|
+
if (glob2 === "" || typeof glob2 !== "string" && !isState) {
|
|
1411
|
+
throw new TypeError("Expected pattern to be a non-empty string");
|
|
1412
|
+
}
|
|
1413
|
+
const opts = options || {};
|
|
1414
|
+
const posix = opts.windows;
|
|
1415
|
+
const regex = isState ? picomatch2.compileRe(glob2, options) : picomatch2.makeRe(glob2, options, false, true);
|
|
1416
|
+
const state = regex.state;
|
|
1417
|
+
delete regex.state;
|
|
1418
|
+
let isIgnored = () => false;
|
|
1419
|
+
if (opts.ignore) {
|
|
1420
|
+
const ignoreOpts = { ...options, ignore: null, onMatch: null, onResult: null };
|
|
1421
|
+
isIgnored = picomatch2(opts.ignore, ignoreOpts, returnState);
|
|
1422
|
+
}
|
|
1423
|
+
const matcher = (input, returnObject = false) => {
|
|
1424
|
+
const { isMatch, match, output } = picomatch2.test(input, regex, options, { glob: glob2, posix });
|
|
1425
|
+
const result = { glob: glob2, state, regex, posix, input, output, match, isMatch };
|
|
1426
|
+
if (typeof opts.onResult === "function") {
|
|
1427
|
+
opts.onResult(result);
|
|
1428
|
+
}
|
|
1429
|
+
if (isMatch === false) {
|
|
1430
|
+
result.isMatch = false;
|
|
1431
|
+
return returnObject ? result : false;
|
|
1432
|
+
}
|
|
1433
|
+
if (isIgnored(input)) {
|
|
1434
|
+
if (typeof opts.onIgnore === "function") {
|
|
1435
|
+
opts.onIgnore(result);
|
|
1436
|
+
}
|
|
1437
|
+
result.isMatch = false;
|
|
1438
|
+
return returnObject ? result : false;
|
|
1439
|
+
}
|
|
1440
|
+
if (typeof opts.onMatch === "function") {
|
|
1441
|
+
opts.onMatch(result);
|
|
1442
|
+
}
|
|
1443
|
+
return returnObject ? result : true;
|
|
1444
|
+
};
|
|
1445
|
+
if (returnState) {
|
|
1446
|
+
matcher.state = state;
|
|
1447
|
+
}
|
|
1448
|
+
return matcher;
|
|
1449
|
+
};
|
|
1450
|
+
picomatch2.test = (input, regex, options, { glob: glob2, posix } = {}) => {
|
|
1451
|
+
if (typeof input !== "string") {
|
|
1452
|
+
throw new TypeError("Expected input to be a string");
|
|
1453
|
+
}
|
|
1454
|
+
if (input === "") {
|
|
1455
|
+
return { isMatch: false, output: "" };
|
|
1456
|
+
}
|
|
1457
|
+
const opts = options || {};
|
|
1458
|
+
const format = opts.format || (posix ? utils.toPosixSlashes : null);
|
|
1459
|
+
let match = input === glob2;
|
|
1460
|
+
let output = match && format ? format(input) : input;
|
|
1461
|
+
if (match === false) {
|
|
1462
|
+
output = format ? format(input) : input;
|
|
1463
|
+
match = output === glob2;
|
|
1464
|
+
}
|
|
1465
|
+
if (match === false || opts.capture === true) {
|
|
1466
|
+
if (opts.matchBase === true || opts.basename === true) {
|
|
1467
|
+
match = picomatch2.matchBase(input, regex, options, posix);
|
|
1468
|
+
} else {
|
|
1469
|
+
match = regex.exec(output);
|
|
1470
|
+
}
|
|
1471
|
+
}
|
|
1472
|
+
return { isMatch: Boolean(match), match, output };
|
|
1473
|
+
};
|
|
1474
|
+
picomatch2.matchBase = (input, glob2, options) => {
|
|
1475
|
+
const regex = glob2 instanceof RegExp ? glob2 : picomatch2.makeRe(glob2, options);
|
|
1476
|
+
return regex.test(utils.basename(input));
|
|
1477
|
+
};
|
|
1478
|
+
picomatch2.isMatch = (str, patterns, options) => picomatch2(patterns, options)(str);
|
|
1479
|
+
picomatch2.parse = (pattern, options) => {
|
|
1480
|
+
if (Array.isArray(pattern)) return pattern.map((p) => picomatch2.parse(p, options));
|
|
1481
|
+
return parse(pattern, { ...options, fastpaths: false });
|
|
1482
|
+
};
|
|
1483
|
+
picomatch2.scan = (input, options) => scan(input, options);
|
|
1484
|
+
picomatch2.compileRe = (state, options, returnOutput = false, returnState = false) => {
|
|
1485
|
+
if (returnOutput === true) {
|
|
1486
|
+
return state.output;
|
|
1487
|
+
}
|
|
1488
|
+
const opts = options || {};
|
|
1489
|
+
const prepend = opts.contains ? "" : "^";
|
|
1490
|
+
const append = opts.contains ? "" : "$";
|
|
1491
|
+
let source = `${prepend}(?:${state.output})${append}`;
|
|
1492
|
+
if (state && state.negated === true) {
|
|
1493
|
+
source = `^(?!${source}).*$`;
|
|
1494
|
+
}
|
|
1495
|
+
const regex = picomatch2.toRegex(source, options);
|
|
1496
|
+
if (returnState === true) {
|
|
1497
|
+
regex.state = state;
|
|
1498
|
+
}
|
|
1499
|
+
return regex;
|
|
1500
|
+
};
|
|
1501
|
+
picomatch2.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
|
|
1502
|
+
if (!input || typeof input !== "string") {
|
|
1503
|
+
throw new TypeError("Expected a non-empty string");
|
|
1504
|
+
}
|
|
1505
|
+
let parsed = { negated: false, fastpaths: true };
|
|
1506
|
+
if (options.fastpaths !== false && (input[0] === "." || input[0] === "*")) {
|
|
1507
|
+
parsed.output = parse.fastpaths(input, options);
|
|
1508
|
+
}
|
|
1509
|
+
if (!parsed.output) {
|
|
1510
|
+
parsed = parse(input, options);
|
|
1511
|
+
}
|
|
1512
|
+
return picomatch2.compileRe(parsed, options, returnOutput, returnState);
|
|
1513
|
+
};
|
|
1514
|
+
picomatch2.toRegex = (source, options) => {
|
|
1515
|
+
try {
|
|
1516
|
+
const opts = options || {};
|
|
1517
|
+
return new RegExp(source, opts.flags || (opts.nocase ? "i" : ""));
|
|
1518
|
+
} catch (err) {
|
|
1519
|
+
if (options && options.debug === true) throw err;
|
|
1520
|
+
return /$^/;
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
picomatch2.constants = constants;
|
|
1524
|
+
module.exports = picomatch2;
|
|
1525
|
+
}
|
|
1526
|
+
});
|
|
1527
|
+
|
|
1528
|
+
// ../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/index.js
|
|
1529
|
+
var require_picomatch2 = __commonJS({
|
|
1530
|
+
"../../node_modules/.pnpm/picomatch@4.0.3/node_modules/picomatch/index.js"(exports, module) {
|
|
1531
|
+
"use strict";
|
|
1532
|
+
var pico = require_picomatch();
|
|
1533
|
+
var utils = require_utils();
|
|
1534
|
+
function picomatch2(glob2, options, returnState = false) {
|
|
1535
|
+
if (options && (options.windows === null || options.windows === void 0)) {
|
|
1536
|
+
options = { ...options, windows: utils.isWindows() };
|
|
1537
|
+
}
|
|
1538
|
+
return pico(glob2, options, returnState);
|
|
1539
|
+
}
|
|
1540
|
+
Object.assign(picomatch2, pico);
|
|
1541
|
+
module.exports = picomatch2;
|
|
1542
|
+
}
|
|
1543
|
+
});
|
|
1544
|
+
|
|
1545
|
+
// src/commands/core/init.ts
|
|
2
1546
|
import { defineCommand } from "citty";
|
|
3
1547
|
import { mkdir, writeFile } from "fs/promises";
|
|
4
|
-
import { join } from "path";
|
|
1548
|
+
import { join, basename, resolve } from "path";
|
|
5
1549
|
|
|
6
1550
|
// ../schema/dist/types.js
|
|
7
1551
|
var SPEC_TYPES = [
|
|
@@ -15,6 +1559,10 @@ var SPEC_TYPES = [
|
|
|
15
1559
|
"quick-spec",
|
|
16
1560
|
"project-context"
|
|
17
1561
|
];
|
|
1562
|
+
var DEPENDENCY_RELATIONSHIPS = {
|
|
1563
|
+
"depends-on": "self-requires-target",
|
|
1564
|
+
"implemented-by": "target-requires-self"
|
|
1565
|
+
};
|
|
18
1566
|
|
|
19
1567
|
// ../schema/dist/sections.js
|
|
20
1568
|
var REQUIRED_SECTIONS = {
|
|
@@ -168,7 +1716,7 @@ var base_spec_default = {
|
|
|
168
1716
|
|
|
169
1717
|
// ../schema/dist/schemas/config.json
|
|
170
1718
|
var config_default = {
|
|
171
|
-
$id: "
|
|
1719
|
+
$id: "specdx-config",
|
|
172
1720
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
173
1721
|
type: "object",
|
|
174
1722
|
properties: {
|
|
@@ -268,6 +1816,15 @@ var config_default = {
|
|
|
268
1816
|
}
|
|
269
1817
|
},
|
|
270
1818
|
additionalProperties: false
|
|
1819
|
+
},
|
|
1820
|
+
agents: {
|
|
1821
|
+
type: "object",
|
|
1822
|
+
properties: {
|
|
1823
|
+
paths: { type: "array", items: { type: "string" } },
|
|
1824
|
+
max_tokens: { type: "integer", minimum: 1 },
|
|
1825
|
+
rules: { type: "object" }
|
|
1826
|
+
},
|
|
1827
|
+
additionalProperties: false
|
|
271
1828
|
}
|
|
272
1829
|
},
|
|
273
1830
|
required: ["version", "specs"],
|
|
@@ -428,7 +1985,7 @@ function validateConfig(data) {
|
|
|
428
1985
|
return { valid: !!valid, errors: valid ? null : configValidator.errors ?? null };
|
|
429
1986
|
}
|
|
430
1987
|
|
|
431
|
-
// src/commands/init.ts
|
|
1988
|
+
// src/commands/core/init.ts
|
|
432
1989
|
var TEMPLATE_SPECS = {
|
|
433
1990
|
lightweight: [
|
|
434
1991
|
{ filename: "prd.md", type: "prd" },
|
|
@@ -497,6 +2054,9 @@ async function scaffoldProject({
|
|
|
497
2054
|
template,
|
|
498
2055
|
targetDir
|
|
499
2056
|
}) {
|
|
2057
|
+
if (!targetDir) {
|
|
2058
|
+
throw new TypeError("scaffoldProject requires `targetDir` \u2014 where to create the project.");
|
|
2059
|
+
}
|
|
500
2060
|
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
501
2061
|
const specsDir = join(targetDir, "specs");
|
|
502
2062
|
await mkdir(specsDir, { recursive: true });
|
|
@@ -511,6 +2071,10 @@ async function scaffoldProject({
|
|
|
511
2071
|
const configContent = buildConfigYaml(projectName, specs);
|
|
512
2072
|
await writeFile(join(targetDir, "spec.config.yaml"), configContent, "utf-8");
|
|
513
2073
|
}
|
|
2074
|
+
function defaultProjectName(dir) {
|
|
2075
|
+
return basename(resolve(dir)) || "my-project";
|
|
2076
|
+
}
|
|
2077
|
+
var VALID_TEMPLATES = ["lightweight", "bmad", "api-first", "quick", "context"];
|
|
514
2078
|
var init_default = defineCommand({
|
|
515
2079
|
meta: {
|
|
516
2080
|
name: "init",
|
|
@@ -519,12 +2083,11 @@ var init_default = defineCommand({
|
|
|
519
2083
|
args: {
|
|
520
2084
|
name: {
|
|
521
2085
|
type: "string",
|
|
522
|
-
description: "Project name"
|
|
523
|
-
required: true
|
|
2086
|
+
description: "Project name (default: the target directory's name)"
|
|
524
2087
|
},
|
|
525
2088
|
template: {
|
|
526
2089
|
type: "string",
|
|
527
|
-
description:
|
|
2090
|
+
description: `Template to use (${VALID_TEMPLATES.join(", ")})`,
|
|
528
2091
|
default: "lightweight"
|
|
529
2092
|
},
|
|
530
2093
|
dir: {
|
|
@@ -534,19 +2097,19 @@ var init_default = defineCommand({
|
|
|
534
2097
|
}
|
|
535
2098
|
},
|
|
536
2099
|
async run({ args }) {
|
|
537
|
-
const {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
console.error(`Unknown template: ${template}. Choose from: ${validTemplates.join(", ")}`);
|
|
2100
|
+
const { template, dir } = args;
|
|
2101
|
+
if (!VALID_TEMPLATES.includes(template)) {
|
|
2102
|
+
console.error(`Unknown template: ${template}. Choose from: ${VALID_TEMPLATES.join(", ")}`);
|
|
541
2103
|
process.exit(1);
|
|
542
2104
|
}
|
|
2105
|
+
const name = args.name || defaultProjectName(dir);
|
|
543
2106
|
console.log(`Scaffolding "${name}" with template "${template}" in ${dir}...`);
|
|
544
2107
|
await scaffoldProject({ projectName: name, template, targetDir: dir });
|
|
545
2108
|
console.log(`Done! Project "${name}" scaffolded successfully.`);
|
|
546
2109
|
}
|
|
547
2110
|
});
|
|
548
2111
|
|
|
549
|
-
// src/commands/lint.ts
|
|
2112
|
+
// src/commands/core/lint.ts
|
|
550
2113
|
import { defineCommand as defineCommand2 } from "citty";
|
|
551
2114
|
|
|
552
2115
|
// ../core/dist/config.js
|
|
@@ -565,7 +2128,7 @@ var CONFIG_FILENAME = "spec.config.yaml";
|
|
|
565
2128
|
async function loadConfig(filePath, searchFrom) {
|
|
566
2129
|
const resolvedPath = filePath ?? await findConfig(searchFrom ?? process.cwd());
|
|
567
2130
|
if (!resolvedPath) {
|
|
568
|
-
throw new ConfigError(`No ${CONFIG_FILENAME} found. Run '
|
|
2131
|
+
throw new ConfigError(`No ${CONFIG_FILENAME} found. Run 'specdx init' to create one.`);
|
|
569
2132
|
}
|
|
570
2133
|
let raw;
|
|
571
2134
|
try {
|
|
@@ -809,6 +2372,112 @@ function buildGraph(config) {
|
|
|
809
2372
|
};
|
|
810
2373
|
}
|
|
811
2374
|
|
|
2375
|
+
// ../core/dist/relations.js
|
|
2376
|
+
function mapEntriesToIds(config, specsByEntry) {
|
|
2377
|
+
const entryIds = /* @__PURE__ */ new Map();
|
|
2378
|
+
for (const key of Object.keys(config.specs)) {
|
|
2379
|
+
const ids = [];
|
|
2380
|
+
for (const spec of specsByEntry.get(key) ?? []) {
|
|
2381
|
+
const id = spec.frontmatter.id;
|
|
2382
|
+
if (typeof id === "string")
|
|
2383
|
+
ids.push(id);
|
|
2384
|
+
}
|
|
2385
|
+
entryIds.set(key, ids);
|
|
2386
|
+
}
|
|
2387
|
+
return entryIds;
|
|
2388
|
+
}
|
|
2389
|
+
function collectKnownIds(specsByEntry) {
|
|
2390
|
+
const ids = /* @__PURE__ */ new Set();
|
|
2391
|
+
for (const specs of specsByEntry.values()) {
|
|
2392
|
+
for (const spec of specs) {
|
|
2393
|
+
const id = spec.frontmatter.id;
|
|
2394
|
+
if (typeof id === "string")
|
|
2395
|
+
ids.add(id);
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
return ids;
|
|
2399
|
+
}
|
|
2400
|
+
function walk(specId, adjacency) {
|
|
2401
|
+
const visited = /* @__PURE__ */ new Set();
|
|
2402
|
+
const stack = [specId];
|
|
2403
|
+
while (stack.length > 0) {
|
|
2404
|
+
const current = stack.pop();
|
|
2405
|
+
for (const next of adjacency.get(current) ?? []) {
|
|
2406
|
+
if (!visited.has(next)) {
|
|
2407
|
+
visited.add(next);
|
|
2408
|
+
stack.push(next);
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
}
|
|
2412
|
+
visited.delete(specId);
|
|
2413
|
+
return [...visited];
|
|
2414
|
+
}
|
|
2415
|
+
function buildRelationResolver(config, specsByEntry) {
|
|
2416
|
+
const entryIds = config ? mapEntriesToIds(config, specsByEntry) : /* @__PURE__ */ new Map();
|
|
2417
|
+
const knownIds = collectKnownIds(specsByEntry);
|
|
2418
|
+
const edgeSources = /* @__PURE__ */ new Map();
|
|
2419
|
+
const addEdge = (from, to, source) => {
|
|
2420
|
+
if (from === to)
|
|
2421
|
+
return;
|
|
2422
|
+
const key = `${from}\0${to}`;
|
|
2423
|
+
const existing = edgeSources.get(key);
|
|
2424
|
+
if (!existing) {
|
|
2425
|
+
edgeSources.set(key, source);
|
|
2426
|
+
} else if (existing !== source) {
|
|
2427
|
+
edgeSources.set(key, "both");
|
|
2428
|
+
}
|
|
2429
|
+
};
|
|
2430
|
+
for (const [key, entry] of Object.entries(config?.specs ?? {})) {
|
|
2431
|
+
const requires = entry.requires ?? [];
|
|
2432
|
+
for (const dep of requires) {
|
|
2433
|
+
for (const from of entryIds.get(dep) ?? []) {
|
|
2434
|
+
for (const to of entryIds.get(key) ?? []) {
|
|
2435
|
+
addEdge(from, to, "requires");
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
}
|
|
2440
|
+
for (const specs of specsByEntry.values()) {
|
|
2441
|
+
for (const spec of specs) {
|
|
2442
|
+
const selfId = spec.frontmatter.id;
|
|
2443
|
+
if (typeof selfId !== "string")
|
|
2444
|
+
continue;
|
|
2445
|
+
const refs = spec.frontmatter.references;
|
|
2446
|
+
if (!Array.isArray(refs))
|
|
2447
|
+
continue;
|
|
2448
|
+
for (const ref of refs) {
|
|
2449
|
+
if (!ref || typeof ref !== "object")
|
|
2450
|
+
continue;
|
|
2451
|
+
const { id: targetId, relationship } = ref;
|
|
2452
|
+
if (typeof targetId !== "string" || typeof relationship !== "string")
|
|
2453
|
+
continue;
|
|
2454
|
+
if (!knownIds.has(targetId))
|
|
2455
|
+
continue;
|
|
2456
|
+
const direction = DEPENDENCY_RELATIONSHIPS[relationship];
|
|
2457
|
+
if (direction === "self-requires-target") {
|
|
2458
|
+
addEdge(targetId, selfId, "references");
|
|
2459
|
+
} else if (direction === "target-requires-self") {
|
|
2460
|
+
addEdge(selfId, targetId, "references");
|
|
2461
|
+
}
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
}
|
|
2465
|
+
const edges = [];
|
|
2466
|
+
const downstreamAdj = /* @__PURE__ */ new Map();
|
|
2467
|
+
const upstreamAdj = /* @__PURE__ */ new Map();
|
|
2468
|
+
for (const [key, source] of edgeSources) {
|
|
2469
|
+
const [from, to] = key.split("\0");
|
|
2470
|
+
edges.push({ from, to, source });
|
|
2471
|
+
downstreamAdj.set(from, [...downstreamAdj.get(from) ?? [], to]);
|
|
2472
|
+
upstreamAdj.set(to, [...upstreamAdj.get(to) ?? [], from]);
|
|
2473
|
+
}
|
|
2474
|
+
return {
|
|
2475
|
+
edges,
|
|
2476
|
+
getUpstream: (specId) => walk(specId, upstreamAdj),
|
|
2477
|
+
getDownstream: (specId) => walk(specId, downstreamAdj)
|
|
2478
|
+
};
|
|
2479
|
+
}
|
|
2480
|
+
|
|
812
2481
|
// ../core/dist/glob.js
|
|
813
2482
|
import { glob } from "tinyglobby";
|
|
814
2483
|
import { join as join3, isAbsolute } from "path";
|
|
@@ -830,14 +2499,17 @@ function createLogger(options) {
|
|
|
830
2499
|
|
|
831
2500
|
// ../core/dist/preset.js
|
|
832
2501
|
import { readFile as readFile3 } from "fs/promises";
|
|
833
|
-
import { resolve, isAbsolute as isAbsolute2 } from "path";
|
|
2502
|
+
import { resolve as resolve2, isAbsolute as isAbsolute2 } from "path";
|
|
834
2503
|
|
|
835
2504
|
// ../lint/dist/engine.js
|
|
836
2505
|
function createLintEngine(options) {
|
|
837
2506
|
return {
|
|
838
2507
|
lint(specs) {
|
|
839
2508
|
const diagnostics = [];
|
|
2509
|
+
const ignored = new Set(options.ignore ?? []);
|
|
840
2510
|
for (const spec of specs) {
|
|
2511
|
+
if (ignored.has(spec.filePath))
|
|
2512
|
+
continue;
|
|
841
2513
|
for (const rule of options.rules) {
|
|
842
2514
|
const results = rule.run({
|
|
843
2515
|
spec,
|
|
@@ -845,7 +2517,11 @@ function createLintEngine(options) {
|
|
|
845
2517
|
config: options.config,
|
|
846
2518
|
graph: options.graph
|
|
847
2519
|
});
|
|
848
|
-
|
|
2520
|
+
for (const diagnostic of results) {
|
|
2521
|
+
if (ignored.has(diagnostic.filePath))
|
|
2522
|
+
continue;
|
|
2523
|
+
diagnostics.push({ ...diagnostic, severity: rule.severity });
|
|
2524
|
+
}
|
|
849
2525
|
}
|
|
850
2526
|
}
|
|
851
2527
|
return {
|
|
@@ -858,6 +2534,18 @@ function createLintEngine(options) {
|
|
|
858
2534
|
}
|
|
859
2535
|
|
|
860
2536
|
// ../lint/dist/rules/valid-frontmatter.js
|
|
2537
|
+
function readablePath(instancePath) {
|
|
2538
|
+
return instancePath.split("/").filter(Boolean).map((segment) => /^\d+$/.test(segment) ? `[${segment}]` : `.${segment}`).join("").replace(/^\./, "");
|
|
2539
|
+
}
|
|
2540
|
+
function describeValidationError(err) {
|
|
2541
|
+
const path = readablePath(err.instancePath ?? "");
|
|
2542
|
+
const allowed = err.params?.allowedValues;
|
|
2543
|
+
let detail = err.message ?? JSON.stringify(err);
|
|
2544
|
+
if (Array.isArray(allowed) && allowed.length > 0) {
|
|
2545
|
+
detail += `: ${allowed.map((v) => JSON.stringify(v)).join(", ")}`;
|
|
2546
|
+
}
|
|
2547
|
+
return path ? `${path} ${detail}` : detail;
|
|
2548
|
+
}
|
|
861
2549
|
var validFrontmatterRule = {
|
|
862
2550
|
id: "structure/valid-frontmatter",
|
|
863
2551
|
description: "Frontmatter matches the schema for the declared spec type",
|
|
@@ -869,7 +2557,7 @@ var validFrontmatterRule = {
|
|
|
869
2557
|
return errors.map((err) => ({
|
|
870
2558
|
ruleId: "structure/valid-frontmatter",
|
|
871
2559
|
severity: "error",
|
|
872
|
-
message: `Invalid frontmatter: ${
|
|
2560
|
+
message: `Invalid frontmatter: ${describeValidationError(err)}`,
|
|
873
2561
|
filePath: context.spec.filePath
|
|
874
2562
|
}));
|
|
875
2563
|
}
|
|
@@ -929,7 +2617,131 @@ var noCircularDepsRule = {
|
|
|
929
2617
|
};
|
|
930
2618
|
|
|
931
2619
|
// ../lint/dist/rules/story-coverage.js
|
|
932
|
-
var
|
|
2620
|
+
var STOPWORDS = /* @__PURE__ */ new Set([
|
|
2621
|
+
"a",
|
|
2622
|
+
"an",
|
|
2623
|
+
"the",
|
|
2624
|
+
"and",
|
|
2625
|
+
"or",
|
|
2626
|
+
"of",
|
|
2627
|
+
"to",
|
|
2628
|
+
"for",
|
|
2629
|
+
"with",
|
|
2630
|
+
"its",
|
|
2631
|
+
"it",
|
|
2632
|
+
"in",
|
|
2633
|
+
"on",
|
|
2634
|
+
"at",
|
|
2635
|
+
"by",
|
|
2636
|
+
"from",
|
|
2637
|
+
"into",
|
|
2638
|
+
"every",
|
|
2639
|
+
"each",
|
|
2640
|
+
"that",
|
|
2641
|
+
"this",
|
|
2642
|
+
"be",
|
|
2643
|
+
"is",
|
|
2644
|
+
"are",
|
|
2645
|
+
"as",
|
|
2646
|
+
"can",
|
|
2647
|
+
"will",
|
|
2648
|
+
"must",
|
|
2649
|
+
"so",
|
|
2650
|
+
"their",
|
|
2651
|
+
"them",
|
|
2652
|
+
"when",
|
|
2653
|
+
"which",
|
|
2654
|
+
"who"
|
|
2655
|
+
]);
|
|
2656
|
+
var OVERLAP_THRESHOLD = 0.5;
|
|
2657
|
+
var REFERENCED_THRESHOLD = 0.34;
|
|
2658
|
+
function tokenise(text) {
|
|
2659
|
+
const words = text.toLowerCase().replace(/[^a-z0-9\s-]/g, " ").split(/\s+/).filter((w) => w.length > 2 && !STOPWORDS.has(w)).map((w) => w.length > 3 && w.endsWith("s") && !w.endsWith("ss") ? w.slice(0, -1) : w);
|
|
2660
|
+
return new Set(words);
|
|
2661
|
+
}
|
|
2662
|
+
function extractFeatureSection(content) {
|
|
2663
|
+
const lines = content.split("\n");
|
|
2664
|
+
const start = lines.findIndex((l) => /^##\s+Features\s*$/.test(l.trim()));
|
|
2665
|
+
if (start === -1)
|
|
2666
|
+
return null;
|
|
2667
|
+
const body = [];
|
|
2668
|
+
for (let i = start + 1; i < lines.length; i++) {
|
|
2669
|
+
if (/^##\s/.test(lines[i]))
|
|
2670
|
+
break;
|
|
2671
|
+
body.push(lines[i]);
|
|
2672
|
+
}
|
|
2673
|
+
return body.join("\n");
|
|
2674
|
+
}
|
|
2675
|
+
function parseFeatures(content) {
|
|
2676
|
+
return parseFeatureEntries(content).map((f) => f.text);
|
|
2677
|
+
}
|
|
2678
|
+
function parseFeatureEntries(content) {
|
|
2679
|
+
const section = extractFeatureSection(content);
|
|
2680
|
+
if (section === null)
|
|
2681
|
+
return [];
|
|
2682
|
+
const ID_PREFIX = /^\*{0,2}F(\d+)\*{0,2}\s*[:.-]\s*/i;
|
|
2683
|
+
const features = [];
|
|
2684
|
+
for (const rawLine of section.split("\n")) {
|
|
2685
|
+
const line = rawLine.trim();
|
|
2686
|
+
if (!line)
|
|
2687
|
+
continue;
|
|
2688
|
+
const bullet = /^[-*]\s+(.*)$/.exec(line);
|
|
2689
|
+
const text = bullet ? (bullet[1] ?? "").trim() : ID_PREFIX.test(line) ? line : "";
|
|
2690
|
+
if (!text)
|
|
2691
|
+
continue;
|
|
2692
|
+
const idMatch = ID_PREFIX.exec(text);
|
|
2693
|
+
const stripped = text.replace(ID_PREFIX, "").trim();
|
|
2694
|
+
if (stripped)
|
|
2695
|
+
features.push({ text: stripped, num: idMatch?.[1] });
|
|
2696
|
+
}
|
|
2697
|
+
return features;
|
|
2698
|
+
}
|
|
2699
|
+
function overlap(featureTokens, storyTokens) {
|
|
2700
|
+
if (featureTokens.size === 0)
|
|
2701
|
+
return 0;
|
|
2702
|
+
let shared = 0;
|
|
2703
|
+
for (const token of featureTokens)
|
|
2704
|
+
if (storyTokens.has(token))
|
|
2705
|
+
shared++;
|
|
2706
|
+
return shared / featureTokens.size;
|
|
2707
|
+
}
|
|
2708
|
+
function referencesSpec(story, specId) {
|
|
2709
|
+
const refs = story.frontmatter.references;
|
|
2710
|
+
if (!Array.isArray(refs))
|
|
2711
|
+
return false;
|
|
2712
|
+
return refs.some((r) => r?.id === specId);
|
|
2713
|
+
}
|
|
2714
|
+
function uncoveredFeatures(features, stories, prdId) {
|
|
2715
|
+
const scored = stories.map((story) => ({
|
|
2716
|
+
tokens: tokenise(`${String(story.frontmatter.title ?? "")} ${story.content}`),
|
|
2717
|
+
threshold: referencesSpec(story, prdId) ? REFERENCED_THRESHOLD : OVERLAP_THRESHOLD
|
|
2718
|
+
}));
|
|
2719
|
+
const tokenised = features.map(tokenise);
|
|
2720
|
+
return features.filter((_feature, i) => {
|
|
2721
|
+
const featureTokens = tokenised[i];
|
|
2722
|
+
const distinctive = distinctiveTokens(featureTokens, tokenised, i);
|
|
2723
|
+
return !scored.some((s) => overlap(featureTokens, s.tokens) >= s.threshold && covers(distinctive, featureTokens, s.tokens));
|
|
2724
|
+
});
|
|
2725
|
+
}
|
|
2726
|
+
function covers(distinctive, featureTokens, storyTokens) {
|
|
2727
|
+
if (distinctive.size === 0 || distinctive.size === featureTokens.size)
|
|
2728
|
+
return true;
|
|
2729
|
+
let matched = 0;
|
|
2730
|
+
for (const token of distinctive)
|
|
2731
|
+
if (storyTokens.has(token))
|
|
2732
|
+
matched++;
|
|
2733
|
+
return matched > distinctive.size / 2;
|
|
2734
|
+
}
|
|
2735
|
+
function distinctiveTokens(featureTokens, allFeatureTokens, index) {
|
|
2736
|
+
const distinctive = new Set(featureTokens);
|
|
2737
|
+
for (let i = 0; i < allFeatureTokens.length; i++) {
|
|
2738
|
+
if (i === index)
|
|
2739
|
+
continue;
|
|
2740
|
+
for (const token of allFeatureTokens[i])
|
|
2741
|
+
distinctive.delete(token);
|
|
2742
|
+
}
|
|
2743
|
+
return distinctive;
|
|
2744
|
+
}
|
|
933
2745
|
var storyCoverageRule = {
|
|
934
2746
|
id: "completeness/story-coverage",
|
|
935
2747
|
description: "Every feature listed in a PRD has at least one corresponding user story",
|
|
@@ -937,17 +2749,11 @@ var storyCoverageRule = {
|
|
|
937
2749
|
run(context) {
|
|
938
2750
|
if (context.spec.frontmatter.type !== "prd")
|
|
939
2751
|
return [];
|
|
940
|
-
const features =
|
|
941
|
-
let match;
|
|
942
|
-
const re = new RegExp(FEATURE_PATTERN.source, "g");
|
|
943
|
-
while ((match = re.exec(context.spec.content)) !== null) {
|
|
944
|
-
features.push(match[1].trim());
|
|
945
|
-
}
|
|
2752
|
+
const features = parseFeatures(context.spec.content);
|
|
946
2753
|
if (features.length === 0)
|
|
947
2754
|
return [];
|
|
948
2755
|
const stories = context.allSpecs.filter((s) => s.frontmatter.type === "user-story");
|
|
949
|
-
|
|
950
|
-
return features.filter((feature) => !storyContent.toLowerCase().includes(feature.toLowerCase())).map((feature) => ({
|
|
2756
|
+
return uncoveredFeatures(features, stories, context.spec.frontmatter.id).map((feature) => ({
|
|
951
2757
|
ruleId: "completeness/story-coverage",
|
|
952
2758
|
severity: "warn",
|
|
953
2759
|
message: `Feature "${feature}" has no corresponding user story`,
|
|
@@ -957,30 +2763,57 @@ var storyCoverageRule = {
|
|
|
957
2763
|
};
|
|
958
2764
|
|
|
959
2765
|
// ../lint/dist/rules/staleness-check.js
|
|
2766
|
+
function groupByEntry(config, specs) {
|
|
2767
|
+
const byEntry = /* @__PURE__ */ new Map();
|
|
2768
|
+
for (const key of Object.keys(config.specs))
|
|
2769
|
+
byEntry.set(key, []);
|
|
2770
|
+
for (const spec of specs) {
|
|
2771
|
+
let bestKey;
|
|
2772
|
+
let bestLen = -1;
|
|
2773
|
+
for (const [key, entry] of Object.entries(config.specs)) {
|
|
2774
|
+
const prefix = entry.path.split("*")[0] ?? "";
|
|
2775
|
+
const normalized = spec.filePath.replace(/\\/g, "/");
|
|
2776
|
+
if (normalized.includes(prefix) && prefix.length > bestLen) {
|
|
2777
|
+
bestKey = key;
|
|
2778
|
+
bestLen = prefix.length;
|
|
2779
|
+
}
|
|
2780
|
+
}
|
|
2781
|
+
if (bestKey)
|
|
2782
|
+
byEntry.get(bestKey).push(spec);
|
|
2783
|
+
}
|
|
2784
|
+
return byEntry;
|
|
2785
|
+
}
|
|
2786
|
+
function lastUpdated(spec) {
|
|
2787
|
+
return spec.frontmatter.updated ?? spec.frontmatter.created ?? "";
|
|
2788
|
+
}
|
|
960
2789
|
var stalenessCheckRule = {
|
|
961
2790
|
id: "freshness/staleness-check",
|
|
962
2791
|
description: "Warns if a spec hasn't been updated since its upstream dependency changed",
|
|
963
2792
|
severity: "warn",
|
|
964
2793
|
run(context) {
|
|
965
|
-
const
|
|
966
|
-
if (
|
|
2794
|
+
const specId = context.spec.frontmatter.id;
|
|
2795
|
+
if (typeof specId !== "string")
|
|
2796
|
+
return [];
|
|
2797
|
+
const specUpdated = lastUpdated(context.spec);
|
|
2798
|
+
if (!specUpdated)
|
|
967
2799
|
return [];
|
|
968
|
-
const specUpdated = context.spec.frontmatter.updated ?? context.spec.frontmatter.created;
|
|
969
2800
|
const specDate = new Date(specUpdated);
|
|
2801
|
+
const byEntry = context.config ? groupByEntry(context.config, context.allSpecs) : /* @__PURE__ */ new Map([["", context.allSpecs]]);
|
|
2802
|
+
const relations = buildRelationResolver(context.config, byEntry);
|
|
2803
|
+
const upstreamIds = relations.getUpstream(specId);
|
|
970
2804
|
const diagnostics = [];
|
|
971
|
-
for (const
|
|
972
|
-
|
|
973
|
-
continue;
|
|
974
|
-
const upstream = context.allSpecs.find((s) => s.frontmatter.id === ref.id);
|
|
2805
|
+
for (const upstreamId of upstreamIds) {
|
|
2806
|
+
const upstream = context.allSpecs.find((s) => s.frontmatter.id === upstreamId);
|
|
975
2807
|
if (!upstream)
|
|
976
2808
|
continue;
|
|
977
|
-
const upstreamUpdated = upstream
|
|
978
|
-
|
|
979
|
-
|
|
2809
|
+
const upstreamUpdated = lastUpdated(upstream);
|
|
2810
|
+
if (!upstreamUpdated)
|
|
2811
|
+
continue;
|
|
2812
|
+
if (new Date(upstreamUpdated) > specDate) {
|
|
980
2813
|
diagnostics.push({
|
|
981
2814
|
ruleId: "freshness/staleness-check",
|
|
982
2815
|
severity: "warn",
|
|
983
|
-
message: `Potentially stale: upstream "${
|
|
2816
|
+
message: `Potentially stale: upstream "${upstreamId}" was updated on ${upstreamUpdated}, but this spec was last updated on ${specUpdated}`,
|
|
984
2817
|
filePath: context.spec.filePath
|
|
985
2818
|
});
|
|
986
2819
|
}
|
|
@@ -1122,8 +2955,6 @@ var EDGE_CASE_KEYWORDS = [
|
|
|
1122
2955
|
"reject",
|
|
1123
2956
|
"unauthorized",
|
|
1124
2957
|
"forbidden",
|
|
1125
|
-
"404",
|
|
1126
|
-
"500",
|
|
1127
2958
|
"missing",
|
|
1128
2959
|
"malformed",
|
|
1129
2960
|
"overflow",
|
|
@@ -1133,8 +2964,24 @@ var EDGE_CASE_KEYWORDS = [
|
|
|
1133
2964
|
"fallback",
|
|
1134
2965
|
"crash",
|
|
1135
2966
|
"nonexistent",
|
|
1136
|
-
"corrupt"
|
|
2967
|
+
"corrupt",
|
|
2968
|
+
// Vocabulary that names a failure without using any of the words above.
|
|
2969
|
+
"conflict",
|
|
2970
|
+
"denied",
|
|
2971
|
+
"expired",
|
|
2972
|
+
"not found",
|
|
2973
|
+
"retry",
|
|
2974
|
+
"rate limit",
|
|
2975
|
+
"unavailable",
|
|
2976
|
+
"unprocessable"
|
|
1137
2977
|
];
|
|
2978
|
+
var ERROR_STATUS_CODE = /\b[45]\d{2}\b/;
|
|
2979
|
+
var EDGE_CASE_SECTION = "edge cases";
|
|
2980
|
+
var PLACEHOLDER_BODIES = /^(todo|tbd|fixme|n\/a|na|none|xxx|\.{2,}|-|\*)$/i;
|
|
2981
|
+
var DISCLAIMED_BODIES = /^(none|no|nothing|n\/a)\b[\s\S]{0,40}$/i;
|
|
2982
|
+
function meaningfulContent(content) {
|
|
2983
|
+
return content.replace(/<!--[\s\S]*?-->/g, "").split("\n").map((line) => line.replace(/^\s*[-*+]\s+/, "").trim()).filter((line) => line.length > 0 && !/^-{3,}$/.test(line)).join("\n").trim();
|
|
2984
|
+
}
|
|
1138
2985
|
var edgeCaseCoverageRule = {
|
|
1139
2986
|
id: "completeness/edge-case-coverage",
|
|
1140
2987
|
description: "Flag user stories or test plans that don't mention error states or edge cases",
|
|
@@ -1143,8 +2990,24 @@ var edgeCaseCoverageRule = {
|
|
|
1143
2990
|
const type = context.spec.frontmatter.type;
|
|
1144
2991
|
if (type !== "user-story" && type !== "test-plan")
|
|
1145
2992
|
return [];
|
|
2993
|
+
const section = context.spec.parsedSections.find((s) => s.heading.trim().toLowerCase() === EDGE_CASE_SECTION);
|
|
2994
|
+
if (type === "test-plan" && section) {
|
|
2995
|
+
const body = meaningfulContent(section.content);
|
|
2996
|
+
const written = body !== "" && !PLACEHOLDER_BODIES.test(body) && !DISCLAIMED_BODIES.test(body);
|
|
2997
|
+
if (written)
|
|
2998
|
+
return [];
|
|
2999
|
+
return [
|
|
3000
|
+
{
|
|
3001
|
+
ruleId: "completeness/edge-case-coverage",
|
|
3002
|
+
severity: "warn",
|
|
3003
|
+
message: `The "${section.heading}" section lists no cases \u2014 describe the boundary conditions and failure modes this plan covers, or the plan asserts only the happy path.`,
|
|
3004
|
+
filePath: context.spec.filePath,
|
|
3005
|
+
section: section.heading
|
|
3006
|
+
}
|
|
3007
|
+
];
|
|
3008
|
+
}
|
|
1146
3009
|
const content = context.spec.content.toLowerCase();
|
|
1147
|
-
const hasEdgeCases = EDGE_CASE_KEYWORDS.some((kw) => content.includes(kw));
|
|
3010
|
+
const hasEdgeCases = EDGE_CASE_KEYWORDS.some((kw) => content.includes(kw)) || ERROR_STATUS_CODE.test(content);
|
|
1148
3011
|
if (hasEdgeCases)
|
|
1149
3012
|
return [];
|
|
1150
3013
|
return [
|
|
@@ -1215,7 +3078,7 @@ var namingConventionsRule = {
|
|
|
1215
3078
|
};
|
|
1216
3079
|
|
|
1217
3080
|
// ../lint/dist/rules/threat-coverage.js
|
|
1218
|
-
var
|
|
3081
|
+
var STOPWORDS2 = /* @__PURE__ */ new Set(["the", "and", "for", "with", "from", "that", "this", "into", "via"]);
|
|
1219
3082
|
function extractThreats(content) {
|
|
1220
3083
|
const parts = content.split(/^(?=## )/m);
|
|
1221
3084
|
const threats = [];
|
|
@@ -1228,7 +3091,7 @@ function extractThreats(content) {
|
|
|
1228
3091
|
return threats;
|
|
1229
3092
|
}
|
|
1230
3093
|
function extractKeyTerms(text) {
|
|
1231
|
-
return text.toLowerCase().split(/\W+/).filter((w) => w.length > 3).filter((w) => !
|
|
3094
|
+
return text.toLowerCase().split(/\W+/).filter((w) => w.length > 3).filter((w) => !STOPWORDS2.has(w));
|
|
1232
3095
|
}
|
|
1233
3096
|
var threatCoverageRule = {
|
|
1234
3097
|
id: "security/threat-coverage",
|
|
@@ -1275,20 +3138,78 @@ var ambiguityScoreAiRule = {
|
|
|
1275
3138
|
{
|
|
1276
3139
|
ruleId: "clarity/ambiguity-score-ai",
|
|
1277
3140
|
severity: "info",
|
|
1278
|
-
message: "AI ambiguity analysis available \u2014 run `
|
|
3141
|
+
message: "AI ambiguity analysis available \u2014 run `specdx check --ai` for LLM-powered ambiguity detection",
|
|
1279
3142
|
filePath: context.spec.filePath
|
|
1280
3143
|
}
|
|
1281
3144
|
];
|
|
1282
3145
|
}
|
|
1283
3146
|
};
|
|
1284
3147
|
|
|
3148
|
+
// ../lint/dist/rules/no-placeholder-sections.js
|
|
3149
|
+
var PLACEHOLDER_BODIES2 = /^(todo|tbd|fixme|n\/a|na|none|xxx|\.{2,}|-|\*)$/i;
|
|
3150
|
+
function meaningfulContent2(content) {
|
|
3151
|
+
return content.replace(/<!--[\s\S]*?-->/g, "").split("\n").map((line) => line.replace(/^\s*[-*+]\s+/, "").trim()).filter((line) => line.length > 0 && !/^-{3,}$/.test(line)).join("\n").trim();
|
|
3152
|
+
}
|
|
3153
|
+
var noPlaceholderSectionsRule = {
|
|
3154
|
+
id: "completeness/no-placeholder-sections",
|
|
3155
|
+
description: "Spec sections contain content, not scaffolding placeholders",
|
|
3156
|
+
severity: "warn",
|
|
3157
|
+
run(context) {
|
|
3158
|
+
return context.spec.parsedSections.filter((section) => section.heading !== "").filter((section) => {
|
|
3159
|
+
const body = meaningfulContent2(section.content);
|
|
3160
|
+
return body === "" || PLACEHOLDER_BODIES2.test(body);
|
|
3161
|
+
}).map((section) => ({
|
|
3162
|
+
ruleId: "completeness/no-placeholder-sections",
|
|
3163
|
+
severity: "warn",
|
|
3164
|
+
message: `Section "${section.heading}" is still a placeholder \u2014 write its content or remove the section`,
|
|
3165
|
+
filePath: context.spec.filePath,
|
|
3166
|
+
section: section.heading
|
|
3167
|
+
}));
|
|
3168
|
+
}
|
|
3169
|
+
};
|
|
3170
|
+
|
|
3171
|
+
// ../lint/dist/rules/id-matches-config-key.js
|
|
3172
|
+
import { basename as basename2 } from "path";
|
|
3173
|
+
var idMatchesConfigKeyRule = {
|
|
3174
|
+
id: "structure/id-matches-config-key",
|
|
3175
|
+
description: "A spec's frontmatter id should match the key it is registered under in the config",
|
|
3176
|
+
severity: "warn",
|
|
3177
|
+
run(context) {
|
|
3178
|
+
const { spec, config } = context;
|
|
3179
|
+
if (!config)
|
|
3180
|
+
return [];
|
|
3181
|
+
const id = spec.frontmatter.id;
|
|
3182
|
+
if (typeof id !== "string" || id.length === 0)
|
|
3183
|
+
return [];
|
|
3184
|
+
const specFile = basename2(spec.filePath);
|
|
3185
|
+
const candidates = Object.entries(config.specs).filter(([, entry]) => {
|
|
3186
|
+
const target = basename2(entry.path);
|
|
3187
|
+
return !target.includes("*") && target === specFile;
|
|
3188
|
+
});
|
|
3189
|
+
if (candidates.length !== 1)
|
|
3190
|
+
return [];
|
|
3191
|
+
const key = candidates[0][0];
|
|
3192
|
+
if (key === id)
|
|
3193
|
+
return [];
|
|
3194
|
+
return [
|
|
3195
|
+
{
|
|
3196
|
+
ruleId: "structure/id-matches-config-key",
|
|
3197
|
+
severity: "warn",
|
|
3198
|
+
message: `Spec declares id "${id}" but is registered in spec.config.yaml as "${key}". Frontmatter references resolve against "${id}" and config requires against "${key}", so the dependency graph shows them as two things. Rename one so they agree.`,
|
|
3199
|
+
filePath: spec.filePath
|
|
3200
|
+
}
|
|
3201
|
+
];
|
|
3202
|
+
}
|
|
3203
|
+
};
|
|
3204
|
+
|
|
1285
3205
|
// ../lint/dist/rules/index.js
|
|
1286
3206
|
var structureRules = [
|
|
1287
3207
|
validFrontmatterRule,
|
|
1288
3208
|
requiredSectionsRule,
|
|
1289
3209
|
validReferencesRule,
|
|
1290
3210
|
noCircularDepsRule,
|
|
1291
|
-
singleProjectContextRule
|
|
3211
|
+
singleProjectContextRule,
|
|
3212
|
+
idMatchesConfigKeyRule
|
|
1292
3213
|
];
|
|
1293
3214
|
var contentRules = [
|
|
1294
3215
|
storyCoverageRule,
|
|
@@ -1298,7 +3219,8 @@ var contentRules = [
|
|
|
1298
3219
|
edgeCaseCoverageRule,
|
|
1299
3220
|
namingConventionsRule,
|
|
1300
3221
|
threatCoverageRule,
|
|
1301
|
-
ambiguityScoreAiRule
|
|
3222
|
+
ambiguityScoreAiRule,
|
|
3223
|
+
noPlaceholderSectionsRule
|
|
1302
3224
|
];
|
|
1303
3225
|
var allBuiltinRules = [...structureRules, ...contentRules];
|
|
1304
3226
|
|
|
@@ -1310,25 +3232,452 @@ function getPreset(name) {
|
|
|
1310
3232
|
case "recommended":
|
|
1311
3233
|
return allBuiltinRules;
|
|
1312
3234
|
case "strict":
|
|
1313
|
-
return allBuiltinRules.map((rule) =>
|
|
3235
|
+
return allBuiltinRules.map((rule) => rule.severity === "warn" ? { ...rule, severity: "error" } : rule);
|
|
1314
3236
|
default:
|
|
1315
3237
|
throw new Error(`Unknown preset: "${name}". Use "minimal", "recommended", or "strict", or resolve external presets via resolvePreset() from @specdx/core.`);
|
|
1316
3238
|
}
|
|
1317
3239
|
}
|
|
1318
3240
|
|
|
3241
|
+
// ../lint/dist/resolve-lint-config.js
|
|
3242
|
+
import { isAbsolute as isAbsolute3, resolve as resolve3 } from "path";
|
|
3243
|
+
|
|
1319
3244
|
// ../lint/dist/custom-rule-loader.js
|
|
1320
3245
|
import { pathToFileURL } from "url";
|
|
3246
|
+
async function loadCustomRule(filePath) {
|
|
3247
|
+
const module = await import(pathToFileURL(filePath).href);
|
|
3248
|
+
const rule = module.default ?? module.rule;
|
|
3249
|
+
if (!rule || !rule.id || !rule.run) {
|
|
3250
|
+
throw new Error(`Custom rule at ${filePath} must export a default LintRule with id and run function`);
|
|
3251
|
+
}
|
|
3252
|
+
return rule;
|
|
3253
|
+
}
|
|
1321
3254
|
|
|
1322
|
-
//
|
|
1323
|
-
var
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
3255
|
+
// ../lint/dist/resolve-lint-config.js
|
|
3256
|
+
var SEVERITIES = /* @__PURE__ */ new Set(["error", "warn", "info"]);
|
|
3257
|
+
function isOff(value) {
|
|
3258
|
+
return value === false || value === null || value === "off";
|
|
3259
|
+
}
|
|
3260
|
+
function severityOf(value) {
|
|
3261
|
+
return typeof value === "string" && SEVERITIES.has(value) ? value : void 0;
|
|
3262
|
+
}
|
|
3263
|
+
function describe(value) {
|
|
3264
|
+
return typeof value === "string" ? `"${value}"` : JSON.stringify(value);
|
|
3265
|
+
}
|
|
3266
|
+
async function resolveLintConfig({ config, preset, configDir }) {
|
|
3267
|
+
const presetName = preset ?? config?.lint?.extends ?? "recommended";
|
|
3268
|
+
const byId = new Map(getPreset(presetName).map((rule) => [rule.id, rule]));
|
|
3269
|
+
const builtins = new Map(allBuiltinRules.map((rule) => [rule.id, rule]));
|
|
3270
|
+
for (const [id, value] of Object.entries(config?.lint?.rules ?? {})) {
|
|
3271
|
+
if (isOff(value)) {
|
|
3272
|
+
if (!builtins.has(id)) {
|
|
3273
|
+
throw new Error(`lint.rules["${id}"]: cannot turn off "${id}" \u2014 no built-in rule has that id. Check the spelling.`);
|
|
3274
|
+
}
|
|
3275
|
+
byId.delete(id);
|
|
3276
|
+
continue;
|
|
3277
|
+
}
|
|
3278
|
+
let severity;
|
|
3279
|
+
let rulePath;
|
|
3280
|
+
if (Array.isArray(value)) {
|
|
3281
|
+
severity = severityOf(value[0]);
|
|
3282
|
+
if (severity === void 0) {
|
|
3283
|
+
throw new Error(`lint.rules["${id}"]: ${describe(value[0])} is not a severity. Use "error", "warn", "info", or "off".`);
|
|
3284
|
+
}
|
|
3285
|
+
const options = value[1];
|
|
3286
|
+
if (options !== void 0) {
|
|
3287
|
+
if (typeof options !== "object" || options === null || Array.isArray(options)) {
|
|
3288
|
+
throw new Error(`lint.rules["${id}"]: expected options like { path: "./rule.js" }, got ${describe(options)}.`);
|
|
3289
|
+
}
|
|
3290
|
+
const declared = options.path;
|
|
3291
|
+
if (declared !== void 0) {
|
|
3292
|
+
if (typeof declared !== "string" || declared.length === 0) {
|
|
3293
|
+
throw new Error(`lint.rules["${id}"]: \`path\` must be a non-empty string.`);
|
|
3294
|
+
}
|
|
3295
|
+
rulePath = declared;
|
|
3296
|
+
}
|
|
3297
|
+
}
|
|
3298
|
+
} else {
|
|
3299
|
+
severity = severityOf(value);
|
|
3300
|
+
if (severity === void 0) {
|
|
3301
|
+
throw new Error(`lint.rules["${id}"]: ${describe(value)} is not a severity. Use "error", "warn", "info", or "off".`);
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3304
|
+
if (rulePath !== void 0) {
|
|
3305
|
+
const absolute = isAbsolute3(rulePath) ? rulePath : resolve3(configDir, rulePath);
|
|
3306
|
+
const custom = await loadCustomRule(absolute);
|
|
3307
|
+
byId.set(id, { ...custom, id, severity });
|
|
3308
|
+
continue;
|
|
3309
|
+
}
|
|
3310
|
+
const existing = byId.get(id) ?? builtins.get(id);
|
|
3311
|
+
if (!existing) {
|
|
3312
|
+
throw new Error(`lint.rules["${id}"]: no built-in rule with that id. For a custom rule, give it a file: ["${severity}", { path: "./rules/my-rule.js" }].`);
|
|
3313
|
+
}
|
|
3314
|
+
byId.set(id, { ...existing, severity });
|
|
3315
|
+
}
|
|
3316
|
+
const ignore = [];
|
|
3317
|
+
for (const pattern of config?.lint?.ignore ?? []) {
|
|
3318
|
+
ignore.push(...await resolveGlob(pattern, configDir));
|
|
3319
|
+
}
|
|
3320
|
+
return { rules: [...byId.values()], ignore };
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
// ../lint/dist/agents/discover.js
|
|
3324
|
+
import { readFile as readFile4 } from "fs/promises";
|
|
3325
|
+
import { relative } from "path";
|
|
3326
|
+
var DEFAULT_AGENT_PATHS = ["AGENTS.md", "CLAUDE.md"];
|
|
3327
|
+
var DEFAULT_MAX_TOKENS = 8e3;
|
|
3328
|
+
async function discoverAgentFiles(patterns, configDir) {
|
|
3329
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3330
|
+
const files = [];
|
|
3331
|
+
for (const pattern of patterns) {
|
|
3332
|
+
for (const filePath of await resolveGlob(pattern, configDir)) {
|
|
3333
|
+
if (seen.has(filePath))
|
|
3334
|
+
continue;
|
|
3335
|
+
seen.add(filePath);
|
|
3336
|
+
const content = await readFile4(filePath, "utf8");
|
|
3337
|
+
files.push({
|
|
3338
|
+
filePath,
|
|
3339
|
+
relativePath: relative(configDir, filePath),
|
|
3340
|
+
content,
|
|
3341
|
+
lines: content.split("\n"),
|
|
3342
|
+
tokens: countTokens(content)
|
|
3343
|
+
});
|
|
3344
|
+
}
|
|
3345
|
+
}
|
|
3346
|
+
return files.sort((a, b) => a.relativePath.localeCompare(b.relativePath));
|
|
3347
|
+
}
|
|
3348
|
+
|
|
3349
|
+
// ../lint/dist/agents/rules/structure.js
|
|
3350
|
+
var structureRule = {
|
|
3351
|
+
id: "agents/structure",
|
|
3352
|
+
description: "Agent instruction files should have content and be organised under headings",
|
|
3353
|
+
severity: "warn",
|
|
3354
|
+
run(context) {
|
|
3355
|
+
const { file } = context;
|
|
3356
|
+
const diagnostics = [];
|
|
3357
|
+
if (file.content.trim() === "") {
|
|
3358
|
+
diagnostics.push({
|
|
3359
|
+
ruleId: "agents/structure",
|
|
3360
|
+
severity: "warn",
|
|
3361
|
+
message: `${file.relativePath} is empty. An empty instruction file steers nothing \u2014 delete it or write it.`,
|
|
3362
|
+
filePath: file.filePath
|
|
3363
|
+
});
|
|
3364
|
+
return { diagnostics };
|
|
3365
|
+
}
|
|
3366
|
+
const headings = file.lines.filter((line) => /^#{1,6}\s+\S/.test(line));
|
|
3367
|
+
if (headings.length === 0) {
|
|
3368
|
+
diagnostics.push({
|
|
3369
|
+
ruleId: "agents/structure",
|
|
3370
|
+
severity: "warn",
|
|
3371
|
+
message: `${file.relativePath} has no headings, so it is one undifferentiated block. Nothing can be referenced, revised, or removed in isolation.`,
|
|
3372
|
+
filePath: file.filePath
|
|
3373
|
+
});
|
|
3374
|
+
}
|
|
3375
|
+
return { diagnostics };
|
|
3376
|
+
}
|
|
3377
|
+
};
|
|
3378
|
+
|
|
3379
|
+
// ../lint/dist/agents/rules/stale-references.js
|
|
3380
|
+
var PATH_SHAPED = /^(?:[\w.@-]+\/)+[\w.-]+$|^[\w.-]+\.(?:ts|tsx|js|jsx|mjs|cjs|json|md|ya?ml|toml|sh|py|rb|rs|go|java|css|html)$/;
|
|
3381
|
+
function isNotAFileClaim(candidate) {
|
|
3382
|
+
return candidate.includes("*") || // a glob describes a set, not a file
|
|
3383
|
+
candidate.includes("://") || // a URL
|
|
3384
|
+
candidate.startsWith("http") || candidate.startsWith("@") || // an npm scope: @specdx/core
|
|
3385
|
+
candidate.startsWith("~") || // a home-relative path outside the repo
|
|
3386
|
+
candidate.startsWith("/") || // an absolute path outside the repo
|
|
3387
|
+
/^[A-Z_]+=/.test(candidate);
|
|
3388
|
+
}
|
|
3389
|
+
function normalise(candidate) {
|
|
3390
|
+
return candidate.replace(/^\.\//, "").replace(/[.,;:)]+$/, "");
|
|
3391
|
+
}
|
|
3392
|
+
function fencedLines(lines) {
|
|
3393
|
+
const fenced = /* @__PURE__ */ new Set();
|
|
3394
|
+
let fence;
|
|
3395
|
+
lines.forEach((line, index) => {
|
|
3396
|
+
const match = /^\s*(`{3,}|~{3,})/.exec(line);
|
|
3397
|
+
if (match) {
|
|
3398
|
+
if (fence === void 0) {
|
|
3399
|
+
fence = match[1];
|
|
3400
|
+
fenced.add(index);
|
|
3401
|
+
return;
|
|
3402
|
+
}
|
|
3403
|
+
if (match[1][0] === fence[0])
|
|
3404
|
+
fence = void 0;
|
|
3405
|
+
fenced.add(index);
|
|
3406
|
+
return;
|
|
3407
|
+
}
|
|
3408
|
+
if (fence !== void 0)
|
|
3409
|
+
fenced.add(index);
|
|
3410
|
+
});
|
|
3411
|
+
return fenced;
|
|
3412
|
+
}
|
|
3413
|
+
function extractReferences(lines) {
|
|
3414
|
+
const skip = fencedLines(lines);
|
|
3415
|
+
const found = [];
|
|
3416
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3417
|
+
lines.forEach((line, index) => {
|
|
3418
|
+
if (skip.has(index))
|
|
3419
|
+
return;
|
|
3420
|
+
const candidates = [];
|
|
3421
|
+
for (const match of line.matchAll(/`([^`\n]+)`/g))
|
|
3422
|
+
candidates.push(match[1]);
|
|
3423
|
+
for (const match of line.matchAll(/\]\((?!https?:|#)([^)\s]+)\)/g))
|
|
3424
|
+
candidates.push(match[1]);
|
|
3425
|
+
for (const raw of candidates) {
|
|
3426
|
+
const candidate = normalise(raw.trim());
|
|
3427
|
+
if (!candidate || isNotAFileClaim(candidate))
|
|
3428
|
+
continue;
|
|
3429
|
+
if (!PATH_SHAPED.test(candidate))
|
|
3430
|
+
continue;
|
|
3431
|
+
if (seen.has(candidate))
|
|
3432
|
+
continue;
|
|
3433
|
+
seen.add(candidate);
|
|
3434
|
+
found.push({ path: candidate, line: index + 1 });
|
|
3435
|
+
}
|
|
3436
|
+
});
|
|
3437
|
+
return found;
|
|
3438
|
+
}
|
|
3439
|
+
var staleReferencesRule = {
|
|
3440
|
+
id: "agents/stale-references",
|
|
3441
|
+
description: "Paths named by an agent instruction file must exist",
|
|
3442
|
+
severity: "warn",
|
|
3443
|
+
run(context) {
|
|
3444
|
+
const { file, exists } = context;
|
|
3445
|
+
const references = extractReferences(file.lines);
|
|
3446
|
+
if (references.length === 0) {
|
|
3447
|
+
return {
|
|
3448
|
+
diagnostics: [],
|
|
3449
|
+
assessed: false,
|
|
3450
|
+
notAssessedReason: `${file.relativePath} names no file paths, so none were checked for staleness.`
|
|
3451
|
+
};
|
|
3452
|
+
}
|
|
3453
|
+
return {
|
|
3454
|
+
diagnostics: references.filter((reference) => !exists(reference.path)).map((reference) => ({
|
|
3455
|
+
ruleId: "agents/stale-references",
|
|
3456
|
+
severity: this.severity,
|
|
3457
|
+
message: `${file.relativePath} refers to "${reference.path}", which does not exist. An agent told to look there will not find it.`,
|
|
3458
|
+
filePath: file.filePath,
|
|
3459
|
+
line: reference.line
|
|
3460
|
+
}))
|
|
3461
|
+
};
|
|
3462
|
+
}
|
|
3463
|
+
};
|
|
3464
|
+
|
|
3465
|
+
// ../lint/dist/agents/rules/size-budget.js
|
|
3466
|
+
var sizeBudgetRule = {
|
|
3467
|
+
id: "agents/size-budget",
|
|
3468
|
+
description: "Agent instruction files should fit a token budget",
|
|
3469
|
+
severity: "warn",
|
|
3470
|
+
run(context) {
|
|
3471
|
+
const { file, maxTokens } = context;
|
|
3472
|
+
if (file.tokens <= maxTokens)
|
|
3473
|
+
return { diagnostics: [] };
|
|
3474
|
+
const over = file.tokens - maxTokens;
|
|
3475
|
+
const percent = Math.round(over / maxTokens * 100);
|
|
3476
|
+
return {
|
|
3477
|
+
diagnostics: [
|
|
3478
|
+
{
|
|
3479
|
+
ruleId: "agents/size-budget",
|
|
3480
|
+
severity: this.severity,
|
|
3481
|
+
message: `${file.relativePath} is ${file.tokens} tokens, ${over} over the ${maxTokens} budget (${percent}% over). It is spending the context window it exists to protect.`,
|
|
3482
|
+
filePath: file.filePath
|
|
3483
|
+
}
|
|
3484
|
+
]
|
|
3485
|
+
};
|
|
3486
|
+
}
|
|
3487
|
+
};
|
|
3488
|
+
|
|
3489
|
+
// ../lint/dist/agents/resolve-reference.js
|
|
3490
|
+
import { readdirSync } from "fs";
|
|
3491
|
+
import { join as join4, sep } from "path";
|
|
3492
|
+
var SKIP_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
3493
|
+
"node_modules",
|
|
3494
|
+
".git",
|
|
3495
|
+
"dist",
|
|
3496
|
+
"build",
|
|
3497
|
+
"coverage",
|
|
3498
|
+
".next",
|
|
3499
|
+
".turbo",
|
|
3500
|
+
".cache",
|
|
3501
|
+
"out"
|
|
3502
|
+
]);
|
|
3503
|
+
var MAX_INDEXED_FILES = 2e4;
|
|
3504
|
+
function indexProjectFiles(configDir) {
|
|
3505
|
+
const found = [];
|
|
3506
|
+
const walk2 = (dir, prefix) => {
|
|
3507
|
+
if (found.length >= MAX_INDEXED_FILES)
|
|
3508
|
+
return;
|
|
3509
|
+
let entries;
|
|
3510
|
+
try {
|
|
3511
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
3512
|
+
} catch {
|
|
3513
|
+
return;
|
|
3514
|
+
}
|
|
3515
|
+
for (const entry of entries) {
|
|
3516
|
+
if (found.length >= MAX_INDEXED_FILES)
|
|
3517
|
+
return;
|
|
3518
|
+
const relative3 = prefix ? `${prefix}/${entry.name}` : entry.name;
|
|
3519
|
+
if (entry.isDirectory()) {
|
|
3520
|
+
if (SKIP_DIRECTORIES.has(entry.name))
|
|
3521
|
+
continue;
|
|
3522
|
+
found.push(relative3);
|
|
3523
|
+
walk2(join4(dir, entry.name), relative3);
|
|
3524
|
+
} else {
|
|
3525
|
+
found.push(relative3);
|
|
3526
|
+
}
|
|
3527
|
+
}
|
|
3528
|
+
};
|
|
3529
|
+
walk2(configDir, "");
|
|
3530
|
+
return found;
|
|
3531
|
+
}
|
|
3532
|
+
var PLACEHOLDER_STEMS = /* @__PURE__ */ new Set([
|
|
3533
|
+
"foo",
|
|
3534
|
+
"bar",
|
|
3535
|
+
"baz",
|
|
3536
|
+
"qux",
|
|
3537
|
+
"example",
|
|
3538
|
+
"your-app",
|
|
3539
|
+
"my-app",
|
|
3540
|
+
"some-file",
|
|
3541
|
+
"path"
|
|
3542
|
+
]);
|
|
3543
|
+
function isPlaceholder(reference) {
|
|
3544
|
+
const base = reference.split("/").pop() ?? reference;
|
|
3545
|
+
const stem = base.split(".")[0] ?? base;
|
|
3546
|
+
return PLACEHOLDER_STEMS.has(stem.toLowerCase());
|
|
3547
|
+
}
|
|
3548
|
+
function createReferenceResolver(files) {
|
|
3549
|
+
const exact = new Set(files);
|
|
3550
|
+
const byLastSegment = /* @__PURE__ */ new Map();
|
|
3551
|
+
for (const file of files) {
|
|
3552
|
+
const last = file.split("/").pop();
|
|
3553
|
+
const bucket = byLastSegment.get(last);
|
|
3554
|
+
if (bucket)
|
|
3555
|
+
bucket.push(file);
|
|
3556
|
+
else
|
|
3557
|
+
byLastSegment.set(last, [file]);
|
|
3558
|
+
}
|
|
3559
|
+
return (reference) => {
|
|
3560
|
+
const normalised = reference.split(sep).join("/");
|
|
3561
|
+
if (exact.has(normalised))
|
|
3562
|
+
return true;
|
|
3563
|
+
if (isPlaceholder(normalised))
|
|
3564
|
+
return true;
|
|
3565
|
+
const last = normalised.split("/").pop();
|
|
3566
|
+
if (!last)
|
|
3567
|
+
return false;
|
|
3568
|
+
const candidates = byLastSegment.get(last);
|
|
3569
|
+
if (!candidates)
|
|
3570
|
+
return false;
|
|
3571
|
+
return candidates.some((candidate) => candidate === normalised || candidate.endsWith(`/${normalised}`));
|
|
3572
|
+
};
|
|
3573
|
+
}
|
|
3574
|
+
|
|
3575
|
+
// ../lint/dist/agents/index.js
|
|
3576
|
+
var AGENT_RULES = [structureRule, staleReferencesRule, sizeBudgetRule];
|
|
3577
|
+
var VALID_SEVERITIES = /* @__PURE__ */ new Set(["error", "warn", "info"]);
|
|
3578
|
+
var AgentConfigError = class extends Error {
|
|
3579
|
+
};
|
|
3580
|
+
function resolveAgentRules(overrides = {}) {
|
|
3581
|
+
const known = new Map(AGENT_RULES.map((rule) => [rule.id, rule]));
|
|
3582
|
+
for (const id of Object.keys(overrides)) {
|
|
3583
|
+
if (!known.has(id)) {
|
|
3584
|
+
throw new AgentConfigError(`Unknown agent rule "${id}" in agents.rules. Known rules: ${[...known.keys()].join(", ")}.`);
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
const resolved = [];
|
|
3588
|
+
for (const rule of AGENT_RULES) {
|
|
3589
|
+
const override = overrides[rule.id];
|
|
3590
|
+
if (override === void 0) {
|
|
3591
|
+
resolved.push(rule);
|
|
3592
|
+
continue;
|
|
3593
|
+
}
|
|
3594
|
+
if (override === false || override === "off")
|
|
3595
|
+
continue;
|
|
3596
|
+
if (typeof override === "string" && VALID_SEVERITIES.has(override)) {
|
|
3597
|
+
resolved.push({ ...rule, severity: override });
|
|
3598
|
+
continue;
|
|
3599
|
+
}
|
|
3600
|
+
throw new AgentConfigError(`Invalid severity ${JSON.stringify(override)} for "${rule.id}". Use "error", "warn", "info", "off", or false.`);
|
|
3601
|
+
}
|
|
3602
|
+
return resolved;
|
|
3603
|
+
}
|
|
3604
|
+
async function lintAgentFiles(options) {
|
|
3605
|
+
const { config, configDir } = options;
|
|
3606
|
+
const agents = config.agents ?? {};
|
|
3607
|
+
const patterns = agents.paths ?? DEFAULT_AGENT_PATHS;
|
|
3608
|
+
const maxTokens = agents.max_tokens ?? DEFAULT_MAX_TOKENS;
|
|
3609
|
+
const rules = resolveAgentRules(agents.rules);
|
|
3610
|
+
const files = await discoverAgentFiles(patterns, configDir);
|
|
3611
|
+
const exists = options.exists ?? (files.length > 0 ? createReferenceResolver(indexProjectFiles(configDir)) : () => true);
|
|
3612
|
+
const diagnostics = [];
|
|
3613
|
+
for (const file of files) {
|
|
3614
|
+
for (const rule of rules) {
|
|
3615
|
+
const result = rule.run({ file, configDir, exists, maxTokens });
|
|
3616
|
+
for (const diagnostic of result.diagnostics) {
|
|
3617
|
+
diagnostics.push({ ...diagnostic, severity: rule.severity });
|
|
3618
|
+
}
|
|
3619
|
+
if (result.assessed === false) {
|
|
3620
|
+
diagnostics.push({
|
|
3621
|
+
ruleId: rule.id,
|
|
3622
|
+
severity: "info",
|
|
3623
|
+
message: result.notAssessedReason ?? `${rule.id} assessed nothing in ${file.relativePath}.`,
|
|
3624
|
+
filePath: file.filePath
|
|
3625
|
+
});
|
|
3626
|
+
}
|
|
3627
|
+
}
|
|
1330
3628
|
}
|
|
3629
|
+
return { diagnostics, filesLinted: files.length, assessed: files.length > 0 };
|
|
3630
|
+
}
|
|
3631
|
+
|
|
3632
|
+
// src/shared-args.ts
|
|
3633
|
+
var quietArg = {
|
|
3634
|
+
type: "boolean",
|
|
3635
|
+
description: "Suppress success and summary output; problems still print",
|
|
3636
|
+
alias: ["q"]
|
|
3637
|
+
};
|
|
3638
|
+
var verboseArg = {
|
|
3639
|
+
type: "boolean",
|
|
3640
|
+
description: "Enable debug output",
|
|
3641
|
+
alias: ["V"]
|
|
1331
3642
|
};
|
|
3643
|
+
function formatArg(formats) {
|
|
3644
|
+
const [fallback] = formats;
|
|
3645
|
+
if (!fallback) throw new Error("formatArg requires at least one format");
|
|
3646
|
+
return {
|
|
3647
|
+
type: "string",
|
|
3648
|
+
description: `Output format (${formats.join(", ")})`,
|
|
3649
|
+
default: fallback
|
|
3650
|
+
};
|
|
3651
|
+
}
|
|
3652
|
+
function sharedArgs(formats) {
|
|
3653
|
+
return { quiet: quietArg, verbose: verboseArg, format: formatArg(formats) };
|
|
3654
|
+
}
|
|
3655
|
+
function resolveFormat(value, formats) {
|
|
3656
|
+
const [fallback] = formats;
|
|
3657
|
+
if (!fallback) throw new Error("resolveFormat requires at least one format");
|
|
3658
|
+
if (value === void 0) return { ok: true, format: fallback };
|
|
3659
|
+
if (formats.includes(value)) return { ok: true, format: value };
|
|
3660
|
+
return {
|
|
3661
|
+
ok: false,
|
|
3662
|
+
message: `unknown --format "${value}". This command renders: ${formats.join(", ")}.`
|
|
3663
|
+
};
|
|
3664
|
+
}
|
|
3665
|
+
|
|
3666
|
+
// src/output.ts
|
|
3667
|
+
function createOutput(options = {}) {
|
|
3668
|
+
const quiet = options.quiet === true;
|
|
3669
|
+
return {
|
|
3670
|
+
info(line = "") {
|
|
3671
|
+
if (!quiet) console.log(line);
|
|
3672
|
+
},
|
|
3673
|
+
out(line = "") {
|
|
3674
|
+
console.log(line);
|
|
3675
|
+
},
|
|
3676
|
+
error(line = "") {
|
|
3677
|
+
console.error(line);
|
|
3678
|
+
}
|
|
3679
|
+
};
|
|
3680
|
+
}
|
|
1332
3681
|
|
|
1333
3682
|
// src/formatters/pretty.ts
|
|
1334
3683
|
function formatPretty(diagnostics) {
|
|
@@ -1348,17 +3697,25 @@ function formatJson(diagnostics) {
|
|
|
1348
3697
|
// src/formatters/github.ts
|
|
1349
3698
|
function formatGithub(diagnostics) {
|
|
1350
3699
|
return diagnostics.map((d) => {
|
|
1351
|
-
const level = d.severity === "error" ? "error" : "warning";
|
|
3700
|
+
const level = d.severity === "error" ? "error" : d.severity === "warn" ? "warning" : "notice";
|
|
1352
3701
|
const line = d.line ? `,line=${d.line}` : "";
|
|
1353
3702
|
return `::${level} file=${d.filePath}${line}::${d.message} (${d.ruleId})`;
|
|
1354
3703
|
}).join("\n");
|
|
1355
3704
|
}
|
|
1356
3705
|
|
|
1357
|
-
// src/commands/lint.ts
|
|
3706
|
+
// src/commands/core/lint.ts
|
|
3707
|
+
var FORMATS = ["pretty", "json", "github"];
|
|
1358
3708
|
async function runLint(options) {
|
|
3709
|
+
if (!options.configDir) {
|
|
3710
|
+
throw new TypeError("runLint requires `configDir` \u2014 the directory holding spec.config.yaml.");
|
|
3711
|
+
}
|
|
1359
3712
|
const config = await loadConfig(void 0, options.configDir);
|
|
1360
3713
|
const preset = options.preset ?? config.lint?.extends ?? "recommended";
|
|
1361
|
-
const rules =
|
|
3714
|
+
const { rules, ignore } = await resolveLintConfig({
|
|
3715
|
+
config,
|
|
3716
|
+
preset,
|
|
3717
|
+
configDir: options.configDir
|
|
3718
|
+
});
|
|
1362
3719
|
const specs = [];
|
|
1363
3720
|
for (const [, entry] of Object.entries(config.specs)) {
|
|
1364
3721
|
const files = await resolveGlob(entry.path, options.configDir);
|
|
@@ -1373,11 +3730,12 @@ async function runLint(options) {
|
|
|
1373
3730
|
} catch (err) {
|
|
1374
3731
|
graphError = err.message;
|
|
1375
3732
|
}
|
|
1376
|
-
const engine = createLintEngine({ rules, config, graph });
|
|
3733
|
+
const engine = createLintEngine({ rules, config, graph, ignore });
|
|
1377
3734
|
const results = engine.lint(specs);
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
3735
|
+
const { specPath } = options;
|
|
3736
|
+
const selects = (filePath) => specPath === void 0 || filePath.includes(specPath);
|
|
3737
|
+
if (specPath !== void 0) {
|
|
3738
|
+
results.diagnostics = results.diagnostics.filter((d) => selects(d.filePath));
|
|
1381
3739
|
results.hasErrors = results.diagnostics.some((d) => d.severity === "error");
|
|
1382
3740
|
results.hasWarnings = results.diagnostics.some((d) => d.severity === "warn");
|
|
1383
3741
|
}
|
|
@@ -1390,18 +3748,57 @@ async function runLint(options) {
|
|
|
1390
3748
|
});
|
|
1391
3749
|
results.hasErrors = true;
|
|
1392
3750
|
}
|
|
1393
|
-
|
|
3751
|
+
let agentFiles = 0;
|
|
3752
|
+
if (config.agents) {
|
|
3753
|
+
const agentResults = await lintAgentFiles({ config, configDir: options.configDir });
|
|
3754
|
+
agentFiles = agentResults.filesLinted;
|
|
3755
|
+
if (!agentResults.assessed) {
|
|
3756
|
+
const patterns = config.agents.paths ?? ["AGENTS.md", "CLAUDE.md"];
|
|
3757
|
+
results.diagnostics.push({
|
|
3758
|
+
ruleId: "agents/paths-match-nothing",
|
|
3759
|
+
severity: "error",
|
|
3760
|
+
message: `agents.paths matched no files (${patterns.join(", ")}), so no agent instruction file was linted. Remove the \`agents\` key or fix the paths.`,
|
|
3761
|
+
filePath: "spec.config.yaml"
|
|
3762
|
+
});
|
|
3763
|
+
results.hasErrors = true;
|
|
3764
|
+
}
|
|
3765
|
+
for (const diagnostic of agentResults.diagnostics) {
|
|
3766
|
+
if (!selects(diagnostic.filePath)) continue;
|
|
3767
|
+
results.diagnostics.push(diagnostic);
|
|
3768
|
+
if (diagnostic.severity === "error") results.hasErrors = true;
|
|
3769
|
+
if (diagnostic.severity === "warn") results.hasWarnings = true;
|
|
3770
|
+
}
|
|
3771
|
+
}
|
|
3772
|
+
const ignored = new Set(ignore);
|
|
3773
|
+
const linted = specs.filter((spec) => !ignored.has(spec.filePath) && selects(spec.filePath));
|
|
3774
|
+
return { ...results, specFiles: linted.length, assessed: linted.length > 0, agentFiles };
|
|
3775
|
+
}
|
|
3776
|
+
function cleanRunMessage(results) {
|
|
3777
|
+
const parts = [`${results.specFiles} ${results.specFiles === 1 ? "spec" : "specs"}`];
|
|
3778
|
+
if (results.agentFiles > 0) {
|
|
3779
|
+
parts.push(`${results.agentFiles} agent ${results.agentFiles === 1 ? "file" : "files"}`);
|
|
3780
|
+
}
|
|
3781
|
+
return ` \u2713 ${parts.join(" and ")} checked, no problems found.
|
|
3782
|
+
`;
|
|
1394
3783
|
}
|
|
1395
3784
|
var lint_default = defineCommand2({
|
|
1396
3785
|
meta: { name: "lint", description: "Lint all specs in the suite" },
|
|
1397
3786
|
args: {
|
|
1398
|
-
...sharedArgs,
|
|
3787
|
+
...sharedArgs(FORMATS),
|
|
1399
3788
|
fix: { type: "boolean", description: "Auto-fix issues where possible" },
|
|
1400
3789
|
path: { type: "positional", description: "Lint a specific spec file", required: false },
|
|
1401
3790
|
preset: { type: "string", description: "Lint preset (minimal, recommended, strict)" }
|
|
1402
3791
|
},
|
|
1403
3792
|
async run({ args }) {
|
|
1404
3793
|
const logger = createLogger({ quiet: args.quiet, verbose: args.verbose });
|
|
3794
|
+
const output = createOutput({ quiet: args.quiet });
|
|
3795
|
+
const format = resolveFormat(args.format, FORMATS);
|
|
3796
|
+
if (!format.ok) {
|
|
3797
|
+
console.error(`
|
|
3798
|
+
\u2717 ${format.message}
|
|
3799
|
+
`);
|
|
3800
|
+
process.exit(1);
|
|
3801
|
+
}
|
|
1405
3802
|
if (args.fix) {
|
|
1406
3803
|
logger.info("No auto-fixable issues supported yet.");
|
|
1407
3804
|
}
|
|
@@ -1411,14 +3808,21 @@ var lint_default = defineCommand2({
|
|
|
1411
3808
|
specPath: args.path,
|
|
1412
3809
|
preset: args.preset
|
|
1413
3810
|
});
|
|
1414
|
-
const formatter =
|
|
3811
|
+
const formatter = format.format === "json" ? formatJson : format.format === "github" ? formatGithub : formatPretty;
|
|
1415
3812
|
if (!results.assessed) {
|
|
1416
3813
|
console.error(
|
|
1417
|
-
|
|
3814
|
+
args.path ? `
|
|
3815
|
+
\u26A0 No specs matched path "${args.path}", so nothing was linted. Check it against the specs declared in spec.config.yaml.
|
|
3816
|
+
` : "\n \u26A0 No specs were linted. Check the spec paths in spec.config.yaml, and whether `lint.ignore` excludes them all.\n"
|
|
1418
3817
|
);
|
|
1419
3818
|
process.exit(3);
|
|
1420
3819
|
}
|
|
1421
|
-
|
|
3820
|
+
const rendered = formatter(results.diagnostics);
|
|
3821
|
+
if (format.format === "pretty" && results.diagnostics.length === 0) {
|
|
3822
|
+
output.info(cleanRunMessage(results));
|
|
3823
|
+
} else {
|
|
3824
|
+
output.out(rendered);
|
|
3825
|
+
}
|
|
1422
3826
|
if (results.hasErrors) process.exit(1);
|
|
1423
3827
|
} catch (err) {
|
|
1424
3828
|
console.error(`
|
|
@@ -1429,11 +3833,11 @@ var lint_default = defineCommand2({
|
|
|
1429
3833
|
}
|
|
1430
3834
|
});
|
|
1431
3835
|
|
|
1432
|
-
// src/commands/pack.ts
|
|
3836
|
+
// src/commands/core/pack.ts
|
|
1433
3837
|
import { defineCommand as defineCommand3 } from "citty";
|
|
1434
3838
|
|
|
1435
3839
|
// ../pack/dist/resolver.js
|
|
1436
|
-
var
|
|
3840
|
+
var STOPWORDS3 = /* @__PURE__ */ new Set([
|
|
1437
3841
|
"a",
|
|
1438
3842
|
"an",
|
|
1439
3843
|
"and",
|
|
@@ -1510,7 +3914,7 @@ var STOPWORDS2 = /* @__PURE__ */ new Set([
|
|
|
1510
3914
|
"your"
|
|
1511
3915
|
]);
|
|
1512
3916
|
function tokenize(task) {
|
|
1513
|
-
return task.split(/[\s\-_/.,;:!?()[\]{}'"]+/).map((t) => t.toLowerCase()).filter((t) => t.length > 1 && !
|
|
3917
|
+
return task.split(/[\s\-_/.,;:!?()[\]{}'"]+/).map((t) => t.toLowerCase()).filter((t) => t.length > 1 && !STOPWORDS3.has(t));
|
|
1514
3918
|
}
|
|
1515
3919
|
var WEIGHT_TAGS = 3;
|
|
1516
3920
|
var WEIGHT_TITLE = 3;
|
|
@@ -1790,12 +4194,18 @@ function allocate(specs, scores, options) {
|
|
|
1790
4194
|
for (const spec of specs) {
|
|
1791
4195
|
specMap.set(spec.frontmatter.id, spec);
|
|
1792
4196
|
}
|
|
4197
|
+
function tokensOf(compressed) {
|
|
4198
|
+
if (compressed.collapsed)
|
|
4199
|
+
return countTokens(compressed.collapsedSummary ?? "");
|
|
4200
|
+
return compressed.sections.reduce((sum, section) => sum + section.tokens, 0);
|
|
4201
|
+
}
|
|
1793
4202
|
const items = [];
|
|
1794
4203
|
for (const score of scores) {
|
|
1795
4204
|
const spec = specMap.get(score.specId);
|
|
1796
4205
|
if (!spec)
|
|
1797
4206
|
continue;
|
|
1798
4207
|
let compressed;
|
|
4208
|
+
let stale;
|
|
1799
4209
|
if (options.full) {
|
|
1800
4210
|
compressed = {
|
|
1801
4211
|
specId: score.specId,
|
|
@@ -1811,20 +4221,34 @@ function allocate(specs, scores, options) {
|
|
|
1811
4221
|
collapsed: false
|
|
1812
4222
|
};
|
|
1813
4223
|
} else {
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
tokens += section.tokens;
|
|
4224
|
+
const compress = (compression) => compressSpec(score.specId, String(spec.frontmatter.type), String(spec.frontmatter.title), spec.frontmatter.status, spec.frontmatter.updated, spec.parsedSections, compression);
|
|
4225
|
+
compressed = compress({ ...options.compression, stableDays: 0 });
|
|
4226
|
+
if (options.compression.stableDays > 0) {
|
|
4227
|
+
const collapsed = compress(options.compression);
|
|
4228
|
+
const collapsedTokens = tokensOf(collapsed);
|
|
4229
|
+
if (collapsedTokens < tokensOf(compressed)) {
|
|
4230
|
+
stale = { spec: collapsed, tokens: collapsedTokens };
|
|
4231
|
+
}
|
|
1823
4232
|
}
|
|
1824
4233
|
}
|
|
1825
|
-
items.push({
|
|
4234
|
+
items.push({
|
|
4235
|
+
compressed,
|
|
4236
|
+
relevance: score.score,
|
|
4237
|
+
tokens: tokensOf(compressed),
|
|
4238
|
+
idMatched: score.idMatched ?? false,
|
|
4239
|
+
stale
|
|
4240
|
+
});
|
|
1826
4241
|
}
|
|
1827
4242
|
items.sort((a, b) => b.relevance - a.relevance || Number(b.idMatched) - Number(a.idMatched));
|
|
4243
|
+
let projected = items.reduce((sum, item) => sum + item.tokens, 0);
|
|
4244
|
+
for (let i = items.length - 1; i >= 0 && projected > options.budget; i--) {
|
|
4245
|
+
const item = items[i];
|
|
4246
|
+
if (!item.stale)
|
|
4247
|
+
continue;
|
|
4248
|
+
projected -= item.tokens - item.stale.tokens;
|
|
4249
|
+
item.compressed = item.stale.spec;
|
|
4250
|
+
item.tokens = item.stale.tokens;
|
|
4251
|
+
}
|
|
1828
4252
|
const totalTokens = items.reduce((sum, item) => sum + item.tokens, 0);
|
|
1829
4253
|
const withinBudget = totalTokens <= options.budget;
|
|
1830
4254
|
const included = [];
|
|
@@ -2091,7 +4515,7 @@ function pack(specs, options, packConfig, graph) {
|
|
|
2091
4515
|
return { output, stats };
|
|
2092
4516
|
}
|
|
2093
4517
|
|
|
2094
|
-
// src/commands/pack.ts
|
|
4518
|
+
// src/commands/core/pack.ts
|
|
2095
4519
|
import { writeFile as writeFile2 } from "fs/promises";
|
|
2096
4520
|
import { execSync } from "child_process";
|
|
2097
4521
|
function copyToClipboard(text) {
|
|
@@ -2108,7 +4532,20 @@ function copyToClipboard(text) {
|
|
|
2108
4532
|
}
|
|
2109
4533
|
execSync(cmd, { input: text, stdio: ["pipe", "ignore", "ignore"] });
|
|
2110
4534
|
}
|
|
4535
|
+
function emptyPackReason(stats, specsResolved) {
|
|
4536
|
+
if (stats.specsIncluded > 0) return void 0;
|
|
4537
|
+
if (specsResolved === 0) {
|
|
4538
|
+
return "no specs resolved from spec.config.yaml \u2014 check the paths in your config";
|
|
4539
|
+
}
|
|
4540
|
+
if (stats.specsExcluded === 0) {
|
|
4541
|
+
return `none of the ${specsResolved} resolved spec(s) scored above the relevance threshold for this task \u2014 try different --task wording, name specs with --specs, or use --full`;
|
|
4542
|
+
}
|
|
4543
|
+
return `all ${stats.specsExcluded} candidate spec(s) were excluded \u2014 widen --specs or raise --budget`;
|
|
4544
|
+
}
|
|
2111
4545
|
async function runPack(options) {
|
|
4546
|
+
if (!options.configDir) {
|
|
4547
|
+
throw new TypeError("runPack requires `configDir` \u2014 the directory holding spec.config.yaml.");
|
|
4548
|
+
}
|
|
2112
4549
|
const config = await loadConfig(void 0, options.configDir);
|
|
2113
4550
|
const allSpecs = [];
|
|
2114
4551
|
for (const [, entry] of Object.entries(config.specs)) {
|
|
@@ -2135,13 +4572,13 @@ async function runPack(options) {
|
|
|
2135
4572
|
config.pack,
|
|
2136
4573
|
graph
|
|
2137
4574
|
);
|
|
2138
|
-
return result;
|
|
4575
|
+
return { ...result, specsResolved: allSpecs.length };
|
|
2139
4576
|
}
|
|
2140
4577
|
var pack_default = defineCommand3({
|
|
2141
4578
|
meta: { name: "pack", description: "Pack specs into AI-ready context" },
|
|
2142
4579
|
args: {
|
|
2143
|
-
quiet:
|
|
2144
|
-
verbose:
|
|
4580
|
+
quiet: quietArg,
|
|
4581
|
+
verbose: verboseArg,
|
|
2145
4582
|
task: { type: "string", description: "Task or context to optimise relevance for" },
|
|
2146
4583
|
specs: { type: "string", description: "Comma-separated spec IDs or glob patterns to include" },
|
|
2147
4584
|
budget: { type: "string", description: "Maximum token budget for the output" },
|
|
@@ -2206,12 +4643,16 @@ var pack_default = defineCommand3({
|
|
|
2206
4643
|
}
|
|
2207
4644
|
console.log(`
|
|
2208
4645
|
Budget: ${stats.used} / ${stats.budget} tokens`);
|
|
2209
|
-
console.log(
|
|
2210
|
-
` Included: ${stats.specsIncluded} / ${stats.specsIncluded + stats.specsExcluded} specs`
|
|
2211
|
-
);
|
|
4646
|
+
console.log(` Included: ${stats.specsIncluded} / ${result.specsResolved} specs`);
|
|
2212
4647
|
console.log(` Sections compressed: ${stats.sectionsCompressed}`);
|
|
2213
4648
|
console.log(` Sections omitted: ${stats.sectionsOmitted}
|
|
2214
4649
|
`);
|
|
4650
|
+
const dryReason = emptyPackReason(stats, result.specsResolved);
|
|
4651
|
+
if (dryReason) {
|
|
4652
|
+
console.log(` \u26A0 Nothing would be packed: ${dryReason}
|
|
4653
|
+
`);
|
|
4654
|
+
process.exit(3);
|
|
4655
|
+
}
|
|
2215
4656
|
return;
|
|
2216
4657
|
}
|
|
2217
4658
|
if (args.out) {
|
|
@@ -2230,6 +4671,14 @@ var pack_default = defineCommand3({
|
|
|
2230
4671
|
`Packed ${stats.specsIncluded}/${total} specs \u2022 ${stats.used} / ${stats.budget} tokens \u2022 ${stats.sectionsCompressed} sections compressed \u2022 ${stats.sectionsOmitted} sections omitted
|
|
2231
4672
|
`
|
|
2232
4673
|
);
|
|
4674
|
+
const emptyReason = emptyPackReason(stats, result.specsResolved);
|
|
4675
|
+
if (emptyReason) {
|
|
4676
|
+
process.stderr.write(`
|
|
4677
|
+
\u26A0 No context packed: ${emptyReason}
|
|
4678
|
+
|
|
4679
|
+
`);
|
|
4680
|
+
process.exit(3);
|
|
4681
|
+
}
|
|
2233
4682
|
} catch (err) {
|
|
2234
4683
|
console.error(`
|
|
2235
4684
|
\u2717 ${err.message}
|
|
@@ -2239,9 +4688,9 @@ var pack_default = defineCommand3({
|
|
|
2239
4688
|
}
|
|
2240
4689
|
});
|
|
2241
4690
|
|
|
2242
|
-
// src/commands/diff.ts
|
|
4691
|
+
// src/commands/core/diff.ts
|
|
2243
4692
|
import { defineCommand as defineCommand4 } from "citty";
|
|
2244
|
-
import { join as
|
|
4693
|
+
import { join as join6 } from "path";
|
|
2245
4694
|
|
|
2246
4695
|
// ../diff/dist/types.js
|
|
2247
4696
|
var DEFAULT_DIFF_CONFIG = {
|
|
@@ -2429,7 +4878,7 @@ Diff.prototype = {
|
|
|
2429
4878
|
tokenize: function tokenize2(value) {
|
|
2430
4879
|
return Array.from(value);
|
|
2431
4880
|
},
|
|
2432
|
-
join: function
|
|
4881
|
+
join: function join5(chars) {
|
|
2433
4882
|
return chars.join("");
|
|
2434
4883
|
},
|
|
2435
4884
|
postProcess: function postProcess(changeObjects) {
|
|
@@ -2669,8 +5118,8 @@ function dedupeWhitespaceInChangeObjects(startKeep, deletion, insertion, endKeep
|
|
|
2669
5118
|
} else if (endKeep) {
|
|
2670
5119
|
var endKeepWsPrefix = endKeep.value.match(/^\s*/)[0];
|
|
2671
5120
|
var deletionWsSuffix = deletion.value.match(/\s*$/)[0];
|
|
2672
|
-
var
|
|
2673
|
-
deletion.value = removeSuffix(deletion.value,
|
|
5121
|
+
var overlap2 = maximumOverlap(deletionWsSuffix, endKeepWsPrefix);
|
|
5122
|
+
deletion.value = removeSuffix(deletion.value, overlap2);
|
|
2674
5123
|
} else if (startKeep) {
|
|
2675
5124
|
var startKeepWsSuffix = startKeep.value.match(/\s*$/)[0];
|
|
2676
5125
|
var deletionWsPrefix = deletion.value.match(/^\s*/)[0];
|
|
@@ -3130,10 +5579,10 @@ var STRUCTURAL_SECTIONS = /* @__PURE__ */ new Set([
|
|
|
3130
5579
|
"API Design",
|
|
3131
5580
|
"Problem Statement"
|
|
3132
5581
|
]);
|
|
3133
|
-
function bfsDistances(startId,
|
|
5582
|
+
function bfsDistances(startId, relations) {
|
|
3134
5583
|
const distances = /* @__PURE__ */ new Map();
|
|
3135
5584
|
const queue = [];
|
|
3136
|
-
for (const edge of
|
|
5585
|
+
for (const edge of relations.edges) {
|
|
3137
5586
|
if (edge.from === startId) {
|
|
3138
5587
|
if (!distances.has(edge.to)) {
|
|
3139
5588
|
distances.set(edge.to, 1);
|
|
@@ -3144,7 +5593,7 @@ function bfsDistances(startId, graph) {
|
|
|
3144
5593
|
while (queue.length > 0) {
|
|
3145
5594
|
const item = queue.shift();
|
|
3146
5595
|
const currentDist = item.distance;
|
|
3147
|
-
for (const edge of
|
|
5596
|
+
for (const edge of relations.edges) {
|
|
3148
5597
|
if (edge.from === item.id && !distances.has(edge.to)) {
|
|
3149
5598
|
distances.set(edge.to, currentDist + 1);
|
|
3150
5599
|
queue.push({ id: edge.to, distance: currentDist + 1 });
|
|
@@ -3161,8 +5610,8 @@ function daysBetween(dateStr) {
|
|
|
3161
5610
|
function clamp(min, max, value) {
|
|
3162
5611
|
return Math.min(max, Math.max(min, value));
|
|
3163
5612
|
}
|
|
3164
|
-
function analyzeImpact(changedSpecId, diff2,
|
|
3165
|
-
const distanceMap = bfsDistances(changedSpecId,
|
|
5613
|
+
function analyzeImpact(changedSpecId, diff2, relations, allSpecs, thresholdDays = 14) {
|
|
5614
|
+
const distanceMap = bfsDistances(changedSpecId, relations);
|
|
3166
5615
|
if (distanceMap.size === 0) {
|
|
3167
5616
|
return {
|
|
3168
5617
|
changedSpec: changedSpecId,
|
|
@@ -3181,11 +5630,11 @@ function analyzeImpact(changedSpecId, diff2, graph, allSpecs, thresholdDays = 14
|
|
|
3181
5630
|
const downstream = [];
|
|
3182
5631
|
for (const [specId, distance] of distanceMap) {
|
|
3183
5632
|
const spec = specById.get(specId);
|
|
3184
|
-
const
|
|
5633
|
+
const lastUpdated2 = spec?.frontmatter.updated ?? spec?.frontmatter.created ?? null;
|
|
3185
5634
|
const filePath = spec?.filePath ?? `specs/${specId}.md`;
|
|
3186
5635
|
let staleness;
|
|
3187
|
-
if (
|
|
3188
|
-
const daysSinceUpdate = daysBetween(
|
|
5636
|
+
if (lastUpdated2) {
|
|
5637
|
+
const daysSinceUpdate = daysBetween(lastUpdated2);
|
|
3189
5638
|
staleness = clamp(0, 1, daysSinceUpdate / thresholdDays * 0.5 + structuralSectionsChanged / totalSections * 0.3 + 1 / distance * 0.2);
|
|
3190
5639
|
} else {
|
|
3191
5640
|
staleness = clamp(0, 1, structuralSectionsChanged / totalSections * 0.3 + 1 / distance * 0.2);
|
|
@@ -3195,8 +5644,8 @@ function analyzeImpact(changedSpecId, diff2, graph, allSpecs, thresholdDays = 14
|
|
|
3195
5644
|
if (structuralSectionsChanged > 0) {
|
|
3196
5645
|
parts.push(`${structuralSectionsChanged} structural section(s) changed`);
|
|
3197
5646
|
}
|
|
3198
|
-
if (
|
|
3199
|
-
const days = Math.round(daysBetween(
|
|
5647
|
+
if (lastUpdated2) {
|
|
5648
|
+
const days = Math.round(daysBetween(lastUpdated2));
|
|
3200
5649
|
parts.push(`last updated ${days} day(s) ago`);
|
|
3201
5650
|
}
|
|
3202
5651
|
const reason = parts.join("; ");
|
|
@@ -3204,7 +5653,7 @@ function analyzeImpact(changedSpecId, diff2, graph, allSpecs, thresholdDays = 14
|
|
|
3204
5653
|
specId,
|
|
3205
5654
|
filePath,
|
|
3206
5655
|
distance,
|
|
3207
|
-
lastUpdated,
|
|
5656
|
+
lastUpdated: lastUpdated2,
|
|
3208
5657
|
staleness,
|
|
3209
5658
|
reason
|
|
3210
5659
|
});
|
|
@@ -3244,53 +5693,181 @@ function checkCrossReferences(allSpecs, removedIds) {
|
|
|
3244
5693
|
}
|
|
3245
5694
|
|
|
3246
5695
|
// ../diff/dist/git.js
|
|
5696
|
+
var import_picomatch = __toESM(require_picomatch2(), 1);
|
|
3247
5697
|
import { execSync as execSync2 } from "child_process";
|
|
3248
|
-
import { realpathSync } from "fs";
|
|
3249
|
-
import { dirname as dirname2, relative, resolve as
|
|
5698
|
+
import { readFileSync, realpathSync } from "fs";
|
|
5699
|
+
import { dirname as dirname2, relative as relative2, resolve as resolve4, sep as sep2 } from "path";
|
|
3250
5700
|
function getRepoRoot(cwd) {
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
5701
|
+
let root;
|
|
5702
|
+
try {
|
|
5703
|
+
root = execSync2("git rev-parse --show-toplevel", {
|
|
5704
|
+
cwd,
|
|
5705
|
+
encoding: "utf-8",
|
|
5706
|
+
stdio: "pipe"
|
|
5707
|
+
}).trim();
|
|
5708
|
+
} catch {
|
|
5709
|
+
throw new DiffError("diff compares specs across git history, and this directory is not inside a git repository. Run `git init` first, or run diff from a checked-out project.");
|
|
5710
|
+
}
|
|
3256
5711
|
return realpathSync(root);
|
|
3257
5712
|
}
|
|
3258
|
-
function validateRef(ref, cwd) {
|
|
5713
|
+
function validateRef(ref, cwd) {
|
|
5714
|
+
try {
|
|
5715
|
+
execSync2(`git rev-parse --verify ${ref}`, { cwd, encoding: "utf-8", stdio: "pipe" });
|
|
5716
|
+
} catch {
|
|
5717
|
+
throw new DiffError(`Invalid git ref: "${ref}"`);
|
|
5718
|
+
}
|
|
5719
|
+
}
|
|
5720
|
+
function gitShow(ref, filePath, projectRoot, repoRoot) {
|
|
5721
|
+
const relPath = relative2(repoRoot, resolve4(projectRoot, filePath));
|
|
5722
|
+
try {
|
|
5723
|
+
return execSync2(`git show ${ref}:${relPath}`, {
|
|
5724
|
+
cwd: repoRoot,
|
|
5725
|
+
encoding: "utf-8",
|
|
5726
|
+
stdio: "pipe"
|
|
5727
|
+
});
|
|
5728
|
+
} catch {
|
|
5729
|
+
throw new DiffError(`Cannot read "${filePath}" at ref "${ref}"`);
|
|
5730
|
+
}
|
|
5731
|
+
}
|
|
5732
|
+
function toPosix(p) {
|
|
5733
|
+
return sep2 === "/" ? p : p.split(sep2).join("/");
|
|
5734
|
+
}
|
|
5735
|
+
function buildEntryMatchers(specPathsByKey, projectRoot, repoRoot) {
|
|
5736
|
+
return [...specPathsByKey].map(([key, specPath]) => ({
|
|
5737
|
+
key,
|
|
5738
|
+
isMatch: (0, import_picomatch.default)(toPosix(relative2(repoRoot, resolve4(projectRoot, specPath))))
|
|
5739
|
+
}));
|
|
5740
|
+
}
|
|
5741
|
+
function getChangedSpecFiles(baseRef, headRef, matchers, projectRoot, repoRoot) {
|
|
5742
|
+
let diffOutput;
|
|
5743
|
+
try {
|
|
5744
|
+
diffOutput = execSync2(`git diff --name-status ${baseRef} ${headRef}`, {
|
|
5745
|
+
cwd: repoRoot,
|
|
5746
|
+
encoding: "utf-8",
|
|
5747
|
+
stdio: "pipe"
|
|
5748
|
+
});
|
|
5749
|
+
} catch {
|
|
5750
|
+
throw new DiffError(`Failed to run git diff between "${baseRef}" and "${headRef}"`);
|
|
5751
|
+
}
|
|
5752
|
+
const result = { modified: [], added: [], deleted: [] };
|
|
5753
|
+
for (const line of diffOutput.trim().split("\n")) {
|
|
5754
|
+
if (!line)
|
|
5755
|
+
continue;
|
|
5756
|
+
const parts = line.split(" ");
|
|
5757
|
+
const status = parts[0];
|
|
5758
|
+
const filePath = parts[1];
|
|
5759
|
+
if (!status || !filePath)
|
|
5760
|
+
continue;
|
|
5761
|
+
const entry = matchers.find((m) => m.isMatch(filePath));
|
|
5762
|
+
if (!entry)
|
|
5763
|
+
continue;
|
|
5764
|
+
const changed = {
|
|
5765
|
+
path: relative2(projectRoot, resolve4(repoRoot, filePath)),
|
|
5766
|
+
entryKey: entry.key
|
|
5767
|
+
};
|
|
5768
|
+
if (status === "M") {
|
|
5769
|
+
result.modified.push(changed);
|
|
5770
|
+
} else if (status === "A") {
|
|
5771
|
+
result.added.push(changed);
|
|
5772
|
+
} else if (status === "D") {
|
|
5773
|
+
result.deleted.push(changed);
|
|
5774
|
+
}
|
|
5775
|
+
}
|
|
5776
|
+
return result;
|
|
5777
|
+
}
|
|
5778
|
+
function listSpecFilesAtRef(ref, matchers, projectRoot, repoRoot) {
|
|
5779
|
+
const byEntry = new Map(matchers.map((m) => [m.key, []]));
|
|
5780
|
+
let listing;
|
|
3259
5781
|
try {
|
|
3260
|
-
execSync2(`git
|
|
5782
|
+
listing = execSync2(`git ls-tree -r --name-only ${ref}`, {
|
|
5783
|
+
cwd: repoRoot,
|
|
5784
|
+
encoding: "utf-8",
|
|
5785
|
+
stdio: "pipe"
|
|
5786
|
+
});
|
|
3261
5787
|
} catch {
|
|
3262
|
-
throw new DiffError(`
|
|
5788
|
+
throw new DiffError(`Failed to list files at ref "${ref}"`);
|
|
3263
5789
|
}
|
|
5790
|
+
for (const filePath of listing.trim().split("\n")) {
|
|
5791
|
+
if (!filePath)
|
|
5792
|
+
continue;
|
|
5793
|
+
const entry = matchers.find((m) => m.isMatch(filePath));
|
|
5794
|
+
if (!entry)
|
|
5795
|
+
continue;
|
|
5796
|
+
byEntry.get(entry.key)?.push(relative2(projectRoot, resolve4(repoRoot, filePath)));
|
|
5797
|
+
}
|
|
5798
|
+
return byEntry;
|
|
3264
5799
|
}
|
|
3265
|
-
function
|
|
3266
|
-
const
|
|
5800
|
+
function listSpecFilesInWorktree(matchers, projectRoot, repoRoot) {
|
|
5801
|
+
const byEntry = new Map(matchers.map((m) => [m.key, []]));
|
|
5802
|
+
let listing;
|
|
3267
5803
|
try {
|
|
3268
|
-
|
|
5804
|
+
listing = execSync2("git ls-files --cached --others --exclude-standard", {
|
|
3269
5805
|
cwd: repoRoot,
|
|
3270
5806
|
encoding: "utf-8",
|
|
3271
5807
|
stdio: "pipe"
|
|
3272
5808
|
});
|
|
3273
5809
|
} catch {
|
|
3274
|
-
throw new DiffError(
|
|
5810
|
+
throw new DiffError("Failed to list files in the working tree");
|
|
3275
5811
|
}
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
5812
|
+
for (const filePath of listing.trim().split("\n")) {
|
|
5813
|
+
if (!filePath)
|
|
5814
|
+
continue;
|
|
5815
|
+
const entry = matchers.find((m) => m.isMatch(filePath));
|
|
5816
|
+
if (!entry)
|
|
5817
|
+
continue;
|
|
5818
|
+
byEntry.get(entry.key)?.push(relative2(projectRoot, resolve4(repoRoot, filePath)));
|
|
3282
5819
|
}
|
|
5820
|
+
return byEntry;
|
|
5821
|
+
}
|
|
5822
|
+
function refSide(ref, matchers, projectRoot, repoRoot) {
|
|
5823
|
+
return {
|
|
5824
|
+
read: (path) => gitShow(ref, path, projectRoot, repoRoot),
|
|
5825
|
+
list: () => listSpecFilesAtRef(ref, matchers, projectRoot, repoRoot)
|
|
5826
|
+
};
|
|
5827
|
+
}
|
|
5828
|
+
function worktreeSide(matchers, projectRoot, repoRoot) {
|
|
5829
|
+
return {
|
|
5830
|
+
read: (path) => {
|
|
5831
|
+
try {
|
|
5832
|
+
return readFileSync(resolve4(projectRoot, path), "utf-8");
|
|
5833
|
+
} catch {
|
|
5834
|
+
throw new DiffError(`Cannot read "${path}" in the working tree`);
|
|
5835
|
+
}
|
|
5836
|
+
},
|
|
5837
|
+
list: () => listSpecFilesInWorktree(matchers, projectRoot, repoRoot)
|
|
5838
|
+
};
|
|
5839
|
+
}
|
|
5840
|
+
function getChangedSpecFilesInWorktree(baseRef, matchers, projectRoot, repoRoot) {
|
|
3283
5841
|
let diffOutput;
|
|
3284
5842
|
try {
|
|
3285
|
-
diffOutput = execSync2(`git diff --name-status ${baseRef}
|
|
5843
|
+
diffOutput = execSync2(`git diff --name-status ${baseRef}`, {
|
|
3286
5844
|
cwd: repoRoot,
|
|
3287
5845
|
encoding: "utf-8",
|
|
3288
5846
|
stdio: "pipe"
|
|
3289
5847
|
});
|
|
3290
5848
|
} catch {
|
|
3291
|
-
throw new DiffError(`Failed to
|
|
5849
|
+
throw new DiffError(`Failed to diff "${baseRef}" against the working tree`);
|
|
3292
5850
|
}
|
|
3293
5851
|
const result = { modified: [], added: [], deleted: [] };
|
|
5852
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5853
|
+
const record = (status, filePath) => {
|
|
5854
|
+
const entry = matchers.find((m) => m.isMatch(filePath));
|
|
5855
|
+
if (!entry)
|
|
5856
|
+
return;
|
|
5857
|
+
if (seen.has(filePath))
|
|
5858
|
+
return;
|
|
5859
|
+
seen.add(filePath);
|
|
5860
|
+
const changed = {
|
|
5861
|
+
path: relative2(projectRoot, resolve4(repoRoot, filePath)),
|
|
5862
|
+
entryKey: entry.key
|
|
5863
|
+
};
|
|
5864
|
+
if (status === "M")
|
|
5865
|
+
result.modified.push(changed);
|
|
5866
|
+
else if (status === "A")
|
|
5867
|
+
result.added.push(changed);
|
|
5868
|
+
else if (status === "D")
|
|
5869
|
+
result.deleted.push(changed);
|
|
5870
|
+
};
|
|
3294
5871
|
for (const line of diffOutput.trim().split("\n")) {
|
|
3295
5872
|
if (!line)
|
|
3296
5873
|
continue;
|
|
@@ -3299,57 +5876,105 @@ function getChangedSpecFiles(baseRef, headRef, specPaths, projectRoot, repoRoot)
|
|
|
3299
5876
|
const filePath = parts[1];
|
|
3300
5877
|
if (!status || !filePath)
|
|
3301
5878
|
continue;
|
|
3302
|
-
|
|
3303
|
-
|
|
5879
|
+
record(status, filePath);
|
|
5880
|
+
}
|
|
5881
|
+
let untracked;
|
|
5882
|
+
try {
|
|
5883
|
+
untracked = execSync2("git ls-files --others --exclude-standard", {
|
|
5884
|
+
cwd: repoRoot,
|
|
5885
|
+
encoding: "utf-8",
|
|
5886
|
+
stdio: "pipe"
|
|
5887
|
+
});
|
|
5888
|
+
} catch {
|
|
5889
|
+
throw new DiffError("Failed to list untracked files");
|
|
5890
|
+
}
|
|
5891
|
+
for (const filePath of untracked.trim().split("\n")) {
|
|
5892
|
+
if (!filePath)
|
|
3304
5893
|
continue;
|
|
3305
|
-
|
|
3306
|
-
result.modified.push(projectRelPath);
|
|
3307
|
-
} else if (status === "A") {
|
|
3308
|
-
result.added.push(projectRelPath);
|
|
3309
|
-
} else if (status === "D") {
|
|
3310
|
-
result.deleted.push(projectRelPath);
|
|
3311
|
-
}
|
|
5894
|
+
record("A", filePath);
|
|
3312
5895
|
}
|
|
3313
5896
|
return result;
|
|
3314
5897
|
}
|
|
3315
|
-
|
|
3316
|
-
|
|
5898
|
+
function listUncommittedSpecFiles(matchers, projectRoot, repoRoot) {
|
|
5899
|
+
let statusOutput;
|
|
5900
|
+
try {
|
|
5901
|
+
statusOutput = execSync2("git status --porcelain", {
|
|
5902
|
+
cwd: repoRoot,
|
|
5903
|
+
encoding: "utf-8",
|
|
5904
|
+
stdio: "pipe"
|
|
5905
|
+
});
|
|
5906
|
+
} catch {
|
|
5907
|
+
return [];
|
|
5908
|
+
}
|
|
5909
|
+
const files = [];
|
|
5910
|
+
for (const line of statusOutput.split("\n")) {
|
|
5911
|
+
if (!line.trim())
|
|
5912
|
+
continue;
|
|
5913
|
+
const rawPath = line.slice(3);
|
|
5914
|
+
const renamed = rawPath.includes(" -> ") ? rawPath.split(" -> ")[1] : void 0;
|
|
5915
|
+
const filePath = (renamed ?? rawPath).replace(/^"|"$/g, "");
|
|
5916
|
+
if (!matchers.some((m) => m.isMatch(filePath)))
|
|
5917
|
+
continue;
|
|
5918
|
+
files.push(relative2(projectRoot, resolve4(repoRoot, filePath)));
|
|
5919
|
+
}
|
|
5920
|
+
return files;
|
|
5921
|
+
}
|
|
5922
|
+
async function specIdsFrom(files, read) {
|
|
5923
|
+
const ids = [];
|
|
5924
|
+
for (const file of files) {
|
|
5925
|
+
try {
|
|
5926
|
+
const parsed = await parseSpecFromString(read(file.path), file.path);
|
|
5927
|
+
ids.push(parsed.frontmatter.id);
|
|
5928
|
+
} catch {
|
|
5929
|
+
ids.push(file.entryKey);
|
|
5930
|
+
}
|
|
5931
|
+
}
|
|
5932
|
+
return ids;
|
|
5933
|
+
}
|
|
5934
|
+
async function diffBetweenRefs(configPath, baseRef, headRef, options = {}) {
|
|
5935
|
+
const projectRoot = realpathSync(dirname2(resolve4(configPath)));
|
|
3317
5936
|
const repoRoot = getRepoRoot(projectRoot);
|
|
3318
5937
|
validateRef(baseRef, projectRoot);
|
|
3319
|
-
|
|
5938
|
+
if (!options.working)
|
|
5939
|
+
validateRef(headRef, projectRoot);
|
|
3320
5940
|
const config = await loadConfig(configPath);
|
|
3321
|
-
const
|
|
3322
|
-
const
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
const
|
|
5941
|
+
const specPathsByKey = /* @__PURE__ */ new Map();
|
|
5942
|
+
for (const [key, entry] of Object.entries(config.specs)) {
|
|
5943
|
+
specPathsByKey.set(key, entry.path);
|
|
5944
|
+
}
|
|
5945
|
+
const matchers = buildEntryMatchers(specPathsByKey, projectRoot, repoRoot);
|
|
5946
|
+
const base = refSide(baseRef, matchers, projectRoot, repoRoot);
|
|
5947
|
+
const head = options.working ? worktreeSide(matchers, projectRoot, repoRoot) : refSide(headRef, matchers, projectRoot, repoRoot);
|
|
5948
|
+
const changed = options.working ? getChangedSpecFilesInWorktree(baseRef, matchers, projectRoot, repoRoot) : getChangedSpecFiles(baseRef, headRef, matchers, projectRoot, repoRoot);
|
|
3328
5949
|
const diffs = [];
|
|
3329
|
-
for (const
|
|
3330
|
-
const
|
|
3331
|
-
const
|
|
3332
|
-
const beforeSpec = await parseSpecFromString(beforeContent, filePath);
|
|
3333
|
-
const afterSpec = await parseSpecFromString(afterContent, filePath);
|
|
5950
|
+
for (const file of changed.modified) {
|
|
5951
|
+
const beforeSpec = await parseSpecFromString(base.read(file.path), file.path);
|
|
5952
|
+
const afterSpec = await parseSpecFromString(head.read(file.path), file.path);
|
|
3334
5953
|
const diff2 = diffSpecs(beforeSpec, afterSpec);
|
|
3335
5954
|
diffs.push(diff2);
|
|
3336
5955
|
}
|
|
3337
|
-
const added = changed.added
|
|
3338
|
-
const removed = changed.deleted
|
|
3339
|
-
const graph = buildGraph(config);
|
|
5956
|
+
const added = await specIdsFrom(changed.added, head.read);
|
|
5957
|
+
const removed = await specIdsFrom(changed.deleted, base.read);
|
|
3340
5958
|
const impact = [];
|
|
3341
5959
|
const allSpecs = [];
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
5960
|
+
const specsByEntry = /* @__PURE__ */ new Map();
|
|
5961
|
+
const filesAtHead = head.list();
|
|
5962
|
+
for (const [key, paths] of filesAtHead) {
|
|
5963
|
+
const forEntry = [];
|
|
5964
|
+
for (const path of paths) {
|
|
5965
|
+
try {
|
|
5966
|
+
const parsed = await parseSpecFromString(head.read(path), path);
|
|
5967
|
+
forEntry.push(parsed);
|
|
5968
|
+
allSpecs.push(parsed);
|
|
5969
|
+
} catch {
|
|
5970
|
+
}
|
|
3348
5971
|
}
|
|
5972
|
+
specsByEntry.set(key, forEntry);
|
|
3349
5973
|
}
|
|
5974
|
+
const relations = buildRelationResolver(config, specsByEntry);
|
|
3350
5975
|
const thresholdDays = config.diff?.staleness_threshold_days ?? 14;
|
|
3351
5976
|
for (const diff2 of diffs) {
|
|
3352
|
-
const analysis = analyzeImpact(diff2.specId, diff2,
|
|
5977
|
+
const analysis = analyzeImpact(diff2.specId, diff2, relations, allSpecs, thresholdDays);
|
|
3353
5978
|
if (analysis.totalAffected > 0) {
|
|
3354
5979
|
impact.push(analysis);
|
|
3355
5980
|
}
|
|
@@ -3373,17 +5998,70 @@ async function diffBetweenRefs(configPath, baseRef, headRef) {
|
|
|
3373
5998
|
summaryParts.push(`${_brokenRefs.length} broken reference(s)`);
|
|
3374
5999
|
}
|
|
3375
6000
|
const summary = summaryParts.length > 0 ? summaryParts.join("; ") : "No changes detected";
|
|
3376
|
-
|
|
6001
|
+
const uncommittedSpecFiles = options.working ? [] : listUncommittedSpecFiles(matchers, projectRoot, repoRoot);
|
|
6002
|
+
return { diffs, added, removed, impact, summary, uncommittedSpecFiles };
|
|
6003
|
+
}
|
|
6004
|
+
|
|
6005
|
+
// src/formatters/changelog.ts
|
|
6006
|
+
function formatChangelog(result, baseRef, headRef) {
|
|
6007
|
+
const lines = [];
|
|
6008
|
+
lines.push(`## Spec Changes (${baseRef}..${headRef})
|
|
6009
|
+
`);
|
|
6010
|
+
if (result.diffs.length > 0) {
|
|
6011
|
+
lines.push("### Modified");
|
|
6012
|
+
for (const diff2 of result.diffs) {
|
|
6013
|
+
const sections = diff2.sections.map((s) => s.heading).join(", ");
|
|
6014
|
+
const versionChange = diff2.frontmatter.find((f) => f.field === "version");
|
|
6015
|
+
const versionStr = versionChange ? ` (${String(versionChange.before)} \u2192 ${String(versionChange.after)})` : "";
|
|
6016
|
+
lines.push(`- **${diff2.specId}**${versionStr} \u2014 ${sections || "frontmatter only"}`);
|
|
6017
|
+
}
|
|
6018
|
+
lines.push("");
|
|
6019
|
+
}
|
|
6020
|
+
if (result.added.length > 0) {
|
|
6021
|
+
lines.push("### Added");
|
|
6022
|
+
for (const id of result.added) {
|
|
6023
|
+
lines.push(`- **${id}**`);
|
|
6024
|
+
}
|
|
6025
|
+
lines.push("");
|
|
6026
|
+
}
|
|
6027
|
+
if (result.removed.length > 0) {
|
|
6028
|
+
lines.push("### Removed");
|
|
6029
|
+
for (const id of result.removed) {
|
|
6030
|
+
lines.push(`- **${id}**`);
|
|
6031
|
+
}
|
|
6032
|
+
lines.push("");
|
|
6033
|
+
}
|
|
6034
|
+
const allDownstream = result.impact.flatMap((i) => i.downstream);
|
|
6035
|
+
if (allDownstream.length > 0) {
|
|
6036
|
+
lines.push("### Downstream Impact");
|
|
6037
|
+
for (const d of allDownstream) {
|
|
6038
|
+
lines.push(`- ${d.specId} may be stale (${d.reason})`);
|
|
6039
|
+
}
|
|
6040
|
+
lines.push("");
|
|
6041
|
+
}
|
|
6042
|
+
if (result.diffs.length === 0 && result.added.length === 0 && result.removed.length === 0) {
|
|
6043
|
+
lines.push("No spec changes detected.\n");
|
|
6044
|
+
}
|
|
6045
|
+
if (result.uncommittedSpecFiles.length > 0) {
|
|
6046
|
+
lines.push(
|
|
6047
|
+
`> \u26A0 ${result.uncommittedSpecFiles.length} spec file(s) changed in the working tree are not covered by this range.
|
|
6048
|
+
`
|
|
6049
|
+
);
|
|
6050
|
+
}
|
|
6051
|
+
return lines.join("\n");
|
|
3377
6052
|
}
|
|
3378
6053
|
|
|
3379
|
-
// src/commands/diff.ts
|
|
6054
|
+
// src/commands/core/diff.ts
|
|
6055
|
+
var FORMATS2 = ["pretty", "json", "changelog"];
|
|
3380
6056
|
async function runDiff(options) {
|
|
3381
|
-
const configDir = process.cwd();
|
|
6057
|
+
const configDir = options.configDir ?? process.cwd();
|
|
3382
6058
|
const config = await loadConfig(void 0, configDir);
|
|
3383
6059
|
const baseRef = options.base ?? config.diff?.baseline_ref ?? DEFAULT_DIFF_CONFIG.baseline_ref;
|
|
3384
6060
|
const headRef = options.head ?? "HEAD";
|
|
3385
|
-
const configPath =
|
|
3386
|
-
const result = await diffBetweenRefs(configPath, baseRef, headRef
|
|
6061
|
+
const configPath = join6(configDir, "spec.config.yaml");
|
|
6062
|
+
const result = await diffBetweenRefs(configPath, baseRef, headRef, {
|
|
6063
|
+
working: options.working ?? false
|
|
6064
|
+
});
|
|
3387
6065
|
if (options.spec) {
|
|
3388
6066
|
result.diffs = result.diffs.filter((d) => d.specId === options.spec);
|
|
3389
6067
|
result.impact = result.impact.filter((i) => i.changedSpec === options.spec);
|
|
@@ -3395,28 +6073,58 @@ var diff_default = defineCommand4({
|
|
|
3395
6073
|
args: {
|
|
3396
6074
|
base: { type: "string", description: "Base git ref (default: from config or 'main')" },
|
|
3397
6075
|
head: { type: "string", description: "Head git ref (default: HEAD)" },
|
|
6076
|
+
working: {
|
|
6077
|
+
type: "boolean",
|
|
6078
|
+
description: "Compare the base ref against the working tree (includes uncommitted specs)",
|
|
6079
|
+
default: false
|
|
6080
|
+
},
|
|
3398
6081
|
spec: { type: "string", description: "Scope to a single spec ID" },
|
|
3399
|
-
|
|
3400
|
-
type: "string",
|
|
3401
|
-
description: "Output format: pretty, json",
|
|
3402
|
-
default: "pretty"
|
|
3403
|
-
}
|
|
6082
|
+
...sharedArgs(FORMATS2)
|
|
3404
6083
|
},
|
|
3405
6084
|
async run({ args }) {
|
|
6085
|
+
const format = resolveFormat(args.format, FORMATS2);
|
|
6086
|
+
if (!format.ok) {
|
|
6087
|
+
console.error(`
|
|
6088
|
+
\u2717 ${format.message}
|
|
6089
|
+
`);
|
|
6090
|
+
process.exit(1);
|
|
6091
|
+
}
|
|
6092
|
+
const output = createOutput({ quiet: args.quiet });
|
|
3406
6093
|
try {
|
|
3407
6094
|
try {
|
|
3408
6095
|
const result = await runDiff({
|
|
3409
6096
|
base: args.base,
|
|
3410
6097
|
head: args.head,
|
|
3411
6098
|
spec: args.spec,
|
|
3412
|
-
format: args.format
|
|
6099
|
+
format: args.format,
|
|
6100
|
+
working: args.working
|
|
3413
6101
|
});
|
|
3414
|
-
if (
|
|
6102
|
+
if (format.format === "json") {
|
|
3415
6103
|
console.log(JSON.stringify(result, null, 2));
|
|
3416
6104
|
return;
|
|
3417
6105
|
}
|
|
6106
|
+
if (format.format === "changelog") {
|
|
6107
|
+
const baseRef = args.base ?? (await loadConfig(void 0, process.cwd())).diff?.baseline_ref ?? "main";
|
|
6108
|
+
console.log(
|
|
6109
|
+
formatChangelog(result, baseRef, args.working ? "working tree" : args.head ?? "HEAD")
|
|
6110
|
+
);
|
|
6111
|
+
return;
|
|
6112
|
+
}
|
|
6113
|
+
const printUncommittedWarning = () => {
|
|
6114
|
+
if (result.uncommittedSpecFiles.length === 0) return;
|
|
6115
|
+
const count = result.uncommittedSpecFiles.length;
|
|
6116
|
+
console.log(
|
|
6117
|
+
`
|
|
6118
|
+
\u26A0 ${count} spec file(s) changed in the working tree are not covered by this comparison:`
|
|
6119
|
+
);
|
|
6120
|
+
for (const file of result.uncommittedSpecFiles) {
|
|
6121
|
+
console.log(` ${file}`);
|
|
6122
|
+
}
|
|
6123
|
+
console.log(" Run with --working to include them.");
|
|
6124
|
+
};
|
|
3418
6125
|
if (result.diffs.length === 0 && result.added.length === 0 && result.removed.length === 0) {
|
|
3419
|
-
|
|
6126
|
+
output.info(" \u2713 No spec changes detected.");
|
|
6127
|
+
printUncommittedWarning();
|
|
3420
6128
|
return;
|
|
3421
6129
|
}
|
|
3422
6130
|
console.log(result.summary);
|
|
@@ -3449,6 +6157,7 @@ var diff_default = defineCommand4({
|
|
|
3449
6157
|
}
|
|
3450
6158
|
}
|
|
3451
6159
|
}
|
|
6160
|
+
printUncommittedWarning();
|
|
3452
6161
|
} catch (err) {
|
|
3453
6162
|
if (err instanceof DiffError) {
|
|
3454
6163
|
console.error(`
|
|
@@ -3467,10 +6176,11 @@ var diff_default = defineCommand4({
|
|
|
3467
6176
|
}
|
|
3468
6177
|
});
|
|
3469
6178
|
|
|
3470
|
-
// src/commands/status.ts
|
|
6179
|
+
// src/commands/core/status.ts
|
|
3471
6180
|
import { defineCommand as defineCommand5 } from "citty";
|
|
3472
|
-
|
|
3473
|
-
|
|
6181
|
+
var FORMATS3 = ["pretty", "json", "github"];
|
|
6182
|
+
async function runStatus(options = {}) {
|
|
6183
|
+
const configDir = options.configDir ?? process.cwd();
|
|
3474
6184
|
const config = await loadConfig(void 0, configDir);
|
|
3475
6185
|
const specs = [];
|
|
3476
6186
|
for (const [, entry] of Object.entries(config.specs)) {
|
|
@@ -3486,7 +6196,11 @@ async function runStatus(_options = {}) {
|
|
|
3486
6196
|
byStatus[status] = (byStatus[status] ?? 0) + 1;
|
|
3487
6197
|
}
|
|
3488
6198
|
const presetName = config.lint?.extends ?? "recommended";
|
|
3489
|
-
const rules =
|
|
6199
|
+
const { rules, ignore } = await resolveLintConfig({
|
|
6200
|
+
config,
|
|
6201
|
+
preset: presetName,
|
|
6202
|
+
configDir
|
|
6203
|
+
});
|
|
3490
6204
|
let graph;
|
|
3491
6205
|
let graphError;
|
|
3492
6206
|
try {
|
|
@@ -3494,7 +6208,7 @@ async function runStatus(_options = {}) {
|
|
|
3494
6208
|
} catch (err) {
|
|
3495
6209
|
graphError = err.message;
|
|
3496
6210
|
}
|
|
3497
|
-
const engine = createLintEngine({ rules, config, graph });
|
|
6211
|
+
const engine = createLintEngine({ rules, config, graph, ignore });
|
|
3498
6212
|
const lintResults = engine.lint(specs.map((s) => s.spec));
|
|
3499
6213
|
if (graphError) {
|
|
3500
6214
|
lintResults.diagnostics.push({
|
|
@@ -3507,6 +6221,10 @@ async function runStatus(_options = {}) {
|
|
|
3507
6221
|
}
|
|
3508
6222
|
const errors = lintResults.diagnostics.filter((d) => d.severity === "error").length;
|
|
3509
6223
|
const warnings = lintResults.diagnostics.filter((d) => d.severity === "warn").length;
|
|
6224
|
+
const specsWithErrors = new Set(
|
|
6225
|
+
lintResults.diagnostics.filter((d) => d.severity === "error").map((d) => d.filePath)
|
|
6226
|
+
);
|
|
6227
|
+
const passing = specs.filter(({ spec }) => !specsWithErrors.has(spec.filePath)).length;
|
|
3510
6228
|
const thresholdDays = config.diff?.staleness_threshold_days ?? DEFAULT_DIFF_CONFIG.staleness_threshold_days;
|
|
3511
6229
|
const now = Date.now();
|
|
3512
6230
|
const staleSpecs = [];
|
|
@@ -3541,9 +6259,9 @@ async function runStatus(_options = {}) {
|
|
|
3541
6259
|
else if (specs.length === 0) verdict = "unassessed";
|
|
3542
6260
|
return {
|
|
3543
6261
|
project: config.project?.name ?? "unknown",
|
|
3544
|
-
|
|
6262
|
+
specFiles: specs.length,
|
|
3545
6263
|
byStatus,
|
|
3546
|
-
lintHealth: { errors, warnings, passing
|
|
6264
|
+
lintHealth: { errors, warnings, passing },
|
|
3547
6265
|
staleSpecs,
|
|
3548
6266
|
integrityIssues,
|
|
3549
6267
|
verdict
|
|
@@ -3551,21 +6269,32 @@ async function runStatus(_options = {}) {
|
|
|
3551
6269
|
}
|
|
3552
6270
|
var status_default = defineCommand5({
|
|
3553
6271
|
meta: { name: "status", description: "Show spec suite health overview" },
|
|
3554
|
-
args: {
|
|
3555
|
-
format: {
|
|
3556
|
-
type: "string",
|
|
3557
|
-
description: "Output format: pretty, json, github",
|
|
3558
|
-
default: "pretty"
|
|
3559
|
-
}
|
|
3560
|
-
},
|
|
6272
|
+
args: { ...sharedArgs(FORMATS3) },
|
|
3561
6273
|
async run({ args }) {
|
|
6274
|
+
const format = resolveFormat(args.format, FORMATS3);
|
|
6275
|
+
if (!format.ok) {
|
|
6276
|
+
console.error(`
|
|
6277
|
+
\u2717 ${format.message}
|
|
6278
|
+
`);
|
|
6279
|
+
process.exit(1);
|
|
6280
|
+
}
|
|
6281
|
+
const output = createOutput({ quiet: args.quiet });
|
|
3562
6282
|
try {
|
|
3563
|
-
const result = await runStatus(
|
|
3564
|
-
if (
|
|
6283
|
+
const result = await runStatus();
|
|
6284
|
+
if (format.format === "json") {
|
|
3565
6285
|
console.log(JSON.stringify(result, null, 2));
|
|
3566
6286
|
return;
|
|
3567
6287
|
}
|
|
3568
|
-
if (
|
|
6288
|
+
if (format.format === "github") {
|
|
6289
|
+
const level = result.verdict === "errors" ? "error" : result.verdict === "healthy" ? "notice" : "warning";
|
|
6290
|
+
console.log(
|
|
6291
|
+
`::${level}::specdx status \u2014 ${result.project} \u2014 ${result.verdict}: ${result.specFiles} spec file(s), ${result.lintHealth.errors} error(s), ${result.lintHealth.warnings} warning(s)`
|
|
6292
|
+
);
|
|
6293
|
+
if (result.verdict === "unassessed") {
|
|
6294
|
+
console.log(
|
|
6295
|
+
"::warning::No specs resolved \u2014 nothing was assessed. Check the spec paths in spec.config.yaml."
|
|
6296
|
+
);
|
|
6297
|
+
}
|
|
3569
6298
|
for (const s of result.staleSpecs) {
|
|
3570
6299
|
console.log(
|
|
3571
6300
|
`::warning::Spec "${s.specId}" is stale (${s.daysSinceUpdate} days since update)`
|
|
@@ -3577,28 +6306,31 @@ var status_default = defineCommand5({
|
|
|
3577
6306
|
return;
|
|
3578
6307
|
}
|
|
3579
6308
|
const icon = result.verdict === "healthy" ? "\u2713" : result.verdict === "warnings" || result.verdict === "unassessed" ? "\u26A0" : "\u2717";
|
|
3580
|
-
|
|
3581
|
-
|
|
6309
|
+
const healthy = result.verdict === "healthy";
|
|
6310
|
+
const headline = `
|
|
6311
|
+
${icon} ${result.project} \u2014 ${result.verdict}`;
|
|
6312
|
+
if (healthy) output.info(headline);
|
|
6313
|
+
else output.out(headline);
|
|
3582
6314
|
if (result.verdict === "unassessed") {
|
|
3583
|
-
|
|
6315
|
+
output.out(
|
|
3584
6316
|
" No specs resolved \u2014 nothing was assessed. Check the spec paths in spec.config.yaml."
|
|
3585
6317
|
);
|
|
3586
6318
|
}
|
|
3587
|
-
|
|
3588
|
-
` ${result.
|
|
6319
|
+
output.info(
|
|
6320
|
+
` ${result.specFiles} specs: ${Object.entries(result.byStatus).map(([k, v]) => `${v} ${k}`).join(", ")}`
|
|
3589
6321
|
);
|
|
3590
|
-
|
|
6322
|
+
output.info(
|
|
3591
6323
|
` Lint: ${result.lintHealth.errors} errors, ${result.lintHealth.warnings} warnings`
|
|
3592
6324
|
);
|
|
3593
6325
|
if (result.staleSpecs.length > 0) {
|
|
3594
|
-
|
|
6326
|
+
output.out(
|
|
3595
6327
|
` Stale: ${result.staleSpecs.map((s) => `${s.specId} (${s.daysSinceUpdate}d)`).join(", ")}`
|
|
3596
6328
|
);
|
|
3597
6329
|
}
|
|
3598
6330
|
if (result.integrityIssues.length > 0) {
|
|
3599
|
-
|
|
6331
|
+
output.out(` Issues: ${result.integrityIssues.join("; ")}`);
|
|
3600
6332
|
}
|
|
3601
|
-
|
|
6333
|
+
output.info();
|
|
3602
6334
|
} catch (err) {
|
|
3603
6335
|
console.error(`
|
|
3604
6336
|
\u2717 ${err.message}
|
|
@@ -3608,188 +6340,95 @@ var status_default = defineCommand5({
|
|
|
3608
6340
|
}
|
|
3609
6341
|
});
|
|
3610
6342
|
|
|
3611
|
-
// src/commands/
|
|
6343
|
+
// src/commands/core/validate.ts
|
|
3612
6344
|
import { defineCommand as defineCommand6 } from "citty";
|
|
3613
|
-
|
|
3614
|
-
async function
|
|
3615
|
-
const
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
lines.push(`- **${diff2.specId}**${versionStr} \u2014 ${sections || "frontmatter only"}`);
|
|
6345
|
+
var FORMATS4 = ["pretty", "json"];
|
|
6346
|
+
async function runValidate(configDir) {
|
|
6347
|
+
const warnings = [];
|
|
6348
|
+
try {
|
|
6349
|
+
const config = await loadConfig(void 0, configDir);
|
|
6350
|
+
buildGraph(config);
|
|
6351
|
+
let specFiles = 0;
|
|
6352
|
+
const missingRequired = [];
|
|
6353
|
+
for (const [key, entry] of Object.entries(config.specs)) {
|
|
6354
|
+
const files = await resolveGlob(entry.path, configDir);
|
|
6355
|
+
specFiles += files.length;
|
|
6356
|
+
if (files.length > 0) continue;
|
|
6357
|
+
if (entry.required) {
|
|
6358
|
+
missingRequired.push(`"${key}" (${entry.path})`);
|
|
6359
|
+
} else {
|
|
6360
|
+
warnings.push(`spec entry "${key}" resolves to no files: ${entry.path}`);
|
|
6361
|
+
}
|
|
3631
6362
|
}
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
6363
|
+
if (missingRequired.length > 0) {
|
|
6364
|
+
return {
|
|
6365
|
+
valid: false,
|
|
6366
|
+
specEntries: Object.keys(config.specs).length,
|
|
6367
|
+
specFiles,
|
|
6368
|
+
warnings,
|
|
6369
|
+
error: `required spec entry resolves to no files: ${missingRequired.join(", ")}`
|
|
6370
|
+
};
|
|
3638
6371
|
}
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
for (const id of result.removed) {
|
|
3644
|
-
lines.push(`- **${id}**`);
|
|
6372
|
+
if (specFiles === 0) {
|
|
6373
|
+
warnings.push(
|
|
6374
|
+
"no spec files found \u2014 every downstream check (lint, status, ready) would pass vacuously"
|
|
6375
|
+
);
|
|
3645
6376
|
}
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
6377
|
+
return {
|
|
6378
|
+
valid: true,
|
|
6379
|
+
specEntries: Object.keys(config.specs).length,
|
|
6380
|
+
specFiles,
|
|
6381
|
+
warnings
|
|
6382
|
+
};
|
|
6383
|
+
} catch (err) {
|
|
6384
|
+
if (err instanceof ConfigError) {
|
|
6385
|
+
return { valid: false, warnings, error: err.message, details: err.errors ?? void 0 };
|
|
3653
6386
|
}
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
6387
|
+
if (err instanceof GraphError) {
|
|
6388
|
+
return { valid: false, warnings, error: err.message };
|
|
6389
|
+
}
|
|
6390
|
+
throw err;
|
|
3658
6391
|
}
|
|
3659
|
-
return lines.join("\n");
|
|
3660
6392
|
}
|
|
3661
|
-
var
|
|
3662
|
-
meta: { name: "
|
|
3663
|
-
args: {
|
|
3664
|
-
from: { type: "string", description: "Start git ref (default: from config or 'main')" },
|
|
3665
|
-
to: { type: "string", description: "End git ref (default: HEAD)" }
|
|
3666
|
-
},
|
|
6393
|
+
var validate_default = defineCommand6({
|
|
6394
|
+
meta: { name: "validate", description: "Validate spec.config.yaml" },
|
|
6395
|
+
args: { ...sharedArgs(FORMATS4) },
|
|
3667
6396
|
async run({ args }) {
|
|
3668
|
-
|
|
3669
|
-
|
|
3670
|
-
const output = await runChangelog(args);
|
|
3671
|
-
console.log(output);
|
|
3672
|
-
} catch (err) {
|
|
3673
|
-
if (err instanceof DiffError) {
|
|
3674
|
-
console.error(`
|
|
3675
|
-
\u2717 ${err.message}
|
|
3676
|
-
`);
|
|
3677
|
-
process.exit(1);
|
|
3678
|
-
}
|
|
3679
|
-
throw err;
|
|
3680
|
-
}
|
|
3681
|
-
} catch (err) {
|
|
6397
|
+
const format = resolveFormat(args.format, FORMATS4);
|
|
6398
|
+
if (!format.ok) {
|
|
3682
6399
|
console.error(`
|
|
3683
|
-
\u2717 ${
|
|
6400
|
+
\u2717 ${format.message}
|
|
3684
6401
|
`);
|
|
3685
6402
|
process.exit(1);
|
|
3686
6403
|
}
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
const configDir = process.cwd();
|
|
3694
|
-
const config = await loadConfig(void 0, configDir);
|
|
3695
|
-
const specs = [];
|
|
3696
|
-
for (const [, entry] of Object.entries(config.specs)) {
|
|
3697
|
-
const paths = await resolveGlob(entry.path, configDir);
|
|
3698
|
-
for (const p of paths) {
|
|
3699
|
-
specs.push(await parseSpec(p));
|
|
3700
|
-
}
|
|
3701
|
-
}
|
|
3702
|
-
const byType = {};
|
|
3703
|
-
const byStatus = {};
|
|
3704
|
-
for (const spec of specs) {
|
|
3705
|
-
const type = spec.frontmatter.type || "unknown";
|
|
3706
|
-
const status = spec.frontmatter.status || "unknown";
|
|
3707
|
-
byType[type] = (byType[type] ?? 0) + 1;
|
|
3708
|
-
byStatus[status] = (byStatus[status] ?? 0) + 1;
|
|
3709
|
-
}
|
|
3710
|
-
const specSummaries = specs.map((spec) => {
|
|
3711
|
-
const firstSection = spec.parsedSections[0];
|
|
3712
|
-
const firstLine = firstSection?.content?.split("\n").find((l) => l.trim().length > 0)?.trim() ?? "";
|
|
3713
|
-
const truncated = firstLine.slice(0, 120) + (firstLine.length > 120 ? "..." : "");
|
|
3714
|
-
return {
|
|
3715
|
-
id: spec.frontmatter.id,
|
|
3716
|
-
type: spec.frontmatter.type,
|
|
3717
|
-
title: spec.frontmatter.title,
|
|
3718
|
-
status: spec.frontmatter.status,
|
|
3719
|
-
firstLine: truncated
|
|
3720
|
-
};
|
|
3721
|
-
});
|
|
3722
|
-
const graph = buildGraph(config);
|
|
3723
|
-
const graphLines = [];
|
|
3724
|
-
for (const node of graph.nodes) {
|
|
3725
|
-
const downstream = graph.edges.filter((e) => e.from === node).map((e) => e.to);
|
|
3726
|
-
if (downstream.length > 0) {
|
|
3727
|
-
graphLines.push(`${node} \u2192 ${downstream.join(", ")}`);
|
|
3728
|
-
} else {
|
|
3729
|
-
graphLines.push(node);
|
|
6404
|
+
const output = createOutput({ quiet: args.quiet });
|
|
6405
|
+
const result = await runValidate(process.cwd());
|
|
6406
|
+
if (format.format === "json") {
|
|
6407
|
+
console.log(JSON.stringify(result, null, 2));
|
|
6408
|
+
if (!result.valid) process.exit(1);
|
|
6409
|
+
return;
|
|
3730
6410
|
}
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
description: config.project?.description,
|
|
3735
|
-
specCount: specs.length,
|
|
3736
|
-
byType,
|
|
3737
|
-
byStatus,
|
|
3738
|
-
specs: specSummaries,
|
|
3739
|
-
graph: graphLines
|
|
3740
|
-
};
|
|
3741
|
-
}
|
|
3742
|
-
var explain_default = defineCommand7({
|
|
3743
|
-
meta: { name: "explain", description: "Explain the spec suite for onboarding" },
|
|
3744
|
-
args: {
|
|
3745
|
-
format: { type: "string", description: "Output format: pretty, json", default: "pretty" }
|
|
3746
|
-
},
|
|
3747
|
-
async run({ args }) {
|
|
3748
|
-
try {
|
|
3749
|
-
const result = await runExplain({ format: args.format });
|
|
3750
|
-
if (args.format === "json") {
|
|
3751
|
-
console.log(JSON.stringify(result, null, 2));
|
|
3752
|
-
return;
|
|
3753
|
-
}
|
|
3754
|
-
console.log(`
|
|
3755
|
-
${result.project}`);
|
|
3756
|
-
if (result.description) {
|
|
3757
|
-
console.log(` ${result.description}`);
|
|
3758
|
-
}
|
|
3759
|
-
console.log(
|
|
3760
|
-
`
|
|
3761
|
-
${result.specCount} specs: ${Object.entries(result.byType).map(([k, v]) => `${v} ${k}`).join(", ")}`
|
|
3762
|
-
);
|
|
3763
|
-
console.log(
|
|
3764
|
-
` Status: ${Object.entries(result.byStatus).map(([k, v]) => `${v} ${k}`).join(", ")}`
|
|
6411
|
+
if (result.valid) {
|
|
6412
|
+
output.info(
|
|
6413
|
+
` \u2713 Config valid. ${result.specEntries} spec entries, ${result.specFiles} spec files.`
|
|
3765
6414
|
);
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
}
|
|
3773
|
-
console.log("\n Dependencies:");
|
|
3774
|
-
for (const line of result.graph) {
|
|
3775
|
-
console.log(` ${line}`);
|
|
3776
|
-
}
|
|
3777
|
-
console.log();
|
|
3778
|
-
} catch (err) {
|
|
3779
|
-
console.error(`
|
|
3780
|
-
\u2717 ${err.message}
|
|
3781
|
-
`);
|
|
3782
|
-
process.exit(1);
|
|
6415
|
+
for (const w of result.warnings) output.out(` \u26A0 ${w}`);
|
|
6416
|
+
return;
|
|
6417
|
+
}
|
|
6418
|
+
console.error(` \u2717 Config invalid: ${result.error}`);
|
|
6419
|
+
for (const w of result.warnings) console.error(` \u26A0 ${w}`);
|
|
6420
|
+
if (result.details) {
|
|
6421
|
+
for (const e of result.details) console.error(` - ${JSON.stringify(e)}`);
|
|
3783
6422
|
}
|
|
6423
|
+
process.exit(1);
|
|
3784
6424
|
}
|
|
3785
6425
|
});
|
|
3786
6426
|
export {
|
|
3787
|
-
runChangelog,
|
|
3788
6427
|
runDiff,
|
|
3789
|
-
runExplain,
|
|
3790
6428
|
runLint,
|
|
3791
6429
|
runPack,
|
|
3792
6430
|
runStatus,
|
|
6431
|
+
runValidate,
|
|
3793
6432
|
scaffoldProject
|
|
3794
6433
|
};
|
|
3795
6434
|
//# sourceMappingURL=index.js.map
|