helix-layer 4.3.0__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.
- helix_layer/__init__.py +1 -0
- helix_layer/auto.py +120 -0
- helix_layer/checks.py +74 -0
- helix_layer/cli.py +633 -0
- helix_layer/config.py +101 -0
- helix_layer/connectors/__init__.py +41 -0
- helix_layer/connectors/azure.py +210 -0
- helix_layer/connectors/base.py +150 -0
- helix_layer/connectors/github.py +120 -0
- helix_layer/connectors/jira.py +114 -0
- helix_layer/connectors/linear.py +93 -0
- helix_layer/git.py +64 -0
- helix_layer/memory.py +312 -0
- helix_layer/pipeline.py +202 -0
- helix_layer/prompt.py +120 -0
- helix_layer/review.py +73 -0
- helix_layer/runner.py +165 -0
- helix_layer/selftest.py +143 -0
- helix_layer/templates/CLAUDE.md +17 -0
- helix_layer/templates/claude/agents/explorer.md +8 -0
- helix_layer/templates/claude/agents/reviewer.md +8 -0
- helix_layer/templates/claude/commands/fix.md +9 -0
- helix_layer/templates/claude/commands/review.md +4 -0
- helix_layer/templates/claude/settings.json +63 -0
- helix_layer/templates/config.toml +27 -0
- helix_layer/usage.py +162 -0
- helix_layer-4.3.0.dist-info/METADATA +68 -0
- helix_layer-4.3.0.dist-info/RECORD +32 -0
- helix_layer-4.3.0.dist-info/WHEEL +5 -0
- helix_layer-4.3.0.dist-info/entry_points.txt +2 -0
- helix_layer-4.3.0.dist-info/licenses/LICENSE +1 -0
- helix_layer-4.3.0.dist-info/top_level.txt +1 -0
helix_layer/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "4.3.0"
|
helix_layer/auto.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"""Zero-command mode: Helix inside Claude Code's own chat (VS Code extension, terminal, desktop Code tab).
|
|
2
|
+
|
|
3
|
+
Claude Code hooks call these:
|
|
4
|
+
SessionStart -> refresh the project map (incremental, ~1s) and say what Helix adds
|
|
5
|
+
UserPromptSubmit -> enrich every raw prompt: ticket text, start-here files, past-bug lessons,
|
|
6
|
+
the right workflow (test-first for bugs) and how to finish (`helix ship`)
|
|
7
|
+
Stop -> real checks (see cli.hook_stop)
|
|
8
|
+
|
|
9
|
+
The injected context is kept small (a few hundred tokens) and is skipped for chit-chat,
|
|
10
|
+
so it saves far more exploration tokens than it costs.
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import re
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
from .config import load_config
|
|
19
|
+
from .connectors import ConnectorError, tracker_from
|
|
20
|
+
from .memory import Lessons, Retriever, build_map, load_map
|
|
21
|
+
from .prompt import STEPS, detect_intent
|
|
22
|
+
|
|
23
|
+
# "#4821", "ticket 4821", "bug 4821", "work item 4821", "AB#4821", "issue 12", "ENG-42"
|
|
24
|
+
TICKET_IN_TEXT = re.compile(
|
|
25
|
+
r"(?:\b(?:ticket|bug|story|task|issue|work\s*item|wi|item)\s*#?\s*(\d{1,7})\b)"
|
|
26
|
+
r"|(?:(?:AB)?#(\d{1,7})\b)"
|
|
27
|
+
r"|(?:\b([A-Z][A-Z0-9]{1,9}-\d{1,6})\b)", re.I)
|
|
28
|
+
SMALL_TALK = re.compile(r"^\s*(hi|hello|hey|thanks|thank you|ok|okay|yes|no|cool|great)\b[\s!.]*$", re.I)
|
|
29
|
+
|
|
30
|
+
SHIP_HINT = ("When the checks pass, finish by running in the terminal:\n"
|
|
31
|
+
" helix ship {ticket}--summary \"<one line>\" --root-cause \"<for bugs>\" --rule \"<one-line rule that "
|
|
32
|
+
"prevents this bug class>\"\n"
|
|
33
|
+
"It commits on a helix/ branch, pushes, opens the PR{link} and saves the lesson. "
|
|
34
|
+
"Do not run git commit/push yourself.")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def find_ticket(prompt: str) -> str | None:
|
|
38
|
+
m = TICKET_IN_TEXT.search(prompt)
|
|
39
|
+
if not m:
|
|
40
|
+
return None
|
|
41
|
+
ref = next(g for g in m.groups() if g)
|
|
42
|
+
return ref.upper() if "-" in ref else ref
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def build_context(prompt: str, root: Path, max_files: int = 6) -> str:
|
|
46
|
+
"""The text added to Claude's context for this prompt ('' = add nothing)."""
|
|
47
|
+
if not prompt.strip() or SMALL_TALK.match(prompt) or prompt.lstrip().startswith("/"):
|
|
48
|
+
return ""
|
|
49
|
+
cfg = load_config(root)
|
|
50
|
+
parts: list[str] = []
|
|
51
|
+
item = None
|
|
52
|
+
ref = find_ticket(prompt)
|
|
53
|
+
if ref and cfg.tracker.get("type"):
|
|
54
|
+
try:
|
|
55
|
+
item = tracker_from(cfg.tracker).get(ref)
|
|
56
|
+
parts.append("## Ticket (fetched by Helix)\n" + item.brief(limit=2500))
|
|
57
|
+
except ConnectorError as exc:
|
|
58
|
+
parts.append(f"## Ticket {ref}\n(Helix could not fetch it: {str(exc)[:150]})")
|
|
59
|
+
query = (item.brief(limit=1500) if item else "") + " " + prompt
|
|
60
|
+
intent = detect_intent(item.title if item else prompt, item)
|
|
61
|
+
if intent == "feature" and len(prompt.split()) < 4 and not item:
|
|
62
|
+
return "" # too vague to help; don't spend tokens
|
|
63
|
+
pmap = load_map(root)
|
|
64
|
+
files = Retriever(pmap).search(query, k=max_files) if pmap.get("files") else []
|
|
65
|
+
if files:
|
|
66
|
+
parts.append("## Start here (ranked by Helix; open these before searching)\n"
|
|
67
|
+
+ "\n".join(f"- {f}" for f, _ in files))
|
|
68
|
+
lessons = Lessons(root).relevant(query, [f for f, _ in files])
|
|
69
|
+
if lessons:
|
|
70
|
+
parts.append("## Past bugs in this repo - do not repeat\n"
|
|
71
|
+
+ "\n".join(f"- {l.get('rule') or l.get('root_cause')}" for l in lessons))
|
|
72
|
+
if intent != "research":
|
|
73
|
+
parts.append(f"## Helix workflow ({intent})\n{STEPS[intent]}")
|
|
74
|
+
parts.append(SHIP_HINT.format(ticket=f"{item.id} " if item else "",
|
|
75
|
+
link=" and links/updates the ticket" if item else ""))
|
|
76
|
+
else:
|
|
77
|
+
parts.append(f"## Helix workflow (question)\n{STEPS['research']}")
|
|
78
|
+
return "[Helix context - added automatically]\n\n" + "\n\n".join(parts)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def hook_prompt(payload: dict) -> dict | None:
|
|
82
|
+
root = Path(payload.get("cwd") or ".")
|
|
83
|
+
try:
|
|
84
|
+
ctx = build_context(payload.get("prompt", ""), root)
|
|
85
|
+
except Exception: # noqa: BLE001 - a hook must never block the user's prompt
|
|
86
|
+
return None
|
|
87
|
+
if not ctx:
|
|
88
|
+
return None
|
|
89
|
+
return {"hookSpecificOutput": {"hookEventName": "UserPromptSubmit", "additionalContext": ctx}}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def hook_session_start(payload: dict) -> dict | None:
|
|
93
|
+
root = Path(payload.get("cwd") or ".")
|
|
94
|
+
try:
|
|
95
|
+
if (root / ".helix").exists():
|
|
96
|
+
build_map(root) # incremental: only changed files are re-parsed
|
|
97
|
+
except Exception: # noqa: BLE001
|
|
98
|
+
return None
|
|
99
|
+
msg = ("Helix is active in this repo: prompts get ticket text, ranked files and past-bug lessons "
|
|
100
|
+
"automatically; checks run before you finish; use `helix ship` to open the PR.")
|
|
101
|
+
return {"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": msg}}
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def merge_settings(existing: dict, template: dict) -> dict:
|
|
105
|
+
"""Add Helix hooks/permissions to a repo's .claude/settings.json without dropping the user's own."""
|
|
106
|
+
out = json.loads(json.dumps(existing))
|
|
107
|
+
perms = out.setdefault("permissions", {})
|
|
108
|
+
for key in ("allow", "deny"):
|
|
109
|
+
cur = perms.setdefault(key, [])
|
|
110
|
+
for rule in template.get("permissions", {}).get(key, []):
|
|
111
|
+
if rule not in cur:
|
|
112
|
+
cur.append(rule)
|
|
113
|
+
hooks = out.setdefault("hooks", {})
|
|
114
|
+
for event, groups in template.get("hooks", {}).items():
|
|
115
|
+
cur = hooks.setdefault(event, [])
|
|
116
|
+
have = {h.get("command") for g in cur for h in g.get("hooks", [])}
|
|
117
|
+
for g in groups:
|
|
118
|
+
if not any(h.get("command") in have for h in g.get("hooks", [])):
|
|
119
|
+
cur.append(g)
|
|
120
|
+
return out
|
helix_layer/checks.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""Real verification: tests, lint and type checks (replaces Jessie's rubric score)."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass
|
|
14
|
+
class CheckResult:
|
|
15
|
+
name: str
|
|
16
|
+
cmd: str
|
|
17
|
+
ok: bool
|
|
18
|
+
output: str
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def detect_checks(root: Path) -> dict[str, str]:
|
|
22
|
+
"""Best-effort defaults when .helix/config.toml has no [checks]."""
|
|
23
|
+
checks: dict[str, str] = {}
|
|
24
|
+
if (root / "pubspec.yaml").exists():
|
|
25
|
+
flutter = "flutter" if shutil.which("flutter") else "dart"
|
|
26
|
+
checks["analyze"] = f"{flutter} analyze"
|
|
27
|
+
if (root / "test").exists():
|
|
28
|
+
checks["test"] = f"{flutter} test"
|
|
29
|
+
pkg = root / "package.json"
|
|
30
|
+
if pkg.exists():
|
|
31
|
+
try:
|
|
32
|
+
scripts = json.loads(pkg.read_text("utf-8")).get("scripts", {})
|
|
33
|
+
except json.JSONDecodeError:
|
|
34
|
+
scripts = {}
|
|
35
|
+
runner = "pnpm" if (root / "pnpm-lock.yaml").exists() else "yarn" if (root / "yarn.lock").exists() else "npm run"
|
|
36
|
+
for name in ("lint", "typecheck", "test"):
|
|
37
|
+
if name in scripts:
|
|
38
|
+
checks[f"js-{name}"] = f"{runner} {name}"
|
|
39
|
+
if "typecheck" not in scripts and (root / "tsconfig.json").exists():
|
|
40
|
+
checks["js-typecheck"] = "npx tsc --noEmit"
|
|
41
|
+
if any((root / f).exists() for f in ("pyproject.toml", "setup.cfg", "pytest.ini", "requirements.txt")):
|
|
42
|
+
if shutil.which("ruff"):
|
|
43
|
+
checks["py-lint"] = "ruff check ."
|
|
44
|
+
if (root / "tests").exists() or (root / "test").exists():
|
|
45
|
+
checks["py-test"] = "python -m pytest -q -x"
|
|
46
|
+
if (root / "go.mod").exists():
|
|
47
|
+
checks["go"] = "go vet ./... && go test ./..."
|
|
48
|
+
return checks
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def portable(cmd: str) -> str:
|
|
52
|
+
"""Run `python` as the interpreter Helix itself uses. Plain `python` can be missing,
|
|
53
|
+
Python 2 (some Linux) or the Store stub (Windows)."""
|
|
54
|
+
return re.sub(r"(^|&&\s*|;\s*|\|\|\s*)python(?=\s)", lambda m: m.group(1) + f'"{sys.executable}"', cmd)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def run_checks(root: Path, checks: dict[str, str], timeout: int = 1200) -> list[CheckResult]:
|
|
58
|
+
results = []
|
|
59
|
+
for name, cmd in checks.items():
|
|
60
|
+
if not cmd:
|
|
61
|
+
continue
|
|
62
|
+
cmd = portable(cmd)
|
|
63
|
+
try:
|
|
64
|
+
p = subprocess.run(cmd, shell=True, cwd=root, capture_output=True, text=True,
|
|
65
|
+
timeout=timeout, encoding="utf-8", errors="replace")
|
|
66
|
+
out = (p.stdout + "\n" + p.stderr).strip()
|
|
67
|
+
results.append(CheckResult(name, cmd, p.returncode == 0, out[-4000:]))
|
|
68
|
+
except subprocess.TimeoutExpired:
|
|
69
|
+
results.append(CheckResult(name, cmd, False, f"timed out after {timeout}s"))
|
|
70
|
+
return results
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def failure_text(results: list[CheckResult]) -> str:
|
|
74
|
+
return "\n\n".join(f"## {r.name}: `{r.cmd}`\n{r.output[-2500:]}" for r in results if not r.ok)
|