@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,114 @@
1
+ # Org memory UI implementation map
2
+
3
+ ## Purpose
4
+
5
+ This document maps the org-scoped company brain and agent memory requirements onto the current Krate web app seams. It is docs-only and should guide implementation without changing code yet.
6
+
7
+ ## Current UI anchors
8
+
9
+ The app already has organization-first navigation and repository routes:
10
+
11
+ | Current file/route | Existing role |
12
+ | --- | --- |
13
+ | `apps/web/app/ui-shell.jsx` | shared app shell, org switcher, org navigation, repository navigation, `orgHref()` route helper. |
14
+ | `apps/web/app/orgs/page.jsx` | organization list. |
15
+ | `apps/web/app/orgs/[org]/page.jsx` | org dashboard. |
16
+ | `apps/web/app/orgs/[org]/repositories/page.jsx` | org repository list. |
17
+ | `apps/web/app/orgs/[org]/repositories/[repo]/code/page.jsx` | org-scoped code page. |
18
+ | `apps/web/app/orgs/[org]/repositories/[repo]/issues/page.jsx` | org-scoped issues page. |
19
+ | `apps/web/app/orgs/[org]/repositories/[repo]/pull-requests/page.jsx` | org-scoped reviews/PR page. |
20
+ | `apps/web/app/orgs/[org]/repositories/[repo]/runs/page.jsx` | org-scoped runs page. |
21
+ | `apps/web/app/orgs/[org]/repositories/[repo]/hooks/page.jsx` | org-scoped automations page. |
22
+ | `apps/web/app/orgs/[org]/repositories/[repo]/settings/page.jsx` | org-scoped repository settings. |
23
+ | `apps/web/app/orgs/[org]/deployments/page.jsx` | org-scoped deployment page. |
24
+ | `apps/web/app/orgs/[org]/runs/page.jsx` | org-level run center. |
25
+ | `apps/web/app/api/orgs/[org]/resources/*` | org-scoped resource API bridge. |
26
+
27
+ This means the future agent/memory work should extend the existing org route tree rather than introduce global `/agents` pages first.
28
+
29
+ ## Missing routes to add later
30
+
31
+ | Route | Purpose | Primary resources |
32
+ | --- | --- | --- |
33
+ | `/orgs/[org]/agents` | org agent dashboard | stacks, runs, approvals, memory health. |
34
+ | `/orgs/[org]/agents/stacks` | stack registry and builder | `AgentStack`, tools, MCP, skills, subagents. |
35
+ | `/orgs/[org]/agents/runs` | all org agent dispatches | `AgentDispatchRun`, attempts, sessions. |
36
+ | `/orgs/[org]/agents/runs/[run]` | CI-like run detail with Agent Mux chat | run, attempt, session, context, artifacts. |
37
+ | `/orgs/[org]/agents/rules` | trigger management | `AgentTriggerRule`, executions. |
38
+ | `/orgs/[org]/agents/workspaces` | workspace/session/work item management | `AgentWorkspace`, links. |
39
+ | `/orgs/[org]/agents/memory` | company brain dashboard | memory repo, ontology, imports, updates. |
40
+ | `/orgs/[org]/agents/memory/graph` | graph browser | graph records and edges. |
41
+ | `/orgs/[org]/agents/memory/search` | grep/frontmatter search | memory query. |
42
+ | `/orgs/[org]/agents/memory/imports` | `.a5c` and session import review | `AgentRunMemoryImport`. |
43
+ | `/orgs/[org]/agents/memory/updates` | memory update PR/review queue | `AgentMemoryUpdate`. |
44
+ | `/orgs/[org]/agents/permissions` | RBAC/secret/config/memory grants | grants and capability requirements. |
45
+
46
+ Repository pages should link into these routes with the active org and repo preserved in query params or source refs.
47
+
48
+ ## Navigation changes
49
+
50
+ Add an `Agents` top-level item to org navigation after `Runs` and before `Capacity`. The item should display attention counters for:
51
+
52
+ - running/failed agent dispatches;
53
+ - pending approvals;
54
+ - memory imports awaiting review;
55
+ - blocked stacks due to missing RBAC, secrets, config, or memory grants;
56
+ - stale memory ontology/index status.
57
+
58
+ The `Advanced` page should keep raw resource plans, but day-to-day agent and memory management belongs under `Agents`.
59
+
60
+ ## Repository page integrations
61
+
62
+ | Repository tab | Agent/memory additions |
63
+ | --- | --- |
64
+ | Code | dispatch agent from path/ref; include company brain records associated with path/repo; memory source preview. |
65
+ | Issues | linked sessions/workspaces/runs; issue-trigger dispatch; related memory runbooks and retrospectives. |
66
+ | Pull requests | failed-check repair dispatch; review artifacts; related decisions/runbooks; memory update suggestions. |
67
+ | Runs | merge CI pipeline rows with agent dispatch rows; link to Agent Mux chat/session. |
68
+ | Hooks | trigger dry-run and webhook-to-agent rule preview. |
69
+ | Settings | `AgentMemorySource`, stack defaults, trigger rules, permissions, secret/config/memory grants. |
70
+
71
+ ## Components to add later
72
+
73
+ | Component | Responsibility |
74
+ | --- | --- |
75
+ | `AgentDashboardPage` | org-level agent overview and attention cards. |
76
+ | `AgentRunDetailPage` | CI-like run timeline, Agent Mux chat, context, memory, artifacts. |
77
+ | `MemoryDashboardPage` | company brain health, current commit, ontology, imports, updates. |
78
+ | `MemoryGraphBrowser` | node/edge browsing with org-scoped permissions. |
79
+ | `MemorySearchPanel` | graph/frontmatter/grep queries with redaction and source preview. |
80
+ | `MemoryImportReviewPanel` | `.a5c` import diff, redaction, validation, approval, merge. |
81
+ | `OrgScopedResourceGuard` | validates org route params against resource labels/namespace before render. |
82
+ | `AgentPermissionReviewPanel` | explains missing RBAC, Secret, ConfigMap, memory, tool, skill grants. |
83
+
84
+ ## API calls needed by UI
85
+
86
+ - `GET /api/orgs/[org]/resources` for generic resource tables.
87
+ - `GET /api/orgs/[org]/agents/summary` for attention counters.
88
+ - `POST /api/orgs/[org]/agents/dispatch` for manual dispatch.
89
+ - `GET /api/orgs/[org]/agents/runs/[run]` for run detail projection.
90
+ - `POST /api/orgs/[org]/agents/memory/query` for preview/search.
91
+ - `POST /api/orgs/[org]/agents/memory/import-babysitter-run` for run import.
92
+ - `POST /api/orgs/[org]/agents/memory/updates/[id]/approve` for review actions.
93
+ - `GET /api/watch/orgs/[org]/agentdispatchruns` for live run updates.
94
+
95
+ ## UX acceptance criteria
96
+
97
+ - Agent and memory pages never render without an org route param.
98
+ - Legacy global agent routes redirect to org routes only when org is unambiguous.
99
+ - Every memory result shows source path, memory commit, digest, and permission status.
100
+ - Every imported `.a5c` run shows source run, session, retention tier, redaction status, validation report, and target memory PR.
101
+ - Repository pages link to org-scoped agent/memory routes without losing repo context.
102
+
103
+ ## Implementation order
104
+
105
+ 1. Add resource-model kinds and examples so generic resource tables can display agent/memory data.
106
+ 2. Add org route shells for `/orgs/[org]/agents` and `/orgs/[org]/agents/memory` with empty states.
107
+ 3. Add summary endpoints and attention counters.
108
+ 4. Add repository dispatch affordances and memory association previews.
109
+ 5. Add run detail with Agent Mux session panel.
110
+ 6. Add memory query/search/graph views.
111
+ 7. Add memory import review and update review flows.
112
+ 8. Add live watch streams and notification counters.
113
+
114
+ Each step should preserve the existing org shell and advanced YAML panels.
@@ -0,0 +1,168 @@
1
+ # Org memory vertical slice spec
2
+
3
+ ## Purpose
4
+
5
+ This document defines the smallest coherent implementation slice for org-scoped agent memory. It is designed to prove that Krate can manage an org company brain, assemble memory into an agent dispatch, import curated run memory, and preserve org isolation without implementing every advanced UI or automation path.
6
+
7
+ ## Slice outcome
8
+
9
+ A user can:
10
+
11
+ 1. select an org;
12
+ 2. open a repository in that org;
13
+ 3. configure a company brain memory source for the repository;
14
+ 4. manually dispatch an agent with a memory preview;
15
+ 5. inspect the run detail with memory snapshot provenance;
16
+ 6. import a summarized run/session into the org memory repo;
17
+ 7. query that imported memory in a later dispatch;
18
+ 8. verify that another org cannot read or import the memory.
19
+
20
+ ## Included resources
21
+
22
+ Config resources:
23
+
24
+ - `Organization`;
25
+ - `OrgNamespaceBinding`;
26
+ - `Repository`;
27
+ - `AgentStack`;
28
+ - `AgentMemoryRepository`;
29
+ - `AgentMemorySource`;
30
+ - `AgentMemoryOntology`;
31
+ - `AgentServiceAccount`;
32
+ - `AgentRoleBinding`.
33
+
34
+ Aggregated resources:
35
+
36
+ - `AgentDispatchRun`;
37
+ - `AgentDispatchAttempt`;
38
+ - `AgentSession`;
39
+ - `AgentContextBundle`;
40
+ - `AgentMemorySnapshot`;
41
+ - `AgentMemoryQuery`;
42
+ - `AgentRunMemoryImport`;
43
+ - `AgentArtifact`;
44
+ - `AgentApproval`.
45
+
46
+ Deferred resources for later slices:
47
+
48
+ - `AgentSubagent` advanced trees;
49
+ - full `AgentMemoryUpdate` editing UI beyond import PRs;
50
+ - broad trigger automation;
51
+ - cross-org sharing;
52
+ - raw artifact-byte retention;
53
+ - vector/embedding indexes.
54
+
55
+ ## UI scope
56
+
57
+ Required screens:
58
+
59
+ | Screen | Minimum capability |
60
+ | --- | --- |
61
+ | `/orgs/[org]` | shows Agents and Memory attention cards. |
62
+ | `/orgs/[org]/repositories/[repo]/code` | manual dispatch button with memory preview. |
63
+ | `/orgs/[org]/repositories/[repo]/runs` | shows agent dispatch rows beside pipeline rows. |
64
+ | `/orgs/[org]/agents/runs/[run]` | shows run timeline, Agent Mux session placeholder/link, context bundle, memory snapshot. |
65
+ | `/orgs/[org]/agents/memory` | shows memory repo health, current commit, ontology status, imports. |
66
+ | `/orgs/[org]/agents/memory/search` | can query selected graph/Markdown sources. |
67
+ | `/orgs/[org]/agents/memory/imports/[import]` | review summarized import, redaction, validation, PR/merge state. |
68
+ | `/orgs/[org]/repositories/[repo]/settings` | can attach `AgentMemorySource` to the repo. |
69
+
70
+ ## API scope
71
+
72
+ Required endpoints:
73
+
74
+ | Endpoint | Minimum capability |
75
+ | --- | --- |
76
+ | `GET /api/orgs/[org]/agents/summary` | dashboard counters. |
77
+ | `POST /api/orgs/[org]/agents/dispatch` | create manual dispatch with memory snapshot. |
78
+ | `GET /api/orgs/[org]/agents/runs/[run]` | run detail projection. |
79
+ | `POST /api/orgs/[org]/agents/memory/query` | graph/frontmatter/grep preview. |
80
+ | `POST /api/orgs/[org]/agents/memory/resolve-ref` | current and explicit ref resolution. |
81
+ | `POST /api/orgs/[org]/agents/memory/import-babysitter-run` | summary-only import. |
82
+ | `POST /api/orgs/[org]/agents/memory/imports/[import]/approve` | approve import PR/merge. |
83
+ | `GET /api/watch/orgs/[org]/agentdispatchruns` | run updates. |
84
+ | `GET /api/watch/orgs/[org]/agentrunmemoryimports` | import updates. |
85
+
86
+ Historical `refAt` can be included if cheap after current/explicit refs, but should not block the first slice.
87
+
88
+ ## Memory repository scope
89
+
90
+ Minimum layout:
91
+
92
+ ```text
93
+ .company-brain/
94
+ README.md
95
+ babysitter/MEMORY.md
96
+ ontology/node-kinds.yaml
97
+ ontology/edge-kinds.yaml
98
+ runbooks/
99
+ repositories/
100
+ babysitter/sessions/
101
+ babysitter/runs/
102
+ indexes/ontology-report.json
103
+ ```
104
+
105
+ Minimum validators:
106
+
107
+ - parse YAML and Markdown frontmatter;
108
+ - require `id`, `kind`, `title`, `owners`, `status` for canonical records;
109
+ - detect duplicate IDs;
110
+ - detect unknown edge kinds;
111
+ - scan for secret-like values;
112
+ - verify imported run memory has org/repo/source digests.
113
+
114
+ ## Dispatch acceptance path
115
+
116
+ ```text
117
+ Given org a5c has repo krate and memory repo org-company-brain
118
+ And repo krate has AgentMemorySource krate-ci-memory
119
+ When a user dispatches agent claude-code-ci-repair from /orgs/a5c/repositories/krate/code
120
+ Then Krate resolves memory repo main to a commit
121
+ And creates AgentMemorySnapshot and AgentContextBundle
122
+ And creates AgentDispatchRun and AgentDispatchAttempt
123
+ And the run detail shows selected memory records/excerpts and digests
124
+ ```
125
+
126
+ ## Import acceptance path
127
+
128
+ ```text
129
+ Given an AgentDispatchRun completed in org a5c
130
+ And its session has a summary and .a5c run metadata
131
+ When a user creates a summary-only AgentRunMemoryImport
132
+ Then Krate redacts and normalizes the source material
133
+ And opens or records a reviewable memory update
134
+ And after approval merges into org-company-brain
135
+ And later memory search can find the imported session/run summary
136
+ ```
137
+
138
+ ## Cross-org negative path
139
+
140
+ ```text
141
+ Given org a5c and org other both have memory repos
142
+ When an a5c dispatch requests memory from other
143
+ Then Krate rejects with CROSS_ORG_REF_DENIED
144
+ And no memory content is returned in preview, prompt, transcript, audit, or tool output
145
+ ```
146
+
147
+ ## Validation gates
148
+
149
+ - Unit/schema tests for new resources and required `organizationRef` fields.
150
+ - API tests for org mismatch and route ambiguity.
151
+ - Context assembly test for memory snapshot digest creation.
152
+ - Import test for summary-only `.a5c` run memory with redaction.
153
+ - UI smoke for org memory dashboard and run detail memory provenance.
154
+ - Package validation for CRDs/examples/docs.
155
+
156
+ ## Out of scope
157
+
158
+ - Multi-org sharing.
159
+ - Full raw journal retention.
160
+ - Editing arbitrary memory files in UI.
161
+ - Vector search.
162
+ - Advanced subagent orchestration.
163
+ - Automated issue/PR/label triggers beyond manual dispatch.
164
+
165
+ ## Fixture and payload references
166
+
167
+ - [Org memory API payload examples](./org-memory-api-payload-examples.md) defines the JSON contracts for this slice.
168
+ - [Org memory E2E fixture plan](./org-memory-e2e-fixture-plan.md) defines the deterministic data needed to prove this slice without external services.
@@ -0,0 +1,111 @@
1
+ # Org resource model delta spec
2
+
3
+ ## Purpose
4
+
5
+ This document captures the concrete resource-model delta between the current Krate core and the proposed org-scoped agent/memory layer. The current model already includes `Organization` and `OrgNamespaceBinding`; the agent memory work should extend that model consistently instead of creating a parallel tenant system.
6
+
7
+ ## Existing core model anchors
8
+
9
+ Current core resource definitions already include:
10
+
11
+ - `Organization` as platform identity with a bound tenant namespace;
12
+ - `OrgNamespaceBinding` as the binding from org to namespace;
13
+ - `Repository`, `User`, `Team`, `Invite`, `IdentityMapping`, `AuthProvider`, `SSHKey`, `RepositoryPermission`, `WebhookSubscription`, `RefPolicy`, `BranchProtection`, `RunnerPool`, `View`, and `Selector` with `organizationRef` requirements;
14
+ - aggregated `PullRequest`, `Issue`, `Review`, `Pipeline`, `Job`, and `WebhookDelivery` with `organizationRef` requirements.
15
+
16
+ Agent resources should follow the same storage split and naming style.
17
+
18
+ ## Config resources to add
19
+
20
+ | Kind | Context | Required spec | Notes |
21
+ | --- | --- | --- | --- |
22
+ | `AgentStack` | agents | `organizationRef`, `baseAgent`, `adapter`, `runtimeIdentity` | org-scoped reusable agent definition. |
23
+ | `AgentSubagent` | agents | `organizationRef`, `stackRef`, `role` | child-agent definition. |
24
+ | `AgentToolProfile` | agents | `organizationRef`, `allowedTools` | native tool policy. |
25
+ | `AgentMcpServer` | agents | `organizationRef`, `endpoint`, `transport` | MCP server config. |
26
+ | `AgentSkill` | agents | `organizationRef`, `source`, `capabilities` | skill definition and dependencies. |
27
+ | `AgentTriggerRule` | agents | `organizationRef`, `sources`, `agentStack` | webhook/CI/issue/PR/manual trigger policy. |
28
+ | `AgentContextLabel` | agents | `organizationRef`, `promptFragment`, `allowedSources` | reviewed context snippet. |
29
+ | `AgentWorkspacePolicy` | agents | `organizationRef`, `mode`, `retentionPolicy` | worktree/runtime policy. |
30
+ | `AgentServiceAccount` | identity | `organizationRef`, `serviceAccountName` | org namespace ServiceAccount binding. |
31
+ | `AgentRoleBinding` | identity | `organizationRef`, `subject`, `roleRef` | desired RBAC binding. |
32
+ | `AgentSecretGrant` | identity | `organizationRef`, `subject`, `secretRef` | secret key access. |
33
+ | `AgentConfigGrant` | identity | `organizationRef`, `subject`, `configMapRef` | ConfigMap key access. |
34
+ | `AgentMemoryRepository` | agents | `organizationRef`, `repositoryRef`, `defaultBranch` | org company brain repo. |
35
+ | `AgentMemorySource` | agents | `organizationRef`, `repositoryRef`, `include` | memory read/query policy. |
36
+ | `AgentMemoryOntology` | agents | `organizationRef`, `memoryRepository`, `ontologyPath` | ontology validation policy. |
37
+ | `AgentMemoryAssociation` | agents | `organizationRef`, `memoryRef`, `targetRef` | memory-to-resource edge. |
38
+
39
+ ## Aggregated resources to add
40
+
41
+ | Kind | Context | Required spec | Notes |
42
+ | --- | --- | --- | --- |
43
+ | `AgentDispatchRun` | agents | `organizationRef`, `repository`, `agentStack`, `sourceRefs` | CI-like agent run. |
44
+ | `AgentDispatchAttempt` | agents | `organizationRef`, `agentDispatchRun`, `attemptReason` | retry/fork attempt. |
45
+ | `AgentSession` | agents | `organizationRef`, `agentMuxSessionId`, `dispatchRun` | Agent Mux session projection. |
46
+ | `AgentWorkspace` | agents | `organizationRef`, `repository`, `workspacePath` | worktree/runtime state. |
47
+ | `AgentApproval` | agents | `organizationRef`, `dispatchRun`, `action` | human approval state. |
48
+ | `AgentContextBundle` | agents | `organizationRef`, `dispatchRun`, `digest` | immutable context snapshot. |
49
+ | `AgentArtifact` | agents | `organizationRef`, `dispatchRun`, `kind`, `digest` | run output. |
50
+ | `AgentTriggerExecution` | agents | `organizationRef`, `triggerRule`, `sourceEvent` | trigger evaluation. |
51
+ | `AgentMemorySnapshot` | agents | `organizationRef`, `memoryRepository`, `resolvedCommit` | pinned memory snapshot. |
52
+ | `AgentMemoryQuery` | agents | `organizationRef`, `snapshotRef`, `query` | graph/frontmatter/grep query. |
53
+ | `AgentMemoryUpdate` | agents | `organizationRef`, `memoryRepository`, `changes` | memory PR/update proposal. |
54
+ | `AgentRunMemoryImport` | agents | `organizationRef`, `memoryRepository`, `source` | curated `.a5c`/session import. |
55
+ | `AgentRunJournalEvent` | agents | `organizationRef`, `runRef`, `sequence`, `digest` | imported journal event projection. |
56
+
57
+ ## Schema conventions
58
+
59
+ All added resources should use:
60
+
61
+ ```yaml
62
+ metadata:
63
+ namespace: krate-org-a5c
64
+ labels:
65
+ krate.a5c.ai/org: a5c
66
+ spec:
67
+ organizationRef: a5c
68
+ status:
69
+ phase: Pending
70
+ conditions: []
71
+ ```
72
+
73
+ `organizationRef` is required even when namespace can imply org, because aggregated API resources may be stored outside etcd and need an explicit partition key.
74
+
75
+ ## Index requirements
76
+
77
+ Aggregated tables need org-first compound indexes:
78
+
79
+ - `(organization_ref, repository, created_at)` for repository activity;
80
+ - `(organization_ref, phase, updated_at)` for dashboards;
81
+ - `(organization_ref, agent_stack, created_at)` for agent run lists;
82
+ - `(organization_ref, memory_repository, resolved_commit)` for memory snapshots;
83
+ - `(organization_ref, source_run, created_at)` for memory imports;
84
+ - `(organization_ref, work_item_ref)` for issue/session/workspace links.
85
+
86
+ ## Admission requirements
87
+
88
+ - `organizationRef` must match namespace binding for namespaced resources.
89
+ - Aggregated resources must store org even when created from a namespaced parent.
90
+ - Cross-org target refs are invalid unless `OrgSharingPolicy` admits them.
91
+ - Secret and ConfigMap refs must name resources in the org namespace unless a future replication policy exists.
92
+ - Memory repository refs must belong to the same org as the dispatch or import.
93
+
94
+ ## Acceptance criteria
95
+
96
+ - A resource implementer can add agent/memory kinds to `src/resource-model.js` without inventing new storage categories.
97
+ - Every new kind has `organizationRef` and org labels.
98
+ - List/watch APIs can filter by org before repository, stack, run, or memory filters.
99
+ - Package validation can assert the full set of org-scoped CRDs and examples.
100
+
101
+ ## Package validation additions
102
+
103
+ Package validation should eventually assert:
104
+
105
+ - every new agent/memory kind has a resource definition;
106
+ - every config kind has a CRD example with `organizationRef`;
107
+ - every aggregated kind has an API schema example with `organizationRef`;
108
+ - org-scoped labels are present in examples;
109
+ - `AgentRunMemoryImport` examples include redaction and retention policy;
110
+ - memory snapshot examples include resolved commit and digest fields;
111
+ - route docs refer to `/orgs/[org]` canonical paths.
@@ -0,0 +1,183 @@
1
+ # Org route and resource model spec
2
+
3
+ ## Purpose
4
+
5
+ Krate should behave as an organization-first forge. This document defines how org scope affects routes, API paths, resource refs, namespaces, controllers, deployments, repositories, and agent memory.
6
+
7
+ ## Route model
8
+
9
+ Preferred UI routes:
10
+
11
+ | Route | Purpose |
12
+ | --- | --- |
13
+ | `/orgs` | list visible orgs and recent activity. |
14
+ | `/orgs/[org]` | org dashboard: repositories, deployments, agents, memory, runners, audit. |
15
+ | `/orgs/[org]/repositories` | org repository list. |
16
+ | `/orgs/[org]/repositories/[repo]/code` | repository code browser. |
17
+ | `/orgs/[org]/repositories/[repo]/issues` | issues and work item boards. |
18
+ | `/orgs/[org]/repositories/[repo]/pull-requests` | PRs and reviews. |
19
+ | `/orgs/[org]/repositories/[repo]/runs` | CI and agent dispatch rows. |
20
+ | `/orgs/[org]/deployments` | deployment/environment inventory. |
21
+ | `/orgs/[org]/agents` | agent dashboard. |
22
+ | `/orgs/[org]/agents/runs/[run]` | dispatch detail and Agent Mux session. |
23
+ | `/orgs/[org]/agents/memory` | company brain memory. |
24
+ | `/orgs/[org]/settings` | org RBAC, namespace, policies, billing/cost if applicable. |
25
+
26
+ Non-org repository and deployment routes are not part of the product surface. Users enter repository, deployment, run, and settings flows through `/orgs/[org]/...` so the current org is always explicit.
27
+
28
+ ## API route model
29
+
30
+ Preferred API routes:
31
+
32
+ | Route | Purpose |
33
+ | --- | --- |
34
+ | `/api/orgs/[org]/resources` | generic org-scoped resource list/apply. |
35
+ | `/api/orgs/[org]/repositories/[repo]/...` | repository-scoped actions. |
36
+ | `/api/orgs/[org]/deployments/[deployment]/...` | deployment-scoped actions. |
37
+ | `/api/orgs/[org]/agents/runs` | dispatch list/create. |
38
+ | `/api/orgs/[org]/agents/memory/query` | memory query. |
39
+ | `/api/orgs/[org]/agents/memory/import-babysitter-run` | run memory import. |
40
+ | `/api/watch/orgs/[org]/...` | org-scoped watches. |
41
+
42
+ Non-org API routes must not operate on org resources. Organization work is always explicit through `/orgs/[org]`, `/api/orgs/[org]/...`, or `/api/watch/orgs/[org]/...`.
43
+
44
+ ## Resource reference shape
45
+
46
+ Every product resource should either include `spec.organizationRef` or be namespaced under an org namespace where org can be inferred.
47
+
48
+ ```yaml
49
+ metadata:
50
+ namespace: krate-org-a5c
51
+ labels:
52
+ krate.a5c.ai/org: a5c
53
+ spec:
54
+ organizationRef: a5c
55
+ ```
56
+
57
+ Cross-resource refs should include org when ambiguity is possible:
58
+
59
+ ```yaml
60
+ repositoryRef:
61
+ organization: a5c
62
+ name: krate
63
+ deploymentRef:
64
+ organization: a5c
65
+ name: krate-web
66
+ memoryRepositoryRef:
67
+ organization: a5c
68
+ name: org-company-brain
69
+ ```
70
+
71
+ ## Deployment scoping
72
+
73
+ Deployments and environments are org siblings to repositories, not global resources.
74
+
75
+ ```text
76
+ Organization
77
+ -> Repository
78
+ -> Deployment
79
+ -> Environment
80
+ -> ReleasePolicy
81
+ -> RuntimeStatus
82
+ -> DeploymentSecretGrant
83
+ -> AgentDispatchRun
84
+ -> may target Repository and Deployment in same org
85
+ ```
86
+
87
+ Agent dispatches that operate on deployments must use an org ServiceAccount and deployment-scoped grants. A repository agent cannot mutate a deployment in another org.
88
+
89
+ ## Namespace enforcement
90
+
91
+ Controllers must enforce:
92
+
93
+ - resource namespace matches org namespace;
94
+ - `metadata.labels[krate.a5c.ai/org]` matches `spec.organizationRef`;
95
+ - referenced repository/deployment/memory/secret/config resources belong to the same org;
96
+ - ServiceAccount tokens are mounted only from the org namespace;
97
+ - cross-org refs require `OrgSharingPolicy` and explicit audit.
98
+
99
+ ## UI behavior
100
+
101
+ - The org switcher is global and persistent.
102
+ - Breadcrumbs always start with org.
103
+ - Search results group by org and hide unauthorized orgs entirely.
104
+ - YAML previews show namespace, org label, and `organizationRef`.
105
+ - Copyable `kubectl` examples include `-n <org-namespace>`.
106
+ - Empty states explain when a user has access to an org but no repositories, deployments, agents, or memory sources.
107
+
108
+ ## Controller behavior
109
+
110
+ ```text
111
+ watch event
112
+ -> resolve namespace
113
+ -> resolve organization
114
+ -> validate labels and organizationRef
115
+ -> validate same-org references
116
+ -> compute effective RBAC and grants
117
+ -> reconcile side effects in org namespace
118
+ -> write status/audit with org and namespace
119
+ ```
120
+
121
+ Controllers may use shared caches and cluster roles for observation, but all writes and runtime side effects are namespaced to the owning org unless explicitly platform-scoped.
122
+
123
+ ## Acceptance criteria
124
+
125
+ - All repository, deployment, agent, runner, memory, session, workspace, secret, config, and audit records have org context.
126
+ - Ambiguous non-org routes are not product surface and return not found instead of selecting an org silently.
127
+ - API and watch routes are org-scoped by construction.
128
+ - Controller status and audit events include org and namespace.
129
+ - Cross-org references fail closed by default.
130
+
131
+ ## Org-scoped resource kind matrix
132
+
133
+ | Domain | Resource examples | Org rule |
134
+ | --- | --- | --- |
135
+ | Core tenancy | `Organization`, `OrgNamespaceBinding`, `OrgSharingPolicy` | platform-owned; binds org to namespace. |
136
+ | Repositories | `Repository`, `PullRequest`, `Issue`, `Review`, `WebhookDelivery` | must match org namespace and labels. |
137
+ | Deployments | `Deployment`, `Environment`, release policies, runtime status | org-scoped sibling to repository. |
138
+ | Agents | `AgentStack`, `AgentTriggerRule`, `AgentDispatchRun`, `AgentSession`, `AgentWorkspace` | org-scoped; may reference same-org repo/deployment/memory. |
139
+ | Memory | `AgentMemoryRepository`, `AgentMemorySource`, `AgentMemorySnapshot`, `AgentRunMemoryImport` | org-scoped; memory repo per org by default. |
140
+ | Identity | `AgentServiceAccount`, `AgentRoleBinding`, `AgentSecretGrant`, `AgentConfigGrant` | namespace-bound to org. |
141
+ | Runners | `RunnerPool`, runner ServiceAccounts, workspace policies | org-scoped unless explicitly shared. |
142
+ | Audit | audit records, approval records, policy evaluations | include org and namespace always. |
143
+
144
+ ## Admission checklist
145
+
146
+ Before accepting a create/update or starting a controller side effect, Krate must verify:
147
+
148
+ 1. `organizationRef` exists and is visible to the actor.
149
+ 2. target namespace equals the org namespace binding.
150
+ 3. org labels match `organizationRef`.
151
+ 4. referenced repository, deployment, memory repo, runner pool, secret, config, ServiceAccount, stack, trigger, session, and workspace are in the same org.
152
+ 5. actor or ServiceAccount has Kubernetes RBAC for the namespace and Krate permission for the product action.
153
+ 6. any cross-org reference has an admitted `OrgSharingPolicy`.
154
+ 7. audit event can be emitted before external side effects.
155
+
156
+ ## Org sharing policy
157
+
158
+ Cross-org sharing should be rare and explicit.
159
+
160
+ ```yaml
161
+ kind: OrgSharingPolicy
162
+ metadata:
163
+ name: a5c-read-shared-memory
164
+ spec:
165
+ sourceOrg: a5c
166
+ targetOrg: platform-shared
167
+ allowedRefs:
168
+ - kind: AgentMemoryRepository
169
+ name: shared-engineering-memory
170
+ permissions: [memory.graph.query, memory.records.read]
171
+ expiresAt: 2026-06-01T00:00:00Z
172
+ approvalPolicy:
173
+ requiredApprovers: [team:security]
174
+ ```
175
+
176
+ Sharing policies cannot grant Secret or ConfigMap values across orgs unless a separate secret replication policy exists.
177
+
178
+ ## Migration requirements
179
+
180
+ - Add org columns/labels to aggregated tables before enforcing org filters.
181
+ - Backfill existing demo resources into a default org such as `a5c`.
182
+ - Keep org-scoped watch tests passing before enabling multi-org data.
183
+ - Flip admission from audit to enforce after backfill and UI route migration are complete.