YERTLE-PYTHON — TODO
====================

Open items that are known, deliberate, and not yet fixed. Numbered entries are
permanent: refer to them by number.


1. `--format json` is not 1:1 with the backend response
-------------------------------------------------------

STATUS: open. Recorded 2026-09-22 while adding the `--format json` epilog to
the noun-group help pages.

THE GOAL

`--format json` should emit exactly what the API returned — same envelope, same
keys, same nesting, one command to one response. Today it emits the *SDK's*
view: whatever `.to_dict()` produces after `yertle.orgs` / `yertle.nodes` /
`yertle.search` have unwrapped and, in one case, recombined it.

Why it matters more than it used to: the end goal is for agents to drive this
CLI the way they drive an MCP server. An agent that learns the shape of
`yertle orgs show --format json` and then reads the OpenAPI spec finds two
different answers, and has no way to know which one is real. Divergence is
cheap for a human reading a table and expensive for a model building a mental
model of the API.

It also undercuts the habit `CLAUDE.md` names as the one that catches this
codebase's most expensive bugs: capturing real payloads into fixtures. A
fixture captured from `--format json` today is a fixture of the SDK, not of the
backend, and it will pass while the real wire shape drifts underneath it.

WHERE IT DIVERGES

  yertle orgs show        WORST — not a response at all.
                          `cli/commands/orgs.py::_merged` issues a SECOND
                          request to `/orgs` and copies `role` and
                          `member_count` onto the `/orgs/{id}` model. The JSON
                          is a composite that no single endpoint ever returned.
                          The comment there explains why (the two endpoints
                          populate disjoint field sets, and `show` displaying
                          less than `list` reads as a bug) — the real fix is
                          backend-side: make `/orgs/{id}` populate all three.

  yertle nodes list       Envelope dropped AND pages concatenated.
                          `nodes.py::list` loops `/orgs/{id}/nodes` at 50 per
                          page and returns a flat array. The wire shape is
                          `NodeListResponse{nodes, total, limit, offset}`; the
                          output is the bare `nodes` array of every page
                          stitched together. So the JSON corresponds to N
                          responses, not one, and `total`/`limit`/`offset` are
                          gone.

  yertle orgs list        Envelope dropped.
                          `orgs.py::list` returns `response.organizations`,
                          discarding `OrganizationListResponse.total`.
                          Deliberate for SDK callers (`total` is redundant with
                          `len()`), but the CLI inherits the unwrap.

  yertle nodes tree       Envelope dropped.
                          `nodes.py::tree` returns `response.entries`,
                          discarding `HierarchyResponse.total`. Single request,
                          so this one is only the envelope.

ALREADY 1:1 — DO NOT "FIX"

  yertle nodes show       `dump_json(state)` on the whole
                          `NodeCompleteStateResponse` from one request.

  yertle nodes search     `dump_json(result)` on the whole `RetrieveResponse`.
                          The `_path` field the table view folds in is injected
                          AFTER the JSON branch returns
                          (`cli/commands/nodes.py`), so it never reaches JSON.
                          Keep that ordering.

NOT A PROBLEM (verified 2026-09-22, do not re-investigate)

  Unknown fields survive. The generated models carry `additional_properties`,
  so a key the backend adds before the client is regenerated round-trips
  through `from_dict`/`to_dict` intact. Confirmed against
  `OrganizationResponse`. An earlier read of this assumed otherwise; it is
  wrong. The divergences above are structural only.

OPTIONS, NOT YET CHOSEN

  a) Keep the SDK unwrapping and have the CLI re-wrap for JSON output. Cheap,
     but it is a second place that knows the envelope shape, which is exactly
     the drift `CLAUDE.md` warns about.
  b) Have the SDK return the envelope and unwrap at the call site. Honest, but
     it taxes every library caller to serve the CLI, and `orgs.py`'s docstring
     argues the opposite on purpose.
  c) Add a separate passthrough path used only by `--format json`. Clean
     separation, but two code paths to one endpoint — the thing invariant 4
     exists to prevent.
  d) Leave the SDK alone and fix only `orgs show`, which is the one case that
     is actively misleading rather than merely reshaped. The envelope drops are
     lossy but not false.

  (d) is the smallest honest step and does not foreclose the others. Whichever
  is chosen, the backend fix to `/orgs/{id}` should land regardless — it is the
  root cause of the worst case here.

RELATED

  A `--debug`/`YERTLE_DEBUG` flag printing the raw HTTP exchange to stderr was
  discussed alongside this and is NOT built. It would answer "what did the
  backend actually send?" directly, via an httpx response event hook installed
  once in `shared/auth.py::get_client` (the generated client accepts
  `httpx_args`). That is a developer diagnostic and a separate concern from
  this item — it does not make `--format json` correct, it just makes the
  divergence visible.


2. Identifiers are raw UUIDs everywhere, and nothing shorter resolves
----------------------------------------------------------------------

STATUS: open. Recorded 2026-09-22 while adding Members / Nodes / Visibility /
Role to `orgs list`.

THE PROBLEM

Every id the CLI prints or accepts is a 36-character UUID. On an 80-column
terminal the id column alone is 45% of the width, which is why `orgs list` now
overflows and why `nodes list` hides its Org column when it can (see the
comment above `ORG_COLUMN` in `cli/commands/nodes.py`). It is also 36
characters to copy by hand every time you want `yertle orgs use <id>`.

The data already has a human-sized identifier. `/orgs` returns a `public_id`
alongside the UUID:

    "id":        "2c440b7a-d5bd-4f0d-9264-8da3195497af"
    "public_id": "pfc-9eebe379"

It is URL-friendly, stable, unique, and roughly a third of the width. The web
app already uses it in URLs.

WHAT IS BLOCKING IT (verified 2026-09-22 against prod)

  `yertle.orgs.get("pfc-9eebe379")`  ->  404 {"detail":"Organization not found"}
  `yertle.orgs.get("2c440b7a-...")`  ->  200 OK

So `/orgs/{id}` resolves UUIDs only. Printing `public_id` in the table today
would show an identifier that no other command accepts — strictly worse than
the UUID, however much better it looks.

THE WORK, IN ORDER

  a) BACKEND: have the path-parameter endpoints resolve either form —
     `/orgs/{id}` accepting `pfc-9eebe379` as well as the UUID. This is the
     load-bearing change; everything else is presentation. The same question
     applies to node ids, which have no public_id at all today and would need
     one (or a short-prefix scheme) to get the same treatment.

  b) CLI: relax `cli/_context.py::validate_org`, which currently hard-requires
     `UUID(value)` and is the single chokepoint every org-scoped command goes
     through. Accepting a `public_id` there is a small change once (a) lands.

  c) CLI: switch the `ID` column in `orgs list` to the short form, and revisit
     `ORG_COLUMN` in `nodes list`, which was suppressed for width alone.

INTERIM OPTION, IF (a) STALLS

  A git-style short prefix can be done entirely client-side: resolve an 8-char
  prefix against `yertle.orgs.list()` inside `validate_org`, and send the full
  UUID on the wire. It needs no backend change and would fit every column
  comfortably (a 6-column `orgs list` lands in ~64 columns with an 8-char id).
  The cost is one extra request to resolve, and prefix collisions to handle.
  Worth doing only if (a) is not happening soon — two identifier schemes is
  worse than one good one.

RELATED

  Item 1 above. `--format json` is unaffected by any of this: it dumps the
  full model, so the complete UUID stays available to scripts and agents no
  matter what the table shows.


3. CLI is read-only; write commands not yet built
---------------------------------------------------

STATUS: planned, not started. Recorded 2026-09-22.

See docs/cli/ROADMAP.md for the full plan. Summary:

  Phase 1  simple writes — nodes create/delete, branches, PRs. Flat request
           bodies, no shared state, no concurrency.
  Phase 2  one honest push layer. Everything state-shaped (edit, attach,
           connect, lay out) goes through `PUT .../tree/{branch}/push`, which
           is a FULL-STATE REPLACE with a required expected_head_commit.
           `nodes attach` is variadic from day one — many children, one push,
           one commit. A `--parent` flag on `create` was considered and
           rejected; see the roadmap for why.
  Phase 3  `yertle apply -f diagram.json` — declarative subtree authoring,
           which is what the push endpoint is natively shaped for. The read
           (`GET /complete`) returns `_branch_context.commit`, so a document
           produced by a read carries its own expected_head_commit; `apply`
           refuses one that does not. That makes read-before-write a
           precondition rather than an instruction, which is the closest a
           CLI gets to what an MCP tool description buys you.

THE ONE THING TO KNOW BEFORE TOUCHING ANY OF THIS

  There is no node update endpoint. Verified 2026-09-22: the complete set of
  node operations is create, delete, list, list-all, get-complete,
  get-canvas, get-branch-head, push. No PATCH, no PUT /nodes/{id}.

  So "edit a node's title" and "attach a child" are the SAME operation. Both
  are a full-state push, and a push that sends only the fields it means to
  change will silently delete the node's tags and directories while returning
  200 and a commit id.
