@balpal4495/quorum 0.1.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 (39) hide show
  1. package/.github/copilot-instructions.md +94 -0
  2. package/CLAUDE.md +86 -0
  3. package/GEMINI.md +73 -0
  4. package/LICENSE +21 -0
  5. package/README.md +202 -0
  6. package/SETUP.md +256 -0
  7. package/bin/init.js +366 -0
  8. package/modules/AGENTS.md +66 -0
  9. package/modules/CLAUDE.md +64 -0
  10. package/modules/README.md +251 -0
  11. package/modules/council/advisors.ts +68 -0
  12. package/modules/council/chairman.ts +112 -0
  13. package/modules/council/deliberate.ts +106 -0
  14. package/modules/council/frame.ts +54 -0
  15. package/modules/council/index.ts +4 -0
  16. package/modules/council/personas.ts +57 -0
  17. package/modules/council/reviewers.ts +81 -0
  18. package/modules/council/types.ts +45 -0
  19. package/modules/jury/evaluate.ts +112 -0
  20. package/modules/jury/index.ts +3 -0
  21. package/modules/jury/schema.ts +15 -0
  22. package/modules/jury/types.ts +31 -0
  23. package/modules/oracle/adapters/lance-db.ts +81 -0
  24. package/modules/oracle/adapters/xenova-embedder.ts +43 -0
  25. package/modules/oracle/bm25.ts +92 -0
  26. package/modules/oracle/index.ts +36 -0
  27. package/modules/oracle/log.ts +15 -0
  28. package/modules/oracle/propose.ts +148 -0
  29. package/modules/oracle/query.ts +145 -0
  30. package/modules/oracle/summary.ts +115 -0
  31. package/modules/oracle/types.ts +32 -0
  32. package/modules/sentinel/assert.ts +95 -0
  33. package/modules/sentinel/coverage.ts +106 -0
  34. package/modules/sentinel/drift.ts +159 -0
  35. package/modules/sentinel/index.ts +6 -0
  36. package/modules/sentinel/review.ts +207 -0
  37. package/modules/setup.ts +153 -0
  38. package/modules/shared/types.ts +148 -0
  39. package/package.json +47 -0
@@ -0,0 +1,94 @@
1
+ # Project Guidelines
2
+
3
+ ## Architecture
4
+
5
+ This project uses three portable reasoning modules: **Oracle**, **Jury**, and **Council**.
6
+ They form the knowledge and validation layer for all agentic work in this codebase.
7
+
8
+ ```
9
+ oracle.query() → jury.evaluate() → council.deliberate() → human gate → Executor
10
+ ```
11
+
12
+ Source: `modules/` — see [modules/README.md](modules/README.md) for full API reference.
13
+
14
+ ---
15
+
16
+ ## Chronicle — the persistent knowledge store
17
+
18
+ Chronicle lives at `.chronicle/` and is the institutional memory of this codebase.
19
+ Every prior decision, investigation finding, and outcome is stored there.
20
+
21
+ **Always query Oracle before proposing a solution.** Treat existing entries as ground truth for what has been tried, what worked, and what failed.
22
+
23
+ ```typescript
24
+ const evidence = await oracle.query("describe what you're about to do")
25
+ // Use evidence to inform your proposal before proceeding
26
+ ```
27
+
28
+ **Never call `oracle.commit()` without explicit human approval.**
29
+ `oracle.propose()` writes a pending file. A human must call `oracle.commit(proposalId)` to index it.
30
+ There are no auto-commits. Do not attempt to bypass this gate.
31
+
32
+ ---
33
+
34
+ ## Module responsibilities
35
+
36
+ | Module | What it does | LLM? |
37
+ |---|---|---|
38
+ | `oracle.query()` | Retrieves relevant Chronicle entries by semantic + BM25 search | No |
39
+ | `oracle.propose()` | Stages a new entry for human review | No |
40
+ | `oracle.commit()` | Indexes an approved entry — human-triggered only | No |
41
+ | `jury.evaluate()` | Scores a design against evidence across 4 dimensions | Yes |
42
+ | `council.deliberate()` | Adversarial validation via advisor/reviewer fan-out | Yes |
43
+
44
+ ---
45
+
46
+ ## Setup
47
+
48
+ ```typescript
49
+ import { setup } from "./modules/setup"
50
+
51
+ const { oracle, evaluate, deliberate } = await setup({ llm: yourProvider })
52
+ ```
53
+
54
+ `setup()` creates Chronicle directories, warms the embedder, and wires all dependencies.
55
+ Call it once at application startup.
56
+
57
+ ---
58
+
59
+ ## Routing rules
60
+
61
+ After `jury.evaluate()`:
62
+
63
+ | `recommendation` | Action |
64
+ |---|---|
65
+ | `proceed` | Pass to `council.deliberate()` |
66
+ | `investigate-more` | Return to Detective with `juryOutput.gaps` |
67
+ | `redesign` | Return to Designer |
68
+
69
+ After `council.deliberate()`:
70
+
71
+ | `satisfied` | `recommendation` | Action |
72
+ |---|---|---|
73
+ | `true` | `proceed` | Human gate → Executor |
74
+ | `false` | `redesign` | Return to Designer with `verdict` as feedback |
75
+ | `false` | `investigate-more` | Return to Detective with `juryOutput.gaps` |
76
+
77
+ ---
78
+
79
+ ## Rules for AI agents
80
+
81
+ - **Evidence first.** Query Oracle before proposing any design or implementation.
82
+ - **No auto-commits.** Never call `oracle.commit()` autonomously. Only propose.
83
+ - **Cite entries.** When referencing Chronicle findings, use the entry ID (e.g. `[abc-123]`).
84
+ - **Respect refuted entries.** A `refuted` entry means this was tried and failed — surface the failure reason, don't ignore it.
85
+ - **Fail loudly.** Jury and Council throw on bad LLM output. Do not swallow errors or default to passing scores.
86
+ - **These modules are the portable core.** Detective, Designer, Executor, and Validator are application-specific — do not add them here.
87
+
88
+ ---
89
+
90
+ ## Build and test
91
+
92
+ ```bash
93
+ npx vitest run modules/
94
+ ```
package/CLAUDE.md ADDED
@@ -0,0 +1,86 @@
1
+ # Quorum — Claude Code Instructions
2
+
3
+ ## Project overview
4
+
5
+ Quorum is a portable reasoning layer for agentic codebases. Three TypeScript modules form
6
+ the knowledge and validation layer for all agentic work:
7
+
8
+ ```
9
+ oracle.query() → jury.evaluate() → council.deliberate() → human gate → Executor
10
+ ```
11
+
12
+ Full module rules and design decisions: [modules/CLAUDE.md](modules/CLAUDE.md)
13
+ File ownership map: [modules/AGENTS.md](modules/AGENTS.md)
14
+
15
+ ---
16
+
17
+ ## Gemini CLI (optional assistant)
18
+
19
+ Before attempting any Gemini call, check availability:
20
+
21
+ ```bash
22
+ which gemini 2>/dev/null
23
+ ```
24
+
25
+ If the command returns empty, skip this section entirely. The project is fully functional
26
+ without Gemini. Never try to install it or ask the user to install it mid-task.
27
+
28
+ **If Gemini is available**, use it as a large-context assistant — it can hold the entire
29
+ codebase in a single context window where you work best on focused, precise tasks.
30
+
31
+ **Call `gemini -p "..."` when:**
32
+ - You need to survey many files at once before deciding where to look
33
+ - You want to trace a pattern, type, or call across the whole codebase
34
+ - You want a second opinion on an architecture decision before proposing it to the user
35
+
36
+ **Important:** The Bash tool does not auto-source shell profiles. Always prefix Gemini
37
+ calls with `source ~/.zshrc &&` so that `GEMINI_API_KEY` and `GEMINI_CLI_TRUST_WORKSPACE`
38
+ are loaded from the user's profile before invoking the CLI.
39
+
40
+ **Patterns:**
41
+
42
+ ```bash
43
+ # Broad survey before narrowing
44
+ source ~/.zshrc && gemini -p "What are all the public exports across modules/ and what does each do?"
45
+
46
+ # Trace a pattern across many files
47
+ source ~/.zshrc && find . -name "*.ts" | xargs cat | gemini -p "Find every place oracle.commit() is called"
48
+
49
+ # Second opinion on a design
50
+ source ~/.zshrc && gemini -p "I'm about to add streaming to oracle/query.ts. Given the full codebase, what should I watch out for?"
51
+ ```
52
+
53
+ **Processing Gemini responses:**
54
+ - You reason about Gemini's output — it assists, you decide
55
+ - If Gemini contradicts what you know from reading the code, trust your direct reading
56
+ - Never pass Gemini's response to the user unfiltered; synthesise it through your own judgment
57
+
58
+ ---
59
+
60
+ ## Chronicle — the persistent knowledge store
61
+
62
+ Chronicle lives at `.chronicle/`. Every prior decision, investigation finding, and outcome
63
+ is stored there.
64
+
65
+ - **Query Oracle before proposing any solution.** Treat entries as ground truth for what has
66
+ been tried, what worked, and what failed.
67
+ - **Never call `oracle.commit()` autonomously.** Use `oracle.propose()` to stage an entry.
68
+ A human must call `oracle.commit(proposalId)` to index it. There are no exceptions.
69
+
70
+ ---
71
+
72
+ ## Rules for AI agents
73
+
74
+ - **Evidence first.** Query Oracle before proposing any design or implementation.
75
+ - **No auto-commits.** Never call `oracle.commit()` without explicit human input.
76
+ - **Cite entries.** Use entry IDs (e.g. `[abc-123]`) when referencing Chronicle findings.
77
+ - **Respect refuted entries.** Surface the failure reason — don't ignore it.
78
+ - **Fail loudly.** Jury and Council throw on bad LLM output. Do not swallow errors.
79
+
80
+ ---
81
+
82
+ ## Build and test
83
+
84
+ ```bash
85
+ npx vitest run modules/
86
+ ```
package/GEMINI.md ADDED
@@ -0,0 +1,73 @@
1
+ # Quorum — Gemini Context
2
+
3
+ > This file is optional. It is only active when Google Gemini CLI is installed and
4
+ > `GEMINI_API_KEY` is set. Projects without Gemini CLI configured can ignore it.
5
+
6
+ ## Your role in this project
7
+
8
+ You are a supporting AI in the Quorum codebase. Claude Code is the primary agent — it handles
9
+ tool execution, file edits, complex reasoning, and final decisions.
10
+
11
+ You are called in two modes:
12
+
13
+ 1. **Assistant mode** — Claude needs large-context analysis it can't efficiently do itself:
14
+ summarise many files, trace a pattern across the codebase, answer questions that require
15
+ holding the entire repo in memory at once.
16
+
17
+ 2. **Second-opinion mode** — Claude asks you to evaluate a design decision before proposing
18
+ it to the user.
19
+
20
+ **When giving a second opinion: be direct and specific. Flag concerns by name. Do not hedge
21
+ excessively. If something will break an invariant (see below), say so plainly.**
22
+
23
+ ---
24
+
25
+ ## Project overview
26
+
27
+ Quorum is a portable reasoning layer for agentic codebases. Three TypeScript modules:
28
+
29
+ | Module | What it does |
30
+ |---|---|
31
+ | **Oracle** | Query and write interface to Chronicle. No LLM required. |
32
+ | **Jury** | Evaluates a proposed design against Oracle evidence. Returns a confidence score + gaps. |
33
+ | **Council** | Adversarial validation via parallel advisors and reviewers. Returns a verdict. |
34
+
35
+ ```
36
+ oracle.query() → jury.evaluate() → council.deliberate() → human gate → Executor
37
+ ```
38
+
39
+ Source lives in `modules/`. Detailed API: `modules/README.md`.
40
+
41
+ ---
42
+
43
+ ## Chronicle
44
+
45
+ Chronicle lives at `.chronicle/` — the persistent institutional memory of the codebase.
46
+
47
+ All writes go through a human-gated path:
48
+ - `oracle.propose()` — stages a pending entry (AI agents may call this)
49
+ - `oracle.commit(proposalId)` — indexes it (human-triggered only, **never AI-triggered**)
50
+
51
+ ---
52
+
53
+ ## Invariants — never suggest breaking these
54
+
55
+ - `oracle.commit()` is **never** called without explicit human input.
56
+ - In `jury/evaluate.ts`, `council_brief` is always overridden from the numeric `confidence`
57
+ value after parsing. The LLM is never trusted to compute it.
58
+ - Both `jury/evaluate.ts` and `council/chairman.ts` throw on schema validation failure.
59
+ There are no fallbacks, defaults, or try/catch that swallows these errors.
60
+ - All dependencies (LLM provider, vector store, embedder) are injected — never hardcoded
61
+ inside module logic. Do not suggest adding imports.
62
+ - `deliberate()` calls `oracle.propose()` at the end of every run — never `oracle.commit()`.
63
+
64
+ ---
65
+
66
+ ## Key file locations
67
+
68
+ | Path | What it contains |
69
+ |---|---|
70
+ | `modules/AGENTS.md` | File ownership map for Oracle, Jury, Council |
71
+ | `modules/CLAUDE.md` | Design decisions and what not to change |
72
+ | `modules/README.md` | Full API reference |
73
+ | `.chronicle/` | LanceDB vector store, pending proposals, query log |
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 balpal4495
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,202 @@
1
+ # Quorum
2
+
3
+ Quorum is a portable reasoning layer for agentic codebases.
4
+
5
+ Drop the `quorum/` folder into any Node.js project, tell your AI to follow `quorum/SETUP.md`, and it wires itself in — installing dependencies, merging instruction files, and initialising a persistent knowledge store called Chronicle.
6
+
7
+ From that point, every AI agent working in the codebase queries Chronicle before proposing solutions, and every significant decision gets written back to it (with human approval). Over time it becomes the institutional memory of the project: what was tried, what worked, what failed, and why.
8
+
9
+ ---
10
+
11
+ ## What's inside
12
+
13
+ Four portable TypeScript modules:
14
+
15
+ | Module | What it does |
16
+ |---|---|
17
+ | **Oracle** | Query and write interface to Chronicle. No LLM required. |
18
+ | **Jury** | Evaluates a proposed design against Oracle evidence. Returns a confidence score. |
19
+ | **Council** | Adversarial validation via a parallel panel of advisors and reviewers. Returns a verdict. |
20
+ | **Sentinel** | Chronicle coverage and drift detection. Surfaces gaps and stale knowledge as Vitest assertions. |
21
+
22
+ ```
23
+ oracle.query() → jury.evaluate() → council.deliberate() → human gate → Executor
24
+ sentinel.coverage() + sentinel.detectDrift() → advisory test output
25
+ ```
26
+
27
+ ---
28
+
29
+ ## How it works
30
+
31
+ **Flow — system components and connections:**
32
+
33
+ ```mermaid
34
+ flowchart LR
35
+ Agent[AI Agent] -->|query| Oracle
36
+ Oracle -->|evidence| Jury
37
+ Jury -->|scores| Council
38
+ Council -->|verdict| Gate[Human Gate]
39
+ Oracle -. reads .-> Chronicle[(Chronicle)]
40
+ Gate -. approved commit .-> Chronicle
41
+ Chronicle -. coverage + drift .-> Sentinel
42
+ Sentinel -. advisory report .-> CI([CI / Developer])
43
+ ```
44
+
45
+ **Sequence — one full decision cycle:**
46
+
47
+ ```mermaid
48
+ sequenceDiagram
49
+ participant Agent as AI Agent
50
+ participant Oracle
51
+ participant Jury
52
+ participant Council
53
+ participant Human
54
+ participant Chronicle
55
+
56
+ Agent->>Oracle: query(text)
57
+ Oracle->>Chronicle: vector search
58
+ Chronicle-->>Oracle: ranked entries
59
+ Oracle-->>Agent: OracleResult[]
60
+
61
+ Agent->>Jury: evaluate(design, evidence)
62
+ Jury-->>Agent: score, flags, passed
63
+
64
+ Agent->>Council: deliberate(design, evaluations)
65
+ Council-->>Agent: satisfied, verdict, proposal
66
+
67
+ alt Council not satisfied
68
+ Note over Agent: revise design and retry
69
+ else Council satisfied
70
+ Agent->>Human: surface verdict and proposal
71
+ Human->>Oracle: commit(proposalId)
72
+ Oracle->>Chronicle: upsert entry
73
+ Oracle-->>Human: ChronicleEntry
74
+ end
75
+ ```
76
+
77
+ ---
78
+
79
+ ## How to use it
80
+
81
+ Run this from any Node.js project root:
82
+
83
+ ```bash
84
+ npx @balpal4495/quorum@latest init
85
+ ```
86
+
87
+ Quorum scaffolds itself — copying modules into `quorum/`, merging AI instruction files (CLAUDE.md, AGENTS.md), and initialising Chronicle. Then run `npm install`.
88
+
89
+ For manual control or AI-assisted setup, tell your AI: *"follow quorum/SETUP.md"*.
90
+
91
+ See [SETUP.md](SETUP.md) for the full bootstrap sequence.
92
+
93
+ ---
94
+
95
+ ## Chronicle
96
+
97
+ Chronicle lives at `.chronicle/` and is the persistent knowledge store that underpins everything. Every Oracle entry goes through a human-gated write path — `oracle.propose()` stages it, a human calls `oracle.commit()` to index it. There are no auto-commits.
98
+
99
+ ```
100
+ .chronicle/
101
+ committed/ ← approved entries as JSON (committed to git, source of truth)
102
+ proposals/ ← staged entries awaiting human approval (JSON, not indexed yet)
103
+ SUMMARY.md ← auto-generated agent context, rebuilt on every commit
104
+ ```
105
+
106
+ `SUMMARY.md` groups the last 12 weeks of entries by week and work context. It gives agents temporal sequence — what happened and in what order — which vector search alone cannot provide.
107
+
108
+ ---
109
+
110
+ ## Dependencies
111
+
112
+ | Package | Purpose |
113
+ |---|---|
114
+ | `zod` | Structured LLM output validation |
115
+ | `vectordb` | LanceDB embedded vector store (swappable) |
116
+ | `@xenova/transformers` | Local ONNX embedder — all-MiniLM-L6-v2 (swappable) |
117
+
118
+ The LLM provider is injectable — Quorum defines a simple function interface and never hardcodes a provider. Wire OpenAI, Anthropic, or anything else at the application level.
119
+
120
+ ---
121
+
122
+ ## Designed to be dropped in — not installed
123
+
124
+ Quorum is intentionally a folder, not an npm package. The source lives in your repo, the modules are readable by any AI agent working in the codebase, and the instruction files (`AGENTS.md`, `CLAUDE.md`) travel with the code. Nothing is hidden inside `node_modules`.
125
+
126
+ ---
127
+
128
+ ## Sentinel
129
+
130
+ Sentinel answers three questions Chronicle cannot answer about itself.
131
+
132
+ **Coverage** — which files have no Chronicle entries? These are the blind spots where agents have no prior knowledge to draw on.
133
+
134
+ **Drift** — do existing Chronicle entries still accurately describe the code? Insights become stale without anyone noticing.
135
+
136
+ **PR coverage map** — when a PR is opened, every module in the codebase is shown with its Chronicle coverage percentage, risk colour, and how many files the PR touches. Reviewers see exactly where the knowledge is solid and where it goes dark — as a table and a colour-coded heatmap, not a prose summary.
137
+
138
+ Sentinel is designed for both new and established projects. On a brand-new project with no Chronicle entries it surfaces a bootstrap prompt rather than a wall of red. As the project matures, coverage thresholds can be raised to enforce standards in CI.
139
+
140
+ ### In CI — coverage and drift as Vitest assertions
141
+
142
+ ```typescript
143
+ import { describe } from "vitest"
144
+ import { sentinelAssertions } from "./modules/sentinel/assert"
145
+
146
+ const assertions = sentinelAssertions({
147
+ chronicleDir: ".chronicle",
148
+ codebasePath: "src", // path to your source tree — defaults to "."
149
+ llm: myLLMProvider, // optional — drift tests skip gracefully when absent
150
+ minCoveragePercent: 50, // optional — 0 (default) = advisory only, never fails CI
151
+ })
152
+
153
+ describe("sentinel", () => { assertions.forEach(a => a()) })
154
+ ```
155
+
156
+ Coverage tests are deterministic — no LLM required, always run. By default (`minCoveragePercent: 0`) gaps are logged but CI never fails, which is right for a new project. Raise the threshold as Chronicle matures. Drift tests are always advisory — they skip when no LLM is configured and never hard-block the build.
157
+
158
+ Test files (`__tests__/`, `*.test.ts`, `*.spec.ts`) are excluded from tracking by default — only source files count toward coverage.
159
+
160
+ ### In PRs — the coverage map
161
+
162
+ The `sentinel-pr.yml` workflow runs on every PR and posts a comment with a full-project coverage table and a colour-coded Mermaid heatmap. Changed modules are bolded. The comment updates in place on each push — one comment per PR, never a thread of duplicates.
163
+
164
+ ```
165
+ ## Sentinel — Chronicle Coverage Map — 2026-W20
166
+
167
+ | Module | Coverage | Entries | Files | PR Changes | Risk |
168
+ |----------|----------|---------|-------|-------------|--------|
169
+ | council/ | 0% | 0 | 8 | — | high |
170
+ | jury/ | 0% | 0 | 4 | — | high |
171
+ | oracle/ | 22% | 4 | 9 | — | medium |
172
+ | scripts/ | 0% | 0 | 1 | **1 files** | high |
173
+ | sentinel/| 0% | 0 | 5 | **2 files** | high |
174
+ | shared/ | 100% | 2 | 1 | — | low |
175
+
176
+ [mermaid heatmap — Chronicle root → all modules, nodes coloured red/yellow/green by risk,
177
+ changed modules labelled with file count]
178
+
179
+ ### Chronicle context for changed modules
180
+ **oracle/**
181
+ - `[30bdc1c1]` schema constraints not LLM self-evaluation — validated (0.88)
182
+ ```
183
+
184
+ On a new project with no Chronicle entries, the comment instead shows a bootstrap prompt guiding the team toward their first `oracle.propose()` call.
185
+
186
+ ```mermaid
187
+ flowchart LR
188
+ Chronicle[(Chronicle)] -->|committed entries| Sentinel
189
+ Codebase[Codebase] -->|source files, excl. tests| Sentinel
190
+ LLM[LLM Provider] -. drift eval .-> Sentinel
191
+ Sentinel --> Vitest([Vitest assertions])
192
+ Sentinel --> PRComment([PR coverage map])
193
+ ```
194
+
195
+ ---
196
+
197
+ ## Module docs
198
+
199
+ - [modules/README.md](modules/README.md) — full API reference and quick-start
200
+ - [modules/AGENTS.md](modules/AGENTS.md) — file ownership and invariants
201
+ - [modules/CLAUDE.md](modules/CLAUDE.md) — design decisions and what not to change
202
+ - [SETUP.md](SETUP.md) — bootstrap sequence for new projects