# Publish a ledger

Publish a local ledger for shared contributions, retaining a local copy; optionally publish a replica while retaining local authority.

Capability: op_sys_ledgers_publish
Protocol: op-sys.capabilities.v1
Runtime: 0.3.0
Availability: Local + configured shared service
Optional integration: false
Canonical page: /docs/reference/op_sys_ledgers_publish

## Authority

Publishing in shared mode explicitly transfers authority; synchronization and copy mode do not. Every exchange checks current permissions.

## Invocation

CLI, SDK and MCP use the same operation and arguments; where a hosted HTTP binding exists, its route carries the same domain contract. Host paths and environment references refer to the runtime host. Illustrative example. Use your own resource identifiers and inputs while preserving the operation’s schema.

### CLI

```sh
op-sys --output json tools call op_sys_ledgers_publish \
  --arguments '{"ledger_id":"ledger_11111111111111111111111111111111","connection":"work"}'
```

### Python SDK

```python
import json
from op_sys import OpSys

client = OpSys()
arguments = json.loads("{\"ledger_id\":\"ledger_11111111111111111111111111111111\",\"connection\":\"work\"}")
result = client.capabilities.call(
    "op_sys_ledgers_publish", arguments
)
print(result)
```

### MCP (initialized connection)

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "op_sys_ledgers_publish",
    "arguments": {
      "ledger_id": "ledger_11111111111111111111111111111111",
      "connection": "work"
    }
  }
}
```

Named CLI command: op-sys ledgers publish (use --help for flags).

SDK convenience: client.ledgers.publish(…). The capability adapter may wrap the result.

## Parameters

### ledger_id

Required; string. Stable ledger identity, local or hosted. A display name is not interchangeable with this ID.

minLength: 1; maxLength: 128

### connection

Optional; string. 

minLength: 1; maxLength: 128

### endpoint

Optional; string. 

minLength: 1; maxLength: 2048

### tenant_id

Optional; string. Workspace ID in the service API. The service checks access for the authenticated caller.

minLength: 1; maxLength: 128

### remote

Optional; string. 

minLength: 1; maxLength: 128

### mode

Optional; string. 

Allowed: "shared", "copy"

### grant_mappings

Optional; array. 

maxItems: 1000
```json
{
  "type": "array",
  "maxItems": 1000,
  "items": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
      "source": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "issuer": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048
          },
          "subject": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          }
        },
        "required": [
          "issuer",
          "subject"
        ]
      },
      "target": {
        "anyOf": [
          {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "issuer": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2048
              },
              "subject": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256
              }
            },
            "required": [
              "issuer",
              "subject"
            ]
          },
          {
            "type": "null"
          }
        ]
      }
    },
    "required": [
      "source",
      "target"
    ]
  }
}
```


### max_items

Optional; integer. 

minimum: 1; maximum: 100

### max_pages

Optional; integer. 

minimum: 1; maximum: 100

### max_file_chunks

Optional; integer. 

minimum: 0; maximum: 1024

### no_browser

Optional; boolean. 



### Complete input schema

```json
{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "ledger_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "connection": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "endpoint": {
      "type": "string",
      "minLength": 1,
      "maxLength": 2048
    },
    "tenant_id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "remote": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128
    },
    "mode": {
      "type": "string",
      "enum": [
        "shared",
        "copy"
      ]
    },
    "grant_mappings": {
      "type": "array",
      "maxItems": 1000,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "source": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "issuer": {
                "type": "string",
                "minLength": 1,
                "maxLength": 2048
              },
              "subject": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256
              }
            },
            "required": [
              "issuer",
              "subject"
            ]
          },
          "target": {
            "anyOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "issuer": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2048
                  },
                  "subject": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 256
                  }
                },
                "required": [
                  "issuer",
                  "subject"
                ]
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "source",
          "target"
        ]
      }
    },
    "max_items": {
      "type": "integer",
      "minimum": 1,
      "maximum": 100
    },
    "max_pages": {
      "type": "integer",
      "minimum": 1,
      "maximum": 100
    },
    "max_file_chunks": {
      "type": "integer",
      "minimum": 0,
      "maximum": 1024
    },
    "no_browser": {
      "type": "boolean"
    }
  },
  "required": [
    "ledger_id"
  ]
}
```

## Behavior

- Shared mode transfers authority to the selected service and retains a local replica. Copy mode retains local authority.
- Publishing remembers a remote and does not make the ledger public or invite participants.
- Repeat the same request to resume. Other local principals require explicit grant mappings.
- Publish or clone a URL to establish a remote automatically; edit connections and remotes for advanced control.
- Synchronize accepted history, referenced files and eligible contributions explicitly.
- Inspect outcomes before retrying uncertain writes.

## Response

A resumable setup or publishing result. Only state=published means publishing has completed.

### Complete result JSON Schema

```json
{
  "anyOf": [
    {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "state": {
          "const": "setup_required"
        },
        "connection": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "setup": {
          "type": "object"
        },
        "next_action": {
          "const": "authenticate"
        }
      },
      "required": [
        "state",
        "setup",
        "next_action"
      ]
    },
    {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "ledger_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "connection": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "remote": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "url": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2048
        },
        "mode": {
          "type": "string",
          "enum": [
            "shared",
            "copy"
          ]
        },
        "state": {
          "type": "string",
          "enum": [
            "synchronizing",
            "transferring",
            "resolve_grants",
            "published"
          ]
        },
        "next_action": {
          "type": "string",
          "enum": [
            "publish",
            "resolve_grants",
            "none"
          ]
        },
        "sync": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "ledger_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "context_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "contributions": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "operation_id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 128
                  },
                  "state": {
                    "type": "string",
                    "enum": [
                      "unsent",
                      "in_flight",
                      "uncertain",
                      "rejected",
                      "accepted",
                      "withdrawn"
                    ]
                  },
                  "recovery": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 256
                  },
                  "diagnostic": {
                    "type": "string",
                    "maxLength": 128
                  }
                },
                "required": [
                  "operation_id",
                  "state",
                  "recovery"
                ]
              },
              "maxItems": 1000
            },
            "remaining": {
              "anyOf": [
                {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                {
                  "type": "null"
                }
              ]
            },
            "files_remaining": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "observation": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "source": {
                  "type": "string",
                  "enum": [
                    "authority",
                    "replica"
                  ]
                },
                "authority_epoch": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "observed_at": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 64
                },
                "coverage": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 4096
                },
                "complete": {
                  "type": "boolean"
                },
                "provenance": {
                  "const": "imported-unverified"
                }
              },
              "required": [
                "source",
                "authority_epoch",
                "observed_at",
                "coverage",
                "complete"
              ]
            },
            "state": {
              "type": "string",
              "enum": [
                "snapshot",
                "changes",
                "files",
                "caught_up",
                "denied",
                "resnapshot_required"
              ]
            },
            "direction": {
              "type": "string",
              "enum": [
                "pull",
                "push"
              ]
            },
            "pages_processed": {
              "type": "integer",
              "minimum": 0
            },
            "records_retained": {
              "type": "integer",
              "minimum": 0
            },
            "next_action": {
              "type": "string",
              "enum": [
                "synchronize",
                "none",
                "reauthenticate"
              ]
            }
          },
          "required": [
            "ledger_id",
            "context_id",
            "contributions",
            "remaining",
            "files_remaining",
            "observation",
            "state",
            "direction",
            "pages_processed",
            "records_retained",
            "next_action"
          ]
        },
        "transfer": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "transfer_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "ledger_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            },
            "phase": {
              "type": "string",
              "enum": [
                "prepared",
                "fenced",
                "ready",
                "activated",
                "completed"
              ]
            },
            "source": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 128
                },
                "epoch": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "state": {
                  "type": "string",
                  "enum": [
                    "active",
                    "fenced",
                    "deleted"
                  ]
                }
              },
              "required": [
                "id",
                "epoch",
                "state"
              ]
            },
            "destination": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 128
                },
                "epoch": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "state": {
                  "type": "string",
                  "enum": [
                    "active",
                    "fenced",
                    "deleted"
                  ]
                }
              },
              "required": [
                "id",
                "epoch",
                "state"
              ]
            },
            "unresolved_grants": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "issuer": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 2048
                  },
                  "subject": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 256
                  }
                },
                "required": [
                  "issuer",
                  "subject"
                ]
              },
              "maxItems": 1000
            },
            "request_digest": {
              "type": "string"
            },
            "progress": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "received": {
                  "type": "integer",
                  "minimum": 0
                },
                "total": {
                  "anyOf": [
                    {
                      "type": "integer",
                      "minimum": 0
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "received",
                "total"
              ]
            },
            "barrier": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "position": {
                  "type": "integer",
                  "minimum": 0
                },
                "items": {
                  "type": "integer",
                  "minimum": 0
                },
                "digest": {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                }
              },
              "required": [
                "position",
                "items",
                "digest"
              ]
            },
            "next_action": {
              "enum": [
                "resolve_grants",
                "resume",
                "none"
              ]
            },
            "ledger": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "ledger_id": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 128
                },
                "name": {
                  "anyOf": [
                    {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 256
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "metadata": {
                  "type": "object"
                },
                "revision": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 9007199254740991
                },
                "lifecycle": {
                  "type": "string",
                  "enum": [
                    "active",
                    "archived",
                    "deleted"
                  ]
                },
                "authority": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "id": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 128
                    },
                    "epoch": {
                      "type": "integer",
                      "minimum": 1,
                      "maximum": 9007199254740991
                    },
                    "state": {
                      "type": "string",
                      "enum": [
                        "active",
                        "fenced",
                        "deleted"
                      ]
                    }
                  },
                  "required": [
                    "id",
                    "epoch",
                    "state"
                  ]
                },
                "admitted_contracts": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "contract_id": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 128
                      },
                      "version": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 128
                      },
                      "digest": {
                        "type": "string",
                        "pattern": "^[a-f0-9]{64}$"
                      }
                    },
                    "required": [
                      "contract_id",
                      "version",
                      "digest"
                    ]
                  },
                  "maxItems": 64
                },
                "default_contract": {
                  "anyOf": [
                    {
                      "type": "object",
                      "additionalProperties": false,
                      "properties": {
                        "contract_id": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 128
                        },
                        "version": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 128
                        },
                        "digest": {
                          "type": "string",
                          "pattern": "^[a-f0-9]{64}$"
                        }
                      },
                      "required": [
                        "contract_id",
                        "version",
                        "digest"
                      ]
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "state_rules": {
                  "type": "array",
                  "maxItems": 32,
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "contract": {
                        "type": "object",
                        "additionalProperties": false,
                        "properties": {
                          "contract_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 128
                          },
                          "version": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 128
                          },
                          "digest": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{64}$"
                          }
                        },
                        "required": [
                          "contract_id",
                          "version",
                          "digest"
                        ]
                      },
                      "key_field": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 256
                      },
                      "state_field": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 256
                      },
                      "version_field": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 256
                      },
                      "transitions": {
                        "type": "array",
                        "maxItems": 32,
                        "items": {
                          "type": "object",
                          "additionalProperties": false,
                          "properties": {
                            "field": {
                              "type": "string",
                              "minLength": 1,
                              "maxLength": 256
                            },
                            "initial": {
                              "type": "array",
                              "minItems": 1,
                              "maxItems": 64,
                              "items": {
                                "type": "string",
                                "minLength": 1,
                                "maxLength": 256
                              }
                            },
                            "edges": {
                              "type": "array",
                              "maxItems": 256,
                              "items": {
                                "type": "array",
                                "minItems": 2,
                                "maxItems": 2,
                                "items": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 256
                                }
                              }
                            }
                          },
                          "required": [
                            "field",
                            "initial",
                            "edges"
                          ]
                        }
                      }
                    },
                    "required": [
                      "contract",
                      "key_field",
                      "state_field",
                      "version_field",
                      "transitions"
                    ]
                  }
                },
                "search": {
                  "type": "object",
                  "additionalProperties": false,
                  "properties": {
                    "enabled": {
                      "type": "boolean",
                      "default": true
                    },
                    "excluded_paths": {
                      "type": "array",
                      "maxItems": 64,
                      "uniqueItems": true,
                      "items": {
                        "type": "string",
                        "maxLength": 1024,
                        "pattern": "^(|/.*)$"
                      },
                      "description": "JSON Pointer paths excluded with their descendants. Payload paths for records; /name and /metadata for ledger discovery. Does not change admission or read permissions."
                    }
                  }
                }
              },
              "required": [
                "ledger_id",
                "name",
                "metadata",
                "revision",
                "lifecycle",
                "authority",
                "admitted_contracts",
                "default_contract"
              ],
              "allOf": [
                {
                  "if": {
                    "properties": {
                      "lifecycle": {
                        "enum": [
                          "active",
                          "archived"
                        ]
                      }
                    }
                  },
                  "then": {
                    "properties": {
                      "default_contract": {
                        "type": "object",
                        "additionalProperties": false,
                        "properties": {
                          "contract_id": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 128
                          },
                          "version": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 128
                          },
                          "digest": {
                            "type": "string",
                            "pattern": "^[a-f0-9]{64}$"
                          }
                        },
                        "required": [
                          "contract_id",
                          "version",
                          "digest"
                        ]
                      }
                    }
                  }
                }
              ]
            }
          },
          "required": [
            "transfer_id",
            "ledger_id",
            "phase",
            "source",
            "destination",
            "unresolved_grants"
          ]
        }
      },
      "required": [
        "ledger_id",
        "connection",
        "remote",
        "url",
        "mode",
        "state",
        "next_action"
      ]
    }
  ]
}
```


[Runtime output field catalog](/docs/output-contracts.json) (descriptive contracts, not JSON Schema validators).

CLI: use --output json. For tools call, read the operation result at payload.tool.result; payload.tool.name identifies the capability. The outer envelope is {schema_version: "v1", payload: {tool: {name, result}}}.

Python: client.capabilities.call(name, arguments) returns the operation result. SDK exceptions preserve reason and code.

MCP: tools/call returns JSON text and structuredContent. Application failures set isError; inspect reason/code instead of matching message text.

No standalone response JSON Schema is published for this operation. The input schema is not a response contract.

## Errors and recovery

[Ledger limits and operation catalog](/docs/ledger-core.json)

Canonical operation: ledgers.publish

Permissions: authority.transfer, destination.context_create

Retry: resume; concurrency: none

Codes: invalid_input, contract_invalid, payload_invalid, contract_not_admitted, permission_denied, not_found, revision_conflict, operation_conflict, unsupported, authority_unavailable, outcome_uncertain, outcome_expired, validation_context_unavailable, file_unavailable, integrity_failure, ledger_archived, ledger_deleted, resnapshot_required, identity_changed, authority_fenced, withdrawal_requires_resolution, limit_exceeded, rate_limited, payment_required

[HTTP status mappings and schemas](/docs/ledger-core.openapi.json)

- resnapshot_required: Discard incomplete coverage and begin a new snapshot.

Family reasons are representative, not exhaustive.

A timeout is not proof that a write failed. Reuse the documented retry identity, batch, offset or mutation ID. If this operation has no documented retry identity, inspect its state before repeating it.

On authorization failure, correct the configured identity or grants; do not change the local actor to impersonate a hosted principal. On validation failure, correct the input against the published schema and selected contract.

On a revision or state conflict, retrieve current state and reconcile intent. Do not automatically overwrite a competing update. Preserve unknown additive response fields when building consumers.

## Source manuals

- [shared-records](/docs/raw/manuals/shared-records.md)
- [public-capabilities](/docs/raw/manuals/public-capabilities.md)
- [command-output-schema](/docs/raw/manuals/command-output-schema.md)
