@wrongstack/tools 0.264.0 → 0.267.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 (90) hide show
  1. package/dist/audit.js +154 -11
  2. package/dist/audit.js.map +1 -1
  3. package/dist/bash.js +138 -2
  4. package/dist/bash.js.map +1 -1
  5. package/dist/batch-tool-use.js +1 -0
  6. package/dist/batch-tool-use.js.map +1 -1
  7. package/dist/builtin.d.ts +20 -1
  8. package/dist/builtin.js +796 -340
  9. package/dist/builtin.js.map +1 -1
  10. package/dist/circuit-breaker.d.ts +20 -0
  11. package/dist/circuit-breaker.js +40 -2
  12. package/dist/circuit-breaker.js.map +1 -1
  13. package/dist/codebase-index/index.d.ts +16 -0
  14. package/dist/codebase-index/index.js +59 -25
  15. package/dist/codebase-index/index.js.map +1 -1
  16. package/dist/codebase-index/worker.js +56 -25
  17. package/dist/codebase-index/worker.js.map +1 -1
  18. package/dist/diff.js +14 -7
  19. package/dist/diff.js.map +1 -1
  20. package/dist/document.js +14 -8
  21. package/dist/document.js.map +1 -1
  22. package/dist/edit.d.ts +1 -0
  23. package/dist/edit.js +33 -22
  24. package/dist/edit.js.map +1 -1
  25. package/dist/exec.js +140 -3
  26. package/dist/exec.js.map +1 -1
  27. package/dist/fetch.js +1 -0
  28. package/dist/fetch.js.map +1 -1
  29. package/dist/format.js +153 -11
  30. package/dist/format.js.map +1 -1
  31. package/dist/git.d.ts +7 -0
  32. package/dist/git.js +20 -2
  33. package/dist/git.js.map +1 -1
  34. package/dist/glob.js +14 -7
  35. package/dist/glob.js.map +1 -1
  36. package/dist/grep.js +14 -7
  37. package/dist/grep.js.map +1 -1
  38. package/dist/index.d.ts +55 -3
  39. package/dist/index.js +957 -341
  40. package/dist/index.js.map +1 -1
  41. package/dist/install.js +153 -11
  42. package/dist/install.js.map +1 -1
  43. package/dist/json.js +1 -0
  44. package/dist/json.js.map +1 -1
  45. package/dist/lint.js +153 -11
  46. package/dist/lint.js.map +1 -1
  47. package/dist/logs.js +14 -7
  48. package/dist/logs.js.map +1 -1
  49. package/dist/memory.js +1 -0
  50. package/dist/memory.js.map +1 -1
  51. package/dist/mode.js +1 -0
  52. package/dist/mode.js.map +1 -1
  53. package/dist/outdated.js +21 -10
  54. package/dist/outdated.js.map +1 -1
  55. package/dist/pack.js +765 -339
  56. package/dist/pack.js.map +1 -1
  57. package/dist/patch.js +14 -7
  58. package/dist/patch.js.map +1 -1
  59. package/dist/process-registry.d.ts +56 -2
  60. package/dist/process-registry.js +138 -3
  61. package/dist/process-registry.js.map +1 -1
  62. package/dist/read.d.ts +3 -0
  63. package/dist/read.js +124 -22
  64. package/dist/read.js.map +1 -1
  65. package/dist/replace.js +14 -7
  66. package/dist/replace.js.map +1 -1
  67. package/dist/scaffold.js +14 -7
  68. package/dist/scaffold.js.map +1 -1
  69. package/dist/search.js +1 -0
  70. package/dist/search.js.map +1 -1
  71. package/dist/test.js +153 -11
  72. package/dist/test.js.map +1 -1
  73. package/dist/todo.js +1 -0
  74. package/dist/todo.js.map +1 -1
  75. package/dist/tool-help.js +1 -0
  76. package/dist/tool-help.js.map +1 -1
  77. package/dist/tool-icons.d.ts +20 -0
  78. package/dist/tool-icons.js +130 -0
  79. package/dist/tool-icons.js.map +1 -0
  80. package/dist/tool-search.js +1 -0
  81. package/dist/tool-search.js.map +1 -1
  82. package/dist/tool-use.js +1 -0
  83. package/dist/tool-use.js.map +1 -1
  84. package/dist/tree.js +14 -7
  85. package/dist/tree.js.map +1 -1
  86. package/dist/typecheck.js +153 -11
  87. package/dist/typecheck.js.map +1 -1
  88. package/dist/write.js +21 -15
  89. package/dist/write.js.map +1 -1
  90. package/package.json +6 -2
@@ -682,39 +682,57 @@ var IndexStore = class {
682
682
  }
683
683
  });
684
684
  }
685
+ /**
686
+ * Bulk-insert refs for many source symbols in a single transaction.
687
+ *
688
+ * Unlike {@link insertRefs} this does NOT delete per source id — the caller
689
+ * (the indexer) has already cleared stale refs for the file via
690
+ * {@link deleteRefsForFile}, so the per-source DELETE would be redundant work
691
+ * repeated once per symbol. One transaction for the whole file instead of one
692
+ * per symbol turns an O(symbols) transaction count into O(1).
693
+ *
694
+ * Each ref's own {@link Ref.fromId} is used; pass an empty array to no-op.
695
+ */
696
+ insertRefsBatch(refs) {
697
+ if (refs.length === 0) return;
698
+ this.runWithRetry(() => {
699
+ const stmt = this.db.prepare(
700
+ `INSERT INTO refs(from_id, to_name, to_id, call_type, line)
701
+ VALUES (?, ?, ?, ?, ?)`
702
+ );
703
+ for (const ref of refs) {
704
+ stmt.run(ref.fromId, ref.toName, ref.toId ?? null, ref.callType, ref.line);
705
+ }
706
+ });
707
+ }
685
708
  /**
686
709
  * Delete all refs whose source symbols are in a given file.
687
710
  * Used when re-indexing a file to clear stale refs.
688
711
  */
689
712
  deleteRefsForFile(file) {
690
713
  this.runWithRetry(() => {
691
- const ids = this.db.prepare(
692
- "SELECT id FROM symbols WHERE file = ?"
693
- ).all(file);
694
- if (!ids.length) return;
695
- const placeholders = ids.map(() => "?").join(",");
696
- this.db.prepare(`DELETE FROM refs WHERE from_id IN (${placeholders})`).run(...ids.map((r) => r.id));
714
+ this.db.prepare(
715
+ "DELETE FROM refs WHERE from_id IN (SELECT id FROM symbols WHERE file = ?)"
716
+ ).run(file);
697
717
  });
698
718
  }
699
719
  /**
700
720
  * Resolve `to_name` → `to_id` for all refs that have a name but no id.
701
721
  * Call this after all symbols have been inserted to fill in cross-references.
722
+ *
723
+ * Single statement: the `to_name IN (SELECT name FROM symbols)` guard restricts
724
+ * the UPDATE to refs that will actually resolve, so `.changes` counts only refs
725
+ * that found a target — matching the previous per-row loop's return value.
702
726
  */
703
727
  resolveRefs() {
704
728
  return this.runWithRetry(() => {
705
- const unresolved = this.db.prepare(
706
- "SELECT id, to_name FROM refs WHERE to_id IS NULL AND to_name IS NOT NULL"
707
- ).all();
708
- let resolved = 0;
709
- for (const row of unresolved) {
710
- const target = this.db.prepare("SELECT id FROM symbols WHERE name = ? LIMIT 1").all(row.to_name);
711
- const first = target[0];
712
- if (first) {
713
- this.db.prepare("UPDATE refs SET to_id = ? WHERE id = ?").run(first.id, row.id);
714
- resolved++;
715
- }
716
- }
717
- return resolved;
729
+ const result = this.db.prepare(
730
+ `UPDATE refs SET to_id = (
731
+ SELECT id FROM symbols WHERE name = refs.to_name LIMIT 1
732
+ ) WHERE to_id IS NULL AND to_name IS NOT NULL
733
+ AND to_name IN (SELECT name FROM symbols)`
734
+ ).run();
735
+ return result.changes ?? 0;
718
736
  });
719
737
  }
720
738
  /**
@@ -2189,13 +2207,26 @@ async function runIndexerWithStore(store, opts) {
2189
2207
  symbolsIndexed += count;
2190
2208
  langStats[lang] = (langStats[lang] ?? 0) + count;
2191
2209
  if (parsed.refs && parsed.refs.length > 0) {
2192
- for (let i = 0; i < symbolsWithIds.length; i++) {
2193
- const sym = expectDefined(symbolsWithIds[i]);
2194
- const symRefs = parsed.refs.filter((r) => r.line === sym.line);
2195
- if (symRefs.length > 0) {
2196
- const refsWithFromId = symRefs.map((r) => ({ ...r, fromId: sym.id }));
2197
- store.insertRefs(sym.id, refsWithFromId);
2210
+ const refsByLine = /* @__PURE__ */ new Map();
2211
+ for (const r of parsed.refs) {
2212
+ let arr = refsByLine.get(r.line);
2213
+ if (!arr) {
2214
+ arr = [];
2215
+ refsByLine.set(r.line, arr);
2198
2216
  }
2217
+ arr.push(r);
2218
+ }
2219
+ const batch = [];
2220
+ for (const sym of symbolsWithIds) {
2221
+ const symRefs = refsByLine.get(sym.line);
2222
+ if (symRefs) {
2223
+ for (const r of symRefs) {
2224
+ batch.push({ ...r, fromId: sym.id });
2225
+ }
2226
+ }
2227
+ }
2228
+ if (batch.length > 0) {
2229
+ store.insertRefsBatch(batch);
2199
2230
  }
2200
2231
  }
2201
2232
  store.upsertFile({