e567e5f717
- Updated bundled skills documentation to clarify the structure and usage across all platforms, ensuring consistency in skill root paths. - Introduced a new `inject-spec-context.py` hook for path-scoped spec context injection, improving the relevance of injected specs during file interactions. - Enhanced existing hooks to support workflow resolution, allowing for dynamic selection of workflows based on task context. - Added a command to manage workflow selections for active tasks, enabling better task management and workflow adherence. - Updated configuration options for spec injection, including character limits and refresh windows, to optimize performance and usability.
139 lines
4.2 KiB
Python
Executable File
139 lines
4.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Git and Session Context utilities.
|
|
|
|
Entry shim — delegates to session_context and packages_context.
|
|
|
|
Provides:
|
|
output_json - Output context in JSON format
|
|
output_text - Output context in text format
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
|
|
from .git import run_git
|
|
from .session_context import (
|
|
get_context_json,
|
|
get_context_text,
|
|
get_context_record_json,
|
|
get_context_text_record,
|
|
output_json,
|
|
output_text,
|
|
)
|
|
from .packages_context import (
|
|
get_context_packages_text,
|
|
get_context_packages_json,
|
|
)
|
|
from .paths import get_repo_root
|
|
from .spec_match import match_specs_for_file
|
|
from .trellis_config import read_trellis_config
|
|
from .workflow_phase import (
|
|
filter_platform,
|
|
get_phase_index,
|
|
get_step,
|
|
resolve_effective_platform,
|
|
)
|
|
|
|
# Backward-compatible alias — external modules import this name
|
|
_run_git_command = run_git
|
|
|
|
|
|
# =============================================================================
|
|
# Main Entry
|
|
# =============================================================================
|
|
|
|
def main() -> None:
|
|
"""CLI entry point."""
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(description="Get Session Context for AI Agent")
|
|
parser.add_argument(
|
|
"--json",
|
|
"-j",
|
|
action="store_true",
|
|
help="Output in JSON format (works with any --mode)",
|
|
)
|
|
parser.add_argument(
|
|
"--mode",
|
|
"-m",
|
|
choices=["default", "record", "packages", "phase", "spec"],
|
|
default="default",
|
|
help="Output mode: default (full context), record (for record-session), packages (package info only), phase (workflow step extraction), spec (specs governing a file)",
|
|
)
|
|
parser.add_argument(
|
|
"--step",
|
|
help="Step id for --mode phase, e.g. 1.1, 2.2. Omit to get the Phase Index.",
|
|
)
|
|
parser.add_argument(
|
|
"--platform",
|
|
help="Platform name for --mode phase, e.g. cursor, claude-code. Filters platform-tagged blocks.",
|
|
)
|
|
parser.add_argument(
|
|
"--file",
|
|
help="File path (absolute or repo-relative) for --mode spec. Lists spec files whose frontmatter paths match it.",
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.mode == "record":
|
|
if args.json:
|
|
print(json.dumps(get_context_record_json(), indent=2, ensure_ascii=False))
|
|
else:
|
|
print(get_context_text_record())
|
|
elif args.mode == "packages":
|
|
if args.json:
|
|
print(json.dumps(get_context_packages_json(), indent=2, ensure_ascii=False))
|
|
else:
|
|
print(get_context_packages_text())
|
|
elif args.mode == "phase":
|
|
content = get_step(args.step) if args.step else get_phase_index()
|
|
if not content.strip():
|
|
if args.step:
|
|
parser.exit(2, f"Step not found: {args.step}\n")
|
|
else:
|
|
parser.exit(2, "Phase Index section not found in workflow.md\n")
|
|
if args.platform:
|
|
effective = resolve_effective_platform(
|
|
args.platform, read_trellis_config()
|
|
)
|
|
content = filter_platform(content, effective)
|
|
print(content, end="")
|
|
elif args.mode == "spec":
|
|
if not args.file:
|
|
parser.error("--file is required with --mode spec")
|
|
matches = match_specs_for_file(get_repo_root(), args.file)
|
|
if args.json:
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"file": args.file,
|
|
"matches": [
|
|
{
|
|
"path": match.rel_path,
|
|
"description": match.description,
|
|
}
|
|
for match in matches
|
|
],
|
|
},
|
|
indent=2,
|
|
ensure_ascii=False,
|
|
)
|
|
)
|
|
elif matches:
|
|
for match in matches:
|
|
print(f"{match.rel_path} — {match.description or '(no description)'}")
|
|
else:
|
|
print(f"No spec files declare paths matching {args.file}.")
|
|
else:
|
|
if args.json:
|
|
output_json()
|
|
else:
|
|
output_text()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|