netherframe.cli 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- netherframe/cli/__init__.py +1 -0
- netherframe/cli/__main__.py +4 -0
- netherframe/cli/commands/__init__.py +93 -0
- netherframe/cli/commands/backend.py +305 -0
- netherframe/cli/commands/config_command.py +98 -0
- netherframe/cli/commands/convert.py +40 -0
- netherframe/cli/commands/discover.py +679 -0
- netherframe/cli/commands/drift.py +499 -0
- netherframe/cli/commands/encode.py +130 -0
- netherframe/cli/commands/generation.py +861 -0
- netherframe/cli/commands/graph_state.py +439 -0
- netherframe/cli/commands/hybrid.py +461 -0
- netherframe/cli/commands/idiff.py +493 -0
- netherframe/cli/commands/infrastructure.py +1182 -0
- netherframe/cli/commands/init_command.py +11 -0
- netherframe/cli/commands/lint.py +49 -0
- netherframe/cli/commands/providers.py +315 -0
- netherframe/cli/commands/shell_command.py +17 -0
- netherframe/cli/commands/skill.py +167 -0
- netherframe/cli/commands/synthesis.py +732 -0
- netherframe/cli/commands/terraform_command.py +17 -0
- netherframe/cli/commands/watch_command.py +117 -0
- netherframe/cli/entrypoint.py +18 -0
- netherframe/cli/logging.py +33 -0
- netherframe/cli/main.py +177 -0
- netherframe/cli/options.py +32 -0
- netherframe/cli/py.typed +0 -0
- netherframe/cli/services/__init__.py +1 -0
- netherframe/cli/services/app_loader.py +62 -0
- netherframe/cli/services/app_resolver.py +205 -0
- netherframe/cli/services/graph_onboarding.py +144 -0
- netherframe/cli/services/legacy_cli.py +51 -0
- netherframe/cli/services/project_config.py +107 -0
- netherframe/cli/services/provider_batch.py +620 -0
- netherframe/cli/services/stack_inventory.py +342 -0
- netherframe/cli/skills/netherframe/SKILL.md +53 -0
- netherframe/cli/skills/netherframe/agents/openai.yaml +3 -0
- netherframe/cli/skills/netherframe/references/authoring.md +77 -0
- netherframe/cli/skills/netherframe/references/execution.md +70 -0
- netherframe/cli/skills/netherframe/references/migration.md +69 -0
- netherframe/cli/state_migration.py +111 -0
- netherframe/cli/tui/__init__.py +1 -0
- netherframe/cli/tui/plan_filters.py +200 -0
- netherframe/cli/tui/plan_models.py +51 -0
- netherframe/cli/tui/plan_viewer.py +745 -0
- netherframe/cli/ui.py +25 -0
- netherframe_cli-0.2.1.dist-info/METADATA +86 -0
- netherframe_cli-0.2.1.dist-info/RECORD +92 -0
- netherframe_cli-0.2.1.dist-info/WHEEL +4 -0
- netherframe_cli-0.2.1.dist-info/entry_points.txt +3 -0
- netherframe_cli-0.2.1.dist-info/licenses/LICENSE +21 -0
- nf/cli/__init__.py +4 -0
- nf/cli/__main__.py +4 -0
- nf/cli/commands/__init__.py +4 -0
- nf/cli/commands/backend.py +4 -0
- nf/cli/commands/config_command.py +4 -0
- nf/cli/commands/convert.py +4 -0
- nf/cli/commands/discover.py +4 -0
- nf/cli/commands/drift.py +4 -0
- nf/cli/commands/encode.py +4 -0
- nf/cli/commands/generation.py +4 -0
- nf/cli/commands/graph_state.py +4 -0
- nf/cli/commands/hybrid.py +4 -0
- nf/cli/commands/idiff.py +4 -0
- nf/cli/commands/infrastructure.py +4 -0
- nf/cli/commands/init_command.py +4 -0
- nf/cli/commands/lint.py +4 -0
- nf/cli/commands/providers.py +4 -0
- nf/cli/commands/shell_command.py +4 -0
- nf/cli/commands/skill.py +4 -0
- nf/cli/commands/synthesis.py +4 -0
- nf/cli/commands/terraform_command.py +4 -0
- nf/cli/commands/watch_command.py +4 -0
- nf/cli/entrypoint.py +4 -0
- nf/cli/logging.py +4 -0
- nf/cli/main.py +4 -0
- nf/cli/options.py +4 -0
- nf/cli/py.typed +0 -0
- nf/cli/services/__init__.py +4 -0
- nf/cli/services/app_loader.py +4 -0
- nf/cli/services/app_resolver.py +4 -0
- nf/cli/services/graph_onboarding.py +4 -0
- nf/cli/services/legacy_cli.py +4 -0
- nf/cli/services/project_config.py +4 -0
- nf/cli/services/provider_batch.py +4 -0
- nf/cli/services/stack_inventory.py +4 -0
- nf/cli/state_migration.py +4 -0
- nf/cli/tui/__init__.py +4 -0
- nf/cli/tui/plan_filters.py +4 -0
- nf/cli/tui/plan_models.py +4 -0
- nf/cli/tui/plan_viewer.py +4 -0
- nf/cli/ui.py +4 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Project initialization command for NF CLI."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@click.command()
|
|
7
|
+
@click.argument("project_name", required=False)
|
|
8
|
+
def init(project_name: str | None = None) -> None:
|
|
9
|
+
"""Initialize a new NF project."""
|
|
10
|
+
name = project_name or "my-project"
|
|
11
|
+
click.echo(f"Initializing project '{name}' not yet implemented")
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""Offline linting using installed policy packs, without provider execution."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from dataclasses import asdict
|
|
5
|
+
|
|
6
|
+
import click
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@click.command()
|
|
10
|
+
@click.option("--app", "app_spec", required=True, help="Trusted Python app/factory: module.path:attribute.")
|
|
11
|
+
@click.option("--pack", "pack_names", multiple=True, help="Installed lint pack name; repeat to combine (default: all installed).")
|
|
12
|
+
@click.option("--all-failures/--first-failure", default=True, show_default=True, help="Show every finding or just the first; evaluation always completes.")
|
|
13
|
+
@click.option("--require-resolved", is_flag=True, help="Also fail when checked values remain unknown.")
|
|
14
|
+
@click.option("--json", "as_json", is_flag=True, help="Emit the complete report, regardless of display limits.")
|
|
15
|
+
@click.pass_context
|
|
16
|
+
def lint(ctx, app_spec, pack_names, all_failures, require_resolved, as_json):
|
|
17
|
+
"""Check all resource lints offline using installed rule packs."""
|
|
18
|
+
from netherframe.core import App
|
|
19
|
+
from netherframe.core.linting import LintError, Linter
|
|
20
|
+
from netherframe.cli.services.app_loader import load_app_from_spec
|
|
21
|
+
|
|
22
|
+
try:
|
|
23
|
+
linter = Linter.from_plugins(pack_names or None)
|
|
24
|
+
except (ValueError, TypeError) as error:
|
|
25
|
+
raise click.ClickException(str(error)) from error
|
|
26
|
+
if not linter.rules:
|
|
27
|
+
raise click.ClickException("No lint rules loaded; install a lint pack such as netherframe.lint.hashicorp.aws.")
|
|
28
|
+
app = load_app_from_spec(app_spec)
|
|
29
|
+
if not isinstance(app, App):
|
|
30
|
+
raise click.ClickException("The app spec must return an NF App.")
|
|
31
|
+
report = linter.lint_app(app)
|
|
32
|
+
if as_json:
|
|
33
|
+
click.echo(json.dumps({**asdict(report), "evaluated": report.evaluated, "findings": len(report.findings), "deferred": len(report.deferred)}, indent=2))
|
|
34
|
+
else:
|
|
35
|
+
# Group diagnostics by resource, while preserving rule order within it.
|
|
36
|
+
for finding in report.findings if all_failures else report.findings[:1]:
|
|
37
|
+
click.echo(f"failed: {finding.address}.{finding.attribute}: {finding.rule_id}: {finding.message}")
|
|
38
|
+
if not all_failures and len(report.findings) > 1:
|
|
39
|
+
click.echo(f"{len(report.findings) - 1} more findings; use --all-failures to display them.")
|
|
40
|
+
click.echo(
|
|
41
|
+
f"{report.resource_count} resources, {report.evaluated} evaluated checks, "
|
|
42
|
+
f"{len(report.findings)} findings, {len(report.deferred)} deferred; "
|
|
43
|
+
f"{len(report.uncovered_resources)} resources without matching rules, "
|
|
44
|
+
f"{len(report.non_schema_uncovered_resources)} without policy/constraint coverage"
|
|
45
|
+
)
|
|
46
|
+
try:
|
|
47
|
+
report.assert_valid(require_resolved=require_resolved)
|
|
48
|
+
except LintError:
|
|
49
|
+
ctx.exit(1)
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
"""Provider-related commands for the NF CLI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from netherframe.core.serialization import orjson_compat as json
|
|
6
|
+
import sys
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
import click
|
|
10
|
+
from netherframe.cli.ui import console
|
|
11
|
+
from rich.table import Table
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def _get_available_provider_packages() -> dict[str, dict[str, Any]]:
|
|
15
|
+
"""Get available provider packages from the generation system."""
|
|
16
|
+
providers: dict[str, dict[str, Any]] = {}
|
|
17
|
+
|
|
18
|
+
try:
|
|
19
|
+
from netherframe.generation.api import PROVIDER_SETS, get_provider_set
|
|
20
|
+
|
|
21
|
+
# Add common provider sets information
|
|
22
|
+
providers["sets"] = {
|
|
23
|
+
set_name: {
|
|
24
|
+
"type": "set",
|
|
25
|
+
"description": f"Provider set with {len(get_provider_set(set_name))} providers",
|
|
26
|
+
"providers": get_provider_set(set_name),
|
|
27
|
+
}
|
|
28
|
+
for set_name in PROVIDER_SETS
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
except ImportError:
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
return providers
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@click.group()
|
|
38
|
+
def providers() -> None:
|
|
39
|
+
"""Provider package management utilities for Netherframe."""
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@providers.command("list")
|
|
43
|
+
@click.option(
|
|
44
|
+
"--json",
|
|
45
|
+
"output_json",
|
|
46
|
+
is_flag=True,
|
|
47
|
+
help="Output in JSON format",
|
|
48
|
+
)
|
|
49
|
+
@click.option(
|
|
50
|
+
"--sets-only",
|
|
51
|
+
is_flag=True,
|
|
52
|
+
help="Show only provider sets, not individual providers",
|
|
53
|
+
)
|
|
54
|
+
def list_providers(output_json: bool, sets_only: bool) -> None:
|
|
55
|
+
"""List available provider packages and sets.
|
|
56
|
+
|
|
57
|
+
Shows provider sets that can be used with 'nf generate providers --set <name>'.
|
|
58
|
+
|
|
59
|
+
Examples:
|
|
60
|
+
nf providers list
|
|
61
|
+
nf providers list --json
|
|
62
|
+
nf providers list --sets-only
|
|
63
|
+
|
|
64
|
+
"""
|
|
65
|
+
try:
|
|
66
|
+
from netherframe.generation.api import PROVIDER_SETS, get_provider_set
|
|
67
|
+
except ImportError:
|
|
68
|
+
console.print("[bold red]Provider generation modules not available.[/bold red]")
|
|
69
|
+
console.print(
|
|
70
|
+
"Install generation dependencies: [dim]pip install netherframe.generation[/dim]",
|
|
71
|
+
)
|
|
72
|
+
sys.exit(1)
|
|
73
|
+
|
|
74
|
+
if output_json:
|
|
75
|
+
# JSON output
|
|
76
|
+
json_data = {}
|
|
77
|
+
|
|
78
|
+
if sets_only:
|
|
79
|
+
json_data = {
|
|
80
|
+
"provider_sets": {
|
|
81
|
+
set_name: {
|
|
82
|
+
"providers": get_provider_set(set_name),
|
|
83
|
+
"count": len(get_provider_set(set_name)),
|
|
84
|
+
}
|
|
85
|
+
for set_name in sorted(PROVIDER_SETS.keys())
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
else:
|
|
89
|
+
json_data = {
|
|
90
|
+
"provider_sets": {
|
|
91
|
+
set_name: {
|
|
92
|
+
"providers": get_provider_set(set_name),
|
|
93
|
+
"count": len(get_provider_set(set_name)),
|
|
94
|
+
}
|
|
95
|
+
for set_name in sorted(PROVIDER_SETS.keys())
|
|
96
|
+
},
|
|
97
|
+
"all_providers": {provider: {"sets": []} for provider_list in PROVIDER_SETS.values() for provider in provider_list},
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
# Add set membership info to providers
|
|
101
|
+
for set_name, provider_list in PROVIDER_SETS.items():
|
|
102
|
+
for provider in provider_list:
|
|
103
|
+
json_data["all_providers"][provider]["sets"].append(set_name)
|
|
104
|
+
|
|
105
|
+
console.print(json.dumps(json_data, indent=2))
|
|
106
|
+
# Rich table output
|
|
107
|
+
elif sets_only:
|
|
108
|
+
table = Table(title="Available Provider Sets")
|
|
109
|
+
table.add_column("Set Name", style="cyan")
|
|
110
|
+
table.add_column("Count", style="yellow")
|
|
111
|
+
table.add_column("Providers", style="white")
|
|
112
|
+
|
|
113
|
+
for set_name in sorted(PROVIDER_SETS.keys()):
|
|
114
|
+
providers = get_provider_set(set_name)
|
|
115
|
+
provider_list = ", ".join(providers[:3])
|
|
116
|
+
if len(providers) > 3:
|
|
117
|
+
provider_list += f" ... (+{len(providers) - 3} more)"
|
|
118
|
+
|
|
119
|
+
table.add_row(
|
|
120
|
+
set_name,
|
|
121
|
+
str(len(providers)),
|
|
122
|
+
provider_list,
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
console.print(table)
|
|
126
|
+
else:
|
|
127
|
+
# Show both sets and individual providers
|
|
128
|
+
console.print("[bold]Provider Sets:[/bold]")
|
|
129
|
+
sets_table = Table()
|
|
130
|
+
sets_table.add_column("Set Name", style="cyan")
|
|
131
|
+
sets_table.add_column("Count", style="yellow")
|
|
132
|
+
sets_table.add_column("Providers", style="white")
|
|
133
|
+
|
|
134
|
+
for set_name in sorted(PROVIDER_SETS.keys()):
|
|
135
|
+
providers = get_provider_set(set_name)
|
|
136
|
+
provider_list = ", ".join(providers[:3])
|
|
137
|
+
if len(providers) > 3:
|
|
138
|
+
provider_list += f" ... (+{len(providers) - 3} more)"
|
|
139
|
+
|
|
140
|
+
sets_table.add_row(
|
|
141
|
+
set_name,
|
|
142
|
+
str(len(providers)),
|
|
143
|
+
provider_list,
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
console.print(sets_table)
|
|
147
|
+
|
|
148
|
+
# Show all unique providers
|
|
149
|
+
all_providers = set()
|
|
150
|
+
provider_sets_map = {}
|
|
151
|
+
|
|
152
|
+
for set_name, provider_list in PROVIDER_SETS.items():
|
|
153
|
+
for provider in provider_list:
|
|
154
|
+
all_providers.add(provider)
|
|
155
|
+
if provider not in provider_sets_map:
|
|
156
|
+
provider_sets_map[provider] = []
|
|
157
|
+
provider_sets_map[provider].append(set_name)
|
|
158
|
+
|
|
159
|
+
console.print("\n[bold]Individual Providers:[/bold]")
|
|
160
|
+
providers_table = Table()
|
|
161
|
+
providers_table.add_column("Provider", style="green")
|
|
162
|
+
providers_table.add_column("Available in Sets", style="blue")
|
|
163
|
+
|
|
164
|
+
for provider in sorted(all_providers):
|
|
165
|
+
sets = ", ".join(sorted(provider_sets_map[provider]))
|
|
166
|
+
providers_table.add_row(provider, sets)
|
|
167
|
+
|
|
168
|
+
console.print(providers_table)
|
|
169
|
+
console.print(
|
|
170
|
+
f"\n[dim]Total: {len(all_providers)} unique providers in {len(PROVIDER_SETS)} sets[/dim]",
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
@providers.command("describe")
|
|
175
|
+
@click.argument("provider_set")
|
|
176
|
+
@click.option(
|
|
177
|
+
"--json",
|
|
178
|
+
"output_json",
|
|
179
|
+
is_flag=True,
|
|
180
|
+
help="Output in JSON format",
|
|
181
|
+
)
|
|
182
|
+
def describe_set(provider_set: str, output_json: bool) -> None:
|
|
183
|
+
"""Describe a specific provider set.
|
|
184
|
+
|
|
185
|
+
Shows detailed information about providers in a set.
|
|
186
|
+
|
|
187
|
+
Examples:
|
|
188
|
+
nf providers describe common
|
|
189
|
+
nf providers describe cloud --json
|
|
190
|
+
|
|
191
|
+
"""
|
|
192
|
+
try:
|
|
193
|
+
from netherframe.generation.api import PROVIDER_SETS, get_provider_set
|
|
194
|
+
except ImportError:
|
|
195
|
+
console.print("[bold red]Provider generation modules not available.[/bold red]")
|
|
196
|
+
console.print(
|
|
197
|
+
"Install generation dependencies: [dim]pip install netherframe.generation[/dim]",
|
|
198
|
+
)
|
|
199
|
+
sys.exit(1)
|
|
200
|
+
|
|
201
|
+
if provider_set not in PROVIDER_SETS:
|
|
202
|
+
console.print(f"[bold red]Provider set '{provider_set}' not found.[/bold red]")
|
|
203
|
+
console.print("Available sets:")
|
|
204
|
+
for set_name in sorted(PROVIDER_SETS.keys()):
|
|
205
|
+
console.print(f" • {set_name}")
|
|
206
|
+
sys.exit(1)
|
|
207
|
+
|
|
208
|
+
providers = get_provider_set(provider_set)
|
|
209
|
+
|
|
210
|
+
if output_json:
|
|
211
|
+
# JSON output
|
|
212
|
+
json_data = {
|
|
213
|
+
"set_name": provider_set,
|
|
214
|
+
"provider_count": len(providers),
|
|
215
|
+
"providers": sorted(providers),
|
|
216
|
+
}
|
|
217
|
+
console.print(json.dumps(json_data, indent=2))
|
|
218
|
+
else:
|
|
219
|
+
# Rich table output
|
|
220
|
+
table = Table(title=f"Provider Set: {provider_set}")
|
|
221
|
+
table.add_column("Provider", style="green")
|
|
222
|
+
table.add_column("Organization", style="blue")
|
|
223
|
+
table.add_column("Name", style="yellow")
|
|
224
|
+
|
|
225
|
+
for provider in sorted(providers):
|
|
226
|
+
if "/" in provider:
|
|
227
|
+
org, name = provider.split("/", 1)
|
|
228
|
+
else:
|
|
229
|
+
org = "hashicorp"
|
|
230
|
+
name = provider
|
|
231
|
+
|
|
232
|
+
table.add_row(provider, org, name)
|
|
233
|
+
|
|
234
|
+
console.print(table)
|
|
235
|
+
console.print(f"\n[dim]Total: {len(providers)} providers[/dim]")
|
|
236
|
+
|
|
237
|
+
console.print("\n[bold]Usage:[/bold]")
|
|
238
|
+
console.print(f" nf generate providers --set {provider_set}")
|
|
239
|
+
console.print(f" nf generate providers --set {provider_set} --parallel")
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
@providers.command("search")
|
|
243
|
+
@click.argument("pattern")
|
|
244
|
+
@click.option(
|
|
245
|
+
"--json",
|
|
246
|
+
"output_json",
|
|
247
|
+
is_flag=True,
|
|
248
|
+
help="Output in JSON format",
|
|
249
|
+
)
|
|
250
|
+
def search_providers(pattern: str, output_json: bool) -> None:
|
|
251
|
+
"""Search for providers by name pattern.
|
|
252
|
+
|
|
253
|
+
Uses glob-style patterns to find matching providers.
|
|
254
|
+
|
|
255
|
+
Examples:
|
|
256
|
+
nf providers search aws
|
|
257
|
+
nf providers search "*google*"
|
|
258
|
+
nf providers search "hashicorp/*" --json
|
|
259
|
+
|
|
260
|
+
"""
|
|
261
|
+
try:
|
|
262
|
+
import fnmatch
|
|
263
|
+
|
|
264
|
+
from netherframe.generation.api import PROVIDER_SETS
|
|
265
|
+
except ImportError:
|
|
266
|
+
console.print("[bold red]Provider generation modules not available.[/bold red]")
|
|
267
|
+
console.print(
|
|
268
|
+
"Install generation dependencies: [dim]pip install netherframe.generation[/dim]",
|
|
269
|
+
)
|
|
270
|
+
sys.exit(1)
|
|
271
|
+
|
|
272
|
+
# Collect all providers
|
|
273
|
+
all_providers = set()
|
|
274
|
+
provider_sets_map = {}
|
|
275
|
+
|
|
276
|
+
for set_name, provider_list in PROVIDER_SETS.items():
|
|
277
|
+
for provider in provider_list:
|
|
278
|
+
all_providers.add(provider)
|
|
279
|
+
if provider not in provider_sets_map:
|
|
280
|
+
provider_sets_map[provider] = []
|
|
281
|
+
provider_sets_map[provider].append(set_name)
|
|
282
|
+
|
|
283
|
+
# Find matching providers
|
|
284
|
+
pattern_lower = pattern.lower()
|
|
285
|
+
matching = []
|
|
286
|
+
|
|
287
|
+
for provider in all_providers:
|
|
288
|
+
if fnmatch.fnmatch(provider.lower(), pattern_lower):
|
|
289
|
+
matching.append(provider)
|
|
290
|
+
|
|
291
|
+
if not matching:
|
|
292
|
+
console.print(f"[yellow]No providers match pattern '{pattern}'[/yellow]")
|
|
293
|
+
return
|
|
294
|
+
|
|
295
|
+
if output_json:
|
|
296
|
+
# JSON output
|
|
297
|
+
json_data = {
|
|
298
|
+
"pattern": pattern,
|
|
299
|
+
"matches": sorted(matching),
|
|
300
|
+
"count": len(matching),
|
|
301
|
+
"details": {provider: {"sets": sorted(provider_sets_map[provider])} for provider in sorted(matching)},
|
|
302
|
+
}
|
|
303
|
+
console.print(json.dumps(json_data, indent=2))
|
|
304
|
+
else:
|
|
305
|
+
# Rich table output
|
|
306
|
+
table = Table(title=f"Providers matching '{pattern}'")
|
|
307
|
+
table.add_column("Provider", style="green")
|
|
308
|
+
table.add_column("Available in Sets", style="blue")
|
|
309
|
+
|
|
310
|
+
for provider in sorted(matching):
|
|
311
|
+
sets = ", ".join(sorted(provider_sets_map[provider]))
|
|
312
|
+
table.add_row(provider, sets)
|
|
313
|
+
|
|
314
|
+
console.print(table)
|
|
315
|
+
console.print(f"\n[dim]Found {len(matching)} matching providers[/dim]")
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Shell command utilities for NF CLI."""
|
|
2
|
+
|
|
3
|
+
import click
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@click.command()
|
|
7
|
+
@click.argument("path", required=False)
|
|
8
|
+
def cd(path: str | None = None) -> None:
|
|
9
|
+
"""Change directory to stack location."""
|
|
10
|
+
target = path or "."
|
|
11
|
+
click.echo(f"Changing to directory '{target}' not yet implemented")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@click.command()
|
|
15
|
+
def shell() -> None:
|
|
16
|
+
"""Start an interactive shell with NF context."""
|
|
17
|
+
click.echo("Interactive shell not yet implemented")
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Display or export the agent guidance shipped with this nf CLI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from collections.abc import Callable
|
|
7
|
+
from importlib.resources import files
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import click
|
|
11
|
+
|
|
12
|
+
SKILL_FILES = ("SKILL.md", "agents/openai.yaml", "references/authoring.md", "references/execution.md", "references/migration.md")
|
|
13
|
+
TOPICS = {"overview": "SKILL.md", "authoring": "references/authoring.md", "execution": "references/execution.md", "migration": "references/migration.md"}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _read(relative: str) -> str:
|
|
17
|
+
return files("netherframe.cli").joinpath("skills", "netherframe", relative).read_text(encoding="utf-8")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _sections(text: str) -> list[tuple[str, int, int]]:
|
|
21
|
+
"""Section slug, heading level and line offset, ignoring fenced code blocks."""
|
|
22
|
+
result = []
|
|
23
|
+
seen: dict[str, int] = {}
|
|
24
|
+
fence = ""
|
|
25
|
+
for index, line in enumerate(text.splitlines(keepends=True)):
|
|
26
|
+
if match := re.match(r"^ {0,3}(`{3,}|~{3,})", line):
|
|
27
|
+
marker = match[1]
|
|
28
|
+
if not fence:
|
|
29
|
+
fence = marker
|
|
30
|
+
elif marker[0] == fence[0] and len(marker) >= len(fence):
|
|
31
|
+
fence = ""
|
|
32
|
+
continue
|
|
33
|
+
if fence:
|
|
34
|
+
continue
|
|
35
|
+
if match := re.match(r"^(#{2,6}) +(.+?) *#*\s*$", line):
|
|
36
|
+
slug = re.sub(r"[^a-z0-9]+", "-", match[2].lower()).strip("-")
|
|
37
|
+
count = seen.get(slug, 0)
|
|
38
|
+
seen[slug] = count + 1
|
|
39
|
+
result.append((f"{slug}-{count}" if count else slug, len(match[1]), index))
|
|
40
|
+
return result
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _filtered(text: str, excluded: set[str]) -> str:
|
|
44
|
+
lines = text.splitlines(keepends=True)
|
|
45
|
+
sections = _sections(text)
|
|
46
|
+
omitted: set[int] = set()
|
|
47
|
+
for position, (slug, level, start) in enumerate(sections):
|
|
48
|
+
if slug not in excluded:
|
|
49
|
+
continue
|
|
50
|
+
end = next((offset for _, other_level, offset in sections[position + 1 :] if other_level <= level), len(lines))
|
|
51
|
+
omitted.update(range(start, end))
|
|
52
|
+
return "".join(line for index, line in enumerate(lines) if index not in omitted)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _bundle(exclude: tuple[str, ...]) -> dict[str, str]:
|
|
56
|
+
content = {name: _read(name) for name in SKILL_FILES}
|
|
57
|
+
known = {topic for topic in TOPICS if topic != "overview"}
|
|
58
|
+
known.update(f"{topic}/{slug}" for topic, path in TOPICS.items() for slug, _, _ in _sections(content[path]))
|
|
59
|
+
unknown = set(exclude).difference(known)
|
|
60
|
+
if unknown:
|
|
61
|
+
raise click.UsageError(f"Unknown skill exclusion: {', '.join(sorted(unknown))}. Run 'nf skill sections' for valid IDs.")
|
|
62
|
+
if not exclude:
|
|
63
|
+
return content
|
|
64
|
+
for topic, path in TOPICS.items():
|
|
65
|
+
if topic in exclude:
|
|
66
|
+
content.pop(path)
|
|
67
|
+
else:
|
|
68
|
+
selected = {value.split("/", 1)[1] for value in exclude if value.startswith(topic + "/")}
|
|
69
|
+
content[path] = _filtered(content[path], selected)
|
|
70
|
+
# Each overview reference is a list item with its indented continuation.
|
|
71
|
+
lines = content["SKILL.md"].splitlines(keepends=True)
|
|
72
|
+
removed = False
|
|
73
|
+
kept = []
|
|
74
|
+
for line in lines:
|
|
75
|
+
if line.startswith("- "):
|
|
76
|
+
removed = any(f"]({TOPICS[topic]})" in line for topic in exclude if topic in TOPICS)
|
|
77
|
+
elif removed and line.strip() and not line.startswith((" ", "\t")):
|
|
78
|
+
removed = False
|
|
79
|
+
if not removed:
|
|
80
|
+
kept.append(line)
|
|
81
|
+
overview = "".join(kept)
|
|
82
|
+
overview = re.sub(r"^description:.*$", "description: Use the included Netherframe (nf) Python infrastructure guidance, scoped to this copy.", overview, count=1, flags=re.MULTILINE)
|
|
83
|
+
# Keep the same scope when the skill tells an agent to read or refresh it.
|
|
84
|
+
flags = " ".join(f"--exclude {value}" for value in dict.fromkeys(exclude))
|
|
85
|
+
overview = overview.replace("nf skill show", f"nf skill show {flags}").replace("nf skill install", f"nf skill install {flags}").replace("`nf skill`", f"`nf skill {flags}`")
|
|
86
|
+
overview += "\n## Scope of this copy\n\nOmitted sections: " + ", ".join(f"`{value}`" for value in dict.fromkeys(exclude)) + ". Preserve these exclusions when refreshing or exporting this skill.\n"
|
|
87
|
+
content["SKILL.md"] = overview
|
|
88
|
+
return content
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _exclusions(ctx: click.Context, exclude: tuple[str, ...]) -> tuple[str, ...]:
|
|
92
|
+
return tuple(dict.fromkeys((*ctx.meta.get("skill_exclusions", ()), *exclude)))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _exclude_option[F: Callable[..., object]](function: F) -> F:
|
|
96
|
+
return click.option("--exclude", multiple=True, metavar="SECTION", help="Omit a topic or topic/section ID; repeat to omit more. See 'nf skill sections'.")(function)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@click.group(invoke_without_command=True)
|
|
100
|
+
@_exclude_option
|
|
101
|
+
@click.pass_context
|
|
102
|
+
def skill(ctx: click.Context, exclude: tuple[str, ...]) -> None:
|
|
103
|
+
"""Read or install the bundled Netherframe skill for AI agents."""
|
|
104
|
+
ctx.meta["skill_exclusions"] = exclude
|
|
105
|
+
if ctx.invoked_subcommand is None:
|
|
106
|
+
click.echo(_bundle(exclude)["SKILL.md"], nl=False)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@skill.command("sections")
|
|
110
|
+
def sections() -> None:
|
|
111
|
+
"""List whole-topic and individual section IDs accepted by --exclude."""
|
|
112
|
+
for topic, path in TOPICS.items():
|
|
113
|
+
if topic != "overview":
|
|
114
|
+
click.echo(topic)
|
|
115
|
+
for slug, _, _ in _sections(_read(path)):
|
|
116
|
+
click.echo(f" {topic}/{slug}")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
@skill.command("show")
|
|
120
|
+
@click.option("--topic", type=click.Choice(tuple(TOPICS)), default="overview", show_default=True)
|
|
121
|
+
@_exclude_option
|
|
122
|
+
@click.pass_context
|
|
123
|
+
def show(ctx: click.Context, topic: str, exclude: tuple[str, ...]) -> None:
|
|
124
|
+
"""Print plain Markdown guidance without loading an app or provider."""
|
|
125
|
+
content = _bundle(_exclusions(ctx, exclude))
|
|
126
|
+
if TOPICS[topic] not in content:
|
|
127
|
+
raise click.UsageError(f"The requested topic '{topic}' is excluded.")
|
|
128
|
+
click.echo(content[TOPICS[topic]], nl=False)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@skill.command("install")
|
|
132
|
+
@click.option("--path", "destination", type=click.Path(path_type=Path), default=".agents/skills/netherframe", show_default=True, help="Destination skill directory")
|
|
133
|
+
@click.option("--force", is_flag=True, help="Replace bundled files in an existing skill directory; keep other files")
|
|
134
|
+
@_exclude_option
|
|
135
|
+
@click.pass_context
|
|
136
|
+
def install(ctx: click.Context, destination: Path, force: bool, exclude: tuple[str, ...]) -> None:
|
|
137
|
+
"""Copy the skill and its references into a project or agent skill directory."""
|
|
138
|
+
content = _bundle(_exclusions(ctx, exclude))
|
|
139
|
+
try:
|
|
140
|
+
if destination.is_symlink() or (destination.exists() and not destination.is_dir()):
|
|
141
|
+
raise click.ClickException(f"Skill destination must be a directory, not a file or symlink: {destination}")
|
|
142
|
+
if destination.exists() and not force:
|
|
143
|
+
raise click.ClickException(f"Skill directory already exists: {destination}. Use --force to replace bundled files.")
|
|
144
|
+
# Check collisions before changing any files, including under --force.
|
|
145
|
+
for name in SKILL_FILES:
|
|
146
|
+
target = destination / name
|
|
147
|
+
if target.is_symlink() or (target.exists() and not target.is_file()):
|
|
148
|
+
raise click.ClickException(f"Cannot replace a non-file skill entry: {target}")
|
|
149
|
+
for parent in target.parents:
|
|
150
|
+
if parent == destination:
|
|
151
|
+
break
|
|
152
|
+
if parent.is_symlink() or (parent.exists() and not parent.is_dir()):
|
|
153
|
+
raise click.ClickException(f"Cannot write through a non-directory skill entry: {parent}")
|
|
154
|
+
destination.mkdir(parents=True, exist_ok=force)
|
|
155
|
+
for name in set(SKILL_FILES).difference(content):
|
|
156
|
+
(destination / name).unlink(missing_ok=True)
|
|
157
|
+
for name, text in content.items():
|
|
158
|
+
target = destination / name
|
|
159
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
160
|
+
target.write_text(text, encoding="utf-8")
|
|
161
|
+
except OSError as error:
|
|
162
|
+
raise click.ClickException(f"Could not install Netherframe skill: {error}") from error
|
|
163
|
+
click.echo(f"Installed Netherframe skill in {destination}")
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
# Export is the same filesystem operation; keep install for existing callers.
|
|
167
|
+
skill.add_command(install, "export")
|