create-cogitator-app 0.1.0 → 0.1.1
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 +84 -0
- package/dist/index.js +63 -61
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +52 -0
- package/dist/lib.js +1315 -0
- package/dist/lib.js.map +1 -0
- package/package.json +9 -3
- package/dist/index.d.ts +0 -2
package/README.md
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# create-cogitator-app
|
|
2
|
+
|
|
3
|
+
Interactive CLI scaffolder for [Cogitator](https://cogitator.dev) — creates production-ready AI agent projects in seconds.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Interactive mode
|
|
9
|
+
npx create-cogitator-app
|
|
10
|
+
|
|
11
|
+
# With arguments
|
|
12
|
+
npx create-cogitator-app my-project --template basic --provider openai
|
|
13
|
+
|
|
14
|
+
# Skip prompts with flags
|
|
15
|
+
npx create-cogitator-app my-project -t swarm -p ollama --pm pnpm --docker --no-git
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Templates
|
|
19
|
+
|
|
20
|
+
| Template | Description |
|
|
21
|
+
|----------|-------------|
|
|
22
|
+
| `basic` | Single agent with tools |
|
|
23
|
+
| `memory` | Agent with Redis-backed persistent memory |
|
|
24
|
+
| `swarm` | Multi-agent hierarchical swarm |
|
|
25
|
+
| `workflow` | DAG workflow with sequential agent nodes |
|
|
26
|
+
| `api-server` | Express REST API with Cogitator backend |
|
|
27
|
+
| `nextjs` | Next.js chat app with streaming UI |
|
|
28
|
+
|
|
29
|
+
## CLI Flags
|
|
30
|
+
|
|
31
|
+
| Flag | Shorthand | Description |
|
|
32
|
+
|------|-----------|-------------|
|
|
33
|
+
| `--template <name>` | `-t` | Template to use |
|
|
34
|
+
| `--provider <name>` | `-p` | LLM provider (`ollama`, `openai`, `anthropic`, `google`) |
|
|
35
|
+
| `--pm <name>` | | Package manager (`pnpm`, `npm`, `yarn`, `bun`) |
|
|
36
|
+
| `--docker` / `--no-docker` | | Include Docker Compose |
|
|
37
|
+
| `--git` / `--no-git` | | Initialize git repository |
|
|
38
|
+
|
|
39
|
+
## Providers
|
|
40
|
+
|
|
41
|
+
| Provider | Default Model | Requires |
|
|
42
|
+
|----------|---------------|---------|
|
|
43
|
+
| `ollama` | `qwen2.5:7b` | [Ollama](https://ollama.com) installed locally |
|
|
44
|
+
| `openai` | `gpt-4o` | `OPENAI_API_KEY` |
|
|
45
|
+
| `anthropic` | `claude-sonnet-4-20250514` | `ANTHROPIC_API_KEY` |
|
|
46
|
+
| `google` | `gemini-2.5-flash` | `GOOGLE_API_KEY` |
|
|
47
|
+
|
|
48
|
+
## Programmatic API
|
|
49
|
+
|
|
50
|
+
```ts
|
|
51
|
+
import { scaffold, parseArgs } from 'create-cogitator-app';
|
|
52
|
+
import type { ProjectOptions } from 'create-cogitator-app';
|
|
53
|
+
|
|
54
|
+
const options: ProjectOptions = {
|
|
55
|
+
name: 'my-agent',
|
|
56
|
+
path: '/path/to/my-agent',
|
|
57
|
+
template: 'basic',
|
|
58
|
+
provider: 'ollama',
|
|
59
|
+
packageManager: 'pnpm',
|
|
60
|
+
docker: false,
|
|
61
|
+
git: true,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
await scaffold(options);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Generated Project Structure
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
my-project/
|
|
71
|
+
├── src/
|
|
72
|
+
│ ├── index.ts # Main entry point
|
|
73
|
+
│ └── tools.ts # Tool definitions
|
|
74
|
+
├── package.json
|
|
75
|
+
├── tsconfig.json
|
|
76
|
+
├── cogitator.yml # Cogitator configuration
|
|
77
|
+
├── .env.example
|
|
78
|
+
├── .gitignore
|
|
79
|
+
└── README.md
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
package/dist/index.js
CHANGED
|
@@ -27,7 +27,7 @@ var defaultModels = {
|
|
|
27
27
|
ollama: "qwen2.5:7b",
|
|
28
28
|
openai: "gpt-4o",
|
|
29
29
|
anthropic: "claude-sonnet-4-20250514",
|
|
30
|
-
google: "gemini-2.
|
|
30
|
+
google: "gemini-2.5-flash"
|
|
31
31
|
};
|
|
32
32
|
function providerConfig(provider) {
|
|
33
33
|
switch (provider) {
|
|
@@ -351,11 +351,8 @@ var swarmTemplate = {
|
|
|
351
351
|
` supervisor: reviewer,`,
|
|
352
352
|
` workers: [researcher, writer],`,
|
|
353
353
|
` hierarchical: {`,
|
|
354
|
-
`
|
|
355
|
-
`
|
|
356
|
-
` workerCommunication: true,`,
|
|
357
|
-
` maxParallelTasks: 2,`,
|
|
358
|
-
` },`,
|
|
354
|
+
` visibility: 'full',`,
|
|
355
|
+
` workerCommunication: true,`,
|
|
359
356
|
` },`,
|
|
360
357
|
` resources: {`,
|
|
361
358
|
` maxConcurrency: 3,`,
|
|
@@ -447,7 +444,6 @@ var workflowTemplate = {
|
|
|
447
444
|
` WorkflowExecutor,`,
|
|
448
445
|
` agentNode,`,
|
|
449
446
|
` functionNode,`,
|
|
450
|
-
` InMemoryCheckpointStore,`,
|
|
451
447
|
`} from '@cogitator-ai/workflows'`,
|
|
452
448
|
`import { analyzer, processor, formatter } from './agents.js'`,
|
|
453
449
|
``,
|
|
@@ -462,46 +458,37 @@ var workflowTemplate = {
|
|
|
462
458
|
` report?: string`,
|
|
463
459
|
`}`,
|
|
464
460
|
``,
|
|
461
|
+
`const analyzeNode = agentNode<WorkflowState>(analyzer, {`,
|
|
462
|
+
` inputMapper: (state) => \`Analyze the following: \${state.input}\`,`,
|
|
463
|
+
` stateMapper: (result) => ({ analysis: result.output }),`,
|
|
464
|
+
`})`,
|
|
465
|
+
``,
|
|
466
|
+
`const processNode = agentNode<WorkflowState>(processor, {`,
|
|
467
|
+
` inputMapper: (state) => \`Process this analysis: \${state.analysis ?? ''}\`,`,
|
|
468
|
+
` stateMapper: (result) => ({ processed: result.output }),`,
|
|
469
|
+
`})`,
|
|
470
|
+
``,
|
|
471
|
+
`const formatNode = agentNode<WorkflowState>(formatter, {`,
|
|
472
|
+
` inputMapper: (state) => \`Format this into a report: \${state.processed ?? ''}\`,`,
|
|
473
|
+
` stateMapper: (result) => ({ report: result.output }),`,
|
|
474
|
+
`})`,
|
|
475
|
+
``,
|
|
476
|
+
`const outputNode = functionNode<WorkflowState>(`,
|
|
477
|
+
` 'output',`,
|
|
478
|
+
` async (state) => state.report,`,
|
|
479
|
+
`)`,
|
|
480
|
+
``,
|
|
465
481
|
`const workflow = new WorkflowBuilder<WorkflowState>('${options.name}-workflow')`,
|
|
466
482
|
` .initialState({ input: '' })`,
|
|
467
|
-
` .entryPoint(
|
|
468
|
-
` .addNode(`,
|
|
469
|
-
`
|
|
470
|
-
`
|
|
471
|
-
`
|
|
472
|
-
` agent: analyzer,`,
|
|
473
|
-
` prompt: (ctx) => \`Analyze the following: \${ctx.input.input}\`,`,
|
|
474
|
-
` }),`,
|
|
475
|
-
` )`,
|
|
476
|
-
` .addNode(`,
|
|
477
|
-
` 'process',`,
|
|
478
|
-
` agentNode({`,
|
|
479
|
-
` cogitator,`,
|
|
480
|
-
` agent: processor,`,
|
|
481
|
-
` prompt: (ctx) => \`Process this analysis: \${ctx.results.analyze}\`,`,
|
|
482
|
-
` }),`,
|
|
483
|
-
` { after: ['analyze'] },`,
|
|
484
|
-
` )`,
|
|
485
|
-
` .addNode(`,
|
|
486
|
-
` 'format',`,
|
|
487
|
-
` agentNode({`,
|
|
488
|
-
` cogitator,`,
|
|
489
|
-
` agent: formatter,`,
|
|
490
|
-
` prompt: (ctx) => \`Format this into a report: \${ctx.results.process}\`,`,
|
|
491
|
-
` }),`,
|
|
492
|
-
` { after: ['process'] },`,
|
|
493
|
-
` )`,
|
|
494
|
-
` .addNode(`,
|
|
495
|
-
` 'output',`,
|
|
496
|
-
` functionNode(async (ctx) => ({`,
|
|
497
|
-
` report: ctx.results.format as string,`,
|
|
498
|
-
` })),`,
|
|
499
|
-
` { after: ['format'] },`,
|
|
500
|
-
` )`,
|
|
483
|
+
` .entryPoint(analyzeNode.name)`,
|
|
484
|
+
` .addNode(analyzeNode.name, analyzeNode.fn)`,
|
|
485
|
+
` .addNode(processNode.name, processNode.fn, { after: [analyzeNode.name] })`,
|
|
486
|
+
` .addNode(formatNode.name, formatNode.fn, { after: [processNode.name] })`,
|
|
487
|
+
` .addNode(outputNode.name, outputNode.fn, { after: [formatNode.name] })`,
|
|
501
488
|
` .build()`,
|
|
502
489
|
``,
|
|
503
490
|
`async function main() {`,
|
|
504
|
-
` const executor = new WorkflowExecutor(cogitator
|
|
491
|
+
` const executor = new WorkflowExecutor(cogitator)`,
|
|
505
492
|
``,
|
|
506
493
|
` console.log('Starting workflow...')`,
|
|
507
494
|
``,
|
|
@@ -957,14 +944,20 @@ function parseArgs(args) {
|
|
|
957
944
|
for (let i = 0; i < args.length; i++) {
|
|
958
945
|
const arg = args[i];
|
|
959
946
|
if (arg === "--template" || arg === "-t") {
|
|
960
|
-
|
|
961
|
-
|
|
947
|
+
if (i + 1 < args.length) {
|
|
948
|
+
const val = args[++i];
|
|
949
|
+
if (validTemplates.includes(val)) parsed.template = val;
|
|
950
|
+
}
|
|
962
951
|
} else if (arg === "--provider" || arg === "-p") {
|
|
963
|
-
|
|
964
|
-
|
|
952
|
+
if (i + 1 < args.length) {
|
|
953
|
+
const val = args[++i];
|
|
954
|
+
if (validProviders.includes(val)) parsed.provider = val;
|
|
955
|
+
}
|
|
965
956
|
} else if (arg === "--pm") {
|
|
966
|
-
|
|
967
|
-
|
|
957
|
+
if (i + 1 < args.length) {
|
|
958
|
+
const val = args[++i];
|
|
959
|
+
if (validPMs.includes(val)) parsed.packageManager = val;
|
|
960
|
+
}
|
|
968
961
|
} else if (arg === "--docker") {
|
|
969
962
|
parsed.docker = true;
|
|
970
963
|
} else if (arg === "--no-docker") {
|
|
@@ -982,7 +975,7 @@ function parseArgs(args) {
|
|
|
982
975
|
return parsed;
|
|
983
976
|
}
|
|
984
977
|
async function collectOptions(args) {
|
|
985
|
-
const
|
|
978
|
+
const rawName = args.name || await p.text({
|
|
986
979
|
message: "Where should we create your project?",
|
|
987
980
|
placeholder: "./my-agents",
|
|
988
981
|
defaultValue: "my-agents",
|
|
@@ -991,11 +984,12 @@ async function collectOptions(args) {
|
|
|
991
984
|
return void 0;
|
|
992
985
|
}
|
|
993
986
|
});
|
|
994
|
-
if (p.isCancel(
|
|
987
|
+
if (p.isCancel(rawName)) {
|
|
995
988
|
p.cancel("Operation cancelled.");
|
|
996
989
|
process.exit(0);
|
|
997
990
|
}
|
|
998
|
-
const
|
|
991
|
+
const name = rawName.trim();
|
|
992
|
+
const projectName = path.basename(path.normalize(name).replace(/^\.\//, "").replace(/^\.\\/, ""));
|
|
999
993
|
const projectPath = path.resolve(process.cwd(), name);
|
|
1000
994
|
const template = args.template || await p.select({
|
|
1001
995
|
message: "Which template would you like?",
|
|
@@ -1015,7 +1009,7 @@ async function collectOptions(args) {
|
|
|
1015
1009
|
},
|
|
1016
1010
|
{ value: "openai", label: "OpenAI", hint: "GPT-4o" },
|
|
1017
1011
|
{ value: "anthropic", label: "Anthropic", hint: "Claude Sonnet" },
|
|
1018
|
-
{ value: "google", label: "Google Gemini", hint: "Gemini 2.
|
|
1012
|
+
{ value: "google", label: "Google Gemini", hint: "Gemini 2.5 Flash" }
|
|
1019
1013
|
]
|
|
1020
1014
|
});
|
|
1021
1015
|
if (p.isCancel(provider)) {
|
|
@@ -1114,7 +1108,7 @@ function generateGitignore() {
|
|
|
1114
1108
|
}
|
|
1115
1109
|
|
|
1116
1110
|
// src/templates/base/env-example.ts
|
|
1117
|
-
function generateEnvExample(provider) {
|
|
1111
|
+
function generateEnvExample(provider, template) {
|
|
1118
1112
|
const lines = ["# Cogitator Environment Variables", ""];
|
|
1119
1113
|
switch (provider) {
|
|
1120
1114
|
case "ollama":
|
|
@@ -1134,6 +1128,11 @@ function generateEnvExample(provider) {
|
|
|
1134
1128
|
lines.push("GOOGLE_API_KEY=...");
|
|
1135
1129
|
break;
|
|
1136
1130
|
}
|
|
1131
|
+
if (template === "memory") {
|
|
1132
|
+
lines.push("");
|
|
1133
|
+
lines.push("# Redis");
|
|
1134
|
+
lines.push("REDIS_URL=redis://localhost:6379");
|
|
1135
|
+
}
|
|
1137
1136
|
lines.push("");
|
|
1138
1137
|
return { path: ".env.example", content: lines.join("\n") };
|
|
1139
1138
|
}
|
|
@@ -1168,9 +1167,9 @@ function generateDockerCompose(provider) {
|
|
|
1168
1167
|
" ports:",
|
|
1169
1168
|
' - "5432:5432"',
|
|
1170
1169
|
" environment:",
|
|
1171
|
-
" POSTGRES_USER: cogitator",
|
|
1172
|
-
" POSTGRES_PASSWORD: cogitator",
|
|
1173
|
-
" POSTGRES_DB: cogitator",
|
|
1170
|
+
" POSTGRES_USER: ${POSTGRES_USER:-cogitator}",
|
|
1171
|
+
" POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-cogitator}",
|
|
1172
|
+
" POSTGRES_DB: ${POSTGRES_DB:-cogitator}",
|
|
1174
1173
|
" volumes:",
|
|
1175
1174
|
" - postgres_data:/var/lib/postgresql/data"
|
|
1176
1175
|
]
|
|
@@ -1242,10 +1241,10 @@ function isGitInstalled() {
|
|
|
1242
1241
|
function initGitRepo(cwd) {
|
|
1243
1242
|
execSync2("git init", { cwd, stdio: "ignore" });
|
|
1244
1243
|
execSync2("git add -A", { cwd, stdio: "ignore" });
|
|
1245
|
-
execSync2(
|
|
1246
|
-
|
|
1247
|
-
stdio: "ignore"
|
|
1248
|
-
|
|
1244
|
+
execSync2(
|
|
1245
|
+
'git -c user.name="Cogitator" -c user.email="init@cogitator.dev" commit -m "feat: initial project scaffold"',
|
|
1246
|
+
{ cwd, stdio: "ignore" }
|
|
1247
|
+
);
|
|
1249
1248
|
}
|
|
1250
1249
|
|
|
1251
1250
|
// src/scaffold.ts
|
|
@@ -1274,7 +1273,7 @@ function collectFiles(options) {
|
|
|
1274
1273
|
files.push({ path: "package.json", content: buildPackageJson(options) });
|
|
1275
1274
|
files.push(...template.files(options));
|
|
1276
1275
|
files.push(generateGitignore());
|
|
1277
|
-
files.push(generateEnvExample(options.provider));
|
|
1276
|
+
files.push(generateEnvExample(options.provider, options.template));
|
|
1278
1277
|
files.push(generateCogitatorYml(options.provider));
|
|
1279
1278
|
files.push(generateReadme(options));
|
|
1280
1279
|
if (options.template !== "nextjs") {
|
|
@@ -1286,6 +1285,9 @@ function collectFiles(options) {
|
|
|
1286
1285
|
return files;
|
|
1287
1286
|
}
|
|
1288
1287
|
async function scaffold(options) {
|
|
1288
|
+
if (fs.existsSync(options.path) && fs.readdirSync(options.path).length > 0) {
|
|
1289
|
+
throw new Error(`Directory "${options.path}" already exists and is not empty`);
|
|
1290
|
+
}
|
|
1289
1291
|
const s = p2.spinner();
|
|
1290
1292
|
s.start("Generating project files");
|
|
1291
1293
|
const files = collectFiles(options);
|