requirements.integration.symposium_skill_hook.setup_state
Requirements index · View definition
Requirement
When the setup advisory of
also applies, the hook MUST provide the sentence of
and the advisory together in one agent context, with the sentence first.
Rationale
I found no gaps.
The subject has one obligation: when the setup advisory also applies, the hook MUST give the skill sentence and the advisory together in one agent context, with the sentence first.
Implementation. src/hook.rs#fn[session_start] carries the {impl} reference and calls session_start_response. That function starts a single context string from SKILL_SENTENCE. If setup::is_configured(&root) is false, it appends a space and then the “Habeas Codicem is not fully configured … Run habeas setup” advisory to that same string. It returns one {"SessionStart": {"additionalContext": context}} value. So the sentence and the advisory share one context, and the sentence comes first. When setup is complete, only the sentence is returned.
Unspecified behavior. The advisory wording, which includes the project path, falls within the cited symposium_setup_hook requirement. I found no extra output beyond what the text covers.
Tests. tests/setup.rs#fn[session_start_puts_the_skill_sentence_before_the_setup_advisory] carries {test} references to the subject. It builds a project that lists habeas under [dev-dependencies] and has no md/habeas.css. It runs the real binary and asserts these points:
- The response has a single
additionalContext. - The context starts with
SKILL_SENTENCE. - The text after the sentence starts with “Habeas Codicem is not fully configured” and mentions
habeas setup. - The
habeasskill is mentioned exactly once.
tests/symposium_hook_smoke.py#def[main] also asserts through Symposium that the incomplete-setup context starts with the sentence and contains the advisory.
Inputs
Implementation
Input 5: outline src/hook.rs fn[session_start]
- File:
src/hook.rs - Selector:
fn[session_start] - Kind:
fn src/hook.rs:12–20
// {impl}`requirements.integration.symposium_skill_hook`
// {impl}`requirements.integration.symposium_skill_hook.setup_state`
// {impl}`requirements.integration.symposium_skill_hook.not_applicable`
pub(crate) fn session_start() -> Result<(), Box<dyn Error>> {
let input: Value = serde_json::from_reader(io::stdin()).unwrap_or(Value::Null);
let response = session_start_response(&input, &std::env::current_dir()?);
serde_json::to_writer(io::stdout().lock(), &response)?;
Ok(())
}
Tests
Input 4: requirements selection requirements.integration.symposium_skill_hook.incomplete_setup
requirements.integration.symposium_skill_hook.incomplete_setup:md/requirements/integration.md:72–74
:::{example} symposium_skill_hook.incomplete_setup
In a project that lists `habeas` under `[dev-dependencies]` but has no `habeas.css` in its book source directory, the agent context starts with the skill sentence, followed by the advisory saying Habeas Codicem is not fully configured and suggesting `habeas setup`. {test}`requirements.integration.symposium_skill_hook.setup_state`
:::
Input 6: outline tests/setup.rs fn[session_start_puts_the_skill_sentence_before_the_setup_advisory]
- File:
tests/setup.rs - Selector:
fn[session_start_puts_the_skill_sentence_before_the_setup_advisory] - Kind:
fn tests/setup.rs:641–674
// {test}`requirements.integration.symposium_skill_hook`
// {test}`requirements.integration.symposium_skill_hook.setup_state`
// {test}`requirements.integration.symposium_skill_hook.incomplete_setup`
#[test]
fn session_start_puts_the_skill_sentence_before_the_setup_advisory() {
let temp = fixture();
let project = temp.path();
let manifest = fs::read_to_string(project.join("Cargo.toml")).unwrap();
fs::write(
project.join("Cargo.toml"),
format!("{manifest}\n[dev-dependencies]\nhabeas = \"0.2\"\n"),
)
.unwrap();
assert!(!project.join("md/habeas.css").exists());
let response = session_start(project, project);
let event = response["SessionStart"].as_object().unwrap();
assert_eq!(event.len(), 1, "one agent context: {response}");
let context = event["additionalContext"].as_str().unwrap();
let advisory = context
.strip_prefix(SKILL_SENTENCE)
.unwrap_or_else(|| panic!("the skill sentence must come first: {context:?}"));
let advisory = advisory.trim_start();
assert!(
advisory.starts_with("Habeas Codicem is not fully configured"),
"{advisory:?}"
);
assert!(advisory.contains("habeas setup"), "{advisory:?}");
assert_eq!(
context.matches("`habeas` skill").count(),
1,
"exactly one sentence points to the skill: {context:?}"
);
}
Input 7: outline tests/symposium_hook_smoke.py def[main]
- File:
tests/symposium_hook_smoke.py - Selector:
def[main] - Kind:
def tests/symposium_hook_smoke.py:65–291
def main():
repo = Path(__file__).resolve().parents[1]
cargo = shutil.which("cargo")
symposium = os.environ.get("SYMPOSIUM_BIN") or shutil.which("cargo-agents")
if cargo is None or symposium is None:
raise RuntimeError("cargo and cargo-agents must be installed")
with tempfile.TemporaryDirectory(prefix="habeas-symposium-hook-") as temporary:
root = Path(temporary)
project = root / "consumer"
symposium_home = root / "symposium-home"
local_crate = root / "habeas-current"
source_skills = repo / "assets" / "skills"
for directory in (
project / "md",
project / "src",
symposium_home,
local_crate / "src",
):
directory.mkdir(parents=True)
runner = root / "habeas-local"
runner.write_text(
"#!/bin/sh\n"
f"exec {shlex.quote(cargo)} run --locked --quiet "
f"--manifest-path {shlex.quote(str(repo / 'Cargo.toml'))} "
'--bin habeas -- "$@"\n'
)
runner.chmod(0o755)
manifest = (repo / "Cargo.toml").read_text()
# The stub crates below live outside the repository, so the vendored
# fork's relative path must point back into it.
fork_path = 'path = "vendor/habeas-rig"'
if manifest.count(fork_path) != 1:
raise AssertionError("Habeas's habeas-rig dependency changed")
manifest = manifest.replace(
fork_path, f"path = {json.dumps(str(repo / 'vendor' / 'habeas-rig'))}", 1
)
cargo_installation = (
'source = "cargo"\ncrate = "habeas"\n'
'executable = "habeas"\nglobal = true'
)
if manifest.count(cargo_installation) != 1:
raise AssertionError("Habeas's Cargo installation declaration changed")
(local_crate / "Cargo.toml").write_text(
manifest.replace(
cargo_installation,
f"executable = {json.dumps(str(runner))}",
1,
)
)
(local_crate / "src" / "lib.rs").write_text("")
shutil.copytree(source_skills, local_crate / "assets" / "skills")
(project / "Cargo.toml").write_text(
'[package]\nname = "habeas-hook-consumer"\nversion = "0.1.0"\n'
'edition = "2024"\n\n[dev-dependencies]\n'
f"habeas = {{ path = {json.dumps(str(local_crate))} }}\n"
)
(project / "Cargo.lock").write_bytes((repo / "Cargo.lock").read_bytes())
(project / "book.toml").write_text('[book]\nsrc = "md"\n')
(project / "md" / "SUMMARY.md").write_text("# Summary\n")
(project / "src" / "lib.rs").write_text("")
(symposium_home / "config.toml").write_text(
'auto-sync = false\nauto-update = "off"\nhook-scope = "project"\n'
'agents-syncing = false\n\n[[agent]]\nname = "codex"\n\n'
"[defaults]\nsymposium-recommendations = false\nuser-plugins = false\n"
)
env = os.environ.copy()
env["SYMPOSIUM_HOME"] = str(symposium_home)
metadata = subprocess.run(
[cargo, "metadata", "--format-version", "1", "--all-features"],
cwd=project,
env=env,
text=True,
capture_output=True,
)
if metadata.returncode:
raise RuntimeError(f"Consumer Cargo metadata failed:\n{metadata.stderr}")
current_version = next(
package["version"]
for package in json.loads(metadata.stdout)["packages"]
if package["name"] == "habeas"
)
major, minor, patch = map(int, current_version.split("."))
next_version = f"{major}.{minor}.{patch + 1}"
# {test}`requirements.integration.symposium_setup_hook`
interactive_sync(symposium, project, env)
saved_config = (symposium_home / "config.toml").read_text()
if "auto-enable" not in saved_config or "habeas" not in saved_config:
raise AssertionError("Symposium did not record the decision to enable Habeas")
hook_registration = project / ".codex" / "hooks.json"
if not hook_registration.is_file() or "session-start" not in hook_registration.read_text():
raise AssertionError("Symposium did not register its session-start hook")
last_stderr = ""
def session_start():
nonlocal last_stderr
payload = {
"hook_event_name": "SessionStart",
"session_id": "habeas-smoke-test",
"cwd": str(project),
}
result = subprocess.run(
[symposium, "-v", "hook", "codex", "session-start"],
cwd=project,
env=env,
input=json.dumps(payload),
text=True,
capture_output=True,
)
last_stderr = result.stderr
if result.returncode:
raise RuntimeError(
f"Symposium hook exited {result.returncode}:\n{result.stderr}"
)
try:
output = json.loads(result.stdout)
except json.JSONDecodeError as error:
raise RuntimeError(f"Invalid Symposium output: {result.stdout}") from error
return output.get("hookSpecificOutput", {}).get("additionalContext", "")
skill_sentence = (
"This project tracks requirements with Habeas; "
"load the `habeas` skill before starting any work."
)
# {test}`requirements.integration.symposium_skill_hook`
# {test}`requirements.integration.symposium_skill_hook.setup_state`
incomplete_context = session_start()
if (
not incomplete_context.startswith(skill_sentence)
or "Habeas Codicem is not fully configured" not in incomplete_context
):
status = subprocess.run(
[symposium, "status"],
cwd=project,
env=env,
text=True,
capture_output=True,
)
raise AssertionError(
"Symposium did not deliver Habeas's skill sentence and setup advisory. "
f"Agent output: {incomplete_context!r}\n"
f"Hook diagnostics: {last_stderr}\n"
f"Plugin status: {status.stdout}\n{status.stderr}"
)
subprocess.run(
[runner, "setup", "--path", str(repo)], cwd=project, check=True
)
configured_context = session_start()
if "Habeas Codicem is not fully configured" in configured_context:
raise AssertionError("Symposium kept advising setup after it was complete")
if configured_context.strip() != skill_sentence:
raise AssertionError(
"Symposium did not deliver only the skill sentence once setup was complete: "
f"{configured_context!r}"
)
# {test}`requirements.integration.symposium`
skills_dir = project / ".agents" / "skills"
skill_names = sorted(
path.name for path in source_skills.iterdir() if (path / "SKILL.md").is_file()
)
if not skill_names:
raise AssertionError("Habeas did not ship any skills")
for name in skill_names:
installed = skills_dir / name / "SKILL.md"
if not installed.is_file() or installed.read_bytes() != (
source_skills / name / "SKILL.md"
).read_bytes():
raise AssertionError(f"Symposium did not install the current {name} skill")
# Symposium 0.5.1 debounces skill comparisons for five seconds and
# caches workspace dependencies by whole-second Cargo.lock mtime.
time.sleep(6)
next_crate = root / "habeas-next"
(next_crate / "src").mkdir(parents=True)
(next_crate / "src" / "lib.rs").write_text("")
shutil.copytree(source_skills, next_crate / "assets" / "skills")
current_version_line = f'version = "{current_version}"'
if current_version_line not in manifest:
raise AssertionError("Cargo did not report the current Habeas version")
(next_crate / "Cargo.toml").write_text(
manifest.replace(current_version_line, f'version = "{next_version}"', 1)
)
changed_skill = next_crate / "assets" / "skills" / skill_names[0] / "SKILL.md"
changed_skill.write_text(changed_skill.read_text() + "\nUpdated in the next release.\n")
(project / "Cargo.toml").write_text(
'[package]\nname = "habeas-hook-consumer"\nversion = "0.1.0"\n'
'edition = "2024"\n\n[dev-dependencies]\n'
f"habeas = {{ path = {json.dumps(str(next_crate))} }}\n"
)
updated_metadata = subprocess.run(
[cargo, "metadata", "--format-version", "1", "--all-features"],
cwd=project,
env=env,
text=True,
capture_output=True,
)
if updated_metadata.returncode:
raise RuntimeError(f"Updated Cargo metadata failed:\n{updated_metadata.stderr}")
packages = json.loads(updated_metadata.stdout)["packages"]
if not any(
package["name"] == "habeas" and package["version"] == next_version
for package in packages
):
raise AssertionError("Cargo did not select the next Habeas version")
updated_sync = subprocess.run(
[symposium, "sync"],
cwd=project,
env=env,
text=True,
capture_output=True,
)
if updated_sync.returncode:
raise RuntimeError(f"Updated Symposium sync failed:\n{updated_sync.stderr}")
if (skills_dir / skill_names[0] / "SKILL.md").read_bytes() != changed_skill.read_bytes():
raise AssertionError("Symposium kept the old skill after the selected version changed")
print(
"Symposium dispatched the local CLI, installed current skills, refreshed changed skills, "
"pointed the agent to the habeas skill, and delivered setup advice only when needed."
)
Referenced definitions
Input 2: requirements selection requirements.integration.symposium_setup_hook
requirements.integration.symposium_setup_hook:md/requirements/integration.md:56–58
:::{req} symposium_setup_hook
For an enabled Habeas plugin, a supported agent session started within a Cargo and mdBook project whose manifest lists `habeas` under `[dev-dependencies]`, as {cite}`requirements.cli.setup` adds it, MUST receive a Symposium `SessionStart` hook. The hook MUST check whether the configuration and files required by `requirements.cli.setup`, {cite}`requirements.test-coverage.setup`, and {cite}`requirements.test-coverage.setup.configuration` are present and compatible. If not, it MUST provide nonblocking agent context saying that Habeas Codicem is not fully configured and suggesting `habeas setup`. If setup is complete or no applicable project is found, it MUST provide no setup advisory. The hook MUST NOT modify project files or run setup itself.
:::
Input 3: requirements selection requirements.integration.symposium_skill_hook
requirements.integration.symposium_skill_hook:md/requirements/integration.md:60–62
:::{req} symposium_skill_hook
For an enabled Habeas plugin, a supported agent session started within a Cargo and mdBook project whose manifest lists `habeas` under `[dev-dependencies]`, as {cite}`requirements.cli.setup` adds it, MUST receive nonblocking agent context from the `SessionStart` hook of {cite}`requirements.integration.symposium_setup_hook`. That context MUST contain exactly one sentence that points to the skill. The sentence says the project uses Habeas and tells the agent to load the `habeas` skill of {cite}`requirements.cli.overview_skill` before starting any work in the project.
:::
Other sources
Input 1: requirements selection requirements.integration.symposium_skill_hook.setup_state
requirements.integration.symposium_skill_hook.setup_state:md/requirements/integration.md:68–70
:::{req} symposium_skill_hook.setup_state
When the setup advisory of {cite}`requirements.integration.symposium_setup_hook` also applies, the hook MUST provide the sentence of {cite}`requirements.integration.symposium_skill_hook` and the advisory together in one agent context, with the sentence first.
:::
Input 8: outline src/hook.rs fn[session_start_response]
- File:
src/hook.rs - Selector:
fn[session_start_response] - Kind:
fn src/hook.rs:22–47
fn session_start_response(input: &Value, fallback_cwd: &Path) -> Value {
let Some(event) = input.get("SessionStart") else {
return json!({"SessionStart": {}});
};
let cwd = event
.get("cwd")
.and_then(Value::as_str)
.map(PathBuf::from)
.unwrap_or_else(|| fallback_cwd.to_path_buf());
let Some(root) = setup::find_project_root(&cwd) else {
return json!({"SessionStart": {}});
};
if !setup::project_depends_on_habeas(&root) {
return json!({"SessionStart": {}});
}
let mut context = SKILL_SENTENCE.to_owned();
if !setup::is_configured(&root) {
context.push(' ');
context.push_str(&format!(
"Habeas Codicem is not fully configured in {}. Run `habeas setup` in this project to configure its mdBook preprocessor, stylesheet, and validation test.",
root.display()
));
}
json!({"SessionStart": {"additionalContext": context}})
}