invar-tools 1.7.0__py3-none-any.whl → 1.7.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.
- invar/core/utils.py +3 -1
- invar/shell/claude_hooks.py +90 -0
- invar/shell/commands/init.py +303 -313
- invar/shell/commands/uninstall.py +145 -7
- invar/shell/contract_coverage.py +4 -1
- invar/shell/templates.py +35 -29
- invar/templates/config/pre-commit.yaml.jinja +2 -0
- {invar_tools-1.7.0.dist-info → invar_tools-1.7.1.dist-info}/METADATA +55 -45
- {invar_tools-1.7.0.dist-info → invar_tools-1.7.1.dist-info}/RECORD +14 -15
- invar/templates/pre-commit-config.yaml.template +0 -46
- {invar_tools-1.7.0.dist-info → invar_tools-1.7.1.dist-info}/WHEEL +0 -0
- {invar_tools-1.7.0.dist-info → invar_tools-1.7.1.dist-info}/entry_points.txt +0 -0
- {invar_tools-1.7.0.dist-info → invar_tools-1.7.1.dist-info}/licenses/LICENSE +0 -0
- {invar_tools-1.7.0.dist-info → invar_tools-1.7.1.dist-info}/licenses/LICENSE-GPL +0 -0
- {invar_tools-1.7.0.dist-info → invar_tools-1.7.1.dist-info}/licenses/NOTICE +0 -0
invar/shell/commands/init.py
CHANGED
|
@@ -2,108 +2,208 @@
|
|
|
2
2
|
Init command for Invar.
|
|
3
3
|
|
|
4
4
|
Shell module: handles project initialization.
|
|
5
|
-
DX-
|
|
6
|
-
DX-55: Unified idempotent init command with smart merge.
|
|
7
|
-
DX-56: Uses unified template sync engine for file generation.
|
|
8
|
-
DX-57: Added Claude Code hooks installation.
|
|
5
|
+
DX-70: Simplified init with interactive menus and safe merge behavior.
|
|
9
6
|
"""
|
|
10
7
|
|
|
11
8
|
from __future__ import annotations
|
|
12
9
|
|
|
13
|
-
import
|
|
14
|
-
import subprocess
|
|
10
|
+
import sys
|
|
15
11
|
from pathlib import Path
|
|
16
12
|
|
|
17
13
|
import typer
|
|
18
14
|
from returns.result import Failure, Success
|
|
19
15
|
from rich.console import Console
|
|
16
|
+
from rich.panel import Panel
|
|
20
17
|
|
|
21
18
|
from invar.core.sync_helpers import SyncConfig
|
|
22
|
-
from invar.
|
|
23
|
-
from invar.shell.claude_hooks import (
|
|
24
|
-
install_claude_hooks,
|
|
25
|
-
sync_claude_hooks,
|
|
26
|
-
)
|
|
27
|
-
from invar.shell.commands.merge import (
|
|
28
|
-
ProjectState,
|
|
29
|
-
detect_project_state,
|
|
30
|
-
)
|
|
19
|
+
from invar.shell.claude_hooks import install_claude_hooks
|
|
31
20
|
from invar.shell.commands.template_sync import sync_templates
|
|
32
21
|
from invar.shell.mcp_config import (
|
|
33
|
-
detect_available_methods,
|
|
34
22
|
generate_mcp_json,
|
|
35
|
-
get_method_by_name,
|
|
36
23
|
get_recommended_method,
|
|
37
24
|
)
|
|
38
|
-
from invar.shell.template_engine import generate_from_manifest
|
|
39
25
|
from invar.shell.templates import (
|
|
40
26
|
add_config,
|
|
41
27
|
create_directories,
|
|
42
|
-
detect_agent_configs,
|
|
43
28
|
install_hooks,
|
|
44
29
|
)
|
|
45
30
|
|
|
46
31
|
console = Console()
|
|
47
32
|
|
|
48
33
|
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
34
|
+
# =============================================================================
|
|
35
|
+
# File Categories (DX-70)
|
|
36
|
+
# =============================================================================
|
|
37
|
+
|
|
38
|
+
FILE_CATEGORIES: dict[str, list[tuple[str, str]]] = {
|
|
39
|
+
"required": [
|
|
40
|
+
("INVAR.md", "Protocol and contract rules"),
|
|
41
|
+
(".invar/", "Config, context, examples"),
|
|
42
|
+
],
|
|
43
|
+
"optional": [
|
|
44
|
+
(".pre-commit-config.yaml", "Verification before commit"),
|
|
45
|
+
("src/core/", "Pure logic directory"),
|
|
46
|
+
("src/shell/", "I/O operations directory"),
|
|
47
|
+
],
|
|
48
|
+
"claude": [
|
|
49
|
+
("CLAUDE.md", "Agent instructions"),
|
|
50
|
+
(".claude/skills/", "Workflow automation"),
|
|
51
|
+
(".claude/commands/", "User commands (/audit, /guard)"),
|
|
52
|
+
(".claude/hooks/", "Tool guidance (+ settings.local.json)"),
|
|
53
|
+
(".mcp.json", "MCP server config"),
|
|
54
|
+
],
|
|
55
|
+
"generic": [
|
|
56
|
+
("AGENT.md", "Universal agent instructions"),
|
|
57
|
+
],
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
AGENT_CONFIGS: dict[str, dict[str, str]] = {
|
|
61
|
+
"claude": {"name": "Claude Code", "category": "claude"},
|
|
62
|
+
"generic": {"name": "Other (AGENT.md)", "category": "generic"},
|
|
63
|
+
# Future: "cursor", "windsurf", etc.
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# =============================================================================
|
|
68
|
+
# Interactive Prompts (DX-70)
|
|
69
|
+
# =============================================================================
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _is_interactive() -> bool:
|
|
73
|
+
"""Check if running in an interactive terminal."""
|
|
74
|
+
return sys.stdin.isatty() and sys.stdout.isatty()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# @shell_orchestration: Style configuration for questionary UI library
|
|
78
|
+
def _get_prompt_style():
|
|
79
|
+
"""Get custom style for questionary prompts.
|
|
80
|
+
|
|
81
|
+
Simple design:
|
|
82
|
+
- Pointer (») indicates current row
|
|
83
|
+
- Checkbox (●/○) indicates selected state
|
|
84
|
+
- All text in default color, no reverse
|
|
55
85
|
"""
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
from questionary import Style
|
|
87
|
+
|
|
88
|
+
return Style([
|
|
89
|
+
("pointer", "fg:cyan bold"), # Pointer: cyan bold
|
|
90
|
+
("highlighted", "noreverse"), # Current row: no reverse
|
|
91
|
+
("selected", "noreverse"), # Selected items: no reverse
|
|
92
|
+
("text", "noreverse"), # Normal text: no reverse
|
|
93
|
+
])
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# @shell_complexity: Interactive prompt with cursor selection
|
|
97
|
+
def _prompt_agent_selection() -> list[str]:
|
|
98
|
+
"""Prompt user to select code agent using cursor navigation."""
|
|
99
|
+
import questionary
|
|
100
|
+
|
|
101
|
+
console.print("\n[bold]Select code agent:[/bold]")
|
|
102
|
+
console.print("[dim]Use arrow keys to move, enter to select[/dim]\n")
|
|
103
|
+
|
|
104
|
+
choices = [
|
|
105
|
+
questionary.Choice("Claude Code (recommended)", value="claude"),
|
|
106
|
+
questionary.Choice("Other (AGENT.md)", value="generic"),
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
selected = questionary.select(
|
|
110
|
+
"",
|
|
111
|
+
choices=choices,
|
|
112
|
+
instruction="",
|
|
113
|
+
style=_get_prompt_style(),
|
|
114
|
+
).ask()
|
|
115
|
+
|
|
116
|
+
# Handle Ctrl+C
|
|
117
|
+
if not selected:
|
|
118
|
+
return ["claude"] # Default to Claude Code
|
|
119
|
+
return [selected]
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
# @shell_complexity: Interactive file selection with cursor navigation
|
|
123
|
+
def _prompt_file_selection(agents: list[str]) -> dict[str, bool]:
|
|
124
|
+
"""Prompt user to select optional files using cursor navigation."""
|
|
125
|
+
import questionary
|
|
126
|
+
|
|
127
|
+
# Build available files
|
|
128
|
+
available: dict[str, list[tuple[str, str]]] = {
|
|
129
|
+
"optional": FILE_CATEGORIES["optional"],
|
|
130
|
+
}
|
|
131
|
+
for agent in agents:
|
|
132
|
+
config = AGENT_CONFIGS.get(agent)
|
|
133
|
+
if config:
|
|
134
|
+
category = config["category"]
|
|
135
|
+
available[category] = FILE_CATEGORIES.get(category, [])
|
|
136
|
+
|
|
137
|
+
# Show header
|
|
138
|
+
console.print("\n[bold]File Selection:[/bold]")
|
|
139
|
+
console.print("[dim]Existing files will be MERGED (your content preserved).[/dim]\n")
|
|
140
|
+
|
|
141
|
+
# Required files (always installed)
|
|
142
|
+
console.print("[bold]Required (always installed):[/bold]")
|
|
143
|
+
for file, desc in FILE_CATEGORIES["required"]:
|
|
144
|
+
console.print(f" [green]✓[/green] {file:30} {desc}")
|
|
145
|
+
|
|
146
|
+
console.print()
|
|
147
|
+
console.print("[dim]Use arrow keys to move, space to toggle, enter to confirm[/dim]\n")
|
|
148
|
+
|
|
149
|
+
# Build choices with categories as separators
|
|
150
|
+
choices: list[questionary.Choice | questionary.Separator] = []
|
|
151
|
+
file_list: list[str] = []
|
|
152
|
+
|
|
153
|
+
for category, files in available.items():
|
|
154
|
+
if category == "required":
|
|
155
|
+
continue
|
|
156
|
+
category_name = category.capitalize()
|
|
157
|
+
if category == "claude":
|
|
158
|
+
category_name = "Claude Code"
|
|
159
|
+
choices.append(questionary.Separator(f"── {category_name} ──"))
|
|
160
|
+
for file, desc in files:
|
|
161
|
+
choices.append(
|
|
162
|
+
questionary.Choice(f"{file:28} {desc}", value=file, checked=True)
|
|
163
|
+
)
|
|
164
|
+
file_list.append(file)
|
|
165
|
+
|
|
166
|
+
selected = questionary.checkbox(
|
|
167
|
+
"Select files to install:",
|
|
168
|
+
choices=choices,
|
|
169
|
+
instruction="",
|
|
170
|
+
style=_get_prompt_style(),
|
|
171
|
+
).ask()
|
|
172
|
+
|
|
173
|
+
# Handle Ctrl+C or empty result
|
|
174
|
+
if selected is None:
|
|
175
|
+
return dict.fromkeys(file_list, True) # Default: all selected
|
|
176
|
+
|
|
177
|
+
# Build result dict
|
|
178
|
+
return {f: f in selected for f in file_list}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _show_execution_output(
|
|
182
|
+
created: list[str],
|
|
183
|
+
merged: list[str],
|
|
184
|
+
skipped: list[str],
|
|
185
|
+
) -> None:
|
|
186
|
+
"""Display execution results."""
|
|
187
|
+
console.print()
|
|
188
|
+
for file in created:
|
|
189
|
+
console.print(f" [green]✓[/green] {file:30} [dim]created[/dim]")
|
|
190
|
+
for file in merged:
|
|
191
|
+
console.print(f" [cyan]↻[/cyan] {file:30} [dim]merged[/dim]")
|
|
192
|
+
for file in skipped:
|
|
193
|
+
console.print(f" [dim]○[/dim] {file:30} [dim]skipped[/dim]")
|
|
84
194
|
|
|
85
195
|
|
|
86
|
-
#
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
) -> None:
|
|
90
|
-
"""Configure MCP server with specified or detected method."""
|
|
91
|
-
import json
|
|
196
|
+
# =============================================================================
|
|
197
|
+
# MCP Configuration
|
|
198
|
+
# =============================================================================
|
|
92
199
|
|
|
93
|
-
# Determine method to use
|
|
94
|
-
if mcp_method:
|
|
95
|
-
config = get_method_by_name(mcp_method)
|
|
96
|
-
if config is None:
|
|
97
|
-
console.print(f"[yellow]Warning:[/yellow] Method '{mcp_method}' not available")
|
|
98
|
-
config = get_recommended_method()
|
|
99
|
-
console.print(f"[dim]Using fallback: {config.description}[/dim]")
|
|
100
|
-
else:
|
|
101
|
-
config = get_recommended_method()
|
|
102
200
|
|
|
103
|
-
|
|
104
|
-
|
|
201
|
+
# @shell_complexity: MCP config merge with existing file handling
|
|
202
|
+
def _configure_mcp(path: Path) -> bool:
|
|
203
|
+
"""Configure MCP server with recommended method."""
|
|
204
|
+
import json
|
|
105
205
|
|
|
106
|
-
|
|
206
|
+
config = get_recommended_method()
|
|
107
207
|
mcp_json_path = path / ".mcp.json"
|
|
108
208
|
mcp_content = generate_mcp_json(config)
|
|
109
209
|
|
|
@@ -111,310 +211,200 @@ def configure_mcp_with_method(
|
|
|
111
211
|
try:
|
|
112
212
|
existing = json.loads(mcp_json_path.read_text())
|
|
113
213
|
if "mcpServers" in existing and "invar" in existing.get("mcpServers", {}):
|
|
114
|
-
|
|
115
|
-
return
|
|
214
|
+
return False # Already configured
|
|
116
215
|
# Add invar to existing config
|
|
117
216
|
if "mcpServers" not in existing:
|
|
118
217
|
existing["mcpServers"] = {}
|
|
119
218
|
existing["mcpServers"]["invar"] = mcp_content["mcpServers"]["invar"]
|
|
120
219
|
mcp_json_path.write_text(json.dumps(existing, indent=2))
|
|
121
|
-
|
|
220
|
+
return True
|
|
122
221
|
except (json.JSONDecodeError, OSError):
|
|
123
|
-
|
|
222
|
+
return False
|
|
124
223
|
else:
|
|
125
224
|
mcp_json_path.write_text(json.dumps(mcp_content, indent=2))
|
|
126
|
-
|
|
225
|
+
return True
|
|
127
226
|
|
|
128
227
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
console.print("\n[bold]Available MCP methods:[/bold]")
|
|
133
|
-
for i, method in enumerate(methods):
|
|
134
|
-
marker = "[green]→[/green]" if i == 0 else " "
|
|
135
|
-
console.print(f" {marker} {method.method.value}: {method.description}")
|
|
228
|
+
# =============================================================================
|
|
229
|
+
# Main Init Command (DX-70)
|
|
230
|
+
# =============================================================================
|
|
136
231
|
|
|
137
232
|
|
|
138
|
-
# @shell_complexity:
|
|
233
|
+
# @shell_complexity: Main CLI entry point with interactive flow and file generation
|
|
139
234
|
def init(
|
|
140
|
-
path: Path = typer.Argument(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
),
|
|
144
|
-
mcp_method: str = typer.Option(
|
|
145
|
-
None,
|
|
146
|
-
"--mcp-method",
|
|
147
|
-
help="MCP execution method: uvx (recommended), command, or python",
|
|
148
|
-
),
|
|
149
|
-
dirs: bool = typer.Option(
|
|
150
|
-
None, "--dirs/--no-dirs", help="Create src/core and src/shell directories"
|
|
151
|
-
),
|
|
152
|
-
hooks: bool = typer.Option(
|
|
153
|
-
True, "--hooks/--no-hooks", help="Install pre-commit hooks (default: ON)"
|
|
154
|
-
),
|
|
155
|
-
claude_hooks: bool = typer.Option(
|
|
156
|
-
None, "--claude-hooks/--no-claude-hooks",
|
|
157
|
-
help="Install Claude Code hooks (default: ON when --claude, DX-57)"
|
|
235
|
+
path: Path = typer.Argument(
|
|
236
|
+
Path(),
|
|
237
|
+
help="Project root directory (default: current directory)",
|
|
158
238
|
),
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
False, "--yes", "-y", help="Accept defaults without prompting"
|
|
164
|
-
),
|
|
165
|
-
check: bool = typer.Option(
|
|
166
|
-
False, "--check", help="Preview changes without applying (DX-55)"
|
|
167
|
-
),
|
|
168
|
-
force: bool = typer.Option(
|
|
169
|
-
False, "--force", help="Update even if already current (DX-55)"
|
|
239
|
+
claude: bool = typer.Option(
|
|
240
|
+
False,
|
|
241
|
+
"--claude",
|
|
242
|
+
help="Auto-select Claude Code, skip all prompts",
|
|
170
243
|
),
|
|
171
|
-
|
|
172
|
-
False,
|
|
244
|
+
preview: bool = typer.Option(
|
|
245
|
+
False,
|
|
246
|
+
"--preview",
|
|
247
|
+
help="Show what would be done (dry run)",
|
|
173
248
|
),
|
|
174
249
|
) -> None:
|
|
175
250
|
"""
|
|
176
|
-
Initialize or update Invar configuration
|
|
251
|
+
Initialize or update Invar configuration.
|
|
177
252
|
|
|
178
|
-
DX-
|
|
179
|
-
It detects current state and does the right thing:
|
|
253
|
+
DX-70: Simplified init with interactive selection and safe merge.
|
|
180
254
|
|
|
181
255
|
\b
|
|
182
|
-
-
|
|
183
|
-
-
|
|
184
|
-
-
|
|
185
|
-
|
|
186
|
-
|
|
256
|
+
This command is safe - it always MERGES with existing files:
|
|
257
|
+
- File doesn't exist → Create
|
|
258
|
+
- File exists → Merge (update invar regions, preserve your content)
|
|
259
|
+
- Never overwrites user content
|
|
260
|
+
- Never deletes files
|
|
187
261
|
|
|
188
262
|
\b
|
|
189
|
-
|
|
190
|
-
- Otherwise: creates invar.toml
|
|
191
|
-
|
|
192
|
-
Use --check to preview changes without applying.
|
|
193
|
-
Use --force to update even if already current.
|
|
194
|
-
Use --reset to discard all user content (dangerous).
|
|
195
|
-
Use --claude to run 'claude /init' first.
|
|
196
|
-
Use --mcp-method to specify MCP execution method (uvx, command, python).
|
|
197
|
-
Use --dirs to always create directories, --no-dirs to skip.
|
|
198
|
-
Use --no-hooks to skip pre-commit hooks installation.
|
|
199
|
-
Use --no-claude-hooks to skip Claude Code hooks (DX-57).
|
|
200
|
-
Use --no-skills to skip .claude/skills/ creation (for Cursor users).
|
|
201
|
-
Use --yes to accept defaults without prompting.
|
|
263
|
+
For full reset, use: invar uninstall && invar init
|
|
202
264
|
"""
|
|
203
265
|
from invar import __version__
|
|
204
266
|
|
|
205
|
-
#
|
|
206
|
-
|
|
267
|
+
# Resolve path
|
|
268
|
+
if path == Path():
|
|
269
|
+
path = Path.cwd()
|
|
270
|
+
path = path.resolve()
|
|
271
|
+
|
|
272
|
+
# Header
|
|
273
|
+
if claude:
|
|
274
|
+
console.print(f"\n[bold]Invar v{__version__} - Quick Setup (Claude Code)[/bold]")
|
|
275
|
+
else:
|
|
276
|
+
console.print(f"\n[bold]Invar v{__version__} - Project Setup[/bold]")
|
|
277
|
+
console.print("=" * 45)
|
|
278
|
+
console.print("[dim]Existing files will be MERGED (your content preserved).[/dim]")
|
|
207
279
|
|
|
208
|
-
#
|
|
209
|
-
if
|
|
210
|
-
|
|
280
|
+
# Determine agents and files
|
|
281
|
+
if claude:
|
|
282
|
+
# Quick mode: use defaults
|
|
283
|
+
agents = ["claude"]
|
|
284
|
+
selected_files: dict[str, bool] = {}
|
|
285
|
+
for category in ["optional", "claude"]:
|
|
286
|
+
for file, _ in FILE_CATEGORIES.get(category, []):
|
|
287
|
+
selected_files[file] = True
|
|
288
|
+
else:
|
|
289
|
+
# Interactive mode
|
|
290
|
+
if not _is_interactive():
|
|
291
|
+
console.print("[yellow]Non-interactive terminal detected. Use --claude for quick setup.[/yellow]")
|
|
292
|
+
raise typer.Exit(1)
|
|
293
|
+
|
|
294
|
+
agents = _prompt_agent_selection()
|
|
295
|
+
selected_files = _prompt_file_selection(agents)
|
|
296
|
+
|
|
297
|
+
# Preview mode
|
|
298
|
+
if preview:
|
|
299
|
+
console.print("\n[bold]Preview - Would create/update:[/bold]")
|
|
300
|
+
console.print("\n[bold]Required:[/bold]")
|
|
301
|
+
for file, desc in FILE_CATEGORIES["required"]:
|
|
302
|
+
console.print(f" [green]✓[/green] {file:30} {desc}")
|
|
303
|
+
|
|
304
|
+
console.print("\n[bold]Selected:[/bold]")
|
|
305
|
+
for file, selected in selected_files.items():
|
|
306
|
+
if selected:
|
|
307
|
+
console.print(f" [green]✓[/green] {file}")
|
|
308
|
+
else:
|
|
309
|
+
console.print(f" [dim]○[/dim] {file} [dim](skipped)[/dim]")
|
|
310
|
+
|
|
311
|
+
console.print("\n[dim]Run without --preview to apply.[/dim]")
|
|
211
312
|
return
|
|
212
313
|
|
|
213
|
-
#
|
|
214
|
-
|
|
215
|
-
if not yes and not typer.confirm(
|
|
216
|
-
"[red]This will DELETE all user customizations. Continue?[/red]",
|
|
217
|
-
default=False,
|
|
218
|
-
):
|
|
219
|
-
console.print("[yellow]Cancelled[/yellow]")
|
|
220
|
-
return
|
|
221
|
-
# Fall through to full init with reset flag
|
|
222
|
-
state = ProjectState(
|
|
223
|
-
initialized=False,
|
|
224
|
-
claude_md_state=ClaudeMdState(state="absent"),
|
|
225
|
-
version="",
|
|
226
|
-
needs_update=True,
|
|
227
|
-
)
|
|
314
|
+
# Execute
|
|
315
|
+
console.print("\n[bold]Creating files...[/bold]")
|
|
228
316
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
if action == "none" and not force:
|
|
233
|
-
# DX-55: Check for missing required files before declaring "no changes needed"
|
|
234
|
-
missing_files = []
|
|
235
|
-
if skills:
|
|
236
|
-
skill_files = [
|
|
237
|
-
".claude/skills/develop/SKILL.md",
|
|
238
|
-
".claude/skills/investigate/SKILL.md",
|
|
239
|
-
".claude/skills/propose/SKILL.md",
|
|
240
|
-
".claude/skills/review/SKILL.md",
|
|
241
|
-
]
|
|
242
|
-
for skill_file in skill_files:
|
|
243
|
-
if not (path / skill_file).exists():
|
|
244
|
-
missing_files.append(skill_file)
|
|
245
|
-
|
|
246
|
-
if not missing_files:
|
|
247
|
-
console.print(f"[green]✓[/green] Invar v{__version__} configured (no changes needed)")
|
|
248
|
-
console.print("[dim]Use --force to refresh managed regions[/dim]")
|
|
249
|
-
return
|
|
250
|
-
else:
|
|
251
|
-
# Recreate missing files
|
|
252
|
-
console.print(f"[yellow]Detected:[/yellow] {len(missing_files)} missing file(s)")
|
|
253
|
-
result = generate_from_manifest(path, syntax="cli", files_to_generate=missing_files)
|
|
254
|
-
if isinstance(result, Success):
|
|
255
|
-
for generated_file in result.unwrap():
|
|
256
|
-
console.print(f"[green]Restored[/green] {generated_file}")
|
|
257
|
-
console.print(f"[green]✓[/green] Invar v{__version__} configured")
|
|
258
|
-
return
|
|
259
|
-
|
|
260
|
-
# DX-21B: Run claude /init if requested (before sync)
|
|
261
|
-
# DX-69: sync_templates() will merge claude's CLAUDE.md with invar template
|
|
262
|
-
if claude:
|
|
263
|
-
run_claude_init(path)
|
|
317
|
+
created: list[str] = []
|
|
318
|
+
merged: list[str] = []
|
|
319
|
+
skipped: list[str] = []
|
|
264
320
|
|
|
321
|
+
# Add config file (.invar/config.toml or pyproject.toml)
|
|
265
322
|
config_result = add_config(path, console)
|
|
266
323
|
if isinstance(config_result, Failure):
|
|
267
324
|
console.print(f"[red]Error:[/red] {config_result.failure()}")
|
|
268
325
|
raise typer.Exit(1)
|
|
269
|
-
config_added = config_result.unwrap()
|
|
270
|
-
|
|
271
|
-
# DX-56: Use unified sync engine for file generation
|
|
272
|
-
console.print("\n[bold]Creating Invar files...[/bold]")
|
|
273
326
|
|
|
274
|
-
#
|
|
275
|
-
|
|
327
|
+
# Ensure .invar directory exists
|
|
328
|
+
invar_dir = path / ".invar"
|
|
329
|
+
if not invar_dir.exists():
|
|
330
|
+
invar_dir.mkdir()
|
|
276
331
|
|
|
277
|
-
# Build skip patterns
|
|
332
|
+
# Build skip patterns based on selection
|
|
278
333
|
skip_patterns: list[str] = []
|
|
279
|
-
if not skills:
|
|
334
|
+
if not selected_files.get(".claude/skills/", True):
|
|
280
335
|
skip_patterns.append(".claude/skills/*")
|
|
336
|
+
if not selected_files.get(".claude/commands/", True):
|
|
337
|
+
skip_patterns.append(".claude/commands/*")
|
|
338
|
+
if not selected_files.get(".pre-commit-config.yaml", True):
|
|
339
|
+
skip_patterns.append(".pre-commit-config.yaml")
|
|
281
340
|
|
|
341
|
+
# Run template sync
|
|
282
342
|
sync_config = SyncConfig(
|
|
283
343
|
syntax="cli",
|
|
284
|
-
inject_project_additions=
|
|
285
|
-
force=
|
|
286
|
-
check=False,
|
|
287
|
-
reset=
|
|
344
|
+
inject_project_additions=(path / ".invar" / "project-additions.md").exists(),
|
|
345
|
+
force=False,
|
|
346
|
+
check=False,
|
|
347
|
+
reset=False,
|
|
288
348
|
skip_patterns=skip_patterns,
|
|
289
349
|
)
|
|
290
350
|
|
|
291
|
-
# DX-56: Run unified sync engine (handles DX-55 state detection internally)
|
|
292
351
|
result = sync_templates(path, sync_config)
|
|
293
|
-
if isinstance(result,
|
|
294
|
-
console.print(f"[yellow]Warning:[/yellow] {result.failure()}")
|
|
295
|
-
else:
|
|
352
|
+
if isinstance(result, Success):
|
|
296
353
|
report = result.unwrap()
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
for file in report.updated:
|
|
300
|
-
console.print(f"[cyan]Updated[/cyan] {file}")
|
|
301
|
-
for error in report.errors:
|
|
302
|
-
console.print(f"[yellow]Warning:[/yellow] {error}")
|
|
303
|
-
|
|
304
|
-
# Create .invar directory structure (for proposals template - not in manifest)
|
|
305
|
-
invar_dir = path / ".invar"
|
|
306
|
-
if not invar_dir.exists():
|
|
307
|
-
invar_dir.mkdir()
|
|
354
|
+
created.extend(report.created)
|
|
355
|
+
merged.extend(report.updated)
|
|
308
356
|
|
|
309
|
-
# Create proposals directory
|
|
357
|
+
# Create proposals directory
|
|
310
358
|
proposals_dir = invar_dir / "proposals"
|
|
311
359
|
if not proposals_dir.exists():
|
|
312
360
|
proposals_dir.mkdir()
|
|
313
361
|
from invar.shell.templates import copy_template
|
|
314
|
-
result = copy_template("proposal.md.template", proposals_dir, "TEMPLATE.md")
|
|
315
|
-
if isinstance(result, Success) and result.unwrap():
|
|
316
|
-
console.print("[green]Created[/green] .invar/proposals/TEMPLATE.md")
|
|
317
362
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
if
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
console.print(" [green]✓[/green] claude: already configured")
|
|
363
|
+
copy_template("proposal.md.template", proposals_dir, "TEMPLATE.md")
|
|
364
|
+
|
|
365
|
+
# Configure MCP if Claude selected
|
|
366
|
+
if "claude" in agents and selected_files.get(".mcp.json", True):
|
|
367
|
+
if _configure_mcp(path):
|
|
368
|
+
created.append(".mcp.json")
|
|
325
369
|
|
|
326
|
-
#
|
|
327
|
-
|
|
370
|
+
# Create directories if selected
|
|
371
|
+
if selected_files.get("src/core/", True):
|
|
372
|
+
create_directories(path, console)
|
|
373
|
+
|
|
374
|
+
# Install pre-commit hooks if selected
|
|
375
|
+
if selected_files.get(".pre-commit-config.yaml", True):
|
|
376
|
+
install_hooks(path, console)
|
|
328
377
|
|
|
329
|
-
#
|
|
330
|
-
if
|
|
331
|
-
|
|
378
|
+
# Install Claude hooks if selected
|
|
379
|
+
if "claude" in agents and selected_files.get(".claude/hooks/", True):
|
|
380
|
+
install_claude_hooks(path, console)
|
|
332
381
|
|
|
333
382
|
# Create MCP setup guide
|
|
334
383
|
mcp_setup = invar_dir / "mcp-setup.md"
|
|
335
384
|
if not mcp_setup.exists():
|
|
336
385
|
from invar.shell.templates import _MCP_SETUP_TEMPLATE
|
|
337
|
-
mcp_setup.write_text(_MCP_SETUP_TEMPLATE)
|
|
338
|
-
console.print("[green]Created[/green] .invar/mcp-setup.md (setup guide)")
|
|
339
386
|
|
|
340
|
-
|
|
341
|
-
if dirs is not False:
|
|
342
|
-
create_directories(path, console)
|
|
387
|
+
mcp_setup.write_text(_MCP_SETUP_TEMPLATE)
|
|
343
388
|
|
|
344
|
-
#
|
|
345
|
-
|
|
346
|
-
|
|
389
|
+
# Track skipped files
|
|
390
|
+
for file, selected in selected_files.items():
|
|
391
|
+
if not selected:
|
|
392
|
+
skipped.append(file)
|
|
347
393
|
|
|
348
|
-
#
|
|
349
|
-
|
|
350
|
-
should_install_claude_hooks = (
|
|
351
|
-
claude_hooks is True # Explicitly requested
|
|
352
|
-
or (claude_hooks is None and claude) # Default ON when --claude
|
|
353
|
-
)
|
|
354
|
-
should_skip_claude_hooks = claude_hooks is False
|
|
394
|
+
# Show results
|
|
395
|
+
_show_execution_output(created, merged, skipped)
|
|
355
396
|
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
install_claude_hooks(path, console)
|
|
359
|
-
elif not should_skip_claude_hooks:
|
|
360
|
-
# Check if hooks already installed and need sync
|
|
361
|
-
claude_hooks_dir = path / ".claude" / "hooks"
|
|
362
|
-
if (claude_hooks_dir / "invar.UserPromptSubmit.sh").exists():
|
|
363
|
-
# Sync existing hooks (idempotent update)
|
|
364
|
-
sync_claude_hooks(path, console)
|
|
365
|
-
|
|
366
|
-
if not config_added and not (path / "INVAR.md").exists():
|
|
367
|
-
console.print("[yellow]Invar already configured.[/yellow]")
|
|
368
|
-
|
|
369
|
-
# DX-55: Summary based on action taken
|
|
370
|
-
if action == "full_init":
|
|
371
|
-
console.print(f"\n[bold green]✓ Initialized Invar v{__version__}[/bold green]")
|
|
372
|
-
console.print("[dim]Note: If you run 'claude /init' later, just run 'invar init' again.[/dim]")
|
|
373
|
-
elif action == "recover":
|
|
374
|
-
console.print(f"\n[bold green]✓ Recovered Invar v{__version__}[/bold green]")
|
|
375
|
-
console.print("[dim]Review the merged content in CLAUDE.md[/dim]")
|
|
376
|
-
elif action == "update" or force:
|
|
377
|
-
console.print(f"\n[bold green]✓ Updated Invar v{__version__}[/bold green]")
|
|
378
|
-
console.print("[dim]Refreshed managed regions, preserved user content[/dim]")
|
|
379
|
-
else:
|
|
380
|
-
console.print("\n[bold green]Invar initialized successfully![/bold green]")
|
|
397
|
+
# Completion message
|
|
398
|
+
console.print(f"\n[bold green]✓ Initialized Invar v{__version__}[/bold green]")
|
|
381
399
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
console.print(f"Current version: [cyan]{state.version or 'N/A'}[/cyan]")
|
|
394
|
-
console.print(f"Needs update: [cyan]{state.needs_update}[/cyan]")
|
|
395
|
-
console.print(f"Action: [cyan]{state.action}[/cyan]\n")
|
|
396
|
-
|
|
397
|
-
match state.action:
|
|
398
|
-
case "none":
|
|
399
|
-
console.print("[green]No changes needed[/green]")
|
|
400
|
-
case "full_init":
|
|
401
|
-
console.print("Would create:")
|
|
402
|
-
console.print(" - INVAR.md")
|
|
403
|
-
console.print(" - CLAUDE.md")
|
|
404
|
-
console.print(" - .invar/context.md")
|
|
405
|
-
console.print(" - .claude/skills/")
|
|
406
|
-
console.print(" - .claude/hooks/ (DX-57, with --claude)")
|
|
407
|
-
console.print(" - .pre-commit-config.yaml")
|
|
408
|
-
case "update":
|
|
409
|
-
console.print("Would update:")
|
|
410
|
-
console.print(f" - CLAUDE.md (managed section v{state.version} → v{version})")
|
|
411
|
-
console.print(" - .claude/skills/* (refresh)")
|
|
412
|
-
console.print(" - .claude/hooks/* (refresh, if installed)")
|
|
413
|
-
case "recover":
|
|
414
|
-
console.print("[yellow]Would recover:[/yellow]")
|
|
415
|
-
console.print(" - CLAUDE.md (restore regions, preserve content)")
|
|
416
|
-
case "create":
|
|
417
|
-
console.print("Would create:")
|
|
418
|
-
console.print(" - CLAUDE.md")
|
|
419
|
-
|
|
420
|
-
console.print("\n[dim]Run 'invar init' to apply.[/dim]")
|
|
400
|
+
# Show tip for Claude users
|
|
401
|
+
if "claude" in agents:
|
|
402
|
+
console.print()
|
|
403
|
+
console.print(
|
|
404
|
+
Panel(
|
|
405
|
+
"[dim]If you run [bold]claude /init[/bold] afterward, "
|
|
406
|
+
"run [bold]invar init[/bold] again to restore protocol.[/dim]",
|
|
407
|
+
title="📌 Tip",
|
|
408
|
+
border_style="dim",
|
|
409
|
+
)
|
|
410
|
+
)
|