Skip to content

Commit a5a0d9d

Browse files
committed
feat: add AI configuration files and update template handling in project setup
1 parent 5525dd9 commit a5a0d9d

File tree

3 files changed

+129
-2
lines changed

3 files changed

+129
-2
lines changed

packages/create-objectstack/src/index.ts

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import chalk from 'chalk';
55
import fs from 'fs';
66
import path from 'path';
77
import { execSync } from 'child_process';
8+
import { fileURLToPath } from 'url';
9+
10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = path.dirname(__filename);
12+
const TEMPLATES_DIR = path.resolve(__dirname, 'templates');
813

914
// ─── Template Registry ──────────────────────────────────────────────
1015

@@ -555,6 +560,23 @@ MIT
555560
},
556561
};
557562

563+
// ─── Shared AI Configuration Files ──────────────────────────────────
564+
// These files are added to every template so third-party developers
565+
// get AI-assisted development (Copilot + Claude) out of the box.
566+
// Templates are maintained as standalone files in src/templates/ for
567+
// easy editing — no need to modify TypeScript code.
568+
569+
function readTemplate(filename: string): string {
570+
return fs.readFileSync(path.join(TEMPLATES_DIR, filename), 'utf-8');
571+
}
572+
573+
const AI_CONFIG_FILES: TemplateFiles = {
574+
'.github/copilot-instructions.md': (name) =>
575+
readTemplate('copilot-instructions.md')
576+
.replaceAll('{{PROJECT_NAME}}', name)
577+
.replaceAll('{{PROJECT_TITLE}}', toTitleCase(name)),
578+
};
579+
558580
// ─── Helpers ────────────────────────────────────────────────────────
559581

560582
function toCamelCase(str: string): string {
@@ -650,8 +672,11 @@ const program = new Command()
650672
fs.mkdirSync(targetDir, { recursive: true });
651673
}
652674

653-
// Write every file defined by the template
654-
for (const [filePath, contentFn] of Object.entries(template.files)) {
675+
// Merge template files with shared AI configuration files
676+
const allFiles: TemplateFiles = { ...template.files, ...AI_CONFIG_FILES };
677+
678+
// Write every file defined by the template + AI config
679+
for (const [filePath, contentFn] of Object.entries(allFiles)) {
655680
const fullPath = path.join(targetDir, filePath);
656681
const dir = path.dirname(fullPath);
657682

@@ -684,6 +709,24 @@ const program = new Command()
684709
}
685710
}
686711

712+
// Install ObjectStack AI skills via the standard skills CLI
713+
if (!options.skipInstall) {
714+
printStep('Installing AI skills for your coding agent...');
715+
try {
716+
execSync('npx -y skills add objectstack-ai/framework --all', {
717+
stdio: 'inherit',
718+
cwd: targetDir,
719+
});
720+
console.log('');
721+
} catch {
722+
printWarning(
723+
'Skills installation skipped. Run manually:\n' +
724+
' npx skills add objectstack-ai/framework',
725+
);
726+
console.log('');
727+
}
728+
}
729+
687730
printSuccess('Project created!');
688731
console.log('');
689732

@@ -697,6 +740,11 @@ const program = new Command()
697740
}
698741
console.log(chalk.dim(' npm run dev # Start development server'));
699742
console.log(chalk.dim(' npm run validate # Check configuration'));
743+
if (options.skipInstall) {
744+
console.log('');
745+
console.log(chalk.bold(' AI Skills (recommended):'));
746+
console.log(chalk.dim(' npx skills add objectstack-ai/framework'));
747+
}
700748
console.log('');
701749

702750
} catch (error: any) {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# {{PROJECT_TITLE}} — Copilot Instructions
2+
3+
> Auto-generated by `create-objectstack`. Customise freely.
4+
5+
## Project Context
6+
7+
This is an **ObjectStack** application — a metadata-driven low-code project
8+
that defines business objects, views, automations, and AI agents in TypeScript.
9+
10+
- **Entry point:** `objectstack.config.ts` (uses `defineStack()`)
11+
- **Spec package:** `@objectstack/spec` (Zod-first schemas and types)
12+
13+
## Naming Conventions
14+
15+
| Context | Convention | Example |
16+
|:--------|:-----------|:--------|
17+
| Config keys (TS props) | `camelCase` | `maxLength`, `defaultValue` |
18+
| Machine names (data values) | `snake_case` | `project_task`, `first_name` |
19+
| Metadata type names | singular | `'agent'`, `'view'`, `'flow'` |
20+
| File names | `{name}.{type}.ts` | `task.object.ts`, `main.app.ts` |
21+
22+
## Key Rules
23+
24+
1. **Zod First** — All schema definitions start with Zod. Types are derived via `z.infer<>`.
25+
2. `defineStack()` is the single configuration entry point in `objectstack.config.ts`.
26+
3. Use `Object.values()` barrel pattern for metadata arrays.
27+
4. Import from `@objectstack/spec` — never use relative paths into the spec package.
28+
29+
## Project Structure
30+
31+
```
32+
{{PROJECT_NAME}}/
33+
├── objectstack.config.ts # defineStack() — the single entry point
34+
├── src/
35+
│ ├── objects/ # Business object definitions (snake_case names)
36+
│ ├── views/ # UI view definitions (list, form, kanban, calendar)
37+
│ ├── apps/ # App navigation & page structure
38+
│ ├── flows/ # Automation flows & workflows
39+
│ ├── actions/ # Custom actions (buttons, bulk ops)
40+
│ ├── dashboards/ # BI dashboards
41+
│ ├── reports/ # Analytics reports
42+
│ ├── agents/ # AI agent definitions
43+
│ ├── i18n/ # Translation bundles
44+
│ └── handlers/ # Runtime hook handlers
45+
```
46+
47+
## AI Skills
48+
49+
This project uses ObjectStack skills from `objectstack-ai/framework`.
50+
Install or update skills with the standard [skills CLI](https://skills.sh/):
51+
52+
```bash
53+
npx skills add objectstack-ai/framework
54+
```
55+
56+
Skills are triggered automatically based on task context:
57+
58+
| Skill | Trigger Context |
59+
|:------|:----------------|
60+
| **objectstack-schema** | Define objects, fields, relationships, validations, indexes |
61+
| **objectstack-query** | Filters, sorting, pagination, aggregation, ObjectQL |
62+
| **objectstack-ui** | Views, dashboards, apps, reports, actions, navigation |
63+
| **objectstack-api** | REST endpoints, authentication, service contracts |
64+
| **objectstack-plugin** | Plugin lifecycle, DI, services, hooks, events |
65+
| **objectstack-automation** | Flows, workflows, triggers, approvals, state machines |
66+
| **objectstack-ai** | Agents, tools, skills, RAG pipelines, LLM config |
67+
| **objectstack-quickstart** | Project setup, defineStack(), driver selection |
68+
| **objectstack-i18n** | Translation bundles, locale config, coverage detection |
69+
70+
## Learn More
71+
72+
- [ObjectStack Documentation](https://objectstack.com/docs)
73+
- [GitHub: objectstack-ai/framework](https://github.com/objectstack-ai/framework)
74+
- [Skills CLI](https://skills.sh/) — Manage AI skills across agents
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
22

33
import { defineConfig } from 'tsup';
4+
import { cpSync } from 'fs';
45

56
export default defineConfig({
67
entry: ['src/index.ts'],
78
format: ['esm'],
89
clean: true,
910
shims: true,
11+
onSuccess: async () => {
12+
// Copy template files to dist/ so they sit alongside the bundled JS
13+
cpSync('src/templates', 'dist/templates', { recursive: true });
14+
},
1015
});

0 commit comments

Comments
 (0)