11import * as fs from "fs" ;
2+ import * as path from "path" ;
23
34import * as out from "../utils/output" ;
45import { getGlobalTokenPath } from "../utils/token" ;
56import { handleSSEStream } from "../utils/sse" ;
67
8+ interface PackageJson {
9+ plotAgentId ?: string ;
10+ }
11+
712interface AgentLogsOptions {
8- agentId : string ;
13+ agentId ?: string ;
14+ id ?: string ;
15+ dir ?: string ;
916 environment ?: string ;
1017 deployToken ?: string ;
1118 apiUrl : string ;
@@ -15,7 +22,33 @@ interface AgentLogsOptions {
1522 * Stream agent logs in real-time
1623 */
1724export async function agentLogsCommand ( options : AgentLogsOptions ) {
18- const { agentId, environment = "personal" , apiUrl } = options ;
25+ const { environment = "personal" , apiUrl, dir = process . cwd ( ) } = options ;
26+
27+ // Determine agent ID from options, positional arg, or package.json
28+ let agentId = options . id || options . agentId ;
29+
30+ if ( ! agentId ) {
31+ // Try to read from package.json
32+ const packageJsonPath = path . join ( dir , "package.json" ) ;
33+ if ( fs . existsSync ( packageJsonPath ) ) {
34+ try {
35+ const packageJsonContent = fs . readFileSync ( packageJsonPath , "utf-8" ) ;
36+ const packageJson : PackageJson = JSON . parse ( packageJsonContent ) ;
37+ agentId = packageJson . plotAgentId ;
38+ } catch ( error ) {
39+ out . error ( "Failed to parse package.json" , String ( error ) ) ;
40+ process . exit ( 1 ) ;
41+ }
42+ }
43+ }
44+
45+ if ( ! agentId ) {
46+ out . error (
47+ "Agent ID required" ,
48+ "Provide agent ID as argument, via --id flag, or add 'plotAgentId' to package.json"
49+ ) ;
50+ process . exit ( 1 ) ;
51+ }
1952
2053 // Load deploy token
2154 let deployToken = options . deployToken ;
0 commit comments