specweave 1.0.464 → 1.0.466
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/dist/plugins/specweave/lib/vendor/core/ac-test-validator-cli.d.ts +16 -0
- package/dist/plugins/specweave/lib/vendor/core/ac-test-validator-cli.js +139 -0
- package/dist/plugins/specweave/lib/vendor/core/ac-test-validator-cli.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/core/ac-test-validator.d.ts +111 -0
- package/dist/plugins/specweave/lib/vendor/core/ac-test-validator.js +304 -0
- package/dist/plugins/specweave/lib/vendor/core/ac-test-validator.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/ac-status-manager.d.ts +115 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/ac-status-manager.js +359 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/ac-status-manager.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/active-increment-manager.d.ts +121 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/active-increment-manager.js +273 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/active-increment-manager.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/auto-transition-manager.d.ts +72 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/auto-transition-manager.js +237 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/auto-transition-manager.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/duplicate-detector.d.ts +52 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/duplicate-detector.js +281 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/duplicate-detector.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/metadata-manager.d.ts +278 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/metadata-manager.js +925 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/metadata-manager.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/status-auto-transition.d.ts +113 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/status-auto-transition.js +317 -0
- package/dist/plugins/specweave/lib/vendor/core/increment/status-auto-transition.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/core/types/increment-metadata.d.ts +442 -0
- package/dist/plugins/specweave/lib/vendor/core/types/increment-metadata.js +246 -0
- package/dist/plugins/specweave/lib/vendor/core/types/increment-metadata.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/core/universal-auto-create.d.ts +64 -0
- package/dist/plugins/specweave/lib/vendor/core/universal-auto-create.js +228 -0
- package/dist/plugins/specweave/lib/vendor/core/universal-auto-create.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/generators/spec/task-parser.d.ts +95 -0
- package/dist/plugins/specweave/lib/vendor/generators/spec/task-parser.js +300 -0
- package/dist/plugins/specweave/lib/vendor/generators/spec/task-parser.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/sync/config.d.ts +73 -0
- package/dist/plugins/specweave/lib/vendor/sync/config.js +132 -0
- package/dist/plugins/specweave/lib/vendor/sync/config.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/sync/github-reconciler.d.ts +163 -0
- package/dist/plugins/specweave/lib/vendor/sync/github-reconciler.js +898 -0
- package/dist/plugins/specweave/lib/vendor/sync/github-reconciler.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/sync/provider-router.d.ts +86 -0
- package/dist/plugins/specweave/lib/vendor/sync/provider-router.js +147 -0
- package/dist/plugins/specweave/lib/vendor/sync/provider-router.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/sync/status-mapper.d.ts +120 -0
- package/dist/plugins/specweave/lib/vendor/sync/status-mapper.js +164 -0
- package/dist/plugins/specweave/lib/vendor/sync/status-mapper.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/utils/auth-helpers.d.ts +151 -0
- package/dist/plugins/specweave/lib/vendor/utils/auth-helpers.js +359 -0
- package/dist/plugins/specweave/lib/vendor/utils/auth-helpers.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/utils/chalk-fallback.d.ts +38 -0
- package/dist/plugins/specweave/lib/vendor/utils/chalk-fallback.js +118 -0
- package/dist/plugins/specweave/lib/vendor/utils/chalk-fallback.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/utils/clean-env.d.ts +47 -0
- package/dist/plugins/specweave/lib/vendor/utils/clean-env.js +63 -0
- package/dist/plugins/specweave/lib/vendor/utils/clean-env.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/utils/credential-masker.d.ts +118 -0
- package/dist/plugins/specweave/lib/vendor/utils/credential-masker.js +275 -0
- package/dist/plugins/specweave/lib/vendor/utils/credential-masker.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/utils/execFileNoThrow.d.ts +99 -0
- package/dist/plugins/specweave/lib/vendor/utils/execFileNoThrow.js +149 -0
- package/dist/plugins/specweave/lib/vendor/utils/execFileNoThrow.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/utils/feature-id-derivation.d.ts +63 -0
- package/dist/plugins/specweave/lib/vendor/utils/feature-id-derivation.js +85 -0
- package/dist/plugins/specweave/lib/vendor/utils/feature-id-derivation.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/utils/fs-native.d.ts +219 -0
- package/dist/plugins/specweave/lib/vendor/utils/fs-native.js +397 -0
- package/dist/plugins/specweave/lib/vendor/utils/fs-native.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/utils/logger.d.ts +56 -0
- package/dist/plugins/specweave/lib/vendor/utils/logger.js +123 -0
- package/dist/plugins/specweave/lib/vendor/utils/logger.js.map +1 -0
- package/dist/plugins/specweave/lib/vendor/utils/translation.d.ts +187 -0
- package/dist/plugins/specweave/lib/vendor/utils/translation.js +414 -0
- package/dist/plugins/specweave/lib/vendor/utils/translation.js.map +1 -0
- package/dist/plugins/specweave-ado/lib/ado-ac-checkbox-sync.js +1 -1
- package/dist/plugins/specweave-ado/lib/ado-ac-checkbox-sync.js.map +1 -1
- package/dist/plugins/specweave-ado/lib/ado-spec-sync.js +1 -1
- package/dist/plugins/specweave-ado/lib/ado-spec-sync.js.map +1 -1
- package/dist/plugins/specweave-github/lib/github-ac-checkbox-sync.js +2 -2
- package/dist/plugins/specweave-github/lib/github-ac-checkbox-sync.js.map +1 -1
- package/dist/plugins/specweave-github/lib/github-feature-sync.d.ts.map +1 -1
- package/dist/plugins/specweave-github/lib/github-feature-sync.js +13 -4
- package/dist/plugins/specweave-github/lib/github-feature-sync.js.map +1 -1
- package/dist/plugins/specweave-jira/lib/jira-ac-checkbox-sync.js +1 -1
- package/dist/plugins/specweave-jira/lib/jira-ac-checkbox-sync.js.map +1 -1
- package/dist/plugins/specweave-jira/lib/jira-spec-sync.js +1 -1
- package/dist/plugins/specweave-jira/lib/jira-spec-sync.js.map +1 -1
- package/dist/src/sync/spec-to-living-docs-sync.js +1 -1
- package/dist/src/sync/spec-to-living-docs-sync.js.map +1 -1
- package/package.json +1 -1
- package/plugins/specweave/lib/vendor/utils/auth-helpers.d.ts +151 -0
- package/plugins/specweave/lib/vendor/utils/auth-helpers.js +359 -0
- package/plugins/specweave/lib/vendor/utils/auth-helpers.js.map +1 -0
- package/plugins/specweave/skills/team-lead/SKILL.md +150 -56
- package/plugins/specweave/skills/team-lead/agents/backend.md +13 -9
- package/plugins/specweave/skills/team-lead/agents/database.md +13 -9
- package/plugins/specweave/skills/team-lead/agents/frontend.md +12 -8
- package/plugins/specweave/skills/team-lead/agents/security.md +13 -9
- package/plugins/specweave/skills/team-lead/agents/testing.md +12 -8
- package/plugins/specweave-ado/lib/ado-ac-checkbox-sync.js +1 -1
- package/plugins/specweave-ado/lib/ado-ac-checkbox-sync.ts +1 -1
- package/plugins/specweave-ado/lib/ado-spec-sync.js +1 -1
- package/plugins/specweave-ado/lib/ado-spec-sync.ts +1 -1
- package/plugins/specweave-github/lib/github-ac-checkbox-sync.js +1 -1
- package/plugins/specweave-github/lib/github-ac-checkbox-sync.ts +2 -2
- package/plugins/specweave-github/lib/github-feature-sync.js +11 -3
- package/plugins/specweave-github/lib/github-feature-sync.ts +13 -4
- package/plugins/specweave-jira/lib/jira-ac-checkbox-sync.js +1 -1
- package/plugins/specweave-jira/lib/jira-ac-checkbox-sync.ts +1 -1
- package/plugins/specweave-jira/lib/jira-spec-sync.js +1 -1
- package/plugins/specweave-jira/lib/jira-spec-sync.ts +1 -1
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native Node.js fs API Helpers
|
|
3
|
+
*
|
|
4
|
+
* Drop-in replacements for fs-extra methods using only Node.js stdlib.
|
|
5
|
+
* All methods use native Node.js 20+ APIs with no external dependencies.
|
|
6
|
+
*
|
|
7
|
+
* Migration from fs-extra: // legacy fs-extra (documentation only)
|
|
8
|
+
* - import fs from 'fs-extra' → import * as fs from './utils/fs-native.js' // legacy fs-extra
|
|
9
|
+
* - All fs-extra methods work as drop-in replacements
|
|
10
|
+
*
|
|
11
|
+
* Benefits:
|
|
12
|
+
* - Zero bundle overhead (no npm packages)
|
|
13
|
+
* - Works in marketplace (no node_modules needed)
|
|
14
|
+
* - Faster startup (native APIs)
|
|
15
|
+
* - Better debugging (native stack traces)
|
|
16
|
+
*/
|
|
17
|
+
import { promises as fsPromises, existsSync, mkdirSync, readFileSync, writeFileSync, statSync, readdirSync, rmSync, unlinkSync, copyFileSync, renameSync as fsRenameSync, mkdtempSync as fsMkdtempSync, chmodSync } from 'fs';
|
|
18
|
+
import path from 'path';
|
|
19
|
+
/**
|
|
20
|
+
* Ensures that a directory exists. If the directory does not exist, it is created.
|
|
21
|
+
* @param dirPath - The directory path to ensure
|
|
22
|
+
*/
|
|
23
|
+
export async function ensureDir(dirPath) {
|
|
24
|
+
if (!existsSync(dirPath)) {
|
|
25
|
+
await fsPromises.mkdir(dirPath, { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Synchronous version of ensureDir
|
|
30
|
+
*/
|
|
31
|
+
export function ensureDirSync(dirPath) {
|
|
32
|
+
if (!existsSync(dirPath)) {
|
|
33
|
+
mkdirSync(dirPath, { recursive: true });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Alias for ensureDirSync (fs-extra compatibility)
|
|
38
|
+
*/
|
|
39
|
+
export function mkdirpSync(dirPath) {
|
|
40
|
+
ensureDirSync(dirPath);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Check if a path exists
|
|
44
|
+
* @param filePath - The path to check
|
|
45
|
+
*/
|
|
46
|
+
export async function pathExists(filePath) {
|
|
47
|
+
return existsSync(filePath);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Synchronous version of pathExists
|
|
51
|
+
*/
|
|
52
|
+
export { existsSync };
|
|
53
|
+
/**
|
|
54
|
+
* Read a JSON file and parse it
|
|
55
|
+
* @param filePath - The JSON file path
|
|
56
|
+
*/
|
|
57
|
+
export async function readJson(filePath) {
|
|
58
|
+
const content = await fsPromises.readFile(filePath, 'utf-8');
|
|
59
|
+
return JSON.parse(content);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Synchronous version of readJson
|
|
63
|
+
*/
|
|
64
|
+
export function readJsonSync(filePath) {
|
|
65
|
+
const content = readFileSync(filePath, 'utf-8');
|
|
66
|
+
return JSON.parse(content);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Write a JSON file with formatting
|
|
70
|
+
* @param filePath - The JSON file path
|
|
71
|
+
* @param data - The data to write
|
|
72
|
+
* @param options - Options (spaces for indentation)
|
|
73
|
+
*/
|
|
74
|
+
export async function writeJson(filePath, data, options) {
|
|
75
|
+
const spaces = options?.spaces ?? 2;
|
|
76
|
+
const content = JSON.stringify(data, null, spaces);
|
|
77
|
+
await fsPromises.writeFile(filePath, content, 'utf-8');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Synchronous version of writeJson
|
|
81
|
+
*/
|
|
82
|
+
export function writeJsonSync(filePath, data, options) {
|
|
83
|
+
const spaces = options?.spaces ?? 2;
|
|
84
|
+
const content = JSON.stringify(data, null, spaces);
|
|
85
|
+
writeFileSync(filePath, content, 'utf-8');
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* fs-extra compatibility: readJSON (uppercase J)
|
|
89
|
+
* Alias for readJson
|
|
90
|
+
*/
|
|
91
|
+
export const readJSON = readJson;
|
|
92
|
+
/**
|
|
93
|
+
* fs-extra compatibility: readJSONSync (uppercase J)
|
|
94
|
+
* Alias for readJsonSync
|
|
95
|
+
*/
|
|
96
|
+
export const readJSONSync = readJsonSync;
|
|
97
|
+
/**
|
|
98
|
+
* fs-extra compatibility: writeJSON (uppercase J)
|
|
99
|
+
* Alias for writeJson
|
|
100
|
+
*/
|
|
101
|
+
export const writeJSON = writeJson;
|
|
102
|
+
/**
|
|
103
|
+
* fs-extra compatibility: writeJSONSync (uppercase J)
|
|
104
|
+
* Alias for writeJsonSync
|
|
105
|
+
*/
|
|
106
|
+
export const writeJSONSync = writeJsonSync;
|
|
107
|
+
/**
|
|
108
|
+
* Remove a file or directory (recursively)
|
|
109
|
+
* @param targetPath - The path to remove
|
|
110
|
+
*/
|
|
111
|
+
export async function remove(targetPath) {
|
|
112
|
+
if (existsSync(targetPath)) {
|
|
113
|
+
await fsPromises.rm(targetPath, { recursive: true, force: true });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Synchronous version of remove
|
|
118
|
+
*/
|
|
119
|
+
export function removeSync(targetPath) {
|
|
120
|
+
if (existsSync(targetPath)) {
|
|
121
|
+
rmSync(targetPath, { recursive: true, force: true });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Copy a file or directory
|
|
126
|
+
* @param src - Source path
|
|
127
|
+
* @param dest - Destination path
|
|
128
|
+
* @param options - Copy options
|
|
129
|
+
*/
|
|
130
|
+
export async function copy(src, dest, options) {
|
|
131
|
+
const srcStat = await fsPromises.stat(src);
|
|
132
|
+
if (srcStat.isFile()) {
|
|
133
|
+
// Copy single file
|
|
134
|
+
await fsPromises.mkdir(path.dirname(dest), { recursive: true });
|
|
135
|
+
await fsPromises.copyFile(src, dest);
|
|
136
|
+
}
|
|
137
|
+
else if (srcStat.isDirectory()) {
|
|
138
|
+
// Copy directory recursively
|
|
139
|
+
await fsPromises.mkdir(dest, { recursive: true });
|
|
140
|
+
const entries = await fsPromises.readdir(src, { withFileTypes: true });
|
|
141
|
+
for (const entry of entries) {
|
|
142
|
+
const srcPath = path.join(src, entry.name);
|
|
143
|
+
const destPath = path.join(dest, entry.name);
|
|
144
|
+
// Apply filter if provided
|
|
145
|
+
if (options?.filter && !options.filter(srcPath)) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (entry.isDirectory()) {
|
|
149
|
+
await copy(srcPath, destPath, options);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
await fsPromises.copyFile(srcPath, destPath);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Synchronous version of copy
|
|
159
|
+
*/
|
|
160
|
+
export function copySync(src, dest, options) {
|
|
161
|
+
const srcStat = statSync(src);
|
|
162
|
+
if (srcStat.isFile()) {
|
|
163
|
+
// Copy single file
|
|
164
|
+
mkdirSync(path.dirname(dest), { recursive: true });
|
|
165
|
+
copyFileSync(src, dest);
|
|
166
|
+
}
|
|
167
|
+
else if (srcStat.isDirectory()) {
|
|
168
|
+
// Copy directory recursively
|
|
169
|
+
mkdirSync(dest, { recursive: true });
|
|
170
|
+
const entries = readdirSync(src, { withFileTypes: true });
|
|
171
|
+
for (const entry of entries) {
|
|
172
|
+
const srcPath = path.join(src, entry.name);
|
|
173
|
+
const destPath = path.join(dest, entry.name);
|
|
174
|
+
// Apply filter if provided
|
|
175
|
+
if (options?.filter && !options.filter(srcPath)) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
if (entry.isDirectory()) {
|
|
179
|
+
copySync(srcPath, destPath, options);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
copyFileSync(srcPath, destPath);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Ensure a file exists (create if it doesn't)
|
|
189
|
+
* @param filePath - The file path
|
|
190
|
+
*/
|
|
191
|
+
export async function ensureFile(filePath) {
|
|
192
|
+
if (!existsSync(filePath)) {
|
|
193
|
+
await fsPromises.mkdir(path.dirname(filePath), { recursive: true });
|
|
194
|
+
await fsPromises.writeFile(filePath, '', 'utf-8');
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Synchronous version of ensureFile
|
|
199
|
+
*/
|
|
200
|
+
export function ensureFileSync(filePath) {
|
|
201
|
+
if (!existsSync(filePath)) {
|
|
202
|
+
mkdirSync(path.dirname(filePath), { recursive: true });
|
|
203
|
+
writeFileSync(filePath, '', 'utf-8');
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Move a file or directory
|
|
208
|
+
* @param src - Source path
|
|
209
|
+
* @param dest - Destination path
|
|
210
|
+
* @param options - Move options
|
|
211
|
+
*/
|
|
212
|
+
export async function move(src, dest, options) {
|
|
213
|
+
// Ensure destination directory exists
|
|
214
|
+
await fsPromises.mkdir(path.dirname(dest), { recursive: true });
|
|
215
|
+
// Check if destination exists
|
|
216
|
+
if (existsSync(dest)) {
|
|
217
|
+
if (options?.overwrite) {
|
|
218
|
+
await remove(dest);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
throw new Error(`Destination already exists: ${dest}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// Try rename first (faster if same filesystem)
|
|
225
|
+
try {
|
|
226
|
+
await fsPromises.rename(src, dest);
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
// If rename fails (different filesystems), copy then delete
|
|
230
|
+
if (err.code === 'EXDEV') {
|
|
231
|
+
await copy(src, dest);
|
|
232
|
+
await remove(src);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
throw err;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Synchronous version of move
|
|
241
|
+
*/
|
|
242
|
+
export function moveSync(src, dest, options) {
|
|
243
|
+
// Ensure destination directory exists
|
|
244
|
+
mkdirSync(path.dirname(dest), { recursive: true });
|
|
245
|
+
// Check if destination exists
|
|
246
|
+
if (existsSync(dest)) {
|
|
247
|
+
if (options?.overwrite) {
|
|
248
|
+
removeSync(dest);
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
throw new Error(`Destination already exists: ${dest}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
// Try rename first (faster if same filesystem)
|
|
255
|
+
try {
|
|
256
|
+
fsRenameSync(src, dest);
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
// If rename fails (different filesystems), copy then delete
|
|
260
|
+
if (err.code === 'EXDEV') {
|
|
261
|
+
copySync(src, dest);
|
|
262
|
+
removeSync(src);
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
throw err;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// ============================================================================
|
|
270
|
+
// SpecWeave Initialization Guard
|
|
271
|
+
// ============================================================================
|
|
272
|
+
/**
|
|
273
|
+
* Check if SpecWeave is properly initialized in a directory.
|
|
274
|
+
*
|
|
275
|
+
* CRITICAL RULE: .specweave/ folders must ONLY be created in project roots
|
|
276
|
+
* where `specweave init` was explicitly run. This function validates that
|
|
277
|
+
* config.json exists, proving explicit initialization.
|
|
278
|
+
*
|
|
279
|
+
* @param projectRoot - The directory to check (defaults to cwd)
|
|
280
|
+
* @returns true if SpecWeave is initialized (has config.json), false otherwise
|
|
281
|
+
*/
|
|
282
|
+
export function isSpecWeaveInitialized(projectRoot) {
|
|
283
|
+
const root = projectRoot || process.cwd();
|
|
284
|
+
const configPath = path.join(root, '.specweave', 'config.json');
|
|
285
|
+
return existsSync(configPath);
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Find the nearest SpecWeave project root by walking up the directory tree.
|
|
289
|
+
*
|
|
290
|
+
* @param startDir - Starting directory (defaults to cwd)
|
|
291
|
+
* @returns The project root path, or null if not found
|
|
292
|
+
*/
|
|
293
|
+
export function findSpecWeaveRoot(startDir) {
|
|
294
|
+
let dir = startDir || process.cwd();
|
|
295
|
+
while (dir !== path.dirname(dir)) { // Stop at filesystem root
|
|
296
|
+
if (isSpecWeaveInitialized(dir)) {
|
|
297
|
+
return dir;
|
|
298
|
+
}
|
|
299
|
+
dir = path.dirname(dir);
|
|
300
|
+
}
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Ensure a directory exists within a SpecWeave project.
|
|
305
|
+
* ONLY creates the directory if SpecWeave is initialized.
|
|
306
|
+
*
|
|
307
|
+
* @param dirPath - The directory path to ensure
|
|
308
|
+
* @param projectRoot - Optional project root (auto-detected from dirPath if not provided)
|
|
309
|
+
* @returns true if directory was created/exists, false if SpecWeave not initialized
|
|
310
|
+
*/
|
|
311
|
+
export function ensureSpecWeaveDir(dirPath, projectRoot) {
|
|
312
|
+
// Auto-detect project root from dirPath if not provided
|
|
313
|
+
const root = projectRoot || findSpecWeaveRoot(path.dirname(dirPath));
|
|
314
|
+
if (!root || !isSpecWeaveInitialized(root)) {
|
|
315
|
+
// SpecWeave not initialized - do NOT create any directories
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
ensureDirSync(dirPath);
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Async version of ensureSpecWeaveDir
|
|
323
|
+
*/
|
|
324
|
+
export async function ensureSpecWeaveDirAsync(dirPath, projectRoot) {
|
|
325
|
+
const root = projectRoot || findSpecWeaveRoot(path.dirname(dirPath));
|
|
326
|
+
if (!root || !isSpecWeaveInitialized(root)) {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
await ensureDir(dirPath);
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
// Re-export common fs/promises methods for convenience
|
|
333
|
+
export const { readFile, writeFile, appendFile, stat, lstat, // Added for symlink detection
|
|
334
|
+
readdir, access, unlink, rmdir, rename, chmod, copyFile, mkdtemp, mkdir, // Added for test compatibility
|
|
335
|
+
symlink, // Added for creating symlinks
|
|
336
|
+
readlink, // Added for reading symlink targets
|
|
337
|
+
} = fsPromises;
|
|
338
|
+
// Create renameSync alias for fs-extra compatibility
|
|
339
|
+
export const renameSync = fsRenameSync;
|
|
340
|
+
// Create mkdtempSync alias
|
|
341
|
+
export const mkdtempSync = fsMkdtempSync;
|
|
342
|
+
// Re-export common synchronous methods
|
|
343
|
+
export { readFileSync, writeFileSync, statSync, readdirSync, unlinkSync, mkdirSync, rmSync, copyFileSync, chmodSync, };
|
|
344
|
+
// Default export for convenience
|
|
345
|
+
export default {
|
|
346
|
+
// Async methods
|
|
347
|
+
ensureDir,
|
|
348
|
+
pathExists,
|
|
349
|
+
readJson,
|
|
350
|
+
writeJson,
|
|
351
|
+
readJSON, // fs-extra compat
|
|
352
|
+
writeJSON, // fs-extra compat
|
|
353
|
+
remove,
|
|
354
|
+
copy,
|
|
355
|
+
move,
|
|
356
|
+
ensureFile,
|
|
357
|
+
readFile,
|
|
358
|
+
writeFile,
|
|
359
|
+
appendFile,
|
|
360
|
+
stat,
|
|
361
|
+
readdir,
|
|
362
|
+
access,
|
|
363
|
+
unlink,
|
|
364
|
+
rename,
|
|
365
|
+
copyFile,
|
|
366
|
+
mkdtemp,
|
|
367
|
+
mkdir,
|
|
368
|
+
// Sync methods
|
|
369
|
+
ensureDirSync,
|
|
370
|
+
mkdirpSync,
|
|
371
|
+
existsSync,
|
|
372
|
+
readJsonSync,
|
|
373
|
+
writeJsonSync,
|
|
374
|
+
readJSONSync, // fs-extra compat
|
|
375
|
+
writeJSONSync, // fs-extra compat
|
|
376
|
+
removeSync,
|
|
377
|
+
copySync,
|
|
378
|
+
moveSync,
|
|
379
|
+
ensureFileSync,
|
|
380
|
+
readFileSync,
|
|
381
|
+
writeFileSync,
|
|
382
|
+
statSync,
|
|
383
|
+
readdirSync,
|
|
384
|
+
unlinkSync,
|
|
385
|
+
mkdirSync,
|
|
386
|
+
rmSync,
|
|
387
|
+
copyFileSync,
|
|
388
|
+
renameSync,
|
|
389
|
+
mkdtempSync,
|
|
390
|
+
chmodSync,
|
|
391
|
+
// SpecWeave guards
|
|
392
|
+
isSpecWeaveInitialized,
|
|
393
|
+
findSpecWeaveRoot,
|
|
394
|
+
ensureSpecWeaveDir,
|
|
395
|
+
ensureSpecWeaveDirAsync,
|
|
396
|
+
};
|
|
397
|
+
//# sourceMappingURL=fs-native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs-native.js","sourceRoot":"","sources":["../../../src/utils/fs-native.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,QAAQ,IAAI,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,IAAI,YAAY,EAAE,WAAW,IAAI,aAAa,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AAE9N,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,OAAe;IAC7C,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QACzB,MAAM,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACvD,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MA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,EACR,OAAO,EACP,KAAK,EAAI,+BAA+B;AACxC,OAAO,EAAG,8BAA8B;AACxC,QAAQ,EAAE,oCAAoC;EAC/C,GAAG,UAAU,CAAC;AAEf,qDAAqD;AACrD,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AAEvC,2BAA2B;AAC3B,MAAM,CAAC,MAAM,WAAW,GAAG,aAAa,CAAC;AAEzC,uCAAuC;AACvC,OAAO,EACL,YAAY,EACZ,aAAa,EACb,QAAQ,EACR,WAAW,EACX,UAAU,EACV,SAAS,EACT,MAAM,EACN,YAAY,EACZ,SAAS,GACV,CAAC;AAEF,iCAAiC;AACjC,eAAe;IACb,gBAAgB;IAChB,SAAS;IACT,UAAU;IACV,QAAQ;IACR,SAAS;IACT,QAAQ,EAAG,kBAAkB;IAC7B,SAAS,EAAG,kBAAkB;IAC9B,MAAM;IACN,IAAI;IACJ,IAAI;IACJ,UAAU;IACV,QAAQ;IACR,SAAS;IACT,UAAU;IACV,IAAI;IACJ,OAAO;IACP,MAAM;IACN,MAAM;IACN,MAAM;IACN,QAAQ;IACR,OAAO;IACP,KAAK;IAEL,eAAe;IACf,aAAa;IACb,UAAU;IACV,UAAU;IACV,YAAY;IACZ,aAAa;IACb,YAAY,EAAG,kBAAkB;IACjC,aAAa,EAAG,kBAAkB;IAClC,UAAU;IACV,QAAQ;IACR,QAAQ;IACR,cAAc;IACd,YAAY;IACZ,aAAa;IACb,QAAQ;IACR,WAAW;IACX,UAAU;IACV,SAAS;IACT,MAAM;IACN,YAAY;IACZ,UAAU;IACV,WAAW;IACX,SAAS;IAET,mBAAmB;IACnB,sBAAsB;IACtB,iBAAiB;IACjB,kBAAkB;IAClB,uBAAuB;CACxB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger Interface
|
|
3
|
+
*
|
|
4
|
+
* Abstraction for logging to enable silent testing and flexible log output.
|
|
5
|
+
* Prevents test output pollution from expected error conditions.
|
|
6
|
+
*
|
|
7
|
+
* SECURITY: All loggers automatically mask credentials using credential-masker utility.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Logger interface for dependency injection
|
|
11
|
+
*/
|
|
12
|
+
export interface Logger {
|
|
13
|
+
/**
|
|
14
|
+
* Log informational message
|
|
15
|
+
*/
|
|
16
|
+
log(message: string, ...args: any[]): void;
|
|
17
|
+
/**
|
|
18
|
+
* Log info message (alias for log)
|
|
19
|
+
*/
|
|
20
|
+
info(message: string, ...args: any[]): void;
|
|
21
|
+
/**
|
|
22
|
+
* Log error message with optional error object
|
|
23
|
+
*/
|
|
24
|
+
error(message: string, error?: any): void;
|
|
25
|
+
/**
|
|
26
|
+
* Log warning message
|
|
27
|
+
*/
|
|
28
|
+
warn(message: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Log debug message
|
|
31
|
+
*/
|
|
32
|
+
debug(message: string): void;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Console logger (default production logger)
|
|
36
|
+
*
|
|
37
|
+
* Logs to console.log/error/warn
|
|
38
|
+
* SECURITY: Automatically masks all credentials before logging
|
|
39
|
+
*/
|
|
40
|
+
export declare const consoleLogger: Logger;
|
|
41
|
+
/**
|
|
42
|
+
* Silent logger (for testing)
|
|
43
|
+
*
|
|
44
|
+
* Suppresses all log output - use in tests to prevent pollution
|
|
45
|
+
* from expected error conditions.
|
|
46
|
+
*/
|
|
47
|
+
export declare const silentLogger: Logger;
|
|
48
|
+
/**
|
|
49
|
+
* Create a custom logger that filters based on log level
|
|
50
|
+
*
|
|
51
|
+
* @param minLevel - Minimum level to log (debug=0, log=1, warn=2, error=3)
|
|
52
|
+
* @returns Logger instance
|
|
53
|
+
* SECURITY: Automatically masks all credentials before logging
|
|
54
|
+
*/
|
|
55
|
+
export declare function createFilteredLogger(minLevel?: 'debug' | 'log' | 'warn' | 'error'): Logger;
|
|
56
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger Interface
|
|
3
|
+
*
|
|
4
|
+
* Abstraction for logging to enable silent testing and flexible log output.
|
|
5
|
+
* Prevents test output pollution from expected error conditions.
|
|
6
|
+
*
|
|
7
|
+
* SECURITY: All loggers automatically mask credentials using credential-masker utility.
|
|
8
|
+
*/
|
|
9
|
+
import { maskCredentials, maskCredentialsInData } from './credential-masker.js';
|
|
10
|
+
/**
|
|
11
|
+
* Mask message and variadic string args
|
|
12
|
+
*/
|
|
13
|
+
function maskMessageAndArgs(message, args) {
|
|
14
|
+
return {
|
|
15
|
+
msg: maskCredentials(message),
|
|
16
|
+
maskedArgs: args.map(arg => typeof arg === 'string' ? maskCredentials(arg) : arg)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Mask an error object or string
|
|
21
|
+
*/
|
|
22
|
+
function maskError(error) {
|
|
23
|
+
if (error && typeof error === 'object') {
|
|
24
|
+
return maskCredentialsInData(error);
|
|
25
|
+
}
|
|
26
|
+
if (typeof error === 'string') {
|
|
27
|
+
return maskCredentials(error);
|
|
28
|
+
}
|
|
29
|
+
return error;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Console logger (default production logger)
|
|
33
|
+
*
|
|
34
|
+
* Logs to console.log/error/warn
|
|
35
|
+
* SECURITY: Automatically masks all credentials before logging
|
|
36
|
+
*/
|
|
37
|
+
export const consoleLogger = {
|
|
38
|
+
log: (message, ...args) => {
|
|
39
|
+
const { msg, maskedArgs } = maskMessageAndArgs(message, args);
|
|
40
|
+
console.log(msg, ...maskedArgs);
|
|
41
|
+
},
|
|
42
|
+
info: (message, ...args) => {
|
|
43
|
+
const { msg, maskedArgs } = maskMessageAndArgs(message, args);
|
|
44
|
+
console.log(msg, ...maskedArgs);
|
|
45
|
+
},
|
|
46
|
+
error: (message, error) => {
|
|
47
|
+
const msg = maskCredentials(message);
|
|
48
|
+
const maskedError = maskError(error);
|
|
49
|
+
if (maskedError) {
|
|
50
|
+
console.error(msg, maskedError);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
console.error(msg);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
warn: (message) => {
|
|
57
|
+
console.warn(maskCredentials(message));
|
|
58
|
+
},
|
|
59
|
+
debug: (message) => {
|
|
60
|
+
console.log(maskCredentials(message));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Silent logger (for testing)
|
|
65
|
+
*
|
|
66
|
+
* Suppresses all log output - use in tests to prevent pollution
|
|
67
|
+
* from expected error conditions.
|
|
68
|
+
*/
|
|
69
|
+
export const silentLogger = {
|
|
70
|
+
log: () => { },
|
|
71
|
+
info: () => { },
|
|
72
|
+
error: () => { },
|
|
73
|
+
warn: () => { },
|
|
74
|
+
debug: () => { }
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Create a custom logger that filters based on log level
|
|
78
|
+
*
|
|
79
|
+
* @param minLevel - Minimum level to log (debug=0, log=1, warn=2, error=3)
|
|
80
|
+
* @returns Logger instance
|
|
81
|
+
* SECURITY: Automatically masks all credentials before logging
|
|
82
|
+
*/
|
|
83
|
+
export function createFilteredLogger(minLevel = 'log') {
|
|
84
|
+
const levels = { debug: 0, log: 1, info: 1, warn: 2, error: 3 };
|
|
85
|
+
const threshold = levels[minLevel];
|
|
86
|
+
return {
|
|
87
|
+
log: (msg, ...args) => {
|
|
88
|
+
if (levels.log < threshold)
|
|
89
|
+
return;
|
|
90
|
+
const { msg: masked, maskedArgs } = maskMessageAndArgs(msg, args);
|
|
91
|
+
console.log(masked, ...maskedArgs);
|
|
92
|
+
},
|
|
93
|
+
info: (msg, ...args) => {
|
|
94
|
+
if (levels.info < threshold)
|
|
95
|
+
return;
|
|
96
|
+
const { msg: masked, maskedArgs } = maskMessageAndArgs(msg, args);
|
|
97
|
+
console.log(masked, ...maskedArgs);
|
|
98
|
+
},
|
|
99
|
+
error: (msg, err) => {
|
|
100
|
+
if (levels.error < threshold)
|
|
101
|
+
return;
|
|
102
|
+
const maskedMsg = maskCredentials(msg);
|
|
103
|
+
const maskedErr = maskError(err);
|
|
104
|
+
if (maskedErr) {
|
|
105
|
+
console.error(maskedMsg, maskedErr);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
console.error(maskedMsg);
|
|
109
|
+
}
|
|
110
|
+
},
|
|
111
|
+
warn: (msg) => {
|
|
112
|
+
if (levels.warn < threshold)
|
|
113
|
+
return;
|
|
114
|
+
console.warn(maskCredentials(msg));
|
|
115
|
+
},
|
|
116
|
+
debug: (msg) => {
|
|
117
|
+
if (levels.debug < threshold)
|
|
118
|
+
return;
|
|
119
|
+
console.log(maskCredentials(msg));
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAEhF;;GAEG;AACH,SAAS,kBAAkB,CAAC,OAAe,EAAE,IAAW;IACtD,OAAO;QACL,GAAG,EAAE,eAAe,CAAC,OAAO,CAAC;QAC7B,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;KAClF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAS,SAAS,CAAC,KAAU;IAC3B,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACvC,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B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