mapwright-agent 0.2.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.
- mapwright/__init__.py +3 -0
- mapwright/__main__.py +3 -0
- mapwright/analyze.py +809 -0
- mapwright/brief.py +208 -0
- mapwright/cli.py +596 -0
- mapwright/concepts.py +190 -0
- mapwright/config.py +204 -0
- mapwright/connect.py +337 -0
- mapwright/export.py +42 -0
- mapwright/firestore.py +168 -0
- mapwright/flow.py +238 -0
- mapwright/hooks.py +111 -0
- mapwright/ignore.py +248 -0
- mapwright/infra.py +253 -0
- mapwright/mcp.py +153 -0
- mapwright/noise.py +80 -0
- mapwright/redact.py +39 -0
- mapwright/render.py +428 -0
- mapwright/routes_js.py +282 -0
- mapwright/server.py +388 -0
- mapwright/titles.py +111 -0
- mapwright/track.py +715 -0
- mapwright/ui/app.css +277 -0
- mapwright/ui/app.js +1025 -0
- mapwright/ui/icons.svg +73 -0
- mapwright/ui/index.html +35 -0
- mapwright/ui/mark.svg +1 -0
- mapwright/ui/vendor/mermaid.LICENSE +21 -0
- mapwright/ui/vendor/mermaid.min.js +2029 -0
- mapwright_agent-0.2.0.dist-info/METADATA +179 -0
- mapwright_agent-0.2.0.dist-info/RECORD +34 -0
- mapwright_agent-0.2.0.dist-info/WHEEL +4 -0
- mapwright_agent-0.2.0.dist-info/entry_points.txt +3 -0
- mapwright_agent-0.2.0.dist-info/licenses/LICENSE +21 -0
mapwright/titles.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"""Derive a short, clean step title for automatic steps. Pure functions, stdlib only.
|
|
2
|
+
|
|
3
|
+
An auto step must never echo a long or messy prompt as its title. `derive_title` cleans the prompt
|
|
4
|
+
(markdown, code, paths, urls, filler) and uses its first meaningful sentence when that is short and
|
|
5
|
+
clear; otherwise it computes a title from the actual changes.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
from collections import Counter
|
|
13
|
+
|
|
14
|
+
MAX_TITLE = 60
|
|
15
|
+
_FILLER = re.compile(
|
|
16
|
+
r"^(?:(?:hey|hi|hello|ok(?:ay)?|so|well|and|also|now|then|just|please|pls|plz|kindly|great|thanks|thank you|"
|
|
17
|
+
r"can you|could you|would you|will you|can we|could we|let'?s|i want you to|i need you to|i want to|i need to|"
|
|
18
|
+
r"i'd like you to|i would like you to|go ahead and|next|first|lastly)\b[,:;\s-]*)+", re.I)
|
|
19
|
+
_TRIVIAL = re.compile(r"^(?:y|yes|yeah|yep|no|ok|okay|k|continue|go|go on|proceed|do it|done|thanks|thank you|great|good|nice|"
|
|
20
|
+
r"sure|fine|retry|again|next|keep going|looks good|lgtm)\W*$", re.I)
|
|
21
|
+
_FENCE = re.compile(r"```.*?(?:```|\Z)", re.S)
|
|
22
|
+
_URL = re.compile(r"https?://\S+|www\.\S+")
|
|
23
|
+
_PATH = re.compile(r"(?<![\w])(?:~|\.{1,2})?/(?:[\w.@+-]+/)+[\w.@+-]*|(?<![\w])[\w.@+-]+/(?:[\w.@+-]+/)*[\w.@+-]+\.\w{1,6}\b")
|
|
24
|
+
_MD = re.compile(r"[*_#>`~|]+|^\s*[-+]\s+|^\s*\d+[.)]\s+", re.M)
|
|
25
|
+
_LINK = re.compile(r"\[([^\]]*)\]\([^)]*\)")
|
|
26
|
+
_SPLIT = re.compile(r"(?<=[.!?])\s+|\n+|;\s+")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def clean_prompt(text: str) -> str:
|
|
30
|
+
"""Prompt text with fences, urls, paths, markdown and links removed, whitespace collapsed."""
|
|
31
|
+
t = _FENCE.sub(" ", text or "")
|
|
32
|
+
t = _LINK.sub(r"\1", t)
|
|
33
|
+
t = re.sub(r"⟨[^⟩]*⟩", " ", t) # redaction placeholders
|
|
34
|
+
t = _URL.sub(" ", t)
|
|
35
|
+
t = _PATH.sub(" ", t)
|
|
36
|
+
t = _MD.sub(" ", t)
|
|
37
|
+
return " ".join(t.split())
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _first_sentence(text: str) -> str:
|
|
41
|
+
for part in _SPLIT.split(text):
|
|
42
|
+
part = _FILLER.sub("", part.strip()).strip(" ,:;-.")
|
|
43
|
+
if len(re.findall(r"[A-Za-z]{2,}", part)) >= 2 and not _TRIVIAL.match(part):
|
|
44
|
+
return part
|
|
45
|
+
return ""
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def cap(text: str, limit: int = MAX_TITLE) -> str:
|
|
49
|
+
"""Cut at a word boundary, with an ellipsis."""
|
|
50
|
+
text = text.strip()
|
|
51
|
+
if len(text) <= limit:
|
|
52
|
+
return text
|
|
53
|
+
cut = text[:limit]
|
|
54
|
+
if text[limit] != " " and " " in cut:
|
|
55
|
+
cut = cut[:cut.rfind(" ")]
|
|
56
|
+
return cut.rstrip(" ,:;-.") + "…"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def prompt_title(prompt: str) -> str | None:
|
|
60
|
+
"""A title from the prompt, or None when it is trivial, long/pasted text or too ambiguous to trust."""
|
|
61
|
+
raw = prompt or ""
|
|
62
|
+
if len(raw.split()) > 60 or raw.count("\n") > 6 or raw.count("```") >= 2:
|
|
63
|
+
return None # a long prompt or pasted text: describe the changes instead
|
|
64
|
+
sentence = _first_sentence(clean_prompt(raw))
|
|
65
|
+
if not sentence or len(sentence.split()) < 2 or len(sentence) > 160:
|
|
66
|
+
return None
|
|
67
|
+
return cap(sentence)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _top_dir(paths: list[str]) -> str:
|
|
71
|
+
dirs: Counter = Counter()
|
|
72
|
+
for p in paths:
|
|
73
|
+
parts = p.split("/")[:-1]
|
|
74
|
+
dirs["/".join(parts[:2])] += 1
|
|
75
|
+
d, n = dirs.most_common(1)[0]
|
|
76
|
+
return d if d and n * 2 >= len(paths) else ""
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def changes_title(changes: list[dict], new_symbols: list[str] | None = None) -> str:
|
|
80
|
+
"""'Update 5 files in apps/web (+3 new)', 'Add calc.py' ... computed from the changes."""
|
|
81
|
+
paths = [c["path"] for c in changes]
|
|
82
|
+
if not paths:
|
|
83
|
+
return "Update files"
|
|
84
|
+
added = [c["path"] for c in changes if c.get("kind") == "added"]
|
|
85
|
+
deleted = [c["path"] for c in changes if c.get("kind") == "deleted"]
|
|
86
|
+
n = len(paths)
|
|
87
|
+
if n == 1:
|
|
88
|
+
verb = "Add" if added else "Delete" if deleted else "Update"
|
|
89
|
+
title = f"{verb} {os.path.basename(paths[0])}"
|
|
90
|
+
if new_symbols and verb == "Update":
|
|
91
|
+
title += f": {new_symbols[0]}"
|
|
92
|
+
return cap(title)
|
|
93
|
+
verb = "Add" if len(added) == n else "Delete" if len(deleted) == n else "Update"
|
|
94
|
+
where = _top_dir(paths)
|
|
95
|
+
title = f"{verb} {n} files" + (f" in {where}" if where else "")
|
|
96
|
+
extras = []
|
|
97
|
+
if verb == "Update" and added:
|
|
98
|
+
extras.append(f"+{len(added)} new")
|
|
99
|
+
if verb == "Update" and deleted:
|
|
100
|
+
extras.append(f"-{len(deleted)} deleted")
|
|
101
|
+
if extras:
|
|
102
|
+
title += f" ({', '.join(extras)})"
|
|
103
|
+
if new_symbols and len(title) < 40:
|
|
104
|
+
title += f": {', '.join(new_symbols[:2])}"
|
|
105
|
+
return cap(title)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def derive_title(prompt: str, changes: list[dict], new_symbols: list[str] | None = None) -> str:
|
|
109
|
+
"""Title of an auto step: the prompt's first meaningful sentence when it is short and clear,
|
|
110
|
+
else one computed from the changes. Never longer than ~60 chars."""
|
|
111
|
+
return prompt_title(prompt) or changes_title(changes, new_symbols)
|