Skip to content

CI core: the control repo (cross-repo dispatch, project records, reconcile) for terragucci and plywood #4568

Closed

Description

@lex00

terragucci holds the control repo today. Under the placement rule (chant#4530, docs concepts/ci-products) it is shared capability, and plywood needs it for plywood#18.

terragucci's pieces, at origin/main:

  • packages/terragucci/src/control-repo.ts: a member's dispatch after a default-branch apply (repository_dispatch, GitLab pipeline trigger, Forgejo workflow dispatch), and the control repo's pipeline running chant workspace run --dependents-of <member> --op <op>.
  • packages/terragucci/src/control-records.ts: projects and shared defaults as control-entry workspace records, read and written through chant workspace records.
  • packages/terragucci/src/reconcile.ts: bring each project's pipeline in line with the records; dry run by default, --mode apply opens a pull request per project and never writes a default branch.

Placement:

  • chant CI core: the dispatch for each forge, the control-entry record kind, and reconcile over the product pipeline (chant#4550), taking each product's generator as input.
  • products: the words, the project settings each product writes, and their docs. terragucci's Terraform provider for the control repo stays in terragucci.

Order: after chant#4550 and chant#4554. terragucci moves onto it under terragucci#1282; plywood uses it in plywood#18.

Related: chant#4530, chant#4550, chant#4551, chant#4554, terragucci#1280, terragucci#1282, plywood#18, plywood#24.

Activity

  1. added
    epic:ci-products
    epic:plywood
    on Oct 27, 2026
  2. lex00 commented on Oct 27, 2026

    @lex00
    ContributorAuthor

    Landed on integration/ci-products: merge bb599f2 (unit branch unit/cp-chant-4568, commit b648b62). It builds on #4550 (words, productStatusContext, the pull request loop options), #4554 (forge clients with defaultBranch) and #4551 (records on the ledger). Typecheck and the docs prose lint pass on the merged tree with no regressions. No tests were run.

    Files:

    • packages/core/src/ci-control.ts, the entry @intentius/chant/ci-control, with CI_CONTROL_FLOOR = NEXT_RELEASE
    • packages/core/src/control/dispatch.ts, records.ts, reconcile.ts, control.test.ts
    • packages/core/src/components/pr-pipeline.ts: a control option on PrLoopPipelineOptions
    • lexicons/github/src/components/generate-pipeline.ts and lexicons/gitlab/src/components/generate-pipeline.ts: the control-dispatch job (Forgejo gets it through the github generator)
    • lexicons/{github,gitlab,forgejo}/src/components/control-pipeline.ts: generateControlPipeline for the control repo's own file
    • lexicons/{github,gitlab}/src/components/generate-pr-pipeline.control.test.ts
    • docs/src/content/docs/concepts/ci-products.mdx: a control repo section

    Dispatch per forge. resolveControlTarget(settings, fallbackMember) takes { repo, op, forge?, member?, tokenSecret?, readTokenSecret?, ref?, apiBase? }, checks it with controlSettingsProblems (terragucci's rules), and settles the forge from the host. controlDispatchRequest(target, { member, op, sha }, words) builds one request: POST /repos/<path>/dispatches with event type <product>-applied on GitHub, POST /projects/<id>/trigger/pipeline with CHANT_CONTROL_MEMBER, CHANT_CONTROL_OP and CHANT_CONTROL_SHA on GitLab, and POST /repos/<path>/actions/workflows/<product>-dependents.yml/dispatches on Forgejo. Two senders use it. dispatchControl sends it in process for a product's bin, and controlDispatchScript is the generated step. The step reads the token from CHANT_CONTROL_TOKEN and pipes it to curl on stdin (-H @-, or --form token=<- on GitLab). terragucci's script put it in curl's argv. sentCheck and markSent take the product's shell lines for the idempotency mark terragucci does with terragucci post sent and post status. controlStatusContext(words) gives <product>/control.

    Generated jobs. With prLoop.control = { target, sentCheck?, markSent? } and applyOnMerge (or a wave gate), the GitHub, Forgejo and GitLab pipelines add a control-dispatch job that needs the last apply job and runs on the green path. The applied commit is the last wave's green-sha (GitLab: $GREEN_SHA), else the green commit. On GitHub and Forgejo the product's secret is mapped into CHANT_CONTROL_TOKEN for that one step. On GitLab a CI/CD variable reaches every job, so the plan job's script unsets CONTROL_TOKEN_VARS and the product's two secret names along with the forge tokens. The control repo's file comes from generateControlPipeline({ words, image?, command? }) in each forge lexicon, built from controlPipelineSpec. It runs npx --no-install chant workspace run --dependents-of "$member" --op "$op" --json after checking both names, one member at a time.

    Control-entry records. They are lines of _control/entries.jsonl on the control repo's chant/lifecycle, appended through appendLedgerLine under the member prefix. No product git writes are involved. Each line is one version of one entry (version, kind: control-entry, id: ctl-NNN, entry: project|defaults, project, state: active|retired, settings, estates, product, at, by?, prev, digest). prev names the digest it replaces, so putControlEntry(..., { expect }) refuses a raced write (ControlEntryConflict) and a reader catches a broken chain. The API is readControlEntries(port, { validate }), putControlEntry, retireControlEntry, importControlConfig, controlConfig and estateClaims, with gitControlLedger({ cwd }) as the port. The product's validate checks its own settings. As with every ledger, nothing pushes; call pushLifecycleReport after.

    Reconcile. reconcileProjects(projects, { mode, words, generate, env, git?, forgeFor?, fetch? }) clones each project and calls the product's generate(dir, { key, name, forge, settings, dryRun }). A dry run reports. An apply pushes <product>/pipeline and opens a pull request against the forge's default branch, or edits the open one. It never writes a default branch. The token comes from the project's tokenEnv, else CHANT_<FORGE>_TOKEN, and reaches git as an http.extraheader in the environment. describeReconcile prints the outcomes.

    For terragucci#1282 part d: control-repo.ts maps ControlSettings (token_env to tokenSecret, read_token_env to readTokenSecret) onto resolveControlTarget. It then calls controlDispatchScript or passes prLoop.control, and generateControlPipeline replaces controlPipeline. control-records.ts becomes readControlEntries, putControlEntry, retireControlEntry and estateClaims over gitControlLedger, with validateConfig as validate. reconcile.ts keeps init and writeGenerated as its generate and calls reconcileProjects. Every import needs a feature-detect on @intentius/chant/ci-control until a release carries it. One change lands at the switch: a control repo's record files move onto the ledger through importControlConfig, and terragucci needs a migration command for that.

    For plywood#18: control in plywood.yml maps onto ControlSettingsInput and goes in as prLoop.control. plywood control init writes generateControlPipeline({ words }) for the control repo's forge. Approvers and pins live in the entries' settings, written with putControlEntry and checked by plywood's validate. Reconcile runs reconcileProjects with plywood's init as the generator.

    Still missing:

    • The ledger table. chant ledger and chant query do not read _control/entries.jsonl yet. That would be a control_entries table under the read contract's floor rule.
    • No chant CLI command sends a dispatch or reconciles. Products call the API from their bins, by the placement rule.
    • The control repo's read checkout for estate ownership (terragucci's controlCheckoutStep and controlCloneScript) stays in terragucci. Since the entries are on the ledger now, that checkout fetches chant/lifecycle with CHANT_CONTROL_READ_TOKEN. Part d of terragucci#1282 should make that change.
    • The tests in packages/core/src/control/control.test.ts and the two lexicon tests, plus a run against two loopback fixture repos (plywood#18's acceptance), wait for epic-ready.
  3. lex00 commented on Oct 29, 2026

    @lex00
    ContributorAuthor

    Close-out (2026-10-29)

    Merged to main: bb599f2 (control repo in CI core: dispatch per forge, control-entry records, reconcile; unit commit b648b62). Follow-ups on main: f08af77 (control_entries table in read contract v1, in chant ledger and chant query), 61c0484 (consumers joined across a control repo), 2c6f4dd (control-repo dispatch after the last wave in Op waves).

    On origin/main: packages/core/src/control/dispatch.ts, records.ts and reconcile.ts. The ledger table the handoff listed as missing is there now. The issue has no checkboxes. The two-fixture-repo run (plywood#18 acceptance) is a harness run and is dropped under the 2026-10-29 ruling. terragucci's move onto this is terragucci#1282 and plywood's use is plywood#18, both tracked there.

    Closing: the shared capability is on main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    epic:ci-productsepic:plywood

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions