@tracecart/cli 0.1.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.
Files changed (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +149 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/commands/delta.d.ts +1 -0
  7. package/dist/commands/delta.js +19 -0
  8. package/dist/commands/delta.js.map +1 -0
  9. package/dist/commands/extract-prompt.d.ts +2 -0
  10. package/dist/commands/extract-prompt.js +35 -0
  11. package/dist/commands/extract-prompt.js.map +1 -0
  12. package/dist/commands/extract-validate.d.ts +2 -0
  13. package/dist/commands/extract-validate.js +21 -0
  14. package/dist/commands/extract-validate.js.map +1 -0
  15. package/dist/commands/finalize.d.ts +1 -0
  16. package/dist/commands/finalize.js +64 -0
  17. package/dist/commands/finalize.js.map +1 -0
  18. package/dist/commands/init.d.ts +1 -0
  19. package/dist/commands/init.js +33 -0
  20. package/dist/commands/init.js.map +1 -0
  21. package/dist/commands/match-prompt.d.ts +2 -0
  22. package/dist/commands/match-prompt.js +51 -0
  23. package/dist/commands/match-prompt.js.map +1 -0
  24. package/dist/commands/match-validate.d.ts +2 -0
  25. package/dist/commands/match-validate.js +15 -0
  26. package/dist/commands/match-validate.js.map +1 -0
  27. package/dist/commands/presets.d.ts +1 -0
  28. package/dist/commands/presets.js +14 -0
  29. package/dist/commands/presets.js.map +1 -0
  30. package/dist/commands/remainder.d.ts +1 -0
  31. package/dist/commands/remainder.js +19 -0
  32. package/dist/commands/remainder.js.map +1 -0
  33. package/dist/commands/reverse-extract-validate.d.ts +1 -0
  34. package/dist/commands/reverse-extract-validate.js +20 -0
  35. package/dist/commands/reverse-extract-validate.js.map +1 -0
  36. package/dist/commands/reverse-match-prompt.d.ts +2 -0
  37. package/dist/commands/reverse-match-prompt.js +50 -0
  38. package/dist/commands/reverse-match-prompt.js.map +1 -0
  39. package/dist/commands/reverse-match-validate.d.ts +1 -0
  40. package/dist/commands/reverse-match-validate.js +14 -0
  41. package/dist/commands/reverse-match-validate.js.map +1 -0
  42. package/dist/commands/split.d.ts +1 -0
  43. package/dist/commands/split.js +26 -0
  44. package/dist/commands/split.js.map +1 -0
  45. package/dist/commands/status.d.ts +1 -0
  46. package/dist/commands/status.js +34 -0
  47. package/dist/commands/status.js.map +1 -0
  48. package/dist/commands/update.d.ts +1 -0
  49. package/dist/commands/update.js +5 -0
  50. package/dist/commands/update.js.map +1 -0
  51. package/dist/extract/extract.d.ts +37 -0
  52. package/dist/extract/extract.js +158 -0
  53. package/dist/extract/extract.js.map +1 -0
  54. package/dist/extract/remainder.d.ts +16 -0
  55. package/dist/extract/remainder.js +34 -0
  56. package/dist/extract/remainder.js.map +1 -0
  57. package/dist/match/coverage.d.ts +64 -0
  58. package/dist/match/coverage.js +375 -0
  59. package/dist/match/coverage.js.map +1 -0
  60. package/dist/output/delta.d.ts +46 -0
  61. package/dist/output/delta.js +155 -0
  62. package/dist/output/delta.js.map +1 -0
  63. package/dist/output/trace-map.d.ts +89 -0
  64. package/dist/output/trace-map.js +135 -0
  65. package/dist/output/trace-map.js.map +1 -0
  66. package/dist/parse/clause-split.d.ts +20 -0
  67. package/dist/parse/clause-split.js +185 -0
  68. package/dist/parse/clause-split.js.map +1 -0
  69. package/dist/parse/discover-inputs.d.ts +16 -0
  70. package/dist/parse/discover-inputs.js +97 -0
  71. package/dist/parse/discover-inputs.js.map +1 -0
  72. package/dist/parse/parse-document.d.ts +28 -0
  73. package/dist/parse/parse-document.js +141 -0
  74. package/dist/parse/parse-document.js.map +1 -0
  75. package/dist/preset.d.ts +18 -0
  76. package/dist/preset.js +85 -0
  77. package/dist/preset.js.map +1 -0
  78. package/package.json +58 -0
  79. package/presets/spec-coverage.json +15 -0
  80. package/prompts/coverage_check.txt +38 -0
  81. package/prompts/extract.txt +40 -0
  82. package/prompts/reverse_check.txt +36 -0
  83. package/templates/claude/commands/tracecart.md +217 -0
@@ -0,0 +1,14 @@
1
+ import { listPresets } from '../preset.js';
2
+ export async function cmdPresets(pkgRoot) {
3
+ const presets = listPresets(pkgRoot);
4
+ if (presets.length === 0) {
5
+ process.stderr.write('No presets found.\n');
6
+ return;
7
+ }
8
+ for (const p of presets) {
9
+ const source = p.source === 'project-local' ? ' [local]' : '';
10
+ const desc = p.description ? ` — ${p.description}` : '';
11
+ process.stdout.write(`${p.name}${source}${desc}\n`);
12
+ }
13
+ }
14
+ //# sourceMappingURL=presets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presets.js","sourceRoot":"","sources":["../../src/commands/presets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAe;IAC9C,MAAM,OAAO,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAErC,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAC5C,OAAO;IACT,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,KAAK,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9D,MAAM,IAAI,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACxD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,GAAG,MAAM,GAAG,IAAI,IAAI,CAAC,CAAC;IACtD,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function cmdRemainder(args: string[]): Promise<void>;
@@ -0,0 +1,19 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { computeRemainder, isComplete, extractionStats } from '../extract/remainder.js';
3
+ export async function cmdRemainder(args) {
4
+ if (args.length < 2) {
5
+ process.stderr.write('Usage: tracecart remainder <clauses.json> <traces.json>\n');
6
+ process.exit(1);
7
+ }
8
+ const clausesData = JSON.parse(readFileSync(args[0], 'utf-8'));
9
+ const clauses = (clausesData.clauses ?? (Array.isArray(clausesData) ? clausesData : []));
10
+ const tracesData = JSON.parse(readFileSync(args[1], 'utf-8'));
11
+ const traces = (tracesData.traces ?? (Array.isArray(tracesData) ? tracesData : []));
12
+ const contentClauses = clauses.filter(c => !c.is_header);
13
+ const remainder = computeRemainder(contentClauses, traces);
14
+ const stats = extractionStats(contentClauses, traces, remainder);
15
+ const complete = isComplete(remainder, null);
16
+ const result = { stats, remainder, complete };
17
+ process.stdout.write(JSON.stringify(result, null, 2));
18
+ }
19
+ //# sourceMappingURL=remainder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remainder.js","sourceRoot":"","sources":["../../src/commands/remainder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAGxF,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,IAAc;IAC/C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2DAA2D,CAAC,CAAC;QAClF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC/D,MAAM,OAAO,GAAa,CAAC,WAAW,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAEnG,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAY,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAE7F,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,SAAS,GAAG,gBAAgB,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;IAC3D,MAAM,KAAK,GAAG,eAAe,CAAC,cAAc,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAE7C,MAAM,MAAM,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;IAC9C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function cmdReverseExtractValidate(args: string[]): Promise<void>;
@@ -0,0 +1,20 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { validateTraces } from '../extract/extract.js';
3
+ export async function cmdReverseExtractValidate(args) {
4
+ if (args.length < 2) {
5
+ process.stderr.write('Usage: tracecart reverse-extract-validate <llm_output.txt> <clauses.json> [--target <file>]\n');
6
+ process.exit(1);
7
+ }
8
+ const rawOutput = readFileSync(args[0], 'utf-8');
9
+ const data = JSON.parse(readFileSync(args[1], 'utf-8'));
10
+ const clauses = data.clauses ?? (Array.isArray(data) ? data : []);
11
+ let targetFile = '';
12
+ for (let i = 2; i < args.length; i++) {
13
+ if (args[i] === '--target' && args[i + 1]) {
14
+ targetFile = args[++i];
15
+ }
16
+ }
17
+ const result = validateTraces(rawOutput, clauses, targetFile, 'RT');
18
+ process.stdout.write(JSON.stringify(result, null, 2));
19
+ }
20
+ //# sourceMappingURL=reverse-extract-validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverse-extract-validate.js","sourceRoot":"","sources":["../../src/commands/reverse-extract-validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGvD,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,IAAc;IAC5D,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,+FAA+F,CAAC,CAAC;QACtH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACjD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IACxD,MAAM,OAAO,GAAa,IAAI,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAE5E,IAAI,UAAU,GAAG,EAAE,CAAC;IACpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAAC,UAAU,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAAC,CAAC;IACxE,CAAC;IAED,MAAM,MAAM,GAAG,cAAc,CAAC,SAAS,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;IACpE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Preset } from '../preset.js';
2
+ export declare function cmdReverseMatchPrompt(args: string[], pkgRoot: string, preset: Preset): Promise<void>;
@@ -0,0 +1,50 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { batchTraces } from '../match/coverage.js';
4
+ export async function cmdReverseMatchPrompt(args, pkgRoot, preset) {
5
+ if (args.length < 2) {
6
+ process.stderr.write('Usage: tracecart reverse-match-prompt <reverse_traces.json> <source_traces.json> [--preset <name>]\n');
7
+ process.exit(1);
8
+ }
9
+ const reverseData = JSON.parse(readFileSync(args[0], 'utf-8'));
10
+ const reverseTraces = reverseData.traces ?? (Array.isArray(reverseData) ? reverseData : []);
11
+ const sourceData = JSON.parse(readFileSync(args[1], 'utf-8'));
12
+ const sourceTraces = sourceData.traces ?? (Array.isArray(sourceData) ? sourceData : []);
13
+ const templateFile = preset.prompts.reverse_check ?? 'reverse_check.txt';
14
+ const templatePath = resolve(pkgRoot, 'prompts', templateFile);
15
+ const template = readFileSync(templatePath, 'utf-8');
16
+ function formatFromPreset(batch) {
17
+ const claimLines = [];
18
+ for (const t of batch) {
19
+ const tid = (t.id ?? '');
20
+ const text = (t.text ?? '');
21
+ const ttype = (t.type ?? 'REQUIREMENT');
22
+ claimLines.push(`[${tid}] (${ttype}) ${text}`);
23
+ }
24
+ const evidenceLines = [];
25
+ for (const t of sourceTraces) {
26
+ const tid = (t.id ?? '');
27
+ const text = (t.text ?? '');
28
+ const ttype = (t.type ?? 'REQUIREMENT');
29
+ const implicit = t.implicit ? ' [implicit]' : '';
30
+ evidenceLines.push(`[${tid}] (${ttype}${implicit}) ${text}`);
31
+ }
32
+ let prompt = template.replace('{claims}', claimLines.join('\n'));
33
+ prompt = prompt.replace('{evidence}', evidenceLines.join('\n'));
34
+ return prompt;
35
+ }
36
+ const batches = batchTraces(reverseTraces);
37
+ if (batches.length === 1) {
38
+ process.stdout.write(formatFromPreset(reverseTraces));
39
+ }
40
+ else {
41
+ for (let bi = 0; bi < batches.length; bi++) {
42
+ process.stderr.write(`--- BATCH ${bi + 1}/${batches.length} ---\n`);
43
+ process.stdout.write(formatFromPreset(batches[bi]));
44
+ if (bi < batches.length - 1) {
45
+ process.stdout.write('\n---BATCH_SEPARATOR---\n');
46
+ }
47
+ }
48
+ }
49
+ }
50
+ //# sourceMappingURL=reverse-match-prompt.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverse-match-prompt.js","sourceRoot":"","sources":["../../src/commands/reverse-match-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,IAAc,EAAE,OAAe,EAAE,MAAc;IACzF,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,sGAAsG,CAAC,CAAC;QAC7H,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC/D,MAAM,aAAa,GAA8B,WAAW,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,W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@
1
+ export declare function cmdReverseMatchValidate(args: string[]): Promise<void>;
@@ -0,0 +1,14 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { validateReverseMatches } from '../match/coverage.js';
3
+ export async function cmdReverseMatchValidate(args) {
4
+ if (args.length < 2) {
5
+ process.stderr.write('Usage: tracecart reverse-match-validate <llm_output.txt> <reverse_traces.json>\n');
6
+ process.exit(1);
7
+ }
8
+ const rawOutput = readFileSync(args[0], 'utf-8');
9
+ const reverseData = JSON.parse(readFileSync(args[1], 'utf-8'));
10
+ const reverseTraces = reverseData.traces ?? (Array.isArray(reverseData) ? reverseData : []);
11
+ const result = validateReverseMatches(rawOutput, reverseTraces);
12
+ process.stdout.write(JSON.stringify(result, null, 2));
13
+ }
14
+ //# sourceMappingURL=reverse-match-validate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reverse-match-validate.js","sourceRoot":"","sources":["../../src/commands/reverse-match-validate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,IAAc;IAC1D,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAC;QACzG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IACjD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC/D,MAAM,aAAa,GAAG,WAAW,CAAC,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAE5F,MAAM,MAAM,GAAG,sBAAsB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC;IAChE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function cmdSplit(args: string[]): Promise<void>;
@@ -0,0 +1,26 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { processDocument } from '../parse/clause-split.js';
3
+ export async function cmdSplit(args) {
4
+ if (!args[0]) {
5
+ process.stderr.write('Usage: tracecart split <source.md> [--lang hu|en]\n');
6
+ process.exit(1);
7
+ }
8
+ const sourcePath = args[0];
9
+ const text = readFileSync(sourcePath, 'utf-8');
10
+ const clauses = processDocument(text);
11
+ const contentClauses = clauses.filter(c => !c.is_header);
12
+ const compoundLines = new Set();
13
+ for (const c of contentClauses) {
14
+ if (c.clause_index > 0)
15
+ compoundLines.add(c.line_number);
16
+ }
17
+ const result = {
18
+ source_file: sourcePath,
19
+ total_lines: text.split('\n').length,
20
+ content_clauses: contentClauses.length,
21
+ compound_lines_split: compoundLines.size,
22
+ clauses,
23
+ };
24
+ process.stdout.write(JSON.stringify(result, null, 2));
25
+ }
26
+ //# sourceMappingURL=split.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"split.js","sourceRoot":"","sources":["../../src/commands/split.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAc;IAC3C,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qDAAqD,CAAC,CAAC;QAC5E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3B,MAAM,IAAI,GAAG,YAAY,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC/C,MAAM,OAAO,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAEtC,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAC;IACxC,KAAK,MAAM,CAAC,IAAI,cAAc,EAAE,CAAC;QAC/B,IAAI,CAAC,CAAC,YAAY,GAAG,CAAC;YAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;IAC3D,CAAC;IAED,MAAM,MAAM,GAAG;QACb,WAAW,EAAE,UAAU;QACvB,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM;QACpC,eAAe,EAAE,cAAc,CAAC,MAAM;QACtC,oBAAoB,EAAE,aAAa,CAAC,IAAI;QACxC,OAAO;KACR,CAAC;IAEF,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AACxD,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function cmdStatus(args: string[]): Promise<void>;
@@ -0,0 +1,34 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { computeRemainder, extractionStats } from '../extract/remainder.js';
3
+ import { computeSummary } from '../output/trace-map.js';
4
+ export async function cmdStatus(args) {
5
+ if (args.length < 2) {
6
+ process.stderr.write('Usage: tracecart status <traces.json> <clauses.json>\n');
7
+ process.exit(1);
8
+ }
9
+ const tracesData = JSON.parse(readFileSync(args[0], 'utf-8'));
10
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
11
+ const traces = tracesData.traces ?? (Array.isArray(tracesData) ? tracesData : []);
12
+ const clausesData = JSON.parse(readFileSync(args[1], 'utf-8'));
13
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
+ const clauses = clausesData.clauses ?? (Array.isArray(clausesData) ? clausesData : []);
15
+ const contentClauses = clauses.filter((c) => !c.is_header);
16
+ const remainder = computeRemainder(contentClauses, traces);
17
+ const stats = extractionStats(contentClauses, traces, remainder);
18
+ const hasStatus = traces.some((t) => 'status' in t);
19
+ process.stderr.write(`Clauses: ${stats.total_clauses}\n`);
20
+ process.stderr.write(`Traces extracted: ${stats.traces_extracted}\n`);
21
+ process.stderr.write(`Clauses consumed: ${stats.clauses_consumed}/${stats.total_clauses} (${stats.coverage_pct.toFixed(1)}%)\n`);
22
+ process.stderr.write(`Remainder: ${stats.clauses_remaining} clauses\n`);
23
+ process.stderr.write(`Extraction complete: ${stats.complete}\n`);
24
+ if (hasStatus) {
25
+ const summary = computeSummary(traces);
26
+ process.stderr.write(`\nCoverage matching:\n`);
27
+ process.stderr.write(` Score: ${summary.coverage_score_pct}%\n`);
28
+ process.stderr.write(` COVERED: ${summary.covered}\n`);
29
+ process.stderr.write(` PARTIAL: ${summary.partial}\n`);
30
+ process.stderr.write(` MISSING: ${summary.missing}\n`);
31
+ process.stderr.write(` DEFERRED: ${summary.deferred}\n`);
32
+ }
33
+ }
34
+ //# sourceMappingURL=status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAc;IAC5C,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,O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E,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAqB,KAAK,CAAC,gBAAgB,IAAI,KAAK,CAAC,aAAa,KAAK,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACjI,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,KAAK,CAAC,iBAAiB,YAAY,CAAC,CAAC;IACxE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,KAAK,CAAC,QAAQ,IAAI,CAAC,CAAC;IAEjE,IAAI,SAAS,EAAE,CAAC;QACd,MAAM,OAAO,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC;QACvC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC/C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,OAAO,CAAC,kBAAkB,KAAK,CAAC,CAAC;QAClE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC;QACxD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC;QACxD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,OAAO,CAAC,OAAO,IAAI,CAAC,CAAC;QACxD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function cmdUpdate(args: string[], pkgRoot: string): Promise<void>;
@@ -0,0 +1,5 @@
1
+ import { cmdInit } from './init.js';
2
+ export async function cmdUpdate(args, pkgRoot) {
3
+ await cmdInit(args, pkgRoot);
4
+ }
5
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/commands/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,IAAc,EAAE,OAAe;IAC7D,MAAM,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,37 @@
1
+ export declare const VALID_TYPES: Set<"REQUIREMENT" | "DECISION" | "WISH" | "OPEN_QUESTION" | "EXCLUSION">;
2
+ export type TraceType = 'REQUIREMENT' | 'DECISION' | 'WISH' | 'OPEN_QUESTION' | 'EXCLUSION';
3
+ export interface TraceSource {
4
+ file: string;
5
+ line: number;
6
+ col_start: number;
7
+ col_end: number;
8
+ }
9
+ export interface Trace {
10
+ id: string;
11
+ text: string;
12
+ type: TraceType;
13
+ source: TraceSource;
14
+ clause_id: string;
15
+ clause_ids: string[];
16
+ topics: string[];
17
+ implicit: boolean;
18
+ triple?: unknown;
19
+ signal?: string;
20
+ }
21
+ export interface Clause {
22
+ clause_id: string;
23
+ text: string;
24
+ line_number: number;
25
+ clause_index: number;
26
+ is_header?: boolean;
27
+ is_meta?: boolean;
28
+ }
29
+ export interface ValidationResult {
30
+ traces: Trace[];
31
+ errors: string[];
32
+ }
33
+ export declare function formatPrompt(clauses: Clause[], sourceFile: string | undefined, language: string | undefined, pkgRoot: string): string;
34
+ export declare function sourceHash(filepath: string): string;
35
+ export declare function validateTraces(rawOutput: string, clauses: Clause[], sourceFile?: string, idPrefix?: string, validTypes?: Set<string>): ValidationResult;
36
+ export declare function parseJsonOutput(raw: string): unknown[] | null;
37
+ export declare function mergeTraces(existing: Trace[], newTraces: Trace[]): Trace[];
@@ -0,0 +1,158 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { createHash } from 'node:crypto';
4
+ export const VALID_TYPES = new Set([
5
+ 'REQUIREMENT', 'DECISION', 'WISH', 'OPEN_QUESTION', 'EXCLUSION',
6
+ ]);
7
+ export function formatPrompt(clauses, sourceFile = '', language = 'hu', pkgRoot) {
8
+ const templatePath = language === 'en'
9
+ ? resolve(pkgRoot, 'prompts', 'en', 'extract.txt')
10
+ : resolve(pkgRoot, 'prompts', 'extract.txt');
11
+ const template = readFileSync(templatePath, 'utf-8');
12
+ const clauseLines = [];
13
+ for (const c of clauses) {
14
+ if (c.is_header || c.is_meta)
15
+ continue;
16
+ clauseLines.push(`[${c.clause_id}] ${c.text}`);
17
+ }
18
+ return template.replace('{clauses}', clauseLines.join('\n'));
19
+ }
20
+ export function sourceHash(filepath) {
21
+ return createHash('sha256').update(filepath, 'utf-8').digest('hex').slice(0, 6);
22
+ }
23
+ export function validateTraces(rawOutput, clauses, sourceFile = '', idPrefix = 'T', validTypes = VALID_TYPES) {
24
+ const errors = [];
25
+ const traces = [];
26
+ const parsed = parseJsonOutput(rawOutput);
27
+ if (parsed === null) {
28
+ return { traces: [], errors: ['Failed to parse LLM output as JSON'] };
29
+ }
30
+ if (!Array.isArray(parsed)) {
31
+ return { traces: [], errors: ['LLM output is not a JSON array'] };
32
+ }
33
+ const clauseMap = new Map();
34
+ for (const c of clauses) {
35
+ if (!c.is_header && !c.is_meta) {
36
+ clauseMap.set(c.clause_id, c);
37
+ }
38
+ }
39
+ const fileHash = sourceHash(sourceFile);
40
+ const idCounter = new Map();
41
+ for (let i = 0; i < parsed.length; i++) {
42
+ const raw = parsed[i];
43
+ if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
44
+ errors.push(`Entry ${i}: not a dict`);
45
+ continue;
46
+ }
47
+ const entry = raw;
48
+ let clauseId = entry.clause_id;
49
+ if (!clauseId) {
50
+ const clauseIds = (entry.clause_ids ?? []);
51
+ if (clauseIds.length > 0) {
52
+ clauseId = clauseIds[0];
53
+ }
54
+ else {
55
+ errors.push(`Entry ${i}: missing clause_id`);
56
+ continue;
57
+ }
58
+ }
59
+ let traceType = (entry.type ?? '').toUpperCase();
60
+ if (!validTypes.has(traceType)) {
61
+ errors.push(`Entry ${i}: invalid type "${traceType}"`);
62
+ traceType = 'REQUIREMENT';
63
+ }
64
+ const text = (entry.text ?? '');
65
+ if (!text) {
66
+ errors.push(`Entry ${i}: missing text`);
67
+ continue;
68
+ }
69
+ const clause = clauseMap.get(clauseId);
70
+ const lineNum = clause ? clause.line_number : 0;
71
+ const clauseIdx = clause ? clause.clause_index : 0;
72
+ const baseId = `${idPrefix}-${fileHash}-${String(lineNum).padStart(3, '0')}-${clauseIdx}`;
73
+ const seq = idCounter.get(baseId) ?? 0;
74
+ idCounter.set(baseId, seq + 1);
75
+ const traceId = seq === 0 ? baseId : `${baseId}-${seq}`;
76
+ const trace = {
77
+ id: traceId,
78
+ text,
79
+ type: traceType,
80
+ source: {
81
+ file: sourceFile,
82
+ line: lineNum,
83
+ col_start: 0,
84
+ col_end: clause ? clause.text.length : text.length,
85
+ },
86
+ clause_id: clauseId,
87
+ clause_ids: (entry.clause_ids ?? [clauseId]),
88
+ topics: (entry.tags ?? entry.topics ?? []),
89
+ implicit: (entry.implicit ?? false),
90
+ triple: entry.triple,
91
+ };
92
+ if (entry.signal) {
93
+ trace.signal = entry.signal;
94
+ }
95
+ traces.push(trace);
96
+ }
97
+ return { traces, errors };
98
+ }
99
+ export function parseJsonOutput(raw) {
100
+ raw = raw.trim();
101
+ if (raw.startsWith('```json')) {
102
+ raw = raw.slice(7);
103
+ }
104
+ if (raw.startsWith('```')) {
105
+ raw = raw.slice(3);
106
+ }
107
+ if (raw.endsWith('```')) {
108
+ raw = raw.slice(0, -3);
109
+ }
110
+ raw = raw.trim();
111
+ try {
112
+ const result = JSON.parse(raw);
113
+ return result;
114
+ }
115
+ catch {
116
+ // fall through
117
+ }
118
+ const start = raw.indexOf('[');
119
+ const end = raw.lastIndexOf(']');
120
+ if (start !== -1 && end !== -1 && end > start) {
121
+ try {
122
+ return JSON.parse(raw.slice(start, end + 1));
123
+ }
124
+ catch {
125
+ // fall through
126
+ }
127
+ }
128
+ return null;
129
+ }
130
+ export function mergeTraces(existing, newTraces) {
131
+ const existingClauseIds = new Set();
132
+ for (const t of existing) {
133
+ if (t.clause_id)
134
+ existingClauseIds.add(t.clause_id);
135
+ if (t.clause_ids) {
136
+ for (const id of t.clause_ids)
137
+ existingClauseIds.add(id);
138
+ }
139
+ }
140
+ const merged = [...existing];
141
+ for (const t of newTraces) {
142
+ const tIds = new Set(t.clause_ids ?? [t.clause_id ?? '']);
143
+ let allExist = true;
144
+ for (const id of tIds) {
145
+ if (!existingClauseIds.has(id)) {
146
+ allExist = false;
147
+ break;
148
+ }
149
+ }
150
+ if (!allExist) {
151
+ merged.push(t);
152
+ for (const id of tIds)
153
+ existingClauseIds.add(id);
154
+ }
155
+ }
156
+ return merged;
157
+ }
158
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../src/extract/extract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,CAAC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IACjC,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,EAAE,WAAW;CACvD,CAAC,CAAC;AAsCZ,MAAM,UAAU,YAAY,CAC1B,OAAiB,EACjB,aAAqB,EAAE,EACvB,WAAmB,IAAI,EACvB,OAAe;IAEf,MAAM,YAAY,GAAG,QAAQ,KAAK,IAAI;QACpC,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,aAAa,CAAC;QAClD,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC;IAE/C,MAAM,QAAQ,GAAG,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAErD,MAAM,WAAW,GAAa,EAAE,CAAC;IACjC,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,C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MAAM;YACR,CAAC;QACH,CAAC;QACD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACf,KAAK,MAAM,EAAE,IAAI,IAAI;gBAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Clause, Trace } from './extract.js';
2
+ export interface ExtractionStats {
3
+ total_clauses: number;
4
+ traces_extracted: number;
5
+ clauses_consumed: number;
6
+ clauses_remaining: number;
7
+ coverage_pct: number;
8
+ complete: boolean;
9
+ }
10
+ export interface RemainderResult {
11
+ stats: ExtractionStats;
12
+ remainder: Clause[];
13
+ }
14
+ export declare function computeRemainder(clauses: Clause[], traces: Trace[]): Clause[];
15
+ export declare function isComplete(remainder: Clause[], previousRemainder?: Clause[] | null): boolean;
16
+ export declare function extractionStats(clauses: Clause[], traces: Trace[], remainder: Clause[]): ExtractionStats;
@@ -0,0 +1,34 @@
1
+ export function computeRemainder(clauses, traces) {
2
+ const tracedIds = new Set();
3
+ for (const trace of traces) {
4
+ if (trace.clause_id)
5
+ tracedIds.add(trace.clause_id);
6
+ if (trace.clause_ids) {
7
+ for (const id of trace.clause_ids)
8
+ tracedIds.add(id);
9
+ }
10
+ }
11
+ return clauses.filter(c => !tracedIds.has(c.clause_id));
12
+ }
13
+ export function isComplete(remainder, previousRemainder = null) {
14
+ if (remainder.length === 0)
15
+ return true;
16
+ if (previousRemainder !== null) {
17
+ if (remainder.length >= previousRemainder.length)
18
+ return true;
19
+ }
20
+ return false;
21
+ }
22
+ export function extractionStats(clauses, traces, remainder) {
23
+ return {
24
+ total_clauses: clauses.length,
25
+ traces_extracted: traces.length,
26
+ clauses_consumed: clauses.length - remainder.length,
27
+ clauses_remaining: remainder.length,
28
+ coverage_pct: clauses.length > 0
29
+ ? (clauses.length - remainder.length) / clauses.length * 100
30
+ : 0,
31
+ complete: remainder.length === 0,
32
+ };
33
+ }
34
+ //# sourceMappingURL=remainder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remainder.js","sourceRoot":"","sources":["../../src/extract/remainder.ts"],"names":[],"mappings":"AAgBA,MAAM,UAAU,gBAAgB,CAAC,OAAiB,EAAE,MAAe;IACjE,MAAM,SAAS,GAAG,IAAI,GAAG,EAAU,CAAC;IACpC,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,KAAK,CAAC,SAAS;YAAE,SAAS,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACpD,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;YACrB,KAAK,MAAM,EAAE,IAAI,KAAK,CAAC,UAAU;gBAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;IAED,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,UAAU,CACxB,SAAmB,EACnB,oBAAqC,IAAI;IAEzC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAExC,IAAI,iBAAiB,KAAK,IAAI,EAAE,CAAC;QAC/B,IAAI,SAAS,CAAC,MAAM,IAAI,iBAAiB,CAAC,MAAM;YAAE,OAAO,IAAI,CAAC;IAChE,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,OAAiB,EACjB,MAAe,EACf,SAAmB;IAEnB,OAAO;QACL,aAAa,EAAE,OAAO,CAAC,MAAM;QAC7B,gBAAgB,EAAE,MAAM,CAAC,MAAM;QAC/B,gBAAgB,EAAE,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM;QACnD,iBAAiB,EAAE,SAAS,CAAC,MAAM;QACnC,YAAY,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC;YAC9B,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,GAAG;YAC5D,CAAC,CAAC,CAAC;QACL,QAAQ,EAAE,SAAS,CAAC,MAAM,KAAK,CAAC;KACjC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,64 @@
1
+ export declare const VALID_STATUSES: Set<"COVERED" | "PARTIAL" | "MISSING" | "DEFERRED" | "N/A">;
2
+ export type CoverageStatus = 'COVERED' | 'PARTIAL' | 'MISSING' | 'DEFERRED' | 'N/A';
3
+ export declare const VALID_REVERSE_STATUSES: Set<"TRACED" | "PARTIAL_SOURCE" | "UNTRACED_IN_SOURCE">;
4
+ export type ReverseStatus = 'TRACED' | 'PARTIAL_SOURCE' | 'UNTRACED_IN_SOURCE';
5
+ export declare const MAX_TRACES_PER_BATCH = 20;
6
+ export interface TargetSection {
7
+ id: string;
8
+ title: string;
9
+ file: string;
10
+ line: number;
11
+ text: string;
12
+ }
13
+ export interface SpecRef {
14
+ file: string;
15
+ section: string;
16
+ line: number;
17
+ }
18
+ export interface Match {
19
+ trace_id: string;
20
+ status: string;
21
+ spec_ref: string;
22
+ notes: string;
23
+ refs?: unknown[];
24
+ }
25
+ export interface ReverseMatch {
26
+ claim_id: string;
27
+ status: string;
28
+ source_trace_id: string | undefined;
29
+ nearest_source_trace: string | undefined;
30
+ similarity_note: string;
31
+ notes: string;
32
+ }
33
+ export interface MatchValidationResult {
34
+ matches: Match[];
35
+ errors: string[];
36
+ }
37
+ export interface ReverseMatchValidationResult {
38
+ matches: ReverseMatch[];
39
+ errors: string[];
40
+ }
41
+ interface TraceInput {
42
+ id?: string;
43
+ sentence_id?: string;
44
+ text?: string;
45
+ type?: string;
46
+ implicit?: boolean;
47
+ status?: string;
48
+ source?: Record<string, unknown>;
49
+ refs?: unknown[];
50
+ nearest_source_trace?: string;
51
+ similarity_note?: string;
52
+ [key: string]: unknown;
53
+ }
54
+ export declare function parseTargetSections(targetText: string, targetFile?: string): TargetSection[];
55
+ export declare function formatPrompt(traces: TraceInput[], targetText: string, exclusions?: string, language?: string): string;
56
+ export declare function batchTraces<T>(traces: T[], batchSize?: number): T[][];
57
+ export declare function validateMatches(rawOutput: string, traces: TraceInput[], validStatuses?: Set<string>): MatchValidationResult;
58
+ export declare function applyMatches(traces: TraceInput[], matches: Match[]): TraceInput[];
59
+ export declare function formatReversePrompt(reverseTraces: TraceInput[], sourceTraces: TraceInput[], language?: string): string;
60
+ export declare function validateReverseMatches(rawOutput: string, reverseTraces: TraceInput[]): ReverseMatchValidationResult;
61
+ export declare function applyReverseMatches(reverseTraces: TraceInput[], matches: ReverseMatch[]): TraceInput[];
62
+ export declare function resolveRefs(traces: TraceInput[], targetFiles: string[]): TraceInput[];
63
+ export declare function parseJsonOutput(raw: string): unknown[] | null;
64
+ export {};