@eliya-oss/agent-diff 0.1.0-alpha.4 → 0.1.0-alpha.6

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.
@@ -16,7 +16,7 @@ PRDs are not the place for every implementation detail. Use the split below:
16
16
  - Read `CONTEXT.md` next. The glossary defines the vocabulary every PRD reuses. adiff has a short
17
17
  language on purpose; a synonym invented in a PRD is a defect.
18
18
  - Read the PRD that owns the behavior. Follow its links to ADRs for durable choices and issues for
19
- implementation steps.
19
+ implementation layers.
20
20
 
21
21
  ## How to write a new PRD
22
22
 
@@ -64,7 +64,7 @@ Before treating a PRD as ready:
64
64
 
65
65
  - [ ] Problem stated from the reviewer's or the agent's perspective, not the code's.
66
66
  - [ ] Solution stated as observable behavior, before any implementation choice is named.
67
- - [ ] User stories cover the happy path, the empty result, the refusal, and the stale case.
67
+ - [ ] User layers cover the happy path, the empty result, the refusal, and the stale case.
68
68
  - [ ] Implementation Decisions are concrete enough that two engineers would build interchangeable
69
69
  implementations.
70
70
  - [ ] File paths, helper names, and rollout order live in GitHub issues.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @eliya-oss/agent-diff
2
2
 
3
+ ## 0.1.0-alpha.6
4
+
5
+ ### Patch Changes
6
+
7
+ - The diff holds still when a trackpad gesture drifts sideways.
8
+
9
+ - The reading order an agent writes is called layers. adiff layers set and adiff layers show replace the story verbs, and the JSON carries layers where it carried steps.
10
+
11
+ - A layer lists the files it covers, and the footer says how to switch between layers and files.
12
+
13
+ ## 0.1.0-alpha.5
14
+
15
+ ### Patch Changes
16
+
17
+ - Wheel bursts move the diff once a frame, the worktree list shows which branches carry a reading order, and a story the branch has moved past says so.
18
+
19
+ - Scrolling with a trackpad settles as soon as your fingers stop.
20
+
3
21
  ## 0.1.0-alpha.4
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -20,7 +20,7 @@ adiff comment add --repo . --branch add-teammate-invitations --file src/api
20
20
  adiff comment stage --repo . --branch add-teammate-invitations --file src/api/invitations.ts --start 4 --end 5 --body "why"
21
21
  adiff review submit --repo . --branch add-teammate-invitations
22
22
  adiff file vouch --repo . --branch add-teammate-invitations --file src/api/invitations.ts
23
- adiff story show --worktree . --fields covered,total,uncovered
23
+ adiff layers show --worktree . --fields covered,total,uncovered
24
24
  adiff describe
25
25
  ```
26
26
 
@@ -50,14 +50,14 @@ adiff comment take --worktree . --wait 300 # block until something arrives
50
50
  Each comment carries the exact snippet it was written against, the side of the diff, and the commit
51
51
  the diff was read at, so the agent needs no other reference. A comment is handed over once.
52
52
 
53
- An agent can also record the reading order for its own work as a story: ordered steps over spans of
54
- files, set with `adiff story set --worktree . --json -`. Where a branch has one, the terminal lists
55
- its steps and scopes the diff to the step you are on. adiff computes the coverage itself, so a story
53
+ An agent can also record the reading order for its own work as a layers: ordered layers over spans of
54
+ files, set with `adiff layers set --worktree . --json -`. Where a branch has one, the terminal lists
55
+ its layers and scopes the diff to the layer you are on. adiff computes the coverage itself, so a layers
56
56
  cannot hide code:
57
57
 
58
58
  ```bash
59
- adiff story show --worktree . --fields covered,total,uncovered
60
- {"ok":true,"story":{"covered":1,"total":3,"uncovered":[{"path":"docs/incidents.md","start":1,"end":6},{"path":"src/api/errors.ts","start":1,"end":11}]}}
59
+ adiff layers show --worktree . --fields covered,total,uncovered
60
+ {"ok":true,"layers":{"covered":1,"total":3,"uncovered":[{"path":"docs/incidents.md","start":1,"end":6},{"path":"src/api/errors.ts","start":1,"end":11}]}}
61
61
  ```
62
62
 
63
63
  ## Skill
@@ -66,7 +66,7 @@ adiff story show --worktree . --fields covered,total,uncovered
66
66
  npx skills add Newbie012/agent-diff --skill adiff
67
67
  ```
68
68
 
69
- Teaches an agent the whole loop: collect comments, act on them, write the story.
69
+ Teaches an agent the whole loop: collect comments, act on them, write the layers.
70
70
 
71
71
  ## Requirements
72
72
 
package/dist/main.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { appendFile, mkdir, readFile, realpath, writeFile } from "node:fs/promises";
3
3
  import { text } from "node:stream/consumers";
4
- import { join } from "node:path";
4
+ import { dirname, join } from "node:path";
5
5
  import { execFile } from "node:child_process";
6
6
  import { promisify } from "node:util";
7
7
  import { homedir, hostname, platform } from "node:os";
8
+ import { existsSync, readFileSync } from "node:fs";
9
+ import { fileURLToPath } from "node:url";
8
10
  import { ASCIIFontRenderable, BoxRenderable, CodeRenderable, LineNumberRenderable, RGBA, SelectRenderable, StyledText, SyntaxStyle, TextRenderable, bg, createCliRenderer, fg, getTreeSitterClient, pathToFiletype, t } from "@opentui/core";
9
11
  //#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/Pipeable.js
10
12
  /**
@@ -10803,7 +10805,7 @@ const defaultRoot = () => join(homedir(), ".adiff");
10803
10805
  const branchDir = (root, worktreePath) => join(root, "branches", slugOf(worktreePath));
10804
10806
  const inboxPath = (root, worktreePath) => join(branchDir(root, worktreePath), "inbox.jsonl");
10805
10807
  const statePath = (root, worktreePath) => join(branchDir(root, worktreePath), "state.json");
10806
- const storyPath = (root, worktreePath) => join(branchDir(root, worktreePath), "story.json");
10808
+ const layersPath = (root, worktreePath) => join(branchDir(root, worktreePath), "layers.json");
10807
10809
  const reportsDir = (root) => join(root, "reports");
10808
10810
  const reportPath = (root, stamp) => join(reportsDir(root), `${stamp}.md`);
10809
10811
  //#endregion
@@ -10856,14 +10858,14 @@ const cursorOps = (state, saveState, inbox) => {
10856
10858
  })
10857
10859
  };
10858
10860
  };
10859
- const storyOps = (root) => {
10861
+ const layersOps = (root) => {
10860
10862
  return {
10861
- story: fn("Store.story")(function* (worktreePath) {
10862
- const raw = yield* readOptional(storyPath(root, worktreePath));
10863
+ layers: fn("Store.layers")(function* (worktreePath) {
10864
+ const raw = yield* readOptional(layersPath(root, worktreePath));
10863
10865
  return map$4(raw, (text) => JSON.parse(text));
10864
10866
  }),
10865
- saveStory: fn("Store.saveStory")(function* (worktreePath, next) {
10866
- const path = storyPath(root, worktreePath);
10867
+ saveLayers: fn("Store.saveLayers")(function* (worktreePath, next) {
10868
+ const path = layersPath(root, worktreePath);
10867
10869
  yield* ensureDir(branchDir(root, worktreePath));
10868
10870
  yield* tryPromise({
10869
10871
  try: () => writeFile(path, JSON.stringify(next, void 0, 2), "utf8"),
@@ -10932,7 +10934,7 @@ const makeStore = (root) => {
10932
10934
  state,
10933
10935
  saveState,
10934
10936
  saveReport,
10935
- ...storyOps(root),
10937
+ ...layersOps(root),
10936
10938
  ...cursors
10937
10939
  };
10938
10940
  };
@@ -10947,8 +10949,8 @@ var UnknownCommand = class extends TaggedError("UnknownCommand") {};
10947
10949
  var MissingOption = class extends TaggedError("MissingOption") {};
10948
10950
  var EmptyReview = class extends TaggedError("EmptyReview") {};
10949
10951
  var UnknownWorktree = class extends TaggedError("UnknownWorktree") {};
10950
- var MalformedStory = class extends TaggedError("MalformedStory") {};
10951
- var NoStory = class extends TaggedError("NoStory") {};
10952
+ var MalformedLayers = class extends TaggedError("MalformedLayers") {};
10953
+ var NoLayers = class extends TaggedError("NoLayers") {};
10952
10954
  //#endregion
10953
10955
  //#region src/cli/commands.ts
10954
10956
  const CONTEXT = 3;
@@ -10976,9 +10978,18 @@ const waitingOn = fn("Cli.waitingOn")(function* (worktree) {
10976
10978
  const store = yield* Store;
10977
10979
  const state = yield* store.state(worktree.path);
10978
10980
  const batches = yield* store.inbox(worktree.path);
10981
+ const told = yield* store.layers(worktree.path);
10979
10982
  return {
10980
10983
  staged: state.pending.length,
10981
- unread: Math.max(0, batches.length - state.consumed)
10984
+ unread: Math.max(0, batches.length - state.consumed),
10985
+ layers: match$2(told, {
10986
+ onNone: () => 0,
10987
+ onSome: (layers) => layers.layers.length
10988
+ }),
10989
+ stale: match$2(told, {
10990
+ onNone: () => false,
10991
+ onSome: (layers) => layers.head !== worktree.head
10992
+ })
10982
10993
  };
10983
10994
  });
10984
10995
  const listBranches = fn("Cli.listBranches")(function* (repo) {
@@ -10996,7 +11007,9 @@ const listBranches = fn("Cli.listBranches")(function* (repo) {
10996
11007
  added: stat.added,
10997
11008
  removed: stat.removed,
10998
11009
  staged: waiting.staged,
10999
- unread: waiting.unread
11010
+ unread: waiting.unread,
11011
+ layers: waiting.layers,
11012
+ stale: waiting.stale
11000
11013
  });
11001
11014
  }
11002
11015
  return summaries.filter((summary) => summary.files > 0);
@@ -11191,19 +11204,19 @@ const fileSource = fn("Cli.fileSource")(function* (repo, branch, file) {
11191
11204
  return getOrElse(found, () => []);
11192
11205
  });
11193
11206
  //#endregion
11194
- //#region src/domain/narrative/model.ts
11195
- const REMAINDER_TITLE = "not in any step";
11207
+ //#region src/domain/layers/model.ts
11208
+ const REMAINDER_TITLE = "not in any layer";
11196
11209
  //#endregion
11197
- //#region src/domain/narrative/coverage.ts
11210
+ //#region src/domain/layers/coverage.ts
11198
11211
  const codeBlockOf$1 = (span) => ({
11199
11212
  kind: "code",
11200
11213
  path: span.path,
11201
11214
  start: span.start,
11202
11215
  end: span.end
11203
11216
  });
11204
- const codeBlocks = (step) => step.blocks.filter((block) => block.kind === "code");
11205
- const noteOf = (step) => step.blocks.filter((block) => block.kind === "prose").map((block) => block.markdown.trim()).filter((markdown) => markdown.length > 0).join(" ");
11206
- const spansOf$1 = (steps) => steps.flatMap((step) => codeBlocks(step).map(({ path, start, end }) => ({
11217
+ const codeBlocks = (layer) => layer.blocks.filter((block) => block.kind === "code");
11218
+ const noteOf = (layer) => layer.blocks.filter((block) => block.kind === "prose").map((block) => block.markdown.trim()).filter((markdown) => markdown.length > 0).join(" ");
11219
+ const spansOf$1 = (layers) => layers.flatMap((layer) => codeBlocks(layer).map(({ path, start, end }) => ({
11207
11220
  path,
11208
11221
  start,
11209
11222
  end
@@ -11220,8 +11233,8 @@ const spanOfHunk = (patch, hunk) => {
11220
11233
  });
11221
11234
  };
11222
11235
  const overlaps = (a, b) => a.path === b.path && a.start <= b.end && a.end >= b.start;
11223
- const coverage = (patches, steps) => {
11224
- const claimed = spansOf$1(steps);
11236
+ const coverage = (patches, layers) => {
11237
+ const claimed = spansOf$1(layers);
11225
11238
  const hunks = patches.flatMap((patch) => patch.hunks.flatMap((hunk) => match$2(spanOfHunk(patch, hunk), {
11226
11239
  onNone: () => [],
11227
11240
  onSome: (s) => [s]
@@ -11233,9 +11246,9 @@ const coverage = (patches, steps) => {
11233
11246
  missing
11234
11247
  };
11235
11248
  };
11236
- const withFullCoverage = (patches, story) => {
11237
- const gap = coverage(patches, story.steps);
11238
- if (gap.missing.length === 0) return story;
11249
+ const withFullCoverage = (patches, layers) => {
11250
+ const gap = coverage(patches, layers.layers);
11251
+ if (gap.missing.length === 0) return layers;
11239
11252
  const remainder = {
11240
11253
  title: REMAINDER_TITLE,
11241
11254
  blocks: [{
@@ -11244,21 +11257,21 @@ const withFullCoverage = (patches, story) => {
11244
11257
  }, ...gap.missing.map((span) => codeBlockOf$1(span))]
11245
11258
  };
11246
11259
  return {
11247
- ...story,
11248
- steps: [...story.steps, remainder]
11260
+ ...layers,
11261
+ layers: [...layers.layers, remainder]
11249
11262
  };
11250
11263
  };
11251
11264
  //#endregion
11252
- //#region src/domain/narrative/version.ts
11253
- const statusOf = (patches, story, branchHead) => {
11254
- const gap = coverage(patches, story.steps);
11265
+ //#region src/domain/layers/version.ts
11266
+ const statusOf = (patches, layers, branchHead) => {
11267
+ const gap = coverage(patches, layers.layers);
11255
11268
  const present = new Set(patches.map((patch) => patch.path));
11256
- const mentioned = new Set(spansOf$1(story.steps).map((span) => span.path));
11269
+ const mentioned = new Set(spansOf$1(layers.layers).map((span) => span.path));
11257
11270
  return {
11258
- version: story.version,
11259
- parent: story.parent,
11260
- stale: story.head !== branchHead,
11261
- storyHead: story.head,
11271
+ version: layers.version,
11272
+ parent: layers.parent,
11273
+ stale: layers.head !== branchHead,
11274
+ layersHead: layers.head,
11262
11275
  branchHead,
11263
11276
  uncovered: gap.missing,
11264
11277
  vanished: [...mentioned].filter((path) => !present.has(path)),
@@ -11267,9 +11280,9 @@ const statusOf = (patches, story, branchHead) => {
11267
11280
  };
11268
11281
  };
11269
11282
  //#endregion
11270
- //#region src/cli/story.ts
11283
+ //#region src/cli/layers.ts
11271
11284
  const unique = (paths) => [...new Set(paths)];
11272
- const spansOfStep = (step) => codeBlocks(step).map(({ path, start, end }) => ({
11285
+ const spansOfLayer = (layer) => codeBlocks(layer).map(({ path, start, end }) => ({
11273
11286
  path,
11274
11287
  start,
11275
11288
  end
@@ -11289,20 +11302,20 @@ const codeBlockOf = (span) => ({
11289
11302
  start: span.start,
11290
11303
  end: span.end
11291
11304
  });
11292
- const blocksOf = (step) => {
11293
- if (Array.isArray(step.blocks)) return step.blocks.filter(isBlock);
11294
- const note = typeof step.note === "string" ? [{
11305
+ const blocksOf = (layer) => {
11306
+ if (Array.isArray(layer.blocks)) return layer.blocks.filter(isBlock);
11307
+ const note = typeof layer.note === "string" ? [{
11295
11308
  kind: "prose",
11296
- markdown: step.note
11309
+ markdown: layer.note
11297
11310
  }] : [];
11298
- const spans = Array.isArray(step.spans) ? step.spans.filter(isSpan) : [];
11311
+ const spans = Array.isArray(layer.spans) ? layer.spans.filter(isSpan) : [];
11299
11312
  return [...note, ...spans.map(codeBlockOf)];
11300
11313
  };
11301
- const stepOf = (value) => {
11302
- const step = value;
11303
- const title = typeof step?.title === "string" ? step.title.trim() : "";
11304
- if (step === void 0 || title.length === 0) return none();
11305
- const blocks = blocksOf(step);
11314
+ const layerOf = (value) => {
11315
+ const layer = value;
11316
+ const title = typeof layer?.title === "string" ? layer.title.trim() : "";
11317
+ if (layer === void 0 || title.length === 0) return none();
11318
+ const blocks = blocksOf(layer);
11306
11319
  return blocks.length === 0 ? none() : some({
11307
11320
  title,
11308
11321
  blocks
@@ -11316,55 +11329,55 @@ const parsed = (text) => {
11316
11329
  return none();
11317
11330
  }
11318
11331
  };
11319
- const readStory = fn("Cli.readStory")(function* (text) {
11332
+ const readLayers = fn("Cli.readLayers")(function* (text) {
11320
11333
  const document = yield* match$2(parsed(text), {
11321
- onNone: () => new MalformedStory({ reason: "the story is not a JSON object" }),
11334
+ onNone: () => new MalformedLayers({ reason: "the layers is not a JSON object" }),
11322
11335
  onSome: succeed
11323
11336
  });
11324
- const raw = document["steps"];
11325
- const steps = (Array.isArray(raw) ? raw : []).flatMap((entry) => match$2(stepOf(entry), {
11337
+ const raw = document["layers"];
11338
+ const layers = (Array.isArray(raw) ? raw : []).flatMap((entry) => match$2(layerOf(entry), {
11326
11339
  onNone: () => [],
11327
- onSome: (step) => [step]
11340
+ onSome: (layer) => [layer]
11328
11341
  }));
11329
- if (steps.length === 0) return yield* new MalformedStory({ reason: "every step needs a title and at least one span or block" });
11342
+ if (layers.length === 0) return yield* new MalformedLayers({ reason: "every layer needs a title and at least one span or block" });
11330
11343
  const summary = document["summary"];
11331
11344
  return {
11332
11345
  summary: typeof summary === "string" ? summary : "",
11333
- steps
11346
+ layers
11334
11347
  };
11335
11348
  });
11336
11349
  const fromStored = (stored) => ({
11337
11350
  ...stored,
11338
11351
  parent: fromNullishOr(stored.parent)
11339
11352
  });
11340
- const toStored = (story) => ({
11341
- ...story,
11342
- parent: getOrUndefined$1(story.parent)
11353
+ const toStored = (layers) => ({
11354
+ ...layers,
11355
+ parent: getOrUndefined$1(layers.parent)
11343
11356
  });
11344
- const stepsOf = (patches, story) => {
11357
+ const reportedLayers = (patches, layers) => {
11345
11358
  const present = new Set(patches.map((patch) => patch.path));
11346
- return withFullCoverage(patches, story).steps.map((step) => ({
11347
- title: step.title,
11348
- note: noteOf(step),
11349
- files: unique(spansOfStep(step).map((span) => span.path)).filter((path) => present.has(path)),
11350
- spans: spansOfStep(step)
11359
+ return withFullCoverage(patches, layers).layers.map((layer) => ({
11360
+ title: layer.title,
11361
+ note: noteOf(layer),
11362
+ files: unique(spansOfLayer(layer).map((span) => span.path)).filter((path) => present.has(path)),
11363
+ spans: spansOfLayer(layer)
11351
11364
  }));
11352
11365
  };
11353
- const reportOf = (patches, story, branchHead) => {
11354
- const status = statusOf(patches, story, branchHead);
11366
+ const reportOf = (patches, layers, branchHead) => {
11367
+ const status = statusOf(patches, layers, branchHead);
11355
11368
  return {
11356
11369
  version: status.version,
11357
11370
  parent: getOrUndefined$1(status.parent),
11358
- head: status.storyHead,
11371
+ head: status.layersHead,
11359
11372
  branchHead: status.branchHead,
11360
11373
  stale: status.stale,
11361
- written: story.written,
11362
- summary: story.summary,
11374
+ written: layers.written,
11375
+ summary: layers.summary,
11363
11376
  covered: status.covered,
11364
11377
  total: status.total,
11365
11378
  uncovered: status.uncovered,
11366
11379
  vanished: status.vanished,
11367
- steps: stepsOf(patches, story)
11380
+ layers: reportedLayers(patches, layers)
11368
11381
  };
11369
11382
  };
11370
11383
  const resolve = (path) => realpath(path).catch(() => path);
@@ -11380,17 +11393,17 @@ const worktreeAt = fn("Cli.worktreeAt")(function* (worktreePath) {
11380
11393
  known: worktrees.map((entry) => entry.path)
11381
11394
  }) : succeed(found);
11382
11395
  });
11383
- const storyOf = fn("Cli.storyOf")(function* (worktree) {
11396
+ const storedLayers = fn("Cli.storedLayers")(function* (worktree) {
11384
11397
  const store = yield* Store;
11385
- return map$4(yield* store.story(worktree.path), fromStored);
11398
+ return map$4(yield* store.layers(worktree.path), fromStored);
11386
11399
  });
11387
- const setStory = fn("Cli.setStory")(function* (worktreePath, text, written) {
11400
+ const setLayers = fn("Cli.setLayers")(function* (worktreePath, text, written) {
11388
11401
  const store = yield* Store;
11389
11402
  const worktree = yield* worktreeAt(worktreePath);
11390
- const input = yield* readStory(text);
11403
+ const input = yield* readLayers(text);
11391
11404
  const patches = yield* patchesOf(worktree);
11392
- const previous = yield* storyOf(worktree);
11393
- const story = {
11405
+ const previous = yield* storedLayers(worktree);
11406
+ const layers = {
11394
11407
  version: match$2(previous, {
11395
11408
  onNone: () => 1,
11396
11409
  onSome: (old) => old.version + 1
@@ -11400,26 +11413,33 @@ const setStory = fn("Cli.setStory")(function* (worktreePath, text, written) {
11400
11413
  base: worktree.base,
11401
11414
  written,
11402
11415
  summary: input.summary,
11403
- steps: input.steps
11416
+ layers: input.layers
11404
11417
  };
11405
- yield* store.saveStory(worktree.path, toStored(story));
11406
- return reportOf(patches, story, worktree.head);
11418
+ yield* store.saveLayers(worktree.path, toStored(layers));
11419
+ return reportOf(patches, layers, worktree.head);
11407
11420
  });
11408
- const showStory = fn("Cli.showStory")(function* (worktreePath) {
11421
+ const showLayers = fn("Cli.showLayers")(function* (worktreePath) {
11409
11422
  const worktree = yield* worktreeAt(worktreePath);
11410
11423
  const patches = yield* patchesOf(worktree);
11411
- const found = yield* storyOf(worktree);
11412
- const story = yield* match$2(found, {
11413
- onNone: () => new NoStory({ worktree: worktree.path }),
11424
+ const found = yield* storedLayers(worktree);
11425
+ const layers = yield* match$2(found, {
11426
+ onNone: () => new NoLayers({ worktree: worktree.path }),
11414
11427
  onSome: succeed
11415
11428
  });
11416
- return reportOf(patches, story, worktree.head);
11429
+ return reportOf(patches, layers, worktree.head);
11417
11430
  });
11418
- const listStorySteps = fn("Cli.listStorySteps")(function* (repo, branch) {
11431
+ const listLayers = fn("Cli.listLayers")(function* (repo, branch) {
11419
11432
  const worktree = yield* findBranch(repo, branch);
11420
- const found = yield* storyOf(worktree);
11421
- if (isNone(found)) return [];
11422
- return stepsOf(yield* patchesOf(worktree), found.value);
11433
+ const found = yield* storedLayers(worktree);
11434
+ if (isNone(found)) return {
11435
+ layers: [],
11436
+ stale: false
11437
+ };
11438
+ const patches = yield* patchesOf(worktree);
11439
+ return {
11440
+ layers: reportedLayers(patches, found.value),
11441
+ stale: found.value.head !== worktree.head
11442
+ };
11423
11443
  });
11424
11444
  //#endregion
11425
11445
  //#region src/cli/parse.ts
@@ -11593,26 +11613,26 @@ const catalog = [
11593
11613
  example: "adiff review progress --repo . --branch cdr-1"
11594
11614
  },
11595
11615
  {
11596
- name: "story set",
11597
- about: "Write the reading order for this worktree's diff: ordered steps over spans of files",
11616
+ name: "layers set",
11617
+ about: "Write the reading order for this worktree's diff: ordered layers over spans of files",
11598
11618
  safety: "write",
11599
11619
  options: [{
11600
11620
  name: "worktree",
11601
11621
  required: true,
11602
11622
  value: "path",
11603
- about: "The worktree the story is about"
11623
+ about: "The worktree the layers is about"
11604
11624
  }, {
11605
11625
  name: "json",
11606
11626
  required: true,
11607
11627
  value: "file|-",
11608
- about: "The story document, as a file path or - to read stdin"
11628
+ about: "The layers document, as a file path or - to read stdin"
11609
11629
  }],
11610
- dataKey: "story",
11611
- example: "adiff story set --worktree . --json -"
11630
+ dataKey: "layers",
11631
+ example: "adiff layers set --worktree . --json -"
11612
11632
  },
11613
11633
  {
11614
- name: "story show",
11615
- about: "The story of a worktree, with the hunks no step claims",
11634
+ name: "layers show",
11635
+ about: "The layers of a worktree, with the hunks no layer claims",
11616
11636
  safety: "read",
11617
11637
  options: [{
11618
11638
  name: "worktree",
@@ -11620,8 +11640,8 @@ const catalog = [
11620
11640
  value: "path",
11621
11641
  about: "The worktree to read"
11622
11642
  }],
11623
- dataKey: "story",
11624
- example: "adiff story show --worktree . --fields steps,uncovered"
11643
+ dataKey: "layers",
11644
+ example: "adiff layers show --worktree . --fields layers,uncovered"
11625
11645
  },
11626
11646
  {
11627
11647
  name: "review open",
@@ -11675,17 +11695,17 @@ const ADVICE = {
11675
11695
  },
11676
11696
  UnknownWorktree: {
11677
11697
  exit: 3,
11678
- suggestion: "Run `adiff story set` from inside a worktree of the repository under review.",
11698
+ suggestion: "Run `adiff layers set` from inside a worktree of the repository under review.",
11679
11699
  retriable: false
11680
11700
  },
11681
- MalformedStory: {
11701
+ MalformedLayers: {
11682
11702
  exit: 2,
11683
- suggestion: "A story is {\"summary\":\"…\",\"steps\":[{\"title\":\"…\",\"spans\":[{\"path\":\"…\",\"start\":1,\"end\":9}]}]}.",
11703
+ suggestion: "A layers is {\"summary\":\"…\",\"layers\":[{\"title\":\"…\",\"spans\":[{\"path\":\"…\",\"start\":1,\"end\":9}]}]}.",
11684
11704
  retriable: false
11685
11705
  },
11686
- NoStory: {
11706
+ NoLayers: {
11687
11707
  exit: 3,
11688
- suggestion: "No story has been written for this worktree. Write one with `adiff story set`.",
11708
+ suggestion: "No layers has been written for this worktree. Write one with `adiff layers set`.",
11689
11709
  retriable: false
11690
11710
  },
11691
11711
  UnselectableRange: {
@@ -11729,6 +11749,55 @@ const failure = (cause) => {
11729
11749
  };
11730
11750
  };
11731
11751
  //#endregion
11752
+ //#region src/cli/help.ts
11753
+ const NAME_ROOM = 18;
11754
+ const REACH = 5;
11755
+ const manifest = () => {
11756
+ const here = dirname(fileURLToPath(import.meta.url));
11757
+ return Array.from({ length: REACH }, (_, layer) => join(here, ...Array(layer).fill(".."))).map((at) => join(at, "package.json")).find((path) => existsSync(path));
11758
+ };
11759
+ const version = () => {
11760
+ const path = manifest();
11761
+ if (path === void 0) return "unknown";
11762
+ const raw = readFileSync(path, "utf8");
11763
+ return JSON.parse(raw).version ?? "unknown";
11764
+ };
11765
+ const line = (command) => ` ${command.name.padEnd(NAME_ROOM)}${command.about}`;
11766
+ const banner = () => [
11767
+ `adiff ${version()}`,
11768
+ "",
11769
+ "Review the work an agent did in a git worktree, and hand your comments back.",
11770
+ "",
11771
+ " adiff review open --repo . open the terminal on this repository",
11772
+ " adiff comment take --worktree . collect the comments left for you",
11773
+ "",
11774
+ "adiff --help lists every command. adiff describe answers the same as JSON."
11775
+ ].join("\n");
11776
+ const help = () => [
11777
+ "adiff, for reviewing an agent's work in a worktree",
11778
+ "",
11779
+ "Commands:",
11780
+ ...catalog.map(line),
11781
+ "",
11782
+ "Run `adiff help <command>` for its options."
11783
+ ].join("\n");
11784
+ const option = (spec) => ` --${spec.name.padEnd(16)}${spec.about}${spec.required ? " (required)" : ""}`;
11785
+ const helpFor = (name) => {
11786
+ const command = findCommand(name);
11787
+ if (command === void 0) return void 0;
11788
+ const options = command.options.length === 0 ? [] : [
11789
+ "",
11790
+ "Options:",
11791
+ ...command.options.map(option)
11792
+ ];
11793
+ return [
11794
+ `adiff ${command.name}`,
11795
+ "",
11796
+ command.about,
11797
+ ...options
11798
+ ].join("\n");
11799
+ };
11800
+ //#endregion
11732
11801
  //#region src/tui/gaps.ts
11733
11802
  const sourceLength = (source) => source.at(-1)?.trim() === "" ? source.length - 1 : source.length;
11734
11803
  const markerText = (hidden) => `⋯ ${hidden} lines hidden · press l`;
@@ -11965,7 +12034,7 @@ const visit = (walk, id, depth) => {
11965
12034
  fileIndex: void 0,
11966
12035
  files: filesUnder(walk.tree, last.id)
11967
12036
  });
11968
- if (collapsed.some((step) => walk.closed.includes(step.path))) return;
12037
+ if (collapsed.some((layer) => walk.closed.includes(layer.path))) return;
11969
12038
  for (const child of last.children) visit(walk, child, depth + 1);
11970
12039
  };
11971
12040
  const flattenTree = (tree, closed) => {
@@ -12019,26 +12088,27 @@ const initialState = (branches) => ({
12019
12088
  revealed: [],
12020
12089
  focus: "diff",
12021
12090
  navOpen: true,
12022
- steps: [],
12023
- stepIndex: 0,
12024
- openSteps: [],
12091
+ layers: [],
12092
+ layersStale: false,
12093
+ layerIndex: 0,
12094
+ openLayers: [],
12025
12095
  rail: "tree"
12026
12096
  });
12027
- const onSteps = (state) => state.rail === "steps" && state.steps.length > 0;
12028
- const stepFiles = (state, stepIndex) => {
12029
- const step = state.steps[stepIndex];
12030
- if (step === void 0) return [];
12031
- return step.files.flatMap((path) => {
12097
+ const onLayers = (state) => state.rail === "layers" && state.layers.length > 0;
12098
+ const layerFiles = (state, layerIndex) => {
12099
+ const layer = state.layers[layerIndex];
12100
+ if (layer === void 0) return [];
12101
+ return layer.files.flatMap((path) => {
12032
12102
  const at = state.patches.findIndex((patch) => patch.path === path);
12033
12103
  return at === -1 ? [] : [at];
12034
12104
  });
12035
12105
  };
12036
- const stepHolding = (state, fileIndex) => {
12106
+ const layerHolding = (state, fileIndex) => {
12037
12107
  const path = state.patches[fileIndex]?.path;
12038
- const at = state.steps.findIndex((step) => step.files.includes(path ?? ""));
12039
- return at === -1 ? state.stepIndex : at;
12108
+ const at = state.layers.findIndex((layer) => layer.files.includes(path ?? ""));
12109
+ return at === -1 ? state.layerIndex : at;
12040
12110
  };
12041
- const stepOpen = (state, stepIndex) => state.openSteps.includes(stepIndex);
12111
+ const layerOpen = (state, layerIndex) => state.openLayers.includes(layerIndex);
12042
12112
  const chunked = (word, room) => word.length <= room ? [word] : [word.slice(0, room), ...chunked(word.slice(room), room)];
12043
12113
  const packed = (lines, word, room) => {
12044
12114
  const last = lines.at(-1);
@@ -12050,29 +12120,50 @@ const wrapped = (text, room) => {
12050
12120
  return text.split(/\s+/).filter((word) => word.length > 0).flatMap((word) => chunked(word, width)).reduce((lines, word) => packed(lines, word, width), []);
12051
12121
  };
12052
12122
  const NO_NOTE = "no note";
12053
- const noteRows$1 = (state, stepIndex, room) => {
12054
- const lines = wrapped(state.steps[stepIndex]?.note ?? "", room);
12123
+ const noteRows$1 = (state, layerIndex, room) => {
12124
+ const lines = wrapped(state.layers[layerIndex]?.note ?? "", room);
12055
12125
  return (lines.length === 0 ? [NO_NOTE] : lines).map((text) => ({
12056
- index: stepIndex,
12126
+ index: layerIndex,
12057
12127
  kind: "note",
12058
12128
  text,
12059
12129
  lead: false
12060
12130
  }));
12061
12131
  };
12062
- const titleRows = (state, stepIndex, room) => wrapped(state.steps[stepIndex]?.title ?? "", room).map((text, at) => ({
12063
- index: stepIndex,
12132
+ const titleRows = (state, layerIndex, room) => wrapped(state.layers[layerIndex]?.title ?? "", room).map((text, at) => ({
12133
+ index: layerIndex,
12064
12134
  kind: "title",
12065
12135
  text,
12066
12136
  lead: at === 0
12067
12137
  }));
12068
- const stepRows = (state, titleRoom, noteRoom) => state.steps.flatMap((_, index) => stepOpen(state, index) ? [...titleRows(state, index, titleRoom), ...noteRows$1(state, index, noteRoom)] : titleRows(state, index, titleRoom));
12069
- const railWindow = (rows, height, stepIndex) => {
12138
+ const clipEnd = (text, room) => {
12139
+ if (text.length <= room) return text;
12140
+ const parts = text.split("/");
12141
+ const kept = [];
12142
+ for (const part of parts.toReversed()) {
12143
+ if ([part, ...kept].join("/").length + 2 > room) break;
12144
+ kept.unshift(part);
12145
+ }
12146
+ return `…/${kept.length === 0 ? parts.at(-1) ?? text : kept.join("/")}`;
12147
+ };
12148
+ const FILE_LEAD = 2;
12149
+ const fileRows = (state, layerIndex, room) => (state.layers[layerIndex]?.files ?? []).map((path) => ({
12150
+ index: layerIndex,
12151
+ kind: "file",
12152
+ text: clipEnd(path, Math.max(1, room - FILE_LEAD)),
12153
+ lead: false
12154
+ }));
12155
+ const layerRows = (state, titleRoom, noteRoom) => state.layers.flatMap((_, index) => layerOpen(state, index) ? [
12156
+ ...titleRows(state, index, titleRoom),
12157
+ ...noteRows$1(state, index, noteRoom),
12158
+ ...fileRows(state, index, noteRoom)
12159
+ ] : titleRows(state, index, titleRoom));
12160
+ const railWindow = (rows, height, layerIndex) => {
12070
12161
  if (rows.length <= height) return {
12071
12162
  rows,
12072
12163
  more: 0
12073
12164
  };
12074
- const first = Math.max(0, rows.findIndex((row) => row.index === stepIndex));
12075
- const block = rows.findLastIndex((row) => row.index === stepIndex) - first + 1;
12165
+ const first = Math.max(0, rows.findIndex((row) => row.index === layerIndex));
12166
+ const block = rows.findLastIndex((row) => row.index === layerIndex) - first + 1;
12076
12167
  const wanted = block >= height ? first : first - Math.floor((height - block) / 2);
12077
12168
  const start = Math.max(0, Math.min(rows.length - height, wanted));
12078
12169
  return {
@@ -12161,7 +12252,7 @@ const CONTEXT_STEPS = [
12161
12252
  60,
12162
12253
  WHOLE_FILE
12163
12254
  ];
12164
- const stepContext = (current, delta) => {
12255
+ const layerContext = (current, delta) => {
12165
12256
  const at = CONTEXT_STEPS.indexOf(current);
12166
12257
  const next = Math.max(0, Math.min(CONTEXT_STEPS.length - 1, (at === -1 ? 0 : at) + delta));
12167
12258
  return CONTEXT_STEPS[next] ?? current;
@@ -12202,8 +12293,8 @@ const nextUnreviewed = (state, from) => {
12202
12293
  return [...order.slice(start + 1), ...order.slice(0, start + 1)].find((index) => !isReviewed(state, index));
12203
12294
  };
12204
12295
  const reviewedCount = (state) => `${state.vouched.length}/${state.patches.length} reviewed`;
12205
- const fileOrder = (state) => onSteps(state) ? stepFiles(state, state.stepIndex) : treeRows(state).flatMap((row) => row.fileIndex === void 0 ? [] : [row.fileIndex]);
12206
- const stepFile = (state, delta) => {
12296
+ const fileOrder = (state) => onLayers(state) ? layerFiles(state, state.layerIndex) : treeRows(state).flatMap((row) => row.fileIndex === void 0 ? [] : [row.fileIndex]);
12297
+ const layerFile = (state, delta) => {
12207
12298
  const order = fileOrder(state);
12208
12299
  const position = order.indexOf(state.patchIndex);
12209
12300
  if (position === -1) return order[0] ?? state.patchIndex;
@@ -12274,6 +12365,7 @@ const command = (input) => ({
12274
12365
  hint: "",
12275
12366
  listed: true,
12276
12367
  whenStaged: false,
12368
+ whenLayers: false,
12277
12369
  ...input
12278
12370
  });
12279
12371
  const commands = [
@@ -12407,21 +12499,23 @@ const commands = [
12407
12499
  }),
12408
12500
  command({
12409
12501
  action: "rail.toggle",
12410
- title: "Switch between steps and files",
12502
+ title: "Switch between layers and files",
12411
12503
  category: "Files",
12412
12504
  keys: ["s"],
12413
- screens: ["review"]
12505
+ screens: ["review"],
12506
+ hint: "layers",
12507
+ whenLayers: true
12414
12508
  }),
12415
12509
  command({
12416
12510
  action: "tree.collapse",
12417
- title: "Close the folder, step, or gap",
12511
+ title: "Close the folder, layer, or gap",
12418
12512
  category: "Files",
12419
12513
  keys: ["h"],
12420
12514
  screens: ["review"]
12421
12515
  }),
12422
12516
  command({
12423
12517
  action: "tree.expand",
12424
- title: "Open the folder, step, or gap",
12518
+ title: "Open the folder, layer, or gap",
12425
12519
  category: "Files",
12426
12520
  keys: ["l"],
12427
12521
  screens: ["review"]
@@ -12592,7 +12686,7 @@ const displayKey = (key) => {
12592
12686
  if (key.startsWith("ctrl+")) return `^${key.slice(5)}`;
12593
12687
  return GLYPHS[key] ?? key;
12594
12688
  };
12595
- const hintsFor = (screen, staged) => commandsFor(screen).filter((entry) => entry.hint.length > 0).filter((entry) => !entry.whenStaged || staged > 0).map((entry) => ({
12689
+ const hintsFor = (screen, staged, layers = 0) => commandsFor(screen).filter((entry) => entry.hint.length > 0).filter((entry) => !entry.whenStaged || staged > 0).filter((entry) => !entry.whenLayers || layers > 0).map((entry) => ({
12596
12690
  key: displayKey(entry.keys[0] ?? ""),
12597
12691
  hint: entry.hint,
12598
12692
  press: entry.keys[0] ?? ""
@@ -12653,7 +12747,7 @@ const atRow = (state, row) => withCursorVisible({
12653
12747
  ...state,
12654
12748
  cursor: clamp(row, 0, lastRow(selectedPatch(state)))
12655
12749
  });
12656
- const stepHunk = (state, delta) => {
12750
+ const layerHunk = (state, delta) => {
12657
12751
  const starts = hunkStarts(state);
12658
12752
  const target = delta > 0 ? starts.find((start) => start > state.cursor) : starts.findLast((start) => start < state.cursor);
12659
12753
  return target === void 0 ? state : atRow(state, target);
@@ -12676,7 +12770,7 @@ const atComment = (state, file, delta) => {
12676
12770
  const landing = delta > 0 ? rows[0] : rows.at(-1);
12677
12771
  return landing === void 0 ? moved : atRow(moved, landing);
12678
12772
  };
12679
- const stepComment = (state, delta) => {
12773
+ const layerComment = (state, delta) => {
12680
12774
  const here = commentRowsIn(state, state.patchIndex);
12681
12775
  const target = delta > 0 ? here.find((row) => row > state.cursor) : here.findLast((row) => row < state.cursor);
12682
12776
  if (target !== void 0) return atRow(state, target);
@@ -12688,13 +12782,13 @@ const movePending = (state, delta) => ({
12688
12782
  ...state,
12689
12783
  pendingIndex: clamp(state.pendingIndex + delta, 0, Math.max(0, state.pending.length - 1))
12690
12784
  });
12691
- const moveStep = (state, delta) => {
12692
- const stepIndex = clamp(state.stepIndex + delta, 0, Math.max(0, state.steps.length - 1));
12785
+ const moveLayer = (state, delta) => {
12786
+ const layerIndex = clamp(state.layerIndex + delta, 0, Math.max(0, state.layers.length - 1));
12693
12787
  const landed = {
12694
12788
  ...state,
12695
- stepIndex
12789
+ layerIndex
12696
12790
  };
12697
- const patchIndex = stepFiles(landed, stepIndex)[0] ?? landed.patchIndex;
12791
+ const patchIndex = layerFiles(landed, layerIndex)[0] ?? landed.patchIndex;
12698
12792
  return {
12699
12793
  ...landed,
12700
12794
  patchIndex,
@@ -12704,18 +12798,18 @@ const moveStep = (state, delta) => {
12704
12798
  selecting: false
12705
12799
  };
12706
12800
  };
12707
- const inRail = (state, delta) => onSteps(state) ? moveStep(state, delta) : moveFile(state, delta);
12708
- const stepDown = (state, delta) => state.focus === "tree" ? inRail(state, delta) : moveCursor(state, delta);
12801
+ const inRail = (state, delta) => onLayers(state) ? moveLayer(state, delta) : moveFile(state, delta);
12802
+ const layerDown = (state, delta) => state.focus === "tree" ? inRail(state, delta) : moveCursor(state, delta);
12709
12803
  const toggleRail = (state) => {
12710
- if (state.steps.length === 0) return withNotice(state, "no story for this branch");
12711
- if (state.rail === "steps") return {
12804
+ if (state.layers.length === 0) return withNotice(state, "no layers for this branch");
12805
+ if (state.rail === "layers") return {
12712
12806
  ...state,
12713
12807
  rail: "tree"
12714
12808
  };
12715
12809
  return {
12716
12810
  ...state,
12717
- rail: "steps",
12718
- stepIndex: stepHolding(state, state.patchIndex)
12811
+ rail: "layers",
12812
+ layerIndex: layerHolding(state, state.patchIndex)
12719
12813
  };
12720
12814
  };
12721
12815
  const foldDirectory = (state, shut) => {
@@ -12727,21 +12821,21 @@ const foldDirectory = (state, shut) => {
12727
12821
  closed: shut ? [...closed, directory] : closed
12728
12822
  };
12729
12823
  };
12730
- const foldStep = (state, shut) => {
12731
- const open = state.openSteps.filter((index) => index !== state.stepIndex);
12824
+ const foldLayer = (state, shut) => {
12825
+ const open = state.openLayers.filter((index) => index !== state.layerIndex);
12732
12826
  return {
12733
12827
  ...state,
12734
- openSteps: shut ? open : [...open, state.stepIndex]
12828
+ openLayers: shut ? open : [...open, state.layerIndex]
12735
12829
  };
12736
12830
  };
12737
- const fold = (state, shut) => onSteps(state) ? foldStep(state, shut) : foldDirectory(state, shut);
12831
+ const fold = (state, shut) => onLayers(state) ? foldLayer(state, shut) : foldDirectory(state, shut);
12738
12832
  const moveBranch = (state, delta) => ({
12739
12833
  ...state,
12740
12834
  branchIndex: clamp(state.branchIndex + delta, 0, Math.max(0, state.branches.length - 1))
12741
12835
  });
12742
12836
  const moveFile = (state, delta) => ({
12743
12837
  ...state,
12744
- patchIndex: stepFile(state, delta),
12838
+ patchIndex: layerFile(state, delta),
12745
12839
  top: 0,
12746
12840
  cursor: 0,
12747
12841
  anchorRow: 0,
@@ -12806,18 +12900,18 @@ const transitions = {
12806
12900
  "branch.next": (state) => moveBranch(state, 1),
12807
12901
  "branch.prev": (state) => moveBranch(state, -1),
12808
12902
  "branch.open": (state) => state,
12809
- "cursor.next": (state) => stepDown(state, 1),
12903
+ "cursor.next": (state) => layerDown(state, 1),
12810
12904
  "cursor.top": (state) => atRow(state, 0),
12811
12905
  "cursor.bottom": (state) => atRow(state, lastRow(selectedPatch(state))),
12812
12906
  "cursor.pageDown": (state) => moveCursor(state, Math.max(1, Math.floor(state.viewport / 2))),
12813
12907
  "cursor.pageUp": (state) => moveCursor(state, -Math.max(1, Math.floor(state.viewport / 2))),
12814
12908
  "context.more": (state) => state,
12815
12909
  "context.less": (state) => state,
12816
- "comment.next": (state) => stepComment(state, 1),
12817
- "comment.prev": (state) => stepComment(state, -1),
12818
- "hunk.next": (state) => stepHunk(state, 1),
12819
- "hunk.prev": (state) => stepHunk(state, -1),
12820
- "cursor.prev": (state) => stepDown(state, -1),
12910
+ "comment.next": (state) => layerComment(state, 1),
12911
+ "comment.prev": (state) => layerComment(state, -1),
12912
+ "hunk.next": (state) => layerHunk(state, 1),
12913
+ "hunk.prev": (state) => layerHunk(state, -1),
12914
+ "cursor.prev": (state) => layerDown(state, -1),
12821
12915
  "file.next": (state) => moveFile(state, 1),
12822
12916
  "file.prev": (state) => moveFile(state, -1),
12823
12917
  "select.start": startSelection,
@@ -12916,18 +13010,20 @@ const withSent = (state, sent) => ({
12916
13010
  ...state,
12917
13011
  sent
12918
13012
  });
12919
- const withStory = (state, steps) => {
13013
+ const withLayers = (state, told) => {
13014
+ const layers = told.layers;
12920
13015
  const opened = {
12921
13016
  ...state,
12922
- steps,
12923
- stepIndex: 0,
12924
- openSteps: [],
12925
- rail: steps.length === 0 ? "tree" : "steps"
13017
+ layers,
13018
+ layersStale: told.stale,
13019
+ layerIndex: 0,
13020
+ openLayers: [],
13021
+ rail: layers.length === 0 ? "tree" : "layers"
12926
13022
  };
12927
- if (steps.length === 0) return opened;
13023
+ if (layers.length === 0) return opened;
12928
13024
  return {
12929
13025
  ...opened,
12930
- patchIndex: stepFiles(opened, 0)[0] ?? opened.patchIndex,
13026
+ patchIndex: layerFiles(opened, 0)[0] ?? opened.patchIndex,
12931
13027
  cursor: 0,
12932
13028
  top: 0
12933
13029
  };
@@ -13255,8 +13351,10 @@ var DiffView = class {
13255
13351
  }
13256
13352
  listenTo(handlers) {
13257
13353
  this.numbers.onMouseScroll = (event) => {
13354
+ const way = event.scroll?.direction;
13355
+ if (way !== "up" && way !== "down") return;
13258
13356
  const size = Math.max(1, event.scroll?.delta ?? 1) * SCROLL_ROWS;
13259
- handlers.scroll(event.scroll?.direction === "up" ? -size : size);
13357
+ handlers.scroll(way === "up" ? -size : size);
13260
13358
  };
13261
13359
  this.numbers.onMouseDown = (event) => handlers.down(event.y);
13262
13360
  this.numbers.onMouseDrag = (event) => handlers.drag(event.y);
@@ -13444,7 +13542,7 @@ const PANE_CHROME = 3;
13444
13542
  const BRANCH_WIDTH = 82;
13445
13543
  const BRANCH_NAME = 44;
13446
13544
  const BRANCH_NAME_MIN = 12;
13447
- const BRANCH_TAIL = 35;
13545
+ const BRANCH_TAIL = 45;
13448
13546
  const MODAL_MARGIN = 4;
13449
13547
  const bodyRoom = (width) => Math.max(0, width - 2 - BODY_BORDER);
13450
13548
  const treeWidth = (width) => {
@@ -13723,26 +13821,42 @@ const shortPath = (path) => {
13723
13821
  const home = process.env["HOME"] ?? "";
13724
13822
  return home.length > 0 && path.startsWith(home) ? `~${path.slice(home.length)}` : path;
13725
13823
  };
13824
+ const HOME_PATH_MIN = 24;
13825
+ const HOME_PATH_CHROME = 10;
13826
+ const elide = (path, room) => {
13827
+ if (path.length <= room) return path;
13828
+ const parts = path.split("/").filter((part) => part.length > 0);
13829
+ const lead = path.startsWith("~") ? "~" : "";
13830
+ const tail = parts.slice(-2).join("/");
13831
+ const middled = `${path.startsWith("/") ? `/${parts[0] ?? ""}` : lead}/…/${tail}`;
13832
+ return middled.length <= room ? middled : `…/${tail}`;
13833
+ };
13726
13834
  const contextLabel = (context) => {
13727
13835
  if (context === 3) return "";
13728
13836
  return context >= 1e5 ? "whole file" : `±${context}`;
13729
13837
  };
13730
13838
  const nameRoom = (pane) => Math.max(BRANCH_NAME_MIN, Math.min(BRANCH_NAME, pane - BRANCH_TAIL));
13731
- const columns = (cells, room) => `${clip(cells.name, room).padEnd(room)}${cells.files.padStart(5)}${cells.added.padStart(8)}${cells.gone.padStart(8)} ${cells.state}`;
13839
+ const columns = (cells, room) => `${clip(cells.name, room).padEnd(room)}${cells.files.padStart(5)}${cells.added.padStart(8)}${cells.gone.padStart(8)} ${cells.layers.padStart(8)} ${cells.state}`;
13732
13840
  const branchHeading = (room) => ` ${columns({
13733
13841
  name: "WORKTREE",
13734
13842
  files: "FILES",
13735
13843
  added: "+",
13736
13844
  gone: "-",
13845
+ layers: "LAYERS",
13737
13846
  state: "STATE"
13738
13847
  }, room)}`;
13739
13848
  const atHome = (state) => state.screen === "branches" || state.screen === "palette" && state.returnTo === "branches";
13849
+ const layersCell = (branch) => {
13850
+ if (branch.layers === 0) return "";
13851
+ return branch.stale ? `${branch.layers} stale` : `${branch.layers} layers`;
13852
+ };
13740
13853
  const branchCells = (branch, here, room) => ({
13741
13854
  lead: `${here ? marks().cursor : " "} `,
13742
13855
  name: clip(branch.branch, room).padEnd(room),
13743
13856
  files: `${branch.files}`.padStart(5),
13744
13857
  added: `+${branch.added}`.padStart(8),
13745
13858
  gone: `-${branch.removed}`.padStart(8),
13859
+ layers: layersCell(branch),
13746
13860
  state: waitingLabel(branch).trim()
13747
13861
  });
13748
13862
  const headerParts = (state, branch, path) => [
@@ -13775,30 +13889,32 @@ const STEP_NUMBER = 3;
13775
13889
  const STEP_LEAD = 8;
13776
13890
  const NOTE_LEAD = 10;
13777
13891
  const STEP_GAP = 1;
13778
- const stepRoom = (state, pane) => {
13779
- const tally = Math.max(1, ...state.steps.map((step) => `${step.files.length}`.length));
13892
+ const layerRoom = (state, pane) => {
13893
+ const tally = Math.max(1, ...state.layers.map((layer) => `${layer.files.length}`.length));
13780
13894
  return {
13781
13895
  title: Math.max(4, pane - PANE_CHROME - STEP_LEAD - STEP_GAP - tally),
13782
13896
  note: Math.max(4, pane - PANE_CHROME - NOTE_LEAD),
13783
13897
  tally
13784
13898
  };
13785
13899
  };
13786
- const stepFold = (state, index) => {
13787
- if (stepOpen(state, index)) return "▾";
13788
- return (state.steps[index]?.note ?? "").length === 0 ? " " : "▸";
13900
+ const layerFold = (state, index) => {
13901
+ if (layerOpen(state, index)) return "▾";
13902
+ return (state.layers[index]?.note ?? "").length === 0 ? " " : "▸";
13789
13903
  };
13790
- const stepHead = (state, row) => {
13904
+ const layerHead = (state, row) => {
13791
13905
  if (!row.lead) return " ".repeat(STEP_LEAD);
13792
- return `${row.index === state.stepIndex ? state.focus === "tree" ? "▸" : "·" : " "} ${stepFold(state, row.index)} ${`${row.index + 1}.`.padStart(STEP_NUMBER)} `;
13906
+ return `${row.index === state.layerIndex ? state.focus === "tree" ? "▸" : "·" : " "} ${layerFold(state, row.index)} ${`${row.index + 1}.`.padStart(STEP_NUMBER)} `;
13793
13907
  };
13794
- const stepText = (state, row, room) => {
13908
+ const layerText = (state, row, room) => {
13909
+ if (row.kind === "file") return `${" ".repeat(NOTE_LEAD)}${marks().file} ${row.text}`;
13795
13910
  if (row.kind === "note") return `${" ".repeat(NOTE_LEAD)}${row.text}`;
13796
- const tail = (row.lead ? `${state.steps[row.index]?.files.length ?? 0}` : "").padStart(room.tally + STEP_GAP);
13797
- return `${stepHead(state, row)}${row.text.padEnd(room.title)}${tail}`;
13911
+ const tail = (row.lead ? `${state.layers[row.index]?.files.length ?? 0}` : "").padStart(room.tally + STEP_GAP);
13912
+ return `${layerHead(state, row)}${row.text.padEnd(room.title)}${tail}`;
13798
13913
  };
13799
- const stepPaint = (state, row) => {
13914
+ const layerPaint = (state, row) => {
13915
+ if (row.kind === "file") return palette.ink;
13800
13916
  if (row.kind === "note") return palette.faint;
13801
- return row.index === state.stepIndex ? palette.ink : palette.muted;
13917
+ return row.index === state.layerIndex ? palette.ink : palette.muted;
13802
13918
  };
13803
13919
  var Screen = class {
13804
13920
  header;
@@ -13902,12 +14018,14 @@ var Screen = class {
13902
14018
  }
13903
14019
  update(state) {
13904
14020
  this.shown = state;
13905
- this.chips = hintsFor(state.screen, state.staged);
14021
+ this.chips = hintsFor(state.screen, state.staged, state.layers.length);
13906
14022
  this.header.content = this.headerText(state);
13907
14023
  this.footer.content = this.footerText(state);
13908
14024
  this.list.content = this.listText(state);
13909
14025
  const many = state.branches.length === 1 ? "1 worktree" : `${state.branches.length} worktrees`;
13910
- this.landing.content = `${shortPath(this.repo)} · ${many}`;
14026
+ const pane = homeWidth(this.renderer.width);
14027
+ const room = Math.max(HOME_PATH_MIN, pane - many.length - HOME_PATH_CHROME);
14028
+ this.landing.content = `${elide(shortPath(this.repo), room)} · ${many}`;
13911
14029
  this.landingKeys.content = this.chipRow();
13912
14030
  this.diffPane.visible = state.screen !== "branches" && !(state.screen === "palette" && state.returnTo === "branches");
13913
14031
  if (this.diffPane.visible) this.paintDiff(state);
@@ -13964,7 +14082,7 @@ var Screen = class {
13964
14082
  }
13965
14083
  listText(state) {
13966
14084
  if (atHome(state)) return this.branchTable(state);
13967
- if (onSteps(state)) return this.stepRail(state);
14085
+ if (onLayers(state)) return this.layerRail(state);
13968
14086
  const height = Math.max(1, this.listPane.height - 1);
13969
14087
  const pane = this.paneRoom();
13970
14088
  const window = treeWindow(state, height);
@@ -13972,13 +14090,18 @@ var Screen = class {
13972
14090
  const more = window.more > 0 ? [fg(palette.faint)(` … ${window.more} more`)] : [];
13973
14091
  return new StyledText([...rows, ...more]);
13974
14092
  }
13975
- stepRail(state) {
14093
+ layerRail(state) {
13976
14094
  const height = Math.max(1, this.listPane.height - 1);
13977
- const room = stepRoom(state, this.paneRoom());
13978
- const window = railWindow(stepRows(state, room.title, room.note), height, state.stepIndex);
13979
- const rows = window.rows.map((row) => fg(stepPaint(state, row))(`${stepText(state, row, room)}\n`));
14095
+ const room = layerRoom(state, this.paneRoom());
14096
+ const window = railWindow(layerRows(state, room.title, room.note), height, state.layerIndex);
14097
+ const rows = window.rows.map((row) => fg(layerPaint(state, row))(`${layerText(state, row, room)}\n`));
13980
14098
  const more = window.more > 0 ? [fg(palette.faint)(` … ${window.more} more`)] : [];
13981
- return new StyledText([...rows, ...more]);
14099
+ const warn = state.layersStale ? [fg(palette.attention)(` stale, the branch moved on\n\n`)] : [];
14100
+ return new StyledText([
14101
+ ...warn,
14102
+ ...rows,
14103
+ ...more
14104
+ ]);
13982
14105
  }
13983
14106
  paintDiff(state) {
13984
14107
  const shown = shownOf(state);
@@ -14069,6 +14192,7 @@ var Screen = class {
14069
14192
  fg(palette.faint)(cells.files),
14070
14193
  fg(palette.added)(cells.added),
14071
14194
  fg(palette.removed)(cells.gone),
14195
+ fg(palette.accent)(` ${cells.layers.padStart(8)}`),
14072
14196
  fg(palette.attention)(` ${cells.state}\n`)
14073
14197
  ];
14074
14198
  });
@@ -14089,8 +14213,14 @@ var Screen = class {
14089
14213
  }
14090
14214
  chipRow() {
14091
14215
  return new StyledText(this.chips.flatMap((chip, index) => {
14092
- const paint = index === this.hovered ? bg(palette.cursor) : fg(palette.faint);
14093
- return [index === this.hovered ? paint(` ${chip.key} ${chip.hint} `) : fg(palette.ink)(chip.key), index === this.hovered ? fg(palette.faint)(" ") : fg(palette.faint)(` ${chip.hint} `)];
14216
+ const lit = index === this.hovered;
14217
+ const key = fg(palette.ink)(chip.key);
14218
+ const hint = fg(lit ? palette.ink : palette.faint)(` ${chip.hint}`);
14219
+ return [
14220
+ lit ? bg(palette.cursor)(key) : key,
14221
+ lit ? bg(palette.cursor)(hint) : hint,
14222
+ fg(palette.faint)(" ")
14223
+ ];
14094
14224
  }));
14095
14225
  }
14096
14226
  paintPane(state) {
@@ -14251,6 +14381,7 @@ var App = class {
14251
14381
  remembered = "";
14252
14382
  keys = [];
14253
14383
  fading;
14384
+ wheel = 0;
14254
14385
  constructor(options) {
14255
14386
  this.renderer = options.renderer;
14256
14387
  this.repo = options.repo;
@@ -14262,13 +14393,14 @@ var App = class {
14262
14393
  this.screen = new Screen(renderer, options.repo);
14263
14394
  this.screen.update(this.state);
14264
14395
  this.screen.listen({
14265
- onScroll: (delta) => this.commit(scrolled(this.measured(), delta)),
14396
+ onScroll: (delta) => this.onWheel(delta),
14266
14397
  onDrag: (from, to) => this.commit(draggedTo(this.measured(), from, to)),
14267
14398
  onChip: (key) => this.dispatchTask(() => this.onKey(asKey(key)))
14268
14399
  });
14269
14400
  renderer.keyInput.on("keypress", (key) => this.dispatch(key));
14270
14401
  renderer.on("destroy", () => this.stopFading());
14271
14402
  renderer.on("frame", () => this.syncGeometry());
14403
+ renderer.setFrameCallback(async () => this.applyWheel());
14272
14404
  const resume = options.resume;
14273
14405
  if (resume !== void 0) this.dispatchTask(() => this.resume(resume));
14274
14406
  }
@@ -14312,6 +14444,16 @@ var App = class {
14312
14444
  settled() {
14313
14445
  return this.pending;
14314
14446
  }
14447
+ onWheel(delta) {
14448
+ this.wheel += delta;
14449
+ this.renderer.requestRender();
14450
+ }
14451
+ applyWheel() {
14452
+ const delta = this.wheel;
14453
+ if (delta === 0) return;
14454
+ this.wheel = 0;
14455
+ this.commit(scrolled(this.measured(), delta));
14456
+ }
14315
14457
  syncGeometry() {
14316
14458
  const rows = this.screen.viewportRows();
14317
14459
  if (rows === this.state.viewport) return;
@@ -14420,10 +14562,10 @@ var App = class {
14420
14562
  const patches = await this.run(listPatches(this.repo, branch.branch));
14421
14563
  const progress = await this.run(reviewProgress(this.repo, branch.branch));
14422
14564
  const pending = await this.run(listPending(this.repo, branch.branch));
14423
- const steps = await this.run(listStorySteps(this.repo, branch.branch));
14565
+ const layers = await this.run(listLayers(this.repo, branch.branch));
14424
14566
  const opened = withVouched(withPatches(this.state, patches), progress.vouched);
14425
14567
  const sent = await this.loadSent(branch.branch);
14426
- this.commit(withStory(withSent(withPending(opened, pending, "review"), sent), steps));
14568
+ this.commit(withLayers(withSent(withPending(opened, pending, "review"), sent), layers));
14427
14569
  await this.loadSource();
14428
14570
  }
14429
14571
  async goBack() {
@@ -14501,7 +14643,7 @@ var App = class {
14501
14643
  }
14502
14644
  async expand(delta) {
14503
14645
  const branch = selectedBranch(this.state);
14504
- const next = stepContext(this.state.context, delta);
14646
+ const next = layerContext(this.state.context, delta);
14505
14647
  if (branch === void 0 || next === this.state.context) return;
14506
14648
  const line = sourceLineAt(this.state, this.state.cursor);
14507
14649
  const patches = await this.run(listPatches(this.repo, branch.branch, next));
@@ -14670,7 +14812,7 @@ const reviewStatus = fn("Main.reviewStatus")(function* (options) {
14670
14812
  const documentAt = fn("Main.documentAt")(function* (source) {
14671
14813
  return yield* tryPromise({
14672
14814
  try: () => source === "-" ? text(process.stdin) : readFile(source, "utf8"),
14673
- catch: (cause) => new MalformedStory({ reason: String(cause) })
14815
+ catch: (cause) => new MalformedLayers({ reason: String(cause) })
14674
14816
  });
14675
14817
  });
14676
14818
  const routes = {
@@ -14680,14 +14822,14 @@ const routes = {
14680
14822
  "comment take": commentTake,
14681
14823
  "review submit": reviewSubmit,
14682
14824
  "review progress": reviewStatus,
14683
- "story set": fn("Main.storySet")(function* (options) {
14825
+ "layers set": fn("Main.layersSet")(function* (options) {
14684
14826
  const document = yield* documentAt(yield* required(options, "json"));
14685
- const story = yield* setStory(yield* required(options, "worktree"), document, options["at"] ?? (/* @__PURE__ */ new Date()).toISOString());
14686
- yield* answer(options, { story });
14827
+ const layers = yield* setLayers(yield* required(options, "worktree"), document, options["at"] ?? (/* @__PURE__ */ new Date()).toISOString());
14828
+ yield* answer(options, { layers });
14687
14829
  }),
14688
- "story show": fn("Main.storyShow")(function* (options) {
14689
- const story = yield* showStory(yield* required(options, "worktree"));
14690
- yield* answer(options, { story });
14830
+ "layers show": fn("Main.layersShow")(function* (options) {
14831
+ const layers = yield* showLayers(yield* required(options, "worktree"));
14832
+ yield* answer(options, { layers });
14691
14833
  }),
14692
14834
  describe: fn("Main.describe")(function* (options) {
14693
14835
  const wanted = options["command"];
@@ -14716,6 +14858,25 @@ const nameOf = (argv) => {
14716
14858
  return findCommand(pair) === void 0 ? words[0] ?? "" : pair;
14717
14859
  };
14718
14860
  const argv = process.argv.slice(2);
14861
+ const ASKS = {
14862
+ "--version": version,
14863
+ "-v": version,
14864
+ "--help": help,
14865
+ "-h": help
14866
+ };
14867
+ const spoken = (words) => {
14868
+ const [first, ...rest] = words;
14869
+ if (first === void 0) return banner();
14870
+ const asked = ASKS[first];
14871
+ if (asked !== void 0) return asked();
14872
+ if (first !== "help") return void 0;
14873
+ return rest.length === 0 ? help() : helpFor(rest.join(" ")) ?? help();
14874
+ };
14875
+ const said = spoken(argv);
14876
+ if (said !== void 0) {
14877
+ process.stdout.write(`${said}\n`);
14878
+ process.exit(0);
14879
+ }
14719
14880
  const layer = mergeAll(GitLive, storeAt(process.env["ADIFF_ROOT"] ?? defaultRoot()));
14720
14881
  const exit = await runPromiseExit(run(nameOf(argv), optionsFrom(argv)).pipe(provide(layer)));
14721
14882
  if (isFailure(exit)) {
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "bin": {
22
22
  "adiff": "./bin/adiff.js"
23
23
  },
24
- "version": "0.1.0-alpha.4",
24
+ "version": "0.1.0-alpha.6",
25
25
  "description": "Review agent work across git worktrees like a PR, and hand the comments back to the agent.",
26
26
  "license": "MIT",
27
27
  "repository": {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: adiff
3
- description: Pick up review comments left on this worktree's diff in the adiff terminal, act on them, and write the story that explains the diff. Use when the user says they left comments, asks you to check adiff, asks you to watch for review feedback, or asks you to hand work over for review.
3
+ description: Pick up review comments left on this worktree's diff in the adiff terminal, act on them, and write the layers that explains the diff. Use when the user says they left comments, asks you to check adiff, asks you to watch for review feedback, or asks you to hand work over for review.
4
4
  ---
5
5
 
6
6
  # adiff
@@ -66,21 +66,21 @@ Read `suggestion` before doing anything else — it names the command that resol
66
66
  Retry only when `retriable` is true. `UnknownBranch` means this worktree is not one adiff knows
67
67
  about, because the reviewer has not opened it; report that rather than looping.
68
68
 
69
- ## Handing work over: write the story
69
+ ## Handing work over: write the layers
70
70
 
71
71
  You know the order the change was built in. The reviewer does not, and rebuilding it by reading
72
72
  every file is the most expensive way to learn something you already have. When you finish a piece
73
- of work, write a **story**: an ordered set of steps over the diff, each one a claim about a span of
73
+ of work, write a **layers**: an ordered set of layers over the diff, each one a claim about a span of
74
74
  code. The reviewer then walks the argument instead of the filesystem.
75
75
 
76
76
  ```bash
77
- adiff story set --worktree . --json - <<'JSON'
77
+ adiff layers set --worktree . --json - <<'JSON'
78
78
  {
79
79
  "summary": "Team invitations, end to end",
80
- "steps": [
80
+ "layers": [
81
81
  {
82
82
  "title": "Add the invitation data model",
83
- "note": "The record every later step leans on",
83
+ "note": "The record every later layer leans on",
84
84
  "spans": [{ "path": "src/db/invites.ts", "start": 1, "end": 48 }]
85
85
  },
86
86
  {
@@ -99,35 +99,35 @@ adiff story set --worktree . --json - <<'JSON'
99
99
  JSON
100
100
  ```
101
101
 
102
- Rules that make a story worth reading:
102
+ Rules that make a layers worth reading:
103
103
 
104
- - **Order is the point.** Step 1 is what the reader must understand before step 2 makes sense.
104
+ - **Order is the point.** Layer 1 is what the reader must understand before layer 2 makes sense.
105
105
  Data model, then the code that uses it, then the surface, then the mechanical bits last.
106
106
  - **A title is a claim, not a file name.** "Add the invitation API", never "changes to
107
107
  src/api/invites.ts".
108
108
  - **Line numbers are the new side of the diff**, the same numbers `adiff comment take` reports.
109
- - **Cover everything.** adiff computes coverage itself and answers with the hunks no step claims;
110
- those show up for the reviewer under "not in any step" whatever you do. A story that quietly
111
- skips a third of the diff is worse than no story, so put the leftovers in a final step and say
109
+ - **Cover everything.** adiff computes coverage itself and answers with the hunks no layer claims;
110
+ those show up for the reviewer under "not in any layer" whatever you do. A layers that quietly
111
+ skips a third of the diff is worse than no layers, so put the leftovers in a final layer and say
112
112
  they are mechanical.
113
113
 
114
- The answer to `story set` is the honest report — check it before you claim to be done:
114
+ The answer to `layers set` is the honest report — check it before you claim to be done:
115
115
 
116
116
  ```json
117
- {"ok":true,"story":{"version":1,"stale":false,"covered":7,"total":9,"uncovered":[{"path":"src/api/router.ts","start":40,"end":52}],"vanished":[],"steps":[{"title":"Add the invitation data model","files":["src/db/invites.ts"]}]}}
117
+ {"ok":true,"layers":{"version":1,"stale":false,"covered":7,"total":9,"uncovered":[{"path":"src/api/router.ts","start":40,"end":52}],"vanished":[],"layers":[{"title":"Add the invitation data model","files":["src/db/invites.ts"]}]}}
118
118
  ```
119
119
 
120
- `covered`/`total` count hunks. `uncovered` names the ones no step claims — claim them and set the
121
- story again. `vanished` names paths a step points at that this branch does not change, which
120
+ `covered`/`total` count hunks. `uncovered` names the ones no layer claims — claim them and set the
121
+ layers again. `vanished` names paths a layer points at that this branch does not change, which
122
122
  usually means a typo in a path. Read it back at any time with:
123
123
 
124
124
  ```bash
125
- adiff story show --worktree . --fields covered,total,uncovered
125
+ adiff layers show --worktree . --fields covered,total,uncovered
126
126
  ```
127
127
 
128
- Setting a story again supersedes the previous one and bumps `version`; the story records the commit
128
+ Setting a layers again supersedes the previous one and bumps `version`; the layers records the commit
129
129
  it was written for, and adiff reports it as `stale` once the branch moves past that commit. After
130
- you address a review, write the story again.
130
+ you address a review, write the layers again.
131
131
 
132
132
  ## Tell the reviewer how to read it
133
133
 
@@ -136,11 +136,11 @@ command and the keys. Name the repository they should point at, which is the rep
136
136
  worktree belongs to:
137
137
 
138
138
  > Open it with `adiff review open --repo <repo>`, then press `enter` on this branch. The sidebar
139
- > lists the steps in reading order; `j` and `k` move between them and the diff follows. Inside a
140
- > step, `]` and `[` walk its files. Select lines with `v`, write a comment with `c`, stage it with
139
+ > lists the layers in reading order; `j` and `k` move between them and the diff follows. Inside a
140
+ > layer, `]` and `[` walk its files. Select lines with `v`, write a comment with `c`, stage it with
141
141
  > `ctrl+a`, and send the whole review with `S`. Press `?` for the rest.
142
142
 
143
- Say what you want looked at hardest, and where you are unsure. A reviewer who knows which step you
143
+ Say what you want looked at hardest, and where you are unsure. A reviewer who knows which layer you
144
144
  doubt spends their attention there.
145
145
 
146
146
  ## Discovering the rest