knowcode 0.1.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.
Files changed (75) hide show
  1. knowcode-0.1.0/.github/workflows/publish.yml +107 -0
  2. knowcode-0.1.0/.gitignore +170 -0
  3. knowcode-0.1.0/.python-version +1 -0
  4. knowcode-0.1.0/PKG-INFO +175 -0
  5. knowcode-0.1.0/README.md +156 -0
  6. knowcode-0.1.0/npm/knowcode/bin/know.js +41 -0
  7. knowcode-0.1.0/npm/knowcode/package.json +23 -0
  8. knowcode-0.1.0/pyproject.toml +30 -0
  9. knowcode-0.1.0/src/runtime/__init__.py +4 -0
  10. knowcode-0.1.0/src/runtime/artifact/__init__.py +1 -0
  11. knowcode-0.1.0/src/runtime/artifact/builder.py +179 -0
  12. knowcode-0.1.0/src/runtime/cli/__init__.py +1 -0
  13. knowcode-0.1.0/src/runtime/cli/animation.py +278 -0
  14. knowcode-0.1.0/src/runtime/cli/app.py +309 -0
  15. knowcode-0.1.0/src/runtime/cli/auth.py +171 -0
  16. knowcode-0.1.0/src/runtime/cli/telemetry.py +91 -0
  17. knowcode-0.1.0/src/runtime/exceptions/__init__.py +1 -0
  18. knowcode-0.1.0/src/runtime/exceptions/errors.py +99 -0
  19. knowcode-0.1.0/src/runtime/repository/__init__.py +13 -0
  20. knowcode-0.1.0/src/runtime/repository/discovery.py +64 -0
  21. knowcode-0.1.0/src/runtime/repository/models.py +103 -0
  22. knowcode-0.1.0/src/runtime/repository/paths.py +50 -0
  23. knowcode-0.1.0/src/runtime/repository/validator.py +100 -0
  24. knowcode-0.1.0/src/runtime/services/__init__.py +1 -0
  25. knowcode-0.1.0/src/runtime/services/ingest_service.py +105 -0
  26. knowcode-0.1.0/src/runtime/services/init_service.py +45 -0
  27. knowcode-0.1.0/src/runtime/services/semantic_sync_service.py +55 -0
  28. knowcode-0.1.0/src/runtime/services/status_service.py +40 -0
  29. knowcode-0.1.0/src/runtime/services/sync_service.py +57 -0
  30. knowcode-0.1.0/src/runtime/templates/KNOWCODE_LOADER.md.j2 +24 -0
  31. knowcode-0.1.0/src/runtime/templates/README_KNOWLEDGE.md.j2 +12 -0
  32. knowcode-0.1.0/src/runtime/templates/README_STRUCTURE.md.j2 +19 -0
  33. knowcode-0.1.0/src/runtime/templates/__init__.py +1 -0
  34. knowcode-0.1.0/src/runtime/templates/active_context.md.j2 +3 -0
  35. knowcode-0.1.0/src/runtime/templates/ingest_legacy.md.j2 +15 -0
  36. knowcode-0.1.0/src/runtime/templates/raw_readme.md.j2 +9 -0
  37. knowcode-0.1.0/src/runtime/templates/sync_reconciliation.md.j2 +17 -0
  38. knowcode-0.1.0/src/runtime/templates/synthesize_knowledge.md.j2 +32 -0
  39. knowcode-0.1.0/src/runtime/templates/track_intent.md.j2 +14 -0
  40. knowcode-0.1.0/src/structural_engine/__init__.py +3 -0
  41. knowcode-0.1.0/src/structural_engine/diff/__init__.py +1 -0
  42. knowcode-0.1.0/src/structural_engine/diff/generator.py +92 -0
  43. knowcode-0.1.0/src/structural_engine/diff/models.py +48 -0
  44. knowcode-0.1.0/src/structural_engine/engine.py +192 -0
  45. knowcode-0.1.0/src/structural_engine/logs/__init__.py +1 -0
  46. knowcode-0.1.0/src/structural_engine/logs/generator.py +33 -0
  47. knowcode-0.1.0/src/structural_engine/parser/__init__.py +7 -0
  48. knowcode-0.1.0/src/structural_engine/parser/discovery.py +165 -0
  49. knowcode-0.1.0/src/structural_engine/parser/extractors/base.py +44 -0
  50. knowcode-0.1.0/src/structural_engine/parser/languages/javascript/adapter.py +149 -0
  51. knowcode-0.1.0/src/structural_engine/parser/languages/python/adapter.py +174 -0
  52. knowcode-0.1.0/src/structural_engine/parser/languages/typescript/adapter.py +165 -0
  53. knowcode-0.1.0/src/structural_engine/parser/models.py +186 -0
  54. knowcode-0.1.0/src/structural_engine/parser/parser.py +160 -0
  55. knowcode-0.1.0/src/structural_engine/parser/resolvers/calls.py +105 -0
  56. knowcode-0.1.0/src/structural_engine/parser/tree_sitter/registry.py +61 -0
  57. knowcode-0.1.0/src/structural_engine/reports/__init__.py +1 -0
  58. knowcode-0.1.0/src/structural_engine/reports/generator.py +77 -0
  59. knowcode-0.1.0/src/structural_engine/results.py +54 -0
  60. knowcode-0.1.0/src/structural_engine/revisions/__init__.py +1 -0
  61. knowcode-0.1.0/src/structural_engine/revisions/tracker.py +32 -0
  62. knowcode-0.1.0/src/structural_engine/snapshot/__init__.py +1 -0
  63. knowcode-0.1.0/src/structural_engine/snapshot/generator.py +58 -0
  64. knowcode-0.1.0/src/structural_engine/snapshot/loader.py +59 -0
  65. knowcode-0.1.0/src/structural_engine/state/__init__.py +1 -0
  66. knowcode-0.1.0/src/structural_engine/state/manager.py +169 -0
  67. knowcode-0.1.0/src/structural_engine/state/models.py +34 -0
  68. knowcode-0.1.0/tests/test_phase1.py +70 -0
  69. knowcode-0.1.0/tests/test_phase2a.py +184 -0
  70. knowcode-0.1.0/tests/test_phase2b.py +145 -0
  71. knowcode-0.1.0/tests/test_phase3.py +66 -0
  72. knowcode-0.1.0/tests/test_phase4.py +73 -0
  73. knowcode-0.1.0/tests/test_phase5.py +108 -0
  74. knowcode-0.1.0/tests/test_phase6.py +77 -0
  75. knowcode-0.1.0/uv.lock +417 -0
@@ -0,0 +1,107 @@
1
+ name: Publish KnowCode
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ pypi:
10
+ name: Publish to PyPI
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - name: Set up Python
15
+ uses: actions/setup-python@v5
16
+ with:
17
+ python-version: "3.13"
18
+ - name: Install build dependencies
19
+ run: python -m pip install --upgrade pip build twine
20
+ - name: Build package
21
+ run: python -m build
22
+ - name: Publish to PyPI
23
+ env:
24
+ TWINE_USERNAME: __token__
25
+ TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
26
+ run: twine upload dist/*
27
+
28
+ build-binaries:
29
+ name: Build & Publish NPM Binaries
30
+ strategy:
31
+ matrix:
32
+ include:
33
+ - os: windows-latest
34
+ pkg_name: knowcode-win32-x64
35
+ npm_os: win32
36
+ npm_cpu: x64
37
+ artifact_name: know.exe
38
+ - os: macos-latest
39
+ pkg_name: knowcode-darwin-arm64
40
+ npm_os: darwin
41
+ npm_cpu: arm64
42
+ artifact_name: know
43
+ - os: ubuntu-latest
44
+ pkg_name: knowcode-linux-x64
45
+ npm_os: linux
46
+ npm_cpu: x64
47
+ artifact_name: know
48
+ runs-on: ${{ matrix.os }}
49
+ steps:
50
+ - uses: actions/checkout@v4
51
+ - name: Set up Python
52
+ uses: actions/setup-python@v5
53
+ with:
54
+ python-version: "3.13"
55
+ - name: Set up Node.js
56
+ uses: actions/setup-node@v4
57
+ with:
58
+ node-version: "20.x"
59
+ registry-url: "https://registry.npmjs.org"
60
+ - name: Install CLI and PyInstaller
61
+ run: |
62
+ pip install .
63
+ pip install pyinstaller
64
+ - name: Build executable
65
+ run: pyinstaller --name know --onefile src/runtime/cli/app.py
66
+ - name: Prepare NPM package
67
+ shell: bash
68
+ run: |
69
+ mkdir -p npm-binary-pkg/bin
70
+ mv dist/${{ matrix.artifact_name }} npm-binary-pkg/bin/
71
+ cat <<EOF > npm-binary-pkg/package.json
72
+ {
73
+ "name": "${{ matrix.pkg_name }}",
74
+ "version": "0.1.0",
75
+ "description": "Platform specific binary for KnowCode",
76
+ "os": [
77
+ "${{ matrix.npm_os }}"
78
+ ],
79
+ "cpu": [
80
+ "${{ matrix.npm_cpu }}"
81
+ ],
82
+ "author": "KnowCode Team",
83
+ "license": "MIT"
84
+ }
85
+ EOF
86
+ - name: Publish to NPM
87
+ working-directory: npm-binary-pkg
88
+ env:
89
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
90
+ run: npm publish --access public
91
+
92
+ publish-npm-wrapper:
93
+ name: Publish NPM Wrapper
94
+ needs: build-binaries
95
+ runs-on: ubuntu-latest
96
+ steps:
97
+ - uses: actions/checkout@v4
98
+ - name: Set up Node.js
99
+ uses: actions/setup-node@v4
100
+ with:
101
+ node-version: "20.x"
102
+ registry-url: "https://registry.npmjs.org"
103
+ - name: Publish Wrapper
104
+ working-directory: npm/knowcode
105
+ env:
106
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
107
+ run: npm publish --access public
@@ -0,0 +1,170 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ .idea/
161
+
162
+ # VS Code
163
+ .vscode/
164
+
165
+ # KnowCode Specific files
166
+ knowcode.log
167
+ .knowcode/
168
+ .agent/
169
+ knowiki.log
170
+ knowcode.md
@@ -0,0 +1 @@
1
+ 3.13
@@ -0,0 +1,175 @@
1
+ Metadata-Version: 2.4
2
+ Name: knowcode
3
+ Version: 0.1.0
4
+ Summary: Structural cognition engine for code repositories
5
+ Requires-Python: >=3.13
6
+ Requires-Dist: jinja2>=3.1.0
7
+ Requires-Dist: platformdirs>=4.0.0
8
+ Requires-Dist: pydantic>=2.11.0
9
+ Requires-Dist: questionary>=2.0.0
10
+ Requires-Dist: rich>=14.0.0
11
+ Requires-Dist: ruamel-yaml>=0.18.0
12
+ Requires-Dist: structlog>=25.0.0
13
+ Requires-Dist: tree-sitter-javascript>=0.25.0
14
+ Requires-Dist: tree-sitter-python>=0.25.0
15
+ Requires-Dist: tree-sitter-typescript>=0.23.2
16
+ Requires-Dist: tree-sitter>=0.25.2
17
+ Requires-Dist: typer>=0.15.0
18
+ Description-Content-Type: text/markdown
19
+
20
+ # KnowCode
21
+
22
+ [![Python Version](https://img.shields.io/badge/python-3.13%2B-blue.svg)](https://www.python.org/)
23
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](#license)
24
+
25
+ **KnowCode** is a structural cognition engine designed specifically for Agentic IDEs (like Cursor, Gemini, and Copilot). It bridges the gap between **physical repository code**, **deterministic structural snapshots**, and **semantic architectural knowledge**, allowing AI agents and human developers to seamlessly inspect, track, and maintain codebase architectures.
26
+
27
+ ---
28
+
29
+ ## Table of Contents
30
+
31
+ - [Overview](#overview)
32
+ - [Key Features](#key-features)
33
+ - [Installation](#installation)
34
+ - [Usage: The Agentic Workflow](#usage-the-agentic-workflow)
35
+ - [Ecosystem Layout](#ecosystem-layout)
36
+ - [CLI Reference & Manual Execution](#cli-reference--manual-execution)
37
+ - [License](#license)
38
+
39
+ ---
40
+
41
+ ## Overview
42
+
43
+ KnowCode completely flips the traditional documentation model. Instead of forcing developers to write specs *before* they code, KnowCode uses an AI agent to track your intent during a development session. When you sync your physical code changes, the AI agent is automatically invoked to synthesize your intent against the deterministic reality of the codebase, ensuring your architectural knowledge naturally accumulates as a byproduct of development.
44
+
45
+ KnowCode partitions codebase understanding into three clean domains:
46
+ 1. **Physical Reality:** The actual source files inside the repository.
47
+ 2. **Structural Truth:** Deterministic representation of files, components, and code symbols parsed via abstract syntax trees (ASTs).
48
+ 3. **Semantic Knowledge:** Permanent architectural rules, decisions, and constraints synthesized by your AI agent.
49
+
50
+ ---
51
+
52
+ ## Key Features
53
+
54
+ - **Native Agent Integration:** Built-in slash commands (`/knowcode`, `/know-sync`) that plug directly into Agentic IDEs without configuration.
55
+ - **Multi-Language AST Parsing**: Built on top of `tree-sitter`, with out-of-the-box support for **Python**, **JavaScript**, and **TypeScript**.
56
+ - **Deterministic State & Revision Tracking**: Tracks codebase changes across sequential revisions (`S-001`, `S-002`, etc.).
57
+ - **Diff & Report Generation**: Automatically computes additions, deletions, line-boundary modifications, and maps changes to their top-level affected components.
58
+
59
+ ---
60
+
61
+ ## Installation
62
+
63
+ ### Prerequisites
64
+ - [Python 3.13+](https://www.python.org/)
65
+ - [uv Package Manager](https://github.com/astral-sh/uv)
66
+
67
+ ### Installation
68
+
69
+ You can install Knowcode directly via pip or npm.
70
+
71
+ **Using pip:**
72
+ ```bash
73
+ pip install knowcode
74
+ ```
75
+
76
+ **Using npm:**
77
+ ```bash
78
+ npm install -g knowcode
79
+ ```
80
+
81
+ #### Development Setup
82
+
83
+ If you want to contribute or modify the code, clone the repository and install it in editable mode:
84
+
85
+ ```bash
86
+ git clone https://github.com/knowiki/knowcode.git
87
+ cd knowcode
88
+ uv sync
89
+ uv pip install -e .
90
+ ```
91
+
92
+ ---
93
+
94
+ ## Usage: The Agentic Workflow
95
+
96
+ KnowCode is designed to be driven by you and your AI agent in tandem.
97
+
98
+ ### 1. Initialize the Repository
99
+ Run the initialization command in your target repository terminal:
100
+ ```bash
101
+ know .
102
+ ```
103
+ This scaffolds the `.agent/` and `.knowcode/` directories, computes your first AST snapshot, and drops `knowcode.md` at your root.
104
+
105
+ *Note: To prevent polluting your repository, `know .` automatically adds `.knowcode/`, `.agent/`, and `knowcode.md` to your `.gitignore`. If you want to share your synthesized semantic knowledge with your team, you can selectively un-ignore `.knowcode/knowledge/`.*
106
+
107
+ ### 2. Activate the Agent
108
+ In your AI chat (Cursor, Copilot, Gemini), simply type:
109
+ ```text
110
+ /knowcode
111
+ ```
112
+ The agent will instantly read `knowcode.md`, lock into the KnowCode governance rules, and begin silently tracking your intent in `.agent/memory/active_context.md` while you code.
113
+
114
+ ### 3. Sync & Synthesize
115
+ After you finish a coding session or fix a bug, instruct the agent to synchronize by typing:
116
+ ```text
117
+ /know-sync
118
+ ```
119
+ The agent will orchestrate the entire lifecycle:
120
+ 1. Run `know sync` to compute structural AST diffs.
121
+ 2. Read the generated structural report (`R-XXX.md`).
122
+ 3. Reconcile the structural reality against your tracked intent.
123
+ 4. Distribute the extracted knowledge into the 5 semantic buckets (`architecture`, `decisions`, etc.).
124
+ 5. Run `know sync-semantic` to commit the knowledge and bump the revision.
125
+
126
+ ---
127
+
128
+ ## Ecosystem Layout
129
+
130
+ When KnowCode is initialized in a repository via `know .`, it generates a governed agent architecture:
131
+
132
+ ```text
133
+ /
134
+ ├── knowcode.md # The Agent Ignition Switch (Read by the AI)
135
+ ├── .agent/ # The Semantic Governance & Memory Layer
136
+ │ ├── memory/
137
+ │ │ ├── active_context.md # The AI's short-term intent tracking buffer
138
+ │ │ └── previous_context.md
139
+ │ ├── skills/
140
+ │ │ ├── track_intent.md # Background skill for tracking architectural intent
141
+ │ │ └── synthesize_knowledge.md
142
+ │ └── workflows/
143
+ │ ├── sync_reconciliation.md # The /know-sync workflow
144
+ │ └── ingest_legacy.md # The /know-ingest workflow
145
+
146
+ └── .knowcode/ # The Deterministic Knowledge Artifact
147
+ ├── state.yaml # Authoritative state registry (managed by the Engine)
148
+ ├── structure/ # Deterministic AST snapshots (e.g. S-001.json)
149
+ ├── reports/ # Change and diff analysis reports (e.g. R-001.md)
150
+ └── knowledge/ # Permanent semantic knowledge (AI synthesized)
151
+ ├── architecture/
152
+ ├── components/
153
+ ├── constraints/
154
+ ├── conventions/
155
+ ├── decisions/
156
+ └── raw/ # Inbox for legacy or unstructured documentation
157
+ ```
158
+
159
+ ---
160
+
161
+ ## CLI Reference & Manual Execution
162
+
163
+ While the Agentic Workflow relies on slash commands to orchestrate operations, developers can bypass the AI entirely and execute any step manually using the `know` CLI. This is useful for CI/CD pipelines, programmatic integration, or direct inspection.
164
+
165
+ - `know .`: Initializes Knowcode in the current directory.
166
+ - `know status`: Displays current structural and semantic revisions.
167
+ - `know sync`: Computes AST diffs, generates a report, and rolls over the memory buffer.
168
+ - `know sync-semantic`: Bumps the semantic revision after the AI (or a human) finishes synthesis.
169
+ - `know ingest-semantic .`: Wipes the raw documentation inbox and bumps the revision.
170
+
171
+ ---
172
+
173
+ ## License
174
+
175
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,156 @@
1
+ # KnowCode
2
+
3
+ [![Python Version](https://img.shields.io/badge/python-3.13%2B-blue.svg)](https://www.python.org/)
4
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](#license)
5
+
6
+ **KnowCode** is a structural cognition engine designed specifically for Agentic IDEs (like Cursor, Gemini, and Copilot). It bridges the gap between **physical repository code**, **deterministic structural snapshots**, and **semantic architectural knowledge**, allowing AI agents and human developers to seamlessly inspect, track, and maintain codebase architectures.
7
+
8
+ ---
9
+
10
+ ## Table of Contents
11
+
12
+ - [Overview](#overview)
13
+ - [Key Features](#key-features)
14
+ - [Installation](#installation)
15
+ - [Usage: The Agentic Workflow](#usage-the-agentic-workflow)
16
+ - [Ecosystem Layout](#ecosystem-layout)
17
+ - [CLI Reference & Manual Execution](#cli-reference--manual-execution)
18
+ - [License](#license)
19
+
20
+ ---
21
+
22
+ ## Overview
23
+
24
+ KnowCode completely flips the traditional documentation model. Instead of forcing developers to write specs *before* they code, KnowCode uses an AI agent to track your intent during a development session. When you sync your physical code changes, the AI agent is automatically invoked to synthesize your intent against the deterministic reality of the codebase, ensuring your architectural knowledge naturally accumulates as a byproduct of development.
25
+
26
+ KnowCode partitions codebase understanding into three clean domains:
27
+ 1. **Physical Reality:** The actual source files inside the repository.
28
+ 2. **Structural Truth:** Deterministic representation of files, components, and code symbols parsed via abstract syntax trees (ASTs).
29
+ 3. **Semantic Knowledge:** Permanent architectural rules, decisions, and constraints synthesized by your AI agent.
30
+
31
+ ---
32
+
33
+ ## Key Features
34
+
35
+ - **Native Agent Integration:** Built-in slash commands (`/knowcode`, `/know-sync`) that plug directly into Agentic IDEs without configuration.
36
+ - **Multi-Language AST Parsing**: Built on top of `tree-sitter`, with out-of-the-box support for **Python**, **JavaScript**, and **TypeScript**.
37
+ - **Deterministic State & Revision Tracking**: Tracks codebase changes across sequential revisions (`S-001`, `S-002`, etc.).
38
+ - **Diff & Report Generation**: Automatically computes additions, deletions, line-boundary modifications, and maps changes to their top-level affected components.
39
+
40
+ ---
41
+
42
+ ## Installation
43
+
44
+ ### Prerequisites
45
+ - [Python 3.13+](https://www.python.org/)
46
+ - [uv Package Manager](https://github.com/astral-sh/uv)
47
+
48
+ ### Installation
49
+
50
+ You can install Knowcode directly via pip or npm.
51
+
52
+ **Using pip:**
53
+ ```bash
54
+ pip install knowcode
55
+ ```
56
+
57
+ **Using npm:**
58
+ ```bash
59
+ npm install -g knowcode
60
+ ```
61
+
62
+ #### Development Setup
63
+
64
+ If you want to contribute or modify the code, clone the repository and install it in editable mode:
65
+
66
+ ```bash
67
+ git clone https://github.com/knowiki/knowcode.git
68
+ cd knowcode
69
+ uv sync
70
+ uv pip install -e .
71
+ ```
72
+
73
+ ---
74
+
75
+ ## Usage: The Agentic Workflow
76
+
77
+ KnowCode is designed to be driven by you and your AI agent in tandem.
78
+
79
+ ### 1. Initialize the Repository
80
+ Run the initialization command in your target repository terminal:
81
+ ```bash
82
+ know .
83
+ ```
84
+ This scaffolds the `.agent/` and `.knowcode/` directories, computes your first AST snapshot, and drops `knowcode.md` at your root.
85
+
86
+ *Note: To prevent polluting your repository, `know .` automatically adds `.knowcode/`, `.agent/`, and `knowcode.md` to your `.gitignore`. If you want to share your synthesized semantic knowledge with your team, you can selectively un-ignore `.knowcode/knowledge/`.*
87
+
88
+ ### 2. Activate the Agent
89
+ In your AI chat (Cursor, Copilot, Gemini), simply type:
90
+ ```text
91
+ /knowcode
92
+ ```
93
+ The agent will instantly read `knowcode.md`, lock into the KnowCode governance rules, and begin silently tracking your intent in `.agent/memory/active_context.md` while you code.
94
+
95
+ ### 3. Sync & Synthesize
96
+ After you finish a coding session or fix a bug, instruct the agent to synchronize by typing:
97
+ ```text
98
+ /know-sync
99
+ ```
100
+ The agent will orchestrate the entire lifecycle:
101
+ 1. Run `know sync` to compute structural AST diffs.
102
+ 2. Read the generated structural report (`R-XXX.md`).
103
+ 3. Reconcile the structural reality against your tracked intent.
104
+ 4. Distribute the extracted knowledge into the 5 semantic buckets (`architecture`, `decisions`, etc.).
105
+ 5. Run `know sync-semantic` to commit the knowledge and bump the revision.
106
+
107
+ ---
108
+
109
+ ## Ecosystem Layout
110
+
111
+ When KnowCode is initialized in a repository via `know .`, it generates a governed agent architecture:
112
+
113
+ ```text
114
+ /
115
+ ├── knowcode.md # The Agent Ignition Switch (Read by the AI)
116
+ ├── .agent/ # The Semantic Governance & Memory Layer
117
+ │ ├── memory/
118
+ │ │ ├── active_context.md # The AI's short-term intent tracking buffer
119
+ │ │ └── previous_context.md
120
+ │ ├── skills/
121
+ │ │ ├── track_intent.md # Background skill for tracking architectural intent
122
+ │ │ └── synthesize_knowledge.md
123
+ │ └── workflows/
124
+ │ ├── sync_reconciliation.md # The /know-sync workflow
125
+ │ └── ingest_legacy.md # The /know-ingest workflow
126
+
127
+ └── .knowcode/ # The Deterministic Knowledge Artifact
128
+ ├── state.yaml # Authoritative state registry (managed by the Engine)
129
+ ├── structure/ # Deterministic AST snapshots (e.g. S-001.json)
130
+ ├── reports/ # Change and diff analysis reports (e.g. R-001.md)
131
+ └── knowledge/ # Permanent semantic knowledge (AI synthesized)
132
+ ├── architecture/
133
+ ├── components/
134
+ ├── constraints/
135
+ ├── conventions/
136
+ ├── decisions/
137
+ └── raw/ # Inbox for legacy or unstructured documentation
138
+ ```
139
+
140
+ ---
141
+
142
+ ## CLI Reference & Manual Execution
143
+
144
+ While the Agentic Workflow relies on slash commands to orchestrate operations, developers can bypass the AI entirely and execute any step manually using the `know` CLI. This is useful for CI/CD pipelines, programmatic integration, or direct inspection.
145
+
146
+ - `know .`: Initializes Knowcode in the current directory.
147
+ - `know status`: Displays current structural and semantic revisions.
148
+ - `know sync`: Computes AST diffs, generates a report, and rolls over the memory buffer.
149
+ - `know sync-semantic`: Bumps the semantic revision after the AI (or a human) finishes synthesis.
150
+ - `know ingest-semantic .`: Wipes the raw documentation inbox and bumps the revision.
151
+
152
+ ---
153
+
154
+ ## License
155
+
156
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ const { spawnSync } = require('child_process');
3
+ const path = require('path');
4
+ const os = require('os');
5
+
6
+ const platform = os.platform(); // 'win32', 'darwin', 'linux'
7
+ const arch = os.arch(); // 'x64', 'arm64'
8
+
9
+ const packageMap = {
10
+ 'win32-x64': 'knowcode-win32-x64',
11
+ 'darwin-arm64': 'knowcode-darwin-arm64',
12
+ 'linux-x64': 'knowcode-linux-x64'
13
+ };
14
+
15
+ const key = `${platform}-${arch}`;
16
+ const targetPackageName = packageMap[key];
17
+
18
+ if (!targetPackageName) {
19
+ console.error(`Unsupported platform/architecture: ${key}`);
20
+ process.exit(1);
21
+ }
22
+
23
+ try {
24
+ const binaryName = platform === 'win32' ? 'know.exe' : 'know';
25
+ const binaryPath = require.resolve(`${targetPackageName}/bin/${binaryName}`);
26
+
27
+ // Set the environment variable to identify npm install method
28
+ process.env.KNOWCODE_INSTALL_METHOD = 'npm';
29
+
30
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
31
+ stdio: 'inherit',
32
+ windowsHide: true
33
+ });
34
+
35
+ process.exit(result.status ?? 0);
36
+ } catch (err) {
37
+ console.error(`Error: Failed to execute KnowCode CLI binary.
38
+ Details: ${err.message}
39
+ Please ensure that the platform-specific dependency '${targetPackageName}' is installed correctly.`);
40
+ process.exit(1);
41
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "knowcode",
3
+ "version": "0.1.0",
4
+ "description": "KnowCode : the knowledge layer to your code",
5
+ "bin": {
6
+ "know": "bin/know.js"
7
+ },
8
+ "files": [
9
+ "bin/know.js"
10
+ ],
11
+ "os": [
12
+ "win32",
13
+ "darwin",
14
+ "linux"
15
+ ],
16
+ "author": "KnowCode Team",
17
+ "license": "MIT",
18
+ "optionalDependencies": {
19
+ "knowcode-win32-x64": "0.1.0",
20
+ "knowcode-darwin-arm64": "0.1.0",
21
+ "knowcode-linux-x64": "0.1.0"
22
+ }
23
+ }