@jefuriiij/synthra 0.4.1 → 0.6.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.
@@ -2935,6 +2935,31 @@ async function pack(files, opts) {
2935
2935
  };
2936
2936
  }
2937
2937
 
2938
+ // src/shared/config.ts
2939
+ function num(name, fallback) {
2940
+ const v = process.env[name];
2941
+ if (!v) return fallback;
2942
+ const n = Number(v);
2943
+ return Number.isFinite(n) ? n : fallback;
2944
+ }
2945
+ function str(name, fallback) {
2946
+ return process.env[name] ?? fallback;
2947
+ }
2948
+ function loadConfig() {
2949
+ return {
2950
+ hardMaxReadChars: num("SYN_HARD_MAX_READ_CHARS", 4e3),
2951
+ gateHintMaxChars: num("SYN_GATE_HINT_CHARS", 1200),
2952
+ readDepsMaxChars: num("SYN_READ_DEPS_CHARS", 900),
2953
+ turnReadBudgetChars: num("SYN_TURN_READ_BUDGET_CHARS", 18e3),
2954
+ fallbackMaxCallsPerTurn: num("SYN_FALLBACK_MAX_CALLS_PER_TURN", 1),
2955
+ retrieveCacheTtlSec: num("SYN_RETRIEVE_CACHE_TTL_SEC", 900),
2956
+ mcpPort: process.env.SYN_MCP_PORT ? num("SYN_MCP_PORT", 0) : null,
2957
+ dashboardPort: num("SYN_DASHBOARD_PORT", 8901),
2958
+ logLevel: str("SYN_LOG_LEVEL", "info"),
2959
+ claudeBin: str("SYN_CLAUDE_BIN", "claude")
2960
+ };
2961
+ }
2962
+
2938
2963
  // src/server/mcp.ts
2939
2964
  var PROTOCOL_VERSION = "2024-11-05";
2940
2965
  var SERVER_INFO = { name: "synthra", version: "0.0.1" };
@@ -2974,7 +2999,7 @@ var TOOLS = [
2974
2999
  },
2975
3000
  {
2976
3001
  name: "graph_read",
2977
- description: "Return the source code for a specific file or symbol. Target is either a project-relative file path (e.g. 'src/auth.ts') or 'file::symbol' (e.g. 'src/auth.ts::AuthService').",
3002
+ description: "Return the source code for a specific file or symbol. Target is either a project-relative file path (e.g. 'src/auth.ts') or 'file::symbol' (e.g. 'src/auth.ts::AuthService'). A symbol read also returns its dependency surface \u2014 the signatures of the symbols it calls (edit against these instead of guessing or re-reading their files) and the names of the symbols that call it.",
2978
3003
  inputSchema: {
2979
3004
  type: "object",
2980
3005
  properties: {
@@ -3251,6 +3276,72 @@ function resolveFileTarget(graph, filePath) {
3251
3276
  if (matches.length > 1) return { ambiguous: matches.map((n) => n.path) };
3252
3277
  return { none: true };
3253
3278
  }
3279
+ var DEPS_SIG_MAX = 140;
3280
+ var DEPS_MAX_CALLEES = 10;
3281
+ var DEPS_MAX_CALLERS = 12;
3282
+ function buildDepsFooter(symbol, graph, maxChars = loadConfig().readDepsMaxChars) {
3283
+ const symById = /* @__PURE__ */ new Map();
3284
+ for (const n of graph.nodes) if (n.kind === "symbol") symById.set(n.id, n);
3285
+ const calleeIds = [];
3286
+ const callerIds = [];
3287
+ const seenCallee = /* @__PURE__ */ new Set();
3288
+ const seenCaller = /* @__PURE__ */ new Set();
3289
+ for (const e of graph.edges) {
3290
+ if (e.kind !== "calls") continue;
3291
+ if (e.from === symbol.id && e.to !== symbol.id && !seenCallee.has(e.to)) {
3292
+ seenCallee.add(e.to);
3293
+ calleeIds.push(e.to);
3294
+ } else if (e.to === symbol.id && e.from !== symbol.id && !seenCaller.has(e.from)) {
3295
+ seenCaller.add(e.from);
3296
+ callerIds.push(e.from);
3297
+ }
3298
+ }
3299
+ const resolve2 = (ids) => ids.map((id) => symById.get(id)).filter((n) => !!n);
3300
+ const callees = resolve2(calleeIds).sort(
3301
+ (a, b) => a.file === b.file ? a.start_line - b.start_line : a.file < b.file ? -1 : 1
3302
+ );
3303
+ const callers = resolve2(callerIds);
3304
+ if (callees.length === 0 && callers.length === 0) return "";
3305
+ const lines = [];
3306
+ let used = 0;
3307
+ if (callees.length > 0) {
3308
+ const head = "Depends on (signatures \u2014 don't guess these):";
3309
+ lines.push(head);
3310
+ used += head.length + 1;
3311
+ let shown = 0;
3312
+ for (const c of callees.slice(0, DEPS_MAX_CALLEES)) {
3313
+ const sig = c.signature.trim().slice(0, DEPS_SIG_MAX);
3314
+ const entry = `\u2022 ${sig} \u2192 mcp__synthra__graph_read("${c.file}::${c.name}")`;
3315
+ if (used + entry.length + 1 > maxChars) break;
3316
+ lines.push(entry);
3317
+ used += entry.length + 1;
3318
+ shown += 1;
3319
+ }
3320
+ const omitted = callees.length - shown;
3321
+ if (omitted > 0) lines.push(`\u2026+${omitted} more`);
3322
+ }
3323
+ if (callers.length > 0) {
3324
+ const sep3 = lines.length > 0 ? 1 : 0;
3325
+ const head = `Used by (${callers.length}): `;
3326
+ const shown = [];
3327
+ let cUsed = used + sep3 + head.length;
3328
+ for (const c of callers.slice(0, DEPS_MAX_CALLERS)) {
3329
+ const part = `${c.name} \u2192 ${c.file}`;
3330
+ const join7 = shown.length > 0 ? 3 : 0;
3331
+ if (cUsed + join7 + part.length > maxChars) break;
3332
+ shown.push(part);
3333
+ cUsed += join7 + part.length;
3334
+ }
3335
+ if (lines.length > 0) lines.push("");
3336
+ if (shown.length > 0) {
3337
+ const omitted = callers.length - shown.length;
3338
+ lines.push(head + shown.join(" \xB7 ") + (omitted > 0 ? ` \u2026+${omitted} more` : ""));
3339
+ } else {
3340
+ lines.push(`Used by (${callers.length} callers)`);
3341
+ }
3342
+ }
3343
+ return lines.join("\n");
3344
+ }
3254
3345
  async function graphRead(args, ctx) {
3255
3346
  const target = typeof args?.target === "string" ? args.target : "";
3256
3347
  if (!target) return errorContent("graph_read: 'target' (string) is required");
@@ -3283,10 +3374,21 @@ ${fileNode.content}`);
3283
3374
  }
3284
3375
  const lines = fileNode.content.split(/\r?\n/);
3285
3376
  const body = lines.slice(symbol.start_line - 1, symbol.end_line).join("\n");
3377
+ const offset = Math.max(1, symbol.start_line - 2);
3378
+ const limit = symbol.end_line - symbol.start_line + 1 + 4;
3379
+ const editHint = `
3380
+
3381
+ ---
3382
+ \u270E To edit this symbol: Read("${fileNode.path}", offset=${offset}, limit=${limit}) then Edit \u2014 that satisfies Claude Code's read-gate at ~${limit} lines; do NOT re-read the whole file.`;
3383
+ const deps = buildDepsFooter(symbol, ctx.graph);
3384
+ const depsBlock = deps ? `
3385
+
3386
+ ---
3387
+ ${deps}` : "";
3286
3388
  return textContent(
3287
3389
  `# ${fileNode.path}::${symbol.name} (L${symbol.start_line}-${symbol.end_line})
3288
3390
 
3289
- ${body}`
3391
+ ${body}${depsBlock}${editHint}`
3290
3392
  );
3291
3393
  }
3292
3394
  var editedFiles = /* @__PURE__ */ new Set();
@@ -3552,32 +3654,6 @@ async function handleContextUpdate(req, ctx) {
3552
3654
  // src/server/routes/gate.ts
3553
3655
  import { appendFile as appendFile4, mkdir as mkdir10 } from "fs/promises";
3554
3656
  import { dirname as dirname11 } from "path";
3555
-
3556
- // src/shared/config.ts
3557
- function num(name, fallback) {
3558
- const v = process.env[name];
3559
- if (!v) return fallback;
3560
- const n = Number(v);
3561
- return Number.isFinite(n) ? n : fallback;
3562
- }
3563
- function str(name, fallback) {
3564
- return process.env[name] ?? fallback;
3565
- }
3566
- function loadConfig() {
3567
- return {
3568
- hardMaxReadChars: num("SYN_HARD_MAX_READ_CHARS", 4e3),
3569
- gateHintMaxChars: num("SYN_GATE_HINT_CHARS", 1200),
3570
- turnReadBudgetChars: num("SYN_TURN_READ_BUDGET_CHARS", 18e3),
3571
- fallbackMaxCallsPerTurn: num("SYN_FALLBACK_MAX_CALLS_PER_TURN", 1),
3572
- retrieveCacheTtlSec: num("SYN_RETRIEVE_CACHE_TTL_SEC", 900),
3573
- mcpPort: process.env.SYN_MCP_PORT ? num("SYN_MCP_PORT", 0) : null,
3574
- dashboardPort: num("SYN_DASHBOARD_PORT", 8901),
3575
- logLevel: str("SYN_LOG_LEVEL", "info"),
3576
- claudeBin: str("SYN_CLAUDE_BIN", "claude")
3577
- };
3578
- }
3579
-
3580
- // src/server/routes/gate.ts
3581
3657
  var BLOCKABLE_TOOLS = /* @__PURE__ */ new Set(["Grep", "Glob"]);
3582
3658
  var RECENT_ACTIVITY_WINDOW_MS = 5 * 60 * 1e3;
3583
3659
  function extractQuery(toolName, input) {
@@ -3600,6 +3676,11 @@ function looksLikeNonSymbolQuery(pattern) {
3600
3676
  if (/:\s*\d/.test(pattern) || /\d(?:px|rem|em|vh|vw)\b/.test(pattern) || /\d%/.test(pattern)) {
3601
3677
  return true;
3602
3678
  }
3679
+ if (/--[a-zA-Z]/.test(pattern)) return true;
3680
+ if (/#[0-9a-fA-F]{3,8}\b/.test(pattern)) return true;
3681
+ const branches = pattern.replace(/\[[^\]]*\]/g, "").split("|").map((b) => b.trim()).filter(Boolean);
3682
+ const isKebab = (b) => /^[a-z][a-z0-9]*(?:-[a-z0-9]+)+$/i.test(b);
3683
+ if (branches.length > 0 && branches.every(isKebab)) return true;
3603
3684
  return false;
3604
3685
  }
3605
3686
  function recentlyTouchedMatchesQuery(recentPaths, queryTokens, graph) {