cognite-create 0.2.15 → 0.2.18
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/bin/index.js +3 -0
- package/package.json +1 -1
- package/templates/.cursor/mcp.json +4 -4
- package/templates/.cursor/rules/core-cdf-apis.mdc +1525 -0
- package/templates/.cursor/rules/datamodelling.mdc +2023 -0
- package/templates/.cursor/rules/development.mdc +90 -0
- package/templates/.cursor/rules/general.mdc +27 -1
- package/templates/.cursor/rules/requirements-gathering.mdc +24 -0
- package/templates/.env.example +8 -0
- package/templates/README.MD +198 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
alwaysApply: true
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# AGENTS.md - Developer & AI Assistant Onboarding Guide
|
|
6
|
+
|
|
7
|
+
Important rules:
|
|
8
|
+
|
|
9
|
+
- Always use the design system provided. cdf-design-system-alpha.
|
|
10
|
+
- Check often for typescript errors, and resolve them as they come. Especially after big changes.
|
|
11
|
+
- When making types for schemas that are represented in data modelling, fetch the details of that view first from CDF.
|
|
12
|
+
- Always use the design system provided. cdf-design-system-alpha.
|
|
13
|
+
|
|
14
|
+
## 1. Project Overview
|
|
15
|
+
|
|
16
|
+
This application is a React-based web application. You will build a react application to the spec that the user provides. You will also help define that spec according to the details in this document. You are provided with some boiler plate. Do not touch the `/src/infrastructure` folder, only use its components when needed.
|
|
17
|
+
|
|
18
|
+
## 2. Core Technologies
|
|
19
|
+
|
|
20
|
+
- **Language:** TypeScript
|
|
21
|
+
- **Framework:** React 17 with Vite.
|
|
22
|
+
- **State Management:** React context
|
|
23
|
+
- **Styling:** Tailwind + Cognite Design System (cdf-design-system-alpha)[node_modules/cdf-design-system-alpha/AI_USAGE_GUIDE.md]
|
|
24
|
+
- **Data Fetching:** React Query + Cognite SDK (@cognite/sdk)
|
|
25
|
+
- **Testing:** Vitest & Playwright
|
|
26
|
+
- **Package Manager:** npm
|
|
27
|
+
- **Authentication:** Use provided components
|
|
28
|
+
- **Other tools:**: Storybook
|
|
29
|
+
|
|
30
|
+
## 3. Development Environment Setup
|
|
31
|
+
|
|
32
|
+
1. **Prerequisites:** Ensure you have Node.js v22+ and Yarn installed
|
|
33
|
+
2. **Install dependencies:** `npm install`
|
|
34
|
+
3. **Environment setup:**
|
|
35
|
+
- Ensure `cdf.yml` has been populated by the user
|
|
36
|
+
4. **Start development server:** `npm start`
|
|
37
|
+
- Runs on `http://localhost:5000` by default
|
|
38
|
+
- Uses hot reloading for development
|
|
39
|
+
|
|
40
|
+
## 4. Coding Style & Design Principles
|
|
41
|
+
|
|
42
|
+
### Architecture Patterns
|
|
43
|
+
|
|
44
|
+
- **Component Structure:** Functional components with hooks, organized by feature in `/components`
|
|
45
|
+
- **Custom Hooks:** Extensive use of custom hooks for business logic (`/hooks`)
|
|
46
|
+
- **Service Layer:** Cognite SDK integration through centralized client (`/services`)
|
|
47
|
+
|
|
48
|
+
### Code Style Guidelines
|
|
49
|
+
|
|
50
|
+
- **Import Organization:** Avoid barrel imports
|
|
51
|
+
- **File Organization:** Co-locate related files (component + types + styles)
|
|
52
|
+
- **State Management:** Prefer React Context for global state, local state for component-specific data
|
|
53
|
+
- **Error Handling:** Use React Error Boundaries and proper error states
|
|
54
|
+
|
|
55
|
+
### Key Conventions
|
|
56
|
+
|
|
57
|
+
- **Exports:** Avoid default exports
|
|
58
|
+
- **Async Operations:** Use react-query
|
|
59
|
+
- **Styling:** Tailwind CSS with Cognites design system
|
|
60
|
+
- **Testing:** Test files co-located with components using `.test.tsx` extension
|
|
61
|
+
|
|
62
|
+
## 5. Styling
|
|
63
|
+
|
|
64
|
+
When asked to style, never use inline styles. Always use as much as possible the design system provided through `cdf-design-system-alpha`. Use tailwindcss actively. See here for more details. (cdf-design-system-alpha)[node_modules/cdf-design-system-alpha/AI_USAGE_GUIDE.md]
|
|
65
|
+
|
|
66
|
+
## 6. Anything Else to Know?
|
|
67
|
+
|
|
68
|
+
### Project Structure Highlights
|
|
69
|
+
|
|
70
|
+
- **`/src/components`**: Feature-based component organization
|
|
71
|
+
- **`/src/pages`**: Top-level page components and routing
|
|
72
|
+
- **`/src/hooks`**: Reusable custom hooks for business logic
|
|
73
|
+
- **`/src/services`**: Services connecting to external data and systems
|
|
74
|
+
- **`/src/config`**: Environment and application configuration
|
|
75
|
+
- **`/src/infrastructure`**: DO NOT EDIT THIS FOLDER. It contains important infrastructure. Use its components as stated
|
|
76
|
+
|
|
77
|
+
### Important Notes
|
|
78
|
+
|
|
79
|
+
- **Cognite Integration:** Heavy integration with Cognite Data Fusion APIs for industrial data
|
|
80
|
+
- **Design system:** Exclusively use components from cdf-design-system-alpha, unless the component does not exist in the library. (cdf-design-system-alpha)[node_modules/cdf-design-system-alpha/AI_USAGE_GUIDE.md] contains an AI usage guide.
|
|
81
|
+
|
|
82
|
+
### Infrastructure
|
|
83
|
+
|
|
84
|
+
The `/src/infrastructure` folder contains important react components used to enable the application to be run not only in a standalone environment, but also within Cognite Fusion - another web application. It handles the authentication for you, among other things, and will provide you an SDK to connect to CDF.
|
|
85
|
+
|
|
86
|
+
- `useCDF` will give you an SDK.
|
|
87
|
+
|
|
88
|
+
### Development Tips
|
|
89
|
+
|
|
90
|
+
- The app connects to Cognite's industrial data platform, so some features require proper API access
|
|
@@ -6,4 +6,30 @@ alwaysApply: true
|
|
|
6
6
|
|
|
7
7
|
Use the ShadCN MCP server to list the Cognite registry for components you can use. If there are no Cognite components fit for purpose, fallback to ShadCN registry ones. When building from reference, make sure to include all components in the reference material in your final build. Do not edit the styling of Cognite components.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Always use semantic Tailwind color classes (e.g., bg-primary, text-primary, border-primary) instead of arbitrary color values (e.g., bg-blue-600, text-red-500). This ensures consistency with the design system.
|
|
10
|
+
|
|
11
|
+
Run `pnpm lint` after your changes to make sure you have fixed all potential errors.
|
|
12
|
+
|
|
13
|
+
When setting up auth rememeber to set up the oidcTokenProvider.
|
|
14
|
+
|
|
15
|
+
Use this function to get the token string:
|
|
16
|
+
|
|
17
|
+
export const getToken = async (clientId: string, clientSecret: string) => {
|
|
18
|
+
const header = "Basic " + btoa(`${clientId}:${clientSecret}`);
|
|
19
|
+
|
|
20
|
+
const response = await fetch("https://auth.cognite.com/oauth2/token", {
|
|
21
|
+
method: "POST",
|
|
22
|
+
headers: {
|
|
23
|
+
Authorization: header,
|
|
24
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
25
|
+
},
|
|
26
|
+
body: new URLSearchParams({
|
|
27
|
+
grant_type: "client_credentials",
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const data = await response.json();
|
|
32
|
+
|
|
33
|
+
console.log("Token response:", data);
|
|
34
|
+
return data.access_token;
|
|
35
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: When asked to develop a set of requirements for an application.
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
USE THE TEMPLATE PROVIDED VIA docs/TEMPLATE_REQUIREMENTS.MD.
|
|
7
|
+
|
|
8
|
+
Generate a comprehensive requirements document for a new application. The application will be a web-based dashboard and reporting tool for monitoring industrial asset performance. The core data model is based on CDF (Cognite Data Fusion). The requirements document should include the following sections:
|
|
9
|
+
|
|
10
|
+
Introduction: A high-level overview of the application's purpose and its target users.
|
|
11
|
+
|
|
12
|
+
Functional Requirements: A detailed list of what the application must do, including data visualization, reporting, user authentication, and interaction with CDF. Specify how data will be retrieved (e.g., using Cognite's APIs for time series. DO NOT USE ASSETS. Only use Data modelling), transformed, and presented.
|
|
13
|
+
|
|
14
|
+
Non-Functional Requirements: Cover aspects like performance (e.g., dashboard load times), security (e.g., user roles and permissions mapped to CDF's security model), scalability, and usability.
|
|
15
|
+
|
|
16
|
+
Data Model & Integration: Describe how the application's data model maps directly to the CDF data model. This section is crucial and must detail the specific CDF core data models and how they will be used to structure the application's data. Include details on how the application will use CDF's asset hierarchy to navigate and filter data. Define new view structures when needed
|
|
17
|
+
|
|
18
|
+
User Stories: Create a set of user stories that encapsulate the key features from the functional requirements, written from the perspective of a typical user (e.g., a plant manager or a maintenance engineer).
|
|
19
|
+
|
|
20
|
+
Technology Stack: Always use what is defined in the development.mdc rule.
|
|
21
|
+
|
|
22
|
+
Ensure the document is structured with clear headings and a professional tone. The output should be a detailed, well-organized document that can serve as a blueprint for the development team.
|
|
23
|
+
|
|
24
|
+
USE THE TEMPLATE PROVIDED VIA docs/TEMPLATE_REQUIREMENTS.MD.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Cognite Configuration
|
|
2
|
+
NEXT_PUBLIC_COGNITE_PROJECT=your-project-name
|
|
3
|
+
NEXT_PUBLIC_COGNITE_BASE_URL=https://api.cognitedata.com
|
|
4
|
+
|
|
5
|
+
# OIDC Authentication (Required for production)
|
|
6
|
+
NEXT_PUBLIC_COGNITE_CLIENT_ID=your_client_id
|
|
7
|
+
NEXT_PUBLIC_COGNITE_TENANT_ID=6a5949bb-8ea1-4bd1-aa0a-4d03846de30e
|
|
8
|
+
COGNITE_CLIENT_SECRET=your_client_secret
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# CDF Application Template
|
|
2
|
+
|
|
3
|
+
A React application template for building applications with Cognite Data Fusion (CDF) using AI assistance.
|
|
4
|
+
|
|
5
|
+
## Prerequisites
|
|
6
|
+
|
|
7
|
+
This project requires Node.js v22 or higher and npm (Node Package Manager).
|
|
8
|
+
|
|
9
|
+
**Don't have Node.js installed?** See [Installing Node.js and npm](#installing-nodejs-and-npm) at the bottom of this document.
|
|
10
|
+
|
|
11
|
+
## Initial Setup
|
|
12
|
+
|
|
13
|
+
1. **Configure your app:** Fill in `app.json` with your application details
|
|
14
|
+
2. **Install dependencies:** `npm install`
|
|
15
|
+
3. **Start development server:** `npm start`
|
|
16
|
+
4. **Deploy to CDF:** `npm run deploy`
|
|
17
|
+
|
|
18
|
+
### Optional: Enable Fast Deployment & MCP Server
|
|
19
|
+
|
|
20
|
+
Create a `.env` file with your CDF credentials:
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
CLIENT_ID=your-client-id
|
|
24
|
+
CLIENT_SECRET=your-client-secret
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
This enables:
|
|
28
|
+
|
|
29
|
+
- **Faster CI deployment:** `npm run deploy:ci`
|
|
30
|
+
- **MCP server for Cursor:** AI can query and create data models directly in CDF
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **MCP Server Integration:** Query CDF data models, spaces, views, and containers directly through Cursor
|
|
35
|
+
- **Cognite Design System:** Pre-configured `cdf-design-system-alpha` for consistent UI styling
|
|
36
|
+
- **Requirements Template:** Structured template to guide AI in building your application
|
|
37
|
+
- **Authentication Included:** Ready-to-use auth for both local development and CDF hosting
|
|
38
|
+
- **Data Modeling Support:** AI can help structure and connect to CDF data models
|
|
39
|
+
|
|
40
|
+
## Building Your Application
|
|
41
|
+
|
|
42
|
+
### 1. Request a Requirements Doc
|
|
43
|
+
|
|
44
|
+
Ask your AI assistant to create requirements based on your input:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
"Write me a set of requirements for an application that [describe your needs]"
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Review the generated requirements carefully. Add, remove, or modify as needed.
|
|
51
|
+
|
|
52
|
+
### 2. Review Requirements List
|
|
53
|
+
|
|
54
|
+
Go through the requirements document line by line. Make sure it accurately captures what you want to build.
|
|
55
|
+
|
|
56
|
+
### 3. Request a Dummy Data Version
|
|
57
|
+
|
|
58
|
+
Start with a working prototype using mock data:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
"Build a dummy data version of this application based on the requirements"
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 4. Build and Iterate
|
|
65
|
+
|
|
66
|
+
Run `npm start` and test your application. Iterate on the UI, functionality, and user experience with your AI assistant.
|
|
67
|
+
|
|
68
|
+
### 5. Connect to CDF (Step by Step)
|
|
69
|
+
|
|
70
|
+
Once satisfied with the prototype, connect it to real CDF data:
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
"Let's connect this to CDF data models. Start by creating the space and containers we need."
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Take this **step by step** - this is where you're most likely to run into issues. Create spaces, then containers, then views, then connect your UI.
|
|
77
|
+
|
|
78
|
+
## Tips and Tricks
|
|
79
|
+
|
|
80
|
+
### Important Warnings
|
|
81
|
+
|
|
82
|
+
⚠️ **If you get errors:** Copy-paste the error into Cursor. If it doesn't work after 3 attempts, ask it to simplify the approach.
|
|
83
|
+
|
|
84
|
+
⚠️ **Don't try to implement notifications** - This rarely works well
|
|
85
|
+
|
|
86
|
+
⚠️ **Don't extend existing data models** - It will likely not work. Create new views instead.
|
|
87
|
+
|
|
88
|
+
⚠️ **Don't delete data models** - You can't easily recover them
|
|
89
|
+
|
|
90
|
+
⚠️ **Limited availability:** Only enabled for select Cognite projects (e.g., lervik, atlas). Not to be used in customer projects.
|
|
91
|
+
|
|
92
|
+
⚠️ **Commit after every step** - Version control saves you from having to rebuild everything
|
|
93
|
+
|
|
94
|
+
### Helpful Prompts
|
|
95
|
+
|
|
96
|
+
- Open browser console to see errors, paste them into Cursor
|
|
97
|
+
- If AI isn't using the design system: "Please use the cdf-design-system-alpha design system"
|
|
98
|
+
- To get correct types: "Fetch the [ViewName] view from CDF and use that to define the type"
|
|
99
|
+
- To check data models: "List the available views in the [space_name] space"
|
|
100
|
+
|
|
101
|
+
## Environment Variables
|
|
102
|
+
|
|
103
|
+
Your `.env` file (optional, for MCP and fast deployment):
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
CLIENT_ID=your-client-id
|
|
107
|
+
CLIENT_SECRET=your-client-secret
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Development Commands
|
|
111
|
+
|
|
112
|
+
- `npm start` - Start development server
|
|
113
|
+
- `npm run build` - Build for production
|
|
114
|
+
- `npm run lint` - Run linter
|
|
115
|
+
- `npm run deploy` - Deploy to CDF
|
|
116
|
+
- `npm run deploy:ci` - Fast deployment (requires .env)
|
|
117
|
+
|
|
118
|
+
## Security
|
|
119
|
+
|
|
120
|
+
- Never commit `.env` files
|
|
121
|
+
- Environment files are automatically ignored by git
|
|
122
|
+
- Use service account credentials for deployment only
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Installing Node.js and npm
|
|
127
|
+
|
|
128
|
+
This project requires Node.js v22 or higher and npm (Node Package Manager).
|
|
129
|
+
|
|
130
|
+
### macOS
|
|
131
|
+
|
|
132
|
+
**Option 1: Using Homebrew (recommended)**
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
# Install Homebrew if you don't have it
|
|
136
|
+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
|
137
|
+
|
|
138
|
+
# Install Node.js (includes npm)
|
|
139
|
+
brew install node@22
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Option 2: Using the official installer**
|
|
143
|
+
|
|
144
|
+
1. Download the installer from [nodejs.org](https://nodejs.org/)
|
|
145
|
+
2. Choose the LTS (Long Term Support) version
|
|
146
|
+
3. Run the installer and follow the prompts
|
|
147
|
+
|
|
148
|
+
### Windows
|
|
149
|
+
|
|
150
|
+
**Option 1: Using the official installer (recommended)**
|
|
151
|
+
|
|
152
|
+
1. Download the installer from [nodejs.org](https://nodejs.org/)
|
|
153
|
+
2. Choose the LTS (Long Term Support) version
|
|
154
|
+
3. Run the `.msi` installer and follow the prompts
|
|
155
|
+
4. Restart your terminal/command prompt
|
|
156
|
+
|
|
157
|
+
**Option 2: Using Chocolatey**
|
|
158
|
+
|
|
159
|
+
```powershell
|
|
160
|
+
# Install Chocolatey if you don't have it
|
|
161
|
+
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
|
|
162
|
+
|
|
163
|
+
# Install Node.js
|
|
164
|
+
choco install nodejs-lts
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Linux
|
|
168
|
+
|
|
169
|
+
**Ubuntu/Debian:**
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
# Install Node.js 22.x
|
|
173
|
+
curl -fsSL https://deb.nodesource.com/setup_22.x | sudo -E bash -
|
|
174
|
+
sudo apt-get install -y nodejs
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Fedora/RHEL/CentOS:**
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
# Install Node.js 22.x
|
|
181
|
+
curl -fsSL https://rpm.nodesource.com/setup_22.x | sudo bash -
|
|
182
|
+
sudo yum install -y nodejs
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Arch Linux:**
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
sudo pacman -S nodejs npm
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Verify Installation
|
|
192
|
+
|
|
193
|
+
After installation, verify that Node.js and npm are installed correctly:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
node --version # Should show v22.x.x or higher
|
|
197
|
+
npm --version # Should show 10.x.x or higher
|
|
198
|
+
```
|