nlp2cmd-intent 0.1.1__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.
@@ -0,0 +1,248 @@
1
+ tauri-wrapper/.env.example
2
+ backend/.env.example
3
+ nlp-service/.env.example
4
+ tests/.env.example
5
+ worker/.env.example
6
+ __pycache__/
7
+ *.pyc
8
+ .env
9
+ .env.backup
10
+ node_modules
11
+
12
+ .env.local
13
+ .venv/
14
+ *.egg-info/
15
+ dist/
16
+ build/
17
+ .idea/
18
+ .vscode/
19
+ *.db
20
+ .idea/llx.iml
21
+ my-api/.env.example
22
+ test-api-qwen/.env.example
23
+ .idea
24
+ .pyqual
25
+ .code2llm
26
+ .code2llm_cache
27
+ litellm_config.yaml
28
+ litellm-config.yaml
29
+ .llm
30
+ managed_components
31
+ .gui-agent.pid
32
+ .gui-server.pid
33
+ .gui-server.log
34
+ gui-server/app_old.py
35
+ gui-server/app.py.bak
36
+ gui-server/index_old.html
37
+ gui-server/index.html.bak
38
+ gui-server/logs/
39
+ gui-agent/logs/
40
+ logs/
41
+ # Byte-compiled / optimized / DLL files
42
+ __pycache__/
43
+ *.py[codz]
44
+ *$py.class
45
+
46
+ # C extensions
47
+ *.so
48
+
49
+ # Distribution / packaging
50
+ .Python
51
+ build/
52
+ develop-eggs/
53
+ dist/
54
+ downloads/
55
+ eggs/
56
+ .eggs/
57
+ lib/
58
+ lib64/
59
+ parts/
60
+ sdist/
61
+ var/
62
+ wheels/
63
+ share/python-wheels/
64
+ *.egg-info/
65
+ .installed.cfg
66
+ *.egg
67
+ MANIFEST
68
+
69
+ # PyInstaller
70
+ # Usually these files are written by a python script from a template
71
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
72
+ *.manifest
73
+ *.spec
74
+
75
+ # Installer logs
76
+ pip-log.txt
77
+ pip-delete-this-directory.txt
78
+
79
+ # Unit test / coverage reports
80
+ htmlcov/
81
+ .tox/
82
+ .nox/
83
+ .coverage
84
+ .coverage.*
85
+ .cache
86
+ nosetests.xml
87
+ coverage.xml
88
+ *.cover
89
+ *.py.cover
90
+ .hypothesis/
91
+ .pytest_cache/
92
+ cover/
93
+
94
+ # Translations
95
+ *.mo
96
+ *.pot
97
+
98
+ # Django stuff:
99
+ *.log
100
+ local_settings.py
101
+ db.sqlite3
102
+ db.sqlite3-journal
103
+
104
+ # Flask stuff:
105
+ instance/
106
+ .webassets-cache
107
+
108
+ # Scrapy stuff:
109
+ .scrapy
110
+
111
+ # Sphinx documentation
112
+ docs/_build/
113
+
114
+ # PyBuilder
115
+ .pybuilder/
116
+ target/
117
+
118
+ # Jupyter Notebook
119
+ .ipynb_checkpoints
120
+
121
+ # IPython
122
+ profile_default/
123
+ ipython_config.py
124
+
125
+ # pyenv
126
+ # For a library or package, you might want to ignore these files since the code is
127
+ # intended to run in multiple environments; otherwise, check them in:
128
+ # .python-version
129
+
130
+ # pipenv
131
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
132
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
133
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
134
+ # install all needed dependencies.
135
+ #Pipfile.lock
136
+
137
+ # UV
138
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
139
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
140
+ # commonly ignored for libraries.
141
+ #uv.lock
142
+
143
+ # poetry
144
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
145
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
146
+ # commonly ignored for libraries.
147
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
148
+ #poetry.lock
149
+ #poetry.toml
150
+
151
+ # pdm
152
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
153
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
154
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
155
+ #pdm.lock
156
+ #pdm.toml
157
+ .pdm-python
158
+ .pdm-build/
159
+
160
+ # pixi
161
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
162
+ #pixi.lock
163
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
164
+ # in the .venv directory. It is recommended not to include this directory in version control.
165
+ .pixi
166
+
167
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
168
+ __pypackages__/
169
+
170
+ # Celery stuff
171
+ celerybeat-schedule
172
+ celerybeat.pid
173
+
174
+ # SageMath parsed files
175
+ *.sage.py
176
+
177
+ # Environments
178
+ .env
179
+ .envrc
180
+ .venv
181
+ env/
182
+ venv/
183
+ ENV/
184
+ env.bak/
185
+ venv.bak/
186
+
187
+ # Spyder project settings
188
+ .spyderproject
189
+ .spyproject
190
+
191
+ # Rope project settings
192
+ .ropeproject
193
+
194
+ # mkdocs documentation
195
+ /site
196
+
197
+ # mypy
198
+ .mypy_cache/
199
+ .dmypy.json
200
+ dmypy.json
201
+
202
+ # Pyre type checker
203
+ .pyre/
204
+
205
+ # pytype static type analyzer
206
+ .pytype/
207
+
208
+ # Cython debug symbols
209
+ cython_debug/
210
+
211
+ # PyCharm
212
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
213
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
214
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
215
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
216
+ #.idea/
217
+
218
+ # Abstra
219
+ # Abstra is an AI-powered process automation framework.
220
+ # Ignore directories containing user credentials, local state, and settings.
221
+ # Learn more at https://abstra.io/docs
222
+ .abstra/
223
+
224
+ # Visual Studio Code
225
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
226
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
227
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
228
+ # you could uncomment the following to ignore the entire vscode folder
229
+ # .vscode/
230
+
231
+ # Ruff stuff:
232
+ .ruff_cache/
233
+
234
+ # PyPI configuration file
235
+ .pypirc
236
+
237
+ # Cursor
238
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
239
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
240
+ # refer to https://docs.cursor.com/context/ignore-files
241
+ .cursorignore
242
+ .cursorindexingignore
243
+
244
+ # Marimo
245
+ marimo/_static/
246
+ marimo/_lsp/
247
+ __marimo__/
248
+ .aider*
@@ -0,0 +1,74 @@
1
+ Metadata-Version: 2.4
2
+ Name: nlp2cmd-intent
3
+ Version: 0.1.1
4
+ Summary: NL normalization, intent detection, and entity extraction for nlp2cmd
5
+ License-Expression: Apache-2.0
6
+ Requires-Python: >=3.10
7
+ Requires-Dist: pact-ir>=0.1.0
8
+ Requires-Dist: pydantic>=2.0
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest>=8.0; extra == 'dev'
11
+ Description-Content-Type: text/markdown
12
+
13
+ # nlp2cmd-intent
14
+
15
+ NL → **IntentIR**: normalizacja, detekcja intencji, encje.
16
+
17
+ Kanoniczna implementacja `KeywordIntentDetector` — nlp2cmd re-eksportuje ją z `nlp2cmd.generation.keywords`.
18
+
19
+ ## Użycie
20
+
21
+ ```python
22
+ from nlp2cmd_intent import IntentPipeline, analyze_query, ensure_intent_clear
23
+
24
+ intent = IntentPipeline().run("znajdź pliki *.py w src")
25
+ print(intent.intent, intent.target_kind, intent.confidence)
26
+
27
+ if intent.needs_clarification():
28
+ # confidence < 0.5 lub niepuste ambiguities
29
+ ...
30
+
31
+ ensure_intent_clear(intent, enforced=True) # raises IntentClarificationRequired
32
+
33
+ structure = analyze_query("znajdź pliki *.py w src", include_plan=True)
34
+ ```
35
+
36
+ ### Egzekwowanie clarification
37
+
38
+ ```mermaid
39
+ flowchart LR
40
+ IR[IntentIR] --> NC{needs_clarification?}
41
+ NC -->|plan — zawsze| BLOCK[IntentClarificationRequired]
42
+ NC -->|show — opcjonalnie| ENV{NLP2CMD_ENFORCE_CLARIFICATION=1}
43
+ ENV -->|tak| BLOCK
44
+ ENV -->|nie| OK[kontynuuj]
45
+ ```
46
+
47
+ | Ścieżka | Zachowanie |
48
+ |---------|------------|
49
+ | `nlp2cmd plan` | zawsze blokuje przy niskiej pewności |
50
+ | `nlp2dsl show` | tylko z `NLP2CMD_ENFORCE_CLARIFICATION=1` |
51
+
52
+ Kontrakty Intract (plan steps) — w **nlp2cmd**, nie w tym pakiecie. Zob. [`docs/intract-integration.md`](../../docs/intract-integration.md).
53
+
54
+ ## CLI (przez nlp2dsl-show)
55
+
56
+ ```bash
57
+ nlp2dsl show "znajdź pliki *.py w src"
58
+ ```
59
+
60
+ ## Instalacja
61
+
62
+ ```bash
63
+ pip install -e packages/pact-ir
64
+ pip install -e packages/nlp2cmd-intent
65
+ ```
66
+
67
+ ## Pliki danych
68
+
69
+ Bundlowane w `src/nlp2cmd_intent/data/`:
70
+
71
+ - `patterns.json`
72
+ - `keyword_intent_detector_config.json`
73
+
74
+ Override: `NLP2CMD_PATTERNS_FILE`, `NLP2CMD_DETECTOR_CONFIG_FILE`, `NLP2CMD_CONFIG_DIR`.
@@ -0,0 +1,62 @@
1
+ # nlp2cmd-intent
2
+
3
+ NL → **IntentIR**: normalizacja, detekcja intencji, encje.
4
+
5
+ Kanoniczna implementacja `KeywordIntentDetector` — nlp2cmd re-eksportuje ją z `nlp2cmd.generation.keywords`.
6
+
7
+ ## Użycie
8
+
9
+ ```python
10
+ from nlp2cmd_intent import IntentPipeline, analyze_query, ensure_intent_clear
11
+
12
+ intent = IntentPipeline().run("znajdź pliki *.py w src")
13
+ print(intent.intent, intent.target_kind, intent.confidence)
14
+
15
+ if intent.needs_clarification():
16
+ # confidence < 0.5 lub niepuste ambiguities
17
+ ...
18
+
19
+ ensure_intent_clear(intent, enforced=True) # raises IntentClarificationRequired
20
+
21
+ structure = analyze_query("znajdź pliki *.py w src", include_plan=True)
22
+ ```
23
+
24
+ ### Egzekwowanie clarification
25
+
26
+ ```mermaid
27
+ flowchart LR
28
+ IR[IntentIR] --> NC{needs_clarification?}
29
+ NC -->|plan — zawsze| BLOCK[IntentClarificationRequired]
30
+ NC -->|show — opcjonalnie| ENV{NLP2CMD_ENFORCE_CLARIFICATION=1}
31
+ ENV -->|tak| BLOCK
32
+ ENV -->|nie| OK[kontynuuj]
33
+ ```
34
+
35
+ | Ścieżka | Zachowanie |
36
+ |---------|------------|
37
+ | `nlp2cmd plan` | zawsze blokuje przy niskiej pewności |
38
+ | `nlp2dsl show` | tylko z `NLP2CMD_ENFORCE_CLARIFICATION=1` |
39
+
40
+ Kontrakty Intract (plan steps) — w **nlp2cmd**, nie w tym pakiecie. Zob. [`docs/intract-integration.md`](../../docs/intract-integration.md).
41
+
42
+ ## CLI (przez nlp2dsl-show)
43
+
44
+ ```bash
45
+ nlp2dsl show "znajdź pliki *.py w src"
46
+ ```
47
+
48
+ ## Instalacja
49
+
50
+ ```bash
51
+ pip install -e packages/pact-ir
52
+ pip install -e packages/nlp2cmd-intent
53
+ ```
54
+
55
+ ## Pliki danych
56
+
57
+ Bundlowane w `src/nlp2cmd_intent/data/`:
58
+
59
+ - `patterns.json`
60
+ - `keyword_intent_detector_config.json`
61
+
62
+ Override: `NLP2CMD_PATTERNS_FILE`, `NLP2CMD_DETECTOR_CONFIG_FILE`, `NLP2CMD_CONFIG_DIR`.
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "nlp2cmd-intent"
7
+ version = "0.1.1"
8
+ description = "NL normalization, intent detection, and entity extraction for nlp2cmd"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "Apache-2.0"
12
+ dependencies = [
13
+ "pact-ir>=0.1.0",
14
+ "pydantic>=2.0",
15
+ ]
16
+
17
+ [project.optional-dependencies]
18
+ dev = ["pytest>=8.0"]
19
+
20
+ [tool.hatch.build.targets.wheel]
21
+ packages = ["src/nlp2cmd_intent"]
22
+
23
+ [tool.pytest.ini_options]
24
+ testpaths = ["tests"]
@@ -0,0 +1,31 @@
1
+ """NL → IntentIR pipeline."""
2
+
3
+ from nlp2cmd_intent.clarification import (
4
+ IntentClarificationRequired,
5
+ clarification_enforced,
6
+ ensure_intent_clear,
7
+ )
8
+ from nlp2cmd_intent.facade import IntentPipeline, default_intent_detector
9
+ from nlp2cmd_intent.input import analyze_query
10
+ from nlp2cmd_intent.keywords import DetectionResult, KeywordIntentDetector, KeywordPatterns
11
+ from nlp2cmd_intent.normalize import QueryNormalizer
12
+ from nlp2cmd_intent.nlp2cmd_convert import detection_to_intent_ir
13
+ from nlp2cmd_intent.protocols import EntityExtractor, IntentDetector
14
+
15
+ __all__ = [
16
+ "DetectionResult",
17
+ "EntityExtractor",
18
+ "IntentClarificationRequired",
19
+ "IntentDetector",
20
+ "IntentPipeline",
21
+ "KeywordIntentDetector",
22
+ "KeywordPatterns",
23
+ "QueryNormalizer",
24
+ "analyze_query",
25
+ "clarification_enforced",
26
+ "default_intent_detector",
27
+ "detection_to_intent_ir",
28
+ "ensure_intent_clear",
29
+ ]
30
+
31
+ __version__ = "0.1.0"
@@ -0,0 +1,37 @@
1
+ """Intent clarification enforcement for low-confidence queries."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import os
6
+
7
+ from pact_ir import IntentIR
8
+
9
+
10
+ class IntentClarificationRequired(Exception):
11
+ """Raised when IntentIR needs user clarification before planning."""
12
+
13
+ def __init__(self, intent: IntentIR) -> None:
14
+ self.intent = intent
15
+ messages: list[str] = []
16
+ for ambiguity in intent.ambiguities:
17
+ messages.append(ambiguity.message)
18
+ if intent.confidence < 0.5:
19
+ messages.append(f"confidence {intent.confidence:.2f} below threshold 0.5")
20
+ super().__init__("; ".join(messages) or "intent needs clarification")
21
+
22
+
23
+ def clarification_enforced() -> bool:
24
+ return os.getenv("NLP2CMD_ENFORCE_CLARIFICATION", "0").strip().lower() in {
25
+ "1",
26
+ "true",
27
+ "yes",
28
+ "on",
29
+ }
30
+
31
+
32
+ def ensure_intent_clear(intent: IntentIR, *, enforced: bool | None = None) -> None:
33
+ """Raise IntentClarificationRequired when clarification is required."""
34
+ if enforced is None:
35
+ enforced = clarification_enforced()
36
+ if enforced and intent.needs_clarification():
37
+ raise IntentClarificationRequired(intent)
@@ -0,0 +1,215 @@
1
+ {
2
+ "$schema": "keyword_intent_detector_config.v1",
3
+ "domain_boosters": {
4
+ "sql": [
5
+ "tabel",
6
+ "tabela",
7
+ "table",
8
+ "kolumna",
9
+ "column",
10
+ "baz",
11
+ "baza",
12
+ "database",
13
+ "sql",
14
+ "where",
15
+ "join",
16
+ "tabeli",
17
+ "z tabeli",
18
+ "select",
19
+ "insert",
20
+ "update",
21
+ "delete",
22
+ "SELECT",
23
+ "INSERT",
24
+ "UPDATE",
25
+ "DELETE"
26
+ ],
27
+ "shell": [
28
+ "list_processes",
29
+ "process",
30
+ "reboot",
31
+ "service_start",
32
+ "service_restart",
33
+ "service_stop",
34
+ "service_status",
35
+ "open_url",
36
+ "search_web",
37
+ "file_operation",
38
+ "find",
39
+ "archive",
40
+ "disk",
41
+ "system_maintenance",
42
+ "development",
43
+ "security",
44
+ "process_management",
45
+ "find",
46
+ "list",
47
+ "znajd\u017a",
48
+ "plik",
49
+ "pliki",
50
+ "u\u017cytkownik",
51
+ "u\u017cytkownika",
52
+ "poka\u017c",
53
+ "pokaz"
54
+ ],
55
+ "docker": [
56
+ "docker",
57
+ "doker",
58
+ "dokcer",
59
+ "kontener",
60
+ "container",
61
+ "obraz",
62
+ "image",
63
+ "compose",
64
+ "dockerfile",
65
+ "ker\u00f3w",
66
+ "k\u00f3r\u00f3w",
67
+ "dker\u00f3w",
68
+ "dkor\u00f3w",
69
+ "logi",
70
+ "logs"
71
+ ],
72
+ "kubernetes": [
73
+ "kubernetes",
74
+ "k8s",
75
+ "kubectl",
76
+ "pod",
77
+ "deployment",
78
+ "namespace",
79
+ "helm",
80
+ "cluster",
81
+ "node",
82
+ "service"
83
+ ],
84
+ "git": [
85
+ "git",
86
+ "repo",
87
+ "repository",
88
+ "commit",
89
+ "branch",
90
+ "ga\u0142\u0105\u017a",
91
+ "merge",
92
+ "push",
93
+ "pull",
94
+ "clone"
95
+ ],
96
+ "dql": [
97
+ "entity",
98
+ "graph",
99
+ "node",
100
+ "edge",
101
+ "relation"
102
+ ],
103
+ "browser": [
104
+ "przegl\u0105dark",
105
+ "browser",
106
+ "strona",
107
+ "website",
108
+ "kliknij",
109
+ "click",
110
+ "formularz",
111
+ "form",
112
+ "przycisk",
113
+ "button",
114
+ "link",
115
+ "url",
116
+ "google",
117
+ "github",
118
+ "amazon",
119
+ "szukaj",
120
+ "wyszukaj",
121
+ "wpisz",
122
+ "type"
123
+ ]
124
+ },
125
+ "priority_intents": {
126
+ "sql": [
127
+ "delete",
128
+ "update",
129
+ "insert",
130
+ "show_tables",
131
+ "aggregate",
132
+ "select"
133
+ ],
134
+ "shell": [
135
+ "find",
136
+ "list_processes",
137
+ "process",
138
+ "reboot",
139
+ "service_start",
140
+ "service_restart",
141
+ "service_stop",
142
+ "service_status",
143
+ "open_url",
144
+ "search_web",
145
+ "file_operation",
146
+ "archive",
147
+ "disk",
148
+ "system_maintenance",
149
+ "development",
150
+ "security",
151
+ "process_management",
152
+ "list_dirs",
153
+ "find"
154
+ ],
155
+ "docker": [
156
+ "stop",
157
+ "prune",
158
+ "build",
159
+ "run",
160
+ "list",
161
+ "logs",
162
+ "exec",
163
+ "start",
164
+ "remove"
165
+ ],
166
+ "kubernetes": [
167
+ "delete",
168
+ "scale",
169
+ "describe",
170
+ "logs"
171
+ ],
172
+ "git": [
173
+ "reset",
174
+ "revert",
175
+ "merge",
176
+ "rebase",
177
+ "push",
178
+ "commit",
179
+ "stash"
180
+ ],
181
+ "browser": [
182
+ "web_action",
183
+ "navigate",
184
+ "click",
185
+ "fill_form"
186
+ ]
187
+ },
188
+ "fast_path": {
189
+ "browser_keywords": [
190
+ "przegl\u0105dark",
191
+ "browser",
192
+ "otw\u00f3rz stron\u0119",
193
+ "open url",
194
+ "open website",
195
+ "go to",
196
+ "navigate to"
197
+ ],
198
+ "search_keywords": [
199
+ "szukaj w internecie",
200
+ "szukaj online",
201
+ "znajd\u017a w internecie",
202
+ "look up online"
203
+ ],
204
+ "common_images": [
205
+ "nginx",
206
+ "redis",
207
+ "postgres",
208
+ "postgresql",
209
+ "mysql",
210
+ "mongo",
211
+ "mongodb",
212
+ "rabbitmq"
213
+ ]
214
+ }
215
+ }