substratum-cli 0.1.0__tar.gz

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 (105) hide show
  1. substratum_cli-0.1.0/PKG-INFO +69 -0
  2. substratum_cli-0.1.0/README.md +369 -0
  3. substratum_cli-0.1.0/pyproject.toml +39 -0
  4. substratum_cli-0.1.0/setup.cfg +4 -0
  5. substratum_cli-0.1.0/substratum_cli/README.md +51 -0
  6. substratum_cli-0.1.0/substratum_cli/__init__.py +6 -0
  7. substratum_cli-0.1.0/substratum_cli/__main__.py +7 -0
  8. substratum_cli-0.1.0/substratum_cli/_vendor/__init__.py +0 -0
  9. substratum_cli-0.1.0/substratum_cli/_vendor/_pro_test_derive.py +169 -0
  10. substratum_cli-0.1.0/substratum_cli/account.py +62 -0
  11. substratum_cli-0.1.0/substratum_cli/cli.py +185 -0
  12. substratum_cli-0.1.0/substratum_cli/codes.py +114 -0
  13. substratum_cli-0.1.0/substratum_cli/commands/__init__.py +0 -0
  14. substratum_cli-0.1.0/substratum_cli/commands/apply.py +49 -0
  15. substratum_cli-0.1.0/substratum_cli/commands/auth.py +37 -0
  16. substratum_cli-0.1.0/substratum_cli/commands/commit.py +40 -0
  17. substratum_cli-0.1.0/substratum_cli/commands/explain.py +63 -0
  18. substratum_cli-0.1.0/substratum_cli/commands/failing.py +80 -0
  19. substratum_cli-0.1.0/substratum_cli/commands/fix.py +48 -0
  20. substratum_cli-0.1.0/substratum_cli/commands/history.py +15 -0
  21. substratum_cli-0.1.0/substratum_cli/commands/init_cmd.py +155 -0
  22. substratum_cli-0.1.0/substratum_cli/commands/replay.py +68 -0
  23. substratum_cli-0.1.0/substratum_cli/commands/scaffold.py +71 -0
  24. substratum_cli-0.1.0/substratum_cli/commands/show.py +18 -0
  25. substratum_cli-0.1.0/substratum_cli/commands/undo.py +28 -0
  26. substratum_cli-0.1.0/substratum_cli/commands/verify.py +193 -0
  27. substratum_cli-0.1.0/substratum_cli/commands/write.py +42 -0
  28. substratum_cli-0.1.0/substratum_cli/config.py +49 -0
  29. substratum_cli-0.1.0/substratum_cli/diffs.py +106 -0
  30. substratum_cli-0.1.0/substratum_cli/engine.py +154 -0
  31. substratum_cli-0.1.0/substratum_cli/gitio.py +102 -0
  32. substratum_cli-0.1.0/substratum_cli/langscan.py +110 -0
  33. substratum_cli-0.1.0/substratum_cli/product_ops.py +639 -0
  34. substratum_cli-0.1.0/substratum_cli/refusals.py +127 -0
  35. substratum_cli-0.1.0/substratum_cli/remote.py +140 -0
  36. substratum_cli-0.1.0/substratum_cli/render.py +332 -0
  37. substratum_cli-0.1.0/substratum_cli/result.py +185 -0
  38. substratum_cli-0.1.0/substratum_cli/run_store.py +162 -0
  39. substratum_cli-0.1.0/substratum_cli/runid.py +69 -0
  40. substratum_cli-0.1.0/substratum_cli/session.py +558 -0
  41. substratum_cli-0.1.0/substratum_cli/style.py +128 -0
  42. substratum_cli-0.1.0/substratum_cli.egg-info/PKG-INFO +69 -0
  43. substratum_cli-0.1.0/substratum_cli.egg-info/SOURCES.txt +103 -0
  44. substratum_cli-0.1.0/substratum_cli.egg-info/dependency_links.txt +1 -0
  45. substratum_cli-0.1.0/substratum_cli.egg-info/entry_points.txt +2 -0
  46. substratum_cli-0.1.0/substratum_cli.egg-info/requires.txt +3 -0
  47. substratum_cli-0.1.0/substratum_cli.egg-info/top_level.txt +1 -0
  48. substratum_cli-0.1.0/tests/test_adaptive_prior.py +109 -0
  49. substratum_cli-0.1.0/tests/test_alias_warrant_trace.py +330 -0
  50. substratum_cli-0.1.0/tests/test_bidirectional_gate_contracts.py +153 -0
  51. substratum_cli-0.1.0/tests/test_coherence_evolution.py +108 -0
  52. substratum_cli-0.1.0/tests/test_coherences.py +155 -0
  53. substratum_cli-0.1.0/tests/test_connection_web_api.py +51 -0
  54. substratum_cli-0.1.0/tests/test_cross_entity_scoping.py +160 -0
  55. substratum_cli-0.1.0/tests/test_data.py +223 -0
  56. substratum_cli-0.1.0/tests/test_de28_negation_refuse.py +99 -0
  57. substratum_cli-0.1.0/tests/test_definite_description_handler.py +166 -0
  58. substratum_cli-0.1.0/tests/test_demo_regression_catalog.py +417 -0
  59. substratum_cli-0.1.0/tests/test_demo_response_shape.py +179 -0
  60. substratum_cli-0.1.0/tests/test_e1_e2_field_alignment.py +222 -0
  61. substratum_cli-0.1.0/tests/test_extraction_class_write_time.py +255 -0
  62. substratum_cli-0.1.0/tests/test_falsification_predictions.py +271 -0
  63. substratum_cli-0.1.0/tests/test_gap_d_wh_normalization.py +347 -0
  64. substratum_cli-0.1.0/tests/test_inference.py +272 -0
  65. substratum_cli-0.1.0/tests/test_inflection_cvc_rule.py +42 -0
  66. substratum_cli-0.1.0/tests/test_inflection_irregular.py +44 -0
  67. substratum_cli-0.1.0/tests/test_intervention.py +103 -0
  68. substratum_cli-0.1.0/tests/test_invariant.py +110 -0
  69. substratum_cli-0.1.0/tests/test_legal_citation_handler.py +347 -0
  70. substratum_cli-0.1.0/tests/test_lens_noop_seam.py +66 -0
  71. substratum_cli-0.1.0/tests/test_markup_tag_handler.py +163 -0
  72. substratum_cli-0.1.0/tests/test_nl_parser.py +210 -0
  73. substratum_cli-0.1.0/tests/test_nl_parser_adversarial.py +466 -0
  74. substratum_cli-0.1.0/tests/test_noise.py +93 -0
  75. substratum_cli-0.1.0/tests/test_pass2_contextual.py +89 -0
  76. substratum_cli-0.1.0/tests/test_perspectives.py +93 -0
  77. substratum_cli-0.1.0/tests/test_polysemous_token_alias_guard.py +106 -0
  78. substratum_cli-0.1.0/tests/test_possessive_normalization.py +81 -0
  79. substratum_cli-0.1.0/tests/test_predicate_canon.py +151 -0
  80. substratum_cli-0.1.0/tests/test_projection_gate.py +409 -0
  81. substratum_cli-0.1.0/tests/test_projection_gate_tag_question.py +118 -0
  82. substratum_cli-0.1.0/tests/test_query_normalizer.py +135 -0
  83. substratum_cli-0.1.0/tests/test_records_answer_format.py +62 -0
  84. substratum_cli-0.1.0/tests/test_referent_aboutness_gate.py +188 -0
  85. substratum_cli-0.1.0/tests/test_referent_quality_gate.py +307 -0
  86. substratum_cli-0.1.0/tests/test_refuse_message_topic_neutrality.py +144 -0
  87. substratum_cli-0.1.0/tests/test_relation_detection.py +57 -0
  88. substratum_cli-0.1.0/tests/test_relaxation.py +114 -0
  89. substratum_cli-0.1.0/tests/test_residual_content_gate.py +243 -0
  90. substratum_cli-0.1.0/tests/test_reverse_lookup_subject_filter.py +73 -0
  91. substratum_cli-0.1.0/tests/test_sec_statement_aliases.py +157 -0
  92. substratum_cli-0.1.0/tests/test_span_lens.py +200 -0
  93. substratum_cli-0.1.0/tests/test_span_lens_query_integration.py +75 -0
  94. substratum_cli-0.1.0/tests/test_substrate.py +246 -0
  95. substratum_cli-0.1.0/tests/test_synonymy_detector.py +485 -0
  96. substratum_cli-0.1.0/tests/test_table_ingest.py +276 -0
  97. substratum_cli-0.1.0/tests/test_triple_ingest.py +379 -0
  98. substratum_cli-0.1.0/tests/test_two_phase_schema.py +44 -0
  99. substratum_cli-0.1.0/tests/test_user_asserted_aliases.py +174 -0
  100. substratum_cli-0.1.0/tests/test_v2_api.py +153 -0
  101. substratum_cli-0.1.0/tests/test_v2_api_claims.py +235 -0
  102. substratum_cli-0.1.0/tests/test_v2_claim_determinism.py +109 -0
  103. substratum_cli-0.1.0/tests/test_word_role.py +141 -0
  104. substratum_cli-0.1.0/tests/test_word_role_wiring.py +72 -0
  105. substratum_cli-0.1.0/tests/test_xbrl_doc_aliases.py +87 -0
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: substratum-cli
3
+ Version: 0.1.0
4
+ Summary: Substratum: verified-or-refused code, with provenance. The terminal over the comprehension engine.
5
+ Author: Substratum
6
+ License: LicenseRef-Proprietary
7
+ Project-URL: Homepage, https://substratum-api.fly.dev
8
+ Keywords: code-generation,verification,deterministic,provenance,developer-tools
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Software Development :: Code Generators
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ Provides-Extra: engine
17
+ Requires-Dist: numpy>=1.24; extra == "engine"
18
+
19
+ # Substratum
20
+
21
+ **Verified-or-refused code, with provenance.** Substratum is a deterministic comprehension engine
22
+ for code. It never streams tokens and hopes — it produces a change only when that change passes a
23
+ gate, and otherwise returns an honest, actionable refusal. Every result carries a run id you can
24
+ replay byte-for-byte.
25
+
26
+ ```
27
+ pip install substratum-cli
28
+ ```
29
+
30
+ Then, in any repository:
31
+
32
+ ```
33
+ substratum # open the interactive session (warms, then drives)
34
+ ```
35
+
36
+ ## What it does
37
+
38
+ - **`summarize`** — describe the codebase in plain English, grounded in its real symbols (not a guess).
39
+ - **`failing`** — run the suite and list the failing tests; each becomes a ready fix target.
40
+ - **`verify`** — gate a diff (stdin, `--staged`, `--commit`): PASS / FAIL / per-hunk. The wedge — point
41
+ it at any tool's diff and it tells you, deterministically, whether the change is real.
42
+ - **`fix`** — produce a verified fix for a failing test, or a named refusal.
43
+ - **`write`** — greenfield code from plain intent (derive-or-refuse; no test required).
44
+ - **`runs` / `show` / `replay` / `undo` / `apply` / `commit`** — a proof-carrying memory of every run.
45
+
46
+ `summarize`, `failing`, and `verify` run **entirely on your machine** — no account, no network, no code
47
+ leaves your repo. They work air-gapped.
48
+
49
+ ## The hosted engine (optional)
50
+
51
+ `fix` and `write` draw on a large mined library. During the demo that library is hosted:
52
+
53
+ ```
54
+ substratum login # GitHub device flow; connects to the hosted engine
55
+ ```
56
+
57
+ When logged in, `write` sends only your intent + signature, and `fix` receives a *candidate* that your
58
+ machine then gates locally — so your code and your tests never leave your machine. `substratum logout`
59
+ returns to fully-local operation.
60
+
61
+ ## The law
62
+
63
+ Never render unproven code. A refusal is a deliverable, not an error. Determinism is a button you
64
+ press to catch us: run the same request twice and get the same run id, or `replay` any run and get a
65
+ byte-identical result.
66
+
67
+ Coverage grows with data. Today the engine refuses more than it resolves, by design — the surface is
68
+ built to feel complete at thin coverage, and the same commands silently resolve more as the library
69
+ scales, with zero change on your end.
@@ -0,0 +1,369 @@
1
+ # Substratum
2
+
3
+ **Private repository. Confidential under NDA.**
4
+
5
+ Substratum is the production codebase for the Cognitive Substrate Framework (CSF):
6
+ a Born-rule inference engine on a projector-based knowledge substrate, augmented
7
+ with a claim-layered record architecture, a projection+filter query interface,
8
+ and a four-code refuse taxonomy. Zero language models in the input path from
9
+ user query to substrate answer. Structural non-hallucination preserved end to end.
10
+
11
+ The canonical architectural reference is the white paper
12
+ `Substratum v2.2.tex` (shared separately under NDA). This README documents the
13
+ codebase: what is here, how it runs, what verifies it.
14
+
15
+ ## Architecture
16
+
17
+ Two substrates under one algebraic schema:
18
+
19
+ 1. **CSF substrate** (`backend/core/`). Sparse density-operator rho on a
20
+ factored Hilbert space. Born-rule measurement, Lindblad coherence evolution,
21
+ Davies gradient-flow generative dynamics, A13 observation-vs-intervention
22
+ counts, A14 noise correction, A15 compositional inference.
23
+
24
+ 2. **Claim-layered substrate** (`backend/substratum_v2/`). ClaimRecord schema
25
+ with UTTERANCE / WORLD / COLLAPSED layers, warrant taxonomy
26
+ (AUTHORITATIVE_DOCUMENT / COLLAPSED_SELF_STATE / CONVERGENT_SOURCES /
27
+ SINGLE_SOURCE), source-identity non-aliasing, layer collapse rule.
28
+ Structured extractor, projection+filter query parser, four-code refuse
29
+ taxonomy, four response patterns.
30
+
31
+ ### One door, one answer
32
+
33
+ Every capability flows through `POST /api/answer` and produces a
34
+ `SubstratumAnswer` envelope (closed-class status enum, closed-class mode
35
+ enum, source pills, claim cards, warrant, layer, trace). The router at
36
+ `backend/substratum_v2/answer/router.py` fans out to nine dispatchers in
37
+ parallel (claim, advice, philosophical chat, composition contradiction,
38
+ legal case treatment, code generation, code review, code completion, code
39
+ refactoring) and merges by status precedence + cascade order. Each
40
+ dispatcher self-gates and returns None when its intent does not latch.
41
+ The frontend renders one panel per answer; no branching by mode.
42
+
43
+ ### Shipped capability surfaces
44
+
45
+ - **Claim and advice** dispatchers serve factual lookup, multi-hop
46
+ composition, and multi-source advice synthesis with calibrated confidence
47
+ and clarification.
48
+ - **Philosophical chat** dispatcher handles philosophical inquiry with
49
+ attribution-first rendering and engagement signals.
50
+ - **Composition** (`backend/substratum_v2/composition/` +
51
+ `composition_wiring/`): generalized passage composer, contradiction
52
+ detection across substrates, claim-diff detection, counterfactual
53
+ application. Refuses on no-topic, ambiguous-topic, no-records, and
54
+ no-contradiction with structural reasons.
55
+ - **Legal vertical** (`backend/substratum_v2/legal/`): first
56
+ regulated-vertical registration. Native slip-opinion ingestion derives
57
+ every per-case property from raw text (deciding court, citation, year,
58
+ source id) by closed-class Bluebook + caption parsers. Case-treatment
59
+ dispatcher answers "did X overrule / distinguish / follow / extend /
60
+ limit / affirm / reverse / vacate / remand Y" with VERIFIED, REFUTED,
61
+ NO_RECORD, ACTOR_UNKNOWN, OBJECT_UNKNOWN, and AMBIGUOUS outcomes. 37
62
+ SCOTUS cases ingested (Fourth Amendment + criminal procedure).
63
+ - **Code intelligence triad**, all deterministic and refuse-when-uncertain:
64
+ - **Autocomplete** (`backend/substratum_v2/autocomplete/`): substrate-
65
+ driven completion engine + LSP server, shipped as the
66
+ `vscode-substratum-autocomplete` extension.
67
+ - **Refactoring** (`backend/substratum_v2/refactoring/`): local rename,
68
+ module-level rename, cross-module workspace-aware rename, wired into
69
+ LSP `textDocument/rename` + `prepareRename`.
70
+ - **Code review** (`backend/substratum_v2/code_review/`): static bug
71
+ detector with provably-real findings only, diff analyzer for breaking-
72
+ change risk, `substratum-check` CLI for pre-commit and PR hooks,
73
+ GitHub Action for PR auto-comment, zero-FP gate report.
74
+
75
+ ## Layout
76
+
77
+ ```
78
+ backend/
79
+ core/ CSF substrate: rho, Born rule, dynamics
80
+ data.py TripleStore with A13 observation/intervention counts
81
+ substrate.py Substrate manager with evolve_coherence + relax_toward
82
+ sparse_rho.py Sparse dictionary rho (OP-embedB cascade locality)
83
+ inference.py InferenceEngine: query, verify, compose, observe
84
+ coherences.py Off-diagonal coherence store
85
+ perspectives.py R3 perspective discovery
86
+ noise.py A14 confusion-matrix inversion
87
+ substratum_v2/ Claim-layered substrate
88
+ claims.py ClaimRecord / NoClaimRecord schemas + enums
89
+ ingestion.py IngestionContext, CORPUS_POLICY, source identity
90
+ linguistic_features.py Token-level closed-class feature registry
91
+ claim_extractor.py Deterministic sentence -> ClaimRecord extractor
92
+ claim_substrate.py Factored-Hilbert family per (IngestionType, Layer, Force)
93
+ query_parser_v2.py Projection + filter parser, four refuse codes
94
+ substrate_filter.py Match records against FilterSpec (linear + indexed)
95
+ projection.py Apply projection spec to matches
96
+ inflection_index.py Substrate-derived verb morphology
97
+ entity_canon.py Entity canonicalization
98
+ queries.py Query primitives: what_did_X_say, is_Y_true,
99
+ self_state, causal_chains, attribution_projection,
100
+ interpretations_of, prob_marginal/conditional/distribution
101
+ query_router.py Claim-pipeline shape detection
102
+ triple_ingest.py Structured-triple ingestion (separate from prose)
103
+ triple_ontologies/ Per-ontology PredicateSpec registries (Wikidata, etc.)
104
+ build_claim_store.py Build claim_store.pkl from corpus
105
+ answer/ Unified /api/answer router + SubstratumAnswer envelope
106
+ router.py Nine-dispatcher fan-out, status precedence merge
107
+ types.py AnswerStatus, ResponseMode, SourcePill, ClaimCard
108
+ adapters.py Pipeline-dict -> SubstratumAnswer normalizers
109
+ prose.py Surface prose rendering
110
+ advice/ Multi-source advice dispatcher
111
+ advice_dispatcher.py Orchestrates parse -> evidence -> synthesis
112
+ conclusion_synthesizer.py Final advice synthesis
113
+ calibration_engine.py Confidence calibration
114
+ frame_state.py Per-session multi-turn state
115
+ production_substrate_adapter.py Indexed candidate narrowing + slow-path filter
116
+ philosophical_chat/ Philosophical inquiry dispatcher with attribution
117
+ composition/ Generalized passage composer + contradiction detector
118
+ + claim diff + counterfactual + citation styles
119
+ composition_wiring/ CONTRADICTION dispatcher into /api/answer
120
+ legal/ Legal-vertical substrate. Native slip-opinion
121
+ ingestion (Bluebook + caption parsers), 15-predicate
122
+ closed-class catalog, case-treatment dispatcher
123
+ alias_store/ DECLARED + DERIVED alias records; one-hop warranted
124
+ expansion at filter time (XBRL, SEC, user-asserted)
125
+ code_generation/ Code-gen v1 (legacy goal composition + pattern lookup)
126
+ code_generation_v2/ Code-gen v2 (delta handlers + bug-fix synthesis;
127
+ v1 falls back to v2 first via handle_v2_g9_bug_fix)
128
+ code_review/ Static bug detector + diff analyzer + CLI + Action
129
+ autocomplete/ Substrate-driven completion engine + LSP server
130
+ refactoring/ Local + module + cross-module rename, LSP-wired
131
+ profile/ Per-session conversation frame + drift detection
132
+ indexes/ Inverted index (referent-keyed candidate narrowing,
133
+ equivalence-tested vs full scan), citation graph,
134
+ source relationships, temporal clustering
135
+ parser/ Closed-class grammar + handlers
136
+ table_ingest/ Table -> ClaimRecord synthesis (RDF, CSV, financial)
137
+ rendering/ Mode-specific renderers under one rendering context
138
+ reasoning/ Reasoning chain capture, rule store, composition engine
139
+ SCHEMA.md Claim schema spec with refuse-code documentation
140
+ AUDIT.md Hand-labeled extraction ground truth (30 sentences)
141
+ _run_audit{1..10}.py Independent audit gates (claim extraction,
142
+ queries, axioms, probability, adversarial,
143
+ response patterns, parser structural, reverse-
144
+ lookup, adversarial parser, table ingest)
145
+ text_ingest/ Non-LLM text-to-observation pattern extractor
146
+ patterns.py Pattern store with substrate alignment
147
+ r3_patterns.py R3 applied to patterns
148
+ structural.py Closed-class function-word analysis
149
+ app.py FastAPI: dispatcher + all endpoints
150
+ nl_parser.py Legacy CSF parser (coupling-based)
151
+ llm_compare.py Anthropic streaming for side-by-side demo
152
+ ingest/ Wikidata ingestion scripts
153
+
154
+ frontend/ React + TypeScript + Vite + Tailwind
155
+ src/components/ SubstratumPanel, GraphCanvas, QueryBar, ...
156
+ src/components/claim/ ClaimCard, SourcePill, LayerBadge,
157
+ ProvenanceChain, ReverseMatchesPanel, GapPanel
158
+ src/types/api.ts Contract with backend SubstratumAnswer shape
159
+
160
+ extensions/
161
+ vscode-substratum-autocomplete/ VS Code LSP client for autocomplete + rename
162
+
163
+ tests/ pytest suite, all green
164
+ test_falsification_predictions.py Reciprocity, interference, Guppy
165
+ test_inference.py Born-rule query/verify/compose
166
+ test_invariant.py Structural non-hallucination
167
+ test_coherence_evolution.py Lindblad semigroup/Markov/CPTP
168
+ test_relaxation.py Davies generative relaxation
169
+ test_noise.py A14 noise correction
170
+ test_adaptive_prior.py A12 adaptive similarity prior
171
+ test_intervention.py A13 observation vs intervention
172
+ test_demo_response_shape.py Frontend contract for shipped demo queries
173
+ test_demo_regression_catalog.py Permanent regression catalog
174
+ answer/ /api/answer router + adapter + index equivalence
175
+ advice/ Advice dispatcher and synthesis
176
+ philosophical_chat/ Philosophical pipeline + dialogue frame
177
+ composition/ Composer + contradiction + counterfactual + diff
178
+ composition_wiring/ CONTRADICTION routing into /api/answer
179
+ legal/ Legal parser + slip-opinion captions + dispatcher
180
+ code_generation/ Code-gen v1 pipeline
181
+ code_generation_v2/ Code-gen v2 delta handlers + synthesis
182
+ code_review/ Static detector + diff analyzer
183
+ autocomplete/ Completion engine + LSP
184
+ refactoring/ Rename engine + LSP wiring
185
+ rendering/ Mode-specific renderers
186
+ reasoning/ Reasoning chain capture, rule eval, composition
187
+ indexes/ Inverted index + cross-backend equivalence
188
+ integration/ End-to-end pipelines
189
+ profile/ Drift detection + active constraints
190
+ text_ingest/ Pattern extraction
191
+ conversation/ Multi-turn session state
192
+ fixtures/ Test data including quality_corpus.jsonl
193
+
194
+ scripts/ Build, benchmark, and quality pipelines
195
+ quality/ 1,403-query end-to-end sweep against /api/answer
196
+ benchmark/ Performance harnesses
197
+ swe_bench/ SWE-Bench Lite integration
198
+ real_engineer_bench/ Real-engineer head-to-head benchmark
199
+ code_review/ Code review benchmark + zero-FP validation
200
+ refactoring/ Refactoring benchmark + binding-safety harness
201
+ autocomplete/ Completion benchmark, held-out stdlib
202
+ code_corpus/ Code corpus curation (multi-language OSS reference)
203
+ philosophical_chat_corpus/ Philosophical dialogue corpus
204
+ derived/ Derived artifact generation
205
+
206
+ fly.toml Fly.io deploy config (substratum-api)
207
+ vercel.json Vercel frontend deploy config
208
+ Dockerfile Backend container
209
+ requirements.txt Python dependencies
210
+ ```
211
+
212
+ ## Quick start
213
+
214
+ ### Backend (local)
215
+
216
+ ```bash
217
+ pip install -r requirements.txt
218
+ python -m backend # starts FastAPI on http://localhost:8000
219
+ ```
220
+
221
+ Environment variables (see `.env.example`):
222
+
223
+ - `ANTHROPIC_API_KEY` - for `/api/llm-stream` Claude streaming (comparison
224
+ panel only; never in the substrate query path)
225
+ - `SUBSTRATUM_ALLOWED_ORIGINS` - comma-separated CORS allowlist (defaults
226
+ to localhost + `*.vercel.app`)
227
+ - `SUBSTRATUM_DEMO_TAG` - public demo-tag header for rate-limited endpoints
228
+ - `SUBSTRATUM_RATE_PER_MINUTE` - per-IP rate limit (default 60)
229
+
230
+ ### Frontend (local)
231
+
232
+ ```bash
233
+ cd frontend
234
+ npm install
235
+ npm run dev # vite dev server on http://localhost:5173
236
+ ```
237
+
238
+ Environment (build time):
239
+
240
+ - `VITE_API_BASE_URL` - backend origin (unset in dev, set in prod)
241
+ - `VITE_DEMO_TAG` - public demo-tag sent as X-Demo-Tag header
242
+
243
+ ### VS Code extension
244
+
245
+ ```bash
246
+ cd extensions/vscode-substratum-autocomplete
247
+ npm install
248
+ # Press F5 in VS Code to launch the extension host
249
+ ```
250
+
251
+ The extension spawns the LSP server at
252
+ `backend/substratum_v2/autocomplete/lsp_server.py`. Configurable via
253
+ `substratum.*` settings in VS Code.
254
+
255
+ ### Build the claim store (optional, for claim-pipeline queries)
256
+
257
+ ```bash
258
+ python -m backend.substratum_v2.build_claim_store
259
+ ```
260
+
261
+ Reads `backend/substratum_v2/data/corpus_cache_30k.pkl`, runs the claim
262
+ extractor, builds the entity canon and source index, pickles
263
+ `claim_store.pkl`. Not tracked in git; regenerated locally.
264
+
265
+ ## Testing and audits
266
+
267
+ ### pytest suite
268
+
269
+ ```bash
270
+ python3 -m pytest tests/ --no-header
271
+ # Full green; slow tests (-m slow) cover production-substrate equivalence
272
+ ```
273
+
274
+ ### Independent audit gates
275
+
276
+ Each audit is self-contained, prints a pass/fail line per case, and exits
277
+ non-zero on any failure.
278
+
279
+ ```bash
280
+ python3 -m backend.substratum_v2._run_audit1 # 30 claim-extraction cases
281
+ python3 -m backend.substratum_v2._run_audit2 # 20 query-primitive cases
282
+ python3 -m backend.substratum_v2._run_audit3 # 60 substrate-axiom checks
283
+ python3 -m backend.substratum_v2._run_audit4 # 10 probability queries
284
+ python3 -m backend.substratum_v2._run_audit5 # 14 adversarial surface-form
285
+ python3 -m backend.substratum_v2._run_audit6 # 4 response patterns
286
+ python3 -m backend.substratum_v2._run_audit7 # 137 parser structural cases
287
+ python3 -m backend.substratum_v2._run_audit8 # 11 reverse-lookup cases
288
+ python3 -m backend.substratum_v2._run_audit9 # 55 adversarial parser cases
289
+ python3 -m backend.substratum_v2._run_audit10 # 15 table-ingest ground truth
290
+ ```
291
+
292
+ ### Quality sweep
293
+
294
+ ```bash
295
+ python3 -m scripts.quality.run_quality_sweep \
296
+ --base-url http://127.0.0.1:8000 \
297
+ --workers 12 \
298
+ --report scripts/quality/last_sweep.json
299
+ ```
300
+
301
+ End-to-end sweep against `/api/answer`. Validates every response is
302
+ graceful, structurally well-formed (SubstratumAnswer shape, closed-class
303
+ status + mode), free of audit-metadata leakage, and under the 25s router
304
+ budget. Corpus combines synthesized adversarial cases with real-world
305
+ queries from a multi-source corpus.
306
+
307
+ ## Deployment
308
+
309
+ ### Backend (Fly.io)
310
+
311
+ ```bash
312
+ flyctl deploy # from repo root
313
+ # fly.toml: substratum-api in iad, 8000, shared-cpu-2x, 3 GB
314
+ ```
315
+
316
+ Health check: `GET /api/stats` every 30s. The Docker image bakes in the
317
+ pre-built completion index pickle so the autocomplete pipeline is ready
318
+ on first request.
319
+
320
+ ### Frontend (Vercel)
321
+
322
+ Connected to GitHub main. A deploy hook URL is held separately and fired
323
+ after each push to bypass the Hobby-plan commit-author gate. The Vercel
324
+ build proxies `/api/*` to the Fly backend; one POST to `/api/answer`
325
+ serves every capability.
326
+
327
+ ## Key references
328
+
329
+ - `backend/substratum_v2/SCHEMA.md` - claim schema, layer rules, warrant
330
+ taxonomy, refuse-code documentation
331
+ - `backend/substratum_v2/AUDIT.md` - extraction audit design
332
+ - `Substratum v2.2.tex` - white paper (shared separately under NDA)
333
+
334
+ ## Status summary
335
+
336
+ - pytest suite green (claim, advice, philosophical, composition,
337
+ composition_wiring, legal, code generation v1+v2, code review,
338
+ autocomplete, refactoring, rendering, reasoning, indexes, profile,
339
+ text ingest, conversation, integration)
340
+ - 10 independent audit gates green (claim extraction, queries, axioms,
341
+ probability, adversarial surface-form, response patterns, parser
342
+ structural, reverse-lookup, adversarial parser, table ingest)
343
+ - 10/10 falsification predictions with live tests
344
+ - Code intelligence triad shipped: autocomplete + refactoring + code review,
345
+ all wired through `/api/answer` and the VS Code extension
346
+ - Composition shipped: contradiction detection + claim-diff + counterfactual
347
+ composer, multi-substrate union (philosophical + legal), CONTRADICTION
348
+ intent routed through `/api/answer`
349
+ - Legal vertical shipped (Ship LG.1): 37 SCOTUS cases ingested natively
350
+ from raw slip-opinion text, case-treatment dispatcher with VERIFIED /
351
+ REFUTED / NO_RECORD / ACTOR_UNKNOWN / OBJECT_UNKNOWN / AMBIGUOUS
352
+ outcomes, opposition pairs registered for circuit-split detection
353
+ - Unified `/api/answer` router with `SubstratumAnswer` envelope; one panel
354
+ at the surface
355
+ - Inverted-index candidate narrowing for the production substrate adapter
356
+ (1700x speedup, equivalence-proven against full scan)
357
+ - 1,403-query end-to-end quality sweep against `/api/answer`
358
+ - Zero language models in the query pipeline
359
+ - Zero hardcoded content in the parser source
360
+ - Deterministic: same input produces byte-equal response
361
+ - Ingestion derives every per-document property from raw text; no filename
362
+ mappings, no metadata sidecars, no human curation
363
+ - Deployed on Fly.io (backend) + Vercel (frontend)
364
+
365
+ ## Confidentiality
366
+
367
+ This repository is private. Access implies NDA. Do not share the source,
368
+ the white paper, or any architectural specifics without explicit written
369
+ authorization from the author.
@@ -0,0 +1,39 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "substratum-cli"
7
+ version = "0.1.0"
8
+ description = "Substratum: verified-or-refused code, with provenance. The terminal over the comprehension engine."
9
+ readme = "substratum_cli/README.md"
10
+ license = { text = "LicenseRef-Proprietary" }
11
+ authors = [{ name = "Substratum" }]
12
+ keywords = ["code-generation", "verification", "deterministic", "provenance", "developer-tools"]
13
+ requires-python = ">=3.11"
14
+ classifiers = [
15
+ "Development Status :: 4 - Beta",
16
+ "Environment :: Console",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Topic :: Software Development :: Code Generators",
20
+ ]
21
+
22
+ # CORE is stdlib-only: the CLI and `verify` carry ZERO runtime dependencies (the air-gapped,
23
+ # zero-egress story). The engine extras are the numpy subset the fix path imports.
24
+ dependencies = []
25
+
26
+ [project.optional-dependencies]
27
+ engine = ["numpy>=1.24"]
28
+
29
+ [project.scripts]
30
+ substratum = "substratum_cli.cli:main"
31
+
32
+ [project.urls]
33
+ Homepage = "https://substratum-api.fly.dev"
34
+
35
+ [tool.setuptools]
36
+ packages = ["substratum_cli", "substratum_cli.commands", "substratum_cli._vendor"]
37
+
38
+ [tool.pytest.ini_options]
39
+ markers = ["slow: loads the full production library (minutes); excluded from the fast gate"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,51 @@
1
+ # Substratum
2
+
3
+ **Verified-or-refused code, with provenance.** Substratum is a deterministic comprehension engine
4
+ for code. It never streams tokens and hopes — it produces a change only when that change passes a
5
+ gate, and otherwise returns an honest, actionable refusal. Every result carries a run id you can
6
+ replay byte-for-byte.
7
+
8
+ ```
9
+ pip install substratum-cli
10
+ ```
11
+
12
+ Then, in any repository:
13
+
14
+ ```
15
+ substratum # open the interactive session (warms, then drives)
16
+ ```
17
+
18
+ ## What it does
19
+
20
+ - **`summarize`** — describe the codebase in plain English, grounded in its real symbols (not a guess).
21
+ - **`failing`** — run the suite and list the failing tests; each becomes a ready fix target.
22
+ - **`verify`** — gate a diff (stdin, `--staged`, `--commit`): PASS / FAIL / per-hunk. The wedge — point
23
+ it at any tool's diff and it tells you, deterministically, whether the change is real.
24
+ - **`fix`** — produce a verified fix for a failing test, or a named refusal.
25
+ - **`write`** — greenfield code from plain intent (derive-or-refuse; no test required).
26
+ - **`runs` / `show` / `replay` / `undo` / `apply` / `commit`** — a proof-carrying memory of every run.
27
+
28
+ `summarize`, `failing`, and `verify` run **entirely on your machine** — no account, no network, no code
29
+ leaves your repo. They work air-gapped.
30
+
31
+ ## The hosted engine (optional)
32
+
33
+ `fix` and `write` draw on a large mined library. During the demo that library is hosted:
34
+
35
+ ```
36
+ substratum login # GitHub device flow; connects to the hosted engine
37
+ ```
38
+
39
+ When logged in, `write` sends only your intent + signature, and `fix` receives a *candidate* that your
40
+ machine then gates locally — so your code and your tests never leave your machine. `substratum logout`
41
+ returns to fully-local operation.
42
+
43
+ ## The law
44
+
45
+ Never render unproven code. A refusal is a deliverable, not an error. Determinism is a button you
46
+ press to catch us: run the same request twice and get the same run id, or `replay` any run and get a
47
+ byte-identical result.
48
+
49
+ Coverage grows with data. Today the engine refuses more than it resolves, by design — the surface is
50
+ built to feel complete at thin coverage, and the same commands silently resolve more as the library
51
+ scales, with zero change on your end.
@@ -0,0 +1,6 @@
1
+ """substratum_cli -- the product surface (CLI + shared object model) over the Substratum engine.
2
+
3
+ Import budget: this package is stdlib-only; the ONLY module reaching into backend.* is
4
+ `engine.py`, lazily. Importing substratum_cli (or any light command) opens nothing heavy.
5
+ """
6
+ __version__ = "0.1.0"
@@ -0,0 +1,7 @@
1
+ """python -m substratum_cli -> the CLI."""
2
+ import sys
3
+
4
+ from .cli import main
5
+
6
+ if __name__ == "__main__":
7
+ sys.exit(main(sys.argv[1:]))