herdr-orchestra 6.49.0 → 6.51.0
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.
- package/CHANGELOG.md +20 -0
- package/VERSION +1 -1
- package/bin/__pycache__/orchcpython-314.pyc +0 -0
- package/bin/orch +456 -42
- package/package.json +1 -1
- package/playbooks/onboard.md +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,26 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes. Versions follow [semantic versioning](https://semver.org).
|
|
4
4
|
|
|
5
|
+
## [6.51.0] - 2026-12-04
|
|
6
|
+
|
|
7
|
+
`/orch-onboard` finds a project's real components, whatever their folder names, and says what each does.
|
|
8
|
+
|
|
9
|
+
- **Components, not folder names:** before, onboard only knew parts named `frontend`, `backend`, `web`, `api` (or under `apps/`, `services/`). A repo with `frontend`, `core`, `worker`, `retriever` and `docpipe` was treated as one app. Now a folder is a component when it has its own `package.json` / `pyproject.toml` / `go.mod`, a Dockerfile, a docker-compose service built from it, or at least 5 code files. Services nested deeper (`platform/services/auth`) are found too. Helper, docs and data folders (`scripts`, `docs`, `postgres` with only SQL) are left out, and at most 8 are offered (deployed ones first). You still tick which ones to write.
|
|
10
|
+
- **One app stays one app:** when the repo root has its own manifest (a `package.json` with dependencies, a `pyproject.toml` ...), its folders (`src/`, `lib/`, `server/`, Django apps) are that app, not components. Such a folder counts only when the app starts it on its own (a start script, a Procfile line, `__main__.py`) or two components import it.
|
|
11
|
+
- **What each does, from its code:** what it imports (Celery: background jobs, Qdrant: search and retrieval, pdfplumber: document processing) and which components import it. Example: `core: core/; shared code, used by retriever, worker`. Relative imports, tsconfig aliases (`@/core`), package names (`@acme/ui`) and Go modules are followed to the folder they point at, so an import of the component's own `src/core` is not a link to `core/`. A link found only by name, or by a dynamic import (`import("../core")`, `importlib.import_module`), is said as a guess: `maybe uses core`.
|
|
12
|
+
|
|
13
|
+
Tokens: nothing any agent reads in a run changes. `orch lead onboard`, read once per project, grows by 40 characters in an empty repo; in a repo with components, each suggested profile carries a short "what it does".
|
|
14
|
+
|
|
15
|
+
## [6.50.0] - 2026-12-04
|
|
16
|
+
|
|
17
|
+
No-cost testing: a project can tell every coder that tests never spend money on outside services, and orch makes its own checks run without the paid keys.
|
|
18
|
+
|
|
19
|
+
- **`## all` profile:** a profile named `all` goes into every coder's task, whatever the milestone's profile (`Profile: none` too, `orch fix` follow-ups and Pi subagent mode included), and every review checks it. `Profile: all` on a milestone is an error, since it already reaches everyone.
|
|
20
|
+
- **Onboard offers it** with four short rules: tests never call a paid outside service (AI, payments, SMS, email) in any kind of test; mock the backend too, since a Playwright mock alone still lets the backend call the real API; a missing mock fails the test; a live test runs only after the developer says so. A UI part's profile (or `all` in a one-app repo) gets one Playwright line: a chat message gets a mocked AI reply.
|
|
21
|
+
- **`Hide keys:`** Example: `Hide keys: OPENAI_API_KEY, GEMINI_API_KEY`. Every check orch runs (the coder's check, the merge check, `orch check`, `orch finish`) goes without those keys, so a forgotten mock fails instead of spending money. The check line coders are told to run hides them too: `env -u GEMINI_API_KEY -u OPENAI_API_KEY sh -c '<check>'`. Onboard fills the list from the repo's packages and the names in `.env.example` (never `.env`, never a value).
|
|
22
|
+
|
|
23
|
+
Tokens: without a profiles file nothing any agent reads changes; wake-ups, `orch lead plan` and `orch lead run` are byte-identical. A coder task gets about 460 characters when `## all` exists, and its check line about 25 more per hidden key. `orch lead onboard`, read once per project, grows by 636 characters (the `all` suggestion).
|
|
24
|
+
|
|
5
25
|
## [6.49.0] - 2026-12-03
|
|
6
26
|
|
|
7
27
|
Agent profiles (beta): each project can now keep its own specialists in `.orchestrate/profiles.md`. This file stays on your machine and is never committed. A profile says which folders it owns, the house rules for that part of the repo, its skills and its check. When the lead writes `Profile: web` on a milestone, that coder gets the web profile's role, folders, rules, skills and check, and none of the backend rules. A project without the file works exactly as before.
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
6.
|
|
1
|
+
6.51.0
|
|
Binary file
|
package/bin/orch
CHANGED
|
@@ -13,7 +13,7 @@ Task status flow (every change goes through move(), which checks TRANSITIONS)
|
|
|
13
13
|
side states: needs-answer, paused, failed, conflict, needs-fix, held (waiting for `orch approve`, from the developer or, for some reasons, the lead), skipped
|
|
14
14
|
Also: .orchestrate/events.jsonl (one line per transition), driver.lock (held by autopilot while it drives).
|
|
15
15
|
"""
|
|
16
|
-
import atexit, contextlib, fcntl, fnmatch, hashlib, json, os, re, shlex, shutil, signal, socket, subprocess, sys, tempfile, textwrap, time
|
|
16
|
+
import atexit, contextlib, fcntl, fnmatch, hashlib, json, os, posixpath, re, shlex, shutil, signal, socket, subprocess, sys, tempfile, textwrap, time
|
|
17
17
|
from pathlib import Path
|
|
18
18
|
|
|
19
19
|
HERDR = os.environ.get("HERDR", "herdr")
|
|
@@ -1872,9 +1872,10 @@ def cmd_sync(args):
|
|
|
1872
1872
|
errors.append(f"{tid} has `Profile: {pn}`, but "
|
|
1873
1873
|
f"{'.orchestrate/profiles.md' if prof_path.parent == ORCH else short(prof_path)} has no `## {pn}` "
|
|
1874
1874
|
f"(profiles: {', '.join(profs) or 'none'})")
|
|
1875
|
-
elif pn
|
|
1876
|
-
errors.append(f"{tid} has `Profile:
|
|
1877
|
-
f"review by itself — give the milestone a coder
|
|
1875
|
+
elif pn in ("reviewer", "all"):
|
|
1876
|
+
errors.append(f"{tid} has `Profile: {pn}`: that profile goes into every "
|
|
1877
|
+
f"{'review' if pn == 'reviewer' else 'coder task'} by itself — give the milestone a coder "
|
|
1878
|
+
f"profile or `Profile: none`")
|
|
1878
1879
|
elif pn:
|
|
1879
1880
|
pr = profs[pn]
|
|
1880
1881
|
ok_owns = [o for o in pr["owns"] if not owns_problem(o)]
|
|
@@ -1888,15 +1889,17 @@ def cmd_sync(args):
|
|
|
1888
1889
|
warns.append(f"{tid} is `Repo: {rp[0]}` but profile {pn} is for repo {pr['repo']}")
|
|
1889
1890
|
house = None
|
|
1890
1891
|
two = {}
|
|
1891
|
-
for pn in [*used, *(["reviewer"] if "reviewer" in profs and reviewer else [])]:
|
|
1892
|
+
for pn in [*used, *(["reviewer"] if "reviewer" in profs and reviewer else []), *(["all"] if "all" in profs else [])]:
|
|
1892
1893
|
pr = profs.get(pn)
|
|
1893
1894
|
if not pr or pn in two:
|
|
1894
1895
|
continue
|
|
1895
1896
|
two[pn] = True
|
|
1896
1897
|
if pr["unknown"]:
|
|
1897
1898
|
warns.append(f"profile {pn}: unknown line(s) {', '.join(pr['unknown'])} — a profile has Role, Owns, "
|
|
1898
|
-
f"Check, Skills, Rules, Review, Repo")
|
|
1899
|
-
if
|
|
1899
|
+
f"Check, Skills, Rules, Review, Repo" + (", Hide keys" if pn == "all" else ""))
|
|
1900
|
+
if pr["hide keys"] and pn != "all":
|
|
1901
|
+
warns.append(f"profile {pn}: `Hide keys:` only works in `## all` (it applies to every check)")
|
|
1902
|
+
if not (pr["rules"] or pr["owns"] or (pn == "reviewer" and pr["role"]) or (pn == "all" and pr["hide keys"])):
|
|
1900
1903
|
warns.append(f"profile {pn} has no Rules and no Owns, so it adds nothing — give it this part's rules")
|
|
1901
1904
|
if pr["size"] > PROFILE_MAX_CHARS:
|
|
1902
1905
|
warns.append(f"profile {pn} is {pr['size']} characters (over {PROFILE_MAX_CHARS}): it goes into every "
|
|
@@ -1936,9 +1939,14 @@ def cmd_sync(args):
|
|
|
1936
1939
|
f"the profile (coders read {house[_norm_rule(r)]} anyway)")
|
|
1937
1940
|
warns += [f"profiles.md has two `## {pn}` sections: only the last one counts — merge them into one"
|
|
1938
1941
|
for pn, pr in profs.items() if pr.get("dup")]
|
|
1942
|
+
all_r = {_norm_rule(r) for r in (profs.get("all") or {}).get("rules", [])}
|
|
1943
|
+
for pn in used:
|
|
1944
|
+
for r in (profs.get(pn) or {}).get("rules", []):
|
|
1945
|
+
if pn != "all" and _norm_rule(r) in all_r:
|
|
1946
|
+
warns.append(f"profile {pn}: \"{r[:80]}\" is already in `## all`, which every coder gets — remove it")
|
|
1939
1947
|
seen_rule = {}
|
|
1940
1948
|
for pn, pr in profs.items():
|
|
1941
|
-
if pn
|
|
1949
|
+
if pn in ("reviewer", "all"):
|
|
1942
1950
|
continue
|
|
1943
1951
|
for r in pr["rules"]:
|
|
1944
1952
|
seen_rule.setdefault(_norm_rule(r), []).append(pn)
|
|
@@ -3396,7 +3404,8 @@ def run_check(st, cwd, tid=None):
|
|
|
3396
3404
|
return True, "", 0
|
|
3397
3405
|
t0 = time.time()
|
|
3398
3406
|
try:
|
|
3399
|
-
r = subprocess.run(cmd, shell=True, cwd=cwd, text=True, capture_output=True, timeout=CHECK_TIMEOUT_S
|
|
3407
|
+
r = subprocess.run(cmd, shell=True, cwd=cwd, text=True, capture_output=True, timeout=CHECK_TIMEOUT_S,
|
|
3408
|
+
env=check_env(st))
|
|
3400
3409
|
ok, tail = r.returncode == 0, "\n".join((r.stdout + r.stderr).splitlines()[-60:])
|
|
3401
3410
|
except subprocess.TimeoutExpired:
|
|
3402
3411
|
ok, tail = False, f"check command timed out after {CHECK_TIMEOUT_S // 60} min"
|
|
@@ -4139,7 +4148,7 @@ def cmd_needs_fix(args):
|
|
|
4139
4148
|
t["job"] = {"file": f"review-fix-{k}.md", "body":
|
|
4140
4149
|
f"# Review findings for {tid}: {t['title']} (round {k})\n\n"
|
|
4141
4150
|
"The reviewer found the problems below. You own the fix: investigate each one and decide how to "
|
|
4142
|
-
f"solve it. Keep every acceptance criterion in {TASK_DIR}/{tid}/task.md, then run `{
|
|
4151
|
+
f"solve it. Keep every acceptance criterion in {TASK_DIR}/{tid}/task.md, then run `{run_line(st, tid)}`.\n"
|
|
4143
4152
|
"If you think a finding is wrong, explain why in your report instead of changing code for it.\n\n"
|
|
4144
4153
|
+ "\n".join(blockers) + "\n"}
|
|
4145
4154
|
move(st, tid, "needs-fix")
|
|
@@ -4251,6 +4260,7 @@ def cmd_review(args):
|
|
|
4251
4260
|
+ (", the decisions listed above" if rules["adrs"] else "")
|
|
4252
4261
|
+ (", the words listed above" if rules["glossary"] else "")
|
|
4253
4262
|
+ (f", the house rules of profile `{prof['name']}` in task.md" if prof and prof["rules"] else "")
|
|
4263
|
+
+ (", the rules for every coder in task.md" if all_profile_lines(st) else "")
|
|
4254
4264
|
+ (", the reviewer profile above" if prof_rv else "") +
|
|
4255
4265
|
"? A `rules` finding names the rule it breaks in `rule`. Only written rules count: a matter of taste is at "
|
|
4256
4266
|
"most a suggestion.\n"
|
|
@@ -4623,7 +4633,7 @@ def _merge_start(tid):
|
|
|
4623
4633
|
f"Other milestones landed on `{st['branch']}` while you worked, and they conflict with "
|
|
4624
4634
|
f"yours in: {', '.join(files) or 'see git status'}.\n"
|
|
4625
4635
|
f"In this folder run `git merge --no-commit {st['branch']}`, resolve every conflict so BOTH "
|
|
4626
|
-
f"sides keep working (you own the resolution), then run `{
|
|
4636
|
+
f"sides keep working (you own the resolution), then run `{run_line(st, tid)}`. Do not commit.\n"}
|
|
4627
4637
|
save(st)
|
|
4628
4638
|
who = t["worker"] if holds(st, tid) else "any free coder"
|
|
4629
4639
|
print(f"CONFLICT {tid} files={','.join(files)} -> conflict job queued for {who} (`orch send-job {tid}`)")
|
|
@@ -4692,7 +4702,7 @@ def _integration_failed(st, tid, tail):
|
|
|
4692
4702
|
f"# {tid} fails the check once merged onto `{st['branch']}` (round {n})\n\n"
|
|
4693
4703
|
f"Your milestone passes `{check_for(st, tid)}` on its own, but fails once it is merged with what landed on "
|
|
4694
4704
|
f"`{st['branch']}` since you started. In this folder run `git merge --no-commit {st['branch']}`, find "
|
|
4695
|
-
f"the cause and fix it (you decide how, and keep both sides working), then run `{
|
|
4705
|
+
f"the cause and fix it (you decide how, and keep both sides working), then run `{run_line(st, tid)}`. "
|
|
4696
4706
|
f"Don't commit, and don't weaken or skip tests.\n\n```\n{tail}\n```\n"}
|
|
4697
4707
|
move(st, tid, "needs-fix", f"fails the check on {st['branch']} once merged (round {n})")
|
|
4698
4708
|
t["wait"] = None
|
|
@@ -5268,7 +5278,7 @@ def cmd_finish(args):
|
|
|
5268
5278
|
if "--recheck" not in args and green_still(st, ROOT):
|
|
5269
5279
|
print(f"CHECK reused: it already passed on exactly these files ({st['green_tree'][:10]}), not run again")
|
|
5270
5280
|
elif st.get("check"):
|
|
5271
|
-
r = subprocess.run(st["check"], shell=True, cwd=ROOT, text=True, capture_output=True)
|
|
5281
|
+
r = subprocess.run(st["check"], shell=True, cwd=ROOT, text=True, capture_output=True, env=check_env(st))
|
|
5272
5282
|
if r.returncode != 0:
|
|
5273
5283
|
die(f"the check fails on {st['branch']} — fix it before finishing:\n"
|
|
5274
5284
|
+ "\n".join((r.stdout + r.stderr).splitlines()[-30:]))
|
|
@@ -5459,7 +5469,7 @@ def project_rules_lines(st, rules):
|
|
|
5459
5469
|
# and check; what the milestone writes itself wins. `## reviewer` is added to every review. No file = nothing changes.
|
|
5460
5470
|
PROFILES_FILE = "profiles.md"
|
|
5461
5471
|
PROFILE_MAX_CHARS = 1200 # one profile's text; longer ones bloat every brief they go into
|
|
5462
|
-
PROFILE_LIST_FIELDS = ("owns", "skills", "rules", "review")
|
|
5472
|
+
PROFILE_LIST_FIELDS = ("owns", "skills", "rules", "review", "hide keys")
|
|
5463
5473
|
PROFILE_FIELDS = ("role", "check", "repo", *PROFILE_LIST_FIELDS)
|
|
5464
5474
|
PROFILE_BULLET_RE = re.compile(r"^\s*(?:[-*+]|\d+[.)])\s+")
|
|
5465
5475
|
|
|
@@ -5512,7 +5522,7 @@ def parse_profiles(text):
|
|
|
5512
5522
|
def _profile_add(p, key, val, inline, bullet=True):
|
|
5513
5523
|
if key in ("role", "check", "repo"):
|
|
5514
5524
|
p[key] = (p[key] + " " + val).strip()
|
|
5515
|
-
elif key in ("owns", "skills"):
|
|
5525
|
+
elif key in ("owns", "skills", "hide keys"):
|
|
5516
5526
|
# comma or space separated; `apps/my web/` in backticks keeps its space
|
|
5517
5527
|
toks = re.findall(r"`([^`]+)`|([^,\s`]+)", PROFILE_BULLET_RE.sub("", val))
|
|
5518
5528
|
p[key] += [w for w in ((a or b).strip().strip("*") for a, b in toks) if w]
|
|
@@ -5554,6 +5564,30 @@ def hide_orch_dir(root):
|
|
|
5554
5564
|
ex.write_text("\n".join(lines + [".orchestrate/"]) + "\n")
|
|
5555
5565
|
|
|
5556
5566
|
|
|
5567
|
+
def check_env(st=None):
|
|
5568
|
+
"""The environment for a check orch runs: this one without the keys the `## all` profile lists under `Hide
|
|
5569
|
+
keys:` (OPENAI_API_KEY, ...), so a test that forgot its mock fails instead of calling a paid service. None
|
|
5570
|
+
(this environment, unchanged) when no profile lists any."""
|
|
5571
|
+
keys = set(((load_profiles(st)[1].get("all") or {}).get("hide keys")) or [])
|
|
5572
|
+
return {k: v for k, v in os.environ.items() if k not in keys} if keys else None
|
|
5573
|
+
|
|
5574
|
+
|
|
5575
|
+
def run_line(st, tid=None):
|
|
5576
|
+
"""The check command as coders are told to run it: when the `## all` profile hides keys, wrapped so their own run
|
|
5577
|
+
goes without them too (`env -u OPENAI_API_KEY sh -c '<check>'`); otherwise the check command unchanged."""
|
|
5578
|
+
cmd = check_for(st, tid)
|
|
5579
|
+
keys = sorted(((load_profiles(st)[1].get("all") or {}).get("hide keys")) or [])
|
|
5580
|
+
return f"env {' '.join('-u ' + k for k in keys)} sh -c {shlex.quote(cmd)}" if cmd and keys else cmd
|
|
5581
|
+
|
|
5582
|
+
|
|
5583
|
+
def all_profile_lines(st):
|
|
5584
|
+
"""The `## all` profile's rules, for every coder's task file whatever its milestone's profile ([] without)."""
|
|
5585
|
+
a = load_profiles(st)[1].get("all")
|
|
5586
|
+
if not a or not a["rules"]:
|
|
5587
|
+
return []
|
|
5588
|
+
return ["## Rules for every coder in this project (the review checks them)", *[f"- {r}" for r in a["rules"]], ""]
|
|
5589
|
+
|
|
5590
|
+
|
|
5557
5591
|
def owns_problem(o):
|
|
5558
5592
|
"""Why an `Owns:` entry can't be used (an absolute path, or one that leaves the repo), else None."""
|
|
5559
5593
|
if o.startswith(("/", "~", "\\")) or re.match(r"^[A-Za-z]:[\\/]", o):
|
|
@@ -6013,9 +6047,32 @@ def onboard_scan(root, reg=None, everyone=False):
|
|
|
6013
6047
|
"part_lines": part_only_lines(root, prof_sugg)}
|
|
6014
6048
|
|
|
6015
6049
|
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6050
|
+
# components: the parts of a repo found from what is in each folder (code, its own manifest, a Dockerfile, a
|
|
6051
|
+
# docker-compose service built from it), never from a list of folder names
|
|
6052
|
+
CODE_EXT = {".py", ".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".go", ".rs", ".java", ".kt", ".rb", ".php", ".cs",
|
|
6053
|
+
".swift", ".vue", ".svelte", ".scala", ".ex", ".exs", ".dart"}
|
|
6054
|
+
MANIFESTS = ("package.json", "pyproject.toml", "requirements.txt", "setup.py", "go.mod", "Cargo.toml", "pom.xml",
|
|
6055
|
+
"build.gradle", "build.gradle.kts", "Gemfile", "composer.json", "mix.exs", "pubspec.yaml")
|
|
6056
|
+
# folders that hold helpers, docs or data, not a component: offered only when they are deployed (Dockerfile/compose)
|
|
6057
|
+
NOT_PARTS = {"docs", "doc", "scripts", "script", "tools", "templates", "examples", "example", "samples", "output",
|
|
6058
|
+
"outputs", "data", "assets", "static", "public", "fixtures", "tests", "test", "e2e", "cypress", "notebooks",
|
|
6059
|
+
"migrations", "config", "configs", "vendor", "third_party", "tmp", "logs", "bin", "brand", "infra",
|
|
6060
|
+
"ops", "deploy", "terraform", "k8s", "helm", "charts"}
|
|
6061
|
+
PART_MIN_FILES = 5 # a folder without a manifest or Dockerfile needs this much code
|
|
6062
|
+
PART_MAX = 8 # never offer more than this many part profiles (the biggest first)
|
|
6063
|
+
# what a component does, from the packages it imports and its name: (words in imports/deps, words in the name, does)
|
|
6064
|
+
PART_ROLES = (
|
|
6065
|
+
(r"celery|dramatiq|\brq\b|bullmq|\bbull\b|\barq\b|kafka|pika|aio_pika|temporalio|sidekiq|apscheduler",
|
|
6066
|
+
r"worker|jobs?|queue|tasks?", "background jobs"),
|
|
6067
|
+
(r"qdrant|pinecone|chromadb|weaviate|faiss|pgvector|elasticsearch|opensearch|llama_index|llama-index|milvus",
|
|
6068
|
+
r"retriev|search|rag|index", "search and retrieval"),
|
|
6069
|
+
(r"airflow|prefect|dagster|luigi|apache_beam|airbyte", r"pipe|etl|ingest|flow", "data pipeline"),
|
|
6070
|
+
(r"pypdf|pdfplumber|pymupdf|fitz|unstructured|docx|tesseract|pdfminer|textract", r"^doc", "document processing"),
|
|
6071
|
+
(r"fastapi|flask|django|express|hono|fastify|@nestjs|starlette|gin-gonic|actix|axum|\bkoa\b", r"api|server|backend",
|
|
6072
|
+
"HTTP API"),
|
|
6073
|
+
(r"openai|anthropic|google\.genai|google-genai|generativeai|langchain|litellm", r"llm|agent|ai", "AI model calls"),
|
|
6074
|
+
)
|
|
6075
|
+
API_STACKS = {"NestJS", "Express", "Fastify", "Hono", "Django", "FastAPI", "Flask"}
|
|
6019
6076
|
DB_DIRS = ("supabase/migrations", "prisma/migrations", "db/migrations", "migrations", "alembic", "prisma")
|
|
6020
6077
|
SKIP_WALK = {"node_modules", ".git", ".orchestrate", "dist", "build", ".next", "vendor", "target", ".venv", "venv"}
|
|
6021
6078
|
|
|
@@ -6034,6 +6091,358 @@ def _find_dirs(root, rels, depth=3):
|
|
|
6034
6091
|
return out
|
|
6035
6092
|
|
|
6036
6093
|
|
|
6094
|
+
# the `## all` profile /orch-onboard offers in every repo: tests never spend money on outside services
|
|
6095
|
+
NO_COST_RULES = (
|
|
6096
|
+
"Tests (unit, integration, E2E, Playwright; frontend and backend) never call a paid outside service (AI, "
|
|
6097
|
+
"payments, SMS, email): mock it",
|
|
6098
|
+
"Mock the backend too: a Playwright mock alone still lets the backend call the real API",
|
|
6099
|
+
"A missing mock fails the test; never fall back to the real service",
|
|
6100
|
+
"A live test against the real service is skipped by default: ask the developer before running it")
|
|
6101
|
+
UI_STACKS = {"Next.js", "React", "React Native", "Expo", "Nuxt", "Vue", "SvelteKit", "Svelte", "Angular"}
|
|
6102
|
+
PLAYWRIGHT_RULE = ("A meaningful UI flow gets a Playwright test with outside APIs mocked, e.g. a chat message gets a "
|
|
6103
|
+
"mocked AI reply")
|
|
6104
|
+
# packages that call a paid service -> the key they read (only the names; no .env file is ever read)
|
|
6105
|
+
PAID_KEYS = (("openai", "OPENAI_API_KEY"), ("@anthropic-ai/sdk", "ANTHROPIC_API_KEY"), ("anthropic", "ANTHROPIC_API_KEY"),
|
|
6106
|
+
("@google/generative-ai", "GEMINI_API_KEY"), ("@google/genai", "GEMINI_API_KEY"),
|
|
6107
|
+
("google-generativeai", "GEMINI_API_KEY"), ("google-genai", "GEMINI_API_KEY"),
|
|
6108
|
+
("stripe", "STRIPE_SECRET_KEY"), ("razorpay", "RAZORPAY_KEY_SECRET"), ("twilio", "TWILIO_AUTH_TOKEN"),
|
|
6109
|
+
("@sendgrid/mail", "SENDGRID_API_KEY"), ("sendgrid", "SENDGRID_API_KEY"), ("resend", "RESEND_API_KEY"))
|
|
6110
|
+
KEY_NAME_RE = re.compile(r"^\s*(?:export\s+)?([A-Z][A-Z0-9_]*(?:API_KEY|SECRET_KEY|SECRET|AUTH_TOKEN|ACCESS_TOKEN))\s*=", re.M)
|
|
6111
|
+
|
|
6112
|
+
|
|
6113
|
+
def paid_keys(root, rels=("",)):
|
|
6114
|
+
"""Key names for paid outside services this repo uses: from its package.json / Python dependencies and the
|
|
6115
|
+
NAMES in .env.example-style files (never a real .env file, never a value)."""
|
|
6116
|
+
root, out = Path(root), []
|
|
6117
|
+
for rel in rels:
|
|
6118
|
+
d = root / rel
|
|
6119
|
+
deps = ""
|
|
6120
|
+
with contextlib.suppress(Exception):
|
|
6121
|
+
pj = json.loads((d / "package.json").read_text())
|
|
6122
|
+
deps += " ".join({**(pj.get("dependencies") or {}), **(pj.get("devDependencies") or {})}) + " "
|
|
6123
|
+
for f in ("requirements.txt", "pyproject.toml"):
|
|
6124
|
+
with contextlib.suppress(Exception):
|
|
6125
|
+
deps += (d / f).read_text(errors="replace").lower() + " "
|
|
6126
|
+
for pkg, key in PAID_KEYS:
|
|
6127
|
+
if re.search(r"(?<![\w@/-])" + re.escape(pkg) + r"(?![\w/-])", deps) and key not in out:
|
|
6128
|
+
out.append(key)
|
|
6129
|
+
for f in (".env.example", ".env.sample", ".env.template", ".env.dist"):
|
|
6130
|
+
with contextlib.suppress(Exception):
|
|
6131
|
+
out += [k for k in KEY_NAME_RE.findall((d / f).read_text(errors="replace")) if k not in out]
|
|
6132
|
+
return out
|
|
6133
|
+
|
|
6134
|
+
|
|
6135
|
+
JS_EXT = {".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".vue", ".svelte"}
|
|
6136
|
+
# import lines: (regex, kind). kinds ending in "dyn" are loaded at run time (a guess, never a fact)
|
|
6137
|
+
IMPORT_RES = {
|
|
6138
|
+
"py": ((re.compile(r"^[ \t]*from[ \t]+(\.*[\w.]*)[ \t]+import\b", re.M), "py"),
|
|
6139
|
+
(re.compile(r"^[ \t]*import[ \t]+([\w.]+(?:[ \t]*,[ \t]*[\w.]+)*)", re.M), "py"),
|
|
6140
|
+
(re.compile(r"(?:import_module|__import__)\(\s*['\"]([\w.]+)['\"]"), "pydyn")),
|
|
6141
|
+
"js": ((re.compile(r"\bfrom\s*['\"]([^'\"\n]+)['\"]|^[ \t]*import\s*['\"]([^'\"\n]+)['\"]|\brequire\(\s*['\"]([^'\"\n]+)['\"]",
|
|
6142
|
+
re.M), "js"),
|
|
6143
|
+
(re.compile(r"\bimport\(\s*['\"]([^'\"\n]+)['\"]"), "jsdyn")),
|
|
6144
|
+
"go": ((re.compile(r"^[ \t]*(?:import[ \t]+)?(?:[\w.]+[ \t]+)?\"([\w.-]+(?:/[\w.-]+)+)\"", re.M), "go"),),
|
|
6145
|
+
}
|
|
6146
|
+
START_SKIP = re.compile(r"lint|format|test|type|check|build|clean|prettier|prepare|install|release|docs?$")
|
|
6147
|
+
|
|
6148
|
+
|
|
6149
|
+
def _part_facts(d, root=None):
|
|
6150
|
+
"""What one folder holds: (code files, its dependencies and imports as text, has an entry point, has tests, its
|
|
6151
|
+
code's imports [(file path from root, import, kind)])."""
|
|
6152
|
+
n, text, entry, tests, seen, imps = 0, "", False, False, 0, []
|
|
6153
|
+
root = Path(root or d)
|
|
6154
|
+
for f in MANIFESTS:
|
|
6155
|
+
with contextlib.suppress(Exception):
|
|
6156
|
+
text += (d / f).read_text(errors="replace")[:20000].lower() + "\n"
|
|
6157
|
+
for cur, dirs, files in os.walk(d):
|
|
6158
|
+
dirs[:] = sorted(x for x in dirs if x not in SKIP_WALK and not x.startswith(".") and x != "__pycache__")
|
|
6159
|
+
if cur.count(os.sep) - str(d).count(os.sep) > 5:
|
|
6160
|
+
dirs[:] = []
|
|
6161
|
+
for fn in sorted(files):
|
|
6162
|
+
ext = os.path.splitext(fn)[1]
|
|
6163
|
+
if ext not in CODE_EXT:
|
|
6164
|
+
continue
|
|
6165
|
+
n += 1
|
|
6166
|
+
low = fn.lower()
|
|
6167
|
+
entry = entry or low.split(".")[0] in ("main", "app", "server", "index", "manage", "worker", "cli",
|
|
6168
|
+
"__main__", "wsgi", "asgi")
|
|
6169
|
+
tests = tests or low.startswith("test_") or ".test." in low or ".spec." in low or low.endswith("_test.go")
|
|
6170
|
+
kind = "py" if ext == ".py" else "js" if ext in JS_EXT else "go" if ext == ".go" else ""
|
|
6171
|
+
if kind and seen < 200: # the imports of the first files are enough to tell what it uses
|
|
6172
|
+
seen += 1
|
|
6173
|
+
with contextlib.suppress(Exception):
|
|
6174
|
+
with open(os.path.join(cur, fn), errors="replace") as fh:
|
|
6175
|
+
head = fh.read(4000)
|
|
6176
|
+
fr = os.path.relpath(os.path.join(cur, fn), root).replace(os.sep, "/")
|
|
6177
|
+
for rx, k in IMPORT_RES[kind]:
|
|
6178
|
+
for m in rx.findall(head):
|
|
6179
|
+
for spec in ([m] if isinstance(m, str) else [x for x in m if x]):
|
|
6180
|
+
for s in (spec.split(",") if k == "py" and not spec.startswith(".") else [spec]):
|
|
6181
|
+
if s.strip():
|
|
6182
|
+
imps.append((fr, s.strip(), k))
|
|
6183
|
+
if n >= 3000:
|
|
6184
|
+
break
|
|
6185
|
+
if n >= 3000:
|
|
6186
|
+
break
|
|
6187
|
+
text += " ".join(s.lower() for _, s, _ in imps)
|
|
6188
|
+
return n, text, entry, tests, imps
|
|
6189
|
+
|
|
6190
|
+
|
|
6191
|
+
def compose_contexts(root):
|
|
6192
|
+
"""Folders a docker-compose file builds a service from (`build: ./worker`, `context: ./services/core`)."""
|
|
6193
|
+
out = set()
|
|
6194
|
+
for f in ("docker-compose.yml", "docker-compose.yaml", "compose.yml", "compose.yaml", "docker-compose.override.yml"):
|
|
6195
|
+
with contextlib.suppress(Exception):
|
|
6196
|
+
for m in re.findall(r"^[ \t]*(?:build|context):[ \t]*['\"]?(?:\./)?([\w./-]+)", (Path(root) / f).read_text(),
|
|
6197
|
+
re.M):
|
|
6198
|
+
m = m.rstrip("/")
|
|
6199
|
+
if m and m not in (".", "..") and not m.startswith("../"):
|
|
6200
|
+
out.add(m)
|
|
6201
|
+
return out
|
|
6202
|
+
|
|
6203
|
+
|
|
6204
|
+
def _root_app(root):
|
|
6205
|
+
"""True when the repo root is itself one app (its own manifest with code dependencies), not a monorepo root: then
|
|
6206
|
+
a folder without its own manifest or Dockerfile is a folder of that app, not a component."""
|
|
6207
|
+
if any((root / f).exists() for f in ("pnpm-workspace.yaml", "lerna.json", "nx.json", "turbo.json", "go.work",
|
|
6208
|
+
"rush.json")):
|
|
6209
|
+
return False
|
|
6210
|
+
for f in ("Cargo.toml", "pyproject.toml"):
|
|
6211
|
+
with contextlib.suppress(Exception):
|
|
6212
|
+
if re.search(r"^\[(?:workspace|tool\.uv\.workspace)\]", (root / f).read_text(errors="replace"), re.M):
|
|
6213
|
+
return False
|
|
6214
|
+
if (root / "package.json").exists():
|
|
6215
|
+
with contextlib.suppress(Exception):
|
|
6216
|
+
pj = json.loads((root / "package.json").read_text())
|
|
6217
|
+
if not pj.get("workspaces") and (pj.get("dependencies") or pj.get("main") or pj.get("bin")):
|
|
6218
|
+
return True
|
|
6219
|
+
return any((root / m).exists() for m in MANIFESTS if m != "package.json")
|
|
6220
|
+
|
|
6221
|
+
|
|
6222
|
+
def _started_dirs(root):
|
|
6223
|
+
"""Top-level folders the root project starts on their own: named in a start-like package.json script, a Procfile
|
|
6224
|
+
line or a pyproject script (`worker = "worker.main:run"`)."""
|
|
6225
|
+
cmds = []
|
|
6226
|
+
with contextlib.suppress(Exception):
|
|
6227
|
+
sc = json.loads((root / "package.json").read_text()).get("scripts") or {}
|
|
6228
|
+
cmds += [v for k, v in sc.items() if isinstance(v, str) and not START_SKIP.search(k)]
|
|
6229
|
+
with contextlib.suppress(Exception):
|
|
6230
|
+
cmds += (root / "Procfile").read_text().splitlines()
|
|
6231
|
+
with contextlib.suppress(Exception):
|
|
6232
|
+
py = (root / "pyproject.toml").read_text()
|
|
6233
|
+
for blk in re.findall(r"^\[(?:project\.scripts|tool\.poetry\.scripts)\]\n((?:[^\[\n].*\n?)*)", py, re.M):
|
|
6234
|
+
cmds += [v.replace(".", "/") for v in re.findall(r"=\s*['\"]([\w.]+):", blk)]
|
|
6235
|
+
return {m for c in cmds for m in re.findall(r"(?:^|[\s'\"=(])(?:\./)?([\w.-]+)(?=$|[\s'\"/)])", c)
|
|
6236
|
+
if (root / m).is_dir()}
|
|
6237
|
+
|
|
6238
|
+
|
|
6239
|
+
def _runs_alone(d):
|
|
6240
|
+
"""A folder of code that is started by itself: a __main__.py, or a top-level file with `if __name__ ==
|
|
6241
|
+
"__main__"` or `package main`."""
|
|
6242
|
+
if (d / "__main__.py").exists():
|
|
6243
|
+
return True
|
|
6244
|
+
for p in sorted(d.iterdir()):
|
|
6245
|
+
if p.is_file() and p.suffix in (".py", ".go"):
|
|
6246
|
+
with contextlib.suppress(Exception):
|
|
6247
|
+
if re.search(r"__name__\s*==\s*['\"]__main__['\"]|^package main\b", p.read_text(errors="replace")[:20000],
|
|
6248
|
+
re.M):
|
|
6249
|
+
return True
|
|
6250
|
+
return False
|
|
6251
|
+
|
|
6252
|
+
|
|
6253
|
+
def _ts_paths(root, rel):
|
|
6254
|
+
"""The import aliases of a component (tsconfig/jsconfig `paths` and `baseUrl`): [(prefix, target path from root,
|
|
6255
|
+
star)] and the baseUrl folder from root (None when not set)."""
|
|
6256
|
+
out, base_dir = [], None
|
|
6257
|
+
for where in (rel, ""):
|
|
6258
|
+
for fn in ("tsconfig.json", "jsconfig.json"):
|
|
6259
|
+
p = root / where / fn
|
|
6260
|
+
if not p.is_file():
|
|
6261
|
+
continue
|
|
6262
|
+
with contextlib.suppress(Exception):
|
|
6263
|
+
raw = re.sub(r"//[^\n]*|/\*.*?\*/", "", p.read_text(errors="replace"), flags=re.S)
|
|
6264
|
+
co = json.loads(re.sub(r",(\s*[}\]])", r"\1", raw)).get("compilerOptions") or {}
|
|
6265
|
+
base = posixpath.normpath(posixpath.join(where or ".", co.get("baseUrl") or "."))
|
|
6266
|
+
if co.get("baseUrl") and base_dir is None:
|
|
6267
|
+
base_dir = base
|
|
6268
|
+
for pat, tg in (co.get("paths") or {}).items():
|
|
6269
|
+
if tg:
|
|
6270
|
+
star = pat.endswith("*")
|
|
6271
|
+
out.append((pat[:-1] if star else pat, posixpath.normpath(posixpath.join(base, tg[0])), star))
|
|
6272
|
+
if out or base_dir:
|
|
6273
|
+
break
|
|
6274
|
+
return out, base_dir
|
|
6275
|
+
|
|
6276
|
+
|
|
6277
|
+
def _owner(path, rels):
|
|
6278
|
+
"""The component (rel) that holds a path from the repo root, or None."""
|
|
6279
|
+
path = posixpath.normpath(path)
|
|
6280
|
+
return next((r for r in sorted(rels, key=len, reverse=True) if path == r or path.startswith(r + "/")), None)
|
|
6281
|
+
|
|
6282
|
+
|
|
6283
|
+
def part_links(root, comps):
|
|
6284
|
+
"""Which components import which: {rel: (sure, maybe)}, each a set of rels. Sure: the import leads to a file in
|
|
6285
|
+
the other component (a relative path, a tsconfig alias, its package name, its go module, or a top-level Python
|
|
6286
|
+
package). Maybe: only the name matches, or the import is dynamic (`import("...")`, `importlib.import_module`)."""
|
|
6287
|
+
rels = [r for r, _ in comps]
|
|
6288
|
+
names = {} # package names a component is imported by
|
|
6289
|
+
for r, _ in comps:
|
|
6290
|
+
d = root / r
|
|
6291
|
+
with contextlib.suppress(Exception):
|
|
6292
|
+
nm = json.loads((d / "package.json").read_text()).get("name")
|
|
6293
|
+
if nm:
|
|
6294
|
+
names[nm.lower()] = r
|
|
6295
|
+
for fn, rx in (("pyproject.toml", r"^name\s*=\s*['\"]([\w.-]+)"), ("go.mod", r"^module\s+(\S+)"),
|
|
6296
|
+
("Cargo.toml", r"^name\s*=\s*['\"]([\w-]+)")):
|
|
6297
|
+
with contextlib.suppress(Exception):
|
|
6298
|
+
m = re.search(rx, (d / fn).read_text(), re.M)
|
|
6299
|
+
if m:
|
|
6300
|
+
names[m.group(1).lower().replace("-", "_") if fn != "go.mod" else m.group(1).lower()] = r
|
|
6301
|
+
out = {}
|
|
6302
|
+
for r, f in comps:
|
|
6303
|
+
sure, maybe = set(), set()
|
|
6304
|
+
aliases, base_dir = _ts_paths(root, r)
|
|
6305
|
+
for fr, spec, kind in f["imports"]:
|
|
6306
|
+
dyn, tgt, guess = kind.endswith("dyn"), None, None
|
|
6307
|
+
if kind.startswith("py"):
|
|
6308
|
+
if spec.startswith("."):
|
|
6309
|
+
lvl = len(spec) - len(spec.lstrip("."))
|
|
6310
|
+
base = posixpath.dirname(fr)
|
|
6311
|
+
for _ in range(lvl - 1):
|
|
6312
|
+
base = posixpath.dirname(base)
|
|
6313
|
+
tgt = posixpath.join(base, spec.lstrip(".").replace(".", "/"))
|
|
6314
|
+
else:
|
|
6315
|
+
first = spec.split(".")[0].lower()
|
|
6316
|
+
here = posixpath.dirname(fr)
|
|
6317
|
+
local = any((root / x / first).exists() or (root / x / (first + ".py")).exists()
|
|
6318
|
+
for x in {here, r})
|
|
6319
|
+
if not local and first in names:
|
|
6320
|
+
tgt = names[first]
|
|
6321
|
+
elif not local and (root / first).is_dir() and first in rels:
|
|
6322
|
+
tgt = first
|
|
6323
|
+
elif not local:
|
|
6324
|
+
guess = next((x for x in rels if posixpath.basename(x).lower() == first), None)
|
|
6325
|
+
elif kind.startswith("js"):
|
|
6326
|
+
s = spec.lower()
|
|
6327
|
+
if spec.startswith("."):
|
|
6328
|
+
tgt = posixpath.join(posixpath.dirname(fr), spec)
|
|
6329
|
+
elif (nm := next((n for n in sorted(names, key=len, reverse=True) if s == n or s.startswith(n + "/")),
|
|
6330
|
+
None)):
|
|
6331
|
+
tgt = names[nm]
|
|
6332
|
+
else:
|
|
6333
|
+
for pre, path, star in aliases:
|
|
6334
|
+
if (star and spec.startswith(pre)) or (not star and spec == pre):
|
|
6335
|
+
tgt = path.replace("*", spec[len(pre):]) if star else path
|
|
6336
|
+
break
|
|
6337
|
+
if tgt is None and base_dir and _owner(posixpath.join(base_dir, spec), rels) and (
|
|
6338
|
+
root / base_dir / spec.split("/")[0]).exists():
|
|
6339
|
+
tgt = posixpath.join(base_dir, spec)
|
|
6340
|
+
if tgt is None and not re.match(r"[@~#]/", spec):
|
|
6341
|
+
bare = re.sub(r"^@[\w.-]+/", "", s).split("/")[0]
|
|
6342
|
+
guess = next((x for x in rels if posixpath.basename(x).lower() == bare), None)
|
|
6343
|
+
elif kind == "go":
|
|
6344
|
+
nm = next((n for n in sorted(names, key=len, reverse=True) if spec.lower() == n or
|
|
6345
|
+
spec.lower().startswith(n + "/")), None)
|
|
6346
|
+
tgt = names[nm] if nm else None
|
|
6347
|
+
o = _owner(tgt, rels) if tgt else None
|
|
6348
|
+
if o and o != r:
|
|
6349
|
+
(maybe if dyn else sure).add(o)
|
|
6350
|
+
elif guess and guess != r:
|
|
6351
|
+
maybe.add(guess)
|
|
6352
|
+
out[r] = (sure, maybe - sure)
|
|
6353
|
+
return out
|
|
6354
|
+
|
|
6355
|
+
|
|
6356
|
+
def repo_parts(root):
|
|
6357
|
+
"""The repo's components: [(name, rel, facts)]. A folder is one when it has its own manifest, or code and either a
|
|
6358
|
+
Dockerfile, a docker-compose service built from it, or at least PART_MIN_FILES code files. When the root is
|
|
6359
|
+
itself one app (its own manifest), its folders (src/, lib/ ...) are that app, not components: such a folder
|
|
6360
|
+
counts only when it is started by itself or is code that two components import. Helper, doc and data folders
|
|
6361
|
+
(NOT_PARTS) count only when they are deployed. A folder with no code of its own but components inside (apps/,
|
|
6362
|
+
services/, platform/services/ ...) is looked into, up to three levels down."""
|
|
6363
|
+
root = Path(root)
|
|
6364
|
+
ctx, one_app = compose_contexts(root), _root_app(root)
|
|
6365
|
+
started = _started_dirs(root) if one_app else set()
|
|
6366
|
+
|
|
6367
|
+
def judge(d, rel):
|
|
6368
|
+
name = d.name.lower()
|
|
6369
|
+
if name.startswith(".") or name in SKIP_WALK:
|
|
6370
|
+
return None
|
|
6371
|
+
n, text, entry, tests, imps = _part_facts(d, root)
|
|
6372
|
+
manifest = any((d / m).exists() for m in MANIFESTS)
|
|
6373
|
+
if not n and not manifest: # no code and nothing that builds: data, config or docs
|
|
6374
|
+
return None
|
|
6375
|
+
docker = any(d.glob("Dockerfile*")) or rel in ctx
|
|
6376
|
+
if name in NOT_PARTS and not docker:
|
|
6377
|
+
return None
|
|
6378
|
+
if not (manifest or docker or n >= PART_MIN_FILES):
|
|
6379
|
+
return None
|
|
6380
|
+
alone = manifest or docker or (one_app and "/" not in rel and (rel in started or _runs_alone(d)))
|
|
6381
|
+
return {"files": n, "text": text, "entry": entry, "tests": tests, "manifest": manifest, "docker": docker,
|
|
6382
|
+
"imports": imps, "alone": alone}
|
|
6383
|
+
|
|
6384
|
+
def own_code(d):
|
|
6385
|
+
return any(p.suffix in CODE_EXT for p in d.iterdir() if p.is_file())
|
|
6386
|
+
|
|
6387
|
+
def kids_of(d, rel, depth):
|
|
6388
|
+
out = []
|
|
6389
|
+
if d.name.startswith(".") or d.name.lower() in NOT_PARTS | SKIP_WALK:
|
|
6390
|
+
return out
|
|
6391
|
+
for c in sorted((x for x in d.iterdir() if x.is_dir()), key=lambda x: x.name):
|
|
6392
|
+
g = judge(c, f"{rel}/{c.name}")
|
|
6393
|
+
if g and (g["manifest"] or g["docker"]):
|
|
6394
|
+
out.append((c.name, f"{rel}/{c.name}", g))
|
|
6395
|
+
elif depth > 1 and not c.name.startswith(".") and not own_code(c):
|
|
6396
|
+
out += kids_of(c, f"{rel}/{c.name}", depth - 1)
|
|
6397
|
+
return out
|
|
6398
|
+
|
|
6399
|
+
out = []
|
|
6400
|
+
for d in sorted((x for x in root.iterdir() if x.is_dir()), key=lambda x: x.name) if root.is_dir() else []:
|
|
6401
|
+
f = judge(d, d.name)
|
|
6402
|
+
kids = [] if (f and (f["manifest"] or f["docker"] or own_code(d))) else kids_of(d, d.name, 3)
|
|
6403
|
+
if len(kids) >= 2 or (kids and not f):
|
|
6404
|
+
out += kids
|
|
6405
|
+
elif f:
|
|
6406
|
+
out.append((d.name, d.name, f))
|
|
6407
|
+
links = part_links(root, [(r, f) for _, r, f in out])
|
|
6408
|
+
if one_app: # the root app's own folders: only ones run alone, or shared by two
|
|
6409
|
+
alone = {r for _, r, f in out if f["alone"]}
|
|
6410
|
+
out = [x for x in out if x[1] in alone or len({r for r in alone if x[1] in links[r][0]}) >= 2]
|
|
6411
|
+
if len(out) > PART_MAX: # deployed ones, then the biggest; the developer can add the rest by hand
|
|
6412
|
+
keep = {r for _, r, _ in sorted(out, key=lambda x: (not x[2]["docker"], -x[2]["files"]))[:PART_MAX]}
|
|
6413
|
+
out = [x for x in out if x[1] in keep]
|
|
6414
|
+
names = [n.lower() for n, _, _ in out]
|
|
6415
|
+
final = {r: re.sub(r"[^a-z0-9_-]+", "-", (r.replace("/", "-") if names.count(n.lower()) > 1 else n).lower())
|
|
6416
|
+
for n, r, _ in out}
|
|
6417
|
+
for _, r, f in out: # how the components use each other, sure or only a guess
|
|
6418
|
+
sure, maybe = links[r]
|
|
6419
|
+
f["uses"] = sorted(final[x] for x in sure if x in final)
|
|
6420
|
+
f["maybe_uses"] = sorted(final[x] for x in maybe if x in final)
|
|
6421
|
+
f["used_by"] = sorted(final[x] for x in final if x != r and r in links[x][0])
|
|
6422
|
+
f["maybe_used_by"] = sorted(final[x] for x in final if x != r and r in links[x][1])
|
|
6423
|
+
return [(final[r], r, f) for _, r, f in out]
|
|
6424
|
+
|
|
6425
|
+
|
|
6426
|
+
def part_does(name, facts, stack):
|
|
6427
|
+
"""What a component does, in words, from what it imports and its name ([] when nothing tells). A link found only
|
|
6428
|
+
by name or by a dynamic import says "maybe"."""
|
|
6429
|
+
out = []
|
|
6430
|
+
for deps, nm, does in PART_ROLES:
|
|
6431
|
+
if does == "HTTP API" and API_STACKS & set(stack):
|
|
6432
|
+
continue # the stack already says it
|
|
6433
|
+
if re.search(deps, facts["text"]) or re.search(nm, name):
|
|
6434
|
+
out.append(does)
|
|
6435
|
+
if not out and facts.get("used_by") and not (facts["entry"] or facts["docker"] or UI_STACKS & set(stack)):
|
|
6436
|
+
out.append("shared code")
|
|
6437
|
+
out = out[:2]
|
|
6438
|
+
lst = lambda xs: ", ".join(xs[:3]) + (" ..." if len(xs) > 3 else "")
|
|
6439
|
+
for key, say in (("used_by", "used by "), ("maybe_used_by", "maybe used by "), ("uses", "uses "),
|
|
6440
|
+
("maybe_uses", "maybe uses ")):
|
|
6441
|
+
if facts.get(key):
|
|
6442
|
+
out.append(say + lst(facts[key]))
|
|
6443
|
+
return out
|
|
6444
|
+
|
|
6445
|
+
|
|
6037
6446
|
def profile_suggestions(root, pm=None):
|
|
6038
6447
|
"""Profiles worth offering for this repo, from its real folders and manifests (no AI, no fixed list):
|
|
6039
6448
|
[{name, owns, check, why}]. Parts of the repo (apps/*, services/*, or frontend/ + backend/ ...) only when there
|
|
@@ -6042,24 +6451,18 @@ def profile_suggestions(root, pm=None):
|
|
|
6042
6451
|
root = Path(root)
|
|
6043
6452
|
pm = pm or next((m for f, m in (("pnpm-lock.yaml", "pnpm"), ("yarn.lock", "yarn"), ("bun.lockb", "bun"),
|
|
6044
6453
|
("bun.lock", "bun")) if (root / f).exists()), None)
|
|
6045
|
-
|
|
6046
|
-
for
|
|
6047
|
-
d = root / par
|
|
6048
|
-
for c in sorted(d.iterdir(), key=lambda x: x.name) if d.is_dir() else []:
|
|
6049
|
-
if c.is_dir() and any((c / m).exists() for m in APP_MARKS):
|
|
6050
|
-
apps.append((c.name, f"{par}/{c.name}"))
|
|
6051
|
-
for n in APP_DIRS:
|
|
6052
|
-
if (root / n).is_dir() and any((root / n / m).exists() for m in APP_MARKS) and n not in {a for a, _ in apps}:
|
|
6053
|
-
apps.append((n, n))
|
|
6454
|
+
parts = repo_parts(root)
|
|
6455
|
+
apps = [(n, r) for n, r, _ in parts]
|
|
6054
6456
|
out = []
|
|
6055
6457
|
if len(apps) >= 2:
|
|
6056
|
-
for name, rel in
|
|
6458
|
+
for name, rel, facts in parts:
|
|
6057
6459
|
stk, cmds, apm = stack_of(root / rel)
|
|
6058
6460
|
test = next((c for c in cmds if c.split()[-1] == "test" or c in ("pytest", "go test ./...", "cargo test")), "")
|
|
6059
6461
|
if test and apm == "npm" and pm and pm != "npm" and not (root / rel / "package-lock.json").exists():
|
|
6060
6462
|
test = test.replace("npm", pm, 1)
|
|
6061
6463
|
out.append({"name": name, "owns": [rel + "/"], "check": f"cd {shlex.quote(rel)} && {test}" if test else "",
|
|
6062
|
-
"why": ", ".join(stk[:3]) or "a part of the repo"
|
|
6464
|
+
"why": ", ".join(stk[:3] + part_does(name, facts, stk)) or "a part of the repo",
|
|
6465
|
+
**({"rules": [PLAYWRIGHT_RULE]} if UI_STACKS & set(stk) else {})})
|
|
6063
6466
|
db = _find_dirs(root, DB_DIRS)
|
|
6064
6467
|
if db:
|
|
6065
6468
|
out.append({"name": "database", "owns": [db[0] + "/"], "check": "", "why": "migrations in " + db[0]})
|
|
@@ -6067,18 +6470,24 @@ def profile_suggestions(root, pm=None):
|
|
|
6067
6470
|
if e2e or any(root.glob("playwright.config.*")):
|
|
6068
6471
|
out.append({"name": "tests", "owns": [x + "/" for x in e2e[:2]] or ["playwright.config.*"], "check": "",
|
|
6069
6472
|
"why": "end-to-end tests"})
|
|
6070
|
-
infra = [x for x in (".github/workflows/", "Dockerfile", "docker-compose.yml", "infra/", "terraform/"
|
|
6473
|
+
infra = [x for x in (".github/workflows/", "Dockerfile", "docker-compose.yml", "infra/", "terraform/", "ops/",
|
|
6474
|
+
"deploy/", "k8s/", "helm/")
|
|
6071
6475
|
if (root / x.rstrip("/")).exists()]
|
|
6072
6476
|
if infra:
|
|
6073
6477
|
out.append({"name": "infra", "owns": infra, "check": "", "why": "CI and deployment files"})
|
|
6074
6478
|
out.append({"name": "reviewer", "owns": [], "check": "", "why": "goes into every review"})
|
|
6479
|
+
one_ui = len(apps) < 2 and bool(UI_STACKS & set(stack_of(root)[0])) # one UI app: its Playwright line goes in `all`
|
|
6480
|
+
keys = paid_keys(root, ["", *(rel for _, rel in apps)])
|
|
6481
|
+
out.append({"name": "all", "owns": [], "check": "", "why": "goes into every coder task: tests never spend money",
|
|
6482
|
+
"rules": list(NO_COST_RULES) + ([PLAYWRIGHT_RULE] if one_ui else []), "hide_keys": keys})
|
|
6075
6483
|
return out
|
|
6076
6484
|
|
|
6077
6485
|
|
|
6078
6486
|
def part_only_lines(root, sugg):
|
|
6079
6487
|
"""AGENTS.md / CLAUDE.md lines that name exactly one suggested part's folder: [(profile, file, line)]. Only a
|
|
6080
6488
|
suggestion to move them into that profile; orch never edits those files."""
|
|
6081
|
-
parts = {s["name"]: [o.rstrip("/*") for o in s["owns"] if o.endswith("/")] for s in sugg
|
|
6489
|
+
parts = {s["name"]: [o.rstrip("/*") for o in s["owns"] if o.endswith("/")] for s in sugg
|
|
6490
|
+
if s["name"] not in ("reviewer", "all")}
|
|
6082
6491
|
out = []
|
|
6083
6492
|
for f in ("AGENTS.md", "CLAUDE.md"):
|
|
6084
6493
|
try:
|
|
@@ -6114,7 +6523,9 @@ def onboard_report_lines(r):
|
|
|
6114
6523
|
("profiles.md exists" if r.get("profiles_file") else "none yet") + "):")
|
|
6115
6524
|
out += [f" - {p['name']}: " + (", ".join(f"`{o}`" if " " in o else o for o in p["owns"]) + "; "
|
|
6116
6525
|
if p["owns"] else "") + p["why"]
|
|
6117
|
-
+ (f"; check `{p['check']}`" if p["check"] else "")
|
|
6526
|
+
+ (f"; check `{p['check']}`" if p["check"] else "")
|
|
6527
|
+
+ ("\n Rules:" + "".join(f"\n - {x}" for x in p["rules"]) if p.get("rules") else "")
|
|
6528
|
+
+ (f"\n Hide keys: {', '.join(p['hide_keys'])}" if p.get("hide_keys") else "") for p in r["profiles"]]
|
|
6118
6529
|
if r.get("part_lines"):
|
|
6119
6530
|
out.append("AGENTS.md / CLAUDE.md lines about one part only (suggest moving each to that profile; orch never "
|
|
6120
6531
|
"edits these files):")
|
|
@@ -6164,12 +6575,13 @@ def profiles_plan_note():
|
|
|
6164
6575
|
profs = parse_profiles(p.read_text(errors="replace")) if p else {}
|
|
6165
6576
|
except Exception: # a problem here never stops the plan
|
|
6166
6577
|
return ""
|
|
6167
|
-
coders = [x for n, x in profs.items() if n
|
|
6168
|
-
if not coders and "reviewer" not in profs:
|
|
6578
|
+
coders = [x for n, x in profs.items() if n not in ("reviewer", "all")]
|
|
6579
|
+
if not coders and "reviewer" not in profs and "all" not in profs:
|
|
6169
6580
|
return ""
|
|
6170
6581
|
out = ["AGENT PROFILES (.orchestrate/profiles.md): " + (", ".join(
|
|
6171
6582
|
x["name"] + (f" ({', '.join(x['owns'][:3])})" if x["owns"] else "") for x in coders) or "none for coders")
|
|
6172
|
-
+ ("; `reviewer` goes into every review by itself" if "reviewer" in profs else "")
|
|
6583
|
+
+ ("; `reviewer` goes into every review by itself" if "reviewer" in profs else "")
|
|
6584
|
+
+ ("; `all` goes into every coder task by itself" if "all" in profs else "") + "."]
|
|
6173
6585
|
if coders:
|
|
6174
6586
|
out.append(" Give a milestone that fits one `Profile: <name>`: it brings that part's Role, Skills, Check and "
|
|
6175
6587
|
"house rules to the coder, so leave those lines out unless this milestone needs other ones (its "
|
|
@@ -6572,6 +6984,7 @@ def cmd_write_task(args):
|
|
|
6572
6984
|
*house, ""]
|
|
6573
6985
|
elif house:
|
|
6574
6986
|
parts += ["## House rules", *house, ""]
|
|
6987
|
+
parts += all_profile_lines(st)
|
|
6575
6988
|
contract = task_contract(st, tid)
|
|
6576
6989
|
parts += [coder_section(secs[tid].replace(f"## [x] {tid}:", "Title:", 1),
|
|
6577
6990
|
drop_criteria=bool(contract["acceptance_criteria"])), ""]
|
|
@@ -6619,7 +7032,7 @@ def cmd_write_task(args):
|
|
|
6619
7032
|
if contract["previous_work"]:
|
|
6620
7033
|
parts += ["## Earlier work", f"An earlier attempt ({contract['previous_work']['by'] or 'another coder'}) left "
|
|
6621
7034
|
"work in this folder. Look at it first and continue from it unless it is wrong.", ""]
|
|
6622
|
-
parts += [f"## Check command\n`{
|
|
7035
|
+
parts += [f"## Check command\n`{run_line(st, tid)}`", "", WORKER_RULES]
|
|
6623
7036
|
out = d / TASK_DIR / tid / "task.md"
|
|
6624
7037
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
6625
7038
|
out.write_text("\n".join(parts))
|
|
@@ -6655,7 +7068,7 @@ def task_contract(st, tid):
|
|
|
6655
7068
|
"files_allowed": t.get("files") or [], "scope": st.get("scope", "warn"),
|
|
6656
7069
|
"tier": t.get("tier"), "needs": t.get("needs") or [], "role": t.get("role") or None,
|
|
6657
7070
|
"interfaces": items("interfaces"), "constraints": items("constraints"), "out_of_scope": items("out of scope"),
|
|
6658
|
-
"depends_on": deps, "check":
|
|
7071
|
+
"depends_on": deps, "check": run_line(st, tid), "attempt": t.get("attempt", 0) + 1, "lost_attempts": t.get("lost", 0),
|
|
6659
7072
|
"previous_work": {"by": t.get("last_worker")} if work_ref(st, tid) else None,
|
|
6660
7073
|
"result_format": RESULT_FORMAT,
|
|
6661
7074
|
}
|
|
@@ -8083,13 +8496,13 @@ def _autopilot(args):
|
|
|
8083
8496
|
def checking(tid):
|
|
8084
8497
|
return any(j["tid"] == tid and j["kind"] == "check" for j in bg.values())
|
|
8085
8498
|
|
|
8086
|
-
def bg_start(name, tid, kind, shell_cmd, cwd, uses_check, on_done, timeout=None):
|
|
8499
|
+
def bg_start(name, tid, kind, shell_cmd, cwd, uses_check, on_done, timeout=None, env=None):
|
|
8087
8500
|
log, ex = BG_DIR / f"{name}.log", BG_DIR / f"{name}.exit"
|
|
8088
8501
|
ex.unlink(missing_ok=True)
|
|
8089
8502
|
q = shlex.quote
|
|
8090
8503
|
wrapped = (f"( {shell_cmd}\n) > {q(str(log))} 2>&1; echo $? > {q(str(ex))}.tmp; "
|
|
8091
8504
|
f"mv {q(str(ex))}.tmp {q(str(ex))}")
|
|
8092
|
-
p = subprocess.Popen(["/bin/sh", "-c", wrapped], cwd=cwd, stdin=subprocess.DEVNULL,
|
|
8505
|
+
p = subprocess.Popen(["/bin/sh", "-c", wrapped], cwd=cwd, stdin=subprocess.DEVNULL, env=env,
|
|
8093
8506
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
|
|
8094
8507
|
bg[name] = {"p": p, "tid": tid, "kind": kind, "t0": time.time(), "log": log, "exit": ex,
|
|
8095
8508
|
"uses_check": uses_check, "on_done": on_done, "timeout": timeout}
|
|
@@ -8172,7 +8585,8 @@ def _autopilot(args):
|
|
|
8172
8585
|
tree0 = tree_of(d)
|
|
8173
8586
|
patch_state(lambda s2: s2["tasks"][tid].update(checking={"since": now(), "where": "worktree"}))
|
|
8174
8587
|
bg_start(f"check-{tid}-{k}", tid, "check", check_for(s_, tid), d, True,
|
|
8175
|
-
lambda code, out, secs: check_done(tid, k, d, tree0, code, out, secs), CHECK_TIMEOUT_S
|
|
8588
|
+
lambda code, out, secs: check_done(tid, k, d, tree0, code, out, secs), CHECK_TIMEOUT_S,
|
|
8589
|
+
env=check_env(s_))
|
|
8176
8590
|
return True
|
|
8177
8591
|
|
|
8178
8592
|
def check_done(tid, k, d, tree0, code, out, secs):
|
|
@@ -8405,7 +8819,7 @@ def _autopilot(args):
|
|
|
8405
8819
|
f"# {tid} changed files outside its scope (round {n})\n\n"
|
|
8406
8820
|
f"This milestone may change only: {', '.join(allowed)}. It also changed: "
|
|
8407
8821
|
f"{', '.join(new)}.\nUndo those changes, or, if the task truly can't be done without them, "
|
|
8408
|
-
f"leave them and explain why in your report. Then run `{
|
|
8822
|
+
f"leave them and explain why in your report. Then run `{run_line(st, tid)}`.\n"),
|
|
8409
8823
|
f"still outside its scope after {MAX_FIX} fix rounds: {', '.join(new)}")
|
|
8410
8824
|
return False
|
|
8411
8825
|
if new:
|
|
@@ -8428,7 +8842,7 @@ def _autopilot(args):
|
|
|
8428
8842
|
+ "\n".join(f"- {c['id']}: {c.get('evidence', '')}" for c in unmet)
|
|
8429
8843
|
+ (f"\n\nAlready deferred by the developer (leave them; keep them `met: false`): "
|
|
8430
8844
|
f"{', '.join(skipped)}." if skipped else "")
|
|
8431
|
-
+ f"\n\nFinish them (you decide how), run `{
|
|
8845
|
+
+ f"\n\nFinish them (you decide how), run `{run_line(st, tid)}`, and write a new result.\n"
|
|
8432
8846
|
"If one truly can't be met in this repo (for example an outside API or service it needs does not "
|
|
8433
8847
|
"exist), don't try again: set status `question`, say which criterion and why, and offer to "
|
|
8434
8848
|
"build the rest and defer that one. The developer decides.\n"),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "herdr-orchestra",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.51.0",
|
|
4
4
|
"description": "Orchestrate AI coding agents (Claude Code, Codex, OpenCode, Amp, Pi) as one team: a lead plans, coders build, a reviewer checks, you get one PR. Runs in Herdr panes, or in one Pi window with subagents.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
package/playbooks/onboard.md
CHANGED
|
@@ -24,7 +24,7 @@ Make one short list. Each item is a file you would write, and only when somethin
|
|
|
24
24
|
- **A folder link** when an agent can't see the skills (the gap says `<agent> can't see ...`): `orch onboard link <its folder> <folder with the skills>`, for example `orch onboard link .agents/skills .agent/skills` when Codex is in the team and the skills are in `.agent/skills`. One copy, no files copied. No `can't see` gap: no link item.
|
|
25
25
|
- **Skills that clash with orch** (the gap lists them): nothing to write. orch tells coders not to use them during a run; the skills stay as they are. Offer it as an item that is ticked by default.
|
|
26
26
|
|
|
27
|
-
- **Agent profiles**: one item per profile under `Profiles you could add` (never another), each a `## <name>` section of `.orchestrate/profiles.md`: `Role
|
|
27
|
+
- **Agent profiles**: one item per profile under `Profiles you could add` (never another), each a `## <name>` section of `.orchestrate/profiles.md`: `Role:` from what it does (listed) and its code, `Owns:` and `Check:` as listed, fitting `Skills:`, and `Rules:` (2 to 6, for THAT part only, from its code: where new files go, what to reuse). Never a line AGENTS.md, CLAUDE.md or coding-standards.md has. `reviewer`: `Rules:` every review should check. `all` (every coder, ticked by default): its listed `Rules:` and `Hide keys:` word for word; listed rules of a part go in that part's `Rules:`. A `lines about one part only` line: offer moving it to that profile; the developer deletes it from the file.
|
|
28
28
|
|
|
29
29
|
Where do the new skills go: in the skill folder the repo already uses (the `Project skills:` line above), else `.agents/skills`. If the team has an agent that doesn't read that folder, add the link item too.
|
|
30
30
|
|