loki-mode 5.51.0 → 5.52.1
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.
- package/README.md +4 -56
- package/SKILL.md +2 -2
- package/VERSION +1 -1
- package/autonomy/hooks/validate-bash.sh +5 -2
- package/dashboard/__init__.py +1 -1
- package/dashboard/server.py +1 -1
- package/docs/INSTALLATION.md +1 -1
- package/docs/alternative-installations.md +3 -3
- package/docs/certification/01-core-concepts/lab.md +174 -0
- package/docs/certification/01-core-concepts/lesson.md +182 -0
- package/docs/certification/01-core-concepts/quiz.md +93 -0
- package/docs/certification/02-enterprise-features/lab.md +154 -0
- package/docs/certification/02-enterprise-features/lesson.md +202 -0
- package/docs/certification/02-enterprise-features/quiz.md +93 -0
- package/docs/certification/03-advanced-patterns/lab.md +138 -0
- package/docs/certification/03-advanced-patterns/lesson.md +199 -0
- package/docs/certification/03-advanced-patterns/quiz.md +93 -0
- package/docs/certification/04-production-deployment/lab.md +160 -0
- package/docs/certification/04-production-deployment/lesson.md +261 -0
- package/docs/certification/04-production-deployment/quiz.md +93 -0
- package/docs/certification/05-troubleshooting/lab.md +254 -0
- package/docs/certification/05-troubleshooting/lesson.md +266 -0
- package/docs/certification/05-troubleshooting/quiz.md +93 -0
- package/docs/certification/README.md +80 -0
- package/docs/certification/answer-key.md +117 -0
- package/docs/certification/certification-exam.md +471 -0
- package/docs/certification/sample-prds/microservices-platform.md +100 -0
- package/docs/certification/sample-prds/saas-dashboard.md +60 -0
- package/docs/certification/sample-prds/todo-app.md +44 -0
- package/mcp/__init__.py +1 -1
- package/mcp/server.py +230 -0
- package/package.json +1 -1
- package/src/plugins/agent-plugin.js +123 -0
- package/src/plugins/gate-plugin.js +153 -0
- package/src/plugins/index.js +116 -0
- package/src/plugins/integration-plugin.js +174 -0
- package/src/plugins/loader.js +275 -0
- package/src/plugins/mcp-plugin.js +190 -0
- package/src/plugins/schemas/agent.json +59 -0
- package/src/plugins/schemas/integration.json +62 -0
- package/src/plugins/schemas/mcp_tool.json +73 -0
- package/src/plugins/schemas/quality_gate.json +52 -0
- package/src/plugins/validator.js +297 -0
- /package/dashboard/{secrets.py → app_secrets.py} +0 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
# Module 3: Advanced Patterns
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This module covers advanced patterns in Loki Mode: specialist review configuration, structured agent prompting, confidence-based routing, Chain-of-Verification, compound learning, and the event-driven hooks system.
|
|
6
|
+
|
|
7
|
+
## Structured Agent Prompting
|
|
8
|
+
|
|
9
|
+
Every Task dispatch in Loki Mode must include four sections: GOAL, CONSTRAINTS, CONTEXT, and OUTPUT. This template is documented in `skills/agents.md`.
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
Task(
|
|
13
|
+
subagent_type="general-purpose",
|
|
14
|
+
model="opus",
|
|
15
|
+
description="Implement user registration API",
|
|
16
|
+
prompt="""
|
|
17
|
+
## GOAL
|
|
18
|
+
Create POST /api/users endpoint that registers new users.
|
|
19
|
+
Success: Endpoint works, tests pass, matches OpenAPI spec.
|
|
20
|
+
|
|
21
|
+
## CONSTRAINTS
|
|
22
|
+
- Use bcrypt for password hashing (already in dependencies)
|
|
23
|
+
- No new dependencies without approval
|
|
24
|
+
- Response time < 200ms
|
|
25
|
+
|
|
26
|
+
## CONTEXT
|
|
27
|
+
- Existing auth pattern: src/auth/login.ts
|
|
28
|
+
- OpenAPI spec: .loki/specs/openapi.yaml
|
|
29
|
+
- User model: src/models/user.ts
|
|
30
|
+
|
|
31
|
+
## OUTPUT
|
|
32
|
+
- [ ] Endpoint implementation in src/routes/users.ts
|
|
33
|
+
- [ ] Unit tests in tests/users.test.ts
|
|
34
|
+
- [ ] Integration test in tests/integration/users.test.ts
|
|
35
|
+
"""
|
|
36
|
+
)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
This structure ensures agents have clear success criteria, boundaries, necessary context, and defined deliverables.
|
|
40
|
+
|
|
41
|
+
## Confidence-Based Routing
|
|
42
|
+
|
|
43
|
+
Loki Mode uses confidence scores to determine how much oversight a task needs. This is enabled by default (`LOKI_CONFIDENCE_ROUTING=true`).
|
|
44
|
+
|
|
45
|
+
| Confidence | Dispatch Strategy |
|
|
46
|
+
|------------|-------------------|
|
|
47
|
+
| >= 0.95 | Direct execution with fast-tier model, no review |
|
|
48
|
+
| 0.70-0.95 | Direct execution + asynchronous review |
|
|
49
|
+
| 0.40-0.70 | Supervisor orchestration, mandatory review |
|
|
50
|
+
| < 0.40 | Flag for human decision |
|
|
51
|
+
|
|
52
|
+
Confidence is calculated from five factors:
|
|
53
|
+
|
|
54
|
+
- Requirement clarity (30%)
|
|
55
|
+
- Similar past successes (20%)
|
|
56
|
+
- Technical complexity match (25%)
|
|
57
|
+
- Resource availability (15%)
|
|
58
|
+
- Time pressure (10%)
|
|
59
|
+
|
|
60
|
+
When confidence is below 0.40, the agent creates a `HUMAN_REVIEW_NEEDED` signal in `.loki/signals/` and blocks the task until human input is received.
|
|
61
|
+
|
|
62
|
+
## Chain-of-Verification (CoVe)
|
|
63
|
+
|
|
64
|
+
Based on research from arXiv 2309.11495, CoVe reduces hallucination by using factored, independent verification. The key insight: the verifier cannot see the original response, preventing confirmation bias.
|
|
65
|
+
|
|
66
|
+
### The 4-Step Process
|
|
67
|
+
|
|
68
|
+
1. **Draft** -- Generate initial code or response
|
|
69
|
+
2. **Plan** -- Self-generate verification questions ("What could be wrong?")
|
|
70
|
+
3. **Execute** -- Answer each question INDEPENDENTLY with no access to the original response
|
|
71
|
+
4. **Revise** -- Incorporate corrections into the final output
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
Draft --> Plan verification questions --> Execute each independently --> Revise
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The critical detail is step 3: each verification runs in isolation. The verifier sees only the verification question and minimal context, not the original draft. This prevents the model from rationalizing its initial mistakes.
|
|
78
|
+
|
|
79
|
+
### Integration with Blind Review
|
|
80
|
+
|
|
81
|
+
CoVe operates as a self-correction step BEFORE the blind review system:
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
Developer Code --> CoVe (self-verification) --> Blind Review (3 parallel reviewers)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
CoVe catches errors early via factored checking. Blind review catches remaining issues independently.
|
|
88
|
+
|
|
89
|
+
## Specialist Review Pool
|
|
90
|
+
|
|
91
|
+
The 5-specialist pool (detailed in `skills/quality-gates.md`) uses trigger-keyword matching to select the most relevant reviewers:
|
|
92
|
+
|
|
93
|
+
| Specialist | Trigger Keywords |
|
|
94
|
+
|-----------|-----------------|
|
|
95
|
+
| security-sentinel | auth, login, password, token, api, sql, query, cookie, cors, csrf |
|
|
96
|
+
| performance-oracle | database, query, cache, render, loop, fetch, load, index, join, pool |
|
|
97
|
+
| architecture-strategist | (always included) |
|
|
98
|
+
| test-coverage-auditor | test, spec, coverage, assert, mock, fixture, expect, describe |
|
|
99
|
+
| dependency-analyst | package, import, require, dependency, npm, pip, yarn, lock |
|
|
100
|
+
|
|
101
|
+
**Selection rules:**
|
|
102
|
+
1. architecture-strategist fills slot 1 (always)
|
|
103
|
+
2. Score remaining 4 specialists by counting keyword matches in the diff
|
|
104
|
+
3. Top 2 fill the remaining slots
|
|
105
|
+
4. Tie-breaker priority: security-sentinel > test-coverage-auditor > performance-oracle > dependency-analyst
|
|
106
|
+
|
|
107
|
+
## Two-Stage Review Protocol
|
|
108
|
+
|
|
109
|
+
Code review is split into two distinct stages. Mixing them causes "technically correct but wrong feature" problems.
|
|
110
|
+
|
|
111
|
+
**Stage 1: Spec Compliance** -- "Does this code implement what the spec requires?"
|
|
112
|
+
- 1 reviewer (spec compliance is objective)
|
|
113
|
+
- Must pass before proceeding to Stage 2
|
|
114
|
+
|
|
115
|
+
**Stage 2: Code Quality** -- "Is this code well-written, maintainable, secure?"
|
|
116
|
+
- 3 reviewers (blind, parallel)
|
|
117
|
+
- Anti-sycophancy check on unanimous approval
|
|
118
|
+
|
|
119
|
+
If Stage 1 fails, return to implementation. Do NOT proceed to Stage 2 (reviewing quality of wrong code wastes resources).
|
|
120
|
+
|
|
121
|
+
## Compound Learning (v5.30.0)
|
|
122
|
+
|
|
123
|
+
The compound learning system extracts reusable knowledge from completed tasks. It has two phases:
|
|
124
|
+
|
|
125
|
+
**Deepen-Plan Phase:** Before implementation begins, 4 parallel research agents enhance the plan:
|
|
126
|
+
- Technical feasibility researcher
|
|
127
|
+
- Similar project pattern finder
|
|
128
|
+
- Risk assessment analyst
|
|
129
|
+
- Dependency compatibility checker
|
|
130
|
+
|
|
131
|
+
**Knowledge Extraction Phase:** After verification passes, if a task produced a novel insight (bug fix, non-obvious solution, reusable pattern), it is extracted to `~/.loki/solutions/{category}/{slug}.md` with YAML frontmatter:
|
|
132
|
+
|
|
133
|
+
```yaml
|
|
134
|
+
---
|
|
135
|
+
title: Fix bcrypt timing attack in login endpoint
|
|
136
|
+
tags: [security, auth, bcrypt, timing]
|
|
137
|
+
symptoms: Login endpoint vulnerable to timing analysis
|
|
138
|
+
root_cause: Using string comparison instead of constant-time comparison
|
|
139
|
+
prevention: Always use crypto.timingSafeEqual for secret comparison
|
|
140
|
+
---
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
CLI commands for compound learning:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
loki compound list # List extracted solutions
|
|
147
|
+
loki compound show # Show a specific solution
|
|
148
|
+
loki compound search # Search solutions by keyword
|
|
149
|
+
loki compound run # Run extraction on recent tasks
|
|
150
|
+
loki compound stats # Show extraction statistics
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Event-Driven Hooks
|
|
154
|
+
|
|
155
|
+
The hooks system (documented in `skills/testing.md`) triggers quality checks on file operations:
|
|
156
|
+
|
|
157
|
+
```yaml
|
|
158
|
+
triggers:
|
|
159
|
+
on_file_write:
|
|
160
|
+
- lint: "npx eslint --fix {file}"
|
|
161
|
+
- typecheck: "npx tsc --noEmit"
|
|
162
|
+
- secrets_scan: "detect-secrets scan {file}"
|
|
163
|
+
on_task_complete:
|
|
164
|
+
- contract_test: "npm run test:contract"
|
|
165
|
+
- spec_lint: "spectral lint .loki/specs/openapi.yaml"
|
|
166
|
+
on_phase_complete:
|
|
167
|
+
- memory_consolidate: "Extract patterns to semantic memory"
|
|
168
|
+
- metrics_update: "Log efficiency scores"
|
|
169
|
+
- checkpoint: "git commit with phase summary"
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
This catches issues 5-10x earlier than waiting for phase-end review.
|
|
173
|
+
|
|
174
|
+
## Agent Handoffs
|
|
175
|
+
|
|
176
|
+
When one agent completes work and another needs to continue, structured handoff data is passed:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
handoff_data = {
|
|
180
|
+
"completed_work": "Implemented user registration endpoint",
|
|
181
|
+
"files_modified": ["src/routes/users.ts", "tests/users.test.ts"],
|
|
182
|
+
"decisions_made": ["Used bcrypt, not argon2", "Email validation via regex"],
|
|
183
|
+
"open_questions": ["Rate limiting not implemented yet"],
|
|
184
|
+
"mistakes_learned": ["First attempt had SQL injection - fixed"]
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
Task(
|
|
188
|
+
subagent_type="general-purpose",
|
|
189
|
+
model="sonnet",
|
|
190
|
+
description="Integration testing for user registration",
|
|
191
|
+
prompt=f"Previous agent completed: {handoff_data}. Now write integration tests..."
|
|
192
|
+
)
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Handoff messages follow the A2A-inspired format and are stored in `.loki/messages/`.
|
|
196
|
+
|
|
197
|
+
## Summary
|
|
198
|
+
|
|
199
|
+
Advanced patterns in Loki Mode include structured prompting (GOAL/CONSTRAINTS/CONTEXT/OUTPUT), confidence-based routing for oversight calibration, Chain-of-Verification for self-correction, keyword-triggered specialist review selection, two-stage review separation, compound learning for knowledge extraction, and event-driven hooks for early issue detection. These patterns are documented in `skills/agents.md`, `skills/quality-gates.md`, `skills/testing.md`, and `skills/compound-learning.md`.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Module 3 Quiz: Advanced Patterns
|
|
2
|
+
|
|
3
|
+
Answer each question by selecting the best option (A, B, C, or D).
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
**Question 1:** What are the four required sections in a structured agent prompt?
|
|
8
|
+
|
|
9
|
+
A) Task, Input, Process, Output
|
|
10
|
+
B) Goal, Constraints, Context, Output
|
|
11
|
+
C) Objective, Scope, Resources, Deliverables
|
|
12
|
+
D) Summary, Details, Requirements, Acceptance
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
**Question 2:** In confidence-based routing, what happens when a task's confidence score is below 0.40?
|
|
17
|
+
|
|
18
|
+
A) The task is executed with the cheapest model
|
|
19
|
+
B) The task is automatically retried 3 times
|
|
20
|
+
C) The task is flagged for human decision
|
|
21
|
+
D) The task is split into smaller subtasks
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
**Question 3:** What is the critical feature of Step 3 (Execute) in the Chain-of-Verification process?
|
|
26
|
+
|
|
27
|
+
A) All verifications run sequentially in the same context
|
|
28
|
+
B) The verifier has full access to the original response for comparison
|
|
29
|
+
C) Each verification runs independently with NO access to the original response
|
|
30
|
+
D) A human must approve each verification question
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
**Question 4:** In the specialist review pool, what is the tie-breaker priority order?
|
|
35
|
+
|
|
36
|
+
A) performance-oracle > dependency-analyst > security-sentinel > test-coverage-auditor
|
|
37
|
+
B) security-sentinel > test-coverage-auditor > performance-oracle > dependency-analyst
|
|
38
|
+
C) test-coverage-auditor > security-sentinel > dependency-analyst > performance-oracle
|
|
39
|
+
D) dependency-analyst > performance-oracle > test-coverage-auditor > security-sentinel
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
**Question 5:** Why is code review split into two stages (spec compliance and code quality)?
|
|
44
|
+
|
|
45
|
+
A) To reduce the number of reviewers needed
|
|
46
|
+
B) To prevent approving well-written code that implements the wrong feature
|
|
47
|
+
C) To allow junior developers to handle Stage 1
|
|
48
|
+
D) To make the review process faster
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
**Question 6:** What triggers the compound learning knowledge extraction phase?
|
|
53
|
+
|
|
54
|
+
A) Every task completion regardless of outcome
|
|
55
|
+
B) Only when a task produces a novel insight (bug fix, non-obvious solution, reusable pattern)
|
|
56
|
+
C) Only when the project reaches the DEPLOYMENT phase
|
|
57
|
+
D) Only when manually invoked with `loki compound run`
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
**Question 7:** Which agent is ALWAYS included in the deepen-plan research phase?
|
|
62
|
+
|
|
63
|
+
A) There are no fixed agents; all 4 are selected dynamically
|
|
64
|
+
B) The security risk assessor
|
|
65
|
+
C) All 4 research agents always run in parallel
|
|
66
|
+
D) Only the technical feasibility researcher
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
**Question 8:** What is the purpose of the `on_file_write` hook trigger?
|
|
71
|
+
|
|
72
|
+
A) To back up files before they are modified
|
|
73
|
+
B) To run lint, typecheck, and secrets scanning immediately after a file is written
|
|
74
|
+
C) To log all file changes to the audit trail
|
|
75
|
+
D) To prevent agents from writing to protected files
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
**Question 9:** In the two-stage review protocol, what happens if Stage 1 (spec compliance) fails?
|
|
80
|
+
|
|
81
|
+
A) The code goes directly to Stage 2 for quality feedback
|
|
82
|
+
B) The review is cancelled and a new agent is assigned
|
|
83
|
+
C) The code returns to implementation; Stage 2 is NOT started
|
|
84
|
+
D) Both stages run in parallel anyway to save time
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
**Question 10:** What information is included in a structured agent handoff?
|
|
89
|
+
|
|
90
|
+
A) Only the list of files modified
|
|
91
|
+
B) Completed work, files modified, decisions made, open questions, and mistakes learned
|
|
92
|
+
C) Only the task ID and completion status
|
|
93
|
+
D) A full copy of the agent's conversation history
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# Module 4 Lab: Deploy with Docker Compose
|
|
2
|
+
|
|
3
|
+
## Objective
|
|
4
|
+
|
|
5
|
+
Deploy Loki Mode using Docker Compose, verify the dashboard is accessible, and configure resource limits.
|
|
6
|
+
|
|
7
|
+
## Prerequisites
|
|
8
|
+
|
|
9
|
+
- Docker and Docker Compose installed
|
|
10
|
+
- Loki Mode source or repository cloned
|
|
11
|
+
- An AI provider API key (e.g., `ANTHROPIC_API_KEY` for Claude)
|
|
12
|
+
|
|
13
|
+
## Step 1: Review the Docker Compose Configuration
|
|
14
|
+
|
|
15
|
+
Examine the `docker-compose.yml` at the repository root:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
cat docker-compose.yml
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Key elements to note:
|
|
22
|
+
- The service mounts your current directory as `/workspace` (read-write)
|
|
23
|
+
- Git config and SSH keys are mounted read-only
|
|
24
|
+
- The dashboard port 57374 is exposed
|
|
25
|
+
- GitHub token is passed through from the host environment
|
|
26
|
+
|
|
27
|
+
## Step 2: Build the Docker Image
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
docker-compose build
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This builds from the `Dockerfile` which installs:
|
|
34
|
+
- Ubuntu 24.04 base
|
|
35
|
+
- Node.js 20 LTS
|
|
36
|
+
- Python 3 with venv support
|
|
37
|
+
- Git, jq, GitHub CLI
|
|
38
|
+
- Loki Mode and its dependencies
|
|
39
|
+
|
|
40
|
+
## Step 3: Start with Docker Compose
|
|
41
|
+
|
|
42
|
+
Create a test project directory and start Loki Mode:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
mkdir -p /tmp/docker-lab && cd /tmp/docker-lab
|
|
46
|
+
git init
|
|
47
|
+
|
|
48
|
+
# Create a minimal PRD
|
|
49
|
+
cat > prd.md << 'EOF'
|
|
50
|
+
# Hello World API
|
|
51
|
+
|
|
52
|
+
## Overview
|
|
53
|
+
A simple Express.js REST API that returns "Hello, World!" on GET /.
|
|
54
|
+
|
|
55
|
+
## Requirements
|
|
56
|
+
- GET / returns JSON: {"message": "Hello, World!"}
|
|
57
|
+
- Responds with HTTP 200
|
|
58
|
+
- Unit test verifies the response
|
|
59
|
+
|
|
60
|
+
## Tech Stack
|
|
61
|
+
- Node.js with Express
|
|
62
|
+
EOF
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Start the container (this will invoke the AI provider and may incur costs):
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
# Pass your API key through to the container
|
|
69
|
+
ANTHROPIC_API_KEY=$ANTHROPIC_API_KEY docker-compose run \
|
|
70
|
+
-e ANTHROPIC_API_KEY \
|
|
71
|
+
loki start ./prd.md
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Note:** Replace `ANTHROPIC_API_KEY` with the appropriate key for your provider (`OPENAI_API_KEY` for Codex, `GOOGLE_API_KEY` for Gemini).
|
|
75
|
+
|
|
76
|
+
## Step 4: Verify the Dashboard
|
|
77
|
+
|
|
78
|
+
While the container is running, access the dashboard from your host browser:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# The dashboard should be available at:
|
|
82
|
+
open http://localhost:57374
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
If using the API:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
curl http://localhost:57374/api/health
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Step 5: Configure Resource Limits
|
|
92
|
+
|
|
93
|
+
Test resource configuration by modifying environment variables:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Run with budget limit and reduced parallel agents
|
|
97
|
+
docker-compose run \
|
|
98
|
+
-e ANTHROPIC_API_KEY \
|
|
99
|
+
-e LOKI_BUDGET_LIMIT=5.00 \
|
|
100
|
+
-e LOKI_MAX_PARALLEL_AGENTS=3 \
|
|
101
|
+
-e LOKI_MAX_ITERATIONS=50 \
|
|
102
|
+
loki start --simple ./prd.md
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Step 6: Use the Sandbox Mode
|
|
106
|
+
|
|
107
|
+
Test the sandbox mode which provides additional isolation:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# Build the sandbox image
|
|
111
|
+
loki sandbox build
|
|
112
|
+
|
|
113
|
+
# Start the sandbox
|
|
114
|
+
loki sandbox start
|
|
115
|
+
|
|
116
|
+
# Check status
|
|
117
|
+
loki sandbox status
|
|
118
|
+
|
|
119
|
+
# Open a shell inside the sandbox
|
|
120
|
+
loki sandbox shell
|
|
121
|
+
|
|
122
|
+
# View logs
|
|
123
|
+
loki sandbox logs
|
|
124
|
+
|
|
125
|
+
# Stop the sandbox
|
|
126
|
+
loki sandbox stop
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Step 7: Verify Health Monitoring
|
|
130
|
+
|
|
131
|
+
Check process and system health:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# From inside the container or on the host with loki installed:
|
|
135
|
+
loki watchdog status
|
|
136
|
+
loki secrets status
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Verification Checklist
|
|
140
|
+
|
|
141
|
+
- [ ] `docker-compose build` completes without errors
|
|
142
|
+
- [ ] `docker-compose run loki version` outputs the correct version
|
|
143
|
+
- [ ] The dashboard is accessible at `http://localhost:57374`
|
|
144
|
+
- [ ] You can pass environment variables to configure resource limits
|
|
145
|
+
- [ ] `loki sandbox` commands work (build, start, status, stop)
|
|
146
|
+
- [ ] You understand the volume mounts and their permissions (rw vs ro)
|
|
147
|
+
|
|
148
|
+
## Cleanup
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
# Stop any running containers
|
|
152
|
+
docker-compose down
|
|
153
|
+
|
|
154
|
+
# Remove test directory
|
|
155
|
+
cd ~
|
|
156
|
+
rm -rf /tmp/docker-lab
|
|
157
|
+
|
|
158
|
+
# Optional: remove the Docker image
|
|
159
|
+
docker rmi loki-mode:latest
|
|
160
|
+
```
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
# Module 4: Production Deployment
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Loki Mode can be deployed using Docker, Docker Compose, or direct installation via npm/Homebrew. This module covers deployment options, security hardening, resource management, and production configuration.
|
|
6
|
+
|
|
7
|
+
## Installation Methods
|
|
8
|
+
|
|
9
|
+
### npm (Recommended for Development)
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install -g loki-mode
|
|
13
|
+
loki version
|
|
14
|
+
loki doctor
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Docker
|
|
18
|
+
|
|
19
|
+
The Docker image is based on Ubuntu 24.04 and includes Node.js 20 LTS, Python 3, Git, jq, and the GitHub CLI.
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Pull the image
|
|
23
|
+
docker pull asklokesh/loki-mode:5.52.0
|
|
24
|
+
|
|
25
|
+
# Run interactively with workspace mounted
|
|
26
|
+
docker run -it -v $(pwd):/workspace asklokesh/loki-mode:latest
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The Dockerfile is at the repository root (`Dockerfile`). A separate `Dockerfile.sandbox` exists for sandboxed execution.
|
|
30
|
+
|
|
31
|
+
### Docker Compose
|
|
32
|
+
|
|
33
|
+
The `docker-compose.yml` at the repository root provides a ready-to-use configuration:
|
|
34
|
+
|
|
35
|
+
```yaml
|
|
36
|
+
services:
|
|
37
|
+
loki:
|
|
38
|
+
build: .
|
|
39
|
+
image: loki-mode:latest
|
|
40
|
+
volumes:
|
|
41
|
+
- .:/workspace:rw
|
|
42
|
+
- ~/.gitconfig:/home/loki/.gitconfig:ro
|
|
43
|
+
- ~/.ssh:/home/loki/.ssh:ro
|
|
44
|
+
- ~/.config/gh:/home/loki/.config/gh:ro
|
|
45
|
+
environment:
|
|
46
|
+
- LOKI_DASHBOARD=true
|
|
47
|
+
- LOKI_DASHBOARD_PORT=57374
|
|
48
|
+
- GITHUB_TOKEN
|
|
49
|
+
- GH_TOKEN
|
|
50
|
+
ports:
|
|
51
|
+
- "57374:57374"
|
|
52
|
+
working_dir: /workspace
|
|
53
|
+
stdin_open: true
|
|
54
|
+
tty: true
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Start with:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
docker-compose run loki start ./prd.md
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Key volume mounts:
|
|
64
|
+
- `.:/workspace:rw` -- Your project directory (read-write)
|
|
65
|
+
- `~/.gitconfig:/home/loki/.gitconfig:ro` -- Git configuration (read-only)
|
|
66
|
+
- `~/.ssh:/home/loki/.ssh:ro` -- SSH keys for git operations (read-only)
|
|
67
|
+
- `~/.config/gh:/home/loki/.config/gh:ro` -- GitHub CLI authentication (read-only)
|
|
68
|
+
|
|
69
|
+
### Docker Sandbox
|
|
70
|
+
|
|
71
|
+
For isolated execution with additional security:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
loki sandbox start # Start sandbox container
|
|
75
|
+
loki sandbox status # Check status
|
|
76
|
+
loki sandbox shell # Open interactive shell
|
|
77
|
+
loki sandbox logs # View container logs
|
|
78
|
+
loki sandbox stop # Stop container
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Or pass `--sandbox` to the start command:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
loki start --sandbox ./prd.md
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The sandbox uses `Dockerfile.sandbox` which adds additional isolation constraints.
|
|
88
|
+
|
|
89
|
+
## Security Hardening
|
|
90
|
+
|
|
91
|
+
### TLS for Dashboard
|
|
92
|
+
|
|
93
|
+
Enable HTTPS for the dashboard API:
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
export LOKI_TLS_CERT=/path/to/fullchain.pem
|
|
97
|
+
export LOKI_TLS_KEY=/path/to/privkey.pem
|
|
98
|
+
loki dashboard start
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Path Restrictions
|
|
102
|
+
|
|
103
|
+
Limit which directories agents can modify:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
export LOKI_ALLOWED_PATHS=/workspace/src,/workspace/tests
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Agents will only be able to write to the specified directories.
|
|
110
|
+
|
|
111
|
+
### Command Blocking
|
|
112
|
+
|
|
113
|
+
Block dangerous shell commands:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
export LOKI_BLOCKED_COMMANDS="rm -rf /,dd if=/dev/zero"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Agent Limits
|
|
120
|
+
|
|
121
|
+
Control concurrent agent spawning:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
export LOKI_MAX_PARALLEL_AGENTS=5 # Default: 10
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Staged Autonomy
|
|
128
|
+
|
|
129
|
+
Require human approval before execution:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
export LOKI_STAGED_AUTONOMY=true
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### OIDC Authentication
|
|
136
|
+
|
|
137
|
+
For SSO integration:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
export LOKI_OIDC_ISSUER=https://accounts.google.com
|
|
141
|
+
export LOKI_OIDC_CLIENT_ID=your-client-id
|
|
142
|
+
export LOKI_OIDC_AUDIENCE=your-audience
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Resource Management
|
|
146
|
+
|
|
147
|
+
### Budget Limits
|
|
148
|
+
|
|
149
|
+
Set a cost budget to auto-pause when exceeded:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
loki start --budget 10.00 ./prd.md
|
|
153
|
+
# Or via environment variable:
|
|
154
|
+
export LOKI_BUDGET_LIMIT=10.00
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Resource Monitoring
|
|
158
|
+
|
|
159
|
+
Loki Mode monitors system resources during execution:
|
|
160
|
+
|
|
161
|
+
| Variable | Default | Description |
|
|
162
|
+
|----------|---------|-------------|
|
|
163
|
+
| `LOKI_RESOURCE_CHECK_INTERVAL` | `300` | Check resources every N seconds |
|
|
164
|
+
| `LOKI_RESOURCE_CPU_THRESHOLD` | `80` | CPU % threshold to warn |
|
|
165
|
+
| `LOKI_RESOURCE_MEM_THRESHOLD` | `80` | Memory % threshold to warn |
|
|
166
|
+
|
|
167
|
+
### Iteration Limits
|
|
168
|
+
|
|
169
|
+
Control how many iterations the agent loop runs:
|
|
170
|
+
|
|
171
|
+
| Variable | Default | Description |
|
|
172
|
+
|----------|---------|-------------|
|
|
173
|
+
| `LOKI_MAX_ITERATIONS` | `1000` | Max loop iterations before exit |
|
|
174
|
+
| `LOKI_MAX_RETRIES` | `50` | Max retry attempts on failure |
|
|
175
|
+
| `LOKI_PERPETUAL_MODE` | `false` | Ignore all completion signals |
|
|
176
|
+
|
|
177
|
+
### Parallel Execution
|
|
178
|
+
|
|
179
|
+
For parallel mode with git worktrees (Claude only):
|
|
180
|
+
|
|
181
|
+
```bash
|
|
182
|
+
loki start --parallel ./prd.md
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
| Variable | Default | Description |
|
|
186
|
+
|----------|---------|-------------|
|
|
187
|
+
| `LOKI_PARALLEL_MODE` | `false` | Enable worktree-based parallelism |
|
|
188
|
+
| `LOKI_MAX_WORKTREES` | `5` | Maximum parallel worktrees |
|
|
189
|
+
| `LOKI_MAX_PARALLEL_SESSIONS` | `3` | Maximum concurrent AI sessions |
|
|
190
|
+
|
|
191
|
+
## Completion Council
|
|
192
|
+
|
|
193
|
+
The completion council prevents premature termination and infinite loops. It is a group of agents that vote on whether the project is truly complete.
|
|
194
|
+
|
|
195
|
+
| Variable | Default | Description |
|
|
196
|
+
|----------|---------|-------------|
|
|
197
|
+
| `LOKI_COUNCIL_ENABLED` | `true` | Enable completion council |
|
|
198
|
+
| `LOKI_COUNCIL_SIZE` | `3` | Number of council members |
|
|
199
|
+
| `LOKI_COUNCIL_THRESHOLD` | `2` | Votes needed for completion |
|
|
200
|
+
| `LOKI_COUNCIL_CHECK_INTERVAL` | `5` | Check every N iterations |
|
|
201
|
+
| `LOKI_COUNCIL_MIN_ITERATIONS` | `3` | Min iterations before council runs |
|
|
202
|
+
| `LOKI_COUNCIL_STAGNATION_LIMIT` | `5` | Max iterations with no git changes |
|
|
203
|
+
|
|
204
|
+
CLI commands:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
loki council status # Check council state
|
|
208
|
+
loki council verdicts # View past verdicts
|
|
209
|
+
loki council convergence # Check convergence metrics
|
|
210
|
+
loki council force-review # Force a council review
|
|
211
|
+
loki council report # Generate council report
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## QA Phase Configuration
|
|
215
|
+
|
|
216
|
+
Individual QA sub-phases can be enabled or disabled:
|
|
217
|
+
|
|
218
|
+
| Variable | Default | Description |
|
|
219
|
+
|----------|---------|-------------|
|
|
220
|
+
| `LOKI_PHASE_UNIT_TESTS` | `true` | Run unit tests |
|
|
221
|
+
| `LOKI_PHASE_API_TESTS` | `true` | Functional API testing |
|
|
222
|
+
| `LOKI_PHASE_E2E_TESTS` | `true` | E2E/UI testing with Playwright |
|
|
223
|
+
| `LOKI_PHASE_SECURITY` | `true` | Security scanning (OWASP/auth) |
|
|
224
|
+
| `LOKI_PHASE_CODE_REVIEW` | `true` | 3-reviewer parallel code review |
|
|
225
|
+
| `LOKI_PHASE_PERFORMANCE` | `true` | Load/performance testing |
|
|
226
|
+
| `LOKI_PHASE_ACCESSIBILITY` | `true` | WCAG compliance testing |
|
|
227
|
+
| `LOKI_PHASE_REGRESSION` | `true` | Regression testing |
|
|
228
|
+
|
|
229
|
+
## Health Monitoring
|
|
230
|
+
|
|
231
|
+
### Dashboard Health
|
|
232
|
+
|
|
233
|
+
The dashboard API server exposes a health endpoint. When running:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
loki dashboard status
|
|
237
|
+
# Or via API:
|
|
238
|
+
curl http://localhost:57374/api/health
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Process Watchdog
|
|
242
|
+
|
|
243
|
+
Monitor Loki Mode process health:
|
|
244
|
+
|
|
245
|
+
```bash
|
|
246
|
+
loki watchdog status # Check process health
|
|
247
|
+
loki watchdog help # Show watchdog commands
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Secrets Validation
|
|
251
|
+
|
|
252
|
+
Validate that API keys are properly configured:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
loki secrets status # Check API key status
|
|
256
|
+
loki secrets validate # Validate keys are functional
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Summary
|
|
260
|
+
|
|
261
|
+
Loki Mode supports Docker, Docker Compose, and npm deployment. Security hardening includes TLS, path restrictions, command blocking, OIDC, and staged autonomy. Resource management covers budget limits, CPU/memory thresholds, iteration limits, and parallel execution constraints. The completion council prevents premature termination. All configuration is done through environment variables, making it compatible with any deployment system.
|