ki-manager 2.0.0__tar.gz
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.
- ki_manager-2.0.0/.gitignore +0 -0
- ki_manager-2.0.0/LICENSE +21 -0
- ki_manager-2.0.0/PKG-INFO +193 -0
- ki_manager-2.0.0/README.md +149 -0
- ki_manager-2.0.0/pyproject.toml +39 -0
- ki_manager-2.0.0/src/ki_manager/__init__.py +2 -0
- ki_manager-2.0.0/src/ki_manager/scripts/add_ki_to_config.py +57 -0
- ki_manager-2.0.0/src/ki_manager/scripts/analyze_module.py +103 -0
- ki_manager-2.0.0/src/ki_manager/scripts/audit_coverage.py +406 -0
- ki_manager-2.0.0/src/ki_manager/scripts/find_unmapped_files.py +81 -0
- ki_manager-2.0.0/src/ki_manager/scripts/generate_dir_index.py +140 -0
- ki_manager-2.0.0/src/ki_manager/scripts/ki_dependency_analyzer.py +233 -0
- ki_manager-2.0.0/src/ki_manager/scripts/ki_utils.py +279 -0
- ki_manager-2.0.0/src/ki_manager/scripts/knowledge_engine.py +232 -0
- ki_manager-2.0.0/src/ki_manager/scripts/sync_agents_md.py +77 -0
- ki_manager-2.0.0/src/ki_manager/server.py +632 -0
- ki_manager-2.0.0/src/ki_manager/tools/__init__.py +1 -0
- ki_manager-2.0.0/src/ki_manager/tools/scaffold.py +272 -0
|
Binary file
|
ki_manager-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bogdan Buliakov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ki-manager
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Knowledge Item (KI) management MCP server for AI-assisted development
|
|
5
|
+
Project-URL: Homepage, https://github.com/Laeryid/KI-base
|
|
6
|
+
Project-URL: Repository, https://github.com/Laeryid/KI-base
|
|
7
|
+
Project-URL: Issues, https://github.com/Laeryid/KI-base/issues
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2026 Bogdan Buliakov
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Keywords: ai,claude,cursor,documentation,knowledge,mcp,windsurf
|
|
31
|
+
Classifier: Development Status :: 4 - Beta
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
41
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
42
|
+
Requires-Python: >=3.8
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
|
|
45
|
+
# ki-manager — Knowledge Item MCP Server
|
|
46
|
+
|
|
47
|
+
> AI-powered knowledge management for software projects.
|
|
48
|
+
> Install once, use across all your projects.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## What is ki-manager?
|
|
53
|
+
|
|
54
|
+
**ki-manager** is an MCP (Model Context Protocol) server that turns any project into a **self-documenting codebase** for AI agents (Claude, Antigravity, Cursor, Windsurf, etc.).
|
|
55
|
+
|
|
56
|
+
It provides:
|
|
57
|
+
- **Knowledge Items (KI)** — structured Markdown snapshots of each module, stored in `.ki-base/knowledge/`
|
|
58
|
+
- **Coverage Audit** — measures how well your KI base covers your actual code
|
|
59
|
+
- **Dependency Analysis** — auto-updates "Related KIs" by analyzing imports
|
|
60
|
+
- **Git Snapshots** — versioned knowledge state (`git_checkpoint`, `git_restore`)
|
|
61
|
+
- **Scaffolding** — one command creates the complete `.ki-base/` structure in any project
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## Installation
|
|
66
|
+
|
|
67
|
+
### Option A: uvx (recommended — no install needed)
|
|
68
|
+
|
|
69
|
+
```json
|
|
70
|
+
{
|
|
71
|
+
"mcpServers": {
|
|
72
|
+
"ki-manager": {
|
|
73
|
+
"command": "uvx",
|
|
74
|
+
"args": ["ki-manager"]
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
> Requires [uv](https://docs.astral.sh/uv/) — install with: `curl -LsSf https://astral.sh/uv/install.sh | sh`
|
|
81
|
+
|
|
82
|
+
### Option B: Smithery (Claude Desktop / Cursor / Windsurf GUI)
|
|
83
|
+
|
|
84
|
+
Search for **ki-manager** in your IDE's MCP marketplace and click Install.
|
|
85
|
+
|
|
86
|
+
### Option C: pip
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pip install ki-manager
|
|
90
|
+
ki-manager # starts the MCP server
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Option D: Docker
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
docker run -i --rm -v "$(pwd):/workspace" ghcr.io/laeryid/ki-manager
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Quickstart
|
|
102
|
+
|
|
103
|
+
### 1. Add the MCP server to your IDE
|
|
104
|
+
|
|
105
|
+
Pick one of the options above and add it to your MCP config.
|
|
106
|
+
|
|
107
|
+
### 2. Initialize a project
|
|
108
|
+
|
|
109
|
+
In your IDE chat, call the `ki_init_project` tool:
|
|
110
|
+
|
|
111
|
+
```
|
|
112
|
+
ki_init_project(project_path="/absolute/path/to/your-project")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
This creates:
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
your-project/
|
|
119
|
+
└── .ki-base/
|
|
120
|
+
├── config.json ← machine-specific (auto-added to .gitignore)
|
|
121
|
+
├── ki_config.json ← project settings (commit to git)
|
|
122
|
+
├── doc_config.json ← file→KI map (commit to git)
|
|
123
|
+
├── AGENTS.md ← agent instructions (commit to git)
|
|
124
|
+
├── DIR_INDEX.md ← directory index (commit to git)
|
|
125
|
+
└── knowledge/
|
|
126
|
+
└── _OVERVIEW.ki.md ← starter Knowledge Item
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 3. Start documenting
|
|
130
|
+
|
|
131
|
+
Use the available tools or slash commands:
|
|
132
|
+
|
|
133
|
+
| Tool / Command | Action |
|
|
134
|
+
|----------------|--------|
|
|
135
|
+
| `audit_coverage` | Find documentation gaps |
|
|
136
|
+
| `generate_dir_index` | Build directory index |
|
|
137
|
+
| `sync_agents_md` | Sync KI table in AGENTS.md |
|
|
138
|
+
| `git_checkpoint` | Save knowledge snapshot to git |
|
|
139
|
+
| `/expand-knowledge` | Iteratively fill gaps (Antigravity) |
|
|
140
|
+
| `/sync-knowledge` | Full sync workflow (Antigravity) |
|
|
141
|
+
| `/create-adr` | Record architectural decision |
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## What Goes Into Git?
|
|
146
|
+
|
|
147
|
+
| Path | Git | Notes |
|
|
148
|
+
|------|:---:|-------|
|
|
149
|
+
| `.ki-base/knowledge/*.ki.md` | ✅ | Project knowledge |
|
|
150
|
+
| `.ki-base/doc_config.json` | ✅ | Module manifest |
|
|
151
|
+
| `.ki-base/ki_config.json` | ✅ | Project settings |
|
|
152
|
+
| `.ki-base/AGENTS.md` | ✅ | Agent instructions |
|
|
153
|
+
| `.ki-base/DIR_INDEX.md` | ✅ | Directory index |
|
|
154
|
+
| `.ki-base/config.json` | ❌ | Machine-specific paths |
|
|
155
|
+
| `.ki-base/doc_state.json` | ❌ | Hash cache |
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Security
|
|
160
|
+
|
|
161
|
+
The MCP server operates in a **sandbox**:
|
|
162
|
+
- All file access is restricted to the `.ki-base/` directory
|
|
163
|
+
- Executable files (`.py`, `.exe`, `.sh`, etc.) cannot be modified via MCP
|
|
164
|
+
- Critical config files are protected from direct overwrite
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## Project Structure (this repo)
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
ki-manager/
|
|
172
|
+
├── pyproject.toml ← pip / uvx package config
|
|
173
|
+
├── smithery.yaml ← Smithery MCP marketplace config
|
|
174
|
+
├── src/ki_manager/
|
|
175
|
+
│ ├── server.py ← MCP server entry point
|
|
176
|
+
│ ├── tools/
|
|
177
|
+
│ │ └── scaffold.py ← ki_init_project implementation
|
|
178
|
+
│ └── scripts/ ← bundled analysis scripts
|
|
179
|
+
│ ├── ki_utils.py ← shared utilities
|
|
180
|
+
│ ├── audit_coverage.py
|
|
181
|
+
│ ├── sync_agents_md.py
|
|
182
|
+
│ ├── generate_dir_index.py
|
|
183
|
+
│ ├── ki_dependency_analyzer.py
|
|
184
|
+
│ └── ...
|
|
185
|
+
├── knowledge/ ← KI documentation of this repo itself
|
|
186
|
+
└── decisions/ ← Architecture Decision Records
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT — free to use, copy, and adapt.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# ki-manager — Knowledge Item MCP Server
|
|
2
|
+
|
|
3
|
+
> AI-powered knowledge management for software projects.
|
|
4
|
+
> Install once, use across all your projects.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## What is ki-manager?
|
|
9
|
+
|
|
10
|
+
**ki-manager** is an MCP (Model Context Protocol) server that turns any project into a **self-documenting codebase** for AI agents (Claude, Antigravity, Cursor, Windsurf, etc.).
|
|
11
|
+
|
|
12
|
+
It provides:
|
|
13
|
+
- **Knowledge Items (KI)** — structured Markdown snapshots of each module, stored in `.ki-base/knowledge/`
|
|
14
|
+
- **Coverage Audit** — measures how well your KI base covers your actual code
|
|
15
|
+
- **Dependency Analysis** — auto-updates "Related KIs" by analyzing imports
|
|
16
|
+
- **Git Snapshots** — versioned knowledge state (`git_checkpoint`, `git_restore`)
|
|
17
|
+
- **Scaffolding** — one command creates the complete `.ki-base/` structure in any project
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
### Option A: uvx (recommended — no install needed)
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"mcpServers": {
|
|
28
|
+
"ki-manager": {
|
|
29
|
+
"command": "uvx",
|
|
30
|
+
"args": ["ki-manager"]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
> Requires [uv](https://docs.astral.sh/uv/) — install with: `curl -LsSf https://astral.sh/uv/install.sh | sh`
|
|
37
|
+
|
|
38
|
+
### Option B: Smithery (Claude Desktop / Cursor / Windsurf GUI)
|
|
39
|
+
|
|
40
|
+
Search for **ki-manager** in your IDE's MCP marketplace and click Install.
|
|
41
|
+
|
|
42
|
+
### Option C: pip
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install ki-manager
|
|
46
|
+
ki-manager # starts the MCP server
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Option D: Docker
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
docker run -i --rm -v "$(pwd):/workspace" ghcr.io/laeryid/ki-manager
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Quickstart
|
|
58
|
+
|
|
59
|
+
### 1. Add the MCP server to your IDE
|
|
60
|
+
|
|
61
|
+
Pick one of the options above and add it to your MCP config.
|
|
62
|
+
|
|
63
|
+
### 2. Initialize a project
|
|
64
|
+
|
|
65
|
+
In your IDE chat, call the `ki_init_project` tool:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
ki_init_project(project_path="/absolute/path/to/your-project")
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
This creates:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
your-project/
|
|
75
|
+
└── .ki-base/
|
|
76
|
+
├── config.json ← machine-specific (auto-added to .gitignore)
|
|
77
|
+
├── ki_config.json ← project settings (commit to git)
|
|
78
|
+
├── doc_config.json ← file→KI map (commit to git)
|
|
79
|
+
├── AGENTS.md ← agent instructions (commit to git)
|
|
80
|
+
├── DIR_INDEX.md ← directory index (commit to git)
|
|
81
|
+
└── knowledge/
|
|
82
|
+
└── _OVERVIEW.ki.md ← starter Knowledge Item
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 3. Start documenting
|
|
86
|
+
|
|
87
|
+
Use the available tools or slash commands:
|
|
88
|
+
|
|
89
|
+
| Tool / Command | Action |
|
|
90
|
+
|----------------|--------|
|
|
91
|
+
| `audit_coverage` | Find documentation gaps |
|
|
92
|
+
| `generate_dir_index` | Build directory index |
|
|
93
|
+
| `sync_agents_md` | Sync KI table in AGENTS.md |
|
|
94
|
+
| `git_checkpoint` | Save knowledge snapshot to git |
|
|
95
|
+
| `/expand-knowledge` | Iteratively fill gaps (Antigravity) |
|
|
96
|
+
| `/sync-knowledge` | Full sync workflow (Antigravity) |
|
|
97
|
+
| `/create-adr` | Record architectural decision |
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## What Goes Into Git?
|
|
102
|
+
|
|
103
|
+
| Path | Git | Notes |
|
|
104
|
+
|------|:---:|-------|
|
|
105
|
+
| `.ki-base/knowledge/*.ki.md` | ✅ | Project knowledge |
|
|
106
|
+
| `.ki-base/doc_config.json` | ✅ | Module manifest |
|
|
107
|
+
| `.ki-base/ki_config.json` | ✅ | Project settings |
|
|
108
|
+
| `.ki-base/AGENTS.md` | ✅ | Agent instructions |
|
|
109
|
+
| `.ki-base/DIR_INDEX.md` | ✅ | Directory index |
|
|
110
|
+
| `.ki-base/config.json` | ❌ | Machine-specific paths |
|
|
111
|
+
| `.ki-base/doc_state.json` | ❌ | Hash cache |
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
## Security
|
|
116
|
+
|
|
117
|
+
The MCP server operates in a **sandbox**:
|
|
118
|
+
- All file access is restricted to the `.ki-base/` directory
|
|
119
|
+
- Executable files (`.py`, `.exe`, `.sh`, etc.) cannot be modified via MCP
|
|
120
|
+
- Critical config files are protected from direct overwrite
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## Project Structure (this repo)
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
ki-manager/
|
|
128
|
+
├── pyproject.toml ← pip / uvx package config
|
|
129
|
+
├── smithery.yaml ← Smithery MCP marketplace config
|
|
130
|
+
├── src/ki_manager/
|
|
131
|
+
│ ├── server.py ← MCP server entry point
|
|
132
|
+
│ ├── tools/
|
|
133
|
+
│ │ └── scaffold.py ← ki_init_project implementation
|
|
134
|
+
│ └── scripts/ ← bundled analysis scripts
|
|
135
|
+
│ ├── ki_utils.py ← shared utilities
|
|
136
|
+
│ ├── audit_coverage.py
|
|
137
|
+
│ ├── sync_agents_md.py
|
|
138
|
+
│ ├── generate_dir_index.py
|
|
139
|
+
│ ├── ki_dependency_analyzer.py
|
|
140
|
+
│ └── ...
|
|
141
|
+
├── knowledge/ ← KI documentation of this repo itself
|
|
142
|
+
└── decisions/ ← Architecture Decision Records
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT — free to use, copy, and adapt.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ki-manager"
|
|
7
|
+
version = "2.0.0"
|
|
8
|
+
description = "Knowledge Item (KI) management MCP server for AI-assisted development"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
keywords = ["mcp", "knowledge", "ai", "documentation", "cursor", "windsurf", "claude"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 4 - Beta",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.8",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Topic :: Software Development :: Documentation",
|
|
24
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.scripts]
|
|
28
|
+
ki-manager = "ki_manager.server:main"
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/Laeryid/KI-base"
|
|
32
|
+
Repository = "https://github.com/Laeryid/KI-base"
|
|
33
|
+
Issues = "https://github.com/Laeryid/KI-base/issues"
|
|
34
|
+
|
|
35
|
+
[tool.hatch.build.targets.wheel]
|
|
36
|
+
packages = ["src/ki_manager"]
|
|
37
|
+
|
|
38
|
+
[tool.hatch.build.targets.sdist]
|
|
39
|
+
include = ["src/ki_manager/**", "README.md", "LICENSE"]
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""
|
|
2
|
+
add_ki_to_config.py
|
|
3
|
+
|
|
4
|
+
CLI helper: registers a new Knowledge Item in doc_config.json.
|
|
5
|
+
|
|
6
|
+
Usage:
|
|
7
|
+
python add_ki_to_config.py <ki_name> <description> <covers_json> <depends_on_json>
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
python add_ki_to_config.py KI_utils.md "Utility helpers" '["Utilities"]' '["src/utils/"]'
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import sys
|
|
14
|
+
import os
|
|
15
|
+
import json
|
|
16
|
+
|
|
17
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
18
|
+
import ki_utils
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def add_ki(ki_name: str, description: str, covers: list, depends_on: list):
|
|
22
|
+
config = ki_utils.get_doc_config()
|
|
23
|
+
if not config:
|
|
24
|
+
print("[!] doc_config.json not found or empty")
|
|
25
|
+
return
|
|
26
|
+
|
|
27
|
+
if "knowledge_items" not in config:
|
|
28
|
+
config["knowledge_items"] = {}
|
|
29
|
+
|
|
30
|
+
config["knowledge_items"][ki_name] = {
|
|
31
|
+
"description": description,
|
|
32
|
+
"covers": covers,
|
|
33
|
+
"depends_on": depends_on,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
with open(ki_utils.get_doc_config_path(), "w", encoding="utf-8") as f:
|
|
37
|
+
json.dump(config, f, indent=4, ensure_ascii=False)
|
|
38
|
+
|
|
39
|
+
print(f"[+] KI registered in doc_config.json: {ki_name}")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
if len(sys.argv) < 5:
|
|
44
|
+
print("Usage: python add_ki_to_config.py <ki_name> <description> "
|
|
45
|
+
"<covers_list_json> <depends_on_list_json>")
|
|
46
|
+
sys.exit(1)
|
|
47
|
+
|
|
48
|
+
ki_name = sys.argv[1]
|
|
49
|
+
description = sys.argv[2]
|
|
50
|
+
try:
|
|
51
|
+
covers = json.loads(sys.argv[3])
|
|
52
|
+
depends_on = json.loads(sys.argv[4])
|
|
53
|
+
except json.JSONDecodeError:
|
|
54
|
+
print("[!] Error: covers and depends_on must be valid JSON arrays")
|
|
55
|
+
sys.exit(1)
|
|
56
|
+
|
|
57
|
+
add_ki(ki_name, description, covers, depends_on)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
import argparse
|
|
4
|
+
import io
|
|
5
|
+
from typing import Dict, List, Optional
|
|
6
|
+
|
|
7
|
+
# Добавляем путь к скриптам, чтобы импортировать ki_utils
|
|
8
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
9
|
+
import ki_utils
|
|
10
|
+
|
|
11
|
+
def format_size(size_bytes: int) -> str:
|
|
12
|
+
if size_bytes < 1024:
|
|
13
|
+
return f"{size_bytes} B"
|
|
14
|
+
elif size_bytes < 1024 * 1024:
|
|
15
|
+
return f"{size_bytes / 1024:.2f} KB"
|
|
16
|
+
else:
|
|
17
|
+
return f"{size_bytes / (1024 * 1024):.2f} MB"
|
|
18
|
+
|
|
19
|
+
def get_tracked_files(config: Dict) -> Dict[str, str]:
|
|
20
|
+
"""Возвращает мапу {путь_к_файлу: имя_KI}"""
|
|
21
|
+
tracked = {}
|
|
22
|
+
ki_items = config.get("knowledge_items", {})
|
|
23
|
+
for ki_name, ki_data in ki_items.items():
|
|
24
|
+
for file_path in ki_data.get("depends_on", []):
|
|
25
|
+
tracked[os.path.normpath(file_path)] = ki_name
|
|
26
|
+
return tracked
|
|
27
|
+
|
|
28
|
+
def analyze_path(target_path: str, recursive: bool = False):
|
|
29
|
+
project_root = ki_utils.get_project_root()
|
|
30
|
+
config = ki_utils.get_doc_config()
|
|
31
|
+
tracked_map = get_tracked_files(config)
|
|
32
|
+
|
|
33
|
+
# Резолвим абсолютный путь
|
|
34
|
+
abs_target = os.path.normpath(os.path.join(project_root, target_path))
|
|
35
|
+
|
|
36
|
+
if not os.path.exists(abs_target):
|
|
37
|
+
print(f"Error: Path {target_path} not found.")
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
print(f"### Analysis for: `{target_path}`")
|
|
41
|
+
print("| Status | File / Directory | Size | KI Link | Density |")
|
|
42
|
+
print("|:---:|:---|:---|:---|:---|")
|
|
43
|
+
|
|
44
|
+
items = []
|
|
45
|
+
if os.path.isfile(abs_target):
|
|
46
|
+
items = [abs_target]
|
|
47
|
+
elif os.path.isdir(abs_target):
|
|
48
|
+
if recursive:
|
|
49
|
+
for root, dirs, files in os.walk(abs_target):
|
|
50
|
+
if any(part in root.split(os.sep) for part in ["__pycache__", ".git", "node_modules", "venv", ".venv"]):
|
|
51
|
+
continue
|
|
52
|
+
for name in files:
|
|
53
|
+
items.append(os.path.join(root, name))
|
|
54
|
+
else:
|
|
55
|
+
for name in os.listdir(abs_target):
|
|
56
|
+
items.append(os.path.join(abs_target, name))
|
|
57
|
+
|
|
58
|
+
for item_path in sorted(items):
|
|
59
|
+
try:
|
|
60
|
+
rel_path = os.path.relpath(item_path, project_root)
|
|
61
|
+
is_dir = os.path.isdir(item_path)
|
|
62
|
+
size = 0
|
|
63
|
+
if is_dir:
|
|
64
|
+
for root, _, files in os.walk(item_path):
|
|
65
|
+
for f in files:
|
|
66
|
+
fp = os.path.join(root, f)
|
|
67
|
+
if os.path.exists(fp):
|
|
68
|
+
size += os.path.getsize(fp)
|
|
69
|
+
else:
|
|
70
|
+
size = os.path.getsize(item_path)
|
|
71
|
+
|
|
72
|
+
ki_name = tracked_map.get(os.path.normpath(rel_path), "")
|
|
73
|
+
status = "✅" if ki_name else "❌"
|
|
74
|
+
|
|
75
|
+
density = "-"
|
|
76
|
+
if ki_name:
|
|
77
|
+
ki_path = os.path.join(ki_utils.get_knowledge_root(), "knowledge", ki_name)
|
|
78
|
+
if os.path.exists(ki_path):
|
|
79
|
+
ki_size = os.path.getsize(ki_path)
|
|
80
|
+
if ki_size > 0:
|
|
81
|
+
density_val = size / ki_size
|
|
82
|
+
density = f"{density_val:.1f} B_code/B_doc"
|
|
83
|
+
|
|
84
|
+
name_display = f"`{os.path.basename(item_path)}`" + ("/" if is_dir else "")
|
|
85
|
+
print(f"| {status} | {name_display} | {format_size(size)} | {ki_name} | {density} |")
|
|
86
|
+
except:
|
|
87
|
+
continue
|
|
88
|
+
|
|
89
|
+
def main():
|
|
90
|
+
# Исправление кодировки для Windows при прямом запуске
|
|
91
|
+
if sys.platform == "win32":
|
|
92
|
+
import io
|
|
93
|
+
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")
|
|
94
|
+
|
|
95
|
+
parser = argparse.ArgumentParser(description="Analyze module statistics with knowledge context.")
|
|
96
|
+
parser.add_argument("path", help="Path relative to project root")
|
|
97
|
+
parser.add_argument("--recursive", action="store_true", help="Recursive analysis")
|
|
98
|
+
|
|
99
|
+
args = parser.parse_args()
|
|
100
|
+
analyze_path(args.path, args.recursive)
|
|
101
|
+
|
|
102
|
+
if __name__ == "__main__":
|
|
103
|
+
main()
|