tracecite 0.0.2__tar.gz

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.
Files changed (88) hide show
  1. tracecite-0.0.2/LICENSE +21 -0
  2. tracecite-0.0.2/PKG-INFO +320 -0
  3. tracecite-0.0.2/README.md +294 -0
  4. tracecite-0.0.2/pyproject.toml +53 -0
  5. tracecite-0.0.2/setup.cfg +4 -0
  6. tracecite-0.0.2/src/tracecite/__init__.py +35 -0
  7. tracecite-0.0.2/src/tracecite/__main__.py +3 -0
  8. tracecite-0.0.2/src/tracecite/cli.py +656 -0
  9. tracecite-0.0.2/src/tracecite/docs/__init__.py +56 -0
  10. tracecite-0.0.2/src/tracecite/docs/build.py +381 -0
  11. tracecite-0.0.2/src/tracecite/docs/config.py +114 -0
  12. tracecite-0.0.2/src/tracecite/docs/contract.py +17 -0
  13. tracecite-0.0.2/src/tracecite/docs/modes.py +240 -0
  14. tracecite-0.0.2/src/tracecite/docs/stage.py +407 -0
  15. tracecite-0.0.2/src/tracecite/docs/vectorize.py +457 -0
  16. tracecite-0.0.2/src/tracecite/evidence/__init__.py +3 -0
  17. tracecite-0.0.2/src/tracecite/evidence/chunking.py +214 -0
  18. tracecite-0.0.2/src/tracecite/evidence/commands.py +552 -0
  19. tracecite-0.0.2/src/tracecite/evidence/config.py +49 -0
  20. tracecite-0.0.2/src/tracecite/evidence/embedding.py +59 -0
  21. tracecite-0.0.2/src/tracecite/evidence/manifest.py +197 -0
  22. tracecite-0.0.2/src/tracecite/evidence/page_extraction.py +200 -0
  23. tracecite-0.0.2/src/tracecite/evidence/page_output.py +80 -0
  24. tracecite-0.0.2/src/tracecite/evidence/page_selection.py +116 -0
  25. tracecite-0.0.2/src/tracecite/evidence/parsers/__init__.py +1 -0
  26. tracecite-0.0.2/src/tracecite/evidence/parsers/base.py +65 -0
  27. tracecite-0.0.2/src/tracecite/evidence/parsers/markdown.py +142 -0
  28. tracecite-0.0.2/src/tracecite/evidence/parsers/pdf.py +315 -0
  29. tracecite-0.0.2/src/tracecite/evidence/parsers/workbook.py +334 -0
  30. tracecite-0.0.2/src/tracecite/evidence/paths.py +94 -0
  31. tracecite-0.0.2/src/tracecite/evidence/schema.py +570 -0
  32. tracecite-0.0.2/src/tracecite/evidence/source_links.py +185 -0
  33. tracecite-0.0.2/src/tracecite/evidence/sync.py +1434 -0
  34. tracecite-0.0.2/src/tracecite/evidence/vector_backend.py +130 -0
  35. tracecite-0.0.2/src/tracecite/evidence/verify.py +368 -0
  36. tracecite-0.0.2/src/tracecite/skills/routing-documentation-source-links/SKILL.md +167 -0
  37. tracecite-0.0.2/src/tracecite/skills/routing-documentation-source-links/agents/openai.yaml +3 -0
  38. tracecite-0.0.2/src/tracecite/skills/routing-documentation-source-links/references/documenter-integration.md +71 -0
  39. tracecite-0.0.2/src/tracecite/skills/routing-documentation-source-links/references/registry-contract.md +86 -0
  40. tracecite-0.0.2/src/tracecite/skills/routing-documentation-source-links/references/staging-and-rewriting.md +118 -0
  41. tracecite-0.0.2/src/tracecite/skills/routing-documentation-source-links/references/validation-and-failure-modes.md +67 -0
  42. tracecite-0.0.2/src/tracecite/skills/using-tracecite/SKILL.md +97 -0
  43. tracecite-0.0.2/src/tracecite/skills/using-tracecite/agents/openai.yaml +3 -0
  44. tracecite-0.0.2/src/tracecite/skills/using-tracecite/references/architecture.md +68 -0
  45. tracecite-0.0.2/src/tracecite/skills/using-tracecite/references/pdf-and-assets.md +67 -0
  46. tracecite-0.0.2/src/tracecite/skills/using-tracecite/references/retrieval.md +45 -0
  47. tracecite-0.0.2/src/tracecite/skills/using-tracecite/references/schema-and-migrations.md +52 -0
  48. tracecite-0.0.2/src/tracecite/skills/using-tracecite/references/synchronisation.md +98 -0
  49. tracecite-0.0.2/src/tracecite/skills/using-tracecite/references/workspace-runtime.md +44 -0
  50. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/SKILL.md +91 -0
  51. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/agents/openai.yaml +3 -0
  52. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/fixtures/README.md +13 -0
  53. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/fixtures/reports/invalid-bad-path.md +5 -0
  54. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/fixtures/reports/invalid-grammar.md +8 -0
  55. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/fixtures/reports/invalid-missing-definition.md +3 -0
  56. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/fixtures/reports/invalid-page-not-indexed.md +5 -0
  57. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/fixtures/reports/invalid-unindexed-path.md +5 -0
  58. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/fixtures/reports/valid-grammar.md +12 -0
  59. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/fixtures/reports/valid-report.md +27 -0
  60. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/fixtures/source-links.toml +17 -0
  61. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/fixtures/validate_fixtures.py +295 -0
  62. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/references/images-and-source-links.md +34 -0
  63. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/references/quotation-and-verification.md +43 -0
  64. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/references/reference-style-citations.md +48 -0
  65. tracecite-0.0.2/src/tracecite/skills/writing-evidence-backed-reports/references/report-structure.md +58 -0
  66. tracecite-0.0.2/src/tracecite/tables/__init__.py +41 -0
  67. tracecite-0.0.2/src/tracecite/tables/_text.py +142 -0
  68. tracecite-0.0.2/src/tracecite/tables/document.py +582 -0
  69. tracecite-0.0.2/src/tracecite/tables/html.py +299 -0
  70. tracecite-0.0.2/src/tracecite/tables/models.py +119 -0
  71. tracecite-0.0.2/src/tracecite/tables/normalise.py +786 -0
  72. tracecite-0.0.2/src/tracecite/tables/pandoc.py +503 -0
  73. tracecite-0.0.2/src/tracecite/tables/publish.py +238 -0
  74. tracecite-0.0.2/src/tracecite/tables/render.py +128 -0
  75. tracecite-0.0.2/src/tracecite/tables/site.py +457 -0
  76. tracecite-0.0.2/src/tracecite.egg-info/PKG-INFO +320 -0
  77. tracecite-0.0.2/src/tracecite.egg-info/SOURCES.txt +86 -0
  78. tracecite-0.0.2/src/tracecite.egg-info/dependency_links.txt +1 -0
  79. tracecite-0.0.2/src/tracecite.egg-info/entry_points.txt +2 -0
  80. tracecite-0.0.2/src/tracecite.egg-info/requires.txt +17 -0
  81. tracecite-0.0.2/src/tracecite.egg-info/top_level.txt +1 -0
  82. tracecite-0.0.2/tests/test_bootstrap_docs.py +198 -0
  83. tracecite-0.0.2/tests/test_build_docs.py +113 -0
  84. tracecite-0.0.2/tests/test_docs.py +496 -0
  85. tracecite-0.0.2/tests/test_repository_tree.py +60 -0
  86. tracecite-0.0.2/tests/test_skills.py +27 -0
  87. tracecite-0.0.2/tests/test_tables.py +442 -0
  88. tracecite-0.0.2/tests/test_version.py +19 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ARPST-UniMelb
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,320 @@
1
+ Metadata-Version: 2.4
2
+ Name: tracecite
3
+ Version: 0.0.2
4
+ Summary: Source-linked table normalisation and evidence retrieval for executable documentation
5
+ Author: ARPST-UniMelb
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: beautifulsoup4>=4.12
11
+ Requires-Dist: pandas>=2.0
12
+ Requires-Dist: PyYAML>=6.0
13
+ Requires-Dist: tabulate>=0.9
14
+ Requires-Dist: nbformat>=5.10
15
+ Requires-Dist: nbclient>=0.11
16
+ Requires-Dist: ipykernel>=7.3
17
+ Provides-Extra: evidence
18
+ Requires-Dist: huggingface-hub<2,>=1.23; extra == "evidence"
19
+ Requires-Dist: pymupdf<2,>=1.28; extra == "evidence"
20
+ Requires-Dist: sentence-transformers<6,>=5.6; extra == "evidence"
21
+ Requires-Dist: sqlite-vec<0.2,>=0.1.9; extra == "evidence"
22
+ Provides-Extra: test
23
+ Requires-Dist: build>=1.2; extra == "test"
24
+ Requires-Dist: pytest<9,>=8.4; extra == "test"
25
+ Dynamic: license-file
26
+
27
+ # TraceCite
28
+
29
+ TraceCite makes executable documentation, and the source documents behind it, searchable and checkable evidence.
30
+
31
+ Its core is source-linked table normalisation. Each table in a rendered Python or Julia documentation page stays in the site as the original evidence, and TraceCite derives deterministic, self-describing row text from it for search, so generated tables become retrievable without changing what readers see.
32
+
33
+ Around that core, TraceCite indexes source collections of Markdown, PDF, `.xlsx`, and `.xlsm` files. It stores retained extraction, source hashes, full-text and vector search records, and source-specific locators such as PDF pages, Markdown lines, and workbook worksheet ranges, and it verifies quotations and report citations against them. The documentation commands join the two parts: `tracecite docs index` adds a project's retained documentation, with its normalised tables, to an evidence index, and `tracecite docs stage` routes source links to local files or public URLs.
34
+
35
+ ## Core architecture
36
+
37
+ ```text
38
+ Python or Julia executable page
39
+ -> Quarto retained Pandoc Markdown
40
+ -> raw table evidence
41
+ -> HTML site
42
+
43
+ retained Markdown
44
+ -> `tracecite prepare` CLI/package
45
+ -> canonical table model
46
+ -> row-oriented retrieval text
47
+ -> diagnostics
48
+ -> optional embedding-inspection website copy
49
+ ```
50
+
51
+ The normal site remains pure Quarto output. The generated inspection copy doubles each table only when explicitly requested.
52
+
53
+ `tracecite docs build docs` is the public automatic documentation builder. It discovers configured executable inputs, selects the complete site when runtimes are available, safely falls back with exact skipped-file warnings, stages retained Markdown, and optionally renders the inspection site. Table normalisation remains in the public `tracecite prepare` command.
54
+
55
+ The searchable-evidence path is separate from the documentation renderer:
56
+
57
+ ```text
58
+ declared PDF, Markdown, or workbook sources
59
+ -> retained source extraction
60
+ -> locator-aware chunks
61
+ -> SQLite FTS5 and sqlite-vec
62
+ -> ranked JSON results with source identity and evidence locators
63
+ ```
64
+
65
+ ## Prerequisites
66
+
67
+ - Python 3.11 or newer;
68
+ - Pandoc, either installed directly or provided by Quarto;
69
+ - Quarto for documentation-site renders;
70
+ - Julia 1.10 or newer only when building Julia documentation pages.
71
+
72
+ The Python normaliser and CLI work without Julia. Automatic documentation builds fall back to the Python-only overlay when configured Julia inputs cannot run; explicit Julia-only builds require Julia.
73
+
74
+ Evidence synchronisation and hybrid search use the optional `evidence` dependencies:
75
+
76
+ ```sh
77
+ uv pip install -e ".[evidence]"
78
+ ```
79
+
80
+ Workbook parsing reads OOXML packages directly with the Python standard library and runs independently of Excel, Julia, Quarto, and third-party workbook readers.
81
+
82
+ ## Usage
83
+
84
+ The public `tracecite` CLI provides table and document normalisation, documentation builds, and source-evidence synchronisation and search. The `prepare` command consumes retained Markdown after a Quarto render and creates the optional inspection-site copy.
85
+
86
+ ### Public API
87
+
88
+ ```python
89
+ from tracecite.tables import (
90
+ normalise_pandoc_table,
91
+ normalise_html_table,
92
+ normalise_document_tables,
93
+ )
94
+ ```
95
+
96
+ `normalise_pandoc_table()` is the core contract. It accepts one Pandoc table and returns raw evidence, canonical Markdown, normalised text, row records, diagnostics, hashes, and version metadata.
97
+
98
+ Each row also receives a deterministic `row_id`. When `row_identity` metadata is supplied, the identifier follows the logical row rather than its current rank or position.
99
+
100
+ `normalise_html_table()` supports Literate.jl, Documenter.jl, PrettyTables, notebook HTML MIME, row spans, and column spans through an HTML-to-canonical-Markdown adapter.
101
+
102
+ ### Index and search source evidence
103
+
104
+ Declare the source collection in a manifest. Explicit sources and include/exclude globs may select `.pdf`, `.md`, `.xlsx`, and `.xlsm` files.
105
+
106
+ ```toml
107
+ schema_version = 1
108
+
109
+ [[source]]
110
+ path = "2023-iasr-ev-workbook.xlsx"
111
+ ```
112
+
113
+ Synchronise the selected sources into a database, search the resulting lexical and semantic index, then run the integrity checks:
114
+
115
+ ```sh
116
+ tracecite sync \
117
+ --root sources \
118
+ --manifest tracecite-sources.toml \
119
+ --database .tracecite/evidence.sqlite \
120
+ --model-cache-dir .tracecite/model-cache
121
+
122
+ tracecite search \
123
+ "weekday versus weekend electric vehicle charging behaviour" \
124
+ --database .tracecite/evidence.sqlite \
125
+ --model-cache-dir .tracecite/model-cache
126
+
127
+ tracecite doctor --database .tracecite/evidence.sqlite
128
+ ```
129
+
130
+ `sync` is incremental and non-pruning. Unavailable or no-longer-selected sources remain in the database until an explicit `tracecite prune` operation is previewed and applied.
131
+
132
+ Restrict `search` to one or more source types with `--source-type` (repeatable; one of `pdf`, `markdown`, `workbook`). The filter is applied before lexical and vector candidates are ranked and truncated to `--limit`, not as a post-hoc filter on the final result list:
133
+
134
+ ```sh
135
+ tracecite search "coal retirement" \
136
+ --database .tracecite/evidence.sqlite \
137
+ --source-type pdf
138
+ ```
139
+
140
+ Search results include retrieval provenance and a source-specific locator. The abbreviated JSON below shows the stable workbook evidence fields; the actual worksheet and ranges depend on the indexed workbook and chunk configuration.
141
+
142
+ ```json
143
+ {
144
+ "source_path": "inputs-and-assumptions.xlsx",
145
+ "source_type": "workbook",
146
+ "source_sha256": "<64-character SHA-256>",
147
+ "locator": {
148
+ "kind": "excel-range",
149
+ "sheet": "<worksheet name>",
150
+ "range": "<bounding A1 range>",
151
+ "range_kind": "bounding",
152
+ "exact_ranges": ["<exact A1 range>"]
153
+ },
154
+ "provenance": ["lexical", "vector"]
155
+ }
156
+ ```
157
+
158
+ The source path and SHA-256 identify the workbook version. The worksheet and `exact_ranges` identify the cells represented in the indexed passage. `range` is only the convenient bounding rectangle and can include cells that did not contribute to the passage. Search rank identifies candidate evidence; inspect the returned cells before using the result to support a claim.
159
+
160
+ The portable workbook citation is the source path and SHA-256 together with the worksheet and A1 ranges. Exact-range opening is handled by the workbook viewer or by a provider-specific link supplied separately.
161
+
162
+ #### Workbook boundaries
163
+
164
+ - `.xlsx` and `.xlsm` OOXML packages are supported. Legacy binary `.xls` files are outside the supported source set.
165
+ - Stored text, numeric, Boolean, error, formula, and cached formula values are retained. Cached values describe the workbook's stored state; TraceCite does not recalculate formulae.
166
+ - The parser reads stored package content only. It does not execute VBA or refresh external links, Power Query, pivot caches, or data connections.
167
+ - Style-only empty cells are ignored. Excel display formatting is not reconstructed, so styled date or time serials can remain numeric.
168
+ - Workbook chunks are row-oriented. The parser does not yet infer formal Excel tables or propagate complex multi-row headers into every row.
169
+
170
+ ### Normalise one table
171
+
172
+ ```sh
173
+ tracecite table normalise table.md --to text
174
+ tracecite table normalise table.html --from html --to debug-markdown
175
+ ```
176
+
177
+ ### Normalise one document
178
+
179
+ ```sh
180
+ tracecite document normalise report.md --to jsonl
181
+ tracecite document normalise report.md --to embedding-markdown --output report.embedding.md
182
+ ```
183
+
184
+ ### Retrieve retained pages and visual evidence
185
+
186
+ `tracecite page` reads retained PDF page text from the SQLite evidence database. Omitting the selector returns physical page 1. A selector can combine individual pages, closed ranges, and open ranges; overlapping terms are deduplicated and returned in ascending physical-page order.
187
+
188
+ ```sh
189
+ tracecite page reports/example.pdf --database evidence.sqlite
190
+ tracecite page reports/example.pdf 5,12-15,20 --database evidence.sqlite
191
+ tracecite page reports/example.pdf 97- --database evidence.sqlite
192
+ tracecite page reports/example.pdf -20 --database evidence.sqlite
193
+ tracecite page reports/example.pdf all --database evidence.sqlite
194
+ ```
195
+
196
+ The standalone selector `all` is the only implicit complete-source form; it cannot be combined with another term. Multi-page text output marks each physical page. `--format json` returns an ordered array containing retained text, extraction metadata, a citation link, and validated paths for the indexed page render and figure crops. Search results expose the same page-render and figure-crop fields for page-local PDF matches.
197
+
198
+ `extract-pages` uses the same selector grammar but reads the indexed source PDF to create a derivative PDF and provenance manifest. The output directory must already exist outside the source root. TraceCite refuses stale source content, symlink output directories, overlap, and overwrite.
199
+
200
+ ```sh
201
+ mkdir -p ../tracecite-exports
202
+ tracecite extract-pages reports/example.pdf 5,12-15,20 \
203
+ --database evidence.sqlite \
204
+ --output-dir ../tracecite-exports
205
+ ```
206
+
207
+ Use database-backed text or indexed page assets for page-local questions. Select `all` only when the complete source is intentionally required.
208
+
209
+ ### Build the documentation
210
+
211
+ ```sh
212
+ uv run tracecite docs build docs
213
+ uv run tracecite docs build docs_quarto_py --only python
214
+ uv run tracecite docs build docs_quarto_jl --only julia
215
+ ```
216
+
217
+ <!-- TODO:
218
+ Explain the expected `[WARNING] Could not fetch resource`
219
+ -->
220
+
221
+ The public builder discovers configured render inputs, automatically selects the complete site when both runtimes are available, and safely falls back to the available language with exact skipped-file warnings.
222
+ Use `--only python` or `--only julia` for explicit reduced builds.
223
+ External projects can invoke `tracecite prepare` directly after their Quarto render when they already have rendered and staged retained Markdown.
224
+
225
+ See `docs/examples/report-adoption/aemo-isp-comparison/` for a complete, real example of the author -> check -> index -> search -> doctor -> publish-only workflow using two AEMO Integrated System Plan reports.
226
+
227
+ `docs/examples/report-adoption/aemo-isp-comparison/docs/tracecite.toml` demonstrates the documentation evidence contract. Schema version 1 defines exactly `authored_root`, `retained_root`, `staged_root`,
228
+ `source_links`, `index_output`, `publication_exclude`, and optional
229
+ `host_render_command` under `[docs]`. Contract paths are repository-relative and
230
+ must remain contained within the repository.
231
+
232
+ If Julia is unavailable, the automatic build names every configured Julia source it skips and renders the Python overlay without modifying Julia sources.
233
+
234
+ To open the final docs:
235
+
236
+ ```sh
237
+ open docs/build/index.html
238
+ ```
239
+
240
+ ### Direct preparation command
241
+
242
+ ```sh
243
+ tracecite prepare docs/build \
244
+ --project-config docs/_quarto.yml \
245
+ --project-profile python \
246
+ --source-project docs \
247
+ --keep-embedding-markdown .tracecite/embedding-site \
248
+ --render-embedding-site
249
+ ```
250
+
251
+ The generated copy includes `_tracecite/tables.jsonl` and `_tracecite/manifest.json`. Its `_quarto.yml` is derived from the selected documentation profile, preserving theme and navigation while removing execution engines and build hooks. It is disposable, gitignored, and excluded from recursive ingestion.
252
+
253
+ The copied Markdown is deliberately redundant: it keeps the original table for audit and appends the normalised representation for inspection. Normal indexing can consume `tables.jsonl` or the `NormalisedTable` objects directly without writing the copied site.
254
+
255
+ ### Install the agent skills
256
+
257
+ TraceCite bundles three agent skills: `using-tracecite`, `writing-evidence-backed-reports`, and `routing-documentation-source-links`. Copy them into the project's `.agents/skills/` directory:
258
+
259
+ ```sh
260
+ tracecite skills install
261
+ ```
262
+
263
+ `--target` installs them into another skills directory, for example Claude Code's personal skills:
264
+
265
+ ```sh
266
+ tracecite skills install --target ~/.claude/skills
267
+ ```
268
+
269
+ Running the command again replaces the copies with the skills from the installed TraceCite version.
270
+
271
+ ## Contributing
272
+
273
+ ### Environment
274
+
275
+ The core package is fully operated under Python.
276
+
277
+ ```sh
278
+ uv venv
279
+ source .venv/bin/activate
280
+ uv pip install -e ".[evidence,test]"
281
+ ```
282
+
283
+ `requirements.txt` pins the runtime and evidence dependencies to the latest versions that `pyproject.toml` allows. Install it for a reproducible environment, and refresh it with [`pru`](https://github.com/yasirroni/pru). Installing `-e ".[evidence]"` in the same command keeps the upgrades within the `pyproject.toml` bounds:
284
+
285
+ ```sh
286
+ uv pip install -r requirements.txt
287
+ pru -r requirements.txt upgrade_requirements --cmd 'uv pip install --upgrade -e ".[evidence]"'
288
+ ```
289
+
290
+ To build the whole `docs/`, Julia environment is needed.
291
+
292
+ ```sh
293
+ julia --project=. -e 'using Pkg; Pkg.instantiate()'
294
+ ```
295
+
296
+ ### Lint and format
297
+
298
+ [pre-commit](https://pre-commit.com/) runs [Ruff](https://docs.astral.sh/ruff/) on the Python files in each commit. Install it once and enable the hook:
299
+
300
+ ```sh
301
+ uv tool install pre-commit
302
+ pre-commit install
303
+ ```
304
+
305
+ To check every file, run `pre-commit run --all-files`.
306
+
307
+ ### Test
308
+
309
+ Python tests and build:
310
+
311
+ ```sh
312
+ python -m pytest
313
+ uv build
314
+ ```
315
+
316
+ The Julia package is tested by its documentation example, `docs/examples/julia/dirty_dataframe.jl`. Building the documentation runs the example, including its hidden checks:
317
+
318
+ ```sh
319
+ tracecite docs build docs
320
+ ```
@@ -0,0 +1,294 @@
1
+ # TraceCite
2
+
3
+ TraceCite makes executable documentation, and the source documents behind it, searchable and checkable evidence.
4
+
5
+ Its core is source-linked table normalisation. Each table in a rendered Python or Julia documentation page stays in the site as the original evidence, and TraceCite derives deterministic, self-describing row text from it for search, so generated tables become retrievable without changing what readers see.
6
+
7
+ Around that core, TraceCite indexes source collections of Markdown, PDF, `.xlsx`, and `.xlsm` files. It stores retained extraction, source hashes, full-text and vector search records, and source-specific locators such as PDF pages, Markdown lines, and workbook worksheet ranges, and it verifies quotations and report citations against them. The documentation commands join the two parts: `tracecite docs index` adds a project's retained documentation, with its normalised tables, to an evidence index, and `tracecite docs stage` routes source links to local files or public URLs.
8
+
9
+ ## Core architecture
10
+
11
+ ```text
12
+ Python or Julia executable page
13
+ -> Quarto retained Pandoc Markdown
14
+ -> raw table evidence
15
+ -> HTML site
16
+
17
+ retained Markdown
18
+ -> `tracecite prepare` CLI/package
19
+ -> canonical table model
20
+ -> row-oriented retrieval text
21
+ -> diagnostics
22
+ -> optional embedding-inspection website copy
23
+ ```
24
+
25
+ The normal site remains pure Quarto output. The generated inspection copy doubles each table only when explicitly requested.
26
+
27
+ `tracecite docs build docs` is the public automatic documentation builder. It discovers configured executable inputs, selects the complete site when runtimes are available, safely falls back with exact skipped-file warnings, stages retained Markdown, and optionally renders the inspection site. Table normalisation remains in the public `tracecite prepare` command.
28
+
29
+ The searchable-evidence path is separate from the documentation renderer:
30
+
31
+ ```text
32
+ declared PDF, Markdown, or workbook sources
33
+ -> retained source extraction
34
+ -> locator-aware chunks
35
+ -> SQLite FTS5 and sqlite-vec
36
+ -> ranked JSON results with source identity and evidence locators
37
+ ```
38
+
39
+ ## Prerequisites
40
+
41
+ - Python 3.11 or newer;
42
+ - Pandoc, either installed directly or provided by Quarto;
43
+ - Quarto for documentation-site renders;
44
+ - Julia 1.10 or newer only when building Julia documentation pages.
45
+
46
+ The Python normaliser and CLI work without Julia. Automatic documentation builds fall back to the Python-only overlay when configured Julia inputs cannot run; explicit Julia-only builds require Julia.
47
+
48
+ Evidence synchronisation and hybrid search use the optional `evidence` dependencies:
49
+
50
+ ```sh
51
+ uv pip install -e ".[evidence]"
52
+ ```
53
+
54
+ Workbook parsing reads OOXML packages directly with the Python standard library and runs independently of Excel, Julia, Quarto, and third-party workbook readers.
55
+
56
+ ## Usage
57
+
58
+ The public `tracecite` CLI provides table and document normalisation, documentation builds, and source-evidence synchronisation and search. The `prepare` command consumes retained Markdown after a Quarto render and creates the optional inspection-site copy.
59
+
60
+ ### Public API
61
+
62
+ ```python
63
+ from tracecite.tables import (
64
+ normalise_pandoc_table,
65
+ normalise_html_table,
66
+ normalise_document_tables,
67
+ )
68
+ ```
69
+
70
+ `normalise_pandoc_table()` is the core contract. It accepts one Pandoc table and returns raw evidence, canonical Markdown, normalised text, row records, diagnostics, hashes, and version metadata.
71
+
72
+ Each row also receives a deterministic `row_id`. When `row_identity` metadata is supplied, the identifier follows the logical row rather than its current rank or position.
73
+
74
+ `normalise_html_table()` supports Literate.jl, Documenter.jl, PrettyTables, notebook HTML MIME, row spans, and column spans through an HTML-to-canonical-Markdown adapter.
75
+
76
+ ### Index and search source evidence
77
+
78
+ Declare the source collection in a manifest. Explicit sources and include/exclude globs may select `.pdf`, `.md`, `.xlsx`, and `.xlsm` files.
79
+
80
+ ```toml
81
+ schema_version = 1
82
+
83
+ [[source]]
84
+ path = "2023-iasr-ev-workbook.xlsx"
85
+ ```
86
+
87
+ Synchronise the selected sources into a database, search the resulting lexical and semantic index, then run the integrity checks:
88
+
89
+ ```sh
90
+ tracecite sync \
91
+ --root sources \
92
+ --manifest tracecite-sources.toml \
93
+ --database .tracecite/evidence.sqlite \
94
+ --model-cache-dir .tracecite/model-cache
95
+
96
+ tracecite search \
97
+ "weekday versus weekend electric vehicle charging behaviour" \
98
+ --database .tracecite/evidence.sqlite \
99
+ --model-cache-dir .tracecite/model-cache
100
+
101
+ tracecite doctor --database .tracecite/evidence.sqlite
102
+ ```
103
+
104
+ `sync` is incremental and non-pruning. Unavailable or no-longer-selected sources remain in the database until an explicit `tracecite prune` operation is previewed and applied.
105
+
106
+ Restrict `search` to one or more source types with `--source-type` (repeatable; one of `pdf`, `markdown`, `workbook`). The filter is applied before lexical and vector candidates are ranked and truncated to `--limit`, not as a post-hoc filter on the final result list:
107
+
108
+ ```sh
109
+ tracecite search "coal retirement" \
110
+ --database .tracecite/evidence.sqlite \
111
+ --source-type pdf
112
+ ```
113
+
114
+ Search results include retrieval provenance and a source-specific locator. The abbreviated JSON below shows the stable workbook evidence fields; the actual worksheet and ranges depend on the indexed workbook and chunk configuration.
115
+
116
+ ```json
117
+ {
118
+ "source_path": "inputs-and-assumptions.xlsx",
119
+ "source_type": "workbook",
120
+ "source_sha256": "<64-character SHA-256>",
121
+ "locator": {
122
+ "kind": "excel-range",
123
+ "sheet": "<worksheet name>",
124
+ "range": "<bounding A1 range>",
125
+ "range_kind": "bounding",
126
+ "exact_ranges": ["<exact A1 range>"]
127
+ },
128
+ "provenance": ["lexical", "vector"]
129
+ }
130
+ ```
131
+
132
+ The source path and SHA-256 identify the workbook version. The worksheet and `exact_ranges` identify the cells represented in the indexed passage. `range` is only the convenient bounding rectangle and can include cells that did not contribute to the passage. Search rank identifies candidate evidence; inspect the returned cells before using the result to support a claim.
133
+
134
+ The portable workbook citation is the source path and SHA-256 together with the worksheet and A1 ranges. Exact-range opening is handled by the workbook viewer or by a provider-specific link supplied separately.
135
+
136
+ #### Workbook boundaries
137
+
138
+ - `.xlsx` and `.xlsm` OOXML packages are supported. Legacy binary `.xls` files are outside the supported source set.
139
+ - Stored text, numeric, Boolean, error, formula, and cached formula values are retained. Cached values describe the workbook's stored state; TraceCite does not recalculate formulae.
140
+ - The parser reads stored package content only. It does not execute VBA or refresh external links, Power Query, pivot caches, or data connections.
141
+ - Style-only empty cells are ignored. Excel display formatting is not reconstructed, so styled date or time serials can remain numeric.
142
+ - Workbook chunks are row-oriented. The parser does not yet infer formal Excel tables or propagate complex multi-row headers into every row.
143
+
144
+ ### Normalise one table
145
+
146
+ ```sh
147
+ tracecite table normalise table.md --to text
148
+ tracecite table normalise table.html --from html --to debug-markdown
149
+ ```
150
+
151
+ ### Normalise one document
152
+
153
+ ```sh
154
+ tracecite document normalise report.md --to jsonl
155
+ tracecite document normalise report.md --to embedding-markdown --output report.embedding.md
156
+ ```
157
+
158
+ ### Retrieve retained pages and visual evidence
159
+
160
+ `tracecite page` reads retained PDF page text from the SQLite evidence database. Omitting the selector returns physical page 1. A selector can combine individual pages, closed ranges, and open ranges; overlapping terms are deduplicated and returned in ascending physical-page order.
161
+
162
+ ```sh
163
+ tracecite page reports/example.pdf --database evidence.sqlite
164
+ tracecite page reports/example.pdf 5,12-15,20 --database evidence.sqlite
165
+ tracecite page reports/example.pdf 97- --database evidence.sqlite
166
+ tracecite page reports/example.pdf -20 --database evidence.sqlite
167
+ tracecite page reports/example.pdf all --database evidence.sqlite
168
+ ```
169
+
170
+ The standalone selector `all` is the only implicit complete-source form; it cannot be combined with another term. Multi-page text output marks each physical page. `--format json` returns an ordered array containing retained text, extraction metadata, a citation link, and validated paths for the indexed page render and figure crops. Search results expose the same page-render and figure-crop fields for page-local PDF matches.
171
+
172
+ `extract-pages` uses the same selector grammar but reads the indexed source PDF to create a derivative PDF and provenance manifest. The output directory must already exist outside the source root. TraceCite refuses stale source content, symlink output directories, overlap, and overwrite.
173
+
174
+ ```sh
175
+ mkdir -p ../tracecite-exports
176
+ tracecite extract-pages reports/example.pdf 5,12-15,20 \
177
+ --database evidence.sqlite \
178
+ --output-dir ../tracecite-exports
179
+ ```
180
+
181
+ Use database-backed text or indexed page assets for page-local questions. Select `all` only when the complete source is intentionally required.
182
+
183
+ ### Build the documentation
184
+
185
+ ```sh
186
+ uv run tracecite docs build docs
187
+ uv run tracecite docs build docs_quarto_py --only python
188
+ uv run tracecite docs build docs_quarto_jl --only julia
189
+ ```
190
+
191
+ <!-- TODO:
192
+ Explain the expected `[WARNING] Could not fetch resource`
193
+ -->
194
+
195
+ The public builder discovers configured render inputs, automatically selects the complete site when both runtimes are available, and safely falls back to the available language with exact skipped-file warnings.
196
+ Use `--only python` or `--only julia` for explicit reduced builds.
197
+ External projects can invoke `tracecite prepare` directly after their Quarto render when they already have rendered and staged retained Markdown.
198
+
199
+ See `docs/examples/report-adoption/aemo-isp-comparison/` for a complete, real example of the author -> check -> index -> search -> doctor -> publish-only workflow using two AEMO Integrated System Plan reports.
200
+
201
+ `docs/examples/report-adoption/aemo-isp-comparison/docs/tracecite.toml` demonstrates the documentation evidence contract. Schema version 1 defines exactly `authored_root`, `retained_root`, `staged_root`,
202
+ `source_links`, `index_output`, `publication_exclude`, and optional
203
+ `host_render_command` under `[docs]`. Contract paths are repository-relative and
204
+ must remain contained within the repository.
205
+
206
+ If Julia is unavailable, the automatic build names every configured Julia source it skips and renders the Python overlay without modifying Julia sources.
207
+
208
+ To open the final docs:
209
+
210
+ ```sh
211
+ open docs/build/index.html
212
+ ```
213
+
214
+ ### Direct preparation command
215
+
216
+ ```sh
217
+ tracecite prepare docs/build \
218
+ --project-config docs/_quarto.yml \
219
+ --project-profile python \
220
+ --source-project docs \
221
+ --keep-embedding-markdown .tracecite/embedding-site \
222
+ --render-embedding-site
223
+ ```
224
+
225
+ The generated copy includes `_tracecite/tables.jsonl` and `_tracecite/manifest.json`. Its `_quarto.yml` is derived from the selected documentation profile, preserving theme and navigation while removing execution engines and build hooks. It is disposable, gitignored, and excluded from recursive ingestion.
226
+
227
+ The copied Markdown is deliberately redundant: it keeps the original table for audit and appends the normalised representation for inspection. Normal indexing can consume `tables.jsonl` or the `NormalisedTable` objects directly without writing the copied site.
228
+
229
+ ### Install the agent skills
230
+
231
+ TraceCite bundles three agent skills: `using-tracecite`, `writing-evidence-backed-reports`, and `routing-documentation-source-links`. Copy them into the project's `.agents/skills/` directory:
232
+
233
+ ```sh
234
+ tracecite skills install
235
+ ```
236
+
237
+ `--target` installs them into another skills directory, for example Claude Code's personal skills:
238
+
239
+ ```sh
240
+ tracecite skills install --target ~/.claude/skills
241
+ ```
242
+
243
+ Running the command again replaces the copies with the skills from the installed TraceCite version.
244
+
245
+ ## Contributing
246
+
247
+ ### Environment
248
+
249
+ The core package is fully operated under Python.
250
+
251
+ ```sh
252
+ uv venv
253
+ source .venv/bin/activate
254
+ uv pip install -e ".[evidence,test]"
255
+ ```
256
+
257
+ `requirements.txt` pins the runtime and evidence dependencies to the latest versions that `pyproject.toml` allows. Install it for a reproducible environment, and refresh it with [`pru`](https://github.com/yasirroni/pru). Installing `-e ".[evidence]"` in the same command keeps the upgrades within the `pyproject.toml` bounds:
258
+
259
+ ```sh
260
+ uv pip install -r requirements.txt
261
+ pru -r requirements.txt upgrade_requirements --cmd 'uv pip install --upgrade -e ".[evidence]"'
262
+ ```
263
+
264
+ To build the whole `docs/`, Julia environment is needed.
265
+
266
+ ```sh
267
+ julia --project=. -e 'using Pkg; Pkg.instantiate()'
268
+ ```
269
+
270
+ ### Lint and format
271
+
272
+ [pre-commit](https://pre-commit.com/) runs [Ruff](https://docs.astral.sh/ruff/) on the Python files in each commit. Install it once and enable the hook:
273
+
274
+ ```sh
275
+ uv tool install pre-commit
276
+ pre-commit install
277
+ ```
278
+
279
+ To check every file, run `pre-commit run --all-files`.
280
+
281
+ ### Test
282
+
283
+ Python tests and build:
284
+
285
+ ```sh
286
+ python -m pytest
287
+ uv build
288
+ ```
289
+
290
+ The Julia package is tested by its documentation example, `docs/examples/julia/dirty_dataframe.jl`. Building the documentation runs the example, including its hidden checks:
291
+
292
+ ```sh
293
+ tracecite docs build docs
294
+ ```
@@ -0,0 +1,53 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "tracecite"
7
+ version = "0.0.2"
8
+ description = "Source-linked table normalisation and evidence retrieval for executable documentation"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{name = "ARPST-UniMelb"}]
14
+ dependencies = [
15
+ "beautifulsoup4>=4.12",
16
+ "pandas>=2.0",
17
+ "PyYAML>=6.0",
18
+ "tabulate>=0.9",
19
+ "nbformat>=5.10",
20
+ "nbclient>=0.11",
21
+ "ipykernel>=7.3",
22
+ ]
23
+
24
+ [project.optional-dependencies]
25
+ evidence = [
26
+ "huggingface-hub>=1.23,<2",
27
+ "pymupdf>=1.28,<2",
28
+ "sentence-transformers>=5.6,<6",
29
+ "sqlite-vec>=0.1.9,<0.2",
30
+ ]
31
+ test = ["build>=1.2", "pytest>=8.4,<9"]
32
+
33
+ [project.scripts]
34
+ tracecite = "tracecite.cli:main"
35
+
36
+ [tool.setuptools.packages.find]
37
+ where = ["src"]
38
+
39
+ [tool.setuptools.package-data]
40
+ tracecite = ["skills/**/*"]
41
+
42
+ [tool.pyright]
43
+ include = ["src", "tests"]
44
+ pythonVersion = "3.11"
45
+
46
+ [tool.ruff]
47
+ # scripts/bootstrap_docs.py copies docs_quarto_py from docs/. Markdown is not formatted
48
+ # because retained .html.md pages are generated output and skill fixtures are test data.
49
+ extend-exclude = ["docs_quarto_py", "*.md"]
50
+
51
+ [tool.ruff.lint.per-file-ignores]
52
+ # A bare expression at the end of a notebook cell displays its value.
53
+ "docs/examples/python/*.py" = ["B018"]