@dimassetoid/septum-mcp 0.2.1 → 0.5.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 (161) hide show
  1. package/README.md +46 -45
  2. package/package.json +8 -6
  3. package/src/cli/commands/check.ts +41 -26
  4. package/src/cli/commands/hook.ts +77 -105
  5. package/src/cli/commands/init.ts +35 -9
  6. package/src/cli/commands/stats.ts +33 -0
  7. package/src/cli/commands/sync-progress.ts +71 -0
  8. package/src/cli/commands/sync.ts +35 -9
  9. package/src/cli/hook-payload.ts +43 -0
  10. package/src/cli/index.ts +15 -51
  11. package/src/cli/scaffold/harness-config.ts +48 -8
  12. package/src/cli/templates/hooks.ts +51 -27
  13. package/src/cli/templates/rules.ts +34 -49
  14. package/src/cli/templates/skill.ts +46 -35
  15. package/src/core/boundary/audit.ts +383 -0
  16. package/src/core/boundary/evaluator.ts +299 -178
  17. package/src/core/boundary/staged-auditor.ts +188 -34
  18. package/src/core/config/domain-ownership.ts +47 -0
  19. package/src/core/config/domain-registration.ts +141 -0
  20. package/src/core/config/loader.ts +82 -54
  21. package/src/core/config/schema.ts +24 -46
  22. package/src/core/database/client.ts +2 -0
  23. package/src/core/database/repositories/dependency.repository.ts +326 -543
  24. package/src/core/database/repositories/domain.repository.ts +48 -4
  25. package/src/core/database/repositories/file.repository.ts +10 -0
  26. package/src/core/database/repositories/symbol.repository.ts +97 -259
  27. package/src/core/database/repository.ts +138 -24
  28. package/src/core/database/schema.ts +28 -33
  29. package/src/core/discovery/declarative-routes.ts +69 -0
  30. package/src/core/discovery/framework-detector.ts +149 -0
  31. package/src/core/discovery/navigation.ts +269 -0
  32. package/src/core/discovery/topology-detector.ts +153 -170
  33. package/src/core/errors.ts +19 -0
  34. package/src/core/ingestion/pipeline.ts +378 -212
  35. package/src/core/parser/behavioral-analyzer.ts +26 -22
  36. package/src/core/parser/boundary-tracker.ts +15 -0
  37. package/src/core/parser/extractors/base.ts +16 -4
  38. package/src/core/parser/extractors/csharp.ts +9 -5
  39. package/src/core/parser/extractors/django-routing.ts +163 -0
  40. package/src/core/parser/extractors/django-semantic.ts +400 -516
  41. package/src/core/parser/extractors/elysia-semantic.ts +172 -496
  42. package/src/core/parser/extractors/express-semantic.ts +195 -398
  43. package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
  44. package/src/core/parser/extractors/fastify-semantic.ts +216 -732
  45. package/src/core/parser/extractors/flask-semantic.ts +92 -388
  46. package/src/core/parser/extractors/go-routing.ts +344 -0
  47. package/src/core/parser/extractors/go-semantic.ts +210 -508
  48. package/src/core/parser/extractors/go.ts +6 -3
  49. package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
  50. package/src/core/parser/extractors/hono-semantic.ts +132 -530
  51. package/src/core/parser/extractors/java.ts +7 -5
  52. package/src/core/parser/extractors/laravel-routing.ts +263 -0
  53. package/src/core/parser/extractors/laravel-semantic.ts +169 -333
  54. package/src/core/parser/extractors/manifest-helpers.ts +64 -0
  55. package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
  56. package/src/core/parser/extractors/mcp-cli-semantic.ts +84 -336
  57. package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
  58. package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
  59. package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
  60. package/src/core/parser/extractors/php.ts +17 -1
  61. package/src/core/parser/extractors/python-route-ast.ts +249 -0
  62. package/src/core/parser/extractors/python.ts +9 -8
  63. package/src/core/parser/extractors/registry.ts +28 -5
  64. package/src/core/parser/extractors/route-prefixes.ts +43 -0
  65. package/src/core/parser/extractors/ruby.ts +10 -7
  66. package/src/core/parser/extractors/rust.ts +35 -17
  67. package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
  68. package/src/core/parser/extractors/symfony-routing.ts +114 -0
  69. package/src/core/parser/extractors/symfony-semantic.ts +75 -262
  70. package/src/core/parser/extractors/typescript-bindings.ts +333 -0
  71. package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
  72. package/src/core/parser/extractors/typescript-fallback.ts +207 -0
  73. package/src/core/parser/extractors/typescript-route-context.ts +58 -0
  74. package/src/core/parser/extractors/typescript.ts +36 -216
  75. package/src/core/parser/implementation-fingerprint.ts +97 -0
  76. package/src/core/parser/language-capabilities.ts +23 -7
  77. package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
  78. package/src/core/parser/schema/schema-provider-registry.ts +1 -3
  79. package/src/core/parser/schema/schema-provider.interface.ts +2 -1
  80. package/src/core/parser/semantic-revision.ts +3 -0
  81. package/src/core/parser/static-string.ts +51 -0
  82. package/src/core/parser/wasm-loader.ts +6 -2
  83. package/src/core/resolver/ast-method-tracer.ts +230 -0
  84. package/src/core/resolver/call-graph-helpers.ts +72 -0
  85. package/src/core/resolver/call-graph-tracer.ts +375 -311
  86. package/src/core/resolver/dependency-analysis.ts +593 -0
  87. package/src/core/resolver/import-candidates.ts +120 -0
  88. package/src/core/resolver/import-evidence.ts +88 -0
  89. package/src/core/resolver/import-resolver.ts +162 -181
  90. package/src/core/resolver/interpretation-inputs.ts +65 -0
  91. package/src/core/resolver/languages/go.ts +103 -0
  92. package/src/core/resolver/languages/managed.ts +200 -0
  93. package/src/core/resolver/languages/python.ts +133 -0
  94. package/src/core/resolver/languages/ruby.ts +40 -0
  95. package/src/core/resolver/languages/rust.ts +127 -0
  96. package/src/core/resolver/languages/shared.ts +74 -0
  97. package/src/core/resolver/module-resolver.ts +18 -7
  98. package/src/core/resolver/path-resolver.ts +6 -3
  99. package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
  100. package/src/core/resolver/slice-catalog.ts +94 -0
  101. package/src/core/resolver/slice-format.ts +22 -0
  102. package/src/core/resolver/slice-selection.ts +237 -0
  103. package/src/core/resolver/symbol-impact.ts +477 -0
  104. package/src/core/resolver/symbol-locator.ts +82 -15
  105. package/src/core/resolver/vertical-slice-tracer.ts +57 -278
  106. package/src/core/resources/ignore.ts +21 -1
  107. package/src/core/resources/limits.ts +2 -1
  108. package/src/core/resources/source-files.ts +143 -20
  109. package/src/core/resources/source-inventory.ts +55 -0
  110. package/src/core/resources/work-queue.ts +167 -4
  111. package/src/core/retrieval/context-page.ts +116 -0
  112. package/src/core/retrieval/context.ts +457 -0
  113. package/src/core/retrieval/resolution-warnings.ts +21 -0
  114. package/src/core/retrieval/source-context.ts +448 -0
  115. package/src/core/retrieval/symbol-details.ts +453 -0
  116. package/src/core/retrieval/symbol-evidence.ts +97 -0
  117. package/src/core/retrieval/typescript-references.ts +293 -0
  118. package/src/core/retrieval/universal-context.ts +182 -0
  119. package/src/core/telemetry/summary.ts +114 -0
  120. package/src/core/telemetry/telemetry.ts +225 -37
  121. package/src/index.ts +0 -3
  122. package/src/mcp/formatters/compact-text.ts +439 -0
  123. package/src/mcp/resources-and-prompts.ts +253 -0
  124. package/src/mcp/schemas/boundary.ts +145 -0
  125. package/src/mcp/schemas/map.ts +250 -0
  126. package/src/mcp/schemas/shared.ts +52 -0
  127. package/src/mcp/schemas/slice.ts +60 -0
  128. package/src/mcp/schemas/symbol.ts +268 -0
  129. package/src/mcp/schemas.ts +5 -1105
  130. package/src/mcp/server.ts +263 -597
  131. package/src/mcp/tool-catalog.ts +331 -0
  132. package/src/mcp/tools/boundary.ts +69 -4
  133. package/src/mcp/tools/map.ts +126 -0
  134. package/src/mcp/tools/slice.ts +101 -3
  135. package/src/mcp/tools/symbol.ts +480 -26
  136. package/src/mcp/ui/app-client.ts +899 -0
  137. package/src/mcp/ui/app.html +478 -0
  138. package/src/mcp/workflow-playbooks.ts +181 -0
  139. package/src/mcp/workspace-boundary.ts +50 -0
  140. package/src/mcp/workspace-manager.ts +102 -18
  141. package/src/mcp/workspace-watcher.ts +38 -19
  142. package/src/types/index.ts +47 -53
  143. package/src/cli/commands/topology.ts +0 -161
  144. package/src/core/database/repositories/environment.repository.ts +0 -207
  145. package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
  146. package/src/core/session/session-manager.ts +0 -107
  147. package/src/core/topology/environment-detector.ts +0 -973
  148. package/src/core/topology/types.ts +0 -83
  149. package/src/mcp/tools/check-boundary.ts +0 -387
  150. package/src/mcp/tools/domain.ts +0 -40
  151. package/src/mcp/tools/feature.ts +0 -67
  152. package/src/mcp/tools/get-domain-catalog.ts +0 -226
  153. package/src/mcp/tools/get-environment-topology.ts +0 -138
  154. package/src/mcp/tools/get-feature-context.ts +0 -224
  155. package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
  156. package/src/mcp/tools/get-symbol-impact.ts +0 -64
  157. package/src/mcp/tools/get-symbol.ts +0 -175
  158. package/src/mcp/tools/locate-symbol.ts +0 -196
  159. package/src/mcp/tools/register-domain.ts +0 -75
  160. package/src/mcp/tools/register-feature.ts +0 -110
  161. package/src/mcp/tools/trace-vertical-slice.ts +0 -80
@@ -1,22 +1,46 @@
1
- import { appendFileSync, existsSync, mkdirSync, renameSync, statSync } from "node:fs";
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ import { appendFileSync, existsSync, renameSync, statSync } from "node:fs";
2
3
  import { dirname, join } from "node:path";
3
4
 
5
+ export interface SeptumToolCallMetrics {
6
+ bytes_out?: number;
7
+ lines_out?: number;
8
+ estimated_tokens?: number;
9
+ nodes_returned?: number;
10
+ response_bytes?: number;
11
+ }
12
+
13
+ export interface SeptumOutputDigest {
14
+ summary?: string;
15
+ sample_preview?: string;
16
+ }
17
+
18
+ export type ToolCallStage = "validation" | "workspace" | "execution" | "cancelled" | "timeout";
19
+
20
+ export interface ToolResponse {
21
+ content?: ReadonlyArray<{ text?: unknown }>;
22
+ metadata?: unknown;
23
+ isError?: boolean;
24
+ }
25
+
4
26
  export interface SeptumToolCallEvent {
27
+ trace_id?: string;
28
+ stage?: ToolCallStage;
5
29
  timestamp?: string;
6
30
  event: "tool_call_completed" | "tool_call_failed";
7
31
  tool: string;
32
+ action?: string;
8
33
  duration_ms: number;
9
34
  input: Record<string, any>;
10
- metrics?: {
11
- bytes_out?: number;
12
- lines_out?: number;
13
- nodes_returned?: number;
14
- };
35
+ metrics?: SeptumToolCallMetrics;
36
+ bloat_alert?: boolean;
37
+ output_digest?: SeptumOutputDigest;
15
38
  session?: {
16
39
  feature_key?: string | null;
17
40
  domain?: string | null;
18
41
  } | null;
19
42
  status: "success" | "error";
43
+ outcome?: string;
20
44
  error?: {
21
45
  code?: string;
22
46
  message: string;
@@ -24,9 +48,111 @@ export interface SeptumToolCallEvent {
24
48
  };
25
49
  }
26
50
 
51
+ const SAFE_ACTIONS = new Set(["locate", "context", "inspect", "impact", "catalog", "register", "file", "staged", "all", "domain", "compact", "full", "deep", "source"]);
52
+ const OUTCOMES = new Set(["success", "partial", "unknown", "approved", "rejected", "ambiguous", "not_found", "NOT_INDEXED", "stale_reference", "invalid_context_options", "budget_too_small"]);
53
+
54
+ function errorCodeFromMetadata(value: unknown): string | undefined {
55
+ if (!value || typeof value !== "object" || !("code" in value)) return;
56
+ const code = value.code;
57
+ return typeof code === "string" && /^[A-Z][A-Z0-9_]{0,63}$/.test(code) ? code : undefined;
58
+ }
59
+
60
+ function outcomeFrom(value: unknown): string | undefined {
61
+ if (!value || typeof value !== "object") return;
62
+ const record = value as Record<string, unknown>;
63
+ const status = record.status ?? (record.found === false ? "not_found" : undefined);
64
+ return typeof status === "string" && OUTCOMES.has(status) ? status : undefined;
65
+ }
66
+
67
+ export interface SeptumTraceContext {
68
+ traceId: string;
69
+ workspaceRoot?: string;
70
+ }
71
+
72
+ export type SeptumSystemLevel = "INFO" | "WARN" | "ERROR";
73
+
27
74
  export class SeptumTelemetry {
28
- private static readonly MAX_LOG_SIZE_BYTES = 2 * 1024 * 1024; // 2MB
29
- private static readonly SLOW_EXECUTION_THRESHOLD_MS = 250;
75
+ private static readonly traceStorage = new AsyncLocalStorage<SeptumTraceContext>();
76
+ public static readonly MAX_LOG_SIZE_BYTES = 2 * 1024 * 1024; // 2MB
77
+ public static readonly MAX_EVENT_BYTES = 4096;
78
+ public static readonly SLOW_EXECUTION_THRESHOLD_MS = 250;
79
+ public static readonly BLOAT_BYTE_THRESHOLD = 16 * 1024; // Serialized output byte threshold.
80
+
81
+ public static withTrace<T>(traceId: string, fn: () => T, workspaceRoot?: string): T {
82
+ return this.traceStorage.run({ traceId, workspaceRoot }, fn);
83
+ }
84
+
85
+ public static getActiveTraceContext(): SeptumTraceContext | undefined {
86
+ return this.traceStorage.getStore();
87
+ }
88
+
89
+ /**
90
+ * Generates a concise sample preview of output content to inspect payload relevancy and bloat.
91
+ */
92
+ public static createOutputDigest(text: string, maxPreviewChars = 300): SeptumOutputDigest {
93
+ const trimmed = text.trim();
94
+ if (!trimmed) {
95
+ return { summary: "empty_output" };
96
+ }
97
+
98
+ const preview = trimmed.replace(/\s+/g, " ");
99
+ const limit = Number.isFinite(maxPreviewChars) ? Math.max(0, Math.min(300, Math.floor(maxPreviewChars))) : 300;
100
+ if (preview.length <= limit) return { sample_preview: preview };
101
+ const marker = " ... [chars omitted] ... ";
102
+ const available = Math.max(0, limit - marker.length);
103
+ const head = Math.ceil(available / 2);
104
+ const tail = available - head;
105
+ return { sample_preview: (preview.slice(0, head) + marker + (tail ? preview.slice(-tail) : "")).slice(0, limit) };
106
+ }
107
+
108
+ public static recordToolResponse(
109
+ event: Omit<SeptumToolCallEvent, "event" | "status">,
110
+ response: ToolResponse,
111
+ workspaceRoot: string | null,
112
+ allowDetails = true,
113
+ ): void {
114
+ try {
115
+ let bytes = 0;
116
+ let lines = 0;
117
+ let preview = "";
118
+ let outcome = outcomeFrom(response.metadata);
119
+ const previewEnabled = allowDetails && (process.env.SEPTUM_LOG_PREVIEW === "1" || process.env.SEPTUM_DEBUG_TELEMETRY === "1");
120
+ for (const item of response.content ?? []) {
121
+ if (typeof item.text !== "string") continue;
122
+ const chunk = item.text;
123
+ bytes += Buffer.byteLength(chunk);
124
+ if (chunk.length > 0) {
125
+ lines++;
126
+ for (let i = 0; i < chunk.length; i++) if (chunk.charCodeAt(i) === 10) lines++;
127
+ }
128
+ if (previewEnabled && preview.length < 1500) preview += chunk.slice(0, 1500 - preview.length);
129
+ if (!outcome && chunk.length <= 65536 && chunk.trimStart().startsWith("{")) {
130
+ try { outcome = outcomeFrom(JSON.parse(chunk)); } catch { /* Text-only results have no structured outcome. */ }
131
+ }
132
+ }
133
+
134
+ const responseBytes = Buffer.byteLength(JSON.stringify(response));
135
+ this.recordToolCall({
136
+ ...event,
137
+ event: response.isError ? "tool_call_failed" : "tool_call_completed",
138
+ status: response.isError ? "error" : "success",
139
+ outcome,
140
+ metrics: { bytes_out: bytes, lines_out: lines, estimated_tokens: Math.round(bytes / 4), response_bytes: responseBytes },
141
+ bloat_alert: responseBytes >= this.BLOAT_BYTE_THRESHOLD,
142
+ output_digest: previewEnabled ? this.createOutputDigest(preview) : undefined,
143
+ error: response.isError ? {
144
+ message: event.error?.message ?? "Tool returned an error.",
145
+ stack: event.error?.stack,
146
+ code: event.error?.code ?? errorCodeFromMetadata(response.metadata) ?? (event.stage === "validation" ? "INVALID_ARGUMENT" :
147
+ event.stage === "workspace" ? "WORKSPACE_ERROR" :
148
+ event.stage === "cancelled" ? "REQUEST_CANCELLED" :
149
+ event.stage === "timeout" ? "REQUEST_TIMEOUT" : "TOOL_ERROR"),
150
+ } : undefined,
151
+ }, workspaceRoot, allowDetails);
152
+ } catch {
153
+ // Measurement failures cannot change the public response.
154
+ }
155
+ }
30
156
 
31
157
  /**
32
158
  * Resolves the log file path inside the active workspace's .septum directory.
@@ -40,31 +166,102 @@ export class SeptumTelemetry {
40
166
  */
41
167
  public static recordToolCall(
42
168
  event: SeptumToolCallEvent,
43
- workspaceRoot: string = process.cwd()
169
+ workspaceRoot: string | null = process.cwd(),
170
+ allowDetails = true,
44
171
  ): void {
45
- const payload: SeptumToolCallEvent = {
46
- timestamp: event.timestamp || new Date().toISOString(),
47
- ...event,
48
- };
49
-
50
- const jsonLine = JSON.stringify(payload);
51
-
52
- // Sink 1: Live stderr stream for operator monitoring (slow queries & failures)
53
- if (payload.status === "error") {
54
- console.error(`[Septum Telemetry ERROR] ${jsonLine}`);
55
- } else if (payload.duration_ms >= this.SLOW_EXECUTION_THRESHOLD_MS) {
56
- console.error(`[Septum Telemetry SLOW_WARN] ${jsonLine}`);
57
- }
172
+ try {
173
+ const debug = allowDetails && process.env.SEPTUM_DEBUG_TELEMETRY === "1";
174
+ const rawInput = allowDetails && (debug || process.env.SEPTUM_LOG_INPUT === "1");
175
+ const preview = allowDetails && (debug || process.env.SEPTUM_LOG_PREVIEW === "1");
176
+ const errorDetails = allowDetails && (debug || process.env.SEPTUM_LOG_ERROR_DETAILS === "1");
177
+ const safeInput = Object.fromEntries(Object.entries(event.input).filter(([key, value]) =>
178
+ ["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") ||
179
+ ["action", "scope", "detail_level", "context_mode"].includes(key) && typeof value === "string" && SAFE_ACTIONS.has(value)));
180
+ const payload: SeptumToolCallEvent = {
181
+ ...event,
182
+ timestamp: event.timestamp ?? new Date().toISOString(),
183
+ tool: event.tool.slice(0, 64),
184
+ action: event.action && SAFE_ACTIONS.has(event.action) ? event.action : undefined,
185
+ input: rawInput ? event.input : safeInput,
186
+ output_digest: preview ? event.output_digest : undefined,
187
+ error: event.error && {
188
+ code: event.error.code?.slice(0, 64),
189
+ message: errorDetails ? event.error.message.slice(0, 512) : "Tool execution failed; inspect the tool response for details.",
190
+ stack: errorDetails ? event.error.stack?.slice(0, 1024) : undefined,
191
+ },
192
+ };
58
193
 
59
- this.appendLog(jsonLine, workspaceRoot);
194
+ let jsonLine = JSON.stringify(payload);
195
+ if (Buffer.byteLength(jsonLine) + 1 > this.MAX_EVENT_BYTES) {
196
+ payload.input = safeInput;
197
+ payload.output_digest = undefined;
198
+ if (payload.error) {
199
+ delete payload.error.stack;
200
+ payload.error.message = "Tool execution failed; inspect the tool response for details.";
201
+ }
202
+ jsonLine = JSON.stringify(payload);
203
+ }
204
+ if (Buffer.byteLength(jsonLine) + 1 > this.MAX_EVENT_BYTES) return;
205
+
206
+ const severity = payload.status === "error" ? "ERROR" :
207
+ payload.bloat_alert ? "BLOAT_WARN" :
208
+ payload.duration_ms >= this.SLOW_EXECUTION_THRESHOLD_MS ? "SLOW_WARN" : undefined;
209
+ if (severity) this.writeStderr(`[Septum Telemetry ${severity}] ${jsonLine}`);
210
+ if (workspaceRoot) this.appendLog(jsonLine, workspaceRoot);
211
+ } catch {
212
+ // Serialization failures cannot change tool execution.
213
+ }
60
214
  }
61
215
 
62
216
  public static recordMemorySample(metrics: Record<string, number>, workspaceRoot: string = process.cwd()): void {
63
- const jsonLine = JSON.stringify({timestamp: new Date().toISOString(), event: "memory_sample", metrics});
64
- console.error(`[Septum Memory] ${jsonLine}`);
217
+ const jsonLine = JSON.stringify({ timestamp: new Date().toISOString(), event: "memory_sample", metrics });
218
+ this.writeStderr(`[Septum Memory] ${jsonLine}`);
65
219
  this.appendLog(jsonLine, workspaceRoot);
66
220
  }
67
221
 
222
+ public static recordSystemEvent(options: {
223
+ level: SeptumSystemLevel;
224
+ component: string;
225
+ event: string;
226
+ fields?: Record<string, unknown>;
227
+ workspaceRoot?: string | null;
228
+ emitStderr?: boolean;
229
+ }): void {
230
+ try {
231
+ const ctx = this.traceStorage.getStore();
232
+ const root = options.workspaceRoot !== undefined ? options.workspaceRoot : ctx?.workspaceRoot;
233
+ const payload: Record<string, unknown> = {
234
+ timestamp: new Date().toISOString(),
235
+ severity_text: options.level,
236
+ ...(ctx?.traceId ? { trace_id: ctx.traceId } : {}),
237
+ component: options.component.slice(0, 64),
238
+ event: options.event.slice(0, 64),
239
+ ...(options.fields ?? {}),
240
+ };
241
+ let jsonLine = JSON.stringify(payload);
242
+ if (Buffer.byteLength(jsonLine) + 1 > this.MAX_EVENT_BYTES) {
243
+ jsonLine = JSON.stringify({
244
+ timestamp: payload.timestamp,
245
+ severity_text: options.level,
246
+ ...(ctx?.traceId ? { trace_id: ctx.traceId } : {}),
247
+ component: payload.component,
248
+ event: payload.event,
249
+ truncated: true,
250
+ });
251
+ }
252
+ if (options.emitStderr !== false && (options.level === "WARN" || options.level === "ERROR")) {
253
+ this.writeStderr(`[Septum ${options.component} ${options.level}] ${jsonLine}`);
254
+ }
255
+ if (root) this.appendLog(jsonLine, root);
256
+ } catch {
257
+ // Telemetry failures must never disrupt caller execution.
258
+ }
259
+ }
260
+
261
+ private static writeStderr(message: string): void {
262
+ try { console.error(message); } catch { /* Keep file logging independent. */ }
263
+ }
264
+
68
265
  private static appendLog(jsonLine: string, workspaceRoot: string): void {
69
266
  // Sink 2: Append-only persistent file recorder in .septum/septum.log
70
267
  try {
@@ -76,20 +273,11 @@ export class SeptumTelemetry {
76
273
  return;
77
274
  }
78
275
 
79
- // Check for rotation if file exceeds 2MB
80
- if (existsSync(logPath)) {
81
- try {
82
- const stats = statSync(logPath);
83
- if (stats.size >= this.MAX_LOG_SIZE_BYTES) {
84
- const rotatedPath = `${logPath}.1`;
85
- renameSync(logPath, rotatedPath);
86
- }
87
- } catch {
88
- // If stat/rotation fails, proceed to append without crashing
89
- }
276
+ if (existsSync(logPath) && statSync(logPath).size + Buffer.byteLength(jsonLine) + 1 > this.MAX_LOG_SIZE_BYTES) {
277
+ renameSync(logPath, `${logPath}.1`);
90
278
  }
91
279
 
92
- appendFileSync(logPath, `${jsonLine}\n`, "utf8");
280
+ appendFileSync(logPath, `${jsonLine}\n`, { encoding: "utf8", mode: 0o600 });
93
281
  } catch {
94
282
  // Telemetry file writes must never crash the main application process
95
283
  }
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