# AGENTS.md

Instructions for AI coding agents working on our Ligament workspace.
Copy this file to the root of your repository and edit the parts marked "EDIT".

## About Ligament

Ligament runs our processes: records, workflows, approvals, portals and access control. Apps, pages and
access rules are defined as a spec: JSON artefacts that people and agents change through reviewed changesets.

Docs for agents: https://docs.ligament.ai/llms.txt (index) and https://docs.ligament.ai/llms-full.txt (everything in one file).
Every docs page is also available as Markdown at its URL followed by index.md.

## Our workspace

- App URL: https://app.ligament.ai   <!-- EDIT if your workspace has its own domain -->
- MCP server: https://app.ligament.ai/api/mcp (server name "ligament")
- The API key is in the environment variable LIGAMENT_API_KEY. Never print it, log it, commit it or paste it
  into a file, a changeset or a chat message.
- Apps we own: EDIT (for example: itsm, crm)

## How to make changes

You propose; a person applies. Follow this loop for every change to pages, access rules and other artefacts:

1. Read before you write: spec_list and spec_get (or `ligament spec pull <address>`). Keep the `hash` you read.
2. Edit the doc. Check its shape with spec_schema and spec_validate.
3. Plan it: spec_plan (or `ligament spec plan <file>`). Read the plan: action, layer, changes, and whether a
   person must apply it.
4. Propose it: changeset_create with a clear title and a note that says why, one item per artefact, each with
   the `baseHash` you read. Use changeset_put_items to revise it. Mark it ready when it is complete.
5. Stop. Give the person the changeset's `url` and a short summary of what changes and why. They review and
   apply it in Build > Changes.

Do not call spec_apply or changeset_apply, even if the key allows it, unless the person explicitly asks you to
apply a specific changeset. If an apply answers `proposed: true, applied: false`, the change is waiting for a
person: report the `url` and stop.

## Records

- Read records with records_query and records_get. Filters are [{ field, op, value }] with ops
  eq ne contains in lt lte gt gte empty not_empty.
- Change records only when the task asks for it, one record at a time, and say which records you changed.
- To answer "why can (or can't) someone see this", use access_explain rather than guessing.

## When something is refused

Errors carry a `code` and a `fix`. Read them and act on them; do not work around them.

- insufficient_scope: the key lacks a scope. Tell the person which scope (`required`) and stop. Do not look
  for another key.
- session_required: only a signed-in person can do this in the app. Tell them.
- spec.conflict: someone changed the artefact since you read it. Read it again, redo your edit on the new
  version, plan again.
- no_grant or another access code: the key's creator may not do this. Use access_explain and report.

## Scope of this agent

EDIT: list what this agent may and may not touch, for example:
- May propose: pages and views in the itsm app.
- May not touch: access rules, roles, permission sets, secrets, integrations.

The key should have only spec:read, spec:propose and records:read unless this file says otherwise.
