(deps commandDeps)
| 181 | } |
| 182 | |
| 183 | func newChannelSendCommand(deps commandDeps) *cobra.Command { |
| 184 | var bodyRaw string |
| 185 | var idempotencyKey string |
| 186 | flags := coordinationMetadataFlags{kind: string(contract.CoordinationMessageStatus)} |
| 187 | |
| 188 | cmd := &cobra.Command{ |
| 189 | Use: "send <channel>", |
| 190 | Short: "Send one task-run coordination message", |
| 191 | Args: exactOneNonBlankArg(), |
| 192 | Example: ` # Send a non-authoritative status message for a run |
| 193 | agh ch send coord-run-123 \ |
| 194 | --task-id task-123 \ |
| 195 | --run-id run-123 \ |
| 196 | --kind status \ |
| 197 | --correlation-id run-123 \ |
| 198 | --body '{"status":"investigating"}' |
| 199 | |
| 200 | # Report a blocker in the same task-bound channel |
| 201 | agh ch send coord-run-123 \ |
| 202 | --task-id task-123 \ |
| 203 | --run-id run-123 \ |
| 204 | --kind blocker \ |
| 205 | --correlation-id run-123 \ |
| 206 | --body '{"blocked_by":"missing credentials"}'`, |
| 207 | RunE: func(cmd *cobra.Command, args []string) error { |
| 208 | channel := strings.TrimSpace(args[0]) |
| 209 | flags.kindExplicit = cmd.Flags().Changed(agentKernelKindKey) |
| 210 | body, err := parseNetworkJSONValue("--body", bodyRaw) |
| 211 | if err != nil { |
| 212 | return err |
| 213 | } |
| 214 | metadata, err := flags.metadata(channel, contract.CoordinationMessageStatus, true) |
| 215 | if err != nil { |
| 216 | return err |
| 217 | } |
| 218 | if metadata.MessageKind == contract.CoordinationMessageReply { |
| 219 | return errors.New("cli: use `agh ch reply --to-message` for reply messages") |
| 220 | } |
| 221 | request := AgentChannelSendRequest{ |
| 222 | Body: body, |
| 223 | Metadata: metadata, |
| 224 | IdempotencyKey: strings.TrimSpace(idempotencyKey), |
| 225 | } |
| 226 | if err := contract.ValidateNoRawClaimTokenField(request); err != nil { |
| 227 | return err |
| 228 | } |
| 229 | |
| 230 | client, err := clientFromDeps(deps) |
| 231 | if err != nil { |
| 232 | return err |
| 233 | } |
| 234 | credentials, err := requireAgentCommandIdentity(cmd.Context(), deps, client, agentActionCLI("ch.send")) |
| 235 | if err != nil { |
| 236 | return err |
| 237 | } |
| 238 | message, err := client.AgentChannelSend(cmd.Context(), channel, request, credentials) |
| 239 | if err != nil { |
| 240 | return err |
no test coverage detected