@granular-software/fractory 0.1.24 → 0.1.25
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/dist/annotations.d.ts +4 -0
- package/dist/compiler.js +161 -4
- package/dist/core.d.ts +1 -0
- package/dist/core.js +1 -0
- package/dist/declared-graph.js +2 -1
- package/dist/factory-graph.d.ts +4 -1
- package/dist/factory-graph.js +77 -6
- package/dist/factory-model.d.ts +14 -0
- package/dist/git-code.js +1 -1
- package/dist/interface-map.d.ts +15 -0
- package/dist/interface-map.js +125 -0
- package/dist/map-quality.d.ts +6 -0
- package/dist/map-quality.js +5 -0
- package/dist/model.d.ts +6 -2
- package/dist/product-map.d.ts +2 -0
- package/dist/product-map.js +33 -4
- package/dist/public-boundaries.d.ts +13 -0
- package/dist/public-boundaries.js +115 -0
- package/dist/repository-map.js +3 -1
- package/dist/scope.d.ts +2 -0
- package/dist/scope.js +77 -3
- package/dist/source-index.js +4 -0
- package/dist/source-review-git.js +3 -1
- package/dist/source-review.d.ts +3 -1
- package/dist/source-review.js +94 -14
- package/dist/work-check.d.ts +1 -0
- package/dist/work-check.js +6 -1
- package/dist/work-cli.js +29 -1
- package/dist/work-context.d.ts +2 -0
- package/dist/work-context.js +30 -4
- package/dist/work-lock-check.d.ts +12 -0
- package/dist/work-lock-check.js +339 -0
- package/dist/work-locks.d.ts +10 -0
- package/dist/work-locks.js +98 -0
- package/dist/work-model.d.ts +9 -0
- package/dist/work-model.js +50 -1
- package/package.json +1 -1
- package/src/annotations.ts +4 -0
- package/src/compiler.ts +190 -4
- package/src/core.ts +4 -0
- package/src/declared-graph.ts +2 -1
- package/src/factory-graph.ts +89 -5
- package/src/factory-model.ts +9 -0
- package/src/git-code.ts +1 -1
- package/src/interface-map.ts +166 -0
- package/src/map-quality.ts +5 -0
- package/src/model.ts +10 -3
- package/src/product-map.ts +51 -16
- package/src/public-boundaries.ts +143 -0
- package/src/repository-map.ts +3 -1
- package/src/scope.ts +92 -3
- package/src/source-index.ts +3 -0
- package/src/source-review-git.ts +3 -1
- package/src/source-review.ts +112 -13
- package/src/work-check.ts +7 -1
- package/src/work-cli.ts +35 -1
- package/src/work-context.ts +43 -3
- package/src/work-lock-check.ts +549 -0
- package/src/work-locks.ts +108 -0
- package/src/work-model.ts +67 -1
- package/toolkit/GUIDE.md +72 -23
- package/toolkit/SKILL.md +16 -5
- package/toolkit/build.json +1 -1
package/src/product-map.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { DefinitionGraph, ElementKind, SourceRef } from "./model";
|
|
2
|
+
import { interfaceMap, type PublicEntry } from "./interface-map";
|
|
2
3
|
|
|
3
4
|
export interface CatalogPart {
|
|
5
|
+
/** Explicit reviewed public surface for this existing implementation ID. */
|
|
6
|
+
entryFor?: string;
|
|
4
7
|
/** Stable identity: a local slug, or a qualified ID retained when a part moves. */
|
|
5
8
|
id?: string;
|
|
6
9
|
name: string;
|
|
@@ -91,6 +94,7 @@ export function buildProductMap(catalog: ProductMapCatalog): DefinitionGraph {
|
|
|
91
94
|
description: catalog.basis,
|
|
92
95
|
},
|
|
93
96
|
];
|
|
97
|
+
const entries: PublicEntry[] = [];
|
|
94
98
|
for (const system of catalog.systems) {
|
|
95
99
|
const evidence = sources(system.parts.flatMap((part) => part.evidence));
|
|
96
100
|
elements.push({
|
|
@@ -125,8 +129,30 @@ export function buildProductMap(catalog: ProductMapCatalog): DefinitionGraph {
|
|
|
125
129
|
provenance: "source",
|
|
126
130
|
description: part.summary,
|
|
127
131
|
signature: part.signature,
|
|
128
|
-
|
|
129
|
-
|
|
132
|
+
...(part.entryFor
|
|
133
|
+
? {
|
|
134
|
+
contract: {
|
|
135
|
+
id,
|
|
136
|
+
input: {
|
|
137
|
+
language: "reviewed-source",
|
|
138
|
+
signature: part.signature,
|
|
139
|
+
declarations: evidence.map((source) => ({
|
|
140
|
+
source,
|
|
141
|
+
declaration: source.symbol,
|
|
142
|
+
})),
|
|
143
|
+
},
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
: {}),
|
|
147
|
+
source: part.entryFor
|
|
148
|
+
? { ...evidence[0], scope: "contract" }
|
|
149
|
+
: evidence[0],
|
|
150
|
+
sources: part.entryFor
|
|
151
|
+
? evidence.map((source) => ({
|
|
152
|
+
...source,
|
|
153
|
+
scope: "contract" as const,
|
|
154
|
+
}))
|
|
155
|
+
: evidence,
|
|
130
156
|
resources: part.resources?.map((resource) => ({
|
|
131
157
|
id: resource.id,
|
|
132
158
|
label: resource.name,
|
|
@@ -144,6 +170,11 @@ export function buildProductMap(catalog: ProductMapCatalog): DefinitionGraph {
|
|
|
144
170
|
provenance: "source",
|
|
145
171
|
})),
|
|
146
172
|
});
|
|
173
|
+
if (part.entryFor)
|
|
174
|
+
entries.push({
|
|
175
|
+
implementation: part.entryFor,
|
|
176
|
+
interface: elements[elements.length - 1],
|
|
177
|
+
});
|
|
147
178
|
addParts(part.parts || [], id);
|
|
148
179
|
}
|
|
149
180
|
};
|
|
@@ -219,18 +250,22 @@ export function buildProductMap(catalog: ProductMapCatalog): DefinitionGraph {
|
|
|
219
250
|
let hash = 14695981039346656037n;
|
|
220
251
|
for (const byte of new TextEncoder().encode(content))
|
|
221
252
|
hash = BigInt.asUintN(64, (hash ^ BigInt(byte)) * 1099511628211n);
|
|
222
|
-
return
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
253
|
+
return interfaceMap(
|
|
254
|
+
{
|
|
255
|
+
schema: "fractal.definition.v1",
|
|
256
|
+
id: catalog.id,
|
|
257
|
+
revision: hash.toString(16).padStart(16, "0"),
|
|
258
|
+
generatedAt: catalog.date,
|
|
259
|
+
scope: `${catalog.name} — whole product`,
|
|
260
|
+
basis: "repository-review",
|
|
261
|
+
supportingAreas: catalog.support,
|
|
262
|
+
elements,
|
|
263
|
+
connections,
|
|
264
|
+
tests: [],
|
|
265
|
+
failures: [],
|
|
266
|
+
gaps: [],
|
|
267
|
+
},
|
|
268
|
+
entries,
|
|
269
|
+
{ exposeAncestors: true },
|
|
270
|
+
);
|
|
236
271
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { DefinitionGraph, Connection } from "./model";
|
|
2
|
+
|
|
3
|
+
const transfers = new Set([
|
|
4
|
+
"calls",
|
|
5
|
+
"renders",
|
|
6
|
+
"callbacks",
|
|
7
|
+
"delegates",
|
|
8
|
+
"resumes",
|
|
9
|
+
"requires",
|
|
10
|
+
"flows",
|
|
11
|
+
"reads",
|
|
12
|
+
"writes",
|
|
13
|
+
"loads",
|
|
14
|
+
"produces",
|
|
15
|
+
"exposes",
|
|
16
|
+
]);
|
|
17
|
+
|
|
18
|
+
/** Outside is relative to each enclosing black box. Never fabricate an interface
|
|
19
|
+
* to make a direct implementation call look encapsulated. Pure source diagnosis. */
|
|
20
|
+
export function boundaryViolations(graph: DefinitionGraph) {
|
|
21
|
+
const byId = new Map(graph.elements.map((n) => [n.id, n]));
|
|
22
|
+
const path = (id: string) => {
|
|
23
|
+
const result: string[] = [],
|
|
24
|
+
seen = new Set<string>();
|
|
25
|
+
while (byId.has(id) && !seen.has(id)) {
|
|
26
|
+
seen.add(id);
|
|
27
|
+
result.push(id);
|
|
28
|
+
id = byId.get(id)?.parent || "";
|
|
29
|
+
}
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
const paths = new Map(graph.elements.map((n) => [n.id, path(n.id)]));
|
|
33
|
+
const exposures = new Map<string, Set<string>>();
|
|
34
|
+
for (const e of graph.connections)
|
|
35
|
+
if (e.relation === "exposes" && byId.get(e.target)?.kind === "interface") {
|
|
36
|
+
if (!exposures.has(e.source)) exposures.set(e.source, new Set());
|
|
37
|
+
exposures.get(e.source)!.add(e.target);
|
|
38
|
+
}
|
|
39
|
+
return graph.connections.flatMap((edge) => {
|
|
40
|
+
if (!transfers.has(edge.relation)) return [];
|
|
41
|
+
const sourcePath = new Set(paths.get(edge.source) || []),
|
|
42
|
+
targetPath = paths.get(edge.target) || [];
|
|
43
|
+
// A receiver itself can be an interface; methods inside it also belong to its contract.
|
|
44
|
+
const issues: {
|
|
45
|
+
connection: string;
|
|
46
|
+
block: string;
|
|
47
|
+
target: string;
|
|
48
|
+
reason: string;
|
|
49
|
+
}[] = [];
|
|
50
|
+
const receiver = byId.get(edge.target);
|
|
51
|
+
if (edge.relation === "exposes") {
|
|
52
|
+
return receiver?.kind === "interface"
|
|
53
|
+
? []
|
|
54
|
+
: [
|
|
55
|
+
{
|
|
56
|
+
connection: edge.id,
|
|
57
|
+
block: edge.source,
|
|
58
|
+
target: edge.target,
|
|
59
|
+
reason: "Only an interface can be publicly exposed.",
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
}
|
|
63
|
+
const owner = targetPath.find((id) => {
|
|
64
|
+
const node = byId.get(id)!;
|
|
65
|
+
return ![
|
|
66
|
+
"interface",
|
|
67
|
+
"method",
|
|
68
|
+
"operation",
|
|
69
|
+
"resource",
|
|
70
|
+
"artifact",
|
|
71
|
+
].includes(node.kind);
|
|
72
|
+
});
|
|
73
|
+
if (
|
|
74
|
+
receiver &&
|
|
75
|
+
owner &&
|
|
76
|
+
!sourcePath.has(owner) &&
|
|
77
|
+
!["interface", "resource", "artifact"].includes(receiver.kind)
|
|
78
|
+
)
|
|
79
|
+
issues.push({
|
|
80
|
+
connection: edge.id,
|
|
81
|
+
block: owner,
|
|
82
|
+
target: edge.target,
|
|
83
|
+
reason: `Connect to a public interface of ${byId.get(owner)!.label}, not its internal ${receiver.label}.`,
|
|
84
|
+
});
|
|
85
|
+
for (let i = 0; i < targetPath.length; i++) {
|
|
86
|
+
const id = targetPath[i],
|
|
87
|
+
node = byId.get(id)!;
|
|
88
|
+
if (sourcePath.has(id)) break;
|
|
89
|
+
if (
|
|
90
|
+
["interface", "method", "operation", "resource", "artifact"].includes(
|
|
91
|
+
node.kind,
|
|
92
|
+
) ||
|
|
93
|
+
id === graph.id
|
|
94
|
+
)
|
|
95
|
+
continue;
|
|
96
|
+
const entry = i > 0 ? byId.get(targetPath[i - 1]) : undefined;
|
|
97
|
+
// An interface is public to its immediate owner. An inner interface is
|
|
98
|
+
// not implicitly exposed on every ancestor.
|
|
99
|
+
const exposed =
|
|
100
|
+
entry?.kind === "interface" ||
|
|
101
|
+
targetPath.slice(0, i).some((target) => exposures.get(id)?.has(target));
|
|
102
|
+
if (!exposed && !issues.some((issue) => issue.block === id))
|
|
103
|
+
issues.push({
|
|
104
|
+
connection: edge.id,
|
|
105
|
+
block: id,
|
|
106
|
+
target: edge.target,
|
|
107
|
+
reason: `Call bypasses the public interface of ${node.label}.`,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return issues;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** New definitions and plan edits are rejected at the model boundary. Readers
|
|
115
|
+
* can still inspect older snapshots and report their original violations. */
|
|
116
|
+
export function assertPublicConnections(graph: DefinitionGraph) {
|
|
117
|
+
const issues = boundaryViolations(graph);
|
|
118
|
+
if (issues.length)
|
|
119
|
+
throw Error(
|
|
120
|
+
issues.map((issue) => `${issue.connection}: ${issue.reason}`).join("\n"),
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function publicConnectionError(
|
|
125
|
+
graph: DefinitionGraph,
|
|
126
|
+
edge: Connection,
|
|
127
|
+
) {
|
|
128
|
+
if (
|
|
129
|
+
![edge.source, edge.target].every((id) =>
|
|
130
|
+
graph.elements.some((node) => node.id === id),
|
|
131
|
+
)
|
|
132
|
+
)
|
|
133
|
+
return "Choose an existing block and a public interface.";
|
|
134
|
+
return boundaryViolations({
|
|
135
|
+
...graph,
|
|
136
|
+
connections: [
|
|
137
|
+
...graph.connections.filter(
|
|
138
|
+
(item) => item.relation === "exposes" && item.id !== edge.id,
|
|
139
|
+
),
|
|
140
|
+
edge,
|
|
141
|
+
],
|
|
142
|
+
}).find((issue) => issue.connection === edge.id)?.reason;
|
|
143
|
+
}
|
package/src/repository-map.ts
CHANGED
|
@@ -112,7 +112,9 @@ export function mapFromArtifacts(
|
|
|
112
112
|
const graph = composeDefinitions(JSON.parse(base), mounts);
|
|
113
113
|
const annotations = map.annotations && read(map.annotations);
|
|
114
114
|
return annotations
|
|
115
|
-
? factoryGraph(JSON.parse(annotations) as FactoryModel, graph
|
|
115
|
+
? factoryGraph(JSON.parse(annotations) as FactoryModel, graph, {
|
|
116
|
+
legacySnapshot: true,
|
|
117
|
+
})
|
|
116
118
|
: graph;
|
|
117
119
|
}
|
|
118
120
|
export function readRepositoryMap(root: string): DefinitionGraph | null {
|
package/src/scope.ts
CHANGED
|
@@ -28,6 +28,50 @@ export function scopeGraph(
|
|
|
28
28
|
);
|
|
29
29
|
const shown = new Set(nodes.map((node) => node.id));
|
|
30
30
|
const external = new Set<string>();
|
|
31
|
+
const frontier = new Set(
|
|
32
|
+
nodes.filter((node) => node.kind === "interface").map((node) => node.id),
|
|
33
|
+
);
|
|
34
|
+
const incoming = new Set(
|
|
35
|
+
graph.connections
|
|
36
|
+
.filter(
|
|
37
|
+
(edge) =>
|
|
38
|
+
edge.relation !== "exposes" &&
|
|
39
|
+
!inside(edge.source) &&
|
|
40
|
+
inside(edge.target),
|
|
41
|
+
)
|
|
42
|
+
.map((edge) => edge.target),
|
|
43
|
+
);
|
|
44
|
+
// Explicitly exposed nested contracts appear on this boundary themselves;
|
|
45
|
+
// a presentation projection must not replace them with a bare owner box.
|
|
46
|
+
for (const edge of graph.connections) {
|
|
47
|
+
const api = byId.get(edge.target);
|
|
48
|
+
if (
|
|
49
|
+
edge.relation === "exposes" &&
|
|
50
|
+
edge.source === scope.id &&
|
|
51
|
+
api?.kind === "interface" &&
|
|
52
|
+
inside(api.id) &&
|
|
53
|
+
incoming.has(api.id)
|
|
54
|
+
) {
|
|
55
|
+
frontier.add(api.id);
|
|
56
|
+
if (!shown.has(api.id)) {
|
|
57
|
+
nodes.push(api);
|
|
58
|
+
shown.add(api.id);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const implementation = new Set<string>();
|
|
63
|
+
let owner = byId.get(scope.parent || "");
|
|
64
|
+
while (owner && ["interface", "method", "operation"].includes(owner.kind))
|
|
65
|
+
owner = byId.get(owner.parent || "");
|
|
66
|
+
const implementationPeer = (id: string) => {
|
|
67
|
+
const seen = new Set<string>();
|
|
68
|
+
while (owner && byId.has(id) && !seen.has(id)) {
|
|
69
|
+
if (id === owner.id) return true;
|
|
70
|
+
seen.add(id);
|
|
71
|
+
id = byId.get(id)!.parent || "";
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
};
|
|
31
75
|
const contextLabel = (node: Element) => {
|
|
32
76
|
const names: string[] = [];
|
|
33
77
|
let current = node.parent ? byId.get(node.parent) : undefined;
|
|
@@ -66,7 +110,7 @@ export function scopeGraph(
|
|
|
66
110
|
// At a product-area zoom level, outside peers are product areas too. Keep
|
|
67
111
|
// fine-grained endpoints on the wire instead of filling the canvas with
|
|
68
112
|
// external methods. Deeper views still meet public interfaces directly.
|
|
69
|
-
if (scope.parent === graph.id) {
|
|
113
|
+
if (scope.kind !== "interface" && scope.parent === graph.id) {
|
|
70
114
|
while (current.parent && current.parent !== graph.id) {
|
|
71
115
|
const parent = byId.get(current.parent);
|
|
72
116
|
if (!parent) break;
|
|
@@ -78,6 +122,8 @@ export function scopeGraph(
|
|
|
78
122
|
nodes.push(current);
|
|
79
123
|
shown.add(id);
|
|
80
124
|
external.add(id);
|
|
125
|
+
if (scope.kind === "interface" && implementationPeer(id))
|
|
126
|
+
implementation.add(id);
|
|
81
127
|
}
|
|
82
128
|
return id;
|
|
83
129
|
};
|
|
@@ -85,10 +131,45 @@ export function scopeGraph(
|
|
|
85
131
|
originalSource: string;
|
|
86
132
|
originalTarget: string;
|
|
87
133
|
})[] = [];
|
|
134
|
+
// The canonical receiver stays the public API. When that API is open, show
|
|
135
|
+
// the known implementation endpoint through its boundary, rather than two
|
|
136
|
+
// unrelated wires ending and starting at different points on the enclosure.
|
|
137
|
+
const entrypoints = new Map(
|
|
138
|
+
graph.connections.flatMap((edge) =>
|
|
139
|
+
scope.kind === "interface" &&
|
|
140
|
+
edge.target === scope.id &&
|
|
141
|
+
!inside(edge.source) &&
|
|
142
|
+
edge.provenance !== "proposed" &&
|
|
143
|
+
edge.entrypoint &&
|
|
144
|
+
edge.entrypoint !== scope.id &&
|
|
145
|
+
inside(edge.entrypoint)
|
|
146
|
+
? [[edge.id, edge.entrypoint] as const]
|
|
147
|
+
: [],
|
|
148
|
+
),
|
|
149
|
+
);
|
|
150
|
+
const reached = new Set(entrypoints.values());
|
|
88
151
|
for (const edge of graph.connections) {
|
|
152
|
+
// Exposure is a contract declaration, shown by the real frontier card.
|
|
153
|
+
// It is not an invocation and should not become another canvas wire.
|
|
154
|
+
if (edge.relation === "exposes") continue;
|
|
155
|
+
// This generated fallback only supplies the interior half when the exact
|
|
156
|
+
// caller-to-member wire is not already visible. Keep authored delegations.
|
|
157
|
+
if (
|
|
158
|
+
edge.source === scope.id &&
|
|
159
|
+
reached.has(edge.target) &&
|
|
160
|
+
edge.id === `interface-implementation:${scope.id}:${edge.target}`
|
|
161
|
+
)
|
|
162
|
+
continue;
|
|
163
|
+
if (
|
|
164
|
+
edge.relation === "delegates" &&
|
|
165
|
+
edge.target === scope.id &&
|
|
166
|
+
byId.get(edge.source)?.kind === "interface" &&
|
|
167
|
+
byId.get(edge.source)?.parent === scope.id
|
|
168
|
+
)
|
|
169
|
+
continue;
|
|
89
170
|
if (!inside(edge.source) && !inside(edge.target)) continue;
|
|
90
171
|
const source = endpoint(edge.source),
|
|
91
|
-
target = endpoint(edge.target);
|
|
172
|
+
target = endpoint(entrypoints.get(edge.id) || edge.target);
|
|
92
173
|
if (source && target && source !== target)
|
|
93
174
|
edges.push({
|
|
94
175
|
...edge,
|
|
@@ -99,5 +180,13 @@ export function scopeGraph(
|
|
|
99
180
|
});
|
|
100
181
|
}
|
|
101
182
|
if (!nodes.length && scope.id !== graph.id) nodes.push(scope);
|
|
102
|
-
return {
|
|
183
|
+
return {
|
|
184
|
+
scope,
|
|
185
|
+
nodes,
|
|
186
|
+
edges,
|
|
187
|
+
external,
|
|
188
|
+
frontier,
|
|
189
|
+
implementation,
|
|
190
|
+
contextLabel,
|
|
191
|
+
};
|
|
103
192
|
}
|
package/src/source-index.ts
CHANGED
|
@@ -73,6 +73,9 @@ export function indexSources(
|
|
|
73
73
|
for (const element of graph.elements) {
|
|
74
74
|
for (const ref of element.sources ||
|
|
75
75
|
(element.source ? [element.source] : [])) {
|
|
76
|
+
// A public signature points to its implementation for contract review,
|
|
77
|
+
// but does not own the body or the rest of an enclosing class/file.
|
|
78
|
+
if (ref.scope === "contract") continue;
|
|
76
79
|
if (!safeFile(ref.file))
|
|
77
80
|
throw new Error("Source paths must be repository relative");
|
|
78
81
|
const list = refs.get(ref.file) || [];
|
package/src/source-review-git.ts
CHANGED
|
@@ -122,7 +122,9 @@ export function revisionSourceMap(
|
|
|
122
122
|
const cached = revisions.get(key);
|
|
123
123
|
if (cached) return cached;
|
|
124
124
|
const source = readMapSources(root, definition, areas, revision);
|
|
125
|
-
const graph = sourceReviewMap(definition, source.files, areas, revision
|
|
125
|
+
const graph = sourceReviewMap(definition, source.files, areas, revision, {
|
|
126
|
+
legacySnapshot: true,
|
|
127
|
+
});
|
|
126
128
|
revisions.set(key, graph);
|
|
127
129
|
if (revisions.size > 4) revisions.delete(revisions.keys().next().value!);
|
|
128
130
|
return graph;
|
package/src/source-review.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { createHash } from "node:crypto";
|
|
|
7
7
|
import { posix } from "node:path";
|
|
8
8
|
import ts from "typescript";
|
|
9
9
|
import type { DefinitionGraph, Element, SourceRef } from "./model";
|
|
10
|
+
import { interfaceMap, type PublicEntry } from "./interface-map";
|
|
10
11
|
export interface SourceArea {
|
|
11
12
|
id: string;
|
|
12
13
|
parent: string;
|
|
@@ -29,6 +30,7 @@ export function sourceReviewMap(
|
|
|
29
30
|
files: Map<string, string>,
|
|
30
31
|
areas: SourceArea[],
|
|
31
32
|
revision?: string,
|
|
33
|
+
options: { legacySnapshot?: boolean } = {},
|
|
32
34
|
): DefinitionGraph {
|
|
33
35
|
const graph = structuredClone(definition);
|
|
34
36
|
const areaIds = new Set(areas.map((area) => area.id));
|
|
@@ -45,10 +47,16 @@ export function sourceReviewMap(
|
|
|
45
47
|
n.provenance === "source" &&
|
|
46
48
|
(discoveredAreas.has(n.id) ||
|
|
47
49
|
(/\/[a-f0-9]{12}$/.test(n.id) &&
|
|
48
|
-
discoveredAreas.has(n.parent || "")
|
|
50
|
+
(discoveredAreas.has(n.parent || "") ||
|
|
51
|
+
discoveredAreas.has(
|
|
52
|
+
(n.parent || "").replace(/::exports$/, ""),
|
|
53
|
+
))) ||
|
|
49
54
|
(areaIds.has(n.id) &&
|
|
50
55
|
n.source?.scope === "file" &&
|
|
51
|
-
n.sources?.every((source) => source.scope === "file"))
|
|
56
|
+
n.sources?.every((source) => source.scope === "file")) ||
|
|
57
|
+
(n.kind === "interface" &&
|
|
58
|
+
n.id.endsWith("::exports") &&
|
|
59
|
+
areaIds.has(n.parent || "")))
|
|
52
60
|
),
|
|
53
61
|
);
|
|
54
62
|
graph.elements = graph.elements.map((node) =>
|
|
@@ -162,7 +170,10 @@ export function sourceReviewMap(
|
|
|
162
170
|
(item) =>
|
|
163
171
|
ts.isImportDeclaration(item) &&
|
|
164
172
|
ts.isStringLiteral(item.moduleSpecifier) &&
|
|
165
|
-
[
|
|
173
|
+
[
|
|
174
|
+
"@granular-software/fractal/annotations",
|
|
175
|
+
"@granular-software/fractory/annotations",
|
|
176
|
+
].includes(item.moduleSpecifier.text) &&
|
|
166
177
|
item.importClause?.namedBindings &&
|
|
167
178
|
ts.isNamedImports(item.importClause.namedBindings) &&
|
|
168
179
|
item.importClause.namedBindings.elements.some(
|
|
@@ -272,11 +283,15 @@ export function sourceReviewMap(
|
|
|
272
283
|
}
|
|
273
284
|
}
|
|
274
285
|
const resolveImport = (file: string, spec: string) => {
|
|
275
|
-
const aliases = areas.find(area => area.matches(file))?.aliases || {};
|
|
276
|
-
const alias = Object.keys(aliases)
|
|
286
|
+
const aliases = areas.find((area) => area.matches(file))?.aliases || {};
|
|
287
|
+
const alias = Object.keys(aliases)
|
|
288
|
+
.sort((a, b) => b.length - a.length)
|
|
289
|
+
.find((prefix) => spec.startsWith(prefix));
|
|
277
290
|
const base = spec.startsWith(".")
|
|
278
291
|
? posix.normalize(posix.join(posix.dirname(file), spec))
|
|
279
|
-
: alias
|
|
292
|
+
: alias
|
|
293
|
+
? posix.normalize(aliases[alias] + spec.slice(alias.length))
|
|
294
|
+
: undefined;
|
|
280
295
|
if (!base) return;
|
|
281
296
|
return [
|
|
282
297
|
base,
|
|
@@ -289,14 +304,20 @@ export function sourceReviewMap(
|
|
|
289
304
|
};
|
|
290
305
|
// Bind lexical symbols without loading dependencies or executing code. A local
|
|
291
306
|
// parameter named like an import must not become a fabricated cross-block call.
|
|
292
|
-
const
|
|
307
|
+
const compilerOptions: ts.CompilerOptions = {
|
|
308
|
+
noLib: true,
|
|
309
|
+
noResolve: true,
|
|
310
|
+
allowJs: true,
|
|
311
|
+
checkJs: false,
|
|
312
|
+
};
|
|
313
|
+
const host = ts.createCompilerHost(compilerOptions);
|
|
293
314
|
const clean = (path: string) => path.replace(/^\//, "");
|
|
294
315
|
host.getCurrentDirectory = () => "/";
|
|
295
316
|
host.getSourceFile = (file) => parsed.get(clean(file));
|
|
296
317
|
host.fileExists = (file) => parsed.has(clean(file));
|
|
297
318
|
host.readFile = (file) => files.get(clean(file));
|
|
298
319
|
const checker = ts
|
|
299
|
-
.createProgram([...parsed.keys()],
|
|
320
|
+
.createProgram([...parsed.keys()], compilerOptions, host)
|
|
300
321
|
.getTypeChecker();
|
|
301
322
|
const connections = new Map<string, DefinitionGraph["connections"][number]>();
|
|
302
323
|
const enclosingOwner = (node: ts.Node, file: string, fallback: string) => {
|
|
@@ -623,15 +644,93 @@ export function sourceReviewMap(
|
|
|
623
644
|
});
|
|
624
645
|
}
|
|
625
646
|
graph.connections.push(...connections.values());
|
|
647
|
+
const entries: PublicEntry[] = [];
|
|
648
|
+
for (const area of areas.filter(
|
|
649
|
+
(area) => active.has(area.id) && byId.get(area.id)?.kind !== "interface",
|
|
650
|
+
)) {
|
|
651
|
+
const members = [...parsed]
|
|
652
|
+
.filter(([file]) => owners.get(file) === area.id && !isTest(file))
|
|
653
|
+
.flatMap(([file, ast]) =>
|
|
654
|
+
ast.statements.flatMap((statement) => {
|
|
655
|
+
if (
|
|
656
|
+
ts.isInterfaceDeclaration(statement) ||
|
|
657
|
+
ts.isTypeAliasDeclaration(statement) ||
|
|
658
|
+
(ts.isExportDeclaration(statement) && statement.isTypeOnly)
|
|
659
|
+
)
|
|
660
|
+
return [];
|
|
661
|
+
const exported =
|
|
662
|
+
ts.isExportAssignment(statement) ||
|
|
663
|
+
ts.isExportDeclaration(statement) ||
|
|
664
|
+
(ts.canHaveModifiers(statement) &&
|
|
665
|
+
ts
|
|
666
|
+
.getModifiers(statement)
|
|
667
|
+
?.some((item) => item.kind === ts.SyntaxKind.ExportKeyword));
|
|
668
|
+
// CommonJS exports are public module entries too; plain private functions are not.
|
|
669
|
+
const commonJS =
|
|
670
|
+
ts.isExpressionStatement(statement) &&
|
|
671
|
+
/^(module\.exports|exports\.)/.test(
|
|
672
|
+
statement.expression.getText(ast),
|
|
673
|
+
);
|
|
674
|
+
if (!exported && !commonJS) return [];
|
|
675
|
+
const source = {
|
|
676
|
+
...refs.get(file)!,
|
|
677
|
+
line:
|
|
678
|
+
ast.getLineAndCharacterOfPosition(statement.getStart(ast)).line +
|
|
679
|
+
1,
|
|
680
|
+
};
|
|
681
|
+
const signature =
|
|
682
|
+
ts.isFunctionDeclaration(statement) && statement.body
|
|
683
|
+
? statement
|
|
684
|
+
.getText(ast)
|
|
685
|
+
.slice(
|
|
686
|
+
0,
|
|
687
|
+
statement.body.getStart(ast) - statement.getStart(ast),
|
|
688
|
+
)
|
|
689
|
+
.trim()
|
|
690
|
+
: statement.getText(ast).split("\n")[0].slice(0, 240);
|
|
691
|
+
return [{ source, signature }];
|
|
692
|
+
}),
|
|
693
|
+
);
|
|
694
|
+
if (!members.length) continue;
|
|
695
|
+
const id = `${area.id}::exports`;
|
|
696
|
+
const api: Element = {
|
|
697
|
+
id,
|
|
698
|
+
parent: area.id,
|
|
699
|
+
label: `${area.label} API`,
|
|
700
|
+
kind: "interface",
|
|
701
|
+
provenance: "source",
|
|
702
|
+
description: `Exported contracts of ${area.label}. Open to inspect the public entries and their implementation.`,
|
|
703
|
+
source: { ...members[0].source, scope: "contract" },
|
|
704
|
+
sources: members.map((member) => ({
|
|
705
|
+
...member.source,
|
|
706
|
+
scope: "contract",
|
|
707
|
+
})),
|
|
708
|
+
contract: { id, input: { language: "typescript", members } },
|
|
709
|
+
};
|
|
710
|
+
// Public functions live in their interface; their source ownership remains exact.
|
|
711
|
+
for (const method of graph.elements.filter(
|
|
712
|
+
(node) =>
|
|
713
|
+
node.kind === "method" &&
|
|
714
|
+
node.parent === area.id &&
|
|
715
|
+
node.provenance === "source",
|
|
716
|
+
))
|
|
717
|
+
method.parent = id;
|
|
718
|
+
entries.push({ implementation: area.id, interface: api });
|
|
719
|
+
}
|
|
720
|
+
const surfaced = interfaceMap(graph, entries, {
|
|
721
|
+
exposeAncestors: true,
|
|
722
|
+
validate: !options.legacySnapshot,
|
|
723
|
+
});
|
|
626
724
|
graph.revision = hash(
|
|
627
725
|
JSON.stringify({
|
|
628
726
|
base: definition.revision,
|
|
629
727
|
revision,
|
|
630
|
-
elements:
|
|
631
|
-
connections:
|
|
632
|
-
tests:
|
|
728
|
+
elements: surfaced.elements,
|
|
729
|
+
connections: surfaced.connections,
|
|
730
|
+
tests: surfaced.tests,
|
|
633
731
|
}),
|
|
634
732
|
);
|
|
635
|
-
|
|
636
|
-
|
|
733
|
+
surfaced.revision = graph.revision;
|
|
734
|
+
surfaced.codeRevision = revision;
|
|
735
|
+
return surfaced;
|
|
637
736
|
}
|
package/src/work-check.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { readGit, resolveComparisonRef } from "./git-refs";
|
|
|
6
6
|
import { parseWorkingStatus } from "./working-code";
|
|
7
7
|
import { readWorkPlan, workBaseline } from "./work-context";
|
|
8
8
|
import { scopeBlocks } from "./work-model";
|
|
9
|
+
import { checkWorkLocks } from "./work-lock-check";
|
|
9
10
|
|
|
10
11
|
/** Conservative file ownership check. Shared and unknown ownership never produce a pass. */
|
|
11
12
|
export async function checkWorkScope(
|
|
@@ -113,11 +114,16 @@ export async function checkWorkScope(
|
|
|
113
114
|
["unassigned", "shared"].includes(file.status),
|
|
114
115
|
);
|
|
115
116
|
const outside = files.filter((file) => file.status === "outside");
|
|
117
|
+
const locks = checkWorkLocks(entry.root, plan, baseline, currentGraph, paths);
|
|
116
118
|
return {
|
|
117
119
|
work: id,
|
|
118
120
|
base: plan.baseCommit,
|
|
119
121
|
head,
|
|
120
|
-
pass:
|
|
122
|
+
pass:
|
|
123
|
+
!outside.length &&
|
|
124
|
+
!uncertain.length &&
|
|
125
|
+
locks.every((l) => l.status === "unchanged"),
|
|
126
|
+
locks,
|
|
121
127
|
files,
|
|
122
128
|
outside: outside.length,
|
|
123
129
|
uncertain: uncertain.length,
|