loreli 0.0.0 → 1.0.0

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 (88) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +670 -97
  3. package/bin/loreli.js +89 -0
  4. package/package.json +74 -14
  5. package/packages/README.md +101 -0
  6. package/packages/action/README.md +98 -0
  7. package/packages/action/src/index.js +656 -0
  8. package/packages/agent/README.md +517 -0
  9. package/packages/agent/src/backends/claude.js +287 -0
  10. package/packages/agent/src/backends/codex.js +278 -0
  11. package/packages/agent/src/backends/cursor.js +294 -0
  12. package/packages/agent/src/backends/index.js +329 -0
  13. package/packages/agent/src/base.js +138 -0
  14. package/packages/agent/src/cli.js +198 -0
  15. package/packages/agent/src/factory.js +119 -0
  16. package/packages/agent/src/index.js +12 -0
  17. package/packages/agent/src/models.js +141 -0
  18. package/packages/agent/src/output.js +62 -0
  19. package/packages/agent/src/session.js +162 -0
  20. package/packages/agent/src/trace.js +186 -0
  21. package/packages/config/README.md +833 -0
  22. package/packages/config/src/defaults.js +134 -0
  23. package/packages/config/src/index.js +192 -0
  24. package/packages/config/src/schema.js +273 -0
  25. package/packages/config/src/validate.js +160 -0
  26. package/packages/context/README.md +165 -0
  27. package/packages/context/src/index.js +198 -0
  28. package/packages/hub/README.md +338 -0
  29. package/packages/hub/src/base.js +154 -0
  30. package/packages/hub/src/github.js +1558 -0
  31. package/packages/hub/src/index.js +79 -0
  32. package/packages/hub/src/labels.js +48 -0
  33. package/packages/identity/README.md +288 -0
  34. package/packages/identity/src/index.js +620 -0
  35. package/packages/identity/src/themes/avatar.js +217 -0
  36. package/packages/identity/src/themes/digimon.js +217 -0
  37. package/packages/identity/src/themes/dragonball.js +217 -0
  38. package/packages/identity/src/themes/lotr.js +217 -0
  39. package/packages/identity/src/themes/marvel.js +217 -0
  40. package/packages/identity/src/themes/pokemon.js +217 -0
  41. package/packages/identity/src/themes/starwars.js +217 -0
  42. package/packages/identity/src/themes/transformers.js +217 -0
  43. package/packages/identity/src/themes/zelda.js +217 -0
  44. package/packages/knowledge/README.md +237 -0
  45. package/packages/knowledge/src/index.js +412 -0
  46. package/packages/log/README.md +93 -0
  47. package/packages/log/src/index.js +252 -0
  48. package/packages/marker/README.md +200 -0
  49. package/packages/marker/src/index.js +184 -0
  50. package/packages/mcp/README.md +279 -0
  51. package/packages/mcp/instructions.md +121 -0
  52. package/packages/mcp/scaffolding/.agents/skills/loreli-context/SKILL.md +89 -0
  53. package/packages/mcp/scaffolding/ISSUE_TEMPLATE/config.yml +2 -0
  54. package/packages/mcp/scaffolding/ISSUE_TEMPLATE/loreli.yml +83 -0
  55. package/packages/mcp/scaffolding/loreli.yml +453 -0
  56. package/packages/mcp/scaffolding/mcp-configs/.codex/config.toml +3 -0
  57. package/packages/mcp/scaffolding/mcp-configs/.cursor/mcp.json +11 -0
  58. package/packages/mcp/scaffolding/mcp-configs/.mcp.json +11 -0
  59. package/packages/mcp/scaffolding/pull-request.md +23 -0
  60. package/packages/mcp/src/index.js +571 -0
  61. package/packages/mcp/src/tools/agents.js +429 -0
  62. package/packages/mcp/src/tools/context.js +199 -0
  63. package/packages/mcp/src/tools/github.js +1199 -0
  64. package/packages/mcp/src/tools/hitl.js +149 -0
  65. package/packages/mcp/src/tools/index.js +17 -0
  66. package/packages/mcp/src/tools/start.js +835 -0
  67. package/packages/mcp/src/tools/status.js +146 -0
  68. package/packages/mcp/src/tools/work.js +124 -0
  69. package/packages/orchestrator/README.md +192 -0
  70. package/packages/orchestrator/src/index.js +1226 -0
  71. package/packages/planner/README.md +168 -0
  72. package/packages/planner/src/index.js +1166 -0
  73. package/packages/review/README.md +129 -0
  74. package/packages/review/src/index.js +1283 -0
  75. package/packages/risk/README.md +119 -0
  76. package/packages/risk/src/index.js +428 -0
  77. package/packages/session/README.md +165 -0
  78. package/packages/session/src/index.js +215 -0
  79. package/packages/test-utils/README.md +96 -0
  80. package/packages/test-utils/src/index.js +354 -0
  81. package/packages/tmux/README.md +261 -0
  82. package/packages/tmux/src/index.js +452 -0
  83. package/packages/workflow/README.md +313 -0
  84. package/packages/workflow/src/index.js +481 -0
  85. package/packages/workflow/src/proof-of-life.js +74 -0
  86. package/packages/workspace/README.md +143 -0
  87. package/packages/workspace/src/index.js +1076 -0
  88. package/index.js +0 -8
@@ -0,0 +1,833 @@
1
+ # loreli/config
2
+
3
+ Centralized configuration for Loreli. Reads `loreli.yml` from target repositories, merges with start parameters and environment variables, and provides typed defaults for every configurable value in the system.
4
+
5
+ ## How It Works
6
+
7
+ ```mermaid
8
+ flowchart TD
9
+ BP["Start Params"] --> Merge["Config.merge()"]
10
+ YML["loreli.yml (repo)"] --> Load["Config.load()"]
11
+ Load --> Resolve["Config.get(path)"]
12
+ Merge --> Resolve
13
+ DOT[".env file"] --> LoadEnv["loadEnv()"]
14
+ LoadEnv --> PEnv["process.env"]
15
+ PEnv --> Resolve
16
+ DEF["Built-in Defaults"] --> Resolve
17
+ Resolve --> Value["Resolved Value"]
18
+ ```
19
+
20
+ Config values are resolved through four layers, highest priority first:
21
+
22
+ 1. **Start tool params** -- explicit per-invocation overrides via `config.merge()`
23
+ 2. **`loreli.yml`** -- repo-level config read via `hub.read()` during `config.load()`
24
+ 3. **Environment variables** -- shell env and `.env` file (via `loadEnv()`)
25
+ 4. **Built-in defaults** -- hardcoded in `defaults.js`
26
+
27
+ ## API Reference
28
+
29
+ ### `new Config()`
30
+
31
+ Creates a config instance with empty layers. All `get()` calls return built-in defaults until `load()` or `merge()` is called.
32
+
33
+ ### `config.load(hub, repo)` -> `Promise<boolean>`
34
+
35
+ Read `loreli.yml` from the target repo root via `hub.read()`. Returns `true` if the file was found, `false` otherwise. When the file is missing, defaults apply gracefully.
36
+
37
+ The following example demonstrates loading config from a repo, which is the first step in start:
38
+
39
+ ```js
40
+ import { Config } from 'loreli/config';
41
+
42
+ const config = new Config();
43
+ const found = await config.load(hub, 'owner/repo');
44
+ // found === true if loreli.yml exists
45
+ ```
46
+
47
+ ### `config.merge(overrides)`
48
+
49
+ Apply a plain object on top of all other layers. Nested objects are shallow-merged one level deep. Values are validated through the schema -- invalid types are silently discarded.
50
+
51
+ The following example shows how start params override file-level config:
52
+
53
+ ```js
54
+ config.merge({ theme: 'pokemon', reviewers: ['alice'] });
55
+ config.get('theme'); // 'pokemon' (overridden)
56
+ ```
57
+
58
+ ### `config.get(path)` -> `*`
59
+
60
+ Resolve a config value through all layers using dot-notation. Returns `undefined` for completely unknown paths.
61
+
62
+ The following example demonstrates accessing nested and top-level values:
63
+
64
+ ```js
65
+ config.get('theme'); // 'transformers'
66
+ config.get('merge.method'); // 'squash'
67
+ config.get('timeouts.stall'); // 600000
68
+ config.get('reviewers'); // []
69
+ ```
70
+
71
+ ### `config.toJSON()` -> `object`
72
+
73
+ Serialize the fully resolved config to a plain object, walking every default key and resolving each through the layer chain. Used for session persistence.
74
+
75
+ ### `config.found` -> `boolean`
76
+
77
+ Whether `loreli.yml` was found during the last `load()` call. Used by start to decide if the file needs scaffolding.
78
+
79
+ ### `loadEnv(path?)` -> `boolean`
80
+
81
+ Load a `.env` file into `process.env` using Node's built-in `process.loadEnvFile()`. Variables already present in the shell environment are **not** overwritten, so shell exports always win.
82
+
83
+ Returns `true` if the file was loaded, `false` if it does not exist. Any other I/O error is re-thrown.
84
+
85
+ The following example demonstrates loading a `.env` file before creating a `Config` instance, which is the recommended pattern for local development and testing. The loaded variables flow into `Config.get()` through the existing env layer — no extra wiring needed:
86
+
87
+ ```js
88
+ import { loadEnv, Config } from 'loreli/config';
89
+
90
+ loadEnv(); // loads .env from cwd (silent no-op if missing)
91
+ const config = new Config();
92
+ config.get('github.token'); // resolves GITHUB_TOKEN from .env
93
+ config.get('log.level'); // resolves LORELI_LOG_LEVEL from .env
94
+ ```
95
+
96
+ The following example shows loading from an explicit path, which is useful in tests or CI where the `.env` file lives in a non-standard location:
97
+
98
+ ```js
99
+ import { loadEnv } from 'loreli/config';
100
+
101
+ const found = loadEnv('/path/to/project/.env.test');
102
+ // found === true if the file existed
103
+ ```
104
+
105
+ > **Note:** `loadEnv` uses Node's built-in `process.loadEnvFile()` (available since Node 20.12). No external dependencies are required. The project targets Node >= 24.
106
+
107
+ ## `loreli.yml` Schema
108
+
109
+ This file lives in the **target repository** root (the repo agents work on). It is scaffolded by start if absent.
110
+
111
+ ```yaml
112
+ # loreli.yml - repo-level orchestration config
113
+ # See https://www.npmjs.com/package/loreli for full documentation.
114
+ #
115
+ # Duration fields support both numbers (milliseconds) and strings parsed by `ms`.
116
+ # Prefer strings like 10m, 1h, 3d for readability.
117
+
118
+ # --- Identity ---
119
+ # theme
120
+ # What: Chooses naming/theme vocabulary for agent identities and system messages.
121
+ # Impact: Cosmetic only; does not change orchestration behavior or model quality.
122
+ # Signal: Humans find agent identity/readability poor in PRs, comments, or dashboards.
123
+ # Change when: You want agent names/messages to match your team's preferred style.
124
+ theme: transformers # string or list: transformers | pokemon | marvel | digimon | starwars | lotr | dragonball | avatar | zelda
125
+ # theme: # list = randomize theme per work item
126
+ # - transformers
127
+ # - pokemon
128
+ # - marvel
129
+
130
+ # --- Agent defaults ---
131
+ # model
132
+ # What: Default model tier when tools do not specify a model explicitly.
133
+ # Impact: Higher tiers are usually stronger but slower/more expensive.
134
+ # Signal: Repeated low-quality outputs at current tier, or cost/latency pressure from higher tiers.
135
+ # Change when: You want a global quality/cost baseline shift for all agents.
136
+ model: balanced # fast | balanced | powerful | exact model string
137
+
138
+ # --- Merge gate ---
139
+ # reviewers
140
+ # What: GitHub usernames for HITL review requests.
141
+ # Impact: Non-empty reviewers typically means more human approval steps.
142
+ # Signal: PRs merge without enough human oversight, or reviewer assignment is missing expected owners.
143
+ # Change when: You want specific humans looped into merges.
144
+ reviewers: [] # empty = autonomous merge path
145
+
146
+ merge:
147
+ # merge.method
148
+ # What: Git merge strategy used by Loreli when merging approved PRs.
149
+ # Impact: Changes commit history shape (single squash commit vs merge commit vs rebase history).
150
+ # Signal: Repository policy violations or maintainer feedback about history shape.
151
+ # Change when: Your repo has a strict merge policy.
152
+ method: squash # squash | merge | rebase
153
+
154
+ # merge.hitl
155
+ # What: Enables/disables Human In The Loop merge gating.
156
+ # Impact: true blocks final merge on human approval; false allows full automation.
157
+ # Signal: Unexpected autonomous merges (need true) or merge throughput too slow due to manual gates (consider false).
158
+ # Change when: You need more safety (set true) or more autonomy/speed (set false).
159
+ hitl: false
160
+
161
+ # merge.base
162
+ # What: Base branch target for agent PRs.
163
+ # Impact: Controls where agent changes accumulate (for example staging branch vs main).
164
+ # Signal: Main branch receiving agent merges too early, or release managers asking for a promotion/staging lane.
165
+ # Change when: You want agents to merge into an integration branch before promotion to main.
166
+ base: loreli
167
+
168
+ # --- PR quality gates ---
169
+ pr:
170
+ validation:
171
+ # pr.validation.command
172
+ # What: Shell command run before `pr/create` is allowed.
173
+ # Impact: Non-zero exit blocks PR creation; stronger checks reduce bad PRs but increase latency.
174
+ # Signal: PRs repeatedly fail CI after creation (tighten command), or PR creation is bottlenecked by long prechecks (lighten command).
175
+ # Change when: You want a different gate (for example lint+test, unit-only, or build-only).
176
+ command: npm test
177
+
178
+ selfReview:
179
+ # pr.selfReview.enabled
180
+ # What: Requires a preview step before actual PR creation.
181
+ # Impact: Adds one extra tool step but catches obvious metadata/diff mistakes early.
182
+ # Signal: Frequent wrong-base/wrong-scope PRs (enable), or operators report friction from two-step create flow (disable).
183
+ # Change when: You want faster single-step PR creation (set false) or stricter guardrails (true).
184
+ enabled: true
185
+
186
+ # --- HITL behavior ---
187
+ hitl:
188
+ # hitl.timeout
189
+ # What: Max idle age for HITL-owned claims before stale-claim eviction logic can act.
190
+ # Impact: Lower values recycle stuck ownership faster; higher values preserve ownership longer.
191
+ # Signal: Claims remain stuck for days (decrease), or valid long human review cycles get evicted too early (increase).
192
+ # Change when: Human review cadence is slower/faster than current default.
193
+ # Special: null disables stale-claim eviction in HITL mode.
194
+ timeout: 3d
195
+
196
+ # --- Stall and lifecycle timeouts ---
197
+ timeouts:
198
+ # timeouts.stall
199
+ # What: No-activity threshold for stall escalation.
200
+ # Impact: >stall triggers tier-1, >2x triggers tier-2 warning, >3x triggers kill.
201
+ # Signal: Agents killed during legitimate long runs (increase), or stalled agents consume slots too long (decrease).
202
+ # Change when: Agents are killed too aggressively on long tasks (increase),
203
+ # or stuck agents linger too long (decrease).
204
+ stall: 10m
205
+
206
+ # timeouts.shutdown
207
+ # What: Grace window for cooperative shutdown before force stop.
208
+ # Impact: Lower values free resources faster; higher values allow cleaner agent exits.
209
+ # Signal: Frequent force-kill shutdowns while agents are still finishing final output (increase),
210
+ # or shutdown hangs tying up capacity (decrease).
211
+ # Change when: Agents need more time to finalize output before shutdown.
212
+ shutdown: 1m
213
+
214
+ # timeouts.poll
215
+ # What: Poll cadence during shutdown waiting loop.
216
+ # Impact: Lower values detect stop faster but increase loop overhead.
217
+ # Signal: Slow recognition of completed shutdowns (decrease), or excessive polling/log churn during shutdown (increase).
218
+ # Change when: You want quicker shutdown detection or lower polling churn.
219
+ poll: 2s
220
+
221
+ # timeouts.rapidDeath
222
+ # What: Startup watch window used to detect immediate backend failures.
223
+ # Impact: Helps mark unhealthy backends degraded sooner after repeated instant failures.
224
+ # Signal: Backends crash quickly but are not degraded soon enough (increase), or degraded too aggressively from transient startup blips (decrease).
225
+ # Change when: Startup failures are missed (increase) or false positives occur (decrease).
226
+ rapidDeath: 15s
227
+
228
+ # timeouts.nudge
229
+ # What: Enables/disables tier-1 "you appear stalled" message.
230
+ # Impact: true may interrupt deep work; false keeps escalation signals without message interruption.
231
+ # Signal: Agents frequently context-switch into status reporting mid-task (disable), or teams need explicit stall prompts (enable).
232
+ # Change when: Long-running autonomous tasks should not be interrupted.
233
+ nudge: true
234
+
235
+ # --- Reactor polling ---
236
+ watch:
237
+ # watch.interval
238
+ # What: Main orchestration tick interval.
239
+ # Impact: Lower = faster reaction to new issues/PR state changes, higher API/process load.
240
+ # Signal: Claim/review actions happen too slowly after repo events (decrease), or API rate pressure/churn is high (increase).
241
+ # Change when: You need faster responsiveness or lower background churn.
242
+ interval: 1m
243
+
244
+ # watch.maxRounds
245
+ # What: Maximum re-review/rework loop cycles before escalation.
246
+ # Impact: Higher values allow deeper autonomous iteration; lower values force earlier human escalation.
247
+ # Signal: PRs escalate before they can converge autonomously (increase), or loops churn too long without convergence (decrease).
248
+ # Change when: PRs routinely need more/less autonomous correction rounds.
249
+ maxRounds: 7
250
+
251
+ # watch.maxClaims
252
+ # What: Max simultaneous issue claims per action agent.
253
+ # Impact: Higher increases per-agent throughput but can dilute focus and increase context switching.
254
+ # Signal: Idle action agents with unclaimed work (increase), or agents juggle too many tasks and miss follow-through (decrease).
255
+ # Change when: Agents are underutilized (increase) or overloaded (decrease).
256
+ maxClaims: 3
257
+
258
+ # --- Review policy ---
259
+ review:
260
+ # review.skipRiskAssessment
261
+ # What: Skips mandatory risk verdict checks in review flow.
262
+ # Impact: Faster review path with less explicit risk gating.
263
+ # Signal: Teams intentionally bypassing risk gates for speed, or conversely incidents from insufficient risk checks (set false).
264
+ # Change when: You intentionally prefer speed over formal risk signoff.
265
+ skipRiskAssessment: false
266
+
267
+ # --- Scaling policy ---
268
+ scaling:
269
+ # scaling.maxAgents
270
+ # What: Global cap for active non-dormant agents.
271
+ # Impact: Upper bound on parallelism and compute/resource consumption.
272
+ # Signal: Backlog grows with idle infrastructure (increase), or host/API limits are saturated (decrease).
273
+ # Change when: You need more throughput (increase) or tighter resource limits (decrease).
274
+ maxAgents: 8
275
+
276
+ maxPerRole:
277
+ # scaling.maxPerRole.action
278
+ # What: Max concurrent action agents.
279
+ # Impact: Controls parallel implementation throughput.
280
+ # Signal: Large implementation queue with insufficient coding capacity.
281
+ # Change when: Work backlog is implementation-heavy.
282
+ action: 3
283
+
284
+ # scaling.maxPerRole.reviewer
285
+ # What: Max concurrent reviewer agents.
286
+ # Impact: Controls review bottleneck relief.
287
+ # Signal: PRs are ready but waiting on reviewer assignment/completion.
288
+ # Change when: PR queue waits on reviews.
289
+ reviewer: 2
290
+
291
+ # scaling.maxPerRole.risk
292
+ # What: Max concurrent risk agents.
293
+ # Impact: Controls parallel risk assessment capacity.
294
+ # Signal: Reviews blocked on risk verdicts.
295
+ # Change when: Risk checks become the bottleneck.
296
+ risk: 3
297
+
298
+ # scaling.maxPerRole.planner
299
+ # What: Max concurrent planner agents.
300
+ # Impact: Limits parallel planning/discussion churn.
301
+ # Signal: Planning queue grows (increase) or discussion noise overwhelms maintainers (decrease).
302
+ # Change when: You want more/fewer simultaneous planning threads.
303
+ planner: 1
304
+
305
+ # scaling.maxPerTick
306
+ # What: Spawn budget per reactor tick.
307
+ # Impact: Higher values ramp up faster but can spike load.
308
+ # Signal: Slow recovery from empty capacity (increase), or sudden spawn bursts causing instability (decrease).
309
+ # Change when: Startup/recovery is too slow (increase) or too bursty (decrease).
310
+ maxPerTick: 2
311
+
312
+ # scaling.cooldown
313
+ # What: Minimum delay before spawning another agent of the same role.
314
+ # Impact: Prevents spawn thrashing when demand oscillates.
315
+ # Signal: Repeated rapid spawn/stop cycles for same role (increase), or role fill speed too slow during sustained demand (decrease).
316
+ # Change when: You see role churn/flapping or need faster re-scaling.
317
+ cooldown: 30s
318
+
319
+ # --- Logging ---
320
+ log:
321
+ # log.level
322
+ # What: Minimum severity written to logs.
323
+ # Impact: Lower levels (debug/trace) increase observability and log volume.
324
+ # Signal: Hard-to-diagnose behavior with insufficient log detail (lower level), or noisy oversized logs (raise level).
325
+ # Change when: Debugging production behavior or reducing noise.
326
+ level: info # error | warn | info | debug | trace
327
+
328
+ # log.maxSize
329
+ # What: Per-file rotation size threshold in bytes.
330
+ # Impact: Larger files reduce rotation frequency but grow disk usage per file.
331
+ # Signal: Too-frequent rotations splitting incidents (increase), or very large log files hard to handle (decrease).
332
+ # Change when: You want fewer rotations or smaller log files.
333
+ maxSize: 10485760 # 10 MB
334
+
335
+ # log.maxFiles
336
+ # What: Number of rotated files retained.
337
+ # Impact: Higher values keep more history and consume more disk.
338
+ # Signal: Needed historical context disappears before investigation (increase), or disk pressure from logs (decrease).
339
+ # Change when: You need longer local forensic history.
340
+ maxFiles: 3
341
+
342
+ # --- Labels ---
343
+ labels:
344
+ # labels.track
345
+ # What: Adds Loreli/provider/model tracking labels to issues and PRs.
346
+ # Impact: Better observability/filtering in GitHub labels, but more label traffic.
347
+ # Signal: Need to filter/report by provider/role/model (enable), or label clutter complaints from maintainers (disable).
348
+ # Change when: You want a cleaner label surface (set false).
349
+ track: true
350
+
351
+ # labels.extra
352
+ # What: Extra labels applied to all Loreli-created items.
353
+ # Impact: Improves triage/routing automation via label-based workflows.
354
+ # Signal: Manual relabeling happens repeatedly after Loreli creates items.
355
+ # Change when: You need team/project labels attached automatically.
356
+ extra: []
357
+
358
+ # --- Agent tool restrictions ---
359
+ agents:
360
+ disallowedTools:
361
+ # agents.disallowedTools
362
+ # What: Commands agents cannot execute directly.
363
+ # Impact: Helps prevent bypassing MCP guardrails and policy checks.
364
+ # Signal: Agents attempt raw GitHub/API shell tooling that bypasses Loreli controls.
365
+ # Change when: You need stricter/looser command policy.
366
+ - gh
367
+ - curl
368
+
369
+ # --- Backend model/env overrides ---
370
+ # backends.{name}.models
371
+ # What: Per-backend tier/provider model routing overrides.
372
+ # Impact: Changes model selection without code changes.
373
+ # Signal: Specific backend underperforms at current tier/provider mapping.
374
+ # Change when: You need backend-specific model tuning.
375
+ #
376
+ # backends.{name}.env
377
+ # What: Env vars injected into backend launcher scripts.
378
+ # Impact: Controls API base URLs, auth endpoints, and backend runtime options.
379
+ # Signal: Backend needs proxy routing/custom endpoint/auth flag and current environment inheritance is insufficient.
380
+ # Change when: You use proxies/self-hosted gateways/custom backend flags.
381
+ #
382
+ # backends:
383
+ # claude:
384
+ # env:
385
+ # ANTHROPIC_BASE_URL: https://your-proxy.example.com/v1
386
+ # models:
387
+ # fast:
388
+ # anthropic: claude-haiku-4-5-20251001
389
+ # balanced:
390
+ # anthropic: claude-sonnet-4-5-20250929
391
+ # powerful:
392
+ # anthropic: claude-opus-4-5-20251101
393
+ # codex:
394
+ # env:
395
+ # OPENAI_BASE_URL: https://your-proxy.example.com/v1
396
+ # models:
397
+ # fast:
398
+ # openai: gpt-5-mini
399
+ # balanced:
400
+ # openai: gpt-5.1-codex
401
+ # powerful:
402
+ # openai: gpt-5.2-pro
403
+ # cursor:
404
+ # models:
405
+ # fast:
406
+ # anthropic: sonnet-4.5
407
+ # openai: gpt-5.3-codex-low
408
+ # balanced:
409
+ # anthropic: sonnet-4.5-thinking
410
+ # openai: gpt-5.3-codex
411
+ # powerful:
412
+ # anthropic: opus-4.6-thinking
413
+ # openai: gpt-5.1-codex-max
414
+
415
+ # --- Trace capture ---
416
+ trace:
417
+ # trace.enabled
418
+ # What: Master switch for workflow trace collection.
419
+ # Impact: Off reduces trace artifacts; on improves debuggability.
420
+ # Signal: Missing forensic context during incidents (enable), or trace storage overhead too high (disable).
421
+ # Change when: You need to reduce trace volume or increase diagnostics.
422
+ enabled: true
423
+
424
+ # trace.includeOutput
425
+ # What: Include model/tool output snippets in traces.
426
+ # Impact: Better debugging context but larger logs and potentially sensitive output in traces.
427
+ # Signal: Investigations lack enough output context (enable), or traces include too much sensitive/noisy content (disable).
428
+ # Change when: You want minimal traces or stricter output hygiene.
429
+ includeOutput: true
430
+
431
+ # trace.maxOutputChars
432
+ # What: Global cap of captured output chars per trace item.
433
+ # Impact: Higher captures richer context but grows trace size.
434
+ # Signal: Trace snippets are cut before key error details appear (increase), or traces are too large/noisy (decrease).
435
+ # Change when: Useful context is being truncated too aggressively.
436
+ maxOutputChars: 8000
437
+
438
+ workflows:
439
+ planner:
440
+ # trace.workflows.planner.enabled / maxOutputChars
441
+ # What: Planner-specific trace override.
442
+ # Impact: Fine-grained planner trace tuning.
443
+ # Signal: Planner traces need different verbosity than global behavior.
444
+ # Change when: Planner traces need different verbosity than global default.
445
+ enabled: true
446
+ maxOutputChars: 4000
447
+
448
+ reviewer:
449
+ # trace.workflows.reviewer.enabled / maxOutputChars
450
+ # What: Reviewer-specific trace override.
451
+ # Impact: Fine-grained reviewer trace tuning.
452
+ # Signal: Reviewer traces are too sparse for diagnosis or too noisy for signal extraction.
453
+ # Change when: Reviewer traces are too noisy or too sparse.
454
+ enabled: true
455
+ maxOutputChars: 4000
456
+
457
+ risk:
458
+ # trace.workflows.risk.enabled / maxOutputChars
459
+ # What: Risk-specific trace override.
460
+ # Impact: Fine-grained risk trace tuning.
461
+ # Signal: Risk reasoning context is truncated (increase) or over-captured (decrease).
462
+ # Change when: Risk traces need tighter/looser capture bounds.
463
+ enabled: true
464
+ maxOutputChars: 2000
465
+
466
+ # --- Proof of life ---
467
+ proofOfLife:
468
+ # proofOfLife.timeout
469
+ # What: Wait window for liveness responses before stale claim eviction actions.
470
+ # Impact: Lower values reclaim work faster; higher values are more tolerant of slow responses.
471
+ # Signal: Active claims get evicted while agents are still responsive (increase), or dead claims linger too long (decrease).
472
+ # Change when: Claims are reclaimed too quickly or too slowly.
473
+ timeout: 5m
474
+
475
+ # --- Workspace lifecycle ---
476
+ workspace:
477
+ # workspace.cleanup
478
+ # What: Deletes per-agent workspace directories on kill/shutdown.
479
+ # Impact: true saves disk space; false preserves artifacts for debugging.
480
+ # Signal: Disk growth from stale workspaces (enable), or need post-run forensic inspection (disable).
481
+ # Change when: You want cleaner disks (true) or post-mortem inspection (false).
482
+ cleanup: false
483
+
484
+ # --- Session cleanup ---
485
+ cleanup:
486
+ # cleanup.retention
487
+ # What: Age threshold for pruning old sessions.
488
+ # Impact: Lower values reduce disk usage; higher values keep history longer.
489
+ # Signal: Session storage growth pressure (decrease), or historical debugging context disappears too soon (increase).
490
+ # Change when: You need more/less historical session retention.
491
+ retention: 12h
492
+
493
+ # cleanup.autoprune
494
+ # What: Runs prune/sweep automatically at start.
495
+ # Impact: true keeps storage tidy without manual cleanup.
496
+ # Signal: Accumulated stale files/sessions between runs (enable), or need strict manual lifecycle control (disable).
497
+ # Change when: You want explicit/manual cleanup control (set false).
498
+ autoprune: true
499
+
500
+ # --- Prompt overrides ---
501
+ # prompts.{role}
502
+ # What: Repo-local prompt file overrides for each role.
503
+ # Impact: Changes agent behavior/instructions without code changes.
504
+ # Signal: Repeated instruction gaps that can be fixed with persistent repo-specific guidance.
505
+ # Change when: You need project-specific guardrails or workflow guidance.
506
+ # prompts:
507
+ # action: .loreli/action.md
508
+ # reviewer: .loreli/review.md
509
+ # planner: .loreli/planner.md
510
+ # risk: .loreli/risk.md
511
+
512
+ # --- Feedback and knowledge capture ---
513
+ feedback:
514
+ # feedback.enabled
515
+ # What: Master switch for feedback marker capture and knowledge aggregation.
516
+ # Impact: false disables automated pattern accumulation.
517
+ # Signal: Need to temporarily pause all feedback mining/noise.
518
+ # Change when: You want to pause feedback mining entirely.
519
+ enabled: true
520
+
521
+ # feedback.threshold
522
+ # What: Repeat-count threshold before a feedback pattern is promoted/escalated.
523
+ # Impact: Lower values promote patterns sooner; higher values reduce noisy promotions.
524
+ # Signal: Too many low-signal promotions (increase), or important repeated issues taking too long to surface (decrease).
525
+ # Change when: Pattern promotion is too noisy (increase) or too slow (decrease).
526
+ threshold: 5
527
+
528
+ # feedback.categories
529
+ # What: Allowed classifier buckets for captured feedback.
530
+ # Impact: Removed categories are ignored by pattern promotion.
531
+ # Signal: Certain feedback classes are irrelevant/noisy for your team.
532
+ # Change when: You want to focus feedback mining on specific quality dimensions.
533
+ categories:
534
+ - naming
535
+ - architecture
536
+ - testing
537
+ - documentation
538
+ - performance
539
+ - security
540
+
541
+ # --- Tmux ---
542
+ tmux:
543
+ # tmux.session
544
+ # What: Shared tmux session name where agent panes run.
545
+ # Impact: Changing this isolates Loreli panes into a different tmux session namespace.
546
+ # Signal: Multiple orchestrations collide in same tmux namespace.
547
+ # Change when: Running multiple isolated Loreli orchestrations on one machine.
548
+ session: loreli
549
+
550
+ # tmux.capture
551
+ # What: Number of pane history lines Loreli reads when inspecting output.
552
+ # Impact: Higher values improve diagnostics but increase capture overhead.
553
+ # Signal: Error root cause appears just above currently captured history window.
554
+ # Change when: Important error context scrolls out of captured history.
555
+ capture: 500
556
+
557
+ # --- GitHub auth override ---
558
+ # github.token
559
+ # What: Fallback GitHub token in config (env token is preferred).
560
+ # Impact: Enables Hub API auth when env injection is unavailable.
561
+ # Signal: Hub/API auth failures in environments where you cannot set env vars.
562
+ # Change when: You cannot provide GITHUB_TOKEN via environment.
563
+ # github:
564
+ # token: ghp_your_token_here
565
+
566
+ ```
567
+
568
+ ## Configurable Base Branch
569
+
570
+ By default agents create pull requests against `main`. The `merge.base` setting redirects all agent work to a dedicated branch, keeping `main` untouched until a human is ready to promote.
571
+
572
+ ### Why
573
+
574
+ Agents run autonomously — often overnight or in batch. Pointing them at a dedicated branch (e.g. `loreli`) creates a natural safety boundary: agent-produced PRs merge into `loreli`, and a single human-reviewed PR promotes the batch from `loreli` into `main`. This prevents unreviewed agent code from landing on `main` directly.
575
+
576
+ ### How to Enable
577
+
578
+ Set `merge.base` in the target repository's `loreli.yml`:
579
+
580
+ ```yaml
581
+ merge:
582
+ base: loreli
583
+ ```
584
+
585
+ The scaffolding template (`loreli.yml` generated by start) already defaults to `loreli`. Repositories that omit `merge.base` or set it to `main` retain the current behavior — agents PR directly against `main`.
586
+
587
+ ### What It Affects
588
+
589
+ The setting flows through every system boundary that references a base branch:
590
+
591
+ | System | Behavior |
592
+ |--------|----------|
593
+ | **Workspace reset** (`reset()`) | Agent workspaces are force-recreated from `origin/<base>` instead of `origin/main` when recycling between issues. The base ref is explicitly fetched since agent clones use `--single-branch`. |
594
+ | **PR creation** (`pr` tool) | PRs opened by action agents target `<base>` instead of `main`. The base is resolved from config and can be overridden per-call via the `base` argument. |
595
+ | **Relay auto-PR** (action workflow) | When the action workflow auto-creates a PR on behalf of a dormant agent, it uses the configured base. |
596
+ | **Review checkout** (`checkout()`) | Reviewer workspaces sync the configured base branch alongside the PR head so diffs are computed against the correct parent. |
597
+ | **Re-review dispatch** (review workflow) | Re-review prompts include the configured base in PR metadata so reviewers evaluate against the correct target. |
598
+
599
+ ### Resolution Order
600
+
601
+ `merge.base` follows the standard config resolution chain:
602
+
603
+ 1. **Start params** — `config.merge({ merge: { base: 'develop' } })`
604
+ 2. **`loreli.yml`** — `merge.base: loreli`
605
+ 3. **Built-in default** — `main`
606
+
607
+ Every call site uses `cfg?.get?.('merge.base') ?? 'main'` as the resolution pattern, ensuring the system degrades gracefully when config is unavailable.
608
+
609
+ ### Workflow
610
+
611
+ The intended workflow with `merge.base: loreli`:
612
+
613
+ ```
614
+ main ──────────────────────────────────────── human review ──▶ main
615
+ │ ▲
616
+ └──▶ loreli ──▶ agent PRs merge here ──────────────┘
617
+ │ ▲ ▲
618
+ ├── agent-0/issue-1 ───┘ (auto-merge)
619
+ └── agent-1/issue-2 ───┘ (auto-merge)
620
+ ```
621
+
622
+ Agents branch from `loreli`, open PRs against `loreli`, and their work is auto-merged (or HITL-reviewed) into `loreli`. A separate human-created PR from `loreli → main` rolls up all agent work for final review.
623
+
624
+ ## PR Quality Gates
625
+
626
+ `pr` config controls pre-PR quality enforcement in the `pr` MCP tool (`action: create`).
627
+
628
+ ```yaml
629
+ pr:
630
+ validation:
631
+ command: npm test
632
+ selfReview:
633
+ enabled: true
634
+ ```
635
+
636
+ - `pr.validation.command`: defaults to `npm test` and runs in the action agent workspace before PR creation. Non-zero exit blocks `pr/create` and returns command output.
637
+ - `pr.selfReview.enabled`: defaults to `true` and switches `pr/create` into a two-step flow. First call returns a diff/stat preview. Second call must pass `confirm: true` to proceed.
638
+
639
+ ## Built-in Defaults
640
+
641
+ Every configurable value has a default in `defaults.js`. These are the lowest-priority layer and apply when no other layer provides a value:
642
+
643
+ | Key | Default | Description |
644
+ |-----|---------|-------------|
645
+ | `theme` | `transformers` | Agent naming theme (`string` or `string[]` for random per work item) |
646
+ | `reviewers` | `[]` | Human reviewers (empty = auto-merge) |
647
+ | `model` | `balanced` | Default model alias |
648
+ | `backends.claude.models.fast.anthropic` | `claude-haiku-4-5-20251001` | Claude fast tier |
649
+ | `backends.claude.models.balanced.anthropic` | `claude-sonnet-4-5-20250929` | Claude balanced tier |
650
+ | `backends.claude.models.powerful.anthropic` | `claude-opus-4-5-20251101` | Claude powerful tier |
651
+ | `backends.codex.models.fast.openai` | `gpt-5-mini` | Codex fast tier |
652
+ | `backends.codex.models.balanced.openai` | `gpt-5.1-codex` | Codex balanced tier |
653
+ | `backends.codex.models.powerful.openai` | `gpt-5.2-pro` | Codex powerful tier |
654
+ | `backends.cursor.models.fast.anthropic` | `sonnet-4.5` | Cursor fast anthropic |
655
+ | `backends.cursor.models.balanced.anthropic` | `sonnet-4.5-thinking` | Cursor balanced anthropic |
656
+ | `backends.cursor.models.powerful.anthropic` | `opus-4.6-thinking` | Cursor powerful anthropic |
657
+ | `backends.{name}.env` | *(none)* | Backend-specific env var overrides (flat string map) |
658
+ | `agents.disallowedTools` | `['gh', 'curl']` | Commands agents cannot execute |
659
+ | `scaling.maxAgents` | `8` | Global cap — max agents across all roles |
660
+ | `scaling.maxPerRole.action` | `3` | Max action agents |
661
+ | `scaling.maxPerRole.reviewer` | `2` | Max reviewer agents |
662
+ | `scaling.maxPerRole.risk` | `3` | Max risk agents |
663
+ | `scaling.maxPerRole.planner` | `1` | Max planner agents |
664
+ | `scaling.maxPerTick` | `2` | Max new agents spawned per reactor tick |
665
+ | `scaling.cooldown` | `30000` | Min time between spawns for same role (ms) |
666
+ | `merge.method` | `squash` | PR merge method |
667
+ | `merge.hitl` | `false` | HITL mode: `false` = auto-merge, `true` = human reviewers |
668
+ | `merge.base` | `main` | Default PR base branch (scaffolding template sets `loreli` for safety — agents work on a dedicated branch, not main) |
669
+ | `pr.validation.command` | `npm test` | Default shell command run before `pr/create`; non-zero exit blocks PR creation |
670
+ | `pr.selfReview.enabled` | `true` | Require two-step self-review flow (`create` preview, then `create` with `confirm=true`) before PR creation |
671
+ | `timeouts.stall` | `600000` | Agent stall detection (ms) |
672
+ | `timeouts.shutdown` | `60000` | Graceful shutdown timeout (ms) |
673
+ | `timeouts.poll` | `2000` | Poll interval (ms) |
674
+ | `timeouts.rapidDeath` | `15000` | Spawn-window backend failure detection delay (ms) |
675
+ | `timeouts.nudge` | `true` | Enable/disable tier-1 stall nudge messages |
676
+ | `log.level` | `info` | Console log level |
677
+ | `log.maxSize` | `10485760` | Max log file size (bytes) |
678
+ | `log.maxFiles` | `3` | Rotated log file count |
679
+ | `proofOfLife.timeout` | `300000` | Proof-of-life response timeout (ms, default 5m) |
680
+ | `cleanup.retention` | `43200000` | Prune sessions older than this (ms, default 12h) |
681
+ | `cleanup.autoprune` | `true` | Run prune at start |
682
+ | `prompts.action` | `undefined` | Custom prompt file for action agents (relative to repo root) |
683
+ | `prompts.reviewer` | `undefined` | Custom prompt file for reviewer agents (relative to repo root) |
684
+ | `prompts.planner` | `undefined` | Custom prompt file for planner agents (relative to repo root) |
685
+ | `prompts.risk` | `undefined` | Custom prompt file for risk agents (relative to repo root) |
686
+ | `tmux.session` | `loreli` | Tmux session name |
687
+ | `tmux.capture` | `500` | Pane capture history lines |
688
+
689
+ ## Environment Variable Mapping
690
+
691
+ Only a subset of config values can be overridden via environment variables. These variables can come from the shell or from a `.env` file loaded via `loadEnv()`:
692
+
693
+ | Config Path | Environment Variable | Purpose |
694
+ |-------------|---------------------|---------|
695
+ | `log.level` | `LORELI_LOG_LEVEL` | Override default log level |
696
+ | `github.token` | `GITHUB_TOKEN` | GitHub API token for hub |
697
+
698
+ Environment variables sit between the file layer and built-in defaults in resolution priority. Shell-set variables take precedence over `.env` file values.
699
+
700
+ Additional env vars recognized by other packages but not routed through `Config.get()`:
701
+
702
+ | Variable | Package | Purpose |
703
+ |----------|---------|---------|
704
+ | `LORELI_HOME` | mcp, agent, log | Override `~/.loreli/` base storage directory |
705
+ | `LORELI_TEST_REPO` | tests | GitHub repo for integration tests (`owner/name`) |
706
+
707
+ Copy `.env.example` from the project root to `.env` for local development. See the root README for the full list.
708
+
709
+ ## Backend Environment Variables
710
+
711
+ Each backend can declare environment variable overrides in `loreli.yml` under `backends.{name}.env`. These are exported in launcher scripts before spawning the CLI agent in tmux.
712
+
713
+ At runtime, the agent package's `models.env()` function merges two layers:
714
+
715
+ 1. **Inherited** — `process.env` vars matching the backend's known prefixes are collected automatically
716
+ 2. **Config overrides** — `backends.{name}.env` from `loreli.yml` or `config.merge()` take precedence on key collision
717
+
718
+ | Backend | Inherited Prefixes |
719
+ |---------|-------------------|
720
+ | `claude` | `ANTHROPIC_*`, `CLAUDE_*` |
721
+ | `codex` | `OPENAI_*`, `CODEX_*` |
722
+ | `cursor` | `ANTHROPIC_*`, `OPENAI_*`, `CLAUDE_*`, `CURSOR_*` |
723
+
724
+ This means critical variables like `ANTHROPIC_BASE_URL` (proxy URL), `ANTHROPIC_AUTH_TOKEN`, and `CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` are forwarded from the orchestrator's environment into tmux-spawned agents without explicit config — but can be overridden in `loreli.yml` when needed:
725
+
726
+ ```yaml
727
+ backends:
728
+ claude:
729
+ env:
730
+ ANTHROPIC_BASE_URL: https://your-proxy.example.com/v1
731
+ codex:
732
+ env:
733
+ OPENAI_BASE_URL: https://your-proxy.example.com/v1
734
+ ```
735
+
736
+ The `env` section is a flat string-to-string map. Non-string values and empty objects are silently discarded by schema validation.
737
+
738
+ ## Tool Blocking
739
+
740
+ Agents can bypass Loreli's MCP guardrails (stamping, role guards, label enforcement) by using raw CLI tools like `gh` or `curl` to interact with GitHub directly. The `agents.disallowedTools` config prevents this by blocking specified commands across all CLI backends.
741
+
742
+ ### How It Works
743
+
744
+ The deny list is enforced through each backend's native mechanism:
745
+
746
+ | Backend | Enforcement | Source |
747
+ |---------|-------------|--------|
748
+ | Claude Code | `--disallowedTools` CLI flag + `PreToolUse` hooks | [Hooks guide](https://code.claude.com/docs/en/hooks-guide) |
749
+ | Cursor Agent | `beforeShellExecution` hooks (`.cursor/hooks.json`) | [Cursor hooks](https://cursor.com/docs/agent/hooks) |
750
+ | Codex CLI | `rules.prefix_rules` via `-c` flags | [Codex config](https://developers.openai.com/codex/config-reference) |
751
+
752
+ When `prepare()` scaffolds an agent workspace with a non-empty deny list, it creates/updates three enforcement files:
753
+
754
+ - **`.loreli/deny.sh`** — Common deny script used by both Claude and Cursor hooks. Reads JSON from stdin, extracts the command, and exits with code 2 (block) if the first token matches a denied command. Exit code 2 is the universal block signal recognized by both Claude Code and Cursor Agent. Always overwritten when the deny list changes.
755
+ - **`.claude/settings.local.json`** — Claude Code project hooks config referencing `deny.sh` for `PreToolUse` events on Bash tools. **Merged** into existing file — user-defined hooks and non-hook settings (e.g. `permissions`) are preserved.
756
+ - **`.cursor/hooks.json`** — Cursor Agent hooks config referencing `deny.sh` for `beforeShellExecution` events with a regex matcher. **Merged** into existing file — user-defined hooks are preserved.
757
+
758
+ Loreli's hook entry is identified by its reference to `deny.sh` in the command string. On subsequent runs, the existing Loreli entry is updated in place (e.g. when the deny list changes) rather than duplicated.
759
+
760
+ ### Customizing the Deny List
761
+
762
+ Override the default deny list in `loreli.yml`:
763
+
764
+ ```yaml
765
+ agents:
766
+ disallowedTools:
767
+ - gh
768
+ - curl
769
+ - wget
770
+ ```
771
+
772
+ To disable tool blocking entirely, set an empty array:
773
+
774
+ ```yaml
775
+ agents:
776
+ disallowedTools: []
777
+ ```
778
+
779
+ ## Input Validation (`check`)
780
+
781
+ The `check` module provides strict validators for tool arguments, preventing invalid inputs before any side effects occur. All validators throw descriptive errors on invalid input and return the validated value on success.
782
+
783
+ ```js
784
+ import { check } from 'loreli/config';
785
+
786
+ check.repo('owner/repo'); // returns 'owner/repo'
787
+ check.repo('invalid'); // throws: Invalid repository format
788
+
789
+ check.name('optimus-0'); // returns 'optimus-0'
790
+ check.name('x'.repeat(65)); // throws: Agent name too long
791
+
792
+ check.role('action'); // returns 'action'
793
+ check.role('admin'); // throws: Invalid role
794
+
795
+ check.theme('transformers'); // returns 'transformers'
796
+ check.theme(['pokemon', 'marvel']); // returns ['pokemon', 'marvel']
797
+ check.provider('anthropic'); // returns 'anthropic'
798
+ check.positive(42, 'PR'); // returns 42
799
+ check.positive(-1, 'count'); // throws: count must be a positive number
800
+ ```
801
+
802
+ ### API
803
+
804
+ | Function | Rule | Error |
805
+ |----------|------|-------|
806
+ | `check.repo(str)` | `owner/name` format, alphanumeric + `.` `-` `_` | `Invalid repository format` |
807
+ | `check.name(str)` | `[A-Za-z0-9_-]+`, max 64 chars | `Agent name too long` / `Invalid agent name` |
808
+ | `check.role(str)` | `planner` \| `action` \| `reviewer` | `Invalid role` |
809
+ | `check.theme(str\|str[])` | Valid theme name(s); arrays must be non-empty | `Invalid theme` / `Theme list must not be empty` |
810
+ | `check.provider(str)` | `openai` \| `anthropic` \| `cursor-openai` \| `cursor-anthropic` | `Invalid provider` |
811
+ | `check.positive(n, label)` | Finite positive number | `{label} must be a positive number` |
812
+
813
+ All validators follow the pattern: required string → format check → return validated value. `null`, `undefined`, and empty strings are rejected with "required" errors.
814
+
815
+ ## Schema Validation
816
+
817
+ The `validate(raw)` function normalizes raw YAML content:
818
+
819
+ - Strips unknown keys
820
+ - Validates types (strings, numbers, arrays of strings)
821
+ - `theme` accepts both a string and an array of strings (single-element arrays collapse to a string)
822
+ - Returns only known, valid fields
823
+
824
+ Invalid values are silently discarded, allowing partial `loreli.yml` files to work correctly.
825
+
826
+ ## Error Handling
827
+
828
+ | Scenario | Behavior |
829
+ |----------|----------|
830
+ | `loreli.yml` missing | `load()` returns `false`, defaults apply |
831
+ | Malformed YAML | `load()` returns `false`, defaults apply |
832
+ | Invalid type in config | `validate()` strips the key, default applies |
833
+ | Unknown keys in YAML | Silently ignored |