specify-cli 1.4.2__py3-none-any.whl → 1.4.4__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.
- specify_cli/__init__.py +46 -36
- specify_cli/_file_handles.py +33 -1
- specify_cli/_project.py +26 -12
- specify_cli/_version.py +6 -0
- specify_cli/agents.py +141 -37
- specify_cli/artifacts/_operation_info.py +1 -1
- specify_cli/artifacts/_operation_list.py +1 -1
- specify_cli/artifacts/mcp_info.py +1 -1
- specify_cli/artifacts/mcp_list.py +1 -1
- specify_cli/artifacts/models.py +1 -1
- specify_cli/authentication/http.py +6 -2
- specify_cli/bundles/project.py +13 -4
- specify_cli/command_init.py +50 -26
- specify_cli/core_pack/extensions/git/extension.yml +1 -1
- specify_cli/core_pack/extensions/git/scripts/bash/create-new-feature-branch.sh +1 -1
- specify_cli/core_pack/extensions/git/scripts/powershell/auto-commit.ps1 +3 -3
- specify_cli/core_pack/extensions/git/scripts/powershell/create-new-feature-branch.ps1 +12 -2
- specify_cli/core_pack/extensions/git/scripts/powershell/git-common.ps1 +6 -0
- specify_cli/core_pack/extensions/git/scripts/powershell/initialize-repo.ps1 +1 -1
- specify_cli/core_pack/extensions/git/scripts/python/auto_commit.py +37 -14
- specify_cli/core_pack/extensions/git/scripts/python/create_new_feature_branch.py +34 -7
- specify_cli/core_pack/extensions/git/scripts/python/git_common.py +15 -8
- specify_cli/core_pack/extensions/git/scripts/python/initialize_repo.py +24 -9
- specify_cli/core_pack/extensions/github/extension.yml +1 -1
- specify_cli/core_pack/extensions/github/scripts/powershell/resolve-tasks.ps1 +9 -1
- specify_cli/core_pack/scripts/bash/common.sh +34 -5
- specify_cli/core_pack/scripts/powershell/common.ps1 +67 -12
- specify_cli/core_pack/scripts/python/common.py +43 -12
- specify_cli/extensions/__init__.py +437 -132
- specify_cli/extensions/_command_update_transaction.py +36 -7
- specify_cli/extensions/_skill_resources.py +556 -0
- specify_cli/extensions/command_add.py +21 -7
- specify_cli/extensions/command_list.py +6 -3
- specify_cli/extensions/command_remove.py +5 -2
- specify_cli/file_helper.py +216 -13
- specify_cli/integrations/__init__.py +6 -0
- specify_cli/integrations/_file_changes.py +75 -0
- specify_cli/integrations/_helpers.py +4 -1
- specify_cli/integrations/_lifecycle.py +217 -52
- specify_cli/integrations/base.py +25 -3
- specify_cli/integrations/command_switch.py +3 -1
- specify_cli/integrations/command_upgrade.py +101 -92
- specify_cli/integrations/copilot/__init__.py +3 -1
- specify_cli/integrations/forge/__init__.py +3 -1
- specify_cli/integrations/generic/__init__.py +48 -2
- specify_cli/integrations/hermes/__init__.py +4 -1
- specify_cli/integrations/installer.py +4 -0
- specify_cli/integrations/manifest.py +23 -6
- specify_cli/integrations/rovodev/__init__.py +3 -1
- specify_cli/markdown_sections.py +230 -0
- specify_cli/presets/_manager_skills.py +64 -12
- specify_cli/presets/_manifest.py +32 -2
- specify_cli/presets/_resolver.py +96 -56
- specify_cli/presets/command_add.py +6 -6
- specify_cli/presets/command_resolve.py +9 -1
- specify_cli/shared_infra.py +44 -21
- specify_cli/workflows/engine.py +6 -5
- specify_cli/workflows/step/github/__init__.py +10 -3
- {specify_cli-1.4.2.dist-info → specify_cli-1.4.4.dist-info}/METADATA +1 -1
- {specify_cli-1.4.2.dist-info → specify_cli-1.4.4.dist-info}/RECORD +63 -61
- {specify_cli-1.4.2.dist-info → specify_cli-1.4.4.dist-info}/WHEEL +0 -0
- {specify_cli-1.4.2.dist-info → specify_cli-1.4.4.dist-info}/entry_points.txt +0 -0
- {specify_cli-1.4.2.dist-info → specify_cli-1.4.4.dist-info}/licenses/LICENSE +0 -0
specify_cli/__init__.py
CHANGED
|
@@ -29,6 +29,7 @@ Or install globally:
|
|
|
29
29
|
|
|
30
30
|
import os
|
|
31
31
|
import sys
|
|
32
|
+
from collections.abc import Iterable
|
|
32
33
|
from pathlib import Path
|
|
33
34
|
|
|
34
35
|
import typer
|
|
@@ -213,46 +214,55 @@ def _install_shared_infra_or_exit(
|
|
|
213
214
|
raise typer.Exit(1)
|
|
214
215
|
|
|
215
216
|
|
|
216
|
-
def ensure_executable_scripts(
|
|
217
|
-
|
|
217
|
+
def ensure_executable_scripts(
|
|
218
|
+
project_path: Path, tracker: StepTracker | None = None, *, files: Iterable[Path] | None = None,
|
|
219
|
+
) -> None:
|
|
220
|
+
"""Set execute bits on shebang shell scripts, scanning .specify by default."""
|
|
218
221
|
if os.name == "nt":
|
|
219
222
|
return # Windows: skip silently
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
223
|
+
from .integrations._file_changes import changing_file
|
|
224
|
+
from .integrations.installer import IntegrationInstallError
|
|
225
|
+
|
|
226
|
+
if files is None:
|
|
227
|
+
scan_roots = [
|
|
228
|
+
project_path / ".specify" / "scripts",
|
|
229
|
+
project_path / ".specify" / "extensions",
|
|
230
|
+
]
|
|
231
|
+
files = (script for root in scan_roots if root.is_dir() for script in root.rglob("*.sh"))
|
|
224
232
|
failures: list[str] = []
|
|
225
233
|
updated = 0
|
|
226
|
-
for
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
234
|
+
for script in files:
|
|
235
|
+
try:
|
|
236
|
+
if script.suffix != ".sh" or script.is_symlink() or not script.is_file():
|
|
237
|
+
continue
|
|
230
238
|
try:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
new_mode |= 0o100
|
|
239
|
+
with script.open("rb") as f:
|
|
240
|
+
if f.read(2) != b"#!":
|
|
241
|
+
continue
|
|
242
|
+
except Exception:
|
|
243
|
+
continue
|
|
244
|
+
st = script.stat()
|
|
245
|
+
mode = st.st_mode
|
|
246
|
+
if mode & 0o111:
|
|
247
|
+
continue
|
|
248
|
+
new_mode = mode
|
|
249
|
+
if mode & 0o400:
|
|
250
|
+
new_mode |= 0o100
|
|
251
|
+
if mode & 0o040:
|
|
252
|
+
new_mode |= 0o010
|
|
253
|
+
if mode & 0o004:
|
|
254
|
+
new_mode |= 0o001
|
|
255
|
+
if not (new_mode & 0o100):
|
|
256
|
+
new_mode |= 0o100
|
|
257
|
+
# Journalled, so a rolled-back upgrade restores the old mode.
|
|
258
|
+
with changing_file(script):
|
|
252
259
|
os.chmod(script, new_mode)
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
260
|
+
updated += 1
|
|
261
|
+
except IntegrationInstallError:
|
|
262
|
+
# The upgrade journal refused the change; fail the operation.
|
|
263
|
+
raise
|
|
264
|
+
except Exception as e:
|
|
265
|
+
failures.append(f"{_display_project_path(project_path, script)}: {e}")
|
|
256
266
|
if tracker:
|
|
257
267
|
detail = f"{updated} updated" + (f", {len(failures)} failed" if failures else "")
|
|
258
268
|
tracker.add("chmod", "Set script permissions recursively")
|
|
@@ -448,10 +458,10 @@ def _require_specify_project(*, load_integrations: bool = False) -> Path:
|
|
|
448
458
|
from ._project import ProjectResolutionError, preflight_project_policy, render_project_error
|
|
449
459
|
|
|
450
460
|
try:
|
|
451
|
-
preflight_project_policy(project_root)
|
|
461
|
+
marker_present = preflight_project_policy(project_root)
|
|
452
462
|
except ProjectResolutionError as exc:
|
|
453
463
|
render_project_error(exc)
|
|
454
|
-
if
|
|
464
|
+
if marker_present:
|
|
455
465
|
if load_integrations:
|
|
456
466
|
from .integrations.installer import IntegrationInstallError, load_installed_integrations
|
|
457
467
|
|
specify_cli/_file_handles.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Private platform
|
|
1
|
+
"""Private platform primitives for confined filesystem operations."""
|
|
2
2
|
|
|
3
3
|
from collections.abc import Iterator
|
|
4
4
|
from contextlib import contextmanager
|
|
@@ -7,6 +7,7 @@ import os
|
|
|
7
7
|
import secrets
|
|
8
8
|
import stat
|
|
9
9
|
import struct
|
|
10
|
+
import sys
|
|
10
11
|
import tempfile
|
|
11
12
|
from pathlib import Path, PureWindowsPath
|
|
12
13
|
from typing import Literal, NamedTuple
|
|
@@ -15,6 +16,37 @@ from typing import Literal, NamedTuple
|
|
|
15
16
|
_IdentityKind = Literal["fileid128", "legacy64"]
|
|
16
17
|
|
|
17
18
|
|
|
19
|
+
def rename_noreplace(source: Path, destination: Path) -> None:
|
|
20
|
+
"""Rename on the same filesystem without ever replacing the destination."""
|
|
21
|
+
if os.name == "nt":
|
|
22
|
+
os.rename(source, destination) # Windows does not enable replacement for os.rename.
|
|
23
|
+
return
|
|
24
|
+
|
|
25
|
+
unsupported = "Atomic no-clobber rename is unavailable on this platform"
|
|
26
|
+
if sys.platform not in {"darwin", "linux"}:
|
|
27
|
+
raise OSError(errno.ENOTSUP, unsupported, source, None, destination)
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
import ctypes
|
|
31
|
+
|
|
32
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
33
|
+
if sys.platform == "darwin":
|
|
34
|
+
rename = libc.renamex_np
|
|
35
|
+
rename.argtypes = [ctypes.c_char_p, ctypes.c_char_p, ctypes.c_uint]
|
|
36
|
+
args = (os.fsencode(source), os.fsencode(destination), 0x4) # RENAME_EXCL
|
|
37
|
+
else:
|
|
38
|
+
rename = libc.renameat2
|
|
39
|
+
rename.argtypes = [ctypes.c_int, ctypes.c_char_p, ctypes.c_int, ctypes.c_char_p, ctypes.c_uint]
|
|
40
|
+
args = (-100, os.fsencode(source), -100, os.fsencode(destination), 1) # AT_FDCWD, RENAME_NOREPLACE
|
|
41
|
+
except (ImportError, AttributeError) as exc:
|
|
42
|
+
raise OSError(errno.ENOTSUP, unsupported, source, None, destination) from exc
|
|
43
|
+
|
|
44
|
+
rename.restype = ctypes.c_int
|
|
45
|
+
if rename(*args) != 0:
|
|
46
|
+
error = ctypes.get_errno()
|
|
47
|
+
raise OSError(error, os.strerror(error), source, None, destination)
|
|
48
|
+
|
|
49
|
+
|
|
18
50
|
class _WindowsFileIdentity(NamedTuple):
|
|
19
51
|
kind: _IdentityKind
|
|
20
52
|
volume: int
|
specify_cli/_project.py
CHANGED
|
@@ -12,7 +12,7 @@ from rich.markup import escape
|
|
|
12
12
|
|
|
13
13
|
from ._console import err_console
|
|
14
14
|
from ._file_policy import ProjectPolicyError, project_files
|
|
15
|
-
from .file_helper import FileHelper
|
|
15
|
+
from .file_helper import FileHelper, FileHelperError, SymlinkDeniedError
|
|
16
16
|
|
|
17
17
|
try:
|
|
18
18
|
from typer._click.globals import get_current_context
|
|
@@ -37,12 +37,16 @@ def _resolve_init_dir_override_unrendered() -> Path | None:
|
|
|
37
37
|
raise ProjectResolutionError(
|
|
38
38
|
f"Cannot resolve SPECIFY_INIT_DIR '{raw}': {exc}"
|
|
39
39
|
) from exc
|
|
40
|
-
|
|
40
|
+
try:
|
|
41
|
+
with FileHelper(init_root):
|
|
42
|
+
pass
|
|
43
|
+
except (FileNotFoundError, NotADirectoryError) as exc:
|
|
41
44
|
raise ProjectResolutionError(
|
|
42
45
|
f"SPECIFY_INIT_DIR does not point to an existing directory: {raw}"
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
) from exc
|
|
47
|
+
except (OSError, FileHelperError, RuntimeError) as exc:
|
|
48
|
+
raise ProjectResolutionError(f"Cannot resolve SPECIFY_INIT_DIR '{raw}': {exc}") from exc
|
|
49
|
+
if not preflight_project_policy(init_root):
|
|
46
50
|
raise ProjectResolutionError(
|
|
47
51
|
"SPECIFY_INIT_DIR is not a Spec Kit project "
|
|
48
52
|
f"(no .specify/ directory): {init_root}"
|
|
@@ -50,20 +54,31 @@ def _resolve_init_dir_override_unrendered() -> Path | None:
|
|
|
50
54
|
return init_root
|
|
51
55
|
|
|
52
56
|
|
|
53
|
-
def preflight_project_policy(project_root: Path) ->
|
|
54
|
-
"""Validate
|
|
57
|
+
def preflight_project_policy(project_root: Path) -> bool:
|
|
58
|
+
"""Validate policy and report marker presence without printing or caching."""
|
|
55
59
|
try:
|
|
56
|
-
project_files(project_root)
|
|
60
|
+
with project_files(project_root):
|
|
61
|
+
pass
|
|
57
62
|
except ProjectPolicyError as exc:
|
|
58
63
|
marker = project_root / ".specify"
|
|
59
|
-
|
|
64
|
+
try:
|
|
65
|
+
with FileHelper(project_root) as files:
|
|
66
|
+
files.directory_exists(".specify")
|
|
67
|
+
except SymlinkDeniedError:
|
|
60
68
|
raise ProjectResolutionError(
|
|
61
69
|
f"Refusing to use symlinked .specify path: {marker}. {exc}"
|
|
62
70
|
) from exc
|
|
63
|
-
|
|
71
|
+
except NotADirectoryError:
|
|
64
72
|
raise ProjectResolutionError(
|
|
65
73
|
f"Not a Spec Kit project: .specify path exists but is not a directory: {marker}"
|
|
66
74
|
) from exc
|
|
75
|
+
except (OSError, FileHelperError, RuntimeError):
|
|
76
|
+
pass # Keep the original policy failure when the marker cannot be classified.
|
|
77
|
+
raise ProjectResolutionError(str(exc)) from exc
|
|
78
|
+
try:
|
|
79
|
+
with FileHelper(project_root) as files:
|
|
80
|
+
return files.directory_exists(".specify")
|
|
81
|
+
except (OSError, FileHelperError, RuntimeError) as exc:
|
|
67
82
|
raise ProjectResolutionError(str(exc)) from exc
|
|
68
83
|
|
|
69
84
|
|
|
@@ -107,8 +122,7 @@ def resolve_specify_project_root() -> Path:
|
|
|
107
122
|
if override is not None:
|
|
108
123
|
return override
|
|
109
124
|
project_root = Path.cwd()
|
|
110
|
-
preflight_project_policy(project_root)
|
|
111
|
-
if not (project_root / ".specify").is_dir():
|
|
125
|
+
if not preflight_project_policy(project_root):
|
|
112
126
|
raise ProjectResolutionError("Not a Spec Kit project (no .specify/ directory)")
|
|
113
127
|
return project_root
|
|
114
128
|
|
specify_cli/_version.py
CHANGED
|
@@ -639,6 +639,8 @@ def _detect_install_method(
|
|
|
639
639
|
[uv_bin, "tool", "list"],
|
|
640
640
|
capture_output=True,
|
|
641
641
|
text=True,
|
|
642
|
+
encoding="utf-8",
|
|
643
|
+
errors="replace",
|
|
642
644
|
timeout=_TIER3_REGISTRY_TIMEOUT_SECS,
|
|
643
645
|
env=_scrubbed_env(),
|
|
644
646
|
check=False,
|
|
@@ -663,6 +665,8 @@ def _detect_install_method(
|
|
|
663
665
|
[pipx_bin, "list", "--json"],
|
|
664
666
|
capture_output=True,
|
|
665
667
|
text=True,
|
|
668
|
+
encoding="utf-8",
|
|
669
|
+
errors="replace",
|
|
666
670
|
timeout=_TIER3_REGISTRY_TIMEOUT_SECS,
|
|
667
671
|
env=_scrubbed_env(),
|
|
668
672
|
check=False,
|
|
@@ -1039,6 +1043,8 @@ def _verify_upgrade(plan: _UpgradePlan) -> str | None:
|
|
|
1039
1043
|
check=False,
|
|
1040
1044
|
capture_output=True,
|
|
1041
1045
|
text=True,
|
|
1046
|
+
encoding="utf-8",
|
|
1047
|
+
errors="replace",
|
|
1042
1048
|
timeout=_VERIFY_TIMEOUT_SECS,
|
|
1043
1049
|
env=_scrubbed_env(),
|
|
1044
1050
|
)
|
specify_cli/agents.py
CHANGED
|
@@ -409,6 +409,7 @@ class CommandRegistrar:
|
|
|
409
409
|
extension_id: Optional[str] = None,
|
|
410
410
|
author: object = "github-spec-kit",
|
|
411
411
|
version: str | None = None,
|
|
412
|
+
rewrite_paths: bool = True,
|
|
412
413
|
) -> str:
|
|
413
414
|
"""Render a command override as a SKILL.md file.
|
|
414
415
|
|
|
@@ -429,7 +430,8 @@ class CommandRegistrar:
|
|
|
429
430
|
agent_config = self.AGENT_CONFIGS.get(agent_name, {})
|
|
430
431
|
if agent_config.get("extension") == "/SKILL.md":
|
|
431
432
|
body = self.resolve_skill_placeholders(
|
|
432
|
-
agent_name, frontmatter, body, project_root, extension_id=extension_id
|
|
433
|
+
agent_name, frontmatter, body, project_root, extension_id=extension_id,
|
|
434
|
+
rewrite_paths=rewrite_paths,
|
|
433
435
|
)
|
|
434
436
|
|
|
435
437
|
description = frontmatter.get(
|
|
@@ -443,7 +445,21 @@ class CommandRegistrar:
|
|
|
443
445
|
author=author,
|
|
444
446
|
version=version,
|
|
445
447
|
)
|
|
446
|
-
|
|
448
|
+
integration = None
|
|
449
|
+
try:
|
|
450
|
+
from specify_cli.integrations import get_integration
|
|
451
|
+
|
|
452
|
+
integration = get_integration(agent_name)
|
|
453
|
+
except (ImportError, ValueError, KeyError):
|
|
454
|
+
pass
|
|
455
|
+
|
|
456
|
+
self.apply_argument_hint(frontmatter, skill_frontmatter, integration)
|
|
457
|
+
skill_content = self.render_frontmatter(skill_frontmatter) + "\n" + body
|
|
458
|
+
if integration is not None and hasattr(
|
|
459
|
+
integration, "post_process_skill_content"
|
|
460
|
+
):
|
|
461
|
+
skill_content = integration.post_process_skill_content(skill_content)
|
|
462
|
+
return skill_content
|
|
447
463
|
|
|
448
464
|
@staticmethod
|
|
449
465
|
def build_skill_frontmatter(
|
|
@@ -505,6 +521,7 @@ class CommandRegistrar:
|
|
|
505
521
|
body: str,
|
|
506
522
|
project_root: Path,
|
|
507
523
|
extension_id: Optional[str] = None,
|
|
524
|
+
rewrite_paths: bool = True,
|
|
508
525
|
) -> str:
|
|
509
526
|
"""Resolve script placeholders for skills-backed agents."""
|
|
510
527
|
if not isinstance(frontmatter, dict):
|
|
@@ -537,9 +554,11 @@ class CommandRegistrar:
|
|
|
537
554
|
|
|
538
555
|
body = body.replace("{ARGS}", "$ARGUMENTS").replace("__AGENT__", agent_name)
|
|
539
556
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
557
|
+
if rewrite_paths:
|
|
558
|
+
return CommandRegistrar.rewrite_project_relative_paths(
|
|
559
|
+
body, extension_id=extension_id
|
|
560
|
+
)
|
|
561
|
+
return body
|
|
543
562
|
|
|
544
563
|
def _convert_argument_placeholder(
|
|
545
564
|
self, content: str, from_placeholder: str, to_placeholder: str
|
|
@@ -644,6 +663,17 @@ class CommandRegistrar:
|
|
|
644
663
|
return None
|
|
645
664
|
return agent
|
|
646
665
|
|
|
666
|
+
@staticmethod
|
|
667
|
+
def _resolve_command_resources(
|
|
668
|
+
source_dir: Path, commands: List[Dict[str, Any]],
|
|
669
|
+
) -> dict[str, list[str]]:
|
|
670
|
+
from .extensions._skill_resources import resolve_skill_resources
|
|
671
|
+
|
|
672
|
+
return {
|
|
673
|
+
cmd["name"]: resolve_skill_resources(source_dir, cmd["resources"])
|
|
674
|
+
for cmd in commands if cmd.get("resources")
|
|
675
|
+
}
|
|
676
|
+
|
|
647
677
|
@project_registration
|
|
648
678
|
def register_commands(
|
|
649
679
|
self,
|
|
@@ -654,10 +684,14 @@ class CommandRegistrar:
|
|
|
654
684
|
project_root: Path,
|
|
655
685
|
context_note: Optional[str] = None,
|
|
656
686
|
_resolved_dir: Optional[Path] = None,
|
|
687
|
+
_resolved_resources: Optional[dict[str, list[str]]] = None,
|
|
657
688
|
link_outputs: bool = False,
|
|
658
689
|
extension_id: Optional[str] = None,
|
|
659
690
|
author: object = "github-spec-kit",
|
|
660
691
|
version: str | None = None,
|
|
692
|
+
previous_resource_hashes: Optional[dict] = None,
|
|
693
|
+
resource_hashes: Optional[dict] = None,
|
|
694
|
+
overwrite_modified: bool = False,
|
|
661
695
|
) -> List[str]:
|
|
662
696
|
"""Register commands for a specific agent.
|
|
663
697
|
|
|
@@ -693,6 +727,17 @@ class CommandRegistrar:
|
|
|
693
727
|
commands_dir = _resolved_dir or self._resolve_agent_dir(
|
|
694
728
|
agent_name, agent_config, project_root,
|
|
695
729
|
)
|
|
730
|
+
resolved_resources: dict[str, list[str]] = {}
|
|
731
|
+
if extension_id and agent_config.get("extension") == "/SKILL.md":
|
|
732
|
+
resolved_resources = (
|
|
733
|
+
_resolved_resources
|
|
734
|
+
if _resolved_resources is not None
|
|
735
|
+
else self._resolve_command_resources(source_dir, commands)
|
|
736
|
+
)
|
|
737
|
+
if resolved_resources and resource_hashes is None:
|
|
738
|
+
raise ValueError(
|
|
739
|
+
"resource_hashes is required when registering commands with skill resources"
|
|
740
|
+
)
|
|
696
741
|
commands_dir.mkdir(parents=True, exist_ok=True)
|
|
697
742
|
|
|
698
743
|
registered = []
|
|
@@ -794,12 +839,13 @@ class CommandRegistrar:
|
|
|
794
839
|
frontmatter[key] = core_frontmatter[key]
|
|
795
840
|
frontmatter.pop("strategy", None)
|
|
796
841
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
frontmatter
|
|
802
|
-
|
|
842
|
+
copy_mode = bool(extension_id and registrar_writes_skills and cmd_info.get("resources"))
|
|
843
|
+
if not copy_mode:
|
|
844
|
+
if extension_id:
|
|
845
|
+
body = self.rewrite_extension_paths(body, extension_id, source_root)
|
|
846
|
+
frontmatter = self._adjust_script_paths(
|
|
847
|
+
frontmatter, extension_id=extension_id
|
|
848
|
+
)
|
|
803
849
|
|
|
804
850
|
for key in agent_config.get("strip_frontmatter_keys", []):
|
|
805
851
|
frontmatter.pop(key, None)
|
|
@@ -847,6 +893,7 @@ class CommandRegistrar:
|
|
|
847
893
|
extension_id=extension_id,
|
|
848
894
|
author=author,
|
|
849
895
|
version=version,
|
|
896
|
+
rewrite_paths=not copy_mode,
|
|
850
897
|
)
|
|
851
898
|
elif agent_config["format"] == "markdown":
|
|
852
899
|
body = self.resolve_skill_placeholders(
|
|
@@ -913,6 +960,16 @@ class CommandRegistrar:
|
|
|
913
960
|
self.write_copilot_prompt(project_root, cmd_name)
|
|
914
961
|
|
|
915
962
|
registered.append(cmd_name)
|
|
963
|
+
if copy_mode:
|
|
964
|
+
from .extensions._skill_resources import deliver_skill_resources
|
|
965
|
+
|
|
966
|
+
assert resource_hashes is not None
|
|
967
|
+
deliver_skill_resources(
|
|
968
|
+
project_root, extension_id, commands_dir, output_name, source_dir,
|
|
969
|
+
resolved_resources[cmd_name], previous_resource_hashes or {},
|
|
970
|
+
resource_hashes,
|
|
971
|
+
overwrite_modified=overwrite_modified,
|
|
972
|
+
)
|
|
916
973
|
|
|
917
974
|
for alias in aliases:
|
|
918
975
|
alias_output_name = self._compute_output_name(
|
|
@@ -940,6 +997,7 @@ class CommandRegistrar:
|
|
|
940
997
|
extension_id=extension_id,
|
|
941
998
|
author=author,
|
|
942
999
|
version=version,
|
|
1000
|
+
rewrite_paths=not copy_mode,
|
|
943
1001
|
)
|
|
944
1002
|
elif agent_config["format"] == "markdown":
|
|
945
1003
|
alias_output = self.render_markdown_command(
|
|
@@ -975,6 +1033,7 @@ class CommandRegistrar:
|
|
|
975
1033
|
extension_id=extension_id,
|
|
976
1034
|
author=author,
|
|
977
1035
|
version=version,
|
|
1036
|
+
rewrite_paths=not copy_mode,
|
|
978
1037
|
)
|
|
979
1038
|
|
|
980
1039
|
alias_file = (
|
|
@@ -998,6 +1057,14 @@ class CommandRegistrar:
|
|
|
998
1057
|
if agent_name == "copilot":
|
|
999
1058
|
self.write_copilot_prompt(project_root, alias)
|
|
1000
1059
|
registered.append(alias)
|
|
1060
|
+
if copy_mode:
|
|
1061
|
+
assert resource_hashes is not None
|
|
1062
|
+
deliver_skill_resources(
|
|
1063
|
+
project_root, extension_id, commands_dir, alias_output_name, source_dir,
|
|
1064
|
+
resolved_resources[cmd_name], previous_resource_hashes or {},
|
|
1065
|
+
resource_hashes,
|
|
1066
|
+
overwrite_modified=overwrite_modified,
|
|
1067
|
+
)
|
|
1001
1068
|
|
|
1002
1069
|
return registered
|
|
1003
1070
|
|
|
@@ -1134,6 +1201,9 @@ class CommandRegistrar:
|
|
|
1134
1201
|
only_agent: Optional[str] = None,
|
|
1135
1202
|
author: object = "github-spec-kit",
|
|
1136
1203
|
version: str | None = None,
|
|
1204
|
+
previous_resource_hashes: Optional[dict] = None,
|
|
1205
|
+
resource_hashes: Optional[dict] = None,
|
|
1206
|
+
overwrite_modified: bool = False,
|
|
1137
1207
|
) -> Dict[str, List[str]]:
|
|
1138
1208
|
"""Register commands for all detected agents in the project.
|
|
1139
1209
|
|
|
@@ -1176,6 +1246,7 @@ class CommandRegistrar:
|
|
|
1176
1246
|
active_skills_dir = self._resolve_agent_dir(
|
|
1177
1247
|
active_skills_agent, active_skills_config, project_root,
|
|
1178
1248
|
)
|
|
1249
|
+
targets: list[tuple[str, dict[str, Any], Path, bool]] = []
|
|
1179
1250
|
active_created_skills_dir: Optional[Path] = None
|
|
1180
1251
|
for agent_name, agent_config in self.AGENT_CONFIGS.items():
|
|
1181
1252
|
if only_agent is not None and agent_name != only_agent:
|
|
@@ -1249,32 +1320,52 @@ class CommandRegistrar:
|
|
|
1249
1320
|
) or register_missing_active_skills_agent
|
|
1250
1321
|
|
|
1251
1322
|
if should_register:
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1323
|
+
targets.append((
|
|
1324
|
+
agent_name,
|
|
1325
|
+
agent_config,
|
|
1326
|
+
agent_dir,
|
|
1327
|
+
register_missing_active_skills_agent,
|
|
1328
|
+
))
|
|
1329
|
+
|
|
1330
|
+
resolved_resources: Optional[dict[str, list[str]]] = None
|
|
1331
|
+
if extension_id and any(
|
|
1332
|
+
cfg.get("extension") == "/SKILL.md" for _, cfg, _, _ in targets
|
|
1333
|
+
):
|
|
1334
|
+
resolved_resources = self._resolve_command_resources(
|
|
1335
|
+
source_dir, commands,
|
|
1336
|
+
)
|
|
1337
|
+
if resolved_resources and resource_hashes is None:
|
|
1338
|
+
raise ValueError(
|
|
1339
|
+
"resource_hashes is required when registering commands with skill resources"
|
|
1340
|
+
)
|
|
1341
|
+
|
|
1342
|
+
for agent_name, _agent_config, agent_dir, register_missing_active_skills_agent in targets:
|
|
1343
|
+
try:
|
|
1344
|
+
registered = self.register_commands(
|
|
1345
|
+
agent_name,
|
|
1346
|
+
commands,
|
|
1347
|
+
source_id,
|
|
1348
|
+
source_dir,
|
|
1349
|
+
project_root,
|
|
1350
|
+
context_note=context_note,
|
|
1351
|
+
_resolved_dir=agent_dir,
|
|
1352
|
+
_resolved_resources=resolved_resources,
|
|
1353
|
+
link_outputs=link_outputs,
|
|
1354
|
+
extension_id=extension_id,
|
|
1355
|
+
author=author,
|
|
1356
|
+
version=version,
|
|
1357
|
+
previous_resource_hashes=previous_resource_hashes,
|
|
1358
|
+
resource_hashes=resource_hashes,
|
|
1359
|
+
overwrite_modified=overwrite_modified,
|
|
1360
|
+
)
|
|
1361
|
+
if registered:
|
|
1362
|
+
results[agent_name] = registered
|
|
1363
|
+
except ValueError:
|
|
1364
|
+
continue
|
|
1365
|
+
except OSError:
|
|
1366
|
+
if register_missing_active_skills_agent:
|
|
1273
1367
|
continue
|
|
1274
|
-
|
|
1275
|
-
if register_missing_active_skills_agent:
|
|
1276
|
-
continue
|
|
1277
|
-
raise
|
|
1368
|
+
raise
|
|
1278
1369
|
|
|
1279
1370
|
return results
|
|
1280
1371
|
|
|
@@ -1358,7 +1449,8 @@ class CommandRegistrar:
|
|
|
1358
1449
|
return results
|
|
1359
1450
|
|
|
1360
1451
|
def unregister_commands(
|
|
1361
|
-
self, registered_commands: Dict[str, List[str]], project_root: Path
|
|
1452
|
+
self, registered_commands: Dict[str, List[str]], project_root: Path,
|
|
1453
|
+
*, extension_id: Optional[str] = None, resource_hashes: Optional[dict] = None,
|
|
1362
1454
|
) -> None:
|
|
1363
1455
|
"""Remove previously registered command files from agent directories.
|
|
1364
1456
|
|
|
@@ -1372,6 +1464,18 @@ class CommandRegistrar:
|
|
|
1372
1464
|
project_root: Path to project root
|
|
1373
1465
|
"""
|
|
1374
1466
|
self._ensure_configs()
|
|
1467
|
+
if extension_id and resource_hashes is not None:
|
|
1468
|
+
from .extensions._skill_resources import retire_skill_resources
|
|
1469
|
+
|
|
1470
|
+
skill_names = set()
|
|
1471
|
+
for agent_name, cmd_names in registered_commands.items():
|
|
1472
|
+
config = self.AGENT_CONFIGS.get(agent_name, {})
|
|
1473
|
+
if config.get("extension") == "/SKILL.md":
|
|
1474
|
+
skill_names.update(
|
|
1475
|
+
self._compute_output_name(agent_name, name, config)
|
|
1476
|
+
for name in cmd_names if isinstance(name, str)
|
|
1477
|
+
)
|
|
1478
|
+
retire_skill_resources(project_root, extension_id, resource_hashes, skill_names)
|
|
1375
1479
|
for agent_name, cmd_names in registered_commands.items():
|
|
1376
1480
|
if agent_name not in self.AGENT_CONFIGS:
|
|
1377
1481
|
continue
|
|
@@ -326,7 +326,7 @@ def _convert_named_stack(
|
|
|
326
326
|
or not _is_optional_string(item["sourceId"])
|
|
327
327
|
or not _is_optional_string(item["presetId"])
|
|
328
328
|
or not _is_optional_string(item["presetName"])
|
|
329
|
-
or item["strategy"] not in ("replace", "wrap", "prepend", "append")
|
|
329
|
+
or item["strategy"] not in ("replace", "wrap", "prepend", "append", "replace-section")
|
|
330
330
|
or not isinstance(item["active"], bool)
|
|
331
331
|
or not isinstance(item["hidden"], bool)
|
|
332
332
|
or not _is_optional_string(item["manifestPath"])
|
|
@@ -24,7 +24,7 @@ class ArtifactListStackEntry(TypedDict):
|
|
|
24
24
|
sourceId: str | None
|
|
25
25
|
presetId: str | None
|
|
26
26
|
presetName: str | None
|
|
27
|
-
strategy: Literal["replace", "wrap", "prepend", "append"]
|
|
27
|
+
strategy: Literal["replace", "wrap", "prepend", "append", "replace-section"]
|
|
28
28
|
active: bool
|
|
29
29
|
hidden: bool
|
|
30
30
|
manifestPath: str | None
|
|
@@ -68,7 +68,7 @@ class ArtifactInfoStackEntryResult(BaseModel):
|
|
|
68
68
|
sourceId: str | None
|
|
69
69
|
presetId: str | None
|
|
70
70
|
presetName: str | None
|
|
71
|
-
strategy: Literal["replace", "wrap", "prepend", "append"]
|
|
71
|
+
strategy: Literal["replace", "wrap", "prepend", "append", "replace-section"]
|
|
72
72
|
active: bool
|
|
73
73
|
hidden: bool
|
|
74
74
|
manifestPath: str | None
|
|
@@ -72,7 +72,7 @@ class ArtifactListStackEntryResult(BaseModel):
|
|
|
72
72
|
sourceId: str | None
|
|
73
73
|
presetId: str | None
|
|
74
74
|
presetName: str | None
|
|
75
|
-
strategy: Literal["replace", "wrap", "prepend", "append"]
|
|
75
|
+
strategy: Literal["replace", "wrap", "prepend", "append", "replace-section"]
|
|
76
76
|
active: bool
|
|
77
77
|
hidden: bool
|
|
78
78
|
manifestPath: str | None
|
specify_cli/artifacts/models.py
CHANGED
|
@@ -8,7 +8,7 @@ from typing import Any, Literal
|
|
|
8
8
|
|
|
9
9
|
ArtifactKind = Literal["command", "template", "script", "hook"]
|
|
10
10
|
LayerName = Literal["project", "preset", "extension"]
|
|
11
|
-
Strategy = Literal["replace", "wrap", "prepend", "append"]
|
|
11
|
+
Strategy = Literal["replace", "wrap", "prepend", "append", "replace-section"]
|
|
12
12
|
HookLayerName = Literal["preset", "extension"]
|
|
13
13
|
|
|
14
14
|
|
|
@@ -263,8 +263,8 @@ def open_url(
|
|
|
263
263
|
try:
|
|
264
264
|
return opener.open(req, timeout=timeout)
|
|
265
265
|
except urllib.error.HTTPError as exc:
|
|
266
|
+
exc.close()
|
|
266
267
|
if exc.code in (401, 403):
|
|
267
|
-
exc.close()
|
|
268
268
|
continue # try next entry
|
|
269
269
|
raise
|
|
270
270
|
|
|
@@ -273,4 +273,8 @@ def open_url(
|
|
|
273
273
|
# No auth is attached on this path, so the handler's host list is empty:
|
|
274
274
|
# here it runs redirect validation only, not auth stripping.
|
|
275
275
|
opener = urllib.request.build_opener(_StripAuthOnRedirect((), redirect_validator))
|
|
276
|
-
|
|
276
|
+
try:
|
|
277
|
+
return opener.open(req, timeout=timeout)
|
|
278
|
+
except urllib.error.HTTPError as exc:
|
|
279
|
+
exc.close()
|
|
280
|
+
raise
|