1- import { serializeResult } from '../../../lib' ;
1+ import { ValidationError , serializeResult } from '../../../lib' ;
22import { getErrorMessage } from '../../errors' ;
33import { getDatasetStatus } from '../../operations/dataset' ;
44import type { DatasetStatusResult } from '../../operations/dataset' ;
5+ import { withCommandRunTelemetry } from '../../telemetry/cli-command-run.js' ;
6+ import { FilterState , FilterType , standardize } from '../../telemetry/schemas/common-shapes.js' ;
57import { COMMAND_DESCRIPTIONS } from '../../tui/copy' ;
68import { requireProject } from '../../tui/guards' ;
79import type { ResourceStatusEntry } from './action' ;
@@ -73,48 +75,58 @@ export const registerStatus = (program: Command) => {
7375 . action ( async ( cliOptions : StatusCliOptions ) => {
7476 requireProject ( ) ;
7577
78+ const telemetryAttrs = {
79+ filter_type : standardize ( FilterType , cliOptions . type ?? 'none' ) ,
80+ filter_state : standardize ( FilterState , cliOptions . state ?? 'none' ) ,
81+ } ;
82+
7683 // Validate --type
7784 if ( cliOptions . type && ! ( VALID_RESOURCE_TYPES as readonly string [ ] ) . includes ( cliOptions . type ) ) {
78- render (
79- < Text color = "red" >
80- Invalid resource type '{ cliOptions . type } '. Valid types: { VALID_RESOURCE_TYPES . join ( ', ' ) }
81- </ Text >
82- ) ;
85+ const msg = `Invalid resource type '${ cliOptions . type } '. Valid types: ${ VALID_RESOURCE_TYPES . join ( ', ' ) } ` ;
86+ await withCommandRunTelemetry ( 'status' , telemetryAttrs , ( ) => ( {
87+ success : false as const ,
88+ error : new ValidationError ( msg ) ,
89+ } ) ) ;
90+ render ( < Text color = "red" > { msg } </ Text > ) ;
8391 return ;
8492 }
8593
8694 // Validate --state
8795 if ( cliOptions . state && ! ( VALID_STATES as readonly string [ ] ) . includes ( cliOptions . state ) ) {
88- render (
89- < Text color = "red" >
90- Invalid state '{ cliOptions . state } '. Valid states: { VALID_STATES . join ( ', ' ) }
91- </ Text >
92- ) ;
96+ const msg = `Invalid state '${ cliOptions . state } '. Valid states: ${ VALID_STATES . join ( ', ' ) } ` ;
97+ await withCommandRunTelemetry ( 'status' , telemetryAttrs , ( ) => ( {
98+ success : false as const ,
99+ error : new ValidationError ( msg ) ,
100+ } ) ) ;
101+ render ( < Text color = "red" > { msg } </ Text > ) ;
93102 return ;
94103 }
95104
96105 try {
97- const context = await loadStatusConfig ( ) ;
98-
99106 // Direct runtime lookup by ID
100107 if ( cliOptions . runtimeId ) {
101- const result = await handleRuntimeLookup ( context , {
102- agentRuntimeId : cliOptions . runtimeId ,
103- targetName : cliOptions . target ,
108+ const result = await withCommandRunTelemetry ( 'status' , telemetryAttrs , async ( ) => {
109+ const context = await loadStatusConfig ( ) ;
110+ return handleRuntimeLookup ( context , {
111+ agentRuntimeId : cliOptions . runtimeId ! ,
112+ targetName : cliOptions . target ,
113+ } ) ;
104114 } ) ;
105115
106- if ( cliOptions . json ) {
107- console . log ( JSON . stringify ( serializeResult ( result ) , null , 2 ) ) ;
108- return ;
116+ if ( ! result . success ) {
117+ if ( cliOptions . json ) {
118+ console . log ( JSON . stringify ( serializeResult ( result ) , null , 2 ) ) ;
119+ } else {
120+ render ( < Text color = "red" > { result . error . message } </ Text > ) ;
121+ }
122+ process . exit ( 1 ) ;
109123 }
110124
111- if ( ! result . success ) {
112- render ( < Text color = "red" > { result . error . message } </ Text > ) ;
125+ if ( cliOptions . json ) {
126+ console . log ( JSON . stringify ( serializeResult ( result ) , null , 2 ) ) ;
113127 return ;
114128 }
115-
116129 const runtimeStatus = result . runtimeStatus ? `Runtime status: ${ result . runtimeStatus } ` : '' ;
117-
118130 render (
119131 < Text >
120132 AgentCore Status - { result . runtimeId } (target: { result . targetName } )
@@ -125,22 +137,23 @@ export const registerStatus = (program: Command) => {
125137 }
126138
127139 // Default path: show all resource types with deployment state
128- const result = await handleProjectStatus ( context , {
129- targetName : cliOptions . target ,
140+ const result = await withCommandRunTelemetry ( 'status' , telemetryAttrs , async ( ) => {
141+ const context = await loadStatusConfig ( ) ;
142+ return handleProjectStatus ( context , { targetName : cliOptions . target } ) ;
130143 } ) ;
131144
132- if ( cliOptions . json ) {
133- if ( result . success ) {
134- const filtered = filterResources ( result . resources , cliOptions ) ;
135- console . log ( JSON . stringify ( { ...result , resources : filtered } , null , 2 ) ) ;
136- } else {
145+ if ( ! result . success ) {
146+ if ( cliOptions . json ) {
137147 console . log ( JSON . stringify ( serializeResult ( result ) , null , 2 ) ) ;
148+ } else {
149+ render ( < Text color = "red" > { result . error . message } </ Text > ) ;
138150 }
139- return ;
151+ process . exit ( 1 ) ;
140152 }
141153
142- if ( ! result . success ) {
143- render ( < Text color = "red" > { result . error . message } </ Text > ) ;
154+ if ( cliOptions . json ) {
155+ const filtered = filterResources ( result . resources , cliOptions ) ;
156+ console . log ( JSON . stringify ( { ...serializeResult ( result ) , resources : filtered } , null , 2 ) ) ;
144157 return ;
145158 }
146159
@@ -162,7 +175,7 @@ export const registerStatus = (program: Command) => {
162175 // Fetch enriched dataset info when --type dataset is specified
163176 let datasetDetails : DatasetStatusResult [ ] = [ ] ;
164177 if ( cliOptions . type === 'dataset' && datasets . length > 0 && result . targetRegion && result . targetName ) {
165- const deployedState = context . deployedState ;
178+ const deployedState = result . deployedState ;
166179 const targetResources = deployedState . targets ?. [ result . targetName ] ?. resources ;
167180 const deployedDatasets = targetResources ?. datasets ?? { } ;
168181
0 commit comments