@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.
- package/README.md +46 -28
- package/package.json +4 -4
- package/src/cli/commands/check.ts +27 -16
- package/src/cli/commands/hook.ts +38 -101
- package/src/cli/commands/init.ts +26 -9
- package/src/cli/commands/sync.ts +4 -6
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +9 -52
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +49 -14
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +39 -35
- package/src/core/boundary/evaluator.ts +67 -83
- package/src/core/boundary/staged-auditor.ts +102 -40
- package/src/core/config/domain-ownership.ts +45 -0
- package/src/core/config/loader.ts +81 -29
- package/src/core/config/schema.ts +0 -10
- package/src/core/database/repositories/dependency.repository.ts +169 -148
- package/src/core/database/repositories/domain.repository.ts +46 -3
- package/src/core/database/repositories/symbol.repository.ts +226 -87
- package/src/core/database/repository.ts +73 -18
- package/src/core/database/schema.ts +2 -33
- package/src/core/discovery/navigation.ts +105 -0
- package/src/core/discovery/topology-detector.ts +60 -2
- package/src/core/ingestion/pipeline.ts +96 -129
- package/src/core/parser/behavioral-analyzer.ts +26 -22
- package/src/core/parser/boundary-tracker.ts +15 -0
- package/src/core/parser/extractors/base.ts +7 -3
- package/src/core/parser/extractors/csharp.ts +7 -3
- package/src/core/parser/extractors/django-semantic.ts +4 -36
- package/src/core/parser/extractors/elysia-semantic.ts +3 -24
- package/src/core/parser/extractors/express-semantic.ts +3 -18
- package/src/core/parser/extractors/fastapi-semantic.ts +19 -53
- package/src/core/parser/extractors/fastify-semantic.ts +3 -18
- package/src/core/parser/extractors/flask-semantic.ts +22 -55
- package/src/core/parser/extractors/go-semantic.ts +92 -33
- package/src/core/parser/extractors/hono-semantic.ts +3 -24
- package/src/core/parser/extractors/java.ts +5 -3
- package/src/core/parser/extractors/laravel-semantic.ts +44 -16
- package/src/core/parser/extractors/mcp-cli-semantic.ts +6 -7
- package/src/core/parser/extractors/nestjs-semantic.ts +3 -19
- package/src/core/parser/extractors/php.ts +16 -0
- package/src/core/parser/extractors/python.ts +9 -4
- package/src/core/parser/extractors/registry.ts +26 -5
- package/src/core/parser/extractors/ruby.ts +8 -5
- package/src/core/parser/extractors/rust.ts +31 -13
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-semantic.ts +4 -37
- package/src/core/parser/extractors/typescript.ts +14 -1
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +23 -7
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +73 -50
- package/src/core/parser/schema/schema-provider-registry.ts +1 -3
- package/src/core/parser/schema/schema-provider.interface.ts +2 -1
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- package/src/core/resolver/call-graph-tracer.ts +337 -28
- package/src/core/resolver/import-resolver.ts +107 -179
- package/src/core/resolver/interpretation-inputs.ts +7 -0
- package/src/core/resolver/languages/go.ts +103 -0
- package/src/core/resolver/languages/managed.ts +200 -0
- package/src/core/resolver/languages/python.ts +115 -0
- package/src/core/resolver/languages/ruby.ts +40 -0
- package/src/core/resolver/languages/rust.ts +127 -0
- package/src/core/resolver/languages/shared.ts +71 -0
- package/src/core/resolver/module-resolver.ts +8 -4
- package/src/core/resolver/slice-catalog.ts +79 -0
- package/src/core/resolver/slice-format.ts +9 -0
- package/src/core/resolver/symbol-impact.ts +381 -0
- package/src/core/resolver/vertical-slice-tracer.ts +93 -115
- package/src/core/resources/ignore.ts +22 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/retrieval/context-page.ts +109 -0
- package/src/core/retrieval/context.ts +320 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +262 -0
- package/src/core/telemetry/telemetry.ts +54 -9
- package/src/index.ts +0 -3
- package/src/mcp/schemas.ts +61 -420
- package/src/mcp/server.ts +116 -290
- package/src/mcp/tools/boundary.ts +2 -2
- package/src/mcp/tools/check-boundary.ts +55 -60
- package/src/mcp/tools/get-domain-catalog.ts +32 -219
- package/src/mcp/tools/get-symbol-impact.ts +45 -5
- package/src/mcp/tools/get-symbol.ts +227 -3
- package/src/mcp/tools/locate-symbol.ts +54 -14
- package/src/mcp/tools/{domain.ts → map.ts} +4 -18
- package/src/mcp/tools/register-domain.ts +41 -3
- package/src/mcp/tools/symbol.ts +23 -21
- package/src/mcp/tools/trace-vertical-slice.ts +36 -10
- package/src/mcp/workspace-manager.ts +15 -4
- package/src/mcp/workspace-watcher.ts +8 -8
- package/src/types/index.ts +35 -53
- package/src/cli/commands/topology.ts +0 -161
- package/src/core/database/repositories/environment.repository.ts +0 -207
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
- package/src/core/session/session-manager.ts +0 -107
- package/src/core/topology/environment-detector.ts +0 -973
- package/src/core/topology/types.ts +0 -83
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-environment-topology.ts +0 -138
- package/src/mcp/tools/get-feature-context.ts +0 -224
- package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
- package/src/mcp/tools/register-feature.ts +0 -110
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import type { Database } from "bun:sqlite";
|
|
2
|
-
import type { CanonicalPlatformTag, EnvironmentLayer, EnvironmentLayerInfo, TopologyNode } from "../../topology/types.ts";
|
|
3
|
-
|
|
4
|
-
export class EnvironmentRepository {
|
|
5
|
-
constructor(private db: Database) {}
|
|
6
|
-
|
|
7
|
-
public getLayer(layer: EnvironmentLayer): EnvironmentLayerInfo | null {
|
|
8
|
-
const row = this.db
|
|
9
|
-
.query<{
|
|
10
|
-
layer: string;
|
|
11
|
-
platform: string | null;
|
|
12
|
-
status: string;
|
|
13
|
-
detected_from_json: string;
|
|
14
|
-
constraints_json: string;
|
|
15
|
-
unresolved_inquiry: string | null;
|
|
16
|
-
}, [string]>("SELECT * FROM environment_topology WHERE layer = ?")
|
|
17
|
-
.get(layer);
|
|
18
|
-
|
|
19
|
-
if (!row) return null;
|
|
20
|
-
return {
|
|
21
|
-
layer: row.layer as EnvironmentLayer,
|
|
22
|
-
platform: row.platform ?? undefined,
|
|
23
|
-
status: row.status as any,
|
|
24
|
-
detected_from: JSON.parse(row.detected_from_json || "[]"),
|
|
25
|
-
constraints: JSON.parse(row.constraints_json || "[]"),
|
|
26
|
-
unresolved_inquiry: row.unresolved_inquiry ?? undefined,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public getAllLayers(): Record<EnvironmentLayer, EnvironmentLayerInfo> {
|
|
31
|
-
const rows = this.db
|
|
32
|
-
.query<{
|
|
33
|
-
layer: string;
|
|
34
|
-
platform: string | null;
|
|
35
|
-
status: string;
|
|
36
|
-
detected_from_json: string;
|
|
37
|
-
constraints_json: string;
|
|
38
|
-
unresolved_inquiry: string | null;
|
|
39
|
-
}, []>("SELECT * FROM environment_topology")
|
|
40
|
-
.all();
|
|
41
|
-
|
|
42
|
-
const result: Partial<Record<EnvironmentLayer, EnvironmentLayerInfo>> = {};
|
|
43
|
-
for (const row of rows) {
|
|
44
|
-
result[row.layer as EnvironmentLayer] = {
|
|
45
|
-
layer: row.layer as EnvironmentLayer,
|
|
46
|
-
platform: row.platform ?? undefined,
|
|
47
|
-
status: row.status as any,
|
|
48
|
-
detected_from: JSON.parse(row.detected_from_json || "[]"),
|
|
49
|
-
constraints: JSON.parse(row.constraints_json || "[]"),
|
|
50
|
-
unresolved_inquiry: row.unresolved_inquiry ?? undefined,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
return result as Record<EnvironmentLayer, EnvironmentLayerInfo>;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
public saveLayer(info: EnvironmentLayerInfo): void {
|
|
57
|
-
this.db
|
|
58
|
-
.query(
|
|
59
|
-
`INSERT INTO environment_topology (
|
|
60
|
-
layer, platform, status, detected_from_json, constraints_json, unresolved_inquiry, updated_at
|
|
61
|
-
) VALUES (?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
|
62
|
-
ON CONFLICT(layer) DO UPDATE SET
|
|
63
|
-
platform = excluded.platform,
|
|
64
|
-
status = excluded.status,
|
|
65
|
-
detected_from_json = excluded.detected_from_json,
|
|
66
|
-
constraints_json = excluded.constraints_json,
|
|
67
|
-
unresolved_inquiry = excluded.unresolved_inquiry,
|
|
68
|
-
updated_at = CURRENT_TIMESTAMP`
|
|
69
|
-
)
|
|
70
|
-
.run(
|
|
71
|
-
info.layer,
|
|
72
|
-
info.platform ?? null,
|
|
73
|
-
info.status,
|
|
74
|
-
JSON.stringify(info.detected_from ?? []),
|
|
75
|
-
JSON.stringify(info.constraints ?? []),
|
|
76
|
-
info.unresolved_inquiry ?? null
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
public clearAll(): void {
|
|
81
|
-
this.db.run("DELETE FROM environment_topology");
|
|
82
|
-
this.db.run("DELETE FROM environment_nodes");
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Node CRUD operations for Multi-Node Topology
|
|
86
|
-
public getNode(id: string): TopologyNode | null {
|
|
87
|
-
const row = this.db
|
|
88
|
-
.query<{
|
|
89
|
-
id: string;
|
|
90
|
-
layer: string;
|
|
91
|
-
name: string;
|
|
92
|
-
platform: string;
|
|
93
|
-
canonical_tag: string;
|
|
94
|
-
domain_or_ip: string | null;
|
|
95
|
-
role: string | null;
|
|
96
|
-
status: string;
|
|
97
|
-
detected_from_json: string;
|
|
98
|
-
constraints_json: string;
|
|
99
|
-
connected_to_json: string;
|
|
100
|
-
unresolved_inquiry: string | null;
|
|
101
|
-
}, [string]>("SELECT * FROM environment_nodes WHERE id = ?")
|
|
102
|
-
.get(id);
|
|
103
|
-
|
|
104
|
-
if (!row) return null;
|
|
105
|
-
return this.mapNodeRow(row);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
public getAllNodes(): TopologyNode[] {
|
|
109
|
-
const rows = this.db
|
|
110
|
-
.query<{
|
|
111
|
-
id: string;
|
|
112
|
-
layer: string;
|
|
113
|
-
name: string;
|
|
114
|
-
platform: string;
|
|
115
|
-
canonical_tag: string;
|
|
116
|
-
domain_or_ip: string | null;
|
|
117
|
-
role: string | null;
|
|
118
|
-
status: string;
|
|
119
|
-
detected_from_json: string;
|
|
120
|
-
constraints_json: string;
|
|
121
|
-
connected_to_json: string;
|
|
122
|
-
unresolved_inquiry: string | null;
|
|
123
|
-
}, []>("SELECT * FROM environment_nodes ORDER BY layer, id")
|
|
124
|
-
.all();
|
|
125
|
-
|
|
126
|
-
return rows.map((r) => this.mapNodeRow(r));
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public getNodesByLayer(layer: EnvironmentLayer): TopologyNode[] {
|
|
130
|
-
const rows = this.db
|
|
131
|
-
.query<{
|
|
132
|
-
id: string;
|
|
133
|
-
layer: string;
|
|
134
|
-
name: string;
|
|
135
|
-
platform: string;
|
|
136
|
-
canonical_tag: string;
|
|
137
|
-
domain_or_ip: string | null;
|
|
138
|
-
role: string | null;
|
|
139
|
-
status: string;
|
|
140
|
-
detected_from_json: string;
|
|
141
|
-
constraints_json: string;
|
|
142
|
-
connected_to_json: string;
|
|
143
|
-
unresolved_inquiry: string | null;
|
|
144
|
-
}, [string]>("SELECT * FROM environment_nodes WHERE layer = ? ORDER BY id")
|
|
145
|
-
.all(layer);
|
|
146
|
-
|
|
147
|
-
return rows.map((r) => this.mapNodeRow(r));
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
public saveNode(node: TopologyNode): void {
|
|
151
|
-
this.db
|
|
152
|
-
.query(
|
|
153
|
-
`INSERT INTO environment_nodes (
|
|
154
|
-
id, layer, name, platform, canonical_tag, domain_or_ip, role, status,
|
|
155
|
-
detected_from_json, constraints_json, connected_to_json, unresolved_inquiry, updated_at
|
|
156
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP)
|
|
157
|
-
ON CONFLICT(id) DO UPDATE SET
|
|
158
|
-
layer = excluded.layer,
|
|
159
|
-
name = excluded.name,
|
|
160
|
-
platform = excluded.platform,
|
|
161
|
-
canonical_tag = excluded.canonical_tag,
|
|
162
|
-
domain_or_ip = excluded.domain_or_ip,
|
|
163
|
-
role = excluded.role,
|
|
164
|
-
status = excluded.status,
|
|
165
|
-
detected_from_json = excluded.detected_from_json,
|
|
166
|
-
constraints_json = excluded.constraints_json,
|
|
167
|
-
connected_to_json = excluded.connected_to_json,
|
|
168
|
-
unresolved_inquiry = excluded.unresolved_inquiry,
|
|
169
|
-
updated_at = CURRENT_TIMESTAMP`
|
|
170
|
-
)
|
|
171
|
-
.run(
|
|
172
|
-
node.id,
|
|
173
|
-
node.layer,
|
|
174
|
-
node.name,
|
|
175
|
-
node.platform,
|
|
176
|
-
node.canonical_tag || "unspecified",
|
|
177
|
-
node.domain_or_ip ?? null,
|
|
178
|
-
node.role ?? null,
|
|
179
|
-
node.status,
|
|
180
|
-
JSON.stringify(node.detected_from ?? []),
|
|
181
|
-
JSON.stringify(node.constraints ?? []),
|
|
182
|
-
JSON.stringify(node.connected_to ?? []),
|
|
183
|
-
node.unresolved_inquiry ?? null
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
public deleteNode(id: string): void {
|
|
188
|
-
this.db.query("DELETE FROM environment_nodes WHERE id = ?").run(id);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private mapNodeRow(row: any): TopologyNode {
|
|
192
|
-
return {
|
|
193
|
-
id: row.id,
|
|
194
|
-
layer: row.layer as EnvironmentLayer,
|
|
195
|
-
name: row.name,
|
|
196
|
-
platform: row.platform,
|
|
197
|
-
canonical_tag: (row.canonical_tag as CanonicalPlatformTag) || "unspecified",
|
|
198
|
-
domain_or_ip: row.domain_or_ip ?? undefined,
|
|
199
|
-
role: row.role ?? undefined,
|
|
200
|
-
status: row.status as any,
|
|
201
|
-
detected_from: JSON.parse(row.detected_from_json || "[]"),
|
|
202
|
-
constraints: JSON.parse(row.constraints_json || "[]"),
|
|
203
|
-
connected_to: JSON.parse(row.connected_to_json || "[]"),
|
|
204
|
-
unresolved_inquiry: row.unresolved_inquiry ?? undefined,
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { readOptionalSourceFile } from "../../../resources/source-files.ts";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import * as path from "node:path";
|
|
4
|
-
import type {
|
|
5
|
-
SchemaFieldSummary,
|
|
6
|
-
SchemaMetadata,
|
|
7
|
-
StackSchemaProvider,
|
|
8
|
-
} from "../schema-provider.interface.ts";
|
|
9
|
-
|
|
10
|
-
export class PrismaSchemaProvider implements StackSchemaProvider {
|
|
11
|
-
public readonly id = "prisma";
|
|
12
|
-
public readonly name = "Prisma Schema Provider";
|
|
13
|
-
|
|
14
|
-
public canHandle(projectRoot: string): boolean {
|
|
15
|
-
return (
|
|
16
|
-
fs.existsSync(path.join(projectRoot, "prisma", "schema.prisma")) ||
|
|
17
|
-
fs.existsSync(path.join(projectRoot, "schema.prisma"))
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public resolveEntitySchema(
|
|
22
|
-
projectRoot: string,
|
|
23
|
-
entitySymbol: string,
|
|
24
|
-
_entityFilePath?: string
|
|
25
|
-
): SchemaMetadata | null {
|
|
26
|
-
const candidatePaths = [
|
|
27
|
-
path.join(projectRoot, "prisma", "schema.prisma"),
|
|
28
|
-
path.join(projectRoot, "schema.prisma"),
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
let schemaPath: string | null = null;
|
|
32
|
-
for (const p of candidatePaths) {
|
|
33
|
-
if (fs.existsSync(p)) {
|
|
34
|
-
schemaPath = p;
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (!schemaPath) return null;
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const content = readOptionalSourceFile(schemaPath, "utf-8");
|
|
43
|
-
const modelRegex = new RegExp(`model\\s+${entitySymbol}\\s*\\{([^}]+)\\}`, "m");
|
|
44
|
-
const match = modelRegex.exec(content);
|
|
45
|
-
if (!match) return null;
|
|
46
|
-
|
|
47
|
-
const body = match[1];
|
|
48
|
-
const lines = body.split("\n");
|
|
49
|
-
const fields: SchemaFieldSummary[] = [];
|
|
50
|
-
|
|
51
|
-
for (const rawLine of lines) {
|
|
52
|
-
const line = rawLine.trim();
|
|
53
|
-
if (!line || line.startsWith("//") || line.startsWith("@@")) continue;
|
|
54
|
-
|
|
55
|
-
// Pattern: fieldName FieldType attributes...
|
|
56
|
-
const parts = line.split(/\s+/);
|
|
57
|
-
if (parts.length >= 2) {
|
|
58
|
-
const name = parts[0];
|
|
59
|
-
let type = parts[1];
|
|
60
|
-
const nullable = type.endsWith("?");
|
|
61
|
-
if (nullable) {
|
|
62
|
-
type = type.slice(0, -1);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const isPrimary = line.includes("@id");
|
|
66
|
-
const isForeign = line.includes("@relation");
|
|
67
|
-
|
|
68
|
-
fields.push({
|
|
69
|
-
name,
|
|
70
|
-
type,
|
|
71
|
-
nullable: nullable || undefined,
|
|
72
|
-
isPrimary: isPrimary || undefined,
|
|
73
|
-
isForeign: isForeign || undefined,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (fields.length === 0) return null;
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
entityName: entitySymbol,
|
|
82
|
-
tableName: entitySymbol.toLowerCase(),
|
|
83
|
-
schemaSourceFile: path.relative(projectRoot, schemaPath),
|
|
84
|
-
fields,
|
|
85
|
-
};
|
|
86
|
-
} catch {
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { join } from "node:path";
|
|
3
|
-
import { randomUUID } from "node:crypto";
|
|
4
|
-
import type { SeptumRepository } from "../database/repository.ts";
|
|
5
|
-
import type { ActiveFeatureSession } from "../../types/index.ts";
|
|
6
|
-
import { SeptumDatabase } from "../database/client.ts";
|
|
7
|
-
|
|
8
|
-
export class SessionManager {
|
|
9
|
-
private static readonly SESSION_FILE = ".septum/session.json";
|
|
10
|
-
|
|
11
|
-
public static getOwnerId(): string {
|
|
12
|
-
return process.env.SEPTUM_SESSION_ID || `process:${process.pid}`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
public static isOwnerAlive(ownerId?: string): boolean {
|
|
16
|
-
if (!ownerId) return false;
|
|
17
|
-
const match = ownerId.match(/^process:(\d+)$/);
|
|
18
|
-
if (!match) {
|
|
19
|
-
// If it's a custom SEPTUM_SESSION_ID or UUID, we cannot inspect OS PID; treat as active.
|
|
20
|
-
return true;
|
|
21
|
-
}
|
|
22
|
-
const pid = parseInt(match[1], 10);
|
|
23
|
-
try {
|
|
24
|
-
process.kill(pid, 0);
|
|
25
|
-
return true;
|
|
26
|
-
} catch (error: any) {
|
|
27
|
-
return error?.code === "EPERM";
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private static mutate<T>(workspaceRoot: string, fn: () => T, repo?: SeptumRepository): T {
|
|
32
|
-
if (repo) return repo.runInTransaction(fn, true);
|
|
33
|
-
const db = new SeptumDatabase(join(workspaceRoot, ".septum/septum.db"));
|
|
34
|
-
try {
|
|
35
|
-
// Serialize ownership checks with writes across CLI and MCP processes.
|
|
36
|
-
return db.raw.transaction(fn).immediate();
|
|
37
|
-
} finally {
|
|
38
|
-
db.close();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
public static saveActiveSession(
|
|
43
|
-
workspaceRoot: string,
|
|
44
|
-
session: ActiveFeatureSession,
|
|
45
|
-
ownerId: string = SessionManager.getOwnerId(),
|
|
46
|
-
persistence?: { repo: SeptumRepository; save: () => void }
|
|
47
|
-
): void {
|
|
48
|
-
SessionManager.mutate(workspaceRoot, () => {
|
|
49
|
-
const current = SessionManager.getActiveSession(workspaceRoot);
|
|
50
|
-
if (current && current.owner_id !== ownerId) {
|
|
51
|
-
if (SessionManager.isOwnerAlive(current.owner_id)) {
|
|
52
|
-
throw new Error(`Workspace already has an active feature session owned by '${current.owner_id || "legacy-session"}'. Release it with its owner, or explicitly run 'septum feature clear --force'.`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const septumDir = join(workspaceRoot, ".septum");
|
|
56
|
-
mkdirSync(septumDir, { recursive: true });
|
|
57
|
-
const sessionPath = join(workspaceRoot, SessionManager.SESSION_FILE);
|
|
58
|
-
const temporaryPath = `${sessionPath}.${randomUUID()}.tmp`;
|
|
59
|
-
try {
|
|
60
|
-
writeFileSync(temporaryPath, JSON.stringify({ ...session, owner_id: ownerId }, null, 2), "utf-8");
|
|
61
|
-
// Metadata and ownership use one write lock; a failed rename rolls back SQLite.
|
|
62
|
-
persistence?.save();
|
|
63
|
-
renameSync(temporaryPath, sessionPath);
|
|
64
|
-
} finally {
|
|
65
|
-
rmSync(temporaryPath, { force: true });
|
|
66
|
-
}
|
|
67
|
-
}, persistence?.repo);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public static getActiveSession(workspaceRoot: string): ActiveFeatureSession | null {
|
|
71
|
-
const sessionPath = join(workspaceRoot, SessionManager.SESSION_FILE);
|
|
72
|
-
if (!existsSync(sessionPath)) return null;
|
|
73
|
-
let parsed: any;
|
|
74
|
-
try {
|
|
75
|
-
parsed = JSON.parse(readFileSync(sessionPath, "utf-8")) as ActiveFeatureSession;
|
|
76
|
-
} catch (e: any) {
|
|
77
|
-
throw new Error(`Corrupted active feature session JSON in '${sessionPath}': ${e.message}. Release it explicitly with 'septum feature clear --force' or 'septum_feature({action: "release", force: true})'.`);
|
|
78
|
-
}
|
|
79
|
-
if (parsed && typeof parsed.feature_key === "string" && parsed.feature_key.trim() &&
|
|
80
|
-
typeof parsed.domain === "string" && parsed.domain.trim() &&
|
|
81
|
-
Array.isArray(parsed.touchpoints) && parsed.touchpoints.every((tp: unknown) => typeof tp === "string") &&
|
|
82
|
-
(parsed.owner_id === undefined || typeof parsed.owner_id === "string")) return parsed;
|
|
83
|
-
throw new Error(`Invalid active feature session in '${sessionPath}'. Release it explicitly with 'septum feature clear --force'.`);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
public static clearActiveSession(
|
|
87
|
-
workspaceRoot: string,
|
|
88
|
-
ownerId: string = SessionManager.getOwnerId(),
|
|
89
|
-
force: boolean = false
|
|
90
|
-
): boolean {
|
|
91
|
-
if (!existsSync(join(workspaceRoot, SessionManager.SESSION_FILE))) return false;
|
|
92
|
-
return SessionManager.mutate(workspaceRoot, () => {
|
|
93
|
-
const sessionPath = join(workspaceRoot, SessionManager.SESSION_FILE);
|
|
94
|
-
if (!existsSync(sessionPath)) return false;
|
|
95
|
-
if (!force) {
|
|
96
|
-
const current = SessionManager.getActiveSession(workspaceRoot);
|
|
97
|
-
if (current?.owner_id && current.owner_id !== ownerId) {
|
|
98
|
-
if (SessionManager.isOwnerAlive(current.owner_id)) {
|
|
99
|
-
throw new Error("Only the active session owner can release it. Use 'septum feature clear --force' for explicit recovery.");
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
rmSync(sessionPath, { force: true });
|
|
104
|
-
return true;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
}
|