record revivable SKILL.md git-ref provenance on skill_writing (guardrail item 7)

This commit is contained in:
Denton Social committed 2026-09-25 00:20:32 -05:00
1 parent f91f86742e
commit d866d94d04
6 files changed
+128 -2

No files matched your search

+40
View File
@@ -13,6 +13,7 @@ from __future__ import annotations
import ast
import json
import select
import subprocess
import sys
import time
import urllib.error
@@ -63,6 +64,45 @@ def read_skill_contract(path: str | None = None) -> str:
return contract.read_text()
def skill_contract_ref(path: str | None = None) -> dict:
"""Provenance pointer for the SKILL.md revision at authoring time.
Returns {"ref": str | None, "dirty": bool | None}. `ref` is the short git
commit sha the contract was read under — revivable with
`git show <ref>:SKILL.md` — and `dirty` records whether the working-tree
contract differed from that commit. Both are None when the contract is not
inside a git checkout (the pointer degrades to nothing rather than a
non-revivable hash). Any subprocess failure degrades the same way; only a
missing contract file raises, mirroring `read_skill_contract`.
"""
contract = Path(path) if path else DEFAULT_CONTRACT
if not contract.is_file():
raise CodegenError(f"skill contract not found: {contract}")
directory = str(contract.parent)
try:
rev = subprocess.run(
["git", "rev-parse", "--short", "HEAD"],
cwd=directory,
capture_output=True,
text=True,
timeout=10.0,
)
if rev.returncode != 0:
return {"ref": None, "dirty": None}
status = subprocess.run(
["git", "status", "--porcelain", "--", contract.name],
cwd=directory,
capture_output=True,
text=True,
timeout=10.0,
)
except (OSError, subprocess.SubprocessError):
return {"ref": None, "dirty": None}
ref = rev.stdout.strip() or None
dirty = bool(status.stdout.strip()) if status.returncode == 0 else None
return {"ref": ref, "dirty": dirty}
class CodegenClient:
"""Minimal OpenAI-compatible chat client for writing skill bodies.
+9 -1
View File
@@ -10,7 +10,12 @@ from __future__ import annotations
from dataclasses import dataclass, field
from typing import Callable
from .codegen import CodegenClient, CodegenError, generate_skill_body
from .codegen import (
CodegenClient,
CodegenError,
generate_skill_body,
skill_contract_ref,
)
from .decisions import DecisionRequest, Option, Request
from .engine import SemIfEngine
from .llm import LLMClient
@@ -420,6 +425,7 @@ class Scheduler:
self.tree.setdefault(category, []).append(
Skill(name=draft.name, category=category, description=draft.description)
)
contract = skill_contract_ref()
self.trace.append(
"skill_writing",
request.id,
@@ -427,6 +433,8 @@ class Scheduler:
skill=draft.name,
description=draft.description,
model=self.codegen.model if self.codegen else None,
contract_ref=contract["ref"],
contract_dirty=contract["dirty"],
)
if self.codegen is None:
+9
View File
@@ -123,6 +123,9 @@ function eventRow(evt) {
div.textContent = `preempted ${evt.preempted}`;
} else if (evt.kind === "skill_writing") {
div.textContent = `writing skill ${evt.skill} — ${evt.description} (${evt.model || "codegen"})`;
if (evt.contract_ref) {
div.title = `SKILL.md @ ${evt.contract_ref}${evt.contract_dirty ? "*" : ""}`;
}
} else if (evt.kind === "skill_created") {
div.textContent = `created ${evt.skill}${evt.written ? " (body written)" : " (stub)"}`;
div.title = evt.body || evt.description || "";
@@ -349,6 +352,12 @@ function eventNode(evt) {
desc.className = "muted";
desc.textContent = evt.description || "";
body.appendChild(desc);
if (evt.contract_ref) {
const ref = document.createElement("div");
ref.className = "muted";
ref.textContent = `SKILL.md @ ${evt.contract_ref}${evt.contract_dirty ? "*" : ""}`;
body.appendChild(ref);
}
const badge = document.createElement("span");
badge.className = "writing-badge";
badge.textContent = "writing skill body…";