@@ -15,7 +15,7 @@ interface Task {
1515 content : string ;
1616 status : string ;
1717 priority : number ;
18- labels ?: string [ ] ;
18+ labels ?: string [ ] | string ;
1919 due_date ?: string ;
2020 created_at ?: string ;
2121 updated_at ?: string ;
@@ -33,10 +33,26 @@ interface Comment {
3333 created_at ?: string ;
3434}
3535
36+ function parsePriority ( value : string ) : number {
37+ const n = parseInt ( value , 10 ) ;
38+ if ( isNaN ( n ) || n < 1 || n > 4 ) {
39+ throw new Error ( "Priority must be 1, 2, 3, or 4." ) ;
40+ }
41+ return n ;
42+ }
43+
44+ function parsePositiveInt ( value : string ) : number {
45+ const n = parseInt ( value , 10 ) ;
46+ if ( isNaN ( n ) || n < 1 ) {
47+ throw new Error ( "Must be a positive integer." ) ;
48+ }
49+ return n ;
50+ }
51+
3652const tasksList = new Command ( "list" )
3753 . description ( "List tasks" )
3854 . option ( "--completed" , "Include completed tasks" )
39- . option ( "--limit <n>" , "Limit results" , parseInt )
55+ . option ( "--limit <n>" , "Limit results" , parsePositiveInt )
4056 . option ( "--json" , "Output raw JSON" )
4157 . addHelpText ( "after" , `
4258Examples:
@@ -82,7 +98,7 @@ Examples:
8298const tasksCreate = new Command ( "create" )
8399 . description ( "Create a new task" )
84100 . argument ( "<content>" , "Task content" )
85- . option ( "--priority <n>" , "Priority 1-4 (default: 1)" , ( v : string ) => parseInt ( v , 10 ) , 1 )
101+ . option ( "--priority <n>" , "Priority 1-4 (default: 1)" , parsePriority , 1 )
86102 . option ( "--labels <labels>" , "Comma-separated labels" )
87103 . option ( "--due <date>" , "Due date (YYYY-MM-DD)" )
88104 . option ( "--json" , "Output raw JSON" )
@@ -137,9 +153,18 @@ Examples:
137153 label ( "Content" , task . content ) ;
138154 label ( "Status" , statusBadge ( task . status ) ) ;
139155 label ( "Priority" , priorityBadge ( task . priority ) ) ;
140- const labels = typeof task . labels === "string" ? JSON . parse ( task . labels ) : task . labels ;
141- if ( labels && labels . length > 0 ) {
156+ let labels = task . labels ;
157+ if ( typeof labels === "string" ) {
158+ try {
159+ labels = JSON . parse ( labels ) as string [ ] | string ;
160+ } catch {
161+ // Keep malformed labels as the raw string instead of crashing.
162+ }
163+ }
164+ if ( Array . isArray ( labels ) && labels . length > 0 ) {
142165 label ( "Labels" , labels . join ( ", " ) ) ;
166+ } else if ( typeof labels === "string" && labels ) {
167+ label ( "Labels" , labels ) ;
143168 }
144169 if ( task . due_date ) label ( "Due" , formatDate ( task . due_date ) ) ;
145170 if ( task . assigned_to_agent_id ) label ( "Delegated To" , task . assigned_to_agent_id ) ;
0 commit comments