Skip to content

Latest commit

 

History

History
505 lines (430 loc) · 26.4 KB

compare.md

File metadata and controls

505 lines (430 loc) · 26.4 KB

Compare Saved Measurements

2026-10-20T12:56:37Z by Showboat 0.6.1

Run each Bash block from the LOCmetry repository root. Setup and replay instructions describe the fresh temporary copy created by source scripts/cli-demo-env.sh, external tools and output projections. The fixture README introduces the shared source tree.

Capture and explain a known change

Each example starts fresh. Here one added source line changes code from 29 to 30. compare reads saved full measurements; optional per-file records are unnecessary. The table excerpt omits the variable input-date footer.

source scripts/cli-demo-env.sh
locmetry --root acme-orders --no-user-config --output before.json
printf 'export const discount = 1;\n' >> acme-orders/web/src/orders/Order.ts
locmetry --root acme-orders --no-user-config --output after.json
locmetry compare before.json after.json --no-color --format table \
  | sed '/^Before measured at:/d; /^After measured at:/d' \
  | demo_wrap
Net change: acme-orders → acme-orders

 ──────────────────────────────────────────────────────────────────────────────────────
                        Lines         │         Code          │         Change
 Kind           before  after  change │ before  after  change │ Comments  Blanks  Files
 ─────────────────────────────────────┼───────────────────────┼────────────────────────
 Source             37     38      +1 │     29     30      +1 │        0       0      0
 Data                2      2       0 │      2      2       0 │        0       0      0
 Documentation       3      3       0 │      0      0       0 │        0       0      0
 ─────────────────────────────────────┼───────────────────────┼────────────────────────
 All counted        42     43      +1 │     31     32      +1 │        0       0      0

 ───────────────────────────────────────────────────────────
                       Lines         │         Code
 Purpose       before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 Production        24     25      +1 │     20     21      +1
 ────────────────────────────────────┼──────────────────────
 Source total      37     38      +1 │     29     30      +1

 Test/prod (Code): 0.35 → 0.33 (before → after)

 ────────────────────────────────────────────────────────────────────────
                                    Lines         │         Code
 Category                   before  after  change │ before  after  change
 ─────────────────────────────────────────────────┼──────────────────────
 production:implementation      19     20      +1 │     16     17      +1
 ─────────────────────────────────────────────────┼──────────────────────
 Source total                   37     38      +1 │     29     30      +1

 ───────────────────────────────────────────────────────────
                       Lines         │         Code
 Language      before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 TypeScript        13     14      +1 │     10     11      +1
 ────────────────────────────────────┼──────────────────────
 Source total      37     38      +1 │     29     30      +1

 Folded: TSX → TypeScript.

 ───────────────────────────────────────────────────────────
                       Lines         │         Code
 Folder        before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 web (both)        19     20      +1 │     16     17      +1
 ────────────────────────────────────┼──────────────────────
 Source total      37     38      +1 │     29     30      +1

 Folders are recursive. Do not sum parents and children.

▸ Measurement notes

- Net change = after − before, from the two saved reports.
- Unreadable files add nothing to the recorded counts: their lines are unknown, not zero.
- A folder seen in only one report may be newly visible, not newly created.
- Unrecognized files: same 2 paths in both reports. Not counted on either side.
- Folder totals containing these files cover counted files only. Per-folder detail is in the JSON field
'findings[].folder'.

No recorded differences in measurement settings. Reports do not fingerprint source, ignore files or executable builds.
This does not prove source-only growth.

Save the comparison

--output silently saves full JSON by default. --format markdown saves a readable document; --output - sends the selected format to stdout. Queries and excerpts select stable fields. A headline is a compact comparison projection.

source scripts/cli-demo-env.sh
locmetry --root acme-orders --no-user-config --output before.json
printf 'export const discount = 1;\n' >> acme-orders/web/src/orders/Order.ts
locmetry --root acme-orders --no-user-config --output after.json
locmetry compare before.json after.json --output change.json
jq '{document_type, schema_version, source: .summary.source}' change.json
locmetry compare before.json after.json --format markdown --output change.md
sed -n '/^## Purpose/,/^## /p' change.md | demo_wrap
locmetry compare before.json after.json --format headline --output - \
  | jq '{document_type, source: .summary.source}'
{
  "document_type": "comparison",
  "schema_version": "3",
  "source": {
    "before": {
      "files": 11,
      "code": 29,
      "comments": 6,
      "blanks": 2,
      "lines": 37
    },
    "after": {
      "files": 11,
      "code": 30,
      "comments": 6,
      "blanks": 2,
      "lines": 38
    },
    "delta": {
      "files": 0,
      "code": 1,
      "comments": 0,
      "blanks": 0,
      "lines": 1
    }
  }
}
## Purpose

| Purpose | Lines before | Lines after | Lines change | Code before | Code after | Code change |
| --- | ---: | ---: | ---: | ---: | ---: | ---: |
| Production | 24 | 25 | +1 | 20 | 21 | +1 |
| **Source total** | **37** | **38** | **+1** | **29** | **30** | **+1** |

*Test/prod (Code): 0.35 → 0.33 (before → after)*

## Categories
{
  "document_type": "comparison",
  "source": {
    "before": {
      "files": 11,
      "code": 29,
      "comments": 6,
      "blanks": 2,
      "lines": 37
    },
    "after": {
      "files": 11,
      "code": 30,
      "comments": 6,
      "blanks": 2,
      "lines": 38
    },
    "delta": {
      "files": 0,
      "code": 1,
      "comments": 0,
      "blanks": 0,
      "lines": 1
    }
  }
}

Print only the change tables

--tables-only keeps the change tables and drops the title, ratio line, notes, findings and input dates. Use it when the rows are what you need; the notes above explain how to read them.

source scripts/cli-demo-env.sh
locmetry --root acme-orders --no-user-config --output before.json
printf 'export const discount = 1;\n' >> acme-orders/web/src/orders/Order.ts
locmetry --root acme-orders --no-user-config --output after.json
locmetry compare before.json after.json --no-color --format table --tables-only
 ──────────────────────────────────────────────────────────────────────────────────────
                        Lines         │         Code          │         Change
 Kind           before  after  change │ before  after  change │ Comments  Blanks  Files
 ─────────────────────────────────────┼───────────────────────┼────────────────────────
 Source             37     38      +1 │     29     30      +1 │        0       0      0
 Data                2      2       0 │      2      2       0 │        0       0      0
 Documentation       3      3       0 │      0      0       0 │        0       0      0
 ─────────────────────────────────────┼───────────────────────┼────────────────────────
 All counted        42     43      +1 │     31     32      +1 │        0       0      0

 ───────────────────────────────────────────────────────────
                       Lines         │         Code
 Purpose       before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 Production        24     25      +1 │     20     21      +1
 ────────────────────────────────────┼──────────────────────
 Source total      37     38      +1 │     29     30      +1

 ────────────────────────────────────────────────────────────────────────
                                    Lines         │         Code
 Category                   before  after  change │ before  after  change
 ─────────────────────────────────────────────────┼──────────────────────
 production:implementation      19     20      +1 │     16     17      +1
 ─────────────────────────────────────────────────┼──────────────────────
 Source total                   37     38      +1 │     29     30      +1

 ───────────────────────────────────────────────────────────
                       Lines         │         Code
 Language      before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 TypeScript        13     14      +1 │     10     11      +1
 ────────────────────────────────────┼──────────────────────
 Source total      37     38      +1 │     29     30      +1

 ───────────────────────────────────────────────────────────
                       Lines         │         Code
 Folder        before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 web (both)        19     20      +1 │     16     17      +1
 ────────────────────────────────────┼──────────────────────
 Source total      37     38      +1 │     29     30      +1

Keep language variants apart

The Languages grid counts a variant within its family's row, so a TSX change appears under TypeScript with a Folded: line. --split-languages shows TSX as its own row, as full JSON does. sed keeps only the Languages grid.

source scripts/cli-demo-env.sh
locmetry --root acme-orders --no-user-config --output before.json
printf 'export const Badge = () => null;\n' >> acme-orders/web/src/orders/OrderView.tsx
locmetry --root acme-orders --no-user-config --output after.json
locmetry compare before.json after.json --no-color --format table \
  | sed -n '/^ Language /,/^ Folded/p'
locmetry compare before.json after.json --no-color --format table --split-languages --tables-only \
  | sed -n '/^ Language /,/^ Source total/p'
 Language      before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 TypeScript        13     14      +1 │     10     11      +1
 ────────────────────────────────────┼──────────────────────
 Source total      37     38      +1 │     29     30      +1

 Folded: TSX → TypeScript.
 Language      before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 TSX                3      4      +1 │      3      4      +1
 ────────────────────────────────────┼──────────────────────
 Source total      37     38      +1 │     29     30      +1

Focus on a workspace member

--member web selects the exact member name from either input. Counts and detail cover that member; input provenance and partial status still cover the workspace reports. Names identify recorded members, not Git revisions.

source scripts/cli-demo-env.sh
locmetry workspace --workspace-file workspace.toml --no-user-config --output before.json
printf 'export const discount = 1;\n' >> acme-orders/web/src/orders/Order.ts
locmetry workspace --workspace-file workspace.toml --no-user-config --output after.json
locmetry compare before.json after.json --member web --no-color --format table \
  | sed '/^Before measured at:/d; /^After measured at:/d' \
  | demo_wrap
Net change: service + web → service + web
Member: web (both). Counts and detail cover this member only.
Input metadata, measurement notes, report-level findings and partial status cover the whole workspace inputs.

 ──────────────────────────────────────────────────────────────────────────────────────
                        Lines         │         Code          │         Change
 Kind           before  after  change │ before  after  change │ Comments  Blanks  Files
 ─────────────────────────────────────┼───────────────────────┼────────────────────────
 Source             19     20      +1 │     16     17      +1 │        0       0      0
 Data                2      2       0 │      2      2       0 │        0       0      0
 Documentation       3      3       0 │      0      0       0 │        0       0      0
 ─────────────────────────────────────┼───────────────────────┼────────────────────────
 All counted        24     25      +1 │     18     19      +1 │        0       0      0

 ───────────────────────────────────────────────────────────
                       Lines         │         Code
 Purpose       before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 Production        13     14      +1 │     12     13      +1
 ────────────────────────────────────┼──────────────────────
 Source total      19     20      +1 │     16     17      +1

 Test/prod (Code): 0.25 → 0.23 (before → after)

 ────────────────────────────────────────────────────────────────────────
                                    Lines         │         Code
 Category                   before  after  change │ before  after  change
 ─────────────────────────────────────────────────┼──────────────────────
 production:implementation      13     14      +1 │     12     13      +1
 ─────────────────────────────────────────────────┼──────────────────────
 Source total                   19     20      +1 │     16     17      +1

 ───────────────────────────────────────────────────────────
                       Lines         │         Code
 Language      before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 TypeScript        13     14      +1 │     10     11      +1
 ────────────────────────────────────┼──────────────────────
 Source total      19     20      +1 │     16     17      +1

 Folded: TSX → TypeScript.

Member source lines: matched +1, entering 0, leaving 0. Total +1.
Member all-counted lines: matched +1, entering 0, leaving 0. Total +1.

Member source code: matched +1, entering 0, leaving 0. Total +1.
Member all-counted code: matched +1, entering 0, leaving 0. Total +1.

 ───────────────────────────────────────────────────────────
                       Lines         │         Code
 Folder        before  after  change │ before  after  change
 ────────────────────────────────────┼──────────────────────
 src (both)        19     20      +1 │     16     17      +1
 ────────────────────────────────────┼──────────────────────
 Source total      19     20      +1 │     16     17      +1

 Folders are recursive. Do not sum parents and children.

▸ Measurement notes

- Net change = after − before, from the two saved reports.
- Unreadable files add nothing to the recorded counts: their lines are unknown, not zero.
- A folder seen in only one report may be newly visible, not newly created.
- Unrecognized files: same 2 paths in both reports. Not counted on either side.
- Folder totals containing these files cover counted files only. Per-folder detail is in the JSON field
'findings[].folder'.

No recorded differences in measurement settings. Reports do not fingerprint source, ignore files or executable builds.
This does not prove source-only growth.

Distinguish membership from deletion

The second capture deliberately selects only the service. Web leaves the measured workspace; its files still exist. Full comparison JSON retains the member presence and count evidence.

source scripts/cli-demo-env.sh
locmetry workspace --workspace-file workspace.toml --no-user-config --output before.json
locmetry workspace --root acme-orders/service --no-user-config --output after.json
locmetry compare before.json after.json --format json \
  | jq '{
      source: .summary.source,
      members: (.members | with_entries(.value = {
        presence: .value.presence,
        source: .value.source
      }))
    }'
test -f acme-orders/web/src/orders/Order.ts
printf 'Web source still exists.\n'
{
  "source": {
    "before": {
      "files": 11,
      "code": 29,
      "comments": 6,
      "blanks": 2,
      "lines": 37
    },
    "after": {
      "files": 5,
      "code": 13,
      "comments": 3,
      "blanks": 2,
      "lines": 18
    },
    "delta": {
      "files": -6,
      "code": -16,
      "comments": -3,
      "blanks": 0,
      "lines": -19
    }
  },
  "members": {
    "service": {
      "presence": "both",
      "source": {
        "before": {
          "files": 5,
          "code": 13,
          "comments": 3,
          "blanks": 2,
          "lines": 18
        },
        "after": {
          "files": 5,
          "code": 13,
          "comments": 3,
          "blanks": 2,
          "lines": 18
        },
        "delta": {
          "files": 0,
          "code": 0,
          "comments": 0,
          "blanks": 0,
          "lines": 0
        }
      }
    },
    "web": {
      "presence": "before_only",
      "source": {
        "before": {
          "files": 6,
          "code": 16,
          "comments": 3,
          "blanks": 0,
          "lines": 19
        },
        "after": {
          "files": 0,
          "code": 0,
          "comments": 0,
          "blanks": 0,
          "lines": 0
        },
        "delta": {
          "files": -6,
          "code": -16,
          "comments": -3,
          "blanks": 0,
          "lines": -19
        }
      }
    }
  }
}
Web source still exists.

Respect the input contract

The help excerpt includes input arguments, member selection and output options, stopping before presentation options.

A headline cannot replace a full baseline. This example checks exit 1 and prints the actual diagnostic. Capture earlier states before editing; a new measurement cannot recover the past. Exit 2 instead indicates partial measured input. The comparison guide owns the full interpretation rules.

source scripts/cli-demo-env.sh
locmetry --root acme-orders --no-user-config --format headline --output headline.json
locmetry --root acme-orders --no-user-config --output full.json
status=0
locmetry compare headline.json full.json --no-color --format json 2> diagnostic.txt || \
  status=$?
test "$status" -eq 1
cat diagnostic.txt | demo_wrap
locmetry compare --no-color --help | sed '/^Presentation:/,$d'
error: Cannot compare before report 'headline.json': A full measurement report is required. Missing: review, breakdown,
metadata.kinds, metadata.modules, metadata.coverage.unrecognized, metadata.config. Capture a full measurement with
'--output FILE' or '--format json'. A headline cannot reconstruct the missing baseline, and rerunning measures the
current tree.
Compare two saved full reports: net change is after minus before.

Defaults to a table on a terminal, a JSON headline in pipes. An option of one format selects it.
--output FILE saves only to that file, defaulting to full JSON; --format overrides the format.

Usage: locmetry compare [OPTIONS] <BEFORE> <AFTER>

Arguments:
  <BEFORE>
          Full JSON measurement before the change

  <AFTER>
          Full JSON measurement after the change

Options:
  -h, --help
          Print help (see a summary with '-h')

Selection and policy:
      --member <NAME>
          Focus on one exact workspace member name; accepts presence on either side

Output and content:
      --format <FORMAT>
          Result format [default: json with --output; otherwise table on a terminal, headline in
          pipes]

          Possible values:
          - table:    Tables and evidence
          - json:     Complete JSON; measurement reports can be compared later
          - headline: Compact JSON for agents and scripts; not a comparison-ready measurement
          - markdown: Markdown tables and evidence for reviews

      --output <FILE>
          Write only to FILE; - selects stdout. Defaults to full JSON; --format overrides it