lgtm-specs 0.0.4

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 (212) hide show
  1. package/.claude/settings.local.json +14 -0
  2. package/.gemini/README.md +8 -0
  3. package/.gemini/config.yaml +20 -0
  4. package/.gemini/styleguide.md +35 -0
  5. package/.github/workflows/README.md +5 -0
  6. package/.github/workflows/release.yml +52 -0
  7. package/.github/workflows/validate.yml +27 -0
  8. package/.prettierignore +4 -0
  9. package/.prettierrc +1 -0
  10. package/AGENTS.md +151 -0
  11. package/README.md +98 -0
  12. package/VERSION +1 -0
  13. package/agents/README.md +73 -0
  14. package/agents/modes/README.md +9 -0
  15. package/agents/modes/build.md +88 -0
  16. package/agents/modes/hack.md +76 -0
  17. package/agents/modes/review.md +79 -0
  18. package/agents/roles/builder.md +75 -0
  19. package/agents/roles/counsel.md +96 -0
  20. package/agents/roles/explorer.md +77 -0
  21. package/agents/roles/lead.md +76 -0
  22. package/agents/roles/librarian.md +63 -0
  23. package/agents/roles/planner.md +75 -0
  24. package/agents/roles/reviewer/BASE.md +9 -0
  25. package/agents/roles/reviewer/OUTPUT_FORMAT.md +4 -0
  26. package/agents/roles/reviewer/README.md +48 -0
  27. package/agents/roles/reviewer/lite.md +51 -0
  28. package/agents/roles/reviewer/logic.md +48 -0
  29. package/agents/roles/reviewer/performance.md +45 -0
  30. package/agents/roles/reviewer/plan.md +52 -0
  31. package/agents/roles/reviewer/quality.md +49 -0
  32. package/agents/roles/reviewer/security.md +47 -0
  33. package/agents/roles/reviewer/test.md +48 -0
  34. package/agents/templates/README.md +6 -0
  35. package/agents/templates/mode.md +33 -0
  36. package/agents/templates/role.md +73 -0
  37. package/contribute/README.md +24 -0
  38. package/contribute/add-agent.md +29 -0
  39. package/contribute/add-ci.md +31 -0
  40. package/contribute/add-constitution.md +17 -0
  41. package/contribute/add-law.md +20 -0
  42. package/contribute/add-policy.md +27 -0
  43. package/contribute/checklist.md +42 -0
  44. package/contribute/maintenance.md +19 -0
  45. package/contribute/update-models.md +47 -0
  46. package/docs/README.md +13 -0
  47. package/docs/adr/0001-knowledge-engineering-workflow.md +22 -0
  48. package/docs/adr/0002-rule-hierarchy.md +25 -0
  49. package/docs/adr/0003-atomic-knowledge-graph.md +21 -0
  50. package/docs/adr/0004-identification-schema.md +22 -0
  51. package/docs/adr/0005-agent-specialization.md +39 -0
  52. package/docs/adr/0006-git-workflow-integrity.md +34 -0
  53. package/docs/adr/0007-operating-modes-and-gates.md +54 -0
  54. package/docs/adr/0008-rules-vs-workflows-boundary.md +64 -0
  55. package/docs/adr/README.md +14 -0
  56. package/docs/agent_architecture.md +164 -0
  57. package/docs/context_lifecycle.md +228 -0
  58. package/docs/engineering_principles.md +128 -0
  59. package/docs/local_policies.md +59 -0
  60. package/docs/meta/collaborative_dynamics.md +142 -0
  61. package/docs/meta/domains/README.md +8 -0
  62. package/docs/meta/domains/bitcoin/01-units.md +21 -0
  63. package/docs/meta/domains/bitcoin/02-broadcast-cancellation.md +20 -0
  64. package/docs/meta/domains/bitcoin/03-fee-rates-rounding.md +21 -0
  65. package/docs/meta/domains/bitcoin/04-confirmations-reorgs.md +20 -0
  66. package/docs/meta/domains/bitcoin/05-address-gap-limit.md +16 -0
  67. package/docs/meta/domains/bitcoin/06-relay-policy.md +27 -0
  68. package/docs/meta/domains/bitcoin/README.md +12 -0
  69. package/docs/meta/domains/git/01-workflow.md +89 -0
  70. package/docs/meta/domains/git/02-commits.md +57 -0
  71. package/docs/meta/domains/git/03-collaboration.md +40 -0
  72. package/docs/meta/domains/git/04-integrity.md +26 -0
  73. package/docs/meta/domains/git/05-configuration.md +209 -0
  74. package/docs/meta/domains/git/06-advanced.md +130 -0
  75. package/docs/meta/domains/git/README.md +29 -0
  76. package/docs/meta/industry_best_practices.md +555 -0
  77. package/docs/meta/languages/README.md +8 -0
  78. package/docs/meta/languages/go/01-concurrency.md +37 -0
  79. package/docs/meta/languages/go/02-api-design.md +30 -0
  80. package/docs/meta/languages/go/03-resilience.md +27 -0
  81. package/docs/meta/languages/go/04-errors.md +27 -0
  82. package/docs/meta/languages/go/05-performance.md +18 -0
  83. package/docs/meta/languages/go/06-safety.md +18 -0
  84. package/docs/meta/languages/go/07-testing.md +44 -0
  85. package/docs/meta/languages/go/08-config-layout.md +23 -0
  86. package/docs/meta/languages/go/README.md +14 -0
  87. package/docs/meta/languages/typescript/01-strictness.md +19 -0
  88. package/docs/meta/languages/typescript/02-immutability.md +15 -0
  89. package/docs/meta/languages/typescript/03-async.md +18 -0
  90. package/docs/meta/languages/typescript/04-design.md +19 -0
  91. package/docs/meta/languages/typescript/05-control-flow.md +11 -0
  92. package/docs/meta/languages/typescript/README.md +11 -0
  93. package/docs/meta/workflow.md +68 -0
  94. package/docs/philosophy.md +36 -0
  95. package/integrate/README.md +459 -0
  96. package/integrate/versioning.md +41 -0
  97. package/models/README.md +68 -0
  98. package/models/registry.yaml +55 -0
  99. package/package.json +11 -0
  100. package/rules/README.md +57 -0
  101. package/rules/RULE-00000-EXAMPLE.md +29 -0
  102. package/rules/constitution/CONS-00001-srp.md +40 -0
  103. package/rules/constitution/CONS-00002-ocp.md +43 -0
  104. package/rules/constitution/CONS-00003-lsp.md +44 -0
  105. package/rules/constitution/CONS-00004-isp.md +46 -0
  106. package/rules/constitution/CONS-00005-dip.md +37 -0
  107. package/rules/constitution/CONS-00006-dry.md +45 -0
  108. package/rules/constitution/CONS-00007-demeter.md +35 -0
  109. package/rules/constitution/CONS-00008-composition.md +44 -0
  110. package/rules/constitution/CONS-00009-deep-modules.md +39 -0
  111. package/rules/constitution/CONS-00010-kiss.md +47 -0
  112. package/rules/constitution/CONS-00011-yagni.md +49 -0
  113. package/rules/constitution/CONS-00012-cognitive-limits.md +28 -0
  114. package/rules/constitution/CONS-00013-boy-scout.md +27 -0
  115. package/rules/constitution/CONS-00014-broken-windows.md +35 -0
  116. package/rules/constitution/CONS-00015-safety.md +46 -0
  117. package/rules/constitution/CONS-00016-cqs.md +39 -0
  118. package/rules/constitution/CONS-00017-postel.md +35 -0
  119. package/rules/constitution/CONS-00018-cap.md +35 -0
  120. package/rules/constitution/CONS-00019-fallacies.md +37 -0
  121. package/rules/constitution/CONS-00020-shift-left.md +28 -0
  122. package/rules/constitution/CONS-00021-congruence.md +28 -0
  123. package/rules/constitution/CONS-00022-orthogonality.md +40 -0
  124. package/rules/constitution/CONS-00023-determinism.md +38 -0
  125. package/rules/constitution/CONS-00024-security.md +42 -0
  126. package/rules/constitution/CONS-00025-efficiency.md +38 -0
  127. package/rules/constitution/CONS-00026-resilience.md +41 -0
  128. package/rules/constitution/CONS-00027-transparency.md +40 -0
  129. package/rules/constitution/CONS-00028-evolvability.md +36 -0
  130. package/rules/constitution/CONS-00029-operability.md +36 -0
  131. package/rules/constitution/CONS-00030-rework-cycle.md +27 -0
  132. package/rules/constitution/CONS-00031-checklist.md +28 -0
  133. package/rules/constitution/CONS-00032-documentation.md +39 -0
  134. package/rules/constitution/README.md +52 -0
  135. package/rules/laws/README.md +15 -0
  136. package/rules/laws/bitcoin/BTC-00001-amounts-as-satoshis.md +39 -0
  137. package/rules/laws/bitcoin/BTC-00002-broadcast-not-cancelable.md +36 -0
  138. package/rules/laws/bitcoin/BTC-00003-fee-rate-math-rounding.md +37 -0
  139. package/rules/laws/bitcoin/BTC-00004-confirmations-and-reorgs.md +40 -0
  140. package/rules/laws/bitcoin/BTC-00005-address-gap-limit.md +37 -0
  141. package/rules/laws/bitcoin/BTC-00006-relay-is-policy-dependent.md +36 -0
  142. package/rules/laws/bitcoin/BTC-00007-dust-policy.md +36 -0
  143. package/rules/laws/bitcoin/BTC-00008-min-relay-fee.md +36 -0
  144. package/rules/laws/bitcoin/BTC-00009-feefilter.md +36 -0
  145. package/rules/laws/bitcoin/README.md +29 -0
  146. package/rules/laws/default.md +30 -0
  147. package/rules/laws/git/GIT-00001-atomic-commit.md +29 -0
  148. package/rules/laws/git/GIT-00002-imperative-subject.md +27 -0
  149. package/rules/laws/git/GIT-00003-formatting-50-72.md +28 -0
  150. package/rules/laws/git/GIT-00004-trunk-based.md +28 -0
  151. package/rules/laws/git/GIT-00005-public-immutability.md +26 -0
  152. package/rules/laws/git/GIT-00006-signing.md +27 -0
  153. package/rules/laws/git/GIT-00007-reviewer-capital.md +26 -0
  154. package/rules/laws/git/GIT-00008-patch-series.md +28 -0
  155. package/rules/laws/git/GIT-00009-branch-naming.md +28 -0
  156. package/rules/laws/git/GIT-00010-pr-hygiene.md +51 -0
  157. package/rules/laws/git/GIT-00011-merge-method.md +35 -0
  158. package/rules/laws/git/GIT-00012-conflict-resolution.md +35 -0
  159. package/rules/laws/git/GIT-00013-ignore-standards.md +38 -0
  160. package/rules/laws/git/GIT-00014-lfs-large-binaries.md +37 -0
  161. package/rules/laws/git/GIT-00015-git-hooks.md +35 -0
  162. package/rules/laws/git/GIT-00016-branch-protection.md +34 -0
  163. package/rules/laws/git/GIT-00017-secrets-management.md +34 -0
  164. package/rules/laws/git/GIT-00018-ci-enforcement.md +33 -0
  165. package/rules/laws/git/GIT-00019-review-checklist.md +39 -0
  166. package/rules/laws/git/GIT-00020-issue-references.md +34 -0
  167. package/rules/laws/git/GIT-00021-partial-staging.md +38 -0
  168. package/rules/laws/git/GIT-00022-feature-flags.md +33 -0
  169. package/rules/laws/git/GIT-00023-breaking-changes.md +41 -0
  170. package/rules/laws/git/GIT-00024-dependency-management.md +44 -0
  171. package/rules/laws/git/GIT-00025-large-repository-optimization.md +54 -0
  172. package/rules/laws/git/README.md +31 -0
  173. package/rules/laws/go/GO-00001-actor-model.md +51 -0
  174. package/rules/laws/go/GO-00002-api-design.md +37 -0
  175. package/rules/laws/go/GO-00003-error-handling.md +43 -0
  176. package/rules/laws/go/GO-00004-context.md +45 -0
  177. package/rules/laws/go/GO-00005-performance.md +40 -0
  178. package/rules/laws/go/GO-00006-packages.md +29 -0
  179. package/rules/laws/go/GO-00007-circuit-breakers.md +43 -0
  180. package/rules/laws/go/GO-00008-safety.md +39 -0
  181. package/rules/laws/go/GO-00009-table-driven-test.md +48 -0
  182. package/rules/laws/go/GO-00010-escape-analysis.md +37 -0
  183. package/rules/laws/go/GO-00011-retry.md +45 -0
  184. package/rules/laws/go/GO-00012-rate-limiting.md +42 -0
  185. package/rules/laws/go/GO-00013-io-buffering.md +43 -0
  186. package/rules/laws/go/GO-00014-memory-layout.md +41 -0
  187. package/rules/laws/go/GO-00015-aaa-pattern.md +49 -0
  188. package/rules/laws/go/GO-00016-test-libraries.md +35 -0
  189. package/rules/laws/go/GO-00017-comments.md +37 -0
  190. package/rules/laws/go/GO-00018-test-isolation.md +38 -0
  191. package/rules/laws/go/GO-00019-test-comments.md +36 -0
  192. package/rules/laws/go/GO-00020-mocking.md +36 -0
  193. package/rules/laws/go/GO-00021-configuration.md +36 -0
  194. package/rules/laws/go/GO-00022-observability.md +34 -0
  195. package/rules/laws/go/GO-00023-dependency-management.md +28 -0
  196. package/rules/laws/go/GO-00024-project-layout.md +30 -0
  197. package/rules/laws/go/GO-00025-concurrency-patterns.md +39 -0
  198. package/rules/laws/go/README.md +45 -0
  199. package/rules/laws/typescript/README.md +14 -0
  200. package/rules/laws/typescript/TS-00001-no-any.md +39 -0
  201. package/rules/laws/typescript/TS-00002-immutability.md +36 -0
  202. package/rules/laws/typescript/TS-00003-async.md +35 -0
  203. package/rules/laws/typescript/TS-00004-strict-null.md +38 -0
  204. package/rules/laws/typescript/TS-00005-unions.md +35 -0
  205. package/rules/laws/typescript/TS-00006-interface.md +38 -0
  206. package/rules/laws/typescript/TS-00007-generics.md +38 -0
  207. package/rules/laws/typescript/TS-00008-modules.md +28 -0
  208. package/rules/policies/README.md +12 -0
  209. package/rules/policies/default.md +28 -0
  210. package/scripts/README.md +45 -0
  211. package/scripts/generate_release_notes.py +376 -0
  212. package/scripts/validate_specs.py +730 -0
@@ -0,0 +1,228 @@
1
+ # Context and Prompt Lifecycle
2
+
3
+ This document explains the lifecycle of the two fundamental components of the LGTM workforce:
4
+
5
+ 1. **Prompt Lifecycle**: The mechanism of how agents are invoked, how they call tools, and how the Runtime orchestrates the loop.
6
+ 2. **Context Lifecycle**: The state of knowledge—how artifacts (maps, rules, diffs) are discovered, filtered, and injected into those prompts.
7
+
8
+ Mode specs (`agents/modes/**`) define orchestration (gates/loops). Role specs (`agents/roles/**`) define worker behavior.
9
+ The implementer contract lives in `/integrate/README.md`.
10
+
11
+ ---
12
+
13
+ ## 1. Prompt Lifecycle (The Mechanism)
14
+
15
+ The "Prompt" is the interface between the Runtime and the Model. It is dynamically constructed for every turn of the conversation.
16
+
17
+ ### 1.1 The Interaction Loop (Who Talks to Whom)
18
+
19
+ The Runtime acts as the central message bus. Agents never communicate directly; they emit **Tool Calls** (structured requests) or **Final Responses** (text/JSON). The Runtime intercepts these signals, executes the requested action (e.g., run a sub-agent, read a file), and feeds the result back to the caller.
20
+
21
+ - **User**: Initiates the Request.
22
+ - **Runtime**: The infinite loop that executes tools and manages state.
23
+ - **Lead**: The root agent that orchestrates other agents.
24
+ - **Sub-Agents**: Worker agents (Explorer, Planner, etc.) invoked by Lead via Tool Calls.
25
+
26
+ ```mermaid
27
+ sequenceDiagram
28
+ participant U as User
29
+ participant R as Runtime
30
+ participant L as "@Lead"
31
+ participant S as SubAgent ("@Explorer/@Planner")
32
+ participant T as Tools (Git/FS)
33
+
34
+ U->>R: Request
35
+ R->>L: Invoke (with Mode + Request)
36
+
37
+ loop Orchestration
38
+ L->>R: Tool Call (e.g., delegate to @Explorer)
39
+ R->>S: Invoke (with tailored Input Packet)
40
+
41
+ loop Sub-Agent Execution
42
+ S->>R: Tool Call (e.g., read file)
43
+ R->>T: Execute
44
+ T-->>R: Result
45
+ R-->>S: Tool Output
46
+ end
47
+
48
+ S-->>R: Final Response (Text/JSON)
49
+ R-->>L: Tool Output (SubAgent Result)
50
+ end
51
+
52
+ L-->>R: Final Response
53
+ R-->>U: Result
54
+ ```
55
+
56
+ ### 1.2 Prompt Construction (How a Spec becomes a Prompt)
57
+
58
+ The Runtime builds the System Prompt by combining the static Agent Spec (`agents/**/*.md`) with dynamic runtime data.
59
+
60
+ 1. **Parse**: The Runtime reads the Markdown spec and extracts tagged sections (e.g., `<Role>`, `<Workflow>`, `<Constraints>`).
61
+ 2. **Strip**: Metadata sections (`<Meta>`, `<Input>`) are stripped out.
62
+ 3. **Template**: Placeholders are replaced with actual content (see Context Lifecycle), including:
63
+ - `{{injected_rules}}` (hydrated rules)
64
+ - `{{reviewer_base_constraints}}` and `{{reviewer_output_format}}` (shared reviewer blocks)
65
+ 4. **Compose**: The final System Prompt is sent to the LLM along with the Conversation History (Messages).
66
+
67
+ For the authoritative section parsing rules and semantics, see `/integrate/README.md`.
68
+
69
+ ```mermaid
70
+ flowchart TD
71
+ SPEC["Agent Spec (agents/**)"] --> PARSE[Runtime: Parse Sections]
72
+
73
+ subgraph Context Injection
74
+ RULES[Hydrated Rules] --> TEMPLATE
75
+ MAP[Context Map] --> TEMPLATE
76
+ end
77
+
78
+ PARSE --> TEMPLATE[Runtime: Template Placeholders]
79
+ TEMPLATE --> PROMPT[Final System Prompt]
80
+ PROMPT --> LLM[Model Invocation]
81
+ ```
82
+
83
+ ---
84
+
85
+ ## 2. Context Lifecycle (The Knowledge)
86
+
87
+ "Context" is the data available to an agent. It is not global; it is discovered, filtered, and injected on a need-to-know basis to manage token costs and focus.
88
+
89
+ ### 2.1 The Context Map (The Terrain)
90
+
91
+ The **Context Map** is the foundation. `@Explorer` acts as the cartographer, converting a raw directory tree into a
92
+ semantic map of "Domains" (languages), "Policies" (repo-local guidance), and "Risks".
93
+
94
+ Policy discovery includes repo-local policies at `.lgtm/policies/README.md` (when present) and other governing docs
95
+ surfaced as **Project Policy Files**.
96
+
97
+ - **Produced by**: `@Explorer`.
98
+ - **Consumed by**: `@Lead` (routing), `@Counsel` (rule selection), `@Planner` (touchpoints).
99
+
100
+ ```mermaid
101
+ flowchart TD
102
+ U[User Request] --> L("@Lead")
103
+ L -- "Tool Call: explore(scope)" --> R[Runtime]
104
+ R -- "Invoke: Query + Scope" --> E("@Explorer")
105
+
106
+ subgraph Discovery
107
+ E -- "list/search/read" --> FS[(Filesystem)]
108
+ FS -- "Paths + Content" --> E
109
+ end
110
+
111
+ E -- "Return: Context Map (JSON/MD)" --> R
112
+ R -- "Tool Output: Context Map" --> L
113
+
114
+ L -.-> NOTE[The Map is now in @Lead context]
115
+
116
+ L -- "Pass Map in Input" --> P("@Planner")
117
+ L -- "Pass Map in Input" --> C("@Counsel")
118
+ ```
119
+
120
+ ### 2.2 Rule Context (The Law)
121
+
122
+ Rule context is a two-stage pipeline: **Selection** and **Hydration**.
123
+
124
+ 1. **Selection**: `@Counsel` selects relevant _paths_ based on the Context Map. It does not read the rule content.
125
+ 2. **Hydration**: The **Runtime** reads the files, strips headers (metadata), and renders the body text.
126
+ 3. **Injection**: The Runtime injects the text into the `{{injected_rules}}` placeholder of downstream agents.
127
+ Shared placeholders (reviewer blocks) are also expanded during prompt templating.
128
+
129
+ ```mermaid
130
+ flowchart TD
131
+ L("@Lead") -- "Tool Call: counsel(task, map, indices)" --> R[Runtime]
132
+ R -- "Invoke: Task + Context Map + Indices" --> C("@Counsel")
133
+ C -- "Return: JSON paths" --> R
134
+
135
+ subgraph Hydration [Runtime Responsibility]
136
+ R -- "Read files" --> FS[(Filesystem)]
137
+ FS -- "Raw markdown" --> R
138
+ R -- "Strip + render (trimmed/full)" --> TEXT[Rule bodies]
139
+ end
140
+
141
+ subgraph Injection
142
+ TEXT -- "Inject subset" --> P("@Planner")
143
+ TEXT -- "Inject per-reviewer subset" --> REV("@Reviewers")
144
+ TEXT -- "Inject subset" --> B("@Builder")
145
+ end
146
+ ```
147
+
148
+ ### 2.3 Tiered Git Context (The Change)
149
+
150
+ Git context is heavy. To maintain speed and reduce costs, we deliver it in tiers.
151
+ Default routing is by role; the Runtime may override based on mode and task.
152
+
153
+ - **Tier 0 (Intent)**: Commit subjects. Cheap. Default: Lead/Counsel; may also appear in `Change Manifest` for others.
154
+ - **Tier 1 (Scope)**: File manifest. Moderate. Default: Planner; optional for Explorer/Lead/Counsel.
155
+ - **Tier 2 (Detail)**: Filtered diff. Expensive. Default: Reviewers; optional for Builder when addressing findings; Lead
156
+ sees Tier 2 only during arbitration.
157
+ - _Optimization_: Tier 2 is often provided as a `Diff Command` rather than inline text, letting the agent fetch it only if needed.
158
+
159
+ ```mermaid
160
+ flowchart TD
161
+ GIT[(Git)] --> T0[Tier 0: Commit Log]
162
+ GIT --> T1[Tier 1: File Manifest]
163
+ GIT --> T2[Tier 2: Filtered Diff]
164
+
165
+ L("@Lead")
166
+ C("@Counsel")
167
+ E("@Explorer")
168
+ P("@Planner")
169
+ REV("@Reviewers")
170
+ B("@Builder")
171
+
172
+ subgraph "High Level (Intent)"
173
+ T0 --> L
174
+ T0 --> C
175
+ end
176
+
177
+ subgraph "Mid Level (Scope)"
178
+ T1 -. Optional .-> E
179
+ T1 --> P
180
+ end
181
+
182
+ subgraph "Low Level (Details)"
183
+ T2 -- "Inline or Command" --> REV
184
+ T2 -. Optional .-> B
185
+ T2 -. Arbitration .-> L
186
+ end
187
+ ```
188
+
189
+ ### 2.4 Arbitration Context (The Escalation)
190
+
191
+ When consensus fails (e.g., Reviewers reject a plan, or disagree on a finding), the `@Lead` enters **Arbitration Mode**. The context window expands to resolve the conflict.
192
+
193
+ 1. **Full Rules**: Contested rules are re-injected with full examples/rationale (overriding the "Trimmed" default).
194
+ 2. **Tier 2 Context**: The Lead, who normally sees only high-level signals, is granted access to the specific diff lines in question to make a ruling.
195
+
196
+ ```mermaid
197
+ stateDiagram-v2
198
+ state "Standard Mode" as S
199
+ state "Arbitration Mode" as A
200
+
201
+ S --> A: Deadlock / Timeout
202
+
203
+ state S {
204
+ [*] --> Lead
205
+ Lead --> Reviewers: Sparse Context
206
+ Reviewers --> Lead: Conflict
207
+ }
208
+
209
+ state A {
210
+ [*] --> Lead
211
+ Lead --> Runtime: Request Arbitration
212
+ Runtime --> Lead: Inject full contested rules + Tier 2 diff (targeted)
213
+ Lead --> User: Final Verdict
214
+ }
215
+ ```
216
+
217
+ ---
218
+
219
+ ## 3. What Goes Where (Quick Reference)
220
+
221
+ | Actor | Produces | Consumed by | Notes |
222
+ | ----------- | -------------------------------------- | ------------------------- | ----------------------------------------------------- |
223
+ | `@Explorer` | Context Map (Summary + Full) | Lead, Counsel, Planner | Summary should include domains + policy files. |
224
+ | `@Counsel` | Rule/policy paths (JSON) | Runtime (tool logs) | Counsel never outputs rule bodies. |
225
+ | Runtime | Hydrated rules + shared blocks | Planner/Builder/Reviewers | Inject role-appropriate subsets; expand placeholders. |
226
+ | `@Planner` | Execution plan / audit plan | Lead, Plan-Reviewer | Plan references rule IDs, not rule text. |
227
+ | Reviewers | Findings (bullets) | Lead | Evidence required (paths + line numbers). |
228
+ | `@Lead` | Synthesis / report / next-step routing | User, Runtime | Clarifies disputes; triggers arbitration when needed. |
@@ -0,0 +1,128 @@
1
+ # Engineering Principles
2
+
3
+ This document abstracts the "First Principles" of software engineering. It groups the 12 core properties into four dimensions, defining the complete quality space of a software system. It is derived from state-of-the-art industry standards recorded in [Industry Best Practices](meta/industry_best_practices.md).
4
+
5
+ ### Quality Dimensions at a Glance
6
+
7
+ | Dimension | Phase | Question | Qualities |
8
+ | :---------------------------------------------------------------- | :------ | :--------------------- | :----------------------------------------------------------------------------------------------------------------------------------------- |
9
+ | **[Structural Design](#structural-design-the-code)** | Design | "How is it organized?" | [Orthogonality](#1-orthogonality-decoupling), [Cohesion](#2-cohesion-focus), [Parsimony](#3-parsimony-simplicity) |
10
+ | **[Behavioral Correctness](#behavioral-correctness-the-logic)** | Verify | "Does it work?" | [Correctness](#4-correctness-safety), [Determinism](#5-determinism-predictability), [Security](#6-security-defense) |
11
+ | **[Runtime Survivability](#runtime-survivability-the-execution)** | Execute | "Will it survive?" | [Robustness](#7-robustness-hardness), [Resilience](#8-resilience-elasticity), [Efficiency](#9-efficiency-performance) |
12
+ | **[Operational Lifecycle](#operational-lifecycle-the-future)** | Evolve | "Can we maintain it?" | [Transparency](#10-transparency-observability), [Operability](#11-operability-runnability), [Evolvability](#12-evolvability-changeability) |
13
+
14
+ ---
15
+
16
+ # Structural Design (The Code)
17
+
18
+ **Thesis**: Complexity is managed by decoupling components (Orthogonality), keeping related code together (Cohesion), and minimizing parts (Parsimony).
19
+
20
+ ## 1. Orthogonality (Decoupling)
21
+
22
+ **Definition**: A system design where changing one component does not create side effects or require changes in other, unrelated components. It is the mathematical independence of system variables.
23
+
24
+ - **Requirements**: Narrow interfaces, no global state.
25
+ - **References**: [SOLID](meta/industry_best_practices.md#1-solid-principles), [Law of Demeter](meta/industry_best_practices.md#84-law-of-demeter).
26
+
27
+ ## 2. Cohesion (Focus)
28
+
29
+ **Definition**: The degree to which the elements inside a module belong together. A highly cohesive module performs one task and contains most of the data and logic required to perform it.
30
+
31
+ - **Requirements**: Fields participate in primary responsibility, locality of behavior.
32
+ - **References**: [SRP](meta/industry_best_practices.md#11-single-responsibility-principle-srp), [Deep Modules](meta/industry_best_practices.md#21-deep-modules).
33
+
34
+ ## 3. Parsimony (Simplicity)
35
+
36
+ **Definition**: The principle that the simplest solution that suffices is the correct one. It prioritizes the reduction of moving parts and cognitive load.
37
+
38
+ - **Requirements**: Reject speculative generality, prefer standard libraries.
39
+ - **References**: [KISS](meta/industry_best_practices.md#81-kiss-keep-it-simple-stupid), [YAGNI](meta/industry_best_practices.md#82-yagni-you-arent-gonna-need-it), [Cognitive Limits](meta/industry_best_practices.md#43-cognitive-limits-batch-size).
40
+
41
+ ---
42
+
43
+ # Behavioral Correctness (The Logic)
44
+
45
+ **Thesis**: A system must fulfill its contract (Correctness), behave predictably (Determinism), and protect its assets (Security).
46
+
47
+ ## 4. Correctness (Safety)
48
+
49
+ **Definition**: The guarantee that the system behaves according to its specification and that illegal states are mathematically unrepresentable.
50
+
51
+ - **Requirements**: State space encoded in types (Enums/Unions), invariants enforced by construction.
52
+ - **References**: [Safety by Design](meta/industry_best_practices.md#61-safety-by-design), [LSP](meta/industry_best_practices.md#13-liskov-substitution-principle-lsp).
53
+
54
+ ## 5. Determinism (Predictability)
55
+
56
+ **Definition**: The property that a system's behavior is consistent and reproducible given the same initial state and inputs.
57
+
58
+ - **Requirements**: Pure functions, explicit dependencies (injected).
59
+ - **References**: [CQS](meta/industry_best_practices.md#62-command-query-separation-cqs), [Explicitness](meta/industry_best_practices.md#35-explicitness).
60
+
61
+ ## 6. Security (Defense)
62
+
63
+ **Definition**: The ability of the system to protect information and maintain functionality in the face of malicious acts.
64
+
65
+ - **Requirements**: Least Privilege, Zero Trust, Secure Defaults.
66
+ - **References**: [Security Engineering](meta/industry_best_practices.md#9-security-engineering), [Privacy](meta/industry_best_practices.md#17-privacy--compliance).
67
+
68
+ ---
69
+
70
+ # Runtime Survivability (The Execution)
71
+
72
+ **Thesis**: A running system must resist local failure (Robustness), recover from systemic failure (Resilience), and respect resource constraints (Efficiency).
73
+
74
+ ## 7. Robustness (Hardness)
75
+
76
+ **Definition**: The ability to resist local failure by handling erroneous inputs or unexpected states gracefully without crashing.
77
+
78
+ - **Requirements**: Input sanitization at boundary, defining errors out of existence.
79
+ - **References**: [Postel's Law](meta/industry_best_practices.md#63-postels-law), [Input Validation](meta/industry_best_practices.md#94-input-validation).
80
+
81
+ ## 8. Resilience (Elasticity)
82
+
83
+ **Definition**: The ability of a system to recover from failure and restore functionality, often involving degradation of service rather than total collapse.
84
+
85
+ - **Requirements**: Idempotency, circuit breakers, timeouts.
86
+ - **References**: [Fallacies](meta/industry_best_practices.md#72-fallacies-of-distributed-computing), [Operational Reliability](meta/industry_best_practices.md#18-operational-reliability).
87
+
88
+ ## 9. Efficiency (Performance)
89
+
90
+ **Definition**: The optimal use of bounded computational resources (time, memory, bandwidth) to achieve the desired result.
91
+
92
+ - **Requirements**: Known Big-O complexity, bounded resource usage.
93
+ - **References**: [Performance](meta/industry_best_practices.md#12-performance--efficiency), [Data Engineering](meta/industry_best_practices.md#13-data-engineering).
94
+
95
+ ---
96
+
97
+ # Operational Lifecycle (The Future)
98
+
99
+ **Thesis**: A system must be visible (Transparency), runnable (Operability), and adaptable (Evolvability) to survive long-term.
100
+
101
+ ## 10. Transparency (Observability)
102
+
103
+ **Definition**: The ability to understand the internal state and runtime behavior of a system by examining its outputs.
104
+
105
+ - **Requirements**: Telemetry by design, distinguishable failure states.
106
+ - **References**: [Observability](meta/industry_best_practices.md#11-observability--operations).
107
+
108
+ ## 11. Operability (Runnability)
109
+
110
+ **Definition**: The ease with which the system can be run, monitored, and maintained by the engineering team.
111
+
112
+ - **Requirements**: Runbooks, congruent team boundaries, automated checklists.
113
+ - **References**: [Socio-Technical Congruence](meta/industry_best_practices.md#52-socio-technical-congruence), [Checklist](meta/industry_best_practices.md#44-the-checklist).
114
+
115
+ ## 12. Evolvability (Changeability)
116
+
117
+ **Definition**: The ease with which the system can be adapted to new requirements or modified to fix defects over time.
118
+
119
+ - **Requirements**: Testability, Feature Flags, API Versioning.
120
+ - **References**: [OCP](meta/industry_best_practices.md#12-openclosed-principle-ocp), [Delivery](meta/industry_best_practices.md#14-delivery--evolution).
121
+
122
+ ---
123
+
124
+ ## Interplay of Qualities
125
+
126
+ - **Structural Design** enables **Evolvability**: If code is orthogonal, it is easier to change safely.
127
+ - **Behavioral Correctness** enables **Robustness**: If invariants are enforced by types, runtime validation has less work to do.
128
+ - **Transparency** enables **Operability**: You cannot run what you cannot see.
@@ -0,0 +1,59 @@
1
+ # Local Policies (Consumer Repos)
2
+
3
+ Local policies are repo-specific by-laws that LGTM tools can load from the user's repository to override/extend defaults.
4
+
5
+ Primary entrypoint:
6
+
7
+ - `.lgtm/policies/README.md`
8
+
9
+ If it does not exist, tools fall back to `rules/policies/default.md`.
10
+
11
+ ## Recommended Layout (Zettelkasten)
12
+
13
+ Create `.lgtm/policies/` with a Primary index file.
14
+
15
+ - `.lgtm/policies/README.md`: the Primary policy entrypoint (summary + links).
16
+ - `.lgtm/policies/*.md`: atomic policy notes (one policy per file).
17
+
18
+ Rule of thumb: keep the Primary file short and link out to atomic notes.
19
+
20
+ ## Policy File Format (Tool-Consumable)
21
+
22
+ To be safely injectable, local policy files SHOULD follow the same section structure as rules in this repo:
23
+
24
+ - `## Definition`
25
+ - `## Requirements`
26
+ - `## Anti-Patterns`
27
+ - `## Examples`
28
+
29
+ This makes it possible for tools to treat policies like other injected rules.
30
+
31
+ ## Prompt Template (Generate Local Policies)
32
+
33
+ Use this prompt in the consumer repo to generate `.lgtm/policies/README.md` and a small set of atomic notes.
34
+
35
+ ```text
36
+ You are generating repo-local LGTM policy files.
37
+
38
+ Inputs you will be given:
39
+ - Repository tree (paths)
40
+ - Key config files (CI, lint, format, language toolchains)
41
+ - Contribution/release docs (CONTRIBUTING, SECURITY, CODEOWNERS, docs)
42
+
43
+ Output requirements:
44
+ 1) Create `.lgtm/policies/README.md` as the Primary entrypoint.
45
+ 2) Create 3-8 atomic policy note files under `.lgtm/policies/` for specific topics that matter in this repo.
46
+ 3) Each policy file MUST contain: `## Definition`, `## Requirements`, `## Anti-Patterns`, `## Examples`.
47
+ 4) Requirements must be concrete and testable (commands, checks, or observable behaviors).
48
+ 5) Keep the Primary file short: summarize the top rules and link to atomic notes.
49
+ 6) Avoid duplicating generic best practices; focus on repo-specific by-laws (tooling choices, workflow rules,
50
+ directory conventions, review requirements).
51
+
52
+ Return:
53
+ - A file list with paths.
54
+ - The full contents for each file.
55
+ ```
56
+
57
+ ## Related
58
+
59
+ - [`contribute/add-policy.md`](/contribute/add-policy.md): How to add shared policies to `lgtm-specs`.
@@ -0,0 +1,142 @@
1
+ # Collaborative Dynamics & Team Architecture
2
+
3
+ This document defines the principles of **Socio-Technical Congruence** and **High-Performance Collaboration**. It serves as the standard for how Agents (and Humans) interact within the LGTM organization.
4
+
5
+ **Sources**: [Team Topologies](https://teamtopologies.com/), [Google SRE](https://sre.google/), [GitLab Handbook](https://about.gitlab.com/handbook/).
6
+
7
+ ---
8
+
9
+ # 1. Cognitive Load Theory
10
+
11
+ _Source: [John Sweller](https://en.wikipedia.org/wiki/Cognitive_load_theory) / [Matthew Skelton & Manuel Pais](https://teamtopologies.com/)_
12
+
13
+ The fundamental constraint on software delivery is not CPU cycles, but human working memory.
14
+
15
+ ## 1.1 Types of Load
16
+
17
+ - **Intrinsic Load**: The difficulty of the task itself (e.g., recursive logic). _Goal: Manage it._
18
+ - **Extraneous Load**: The environment noise (e.g., confusing API, manual deployment). _Goal: Eliminate it._
19
+ - **Germane Load**: The effort of learning and schema formation. _Goal: Optimize it._
20
+
21
+ ## 1.2 The Strategy
22
+
23
+ - **Minimize Extraneous Load**: Agents/Tools must handle rote tasks (Linting, Formatting, Imports). If a human has to "remember" to format code, the tool has failed.
24
+ - **Match Team to Stream**: A team's cognitive capacity must match the complexity of their owned software subsystem.
25
+
26
+ ---
27
+
28
+ # 2. Team Topologies & Ownership
29
+
30
+ _Source: [Conway's Law](https://en.wikipedia.org/wiki/Conway%27s_law) / [Inverse Conway Maneuver](https://martinfowler.com/bliki/ConwaysLaw.html)_
31
+
32
+ ## 2.1 The Stream-Aligned Team (The "Squad")
33
+
34
+ - **Purpose**: Aligned to a single stream of work. Empowered to deliver value independently.
35
+ - **Composition**: Cross-functional (Dev + QA + Ops). No hand-offs.
36
+ - **Agent Mapping**: The default "LGTM Engineering Team" (Lead, Builder, Reviewer).
37
+
38
+ ## 2.2 The Two-Pizza Rule
39
+
40
+ - **Principle**: A team should be small enough (5-7 agents/people) to maintain high-bandwidth communication without combinatorial explosion.
41
+
42
+ ## 2.3 The Team API
43
+
44
+ - **Definition**: Teams interact only through defined, versioned interfaces.
45
+ - **SLA Schema**:
46
+ - **Response Time**: (e.g., "Critical: 1h, Normal: 24h")
47
+ - **Versioning**: (e.g., "v1.0 stable, v2.0 beta")
48
+ - **Support Channel**: (e.g., "#team-auth-help")
49
+
50
+ ---
51
+
52
+ # 3. Decision Making & Escalation
53
+
54
+ _Source: [Thinking in Bets](https://en.wikipedia.org/wiki/Annie_Duke#Thinking_in_Bets) / [Amazon Leadership Principles](https://www.amazon.jobs/en/principles)_
55
+
56
+ ## 3.1 The Tie-Breaker Rule
57
+
58
+ When principles conflict, we prioritize:
59
+
60
+ 1. **Correctness** over Efficiency.
61
+ 2. **Robustness** over Features.
62
+ 3. **Transparency** over Convenience.
63
+
64
+ ## 3.2 The Disagreement Protocol
65
+
66
+ When Agents (e.g., Builder vs. Reviewer) disagree:
67
+
68
+ 1. **State the Tradeoff**: Explicitly name the conflict (e.g., "Trading Parsimony for Performance").
69
+ 2. **Consult the Principle**: Which dimension (Structure vs Behavior) takes precedence?
70
+ 3. **Escalation**: Technical -> Tech Lead. Priority -> Product Owner.
71
+ 4. **Record Decision**: If the decision is significant/irreversible, it MUST be recorded in an **Architecture Decision Record (ADR)**.
72
+
73
+ ---
74
+
75
+ # 4. Context Continuity & Onboarding
76
+
77
+ _Source: [Cognitive Load Theory](https://en.wikipedia.org/wiki/Cognitive_load_theory)_
78
+
79
+ ## 4.1 The Handoff Protocol
80
+
81
+ When passing work between Agents:
82
+
83
+ - **Outgoing Agent**: Summarize Current State, Decisions Made, and Open Questions.
84
+ - **Incoming Agent**: Acknowledge receipt, Validate understanding, Identify missing context within 5 minutes.
85
+
86
+ ## 4.2 The Context Budget
87
+
88
+ Every interaction has a cost (Tokens/Time). Prioritize recent changes. Link to full details (Artifacts), do not inline them.
89
+
90
+ ## 4.3 Agent Onboarding
91
+
92
+ When an Agent joins a new codebase:
93
+
94
+ - **Read**: Engineering Principles (`docs/engineering_principles.md`) and Best Practices (`docs/meta/industry_best_practices.md`).
95
+ - **Study**: 3 representative PRs and key ADRs.
96
+ - **Task**: Complete 1 guided verification task before writing code.
97
+
98
+ ---
99
+
100
+ # 5. Collaborative Mechanics
101
+
102
+ _Source: [GitLab Handbook](https://about.gitlab.com/handbook/) / [Deep Work (Cal Newport)](https://www.calnewport.com/books/deep-work/)_
103
+
104
+ ## 5.1 Async First & Written Culture
105
+
106
+ - **Principle**: "If it isn't written down, it didn't happen."
107
+ - **Implementation**: Agents communicate via **Artifacts** (PRs, Design Docs), not transient chat.
108
+
109
+ ## 5.2 The Maker's Schedule
110
+
111
+ - **Principle**: Interruptions destroy deep work context.
112
+ - **Protocol**: Batch communications. Do not interrupt execution loops. Wait for "Ready" signals.
113
+
114
+ ## 5.3 Communication Standards
115
+
116
+ - **No Hello**: State the request immediately.
117
+ - **Structured Updates**: STATUS | BLOCKERS | NEXT.
118
+
119
+ ---
120
+
121
+ # 6. Operational Resilience
122
+
123
+ _Source: [Google SRE Book](https://sre.google/sre-book/table-of-contents/)_
124
+
125
+ ## 6.1 Agent Failure Modes
126
+
127
+ - **Context Overflow**: Exceeding token limits.
128
+ - **Hallucination**: Producing incorrect info.
129
+ - **Stall**: No progress.
130
+
131
+ ## 6.2 Circuit Breakers
132
+
133
+ After N failures:
134
+
135
+ 1. **Halt** the agent.
136
+ 2. **Preserve** context/state.
137
+ 3. **Escalate** to human or Lead Agent.
138
+
139
+ ## 6.3 Psychological Safety
140
+
141
+ - **Principle**: **Blameless Postmortems.**
142
+ - **Implementation**: Analyze the _Process_ (Prompt/Context), not the _Agent_. Assume rationality.
@@ -0,0 +1,8 @@
1
+ # Engineering Domains
2
+
3
+ **Scope**: High-level systems, infrastructure, and cross-cutting concerns.
4
+
5
+ ## Index
6
+
7
+ - **[Git](git/README.md)**: The protocol of version control and collaboration.
8
+ - **[Bitcoin](bitcoin/README.md)**: Consensus and financial engineering.
@@ -0,0 +1,21 @@
1
+ # Bitcoin: Units & Amounts
2
+
3
+ **Sources**:
4
+
5
+ - Bitcoin Core `amount.h` (CAmount / satoshis): https://github.com/bitcoin/bitcoin/blob/master/src/amount.h
6
+
7
+ ## Amount Representation
8
+
9
+ - **MUST** represent money as integers representing **satoshis**.
10
+ - **MUST NOT** use floating point for monetary values.
11
+
12
+ ## Fee Math
13
+
14
+ - Fee rates may be fractional (e.g., sat/vB). Use exact rational math until the final conversion to sats.
15
+ - When converting a fee rate and size into a final fee in sats, be explicit about rounding.
16
+ - For fee payment constraints, prefer **rounding up** to avoid underpaying.
17
+
18
+ ## Unit Clarity
19
+
20
+ - Make units explicit in names and boundaries (e.g., `amount_sats`, `fee_rate_sat_vb`).
21
+ - Convert to display units (BTC) only at UI boundaries.
@@ -0,0 +1,20 @@
1
+ # Bitcoin: Broadcast, Cancellation, and Replacement
2
+
3
+ **Sources**:
4
+
5
+ - Bitcoin RPC `abandontransaction`: https://developer.bitcoin.org/reference/rpc/abandontransaction.html
6
+ - Bitcoin Dev Guide (Transaction broadcasting / mempool): https://developer.bitcoin.org/devguide/p2p_network.html#transaction-broadcasting
7
+ - Bitcoin Dev Guide (reissue by invalidating inputs): https://developer.bitcoin.org/devguide/transactions.html#transaction-malleability
8
+ - BIP-0125 (Opt-in Full RBF): https://github.com/bitcoin/bips/blob/master/bip-0125.mediawiki
9
+
10
+ ## Broadcast Is Not Retractable
11
+
12
+ - Once a transaction is broadcast, you cannot reliably "cancel" it by deleting it locally.
13
+ - If your node/wallet does not show it in the mempool, it may still exist on other peers and reach miners.
14
+ - Unconfirmed transactions are not a permanent part of the network state (mempools are non-persistent).
15
+
16
+ ## Practical Replacement
17
+
18
+ - The only practical way to "cancel" is to create a **conflicting spend** that double-spends at least one input.
19
+ - Replacement is not guaranteed until one of the conflicting transactions confirms.
20
+ - If you rely on replacement, ensure your wallet/node policy supports it (e.g., opt-in RBF).
@@ -0,0 +1,21 @@
1
+ # Bitcoin: Fee Rates, Rational Math, and Rounding
2
+
3
+ **Sources**:
4
+
5
+ - btcwallet/btcunit README: https://raw.githubusercontent.com/btcsuite/btcwallet/sql-wallet/pkg/btcunit/README.md
6
+ - btcwallet/btcunit fee math (round up): https://raw.githubusercontent.com/btcsuite/btcwallet/sql-wallet/pkg/btcunit/rates.go
7
+
8
+ ## Rational Fee Rates
9
+
10
+ - Fee rates may be fractional; represent them as arbitrary-precision rationals (e.g., `math/big.Rat`).
11
+ - Keep a canonical internal unit and convert explicitly.
12
+
13
+ ## Rounding Policy
14
+
15
+ - Define a single rounding policy when converting rational fee math into integer sats.
16
+ - For paying fees, prefer **ceiling** (round up) to avoid falling below minimum relay/mempool policy.
17
+
18
+ ## Units
19
+
20
+ - Make feerate units explicit (commonly sat/vB).
21
+ - Do not mix sat/vB, sat/B, and sat/kw without explicit conversion.
@@ -0,0 +1,20 @@
1
+ # Bitcoin: Confirmations & Reorgs
2
+
3
+ **Sources**:
4
+
5
+ - Bitcoin Dev Guide (Chain / confirmations): https://developer.bitcoin.org/devguide/block_chain.html
6
+
7
+ ## Confirmation Policy
8
+
9
+ - Confirmations are a risk control; treat 0-conf as reversible.
10
+ - Define explicit thresholds per asset/risk tier.
11
+
12
+ ## Reorg Handling
13
+
14
+ - Track both block height and block hash when recording confirmation state.
15
+ - On reorg, be able to rollback derived state and re-derive.
16
+
17
+ ## Practical Depth
18
+
19
+ - Design for 1-2 block reorgs as a practical concern.
20
+ - Deeper reorgs are possible; ensure rollback code is safe under repeated application.
@@ -0,0 +1,16 @@
1
+ # Bitcoin: Address Gap Limit and Recovery Risk
2
+
3
+ **Sources**:
4
+
5
+ - BIP-0044 (Address gap limit = 20): https://raw.githubusercontent.com/bitcoin/bips/master/bip-0044.mediawiki
6
+ - btcwallet issue (gap limit failure mode): https://github.com/btcsuite/btcwallet/issues/1167
7
+
8
+ ## The Gap Limit Problem
9
+
10
+ - HD wallet recovery typically scans forward until it sees N consecutive unused addresses.
11
+ - If an application generates many unused addresses, restored wallets may stop scanning early and miss funds.
12
+
13
+ ## Operational Guidance
14
+
15
+ - Avoid generating large volumes of unused deposit addresses without tracking issued-vs-used indices.
16
+ - If privacy policy requires frequent new addresses, make the gap limit an explicit, tested operational parameter.