# Tell a moved function from a real edit with sem-jiff

**Agent Signal · November 16, 2026 · 20–30 minutes**

**Validation status:** Source-reviewed, not executed. Outcomes below are expected results, not measurements. Package/API review used commit `3befed160c69ff3fc8f2ee3d2321b74c0e78959b`, whose package version is `0.2.1`. npm availability could not be independently confirmed during preparation.

## What you will learn

A normal patch marks lines removed and added even when a function merely moves. sem-jiff uses tree-sitter to add structural labels. Compare an unchanged function reorder with a genuine change from `return 1` to `return 9`.

This is a small diagnostic exercise, not proof of behavioral understanding or a benchmark of coding-agent quality.

## Prerequisites and cost

- Node.js **24 or newer**, npm and a terminal supporting these shell commands.
- A new disposable directory, not a work repository.
- Internet access to obtain the package and dependencies.
- No model, API key, GPU, account or subscription.
- No paid API calls. Optional Jev/Clef opinions are deliberately not configured.
- The library is MIT OR Apache-2.0; bundled components retain their own licenses.

The commands install third-party code locally. Review the package and dependencies before running it. Do not use proprietary code or real secrets.

## 1. Check prerequisites and pin availability

```sh
node --version
npm --version
npm view @plannotator/sem-jiff@0.2.1 version
```

**Expected:** Node reports v24 or newer; the last command prints `0.2.1`.

Stop if the exact package is unavailable. Do not silently replace it with `latest`. The source version is verified, but the registry page was inaccessible during preparation.

Create a directory with an unused name:

```sh
mkdir sem-jiff-lab-2026-11-16
cd sem-jiff-lab-2026-11-16
npm init -y
npm install --save-exact --ignore-scripts --no-audit --no-fund @plannotator/sem-jiff@0.2.1
npm ls @plannotator/sem-jiff
```

**Expected:** npm lists `@plannotator/sem-jiff@0.2.1`. Retain `package-lock.json` so repetitions can use the same resolved dependencies. The top-level package is pinned; the lockfile records dependency versions.

The package is documented to include built JavaScript and prebuilt WebAssembly grammars. This lab does not build from source, enable lifecycle scripts or run the repository's development setup.

## 2. Create the synthetic fixture

Save this as `lab.mjs`:

```js
import assert from 'node:assert/strict';
import { semanticDiffFile, languageForPath } from '@plannotator/sem-jiff';
import { reviewSummary } from '@plannotator/sem-jiff/summary';

const oldText = `export function a() {
  return 1;
}

export function b() {
  return 2;
}
`;

const movedText = `export function b() {
  return 2;
}

export function a() {
  return 1;
}
`;

const editedText = oldText.replace('return 1;', 'return 9;');
const path = 'fixture.ts';
const language = languageForPath(path);

for (const [name, nextText] of [
  ['move-only', movedText],
  ['real-edit', editedText],
]) {
  const result = await semanticDiffFile(
    language,
    oldText,
    nextText,
    path,
    { maxChars: 10000 },
  );
  const summary = reviewSummary(result.semanticOperations);
  const types = result.semanticOperations.map(operation => operation.type);

  console.log('\nCASE: ' + name);
  console.log(JSON.stringify({
    types,
    counts: summary.counts,
    read: summary.read.map(operation => operation.type),
    skim: summary.skim.map(operation => operation.type),
    diagnostics: result.diagnostics,
  }, null, 2));

  console.log('FULL PATCH:');
  console.log(result.patch);

  if (name === 'move-only') {
    assert.ok(types.includes('moved'),
      'Expected a move label; inspect the actual output.');
  } else {
    assert.ok(summary.read.length > 0,
      'A behavior edit must remain in the read group.');
  }
}

console.log('\nFixture assertions passed. Human review is still required.');
```

The move-only case follows the project's package smoke-test fixture. The second case adds a negative control: a reviewer must still see the behavior change.

## 3. Run locally

```sh
node lab.mjs
```

No `secondOpinion` option is supplied. Do not add API keys or configure a model to make an assertion pass.

**Expected, not observed:**

- `move-only` includes a `moved` operation.
- `real-edit` has at least one operation in the `read` group.
- Both cases print the ordinary patch.
- The script ends with `Fixture assertions passed. Human review is still required.`

Exact operation counts and patch layout are intentionally not promised.

## 4. Inspect before scoring

Read the full patch, not only the labels.

1. Confirm the first case changes only function order.
2. Confirm the second changes the return value from 1 to 9.
3. Inspect diagnostics for failed or skipped passes.
4. Check that the real edit was not treated exclusively as skimmable.
5. Record the package version, Node version and actual output.

A structural label is a review aid, not a correctness certificate. Collapse skimmable operations if useful, but never remove the underlying patch.

## Scorecard

Give one point for each:

- The unchanged reorder receives a `moved` label.
- The return-value change remains in `read`.
- You can inspect both full patches.
- You record diagnostics and unexpected output honestly.

**4/4:** The bounded smoke test behaves as expected.

**2–3/4:** Inspect discrepancies before using the library in a review interface.

**0–1/4:** Stop integration work and investigate version, packaging or parser errors.

This score says nothing about accuracy on real projects or other languages.

## Troubleshooting

- **Exact version missing:** Stop. Check the repository and registry later; do not substitute a newer version without reviewing changes.
- **Node engine warning:** Use Node 24+ and repeat the prerequisite check.
- **Import or grammar/WASM error:** Check `npm ls` and installation output. Do not enable unknown lifecycle scripts or fetch arbitrary replacement binaries.
- **No move label:** Keep the failure as a result. Check the patch and diagnostics rather than weakening the assertion.
- **Real edit only in skim:** Treat this as a review-safety failure. Do not hide the patch or deploy automatic collapsing based on this result.
- **Unexpected fallback:** Plain-diff fallback is not evidence that nothing changed.

## Scope limits

Version 0.2.1 holds back several Swift, Ruby and Kotlin labels after fresh testing. This TypeScript fixture does not validate those languages. Optional model opinions have different costs and data-sharing implications and are outside this exercise.

The sample TypeScript strings are parsed as data, not executed. The lab harness and library do execute locally. No real repository, browser, agent session or model service is connected.

## Sources

- [Pinned package metadata](https://github.com/plannotator/sem-jiff/blob/3befed160c69ff3fc8f2ee3d2321b74c0e78959b/package.json)
- [Pinned usage and guardrails](https://github.com/plannotator/sem-jiff/blob/3befed160c69ff3fc8f2ee3d2321b74c0e78959b/docs/usage.md)
- [Pinned package smoke test](https://github.com/plannotator/sem-jiff/blob/3befed160c69ff3fc8f2ee3d2321b74c0e78959b/scripts/smoke.mjs)
- [Read/skim implementation](https://github.com/plannotator/sem-jiff/blob/3befed160c69ff3fc8f2ee3d2321b74c0e78959b/src/summary.ts)
- [Changelog and language limitations](https://github.com/plannotator/sem-jiff/blob/3befed160c69ff3fc8f2ee3d2321b74c0e78959b/CHANGELOG.md)
