Skip to content

Commit 9fefaca

Browse files
committed
plot agent logs takes id from package.json
1 parent 0952e53 commit 9fefaca

3 files changed

Lines changed: 48 additions & 4 deletions

File tree

.changeset/large-eyes-hide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plotday/sdk": patch
3+
---
4+
5+
Changed: plot agent logs takes id from package.json

sdk/cli/commands/agent-logs.ts

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import * as fs from "fs";
2+
import * as path from "path";
23

34
import * as out from "../utils/output";
45
import { getGlobalTokenPath } from "../utils/token";
56
import { handleSSEStream } from "../utils/sse";
67

8+
interface PackageJson {
9+
plotAgentId?: string;
10+
}
11+
712
interface 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
*/
1724
export 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;

sdk/cli/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,28 @@ agent
118118
});
119119

120120
agent
121-
.command("logs <agent-id>")
121+
.command("logs [agent-id]")
122122
.description("Stream real-time logs from an agent")
123+
.option("-d, --dir <directory>", "Agent directory", process.cwd())
124+
.option("--id <agentId>", "Agent ID")
123125
.option(
124126
"-e, --environment <env>",
125127
"Agent environment (personal, private, review)",
126128
"personal"
127129
)
128130
.option("--deploy-token <token>", "Authentication token")
129-
.action(function (this: Command, agentId: string) {
131+
.action(function (this: Command, agentId?: string) {
130132
const opts = this.optsWithGlobals() as {
133+
dir?: string;
134+
id?: string;
131135
environment?: string;
132136
deployToken?: string;
133137
apiUrl: string;
134138
};
135139
return agentLogsCommand({
136140
agentId,
141+
id: opts.id,
142+
dir: opts.dir,
137143
environment: opts.environment,
138144
deployToken: opts.deployToken,
139145
apiUrl: opts.apiUrl,

0 commit comments

Comments
 (0)