ratifypoint 3.0.4__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.
- ratifypoint/__init__.py +3 -0
- ratifypoint/adapter/__init__.py +5 -0
- ratifypoint/adapter/server.py +413 -0
- ratifypoint/adapter/texts.py +108 -0
- ratifypoint/cli.py +75 -0
- ratifypoint/commands/__init__.py +19 -0
- ratifypoint/commands/checks.py +58 -0
- ratifypoint/commands/clean.py +368 -0
- ratifypoint/commands/edit.py +370 -0
- ratifypoint/commands/init.py +52 -0
- ratifypoint/commands/save.py +98 -0
- ratifypoint/commands/session.py +251 -0
- ratifypoint/commands/versions.py +100 -0
- ratifypoint/delivery/__init__.py +27 -0
- ratifypoint/delivery/context.py +322 -0
- ratifypoint/delivery/receipt.py +70 -0
- ratifypoint/hooks/__init__.py +5 -0
- ratifypoint/hooks/hooks.py +57 -0
- ratifypoint/integrations/__init__.py +21 -0
- ratifypoint/integrations/install.py +144 -0
- ratifypoint/integrations/plugin.py +81 -0
- ratifypoint/knowledge/__init__.py +19 -0
- ratifypoint/knowledge/conflicts.py +106 -0
- ratifypoint/knowledge/duplicates.py +128 -0
- ratifypoint/knowledge/integrity.py +75 -0
- ratifypoint/knowledge/lifecycle.py +90 -0
- ratifypoint/knowledge/related.py +54 -0
- ratifypoint/model/__init__.py +7 -0
- ratifypoint/model/form.py +508 -0
- ratifypoint/model/ids.py +27 -0
- ratifypoint/model/json.py +51 -0
- ratifypoint/model/profile.py +26 -0
- ratifypoint/model/scope.py +51 -0
- ratifypoint/presentation/__init__.py +7 -0
- ratifypoint/presentation/form.py +238 -0
- ratifypoint/presentation/record.py +85 -0
- ratifypoint/presentation/search.py +106 -0
- ratifypoint/presentation/window.py +67 -0
- ratifypoint/report.py +333 -0
- ratifypoint/show.py +29 -0
- ratifypoint/status.py +69 -0
- ratifypoint/storage/__init__.py +15 -0
- ratifypoint/storage/files.py +228 -0
- ratifypoint/storage/project.py +149 -0
- ratifypoint-3.0.4.dist-info/METADATA +136 -0
- ratifypoint-3.0.4.dist-info/RECORD +50 -0
- ratifypoint-3.0.4.dist-info/WHEEL +5 -0
- ratifypoint-3.0.4.dist-info/entry_points.txt +2 -0
- ratifypoint-3.0.4.dist-info/licenses/LICENSE +202 -0
- ratifypoint-3.0.4.dist-info/top_level.txt +1 -0
ratifypoint/__init__.py
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
"""The MCP server: tools, windows of elicitation and errors."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from collections.abc import Callable
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import anyio
|
|
9
|
+
import mcp_types as types
|
|
10
|
+
from mcp.server.context import ServerRequestContext
|
|
11
|
+
from mcp.server.lowlevel import Server
|
|
12
|
+
from mcp.server.runner import serve_loop
|
|
13
|
+
from mcp.server.stdio import stdio_server
|
|
14
|
+
from mcp.shared.exceptions import MCPError
|
|
15
|
+
|
|
16
|
+
from .. import __version__
|
|
17
|
+
from ..commands import (
|
|
18
|
+
Answer,
|
|
19
|
+
Cleaner,
|
|
20
|
+
CommandError,
|
|
21
|
+
Editor,
|
|
22
|
+
Initializer,
|
|
23
|
+
Saver,
|
|
24
|
+
Session,
|
|
25
|
+
Window,
|
|
26
|
+
)
|
|
27
|
+
from ..model.form import KINDS, STATES
|
|
28
|
+
from ..presentation import errors_text
|
|
29
|
+
from ..storage import NotInRepositoryError
|
|
30
|
+
from .texts import DESCRIPTIONS, INSTRUCTIONS
|
|
31
|
+
|
|
32
|
+
TEXTS = {"type": "array", "items": {"type": "string"}}
|
|
33
|
+
SCHEMAS: dict[str, dict[str, Any]] = {
|
|
34
|
+
"get_project_context": {
|
|
35
|
+
"properties": {
|
|
36
|
+
"paths": {
|
|
37
|
+
**TEXTS,
|
|
38
|
+
"description": (
|
|
39
|
+
"Up to 10 project paths; prefer paths relative to the repository "
|
|
40
|
+
"root. End folder paths with /. Omit or pass [] for start "
|
|
41
|
+
"context. A folder request does not list its subtree."
|
|
42
|
+
),
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"get_record": {
|
|
47
|
+
"properties": {
|
|
48
|
+
"ids": {
|
|
49
|
+
**TEXTS,
|
|
50
|
+
"description": (
|
|
51
|
+
"Required list of 1–20 record ids from context or search results."
|
|
52
|
+
),
|
|
53
|
+
},
|
|
54
|
+
"details": {
|
|
55
|
+
"type": "boolean",
|
|
56
|
+
"description": (
|
|
57
|
+
"Include author, timestamps, confirmation, client and lifecycle "
|
|
58
|
+
"metadata. Defaults to false; cannot be true with fields."
|
|
59
|
+
),
|
|
60
|
+
},
|
|
61
|
+
"history": {
|
|
62
|
+
"type": "boolean",
|
|
63
|
+
"description": (
|
|
64
|
+
"Include summaries of earlier and later versions. Defaults to "
|
|
65
|
+
"false; cannot be true with fields. Read a version by its id "
|
|
66
|
+
"for its full contents."
|
|
67
|
+
),
|
|
68
|
+
},
|
|
69
|
+
"fields": {
|
|
70
|
+
**TEXTS,
|
|
71
|
+
"description": (
|
|
72
|
+
"Non-empty list of RFC 6901 JSON Pointers, e.g. "
|
|
73
|
+
"/properties/memory/bytes. Array indexes start at 0; escape ~ "
|
|
74
|
+
"as ~0 and / as ~1 in keys. Missing paths are errors. Do not "
|
|
75
|
+
"combine with details/history. Omit for full records."
|
|
76
|
+
),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
"required": ["ids"],
|
|
80
|
+
},
|
|
81
|
+
"search_records": {
|
|
82
|
+
"properties": {
|
|
83
|
+
"query": {
|
|
84
|
+
"type": "string",
|
|
85
|
+
"description": (
|
|
86
|
+
"Topic words, a question, entity name or alias. Matches any "
|
|
87
|
+
"whole normalized query word, ignoring case; punctuation "
|
|
88
|
+
"separates words. Omit or leave empty to list newest records "
|
|
89
|
+
"within the selected filters."
|
|
90
|
+
),
|
|
91
|
+
},
|
|
92
|
+
"kinds": {
|
|
93
|
+
"type": "array",
|
|
94
|
+
"items": {"enum": list(KINDS)},
|
|
95
|
+
"description": (
|
|
96
|
+
"Record kinds to include. Omit or pass [] to search all kinds."
|
|
97
|
+
),
|
|
98
|
+
},
|
|
99
|
+
"states": {
|
|
100
|
+
"type": "array",
|
|
101
|
+
"items": {"enum": list(STATES)},
|
|
102
|
+
"description": (
|
|
103
|
+
"Lifecycle states to include. Omit or pass [] for active. "
|
|
104
|
+
"Active results may include future or expired knowledge with "
|
|
105
|
+
"warnings. Use replaced, outdated or closed when needed."
|
|
106
|
+
),
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"get_record_form": {
|
|
111
|
+
"properties": {
|
|
112
|
+
"kinds": {
|
|
113
|
+
"type": "array",
|
|
114
|
+
"items": {"enum": list(KINDS)},
|
|
115
|
+
"description": (
|
|
116
|
+
"Required non-empty list of record kinds whose forms are needed."
|
|
117
|
+
),
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"required": ["kinds"],
|
|
121
|
+
},
|
|
122
|
+
"save_record": {
|
|
123
|
+
"properties": {
|
|
124
|
+
"record": {
|
|
125
|
+
"type": "object",
|
|
126
|
+
"description": (
|
|
127
|
+
"One new record object containing kind and the fields returned "
|
|
128
|
+
"by get_record_form. Do not pass a list, record id, author, "
|
|
129
|
+
"timestamps or confirmation. Scope the knowledge to where it "
|
|
130
|
+
"applies. Never include secrets."
|
|
131
|
+
),
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
"required": ["record"],
|
|
135
|
+
},
|
|
136
|
+
"edit_record": {
|
|
137
|
+
"properties": {
|
|
138
|
+
"edit": {
|
|
139
|
+
"type": "object",
|
|
140
|
+
"description": (
|
|
141
|
+
"One operation object containing action, its target and "
|
|
142
|
+
"action-specific fields. Put replacement fields directly "
|
|
143
|
+
"inside this object, without a changes wrapper.\n"
|
|
144
|
+
"Actions (action is required):\n"
|
|
145
|
+
"- replace: id and changed form fields; creates a new version. "
|
|
146
|
+
"To merge, use ids with at least two distinct record ids "
|
|
147
|
+
"instead of id.\n"
|
|
148
|
+
"- delete: id; marks the record outdated, retaining its file.\n"
|
|
149
|
+
"- restore: id; reactivates an outdated or replaced record.\n"
|
|
150
|
+
"- confirm: id; requests confirmation that the current record "
|
|
151
|
+
"is correct, not agent-supplied approval.\n"
|
|
152
|
+
"- close: id of a question and answer_id of an existing answer "
|
|
153
|
+
"record.\n"
|
|
154
|
+
"- link: id and other_id; adds a related-record link.\n"
|
|
155
|
+
"- not_conflict: id and other_id; removes a conflict mark "
|
|
156
|
+
"between the records.\n"
|
|
157
|
+
"- rename_area: area and new_area, without id; renames a topic "
|
|
158
|
+
"tag in every record.\n"
|
|
159
|
+
"For replace, clear lists form fields to remove; the resulting "
|
|
160
|
+
"record must remain valid. properties is the complete new "
|
|
161
|
+
"profile JSON object. Other replacement fields follow the "
|
|
162
|
+
"selected kind's get_record_form. "
|
|
163
|
+
'Example: {"id": "<record-id>", "action": "replace", '
|
|
164
|
+
'"statement": "Updated knowledge."}.'
|
|
165
|
+
),
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
"required": ["edit"],
|
|
169
|
+
},
|
|
170
|
+
"init_project": {"properties": {}},
|
|
171
|
+
"clean_memory": {"properties": {}},
|
|
172
|
+
}
|
|
173
|
+
READ_ONLY = types.ToolAnnotations(read_only_hint=True, open_world_hint=False)
|
|
174
|
+
# Promises of RatifyPoint: a repeated call changes nothing more.
|
|
175
|
+
CHANGES = types.ToolAnnotations(
|
|
176
|
+
read_only_hint=False,
|
|
177
|
+
destructive_hint=False,
|
|
178
|
+
idempotent_hint=True,
|
|
179
|
+
open_world_hint=False,
|
|
180
|
+
)
|
|
181
|
+
ANNOTATIONS = {
|
|
182
|
+
"get_project_context": READ_ONLY,
|
|
183
|
+
"get_record": READ_ONLY,
|
|
184
|
+
"search_records": READ_ONLY,
|
|
185
|
+
"get_record_form": READ_ONLY,
|
|
186
|
+
"save_record": CHANGES,
|
|
187
|
+
"edit_record": CHANGES,
|
|
188
|
+
"init_project": CHANGES,
|
|
189
|
+
"clean_memory": READ_ONLY,
|
|
190
|
+
}
|
|
191
|
+
LABELS = {
|
|
192
|
+
"approve": "Yes",
|
|
193
|
+
"cancel": "Skip",
|
|
194
|
+
"change": "Change",
|
|
195
|
+
"other": "Other (type it in the text field)",
|
|
196
|
+
"replace": "Replace",
|
|
197
|
+
"keep_existing": "Keep existing",
|
|
198
|
+
"keep": "Keep",
|
|
199
|
+
"delete": "Delete",
|
|
200
|
+
"local": "Local: only on this computer",
|
|
201
|
+
"shared": "Shared: in Git with the project",
|
|
202
|
+
"english": "English",
|
|
203
|
+
}
|
|
204
|
+
NOT_IN_GIT = (
|
|
205
|
+
"RatifyPoint needs a Git repository: the server started in {start}, which is "
|
|
206
|
+
"not inside one. Fix: configure the RatifyPoint MCP server at the project level "
|
|
207
|
+
"so it starts in the project folder, or run git init there."
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
Context = ServerRequestContext[Any]
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
class Adapter:
|
|
214
|
+
"""The commands of one server process and the request whose windows they
|
|
215
|
+
show. Calls run one at a time to keep each confirmation with its operation."""
|
|
216
|
+
|
|
217
|
+
def __init__(self, start: Path, home: Path) -> None:
|
|
218
|
+
self.start = start
|
|
219
|
+
self.home = home
|
|
220
|
+
self.lock = anyio.Lock()
|
|
221
|
+
self.request: Context | None = None
|
|
222
|
+
self.commands: dict[
|
|
223
|
+
str, Callable[[dict[str, Any]], str | dict[str, object]]
|
|
224
|
+
] = {}
|
|
225
|
+
|
|
226
|
+
async def list_tools(
|
|
227
|
+
self, ctx: Context, params: types.PaginatedRequestParams | None
|
|
228
|
+
) -> types.ListToolsResult:
|
|
229
|
+
tools = []
|
|
230
|
+
for name, description in DESCRIPTIONS.items():
|
|
231
|
+
meta = None
|
|
232
|
+
# Loaded at once in Claude Code, without a tool search.
|
|
233
|
+
if name == "get_project_context":
|
|
234
|
+
meta = {"anthropic/alwaysLoad": True}
|
|
235
|
+
schema = {"type": "object", **SCHEMAS[name]}
|
|
236
|
+
tools.append(
|
|
237
|
+
types.Tool(
|
|
238
|
+
name=name,
|
|
239
|
+
description=description,
|
|
240
|
+
input_schema=schema,
|
|
241
|
+
annotations=ANNOTATIONS[name],
|
|
242
|
+
_meta=meta,
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
return types.ListToolsResult(tools=tools)
|
|
246
|
+
|
|
247
|
+
async def call_tool(
|
|
248
|
+
self, ctx: Context, params: types.CallToolRequestParams
|
|
249
|
+
) -> types.CallToolResult:
|
|
250
|
+
async with self.lock:
|
|
251
|
+
self.request = ctx
|
|
252
|
+
try:
|
|
253
|
+
text = await anyio.to_thread.run_sync(self._call, params)
|
|
254
|
+
except CommandError as error:
|
|
255
|
+
return _result(str(error), True)
|
|
256
|
+
except Exception as error:
|
|
257
|
+
internal = (
|
|
258
|
+
f"Internal error: {type(error).__name__}: {error}. "
|
|
259
|
+
"This is a RatifyPoint bug; tell the user.\n"
|
|
260
|
+
)
|
|
261
|
+
return _result(internal, True)
|
|
262
|
+
return _result(text, False)
|
|
263
|
+
|
|
264
|
+
def _call(self, params: types.CallToolRequestParams) -> str | dict[str, object]:
|
|
265
|
+
# The low-level server of the SDK does not check tool names.
|
|
266
|
+
if params.name not in DESCRIPTIONS:
|
|
267
|
+
raise CommandError(f"Unknown tool: {params.name}.\n")
|
|
268
|
+
arguments = params.arguments or {}
|
|
269
|
+
# Nor arguments: one the tool does not have would be ignored silently.
|
|
270
|
+
allowed = list(SCHEMAS[params.name]["properties"])
|
|
271
|
+
known = ", ".join(allowed) or "no arguments"
|
|
272
|
+
errors = []
|
|
273
|
+
for name in arguments:
|
|
274
|
+
if name not in allowed:
|
|
275
|
+
errors.append(f"{name}: unknown argument. Fix: use {known}.")
|
|
276
|
+
if errors:
|
|
277
|
+
raise CommandError(errors_text(errors))
|
|
278
|
+
if not self.commands:
|
|
279
|
+
self._start()
|
|
280
|
+
return self.commands[params.name](arguments)
|
|
281
|
+
|
|
282
|
+
def _start(self) -> None:
|
|
283
|
+
"""The session and the commands, on the first call made inside Git."""
|
|
284
|
+
client = None
|
|
285
|
+
assert self.request is not None
|
|
286
|
+
client_params = self.request.session.client_params
|
|
287
|
+
if client_params is not None:
|
|
288
|
+
client = client_params.client_info.name
|
|
289
|
+
try:
|
|
290
|
+
session = Session(self.start, self.home, client, self.ask)
|
|
291
|
+
except NotInRepositoryError as error:
|
|
292
|
+
raise CommandError(NOT_IN_GIT.format(start=self.start) + "\n") from error
|
|
293
|
+
saver = Saver(session)
|
|
294
|
+
editor = Editor(session)
|
|
295
|
+
initializer = Initializer(session)
|
|
296
|
+
cleaner = Cleaner(session)
|
|
297
|
+
self.commands = {
|
|
298
|
+
"get_project_context": lambda a: session.project_context(
|
|
299
|
+
a.get("paths") or []
|
|
300
|
+
),
|
|
301
|
+
"get_record": lambda a: session.record(
|
|
302
|
+
a.get("ids") or [],
|
|
303
|
+
bool(a.get("details")),
|
|
304
|
+
bool(a.get("history")),
|
|
305
|
+
a.get("fields"),
|
|
306
|
+
),
|
|
307
|
+
"search_records": lambda a: session.search(
|
|
308
|
+
a.get("query") or "", a.get("kinds") or [], a.get("states") or []
|
|
309
|
+
),
|
|
310
|
+
"get_record_form": lambda a: session.form(a.get("kinds") or []),
|
|
311
|
+
"save_record": lambda a: saver.save(a.get("record")),
|
|
312
|
+
"edit_record": lambda a: editor.edit(a.get("edit")),
|
|
313
|
+
"init_project": lambda a: initializer.init(),
|
|
314
|
+
"clean_memory": lambda a: cleaner.clean(),
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
def ask(self, window: Window) -> Answer | None:
|
|
318
|
+
"""A window of elicitation, from the command's thread."""
|
|
319
|
+
assert self.request is not None
|
|
320
|
+
capabilities = self.request.session.client_capabilities
|
|
321
|
+
if capabilities is None or capabilities.elicitation is None:
|
|
322
|
+
return None
|
|
323
|
+
return anyio.from_thread.run(_elicit, self.request, window)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
async def _elicit(request: Context, window: Window) -> Answer | None:
|
|
327
|
+
"""Windows only the old way, by a request in the middle of a call: a client
|
|
328
|
+
of the 2026-07-28 revision has no channel for it and fails like a broken
|
|
329
|
+
window. A window without options asks only for its text field."""
|
|
330
|
+
try:
|
|
331
|
+
result = await request.session.elicit_form(
|
|
332
|
+
window.text, _schema(window), request.request_id
|
|
333
|
+
)
|
|
334
|
+
except MCPError as error:
|
|
335
|
+
raise CommandError(
|
|
336
|
+
f"Not applied: {window.text.splitlines()[0].rstrip('.')}. "
|
|
337
|
+
"The MCP confirmation request failed; no approval was received. "
|
|
338
|
+
"Check the client elicitation settings before trying again.\n"
|
|
339
|
+
) from error
|
|
340
|
+
# Clients can decline automatically without showing the question to anyone.
|
|
341
|
+
if result.action == "decline":
|
|
342
|
+
return Answer("decline")
|
|
343
|
+
if result.action == "cancel":
|
|
344
|
+
return Answer("close")
|
|
345
|
+
content = result.content
|
|
346
|
+
if content is None:
|
|
347
|
+
return Answer("invalid", "the client accepted the form without content")
|
|
348
|
+
option = content.get("answer") if window.options else "other"
|
|
349
|
+
allowed = window.options or ("other",)
|
|
350
|
+
if not isinstance(option, str) or option not in allowed:
|
|
351
|
+
return Answer(
|
|
352
|
+
"invalid",
|
|
353
|
+
f"the client returned answer {option!r}; expected {', '.join(allowed)}",
|
|
354
|
+
)
|
|
355
|
+
text = content.get("text", "")
|
|
356
|
+
if not isinstance(text, str) or (not window.options and "text" not in content):
|
|
357
|
+
return Answer("invalid", "the client did not return the required text string")
|
|
358
|
+
return Answer(option, text)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def _schema(window: Window) -> dict[str, Any]:
|
|
362
|
+
"""The choice of options with the details under it, and the text field."""
|
|
363
|
+
if not window.options:
|
|
364
|
+
text = {"type": "string", "title": window.field, "description": window.question}
|
|
365
|
+
return {"type": "object", "properties": {"text": text}, "required": ["text"]}
|
|
366
|
+
answer: dict[str, Any] = {
|
|
367
|
+
"type": "string",
|
|
368
|
+
"title": window.question,
|
|
369
|
+
"oneOf": [
|
|
370
|
+
{"const": option, "title": LABELS[option]} for option in window.options
|
|
371
|
+
],
|
|
372
|
+
}
|
|
373
|
+
if window.details:
|
|
374
|
+
answer["description"] = window.details
|
|
375
|
+
properties: dict[str, Any] = {"answer": answer}
|
|
376
|
+
if window.field is not None:
|
|
377
|
+
properties["text"] = {"type": "string", "title": window.field}
|
|
378
|
+
return {"type": "object", "properties": properties, "required": ["answer"]}
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def create_server(start: Path, home: Path) -> Server[Any]:
|
|
382
|
+
adapter = Adapter(start, home)
|
|
383
|
+
return Server(
|
|
384
|
+
"ratifypoint",
|
|
385
|
+
version=__version__,
|
|
386
|
+
instructions=INSTRUCTIONS,
|
|
387
|
+
on_list_tools=adapter.list_tools,
|
|
388
|
+
on_call_tool=adapter.call_tool,
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
async def serve(start: Path, home: Path) -> None:
|
|
393
|
+
"""The server on stdio until the client closes it. Only the handshake era
|
|
394
|
+
of MCP: its windows are requests in the middle of a call; a
|
|
395
|
+
client that probes the 2026-07-28 era falls back to `initialize`."""
|
|
396
|
+
mcp_server = create_server(start, home)
|
|
397
|
+
options = mcp_server.create_initialization_options()
|
|
398
|
+
async with stdio_server() as (read, write):
|
|
399
|
+
await serve_loop(
|
|
400
|
+
mcp_server, read, write, lifespan_state={}, init_options=options
|
|
401
|
+
)
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def _result(body: str | dict[str, object], error: bool) -> types.CallToolResult:
|
|
405
|
+
if isinstance(body, str):
|
|
406
|
+
return types.CallToolResult(
|
|
407
|
+
content=[types.TextContent(text=body)], is_error=error
|
|
408
|
+
)
|
|
409
|
+
return types.CallToolResult(
|
|
410
|
+
content=[types.TextContent(text=json.dumps(body, ensure_ascii=False))],
|
|
411
|
+
structured_content=body,
|
|
412
|
+
is_error=error,
|
|
413
|
+
)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"""Server instructions and tool contracts."""
|
|
2
|
+
|
|
3
|
+
INSTRUCTIONS = (
|
|
4
|
+
"RatifyPoint stores this project's user-confirmed rules, decisions, facts, "
|
|
5
|
+
"procedures and entity profiles.\n"
|
|
6
|
+
"- Reuse context already available. If the start context is missing, call "
|
|
7
|
+
"get_project_context without paths. Before editing or creating files, call it "
|
|
8
|
+
"with their paths unless that context is already available.\n"
|
|
9
|
+
"- Consult saved knowledge when the task needs project-specific requirements, "
|
|
10
|
+
"earlier decisions, facts or procedures. Before connecting to, querying or "
|
|
11
|
+
"changing a project resource, server, service, environment or database, "
|
|
12
|
+
"consult its relevant profile, including for read-only work. Do this without "
|
|
13
|
+
"waiting for the user to request a RatifyPoint lookup.\n"
|
|
14
|
+
"- If a relevant record is already listed, use get_record to read the details "
|
|
15
|
+
"the task needs. Otherwise, use search_records by topic, entity name or alias, "
|
|
16
|
+
"then read relevant results. Profile summaries omit parameters and restrictions; "
|
|
17
|
+
"procedure summaries omit steps. Apply scopes, dates and warnings.\n"
|
|
18
|
+
"- Propose only lasting knowledge the user stated or asked to keep. Read "
|
|
19
|
+
"get_record_form for its kind first. Use save_record for new knowledge and "
|
|
20
|
+
"edit_record to correct or extend existing knowledge. Before creating a "
|
|
21
|
+
"profile, look for the same entity; before editing, read the current record. "
|
|
22
|
+
"A supplied properties object replaces the whole object: preserve unchanged "
|
|
23
|
+
"properties.\n"
|
|
24
|
+
"- When the user corrects saved knowledge or a completed, user-approved "
|
|
25
|
+
"change makes it outdated, read the affected records and propose edit_record "
|
|
26
|
+
"before finishing the task, without waiting for a request to update "
|
|
27
|
+
"RatifyPoint. Replace changed knowledge; retire records that no longer apply. "
|
|
28
|
+
"If the change is uncertain or code merely conflicts with a saved rule, "
|
|
29
|
+
"explain the discrepancy and clarify it with the user before proposing "
|
|
30
|
+
"a replacement.\n"
|
|
31
|
+
"- RatifyPoint asks the user directly through MCP. Never supply approval, "
|
|
32
|
+
"retry a declined request without the user asking, or write record files "
|
|
33
|
+
"to bypass confirmation. Report what the tool actually saved or changed.\n"
|
|
34
|
+
"- Never store passwords, tokens or other secrets. Recording knowledge does "
|
|
35
|
+
"not authorize operations on the infrastructure it describes."
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
DESCRIPTIONS = {
|
|
39
|
+
"get_project_context": (
|
|
40
|
+
"Use when the start context is missing or before editing or creating files. "
|
|
41
|
+
"Without paths, returns project-wide records and a count of scoped records. "
|
|
42
|
+
"With paths, returns applicable scoped records, including parent scopes; "
|
|
43
|
+
"project-wide records remain in the start context. A folder request does not "
|
|
44
|
+
"list its subtree. Read relevant indexed records with get_record; use "
|
|
45
|
+
"search_records to find knowledge by topic or entity."
|
|
46
|
+
),
|
|
47
|
+
"get_record": (
|
|
48
|
+
"Use to read details of a listed or found record, including profile "
|
|
49
|
+
"parameters, operating restrictions and procedure steps, or before editing "
|
|
50
|
+
"existing knowledge. Returns full records by default; fields selects exact "
|
|
51
|
+
"JSON values as structured content and matching JSON text. All reading "
|
|
52
|
+
"modes retain trust, lifecycle and date warnings. Apply scopes, dates and "
|
|
53
|
+
"warnings before using the knowledge."
|
|
54
|
+
),
|
|
55
|
+
"search_records": (
|
|
56
|
+
"Use when the task needs project knowledge that has not been located, "
|
|
57
|
+
"including profiles of resources, servers, services, environments and "
|
|
58
|
+
"database connections for read-only work. Searches whole normalized words "
|
|
59
|
+
"in record text, tags, scope paths and string property values; JSON keys "
|
|
60
|
+
"and non-string values are not searched. Returns up to 50 summaries with "
|
|
61
|
+
"ids, ranked by relevance; an empty query lists newest first. Read relevant "
|
|
62
|
+
"results with get_record. Narrow the query when more results match."
|
|
63
|
+
),
|
|
64
|
+
"get_record_form": (
|
|
65
|
+
"Use before preparing a new record or changing record fields when its "
|
|
66
|
+
"form is not already available. Returns required and optional fields, "
|
|
67
|
+
"allowed values, limits, examples and the project's record language. "
|
|
68
|
+
"Use the form to prepare one save_record or edit_record proposal; it does "
|
|
69
|
+
"not read existing records."
|
|
70
|
+
),
|
|
71
|
+
"save_record": (
|
|
72
|
+
"Use for new lasting knowledge the user stated or asked to keep. Read its "
|
|
73
|
+
"form first; before creating a profile, look for the same entity and update "
|
|
74
|
+
"an existing profile instead. Proposes one record and saves only after "
|
|
75
|
+
"direct MCP confirmation of its complete contents. Returns the saved id "
|
|
76
|
+
"and contents, a duplicate notice, a skip result or requested corrections. "
|
|
77
|
+
"No batches or agent-supplied approval. Do not retry a declined confirmation "
|
|
78
|
+
"unless the user asks."
|
|
79
|
+
),
|
|
80
|
+
"edit_record": (
|
|
81
|
+
"Use to correct, extend, retire or recheck existing knowledge. When the "
|
|
82
|
+
"user corrects saved knowledge or a completed, user-approved change makes "
|
|
83
|
+
"it outdated, propose an update without waiting for a RatifyPoint request. "
|
|
84
|
+
"Clarify uncertain changes or code/rule mismatches first. Read the current "
|
|
85
|
+
"record. Proposes one operation for direct MCP confirmation "
|
|
86
|
+
"of the exact change. replace creates a new version; identical replacement "
|
|
87
|
+
"fields return Unchanged without writing. A supplied properties object "
|
|
88
|
+
"replaces the whole object: preserve unchanged properties. Report the "
|
|
89
|
+
"returned result and use the new id after replacement. No batches or "
|
|
90
|
+
"agent-supplied approval. Do not retry a declined confirmation unless "
|
|
91
|
+
"the user asks."
|
|
92
|
+
),
|
|
93
|
+
"init_project": (
|
|
94
|
+
"Use when the user wants to initialize RatifyPoint or change its knowledge "
|
|
95
|
+
"storage mode or record language. Call without arguments. RatifyPoint asks "
|
|
96
|
+
"both questions through MCP and writes settings after valid answers. "
|
|
97
|
+
"Returns the selected mode and language. This configures knowledge storage, "
|
|
98
|
+
"not the infrastructure described by profiles."
|
|
99
|
+
),
|
|
100
|
+
"clean_memory": (
|
|
101
|
+
"Use when the user requests knowledge cleanup. Returns the next portion "
|
|
102
|
+
"of records to review for doubts, duplicates, contradictions and open "
|
|
103
|
+
"questions; it does not change records. Follow the returned steps and "
|
|
104
|
+
"propose changes separately with edit_record or save_record. After reviewing "
|
|
105
|
+
"a portion and resolving any proposals, call again until Cleanup complete, "
|
|
106
|
+
"then report what was checked and changed."
|
|
107
|
+
),
|
|
108
|
+
}
|
ratifypoint/cli.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""The `ratifypoint` command. Each command imports only what it needs: a hook
|
|
2
|
+
must start fast and never loads the MCP SDK."""
|
|
3
|
+
|
|
4
|
+
import argparse
|
|
5
|
+
import sys
|
|
6
|
+
from datetime import date, timedelta
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
from .integrations import CLIENTS, InstallError, install, uninstall
|
|
10
|
+
|
|
11
|
+
# How far back `report` reads session logs by default.
|
|
12
|
+
REPORT_DAYS = 7
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main(argv: list[str] | None = None) -> int:
|
|
16
|
+
parser = argparse.ArgumentParser(prog="ratifypoint")
|
|
17
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
18
|
+
for name in ("install", "uninstall"):
|
|
19
|
+
commands.add_parser(name).add_argument("client", choices=CLIENTS)
|
|
20
|
+
commands.add_parser("status")
|
|
21
|
+
commands.add_parser("show").add_argument("paths", nargs="*")
|
|
22
|
+
week_ago = date.today() - timedelta(days=REPORT_DAYS)
|
|
23
|
+
commands.add_parser("report").add_argument(
|
|
24
|
+
"--since", type=date.fromisoformat, default=week_ago, metavar="YYYY-MM-DD"
|
|
25
|
+
)
|
|
26
|
+
mcp = commands.add_parser("mcp").add_subparsers(dest="action", required=True)
|
|
27
|
+
mcp.add_parser("serve")
|
|
28
|
+
hook = commands.add_parser("hook")
|
|
29
|
+
hook.add_argument("event", choices=("session-start",))
|
|
30
|
+
hook.add_argument("client", choices=CLIENTS)
|
|
31
|
+
arguments = parser.parse_args(argv)
|
|
32
|
+
home = Path.home()
|
|
33
|
+
start = Path.cwd()
|
|
34
|
+
if arguments.command == "hook":
|
|
35
|
+
from .hooks import session_start
|
|
36
|
+
|
|
37
|
+
# The client's JSON in, the hook's JSON out; silent on any problem.
|
|
38
|
+
output = session_start(sys.stdin.read(), arguments.client, home)
|
|
39
|
+
if output:
|
|
40
|
+
print(output)
|
|
41
|
+
return 0
|
|
42
|
+
if arguments.command == "mcp":
|
|
43
|
+
import anyio
|
|
44
|
+
|
|
45
|
+
from .adapter import serve
|
|
46
|
+
|
|
47
|
+
anyio.run(serve, start, home)
|
|
48
|
+
return 0
|
|
49
|
+
if arguments.command == "status":
|
|
50
|
+
from .status import status
|
|
51
|
+
|
|
52
|
+
text, code = status(start, home)
|
|
53
|
+
print(text, end="")
|
|
54
|
+
return code
|
|
55
|
+
if arguments.command == "show":
|
|
56
|
+
from .show import show
|
|
57
|
+
|
|
58
|
+
text, code = show(start, home, arguments.paths)
|
|
59
|
+
print(text, end="")
|
|
60
|
+
return code
|
|
61
|
+
if arguments.command == "report":
|
|
62
|
+
from .report import report
|
|
63
|
+
|
|
64
|
+
text, code = report(start, home, arguments.since.isoformat())
|
|
65
|
+
print(text, end="")
|
|
66
|
+
return code
|
|
67
|
+
run = install
|
|
68
|
+
if arguments.command == "uninstall":
|
|
69
|
+
run = uninstall
|
|
70
|
+
try:
|
|
71
|
+
print(run(arguments.client, home))
|
|
72
|
+
except InstallError as error:
|
|
73
|
+
print(error, file=sys.stderr)
|
|
74
|
+
return 1
|
|
75
|
+
return 0
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""Commands behind the MCP tools: a session over the project and its records."""
|
|
2
|
+
|
|
3
|
+
from .clean import Cleaner
|
|
4
|
+
from .edit import Editor
|
|
5
|
+
from .init import Initializer
|
|
6
|
+
from .save import Saver
|
|
7
|
+
from .session import Answer, Ask, CommandError, Session, Window
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"Answer",
|
|
11
|
+
"Ask",
|
|
12
|
+
"Cleaner",
|
|
13
|
+
"CommandError",
|
|
14
|
+
"Editor",
|
|
15
|
+
"Initializer",
|
|
16
|
+
"Saver",
|
|
17
|
+
"Session",
|
|
18
|
+
"Window",
|
|
19
|
+
]
|