okstra 0.31.0 → 0.32.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/package.json +1 -1
- package/runtime/BUILD.json +2 -2
- package/runtime/agents/SKILL.md +3 -3
- package/runtime/agents/workers/report-writer-worker.md +45 -67
- package/runtime/bin/okstra-render-final-report.py +101 -0
- package/runtime/bin/okstra-render-report-views.py +17 -10
- package/runtime/bin/okstra-token-usage.py +3 -1
- package/runtime/python/okstra_ctl/final_report_schema.py +253 -0
- package/runtime/python/okstra_ctl/render_final_report.py +201 -0
- package/runtime/python/okstra_ctl/report_views.py +108 -305
- package/runtime/python/okstra_token_usage/__init__.py +5 -1
- package/runtime/python/okstra_token_usage/cli.py +66 -36
- package/runtime/python/okstra_token_usage/report.py +148 -65
- package/runtime/python/okstra_vendor/__init__.py +37 -0
- package/runtime/python/okstra_vendor/jinja2/__init__.py +38 -0
- package/runtime/python/okstra_vendor/jinja2/_identifier.py +6 -0
- package/runtime/python/okstra_vendor/jinja2/async_utils.py +99 -0
- package/runtime/python/okstra_vendor/jinja2/bccache.py +408 -0
- package/runtime/python/okstra_vendor/jinja2/compiler.py +1998 -0
- package/runtime/python/okstra_vendor/jinja2/constants.py +20 -0
- package/runtime/python/okstra_vendor/jinja2/debug.py +191 -0
- package/runtime/python/okstra_vendor/jinja2/defaults.py +48 -0
- package/runtime/python/okstra_vendor/jinja2/environment.py +1672 -0
- package/runtime/python/okstra_vendor/jinja2/exceptions.py +166 -0
- package/runtime/python/okstra_vendor/jinja2/ext.py +870 -0
- package/runtime/python/okstra_vendor/jinja2/filters.py +1873 -0
- package/runtime/python/okstra_vendor/jinja2/idtracking.py +318 -0
- package/runtime/python/okstra_vendor/jinja2/lexer.py +868 -0
- package/runtime/python/okstra_vendor/jinja2/loaders.py +693 -0
- package/runtime/python/okstra_vendor/jinja2/meta.py +112 -0
- package/runtime/python/okstra_vendor/jinja2/nativetypes.py +130 -0
- package/runtime/python/okstra_vendor/jinja2/nodes.py +1206 -0
- package/runtime/python/okstra_vendor/jinja2/optimizer.py +48 -0
- package/runtime/python/okstra_vendor/jinja2/parser.py +1049 -0
- package/runtime/python/okstra_vendor/jinja2/py.typed +0 -0
- package/runtime/python/okstra_vendor/jinja2/runtime.py +1062 -0
- package/runtime/python/okstra_vendor/jinja2/sandbox.py +436 -0
- package/runtime/python/okstra_vendor/jinja2/tests.py +256 -0
- package/runtime/python/okstra_vendor/jinja2/utils.py +766 -0
- package/runtime/python/okstra_vendor/jinja2/visitor.py +92 -0
- package/runtime/python/okstra_vendor/markupsafe/__init__.py +396 -0
- package/runtime/python/okstra_vendor/markupsafe/_native.py +8 -0
- package/runtime/python/okstra_vendor/markupsafe/py.typed +0 -0
- package/runtime/schemas/final-report-v1.0.schema.json +1391 -0
- package/runtime/skills/okstra-report-writer/SKILL.md +29 -28
- package/runtime/templates/reports/final-report.template.md +370 -411
- package/runtime/templates/reports/report.css +12 -6
- package/runtime/validators/lib/fixtures.sh +7 -7
- package/runtime/validators/validate-report-views.py +24 -153
- package/runtime/validators/validate-run.py +102 -19
- package/src/install.mjs +20 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#: list of lorem ipsum words used by the lipsum() helper function
|
|
2
|
+
LOREM_IPSUM_WORDS = """\
|
|
3
|
+
a ac accumsan ad adipiscing aenean aliquam aliquet amet ante aptent arcu at
|
|
4
|
+
auctor augue bibendum blandit class commodo condimentum congue consectetuer
|
|
5
|
+
consequat conubia convallis cras cubilia cum curabitur curae cursus dapibus
|
|
6
|
+
diam dictum dictumst dignissim dis dolor donec dui duis egestas eget eleifend
|
|
7
|
+
elementum elit enim erat eros est et etiam eu euismod facilisi facilisis fames
|
|
8
|
+
faucibus felis fermentum feugiat fringilla fusce gravida habitant habitasse hac
|
|
9
|
+
hendrerit hymenaeos iaculis id imperdiet in inceptos integer interdum ipsum
|
|
10
|
+
justo lacinia lacus laoreet lectus leo libero ligula litora lobortis lorem
|
|
11
|
+
luctus maecenas magna magnis malesuada massa mattis mauris metus mi molestie
|
|
12
|
+
mollis montes morbi mus nam nascetur natoque nec neque netus nibh nisi nisl non
|
|
13
|
+
nonummy nostra nulla nullam nunc odio orci ornare parturient pede pellentesque
|
|
14
|
+
penatibus per pharetra phasellus placerat platea porta porttitor posuere
|
|
15
|
+
potenti praesent pretium primis proin pulvinar purus quam quis quisque rhoncus
|
|
16
|
+
ridiculus risus rutrum sagittis sapien scelerisque sed sem semper senectus sit
|
|
17
|
+
sociis sociosqu sodales sollicitudin suscipit suspendisse taciti tellus tempor
|
|
18
|
+
tempus tincidunt torquent tortor tristique turpis ullamcorper ultrices
|
|
19
|
+
ultricies urna ut varius vehicula vel velit venenatis vestibulum vitae vivamus
|
|
20
|
+
viverra volutpat vulputate"""
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import typing as t
|
|
3
|
+
from types import CodeType
|
|
4
|
+
from types import TracebackType
|
|
5
|
+
|
|
6
|
+
from .exceptions import TemplateSyntaxError
|
|
7
|
+
from .utils import internal_code
|
|
8
|
+
from .utils import missing
|
|
9
|
+
|
|
10
|
+
if t.TYPE_CHECKING:
|
|
11
|
+
from .runtime import Context
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def rewrite_traceback_stack(source: t.Optional[str] = None) -> BaseException:
|
|
15
|
+
"""Rewrite the current exception to replace any tracebacks from
|
|
16
|
+
within compiled template code with tracebacks that look like they
|
|
17
|
+
came from the template source.
|
|
18
|
+
|
|
19
|
+
This must be called within an ``except`` block.
|
|
20
|
+
|
|
21
|
+
:param source: For ``TemplateSyntaxError``, the original source if
|
|
22
|
+
known.
|
|
23
|
+
:return: The original exception with the rewritten traceback.
|
|
24
|
+
"""
|
|
25
|
+
_, exc_value, tb = sys.exc_info()
|
|
26
|
+
exc_value = t.cast(BaseException, exc_value)
|
|
27
|
+
tb = t.cast(TracebackType, tb)
|
|
28
|
+
|
|
29
|
+
if isinstance(exc_value, TemplateSyntaxError) and not exc_value.translated:
|
|
30
|
+
exc_value.translated = True
|
|
31
|
+
exc_value.source = source
|
|
32
|
+
# Remove the old traceback, otherwise the frames from the
|
|
33
|
+
# compiler still show up.
|
|
34
|
+
exc_value.with_traceback(None)
|
|
35
|
+
# Outside of runtime, so the frame isn't executing template
|
|
36
|
+
# code, but it still needs to point at the template.
|
|
37
|
+
tb = fake_traceback(
|
|
38
|
+
exc_value, None, exc_value.filename or "<unknown>", exc_value.lineno
|
|
39
|
+
)
|
|
40
|
+
else:
|
|
41
|
+
# Skip the frame for the render function.
|
|
42
|
+
tb = tb.tb_next
|
|
43
|
+
|
|
44
|
+
stack = []
|
|
45
|
+
|
|
46
|
+
# Build the stack of traceback object, replacing any in template
|
|
47
|
+
# code with the source file and line information.
|
|
48
|
+
while tb is not None:
|
|
49
|
+
# Skip frames decorated with @internalcode. These are internal
|
|
50
|
+
# calls that aren't useful in template debugging output.
|
|
51
|
+
if tb.tb_frame.f_code in internal_code:
|
|
52
|
+
tb = tb.tb_next
|
|
53
|
+
continue
|
|
54
|
+
|
|
55
|
+
template = tb.tb_frame.f_globals.get("__jinja_template__")
|
|
56
|
+
|
|
57
|
+
if template is not None:
|
|
58
|
+
lineno = template.get_corresponding_lineno(tb.tb_lineno)
|
|
59
|
+
fake_tb = fake_traceback(exc_value, tb, template.filename, lineno)
|
|
60
|
+
stack.append(fake_tb)
|
|
61
|
+
else:
|
|
62
|
+
stack.append(tb)
|
|
63
|
+
|
|
64
|
+
tb = tb.tb_next
|
|
65
|
+
|
|
66
|
+
tb_next = None
|
|
67
|
+
|
|
68
|
+
# Assign tb_next in reverse to avoid circular references.
|
|
69
|
+
for tb in reversed(stack):
|
|
70
|
+
tb.tb_next = tb_next
|
|
71
|
+
tb_next = tb
|
|
72
|
+
|
|
73
|
+
return exc_value.with_traceback(tb_next)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def fake_traceback( # type: ignore
|
|
77
|
+
exc_value: BaseException, tb: t.Optional[TracebackType], filename: str, lineno: int
|
|
78
|
+
) -> TracebackType:
|
|
79
|
+
"""Produce a new traceback object that looks like it came from the
|
|
80
|
+
template source instead of the compiled code. The filename, line
|
|
81
|
+
number, and location name will point to the template, and the local
|
|
82
|
+
variables will be the current template context.
|
|
83
|
+
|
|
84
|
+
:param exc_value: The original exception to be re-raised to create
|
|
85
|
+
the new traceback.
|
|
86
|
+
:param tb: The original traceback to get the local variables and
|
|
87
|
+
code info from.
|
|
88
|
+
:param filename: The template filename.
|
|
89
|
+
:param lineno: The line number in the template source.
|
|
90
|
+
"""
|
|
91
|
+
if tb is not None:
|
|
92
|
+
# Replace the real locals with the context that would be
|
|
93
|
+
# available at that point in the template.
|
|
94
|
+
locals = get_template_locals(tb.tb_frame.f_locals)
|
|
95
|
+
locals.pop("__jinja_exception__", None)
|
|
96
|
+
else:
|
|
97
|
+
locals = {}
|
|
98
|
+
|
|
99
|
+
globals = {
|
|
100
|
+
"__name__": filename,
|
|
101
|
+
"__file__": filename,
|
|
102
|
+
"__jinja_exception__": exc_value,
|
|
103
|
+
}
|
|
104
|
+
# Raise an exception at the correct line number.
|
|
105
|
+
code: CodeType = compile(
|
|
106
|
+
"\n" * (lineno - 1) + "raise __jinja_exception__", filename, "exec"
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
# Build a new code object that points to the template file and
|
|
110
|
+
# replaces the location with a block name.
|
|
111
|
+
location = "template"
|
|
112
|
+
|
|
113
|
+
if tb is not None:
|
|
114
|
+
function = tb.tb_frame.f_code.co_name
|
|
115
|
+
|
|
116
|
+
if function == "root":
|
|
117
|
+
location = "top-level template code"
|
|
118
|
+
elif function.startswith("block_"):
|
|
119
|
+
location = f"block {function[6:]!r}"
|
|
120
|
+
|
|
121
|
+
if sys.version_info >= (3, 8):
|
|
122
|
+
code = code.replace(co_name=location)
|
|
123
|
+
else:
|
|
124
|
+
code = CodeType(
|
|
125
|
+
code.co_argcount,
|
|
126
|
+
code.co_kwonlyargcount,
|
|
127
|
+
code.co_nlocals,
|
|
128
|
+
code.co_stacksize,
|
|
129
|
+
code.co_flags,
|
|
130
|
+
code.co_code,
|
|
131
|
+
code.co_consts,
|
|
132
|
+
code.co_names,
|
|
133
|
+
code.co_varnames,
|
|
134
|
+
code.co_filename,
|
|
135
|
+
location,
|
|
136
|
+
code.co_firstlineno,
|
|
137
|
+
code.co_lnotab,
|
|
138
|
+
code.co_freevars,
|
|
139
|
+
code.co_cellvars,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
# Execute the new code, which is guaranteed to raise, and return
|
|
143
|
+
# the new traceback without this frame.
|
|
144
|
+
try:
|
|
145
|
+
exec(code, globals, locals)
|
|
146
|
+
except BaseException:
|
|
147
|
+
return sys.exc_info()[2].tb_next # type: ignore
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def get_template_locals(real_locals: t.Mapping[str, t.Any]) -> t.Dict[str, t.Any]:
|
|
151
|
+
"""Based on the runtime locals, get the context that would be
|
|
152
|
+
available at that point in the template.
|
|
153
|
+
"""
|
|
154
|
+
# Start with the current template context.
|
|
155
|
+
ctx: t.Optional[Context] = real_locals.get("context")
|
|
156
|
+
|
|
157
|
+
if ctx is not None:
|
|
158
|
+
data: t.Dict[str, t.Any] = ctx.get_all().copy()
|
|
159
|
+
else:
|
|
160
|
+
data = {}
|
|
161
|
+
|
|
162
|
+
# Might be in a derived context that only sets local variables
|
|
163
|
+
# rather than pushing a context. Local variables follow the scheme
|
|
164
|
+
# l_depth_name. Find the highest-depth local that has a value for
|
|
165
|
+
# each name.
|
|
166
|
+
local_overrides: t.Dict[str, t.Tuple[int, t.Any]] = {}
|
|
167
|
+
|
|
168
|
+
for name, value in real_locals.items():
|
|
169
|
+
if not name.startswith("l_") or value is missing:
|
|
170
|
+
# Not a template variable, or no longer relevant.
|
|
171
|
+
continue
|
|
172
|
+
|
|
173
|
+
try:
|
|
174
|
+
_, depth_str, name = name.split("_", 2)
|
|
175
|
+
depth = int(depth_str)
|
|
176
|
+
except ValueError:
|
|
177
|
+
continue
|
|
178
|
+
|
|
179
|
+
cur_depth = local_overrides.get(name, (-1,))[0]
|
|
180
|
+
|
|
181
|
+
if cur_depth < depth:
|
|
182
|
+
local_overrides[name] = (depth, value)
|
|
183
|
+
|
|
184
|
+
# Modify the context with any derived context.
|
|
185
|
+
for name, (_, value) in local_overrides.items():
|
|
186
|
+
if value is missing:
|
|
187
|
+
data.pop(name, None)
|
|
188
|
+
else:
|
|
189
|
+
data[name] = value
|
|
190
|
+
|
|
191
|
+
return data
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import typing as t
|
|
2
|
+
|
|
3
|
+
from .filters import FILTERS as DEFAULT_FILTERS # noqa: F401
|
|
4
|
+
from .tests import TESTS as DEFAULT_TESTS # noqa: F401
|
|
5
|
+
from .utils import Cycler
|
|
6
|
+
from .utils import generate_lorem_ipsum
|
|
7
|
+
from .utils import Joiner
|
|
8
|
+
from .utils import Namespace
|
|
9
|
+
|
|
10
|
+
if t.TYPE_CHECKING:
|
|
11
|
+
import typing_extensions as te
|
|
12
|
+
|
|
13
|
+
# defaults for the parser / lexer
|
|
14
|
+
BLOCK_START_STRING = "{%"
|
|
15
|
+
BLOCK_END_STRING = "%}"
|
|
16
|
+
VARIABLE_START_STRING = "{{"
|
|
17
|
+
VARIABLE_END_STRING = "}}"
|
|
18
|
+
COMMENT_START_STRING = "{#"
|
|
19
|
+
COMMENT_END_STRING = "#}"
|
|
20
|
+
LINE_STATEMENT_PREFIX: t.Optional[str] = None
|
|
21
|
+
LINE_COMMENT_PREFIX: t.Optional[str] = None
|
|
22
|
+
TRIM_BLOCKS = False
|
|
23
|
+
LSTRIP_BLOCKS = False
|
|
24
|
+
NEWLINE_SEQUENCE: "te.Literal['\\n', '\\r\\n', '\\r']" = "\n"
|
|
25
|
+
KEEP_TRAILING_NEWLINE = False
|
|
26
|
+
|
|
27
|
+
# default filters, tests and namespace
|
|
28
|
+
|
|
29
|
+
DEFAULT_NAMESPACE = {
|
|
30
|
+
"range": range,
|
|
31
|
+
"dict": dict,
|
|
32
|
+
"lipsum": generate_lorem_ipsum,
|
|
33
|
+
"cycler": Cycler,
|
|
34
|
+
"joiner": Joiner,
|
|
35
|
+
"namespace": Namespace,
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
# default policies
|
|
39
|
+
DEFAULT_POLICIES: t.Dict[str, t.Any] = {
|
|
40
|
+
"compiler.ascii_str": True,
|
|
41
|
+
"urlize.rel": "noopener",
|
|
42
|
+
"urlize.target": None,
|
|
43
|
+
"urlize.extra_schemes": None,
|
|
44
|
+
"truncate.leeway": 5,
|
|
45
|
+
"json.dumps_function": None,
|
|
46
|
+
"json.dumps_kwargs": {"sort_keys": True},
|
|
47
|
+
"ext.i18n.trimmed": False,
|
|
48
|
+
}
|