@eliya-oss/agent-diff 0.1.0-alpha.5 → 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,15 @@
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
+
3
13
  ## 0.1.0-alpha.5
4
14
 
5
15
  ### 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,17 +10978,17 @@ 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);
10979
- const told = yield* store.story(worktree.path);
10981
+ const told = yield* store.layers(worktree.path);
10980
10982
  return {
10981
10983
  staged: state.pending.length,
10982
10984
  unread: Math.max(0, batches.length - state.consumed),
10983
- steps: match$2(told, {
10985
+ layers: match$2(told, {
10984
10986
  onNone: () => 0,
10985
- onSome: (story) => story.steps.length
10987
+ onSome: (layers) => layers.layers.length
10986
10988
  }),
10987
10989
  stale: match$2(told, {
10988
10990
  onNone: () => false,
10989
- onSome: (story) => story.head !== worktree.head
10991
+ onSome: (layers) => layers.head !== worktree.head
10990
10992
  })
10991
10993
  };
10992
10994
  });
@@ -11006,7 +11008,7 @@ const listBranches = fn("Cli.listBranches")(function* (repo) {
11006
11008
  removed: stat.removed,
11007
11009
  staged: waiting.staged,
11008
11010
  unread: waiting.unread,
11009
- steps: waiting.steps,
11011
+ layers: waiting.layers,
11010
11012
  stale: waiting.stale
11011
11013
  });
11012
11014
  }
@@ -11202,19 +11204,19 @@ const fileSource = fn("Cli.fileSource")(function* (repo, branch, file) {
11202
11204
  return getOrElse(found, () => []);
11203
11205
  });
11204
11206
  //#endregion
11205
- //#region src/domain/narrative/model.ts
11206
- const REMAINDER_TITLE = "not in any step";
11207
+ //#region src/domain/layers/model.ts
11208
+ const REMAINDER_TITLE = "not in any layer";
11207
11209
  //#endregion
11208
- //#region src/domain/narrative/coverage.ts
11210
+ //#region src/domain/layers/coverage.ts
11209
11211
  const codeBlockOf$1 = (span) => ({
11210
11212
  kind: "code",
11211
11213
  path: span.path,
11212
11214
  start: span.start,
11213
11215
  end: span.end
11214
11216
  });
11215
- const codeBlocks = (step) => step.blocks.filter((block) => block.kind === "code");
11216
- const noteOf = (step) => step.blocks.filter((block) => block.kind === "prose").map((block) => block.markdown.trim()).filter((markdown) => markdown.length > 0).join(" ");
11217
- 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 }) => ({
11218
11220
  path,
11219
11221
  start,
11220
11222
  end
@@ -11231,8 +11233,8 @@ const spanOfHunk = (patch, hunk) => {
11231
11233
  });
11232
11234
  };
11233
11235
  const overlaps = (a, b) => a.path === b.path && a.start <= b.end && a.end >= b.start;
11234
- const coverage = (patches, steps) => {
11235
- const claimed = spansOf$1(steps);
11236
+ const coverage = (patches, layers) => {
11237
+ const claimed = spansOf$1(layers);
11236
11238
  const hunks = patches.flatMap((patch) => patch.hunks.flatMap((hunk) => match$2(spanOfHunk(patch, hunk), {
11237
11239
  onNone: () => [],
11238
11240
  onSome: (s) => [s]
@@ -11244,9 +11246,9 @@ const coverage = (patches, steps) => {
11244
11246
  missing
11245
11247
  };
11246
11248
  };
11247
- const withFullCoverage = (patches, story) => {
11248
- const gap = coverage(patches, story.steps);
11249
- 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;
11250
11252
  const remainder = {
11251
11253
  title: REMAINDER_TITLE,
11252
11254
  blocks: [{
@@ -11255,21 +11257,21 @@ const withFullCoverage = (patches, story) => {
11255
11257
  }, ...gap.missing.map((span) => codeBlockOf$1(span))]
11256
11258
  };
11257
11259
  return {
11258
- ...story,
11259
- steps: [...story.steps, remainder]
11260
+ ...layers,
11261
+ layers: [...layers.layers, remainder]
11260
11262
  };
11261
11263
  };
11262
11264
  //#endregion
11263
- //#region src/domain/narrative/version.ts
11264
- const statusOf = (patches, story, branchHead) => {
11265
- 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);
11266
11268
  const present = new Set(patches.map((patch) => patch.path));
11267
- 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));
11268
11270
  return {
11269
- version: story.version,
11270
- parent: story.parent,
11271
- stale: story.head !== branchHead,
11272
- storyHead: story.head,
11271
+ version: layers.version,
11272
+ parent: layers.parent,
11273
+ stale: layers.head !== branchHead,
11274
+ layersHead: layers.head,
11273
11275
  branchHead,
11274
11276
  uncovered: gap.missing,
11275
11277
  vanished: [...mentioned].filter((path) => !present.has(path)),
@@ -11278,9 +11280,9 @@ const statusOf = (patches, story, branchHead) => {
11278
11280
  };
11279
11281
  };
11280
11282
  //#endregion
11281
- //#region src/cli/story.ts
11283
+ //#region src/cli/layers.ts
11282
11284
  const unique = (paths) => [...new Set(paths)];
11283
- const spansOfStep = (step) => codeBlocks(step).map(({ path, start, end }) => ({
11285
+ const spansOfLayer = (layer) => codeBlocks(layer).map(({ path, start, end }) => ({
11284
11286
  path,
11285
11287
  start,
11286
11288
  end
@@ -11300,20 +11302,20 @@ const codeBlockOf = (span) => ({
11300
11302
  start: span.start,
11301
11303
  end: span.end
11302
11304
  });
11303
- const blocksOf = (step) => {
11304
- if (Array.isArray(step.blocks)) return step.blocks.filter(isBlock);
11305
- 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" ? [{
11306
11308
  kind: "prose",
11307
- markdown: step.note
11309
+ markdown: layer.note
11308
11310
  }] : [];
11309
- const spans = Array.isArray(step.spans) ? step.spans.filter(isSpan) : [];
11311
+ const spans = Array.isArray(layer.spans) ? layer.spans.filter(isSpan) : [];
11310
11312
  return [...note, ...spans.map(codeBlockOf)];
11311
11313
  };
11312
- const stepOf = (value) => {
11313
- const step = value;
11314
- const title = typeof step?.title === "string" ? step.title.trim() : "";
11315
- if (step === void 0 || title.length === 0) return none();
11316
- 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);
11317
11319
  return blocks.length === 0 ? none() : some({
11318
11320
  title,
11319
11321
  blocks
@@ -11327,55 +11329,55 @@ const parsed = (text) => {
11327
11329
  return none();
11328
11330
  }
11329
11331
  };
11330
- const readStory = fn("Cli.readStory")(function* (text) {
11332
+ const readLayers = fn("Cli.readLayers")(function* (text) {
11331
11333
  const document = yield* match$2(parsed(text), {
11332
- onNone: () => new MalformedStory({ reason: "the story is not a JSON object" }),
11334
+ onNone: () => new MalformedLayers({ reason: "the layers is not a JSON object" }),
11333
11335
  onSome: succeed
11334
11336
  });
11335
- const raw = document["steps"];
11336
- 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), {
11337
11339
  onNone: () => [],
11338
- onSome: (step) => [step]
11340
+ onSome: (layer) => [layer]
11339
11341
  }));
11340
- 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" });
11341
11343
  const summary = document["summary"];
11342
11344
  return {
11343
11345
  summary: typeof summary === "string" ? summary : "",
11344
- steps
11346
+ layers
11345
11347
  };
11346
11348
  });
11347
11349
  const fromStored = (stored) => ({
11348
11350
  ...stored,
11349
11351
  parent: fromNullishOr(stored.parent)
11350
11352
  });
11351
- const toStored = (story) => ({
11352
- ...story,
11353
- parent: getOrUndefined$1(story.parent)
11353
+ const toStored = (layers) => ({
11354
+ ...layers,
11355
+ parent: getOrUndefined$1(layers.parent)
11354
11356
  });
11355
- const stepsOf = (patches, story) => {
11357
+ const reportedLayers = (patches, layers) => {
11356
11358
  const present = new Set(patches.map((patch) => patch.path));
11357
- return withFullCoverage(patches, story).steps.map((step) => ({
11358
- title: step.title,
11359
- note: noteOf(step),
11360
- files: unique(spansOfStep(step).map((span) => span.path)).filter((path) => present.has(path)),
11361
- 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)
11362
11364
  }));
11363
11365
  };
11364
- const reportOf = (patches, story, branchHead) => {
11365
- const status = statusOf(patches, story, branchHead);
11366
+ const reportOf = (patches, layers, branchHead) => {
11367
+ const status = statusOf(patches, layers, branchHead);
11366
11368
  return {
11367
11369
  version: status.version,
11368
11370
  parent: getOrUndefined$1(status.parent),
11369
- head: status.storyHead,
11371
+ head: status.layersHead,
11370
11372
  branchHead: status.branchHead,
11371
11373
  stale: status.stale,
11372
- written: story.written,
11373
- summary: story.summary,
11374
+ written: layers.written,
11375
+ summary: layers.summary,
11374
11376
  covered: status.covered,
11375
11377
  total: status.total,
11376
11378
  uncovered: status.uncovered,
11377
11379
  vanished: status.vanished,
11378
- steps: stepsOf(patches, story)
11380
+ layers: reportedLayers(patches, layers)
11379
11381
  };
11380
11382
  };
11381
11383
  const resolve = (path) => realpath(path).catch(() => path);
@@ -11391,17 +11393,17 @@ const worktreeAt = fn("Cli.worktreeAt")(function* (worktreePath) {
11391
11393
  known: worktrees.map((entry) => entry.path)
11392
11394
  }) : succeed(found);
11393
11395
  });
11394
- const storyOf = fn("Cli.storyOf")(function* (worktree) {
11396
+ const storedLayers = fn("Cli.storedLayers")(function* (worktree) {
11395
11397
  const store = yield* Store;
11396
- return map$4(yield* store.story(worktree.path), fromStored);
11398
+ return map$4(yield* store.layers(worktree.path), fromStored);
11397
11399
  });
11398
- const setStory = fn("Cli.setStory")(function* (worktreePath, text, written) {
11400
+ const setLayers = fn("Cli.setLayers")(function* (worktreePath, text, written) {
11399
11401
  const store = yield* Store;
11400
11402
  const worktree = yield* worktreeAt(worktreePath);
11401
- const input = yield* readStory(text);
11403
+ const input = yield* readLayers(text);
11402
11404
  const patches = yield* patchesOf(worktree);
11403
- const previous = yield* storyOf(worktree);
11404
- const story = {
11405
+ const previous = yield* storedLayers(worktree);
11406
+ const layers = {
11405
11407
  version: match$2(previous, {
11406
11408
  onNone: () => 1,
11407
11409
  onSome: (old) => old.version + 1
@@ -11411,31 +11413,31 @@ const setStory = fn("Cli.setStory")(function* (worktreePath, text, written) {
11411
11413
  base: worktree.base,
11412
11414
  written,
11413
11415
  summary: input.summary,
11414
- steps: input.steps
11416
+ layers: input.layers
11415
11417
  };
11416
- yield* store.saveStory(worktree.path, toStored(story));
11417
- return reportOf(patches, story, worktree.head);
11418
+ yield* store.saveLayers(worktree.path, toStored(layers));
11419
+ return reportOf(patches, layers, worktree.head);
11418
11420
  });
11419
- const showStory = fn("Cli.showStory")(function* (worktreePath) {
11421
+ const showLayers = fn("Cli.showLayers")(function* (worktreePath) {
11420
11422
  const worktree = yield* worktreeAt(worktreePath);
11421
11423
  const patches = yield* patchesOf(worktree);
11422
- const found = yield* storyOf(worktree);
11423
- const story = yield* match$2(found, {
11424
- 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 }),
11425
11427
  onSome: succeed
11426
11428
  });
11427
- return reportOf(patches, story, worktree.head);
11429
+ return reportOf(patches, layers, worktree.head);
11428
11430
  });
11429
- const listStorySteps = fn("Cli.listStorySteps")(function* (repo, branch) {
11431
+ const listLayers = fn("Cli.listLayers")(function* (repo, branch) {
11430
11432
  const worktree = yield* findBranch(repo, branch);
11431
- const found = yield* storyOf(worktree);
11433
+ const found = yield* storedLayers(worktree);
11432
11434
  if (isNone(found)) return {
11433
- steps: [],
11435
+ layers: [],
11434
11436
  stale: false
11435
11437
  };
11436
11438
  const patches = yield* patchesOf(worktree);
11437
11439
  return {
11438
- steps: stepsOf(patches, found.value),
11440
+ layers: reportedLayers(patches, found.value),
11439
11441
  stale: found.value.head !== worktree.head
11440
11442
  };
11441
11443
  });
@@ -11611,26 +11613,26 @@ const catalog = [
11611
11613
  example: "adiff review progress --repo . --branch cdr-1"
11612
11614
  },
11613
11615
  {
11614
- name: "story set",
11615
- 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",
11616
11618
  safety: "write",
11617
11619
  options: [{
11618
11620
  name: "worktree",
11619
11621
  required: true,
11620
11622
  value: "path",
11621
- about: "The worktree the story is about"
11623
+ about: "The worktree the layers is about"
11622
11624
  }, {
11623
11625
  name: "json",
11624
11626
  required: true,
11625
11627
  value: "file|-",
11626
- 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"
11627
11629
  }],
11628
- dataKey: "story",
11629
- example: "adiff story set --worktree . --json -"
11630
+ dataKey: "layers",
11631
+ example: "adiff layers set --worktree . --json -"
11630
11632
  },
11631
11633
  {
11632
- name: "story show",
11633
- 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",
11634
11636
  safety: "read",
11635
11637
  options: [{
11636
11638
  name: "worktree",
@@ -11638,8 +11640,8 @@ const catalog = [
11638
11640
  value: "path",
11639
11641
  about: "The worktree to read"
11640
11642
  }],
11641
- dataKey: "story",
11642
- example: "adiff story show --worktree . --fields steps,uncovered"
11643
+ dataKey: "layers",
11644
+ example: "adiff layers show --worktree . --fields layers,uncovered"
11643
11645
  },
11644
11646
  {
11645
11647
  name: "review open",
@@ -11693,17 +11695,17 @@ const ADVICE = {
11693
11695
  },
11694
11696
  UnknownWorktree: {
11695
11697
  exit: 3,
11696
- 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.",
11697
11699
  retriable: false
11698
11700
  },
11699
- MalformedStory: {
11701
+ MalformedLayers: {
11700
11702
  exit: 2,
11701
- 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}]}]}.",
11702
11704
  retriable: false
11703
11705
  },
11704
- NoStory: {
11706
+ NoLayers: {
11705
11707
  exit: 3,
11706
- 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`.",
11707
11709
  retriable: false
11708
11710
  },
11709
11711
  UnselectableRange: {
@@ -11747,6 +11749,55 @@ const failure = (cause) => {
11747
11749
  };
11748
11750
  };
11749
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
11750
11801
  //#region src/tui/gaps.ts
11751
11802
  const sourceLength = (source) => source.at(-1)?.trim() === "" ? source.length - 1 : source.length;
11752
11803
  const markerText = (hidden) => `⋯ ${hidden} lines hidden · press l`;
@@ -11983,7 +12034,7 @@ const visit = (walk, id, depth) => {
11983
12034
  fileIndex: void 0,
11984
12035
  files: filesUnder(walk.tree, last.id)
11985
12036
  });
11986
- if (collapsed.some((step) => walk.closed.includes(step.path))) return;
12037
+ if (collapsed.some((layer) => walk.closed.includes(layer.path))) return;
11987
12038
  for (const child of last.children) visit(walk, child, depth + 1);
11988
12039
  };
11989
12040
  const flattenTree = (tree, closed) => {
@@ -12037,27 +12088,27 @@ const initialState = (branches) => ({
12037
12088
  revealed: [],
12038
12089
  focus: "diff",
12039
12090
  navOpen: true,
12040
- steps: [],
12041
- storyStale: false,
12042
- stepIndex: 0,
12043
- openSteps: [],
12091
+ layers: [],
12092
+ layersStale: false,
12093
+ layerIndex: 0,
12094
+ openLayers: [],
12044
12095
  rail: "tree"
12045
12096
  });
12046
- const onSteps = (state) => state.rail === "steps" && state.steps.length > 0;
12047
- const stepFiles = (state, stepIndex) => {
12048
- const step = state.steps[stepIndex];
12049
- if (step === void 0) return [];
12050
- 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) => {
12051
12102
  const at = state.patches.findIndex((patch) => patch.path === path);
12052
12103
  return at === -1 ? [] : [at];
12053
12104
  });
12054
12105
  };
12055
- const stepHolding = (state, fileIndex) => {
12106
+ const layerHolding = (state, fileIndex) => {
12056
12107
  const path = state.patches[fileIndex]?.path;
12057
- const at = state.steps.findIndex((step) => step.files.includes(path ?? ""));
12058
- return at === -1 ? state.stepIndex : at;
12108
+ const at = state.layers.findIndex((layer) => layer.files.includes(path ?? ""));
12109
+ return at === -1 ? state.layerIndex : at;
12059
12110
  };
12060
- const stepOpen = (state, stepIndex) => state.openSteps.includes(stepIndex);
12111
+ const layerOpen = (state, layerIndex) => state.openLayers.includes(layerIndex);
12061
12112
  const chunked = (word, room) => word.length <= room ? [word] : [word.slice(0, room), ...chunked(word.slice(room), room)];
12062
12113
  const packed = (lines, word, room) => {
12063
12114
  const last = lines.at(-1);
@@ -12069,29 +12120,50 @@ const wrapped = (text, room) => {
12069
12120
  return text.split(/\s+/).filter((word) => word.length > 0).flatMap((word) => chunked(word, width)).reduce((lines, word) => packed(lines, word, width), []);
12070
12121
  };
12071
12122
  const NO_NOTE = "no note";
12072
- const noteRows$1 = (state, stepIndex, room) => {
12073
- const lines = wrapped(state.steps[stepIndex]?.note ?? "", room);
12123
+ const noteRows$1 = (state, layerIndex, room) => {
12124
+ const lines = wrapped(state.layers[layerIndex]?.note ?? "", room);
12074
12125
  return (lines.length === 0 ? [NO_NOTE] : lines).map((text) => ({
12075
- index: stepIndex,
12126
+ index: layerIndex,
12076
12127
  kind: "note",
12077
12128
  text,
12078
12129
  lead: false
12079
12130
  }));
12080
12131
  };
12081
- const titleRows = (state, stepIndex, room) => wrapped(state.steps[stepIndex]?.title ?? "", room).map((text, at) => ({
12082
- index: stepIndex,
12132
+ const titleRows = (state, layerIndex, room) => wrapped(state.layers[layerIndex]?.title ?? "", room).map((text, at) => ({
12133
+ index: layerIndex,
12083
12134
  kind: "title",
12084
12135
  text,
12085
12136
  lead: at === 0
12086
12137
  }));
12087
- 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));
12088
- 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) => {
12089
12161
  if (rows.length <= height) return {
12090
12162
  rows,
12091
12163
  more: 0
12092
12164
  };
12093
- const first = Math.max(0, rows.findIndex((row) => row.index === stepIndex));
12094
- 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;
12095
12167
  const wanted = block >= height ? first : first - Math.floor((height - block) / 2);
12096
12168
  const start = Math.max(0, Math.min(rows.length - height, wanted));
12097
12169
  return {
@@ -12180,7 +12252,7 @@ const CONTEXT_STEPS = [
12180
12252
  60,
12181
12253
  WHOLE_FILE
12182
12254
  ];
12183
- const stepContext = (current, delta) => {
12255
+ const layerContext = (current, delta) => {
12184
12256
  const at = CONTEXT_STEPS.indexOf(current);
12185
12257
  const next = Math.max(0, Math.min(CONTEXT_STEPS.length - 1, (at === -1 ? 0 : at) + delta));
12186
12258
  return CONTEXT_STEPS[next] ?? current;
@@ -12221,8 +12293,8 @@ const nextUnreviewed = (state, from) => {
12221
12293
  return [...order.slice(start + 1), ...order.slice(0, start + 1)].find((index) => !isReviewed(state, index));
12222
12294
  };
12223
12295
  const reviewedCount = (state) => `${state.vouched.length}/${state.patches.length} reviewed`;
12224
- const fileOrder = (state) => onSteps(state) ? stepFiles(state, state.stepIndex) : treeRows(state).flatMap((row) => row.fileIndex === void 0 ? [] : [row.fileIndex]);
12225
- 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) => {
12226
12298
  const order = fileOrder(state);
12227
12299
  const position = order.indexOf(state.patchIndex);
12228
12300
  if (position === -1) return order[0] ?? state.patchIndex;
@@ -12293,6 +12365,7 @@ const command = (input) => ({
12293
12365
  hint: "",
12294
12366
  listed: true,
12295
12367
  whenStaged: false,
12368
+ whenLayers: false,
12296
12369
  ...input
12297
12370
  });
12298
12371
  const commands = [
@@ -12426,21 +12499,23 @@ const commands = [
12426
12499
  }),
12427
12500
  command({
12428
12501
  action: "rail.toggle",
12429
- title: "Switch between steps and files",
12502
+ title: "Switch between layers and files",
12430
12503
  category: "Files",
12431
12504
  keys: ["s"],
12432
- screens: ["review"]
12505
+ screens: ["review"],
12506
+ hint: "layers",
12507
+ whenLayers: true
12433
12508
  }),
12434
12509
  command({
12435
12510
  action: "tree.collapse",
12436
- title: "Close the folder, step, or gap",
12511
+ title: "Close the folder, layer, or gap",
12437
12512
  category: "Files",
12438
12513
  keys: ["h"],
12439
12514
  screens: ["review"]
12440
12515
  }),
12441
12516
  command({
12442
12517
  action: "tree.expand",
12443
- title: "Open the folder, step, or gap",
12518
+ title: "Open the folder, layer, or gap",
12444
12519
  category: "Files",
12445
12520
  keys: ["l"],
12446
12521
  screens: ["review"]
@@ -12611,7 +12686,7 @@ const displayKey = (key) => {
12611
12686
  if (key.startsWith("ctrl+")) return `^${key.slice(5)}`;
12612
12687
  return GLYPHS[key] ?? key;
12613
12688
  };
12614
- 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) => ({
12615
12690
  key: displayKey(entry.keys[0] ?? ""),
12616
12691
  hint: entry.hint,
12617
12692
  press: entry.keys[0] ?? ""
@@ -12672,7 +12747,7 @@ const atRow = (state, row) => withCursorVisible({
12672
12747
  ...state,
12673
12748
  cursor: clamp(row, 0, lastRow(selectedPatch(state)))
12674
12749
  });
12675
- const stepHunk = (state, delta) => {
12750
+ const layerHunk = (state, delta) => {
12676
12751
  const starts = hunkStarts(state);
12677
12752
  const target = delta > 0 ? starts.find((start) => start > state.cursor) : starts.findLast((start) => start < state.cursor);
12678
12753
  return target === void 0 ? state : atRow(state, target);
@@ -12695,7 +12770,7 @@ const atComment = (state, file, delta) => {
12695
12770
  const landing = delta > 0 ? rows[0] : rows.at(-1);
12696
12771
  return landing === void 0 ? moved : atRow(moved, landing);
12697
12772
  };
12698
- const stepComment = (state, delta) => {
12773
+ const layerComment = (state, delta) => {
12699
12774
  const here = commentRowsIn(state, state.patchIndex);
12700
12775
  const target = delta > 0 ? here.find((row) => row > state.cursor) : here.findLast((row) => row < state.cursor);
12701
12776
  if (target !== void 0) return atRow(state, target);
@@ -12707,13 +12782,13 @@ const movePending = (state, delta) => ({
12707
12782
  ...state,
12708
12783
  pendingIndex: clamp(state.pendingIndex + delta, 0, Math.max(0, state.pending.length - 1))
12709
12784
  });
12710
- const moveStep = (state, delta) => {
12711
- 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));
12712
12787
  const landed = {
12713
12788
  ...state,
12714
- stepIndex
12789
+ layerIndex
12715
12790
  };
12716
- const patchIndex = stepFiles(landed, stepIndex)[0] ?? landed.patchIndex;
12791
+ const patchIndex = layerFiles(landed, layerIndex)[0] ?? landed.patchIndex;
12717
12792
  return {
12718
12793
  ...landed,
12719
12794
  patchIndex,
@@ -12723,18 +12798,18 @@ const moveStep = (state, delta) => {
12723
12798
  selecting: false
12724
12799
  };
12725
12800
  };
12726
- const inRail = (state, delta) => onSteps(state) ? moveStep(state, delta) : moveFile(state, delta);
12727
- 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);
12728
12803
  const toggleRail = (state) => {
12729
- if (state.steps.length === 0) return withNotice(state, "no story for this branch");
12730
- 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 {
12731
12806
  ...state,
12732
12807
  rail: "tree"
12733
12808
  };
12734
12809
  return {
12735
12810
  ...state,
12736
- rail: "steps",
12737
- stepIndex: stepHolding(state, state.patchIndex)
12811
+ rail: "layers",
12812
+ layerIndex: layerHolding(state, state.patchIndex)
12738
12813
  };
12739
12814
  };
12740
12815
  const foldDirectory = (state, shut) => {
@@ -12746,21 +12821,21 @@ const foldDirectory = (state, shut) => {
12746
12821
  closed: shut ? [...closed, directory] : closed
12747
12822
  };
12748
12823
  };
12749
- const foldStep = (state, shut) => {
12750
- const open = state.openSteps.filter((index) => index !== state.stepIndex);
12824
+ const foldLayer = (state, shut) => {
12825
+ const open = state.openLayers.filter((index) => index !== state.layerIndex);
12751
12826
  return {
12752
12827
  ...state,
12753
- openSteps: shut ? open : [...open, state.stepIndex]
12828
+ openLayers: shut ? open : [...open, state.layerIndex]
12754
12829
  };
12755
12830
  };
12756
- 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);
12757
12832
  const moveBranch = (state, delta) => ({
12758
12833
  ...state,
12759
12834
  branchIndex: clamp(state.branchIndex + delta, 0, Math.max(0, state.branches.length - 1))
12760
12835
  });
12761
12836
  const moveFile = (state, delta) => ({
12762
12837
  ...state,
12763
- patchIndex: stepFile(state, delta),
12838
+ patchIndex: layerFile(state, delta),
12764
12839
  top: 0,
12765
12840
  cursor: 0,
12766
12841
  anchorRow: 0,
@@ -12825,18 +12900,18 @@ const transitions = {
12825
12900
  "branch.next": (state) => moveBranch(state, 1),
12826
12901
  "branch.prev": (state) => moveBranch(state, -1),
12827
12902
  "branch.open": (state) => state,
12828
- "cursor.next": (state) => stepDown(state, 1),
12903
+ "cursor.next": (state) => layerDown(state, 1),
12829
12904
  "cursor.top": (state) => atRow(state, 0),
12830
12905
  "cursor.bottom": (state) => atRow(state, lastRow(selectedPatch(state))),
12831
12906
  "cursor.pageDown": (state) => moveCursor(state, Math.max(1, Math.floor(state.viewport / 2))),
12832
12907
  "cursor.pageUp": (state) => moveCursor(state, -Math.max(1, Math.floor(state.viewport / 2))),
12833
12908
  "context.more": (state) => state,
12834
12909
  "context.less": (state) => state,
12835
- "comment.next": (state) => stepComment(state, 1),
12836
- "comment.prev": (state) => stepComment(state, -1),
12837
- "hunk.next": (state) => stepHunk(state, 1),
12838
- "hunk.prev": (state) => stepHunk(state, -1),
12839
- "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),
12840
12915
  "file.next": (state) => moveFile(state, 1),
12841
12916
  "file.prev": (state) => moveFile(state, -1),
12842
12917
  "select.start": startSelection,
@@ -12935,20 +13010,20 @@ const withSent = (state, sent) => ({
12935
13010
  ...state,
12936
13011
  sent
12937
13012
  });
12938
- const withStory = (state, told) => {
12939
- const steps = told.steps;
13013
+ const withLayers = (state, told) => {
13014
+ const layers = told.layers;
12940
13015
  const opened = {
12941
13016
  ...state,
12942
- steps,
12943
- storyStale: told.stale,
12944
- stepIndex: 0,
12945
- openSteps: [],
12946
- rail: steps.length === 0 ? "tree" : "steps"
13017
+ layers,
13018
+ layersStale: told.stale,
13019
+ layerIndex: 0,
13020
+ openLayers: [],
13021
+ rail: layers.length === 0 ? "tree" : "layers"
12947
13022
  };
12948
- if (steps.length === 0) return opened;
13023
+ if (layers.length === 0) return opened;
12949
13024
  return {
12950
13025
  ...opened,
12951
- patchIndex: stepFiles(opened, 0)[0] ?? opened.patchIndex,
13026
+ patchIndex: layerFiles(opened, 0)[0] ?? opened.patchIndex,
12952
13027
  cursor: 0,
12953
13028
  top: 0
12954
13029
  };
@@ -13276,8 +13351,10 @@ var DiffView = class {
13276
13351
  }
13277
13352
  listenTo(handlers) {
13278
13353
  this.numbers.onMouseScroll = (event) => {
13354
+ const way = event.scroll?.direction;
13355
+ if (way !== "up" && way !== "down") return;
13279
13356
  const size = Math.max(1, event.scroll?.delta ?? 1) * SCROLL_ROWS;
13280
- handlers.scroll(event.scroll?.direction === "up" ? -size : size);
13357
+ handlers.scroll(way === "up" ? -size : size);
13281
13358
  };
13282
13359
  this.numbers.onMouseDown = (event) => handlers.down(event.y);
13283
13360
  this.numbers.onMouseDrag = (event) => handlers.drag(event.y);
@@ -13744,24 +13821,34 @@ const shortPath = (path) => {
13744
13821
  const home = process.env["HOME"] ?? "";
13745
13822
  return home.length > 0 && path.startsWith(home) ? `~${path.slice(home.length)}` : path;
13746
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
+ };
13747
13834
  const contextLabel = (context) => {
13748
13835
  if (context === 3) return "";
13749
13836
  return context >= 1e5 ? "whole file" : `±${context}`;
13750
13837
  };
13751
13838
  const nameRoom = (pane) => Math.max(BRANCH_NAME_MIN, Math.min(BRANCH_NAME, pane - BRANCH_TAIL));
13752
- const columns = (cells, room) => `${clip(cells.name, room).padEnd(room)}${cells.files.padStart(5)}${cells.added.padStart(8)}${cells.gone.padStart(8)} ${cells.story.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}`;
13753
13840
  const branchHeading = (room) => ` ${columns({
13754
13841
  name: "WORKTREE",
13755
13842
  files: "FILES",
13756
13843
  added: "+",
13757
13844
  gone: "-",
13758
- story: "STORY",
13845
+ layers: "LAYERS",
13759
13846
  state: "STATE"
13760
13847
  }, room)}`;
13761
13848
  const atHome = (state) => state.screen === "branches" || state.screen === "palette" && state.returnTo === "branches";
13762
- const storyCell = (branch) => {
13763
- if (branch.steps === 0) return "";
13764
- return branch.stale ? `${branch.steps} stale` : `${branch.steps} story`;
13849
+ const layersCell = (branch) => {
13850
+ if (branch.layers === 0) return "";
13851
+ return branch.stale ? `${branch.layers} stale` : `${branch.layers} layers`;
13765
13852
  };
13766
13853
  const branchCells = (branch, here, room) => ({
13767
13854
  lead: `${here ? marks().cursor : " "} `,
@@ -13769,7 +13856,7 @@ const branchCells = (branch, here, room) => ({
13769
13856
  files: `${branch.files}`.padStart(5),
13770
13857
  added: `+${branch.added}`.padStart(8),
13771
13858
  gone: `-${branch.removed}`.padStart(8),
13772
- story: storyCell(branch),
13859
+ layers: layersCell(branch),
13773
13860
  state: waitingLabel(branch).trim()
13774
13861
  });
13775
13862
  const headerParts = (state, branch, path) => [
@@ -13802,30 +13889,32 @@ const STEP_NUMBER = 3;
13802
13889
  const STEP_LEAD = 8;
13803
13890
  const NOTE_LEAD = 10;
13804
13891
  const STEP_GAP = 1;
13805
- const stepRoom = (state, pane) => {
13806
- 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));
13807
13894
  return {
13808
13895
  title: Math.max(4, pane - PANE_CHROME - STEP_LEAD - STEP_GAP - tally),
13809
13896
  note: Math.max(4, pane - PANE_CHROME - NOTE_LEAD),
13810
13897
  tally
13811
13898
  };
13812
13899
  };
13813
- const stepFold = (state, index) => {
13814
- if (stepOpen(state, index)) return "▾";
13815
- 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 ? " " : "▸";
13816
13903
  };
13817
- const stepHead = (state, row) => {
13904
+ const layerHead = (state, row) => {
13818
13905
  if (!row.lead) return " ".repeat(STEP_LEAD);
13819
- 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)} `;
13820
13907
  };
13821
- const stepText = (state, row, room) => {
13908
+ const layerText = (state, row, room) => {
13909
+ if (row.kind === "file") return `${" ".repeat(NOTE_LEAD)}${marks().file} ${row.text}`;
13822
13910
  if (row.kind === "note") return `${" ".repeat(NOTE_LEAD)}${row.text}`;
13823
- const tail = (row.lead ? `${state.steps[row.index]?.files.length ?? 0}` : "").padStart(room.tally + STEP_GAP);
13824
- 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}`;
13825
13913
  };
13826
- const stepPaint = (state, row) => {
13914
+ const layerPaint = (state, row) => {
13915
+ if (row.kind === "file") return palette.ink;
13827
13916
  if (row.kind === "note") return palette.faint;
13828
- return row.index === state.stepIndex ? palette.ink : palette.muted;
13917
+ return row.index === state.layerIndex ? palette.ink : palette.muted;
13829
13918
  };
13830
13919
  var Screen = class {
13831
13920
  header;
@@ -13929,12 +14018,14 @@ var Screen = class {
13929
14018
  }
13930
14019
  update(state) {
13931
14020
  this.shown = state;
13932
- this.chips = hintsFor(state.screen, state.staged);
14021
+ this.chips = hintsFor(state.screen, state.staged, state.layers.length);
13933
14022
  this.header.content = this.headerText(state);
13934
14023
  this.footer.content = this.footerText(state);
13935
14024
  this.list.content = this.listText(state);
13936
14025
  const many = state.branches.length === 1 ? "1 worktree" : `${state.branches.length} worktrees`;
13937
- 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}`;
13938
14029
  this.landingKeys.content = this.chipRow();
13939
14030
  this.diffPane.visible = state.screen !== "branches" && !(state.screen === "palette" && state.returnTo === "branches");
13940
14031
  if (this.diffPane.visible) this.paintDiff(state);
@@ -13991,7 +14082,7 @@ var Screen = class {
13991
14082
  }
13992
14083
  listText(state) {
13993
14084
  if (atHome(state)) return this.branchTable(state);
13994
- if (onSteps(state)) return this.stepRail(state);
14085
+ if (onLayers(state)) return this.layerRail(state);
13995
14086
  const height = Math.max(1, this.listPane.height - 1);
13996
14087
  const pane = this.paneRoom();
13997
14088
  const window = treeWindow(state, height);
@@ -13999,13 +14090,13 @@ var Screen = class {
13999
14090
  const more = window.more > 0 ? [fg(palette.faint)(` … ${window.more} more`)] : [];
14000
14091
  return new StyledText([...rows, ...more]);
14001
14092
  }
14002
- stepRail(state) {
14093
+ layerRail(state) {
14003
14094
  const height = Math.max(1, this.listPane.height - 1);
14004
- const room = stepRoom(state, this.paneRoom());
14005
- const window = railWindow(stepRows(state, room.title, room.note), height, state.stepIndex);
14006
- 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`));
14007
14098
  const more = window.more > 0 ? [fg(palette.faint)(` … ${window.more} more`)] : [];
14008
- const warn = state.storyStale ? [fg(palette.attention)(` stale, the branch moved on\n\n`)] : [];
14099
+ const warn = state.layersStale ? [fg(palette.attention)(` stale, the branch moved on\n\n`)] : [];
14009
14100
  return new StyledText([
14010
14101
  ...warn,
14011
14102
  ...rows,
@@ -14101,7 +14192,7 @@ var Screen = class {
14101
14192
  fg(palette.faint)(cells.files),
14102
14193
  fg(palette.added)(cells.added),
14103
14194
  fg(palette.removed)(cells.gone),
14104
- fg(palette.accent)(` ${cells.story.padStart(8)}`),
14195
+ fg(palette.accent)(` ${cells.layers.padStart(8)}`),
14105
14196
  fg(palette.attention)(` ${cells.state}\n`)
14106
14197
  ];
14107
14198
  });
@@ -14122,8 +14213,14 @@ var Screen = class {
14122
14213
  }
14123
14214
  chipRow() {
14124
14215
  return new StyledText(this.chips.flatMap((chip, index) => {
14125
- const paint = index === this.hovered ? bg(palette.cursor) : fg(palette.faint);
14126
- 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
+ ];
14127
14224
  }));
14128
14225
  }
14129
14226
  paintPane(state) {
@@ -14465,10 +14562,10 @@ var App = class {
14465
14562
  const patches = await this.run(listPatches(this.repo, branch.branch));
14466
14563
  const progress = await this.run(reviewProgress(this.repo, branch.branch));
14467
14564
  const pending = await this.run(listPending(this.repo, branch.branch));
14468
- const steps = await this.run(listStorySteps(this.repo, branch.branch));
14565
+ const layers = await this.run(listLayers(this.repo, branch.branch));
14469
14566
  const opened = withVouched(withPatches(this.state, patches), progress.vouched);
14470
14567
  const sent = await this.loadSent(branch.branch);
14471
- this.commit(withStory(withSent(withPending(opened, pending, "review"), sent), steps));
14568
+ this.commit(withLayers(withSent(withPending(opened, pending, "review"), sent), layers));
14472
14569
  await this.loadSource();
14473
14570
  }
14474
14571
  async goBack() {
@@ -14546,7 +14643,7 @@ var App = class {
14546
14643
  }
14547
14644
  async expand(delta) {
14548
14645
  const branch = selectedBranch(this.state);
14549
- const next = stepContext(this.state.context, delta);
14646
+ const next = layerContext(this.state.context, delta);
14550
14647
  if (branch === void 0 || next === this.state.context) return;
14551
14648
  const line = sourceLineAt(this.state, this.state.cursor);
14552
14649
  const patches = await this.run(listPatches(this.repo, branch.branch, next));
@@ -14715,7 +14812,7 @@ const reviewStatus = fn("Main.reviewStatus")(function* (options) {
14715
14812
  const documentAt = fn("Main.documentAt")(function* (source) {
14716
14813
  return yield* tryPromise({
14717
14814
  try: () => source === "-" ? text(process.stdin) : readFile(source, "utf8"),
14718
- catch: (cause) => new MalformedStory({ reason: String(cause) })
14815
+ catch: (cause) => new MalformedLayers({ reason: String(cause) })
14719
14816
  });
14720
14817
  });
14721
14818
  const routes = {
@@ -14725,14 +14822,14 @@ const routes = {
14725
14822
  "comment take": commentTake,
14726
14823
  "review submit": reviewSubmit,
14727
14824
  "review progress": reviewStatus,
14728
- "story set": fn("Main.storySet")(function* (options) {
14825
+ "layers set": fn("Main.layersSet")(function* (options) {
14729
14826
  const document = yield* documentAt(yield* required(options, "json"));
14730
- const story = yield* setStory(yield* required(options, "worktree"), document, options["at"] ?? (/* @__PURE__ */ new Date()).toISOString());
14731
- 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 });
14732
14829
  }),
14733
- "story show": fn("Main.storyShow")(function* (options) {
14734
- const story = yield* showStory(yield* required(options, "worktree"));
14735
- 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 });
14736
14833
  }),
14737
14834
  describe: fn("Main.describe")(function* (options) {
14738
14835
  const wanted = options["command"];
@@ -14761,6 +14858,25 @@ const nameOf = (argv) => {
14761
14858
  return findCommand(pair) === void 0 ? words[0] ?? "" : pair;
14762
14859
  };
14763
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
+ }
14764
14880
  const layer = mergeAll(GitLive, storeAt(process.env["ADIFF_ROOT"] ?? defaultRoot()));
14765
14881
  const exit = await runPromiseExit(run(nameOf(argv), optionsFrom(argv)).pipe(provide(layer)));
14766
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.5",
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