Skip to content

Commit 81eebe4

Browse files
committed
Setup Kiro, docs/, web_app_template, and Inventory_Dashboard
1 parent eb7a8ae commit 81eebe4

60 files changed

Lines changed: 16834 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"enabled": true,
3+
"name": "Check Docs Before Writing",
4+
"description": "Before writing any Python file, the agent checks the NCM API documentation and known issues to ensure the code follows documented patterns and avoids known gotchas.",
5+
"version": "1",
6+
"when": {
7+
"type": "preToolUse",
8+
"toolTypes": [
9+
"write"
10+
]
11+
},
12+
"then": {
13+
"type": "askAgent",
14+
"prompt": "Check if the file being written is a Python (.py) file. If it is NOT a .py file (e.g., it's a .md, .json, .css, .html, or other non-Python file), skip this check entirely and proceed with the write. If it IS a .py file, verify: (1) Have you consulted the relevant docs in docs/ for the API endpoints being used? (2) Have you checked docs/known-issues.md for gotchas? (3) Are you following the patterns in docs/common-patterns.md? (4) Are all API URLs using trailing slashes? (5) Is error handling with retries included? (6) Does the script call check_env() from utils.env_check at startup? If you haven't consulted the docs yet, read the relevant ones now before proceeding."
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"enabled": true,
3+
"name": "Fix Errors After Run",
4+
"description": "After running any shell command (typically tests or script execution), the agent reviews the output for errors and iterates on fixes until the code runs clean.",
5+
"version": "1",
6+
"when": {
7+
"type": "postToolUse",
8+
"toolTypes": [
9+
"shell"
10+
]
11+
},
12+
"then": {
13+
"type": "askAgent",
14+
"prompt": "Review the output of the command that just ran. If there are any errors (syntax errors, import errors, runtime exceptions, API errors), diagnose the root cause and fix the code. Re-run until clean. If the error reveals something about the API that isn't documented, make a note to update docs in the reflexion step."
15+
}
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"enabled": true,
3+
"name": "Reflexion: Update Docs",
4+
"description": "After the agent stops, it reviews whether any new API behaviors, gotchas, or patterns were discovered during the session and updates docs/known-issues.md, docs/common-patterns.md, and docs/CHANGELOG.md accordingly. Only updates docs for generally applicable discoveries, not app-specific ones.",
5+
"version": "1",
6+
"when": {
7+
"type": "agentStop"
8+
},
9+
"then": {
10+
"type": "askAgent",
11+
"prompt": "Review the work you just completed. Did you discover any new API behaviors, gotchas, workarounds, or reusable patterns that are NOT already documented in docs/known-issues.md or docs/common-patterns.md? If yes, and if the discovery applies generally (not just to this specific app), update the relevant docs file and append an entry to docs/CHANGELOG.md. If nothing new was discovered, do nothing."
12+
}
13+
}

.kiro/steering/code-standards.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
inclusion: auto
3+
---
4+
5+
# Code Standards for NCM Scripts
6+
7+
## Virtual Environment
8+
9+
**Always use the project `.venv`**. Never run scripts with the system Python.
10+
11+
When running any script or command, use:
12+
```bash
13+
.venv/bin/python scripts/my_script.py
14+
```
15+
16+
When installing packages:
17+
```bash
18+
.venv/bin/pip install -r requirements.txt
19+
```
20+
21+
The venv uses Python 3.12 and is located at the project root `.venv/`.
22+
23+
## Required Environment Variables
24+
25+
All scripts require these environment variables for API authentication:
26+
27+
| Variable | Description |
28+
|----------|-------------|
29+
| `CP_API_ID` | Cradlepoint API ID |
30+
| `CP_API_KEY` | Cradlepoint API Key |
31+
| `ECM_API_ID` | ECM API ID |
32+
| `ECM_API_KEY` | ECM API Key |
33+
34+
Optional (for v3 API):
35+
36+
| Variable | Description |
37+
|----------|-------------|
38+
| `CP_API_TOKEN` | Bearer token for API v3 |
39+
40+
### If env vars are not set, scripts must detect this and print setup instructions.
41+
42+
Use the helper at `scripts/utils/env_check.py` (see below) to validate at script startup.
43+
44+
### How to set env vars by OS:
45+
46+
**Recommended: Use the setup script**
47+
```bash
48+
.venv/bin/python setup_env.py
49+
```
50+
This prompts for all keys (including v3 token), injects them into the `.venv/bin/activate`
51+
scripts, and they load automatically every time you `source .venv/bin/activate`.
52+
Run it again anytime to update credentials.
53+
54+
**Manual setup — macOS / Linux (bash/zsh):**
55+
```bash
56+
export CP_API_ID="your_cp_api_id"
57+
export CP_API_KEY="your_cp_api_key"
58+
export ECM_API_ID="your_ecm_api_id"
59+
export ECM_API_KEY="your_ecm_api_key"
60+
export CP_API_TOKEN="your_v3_token" # optional, for v3 API
61+
```
62+
To persist, add these to `~/.zshrc` (macOS) or `~/.bashrc` (Linux).
63+
64+
**Windows (PowerShell):**
65+
```powershell
66+
$env:CP_API_ID = "your_cp_api_id"
67+
$env:CP_API_KEY = "your_cp_api_key"
68+
$env:ECM_API_ID = "your_ecm_api_id"
69+
$env:ECM_API_KEY = "your_ecm_api_key"
70+
$env:CP_API_TOKEN = "your_v3_token" # optional, for v3 API
71+
```
72+
To persist, use System Properties → Environment Variables, or add to your PowerShell profile.
73+
74+
**Windows (Command Prompt):**
75+
```cmd
76+
set CP_API_ID=your_cp_api_id
77+
set CP_API_KEY=your_cp_api_key
78+
set ECM_API_ID=your_ecm_api_id
79+
set ECM_API_KEY=your_ecm_api_key
80+
set CP_API_TOKEN=your_v3_token &REM optional, for v3 API
81+
```
82+
83+
## File Structure
84+
85+
All new scripts should follow this structure:
86+
```python
87+
"""
88+
Script description.
89+
"""
90+
import os
91+
import sys
92+
93+
# Add project root to path if needed
94+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
95+
96+
from utils.env_check import check_env
97+
from utils.credentials import get_credentials
98+
from utils.session import APISession
99+
from utils.logger import get_logger
100+
101+
def main():
102+
"""Main entry point."""
103+
check_env() # Always call first — exits with instructions if vars missing
104+
# ... implementation
105+
106+
if __name__ == '__main__':
107+
main()
108+
```
109+
110+
## Authentication
111+
112+
- Never hardcode API keys in source files
113+
- Use environment variables (preferred) or `scripts/utils/credentials.py` as fallback
114+
- For the NCM SDK: pass keys as a dictionary
115+
- For direct API calls: use `scripts/utils/session.py`
116+
117+
## Error Handling
118+
119+
- Always wrap API calls in try/except
120+
- Implement retry logic for transient errors (408, 429, 503, 504)
121+
- Log errors with context (which endpoint, what parameters)
122+
123+
## Output
124+
125+
- Use CSV for tabular data exports
126+
- Use JSON for structured data
127+
- Print progress for long-running operations
128+
- Store output files in `scripts/script_manager/csv_files/` when using script_manager
129+
130+
## Dependencies
131+
132+
- Core: `requests`, `ncm` (SDK)
133+
- Check `requirements.txt` before adding new dependencies
134+
- If a new dependency is needed, add it to `requirements.txt`
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
inclusion: auto
3+
---
4+
5+
# NetCloud Manager API Development Guide
6+
7+
## Reflexion Workflow
8+
9+
When building any application that uses the Cradlepoint NetCloud Manager API, follow this workflow:
10+
11+
### 1. Consult Documentation First
12+
Before writing any code, read the relevant documentation in `docs/`:
13+
- `docs/api-overview.md` — for auth, base URLs, pagination, filtering
14+
- `docs/api-v2-endpoints.md` — for v2 endpoint details
15+
- `docs/api-v3-endpoints.md` — for v3 endpoint details
16+
- `docs/api-configuration.md` — for device/group configuration
17+
- `docs/api-webhooks.md` — for webhook setup
18+
- `docs/ncm-sdk-reference.md` — for Python SDK methods
19+
- `docs/common-patterns.md` — for reusable code patterns
20+
- `docs/known-issues.md` — for gotchas and workarounds
21+
22+
### 2. Choose the Right Approach
23+
- Use the NCM SDK (`from ncm import ncm`) when possible — it handles pagination, retries, auth
24+
- Use `scripts/utils/session.py` for direct API calls with automatic retry/pagination
25+
- Use raw `requests` only when SDK/session don't cover the use case
26+
27+
### 3. Build and Test
28+
- Write the code following patterns in `docs/common-patterns.md`
29+
- Run the code and check for errors
30+
- Fix errors iteratively until clean
31+
32+
### 4. Reflexion — Update Documentation
33+
After completing any task, evaluate whether you discovered anything new:
34+
- **New API behavior** not documented → update the relevant `docs/*.md` file
35+
- **Bug or gotcha** discovered → append to `docs/known-issues.md`
36+
- **New reusable pattern** → add to `docs/common-patterns.md`
37+
- **Documentation was wrong** → fix it and log the change in `docs/CHANGELOG.md`
38+
- **Only applies to this specific app** → do NOT update docs (keep docs general)
39+
40+
## Endpoint Routing Guide
41+
42+
Use this to quickly find which doc and SDK method to use for a given task:
43+
44+
| Task | Doc File | SDK Methods |
45+
|------|----------|-------------|
46+
| List/manage routers | api-v2-endpoints.md → routers | `get_routers()`, `get_router_by_id()` |
47+
| Router online/offline status | api-v2-endpoints.md → router_state_samples | `get_router_state_samples()` |
48+
| Push device config | api-configuration.md | `patch_configuration_managers()`, `put_configuration_managers()` |
49+
| Push group config | api-configuration.md | `patch_group_configuration()`, `put_group_configuration()` |
50+
| Get/set locations | api-v2-endpoints.md → locations | `get_locations()`, `get_historical_locations()` |
51+
| Manage alerts | api-v2-endpoints.md → alerts | `get_alerts()`, `get_router_alerts()` |
52+
| Setup webhooks | api-webhooks.md | Direct API calls to `alert_push_destinations` |
53+
| Manage groups | api-v2-endpoints.md → groups | `get_groups()`, `create_group_by_parent_id()` |
54+
| Network device info | api-v2-endpoints.md → net_devices | `get_net_devices()`, `get_net_device_metrics()` |
55+
| Signal/usage data | api-v2-endpoints.md → net_device_signal/usage | `get_net_device_signal_samples()`, `get_net_device_usage_samples()` |
56+
| Firmware info | api-v2-endpoints.md → firmwares | `get_firmwares()` |
57+
| Reboot devices | api-v2-endpoints.md → reboot_activity | `reboot_device()`, `reboot_group()` |
58+
| Speed tests | api-v2-endpoints.md → speed_test | `create_speed_test()` |
59+
| Manage users | api-v3-endpoints.md → users | `get_users()`, `create_user()` |
60+
| Subscriptions | api-v3-endpoints.md → subscriptions | `get_subscriptions()`, `regrade()` |
61+
| Private cellular | api-v3-endpoints.md → private_cellular_* | `get_private_cellular_networks()`, etc. |
62+
| NCX sites/resources | api-v3-endpoints.md → exchange_* | `get_exchange_sites()`, `create_exchange_site()` |
63+
| Export data to CSV | common-patterns.md | `export_to_csv()` pattern |
64+
| Batch operations | common-patterns.md | `batch_operation()` pattern |
65+
66+
## Critical Rules (Always Follow)
67+
68+
1. **Trailing slash**: ALL v2 URLs must end with `/`
69+
2. **Config manager ID ≠ Router ID**: Always look up the config manager ID first
70+
3. **PATCH vs PUT**: PATCH merges, PUT replaces. Use PATCH for incremental changes
71+
4. **_id_ fields**: When using UUID keys, include `_id_` inside the object too
72+
5. **Check deprecations**: Before using any endpoint, verify it's not deprecated in `docs/api-deprecations.md`
73+
6. **Error handling**: Always implement retry logic with exponential backoff
74+
7. **Pagination**: Always handle pagination for list endpoints (SDK does this automatically)
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
inclusion: auto
3+
---
4+
5+
# Reflexion Workflow System
6+
7+
## Purpose
8+
9+
This steering file defines the reflexion loop: a self-improving workflow where the AI
10+
updates its own documentation and steering rules when it discovers new information
11+
during development.
12+
13+
## The Reflexion Loop
14+
15+
```
16+
User Request → Consult Docs → Build Code → Test → Fix Errors → Reflect → Update Docs
17+
↑ |
18+
└──────────────────────────────────────────────────────────┘
19+
```
20+
21+
## When Building Any NCM Application
22+
23+
### Step 1: Understand the Request
24+
- Identify which API endpoints are needed
25+
- Check `#[[file:docs/api-overview.md]]` for API basics
26+
- Use the Endpoint Routing Guide in the NCM steering to find the right docs
27+
28+
### Step 2: Check Known Issues
29+
- Read `#[[file:docs/known-issues.md]]` before writing code
30+
- Avoid known pitfalls
31+
32+
### Step 3: Write Code
33+
- Follow patterns from `#[[file:docs/common-patterns.md]]`
34+
- Use the NCM SDK when possible
35+
- Include proper error handling and retry logic
36+
37+
### Step 4: Test
38+
- Run the code
39+
- Check for syntax errors, import errors, runtime errors
40+
- Verify output matches expectations
41+
42+
### Step 5: Fix Errors
43+
- If errors occur, diagnose and fix
44+
- Re-run until clean
45+
- If the error reveals a documentation gap, note it for Step 6
46+
47+
### Step 6: Reflect and Update
48+
After completing the task, ask yourself:
49+
50+
**Should I update documentation?** Update if:
51+
- You discovered an API behavior not documented in `docs/`
52+
- You found a documentation error
53+
- You created a reusable pattern others could benefit from
54+
- You hit a gotcha that should be warned about
55+
56+
**Should I NOT update documentation?** Skip if:
57+
- The discovery is specific to this one application
58+
- It's a user-specific configuration issue
59+
- It's already documented
60+
61+
**What to update:**
62+
- `docs/known-issues.md` — append new gotchas under "Discovered Issues Log"
63+
- `docs/common-patterns.md` — add new reusable patterns
64+
- `docs/CHANGELOG.md` — log what changed and why
65+
- Relevant `docs/*.md` file — fix errors or add missing info
66+
- `.kiro/steering/*.md` — update routing guide if new endpoint patterns discovered
67+
68+
## Documentation Update Format
69+
70+
When appending to `docs/known-issues.md`:
71+
```markdown
72+
### [Short Title] (discovered YYYY-MM-DD)
73+
[Description of the issue and workaround]
74+
```
75+
76+
When appending to `docs/CHANGELOG.md`:
77+
```markdown
78+
## YYYY-MM-DD — [Brief Description]
79+
- [What changed and why]
80+
```
81+
82+
## Quality Gates
83+
84+
Before considering any NCM application complete:
85+
1. Code runs without errors
86+
2. All API calls use proper authentication
87+
3. All URLs have trailing slashes
88+
4. Pagination is handled for list operations
89+
5. Error handling with retries is implemented
90+
6. No deprecated endpoints are used
91+
7. Documentation has been updated if applicable

0 commit comments

Comments
 (0)