nex-cli 0.2.1__tar.gz → 0.3.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.
nex_cli-0.3.0/LICENSE ADDED
@@ -0,0 +1,200 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ https://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You meet
92
+ the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative Works
95
+ a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works that
101
+ You distribute, all copyright, patent, trademark, and attribution
102
+ notices from the Source form of the Work, excluding those notices
103
+ that do not pertain to any part of the Derivative Works; and
104
+
105
+ (d) If the Work includes a "NOTICE" text file as part of its
106
+ distribution, then any Derivative Works that You distribute must
107
+ include a readable copy of the attribution notices contained
108
+ within such NOTICE file, excluding those notices that do not
109
+ pertain to any part of the Derivative Works, in at least one
110
+ of the following places: within a NOTICE text file distributed
111
+ as part of the Derivative Works; within the Source form or
112
+ documentation, if provided along with the Derivative Works; or,
113
+ within a display generated by the Derivative Works, if and
114
+ wherever such third-party notices normally appear. The contents
115
+ of the NOTICE file are for informational purposes only and
116
+ do not modify the License. You may add Your own attribution
117
+ notices within Derivative Works that You distribute, alongside
118
+ or as an addendum to the NOTICE text from the Work, provided
119
+ that such additional attribution notices cannot be construed
120
+ as modifying the License.
121
+
122
+ You may add Your own copyright statement to Your modifications and
123
+ may provide additional or different license terms and conditions
124
+ for use, reproduction, or distribution of Your modifications, or
125
+ for any such Derivative Works as a whole, provided Your use,
126
+ reproduction, and distribution of the Work otherwise complies with
127
+ the conditions stated in this License.
128
+
129
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
130
+ any Contribution intentionally submitted for inclusion in the Work
131
+ by You to the Licensor shall be under the terms and conditions of
132
+ this License, without any additional terms or conditions.
133
+ Notwithstanding the above, nothing herein shall supersede or modify
134
+ the terms of any separate license agreement you may have executed
135
+ with Licensor regarding such Contributions.
136
+
137
+ 6. Trademarks. This License does not grant permission to use the trade
138
+ names, trademarks, service marks, or product names of the Licensor,
139
+ except as required for reasonable and customary use in describing the
140
+ origin of the Work and reproducing the content of the NOTICE file.
141
+
142
+ 7. Disclaimer of Warranty. Unless required by applicable law or
143
+ agreed to in writing, Licensor provides the Work (and each
144
+ Contributor provides its Contributions) on an "AS IS" BASIS,
145
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
146
+ implied, including, without limitation, any warranties or conditions
147
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
148
+ PARTICULAR PURPOSE. You are solely responsible for determining the
149
+ appropriateness of using or redistributing the Work and assume any
150
+ risks associated with Your exercise of permissions under this License.
151
+
152
+ 8. Limitation of Liability. In no event and under no legal theory,
153
+ whether in tort (including negligence), contract, or otherwise,
154
+ unless required by applicable law (such as deliberate and grossly
155
+ negligent acts) or agreed to in writing, shall any Contributor be
156
+ liable to You for damages, including any direct, indirect, special,
157
+ incidental, or consequential damages of any character arising as a
158
+ result of this License or out of the use or inability to use the
159
+ Work (including but not limited to damages for loss of goodwill,
160
+ work stoppage, computer failure or malfunction, or any and all
161
+ other commercial damages or losses), even if such Contributor
162
+ has been advised of the possibility of such damages.
163
+
164
+ 9. Accepting Warranty or Additional Liability. While redistributing
165
+ the Work or Derivative Works thereof, You may choose to offer,
166
+ and charge a fee for, acceptance of support, warranty, indemnity,
167
+ or other liability obligations and/or rights consistent with this
168
+ License. However, in accepting such obligations, You may act only
169
+ on Your own behalf and on Your sole responsibility, not on behalf
170
+ of any other Contributor, and only if You agree to indemnify,
171
+ defend, and hold each Contributor harmless for any liability
172
+ incurred by, or claims asserted against, such Contributor by reason
173
+ of your accepting any such warranty or additional liability.
174
+
175
+ END OF TERMS AND CONDITIONS
176
+
177
+ APPENDIX: How to apply the Apache License to your work.
178
+
179
+ To apply the Apache License to your work, attach the following
180
+ boilerplate notice, with the fields enclosed by brackets "[]"
181
+ replaced with your own identifying information. (Don't include
182
+ the brackets!) The text should be enclosed in the appropriate
183
+ comment syntax for the file format. We also recommend that a
184
+ file or class name and description of purpose be included on the
185
+ same "printed page" as the copyright notice for easier
186
+ identification within third-party archives.
187
+
188
+ Copyright 2026 Ankush Thakur
189
+
190
+ Licensed under the Apache License, Version 2.0 (the "License");
191
+ you may not use this file except in compliance with the License.
192
+ You may obtain a copy of the License at
193
+
194
+ https://www.apache.org/licenses/LICENSE-2.0
195
+
196
+ Unless required by applicable law or agreed to in writing, software
197
+ distributed under the License is distributed on an "AS IS" BASIS,
198
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
199
+ See the License for the specific language governing permissions and
200
+ limitations under the License.
nex_cli-0.3.0/PKG-INFO ADDED
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.5
2
+ Name: nex-cli
3
+ Version: 0.3.0
4
+ Summary: A command-line interface for Nex.
5
+ Author: Nex contributors
6
+ License: Apache-2.0
7
+ License-File: LICENSE
8
+ Requires-Python: >=3.12
9
+ Requires-Dist: rich>=13
10
+ Requires-Dist: typer>=0.12
11
+ Provides-Extra: dev
12
+ Requires-Dist: pytest>=7; extra == 'dev'
13
+ Description-Content-Type: text/markdown
14
+
15
+ # nex-cli
16
+
17
+ `nex-cli` is the command-line interface for Nex.
18
+
19
+ ## Installation
20
+
21
+ For normal use, install Nex from PyPI with [pipx](https://pipx.pypa.io/):
22
+
23
+ ```bash
24
+ pipx install nex-cli
25
+ nex --version
26
+ ```
27
+
28
+ The current release reports `nex 0.2.1`.
29
+
30
+ ## Development
31
+
32
+ To work on Nex locally, clone the repository and install the development
33
+ dependencies in an isolated environment:
34
+
35
+ ```bash
36
+ git clone https://github.com/ankush-exe/nex-cli.git
37
+ cd nex-cli
38
+ python -m venv .venv
39
+ source .venv/bin/activate
40
+ python -m pip install -e ".[dev]"
41
+ pytest
42
+ ```
43
+
44
+ On Windows, activate the environment with `.venv\\Scripts\\activate` instead.
45
+
46
+ ## Usage
47
+
48
+ ```bash
49
+ nex learn # Discover the project and save workflow configuration
50
+ nex # Execute the saved workflow when one component is runnable
51
+ nex --component client # Execute the workflow for the client component
52
+ nex learn --force # Replace an existing Nex config
53
+ nex --help
54
+ nex --version
55
+ ```
56
+
57
+ `nex learn` discovers and understands the project, then saves workflow
58
+ configuration to `.nex/config.toml`. For example, run `nex learn` from a
59
+ project root before running `nex`:
60
+
61
+ ```bash
62
+ nex learn
63
+ nex
64
+ ```
65
+
66
+ Bare `nex` reads the saved configuration and executes the workflow when exactly
67
+ one runnable component exists. If discovery finds multiple runnable components,
68
+ bare `nex` asks you to select one by its relative path:
69
+
70
+ ```bash
71
+ nex --component client
72
+ ```
73
+
74
+ Nex streams workflow output directly to the terminal, returns the workflow's
75
+ exit code, and maps Ctrl+C to exit code 130.
76
+
77
+ `nex learn` scans the current directory and up to three levels of child
78
+ directories, reports each detected project component, and saves the result to
79
+ `.nex/config.toml`. It detects `package.json`, `requirements.txt`,
80
+ `pyproject.toml`, and `docker-compose.yml`, while skipping common generated,
81
+ environment, dependency, and version-control directories.
82
+
83
+ For JavaScript components, Nex reports `dev` and `start` scripts and detects
84
+ the package manager from lockfiles for npm, pnpm, Yarn, or Bun. For Python
85
+ components, it records safe metadata such as the project name and Python
86
+ requirement from `pyproject.toml`. Malformed manifests are retained as detected
87
+ components and reported as warnings instead of stopping discovery. `nex learn`
88
+ does not install dependencies, modify project files, or start processes.
89
+
90
+ The generated configuration uses schema version 2 and records components,
91
+ signals, workflows, warnings, and deterministic suggested commands. Nex
92
+ refuses to replace an existing config unless you pass `--force`; this leaves
93
+ older v0.2.x schema version 1 files untouched until the user explicitly
94
+ chooses to replace them.
95
+
96
+ Nex v0.3.0 executes one workflow command at a time. It does not configure
97
+ environments, orchestrate multiple services, or supervise process trees. When
98
+ one component exposes more than one suggestion, Nex runs its first deterministic
99
+ suggestion (`dev` before `start`).
100
+
101
+ ## Not yet
102
+
103
+ - Multi-service orchestration and process supervision
104
+ - Automatic workflow detection beyond the reported file signals
105
+ - Dependency installation
106
+
107
+ ## License
108
+
109
+ Nex is licensed under the Apache License 2.0. See [LICENSE](LICENSE) for the
110
+ full terms.
111
+
112
+ The `v0.1.0`, `v0.2.0`, and `v0.2.1` release tags and their distributed
113
+ artifacts remain available under their original MIT licenses. This change does
114
+ not revoke permissions already granted under those licenses.
115
+
116
+ ---
117
+
118
+ © 2026 Ankush Thakur. All rights reserved.
@@ -0,0 +1,104 @@
1
+ # nex-cli
2
+
3
+ `nex-cli` is the command-line interface for Nex.
4
+
5
+ ## Installation
6
+
7
+ For normal use, install Nex from PyPI with [pipx](https://pipx.pypa.io/):
8
+
9
+ ```bash
10
+ pipx install nex-cli
11
+ nex --version
12
+ ```
13
+
14
+ The current release reports `nex 0.2.1`.
15
+
16
+ ## Development
17
+
18
+ To work on Nex locally, clone the repository and install the development
19
+ dependencies in an isolated environment:
20
+
21
+ ```bash
22
+ git clone https://github.com/ankush-exe/nex-cli.git
23
+ cd nex-cli
24
+ python -m venv .venv
25
+ source .venv/bin/activate
26
+ python -m pip install -e ".[dev]"
27
+ pytest
28
+ ```
29
+
30
+ On Windows, activate the environment with `.venv\\Scripts\\activate` instead.
31
+
32
+ ## Usage
33
+
34
+ ```bash
35
+ nex learn # Discover the project and save workflow configuration
36
+ nex # Execute the saved workflow when one component is runnable
37
+ nex --component client # Execute the workflow for the client component
38
+ nex learn --force # Replace an existing Nex config
39
+ nex --help
40
+ nex --version
41
+ ```
42
+
43
+ `nex learn` discovers and understands the project, then saves workflow
44
+ configuration to `.nex/config.toml`. For example, run `nex learn` from a
45
+ project root before running `nex`:
46
+
47
+ ```bash
48
+ nex learn
49
+ nex
50
+ ```
51
+
52
+ Bare `nex` reads the saved configuration and executes the workflow when exactly
53
+ one runnable component exists. If discovery finds multiple runnable components,
54
+ bare `nex` asks you to select one by its relative path:
55
+
56
+ ```bash
57
+ nex --component client
58
+ ```
59
+
60
+ Nex streams workflow output directly to the terminal, returns the workflow's
61
+ exit code, and maps Ctrl+C to exit code 130.
62
+
63
+ `nex learn` scans the current directory and up to three levels of child
64
+ directories, reports each detected project component, and saves the result to
65
+ `.nex/config.toml`. It detects `package.json`, `requirements.txt`,
66
+ `pyproject.toml`, and `docker-compose.yml`, while skipping common generated,
67
+ environment, dependency, and version-control directories.
68
+
69
+ For JavaScript components, Nex reports `dev` and `start` scripts and detects
70
+ the package manager from lockfiles for npm, pnpm, Yarn, or Bun. For Python
71
+ components, it records safe metadata such as the project name and Python
72
+ requirement from `pyproject.toml`. Malformed manifests are retained as detected
73
+ components and reported as warnings instead of stopping discovery. `nex learn`
74
+ does not install dependencies, modify project files, or start processes.
75
+
76
+ The generated configuration uses schema version 2 and records components,
77
+ signals, workflows, warnings, and deterministic suggested commands. Nex
78
+ refuses to replace an existing config unless you pass `--force`; this leaves
79
+ older v0.2.x schema version 1 files untouched until the user explicitly
80
+ chooses to replace them.
81
+
82
+ Nex v0.3.0 executes one workflow command at a time. It does not configure
83
+ environments, orchestrate multiple services, or supervise process trees. When
84
+ one component exposes more than one suggestion, Nex runs its first deterministic
85
+ suggestion (`dev` before `start`).
86
+
87
+ ## Not yet
88
+
89
+ - Multi-service orchestration and process supervision
90
+ - Automatic workflow detection beyond the reported file signals
91
+ - Dependency installation
92
+
93
+ ## License
94
+
95
+ Nex is licensed under the Apache License 2.0. See [LICENSE](LICENSE) for the
96
+ full terms.
97
+
98
+ The `v0.1.0`, `v0.2.0`, and `v0.2.1` release tags and their distributed
99
+ artifacts remain available under their original MIT licenses. This change does
100
+ not revoke permissions already granted under those licenses.
101
+
102
+ ---
103
+
104
+ © 2026 Ankush Thakur. All rights reserved.
@@ -9,7 +9,8 @@ from rich.table import Table
9
9
 
10
10
  from nex import __version__
11
11
  from nex.config import ConfigAlreadyExistsError, build_learn_config, write_learn_config
12
- from nex.detection import detect_project
12
+ from nex.discovery import discover_project
13
+ from nex.execution import WorkflowConfigError, run_configured_workflow
13
14
 
14
15
 
15
16
  def version_callback(value: bool) -> None:
@@ -37,10 +38,20 @@ def main(
37
38
  is_eager=True,
38
39
  help="Show the Nex version and exit.",
39
40
  ),
41
+ component: str | None = typer.Option(
42
+ None,
43
+ "--component",
44
+ help="Select one component path when multiple workflows are available.",
45
+ ),
40
46
  ) -> None:
41
47
  """Nex command-line interface."""
42
48
  if ctx.invoked_subcommand is None and not version:
43
- typer.echo(ctx.get_help())
49
+ try:
50
+ exit_code = run_configured_workflow(Path.cwd().resolve(), component)
51
+ except WorkflowConfigError as error:
52
+ typer.echo(str(error), err=True)
53
+ raise typer.Exit(code=1) from None
54
+ raise typer.Exit(code=exit_code)
44
55
 
45
56
 
46
57
  @app.command()
@@ -53,31 +64,44 @@ def learn(
53
64
  ) -> None:
54
65
  """Detect project signals and save them to .nex/config.toml."""
55
66
  root = Path.cwd().resolve()
56
- detection = detect_project(directory=root)
67
+ discovery = discover_project(root)
57
68
  console = Console()
58
69
 
59
- if not detection.found_anything:
70
+ if not discovery.found_anything:
60
71
  console.print(
61
72
  Panel("No supported project signals found in this directory.", title="Nex learn")
62
73
  )
63
74
  else:
64
75
  table = Table(title="Nex learn", show_header=True)
65
- table.add_column("Type", style="bold")
66
- table.add_column("Detected")
67
-
68
- if detection.frontend:
69
- scripts = ", ".join(detection.frontend.scripts) or "no dev/start script"
70
- table.add_row("Frontend", f"package.json ({scripts})")
71
- if detection.python_files:
72
- table.add_row("Python backend", ", ".join(detection.python_files))
73
- if detection.docker_compose:
74
- table.add_row("Services", "docker-compose.yml")
76
+ table.add_column("Component", style="bold")
77
+ table.add_column("Role")
78
+ table.add_column("Signals")
79
+ table.add_column("Workflow")
80
+
81
+ for component in discovery.components:
82
+ workflows = []
83
+ for workflow in component.workflows:
84
+ details = workflow.ecosystem
85
+ if workflow.package_manager:
86
+ details += f"/{workflow.package_manager}"
87
+ if workflow.scripts:
88
+ details += f" ({', '.join(workflow.scripts)})"
89
+ workflows.append(details)
90
+ table.add_row(
91
+ component.relative_path.as_posix(),
92
+ component.role,
93
+ ", ".join(signal.name for signal in component.signals),
94
+ ", ".join(workflows) or "-",
95
+ )
75
96
 
76
97
  console.print(table)
98
+ for component in discovery.components:
99
+ for warning in component.warnings:
100
+ console.print(f"[yellow]Warning: {warning}[/yellow]")
77
101
 
78
102
  try:
79
103
  config_path = write_learn_config(
80
- build_learn_config(root, detection), force=force
104
+ build_learn_config(root, discovery), force=force
81
105
  )
82
106
  except ConfigAlreadyExistsError as error:
83
107
  console.print(
@@ -0,0 +1,147 @@
1
+ """Persistence for the project signals learned by Nex."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ from dataclasses import dataclass
7
+ from pathlib import Path
8
+
9
+ from nex.discovery.models import ProjectDiscovery
10
+
11
+
12
+ CONFIG_DIRECTORY = ".nex"
13
+ CONFIG_FILENAME = "config.toml"
14
+
15
+
16
+ class ConfigAlreadyExistsError(FileExistsError):
17
+ """Raised when saving would overwrite an existing Nex config."""
18
+
19
+
20
+ @dataclass(frozen=True)
21
+ class LearnConfig:
22
+ """The stable, persisted representation of a discovery result."""
23
+
24
+ root: Path
25
+ components: tuple[ComponentConfig, ...]
26
+
27
+
28
+ @dataclass(frozen=True)
29
+ class ComponentConfig:
30
+ """The serializable representation of one discovered component."""
31
+
32
+ name: str
33
+ path: str
34
+ role: str
35
+ signals: tuple[str, ...]
36
+ workflows: tuple[WorkflowConfig, ...]
37
+ warnings: tuple[str, ...]
38
+
39
+
40
+ @dataclass(frozen=True)
41
+ class WorkflowConfig:
42
+ """The serializable representation of one component workflow."""
43
+
44
+ ecosystem: str
45
+ manifest: str
46
+ package_manager: str | None
47
+ scripts: tuple[str, ...]
48
+ metadata: tuple[tuple[str, str], ...]
49
+ suggested_commands: tuple[str, ...]
50
+
51
+
52
+ def build_learn_config(root: Path, discovery: ProjectDiscovery) -> LearnConfig:
53
+ """Convert a project discovery result into Nex's persisted configuration."""
54
+ components = tuple(
55
+ ComponentConfig(
56
+ name=component.name,
57
+ path=component.relative_path.as_posix(),
58
+ role=component.role,
59
+ signals=tuple(signal.name for signal in component.signals),
60
+ workflows=tuple(
61
+ WorkflowConfig(
62
+ ecosystem=workflow.ecosystem,
63
+ manifest=workflow.manifest,
64
+ package_manager=workflow.package_manager,
65
+ scripts=workflow.scripts,
66
+ metadata=workflow.metadata,
67
+ suggested_commands=workflow.suggested_commands,
68
+ )
69
+ for workflow in component.workflows
70
+ ),
71
+ warnings=component.warnings,
72
+ )
73
+ for component in discovery.components
74
+ )
75
+ return LearnConfig(root=root.resolve(), components=components)
76
+
77
+
78
+ def write_learn_config(config: LearnConfig, *, force: bool = False) -> Path:
79
+ """Write a learned config, refusing to replace an existing file by default."""
80
+ config_path = config.root / CONFIG_DIRECTORY / CONFIG_FILENAME
81
+ if config_path.exists() and not force:
82
+ raise ConfigAlreadyExistsError(config_path)
83
+
84
+ config_path.parent.mkdir(parents=True, exist_ok=True)
85
+ config_path.write_text(render_learn_config(config), encoding="utf-8")
86
+ return config_path
87
+
88
+
89
+ def render_learn_config(config: LearnConfig) -> str:
90
+ """Render the v2 multi-component configuration schema as TOML."""
91
+ lines = [
92
+ "schema_version = 2",
93
+ "",
94
+ "[project]",
95
+ f"name = {_toml_string(config.root.name)}",
96
+ f"root = {_toml_string(str(config.root))}",
97
+ ]
98
+ for component in config.components:
99
+ lines.extend(
100
+ (
101
+ "",
102
+ "[[components]]",
103
+ f"name = {_toml_string(component.name)}",
104
+ f"path = {_toml_string(component.path)}",
105
+ f"role = {_toml_string(component.role)}",
106
+ f"signals = {_toml_string_array(component.signals)}",
107
+ )
108
+ )
109
+ for workflow in component.workflows:
110
+ lines.extend(
111
+ (
112
+ "",
113
+ "[[components.workflows]]",
114
+ f"ecosystem = {_toml_string(workflow.ecosystem)}",
115
+ f"manifest = {_toml_string(workflow.manifest)}",
116
+ )
117
+ )
118
+ if workflow.package_manager is not None:
119
+ lines.append(
120
+ f"package_manager = {_toml_string(workflow.package_manager)}"
121
+ )
122
+ lines.append(f"scripts = {_toml_string_array(workflow.scripts)}")
123
+ lines.append(
124
+ f"suggested_commands = {_toml_string_array(workflow.suggested_commands)}"
125
+ )
126
+ if workflow.metadata:
127
+ lines.append("[components.workflows.metadata]")
128
+ for key, value in workflow.metadata:
129
+ lines.append(f"{_toml_key(key)} = {_toml_string(value)}")
130
+ if component.warnings:
131
+ lines.append(f"warnings = {_toml_string_array(component.warnings)}")
132
+
133
+ lines.append("")
134
+ return "\n".join(lines)
135
+
136
+
137
+ def _toml_string(value: str) -> str:
138
+ """Encode a string using TOML's JSON-compatible basic-string syntax."""
139
+ return json.dumps(value)
140
+
141
+
142
+ def _toml_string_array(values: tuple[str, ...]) -> str:
143
+ return f"[{', '.join(_toml_string(value) for value in values)}]"
144
+
145
+
146
+ def _toml_key(value: str) -> str:
147
+ return value if value.replace("-", "").replace("_", "").isalnum() else _toml_string(value)
@@ -0,0 +1,13 @@
1
+ """Multi-directory project discovery for Nex."""
2
+
3
+ from nex.discovery.models import Component, ProjectDiscovery, Signal, Workflow
4
+ from nex.discovery.scanner import DEFAULT_MAX_DEPTH, discover_project
5
+
6
+ __all__ = [
7
+ "Component",
8
+ "DEFAULT_MAX_DEPTH",
9
+ "ProjectDiscovery",
10
+ "Signal",
11
+ "Workflow",
12
+ "discover_project",
13
+ ]