requirements.integration.symposium_skill_hook
Requirements index · View definition
Requirement
For an enabled Habeas plugin, a supported agent session started within a Cargo and mdBook project whose manifest lists
habeasunder[dev-dependencies], asadds it, MUST receive nonblocking agent context from the
SessionStarthook of. 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
habeasskill ofbefore starting any work in the project.
Rationale
I found no gap.
Obligations
- A session in an applicable project must receive nonblocking agent context from the
SessionStarthook. - That context must contain exactly one sentence that points to the skill.
- The sentence must say the project uses Habeas.
- The sentence must tell the agent to load the
habeasskill before starting any work.
Code
- The hook is registered in
Cargo.tomlunder[package.metadata.symposium.hooks]as aSessionStarthook that runshabeas hook session-start. That registration already carries thesymposium_setup_hookandsymposium_cliimpl references. src/hook.rs#fn[session_start]is the marked impl. It reads the hook input and writes the response fromsession_start_response.session_start_responsefinds the project root withsetup::find_project_root, which needs bothCargo.tomlandbook.toml.- It then requires
setup::project_depends_on_habeas. That function checks only[dev-dependencies], so a project withhabeasonly under[dependencies]is not applicable. - For an applicable project it starts the context with
SKILL_SENTENCE: “This project tracks requirements with Habeas; load thehabeasskill before starting any work.” This one sentence says the project uses Habeas and tells the agent to load thehabeasskill first. - The response is
{"SessionStart": {"additionalContext": ...}}. It carries no blocking field, so it is nonblocking. - If
setup::is_configuredfails, an advisory is appended after the skill sentence. That advisory does not mention the skill, so the context still has exactly one sentence pointing to the skill.
Tests
tests/setup.rs#fn[session_start_points_to_the_habeas_skill_once_setup_is_complete]runshabeas setup. It then asserts that the whole response is exactly the skill sentence, from both the project root and a nested directory. It also asserts there is no advisory. This covers theconfiguredexample.tests/setup.rs#fn[session_start_puts_the_skill_sentence_before_the_setup_advisory]uses a manifest with ahabeasdev-dependency and incomplete setup. It asserts the following:- one agent context;
- the skill sentence comes first;
- the advisory follows;
`habeas` skillappears exactly once.
tests/setup.rs#fn[session_start_gives_no_context_outside_habeas_projects]covers the applicability boundary. That includes the[dependencies]-only case.tests/symposium_hook_smoke.py#def[main]runs the real SymposiumSessionStarthook. It checks the skill sentence plus the advisory before setup, and only the skill sentence after setup.
Every obligation has an implementation and a test that asserts its outcome.
Inputs
Implementation
Input 6: 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 5: requirements selection requirements.integration.symposium_skill_hook.configured
requirements.integration.symposium_skill_hook.configured:md/requirements/integration.md:64–66
:::{example} symposium_skill_hook.configured
In a project where `habeas setup` has completed, the whole session-start agent context is one sentence such as "This project tracks requirements with Habeas; load the `habeas` skill before starting any work." {test}`requirements.integration.symposium_skill_hook`
:::
Input 7: outline tests/setup.rs fn[session_start_points_to_the_habeas_skill_once_setup_is_complete]
- File:
tests/setup.rs - Selector:
fn[session_start_points_to_the_habeas_skill_once_setup_is_complete] - Kind:
fn tests/setup.rs:620–639
// {test}`requirements.integration.symposium_skill_hook`
// {test}`requirements.integration.symposium_skill_hook.configured`
#[test]
fn session_start_points_to_the_habeas_skill_once_setup_is_complete() {
let temp = fixture();
let project = temp.path();
run(project, &["setup", "--path", env!("CARGO_MANIFEST_DIR")]);
let nested = project.join("src/nested");
fs::create_dir_all(&nested).unwrap();
for cwd in [project, nested.as_path()] {
let response = session_start(project, cwd);
assert_eq!(
response,
skill_sentence_only(),
"the whole context of a configured project is the skill sentence"
);
assert!(!advises_setup(&response));
}
}
Input 8: 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 9: 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.cli.setup
requirements.cli.setup:md/requirements/cli.md:11–13
:::{req} setup
Running `habeas setup` in an existing Cargo and mdBook project MUST add Habeas as a dev dependency, configure `habeas mdbook` as its preprocessor, add the badge stylesheet, enable sidebar folding with `output.html.fold.enable` unless the book already sets it, and create `tests/habeas.rs` that calls `habeas::validate()`. Repeating setup MUST avoid duplicate configuration and MUST NOT overwrite a differing test or stylesheet. Setup MUST NOT install or modify agent skills.
:::
Input 3: 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 4: requirements selection requirements.cli.overview_skill
requirements.cli.overview_skill:md/requirements/cli.md:97–100
:::{req} overview_skill
Habeas MUST bundle a `habeas` skill whose description tells agents to use it at the start of any work in a Habeas project, naming as signs of one a `habeas` dev-dependency, a `habeas.toml`, `{req}` directives in the book, and `{impl}`, `{test}`, or `{cite}` references in code.
:::
Other sources
Input 1: 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.
:::
Input 10: outline src/hook.rs use@a552f69c94db
- File:
src/hook.rs - Selector:
use@a552f69c94db - Kind:
use src/hook.rs:1–1
use std::error::Error;
Input 11: outline src/hook.rs use@95d18074761c
- File:
src/hook.rs - Selector:
use@95d18074761c - Kind:
use src/hook.rs:2–2
use std::io;
Input 12: outline src/hook.rs use@3970e6901143
- File:
src/hook.rs - Selector:
use@3970e6901143 - Kind:
use src/hook.rs:3–3
use std::path::{Path, PathBuf};
Input 13: outline src/hook.rs use@6e42e0801700
- File:
src/hook.rs - Selector:
use@6e42e0801700 - Kind:
use src/hook.rs:5–5
use serde_json::{Value, json};
Input 14: outline src/hook.rs use@4bead300e6e4
- File:
src/hook.rs - Selector:
use@4bead300e6e4 - Kind:
use src/hook.rs:7–7
use crate::setup;
Input 15: outline src/hook.rs const[SKILL_SENTENCE]
- File:
src/hook.rs - Selector:
const[SKILL_SENTENCE] - Kind:
const src/hook.rs:9–10
/// The sentence every applicable session receives, pointing at the overview skill.
const SKILL_SENTENCE: &str = "This project tracks requirements with Habeas; load the `habeas` skill before starting any work.";
Input 16: 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}})
}