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,423 @@
|
|
|
1
|
+
"""The word grammar (SCH-B16, SCH-B17, SCH-B2; ADR `exact-formats-first-and-an-optional-word-grammar-echoed-back`): English phrases into the canonical form of their exact twins.
|
|
2
|
+
|
|
3
|
+
A grammar, not a guesser: a phrase is read by fixed rules, ends in the same builders as the exact formats, and a
|
|
4
|
+
phrase with more than one reading is a `Needs` with the readings as choices, each reading being a phrase that says
|
|
5
|
+
it explicitly. A phrase that matches no rule is refused `when_unparsed` with the nearest phrases.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import dataclasses
|
|
11
|
+
import difflib
|
|
12
|
+
import re
|
|
13
|
+
from dataclasses import dataclass
|
|
14
|
+
from datetime import date, datetime, time, timedelta
|
|
15
|
+
|
|
16
|
+
from tempergraph.schedule.exact import (
|
|
17
|
+
ABBREVIATIONS,
|
|
18
|
+
Parsed,
|
|
19
|
+
build_once,
|
|
20
|
+
build_recur,
|
|
21
|
+
check_zone,
|
|
22
|
+
interval_rule,
|
|
23
|
+
local_now,
|
|
24
|
+
parse_wall,
|
|
25
|
+
resolve_zone,
|
|
26
|
+
with_bounds,
|
|
27
|
+
)
|
|
28
|
+
from tempergraph.schedule.model import Needs, Reading, Rule, ScheduleError, floor_minute, zone_of
|
|
29
|
+
|
|
30
|
+
TEMPLATES = (
|
|
31
|
+
"in 2 hours", "tomorrow at 9am", "at 18:00", "next monday at 10:00", "on dec 1 at 08:00", "2026-12-01 08:00",
|
|
32
|
+
"every day at 9am", "daily at 09:00", "every weekday at 8:00", "every monday and thursday at 7pm",
|
|
33
|
+
"every 2 weeks on friday at 16:00", "every month on the 1st at 9am", "every month on the last day at 17:00",
|
|
34
|
+
"every first monday of the month at 9am", "every 2 hours", "every 30 minutes", "hourly",
|
|
35
|
+
"every 2 hours between 9am and 5pm on weekdays",
|
|
36
|
+
)
|
|
37
|
+
WEEKDAYS = {"monday": 0, "mon": 0, "tuesday": 1, "tue": 1, "wednesday": 2, "wed": 2, "thursday": 3, "thu": 3,
|
|
38
|
+
"friday": 4, "fri": 4, "saturday": 5, "sat": 5, "sunday": 6, "sun": 6}
|
|
39
|
+
MONTHS = {"january": 1, "february": 2, "march": 3, "april": 4, "may": 5, "june": 6, "july": 7, "august": 8,
|
|
40
|
+
"september": 9, "october": 10, "november": 11, "december": 12, "jan": 1, "feb": 2, "mar": 3, "apr": 4,
|
|
41
|
+
"jun": 6, "jul": 7, "aug": 8, "sep": 9, "sept": 9, "oct": 10, "nov": 11, "dec": 12}
|
|
42
|
+
ORDINALS = {"first": 1, "second": 2, "third": 3, "fourth": 4, "fifth": 5, "last": -1}
|
|
43
|
+
_WD = "|".join(sorted(WEEKDAYS, key=len, reverse=True))
|
|
44
|
+
_MON = "|".join(sorted(MONTHS, key=len, reverse=True))
|
|
45
|
+
_STRICT = r"(?:noon|midnight|\d{1,2}(?::\d{2})?\s*(?:am|pm)|\d{1,2}:\d{2})"
|
|
46
|
+
_TIME = rf"(?:{_STRICT}|\d{{1,2}})"
|
|
47
|
+
WEEKDAY_SET = tuple((0, d) for d in range(5))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class _Ctx:
|
|
52
|
+
now: datetime
|
|
53
|
+
zone: str
|
|
54
|
+
notes: list[str]
|
|
55
|
+
tail: str = ""
|
|
56
|
+
suffix: str = ""
|
|
57
|
+
from_date: date | None = None
|
|
58
|
+
until: str | None = None
|
|
59
|
+
count: int | None = None
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def now_wall(self) -> datetime:
|
|
63
|
+
return local_now(self.now, self.zone)
|
|
64
|
+
|
|
65
|
+
@property
|
|
66
|
+
def today(self) -> date:
|
|
67
|
+
return self.now_wall.date()
|
|
68
|
+
|
|
69
|
+
def compose(self, main: str) -> str:
|
|
70
|
+
return main + self.tail + self.suffix
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _unparsed(raw: str) -> ScheduleError:
|
|
74
|
+
near = difflib.get_close_matches(raw.lower(), TEMPLATES, n=3, cutoff=0.0)
|
|
75
|
+
return ScheduleError("when_unparsed", f"{raw!r} matches no rule; the nearest phrases are: " + "; ".join(near))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _hhmm(h: int, m: int) -> str:
|
|
79
|
+
return f"{h:02d}:{m:02d}"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _time_of(tok: str, raw: str) -> tuple[int, int, tuple[int, int] | None]:
|
|
83
|
+
"""(hour, minute, the other reading of a bare hour 1 to 12, else None)."""
|
|
84
|
+
tok = re.sub(r"\s+", "", tok)
|
|
85
|
+
if tok == "noon":
|
|
86
|
+
return 12, 0, None
|
|
87
|
+
if tok == "midnight":
|
|
88
|
+
return 0, 0, None
|
|
89
|
+
m = re.fullmatch(r"(\d{1,2})(?::(\d{2}))?(am|pm)", tok)
|
|
90
|
+
if m:
|
|
91
|
+
h, mi = int(m.group(1)), int(m.group(2) or 0)
|
|
92
|
+
if not 1 <= h <= 12 or mi > 59:
|
|
93
|
+
raise _unparsed(raw)
|
|
94
|
+
return h % 12 + (12 if m.group(3) == "pm" else 0), mi, None
|
|
95
|
+
m = re.fullmatch(r"(\d{1,2}):(\d{2})", tok)
|
|
96
|
+
if m:
|
|
97
|
+
h, mi = int(m.group(1)), int(m.group(2))
|
|
98
|
+
if h > 23 or mi > 59:
|
|
99
|
+
raise _unparsed(raw)
|
|
100
|
+
return h, mi, None
|
|
101
|
+
if tok.isdigit():
|
|
102
|
+
h = int(tok)
|
|
103
|
+
if 1 <= h <= 12:
|
|
104
|
+
return h, 0, ((h + 12) % 24, 0) # 9 is 09:00 or 21:00; 12 is 12:00 or 00:00
|
|
105
|
+
if h == 0 or 13 <= h <= 23:
|
|
106
|
+
return h, 0, None
|
|
107
|
+
raise _unparsed(raw)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _yearless(month: int, day: int, c: _Ctx, raw: str) -> date:
|
|
111
|
+
try:
|
|
112
|
+
cand = date(c.today.year, month, day)
|
|
113
|
+
return cand if cand >= c.today else date(c.today.year + 1, month, day)
|
|
114
|
+
except ValueError:
|
|
115
|
+
raise _unparsed(raw) from None
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _date_of(tok: str, c: _Ctx, raw: str) -> date:
|
|
119
|
+
tok = tok.strip()
|
|
120
|
+
if tok == "today":
|
|
121
|
+
return c.today
|
|
122
|
+
if tok == "tomorrow":
|
|
123
|
+
return c.today + timedelta(days=1)
|
|
124
|
+
m = re.fullmatch(r"(\d{4})-(\d{2})-(\d{2})", tok)
|
|
125
|
+
if m:
|
|
126
|
+
try:
|
|
127
|
+
return date(int(m.group(1)), int(m.group(2)), int(m.group(3)))
|
|
128
|
+
except ValueError:
|
|
129
|
+
raise _unparsed(raw) from None
|
|
130
|
+
m = re.fullmatch(rf"({_MON})\.?\s+(\d{{1,2}})(?:st|nd|rd|th)?(?:,?\s+(\d{{4}}))?", tok)
|
|
131
|
+
mon, day, year = (m.group(1), m.group(2), m.group(3)) if m else (None, None, None)
|
|
132
|
+
if not m:
|
|
133
|
+
m = re.fullmatch(rf"(\d{{1,2}})(?:st|nd|rd|th)?\s+({_MON})\.?(?:,?\s+(\d{{4}}))?", tok)
|
|
134
|
+
if m:
|
|
135
|
+
day, mon, year = m.group(1), m.group(2), m.group(3)
|
|
136
|
+
if m and mon and day:
|
|
137
|
+
if year:
|
|
138
|
+
try:
|
|
139
|
+
return date(int(year), MONTHS[mon], int(day))
|
|
140
|
+
except ValueError:
|
|
141
|
+
raise _unparsed(raw) from None
|
|
142
|
+
return _yearless(MONTHS[mon], int(day), c, raw)
|
|
143
|
+
m = re.fullmatch(r"(\d{1,2})[/.\-](\d{1,2})(?:[/.\-](\d{2,4}))?", tok)
|
|
144
|
+
if m:
|
|
145
|
+
a, b = int(m.group(1)), int(m.group(2))
|
|
146
|
+
isos: list[str] = []
|
|
147
|
+
for month, dom in ((a, b), (b, a)):
|
|
148
|
+
try:
|
|
149
|
+
if m.group(3):
|
|
150
|
+
y = int(m.group(3)) + (2000 if len(m.group(3)) == 2 else 0)
|
|
151
|
+
found = date(y, month, dom)
|
|
152
|
+
else:
|
|
153
|
+
found = _yearless(month, dom, c, raw)
|
|
154
|
+
except (ValueError, ScheduleError):
|
|
155
|
+
continue
|
|
156
|
+
if found.isoformat() not in isos:
|
|
157
|
+
isos.append(found.isoformat())
|
|
158
|
+
if not isos:
|
|
159
|
+
raise _unparsed(raw)
|
|
160
|
+
raise ScheduleError("date_ambiguous", f"{tok!r} is a month and a day in either order; write an ISO date: "
|
|
161
|
+
+ " or ".join(isos))
|
|
162
|
+
raise _unparsed(raw)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def _daylist(text: str) -> list[int] | None:
|
|
166
|
+
names = [n.strip() for n in re.split(r",|\band\b", text) if n.strip()]
|
|
167
|
+
days = []
|
|
168
|
+
for n in names:
|
|
169
|
+
n = n[:-1] if n.endswith("s") and n[:-1] in WEEKDAYS else n
|
|
170
|
+
if n not in WEEKDAYS:
|
|
171
|
+
return None
|
|
172
|
+
days.append(WEEKDAYS[n])
|
|
173
|
+
return sorted(set(days)) or None
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
def _need_time(c: _Ctx, core: str, tail_suffix: str) -> Needs:
|
|
177
|
+
return Needs("the phrase gives no time of day; 09:00 is offered and never applied silently",
|
|
178
|
+
[Reading("09:00", c.compose(f"{core} at 09:00{tail_suffix}"))])
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
# --- once --------------------------------------------------------------------------------------------------------
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
def _once(c: _Ctx, main: str, raw: str) -> Parsed:
|
|
185
|
+
if c.from_date or c.until or c.count:
|
|
186
|
+
raise _unparsed(raw) # a bound belongs to a recurrence
|
|
187
|
+
if main == "in half an hour":
|
|
188
|
+
return build_once(c.now_wall + timedelta(minutes=30), c.zone, c.now, c.notes)
|
|
189
|
+
m = re.fullmatch(r"in (?:(\d+)|an?) (minute|hour|day|week)s?", main)
|
|
190
|
+
if m:
|
|
191
|
+
n = int(m.group(1)) if m.group(1) else 1
|
|
192
|
+
if n == 0:
|
|
193
|
+
raise _unparsed(raw)
|
|
194
|
+
unit = m.group(2)
|
|
195
|
+
if unit in ("minute", "hour"): # now plus the elapsed time, as local time in the zone
|
|
196
|
+
at = floor_minute(c.now) + timedelta(**{unit + "s": n})
|
|
197
|
+
wall = at.astimezone(zone_of(c.zone)).replace(tzinfo=None)
|
|
198
|
+
else:
|
|
199
|
+
wall = c.now_wall + timedelta(days=n * (7 if unit == "week" else 1))
|
|
200
|
+
return build_once(wall, c.zone, c.now, c.notes)
|
|
201
|
+
if re.fullmatch(r"\d{4}-\d{2}-\d{2}[t ]\d{2}:\d{2}(?::\d{2})?\s*(?:z|[+-]\d{2}:?\d{2})?", main):
|
|
202
|
+
wall, _ = parse_wall(main.upper(), c.zone, "the phrase", c.notes)
|
|
203
|
+
return build_once(wall, c.zone, c.now, c.notes)
|
|
204
|
+
body = main[3:] if main.startswith("on ") else main
|
|
205
|
+
day_text, tok = "", None
|
|
206
|
+
m = re.fullmatch(rf"at\s+({_TIME})", body)
|
|
207
|
+
if m:
|
|
208
|
+
tok = m.group(1)
|
|
209
|
+
else:
|
|
210
|
+
m = re.fullmatch(rf"(.+?)\s+at\s+({_TIME})", body) or re.fullmatch(rf"(.+?)\s+({_STRICT})", body)
|
|
211
|
+
if m:
|
|
212
|
+
day_text, tok = m.group(1), m.group(2)
|
|
213
|
+
else:
|
|
214
|
+
day_text = body
|
|
215
|
+
if tok is None:
|
|
216
|
+
_day_of(c, day_text, time(0), raw) # a day that does not read is unparsed before the question
|
|
217
|
+
raise _need_time(c, main, "")
|
|
218
|
+
h, mi, alt = _time_of(tok, raw)
|
|
219
|
+
if alt is not None:
|
|
220
|
+
head = main[: -len(tok)]
|
|
221
|
+
raise Needs("the hour has no am, pm or minutes; a 24-hour reading is offered",
|
|
222
|
+
[Reading(_hhmm(h, mi), c.compose(head + _hhmm(h, mi))), Reading(_hhmm(*alt), c.compose(head + _hhmm(*alt)))])
|
|
223
|
+
if not day_text:
|
|
224
|
+
wall = datetime.combine(c.today, time(h, mi))
|
|
225
|
+
if wall < c.now_wall:
|
|
226
|
+
tomorrow = f"tomorrow at {_hhmm(h, mi)}"
|
|
227
|
+
raise Needs(f"{_hhmm(h, mi)} has passed today", [Reading(tomorrow, c.compose(tomorrow)),
|
|
228
|
+
Reading("refuse: it has passed today", None)])
|
|
229
|
+
else:
|
|
230
|
+
wall = datetime.combine(_day_of(c, day_text, time(h, mi), raw), time(h, mi))
|
|
231
|
+
return build_once(wall, c.zone, c.now, c.notes)
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def _day_of(c: _Ctx, text: str, t: time, raw: str) -> date:
|
|
235
|
+
m = re.fullmatch(rf"(?:(next|this)\s+)?({_WD})", text)
|
|
236
|
+
if not m:
|
|
237
|
+
return _date_of(text, c, raw)
|
|
238
|
+
wd = WEEKDAYS[m.group(2)]
|
|
239
|
+
monday = c.today - timedelta(days=c.today.weekday())
|
|
240
|
+
if m.group(1) == "next":
|
|
241
|
+
return monday + timedelta(days=7 + wd) # next week's, never this week's
|
|
242
|
+
if m.group(1) == "this":
|
|
243
|
+
return monday + timedelta(days=wd)
|
|
244
|
+
d = c.today + timedelta(days=(wd - c.today.weekday()) % 7)
|
|
245
|
+
return d + timedelta(days=7) if d == c.today and datetime.combine(d, t) < c.now_wall else d
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
# --- recur -------------------------------------------------------------------------------------------------------
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _finish(c: _Ctx, rule: Rule, starts: datetime | None) -> Parsed:
|
|
252
|
+
rule = with_bounds(rule, c.until, c.count, c.zone, c.notes)
|
|
253
|
+
if starts is None and c.from_date is not None:
|
|
254
|
+
starts = datetime.combine(c.from_date, time(0))
|
|
255
|
+
return build_recur(rule, c.zone, starts, c.now, c.notes)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def _between(c: _Ctx, m: re.Match[str], raw: str) -> Parsed:
|
|
259
|
+
k = int(m.group(1))
|
|
260
|
+
(h1, m1, a1), (h2, m2, a2) = _time_of(m.group(2), raw), _time_of(m.group(3), raw)
|
|
261
|
+
if k == 0 or a1 or a2 or m1 or m2 or h1 > h2:
|
|
262
|
+
raise _unparsed(raw)
|
|
263
|
+
if 24 % k:
|
|
264
|
+
raise ScheduleError("rule_unsupported", f"every {k} hours between two times: {k} does not divide 24, so the hours "
|
|
265
|
+
"would drift from day to day")
|
|
266
|
+
days: tuple[tuple[int, int], ...] = ()
|
|
267
|
+
if m.group(4) and m.group(4) not in ("every day", "days"):
|
|
268
|
+
if m.group(4) in ("weekday", "weekdays"):
|
|
269
|
+
days = WEEKDAY_SET
|
|
270
|
+
else:
|
|
271
|
+
lst = _daylist(m.group(4))
|
|
272
|
+
if lst is None:
|
|
273
|
+
raise _unparsed(raw)
|
|
274
|
+
days = tuple((0, d) for d in lst)
|
|
275
|
+
rule = Rule(freq="HOURLY", interval=k, byday=days, byhour=tuple(range(h1, h2 + 1, k)))
|
|
276
|
+
return _finish(c, rule, datetime.combine(c.from_date or c.today, time(h1, 0)))
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def _recur(c: _Ctx, main: str, raw: str) -> Parsed:
|
|
280
|
+
if main in ("hourly", "every hour"):
|
|
281
|
+
return _finish(c, interval_rule(60), None)
|
|
282
|
+
m = re.fullmatch(r"every (\d+) (minute|hour)s?", main)
|
|
283
|
+
if m:
|
|
284
|
+
if int(m.group(1)) == 0:
|
|
285
|
+
raise _unparsed(raw)
|
|
286
|
+
return _finish(c, interval_rule(int(m.group(1)) * (60 if m.group(2) == "hour" else 1)), None)
|
|
287
|
+
m = re.fullmatch(rf"every (\d+) hours? between ({_STRICT}|\d{{1,2}}) and ({_STRICT}|\d{{1,2}})(?: on (.+))?", main)
|
|
288
|
+
if m:
|
|
289
|
+
return _between(c, m, raw)
|
|
290
|
+
skip = re.search(r",?\s+skipping short months$", main)
|
|
291
|
+
core = main[: skip.start()] if skip else main
|
|
292
|
+
skip_text = ", skipping short months" if skip else ""
|
|
293
|
+
base, tok = core, None
|
|
294
|
+
m = re.fullmatch(rf"(.+?)\s+at\s+({_TIME})", core)
|
|
295
|
+
if m:
|
|
296
|
+
base, tok = m.group(1), m.group(2)
|
|
297
|
+
rule = _calendar_rule(base, raw)
|
|
298
|
+
if tok is None:
|
|
299
|
+
raise _need_time(c, core, skip_text)
|
|
300
|
+
h, mi, alt = _time_of(tok, raw)
|
|
301
|
+
if alt is not None:
|
|
302
|
+
head = core[: -len(tok)]
|
|
303
|
+
raise Needs("the hour has no am, pm or minutes; a 24-hour reading is offered",
|
|
304
|
+
[Reading(_hhmm(h, mi), c.compose(head + _hhmm(h, mi) + skip_text)),
|
|
305
|
+
Reading(_hhmm(*alt), c.compose(head + _hhmm(*alt) + skip_text))])
|
|
306
|
+
if len(rule.bymonthday) == 1 and rule.bymonthday[0] in (29, 30, 31) and not skip:
|
|
307
|
+
day = rule.bymonthday[0]
|
|
308
|
+
raise Needs(f"not every month has a {day}th day",
|
|
309
|
+
[Reading("skip short months", c.compose(core + ", skipping short months")),
|
|
310
|
+
Reading("use the last day", c.compose(re.sub(r"on the \d{1,2}(?:st|nd|rd|th)", "on the last day",
|
|
311
|
+
core)))])
|
|
312
|
+
rule = dataclasses.replace(rule, byhour=(h,), byminute=(mi,))
|
|
313
|
+
return _finish(c, rule, None)
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def _calendar_rule(base: str, raw: str) -> Rule:
|
|
317
|
+
"""The recurrence without its time of day: a frequency, an interval and the days."""
|
|
318
|
+
if base == "daily":
|
|
319
|
+
return Rule(freq="DAILY")
|
|
320
|
+
if not base.startswith("every "):
|
|
321
|
+
raise _unparsed(raw)
|
|
322
|
+
body = base[6:]
|
|
323
|
+
if body == "day":
|
|
324
|
+
return Rule(freq="DAILY")
|
|
325
|
+
if body in ("weekday", "weekdays"):
|
|
326
|
+
return Rule(freq="WEEKLY", byday=WEEKDAY_SET)
|
|
327
|
+
if body in ("weekend", "weekends"):
|
|
328
|
+
return Rule(freq="WEEKLY", byday=((0, 5), (0, 6)))
|
|
329
|
+
m = re.fullmatch(r"(\d+) days?", body)
|
|
330
|
+
if m and int(m.group(1)) >= 1:
|
|
331
|
+
return Rule(freq="DAILY", interval=int(m.group(1)))
|
|
332
|
+
m = re.fullmatch(r"(?:(\d+) )?weeks?(?: on (.+))?", body)
|
|
333
|
+
if m and int(m.group(1) or 1) >= 1:
|
|
334
|
+
days = _daylist(m.group(2)) if m.group(2) else []
|
|
335
|
+
if days is None:
|
|
336
|
+
raise _unparsed(raw)
|
|
337
|
+
return Rule(freq="WEEKLY", interval=int(m.group(1) or 1), byday=tuple((0, d) for d in days))
|
|
338
|
+
m = re.fullmatch(r"(?:(\d+) )?months?(?: on the (.+))?", body)
|
|
339
|
+
if m and int(m.group(1) or 1) >= 1:
|
|
340
|
+
interval, what = int(m.group(1) or 1), m.group(2)
|
|
341
|
+
if what is None:
|
|
342
|
+
return Rule(freq="MONTHLY", interval=interval)
|
|
343
|
+
if what == "last day":
|
|
344
|
+
return Rule(freq="MONTHLY", interval=interval, bymonthday=(-1,))
|
|
345
|
+
d = re.fullmatch(r"(\d{1,2})(?:st|nd|rd|th)", what)
|
|
346
|
+
if d and 1 <= int(d.group(1)) <= 31:
|
|
347
|
+
return Rule(freq="MONTHLY", interval=interval, bymonthday=(int(d.group(1)),))
|
|
348
|
+
o = re.fullmatch(rf"({'|'.join(ORDINALS)}) ({_WD})", what)
|
|
349
|
+
if o:
|
|
350
|
+
return Rule(freq="MONTHLY", interval=interval, byday=((ORDINALS[o.group(1)], WEEKDAYS[o.group(2)]),))
|
|
351
|
+
raise _unparsed(raw)
|
|
352
|
+
m = re.fullmatch(rf"({'|'.join(ORDINALS)}) ({_WD}) of the month", body)
|
|
353
|
+
if m:
|
|
354
|
+
return Rule(freq="MONTHLY", byday=((ORDINALS[m.group(1)], WEEKDAYS[m.group(2)]),))
|
|
355
|
+
days = _daylist(body)
|
|
356
|
+
if days is not None:
|
|
357
|
+
return Rule(freq="WEEKLY", byday=tuple((0, d) for d in days))
|
|
358
|
+
raise _unparsed(raw)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
# --- the entry point ---------------------------------------------------------------------------------------------
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
def _parse(phrase: str, now: datetime, tz: str | None, machine: tuple[str, str] | None) -> Parsed:
|
|
365
|
+
raw = " ".join(phrase.split()).rstrip(".").strip()
|
|
366
|
+
if not raw:
|
|
367
|
+
raise _unparsed(raw)
|
|
368
|
+
zone_phrase: str | None = None
|
|
369
|
+
z = re.search(r"\s+in\s+((?:[A-Za-z_]+/[A-Za-z0-9_+\-/]+)|[Uu][Tt][Cc])$", raw)
|
|
370
|
+
if z:
|
|
371
|
+
zone_phrase = "UTC" if z.group(1).lower() == "utc" else z.group(1)
|
|
372
|
+
raw_main = raw[: z.start()]
|
|
373
|
+
else:
|
|
374
|
+
raw_main = raw
|
|
375
|
+
if raw.split()[-1].upper() in ABBREVIATIONS:
|
|
376
|
+
check_zone(raw.split()[-1]) # EST, CET: an abbreviation names no rules
|
|
377
|
+
if zone_phrase and tz and zone_phrase != tz:
|
|
378
|
+
raise ScheduleError("when_malformed", f"two zones for one schedule: {zone_phrase} in the phrase and {tz} given")
|
|
379
|
+
notes: list[str] = []
|
|
380
|
+
zone = resolve_zone(zone_phrase or tz, machine, notes)
|
|
381
|
+
c = _Ctx(now=now, zone=zone, notes=notes, suffix=f" in {zone_phrase}" if zone_phrase else "")
|
|
382
|
+
t = raw_main.lower()
|
|
383
|
+
parts = re.split(r"\s+(?=(?:from|until)\s|for\s+\d+\s+times?\b)", t)
|
|
384
|
+
main, clauses = parts[0], parts[1:]
|
|
385
|
+
c.tail = "".join(" " + x for x in clauses)
|
|
386
|
+
for clause in clauses:
|
|
387
|
+
m = re.fullmatch(r"for (\d+) times?", clause)
|
|
388
|
+
if m:
|
|
389
|
+
c.count = int(m.group(1))
|
|
390
|
+
continue
|
|
391
|
+
m = re.fullmatch(r"(from|until) (.+)", clause)
|
|
392
|
+
if not m:
|
|
393
|
+
raise _unparsed(raw)
|
|
394
|
+
d = _date_of(m.group(2), c, raw)
|
|
395
|
+
if m.group(1) == "from":
|
|
396
|
+
c.from_date = d
|
|
397
|
+
else:
|
|
398
|
+
c.until = d.isoformat()
|
|
399
|
+
if main in ("hourly", "daily") or main.startswith(("every ", "daily ")):
|
|
400
|
+
parsed = _recur(c, main, raw)
|
|
401
|
+
else:
|
|
402
|
+
parsed = _once(c, main, raw)
|
|
403
|
+
return parsed
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
def parse_words(phrase: str, *, now: datetime, tz: str | None = None, machine: tuple[str, str] | None = None,
|
|
407
|
+
choose: int | None = None) -> Parsed:
|
|
408
|
+
"""A phrase to the canonical form; `Needs` for an ambiguity, answered by `choose` (the reading's number)."""
|
|
409
|
+
try:
|
|
410
|
+
parsed = _parse(phrase, now, tz, machine)
|
|
411
|
+
except Needs as ask:
|
|
412
|
+
if choose is None:
|
|
413
|
+
raise
|
|
414
|
+
if not 1 <= choose <= len(ask.readings):
|
|
415
|
+
raise ScheduleError("choose_invalid", f"--choose {choose}: the readings are 1 to {len(ask.readings)}") from None
|
|
416
|
+
reading = ask.readings[choose - 1]
|
|
417
|
+
if reading.phrase is None:
|
|
418
|
+
raise ScheduleError("when_in_past", f"refused by the choice: {reading.label}") from None
|
|
419
|
+
return parse_words(reading.phrase, now=now, tz=tz, machine=machine) # the choice is spent; a second question is asked
|
|
420
|
+
if choose is not None:
|
|
421
|
+
raise ScheduleError("choose_invalid", f"--choose {choose}: the phrase has one reading; leave --choose out")
|
|
422
|
+
parsed.phrase = phrase
|
|
423
|
+
return parsed
|
|
File without changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Sanctioned launch sites (SEC-B5, SEC-B6, SEC-B7).
|
|
2
|
+
|
|
3
|
+
Every process launch in the engine goes through one of the functions listed here; a source-scan test
|
|
4
|
+
(``tests/test_source_rules.py``) fails when any other module imports :mod:`subprocess` or calls
|
|
5
|
+
``os.system``/``os.exec*``/``os.spawn*``/``os.popen`` (SEC-AC1).
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
# Module path -> what it launches. Keep in step with SEC-B7.
|
|
11
|
+
SANCTIONED_SITES: dict[str, str] = {
|
|
12
|
+
"tempergraph.git": "git reader: git with constant arguments",
|
|
13
|
+
"tempergraph.run.commands": "workflow command runner: resolved allow-list argv for checks, scripts, finalizer; an operator's registered hook argv",
|
|
14
|
+
"tempergraph.install.launch": "updater: venv, pip from engine-derived paths, the interpreter probe and self-check",
|
|
15
|
+
"tempergraph.executors.launcher": "session launcher: an executor's CLI, its model-free probes, host speed, the resources listing",
|
|
16
|
+
"tempergraph.executors.mcpproxy": "judge's filtering MCP proxy: the operator's own local MCP server as its child, and the start check of that server",
|
|
17
|
+
"tempergraph.detach": "detached child launcher: the engine interpreter with a constant module and words",
|
|
18
|
+
"tempergraph.improve.codehost": "code host client: `gh` with constant subcommands, the body on stdin",
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
SHELL_METACHARACTERS = frozenset(";&|`$<>()\\\n\r*?[]{}!~#'\"")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def has_shell_metacharacter(text: str) -> bool:
|
|
25
|
+
return any(ch in SHELL_METACHARACTERS for ch in text)
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""The pattern scrubber (SEC-B8 to SEC-B11).
|
|
2
|
+
|
|
3
|
+
Patterns are a floor, not the control: the publish boundary is a file boundary. A scrubber that raises
|
|
4
|
+
drops the text and returns a fixed word, and the run continues (OVR-B4, SEC-B7, SEC-B8).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import re
|
|
10
|
+
|
|
11
|
+
REDACTED = "[redacted]"
|
|
12
|
+
DROPPED = "[scrub-failed]"
|
|
13
|
+
|
|
14
|
+
_PATTERNS: tuple[re.Pattern[str], ...] = (
|
|
15
|
+
re.compile(r"-----BEGIN [A-Z ]*PRIVATE KEY-----.*?-----END [A-Z ]*PRIVATE KEY-----", re.S),
|
|
16
|
+
re.compile(r"\bsk-ant-[A-Za-z0-9_-]{8,}"),
|
|
17
|
+
re.compile(r"\bsk-[A-Za-z0-9_-]{20,}"),
|
|
18
|
+
re.compile(r"\bgh[pousr]_[A-Za-z0-9]{20,}"),
|
|
19
|
+
re.compile(r"\bgithub_pat_[A-Za-z0-9_]{20,}"),
|
|
20
|
+
re.compile(r"\bxox[abprs]-[A-Za-z0-9-]{10,}"),
|
|
21
|
+
re.compile(r"\bAKIA[0-9A-Z]{16}\b"),
|
|
22
|
+
re.compile(r"\bAIza[0-9A-Za-z_-]{30,}"),
|
|
23
|
+
re.compile(r"(?i)\bbearer\s+[A-Za-z0-9._~+/=-]{16,}"),
|
|
24
|
+
re.compile(r"(?i)\b(api[_-]?key|secret|token|password|passwd|auth)\b(\s*[:=]\s*)(\"?)[^\s\"']{6,}"),
|
|
25
|
+
re.compile(r"(?i)https?://[^/\s:@]+:[^/\s@]+@"), # credentials in a URL
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def scrub(text: str | None) -> str:
|
|
30
|
+
if not text:
|
|
31
|
+
return text or ""
|
|
32
|
+
try:
|
|
33
|
+
out = text
|
|
34
|
+
for pat in _PATTERNS:
|
|
35
|
+
if pat.groups >= 2:
|
|
36
|
+
out = pat.sub(lambda m: f"{m.group(1)}{m.group(2)}{m.group(3)}{REDACTED}", out)
|
|
37
|
+
else:
|
|
38
|
+
out = pat.sub(REDACTED, out)
|
|
39
|
+
return out
|
|
40
|
+
except Exception:
|
|
41
|
+
return DROPPED
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def clip(text: str | None, limit: int) -> str:
|
|
45
|
+
"""Clip to ``limit`` chars; one line, scrubbed."""
|
|
46
|
+
one = scrub((text or "").replace("\r", " ").replace("\n", " ")).strip()
|
|
47
|
+
return one if len(one) <= limit else one[: max(0, limit - 1)] + "…"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def head_tail(text: str, limit: int, marker: str = "⟨… {n} chars omitted …⟩") -> str:
|
|
51
|
+
"""Keep head and tail around an exact marker with the omitted count (JDG-B3, JDG-B13, JDG-B11)."""
|
|
52
|
+
if len(text) <= limit:
|
|
53
|
+
return text
|
|
54
|
+
keep = max(0, limit - 40)
|
|
55
|
+
head = keep // 2
|
|
56
|
+
tail = keep - head
|
|
57
|
+
omitted = len(text) - head - tail
|
|
58
|
+
return text[:head] + marker.format(n=omitted) + text[len(text) - tail :]
|