@a5c-ai/krate 5.0.1-staging.f672fe79b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/Dockerfile +29 -0
  2. package/README.md +183 -0
  3. package/bin/krate-demo.mjs +23 -0
  4. package/bin/krate-server.mjs +14 -0
  5. package/dist/krate-controller-ui.json +2407 -0
  6. package/dist/krate-lifecycle.json +201 -0
  7. package/dist/krate-runtime-snapshot.json +2955 -0
  8. package/dist/krate-summary.json +687 -0
  9. package/docs/README.md +61 -0
  10. package/docs/agents/README.md +83 -0
  11. package/docs/agents/acceptance-test-matrix.md +193 -0
  12. package/docs/agents/agent-mux-adapter-contract.md +167 -0
  13. package/docs/agents/agent-mux-source-map.md +310 -0
  14. package/docs/agents/agent-run-memory-import-spec.md +256 -0
  15. package/docs/agents/agent-stack-management-spec.md +421 -0
  16. package/docs/agents/api-contract-spec.md +309 -0
  17. package/docs/agents/artifacts-writeback-spec.md +145 -0
  18. package/docs/agents/chart-packaging-spec.md +128 -0
  19. package/docs/agents/ci-orchestration-spec.md +140 -0
  20. package/docs/agents/context-assembly-spec.md +219 -0
  21. package/docs/agents/controller-reconciliation-spec.md +255 -0
  22. package/docs/agents/crd-schema-spec.md +315 -0
  23. package/docs/agents/decision-log-open-questions.md +169 -0
  24. package/docs/agents/developer-implementation-checklist.md +329 -0
  25. package/docs/agents/dispatching-design.md +262 -0
  26. package/docs/agents/glossary.md +66 -0
  27. package/docs/agents/implementation-blueprint.md +324 -0
  28. package/docs/agents/implementation-rollout-slices.md +251 -0
  29. package/docs/agents/memory-context-integration-spec.md +194 -0
  30. package/docs/agents/memory-ontology-schema-spec.md +253 -0
  31. package/docs/agents/memory-operations-runbook.md +121 -0
  32. package/docs/agents/mvp-vertical-slice-spec.md +146 -0
  33. package/docs/agents/observability-audit-spec.md +265 -0
  34. package/docs/agents/operator-runbook.md +174 -0
  35. package/docs/agents/org-memory-api-payload-examples.md +333 -0
  36. package/docs/agents/org-memory-controller-sequence-spec.md +181 -0
  37. package/docs/agents/org-memory-e2e-fixture-plan.md +161 -0
  38. package/docs/agents/org-memory-ui-implementation-map.md +114 -0
  39. package/docs/agents/org-memory-vertical-slice-spec.md +168 -0
  40. package/docs/agents/org-resource-model-delta-spec.md +111 -0
  41. package/docs/agents/org-route-resource-model-spec.md +183 -0
  42. package/docs/agents/org-scoping-namespace-spec.md +114 -0
  43. package/docs/agents/rbac-secrets-management-spec.md +406 -0
  44. package/docs/agents/repository-page-integration-spec.md +255 -0
  45. package/docs/agents/resource-contract-examples.md +808 -0
  46. package/docs/agents/resource-relationship-map.md +190 -0
  47. package/docs/agents/security-threat-model.md +188 -0
  48. package/docs/agents/shared-memory-company-brain-spec.md +358 -0
  49. package/docs/agents/storage-migration-spec.md +168 -0
  50. package/docs/agents/subagent-orchestration-spec.md +152 -0
  51. package/docs/agents/system-overview.md +88 -0
  52. package/docs/agents/tools-mcp-skills-spec.md +189 -0
  53. package/docs/agents/traceability-matrix.md +79 -0
  54. package/docs/agents/ui-flow-spec.md +211 -0
  55. package/docs/agents/ui-ux-system-spec.md +426 -0
  56. package/docs/agents/workspace-lifecycle-spec.md +166 -0
  57. package/docs/architecture-spec.md +78 -0
  58. package/docs/components/control-plane.md +78 -0
  59. package/docs/components/data-plane.md +69 -0
  60. package/docs/components/hooks-events.md +67 -0
  61. package/docs/components/identity-rbac-policy.md +73 -0
  62. package/docs/components/kubevela-oam.md +70 -0
  63. package/docs/components/operations-publishing.md +81 -0
  64. package/docs/components/runners-ci.md +66 -0
  65. package/docs/components/web-ui.md +94 -0
  66. package/docs/external/README.md +47 -0
  67. package/docs/external/bidirectional-sync-design.md +134 -0
  68. package/docs/external/cicd-interface.md +64 -0
  69. package/docs/external/external-backend-controllers.md +170 -0
  70. package/docs/external/external-backend-crds.md +234 -0
  71. package/docs/external/external-backend-ui-spec.md +151 -0
  72. package/docs/external/external-backend-ux-flows.md +115 -0
  73. package/docs/external/external-object-mapping.md +125 -0
  74. package/docs/external/git-forge-interface.md +68 -0
  75. package/docs/external/github-integration-design.md +151 -0
  76. package/docs/external/issue-tracking-interface.md +66 -0
  77. package/docs/external/provider-capability-manifests.md +204 -0
  78. package/docs/external/provider-catalog.md +139 -0
  79. package/docs/external/provider-rollout-testing.md +78 -0
  80. package/docs/external/research-results.md +48 -0
  81. package/docs/external/security-auth-permissions.md +81 -0
  82. package/docs/external/sync-state-machines.md +108 -0
  83. package/docs/external/unified-external-backend-model.md +107 -0
  84. package/docs/external/user-facing-changes.md +67 -0
  85. package/docs/gaps.md +161 -0
  86. package/docs/install.md +94 -0
  87. package/docs/krate-design.md +334 -0
  88. package/docs/local-minikube.md +55 -0
  89. package/docs/ontology/README.md +32 -0
  90. package/docs/ontology/bounded-contexts.md +29 -0
  91. package/docs/ontology/events-and-hooks.md +32 -0
  92. package/docs/ontology/oam-kubevela.md +32 -0
  93. package/docs/ontology/operations-and-release.md +25 -0
  94. package/docs/ontology/personas-and-actors.md +32 -0
  95. package/docs/ontology/policies-and-invariants.md +33 -0
  96. package/docs/ontology/problem-space.md +30 -0
  97. package/docs/ontology/resource-contracts.md +40 -0
  98. package/docs/ontology/resource-taxonomy.md +42 -0
  99. package/docs/ontology/runners-and-ci.md +29 -0
  100. package/docs/ontology/solution-space.md +24 -0
  101. package/docs/ontology/storage-and-data-boundaries.md +29 -0
  102. package/docs/ontology/validation-matrix.md +24 -0
  103. package/docs/ontology/web-ui-excellent-flows.md +32 -0
  104. package/docs/ontology/workflows.md +39 -0
  105. package/docs/ontology/world.md +35 -0
  106. package/docs/product-requirements.md +62 -0
  107. package/docs/roadmap-mvp.md +87 -0
  108. package/docs/system-requirements.md +90 -0
  109. package/docs/tests/README.md +53 -0
  110. package/docs/tests/agent-qa-plan.md +63 -0
  111. package/docs/tests/browser-ui-tests.md +62 -0
  112. package/docs/tests/ci-quality-gates.md +48 -0
  113. package/docs/tests/coverage-model.md +64 -0
  114. package/docs/tests/e2e-scenario-tests.md +53 -0
  115. package/docs/tests/fixtures-test-data.md +63 -0
  116. package/docs/tests/observability-reliability-tests.md +54 -0
  117. package/docs/tests/product-test-matrix.md +145 -0
  118. package/docs/tests/qa-adoption-roadmap.md +130 -0
  119. package/docs/tests/qa-automation-plan.md +101 -0
  120. package/docs/tests/security-compliance-tests.md +57 -0
  121. package/docs/tests/test-framework-tools.md +88 -0
  122. package/docs/tests/test-suite-layout.md +121 -0
  123. package/docs/tests/unit-integration-tests.md +48 -0
  124. package/docs/todo-kyverno +714 -0
  125. package/docs/user-stories.md +78 -0
  126. package/examples/minikube-demo.yaml +190 -0
  127. package/examples/oam-application.yaml +23 -0
  128. package/examples/policy-kyverno-pr-title.yaml +18 -0
  129. package/package.json +63 -0
  130. package/scripts/build.mjs +29 -0
  131. package/scripts/setup-minikube.mjs +65 -0
  132. package/scripts/smoke.mjs +37 -0
  133. package/scripts/validate-doc-coverage.mjs +152 -0
  134. package/scripts/validate-package.mjs +93 -0
  135. package/scripts/validate-ui.mjs +207 -0
  136. package/src/agent-approval-controller.js +123 -0
  137. package/src/agent-context-bundles.js +242 -0
  138. package/src/agent-dispatch-controller.js +86 -0
  139. package/src/agent-mux-client.js +280 -0
  140. package/src/agent-permission-review.js +162 -0
  141. package/src/agent-stack-controller.js +296 -0
  142. package/src/agent-trigger-controller.js +108 -0
  143. package/src/api-controller.js +206 -0
  144. package/src/argocd-gitops.js +43 -0
  145. package/src/auth.js +265 -0
  146. package/src/component-catalog.js +41 -0
  147. package/src/control-plane.js +136 -0
  148. package/src/controller-client.js +38 -0
  149. package/src/controller-ui.js +538 -0
  150. package/src/data-plane.js +178 -0
  151. package/src/gitea-backend.js +95 -0
  152. package/src/handoff.js +98 -0
  153. package/src/hooks-events.js +63 -0
  154. package/src/http-server.js +151 -0
  155. package/src/identity-policy.js +86 -0
  156. package/src/index.js +30 -0
  157. package/src/kubernetes-controller.js +812 -0
  158. package/src/kubernetes-resource-gateway.js +48 -0
  159. package/src/operations.js +112 -0
  160. package/src/resource-model.js +203 -0
  161. package/src/runners-ci.js +48 -0
  162. package/src/runtime.js +196 -0
  163. package/src/web-ui.js +40 -0
  164. package/tests/agent-approval-controller.test.js +173 -0
  165. package/tests/agent-context-bundles.test.js +278 -0
  166. package/tests/agent-dispatch-controller.test.js +176 -0
  167. package/tests/agent-mux-client.test.js +204 -0
  168. package/tests/agent-permission-review.test.js +209 -0
  169. package/tests/agent-resources.test.js +212 -0
  170. package/tests/agent-stack-controller.test.js +221 -0
  171. package/tests/agent-trigger-controller.test.js +211 -0
  172. package/tests/deployment.test.js +395 -0
  173. package/tests/e2e/lifecycle.test.js +117 -0
  174. package/tests/krate.test.js +727 -0
@@ -0,0 +1,94 @@
1
+ # Web UI Component Requirements
2
+
3
+ ## Purpose
4
+
5
+ The Web UI makes Kubernetes-native forge concepts usable without hiding them. It provides developer-grade PR, code, CI, hooks, policy, and triage workflows while exposing the YAML and `kubectl` equivalent for every mutation.
6
+
7
+ ## Responsibilities
8
+
9
+ - Render repositories, code, PRs, issues, pipelines, runners, hooks, policies, insights, and settings.
10
+ - Fetch data from the Kubernetes and aggregated APIs without a separate forge backend.
11
+ - Stream resource changes through Watch API to SSE.
12
+ - Provide GitOps-transparent mutation panels.
13
+ - Preserve RBAC semantics by carrying user identity to the API server.
14
+
15
+ ## Information architecture
16
+
17
+ Org-scoped sections:
18
+
19
+ - Repositories
20
+ - Inbox
21
+ - Runs
22
+ - Runners
23
+ - Hooks & Policies
24
+ - Insights
25
+ - Settings
26
+
27
+ Per-repository sections:
28
+
29
+ - Code
30
+ - Pull Requests
31
+ - Issues
32
+ - Runs
33
+ - Hooks
34
+ - Settings
35
+
36
+ ## Requirements
37
+
38
+ - Use Next.js App Router and Server Components for primary data fetching.
39
+ - Use route handlers for `/api/watch/orgs/[org]/*` SSE streams.
40
+ - Use `/api/git-proxy` to stream smart-HTTP to the Gitea backend where needed.
41
+ - Use Monaco or CodeMirror for code and diff views.
42
+ - Every mutating action must include a stable `</>` affordance showing YAML, kubectl command, copy-as-apply, and save/open PR options where relevant.
43
+ - Every detail page should include a YAML tab.
44
+ - Saved views must map to `View` or `Selector` resources.
45
+
46
+ ## Dependencies
47
+
48
+ - Aggregated API server and CRDs.
49
+ - OIDC and TokenRequest integration.
50
+ - Gitea backend.
51
+ - Watch API.
52
+ - Optional Kyverno/Gatekeeper policy metadata.
53
+
54
+ ## Security and policy
55
+
56
+ - The UI must not implement a shadow permission model.
57
+ - Disabled or hidden actions must still be backed by API authorization outcomes.
58
+ - Token handling must keep user credentials out of client-side JavaScript where possible.
59
+ - Mutating route handlers must call the same API path as generated YAML apply.
60
+
61
+ ## Scaling and performance
62
+
63
+ - Watch streams should avoid polling for PR, comment, pipeline, and webhook state.
64
+ - Large diffs and logs must virtualize rendering.
65
+ - Route handlers must apply backpressure for long-lived SSE and Git proxy streams.
66
+
67
+ ## Failure modes
68
+
69
+ - Watch disconnect: UI reconnects and resumes from current list state.
70
+ - RBAC denied: UI shows actionable denied status and resource/verb context.
71
+ - API unavailable: UI shows degraded state with correlation IDs.
72
+ - Git proxy failure: code/clone/push flows surface data-plane health.
73
+
74
+ ## Observability
75
+
76
+ - Web vitals, API route latency, watch connection count, SSE reconnects, denied action count, Git proxy errors, mutation success/failure.
77
+
78
+ ## Acceptance criteria
79
+
80
+ - Repo list, file view, PR list, and PR detail render from API resources.
81
+ - PR/pipeline state updates through SSE without manual refresh.
82
+ - Mutating forms expose YAML and `kubectl apply` equivalents.
83
+ - Runner live view streams logs and pod event hints.
84
+
85
+ ## Implemented forge navigation proof
86
+
87
+ The Next.js console now treats YAML as transparency rather than the default user journey:
88
+
89
+ - Global pages render breadcrumbs, degraded-state banners, and direct navigation for repositories, PRs/issues, pipelines, runners, hooks, insights, operations, and the YAML workbench.
90
+ - The dashboard and repository landing render a `ForgeFlowRail` for the developer path: create, clone, branch, open PR, merge, deploy, and notify.
91
+ - Repository subpages render a `RepositoryCommandBar` with clone, branch, watch, RBAC, PR-flow, and YAML affordances before the code, pull request, issue, pipeline, hook, and settings tabs.
92
+ - The architecture map exposes the `krate-api-controller`, `kubernetes-resource-gateway`, `kubernetes-resource-client`, `krate-kubernetes-reconciler`, and `git-data-plane` lanes so users can understand what owns UI/API flow versus Kubernetes reconciliation.
93
+
94
+ `npm run ui:validate` checks these route-flow and architecture-boundary affordances, and `npm run ui:build` proves every app route compiles in the production Next.js build.
@@ -0,0 +1,47 @@
1
+ # External backend integration docs
2
+
3
+ ## Purpose
4
+
5
+ This directory defines how Krate should integrate with GitHub first and support other externally managed backends later. External backends can implement one, two, or all three Krate provider interfaces:
6
+
7
+ 1. issue tracking and work management sync;
8
+ 2. CI/CD, triggers, runners, pipelines, checks, and workflow sync;
9
+ 3. git forge sync for repositories, pull requests, refs, commits, SSH/deploy keys, collaborators, and repository policy.
10
+
11
+ The design supports bidirectional, efficient sync without forcing every backend to be a full forge.
12
+
13
+ ## Documents
14
+
15
+ - [Research results](./research-results.md) summarizes GitHub API and webhook capabilities used by this design.
16
+ - [Pluggable backend provider catalog](./provider-catalog.md) lists GitHub, GitLab, Bitbucket, Azure DevOps, Jira, Linear, Buildkite, CircleCI, Jenkins, Gitea, Gerrit, raw Git, and custom providers by supported interface.
17
+
18
+ - [Unified external backend model](./unified-external-backend-model.md) defines provider capabilities, ownership, identifiers, sync modes, and the three interface split.
19
+ - [Provider capability manifests](./provider-capability-manifests.md) defines data-driven adapter manifests for operations, auth, webhooks, and tests.
20
+ - [External object mapping spec](./external-object-mapping.md) defines loss-aware mappings from provider objects to Krate resources.
21
+
22
+ - [Issue tracking interface](./issue-tracking-interface.md) defines issue/comment/label/milestone/project/work-item sync.
23
+ - [CI/CD interface](./cicd-interface.md) defines workflow/check/pipeline/job/runner/trigger sync.
24
+ - [Git forge interface](./git-forge-interface.md) defines repository/PR/ref/commit/key/collaborator/policy sync.
25
+ - [GitHub integration design](./github-integration-design.md) maps GitHub App, REST, GraphQL, webhooks, and Actions onto the three interfaces.
26
+ - [Efficient bidirectional sync](./bidirectional-sync-design.md) defines webhook-first, cursor-based, idempotent reconciliation and conflict handling.
27
+ - [External sync state machines](./sync-state-machines.md) defines stable phases for providers, bindings, deliveries, backfill, writes, and conflicts.
28
+
29
+ - [External backend CRDs](./external-backend-crds.md) defines resources and schemas.
30
+ - [External backend controllers](./external-backend-controllers.md) defines reconciliation loops and side effects.
31
+ - [User-facing changes](./user-facing-changes.md) defines UI, settings, status, and workflow changes.
32
+ - [External backend UI specification](./external-backend-ui-spec.md) defines org-scoped provider setup, bindings, sync health, conflicts, write intents, webhook, and repository UI.
33
+ - [External backend UX flows](./external-backend-ux-flows.md) defines user-facing setup, mixed-provider, conflict, write approval, recovery, and rate-limit flows.
34
+
35
+
36
+ - [Security, auth, and permissions](./security-auth-permissions.md) defines GitHub App auth, tokens, secrets, RBAC, and audit.
37
+ - [Provider rollout and testing](./provider-rollout-testing.md) defines implementation slices, validation, and QA coverage.
38
+
39
+ ## Design principles
40
+
41
+ - Krate keeps its org namespace and resource model; external backends are providers, not the source of Krate tenancy.
42
+ - Providers declare which interfaces they support.
43
+ - Every external object stores provider ID, native ID, global node ID when available, URL, etag/cursor, and last synced generation.
44
+ - Webhooks are the primary freshness mechanism; polling/backfill repairs missed or truncated events.
45
+ - Krate can run in mirror mode, bidirectional mode, or Krate-owned mode per interface and resource type.
46
+ - Conflicts are explicit resources and UI states, not silent overwrites.
47
+ - Secrets and provider tokens stay in Kubernetes Secrets and are surfaced only as grant metadata.
@@ -0,0 +1,134 @@
1
+ # Efficient bidirectional sync design
2
+
3
+ ## Purpose
4
+
5
+ External backends need efficient two-way sync that converges quickly without overwriting user changes or exhausting provider rate limits. This document defines the common sync strategy for all provider interfaces.
6
+
7
+ ## Sync layers
8
+
9
+ | Layer | Purpose |
10
+ | --- | --- |
11
+ | Webhook ingest | near-real-time event capture and trigger source. |
12
+ | Event normalizer | convert provider payloads into canonical Krate sync events. |
13
+ | Cursor backfill | recover missed events and hydrate lists. |
14
+ | Object reconciler | compare desired/local/provider state and write projections. |
15
+ | Write intent queue | apply Krate-originated writes to provider with retries. |
16
+ | Conflict detector | detect local/external divergence. |
17
+ | Audit/event stream | explain every sync and write. |
18
+
19
+ ## Sync resource model
20
+
21
+ ```yaml
22
+ kind: ExternalSyncState
23
+ spec:
24
+ organizationRef: a5c
25
+ providerRef: github-a5c
26
+ bindingRef: github-krate
27
+ interface: gitForge
28
+ resourceKind: PullRequest
29
+ status:
30
+ highWatermark: 2026-05-11T12:00:00Z
31
+ cursor: opaque-provider-cursor
32
+ lastWebhookDeliveryId: "..."
33
+ lastFullBackfillAt: 2026-05-11T00:00:00Z
34
+ phase: Ready
35
+ ```
36
+
37
+ ```yaml
38
+ kind: ExternalSyncConflict
39
+ spec:
40
+ organizationRef: a5c
41
+ providerRef: github-a5c
42
+ resourceRef:
43
+ kind: Issue
44
+ name: issue-42
45
+ fieldConflicts:
46
+ - field: labels
47
+ local: [bug, priority]
48
+ external: [bug]
49
+ resolutionPolicy: manual
50
+ ```
51
+
52
+ ## Event processing
53
+
54
+ ```text
55
+ provider webhook
56
+ -> validate signature
57
+ -> persist ExternalWebhookDelivery
58
+ -> enqueue by provider installation and repository
59
+ -> normalize into ExternalSyncEvent
60
+ -> dedupe by delivery ID + action + native object ID
61
+ -> apply object-specific reconcile
62
+ -> update Krate projection and sync state
63
+ -> emit audit and watch event
64
+ ```
65
+
66
+ ## Backfill processing
67
+
68
+ ```text
69
+ scheduled or manual backfill
70
+ -> read ExternalSyncState cursor/highWatermark
71
+ -> list changed objects from provider
72
+ -> hydrate missing details
73
+ -> upsert Krate projections
74
+ -> mark deleted/missing objects according to tombstone policy
75
+ -> update cursor/highWatermark
76
+ ```
77
+
78
+ ## Write processing
79
+
80
+ ```text
81
+ Krate user/agent action
82
+ -> admission and RBAC
83
+ -> create ExternalWriteIntent
84
+ -> optional approval
85
+ -> provider write through connector
86
+ -> verify provider response
87
+ -> update local projection with provider IDs/version
88
+ -> wait for webhook or backfill confirmation
89
+ -> close write intent
90
+ ```
91
+
92
+ ## Efficiency rules
93
+
94
+ - Prefer webhook payloads for targeted updates.
95
+ - Use GraphQL/cursor pagination for bulk list hydration where supported.
96
+ - Use REST endpoints for provider-specific operations and logs/artifacts.
97
+ - Store ETag or provider resource version when available.
98
+ - Batch by installation/org/repository to respect rate limits.
99
+ - Lazy-load large logs, diffs, artifacts, and comments.
100
+ - Apply bounded retries with dead-letter status for repeated provider errors.
101
+ - Separate sync freshness from user-facing last-updated time.
102
+
103
+ ## Conflict rules
104
+
105
+ Conflict when:
106
+
107
+ - local desired generation changed after last sync and provider field also changed;
108
+ - provider rejects a write because native version/precondition changed;
109
+ - provider has a value Krate cannot represent losslessly;
110
+ - ownership mode says external-owned and Krate has pending local mutation;
111
+ - write intent remains unconfirmed beyond timeout.
112
+
113
+ Resolution options:
114
+
115
+ - prefer external;
116
+ - prefer Krate desired;
117
+ - manual merge;
118
+ - create reviewed provider-side change;
119
+ - ignore unsupported field with warning.
120
+
121
+ ## Deletion and tombstones
122
+
123
+ - External deletions become tombstones before local deletion when audit requires retention.
124
+ - Krate deletions in mirror mode should not delete provider objects.
125
+ - Krate-owned resources may delete provider objects if admission and provider permissions allow it.
126
+ - PR/issue deletion may be unsupported in some providers; close/archive instead.
127
+
128
+ ## Acceptance criteria
129
+
130
+ - Webhook replay and backfill converge to the same resource state.
131
+ - Duplicate webhooks are idempotent.
132
+ - Rate-limit responses slow sync without losing events.
133
+ - Conflicts are visible in UI and API.
134
+ - Writes are auditable from Krate action to provider confirmation.
@@ -0,0 +1,64 @@
1
+ # CI/CD interface
2
+
3
+ ## Purpose
4
+
5
+ The CI/CD interface syncs external workflow/check/pipeline state into Krate and can trigger or control external runs when allowed. It covers workflows, workflow runs, jobs, logs, artifacts, checks, commit statuses, runner groups, and self-hosted runners.
6
+
7
+ ## Provider contract
8
+
9
+ ```ts
10
+ interface CicdProvider {
11
+ listPipelines(cursor): Page<ExternalPipeline>;
12
+ getPipeline(ref): ExternalPipeline;
13
+ listJobs(pipelineRef, cursor): Page<ExternalJob>;
14
+ getJobLog(jobRef): ExternalLogRef;
15
+ listArtifacts(pipelineRef, cursor): Page<ExternalArtifact>;
16
+ rerunPipeline(ref, options): ExternalPipeline;
17
+ cancelPipeline(ref): ExternalPipeline;
18
+ listRunners(cursor): Page<ExternalRunner>;
19
+ registerRunner(scope, options): RunnerRegistration;
20
+ createCheck(input): ExternalCheck;
21
+ updateCheck(ref, patch): ExternalCheck;
22
+ }
23
+ ```
24
+
25
+ Providers can implement checks/statuses without implementing runner management.
26
+
27
+ ## Resource mapping
28
+
29
+ | External concept | Krate resource/projection |
30
+ | --- | --- |
31
+ | workflow/workflow definition | `PipelineTemplate` projection or provider metadata |
32
+ | workflow run/pipeline | `Pipeline` |
33
+ | job/step | `Job` |
34
+ | check run/status | `CheckRun` projection or `Job.status.checks` |
35
+ | runner | `RunnerPool` / `Runner` projection |
36
+ | artifact/log | `Artifact` / object-storage reference |
37
+ | trigger event | `WebhookDelivery` / `ExternalSyncEvent` |
38
+
39
+ ## GitHub mapping
40
+
41
+ GitHub Actions workflow runs map to `Pipeline`; workflow jobs map to `Job`; check runs and commit statuses map to check projections and PR gates. GitHub self-hosted runners map to runner inventory and runner registration flows when Krate is allowed to manage them.
42
+
43
+ ## Sync rules
44
+
45
+ - Webhooks handle `workflow_run`, `workflow_job`, `check_run`, `check_suite`, `status`, and `push` events.
46
+ - Backfill periodically lists workflow runs/jobs by repository and updated timestamp.
47
+ - Logs and artifacts are lazy-loaded and stored by digest or external URL depending on retention policy.
48
+ - Rerun/cancel actions require permission review and provider capability.
49
+ - External runner registration tokens are short-lived and never stored as plain status.
50
+
51
+ ## User-facing changes
52
+
53
+ - Repository Runs page shows external pipelines next to Krate-native runs.
54
+ - Run detail badges show external provider and native link.
55
+ - Rerun/cancel buttons are disabled unless provider and RBAC allow them.
56
+ - Runner pages distinguish Krate-managed, provider-managed, and mirrored runners.
57
+ - Agent triggers can subscribe to external CI failure events through the same trigger rule model.
58
+
59
+ ## Acceptance criteria
60
+
61
+ - A CI-only provider can sync pipelines/jobs without repo/issue ownership.
62
+ - GitHub workflow jobs converge through webhook and backfill.
63
+ - Logs/artifacts are fetched lazily and redacted according to policy.
64
+ - Rerun/cancel actions are audited and idempotent.
@@ -0,0 +1,170 @@
1
+ # External backend controllers
2
+
3
+ ## Purpose
4
+
5
+ External backend controllers reconcile provider configuration, webhook deliveries, backfill, object projection, writes, conflicts, and status.
6
+
7
+ ## Controller set
8
+
9
+ | Controller | Responsibilities |
10
+ | --- | --- |
11
+ | provider controller | validate auth, capabilities, installation access, rate limits, and status. |
12
+ | binding controller | validate target refs, create provider webhooks, initialize sync states. |
13
+ | webhook controller | validate signatures, persist deliveries, enqueue events, support replay. |
14
+ | sync controller | process events/backfills and update Krate projections. |
15
+ | write controller | apply Krate write intents to provider, retry, confirm, audit. |
16
+ | conflict controller | detect field/resource conflicts and manage resolution workflow. |
17
+ | runner/controller adapter | manage external CI runners when provider supports it. |
18
+ | garbage/tombstone controller | handle external deletions and retention. |
19
+
20
+ ## Reconciliation order
21
+
22
+ ```text
23
+ ExternalBackendProvider
24
+ -> auth/capability check
25
+ -> ExternalBackendBinding
26
+ -> webhook registration and sync state initialization
27
+ -> webhook events and backfill
28
+ -> Krate resource projections
29
+ -> write intents and conflicts
30
+ ```
31
+
32
+ ## Provider controller
33
+
34
+ - Resolve org namespace and Secret refs.
35
+ - Validate provider type and base URLs.
36
+ - Verify credentials without storing token values.
37
+ - Discover capabilities where possible.
38
+ - Track rate-limit status and degraded state.
39
+ - Emit `AuthReady`, `InstallationReady`, and interface readiness conditions.
40
+
41
+ ## Binding controller
42
+
43
+ - Validate target resource belongs to same org.
44
+ - Validate provider supports requested interfaces.
45
+ - Create/update provider webhooks when Krate owns webhook configuration.
46
+ - Create initial `ExternalSyncState` objects.
47
+ - Kick off initial backfill.
48
+
49
+ ## Webhook controller
50
+
51
+ - Validate HMAC/signature before accepting payload.
52
+ - Persist `ExternalWebhookDelivery` with provider delivery ID.
53
+ - Dedupe repeated deliveries.
54
+ - Enqueue normalized `ExternalSyncEvent`.
55
+ - Return quickly and process asynchronously.
56
+ - Support manual replay/redelivery records.
57
+
58
+ ## Sync controller
59
+
60
+ - Hydrate provider objects from webhook payload or API.
61
+ - Upsert Krate resources/projections with external identity fields.
62
+ - Maintain high-watermarks and cursors.
63
+ - Respect ownership mode.
64
+ - Mark tombstones for external deletions.
65
+ - Emit watch and audit events.
66
+
67
+ ## Write controller
68
+
69
+ - Reads `ExternalWriteIntent` after Krate admission and optional approval.
70
+ - Applies provider write with provider-specific idempotency where available.
71
+ - Handles rate limits and retryable failures.
72
+ - Confirms via provider response, webhook, or follow-up read.
73
+ - Creates conflict if provider state diverged.
74
+
75
+ ## Controller acceptance criteria
76
+
77
+ - Controllers are idempotent by provider, installation, interface, native object ID, and delivery/write ID.
78
+ - Provider outage degrades sync without corrupting Krate state.
79
+ - Cross-org references fail before provider calls.
80
+ - Secret/token values never enter status, events, logs, or sync payloads.
81
+ - Webhook replay and cursor backfill converge.
82
+
83
+ ## Interface adapter controllers
84
+
85
+ Each interface has a provider-neutral reconciler and provider-specific adapter methods.
86
+
87
+ ### Issue sync controller
88
+
89
+ Responsibilities:
90
+
91
+ - watch issue-related webhooks;
92
+ - backfill issues, comments, labels, milestones, project fields;
93
+ - upsert `Issue` projections;
94
+ - link PR-backed issue numbers to `PullRequest`;
95
+ - process issue write intents;
96
+ - detect comment/label/state conflicts.
97
+
98
+ ### CI/CD sync controller
99
+
100
+ Responsibilities:
101
+
102
+ - watch workflow/check/status events;
103
+ - backfill pipelines, jobs, checks, logs, artifacts;
104
+ - upsert `Pipeline` and `Job` projections;
105
+ - lazy-fetch logs/artifacts on demand;
106
+ - process rerun/cancel/check update write intents;
107
+ - sync runner inventory where supported.
108
+
109
+ ### Git forge sync controller
110
+
111
+ Responsibilities:
112
+
113
+ - watch repository, PR, review, push, branch/tag, key, collaborator, and protection events;
114
+ - backfill repos, pull requests, refs, branch protection, keys, collaborators;
115
+ - upsert `Repository`, `PullRequest`, `Review`, `SSHKey`, `RepositoryPermission`, `BranchProtection`, and `RefPolicy` projections;
116
+ - process PR, merge, key, collaborator, and branch protection writes;
117
+ - detect force-push and stale diff/check state.
118
+
119
+ ## Provider adapter lifecycle
120
+
121
+ ```text
122
+ load provider descriptor
123
+ -> validate configured interfaces
124
+ -> create adapter client with scoped credentials
125
+ -> run health/capability probe
126
+ -> start webhook/backfill loops
127
+ -> expose provider operations to sync/write controllers
128
+ ```
129
+
130
+ ## Rate-limit handling
131
+
132
+ Controllers should:
133
+
134
+ - bucket requests by provider, installation/account, org, and repository;
135
+ - preserve webhook deliveries even when rate limited;
136
+ - pause backfill before write intents when budget is low;
137
+ - expose `RateLimited` conditions with reset time;
138
+ - avoid retry storms by using exponential backoff and jitter.
139
+
140
+ ## Provider plugin contract
141
+
142
+ Future provider plugins should implement:
143
+
144
+ ```ts
145
+ interface ExternalProviderAdapter {
146
+ descriptor(): ProviderDescriptor;
147
+ health(): ProviderHealth;
148
+ issueTracking?: IssueTrackingProvider;
149
+ cicd?: CicdProvider;
150
+ gitForge?: GitForgeProvider;
151
+ normalizeWebhook(payload): NormalizedExternalEvent[];
152
+ verifyWebhook(request): VerificationResult;
153
+ }
154
+ ```
155
+
156
+ The core controllers own persistence, org checks, queueing, conflicts, and audit; adapters only translate provider operations.
157
+
158
+ ## Controller status surfaces
159
+
160
+ Provider and binding status should expose:
161
+
162
+ - interface readiness;
163
+ - last successful webhook;
164
+ - last failed webhook;
165
+ - last backfill by interface;
166
+ - queue depth;
167
+ - rate limit remaining/reset;
168
+ - conflicts count;
169
+ - pending write count;
170
+ - last provider error class.