feat(schema): retire schema_agent_metadata JSON in favor of catalog-only delivery
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -12,12 +12,10 @@ policy_prepare_runtime "$ROOT"
|
||||
|
||||
tmp="$(mktemp -d)"
|
||||
exec_tmp="$(policy_runtime_mktemp_dir dws-generated-drift)"
|
||||
metadata_generator="$exec_tmp/schema-agent-metadata"
|
||||
catalog_generator="$exec_tmp/schema-catalog"
|
||||
param_aliases_generator="$exec_tmp/param-aliases"
|
||||
trap 'rm -rf "$tmp" "$exec_tmp"' EXIT HUP INT TERM
|
||||
|
||||
go build -o "$metadata_generator" ./internal/generator/cmd_schema_agent_metadata
|
||||
go build -a -o "$catalog_generator" ./internal/generator/cmd_schema_catalog
|
||||
go build -o "$param_aliases_generator" ./internal/generator/cmd_param_aliases
|
||||
|
||||
@@ -45,30 +43,16 @@ fi
|
||||
selection_guard="$tmp/selection-hints"
|
||||
cp -R internal/cli/schema_hints/selection "$selection_guard"
|
||||
|
||||
metadata_tmp="$tmp/metadata"
|
||||
audit_tmp="$tmp/audit.json"
|
||||
catalog_tmp="$tmp/schema_catalog"
|
||||
catalog_tmp_second="$tmp/schema_catalog-second"
|
||||
param_aliases_tmp="$tmp/param_aliases_generated.go"
|
||||
param_aliases_tmp_second="$tmp/param_aliases_generated-second.go"
|
||||
|
||||
"$metadata_generator" \
|
||||
-root . \
|
||||
-registry internal/cli/schema_command_registry \
|
||||
-output-dir "$metadata_tmp" \
|
||||
-audit-output "$audit_tmp"
|
||||
|
||||
if ! diff -qr internal/cli/schema_agent_metadata "$metadata_tmp" >/dev/null; then
|
||||
printf '%s\n' 'generated drift: internal/cli/schema_agent_metadata is stale' >&2
|
||||
printf '%s\n' 'run: make generate-schema' >&2
|
||||
diff -ru internal/cli/schema_agent_metadata "$metadata_tmp" || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! cmp -s internal/cli/schema_agent_metadata_audit.json "$audit_tmp"; then
|
||||
printf '%s\n' 'generated drift: internal/cli/schema_agent_metadata_audit.json is stale' >&2
|
||||
printf '%s\n' 'run: make generate-schema' >&2
|
||||
diff -u internal/cli/schema_agent_metadata_audit.json "$audit_tmp" || true
|
||||
# Retired intermediate: schema_agent_metadata/ must not reappear as a delivery
|
||||
# artifact. Catalog generation injects Agent metadata in-memory only.
|
||||
if [ -e internal/cli/schema_agent_metadata ] || [ -e internal/cli/schema_agent_metadata_audit.json ]; then
|
||||
printf '%s\n' 'generated drift: retired schema_agent_metadata delivery artifact is present' >&2
|
||||
printf '%s\n' 'remove internal/cli/schema_agent_metadata/ and schema_agent_metadata_audit.json' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
@@ -28,15 +28,17 @@ registry_count="$(jq -r '.tools | length' "$catalog")"
|
||||
catalog_count="$registry_count"
|
||||
catalog_product_count="$(jq -r '.catalog.count' "$catalog")"
|
||||
mcp_snapshot_registry_count="$(jq -r '.coverage.surface_tools' internal/cli/schema_mcp_metadata.json)"
|
||||
agent_registry_count="$(jq -r '.coverage.surface_tools' internal/cli/schema_agent_metadata/index.json)"
|
||||
agent_product_count="$(jq -r '.coverage.products_with_metadata' internal/cli/schema_agent_metadata/index.json)"
|
||||
agent_selection_count="$(jq -r '[.coverage.tools_with_use_when, .coverage.tools_with_avoid_when, .coverage.tools_with_examples, .coverage.tools_with_interface_mode] | min' internal/cli/schema_agent_metadata/index.json)"
|
||||
# Agent metadata is no longer a shipped intermediate. Selection completeness is
|
||||
# proven on the Catalog itself (every tool/product carries Agent prose).
|
||||
agent_registry_count="$registry_count"
|
||||
agent_product_count="$catalog_product_count"
|
||||
agent_selection_count="$(jq -r '[.tools[] | select((.use_when|type)=="array" and (.avoid_when|type)=="array" and (.examples|type)=="array" and ((.interface_mode//"")|length)>0)] | length' "$catalog")"
|
||||
if [ "$agent_registry_count" != "$registry_count" ] ||
|
||||
[ "$agent_product_count" != "$catalog_product_count" ] ||
|
||||
[ "$agent_selection_count" != "$registry_count" ]; then
|
||||
printf 'generated schema counts disagree: registry=%s catalog=%s products=%s agent=%s/%s\n' \
|
||||
printf 'generated schema counts disagree: registry=%s catalog=%s products=%s selection=%s\n' \
|
||||
"$registry_count" "$catalog_count" "$catalog_product_count" \
|
||||
"$agent_product_count" "$agent_registry_count" >&2
|
||||
"$agent_selection_count" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -110,10 +112,8 @@ if ! jq -e '
|
||||
fi
|
||||
|
||||
catalog_registry_hash="$(jq -r '.surface_hash' "$catalog")"
|
||||
agent_registry_hash="$(jq -r '.surface_hash' internal/cli/schema_agent_metadata/index.json)"
|
||||
if [ "$catalog_registry_hash" != "$agent_registry_hash" ]; then
|
||||
printf 'schema CommandRegistry hashes disagree: catalog=%s agent=%s\n' \
|
||||
"$catalog_registry_hash" "$agent_registry_hash" >&2
|
||||
if [ -z "$catalog_registry_hash" ] || [ "$catalog_registry_hash" = "null" ]; then
|
||||
printf 'schema Catalog is missing surface_hash\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -256,13 +256,17 @@ if policy_search_paths 'mcp-gw\.dingtalk\.com|mcp\.dingtalk\.com/server|Authoriz
|
||||
"$catalog" \
|
||||
internal/cli/schema_mcp_metadata.json \
|
||||
internal/cli/schema_mcp_service_review.json \
|
||||
internal/cli/schema_agent_metadata \
|
||||
internal/cli/schema_parameter_bindings.json \
|
||||
internal/cli/schema_hints; then
|
||||
printf '%s\n' 'schema assets contain endpoint or credential material' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -e internal/cli/schema_agent_metadata ] || [ -e internal/cli/schema_agent_metadata_audit.json ]; then
|
||||
printf '%s\n' 'retired schema_agent_metadata delivery artifact must not be present' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if policy_search_go '\.ListTools\(' internal/app internal/cli; then
|
||||
printf '%s\n' 'startup/schema packages must not call MCP tools/list' >&2
|
||||
exit 1
|
||||
|
||||
@@ -39,8 +39,12 @@ fi
|
||||
|
||||
# The registry argument is validation-only and all go:generate outputs must be
|
||||
# downstream assets. Reject any directive that targets the reviewed input.
|
||||
if ! grep -Eq '^//go:generate .*cmd_schema_agent_metadata .* -registry internal/cli/schema_command_registry ' internal/cli/gen.go; then
|
||||
printf '%s\n' 'go generate must validate the reviewed CommandRegistry explicitly' >&2
|
||||
if ! grep -Eq '^//go:generate .*cmd_schema_catalog ' internal/cli/gen.go; then
|
||||
printf '%s\n' 'go generate must register the Catalog generator' >&2
|
||||
exit 1
|
||||
fi
|
||||
if grep -E '^//go:generate' internal/cli/gen.go | grep -Eq 'cmd_schema_agent_metadata|schema_agent_metadata'; then
|
||||
printf '%s\n' 'go generate must not regenerate retired schema_agent_metadata/' >&2
|
||||
exit 1
|
||||
fi
|
||||
if policy_search_go '^//go:generate .*-(output|output-dir|audit-output)(=|[[:space:]]+)([^[:space:]]*/)?schema_command_registry\.json([[:space:]]|$)' \
|
||||
@@ -51,11 +55,20 @@ if policy_search_go '^//go:generate .*-(output|output-dir|audit-output)(=|[[:spa
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Embedded Agent/MCP/parameter metadata is intentionally expensive and must be
|
||||
# Embedded MCP/parameter metadata is intentionally expensive and must be
|
||||
# parsed only through its sync.Once accessor. Each raw loader is allowed at
|
||||
# exactly two production locations: its declaration and the assignment inside
|
||||
# that accessor. Any third reference is an eager initializer or an accessor
|
||||
# bypass and fails this static check.
|
||||
# Agent metadata embed/loader is retired; production must not reopen it.
|
||||
if policy_search_production_go 'go:embed schema_agent_metadata' internal/cli; then
|
||||
printf '%s\n' 'schema_agent_metadata must not be re-embedded' >&2
|
||||
exit 1
|
||||
fi
|
||||
if policy_search_production_go 'loadEmbeddedAgentMetadata\(' internal/cli; then
|
||||
printf '%s\n' 'retired loadEmbeddedAgentMetadata must not remain in production code' >&2
|
||||
exit 1
|
||||
fi
|
||||
check_schema_loader_references() {
|
||||
loader="$1"
|
||||
allowed="$2"
|
||||
@@ -73,9 +86,6 @@ check_schema_loader_references() {
|
||||
fi
|
||||
}
|
||||
|
||||
check_schema_loader_references \
|
||||
'loadEmbeddedAgentMetadata' \
|
||||
'^internal/cli/schema_agent_metadata\.go:[0-9]+:(func loadEmbeddedAgentMetadata\(\) embeddedAgentMetadata \{|[[:space:]]*runtimeEmbeddedAgentMetadataLazy\.metadata = loadEmbeddedAgentMetadata\(\))$'
|
||||
check_schema_loader_references \
|
||||
'loadEmbeddedMCPMetadata' \
|
||||
'^internal/cli/runtime_schema\.go:[0-9]+:(func loadEmbeddedMCPMetadata\(\) embeddedMCPMetadata \{|[[:space:]]*runtimeEmbeddedMCPMetadataLazy\.metadata = loadEmbeddedMCPMetadata\(\))$'
|
||||
|
||||
Reference in New Issue
Block a user