qualiow-exploratory-testing 1.2.0 → 2.0.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.
Files changed (111) hide show
  1. package/.claude-plugin/plugin.json +22 -0
  2. package/.env.example +27 -0
  3. package/CHANGELOG.md +194 -0
  4. package/README.md +428 -179
  5. package/agents/qa-gather-agent.md +24 -0
  6. package/{scripts → bin}/doctor-mobile.sh +57 -18
  7. package/bin/mcli +15 -9
  8. package/bin/mobile-cli.mjs +574 -286
  9. package/{scripts → bin}/setup-mobile.sh +56 -19
  10. package/bin/wadb +10 -4
  11. package/bin/wk-ios +29 -17
  12. package/bin/wkeval.mjs +7 -1
  13. package/data/domains/_default.yml +1 -1
  14. package/data/domains/identity.yml +138 -0
  15. package/data/knowledge/changelog.yml +104 -0
  16. package/data/knowledge/learned-patterns.md +172 -86
  17. package/data/knowledge/manifest.yml +481 -70
  18. package/data/knowledge/releases/v0.1.0/entries/technique-business-logic-race-conditions.yml +1 -1
  19. package/data/knowledge/releases/v0.1.0/release.yml +8 -1
  20. package/data/knowledge/releases/v0.2.0/entries/technique-contract-narrowing.yml +150 -0
  21. package/data/knowledge/releases/v0.2.0/entries/technique-test-suite-audit.yml +116 -0
  22. package/data/knowledge/releases/v0.2.0/release.yml +20 -0
  23. package/data/knowledge/releases/v0.3.0/entries/technique-functional-diff-analysis.yml +119 -0
  24. package/data/knowledge/releases/v0.3.0/entries/technique-llm-output-verification.yml +102 -0
  25. package/data/knowledge/releases/v0.3.0/entries/technique-verification-mode-selection.yml +153 -0
  26. package/data/knowledge/releases/v0.3.0/release.yml +25 -0
  27. package/data/knowledge/releases/v0.4.0/entries/technique-authenticated-api-probing.yml +137 -0
  28. package/data/knowledge/releases/v0.4.0/entries/technique-environment-fingerprinting.yml +113 -0
  29. package/data/knowledge/releases/v0.4.0/entries/technique-silent-failure-audit.yml +86 -0
  30. package/data/knowledge/releases/v0.4.0/entries/technique-ui-api-differential.yml +97 -0
  31. package/data/knowledge/releases/v0.4.0/release.yml +28 -0
  32. package/data/knowledge/releases/v0.5.0/entries/technique-config-surface-verification.yml +77 -0
  33. package/data/knowledge/releases/v0.5.0/entries/technique-derived-value-verification.yml +81 -0
  34. package/data/knowledge/releases/v0.5.0/entries/technique-expected-behaviour-specification.yml +97 -0
  35. package/data/knowledge/releases/v0.5.0/entries/technique-presentation-integrity.yml +78 -0
  36. package/data/knowledge/releases/v0.5.0/entries/technique-release-readiness-verification.yml +110 -0
  37. package/data/knowledge/releases/v0.5.0/release.yml +33 -0
  38. package/data/knowledge/releases/v0.6.0/entries/technique-async-callback-contracts.yml +98 -0
  39. package/data/knowledge/releases/v0.6.0/entries/technique-exactly-once-verification.yml +116 -0
  40. package/data/knowledge/releases/v0.6.0/release.yml +30 -0
  41. package/data/security/SECURITY-POLICY.md +273 -0
  42. package/data/targets/_default.yml +1 -1
  43. package/data/targets/_example-api-only.yml +80 -0
  44. package/data/targets/_example-backend.yml +123 -0
  45. package/data/targets/_example-mobile-emulation.yml +2 -2
  46. package/data/targets/_example-native-mobile.yml +2 -2
  47. package/data/targets/_example-sim-android-chrome.yml +1 -1
  48. package/data/targets/_example-sim-ios-safari.yml +1 -1
  49. package/data/templates/api-probe-matrix.md +99 -0
  50. package/data/templates/bug-report.md +29 -151
  51. package/data/templates/coverage-map.md +23 -6
  52. package/data/templates/expected-behaviour.md +94 -0
  53. package/data/templates/session-charter.md +3 -0
  54. package/data/templates/session-report.md +57 -80
  55. package/dist/cli/index.js +1500 -739
  56. package/dist/index.d.ts +673 -75
  57. package/dist/index.js +1664 -270
  58. package/docs/BACKEND-VERIFICATION.md +307 -0
  59. package/docs/GETTING-STARTED.md +188 -128
  60. package/docs/MOBILE-SETUP.md +149 -18
  61. package/package.json +32 -16
  62. package/skills/qa-explore/SKILL.md +31 -25
  63. package/skills/qa-explore/phases/00-setup.md +67 -41
  64. package/skills/qa-explore/phases/01-auth.md +32 -15
  65. package/skills/qa-explore/phases/02-charter.md +16 -5
  66. package/skills/qa-explore/phases/03-discovery.md +50 -26
  67. package/skills/qa-explore/phases/04-journeys.md +2 -2
  68. package/skills/qa-explore/phases/05-features.md +39 -24
  69. package/skills/qa-explore/phases/06-edge-cases.md +24 -13
  70. package/skills/qa-explore/phases/07-reporting.md +79 -140
  71. package/skills/qa-explore/references/context-integration.md +1 -1
  72. package/skills/qa-explore/references/output-contract.md +187 -0
  73. package/skills/qa-explore/references/paths.md +84 -0
  74. package/skills/qa-explore/references/playwright-agents-integration.md +61 -84
  75. package/skills/qa-explore/references/security-rules.md +66 -25
  76. package/skills/qa-explore/references/severity-guide.md +31 -4
  77. package/skills/qa-explore-cleanup/SKILL.md +17 -6
  78. package/skills/qa-explore-feedback/SKILL.md +18 -5
  79. package/skills/qa-explore-mobile/SKILL.md +86 -64
  80. package/skills/qa-explore-mobile/phases/00-setup.md +71 -62
  81. package/skills/qa-explore-mobile/phases/01-auth.md +28 -31
  82. package/skills/qa-explore-mobile/phases/02-charter.md +8 -4
  83. package/skills/qa-explore-mobile/phases/03-discovery.md +17 -11
  84. package/skills/qa-explore-mobile/phases/04-journeys.md +6 -6
  85. package/skills/qa-explore-mobile/phases/05-features.md +9 -9
  86. package/skills/qa-explore-mobile/phases/06-edge-cases.md +35 -40
  87. package/skills/qa-explore-mobile/phases/07-reporting.md +82 -56
  88. package/skills/qa-explore-mobile/references/mobile-edges.md +26 -26
  89. package/skills/qa-explore-quick/SKILL.md +60 -25
  90. package/skills/qa-explore-report/SKILL.md +40 -34
  91. package/skills/qa-gather/SKILL.md +17 -2
  92. package/skills/qa-knowledge-add/SKILL.md +20 -9
  93. package/skills/qa-knowledge-list/SKILL.md +12 -3
  94. package/skills/qa-target-setup/SKILL.md +63 -41
  95. package/skills/qa-verify-backend/SKILL.md +172 -0
  96. package/skills/qa-verify-backend/phases/00-setup.md +142 -0
  97. package/skills/qa-verify-backend/phases/01-ac-decomposition.md +58 -0
  98. package/skills/qa-verify-backend/phases/02-static-review.md +71 -0
  99. package/skills/qa-verify-backend/phases/03-live-verification.md +62 -0
  100. package/skills/qa-verify-backend/phases/03b-api-verification.md +170 -0
  101. package/skills/qa-verify-backend/phases/04-e2e-trigger.md +82 -0
  102. package/skills/qa-verify-backend/phases/05-reporting.md +163 -0
  103. package/skills/qa-verify-backend/references/api-probes.md +168 -0
  104. package/skills/qa-verify-backend/references/aws-readonly-probes.md +156 -0
  105. package/skills/qa-verify-backend/references/environment-fingerprinting.md +104 -0
  106. package/skills/qa-verify-backend/references/payload-verification.md +112 -0
  107. package/skills/qa-verify-backend/references/release-readiness.md +97 -0
  108. package/skills/qa-verify-backend/references/safety-rules.md +95 -0
  109. package/dist/cli/index.d.ts +0 -1
  110. package/dist/cli/index.js.map +0 -1
  111. package/dist/index.js.map +0 -1
package/dist/cli/index.js CHANGED
@@ -5,64 +5,145 @@ import { Command as Command7 } from "commander";
5
5
 
6
6
  // src/cli/commands/init.ts
7
7
  import { Command } from "commander";
8
- import { fileURLToPath } from "url";
9
- import { dirname, resolve, join } from "path";
8
+ import { resolve as resolve2, join as join2, relative, dirname as dirname2 } from "path";
10
9
  import {
11
- existsSync,
12
- readFileSync,
10
+ existsSync as existsSync2,
11
+ readFileSync as readFileSync2,
13
12
  writeFileSync,
14
13
  mkdirSync,
15
- readdirSync
14
+ readdirSync,
15
+ statSync,
16
+ copyFileSync,
17
+ chmodSync
16
18
  } from "fs";
17
- import { cp } from "fs/promises";
18
19
  import chalk from "chalk";
19
- var __dirname = dirname(fileURLToPath(import.meta.url));
20
- function resolvePackageRoot() {
21
- let current = __dirname;
20
+
21
+ // src/utils/paths.ts
22
+ import { fileURLToPath } from "url";
23
+ import { dirname, resolve, join, basename } from "path";
24
+ import { existsSync, readFileSync } from "fs";
25
+ var HERE = dirname(fileURLToPath(import.meta.url));
26
+ function getPackageRoot() {
27
+ let current = HERE;
22
28
  for (let i = 0; i < 10; i++) {
23
29
  if (existsSync(join(current, "data")) && existsSync(join(current, "package.json"))) {
24
30
  return current;
25
31
  }
26
- current = dirname(current);
32
+ const parent = dirname(current);
33
+ if (parent === current) break;
34
+ current = parent;
27
35
  }
28
- return resolve(__dirname, "..", "..");
36
+ return resolve(HERE, "..", "..");
37
+ }
38
+ function getPackageVersion(pkgRoot = getPackageRoot()) {
39
+ try {
40
+ const pkg = JSON.parse(
41
+ readFileSync(join(pkgRoot, "package.json"), "utf-8")
42
+ );
43
+ return pkg.version ?? "0.0.0";
44
+ } catch {
45
+ return "0.0.0";
46
+ }
47
+ }
48
+ function resolveSkillsSource(pkgRoot) {
49
+ const shipped = join(pkgRoot, "skills");
50
+ if (existsSync(shipped)) return shipped;
51
+ const canonical = join(pkgRoot, ".claude", "skills");
52
+ if (existsSync(canonical)) return canonical;
53
+ return null;
54
+ }
55
+ function resolveTargetPath(cwd, name, pkgRoot = getPackageRoot()) {
56
+ if (name) {
57
+ const candidates = [
58
+ resolve(cwd, "data", "targets", `${name}.yml`),
59
+ resolve(pkgRoot, "data", "targets", `${name}.yml`)
60
+ ];
61
+ return candidates.find((p) => existsSync(p)) ?? candidates[0];
62
+ }
63
+ const projectLocal = resolve(cwd, "qa", "target.yml");
64
+ if (existsSync(projectLocal)) return projectLocal;
65
+ const cwdDefault = resolve(cwd, "data", "targets", "_default.yml");
66
+ if (existsSync(cwdDefault)) return cwdDefault;
67
+ return resolve(pkgRoot, "data", "targets", "_default.yml");
68
+ }
69
+
70
+ // src/utils/index-files.ts
71
+ var INDEX_COLUMNS = [
72
+ "Date",
73
+ "Kind",
74
+ "Target",
75
+ "Bugs",
76
+ "Duration",
77
+ "Status",
78
+ "Report"
79
+ ];
80
+ var ALL_BUGS_COLUMNS = [
81
+ "ID",
82
+ "Session",
83
+ "Title",
84
+ "Severity",
85
+ "Status",
86
+ "Report"
87
+ ];
88
+ function table(title, note, columns) {
89
+ const header = `| ${columns.join(" | ")} |`;
90
+ const sep = `|${columns.map(() => "---").join("|")}|`;
91
+ return `# ${title}
92
+
93
+ ${note}
94
+
95
+ ${header}
96
+ ${sep}
97
+ `;
29
98
  }
30
- var GITIGNORE_ENTRIES = [
31
- "",
32
- "# Qualiow",
99
+ var INDEX_MD_HEADER = table(
100
+ "Exploratory Testing Sessions",
101
+ "_Index of exploratory testing sessions. Newest last._",
102
+ INDEX_COLUMNS
103
+ );
104
+ var ALL_BUGS_MD_HEADER = table(
105
+ "All Bugs Found",
106
+ "_Consolidated index across all exploratory testing sessions._",
107
+ ALL_BUGS_COLUMNS
108
+ );
109
+
110
+ // src/utils/gitignore.ts
111
+ var QUALIOW_GITIGNORE_HEADER = "# Qualiow";
112
+ var QUALIOW_GITIGNORE_ENTRIES = [
33
113
  ".auth/",
34
114
  ".env",
115
+ "qa/.env",
35
116
  "output/sessions/*/",
117
+ "!output/sessions/INDEX.md",
118
+ "output/context/*.md",
119
+ "data/targets/local-*.yml",
36
120
  ".playwright-cli/",
37
121
  "*.trace.zip",
38
- "*.webm",
39
- "dist/"
122
+ "*.webm"
40
123
  ];
41
- var INDEX_MD_HEADER = `# Exploratory Testing Sessions
42
-
43
- | Date | Target | Duration | Bugs | Session Directory |
44
- |------|--------|----------|------|-------------------|
45
- `;
46
- var ALL_BUGS_MD_HEADER = `# All Bugs \u2014 Exploratory Testing
47
-
48
- > Aggregated bug list across all sessions.
49
-
50
- | ID | Title | Severity | Session | Component |
51
- |----|-------|----------|---------|-----------|
52
- `;
53
- var ENV_EXAMPLE = `# Qualiow \u2014 Environment Variables
54
- # Copy this file to .env and fill in values.
55
-
56
- # Target auth tokens (if needed)
57
- # AUTH_TOKEN=
124
+ function mergeGitignore(existing) {
125
+ const existingLines = new Set(
126
+ existing.split("\n").map((l) => l.replace(/\s+$/, ""))
127
+ );
128
+ const missing = QUALIOW_GITIGNORE_ENTRIES.filter(
129
+ (e) => !existingLines.has(e)
130
+ );
131
+ if (missing.length === 0) return null;
132
+ const block = [];
133
+ if (!existingLines.has(QUALIOW_GITIGNORE_HEADER)) {
134
+ block.push(QUALIOW_GITIGNORE_HEADER);
135
+ }
136
+ block.push(...missing);
137
+ const prefix = existing.length === 0 || existing.endsWith("\n") ? "" : "\n";
138
+ const leadingBlank = existing.length > 0 ? "\n" : "";
139
+ return existing + prefix + leadingBlank + block.join("\n") + "\n";
140
+ }
58
141
 
59
- # Playwright options
60
- # HEADLESS=false
61
- `;
142
+ // src/cli/commands/init.ts
62
143
  function initCommand() {
63
- const cmd = new Command("init").description("Initialize qualiow in the current project").option("--include-examples", "Include example target configurations", false).option("--force", "Overwrite existing files", false).action(async (options) => {
144
+ const cmd = new Command("init").description("Initialize qualiow in the current project").option("--include-examples", "Also install the _example-* and testers-ai target configs", false).option("--force", "Overwrite files that already exist and differ", false).option("--dry-run", "Print what would be written without writing anything", false).action(async (options) => {
64
145
  try {
65
- await runInit(options);
146
+ await runInit(options, { cwd: process.cwd() });
66
147
  } catch (err) {
67
148
  console.error(chalk.red("Error during init:"), err instanceof Error ? err.message : err);
68
149
  process.exit(1);
@@ -70,159 +151,191 @@ function initCommand() {
70
151
  });
71
152
  return cmd;
72
153
  }
73
- async function runInit(options) {
74
- const cwd = process.cwd();
75
- const pkgRoot = resolvePackageRoot();
76
- const skillsDest = join(cwd, ".claude", "skills");
77
- const existingSkills = existsSync(skillsDest) ? readdirSync(skillsDest).filter((f) => f.startsWith("qa-")) : [];
78
- if (existingSkills.length > 0 && !options.force) {
79
- console.warn(
80
- chalk.yellow(
81
- `Warning: ${existingSkills.length} skill(s) already exist in .claude/skills/ (${existingSkills.join(", ")}). Use --force to overwrite.`
82
- )
83
- );
154
+ function sameContent(a, b) {
155
+ try {
156
+ return readFileSync2(a).equals(readFileSync2(b));
157
+ } catch {
158
+ return false;
159
+ }
160
+ }
161
+ function copyEntry(src, dest, opts) {
162
+ let status;
163
+ if (!existsSync2(dest)) {
164
+ status = "installed";
165
+ } else if (sameContent(src, dest)) {
166
+ status = "unchanged";
167
+ } else {
168
+ status = opts.force ? "overwritten" : "skipped";
169
+ }
170
+ if (!opts.dryRun && (status === "installed" || status === "overwritten")) {
171
+ mkdirSync(dirname2(dest), { recursive: true });
172
+ copyFileSync(src, dest);
173
+ chmodSync(dest, statSync(src).mode & 511);
84
174
  }
85
- const skillsSrc = join(pkgRoot, ".claude", "skills");
86
- if (existsSync(skillsSrc)) {
87
- const srcReal = resolve(skillsSrc);
88
- const destReal = resolve(skillsDest);
89
- if (srcReal !== destReal) {
90
- if (existingSkills.length === 0 || options.force) {
91
- mkdirSync(skillsDest, { recursive: true });
92
- await cp(skillsSrc, skillsDest, { recursive: true, force: options.force });
93
- console.log(chalk.green(" \u2713 Skills installed to .claude/skills/"));
175
+ return { dest, status };
176
+ }
177
+ function listFiles(dir, filter) {
178
+ const out = [];
179
+ const walk = (current) => {
180
+ for (const entry of readdirSync(current, { withFileTypes: true })) {
181
+ const full = join2(current, entry.name);
182
+ if (entry.isDirectory()) {
183
+ walk(full);
94
184
  } else {
95
- console.log(chalk.cyan(" \u25CB Skills skipped (already exist, use --force to overwrite)"));
185
+ const rel = relative(dir, full).split("\\").join("/");
186
+ if (!filter || filter(rel)) out.push(rel);
96
187
  }
97
- } else {
98
- console.log(chalk.cyan(" \u25CB Skills directory is the same as source \u2014 skipped"));
99
188
  }
189
+ };
190
+ walk(dir);
191
+ return out.sort();
192
+ }
193
+ function copyTree(srcDir, destDir, opts) {
194
+ if (!existsSync2(srcDir)) return [];
195
+ return listFiles(srcDir, opts.filter).map(
196
+ (rel) => copyEntry(join2(srcDir, rel), join2(destDir, rel), opts)
197
+ );
198
+ }
199
+ async function runInit(options, ctx) {
200
+ const cwd = ctx.cwd;
201
+ const pkgRoot = ctx.pkgRoot ?? getPackageRoot();
202
+ const log = ctx.log ?? ((line) => console.log(line));
203
+ const copyOpts = { force: options.force, dryRun: options.dryRun };
204
+ const copies = [];
205
+ const createdDirs = [];
206
+ const createdFiles = [];
207
+ if (options.dryRun) log(chalk.cyan.bold("Dry run \u2014 nothing will be written\n"));
208
+ if (resolve2(pkgRoot) === resolve2(cwd)) {
209
+ log(chalk.yellow(" \u25CB Running inside the package itself \u2014 skills and data are already in place"));
100
210
  } else {
101
- console.log(chalk.yellow(" \u26A0 No skills/ directory found in package root"));
102
- }
103
- const dataSrc = join(pkgRoot, "data");
104
- const dataDest = join(cwd, "data");
105
- if (existsSync(dataSrc)) {
106
- const srcReal = resolve(dataSrc);
107
- const destReal = resolve(dataDest);
108
- if (srcReal !== destReal) {
109
- mkdirSync(dataDest, { recursive: true });
110
- const knowledgeSrc = join(dataSrc, "knowledge");
111
- if (existsSync(knowledgeSrc)) {
112
- await cp(knowledgeSrc, join(dataDest, "knowledge"), { recursive: true, force: options.force });
113
- console.log(chalk.green(" \u2713 Knowledge base installed to data/knowledge/"));
114
- }
115
- const domainsSrc = join(dataSrc, "domains");
116
- if (existsSync(domainsSrc)) {
117
- await cp(domainsSrc, join(dataDest, "domains"), { recursive: true, force: options.force });
118
- console.log(chalk.green(" \u2713 Domain configs installed to data/domains/"));
119
- }
120
- const templatesSrc = join(dataSrc, "templates");
121
- if (existsSync(templatesSrc)) {
122
- await cp(templatesSrc, join(dataDest, "templates"), { recursive: true, force: options.force });
123
- console.log(chalk.green(" \u2713 Templates installed to data/templates/"));
124
- }
125
- const securitySrc = join(dataSrc, "security");
126
- if (existsSync(securitySrc)) {
127
- await cp(securitySrc, join(dataDest, "security"), { recursive: true, force: options.force });
128
- console.log(chalk.green(" \u2713 Security policies installed to data/security/"));
129
- }
130
- const targetsSrc = join(dataSrc, "targets");
131
- const targetsDest = join(dataDest, "targets");
132
- if (existsSync(targetsSrc)) {
133
- mkdirSync(targetsDest, { recursive: true });
134
- const defaultFile = join(targetsSrc, "_default.yml");
135
- if (existsSync(defaultFile)) {
136
- const content = readFileSync(defaultFile, "utf-8");
137
- writeFileSync(join(targetsDest, "_default.yml"), content);
138
- }
139
- if (options.includeExamples) {
140
- const targetFiles = readdirSync(targetsSrc).filter(
141
- (f) => f.endsWith(".yml") && f !== "_default.yml"
142
- );
143
- for (const file of targetFiles) {
144
- const content = readFileSync(join(targetsSrc, file), "utf-8");
145
- writeFileSync(join(targetsDest, file), content);
146
- }
147
- console.log(chalk.green(" \u2713 Target configs installed to data/targets/ (with examples)"));
148
- } else {
149
- console.log(chalk.green(" \u2713 Default target config installed to data/targets/"));
211
+ const skillsSrc = resolveSkillsSource(pkgRoot);
212
+ if (!skillsSrc) {
213
+ throw new Error(`No skills directory found under ${pkgRoot}`);
214
+ }
215
+ copies.push(
216
+ ...copyTree(skillsSrc, join2(cwd, ".claude", "skills"), {
217
+ ...copyOpts,
218
+ filter: (rel2) => rel2.startsWith("qa-")
219
+ })
220
+ );
221
+ const agentCandidates = [
222
+ join2(pkgRoot, "agents", "qa-gather-agent.md"),
223
+ join2(pkgRoot, ".claude", "agents", "qa-gather-agent.md")
224
+ ];
225
+ const agentSrc = agentCandidates.find((p) => existsSync2(p));
226
+ if (agentSrc) {
227
+ copies.push(
228
+ copyEntry(agentSrc, join2(cwd, ".claude", "agents", "qa-gather-agent.md"), copyOpts)
229
+ );
230
+ }
231
+ const dataSrc = join2(pkgRoot, "data");
232
+ copies.push(...copyTree(join2(dataSrc, "knowledge"), join2(cwd, "data", "knowledge"), copyOpts));
233
+ copies.push(
234
+ ...copyTree(join2(dataSrc, "domains"), join2(cwd, "data", "domains"), {
235
+ ...copyOpts,
236
+ filter: (rel2) => rel2.endsWith(".yml")
237
+ })
238
+ );
239
+ copies.push(...copyTree(join2(dataSrc, "templates"), join2(cwd, "data", "templates"), copyOpts));
240
+ copies.push(...copyTree(join2(dataSrc, "security"), join2(cwd, "data", "security"), copyOpts));
241
+ copies.push(
242
+ ...copyTree(join2(dataSrc, "targets"), join2(cwd, "data", "targets"), {
243
+ ...copyOpts,
244
+ filter: (rel2) => {
245
+ if (!rel2.endsWith(".yml") || rel2.includes("/")) return false;
246
+ if (rel2.startsWith("local-")) return false;
247
+ if (rel2 === "_default.yml") return true;
248
+ if (!options.includeExamples) return false;
249
+ return rel2.startsWith("_example-") || rel2 === "testers-ai.yml";
150
250
  }
251
+ })
252
+ );
253
+ const binSrc = join2(pkgRoot, "bin");
254
+ copies.push(...copyTree(binSrc, join2(cwd, "qa", "bin"), copyOpts));
255
+ if (existsSync2(binSrc)) {
256
+ const versionPath = join2(cwd, "qa", "bin", "VERSION");
257
+ const version = `${getPackageVersion(pkgRoot)}
258
+ `;
259
+ const exists = existsSync2(versionPath);
260
+ const same = exists && readFileSync2(versionPath, "utf-8") === version;
261
+ const status = !exists ? "installed" : same ? "unchanged" : options.force ? "overwritten" : "skipped";
262
+ if (!options.dryRun && (status === "installed" || status === "overwritten")) {
263
+ mkdirSync(dirname2(versionPath), { recursive: true });
264
+ writeFileSync(versionPath, version);
151
265
  }
152
- } else {
153
- console.log(chalk.cyan(" \u25CB Data directory is the same as source \u2014 skipped"));
154
- }
155
- }
156
- const outputDirs = [
157
- join(cwd, "output", "sessions"),
158
- join(cwd, "output", "bugs"),
159
- join(cwd, "output", "context"),
160
- join(cwd, ".auth")
161
- ];
162
- for (const dir of outputDirs) {
163
- mkdirSync(dir, { recursive: true });
164
- }
165
- console.log(chalk.green(" \u2713 Output directories created"));
166
- const indexPath = join(cwd, "output", "sessions", "INDEX.md");
167
- if (!existsSync(indexPath)) {
168
- writeFileSync(indexPath, INDEX_MD_HEADER);
169
- console.log(chalk.green(" \u2713 Created output/sessions/INDEX.md"));
170
- }
171
- const allBugsPath = join(cwd, "output", "bugs", "all-bugs.md");
172
- if (!existsSync(allBugsPath)) {
173
- writeFileSync(allBugsPath, ALL_BUGS_MD_HEADER);
174
- console.log(chalk.green(" \u2713 Created output/bugs/all-bugs.md"));
175
- }
176
- const envExamplePath = join(cwd, ".env.example");
177
- if (!existsSync(envExamplePath)) {
178
- writeFileSync(envExamplePath, ENV_EXAMPLE);
179
- console.log(chalk.green(" \u2713 Created .env.example"));
180
- }
181
- const gitignorePath = join(cwd, ".gitignore");
182
- let gitignoreContent = "";
183
- if (existsSync(gitignorePath)) {
184
- gitignoreContent = readFileSync(gitignorePath, "utf-8");
185
- }
186
- const linesToAdd = [];
187
- for (const entry of GITIGNORE_ENTRIES) {
188
- if (entry === "" || entry.startsWith("#")) {
189
- if (!gitignoreContent.includes("# Qualiow") && entry === "# Qualiow") {
190
- linesToAdd.push(entry);
191
- } else if (entry === "" && linesToAdd.length === 0) {
192
- linesToAdd.push(entry);
266
+ copies.push({ dest: versionPath, status });
267
+ }
268
+ const envExampleSrc = join2(pkgRoot, ".env.example");
269
+ if (existsSync2(envExampleSrc)) {
270
+ copies.push(copyEntry(envExampleSrc, join2(cwd, "qa", ".env.example"), copyOpts));
271
+ }
272
+ }
273
+ for (const dir of ["output/sessions", "output/bugs", "output/context", ".auth", "qa"]) {
274
+ const full = join2(cwd, dir);
275
+ if (!existsSync2(full)) {
276
+ createdDirs.push(full);
277
+ if (!options.dryRun) mkdirSync(full, { recursive: true });
278
+ }
279
+ }
280
+ for (const [rel2, content] of [
281
+ ["output/sessions/INDEX.md", INDEX_MD_HEADER],
282
+ ["output/bugs/all-bugs.md", ALL_BUGS_MD_HEADER]
283
+ ]) {
284
+ const full = join2(cwd, rel2);
285
+ if (!existsSync2(full)) {
286
+ createdFiles.push(full);
287
+ if (!options.dryRun) {
288
+ mkdirSync(dirname2(full), { recursive: true });
289
+ writeFileSync(full, content);
193
290
  }
194
- continue;
195
- }
196
- if (!gitignoreContent.includes(entry)) {
197
- linesToAdd.push(entry);
198
291
  }
199
292
  }
200
- if (linesToAdd.length > 0) {
201
- const appendStr = (gitignoreContent.endsWith("\n") || gitignoreContent === "" ? "" : "\n") + linesToAdd.join("\n") + "\n";
202
- writeFileSync(gitignorePath, gitignoreContent + appendStr);
203
- console.log(chalk.green(" \u2713 Updated .gitignore"));
293
+ const gitignorePath = join2(cwd, ".gitignore");
294
+ const existing = existsSync2(gitignorePath) ? readFileSync2(gitignorePath, "utf-8") : "";
295
+ const merged = mergeGitignore(existing);
296
+ const gitignoreUpdated = merged !== null;
297
+ if (merged !== null && !options.dryRun) {
298
+ writeFileSync(gitignorePath, merged);
204
299
  }
205
- console.log("");
206
- console.log(chalk.cyan.bold("Qualiow initialized successfully!"));
207
- console.log("");
208
- console.log(chalk.white("Next steps:"));
209
- console.log(chalk.white(" 1. Install Playwright CLI: npm install @playwright/cli"));
210
- console.log(chalk.white(" 2. Run your first session: /qa-explore https://your-app.com"));
211
- console.log(chalk.white(" 3. Or use the CLI: npx qualiow explore https://your-app.com"));
212
- console.log("");
300
+ const counts = { installed: 0, unchanged: 0, overwritten: 0, skipped: 0 };
301
+ for (const c of copies) counts[c.status]++;
302
+ const rel = (p) => relative(cwd, p) || ".";
303
+ if (copies.length) {
304
+ log(
305
+ chalk.green(` \u2713 Files: ${counts.installed} installed, ${counts.unchanged} unchanged` + (counts.overwritten ? `, ${counts.overwritten} overwritten` : "") + (counts.skipped ? chalk.yellow(`, ${counts.skipped} skipped (exist and differ \u2014 use --force)`) : ""))
306
+ );
307
+ for (const c of copies.filter((x) => x.status === "skipped")) {
308
+ log(chalk.yellow(` skipped ${rel(c.dest)}`));
309
+ }
310
+ }
311
+ for (const d of createdDirs) log(chalk.green(` \u2713 Created ${rel(d)}/`));
312
+ for (const f of createdFiles) log(chalk.green(` \u2713 Created ${rel(f)}`));
313
+ log(
314
+ gitignoreUpdated ? chalk.green(" \u2713 Updated .gitignore (Qualiow block)") : chalk.cyan(" \u25CB .gitignore already up to date")
315
+ );
316
+ log("");
317
+ log(chalk.cyan.bold(options.dryRun ? "Dry run complete." : "Qualiow initialized."));
318
+ log("");
319
+ log(chalk.white("Next steps:"));
320
+ log(chalk.white(" 1. npx playwright-cli install --skills # official Playwright skill, next to qualiow"));
321
+ log(chalk.white(" 2. cp qa/.env.example qa/.env # credentials by env var name only"));
322
+ log(chalk.white(" 3. /qa-target-setup or /qa-explore https://your-app.com"));
323
+ log(chalk.white(" 4. mobile: qa/bin/doctor-mobile.sh # then /qa-explore-mobile --target <id>"));
324
+ log("");
325
+ return { copies, createdDirs, createdFiles, gitignoreUpdated };
213
326
  }
214
327
 
215
328
  // src/cli/commands/validate.ts
216
329
  import { Command as Command2 } from "commander";
217
- import { resolve as resolve3, relative } from "path";
218
- import { existsSync as existsSync2 } from "fs";
219
- import { globSync as globSync2 } from "glob";
330
+ import { resolve as resolve4, relative as relative3, join as join5 } from "path";
331
+ import { existsSync as existsSync5 } from "fs";
332
+ import { globSync as globSync3 } from "glob";
220
333
  import chalk2 from "chalk";
221
334
 
222
335
  // src/utils/validate.ts
223
- import { readFileSync as readFileSync2 } from "fs";
224
- import { resolve as resolve2, join as join2 } from "path";
225
- import { parse as parseYaml } from "yaml";
336
+ import { readFileSync as readFileSync4, existsSync as existsSync4 } from "fs";
337
+ import { resolve as resolve3, join as join4, basename as basename3 } from "path";
338
+ import { parse as parseYaml2 } from "yaml";
226
339
  import { ZodError } from "zod";
227
340
 
228
341
  // src/schemas/target.schema.ts
@@ -244,38 +357,92 @@ var AuthConfigSchema = z.object({
244
357
  credentials: z.object({
245
358
  username: z.string(),
246
359
  password: z.string()
247
- }).optional(),
360
+ }).strict().optional(),
248
361
  token: z.string().optional(),
249
362
  identity_provider: z.string().optional(),
250
363
  // Staging builds sometimes accept a fixed OTP — recorded so the auth phase can
251
364
  // use it instead of waiting for a real code. Never a real credential.
252
365
  static_otp: z.string().optional(),
253
- test_email_pattern: z.string().optional()
254
- });
366
+ test_email_pattern: z.string().optional(),
367
+ notes: z.string().optional()
368
+ }).strict();
255
369
  var BrowserConfigSchema = z.object({
256
370
  headless: z.boolean(),
257
371
  viewport: z.object({
258
372
  width: z.number().int().positive(),
259
373
  height: z.number().int().positive()
260
- }),
374
+ }).strict(),
261
375
  // Optional engine selection + Playwright device descriptor for mobile-web
262
376
  // emulation targets (e.g. engine: webkit, device: "iPhone 15").
263
377
  engine: z.enum(["chromium", "webkit", "firefox"]).optional(),
264
378
  channel: z.string().optional(),
265
379
  device: z.string().optional()
266
- });
380
+ }).strict();
267
381
  var ScopeConfigSchema = z.object({
268
382
  start_pages: z.array(z.string()).optional(),
269
383
  max_depth: z.number().int().min(0),
270
384
  include_patterns: z.array(z.string()).optional(),
271
385
  exclude_patterns: z.array(z.string()).optional()
272
- });
386
+ }).strict();
273
387
  var SafetyConfigSchema = z.object({
274
388
  read_only: z.boolean(),
275
389
  no_form_submit: z.boolean(),
276
390
  no_file_upload: z.boolean().optional(),
277
391
  no_delete_actions: z.boolean().optional()
278
- });
392
+ }).strict();
393
+ var EnvironmentConfigSchema = z.object({
394
+ kind: z.enum(["dev", "ephemeral", "staging", "production"]),
395
+ destroyed_automatically: z.boolean().optional()
396
+ }).strict();
397
+ var BackendConfigSchema = z.object({
398
+ provider: z.enum(["aws"]).optional(),
399
+ aws_profile_env: z.string().optional(),
400
+ region_env: z.string().optional(),
401
+ region: z.string().optional(),
402
+ // Expected account. The skill compares it to `sts get-caller-identity` and
403
+ // stops the live lane on a mismatch rather than probing someone else's account.
404
+ account_id: z.string().optional(),
405
+ env_suffix: z.string().optional(),
406
+ // Free-form logical name -> deployed resource name (config_table, dlq, ...).
407
+ resources: z.record(z.string(), z.string()).optional(),
408
+ notes: z.string().optional()
409
+ }).strict();
410
+ var ApiSurfaceConfigSchema = z.object({
411
+ // Defaults to the target's base_url when omitted.
412
+ base_url: z.string().optional(),
413
+ auth: z.enum(["session-cookie", "bearer-env", "api-key-env", "none"]).optional(),
414
+ // NAME of the env var holding the credential, for `auth: bearer-env` (a bearer
415
+ // token) or `auth: api-key-env` (a static API key sent in its own header).
416
+ token_env: z.string().optional(),
417
+ // Header carrying the credential for `auth: api-key-env`. Defaults to
418
+ // `X-Api-Key`. The VALUE always comes from `token_env`, never from here.
419
+ header_name: z.string().optional(),
420
+ // Persistent browser profile directory holding the authenticated session,
421
+ // e.g. `.auth/my-service-dev-profile`. Gitignored.
422
+ browser_profile: z.string().optional(),
423
+ // Endpoint returning the deployed build, used to fingerprint the environment.
424
+ version_endpoint: z.string().optional(),
425
+ // Logical name -> "VERB /path", e.g. search: "POST /api/v1/search".
426
+ endpoints: z.record(z.string(), z.string()).optional(),
427
+ // The ONLY endpoints the read-only API lane may call without asking.
428
+ probe_allowlist: z.array(z.string()).optional(),
429
+ // The ONLY endpoints phase 4 may call through the real write path, and only in
430
+ // a dev or ephemeral environment. Empty or absent means the API lane is
431
+ // read-only here and every state-changing AC needs a different channel.
432
+ write_allowlist: z.array(z.string()).optional(),
433
+ // Other target ids to run the same matrix against, for parity comparison.
434
+ parity_targets: z.array(z.string()).optional(),
435
+ // Flag name -> where its deployed value is declared for this environment.
436
+ // A flag can select between two implementations inside one identical build.
437
+ feature_flags: z.record(z.string(), z.string()).optional(),
438
+ notes: z.string().optional()
439
+ }).strict();
440
+ var SourceBranchConfigSchema = z.object({
441
+ repo_path: z.string(),
442
+ branch: z.string(),
443
+ base_branch: z.string().optional(),
444
+ components: z.record(z.string(), z.string()).optional()
445
+ }).strict();
279
446
  var WebTargetConfigSchema = z.object({
280
447
  id: z.string().min(1),
281
448
  name: z.string().min(1),
@@ -287,8 +454,14 @@ var WebTargetConfigSchema = z.object({
287
454
  browser: BrowserConfigSchema,
288
455
  scope: ScopeConfigSchema,
289
456
  safety: SafetyConfigSchema.optional(),
457
+ // Optional blocks consumed by /qa-verify-backend. A target without them is
458
+ // still a valid /qa-explore target.
459
+ environment: EnvironmentConfigSchema.optional(),
460
+ backend: BackendConfigSchema.optional(),
461
+ api: ApiSurfaceConfigSchema.optional(),
462
+ source: SourceBranchConfigSchema.optional(),
290
463
  notes: z.string().optional()
291
- });
464
+ }).strict();
292
465
  var MobileDeviceConfigSchema = z.object({
293
466
  name: z.string().optional(),
294
467
  // iOS simulator name (portable across machines)
@@ -298,7 +471,7 @@ var MobileDeviceConfigSchema = z.object({
298
471
  // Android AVD name
299
472
  serial: z.string().optional()
300
473
  // Android serial once booted (e.g. emulator-5554)
301
- });
474
+ }).strict();
302
475
  var MobileAppConfigSchema = z.object({
303
476
  bundle_id: z.string().optional(),
304
477
  // iOS bundle id (or browser bundle in web mode)
@@ -308,21 +481,21 @@ var MobileAppConfigSchema = z.object({
308
481
  // iOS .app artifact(s) — native mode
309
482
  apk_paths: z.array(z.string()).optional()
310
483
  // Android APK(s) — native mode
311
- });
484
+ }).strict();
312
485
  var MobileWebConfigSchema = z.object({
313
486
  base_url: z.string().url(),
314
487
  start_url: z.string().url().optional()
315
- });
488
+ }).strict();
316
489
  var SourceRepoConfigSchema = z.object({
317
490
  path: z.string(),
318
491
  build_commands: z.record(z.string(), z.string()).optional()
319
- });
492
+ }).strict();
320
493
  var MobileScopeConfigSchema = z.object({
321
494
  start_screen: z.string().optional(),
322
495
  start_url: z.string().optional(),
323
496
  include_patterns: z.array(z.string()).optional(),
324
497
  exclude_patterns: z.array(z.string()).optional()
325
- });
498
+ }).strict();
326
499
  var MobileTargetConfigSchema = z.object({
327
500
  id: z.string().min(1),
328
501
  name: z.string().min(1),
@@ -338,15 +511,22 @@ var MobileTargetConfigSchema = z.object({
338
511
  safety: SafetyConfigSchema.optional(),
339
512
  source_repo: SourceRepoConfigSchema.optional(),
340
513
  notes: z.string().optional()
341
- });
342
- var TargetConfigSchema = z.custom().superRefine((data, ctx) => {
343
- const isMobile = typeof data === "object" && data !== null && "platform" in data;
514
+ }).strict();
515
+ var TargetConfigSchema = z.unknown().transform((data, ctx) => {
516
+ if (typeof data !== "object" || data === null || Array.isArray(data)) {
517
+ ctx.addIssue({ code: "custom", message: "Expected a target config object" });
518
+ return z.NEVER;
519
+ }
520
+ const isMobile = "platform" in data;
344
521
  const branch = isMobile ? MobileTargetConfigSchema : WebTargetConfigSchema;
345
522
  const result = branch.safeParse(data);
346
523
  if (!result.success) {
347
- for (const issue of result.error.issues)
524
+ for (const issue of result.error.issues) {
348
525
  ctx.addIssue(issue);
526
+ }
527
+ return z.NEVER;
349
528
  }
529
+ return result.data;
350
530
  });
351
531
 
352
532
  // src/schemas/knowledge-entry.schema.ts
@@ -371,30 +551,193 @@ var KnowledgeEntrySchema = z2.object({
371
551
 
372
552
  // src/schemas/domain-config.schema.ts
373
553
  import { z as z3 } from "zod";
554
+ var RiskRankingSchema = z3.object({
555
+ p0: z3.array(z3.string()).min(1),
556
+ p1: z3.array(z3.string()).min(1),
557
+ p2: z3.array(z3.string()).min(1),
558
+ p3: z3.array(z3.string()).min(1)
559
+ }).strict();
374
560
  var JourneySchema = z3.object({
375
- id: z3.string().min(1),
376
561
  name: z3.string().min(1),
377
- description: z3.string().min(1),
378
- steps: z3.array(z3.string()).min(1),
379
- risk: z3.enum(["high", "medium", "low"])
380
- });
562
+ steps: z3.array(z3.string()).min(1)
563
+ }).strict();
381
564
  var DomainConfigSchema = z3.object({
382
565
  id: z3.string().min(1),
383
566
  name: z3.string().min(1),
384
- risk_ranking: z3.array(z3.string()).min(1),
567
+ risk_ranking: RiskRankingSchema,
385
568
  completeness_checklist: z3.array(z3.string()).min(1),
386
569
  data_integrity_checks: z3.array(z3.string()).min(1),
387
570
  journeys: z3.array(JourneySchema).min(1),
388
- guidance: z3.array(z3.string()).min(1)
571
+ must_test_patterns: z3.record(z3.string(), z3.array(z3.string())),
572
+ common_bugs: z3.array(z3.string()).min(1),
573
+ compliance: z3.array(z3.string()).min(1),
574
+ guidance: z3.string().min(1)
575
+ }).strict();
576
+
577
+ // src/schemas/knowledge-manifest.schema.ts
578
+ import { z as z4 } from "zod";
579
+ var KnowledgeManifestStatsSchema = z4.object({
580
+ total_entries: z4.number().int().min(0),
581
+ heuristics: z4.number().int().min(0),
582
+ techniques: z4.number().int().min(0),
583
+ checklists: z4.number().int().min(0),
584
+ references: z4.number().int().min(0),
585
+ domain_profiles: z4.number().int().min(0),
586
+ custom_entries: z4.number().int().min(0)
587
+ });
588
+ var KnowledgeManifestEntrySchema = z4.object({
589
+ id: z4.string().min(1),
590
+ file: z4.string().min(1),
591
+ type: z4.string().min(1),
592
+ priority: z4.enum(["high", "medium", "low"]),
593
+ tags: z4.array(z4.string()),
594
+ domains: z4.array(z4.string())
595
+ });
596
+ var LoadingStrategySchema = z4.object({
597
+ always: z4.array(z4.string()),
598
+ by_domain: z4.record(z4.string(), z4.array(z4.string())),
599
+ by_tag: z4.record(z4.string(), z4.array(z4.string()))
600
+ });
601
+ var KnowledgeManifestSchema = z4.object({
602
+ version: z4.string().min(1),
603
+ last_updated: z4.string().min(1),
604
+ active_releases: z4.array(z4.string()).min(1),
605
+ stats: KnowledgeManifestStatsSchema,
606
+ loading_strategy: LoadingStrategySchema,
607
+ entries: z4.array(KnowledgeManifestEntrySchema).min(1)
389
608
  });
390
609
 
391
- // src/utils/validate.ts
610
+ // src/schemas/knowledge-release.schema.ts
611
+ import { z as z5 } from "zod";
612
+ var KnowledgeReleaseSchema = z5.object({
613
+ version: z5.string().min(1),
614
+ date: z5.string().min(1),
615
+ author: z5.string().min(1),
616
+ status: z5.enum(["active", "deprecated"]),
617
+ notes: z5.string().min(1),
618
+ entry_count: z5.number().int().min(0),
619
+ entries: z5.array(z5.string().min(1)).min(1)
620
+ }).strict().refine((r) => r.entry_count === r.entries.length, {
621
+ message: "entry_count must equal the number of listed entries",
622
+ path: ["entry_count"]
623
+ });
624
+
625
+ // src/schemas/knowledge-changelog.schema.ts
626
+ import { z as z6 } from "zod";
627
+ var ChangelogEntrySchema = z6.object({
628
+ id: z6.string().min(1),
629
+ type: z6.enum(["heuristic", "technique", "checklist", "reference"]),
630
+ name: z6.string().min(1),
631
+ description: z6.string().min(1)
632
+ }).strict();
633
+ var ChangelogReleaseSchema = z6.object({
634
+ version: z6.string().min(1),
635
+ date: z6.string().min(1),
636
+ summary: z6.string().min(1),
637
+ entries_added: z6.array(ChangelogEntrySchema),
638
+ entries_modified: z6.array(z6.string()).default([]),
639
+ entries_removed: z6.array(z6.string()).default([]),
640
+ origin: z6.string().optional()
641
+ }).strict();
642
+ var KnowledgeChangelogSchema = z6.object({
643
+ releases: z6.array(ChangelogReleaseSchema).min(1)
644
+ }).strict();
645
+
646
+ // src/utils/kb-sync.ts
647
+ import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, existsSync as existsSync3, readdirSync as readdirSync2 } from "fs";
648
+ import { join as join3, relative as relative2, basename as basename2 } from "path";
649
+ import { parse as parseYaml, parseDocument } from "yaml";
392
650
  import { globSync } from "glob";
651
+ var TYPE_TO_STAT = {
652
+ heuristic: "heuristics",
653
+ technique: "techniques",
654
+ checklist: "checklists",
655
+ reference: "references"
656
+ };
657
+ function listReleaseDirs(knowledgeDir) {
658
+ const releasesDir = join3(knowledgeDir, "releases");
659
+ if (!existsSync3(releasesDir)) return [];
660
+ return readdirSync2(releasesDir, { withFileTypes: true }).filter((d) => d.isDirectory() && /^v\d+\.\d+\.\d+$/.test(d.name)).map((d) => d.name).sort(compareVersions);
661
+ }
662
+ function compareVersions(a, b) {
663
+ const pa = a.replace(/^v/, "").split(".").map(Number);
664
+ const pb = b.replace(/^v/, "").split(".").map(Number);
665
+ for (let i = 0; i < 3; i++) {
666
+ if (pa[i] !== pb[i]) return pa[i] - pb[i];
667
+ }
668
+ return 0;
669
+ }
670
+ function buildManifestRegistry(dataDir) {
671
+ const knowledgeDir = join3(dataDir, "knowledge");
672
+ const registry = [];
673
+ for (const rel of listReleaseDirs(knowledgeDir)) {
674
+ const files = globSync(join3(knowledgeDir, "releases", rel, "entries", "*.yml")).sort();
675
+ for (const file of files) {
676
+ const entry = parseYaml(readFileSync3(file, "utf-8"));
677
+ registry.push({
678
+ id: entry.id,
679
+ file: relative2(knowledgeDir, file).split("\\").join("/"),
680
+ type: entry.type,
681
+ priority: entry.priority,
682
+ tags: entry.tags,
683
+ domains: entry.domains
684
+ });
685
+ }
686
+ }
687
+ return registry;
688
+ }
689
+ function computeStats(dataDir, registry) {
690
+ const stats = {
691
+ total_entries: registry.length,
692
+ heuristics: 0,
693
+ techniques: 0,
694
+ checklists: 0,
695
+ references: 0,
696
+ domain_profiles: 0,
697
+ custom_entries: 0
698
+ };
699
+ for (const e of registry) {
700
+ const key = TYPE_TO_STAT[e.type];
701
+ if (key) stats[key]++;
702
+ }
703
+ const domainsDir = join3(dataDir, "domains");
704
+ if (existsSync3(domainsDir)) {
705
+ stats.domain_profiles = readdirSync2(domainsDir).filter(
706
+ (f) => f.endsWith(".yml")
707
+ ).length;
708
+ }
709
+ const customDir = join3(dataDir, "knowledge", "custom");
710
+ if (existsSync3(customDir)) {
711
+ stats.custom_entries = readdirSync2(customDir).filter(
712
+ (f) => f.endsWith(".yml")
713
+ ).length;
714
+ }
715
+ return stats;
716
+ }
717
+ function syncKnowledgeManifest(dataDir, opts = {}) {
718
+ const manifestPath = join3(dataDir, "knowledge", "manifest.yml");
719
+ const raw = readFileSync3(manifestPath, "utf-8");
720
+ const doc = parseDocument(raw);
721
+ const registry = buildManifestRegistry(dataDir);
722
+ const stats = computeStats(dataDir, registry);
723
+ const current = parseYaml(raw);
724
+ const inSync = JSON.stringify(current.entries) === JSON.stringify(registry) && JSON.stringify(current.stats) === JSON.stringify(stats);
725
+ if (!opts.check && !inSync) {
726
+ doc.set("stats", stats);
727
+ doc.set("entries", registry);
728
+ doc.set("last_updated", (/* @__PURE__ */ new Date()).toISOString().slice(0, 10));
729
+ writeFileSync2(manifestPath, doc.toString(), "utf-8");
730
+ }
731
+ return { changed: !inSync, stats, entryCount: registry.length };
732
+ }
733
+
734
+ // src/utils/validate.ts
735
+ import { globSync as globSync2 } from "glob";
393
736
  function validateYamlFile(filePath, schema) {
394
- const absPath = resolve2(filePath);
737
+ const absPath = resolve3(filePath);
395
738
  try {
396
- const raw = readFileSync2(absPath, "utf-8");
397
- const data = parseYaml(raw);
739
+ const raw = readFileSync4(absPath, "utf-8");
740
+ const data = parseYaml2(raw);
398
741
  schema.parse(data);
399
742
  return { file: absPath, valid: true };
400
743
  } catch (err) {
@@ -420,21 +763,136 @@ function validateYamlFile(filePath, schema) {
420
763
  };
421
764
  }
422
765
  }
766
+ function validateWithId(filePath, schema) {
767
+ const result = validateYamlFile(filePath, schema);
768
+ if (!result.valid) return result;
769
+ try {
770
+ const data = parseYaml2(readFileSync4(filePath, "utf-8"));
771
+ const stem = basename3(filePath, ".yml");
772
+ if (data.id !== stem) {
773
+ return {
774
+ file: resolve3(filePath),
775
+ valid: false,
776
+ errors: [
777
+ {
778
+ path: "id",
779
+ message: `id "${data.id}" must equal the file name "${stem}"`
780
+ }
781
+ ]
782
+ };
783
+ }
784
+ } catch {
785
+ }
786
+ return result;
787
+ }
423
788
  function validateTargetConfig(filePath) {
424
- return validateYamlFile(filePath, TargetConfigSchema);
789
+ return validateWithId(filePath, TargetConfigSchema);
425
790
  }
426
791
  function validateKnowledgeEntry(filePath) {
427
792
  return validateYamlFile(filePath, KnowledgeEntrySchema);
428
793
  }
429
794
  function validateDomainConfig(filePath) {
430
- return validateYamlFile(filePath, DomainConfigSchema);
795
+ return validateWithId(filePath, DomainConfigSchema);
796
+ }
797
+ function validateKnowledgeBase(dataDir) {
798
+ const results = [];
799
+ const knowledgeDir = resolve3(dataDir, "knowledge");
800
+ const manifestPath = join4(knowledgeDir, "manifest.yml");
801
+ const changelogPath = join4(knowledgeDir, "changelog.yml");
802
+ results.push(validateYamlFile(manifestPath, KnowledgeManifestSchema));
803
+ results.push(validateYamlFile(changelogPath, KnowledgeChangelogSchema));
804
+ const releaseDirs = listReleaseDirs(knowledgeDir);
805
+ for (const rel of releaseDirs) {
806
+ const releasePath = join4(knowledgeDir, "releases", rel, "release.yml");
807
+ const schemaResult = validateYamlFile(releasePath, KnowledgeReleaseSchema);
808
+ const errors = schemaResult.errors ?? [];
809
+ if (schemaResult.valid || errors.length === 0) {
810
+ try {
811
+ const release = parseYaml2(readFileSync4(releasePath, "utf-8"));
812
+ if (`v${release.version}` !== rel) {
813
+ errors.push({
814
+ path: "version",
815
+ message: `version "${release.version}" does not match directory "${rel}"`
816
+ });
817
+ }
818
+ const entryDir = join4(knowledgeDir, "releases", rel, "entries");
819
+ const filesOnDisk = existsSync4(entryDir) ? globSync2(join4(entryDir, "*.yml")).map((f) => basename3(f, ".yml")) : [];
820
+ for (const id of release.entries) {
821
+ if (!filesOnDisk.includes(id)) {
822
+ errors.push({ path: "entries", message: `declared entry "${id}" has no file` });
823
+ }
824
+ }
825
+ for (const id of filesOnDisk) {
826
+ if (!release.entries.includes(id)) {
827
+ errors.push({ path: "entries", message: `entry file "${id}" is not declared` });
828
+ }
829
+ }
830
+ } catch {
831
+ }
832
+ }
833
+ results.push(
834
+ errors.length ? { file: resolve3(releasePath), valid: false, errors } : { file: resolve3(releasePath), valid: true }
835
+ );
836
+ }
837
+ const crossErrors = [];
838
+ try {
839
+ const manifest = parseYaml2(readFileSync4(manifestPath, "utf-8"));
840
+ const registry = buildManifestRegistry(dataDir);
841
+ const stats = computeStats(dataDir, registry);
842
+ const registryIds = new Set(registry.map((e) => e.id));
843
+ if (JSON.stringify(manifest.entries) !== JSON.stringify(registry)) {
844
+ crossErrors.push({
845
+ path: "entries",
846
+ message: "registry is out of sync with the entry files (run `qualiow kb sync`)"
847
+ });
848
+ }
849
+ if (JSON.stringify(manifest.stats) !== JSON.stringify(stats)) {
850
+ crossErrors.push({
851
+ path: "stats",
852
+ message: `stats out of sync (expected total_entries ${stats.total_entries})`
853
+ });
854
+ }
855
+ const activeExpected = [...listReleaseDirs(knowledgeDir)].sort();
856
+ if (JSON.stringify([...manifest.active_releases].sort()) !== JSON.stringify(activeExpected)) {
857
+ crossErrors.push({ path: "active_releases", message: "does not match the release directories" });
858
+ }
859
+ const ls = manifest.loading_strategy;
860
+ const allRefs = [
861
+ ...ls.always,
862
+ ...Object.values(ls.by_domain).flat(),
863
+ ...Object.values(ls.by_tag).flat()
864
+ ];
865
+ for (const id of allRefs) {
866
+ if (!registryIds.has(id)) {
867
+ crossErrors.push({ path: "loading_strategy", message: `references unknown entry "${id}"` });
868
+ }
869
+ }
870
+ const changelog = parseYaml2(readFileSync4(changelogPath, "utf-8"));
871
+ for (const r of changelog.releases) {
872
+ for (const e of r.entries_added) {
873
+ if (!registryIds.has(e.id)) {
874
+ crossErrors.push({ path: "changelog", message: `entry "${e.id}" is not in the registry` });
875
+ }
876
+ }
877
+ }
878
+ } catch (err) {
879
+ crossErrors.push({
880
+ path: "",
881
+ message: err instanceof Error ? err.message : "cross-check failed"
882
+ });
883
+ }
884
+ results.push(
885
+ crossErrors.length ? { file: join4(knowledgeDir, "(cross-check)"), valid: false, errors: crossErrors } : { file: join4(knowledgeDir, "(cross-check)"), valid: true }
886
+ );
887
+ return results;
431
888
  }
432
889
 
433
890
  // src/cli/commands/validate.ts
434
891
  function validateCommand() {
435
- const cmd = new Command2("validate").description("Validate all configuration files").option("--targets", "Validate target configurations only").option("--knowledge", "Validate knowledge entries only").option("--domains", "Validate domain configurations only").option("--all", "Validate all configurations (default)").action(async (options) => {
892
+ const cmd = new Command2("validate").description("Validate configuration files (targets, domains, knowledge entries, knowledge base)").option("--targets", "Validate target configurations (data/targets/*.yml and qa/target.yml)").option("--knowledge", "Validate knowledge entries").option("--domains", "Validate domain configurations").option("--kb", "Cross-check the knowledge base (manifest, releases, changelog)").option("--all", "Validate everything (default)").action(async (options) => {
436
893
  try {
437
- runValidate(options);
894
+ const failed = runValidate(options, process.cwd());
895
+ if (failed > 0) process.exit(1);
438
896
  } catch (err) {
439
897
  console.error(chalk2.red("Error during validation:"), err instanceof Error ? err.message : err);
440
898
  process.exit(1);
@@ -442,58 +900,47 @@ function validateCommand() {
442
900
  });
443
901
  return cmd;
444
902
  }
445
- function runValidate(options) {
446
- const cwd = process.cwd();
447
- const dataDir = resolve3(cwd, "data");
448
- const runAll = options.all || !options.targets && !options.knowledge && !options.domains;
449
- if (!existsSync2(dataDir)) {
450
- console.error(chalk2.red("Error: data/ directory not found. Run `npx qualiow init` first."));
451
- process.exit(1);
903
+ function runValidate(options, cwd) {
904
+ const dataDir = resolve4(cwd, "data");
905
+ const runAll = options.all || !options.targets && !options.knowledge && !options.domains && !options.kb;
906
+ if (!existsSync5(dataDir)) {
907
+ throw new Error("data/ directory not found. Run `npx qualiow init` first.");
452
908
  }
453
909
  const results = [];
454
- if (runAll || options.targets) {
455
- const targetDir = resolve3(dataDir, "targets");
456
- if (existsSync2(targetDir)) {
457
- const files = globSync2(resolve3(targetDir, "*.yml"));
458
- console.log(chalk2.cyan.bold(`
459
- Targets (${files.length} files):`));
460
- for (const file of files) {
461
- const result = validateTargetConfig(file);
462
- results.push(result);
463
- printResult(result, cwd);
464
- }
465
- } else {
466
- console.log(chalk2.yellow("\n No targets/ directory found"));
910
+ const section = (title, files, fn) => {
911
+ console.log(chalk2.cyan.bold(`
912
+ ${title} (${files.length} files):`));
913
+ for (const file of files) {
914
+ const result = fn(file);
915
+ results.push(result);
916
+ printResult(result, cwd);
467
917
  }
918
+ };
919
+ if (runAll || options.targets) {
920
+ const files = globSync3(resolve4(dataDir, "targets", "*.yml")).sort();
921
+ const projectLocal = join5(cwd, "qa", "target.yml");
922
+ if (existsSync5(projectLocal)) files.unshift(projectLocal);
923
+ section("Targets", files, validateTargetConfig);
924
+ }
925
+ if (runAll || options.domains) {
926
+ section("Domains", globSync3(resolve4(dataDir, "domains", "*.yml")).sort(), validateDomainConfig);
468
927
  }
469
928
  if (runAll || options.knowledge) {
470
- const knowledgeDir = resolve3(dataDir, "knowledge");
471
- if (existsSync2(knowledgeDir)) {
472
- const files = globSync2(resolve3(knowledgeDir, "releases", "**", "entries", "*.yml"));
473
- console.log(chalk2.cyan.bold(`
474
- Knowledge entries (${files.length} files):`));
475
- for (const file of files) {
476
- const result = validateKnowledgeEntry(file);
477
- results.push(result);
478
- printResult(result, cwd);
479
- }
480
- } else {
481
- console.log(chalk2.yellow("\n No knowledge/ directory found"));
482
- }
929
+ section(
930
+ "Knowledge entries",
931
+ globSync3(resolve4(dataDir, "knowledge", "releases", "**", "entries", "*.yml")).sort(),
932
+ validateKnowledgeEntry
933
+ );
483
934
  }
484
- if (runAll || options.domains) {
485
- const domainsDir = resolve3(dataDir, "domains");
486
- if (existsSync2(domainsDir)) {
487
- const files = globSync2(resolve3(domainsDir, "*.yml"));
488
- console.log(chalk2.cyan.bold(`
489
- Domains (${files.length} files):`));
490
- for (const file of files) {
491
- const result = validateDomainConfig(file);
935
+ if (runAll || options.kb) {
936
+ if (existsSync5(join5(dataDir, "knowledge", "manifest.yml"))) {
937
+ console.log(chalk2.cyan.bold("\nKnowledge base:"));
938
+ for (const result of validateKnowledgeBase(dataDir)) {
492
939
  results.push(result);
493
940
  printResult(result, cwd);
494
941
  }
495
942
  } else {
496
- console.log(chalk2.yellow("\n No domains/ directory found"));
943
+ console.log(chalk2.yellow("\n No knowledge/manifest.yml found"));
497
944
  }
498
945
  }
499
946
  const total = results.length;
@@ -502,38 +949,121 @@ Domains (${files.length} files):`));
502
949
  console.log("");
503
950
  console.log(chalk2.bold("Summary:"));
504
951
  console.log(
505
- ` ${total} files validated, ${chalk2.green(`${passed} passed`)}, ${failed > 0 ? chalk2.red(`${failed} failed`) : chalk2.green(`${failed} failed`)}`
952
+ ` ${total} checks, ${chalk2.green(`${passed} passed`)}, ${failed > 0 ? chalk2.red(`${failed} failed`) : chalk2.green("0 failed")}`
506
953
  );
507
954
  console.log("");
508
- if (failed > 0) {
509
- process.exit(1);
510
- }
955
+ return failed;
511
956
  }
512
957
  function printResult(result, cwd) {
513
- const relPath = relative(cwd, result.file);
958
+ const relPath = relative3(cwd, result.file);
514
959
  if (result.valid) {
515
960
  console.log(` ${chalk2.green("PASS")} ${relPath}`);
516
961
  } else {
517
962
  console.log(` ${chalk2.red("FAIL")} ${relPath}`);
518
- if (result.errors) {
519
- for (const err of result.errors) {
520
- const pathStr = err.path ? `[${err.path}] ` : "";
521
- console.log(` ${chalk2.red("\u2192")} ${pathStr}${err.message}`);
522
- }
963
+ for (const err of result.errors ?? []) {
964
+ const pathStr = err.path ? `[${err.path}] ` : "";
965
+ console.log(` ${chalk2.red("\u2192")} ${pathStr}${err.message}`);
523
966
  }
524
967
  }
525
968
  }
526
969
 
527
970
  // src/cli/commands/list.ts
528
971
  import { Command as Command3 } from "commander";
529
- import { resolve as resolve4, join as join3 } from "path";
530
- import { existsSync as existsSync3, readFileSync as readFileSync3, readdirSync as readdirSync2 } from "fs";
531
- import { parse as parseYaml2 } from "yaml";
972
+ import { resolve as resolve5, join as join6, basename as basename4 } from "path";
973
+ import { existsSync as existsSync6, readFileSync as readFileSync5, readdirSync as readdirSync3 } from "fs";
974
+ import { parse as parseYaml3 } from "yaml";
975
+ import { globSync as globSync4 } from "glob";
532
976
  import chalk3 from "chalk";
977
+
978
+ // src/utils/markdown-table.ts
979
+ function splitRow(line) {
980
+ const cells = line.split("|").map((c) => c.trim());
981
+ if (cells.length && cells[0] === "") cells.shift();
982
+ if (cells.length && cells[cells.length - 1] === "") cells.pop();
983
+ return cells;
984
+ }
985
+ function isSeparator(line) {
986
+ return /^\s*\|?\s*:?-{2,}/.test(line) && /-\s*\|/.test(line + "|");
987
+ }
988
+ function parseMarkdownTable(md, opts = {}) {
989
+ const lines = md.split("\n");
990
+ let start = 0;
991
+ if (opts.headingPrefix) {
992
+ const prefix = opts.headingPrefix.toLowerCase();
993
+ let found = -1;
994
+ for (let i = 0; i < lines.length; i++) {
995
+ const h = lines[i].match(/^#{1,6}\s+(.*)$/);
996
+ if (h && h[1].trim().toLowerCase().startsWith(prefix)) {
997
+ found = i + 1;
998
+ break;
999
+ }
1000
+ }
1001
+ if (found === -1) return null;
1002
+ start = found;
1003
+ }
1004
+ let headerIdx = -1;
1005
+ for (let i = start; i < lines.length - 1; i++) {
1006
+ const line = lines[i];
1007
+ if (line.includes("|") && isSeparator(lines[i + 1])) {
1008
+ headerIdx = i;
1009
+ break;
1010
+ }
1011
+ if (opts.headingPrefix && /^#{1,6}\s/.test(line) && i > start) {
1012
+ return null;
1013
+ }
1014
+ }
1015
+ if (headerIdx === -1) return null;
1016
+ const headers = splitRow(lines[headerIdx]);
1017
+ const keys = headers.map((h) => h.toLowerCase());
1018
+ const rows = [];
1019
+ for (let i = headerIdx + 2; i < lines.length; i++) {
1020
+ const line = lines[i];
1021
+ if (!line.includes("|")) break;
1022
+ if (isSeparator(line)) continue;
1023
+ const cells = splitRow(line);
1024
+ if (cells.every((c) => c === "")) continue;
1025
+ const row = {};
1026
+ keys.forEach((k, idx) => {
1027
+ row[k] = cells[idx] ?? "";
1028
+ });
1029
+ rows.push(row);
1030
+ }
1031
+ return { headers, rows };
1032
+ }
1033
+
1034
+ // src/utils/session-dir.ts
1035
+ var SESSION_DIR_RE = /^(\d{4}-\d{2}-\d{2}-\d{4})-(explore|quick|mobile|backend)-([a-z0-9][a-z0-9-]*)$/;
1036
+ function slugify(input) {
1037
+ let s = (input ?? "").trim();
1038
+ try {
1039
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(s)) {
1040
+ s = new URL(s).hostname;
1041
+ }
1042
+ } catch {
1043
+ }
1044
+ s = s.toLowerCase().replace(/^_+/, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40).replace(/-+$/g, "");
1045
+ return s || "session";
1046
+ }
1047
+ function pad(n) {
1048
+ return String(n).padStart(2, "0");
1049
+ }
1050
+ function sessionTimestamp(date = /* @__PURE__ */ new Date()) {
1051
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}-${pad(date.getHours())}${pad(date.getMinutes())}`;
1052
+ }
1053
+ function sessionDirName(kind, target, date = /* @__PURE__ */ new Date()) {
1054
+ return `${sessionTimestamp(date)}-${kind}-${slugify(target)}`;
1055
+ }
1056
+ function parseSessionDirName(name) {
1057
+ const m = SESSION_DIR_RE.exec(name);
1058
+ if (!m) return null;
1059
+ return { timestamp: m[1], kind: m[2], slug: m[3] };
1060
+ }
1061
+
1062
+ // src/cli/commands/list.ts
533
1063
  function listCommand() {
534
1064
  const cmd = new Command3("list").description("List sessions, knowledge, targets, or domains").argument("<type>", "What to list: sessions, knowledge, targets, domains").action(async (type) => {
535
1065
  try {
536
- await runList(type);
1066
+ await runList(type, process.cwd());
537
1067
  } catch (err) {
538
1068
  console.error(chalk3.red("Error:"), err instanceof Error ? err.message : err);
539
1069
  process.exit(1);
@@ -541,8 +1071,7 @@ function listCommand() {
541
1071
  });
542
1072
  return cmd;
543
1073
  }
544
- async function runList(type) {
545
- const cwd = process.cwd();
1074
+ async function runList(type, cwd) {
546
1075
  switch (type) {
547
1076
  case "sessions":
548
1077
  listSessions(cwd);
@@ -557,54 +1086,81 @@ async function runList(type) {
557
1086
  listDomains(cwd);
558
1087
  break;
559
1088
  default:
560
- console.error(chalk3.red(`Unknown type: "${type}". Choose from: sessions, knowledge, targets, domains`));
561
- process.exit(1);
1089
+ throw new Error(`Unknown type: "${type}". Choose from: sessions, knowledge, targets, domains`);
562
1090
  }
563
1091
  }
1092
+ function readSessionIndex(indexPath) {
1093
+ if (!existsSync6(indexPath)) return [];
1094
+ const table2 = parseMarkdownTable(readFileSync5(indexPath, "utf-8"));
1095
+ if (!table2) return [];
1096
+ const rows = [];
1097
+ for (const row of table2.rows) {
1098
+ const date = row["date"] ?? "";
1099
+ if (!date || date.startsWith("_")) continue;
1100
+ rows.push({
1101
+ date,
1102
+ kind: row["kind"] ?? "",
1103
+ target: row["target"] ?? "",
1104
+ bugs: row["bugs"] ?? "",
1105
+ duration: row["duration"] ?? "",
1106
+ status: row["status"] ?? "",
1107
+ report: row["report"] ?? row["session directory"] ?? ""
1108
+ });
1109
+ }
1110
+ return rows;
1111
+ }
564
1112
  function listSessions(cwd) {
565
- const indexPath = resolve4(cwd, "output", "sessions", "INDEX.md");
566
- if (!existsSync3(indexPath)) {
567
- console.log(chalk3.yellow("No sessions found. Run `npx qualiow init` first, then start a session."));
1113
+ const sessionsDir = resolve5(cwd, "output", "sessions");
1114
+ const indexPath = join6(sessionsDir, "INDEX.md");
1115
+ if (!existsSync6(sessionsDir)) {
1116
+ console.log(chalk3.yellow("No sessions directory. Run `npx qualiow init` first, then start a session."));
568
1117
  return;
569
1118
  }
570
- const content = readFileSync3(indexPath, "utf-8");
571
- const lines = content.split("\n");
572
- const tableRows = lines.filter(
573
- (line) => line.startsWith("|") && !line.startsWith("|---") && !line.startsWith("| Date") && line.trim() !== ""
574
- );
575
- if (tableRows.length === 0) {
576
- console.log(chalk3.cyan("\nSessions:"));
1119
+ const rows = readSessionIndex(indexPath);
1120
+ const indexedDirs = new Set(rows.map((r) => basename4(r.report.replace(/\/session-report\.md$/, ""))));
1121
+ const unindexed = readdirSync3(sessionsDir, { withFileTypes: true }).filter((d) => d.isDirectory() && SESSION_DIR_RE.test(d.name) && !indexedDirs.has(d.name)).map((d) => d.name).sort();
1122
+ console.log(chalk3.cyan.bold("\nSessions:"));
1123
+ console.log("");
1124
+ if (rows.length === 0 && unindexed.length === 0) {
577
1125
  console.log(chalk3.yellow(" No sessions recorded yet."));
578
- console.log(chalk3.white(" Start one with: npx qualiow explore <url>"));
1126
+ console.log(chalk3.white(" Start one with: /qa-explore <url>"));
1127
+ console.log("");
579
1128
  return;
580
1129
  }
581
- console.log(chalk3.cyan.bold("\nSessions:"));
582
- console.log("");
583
- const header = ` ${pad("Date", 12)} ${pad("Target", 20)} ${pad("Duration", 10)} ${pad("Bugs", 6)} Session Directory`;
584
- console.log(chalk3.bold(header));
585
- console.log(` ${"\u2500".repeat(12)} ${"\u2500".repeat(20)} ${"\u2500".repeat(10)} ${"\u2500".repeat(6)} ${"\u2500".repeat(30)}`);
586
- for (const row of tableRows) {
587
- const cells = row.split("|").map((c) => c.trim()).filter((c) => c !== "");
588
- if (cells.length >= 5) {
589
- console.log(
590
- ` ${pad(cells[0], 12)} ${pad(cells[1], 20)} ${pad(cells[2], 10)} ${pad(cells[3], 6)} ${cells[4]}`
591
- );
592
- }
1130
+ const widths = [16, 8, 22, 5, 9, 12];
1131
+ const header = INDEX_COLUMNS.map((c, i) => i < widths.length ? pad2(c, widths[i]) : c).join(" ");
1132
+ console.log(chalk3.bold(` ${header}`));
1133
+ console.log(` ${widths.map((w) => "\u2500".repeat(w)).join(" ")} ${"\u2500".repeat(30)}`);
1134
+ for (const r of rows) {
1135
+ console.log(
1136
+ ` ${pad2(r.date, 16)} ${pad2(r.kind, 8)} ${pad2(r.target, 22)} ${pad2(r.bugs, 5)} ${pad2(r.duration, 9)} ${pad2(r.status, 12)} ${r.report}`
1137
+ );
1138
+ }
1139
+ for (const d of unindexed) {
1140
+ console.log(chalk3.gray(` ${pad2(d.slice(0, 15), 16)} ${pad2("", 8)} ${pad2("", 22)} ${pad2("", 5)} ${pad2("", 9)} ${pad2("unindexed", 12)} ${d}`));
593
1141
  }
594
1142
  console.log("");
595
- console.log(chalk3.white(` Total: ${tableRows.length} session(s)`));
1143
+ console.log(chalk3.white(` Total: ${rows.length} session(s)` + (unindexed.length ? chalk3.gray(` (+${unindexed.length} unindexed)`) : "")));
596
1144
  console.log("");
597
1145
  }
598
1146
  function listKnowledge(cwd) {
599
- const manifestPath = resolve4(cwd, "data", "knowledge", "manifest.yml");
600
- if (!existsSync3(manifestPath)) {
1147
+ const knowledgeDir = resolve5(cwd, "data", "knowledge");
1148
+ const manifestPath = join6(knowledgeDir, "manifest.yml");
1149
+ if (!existsSync6(manifestPath)) {
601
1150
  console.log(chalk3.yellow("No knowledge base found. Run `npx qualiow init` first."));
602
1151
  return;
603
1152
  }
604
- const raw = readFileSync3(manifestPath, "utf-8");
605
- const manifest = parseYaml2(raw);
1153
+ const manifest = parseYaml3(readFileSync5(manifestPath, "utf-8"));
1154
+ const filesOnDisk = globSync4(join6(knowledgeDir, "releases", "*", "entries", "*.yml")).length;
606
1155
  console.log(chalk3.cyan.bold("\nKnowledge Base:"));
607
- console.log(chalk3.white(` Version: ${manifest.version} | Entries: ${manifest.stats.total_entries}`));
1156
+ console.log(chalk3.white(` Version: ${manifest.version} | Entries: ${manifest.entries.length}`));
1157
+ if (filesOnDisk !== manifest.entries.length || manifest.stats.total_entries !== filesOnDisk) {
1158
+ console.log(
1159
+ chalk3.yellow(
1160
+ ` \u26A0 Registry (${manifest.entries.length}) / stats (${manifest.stats.total_entries}) disagree with ${filesOnDisk} entry files \u2014 run: npx qualiow kb sync`
1161
+ )
1162
+ );
1163
+ }
608
1164
  console.log("");
609
1165
  const grouped = /* @__PURE__ */ new Map();
610
1166
  for (const entry of manifest.entries) {
@@ -617,68 +1173,67 @@ function listKnowledge(cwd) {
617
1173
  for (const entry of entries) {
618
1174
  const priorityColor = entry.priority === "high" ? chalk3.red : entry.priority === "medium" ? chalk3.yellow : chalk3.white;
619
1175
  const tags = entry.tags.map((t) => chalk3.gray(t)).join(", ");
620
- console.log(
621
- ` ${priorityColor(`[${entry.priority}]`)} ${entry.id} ${chalk3.gray("tags:")} ${tags}`
622
- );
1176
+ console.log(` ${priorityColor(`[${entry.priority}]`)} ${entry.id} ${chalk3.gray("tags:")} ${tags}`);
623
1177
  }
624
1178
  console.log("");
625
1179
  }
626
1180
  }
627
1181
  function listTargets(cwd) {
628
- const targetsDir = resolve4(cwd, "data", "targets");
629
- if (!existsSync3(targetsDir)) {
1182
+ const targetsDir = resolve5(cwd, "data", "targets");
1183
+ if (!existsSync6(targetsDir)) {
630
1184
  console.log(chalk3.yellow("No targets found. Run `npx qualiow init` first."));
631
1185
  return;
632
1186
  }
633
- const files = readdirSync2(targetsDir).filter((f) => f.endsWith(".yml"));
634
- if (files.length === 0) {
1187
+ const files = readdirSync3(targetsDir).filter((f) => f.endsWith(".yml")).sort();
1188
+ const projectLocal = resolve5(cwd, "qa", "target.yml");
1189
+ if (files.length === 0 && !existsSync6(projectLocal)) {
635
1190
  console.log(chalk3.yellow("No target configurations found."));
636
1191
  return;
637
1192
  }
638
1193
  console.log(chalk3.cyan.bold("\nTargets:"));
639
1194
  console.log("");
640
- const header = ` ${pad("ID", 22)} ${pad("Name", 35)} ${pad("Domain", 12)} ${pad("Auth", 16)} Base URL`;
1195
+ const header = ` ${pad2("File", 34)} ${pad2("Name", 32)} ${pad2("Domain", 11)} ${pad2("Auth", 16)} Base URL`;
641
1196
  console.log(chalk3.bold(header));
642
- console.log(` ${"\u2500".repeat(22)} ${"\u2500".repeat(35)} ${"\u2500".repeat(12)} ${"\u2500".repeat(16)} ${"\u2500".repeat(30)}`);
643
- for (const file of files) {
1197
+ console.log(` ${"\u2500".repeat(34)} ${"\u2500".repeat(32)} ${"\u2500".repeat(11)} ${"\u2500".repeat(16)} ${"\u2500".repeat(30)}`);
1198
+ const printTarget = (label, path) => {
644
1199
  try {
645
- const raw = readFileSync3(join3(targetsDir, file), "utf-8");
646
- const target = parseYaml2(raw);
1200
+ const target = parseYaml3(readFileSync5(path, "utf-8"));
1201
+ const url = target.base_url || target.web?.base_url || chalk3.gray("(none)");
647
1202
  console.log(
648
- ` ${pad(target.id, 22)} ${pad(target.name, 35)} ${pad(target.domain, 12)} ${pad(target.auth.strategy, 16)} ${target.base_url || chalk3.gray("(none)")}`
1203
+ ` ${pad2(label, 34)} ${pad2(target.name, 32)} ${pad2(target.domain, 11)} ${pad2(target.auth?.strategy ?? "", 16)} ${url}`
649
1204
  );
650
1205
  } catch {
651
- console.log(` ${chalk3.red("ERROR")} Could not parse ${file}`);
1206
+ console.log(` ${chalk3.red("ERROR")} Could not parse ${label}`);
652
1207
  }
653
- }
1208
+ };
1209
+ if (existsSync6(projectLocal)) printTarget("qa/target.yml", projectLocal);
1210
+ for (const file of files) printTarget(`data/targets/${file}`, join6(targetsDir, file));
654
1211
  console.log("");
655
- console.log(chalk3.white(` Total: ${files.length} target(s)`));
1212
+ console.log(chalk3.white(` Total: ${files.length + (existsSync6(projectLocal) ? 1 : 0)} target(s)`));
656
1213
  console.log("");
657
1214
  }
658
1215
  function listDomains(cwd) {
659
- const domainsDir = resolve4(cwd, "data", "domains");
660
- if (!existsSync3(domainsDir)) {
1216
+ const domainsDir = resolve5(cwd, "data", "domains");
1217
+ if (!existsSync6(domainsDir)) {
661
1218
  console.log(chalk3.yellow("No domain configs found. Run `npx qualiow init` first."));
662
1219
  return;
663
1220
  }
664
- const files = readdirSync2(domainsDir).filter((f) => f.endsWith(".yml"));
1221
+ const files = readdirSync3(domainsDir).filter((f) => f.endsWith(".yml")).sort();
665
1222
  if (files.length === 0) {
666
1223
  console.log(chalk3.yellow("No domain configurations found."));
667
1224
  return;
668
1225
  }
669
1226
  console.log(chalk3.cyan.bold("\nDomains:"));
670
1227
  console.log("");
671
- const header = ` ${pad("ID", 16)} ${pad("Name", 28)} ${pad("Checklist", 12)} ${pad("Journeys", 10)}`;
1228
+ const header = ` ${pad2("File", 18)} ${pad2("Name", 32)} ${pad2("Checklist", 10)} ${pad2("Journeys", 9)} ${pad2("Patterns", 9)}`;
672
1229
  console.log(chalk3.bold(header));
673
- console.log(` ${"\u2500".repeat(16)} ${"\u2500".repeat(28)} ${"\u2500".repeat(12)} ${"\u2500".repeat(10)}`);
1230
+ console.log(` ${"\u2500".repeat(18)} ${"\u2500".repeat(32)} ${"\u2500".repeat(10)} ${"\u2500".repeat(9)} ${"\u2500".repeat(9)}`);
674
1231
  for (const file of files) {
675
1232
  try {
676
- const raw = readFileSync3(join3(domainsDir, file), "utf-8");
677
- const domain = parseYaml2(raw);
678
- const checklistCount = domain.completeness_checklist?.length ?? 0;
679
- const journeyCount = domain.journeys?.length ?? 0;
1233
+ const domain = parseYaml3(readFileSync5(join6(domainsDir, file), "utf-8"));
1234
+ const patterns = Object.values(domain.must_test_patterns ?? {}).reduce((n, arr) => n + arr.length, 0);
680
1235
  console.log(
681
- ` ${pad(domain.id, 16)} ${pad(domain.name, 28)} ${pad(String(checklistCount), 12)} ${pad(String(journeyCount), 10)}`
1236
+ ` ${pad2(file, 18)} ${pad2(domain.name, 32)} ${pad2(String(domain.completeness_checklist?.length ?? 0), 10)} ${pad2(String(domain.journeys?.length ?? 0), 9)} ${pad2(String(patterns), 9)}`
682
1237
  );
683
1238
  } catch {
684
1239
  console.log(` ${chalk3.red("ERROR")} Could not parse ${file}`);
@@ -688,27 +1243,23 @@ function listDomains(cwd) {
688
1243
  console.log(chalk3.white(` Total: ${files.length} domain(s)`));
689
1244
  console.log("");
690
1245
  }
691
- function pad(str, len) {
692
- if (str.length >= len) {
693
- return str.slice(0, len);
694
- }
1246
+ function pad2(str, len) {
1247
+ if (str.length >= len) return str.slice(0, len);
695
1248
  return str + " ".repeat(len - str.length);
696
1249
  }
697
1250
 
698
1251
  // src/cli/commands/report.ts
699
1252
  import { Command as Command4 } from "commander";
700
- import { resolve as resolve6, join as join5, basename as basename2 } from "path";
701
- import { existsSync as existsSync6, readdirSync as readdirSync4, writeFileSync as writeFileSync2 } from "fs";
1253
+ import { resolve as resolve6, join as join9, basename as basename6, relative as relative4 } from "path";
1254
+ import { existsSync as existsSync9, readdirSync as readdirSync5, readFileSync as readFileSync8, writeFileSync as writeFileSync3 } from "fs";
702
1255
  import chalk4 from "chalk";
703
1256
 
704
1257
  // src/formatters/html-report.ts
705
- import { readFileSync as readFileSync5, existsSync as existsSync5 } from "fs";
706
- import { resolve as resolve5, extname } from "path";
707
1258
  import Handlebars from "handlebars";
708
1259
 
709
1260
  // src/utils/parse-session.ts
710
- import { readFileSync as readFileSync4, readdirSync as readdirSync3, existsSync as existsSync4 } from "fs";
711
- import { join as join4, basename } from "path";
1261
+ import { readFileSync as readFileSync6, readdirSync as readdirSync4, existsSync as existsSync7 } from "fs";
1262
+ import { join as join7, basename as basename5 } from "path";
712
1263
  var SEVERITY_ORDER = {
713
1264
  critical: 0,
714
1265
  high: 1,
@@ -762,33 +1313,48 @@ function extractNumberedList(text) {
762
1313
  }
763
1314
  return steps;
764
1315
  }
1316
+ function cleanValue(v) {
1317
+ return v.trim().replace(/^`|`$/g, "").trim();
1318
+ }
765
1319
  function extractEvidence(content) {
766
- const screenshots = [];
767
- const console_errors = [];
1320
+ const evidence = {
1321
+ screenshots: [],
1322
+ videos: [],
1323
+ logs: [],
1324
+ console_errors: [],
1325
+ network_failures: []
1326
+ };
768
1327
  const evidenceText = extractSection(content, "Evidence");
769
- if (!evidenceText) {
770
- return { screenshots, console_errors };
771
- }
1328
+ if (!evidenceText) return evidence;
772
1329
  for (const line of evidenceText.split("\n")) {
773
1330
  const trimmed = line.replace(/^[-*]\s*/, "").trim();
774
- if (/screenshot/i.test(trimmed)) {
775
- const pathMatch = trimmed.match(/:\s*(.+)/);
776
- if (pathMatch) {
777
- screenshots.push(pathMatch[1].trim());
778
- }
779
- }
780
- if (/console\s*(error|log)/i.test(trimmed)) {
781
- const msgMatch = trimmed.match(/:\s*(.+)/);
782
- if (msgMatch && !/none/i.test(msgMatch[1])) {
783
- console_errors.push(msgMatch[1].trim());
784
- }
785
- }
786
- }
787
- return { screenshots, console_errors };
1331
+ const value = () => {
1332
+ const m = trimmed.match(/:\s*(.+)/);
1333
+ return m ? cleanValue(m[1]) : "";
1334
+ };
1335
+ const nonEmpty = (v) => v && !/^none\b/i.test(v);
1336
+ if (/^screenshot/i.test(trimmed)) {
1337
+ const v = value();
1338
+ if (nonEmpty(v)) evidence.screenshots.push(v);
1339
+ } else if (/^video/i.test(trimmed)) {
1340
+ const v = value();
1341
+ if (nonEmpty(v)) evidence.videos.push(v);
1342
+ } else if (/^log\b/i.test(trimmed)) {
1343
+ const v = value();
1344
+ if (nonEmpty(v)) evidence.logs.push(v);
1345
+ } else if (/console\s*(error|log)/i.test(trimmed)) {
1346
+ const v = value();
1347
+ if (nonEmpty(v)) evidence.console_errors.push(v);
1348
+ } else if (/network\s*(failure|error|request)/i.test(trimmed)) {
1349
+ const v = value();
1350
+ if (nonEmpty(v)) evidence.network_failures.push(v);
1351
+ }
1352
+ }
1353
+ return evidence;
788
1354
  }
789
1355
  async function parseBugReport(filePath) {
790
- const content = readFileSync4(filePath, "utf-8");
791
- const filename = basename(filePath, ".md");
1356
+ const content = readFileSync6(filePath, "utf-8");
1357
+ const filename = basename5(filePath, ".md");
792
1358
  const id = filename;
793
1359
  let title = "";
794
1360
  let component = "";
@@ -801,6 +1367,10 @@ async function parseBugReport(filePath) {
801
1367
  component = componentMatch[1];
802
1368
  title = title.replace(/^\[[^\]]+\]\s*/, "").trim();
803
1369
  }
1370
+ const componentField = content.match(/\*\*Component:\*\*\s*(.+)/i);
1371
+ if (componentField) {
1372
+ component = cleanValue(componentField[1]);
1373
+ }
804
1374
  if (!component) {
805
1375
  const categoryMatch = content.match(/\|\s*Category\s*\|\s*(.+?)\s*\|/i);
806
1376
  if (categoryMatch) {
@@ -815,8 +1385,14 @@ async function parseBugReport(filePath) {
815
1385
  let url = "";
816
1386
  const urlMatch = content.match(/\*\*URL:\*\*\s*(.+)/i) ?? content.match(/URL:\s*(https?:\/\/[^\s]+)/i);
817
1387
  if (urlMatch) {
818
- url = urlMatch[1].trim();
1388
+ url = cleanValue(urlMatch[1]);
819
1389
  }
1390
+ const priority = cleanValue(content.match(/\*\*Priority:\*\*\s*(.+)/i)?.[1] ?? "");
1391
+ const environment = cleanValue(content.match(/\*\*Environment:\*\*\s*(.+)/i)?.[1] ?? "");
1392
+ const reproduction_rate = cleanValue(
1393
+ content.match(/\*\*Reproduction rate:\*\*\s*(.+)/i)?.[1] ?? ""
1394
+ );
1395
+ const summary = extractSection(content, "Summary").replace(/^>\s*/gm, "").trim();
820
1396
  const expected = extractSection(content, "Expected").replace(/^_.*_\n?/, "").replace(/^>\s*/gm, "").trim();
821
1397
  const actual = extractSection(content, "Actual").replace(/^_.*_\n?/, "").replace(/^>\s*/gm, "").trim();
822
1398
  const stepsSection = extractSection(content, "Steps to Reproduce");
@@ -827,8 +1403,12 @@ async function parseBugReport(filePath) {
827
1403
  id,
828
1404
  title,
829
1405
  severity,
1406
+ priority,
830
1407
  component,
831
1408
  url,
1409
+ environment,
1410
+ reproduction_rate,
1411
+ summary,
832
1412
  expected,
833
1413
  actual,
834
1414
  steps,
@@ -837,33 +1417,33 @@ async function parseBugReport(filePath) {
837
1417
  };
838
1418
  }
839
1419
  async function parseSession(sessionDir) {
840
- const id = basename(sessionDir);
1420
+ const id = basename5(sessionDir);
841
1421
  let charter;
842
- const charterPath = join4(sessionDir, "charter.md");
843
- if (existsSync4(charterPath)) {
844
- charter = readFileSync4(charterPath, "utf-8");
1422
+ const charterPath = join7(sessionDir, "charter.md");
1423
+ if (existsSync7(charterPath)) {
1424
+ charter = readFileSync6(charterPath, "utf-8");
845
1425
  }
846
1426
  let report;
847
- const reportPath = join4(sessionDir, "session-report.md");
848
- if (existsSync4(reportPath)) {
849
- report = readFileSync4(reportPath, "utf-8");
1427
+ const reportPath = join7(sessionDir, "session-report.md");
1428
+ if (existsSync7(reportPath)) {
1429
+ report = readFileSync6(reportPath, "utf-8");
850
1430
  }
851
1431
  const phases = [];
852
- if (existsSync4(sessionDir)) {
853
- const files = readdirSync3(sessionDir);
1432
+ if (existsSync7(sessionDir)) {
1433
+ const files = readdirSync4(sessionDir);
854
1434
  const phaseFiles = files.filter((f) => /^phase-\d+/i.test(f)).sort();
855
1435
  for (const file of phaseFiles) {
856
- const content = readFileSync4(join4(sessionDir, file), "utf-8");
1436
+ const content = readFileSync6(join7(sessionDir, file), "utf-8");
857
1437
  const name = file.replace(/\.md$/, "");
858
1438
  phases.push({ name, content });
859
1439
  }
860
1440
  }
861
- const bugsDir = join4(sessionDir, "bugs");
1441
+ const bugsDir = join7(sessionDir, "bugs");
862
1442
  const bugs = [];
863
- if (existsSync4(bugsDir)) {
864
- const bugFiles = readdirSync3(bugsDir).filter((f) => /^BUG-.*\.md$/i.test(f)).sort();
1443
+ if (existsSync7(bugsDir)) {
1444
+ const bugFiles = readdirSync4(bugsDir).filter((f) => /^BUG-.*\.md$/i.test(f)).sort();
865
1445
  for (const file of bugFiles) {
866
- const bug = await parseBugReport(join4(bugsDir, file));
1446
+ const bug = await parseBugReport(join7(bugsDir, file));
867
1447
  bugs.push(bug);
868
1448
  }
869
1449
  }
@@ -877,7 +1457,164 @@ async function parseSession(sessionDir) {
877
1457
  };
878
1458
  }
879
1459
 
880
- // src/formatters/html-report.ts
1460
+ // src/utils/redact.ts
1461
+ var EMAIL_ALLOW = /(?:@|\.)(?:example\.(?:com|org|net)|localhost)$/i;
1462
+ function luhnValid(digits) {
1463
+ let sum = 0;
1464
+ let alt = false;
1465
+ for (let i = digits.length - 1; i >= 0; i--) {
1466
+ let d = digits.charCodeAt(i) - 48;
1467
+ if (d < 0 || d > 9) return false;
1468
+ if (alt) {
1469
+ d *= 2;
1470
+ if (d > 9) d -= 9;
1471
+ }
1472
+ sum += d;
1473
+ alt = !alt;
1474
+ }
1475
+ return sum % 10 === 0;
1476
+ }
1477
+ var RULES = [
1478
+ {
1479
+ name: "Private key",
1480
+ pattern: /-----BEGIN (?:[A-Z0-9 ]+ )?PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z0-9 ]+ )?PRIVATE KEY-----/g,
1481
+ replacement: "[PRIVATE_KEY_REDACTED]"
1482
+ },
1483
+ {
1484
+ name: "JWT",
1485
+ pattern: /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{6,}\.[A-Za-z0-9_-]{6,}\b/g,
1486
+ replacement: "[JWT_REDACTED]"
1487
+ },
1488
+ {
1489
+ name: "Authorization header",
1490
+ pattern: /(authorization)(\s*[:=]\s*)(\S[^\n\r]*)/gi,
1491
+ replace: (m, k, sep, value) => /_REDACTED\]/.test(value) ? m : `${k}${sep}[REDACTED]`
1492
+ },
1493
+ {
1494
+ name: "Cookie header",
1495
+ pattern: /^(set-cookie|cookie)(\s*:\s*).+$/gim,
1496
+ replace: (_m, k, sep) => `${k}${sep}[REDACTED]`
1497
+ },
1498
+ {
1499
+ name: "AWS access key id",
1500
+ pattern: /\b(?:AKIA|ASIA|AROA|AIDA)[0-9A-Z]{16}\b/g,
1501
+ replacement: "[AWS_KEY_REDACTED]"
1502
+ },
1503
+ {
1504
+ name: "AWS secret access key",
1505
+ pattern: /(aws_secret_access_key)(\s*[:=]\s*)\S+/gi,
1506
+ replace: (_m, k, sep) => `${k}${sep}[REDACTED]`
1507
+ },
1508
+ {
1509
+ name: "OpenAI-style key",
1510
+ pattern: /\bsk-(?:proj-)?[A-Za-z0-9_-]{20,}\b/g,
1511
+ replacement: "[SK_KEY_REDACTED]"
1512
+ },
1513
+ {
1514
+ name: "GitHub token",
1515
+ pattern: /\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,})\b/g,
1516
+ replacement: "[GITHUB_TOKEN_REDACTED]"
1517
+ },
1518
+ {
1519
+ name: "Slack token",
1520
+ pattern: /\bxox[abposr]-[A-Za-z0-9-]{10,}\b/g,
1521
+ replacement: "[SLACK_TOKEN_REDACTED]"
1522
+ },
1523
+ {
1524
+ name: "API key",
1525
+ pattern: /(x-api-key|api[_-]?key)(\s*[:=]\s*)["']?[A-Za-z0-9._-]{8,}["']?/gi,
1526
+ replace: (_m, k, sep) => `${k}${sep}[REDACTED]`
1527
+ },
1528
+ {
1529
+ name: "Password",
1530
+ pattern: /(password|passwd|pwd)(\s*[:=]\s*)["']?[^\s,}"']+["']?/gi,
1531
+ replace: (_m, k, sep) => `${k}${sep}[REDACTED]`
1532
+ },
1533
+ {
1534
+ name: "Token",
1535
+ pattern: /(access[_-]?token|refresh[_-]?token|token)(\s*[:=]\s*)["']?[A-Za-z0-9._-]{8,}["']?/gi,
1536
+ replace: (_m, k, sep) => `${k}${sep}[REDACTED]`
1537
+ },
1538
+ {
1539
+ name: "Secret",
1540
+ pattern: /([a-z_]*secret)(\s*[:=]\s*)["']?[^\s,}"']+["']?/gi,
1541
+ replace: (_m, k, sep) => `${k}${sep}[REDACTED]`
1542
+ },
1543
+ {
1544
+ name: "SSN",
1545
+ pattern: /\b\d{3}-\d{2}-\d{4}\b/g,
1546
+ replacement: "[SSN_REDACTED]"
1547
+ },
1548
+ {
1549
+ name: "Credit card number",
1550
+ pattern: /\b\d(?:[ -]?\d){12,18}\b/g,
1551
+ replace: (match) => {
1552
+ const digits = match.replace(/\D/g, "");
1553
+ if (digits.length < 13 || digits.length > 19) return match;
1554
+ if (!/^[3-6]/.test(digits)) return match;
1555
+ return luhnValid(digits) ? "[CARD_NUMBER_REDACTED]" : match;
1556
+ }
1557
+ }
1558
+ ];
1559
+ function redact(text, opts = {}) {
1560
+ const redactions = /* @__PURE__ */ new Set();
1561
+ let result = text;
1562
+ const rules = RULES.slice();
1563
+ if (opts.emails !== false) {
1564
+ rules.push({
1565
+ name: "Email",
1566
+ pattern: /\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b/g,
1567
+ replace: (match) => EMAIL_ALLOW.test(match) ? match : "[EMAIL_REDACTED]"
1568
+ });
1569
+ }
1570
+ for (const rule of rules) {
1571
+ rule.pattern.lastIndex = 0;
1572
+ let fired = false;
1573
+ result = result.replace(rule.pattern, (...args) => {
1574
+ const match = args[0];
1575
+ const groups = args.slice(1, -2);
1576
+ const out = rule.replace ? rule.replace(match, ...groups) : rule.replacement;
1577
+ if (out !== match) fired = true;
1578
+ return out;
1579
+ });
1580
+ if (fired) redactions.add(rule.name);
1581
+ }
1582
+ return { text: result, redactions: [...redactions] };
1583
+ }
1584
+ var REDACTION_CATEGORIES = RULES.map((r) => r.name).concat("Email");
1585
+
1586
+ // src/formatters/common.ts
1587
+ function redactString(s) {
1588
+ return s ? redact(s).text : s;
1589
+ }
1590
+ function redactBug(bug) {
1591
+ return {
1592
+ ...bug,
1593
+ title: redactString(bug.title),
1594
+ url: redactString(bug.url),
1595
+ environment: redactString(bug.environment),
1596
+ summary: redactString(bug.summary),
1597
+ expected: redactString(bug.expected),
1598
+ actual: redactString(bug.actual),
1599
+ steps: bug.steps.map(redactString),
1600
+ business_impact: redactString(bug.business_impact),
1601
+ evidence: {
1602
+ screenshots: bug.evidence.screenshots.map(redactString),
1603
+ videos: bug.evidence.videos.map(redactString),
1604
+ logs: bug.evidence.logs.map(redactString),
1605
+ console_errors: bug.evidence.console_errors.map(redactString),
1606
+ network_failures: bug.evidence.network_failures.map(redactString)
1607
+ }
1608
+ };
1609
+ }
1610
+ async function loadSessionForOutput(sessionDir) {
1611
+ const session = await parseSession(sessionDir);
1612
+ const report = session.report ? redact(session.report).text : "";
1613
+ return {
1614
+ session: { ...session, bugs: session.bugs.map(redactBug), report },
1615
+ report
1616
+ };
1617
+ }
881
1618
  function extractReportMeta(report, sessionId) {
882
1619
  const meta = {
883
1620
  target: sessionId,
@@ -892,40 +1629,34 @@ function extractReportMeta(report, sessionId) {
892
1629
  if (durationMatch) meta.duration = durationMatch[1].trim();
893
1630
  const targetMatch = report.match(/\*\*Application:\*\*\s*(.+)/i) ?? report.match(/\*\*Target:\*\*\s*(.+)/i) ?? report.match(/\|\s*Target\s*\|\s*(.+?)\s*\|/i);
894
1631
  if (targetMatch) meta.target = targetMatch[1].trim();
895
- const summaryMatch = report.match(/##\s+Executive Summary\s*\n+([\s\S]*?)(?=\n##\s|\n---)/i);
1632
+ const summaryMatch = report.match(
1633
+ /##\s+Executive Summary\s*\n+([\s\S]*?)(?=\n##\s|\n---|$)/i
1634
+ );
896
1635
  if (summaryMatch) meta.summary = summaryMatch[1].trim();
897
1636
  return meta;
898
1637
  }
899
1638
  function extractCoverage(report) {
900
- const entries = [];
901
- const tableMatch = report.match(
902
- /\|\s*Area\s*\|\s*Status\s*\|[\s\S]*?\n((?:\|.+\|.+\n?)+)/i
903
- );
904
- if (!tableMatch) return entries;
905
- const rows = tableMatch[1].split("\n").filter((r) => r.trim().startsWith("|"));
906
- for (const row of rows) {
907
- const cells = row.split("|").map((c) => c.trim()).filter(Boolean);
908
- if (cells.length >= 2 && !cells[0].startsWith("---")) {
909
- entries.push({
910
- area: cells[0] || "",
911
- status: cells[1] || "",
912
- bugsFound: cells[3] || "0",
913
- notes: cells[4] || ""
914
- });
915
- }
916
- }
917
- return entries;
1639
+ const table2 = parseMarkdownTable(report, { headingPrefix: "Coverage" });
1640
+ if (!table2) return [];
1641
+ return table2.rows.map((row) => ({
1642
+ area: row["area"] ?? "",
1643
+ risk: row["risk"] ?? "",
1644
+ status: row["status"] ?? row["tested?"] ?? row["tested"] ?? "",
1645
+ bugsFound: row["bugs"] ?? row["bugs found"] ?? row["findings"] ?? "0",
1646
+ notes: row["notes"] ?? ""
1647
+ }));
918
1648
  }
919
1649
  function extractListSection(report, heading) {
920
1650
  const items = [];
921
- const regex = new RegExp(`##\\s+${heading}\\s*\\n+([\\s\\S]*?)(?=\\n##\\s|\\n---|$)`, "i");
1651
+ const regex = new RegExp(
1652
+ `##\\s+${heading}\\s*\\n+([\\s\\S]*?)(?=\\n##\\s|\\n---|$)`,
1653
+ "i"
1654
+ );
922
1655
  const match = report.match(regex);
923
1656
  if (!match) return items;
924
1657
  for (const line of match[1].split("\n")) {
925
1658
  const itemMatch = line.match(/^[-*]\s+(?:\[.\]\s+)?(.+)/);
926
- if (itemMatch) {
927
- items.push(itemMatch[1].trim());
928
- }
1659
+ if (itemMatch) items.push(itemMatch[1].trim());
929
1660
  const numberedMatch = line.match(/^\d+\.\s+\*\*(.+?)\*\*\s*(.+)?/);
930
1661
  if (numberedMatch) {
931
1662
  const text = numberedMatch[2] ? `${numberedMatch[1]} ${numberedMatch[2]}` : numberedMatch[1];
@@ -934,11 +1665,25 @@ function extractListSection(report, heading) {
934
1665
  }
935
1666
  return items;
936
1667
  }
1668
+
1669
+ // src/utils/confidentiality.ts
1670
+ var CONFIDENTIALITY_LINES = [
1671
+ "CONFIDENTIAL: This report may contain internal URLs, security vulnerabilities,",
1672
+ "and application details. Do not share outside your organization without review."
1673
+ ];
1674
+ var CONFIDENTIALITY_HEADER_MD = CONFIDENTIALITY_LINES.map(
1675
+ (l) => `> ${l}`
1676
+ ).join("\n");
1677
+ var CONFIDENTIALITY_NOTICE = CONFIDENTIALITY_LINES.join(" ");
1678
+
1679
+ // src/formatters/html-report.ts
937
1680
  var HTML_TEMPLATE = `<!DOCTYPE html>
938
1681
  <html lang="en">
939
1682
  <head>
940
1683
  <meta charset="UTF-8">
941
1684
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
1685
+ <meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'; img-src data:">
1686
+ <meta name="robots" content="noindex, nofollow">
942
1687
  <title>Qualiow Report \u2014 {{meta.target}}</title>
943
1688
  <style>
944
1689
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
@@ -954,17 +1699,6 @@ var HTML_TEMPLATE = `<!DOCTYPE html>
954
1699
  a { color: #3498db; text-decoration: none; }
955
1700
  a:hover { text-decoration: underline; }
956
1701
 
957
- .screenshot-container { margin: 0.75rem 0; }
958
- .screenshot-img {
959
- max-width: 100%;
960
- border-radius: 6px;
961
- border: 1px solid #1e2a3a;
962
- cursor: pointer;
963
- transition: transform 0.2s;
964
- }
965
- .screenshot-img:hover { transform: scale(1.02); }
966
- .screenshot-label { font-size: 0.8rem; color: #8899aa; margin-top: 0.25rem; }
967
-
968
1702
  .container { max-width: 960px; margin: 0 auto; }
969
1703
 
970
1704
  /* Header */
@@ -1143,6 +1877,18 @@ var HTML_TEMPLATE = `<!DOCTYPE html>
1143
1877
  margin-bottom: 0.35rem;
1144
1878
  }
1145
1879
 
1880
+ /* Confidentiality banner */
1881
+ .confidential {
1882
+ background: #2a1a1a;
1883
+ border: 1px solid #663333;
1884
+ color: #e0b0b0;
1885
+ border-radius: 6px;
1886
+ padding: 0.6rem 1rem;
1887
+ font-size: 0.8rem;
1888
+ margin-bottom: 1.5rem;
1889
+ letter-spacing: 0.02em;
1890
+ }
1891
+
1146
1892
  /* Footer */
1147
1893
  .footer {
1148
1894
  margin-top: 3rem;
@@ -1189,6 +1935,8 @@ var HTML_TEMPLATE = `<!DOCTYPE html>
1189
1935
  <body>
1190
1936
  <div class="container">
1191
1937
 
1938
+ <div class="confidential">{{confidentialityNotice}}</div>
1939
+
1192
1940
  <div class="header">
1193
1941
  <h1>Exploratory Testing Report</h1>
1194
1942
  <div class="meta">
@@ -1252,11 +2000,8 @@ var HTML_TEMPLATE = `<!DOCTYPE html>
1252
2000
 
1253
2001
  {{#if this.hasEvidence}}
1254
2002
  <div class="bug-section-label">Evidence</div>
1255
- {{#each this.embeddedScreenshots}}
1256
- <div class="screenshot-container">
1257
- <img src="{{this.dataUri}}" alt="{{this.filename}}" class="screenshot-img" />
1258
- <p class="screenshot-label">{{this.filename}}</p>
1259
- </div>
2003
+ {{#each this.evidence.screenshots}}
2004
+ <p class="evidence-item">Screenshot: {{this}}</p>
1260
2005
  {{/each}}
1261
2006
  {{#each this.evidence.console_errors}}
1262
2007
  <p class="evidence-item">Console: {{this}}</p>
@@ -1312,7 +2057,7 @@ var HTML_TEMPLATE = `<!DOCTYPE html>
1312
2057
  {{/if}}
1313
2058
 
1314
2059
  <div class="footer">
1315
- Generated by Qualiow Exploratory Testing
2060
+ Generated by Qualiow Exploratory Testing \xB7 CONFIDENTIAL \u2014 internal use only
1316
2061
  </div>
1317
2062
 
1318
2063
  </div>
@@ -1320,8 +2065,7 @@ var HTML_TEMPLATE = `<!DOCTYPE html>
1320
2065
  </html>`;
1321
2066
  var compiledTemplate = Handlebars.compile(HTML_TEMPLATE);
1322
2067
  async function generateHtmlReport(sessionDir) {
1323
- const session = await parseSession(sessionDir);
1324
- const report = session.report ?? "";
2068
+ const { session, report } = await loadSessionForOutput(sessionDir);
1325
2069
  const meta = extractReportMeta(report, session.id);
1326
2070
  const coverage = extractCoverage(report);
1327
2071
  const observations = extractListSection(report, "Observations");
@@ -1330,39 +2074,14 @@ async function generateHtmlReport(sessionDir) {
1330
2074
  for (const bug of session.bugs) {
1331
2075
  counts[bug.severity]++;
1332
2076
  }
1333
- const bugsForTemplate = session.bugs.map((bug) => {
1334
- const embeddedScreenshots = bug.evidence.screenshots.map((screenshotRef) => {
1335
- const cleaned = screenshotRef.replace(/`/g, "").replace(/\s*\(.*?\)\s*$/, "").trim();
1336
- const possiblePaths = [
1337
- resolve5(sessionDir, cleaned),
1338
- resolve5(sessionDir, "screenshots", cleaned),
1339
- resolve5(sessionDir, cleaned.replace(/^screenshots\//, "")),
1340
- resolve5(sessionDir, "screenshots", cleaned.replace(/^screenshots\//, ""))
1341
- ];
1342
- for (const imgPath of possiblePaths) {
1343
- if (existsSync5(imgPath)) {
1344
- try {
1345
- const ext = extname(imgPath).toLowerCase().replace(".", "");
1346
- const mime = ext === "jpg" ? "image/jpeg" : `image/${ext || "png"}`;
1347
- const data = readFileSync5(imgPath).toString("base64");
1348
- const filename = imgPath.split("/").pop() || screenshotRef;
1349
- return { dataUri: `data:${mime};base64,${data}`, filename };
1350
- } catch {
1351
- return null;
1352
- }
1353
- }
1354
- }
1355
- return null;
1356
- }).filter(Boolean);
1357
- return {
1358
- ...bug,
1359
- business_impact_summary: summarizeBusinessImpact(bug.business_impact),
1360
- hasEvidence: embeddedScreenshots.length > 0 || bug.evidence.console_errors.length > 0,
1361
- embeddedScreenshots
1362
- };
1363
- });
2077
+ const bugsForTemplate = session.bugs.map((bug) => ({
2078
+ ...bug,
2079
+ business_impact_summary: summarizeBusinessImpact(bug.business_impact),
2080
+ hasEvidence: bug.evidence.screenshots.length > 0 || bug.evidence.console_errors.length > 0
2081
+ }));
1364
2082
  const html = compiledTemplate({
1365
2083
  meta,
2084
+ confidentialityNotice: CONFIDENTIALITY_NOTICE,
1366
2085
  totalBugs: session.bugs.length,
1367
2086
  criticalCount: counts.critical,
1368
2087
  highCount: counts.high,
@@ -1392,8 +2111,7 @@ function summarizeBusinessImpact(impact) {
1392
2111
  function extractTarget(report, sessionId) {
1393
2112
  const match = report.match(/\*\*Application:\*\*\s*(.+)/i) ?? report.match(/\*\*Target:\*\*\s*(.+)/i) ?? report.match(/\|\s*Target\s*\|\s*(.+?)\s*\|/i);
1394
2113
  if (match) return match[1].trim();
1395
- const parts = sessionId.split("-");
1396
- return parts[parts.length - 1] || sessionId;
2114
+ return parseSessionDirName(sessionId)?.slug ?? sessionId;
1397
2115
  }
1398
2116
  function extractDate(report) {
1399
2117
  const match = report.match(/\*\*Date:\*\*\s*(\d{4}-\d{2}-\d{2})/i) ?? report.match(/\|\s*Date\s*\|\s*(\d{4}-\d{2}-\d{2})\s*\|/i);
@@ -1407,64 +2125,33 @@ function extractPagesExplored(report) {
1407
2125
  const match = report.match(/Pages\s+Explored\s*\|\s*(\d+)/i);
1408
2126
  return match ? parseInt(match[1], 10) : 0;
1409
2127
  }
1410
- function extractCoverage2(report) {
1411
- const entries = [];
1412
- const tableMatch = report.match(
1413
- /\|\s*Area\s*\|\s*Status\s*\|[\s\S]*?\n((?:\|.+\|.+\n?)+)/i
1414
- );
1415
- if (!tableMatch) return entries;
1416
- const rows = tableMatch[1].split("\n").filter((r) => r.trim().startsWith("|"));
1417
- for (const row of rows) {
1418
- const cells = row.split("|").map((c) => c.trim()).filter(Boolean);
1419
- if (cells.length >= 2 && !cells[0].startsWith("---")) {
1420
- entries.push({
1421
- area: cells[0] || "",
1422
- status: cells[1] || "",
1423
- bugs_found: parseInt(cells[3] || "0", 10) || 0,
1424
- notes: cells[4] || ""
1425
- });
1426
- }
1427
- }
1428
- return entries;
1429
- }
1430
- function extractListSection2(report, heading) {
1431
- const items = [];
1432
- const regex = new RegExp(`##\\s+${heading}\\s*\\n+([\\s\\S]*?)(?=\\n##\\s|\\n---|$)`, "i");
1433
- const match = report.match(regex);
1434
- if (!match) return items;
1435
- for (const line of match[1].split("\n")) {
1436
- const itemMatch = line.match(/^[-*]\s+(?:\[.\]\s+)?(.+)/);
1437
- if (itemMatch) {
1438
- items.push(itemMatch[1].trim());
1439
- }
1440
- const numberedMatch = line.match(/^\d+\.\s+\*\*(.+?)\*\*\s*(.+)?/);
1441
- if (numberedMatch) {
1442
- const text = numberedMatch[2] ? `${numberedMatch[1]} ${numberedMatch[2]}` : numberedMatch[1];
1443
- items.push(text.replace(/\s*--\s*/, " -- "));
1444
- }
1445
- }
1446
- return items;
1447
- }
1448
2128
  async function generateJsonReport(sessionDir) {
1449
- const session = await parseSession(sessionDir);
1450
- const report = session.report ?? "";
1451
- const target = extractTarget(report, session.id);
1452
- const date = extractDate(report);
1453
- const duration_min = extractDuration(report);
1454
- const pages_explored = extractPagesExplored(report);
2129
+ const { session, report } = await loadSessionForOutput(sessionDir);
1455
2130
  const counts = { critical: 0, high: 0, medium: 0, low: 0 };
1456
2131
  for (const bug of session.bugs) {
1457
2132
  counts[bug.severity]++;
1458
2133
  }
1459
- const coverage = extractCoverage2(report);
1460
- const observations = extractListSection2(report, "Observations");
1461
- const recommendations = extractListSection2(report, "Recommendations");
2134
+ const coverage = extractCoverage(report).map((c) => ({
2135
+ area: c.area,
2136
+ risk: c.risk,
2137
+ status: c.status,
2138
+ bugs_found: parseInt(c.bugsFound, 10) || 0,
2139
+ notes: c.notes
2140
+ }));
1462
2141
  return {
2142
+ meta: {
2143
+ classification: "CONFIDENTIAL",
2144
+ notice: CONFIDENTIALITY_NOTICE,
2145
+ generated_by: `qualiow-exploratory-testing ${getPackageVersion()}`,
2146
+ generated_at: (/* @__PURE__ */ new Date()).toISOString(),
2147
+ redacted: true
2148
+ },
1463
2149
  session: {
1464
2150
  id: session.id,
1465
- target,
1466
- date,
1467
- duration_min
2151
+ kind: parseSessionDirName(session.id)?.kind ?? null,
2152
+ target: extractTarget(report, session.id),
2153
+ date: extractDate(report),
2154
+ duration_min: extractDuration(report)
1468
2155
  },
1469
2156
  summary: {
1470
2157
  total_bugs: session.bugs.length,
@@ -1472,21 +2159,25 @@ async function generateJsonReport(sessionDir) {
1472
2159
  high: counts.high,
1473
2160
  medium: counts.medium,
1474
2161
  low: counts.low,
1475
- pages_explored
2162
+ pages_explored: extractPagesExplored(report)
1476
2163
  },
1477
2164
  bugs: session.bugs.map((bug) => ({
1478
2165
  id: bug.id,
1479
2166
  title: bug.title,
1480
2167
  severity: bug.severity,
2168
+ priority: bug.priority,
1481
2169
  component: bug.component,
1482
2170
  url: bug.url,
2171
+ environment: bug.environment,
2172
+ reproduction_rate: bug.reproduction_rate,
2173
+ summary: bug.summary,
1483
2174
  business_impact: bug.business_impact,
1484
2175
  steps: bug.steps,
1485
2176
  evidence: bug.evidence
1486
2177
  })),
1487
2178
  coverage,
1488
- observations,
1489
- recommendations
2179
+ observations: extractListSection(report, "Observations"),
2180
+ recommendations: extractListSection(report, "Recommendations")
1490
2181
  };
1491
2182
  }
1492
2183
 
@@ -1499,53 +2190,49 @@ var SEVERITY_TO_JIRA_PRIORITY = {
1499
2190
  };
1500
2191
  function csvEscape(value) {
1501
2192
  if (!value) return '""';
1502
- const escaped = value.replace(/"/g, '""');
1503
- return `"${escaped}"`;
2193
+ let v = value;
2194
+ if (/^[=+\-@\t\r]/.test(v)) v = `'${v}`;
2195
+ return `"${v.replace(/"/g, '""')}"`;
1504
2196
  }
1505
2197
  function formatDescription(bug) {
1506
2198
  const parts = [];
2199
+ if (bug.summary) {
2200
+ parts.push(bug.summary, "");
2201
+ }
1507
2202
  if (bug.steps.length > 0) {
1508
2203
  parts.push("h3. Steps to Reproduce");
1509
- for (const step of bug.steps) {
1510
- parts.push(`# ${step}`);
1511
- }
2204
+ for (const step of bug.steps) parts.push(`# ${step}`);
1512
2205
  parts.push("");
1513
2206
  }
1514
2207
  if (bug.expected) {
1515
- parts.push(`h3. Expected Behavior`);
1516
- parts.push(bug.expected);
1517
- parts.push("");
2208
+ parts.push("h3. Expected Behavior", bug.expected, "");
1518
2209
  }
1519
2210
  if (bug.actual) {
1520
- parts.push(`h3. Actual Behavior`);
1521
- parts.push(bug.actual);
1522
- parts.push("");
2211
+ parts.push("h3. Actual Behavior", bug.actual, "");
1523
2212
  }
1524
2213
  if (bug.business_impact) {
1525
- parts.push("h3. Business Impact");
1526
- parts.push(bug.business_impact);
1527
- parts.push("");
2214
+ parts.push("h3. Business Impact", bug.business_impact, "");
2215
+ }
2216
+ if (bug.environment) {
2217
+ parts.push("h3. Environment", bug.environment, "");
1528
2218
  }
1529
2219
  if (bug.url) {
1530
- parts.push(`h3. URL`);
1531
- parts.push(bug.url);
2220
+ parts.push("h3. URL", bug.url, "");
1532
2221
  }
2222
+ parts.push(`_${CONFIDENTIALITY_NOTICE}_`);
1533
2223
  return parts.join("\n");
1534
2224
  }
1535
- function extractDomain(sessionId) {
1536
- return "general";
1537
- }
1538
2225
  async function generateJiraExport(sessionDir) {
1539
- const session = await parseSession(sessionDir);
2226
+ const { session } = await loadSessionForOutput(sessionDir);
1540
2227
  const headers = ["Summary", "Priority", "Description", "Component", "Labels"];
1541
2228
  const rows = [headers.join(",")];
1542
- const domain = extractDomain(session.id);
2229
+ const kind = parseSessionDirName(session.id)?.kind ?? "";
1543
2230
  for (const bug of session.bugs) {
1544
2231
  const summary = `${bug.id}: ${bug.title}`;
1545
2232
  const priority = SEVERITY_TO_JIRA_PRIORITY[bug.severity] ?? "Major";
1546
2233
  const description = formatDescription(bug);
1547
2234
  const component = bug.component || "";
1548
- const labels = ["qualiow", "exploratory-testing", domain].filter(Boolean).join(" ");
2235
+ const labels = ["qualiow", "exploratory-testing", kind].filter(Boolean).join(" ");
1549
2236
  rows.push(
1550
2237
  [
1551
2238
  csvEscape(summary),
@@ -1559,11 +2246,139 @@ async function generateJiraExport(sessionDir) {
1559
2246
  return rows.join("\n");
1560
2247
  }
1561
2248
 
2249
+ // src/formatters/markdown-summary.ts
2250
+ var SEVERITY_LABEL = {
2251
+ critical: "Critical",
2252
+ high: "High",
2253
+ medium: "Medium",
2254
+ low: "Low"
2255
+ };
2256
+ async function generateMarkdownSummary(sessionDir) {
2257
+ const { session, report } = await loadSessionForOutput(sessionDir);
2258
+ const meta = extractReportMeta(report, session.id);
2259
+ const counts = { critical: 0, high: 0, medium: 0, low: 0 };
2260
+ for (const bug of session.bugs) counts[bug.severity]++;
2261
+ const lines = [];
2262
+ lines.push(CONFIDENTIALITY_HEADER_MD, "");
2263
+ lines.push(`# Session Summary \u2014 ${meta.target}`, "");
2264
+ lines.push("| Field | Value |", "|---|---|");
2265
+ lines.push(`| Session | ${session.id} |`);
2266
+ if (meta.date) lines.push(`| Date | ${meta.date} |`);
2267
+ if (meta.duration) lines.push(`| Duration | ${meta.duration} |`);
2268
+ lines.push(
2269
+ `| Bugs | ${session.bugs.length} (Critical ${counts.critical} \xB7 High ${counts.high} \xB7 Medium ${counts.medium} \xB7 Low ${counts.low}) |`,
2270
+ ""
2271
+ );
2272
+ if (meta.summary) {
2273
+ lines.push("## Executive Summary", "", meta.summary, "");
2274
+ }
2275
+ if (session.bugs.length) {
2276
+ lines.push("## Bugs", "", "| ID | Severity | Component | Title |", "|---|---|---|---|");
2277
+ for (const bug of session.bugs) {
2278
+ lines.push(
2279
+ `| ${bug.id} | ${SEVERITY_LABEL[bug.severity]} | ${bug.component || "\u2014"} | ${bug.title} |`
2280
+ );
2281
+ }
2282
+ lines.push("");
2283
+ }
2284
+ const coverage = extractCoverage(report);
2285
+ if (coverage.length) {
2286
+ lines.push("## Coverage", "", "| Area | Risk | Status | Bugs | Notes |", "|---|---|---|---|---|");
2287
+ for (const c of coverage) {
2288
+ lines.push(`| ${c.area} | ${c.risk} | ${c.status} | ${c.bugsFound} | ${c.notes} |`);
2289
+ }
2290
+ lines.push("");
2291
+ }
2292
+ const recommendations = extractListSection(report, "Recommendations");
2293
+ if (recommendations.length) {
2294
+ lines.push("## Recommendations", "");
2295
+ for (const r of recommendations) lines.push(`- ${r}`);
2296
+ lines.push("");
2297
+ }
2298
+ return lines.join("\n");
2299
+ }
2300
+
2301
+ // src/schemas/session-metrics.schema.ts
2302
+ import { z as z7 } from "zod";
2303
+ var SeverityCountsSchema = z7.object({
2304
+ critical: z7.number().int().min(0),
2305
+ high: z7.number().int().min(0),
2306
+ medium: z7.number().int().min(0),
2307
+ low: z7.number().int().min(0)
2308
+ });
2309
+ var SessionMetricsSchema = z7.object({
2310
+ session_id: z7.string().min(1),
2311
+ target: z7.string().min(1),
2312
+ date: z7.string().min(1),
2313
+ duration_min: z7.number().min(0),
2314
+ bugs_found: z7.number().int().min(0),
2315
+ severity_counts: SeverityCountsSchema,
2316
+ pages_explored: z7.number().int().min(0),
2317
+ // Optional context.
2318
+ kind: z7.enum(["explore", "quick", "mobile", "backend"]).optional(),
2319
+ domain: z7.string().optional(),
2320
+ started_at: z7.string().optional(),
2321
+ completed_at: z7.string().optional(),
2322
+ phases_completed: z7.number().int().min(0).optional(),
2323
+ total_phases: z7.number().int().min(0).optional(),
2324
+ coverage: z7.record(z7.string(), z7.unknown()).optional(),
2325
+ evidence: z7.record(z7.string(), z7.unknown()).optional(),
2326
+ areas_not_tested: z7.array(z7.string()).optional(),
2327
+ blocked_by: z7.string().nullable().optional()
2328
+ });
2329
+
2330
+ // src/utils/metrics.ts
2331
+ import { readFileSync as readFileSync7, appendFileSync, existsSync as existsSync8, mkdirSync as mkdirSync2 } from "fs";
2332
+ import { join as join8, dirname as dirname3 } from "path";
2333
+ var METRICS_FILENAME = "metrics.jsonl";
2334
+ function appendSessionMetrics(outputDir, metrics) {
2335
+ SessionMetricsSchema.parse(metrics);
2336
+ const filePath = join8(outputDir, METRICS_FILENAME);
2337
+ const dir = dirname3(filePath);
2338
+ if (!existsSync8(dir)) {
2339
+ mkdirSync2(dir, { recursive: true });
2340
+ }
2341
+ const line = JSON.stringify(metrics) + "\n";
2342
+ appendFileSync(filePath, line, "utf-8");
2343
+ }
2344
+ function readAllMetrics(outputDir) {
2345
+ const filePath = join8(outputDir, METRICS_FILENAME);
2346
+ if (!existsSync8(filePath)) {
2347
+ return [];
2348
+ }
2349
+ const content = readFileSync7(filePath, "utf-8").trim();
2350
+ if (!content) {
2351
+ return [];
2352
+ }
2353
+ const lines = content.split("\n");
2354
+ const results = [];
2355
+ for (const line of lines) {
2356
+ if (!line.trim()) continue;
2357
+ let parsed;
2358
+ try {
2359
+ parsed = JSON.parse(line);
2360
+ } catch {
2361
+ continue;
2362
+ }
2363
+ const result = SessionMetricsSchema.safeParse(parsed);
2364
+ if (result.success) results.push(result.data);
2365
+ }
2366
+ return results;
2367
+ }
2368
+ function appendSessionMetricsDeduped(outputDir, metrics) {
2369
+ const existing = readAllMetrics(outputDir);
2370
+ if (existing.some((m) => m.session_id === metrics.session_id)) {
2371
+ return false;
2372
+ }
2373
+ appendSessionMetrics(outputDir, metrics);
2374
+ return true;
2375
+ }
2376
+
1562
2377
  // src/cli/commands/report.ts
1563
2378
  function reportCommand() {
1564
- const cmd = new Command4("report").description("Generate a report from a session").option("-s, --session <id>", 'Session ID or "latest"', "latest").option("-f, --format <format>", "Output format: md, html, json, jira", "md").action(async (options) => {
2379
+ const cmd = new Command4("report").description("Generate a report (md summary, html, json or jira csv) from a session").option("-s, --session <id>", 'Session directory name, a unique substring, or "latest"', "latest").option("-f, --format <format>", "Output format: md, html, json, jira", "md").option("-o, --output <file>", "Write to this file instead of the session directory").option("--stdout", "Print to stdout instead of writing a file", false).action(async (options) => {
1565
2380
  try {
1566
- await runReport(options);
2381
+ await runReport(options, { cwd: process.cwd() });
1567
2382
  } catch (err) {
1568
2383
  console.error(chalk4.red("Error:"), err instanceof Error ? err.message : err);
1569
2384
  process.exit(1);
@@ -1571,90 +2386,93 @@ function reportCommand() {
1571
2386
  });
1572
2387
  return cmd;
1573
2388
  }
1574
- async function runReport(options) {
1575
- const cwd = process.cwd();
2389
+ var DEFAULT_FILENAMES = {
2390
+ md: "session-summary.md",
2391
+ html: "session-report.html",
2392
+ json: "session-report.json",
2393
+ jira: "jira-export.csv"
2394
+ };
2395
+ async function runReport(options, ctx) {
2396
+ const cwd = ctx.cwd;
2397
+ const log = ctx.log ?? ((line) => console.log(line));
1576
2398
  const sessionsDir = resolve6(cwd, "output", "sessions");
1577
- if (!existsSync6(sessionsDir)) {
1578
- console.error(chalk4.red("No sessions directory found. Run `npx qualiow init` first."));
1579
- process.exit(1);
2399
+ if (!existsSync9(sessionsDir)) {
2400
+ throw new Error("No output/sessions directory found. Run `npx qualiow init` first.");
1580
2401
  }
1581
2402
  const sessionDir = resolveSessionDir(sessionsDir, options.session);
1582
- if (!sessionDir) {
1583
- console.error(chalk4.red("No session found. Run an exploratory testing session first."));
1584
- process.exit(1);
1585
- }
1586
- const sessionName = basename2(sessionDir);
1587
- console.log(chalk4.cyan(`
1588
- Session: ${sessionName}`));
2403
+ const sessionName = basename6(sessionDir);
1589
2404
  const format = options.format.toLowerCase();
2405
+ let content;
1590
2406
  switch (format) {
1591
- case "md": {
1592
- const reportPath = join5(sessionDir, "session-report.md");
1593
- if (existsSync6(reportPath)) {
1594
- console.log(chalk4.green(`
1595
- Report: ${reportPath}`));
1596
- } else {
1597
- console.log(chalk4.yellow(" No session-report.md found in this session."));
1598
- }
2407
+ case "md":
2408
+ content = await generateMarkdownSummary(sessionDir);
1599
2409
  break;
1600
- }
1601
- case "html": {
1602
- const html = await generateHtmlReport(sessionDir);
1603
- const outputPath = join5(sessionDir, "session-report.html");
1604
- writeFileSync2(outputPath, html);
1605
- console.log(chalk4.green(`
1606
- HTML report saved: ${outputPath}`));
2410
+ case "html":
2411
+ content = await generateHtmlReport(sessionDir);
1607
2412
  break;
1608
- }
1609
- case "json": {
1610
- const data = await generateJsonReport(sessionDir);
1611
- const outputPath = join5(sessionDir, "session-report.json");
1612
- writeFileSync2(outputPath, JSON.stringify(data, null, 2));
1613
- console.log(chalk4.green(`
1614
- JSON report saved: ${outputPath}`));
2413
+ case "json":
2414
+ content = JSON.stringify(await generateJsonReport(sessionDir), null, 2);
1615
2415
  break;
1616
- }
1617
- case "jira": {
1618
- const csv = await generateJiraExport(sessionDir);
1619
- const outputPath = join5(sessionDir, "jira-export.csv");
1620
- writeFileSync2(outputPath, csv);
1621
- console.log(chalk4.green(`
1622
- Jira export saved: ${outputPath}`));
2416
+ case "jira":
2417
+ content = await generateJiraExport(sessionDir);
1623
2418
  break;
1624
- }
1625
2419
  default:
1626
- console.error(chalk4.red(`Unknown format: "${format}". Choose from: md, html, json, jira`));
1627
- process.exit(1);
2420
+ throw new Error(`Unknown format: "${format}". Choose from: md, html, json, jira`);
1628
2421
  }
1629
- console.log("");
2422
+ if (options.stdout) {
2423
+ process.stdout.write(content.endsWith("\n") ? content : content + "\n");
2424
+ return { content };
2425
+ }
2426
+ const outputPath = options.output ? resolve6(cwd, options.output) : join9(sessionDir, DEFAULT_FILENAMES[format]);
2427
+ writeFileSync3(outputPath, content);
2428
+ log(chalk4.cyan(`
2429
+ Session: ${sessionName}`));
2430
+ log(chalk4.green(` ${format.toUpperCase()} written: ${relative4(cwd, outputPath)}`));
2431
+ const statsPath = join9(sessionDir, "stats.json");
2432
+ if (existsSync9(statsPath)) {
2433
+ try {
2434
+ const stats = SessionMetricsSchema.parse(JSON.parse(readFileSync8(statsPath, "utf-8")));
2435
+ if (appendSessionMetricsDeduped(resolve6(cwd, "output"), stats)) {
2436
+ log(chalk4.green(" \u2713 Metrics appended to output/metrics.jsonl"));
2437
+ }
2438
+ } catch {
2439
+ log(chalk4.yellow(" \u26A0 stats.json present but not in the expected shape \u2014 metrics not recorded"));
2440
+ }
2441
+ }
2442
+ log("");
2443
+ return { outputPath, content };
1630
2444
  }
1631
2445
  function resolveSessionDir(sessionsDir, sessionId) {
2446
+ const dirs = readdirSync5(sessionsDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort();
1632
2447
  if (sessionId === "latest") {
1633
- const dirs2 = readdirSync4(sessionsDir, { withFileTypes: true }).filter((d) => d.isDirectory()).map((d) => d.name).sort();
1634
- if (dirs2.length === 0) return null;
1635
- return join5(sessionsDir, dirs2[dirs2.length - 1]);
1636
- }
1637
- const exactPath = join5(sessionsDir, sessionId);
1638
- if (existsSync6(exactPath)) {
1639
- return exactPath;
1640
- }
1641
- const dirs = readdirSync4(sessionsDir, { withFileTypes: true }).filter((d) => d.isDirectory() && d.name.includes(sessionId)).map((d) => d.name).sort();
1642
- if (dirs.length > 0) {
1643
- return join5(sessionsDir, dirs[dirs.length - 1]);
2448
+ const canonical = dirs.filter((d) => SESSION_DIR_RE.test(d));
2449
+ const pool = canonical.length ? canonical : dirs;
2450
+ if (pool.length === 0) throw new Error("No sessions found. Run an exploratory testing session first.");
2451
+ return join9(sessionsDir, pool[pool.length - 1]);
2452
+ }
2453
+ if (dirs.includes(sessionId)) return join9(sessionsDir, sessionId);
2454
+ const matches = dirs.filter((d) => d.includes(sessionId));
2455
+ if (matches.length === 1) return join9(sessionsDir, matches[0]);
2456
+ if (matches.length > 1) {
2457
+ throw new Error(
2458
+ `"${sessionId}" matches ${matches.length} sessions \u2014 be more specific:
2459
+ ${matches.join("\n ")}`
2460
+ );
1644
2461
  }
1645
- return null;
2462
+ throw new Error(`No session matches "${sessionId}". List them with: npx qualiow list sessions`);
1646
2463
  }
1647
2464
 
1648
2465
  // src/cli/commands/explore.ts
1649
2466
  import { Command as Command5 } from "commander";
1650
- import { resolve as resolve7, join as join6 } from "path";
1651
- import { existsSync as existsSync7, mkdirSync as mkdirSync2, writeFileSync as writeFileSync3 } from "fs";
1652
- import { execSync } from "child_process";
2467
+ import { resolve as resolve7, join as join10, relative as relative5 } from "path";
2468
+ import { existsSync as existsSync10, mkdirSync as mkdirSync3, writeFileSync as writeFileSync4 } from "fs";
1653
2469
  import chalk5 from "chalk";
1654
2470
  function exploreCommand() {
1655
- const cmd = new Command5("explore").description("Run an exploratory testing session").argument("[url]", "Target URL to explore").option("-t, --target <name>", "Target configuration name").option("-c, --context <file>", "Context file path").option("--time-box <duration>", "Time box duration (e.g., 30m, 1h)", "30m").option("--dry-run", "Validate inputs and show what would happen", false).action(async (url, options) => {
2471
+ const cmd = new Command5("explore").description(
2472
+ "Pre-flight for an exploratory session: validates inputs and creates the session directory. The session itself runs in Claude Code via /qa-explore."
2473
+ ).argument("[url]", "Target URL to explore").option("-t, --target <name>", "Target configuration name (data/targets/<name>.yml)").option("-c, --context <file>", "Context file path").option("--time-box <duration>", "Time box, e.g. 45m (max 45m)", "45m").option("--dry-run", "Validate inputs and show what would happen", false).action(async (url, options) => {
1656
2474
  try {
1657
- await runExplore(url, options);
2475
+ await runExplore(url, options, { cwd: process.cwd() });
1658
2476
  } catch (err) {
1659
2477
  console.error(chalk5.red("Error:"), err instanceof Error ? err.message : err);
1660
2478
  process.exit(1);
@@ -1662,86 +2480,85 @@ function exploreCommand() {
1662
2480
  });
1663
2481
  return cmd;
1664
2482
  }
1665
- async function runExplore(url, options) {
1666
- const cwd = process.cwd();
2483
+ function parseTimeBox(value) {
2484
+ const m = /^(\d+)m$/.exec(value.trim());
2485
+ if (!m) throw new Error(`Invalid --time-box "${value}": use minutes like 30m or 45m`);
2486
+ const minutes = parseInt(m[1], 10);
2487
+ if (minutes < 1 || minutes > 45) {
2488
+ throw new Error(`--time-box must be between 1m and 45m (got ${value})`);
2489
+ }
2490
+ return minutes;
2491
+ }
2492
+ async function runExplore(url, options, ctx) {
2493
+ const cwd = ctx.cwd;
2494
+ const now = ctx.now ?? /* @__PURE__ */ new Date();
2495
+ const log = ctx.log ?? ((line) => console.log(line));
1667
2496
  if (url) {
1668
2497
  try {
1669
2498
  new URL(url);
1670
2499
  } catch {
1671
- console.error(chalk5.red(`Invalid URL: "${url}". Please provide a valid URL (e.g., https://example.com).`));
1672
- process.exit(1);
2500
+ throw new Error(`Invalid URL: "${url}". Provide a full URL such as https://example.com`);
1673
2501
  }
1674
2502
  }
1675
- let targetName = "adhoc";
1676
- if (options.target) {
1677
- const targetPath = resolve7(cwd, "data", "targets", `${options.target}.yml`);
1678
- if (!existsSync7(targetPath)) {
1679
- console.error(
1680
- chalk5.red(`Target config not found: ${targetPath}`)
2503
+ const minutes = parseTimeBox(options.timeBox);
2504
+ const targetPath = resolveTargetPath(cwd, options.target);
2505
+ let targetLabel = options.target ?? "adhoc";
2506
+ if (options.target || existsSync10(targetPath)) {
2507
+ if (!existsSync10(targetPath)) {
2508
+ throw new Error(
2509
+ `Target config not found: ${relative5(cwd, targetPath)}
2510
+ Available targets: npx qualiow list targets`
1681
2511
  );
1682
- console.error(chalk5.white(" Available targets: npx qualiow list targets"));
1683
- process.exit(1);
1684
2512
  }
1685
2513
  const result = validateTargetConfig(targetPath);
1686
2514
  if (!result.valid) {
1687
- console.error(chalk5.red(`Target config "${options.target}" is invalid:`));
1688
- for (const err of result.errors ?? []) {
1689
- console.error(chalk5.red(` \u2192 ${err.path ? `[${err.path}] ` : ""}${err.message}`));
1690
- }
1691
- process.exit(1);
2515
+ const details = (result.errors ?? []).map((e) => ` \u2192 ${e.path ? `[${e.path}] ` : ""}${e.message}`).join("\n");
2516
+ throw new Error(`Target config ${relative5(cwd, targetPath)} is invalid:
2517
+ ${details}`);
1692
2518
  }
1693
- targetName = options.target;
1694
- console.log(chalk5.green(` \u2713 Target config "${options.target}" is valid`));
2519
+ if (!options.target) targetLabel = url ? slugify(url) : "adhoc";
2520
+ log(chalk5.green(` \u2713 Target config valid: ${relative5(cwd, targetPath)}`));
2521
+ } else if (url) {
2522
+ targetLabel = slugify(url);
1695
2523
  }
1696
2524
  if (options.context) {
1697
2525
  const contextPath = resolve7(cwd, options.context);
1698
- if (!existsSync7(contextPath)) {
1699
- console.error(chalk5.red(`Context file not found: ${contextPath}`));
1700
- process.exit(1);
2526
+ if (!existsSync10(contextPath)) {
2527
+ throw new Error(`Context file not found: ${contextPath}`);
1701
2528
  }
1702
- console.log(chalk5.green(` \u2713 Context file found: ${options.context}`));
1703
- }
1704
- const now = /* @__PURE__ */ new Date();
1705
- const timestamp = [
1706
- now.getFullYear(),
1707
- String(now.getMonth() + 1).padStart(2, "0"),
1708
- String(now.getDate()).padStart(2, "0"),
1709
- "-",
1710
- String(now.getHours()).padStart(2, "0"),
1711
- String(now.getMinutes()).padStart(2, "0")
1712
- ].join("");
1713
- const sessionName = `${timestamp}-${targetName}`;
2529
+ log(chalk5.green(` \u2713 Context file found: ${options.context}`));
2530
+ }
2531
+ const sessionName = sessionDirName("explore", targetLabel, now);
1714
2532
  const sessionDir = resolve7(cwd, "output", "sessions", sessionName);
1715
2533
  if (options.dryRun) {
1716
- console.log("");
1717
- console.log(chalk5.cyan.bold("Dry run \u2014 no files created"));
1718
- console.log("");
1719
- console.log(chalk5.white(" Session would be created at:"));
1720
- console.log(chalk5.white(` ${sessionDir}`));
1721
- console.log("");
1722
- console.log(chalk5.white(" Configuration:"));
1723
- console.log(chalk5.white(` URL: ${url ?? "(none \u2014 will be prompted)"}`));
1724
- console.log(chalk5.white(` Target: ${options.target ?? "(ad-hoc)"}`));
1725
- console.log(chalk5.white(` Context: ${options.context ?? "(none)"}`));
1726
- console.log(chalk5.white(` Time box: ${options.timeBox}`));
1727
- console.log("");
1728
- console.log(chalk5.green(" \u2713 All inputs valid"));
1729
- return;
2534
+ log("");
2535
+ log(chalk5.cyan.bold("Dry run \u2014 no files created"));
2536
+ log(chalk5.white(` Session directory: ${relative5(cwd, sessionDir)}`));
2537
+ log(chalk5.white(` URL: ${url ?? "(none \u2014 /qa-explore will ask)"}`));
2538
+ log(chalk5.white(` Target: ${options.target ?? relative5(cwd, targetPath)}`));
2539
+ log(chalk5.white(` Context: ${options.context ?? "(none)"}`));
2540
+ log(chalk5.white(` Time box: ${minutes} min`));
2541
+ return { sessionDir };
1730
2542
  }
1731
- mkdirSync2(sessionDir, { recursive: true });
1732
- mkdirSync2(join6(sessionDir, "screenshots"), { recursive: true });
1733
- mkdirSync2(join6(sessionDir, "bugs"), { recursive: true });
1734
- const charterContent = `# Exploratory Testing Charter
2543
+ for (const sub of ["", "screenshots", "bugs", "videos"]) {
2544
+ mkdirSync3(join10(sessionDir, sub), { recursive: true });
2545
+ }
2546
+ const date = now.toISOString().slice(0, 10);
2547
+ writeFileSync4(
2548
+ join10(sessionDir, "charter.md"),
2549
+ `${CONFIDENTIALITY_HEADER_MD}
2550
+
2551
+ # Exploratory Testing Charter
1735
2552
 
1736
2553
  **Session:** ${sessionName}
1737
- **Date:** ${now.toISOString().split("T")[0]}
1738
- **Target:** ${options.target ?? "Ad-hoc"}
2554
+ **Date:** ${date}
2555
+ **Target:** ${options.target ?? targetLabel}
1739
2556
  **URL:** ${url ?? "TBD"}
1740
- **Time Box:** ${options.timeBox}
2557
+ **Time Box:** ${minutes} min
1741
2558
 
1742
2559
  ## Mission
1743
2560
 
1744
- > Describe the testing mission here.
2561
+ > Filled in by /qa-explore phase 2.
1745
2562
 
1746
2563
  ## Areas of Focus
1747
2564
 
@@ -1750,131 +2567,75 @@ async function runExplore(url, options) {
1750
2567
  ## Risks & Concerns
1751
2568
 
1752
2569
  -
2570
+ `
2571
+ );
2572
+ writeFileSync4(
2573
+ join10(sessionDir, "session-log.md"),
2574
+ `${CONFIDENTIALITY_HEADER_MD}
1753
2575
 
1754
- ## Notes
1755
-
1756
- -
1757
- `;
1758
- writeFileSync3(join6(sessionDir, "charter.md"), charterContent);
1759
- const sessionLogContent = `# Session Log \u2014 ${sessionName}
2576
+ # Session Log \u2014 ${sessionName}
1760
2577
 
1761
- | Time | Action | Observation | Bug? |
1762
- |------|--------|-------------|------|
1763
- `;
1764
- writeFileSync3(join6(sessionDir, "session-log.md"), sessionLogContent);
1765
- console.log("");
1766
- console.log(chalk5.green.bold("Session created!"));
1767
- console.log("");
1768
- console.log(chalk5.white(` Directory: ${sessionDir}`));
1769
- console.log("");
1770
- let claudeAvailable = false;
1771
- try {
1772
- execSync("which claude", { stdio: "pipe" });
1773
- claudeAvailable = true;
1774
- } catch {
1775
- }
1776
- if (claudeAvailable) {
1777
- console.log(chalk5.cyan(" Claude Code detected! To start exploring:"));
1778
- console.log("");
1779
- console.log(chalk5.white(` /qa-explore ${url ?? "<url>"}`));
1780
- } else {
1781
- console.log(chalk5.cyan(" Next steps:"));
1782
- console.log(chalk5.white(" 1. Install Claude Code (https://docs.anthropic.com/en/docs/claude-code)"));
1783
- console.log(chalk5.white(` 2. Run: /qa-explore ${url ?? "<url>"}`));
1784
- }
1785
- console.log("");
1786
- console.log(chalk5.gray(` Session directory: ${sessionDir}`));
1787
- console.log("");
2578
+ [${now.toISOString()}] [PRE-FLIGHT] Session directory created by \`qualiow explore\`
2579
+ `
2580
+ );
2581
+ log("");
2582
+ log(chalk5.green.bold("Session skeleton created (pre-flight only \u2014 no browser was launched)."));
2583
+ log(chalk5.white(` Directory: ${relative5(cwd, sessionDir)}`));
2584
+ log("");
2585
+ log(chalk5.cyan(" Run the session in Claude Code:"));
2586
+ const args = [url ?? "<url>", options.target ? `--target ${options.target}` : "", options.context ? `--context ${options.context}` : ""].filter(Boolean).join(" ");
2587
+ log(chalk5.white(` /qa-explore ${args} --session output/sessions/${sessionName}`));
2588
+ log("");
2589
+ return { sessionDir };
1788
2590
  }
1789
2591
 
1790
- // src/cli/commands/gather.ts
2592
+ // src/cli/commands/kb.ts
1791
2593
  import { Command as Command6 } from "commander";
1792
2594
  import { resolve as resolve8 } from "path";
1793
- import { existsSync as existsSync8, mkdirSync as mkdirSync3 } from "fs";
1794
- import { execSync as execSync2 } from "child_process";
2595
+ import { existsSync as existsSync11 } from "fs";
1795
2596
  import chalk6 from "chalk";
1796
- function gatherCommand() {
1797
- const cmd = new Command6("gather").description("Gather and analyze requirements for testing context").argument("<source>", "Source file path or URL to gather context from").option("-o, --output <file>", "Output file path").option("-d, --domain <name>", "Domain configuration name").action(async (source, options) => {
2597
+ function kbCommand() {
2598
+ const cmd = new Command6("kb").description("Knowledge-base maintenance");
2599
+ cmd.command("sync").description("Regenerate data/knowledge/manifest.yml entries and stats from the release files").action(() => {
1798
2600
  try {
1799
- await runGather(source, options);
2601
+ const result = runKb("sync", process.cwd());
2602
+ console.log(
2603
+ result.changed ? chalk6.green(` \u2713 manifest.yml updated (${result.entryCount} entries)`) : chalk6.cyan(` \u25CB manifest.yml already in sync (${result.entryCount} entries)`)
2604
+ );
1800
2605
  } catch (err) {
1801
2606
  console.error(chalk6.red("Error:"), err instanceof Error ? err.message : err);
1802
2607
  process.exit(1);
1803
2608
  }
1804
2609
  });
1805
- return cmd;
1806
- }
1807
- async function runGather(source, options) {
1808
- const cwd = process.cwd();
1809
- const isUrl = isValidUrl(source);
1810
- const isFile = !isUrl && existsSync8(resolve8(cwd, source));
1811
- if (!isUrl && !isFile) {
1812
- console.error(chalk6.red(`Source not found: "${source}"`));
1813
- console.error(chalk6.white(" Provide a valid file path or URL."));
1814
- process.exit(1);
1815
- }
1816
- if (isUrl) {
1817
- console.log(chalk6.green(` \u2713 Source is a URL: ${source}`));
1818
- } else {
1819
- console.log(chalk6.green(` \u2713 Source file found: ${resolve8(cwd, source)}`));
1820
- }
1821
- if (options.domain) {
1822
- const domainPath = resolve8(cwd, "data", "domains", `${options.domain}.yml`);
1823
- if (!existsSync8(domainPath)) {
1824
- console.error(chalk6.red(`Domain config not found: ${domainPath}`));
1825
- console.error(chalk6.white(" Available domains: npx qualiow list domains"));
2610
+ cmd.command("check").description("Exit 1 if manifest.yml is out of sync with the release files").action(() => {
2611
+ try {
2612
+ const result = runKb("check", process.cwd());
2613
+ if (result.changed) {
2614
+ console.error(chalk6.red(" \u2717 manifest.yml is out of sync \u2014 run: npx qualiow kb sync"));
2615
+ process.exit(1);
2616
+ }
2617
+ console.log(chalk6.green(` \u2713 manifest.yml in sync (${result.entryCount} entries)`));
2618
+ } catch (err) {
2619
+ console.error(chalk6.red("Error:"), err instanceof Error ? err.message : err);
1826
2620
  process.exit(1);
1827
2621
  }
1828
- console.log(chalk6.green(` \u2713 Domain config "${options.domain}" found`));
1829
- }
1830
- const outputDir = resolve8(cwd, "output", "context");
1831
- mkdirSync3(outputDir, { recursive: true });
1832
- if (options.output) {
1833
- console.log(chalk6.green(` \u2713 Output will be saved to: ${resolve8(cwd, options.output)}`));
1834
- } else {
1835
- console.log(chalk6.green(` \u2713 Output directory ready: ${outputDir}`));
1836
- }
1837
- let claudeAvailable = false;
1838
- try {
1839
- execSync2("which claude", { stdio: "pipe" });
1840
- claudeAvailable = true;
1841
- } catch {
1842
- }
1843
- console.log("");
1844
- console.log(chalk6.cyan.bold("Ready to gather context!"));
1845
- console.log("");
1846
- if (claudeAvailable) {
1847
- console.log(chalk6.cyan(" Claude Code detected! To gather context:"));
1848
- console.log("");
1849
- console.log(chalk6.white(` /qa-gather ${source}`));
1850
- } else {
1851
- console.log(chalk6.cyan(" Next steps:"));
1852
- console.log(chalk6.white(" 1. Install Claude Code (https://docs.anthropic.com/en/docs/claude-code)"));
1853
- console.log(chalk6.white(` 2. Run: /qa-gather ${source}`));
1854
- }
1855
- console.log("");
1856
- console.log(chalk6.gray(" The /qa-gather skill will:"));
1857
- console.log(chalk6.gray(" - Analyze the source for testable requirements"));
1858
- console.log(chalk6.gray(" - Generate testing context and risk assessment"));
1859
- console.log(chalk6.gray(" - Save output to output/context/"));
1860
- console.log("");
2622
+ });
2623
+ return cmd;
1861
2624
  }
1862
- function isValidUrl(str) {
1863
- try {
1864
- const url = new URL(str);
1865
- return url.protocol === "http:" || url.protocol === "https:";
1866
- } catch {
1867
- return false;
2625
+ function runKb(mode, cwd) {
2626
+ const dataDir = resolve8(cwd, "data");
2627
+ if (!existsSync11(resolve8(dataDir, "knowledge", "manifest.yml"))) {
2628
+ throw new Error("data/knowledge/manifest.yml not found. Run `npx qualiow init` first.");
1868
2629
  }
2630
+ return syncKnowledgeManifest(dataDir, { check: mode === "check" });
1869
2631
  }
1870
2632
 
1871
2633
  // src/cli/index.ts
1872
- var program = new Command7().name("qualiow").description("qualiow \u2014 AI-powered exploratory testing").version("1.0.0");
2634
+ var program = new Command7().name("qualiow").description("qualiow \u2014 AI-powered exploratory testing (web, mobile, backend)").version(getPackageVersion());
1873
2635
  program.addCommand(initCommand());
1874
2636
  program.addCommand(validateCommand());
1875
2637
  program.addCommand(listCommand());
1876
2638
  program.addCommand(reportCommand());
1877
2639
  program.addCommand(exploreCommand());
1878
- program.addCommand(gatherCommand());
2640
+ program.addCommand(kbCommand());
1879
2641
  program.parse();
1880
- //# sourceMappingURL=index.js.map