create-cogitator-app 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +81 -38
- package/dist/index.js +222 -121
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +39 -2
- package/dist/lib.js +189 -111
- package/dist/lib.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2,17 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
// src/index.ts
|
|
4
4
|
import * as p3 from "@clack/prompts";
|
|
5
|
+
import { readFileSync } from "fs";
|
|
5
6
|
import pc2 from "picocolors";
|
|
6
7
|
|
|
7
8
|
// src/utils/logger.ts
|
|
8
9
|
import pc from "picocolors";
|
|
9
|
-
|
|
10
|
+
var MIN_INNER_WIDTH = 39;
|
|
11
|
+
function banner(version) {
|
|
12
|
+
const title = "create-cogitator-app";
|
|
13
|
+
const tagline = "Build AI agents in minutes";
|
|
14
|
+
const versionLabel = `v${version}`;
|
|
15
|
+
const lines = [
|
|
16
|
+
{
|
|
17
|
+
text: `${pc.bold(pc.white(title))} ${pc.dim(versionLabel)}`,
|
|
18
|
+
width: title.length + 2 + versionLabel.length
|
|
19
|
+
},
|
|
20
|
+
{ text: pc.dim(tagline), width: tagline.length }
|
|
21
|
+
];
|
|
22
|
+
const inner = Math.max(MIN_INNER_WIDTH, ...lines.map((line) => line.width + 4));
|
|
10
23
|
const art = [
|
|
11
24
|
"",
|
|
12
|
-
` ${pc.cyan("\
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
25
|
+
` ${pc.cyan(`\u2554${"\u2550".repeat(inner)}\u2557`)}`,
|
|
26
|
+
...lines.map(
|
|
27
|
+
(line) => ` ${pc.cyan("\u2551")} ${line.text}${" ".repeat(inner - 2 - line.width)}${pc.cyan("\u2551")}`
|
|
28
|
+
),
|
|
29
|
+
` ${pc.cyan(`\u255A${"\u2550".repeat(inner)}\u255D`)}`,
|
|
16
30
|
""
|
|
17
31
|
];
|
|
18
32
|
console.log(art.join("\n"));
|
|
@@ -70,6 +84,9 @@ function providerConfig(provider) {
|
|
|
70
84
|
}
|
|
71
85
|
}
|
|
72
86
|
|
|
87
|
+
// src/templates/versions.ts
|
|
88
|
+
var ZOD_VERSION = "^4.6.5";
|
|
89
|
+
|
|
73
90
|
// src/templates/basic.ts
|
|
74
91
|
var basicTemplate = {
|
|
75
92
|
files(options) {
|
|
@@ -138,7 +155,7 @@ var basicTemplate = {
|
|
|
138
155
|
dependencies() {
|
|
139
156
|
return {
|
|
140
157
|
"@cogitator-ai/core": "latest",
|
|
141
|
-
zod:
|
|
158
|
+
zod: ZOD_VERSION
|
|
142
159
|
};
|
|
143
160
|
},
|
|
144
161
|
devDependencies() {
|
|
@@ -247,7 +264,7 @@ var memoryTemplate = {
|
|
|
247
264
|
"@cogitator-ai/core": "latest",
|
|
248
265
|
"@cogitator-ai/memory": "latest",
|
|
249
266
|
"@cogitator-ai/redis": "latest",
|
|
250
|
-
zod:
|
|
267
|
+
zod: ZOD_VERSION
|
|
251
268
|
};
|
|
252
269
|
},
|
|
253
270
|
devDependencies() {
|
|
@@ -368,7 +385,7 @@ var swarmTemplate = {
|
|
|
368
385
|
` })`,
|
|
369
386
|
``,
|
|
370
387
|
` console.log('Result:', result.output)`,
|
|
371
|
-
` console.log('Strategy:',
|
|
388
|
+
` console.log('Strategy:', team.strategyType)`,
|
|
372
389
|
``,
|
|
373
390
|
` await team.close()`,
|
|
374
391
|
`}`,
|
|
@@ -388,7 +405,7 @@ var swarmTemplate = {
|
|
|
388
405
|
return {
|
|
389
406
|
"@cogitator-ai/core": "latest",
|
|
390
407
|
"@cogitator-ai/swarms": "latest",
|
|
391
|
-
zod:
|
|
408
|
+
zod: ZOD_VERSION
|
|
392
409
|
};
|
|
393
410
|
},
|
|
394
411
|
devDependencies() {
|
|
@@ -451,7 +468,7 @@ var workflowTemplate = {
|
|
|
451
468
|
providerConfig(options.provider),
|
|
452
469
|
`})`,
|
|
453
470
|
``,
|
|
454
|
-
`
|
|
471
|
+
`type WorkflowState = {`,
|
|
455
472
|
` input: string`,
|
|
456
473
|
` analysis?: string`,
|
|
457
474
|
` processed?: string`,
|
|
@@ -512,7 +529,7 @@ var workflowTemplate = {
|
|
|
512
529
|
return {
|
|
513
530
|
"@cogitator-ai/core": "latest",
|
|
514
531
|
"@cogitator-ai/workflows": "latest",
|
|
515
|
-
zod:
|
|
532
|
+
zod: ZOD_VERSION
|
|
516
533
|
};
|
|
517
534
|
},
|
|
518
535
|
devDependencies() {
|
|
@@ -533,7 +550,9 @@ var workflowTemplate = {
|
|
|
533
550
|
};
|
|
534
551
|
|
|
535
552
|
// src/templates/api-server.ts
|
|
553
|
+
var BASE_PATH = "/api";
|
|
536
554
|
var apiServerTemplate = {
|
|
555
|
+
healthPath: `${BASE_PATH}/health`,
|
|
537
556
|
files(options) {
|
|
538
557
|
const model = defaultModels[options.provider];
|
|
539
558
|
const agentsTs = [
|
|
@@ -585,7 +604,7 @@ var apiServerTemplate = {
|
|
|
585
604
|
` cogitator,`,
|
|
586
605
|
` agents: { assistant, coder },`,
|
|
587
606
|
` config: {`,
|
|
588
|
-
` basePath: '
|
|
607
|
+
` basePath: '${BASE_PATH}',`,
|
|
589
608
|
` enableSwagger: true,`,
|
|
590
609
|
` cors: { origin: '*' },`,
|
|
591
610
|
` swagger: {`,
|
|
@@ -600,7 +619,7 @@ var apiServerTemplate = {
|
|
|
600
619
|
``,
|
|
601
620
|
` app.listen(port, () => {`,
|
|
602
621
|
` console.log(\`Server running at http://localhost:\${port}\`)`,
|
|
603
|
-
` console.log(\`Swagger docs at http://localhost:\${port}/
|
|
622
|
+
` console.log(\`Swagger docs at http://localhost:\${port}${BASE_PATH}/docs\`)`,
|
|
604
623
|
` })`,
|
|
605
624
|
`}`,
|
|
606
625
|
``,
|
|
@@ -616,8 +635,8 @@ var apiServerTemplate = {
|
|
|
616
635
|
return {
|
|
617
636
|
"@cogitator-ai/core": "latest",
|
|
618
637
|
"@cogitator-ai/express": "latest",
|
|
619
|
-
express: "^
|
|
620
|
-
zod:
|
|
638
|
+
express: "^5.2.1",
|
|
639
|
+
zod: ZOD_VERSION
|
|
621
640
|
};
|
|
622
641
|
},
|
|
623
642
|
devDependencies() {
|
|
@@ -625,7 +644,7 @@ var apiServerTemplate = {
|
|
|
625
644
|
typescript: "^5.8.0",
|
|
626
645
|
tsx: "^4.19.0",
|
|
627
646
|
"@types/node": "^22.0.0",
|
|
628
|
-
"@types/express": "^5.0.
|
|
647
|
+
"@types/express": "^5.0.6"
|
|
629
648
|
};
|
|
630
649
|
},
|
|
631
650
|
scripts() {
|
|
@@ -640,6 +659,7 @@ var apiServerTemplate = {
|
|
|
640
659
|
|
|
641
660
|
// src/templates/nextjs.ts
|
|
642
661
|
var nextjsTemplate = {
|
|
662
|
+
healthPath: "/api/health",
|
|
643
663
|
files(options) {
|
|
644
664
|
const model = defaultModels[options.provider];
|
|
645
665
|
const agentTs = [
|
|
@@ -677,6 +697,12 @@ var nextjsTemplate = {
|
|
|
677
697
|
`export const POST = createChatHandler(cogitator, agent)`,
|
|
678
698
|
``
|
|
679
699
|
].join("\n");
|
|
700
|
+
const healthRouteTs = [
|
|
701
|
+
`export function GET() {`,
|
|
702
|
+
` return Response.json({ status: 'ok' })`,
|
|
703
|
+
`}`,
|
|
704
|
+
``
|
|
705
|
+
].join("\n");
|
|
680
706
|
const pageTsx = [
|
|
681
707
|
`'use client'`,
|
|
682
708
|
``,
|
|
@@ -843,6 +869,7 @@ var nextjsTemplate = {
|
|
|
843
869
|
return [
|
|
844
870
|
{ path: "src/lib/agent.ts", content: agentTs },
|
|
845
871
|
{ path: "src/app/api/chat/route.ts", content: routeTs },
|
|
872
|
+
{ path: "src/app/api/health/route.ts", content: healthRouteTs },
|
|
846
873
|
{ path: "src/app/page.tsx", content: pageTsx },
|
|
847
874
|
{ path: "src/app/layout.tsx", content: layoutTsx },
|
|
848
875
|
{ path: "src/app/globals.css", content: globalsCss },
|
|
@@ -859,7 +886,7 @@ var nextjsTemplate = {
|
|
|
859
886
|
next: "^15.0.0",
|
|
860
887
|
react: "^19.0.0",
|
|
861
888
|
"react-dom": "^19.0.0",
|
|
862
|
-
zod:
|
|
889
|
+
zod: ZOD_VERSION
|
|
863
890
|
};
|
|
864
891
|
},
|
|
865
892
|
devDependencies() {
|
|
@@ -966,6 +993,10 @@ function parseArgs(args) {
|
|
|
966
993
|
parsed.git = true;
|
|
967
994
|
} else if (arg === "--no-git") {
|
|
968
995
|
parsed.git = false;
|
|
996
|
+
} else if (arg === "--install") {
|
|
997
|
+
parsed.install = true;
|
|
998
|
+
} else if (arg === "--no-install") {
|
|
999
|
+
parsed.install = false;
|
|
969
1000
|
} else if (arg === "-y" || arg === "--yes") {
|
|
970
1001
|
parsed.yes = true;
|
|
971
1002
|
} else if (!arg.startsWith("-") && !parsed.name) {
|
|
@@ -974,78 +1005,83 @@ function parseArgs(args) {
|
|
|
974
1005
|
}
|
|
975
1006
|
return parsed;
|
|
976
1007
|
}
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
});
|
|
987
|
-
if (p.isCancel(rawName)) {
|
|
1008
|
+
var defaultAnswers = {
|
|
1009
|
+
name: "my-agents",
|
|
1010
|
+
template: "basic",
|
|
1011
|
+
provider: "ollama",
|
|
1012
|
+
docker: true,
|
|
1013
|
+
git: true
|
|
1014
|
+
};
|
|
1015
|
+
function unlessCancelled(answer) {
|
|
1016
|
+
if (p.isCancel(answer)) {
|
|
988
1017
|
p.cancel("Operation cancelled.");
|
|
989
1018
|
process.exit(0);
|
|
990
1019
|
}
|
|
1020
|
+
return answer;
|
|
1021
|
+
}
|
|
1022
|
+
async function collectOptions(args) {
|
|
1023
|
+
const interactive = !args.yes;
|
|
1024
|
+
const rawName = args.name || (interactive ? unlessCancelled(
|
|
1025
|
+
await p.text({
|
|
1026
|
+
message: "Where should we create your project?",
|
|
1027
|
+
placeholder: `./${defaultAnswers.name}`,
|
|
1028
|
+
defaultValue: defaultAnswers.name,
|
|
1029
|
+
validate: (value) => {
|
|
1030
|
+
if (value && !value.trim()) return "Project name is required";
|
|
1031
|
+
return void 0;
|
|
1032
|
+
}
|
|
1033
|
+
})
|
|
1034
|
+
) : defaultAnswers.name);
|
|
991
1035
|
const name = rawName.trim();
|
|
992
1036
|
const projectName = path.basename(path.normalize(name).replace(/^\.\//, "").replace(/^\.\\/, ""));
|
|
993
1037
|
const projectPath = path.resolve(process.cwd(), name);
|
|
994
|
-
const template = args.template
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
p.
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
const git = args.git ?? await p.confirm({
|
|
1042
|
-
message: "Initialize git repository?",
|
|
1043
|
-
initialValue: true
|
|
1044
|
-
});
|
|
1045
|
-
if (p.isCancel(git)) {
|
|
1046
|
-
p.cancel("Operation cancelled.");
|
|
1047
|
-
process.exit(0);
|
|
1048
|
-
}
|
|
1038
|
+
const template = args.template ?? (interactive ? unlessCancelled(
|
|
1039
|
+
await p.select({
|
|
1040
|
+
message: "Which template would you like?",
|
|
1041
|
+
options: templateChoices,
|
|
1042
|
+
initialValue: defaultAnswers.template
|
|
1043
|
+
})
|
|
1044
|
+
) : defaultAnswers.template);
|
|
1045
|
+
const provider = args.provider ?? (interactive ? unlessCancelled(
|
|
1046
|
+
await p.select({
|
|
1047
|
+
message: "Which LLM provider?",
|
|
1048
|
+
options: [
|
|
1049
|
+
{
|
|
1050
|
+
value: "ollama",
|
|
1051
|
+
label: "Ollama",
|
|
1052
|
+
hint: `${defaultModels.ollama} \u2014 local, free, requires Ollama installed`
|
|
1053
|
+
},
|
|
1054
|
+
{ value: "openai", label: "OpenAI", hint: defaultModels.openai },
|
|
1055
|
+
{ value: "anthropic", label: "Anthropic", hint: defaultModels.anthropic },
|
|
1056
|
+
{ value: "google", label: "Google Gemini", hint: defaultModels.google }
|
|
1057
|
+
],
|
|
1058
|
+
initialValue: defaultAnswers.provider
|
|
1059
|
+
})
|
|
1060
|
+
) : defaultAnswers.provider);
|
|
1061
|
+
const packageManager = args.packageManager ?? (interactive ? unlessCancelled(
|
|
1062
|
+
await p.select({
|
|
1063
|
+
message: "Package manager?",
|
|
1064
|
+
options: [
|
|
1065
|
+
{ value: "pnpm", label: "pnpm" },
|
|
1066
|
+
{ value: "npm", label: "npm" },
|
|
1067
|
+
{ value: "yarn", label: "yarn" },
|
|
1068
|
+
{ value: "bun", label: "bun" }
|
|
1069
|
+
],
|
|
1070
|
+
initialValue: detectPackageManager()
|
|
1071
|
+
})
|
|
1072
|
+
) : detectPackageManager());
|
|
1073
|
+
const docker = args.docker ?? (interactive ? unlessCancelled(
|
|
1074
|
+
await p.confirm({
|
|
1075
|
+
message: "Include Docker Compose? (Redis + Postgres" + (provider === "ollama" ? " + Ollama)" : ")"),
|
|
1076
|
+
initialValue: defaultAnswers.docker
|
|
1077
|
+
})
|
|
1078
|
+
) : defaultAnswers.docker);
|
|
1079
|
+
const git = args.git ?? (interactive ? unlessCancelled(
|
|
1080
|
+
await p.confirm({
|
|
1081
|
+
message: "Initialize git repository?",
|
|
1082
|
+
initialValue: defaultAnswers.git
|
|
1083
|
+
})
|
|
1084
|
+
) : defaultAnswers.git);
|
|
1049
1085
|
return {
|
|
1050
1086
|
name: projectName,
|
|
1051
1087
|
path: projectPath,
|
|
@@ -1053,7 +1089,8 @@ async function collectOptions(args) {
|
|
|
1053
1089
|
provider,
|
|
1054
1090
|
packageManager,
|
|
1055
1091
|
docker,
|
|
1056
|
-
git
|
|
1092
|
+
git,
|
|
1093
|
+
...args.install !== void 0 && { install: args.install }
|
|
1057
1094
|
};
|
|
1058
1095
|
}
|
|
1059
1096
|
|
|
@@ -1182,15 +1219,40 @@ function generateDockerCompose(provider) {
|
|
|
1182
1219
|
}
|
|
1183
1220
|
|
|
1184
1221
|
// src/templates/base/cogitator-yml.ts
|
|
1185
|
-
function generateCogitatorYml(provider) {
|
|
1186
|
-
const
|
|
1187
|
-
|
|
1222
|
+
function generateCogitatorYml(provider, template) {
|
|
1223
|
+
const lines = [
|
|
1224
|
+
"llm:",
|
|
1225
|
+
` defaultProvider: ${provider}`,
|
|
1226
|
+
` defaultModel: ${defaultModels[provider]}`
|
|
1227
|
+
];
|
|
1188
1228
|
if (provider === "ollama") {
|
|
1189
|
-
lines.push(
|
|
1229
|
+
lines.push(
|
|
1230
|
+
" providers:",
|
|
1231
|
+
" ollama:",
|
|
1232
|
+
" baseUrl: ${OLLAMA_BASE_URL:-http://localhost:11434}"
|
|
1233
|
+
);
|
|
1234
|
+
}
|
|
1235
|
+
if (template === "memory") {
|
|
1236
|
+
lines.push(
|
|
1237
|
+
"",
|
|
1238
|
+
"memory:",
|
|
1239
|
+
" adapter: redis",
|
|
1240
|
+
" redis:",
|
|
1241
|
+
" url: ${REDIS_URL:-redis://localhost:6379}"
|
|
1242
|
+
);
|
|
1190
1243
|
}
|
|
1244
|
+
const healthPath = template ? getTemplate(template).healthPath : void 0;
|
|
1245
|
+
if (healthPath) {
|
|
1246
|
+
lines.push("", "deploy:", " health:", ` path: ${healthPath}`);
|
|
1247
|
+
}
|
|
1248
|
+
lines.push("");
|
|
1191
1249
|
return { path: "cogitator.yml", content: lines.join("\n") };
|
|
1192
1250
|
}
|
|
1193
1251
|
|
|
1252
|
+
// src/utils/links.ts
|
|
1253
|
+
var DOCS_URL = "https://cogitator.app/docs";
|
|
1254
|
+
var REPO_URL = "https://github.com/cogitator-ai/Cogitator-AI";
|
|
1255
|
+
|
|
1194
1256
|
// src/templates/base/readme.ts
|
|
1195
1257
|
var templateNames = {
|
|
1196
1258
|
basic: "Basic Agent",
|
|
@@ -1206,7 +1268,7 @@ function generateReadme(options) {
|
|
|
1206
1268
|
const content = [
|
|
1207
1269
|
`# ${options.name}`,
|
|
1208
1270
|
"",
|
|
1209
|
-
`> Created with [create-cogitator-app](
|
|
1271
|
+
`> Created with [create-cogitator-app](${REPO_URL}) \u2014 ${templateName} template`,
|
|
1210
1272
|
"",
|
|
1211
1273
|
"## Getting Started",
|
|
1212
1274
|
"",
|
|
@@ -1221,8 +1283,8 @@ function generateReadme(options) {
|
|
|
1221
1283
|
...options.docker ? ["## Docker Services", "", "```bash", "docker compose up -d", "```", ""] : [],
|
|
1222
1284
|
"## Learn More",
|
|
1223
1285
|
"",
|
|
1224
|
-
|
|
1225
|
-
|
|
1286
|
+
`- [Cogitator Documentation](${DOCS_URL})`,
|
|
1287
|
+
`- [GitHub Repository](${REPO_URL})`,
|
|
1226
1288
|
""
|
|
1227
1289
|
];
|
|
1228
1290
|
return { path: "README.md", content: content.join("\n") };
|
|
@@ -1240,22 +1302,38 @@ function generatePnpmWorkspace() {
|
|
|
1240
1302
|
}
|
|
1241
1303
|
|
|
1242
1304
|
// src/utils/git.ts
|
|
1243
|
-
import {
|
|
1305
|
+
import { execFileSync } from "child_process";
|
|
1306
|
+
var FALLBACK_IDENTITY = [
|
|
1307
|
+
"-c",
|
|
1308
|
+
"user.name=create-cogitator-app",
|
|
1309
|
+
"-c",
|
|
1310
|
+
"user.email=create-cogitator-app@localhost"
|
|
1311
|
+
];
|
|
1244
1312
|
function isGitInstalled() {
|
|
1245
1313
|
try {
|
|
1246
|
-
|
|
1314
|
+
execFileSync("git", ["--version"], { stdio: "ignore" });
|
|
1247
1315
|
return true;
|
|
1248
1316
|
} catch {
|
|
1249
1317
|
return false;
|
|
1250
1318
|
}
|
|
1251
1319
|
}
|
|
1320
|
+
function hasIdentity(cwd) {
|
|
1321
|
+
try {
|
|
1322
|
+
const name = execFileSync("git", ["config", "user.name"], { cwd, encoding: "utf8" }).trim();
|
|
1323
|
+
const email = execFileSync("git", ["config", "user.email"], { cwd, encoding: "utf8" }).trim();
|
|
1324
|
+
return name.length > 0 && email.length > 0;
|
|
1325
|
+
} catch {
|
|
1326
|
+
return false;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1252
1329
|
function initGitRepo(cwd) {
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1330
|
+
execFileSync("git", ["init"], { cwd, stdio: "ignore" });
|
|
1331
|
+
execFileSync("git", ["add", "-A"], { cwd, stdio: "ignore" });
|
|
1332
|
+
const identity = hasIdentity(cwd) ? [] : FALLBACK_IDENTITY;
|
|
1333
|
+
execFileSync("git", [...identity, "commit", "-m", "feat: initial project scaffold"], {
|
|
1334
|
+
cwd,
|
|
1335
|
+
stdio: "ignore"
|
|
1336
|
+
});
|
|
1259
1337
|
}
|
|
1260
1338
|
|
|
1261
1339
|
// src/scaffold.ts
|
|
@@ -1267,7 +1345,7 @@ function writeFile(basePath, file) {
|
|
|
1267
1345
|
function buildPackageJson(options) {
|
|
1268
1346
|
const template = getTemplate(options.template);
|
|
1269
1347
|
const isNextjs = options.template === "nextjs";
|
|
1270
|
-
const
|
|
1348
|
+
const pkg2 = {
|
|
1271
1349
|
name: options.name,
|
|
1272
1350
|
version: "0.1.0",
|
|
1273
1351
|
private: true,
|
|
@@ -1276,7 +1354,7 @@ function buildPackageJson(options) {
|
|
|
1276
1354
|
dependencies: template.dependencies(),
|
|
1277
1355
|
devDependencies: template.devDependencies()
|
|
1278
1356
|
};
|
|
1279
|
-
return JSON.stringify(
|
|
1357
|
+
return JSON.stringify(pkg2, null, 2) + "\n";
|
|
1280
1358
|
}
|
|
1281
1359
|
function collectFiles(options) {
|
|
1282
1360
|
const template = getTemplate(options.template);
|
|
@@ -1285,7 +1363,7 @@ function collectFiles(options) {
|
|
|
1285
1363
|
files.push(...template.files(options));
|
|
1286
1364
|
files.push(generateGitignore());
|
|
1287
1365
|
files.push(generateEnvExample(options.provider, options.template));
|
|
1288
|
-
files.push(generateCogitatorYml(options.provider));
|
|
1366
|
+
files.push(generateCogitatorYml(options.provider, options.template));
|
|
1289
1367
|
files.push(generateReadme(options));
|
|
1290
1368
|
if (options.template !== "nextjs") {
|
|
1291
1369
|
files.push(generateTsconfig());
|
|
@@ -1298,6 +1376,17 @@ function collectFiles(options) {
|
|
|
1298
1376
|
}
|
|
1299
1377
|
return files;
|
|
1300
1378
|
}
|
|
1379
|
+
function runStep(spinner2, messages, step) {
|
|
1380
|
+
spinner2.start(messages.start);
|
|
1381
|
+
try {
|
|
1382
|
+
step();
|
|
1383
|
+
spinner2.stop(messages.done);
|
|
1384
|
+
return { status: "done" };
|
|
1385
|
+
} catch (error) {
|
|
1386
|
+
spinner2.stop(messages.failed);
|
|
1387
|
+
return { status: "failed", error: error instanceof Error ? error : new Error(String(error)) };
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1301
1390
|
async function scaffold(options) {
|
|
1302
1391
|
if (fs.existsSync(options.path) && fs.readdirSync(options.path).length > 0) {
|
|
1303
1392
|
throw new Error(`Directory "${options.path}" already exists and is not empty`);
|
|
@@ -1310,40 +1399,52 @@ async function scaffold(options) {
|
|
|
1310
1399
|
writeFile(options.path, file);
|
|
1311
1400
|
}
|
|
1312
1401
|
s.stop("Generated project files");
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1402
|
+
const install = options.install === false ? { status: "skipped" } : runStep(
|
|
1403
|
+
s,
|
|
1404
|
+
{
|
|
1405
|
+
start: "Installing dependencies",
|
|
1406
|
+
done: "Installed dependencies",
|
|
1407
|
+
failed: `Failed to install dependencies, run "${options.packageManager} install" yourself`
|
|
1408
|
+
},
|
|
1409
|
+
() => installDependencies(options.path, options.packageManager)
|
|
1410
|
+
);
|
|
1411
|
+
const git = options.git && isGitInstalled() ? runStep(
|
|
1412
|
+
s,
|
|
1413
|
+
{
|
|
1414
|
+
start: "Initializing git repository",
|
|
1415
|
+
done: "Initialized git repository",
|
|
1416
|
+
failed: 'Failed to initialize git, run "git init" yourself'
|
|
1417
|
+
},
|
|
1418
|
+
() => initGitRepo(options.path)
|
|
1419
|
+
) : { status: "skipped" };
|
|
1420
|
+
return { files: files.map((file) => file.path), install, git };
|
|
1329
1421
|
}
|
|
1330
1422
|
|
|
1331
1423
|
// src/index.ts
|
|
1424
|
+
var pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf-8"));
|
|
1332
1425
|
async function main() {
|
|
1333
|
-
banner();
|
|
1426
|
+
banner(pkg.version);
|
|
1334
1427
|
p3.intro(pc2.cyan("Let's build something with AI agents"));
|
|
1335
1428
|
const args = parseArgs(process.argv.slice(2));
|
|
1336
1429
|
const options = await collectOptions(args);
|
|
1337
|
-
await scaffold(options);
|
|
1430
|
+
const result = await scaffold(options);
|
|
1431
|
+
if (result.install.status === "failed") {
|
|
1432
|
+
p3.log.warn(`${options.packageManager} install failed: ${result.install.error.message}`);
|
|
1433
|
+
}
|
|
1434
|
+
if (result.git.status === "failed") {
|
|
1435
|
+
p3.log.warn(`git init failed: ${result.git.error.message}`);
|
|
1436
|
+
}
|
|
1338
1437
|
const dev = devCommand(options.packageManager);
|
|
1438
|
+
const install = result.install.status === "done" ? [] : [` ${pc2.cyan(`${options.packageManager} install`)}`];
|
|
1339
1439
|
p3.outro(
|
|
1340
1440
|
[
|
|
1341
1441
|
pc2.green("Done! ") + "Next steps:",
|
|
1342
1442
|
"",
|
|
1343
1443
|
` ${pc2.cyan("cd")} ${options.name}`,
|
|
1444
|
+
...install,
|
|
1344
1445
|
` ${pc2.cyan(dev)}`,
|
|
1345
1446
|
"",
|
|
1346
|
-
pc2.dim(
|
|
1447
|
+
pc2.dim(`Docs: ${DOCS_URL}`)
|
|
1347
1448
|
].join("\n")
|
|
1348
1449
|
);
|
|
1349
1450
|
}
|