@rotorsoft/act-diagram 1.0.13 → 1.0.15

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/dist/cli/act.js CHANGED
@@ -817,6 +817,10 @@ function mock_state(entry, on_build) {
817
817
  // state from the parsed model.
818
818
  autocloses: () => action_builder(_currentAction),
819
819
  archives: () => action_builder(_currentAction),
820
+ // Disclosure predicate for `sensitive()` fields. Same reasoning as
821
+ // the close-policy methods above: the diagram doesn't render it, but
822
+ // the chain must survive or the whole state is dropped (#1394).
823
+ discloses: () => action_builder(_currentAction),
820
824
  build: () => {
821
825
  on_build?.(info);
822
826
  return info;
@@ -890,23 +894,34 @@ function mock_slice(on_build) {
890
894
  if (p) info.projections.push(p);
891
895
  return builder;
892
896
  },
897
+ // Lane declaration — the diagram doesn't render lanes, but the chain
898
+ // must survive or the slice is dropped (#1394).
899
+ withLane() {
900
+ return builder;
901
+ },
893
902
  on(event_name) {
903
+ const reaction_chain = (handler) => {
904
+ const dispatches = capture_dispatches(handler);
905
+ const reaction = {
906
+ event: event_name,
907
+ handlerName: typeof handler?.name === "string" && handler.name || `on ${event_name}`,
908
+ dispatches
909
+ };
910
+ info.reactions.push(reaction);
911
+ return {
912
+ ...builder,
913
+ to() {
914
+ return builder;
915
+ }
916
+ };
917
+ };
894
918
  return {
895
- do(handler) {
896
- const dispatches = capture_dispatches(handler);
897
- const reaction = {
898
- event: event_name,
899
- handlerName: typeof handler?.name === "string" && handler.name || `on ${event_name}`,
900
- dispatches
901
- };
902
- info.reactions.push(reaction);
903
- return {
904
- ...builder,
905
- to() {
906
- return builder;
907
- }
908
- };
909
- }
919
+ // `.defer(...)` sits between `.on(...)` and `.do(...)`; it only
920
+ // schedules, so the reaction is still recorded by `.do`.
921
+ defer() {
922
+ return { do: reaction_chain };
923
+ },
924
+ do: reaction_chain
910
925
  };
911
926
  },
912
927
  build: () => {
@@ -923,6 +938,26 @@ function mock_projection(target, on_build) {
923
938
  handles: []
924
939
  };
925
940
  const builder = {
941
+ // State-projection (fold) form: `projection(n).of(State, ...).flush(fn)`.
942
+ // The folded state's own events are what the projection handles, so
943
+ // record them from each passed state — that is what makes the
944
+ // projection show up as a consumer of those events (#1394).
945
+ of(...states) {
946
+ for (const st of states) {
947
+ const events = st?.events;
948
+ if (events)
949
+ for (const name of Object.keys(events)) {
950
+ if (!info.handles.includes(name)) info.handles.push(name);
951
+ }
952
+ }
953
+ return builder;
954
+ },
955
+ flush() {
956
+ return builder;
957
+ },
958
+ batch() {
959
+ return builder;
960
+ },
926
961
  on(event_entry) {
927
962
  const event_name = Object.keys(event_entry)[0];
928
963
  info.handles.push(event_name);
@@ -967,6 +1002,9 @@ function mock_act(on_build) {
967
1002
  return builder;
968
1003
  },
969
1004
  withActor: () => builder,
1005
+ // Lane declaration — not rendered, but the chain must survive or the
1006
+ // whole orchestrator is dropped from the model (#1394).
1007
+ withLane: () => builder,
970
1008
  on(event_name) {
971
1009
  return {
972
1010
  do(handler) {
@@ -1133,12 +1171,46 @@ function resolve(imp, from_path, by_key) {
1133
1171
 
1134
1172
  // src/client/lib/evaluate.ts
1135
1173
  var strip_non_code = (src, level = "full") => {
1136
- const blank = (m) => m.replace(/[^\n]/g, " ");
1137
- let result = src.replace(/\/\/[^\n]*/g, blank).replace(/\/\*[\s\S]*?\*\//g, blank).replace(/`(?:\\[\s\S]|[^`\\])*`/g, blank);
1138
- if (level === "full") {
1139
- result = result.replace(/"(?:\\[\s\S]|[^"\\])*"/g, blank).replace(/'(?:\\[\s\S]|[^'\\])*'/g, blank);
1174
+ const strip_strings = level === "full";
1175
+ let out = "";
1176
+ let i2 = 0;
1177
+ const blank = (from, to) => {
1178
+ out += src.slice(from, to).replace(/[^\n]/g, " ");
1179
+ };
1180
+ while (i2 < src.length) {
1181
+ const c2 = src[i2];
1182
+ const next = src[i2 + 1];
1183
+ if (c2 === "/" && next === "/") {
1184
+ const end = src.indexOf("\n", i2);
1185
+ const stop = end === -1 ? src.length : end;
1186
+ blank(i2, stop);
1187
+ i2 = stop;
1188
+ } else if (c2 === "/" && next === "*") {
1189
+ const end = src.indexOf("*/", i2 + 2);
1190
+ const stop = end === -1 ? src.length : end + 2;
1191
+ blank(i2, stop);
1192
+ i2 = stop;
1193
+ } else if (c2 === "`" || c2 === '"' || c2 === "'") {
1194
+ let j = i2 + 1;
1195
+ while (j < src.length) {
1196
+ if (src[j] === "\\") {
1197
+ j += 2;
1198
+ continue;
1199
+ }
1200
+ if (src[j] === c2) break;
1201
+ if (c2 !== "`" && src[j] === "\n") break;
1202
+ j++;
1203
+ }
1204
+ const stop = Math.min(j + 1, src.length);
1205
+ if (c2 === "`" || strip_strings) blank(i2, stop);
1206
+ else out += src.slice(i2, stop);
1207
+ i2 = stop;
1208
+ } else {
1209
+ out += c2;
1210
+ i2++;
1211
+ }
1140
1212
  }
1141
- return result;
1213
+ return out;
1142
1214
  };
1143
1215
  var is_source_file = (f) => f.path.endsWith(".ts") && !f.path.endsWith(".d.ts") && !f.path.endsWith(".tsx") && !f.path.endsWith(".spec.ts") && !f.path.endsWith(".test.ts") && !f.path.includes("node_modules/") && !f.path.includes("__tests__/") && !f.path.includes("/test/") && !f.path.startsWith("test/");
1144
1216
  function transpile(code) {
@@ -1288,9 +1360,15 @@ function extract_model(files) {
1288
1360
  }
1289
1361
 
1290
1362
  // src/cli/contract-index.ts
1363
+ function event_names_for(idx, state) {
1364
+ return (state ? idx.events_by_state.get(state) : void 0) ?? idx.all_event_names;
1365
+ }
1291
1366
  function decompose_event_name(name) {
1292
1367
  const m = name.match(/^(.+)_v(\d+)$/);
1293
- if (m) return { base: m[1], version: Number.parseInt(m[2], 10) };
1368
+ if (m) {
1369
+ const version = Number.parseInt(m[2], 10);
1370
+ if (version >= 2) return { base: m[1], version };
1371
+ }
1294
1372
  return { base: name, version: 1 };
1295
1373
  }
1296
1374
  function event_status(name, all_names) {
@@ -1310,6 +1388,7 @@ function event_status(name, all_names) {
1310
1388
  function build_contract_index(model) {
1311
1389
  const entries = [];
1312
1390
  const all_event_names = /* @__PURE__ */ new Set();
1391
+ const events_by_state = /* @__PURE__ */ new Map();
1313
1392
  for (const st of model.states) {
1314
1393
  entries.push({
1315
1394
  kind: "state",
@@ -1317,8 +1396,14 @@ function build_contract_index(model) {
1317
1396
  file: st.file,
1318
1397
  line: st.line
1319
1398
  });
1399
+ let own = events_by_state.get(st.name);
1400
+ if (!own) {
1401
+ own = /* @__PURE__ */ new Set();
1402
+ events_by_state.set(st.name, own);
1403
+ }
1320
1404
  for (const ev of st.events) {
1321
1405
  all_event_names.add(ev.name);
1406
+ own.add(ev.name);
1322
1407
  entries.push({
1323
1408
  kind: "event",
1324
1409
  name: ev.name,
@@ -1374,7 +1459,7 @@ function build_contract_index(model) {
1374
1459
  line: r2.line
1375
1460
  });
1376
1461
  }
1377
- return { entries, model, all_event_names };
1462
+ return { entries, model, all_event_names, events_by_state };
1378
1463
  }
1379
1464
  var CATEGORY_KEYWORDS = {
1380
1465
  event: "event",
@@ -1525,7 +1610,10 @@ function format_event(idx, entry) {
1525
1610
  }
1526
1611
  }
1527
1612
  const file = entry.file ?? owning_state?.file;
1528
- const status = event_status(entry.name, idx.all_event_names);
1613
+ const status = event_status(
1614
+ entry.name,
1615
+ event_names_for(idx, entry.qualifier)
1616
+ );
1529
1617
  const status_line = status.status === "active" ? green("active") : (
1530
1618
  // `superseded_by` is always set on deprecated entries — see event_status.
1531
1619
  `${red("deprecated")} (superseded by ${orange(status.superseded_by)})`
@@ -1603,23 +1691,39 @@ function format_action(idx, entry) {
1603
1691
  return lines.join("\n");
1604
1692
  }
1605
1693
  function format_state(idx, entry) {
1606
- const st = idx.model.states.find((s) => s.name === entry.name);
1694
+ const partials = idx.model.states.filter((s) => s.name === entry.name);
1607
1695
  const lines = [];
1608
1696
  lines.push(bold(amber(entry.name)));
1609
- if (entry.file) lines.push(` in: ${dim(loc(entry.file, entry.line))}`);
1610
- if (!st) return lines.join("\n");
1611
- if (st.actions.length > 0) {
1697
+ const files = [...new Set(partials.map((s) => s.file).filter(Boolean))];
1698
+ if (files.length > 1) {
1699
+ lines.push(" in:");
1700
+ for (const f of files) lines.push(` - ${dim(loc(f))}`);
1701
+ } else {
1702
+ const file = files[0] ?? entry.file;
1703
+ if (file) lines.push(` in: ${dim(loc(file, entry.line))}`);
1704
+ }
1705
+ if (!partials.length) return lines.join("\n");
1706
+ const show_file = files.length > 1;
1707
+ const actions = partials.flatMap(
1708
+ (s) => s.actions.map((a2) => ({ node: a2, file: s.file }))
1709
+ );
1710
+ if (actions.length > 0) {
1612
1711
  lines.push(" actions:");
1613
- for (const a2 of st.actions) {
1614
- const emits = a2.emits.length > 0 ? ` \u2192 ${a2.emits.join(", ")}` : "";
1615
- lines.push(` - ${pink(a2.name)}${emits}`);
1712
+ for (const { node, file } of actions) {
1713
+ const emits = node.emits.length > 0 ? ` \u2192 ${node.emits.join(", ")}` : "";
1714
+ const where = show_file && file ? ` ${dim(loc(file, node.line))}` : "";
1715
+ lines.push(` - ${pink(node.name)}${emits}${where}`);
1616
1716
  }
1617
1717
  }
1618
- if (st.events.length > 0) {
1718
+ const events = partials.flatMap(
1719
+ (s) => s.events.map((e) => ({ node: e, file: s.file }))
1720
+ );
1721
+ if (events.length > 0) {
1619
1722
  lines.push(" events:");
1620
- for (const e of st.events) {
1621
- const schema = e.schema ? ` ${dim(e.schema)}` : "";
1622
- lines.push(` - ${orange(e.name)}${schema}`);
1723
+ for (const { node, file } of events) {
1724
+ const schema = node.schema ? ` ${dim(node.schema)}` : "";
1725
+ const where = show_file && file ? ` ${dim(loc(file, node.line))}` : "";
1726
+ lines.push(` - ${orange(node.name)}${schema}${where}`);
1623
1727
  }
1624
1728
  }
1625
1729
  return lines.join("\n");
@@ -1632,8 +1736,10 @@ function format_slice(idx, entry) {
1632
1736
  if (!sl) return lines.join("\n");
1633
1737
  if (sl.error) lines.push(` ${red("error: " + sl.error)}`);
1634
1738
  if (sl.states.length > 0) {
1739
+ const by_var = new Map(idx.model.states.map((st) => [st.varName, st.name]));
1740
+ const names = [...new Set(sl.states.map((s) => by_var.get(s) ?? s))];
1635
1741
  lines.push(" states:");
1636
- for (const s of sl.states) lines.push(` - ${amber(s)}`);
1742
+ for (const s of names) lines.push(` - ${amber(s)}`);
1637
1743
  }
1638
1744
  if (sl.projections.length > 0) {
1639
1745
  lines.push(" projections:");
@@ -1785,7 +1891,7 @@ function format_json_schema(idx) {
1785
1891
  const events = {};
1786
1892
  for (const st of m.states) {
1787
1893
  for (const ev of st.events) {
1788
- const status = event_status(ev.name, idx.all_event_names);
1894
+ const status = event_status(ev.name, event_names_for(idx, st.name));
1789
1895
  const conv = toJsonSchemaSafe(ev.zod);
1790
1896
  const report = {
1791
1897
  name: ev.name,
@@ -1974,7 +2080,7 @@ function format_markdown(idx) {
1974
2080
  break;
1975
2081
  }
1976
2082
  }
1977
- const status = event_status(e.name, idx.all_event_names);
2083
+ const status = event_status(e.name, event_names_for(idx, owning_state));
1978
2084
  const status_label = status.status === "active" ? "active" : `deprecated \u2014 superseded by **${status.superseded_by}**`;
1979
2085
  lines.push(`### \`${e.name}\``);
1980
2086
  if (e.file) lines.push(`- **defined in:** \`${loc2(e.file, e.line)}\``);
@@ -3133,6 +3239,217 @@ ${r2}
3133
3239
  }
3134
3240
  }).prompt();
3135
3241
 
3242
+ // src/client/lib/navigate.ts
3243
+ function position_at(content, index) {
3244
+ const before = content.slice(0, index);
3245
+ const line = before.split("\n").length;
3246
+ const last_nl = before.lastIndexOf("\n");
3247
+ const col = index - (last_nl >= 0 ? last_nl : 0);
3248
+ return { line, col };
3249
+ }
3250
+ function build_patterns(esc, type) {
3251
+ const state_patterns = [new RegExp(`state\\(\\s*\\{\\s*(${esc})\\s*[}:,]`)];
3252
+ const action_patterns = [new RegExp(`\\.on\\(\\s*\\{\\s*(${esc})\\s*[},:]`)];
3253
+ const event_patterns = [
3254
+ // Match event name inside .emits({ EventName: ... }) — inline declaration
3255
+ new RegExp(`\\.emits\\([\\s\\S]*?(${esc})\\s*:`),
3256
+ // Match event name as key in a schema object: EventName: z.object(...)
3257
+ new RegExp(`(${esc})\\s*:\\s*z\\.object\\(`)
3258
+ ];
3259
+ const reaction_patterns = [
3260
+ // .do(handlerName) or .do(module.handlerName) — handler declaration in builder
3261
+ new RegExp(`\\.do\\(\\s*(?:\\w+\\.)?(${esc})\\b`),
3262
+ // inline function in .do()
3263
+ new RegExp(
3264
+ `\\.on\\(\\s*["'\`][^"'\`]+["'\`]\\s*\\)\\s*\\.do\\(\\s*(?:async\\s+)?function\\s+(${esc})\\b`
3265
+ ),
3266
+ // Fallback: function definition
3267
+ new RegExp(`(?:export\\s+)?async\\s+function\\s+(${esc})\\s*\\(`)
3268
+ ];
3269
+ const projection_patterns = [
3270
+ new RegExp(`(?:const|let|var)\\s+(${esc})\\s*=\\s*projection\\s*\\(`),
3271
+ new RegExp(`projection\\(\\s*["'\`](${esc})["'\`]`)
3272
+ ];
3273
+ const guard_patterns = [
3274
+ // Guard definition — prefer jumping to the declaration
3275
+ new RegExp(`(?:const|let|var)\\s+(${esc})\\s*(?::\\s*Invariant)?\\s*=`),
3276
+ new RegExp(`rule\\(\\s*["'\`](${esc})["'\`]`),
3277
+ new RegExp(`description:\\s*["'\`](${esc})["'\`]`),
3278
+ // .given() usage in the state builder — last resort
3279
+ new RegExp(`\\.given\\([\\s\\S]*?(${esc})`)
3280
+ ];
3281
+ const slice_patterns = [
3282
+ new RegExp(`(?:const|let|var)\\s+(${esc})\\s*=\\s*slice\\s*\\(`)
3283
+ ];
3284
+ const generic = [
3285
+ new RegExp(
3286
+ `(?:const|let|var)\\s+(${esc})\\s*=\\s*(?:state|slice|projection|act)\\s*\\(`
3287
+ ),
3288
+ new RegExp(`(?:const|let|var)\\s+(${esc})\\s*=`),
3289
+ new RegExp(`\\b(${esc})\\b`)
3290
+ ];
3291
+ switch (type) {
3292
+ case "state":
3293
+ return [...state_patterns, ...generic];
3294
+ case "action":
3295
+ return [...action_patterns, ...generic];
3296
+ case "event":
3297
+ return [...event_patterns, ...generic];
3298
+ case "reaction":
3299
+ return [...reaction_patterns, ...generic];
3300
+ case "projection":
3301
+ return [...projection_patterns, ...generic];
3302
+ case "guard":
3303
+ return [...guard_patterns, ...generic];
3304
+ default:
3305
+ return [
3306
+ ...slice_patterns,
3307
+ ...state_patterns,
3308
+ ...action_patterns,
3309
+ ...event_patterns,
3310
+ ...reaction_patterns,
3311
+ ...projection_patterns,
3312
+ ...guard_patterns,
3313
+ ...generic
3314
+ ];
3315
+ }
3316
+ }
3317
+ function navigate_to_code(files, name, type, target_file) {
3318
+ const stripped = /* @__PURE__ */ new Map();
3319
+ const code = (f) => {
3320
+ let c2 = stripped.get(f.path);
3321
+ if (c2 === void 0) {
3322
+ c2 = strip_non_code(f.content, "nav");
3323
+ stripped.set(f.path, c2);
3324
+ }
3325
+ return c2;
3326
+ };
3327
+ if (type === "file") {
3328
+ const file = files.find((f) => f.path === name || f.path.endsWith(name));
3329
+ if (file) {
3330
+ const act_match = /\bact\s*\(\s*\)/.exec(code(file));
3331
+ if (act_match) {
3332
+ const { line, col } = position_at(file.content, act_match.index);
3333
+ return { file: file.path, line, col };
3334
+ }
3335
+ return { file: file.path, line: 1, col: 1 };
3336
+ }
3337
+ return void 0;
3338
+ }
3339
+ if (target_file) {
3340
+ const file = files.find((f) => f.path === target_file);
3341
+ if (file) {
3342
+ const c2 = code(file);
3343
+ const esc2 = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3344
+ if (type === "event") {
3345
+ const emits_block_re = new RegExp(
3346
+ `\\.emits\\([\\s\\S]*?(${esc2})\\s*[,:}]`
3347
+ );
3348
+ const block_match = emits_block_re.exec(c2);
3349
+ if (block_match) {
3350
+ const name_idx = block_match.index + block_match[0].lastIndexOf(name);
3351
+ const { line, col } = position_at(file.content, name_idx);
3352
+ return { file: file.path, line, col };
3353
+ }
3354
+ const name_re2 = new RegExp(`\\b${esc2}\\b`, "g");
3355
+ if (name_re2.exec(c2)) {
3356
+ const emits_match = /\.emits\s*\(/.exec(c2);
3357
+ if (emits_match) {
3358
+ const { line, col } = position_at(
3359
+ file.content,
3360
+ emits_match.index + 1
3361
+ );
3362
+ return { file: file.path, line, col };
3363
+ }
3364
+ }
3365
+ }
3366
+ if (type === "guard") {
3367
+ const desc_re = new RegExp(`description:\\s*["'\`]${esc2}["'\`]`);
3368
+ const desc_match = desc_re.exec(c2);
3369
+ if (desc_match) {
3370
+ const before = c2.slice(0, desc_match.index);
3371
+ const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
3372
+ let last_decl = null;
3373
+ let m;
3374
+ while ((m = decl_re.exec(before)) !== null) {
3375
+ last_decl = m;
3376
+ }
3377
+ if (last_decl) {
3378
+ const name_idx = last_decl.index + last_decl[0].indexOf(last_decl[1]);
3379
+ const { line: line2, col: col2 } = position_at(file.content, name_idx);
3380
+ return { file: file.path, line: line2, col: col2 };
3381
+ }
3382
+ const { line, col } = position_at(file.content, desc_match.index);
3383
+ return { file: file.path, line, col };
3384
+ }
3385
+ }
3386
+ if (type === "action") {
3387
+ const name_re2 = new RegExp(`\\b${esc2}\\b`, "g");
3388
+ const block_start = c2.indexOf(".on(");
3389
+ if (block_start >= 0) {
3390
+ name_re2.lastIndex = block_start;
3391
+ const match2 = name_re2.exec(c2);
3392
+ if (match2) {
3393
+ const { line, col } = position_at(file.content, match2.index);
3394
+ return { file: file.path, line, col };
3395
+ }
3396
+ }
3397
+ }
3398
+ const name_re = new RegExp(`\\b${esc2}\\b`);
3399
+ const match = name_re.exec(c2);
3400
+ if (match) {
3401
+ const { line, col } = position_at(file.content, match.index);
3402
+ return { file: file.path, line, col };
3403
+ }
3404
+ }
3405
+ return void 0;
3406
+ }
3407
+ const esc = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3408
+ const is_test_file = (p) => /(?:\.spec\.|\.test\.|__tests__)/.test(p) || /\/test\//.test(p);
3409
+ const sorted_files = [...files].sort(
3410
+ (a2, b) => (is_test_file(a2.path) ? 1 : 0) - (is_test_file(b.path) ? 1 : 0)
3411
+ );
3412
+ if (type === "guard") {
3413
+ const desc_re = new RegExp(`description:\\s*["'\`]${esc}["'\`]`);
3414
+ for (const f of sorted_files) {
3415
+ if (!/\.tsx?$/.test(f.path)) continue;
3416
+ const c2 = code(f);
3417
+ const desc_match = desc_re.exec(c2);
3418
+ if (desc_match) {
3419
+ const before = c2.slice(0, desc_match.index);
3420
+ const decl_re = /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::\s*Invariant[^=]*)?\s*=/g;
3421
+ let last_decl = null;
3422
+ let m;
3423
+ while ((m = decl_re.exec(before)) !== null) last_decl = m;
3424
+ if (last_decl) {
3425
+ const name_idx = last_decl.index + last_decl[0].indexOf(last_decl[1]);
3426
+ const { line: line2, col: col2 } = position_at(f.content, name_idx);
3427
+ return { file: f.path, line: line2, col: col2 };
3428
+ }
3429
+ const { line, col } = position_at(f.content, desc_match.index);
3430
+ return { file: f.path, line, col };
3431
+ }
3432
+ }
3433
+ }
3434
+ const patterns = build_patterns(esc, type);
3435
+ for (const re of patterns) {
3436
+ for (const f of sorted_files) {
3437
+ if (!/\.tsx?$/.test(f.path)) continue;
3438
+ const c2 = code(f);
3439
+ const global_re = new RegExp(re.source, re.flags + "g");
3440
+ let match;
3441
+ while ((match = global_re.exec(c2)) !== null) {
3442
+ const match_text = match[0];
3443
+ const name_offset_in_match = match_text.lastIndexOf(name);
3444
+ const name_start = match.index + Math.max(0, name_offset_in_match);
3445
+ const { line, col } = position_at(f.content, name_start);
3446
+ return { file: f.path, line, col };
3447
+ }
3448
+ }
3449
+ }
3450
+ return void 0;
3451
+ }
3452
+
3136
3453
  // src/cli/open-editor.ts
3137
3454
  import { spawn } from "child_process";
3138
3455
  import { resolve as resolve2 } from "path";
@@ -3251,7 +3568,7 @@ var label_entry = (e) => {
3251
3568
  const colored = kind_color[e.kind](e.name);
3252
3569
  return `${colored}${qual}${where}`;
3253
3570
  };
3254
- async function pick_from_list(idx, root_dir, message, entries) {
3571
+ async function pick_from_list(idx, root_dir, files, message, entries) {
3255
3572
  if (entries.length === 0) {
3256
3573
  log.warn("nothing to show.");
3257
3574
  return;
@@ -3266,9 +3583,9 @@ async function pick_from_list(idx, root_dir, message, entries) {
3266
3583
  maxItems: 12
3267
3584
  });
3268
3585
  if (isCancel(pick)) return;
3269
- await show_detail(idx, root_dir, pick);
3586
+ await show_detail(idx, root_dir, files, pick);
3270
3587
  }
3271
- async function show_detail(idx, root_dir, entry) {
3588
+ async function show_detail(idx, root_dir, files, entry) {
3272
3589
  log.message(format_detail(idx, entry));
3273
3590
  if (!entry.file) return;
3274
3591
  const editor = pick_editor(process.env);
@@ -3283,7 +3600,11 @@ async function show_detail(idx, root_dir, entry) {
3283
3600
  ]
3284
3601
  });
3285
3602
  if (isCancel(action)) return;
3286
- const result = await open_in_editor(entry.file, entry.line, { root_dir });
3603
+ const nav = navigate_to_code(files, entry.name, entry.kind, entry.file);
3604
+ const line = entry.line ?? nav?.line;
3605
+ const result = await open_in_editor(nav?.file ?? entry.file, line, {
3606
+ root_dir
3607
+ });
3287
3608
  if (!result.ok) log.warn(`editor exited: ${result.reason ?? "unknown"}`);
3288
3609
  }
3289
3610
  var DEFAULT_PATHS = {
@@ -3329,7 +3650,7 @@ async function export_registry(idx, root_dir) {
3329
3650
  );
3330
3651
  }
3331
3652
  }
3332
- async function search_by_name(idx, root_dir) {
3653
+ async function search_by_name(idx, root_dir, files) {
3333
3654
  vim_keys?.pause();
3334
3655
  const q = await text({
3335
3656
  message: `Partial name to search ${dim("(esc to cancel)")}`,
@@ -3343,6 +3664,7 @@ async function search_by_name(idx, root_dir) {
3343
3664
  await pick_from_list(
3344
3665
  idx,
3345
3666
  root_dir,
3667
+ files,
3346
3668
  `${KIND_LABELS[kind]}`,
3347
3669
  list_by_kind(idx, kind)
3348
3670
  );
@@ -3353,15 +3675,15 @@ async function search_by_name(idx, root_dir) {
3353
3675
  log.warn(`no matches for "${q}"`);
3354
3676
  return;
3355
3677
  }
3356
- await pick_from_list(idx, root_dir, `matches for "${q}"`, matches2);
3678
+ await pick_from_list(idx, root_dir, files, `matches for "${q}"`, matches2);
3357
3679
  }
3358
- async function run_interactive(idx, root_dir) {
3680
+ async function run_interactive(idx, root_dir, files = []) {
3359
3681
  vim_keys = enableVimKeys(process.stdin);
3360
3682
  const unsub = vim_keys.on_slash(() => {
3361
3683
  search_requested = true;
3362
3684
  });
3363
3685
  try {
3364
- await drive_interactive(idx, root_dir);
3686
+ await drive_interactive(idx, root_dir, files);
3365
3687
  } finally {
3366
3688
  unsub();
3367
3689
  vim_keys.restore();
@@ -3369,13 +3691,13 @@ async function run_interactive(idx, root_dir) {
3369
3691
  search_requested = false;
3370
3692
  }
3371
3693
  }
3372
- async function drive_interactive(idx, root_dir) {
3694
+ async function drive_interactive(idx, root_dir, files) {
3373
3695
  intro("act \u2014 contracts explorer");
3374
3696
  log.message(format_summary(idx));
3375
3697
  while (true) {
3376
3698
  if (search_requested) {
3377
3699
  search_requested = false;
3378
- await search_by_name(idx, root_dir);
3700
+ await search_by_name(idx, root_dir, files);
3379
3701
  continue;
3380
3702
  }
3381
3703
  const choice = await select({
@@ -3406,6 +3728,7 @@ async function drive_interactive(idx, root_dir) {
3406
3728
  await pick_from_list(
3407
3729
  idx,
3408
3730
  root_dir,
3731
+ files,
3409
3732
  `${KIND_LABELS[choice]}`,
3410
3733
  list_by_kind(idx, choice)
3411
3734
  );
@@ -3525,7 +3848,7 @@ async function main(deps) {
3525
3848
  deps.output.write(format_matches(args.query, uniq_matches) + "\n");
3526
3849
  return 0;
3527
3850
  }
3528
- await (deps.run_interactive ?? run_interactive)(idx, root_dir);
3851
+ await (deps.run_interactive ?? run_interactive)(idx, root_dir, files);
3529
3852
  return 0;
3530
3853
  }
3531
3854
  var isMain = (() => {