@@ -6,6 +6,8 @@ import * as out from "../utils/output";
66
77interface CreateOptions {
88 dir ?: string ;
9+ name ?: string ;
10+ displayName ?: string ;
911}
1012
1113/**
@@ -34,27 +36,53 @@ function detectPackageManager(): string {
3436export async function createCommand ( options : CreateOptions ) {
3537 out . header ( "Create a new Plot agent" ) ;
3638
37- const response = await prompts ( [
38- {
39- type : "text" ,
40- name : "name" ,
41- message : "Package name:" ,
42- initial : options . dir || undefined ,
43- validate : ( value : string ) =>
44- / ^ [ a - z 0 - 9 - ] + $ / . test ( value ) ||
45- "Must be kebab-case (lowercase, hyphens only)" ,
46- } ,
47- {
48- type : "text" ,
49- name : "displayName" ,
50- message : "Display name:" ,
51- validate : ( value : string ) => value . length > 0 || "Name is required" ,
52- } ,
53- ] ) ;
39+ let response : { name : string ; displayName : string } ;
40+
41+ // If both name and displayName are provided via CLI, use them directly
42+ if ( options . name && options . displayName ) {
43+ // Validate name
44+ if ( ! / ^ [ a - z 0 - 9 - ] + $ / . test ( options . name ) ) {
45+ out . error ( "Name must be kebab-case (lowercase, hyphens only)" ) ;
46+ process . exit ( 1 ) ;
47+ }
48+
49+ // Validate displayName
50+ if ( options . displayName . length === 0 ) {
51+ out . error ( "Display name is required" ) ;
52+ process . exit ( 1 ) ;
53+ }
5454
55- if ( Object . keys ( response ) . length === 0 ) {
56- out . plain ( "\nCancelled." ) ;
57- process . exit ( 0 ) ;
55+ response = {
56+ name : options . name ,
57+ displayName : options . displayName ,
58+ } ;
59+ } else {
60+ // Use interactive prompts
61+ const promptResponse = await prompts ( [
62+ {
63+ type : "text" ,
64+ name : "name" ,
65+ message : "Package name:" ,
66+ initial : options . dir || options . name || undefined ,
67+ validate : ( value : string ) =>
68+ / ^ [ a - z 0 - 9 - ] + $ / . test ( value ) ||
69+ "Must be kebab-case (lowercase, hyphens only)" ,
70+ } ,
71+ {
72+ type : "text" ,
73+ name : "displayName" ,
74+ message : "Display name:" ,
75+ initial : options . displayName || undefined ,
76+ validate : ( value : string ) => value . length > 0 || "Name is required" ,
77+ } ,
78+ ] ) ;
79+
80+ if ( Object . keys ( promptResponse ) . length === 0 ) {
81+ out . plain ( "\nCancelled." ) ;
82+ process . exit ( 0 ) ;
83+ }
84+
85+ response = promptResponse as { name : string ; displayName : string } ;
5886 }
5987
6088 const agentDir = options . dir || response . name ;
@@ -122,22 +150,18 @@ export async function createCommand(options: CreateOptions) {
122150 type Activity,
123151 Agent,
124152 type Tools,
125- createAgent,
126153} from "@plotday/sdk";
127154
128- export default createAgent(
129- class extends Agent {
130-
131- constructor(tools: Tools) {
132- super();
133- }
155+ export default class extends Agent {
156+ constructor(tools: Tools) {
157+ super();
158+ }
134159
135- async activity(activity: Activity) {
136- // Implement your agent logic here
137- console.log("Received activity:", activity);
138- }
160+ async activity(activity: Activity) {
161+ // Implement your agent logic here
162+ console.log("Received activity:", activity);
139163 }
140- );
164+ }
141165` ;
142166 fs . writeFileSync ( path . join ( agentPath , "src" , "index.ts" ) , agentTemplate ) ;
143167
0 commit comments