ctxmedic 0.7.0 → 0.9.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.
package/README.md CHANGED
@@ -108,6 +108,9 @@ their severity or thresholds, or ignore paths, add `ctxmedic.config.json`:
108
108
  { "rules": { "INFO_UNSUPPORTED_SYNTAX": "off", "WARN_CONTEXT_BLOAT": ["on", { "tokens": 6000 }] } }
109
109
  ```
110
110
 
111
+ Add `"$schema": "./node_modules/ctxmedic/schema.json"` for autocomplete of rule
112
+ ids and options in your editor ([details](docs/rules/README.md#configuring-rules)).
113
+
111
114
  To silence a rule for one Markdown file: `<!-- ctxmedic-disable WARN_CONTEXT_BLOAT -- reason -->`.
112
115
 
113
116
  ## What ctxmedic reads and writes
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ import { Command } from "commander";
9
9
  import pc2 from "picocolors";
10
10
 
11
11
  // ../clinical/src/schema.ts
12
- import { z as z5 } from "zod";
12
+ import { z as z6 } from "zod";
13
13
 
14
14
  // ../core/src/schema.ts
15
15
  import { z } from "zod";
@@ -753,6 +753,38 @@ var syntax = {
753
753
  }
754
754
  };
755
755
 
756
+ // ../core/src/rules/finopsMeta.ts
757
+ import { z as z4 } from "zod";
758
+ var MCP_SCHEMA_TOKENS = 1500;
759
+ var SNOWBALL_STEPS = 35;
760
+ var SNOWBALL_HEAVY_STEPS = 10;
761
+ var CACHE_HIT_MIN = 0.4;
762
+ var CACHE_HIT_TARGET = 0.7;
763
+ var CACHE_MIN_TOKENS = 1e6;
764
+ var OVERKILL_MAX_STEPS = 2;
765
+ var OVERKILL_MIN_SESSIONS = 3;
766
+ var posInt = (d2) => z4.number().int().positive().default(d2);
767
+ var ratio = (d2) => z4.number().min(0).max(1).default(d2);
768
+ var FinOptions = {
769
+ FIN_UNUSED_MCP: z4.object({ schemaTokens: posInt(MCP_SCHEMA_TOKENS) }),
770
+ FIN_MODEL_OVERKILL: z4.object({ maxSteps: posInt(OVERKILL_MAX_STEPS), minSessions: posInt(OVERKILL_MIN_SESSIONS) }),
771
+ FIN_CONTEXT_SNOWBALL: z4.object({ steps: posInt(SNOWBALL_STEPS), heavySteps: posInt(SNOWBALL_HEAVY_STEPS) }),
772
+ FIN_CACHE_MISS: z4.object({ minHitRatio: ratio(CACHE_HIT_MIN), targetHitRatio: ratio(CACHE_HIT_TARGET), minTokens: posInt(CACHE_MIN_TOKENS) }).refine((o2) => o2.targetHitRatio >= o2.minHitRatio, { message: "targetHitRatio must be at least minHitRatio" })
773
+ };
774
+ var meta = (id, description) => ({
775
+ description,
776
+ type: "suggestion",
777
+ docs: docsUrl(id),
778
+ fixable: false,
779
+ options: FinOptions[id]
780
+ });
781
+ var finopsMeta = {
782
+ FIN_UNUSED_MCP: meta("FIN_UNUSED_MCP", "Remove MCP servers that are never called"),
783
+ FIN_MODEL_OVERKILL: meta("FIN_MODEL_OVERKILL", "Route one-shot tasks to a cheaper model"),
784
+ FIN_CONTEXT_SNOWBALL: meta("FIN_CONTEXT_SNOWBALL", "Compact or clear long sessions"),
785
+ FIN_CACHE_MISS: meta("FIN_CACHE_MISS", "Keep the prompt cache warm")
786
+ };
787
+
756
788
  // ../core/src/rules/index.ts
757
789
  var rules = [brokenLink, contextBloat, duplicates, skills, secretLeak, syntax, bloatIgnore];
758
790
  async function runRules(ctx2, list = rules, options = {}, off = /* @__PURE__ */ new Set()) {
@@ -873,15 +905,15 @@ import crypto2 from "crypto";
873
905
  import fs6 from "fs";
874
906
  import path9 from "path";
875
907
  import picomatch2 from "picomatch";
876
- import { z as z4 } from "zod";
908
+ import { z as z5 } from "zod";
877
909
  var CONFIG_FILE = "ctxmedic.config.json";
878
- var RuleLevel = z4.union([z4.literal("off"), z4.literal("on"), Severity]);
879
- var RuleEntry = z4.union([RuleLevel, z4.tuple([RuleLevel]), z4.tuple([RuleLevel, z4.record(z4.string(), z4.unknown())])]);
880
- var CtxmedicConfig = z4.object({
881
- $schema: z4.string().optional(),
882
- rules: z4.partialRecord(RuleId, RuleEntry).default({}),
910
+ var RuleLevel = z5.union([z5.literal("off"), z5.literal("on"), Severity]);
911
+ var RuleEntry = z5.union([RuleLevel, z5.tuple([RuleLevel]), z5.tuple([RuleLevel, z5.record(z5.string(), z5.unknown())])]);
912
+ var CtxmedicConfig = z5.object({
913
+ $schema: z5.string().optional(),
914
+ rules: z5.partialRecord(RuleId, RuleEntry).default({}),
883
915
  /** Globs over finding paths (project-relative, or `~/` for global files). */
884
- ignores: z4.array(z4.string()).default([])
916
+ ignores: z5.array(z5.string()).default([])
885
917
  });
886
918
  var ConfigError = class extends Error {
887
919
  };
@@ -897,14 +929,14 @@ function loadConfig(root) {
897
929
  throw new ConfigError(`${CONFIG_FILE}: ${e.message}`);
898
930
  }
899
931
  const r = CtxmedicConfig.safeParse(raw);
900
- if (!r.success) throw new ConfigError(`${CONFIG_FILE}: ${z4.prettifyError(r.error)}`);
932
+ if (!r.success) throw new ConfigError(`${CONFIG_FILE}: ${z5.prettifyError(r.error)}`);
901
933
  for (const [id, entry] of Object.entries(r.data.rules)) {
902
934
  const opts = optionsOf(entry);
903
935
  if (!Object.keys(opts).length) continue;
904
- const schema = rules.find((x) => x.id === id)?.meta.options;
936
+ const schema = (rules.find((x) => x.id === id)?.meta ?? finopsMeta[id])?.options;
905
937
  if (!schema) throw new ConfigError(`${CONFIG_FILE}: rule ${id} takes no options`);
906
938
  const o2 = schema.safeParse(opts);
907
- if (!o2.success) throw new ConfigError(`${CONFIG_FILE}: rule ${id}: ${z4.prettifyError(o2.error)}`);
939
+ if (!o2.success) throw new ConfigError(`${CONFIG_FILE}: rule ${id}: ${z5.prettifyError(o2.error)}`);
908
940
  }
909
941
  return r.data;
910
942
  }
@@ -956,64 +988,64 @@ async function examine(root, profiles, opts = {}) {
956
988
  }
957
989
 
958
990
  // ../clinical/src/schema.ts
959
- var Lang = z5.enum(["en"]);
960
- var Triage = z5.enum(["resuscitation", "therapy", "preventive"]);
961
- var PrescriptionRx = z5.object({
962
- id: z5.string().regex(/^RX-\d{2,}$/),
963
- action: z5.string(),
964
- command: z5.string().optional(),
965
- autoFix: z5.boolean(),
966
- healthGain: z5.number().nonnegative(),
967
- monthlySavingsUsd: z5.number().nonnegative().optional()
991
+ var Lang = z6.enum(["en"]);
992
+ var Triage = z6.enum(["resuscitation", "therapy", "preventive"]);
993
+ var PrescriptionRx = z6.object({
994
+ id: z6.string().regex(/^RX-\d{2,}$/),
995
+ action: z6.string(),
996
+ command: z6.string().optional(),
997
+ autoFix: z6.boolean(),
998
+ healthGain: z6.number().nonnegative(),
999
+ monthlySavingsUsd: z6.number().nonnegative().optional()
968
1000
  });
969
- var ClinicalDiagnosis = z5.object({
1001
+ var ClinicalDiagnosis = z6.object({
970
1002
  code: RuleId,
971
1003
  triage: Triage,
972
- diagnosis: z5.string(),
973
- summary: z5.string(),
974
- vitals: z5.array(z5.object({ label: z5.string(), value: z5.string() })),
975
- prognosis: z5.string(),
1004
+ diagnosis: z6.string(),
1005
+ summary: z6.string(),
1006
+ vitals: z6.array(z6.object({ label: z6.string(), value: z6.string() })),
1007
+ prognosis: z6.string(),
976
1008
  rx: PrescriptionRx,
977
- files: z5.array(z5.string()),
1009
+ files: z6.array(z6.string()),
978
1010
  finding: Finding
979
1011
  });
980
- var Counts = z5.object({ resuscitation: z5.number(), therapy: z5.number(), preventive: z5.number() });
981
- var Anamnesis = z5.object({
982
- priority: z5.enum(["economy", "balanced", "quality"]).default("balanced"),
983
- primaryHarness: z5.string().optional(),
984
- monthlyBudgetUsd: z5.number().nonnegative().optional()
1012
+ var Counts = z6.object({ resuscitation: z6.number(), therapy: z6.number(), preventive: z6.number() });
1013
+ var Anamnesis = z6.object({
1014
+ priority: z6.enum(["economy", "balanced", "quality"]).default("balanced"),
1015
+ primaryHarness: z6.string().optional(),
1016
+ monthlyBudgetUsd: z6.number().nonnegative().optional()
985
1017
  });
986
- var ScanSettings = z5.object({
987
- global: z5.boolean(),
988
- finops: z5.boolean(),
989
- days: z5.number(),
1018
+ var ScanSettings = z6.object({
1019
+ global: z6.boolean(),
1020
+ finops: z6.boolean(),
1021
+ days: z6.number(),
990
1022
  /** `configHash` of ctxmedic.config.json; "" without one, and in history written before v0.3. */
991
- config: z5.string().default("")
1023
+ config: z6.string().default("")
992
1024
  });
993
1025
  var DEFAULT_SCAN = { global: true, finops: true, days: 30, config: "" };
994
- var Visit = z5.object({
995
- at: z5.string(),
996
- root: z5.string(),
1026
+ var Visit = z6.object({
1027
+ at: z6.string(),
1028
+ root: z6.string(),
997
1029
  /** Missing in history written by v0.1.0: those runs are assumed to use the defaults. */
998
1030
  scan: ScanSettings.default(DEFAULT_SCAN),
999
- healthScore: z5.number(),
1031
+ healthScore: z6.number(),
1000
1032
  counts: Counts,
1001
- monthlySpendUsd: z5.number().optional(),
1002
- potentialMonthlySavingsUsd: z5.number()
1033
+ monthlySpendUsd: z6.number().optional(),
1034
+ potentialMonthlySavingsUsd: z6.number()
1003
1035
  });
1004
- var ClinicalReport = z5.object({
1005
- tool: z5.literal("ctxmedic"),
1006
- version: z5.string(),
1036
+ var ClinicalReport = z6.object({
1037
+ tool: z6.literal("ctxmedic"),
1038
+ version: z6.string(),
1007
1039
  lang: Lang,
1008
- generatedAt: z5.string(),
1040
+ generatedAt: z6.string(),
1009
1041
  patient: PatientVitals,
1010
- healthScore: z5.number().min(0).max(100),
1042
+ healthScore: z6.number().min(0).max(100),
1011
1043
  previous: Visit.nullable(),
1012
- opinion: z5.string(),
1044
+ opinion: z6.string(),
1013
1045
  counts: Counts,
1014
- diagnoses: z5.array(ClinicalDiagnosis),
1046
+ diagnoses: z6.array(ClinicalDiagnosis),
1015
1047
  finops: FinOpsReport.nullable(),
1016
- potentialMonthlySavingsUsd: z5.number()
1048
+ potentialMonthlySavingsUsd: z6.number()
1017
1049
  });
1018
1050
 
1019
1051
  // ../finops/src/cache.ts
@@ -1109,14 +1141,6 @@ function costOf(model, u) {
1109
1141
  }
1110
1142
 
1111
1143
  // ../finops/src/detectors.ts
1112
- var MCP_SCHEMA_TOKENS = 1500;
1113
- var SNOWBALL_STEPS = 35;
1114
- var SNOWBALL_HEAVY_STEPS = 10;
1115
- var CACHE_HIT_MIN = 0.4;
1116
- var CACHE_HIT_TARGET = 0.7;
1117
- var CACHE_MIN_TOKENS = 1e6;
1118
- var OVERKILL_MAX_STEPS = 2;
1119
- var OVERKILL_MIN_SESSIONS = 3;
1120
1144
  var monthly = (usd3, days) => usd3 * 30 / days;
1121
1145
  var round = (n2) => Math.round(n2 * 100) / 100;
1122
1146
  var dominant = (sessions) => {
@@ -1125,7 +1149,8 @@ var dominant = (sessions) => {
1125
1149
  return Object.entries(m).sort((a2, b) => b[1] - a2[1])[0]?.[0];
1126
1150
  };
1127
1151
  var sev = (usd3) => usd3 >= 1 ? "warning" : "info";
1128
- function unusedMcp({ sessions, days, files, root }) {
1152
+ var detector = (id, check) => ({ id, meta: finopsMeta[id], check });
1153
+ var unusedMcp = detector("FIN_UNUSED_MCP", ({ sessions, days, files, root }, { schemaTokens: fallback }) => {
1129
1154
  const out = [];
1130
1155
  const calls = {};
1131
1156
  for (const s of sessions) for (const [k, n2] of Object.entries(s.mcpCalls)) calls[k] = (calls[k] ?? 0) + n2;
@@ -1139,7 +1164,7 @@ function unusedMcp({ sessions, days, files, root }) {
1139
1164
  const idle = Object.keys(mcpServers(f.path, f.text, root)).filter((name) => !calls[name] && !calls[name.replace(/[^\w]/g, "_")]);
1140
1165
  if (!idle.length) continue;
1141
1166
  const measured = idle.map((name) => Math.max(0, ...hs.map((s) => s.mcpSchemaTokens?.[name] ?? s.mcpSchemaTokens?.[name.replace(/[^\w]/g, "_")] ?? 0)) || null);
1142
- const schemaTokens = measured.reduce((n2, t2) => n2 + (t2 ?? MCP_SCHEMA_TOKENS), 0);
1167
+ const schemaTokens = measured.reduce((n2, t2) => n2 + (t2 ?? fallback), 0);
1143
1168
  const estimated = measured.some((t2) => t2 === null);
1144
1169
  const usd3 = monthly(schemaTokens * steps * priceOf(model).price.cacheRead / 1e6, days);
1145
1170
  out.push({
@@ -1153,11 +1178,11 @@ function unusedMcp({ sessions, days, files, root }) {
1153
1178
  }
1154
1179
  }
1155
1180
  return out;
1156
- }
1157
- function modelOverkill({ sessions, days }) {
1181
+ });
1182
+ var modelOverkill = detector("FIN_MODEL_OVERKILL", ({ sessions, days }, { maxSteps, minSessions }) => {
1158
1183
  const byModel = /* @__PURE__ */ new Map();
1159
1184
  for (const s of sessions) {
1160
- if (s.steps === 0 || s.steps > OVERKILL_MAX_STEPS) continue;
1185
+ if (s.steps === 0 || s.steps > maxSteps) continue;
1161
1186
  for (const [model, u] of Object.entries(s.models)) {
1162
1187
  const to = lighterModel(model);
1163
1188
  if (!to) continue;
@@ -1168,7 +1193,7 @@ function modelOverkill({ sessions, days }) {
1168
1193
  byModel.set(model, e);
1169
1194
  }
1170
1195
  }
1171
- return [...byModel].filter(([, e]) => e.n >= OVERKILL_MIN_SESSIONS).map(([model, e]) => {
1196
+ return [...byModel].filter(([, e]) => e.n >= minSessions).map(([model, e]) => {
1172
1197
  const usd3 = monthly(e.cost - e.cheaper, days);
1173
1198
  return {
1174
1199
  ruleId: "FIN_MODEL_OVERKILL",
@@ -1179,9 +1204,9 @@ function modelOverkill({ sessions, days }) {
1179
1204
  monthlySavingsUsd: round(usd3)
1180
1205
  };
1181
1206
  });
1182
- }
1183
- function contextSnowball({ sessions, days }) {
1184
- const bad = sessions.filter((s) => s.steps > SNOWBALL_STEPS && s.heavySteps >= SNOWBALL_HEAVY_STEPS && s.compactions === 0);
1207
+ });
1208
+ var contextSnowball = detector("FIN_CONTEXT_SNOWBALL", ({ sessions, days }, { steps, heavySteps }) => {
1209
+ const bad = sessions.filter((s) => s.steps > steps && s.heavySteps >= heavySteps && s.compactions === 0);
1185
1210
  if (!bad.length) return [];
1186
1211
  let usd3 = 0;
1187
1212
  for (const s of bad) {
@@ -1194,14 +1219,14 @@ function contextSnowball({ sessions, days }) {
1194
1219
  {
1195
1220
  ruleId: "FIN_CONTEXT_SNOWBALL",
1196
1221
  severity: sev(usd3),
1197
- message: `${bad.length} session(s) ran >${SNOWBALL_STEPS} steps with 100k+ context and no /clear or /compact`,
1222
+ message: `${bad.length} session(s) ran >${steps} steps with 100k+ context and no /clear or /compact`,
1198
1223
  files: bad.slice(0, 5).map((s) => `session ${path12.basename(s.file, ".jsonl")}`),
1199
1224
  data: { sessions: bad.length, worstSteps: worst.steps, worstMaxContext: worst.maxContext, days },
1200
1225
  monthlySavingsUsd: round(usd3)
1201
1226
  }
1202
1227
  ];
1203
- }
1204
- function cacheMiss({ sessions, days }) {
1228
+ });
1229
+ var cacheMiss = detector("FIN_CACHE_MISS", ({ sessions, days }, { minHitRatio, targetHitRatio, minTokens }) => {
1205
1230
  const out = [];
1206
1231
  for (const h of ["claude-code", "codex"]) {
1207
1232
  const hs = sessions.filter((s) => s.harness === h);
@@ -1210,22 +1235,22 @@ function cacheMiss({ sessions, days }) {
1210
1235
  let write = 0;
1211
1236
  for (const s of hs) for (const u of Object.values(s.models)) input += u.input, read += u.cacheRead, write += u.cacheWrite;
1212
1237
  const total = input + read + write;
1213
- if (total < CACHE_MIN_TOKENS) continue;
1214
- const ratio = read / total;
1215
- if (ratio >= CACHE_HIT_MIN) continue;
1238
+ if (total < minTokens) continue;
1239
+ const ratio2 = read / total;
1240
+ if (ratio2 >= minHitRatio) continue;
1216
1241
  const p3 = priceOf(dominant(hs) ?? "claude-sonnet-5-5").price;
1217
- const usd3 = monthly((CACHE_HIT_TARGET - ratio) * total * (p3.input - p3.cacheRead) / 1e6, days);
1242
+ const usd3 = monthly((targetHitRatio - ratio2) * total * (p3.input - p3.cacheRead) / 1e6, days);
1218
1243
  out.push({
1219
1244
  ruleId: "FIN_CACHE_MISS",
1220
1245
  severity: sev(usd3),
1221
- message: `${h} prompt-cache hit ratio is ${Math.round(ratio * 100)}% (healthy: \u2265${CACHE_HIT_MIN * 100}%)`,
1246
+ message: `${h} prompt-cache hit ratio is ${Math.round(ratio2 * 100)}% (healthy: \u2265${Math.round(minHitRatio * 100)}%)`,
1222
1247
  files: [],
1223
- data: { harness: h, cacheHitRatio: ratio, totalInputTokens: total, days },
1248
+ data: { harness: h, cacheHitRatio: ratio2, totalInputTokens: total, days },
1224
1249
  monthlySavingsUsd: round(Math.max(0, usd3))
1225
1250
  });
1226
1251
  }
1227
1252
  return out;
1228
- }
1253
+ });
1229
1254
  var detectors = [unusedMcp, modelOverkill, contextSnowball, cacheMiss];
1230
1255
 
1231
1256
  // ../finops/src/parsers.ts
@@ -1394,7 +1419,7 @@ function buildReport(sessions, { days = 30, root, files, config }) {
1394
1419
  read += u.cacheRead;
1395
1420
  }
1396
1421
  }
1397
- const raw = detectors.flatMap((d2) => d2({ sessions, days, files, root }));
1422
+ const raw = detectors.filter((d2) => levelOf(config?.rules[d2.id]) !== "off").flatMap((d2) => d2.check({ sessions, days, files, root }, d2.meta.options.parse(optionsOf(config?.rules[d2.id]))));
1398
1423
  const findings = config ? applyConfig(raw, files, config) : raw;
1399
1424
  return FinOpsReport.parse({
1400
1425
  periodDays: days,
@@ -1672,7 +1697,7 @@ var harnesses = [
1672
1697
  ];
1673
1698
 
1674
1699
  // ../clinical/src/engine.ts
1675
- var VERSION = true ? "0.7.0" : "0.0.0-dev";
1700
+ var VERSION = true ? "0.9.0" : "0.0.0-dev";
1676
1701
  var TRIAGE = { critical: "resuscitation", warning: "therapy", info: "preventive" };
1677
1702
  var ORDER = ["resuscitation", "therapy", "preventive"];
1678
1703
  var human = (k) => k.replace(/([A-Z])/g, " $1").replace(/^./, (c) => c.toUpperCase());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctxmedic",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "description": "The context medic for your AI coding setup: checkup, treat, savings for Claude Code, Cursor, Windsurf, Codex CLI, OpenCode, Cline and Copilot.",
5
5
  "type": "module",
6
6
  "license": "FSL-1.1-MIT",
@@ -41,6 +41,7 @@
41
41
  "files": [
42
42
  "dist",
43
43
  "public",
44
+ "schema.json",
44
45
  "LICENSE",
45
46
  "NOTICE",
46
47
  "README.md"
package/schema.json ADDED
@@ -0,0 +1,491 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "type": "object",
4
+ "properties": {
5
+ "$schema": {
6
+ "type": "string"
7
+ },
8
+ "rules": {
9
+ "type": "object",
10
+ "properties": {
11
+ "ERR_BROKEN_LINK": {
12
+ "anyOf": [
13
+ {
14
+ "$ref": "#/definitions/RuleLevel"
15
+ },
16
+ {
17
+ "type": "array",
18
+ "items": [
19
+ {
20
+ "$ref": "#/definitions/RuleLevel"
21
+ }
22
+ ],
23
+ "additionalItems": false,
24
+ "minItems": 1,
25
+ "maxItems": 1
26
+ },
27
+ {
28
+ "type": "array",
29
+ "items": [
30
+ {
31
+ "$ref": "#/definitions/RuleLevel"
32
+ },
33
+ {
34
+ "type": "object",
35
+ "properties": {},
36
+ "additionalProperties": false
37
+ }
38
+ ],
39
+ "additionalItems": false,
40
+ "minItems": 2,
41
+ "maxItems": 2
42
+ }
43
+ ],
44
+ "description": "Symlinked configs must point to an existing target, without loops or absolute paths. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/ERR_BROKEN_LINK.md"
45
+ },
46
+ "WARN_CONTEXT_BLOAT": {
47
+ "anyOf": [
48
+ {
49
+ "$ref": "#/definitions/RuleLevel"
50
+ },
51
+ {
52
+ "type": "array",
53
+ "items": [
54
+ {
55
+ "$ref": "#/definitions/RuleLevel"
56
+ }
57
+ ],
58
+ "additionalItems": false,
59
+ "minItems": 1,
60
+ "maxItems": 1
61
+ },
62
+ {
63
+ "type": "array",
64
+ "items": [
65
+ {
66
+ "$ref": "#/definitions/RuleLevel"
67
+ },
68
+ {
69
+ "type": "object",
70
+ "properties": {
71
+ "tokens": {
72
+ "default": 3500,
73
+ "type": "integer",
74
+ "exclusiveMinimum": 0,
75
+ "maximum": 9007199254740991
76
+ }
77
+ }
78
+ }
79
+ ],
80
+ "additionalItems": false,
81
+ "minItems": 2,
82
+ "maxItems": 2
83
+ }
84
+ ],
85
+ "description": "Limit the tokens a harness loads at session start. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/WARN_CONTEXT_BLOAT.md"
86
+ },
87
+ "WARN_DUPLICATE_RULES": {
88
+ "anyOf": [
89
+ {
90
+ "$ref": "#/definitions/RuleLevel"
91
+ },
92
+ {
93
+ "type": "array",
94
+ "items": [
95
+ {
96
+ "$ref": "#/definitions/RuleLevel"
97
+ }
98
+ ],
99
+ "additionalItems": false,
100
+ "minItems": 1,
101
+ "maxItems": 1
102
+ },
103
+ {
104
+ "type": "array",
105
+ "items": [
106
+ {
107
+ "$ref": "#/definitions/RuleLevel"
108
+ },
109
+ {
110
+ "type": "object",
111
+ "properties": {
112
+ "similarity": {
113
+ "default": 0.75,
114
+ "type": "number",
115
+ "exclusiveMinimum": 0,
116
+ "exclusiveMaximum": 1
117
+ }
118
+ }
119
+ }
120
+ ],
121
+ "additionalItems": false,
122
+ "minItems": 2,
123
+ "maxItems": 2
124
+ }
125
+ ],
126
+ "description": "Do not keep near-identical instruction files for different harnesses. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/WARN_DUPLICATE_RULES.md"
127
+ },
128
+ "ERR_INVALID_SKILL": {
129
+ "anyOf": [
130
+ {
131
+ "$ref": "#/definitions/RuleLevel"
132
+ },
133
+ {
134
+ "type": "array",
135
+ "items": [
136
+ {
137
+ "$ref": "#/definitions/RuleLevel"
138
+ }
139
+ ],
140
+ "additionalItems": false,
141
+ "minItems": 1,
142
+ "maxItems": 1
143
+ },
144
+ {
145
+ "type": "array",
146
+ "items": [
147
+ {
148
+ "$ref": "#/definitions/RuleLevel"
149
+ },
150
+ {
151
+ "type": "object",
152
+ "properties": {},
153
+ "additionalProperties": false
154
+ }
155
+ ],
156
+ "additionalItems": false,
157
+ "minItems": 2,
158
+ "maxItems": 2
159
+ }
160
+ ],
161
+ "description": "Skills need valid frontmatter, a unique name and a description with a trigger. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/ERR_INVALID_SKILL.md"
162
+ },
163
+ "CRIT_SECRET_LEAK": {
164
+ "anyOf": [
165
+ {
166
+ "$ref": "#/definitions/RuleLevel"
167
+ },
168
+ {
169
+ "type": "array",
170
+ "items": [
171
+ {
172
+ "$ref": "#/definitions/RuleLevel"
173
+ }
174
+ ],
175
+ "additionalItems": false,
176
+ "minItems": 1,
177
+ "maxItems": 1
178
+ },
179
+ {
180
+ "type": "array",
181
+ "items": [
182
+ {
183
+ "$ref": "#/definitions/RuleLevel"
184
+ },
185
+ {
186
+ "type": "object",
187
+ "properties": {},
188
+ "additionalProperties": false
189
+ }
190
+ ],
191
+ "additionalItems": false,
192
+ "minItems": 2,
193
+ "maxItems": 2
194
+ }
195
+ ],
196
+ "description": "Do not store secrets in plain text in AI configs. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/CRIT_SECRET_LEAK.md"
197
+ },
198
+ "INFO_UNSUPPORTED_SYNTAX": {
199
+ "anyOf": [
200
+ {
201
+ "$ref": "#/definitions/RuleLevel"
202
+ },
203
+ {
204
+ "type": "array",
205
+ "items": [
206
+ {
207
+ "$ref": "#/definitions/RuleLevel"
208
+ }
209
+ ],
210
+ "additionalItems": false,
211
+ "minItems": 1,
212
+ "maxItems": 1
213
+ },
214
+ {
215
+ "type": "array",
216
+ "items": [
217
+ {
218
+ "$ref": "#/definitions/RuleLevel"
219
+ },
220
+ {
221
+ "type": "object",
222
+ "properties": {},
223
+ "additionalProperties": false
224
+ }
225
+ ],
226
+ "additionalItems": false,
227
+ "minItems": 2,
228
+ "maxItems": 2
229
+ }
230
+ ],
231
+ "description": "Flag directives a harness does not understand. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/INFO_UNSUPPORTED_SYNTAX.md"
232
+ },
233
+ "FIN_BLOAT_IGNORE": {
234
+ "anyOf": [
235
+ {
236
+ "$ref": "#/definitions/RuleLevel"
237
+ },
238
+ {
239
+ "type": "array",
240
+ "items": [
241
+ {
242
+ "$ref": "#/definitions/RuleLevel"
243
+ }
244
+ ],
245
+ "additionalItems": false,
246
+ "minItems": 1,
247
+ "maxItems": 1
248
+ },
249
+ {
250
+ "type": "array",
251
+ "items": [
252
+ {
253
+ "$ref": "#/definitions/RuleLevel"
254
+ },
255
+ {
256
+ "type": "object",
257
+ "properties": {},
258
+ "additionalProperties": false
259
+ }
260
+ ],
261
+ "additionalItems": false,
262
+ "minItems": 2,
263
+ "maxItems": 2
264
+ }
265
+ ],
266
+ "description": "Keep build output and lockfiles out of the AI index with an ignore file. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/FIN_BLOAT_IGNORE.md"
267
+ },
268
+ "FIN_UNUSED_MCP": {
269
+ "anyOf": [
270
+ {
271
+ "$ref": "#/definitions/RuleLevel"
272
+ },
273
+ {
274
+ "type": "array",
275
+ "items": [
276
+ {
277
+ "$ref": "#/definitions/RuleLevel"
278
+ }
279
+ ],
280
+ "additionalItems": false,
281
+ "minItems": 1,
282
+ "maxItems": 1
283
+ },
284
+ {
285
+ "type": "array",
286
+ "items": [
287
+ {
288
+ "$ref": "#/definitions/RuleLevel"
289
+ },
290
+ {
291
+ "type": "object",
292
+ "properties": {
293
+ "schemaTokens": {
294
+ "default": 1500,
295
+ "type": "integer",
296
+ "exclusiveMinimum": 0,
297
+ "maximum": 9007199254740991
298
+ }
299
+ }
300
+ }
301
+ ],
302
+ "additionalItems": false,
303
+ "minItems": 2,
304
+ "maxItems": 2
305
+ }
306
+ ],
307
+ "description": "Remove MCP servers that are never called. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/FIN_UNUSED_MCP.md"
308
+ },
309
+ "FIN_MODEL_OVERKILL": {
310
+ "anyOf": [
311
+ {
312
+ "$ref": "#/definitions/RuleLevel"
313
+ },
314
+ {
315
+ "type": "array",
316
+ "items": [
317
+ {
318
+ "$ref": "#/definitions/RuleLevel"
319
+ }
320
+ ],
321
+ "additionalItems": false,
322
+ "minItems": 1,
323
+ "maxItems": 1
324
+ },
325
+ {
326
+ "type": "array",
327
+ "items": [
328
+ {
329
+ "$ref": "#/definitions/RuleLevel"
330
+ },
331
+ {
332
+ "type": "object",
333
+ "properties": {
334
+ "maxSteps": {
335
+ "default": 2,
336
+ "type": "integer",
337
+ "exclusiveMinimum": 0,
338
+ "maximum": 9007199254740991
339
+ },
340
+ "minSessions": {
341
+ "default": 3,
342
+ "type": "integer",
343
+ "exclusiveMinimum": 0,
344
+ "maximum": 9007199254740991
345
+ }
346
+ }
347
+ }
348
+ ],
349
+ "additionalItems": false,
350
+ "minItems": 2,
351
+ "maxItems": 2
352
+ }
353
+ ],
354
+ "description": "Route one-shot tasks to a cheaper model. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/FIN_MODEL_OVERKILL.md"
355
+ },
356
+ "FIN_CONTEXT_SNOWBALL": {
357
+ "anyOf": [
358
+ {
359
+ "$ref": "#/definitions/RuleLevel"
360
+ },
361
+ {
362
+ "type": "array",
363
+ "items": [
364
+ {
365
+ "$ref": "#/definitions/RuleLevel"
366
+ }
367
+ ],
368
+ "additionalItems": false,
369
+ "minItems": 1,
370
+ "maxItems": 1
371
+ },
372
+ {
373
+ "type": "array",
374
+ "items": [
375
+ {
376
+ "$ref": "#/definitions/RuleLevel"
377
+ },
378
+ {
379
+ "type": "object",
380
+ "properties": {
381
+ "steps": {
382
+ "default": 35,
383
+ "type": "integer",
384
+ "exclusiveMinimum": 0,
385
+ "maximum": 9007199254740991
386
+ },
387
+ "heavySteps": {
388
+ "default": 10,
389
+ "type": "integer",
390
+ "exclusiveMinimum": 0,
391
+ "maximum": 9007199254740991
392
+ }
393
+ }
394
+ }
395
+ ],
396
+ "additionalItems": false,
397
+ "minItems": 2,
398
+ "maxItems": 2
399
+ }
400
+ ],
401
+ "description": "Compact or clear long sessions. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/FIN_CONTEXT_SNOWBALL.md"
402
+ },
403
+ "FIN_CACHE_MISS": {
404
+ "anyOf": [
405
+ {
406
+ "$ref": "#/definitions/RuleLevel"
407
+ },
408
+ {
409
+ "type": "array",
410
+ "items": [
411
+ {
412
+ "$ref": "#/definitions/RuleLevel"
413
+ }
414
+ ],
415
+ "additionalItems": false,
416
+ "minItems": 1,
417
+ "maxItems": 1
418
+ },
419
+ {
420
+ "type": "array",
421
+ "items": [
422
+ {
423
+ "$ref": "#/definitions/RuleLevel"
424
+ },
425
+ {
426
+ "type": "object",
427
+ "properties": {
428
+ "minHitRatio": {
429
+ "default": 0.4,
430
+ "type": "number",
431
+ "minimum": 0,
432
+ "maximum": 1
433
+ },
434
+ "targetHitRatio": {
435
+ "default": 0.7,
436
+ "type": "number",
437
+ "minimum": 0,
438
+ "maximum": 1
439
+ },
440
+ "minTokens": {
441
+ "default": 1000000,
442
+ "type": "integer",
443
+ "exclusiveMinimum": 0,
444
+ "maximum": 9007199254740991
445
+ }
446
+ }
447
+ }
448
+ ],
449
+ "additionalItems": false,
450
+ "minItems": 2,
451
+ "maxItems": 2
452
+ }
453
+ ],
454
+ "description": "Keep the prompt cache warm. https://github.com/ponomarenko/ctxmedic/blob/main/docs/rules/FIN_CACHE_MISS.md"
455
+ }
456
+ },
457
+ "additionalProperties": false,
458
+ "description": "Rule levels and options: \"off\", \"on\", a severity, or [level, options]."
459
+ },
460
+ "ignores": {
461
+ "type": "array",
462
+ "items": {
463
+ "type": "string"
464
+ },
465
+ "description": "Globs over finding paths (project-relative, or ~/ for global files)."
466
+ }
467
+ },
468
+ "definitions": {
469
+ "RuleLevel": {
470
+ "anyOf": [
471
+ {
472
+ "type": "string",
473
+ "const": "off"
474
+ },
475
+ {
476
+ "type": "string",
477
+ "const": "on"
478
+ },
479
+ {
480
+ "type": "string",
481
+ "enum": [
482
+ "critical",
483
+ "warning",
484
+ "info"
485
+ ]
486
+ }
487
+ ],
488
+ "description": "\"off\", \"on\" (the rule picks the severity) or a severity to force"
489
+ }
490
+ }
491
+ }