karni-cli 0.3.1__py3-none-any.whl
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.
- karni_cli/__init__.py +3 -0
- karni_cli/_agent/__init__.py +82 -0
- karni_cli/_agent/__main__.py +44 -0
- karni_cli/_agent/check.py +658 -0
- karni_cli/_agent/history.py +328 -0
- karni_cli/_agent/history_chronicle.py +246 -0
- karni_cli/_agent/overrides.py +194 -0
- karni_cli/_agent/rules.py +673 -0
- karni_cli/_changelog/0.2.0.toml +304 -0
- karni_cli/_changelog/0.3.0.toml +25 -0
- karni_cli/_changelog/__init__.py +248 -0
- karni_cli/_errorcodes/__init__.py +1171 -0
- karni_cli/_errorcodes/__main__.py +34 -0
- karni_cli/_errorcodes/links.py +217 -0
- karni_cli/_templates/project/cookiecutter.json +8 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/.dockerignore +7 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/.env.example +85 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/.gitignore +10 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/Caddyfile +22 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/Dockerfile +53 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/Makefile +52 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/README.md +169 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/config/__init__.py +16 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/config/asgi.py +14 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/config/celery.py +17 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/config/settings.py +28 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/config/urls.py +31 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/config/wsgi.py +14 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/docker-compose.yml +126 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/.dockerignore +2 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/.jscpd.json +9 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/.npmrc +7 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/Dockerfile.dev +17 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/eslint.config.js +32 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/index.html +14 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/package.json +43 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/postcss.config.js +6 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/public/favicon.svg +6 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/src/App.tsx +18 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/src/api/health.ts +21 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/src/index.css +11 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/src/layout.tsx +51 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/src/main.tsx +11 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/src/pages/home.tsx +28 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/src/routes.tsx +24 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/src/vite-env.d.ts +1 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/tailwind.config.ts +13 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/tsconfig.json +19 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/frontend/vite.config.ts +18 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/manage.py +23 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/pyproject.toml +31 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/tests/__init__.py +0 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/tests/test_api_schema.py +17 -0
- karni_cli/_templates/project/{{cookiecutter.project_slug}}/tests/test_smoke.py +11 -0
- karni_cli/adapters.py +373 -0
- karni_cli/agent_adapters.toml +160 -0
- karni_cli/agent_data.py +260 -0
- karni_cli/brand.py +55 -0
- karni_cli/clidoc.py +254 -0
- karni_cli/commands/__init__.py +0 -0
- karni_cli/commands/add.py +144 -0
- karni_cli/commands/beat.py +36 -0
- karni_cli/commands/check.py +101 -0
- karni_cli/commands/config.py +81 -0
- karni_cli/commands/context.py +171 -0
- karni_cli/commands/createsuperuser.py +28 -0
- karni_cli/commands/doctor.py +136 -0
- karni_cli/commands/explain.py +60 -0
- karni_cli/commands/make.py +55 -0
- karni_cli/commands/manage_passthrough.py +28 -0
- karni_cli/commands/mcp.py +20 -0
- karni_cli/commands/migrate.py +23 -0
- karni_cli/commands/new.py +106 -0
- karni_cli/commands/routes.py +20 -0
- karni_cli/commands/rules.py +139 -0
- karni_cli/commands/run_tests.py +38 -0
- karni_cli/commands/schedule.py +40 -0
- karni_cli/commands/seed.py +34 -0
- karni_cli/commands/serve.py +50 -0
- karni_cli/commands/shell.py +28 -0
- karni_cli/commands/sync_roles.py +32 -0
- karni_cli/commands/types.py +72 -0
- karni_cli/commands/upgrade.py +231 -0
- karni_cli/commands/worker.py +63 -0
- karni_cli/config.py +142 -0
- karni_cli/environment.py +29 -0
- karni_cli/errorcodes.py +377 -0
- karni_cli/errordoc.py +227 -0
- karni_cli/generators/__init__.py +67 -0
- karni_cli/generators/apitest.py +206 -0
- karni_cli/generators/app.py +103 -0
- karni_cli/generators/command.py +98 -0
- karni_cli/generators/component.py +115 -0
- karni_cli/generators/core.py +319 -0
- karni_cli/generators/event.py +57 -0
- karni_cli/generators/factory.py +88 -0
- karni_cli/generators/fields.py +343 -0
- karni_cli/generators/introspect.py +263 -0
- karni_cli/generators/listener.py +168 -0
- karni_cli/generators/middleware.py +95 -0
- karni_cli/generators/migration.py +82 -0
- karni_cli/generators/model.py +235 -0
- karni_cli/generators/module.py +255 -0
- karni_cli/generators/naming.py +100 -0
- karni_cli/generators/page.py +373 -0
- karni_cli/generators/pysource.py +304 -0
- karni_cli/generators/schedule.py +174 -0
- karni_cli/generators/seeder.py +86 -0
- karni_cli/generators/serializer.py +165 -0
- karni_cli/generators/service.py +68 -0
- karni_cli/generators/task.py +84 -0
- karni_cli/generators/viewset.py +179 -0
- karni_cli/history.py +59 -0
- karni_cli/local_state.py +73 -0
- karni_cli/main.py +104 -0
- karni_cli/mcp_server.py +103 -0
- karni_cli/project.py +248 -0
- karni_cli/rules_render.py +86 -0
- karni_cli/scaffold.py +197 -0
- karni_cli/settings_edit.py +128 -0
- karni_cli/tips.py +53 -0
- karni_cli/typegen.py +101 -0
- karni_cli/upgrades/__init__.py +28 -0
- karni_cli/upgrades/changelog.py +123 -0
- karni_cli/upgrades/codemod.py +125 -0
- karni_cli/upgrades/engine.py +224 -0
- karni_cli/upgrades/legacy_agent_files.py +138 -0
- karni_cli/upgrades/python.py +670 -0
- karni_cli/upgrades/transforms/rename-export.cjs +96 -0
- karni_cli/upgrades/typescript.py +160 -0
- karni_cli/upgrades/v0_2/__init__.py +1 -0
- karni_cli/upgrades/v0_2/agent_guidance.py +269 -0
- karni_cli/upgrades/v1_0/__init__.py +5 -0
- karni_cli/upgrades/v1_0/all_objects_to_without.py +18 -0
- karni_cli/upgrades/v1_0/all_with_deleted_to_without.py +13 -0
- karni_cli/upgrades/v1_0/deleted_only_to_without_dead.py +13 -0
- karni_cli/upgrades/v1_0/object_permission_classes_to_access.py +16 -0
- karni_cli/upgrades/v1_0/related_lookups_to_optimize.py +15 -0
- karni_cli/upgrades/v1_0/scoped_related_lookups_to_optimize.py +15 -0
- karni_cli/upgrades/v1_0/soft_delete_manager_mixin_to_scoped.py +14 -0
- karni_cli-0.3.1.dist-info/METADATA +191 -0
- karni_cli-0.3.1.dist-info/RECORD +145 -0
- karni_cli-0.3.1.dist-info/WHEEL +4 -0
- karni_cli-0.3.1.dist-info/entry_points.txt +2 -0
- karni_cli-0.3.1.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Karni's phase-8 scaffold agent files, frozen verbatim (karni-cli 0.1.0 template).
|
|
2
|
+
|
|
3
|
+
The upgrade codemod (:mod:`karni_cli.upgrades.v0_2.agent_guidance`) diffs a
|
|
4
|
+
project's files against these to tell Karni's text from the project's own
|
|
5
|
+
additions. Never edit them: they are historical records, not guidance.
|
|
6
|
+
``PROJECT_NAME`` marks where the template substituted the project name.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
PROJECT_NAME = "<<PROJECT_NAME>>"
|
|
12
|
+
|
|
13
|
+
#: relative path -> verbatim content of the generated file
|
|
14
|
+
LEGACY_FILES: dict[str, str] = {
|
|
15
|
+
"AGENTS.md": (
|
|
16
|
+
"# <<PROJECT_NAME>> — agent guidance\n"
|
|
17
|
+
"\n"
|
|
18
|
+
"This project is built on Karni. Karni already implements everything generic;\n"
|
|
19
|
+
"you write only domain code. Extending Karni is always cheaper than reinventing it.\n"
|
|
20
|
+
"\n"
|
|
21
|
+
"## First action, every session\n"
|
|
22
|
+
"Run `karni context` before reading any files. It prints the current models,\n"
|
|
23
|
+
"viewsets, UI components, hooks and installed modules in ~200 tokens. Trust it.\n"
|
|
24
|
+
"\n"
|
|
25
|
+
"## Never write\n"
|
|
26
|
+
"Auth flows, user models, admin registration, serializers, routers, settings,\n"
|
|
27
|
+
"Docker/Compose config, Celery config, HTML tables, forms, or detail views.\n"
|
|
28
|
+
"Karni provides all of these. If you think you need one, you need an override\n"
|
|
29
|
+
"on an existing Karni base instead.\n"
|
|
30
|
+
"\n"
|
|
31
|
+
"## Always\n"
|
|
32
|
+
"- Models inherit `karni.models.BaseModel` (or `SoftDeleteModel`).\n"
|
|
33
|
+
"- Viewsets inherit `karni.api.BaseViewSet` — usually just `model = X`.\n"
|
|
34
|
+
"- Screens compose `@karni/ui` components (`Page`, `ResourceTable`,\n"
|
|
35
|
+
" `ResourceForm`, `ResourceDetail`, ...). Never hand-roll a table or form.\n"
|
|
36
|
+
"- Page files stay at 50 lines or fewer (enforced by `karni/max-page-lines`).\n"
|
|
37
|
+
" Past that you are rebuilding something Karni ships — use the component's props.\n"
|
|
38
|
+
"- After any model change: `make migrate && karni types`.\n"
|
|
39
|
+
"- Run `karni check` before committing — every rule fails the build. Opt-outs\n"
|
|
40
|
+
" are inline and REQUIRE a reason, e.g. `# karni: allow(raw-sql): <why>`.\n"
|
|
41
|
+
"\n"
|
|
42
|
+
"## Extend, don't fork\n"
|
|
43
|
+
"If an existing component or base class almost fits, extend it through its\n"
|
|
44
|
+
"override props / hooks (`columns`, `fields`, `slots`, `AdminMeta`, `APIMeta`,\n"
|
|
45
|
+
"overridable methods). Do not create a parallel variant.\n"
|
|
46
|
+
"\n"
|
|
47
|
+
"## The stack is fixed\n"
|
|
48
|
+
"Do not introduce a state library, form library, table library, HTTP client or\n"
|
|
49
|
+
"CSS framework beyond what Karni ships (TanStack Query/Table, react-hook-form,\n"
|
|
50
|
+
"Zod, Tailwind, Radix via @karni/ui).\n"
|
|
51
|
+
"\n"
|
|
52
|
+
"## Where code goes\n"
|
|
53
|
+
"- Backend app: `<app>/models.py`, `<app>/viewsets.py` — nothing else per entity.\n"
|
|
54
|
+
"- Frontend pages: `frontend/src/pages/`.\n"
|
|
55
|
+
"- Project slash commands: `.claude/commands/` (/new-model, /new-page,\n"
|
|
56
|
+
" /add-module, /new-module) encode the standard procedures — prefer them.\n"
|
|
57
|
+
"\n"
|
|
58
|
+
"## Commands\n"
|
|
59
|
+
"- `make up` — start the stack; `make migrate` — makemigrations + migrate\n"
|
|
60
|
+
"- `karni types` — regenerate TS types + typed hooks from the API schema\n"
|
|
61
|
+
"- `karni check` — architecture and system checks; `karni context` — inventory\n"
|
|
62
|
+
),
|
|
63
|
+
"CLAUDE.md": ("@AGENTS.md\n"),
|
|
64
|
+
".cursorrules": (
|
|
65
|
+
"Canonical agent rules live in AGENTS.md at the project root. Read AGENTS.md\n"
|
|
66
|
+
"before any work and follow it exactly. Do not duplicate its content here —\n"
|
|
67
|
+
"AGENTS.md is the single source of truth (CLAUDE.md and this file only point\n"
|
|
68
|
+
"to it, so the three can never drift).\n"
|
|
69
|
+
),
|
|
70
|
+
".claude/commands/new-model.md": (
|
|
71
|
+
"---\n"
|
|
72
|
+
"description: Add a domain model the Karni way (model + viewset, nothing else)\n"
|
|
73
|
+
"---\n"
|
|
74
|
+
"Add a new domain model: $ARGUMENTS\n"
|
|
75
|
+
"\n"
|
|
76
|
+
"1. Run `karni context` to see existing models and viewsets.\n"
|
|
77
|
+
"2. In the owning app's `models.py`, define the model inheriting\n"
|
|
78
|
+
" `karni.models.BaseModel` (`SoftDeleteModel` if it needs restore).\n"
|
|
79
|
+
" Declare `class APIMeta:` / `class AdminMeta:` only for fields that must be\n"
|
|
80
|
+
" hidden, read-only or write-only. Do NOT write an admin, serializer or router.\n"
|
|
81
|
+
"3. In the same app's `viewsets.py`:\n"
|
|
82
|
+
" `class XViewSet(BaseViewSet): model = X` (+ `search_fields` if searchable).\n"
|
|
83
|
+
" The auto-router registers it; admin, filters, schema are derived.\n"
|
|
84
|
+
"4. `make migrate && karni types`\n"
|
|
85
|
+
"5. Verify: `karni context` lists the model and viewset; GET /api/<plural>/ works.\n"
|
|
86
|
+
"\n"
|
|
87
|
+
"Total new code should be well under 20 lines. If it isn't, stop — you are\n"
|
|
88
|
+
"reimplementing something Karni provides.\n"
|
|
89
|
+
),
|
|
90
|
+
".claude/commands/new-page.md": (
|
|
91
|
+
"---\n"
|
|
92
|
+
"description: Add a frontend page composing @karni/ui (under 50 lines)\n"
|
|
93
|
+
"---\n"
|
|
94
|
+
"Add a page: $ARGUMENTS\n"
|
|
95
|
+
"\n"
|
|
96
|
+
"1. Run `karni context` for available components, hooks and resources.\n"
|
|
97
|
+
"2. Create one file in `frontend/src/pages/`. Compose @karni/ui — never\n"
|
|
98
|
+
" hand-roll tables, forms or fetching:\n"
|
|
99
|
+
' - list screen: `<Page title="..."><ResourceTable resource="..." /></Page>`\n'
|
|
100
|
+
' - edit/create: `<ResourceForm resource="..." id={...} />`\n'
|
|
101
|
+
' - read view: `<ResourceDetail resource="..." id={...} />`\n'
|
|
102
|
+
"3. Custom behaviour goes through props (`columns`, `fields`, `rowActions`,\n"
|
|
103
|
+
" slots, custom cell/field renderers) — extend, never fork a variant.\n"
|
|
104
|
+
"4. Register the route alongside the existing pages.\n"
|
|
105
|
+
"5. The file must stay under 50 lines. Data access only via @karni/ui hooks\n"
|
|
106
|
+
" (`useResourceList`, `useResourceItem`, `useResourceMutations`, generated\n"
|
|
107
|
+
" typed hooks from `karni types`).\n"
|
|
108
|
+
),
|
|
109
|
+
".claude/commands/add-module.md": (
|
|
110
|
+
"---\n"
|
|
111
|
+
"description: Install an optional Karni module and wire it into settings\n"
|
|
112
|
+
"---\n"
|
|
113
|
+
"Install Karni module: $ARGUMENTS\n"
|
|
114
|
+
"\n"
|
|
115
|
+
"1. Run `karni add <module>` — it adds the `karni-<module>` dependency to\n"
|
|
116
|
+
" pyproject.toml and wires `karni_<module>` into the INSTALLED_APPS block\n"
|
|
117
|
+
" marked `# karni:apps` in config/settings.py.\n"
|
|
118
|
+
"2. Rebuild/install: `docker compose build` (or `uv pip install -r\n"
|
|
119
|
+
" pyproject.toml` in a host venv), then `make migrate`.\n"
|
|
120
|
+
"3. Run `karni context` — the module must appear under MODULES.\n"
|
|
121
|
+
"4. Configure only settings the module documents; do not patch its internals.\n"
|
|
122
|
+
),
|
|
123
|
+
".claude/commands/new-module.md": (
|
|
124
|
+
"---\n"
|
|
125
|
+
"description: Create a new local Django app following Karni conventions\n"
|
|
126
|
+
"---\n"
|
|
127
|
+
"Create a local app: $ARGUMENTS\n"
|
|
128
|
+
"\n"
|
|
129
|
+
"1. Run `karni context` first — confirm the domain isn't already covered.\n"
|
|
130
|
+
"2. Create `<app>/` with only: `__init__.py`, `apps.py` (plain AppConfig),\n"
|
|
131
|
+
" `models.py` (BaseModel subclasses), `viewsets.py` (BaseViewSet subclasses).\n"
|
|
132
|
+
" No admin.py, serializers.py, urls.py, forms.py — Karni derives all of that.\n"
|
|
133
|
+
"3. Add the app to the `# karni:apps` block in config/settings.py.\n"
|
|
134
|
+
"4. `make migrate && karni types`, then `karni context` to verify.\n"
|
|
135
|
+
"5. Anything reusable across projects belongs in a Karni module\n"
|
|
136
|
+
" (karni_<name> package), not in this project — say so instead of building it.\n"
|
|
137
|
+
),
|
|
138
|
+
}
|