stintlock 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.
- stintlock/__init__.py +5 -0
- stintlock/cli.py +569 -0
- stintlock/config.py +156 -0
- stintlock/context/__init__.py +1 -0
- stintlock/context/budget.py +107 -0
- stintlock/context/builder.py +232 -0
- stintlock/context/redaction.py +107 -0
- stintlock/core/__init__.py +1 -0
- stintlock/core/checkpoint.py +146 -0
- stintlock/core/demo.py +141 -0
- stintlock/core/drift.py +277 -0
- stintlock/core/integrity.py +136 -0
- stintlock/core/verification.py +163 -0
- stintlock/git/__init__.py +1 -0
- stintlock/git/fingerprint.py +154 -0
- stintlock/git/inspector.py +200 -0
- stintlock/git/parser.py +164 -0
- stintlock/integrations/__init__.py +1 -0
- stintlock/integrations/agents/__init__.py +1 -0
- stintlock/integrations/agents/templates.py +89 -0
- stintlock/integrations/github.py +77 -0
- stintlock/mcp_server.py +237 -0
- stintlock/models.py +298 -0
- stintlock/reporters/__init__.py +1 -0
- stintlock/reporters/json.py +20 -0
- stintlock/reporters/markdown.py +56 -0
- stintlock/reporters/terminal.py +116 -0
- stintlock/storage/__init__.py +1 -0
- stintlock/storage/database.py +151 -0
- stintlock/storage/repository.py +266 -0
- stintlock-0.1.0.dist-info/METADATA +250 -0
- stintlock-0.1.0.dist-info/RECORD +35 -0
- stintlock-0.1.0.dist-info/WHEEL +4 -0
- stintlock-0.1.0.dist-info/entry_points.txt +2 -0
- stintlock-0.1.0.dist-info/licenses/LICENSE +21 -0
stintlock/__init__.py
ADDED
stintlock/cli.py
ADDED
|
@@ -0,0 +1,569 @@
|
|
|
1
|
+
"""Typer CLI entry point for StintLock."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from enum import StrEnum
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Annotated
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
from rich.console import Console
|
|
11
|
+
from rich.panel import Panel
|
|
12
|
+
|
|
13
|
+
from stintlock import __version__
|
|
14
|
+
from stintlock.config import load_config, resolve_database_path
|
|
15
|
+
from stintlock.context.builder import build_handoff_context
|
|
16
|
+
from stintlock.core.checkpoint import capture_checkpoint, init_repository_storage
|
|
17
|
+
from stintlock.core.demo import run_offline_demo
|
|
18
|
+
from stintlock.core.drift import diff_checkpoints, verify_checkpoint_against_workspace
|
|
19
|
+
from stintlock.git.inspector import GitInspectionError, inspect_repository, resolve_repo_root
|
|
20
|
+
from stintlock.integrations.agents.templates import render_agent_handoff
|
|
21
|
+
from stintlock.integrations.github import fetch_github_metadata
|
|
22
|
+
from stintlock.reporters.json import render_model_json, render_payload_json
|
|
23
|
+
from stintlock.reporters.markdown import render_handoff_markdown
|
|
24
|
+
from stintlock.reporters.terminal import (
|
|
25
|
+
render_checkpoint_show_terminal,
|
|
26
|
+
render_checkpoints_table,
|
|
27
|
+
render_diff_terminal,
|
|
28
|
+
render_git_status_terminal,
|
|
29
|
+
render_resume_terminal,
|
|
30
|
+
render_verification_report_terminal,
|
|
31
|
+
)
|
|
32
|
+
from stintlock.storage.database import (
|
|
33
|
+
CheckpointNotFoundError,
|
|
34
|
+
StorageCorruptionError,
|
|
35
|
+
StorageError,
|
|
36
|
+
)
|
|
37
|
+
from stintlock.storage.repository import CheckpointStore
|
|
38
|
+
|
|
39
|
+
app = typer.Typer(
|
|
40
|
+
name="stintlock",
|
|
41
|
+
help="Local-first, Git-aware checkpoint and handoff system for AI coding agents.",
|
|
42
|
+
no_args_is_help=True,
|
|
43
|
+
)
|
|
44
|
+
console = Console()
|
|
45
|
+
err_console = Console(stderr=True)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class ExportFormat(StrEnum):
|
|
49
|
+
"""Supported export formats."""
|
|
50
|
+
|
|
51
|
+
MARKDOWN = "markdown"
|
|
52
|
+
JSON = "json"
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class ResumeFormat(StrEnum):
|
|
56
|
+
"""Supported resume output formats."""
|
|
57
|
+
|
|
58
|
+
TERMINAL = "terminal"
|
|
59
|
+
MARKDOWN = "markdown"
|
|
60
|
+
JSON = "json"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _resolve_store(workspace: Path, db: Path | None) -> tuple[Path | None, CheckpointStore]:
|
|
64
|
+
repo_root: Path | None = None
|
|
65
|
+
try:
|
|
66
|
+
repo_root = resolve_repo_root(workspace)
|
|
67
|
+
except GitInspectionError:
|
|
68
|
+
repo_root = None
|
|
69
|
+
cfg = load_config(repo_root)
|
|
70
|
+
db_path = resolve_database_path(repo_root, cfg, db_override=db)
|
|
71
|
+
return repo_root, CheckpointStore(db_path)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _version_callback(value: bool) -> None:
|
|
75
|
+
if value:
|
|
76
|
+
typer.echo(f"stintlock {__version__}")
|
|
77
|
+
raise typer.Exit(0)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@app.callback()
|
|
81
|
+
def root_callback(
|
|
82
|
+
version: Annotated[
|
|
83
|
+
bool,
|
|
84
|
+
typer.Option(
|
|
85
|
+
"--version",
|
|
86
|
+
"-V",
|
|
87
|
+
callback=_version_callback,
|
|
88
|
+
is_eager=True,
|
|
89
|
+
help="Show version and exit.",
|
|
90
|
+
),
|
|
91
|
+
] = False,
|
|
92
|
+
) -> None:
|
|
93
|
+
"""StintLock CLI."""
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
@app.command()
|
|
97
|
+
def init(
|
|
98
|
+
workspace: Annotated[Path, typer.Option("--workspace", "-C", help="Repository path.")] = Path(
|
|
99
|
+
"."
|
|
100
|
+
),
|
|
101
|
+
storage_mode: Annotated[
|
|
102
|
+
str,
|
|
103
|
+
typer.Option("--storage-mode", help="Storage mode: 'user_data' or 'local_dir'."),
|
|
104
|
+
] = "user_data",
|
|
105
|
+
db: Annotated[Path | None, typer.Option("--db", help="Explicit SQLite database path.")] = None,
|
|
106
|
+
json_output: Annotated[bool, typer.Option("--json", help="Emit JSON output.")] = False,
|
|
107
|
+
) -> None:
|
|
108
|
+
"""Initialize checkpoint configuration and storage for a Git repository."""
|
|
109
|
+
try:
|
|
110
|
+
res = init_repository_storage(workspace, storage_mode=storage_mode, db_override=db)
|
|
111
|
+
except (GitInspectionError, StorageError, ValueError) as exc:
|
|
112
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
113
|
+
raise typer.Exit(1) from exc
|
|
114
|
+
|
|
115
|
+
if json_output:
|
|
116
|
+
typer.echo(
|
|
117
|
+
render_payload_json(
|
|
118
|
+
{
|
|
119
|
+
"repo_root": res.repo_root.as_posix(),
|
|
120
|
+
"config_path": res.config_path.as_posix(),
|
|
121
|
+
"db_path": res.db_path.as_posix(),
|
|
122
|
+
"created_config": res.created_config,
|
|
123
|
+
}
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
return
|
|
127
|
+
|
|
128
|
+
console.print(
|
|
129
|
+
Panel(
|
|
130
|
+
f"[bold]Repo Root:[/bold] {res.repo_root}\n"
|
|
131
|
+
f"[bold]Config:[/bold] {res.config_path}\n"
|
|
132
|
+
f"[bold]Database:[/bold] {res.db_path}",
|
|
133
|
+
title="StintLock Initialized",
|
|
134
|
+
border_style="green",
|
|
135
|
+
)
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
@app.command()
|
|
140
|
+
def save(
|
|
141
|
+
task: Annotated[
|
|
142
|
+
str, typer.Option("--task", "--objective", "-t", help="Development objective.")
|
|
143
|
+
],
|
|
144
|
+
agent: Annotated[str, typer.Option("--agent", "-a", help="Source coding agent ID.")] = "manual",
|
|
145
|
+
criteria: Annotated[
|
|
146
|
+
list[str] | None, typer.Option("--criteria", help="Acceptance criterion.")
|
|
147
|
+
] = None,
|
|
148
|
+
done: Annotated[
|
|
149
|
+
list[str] | None, typer.Option("--done", help="Agent-reported completed task.")
|
|
150
|
+
] = None,
|
|
151
|
+
pending: Annotated[list[str] | None, typer.Option("--pending", help="Pending task.")] = None,
|
|
152
|
+
decision: Annotated[
|
|
153
|
+
list[str] | None, typer.Option("--decision", help="Architectural decision.")
|
|
154
|
+
] = None,
|
|
155
|
+
rejected: Annotated[
|
|
156
|
+
list[str] | None, typer.Option("--rejected", help="Rejected approach.")
|
|
157
|
+
] = None,
|
|
158
|
+
blocker: Annotated[list[str] | None, typer.Option("--blocker", help="Known blocker.")] = None,
|
|
159
|
+
next_action: Annotated[
|
|
160
|
+
str | None, typer.Option("--next-action", help="Suggested next action.")
|
|
161
|
+
] = None,
|
|
162
|
+
issue: Annotated[str | None, typer.Option("--issue", help="GitHub issue reference.")] = None,
|
|
163
|
+
pr: Annotated[str | None, typer.Option("--pr", help="GitHub PR reference.")] = None,
|
|
164
|
+
fetch_github: Annotated[
|
|
165
|
+
bool,
|
|
166
|
+
typer.Option(
|
|
167
|
+
"--fetch-github",
|
|
168
|
+
help="Optionally fetch read-only issue/PR metadata via local `gh` CLI.",
|
|
169
|
+
),
|
|
170
|
+
] = False,
|
|
171
|
+
verify: Annotated[
|
|
172
|
+
bool, typer.Option("--verify/--no-verify", help="Run approved local verification commands.")
|
|
173
|
+
] = False,
|
|
174
|
+
verify_cmd: Annotated[
|
|
175
|
+
list[str] | None, typer.Option("--verify-cmd", help="Filter verification command names.")
|
|
176
|
+
] = None,
|
|
177
|
+
workspace: Annotated[Path, typer.Option("--workspace", "-C", help="Repository path.")] = Path(
|
|
178
|
+
"."
|
|
179
|
+
),
|
|
180
|
+
config: Annotated[Path | None, typer.Option("--config", help="Explicit config path.")] = None,
|
|
181
|
+
db: Annotated[Path | None, typer.Option("--db", help="Explicit SQLite database path.")] = None,
|
|
182
|
+
json_output: Annotated[bool, typer.Option("--json", help="Emit JSON output.")] = False,
|
|
183
|
+
) -> None:
|
|
184
|
+
"""Capture an immutable checkpoint of observed Git state and agent context."""
|
|
185
|
+
notes_lines: list[str] = []
|
|
186
|
+
if fetch_github:
|
|
187
|
+
if issue:
|
|
188
|
+
issue_meta = fetch_github_metadata(workspace, kind="issue", ref=issue)
|
|
189
|
+
if issue_meta is not None:
|
|
190
|
+
notes_lines.append(
|
|
191
|
+
f"GitHub Issue #{issue_meta.number} [{issue_meta.state}]: {issue_meta.title}"
|
|
192
|
+
)
|
|
193
|
+
if pr:
|
|
194
|
+
pr_meta = fetch_github_metadata(workspace, kind="pr", ref=pr)
|
|
195
|
+
if pr_meta is not None:
|
|
196
|
+
notes_lines.append(
|
|
197
|
+
f"GitHub PR #{pr_meta.number} [{pr_meta.state}]: {pr_meta.title}"
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
try:
|
|
201
|
+
ckpt = capture_checkpoint(
|
|
202
|
+
workspace,
|
|
203
|
+
objective=task,
|
|
204
|
+
source_agent=agent,
|
|
205
|
+
acceptance_criteria=criteria,
|
|
206
|
+
completed_tasks=done,
|
|
207
|
+
pending_tasks=pending,
|
|
208
|
+
architectural_decisions=decision,
|
|
209
|
+
rejected_approaches=rejected,
|
|
210
|
+
known_blockers=blocker,
|
|
211
|
+
suggested_next_action=next_action,
|
|
212
|
+
notes="\n".join(notes_lines),
|
|
213
|
+
github_issue=issue,
|
|
214
|
+
github_pr=pr,
|
|
215
|
+
verify=verify,
|
|
216
|
+
verify_commands=verify_cmd,
|
|
217
|
+
config_path=config,
|
|
218
|
+
db_override=db,
|
|
219
|
+
)
|
|
220
|
+
except (GitInspectionError, StorageError, ValueError) as exc:
|
|
221
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
222
|
+
raise typer.Exit(1) from exc
|
|
223
|
+
|
|
224
|
+
if json_output:
|
|
225
|
+
typer.echo(render_model_json(ckpt))
|
|
226
|
+
return
|
|
227
|
+
|
|
228
|
+
render_checkpoint_show_terminal(console, ckpt)
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
@app.command()
|
|
232
|
+
def status(
|
|
233
|
+
workspace: Annotated[Path, typer.Option("--workspace", "-C", help="Repository path.")] = Path(
|
|
234
|
+
"."
|
|
235
|
+
),
|
|
236
|
+
json_output: Annotated[bool, typer.Option("--json", help="Emit JSON output.")] = False,
|
|
237
|
+
) -> None:
|
|
238
|
+
"""Inspect live observed Git state without modifying the repository."""
|
|
239
|
+
try:
|
|
240
|
+
snap = inspect_repository(workspace)
|
|
241
|
+
except GitInspectionError as exc:
|
|
242
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
243
|
+
raise typer.Exit(1) from exc
|
|
244
|
+
|
|
245
|
+
if json_output:
|
|
246
|
+
typer.echo(render_model_json(snap))
|
|
247
|
+
return
|
|
248
|
+
|
|
249
|
+
render_git_status_terminal(console, snap)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
@app.command(name="list")
|
|
253
|
+
def list_cmd(
|
|
254
|
+
workspace: Annotated[Path, typer.Option("--workspace", "-C", help="Repository path.")] = Path(
|
|
255
|
+
"."
|
|
256
|
+
),
|
|
257
|
+
all_repos: Annotated[
|
|
258
|
+
bool, typer.Option("--all", help="List checkpoints across all repositories.")
|
|
259
|
+
] = False,
|
|
260
|
+
branch: Annotated[str | None, typer.Option("--branch", help="Filter by branch name.")] = None,
|
|
261
|
+
agent: Annotated[str | None, typer.Option("--agent", help="Filter by source agent.")] = None,
|
|
262
|
+
query: Annotated[str | None, typer.Option("--query", "-q", help="Search objective/ID.")] = None,
|
|
263
|
+
limit: Annotated[int, typer.Option("--limit", "-n", help="Max results.")] = 20,
|
|
264
|
+
db: Annotated[Path | None, typer.Option("--db", help="Explicit SQLite database path.")] = None,
|
|
265
|
+
json_output: Annotated[bool, typer.Option("--json", help="Emit JSON output.")] = False,
|
|
266
|
+
) -> None:
|
|
267
|
+
"""List saved checkpoints."""
|
|
268
|
+
try:
|
|
269
|
+
repo_root, store = _resolve_store(workspace, db)
|
|
270
|
+
repo_id: str | None = None
|
|
271
|
+
if not all_repos and repo_root is not None:
|
|
272
|
+
repo_id = inspect_repository(repo_root).repository.repo_id
|
|
273
|
+
rows = store.list_checkpoints(
|
|
274
|
+
repo_id=repo_id,
|
|
275
|
+
branch=branch,
|
|
276
|
+
agent=agent,
|
|
277
|
+
query=query,
|
|
278
|
+
limit=limit,
|
|
279
|
+
)
|
|
280
|
+
except (GitInspectionError, StorageError) as exc:
|
|
281
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
282
|
+
raise typer.Exit(1) from exc
|
|
283
|
+
|
|
284
|
+
if json_output:
|
|
285
|
+
typer.echo(render_payload_json([row.model_dump(mode="json") for row in rows]))
|
|
286
|
+
return
|
|
287
|
+
|
|
288
|
+
render_checkpoints_table(console, rows)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
@app.command()
|
|
292
|
+
def show(
|
|
293
|
+
checkpoint_id: Annotated[str, typer.Argument(help="Checkpoint ID to inspect.")],
|
|
294
|
+
workspace: Annotated[Path, typer.Option("--workspace", "-C", help="Repository path.")] = Path(
|
|
295
|
+
"."
|
|
296
|
+
),
|
|
297
|
+
db: Annotated[Path | None, typer.Option("--db", help="Explicit SQLite database path.")] = None,
|
|
298
|
+
json_output: Annotated[bool, typer.Option("--json", help="Emit JSON output.")] = False,
|
|
299
|
+
) -> None:
|
|
300
|
+
"""Display details of a stored checkpoint without modifying the workspace."""
|
|
301
|
+
try:
|
|
302
|
+
_, store = _resolve_store(workspace, db)
|
|
303
|
+
ckpt = store.get(checkpoint_id)
|
|
304
|
+
except CheckpointNotFoundError as exc:
|
|
305
|
+
err_console.print(f"[red]Not found:[/red] {exc}")
|
|
306
|
+
raise typer.Exit(3) from exc
|
|
307
|
+
except StorageError as exc:
|
|
308
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
309
|
+
raise typer.Exit(1) from exc
|
|
310
|
+
|
|
311
|
+
if json_output:
|
|
312
|
+
typer.echo(render_model_json(ckpt))
|
|
313
|
+
return
|
|
314
|
+
|
|
315
|
+
render_checkpoint_show_terminal(console, ckpt)
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
@app.command()
|
|
319
|
+
def verify(
|
|
320
|
+
checkpoint_id: Annotated[str, typer.Argument(help="Checkpoint ID to verify.")],
|
|
321
|
+
workspace: Annotated[Path, typer.Option("--workspace", "-C", help="Repository path.")] = Path(
|
|
322
|
+
"."
|
|
323
|
+
),
|
|
324
|
+
db: Annotated[Path | None, typer.Option("--db", help="Explicit SQLite database path.")] = None,
|
|
325
|
+
json_output: Annotated[bool, typer.Option("--json", help="Emit JSON output.")] = False,
|
|
326
|
+
) -> None:
|
|
327
|
+
"""Verify checkpoint integrity, schema, and live repository drift (read-only)."""
|
|
328
|
+
try:
|
|
329
|
+
_, store = _resolve_store(workspace, db)
|
|
330
|
+
integrity = store.get_with_integrity(checkpoint_id)
|
|
331
|
+
except CheckpointNotFoundError as exc:
|
|
332
|
+
err_console.print(f"[red]Not found:[/red] {exc}")
|
|
333
|
+
raise typer.Exit(3) from exc
|
|
334
|
+
except StorageCorruptionError as exc:
|
|
335
|
+
err_console.print(f"[red]Corrupted:[/red] {exc}")
|
|
336
|
+
raise typer.Exit(2) from exc
|
|
337
|
+
except StorageError as exc:
|
|
338
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
339
|
+
raise typer.Exit(1) from exc
|
|
340
|
+
|
|
341
|
+
if integrity.checkpoint is None:
|
|
342
|
+
if json_output:
|
|
343
|
+
typer.echo(
|
|
344
|
+
render_payload_json(
|
|
345
|
+
{
|
|
346
|
+
"checkpoint_id": checkpoint_id,
|
|
347
|
+
"integrity_valid": False,
|
|
348
|
+
"schema_supported": integrity.schema_supported,
|
|
349
|
+
"findings": [f.model_dump(mode="json") for f in integrity.findings],
|
|
350
|
+
}
|
|
351
|
+
)
|
|
352
|
+
)
|
|
353
|
+
else:
|
|
354
|
+
for finding in integrity.findings:
|
|
355
|
+
err_console.print(f"[red]{finding.status.value}:[/red] {finding.message}")
|
|
356
|
+
raise typer.Exit(2)
|
|
357
|
+
|
|
358
|
+
report = verify_checkpoint_against_workspace(integrity.checkpoint, workspace)
|
|
359
|
+
if json_output:
|
|
360
|
+
typer.echo(render_model_json(report))
|
|
361
|
+
else:
|
|
362
|
+
render_verification_report_terminal(console, report)
|
|
363
|
+
|
|
364
|
+
if not report.is_clean_match:
|
|
365
|
+
raise typer.Exit(2)
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
@app.command()
|
|
369
|
+
def diff(
|
|
370
|
+
checkpoint_a: Annotated[str, typer.Argument(help="Baseline checkpoint ID.")],
|
|
371
|
+
checkpoint_b: Annotated[str, typer.Argument(help="Target checkpoint ID.")],
|
|
372
|
+
workspace: Annotated[Path, typer.Option("--workspace", "-C", help="Repository path.")] = Path(
|
|
373
|
+
"."
|
|
374
|
+
),
|
|
375
|
+
db: Annotated[Path | None, typer.Option("--db", help="Explicit SQLite database path.")] = None,
|
|
376
|
+
json_output: Annotated[bool, typer.Option("--json", help="Emit JSON output.")] = False,
|
|
377
|
+
) -> None:
|
|
378
|
+
"""Compare two checkpoints without modifying the workspace."""
|
|
379
|
+
try:
|
|
380
|
+
_, store = _resolve_store(workspace, db)
|
|
381
|
+
ckpt_a = store.get(checkpoint_a)
|
|
382
|
+
ckpt_b = store.get(checkpoint_b)
|
|
383
|
+
except CheckpointNotFoundError as exc:
|
|
384
|
+
err_console.print(f"[red]Not found:[/red] {exc}")
|
|
385
|
+
raise typer.Exit(3) from exc
|
|
386
|
+
except StorageError as exc:
|
|
387
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
388
|
+
raise typer.Exit(1) from exc
|
|
389
|
+
|
|
390
|
+
diff_res = diff_checkpoints(ckpt_a, ckpt_b)
|
|
391
|
+
if json_output:
|
|
392
|
+
typer.echo(render_model_json(diff_res))
|
|
393
|
+
return
|
|
394
|
+
|
|
395
|
+
render_diff_terminal(console, diff_res)
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
@app.command()
|
|
399
|
+
def resume(
|
|
400
|
+
checkpoint_id: Annotated[
|
|
401
|
+
str | None, typer.Argument(help="Checkpoint ID (defaults to latest for repo).")
|
|
402
|
+
] = None,
|
|
403
|
+
workspace: Annotated[Path, typer.Option("--workspace", "-C", help="Repository path.")] = Path(
|
|
404
|
+
"."
|
|
405
|
+
),
|
|
406
|
+
output_format: Annotated[
|
|
407
|
+
ResumeFormat, typer.Option("--format", "-f", help="Output format.")
|
|
408
|
+
] = ResumeFormat.MARKDOWN,
|
|
409
|
+
max_chars: Annotated[
|
|
410
|
+
int | None, typer.Option("--max-chars", help="Maximum context character budget.")
|
|
411
|
+
] = None,
|
|
412
|
+
template: Annotated[
|
|
413
|
+
str | None,
|
|
414
|
+
typer.Option(
|
|
415
|
+
"--template",
|
|
416
|
+
help=(
|
|
417
|
+
"Agent handoff template "
|
|
418
|
+
"(antigravity, claude-code, codex, gemini-cli, cursor, opencode)."
|
|
419
|
+
),
|
|
420
|
+
),
|
|
421
|
+
] = None,
|
|
422
|
+
db: Annotated[Path | None, typer.Option("--db", help="Explicit SQLite database path.")] = None,
|
|
423
|
+
json_output: Annotated[bool, typer.Option("--json", help="Emit JSON output.")] = False,
|
|
424
|
+
) -> None:
|
|
425
|
+
"""Generate verified handoff context for resuming work without altering the repository."""
|
|
426
|
+
try:
|
|
427
|
+
repo_root, store = _resolve_store(workspace, db)
|
|
428
|
+
if checkpoint_id is not None:
|
|
429
|
+
ckpt = store.get(checkpoint_id)
|
|
430
|
+
else:
|
|
431
|
+
repo_id = inspect_repository(repo_root).repository.repo_id if repo_root else None
|
|
432
|
+
latest_ckpt = store.latest(repo_id=repo_id)
|
|
433
|
+
if latest_ckpt is None:
|
|
434
|
+
raise CheckpointNotFoundError("No checkpoints found for this repository.")
|
|
435
|
+
ckpt = latest_ckpt
|
|
436
|
+
except CheckpointNotFoundError as exc:
|
|
437
|
+
err_console.print(f"[red]Not found:[/red] {exc}")
|
|
438
|
+
raise typer.Exit(3) from exc
|
|
439
|
+
except (GitInspectionError, StorageError) as exc:
|
|
440
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
441
|
+
raise typer.Exit(1) from exc
|
|
442
|
+
|
|
443
|
+
cfg = load_config(repo_root)
|
|
444
|
+
budget = max_chars if max_chars is not None else cfg.context.default_max_chars
|
|
445
|
+
report = verify_checkpoint_against_workspace(ckpt, workspace)
|
|
446
|
+
ctx = build_handoff_context(ckpt, verification_report=report, max_chars=budget)
|
|
447
|
+
|
|
448
|
+
if json_output or output_format == ResumeFormat.JSON:
|
|
449
|
+
typer.echo(render_model_json(ctx))
|
|
450
|
+
elif output_format == ResumeFormat.TERMINAL:
|
|
451
|
+
render_resume_terminal(console, ctx)
|
|
452
|
+
elif template is not None:
|
|
453
|
+
try:
|
|
454
|
+
typer.echo(render_agent_handoff(ctx, template))
|
|
455
|
+
except ValueError as exc:
|
|
456
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
457
|
+
raise typer.Exit(1) from exc
|
|
458
|
+
else:
|
|
459
|
+
typer.echo(render_handoff_markdown(ctx))
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
@app.command()
|
|
463
|
+
def export(
|
|
464
|
+
checkpoint_id: Annotated[str, typer.Argument(help="Checkpoint ID to export.")],
|
|
465
|
+
output_format: Annotated[
|
|
466
|
+
ExportFormat, typer.Option("--format", "-f", help="Export format: markdown or json.")
|
|
467
|
+
] = ExportFormat.MARKDOWN,
|
|
468
|
+
output_file: Annotated[
|
|
469
|
+
Path | None, typer.Option("--output", "-o", help="Optional output file path.")
|
|
470
|
+
] = None,
|
|
471
|
+
max_chars: Annotated[
|
|
472
|
+
int | None, typer.Option("--max-chars", help="Max characters for markdown export.")
|
|
473
|
+
] = None,
|
|
474
|
+
template: Annotated[
|
|
475
|
+
str | None,
|
|
476
|
+
typer.Option("--template", help="Optional agent-specific handoff template."),
|
|
477
|
+
] = None,
|
|
478
|
+
workspace: Annotated[Path, typer.Option("--workspace", "-C", help="Repository path.")] = Path(
|
|
479
|
+
"."
|
|
480
|
+
),
|
|
481
|
+
db: Annotated[Path | None, typer.Option("--db", help="Explicit SQLite database path.")] = None,
|
|
482
|
+
) -> None:
|
|
483
|
+
"""Export a checkpoint to portable Markdown or JSON."""
|
|
484
|
+
try:
|
|
485
|
+
repo_root, store = _resolve_store(workspace, db)
|
|
486
|
+
ckpt = store.get(checkpoint_id)
|
|
487
|
+
except CheckpointNotFoundError as exc:
|
|
488
|
+
err_console.print(f"[red]Not found:[/red] {exc}")
|
|
489
|
+
raise typer.Exit(3) from exc
|
|
490
|
+
except StorageError as exc:
|
|
491
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
492
|
+
raise typer.Exit(1) from exc
|
|
493
|
+
|
|
494
|
+
if output_format == ExportFormat.JSON:
|
|
495
|
+
rendered = render_model_json(ckpt)
|
|
496
|
+
else:
|
|
497
|
+
cfg = load_config(repo_root)
|
|
498
|
+
budget = max_chars if max_chars is not None else cfg.context.default_max_chars
|
|
499
|
+
ctx = build_handoff_context(ckpt, max_chars=budget)
|
|
500
|
+
if template is not None:
|
|
501
|
+
try:
|
|
502
|
+
rendered = render_agent_handoff(ctx, template)
|
|
503
|
+
except ValueError as exc:
|
|
504
|
+
err_console.print(f"[red]Error:[/red] {exc}")
|
|
505
|
+
raise typer.Exit(1) from exc
|
|
506
|
+
else:
|
|
507
|
+
rendered = render_handoff_markdown(ctx)
|
|
508
|
+
|
|
509
|
+
if output_file is not None:
|
|
510
|
+
output_file.parent.mkdir(parents=True, exist_ok=True)
|
|
511
|
+
output_file.write_text(rendered, encoding="utf-8")
|
|
512
|
+
console.print(f"Exported checkpoint to {output_file}")
|
|
513
|
+
else:
|
|
514
|
+
typer.echo(rendered)
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
@app.command()
|
|
518
|
+
def mcp(
|
|
519
|
+
workspace: Annotated[
|
|
520
|
+
Path, typer.Option("--workspace", "-C", help="Authorized repository root.")
|
|
521
|
+
] = Path("."),
|
|
522
|
+
allow_write: Annotated[
|
|
523
|
+
bool,
|
|
524
|
+
typer.Option("--allow-write", help="Enable explicit checkpoint_save MCP tool."),
|
|
525
|
+
] = False,
|
|
526
|
+
db: Annotated[Path | None, typer.Option("--db", help="Explicit SQLite database path.")] = None,
|
|
527
|
+
) -> None:
|
|
528
|
+
"""Run the local stdio MCP server (read-only by default)."""
|
|
529
|
+
from stintlock.mcp_server import run_stdio_server
|
|
530
|
+
|
|
531
|
+
run_stdio_server(workspace=workspace, allow_write=allow_write, db_override=db)
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
@app.command()
|
|
535
|
+
def demo(
|
|
536
|
+
json_output: Annotated[bool, typer.Option("--json", help="Emit JSON metrics.")] = False,
|
|
537
|
+
) -> None:
|
|
538
|
+
"""Run an offline reproducible cross-agent handoff and drift demonstration."""
|
|
539
|
+
metrics = run_offline_demo()
|
|
540
|
+
if json_output:
|
|
541
|
+
typer.echo(render_model_json(metrics))
|
|
542
|
+
return
|
|
543
|
+
|
|
544
|
+
console.print(
|
|
545
|
+
Panel(
|
|
546
|
+
f"[bold]Checkpoint ID:[/bold] {metrics.checkpoint_id}\n"
|
|
547
|
+
f"[bold]Create Latency:[/bold] {metrics.checkpoint_creation_ms} ms\n"
|
|
548
|
+
f"[bold]Clean Verify:[/bold] {', '.join(metrics.clean_match_statuses)} "
|
|
549
|
+
f"({metrics.clean_verify_ms} ms)\n"
|
|
550
|
+
f"[bold]After Edit Drift:[/bold] {', '.join(metrics.drift_statuses)} "
|
|
551
|
+
f"({metrics.drift_verify_ms} ms)\n"
|
|
552
|
+
f"[bold]Stale Evidence Detected:[/bold] {', '.join(metrics.stale_evidence_ids)}\n"
|
|
553
|
+
f"[bold]Storage Size:[/bold] {metrics.storage_size_bytes} bytes\n"
|
|
554
|
+
f"[bold]Context Export Size:[/bold] {metrics.context_export_bytes} bytes\n"
|
|
555
|
+
f"[bold]Secret Redaction Verified:[/bold] {metrics.redaction_verified}\n"
|
|
556
|
+
f"[bold]Drift Warning Raised on Resume:[/bold] {metrics.drift_warning_present}",
|
|
557
|
+
title="StintLock Offline Demo",
|
|
558
|
+
border_style="green",
|
|
559
|
+
)
|
|
560
|
+
)
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
def main() -> None:
|
|
564
|
+
"""CLI entry point."""
|
|
565
|
+
app()
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
if __name__ == "__main__":
|
|
569
|
+
main()
|