Demo page details
Page source code: pharaoh.rst
1{% set page="pharaoh.rst" %}
2{% include "demo_page_header.rst" with context %}
3
4🦅 Pharaoh setup
5================
6
7`Pharaoh <https://github.com/useblocks/pharaoh>`__ is an authoring and
8review layer that sits on top of Sphinx-Needs. It does not change how
9needs are stored or built. Sphinx-Needs remains the source of truth.
10Pharaoh adds:
11
12* atomic skills for drafting, reviewing, and auditing requirements,
13 architecture elements, FMEA entries, test cases, and decisions.
14* a per-project tailoring layer (``.pharaoh/project/``) that captures
15 workflow states, artefact catalogs, ID conventions, and review
16 checklists in YAML.
17* a traceability gate (``pharaoh:mece``) that reports gaps, orphans,
18 and link inconsistencies against the project's declared chains.
19* GitHub Copilot agents (``@pharaoh.req-draft``, ``@pharaoh.mece``,
20 ``@pharaoh.flow``, ...) installed under ``.github/agents``.
21
22This page records how Pharaoh was bootstrapped on the
23sphinx-needs-demo repository so the setup can be reproduced.
24
25What Pharaoh adds on top of Sphinx-Needs
26----------------------------------------
27
28The demo project already declares its need types and link options in
29``docs/ubproject.toml``. Pharaoh re-uses those declarations and adds
30the files described below.
31
32.. list-table::
33 :header-rows: 1
34 :widths: 30 50 20
35
36 * - File / directory
37 - Purpose
38 - Tracked in git?
39 * - ``pharaoh.toml``
40 - Pharaoh strictness, mode, traceability rules, codelinks toggle.
41 Only Pharaoh's own behavior, not Sphinx-Needs configuration.
42 - yes
43 * - ``.pharaoh/project/workflows.yaml``
44 - Lifecycle state machine per need type
45 (``draft → reviewed → approved``).
46 - yes
47 * - ``.pharaoh/project/id-conventions.yaml``
48 - Per-type ID prefixes and the project's ``id_regex`` mirror.
49 - yes
50 * - ``.pharaoh/project/artefact-catalog.yaml``
51 - Required and optional fields per type, parent-of relations,
52 lifecycle reference.
53 - yes
54 * - ``.pharaoh/project/checklists/<type>.md``
55 - Review checklist consumed by ``pharaoh:<type>-review`` skills.
56 - yes
57 * - ``.pharaoh/runs/``, ``.pharaoh/plans/``,
58 ``.pharaoh/session.json``, ``.pharaoh/cache/``
59 - Run-time artefacts emitted by Pharaoh skills.
60 - **no** (gitignored)
61 * - ``.github/agents/pharaoh.*.agent.md``
62 - Custom Copilot Chat agents.
63 - yes
64 * - ``.github/prompts/pharaoh.*.prompt.md``
65 - Reusable prompts (``/pharaoh.author``, ``/pharaoh.mece``, ...).
66 - yes
67 * - ``.github/copilot-instructions.md``
68 - Repository-wide Copilot preamble that loads Pharaoh context.
69 - yes
70
71Setup
72-----
73
74The setup is performed by the Pharaoh setup agent. It is idempotent:
75re-running it on an already-configured project shows a diff and asks
76before overwriting any file.
77
78Prerequisites
79^^^^^^^^^^^^^
80
81* a Sphinx project with Sphinx-Needs already configured
82 (``ubproject.toml`` or ``conf.py`` declaring at least one
83 ``[[needs.types]]`` entry).
84* the Pharaoh plugin installed in your AI assistant of choice
85 (see below).
86
87Optional but recommended:
88
89* the ``ubc`` CLI on ``PATH`` (faster, deterministic data access).
90* the ubCode VS Code extension (live indexing and MCP integration).
91
92Installing the Pharaoh plugin
93^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94
95**Claude Code.** Add the marketplace, install the plugin, and reload
96plugins:
97
98.. code-block:: text
99
100 /plugin marketplace add useblocks/pharaoh
101 /plugin install pharaoh@pharaoh-dev
102 /reload-plugins
103
104To pin a specific Pharaoh release instead of tracking ``pharaoh-dev``,
105add the marketplace at a tag:
106
107.. code-block:: text
108
109 /plugin marketplace add useblocks/pharaoh#v1.0.0
110
111**GitHub Copilot CLI.** Same flow with the ``copilot`` command:
112
113.. code-block:: bash
114
115 copilot plugin marketplace add useblocks/pharaoh
116 copilot plugin install pharaoh@pharaoh-dev
117
118Once the plugin is installed, the agents and skills described below
119become available in the assistant.
120
121Running the setup
122^^^^^^^^^^^^^^^^^
123
124After the plugin is installed and the agents in this PR are committed,
125GitHub Copilot Chat exposes ``@pharaoh.setup`` as the entry point:
126
127.. code-block:: text
128
129 @pharaoh.setup
130
131In Claude Code, invoke the same skill via its plugin slash form:
132
133.. code-block:: text
134
135 /pharaoh:pharaoh-setup
136
137Either form runs the same five steps:
138
1391. **Detect project structure.** Reads ``ubproject.toml``, lists
140 declared types and link options, samples existing IDs, and detects
141 whether sphinx-codelinks is configured.
1422. **Generate** ``pharaoh.toml``. Asks for a strictness mode and a
143 project-lifecycle mode (``reverse-eng``, ``greenfield``, or
144 ``steady-state``) and writes the file at the workspace root.
1453. **Scaffold Copilot agents** under ``.github/agents/`` and
146 ``.github/prompts/``.
1474. **Configure** ``.gitignore``. Adds narrow entries for the
148 ephemeral ``.pharaoh/`` paths and leaves ``.pharaoh/project/``
149 tracked.
1505. **Bootstrap tailoring.** Calls ``pharaoh-tailor-bootstrap`` to
151 write the YAML tailoring files and the per-type checklists into
152 ``.pharaoh/project/``.
153
154This demo's ``pharaoh.toml``
155----------------------------
156
157.. literalinclude:: ../pharaoh.toml
158 :language: toml
159 :caption: pharaoh.toml
160
161A few decisions worth calling out:
162
163* **Mode** is ``reverse-eng``. The catalogue already exists, so the
164 ``require_change_analysis`` and ``require_mece_on_release`` gates
165 start permissive. They can be tightened with ``pharaoh:gate-advisor``
166 once the workflow stabilises.
167* **Strictness** is ``advisory``. Pharaoh skills suggest the
168 recommended workflow but never block authoring.
169* **Required link chains** reflect the 100%-coverage policy that the
170 existing needs already satisfy: ``spec → req``, ``arch → req``,
171 ``safety_goal → hazard``, ``fsr → safety_goal``. Chains for
172 ``impl`` and ``test`` were intentionally left out because the
173 corpus shows mixed parent types below 90% coverage.
174* **Codelinks** are enabled. Pharaoh's change-impact analysis follows
175 the ``[codelinks.projects.coffee_machine]`` configuration declared
176 in ``docs/ubproject.toml``.
177
178Verifying the setup
179-------------------
180
181Build the documentation and run the MECE check to confirm the
182traceability rules match the corpus:
183
184.. code-block:: bash
185
186 uv sync
187 uv run sphinx-build -b html docs docs/_build/html -W
188
189After the build emits ``docs/_build/html/needs.json``, invoke MECE
190from your agent. In Copilot Chat:
191
192.. code-block:: text
193
194 @pharaoh.mece
195
196The same prompt is available as ``/pharaoh.mece`` and, in Claude
197Code, as ``/pharaoh:pharaoh-mece``.
198
199For the demo's current state the report shows zero gaps against the
200configured chains. Other findings (status mismatches, ID-regex
201violations, undeclared types injected by ``sphinx-test-reports``) are
202pre-existing properties of the corpus and are surfaced for review,
203not introduced by Pharaoh.
204
205🛠️ Walkthrough: AI-assisted V-model authoring
206---------------------------------------------
207
208Once setup is complete, the typical Pharaoh workflow on this demo
209takes four prompts. Each prompt is self-contained, so they can be run
210top-to-bottom or in isolation. The example below uses the GitHub
211Copilot Chat syntax (``@pharaoh.<name>``); in Claude Code the
212equivalent slash form is ``/pharaoh:pharaoh-<name>``.
213
214The shared scenario across the four prompts is the existing
215``REQ_001 — Lane Detection Algorithm`` and the ``LaneDetection`` class
216in ``src/automotive_adas.py``. The walkthrough fills a focused
217API-encapsulation requirement, writes the test that verifies it, and
218then asks what changes if ``REQ_001`` itself is revised.
219
220Step 1: gap analysis
221^^^^^^^^^^^^^^^^^^^^
222
223.. code-block:: text
224
225 @pharaoh.mece
226
227Expected: the four declared traceability chains hit 100 percent
228coverage, but the report surfaces parent-closed/child-open status
229mismatches, needs of types injected by ``sphinx-test-reports`` that
230are not declared in ``[[needs.types]]``, and a number of existing
231need IDs that fail the project's own ``id_regex``.
232
233Step 2: reverse-engineer a focused requirement from code
234^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
235
236.. code-block:: text
237
238 @pharaoh.req-from-code
239
240 src/automotive_adas.py — focused API contract for the LaneDetection
241 class as a child of REQ_001. Emit a single `req` directive. Use only
242 fields declared in ubproject.toml; do not emit :source_doc: or
243 :verification: unless the project's catalogue declares them.
244
245Expected: a ``.. req::`` block with a short domain-shaped ID, status
246``open``, ``:links: REQ_001``, and a single shall-clause grounded in
247the ``LaneDetection`` class's public methods. The skill follows the
248project's id-conventions and uses only declared fields. If the
249emitted RST still carries Pharaoh-internal placeholders, strip them
250before pasting under ``docs/automotive-adas/`` or add the fields to
251``ubproject.toml``.
252
253Step 3: write the missing test
254^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
255
256.. code-block:: text
257
258 @pharaoh.vplan-draft
259
260 System test for REQ_001 with measurable lighting-condition
261 thresholds. Emit only the RST `.. test::` directive ready to paste,
262 no review and no self-evaluation.
263
264Expected: a ``.. test::`` block with a short domain-shaped ID, three
265body sections (Inputs, Steps, Expected), and a measurable acceptance
266criterion such as a lateral-deviation or IoU threshold across
267lighting scenarios.
268
269Step 4: change-impact analysis
270^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
271
272.. code-block:: text
273
274 @pharaoh.change
275
276 REQ_001 is being revised: tighter lateral tolerance, ECU port.
277 Scope to the lane-detection domain. Emit the full change-impact
278 report directly; do not stop at an acknowledgement prompt.
279
280Expected: a tight blast radius of about 6 to 8 needs — one
281architecture element, three software requirements, two system tests,
282the release window, and any newly authored child needs from Steps 2
283and 3. The ``emit directly`` nudge bypasses the acknowledgement
284workflow gate added in Pharaoh v1.2.
285
286Why so short
287^^^^^^^^^^^^
288
289The agent reads the project's tailoring (``.pharaoh/project/``) and
290``ubproject.toml`` itself, so the user does not have to repeat the
291declared types, link options, ID regex, or status enum. The short
292nudges in Steps 2, 3, and 4 keep specific Pharaoh atomic skills from
293drifting into adjacent behaviour:
294
295* ``pharaoh-req-from-code`` happily emits several SW-level
296 requirements when one feature-level requirement was asked for, and
297 emits Pharaoh-internal placeholder fields (``:source_doc:``,
298 ``:verification:``) regardless of whether the project declares
299 them.
300* ``pharaoh-vplan-draft`` happily follows its draft with a
301 self-review pass and returns the review instead of the test.
302* ``pharaoh-change`` (since Pharaoh v1.2) writes a session-state
303 acknowledgement gate and waits for the user to approve before
304 emitting the full impact report.
305
306All three behaviours are tracked as upstream Pharaoh issues. The
307nudges are workshop-grade workarounds, not project-specific tailoring.
308
309Sanity-check the artefacts
310^^^^^^^^^^^^^^^^^^^^^^^^^^
311
312The two RST blocks emitted by Steps 2 and 3 paste directly under
313``docs/automotive-adas/``. Re-run the build and the ubc check to
314confirm both still pass:
315
316.. code-block:: bash
317
318 uv run sphinx-build -W -b html docs docs/_build/html
319 ubc check docs
320
321Both commands should report success with the new needs included.
322
323Tailoring layer
324---------------
325
326The files under ``.pharaoh/project/`` are intentionally human-readable
327so that they can be hand-tuned. Key entry points:
328
329* ``workflows.yaml``: change the allowed lifecycle states or add a
330 ``deprecated`` terminal state.
331* ``artefact-catalog.yaml``: promote a field from optional to
332 required, or add a project-specific link option (for example
333 ``mitigates`` for safety goals) to a type's ``required_fields``.
334* ``checklists/<type>.md``: edit the review questions consumed by
335 the per-type review skills.
336* ``id-conventions.yaml``: tighten or relax the ID regex once the
337 ID-policy collisions in the project's own ``[[needs.types]]`` are
338 resolved.
339
340Re-run ``@pharaoh.tailor-detect`` once the catalogue grows past a
341few dozen new needs to refresh the inferred conventions.
🦅 Pharaoh setup¶
Pharaoh is an authoring and review layer that sits on top of Sphinx-Needs. It does not change how needs are stored or built. Sphinx-Needs remains the source of truth. Pharaoh adds:
atomic skills for drafting, reviewing, and auditing requirements, architecture elements, FMEA entries, test cases, and decisions.
a per-project tailoring layer (
.pharaoh/project/) that captures workflow states, artefact catalogs, ID conventions, and review checklists in YAML.a traceability gate (
pharaoh:mece) that reports gaps, orphans, and link inconsistencies against the project’s declared chains.GitHub Copilot agents (
@pharaoh.req-draft,@pharaoh.mece,@pharaoh.flow, …) installed under.github/agents.
This page records how Pharaoh was bootstrapped on the sphinx-needs-demo repository so the setup can be reproduced.
What Pharaoh adds on top of Sphinx-Needs¶
The demo project already declares its need types and link options in
docs/ubproject.toml. Pharaoh re-uses those declarations and adds
the files described below.
File / directory |
Purpose |
Tracked in git? |
|---|---|---|
|
Pharaoh strictness, mode, traceability rules, codelinks toggle. Only Pharaoh’s own behavior, not Sphinx-Needs configuration. |
yes |
|
Lifecycle state machine per need type
( |
yes |
|
Per-type ID prefixes and the project’s |
yes |
|
Required and optional fields per type, parent-of relations, lifecycle reference. |
yes |
|
Review checklist consumed by |
yes |
|
Run-time artefacts emitted by Pharaoh skills. |
no (gitignored) |
|
Custom Copilot Chat agents. |
yes |
|
Reusable prompts ( |
yes |
|
Repository-wide Copilot preamble that loads Pharaoh context. |
yes |
Setup¶
The setup is performed by the Pharaoh setup agent. It is idempotent: re-running it on an already-configured project shows a diff and asks before overwriting any file.
Prerequisites¶
a Sphinx project with Sphinx-Needs already configured (
ubproject.tomlorconf.pydeclaring at least one[[needs.types]]entry).the Pharaoh plugin installed in your AI assistant of choice (see below).
Optional but recommended:
the
ubcCLI onPATH(faster, deterministic data access).the ubCode VS Code extension (live indexing and MCP integration).
Installing the Pharaoh plugin¶
Claude Code. Add the marketplace, install the plugin, and reload plugins:
/plugin marketplace add useblocks/pharaoh
/plugin install pharaoh@pharaoh-dev
/reload-plugins
To pin a specific Pharaoh release instead of tracking pharaoh-dev,
add the marketplace at a tag:
/plugin marketplace add useblocks/pharaoh#v1.0.0
GitHub Copilot CLI. Same flow with the copilot command:
copilot plugin marketplace add useblocks/pharaoh
copilot plugin install pharaoh@pharaoh-dev
Once the plugin is installed, the agents and skills described below become available in the assistant.
Running the setup¶
After the plugin is installed and the agents in this PR are committed,
GitHub Copilot Chat exposes @pharaoh.setup as the entry point:
@pharaoh.setup
In Claude Code, invoke the same skill via its plugin slash form:
/pharaoh:pharaoh-setup
Either form runs the same five steps:
Detect project structure. Reads
ubproject.toml, lists declared types and link options, samples existing IDs, and detects whether sphinx-codelinks is configured.Generate
pharaoh.toml. Asks for a strictness mode and a project-lifecycle mode (reverse-eng,greenfield, orsteady-state) and writes the file at the workspace root.Scaffold Copilot agents under
.github/agents/and.github/prompts/.Configure
.gitignore. Adds narrow entries for the ephemeral.pharaoh/paths and leaves.pharaoh/project/tracked.Bootstrap tailoring. Calls
pharaoh-tailor-bootstrapto write the YAML tailoring files and the per-type checklists into.pharaoh/project/.
This demo’s pharaoh.toml¶
# Pharaoh configuration for sphinx-needs-demo.
# Need types and link types are read from docs/ubproject.toml. They are not
# re-defined here.
[pharaoh]
# "advisory" (default): suggests workflow but never blocks.
# "enforcing": skills gate each other per workflow rules.
strictness = "advisory"
[pharaoh.id_scheme]
# Available placeholders: {TYPE}, {MODULE}, {NUMBER}.
# Existing project IDs use a domain prefix (e.g. BRAKE_CTRL_01, FSR_POWER_01).
# The default below is a safe starting point for new IDs allocated by Pharaoh.
pattern = "{TYPE}_{NUMBER}"
auto_increment = true
[pharaoh.workflow]
# mode: reverse-eng. Pharaoh is being introduced over an existing catalogue.
# Tighten as the catalogue stabilises (see skills/shared/gate-enablement.md).
require_change_analysis = false
require_verification = true
require_mece_on_release = false
[pharaoh.traceability]
# Required link chains. pharaoh:mece reports violations.
# Format: "source_type -> target_type". Every <source> must have at least one
# outgoing link to a need of <target> type (across any link option).
# Chains below reflect 100%-coverage policy observed in this repo's needs.json:
# spec :reqs: -> req
# arch :links: -> req
# safety_goal :mitigates: -> hazard
# fsr :derives_from: -> safety_goal
# Chains for impl/test/component were intentionally omitted: corpus shows mixed
# parent types (swreq, swarch, interface, ...) below 90% coverage, so they are
# not project-wide policy yet. Add them once the convention stabilises.
required_links = [
"spec -> req",
"arch -> req",
"safety_goal -> hazard",
"fsr -> safety_goal",
]
[pharaoh.codelinks]
# sphinx-codelinks detected in docs/ubproject.toml [codelinks]. Pharaoh's
# change-impact analysis follows it.
enabled = true
A few decisions worth calling out:
Mode is
reverse-eng. The catalogue already exists, so therequire_change_analysisandrequire_mece_on_releasegates start permissive. They can be tightened withpharaoh:gate-advisoronce the workflow stabilises.Strictness is
advisory. Pharaoh skills suggest the recommended workflow but never block authoring.Required link chains reflect the 100%-coverage policy that the existing needs already satisfy:
spec → req,arch → req,safety_goal → hazard,fsr → safety_goal. Chains forimplandtestwere intentionally left out because the corpus shows mixed parent types below 90% coverage.Codelinks are enabled. Pharaoh’s change-impact analysis follows the
[codelinks.projects.coffee_machine]configuration declared indocs/ubproject.toml.
Verifying the setup¶
Build the documentation and run the MECE check to confirm the traceability rules match the corpus:
uv sync
uv run sphinx-build -b html docs docs/_build/html -W
After the build emits docs/_build/html/needs.json, invoke MECE
from your agent. In Copilot Chat:
@pharaoh.mece
The same prompt is available as /pharaoh.mece and, in Claude
Code, as /pharaoh:pharaoh-mece.
For the demo’s current state the report shows zero gaps against the
configured chains. Other findings (status mismatches, ID-regex
violations, undeclared types injected by sphinx-test-reports) are
pre-existing properties of the corpus and are surfaced for review,
not introduced by Pharaoh.
Tailoring layer¶
The files under .pharaoh/project/ are intentionally human-readable
so that they can be hand-tuned. Key entry points:
workflows.yaml: change the allowed lifecycle states or add adeprecatedterminal state.artefact-catalog.yaml: promote a field from optional to required, or add a project-specific link option (for examplemitigatesfor safety goals) to a type’srequired_fields.checklists/<type>.md: edit the review questions consumed by the per-type review skills.id-conventions.yaml: tighten or relax the ID regex once the ID-policy collisions in the project’s own[[needs.types]]are resolved.
Re-run @pharaoh.tailor-detect once the catalogue grows past a
few dozen new needs to refresh the inferred conventions.