@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,194 @@
1
+ # Memory context integration spec
2
+
3
+ ## Purpose
4
+
5
+ This document defines how Krate's context layer should read the company brain and add memory-backed context to `AgentContextBundle` resources. Memory follows the same core rules as every other context source: permission review, provenance, redaction, bounded size, immutable digests, and preview before dispatch.
6
+
7
+ ## Source families
8
+
9
+ | Family | Example | Retrieval | Prompt treatment |
10
+ | --- | --- | --- | --- |
11
+ | Graph YAML records | `graph/orgs/[org]/repositories/krate.yaml` | ID lookup, kind filters, edge traversal | summarized records with IDs, owners, and edge breadcrumbs. |
12
+ | Markdown records | `runbooks/ci/playwright-flake.md` | frontmatter filters and bounded reads | title, frontmatter, body excerpts, source path. |
13
+ | Free-form Markdown | `notes/investigations/*.md` | grep/ripgrep search within allowed paths | line excerpts with context and digest. |
14
+ | Ontology records | `ontology/node-kinds.yaml` | schema lookup and validation report | validation context, not task facts unless requested. |
15
+
16
+ Graph and grep results should work together: graph traversal can identify relevant repositories, services, decisions, and runbooks; grep can then search those candidate paths for specific failure signatures or terms.
17
+
18
+ ## `AgentContextBundle` additions
19
+
20
+ ```yaml
21
+ spec:
22
+ memory:
23
+ enabled: true
24
+ repositoryRef: org-company-brain
25
+ requestedRef: main
26
+ resolvedCommit: abcdef1234567890
27
+ refResolution:
28
+ mode: current
29
+ snapshotRef: memory-snapshot-01hx
30
+ queryManifestDigest: sha256:...
31
+ ontologyDigest: sha256:...
32
+ indexDigest: sha256:...
33
+ sources:
34
+ - kind: memory-graph-record
35
+ id: runbook:ci-playwright-flake
36
+ path: runbooks/ci/playwright-flake.md
37
+ digest: sha256:...
38
+ - kind: memory-grep-excerpt
39
+ path: notes/investigations/2026-05-playwright.md
40
+ lineStart: 42
41
+ lineEnd: 48
42
+ digest: sha256:...
43
+ limits:
44
+ maxMemoryBytes: 128000
45
+ truncated: false
46
+ ```
47
+
48
+ Memory entries may also appear in the existing `sources` list, but the dedicated `memory` block is required for retries, stale-memory warnings, historical refs, and audits.
49
+
50
+ ## Query modes
51
+
52
+ | Mode | Behavior | Use |
53
+ | --- | --- | --- |
54
+ | `graph-only` | query structured graph/frontmatter records only | ownership, dependency, runbook, and ontology-driven tasks. |
55
+ | `grep-only` | search allowed Markdown paths without graph traversal | raw notes, broad recall, and unstructured history. |
56
+ | `graph-and-grep` | graph narrows candidate paths, then grep searches them | default for repository tasks. |
57
+ | `document-read` | read selected memory documents by path or ID | user-selected context in composer. |
58
+ | `ontology-validation` | validate proposed graph/frontmatter changes | update review and memory CI. |
59
+ | `diff-ref` | compare current memory with pinned memory | time-travel and stale-context warnings. |
60
+
61
+ ## Ref resolution
62
+
63
+ ```yaml
64
+ memory:
65
+ refResolution:
66
+ mode: current | explicit-ref | ref-at-time | snapshot-tag
67
+ requested: main
68
+ resolvedCommit: abcdef1234567890
69
+ resolvedAt: 2026-05-10T12:00:00Z
70
+ ```
71
+
72
+ Rules:
73
+
74
+ - `current` resolves the configured default branch at dispatch creation.
75
+ - `explicit-ref` resolves a branch, tag, or SHA.
76
+ - `ref-at-time` resolves the latest approved commit at or before a timestamp.
77
+ - `snapshot-tag` resolves a Krate-created stable snapshot tag.
78
+ - Ambiguous or missing refs block dispatch before Agent Mux launch.
79
+
80
+ ## Assembly flow
81
+
82
+ ```text
83
+ source event or manual dispatch
84
+ -> resolve AgentStack and AgentMemorySource
85
+ -> review memory read/query permissions
86
+ -> resolve memory ref to commit
87
+ -> load ontology and index manifests at commit
88
+ -> run graph, frontmatter, and grep retrieval
89
+ -> redact, rank, and bound selected memory
90
+ -> create AgentMemorySnapshot and AgentMemoryQuery records
91
+ -> add memory block to AgentContextBundle
92
+ -> launch AgentDispatchAttempt with immutable snapshot
93
+ ```
94
+
95
+ ## Ranking requirements
96
+
97
+ The preview must explain why each memory item was selected. Rank by:
98
+
99
+ 1. explicit user selection;
100
+ 2. direct association to repository, issue, PR, service, stack, trigger, or skill;
101
+ 3. graph edge distance from source refs;
102
+ 4. allow-list specificity;
103
+ 5. grep match strength and recency;
104
+ 6. owner-approved status;
105
+ 7. size and freshness constraints.
106
+
107
+ ## Prompt rendering
108
+
109
+ Memory should render in a dedicated prompt section after repository instructions and before transient logs or diffs:
110
+
111
+ ```text
112
+ ## Company Brain Memory
113
+ Memory repository: org-company-brain
114
+ Resolved commit: abcdef1234567890
115
+ Query manifest: sha256:...
116
+
117
+ ### Graph records
118
+ - runbook:ci-playwright-flake ...
119
+
120
+ ### Markdown excerpts
121
+ - notes/investigations/2026-05-playwright.md:42 ...
122
+ ```
123
+
124
+ The prompt must tell agents that memory is advisory and may be stale, especially when pinned to a historical ref.
125
+
126
+ ## Historical memory runs
127
+
128
+ When dispatch uses `refAt` or an old snapshot:
129
+
130
+ - UI displays `Memory is pinned to <commit> from <date>`.
131
+ - Context bundle stores current memory commit separately for comparison.
132
+ - Run detail offers `Diff memory against current`.
133
+ - Agent prompt includes a stale-memory banner.
134
+ - Memory read tools default to the pinned commit.
135
+ - Memory update proposals target current `main` unless policy explicitly says otherwise.
136
+
137
+ Example:
138
+
139
+ ```yaml
140
+ memory:
141
+ requestedRefAt: 2026-05-08T09:30:00Z
142
+ resolvedCommit: 13579bdf2468
143
+ currentCommitAtDispatch: abcdef1234567890
144
+ staleBy: 2d3h
145
+ ```
146
+
147
+ ## Memory tools
148
+
149
+ After Krate permission review, Agent Mux can expose:
150
+
151
+ - `memory.graph.search`: search graph records by text, kind, edge, owner, or association.
152
+ - `memory.record.read`: read graph or Markdown records by ID/path at the pinned commit.
153
+ - `memory.docs.grep`: grep allowed Markdown paths at the pinned commit.
154
+ - `memory.snapshot.diff`: diff pinned memory against another ref.
155
+ - `memory.update.propose`: create a proposed memory patch artifact.
156
+ - `memory.ontology.validate`: validate proposed graph/frontmatter changes.
157
+
158
+ Tools operate against the dispatch memory snapshot by default. Reading current memory from a historical run requires explicit refresh or approval.
159
+
160
+ ## Failure behavior
161
+
162
+ | Failure | Required behavior |
163
+ | --- | --- |
164
+ | Memory repo unavailable | block if memory is required; warn and continue only if optional. |
165
+ | Ref cannot resolve | block dispatch. |
166
+ | Ontology invalid | block update merges; allow reads only with warning if policy permits. |
167
+ | Grep returns too much | truncate with omitted-count summary. |
168
+ | Permission denied | omit content and show denied path/kind without leaking values. |
169
+ | Secret-like content detected | redact; mark unsafe if redaction is too broad. |
170
+
171
+ ## Acceptance criteria
172
+
173
+ - `AgentContextBundle` explains memory repository, requested ref, resolved commit, selected records, selected excerpts, and query manifest.
174
+ - Graph and grep results can be combined in one dispatch.
175
+ - Time-travel memory uses a commit-pinned snapshot and never silently refreshes during retry.
176
+ - Agents can only call memory tools for paths/kinds granted by Krate.
177
+ - Context preview and run detail expose stale-memory warnings and diff actions.
178
+
179
+ ## Babysitter memory context
180
+
181
+ Context assembly can include curated Babysitter run memory from the org company brain:
182
+
183
+ - `babysitter/MEMORY.md` for stable orchestration instructions and conventions;
184
+ - session summaries for previous related agent work;
185
+ - curated run journals for replaying decisions and state transitions;
186
+ - task results and artifact manifests for evidence-backed context;
187
+ - retrospectives for process improvements and known pitfalls.
188
+
189
+ Selection rules:
190
+
191
+ - match org first, then repository, stack, process, trigger, issue/PR, and run status;
192
+ - prefer summarized sessions and retrospectives over raw journal events unless a replay/debug task needs detail;
193
+ - include raw journal excerpts only with line/event bounds and redaction;
194
+ - pin all imported run memory to the same memory commit as other company brain sources.
@@ -0,0 +1,253 @@
1
+ # Memory ontology and file schema spec
2
+
3
+ ## Purpose
4
+
5
+ The company brain needs a maintained ontology so shared memory stays navigable, enforceable, searchable, and useful to agents. This document defines Markdown/YAML schema conventions for graph records, frontmatter records, free-form documents, ontology files, and generated indexes.
6
+
7
+ ## Principles
8
+
9
+ - Human-readable files are authoritative.
10
+ - Canonical facts have stable IDs.
11
+ - Graph structure improves retrieval but does not block useful notes.
12
+ - Ontology changes are reviewed like code.
13
+ - Derived indexes are reproducible from Git contents.
14
+ - Memory records expose owners, status, and source references where possible.
15
+
16
+ ## File classes
17
+
18
+ | Class | Pattern | Structure |
19
+ | --- | --- | --- |
20
+ | Graph records | `graph/**/*.yaml` | Atlas-style `nodeKind`, `id`, `attributes`, `edges`. |
21
+ | Markdown records | `runbooks/**/*.md`, `decisions/**/*.md`, `incidents/**/*.md`, `repositories/**/*.md` | YAML frontmatter plus body. |
22
+ | Free-form notes | `notes/**/*.md`, `meetings/**/*.md`, `scratch/**/*.md` | body required; frontmatter optional. |
23
+ | Ontology | `ontology/**/*.yaml` | node kinds, edge kinds, vocabularies, validation rules. |
24
+ | Generated indexes | `indexes/**/*` | generated reports tied to source commit/digest. |
25
+
26
+ ## Graph YAML schema
27
+
28
+ ```yaml
29
+ nodeKind: Runbook
30
+ id: runbook:ci-playwright-flake
31
+ attributes:
32
+ title: Playwright flake triage
33
+ status: approved
34
+ owners: [team:platform]
35
+ summary: How to diagnose recurring Playwright failures in Krate CI.
36
+ tags: [ci, playwright, krate]
37
+ updatedAt: 2026-05-10T12:00:00Z
38
+ edges:
39
+ applies_to_repo:
40
+ - target: repository:krate
41
+ owned_by:
42
+ - target: team:platform
43
+ supersedes:
44
+ - target: runbook:old-playwright-flake
45
+ ```
46
+
47
+ Required graph fields:
48
+
49
+ - `nodeKind`: ontology kind name.
50
+ - `id`: stable prefixed ID.
51
+ - `attributes.title`: display name.
52
+ - `attributes.status`: `draft`, `approved`, `deprecated`, or `archived`.
53
+ - `attributes.owners`: one or more teams/users.
54
+ - `attributes.updatedAt`: ISO timestamp.
55
+
56
+ ## Markdown frontmatter schema
57
+
58
+ ```markdown
59
+ ---
60
+ id: decision:agent-memory-git-backed
61
+ kind: Decision
62
+ title: Use Git as source of truth for company brain
63
+ status: approved
64
+ owners:
65
+ - team:platform
66
+ aliases:
67
+ - company brain git memory
68
+ repoRefs:
69
+ - repository:krate
70
+ tags:
71
+ - agents
72
+ - memory
73
+ related:
74
+ documents:
75
+ - runbook:agent-memory-update-review
76
+ supersedes:
77
+ - decision:agent-memory-db-only
78
+ updatedAt: 2026-05-10T12:00:00Z
79
+ ---
80
+
81
+ # Use Git as source of truth for company brain
82
+
83
+ Decision body...
84
+ ```
85
+
86
+ | Field | Required | Notes |
87
+ | --- | --- | --- |
88
+ | `id` | yes for records | Stable graph ID; optional for pure free-form notes. |
89
+ | `kind` | yes for records | Ontology node kind. |
90
+ | `title` | yes | Display title; free-form notes can fall back to first H1. |
91
+ | `status` | yes for records | `draft`, `approved`, `deprecated`, `archived`. |
92
+ | `owners` | yes for records | Team/user IDs. |
93
+ | `aliases` | no | Search and disambiguation terms. |
94
+ | `repoRefs` | no | Associated Krate repositories. |
95
+ | `tags` | no | Controlled vocabulary preferred. |
96
+ | `related` | no | Edge map from edge kind to target IDs. |
97
+ | `updatedAt` | yes for records | ISO timestamp. |
98
+ | `sensitivity` | no | `public`, `internal`, `restricted`, `secret-metadata`. |
99
+ | `sourceRefs` | no | Issues, PRs, dispatch runs, incidents, docs, URLs. |
100
+
101
+ ## Free-form Markdown
102
+
103
+ Free-form files are intentionally lightweight:
104
+
105
+ ```markdown
106
+ ---
107
+ title: Investigation notes for flaky Krate checks
108
+ owners: [user:alice]
109
+ tags: [investigation, ci]
110
+ repoRefs: [repository:krate]
111
+ status: draft
112
+ ---
113
+
114
+ Raw notes...
115
+ ```
116
+
117
+ Rules:
118
+
119
+ - frontmatter is optional but recommended;
120
+ - `id` is optional unless the note should be graph-addressable;
121
+ - grep search may return excerpts from files without IDs;
122
+ - promotion from note to canonical record should preserve source links.
123
+
124
+ ## Initial node kinds
125
+
126
+ | Node kind | Purpose |
127
+ | --- | --- |
128
+ | `Organization` | company or business unit. |
129
+ | `Team` | owner, reviewer, or operating group. |
130
+ | `Repository` | Krate repository identity and associated practices. |
131
+ | `Service` | deployed service or component. |
132
+ | `Package` | package/library/module ownership and practices. |
133
+ | `Runbook` | operational procedure. |
134
+ | `Decision` | architectural, product, or process decision. |
135
+ | `Incident` | incident summary, remediation, follow-up. |
136
+ | `AgentPractice` | reusable lesson for agent dispatches. |
137
+ | `Skill` | agent skill knowledge and requirements. |
138
+ | `Tool` | native tool or MCP capability knowledge. |
139
+ | `Customer` | customer-specific context when allowed. |
140
+ | `ProductArea` | product/domain grouping. |
141
+ | `Term` | glossary, aliases, and terminology. |
142
+ | `PromptFragment` | reviewed context text reusable by stacks. |
143
+
144
+ ## Initial edge kinds
145
+
146
+ | Edge kind | Use |
147
+ | --- | --- |
148
+ | `documents` | page or record documents another node. |
149
+ | `implements` | service/package implements a decision or capability. |
150
+ | `depends_on` | dependency or operational prerequisite. |
151
+ | `supersedes` | replaces older record. |
152
+ | `owned_by` | ownership by team/user. |
153
+ | `applies_to_repo` | memory applies to a repository. |
154
+ | `applies_to_stack` | memory applies to an agent stack. |
155
+ | `mentions` | weak mention/reference. |
156
+ | `derived_from` | extracted from run, issue, PR, incident, or note. |
157
+ | `requires_secret` | tool/skill/runbook requires a named secret grant. |
158
+ | `requires_config` | tool/skill/runbook requires a named config grant. |
159
+ | `safe_for_trigger` | approved for a trigger source or trust level. |
160
+ | `resolved_by` | incident or issue resolved by runbook, decision, PR, or dispatch. |
161
+
162
+ ## ID conventions
163
+
164
+ | Kind | Example |
165
+ | --- | --- |
166
+ | Repository | `repository:krate` |
167
+ | Team | `team:platform` |
168
+ | Runbook | `runbook:ci-playwright-flake` |
169
+ | Decision | `decision:agent-memory-git-backed` |
170
+ | Incident | `incident:2026-05-krate-ci-outage` |
171
+ | AgentPractice | `agent-practice:prefer-focused-tests-first` |
172
+ | Skill | `skill:focused-test-selection` |
173
+ | Tool | `tool:memory-docs-grep` |
174
+
175
+ IDs are immutable. Renames update title and aliases. Replacements use `supersedes` and deprecate the older record.
176
+
177
+ ## Validation rules
178
+
179
+ Validators should check:
180
+
181
+ - YAML parse errors and Markdown frontmatter parse errors;
182
+ - duplicate IDs;
183
+ - unknown node kinds and edge kinds;
184
+ - missing required fields;
185
+ - invalid owner IDs;
186
+ - dangling edges;
187
+ - forbidden status transitions;
188
+ - forbidden secrets or high-entropy strings;
189
+ - path policy violations;
190
+ - stale generated indexes;
191
+ - ontology compatibility version.
192
+
193
+ ## Derived index shape
194
+
195
+ ```yaml
196
+ generatedAt: 2026-05-10T12:00:00Z
197
+ sourceCommit: abcdef1234567890
198
+ ontologyDigest: sha256:...
199
+ stats:
200
+ records: 1200
201
+ edges: 4200
202
+ markdownRecords: 550
203
+ freeFormDocuments: 900
204
+ parseErrors: 0
205
+ records: {}
206
+ edges: []
207
+ pathIndex: {}
208
+ ownerIndex: {}
209
+ repoIndex: {}
210
+ tagIndex: {}
211
+ ```
212
+
213
+ Indexes may be committed for review or stored as controller artifacts, but Krate must be able to rebuild them from source.
214
+
215
+ ## Governance
216
+
217
+ - Ontology changes require memory-owner review.
218
+ - New node/edge kinds need examples and validation rules.
219
+ - Deprecated kinds stay readable until migration completes.
220
+ - Reports show unowned records, stale records, dangling edges, and sensitive records.
221
+ - Canonical records should include source references when derived from runs, incidents, issues, or PRs.
222
+
223
+ ## Acceptance criteria
224
+
225
+ - A developer can add a useful free-form note without learning the full graph schema.
226
+ - A memory steward can promote a note into a canonical graph or Markdown record.
227
+ - Validators catch duplicate IDs, dangling edges, unknown kinds, and secret-like content.
228
+ - Krate can build graph traversal, frontmatter filters, and grep search from the same Git ref.
229
+ - UI can explain owners, source refs, and associations to repositories, stacks, skills, tools, triggers, and runs.
230
+
231
+ ## Babysitter memory schema
232
+
233
+ Add ontology support for Babysitter orchestration memory:
234
+
235
+ | Node kind | Purpose |
236
+ | --- | --- |
237
+ | `BabysitterRun` | org-scoped orchestration run with status, source repo, process, and task graph. |
238
+ | `BabysitterSession` | chat/session summary linked to one or more dispatches or runs. |
239
+ | `RunJournalEvent` | ordered event extracted from `.a5c/runs/<run>/journal`. |
240
+ | `RunTaskResult` | task-level result, evidence, artifacts, and validation status. |
241
+ | `RunRetrospective` | durable lesson or process improvement derived from a run. |
242
+
243
+ Additional edge kinds:
244
+
245
+ | Edge kind | Use |
246
+ | --- | --- |
247
+ | `has_journal_event` | run contains ordered journal event. |
248
+ | `has_task_result` | run contains task result. |
249
+ | `summarized_by` | session/run is summarized by Markdown memory. |
250
+ | `produced_artifact` | task or run produced artifact manifest/digest. |
251
+ | `learned_from` | practice, runbook, or retrospective derived from run/session. |
252
+
253
+ `MEMORY.md` may remain a special entrypoint file, but durable facts extracted from it should use normal graph IDs and frontmatter when promoted.
@@ -0,0 +1,121 @@
1
+ # Memory operations runbook
2
+
3
+ ## Purpose
4
+
5
+ This runbook defines operational flows for bootstrapping, validating, querying, updating, rolling back, and time-traveling the company brain memory repository.
6
+
7
+ ## Bootstrap org memory
8
+
9
+ 1. Create `AgentMemoryRepository` with `managedByKrate=true`.
10
+ 2. Krate creates or adopts the Git repository.
11
+ 3. Seed `ontology/`, `graph/`, `pages/`, `notes/`, `runbooks/`, `decisions/`, `incidents/`, and `indexes/`.
12
+ 4. Seed base ontology with node kinds, edge kinds, statuses, sensitivity levels, and owner vocabulary.
13
+ 5. Create default `AgentMemorySource` policies per repository/team.
14
+ 6. Build initial indexes and validation report.
15
+ 7. Expose `/agents/memory` only to users with memory read permission.
16
+
17
+ ## Validate memory repository
18
+
19
+ Validation should run on every memory PR, scheduled reconcile, and manual UI request.
20
+
21
+ Required checks:
22
+
23
+ - parse YAML and Markdown frontmatter;
24
+ - enforce ontology schema;
25
+ - verify graph IDs and edge targets;
26
+ - verify owner/team references;
27
+ - scan for secret-like content;
28
+ - rebuild derived indexes;
29
+ - compare generated indexes with committed indexes when committed indexes are enabled;
30
+ - produce `ontology-report.json` and update `AgentMemoryOntology` status.
31
+
32
+ ## Dispatch with current memory
33
+
34
+ 1. User or trigger selects stack.
35
+ 2. Krate resolves default memory branch to commit.
36
+ 3. Context assembler runs allowed memory queries.
37
+ 4. Run detail stores `AgentMemorySnapshot` and selected context.
38
+ 5. Agent Mux launch receives prompt content plus memory tool descriptors.
39
+
40
+ ## Dispatch with memory from two days ago
41
+
42
+ 1. User selects `Memory ref: two days ago` in advanced dispatch settings.
43
+ 2. Krate converts the request to an absolute timestamp.
44
+ 3. Memory controller finds the latest approved commit at or before that timestamp.
45
+ 4. UI shows resolved commit and current-vs-pinned diff summary.
46
+ 5. `AgentContextBundle` stores both resolved historical commit and current commit.
47
+ 6. Agent prompt includes a stale-memory banner.
48
+ 7. Agent tools default to the pinned memory commit.
49
+
50
+ Example:
51
+
52
+ ```yaml
53
+ memory:
54
+ repositoryRef: org-company-brain
55
+ refAt: 2026-05-08T12:00:00Z
56
+ resolutionPolicy: latest-commit-before-or-at
57
+ requireApprovedCommit: true
58
+ ```
59
+
60
+ ## Propose memory update from a run
61
+
62
+ 1. Agent writes a memory update artifact with file changes and rationale.
63
+ 2. Krate validates the patch against ontology, path, owner, and redaction policy.
64
+ 3. Krate creates `AgentMemoryUpdate`.
65
+ 4. If allowed, Krate opens a PR or internal review branch.
66
+ 5. Reviewers inspect diff, source run, selected evidence, and validation report.
67
+ 6. Merge updates default branch and rebuilds indexes.
68
+ 7. Original run links to merged memory commit.
69
+
70
+ ## Recover from bad memory
71
+
72
+ 1. Identify bad commit, PR, or update record.
73
+ 2. Disable affected `AgentMemorySource` paths if needed.
74
+ 3. Revert or fix-forward in the memory repository.
75
+ 4. Rebuild indexes.
76
+ 5. Mark affected `AgentMemorySnapshot` records as `KnownBad` without mutating their content.
77
+ 6. Notify owners of dispatches that consumed the bad memory.
78
+ 7. Add a `Decision` or `Incident` record describing remediation when appropriate.
79
+
80
+ ## Rotate or move memory repository
81
+
82
+ 1. Create a new `AgentMemoryRepository` in disabled/read-only mode.
83
+ 2. Mirror Git contents and verify digest parity.
84
+ 3. Rebuild indexes from source.
85
+ 4. Update `AgentMemorySource` policies to point to the new repository.
86
+ 5. Run dry-run context assembly for representative stacks.
87
+ 6. Switch writes after validation.
88
+ 7. Keep old repository read-only until retention expires.
89
+
90
+ ## Operational dashboards
91
+
92
+ `/agents/memory` should show:
93
+
94
+ - current commit and last successful index build;
95
+ - ontology validation state;
96
+ - pending updates and stale PRs;
97
+ - top memory consumers by repository/stack;
98
+ - recent historical-memory runs;
99
+ - denied memory queries;
100
+ - records without owners;
101
+ - stale approved records;
102
+ - secret-scan alerts.
103
+
104
+ ## Alerts
105
+
106
+ | Alert | Severity | Response |
107
+ | --- | --- | --- |
108
+ | memory index build failed | warning/critical by duration | inspect parse errors and block new writes if stale. |
109
+ | ontology validation failed on main | critical | disable update merges and surface degraded context warning. |
110
+ | secret-like content detected | critical | block merge, revoke if leaked, notify owners. |
111
+ | memory repo unreachable | warning | block required-memory dispatches; allow optional-memory dispatches with warning. |
112
+ | stale generated indexes | warning | rebuild and compare source commit. |
113
+ | historical ref cannot resolve | warning | block requested dispatch. |
114
+
115
+ ## Acceptance criteria
116
+
117
+ - Operators can bootstrap an org memory repo from UI or CRD.
118
+ - Every memory PR receives validation output before merge.
119
+ - Users can run with current, explicit-ref, snapshot-tag, or ref-at-time memory.
120
+ - Bad memory can be reverted without corrupting past run snapshots.
121
+ - Dashboards make memory health, permissions, and pending updates visible.