@kirrosh/zond 0.26.0 → 0.27.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 (261) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/README.md +22 -21
  3. package/bin/zond.mjs +23 -0
  4. package/package.json +13 -16
  5. package/scripts/npm/postinstall.mjs +76 -0
  6. package/src/CLAUDE.md +0 -112
  7. package/src/bun-types.d.ts +0 -5
  8. package/src/cli/argv.ts +0 -122
  9. package/src/cli/commands/add-api.ts +0 -146
  10. package/src/cli/commands/api/annotate/idempotency.ts +0 -59
  11. package/src/cli/commands/api/annotate/index.ts +0 -880
  12. package/src/cli/commands/api/annotate/lifecycle.ts +0 -74
  13. package/src/cli/commands/api/annotate/overlay.ts +0 -206
  14. package/src/cli/commands/api/annotate/pagination.ts +0 -64
  15. package/src/cli/commands/api/annotate/prompts.ts +0 -220
  16. package/src/cli/commands/api/annotate/readback.ts +0 -58
  17. package/src/cli/commands/api/annotate/resources.ts +0 -91
  18. package/src/cli/commands/api/annotate/seed-bodies.ts +0 -61
  19. package/src/cli/commands/audit.ts +0 -786
  20. package/src/cli/commands/catalog.ts +0 -97
  21. package/src/cli/commands/check.ts +0 -361
  22. package/src/cli/commands/checks.ts +0 -1072
  23. package/src/cli/commands/ci-init.ts +0 -223
  24. package/src/cli/commands/clean.ts +0 -212
  25. package/src/cli/commands/cleanup.ts +0 -236
  26. package/src/cli/commands/completions.ts +0 -192
  27. package/src/cli/commands/coverage.ts +0 -872
  28. package/src/cli/commands/db.ts +0 -611
  29. package/src/cli/commands/describe.ts +0 -120
  30. package/src/cli/commands/discover.ts +0 -1356
  31. package/src/cli/commands/doctor.ts +0 -661
  32. package/src/cli/commands/fixtures.ts +0 -402
  33. package/src/cli/commands/generate.ts +0 -577
  34. package/src/cli/commands/init/agents-md.ts +0 -61
  35. package/src/cli/commands/init/bootstrap.ts +0 -111
  36. package/src/cli/commands/init/index.ts +0 -244
  37. package/src/cli/commands/init/skills.ts +0 -141
  38. package/src/cli/commands/init/templates/agents.md +0 -86
  39. package/src/cli/commands/init/templates/markdown.d.ts +0 -4
  40. package/src/cli/commands/init/templates/skills/warm-up-target.md +0 -122
  41. package/src/cli/commands/init/templates/skills/zond-checks.md +0 -621
  42. package/src/cli/commands/init/templates/skills/zond-seed.md +0 -114
  43. package/src/cli/commands/init/templates/skills/zond-triage.md +0 -272
  44. package/src/cli/commands/init/templates/skills/zond.md +0 -861
  45. package/src/cli/commands/init/templates/zond-config.yml +0 -14
  46. package/src/cli/commands/prepare-fixtures.ts +0 -97
  47. package/src/cli/commands/probe/_seed-bodies.ts +0 -52
  48. package/src/cli/commands/probe/mass-assignment.ts +0 -594
  49. package/src/cli/commands/probe/security.ts +0 -537
  50. package/src/cli/commands/probe/static.ts +0 -255
  51. package/src/cli/commands/probe/webhooks.ts +0 -163
  52. package/src/cli/commands/probe.ts +0 -535
  53. package/src/cli/commands/reference.ts +0 -87
  54. package/src/cli/commands/refresh-api.ts +0 -227
  55. package/src/cli/commands/remove-api.ts +0 -150
  56. package/src/cli/commands/report-bundle.ts +0 -310
  57. package/src/cli/commands/report.ts +0 -241
  58. package/src/cli/commands/request.ts +0 -548
  59. package/src/cli/commands/run.ts +0 -1142
  60. package/src/cli/commands/schema-from-runs.ts +0 -128
  61. package/src/cli/commands/secrets.ts +0 -133
  62. package/src/cli/commands/session.ts +0 -244
  63. package/src/cli/commands/use.ts +0 -74
  64. package/src/cli/index.ts +0 -55
  65. package/src/cli/json-envelope.ts +0 -108
  66. package/src/cli/json-schemas.ts +0 -314
  67. package/src/cli/output.ts +0 -40
  68. package/src/cli/program.ts +0 -219
  69. package/src/cli/resolve.ts +0 -105
  70. package/src/cli/runtime.ts +0 -7
  71. package/src/cli/safe-live.ts +0 -24
  72. package/src/cli/status-filter.ts +0 -114
  73. package/src/cli/util/api-context.ts +0 -85
  74. package/src/cli/version.ts +0 -8
  75. package/src/core/audit/persist.ts +0 -183
  76. package/src/core/checks/budget.ts +0 -59
  77. package/src/core/checks/checks/_crud-helpers.ts +0 -133
  78. package/src/core/checks/checks/_negative_mutator.ts +0 -133
  79. package/src/core/checks/checks/_readback-helpers.ts +0 -133
  80. package/src/core/checks/checks/content_type_conformance.ts +0 -39
  81. package/src/core/checks/checks/cross_call_references.ts +0 -147
  82. package/src/core/checks/checks/cursor_boundary_fuzzing.ts +0 -219
  83. package/src/core/checks/checks/ensure_resource_availability.ts +0 -62
  84. package/src/core/checks/checks/idempotency_replay.ts +0 -242
  85. package/src/core/checks/checks/ignored_auth.ts +0 -254
  86. package/src/core/checks/checks/index.ts +0 -68
  87. package/src/core/checks/checks/lifecycle_transitions.ts +0 -416
  88. package/src/core/checks/checks/missing_required_header.ts +0 -40
  89. package/src/core/checks/checks/negative_data_rejection.ts +0 -148
  90. package/src/core/checks/checks/not_a_server_error.ts +0 -35
  91. package/src/core/checks/checks/open_cors_on_sensitive.ts +0 -160
  92. package/src/core/checks/checks/pagination_invariants.ts +0 -419
  93. package/src/core/checks/checks/positive_data_acceptance.ts +0 -33
  94. package/src/core/checks/checks/rate_limit_headers_absent.ts +0 -77
  95. package/src/core/checks/checks/response_headers_conformance.ts +0 -74
  96. package/src/core/checks/checks/response_schema_conformance.ts +0 -30
  97. package/src/core/checks/checks/status_code_conformance.ts +0 -132
  98. package/src/core/checks/checks/unsupported_method.ts +0 -63
  99. package/src/core/checks/checks/use_after_free.ts +0 -78
  100. package/src/core/checks/index.ts +0 -30
  101. package/src/core/checks/mode.ts +0 -82
  102. package/src/core/checks/recommended-action.ts +0 -68
  103. package/src/core/checks/registry.ts +0 -78
  104. package/src/core/checks/runner.ts +0 -1461
  105. package/src/core/checks/sarif.ts +0 -230
  106. package/src/core/checks/spec-findings.ts +0 -308
  107. package/src/core/checks/stateful.ts +0 -121
  108. package/src/core/checks/types.ts +0 -305
  109. package/src/core/checks/zond-extensions.ts +0 -73
  110. package/src/core/classifier/recommended-action.ts +0 -251
  111. package/src/core/context/current.ts +0 -51
  112. package/src/core/context/session.ts +0 -78
  113. package/src/core/coverage/loader.ts +0 -216
  114. package/src/core/coverage/reasons.ts +0 -300
  115. package/src/core/diagnostics/db-analysis.ts +0 -666
  116. package/src/core/diagnostics/failure-class.ts +0 -140
  117. package/src/core/diagnostics/failure-hints.ts +0 -112
  118. package/src/core/diagnostics/spec-pointer.ts +0 -99
  119. package/src/core/diagnostics/suggested-fixes.ts +0 -155
  120. package/src/core/exporter/case-study/index.ts +0 -270
  121. package/src/core/exporter/curl.ts +0 -40
  122. package/src/core/exporter/exporter.ts +0 -48
  123. package/src/core/exporter/html-report/escape.ts +0 -24
  124. package/src/core/exporter/html-report/index.ts +0 -479
  125. package/src/core/exporter/html-report/script.ts +0 -100
  126. package/src/core/exporter/html-report/styles.ts +0 -408
  127. package/src/core/generator/catalog-builder.ts +0 -179
  128. package/src/core/generator/chunker.ts +0 -78
  129. package/src/core/generator/coverage-phase.ts +0 -0
  130. package/src/core/generator/coverage-scanner.ts +0 -87
  131. package/src/core/generator/data-factory.ts +0 -759
  132. package/src/core/generator/describe.ts +0 -302
  133. package/src/core/generator/endpoint-warnings.ts +0 -52
  134. package/src/core/generator/fixtures-builder.ts +0 -332
  135. package/src/core/generator/index.ts +0 -14
  136. package/src/core/generator/openapi-reader.ts +0 -297
  137. package/src/core/generator/path-param-disambig.ts +0 -140
  138. package/src/core/generator/resources-builder.ts +0 -898
  139. package/src/core/generator/schema-utils.ts +0 -112
  140. package/src/core/generator/serializer.ts +0 -343
  141. package/src/core/generator/suite-generator.ts +0 -1301
  142. package/src/core/generator/types.ts +0 -63
  143. package/src/core/identity/identity-file.ts +0 -0
  144. package/src/core/lint/affects.ts +0 -28
  145. package/src/core/lint/config.ts +0 -96
  146. package/src/core/lint/format.ts +0 -42
  147. package/src/core/lint/index.ts +0 -94
  148. package/src/core/lint/reporter.ts +0 -128
  149. package/src/core/lint/rules/consistency.ts +0 -158
  150. package/src/core/lint/rules/heuristics.ts +0 -97
  151. package/src/core/lint/rules/strictness.ts +0 -109
  152. package/src/core/lint/types.ts +0 -96
  153. package/src/core/lint/walker.ts +0 -248
  154. package/src/core/meta/meta-store.ts +0 -11
  155. package/src/core/output/README.md +0 -73
  156. package/src/core/output/index.ts +0 -13
  157. package/src/core/output/run.ts +0 -91
  158. package/src/core/output/types.ts +0 -122
  159. package/src/core/parser/dynamic-values.ts +0 -160
  160. package/src/core/parser/env-interpolation.ts +0 -104
  161. package/src/core/parser/filter.ts +0 -97
  162. package/src/core/parser/schema.ts +0 -359
  163. package/src/core/parser/types.ts +0 -117
  164. package/src/core/parser/variables.ts +0 -0
  165. package/src/core/parser/yaml-parser.ts +0 -181
  166. package/src/core/probe/bootstrap.ts +0 -34
  167. package/src/core/probe/dry-run-envelope.ts +0 -61
  168. package/src/core/probe/mass-assignment/classify.ts +0 -175
  169. package/src/core/probe/mass-assignment/cleanup.ts +0 -52
  170. package/src/core/probe/mass-assignment/digest.ts +0 -114
  171. package/src/core/probe/mass-assignment/orchestrator.ts +0 -459
  172. package/src/core/probe/mass-assignment/regression.ts +0 -141
  173. package/src/core/probe/mass-assignment/suspects.ts +0 -92
  174. package/src/core/probe/mass-assignment/types.ts +0 -135
  175. package/src/core/probe/mass-assignment-probe-class.ts +0 -198
  176. package/src/core/probe/mass-assignment-probe.ts +0 -27
  177. package/src/core/probe/mass-assignment-template.ts +0 -240
  178. package/src/core/probe/method-probe.ts +0 -164
  179. package/src/core/probe/method-shared.ts +0 -69
  180. package/src/core/probe/negative-probe.ts +0 -691
  181. package/src/core/probe/orphan-tracker.ts +0 -188
  182. package/src/core/probe/path-discovery.ts +0 -439
  183. package/src/core/probe/probe-harness.ts +0 -119
  184. package/src/core/probe/registry.ts +0 -89
  185. package/src/core/probe/runner.ts +0 -136
  186. package/src/core/probe/security/baseline.ts +0 -174
  187. package/src/core/probe/security/classify.ts +0 -341
  188. package/src/core/probe/security/cleanup.ts +0 -125
  189. package/src/core/probe/security/detectors.ts +0 -71
  190. package/src/core/probe/security/digest.ts +0 -104
  191. package/src/core/probe/security/orchestrator.ts +0 -398
  192. package/src/core/probe/security/regression.ts +0 -103
  193. package/src/core/probe/security/types.ts +0 -151
  194. package/src/core/probe/security-probe-class.ts +0 -207
  195. package/src/core/probe/security-probe.ts +0 -32
  196. package/src/core/probe/shared.ts +0 -531
  197. package/src/core/probe/static-probe-class.ts +0 -125
  198. package/src/core/probe/types.ts +0 -165
  199. package/src/core/probe/verdict-aggregator.ts +0 -33
  200. package/src/core/probe/webhooks-probe.ts +0 -282
  201. package/src/core/reporter/console.ts +0 -240
  202. package/src/core/reporter/index.ts +0 -22
  203. package/src/core/reporter/json.ts +0 -22
  204. package/src/core/reporter/junit.ts +0 -93
  205. package/src/core/reporter/ndjson.ts +0 -37
  206. package/src/core/reporter/types.ts +0 -15
  207. package/src/core/runner/assertions.ts +0 -383
  208. package/src/core/runner/async-pool.ts +0 -108
  209. package/src/core/runner/auth-path.ts +0 -8
  210. package/src/core/runner/ci-context.ts +0 -72
  211. package/src/core/runner/executor.ts +0 -652
  212. package/src/core/runner/expr-eval.ts +0 -41
  213. package/src/core/runner/form-encode.ts +0 -41
  214. package/src/core/runner/http-client.ts +0 -224
  215. package/src/core/runner/learn-drift.ts +0 -293
  216. package/src/core/runner/preflight-vars.ts +0 -153
  217. package/src/core/runner/progress-tracker.ts +0 -73
  218. package/src/core/runner/rate-limiter.ts +0 -185
  219. package/src/core/runner/run-kind.ts +0 -45
  220. package/src/core/runner/schema-validator.ts +0 -308
  221. package/src/core/runner/send-request.ts +0 -232
  222. package/src/core/runner/transforms.ts +0 -65
  223. package/src/core/runner/types.ts +0 -94
  224. package/src/core/secrets/registry.ts +0 -164
  225. package/src/core/secrets/secrets-file.ts +0 -115
  226. package/src/core/selectors/operation-filter.ts +0 -144
  227. package/src/core/setup-api.ts +0 -590
  228. package/src/core/severity/category.ts +0 -94
  229. package/src/core/severity/index.ts +0 -58
  230. package/src/core/spec/infer-schema.ts +0 -102
  231. package/src/core/spec/layers.ts +0 -154
  232. package/src/core/spec/merge-specs.ts +0 -156
  233. package/src/core/spec/schema-from-runs.ts +0 -117
  234. package/src/core/spec/schema-overlay.ts +0 -130
  235. package/src/core/util/ajv.ts +0 -13
  236. package/src/core/util/format-eta.ts +0 -21
  237. package/src/core/util/headers.ts +0 -9
  238. package/src/core/util/url.ts +0 -24
  239. package/src/core/utils.ts +0 -13
  240. package/src/core/workspace/config.ts +0 -129
  241. package/src/core/workspace/fixture-gap-report.ts +0 -84
  242. package/src/core/workspace/fixture-gaps.ts +0 -71
  243. package/src/core/workspace/manifest.ts +0 -283
  244. package/src/core/workspace/output-rotation.ts +0 -62
  245. package/src/core/workspace/root.ts +0 -96
  246. package/src/core/workspace/triage-path.ts +0 -87
  247. package/src/db/lint-runs.ts +0 -47
  248. package/src/db/migrate.ts +0 -128
  249. package/src/db/migrations/0001_run_kind.sql +0 -25
  250. package/src/db/migrations/0002_run_kind_request.sql +0 -59
  251. package/src/db/migrations/sql.d.ts +0 -4
  252. package/src/db/queries/collections.ts +0 -133
  253. package/src/db/queries/coverage.ts +0 -9
  254. package/src/db/queries/dashboard.ts +0 -59
  255. package/src/db/queries/results.ts +0 -216
  256. package/src/db/queries/runs.ts +0 -289
  257. package/src/db/queries/sessions.ts +0 -42
  258. package/src/db/queries/settings.ts +0 -28
  259. package/src/db/queries/types.ts +0 -172
  260. package/src/db/queries.ts +0 -75
  261. package/src/db/schema.ts +0 -298
@@ -1,283 +0,0 @@
1
- /**
2
- * `.zond/manifest.json` — auto-generated file tracking (TASK-156, m-9).
3
- *
4
- * Every command that writes files into the workspace appends an entry
5
- * here so `zond clean` can later remove only what zond produced, leaving
6
- * user edits intact (sha256 mismatch → manually-edited → skipped).
7
- */
8
-
9
- import { existsSync, mkdirSync, readFileSync, writeFileSync, statSync } from "node:fs";
10
- import { createHash } from "node:crypto";
11
- import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
12
-
13
- const MANIFEST_VERSION = 1;
14
- const MANIFEST_RELPATH = ".zond/manifest.json";
15
-
16
- export type ManifestCategory =
17
- | "spec"
18
- | "catalog"
19
- | "resources"
20
- | "fixtures"
21
- | "env"
22
- | "tests"
23
- | "probes"
24
- | "other";
25
-
26
- export interface ManifestEntry {
27
- /** Workspace-relative POSIX path. */
28
- path: string;
29
- /** sha256 of the file contents at write-time. */
30
- sha256: string;
31
- /** Command that emitted the file (e.g. "zond generate", "zond probe-validation --emit"). */
32
- by: string;
33
- /** ISO 8601 timestamp. */
34
- ts: string;
35
- /** API name when applicable (used by `zond clean --api <name>`). */
36
- api?: string;
37
- /** Logical category for `zond clean --probes` etc. */
38
- category?: ManifestCategory;
39
- }
40
-
41
- export interface Manifest {
42
- version: number;
43
- generated: ManifestEntry[];
44
- }
45
-
46
- function getManifestPath(workspaceRoot: string): string {
47
- return join(workspaceRoot, MANIFEST_RELPATH);
48
- }
49
-
50
- export function loadManifest(workspaceRoot: string): Manifest {
51
- const p = getManifestPath(workspaceRoot);
52
- if (!existsSync(p)) return { version: MANIFEST_VERSION, generated: [] };
53
- try {
54
- const raw = readFileSync(p, "utf-8");
55
- const parsed = JSON.parse(raw);
56
- if (!parsed || typeof parsed !== "object" || !Array.isArray(parsed.generated)) {
57
- return { version: MANIFEST_VERSION, generated: [] };
58
- }
59
- return {
60
- version: typeof parsed.version === "number" ? parsed.version : MANIFEST_VERSION,
61
- generated: parsed.generated as ManifestEntry[],
62
- };
63
- } catch {
64
- return { version: MANIFEST_VERSION, generated: [] };
65
- }
66
- }
67
-
68
- function saveManifest(workspaceRoot: string, manifest: Manifest): void {
69
- const p = getManifestPath(workspaceRoot);
70
- mkdirSync(dirname(p), { recursive: true });
71
- writeFileSync(p, JSON.stringify(manifest, null, 2) + "\n", "utf-8");
72
- }
73
-
74
- /** Workspace-relative POSIX path. */
75
- export function toWorkspacePath(workspaceRoot: string, filePath: string): string {
76
- const abs = isAbsolute(filePath) ? filePath : resolve(filePath);
77
- let rel = relative(workspaceRoot, abs);
78
- if (sep === "\\") rel = rel.split(sep).join("/");
79
- return rel;
80
- }
81
-
82
- export function sha256OfFile(filePath: string): string | null {
83
- try {
84
- const buf = readFileSync(filePath);
85
- return createHash("sha256").update(buf).digest("hex");
86
- } catch {
87
- return null;
88
- }
89
- }
90
-
91
- function sha256OfString(content: string): string {
92
- return createHash("sha256").update(content).digest("hex");
93
- }
94
-
95
- export interface RecordInput {
96
- /** Absolute or workspace-relative path of the file just written. */
97
- path: string;
98
- by: string;
99
- api?: string;
100
- category?: ManifestCategory;
101
- /** Pre-computed sha256; if absent, the file is read from disk. */
102
- sha256?: string;
103
- }
104
-
105
- /**
106
- * Append (or replace) entries in the manifest. Existing entries with the
107
- * same `path` are replaced so re-running a generator updates the hash
108
- * instead of accumulating duplicates.
109
- */
110
- export function recordGeneratedFiles(workspaceRoot: string, entries: RecordInput[]): void {
111
- if (entries.length === 0) return;
112
- const ts = new Date().toISOString();
113
- const accepted: ManifestEntry[] = [];
114
-
115
- for (const e of entries) {
116
- const abs = isAbsolute(e.path) ? e.path : resolve(workspaceRoot, e.path);
117
- const rel = toWorkspacePath(workspaceRoot, abs);
118
- // Refuse to record paths that escape the workspace — happens when tests
119
- // run setupApi from a tmp dir but findWorkspaceRoot walks up to the host
120
- // project root. Without this guard, a `../../../tmp/...` entry pollutes
121
- // the host workspace's manifest.
122
- if (rel.startsWith("..") || isAbsolute(rel)) continue;
123
- const sha = e.sha256 ?? sha256OfFile(abs);
124
- if (!sha) continue; // file vanished; skip
125
- accepted.push({
126
- path: rel,
127
- sha256: sha,
128
- by: e.by,
129
- ts,
130
- api: e.api,
131
- category: e.category,
132
- });
133
- }
134
-
135
- // Don't touch disk when nothing applied to this workspace — keeps tests
136
- // (which run from /tmp but inherit the host's workspace root) from
137
- // creating an empty `.zond/manifest.json` in the dev repo.
138
- if (accepted.length === 0) return;
139
-
140
- const manifest = loadManifest(workspaceRoot);
141
- const byPath = new Map<string, ManifestEntry>();
142
- for (const e of manifest.generated) byPath.set(e.path, e);
143
- for (const e of accepted) byPath.set(e.path, e);
144
-
145
- manifest.version = MANIFEST_VERSION;
146
- manifest.generated = [...byPath.values()].sort((a, b) => a.path.localeCompare(b.path));
147
- saveManifest(workspaceRoot, manifest);
148
- }
149
-
150
- export function recordGeneratedFile(workspaceRoot: string, entry: RecordInput): void {
151
- recordGeneratedFiles(workspaceRoot, [entry]);
152
- }
153
-
154
- export interface CleanFilter {
155
- api?: string;
156
- category?: ManifestCategory;
157
- /** When true, include all entries regardless of api/category. */
158
- all?: boolean;
159
- }
160
-
161
- export interface SelectEntriesResult {
162
- selected: ManifestEntry[];
163
- /** Entries that match `api` filter but were excluded because the user
164
- * did not explicitly opt into the `probes` category. Surfaced so the
165
- * CLI can hint at how to reach them (TASK-258). */
166
- probesPreserved: ManifestEntry[];
167
- }
168
-
169
- export function selectEntries(manifest: Manifest, filter: CleanFilter): ManifestEntry[] {
170
- return selectEntriesEx(manifest, filter).selected;
171
- }
172
-
173
- export function selectEntriesEx(manifest: Manifest, filter: CleanFilter): SelectEntriesResult {
174
- const selected: ManifestEntry[] = [];
175
- const probesPreserved: ManifestEntry[] = [];
176
- // TASK-258: when scoping by --api alone (no explicit --probes / --all),
177
- // probes/ belongs to a separate pipeline (zond probe-validation/-methods)
178
- // and re-generating it costs ~30s on a 200-endpoint spec. Treat it as
179
- // out-of-scope and surface a hint instead of silently nuking suites.
180
- const protectProbes = !!filter.api && filter.category !== "probes" && !filter.all;
181
- for (const e of manifest.generated) {
182
- // spec.json is the source-of-truth snapshot downloaded from the network.
183
- // It is never auto-deleted — removal requires manual action or re-adding the API.
184
- if (e.category === "spec") continue;
185
- if (filter.all) {
186
- selected.push(e);
187
- continue;
188
- }
189
- if (filter.api) {
190
- const matchesApi = e.api === filter.api ||
191
- e.path.startsWith(`apis/${filter.api}/`);
192
- if (!matchesApi) continue;
193
- }
194
- if (filter.category && e.category !== filter.category) continue;
195
- if (protectProbes && e.category === "probes") {
196
- probesPreserved.push(e);
197
- continue;
198
- }
199
- selected.push(e);
200
- }
201
- return { selected, probesPreserved };
202
- }
203
-
204
- export type CleanVerdict = "delete" | "modified" | "missing";
205
-
206
- export interface CleanItem {
207
- entry: ManifestEntry;
208
- absPath: string;
209
- verdict: CleanVerdict;
210
- /** Current sha256 if file exists. */
211
- currentSha256?: string;
212
- }
213
-
214
- export function inspectEntries(workspaceRoot: string, entries: ManifestEntry[]): CleanItem[] {
215
- const items: CleanItem[] = [];
216
- for (const entry of entries) {
217
- const abs = resolve(workspaceRoot, entry.path);
218
- if (!existsSync(abs)) {
219
- items.push({ entry, absPath: abs, verdict: "missing" });
220
- continue;
221
- }
222
- const cur = sha256OfFile(abs);
223
- if (cur && cur !== entry.sha256) {
224
- items.push({ entry, absPath: abs, verdict: "modified", currentSha256: cur });
225
- } else {
226
- items.push({ entry, absPath: abs, verdict: "delete", currentSha256: cur ?? undefined });
227
- }
228
- }
229
- return items;
230
- }
231
-
232
- /**
233
- * Drop entries from the manifest by absolute or workspace-relative path.
234
- */
235
- export function removeManifestEntries(workspaceRoot: string, paths: string[]): void {
236
- if (paths.length === 0) return;
237
- const manifest = loadManifest(workspaceRoot);
238
- const drop = new Set(paths.map((p) => toWorkspacePath(workspaceRoot, p)));
239
- manifest.generated = manifest.generated.filter((e) => !drop.has(e.path));
240
- saveManifest(workspaceRoot, manifest);
241
- }
242
-
243
- /** True when the workspace has a manifest file. */
244
- export function hasManifest(workspaceRoot: string): boolean {
245
- return existsSync(getManifestPath(workspaceRoot));
246
- }
247
-
248
- /**
249
- * Header comment prepended to every YAML/MD file zond writes, so a human
250
- * opening the file sees who wrote it and how to regenerate it. Pair with
251
- * `recordGeneratedFile` for the machine-readable audit trail.
252
- */
253
- export function autoGenHeader(by: string, regenerate?: string): string {
254
- const lines = [
255
- `# Auto-generated by ${by}.`,
256
- `# ⚠️ Edits will be overwritten on regenerate. Drop from .zond/manifest.json (or rename) to keep changes.`,
257
- ];
258
- if (regenerate) lines.push(`# Regenerate: ${regenerate}`);
259
- return lines.join("\n") + "\n";
260
- }
261
-
262
- /**
263
- * Best-effort: derive the API name from a path like `apis/<name>/tests`.
264
- * Returns undefined for non-conventional layouts so manifest entries stay
265
- * un-tagged rather than mis-tagged.
266
- */
267
- export function inferApiName(outputDir: string): string | undefined {
268
- const norm = outputDir.replace(/\\/g, "/");
269
- const m = norm.match(/(?:^|\/)apis\/([^/]+)(?:\/|$)/);
270
- return m?.[1];
271
- }
272
-
273
- /** Cheap sanity check used by zond doctor — true when path lives in workspace. */
274
- function isWithinWorkspace(workspaceRoot: string, candidate: string): boolean {
275
- const abs = isAbsolute(candidate) ? candidate : resolve(workspaceRoot, candidate);
276
- try {
277
- statSync(abs);
278
- } catch {
279
- return false;
280
- }
281
- const rel = relative(workspaceRoot, abs);
282
- return !rel.startsWith("..") && !isAbsolute(rel);
283
- }
@@ -1,62 +0,0 @@
1
- /**
2
- * Auto-rotate `--output <path>` targets so a second `zond report ...` (or
3
- * `zond probe-* --output ...`) does not silently clobber the previous
4
- * artifact (TASK-162, m-9 P6).
5
- *
6
- * Strategy: when `path` already exists, rename it to `<basename>-vN<ext>`
7
- * with the smallest free N (≥ 2) and return that rotation info so the
8
- * caller can print it. The `--overwrite` flag short-circuits to no-op so
9
- * users keep the previous behaviour when they explicitly ask for it.
10
- */
11
-
12
- import { existsSync, renameSync } from "node:fs";
13
- import { basename, dirname, extname, join } from "node:path";
14
-
15
- export interface RotationResult {
16
- /** The path that was renamed (the old artifact). undefined when no rotation happened. */
17
- rotatedFrom?: string;
18
- /** Where the old artifact moved to. undefined when no rotation happened. */
19
- rotatedTo?: string;
20
- /** True when caller asked for `--overwrite` (or the target didn't exist). */
21
- overwrite: boolean;
22
- }
23
-
24
- export interface RotateOptions {
25
- /** When true, skip rotation entirely (overwrite-in-place). */
26
- overwrite?: boolean;
27
- /** Optional callback for the human-facing notice; defaults to stderr. */
28
- notice?: (msg: string) => void;
29
- }
30
-
31
- /**
32
- * Rename `targetPath` to `<base>-vN<ext>` if it exists and `--overwrite`
33
- * is not set. Returns rotation info; the caller is responsible for
34
- * actually writing the new artifact at `targetPath`.
35
- */
36
- export function rotateOutputTarget(targetPath: string, opts: RotateOptions = {}): RotationResult {
37
- if (opts.overwrite) return { overwrite: true };
38
- if (!existsSync(targetPath)) return { overwrite: false };
39
-
40
- const dir = dirname(targetPath);
41
- const ext = extname(targetPath);
42
- const stem = basename(targetPath, ext);
43
- // Strip an existing `-vN` suffix from the stem so successive rotations
44
- // produce `digest-v2.md`, `digest-v3.md` rather than
45
- // `digest-v2-v2.md` etc.
46
- const stemBare = stem.replace(/-v\d+$/, "");
47
-
48
- let n = 2;
49
- while (n < 1000) {
50
- const candidate = join(dir, `${stemBare}-v${n}${ext}`);
51
- if (!existsSync(candidate)) {
52
- renameSync(targetPath, candidate);
53
- const notice = opts.notice ?? ((m: string) => process.stderr.write(m + "\n"));
54
- notice(`Previous artifact moved to ${candidate}`);
55
- return { rotatedFrom: targetPath, rotatedTo: candidate, overwrite: false };
56
- }
57
- n++;
58
- }
59
- // Pathological: 1000 versions exist. Fall back to overwrite to avoid
60
- // an infinite-loop UX failure.
61
- return { overwrite: true };
62
- }
@@ -1,96 +0,0 @@
1
- import { existsSync, statSync } from "node:fs";
2
- import { dirname, join, resolve } from "node:path";
3
- import { homedir } from "node:os";
4
-
5
- /**
6
- * Files / directories that mark a workspace root. Order matters — earlier
7
- * markers win when more than one is present in the same directory.
8
- *
9
- * zond.config.yml — explicit project config (T12)
10
- * .zond/ — runtime state subdir (holds zond.db, current-api, …)
11
- * apis/ — collections directory
12
- */
13
- export const WORKSPACE_MARKERS = ["zond.config.yml", ".zond", "apis"] as const;
14
- export type WorkspaceMarker = (typeof WORKSPACE_MARKERS)[number];
15
-
16
- export interface WorkspaceInfo {
17
- /** Absolute path to the workspace root. */
18
- root: string;
19
- /** Marker that triggered detection, or "" when fallback (cwd) was used. */
20
- marker: WorkspaceMarker | "";
21
- /** True when no marker was found and we fell back to `cwd`. */
22
- fromFallback: boolean;
23
- }
24
-
25
- let warned = false;
26
-
27
- function hasMarker(dir: string): WorkspaceMarker | null {
28
- for (const m of WORKSPACE_MARKERS) {
29
- const p = join(dir, m);
30
- if (!existsSync(p)) continue;
31
- // .zond and apis must be directories; zond.config.yml must be a file
32
- try {
33
- const st = statSync(p);
34
- if (m === ".zond" || m === "apis") {
35
- if (st.isDirectory()) return m;
36
- } else if (st.isFile()) {
37
- return m;
38
- }
39
- } catch {
40
- /* race / permissions — treat as no marker */
41
- }
42
- }
43
- return null;
44
- }
45
-
46
- /**
47
- * Walk-up from `cwd` (default `process.cwd()`) to the nearest workspace
48
- * marker. The walk stops at `os.homedir()` to avoid accidentally picking up
49
- * `~/apis` or `~/.zond` when the user runs zond from somewhere unrelated.
50
- *
51
- * When no marker is found, returns `{ root: cwd, fromFallback: true }` and
52
- * prints a one-time stderr warning so the user knows zond is operating in
53
- * cwd-mode.
54
- */
55
- export function findWorkspaceRoot(cwd?: string): WorkspaceInfo {
56
- // Explicit override for headless/CI/workflow runs: skip walk-up entirely and
57
- // anchor the workspace at ZOND_WORKSPACE. Lets each run own an isolated root
58
- // (its own .zond/zond.db, apis/) without depending on cwd or a parent marker.
59
- const override = process.env.ZOND_WORKSPACE?.trim();
60
- if (override) {
61
- return { root: resolve(override), marker: "", fromFallback: false };
62
- }
63
-
64
- const start = resolve(cwd ?? process.cwd());
65
- const stop = resolve(homedir());
66
-
67
- let dir = start;
68
- // Walk strictly while above (or equal to) HOME's length, but include HOME
69
- // itself as a candidate only when start is inside HOME. If start is outside
70
- // HOME (e.g. /tmp), walk all the way to "/".
71
- const insideHome = start === stop || start.startsWith(stop + "/") || start.startsWith(stop + "\\");
72
-
73
- while (true) {
74
- const marker = hasMarker(dir);
75
- if (marker) return { root: dir, marker, fromFallback: false };
76
-
77
- const parent = dirname(dir);
78
- if (parent === dir) break; // filesystem root
79
- if (insideHome && dir === stop) break; // do not climb past HOME
80
- dir = parent;
81
- }
82
-
83
- if (!warned) {
84
- warned = true;
85
- process.stderr.write(
86
- `[zond] no workspace marker found from ${start}; using cwd. ` +
87
- `Run 'zond init' or create zond.config.yml to anchor the workspace.\n`,
88
- );
89
- }
90
- return { root: start, marker: "", fromFallback: true };
91
- }
92
-
93
- /** Test helper: reset the one-shot warning latch. */
94
- export function _resetWorkspaceWarning(): void {
95
- warned = false;
96
- }
@@ -1,87 +0,0 @@
1
- /**
2
- * Default `triage/` path for `--output` (TASK-163, m-9 P7).
3
- *
4
- * Rule: when the user runs a report-emitting command without `--output`,
5
- * we drop the artifact into:
6
- *
7
- * <workspace>/triage/<api|"adhoc">/<run-id>/<command>-<timestamp>.<ext>
8
- *
9
- * If they pass `--output some-filename.md` (no slash), that filename is
10
- * used as the basename inside the same directory. An `--output` that
11
- * includes a directory component is honoured verbatim.
12
- */
13
-
14
- import { existsSync, mkdirSync } from "node:fs";
15
- import { dirname, isAbsolute, join, resolve } from "node:path";
16
- import { findWorkspaceRoot } from "./root.ts";
17
-
18
- export interface TriageOpts {
19
- /** Logical command name — used in the auto-filename. */
20
- command: string;
21
- /** Run id (or undefined for ad-hoc artifacts). */
22
- runId?: number | null;
23
- /** API/collection name; falls back to `"adhoc"` when not known. */
24
- api?: string | null;
25
- /** Default extension (md / html / json). Without a leading dot. */
26
- ext: string;
27
- /** What the user typed in --output (may be undefined). */
28
- userOutput?: string;
29
- /** Optional explicit timestamp for tests. */
30
- now?: Date;
31
- }
32
-
33
- export interface ResolvedTriagePath {
34
- /** Absolute path to write. */
35
- absolute: string;
36
- /** Workspace-relative path for prettier console output. */
37
- relative: string;
38
- /** True when we landed under triage/ vs. honoured the user path. */
39
- underTriage: boolean;
40
- }
41
-
42
- function pad(n: number): string {
43
- return n < 10 ? `0${n}` : `${n}`;
44
- }
45
-
46
- function timestamp(d: Date): string {
47
- return `${d.getFullYear()}${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}`;
48
- }
49
-
50
- export function resolveTriageOutput(opts: TriageOpts): ResolvedTriagePath {
51
- const ws = findWorkspaceRoot();
52
- const root = ws.root;
53
- const ext = opts.ext.replace(/^\./, "");
54
- const ts = timestamp(opts.now ?? new Date());
55
- const apiSlug = opts.api ?? "adhoc";
56
- const runSlug = opts.runId != null ? `run-${opts.runId}` : "adhoc";
57
-
58
- // 1) User passed a path with a directory component → honour verbatim.
59
- if (opts.userOutput && /[\\/]/.test(opts.userOutput)) {
60
- const abs = isAbsolute(opts.userOutput) ? opts.userOutput : resolve(opts.userOutput);
61
- mkdirSync(dirname(abs), { recursive: true });
62
- return {
63
- absolute: abs,
64
- relative: relPath(abs, root),
65
- underTriage: false,
66
- };
67
- }
68
-
69
- // 2) Default location.
70
- const dir = join(root, "triage", apiSlug, runSlug);
71
- if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
72
- const basename = opts.userOutput ?? `${opts.command}-${ts}.${ext}`;
73
- const abs = join(dir, basename);
74
- return {
75
- absolute: abs,
76
- relative: relPath(abs, root),
77
- underTriage: true,
78
- };
79
- }
80
-
81
- function relPath(abs: string, root: string): string {
82
- if (abs.startsWith(root)) {
83
- const r = abs.slice(root.length).replace(/^[\\/]+/, "");
84
- return r.replace(/\\/g, "/");
85
- }
86
- return abs;
87
- }
@@ -1,47 +0,0 @@
1
- import type { Database } from "bun:sqlite";
2
- import type { Issue, LintConfig, LintStats } from "../core/lint/index.ts";
3
-
4
- export interface LintRunRow {
5
- id: number;
6
- spec_path: string;
7
- started_at: string;
8
- finished_at: string | null;
9
- total: number;
10
- high_count: number;
11
- medium_count: number;
12
- low_count: number;
13
- endpoint_count: number;
14
- }
15
-
16
- export function createLintRun(db: Database, specPath: string): number {
17
- const startedAt = new Date().toISOString();
18
- const stmt = db.prepare(
19
- "INSERT INTO lint_runs (spec_path, started_at) VALUES (?, ?)",
20
- );
21
- const info = stmt.run(specPath, startedAt) as { lastInsertRowid: number | bigint };
22
- return Number(info.lastInsertRowid);
23
- }
24
-
25
- export function finalizeLintRun(
26
- db: Database,
27
- id: number,
28
- issues: Issue[],
29
- stats: LintStats,
30
- config: LintConfig,
31
- ): void {
32
- db.prepare(
33
- `UPDATE lint_runs SET
34
- finished_at = ?,
35
- total = ?, high_count = ?, medium_count = ?, low_count = ?,
36
- endpoint_count = ?,
37
- config_json = ?, issues_json = ?
38
- WHERE id = ?`,
39
- ).run(
40
- new Date().toISOString(),
41
- stats.total, stats.high, stats.medium, stats.low,
42
- stats.endpoints,
43
- JSON.stringify({ rules: config.rules, heuristics: config.heuristics, ignore_paths: config.ignore_paths }),
44
- JSON.stringify(issues),
45
- id,
46
- );
47
- }