@dimassetoid/septum-mcp 0.2.1 → 0.3.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 (106) hide show
  1. package/README.md +46 -28
  2. package/package.json +4 -4
  3. package/src/cli/commands/check.ts +27 -16
  4. package/src/cli/commands/hook.ts +38 -101
  5. package/src/cli/commands/init.ts +26 -9
  6. package/src/cli/commands/sync.ts +4 -6
  7. package/src/cli/hook-payload.ts +43 -0
  8. package/src/cli/index.ts +9 -52
  9. package/src/cli/scaffold/harness-config.ts +48 -8
  10. package/src/cli/templates/hooks.ts +49 -14
  11. package/src/cli/templates/rules.ts +34 -49
  12. package/src/cli/templates/skill.ts +39 -35
  13. package/src/core/boundary/evaluator.ts +67 -83
  14. package/src/core/boundary/staged-auditor.ts +102 -40
  15. package/src/core/config/domain-ownership.ts +45 -0
  16. package/src/core/config/loader.ts +81 -29
  17. package/src/core/config/schema.ts +0 -10
  18. package/src/core/database/repositories/dependency.repository.ts +169 -148
  19. package/src/core/database/repositories/domain.repository.ts +46 -3
  20. package/src/core/database/repositories/symbol.repository.ts +226 -87
  21. package/src/core/database/repository.ts +73 -18
  22. package/src/core/database/schema.ts +2 -33
  23. package/src/core/discovery/navigation.ts +105 -0
  24. package/src/core/discovery/topology-detector.ts +60 -2
  25. package/src/core/ingestion/pipeline.ts +96 -129
  26. package/src/core/parser/behavioral-analyzer.ts +26 -22
  27. package/src/core/parser/boundary-tracker.ts +15 -0
  28. package/src/core/parser/extractors/base.ts +7 -3
  29. package/src/core/parser/extractors/csharp.ts +7 -3
  30. package/src/core/parser/extractors/django-semantic.ts +4 -36
  31. package/src/core/parser/extractors/elysia-semantic.ts +3 -24
  32. package/src/core/parser/extractors/express-semantic.ts +3 -18
  33. package/src/core/parser/extractors/fastapi-semantic.ts +19 -53
  34. package/src/core/parser/extractors/fastify-semantic.ts +3 -18
  35. package/src/core/parser/extractors/flask-semantic.ts +22 -55
  36. package/src/core/parser/extractors/go-semantic.ts +92 -33
  37. package/src/core/parser/extractors/hono-semantic.ts +3 -24
  38. package/src/core/parser/extractors/java.ts +5 -3
  39. package/src/core/parser/extractors/laravel-semantic.ts +44 -16
  40. package/src/core/parser/extractors/mcp-cli-semantic.ts +6 -7
  41. package/src/core/parser/extractors/nestjs-semantic.ts +3 -19
  42. package/src/core/parser/extractors/php.ts +16 -0
  43. package/src/core/parser/extractors/python.ts +9 -4
  44. package/src/core/parser/extractors/registry.ts +26 -5
  45. package/src/core/parser/extractors/ruby.ts +8 -5
  46. package/src/core/parser/extractors/rust.ts +31 -13
  47. package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
  48. package/src/core/parser/extractors/symfony-semantic.ts +4 -37
  49. package/src/core/parser/extractors/typescript.ts +14 -1
  50. package/src/core/parser/implementation-fingerprint.ts +97 -0
  51. package/src/core/parser/language-capabilities.ts +23 -7
  52. package/src/core/parser/schema/providers/laravel-migration-provider.ts +73 -50
  53. package/src/core/parser/schema/schema-provider-registry.ts +1 -3
  54. package/src/core/parser/schema/schema-provider.interface.ts +2 -1
  55. package/src/core/parser/semantic-revision.ts +3 -0
  56. package/src/core/parser/static-string.ts +51 -0
  57. package/src/core/resolver/call-graph-tracer.ts +337 -28
  58. package/src/core/resolver/import-resolver.ts +107 -179
  59. package/src/core/resolver/interpretation-inputs.ts +7 -0
  60. package/src/core/resolver/languages/go.ts +103 -0
  61. package/src/core/resolver/languages/managed.ts +200 -0
  62. package/src/core/resolver/languages/python.ts +115 -0
  63. package/src/core/resolver/languages/ruby.ts +40 -0
  64. package/src/core/resolver/languages/rust.ts +127 -0
  65. package/src/core/resolver/languages/shared.ts +71 -0
  66. package/src/core/resolver/module-resolver.ts +8 -4
  67. package/src/core/resolver/slice-catalog.ts +79 -0
  68. package/src/core/resolver/slice-format.ts +9 -0
  69. package/src/core/resolver/symbol-impact.ts +381 -0
  70. package/src/core/resolver/vertical-slice-tracer.ts +93 -115
  71. package/src/core/resources/ignore.ts +22 -1
  72. package/src/core/resources/source-files.ts +143 -20
  73. package/src/core/resources/source-inventory.ts +55 -0
  74. package/src/core/retrieval/context-page.ts +109 -0
  75. package/src/core/retrieval/context.ts +320 -0
  76. package/src/core/retrieval/resolution-warnings.ts +21 -0
  77. package/src/core/retrieval/symbol-evidence.ts +97 -0
  78. package/src/core/retrieval/typescript-references.ts +262 -0
  79. package/src/core/telemetry/telemetry.ts +54 -9
  80. package/src/index.ts +0 -3
  81. package/src/mcp/schemas.ts +61 -420
  82. package/src/mcp/server.ts +116 -290
  83. package/src/mcp/tools/boundary.ts +2 -2
  84. package/src/mcp/tools/check-boundary.ts +55 -60
  85. package/src/mcp/tools/get-domain-catalog.ts +32 -219
  86. package/src/mcp/tools/get-symbol-impact.ts +45 -5
  87. package/src/mcp/tools/get-symbol.ts +227 -3
  88. package/src/mcp/tools/locate-symbol.ts +54 -14
  89. package/src/mcp/tools/{domain.ts → map.ts} +4 -18
  90. package/src/mcp/tools/register-domain.ts +41 -3
  91. package/src/mcp/tools/symbol.ts +23 -21
  92. package/src/mcp/tools/trace-vertical-slice.ts +36 -10
  93. package/src/mcp/workspace-manager.ts +15 -4
  94. package/src/mcp/workspace-watcher.ts +8 -8
  95. package/src/types/index.ts +35 -53
  96. package/src/cli/commands/topology.ts +0 -161
  97. package/src/core/database/repositories/environment.repository.ts +0 -207
  98. package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
  99. package/src/core/session/session-manager.ts +0 -107
  100. package/src/core/topology/environment-detector.ts +0 -973
  101. package/src/core/topology/types.ts +0 -83
  102. package/src/mcp/tools/feature.ts +0 -67
  103. package/src/mcp/tools/get-environment-topology.ts +0 -138
  104. package/src/mcp/tools/get-feature-context.ts +0 -224
  105. package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
  106. package/src/mcp/tools/register-feature.ts +0 -110
@@ -0,0 +1,262 @@
1
+ import ts from "typescript";
2
+
3
+ export type ContextValue = { kind: "unknown" | "undefined" } |
4
+ { kind: "literal"; value: string | number | boolean | null } |
5
+ { kind: "object"; properties: Record<string, ContextValue> };
6
+
7
+ /** Bind identifiers inside one verified file, without reading libraries or disk.
8
+ * Import resolution remains owned by Septum's observed resolver.
9
+ */
10
+ export function bindContextFile(path: string, text: string) {
11
+ const source = ts.createSourceFile(path, text, ts.ScriptTarget.Latest, true);
12
+ const host: ts.CompilerHost = {
13
+ getSourceFile: name => name === path ? source : undefined,
14
+ getDefaultLibFileName: () => "", writeFile: () => {}, getCurrentDirectory: () => "",
15
+ getDirectories: () => [], fileExists: name => name === path,
16
+ readFile: name => name === path ? text : undefined, getCanonicalFileName: name => name,
17
+ useCaseSensitiveFileNames: () => true, getNewLine: () => "\n",
18
+ };
19
+ const program = ts.createProgram([path], { noLib: true, noResolve: true }, host);
20
+ const checker = program.getTypeChecker();
21
+ function top(node: ts.Node): ts.Node {
22
+ while (node.parent && node.parent !== source) node = node.parent;
23
+ return node;
24
+ }
25
+ return {
26
+ source,
27
+ hasErrors: program.getSyntacticDiagnostics(source).length > 0,
28
+ declaration(start: number, end: number) {
29
+ return source.statements.find(node => source.getLineAndCharacterOfPosition(node.getStart()).line + 1 <= start &&
30
+ source.getLineAndCharacterOfPosition(node.end).line + 1 >= end);
31
+ },
32
+ contract(node: ts.ClassDeclaration) {
33
+ const printer = ts.createPrinter();
34
+ const members: string[] = [];
35
+ const signatures: ts.Node[] = [...(node.typeParameters ?? []), ...(node.heritageClauses ?? [])];
36
+ let inferred = false;
37
+ for (const member of node.members) {
38
+ const modifiers = ts.canHaveModifiers(member) ? ts.getModifiers(member) : undefined;
39
+ if (modifiers?.some(m => [ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword, ts.SyntaxKind.StaticKeyword].includes(m.kind))) continue;
40
+ if (ts.isConstructorDeclaration(member)) {
41
+ for (const parameter of member.parameters) {
42
+ if (!ts.isIdentifier(parameter.name) || !parameter.modifiers?.some(m => m.kind === ts.SyntaxKind.PublicKeyword || m.kind === ts.SyntaxKind.ReadonlyKeyword) ||
43
+ parameter.modifiers.some(m => m.kind === ts.SyntaxKind.PrivateKeyword || m.kind === ts.SyntaxKind.ProtectedKeyword)) continue;
44
+ if (parameter.type) signatures.push(parameter.type); else inferred = true;
45
+ members.push(printer.printNode(ts.EmitHint.Unspecified, ts.factory.createPropertySignature(
46
+ parameter.modifiers.filter(m => m.kind === ts.SyntaxKind.ReadonlyKeyword), parameter.name, parameter.questionToken,
47
+ parameter.type ?? ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)), source));
48
+ }
49
+ }
50
+ if (!member.name || ts.isPrivateIdentifier(member.name) || ts.isComputedPropertyName(member.name)) continue;
51
+ if (ts.isMethodDeclaration(member)) {
52
+ signatures.push(...(member.typeParameters ?? []));
53
+ const parameters = member.parameters.map(p => {
54
+ if (p.type) signatures.push(p.type); else inferred = true;
55
+ return ts.factory.updateParameterDeclaration(p, undefined, p.dotDotDotToken, p.name,
56
+ p.questionToken ?? (p.initializer ? ts.factory.createToken(ts.SyntaxKind.QuestionToken) : undefined),
57
+ p.type ?? ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword), undefined);
58
+ });
59
+ if (member.type) signatures.push(member.type); else inferred = true;
60
+ const signature = ts.factory.createMethodSignature(undefined, member.name, member.questionToken,
61
+ member.typeParameters, parameters, member.type ?? ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword));
62
+ members.push(printer.printNode(ts.EmitHint.Unspecified, signature, source));
63
+ } else if (ts.isPropertyDeclaration(member)) {
64
+ if (member.type) signatures.push(member.type); else inferred = true;
65
+ members.push(printer.printNode(ts.EmitHint.Unspecified, ts.factory.createPropertySignature(
66
+ modifiers?.filter(m => m.kind === ts.SyntaxKind.ReadonlyKeyword), member.name, member.questionToken,
67
+ member.type ?? ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)), source));
68
+ } else if (ts.isGetAccessorDeclaration(member) || ts.isSetAccessorDeclaration(member)) {
69
+ const type = ts.isGetAccessorDeclaration(member) ? member.type : member.parameters[0]?.type;
70
+ if (type) signatures.push(type); else inferred = true;
71
+ members.push(`${member.name.getText(source)}: ${type?.getText(source) ?? "unknown"};`);
72
+ }
73
+ }
74
+ const heritage = node.heritageClauses?.find(clause => clause.token === ts.SyntaxKind.ExtendsKeyword);
75
+ return { text: `interface ${node.name?.text ?? "Anonymous"}${node.typeParameters ? `<${node.typeParameters.map(p => p.getText(source)).join(", ")}>` : ""}${heritage ? ` ${heritage.getText(source)}` : ""} {\n${members.map(m => ` ${m}`).join("\n")}\n}`,
76
+ signatures, inferred };
77
+ },
78
+ references(node: ts.Node, argumentFacts?: ContextValue[], signatureNodes?: ts.Node[]) {
79
+ const locals = new Set<ts.Node>();
80
+ const imports = new Map<ts.ImportDeclaration, Set<string>>();
81
+ const calls: Array<{ target: ts.Node; name?: string; arguments: ContextValue[] }> = [];
82
+ const escapes = new Set<ts.Node>();
83
+ const facts = new Map<ts.Symbol, ContextValue>();
84
+ const unknown: ContextValue = { kind: "unknown" };
85
+ const absent: ContextValue = { kind: "undefined" };
86
+ const fn = ts.isFunctionLike(node) ? node : ts.isVariableStatement(node) && node.declarationList.declarations.length === 1
87
+ ? node.declarationList.declarations[0]?.initializer : undefined;
88
+ const evaluate = (expression: ts.Node, depth = 0): ContextValue => {
89
+ if (depth > 8) return unknown;
90
+ if (ts.isParenthesizedExpression(expression) || ts.isAsExpression(expression) || ts.isNonNullExpression(expression)) return evaluate(expression.expression, depth + 1);
91
+ if (expression.kind === ts.SyntaxKind.TrueKeyword) return { kind: "literal", value: true };
92
+ if (expression.kind === ts.SyntaxKind.FalseKeyword) return { kind: "literal", value: false };
93
+ if (expression.kind === ts.SyntaxKind.NullKeyword) return { kind: "literal", value: null };
94
+ if (ts.isStringLiteral(expression) && expression.text.length <= 256) return { kind: "literal", value: expression.text };
95
+ if (ts.isNumericLiteral(expression)) return { kind: "literal", value: Number(expression.text) };
96
+ if (ts.isIdentifier(expression)) {
97
+ const symbol = checker.getSymbolAtLocation(expression);
98
+ if (symbol && facts.has(symbol)) return facts.get(symbol)!;
99
+ if (expression.text === "undefined" && !symbol?.declarations?.length) return absent;
100
+ const declaration = symbol?.valueDeclaration;
101
+ if (declaration && ts.isVariableDeclaration(declaration) && declaration.initializer &&
102
+ ts.isVariableDeclarationList(declaration.parent) && declaration.parent.flags & ts.NodeFlags.Const) {
103
+ // const protects the binding, not a mutable object shared with the caller.
104
+ if (ts.isObjectLiteralExpression(declaration.initializer)) return unknown;
105
+ return evaluate(declaration.initializer, depth + 1);
106
+ }
107
+ return unknown;
108
+ }
109
+ if (ts.isObjectLiteralExpression(expression)) {
110
+ const properties: Record<string, ContextValue> = Object.create(null);
111
+ if (expression.properties.length > 32) return unknown;
112
+ for (const property of expression.properties) {
113
+ if (!ts.isPropertyAssignment(property) && !ts.isShorthandPropertyAssignment(property)) return unknown;
114
+ if (!ts.isIdentifier(property.name) && !ts.isStringLiteral(property.name)) return unknown;
115
+ properties[property.name.text] = evaluate(ts.isPropertyAssignment(property) ? property.initializer : property.name, depth + 1);
116
+ }
117
+ return { kind: "object", properties };
118
+ }
119
+ if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)) {
120
+ const owner = evaluate(expression.expression, depth + 1);
121
+ const key = ts.isPropertyAccessExpression(expression) ? expression.name.text :
122
+ expression.argumentExpression && ts.isStringLiteral(expression.argumentExpression) ? expression.argumentExpression.text : undefined;
123
+ if (owner.kind === "object" && key !== undefined) return owner.properties[key] ?? absent;
124
+ if (expression.questionDotToken && (owner.kind === "undefined" || owner.kind === "literal" && owner.value === null)) return absent;
125
+ }
126
+ if (ts.isPrefixUnaryExpression(expression) && expression.operator === ts.SyntaxKind.ExclamationToken) {
127
+ const value = evaluate(expression.operand, depth + 1);
128
+ if (value.kind !== "unknown") return { kind: "literal", value: value.kind === "undefined" || value.kind === "literal" && !value.value };
129
+ }
130
+ if (ts.isBinaryExpression(expression) && [ts.SyntaxKind.EqualsEqualsEqualsToken, ts.SyntaxKind.ExclamationEqualsEqualsToken].includes(expression.operatorToken.kind)) {
131
+ const left = evaluate(expression.left, depth + 1), right = evaluate(expression.right, depth + 1);
132
+ if ((left.kind === "literal" || left.kind === "undefined") && (right.kind === "literal" || right.kind === "undefined")) {
133
+ const equal = (left.kind === "literal" ? left.value : undefined) === (right.kind === "literal" ? right.value : undefined);
134
+ return { kind: "literal", value: expression.operatorToken.kind === ts.SyntaxKind.EqualsEqualsEqualsToken ? equal : !equal };
135
+ }
136
+ }
137
+ return unknown;
138
+ };
139
+ if (fn && ts.isFunctionLike(fn)) fn.parameters.forEach((parameter, index) => {
140
+ if (!ts.isIdentifier(parameter.name)) return;
141
+ const symbol = checker.getSymbolAtLocation(parameter.name);
142
+ let value = argumentFacts ? argumentFacts[index] ?? absent : unknown;
143
+ if (value.kind === "undefined" && parameter.initializer) value = evaluate(parameter.initializer);
144
+ if (symbol) facts.set(symbol, value);
145
+ });
146
+ const invalidate = (expression: ts.Node): void => {
147
+ const tracked = new Set<ContextValue>([...facts.values()].filter(value => value.kind === "object"));
148
+ const aliases = (value: ContextValue): boolean => tracked.has(value) ||
149
+ value.kind === "object" && Object.values(value.properties).some(aliases);
150
+ if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression) || aliases(evaluate(expression)))
151
+ for (const [key, value] of facts) if (value.kind === "object") facts.set(key, unknown);
152
+ if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)) return invalidate(expression.expression);
153
+ if (!ts.isIdentifier(expression)) return;
154
+ const symbol = checker.getSymbolAtLocation(expression);
155
+ if (symbol) facts.set(symbol, unknown);
156
+ };
157
+ const escapedClosures = new Set<ts.Node>();
158
+ const escape = (expression: ts.Node, depth = 0): void => {
159
+ if (depth > 64) {
160
+ for (const [key, value] of facts) if (value.kind === "object") facts.set(key, unknown);
161
+ return;
162
+ }
163
+ if (evaluate(expression).kind === "object") invalidate(expression);
164
+ // A scalar property read does not expose the containing option object.
165
+ if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)) return;
166
+ if (ts.isIdentifier(expression)) {
167
+ const declaration = checker.getSymbolAtLocation(expression)?.valueDeclaration;
168
+ const initializer = declaration && ts.isVariableDeclaration(declaration) ? declaration.initializer : declaration;
169
+ if (initializer && !escapedClosures.has(initializer) &&
170
+ (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer) || ts.isFunctionDeclaration(initializer))) {
171
+ escapedClosures.add(initializer);
172
+ ts.forEachChild(initializer, child => escape(child, depth + 1));
173
+ }
174
+ return;
175
+ }
176
+ ts.forEachChild(expression, child => escape(child, depth + 1));
177
+ };
178
+ let prunedBranches = 0;
179
+ const visit = (child: ts.Node) => {
180
+ if (child !== node && child !== fn && ts.isFunctionLike(child)) {
181
+ const saved = new Map(facts);
182
+ facts.clear();
183
+ ts.forEachChild(child, visit);
184
+ facts.clear();
185
+ for (const [key, value] of saved) facts.set(key, value);
186
+ return;
187
+ }
188
+ if (!signatureNodes && (ts.isIfStatement(child) || ts.isConditionalExpression(child))) {
189
+ const condition = ts.isIfStatement(child) ? child.expression : child.condition;
190
+ const value = evaluate(condition);
191
+ visit(condition);
192
+ if (value.kind !== "unknown") {
193
+ const truthy = value.kind === "object" || value.kind === "literal" && Boolean(value.value);
194
+ const chosen = ts.isIfStatement(child) ? truthy ? child.thenStatement : child.elseStatement : truthy ? child.whenTrue : child.whenFalse;
195
+ prunedBranches++;
196
+ if (chosen) visit(chosen);
197
+ return;
198
+ }
199
+ }
200
+ if (!signatureNodes && ts.isCallExpression(child)) {
201
+ if (ts.isIdentifier(child.expression)) {
202
+ const effectful = (arg: ts.Node): boolean => ts.isCallExpression(arg) || ts.isNewExpression(arg) ||
203
+ ts.isAwaitExpression(arg) || ts.isDeleteExpression(arg) ||
204
+ ts.isBinaryExpression(arg) && arg.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && arg.operatorToken.kind <= ts.SyntaxKind.LastAssignment ||
205
+ ts.isPostfixUnaryExpression(arg) || ts.forEachChild(arg, n => effectful(n) || undefined) === true;
206
+ for (const declaration of checker.getSymbolAtLocation(child.expression)?.declarations ?? []) {
207
+ calls.push({ target: top(declaration),
208
+ name: ts.isImportSpecifier(declaration) ? (declaration.propertyName ?? declaration.name).text :
209
+ ts.isImportClause(declaration) ? "default" : undefined,
210
+ arguments: child.arguments.length <= 16 ? child.arguments.map(arg => child.arguments.some(effectful) ? unknown : evaluate(arg)) : Array(16).fill(unknown) });
211
+ }
212
+ }
213
+ ts.forEachChild(child, visit);
214
+ // An unknown callee may mutate object arguments. Subsequent guards cannot reuse those facts.
215
+ for (const arg of child.arguments) escape(arg);
216
+ return;
217
+ }
218
+ if (!signatureNodes && ts.isNewExpression(child)) {
219
+ ts.forEachChild(child, visit);
220
+ for (const arg of child.arguments ?? []) escape(arg);
221
+ return;
222
+ }
223
+ if (!signatureNodes && ts.isYieldExpression(child)) {
224
+ if (child.expression) escape(child.expression);
225
+ ts.forEachChild(child, visit);
226
+ return;
227
+ }
228
+ if (!signatureNodes && ts.isBinaryExpression(child) && child.operatorToken.kind >= ts.SyntaxKind.FirstAssignment && child.operatorToken.kind <= ts.SyntaxKind.LastAssignment) invalidate(child.left);
229
+ if (!signatureNodes && ts.isDeleteExpression(child)) invalidate(child.expression);
230
+ if (!signatureNodes && (ts.isPostfixUnaryExpression(child) || ts.isPrefixUnaryExpression(child)) &&
231
+ [ts.SyntaxKind.PlusPlusToken, ts.SyntaxKind.MinusMinusToken].includes(child.operator)) invalidate(child.operand);
232
+ if (ts.isIdentifier(child)) {
233
+ for (const decl of checker.getSymbolAtLocation(child)?.declarations ?? []) {
234
+ const owner = top(decl);
235
+ if (ts.isImportDeclaration(owner)) {
236
+ if (!(ts.isCallExpression(child.parent) && child.parent.expression === child)) escapes.add(owner);
237
+ const names = imports.get(owner) ?? new Set<string>();
238
+ names.add(ts.isImportSpecifier(decl) ? (decl.propertyName ?? decl.name).text :
239
+ ts.isImportClause(decl) ? "default" : "*");
240
+ imports.set(owner, names);
241
+ } else if (owner !== node && !(owner.pos <= node.pos && owner.end >= node.end) && source.statements.includes(owner as ts.Statement)) {
242
+ locals.add(owner);
243
+ if (!(ts.isCallExpression(child.parent) && child.parent.expression === child)) escapes.add(owner);
244
+ }
245
+ }
246
+ }
247
+ ts.forEachChild(child, visit);
248
+ };
249
+ if (signatureNodes) signatureNodes.forEach(visit); else visit(node);
250
+ return { locals: [...locals], imports, calls, escapes, prunedBranches };
251
+ },
252
+ exported(name: string) {
253
+ return source.statements.find(node => {
254
+ const modifiers = ts.canHaveModifiers(node) ? ts.getModifiers(node) : undefined;
255
+ if (!modifiers?.some(m => m.kind === ts.SyntaxKind.ExportKeyword)) return false;
256
+ if (name === "default") return modifiers.some(m => m.kind === ts.SyntaxKind.DefaultKeyword);
257
+ if (ts.isVariableStatement(node)) return node.declarationList.declarations.some(d => ts.isIdentifier(d.name) && d.name.text === name);
258
+ return "name" in node && (node as unknown as ts.NamedDeclaration).name?.getText(source) === name;
259
+ });
260
+ },
261
+ };
262
+ }
@@ -1,22 +1,34 @@
1
- import { appendFileSync, existsSync, mkdirSync, renameSync, statSync } from "node:fs";
1
+ import { appendFileSync, existsSync, renameSync, statSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
 
4
+ export interface SeptumToolCallMetrics {
5
+ bytes_out?: number;
6
+ lines_out?: number;
7
+ estimated_tokens?: number;
8
+ nodes_returned?: number;
9
+ }
10
+
11
+ export interface SeptumOutputDigest {
12
+ summary?: string;
13
+ sample_preview?: string;
14
+ }
15
+
4
16
  export interface SeptumToolCallEvent {
5
17
  timestamp?: string;
6
18
  event: "tool_call_completed" | "tool_call_failed";
7
19
  tool: string;
20
+ action?: string;
8
21
  duration_ms: number;
9
22
  input: Record<string, any>;
10
- metrics?: {
11
- bytes_out?: number;
12
- lines_out?: number;
13
- nodes_returned?: number;
14
- };
23
+ metrics?: SeptumToolCallMetrics;
24
+ bloat_alert?: boolean;
25
+ output_digest?: SeptumOutputDigest;
15
26
  session?: {
16
27
  feature_key?: string | null;
17
28
  domain?: string | null;
18
29
  } | null;
19
30
  status: "success" | "error";
31
+ outcome?: string;
20
32
  error?: {
21
33
  code?: string;
22
34
  message: string;
@@ -25,8 +37,32 @@ export interface SeptumToolCallEvent {
25
37
  }
26
38
 
27
39
  export class SeptumTelemetry {
28
- private static readonly MAX_LOG_SIZE_BYTES = 2 * 1024 * 1024; // 2MB
29
- private static readonly SLOW_EXECUTION_THRESHOLD_MS = 250;
40
+ public static readonly MAX_LOG_SIZE_BYTES = 2 * 1024 * 1024; // 2MB
41
+ public static readonly SLOW_EXECUTION_THRESHOLD_MS = 250;
42
+ public static readonly BLOAT_BYTE_THRESHOLD = 16 * 1024; // Serialized output byte threshold.
43
+
44
+ /**
45
+ * Generates a concise sample preview of output content to inspect payload relevancy and bloat.
46
+ */
47
+ public static createOutputDigest(text: string, maxPreviewChars = 300): SeptumOutputDigest {
48
+ const trimmed = text.trim();
49
+ if (!trimmed) {
50
+ return { summary: "empty_output" };
51
+ }
52
+
53
+ let samplePreview = trimmed;
54
+ if (trimmed.length > maxPreviewChars) {
55
+ const head = trimmed.slice(0, 200).replace(/\s+/g, " ");
56
+ const tail = trimmed.slice(-80).replace(/\s+/g, " ");
57
+ samplePreview = `${head} ... [${trimmed.length - 280} chars omitted] ... ${tail}`;
58
+ } else {
59
+ samplePreview = trimmed.replace(/\s+/g, " ");
60
+ }
61
+
62
+ return {
63
+ sample_preview: samplePreview,
64
+ };
65
+ }
30
66
 
31
67
  /**
32
68
  * Resolves the log file path inside the active workspace's .septum directory.
@@ -42,16 +78,25 @@ export class SeptumTelemetry {
42
78
  event: SeptumToolCallEvent,
43
79
  workspaceRoot: string = process.cwd()
44
80
  ): void {
81
+ const debug = process.env.SEPTUM_DEBUG_TELEMETRY === "1";
82
+ const input = Object.fromEntries(Object.entries(event.input).filter(([key, value]) =>
83
+ ["include_source", "include_dependencies", "limit", "max_depth", "budget_bytes", "source_line_limit", "semantic_depth", "ingest_now", "staged"].includes(key) && (typeof value === "number" || typeof value === "boolean") ||
84
+ ["action", "scope", "detail_level", "context_mode"].includes(key) && typeof value === "string" && ["locate", "context", "inspect", "impact", "catalog", "register", "file", "staged", "all", "domain", "compact", "full", "deep", "source"].includes(value)));
45
85
  const payload: SeptumToolCallEvent = {
46
86
  timestamp: event.timestamp || new Date().toISOString(),
47
87
  ...event,
88
+ input: debug ? event.input : input,
89
+ output_digest: debug ? event.output_digest : undefined,
90
+ error: event.error && !debug ? { message: "Tool execution failed; inspect the tool response for details.", code: event.error.code } : event.error,
48
91
  };
49
92
 
50
93
  const jsonLine = JSON.stringify(payload);
51
94
 
52
- // Sink 1: Live stderr stream for operator monitoring (slow queries & failures)
95
+ // Sink 1: Live stderr stream for operator monitoring (slow queries, bloat alerts & failures)
53
96
  if (payload.status === "error") {
54
97
  console.error(`[Septum Telemetry ERROR] ${jsonLine}`);
98
+ } else if (payload.bloat_alert) {
99
+ console.error(`[Septum Telemetry BLOAT_WARN] Tool '${payload.tool}' output exceeds configured byte threshold (${payload.metrics?.bytes_out} bytes)`);
55
100
  } else if (payload.duration_ms >= this.SLOW_EXECUTION_THRESHOLD_MS) {
56
101
  console.error(`[Septum Telemetry SLOW_WARN] ${jsonLine}`);
57
102
  }
package/src/index.ts CHANGED
@@ -9,9 +9,6 @@ export * from "./core/ingestion/pipeline.ts";
9
9
  export * from "./core/boundary/evaluator.ts";
10
10
  export * from "./core/resolver/call-graph-tracer.ts";
11
11
  export * from "./core/resolver/vertical-slice-tracer.ts";
12
- export * from "./core/topology/types.ts";
13
- export * from "./core/topology/environment-detector.ts";
14
- export * from "./mcp/tools/get-environment-topology.ts";
15
12
  export * from "./mcp/server.ts";
16
13
  export * from "./cli/index.ts";
17
14