@bbcsoftwarefactory/cli 0.1.0 → 0.1.1
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/bbc.d.ts +2 -0
- package/dist/bbc.js +40 -0
- package/dist/bigo/complexity.d.ts +18 -0
- package/dist/bigo/complexity.js +139 -0
- package/dist/bigo/functions.d.ts +5 -0
- package/dist/bigo/functions.js +174 -0
- package/dist/bigo/keywords.d.ts +1 -0
- package/dist/bigo/keywords.js +43 -0
- package/dist/bigo/lexical.d.ts +14 -0
- package/dist/bigo/lexical.js +69 -0
- package/dist/bigo/source-files.d.ts +1 -0
- package/dist/bigo/source-files.js +80 -0
- package/dist/change-lane/classification.d.ts +41 -0
- package/dist/change-lane/classification.js +102 -0
- package/dist/change-lane/git.d.ts +8 -0
- package/dist/change-lane/git.js +105 -0
- package/dist/classify-change-lane.d.ts +2 -0
- package/dist/classify-change-lane.js +128 -0
- package/dist/diff-scope/git-diff.d.ts +25 -0
- package/dist/diff-scope/git-diff.js +146 -0
- package/dist/extract-diff-scope.d.ts +2 -0
- package/dist/extract-diff-scope.js +111 -0
- package/dist/measure-bigo.d.ts +2 -0
- package/dist/measure-bigo.js +84 -0
- package/dist/render-workflow.d.ts +2 -0
- package/dist/render-workflow.js +144 -0
- package/dist/workflow/render.d.ts +13 -0
- package/dist/workflow/render.js +31 -0
- package/dist/workflow/schema.d.ts +25 -0
- package/dist/workflow/schema.js +99 -0
- package/package.json +7 -7
- package/src/bbc.ts +0 -39
- package/src/bigo/complexity.ts +0 -138
- package/src/bigo/functions.ts +0 -183
- package/src/bigo/keywords.ts +0 -41
- package/src/bigo/lexical.ts +0 -68
- package/src/bigo/source-files.ts +0 -80
- package/src/change-lane/classification.ts +0 -128
- package/src/change-lane/git.ts +0 -110
- package/src/classify-change-lane.ts +0 -140
- package/src/diff-scope/git-diff.ts +0 -161
- package/src/extract-diff-scope.ts +0 -130
- package/src/measure-bigo.ts +0 -86
- package/src/render-workflow.ts +0 -144
- package/src/workflow/render.ts +0 -40
- package/src/workflow/schema.ts +0 -141
package/src/workflow/render.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LAYER: Application
|
|
3
|
-
* Contains: Mermaid rendering of a validated workflow document.
|
|
4
|
-
* Rules: Print a node label at its first appearance only.
|
|
5
|
-
* BigO: placeholder
|
|
6
|
-
* keywords: [MermaidRender, MarkerSection]
|
|
7
|
-
* GOAL: Produce the deterministic README block the workflow source describes.
|
|
8
|
-
*/
|
|
9
|
-
import type { WorkflowDocument, WorkflowEdge } from './schema.ts';
|
|
10
|
-
|
|
11
|
-
export const workflowBegin = '<!-- workflow:begin generated by skills/workflow-auditor/scripts/render-workflow.py from docs/diagrams/workflow.json; do not edit by hand -->';
|
|
12
|
-
export const workflowEnd = '<!-- workflow:end -->';
|
|
13
|
-
|
|
14
|
-
const arrows = { solid: '-->', dotted: '-.->' } as const;
|
|
15
|
-
|
|
16
|
-
export function renderFlowchart(document: WorkflowDocument): string {
|
|
17
|
-
const declared = new Set<string>();
|
|
18
|
-
const reference = (id: string): string => {
|
|
19
|
-
if (declared.has(id)) return id;
|
|
20
|
-
declared.add(id);
|
|
21
|
-
return `${id}["${document.nodes[id]?.label ?? ''}"]`;
|
|
22
|
-
};
|
|
23
|
-
const line = (edge: WorkflowEdge, indent: string): string => {
|
|
24
|
-
let arrow: string = arrows[edge.style ?? 'solid'];
|
|
25
|
-
if (edge.label !== undefined) arrow += `|${edge.label}|`;
|
|
26
|
-
return `${indent}${reference(edge.from)} ${arrow} ${reference(edge.to)}`;
|
|
27
|
-
};
|
|
28
|
-
const out = [`flowchart ${document.direction}`];
|
|
29
|
-
for (const group of document.groups) {
|
|
30
|
-
out.push(` subgraph ${group.id}["${group.title}"]`);
|
|
31
|
-
for (const edge of group.edges) out.push(line(edge, ' '));
|
|
32
|
-
out.push(' end');
|
|
33
|
-
}
|
|
34
|
-
for (const edge of document.edges) out.push(line(edge, ' '));
|
|
35
|
-
return `${out.join('\n')}\n`;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function generatedSection(document: WorkflowDocument): string {
|
|
39
|
-
return `${workflowBegin}\n\n\`\`\`mermaid\n${renderFlowchart(document)}\`\`\`\n\n${workflowEnd}`;
|
|
40
|
-
}
|
package/src/workflow/schema.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LAYER: Domain
|
|
3
|
-
* Contains: Workflow document model and its invariants.
|
|
4
|
-
* Rules: Reject every shape the legacy renderer rejects, with the same message.
|
|
5
|
-
* BigO: placeholder
|
|
6
|
-
* keywords: [WorkflowDocument, SourceInvariants]
|
|
7
|
-
* GOAL: Validate docs/diagrams/workflow.json before anything renders it.
|
|
8
|
-
*/
|
|
9
|
-
import { compareCodePoints, describeValue, pythonListRepr, pythonRepr } from '@bbcsoftwarefactory/cli-core/python-compat';
|
|
10
|
-
|
|
11
|
-
export class WorkflowError extends Error {}
|
|
12
|
-
|
|
13
|
-
export interface WorkflowNode {
|
|
14
|
-
label: string;
|
|
15
|
-
agents: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface WorkflowEdge {
|
|
19
|
-
from: string;
|
|
20
|
-
to: string;
|
|
21
|
-
style?: 'solid' | 'dotted';
|
|
22
|
-
label?: string;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface WorkflowGroup {
|
|
26
|
-
id: string;
|
|
27
|
-
title: string;
|
|
28
|
-
edges: WorkflowEdge[];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface WorkflowDocument {
|
|
32
|
-
version: 1;
|
|
33
|
-
direction: 'TD' | 'LR';
|
|
34
|
-
nodes: Record<string, WorkflowNode>;
|
|
35
|
-
groups: WorkflowGroup[];
|
|
36
|
-
edges: WorkflowEdge[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const idPattern = /^[A-Za-z][A-Za-z0-9]{0,39}$/;
|
|
40
|
-
const idSource = '[A-Za-z][A-Za-z0-9]{0,39}';
|
|
41
|
-
const unsafeLabel = /["`[\n\r]/;
|
|
42
|
-
const unsafeEdgeLabel = /[|"`\n\r]/;
|
|
43
|
-
const unsafeAgents = /[\n\r]/;
|
|
44
|
-
|
|
45
|
-
function require(condition: boolean, message: string): asserts condition {
|
|
46
|
-
if (!condition) throw new WorkflowError(message);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
50
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function exactKeys(
|
|
54
|
-
value: unknown,
|
|
55
|
-
required: readonly string[],
|
|
56
|
-
optional: readonly string[],
|
|
57
|
-
where: string,
|
|
58
|
-
): Record<string, unknown> {
|
|
59
|
-
require(isPlainObject(value), `${where}: must be an object`);
|
|
60
|
-
const keys = Object.keys(value);
|
|
61
|
-
const missing = required.filter((key) => !keys.includes(key)).sort(compareCodePoints);
|
|
62
|
-
require(missing.length === 0, `${where}: missing ${pythonListRepr(missing)}`);
|
|
63
|
-
const unknown = keys.filter((key) => !required.includes(key) && !optional.includes(key)).sort(compareCodePoints);
|
|
64
|
-
require(unknown.length === 0, `${where}: unknown ${pythonListRepr(unknown)}`);
|
|
65
|
-
return value;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function text(value: unknown, where: string, unsafe: RegExp): string {
|
|
69
|
-
require(
|
|
70
|
-
typeof value === 'string' && value.trim() === value && value !== '',
|
|
71
|
-
`${where}: must be a trimmed, non-empty string`,
|
|
72
|
-
);
|
|
73
|
-
require([...value].length <= 160, `${where}: longer than 160 characters`);
|
|
74
|
-
require(!unsafe.test(value), `${where}: contains a character that would break Mermaid syntax`);
|
|
75
|
-
return value;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function edge(value: unknown, where: string, nodes: Record<string, WorkflowNode>, used: Set<string>): WorkflowEdge {
|
|
79
|
-
const keys = exactKeys(value, ['from', 'to'], ['style', 'label'], where);
|
|
80
|
-
for (const end of ['from', 'to'] as const) {
|
|
81
|
-
const target = keys[end];
|
|
82
|
-
require(typeof target === 'string' && Object.hasOwn(nodes, target), `${where}.${end}: unknown node ${describeValue(target)}`);
|
|
83
|
-
used.add(target);
|
|
84
|
-
}
|
|
85
|
-
const style = keys.style ?? 'solid';
|
|
86
|
-
require(style === 'solid' || style === 'dotted', `${where}.style: must be solid or dotted`);
|
|
87
|
-
const label = 'label' in keys ? text(keys.label, `${where}.label`, unsafeEdgeLabel) : undefined;
|
|
88
|
-
const rendered: WorkflowEdge = { from: keys.from as string, to: keys.to as string, style };
|
|
89
|
-
if (label !== undefined) rendered.label = label;
|
|
90
|
-
return rendered;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function validateWorkflow(value: unknown): WorkflowDocument {
|
|
94
|
-
const top = exactKeys(value, ['version', 'direction', 'nodes', 'groups', 'edges'], [], 'workflow');
|
|
95
|
-
require(top.version === 1, 'workflow.version: must be 1');
|
|
96
|
-
require(top.direction === 'TD' || top.direction === 'LR', 'workflow.direction: must be TD or LR');
|
|
97
|
-
require(isPlainObject(top.nodes) && Object.keys(top.nodes).length > 0, 'workflow.nodes: must be a non-empty object');
|
|
98
|
-
const nodes: Record<string, WorkflowNode> = {};
|
|
99
|
-
for (const [id, node] of Object.entries(top.nodes)) {
|
|
100
|
-
require(idPattern.test(id), `node id ${pythonRepr(id)}: must match ${idSource}`);
|
|
101
|
-
const keys = exactKeys(node, ['label', 'agents'], [], `nodes.${id}`);
|
|
102
|
-
nodes[id] = {
|
|
103
|
-
label: text(keys.label, `nodes.${id}.label`, unsafeLabel),
|
|
104
|
-
agents: text(keys.agents, `nodes.${id}.agents`, unsafeAgents),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
require(Array.isArray(top.groups), 'workflow.groups: must be a list');
|
|
108
|
-
require(Array.isArray(top.edges), 'workflow.edges: must be a list');
|
|
109
|
-
const seen = new Set<string>();
|
|
110
|
-
const groups: WorkflowGroup[] = [];
|
|
111
|
-
top.groups.forEach((group, index) => {
|
|
112
|
-
const keys = exactKeys(group, ['id', 'title', 'edges'], [], `groups[${index}]`);
|
|
113
|
-
require(
|
|
114
|
-
typeof keys.id === 'string' && idPattern.test(keys.id) && !Object.hasOwn(nodes, keys.id),
|
|
115
|
-
`groups[${index}].id: invalid or reused`,
|
|
116
|
-
);
|
|
117
|
-
require(!seen.has(keys.id), `groups[${index}].id: duplicate ${keys.id}`);
|
|
118
|
-
seen.add(keys.id);
|
|
119
|
-
const title = text(keys.title, `groups[${index}].title`, unsafeLabel);
|
|
120
|
-
require(Array.isArray(keys.edges) && keys.edges.length > 0, `groups[${index}].edges: must be a non-empty list`);
|
|
121
|
-
groups.push({ id: keys.id, title, edges: [] });
|
|
122
|
-
});
|
|
123
|
-
const used = new Set<string>();
|
|
124
|
-
top.groups.forEach((group, index) => {
|
|
125
|
-
const keys = group as Record<string, unknown>;
|
|
126
|
-
const target = groups[index];
|
|
127
|
-
if (target === undefined) return;
|
|
128
|
-
target.edges = (keys.edges as unknown[]).map((item, position) =>
|
|
129
|
-
edge(item, `groups[${index}].edges[${position}]`, nodes, used));
|
|
130
|
-
});
|
|
131
|
-
const edges = top.edges.map((item, position) => edge(item, `edges[${position}]`, nodes, used));
|
|
132
|
-
const unused = Object.keys(nodes).filter((id) => !used.has(id)).sort(compareCodePoints);
|
|
133
|
-
require(unused.length === 0, `nodes not used by any edge: ${pythonListRepr(unused)}`);
|
|
134
|
-
return {
|
|
135
|
-
version: 1,
|
|
136
|
-
direction: top.direction,
|
|
137
|
-
nodes,
|
|
138
|
-
groups,
|
|
139
|
-
edges,
|
|
140
|
-
};
|
|
141
|
-
}
|