gvn-workbench 0.1.0__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.
- gvn_workbench/__init__.py +6 -0
- gvn_workbench/app.py +333 -0
- gvn_workbench/editing/__init__.py +254 -0
- gvn_workbench/editing/address.py +132 -0
- gvn_workbench/editing/editor.py +728 -0
- gvn_workbench/editing/effects.py +246 -0
- gvn_workbench/editing/errors.py +40 -0
- gvn_workbench/editing/fresh_process.py +312 -0
- gvn_workbench/editing/proposing.py +119 -0
- gvn_workbench/editing/replacing.py +97 -0
- gvn_workbench/editing/section.py +265 -0
- gvn_workbench/editing/shapes.py +264 -0
- gvn_workbench/editing/stores.py +189 -0
- gvn_workbench/editing/supervised.py +134 -0
- gvn_workbench/editing/supervisor.py +347 -0
- gvn_workbench/editing/verification.py +257 -0
- gvn_workbench/evals/__init__.py +92 -0
- gvn_workbench/evals/section.py +34 -0
- gvn_workbench/evals/site.py +918 -0
- gvn_workbench/evals/static/app.css +1294 -0
- gvn_workbench/evals/static/app.js +110 -0
- gvn_workbench/evals/static/index.html +42 -0
- gvn_workbench/evals/static/js/api.js +77 -0
- gvn_workbench/evals/static/js/cases.js +472 -0
- gvn_workbench/evals/static/js/compare.js +337 -0
- gvn_workbench/evals/static/js/dom.js +338 -0
- gvn_workbench/evals/static/js/help.js +41 -0
- gvn_workbench/evals/static/js/report.js +404 -0
- gvn_workbench/evals/static/js/reviews.js +267 -0
- gvn_workbench/evals/static/js/runs.js +153 -0
- gvn_workbench/evals/static/js/trial.js +250 -0
- gvn_workbench/guide/__init__.py +14 -0
- gvn_workbench/guide/conversations.py +545 -0
- gvn_workbench/guide/instructions.py +34 -0
- gvn_workbench/guide/section.py +190 -0
- gvn_workbench/guide/turns.py +217 -0
- gvn_workbench/mcp/__init__.py +19 -0
- gvn_workbench/mcp/endpoint.py +205 -0
- gvn_workbench/mcp/section.py +123 -0
- gvn_workbench/mcp/token.py +61 -0
- gvn_workbench/reading/__init__.py +219 -0
- gvn_workbench/reading/errors.py +8 -0
- gvn_workbench/reading/journals.py +58 -0
- gvn_workbench/reading/plain.py +182 -0
- gvn_workbench/reading/reader.py +496 -0
- gvn_workbench/reading/runs.py +353 -0
- gvn_workbench/reading/section.py +212 -0
- gvn_workbench/reading/templates.py +339 -0
- gvn_workbench/run_actions/__init__.py +130 -0
- gvn_workbench/run_actions/actions.py +510 -0
- gvn_workbench/run_actions/continuing.py +99 -0
- gvn_workbench/run_actions/errors.py +25 -0
- gvn_workbench/run_actions/journals.py +365 -0
- gvn_workbench/run_actions/read_only.py +158 -0
- gvn_workbench/run_actions/section.py +195 -0
- gvn_workbench/section.py +100 -0
- gvn_workbench/security.py +395 -0
- gvn_workbench/serial.py +83 -0
- gvn_workbench/shell/__init__.py +8 -0
- gvn_workbench/shell/section.py +122 -0
- gvn_workbench/shell/static/assets/_commonjs-dynamic-modules-TDtrdbi3.js +1 -0
- gvn_workbench/shell/static/assets/elk-api-BWsEwNNR.js +1 -0
- gvn_workbench/shell/static/assets/elk-worker.min-J_vVZCZ4.js +6482 -0
- gvn_workbench/shell/static/assets/elk-worker.min-UNIMIGq9.js +1 -0
- gvn_workbench/shell/static/assets/elk.bundled-8PLqhzqu.js +26 -0
- gvn_workbench/shell/static/assets/index-6kyBzABJ.css +1 -0
- gvn_workbench/shell/static/assets/index-DTB2-Uni.js +24 -0
- gvn_workbench/shell/static/favicon.svg +1 -0
- gvn_workbench/shell/static/index.html +19 -0
- gvn_workbench/source/__init__.py +177 -0
- gvn_workbench/source/chains.py +146 -0
- gvn_workbench/source/checks.py +207 -0
- gvn_workbench/source/classifying.py +243 -0
- gvn_workbench/source/dict_entries.py +108 -0
- gvn_workbench/source/edit.py +242 -0
- gvn_workbench/source/follow_ups.py +372 -0
- gvn_workbench/source/imports.py +118 -0
- gvn_workbench/source/inventory.py +380 -0
- gvn_workbench/source/join_edits.py +141 -0
- gvn_workbench/source/literals.py +237 -0
- gvn_workbench/source/located.py +146 -0
- gvn_workbench/source/locating.py +388 -0
- gvn_workbench/source/modules.py +164 -0
- gvn_workbench/source/offers.py +156 -0
- gvn_workbench/source/owners.py +80 -0
- gvn_workbench/source/patch.py +482 -0
- gvn_workbench/source/plan_reading.py +519 -0
- gvn_workbench/source/ranges.py +89 -0
- gvn_workbench/source/reads.py +196 -0
- gvn_workbench/source/rewriting.py +57 -0
- gvn_workbench/source/route_edits.py +190 -0
- gvn_workbench/source/scopes.py +533 -0
- gvn_workbench/source/sentences.py +188 -0
- gvn_workbench/source/sites.py +702 -0
- gvn_workbench/source/snapshot.py +104 -0
- gvn_workbench/source/state_edits.py +604 -0
- gvn_workbench/source/symbol_edits.py +492 -0
- gvn_workbench/source/text.py +223 -0
- gvn_workbench/source/transition_edits.py +394 -0
- gvn_workbench/source/value_edits.py +332 -0
- gvn_workbench/tools/__init__.py +65 -0
- gvn_workbench/tools/context.py +76 -0
- gvn_workbench/tools/glossary.py +475 -0
- gvn_workbench/tools/marking.py +84 -0
- gvn_workbench/tools/offered.py +672 -0
- gvn_workbench/tools/places.py +128 -0
- gvn_workbench/tools/refusal.py +7 -0
- gvn_workbench/tools/surface.py +212 -0
- gvn_workbench-0.1.0.dist-info/METADATA +49 -0
- gvn_workbench-0.1.0.dist-info/RECORD +112 -0
- gvn_workbench-0.1.0.dist-info/WHEEL +4 -0
- gvn_workbench-0.1.0.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""The gvn Workbench: one local page for building, inspecting and evaluating harnesses.
|
|
2
|
+
|
|
3
|
+
A development tool. It is started in the repository that uses gvn (``gvn eval serve``
|
|
4
|
+
opens it), reads that project through gvn's own interfaces, and writes only the
|
|
5
|
+
project's files. A deployed harness does not import it and does not need it installed.
|
|
6
|
+
"""
|
gvn_workbench/app.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"""The Workbench's local site: one ASGI application made of sections, and ``serve``.
|
|
2
|
+
|
|
3
|
+
``Workbench`` composes the sections of the site (each a ``gvn_workbench.section.Section``
|
|
4
|
+
declared in its own package), each answering under its own addresses, behind the rules
|
|
5
|
+
of ``gvn_workbench.security`` (applied to every request, whichever section answers it):
|
|
6
|
+
|
|
7
|
+
- the Evals section (``gvn_workbench.evals``): the eval page under ``/evals/`` and its
|
|
8
|
+
JSON interface under ``/api/evals/``;
|
|
9
|
+
- the editing section (``gvn_workbench.editing``): each harness's source by target under
|
|
10
|
+
``/api/harnesses/<harness>/source``, previewing and saving edit groups under
|
|
11
|
+
``/api/edits/``, agents' pending proposals under ``/api/proposals`` and the canvas
|
|
12
|
+
layout under ``/api/layouts/``;
|
|
13
|
+
- the run actions (``gvn_workbench.run_actions``): the journals read under
|
|
14
|
+
``/api/journals``, what runs wait on a person for under ``/api/waiting``, and forking,
|
|
15
|
+
answering, continuing, making a case of and replaying a run under
|
|
16
|
+
``/api/runs/<run>/<action>``;
|
|
17
|
+
- the Reading section (``gvn_workbench.reading``): the project, its harnesses, their
|
|
18
|
+
machines and its recorded runs under ``/api/project``, ``/api/harnesses/`` and
|
|
19
|
+
``/api/runs``;
|
|
20
|
+
- the MCP section (``gvn_workbench.mcp``): the MCP server over the Workbench's tools at
|
|
21
|
+
``/mcp``, for coding agents and the guide, with the MCP token;
|
|
22
|
+
- the guide's section (``gvn_workbench.guide``): the built-in guide's conversations under
|
|
23
|
+
``/api/guide/conversations``;
|
|
24
|
+
- the shell (``gvn_workbench.shell``): ``/`` is the shell's page and its files are
|
|
25
|
+
beneath ``/``; while there is no shell page, ``/`` leads to ``/evals/``.
|
|
26
|
+
|
|
27
|
+
Any other address is 404, ``{"error": ...}``. Work against the project's stores runs one
|
|
28
|
+
request at a time on one event loop of its own (``gvn_workbench.serial``), so the
|
|
29
|
+
server's event loop is never blocked by it.
|
|
30
|
+
|
|
31
|
+
``serve`` runs the Workbench with uvicorn on 127.0.0.1 until Ctrl-C. Given the project's
|
|
32
|
+
address (as ``gvn eval serve`` gives it), it runs supervised
|
|
33
|
+
(``gvn_workbench.editing.supervisor``): the server is a child process started again on
|
|
34
|
+
the changed code after every save, on the same port with the same tokens.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
from __future__ import annotations
|
|
38
|
+
|
|
39
|
+
import asyncio
|
|
40
|
+
import errno
|
|
41
|
+
import os
|
|
42
|
+
import pathlib
|
|
43
|
+
import socket
|
|
44
|
+
import sys
|
|
45
|
+
import typing
|
|
46
|
+
import webbrowser
|
|
47
|
+
|
|
48
|
+
import uvicorn
|
|
49
|
+
from gvn.console.project import Project
|
|
50
|
+
from gvn_tools.protocol import LocalMcpServer
|
|
51
|
+
from starlette.routing import Router
|
|
52
|
+
|
|
53
|
+
from gvn_workbench.editing.address import ProjectAddress, project_files
|
|
54
|
+
from gvn_workbench.editing.section import EditingSection
|
|
55
|
+
from gvn_workbench.editing.supervisor import Supervisor
|
|
56
|
+
from gvn_workbench.evals.section import EvalsSection
|
|
57
|
+
from gvn_workbench.guide.section import GuideSection
|
|
58
|
+
from gvn_workbench.mcp.section import McpSection
|
|
59
|
+
from gvn_workbench.mcp.token import mcp_token as kept_mcp_token
|
|
60
|
+
from gvn_workbench.mcp.token import workbench_home
|
|
61
|
+
from gvn_workbench.reading.section import ReadingSection
|
|
62
|
+
from gvn_workbench.run_actions.journals import WorkbenchJournals
|
|
63
|
+
from gvn_workbench.run_actions.section import RunActionsSection
|
|
64
|
+
from gvn_workbench.section import nowhere
|
|
65
|
+
from gvn_workbench.security import Guard, Guarded, new_token
|
|
66
|
+
from gvn_workbench.serial import SerialLoop
|
|
67
|
+
from gvn_workbench.shell.section import ShellSection
|
|
68
|
+
|
|
69
|
+
if typing.TYPE_CHECKING:
|
|
70
|
+
from collections.abc import Awaitable, Callable, Iterable, MutableMapping
|
|
71
|
+
|
|
72
|
+
from gvn_tools.protocol import McpServer
|
|
73
|
+
|
|
74
|
+
_Message = MutableMapping[str, typing.Any]
|
|
75
|
+
_Receive = Callable[[], Awaitable[_Message]]
|
|
76
|
+
_Send = Callable[[_Message], Awaitable[None]]
|
|
77
|
+
|
|
78
|
+
_HOST = "127.0.0.1"
|
|
79
|
+
_EVALS = "/evals/"
|
|
80
|
+
_MCP = "/mcp"
|
|
81
|
+
_STOP_SECONDS = 5 # how long Ctrl-C waits for the requests being answered
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _kind(value: object) -> str:
|
|
85
|
+
return type(value).__name__
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def reach_with(mcp_token: str | None) -> Callable[[str], McpServer]:
|
|
89
|
+
"""How the guide reaches the site's MCP server: gvn's MCP client over Streamable
|
|
90
|
+
HTTP at the address it is given, sending ``mcp_token`` (None: no token, so the
|
|
91
|
+
server refuses it)."""
|
|
92
|
+
headers = {} if mcp_token is None else {"X-Gvn-Token": mcp_token}
|
|
93
|
+
|
|
94
|
+
def reach(url: str) -> McpServer:
|
|
95
|
+
return LocalMcpServer.http(url, headers)
|
|
96
|
+
|
|
97
|
+
return reach
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class Workbench:
|
|
101
|
+
"""The Workbench's site for one ``project`` (a ``gvn.console.project.Project``), as
|
|
102
|
+
one ASGI application: call it with ``(scope, receive, send)``. ``token``: the
|
|
103
|
+
non-empty str written into the pages served and required (header ``X-Gvn-Token``)
|
|
104
|
+
on every changing request. ``shell``: the folder of the shell's files, a
|
|
105
|
+
``pathlib.Path``; None (the default) is ``gvn_workbench/shell/static``.
|
|
106
|
+
``mcp_token``: the token every request to the MCP server must carry
|
|
107
|
+
(``gvn_workbench.mcp.mcp_token`` keeps it), not the page's; None (the default): the
|
|
108
|
+
MCP server refuses every request. ``home``: the folder the Workbench keeps its own
|
|
109
|
+
files in (the guide's journal); None (the default) is ``<project root>/.gvn/workbench``.
|
|
110
|
+
Nothing is written there for the guide until its first message. ``reach``: how the
|
|
111
|
+
guide reaches the MCP server, a function of its address returning a
|
|
112
|
+
``gvn_tools.protocol.McpServer``; None (the default) is ``reach_with(mcp_token)``.
|
|
113
|
+
``address``: how a fresh process loads the project, a
|
|
114
|
+
``gvn_workbench.editing.ProjectAddress``, to check edits before they are saved;
|
|
115
|
+
None (the default) reads it from ``[tool.gvn]`` in the project's ``pyproject.toml``.
|
|
116
|
+
``restart``: called with no arguments after a save wrote the project's files (the
|
|
117
|
+
supervisor's way to come back up on them); None (the default): a save answers that
|
|
118
|
+
the Workbench has to be restarted by hand.
|
|
119
|
+
|
|
120
|
+
The sections are, in the order their routes are tried: Evals, editing, the run
|
|
121
|
+
actions, Reading, MCP, the guide, the shell.
|
|
122
|
+
An address no route claims goes to the first section offering a default (the
|
|
123
|
+
shell's files), else is 404. Every request passes
|
|
124
|
+
``gvn_workbench.security.Guarded`` before a section sees it. ``close`` stops the
|
|
125
|
+
loops the sections' work runs on; call it when the site stops.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
__slots__ = ("_app", "_serial", "_mcp", "_guide", "_editing")
|
|
129
|
+
|
|
130
|
+
def __init__(
|
|
131
|
+
self,
|
|
132
|
+
project: Project,
|
|
133
|
+
token: str,
|
|
134
|
+
shell: pathlib.Path | None = None,
|
|
135
|
+
mcp_token: str | None = None,
|
|
136
|
+
home: pathlib.Path | None = None,
|
|
137
|
+
reach: Callable[[str], McpServer] | None = None,
|
|
138
|
+
address: ProjectAddress | None = None,
|
|
139
|
+
restart: Callable[[], None] | None = None,
|
|
140
|
+
) -> None:
|
|
141
|
+
if not isinstance(project, Project):
|
|
142
|
+
raise TypeError(f"project must be a Project, got {_kind(project)}")
|
|
143
|
+
if shell is not None and not isinstance(shell, pathlib.Path):
|
|
144
|
+
raise TypeError(f"shell must be a Path or None, got {_kind(shell)}")
|
|
145
|
+
if home is not None and not isinstance(home, pathlib.Path):
|
|
146
|
+
raise TypeError(f"home must be a Path or None, got {_kind(home)}")
|
|
147
|
+
if reach is not None and not callable(reach):
|
|
148
|
+
raise TypeError(f"reach must be a function or None, got {_kind(reach)}")
|
|
149
|
+
if address is not None and not isinstance(address, ProjectAddress):
|
|
150
|
+
raise TypeError(f"address must be a ProjectAddress or None, got {_kind(address)}")
|
|
151
|
+
guard = Guard(token, mcp_token)
|
|
152
|
+
serial = SerialLoop()
|
|
153
|
+
journals = WorkbenchJournals(project) # read by Reading, kept by the run actions
|
|
154
|
+
self._editing = EditingSection(
|
|
155
|
+
project,
|
|
156
|
+
token,
|
|
157
|
+
serial,
|
|
158
|
+
workbench_home(project.root()) if home is None else home,
|
|
159
|
+
address=address,
|
|
160
|
+
restart=restart,
|
|
161
|
+
)
|
|
162
|
+
# The MCP tools read every journal and propose edits through the editing
|
|
163
|
+
# section's own Editor, so a proposal they keep is the one the page lists.
|
|
164
|
+
self._mcp = McpSection(
|
|
165
|
+
project, token, serial, mcp_token, journals, editor=self._editing.editor()
|
|
166
|
+
)
|
|
167
|
+
self._guide = GuideSection(
|
|
168
|
+
project,
|
|
169
|
+
token,
|
|
170
|
+
serial,
|
|
171
|
+
workbench_home(project.root()) if home is None else home,
|
|
172
|
+
reach_with(mcp_token) if reach is None else reach,
|
|
173
|
+
)
|
|
174
|
+
sections = (
|
|
175
|
+
EvalsSection(project, token, serial),
|
|
176
|
+
self._editing,
|
|
177
|
+
RunActionsSection(project, token, serial, journals),
|
|
178
|
+
ReadingSection(project, token, serial, journals),
|
|
179
|
+
self._mcp,
|
|
180
|
+
self._guide,
|
|
181
|
+
ShellSection(project, token, serial, shell),
|
|
182
|
+
)
|
|
183
|
+
routes = []
|
|
184
|
+
default = None
|
|
185
|
+
for section in sections:
|
|
186
|
+
routes.extend(section.routes())
|
|
187
|
+
if default is None:
|
|
188
|
+
default = section.default()
|
|
189
|
+
router = Router(routes=routes, default=default if default is not None else nowhere)
|
|
190
|
+
self._app = Guarded(router, guard)
|
|
191
|
+
self._serial = serial
|
|
192
|
+
|
|
193
|
+
async def __call__(self, scope: _Message, receive: _Receive, send: _Send) -> None:
|
|
194
|
+
await self._app(scope, receive, send)
|
|
195
|
+
|
|
196
|
+
def editing(self) -> EditingSection:
|
|
197
|
+
"""The editing section (its ``editor()`` is what the ``propose_edits`` tool uses)."""
|
|
198
|
+
return self._editing
|
|
199
|
+
|
|
200
|
+
def close(self) -> None:
|
|
201
|
+
"""Stop the loops the sections' work runs on (they start again when needed)."""
|
|
202
|
+
self._guide.close()
|
|
203
|
+
self._mcp.close()
|
|
204
|
+
self._serial.close()
|
|
205
|
+
|
|
206
|
+
def __repr__(self) -> str:
|
|
207
|
+
return "Workbench(...)"
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _bound(port: int) -> socket.socket:
|
|
211
|
+
"""A socket listening on 127.0.0.1:``port``. OSError with a sentence suggesting
|
|
212
|
+
``--port`` when the port is taken."""
|
|
213
|
+
listening = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
214
|
+
try:
|
|
215
|
+
# A port left in TIME_WAIT by the last run can be bound again.
|
|
216
|
+
listening.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
217
|
+
listening.bind((_HOST, port))
|
|
218
|
+
listening.listen(128)
|
|
219
|
+
except OSError as problem:
|
|
220
|
+
listening.close()
|
|
221
|
+
if problem.errno == errno.EADDRINUSE:
|
|
222
|
+
raise OSError(
|
|
223
|
+
f"Port {port} is already in use on this computer; start the page on "
|
|
224
|
+
"another one with --port."
|
|
225
|
+
) from None
|
|
226
|
+
raise
|
|
227
|
+
return listening
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def _announced(
|
|
231
|
+
listening: socket.socket, home: pathlib.Path, out: typing.TextIO, open_browser: bool
|
|
232
|
+
) -> None:
|
|
233
|
+
"""Say where the site and its MCP server are, and open the page when asked."""
|
|
234
|
+
site = f"http://{_HOST}:{listening.getsockname()[1]}"
|
|
235
|
+
address = f"{site}{_EVALS}"
|
|
236
|
+
out.write(f"The eval page is at {address} on this computer; press Ctrl-C to stop it.\n")
|
|
237
|
+
out.write(
|
|
238
|
+
f"Coding agents reach its MCP server at {site}{_MCP} with the header "
|
|
239
|
+
f"X-Gvn-Token set to the token in {home / 'mcp-token'}.\n"
|
|
240
|
+
)
|
|
241
|
+
out.flush()
|
|
242
|
+
if open_browser:
|
|
243
|
+
webbrowser.open(address)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
def _supervised(
|
|
247
|
+
project: Project,
|
|
248
|
+
port: int,
|
|
249
|
+
open_browser: bool,
|
|
250
|
+
out: typing.TextIO,
|
|
251
|
+
address: ProjectAddress,
|
|
252
|
+
) -> None:
|
|
253
|
+
"""``serve`` with the server run, and started again after each save, as a child of
|
|
254
|
+
a ``gvn_workbench.editing.supervisor.Supervisor``."""
|
|
255
|
+
home = workbench_home(project.root())
|
|
256
|
+
mcp_token = kept_mcp_token(home)
|
|
257
|
+
listening = _bound(port)
|
|
258
|
+
try:
|
|
259
|
+
_announced(listening, home, out, open_browser)
|
|
260
|
+
files = project_files(project.root())
|
|
261
|
+
Supervisor(address, project.root(), listening, new_token(), mcp_token, files, out).run()
|
|
262
|
+
finally:
|
|
263
|
+
listening.close()
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def serve(
|
|
267
|
+
project: Project,
|
|
268
|
+
port: int = 8000,
|
|
269
|
+
open_browser: bool = False,
|
|
270
|
+
out: typing.TextIO | None = None,
|
|
271
|
+
spec: str | None = None,
|
|
272
|
+
pythonpath: Iterable[str] = (),
|
|
273
|
+
) -> None:
|
|
274
|
+
"""Serve the Workbench of ``project`` on this computer until interrupted (Ctrl-C
|
|
275
|
+
ends it quietly and this function returns).
|
|
276
|
+
|
|
277
|
+
``spec``: the project as ``package.module:attribute`` and ``pythonpath`` the
|
|
278
|
+
absolute folders put first on ``sys.path`` to load it (what ``gvn eval serve``
|
|
279
|
+
found): the server then runs supervised, as a child process that starts again on the
|
|
280
|
+
changed code after every save, on the same port with the same tokens (the
|
|
281
|
+
supervisor answers in the meantime, and says so when the changed code cannot start).
|
|
282
|
+
None (the default, as when called from Python): it runs in this process, and a save
|
|
283
|
+
answers that the Workbench has to be restarted.
|
|
284
|
+
|
|
285
|
+
Binds 127.0.0.1 only, never 0.0.0.0 or another interface: the site can write cases
|
|
286
|
+
files and record verdicts, so nothing outside this computer may reach it. A fresh
|
|
287
|
+
random token is made for this run and written into the page. The MCP server's token
|
|
288
|
+
is kept in ``<project root>/.gvn/workbench/mcp-token`` (made on the first start, mode
|
|
289
|
+
0600, read back after). ``port``: 0 to 65535 (0: any free port). ``open_browser``:
|
|
290
|
+
open the eval page in the default browser. ``out``: where the sentences with the eval
|
|
291
|
+
page's address and the way to connect a coding agent go (None: standard output).
|
|
292
|
+
Work against the project's stores runs one request at a time. OSError with a
|
|
293
|
+
sentence suggesting ``--port`` when the port is taken.
|
|
294
|
+
"""
|
|
295
|
+
if not isinstance(project, Project):
|
|
296
|
+
raise TypeError(f"project must be a Project, got {_kind(project)}")
|
|
297
|
+
if isinstance(port, bool) or not isinstance(port, int):
|
|
298
|
+
raise TypeError(f"port must be an int, got {_kind(port)}")
|
|
299
|
+
if not 0 <= port <= 65535:
|
|
300
|
+
raise ValueError(f"port must lie between 0 and 65535, got {port}")
|
|
301
|
+
if not isinstance(open_browser, bool):
|
|
302
|
+
raise TypeError(f"open_browser must be a bool, got {_kind(open_browser)}")
|
|
303
|
+
if out is None:
|
|
304
|
+
out = sys.stdout
|
|
305
|
+
if spec is not None:
|
|
306
|
+
if isinstance(pythonpath, (str, bytes)):
|
|
307
|
+
raise TypeError("pythonpath must be a list of folders, not one str")
|
|
308
|
+
_supervised(project, port, open_browser, out, ProjectAddress(spec, pythonpath, os.getcwd()))
|
|
309
|
+
return
|
|
310
|
+
home = workbench_home(project.root())
|
|
311
|
+
workbench = Workbench(project, new_token(), mcp_token=kept_mcp_token(home))
|
|
312
|
+
listening = _bound(port)
|
|
313
|
+
try:
|
|
314
|
+
config = uvicorn.Config(
|
|
315
|
+
workbench,
|
|
316
|
+
interface="asgi3",
|
|
317
|
+
lifespan="off",
|
|
318
|
+
log_config=None,
|
|
319
|
+
log_level="warning",
|
|
320
|
+
access_log=False,
|
|
321
|
+
proxy_headers=False,
|
|
322
|
+
server_header=False,
|
|
323
|
+
timeout_graceful_shutdown=_STOP_SECONDS,
|
|
324
|
+
)
|
|
325
|
+
server = uvicorn.Server(config)
|
|
326
|
+
_announced(listening, home, out, open_browser)
|
|
327
|
+
try:
|
|
328
|
+
asyncio.run(server.serve(sockets=[listening]))
|
|
329
|
+
except KeyboardInterrupt:
|
|
330
|
+
pass
|
|
331
|
+
finally:
|
|
332
|
+
listening.close()
|
|
333
|
+
workbench.close()
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"""Changing a project's harnesses: an edit group previewed as a patch, checked in a fresh
|
|
2
|
+
process, saved to the project's own Python files, and the Workbench back up on them.
|
|
3
|
+
|
|
4
|
+
Python is the only source of truth. ``gvn_workbench.source`` finds where each part of a
|
|
5
|
+
harness is written and turns a group of edits into new file texts; this package is
|
|
6
|
+
what a person (or an agent) does with that:
|
|
7
|
+
|
|
8
|
+
1. **List** what can be edited where (``GET /api/harnesses/<harness>/source``, and
|
|
9
|
+
``GET /api/versions/<version>/source`` for an eval version, such as a candidate with
|
|
10
|
+
its own plan): every target of a drawing, edited here (``own``), edited here and
|
|
11
|
+
elsewhere (``shared``) or defined in code (``code``), with its file and lines, the
|
|
12
|
+
kinds of edit it takes, and for a stage, join or child the settings it does not
|
|
13
|
+
write yet.
|
|
14
|
+
2. **Preview** a group (``POST /api/edits/preview``): the per-file diff, the notes, what
|
|
15
|
+
else each edit changes, and the result of loading the changed project in a fresh
|
|
16
|
+
process (``verification``: every plan of every harness and every version built,
|
|
17
|
+
every definition examined, every change read back). What the group still needs is
|
|
18
|
+
derived from what the verifier found, what the plan checks found and what its edits
|
|
19
|
+
require of each other: every further edit that can make it is offered as a ready
|
|
20
|
+
edit (``suggestions``) for the person to add to the group, and what no edit can make
|
|
21
|
+
is said with the file and line to change by hand (``by_hand``). Adding the
|
|
22
|
+
suggestions and previewing again leads to a group that verifies. Nothing is written,
|
|
23
|
+
and nothing is ever added to a group but by the person.
|
|
24
|
+
3. **Save** a group (``POST /api/edits/save``): the same checks, then each file replaced
|
|
25
|
+
atomically, never over a file that changed on disk since it was read
|
|
26
|
+
(``gvn_workbench.editing.editor`` says the protocol step by step). A failed save
|
|
27
|
+
leaves every file byte for byte as it was.
|
|
28
|
+
4. **Come back up** on the changed code. ``gvn eval serve`` runs the Workbench under a
|
|
29
|
+
supervisor (``gvn_workbench.editing.supervisor``) that keeps the port and both
|
|
30
|
+
tokens and starts the server again after every save; ``/api/project`` answers a new
|
|
31
|
+
``generation`` once it is back. Served from Python without the project's address,
|
|
32
|
+
a save answers that the Workbench has to be restarted.
|
|
33
|
+
|
|
34
|
+
Agents propose, people approve. The ``propose_edits`` tool (``propose``) takes the same
|
|
35
|
+
group, answers the preview, and keeps it as a pending proposal under
|
|
36
|
+
``<project root>/.gvn/workbench/proposals/``; it never writes a project file. Only a
|
|
37
|
+
request from the page, with the page's token, saves a proposal; the MCP token reaches
|
|
38
|
+
``/mcp`` only. The canvas layout is kept beside the project in
|
|
39
|
+
``.gvn/workbench/layouts.json``, never in its Python. Every file the Workbench writes for
|
|
40
|
+
itself is under ``.gvn/workbench/``.
|
|
41
|
+
|
|
42
|
+
Addresses
|
|
43
|
+
---------
|
|
44
|
+
|
|
45
|
+
All JSON; changing requests (POST, PUT, DELETE) carry the page's token. A refusal is
|
|
46
|
+
``{"error": "<one sentence>", ...}``: 400 for a request that does not read, 404 for a
|
|
47
|
+
harness, drawing or proposal that is not there, 409 for a save refused (with
|
|
48
|
+
``reason``).
|
|
49
|
+
|
|
50
|
+
``GET /api/harnesses/<harness>/source?template=<template>``
|
|
51
|
+
``{"harness", "template", "targets": [Located], "files": {<file>: <sha256>}}``.
|
|
52
|
+
Located is ``gvn_workbench.source.Located.plain()``: ``{"harness", "version",
|
|
53
|
+
"template", "target", "what", "tier": "own" | "shared" | "code", "file", "lines":
|
|
54
|
+
[first, last], "value", "kind", "shares": [Share], "reason", "edits": [<kind>],
|
|
55
|
+
"unwritten_settings": [{"setting", "target", "default", "plain_default", "edits":
|
|
56
|
+
[<kind>]}]}``. ``what``: the target in words ("the turns of the
|
|
57
|
+
reviewing_components child").
|
|
58
|
+
``harness`` or ``version`` names the owner (the other is null). ``edits``: the
|
|
59
|
+
kinds of edit (below) that apply to the target; none when it is defined in code.
|
|
60
|
+
``unwritten_settings``: for a ``stage:``, ``join:`` or ``child:`` constructor, each
|
|
61
|
+
setting its class takes that the source does not write, with the constructor's
|
|
62
|
+
default when ``plain_default`` (a plain literal); ``set_value`` on its ``target``
|
|
63
|
+
writes it as a new keyword argument.
|
|
64
|
+
|
|
65
|
+
``GET /api/versions/<version>/source?template=<template>``
|
|
66
|
+
The same for an eval version of the project: ``{"version", "same_as_harness",
|
|
67
|
+
"template", "targets": [Located], "files"}``. ``same_as_harness``: the harness the
|
|
68
|
+
version is, when its entry actor is that harness's very class (a baseline), else
|
|
69
|
+
null; such a version and its harness are one thing and share nothing with each
|
|
70
|
+
other. A target another version (a candidate built on the same chain or stages)
|
|
71
|
+
and a harness both reach is ``shared`` and names the other.
|
|
72
|
+
|
|
73
|
+
``POST /api/edits/preview`` ``{"edits": [Edit]}``
|
|
74
|
+
Preview: ``{"edits": [<each edit in a sentence>], "edit_targets": [{"kind",
|
|
75
|
+
"harness", "version", "template", "target"}], "patch": Patch, "bases": {<file>:
|
|
76
|
+
<sha256>}, "acknowledge": [<what>], "acknowledge_shares": [Share], "verification":
|
|
77
|
+
Verification | None, "suggestions": [Suggestion], "by_hand": [ByHand]}``. ``edits``
|
|
78
|
+
says each edit for a person ("Set the turns of the reviewing_components child to
|
|
79
|
+
3"); ``edit_targets`` says the same for programs, in the same order (``target`` as
|
|
80
|
+
``gvn_workbench.source`` names targets). ``bases``: the files the patch was made from
|
|
81
|
+
(send them back with the save). ``acknowledge``: every ``what`` the edits also
|
|
82
|
+
change, which a save needs in ``acknowledged``; ``acknowledge_shares``: the Share
|
|
83
|
+
behind each, in the same order. ``verification`` is None when the patch was
|
|
84
|
+
refused; ``suggestions`` and ``by_hand`` are given either way (a group refused
|
|
85
|
+
because one edit needs another is followed by that other).
|
|
86
|
+
|
|
87
|
+
``POST /api/edits/save`` ``{"edits": [Edit], "acknowledged": [<what>], "bases"?: {...}}``
|
|
88
|
+
``{"saved": true, "files": [{"path", "added", "removed"}], "restart": "restarting" |
|
|
89
|
+
"needed", "sentence"}``. Refused (409), writing nothing, with ``reason``:
|
|
90
|
+
``changed_on_disk`` (``changed``: the files; ``lost``: the Refusal of the edit that
|
|
91
|
+
no longer finds its place, or None and ``patch`` / ``bases``: the edits placed again
|
|
92
|
+
in the new text, to look at and save again), ``refused`` (``refusal``),
|
|
93
|
+
``not_acknowledged`` (``acknowledge``, ``acknowledge_shares``, ``changes``),
|
|
94
|
+
``verification_failed`` (``verification``, ``suggestions``, ``by_hand``) or
|
|
95
|
+
``write_failed`` (``file``; the files replaced before it are put back).
|
|
96
|
+
|
|
97
|
+
``GET /api/proposals``
|
|
98
|
+
``{"proposals": [{"id", "created", "note", "edits": [<sentence>], "files": [<file>],
|
|
99
|
+
"verified": bool, "acknowledge": [<what>], "stale": bool, "changed": [<file>]}]}``,
|
|
100
|
+
oldest first. ``stale``: a file the proposal was made from has changed since.
|
|
101
|
+
|
|
102
|
+
``GET /api/proposals/<id>``
|
|
103
|
+
The proposal in full: the Preview it was made with, ``id``, ``created``, ``note``,
|
|
104
|
+
``plain_edits`` (its group), ``stale``, ``changed``, ``stale_sentence``.
|
|
105
|
+
|
|
106
|
+
``POST /api/proposals/<id>/save`` ``{"acknowledged": [<what>]}``
|
|
107
|
+
Save it as ``/api/edits/save`` does, against the files it was proposed on; a saved
|
|
108
|
+
proposal is deleted. The answer adds ``proposal``.
|
|
109
|
+
|
|
110
|
+
``DELETE /api/proposals/<id>``
|
|
111
|
+
``{"deleted": <id>}``.
|
|
112
|
+
|
|
113
|
+
``GET /api/layouts/<harness>?template=<template>``
|
|
114
|
+
``{"harness", "template", "positions": {<state>: {"x": number, "y": number}}}``.
|
|
115
|
+
``PUT /api/layouts/<harness>?template=<template>`` ``{"positions": {...}}``
|
|
116
|
+
Keep the drawing's positions (each a state of the drawing, finite numbers, at most
|
|
117
|
+
2000 a drawing, the file at most 1 MB); answers them as kept.
|
|
118
|
+
|
|
119
|
+
While the supervisor has no server running (the changed code would not start), the
|
|
120
|
+
port answers 503 with ``{"error": <what failed>, "running": false}`` and ``POST
|
|
121
|
+
/api/workbench/restart`` (page token) tries again.
|
|
122
|
+
|
|
123
|
+
Edits
|
|
124
|
+
-----
|
|
125
|
+
|
|
126
|
+
Every edit is an object with ``kind``, its owner (``harness``: a harness's name, or
|
|
127
|
+
``version``: an eval version's name; one of the two), ``template`` (the template path
|
|
128
|
+
of the actor it changes, ``""`` for the entry actor), and the members below. Targets
|
|
129
|
+
and template paths are as ``gvn_workbench.source`` names them; state, input and output
|
|
130
|
+
names start with a letter and hold letters, digits, ``_ . -``. ``rewrite``? (true or
|
|
131
|
+
false) accepts the rewrite a refusal offered (``rewrite_offered``): the one statement
|
|
132
|
+
is written again and every comment it held is moved above it, each named in a
|
|
133
|
+
``moved_comment`` note and shown in the diff. Only ``set_value`` (a comment inside the
|
|
134
|
+
text or list it replaces), ``remove_inputs`` and ``remove_outputs`` (a comment between
|
|
135
|
+
the names) are ever offered one.
|
|
136
|
+
|
|
137
|
+
====================== ===================================== ============================
|
|
138
|
+
kind members what it does
|
|
139
|
+
====================== ===================================== ============================
|
|
140
|
+
``set_value`` ``target``, ``value`` (text, number, writes the value where a
|
|
141
|
+
true/false, null, or a list of these; ``stage:``, ``join:`` or
|
|
142
|
+
names for a list of references) ``child:`` setting is
|
|
143
|
+
written, or adds an
|
|
144
|
+
unwritten setting
|
|
145
|
+
``add_route`` ``state``, ``final``, ``symbol`` routes a child's final state
|
|
146
|
+
``change_route`` ``state``, ``final``, ``symbol`` routes it elsewhere
|
|
147
|
+
``remove_route`` ``state``, ``final`` removes its route
|
|
148
|
+
``add_transition`` ``source``, ``input``, ``target``, adds ``.on(...)`` (output on
|
|
149
|
+
``output``? (Mealy only) a Mealy machine only)
|
|
150
|
+
``remove_transition`` ``source``, ``input`` removes it (a branch's route
|
|
151
|
+
with its outcome in the
|
|
152
|
+
branch's ``Alphabet.of``;
|
|
153
|
+
the whole ``.branch`` with
|
|
154
|
+
its last route)
|
|
155
|
+
``retarget_transition`` ``source``, ``input``, ``target`` points it elsewhere
|
|
156
|
+
``add_state`` ``name`` a state with an Agent stage
|
|
157
|
+
``remove_state`` ``name`` the state, its transitions
|
|
158
|
+
and its stage in every plan;
|
|
159
|
+
a final state only once the
|
|
160
|
+
group leaves nothing
|
|
161
|
+
reaching it
|
|
162
|
+
``rename_state`` ``old``, ``new`` everywhere the chain is used
|
|
163
|
+
``reorder_states`` ``order`` (every state, once) the ``.state`` calls' order
|
|
164
|
+
``swap_join`` ``state``, ``join`` (``AllOf``, the join's class
|
|
165
|
+
``AnyOf``, ``Quorum``), ``count``?
|
|
166
|
+
(a Quorum's, only)
|
|
167
|
+
``remove_inputs`` ``names`` (a list, one at least) inputs nothing reads once
|
|
168
|
+
the group is made
|
|
169
|
+
``remove_outputs`` ``names`` (a list, one at least) outputs nothing emits once
|
|
170
|
+
the group is made
|
|
171
|
+
====================== ===================================== ============================
|
|
172
|
+
|
|
173
|
+
Values
|
|
174
|
+
------
|
|
175
|
+
|
|
176
|
+
Share
|
|
177
|
+
``{"what", "harness", "version", "template", "target", "file", "line"}``: something
|
|
178
|
+
else an edit changes. ``what`` says it for a person: the same target of another
|
|
179
|
+
owner ("the same setting of the version candidate"), another target of another owner
|
|
180
|
+
("the turns of the reviewing child of the harness other"), another plan built on the
|
|
181
|
+
same machine ("the plan at src/x.py:40, built on the same machine"), or another read
|
|
182
|
+
of the constant the edit changes ("COMPONENT_REVIEW_TURNS is also read at
|
|
183
|
+
src/release_review/candidate.py:92"). The other members say the same for programs:
|
|
184
|
+
``harness`` or ``version`` names the other owner, with its ``template`` and raw
|
|
185
|
+
``target`` (all three null for a plan or a read of a constant).
|
|
186
|
+
|
|
187
|
+
Patch
|
|
188
|
+
``{"refusal": {"edit", "sentence", "rewrite_offered": bool} | None, "files":
|
|
189
|
+
[{"path", "base": {"path", "sha256", "mtime_ns", "size"}, "added", "removed"}],
|
|
190
|
+
"diff": <unified diff of every file>, "changes": [{"edit", "kind", "harness",
|
|
191
|
+
"version", "template", "target", "also_changes": [Share]}], "notes": [{"kind":
|
|
192
|
+
"left_behind" | "orphaned_comment" | "moved_comment" | "long_line" | "no_stage" |
|
|
193
|
+
"covered", "file", "line", "note"}]}``. A change's ``edit`` is the edit's sentence,
|
|
194
|
+
the other members its raw kind, owner, template and target. A group is refused when
|
|
195
|
+
one of its edits needs another to go with it (removing an input a transition still
|
|
196
|
+
reads, a final state a transition still reaches) and the group does not make it.
|
|
197
|
+
|
|
198
|
+
Edits of one group may change the same text. An edit whose every change lies inside
|
|
199
|
+
text another edit of the group removes is covered by it, and a ``covered`` note
|
|
200
|
+
says so ("'Point the transition from a on x at b' is covered by removing the state
|
|
201
|
+
a"); the same change made twice is made once; removals of inputs (or of outputs) of
|
|
202
|
+
one machine, and removals of every route of one branch, are made together (noted
|
|
203
|
+
too). A covered note has no ``file`` or ``line``. Two edits writing different values
|
|
204
|
+
over the same text are refused, naming both ("... set the same thing in <file> to
|
|
205
|
+
different values; keep one of them"); any other overlap is refused naming both and
|
|
206
|
+
saying to save one of them first.
|
|
207
|
+
|
|
208
|
+
Verification
|
|
209
|
+
``{"ok": bool, "loaded": bool, "seconds": number, "sentence", "checked": [{"what":
|
|
210
|
+
"harness <name>" | "version <name>", "plans", "definitions"}], "problems": [{"what",
|
|
211
|
+
"harness", "version", "template", "sentence", "findings": [{"code", "subject",
|
|
212
|
+
"message"}], "file", "line"}], "effects": [{"edit", "ok", "sentence"}]}``. ``findings`` are the
|
|
213
|
+
verifier's (``gvn.kernel.verifier`` codes) or a plan's problems
|
|
214
|
+
(``plan-rejected``). A process that could not start, failed or ran past its time
|
|
215
|
+
limit is one problem in words.
|
|
216
|
+
|
|
217
|
+
Suggestion
|
|
218
|
+
``{"why": <sentence>, "edit": Edit, "sentence": <the edit's sentence>}``: a further
|
|
219
|
+
edit the group needs, ready to add to it, together with every other suggestion of
|
|
220
|
+
the same answer: ``remove_inputs`` for the inputs no transition uses,
|
|
221
|
+
``remove_outputs`` for the outputs nothing emits, ``remove_state`` for each state
|
|
222
|
+
nothing reaches, ``remove_transition`` for each transition still reaching a state the
|
|
223
|
+
group removes or still reading an input it removes, and ``change_route`` for each
|
|
224
|
+
route of a stage still ending it with such an input (sent to another symbol the
|
|
225
|
+
stage ends with). Each is placed with the group and the suggestions before it, so
|
|
226
|
+
what one requires is suggested beside it.
|
|
227
|
+
|
|
228
|
+
ByHand
|
|
229
|
+
``{"sentence", "file", "line"}``: what the group still needs that no edit can make,
|
|
230
|
+
in one sentence naming the file and line a person changes by hand: a judge's
|
|
231
|
+
Decision class that still answers an outcome nothing leads from any more, a branch
|
|
232
|
+
whose outcomes are a constant, a name written in code the edits do not reach.
|
|
233
|
+
"""
|
|
234
|
+
|
|
235
|
+
from gvn_workbench.editing.address import ProjectAddress
|
|
236
|
+
from gvn_workbench.editing.editor import Editor
|
|
237
|
+
from gvn_workbench.editing.errors import Refused
|
|
238
|
+
from gvn_workbench.editing.replacing import AtomicReplacer, ChangedSince, FileReplacer
|
|
239
|
+
from gvn_workbench.editing.shapes import SHAPES, edit_from_plain, group_plain
|
|
240
|
+
from gvn_workbench.editing.verification import FreshCheck, Verification
|
|
241
|
+
|
|
242
|
+
__all__ = [
|
|
243
|
+
"SHAPES",
|
|
244
|
+
"AtomicReplacer",
|
|
245
|
+
"ChangedSince",
|
|
246
|
+
"Editor",
|
|
247
|
+
"FileReplacer",
|
|
248
|
+
"FreshCheck",
|
|
249
|
+
"ProjectAddress",
|
|
250
|
+
"Refused",
|
|
251
|
+
"Verification",
|
|
252
|
+
"edit_from_plain",
|
|
253
|
+
"group_plain",
|
|
254
|
+
]
|