septum 0.1.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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +100 -0
  3. package/bin/septum.ts +4 -0
  4. package/package.json +62 -0
  5. package/src/cli/commands/check.ts +161 -0
  6. package/src/cli/commands/hook.ts +188 -0
  7. package/src/cli/commands/ingest.ts +29 -0
  8. package/src/cli/commands/init.ts +211 -0
  9. package/src/cli/commands/locate.ts +61 -0
  10. package/src/cli/commands/query.ts +64 -0
  11. package/src/cli/commands/serve.ts +5 -0
  12. package/src/cli/commands/slice.ts +90 -0
  13. package/src/cli/commands/sync.ts +31 -0
  14. package/src/cli/index.ts +178 -0
  15. package/src/cli/templates/hooks.ts +75 -0
  16. package/src/cli/templates/rules.ts +38 -0
  17. package/src/cli/templates/skill.ts +66 -0
  18. package/src/core/boundary/evaluator.ts +210 -0
  19. package/src/core/config/loader.ts +84 -0
  20. package/src/core/config/schema.ts +39 -0
  21. package/src/core/database/client.ts +132 -0
  22. package/src/core/database/repositories/dependency.repository.ts +279 -0
  23. package/src/core/database/repositories/domain.repository.ts +198 -0
  24. package/src/core/database/repositories/file.repository.ts +99 -0
  25. package/src/core/database/repositories/meta.repository.ts +33 -0
  26. package/src/core/database/repositories/symbol.repository.ts +424 -0
  27. package/src/core/database/repository.ts +242 -0
  28. package/src/core/database/schema.sql +92 -0
  29. package/src/core/discovery/topology-detector.ts +418 -0
  30. package/src/core/ingestion/hasher.ts +5 -0
  31. package/src/core/ingestion/pipeline.ts +438 -0
  32. package/src/core/parser/boundary-tracker.ts +128 -0
  33. package/src/core/parser/extractors/base.ts +60 -0
  34. package/src/core/parser/extractors/frontend.ts +194 -0
  35. package/src/core/parser/extractors/go.ts +176 -0
  36. package/src/core/parser/extractors/laravel-semantic.ts +426 -0
  37. package/src/core/parser/extractors/mcp-cli-semantic.ts +199 -0
  38. package/src/core/parser/extractors/nestjs-semantic.ts +119 -0
  39. package/src/core/parser/extractors/php.ts +149 -0
  40. package/src/core/parser/extractors/python.ts +226 -0
  41. package/src/core/parser/extractors/registry.ts +49 -0
  42. package/src/core/parser/extractors/semantic-extractor.interface.ts +21 -0
  43. package/src/core/parser/extractors/typescript.ts +177 -0
  44. package/src/core/parser/tree-sitter.ts +39 -0
  45. package/src/core/resolver/call-graph-tracer.ts +668 -0
  46. package/src/core/resolver/module-resolver.ts +323 -0
  47. package/src/core/resolver/symbol-locator.ts +405 -0
  48. package/src/core/resolver/vertical-slice-tracer.ts +236 -0
  49. package/src/core/session/session-manager.ts +56 -0
  50. package/src/core/telemetry/telemetry.ts +86 -0
  51. package/src/index.ts +18 -0
  52. package/src/mcp/schemas.ts +68 -0
  53. package/src/mcp/server.ts +602 -0
  54. package/src/mcp/tools/check-boundary.ts +102 -0
  55. package/src/mcp/tools/get-domain-catalog.ts +91 -0
  56. package/src/mcp/tools/get-feature-context.ts +116 -0
  57. package/src/mcp/tools/get-symbol-hotspots.ts +49 -0
  58. package/src/mcp/tools/get-symbol-impact.ts +26 -0
  59. package/src/mcp/tools/get-symbol.ts +63 -0
  60. package/src/mcp/tools/locate-symbol.ts +74 -0
  61. package/src/mcp/tools/register-domain.ts +64 -0
  62. package/src/mcp/tools/trace-vertical-slice.ts +102 -0
  63. package/src/types/index.ts +296 -0
@@ -0,0 +1,86 @@
1
+ import { appendFileSync, existsSync, mkdirSync, renameSync, statSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+
4
+ export interface SeptumToolCallEvent {
5
+ timestamp?: string;
6
+ event: "tool_call_completed" | "tool_call_failed";
7
+ tool: string;
8
+ duration_ms: number;
9
+ input: Record<string, any>;
10
+ metrics?: {
11
+ bytes_out?: number;
12
+ lines_out?: number;
13
+ nodes_returned?: number;
14
+ };
15
+ session?: {
16
+ feature_key?: string | null;
17
+ domain?: string | null;
18
+ } | null;
19
+ status: "success" | "error";
20
+ error?: {
21
+ code?: string;
22
+ message: string;
23
+ stack?: string;
24
+ };
25
+ }
26
+
27
+ export class SeptumTelemetry {
28
+ private static readonly MAX_LOG_SIZE_BYTES = 2 * 1024 * 1024; // 2MB
29
+ private static readonly SLOW_EXECUTION_THRESHOLD_MS = 250;
30
+
31
+ /**
32
+ * Resolves the log file path inside the active workspace's .septum directory.
33
+ */
34
+ public static getLogPath(workspaceRoot: string = process.cwd()): string {
35
+ return join(workspaceRoot, ".septum", "septum.log");
36
+ }
37
+
38
+ /**
39
+ * Records a tool call event to both stderr (dual-sink) and .septum/septum.log.
40
+ */
41
+ public static recordToolCall(
42
+ event: SeptumToolCallEvent,
43
+ workspaceRoot: string = process.cwd()
44
+ ): 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
+ }
58
+
59
+ // Sink 2: Append-only persistent file recorder in .septum/septum.log
60
+ try {
61
+ const logPath = this.getLogPath(workspaceRoot);
62
+ const logDir = dirname(logPath);
63
+
64
+ if (!existsSync(logDir)) {
65
+ mkdirSync(logDir, { recursive: true });
66
+ }
67
+
68
+ // Check for rotation if file exceeds 2MB
69
+ if (existsSync(logPath)) {
70
+ try {
71
+ const stats = statSync(logPath);
72
+ if (stats.size >= this.MAX_LOG_SIZE_BYTES) {
73
+ const rotatedPath = `${logPath}.1`;
74
+ renameSync(logPath, rotatedPath);
75
+ }
76
+ } catch {
77
+ // If stat/rotation fails, proceed to append without crashing
78
+ }
79
+ }
80
+
81
+ appendFileSync(logPath, `${jsonLine}\n`, "utf8");
82
+ } catch {
83
+ // Telemetry file writes must never crash the main application process
84
+ }
85
+ }
86
+ }
package/src/index.ts ADDED
@@ -0,0 +1,18 @@
1
+ export * from "./types/index.ts";
2
+ export * from "./core/config/schema.ts";
3
+ export * from "./core/config/loader.ts";
4
+ export * from "./core/database/client.ts";
5
+ export * from "./core/database/repository.ts";
6
+ export * from "./core/parser/extractors/base.ts";
7
+ export * from "./core/parser/tree-sitter.ts";
8
+ export * from "./core/ingestion/pipeline.ts";
9
+ export * from "./core/boundary/evaluator.ts";
10
+ export * from "./core/resolver/call-graph-tracer.ts";
11
+ export * from "./core/resolver/vertical-slice-tracer.ts";
12
+ export * from "./mcp/server.ts";
13
+ export * from "./cli/index.ts";
14
+
15
+ import { runCLI } from "./cli/index.ts";
16
+ if (import.meta.main) {
17
+ runCLI(process.argv);
18
+ }
@@ -0,0 +1,68 @@
1
+ import { z } from "zod";
2
+
3
+ export const GetDomainCatalogSchema = z.object({
4
+ domain: z.string().optional(),
5
+ archetype: z.string().optional(),
6
+ });
7
+ export type GetDomainCatalogArgs = z.infer<typeof GetDomainCatalogSchema>;
8
+
9
+ export const GetFeatureContextSchema = z.object({
10
+ feature: z.string().min(1, "feature is required"),
11
+ });
12
+ export type GetFeatureContextArgs = z.infer<typeof GetFeatureContextSchema>;
13
+
14
+ export const LocateSymbolSchema = z.object({
15
+ query: z.string().min(1, "query is required"),
16
+ domain: z.string().optional(),
17
+ limit: z.number().int().positive().optional().default(10),
18
+ });
19
+ export type LocateSymbolArgs = z.infer<typeof LocateSymbolSchema>;
20
+
21
+ export const GetSymbolSchema = z.object({
22
+ symbol: z.string().min(1, "symbol is required"),
23
+ domain: z.string().optional(),
24
+ include_dependencies: z.boolean().optional().default(true),
25
+ });
26
+ export type GetSymbolArgs = z.infer<typeof GetSymbolSchema>;
27
+
28
+ export const GetSymbolImpactSchema = z.object({
29
+ symbol: z.string().min(1, "symbol is required"),
30
+ });
31
+ export type GetSymbolImpactArgs = z.infer<typeof GetSymbolImpactSchema>;
32
+
33
+ export const TraceVerticalSliceSchema = z.object({
34
+ query: z.string().min(1, "query is required"),
35
+ max_depth: z.number().int().positive().optional().default(5),
36
+ });
37
+ export type TraceVerticalSliceArgs = z.infer<typeof TraceVerticalSliceSchema>;
38
+
39
+ export const CheckBoundarySchema = z.object({
40
+ file_path: z.string().optional(),
41
+ file_paths: z.array(z.string()).optional(),
42
+ proposed_imports: z.array(z.string()).default([]),
43
+ feature_key: z.string().optional(),
44
+ });
45
+ export type CheckBoundaryArgs = z.infer<typeof CheckBoundarySchema>;
46
+
47
+ export const GetSymbolHotspotsSchema = z.object({
48
+ domain: z.string().optional(),
49
+ limit: z.number().int().positive().optional().default(10),
50
+ });
51
+ export type GetSymbolHotspotsArgs = z.infer<typeof GetSymbolHotspotsSchema>;
52
+
53
+ export const RegisterDomainSchema = z.object({
54
+ name: z.string().min(1, "Domain name is required"),
55
+ root: z.string().min(1, "Domain root path is required"),
56
+ description: z.string().optional(),
57
+ allowed_dependencies: z.array(z.string()).optional(),
58
+ forbidden_dependencies: z.array(z.string()).optional(),
59
+ archetypes: z.record(z.string()).optional(),
60
+ ingest_now: z.boolean().optional().default(false),
61
+ });
62
+ export type RegisterDomainArgs = z.infer<typeof RegisterDomainSchema>;
63
+
64
+ export const AutoDiscoverDomainsSchema = z.object({
65
+ persist: z.boolean().optional().default(true),
66
+ });
67
+ export type AutoDiscoverDomainsArgs = z.infer<typeof AutoDiscoverDomainsSchema>;
68
+