Files
dingtalk-workspace-cli/internal/cli/schema_identity_resolver.go
T
玉澜andCursor a26d219b27 refactor(schema): remove cli contract aliases; single entry at corecmd/contract
Drop the dual-entry thin alias layer so helpers/shortcut/framework author
contract.* types directly; keep only AnnotateRuntime* delivery helpers in cli
and document the corecmd→cli seam.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-01 19:51:54 +08:00

65 lines
2.1 KiB
Go

// Copyright 2026 Alibaba Group
// Licensed under the Apache License, Version 2.0 (the "License");
package cli
import (
"encoding/json"
"strings"
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/internal/corecmd/contract"
"github.com/spf13/cobra"
)
// commandRegistryIdentityProvenance records one selected registry identity and
// any agreeing implementation evidence. Native/manual annotations never
// compete for identity here: the Cobra binder has already rejected every
// disagreement before a ToolSpec can be assembled.
func commandRegistryIdentityProvenance(command BoundCommandSpec) contract.FieldProvenance {
canonical := strings.TrimSpace(command.CanonicalPath)
value, _ := json.Marshal(canonical)
selected := true
precedence := "command_registry"
candidates := []contract.FieldCandidateProvenance{{
Value: append(json.RawMessage(nil), value...),
Source: command.Source,
SourceRef: command.PrimaryCLIPath,
Precedence: precedence,
ReviewReason: command.ReviewReason,
Selected: &selected,
}}
// Cobra does not expose an annotation-only interface in older versions, so
// collect evidence directly while retaining the exact reviewed CLI path.
appendEvidence := func(path string, leaf *cobra.Command) {
if leaf == nil {
return
}
if productID, toolName, sourceRef := runtimeSchemaAnnotations(leaf); productID != "" && toolName != "" {
nativeValue, _ := json.Marshal(productID + "." + toolName)
unselected := false
candidates = append(candidates, contract.FieldCandidateProvenance{
Value: nativeValue,
Source: "native_annotation",
SourceRef: defaultString(strings.TrimSpace(sourceRef), path),
Precedence: "native_annotation",
Selected: &unselected,
})
}
}
appendEvidence(command.PrimaryCLIPath, command.PrimaryCommand)
for _, alias := range command.AliasCommands {
appendEvidence(alias.Path, alias.Command)
}
return contract.FieldProvenance{
Value: value,
Source: command.Source,
SourceRef: command.PrimaryCLIPath,
Precedence: precedence,
Resolution: "registry_identity",
ReviewReason: command.ReviewReason,
Candidates: candidates,
}
}