prolog-trace-viz 1.1.2 β 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 +268 -96
- 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 +12 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +67 -35
- 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 +8 -1
- package/dist/wrapper.d.ts.map +1 -1
- package/dist/wrapper.js +41 -17
- package/dist/wrapper.js.map +1 -1
- package/package.json +1 -1
- package/tracer.pl +127 -16
package/README.md
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
# prolog-trace-viz
|
|
2
2
|
|
|
3
|
-
Generate beautiful, educational
|
|
3
|
+
Generate beautiful, educational visualisations from Prolog execution traces.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- Custom Prolog tracer using SWI-Prolog's trace interception hook
|
|
8
8
|
- Captures accurate unification information directly from execution
|
|
9
|
+
- **Dual visualisation format**: execution timeline + call tree diagram
|
|
10
|
+
- **Pattern matching display**: Shows how goals unify with clause heads
|
|
11
|
+
- **Subgoal tracking**: Labels and tracks subgoals with [N.M] notation
|
|
9
12
|
- Generates colour-coded Mermaid diagrams
|
|
10
13
|
- Produces complete markdown documentation with step-by-step breakdowns
|
|
11
|
-
- Tracks
|
|
14
|
+
- Tracks variable bindings and clause usage
|
|
12
15
|
- **Smart clause filtering** - Only shows clauses that were actually used during execution
|
|
13
|
-
- **
|
|
16
|
+
- **Depth limiting** - Control trace depth to focus on relevant execution
|
|
14
17
|
- No external dependencies beyond SWI-Prolog
|
|
15
18
|
|
|
16
19
|
## Prerequisites
|
|
@@ -46,7 +49,8 @@ prolog-trace-viz <prolog-file> <query> [options]
|
|
|
46
49
|
|
|
47
50
|
| Option | Description |
|
|
48
51
|
|--------|-------------|
|
|
49
|
-
| `-o, --output <file>` | Write output to file
|
|
52
|
+
| `-o, --output <file>` | Write output to file (default: `<source>-output.md`) |
|
|
53
|
+
| `--depth <number>` | Maximum trace depth to capture (default: 100) |
|
|
50
54
|
| `--verbose` | Display detailed processing information |
|
|
51
55
|
| `--quiet` | Suppress all non-error output except final result |
|
|
52
56
|
| `-h, --help` | Show help message |
|
|
@@ -72,6 +76,12 @@ With verbose output:
|
|
|
72
76
|
prolog-trace-viz program.pl "factorial(5, X)" --verbose
|
|
73
77
|
```
|
|
74
78
|
|
|
79
|
+
Limit trace depth:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
prolog-trace-viz program.pl "factorial(10, X)" --depth 20
|
|
83
|
+
```
|
|
84
|
+
|
|
75
85
|
## Example Output
|
|
76
86
|
|
|
77
87
|
Given a simple Prolog file `append.pl`:
|
|
@@ -90,28 +100,29 @@ prolog-trace-viz append.pl "append([1,2], [3], X)"
|
|
|
90
100
|
Produces a markdown document with:
|
|
91
101
|
|
|
92
102
|
1. **Query section** - The original query in a code block
|
|
93
|
-
2. **
|
|
94
|
-
3. **
|
|
95
|
-
4. **
|
|
96
|
-
5. **Final answer** - The result bindings
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
-
|
|
112
|
-
-
|
|
113
|
-
-
|
|
114
|
-
-
|
|
103
|
+
2. **Clause definitions** - Table showing clauses used during execution
|
|
104
|
+
3. **Execution timeline** - Step-by-step breakdown with subgoal tracking
|
|
105
|
+
4. **Call tree diagram** - Mermaid visualisation showing execution structure
|
|
106
|
+
5. **Final answer** - The result bindings with original query variables
|
|
107
|
+
|
|
108
|
+
### Timeline Format
|
|
109
|
+
|
|
110
|
+
The execution timeline shows each step with:
|
|
111
|
+
- Step number and event type (CALL, EXIT, REDO, FAIL)
|
|
112
|
+
- Goal being solved
|
|
113
|
+
- Pattern matches and unifications
|
|
114
|
+
- Subgoal labels in `[N.M]` format
|
|
115
|
+
- Variable flow between steps
|
|
116
|
+
- Box drawing characters for visual structure
|
|
117
|
+
|
|
118
|
+
### Call Tree Format
|
|
119
|
+
|
|
120
|
+
The Mermaid diagram shows:
|
|
121
|
+
- Circled numbers (β β‘β’...) for step references
|
|
122
|
+
- Node colours: blue (root query), green (success), red (failure)
|
|
123
|
+
- Edges labelled with subgoal relationships
|
|
124
|
+
- Clause numbers for each call
|
|
125
|
+
- Final bindings at EXIT nodes
|
|
115
126
|
|
|
116
127
|
## Architecture
|
|
117
128
|
|
|
@@ -121,16 +132,18 @@ The tool uses a custom Prolog tracer that leverages SWI-Prolog's `prolog_trace_i
|
|
|
121
132
|
- **No code instrumentation**: Your Prolog code runs unmodified
|
|
122
133
|
- **Reliable clause tracking**: Clause numbers come from Prolog's internal tracking
|
|
123
134
|
- **Structured output**: JSON-based trace format for easy parsing
|
|
135
|
+
- **Depth control**: Configurable trace depth to manage output size
|
|
124
136
|
|
|
125
137
|
### Pipeline
|
|
126
138
|
|
|
127
139
|
1. Parse user's Prolog file to extract clauses
|
|
128
|
-
2. Generate wrapper that loads custom tracer
|
|
140
|
+
2. Generate wrapper that loads custom tracer with depth limit
|
|
129
141
|
3. Execute query with trace interception active
|
|
130
142
|
4. Export trace events as JSON
|
|
131
|
-
5. Build execution tree
|
|
132
|
-
6.
|
|
133
|
-
7.
|
|
143
|
+
5. Build execution timeline and call tree in parallel
|
|
144
|
+
6. Format timeline with subgoal tracking and variable flow
|
|
145
|
+
7. Generate Mermaid diagram from call tree
|
|
146
|
+
8. Render complete markdown document
|
|
134
147
|
|
|
135
148
|
## Development
|
|
136
149
|
|
package/dist/analyzer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.d.ts","sourceRoot":"","sources":["../src/analyzer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACxD,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,aAAa,GAAG,OAAO,CAAC;IACvF,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,C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