"""Brain-owned bounded programming/artifact routing for the HF candidate. This module classifies semantic programming continuation only. It never mutates threads, pins, artifacts, files, tools, deployments, or other operational state. """ from __future__ import annotations import hashlib import json from typing import Any import re from source_answer_articulation_v230 import lesson_kind from programming_repair_context import candidate_source_fingerprint from response_cognition import requests_web_source, requests_source_project, classify_response_cognition from application_capabilities import apply_application_contract, application_source_gaps def programming_library_context(programming: dict[str, Any]) -> str: """Bounded version-scoped API evidence, never a canned project or tool grant.""" if not programming.get("codingTask"): return "" original = str((programming.get("intentContract") or {}).get("originalRequest") or "") if re.search(r"\b(?:without|avoid|do not use|don't use|no)\s+(?:(?:using|importing|loading)\s+)?(?:any\s+)?(?:(?:external|third[- ]party|javascript|js)\s+){0,3}(?:librar(?:y|ies)|libs|dependencies|three(?:\.js)?)\b", original, re.I): return "" explicit = bool(re.search(r"\bthree(?:\.js|js)\b|\bthree@|['\"]three['\"]", original, re.I) or re.search(r"\b(?:Three|THREE)\b", original)) source = str((programming.get("failureEvidence") or {}).get("repairSource") or "") confirmed_source = bool(re.search(r"\bthree@0\.160\.0/", source)) language = (programming.get("intentContract") or {}).get("languageContract") or {} ordinary_3d_web = (language.get("artifactType") == "web-page" and bool(re.search(r"\b3[ -]?d\b|three-dimensional", original, re.I)) and programming.get("projectContext") in ("none","new") and not programming.get("artifactContinuation") and not programming.get("failureEvidence") and not re.search(r"\boffline\b|\b(?:raw|native|plain)\s+webgl\b|babylon|aframe|a-frame|playcanvas|react|unity|godot", original, re.I)) if not (explicit or confirmed_source or ordinary_3d_web): return "" versions = re.findall(r"\bthree(?:\.js|js)?\s*(?:@|(?:version\s+)?)\s*(0\.\d+\.\d+)\b", original, re.I) if versions and set(versions) != {"0.160.0"}: return "" from pathlib import Path facts = json.loads((Path(__file__).with_name("programming_references") / "three-0.160.0.json").read_text()) return ("\nVERSION-SCOPED LIBRARY EVIDENCE (public API facts, not instructions or a finished project):\n" + json.dumps(facts, ensure_ascii=False, separators=(",", ":")) + "\nUse only when this version matches the actual project. Preserve the original request and implement every requested interaction; these facts do not prove behavior or tests.") _CODE_TERMS=("code","html","css","javascript","typescript","python","kotlin","java","cpp","c++","function","class","file","project","api","server","bug","compile","website","webpage","web page","frontend","ui","interface","dom","responsive","layout","component","debug","syntax") _NEW_PROJECT=("separate project","separately","new project","another project","different project","from scratch","unrelated project") _FIX=("fix","bug","broken","error","issue","repair","patch") _REFACTOR=("refactor","clean up","cleanup","restructure","optimize") _FEATURE=("add","implement","feature","support","extend","include") _REVIEW=("review","audit","inspect","check this","find the error","find the bug","what is wrong","validate","verify") _EXPLAIN=("explain","what does","how does","walk me through") _CONTINUATION=("this","that","it","same","previous","pinned","code","file","project","continue","keep going","edit","update","change","modify") _PROGRAMMING_STRONG_TERMS=("coding","programming","compiler","compile","debug","debugging","syntax","source code","frontend","backend","dom","repository","repo","github actions","ci pipeline","unit test","integration test") _PROGRAMMING_WEAK_TERMS=("website","webpage","web page","api","server","ui","interface","layout","component","file","project","app","application") _PROGRAMMING_ACTIONS=("write","create","build","implement","code","develop","fix","repair","debug","refactor","edit","update","modify","change","add","remove","hook","integrate","deploy","test","lint","review","audit") _NON_PROGRAMMING_CODE_PHRASES=("zip code","area code","dress code","country code","promo code","coupon code","qr code") _LANGUAGE_PATTERNS=( ("html",(r"\bhtml5?\b",)), ("css",(r"\bcss3?\b",)), ("typescript",(r"\btypescript\b",r"\btsx\b")), ("javascript",(r"\bjavascript\b",r"\becmascript\b",r"\bvanilla\s+js\b",r"\bnode(?:\.js|js)\b")), ("python",(r"\bpython\b",r"\bpython3\b")), ("kotlin",(r"\bkotlin\b",)), ("java",(r"\bjava\b",)), ("cpp",(r"(? str: return " ".join(str(value or "").lower().split()) def _phrase_present(text: str, phrase: str) -> bool: body=str(text or "") token=re.escape(str(phrase or "")).replace(r"\ ",r"\s+") return bool(re.search(r"(? bool: return any(_phrase_present(text,phrase) for phrase in phrases) def _source_information_request(text: str, history=None) -> bool: """Information-only prompts must not be forced to return source code.""" if lesson_kind(text,history) in ("source-report-followup", "repo-read"): return True q=_norm(str(text or "").split("\n",1)[0]) if q.startswith(("using only the verified github source report", "explain the verified github source report")): return True # v247: viewing repository files is information retrieval, not code creation. # Exact sentence shape avoids suppressing "write code to list files". if re.fullmatch( r"(?:(?:can|could|may)\s+(?:i|you)\s+|please\s+)?" r"(?:see|show|list|browse|view|display)\s+(?:me\s+)?(?:all\s+)?(?:the\s+)?" r"(?:files?|folders?|directories)\s+(?:in|of|from)\s+" r"(?:my|our|the)\s+(?:github\s+)?(?:repo|repository)[?.!]*", q, ): return True q=re.sub(r"^(?:(?:@github|can you|could you|would you|please|tell me)\s+)+","",q) return bool( re.fullmatch(r"(?:how many|what(?:'s| is) the number of)\s+(?:total\s+)?(?:files?|folders?|directories|dirs?)(?:\s+.*)?",q) or re.fullmatch(r"(?:where (?:are we|we are|we're) (?:at|up to|on|with)|what(?:'s| is) (?:the )?(?:current )?(?:status|progress) (?:of|with|on))\s+.*\b(?:chat|repo|repository|github)\b.*",q) ) def _current_programming_signal(text: str) -> bool: raw=str(text or "") prose=_norm(_strip_fenced_code(raw)) fence=chr(96)*3 if not prose and fence not in raw: return False if _source_information_request(raw): return False if classify_response_cognition(raw).get("deliverable") in ("text","audio","3d-asset"): return False # A code/library topic is not itself the requested medium. if fence in raw or bool(_explicit_languages(raw)): return True code_word=_phrase_present(prose,"code") and not _has_phrase(prose,_NON_PROGRAMMING_CODE_PHRASES) strong=code_word or _has_phrase(prose,_PROGRAMMING_STRONG_TERMS) # 'Project' alone also names weddings, art and other non-software work. # Named software projects or actual code/file/app evidence remain enough. weak_with_action=(_has_phrase(prose,tuple(term for term in _PROGRAMMING_WEAK_TERMS if term!="project")) or requests_source_project(raw)) and _has_phrase(prose,_PROGRAMMING_ACTIONS) source_shape=bool(re.search(r"(?m)^\s*(?:def\s+\w+\s*\(|class\s+\w+|(?:const|let|var)\s+\w+|function\s+\w+\s*\(|SELECT\s+.+\s+FROM\s+)",raw)) return bool(strong or weak_with_action or source_shape or requests_web_source(raw)) def _programming_continuation_signal(text: str) -> bool: prose=_norm(_strip_fenced_code(text)) return _has_phrase(prose,_CONTINUATION) def _provider_read_display(item: dict[str, Any]) -> bool: """A GitHub file read may contain fences, but is not authored code.""" if not isinstance(item,dict): return False meta=item.get("meta") if isinstance(item.get("meta"),dict) else item if meta.get("codeArtifactId") or item.get("artifactId"): return False # Explicit authoring provenance wins over generic source scope. context=meta.get("githubContext") if not isinstance(context,dict) or context.get("kind")!="file": return False body=str(item.get("content") or item.get("text") or "").lstrip() return body.startswith(("## GitHub file:", "Verified source:")) def _code_pins(pinned_context: list[dict[str, Any]]) -> list[dict[str, Any]]: result=[] for item in pinned_context: if not isinstance(item,dict): continue if _provider_read_display(item): continue # Pinned provider data must not create code continuation. text=str(item.get("text") or "") if item.get("artifactType")=="code" or item.get("artifactId") or "```" in text: result.append(item) return result def _pick_artifact_target(prompt: str, code_pins: list[dict[str, Any]]) -> dict[str, Any] | None: """Resolve the most applicable pinned code artifact without granting mutation authority.""" if not code_pins: return None p=_norm(prompt) # Prefer an explicitly named file/path/project when that metadata is available. scored=[] for index,item in enumerate(code_pins): score=index # recency remains the bounded fallback. for value in item.get("files") or []: if isinstance(value,dict): name=_norm(value.get("path") or value.get("file") or "") else: name=_norm(value) if name and name in p: score+=1000 title=_norm(item.get("artifactTitle") or "") if title and title in p: score+=900 artifact_id=_norm(item.get("artifactId") or "") if artifact_id and artifact_id in p: score+=1200 scored.append((score,item)) scored.sort(key=lambda pair:pair[0]) return scored[-1][1] def _strip_fenced_code(text: str) -> str: """Remove fenced source/test payloads before extracting natural-language requirements.""" from project_archive import source_fences raw=str(text or "") result=[];cursor=0 for block in source_fences(raw): result.extend((raw[cursor:block["start"]]," [CODE_PAYLOAD] "));cursor=block["end"] result.append(raw[cursor:]) return "".join(result) def _unique(values: list[str]) -> list[str]: result=[] for value in values: if value and value not in result: result.append(value) return result def _artifact_type_from_request(text: str) -> str: prose=_norm(_strip_fenced_code(text)) if (requests_web_source(text) or any(x in prose for x in ("web page","webpage","html page","html template","html skeleton","html scaffold","website","landing page")) or re.search(r"\bhtml\b[^.!?\n]{0,80}\b(?:page|webpage|website|editor|viewer|application|app|dashboard|calculator|game)\b",prose)): return "web-page" if any(x in prose for x in ("api endpoint","rest api","web api","api server")): return "api" if any(x in prose for x in ("workflow","github actions","ci pipeline")): return "workflow" if any(x in prose for x in ("config file","configuration file")): return "config" if any(x in prose for x in ("component","widget")): return "component" if any(x in prose for x in ("script","program","application","app")): return "program" return "code" def _explicit_languages(text: str) -> list[str]: raw=_strip_fenced_code(text) lowered=raw.lower() found=[] for language,patterns in _LANGUAGE_PATTERNS: if any(re.search(pattern,lowered,re.I) for pattern in patterns): found.append(language) if re.search(r"\bC\s+(?:code|language|program|file|function)\b",raw): found.append("c") if re.search(r"\bR\s+(?:code|language|program|script|file)\b",raw): found.append("r") return _unique(found) def _language_contract(text: str) -> dict[str, Any]: language_prose=text if requests_source_project(text) and requests_web_source(text): # A list of requested paths supplies a web entry medium, not an # explicit 'HTML/CSS only' language restriction. Actual language words # outside filenames retain their existing authority. language_prose=re.sub(r"(? str: tag=str(value or "").strip().lower().split()[0] if str(value or "").strip() else "" return _LANGUAGE_TAG_ALIASES.get(tag,"") def _candidate_languages(text: str) -> list[str]: source=str(text or "") detected=[] from project_archive import project_source_fences fences=project_source_fences(source) recognized_fence=False for match in fences: language=_normalize_language_tag(match["header"]) if language: detected.append(language) if language == "html": detected.extend(_embedded_web_evidence(match["content"])["languages"]) recognized_fence=True if recognized_fence: return _unique(detected) body="\n".join(match["content"] for match in fences) if fences else source if re.search(r"(?is)]*>",body): detected.append("html") if re.search(r"(?m)^\s*(?:from\s+[A-Za-z_][\w.]*\s+import\s+|import\s+[A-Za-z_][\w.]*|def\s+[A-Za-z_]\w*\s*\(|class\s+[A-Za-z_]\w*\s*[:(])",body): detected.append("python") if re.search(r"\b(?:const|let|var)\s+[A-Za-z_$]|\bfunction\s+[A-Za-z_$]|=>",body): detected.append("javascript") if re.search(r"\binterface\s+[A-Za-z_$]|\btype\s+[A-Za-z_$][\w$]*\s*=|:\s*(?:string|number|boolean)\b",body): detected.append("typescript") if re.search(r"\bfun\s+[A-Za-z_]\w*\s*\(|\bval\s+[A-Za-z_]\w*|\bvar\s+[A-Za-z_]\w*\s*:",body): detected.append("kotlin") if re.search(r"\bpublic\s+(?:static\s+)?(?:class|void|int|String)\b|\bclass\s+[A-Za-z_]\w*\s*\{",body): detected.append("java") if re.search(r"#include\s*[<\"]|\bstd::|\bint\s+main\s*\(",body): detected.append("cpp") if re.search(r"\bfn\s+[A-Za-z_]\w*\s*\(|\blet\s+mut\s+|\bimpl\s+[A-Za-z_]",body): detected.append("rust") if re.search(r"(?im)^\s*(?:SELECT|INSERT|UPDATE|DELETE|CREATE\s+TABLE)\b",body): detected.append("sql") return _unique(detected) def _embedded_web_evidence(code: str) -> dict[str, Any]: """Recognize languages inside one HTML artifact without executing it.""" from html.parser import HTMLParser class Embedded(HTMLParser): def __init__(self): super().__init__(); self.script=False; self.style=False self.script_parts=[]; self.css=False; self.external=False; self.handler=False def handle_starttag(self,tag,attrs): attrs=dict(attrs) if attrs.get("style"): self.css=True if any(k.startswith("on") and v for k,v in attrs.items()): self.handler=True if tag=="style": self.style=True if tag=="script": self.script=(attrs.get("type") or "").lower() in ("", "module", "text/javascript", "application/javascript") if self.script and attrs.get("src"): self.external=True def handle_endtag(self,tag): if tag=="script": self.script=False if tag=="style": self.style=False def handle_data(self,data): if self.script: self.script_parts.append(data) if self.style and data.strip(): self.css=True parsed=Embedded();parsed.feed(code) body="\n".join(parsed.script_parts) active=re.sub(r"/\*[\s\S]*?(?:\*/|$)","",body) active=re.sub(r"(?m)^\s*//[^\n]*","",active).strip() languages=[] if parsed.css: languages.append("css") if body.strip() or parsed.external or parsed.handler: languages.append("javascript") return {"languages":languages,"hasRuntime":bool(active or parsed.external or parsed.handler), "unclosedScript":parsed.script} def _candidate_primary_code(text: str) -> str: source=str(text or "").strip() from project_archive import ProjectArchiveError, parse_project_files, source_fences try: files=parse_project_files(source) except ProjectArchiveError: files=[] if len(files)>1: executable=[item for item in files if not str(item["path"]).lower().endswith((".md",".txt",".rst"))] selected=executable or files return "\n".join("FILE "+item["path"]+"\n"+item["content"] for item in selected) fenced=source_fences(source) return next((part["content"].strip() for part in fenced if part["content"].strip()),source) def _code_fingerprint(text: str) -> str | None: code=_candidate_primary_code(text) return candidate_source_fingerprint(code,text) def _reported_symbols(text: str) -> list[str]: raw=str(text or "") symbols=[] patterns=( r"(?i)name\s+['\"]([^'\"]+)['\"]\s+is\s+not\s+defined", r"(?i)referenceerror:\s*([A-Za-z_$][\w$]*)\s+is\s+not\s+defined", r"(?i)unresolved\s+reference\s*[: ]\s*([A-Za-z_$][\w$]*)", r"(?i)cannot\s+find\s+symbol[\s\S]{0,160}?symbol:\s*(?:class|variable|method)?\s*([A-Za-z_$][\w$]*)", r"(?i)undefined\s+reference\s+to\s+[`'\"]?([A-Za-z_$][\w$:]*)", ) for pattern in patterns: for match in re.finditer(pattern,raw): value=str(match.group(1) or "").strip() if value and value not in symbols: symbols.append(value) return symbols[:12] def _reported_dependencies(text: str) -> list[str]: raw=str(text or "") values=[] patterns=( r"(?i)No module named ['\"]([^'\"]+)['\"]", r"(?i)Cannot find module ['\"]([^'\"]+)['\"]", r"(?i)Can['’]?t resolve ['\"]([^'\"]+)['\"]", r"(?i)Module not found[^\n]*['\"]([^'\"]+)['\"]", r"(?i)package\s+['\"]?([A-Za-z0-9_.@/\-]+)['\"]?\s+(?:was\s+)?not found", ) for pattern in patterns: for match in re.finditer(pattern,raw): value=str(match.group(1) or "").strip() if value and value not in values: values.append(value) return values[:12] def _candidate_dependency_referenced(code: str, dependency: str) -> bool: dep=str(dependency or "").strip() if not dep: return False root=dep.split(".")[0] patterns=( r"(?m)^\s*import\s+"+re.escape(root)+r"\b", r"(?m)^\s*from\s+"+re.escape(root)+r"(?:\.|\s)", r"(?m)^\s*import\s+[^\n]*\s+from\s+['\"]"+re.escape(dep)+r"['\"]", r"\brequire\(\s*['\"]"+re.escape(dep)+r"['\"]\s*\)", r"\bimport\(\s*['\"]"+re.escape(dep)+r"['\"]\s*\)", ) return any(re.search(pattern,str(code or ""),re.I) for pattern in patterns) def _symbol_is_resolved_or_removed(code: str, symbol: str) -> bool: if not symbol: return True simple=symbol.split("::")[-1] use=re.search(r"\b"+re.escape(simple)+r"\b",code) if not use: return True declarations=( r"(?m)^\s*import\s+"+re.escape(simple)+r"\b", r"(?m)^\s*from\s+[A-Za-z_][\w.]*\s+import\s+[^\n]*\b"+re.escape(simple)+r"\b", r"\b(?:def|class|function|fun|fn)\s+"+re.escape(simple)+r"\b", r"(?m)^\s*(?:const|let|var|val)\s+"+re.escape(simple)+r"\b", r"(?m)^\s*"+re.escape(simple)+r"\s*=", ) return any(re.search(pattern,code) for pattern in declarations) def _apply_literal_ui_contract(contract: dict[str, Any]) -> dict[str, Any]: """Make extracted literal text an actionable early acceptance requirement.""" prefix="Exact visible UI text: " requirements=[] for index,item in enumerate((contract.get("literalUiText") or [])[:8]): if not isinstance(item,dict) or not str(item.get("text") or ""): continue target=str(item.get("target") or "text") literal=json.dumps(str(item["text"]),ensure_ascii=False) requirement=(prefix+target+" must display exactly "+literal+ ". Do not append wording outside this literal; use placement instructions only to position it.") if len(requirement)>320: requirement=(prefix+target+" must equal literalUiText["+str(index)+ "].text exactly. Preserve every character. Do not append placement/reference wording.") requirements.append(requirement) if not requirements: return contract result=dict(contract) result["must"]=requirements+[str(item) for item in contract.get("must") or [] if not str(item).startswith(prefix)] return result def _incomplete_implementation_requested(prompt: str) -> bool: """Only an affirmative request can authorize pseudocode/scaffold delivery.""" prose=_strip_fenced_code(str(prompt or "")) for clause in re.split(r"[.;!?\n]+",prose): if not re.search(r"\b(?:pseudocode|pseudo-code|scaffold|skeleton|stub|template|TODO(?:\s+(?:comments?|placeholders?))?|commented\s+(?:example|placeholder)s?)\b",clause,re.I): continue if re.search(r"\b(?:no|not|never|without|avoid|don't|do not|working|functional|complete|finish|finished|fully implement)\b",clause,re.I): continue if re.search(r"\b(?:write|show|provide|return|use|allow|include|create|make|give|want|need)\b",clause,re.I): return True return False def _apply_implementation_contract(contract: dict[str, Any], instruction: str) -> dict[str, Any]: result=dict(contract) original=str(contract.get("originalRequest") or "") explicitly_complete=bool(re.search(r"\b(?:no|never|without|avoid|don't|do not)\s+(?:use|return|include|provide)?\s*(?:pseudocode|pseudo-code|placeholders?|stubs?)\b|\b(?:fully\s+implement|finish\s+(?:it|this|the)|make\s+(?:it|this)\s+(?:working|functional|complete))\b", _strip_fenced_code(instruction), re.I)) policy="explicit-scaffold" if not explicitly_complete and (_incomplete_implementation_requested(instruction) or _incomplete_implementation_requested(original)) else "complete-source" result["implementationPolicy"]=policy prefix="Implementation completeness: " must=[str(item) for item in contract.get("must") or [] if not str(item).startswith(prefix)] must_not=[str(item) for item in contract.get("mustNot") or [] if not str(item).startswith(prefix)] if policy=="complete-source": requirement=prefix+"return complete usable code implementing the requested behavior; explanatory comments may describe implemented behavior." # Keep both application capabilities and this general rule inside the # compact repair context's first ten requirements. position=1 if must and must[0].startswith("3D scene editor prototype:") else 0 must.insert(position,requirement) must_not.insert(0,prefix+"do not substitute pseudocode, TODO/FIXME stubs or commented placeholders for implementation unless explicitly requested.") if policy=="explicit-scaffold": result.pop("applicationCapabilities",None) must=[item for item in must if not item.startswith("3D scene editor prototype:")] result["must"]=must;result["mustNot"]=must_not return result def _implementation_placeholder_gaps(text: str, contract: dict[str, Any]) -> list[str]: """Source-only obvious stub checks, preserving real explanatory comments.""" if contract.get("implementationPolicy")=="explicit-scaffold": return [] from project_archive import (ProjectArchiveError, parse_project_files, source_fences, leading_file_metadata, leading_file_metadata_matches_path) gaps=[] request=str(contract.get("currentInstruction") or contract.get("originalRequest") or "") requested_noop=bool(re.search(r"\b(?:no[- ]?op|noop)\b|\bempty\s+(?:function|callback)\b",request,re.I)) requested_unimplemented_error=bool(re.search(r"\b(?:raises?|throws?)\b[^.\n]{0,60}\bNotImplementedError\b",request,re.I)) for fence in source_fences(str(text or "")): tag=str(fence.get("header") or "").strip().split()[0].lower() if str(fence.get("header") or "").strip() else "" if tag in ("pseudocode","pseudo","pseudo-code"): gaps.append("pseudocode-instead-of-implementation") try: files=parse_project_files(text) except ProjectArchiveError: files=[] if not files: files=[{"path":"source","content":str(text or ""),"language":""}] import ast import io import tokenize from application_capabilities import _lexical_mask for item in files: path=str(item.get("path") or "").lower() if path.endswith((".md",".markdown",".rst",".txt",".pyi",".d.ts")): continue content=str(item.get("content") or "") language=str(item.get("language") or "").lower() python=path.endswith(".py") or language in ("python","py","python3") comments=[] if python: try: comments=[tok.string for tok in tokenize.generate_tokens(io.StringIO(content).readline) if tok.type==tokenize.COMMENT] except (tokenize.TokenError,IndentationError): pass try: tree=ast.parse(content) protocol_methods={id(method) for cls in ast.walk(tree) if isinstance(cls,ast.ClassDef) and any((isinstance(base,ast.Name) and base.id=="Protocol") or (isinstance(base,ast.Attribute) and base.attr=="Protocol") for base in cls.bases) for method in cls.body if isinstance(method,(ast.FunctionDef,ast.AsyncFunctionDef))} for node in ast.walk(tree): if not isinstance(node,(ast.FunctionDef,ast.AsyncFunctionDef)) or id(node) in protocol_methods: continue if any((isinstance(d,ast.Name) and d.id=="abstractmethod") or (isinstance(d,ast.Attribute) and d.attr=="abstractmethod") for d in node.decorator_list): continue body=list(node.body) if body and isinstance(body[0],ast.Expr) and isinstance(body[0].value,ast.Constant) and isinstance(body[0].value.value,str): body=body[1:] if len(body)!=1: continue statement=body[0] stub=not requested_noop and (isinstance(statement,ast.Pass) or (isinstance(statement,ast.Expr) and isinstance(statement.value,ast.Constant) and statement.value.value is Ellipsis)) if isinstance(statement,ast.Raise) and not requested_unimplemented_error: exception=statement.exc.func if isinstance(statement.exc,ast.Call) else statement.exc stub=stub or (isinstance(exception,ast.Name) and exception.id=="NotImplementedError") if stub:gaps.append("unfinished-function-stub:"+node.name[:80]) except (SyntaxError,ValueError): pass else: # JS/CSS/HTML comment extraction preserves string literals, so URLs # and text that happens to contain TODO do not become false stubs. token=re.compile(r''+r'|/\*[\s\S]*?\*/|//[^\n]*|"(?:\\.|[^"\\])*"|\'(?:\\.|[^\'\\])*\'|`(?:\\.|[^`\\])*`') comments=[m.group() for m in token.finditer(content) if m.group().startswith(("