typeglish 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 (51) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +13 -0
  3. package/README.md +301 -0
  4. package/dist/chunk-3NQ3VYO6.js +566 -0
  5. package/dist/chunk-3NQ3VYO6.js.map +1 -0
  6. package/dist/chunk-KRYC4OTL.js +3573 -0
  7. package/dist/chunk-KRYC4OTL.js.map +1 -0
  8. package/dist/chunk-NLQIL5WD.js +25 -0
  9. package/dist/chunk-NLQIL5WD.js.map +1 -0
  10. package/dist/chunk-PR4QN5HX.js +39 -0
  11. package/dist/chunk-PR4QN5HX.js.map +1 -0
  12. package/dist/chunk-PXAMTGYY.js +3 -0
  13. package/dist/chunk-PXAMTGYY.js.map +1 -0
  14. package/dist/chunk-VMACILYN.js +140 -0
  15. package/dist/chunk-VMACILYN.js.map +1 -0
  16. package/dist/chunk-Y64EAEYB.js +10919 -0
  17. package/dist/chunk-Y64EAEYB.js.map +1 -0
  18. package/dist/chunk-YH4ZLQ4G.js +4260 -0
  19. package/dist/chunk-YH4ZLQ4G.js.map +1 -0
  20. package/dist/chunk-ZKMHZHID.js +56 -0
  21. package/dist/chunk-ZKMHZHID.js.map +1 -0
  22. package/dist/cli.d.ts +1 -0
  23. package/dist/cli.js +447 -0
  24. package/dist/cli.js.map +1 -0
  25. package/dist/compile-DViQS2oG.d.ts +310 -0
  26. package/dist/diagnostics-BWJ_oMd8.d.ts +49 -0
  27. package/dist/exhaustiveness-VBVWCX5W.js +123 -0
  28. package/dist/exhaustiveness-VBVWCX5W.js.map +1 -0
  29. package/dist/index-Df_QnTgq.d.ts +313 -0
  30. package/dist/index.d.ts +3 -0
  31. package/dist/index.js +7 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/mcp.d.ts +11 -0
  34. package/dist/mcp.js +36378 -0
  35. package/dist/mcp.js.map +1 -0
  36. package/dist/monaco.css +46 -0
  37. package/dist/monaco.d.ts +43 -0
  38. package/dist/monaco.js +971 -0
  39. package/dist/monaco.js.map +1 -0
  40. package/dist/node.d.ts +21 -0
  41. package/dist/node.js +8 -0
  42. package/dist/node.js.map +1 -0
  43. package/dist/spell-node.d.ts +8 -0
  44. package/dist/spell-node.js +23 -0
  45. package/dist/spell-node.js.map +1 -0
  46. package/dist/spell.d.ts +18 -0
  47. package/dist/spell.js +4 -0
  48. package/dist/spell.js.map +1 -0
  49. package/dist/z3-MWU3GSVT.js +5 -0
  50. package/dist/z3-MWU3GSVT.js.map +1 -0
  51. package/package.json +160 -0
@@ -0,0 +1,313 @@
1
+ import { C as CompileOptions, S as Span, D as Deontic, k as PredicateIR, B as Bag } from './compile-DViQS2oG.js';
2
+ import { S as Severity, D as Diagnostic } from './diagnostics-BWJ_oMd8.js';
3
+
4
+ type Importance = 'critical' | 'important' | 'advisory';
5
+ /** Is `a` at least as important as `b`? (`critical ≥ important ≥ advisory`.) */
6
+ declare function atLeastImportant(a: Importance, b: Importance): boolean;
7
+ /**
8
+ * How much a diagnostic matters, independent of its severity level. An `error` is always `critical`; a
9
+ * correctness-category warning/info is `important`; a style / quality / grammar / spelling nudge is `advisory`.
10
+ */
11
+ declare function importanceOf(code: string, severity: Severity): Importance;
12
+
13
+ /** How strict to be — a product tightens the compiler here so no IMPORTANT warning slips through unblocking. */
14
+ interface StrictnessPolicy {
15
+ /** Escalate every `warn` to a blocking `error` (the blunt "warnings as errors" switch). `info` stays advisory. */
16
+ strict?: boolean;
17
+ /** Escalate specific diagnostics to `error` — by full code (`structure/unused-tool`) or whole category (`style`). */
18
+ escalate?: string[];
19
+ /** Escalate any diagnostic at or above this IMPORTANCE to a blocking error — the precise "strict about what
20
+ * MATTERS" knob. `'important'` blocks every correctness finding (dangling refs, dead rules, leaked secrets)
21
+ * while leaving style / quality nudges advisory; `'critical'` blocks only hard errors. */
22
+ escalateImportance?: Importance;
23
+ /** The ONLY way to make a warning non-blocking: name its code / category here. Explicit and auditable — never
24
+ * silent. A relaxed diagnostic still appears in the report, demoted to `info`, so nothing disappears. */
25
+ relax?: string[];
26
+ }
27
+ interface ReportRange {
28
+ line: number;
29
+ column: number;
30
+ endColumn: number;
31
+ }
32
+ interface ReportDiagnostic {
33
+ code: string;
34
+ category: string;
35
+ name: string;
36
+ importance: Importance;
37
+ severity: Severity;
38
+ effectiveSeverity: Severity;
39
+ blocking: boolean;
40
+ range: ReportRange;
41
+ message: string;
42
+ fix?: {
43
+ title: string;
44
+ replacement: string;
45
+ };
46
+ }
47
+ interface ProgramSummary {
48
+ inputs: {
49
+ name: string;
50
+ type: string;
51
+ }[];
52
+ defines: string[];
53
+ sections: string[];
54
+ tools: string[];
55
+ routes: string[];
56
+ steps: number;
57
+ switches: {
58
+ value: number;
59
+ predicate: number;
60
+ tuple: number;
61
+ inline: number;
62
+ };
63
+ }
64
+ interface TgReport {
65
+ ok: boolean;
66
+ consistent: boolean;
67
+ wellFormed: boolean;
68
+ counts: {
69
+ error: number;
70
+ warn: number;
71
+ info: number;
72
+ };
73
+ diagnostics: ReportDiagnostic[];
74
+ program: ProgramSummary;
75
+ xml: string;
76
+ }
77
+ /** The compile knobs a report caller may thread through — the ambient project layer (`glish.tgc`), the
78
+ * edge-injected dictionary, and extra addressee nouns. A subset of {@link CompileOptions}: the report stays
79
+ * the agent envelope; rubric/instructions belong to richer compile callers. */
80
+ type ReportCompileOptions = Pick<CompileOptions, 'glishConfig' | 'isWord' | 'addressees'>;
81
+ /**
82
+ * The agent-consumable compile report. Pure and JSON-serializable. Pass `extraDiagnostics` to fold in the async
83
+ * solver tiers (numeric conflicts, Z3 exhaustiveness) a Node/server caller has already computed, so the report
84
+ * reflects the FULL check, not just the synchronous one. Pass `compile` to thread the project's `glish.tgc` /
85
+ * dictionary / addressees into the underlying compile — same knobs, same envelope.
86
+ */
87
+ declare function report(source: string, opts?: {
88
+ policy?: StrictnessPolicy;
89
+ extraDiagnostics?: Diagnostic[];
90
+ compile?: ReportCompileOptions;
91
+ }): TgReport;
92
+
93
+ /**
94
+ * Compile the TypeGlish source into the prompt the agent runs: declarations expanded, comments and IMPORT
95
+ * manifests stripped, cosmetic indentation removed — System then Instructions.
96
+ *
97
+ * Markdown headers (`# Role`) and XML tags (`<examples>…</examples>`) are PRESERVED AS AUTHORED — the two are
98
+ * NOT interconverted. They solve different problems and the model leans on them differently: a `#` heading
99
+ * signals document structure and semantic weight (section / subsection), while a `<tag>` marks a hard block
100
+ * boundary the model treats as a delimiter ("everything here is examples"). Rewriting `#` into `<tag>` (as an
101
+ * earlier version did) erased that distinction and made it ambiguous which one was authoritative; leaving each
102
+ * as written keeps the signal clean. (The name is historical — the output is a compiled prompt, not only XML.)
103
+ */
104
+ declare function compileToXml(systemContent: string, instructionsContent: string): string;
105
+
106
+ interface EditResult {
107
+ /** Did the edit apply? When false, `source` is unchanged and `error` says why. */
108
+ ok: boolean;
109
+ source: string;
110
+ changed: number;
111
+ error?: string;
112
+ }
113
+ /**
114
+ * Rename a declared `$REQUIRE variable` or `$DEFINE` — the declaration AND every `$name` reference (guards,
115
+ * switches, other defines, prose) — leaving quotes, comments, and `$TOOL`/`$SERVICE` block bodies untouched.
116
+ * Refuses an invalid target (bad identifier, reserved word, name already taken, a no-op) so the result is
117
+ * always well-formed. Pure and stateless.
118
+ */
119
+ declare function rename(source: string, kind: 'variable' | 'define', from: string, to: string): EditResult;
120
+
121
+ /** One atomic claim extracted from a line. A compound line (`IF g THEN a; b`) yields several atoms —
122
+ * the spike showed sentence-level entailment fails on compound lines (0.01 ent on real paraphrase
123
+ * pairs) while atom-level matching recovers them at ≥0.96, so atoms are the unit of comparison. */
124
+ interface SemanticAtom {
125
+ /** Content hash of (text + guard) — durable identity across line moves and renumbering. The
126
+ * verdict cache keys on this, so an unchanged claim never re-scores. */
127
+ id: string;
128
+ /** 0-based source line the atom came from — session-local position, NOT identity. */
129
+ line: number;
130
+ span: Span;
131
+ /** The self-contained claim an entailment model reads: guard folded in, polarity re-injected
132
+ * ("When <guard>, you must not <action>."). */
133
+ text: string;
134
+ kind: 'directive' | 'declaration' | 'prose';
135
+ /** Deontic force when the atom came from a directive. */
136
+ deontic?: Deontic;
137
+ /** Normalized subject ('' is the implicit agent) when directive-derived. */
138
+ subject?: string;
139
+ /** The original guard text when the claim is conditional. */
140
+ guard?: string;
141
+ /** Parsed predicates (verb + theme + roles + tool) — the structured view of what the claim DOES.
142
+ * Directive atoms carry their IR predicate; prose atoms carry recall-oriented chunk parses.
143
+ * Feeds the candidate gate; never the claim text or id (cache/fixtures stay valid). */
144
+ predicates?: PredicateIR[];
145
+ }
146
+ /** The five semantic relations between two claims. `covers` is read from `a`'s perspective:
147
+ * a is the broader claim and fully implies b. */
148
+ type OverlapRelation = 'equivalent' | 'covers' | 'covered_by' | 'contradicts' | 'distinct';
149
+ /** A scored relation between two atoms. Raw model scores ride along as the receipt — every finding
150
+ * the UI shows can point at the numbers behind it. */
151
+ interface PairVerdict {
152
+ /** Atom ids, in canonical (sorted) order. */
153
+ a: string;
154
+ b: string;
155
+ relation: OverlapRelation;
156
+ /** P(a entails b) — a as premise. High means a is at least as strong as b. */
157
+ entAB: number;
158
+ /** P(b entails a). */
159
+ entBA: number;
160
+ /** max of the two directions' contradiction probability — the display receipt. */
161
+ conMax: number;
162
+ /** min of the two directions — the TRIGGER: true contradictions are symmetric (~1.00 both ways
163
+ * on the bench) while several distinct-but-related traps fire only one way. */
164
+ conMin: number;
165
+ /** How sure we are about WHICH side covers the other. NLI alone is unreliable on deontic
166
+ * direction (0.17 in the spike), so nli-tier verdicts cap this below the actionable threshold;
167
+ * the judge tier raises it. */
168
+ directionConfidence: number;
169
+ tier: 'nli' | 'nli+judge';
170
+ modelVersion: string;
171
+ }
172
+ /** How well one atom is covered by the rest of the prompt: the conjunction-coverage receipt. */
173
+ interface AtomCoverage {
174
+ atom: string;
175
+ /** ent(conjunction-of-coverers ⊨ atom) — 0.99 vs 0.002 solo in the spike. */
176
+ score: number;
177
+ /** The atoms whose conjunction covers this one. */
178
+ coveredBy: string[];
179
+ }
180
+ /** The per-line audit — the product's unit of output: what this line uniquely contributes. */
181
+ interface LineAudit {
182
+ /** 0-based source line. */
183
+ line: number;
184
+ atoms: string[];
185
+ /** 1 − min coverage across the line's atoms: the least-covered atom rules, so a line is only
186
+ * low-residual when EVERYTHING it says is already said elsewhere. */
187
+ residual: number;
188
+ /** Receipt: which lines cover this one, through which atoms, at what strength. */
189
+ coveredBy: {
190
+ line: number;
191
+ atoms: string[];
192
+ ent: number;
193
+ }[];
194
+ /** Lines this one semantically conflicts with. `confirmed` = a judge-tier verdict (warn-worthy);
195
+ * unconfirmed entries are NLI candidates and stay panel-only. */
196
+ contradicts: {
197
+ line: number;
198
+ conf: number;
199
+ confirmed: boolean;
200
+ }[];
201
+ /** True when every atom's coverage clears the removable threshold. Advisory — the behavioral
202
+ * ablation verifier (existing profiler) confirms before anyone acts on it. */
203
+ proposedRemovable: boolean;
204
+ /** Filled by the behavioral verifier: score delta when this line is ablated. */
205
+ verified?: {
206
+ delta: number;
207
+ stderr: number;
208
+ samples: number;
209
+ };
210
+ }
211
+ /** One step of the greedy reduction loop: cut lowest-residual, recompute, repeat. */
212
+ interface ReductionStep {
213
+ order: number;
214
+ line: number;
215
+ text: string;
216
+ residualAtCut: number;
217
+ coveredBy: {
218
+ line: number;
219
+ ent: number;
220
+ }[];
221
+ }
222
+ interface SemanticReport {
223
+ atoms: SemanticAtom[];
224
+ pairs: PairVerdict[];
225
+ coverage: AtomCoverage[];
226
+ lines: LineAudit[];
227
+ stats: {
228
+ pairsScored: number;
229
+ pairsFromCache: number;
230
+ pairsTruncated: number;
231
+ /** Fresh judge-tier calls this analysis (cached judge verdicts don't re-bill). */
232
+ judgeCalls?: number;
233
+ ms: number;
234
+ };
235
+ }
236
+
237
+ /** Decompose a whole prompt into atomic claims. Lines the compiler already understands (directives,
238
+ * conditionals, declarations) become IR-derived atoms; remaining content lines fall back to
239
+ * sentence + `;` segmentation. Comments, blanks, headings, fenced code, and $-command manifests
240
+ * yield nothing — the same gates runDiagnostics applies. */
241
+ declare function decompose(source: string): SemanticAtom[];
242
+
243
+ interface CandidatePair {
244
+ a: SemanticAtom;
245
+ b: SemanticAtom;
246
+ /** The lexical-overlap gate score — kept as a fusion feature and for truncation ordering. */
247
+ jaccard: number;
248
+ /** Which gate admitted the pair — 'predicate' marks zero-lexical-overlap recoveries. */
249
+ via: 'lexical' | 'predicate' | 'both';
250
+ }
251
+ interface CandidateSet {
252
+ pairs: CandidatePair[];
253
+ /** Pairs dropped by MAX_PAIRS — surfaced in stats, never silent. */
254
+ truncated: number;
255
+ }
256
+ /** Gate all cross-line atom pairs down to the candidates worth scoring. Same-line pairs are never
257
+ * candidates: a line doesn't overlap itself, it IS itself. */
258
+ declare function candidatePairs(atoms: SemanticAtom[]): CandidateSet;
259
+
260
+ interface PairScores {
261
+ /** P(a entails b) — a as premise. */
262
+ entAB: number;
263
+ /** P(b entails a). */
264
+ entBA: number;
265
+ /** P(contradiction) with a as premise. */
266
+ conAB: number;
267
+ /** P(contradiction) with b as premise. */
268
+ conBA: number;
269
+ }
270
+ /** Classify one scored pair. Contradiction triggers on the SYMMETRIC signal — min of both
271
+ * directions: bench data shows every true contradiction fires ~1.00 both ways while several traps
272
+ * fire only one way (min kills 4 of 9 trap false positives outright). Even so, NLI contradiction
273
+ * precision on rule-prose caps at ~0.62, so a contradicts verdict is a CANDIDATE — the warn
274
+ * diagnostic is gated on judge confirmation; unconfirmed conflicts surface panel-only. Direction
275
+ * confidence from NLI alone is capped below the actionable threshold: the spike measured NLI at
276
+ * 0.17 on deontic direction (worse than chance), so "which side is broader" must come from the
277
+ * judge tier or the fine-tuned model, never from these scores. */
278
+ declare function classifyPair(s: PairScores): {
279
+ relation: OverlapRelation;
280
+ directionConfidence: number;
281
+ };
282
+ /** Build a full PairVerdict from scores (canonical atom order preserved by the caller). */
283
+ declare function verdictFrom(a: string, b: string, s: PairScores, tier?: PairVerdict['tier']): PairVerdict;
284
+ /** Assemble per-line audits from atoms + verdicts + coverage. Residual is 1 − the line's WORST
285
+ * atom coverage: a line is only as redundant as its least-covered claim, so nothing gets proposed
286
+ * for removal while any part of it is unique. */
287
+ declare function assembleAudits(atoms: SemanticAtom[], verdicts: PairVerdict[], coverage: AtomCoverage[]): LineAudit[];
288
+ /** Assemble the full report the API returns and the UI renders. */
289
+ declare function buildReport(atoms: SemanticAtom[], verdicts: PairVerdict[], coverage: AtomCoverage[], stats: SemanticReport['stats']): SemanticReport;
290
+
291
+ interface ReduceOptions {
292
+ /** Runaway backstop — a prompt proposing more cuts than this deserves human eyes first. */
293
+ maxCuts?: number;
294
+ }
295
+ declare function proposeReduction(source: string, analyze: (source: string) => Promise<SemanticReport>, opts?: ReduceOptions): Promise<ReductionStep[]>;
296
+
297
+ /** Fold a semantic report into advisory diagnostics — the strongest finding per line, receipts in
298
+ * the message, everything else left to the findings panel. Priority: a semantic conflict outranks
299
+ * redundancy (a wrong rule beats a repeated one), full coverage outranks pairwise equivalence
300
+ * (it's the stronger, direction-free claim). */
301
+ declare function semanticDiagnostics(report: SemanticReport, source: string, displaySource?: string): Diagnostic[];
302
+
303
+ /** Knobs for WHERE a resolve runs. The default is the FINAL, model-facing render: an undecidable guard
304
+ * strips fail-open (the model must never read `when=` scaffolding). The import pipeline's INTERMEDIATE
305
+ * resolve opts into `keepUndecidedGuards`: an unbound guard's tag line stays VERBATIM (attribute and
306
+ * `@{}` pointers intact), so conditionality SURVIVES the module boundary and the host's own resolve —
307
+ * which holds the runtime bag — decides it. */
308
+ interface ResolveOptions {
309
+ keepUndecidedGuards?: boolean;
310
+ }
311
+ declare function resolve(source: string, bag: Bag, opts?: ResolveOptions): string;
312
+
313
+ export { type AtomCoverage as A, type EditResult as E, type Importance as I, type LineAudit as L, type OverlapRelation as O, type PairVerdict as P, type ReportCompileOptions as R, type StrictnessPolicy as S, type TgReport as T, type ProgramSummary as a, type ReductionStep as b, type ReportDiagnostic as c, type ReportRange as d, type SemanticAtom as e, type SemanticReport as f, assembleAudits as g, atLeastImportant as h, buildReport as i, candidatePairs as j, classifyPair as k, compileToXml as l, decompose as m, importanceOf as n, report as o, proposeReduction as p, resolve as q, rename as r, semanticDiagnostics as s, verdictFrom as v };
@@ -0,0 +1,3 @@
1
+ export { A as AgentBundle, B as Bag, C as CompileOptions, a as CompileResult, E as Expr, H as HttpMethod, I as IR, b as IRNode, P as ParamType, c as PreparedTemplate, R as ResolvedModel, T as ToolBinding, d as ToolDef, e as ToolParam, f as compile, g as evalExpr, h as exprAtoms, n as numericDiagnostics, p as parseExpr, i as parseTools, j as prepareTemplate, s as structuralDiagnostics, t as toolInputSchema } from './compile-DViQS2oG.js';
2
+ export { A as AtomCoverage, E as EditResult, I as Importance, L as LineAudit, O as OverlapRelation, P as PairVerdict, a as ProgramSummary, b as ReductionStep, c as ReportDiagnostic, d as ReportRange, e as SemanticAtom, f as SemanticReport, S as StrictnessPolicy, T as TgReport, g as assembleAudits, h as atLeastImportant, i as buildReport, j as candidatePairs, k as classifyPair, l as compileToXml, m as decompose, n as importanceOf, p as proposeReduction, r as rename, o as report, q as resolve, s as semanticDiagnostics, v as verdictFrom } from './index-Df_QnTgq.js';
3
+ export { D as Diagnostic, R as RubricDim, S as Severity, a as SpellChecker, b as applyFix, c as composeSpans, r as runDiagnostics } from './diagnostics-BWJ_oMd8.js';
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import './chunk-PXAMTGYY.js';
2
+ export { applyFix, assembleAudits, atLeastImportant, buildReport, candidatePairs, classifyPair, compile, composeSpans, decompose, importanceOf, numericDiagnostics, prepareTemplate, proposeReduction, rename, report, resolve, runDiagnostics, semanticDiagnostics, structuralDiagnostics, verdictFrom } from './chunk-KRYC4OTL.js';
3
+ export { compileToXml, evalExpr, exprAtoms, parseExpr, parseTools, toolInputSchema } from './chunk-YH4ZLQ4G.js';
4
+ import './chunk-Y64EAEYB.js';
5
+ import './chunk-PR4QN5HX.js';
6
+ //# sourceMappingURL=index.js.map
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/dist/mcp.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+
3
+ interface McpOptions {
4
+ cwd?: string;
5
+ version?: string;
6
+ }
7
+ declare function createTypeglishServer(opts?: McpOptions): McpServer;
8
+ /** `typeglish mcp` — serve the tools over stdio until the host closes the pipe. */
9
+ declare function startMcpServer(opts?: McpOptions): Promise<void>;
10
+
11
+ export { type McpOptions, createTypeglishServer, startMcpServer };