@kirrosh/zond 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +758 -3
- package/README.md +78 -15
- package/package.json +17 -10
- package/src/cli/argv.ts +122 -0
- package/src/cli/commands/add-api.ts +134 -0
- package/src/cli/commands/api/annotate/idempotency.ts +59 -0
- package/src/cli/commands/api/annotate/index.ts +525 -0
- package/src/cli/commands/api/annotate/lifecycle.ts +74 -0
- package/src/cli/commands/api/annotate/overlay.ts +206 -0
- package/src/cli/commands/api/annotate/pagination.ts +60 -0
- package/src/cli/commands/api/annotate/prompts.ts +183 -0
- package/src/cli/commands/api/annotate/readback.ts +58 -0
- package/src/cli/commands/api/annotate/resources.ts +91 -0
- package/src/cli/commands/api/annotate/seed-bodies.ts +61 -0
- package/src/cli/commands/audit.ts +480 -0
- package/src/cli/commands/bootstrap.ts +710 -0
- package/src/cli/commands/catalog.ts +35 -0
- package/src/cli/commands/check.ts +348 -0
- package/src/cli/commands/checks.ts +756 -0
- package/src/cli/commands/ci-init.ts +55 -6
- package/src/cli/commands/clean.ts +212 -0
- package/src/cli/commands/cleanup.ts +262 -0
- package/src/cli/commands/completions.ts +192 -0
- package/src/cli/commands/coverage.ts +605 -132
- package/src/cli/commands/db.ts +180 -8
- package/src/cli/commands/describe.ts +37 -2
- package/src/cli/commands/discover.ts +1236 -0
- package/src/cli/commands/doctor.ts +607 -0
- package/src/cli/commands/fixtures.ts +402 -0
- package/src/cli/commands/generate.ts +420 -47
- package/src/cli/commands/init/agents-md.ts +61 -0
- package/src/cli/commands/init/bootstrap.ts +108 -0
- package/src/cli/commands/init/index.ts +244 -0
- package/src/cli/commands/init/skills.ts +98 -0
- package/src/cli/commands/init/templates/agents.md +77 -0
- package/src/cli/commands/init/templates/markdown.d.ts +4 -0
- package/src/cli/commands/init/templates/skills/zond-checks.md +397 -0
- package/src/cli/commands/init/templates/skills/zond-triage.md +210 -0
- package/src/cli/commands/init/templates/skills/zond.md +651 -0
- package/src/cli/commands/init/templates/zond-config.yml +14 -0
- package/src/cli/commands/prepare-fixtures.ts +135 -0
- package/src/cli/commands/probe/mass-assignment.ts +503 -0
- package/src/cli/commands/probe/security.ts +454 -0
- package/src/cli/commands/probe/static.ts +255 -0
- package/src/cli/commands/probe/webhooks.ts +161 -0
- package/src/cli/commands/probe.ts +459 -0
- package/src/cli/commands/reference.ts +87 -0
- package/src/cli/commands/refresh-api.ts +169 -0
- package/src/cli/commands/remove-api.ts +150 -0
- package/src/cli/commands/report-bundle.ts +318 -0
- package/src/cli/commands/report.ts +241 -0
- package/src/cli/commands/request.ts +379 -4
- package/src/cli/commands/run.ts +911 -33
- package/src/cli/commands/session.ts +244 -0
- package/src/cli/commands/use.ts +74 -0
- package/src/cli/index.ts +36 -607
- package/src/cli/json-envelope.ts +112 -3
- package/src/cli/json-schemas.ts +263 -0
- package/src/cli/program.ts +218 -0
- package/src/cli/resolve.ts +105 -0
- package/src/cli/status-filter.ts +124 -0
- package/src/cli/util/api-context.ts +85 -0
- package/src/cli/version.ts +8 -0
- package/src/core/anti-fp/bootstrap.ts +34 -0
- package/src/core/anti-fp/index.ts +33 -0
- package/src/core/anti-fp/registry.ts +44 -0
- package/src/core/anti-fp/rules/baseline-echo.ts +74 -0
- package/src/core/anti-fp/rules/schemathesis/body_negation_becomes_valid.ts +52 -0
- package/src/core/anti-fp/rules/schemathesis/coverage_phase_boundary_positive.ts +38 -0
- package/src/core/anti-fp/rules/schemathesis/has_unverifiable_mutations.ts +35 -0
- package/src/core/anti-fp/rules/schemathesis/index.ts +24 -0
- package/src/core/anti-fp/rules/schemathesis/string_type_mutation_becomes_valid.ts +53 -0
- package/src/core/anti-fp/rules/subscription-gated/index.ts +11 -0
- package/src/core/anti-fp/rules/subscription-gated/paid-plan-403.ts +75 -0
- package/src/core/anti-fp/types.ts +68 -0
- package/src/core/checks/checks/_crud-helpers.ts +133 -0
- package/src/core/checks/checks/_negative_mutator.ts +133 -0
- package/src/core/checks/checks/_readback-helpers.ts +133 -0
- package/src/core/checks/checks/content_type_conformance.ts +39 -0
- package/src/core/checks/checks/cross_call_references.ts +134 -0
- package/src/core/checks/checks/ensure_resource_availability.ts +62 -0
- package/src/core/checks/checks/idempotency_replay.ts +246 -0
- package/src/core/checks/checks/ignored_auth.ts +211 -0
- package/src/core/checks/checks/index.ts +65 -0
- package/src/core/checks/checks/lifecycle_transitions.ts +273 -0
- package/src/core/checks/checks/missing_required_header.ts +40 -0
- package/src/core/checks/checks/negative_data_rejection.ts +45 -0
- package/src/core/checks/checks/not_a_server_error.ts +27 -0
- package/src/core/checks/checks/open_cors_on_sensitive.ts +131 -0
- package/src/core/checks/checks/pagination_invariants.ts +238 -0
- package/src/core/checks/checks/positive_data_acceptance.ts +36 -0
- package/src/core/checks/checks/rate_limit_headers_absent.ts +77 -0
- package/src/core/checks/checks/response_headers_conformance.ts +74 -0
- package/src/core/checks/checks/response_schema_conformance.ts +30 -0
- package/src/core/checks/checks/status_code_conformance.ts +61 -0
- package/src/core/checks/checks/unsupported_method.ts +63 -0
- package/src/core/checks/checks/use_after_free.ts +78 -0
- package/src/core/checks/index.ts +30 -0
- package/src/core/checks/mode.ts +79 -0
- package/src/core/checks/recommended-action.ts +64 -0
- package/src/core/checks/registry.ts +78 -0
- package/src/core/checks/runner.ts +874 -0
- package/src/core/checks/sarif.ts +230 -0
- package/src/core/checks/stateful.ts +121 -0
- package/src/core/checks/types.ts +189 -0
- package/src/core/classifier/recommended-action.ts +222 -0
- package/src/core/context/current.ts +51 -0
- package/src/core/context/session.ts +78 -0
- package/src/core/coverage/loader.ts +185 -0
- package/src/core/coverage/reasons.ts +300 -0
- package/src/core/diagnostics/db-analysis.ts +161 -12
- package/src/core/diagnostics/failure-class.ts +120 -0
- package/src/core/diagnostics/failure-hints.ts +212 -9
- package/src/core/diagnostics/spec-pointer.ts +99 -0
- package/src/core/diagnostics/suggested-fixes.ts +156 -0
- package/src/core/exporter/case-study/index.ts +270 -0
- package/src/core/exporter/curl.ts +40 -0
- package/src/core/exporter/exporter.ts +48 -0
- package/src/core/exporter/html-report/escape.ts +24 -0
- package/src/core/exporter/html-report/index.ts +479 -0
- package/src/core/exporter/html-report/script.ts +100 -0
- package/src/core/exporter/html-report/styles.ts +408 -0
- package/src/core/generator/chunker.ts +53 -15
- package/src/core/generator/coverage-phase.ts +0 -0
- package/src/core/generator/create-body.ts +89 -0
- package/src/core/generator/data-factory.ts +490 -33
- package/src/core/generator/describe.ts +1 -1
- package/src/core/generator/fixtures-builder.ts +325 -0
- package/src/core/generator/index.ts +7 -5
- package/src/core/generator/openapi-reader.ts +55 -3
- package/src/core/generator/path-param-disambig.ts +114 -0
- package/src/core/generator/resources-builder.ts +648 -0
- package/src/core/generator/schema-utils.ts +11 -3
- package/src/core/generator/serializer.ts +114 -15
- package/src/core/generator/suite-generator.ts +484 -77
- package/src/core/generator/types.ts +8 -0
- package/src/core/identity/identity-file.ts +129 -0
- package/src/core/lint/affects.ts +28 -0
- package/src/core/lint/config.ts +96 -0
- package/src/core/lint/format.ts +42 -0
- package/src/core/lint/index.ts +94 -0
- package/src/core/lint/reporter.ts +128 -0
- package/src/core/lint/rules/consistency.ts +158 -0
- package/src/core/lint/rules/heuristics.ts +97 -0
- package/src/core/lint/rules/strictness.ts +109 -0
- package/src/core/lint/types.ts +96 -0
- package/src/core/lint/walker.ts +248 -0
- package/src/core/meta/meta-store.ts +6 -73
- package/src/core/output/README.md +91 -0
- package/src/core/output/index.ts +13 -0
- package/src/core/output/run.ts +126 -0
- package/src/core/output/types.ts +129 -0
- package/src/core/parser/env-interpolation.ts +104 -0
- package/src/core/parser/filter.ts +57 -0
- package/src/core/parser/schema.ts +132 -5
- package/src/core/parser/types.ts +29 -2
- package/src/core/parser/variables.ts +0 -0
- package/src/core/parser/yaml-parser.ts +108 -13
- package/src/core/probe/bootstrap.ts +34 -0
- package/src/core/probe/dry-run-envelope.ts +57 -0
- package/src/core/probe/mass-assignment-probe-class.ts +198 -0
- package/src/core/probe/mass-assignment-probe.ts +1122 -0
- package/src/core/probe/mass-assignment-template.ts +212 -0
- package/src/core/probe/method-probe.ts +164 -0
- package/src/core/probe/method-shared.ts +69 -0
- package/src/core/probe/negative-probe.ts +691 -0
- package/src/core/probe/orphan-tracker.ts +188 -0
- package/src/core/probe/path-discovery.ts +440 -0
- package/src/core/probe/probe-harness.ts +120 -0
- package/src/core/probe/registry.ts +89 -0
- package/src/core/probe/runner.ts +136 -0
- package/src/core/probe/security-probe-class.ts +201 -0
- package/src/core/probe/security-probe.ts +1453 -0
- package/src/core/probe/shared.ts +505 -0
- package/src/core/probe/static-probe-class.ts +125 -0
- package/src/core/probe/types.ts +165 -0
- package/src/core/probe/verdict-aggregator.ts +33 -0
- package/src/core/probe/webhooks-probe.ts +284 -0
- package/src/core/reporter/console.ts +69 -4
- package/src/core/reporter/index.ts +2 -3
- package/src/core/reporter/json.ts +15 -2
- package/src/core/reporter/junit.ts +27 -12
- package/src/core/reporter/ndjson.ts +37 -0
- package/src/core/reporter/types.ts +3 -0
- package/src/core/runner/assertions.ts +62 -2
- package/src/core/runner/async-pool.ts +108 -0
- package/src/core/runner/auth-path.ts +8 -0
- package/src/core/runner/ci-context.ts +72 -0
- package/src/core/runner/executor.ts +391 -52
- package/src/core/runner/form-encode.ts +51 -0
- package/src/core/runner/http-client.ts +115 -7
- package/src/core/runner/learn-drift.ts +293 -0
- package/src/core/runner/preflight-vars.ts +149 -0
- package/src/core/runner/progress-tracker.ts +73 -0
- package/src/core/runner/rate-limiter.ts +203 -0
- package/src/core/runner/run-kind.ts +39 -0
- package/src/core/runner/schema-validator.ts +312 -0
- package/src/core/runner/send-request.ts +153 -20
- package/src/core/runner/types.ts +38 -0
- package/src/core/secrets/registry.ts +164 -0
- package/src/core/secrets/secrets-file.ts +115 -0
- package/src/core/selectors/operation-filter.ts +144 -0
- package/src/core/setup-api.ts +419 -17
- package/src/core/severity/category.ts +94 -0
- package/src/core/severity/index.ts +121 -0
- package/src/core/spec/layers.ts +154 -0
- package/src/core/util/format-eta.ts +21 -0
- package/src/core/utils.ts +5 -1
- package/src/core/workspace/config.ts +129 -0
- package/src/core/workspace/manifest.ts +283 -0
- package/src/core/workspace/output-rotation.ts +62 -0
- package/src/core/workspace/root.ts +94 -0
- package/src/core/workspace/triage-path.ts +87 -0
- package/src/db/lint-runs.ts +47 -0
- package/src/db/migrate.ts +126 -0
- package/src/db/migrations/0001_run_kind.sql +25 -0
- package/src/db/migrations/sql.d.ts +4 -0
- package/src/db/queries/collections.ts +133 -0
- package/src/db/queries/coverage.ts +9 -0
- package/src/db/queries/dashboard.ts +59 -0
- package/src/db/queries/results.ts +128 -0
- package/src/db/queries/runs.ts +235 -0
- package/src/db/queries/sessions.ts +42 -0
- package/src/db/queries/settings.ts +28 -0
- package/src/db/queries/types.ts +172 -0
- package/src/db/queries.ts +72 -802
- package/src/db/schema.ts +179 -48
- package/src/cli/commands/export.ts +0 -144
- package/src/cli/commands/guide.ts +0 -127
- package/src/cli/commands/init.ts +0 -57
- package/src/cli/commands/serve.ts +0 -81
- package/src/cli/commands/sync.ts +0 -269
- package/src/cli/commands/update.ts +0 -189
- package/src/cli/commands/validate.ts +0 -34
- package/src/core/exporter/postman.ts +0 -963
- package/src/core/generator/guide-builder.ts +0 -253
- package/src/core/meta/types.ts +0 -21
- package/src/core/parser/index.ts +0 -21
- package/src/core/runner/execute-run.ts +0 -132
- package/src/core/runner/index.ts +0 -12
- package/src/core/sync/spec-differ.ts +0 -38
- package/src/web/data/collection-state.ts +0 -362
- package/src/web/routes/api.ts +0 -314
- package/src/web/routes/dashboard.ts +0 -350
- package/src/web/routes/runs.ts +0 -64
- package/src/web/schemas.ts +0 -121
- package/src/web/server.ts +0 -134
- package/src/web/static/htmx.min.cjs +0 -1
- package/src/web/static/style.css +0 -1148
- package/src/web/views/endpoints-tab.ts +0 -174
- package/src/web/views/explorer-tab.ts +0 -402
- package/src/web/views/health-strip.ts +0 -92
- package/src/web/views/layout.ts +0 -48
- package/src/web/views/results.ts +0 -210
- package/src/web/views/runs-tab.ts +0 -126
- package/src/web/views/suites-tab.ts +0 -181
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
3
|
+
|
|
4
|
+
import { upsertAgentsBlock, type AgentsBlockResult } from "./agents-md.ts";
|
|
5
|
+
import {
|
|
6
|
+
detectStaleSkills,
|
|
7
|
+
pruneStaleSkills,
|
|
8
|
+
upsertSkills,
|
|
9
|
+
type SkillResult,
|
|
10
|
+
type StaleSkill,
|
|
11
|
+
} from "./skills.ts";
|
|
12
|
+
import zondConfigTemplate from "./templates/zond-config.yml" with { type: "text" };
|
|
13
|
+
|
|
14
|
+
export interface BootstrapOptions {
|
|
15
|
+
cwd?: string;
|
|
16
|
+
/** Whether to write/upsert AGENTS.md. Defaults to true. */
|
|
17
|
+
writeAgents?: boolean;
|
|
18
|
+
/** Whether to write Claude Code skills under .claude/skills/. Defaults to true. */
|
|
19
|
+
writeSkills?: boolean;
|
|
20
|
+
/** Remove legacy skill dirs (zond-base, zond-scenarios, …) instead of just warning. */
|
|
21
|
+
pruneStaleSkills?: boolean;
|
|
22
|
+
/** Override $HOME — used by tests and intentional overrides. */
|
|
23
|
+
home?: string;
|
|
24
|
+
dryRun?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface BootstrapResult {
|
|
28
|
+
cwd: string;
|
|
29
|
+
configPath: string;
|
|
30
|
+
configAction: "created" | "noop";
|
|
31
|
+
apisDir: string;
|
|
32
|
+
apisAction: "created" | "noop";
|
|
33
|
+
agents: AgentsBlockResult | null;
|
|
34
|
+
skills: SkillResult[];
|
|
35
|
+
/** Legacy skill dirs that exist on disk but are no longer in `SKILLS`. */
|
|
36
|
+
staleSkills: StaleSkill[];
|
|
37
|
+
/** Subset of `staleSkills` that were actually removed (empty unless `pruneStaleSkills`). */
|
|
38
|
+
prunedSkills: StaleSkill[];
|
|
39
|
+
warnings: string[];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Idempotent workspace bootstrap. Creates `zond.config.yml`, `apis/`, and
|
|
44
|
+
* (unless `writeAgents` is false) `AGENTS.md`.
|
|
45
|
+
*/
|
|
46
|
+
export function bootstrapWorkspace(opts: BootstrapOptions = {}): BootstrapResult {
|
|
47
|
+
const cwd = resolve(opts.cwd ?? process.cwd());
|
|
48
|
+
const warnings: string[] = [];
|
|
49
|
+
const writeAgents = opts.writeAgents ?? true;
|
|
50
|
+
const writeSkills = opts.writeSkills ?? true;
|
|
51
|
+
|
|
52
|
+
// 1. zond.config.yml
|
|
53
|
+
const configPath = join(cwd, "zond.config.yml");
|
|
54
|
+
let configAction: "created" | "noop" = "noop";
|
|
55
|
+
if (!existsSync(configPath)) {
|
|
56
|
+
if (!opts.dryRun) writeFileSync(configPath, zondConfigTemplate, "utf-8");
|
|
57
|
+
configAction = "created";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// 2. apis/
|
|
61
|
+
const apisDir = join(cwd, "apis");
|
|
62
|
+
let apisAction: "created" | "noop" = "noop";
|
|
63
|
+
if (!existsSync(apisDir)) {
|
|
64
|
+
if (!opts.dryRun) mkdirSync(apisDir, { recursive: true });
|
|
65
|
+
apisAction = "created";
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 3. AGENTS.md
|
|
69
|
+
let agents: AgentsBlockResult | null = null;
|
|
70
|
+
if (writeAgents) {
|
|
71
|
+
if (!opts.dryRun) {
|
|
72
|
+
agents = upsertAgentsBlock(cwd);
|
|
73
|
+
} else {
|
|
74
|
+
agents = { path: join(cwd, "AGENTS.md"), action: existsSync(join(cwd, "AGENTS.md")) ? "updated" : "created" };
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 4. .claude/skills/zond-*/SKILL.md
|
|
79
|
+
const skills: SkillResult[] = writeSkills ? upsertSkills(cwd, { dryRun: opts.dryRun }) : [];
|
|
80
|
+
|
|
81
|
+
// 5. Detect (and optionally prune) legacy skill dirs left over from
|
|
82
|
+
// retired templates. User-authored skill dirs are NOT touched —
|
|
83
|
+
// only names in `LEGACY_SKILL_NAMES` are considered.
|
|
84
|
+
const staleSkills = writeSkills ? detectStaleSkills(cwd) : [];
|
|
85
|
+
let prunedSkills: StaleSkill[] = [];
|
|
86
|
+
if (writeSkills && opts.pruneStaleSkills && staleSkills.length > 0) {
|
|
87
|
+
prunedSkills = pruneStaleSkills(cwd, { dryRun: opts.dryRun });
|
|
88
|
+
} else if (staleSkills.length > 0) {
|
|
89
|
+
for (const { name } of staleSkills) {
|
|
90
|
+
warnings.push(
|
|
91
|
+
`stale skill detected: .claude/skills/${name}/ — re-run with --prune-stale-skills to remove`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
cwd,
|
|
98
|
+
configPath,
|
|
99
|
+
configAction,
|
|
100
|
+
apisDir,
|
|
101
|
+
apisAction,
|
|
102
|
+
agents,
|
|
103
|
+
skills,
|
|
104
|
+
staleSkills,
|
|
105
|
+
prunedSkills,
|
|
106
|
+
warnings,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from "node:fs";
|
|
2
|
+
import { setupApi, type SetupApiResult } from "../../../core/setup-api.ts";
|
|
3
|
+
import { printError, printSuccess } from "../../output.ts";
|
|
4
|
+
import { jsonOk, jsonError, printJson } from "../../json-envelope.ts";
|
|
5
|
+
import { bootstrapWorkspace, type BootstrapResult } from "./bootstrap.ts";
|
|
6
|
+
|
|
7
|
+
export interface InitOptions {
|
|
8
|
+
// register-an-API options (existing)
|
|
9
|
+
name?: string;
|
|
10
|
+
spec?: string;
|
|
11
|
+
baseUrl?: string;
|
|
12
|
+
dir?: string;
|
|
13
|
+
force?: boolean;
|
|
14
|
+
insecure?: boolean;
|
|
15
|
+
dbPath?: string;
|
|
16
|
+
json?: boolean;
|
|
17
|
+
|
|
18
|
+
// workspace bootstrap (new)
|
|
19
|
+
workspace?: boolean;
|
|
20
|
+
withSpec?: string;
|
|
21
|
+
/** Skip writing AGENTS.md. */
|
|
22
|
+
noAgents?: boolean;
|
|
23
|
+
/** Skip writing Claude Code skills under .claude/skills/. */
|
|
24
|
+
noSkills?: boolean;
|
|
25
|
+
/** Remove legacy skill dirs (zond-base, zond-scenarios, …) — by default a warning is printed. */
|
|
26
|
+
pruneStaleSkills?: boolean;
|
|
27
|
+
/** Override cwd for bootstrap (used by tests; CLI always uses process.cwd()). */
|
|
28
|
+
cwd?: string;
|
|
29
|
+
/** Override $HOME for MCP install (used by tests). */
|
|
30
|
+
home?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type InitMode = "register" | "workspace" | "bootstrap+register";
|
|
34
|
+
|
|
35
|
+
function resolveMode(options: InitOptions): InitMode {
|
|
36
|
+
if (options.spec) return "register";
|
|
37
|
+
if (options.withSpec) return "bootstrap+register";
|
|
38
|
+
return "workspace";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function initCommand(options: InitOptions): Promise<number> {
|
|
42
|
+
// Reject conflicting combos
|
|
43
|
+
if (options.spec && options.workspace) {
|
|
44
|
+
const msg = "Cannot use --spec and --workspace together. Use --with-spec to bootstrap and register in one step.";
|
|
45
|
+
if (options.json) printJson(jsonError("init", [msg]));
|
|
46
|
+
else printError(msg);
|
|
47
|
+
return 2;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const mode = resolveMode(options);
|
|
51
|
+
const writeAgents = !options.noAgents;
|
|
52
|
+
const writeSkills = !options.noSkills;
|
|
53
|
+
|
|
54
|
+
try {
|
|
55
|
+
if (mode === "register") {
|
|
56
|
+
const result = await registerApi(options);
|
|
57
|
+
printRegisterResult(options, result);
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const bootstrap = bootstrapWorkspace({
|
|
62
|
+
writeAgents,
|
|
63
|
+
writeSkills,
|
|
64
|
+
pruneStaleSkills: options.pruneStaleSkills,
|
|
65
|
+
cwd: options.cwd,
|
|
66
|
+
home: options.home,
|
|
67
|
+
});
|
|
68
|
+
let register: SetupApiResult | null = null;
|
|
69
|
+
|
|
70
|
+
if (mode === "bootstrap+register") {
|
|
71
|
+
register = await registerApi({ ...options, spec: options.withSpec });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (options.json) {
|
|
75
|
+
const data: Record<string, unknown> = {
|
|
76
|
+
mode,
|
|
77
|
+
configPath: bootstrap.configPath,
|
|
78
|
+
configAction: bootstrap.configAction,
|
|
79
|
+
apisDir: bootstrap.apisDir,
|
|
80
|
+
apisAction: bootstrap.apisAction,
|
|
81
|
+
agentsPath: bootstrap.agents?.path ?? null,
|
|
82
|
+
agentsAction: bootstrap.agents?.action ?? null,
|
|
83
|
+
skills: bootstrap.skills.map((s) => ({ name: s.name, path: s.path, action: s.action })),
|
|
84
|
+
staleSkills: bootstrap.staleSkills.map((s) => ({ name: s.name, path: s.path })),
|
|
85
|
+
prunedSkills: bootstrap.prunedSkills.map((s) => ({ name: s.name, path: s.path })),
|
|
86
|
+
};
|
|
87
|
+
if (register) {
|
|
88
|
+
data.collectionId = register.collectionId;
|
|
89
|
+
data.baseDir = register.baseDir;
|
|
90
|
+
data.testPath = register.testPath;
|
|
91
|
+
data.endpoints = register.specEndpoints;
|
|
92
|
+
}
|
|
93
|
+
printJson(jsonOk("init", data, [...bootstrap.warnings, ...(register?.warnings ?? [])]));
|
|
94
|
+
} else {
|
|
95
|
+
printBootstrapResult(bootstrap, writeAgents);
|
|
96
|
+
if (register) printRegisterResult(options, register);
|
|
97
|
+
}
|
|
98
|
+
return 0;
|
|
99
|
+
} catch (err) {
|
|
100
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
101
|
+
if (options.json) printJson(jsonError("init", [message]));
|
|
102
|
+
else printError(message);
|
|
103
|
+
return 2;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function registerApi(options: InitOptions): Promise<SetupApiResult> {
|
|
108
|
+
const envVars: Record<string, string> = {};
|
|
109
|
+
if (options.baseUrl) envVars.base_url = options.baseUrl;
|
|
110
|
+
|
|
111
|
+
return await setupApi({
|
|
112
|
+
name: options.name,
|
|
113
|
+
spec: options.spec ?? options.withSpec,
|
|
114
|
+
dir: options.dir,
|
|
115
|
+
envVars: Object.keys(envVars).length > 0 ? envVars : undefined,
|
|
116
|
+
dbPath: options.dbPath,
|
|
117
|
+
force: options.force,
|
|
118
|
+
insecure: options.insecure,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function printRegisterResult(options: InitOptions, result: SetupApiResult): void {
|
|
123
|
+
if (options.json) {
|
|
124
|
+
// Only used by the legacy "register"-only path
|
|
125
|
+
printJson(jsonOk("init", {
|
|
126
|
+
mode: "register",
|
|
127
|
+
collectionId: result.collectionId,
|
|
128
|
+
baseDir: result.baseDir,
|
|
129
|
+
testPath: result.testPath,
|
|
130
|
+
endpoints: result.specEndpoints,
|
|
131
|
+
}, result.warnings));
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
printSuccess(`Created API '${options.name ?? "api"}' at ${result.baseDir} (${result.specEndpoints} endpoints)`);
|
|
135
|
+
if (result.warnings) {
|
|
136
|
+
for (const w of result.warnings) process.stderr.write(`Warning: ${w}\n`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function printBootstrapResult(b: BootstrapResult, writeAgents: boolean): void {
|
|
141
|
+
const lines: string[] = [];
|
|
142
|
+
lines.push(` ${verb(b.configAction)} zond.config.yml`);
|
|
143
|
+
lines.push(` ${verb(b.apisAction)} apis/`);
|
|
144
|
+
if (b.agents) lines.push(` ${verb(b.agents.action)} AGENTS.md`);
|
|
145
|
+
for (const s of b.skills) {
|
|
146
|
+
lines.push(` ${verb(s.action)} .claude/skills/${s.name}/SKILL.md`);
|
|
147
|
+
}
|
|
148
|
+
for (const s of b.prunedSkills) {
|
|
149
|
+
lines.push(` Removed .claude/skills/${s.name}/ (stale)`);
|
|
150
|
+
}
|
|
151
|
+
for (const w of b.warnings) {
|
|
152
|
+
process.stderr.write(`Warning: ${w}\n`);
|
|
153
|
+
}
|
|
154
|
+
process.stdout.write(lines.join("\n") + "\n");
|
|
155
|
+
if (!writeAgents) {
|
|
156
|
+
printSuccess("Workspace ready. Run `zond init --spec <path>` to register your first API.");
|
|
157
|
+
} else {
|
|
158
|
+
printSuccess("Workspace ready. See AGENTS.md for the CLI workflow.");
|
|
159
|
+
}
|
|
160
|
+
const apiNames = listExistingApis(b.cwd);
|
|
161
|
+
if (apiNames.length === 0) {
|
|
162
|
+
process.stderr.write(
|
|
163
|
+
`\nNext steps:\n` +
|
|
164
|
+
` 1. zond add api <name> --spec <path|url> # register API → builds .api-fixtures.yaml (manifest)\n` +
|
|
165
|
+
` 2. zond doctor --api <name> # gap report: which vars are UNSET in .env.yaml\n` +
|
|
166
|
+
` 3. zond prepare-fixtures --api <name> --apply [--seed] # fill .env.yaml values\n` +
|
|
167
|
+
`\nNote: zond init only refreshes workspace files (skills, AGENTS.md, zond.config.yml).\n` +
|
|
168
|
+
` It does NOT touch fixtures or .env.yaml — that's the doctor/prepare-fixtures loop above.\n`
|
|
169
|
+
);
|
|
170
|
+
} else {
|
|
171
|
+
const sample = apiNames[0]!;
|
|
172
|
+
process.stderr.write(
|
|
173
|
+
`\nFixtures untouched. zond init only refreshes skills/AGENTS.md/zond.config.yml.\n` +
|
|
174
|
+
`Verify env state with:\n` +
|
|
175
|
+
` zond doctor --api ${sample} --missing-only # show UNSET vars + blocked endpoints\n` +
|
|
176
|
+
` zond prepare-fixtures --api ${sample} --apply [--seed] # discover/seed values\n`
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function listExistingApis(cwd: string): string[] {
|
|
182
|
+
try {
|
|
183
|
+
const apisDir = `${cwd}/apis`;
|
|
184
|
+
if (!existsSync(apisDir)) return [];
|
|
185
|
+
return readdirSync(apisDir, { withFileTypes: true })
|
|
186
|
+
.filter((d) => d.isDirectory() && existsSync(`${apisDir}/${d.name}/spec.json`))
|
|
187
|
+
.map((d) => d.name)
|
|
188
|
+
.sort();
|
|
189
|
+
} catch {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function verb(action: "created" | "updated" | "noop"): string {
|
|
195
|
+
return action === "created" ? "Created" : action === "updated" ? "Updated" : "Up-to-date:";
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
import type { Command } from "commander";
|
|
199
|
+
import { globalJson } from "../../resolve.ts";
|
|
200
|
+
|
|
201
|
+
export function registerInit(program: Command): void {
|
|
202
|
+
program
|
|
203
|
+
.command("init [spec]")
|
|
204
|
+
.description("Bootstrap a workspace, or register an API when --spec is given")
|
|
205
|
+
.option("--name <name>", "API name (auto-detected from spec title if omitted)")
|
|
206
|
+
.option("--spec <path>", "Path to OpenAPI spec file (registers a single API)")
|
|
207
|
+
.option("--base-url <url>", "Override base URL")
|
|
208
|
+
.option("--dir <path>", "Target directory")
|
|
209
|
+
.option("--force", "Overwrite existing API collection")
|
|
210
|
+
.option("--insecure", "Skip TLS verification when fetching the spec")
|
|
211
|
+
.option("--db <path>", "Path to SQLite database file")
|
|
212
|
+
.option("--workspace", "Bootstrap a zond workspace (zond.config.yml, apis/, AGENTS.md)")
|
|
213
|
+
.option("--with-spec <path>", "Bootstrap workspace AND register first API from spec")
|
|
214
|
+
.option("--no-agents-md", "Skip writing AGENTS.md when bootstrapping")
|
|
215
|
+
.option("--no-skills", "Skip writing Claude Code skills under .claude/skills/")
|
|
216
|
+
.option(
|
|
217
|
+
"--prune-stale-skills",
|
|
218
|
+
"Remove .claude/skills/ dirs for retired template names (zond-base, zond-scenarios)",
|
|
219
|
+
)
|
|
220
|
+
.action(async (specPos: string | undefined, opts, cmd: Command) => {
|
|
221
|
+
const spec = opts.spec ?? specPos;
|
|
222
|
+
const json = globalJson(cmd);
|
|
223
|
+
if ((spec || opts.withSpec) && !json) {
|
|
224
|
+
process.stderr.write(
|
|
225
|
+
`Warning: 'zond init --spec' / '--with-spec' is deprecated. Use \`zond add api <name> --spec <path>\` (run \`zond init\` separately to bootstrap the workspace).\n`,
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
process.exitCode = await initCommand({
|
|
229
|
+
name: opts.name,
|
|
230
|
+
spec,
|
|
231
|
+
baseUrl: opts.baseUrl,
|
|
232
|
+
dir: opts.dir,
|
|
233
|
+
force: opts.force === true,
|
|
234
|
+
insecure: opts.insecure === true,
|
|
235
|
+
dbPath: opts.db,
|
|
236
|
+
workspace: opts.workspace === true,
|
|
237
|
+
withSpec: opts.withSpec,
|
|
238
|
+
noAgents: opts.agentsMd === false,
|
|
239
|
+
noSkills: opts.skills === false,
|
|
240
|
+
pruneStaleSkills: opts.pruneStaleSkills === true,
|
|
241
|
+
json,
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
|
|
4
|
+
import zondSkill from "./templates/skills/zond.md" with { type: "text" };
|
|
5
|
+
import checksSkill from "./templates/skills/zond-checks.md" with { type: "text" };
|
|
6
|
+
import triageSkill from "./templates/skills/zond-triage.md" with { type: "text" };
|
|
7
|
+
|
|
8
|
+
export interface SkillResult {
|
|
9
|
+
name: string;
|
|
10
|
+
path: string;
|
|
11
|
+
action: "created" | "updated" | "noop";
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface SkillTemplate {
|
|
15
|
+
name: string;
|
|
16
|
+
body: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const SKILLS: SkillTemplate[] = [
|
|
20
|
+
// Primary skill: artifact model + iron rules + full workflow
|
|
21
|
+
// (init → fixtures → annotate → generate → run → stateful checks →
|
|
22
|
+
// probes → coverage → share) + single-flow scenario authoring.
|
|
23
|
+
{ name: "zond", body: zondSkill },
|
|
24
|
+
// Depth-check reference: conformance + security + m-20 stateful
|
|
25
|
+
// (cross_call_references, idempotency_replay, pagination_invariants,
|
|
26
|
+
// lifecycle_transitions) with per-aspect annotate flow.
|
|
27
|
+
{ name: "zond-checks", body: checksSkill },
|
|
28
|
+
// Read-only triage of a finished run / probe artifact.
|
|
29
|
+
{ name: "zond-triage", body: triageSkill },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Names previously emitted by `upsertSkills` but no longer in `SKILLS`.
|
|
34
|
+
* Detected as stale by `detectStaleSkills` and removed by
|
|
35
|
+
* `pruneStaleSkills` (only when the user opts in via `--prune-stale-skills`).
|
|
36
|
+
*
|
|
37
|
+
* Append a name here whenever a skill template is retired. User-authored
|
|
38
|
+
* skills (any name NOT in this list) are never touched.
|
|
39
|
+
*/
|
|
40
|
+
const LEGACY_SKILL_NAMES: readonly string[] = [
|
|
41
|
+
"zond-base", // retired by skills-consolidation refactor (folded into zond)
|
|
42
|
+
"zond-scenarios", // retired by skills-consolidation refactor (folded into zond)
|
|
43
|
+
] as const;
|
|
44
|
+
|
|
45
|
+
export interface StaleSkill {
|
|
46
|
+
name: string;
|
|
47
|
+
path: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Returns directories under `<cwd>/.claude/skills/` whose name is in
|
|
52
|
+
* `LEGACY_SKILL_NAMES`. User-authored skill directories (any other
|
|
53
|
+
* name) are intentionally ignored.
|
|
54
|
+
*/
|
|
55
|
+
export function detectStaleSkills(cwd: string): StaleSkill[] {
|
|
56
|
+
const out: StaleSkill[] = [];
|
|
57
|
+
for (const name of LEGACY_SKILL_NAMES) {
|
|
58
|
+
const path = join(cwd, ".claude", "skills", name);
|
|
59
|
+
if (existsSync(path)) out.push({ name, path });
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Recursively removes the directories returned by `detectStaleSkills`.
|
|
66
|
+
* Returns the list of names that were actually removed.
|
|
67
|
+
*/
|
|
68
|
+
export function pruneStaleSkills(cwd: string, opts: { dryRun?: boolean } = {}): StaleSkill[] {
|
|
69
|
+
const stale = detectStaleSkills(cwd);
|
|
70
|
+
if (!opts.dryRun) {
|
|
71
|
+
for (const { path } of stale) rmSync(path, { recursive: true, force: true });
|
|
72
|
+
}
|
|
73
|
+
return stale;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Idempotently writes Claude Code skills into `<cwd>/.claude/skills/<name>/SKILL.md`.
|
|
78
|
+
* Body is identical to the in-binary template — overwrites on drift, noop on match.
|
|
79
|
+
*/
|
|
80
|
+
export function upsertSkills(cwd: string, opts: { dryRun?: boolean } = {}): SkillResult[] {
|
|
81
|
+
return SKILLS.map(({ name, body }) => {
|
|
82
|
+
const path = join(cwd, ".claude", "skills", name, "SKILL.md");
|
|
83
|
+
const desired = body.endsWith("\n") ? body : body + "\n";
|
|
84
|
+
|
|
85
|
+
if (!existsSync(path)) {
|
|
86
|
+
if (!opts.dryRun) {
|
|
87
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
88
|
+
writeFileSync(path, desired, "utf-8");
|
|
89
|
+
}
|
|
90
|
+
return { name, path, action: "created" };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const current = readFileSync(path, "utf-8");
|
|
94
|
+
if (current === desired) return { name, path, action: "noop" };
|
|
95
|
+
if (!opts.dryRun) writeFileSync(path, desired, "utf-8");
|
|
96
|
+
return { name, path, action: "updated" };
|
|
97
|
+
});
|
|
98
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
## API testing with zond
|
|
2
|
+
|
|
3
|
+
This workspace uses [zond](https://github.com/kirrosh/zond) for API testing — CLI
|
|
4
|
+
only, no MCP server in this workspace.
|
|
5
|
+
|
|
6
|
+
### Skills
|
|
7
|
+
|
|
8
|
+
- **`.claude/skills/zond/SKILL.md` (primary)** — artifact model + iron
|
|
9
|
+
rules + full workflow: fixtures → annotate → generate → smoke → CRUD
|
|
10
|
+
→ stateful checks → probes → coverage → report, plus single-flow
|
|
11
|
+
scenario authoring. Loads on workspace touch and on intent ("audit
|
|
12
|
+
this API", "find bugs", "write a test for X flow").
|
|
13
|
+
- **`.claude/skills/zond-checks/SKILL.md`** — depth-check reference:
|
|
14
|
+
conformance + security + m-20 stateful invariants
|
|
15
|
+
(cross_call_references, idempotency_replay, pagination_invariants,
|
|
16
|
+
lifecycle_transitions) and the `zond api annotate dump+apply` flow.
|
|
17
|
+
- **`.claude/skills/zond-triage/SKILL.md`** — read-only triage of a
|
|
18
|
+
finished run / probe artifact. Routes by `recommended_action` enum.
|
|
19
|
+
|
|
20
|
+
Both skills work off the per-API artifacts written by `zond add api`:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
apis/<name>/
|
|
24
|
+
spec.json # dereferenced OpenAPI (machine source — only generators read it)
|
|
25
|
+
.api-catalog.yaml # endpoint index (cheap to read, agent-friendly)
|
|
26
|
+
.api-resources.yaml # CRUD chains, FK deps, ETag/soft-delete flags
|
|
27
|
+
.api-fixtures.yaml # MANIFEST: required {{vars}} (read-only, auto-generated)
|
|
28
|
+
.env.yaml # VALUES: variable values (user-edited; auto-gitignored)
|
|
29
|
+
tests/ scenarios/ probes/
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`.api-fixtures.yaml` is the **manifest** (single source of truth for the
|
|
33
|
+
list of vars an API needs) and `.env.yaml` holds their **values**. Don't
|
|
34
|
+
add a key to `.env.yaml` that's not in the manifest — it'll be warned and
|
|
35
|
+
ignored. A missing entry in the manifest is a generator/manifest bug, not
|
|
36
|
+
an env fix.
|
|
37
|
+
|
|
38
|
+
### Setup flow
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
zond init # bootstrap workspace (no fixture changes)
|
|
42
|
+
zond add api <name> --spec <path-or-url> # register API + emit manifest + seed empty .env.yaml
|
|
43
|
+
zond doctor --api <name> --missing-only # gap report: which vars are UNSET
|
|
44
|
+
zond prepare-fixtures --api <name> --apply [--seed] # fill .env.yaml from live API
|
|
45
|
+
zond doctor --api <name> # re-check (exit 0 = ready)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
What each step does to `.env.yaml`:
|
|
49
|
+
|
|
50
|
+
| Command | Touches `.env.yaml`? |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `zond init` | no — only writes workspace/skills files |
|
|
53
|
+
| `zond add api` | seeds skeleton with empty placeholders for every required var |
|
|
54
|
+
| `zond doctor` | no — read-only diagnostic |
|
|
55
|
+
| `zond prepare-fixtures --apply` | writes discovered values (`.bak` backup); `--seed` POST-creates resources when list endpoints return `[]` |
|
|
56
|
+
| `zond refresh-api` | no — only re-snapshots `spec.json` and rebuilds the manifest |
|
|
57
|
+
|
|
58
|
+
`zond refresh-api <name> [--spec <new-source>]` re-snapshots when the upstream
|
|
59
|
+
spec changes.
|
|
60
|
+
|
|
61
|
+
**Re-running `zond init`** is safe and expected after a CLI upgrade: it
|
|
62
|
+
re-emits skills/AGENTS.md/zond.config.yml only. Fixtures stay exactly as
|
|
63
|
+
they were — never relies on init to fill `.env.yaml`.
|
|
64
|
+
|
|
65
|
+
### Mandatory rules (mirrored from the skills — non-negotiable)
|
|
66
|
+
|
|
67
|
+
- **NEVER read raw OpenAPI/Swagger** with Read/cat/grep — use the artifacts
|
|
68
|
+
in `apis/<name>/.api-*.yaml`. Drop into `spec.json` only when a probe
|
|
69
|
+
generator needs full schemas.
|
|
70
|
+
- **NEVER use curl/wget** — use `zond request <method> <url>` for ad-hoc HTTP.
|
|
71
|
+
- **NEVER write test YAML from scratch for autogen flows** — start with
|
|
72
|
+
`zond generate`, then edit failures. (Hand-written YAML is fine for
|
|
73
|
+
scenarios.)
|
|
74
|
+
- **NEVER hardcode tokens** — `apis/<name>/.env.yaml` (auto-gitignored),
|
|
75
|
+
reference as `{{auth_token}}`.
|
|
76
|
+
- **`recommended_action: report_backend_bug` (5xx) → STOP**, do not edit
|
|
77
|
+
assertions to make the test pass.
|