prolog-trace-viz 1.1.3 → 2.0.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 +43 -30
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +106 -53
- package/dist/analyzer.js.map +1 -1
- package/dist/build-info.d.ts +3 -3
- package/dist/build-info.js +3 -3
- package/dist/clauses.d.ts +11 -0
- package/dist/clauses.d.ts.map +1 -1
- package/dist/clauses.js +12 -0
- package/dist/clauses.js.map +1 -1
- package/dist/cli.d.ts +4 -6
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +2 -25
- package/dist/cli.js.map +1 -1
- package/dist/index.js +80 -22
- package/dist/index.js.map +1 -1
- package/dist/markdown-generator.d.ts +24 -0
- package/dist/markdown-generator.d.ts.map +1 -0
- package/dist/markdown-generator.js +124 -0
- package/dist/markdown-generator.js.map +1 -0
- package/dist/parser.d.ts +9 -0
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +57 -32
- package/dist/parser.js.map +1 -1
- package/dist/timeline-formatter.d.ts +9 -0
- package/dist/timeline-formatter.d.ts.map +1 -0
- package/dist/timeline-formatter.js +149 -0
- package/dist/timeline-formatter.js.map +1 -0
- package/dist/timeline.d.ts +148 -0
- package/dist/timeline.d.ts.map +1 -0
- package/dist/timeline.js +601 -0
- package/dist/timeline.js.map +1 -0
- package/dist/tree-formatter.d.ts +13 -0
- package/dist/tree-formatter.d.ts.map +1 -0
- package/dist/tree-formatter.js +136 -0
- package/dist/tree-formatter.js.map +1 -0
- package/dist/tree.d.ts +75 -0
- package/dist/tree.d.ts.map +1 -0
- package/dist/tree.js +267 -0
- package/dist/tree.js.map +1 -0
- package/dist/wrapper.d.ts.map +1 -1
- package/dist/wrapper.js +6 -20
- package/dist/wrapper.js.map +1 -1
- package/package.json +1 -1
- package/tracer.pl +127 -16
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree Formatter - Generates Mermaid diagram from tree structure
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Format tree as Mermaid diagram
|
|
6
|
+
*/
|
|
7
|
+
export function formatTreeAsMermaid(root) {
|
|
8
|
+
if (!root) {
|
|
9
|
+
return 'graph TD\n A["No execution tree"]';
|
|
10
|
+
}
|
|
11
|
+
const lines = [];
|
|
12
|
+
lines.push('graph TD');
|
|
13
|
+
lines.push('');
|
|
14
|
+
// Generate nodes
|
|
15
|
+
const nodes = [];
|
|
16
|
+
const edges = [];
|
|
17
|
+
const styles = [];
|
|
18
|
+
collectNodesAndEdges(root, nodes, edges, styles);
|
|
19
|
+
// Add nodes section
|
|
20
|
+
lines.push('%% Nodes');
|
|
21
|
+
lines.push(...nodes);
|
|
22
|
+
lines.push('');
|
|
23
|
+
// Add edges section
|
|
24
|
+
lines.push('%% Edges');
|
|
25
|
+
lines.push(...edges);
|
|
26
|
+
lines.push('');
|
|
27
|
+
// Add styles section
|
|
28
|
+
lines.push('%% Styles');
|
|
29
|
+
lines.push(...styles);
|
|
30
|
+
return lines.join('\n');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Collect nodes, edges, and styles recursively
|
|
34
|
+
*/
|
|
35
|
+
function collectNodesAndEdges(node, nodes, edges, styles, isRoot = true) {
|
|
36
|
+
// Generate node definition
|
|
37
|
+
const nodeLabel = formatNodeLabel(node);
|
|
38
|
+
nodes.push(`${node.id}[${nodeLabel}]`);
|
|
39
|
+
// Generate style
|
|
40
|
+
const style = getNodeStyle(node, isRoot);
|
|
41
|
+
if (style) {
|
|
42
|
+
styles.push(style);
|
|
43
|
+
}
|
|
44
|
+
// Generate edges to children
|
|
45
|
+
for (let i = 0; i < node.children.length; i++) {
|
|
46
|
+
const child = node.children[i];
|
|
47
|
+
// Use actual subgoal content if available, otherwise generic label
|
|
48
|
+
let edgeLabel = `subgoal ${i + 1}`;
|
|
49
|
+
if (node.subgoals && i < node.subgoals.length) {
|
|
50
|
+
edgeLabel = node.subgoals[i].goal;
|
|
51
|
+
}
|
|
52
|
+
edges.push(`${node.id} -->|"${edgeLabel}"| ${child.id}`);
|
|
53
|
+
// Recursively process child
|
|
54
|
+
collectNodesAndEdges(child, nodes, edges, styles, false);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Format node label with circled numbers and clause info
|
|
59
|
+
*/
|
|
60
|
+
function formatNodeLabel(node) {
|
|
61
|
+
const parts = [];
|
|
62
|
+
// Use source clause head if available, otherwise use goal
|
|
63
|
+
const displayGoal = node.clauseHead || node.goal;
|
|
64
|
+
// Add call step with circled number
|
|
65
|
+
parts.push(`${toCircledNumber(node.callStep)} ${displayGoal}`);
|
|
66
|
+
// Add clause number if available
|
|
67
|
+
if (node.clauseNumber) {
|
|
68
|
+
parts.push(`clause ${node.clauseNumber}`);
|
|
69
|
+
}
|
|
70
|
+
// Add exit step and binding if available
|
|
71
|
+
if (node.exitStep) {
|
|
72
|
+
parts.push(`${toCircledNumber(node.exitStep)} EXIT${node.finalBinding ? ': ' + node.finalBinding : ''}`);
|
|
73
|
+
}
|
|
74
|
+
return `"${parts.join('<br/>')}"`;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Convert number to circled Unicode character
|
|
78
|
+
*/
|
|
79
|
+
function toCircledNumber(n) {
|
|
80
|
+
if (n >= 1 && n <= 20) {
|
|
81
|
+
// Unicode circled numbers 1-20
|
|
82
|
+
return String.fromCharCode(0x2460 + n - 1);
|
|
83
|
+
}
|
|
84
|
+
else if (n >= 21 && n <= 35) {
|
|
85
|
+
// Unicode circled numbers 21-35
|
|
86
|
+
return String.fromCharCode(0x3251 + n - 21);
|
|
87
|
+
}
|
|
88
|
+
else if (n >= 36 && n <= 50) {
|
|
89
|
+
// Unicode circled numbers 36-50
|
|
90
|
+
return String.fromCharCode(0x32B1 + n - 36);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Fallback for numbers > 50
|
|
94
|
+
return `(${n})`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Get Mermaid style for node based on status
|
|
99
|
+
*/
|
|
100
|
+
function getNodeStyle(node, isRoot) {
|
|
101
|
+
if (isRoot) {
|
|
102
|
+
// Blue for root query
|
|
103
|
+
return `style ${node.id} fill:#e1f5ff,stroke:#01579b,stroke-width:3px`;
|
|
104
|
+
}
|
|
105
|
+
switch (node.status) {
|
|
106
|
+
case 'success':
|
|
107
|
+
// Green for success
|
|
108
|
+
return `style ${node.id} fill:#c8e6c9,stroke:#388e3c`;
|
|
109
|
+
case 'failure':
|
|
110
|
+
// Red for failure
|
|
111
|
+
return `style ${node.id} fill:#ffcdd2,stroke:#c62828`;
|
|
112
|
+
case 'pending':
|
|
113
|
+
// Yellow for pending
|
|
114
|
+
return `style ${node.id} fill:#fff9c4,stroke:#f57f17`;
|
|
115
|
+
default:
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Handle backtracking visualization in tree
|
|
121
|
+
*/
|
|
122
|
+
export function markBacktrackingPaths(root) {
|
|
123
|
+
// Walk the tree and mark failed attempts
|
|
124
|
+
function markNode(node) {
|
|
125
|
+
// If this node failed, mark it
|
|
126
|
+
if (node.status === 'failure') {
|
|
127
|
+
// Already marked by status
|
|
128
|
+
}
|
|
129
|
+
// Process children
|
|
130
|
+
for (const child of node.children) {
|
|
131
|
+
markNode(child);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
markNode(root);
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=tree-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree-formatter.js","sourceRoot":"","sources":["../src/tree-formatter.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAqB;IACvD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,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AAS;YACZ,kBAAkB;YAClB,OAAO,SAAS,IAAI,CAAC,EAAE,8BAA8B,CAAC;QACxD,KAAK,SAAS;YACZ,qBAAqB;YACrB,OAAO,SAAS,IAAI,CAAC,EAAE,8BAA8B,CAAC;QACxD;YACE,OAAO,IAAI,CAAC;IAChB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAc;IAClD,yCAAyC;IACzC,SAAS,QAAQ,CAAC,IAAc;QAC9B,+BAA+B;QAC/B,IAAI,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC9B,2BAA2B;QAC7B,CAAC;QAED,mBAAmB;QACnB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,IAAI,CAAC,CAAC;AACjB,CAAC"}
|
package/dist/tree.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree Builder - Constructs hierarchical call tree from trace events
|
|
3
|
+
*/
|
|
4
|
+
import { TraceEvent } from './timeline.js';
|
|
5
|
+
import { SourceClauseMap } from './clauses.js';
|
|
6
|
+
export interface TreeNode {
|
|
7
|
+
id: string;
|
|
8
|
+
goal: string;
|
|
9
|
+
clauseHead?: string;
|
|
10
|
+
clauseNumber?: string;
|
|
11
|
+
callStep: number;
|
|
12
|
+
exitStep?: number;
|
|
13
|
+
status: 'success' | 'failure' | 'pending';
|
|
14
|
+
children: TreeNode[];
|
|
15
|
+
finalBinding?: string;
|
|
16
|
+
subgoals?: Array<{
|
|
17
|
+
label: string;
|
|
18
|
+
goal: string;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Tree Builder class - constructs call tree from trace events
|
|
23
|
+
*/
|
|
24
|
+
export declare class TreeBuilder {
|
|
25
|
+
private events;
|
|
26
|
+
private sourceClauseMap?;
|
|
27
|
+
private nodes;
|
|
28
|
+
private nodeCounter;
|
|
29
|
+
private callStack;
|
|
30
|
+
private stepToNode;
|
|
31
|
+
private stepCounter;
|
|
32
|
+
constructor(events: TraceEvent[], sourceClauseMap?: SourceClauseMap | undefined);
|
|
33
|
+
/**
|
|
34
|
+
* Check if a predicate is part of tracer infrastructure and should be filtered
|
|
35
|
+
*/
|
|
36
|
+
private isTracerPredicate;
|
|
37
|
+
/**
|
|
38
|
+
* Build the complete tree from trace events
|
|
39
|
+
*/
|
|
40
|
+
build(): TreeNode | null;
|
|
41
|
+
/**
|
|
42
|
+
* Backfill clause information from EXIT events to nodes
|
|
43
|
+
* CALL events don't have clause info, only EXIT events do
|
|
44
|
+
*/
|
|
45
|
+
private backfillClauseInfo;
|
|
46
|
+
/**
|
|
47
|
+
* Generate node ID (A-Z, AA-AZ, BA-BZ, ...)
|
|
48
|
+
*/
|
|
49
|
+
private generateNodeId;
|
|
50
|
+
/**
|
|
51
|
+
* Process CALL event - create new node
|
|
52
|
+
*/
|
|
53
|
+
private processCall;
|
|
54
|
+
/**
|
|
55
|
+
* Extract subgoals from a clause body
|
|
56
|
+
*/
|
|
57
|
+
private extractSubgoals;
|
|
58
|
+
/**
|
|
59
|
+
* Process EXIT event - mark node as successful
|
|
60
|
+
*/
|
|
61
|
+
private processExit;
|
|
62
|
+
/**
|
|
63
|
+
* Process FAIL event - mark node as failed
|
|
64
|
+
*/
|
|
65
|
+
private processFail;
|
|
66
|
+
/**
|
|
67
|
+
* Extract binding by comparing CALL and EXIT goals
|
|
68
|
+
*/
|
|
69
|
+
private extractBinding;
|
|
70
|
+
/**
|
|
71
|
+
* Split arguments respecting parentheses and brackets
|
|
72
|
+
*/
|
|
73
|
+
private splitArguments;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../src/tree.ts"],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IAWnB;;OAEG;IACH,OAAO,CAAC,cAAc;IAyBtB;;OAEG;IACH,OAAO,CAAC,cAAc;CA0BvB"}
|
package/dist/tree.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree Builder - Constructs hierarchical call tree from trace events
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Tree Builder class - constructs call tree from trace events
|
|
6
|
+
*/
|
|
7
|
+
export class TreeBuilder {
|
|
8
|
+
events;
|
|
9
|
+
sourceClauseMap;
|
|
10
|
+
nodes = [];
|
|
11
|
+
nodeCounter = 0;
|
|
12
|
+
callStack = new Map(); // level -> node
|
|
13
|
+
stepToNode = new Map(); // step number -> node
|
|
14
|
+
stepCounter = 0;
|
|
15
|
+
constructor(events, sourceClauseMap) {
|
|
16
|
+
this.events = events;
|
|
17
|
+
this.sourceClauseMap = sourceClauseMap;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Check if a predicate is part of tracer infrastructure and should be filtered
|
|
21
|
+
*/
|
|
22
|
+
isTracerPredicate(predicate) {
|
|
23
|
+
const tracerPredicates = [
|
|
24
|
+
'catch/3',
|
|
25
|
+
'export_trace_json/1',
|
|
26
|
+
'run_trace/0',
|
|
27
|
+
'install_tracer/1',
|
|
28
|
+
'remove_tracer/0',
|
|
29
|
+
];
|
|
30
|
+
return tracerPredicates.includes(predicate);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build the complete tree from trace events
|
|
34
|
+
*/
|
|
35
|
+
build() {
|
|
36
|
+
let root = null;
|
|
37
|
+
for (const event of this.events) {
|
|
38
|
+
// Filter out tracer infrastructure
|
|
39
|
+
if (this.isTracerPredicate(event.predicate)) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
this.stepCounter++;
|
|
43
|
+
switch (event.port) {
|
|
44
|
+
case 'call':
|
|
45
|
+
const node = this.processCall(event, this.stepCounter);
|
|
46
|
+
if (!root) {
|
|
47
|
+
root = node;
|
|
48
|
+
}
|
|
49
|
+
break;
|
|
50
|
+
case 'exit':
|
|
51
|
+
this.processExit(event, this.stepCounter);
|
|
52
|
+
break;
|
|
53
|
+
case 'redo':
|
|
54
|
+
// REDO doesn't create new nodes, just marks retry
|
|
55
|
+
break;
|
|
56
|
+
case 'fail':
|
|
57
|
+
this.processFail(event, this.stepCounter);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Backfill clause info from EXIT events to nodes
|
|
62
|
+
if (root) {
|
|
63
|
+
this.backfillClauseInfo();
|
|
64
|
+
}
|
|
65
|
+
return root;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Backfill clause information from EXIT events to nodes
|
|
69
|
+
* CALL events don't have clause info, only EXIT events do
|
|
70
|
+
*/
|
|
71
|
+
backfillClauseInfo() {
|
|
72
|
+
// For each node, find its EXIT event to get clause info
|
|
73
|
+
for (const node of this.nodes) {
|
|
74
|
+
if (!node.clauseHead && node.clauseNumber && this.sourceClauseMap) {
|
|
75
|
+
const lineNumber = parseInt(node.clauseNumber);
|
|
76
|
+
const sourceClause = this.sourceClauseMap[lineNumber];
|
|
77
|
+
if (sourceClause) {
|
|
78
|
+
node.clauseHead = sourceClause.head;
|
|
79
|
+
// Extract subgoals from clause body
|
|
80
|
+
if (sourceClause.body && sourceClause.body !== 'true') {
|
|
81
|
+
const subgoalGoals = this.extractSubgoals(sourceClause.body);
|
|
82
|
+
node.subgoals = subgoalGoals.map((goal, index) => ({
|
|
83
|
+
label: `[${node.callStep}.${index + 1}]`,
|
|
84
|
+
goal,
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Generate node ID (A-Z, AA-AZ, BA-BZ, ...)
|
|
93
|
+
*/
|
|
94
|
+
generateNodeId() {
|
|
95
|
+
const index = this.nodeCounter++;
|
|
96
|
+
if (index < 26) {
|
|
97
|
+
return String.fromCharCode(65 + index); // A-Z
|
|
98
|
+
}
|
|
99
|
+
// After Z: AA, AB, AC, ..., AZ, BA, BB, ...
|
|
100
|
+
const firstChar = String.fromCharCode(65 + Math.floor(index / 26) - 1);
|
|
101
|
+
const secondChar = String.fromCharCode(65 + (index % 26));
|
|
102
|
+
return firstChar + secondChar;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Process CALL event - create new node
|
|
106
|
+
*/
|
|
107
|
+
processCall(event, stepNumber) {
|
|
108
|
+
// Get source clause if available
|
|
109
|
+
let clauseHead;
|
|
110
|
+
let subgoals;
|
|
111
|
+
if (event.clause && this.sourceClauseMap) {
|
|
112
|
+
const sourceClause = this.sourceClauseMap[event.clause.line];
|
|
113
|
+
if (sourceClause) {
|
|
114
|
+
clauseHead = sourceClause.head;
|
|
115
|
+
// Extract subgoals from clause body
|
|
116
|
+
if (sourceClause.body && sourceClause.body !== 'true') {
|
|
117
|
+
const subgoalGoals = this.extractSubgoals(sourceClause.body);
|
|
118
|
+
subgoals = subgoalGoals.map((goal, index) => ({
|
|
119
|
+
label: `[${stepNumber}.${index + 1}]`,
|
|
120
|
+
goal,
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const node = {
|
|
126
|
+
id: this.generateNodeId(),
|
|
127
|
+
goal: event.goal,
|
|
128
|
+
clauseHead,
|
|
129
|
+
clauseNumber: event.clause?.line.toString(),
|
|
130
|
+
callStep: stepNumber,
|
|
131
|
+
status: 'pending',
|
|
132
|
+
children: [],
|
|
133
|
+
subgoals,
|
|
134
|
+
};
|
|
135
|
+
// Add as child to parent if there is one
|
|
136
|
+
const parentLevel = event.level - 1;
|
|
137
|
+
const parent = this.callStack.get(parentLevel);
|
|
138
|
+
if (parent) {
|
|
139
|
+
parent.children.push(node);
|
|
140
|
+
}
|
|
141
|
+
// Track in call stack
|
|
142
|
+
this.callStack.set(event.level, node);
|
|
143
|
+
this.stepToNode.set(stepNumber, node);
|
|
144
|
+
this.nodes.push(node);
|
|
145
|
+
return node;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Extract subgoals from a clause body
|
|
149
|
+
*/
|
|
150
|
+
extractSubgoals(clauseBody) {
|
|
151
|
+
if (!clauseBody || clauseBody === 'true') {
|
|
152
|
+
return [];
|
|
153
|
+
}
|
|
154
|
+
// Split on commas, respecting parentheses depth
|
|
155
|
+
const subgoals = [];
|
|
156
|
+
let current = '';
|
|
157
|
+
let depth = 0;
|
|
158
|
+
for (const char of clauseBody) {
|
|
159
|
+
if (char === '(') {
|
|
160
|
+
depth++;
|
|
161
|
+
current += char;
|
|
162
|
+
}
|
|
163
|
+
else if (char === ')') {
|
|
164
|
+
depth--;
|
|
165
|
+
current += char;
|
|
166
|
+
}
|
|
167
|
+
else if (char === ',' && depth === 0) {
|
|
168
|
+
subgoals.push(current.trim());
|
|
169
|
+
current = '';
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
current += char;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (current.trim()) {
|
|
176
|
+
subgoals.push(current.trim());
|
|
177
|
+
}
|
|
178
|
+
return subgoals;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Process EXIT event - mark node as successful
|
|
182
|
+
*/
|
|
183
|
+
processExit(event, stepNumber) {
|
|
184
|
+
const node = this.callStack.get(event.level);
|
|
185
|
+
if (node) {
|
|
186
|
+
node.exitStep = stepNumber;
|
|
187
|
+
node.status = 'success';
|
|
188
|
+
// Store clause number from EXIT event
|
|
189
|
+
if (event.clause && !node.clauseNumber) {
|
|
190
|
+
node.clauseNumber = event.clause.line.toString();
|
|
191
|
+
}
|
|
192
|
+
// Extract final binding if available
|
|
193
|
+
// Compare CALL goal with EXIT goal to find bindings
|
|
194
|
+
const callGoal = node.goal;
|
|
195
|
+
const exitGoal = event.goal;
|
|
196
|
+
if (callGoal !== exitGoal) {
|
|
197
|
+
node.finalBinding = this.extractBinding(callGoal, exitGoal);
|
|
198
|
+
}
|
|
199
|
+
// Remove from call stack
|
|
200
|
+
this.callStack.delete(event.level);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Process FAIL event - mark node as failed
|
|
205
|
+
*/
|
|
206
|
+
processFail(event, stepNumber) {
|
|
207
|
+
const node = this.callStack.get(event.level);
|
|
208
|
+
if (node) {
|
|
209
|
+
node.exitStep = stepNumber;
|
|
210
|
+
node.status = 'failure';
|
|
211
|
+
// Remove from call stack
|
|
212
|
+
this.callStack.delete(event.level);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Extract binding by comparing CALL and EXIT goals
|
|
217
|
+
*/
|
|
218
|
+
extractBinding(callGoal, exitGoal) {
|
|
219
|
+
// Simple extraction - find the first variable that changed
|
|
220
|
+
const callMatch = callGoal.match(/^([^(]+)\((.*)\)$/);
|
|
221
|
+
const exitMatch = exitGoal.match(/^([^(]+)\((.*)\)$/);
|
|
222
|
+
if (!callMatch || !exitMatch) {
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
const callArgs = this.splitArguments(callMatch[2]);
|
|
226
|
+
const exitArgs = this.splitArguments(exitMatch[2]);
|
|
227
|
+
// Find first differing argument where call has variable
|
|
228
|
+
for (let i = 0; i < Math.min(callArgs.length, exitArgs.length); i++) {
|
|
229
|
+
const callArg = callArgs[i].trim();
|
|
230
|
+
const exitArg = exitArgs[i].trim();
|
|
231
|
+
if (callArg !== exitArg && /^[A-Z_]/.test(callArg)) {
|
|
232
|
+
return `${callArg}=${exitArg}`;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return undefined;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Split arguments respecting parentheses and brackets
|
|
239
|
+
*/
|
|
240
|
+
splitArguments(argsStr) {
|
|
241
|
+
const args = [];
|
|
242
|
+
let current = '';
|
|
243
|
+
let depth = 0;
|
|
244
|
+
for (const char of argsStr) {
|
|
245
|
+
if (char === '(' || char === '[') {
|
|
246
|
+
depth++;
|
|
247
|
+
current += char;
|
|
248
|
+
}
|
|
249
|
+
else if (char === ')' || char === ']') {
|
|
250
|
+
depth--;
|
|
251
|
+
current += char;
|
|
252
|
+
}
|
|
253
|
+
else if (char === ',' && depth === 0) {
|
|
254
|
+
args.push(current.trim());
|
|
255
|
+
current = '';
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
current += char;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
if (current.trim()) {
|
|
262
|
+
args.push(current.trim());
|
|
263
|
+
}
|
|
264
|
+
return args;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=tree.js.map
|
package/dist/tree.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.js","sourceRoot":"","sources":["../src/tree.ts"],"names":[],"mappings":"AAAA;;GAEG;AAkBH;;GAEG;AACH,MAAM,OAAO,WAAW;IAOF;IAA8B;IAN1C,KAAK,GAAe,EAAE,CAAC;IACvB,WAAW,GAAG,CAAC,CAAC;IAChB,SAAS,GAA0B,IAAI,GAAG,EAAE,CAAC,CAAC,gBAAgB;IAC9D,UAAU,GAA0B,IAAI,GAAG,EAAE,CAAC,CAAC,sBAAsB;IACrE,WAAW,GAAG,CAAC,CAAC;IAExB,YAAoB,MAAoB,EAAU,eAAiC;QAA/D,WAAM,GAAN,MAAM,CAAc;QAAU,oBAAe,GAAf,eAAe,CAAkB;IAAG,CAAC;IAEvF;;OAEG;IACK,iBAAiB,CAAC,SAAiB;QACzC,MAAM,gBAAgB,GAAG;YACvB,SAAS;YACT,qBAAqB;YACrB,aAAa;YACb,kBAAkB;YAClB,iBAAiB;SAClB,CAAC;QACF,OAAO,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,KA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,CAAC;iBAAM,IAAI,IAAI,KAAK,GAAG,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;gBACvC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;gBAC1B,OAAO,GAAG,EAAE,CAAC;YACf,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,IAAI,CAAC;YAClB,CAAC;QACH,CAAC;QAED,IAAI,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;YACnB,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;QAC5B,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
package/dist/wrapper.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../src/wrapper.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../src/wrapper.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAgC7D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,CASjE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,GAAG,MAAM,CAMzF;AACD,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiBhF;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CA2BlE"}
|
package/dist/wrapper.js
CHANGED
|
@@ -11,7 +11,8 @@ import * as os from 'node:os';
|
|
|
11
11
|
* - Tracer cleanup
|
|
12
12
|
*/
|
|
13
13
|
export function generateWrapper(config) {
|
|
14
|
-
const { prologContent, query, tracerPath } = config;
|
|
14
|
+
const { prologContent, query, depth, tracerPath } = config;
|
|
15
|
+
const maxDepth = depth || 100; // Default to 100 if not specified
|
|
15
16
|
const lines = [
|
|
16
17
|
`% Load custom tracer`,
|
|
17
18
|
`:- ['${tracerPath}'].`,
|
|
@@ -25,7 +26,7 @@ export function generateWrapper(config) {
|
|
|
25
26
|
lines.push('');
|
|
26
27
|
lines.push('% Run trace with error handling');
|
|
27
28
|
lines.push('run_trace :-');
|
|
28
|
-
lines.push(
|
|
29
|
+
lines.push(` install_tracer(${maxDepth}),`);
|
|
29
30
|
lines.push(' catch(');
|
|
30
31
|
lines.push(` (${query.trim()}, export_trace_json('trace.json')),`);
|
|
31
32
|
lines.push(' Error,');
|
|
@@ -57,24 +58,9 @@ export function calculateLineOffset(prologContent) {
|
|
|
57
58
|
*/
|
|
58
59
|
export function mapWrapperLineToSource(wrapperLine, prologContent) {
|
|
59
60
|
const offset = calculateLineOffset(prologContent);
|
|
60
|
-
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
const sourceLines = prologContent.split('\n');
|
|
64
|
-
let actualSourceLine = 0;
|
|
65
|
-
let nonEmptyLineCount = 0;
|
|
66
|
-
for (let i = 0; i < sourceLines.length; i++) {
|
|
67
|
-
actualSourceLine = i + 1; // 1-based line numbers
|
|
68
|
-
const line = sourceLines[i].trim();
|
|
69
|
-
// Skip empty lines and comments when counting
|
|
70
|
-
if (line.length > 0 && !line.startsWith('%') && !line.startsWith('/*')) {
|
|
71
|
-
nonEmptyLineCount++;
|
|
72
|
-
if (nonEmptyLineCount === sourceLineInWrapper) {
|
|
73
|
-
return actualSourceLine;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return actualSourceLine; // Fallback to last line
|
|
61
|
+
// Simple mapping: wrapper line - offset = source line
|
|
62
|
+
// The wrapper includes all source lines as-is, so no need to skip empty lines or comments
|
|
63
|
+
return wrapperLine - offset;
|
|
78
64
|
}
|
|
79
65
|
export async function createTempWrapper(config) {
|
|
80
66
|
const content = generateWrapper(config);
|
package/dist/wrapper.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../src/wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAc9B;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,MAAqB;IACnD,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"wrapper.js","sourceRoot":"","sources":["../src/wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;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