Edición publicada en febrero de 2026
Documento original en inglés
CSIL — Capability Self-Improvement Loop (Experimental)
Version 0.1.0
Status: DRAFT
Experimental: This is an experimental standard under development. Part of the OKHAM ecosystem.
Capability Self-Improvement Loop (CSIL) enables capabilities to observe, evaluate, propose, and remediate issues strictly within declared rules and guardrails.
1. Introduction
1.1 Motivation
OKHAM capabilities operate in distributed systems where consistency, compliance, and operational integrity are critical. Over time, capabilities may accumulate:
- Configuration drift from canonical standards
- Deprecated patterns introduced by updates
- Accumulated technical debt from rapid iteration
- Unintentional violations of new lint rules
Manual remediation is error-prone and does not scale. CSIL provides a structured, auditable mechanism for capabilities to self-correct within defined boundaries.
1.2 What CSIL Is Not
CSIL is NOT:
- Free-form self-modifying code
- Autonomous creativity or invention
- A general AI planner or reasoning engine
- A workflow orchestration system
- A mechanism for modifying policies or standards
CSIL IS:
- A declarative compliance loop
- A structured self-observation and remediation mechanism
- An auditable, traceable system
- A governed extension of existing OKHAM patterns
1.3 Fundamental Axioms
-
Self-improvement means self-conformance, not self-authority
- A capability never defines what is correct
- Standards, linters, and policies define correctness
-
No direct mutation
- All changes MUST be expressed as patches or proposals
- Live code mutation is explicitly forbidden
-
Everything is traceable
- Every step produces structured output, events, and audit logs
- Trace IDs enable end-to-end provenance
-
Guards always run
- Linters, tests, and policy checks are mandatory gates
- No bypass is permitted
-
Standards are immutable from inside
- CSIL MUST NOT modify
/docs/standards/**directly - Standard modifications require external governance
- CSIL MUST NOT modify
2. CSIL Declaration
2.1 Declaration Schema
Capabilities opt into CSIL by declaring selfGovernance in their capability.yaml:
selfGovernance:
enabled: true
profile: okham.csil.v0
level: report-only | propose | apply-guarded
guards:
- okham.lint.strict
- tests.required
- policy.check
allowedDomains:
- "*.yaml"
- "*.md"
- "Makefile"
excludedPaths:
- "**/standards/**"
- "**/.git/**"
- "**/secrets/**"
maxPatchSize: 1024
auditDestination: nats://nats:4222/okham.audit.csil
2.2 Declaration Fields
| Field | Type | Required | Description |
|---|---|---|---|
enabled |
boolean | Yes | Enables CSIL processing |
profile |
string | Yes | CSIL profile version (currently okham.csil.v0) |
level |
enum | Yes | Compliance level: report-only, propose, apply-guarded |
guards |
array | Yes | Mandatory guard checks |
allowedDomains |
array | Yes | File patterns eligible for modification |
excludedPaths |
array | Yes | Paths never eligible for modification |
maxPatchSize |
integer | Yes | Maximum bytes in a single patch |
auditDestination |
string | Yes | NATS subject for audit events |
2.3 Minimal Declaration
Capabilities may use the minimal declaration for report-only mode:
selfGovernance:
enabled: true
level: report-only
This enables observation and evaluation without generating proposals.
3. Canonical Pipeline
CSIL operates through five mandatory phases, executed in sequence:
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐
│ Observe │──►│ Evaluate│──►│ Plan │──►│ Propose │──►│ Apply │
└─────────┘ └─────────┘ └─────────┘ └─────────┘ └─────────┘
│ │ │ │ │
▼ ▼ ▼ ▼ ▼
Runtime Linting Change Patch Guarded
Context Results Strategy Proposal Application
3.1 Phase 1: Observe
Purpose: Collect current state and context for evaluation.
Inputs:
- Capability runtime context (
RuntimeContext) - File tree snapshot (within
allowedDomains) - Current git state (HEAD commit, branch)
- Previous audit records
Outputs:
ObservationReportcontaining:- File inventory with checksums
- Git metadata
- Timestamp and trace ID
Events:
{
"type": "csil.phase.observe",
"traceId": "uuid-v4",
"timestamp": "2026-01-14T12:00:00Z",
"capabilityId": "my-capability",
"filesObserved": 42,
"gitBranch": "main",
"gitCommit": "abc123"
}
3.2 Phase 2: Evaluate
Purpose: Run all configured evaluators against observed state.
Inputs:
ObservationReportfrom Observe phase- Configured evaluators (linters, validators, health checks)
Outputs:
EvaluationReportcontaining:- All findings from each evaluator
- Categorized by severity and domain
- Violations with rule references
Evaluators (standard):
okham-lint(strict mode if configured)- Catalog validator
- Documentation drift detector
- Health check executor
Events:
{
"type": "csil.phase.evaluate",
"traceId": "uuid-v4",
"findingsCount": 5,
"violations": [
{
"rule": "DOC-001",
"severity": "ERROR",
"file": "docs/DEVELOPMENT/LOGGING.md",
"line": 3
}
]
}
3.3 Phase 3: Plan
Purpose: Determine remediation strategy based on findings.
Inputs:
EvaluationReportfrom Evaluate phase- Capability's
levelconfiguration
Outputs:
ChangePlancontaining:- Proposed changes with rationale
- Impact assessment
- Risk classification
Planning Rules:
- Only violations with fixes SHOULD generate proposals
- Multiple violations of same rule MAY be batched
report-onlylevel produces no plan (terminates here)- Proceeding beyond Plan requires non-zero violations
Events:
{
"type": "csil.phase.plan",
"traceId": "uuid-v4",
"violationsFound": 5,
"violationsFixable": 3,
"planId": "plan-uuid"
}
3.4 Phase 4: Propose
Purpose: Generate patch artifacts for approved changes.
Inputs:
ChangePlanfrom Plan phase- Allowed file patterns
Outputs:
PatchSetcontaining:- Unified diff format patches
- Original and modified content
- Patch metadata (author, timestamp, trace)
Constraints:
- Patches MUST be deterministic (same input → same output)
- Patches MUST not exceed
maxPatchSize - Patches MUST not modify excluded paths
- Patches MUST be reviewable in isolation
Events:
{
"type": "csil.phase.propose",
"traceId": "uuid-v4",
"patchesGenerated": 3,
"totalBytes": 512,
"patchSetId": "patchset-uuid"
}
3.5 Phase 5: Apply (Guarded)
Purpose: Apply patches through mandatory gates.
Inputs:
PatchSetfrom Propose phase- Configured
guards
Outputs:
GateResultfor each guard- Applied patches or rejection
- Final audit record
Mandatory Gates:
- Lint gate:
okham-lint --strictpasses - Test gate: All tests pass (if present)
- Policy gate: Custom policy checks pass
Decision Logic:
IF all gates pass:
Apply patches
Emit "csil.apply.success"
ELSE:
Reject patches
Emit "csil.apply.rejected"
Include gate failure details
Events:
{
"type": "csil.phase.apply",
"traceId": "uuid-v4",
"gatesPassed": 3,
"gatesFailed": 0,
"patchesApplied": 3,
"decision": "applied"
}
4. Canonical Types
CSIL uses OTC-defined types where possible. This section defines CSIL-specific extensions.
4.1 Finding
type: okham_core_csil.finding
version: "1.0.0"
properties:
id: string # Unique finding identifier
rule: string # Rule identifier (e.g., "DOC-001")
severity: enum # ERROR, WARN, INFO
domain: string # e.g., "docs", "catalog", "code"
file: string # Relative path
line: integer # Line number (optional)
message: string # Human-readable message
context: string # Code/content snippet
4.2 Violation
type: okham_core_csil.violation
version: "1.0.0"
properties:
finding: Finding # Reference to finding
fixable: boolean # Whether auto-fix is possible
fixComplexity: enum # trivial, simple, complex
requiredGuards: array # Guards required for this violation
4.3 ChangePlan
type: okham_core_csil.change-plan
version: "1.0.0"
properties:
planId: string # Unique plan identifier
capabilityId: string # Source capability
violations: array # List of Violation
changes: array # ProposedChange items
riskLevel: enum # low, medium, high
rationale: string # Explanation of changes
4.4 ProposedChange
type: okham_core_csil.proposed-change
version: "1.0.0"
properties:
file: string # Target file path
originalChecksum: string # SHA-256 before change
modifiedChecksum: string # SHA-256 after change
patch: string # Unified diff
changeType: enum # create, modify, delete
4.5 GateResult
type: okham_core_csil.gate-result
version: "1.0.0"
properties:
gateId: string # Gate identifier
passed: boolean # Pass/fail status
output: string # Command output
durationMs: integer # Execution time
error: string # Error message if failed
4.6 AuditRecord
type: okham_core_csil.audit-record
version: "1.0.0"
properties:
traceId: string # End-to-end trace identifier
capabilityId: string # Source capability
level: enum # report-only, propose, apply-guarded
phasesCompleted: array # Phases executed
findingsCount: integer # Total findings
patchesGenerated: integer # Patches in propose phase
patchesApplied: integer # Patches actually applied
gatesPassed: integer # Gates that passed
gatesFailed: integer # Gates that failed
durationMs: integer # Total execution time
outcome: enum # success, partial, rejected
timestamp: string # ISO 8601 timestamp
5. OIC Integration
CSIL phases map to OIC intents for execution. This section defines the binding without redefining OIC.
5.1 Phase-to-Intent Mapping
| Phase | OIC Intent | Description |
|---|---|---|
| Observe | runtime.observe |
Collect capability state |
| Evaluate | runtime.evaluate |
Run evaluators against state |
| Plan | runtime.plan |
Determine remediation strategy |
| Propose | repo.patch.propose |
Generate patch artifacts |
| Apply | repo.patch.apply |
Execute guarded application |
5.2 Intent Structure
Each intent follows OIC structure:
intent:
id: "intent-uuid"
type: "{phase}.{action}"
actor: "csil/{capability-id}"
timestamp: "2026-01-14T12:00:00Z"
payload:
# Phase-specific payload
5.3 Execution Binding
CSIL executes intents through the OKHAM runtime:
// Example: Execute evaluate phase
intent := clic.Intent{
Type: "runtime.evaluate",
Actor: "csil/my-capability",
Payload: observationReport,
}
result := rt.MCP.ExecuteIntent(intent)
6. OHB Triggers
CSIL can be triggered by standard Open Hook Bindings (OHB) events.
6.1 Standard Triggers
| Event | Condition | CSIL Response |
|---|---|---|
lint.failed |
Any lint rule fails | Run full pipeline |
catalog.invalid |
Catalog validation fails | Run evaluate + plan |
docs.drift.detected |
Doc drift detected | Run full pipeline |
capability.health.degraded |
Health check fails | Run evaluate only |
scheduled |
Cron-based trigger | Run full pipeline |
6.2 Trigger Binding
hooks:
- trigger: lint.failed
action: csil.execute
config:
phases: ["observe", "evaluate", "plan", "propose", "apply"]
6.3 Trigger Sources
CSIL triggers MUST originate from:
- OKHAM runtime health system
- CI/CD pipeline webhooks
- Scheduled cron jobs
- Manual invocation via MCP tool
7. Guardrails (CRITICAL)
7.1 Prohibited Actions
CSIL MUST NOT:
-
Modify standards directly
/docs/standards/**is always inexcludedPaths- Standard changes require external governance
-
Disable or bypass linters
- Guard configuration cannot exclude rules
- Lint output is always captured
-
Escalate permissions
- Cannot modify file permissions
- Cannot add or modify system users
-
Apply changes without passing gates
- All configured
guardsMUST pass - Partial application is forbidden
- All configured
-
Hide or suppress audit data
- All phases emit events
- Audit records cannot be deleted
- Trace IDs are mandatory
-
Modify secrets, credentials, or keys
- Files matching
**/secrets/**are always excluded
- Files matching
-
Modify git history
- Cannot amend, rebase, or force-push
- Only forward commits are allowed
7.2 Mandatory Gates
Every apply-guarded execution MUST pass:
-
Lint Gate
okham-lint --strict -
Test Gate (if tests exist)
go test ./... -
Policy Gate (if configured)
- Custom policy checks defined in capability
7.3 Guard Configuration
guards:
- okham.lint.strict # Always required
- tests.required # Required if tests exist
- policy.check # Optional, depends on capability
7.4 Gate Failure Handling
On any gate failure:
- Patches are NOT applied
- Audit record is emitted with failure details
- Trace ID enables root cause analysis
- Operator notification is triggered
8. Compliance Levels
CSIL defines three compliance levels. Higher levels require explicit opt-in and governance approval.
8.1 Level 0: Report Only
Description: Findings and recommendations only. No changes generated.
Configuration:
selfGovernance:
enabled: true
level: report-only
Behavior:
- Observe phase: Executes
- Evaluate phase: Executes
- Plan phase: Executes (produces report)
- Propose phase: Skipped
- Apply phase: Skipped
Audit Outputs:
- Observation report
- Evaluation report
- Change plan (read-only)
Safe Default: Yes. Suitable for all capabilities.
8.2 Level 1: Propose
Description: Generates patches or pull requests. No auto-application.
Configuration:
selfGovernance:
enabled: true
level: propose
guards:
- okham.lint.strict
Behavior:
- Observe phase: Executes
- Evaluate phase: Executes
- Plan phase: Executes
- Propose phase: Executes (generates patches)
- Apply phase: Skipped
Audit Outputs:
- All L0 outputs
- Patch set (for review)
Requires: Explicit opt-in. Patches require human review.
8.3 Level 2: Apply Guarded
Description: Applies changes only after all gates pass.
Configuration:
selfGovernance:
enabled: true
level: apply-guarded
guards:
- okham.lint.strict
- tests.required
- policy.check
allowedDomains:
- "**/*.yaml"
- "**/*.md"
- "Makefile"
excludedPaths:
- "**/standards/**"
- "**/.git/**"
- "**/secrets/**"
maxPatchSize: 1024
Behavior:
- Observe phase: Executes
- Evaluate phase: Executes
- Plan phase: Executes
- Propose phase: Executes
- Apply phase: Executes (gated)
Audit Outputs:
- All L1 outputs
- Gate results
- Before/after diffs
- Final audit record
Requires: Explicit opt-in + governance approval. Suitable for mature capabilities.
8.4 Level Selection Matrix
| Capability Maturity | Recommended Level | Rationale |
|---|---|---|
| Experimental | L0 | High uncertainty, safe observation |
| Development | L0 or L1 | Review required for changes |
| Stable | L1 or L2 | Confidence in changes |
| Production | L2 | Requires full guardrails |
9. Audit and Transparency
9.1 Mandatory Outputs
Every CSIL execution produces:
-
Structured Reports
- JSON format for machine processing
- Human-readable summaries
-
Trace IDs
- UUIDv4 for each execution
- Propagated through all phases
- Enables end-to-end correlation
-
Before/After Diffs
- Unified diff format
- Checksums for integrity
-
Decision Outcomes
- Explicit pass/fail for each gate
- Rationale for rejected patches
9.2 Audit Event Schema
All audit events follow this schema:
audit:
traceId: "uuid-v4" # Required
capabilityId: "my-capability" # Required
timestamp: "2026-01-14T12:00:00Z" # Required
level: "apply-guarded"
outcome: "success" | "partial" | "rejected"
phases:
- name: "observe"
durationMs: 150
status: "success"
- name: "evaluate"
durationMs: 320
status: "success"
findings: 5
- name: "plan"
durationMs: 80
status: "success"
changesProposed: 3
- name: "propose"
durationMs: 200
status: "success"
patches: 3
- name: "apply"
durationMs: 500
status: "success"
gates:
- id: "okham.lint.strict"
passed: true
- id: "tests.required"
passed: true
- id: "policy.check"
passed: true
9.3 Audit Destination
Audit events are published to NATS:
auditDestination: "nats://nats:4222/okham.audit.csil"
Subscribers can include:
- Monitoring systems
- Audit log aggregation
- Compliance dashboards
- Human notification channels
10. End-to-End Example
10.1 Scenario
A capability, my-camera-mgmt, has accumulated documentation drift. A lint check (DOC-001) fails due to missing non-normative disclaimer.
10.2 Execution Flow
1. Trigger
Event: lint.failed
Rule: DOC-001
File: docs/DEVELOPMENT/LOGGING.md
2. Observe Phase
Input: RuntimeContext, file tree
Output:
- Files observed: 23
- Git branch: main
- Git commit: abc123def
- TraceId: 550e8400-e29b-41d4-a716-446655440000
3. Evaluate Phase
Lint Output:
[ERROR] DOC-001: docs/DEVELOPMENT/LOGGING.md:3
Normative language outside /docs/standards
Found: "All logging in OKHAM capabilities MUST use..."
Evaluation Report:
findings:
- rule: DOC-001
severity: ERROR
file: docs/DEVELOPMENT/LOGGING.md
line: 3
message: "Normative language outside /docs/standards"
4. Plan Phase
Change Plan:
- Violation: DOC-001 (fixable)
- Change: Replace "MUST" with "should"
- Risk: low
- Rationale: Non-blocking lint violation, safe change
5. Propose Phase
Patch Set:
@@ -1,5 +1,5 @@
# Logging
> **Non-normative**: This document provides implementation guidance.
-All logging in OKHAM capabilities MUST use...
+All logging in OKHAM capabilities should use...
6. Apply Phase (L2 only)
Gates:
1. okham-lint --strict: PASS
2. go test ./...: PASS
3. policy.check: PASS
Result: APPLIED
10.3 Audit Record
{
"traceId": "550e8400-e29b-41d4-a716-446655440000",
"capabilityId": "my-camera-mgmt",
"level": "apply-guarded",
"phasesCompleted": ["observe", "evaluate", "plan", "propose", "apply"],
"findingsCount": 1,
"patchesGenerated": 1,
"patchesApplied": 1,
"gatesPassed": 3,
"gatesFailed": 0,
"durationMs": 1250,
"outcome": "success",
"timestamp": "2026-01-14T12:00:01.250Z"
}
11. Non-Goals
The following are explicitly OUT OF SCOPE for CSIL:
-
Free-form reasoning
- CSIL does not enable AI or LLM-based reasoning
- All decisions are rule-based
-
Creative refactoring
- Only violations generate changes
- No architectural improvements or optimizations
-
Multi-capability orchestration
- CSIL operates on single capabilities
- Cross-capability coordination is not defined
-
Cross-standard modification
- Cannot modify
/docs/standards/** - Policy definition is external to CSIL
- Cannot modify
-
Live code mutation
- Patches are declarative artifacts
- Runtime code modification is forbidden
-
Permission escalation
- Cannot modify access controls
- Cannot add capabilities
12. Implementation Guidance
12.1 Minimal Implementation
To implement CSIL minimally:
- Implement
Observephase (file snapshot + git state) - Integrate
okham-lintforEvaluatephase - Generate JSON report for
Planphase - Stop at
Plan(L0 compliance)
12.2 Progressive Implementation
| Phase | Complexity | Effort |
|---|---|---|
| Observe | Low | 1 day |
| Evaluate | Low | 1 day |
| Plan | Medium | 2 days |
| Propose | Medium | 3 days |
| Apply | High | 5 days |
12.3 Testing Strategy
- Unit Tests: Each phase in isolation
- Integration Tests: Full pipeline execution
- Guard Tests: Verify gate failure handling
- Security Tests: Attempt prohibited actions (should fail)
- Audit Tests: Verify trace ID propagation
13. Future Considerations
This is an EXPERIMENTAL standard. Future versions may address:
- Patch batching: Group multiple violations
- Rollback capability: Revert applied changes
- Dry-run mode: Preview changes without execution
- Distributed CSIL: Multi-capability coordination
- Policy templates: Standard guard configurations
14. References
- OCC Specification
- CTC Specification
- CLIC Specification
- OHB Specification
- Linting Specification
- WCAG 2.1
Appendix A: Quick Reference
CSIL Declaration
selfGovernance:
enabled: true
profile: okham.csil.v0
level: report-only | propose | apply-guarded
guards: [...]
allowedDomains: [...]
excludedPaths: [...]
maxPatchSize: 1024
auditDestination: nats://...
Pipeline Phases
| Phase | Input | Output | Mandatory |
|---|---|---|---|
| Observe | RuntimeContext | ObservationReport | Yes |
| Evaluate | ObservationReport | EvaluationReport | Yes |
| Plan | EvaluationReport | ChangePlan | Yes |
| Propose | ChangePlan | PatchSet | No (L0) |
| Apply | PatchSet | AuditRecord | No (L0/L1) |
Compliance Levels
| Level | Changes | Auto-Apply | Requires Approval |
|---|---|---|---|
| L0 | Report only | No | No |
| L1 | Proposals | No | Yes |
| L2 | Patches | Yes (gated) | Yes + governance |
Mandatory Guards
okham.lint.stricttests.required(if tests exist)policy.check(if configured)