tempergraph 0.7.1__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.
- tempergraph/__init__.py +8 -0
- tempergraph/__main__.py +5 -0
- tempergraph/api.py +428 -0
- tempergraph/audit/__init__.py +305 -0
- tempergraph/audit/catalog.py +342 -0
- tempergraph/audit/definition.py +387 -0
- tempergraph/audit/history.py +414 -0
- tempergraph/audit/history_rules.py +268 -0
- tempergraph/audit/history_rules_more.py +244 -0
- tempergraph/audit/host.py +270 -0
- tempergraph/audit/owned.py +96 -0
- tempergraph/audit/prompts.py +89 -0
- tempergraph/audit/report.py +248 -0
- tempergraph/audit/revisit.py +220 -0
- tempergraph/audit/surface.py +224 -0
- tempergraph/audit/text_health.py +176 -0
- tempergraph/audit/tools.py +391 -0
- tempergraph/author/__init__.py +2 -0
- tempergraph/author/blueprint.py +346 -0
- tempergraph/author/compare.py +122 -0
- tempergraph/author/criteria_lint.py +200 -0
- tempergraph/author/draw.py +112 -0
- tempergraph/author/inventory.py +210 -0
- tempergraph/author/literals.py +138 -0
- tempergraph/author/scaffold.py +568 -0
- tempergraph/author/session.py +439 -0
- tempergraph/author/trial.py +391 -0
- tempergraph/author/verify.py +353 -0
- tempergraph/builtin/__init__.py +1 -0
- tempergraph/builtin/upgrade.py +288 -0
- tempergraph/catalog.py +134 -0
- tempergraph/check_helpers.py +99 -0
- tempergraph/cli/__init__.py +1 -0
- tempergraph/cli/audit.py +190 -0
- tempergraph/cli/author.py +361 -0
- tempergraph/cli/improve.py +564 -0
- tempergraph/cli/improve_review.py +111 -0
- tempergraph/cli/install.py +35 -0
- tempergraph/cli/main.py +1261 -0
- tempergraph/cli/observe_cli.py +544 -0
- tempergraph/cli/outcome.py +77 -0
- tempergraph/cli/schedule_cli.py +1090 -0
- tempergraph/cli/upgrade.py +126 -0
- tempergraph/cli/workflows.py +96 -0
- tempergraph/compiler/__init__.py +6 -0
- tempergraph/compiler/graph.py +305 -0
- tempergraph/compiler/state.py +229 -0
- tempergraph/constants.py +72 -0
- tempergraph/contracts.py +1025 -0
- tempergraph/data/executor_compat.json +11 -0
- tempergraph/data/promotion.json +35 -0
- tempergraph/data/release.json +20 -0
- tempergraph/detach.py +65 -0
- tempergraph/docs.py +90 -0
- tempergraph/durability/__init__.py +2 -0
- tempergraph/durability/alias.py +66 -0
- tempergraph/durability/carry.py +591 -0
- tempergraph/durability/checkpoint.py +179 -0
- tempergraph/durability/control.py +109 -0
- tempergraph/durability/engine_file.py +301 -0
- tempergraph/durability/lock.py +138 -0
- tempergraph/durability/status.py +390 -0
- tempergraph/engine_identity.py +42 -0
- tempergraph/executor_compat.py +56 -0
- tempergraph/executors/__init__.py +4 -0
- tempergraph/executors/binding.py +91 -0
- tempergraph/executors/capabilities.py +95 -0
- tempergraph/executors/claude.py +603 -0
- tempergraph/executors/launcher.py +394 -0
- tempergraph/executors/mcpconfig.py +156 -0
- tempergraph/executors/mcpproxy.py +216 -0
- tempergraph/executors/preflight.py +196 -0
- tempergraph/executors/registry.py +71 -0
- tempergraph/executors/scripted.py +18 -0
- tempergraph/executors/session.py +107 -0
- tempergraph/executors/standins.py +118 -0
- tempergraph/executors/summary.py +110 -0
- tempergraph/executors/viewcatalog.py +27 -0
- tempergraph/git.py +403 -0
- tempergraph/identity.py +65 -0
- tempergraph/improve/__init__.py +5 -0
- tempergraph/improve/analysis.py +437 -0
- tempergraph/improve/artifact.py +477 -0
- tempergraph/improve/autonomy.py +192 -0
- tempergraph/improve/bindings.py +191 -0
- tempergraph/improve/calibration.py +1016 -0
- tempergraph/improve/causes.py +416 -0
- tempergraph/improve/child.py +651 -0
- tempergraph/improve/codehost.py +520 -0
- tempergraph/improve/digest.py +472 -0
- tempergraph/improve/escape.py +100 -0
- tempergraph/improve/filing.py +1047 -0
- tempergraph/improve/harvest.py +158 -0
- tempergraph/improve/issue_context.py +192 -0
- tempergraph/improve/lenses.py +204 -0
- tempergraph/improve/lessons.py +233 -0
- tempergraph/improve/loop_report.py +138 -0
- tempergraph/improve/loop_summary.py +85 -0
- tempergraph/improve/lost.py +119 -0
- tempergraph/improve/measure.py +121 -0
- tempergraph/improve/params.py +98 -0
- tempergraph/improve/pause_facts.py +134 -0
- tempergraph/improve/pr_later.py +186 -0
- tempergraph/improve/prebinding.py +130 -0
- tempergraph/improve/promotion.py +413 -0
- tempergraph/improve/proposals.py +934 -0
- tempergraph/improve/record.py +322 -0
- tempergraph/improve/release.py +89 -0
- tempergraph/improve/reliability.py +457 -0
- tempergraph/improve/repeat.py +115 -0
- tempergraph/improve/review.py +910 -0
- tempergraph/improve/suites.py +586 -0
- tempergraph/improve/trials.py +525 -0
- tempergraph/install/__init__.py +11 -0
- tempergraph/install/bootstrap.py +133 -0
- tempergraph/install/environment.py +173 -0
- tempergraph/install/launch.py +37 -0
- tempergraph/install/python.py +53 -0
- tempergraph/install/reconcile.py +52 -0
- tempergraph/install/selfcheck.py +29 -0
- tempergraph/install/shim.py +81 -0
- tempergraph/install/update.py +400 -0
- tempergraph/model/__init__.py +0 -0
- tempergraph/model/diagram.py +185 -0
- tempergraph/model/flow.py +324 -0
- tempergraph/model/prompt_lint.py +203 -0
- tempergraph/model/retire.py +52 -0
- tempergraph/model/subworkflow.py +274 -0
- tempergraph/model/text.py +67 -0
- tempergraph/model/validate.py +1158 -0
- tempergraph/observe/__init__.py +1 -0
- tempergraph/observe/attention.py +196 -0
- tempergraph/observe/detail.py +773 -0
- tempergraph/observe/forget.py +138 -0
- tempergraph/observe/hooks.py +272 -0
- tempergraph/observe/labels.py +95 -0
- tempergraph/observe/overlay.py +46 -0
- tempergraph/observe/report.py +402 -0
- tempergraph/observe/risk_report.py +110 -0
- tempergraph/observe/rows.py +444 -0
- tempergraph/observe/sinks.py +793 -0
- tempergraph/observe/supervision_cost.py +797 -0
- tempergraph/observe/supervision_report.py +295 -0
- tempergraph/observe/switch_report.py +140 -0
- tempergraph/package/__init__.py +2 -0
- tempergraph/package/change_report.py +116 -0
- tempergraph/package/changelog.py +263 -0
- tempergraph/package/docs_check.py +115 -0
- tempergraph/package/importer.py +90 -0
- tempergraph/package/inventory.py +111 -0
- tempergraph/package/loader.py +250 -0
- tempergraph/package/manifest.py +256 -0
- tempergraph/package/readiness.py +124 -0
- tempergraph/package/registry.py +383 -0
- tempergraph/package/rules.py +128 -0
- tempergraph/package/scan.py +65 -0
- tempergraph/package/selftest.py +348 -0
- tempergraph/package/stamp.py +213 -0
- tempergraph/package/transforms.py +481 -0
- tempergraph/package/upgrade.py +625 -0
- tempergraph/provenance.py +183 -0
- tempergraph/py.typed +0 -0
- tempergraph/release.py +17 -0
- tempergraph/render/__init__.py +0 -0
- tempergraph/render/output.py +72 -0
- tempergraph/render/prompt.py +166 -0
- tempergraph/render/template.py +86 -0
- tempergraph/run/__init__.py +2 -0
- tempergraph/run/asking.py +233 -0
- tempergraph/run/audit.py +63 -0
- tempergraph/run/check_worker.py +167 -0
- tempergraph/run/checks.py +517 -0
- tempergraph/run/commands.py +210 -0
- tempergraph/run/complexity.py +268 -0
- tempergraph/run/contest.py +76 -0
- tempergraph/run/council.py +368 -0
- tempergraph/run/council_run.py +527 -0
- tempergraph/run/events.py +279 -0
- tempergraph/run/finalize.py +132 -0
- tempergraph/run/gate.py +747 -0
- tempergraph/run/guard.py +89 -0
- tempergraph/run/judging.py +357 -0
- tempergraph/run/ladder.py +230 -0
- tempergraph/run/log.py +600 -0
- tempergraph/run/mapping.py +183 -0
- tempergraph/run/nodes.py +2304 -0
- tempergraph/run/outcome.py +255 -0
- tempergraph/run/outcome_record.py +292 -0
- tempergraph/run/outcome_trust.py +99 -0
- tempergraph/run/rerun.py +351 -0
- tempergraph/run/reserve.py +85 -0
- tempergraph/run/resources.py +76 -0
- tempergraph/run/risk.py +231 -0
- tempergraph/run/runner.py +1579 -0
- tempergraph/run/scriptcache.py +178 -0
- tempergraph/run/selfcheck.py +105 -0
- tempergraph/run/session_record.py +72 -0
- tempergraph/run/subrun.py +278 -0
- tempergraph/run/supervision.py +125 -0
- tempergraph/run/tool_access.py +101 -0
- tempergraph/schedule/__init__.py +25 -0
- tempergraph/schedule/credentials.py +167 -0
- tempergraph/schedule/echo.py +169 -0
- tempergraph/schedule/exact.py +275 -0
- tempergraph/schedule/export.py +164 -0
- tempergraph/schedule/launch.py +89 -0
- tempergraph/schedule/ledger.py +133 -0
- tempergraph/schedule/loop.py +176 -0
- tempergraph/schedule/model.py +440 -0
- tempergraph/schedule/policies.py +414 -0
- tempergraph/schedule/store.py +150 -0
- tempergraph/schedule/tick.py +377 -0
- tempergraph/schedule/token.py +81 -0
- tempergraph/schedule/triggers.py +210 -0
- tempergraph/schedule/words.py +423 -0
- tempergraph/security/__init__.py +0 -0
- tempergraph/security/launch.py +25 -0
- tempergraph/security/scrub.py +58 -0
- tempergraph/settings.py +950 -0
- tempergraph/store/__init__.py +0 -0
- tempergraph/store/codelog.py +73 -0
- tempergraph/store/layout.py +198 -0
- tempergraph/store/logs.py +325 -0
- tempergraph/store/manifest.py +99 -0
- tempergraph/store/migrate.py +188 -0
- tempergraph/workspace.py +874 -0
- tempergraph-0.7.1.dist-info/METADATA +70 -0
- tempergraph-0.7.1.dist-info/RECORD +232 -0
- tempergraph-0.7.1.dist-info/WHEEL +5 -0
- tempergraph-0.7.1.dist-info/entry_points.txt +5 -0
- tempergraph-0.7.1.dist-info/top_level.txt +2 -0
- tempergraph_pytest_plugin.py +64 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
"""The home workflow registry, `registry.json` (UPD-B20 to UPD-B24, ADR `registered-workflows-are-reinstalled-and-pinned-never-lost`), and the `workflows` verbs' logic.
|
|
2
|
+
|
|
3
|
+
The registry lives in the home folder, outside every engine environment. No verb but `unregister` removes
|
|
4
|
+
an entry; a path that disappeared keeps its entry as `missing`. Loading and validation call no model.
|
|
5
|
+
|
|
6
|
+
Release 1 has no managed engine environment yet (plan T8.2), so `reinstall` checks each package's declared
|
|
7
|
+
requirements against the dependency gate and records their digest, but installs nothing: a package that
|
|
8
|
+
declares requirements is reported `dependencies_pending` until the environment exists.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import hashlib
|
|
14
|
+
import json
|
|
15
|
+
import os
|
|
16
|
+
from collections.abc import Callable, Mapping
|
|
17
|
+
from dataclasses import dataclass, field
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
from tempergraph.constants import ENGINE_VERSION
|
|
22
|
+
from tempergraph.contracts import Capabilities
|
|
23
|
+
from tempergraph.docs import write_json
|
|
24
|
+
from tempergraph.git import GitError, git
|
|
25
|
+
from tempergraph.model.validate import Finding, validate
|
|
26
|
+
from tempergraph.package.importer import private_name
|
|
27
|
+
from tempergraph.package.loader import LoadedPackage, PackageNotLoaded, load_package
|
|
28
|
+
from tempergraph.package.manifest import ENGINE_JSON, workflow_name
|
|
29
|
+
from tempergraph.store.layout import ensure_home, home_path, lock_path, now_iso
|
|
30
|
+
|
|
31
|
+
SCHEMA_VERSION = 1
|
|
32
|
+
KINDS = ("plugin", "local", "builtin")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class RegistryRefusal(Exception):
|
|
36
|
+
def __init__(self, code: str, message: str, findings: list[Finding] | None = None) -> None:
|
|
37
|
+
super().__init__(f"{code}: {message}")
|
|
38
|
+
self.code = code
|
|
39
|
+
self.findings = findings or []
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def plugin_cache() -> Path:
|
|
43
|
+
"""Claude Code's plugin cache (research `updating-a-tool-with-long-lived-runs` U4); `CLAUDE_CONFIG_DIR` moves it."""
|
|
44
|
+
base = os.environ.get("CLAUDE_CONFIG_DIR")
|
|
45
|
+
return (Path(base) if base else Path.home() / ".claude") / "plugins" / "cache"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def registry_path(home: Path | None = None) -> Path:
|
|
49
|
+
return (home or home_path()) / "registry.json"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def read_entries(home: Path | None = None) -> list[dict[str, Any]]:
|
|
53
|
+
path = registry_path(home)
|
|
54
|
+
try:
|
|
55
|
+
doc = json.loads(path.read_text(encoding="utf-8"))
|
|
56
|
+
except FileNotFoundError:
|
|
57
|
+
return []
|
|
58
|
+
except (OSError, ValueError) as exc:
|
|
59
|
+
raise RegistryRefusal("registry-unreadable", f"{path}: {type(exc).__name__}") from exc
|
|
60
|
+
rows = doc.get("workflows") if isinstance(doc, dict) else None
|
|
61
|
+
return [dict(r) for r in rows or [] if isinstance(r, dict) and r.get("name")]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def write_entries(entries: list[dict[str, Any]], home: Path | None = None) -> None:
|
|
65
|
+
home = ensure_home(home)
|
|
66
|
+
write_json(registry_path(home), {"schema_version": SCHEMA_VERSION,
|
|
67
|
+
"workflows": sorted(entries, key=lambda e: str(e["name"]))})
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def requirements_digest(deps: tuple[str, ...]) -> str:
|
|
71
|
+
return hashlib.sha256("\n".join(sorted(" ".join(d.split()) for d in deps)).encode()).hexdigest()[:16]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@dataclass(kw_only=True)
|
|
75
|
+
class Checked:
|
|
76
|
+
"""One load and validation of a registered or candidate package."""
|
|
77
|
+
|
|
78
|
+
entry: dict[str, Any]
|
|
79
|
+
loaded: LoadedPackage | None = None
|
|
80
|
+
findings: list[Finding] = field(default_factory=list)
|
|
81
|
+
remedy: str = ""
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def ok(self) -> bool:
|
|
85
|
+
return self.loaded is not None and not any(f.severity == "error" for f in self.findings)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def check_package(path: Path, caps: Mapping[str, Capabilities], entry: dict[str, Any] | None = None) -> Checked:
|
|
89
|
+
"""Load and validate; fill the entry's state, versions and requirement fields."""
|
|
90
|
+
e = dict(entry or {})
|
|
91
|
+
last_seen = e.get("last_checked_at")
|
|
92
|
+
e["last_checked_at"] = now_iso()
|
|
93
|
+
if not path.exists():
|
|
94
|
+
e["state"] = "missing"
|
|
95
|
+
return Checked(entry=e, findings=[Finding("missing", None, f"{path} does not exist")])
|
|
96
|
+
try:
|
|
97
|
+
loaded = load_package(path)
|
|
98
|
+
except PackageNotLoaded as exc:
|
|
99
|
+
e["state"], e["reason"] = "not_loaded", exc.reason
|
|
100
|
+
found = exc.findings or [Finding(exc.reason, None, exc.detail or str(exc))]
|
|
101
|
+
return Checked(entry=e, findings=found, remedy=exc.remedy)
|
|
102
|
+
findings = validate(loaded.spec, caps)
|
|
103
|
+
deps = loaded.pyproject.dependencies if loaded.pyproject else ()
|
|
104
|
+
last_version, last_wv = e.get("version"), e.get("workflow_version")
|
|
105
|
+
if (e.get("kind") == "plugin" and last_version == loaded.spec.version and last_wv
|
|
106
|
+
and last_wv != loaded.workflow_version):
|
|
107
|
+
findings.append(Finding("version-not-bumped", None, f"content changed under version {last_version}; "
|
|
108
|
+
"the plugin cache is keyed by the version string (VER-B14, VER-B15)", "warning"))
|
|
109
|
+
if last_version and (last_version != loaded.spec.version or (last_wv and last_wv != loaded.workflow_version)):
|
|
110
|
+
e["previous"] = {"version": last_version, "workflow_version": last_wv, # UPD-B25: the last-seen state
|
|
111
|
+
"outcome_revision": e.get("outcome_revision"), "seen_at": last_seen}
|
|
112
|
+
outcome = loaded.spec.outcome
|
|
113
|
+
e.update(version=loaded.spec.version, workflow_version=loaded.workflow_version,
|
|
114
|
+
outcome_revision=int(getattr(outcome, "revision", 0) or 0),
|
|
115
|
+
requirements_digest=requirements_digest(deps))
|
|
116
|
+
e.pop("reason", None)
|
|
117
|
+
errors = [f for f in findings if f.severity == "error"]
|
|
118
|
+
if errors:
|
|
119
|
+
e["state"], e["reason"] = "not_loaded", "invalid"
|
|
120
|
+
elif e.get("engine_pin"):
|
|
121
|
+
e["state"] = "pinned"
|
|
122
|
+
else:
|
|
123
|
+
e["state"] = "ok"
|
|
124
|
+
if deps and ENGINE_VERSION not in (e.get("installed_into") or []):
|
|
125
|
+
e["dependencies"] = "pending" # no managed environment before plan T8.2
|
|
126
|
+
else:
|
|
127
|
+
e.pop("dependencies", None)
|
|
128
|
+
return Checked(entry=e, loaded=loaded, findings=findings)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def register(path: Path, caps: Mapping[str, Capabilities], *, check_only: bool = False,
|
|
132
|
+
home: Path | None = None) -> Checked:
|
|
133
|
+
"""`workflows register <path> [--check]`: a local source that loads and validates (UPD-B20 to UPD-B24)."""
|
|
134
|
+
root = path.expanduser().resolve()
|
|
135
|
+
if root.is_relative_to(plugin_cache().resolve()):
|
|
136
|
+
raise RegistryRefusal("plugin-cache-path", f"{root} is in Claude Code's plugin cache; installed workflow "
|
|
137
|
+
"plugins are registered by `tempergraph install` or `update`")
|
|
138
|
+
if not (root / ENGINE_JSON).is_file():
|
|
139
|
+
raise RegistryRefusal("not-a-package", f"{root} holds no tempergraph.json, so it is not a workflow package")
|
|
140
|
+
entries = read_entries(home)
|
|
141
|
+
kept_keys = ("version", "workflow_version", "outcome_revision", "last_checked_at", "previous")
|
|
142
|
+
seen = next((e for e in entries if Path(str(e.get("path") or "")).resolve() == root), {})
|
|
143
|
+
got = check_package(root, caps, {"kind": "local", "path": str(root), **{k: seen[k] for k in kept_keys if k in seen}})
|
|
144
|
+
if got.loaded is None or not got.ok:
|
|
145
|
+
raise RegistryRefusal("not-valid", f"{root} does not load and validate", got.findings)
|
|
146
|
+
name = got.loaded.spec.name
|
|
147
|
+
for e in entries:
|
|
148
|
+
same_private = private_name(str(e["name"])) == private_name(name)
|
|
149
|
+
if (e["name"] == name or same_private) and Path(str(e.get("path") or "")).resolve() != root:
|
|
150
|
+
raise RegistryRefusal("name-taken", f"workflow {e['name']!r} is registered from {e.get('path')}")
|
|
151
|
+
prior = next((e for e in entries if e["name"] == name), {})
|
|
152
|
+
entry = {**prior, **got.entry, "name": name, "kind": prior.get("kind", "local"), "path": str(root),
|
|
153
|
+
"registered_at": prior.get("registered_at") or now_iso(), "engine_pin": prior.get("engine_pin"),
|
|
154
|
+
"installed_into": prior.get("installed_into") or []}
|
|
155
|
+
got.entry = entry
|
|
156
|
+
if not check_only:
|
|
157
|
+
write_entries([e for e in entries if e["name"] != name] + [entry], home)
|
|
158
|
+
return got
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _git_out(cwd: Path, *args: str) -> str | None:
|
|
162
|
+
try:
|
|
163
|
+
out = git(list(args), cwd, timeout_s=30).strip()
|
|
164
|
+
except GitError:
|
|
165
|
+
return None
|
|
166
|
+
return out or None
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def other_checkout(root: Path, name: str, home: Path | None = None) -> Path | None:
|
|
170
|
+
"""The registered path of `name` when it is another checkout of the package at `root`: both folders lie in
|
|
171
|
+
working trees of one git repository and sit at the same place from their top levels (SCF-B24). None otherwise,
|
|
172
|
+
and None when git cannot answer."""
|
|
173
|
+
root = root.expanduser().resolve()
|
|
174
|
+
for e in read_entries(home):
|
|
175
|
+
if not (e["name"] == name or private_name(str(e["name"])) == private_name(name)):
|
|
176
|
+
continue
|
|
177
|
+
other = Path(str(e.get("path") or "")).resolve()
|
|
178
|
+
if other == root or not other.is_dir() or not root.is_dir():
|
|
179
|
+
return None
|
|
180
|
+
mine = _git_out(root, "rev-parse", "--path-format=absolute", "--git-common-dir", "--show-toplevel")
|
|
181
|
+
theirs = _git_out(other, "rev-parse", "--path-format=absolute", "--git-common-dir", "--show-toplevel")
|
|
182
|
+
if mine is None or theirs is None:
|
|
183
|
+
return None
|
|
184
|
+
(mine_common, mine_top), (their_common, their_top) = mine.splitlines(), theirs.splitlines()
|
|
185
|
+
if Path(mine_common).resolve() != Path(their_common).resolve():
|
|
186
|
+
return None
|
|
187
|
+
if root.relative_to(Path(mine_top).resolve()) != other.relative_to(Path(their_top).resolve()):
|
|
188
|
+
return None
|
|
189
|
+
return other
|
|
190
|
+
return None
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def live_threads(name: str, state_roots: list[Path]) -> list[str]:
|
|
194
|
+
"""Threads of the workflow holding a run lock in the given state roots (WSP, DUR)."""
|
|
195
|
+
from tempergraph.durability.lock import is_held
|
|
196
|
+
|
|
197
|
+
out = []
|
|
198
|
+
for root in state_roots:
|
|
199
|
+
folder = lock_path(root, name, "x").parent
|
|
200
|
+
for lock in sorted(folder.glob("*.lock")) if folder.is_dir() else []:
|
|
201
|
+
if is_held(lock):
|
|
202
|
+
out.append(f"{name}:{lock.stem}")
|
|
203
|
+
return out
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def unregister(name: str, state_roots: list[Path], *, home: Path | None = None) -> dict[str, Any]:
|
|
207
|
+
"""Remove the entry only, never files; refused while a thread of it is live (UPD-B20 to UPD-B24)."""
|
|
208
|
+
entries = read_entries(home)
|
|
209
|
+
entry = next((e for e in entries if e["name"] == name), None)
|
|
210
|
+
if entry is None:
|
|
211
|
+
raise RegistryRefusal("unknown-workflow", f"{name!r} is not registered")
|
|
212
|
+
live = live_threads(name, state_roots)
|
|
213
|
+
if live:
|
|
214
|
+
raise RegistryRefusal("thread-live", f"{name!r} has live threads: {', '.join(live)}")
|
|
215
|
+
write_entries([e for e in entries if e["name"] != name], home)
|
|
216
|
+
return entry
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def reinstall(names: list[str] | None, caps: Mapping[str, Capabilities], *, home: Path | None = None,
|
|
220
|
+
path_of: Callable[[dict[str, Any]], Path] | None = None, installer: Installer | None = None,
|
|
221
|
+
engine: str | None = None) -> list[Checked]:
|
|
222
|
+
"""Dependencies into the current environment (pending before T8.2), then load and validate; clears a pin
|
|
223
|
+
that no longer applies (UPD-B20 to UPD-B24)."""
|
|
224
|
+
entries = read_entries(home)
|
|
225
|
+
chosen = entries if names is None else [e for e in entries if e["name"] in names]
|
|
226
|
+
unknown = set(names or ()) - {str(e["name"]) for e in entries}
|
|
227
|
+
if unknown:
|
|
228
|
+
raise RegistryRefusal("unknown-workflow", f"not registered: {', '.join(sorted(unknown))}")
|
|
229
|
+
out = []
|
|
230
|
+
for e in chosen:
|
|
231
|
+
path = path_of(e) if path_of else Path(str(e.get("path") or ""))
|
|
232
|
+
got = check_package(path, caps, e)
|
|
233
|
+
dep_error = install_dependencies(got, installer, engine or ENGINE_VERSION) if got.loaded is not None \
|
|
234
|
+
and installer is not None else None
|
|
235
|
+
if got.ok and dep_error is None and e.get("engine_pin"):
|
|
236
|
+
got.entry["engine_pin"], got.entry["state"] = None, "ok" # the pin no longer applies
|
|
237
|
+
out.append(got)
|
|
238
|
+
done = {str(c.entry["name"]): c.entry for c in out}
|
|
239
|
+
write_entries([done.get(str(e["name"]), e) for e in entries], home)
|
|
240
|
+
return out
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
Installer = Callable[[str, list[str]], str | None] # (workflow name, requirement lines) -> an error, or None
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def install_dependencies(got: Checked, installer: Installer | None, engine: str) -> str | None:
|
|
247
|
+
"""UPD-B20 to UPD-B24: the package's declared requirements, through the dependency gate, into this environment.
|
|
248
|
+
Returns the reason they are not installed, or None. Without an installer nothing is installed and an
|
|
249
|
+
entry that declares requirements stays `dependencies: pending`."""
|
|
250
|
+
from tempergraph.package.manifest import gate_dependencies
|
|
251
|
+
|
|
252
|
+
deps = tuple(got.loaded.pyproject.dependencies) if got.loaded and got.loaded.pyproject else ()
|
|
253
|
+
e = got.entry
|
|
254
|
+
if not deps:
|
|
255
|
+
e.pop("dependencies", None)
|
|
256
|
+
return None
|
|
257
|
+
if engine in (e.get("installed_into") or []) and e.get("installed_digest") == e.get("requirements_digest"):
|
|
258
|
+
e.pop("dependencies", None)
|
|
259
|
+
return None
|
|
260
|
+
if installer is None:
|
|
261
|
+
e["dependencies"] = "pending"
|
|
262
|
+
return None
|
|
263
|
+
refused = gate_dependencies(deps)
|
|
264
|
+
if refused:
|
|
265
|
+
got.findings += refused
|
|
266
|
+
e["dependencies"] = "refused"
|
|
267
|
+
return "dependency_refused"
|
|
268
|
+
err = installer(str(e.get("name") or "workflow"), list(deps))
|
|
269
|
+
if err:
|
|
270
|
+
got.findings.append(Finding("dependency_conflict", None, err[:300]))
|
|
271
|
+
e["dependencies"] = "failed"
|
|
272
|
+
return "dependency_conflict"
|
|
273
|
+
e["installed_into"] = sorted({*(e.get("installed_into") or []), engine})
|
|
274
|
+
e["installed_digest"] = e.get("requirements_digest")
|
|
275
|
+
e.pop("dependencies", None)
|
|
276
|
+
return None
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def settle(got: Checked, *, was: str | None, previous: str | None, dep_error: str | None) -> Checked:
|
|
280
|
+
"""UPD-B7's table: a workflow that worked on the old engine and fails on this one is pinned to the old
|
|
281
|
+
one; one that never worked is `not_loaded`; one that works has its pin cleared (UPD-B8)."""
|
|
282
|
+
e = got.entry
|
|
283
|
+
works = got.ok and dep_error is None
|
|
284
|
+
if works:
|
|
285
|
+
e["engine_pin"], e["state"] = None, "ok"
|
|
286
|
+
e.pop("reason", None)
|
|
287
|
+
return got
|
|
288
|
+
reason = dep_error or next((f.code for f in got.findings if f.severity == "error"), "not_loaded")
|
|
289
|
+
if isinstance(e.get("engine_pin"), dict):
|
|
290
|
+
e["state"] = "pinned"
|
|
291
|
+
elif was == "ok" and previous:
|
|
292
|
+
e["engine_pin"] = {"engine": previous, "reason": reason, "since": now_iso()}
|
|
293
|
+
e["state"] = "pinned"
|
|
294
|
+
else:
|
|
295
|
+
e["engine_pin"], e["state"], e["reason"] = None, "not_loaded", reason
|
|
296
|
+
return got
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
def after_update(caps: Mapping[str, Capabilities], *, previous: str | None, engine: str,
|
|
300
|
+
installer: Installer | None = None, cache: Path | None = None,
|
|
301
|
+
home: Path | None = None) -> list[Checked]:
|
|
302
|
+
"""`update` step 6 inside the new environment: reconcile the registry, install every entry's
|
|
303
|
+
dependencies, load and validate each, and pin what broke. No entry is ever removed (UPD-AC7)."""
|
|
304
|
+
before = {str(e.get("name")): e.get("state") for e in read_entries(home)}
|
|
305
|
+
reconcile(caps, cache=cache, home=home)
|
|
306
|
+
out: list[Checked] = []
|
|
307
|
+
entries = read_entries(home)
|
|
308
|
+
for e in entries:
|
|
309
|
+
path = Path(str(e.get("path") or ""))
|
|
310
|
+
got = check_package(path, caps, e)
|
|
311
|
+
dep_error = install_dependencies(got, installer, engine) if got.loaded is not None else None
|
|
312
|
+
out.append(settle(got, was=before.get(str(e.get("name"))), previous=previous, dep_error=dep_error))
|
|
313
|
+
write_entries([c.entry for c in out], home)
|
|
314
|
+
return out
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def listing(home: Path | None = None) -> dict[str, Any]:
|
|
318
|
+
from tempergraph.package import change_report
|
|
319
|
+
|
|
320
|
+
rows = []
|
|
321
|
+
for e in read_entries(home):
|
|
322
|
+
row: dict[str, Any] = {k: e.get(k) for k in ("name", "kind", "plugin", "path", "version", "workflow_version", "state",
|
|
323
|
+
"reason", "engine_pin", "dependencies", "registered_at",
|
|
324
|
+
"last_checked_at") if k in e or k in ("state", "engine_pin")}
|
|
325
|
+
prev = e.get("previous")
|
|
326
|
+
row["previous_version"] = prev.get("version") if isinstance(prev, Mapping) else None
|
|
327
|
+
row["changes_since_previous"] = change_report.count(change_report.build(e)) if prev else 0
|
|
328
|
+
rows.append(row)
|
|
329
|
+
return {"schema_version": SCHEMA_VERSION, "workflows": rows}
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
def _version_key(v: str) -> tuple[Any, ...]:
|
|
333
|
+
parts = []
|
|
334
|
+
for p in v.split("+", 1)[0].split("."):
|
|
335
|
+
parts.append((0, int(p), "") if p.isdigit() else (1, 0, p))
|
|
336
|
+
return tuple(parts)
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def cached_plugins(cache: Path | None = None) -> dict[str, Path]:
|
|
340
|
+
"""`<plugin>@<marketplace>` -> its newest non-orphaned version folder holding a workflow package
|
|
341
|
+
(`<cache>/<marketplace>/<plugin>/<version>/`, research `updating-a-tool-with-long-lived-runs` U4)."""
|
|
342
|
+
root = cache or plugin_cache()
|
|
343
|
+
out: dict[str, Path] = {}
|
|
344
|
+
for market in sorted(p for p in root.iterdir() if p.is_dir()) if root.is_dir() else []:
|
|
345
|
+
for plugin in sorted(p for p in market.iterdir() if p.is_dir()):
|
|
346
|
+
versions = [v for v in plugin.iterdir() if v.is_dir() and (v / ENGINE_JSON).is_file()
|
|
347
|
+
and not (v / ".orphaned_at").exists()]
|
|
348
|
+
if versions:
|
|
349
|
+
out[f"{plugin.name}@{market.name}"] = max(versions, key=lambda v: _version_key(v.name))
|
|
350
|
+
return out
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
def reconcile(caps: Mapping[str, Capabilities], *, cache: Path | None = None,
|
|
354
|
+
home: Path | None = None) -> list[Checked]:
|
|
355
|
+
"""Repoint `plugin` entries to their current cache folder, register newly installed workflow plugins,
|
|
356
|
+
mark a vanished one `missing`, never delete one (UPD-B20 to UPD-B24, PKG-B1)."""
|
|
357
|
+
entries = read_entries(home)
|
|
358
|
+
found = cached_plugins(cache)
|
|
359
|
+
by_plugin = {str(e.get("plugin")): e for e in entries if e.get("kind") == "plugin"}
|
|
360
|
+
out: list[Checked] = []
|
|
361
|
+
kept: list[dict[str, Any]] = [e for e in entries if e.get("kind") != "plugin"]
|
|
362
|
+
taken = {str(e["name"]) for e in kept}
|
|
363
|
+
for pid, path in sorted(found.items()):
|
|
364
|
+
prior = by_plugin.pop(pid, None)
|
|
365
|
+
base = dict(prior) if prior else {"kind": "plugin", "plugin": pid, "registered_at": now_iso(),
|
|
366
|
+
"engine_pin": None, "installed_into": []}
|
|
367
|
+
base["path"] = str(path)
|
|
368
|
+
got = check_package(path, caps, base)
|
|
369
|
+
name = got.loaded.spec.name if got.loaded else str(base.get("name") or workflow_name(pid.split("@", 1)[0]))
|
|
370
|
+
if name in taken:
|
|
371
|
+
got.findings.append(Finding("name-taken", None, f"{pid}: workflow {name!r} is already registered"))
|
|
372
|
+
out.append(got)
|
|
373
|
+
continue
|
|
374
|
+
got.entry["name"] = name
|
|
375
|
+
taken.add(name)
|
|
376
|
+
kept.append(got.entry)
|
|
377
|
+
out.append(got)
|
|
378
|
+
for e in by_plugin.values(): # uninstalled: keep the entry and its threads
|
|
379
|
+
e = {**e, "state": "missing", "last_checked_at": now_iso()}
|
|
380
|
+
kept.append(e)
|
|
381
|
+
out.append(Checked(entry=e, findings=[Finding("missing", None, f"{e.get('plugin')} is not in the cache")]))
|
|
382
|
+
write_entries(kept, home)
|
|
383
|
+
return out
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"""The package rules of PKG, applied after WFM `validate` (PKG-B15, PKG-B16, PKG-B17 step 6, PKG-B11, PKG-B12, PKG-B19, PKG-B20, PKG-B11, PKG-B13, PKG-B14, PKG-B17, PKG-B18, PKG-B19, PKG-B20, PKG-B23)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from tempergraph.contracts import TextRef, WorkflowSpec
|
|
9
|
+
from tempergraph.model.validate import Finding
|
|
10
|
+
from tempergraph.package.inventory import PackageInventory
|
|
11
|
+
from tempergraph.package.manifest import Manifests, Pyproject
|
|
12
|
+
|
|
13
|
+
# Refused plugin parts (PKG-B11, PKG-B12, ADR `plugin-content-reaches-each-executor-by-a-declared-route`): code -> remedy.
|
|
14
|
+
REMEDY = {
|
|
15
|
+
"plugin-hooks": "declare the tools the step needs; lifecycle hooks are registered with `tempergraph hooks add`",
|
|
16
|
+
"plugin-mcp": "declare the step's MCP tools as `mcp:<server>/<tool>`; the server is configured on the machine",
|
|
17
|
+
"plugin-bin": "run programs from a script unit or a declared command, not from the plugin's bin/",
|
|
18
|
+
"plugin-session-settings": "a step's session is configured by its declaration, not by plugin settings",
|
|
19
|
+
"plugin-instruction-file": "Claude Code does not read it from a plugin; put the text in prompts/ or a skill",
|
|
20
|
+
}
|
|
21
|
+
# Files the layout requires once a package exists, short of those whose absence stops loading (PKG-B11, PKG-B12).
|
|
22
|
+
REQUIRED_FILES = ("README.md", "docs", "tests", "diagram", "evals/cases.json")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _refused(code: str, what: str) -> Finding:
|
|
26
|
+
return Finding(code, None, f"{what} is refused in a workflow package: {REMEDY[code]}")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def plugin_parts(root: Path, manifests: Manifests) -> list[Finding]:
|
|
30
|
+
out: list[Finding] = []
|
|
31
|
+
plugin = manifests.plugin
|
|
32
|
+
if (root / "hooks" / "hooks.json").exists() or "hooks" in plugin:
|
|
33
|
+
out.append(_refused("plugin-hooks", "hooks/hooks.json or a `hooks` manifest key"))
|
|
34
|
+
if (root / ".mcp.json").exists() or "mcpServers" in plugin:
|
|
35
|
+
out.append(_refused("plugin-mcp", ".mcp.json or `mcpServers`"))
|
|
36
|
+
if (root / "bin").exists():
|
|
37
|
+
out.append(_refused("plugin-bin", "bin/"))
|
|
38
|
+
settings = root / "settings.json"
|
|
39
|
+
agent_settings = False
|
|
40
|
+
if settings.is_file():
|
|
41
|
+
try:
|
|
42
|
+
agent_settings = "agent" in json.loads(settings.read_text(encoding="utf-8"))
|
|
43
|
+
except (OSError, ValueError, TypeError):
|
|
44
|
+
agent_settings = False
|
|
45
|
+
if (root / ".lsp.json").exists() or "lspServers" in plugin or agent_settings:
|
|
46
|
+
out.append(_refused("plugin-session-settings", ".lsp.json, `lspServers` or settings.json with `agent`"))
|
|
47
|
+
for name in ("CLAUDE.md", "AGENTS.md"):
|
|
48
|
+
if (root / name).exists():
|
|
49
|
+
out.append(_refused("plugin-instruction-file", name))
|
|
50
|
+
return out
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def layout(root: Path, manifests: Manifests, pyproject: Pyproject, inventory: PackageInventory) -> list[Finding]:
|
|
54
|
+
out: list[Finding] = []
|
|
55
|
+
want = f"tgwf-{manifests.engine.name}"
|
|
56
|
+
if pyproject.name != want:
|
|
57
|
+
out.append(Finding("pyproject-name", None, f"workflow/pyproject.toml name is {pyproject.name!r}; "
|
|
58
|
+
f"it must be {want!r}"))
|
|
59
|
+
for rel in REQUIRED_FILES:
|
|
60
|
+
if not inventory.has(rel):
|
|
61
|
+
out.append(Finding("package-file-missing", None, f"{rel} is part of every package (PKG-B11, PKG-B12)",
|
|
62
|
+
"warning"))
|
|
63
|
+
return out
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def check_cases(spec: WorkflowSpec, root: Path) -> list[Finding]:
|
|
67
|
+
"""EVS-B1: every check is tested both ways, with a must-pass and a must-fail fixture under
|
|
68
|
+
`evals/checks/<unit>/`."""
|
|
69
|
+
out: list[Finding] = []
|
|
70
|
+
for name, u in spec.units.items():
|
|
71
|
+
if u.gate.check is None:
|
|
72
|
+
continue
|
|
73
|
+
base = root / "evals" / "checks" / name
|
|
74
|
+
for which, code in (("must-fail", "check_without_fail_case"), ("must-pass", "check_without_pass_case")):
|
|
75
|
+
if not any((base / which).glob("*")):
|
|
76
|
+
out.append(Finding(code, name, f"the check of {name} has no {which} fixture under "
|
|
77
|
+
f"evals/checks/{name}/{which}/ (EVS-B9, EVS-B2, EVS-B10)", "warning"))
|
|
78
|
+
return out
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def text_refs(spec: WorkflowSpec, root: Path) -> list[Finding]:
|
|
82
|
+
"""Every `text()` reference and judge file resolves inside the package (PKG-B19, PKG-B20, PKG-B11, PKG-B13, PKG-B14, PKG-B17, PKG-B18, PKG-B23 `text-ref`)."""
|
|
83
|
+
out: list[Finding] = []
|
|
84
|
+
base = root.resolve()
|
|
85
|
+
|
|
86
|
+
def check(unit: str, rel: str) -> None:
|
|
87
|
+
path = (base / rel).resolve()
|
|
88
|
+
if not path.is_relative_to(base):
|
|
89
|
+
out.append(Finding("text-ref", unit, f"{rel}: outside the package"))
|
|
90
|
+
elif not path.is_file():
|
|
91
|
+
out.append(Finding("text-ref", unit, f"{rel}: no such file in the package"))
|
|
92
|
+
|
|
93
|
+
for name, u in spec.units.items():
|
|
94
|
+
if u.step is not None and isinstance(u.step.prompt, TextRef):
|
|
95
|
+
check(name, u.step.prompt.path)
|
|
96
|
+
if u.gate.judge is not None and u.gate.judge.file:
|
|
97
|
+
check(name, u.gate.judge.file)
|
|
98
|
+
return out
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def change_files(root: Path) -> list[Finding]:
|
|
102
|
+
"""PKG-B27 `changes-version`: a `changes/<version>.json` whose `version` is not its file name. A file name that
|
|
103
|
+
is not a version and a file that is not JSON are skipped here."""
|
|
104
|
+
from tempergraph.package.changelog import releases
|
|
105
|
+
|
|
106
|
+
out: list[Finding] = []
|
|
107
|
+
for _, path in releases(root / "changes"):
|
|
108
|
+
try:
|
|
109
|
+
doc = json.loads(path.read_text(encoding="utf-8"))
|
|
110
|
+
except (OSError, ValueError):
|
|
111
|
+
continue
|
|
112
|
+
if isinstance(doc, dict) and doc.get("version") != path.stem:
|
|
113
|
+
out.append(Finding("changes-version", None, f"changes/{path.stem}.json holds version "
|
|
114
|
+
f"{doc.get('version')!r}; it must be {path.stem!r}"))
|
|
115
|
+
return out
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def criteria_twice(spec: WorkflowSpec, inline: dict[str, set[str]]) -> list[Finding]:
|
|
119
|
+
"""An id given both inline on a gate and in `outcome.json` (PKG-B19, PKG-B20 `criterion-declared-twice`)."""
|
|
120
|
+
if spec.outcome is None:
|
|
121
|
+
return []
|
|
122
|
+
out = []
|
|
123
|
+
for unit, ids in inline.items():
|
|
124
|
+
inter = spec.outcome.intermediate.get(unit)
|
|
125
|
+
dup = ids & {c.id for c in inter.criteria if c.id} if inter is not None else set()
|
|
126
|
+
for cid in sorted(dup):
|
|
127
|
+
out.append(Finding("criterion-declared-twice", unit, f"criterion {cid!r} is inline and in outcome.json"))
|
|
128
|
+
return out
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""The source scan of a package's Python half, before any import (PKG-B15, PKG-B16, PKG-B17 step 3, PKG-B4).
|
|
2
|
+
|
|
3
|
+
Imports are limited to the standard library, the requirements in `pyproject.toml`, the package's own
|
|
4
|
+
modules (imported relatively, because the entry module is imported under its private name) and
|
|
5
|
+
`tempergraph.api`. The scan reads the source with `ast`; nothing is executed.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import ast
|
|
11
|
+
import sys
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from tempergraph.model.validate import Finding
|
|
15
|
+
from tempergraph.package.manifest import normalized
|
|
16
|
+
|
|
17
|
+
PUBLIC_MODULE = "tempergraph.api"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _imports(tree: ast.Module) -> list[tuple[str, int, bool]]:
|
|
21
|
+
"""(module, line, relative) for every import; `from tempergraph import x` yields `tempergraph.x`."""
|
|
22
|
+
out: list[tuple[str, int, bool]] = []
|
|
23
|
+
for node in ast.walk(tree):
|
|
24
|
+
if isinstance(node, ast.Import):
|
|
25
|
+
out += [(a.name, node.lineno, False) for a in node.names]
|
|
26
|
+
elif isinstance(node, ast.ImportFrom):
|
|
27
|
+
if node.level:
|
|
28
|
+
out.append((node.module or "", node.lineno, True))
|
|
29
|
+
elif node.module == "tempergraph":
|
|
30
|
+
out += [(f"tempergraph.{a.name}", node.lineno, False) for a in node.names]
|
|
31
|
+
elif node.module:
|
|
32
|
+
out.append((node.module, node.lineno, False))
|
|
33
|
+
return out
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def scan(package_path: Path, module: str, requirements: tuple[str, ...]) -> list[Finding]:
|
|
37
|
+
src = package_path / "workflow"
|
|
38
|
+
allowed = {normalized(r) for r in requirements}
|
|
39
|
+
stdlib = set(sys.stdlib_module_names) | {"__future__"}
|
|
40
|
+
out: list[Finding] = []
|
|
41
|
+
for path in sorted(src.rglob("*.py")):
|
|
42
|
+
rel = path.relative_to(package_path).as_posix()
|
|
43
|
+
try:
|
|
44
|
+
tree = ast.parse(path.read_text(encoding="utf-8"), filename=rel)
|
|
45
|
+
except (OSError, SyntaxError, ValueError) as exc:
|
|
46
|
+
out.append(Finding("source-unparsable", None, f"{rel}: {type(exc).__name__}"))
|
|
47
|
+
continue
|
|
48
|
+
for name, line, relative in _imports(tree):
|
|
49
|
+
if relative:
|
|
50
|
+
continue
|
|
51
|
+
top = name.partition(".")[0]
|
|
52
|
+
where = f"{rel}:{line}"
|
|
53
|
+
if top == "tempergraph":
|
|
54
|
+
if name != PUBLIC_MODULE and not name.startswith(PUBLIC_MODULE + "."):
|
|
55
|
+
out.append(Finding("private-engine-import", None,
|
|
56
|
+
f"{where} imports {name}; a workflow imports only {PUBLIC_MODULE}"))
|
|
57
|
+
elif top == module:
|
|
58
|
+
out.append(Finding("own-module-absolute-import", None,
|
|
59
|
+
f"{where} imports {name} by its folder name; import the package's own "
|
|
60
|
+
"modules relatively (`from . import checks`)"))
|
|
61
|
+
elif top not in stdlib and normalized(top) not in allowed:
|
|
62
|
+
out.append(Finding("undeclared-import", None,
|
|
63
|
+
f"{where} imports {top}, which is neither the standard library nor a "
|
|
64
|
+
"requirement in workflow/pyproject.toml", "warning"))
|
|
65
|
+
return out
|