agentleFS
HorizunGroupHorizunGroup/horizun-pbi-mcp/AGENTS.md

horizun-pbi-mcp

AGENTS.md29 starsChanged 58 days agoApache-2.0View on GitHub

Operating instructions for any agent (or person) modifying Horizun PBI MCP. They take priority over any general convention. If the baseline is already broken, fix it or report it first. Don't build on red. The 34 baseline tools are frozen in tests/golden/tools_v1.json. Forbidden without explicit approval: - removing a tool - renaming a tool - removing a parameter - adding a required parameter - changing a parameter's type - changing a default value - changing the response shape Allowed: -…

  • Reads credentials
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,736 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository3 other files it gives its agents.

The file

We split this AGENTS.md into the rules it gives an agent

11 rules. About 0 are common, 6 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If the baseline is already broken, fix it or report it first.

    line 15
  2. Very specific:

    Never declare as read_only anything that calls guard_mutation or writes a file.

    line 41
  3. Distinctive:

    Check at any time:

    line 45
  4. Distinctive:

    After a deliberate, approved change:

    line 53
  5. Very specific:

    stdout is the JSON-RPC channel: All logging goes to stderr or a file.

    line 63
  6. Distinctive:

    Never overwrite JSON that doesn't parse: If it can't be read, abort.

    line 64
  7. Very specific:

    No write path leaves the active project: Use ensure_within_base().

    line 66
  8. Very specific:

    Real data is never versioned: no one's .pbix, no one's .pbip, no DLLs, no outputs/, no backups/, no .env, no .mcp.json.

    line 140
  9. Very specific:

    R13 (single-destination atomicity): closed: All flows targeting the same destination are single transactions or a single SaveChanges.

    line 202
  10. Distinctive:

    Don't trust the list above.

    line 239
  11. Distinctive:

    Don't mark any risk as closed without a regression test that fails before the fix and passes after.

    line 258

≈ “Common” is an estimate: at least 1 in 5 of the 16,597 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Repository rules for agents

Operating instructions for any agent (or person) modifying Horizun PBI MCP. They take priority over any general convention.


1. Before touching anything

python -m pytest -q                    # must pass green
python scripts/doctor.py               # must exit with code 0

If the baseline is already broken, fix it or report it first. Don't build on red.


2. The MCP contract is untouchable

The 34 baseline tools are frozen in tests/golden/tools_v1.json.

Forbidden without explicit approval:

  • removing a tool
  • renaming a tool
  • removing a parameter
  • adding a required parameter
  • changing a parameter's type
  • changing a default value
  • changing the response shape

Allowed:

  • adding new tools
  • adding optional parameters with a default
  • adding new fields to the response dict
  • improving descriptions

Adding a tool also means classifying it in src/tools/risk.py. The suite fails if you don't: an unclassified tool is announced to the client as destructive — which is the safe default, but the table has to say so out loud. Never declare as read_only anything that calls guard_mutation or writes a file; tests/test_tool_annotations.py checks that against the code, not against the docs.

Check at any time:

python -m tests.contract_utils

Returns 0 if there are no breaks, 1 if there are, with a report stating what changed and whether it breaks compatibility — not a dump of two JSONs.

After a deliberate, approved change:

python -m tests.contract_utils --write

3. Invariants no phase can break

  1. stdout is the JSON-RPC channel. All logging goes to stderr or a file. A debug print() breaks the client connection.
  2. Never overwrite JSON that doesn't parse. If it can't be read, abort.
  3. Every write to the user's project: backup before, re-read after.
  4. No write path leaves the active project. Use ensure_within_base().
  5. No fields are invented that don't exist in the model. If a field doesn't exist, report it; don't guess.
  6. Destructive tools require confirm=true.
  7. Prefer cloning a real template over hand-building visual JSON.

4. Real data: never enters git

Never versionDo version
Real .pbix, .pbip, .Report/, .SemanticModel/tests/fixtures/synthetic/**
libs/ (DLLs)scripts/fetch_libs.py
outputs/, backups/, *.log*.example.* templates
.env, .mcp.json, credentials.env.example, .mcp.json.example
tests/fixtures/local/docs/, tests/

Before any commit:

git status --short --ignored

Synthetic fixtures contain no commercial names, data or information from any real project. If you need real PBIR structure, use the ignored local fixture (scripts/setup_local_fixture.py) and never promote it to synthetic/ without anonymizing it and without review.


5. Tests

LevelWhereRule
Unittests/test_*.pyNo real I/O outside tmp_path
Synthetic fixturestests/fixtures/synthetic/Use materialize(tmp_path). Never write over the versioned fixture
MCP contracttests/test_tool_contract.pyMust always pass
Livemarked @pytest.mark.skip or liveNot run on their own. Never destructive against a real model
Local fixturemarked local_fixtureRead-only. Skipped if the folder doesn't exist

Scripts that drive a real Power BI Desktop (ad-hoc checks, not part of the suite) must isolate the persisted session before doing anything else:

HORIZUN_PBI_MCP_OUTPUTS_DIR=/some/scratch/outputs python your_live_script.py

Opening a project persists it (project_locator.open_project() writes outputs/session.json), so without this a check leaves the user's session pointing at a temporary fixture. The variable is read once, when settings are first resolved, so it has to be set before the process imports anything that touches them. Same rule for the windows themselves: identify every process and file before acting, close only the instances the script opened, and never point one at a real project. tests/test_correcciones_de_auditoria.py (group 22) pins the isolation route.

Path traversal tests: the "outside" must be created inside pytest's tmp_path (synthetic.outside_marker_dir()). Never point at a real machine path, not even to demonstrate a failure.


6. Git and contributions

This is the public repository. Contributions go through branches and pull requests.

  • Never force-push to main. Rewriting published history breaks any clone and any reference to a commit.
  • One branch per change, with a name that says what it does.
  • Before opening a PR, all three green:

    python -m pytest -q
    python scripts/doctor.py
    python -m tests.contract_utils

    CI repeats them on windows-latest with Python 3.10 and 3.13. A red PR is not reviewed.

  • The MCP contract is frozen. See section 2: adding is free, changing or removing is not.
  • Real data is never versioned: no one's .pbix, no one's .pbip, no DLLs, no outputs/, no backups/, no .env, no .mcp.json. See section 4.
  • One commit per logical change. The message explains what was wrong, not just what was touched.
  • Publishing is gated, not forbidden. .github/workflows/release.yml publishes to PyPI on a tag, and only after the build-and-test job it depends on is green over the same commit. Nothing is published from a branch, from a manual run by default, or from a local clone. This line used to say that nothing was published from this repository, which stopped being true when release.yml landed.

Extended contribution guide: CONTRIBUTING.md.


7. Risk status

Three states, and only three: closed, partially closed, open. Detail in docs/PHASE_1A_DESIGN.md.

IdRiskStatus
R2Corrupting a .pbip: no Desktop detection, no post-write verificationClosed (1A)
R3Write traversal in PBIRClosed (1A)
R5Backups without validated location or retentionClosed (F/R5) — validated location, hash identification, manifest, and purge via pbi_purge_backups: dry-run by default, validated root, only recognizable journals, symlinks not followed, and the most recent one plus all pending ones are always kept
R6session.json pointing to a dead or reused portClosed (1A)
R7pbi_run_dax without read-only validationClosed (1A)
R11.tmp leftover inside the .pbip when os.replace failsClosed (1A)
R12Rollback left empty, orphaned page directoriesClosed (1A.1)
R13Multi-file PBIR flow atomicityPartially closed — see below
R14Incomplete packaging (services*, reporting)Closed (1A.1), with an installed-wheel test

R13 — multi-file atomicity, in detail

Don't mark this risk closed while a single flow remains uncovered.

FlowFilesStatus
pbi_create_page_from_specpage.json + pages.json + N visual.json✅ one transaction
pbi_arrange_visualsN visual.json✅ one transaction
pbi_generate_report_pagepage.json + pages.json + N visual.json✅ one transaction
pbi_create_html_visualreport.json + visual.json✅ one transaction
pbir_writer.create_pagepage.json + pages.json✅ one transaction
pbi_hide_columns (pbip)N TMDL files✅ one transaction (1A.2)
pbi_hide_columns (live)N TOM columns✅ a single SaveChanges (1A.2)

Inventory expansion (Phase D) — flows that were missing

The inventory above was built with lexical searches (grep for project_transaction inside a for). That method has a blind spot: the transaction opens inside the called function, not inside the loop. Two high-level workflows fell right into that gap and didn't show up:

FlowWhat it didEvidence
pbi_repair_broken_referencesOne transaction per visual, inside a for, with except Exception that kept going. If the fifth one failed, the previous four stayed committed and the tool returned ok:true with a list of failures.workflows.py:222 (before)
pbi_normalize_reportOne transaction per page. Atomic within each one, but if the third failed, the first two were left rearranged.workflows.py:273 (before)

And a third defect, at the commit boundary:

FlowWhat it did
txn._ProjectTransactionCM.__exit__Called commit() unprotected. If the commit itself failed (manifest, disk, permissions), the exception escaped without rolling back: the files stayed written and the operation looked failed.

Fixed in Phase D: pbir_writer.plan_visuals_bulk() and pbir_edit.plan_replace_visual_field() were factored out (pure, no writes), the two workflows now compile everything and write in one transaction, and __exit__ rolls back if the commit fails.

tests/test_workflow_atomicity.py injects failures on first / middle / last write, prior validation, commit and compensation, and requires byte-for-byte restoration and zero orphaned directories. Six of those tests fail against the previous commit.

It also includes two static checks: a lexical one (transaction inside a for) and one that covers the blind spot: a loop that calls a function that opens its own transaction.

Also verified: exactly 1 SaveChanges per function, 7 in total, counting AST Call nodes and not text occurrences — a grep counts 6 in set_columns_hidden_bulk because the docstring mentions it. The original R13 claim holds.

R13 (single-destination atomicity): closed. All flows targeting the same destination are single transactions or a single SaveChanges.


7 bis. R15 — dual consistency: OPEN

This risk is not closed and will not be closed in Phase 1A. It's a system limit.

ModeRequirementStatus
livePower BI Desktop open and valid session✅ Available
pbipProject closed or verifiably safe✅ Available
bothMutually incompatible requirements🚫 Blocked in 1A

live talks to msmdsrv.exe, which only exists if Desktop is open. pbip writes files that Desktop overwrites on save, so the strict policy blocks it if Desktop is open or unknown. There is no system state in which both destinations can be safely written in a single call.

What it used to do: apply live first, then pbip. With Desktop open — the only state in which live is possible — the result was a deterministic partial state: 1 SaveChanges executed, column hidden in memory, disk untouched, consistent: False.

Now: the six dual tools reject mode="both" with dual_mode_not_safely_available before any effect — before connecting to TOM, validating against the engine, creating a journal, reading to plan, or touching a file. No environment-variable bypass.

The six: pbi_create_measure, pbi_update_measure, pbi_delete_measure, pbi_set_column_visibility, pbi_hide_columns, pbi_set_relationship_direction.

The compensated coordinator is still there, as an internal mechanism

_apply_both_compensated() in tools/model_edit_tools.py implements disk→memory with compensation. It's not reachable from the public tool and doesn't justify accepting both. It's kept with direct unit tests because Phase 1B will have to decide between: a two-stage workflow, persisting only via TOM and letting the user save, abandoning both, or another safe coordination.

Coordinator error taxonomy

CodeWhenRequires intervention
bulk_apply_failedIt failed and compensation left everything as it wasNo
bulk_partially_appliedCompensation was left incomplete or in conflictYes, with the journal

"Partial" is never reported when the restoration was complete.

How to audit this yourself

Don't trust the list above. The five patterns to search for:

# 1. A decorated tool calling another decorated tool
grep -rn "@mcp.tool" -A40 src/tools/ | grep -E "pbi_[a-z_]+\("
# 2. Writes inside loops
grep -rnE "for |while " -A6 src/ | grep -E "write_|SaveChanges|create_page"
# 3. Transactions opened inside loops  ← the bad pattern
grep -rn "project_transaction\|with transaction" src/
# 4. Multiple SaveChanges in the same function
grep -rn "SaveChanges" src/powerbi/
# 5. backup_before_edit (doesn't restore; only for unmigrated paths)
grep -rn "backup_before_edit" src/

A for inside a transaction is correct. A transaction inside a for is not.

Never make a tool call another decorated tool. guard() turns errors into data: the loop continues, the outer result says ok:true and the failures stay buried in the list. Extract an undecorated service and have both tools wrap it.

Don't mark any risk as closed without a regression test that fails before the fix and passes after.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.