sensemaking 0.7.2 → 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.
Files changed (207) hide show
  1. package/README.md +90 -61
  2. package/dist/cjs/cli/check.js +367 -0
  3. package/dist/cjs/cli/check.js.map +1 -0
  4. package/dist/cjs/{commands → cli}/index.js +2 -2
  5. package/dist/cjs/cli/index.js.map +1 -0
  6. package/dist/cjs/{commands → cli}/init.js +3 -0
  7. package/dist/cjs/cli/init.js.map +1 -0
  8. package/dist/cjs/{commands → cli}/map.js +2 -2
  9. package/dist/cjs/cli/map.js.map +1 -0
  10. package/dist/cjs/{commands → cli}/named.d.cts +1 -1
  11. package/dist/cjs/{commands → cli}/named.d.ts +1 -1
  12. package/dist/cjs/cli/named.js +219 -0
  13. package/dist/cjs/cli/named.js.map +1 -0
  14. package/dist/cjs/{commands → cli}/peek.js +2 -2
  15. package/dist/cjs/cli/peek.js.map +1 -0
  16. package/dist/cjs/cli/query.js.map +1 -0
  17. package/dist/cjs/cli/rebuild.js.map +1 -0
  18. package/dist/cjs/cli/search.d.cts +3 -0
  19. package/dist/cjs/cli/search.d.ts +3 -0
  20. package/dist/cjs/{commands/find.js → cli/search.js} +9 -8
  21. package/dist/cjs/cli/search.js.map +1 -0
  22. package/dist/cjs/{commands → cli}/shared.d.cts +1 -0
  23. package/dist/{esm/commands → cjs/cli}/shared.d.ts +1 -0
  24. package/dist/cjs/{commands → cli}/shared.js +9 -0
  25. package/dist/cjs/cli/shared.js.map +1 -0
  26. package/dist/cjs/{commands → cli}/status.js +36 -13
  27. package/dist/cjs/cli/status.js.map +1 -0
  28. package/dist/cjs/{commands → cli}/types.d.cts +3 -1
  29. package/dist/{esm/commands → cjs/cli}/types.d.ts +3 -1
  30. package/dist/cjs/cli/watch.js.map +1 -0
  31. package/dist/cjs/cli.js +42 -17
  32. package/dist/cjs/cli.js.map +1 -1
  33. package/dist/{esm/verbs.d.ts → cjs/commands.d.cts} +15 -5
  34. package/dist/cjs/{verbs.d.cts → commands.d.ts} +15 -5
  35. package/dist/cjs/{verbs.js → commands.js} +329 -39
  36. package/dist/cjs/commands.js.map +1 -0
  37. package/dist/cjs/config.d.cts +45 -12
  38. package/dist/cjs/config.d.ts +45 -12
  39. package/dist/cjs/config.js +464 -125
  40. package/dist/cjs/config.js.map +1 -1
  41. package/dist/cjs/db.d.cts +1 -1
  42. package/dist/cjs/db.d.ts +1 -1
  43. package/dist/cjs/db.js +293 -76
  44. package/dist/cjs/db.js.map +1 -1
  45. package/dist/cjs/errors.d.cts +1 -1
  46. package/dist/cjs/errors.d.ts +1 -1
  47. package/dist/cjs/errors.js.map +1 -1
  48. package/dist/cjs/features/embed.js +19 -3
  49. package/dist/cjs/features/embed.js.map +1 -1
  50. package/dist/cjs/features/links.js +201 -24
  51. package/dist/cjs/features/links.js.map +1 -1
  52. package/dist/cjs/features/rank.js +8 -1
  53. package/dist/cjs/features/rank.js.map +1 -1
  54. package/dist/cjs/features/types.d.cts +12 -4
  55. package/dist/cjs/features/types.d.ts +12 -4
  56. package/dist/cjs/index.d.cts +3 -3
  57. package/dist/cjs/index.d.ts +3 -3
  58. package/dist/cjs/index.js +9 -6
  59. package/dist/cjs/index.js.map +1 -1
  60. package/dist/cjs/output.d.cts +16 -0
  61. package/dist/cjs/output.d.ts +16 -0
  62. package/dist/cjs/output.js +27 -5
  63. package/dist/cjs/output.js.map +1 -1
  64. package/dist/cjs/progress.d.cts +5 -0
  65. package/dist/cjs/progress.d.ts +5 -0
  66. package/dist/cjs/progress.js +54 -0
  67. package/dist/cjs/progress.js.map +1 -0
  68. package/dist/cjs/scan.d.cts +4 -0
  69. package/dist/cjs/scan.d.ts +4 -0
  70. package/dist/cjs/scan.js +87 -6
  71. package/dist/cjs/scan.js.map +1 -1
  72. package/dist/esm/{commands → cli}/check.js +41 -22
  73. package/dist/esm/cli/check.js.map +1 -0
  74. package/dist/esm/{commands → cli}/index.js +1 -1
  75. package/dist/esm/cli/index.js.map +1 -0
  76. package/dist/esm/{commands → cli}/init.js +3 -0
  77. package/dist/esm/cli/init.js.map +1 -0
  78. package/dist/esm/{commands → cli}/map.js +1 -1
  79. package/dist/esm/cli/map.js.map +1 -0
  80. package/dist/esm/{commands → cli}/named.d.ts +1 -1
  81. package/dist/esm/cli/named.js +41 -0
  82. package/dist/esm/cli/named.js.map +1 -0
  83. package/dist/esm/{commands → cli}/peek.js +1 -1
  84. package/dist/esm/cli/peek.js.map +1 -0
  85. package/dist/esm/cli/query.js.map +1 -0
  86. package/dist/esm/cli/rebuild.js.map +1 -0
  87. package/dist/esm/cli/search.d.ts +3 -0
  88. package/dist/esm/cli/search.js +16 -0
  89. package/dist/esm/cli/search.js.map +1 -0
  90. package/dist/{cjs/commands → esm/cli}/shared.d.ts +1 -0
  91. package/dist/esm/{commands → cli}/shared.js +9 -0
  92. package/dist/esm/cli/shared.js.map +1 -0
  93. package/dist/esm/{commands → cli}/status.js +17 -11
  94. package/dist/esm/cli/status.js.map +1 -0
  95. package/dist/{cjs/commands → esm/cli}/types.d.ts +3 -1
  96. package/dist/esm/cli/types.js.map +1 -0
  97. package/dist/esm/cli/watch.js.map +1 -0
  98. package/dist/esm/cli.js +24 -6
  99. package/dist/esm/cli.js.map +1 -1
  100. package/dist/{cjs/verbs.d.ts → esm/commands.d.ts} +15 -5
  101. package/dist/esm/commands.js +386 -0
  102. package/dist/esm/commands.js.map +1 -0
  103. package/dist/esm/config.d.ts +45 -12
  104. package/dist/esm/config.js +367 -93
  105. package/dist/esm/config.js.map +1 -1
  106. package/dist/esm/db.d.ts +1 -1
  107. package/dist/esm/db.js +126 -17
  108. package/dist/esm/db.js.map +1 -1
  109. package/dist/esm/errors.d.ts +1 -1
  110. package/dist/esm/errors.js.map +1 -1
  111. package/dist/esm/features/embed.js +18 -2
  112. package/dist/esm/features/embed.js.map +1 -1
  113. package/dist/esm/features/links.js +130 -20
  114. package/dist/esm/features/links.js.map +1 -1
  115. package/dist/esm/features/rank.js +8 -1
  116. package/dist/esm/features/rank.js.map +1 -1
  117. package/dist/esm/features/types.d.ts +12 -4
  118. package/dist/esm/features/types.js.map +1 -1
  119. package/dist/esm/index.d.ts +3 -3
  120. package/dist/esm/index.js +1 -1
  121. package/dist/esm/index.js.map +1 -1
  122. package/dist/esm/output.d.ts +16 -0
  123. package/dist/esm/output.js +20 -5
  124. package/dist/esm/output.js.map +1 -1
  125. package/dist/esm/progress.d.ts +5 -0
  126. package/dist/esm/progress.js +44 -0
  127. package/dist/esm/progress.js.map +1 -0
  128. package/dist/esm/scan.d.ts +4 -0
  129. package/dist/esm/scan.js +37 -6
  130. package/dist/esm/scan.js.map +1 -1
  131. package/package.json +12 -2
  132. package/schema.json +85 -50
  133. package/skills/sense/EXAMPLES.md +16 -12
  134. package/skills/sense/SKILL.md +74 -55
  135. package/skills/sense-setup/EXAMPLES.md +121 -0
  136. package/skills/sense-setup/SKILL.md +73 -54
  137. package/dist/cjs/commands/check.js +0 -143
  138. package/dist/cjs/commands/check.js.map +0 -1
  139. package/dist/cjs/commands/find.d.cts +0 -3
  140. package/dist/cjs/commands/find.d.ts +0 -3
  141. package/dist/cjs/commands/find.js.map +0 -1
  142. package/dist/cjs/commands/index.js.map +0 -1
  143. package/dist/cjs/commands/init.js.map +0 -1
  144. package/dist/cjs/commands/map.js.map +0 -1
  145. package/dist/cjs/commands/named.js +0 -23
  146. package/dist/cjs/commands/named.js.map +0 -1
  147. package/dist/cjs/commands/peek.js.map +0 -1
  148. package/dist/cjs/commands/query.js.map +0 -1
  149. package/dist/cjs/commands/rebuild.js.map +0 -1
  150. package/dist/cjs/commands/shared.js.map +0 -1
  151. package/dist/cjs/commands/status.js.map +0 -1
  152. package/dist/cjs/commands/watch.js.map +0 -1
  153. package/dist/cjs/verbs.js.map +0 -1
  154. package/dist/esm/commands/check.js.map +0 -1
  155. package/dist/esm/commands/find.d.ts +0 -3
  156. package/dist/esm/commands/find.js +0 -15
  157. package/dist/esm/commands/find.js.map +0 -1
  158. package/dist/esm/commands/index.js.map +0 -1
  159. package/dist/esm/commands/init.js.map +0 -1
  160. package/dist/esm/commands/map.js.map +0 -1
  161. package/dist/esm/commands/named.js +0 -12
  162. package/dist/esm/commands/named.js.map +0 -1
  163. package/dist/esm/commands/peek.js.map +0 -1
  164. package/dist/esm/commands/query.js.map +0 -1
  165. package/dist/esm/commands/rebuild.js.map +0 -1
  166. package/dist/esm/commands/shared.js.map +0 -1
  167. package/dist/esm/commands/status.js.map +0 -1
  168. package/dist/esm/commands/types.js.map +0 -1
  169. package/dist/esm/commands/watch.js.map +0 -1
  170. package/dist/esm/verbs.js +0 -190
  171. package/dist/esm/verbs.js.map +0 -1
  172. /package/dist/cjs/{commands → cli}/check.d.cts +0 -0
  173. /package/dist/cjs/{commands → cli}/check.d.ts +0 -0
  174. /package/dist/cjs/{commands → cli}/index.d.cts +0 -0
  175. /package/dist/cjs/{commands → cli}/index.d.ts +0 -0
  176. /package/dist/cjs/{commands → cli}/init.d.cts +0 -0
  177. /package/dist/cjs/{commands → cli}/init.d.ts +0 -0
  178. /package/dist/cjs/{commands → cli}/map.d.cts +0 -0
  179. /package/dist/cjs/{commands → cli}/map.d.ts +0 -0
  180. /package/dist/cjs/{commands → cli}/peek.d.cts +0 -0
  181. /package/dist/cjs/{commands → cli}/peek.d.ts +0 -0
  182. /package/dist/cjs/{commands → cli}/query.d.cts +0 -0
  183. /package/dist/cjs/{commands → cli}/query.d.ts +0 -0
  184. /package/dist/cjs/{commands → cli}/query.js +0 -0
  185. /package/dist/cjs/{commands → cli}/rebuild.d.cts +0 -0
  186. /package/dist/cjs/{commands → cli}/rebuild.d.ts +0 -0
  187. /package/dist/cjs/{commands → cli}/rebuild.js +0 -0
  188. /package/dist/cjs/{commands → cli}/status.d.cts +0 -0
  189. /package/dist/cjs/{commands → cli}/status.d.ts +0 -0
  190. /package/dist/cjs/{commands → cli}/types.js +0 -0
  191. /package/dist/cjs/{commands → cli}/types.js.map +0 -0
  192. /package/dist/cjs/{commands → cli}/watch.d.cts +0 -0
  193. /package/dist/cjs/{commands → cli}/watch.d.ts +0 -0
  194. /package/dist/cjs/{commands → cli}/watch.js +0 -0
  195. /package/dist/esm/{commands → cli}/check.d.ts +0 -0
  196. /package/dist/esm/{commands → cli}/index.d.ts +0 -0
  197. /package/dist/esm/{commands → cli}/init.d.ts +0 -0
  198. /package/dist/esm/{commands → cli}/map.d.ts +0 -0
  199. /package/dist/esm/{commands → cli}/peek.d.ts +0 -0
  200. /package/dist/esm/{commands → cli}/query.d.ts +0 -0
  201. /package/dist/esm/{commands → cli}/query.js +0 -0
  202. /package/dist/esm/{commands → cli}/rebuild.d.ts +0 -0
  203. /package/dist/esm/{commands → cli}/rebuild.js +0 -0
  204. /package/dist/esm/{commands → cli}/status.d.ts +0 -0
  205. /package/dist/esm/{commands → cli}/types.js +0 -0
  206. /package/dist/esm/{commands → cli}/watch.d.ts +0 -0
  207. /package/dist/esm/{commands → cli}/watch.js +0 -0
@@ -4,34 +4,49 @@ import { SenseError } from './errors.js';
4
4
  export const CONFIG_FILENAME = 'sense.config.json';
5
5
  export const STATE_DIR = '.sense';
6
6
  // Highest sense.config.json `version` this build understands. Older versions auto-migrate on load.
7
- export const SUPPORTED_CONFIG_VERSION = 2;
8
- // Each feature owns its tables, parse-time extraction, and reconcile step; verbs degrade when one is off.
9
- // links/sections/rank are opt-out (absent = on); embed is opt-in (absent = off) -- most trees don't need vectors.
7
+ export const SUPPORTED_CONFIG_VERSION = 3;
8
+ // Each feature owns its tables, parse-time extraction, and reconcile step; commands degrade when one is off.
9
+ // links/sections/rank are opt-out toggles in the top-level `features` block; embed is not a
10
+ // member of that block -- it is derived from whether any declared preset has semantic on.
10
11
  const FEATURE_NAMES = [
11
12
  'links',
12
13
  'sections',
13
14
  'rank',
14
15
  'embed'
15
16
  ];
16
- const OPT_OUT_NAMES = [
17
+ // v1 -> v2 migration only: the features v2 introduced as opt-out (embed was opt-in then).
18
+ const V2_OPT_OUT_NAMES = [
17
19
  'links',
18
20
  'sections',
19
21
  'rank'
20
22
  ];
21
23
  export const DEFAULT_EMBED_MODEL = 'minishlab/potion-retrieval-32M';
22
- // Opt-out features: absent block or key means enabled. `rank` additionally requires `links`.
23
- // `embed` is the opposite: enabled only when the config says so.
24
+ export function presetNames(cfg) {
25
+ return Object.keys(cfg.presets);
26
+ }
27
+ // A preset's own resolved vector participation: absent or true means on, false means off.
28
+ export function presetSemanticEnabled(cfg, name) {
29
+ var _cfg_presets_name;
30
+ return ((_cfg_presets_name = cfg.presets[name]) === null || _cfg_presets_name === void 0 ? void 0 : _cfg_presets_name.semantic) !== false;
31
+ }
32
+ // Whether embedding needs to run at all: true when at least one declared preset wants vectors.
33
+ export function anyPresetEmbeds(cfg) {
34
+ return presetNames(cfg).some((name)=>presetSemanticEnabled(cfg, name));
35
+ }
36
+ // Opt-out features (default on): absent block or key means enabled. `rank` additionally
37
+ // requires `links`. `embed` is derived, not a features-block member: on iff any declared
38
+ // preset has semantic on.
24
39
  export function featureEnabled(cfg, name) {
25
- var _cfg_features, _cfg_features1;
26
- if (name === 'embed') return Boolean((_cfg_features = cfg.features) === null || _cfg_features === void 0 ? void 0 : _cfg_features.embed);
27
- const enabled = ((_cfg_features1 = cfg.features) === null || _cfg_features1 === void 0 ? void 0 : _cfg_features1[name]) !== false;
40
+ var _cfg_features;
41
+ if (name === 'embed') return anyPresetEmbeds(cfg);
42
+ const enabled = ((_cfg_features = cfg.features) === null || _cfg_features === void 0 ? void 0 : _cfg_features[name]) !== false;
28
43
  if (name === 'rank') return enabled && featureEnabled(cfg, 'links');
29
44
  return enabled;
30
45
  }
31
46
  export function enabledFeatures(cfg) {
32
47
  return FEATURE_NAMES.filter((name)=>featureEnabled(cfg, name));
33
48
  }
34
- // Every feature with its current state; verbs surface this so "off" and "empty" stay
49
+ // Every feature with its current state; commands surface this so "off" and "empty" stay
35
50
  // distinguishable in output.
36
51
  export function featureStates(cfg) {
37
52
  return {
@@ -39,40 +54,158 @@ export function featureStates(cfg) {
39
54
  off: FEATURE_NAMES.filter((name)=>!featureEnabled(cfg, name))
40
55
  };
41
56
  }
42
- // Resolved embed settings, or null when the feature is off.
57
+ // Resolved embed provider settings, or null when no preset wants embeddings at all.
43
58
  export function embedConfig(cfg) {
44
- var _o_model, _o_type;
45
- var _cfg_features;
46
- const e = (_cfg_features = cfg.features) === null || _cfg_features === void 0 ? void 0 : _cfg_features.embed;
47
- if (!e) return null;
48
- const o = e === true ? {} : e;
59
+ var _cfg_embed, _e_model, _e_type;
60
+ if (!anyPresetEmbeds(cfg)) return null;
61
+ const e = (_cfg_embed = cfg.embed) !== null && _cfg_embed !== void 0 ? _cfg_embed : {};
49
62
  return {
50
- model: (_o_model = o.model) !== null && _o_model !== void 0 ? _o_model : DEFAULT_EMBED_MODEL,
51
- type: (_o_type = o.type) !== null && _o_type !== void 0 ? _o_type : 'static',
52
- url: o.url,
53
- key: o.key
63
+ model: (_e_model = e.model) !== null && _e_model !== void 0 ? _e_model : DEFAULT_EMBED_MODEL,
64
+ type: (_e_type = e.type) !== null && _e_type !== void 0 ? _e_type : 'static',
65
+ url: e.url,
66
+ key: e.key
54
67
  };
55
68
  }
56
- // Cache-key string: embed carries its type + model so a model change rebuilds like a toggle.
69
+ // Cache-key string: embed carries its type + model so a model change rebuilds like a toggle,
70
+ // and every declared preset carries its include/exclude/semantic so an edit to any of those
71
+ // rebuilds too -- indexing and embedding are both derived from presets, so any change to the
72
+ // derivation inputs must invalidate the cache.
57
73
  export function featureSignature(cfg) {
58
- return enabledFeatures(cfg).map((name)=>{
59
- if (name !== 'embed') return name;
60
- const e = embedConfig(cfg);
61
- return `embed:${e === null || e === void 0 ? void 0 : e.type}:${e === null || e === void 0 ? void 0 : e.model}`;
62
- }).join(',');
74
+ const globalPart = enabledFeatures(cfg).filter((name)=>name !== 'embed').join(',');
75
+ const e = embedConfig(cfg);
76
+ const embedPart = e ? `embed:${e.type}:${e.model}` : 'embed:off';
77
+ // One keyed segment per preset so a rebuild notice can name exactly which preset moved.
78
+ const presetsPart = [
79
+ ...presetNames(cfg)
80
+ ].sort().map((name)=>{
81
+ var _p_exclude;
82
+ const p = cfg.presets[name];
83
+ const include = [
84
+ ...p.include
85
+ ].sort().join('+');
86
+ const exclude = [
87
+ ...(_p_exclude = p.exclude) !== null && _p_exclude !== void 0 ? _p_exclude : []
88
+ ].sort().join('+');
89
+ return `preset:${name}:${include}:${exclude}:${p.semantic === false ? 'off' : 'on'}`;
90
+ }).join('|');
91
+ return [
92
+ `features:${globalPart}`,
93
+ embedPart,
94
+ presetsPart
95
+ ].join('|');
96
+ }
97
+ // Looks up a declared preset by name, defaulting to `default`. Throws naming every declared
98
+ // preset when an explicit name is not declared -- the `default` fallback is never unknown
99
+ // itself (validateConfig requires it).
100
+ export function resolvePreset(cfg, name) {
101
+ const presetName = name !== null && name !== void 0 ? name : 'default';
102
+ const preset = cfg.presets[presetName];
103
+ if (!preset) throw new SenseError('PRESET_UNKNOWN', `unknown preset "${presetName}"; declared presets: ${presetNames(cfg).join(', ')}`);
104
+ return {
105
+ name: presetName,
106
+ preset
107
+ };
108
+ }
109
+ // Resolution precedence: built-ins (k=10, semantic on, whole-index scope) <- named preset's
110
+ // fields (or `default` when none named) <- caller overrides. Each stage overrides only the
111
+ // fields it sets. `opts` here is expected to already carry whatever a saved query and an
112
+ // explicit CLI flag resolved between themselves (src/cli/named.ts does that `cli ?? saved`
113
+ // merge before calling in) -- one `??` per field composes the full four-stage chain, since
114
+ // `??` is associative field-by-field.
115
+ export function resolveSearch(cfg, opts = {}) {
116
+ var _ref, _opts_k, _opts_where, _opts_include;
117
+ const { name: presetName, preset } = resolvePreset(cfg, opts.preset);
118
+ const k = (_ref = (_opts_k = opts.k) !== null && _opts_k !== void 0 ? _opts_k : preset.k) !== null && _ref !== void 0 ? _ref : 10;
119
+ const where = (_opts_where = opts.where) !== null && _opts_where !== void 0 ? _opts_where : preset.where;
120
+ // An explicit include (CLI --include, or a saved search's own `include`) is a full ad hoc
121
+ // scope override -- it replaces the preset's include/exclude pair rather than layering on
122
+ // top of it, the same "replaces, doesn't AND" rule --where already uses.
123
+ const include = (_opts_include = opts.include) !== null && _opts_include !== void 0 ? _opts_include : preset.include;
124
+ const exclude = opts.include ? undefined : preset.exclude;
125
+ const semantic = opts.semantic !== undefined ? opts.semantic : preset.semantic !== false;
126
+ return {
127
+ presetName,
128
+ k,
129
+ where,
130
+ include,
131
+ exclude,
132
+ semantic
133
+ };
63
134
  }
64
135
  // Pure per-version steps; loadConfig chains them from the file's version up to SUPPORTED_CONFIG_VERSION.
136
+ // Intermediate shapes predate the current Config type (v1 has no features block, v2 has
137
+ // scan/find not presets/search), so steps work loosely-typed and only the final result is cast
138
+ // back to Config.
65
139
  const MIGRATIONS = {
66
140
  // v1 -> v2: features block introduced, opt-out features enabled (matches the old implicit
67
141
  // behavior of `links` etc. not existing). embed stays absent -- opt-in.
68
142
  1: (cfg)=>({
69
143
  ...cfg,
70
144
  version: 2,
71
- features: Object.fromEntries(OPT_OUT_NAMES.map((name)=>[
145
+ features: Object.fromEntries(V2_OPT_OUT_NAMES.map((name)=>[
72
146
  name,
73
147
  true
74
148
  ]))
75
- })
149
+ }),
150
+ // v2 -> v3: mechanical-minimal, by decision -- only what keeps an existing config loading.
151
+ // No restructuring, no preset inference, no query rewriting; real trees get hand-migrated
152
+ // separately to actually use presets.
153
+ 2: (cfg)=>{
154
+ var _prevDefaults_find;
155
+ const { scan, defaults, features, checks, queries, ...rest } = cfg;
156
+ const scanInclude = scan.include;
157
+ const nextQueries = {};
158
+ for (const [name, value] of Object.entries(queries !== null && queries !== void 0 ? queries : {})){
159
+ if (typeof value === 'string') {
160
+ nextQueries[name] = value;
161
+ continue;
162
+ }
163
+ const entry = value;
164
+ const search = {
165
+ search: entry.find
166
+ };
167
+ if (entry.k !== undefined) search.k = entry.k;
168
+ if (entry.where !== undefined) search.where = entry.where;
169
+ // semantic: true was opt-in; it is now the default, so it drops. semantic: false is kept.
170
+ if (entry.semantic === false) search.semantic = false;
171
+ nextQueries[name] = search;
172
+ }
173
+ const prevDefaults = defaults;
174
+ const defaultWhere = prevDefaults === null || prevDefaults === void 0 ? void 0 : (_prevDefaults_find = prevDefaults.find) === null || _prevDefaults_find === void 0 ? void 0 : _prevDefaults_find.where;
175
+ // features.embed: true/absent -> simply removed (v3 default is on). An explicit `false`
176
+ // becomes semantic: false on every preset this migration produces -- there is only ever
177
+ // one (`default`), since v2 has no notion of multiple scopes, but the rule is written to
178
+ // apply to "every migrated preset" rather than hardcoded to `default` in case a later
179
+ // migration step ever produces more than one.
180
+ const prevFeatures = features !== null && features !== void 0 ? features : {};
181
+ const embedWasOff = prevFeatures.embed === false;
182
+ // Object form carried provider settings (model/type/url/key), not a toggle -- they move
183
+ // to the v3 top-level `embed` block verbatim; dropping them would silently switch an
184
+ // api tree back to the built-in static model.
185
+ const embedProvider = typeof prevFeatures.embed === 'object' && prevFeatures.embed !== null ? prevFeatures.embed : undefined;
186
+ const { embed: _embed, ...restFeatures } = prevFeatures;
187
+ const defaultPreset = {
188
+ include: scanInclude
189
+ };
190
+ if (defaultWhere !== undefined) defaultPreset.where = defaultWhere;
191
+ if (embedWasOff) defaultPreset.semantic = false;
192
+ // checks (assertions over saved queries) was removed in v3; its queries still run under
193
+ // `queries`, just without the pass/fail assertion -- reachable now only as a saved query.
194
+ if (checks !== undefined) {
195
+ console.error('sense: v2 "checks" was removed in v3 (sense check no longer asserts on saved queries); its queries are carried over under "queries" -- a returned row set is now the reader\'s judgment');
196
+ }
197
+ const result = {
198
+ ...rest,
199
+ version: 3,
200
+ presets: {
201
+ default: defaultPreset
202
+ },
203
+ queries: nextQueries
204
+ };
205
+ if (embedProvider !== undefined) result.embed = embedProvider;
206
+ if (Object.keys(restFeatures).length > 0) result.features = restFeatures;
207
+ return result;
208
+ }
76
209
  };
77
210
  export function migrateConfig(cfg) {
78
211
  var _cfg_version;
@@ -92,15 +225,20 @@ function starterConfig() {
92
225
  return {
93
226
  $schema: 'https://unpkg.com/sensemaking/schema.json',
94
227
  version: SUPPORTED_CONFIG_VERSION,
95
- scan: {
96
- include: [
97
- '**/*.md'
98
- ]
228
+ presets: {
229
+ default: {
230
+ include: [
231
+ '**/*.md'
232
+ ],
233
+ k: 10
234
+ },
235
+ large: {
236
+ include: [
237
+ '**/*.md'
238
+ ],
239
+ k: 20
240
+ }
99
241
  },
100
- features: Object.fromEntries(OPT_OUT_NAMES.map((name)=>[
101
- name,
102
- true
103
- ])),
104
242
  queries: {}
105
243
  };
106
244
  }
@@ -125,80 +263,202 @@ export function findConfigPath(startDir) {
125
263
  }
126
264
  // Shape check for hand-edited files: a typo'd config fails with a named error, not a
127
265
  // TypeError from whatever code touched the missing field first. `queries` is optional
128
- // on disk (absent = none); `scan.include` has no usable default.
129
- // Keys each block actually reads. A key outside these sets is accepted and ignored, which
130
- // looks identical to working -- one field report set `scan.exclude`, saw no change in doc
131
- // count and no warning, and reasonably concluded the filter had applied. Reported as a
132
- // warning rather than an error so a config carrying an unknown key still runs.
266
+ // on disk (absent = none); `presets` has no usable default.
267
+ // Unknown top-level keys are reported as a soft warning (cli.ts prints it) rather than an
268
+ // error, so a config carrying a stray field still runs -- but unknown keys inside a preset,
269
+ // features, embed, or saved-query block are hard errors: those blocks are small and fully
270
+ // owned, so a typo there is far more likely a mistake than a forward-compat field.
133
271
  const KNOWN_KEYS = new Set([
134
272
  '$schema',
135
273
  'version',
136
- 'scan',
274
+ 'presets',
137
275
  'features',
138
- 'defaults',
139
- 'checks',
276
+ 'embed',
140
277
  'queries'
141
278
  ]);
142
- const KNOWN_SCAN_KEYS = new Set([
143
- 'include'
279
+ const KNOWN_PRESET_KEYS = new Set([
280
+ 'include',
281
+ 'exclude',
282
+ 'k',
283
+ 'semantic',
284
+ 'where'
285
+ ]);
286
+ const KNOWN_FEATURE_KEYS = new Set([
287
+ 'links',
288
+ 'sections',
289
+ 'rank'
290
+ ]);
291
+ const KNOWN_EMBED_KEYS = new Set([
292
+ 'model',
293
+ 'type',
294
+ 'url',
295
+ 'key'
296
+ ]);
297
+ const SAVED_SEARCH_KEYS = new Set([
298
+ 'search',
299
+ 'preset',
300
+ 'include',
301
+ 'where',
302
+ 'k',
303
+ 'semantic'
144
304
  ]);
145
305
  function unknownConfigKeys(cfg) {
146
- const unknown = Object.keys(cfg).filter((k)=>!KNOWN_KEYS.has(k)).map((k)=>k);
147
- const scan = cfg.scan;
148
- if (scan && typeof scan === 'object' && !Array.isArray(scan)) {
149
- unknown.push(...Object.keys(scan).filter((k)=>!KNOWN_SCAN_KEYS.has(k)).map((k)=>`scan.${k}`));
306
+ return Object.keys(cfg).filter((k)=>!KNOWN_KEYS.has(k));
307
+ }
308
+ function isNonEmptyStringArray(value) {
309
+ return Array.isArray(value) && value.length > 0 && value.every((g)=>typeof g === 'string' && g.length > 0);
310
+ }
311
+ // Pre-v3 shape check, just enough for migrateConfig to run safely (it reads scan.include
312
+ // directly). The full v3 shape is checked by validateConfig once migration has produced it.
313
+ function validateLegacyScan(parsed, configPath) {
314
+ const cfg = typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) ? parsed : null;
315
+ const scan = cfg === null || cfg === void 0 ? void 0 : cfg.scan;
316
+ if (!cfg || !scan || !isNonEmptyStringArray(scan.include)) {
317
+ throw new SenseError('CONFIG_INVALID', `${configPath}: scan.include must be a non-empty array of glob strings`);
318
+ }
319
+ }
320
+ function validateFeaturesBlock(value, configPath) {
321
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
322
+ throw new SenseError('CONFIG_INVALID', `${configPath}: features must be an object of name -> boolean`);
323
+ }
324
+ const block = value;
325
+ const unknown = Object.keys(block).filter((k)=>!KNOWN_FEATURE_KEYS.has(k));
326
+ if (unknown.length > 0) {
327
+ throw new SenseError('CONFIG_INVALID', `${configPath}: features has unknown key(s) ${unknown.join(', ')}; embed is not a features key -- see the top-level "embed" block and each preset's "semantic"`);
328
+ }
329
+ for (const [name, v] of Object.entries(block)){
330
+ if (typeof v !== 'boolean') {
331
+ throw new SenseError('CONFIG_INVALID', `${configPath}: features.${name} must be a boolean`);
332
+ }
333
+ }
334
+ }
335
+ function validateEmbedBlock(value, configPath) {
336
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
337
+ throw new SenseError('CONFIG_INVALID', `${configPath}: embed must be an object of { model?, type?: "static"|"api", url?, key? }`);
338
+ }
339
+ const embed = value;
340
+ const unknown = Object.keys(embed).filter((k)=>!KNOWN_EMBED_KEYS.has(k));
341
+ if (unknown.length > 0) {
342
+ throw new SenseError('CONFIG_INVALID', `${configPath}: embed has unknown key(s) ${unknown.join(', ')}`);
343
+ }
344
+ if (embed.model !== undefined && typeof embed.model !== 'string') {
345
+ throw new SenseError('CONFIG_INVALID', `${configPath}: embed.model must be a string`);
346
+ }
347
+ if (embed.type !== undefined && embed.type !== 'static' && embed.type !== 'api') {
348
+ throw new SenseError('CONFIG_INVALID', `${configPath}: embed.type must be "static" or "api"`);
349
+ }
350
+ if (embed.url !== undefined && typeof embed.url !== 'string') {
351
+ throw new SenseError('CONFIG_INVALID', `${configPath}: embed.url must be a string`);
150
352
  }
151
- const features = cfg.features;
152
- if (features && typeof features === 'object' && !Array.isArray(features)) {
153
- unknown.push(...Object.keys(features).filter((k)=>!FEATURE_NAMES.includes(k)).map((k)=>`features.${k}`));
353
+ if (embed.key !== undefined && typeof embed.key !== 'string') {
354
+ throw new SenseError('CONFIG_INVALID', `${configPath}: embed.key must be a string`);
154
355
  }
155
- return unknown;
356
+ }
357
+ function validatePreset(name, value, configPath) {
358
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
359
+ throw new SenseError('CONFIG_INVALID', `${configPath}: presets.${name} must be an object`);
360
+ }
361
+ const preset = value;
362
+ const unknown = Object.keys(preset).filter((k)=>!KNOWN_PRESET_KEYS.has(k));
363
+ if (unknown.length > 0) {
364
+ throw new SenseError('CONFIG_INVALID', `${configPath}: presets.${name} has unknown key(s) ${unknown.join(', ')}; a preset takes include, exclude, k, semantic, where`);
365
+ }
366
+ if (!isNonEmptyStringArray(preset.include)) {
367
+ throw new SenseError('CONFIG_INVALID', `${configPath}: presets.${name}.include must be a non-empty array of glob strings`);
368
+ }
369
+ if (preset.exclude !== undefined && !isNonEmptyStringArray(preset.exclude)) {
370
+ throw new SenseError('CONFIG_INVALID', `${configPath}: presets.${name}.exclude must be a non-empty array of glob strings`);
371
+ }
372
+ if (preset.k !== undefined && (typeof preset.k !== 'number' || !Number.isInteger(preset.k) || preset.k <= 0)) {
373
+ throw new SenseError('CONFIG_INVALID', `${configPath}: presets.${name}.k must be a positive integer`);
374
+ }
375
+ if (preset.semantic !== undefined && typeof preset.semantic !== 'boolean') {
376
+ throw new SenseError('CONFIG_INVALID', `${configPath}: presets.${name}.semantic must be a boolean`);
377
+ }
378
+ if (preset.where !== undefined && typeof preset.where !== 'string') {
379
+ throw new SenseError('CONFIG_INVALID', `${configPath}: presets.${name}.where must be a SQL condition string`);
380
+ }
381
+ }
382
+ // A queries.<name> entry: a SQL string, { sql }, or a saved search { search, preset?, include?, where?, k?, semantic? }.
383
+ function validateSavedQuery(name, value, configPath) {
384
+ if (typeof value === 'string') return;
385
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
386
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name} must be a SQL string, { sql }, or { search, preset?, include?, where?, k?, semantic? }`);
387
+ }
388
+ const entry = value;
389
+ if ('sql' in entry) {
390
+ const unknown = Object.keys(entry).filter((k)=>k !== 'sql');
391
+ if (unknown.length > 0) {
392
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name} has unknown key(s) ${unknown.join(', ')}; a { sql } query takes only sql`);
393
+ }
394
+ if (typeof entry.sql !== 'string' || entry.sql.trim() === '') {
395
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name}.sql must be a non-empty string`);
396
+ }
397
+ return;
398
+ }
399
+ if ('search' in entry) {
400
+ const unknown = Object.keys(entry).filter((k)=>!SAVED_SEARCH_KEYS.has(k));
401
+ if (unknown.length > 0) {
402
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name} has unknown key(s) ${unknown.join(', ')}; a saved search takes search, preset, include, where, k, semantic`);
403
+ }
404
+ // A saved query saves a question; a scope without a question is just flags.
405
+ if (typeof entry.search !== 'string' || entry.search.trim() === '') {
406
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name}.search must be non-empty text`);
407
+ }
408
+ if (entry.preset !== undefined && (typeof entry.preset !== 'string' || entry.preset.length === 0)) {
409
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name}.preset must be a preset name`);
410
+ }
411
+ if (entry.include !== undefined && !isNonEmptyStringArray(entry.include)) {
412
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name}.include must be a non-empty array of glob strings`);
413
+ }
414
+ if (entry.where !== undefined && typeof entry.where !== 'string') {
415
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name}.where must be a SQL condition string`);
416
+ }
417
+ if (entry.k !== undefined && (typeof entry.k !== 'number' || !Number.isInteger(entry.k) || entry.k <= 0)) {
418
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name}.k must be a positive integer`);
419
+ }
420
+ if (entry.semantic !== undefined && typeof entry.semantic !== 'boolean') {
421
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name}.semantic must be a boolean`);
422
+ }
423
+ return;
424
+ }
425
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries.${name} must be a SQL string, { sql }, or { search, preset?, include?, where?, k?, semantic? }`);
156
426
  }
157
427
  function validateConfig(parsed, configPath) {
158
- var _cfg_features;
159
- var _defaults_find;
160
428
  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
161
429
  throw new SenseError('CONFIG_INVALID', `${configPath}: config must be a JSON object`);
162
430
  }
163
431
  const cfg = parsed;
164
- const scan = cfg.scan;
165
- if (!scan || !Array.isArray(scan.include) || scan.include.length === 0 || !scan.include.every((g)=>typeof g === 'string')) {
166
- throw new SenseError('CONFIG_INVALID', `${configPath}: scan.include must be a non-empty array of glob strings`);
432
+ // `checks` (assertions over saved queries) was removed in v3, not merely deprecated: a
433
+ // hand-written v3 config still carrying it gets a named rejection rather than a silent
434
+ // "unknown key" warning, since silence here would hide that the assertion behavior it
435
+ // implies no longer exists.
436
+ if (cfg.checks !== undefined) {
437
+ throw new SenseError('CONFIG_INVALID', `${configPath}: checks was removed in v3 -- sense check no longer asserts on saved queries; a returned row set is the reader's judgment`);
438
+ }
439
+ const presets = cfg.presets;
440
+ if (!presets || typeof presets !== 'object' || Array.isArray(presets) || Object.keys(presets).length === 0) {
441
+ throw new SenseError('CONFIG_INVALID', `${configPath}: presets must be a non-empty object of preset name -> { include, exclude?, k?, semantic?, where? }`);
442
+ }
443
+ for (const [name, value] of Object.entries(presets)){
444
+ validatePreset(name, value, configPath);
445
+ }
446
+ if (presets.default === undefined) {
447
+ throw new SenseError('CONFIG_INVALID', `${configPath}: presets must include a "default" preset`);
167
448
  }
168
449
  if (cfg.queries === undefined) cfg.queries = {};
169
- if (typeof cfg.queries !== 'object' || cfg.queries === null || Array.isArray(cfg.queries) || !Object.values(cfg.queries).every((q)=>typeof q === 'string')) {
170
- throw new SenseError('CONFIG_INVALID', `${configPath}: queries must be an object of name -> SQL string`);
171
- }
172
- const defaults = cfg.defaults;
173
- if (defaults !== undefined && (typeof defaults !== 'object' || defaults === null || Array.isArray(defaults) || defaults.find !== undefined && typeof ((_defaults_find = defaults.find) === null || _defaults_find === void 0 ? void 0 : _defaults_find.where) !== 'string')) {
174
- throw new SenseError('CONFIG_INVALID', `${configPath}: defaults.find.where must be a SQL condition string`);
175
- }
176
- const checks = cfg.checks;
177
- if (checks !== undefined) {
178
- var _cfg_queries;
179
- if (typeof checks !== 'object' || checks === null || Array.isArray(checks) || !Object.values(checks).every((v)=>v === 'empty')) {
180
- throw new SenseError('CONFIG_INVALID', `${configPath}: checks must be an object of query name -> "empty"`);
181
- }
182
- const queries = (_cfg_queries = cfg.queries) !== null && _cfg_queries !== void 0 ? _cfg_queries : {};
183
- for (const name of Object.keys(checks)){
184
- if (queries[name] === undefined) throw new SenseError('CONFIG_INVALID', `${configPath}: checks names "${name}", which is not a saved query`);
185
- }
450
+ if (typeof cfg.queries !== 'object' || cfg.queries === null || Array.isArray(cfg.queries)) {
451
+ throw new SenseError('CONFIG_INVALID', `${configPath}: queries must be an object of name -> SQL string, { sql }, or saved search`);
186
452
  }
187
- if (cfg.features !== undefined && (typeof cfg.features !== 'object' || cfg.features === null || Array.isArray(cfg.features))) {
188
- throw new SenseError('CONFIG_INVALID', `${configPath}: features must be an object of name -> boolean`);
453
+ const queries = cfg.queries;
454
+ for (const [name, value] of Object.entries(queries)){
455
+ validateSavedQuery(name, value, configPath);
189
456
  }
190
- for (const [name, value] of Object.entries((_cfg_features = cfg.features) !== null && _cfg_features !== void 0 ? _cfg_features : {})){
191
- if (typeof value === 'boolean') continue;
192
- // embed alone takes an object form: { model?, type?: static|api, url?, key? }.
193
- const embed = value;
194
- const shapeOk = name === 'embed' && typeof value === 'object' && value !== null && !Array.isArray(value) && [
195
- 'model',
196
- 'url',
197
- 'key'
198
- ].every((f)=>embed[f] === undefined || typeof embed[f] === 'string') && (embed.type === undefined || embed.type === 'static' || embed.type === 'api');
199
- if (!shapeOk) {
200
- throw new SenseError('CONFIG_INVALID', `${configPath}: features.${name} must be a boolean${name === 'embed' ? ' or { model?, type?: "static"|"api", url?, key? }' : ''}`);
201
- }
457
+ if (cfg.features !== undefined) {
458
+ validateFeaturesBlock(cfg.features, configPath);
459
+ }
460
+ if (cfg.embed !== undefined) {
461
+ validateEmbedBlock(cfg.embed, configPath);
202
462
  }
203
463
  return cfg;
204
464
  }
@@ -216,19 +476,33 @@ export function loadConfig(explicitPath) {
216
476
  }
217
477
  const raw = readFileSync(configPath, 'utf8');
218
478
  const parsed = JSON.parse(raw);
479
+ // Ahead of both the version gate and legacy/current shape checks: a non-object file (or
480
+ // an array -- typeof [] is also 'object') is malformed at every version, so it gets one
481
+ // error regardless of which branch would otherwise run.
482
+ if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
483
+ throw new SenseError('CONFIG_INVALID', `${configPath}: config must be a JSON object`);
484
+ }
219
485
  // Version gate before shape validation: a config written by a newer sense should fail
220
486
  // with "requires a newer sense", not with shape errors its own version may not have.
221
487
  const version = typeof parsed === 'object' && parsed !== null && typeof parsed.version === 'number' ? parsed.version : 1;
222
488
  if (version > SUPPORTED_CONFIG_VERSION) {
223
489
  throw new SenseError('CONFIG_VERSION_UNSUPPORTED', `config version ${version} requires a newer sense`);
224
490
  }
225
- let cfg = validateConfig(parsed, configPath);
491
+ // validateConfig only understands the current v3 shape (presets, saved-query object
492
+ // shapes); a pre-v3 file on disk is scan/find-shaped and must migrate before it can pass
493
+ // that check. Validate just enough of the old shape to migrate safely, migrate, then run
494
+ // the full v3 validateConfig on the migrated result -- the shape that actually lands on
495
+ // disk and in ResolvedConfig.
496
+ let cfg;
226
497
  let migratedFrom;
227
498
  if (version < SUPPORTED_CONFIG_VERSION) {
228
- const result = migrateConfig(cfg);
229
- cfg = result.cfg;
499
+ validateLegacyScan(parsed, configPath);
500
+ const result = migrateConfig(parsed);
501
+ cfg = validateConfig(result.cfg, configPath);
230
502
  migratedFrom = result.from;
231
503
  writeFileSync(configPath, `${JSON.stringify(cfg, null, 2)}\n`);
504
+ } else {
505
+ cfg = validateConfig(parsed, configPath);
232
506
  }
233
507
  const unknownKeys = unknownConfigKeys(cfg);
234
508
  return {