- Go 100%
lichen-publish #
A shared, portable Go publisher for explicit public Markdown sources targeting Lichen wikis. Source releases are immutable commits. Consumers verify the pinned source archive checksum before building. Hosted publishing is enabled only after that consumer’s acceptance checks pass.
The Social Wire integration tracks issue #380. Other projects should use the same reviewed release rather than copying the publisher.
Install with Homebrew #
brew tap samclemente/tap https://tangled.org/samclemente.me/homebrew-tap
brew install samclemente/tap/lichen-publish
lichen-publish --version
The tap builds the tagged release from its SHA-256-verified source archive. No GitHub mirror or prebuilt bottle is required. Update with brew update followed by brew upgrade samclemente/tap/lichen-publish.
Build and verify #
Go 1.27 or newer is required. ATProto OAuth uses the official Indigo SDK pinned in go.mod and go.sum.
go test ./...
go vet ./...
go build -o lichen-publish .
The checked-in Tangled workflow runs tests, vet, and build on pushes and pull requests to main. It has no publisher credentials and performs no remote writes. Its first hosted run is still required to verify the CI environment.
Local commands #
Run against a source repository with an explicit JSON manifest:
lichen-publish --validate --root /path/to/source --config lichen.json
lichen-publish --dry-run --root /path/to/source --config lichen.json
--validate reads local sources only. Dry run is the default and reads remote public wiki state without changing it. Neither command authenticates or publishes records.
Publishing and adoption require a durable journal location. Adoption records a reviewed remote baseline locally; it performs no remote writes:
lichen-publish --adopt --root /path/to/source --config lichen.json \
--state /private/durable/lichen-state.json
Use --adopt only after comparing the existing page identity, contents, and head with the intended import. Keep a backup of the journal before adopting or reconciling anything.
A handle alone signs in with OAuth. Passing a password explicitly selects password authentication instead:
lichen-publish samclemente.me
lichen-publish --handle samclemente.me --password "$APP_PASSWORD"
The CLI prints a browser authorization URL and listens on a random loopback port for the callback. OAuth requests only create access to Lichen note and revision records. Sessions and their DPoP keys are saved in a private local configuration directory; --session /private/path/oauth-session.json selects a different location. Reused sessions refresh through the discovered authorization server. --login explicitly reauthorizes. A supplied password is never persisted; command-line passwords can appear in process listings, so prefer LICHEN_APP_PASSWORD for unattended password use.
Publishing uses the saved OAuth session by default. A handle can authorize a session when none exists. --pds is an optional identity check against the discovered PDS, not an authentication destination override:
lichen-publish --publish --serialized-run --root /path/to/source --config lichen.json \
--state /private/durable/lichen-state.json --pds https://publisher-pds.example \
--commit COMMIT_SHA --message 'Documentation update'
For unattended password authentication, set LICHEN_IDENTIFIER and LICHEN_APP_PASSWORD using a secret manager or CI secret injection. Avoid password arguments where possible, and never put credentials in manifests, source, artifacts, or logs. Both OAuth and password flows require live acceptance for the selected publishing identity. Do not enable a Production write job until this has been tested with the actual PDS and a dedicated contributor identity. Browser OAuth credentials must not be extracted or repurposed for this CLI.
--appview defaults to https://lichen.wiki. API origins require HTTPS, except loopback HTTP for local testing; credentials in URLs and redirects are refused.
Manifest and identities #
The manifest has version: 1 and a publications array. Each publication has a stable id, a target (owner, slug, uri, verified), an optional navigation Markdown path, and an explicit pages array. Each page has a stable id, repository-relative source, immutable Lichen slug, and optional existingNoteUri for reviewed adoption. See the integration manifest in The Social Wire for a full example.
Preserve page IDs when moving source files. Preserve wiki AT-URIs, note AT-URIs, and slugs. The public allowlist is exact: an unlisted file is never published. _Sidebar.md is deliberately configured as navigation and maps to the special _sidebar note. Removed sources are not deleted remotely; reconcile the manifest and journal explicitly. A new target wiki must already exist, and its owner/URI and publisher permissions must be verified.
Relative Markdown and wikilinks resolve only to approved pages, with fragments retained. Links to excluded files must use reviewed canonical external URLs. Images/assets are rejected rather than uploaded implicitly. The parser supports simple inline Markdown link syntax, not every Markdown extension; validate the actual output for complex documents.
Revision and recovery contract #
The protocol was inspected at Lichen source commit 56e39aade82d19615c78527bc4c2062e864b6602 and its wiki.lichen lexicons. The official @lichen-wiki/client package is a useful protocol reference; it is not this CLI.
Lichen stores note identities as wiki.lichen.note records with TID keys. Notes reference immutable wiki identities, and revisions reference both the note and previous revision. wiki.lichen.getNote returns the reconstructed body byte for byte and the accepted head; the publisher does not treat a raw revision's diff as the current Markdown. Existing diff-match-patch histories remain intact. The publisher writes full-text revisions, which Lichen ingests only when parentRevision is its current head. Git attribution belongs in the supported revision message, not invented schema fields.
New note and initial revision records are created in one PDS applyWrites request. Existing notes receive an incremental full-text revision. Identical content and title need no revision. A publish confirms that Lichen accepted the exact expected head and contents; PDS success alone is not publication success.
A pending operation's fixed TIDs and timestamp must remain in the journal across retries. Canonical PDS records are checked before replay: identical records are recognized, different data or partial records require reconciliation. Do not delete the journal, generate new IDs, or retry a fresh operation after a timeout. Read the PDS and Lichen state first. A timeout may mean ingestion has not caught up or rejected the attempted revision.
The full-text head check is enforced atomically by Lichen ingestion. It is not a cross-contributor PDS compare-and-swap: a rejected attempt can remain in the publisher's PDS. The CLI must fail on competing heads and never silently replace manual edits. It does not delete pages, revisions, or history, and does not sync Lichen edits back into Git.
Lichen's official client also writes contributor snapshots for recovery if contributors disappear. This implementation preserves existing snapshots but does not create new ones; retention of the publishing identity and its revision history is therefore required. Snapshot/backfill acceptance remains part of the shared publisher's release review.
For local tests, --serialized-run asserts an external exclusive lock. Hosted runs use --state-remote, --state-branch, and --run-id instead: the CLI acquires an atomic Git lease and restores a durable encrypted journal and OAuth session. It checkpoints both before PDS writes and before a refreshed token can authorize a retry. Different runners cannot acquire the same active lease. A lost checkpoint stops publishing and retains the lease for explicit recovery.
The state remote contains only AES-256-GCM ciphertext. Inject LICHEN_STATE_KEY as a base64 32-byte key and configure Git transport with a dedicated write identity and pinned SSH host keys. Never store the encryption key or plaintext OAuth session in Git or build artifacts.
Bootstrap once from reviewed local state:
lichen-publish --bootstrap-state --root /path/to/source --config lichen.json \
--state-remote git@tangled.org:owner/lichen-publish --state-branch ci-state/project \
--run-id operator-bootstrap --import-session /private/oauth-session.json \
--import-journal /private/reviewed.state.json
An imported journal is optional for a new project. --adopt with those remote-state flags establishes an explicitly reviewed baseline without remote Lichen writes. --publish uses the encrypted session noninteractively; it forbids local authentication overrides. Preserve IDs and restore the original source when retrying a pending write.
Leases never expire automatically. After inspecting a crashed run and the current remote state commit, pass --recover-state-commit FULL_SHA on an operator invocation to reclaim exactly that observed lease without losing pending operations. Never force-push the state branch or reset it to an earlier snapshot. Rotate keys by stopping all publishers and re-encrypting the latest journal/session under a new key; retain protected recovery material until a successful run is confirmed.
--source-commit SHA --source-branch main --source-remote origin rechecks protected source before each PDS mutation. Moved source fails safely. Git itself is the lease authority; ambiguous pushes are accepted only after exact remote-ref readback.
Publisher provisioning #
Use a separate ATProto account with contributor membership on each target wiki. The wiki owner grants membership; the publisher checks getWiki with the publishing DID and refuses writes unless viewer.canWrite is true. A successful PDS login does not prove wiki membership or ingestion acceptance.
Provision an app password only after verifying that the selected PDS supports the required noninteractive record operations. Store it as a Tangled repository secret, available solely to trusted default-branch publishing jobs. Never expose write secrets to pull requests or fork builds. Rotate by provisioning a replacement password, testing against the test wiki, replacing the injected secret, then revoking the old password. Revoke wiki membership and PDS app passwords to stop publishing; preserve the account's historical records for recovery.
Release blockers #
Before publishing a pinned, integrity-verified release or enabling any Production write workflow:
- Demonstrate the authentication flow using a dedicated publisher and test wiki.
- Verify creation, one changed-page revision, zero-revision identical reruns, journaled partial-failure recovery, and safe concurrent manual-edit rejection in Lichen's actual page/history UI.
- Verify snapshot/backfill recovery expectations and the current protocol against the running AppView.
- Verify shared durable state and serialization across overlapping CI workers.
- Review, tag, build, and publish immutable binaries with checksums; configure integrations to verify both version and integrity.
- Verify the actual Tangled hosted jobs and secret boundaries.
The public test wiki https://lichen.wiki/@samclemente.me/social-wire-publisher-test was created separately for acceptance work. Its existence does not verify CLI authentication or publishing. Production publishing remains disabled pending the evidence above.
OAuth Session Handling #
The loopback client uses the official ATProto OAuth profile: account/PDS and authorization-server discovery, mandatory PAR, PKCE, callback state and issuer validation, and DPoP-bound tokens. This local sign-in profile must be verified separately before any hosted CI session policy is enabled.
The session file contains refresh tokens and the DPoP private key. Its directory must be private (0700), the file must be 0600, and neither may be a symlink. Keep it outside Git and artifacts. A process lock covers the loaded session so rotating refresh tokens cannot race between CLI processes. The original client identity is retained for refresh. Refresh persistence failures stop further authenticated requests.
To switch accounts, select another --session path or explicitly use --login. Revoke the grant at the account provider when retiring a session; deleting a local file alone does not revoke the server grant. Never copy a personal OAuth session into CI without an explicit account/session policy and verified publisher access.
Versioned Releases #
VERSION is the release version embedded in the binary. From v0.1.1 onward, lichen-publish --version reports it without reading configuration or authenticating. Tags use vMAJOR.MINOR.PATCH; never move an existing release tag. Historical v0.1.0 remains pinned for the current Social Wire CI consumer until that integration deliberately upgrades.
For each release, update VERSION, run tests/vet/build, commit the reviewed source on a feature branch, publish it to Tangled, and tag that exact commit after hosted verification. Tagged CI verifies that the tag matches VERSION and that the built binary reports the same version. Update the Homebrew formula’s tag URL and downloaded-archive SHA-256, then run its install and functional test before publishing the tap update.