@eliya-oss/agent-diff 0.1.0-alpha.2 → 0.1.0-alpha.20
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.
- package/.agents/prd/README.md +2 -2
- package/CHANGELOG.md +124 -0
- package/README.md +23 -10
- package/bin/adiff.js +76 -2
- package/dist/main.js +2862 -407
- package/package.json +6 -4
- package/skills/adiff/SKILL.md +67 -18
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, mkdirSync, readFileSync, watch } 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
|
/**
|
|
@@ -456,6 +458,38 @@ function isNumber(input) {
|
|
|
456
458
|
return typeof input === "number";
|
|
457
459
|
}
|
|
458
460
|
/**
|
|
461
|
+
* Checks whether a value is a `boolean`.
|
|
462
|
+
*
|
|
463
|
+
* **When to use**
|
|
464
|
+
*
|
|
465
|
+
* Use when you need a `Predicate` guard to narrow an `unknown` value to a
|
|
466
|
+
* boolean.
|
|
467
|
+
*
|
|
468
|
+
* **Details**
|
|
469
|
+
*
|
|
470
|
+
* Uses `typeof input === "boolean"`.
|
|
471
|
+
*
|
|
472
|
+
* **Example** (Guarding booleans)
|
|
473
|
+
*
|
|
474
|
+
* ```ts
|
|
475
|
+
* import { Predicate } from "effect"
|
|
476
|
+
*
|
|
477
|
+
* const data: unknown = true
|
|
478
|
+
*
|
|
479
|
+
* if (Predicate.isBoolean(data)) {
|
|
480
|
+
* console.log(data ? "yes" : "no")
|
|
481
|
+
* }
|
|
482
|
+
* ```
|
|
483
|
+
*
|
|
484
|
+
* @see {@link isString}
|
|
485
|
+
* @see {@link isNumber}
|
|
486
|
+
* @category guards
|
|
487
|
+
* @since 2.0.0
|
|
488
|
+
*/
|
|
489
|
+
function isBoolean(input) {
|
|
490
|
+
return typeof input === "boolean";
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
459
493
|
* Checks whether a value is a `function`.
|
|
460
494
|
*
|
|
461
495
|
* **When to use**
|
|
@@ -487,6 +521,38 @@ function isFunction(input) {
|
|
|
487
521
|
return typeof input === "function";
|
|
488
522
|
}
|
|
489
523
|
/**
|
|
524
|
+
* Checks whether a value is not `null` and not `undefined`.
|
|
525
|
+
*
|
|
526
|
+
* **When to use**
|
|
527
|
+
*
|
|
528
|
+
* Use when you need a `Predicate` refinement that filters out nullish values
|
|
529
|
+
* but keeps other falsy ones.
|
|
530
|
+
*
|
|
531
|
+
* **Details**
|
|
532
|
+
*
|
|
533
|
+
* Uses `input != null`.
|
|
534
|
+
*
|
|
535
|
+
* **Example** (Filtering non-nullish values)
|
|
536
|
+
*
|
|
537
|
+
* ```ts
|
|
538
|
+
* import { Predicate } from "effect"
|
|
539
|
+
*
|
|
540
|
+
* const values = [0, null, "", undefined]
|
|
541
|
+
* const present = values.filter(Predicate.isNotNullish)
|
|
542
|
+
*
|
|
543
|
+
* console.log(present)
|
|
544
|
+
* ```
|
|
545
|
+
*
|
|
546
|
+
* @see {@link isNullish}
|
|
547
|
+
* @see {@link isNotNull}
|
|
548
|
+
* @see {@link isNotUndefined}
|
|
549
|
+
* @category guards
|
|
550
|
+
* @since 4.0.0
|
|
551
|
+
*/
|
|
552
|
+
function isNotNullish(input) {
|
|
553
|
+
return input != null;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
490
556
|
* Checks whether a value is an `object` in the JavaScript sense (objects, arrays, functions).
|
|
491
557
|
*
|
|
492
558
|
* **When to use**
|
|
@@ -5435,8 +5501,22 @@ const failCauseSync$1 = (evaluate) => suspend(() => failCause$1(internalCall(eva
|
|
|
5435
5501
|
/** @internal */
|
|
5436
5502
|
const die = (defect) => exitDie(defect);
|
|
5437
5503
|
/** @internal */
|
|
5504
|
+
const failSync = (error) => suspend(() => fail$2(internalCall(error)));
|
|
5505
|
+
/** @internal */
|
|
5438
5506
|
const void_$2 = /*#__PURE__*/ succeed$2(void 0);
|
|
5439
5507
|
/** @internal */
|
|
5508
|
+
const try_$1 = (options) => {
|
|
5509
|
+
const evaluate = typeof options === "function" ? options : options.try;
|
|
5510
|
+
const catcher = typeof options === "function" ? (cause) => new UnknownError(cause, "An error occurred in Effect.try") : options.catch;
|
|
5511
|
+
return suspend(() => {
|
|
5512
|
+
try {
|
|
5513
|
+
return succeed$2(internalCall(evaluate));
|
|
5514
|
+
} catch (err) {
|
|
5515
|
+
return fail$2(internalCall(() => catcher(err)));
|
|
5516
|
+
}
|
|
5517
|
+
});
|
|
5518
|
+
};
|
|
5519
|
+
/** @internal */
|
|
5440
5520
|
const promise$1 = (evaluate) => callbackOptions(function(resume, signal) {
|
|
5441
5521
|
internalCall(() => evaluate(signal)).then((a) => resume(succeed$2(a)), (e) => resume(die(e)));
|
|
5442
5522
|
}, evaluate.length !== 0);
|
|
@@ -5555,6 +5635,40 @@ const makeFn = (name, bodyOrOptions, defError, pipeables, addSpan, spanOptions)
|
|
|
5555
5635
|
}));
|
|
5556
5636
|
});
|
|
5557
5637
|
};
|
|
5638
|
+
/** @internal */
|
|
5639
|
+
const fnUntracedEager$1 = (body, ...pipeables) => defineFunctionLength(body.length, pipeables.length === 0 ? function() {
|
|
5640
|
+
return fromIteratorEagerUnsafe(() => body.apply(this, arguments));
|
|
5641
|
+
} : function() {
|
|
5642
|
+
let effect = fromIteratorEagerUnsafe(() => body.apply(this, arguments));
|
|
5643
|
+
for (const pipeable of pipeables) effect = pipeable(effect);
|
|
5644
|
+
return effect;
|
|
5645
|
+
});
|
|
5646
|
+
const fromIteratorEagerUnsafe = (evaluate) => {
|
|
5647
|
+
try {
|
|
5648
|
+
const iterator = evaluate();
|
|
5649
|
+
let value = void 0;
|
|
5650
|
+
while (true) {
|
|
5651
|
+
const state = iterator.next(value);
|
|
5652
|
+
if (state.done) return succeed$2(state.value);
|
|
5653
|
+
const primitive = state.value;
|
|
5654
|
+
if (primitive && primitive._tag === "Success") {
|
|
5655
|
+
value = primitive.value;
|
|
5656
|
+
continue;
|
|
5657
|
+
} else if (primitive && primitive._tag === "Failure") return state.value;
|
|
5658
|
+
else {
|
|
5659
|
+
let isFirstExecution = true;
|
|
5660
|
+
return suspend(() => {
|
|
5661
|
+
if (isFirstExecution) {
|
|
5662
|
+
isFirstExecution = false;
|
|
5663
|
+
return flatMap$1(state.value, (value) => fromIteratorUnsafe(iterator, value));
|
|
5664
|
+
} else return suspend(() => fromIteratorUnsafe(evaluate()));
|
|
5665
|
+
});
|
|
5666
|
+
}
|
|
5667
|
+
}
|
|
5668
|
+
} catch (error) {
|
|
5669
|
+
return die(error);
|
|
5670
|
+
}
|
|
5671
|
+
};
|
|
5558
5672
|
const fromIteratorUnsafe = /*#__PURE__*/ makePrimitive({
|
|
5559
5673
|
op: "Iterator",
|
|
5560
5674
|
single: false,
|
|
@@ -5671,6 +5785,13 @@ const OnFailureProto = /*#__PURE__*/ makePrimitiveProto({
|
|
|
5671
5785
|
}
|
|
5672
5786
|
});
|
|
5673
5787
|
/** @internal */
|
|
5788
|
+
const catchCauseFilter = /*#__PURE__*/ dual(3, (self, filter, f) => catchCause$1(self, (cause) => {
|
|
5789
|
+
const eb = filter(cause);
|
|
5790
|
+
return isFailure$1(eb) ? failCause$1(eb.failure) : internalCall(() => f(eb.success, cause));
|
|
5791
|
+
}));
|
|
5792
|
+
/** @internal */
|
|
5793
|
+
const catch_ = /*#__PURE__*/ dual(2, (self, f) => catchCauseFilter(self, findError, (e) => f(e)));
|
|
5794
|
+
/** @internal */
|
|
5674
5795
|
const catchIf = /*#__PURE__*/ dual((args) => isEffect(args[0]), (self, predicate, f, orElse) => catchCause$1(self, (cause) => {
|
|
5675
5796
|
const error = findError(cause);
|
|
5676
5797
|
if (isFailure$1(error)) return failCause$1(error.failure);
|
|
@@ -5683,6 +5804,8 @@ const catchTag$1 = /*#__PURE__*/ dual((args) => isEffect(args[0]), (self, k, f,
|
|
|
5683
5804
|
return catchIf(self, pred, f, orElse);
|
|
5684
5805
|
});
|
|
5685
5806
|
/** @internal */
|
|
5807
|
+
const mapError$1 = /*#__PURE__*/ dual(2, (self, f) => catch_(self, (error) => failSync(() => f(error))));
|
|
5808
|
+
/** @internal */
|
|
5686
5809
|
const exit$2 = (self) => effectIsExit(self) ? exitSucceed(self) : exitPrimitive(self);
|
|
5687
5810
|
const exitPrimitive = /*#__PURE__*/ makePrimitive({
|
|
5688
5811
|
op: "Exit",
|
|
@@ -6344,6 +6467,39 @@ const map$1 = causeMap;
|
|
|
6344
6467
|
const squash = causeSquash;
|
|
6345
6468
|
Service()("effect/Cause/StackTrace");
|
|
6346
6469
|
Service()("effect/Cause/InterruptorStackTrace");
|
|
6470
|
+
//#endregion
|
|
6471
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/Exit.js
|
|
6472
|
+
/**
|
|
6473
|
+
* Creates a failed Exit from a Cause.
|
|
6474
|
+
*
|
|
6475
|
+
* **When to use**
|
|
6476
|
+
*
|
|
6477
|
+
* Use when you already have a `Cause<E>` and want to wrap it in an Exit
|
|
6478
|
+
* for advanced error handling where you need full control over the Cause
|
|
6479
|
+
* structure.
|
|
6480
|
+
*
|
|
6481
|
+
* **Details**
|
|
6482
|
+
*
|
|
6483
|
+
* Returns a `Failure<never, E>`. If you only have an error value, use
|
|
6484
|
+
* {@link fail} instead.
|
|
6485
|
+
*
|
|
6486
|
+
* **Example** (Creating a failed Exit from a Cause)
|
|
6487
|
+
*
|
|
6488
|
+
* ```ts
|
|
6489
|
+
* import { Cause, Exit } from "effect"
|
|
6490
|
+
*
|
|
6491
|
+
* const cause = Cause.fail("Something went wrong")
|
|
6492
|
+
* const exit = Exit.failCause(cause)
|
|
6493
|
+
* console.log(Exit.isFailure(exit)) // true
|
|
6494
|
+
* ```
|
|
6495
|
+
*
|
|
6496
|
+
* @see {@link fail} to create a Failure from a plain error value
|
|
6497
|
+
* @see {@link die} to create a Failure from a defect
|
|
6498
|
+
*
|
|
6499
|
+
* @category constructors
|
|
6500
|
+
* @since 2.0.0
|
|
6501
|
+
*/
|
|
6502
|
+
const failCause = exitFailCause;
|
|
6347
6503
|
/**
|
|
6348
6504
|
* Creates a failed Exit from a typed error value.
|
|
6349
6505
|
*
|
|
@@ -7448,6 +7604,7 @@ const fail = fail$2;
|
|
|
7448
7604
|
* @since 2.0.0
|
|
7449
7605
|
*/
|
|
7450
7606
|
const failCauseSync = failCauseSync$1;
|
|
7607
|
+
const try_ = try_$1;
|
|
7451
7608
|
/**
|
|
7452
7609
|
* Chains effects to produce new `Effect` instances, useful for combining
|
|
7453
7610
|
* operations that depend on previous results.
|
|
@@ -7516,6 +7673,49 @@ const failCauseSync = failCauseSync$1;
|
|
|
7516
7673
|
*/
|
|
7517
7674
|
const flatMap = flatMap$1;
|
|
7518
7675
|
/**
|
|
7676
|
+
* Transforms an effect to encapsulate both failure and success using the `Exit`
|
|
7677
|
+
* data type.
|
|
7678
|
+
*
|
|
7679
|
+
* **When to use**
|
|
7680
|
+
*
|
|
7681
|
+
* Use when you need to inspect the full outcome, including typed failures, defects,
|
|
7682
|
+
* and interruptions.
|
|
7683
|
+
*
|
|
7684
|
+
* **Details**
|
|
7685
|
+
*
|
|
7686
|
+
* `exit` wraps an effect's success or failure inside an `Exit` type, allowing
|
|
7687
|
+
* you to handle both cases explicitly.
|
|
7688
|
+
*
|
|
7689
|
+
* The resulting effect cannot fail because the failure is encapsulated within
|
|
7690
|
+
* the `Exit.Failure` type. The error type is set to `never`, indicating that
|
|
7691
|
+
* the effect is structured to never fail directly.
|
|
7692
|
+
*
|
|
7693
|
+
* **Example** (Capturing completion as Exit)
|
|
7694
|
+
*
|
|
7695
|
+
* ```ts
|
|
7696
|
+
* import { Effect } from "effect"
|
|
7697
|
+
*
|
|
7698
|
+
* const success = Effect.succeed(42)
|
|
7699
|
+
* const failure = Effect.fail("Something went wrong")
|
|
7700
|
+
*
|
|
7701
|
+
* const program1 = Effect.exit(success)
|
|
7702
|
+
* const program2 = Effect.exit(failure)
|
|
7703
|
+
*
|
|
7704
|
+
* Effect.runPromise(program1).then(console.log)
|
|
7705
|
+
* // { _id: 'Exit', _tag: 'Success', value: 42 }
|
|
7706
|
+
*
|
|
7707
|
+
* Effect.runPromise(program2).then(console.log)
|
|
7708
|
+
* // { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Something went wrong' } }
|
|
7709
|
+
* ```
|
|
7710
|
+
*
|
|
7711
|
+
* @see {@link option} for a version that uses `Option` instead.
|
|
7712
|
+
* @see {@link result} for a version that uses `Result` instead.
|
|
7713
|
+
*
|
|
7714
|
+
* @category outcome encapsulation
|
|
7715
|
+
* @since 2.0.0
|
|
7716
|
+
*/
|
|
7717
|
+
const exit$1 = exit$2;
|
|
7718
|
+
/**
|
|
7519
7719
|
* Transforms the value inside an effect by applying a function to it.
|
|
7520
7720
|
*
|
|
7521
7721
|
* **When to use**
|
|
@@ -7658,6 +7858,45 @@ const catchTag = catchTag$1;
|
|
|
7658
7858
|
*/
|
|
7659
7859
|
const catchCause = catchCause$1;
|
|
7660
7860
|
/**
|
|
7861
|
+
* Transforms the failure value of an effect without changing its success value.
|
|
7862
|
+
*
|
|
7863
|
+
* **When to use**
|
|
7864
|
+
*
|
|
7865
|
+
* Use to translate an `Effect`'s typed failures while leaving successful values
|
|
7866
|
+
* unchanged.
|
|
7867
|
+
*
|
|
7868
|
+
* **Details**
|
|
7869
|
+
*
|
|
7870
|
+
* Only the failure channel is transformed. The success channel and requirements
|
|
7871
|
+
* are preserved.
|
|
7872
|
+
*
|
|
7873
|
+
* **Example** (Transforming the error channel)
|
|
7874
|
+
*
|
|
7875
|
+
* ```ts
|
|
7876
|
+
* import { Data, Effect } from "effect"
|
|
7877
|
+
*
|
|
7878
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
7879
|
+
*
|
|
7880
|
+
* // ┌─── Effect<number, string, never>
|
|
7881
|
+
* // ▼
|
|
7882
|
+
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
7883
|
+
*
|
|
7884
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
7885
|
+
* // ▼
|
|
7886
|
+
* const mapped = Effect.mapError(
|
|
7887
|
+
* simulatedTask,
|
|
7888
|
+
* (message) => new TaskError({ message })
|
|
7889
|
+
* )
|
|
7890
|
+
* ```
|
|
7891
|
+
*
|
|
7892
|
+
* @see {@link map} for a version that operates on the success channel.
|
|
7893
|
+
* @see {@link mapBoth} for a version that operates on both channels.
|
|
7894
|
+
*
|
|
7895
|
+
* @category error handling
|
|
7896
|
+
* @since 2.0.0
|
|
7897
|
+
*/
|
|
7898
|
+
const mapError = mapError$1;
|
|
7899
|
+
/**
|
|
7661
7900
|
* Returns an effect that suspends the current fiber for the specified duration
|
|
7662
7901
|
* without blocking a JavaScript thread.
|
|
7663
7902
|
*
|
|
@@ -8107,6 +8346,32 @@ const mapEager = mapEager$1;
|
|
|
8107
8346
|
* @since 4.0.0
|
|
8108
8347
|
*/
|
|
8109
8348
|
const flatMapEager = flatMapEager$1;
|
|
8349
|
+
/**
|
|
8350
|
+
* Creates untraced function effects with eager evaluation optimization.
|
|
8351
|
+
*
|
|
8352
|
+
* **Details**
|
|
8353
|
+
*
|
|
8354
|
+
* Executes generator functions eagerly when all yielded effects are synchronous,
|
|
8355
|
+
* stopping at the first async effect and deferring to normal execution.
|
|
8356
|
+
*
|
|
8357
|
+
* **Example** (Defining eager untraced effect functions)
|
|
8358
|
+
*
|
|
8359
|
+
* ```ts
|
|
8360
|
+
* import { Effect } from "effect"
|
|
8361
|
+
*
|
|
8362
|
+
* const computation = Effect.fnUntracedEager(function*() {
|
|
8363
|
+
* yield* Effect.succeed(1)
|
|
8364
|
+
* yield* Effect.succeed(2)
|
|
8365
|
+
* return "computed eagerly"
|
|
8366
|
+
* })
|
|
8367
|
+
*
|
|
8368
|
+
* const effect = computation() // Executed immediately if all effects are sync
|
|
8369
|
+
* ```
|
|
8370
|
+
*
|
|
8371
|
+
* @category eager
|
|
8372
|
+
* @since 4.0.0
|
|
8373
|
+
*/
|
|
8374
|
+
const fnUntracedEager = fnUntracedEager$1;
|
|
8110
8375
|
//#endregion
|
|
8111
8376
|
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/internal/schema/annotations.js
|
|
8112
8377
|
/** @internal */
|
|
@@ -8307,6 +8572,72 @@ var Pointer = class extends Base$1 {
|
|
|
8307
8572
|
}
|
|
8308
8573
|
};
|
|
8309
8574
|
/**
|
|
8575
|
+
* Represents a schema issue produced when a required key or tuple index is missing from the input.
|
|
8576
|
+
*
|
|
8577
|
+
* **When to use**
|
|
8578
|
+
*
|
|
8579
|
+
* Use when you need to detect absent fields in struct/tuple validation.
|
|
8580
|
+
*
|
|
8581
|
+
* **Details**
|
|
8582
|
+
*
|
|
8583
|
+
* - Has no `actual` value — {@link getActual} returns `Option.none()`.
|
|
8584
|
+
* - `annotations` may contain a custom `messageMissingKey` for formatting.
|
|
8585
|
+
*
|
|
8586
|
+
* @see {@link Pointer} — wraps this issue with the missing key's path
|
|
8587
|
+
* @see {@link UnexpectedKey} — the opposite case (extra key present)
|
|
8588
|
+
*
|
|
8589
|
+
* @category models
|
|
8590
|
+
* @since 4.0.0
|
|
8591
|
+
*/
|
|
8592
|
+
var MissingKey = class extends Base$1 {
|
|
8593
|
+
_tag = "MissingKey";
|
|
8594
|
+
/**
|
|
8595
|
+
* The metadata for the issue.
|
|
8596
|
+
*/
|
|
8597
|
+
annotations;
|
|
8598
|
+
constructor(annotations) {
|
|
8599
|
+
super();
|
|
8600
|
+
this.annotations = annotations;
|
|
8601
|
+
}
|
|
8602
|
+
};
|
|
8603
|
+
/**
|
|
8604
|
+
* Represents a schema issue produced when an input object or tuple contains a key/index not
|
|
8605
|
+
* declared by the schema.
|
|
8606
|
+
*
|
|
8607
|
+
* **When to use**
|
|
8608
|
+
*
|
|
8609
|
+
* Use when you need to detect excess properties during strict struct/tuple
|
|
8610
|
+
* validation.
|
|
8611
|
+
*
|
|
8612
|
+
* **Details**
|
|
8613
|
+
*
|
|
8614
|
+
* - `actual` is the raw value at the unexpected key (plain `unknown`).
|
|
8615
|
+
* - `ast` is the schema that was being validated against.
|
|
8616
|
+
* - `annotations` on `ast` may contain a custom `messageUnexpectedKey`.
|
|
8617
|
+
*
|
|
8618
|
+
* @see {@link MissingKey} — the opposite case (required key absent)
|
|
8619
|
+
* @see {@link Pointer} — wraps this issue with the unexpected key's path
|
|
8620
|
+
*
|
|
8621
|
+
* @category models
|
|
8622
|
+
* @since 4.0.0
|
|
8623
|
+
*/
|
|
8624
|
+
var UnexpectedKey = class extends Base$1 {
|
|
8625
|
+
_tag = "UnexpectedKey";
|
|
8626
|
+
/**
|
|
8627
|
+
* The schema that caused the issue.
|
|
8628
|
+
*/
|
|
8629
|
+
ast;
|
|
8630
|
+
/**
|
|
8631
|
+
* The input value that caused the issue.
|
|
8632
|
+
*/
|
|
8633
|
+
actual;
|
|
8634
|
+
constructor(ast, actual) {
|
|
8635
|
+
super();
|
|
8636
|
+
this.ast = ast;
|
|
8637
|
+
this.actual = actual;
|
|
8638
|
+
}
|
|
8639
|
+
};
|
|
8640
|
+
/**
|
|
8310
8641
|
* Represents a schema issue that groups multiple child issues under a single schema node.
|
|
8311
8642
|
*
|
|
8312
8643
|
* **When to use**
|
|
@@ -9415,64 +9746,558 @@ function numberToJson(checks) {
|
|
|
9415
9746
|
* @since 4.0.0
|
|
9416
9747
|
*/
|
|
9417
9748
|
const number = /*#__PURE__*/ new Number$2();
|
|
9418
|
-
const resolveConcurrency = (value) => {
|
|
9419
|
-
value = value === "unbounded" ? Infinity : value ?? 1;
|
|
9420
|
-
return value > 1 ? { concurrency: value } : void 0;
|
|
9421
|
-
};
|
|
9422
9749
|
/**
|
|
9423
|
-
*
|
|
9424
|
-
*
|
|
9750
|
+
* AST node matching any `boolean` value (`true` or `false`).
|
|
9751
|
+
*
|
|
9752
|
+
* @see {@link boolean}
|
|
9753
|
+
* @see {@link isBoolean}
|
|
9754
|
+
*
|
|
9755
|
+
* @category models
|
|
9756
|
+
* @since 4.0.0
|
|
9425
9757
|
*/
|
|
9426
|
-
|
|
9427
|
-
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
}
|
|
9432
|
-
function getCandidateTypes(ast) {
|
|
9433
|
-
switch (ast._tag) {
|
|
9434
|
-
case "Null": return ["null"];
|
|
9435
|
-
case "Undefined": return ["undefined"];
|
|
9436
|
-
case "String":
|
|
9437
|
-
case "TemplateLiteral": return ["string"];
|
|
9438
|
-
case "Number": return ["number"];
|
|
9439
|
-
case "Boolean": return ["boolean"];
|
|
9440
|
-
case "Symbol":
|
|
9441
|
-
case "UniqueSymbol": return ["symbol"];
|
|
9442
|
-
case "BigInt": return ["bigint"];
|
|
9443
|
-
case "Arrays": return ["array"];
|
|
9444
|
-
case "ObjectKeyword": return [
|
|
9445
|
-
"object",
|
|
9446
|
-
"array",
|
|
9447
|
-
"function"
|
|
9448
|
-
];
|
|
9449
|
-
case "Objects": return ast.propertySignatures.length || ast.indexSignatures.length ? ["object"] : [
|
|
9450
|
-
"string",
|
|
9451
|
-
"number",
|
|
9452
|
-
"boolean",
|
|
9453
|
-
"symbol",
|
|
9454
|
-
"bigint",
|
|
9455
|
-
"object",
|
|
9456
|
-
"array",
|
|
9457
|
-
"function"
|
|
9458
|
-
];
|
|
9459
|
-
case "Enum": return Array.from(new Set(ast.enums.map(([, v]) => typeof v)));
|
|
9460
|
-
case "Literal": return [typeof ast.literal];
|
|
9461
|
-
case "Union": return Array.from(new Set(ast.types.flatMap(getCandidateTypes)));
|
|
9462
|
-
default: return [
|
|
9463
|
-
"null",
|
|
9464
|
-
"undefined",
|
|
9465
|
-
"string",
|
|
9466
|
-
"number",
|
|
9467
|
-
"boolean",
|
|
9468
|
-
"symbol",
|
|
9469
|
-
"bigint",
|
|
9470
|
-
"object",
|
|
9471
|
-
"array",
|
|
9472
|
-
"function"
|
|
9473
|
-
];
|
|
9758
|
+
var Boolean$1 = class extends Base {
|
|
9759
|
+
_tag = "Boolean";
|
|
9760
|
+
/** @internal */
|
|
9761
|
+
getParser() {
|
|
9762
|
+
return fromRefinement(this, isBoolean);
|
|
9474
9763
|
}
|
|
9475
|
-
|
|
9764
|
+
/** @internal */
|
|
9765
|
+
getExpected() {
|
|
9766
|
+
return "boolean";
|
|
9767
|
+
}
|
|
9768
|
+
};
|
|
9769
|
+
/**
|
|
9770
|
+
* Provides the singleton {@link Boolean} AST instance.
|
|
9771
|
+
*
|
|
9772
|
+
* **When to use**
|
|
9773
|
+
*
|
|
9774
|
+
* Use to reuse the standard AST node that accepts either `true` or `false` when
|
|
9775
|
+
* constructing schema ASTs directly.
|
|
9776
|
+
*
|
|
9777
|
+
* @see {@link Boolean} for the AST node class
|
|
9778
|
+
* @see {@link Literal} for exact boolean literal AST nodes
|
|
9779
|
+
*
|
|
9780
|
+
* @category constructors
|
|
9781
|
+
* @since 4.0.0
|
|
9782
|
+
*/
|
|
9783
|
+
const boolean = /*#__PURE__*/ new Boolean$1();
|
|
9784
|
+
/**
|
|
9785
|
+
* AST node for array-like types — both tuples and arrays.
|
|
9786
|
+
*
|
|
9787
|
+
* **When to use**
|
|
9788
|
+
*
|
|
9789
|
+
* Use when constructing or inspecting AST nodes for tuple or array-like schemas,
|
|
9790
|
+
* including rest elements.
|
|
9791
|
+
*
|
|
9792
|
+
* **Details**
|
|
9793
|
+
*
|
|
9794
|
+
* - `elements` — positional element types (tuple elements). An element is
|
|
9795
|
+
* optional if its {@link Context.isOptional} is `true`.
|
|
9796
|
+
* - `rest` — the rest/variadic element types. When non-empty, the first
|
|
9797
|
+
* entry is the "spread" type (e.g. `...Array<string>`), and subsequent
|
|
9798
|
+
* entries are trailing positional elements after the spread.
|
|
9799
|
+
* - `isMutable` — whether the resulting array is `readonly` (`false`) or
|
|
9800
|
+
* mutable (`true`).
|
|
9801
|
+
*
|
|
9802
|
+
* **Gotchas**
|
|
9803
|
+
*
|
|
9804
|
+
* Construction enforces TypeScript ordering rules: a required element
|
|
9805
|
+
* cannot follow an optional one, and an optional element cannot follow a
|
|
9806
|
+
* rest element.
|
|
9807
|
+
*
|
|
9808
|
+
* **Example** (Inspecting a tuple AST)
|
|
9809
|
+
*
|
|
9810
|
+
* ```ts
|
|
9811
|
+
* import { Schema, SchemaAST } from "effect"
|
|
9812
|
+
*
|
|
9813
|
+
* const schema = Schema.Tuple([Schema.String, Schema.Number])
|
|
9814
|
+
* const ast = schema.ast
|
|
9815
|
+
*
|
|
9816
|
+
* if (SchemaAST.isArrays(ast)) {
|
|
9817
|
+
* console.log(ast.elements.length) // 2
|
|
9818
|
+
* console.log(ast.rest.length) // 0
|
|
9819
|
+
* }
|
|
9820
|
+
* ```
|
|
9821
|
+
*
|
|
9822
|
+
* @see {@link isArrays}
|
|
9823
|
+
* @see {@link Objects}
|
|
9824
|
+
* @category models
|
|
9825
|
+
* @since 4.0.0
|
|
9826
|
+
*/
|
|
9827
|
+
var Arrays = class Arrays extends Base {
|
|
9828
|
+
_tag = "Arrays";
|
|
9829
|
+
isMutable;
|
|
9830
|
+
elements;
|
|
9831
|
+
rest;
|
|
9832
|
+
encodingChecks;
|
|
9833
|
+
constructor(isMutable, elements, rest, annotations, checks, encoding, context, encodingChecks) {
|
|
9834
|
+
super(annotations, checks, encoding, context);
|
|
9835
|
+
this.isMutable = isMutable;
|
|
9836
|
+
this.elements = elements;
|
|
9837
|
+
this.rest = rest;
|
|
9838
|
+
this.encodingChecks = encodingChecks;
|
|
9839
|
+
const i = elements.findIndex(isOptional);
|
|
9840
|
+
if (i !== -1 && (elements.slice(i + 1).some((e) => !isOptional(e)) || rest.length > 1)) throw new Error("A required element cannot follow an optional element. ts(1257)");
|
|
9841
|
+
if (rest.length > 1 && rest.slice(1).some(isOptional)) throw new Error("An optional element cannot follow a rest element. ts(1266)");
|
|
9842
|
+
}
|
|
9843
|
+
/** @internal */
|
|
9844
|
+
getParser(recur) {
|
|
9845
|
+
const ast = this;
|
|
9846
|
+
const elements = ast.elements.map((ast) => ({
|
|
9847
|
+
ast,
|
|
9848
|
+
parser: recur(ast)
|
|
9849
|
+
}));
|
|
9850
|
+
const rest = ast.rest.map((ast) => ({
|
|
9851
|
+
ast,
|
|
9852
|
+
parser: recur(ast)
|
|
9853
|
+
}));
|
|
9854
|
+
const elementLen = elements.length;
|
|
9855
|
+
const [head, ...tail] = rest;
|
|
9856
|
+
const tailLen = tail.length;
|
|
9857
|
+
function getParser(tailThreshold, index) {
|
|
9858
|
+
if (index < elementLen) return elements[index];
|
|
9859
|
+
else if (index >= tailThreshold) return tail[index - tailThreshold];
|
|
9860
|
+
return head;
|
|
9861
|
+
}
|
|
9862
|
+
return fnUntracedEager(function* (oinput, options) {
|
|
9863
|
+
if (oinput._tag === "None") return oinput;
|
|
9864
|
+
const input = oinput.value;
|
|
9865
|
+
if (!Array.isArray(input)) return yield* fail(new InvalidType(ast, oinput));
|
|
9866
|
+
const len = input.length;
|
|
9867
|
+
const state = {
|
|
9868
|
+
ast,
|
|
9869
|
+
getParser,
|
|
9870
|
+
oinput,
|
|
9871
|
+
len,
|
|
9872
|
+
tailThreshold: resolveTailThreshold(len, elementLen, tailLen),
|
|
9873
|
+
output: new globalThis.Array(len),
|
|
9874
|
+
issues: void 0,
|
|
9875
|
+
options
|
|
9876
|
+
};
|
|
9877
|
+
const concurrency = resolveConcurrency(options?.concurrency);
|
|
9878
|
+
const eff = parseArray(state, input, {
|
|
9879
|
+
concurrency: concurrency?.concurrency,
|
|
9880
|
+
end: ast.rest.length === 0 ? elementLen : Math.max(len, elementLen + tailLen)
|
|
9881
|
+
});
|
|
9882
|
+
if (eff) yield* eff;
|
|
9883
|
+
if (ast.rest.length === 0 && len > elementLen) for (let i = elementLen; i <= len - 1; i++) {
|
|
9884
|
+
const issue = new Pointer([i], new UnexpectedKey(ast, input[i]));
|
|
9885
|
+
if (options.errors === "all") if (state.issues) state.issues.push(issue);
|
|
9886
|
+
else state.issues = [issue];
|
|
9887
|
+
else return yield* fail(new Composite(ast, oinput, [issue]));
|
|
9888
|
+
}
|
|
9889
|
+
if (state.issues) return yield* fail(new Composite(ast, oinput, state.issues));
|
|
9890
|
+
return some(state.output);
|
|
9891
|
+
});
|
|
9892
|
+
}
|
|
9893
|
+
_rebuild(recur, checks, encodingChecks) {
|
|
9894
|
+
const elements = mapOrSame(this.elements, recur);
|
|
9895
|
+
const rest = mapOrSame(this.rest, recur);
|
|
9896
|
+
return elements === this.elements && rest === this.rest && checks === this.checks && encodingChecks === this.encodingChecks ? this : new Arrays(this.isMutable, elements, rest, this.annotations, checks, void 0, this.context, encodingChecks);
|
|
9897
|
+
}
|
|
9898
|
+
/** @internal */
|
|
9899
|
+
recur(recur) {
|
|
9900
|
+
return this._rebuild(recur, this.checks, this.encodingChecks);
|
|
9901
|
+
}
|
|
9902
|
+
/** @internal */
|
|
9903
|
+
flip(recur) {
|
|
9904
|
+
return this._rebuild(recur, this.encodingChecks, this.checks);
|
|
9905
|
+
}
|
|
9906
|
+
/** @internal */
|
|
9907
|
+
getExpected() {
|
|
9908
|
+
return "array";
|
|
9909
|
+
}
|
|
9910
|
+
};
|
|
9911
|
+
const parseArray = /*#__PURE__*/ iterateEager()({
|
|
9912
|
+
onItem(s, item, i) {
|
|
9913
|
+
const value = i < s.len ? some(item) : none();
|
|
9914
|
+
return s.getParser(s.tailThreshold, i).parser(value, s.options);
|
|
9915
|
+
},
|
|
9916
|
+
step(s, _, exit, i) {
|
|
9917
|
+
if (exit._tag === "Failure") return wrapPropertyKeyIssue(s, s.ast, i, exit);
|
|
9918
|
+
else if (exit.value._tag === "Some") s.output[i] = exit.value.value;
|
|
9919
|
+
else {
|
|
9920
|
+
const p = s.getParser(s.tailThreshold, i);
|
|
9921
|
+
if (isOptional(p.ast)) return;
|
|
9922
|
+
const issue = new Pointer([i], new MissingKey(p.ast.context?.annotations));
|
|
9923
|
+
if (s.options.errors === "all") if (s.issues) s.issues.push(issue);
|
|
9924
|
+
else s.issues = [issue];
|
|
9925
|
+
else return fail$1(new Composite(s.ast, s.oinput, [issue]));
|
|
9926
|
+
}
|
|
9927
|
+
}
|
|
9928
|
+
});
|
|
9929
|
+
function resolveTailThreshold(inputLen, elementLen, tailLen) {
|
|
9930
|
+
return Math.max(elementLen, inputLen - tailLen);
|
|
9931
|
+
}
|
|
9932
|
+
const resolveConcurrency = (value) => {
|
|
9933
|
+
value = value === "unbounded" ? Infinity : value ?? 1;
|
|
9934
|
+
return value > 1 ? { concurrency: value } : void 0;
|
|
9935
|
+
};
|
|
9936
|
+
const wrapPropertyKeyIssue = (s, ast, key, exit) => {
|
|
9937
|
+
if (exit.cause.reasons.length === 0) return exit;
|
|
9938
|
+
const issue = getSchemaIssue(exit.cause);
|
|
9939
|
+
if (issue === void 0) return failCause(map$1(exit.cause, (issue) => new Composite(ast, s.oinput, [new Pointer([key], issue)])));
|
|
9940
|
+
const pointer = new Pointer([key], issue);
|
|
9941
|
+
if (s.options.errors === "all") if (s.issues) s.issues.push(pointer);
|
|
9942
|
+
else s.issues = [pointer];
|
|
9943
|
+
else return fail$1(new Composite(ast, s.oinput, [pointer]));
|
|
9944
|
+
};
|
|
9945
|
+
/**
|
|
9946
|
+
* floating point or integer, with optional exponent
|
|
9947
|
+
* @internal
|
|
9948
|
+
*/
|
|
9949
|
+
const FINITE_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?";
|
|
9950
|
+
/**
|
|
9951
|
+
* Returns the object keys that match the index signature parameter schema.
|
|
9952
|
+
* @internal
|
|
9953
|
+
*/
|
|
9954
|
+
function getIndexSignatureKeys(input, parameter, options = defaultParseOptions) {
|
|
9955
|
+
let stringKeys;
|
|
9956
|
+
let symbolKeys;
|
|
9957
|
+
function go(parameter) {
|
|
9958
|
+
switch (parameter._tag) {
|
|
9959
|
+
case "String":
|
|
9960
|
+
case "TemplateLiteral": return (stringKeys ??= Object.keys(input)).filter((k) => parameter.matchPart(k, options) !== void 0);
|
|
9961
|
+
case "Number": return (stringKeys ??= Object.keys(input)).filter((k) => parameter.matchKey(k, options) !== void 0);
|
|
9962
|
+
case "Symbol": return (symbolKeys ??= Object.getOwnPropertySymbols(input)).filter((k) => parameter.matchKey(k, options) !== void 0);
|
|
9963
|
+
case "Union": return [...new Set(parameter.types.flatMap(go))];
|
|
9964
|
+
default: return [];
|
|
9965
|
+
}
|
|
9966
|
+
}
|
|
9967
|
+
return go(parameterFromPropertyKey(toEncoded(parameter)));
|
|
9968
|
+
}
|
|
9969
|
+
/**
|
|
9970
|
+
* Represents a named property within an {@link Objects} node.
|
|
9971
|
+
*
|
|
9972
|
+
* **Details**
|
|
9973
|
+
*
|
|
9974
|
+
* Pairs a `name` (any `PropertyKey`) with a `type` ({@link AST}). The
|
|
9975
|
+
* property's optionality and mutability are determined by the `type`'s
|
|
9976
|
+
* {@link Context}.
|
|
9977
|
+
*
|
|
9978
|
+
* @see {@link Objects}
|
|
9979
|
+
* @category models
|
|
9980
|
+
* @since 3.10.0
|
|
9981
|
+
*/
|
|
9982
|
+
var PropertySignature = class {
|
|
9983
|
+
name;
|
|
9984
|
+
type;
|
|
9985
|
+
constructor(name, type) {
|
|
9986
|
+
this.name = name;
|
|
9987
|
+
this.type = type;
|
|
9988
|
+
}
|
|
9989
|
+
};
|
|
9990
|
+
function isIndexSignatureParameterSide(ast) {
|
|
9991
|
+
switch (ast._tag) {
|
|
9992
|
+
case "String":
|
|
9993
|
+
case "Number":
|
|
9994
|
+
case "Symbol":
|
|
9995
|
+
case "TemplateLiteral": return true;
|
|
9996
|
+
case "Union": return ast.types.every(isIndexSignatureParameterSide);
|
|
9997
|
+
default: return false;
|
|
9998
|
+
}
|
|
9999
|
+
}
|
|
10000
|
+
function isIndexSignatureParameter(ast) {
|
|
10001
|
+
return isIndexSignatureParameterSide(ast) && isIndexSignatureParameterSide(toEncoded(ast));
|
|
10002
|
+
}
|
|
10003
|
+
/**
|
|
10004
|
+
* Represents an index signature entry within an {@link Objects} node.
|
|
10005
|
+
*
|
|
10006
|
+
* **When to use**
|
|
10007
|
+
*
|
|
10008
|
+
* Use when constructing or inspecting object AST entries for record-like keys
|
|
10009
|
+
* and values.
|
|
10010
|
+
*
|
|
10011
|
+
* **Details**
|
|
10012
|
+
*
|
|
10013
|
+
* - `parameter` — the key type AST (e.g. {@link String} for `string` keys,
|
|
10014
|
+
* {@link TemplateLiteral} for patterned keys).
|
|
10015
|
+
* - `type` — the value type SchemaAST.
|
|
10016
|
+
* - `merge` — optional {@link KeyValueCombiner} for handling duplicate keys.
|
|
10017
|
+
*
|
|
10018
|
+
* **Gotchas**
|
|
10019
|
+
*
|
|
10020
|
+
* Using `Schema.optionalKey` on the value type is not allowed for index
|
|
10021
|
+
* signatures (throws at construction); use `Schema.optional` instead.
|
|
10022
|
+
*
|
|
10023
|
+
* @see {@link Objects}
|
|
10024
|
+
* @see {@link PropertySignature}
|
|
10025
|
+
* @category models
|
|
10026
|
+
* @since 3.10.0
|
|
10027
|
+
*/
|
|
10028
|
+
var IndexSignature = class {
|
|
10029
|
+
parameter;
|
|
10030
|
+
type;
|
|
10031
|
+
merge;
|
|
10032
|
+
constructor(parameter, type, merge) {
|
|
10033
|
+
if (!isIndexSignatureParameter(parameter)) throw new Error(`Invalid index signature parameter ${parameter._tag}`);
|
|
10034
|
+
this.parameter = parameter;
|
|
10035
|
+
this.type = type;
|
|
10036
|
+
this.merge = merge;
|
|
10037
|
+
if (isOptional(type) && !containsUndefined(type)) throw new Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.");
|
|
10038
|
+
}
|
|
10039
|
+
};
|
|
10040
|
+
/**
|
|
10041
|
+
* AST node for object-like schemas, including structs and records.
|
|
10042
|
+
*
|
|
10043
|
+
* **When to use**
|
|
10044
|
+
*
|
|
10045
|
+
* Use when constructing or inspecting AST nodes for structs or records rather
|
|
10046
|
+
* than array-like schemas.
|
|
10047
|
+
*
|
|
10048
|
+
* **Details**
|
|
10049
|
+
*
|
|
10050
|
+
* - `propertySignatures` — named properties with their types (struct fields).
|
|
10051
|
+
* - `indexSignatures` — index signature entries (record patterns), each with
|
|
10052
|
+
* a `parameter` AST for matching keys and a `type` AST for values.
|
|
10053
|
+
*
|
|
10054
|
+
* An `Objects` node with no properties and no index signatures performs only a
|
|
10055
|
+
* non-nullish check: it accepts any value except `null` and `undefined`,
|
|
10056
|
+
* including primitive values.
|
|
10057
|
+
*
|
|
10058
|
+
* **Gotchas**
|
|
10059
|
+
*
|
|
10060
|
+
* Duplicate property names throw at construction time.
|
|
10061
|
+
*
|
|
10062
|
+
* **Example** (Inspecting a struct AST)
|
|
10063
|
+
*
|
|
10064
|
+
* ```ts
|
|
10065
|
+
* import { Schema, SchemaAST } from "effect"
|
|
10066
|
+
*
|
|
10067
|
+
* const schema = Schema.Struct({ name: Schema.String })
|
|
10068
|
+
* const ast = schema.ast
|
|
10069
|
+
*
|
|
10070
|
+
* if (SchemaAST.isObjects(ast)) {
|
|
10071
|
+
* for (const ps of ast.propertySignatures) {
|
|
10072
|
+
* console.log(ps.name, ps.type._tag)
|
|
10073
|
+
* }
|
|
10074
|
+
* // "name" "String"
|
|
10075
|
+
* }
|
|
10076
|
+
* ```
|
|
10077
|
+
*
|
|
10078
|
+
* @see {@link isObjects}
|
|
10079
|
+
* @see {@link PropertySignature}
|
|
10080
|
+
* @see {@link IndexSignature}
|
|
10081
|
+
* @see {@link Arrays}
|
|
10082
|
+
* @category models
|
|
10083
|
+
* @since 4.0.0
|
|
10084
|
+
*/
|
|
10085
|
+
var Objects = class Objects extends Base {
|
|
10086
|
+
_tag = "Objects";
|
|
10087
|
+
propertySignatures;
|
|
10088
|
+
indexSignatures;
|
|
10089
|
+
encodingChecks;
|
|
10090
|
+
constructor(propertySignatures, indexSignatures, annotations, checks, encoding, context, encodingChecks) {
|
|
10091
|
+
super(annotations, checks, encoding, context);
|
|
10092
|
+
this.propertySignatures = propertySignatures;
|
|
10093
|
+
this.indexSignatures = indexSignatures;
|
|
10094
|
+
this.encodingChecks = encodingChecks;
|
|
10095
|
+
const duplicates = propertySignatures.map((ps) => ps.name).filter((name, i, arr) => arr.indexOf(name) !== i);
|
|
10096
|
+
if (duplicates.length > 0) throw new Error(`Duplicate identifiers: ${JSON.stringify(duplicates)}. ts(2300)`);
|
|
10097
|
+
}
|
|
10098
|
+
/** @internal */
|
|
10099
|
+
getParser(recur) {
|
|
10100
|
+
const ast = this;
|
|
10101
|
+
const expectedKeys = [];
|
|
10102
|
+
const expectedKeysSet = /* @__PURE__ */ new Set();
|
|
10103
|
+
const properties = [];
|
|
10104
|
+
for (const ps of ast.propertySignatures) {
|
|
10105
|
+
expectedKeys.push(ps.name);
|
|
10106
|
+
expectedKeysSet.add(ps.name);
|
|
10107
|
+
properties.push({
|
|
10108
|
+
ps,
|
|
10109
|
+
parser: recur(ps.type),
|
|
10110
|
+
name: ps.name,
|
|
10111
|
+
type: ps.type
|
|
10112
|
+
});
|
|
10113
|
+
}
|
|
10114
|
+
const indexCount = ast.indexSignatures.length;
|
|
10115
|
+
if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) return fromRefinement(ast, isNotNullish);
|
|
10116
|
+
const parseIndexes = indexCount > 0 ? iterateEager()({
|
|
10117
|
+
onItem: fnUntracedEager(function* (s, [key, is]) {
|
|
10118
|
+
const effKey = recur(parameterFromPropertyKey(is.parameter))(some(key), s.options);
|
|
10119
|
+
const exitKey = effectIsExit(effKey) ? effKey : yield* exit$1(effKey);
|
|
10120
|
+
if (exitKey._tag === "Failure") {
|
|
10121
|
+
const eff = wrapPropertyKeyIssue(s, ast, key, exitKey);
|
|
10122
|
+
if (eff) yield* eff;
|
|
10123
|
+
return;
|
|
10124
|
+
}
|
|
10125
|
+
const value = some(s.input[key]);
|
|
10126
|
+
const effValue = recur(is.type)(value, s.options);
|
|
10127
|
+
const exitValue = effectIsExit(effValue) ? effValue : yield* exit$1(effValue);
|
|
10128
|
+
if (exitValue._tag === "Failure") {
|
|
10129
|
+
const eff = wrapPropertyKeyIssue(s, ast, key, exitValue);
|
|
10130
|
+
if (eff) yield* eff;
|
|
10131
|
+
return;
|
|
10132
|
+
} else if (exitKey.value._tag === "Some" && exitValue.value._tag === "Some") {
|
|
10133
|
+
const k2 = exitKey.value.value;
|
|
10134
|
+
if (expectedKeysSet.has(key) || expectedKeysSet.has(k2)) return;
|
|
10135
|
+
const v2 = exitValue.value.value;
|
|
10136
|
+
if (is.merge && is.merge.decode && Object.hasOwn(s.out, k2)) {
|
|
10137
|
+
const [k, v] = is.merge.decode.combine([k2, s.out[k2]], [k2, v2]);
|
|
10138
|
+
assignProperty(s.out, k, v);
|
|
10139
|
+
} else assignProperty(s.out, k2, v2);
|
|
10140
|
+
}
|
|
10141
|
+
}),
|
|
10142
|
+
step: (_s, _, exit) => exit._tag === "Failure" ? exit : void 0
|
|
10143
|
+
}) : void 0;
|
|
10144
|
+
return fnUntracedEager(function* (oinput, options) {
|
|
10145
|
+
if (oinput._tag === "None") return oinput;
|
|
10146
|
+
const input = oinput.value;
|
|
10147
|
+
if (!(typeof input === "object" && input !== null && !Array.isArray(input))) return yield* fail(new InvalidType(ast, oinput));
|
|
10148
|
+
const out = {};
|
|
10149
|
+
const state = {
|
|
10150
|
+
ast,
|
|
10151
|
+
oinput,
|
|
10152
|
+
input,
|
|
10153
|
+
out,
|
|
10154
|
+
issues: void 0,
|
|
10155
|
+
options
|
|
10156
|
+
};
|
|
10157
|
+
const errorsAllOption = options.errors === "all";
|
|
10158
|
+
const onExcessPropertyError = options.onExcessProperty === "error";
|
|
10159
|
+
const onExcessPropertyPreserve = options.onExcessProperty === "preserve";
|
|
10160
|
+
let inputKeys;
|
|
10161
|
+
if (ast.indexSignatures.length === 0 && (onExcessPropertyError || onExcessPropertyPreserve)) {
|
|
10162
|
+
inputKeys = Reflect.ownKeys(input);
|
|
10163
|
+
for (let i = 0; i < inputKeys.length; i++) {
|
|
10164
|
+
const key = inputKeys[i];
|
|
10165
|
+
if (!expectedKeysSet.has(key)) if (onExcessPropertyError) {
|
|
10166
|
+
const issue = new Pointer([key], new UnexpectedKey(ast, input[key]));
|
|
10167
|
+
if (errorsAllOption) {
|
|
10168
|
+
if (state.issues) state.issues.push(issue);
|
|
10169
|
+
else state.issues = [issue];
|
|
10170
|
+
continue;
|
|
10171
|
+
} else return yield* fail(new Composite(ast, oinput, [issue]));
|
|
10172
|
+
} else assignProperty(out, key, input[key]);
|
|
10173
|
+
}
|
|
10174
|
+
}
|
|
10175
|
+
const concurrency = resolveConcurrency(options?.concurrency);
|
|
10176
|
+
const eff = parseProperties(state, properties, concurrency);
|
|
10177
|
+
if (eff) yield* eff;
|
|
10178
|
+
if (parseIndexes) {
|
|
10179
|
+
const keyPairs = empty$1();
|
|
10180
|
+
for (let i = 0; i < indexCount; i++) {
|
|
10181
|
+
const is = ast.indexSignatures[i];
|
|
10182
|
+
const keys = getIndexSignatureKeys(input, is.parameter, options);
|
|
10183
|
+
for (let j = 0; j < keys.length; j++) {
|
|
10184
|
+
const key = keys[j];
|
|
10185
|
+
keyPairs.push([key, is]);
|
|
10186
|
+
}
|
|
10187
|
+
}
|
|
10188
|
+
const eff = parseIndexes(state, keyPairs, concurrency);
|
|
10189
|
+
if (eff) yield* eff;
|
|
10190
|
+
}
|
|
10191
|
+
if (state.issues) return yield* fail(new Composite(ast, oinput, state.issues));
|
|
10192
|
+
if (options.propertyOrder === "original") {
|
|
10193
|
+
const keys = (inputKeys ?? Reflect.ownKeys(input)).concat(expectedKeys);
|
|
10194
|
+
const preserved = {};
|
|
10195
|
+
for (const key of keys) if (Object.hasOwn(out, key)) assignProperty(preserved, key, out[key]);
|
|
10196
|
+
return some(preserved);
|
|
10197
|
+
}
|
|
10198
|
+
return some(out);
|
|
10199
|
+
});
|
|
10200
|
+
}
|
|
10201
|
+
_rebuild(recur, recurParameter, flipMerge, checks, encodingChecks) {
|
|
10202
|
+
const props = mapOrSame(this.propertySignatures, (ps) => {
|
|
10203
|
+
const t = recur(ps.type);
|
|
10204
|
+
return t === ps.type ? ps : new PropertySignature(ps.name, t);
|
|
10205
|
+
});
|
|
10206
|
+
const indexes = mapOrSame(this.indexSignatures, (is) => {
|
|
10207
|
+
const p = recurParameter(is.parameter);
|
|
10208
|
+
const t = recur(is.type);
|
|
10209
|
+
const merge = flipMerge ? is.merge?.flip() : is.merge;
|
|
10210
|
+
return p === is.parameter && t === is.type && merge === is.merge ? is : new IndexSignature(p, t, merge);
|
|
10211
|
+
});
|
|
10212
|
+
return props === this.propertySignatures && indexes === this.indexSignatures && checks === this.checks && encodingChecks === this.encodingChecks ? this : new Objects(props, indexes, this.annotations, checks, void 0, this.context, encodingChecks);
|
|
10213
|
+
}
|
|
10214
|
+
/** @internal */
|
|
10215
|
+
flip(recur) {
|
|
10216
|
+
return this._rebuild(recur, recur, true, this.encodingChecks, this.checks);
|
|
10217
|
+
}
|
|
10218
|
+
/** @internal */
|
|
10219
|
+
recur(recur, recurParameter = recur) {
|
|
10220
|
+
return this._rebuild(recur, recurParameter, false, this.checks, this.encodingChecks);
|
|
10221
|
+
}
|
|
10222
|
+
/** @internal */
|
|
10223
|
+
getExpected() {
|
|
10224
|
+
if (this.propertySignatures.length === 0 && this.indexSignatures.length === 0) return "object | array";
|
|
10225
|
+
return "object";
|
|
10226
|
+
}
|
|
10227
|
+
};
|
|
10228
|
+
const parseProperties = /*#__PURE__*/ iterateEager()({
|
|
10229
|
+
onItem(s, p) {
|
|
10230
|
+
const value = Object.hasOwn(s.input, p.name) ? some(s.input[p.name]) : none();
|
|
10231
|
+
return p.parser(value, s.options);
|
|
10232
|
+
},
|
|
10233
|
+
step(s, p, exit) {
|
|
10234
|
+
if (exit._tag === "Failure") return wrapPropertyKeyIssue(s, s.ast, p.name, exit);
|
|
10235
|
+
else if (exit.value._tag === "Some") assignProperty(s.out, p.name, exit.value.value);
|
|
10236
|
+
else if (!isOptional(p.type)) {
|
|
10237
|
+
const issue = new Pointer([p.name], new MissingKey(p.type.context?.annotations));
|
|
10238
|
+
if (s.options.errors === "all") {
|
|
10239
|
+
if (s.issues) s.issues.push(issue);
|
|
10240
|
+
else s.issues = [issue];
|
|
10241
|
+
return;
|
|
10242
|
+
} else return fail$1(new Composite(s.ast, s.oinput, [issue]));
|
|
10243
|
+
}
|
|
10244
|
+
}
|
|
10245
|
+
});
|
|
10246
|
+
function combineChecks(a, b) {
|
|
10247
|
+
if (!a) return b;
|
|
10248
|
+
if (!b) return a;
|
|
10249
|
+
return [...a, ...b];
|
|
10250
|
+
}
|
|
10251
|
+
/** @internal */
|
|
10252
|
+
function struct(fields, checks, annotations) {
|
|
10253
|
+
return new Objects(Reflect.ownKeys(fields).map((key) => {
|
|
10254
|
+
return new PropertySignature(key, fields[key].ast);
|
|
10255
|
+
}), [], annotations, checks);
|
|
10256
|
+
}
|
|
10257
|
+
function getCandidateTypes(ast) {
|
|
10258
|
+
switch (ast._tag) {
|
|
10259
|
+
case "Null": return ["null"];
|
|
10260
|
+
case "Undefined": return ["undefined"];
|
|
10261
|
+
case "String":
|
|
10262
|
+
case "TemplateLiteral": return ["string"];
|
|
10263
|
+
case "Number": return ["number"];
|
|
10264
|
+
case "Boolean": return ["boolean"];
|
|
10265
|
+
case "Symbol":
|
|
10266
|
+
case "UniqueSymbol": return ["symbol"];
|
|
10267
|
+
case "BigInt": return ["bigint"];
|
|
10268
|
+
case "Arrays": return ["array"];
|
|
10269
|
+
case "ObjectKeyword": return [
|
|
10270
|
+
"object",
|
|
10271
|
+
"array",
|
|
10272
|
+
"function"
|
|
10273
|
+
];
|
|
10274
|
+
case "Objects": return ast.propertySignatures.length || ast.indexSignatures.length ? ["object"] : [
|
|
10275
|
+
"string",
|
|
10276
|
+
"number",
|
|
10277
|
+
"boolean",
|
|
10278
|
+
"symbol",
|
|
10279
|
+
"bigint",
|
|
10280
|
+
"object",
|
|
10281
|
+
"array",
|
|
10282
|
+
"function"
|
|
10283
|
+
];
|
|
10284
|
+
case "Enum": return Array.from(new Set(ast.enums.map(([, v]) => typeof v)));
|
|
10285
|
+
case "Literal": return [typeof ast.literal];
|
|
10286
|
+
case "Union": return Array.from(new Set(ast.types.flatMap(getCandidateTypes)));
|
|
10287
|
+
default: return [
|
|
10288
|
+
"null",
|
|
10289
|
+
"undefined",
|
|
10290
|
+
"string",
|
|
10291
|
+
"number",
|
|
10292
|
+
"boolean",
|
|
10293
|
+
"symbol",
|
|
10294
|
+
"bigint",
|
|
10295
|
+
"object",
|
|
10296
|
+
"array",
|
|
10297
|
+
"function"
|
|
10298
|
+
];
|
|
10299
|
+
}
|
|
10300
|
+
}
|
|
9476
10301
|
/** @internal */
|
|
9477
10302
|
function collectSentinels(ast) {
|
|
9478
10303
|
switch (ast._tag) {
|
|
@@ -10072,6 +10897,14 @@ const flip = /*#__PURE__*/ memoize((ast) => {
|
|
|
10072
10897
|
const out = ast;
|
|
10073
10898
|
return out.flip?.(flip) ?? out.recur?.(flip) ?? out;
|
|
10074
10899
|
});
|
|
10900
|
+
/** @internal */
|
|
10901
|
+
function containsUndefined(ast) {
|
|
10902
|
+
switch (ast._tag) {
|
|
10903
|
+
case "Undefined": return true;
|
|
10904
|
+
case "Union": return ast.types.some(containsUndefined);
|
|
10905
|
+
default: return false;
|
|
10906
|
+
}
|
|
10907
|
+
}
|
|
10075
10908
|
function fromConst(ast, value) {
|
|
10076
10909
|
const succeed = succeedSome(value);
|
|
10077
10910
|
return (oinput) => {
|
|
@@ -10298,6 +11131,35 @@ function make$2(schema) {
|
|
|
10298
11131
|
throw new Error(issue.toString(), { cause: issue });
|
|
10299
11132
|
};
|
|
10300
11133
|
}
|
|
11134
|
+
/**
|
|
11135
|
+
* Creates an effectful decoder for `unknown` input.
|
|
11136
|
+
*
|
|
11137
|
+
* **When to use**
|
|
11138
|
+
*
|
|
11139
|
+
* Use when you need to decode untyped boundary input in an `Effect` whose
|
|
11140
|
+
* failure channel is `SchemaIssue.Issue`, while preserving transformations
|
|
11141
|
+
* and service requirements.
|
|
11142
|
+
*
|
|
11143
|
+
* **Details**
|
|
11144
|
+
*
|
|
11145
|
+
* The returned function succeeds with the schema's decoded `Type` or fails with a
|
|
11146
|
+
* `SchemaIssue.Issue`. Decoding service requirements are preserved in the returned
|
|
11147
|
+
* `Effect`. Parse options may be provided when creating the decoder and overridden
|
|
11148
|
+
* when applying it.
|
|
11149
|
+
*
|
|
11150
|
+
* @see {@link decodeEffect} for input already typed as the schema's `Encoded` type
|
|
11151
|
+
*
|
|
11152
|
+
* @category decoding
|
|
11153
|
+
* @since 4.0.0
|
|
11154
|
+
*/
|
|
11155
|
+
function decodeUnknownEffect$1(schema, options) {
|
|
11156
|
+
const parser = run$1(schema.ast);
|
|
11157
|
+
return options === void 0 ? parser : (input, overrideOptions) => parser(input, mergeParseOptions(options, overrideOptions));
|
|
11158
|
+
}
|
|
11159
|
+
const mergeParseOptions = (options, overrideOptions) => overrideOptions === void 0 ? options : {
|
|
11160
|
+
...options,
|
|
11161
|
+
...overrideOptions
|
|
11162
|
+
};
|
|
10301
11163
|
/** @internal */
|
|
10302
11164
|
function run$1(ast) {
|
|
10303
11165
|
const parser = recur(ast);
|
|
@@ -10404,31 +11266,160 @@ function make$1(ast, options) {
|
|
|
10404
11266
|
function fromIssueEffect(self) {
|
|
10405
11267
|
return catchCause(self, (cause) => failCauseSync(() => map$1(cause, (issue) => new SchemaError(issue))));
|
|
10406
11268
|
}
|
|
11269
|
+
//#endregion
|
|
11270
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/Struct.js
|
|
11271
|
+
/**
|
|
11272
|
+
* Wraps a plain function as a {@link Lambda} value so it can be used with
|
|
11273
|
+
* {@link map}, {@link mapPick}, and {@link mapOmit}.
|
|
11274
|
+
*
|
|
11275
|
+
* **When to use**
|
|
11276
|
+
*
|
|
11277
|
+
* Use to create a typed lambda for struct mapping APIs that need type-level
|
|
11278
|
+
* input and output tracking.
|
|
11279
|
+
*
|
|
11280
|
+
* **Details**
|
|
11281
|
+
*
|
|
11282
|
+
* The type parameter `L` encodes both the input and output types at the type
|
|
11283
|
+
* level, allowing the compiler to track how struct value types change. At
|
|
11284
|
+
* runtime, the returned value is the same function; `lambda` only adjusts the
|
|
11285
|
+
* type.
|
|
11286
|
+
*
|
|
11287
|
+
* **Example** (Wrapping values in arrays)
|
|
11288
|
+
*
|
|
11289
|
+
* ```ts
|
|
11290
|
+
* import { pipe, Struct } from "effect"
|
|
11291
|
+
*
|
|
11292
|
+
* interface AsArray extends Struct.Lambda {
|
|
11293
|
+
* <A>(self: A): Array<A>
|
|
11294
|
+
* readonly "~lambda.out": Array<this["~lambda.in"]>
|
|
11295
|
+
* }
|
|
11296
|
+
*
|
|
11297
|
+
* const asArray = Struct.lambda<AsArray>((a) => [a])
|
|
11298
|
+
* const result = pipe({ x: 1, y: "hello" }, Struct.map(asArray))
|
|
11299
|
+
* console.log(result) // { x: [1], y: ["hello"] }
|
|
11300
|
+
* ```
|
|
11301
|
+
*
|
|
11302
|
+
* @see {@link Lambda} – the type-level interface
|
|
11303
|
+
* @see {@link map} – apply a lambda to all struct values
|
|
11304
|
+
* @category Lambda
|
|
11305
|
+
* @since 4.0.0
|
|
11306
|
+
*/
|
|
11307
|
+
const lambda = (f) => f;
|
|
11308
|
+
/**
|
|
11309
|
+
* Decodes an `unknown` input against a schema, returning an `Effect` that
|
|
11310
|
+
* succeeds with the decoded value or fails with a {@link SchemaError}.
|
|
11311
|
+
*
|
|
11312
|
+
* **When to use**
|
|
11313
|
+
*
|
|
11314
|
+
* Use when you need to decode unknown input in an `Effect` whose failure
|
|
11315
|
+
* channel is `SchemaError`.
|
|
11316
|
+
*
|
|
11317
|
+
* **Details**
|
|
11318
|
+
*
|
|
11319
|
+
* Prefer {@link decodeEffect} when the input is already typed as the schema's
|
|
11320
|
+
* `Encoded` type.
|
|
11321
|
+
* Options may be provided either when creating the decoder or when applying it;
|
|
11322
|
+
* application options override creation options.
|
|
11323
|
+
*
|
|
11324
|
+
* @see {@link SchemaParser.decodeUnknownEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
11325
|
+
*
|
|
11326
|
+
* @category decoding
|
|
11327
|
+
* @since 4.0.0
|
|
11328
|
+
*/
|
|
11329
|
+
function decodeUnknownEffect(schema, options) {
|
|
11330
|
+
const parser = decodeUnknownEffect$1(schema, options);
|
|
11331
|
+
return (input, options) => {
|
|
11332
|
+
return fromIssueEffect(parser(input, options));
|
|
11333
|
+
};
|
|
11334
|
+
}
|
|
10407
11335
|
/**
|
|
10408
11336
|
* Creates a schema from an AST (Abstract Syntax Tree) node.
|
|
10409
11337
|
*
|
|
10410
11338
|
* **Details**
|
|
10411
11339
|
*
|
|
10412
|
-
* This is the fundamental constructor for all schemas in the Effect Schema
|
|
10413
|
-
* library. It takes an AST node and wraps it in a fully-typed schema that
|
|
10414
|
-
* preserves all type information and provides the complete schema API.
|
|
11340
|
+
* This is the fundamental constructor for all schemas in the Effect Schema
|
|
11341
|
+
* library. It takes an AST node and wraps it in a fully-typed schema that
|
|
11342
|
+
* preserves all type information and provides the complete schema API.
|
|
11343
|
+
*
|
|
11344
|
+
* The `make` function is used internally to create all primitive schemas like
|
|
11345
|
+
* `String`, `Number`, `Boolean`, etc., as well as more complex schemas. It's
|
|
11346
|
+
* the bridge between the untyped AST representation and the strongly-typed
|
|
11347
|
+
* schema.
|
|
11348
|
+
*
|
|
11349
|
+
* @category constructors
|
|
11350
|
+
* @since 3.10.0
|
|
11351
|
+
*/
|
|
11352
|
+
const make = make$1;
|
|
11353
|
+
/**
|
|
11354
|
+
* Schema for `string` values. Validates that the input is `typeof` `"string"`.
|
|
11355
|
+
*
|
|
11356
|
+
* @category schemas
|
|
11357
|
+
* @since 4.0.0
|
|
11358
|
+
*/
|
|
11359
|
+
const String$1 = /*#__PURE__*/ make(string);
|
|
11360
|
+
/**
|
|
11361
|
+
* Schema for `boolean` values. Validates that the input is `typeof` `"boolean"`.
|
|
11362
|
+
*
|
|
11363
|
+
* **When to use**
|
|
11364
|
+
*
|
|
11365
|
+
* Use to validate values that are already JavaScript booleans.
|
|
11366
|
+
*
|
|
11367
|
+
* @see {@link BooleanFromBit} for a schema that decodes bit literals `0` or `1` into a boolean
|
|
11368
|
+
*
|
|
11369
|
+
* @category boolean
|
|
11370
|
+
* @since 4.0.0
|
|
11371
|
+
*/
|
|
11372
|
+
const Boolean = /*#__PURE__*/ make(boolean);
|
|
11373
|
+
function makeStruct(ast, fields) {
|
|
11374
|
+
return make(ast, {
|
|
11375
|
+
fields,
|
|
11376
|
+
mapFields(f, options) {
|
|
11377
|
+
const fields = f(this.fields);
|
|
11378
|
+
return makeStruct(struct(fields, options?.unsafePreserveChecks ? this.ast.checks : void 0), fields);
|
|
11379
|
+
}
|
|
11380
|
+
});
|
|
11381
|
+
}
|
|
11382
|
+
/**
|
|
11383
|
+
* Defines a struct schema from a map of field schemas.
|
|
11384
|
+
*
|
|
11385
|
+
* **Details**
|
|
11386
|
+
*
|
|
11387
|
+
* Each field value is a schema. Use {@link optionalKey} or {@link optional} to
|
|
11388
|
+
* mark fields as optional, and {@link mutableKey} to mark them as mutable.
|
|
10415
11389
|
*
|
|
10416
|
-
* The `
|
|
10417
|
-
*
|
|
10418
|
-
*
|
|
10419
|
-
*
|
|
11390
|
+
* The resulting schema's `Type` is a readonly object type with the fields'
|
|
11391
|
+
* decoded types. The `Encoded` form mirrors the field schemas' encoded types.
|
|
11392
|
+
*
|
|
11393
|
+
* **Example** (Defining a basic struct)
|
|
11394
|
+
*
|
|
11395
|
+
* ```ts
|
|
11396
|
+
* import { Schema } from "effect"
|
|
11397
|
+
*
|
|
11398
|
+
* const Person = Schema.Struct({
|
|
11399
|
+
* name: Schema.String,
|
|
11400
|
+
* age: Schema.Number,
|
|
11401
|
+
* email: Schema.optionalKey(Schema.String)
|
|
11402
|
+
* })
|
|
11403
|
+
*
|
|
11404
|
+
* // { readonly name: string; readonly age: number; readonly email?: string }
|
|
11405
|
+
* type Person = typeof Person.Type
|
|
11406
|
+
*
|
|
11407
|
+
* const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
|
|
11408
|
+
* console.log(alice)
|
|
11409
|
+
* // { name: 'Alice', age: 30 }
|
|
11410
|
+
* ```
|
|
10420
11411
|
*
|
|
10421
11412
|
* @category constructors
|
|
10422
11413
|
* @since 3.10.0
|
|
10423
11414
|
*/
|
|
10424
|
-
|
|
11415
|
+
function Struct(fields) {
|
|
11416
|
+
return makeStruct(struct(fields, void 0), fields);
|
|
11417
|
+
}
|
|
10425
11418
|
/**
|
|
10426
|
-
*
|
|
10427
|
-
*
|
|
10428
|
-
* @category schemas
|
|
11419
|
+
* @category constructors
|
|
10429
11420
|
* @since 4.0.0
|
|
10430
11421
|
*/
|
|
10431
|
-
const
|
|
11422
|
+
const ArraySchema = /*#__PURE__*/ lambda((schema) => make(new Arrays(false, [], [schema.ast]), { value: schema }));
|
|
10432
11423
|
/**
|
|
10433
11424
|
* Adds a nominal brand to a schema, intersecting the output type with
|
|
10434
11425
|
* `Brand.Brand<B>` to prevent accidental mixing of structurally identical types.
|
|
@@ -10524,6 +11515,7 @@ const openHunk = (draft, line) => {
|
|
|
10524
11515
|
marker: line,
|
|
10525
11516
|
scope: (header?.[3] ?? "").trim(),
|
|
10526
11517
|
startRow: draft.rows.length,
|
|
11518
|
+
newStart: draft.newLine,
|
|
10527
11519
|
rows: [],
|
|
10528
11520
|
skipped: draft.hunks.length === 0 ? 0 : Math.max(0, draft.newLine - previousNew)
|
|
10529
11521
|
});
|
|
@@ -10792,7 +11784,8 @@ var StoreUnreadable = class extends TaggedError("StoreUnreadable") {};
|
|
|
10792
11784
|
const emptyBranchState = {
|
|
10793
11785
|
vouches: {},
|
|
10794
11786
|
consumed: 0,
|
|
10795
|
-
pending: []
|
|
11787
|
+
pending: [],
|
|
11788
|
+
settled: {}
|
|
10796
11789
|
};
|
|
10797
11790
|
//#endregion
|
|
10798
11791
|
//#region src/service/store/paths.ts
|
|
@@ -10801,8 +11794,10 @@ const slugOf = (worktreePath) => worktreePath.replace(NON_SLUG, "-");
|
|
|
10801
11794
|
const defaultRoot = () => join(homedir(), ".adiff");
|
|
10802
11795
|
const branchDir = (root, worktreePath) => join(root, "branches", slugOf(worktreePath));
|
|
10803
11796
|
const inboxPath = (root, worktreePath) => join(branchDir(root, worktreePath), "inbox.jsonl");
|
|
11797
|
+
const outboxPath = (root, worktreePath) => join(branchDir(root, worktreePath), "outbox.jsonl");
|
|
10804
11798
|
const statePath = (root, worktreePath) => join(branchDir(root, worktreePath), "state.json");
|
|
10805
|
-
const
|
|
11799
|
+
const layersPath = (root, worktreePath) => join(branchDir(root, worktreePath), "layers.json");
|
|
11800
|
+
const settingsPath = (root) => join(root, "settings.json");
|
|
10806
11801
|
const reportsDir = (root) => join(root, "reports");
|
|
10807
11802
|
const reportPath = (root, stamp) => join(reportsDir(root), `${stamp}.md`);
|
|
10808
11803
|
//#endregion
|
|
@@ -10827,7 +11822,12 @@ const readOptional = fn("Store.readOptional")(function* (path) {
|
|
|
10827
11822
|
}).pipe(map(some), catchTag("StoreUnreadable", () => missing));
|
|
10828
11823
|
});
|
|
10829
11824
|
const missing = succeed(none());
|
|
11825
|
+
const parseSettings = (raw) => {
|
|
11826
|
+
const parsed = JSON.parse(raw);
|
|
11827
|
+
return typeof parsed.wrap === "boolean" ? { wrap: parsed.wrap } : {};
|
|
11828
|
+
};
|
|
10830
11829
|
const parseBatches = (raw) => raw.split("\n").filter((line) => line.trim().length > 0).map((line) => JSON.parse(line));
|
|
11830
|
+
const parseAnswers = (raw) => raw.split("\n").filter((line) => line.trim().length > 0).map((line) => JSON.parse(line));
|
|
10831
11831
|
const parseState = (raw) => ({
|
|
10832
11832
|
...emptyBranchState,
|
|
10833
11833
|
...JSON.parse(raw)
|
|
@@ -10843,6 +11843,26 @@ const cursorOps = (state, saveState, inbox) => {
|
|
|
10843
11843
|
});
|
|
10844
11844
|
return pending;
|
|
10845
11845
|
}),
|
|
11846
|
+
restage: fn("Store.restage")(function* (worktreePath, comment) {
|
|
11847
|
+
const current = yield* state(worktreePath);
|
|
11848
|
+
if (!current.pending.some((entry) => entry.id === comment.id)) return none();
|
|
11849
|
+
const pending = current.pending.map((entry) => entry.id === comment.id ? comment : entry);
|
|
11850
|
+
yield* saveState(worktreePath, {
|
|
11851
|
+
...current,
|
|
11852
|
+
pending
|
|
11853
|
+
});
|
|
11854
|
+
return some(pending);
|
|
11855
|
+
}),
|
|
11856
|
+
unstage: fn("Store.unstage")(function* (worktreePath, id) {
|
|
11857
|
+
const current = yield* state(worktreePath);
|
|
11858
|
+
if (!current.pending.some((entry) => entry.id === id)) return none();
|
|
11859
|
+
const pending = current.pending.filter((entry) => entry.id !== id);
|
|
11860
|
+
yield* saveState(worktreePath, {
|
|
11861
|
+
...current,
|
|
11862
|
+
pending
|
|
11863
|
+
});
|
|
11864
|
+
return some(pending);
|
|
11865
|
+
}),
|
|
10846
11866
|
take: fn("Store.take")(function* (worktreePath) {
|
|
10847
11867
|
const batches = yield* inbox(worktreePath);
|
|
10848
11868
|
const current = yield* state(worktreePath);
|
|
@@ -10855,14 +11875,70 @@ const cursorOps = (state, saveState, inbox) => {
|
|
|
10855
11875
|
})
|
|
10856
11876
|
};
|
|
10857
11877
|
};
|
|
10858
|
-
const
|
|
11878
|
+
const settingsOps = (root) => {
|
|
11879
|
+
return {
|
|
11880
|
+
settings: fn("Store.settings")(function* () {
|
|
11881
|
+
const raw = yield* readOptional(settingsPath(root));
|
|
11882
|
+
return match$2(raw, {
|
|
11883
|
+
onNone: () => ({}),
|
|
11884
|
+
onSome: parseSettings
|
|
11885
|
+
});
|
|
11886
|
+
}),
|
|
11887
|
+
saveSettings: fn("Store.saveSettings")(function* (next) {
|
|
11888
|
+
const path = settingsPath(root);
|
|
11889
|
+
yield* ensureDir(root);
|
|
11890
|
+
yield* tryPromise({
|
|
11891
|
+
try: () => writeFile(path, JSON.stringify(next), "utf8"),
|
|
11892
|
+
catch: (cause) => new StoreUnwritable({
|
|
11893
|
+
path,
|
|
11894
|
+
reason: String(cause)
|
|
11895
|
+
})
|
|
11896
|
+
});
|
|
11897
|
+
})
|
|
11898
|
+
};
|
|
11899
|
+
};
|
|
11900
|
+
const reportOps = (root) => fn("Store.saveReport")(function* (stamp, text) {
|
|
11901
|
+
const path = reportPath(root, stamp);
|
|
11902
|
+
yield* ensureDir(reportsDir(root));
|
|
11903
|
+
yield* tryPromise({
|
|
11904
|
+
try: () => writeFile(path, text, "utf8"),
|
|
11905
|
+
catch: (cause) => new StoreUnwritable({
|
|
11906
|
+
path,
|
|
11907
|
+
reason: String(cause)
|
|
11908
|
+
})
|
|
11909
|
+
});
|
|
11910
|
+
return path;
|
|
11911
|
+
});
|
|
11912
|
+
const answerOps = (root) => {
|
|
11913
|
+
return {
|
|
11914
|
+
answer: fn("Store.answer")(function* (worktreePath, entry) {
|
|
11915
|
+
const path = outboxPath(root, worktreePath);
|
|
11916
|
+
yield* ensureDir(branchDir(root, worktreePath));
|
|
11917
|
+
yield* tryPromise({
|
|
11918
|
+
try: () => appendFile(path, `${JSON.stringify(entry)}\n`, "utf8"),
|
|
11919
|
+
catch: (cause) => new StoreUnwritable({
|
|
11920
|
+
path,
|
|
11921
|
+
reason: String(cause)
|
|
11922
|
+
})
|
|
11923
|
+
});
|
|
11924
|
+
}),
|
|
11925
|
+
answers: fn("Store.answers")(function* (worktreePath) {
|
|
11926
|
+
const raw = yield* readOptional(outboxPath(root, worktreePath));
|
|
11927
|
+
return match$2(raw, {
|
|
11928
|
+
onNone: () => [],
|
|
11929
|
+
onSome: parseAnswers
|
|
11930
|
+
});
|
|
11931
|
+
})
|
|
11932
|
+
};
|
|
11933
|
+
};
|
|
11934
|
+
const layersOps = (root) => {
|
|
10859
11935
|
return {
|
|
10860
|
-
|
|
10861
|
-
const raw = yield* readOptional(
|
|
11936
|
+
layers: fn("Store.layers")(function* (worktreePath) {
|
|
11937
|
+
const raw = yield* readOptional(layersPath(root, worktreePath));
|
|
10862
11938
|
return map$4(raw, (text) => JSON.parse(text));
|
|
10863
11939
|
}),
|
|
10864
|
-
|
|
10865
|
-
const path =
|
|
11940
|
+
saveLayers: fn("Store.saveLayers")(function* (worktreePath, next) {
|
|
11941
|
+
const path = layersPath(root, worktreePath);
|
|
10866
11942
|
yield* ensureDir(branchDir(root, worktreePath));
|
|
10867
11943
|
yield* tryPromise({
|
|
10868
11944
|
try: () => writeFile(path, JSON.stringify(next, void 0, 2), "utf8"),
|
|
@@ -10911,18 +11987,6 @@ const makeStore = (root) => {
|
|
|
10911
11987
|
})
|
|
10912
11988
|
});
|
|
10913
11989
|
});
|
|
10914
|
-
const saveReport = fn("Store.saveReport")(function* (stamp, text) {
|
|
10915
|
-
const path = reportPath(root, stamp);
|
|
10916
|
-
yield* ensureDir(reportsDir(root));
|
|
10917
|
-
yield* tryPromise({
|
|
10918
|
-
try: () => writeFile(path, text, "utf8"),
|
|
10919
|
-
catch: (cause) => new StoreUnwritable({
|
|
10920
|
-
path,
|
|
10921
|
-
reason: String(cause)
|
|
10922
|
-
})
|
|
10923
|
-
});
|
|
10924
|
-
return path;
|
|
10925
|
-
});
|
|
10926
11990
|
const cursors = cursorOps(state, saveState, inbox);
|
|
10927
11991
|
return {
|
|
10928
11992
|
root,
|
|
@@ -10930,8 +11994,10 @@ const makeStore = (root) => {
|
|
|
10930
11994
|
inbox,
|
|
10931
11995
|
state,
|
|
10932
11996
|
saveState,
|
|
10933
|
-
saveReport,
|
|
10934
|
-
...
|
|
11997
|
+
saveReport: reportOps(root),
|
|
11998
|
+
...settingsOps(root),
|
|
11999
|
+
...answerOps(root),
|
|
12000
|
+
...layersOps(root),
|
|
10935
12001
|
...cursors
|
|
10936
12002
|
};
|
|
10937
12003
|
};
|
|
@@ -10941,16 +12007,18 @@ storeAt(defaultRoot());
|
|
|
10941
12007
|
//#region src/cli/error.ts
|
|
10942
12008
|
var UnknownBranch = class extends TaggedError("UnknownBranch") {};
|
|
10943
12009
|
var UnknownFile = class extends TaggedError("UnknownFile") {};
|
|
12010
|
+
var UnknownComment = class extends TaggedError("UnknownComment") {};
|
|
10944
12011
|
var UnselectableRange = class extends TaggedError("UnselectableRange") {};
|
|
10945
12012
|
var UnknownCommand = class extends TaggedError("UnknownCommand") {};
|
|
10946
12013
|
var MissingOption = class extends TaggedError("MissingOption") {};
|
|
10947
12014
|
var EmptyReview = class extends TaggedError("EmptyReview") {};
|
|
10948
12015
|
var UnknownWorktree = class extends TaggedError("UnknownWorktree") {};
|
|
10949
|
-
var
|
|
10950
|
-
var
|
|
12016
|
+
var MalformedLayers = class extends TaggedError("MalformedLayers") {};
|
|
12017
|
+
var NoLayers = class extends TaggedError("NoLayers") {};
|
|
10951
12018
|
//#endregion
|
|
10952
12019
|
//#region src/cli/commands.ts
|
|
10953
12020
|
const CONTEXT = 3;
|
|
12021
|
+
const WHOLE_FILE$1 = 1e5;
|
|
10954
12022
|
const POLL = "500 millis";
|
|
10955
12023
|
const findBranch = fn("Cli.findBranch")(function* (repo, branch) {
|
|
10956
12024
|
const worktrees = yield* (yield* Git).worktrees(repo);
|
|
@@ -10961,8 +12029,8 @@ const findBranch = fn("Cli.findBranch")(function* (repo, branch) {
|
|
|
10961
12029
|
known: worktrees.map((w) => w.branch)
|
|
10962
12030
|
}) : succeed(found);
|
|
10963
12031
|
});
|
|
10964
|
-
const patchesOf = fn("Cli.patchesOf")(function* (worktree) {
|
|
10965
|
-
const raw = yield* (yield* Git).diff(worktree,
|
|
12032
|
+
const patchesOf = fn("Cli.patchesOf")(function* (worktree, context = CONTEXT) {
|
|
12033
|
+
const raw = yield* (yield* Git).diff(worktree, context);
|
|
10966
12034
|
return parsePatches(raw);
|
|
10967
12035
|
});
|
|
10968
12036
|
const findPatch = (patches, file) => fromNullishOr(patches.find((patch) => patch.path === file));
|
|
@@ -10974,9 +12042,18 @@ const waitingOn = fn("Cli.waitingOn")(function* (worktree) {
|
|
|
10974
12042
|
const store = yield* Store;
|
|
10975
12043
|
const state = yield* store.state(worktree.path);
|
|
10976
12044
|
const batches = yield* store.inbox(worktree.path);
|
|
12045
|
+
const told = yield* store.layers(worktree.path);
|
|
10977
12046
|
return {
|
|
10978
12047
|
staged: state.pending.length,
|
|
10979
|
-
unread: Math.max(0, batches.length - state.consumed)
|
|
12048
|
+
unread: Math.max(0, batches.length - state.consumed),
|
|
12049
|
+
layers: match$2(told, {
|
|
12050
|
+
onNone: () => 0,
|
|
12051
|
+
onSome: (layers) => layers.layers.length
|
|
12052
|
+
}),
|
|
12053
|
+
stale: match$2(told, {
|
|
12054
|
+
onNone: () => false,
|
|
12055
|
+
onSome: (layers) => layers.head !== worktree.head
|
|
12056
|
+
})
|
|
10980
12057
|
};
|
|
10981
12058
|
});
|
|
10982
12059
|
const listBranches = fn("Cli.listBranches")(function* (repo) {
|
|
@@ -10994,7 +12071,9 @@ const listBranches = fn("Cli.listBranches")(function* (repo) {
|
|
|
10994
12071
|
added: stat.added,
|
|
10995
12072
|
removed: stat.removed,
|
|
10996
12073
|
staged: waiting.staged,
|
|
10997
|
-
unread: waiting.unread
|
|
12074
|
+
unread: waiting.unread,
|
|
12075
|
+
layers: waiting.layers,
|
|
12076
|
+
stale: waiting.stale
|
|
10998
12077
|
});
|
|
10999
12078
|
}
|
|
11000
12079
|
return summaries.filter((summary) => summary.files > 0);
|
|
@@ -11041,7 +12120,7 @@ const reviewProgress = fn("Cli.reviewProgress")(function* (repo, branch) {
|
|
|
11041
12120
|
});
|
|
11042
12121
|
const anchorRequest = fn("Cli.anchorRequest")(function* (request) {
|
|
11043
12122
|
const worktree = yield* findBranch(request.repo, request.branch);
|
|
11044
|
-
const patches = yield* patchesOf(worktree);
|
|
12123
|
+
const patches = yield* patchesOf(worktree, WHOLE_FILE$1);
|
|
11045
12124
|
const resolved = yield* match$2(findPatch(patches, request.file), {
|
|
11046
12125
|
onNone: () => new UnknownFile({
|
|
11047
12126
|
file: request.file,
|
|
@@ -11076,10 +12155,30 @@ const stageComment = fn("Cli.stageComment")(function* (request) {
|
|
|
11076
12155
|
};
|
|
11077
12156
|
return { pending: (yield* store.stage(worktree.path, entry)).length };
|
|
11078
12157
|
});
|
|
12158
|
+
const editStaged = fn("Cli.editStaged")(function* (request) {
|
|
12159
|
+
const store = yield* Store;
|
|
12160
|
+
const worktree = yield* findBranch(request.repo, request.branch);
|
|
12161
|
+
const current = yield* store.state(worktree.path);
|
|
12162
|
+
const found = current.pending.find((entry) => entry.id === request.id);
|
|
12163
|
+
if (found === void 0) return yield* new UnknownComment({ id: request.id });
|
|
12164
|
+
const pending = yield* store.restage(worktree.path, {
|
|
12165
|
+
...found,
|
|
12166
|
+
body: request.body
|
|
12167
|
+
});
|
|
12168
|
+
return { pending: getOrElse(pending, () => current.pending).length };
|
|
12169
|
+
});
|
|
12170
|
+
const dropStaged = fn("Cli.dropStaged")(function* (repo, branch, id) {
|
|
12171
|
+
const store = yield* Store;
|
|
12172
|
+
const worktree = yield* findBranch(repo, branch);
|
|
12173
|
+
const pending = yield* store.unstage(worktree.path, id);
|
|
12174
|
+
if (isNone(pending)) return yield* new UnknownComment({ id });
|
|
12175
|
+
return { pending: pending.value.length };
|
|
12176
|
+
});
|
|
11079
12177
|
const listPending = fn("Cli.listPending")(function* (repo, branch) {
|
|
11080
12178
|
const store = yield* Store;
|
|
11081
12179
|
const worktree = yield* findBranch(repo, branch);
|
|
11082
12180
|
return (yield* store.state(worktree.path)).pending.map((entry) => ({
|
|
12181
|
+
id: entry.id,
|
|
11083
12182
|
file: entry.anchor.path,
|
|
11084
12183
|
side: entry.anchor.side,
|
|
11085
12184
|
start: entry.anchor.start,
|
|
@@ -11087,16 +12186,28 @@ const listPending = fn("Cli.listPending")(function* (repo, branch) {
|
|
|
11087
12186
|
body: entry.body
|
|
11088
12187
|
}));
|
|
11089
12188
|
});
|
|
11090
|
-
const
|
|
11091
|
-
|
|
11092
|
-
const
|
|
11093
|
-
return
|
|
12189
|
+
const bodyOf = (entry) => entry.body;
|
|
12190
|
+
const sentOf = (comment, spoken, settled, head) => {
|
|
12191
|
+
const mine = spoken.filter((entry) => entry.comment === comment.id);
|
|
12192
|
+
return {
|
|
12193
|
+
id: comment.id,
|
|
11094
12194
|
file: comment.file,
|
|
11095
12195
|
side: comment.side,
|
|
11096
12196
|
start: comment.start,
|
|
11097
12197
|
end: comment.end,
|
|
11098
|
-
body: comment.body
|
|
11099
|
-
|
|
12198
|
+
body: comment.body,
|
|
12199
|
+
settled: Object.hasOwn(settled, comment.id),
|
|
12200
|
+
stale: comment.head !== head,
|
|
12201
|
+
asks: mine.at(-1)?.asks === true,
|
|
12202
|
+
answers: mine.map(bodyOf)
|
|
12203
|
+
};
|
|
12204
|
+
};
|
|
12205
|
+
const listSent = fn("Cli.listSent")(function* (repo, branch) {
|
|
12206
|
+
const store = yield* Store;
|
|
12207
|
+
const worktree = yield* findBranch(repo, branch);
|
|
12208
|
+
const spoken = yield* store.answers(worktree.path);
|
|
12209
|
+
const current = yield* store.state(worktree.path);
|
|
12210
|
+
return flatten(yield* store.inbox(worktree.path)).map((comment) => sentOf(comment, spoken, current.settled, worktree.head));
|
|
11100
12211
|
});
|
|
11101
12212
|
const submitReview = fn("Cli.submitReview")(function* (repo, branch, id, at) {
|
|
11102
12213
|
const store = yield* Store;
|
|
@@ -11124,7 +12235,7 @@ const submitReview = fn("Cli.submitReview")(function* (repo, branch, id, at) {
|
|
|
11124
12235
|
const submitComment = fn("Cli.submitComment")(function* (request) {
|
|
11125
12236
|
const store = yield* Store;
|
|
11126
12237
|
const worktree = yield* findBranch(request.repo, request.branch);
|
|
11127
|
-
const patches = yield* patchesOf(worktree);
|
|
12238
|
+
const patches = yield* patchesOf(worktree, WHOLE_FILE$1);
|
|
11128
12239
|
const patch = findPatch(patches, request.file);
|
|
11129
12240
|
const resolved = yield* match$2(patch, {
|
|
11130
12241
|
onNone: () => new UnknownFile({
|
|
@@ -11164,6 +12275,7 @@ const listPatches = fn("Cli.listPatches")(function* (repo, branch, context = CON
|
|
|
11164
12275
|
return parsePatches(yield* git.diff(worktree, context));
|
|
11165
12276
|
});
|
|
11166
12277
|
const flatten = (batches) => batches.flatMap((batch) => batch.comments.map((comment) => ({
|
|
12278
|
+
id: comment.id,
|
|
11167
12279
|
at: batch.at,
|
|
11168
12280
|
head: batch.head,
|
|
11169
12281
|
file: comment.anchor.path,
|
|
@@ -11188,19 +12300,28 @@ const fileSource = fn("Cli.fileSource")(function* (repo, branch, file) {
|
|
|
11188
12300
|
const found = yield* git.source(worktree, file);
|
|
11189
12301
|
return getOrElse(found, () => []);
|
|
11190
12302
|
});
|
|
12303
|
+
const saveWrap = fn("Cli.saveWrap")(function* (wrap) {
|
|
12304
|
+
const store = yield* Store;
|
|
12305
|
+
const current = yield* store.settings();
|
|
12306
|
+
yield* store.saveSettings({
|
|
12307
|
+
...current,
|
|
12308
|
+
wrap
|
|
12309
|
+
});
|
|
12310
|
+
});
|
|
11191
12311
|
//#endregion
|
|
11192
|
-
//#region src/domain/
|
|
11193
|
-
const REMAINDER_TITLE = "not in any
|
|
12312
|
+
//#region src/domain/layers/model.ts
|
|
12313
|
+
const REMAINDER_TITLE = "not in any layer";
|
|
11194
12314
|
//#endregion
|
|
11195
|
-
//#region src/domain/
|
|
12315
|
+
//#region src/domain/layers/coverage.ts
|
|
11196
12316
|
const codeBlockOf$1 = (span) => ({
|
|
11197
12317
|
kind: "code",
|
|
11198
12318
|
path: span.path,
|
|
11199
12319
|
start: span.start,
|
|
11200
12320
|
end: span.end
|
|
11201
12321
|
});
|
|
11202
|
-
const codeBlocks = (
|
|
11203
|
-
const
|
|
12322
|
+
const codeBlocks = (layer) => layer.blocks.filter((block) => block.kind === "code");
|
|
12323
|
+
const noteOf = (layer) => layer.blocks.filter((block) => block.kind === "prose").map((block) => block.markdown.trim()).filter((markdown) => markdown.length > 0).join(" ");
|
|
12324
|
+
const spansOf$1 = (layers) => layers.flatMap((layer) => codeBlocks(layer).map(({ path, start, end }) => ({
|
|
11204
12325
|
path,
|
|
11205
12326
|
start,
|
|
11206
12327
|
end
|
|
@@ -11217,8 +12338,8 @@ const spanOfHunk = (patch, hunk) => {
|
|
|
11217
12338
|
});
|
|
11218
12339
|
};
|
|
11219
12340
|
const overlaps = (a, b) => a.path === b.path && a.start <= b.end && a.end >= b.start;
|
|
11220
|
-
const coverage = (patches,
|
|
11221
|
-
const claimed = spansOf(
|
|
12341
|
+
const coverage = (patches, layers) => {
|
|
12342
|
+
const claimed = spansOf$1(layers);
|
|
11222
12343
|
const hunks = patches.flatMap((patch) => patch.hunks.flatMap((hunk) => match$2(spanOfHunk(patch, hunk), {
|
|
11223
12344
|
onNone: () => [],
|
|
11224
12345
|
onSome: (s) => [s]
|
|
@@ -11230,9 +12351,9 @@ const coverage = (patches, steps) => {
|
|
|
11230
12351
|
missing
|
|
11231
12352
|
};
|
|
11232
12353
|
};
|
|
11233
|
-
const withFullCoverage = (patches,
|
|
11234
|
-
const gap = coverage(patches,
|
|
11235
|
-
if (gap.missing.length === 0) return
|
|
12354
|
+
const withFullCoverage = (patches, layers) => {
|
|
12355
|
+
const gap = coverage(patches, layers.layers);
|
|
12356
|
+
if (gap.missing.length === 0) return layers;
|
|
11236
12357
|
const remainder = {
|
|
11237
12358
|
title: REMAINDER_TITLE,
|
|
11238
12359
|
blocks: [{
|
|
@@ -11241,21 +12362,48 @@ const withFullCoverage = (patches, story) => {
|
|
|
11241
12362
|
}, ...gap.missing.map((span) => codeBlockOf$1(span))]
|
|
11242
12363
|
};
|
|
11243
12364
|
return {
|
|
11244
|
-
...
|
|
11245
|
-
|
|
12365
|
+
...layers,
|
|
12366
|
+
layers: [...layers.layers, remainder]
|
|
11246
12367
|
};
|
|
11247
12368
|
};
|
|
12369
|
+
const proseAnchors = (layer) => {
|
|
12370
|
+
const anchors = [];
|
|
12371
|
+
let pending = [];
|
|
12372
|
+
let last;
|
|
12373
|
+
for (const block of layer.blocks) {
|
|
12374
|
+
if (block.kind === "prose") {
|
|
12375
|
+
const markdown = block.markdown.trim();
|
|
12376
|
+
if (markdown.length > 0) pending.push(markdown);
|
|
12377
|
+
continue;
|
|
12378
|
+
}
|
|
12379
|
+
for (const markdown of pending) anchors.push({
|
|
12380
|
+
path: block.path,
|
|
12381
|
+
line: block.start,
|
|
12382
|
+
markdown,
|
|
12383
|
+
after: false
|
|
12384
|
+
});
|
|
12385
|
+
pending = [];
|
|
12386
|
+
last = block;
|
|
12387
|
+
}
|
|
12388
|
+
if (last === void 0) return anchors;
|
|
12389
|
+
return [...anchors, ...pending.map((markdown) => ({
|
|
12390
|
+
path: last.path,
|
|
12391
|
+
line: last.end,
|
|
12392
|
+
markdown,
|
|
12393
|
+
after: true
|
|
12394
|
+
}))];
|
|
12395
|
+
};
|
|
11248
12396
|
//#endregion
|
|
11249
|
-
//#region src/domain/
|
|
11250
|
-
const statusOf = (patches,
|
|
11251
|
-
const gap = coverage(patches,
|
|
12397
|
+
//#region src/domain/layers/version.ts
|
|
12398
|
+
const statusOf = (patches, layers, branchHead) => {
|
|
12399
|
+
const gap = coverage(patches, layers.layers);
|
|
11252
12400
|
const present = new Set(patches.map((patch) => patch.path));
|
|
11253
|
-
const mentioned = new Set(spansOf(
|
|
12401
|
+
const mentioned = new Set(spansOf$1(layers.layers).map((span) => span.path));
|
|
11254
12402
|
return {
|
|
11255
|
-
version:
|
|
11256
|
-
parent:
|
|
11257
|
-
stale:
|
|
11258
|
-
|
|
12403
|
+
version: layers.version,
|
|
12404
|
+
parent: layers.parent,
|
|
12405
|
+
stale: layers.head !== branchHead,
|
|
12406
|
+
layersHead: layers.head,
|
|
11259
12407
|
branchHead,
|
|
11260
12408
|
uncovered: gap.missing,
|
|
11261
12409
|
vanished: [...mentioned].filter((path) => !present.has(path)),
|
|
@@ -11264,9 +12412,10 @@ const statusOf = (patches, story, branchHead) => {
|
|
|
11264
12412
|
};
|
|
11265
12413
|
};
|
|
11266
12414
|
//#endregion
|
|
11267
|
-
//#region src/cli/
|
|
12415
|
+
//#region src/cli/layers.ts
|
|
12416
|
+
const STALE_ADVICE = "These layers describe an older commit. Read the diff again and write a new revision with layers set.";
|
|
11268
12417
|
const unique = (paths) => [...new Set(paths)];
|
|
11269
|
-
const
|
|
12418
|
+
const spansOfLayer = (layer) => codeBlocks(layer).map(({ path, start, end }) => ({
|
|
11270
12419
|
path,
|
|
11271
12420
|
start,
|
|
11272
12421
|
end
|
|
@@ -11286,20 +12435,20 @@ const codeBlockOf = (span) => ({
|
|
|
11286
12435
|
start: span.start,
|
|
11287
12436
|
end: span.end
|
|
11288
12437
|
});
|
|
11289
|
-
const blocksOf = (
|
|
11290
|
-
if (Array.isArray(
|
|
11291
|
-
const note = typeof
|
|
12438
|
+
const blocksOf = (layer) => {
|
|
12439
|
+
if (Array.isArray(layer.blocks)) return layer.blocks.filter(isBlock);
|
|
12440
|
+
const note = typeof layer.note === "string" ? [{
|
|
11292
12441
|
kind: "prose",
|
|
11293
|
-
markdown:
|
|
12442
|
+
markdown: layer.note
|
|
11294
12443
|
}] : [];
|
|
11295
|
-
const spans = Array.isArray(
|
|
12444
|
+
const spans = Array.isArray(layer.spans) ? layer.spans.filter(isSpan) : [];
|
|
11296
12445
|
return [...note, ...spans.map(codeBlockOf)];
|
|
11297
12446
|
};
|
|
11298
|
-
const
|
|
11299
|
-
const
|
|
11300
|
-
const title = typeof
|
|
11301
|
-
if (
|
|
11302
|
-
const blocks = blocksOf(
|
|
12447
|
+
const layerOf = (value) => {
|
|
12448
|
+
const layer = value;
|
|
12449
|
+
const title = typeof layer?.title === "string" ? layer.title.trim() : "";
|
|
12450
|
+
if (layer === void 0 || title.length === 0) return none();
|
|
12451
|
+
const blocks = blocksOf(layer);
|
|
11303
12452
|
return blocks.length === 0 ? none() : some({
|
|
11304
12453
|
title,
|
|
11305
12454
|
blocks
|
|
@@ -11313,54 +12462,57 @@ const parsed = (text) => {
|
|
|
11313
12462
|
return none();
|
|
11314
12463
|
}
|
|
11315
12464
|
};
|
|
11316
|
-
const
|
|
12465
|
+
const readLayers = fn("Cli.readLayers")(function* (text) {
|
|
11317
12466
|
const document = yield* match$2(parsed(text), {
|
|
11318
|
-
onNone: () => new
|
|
12467
|
+
onNone: () => new MalformedLayers({ reason: "the layers is not a JSON object" }),
|
|
11319
12468
|
onSome: succeed
|
|
11320
12469
|
});
|
|
11321
|
-
const raw = document["
|
|
11322
|
-
const
|
|
12470
|
+
const raw = document["layers"];
|
|
12471
|
+
const layers = (Array.isArray(raw) ? raw : []).flatMap((entry) => match$2(layerOf(entry), {
|
|
11323
12472
|
onNone: () => [],
|
|
11324
|
-
onSome: (
|
|
12473
|
+
onSome: (layer) => [layer]
|
|
11325
12474
|
}));
|
|
11326
|
-
if (
|
|
12475
|
+
if (layers.length === 0) return yield* new MalformedLayers({ reason: "every layer needs a title and at least one span or block" });
|
|
11327
12476
|
const summary = document["summary"];
|
|
11328
12477
|
return {
|
|
11329
12478
|
summary: typeof summary === "string" ? summary : "",
|
|
11330
|
-
|
|
12479
|
+
layers
|
|
11331
12480
|
};
|
|
11332
12481
|
});
|
|
11333
12482
|
const fromStored = (stored) => ({
|
|
11334
12483
|
...stored,
|
|
11335
12484
|
parent: fromNullishOr(stored.parent)
|
|
11336
12485
|
});
|
|
11337
|
-
const toStored = (
|
|
11338
|
-
...
|
|
11339
|
-
parent: getOrUndefined$1(
|
|
12486
|
+
const toStored = (layers) => ({
|
|
12487
|
+
...layers,
|
|
12488
|
+
parent: getOrUndefined$1(layers.parent)
|
|
11340
12489
|
});
|
|
11341
|
-
const
|
|
12490
|
+
const reportedLayers = (patches, layers) => {
|
|
11342
12491
|
const present = new Set(patches.map((patch) => patch.path));
|
|
11343
|
-
return withFullCoverage(patches,
|
|
11344
|
-
title:
|
|
11345
|
-
|
|
11346
|
-
|
|
12492
|
+
return withFullCoverage(patches, layers).layers.map((layer) => ({
|
|
12493
|
+
title: layer.title,
|
|
12494
|
+
note: noteOf(layer),
|
|
12495
|
+
files: unique(spansOfLayer(layer).map((span) => span.path)).filter((path) => present.has(path)),
|
|
12496
|
+
spans: spansOfLayer(layer),
|
|
12497
|
+
prose: proseAnchors(layer).filter((anchor) => present.has(anchor.path))
|
|
11347
12498
|
}));
|
|
11348
12499
|
};
|
|
11349
|
-
const reportOf = (patches,
|
|
11350
|
-
const status = statusOf(patches,
|
|
12500
|
+
const reportOf = (patches, layers, branchHead) => {
|
|
12501
|
+
const status = statusOf(patches, layers, branchHead);
|
|
11351
12502
|
return {
|
|
11352
12503
|
version: status.version,
|
|
11353
12504
|
parent: getOrUndefined$1(status.parent),
|
|
11354
|
-
head: status.
|
|
12505
|
+
head: status.layersHead,
|
|
11355
12506
|
branchHead: status.branchHead,
|
|
11356
12507
|
stale: status.stale,
|
|
11357
|
-
|
|
11358
|
-
|
|
12508
|
+
...status.stale ? { advice: STALE_ADVICE } : {},
|
|
12509
|
+
written: layers.written,
|
|
12510
|
+
summary: layers.summary,
|
|
11359
12511
|
covered: status.covered,
|
|
11360
12512
|
total: status.total,
|
|
11361
12513
|
uncovered: status.uncovered,
|
|
11362
12514
|
vanished: status.vanished,
|
|
11363
|
-
|
|
12515
|
+
layers: reportedLayers(patches, layers)
|
|
11364
12516
|
};
|
|
11365
12517
|
};
|
|
11366
12518
|
const resolve = (path) => realpath(path).catch(() => path);
|
|
@@ -11376,17 +12528,17 @@ const worktreeAt = fn("Cli.worktreeAt")(function* (worktreePath) {
|
|
|
11376
12528
|
known: worktrees.map((entry) => entry.path)
|
|
11377
12529
|
}) : succeed(found);
|
|
11378
12530
|
});
|
|
11379
|
-
const
|
|
12531
|
+
const storedLayers = fn("Cli.storedLayers")(function* (worktree) {
|
|
11380
12532
|
const store = yield* Store;
|
|
11381
|
-
return map$4(yield* store.
|
|
12533
|
+
return map$4(yield* store.layers(worktree.path), fromStored);
|
|
11382
12534
|
});
|
|
11383
|
-
const
|
|
12535
|
+
const setLayers = fn("Cli.setLayers")(function* (worktreePath, text, written) {
|
|
11384
12536
|
const store = yield* Store;
|
|
11385
12537
|
const worktree = yield* worktreeAt(worktreePath);
|
|
11386
|
-
const input = yield*
|
|
12538
|
+
const input = yield* readLayers(text);
|
|
11387
12539
|
const patches = yield* patchesOf(worktree);
|
|
11388
|
-
const previous = yield*
|
|
11389
|
-
const
|
|
12540
|
+
const previous = yield* storedLayers(worktree);
|
|
12541
|
+
const layers = {
|
|
11390
12542
|
version: match$2(previous, {
|
|
11391
12543
|
onNone: () => 1,
|
|
11392
12544
|
onSome: (old) => old.version + 1
|
|
@@ -11396,26 +12548,103 @@ const setStory = fn("Cli.setStory")(function* (worktreePath, text, written) {
|
|
|
11396
12548
|
base: worktree.base,
|
|
11397
12549
|
written,
|
|
11398
12550
|
summary: input.summary,
|
|
11399
|
-
|
|
12551
|
+
layers: input.layers
|
|
11400
12552
|
};
|
|
11401
|
-
yield* store.
|
|
11402
|
-
return reportOf(patches,
|
|
12553
|
+
yield* store.saveLayers(worktree.path, toStored(layers));
|
|
12554
|
+
return reportOf(patches, layers, worktree.head);
|
|
11403
12555
|
});
|
|
11404
|
-
const
|
|
12556
|
+
const showLayers = fn("Cli.showLayers")(function* (worktreePath) {
|
|
11405
12557
|
const worktree = yield* worktreeAt(worktreePath);
|
|
11406
12558
|
const patches = yield* patchesOf(worktree);
|
|
11407
|
-
const found = yield*
|
|
11408
|
-
const
|
|
11409
|
-
onNone: () => new
|
|
12559
|
+
const found = yield* storedLayers(worktree);
|
|
12560
|
+
const layers = yield* match$2(found, {
|
|
12561
|
+
onNone: () => new NoLayers({ worktree: worktree.path }),
|
|
11410
12562
|
onSome: succeed
|
|
11411
12563
|
});
|
|
11412
|
-
return reportOf(patches,
|
|
12564
|
+
return reportOf(patches, layers, worktree.head);
|
|
12565
|
+
});
|
|
12566
|
+
const listLayers = fn("Cli.listLayers")(function* (repo, branch) {
|
|
12567
|
+
const worktree = yield* findBranch(repo, branch);
|
|
12568
|
+
const found = yield* storedLayers(worktree);
|
|
12569
|
+
if (isNone(found)) return {
|
|
12570
|
+
layers: [],
|
|
12571
|
+
stale: false
|
|
12572
|
+
};
|
|
12573
|
+
const patches = yield* patchesOf(worktree);
|
|
12574
|
+
return {
|
|
12575
|
+
layers: reportedLayers(patches, found.value),
|
|
12576
|
+
stale: found.value.head !== worktree.head
|
|
12577
|
+
};
|
|
12578
|
+
});
|
|
12579
|
+
//#endregion
|
|
12580
|
+
//#region src/cli/threads.ts
|
|
12581
|
+
const stateOf$1 = (answers, isSettled) => {
|
|
12582
|
+
if (isSettled) return "done";
|
|
12583
|
+
const last = answers.at(-1);
|
|
12584
|
+
if (last === void 0) return "submitted";
|
|
12585
|
+
return last.asks ? "question" : "answered";
|
|
12586
|
+
};
|
|
12587
|
+
const spoken$1 = (entry) => ({
|
|
12588
|
+
body: entry.body,
|
|
12589
|
+
at: entry.at,
|
|
12590
|
+
asks: entry.asks
|
|
12591
|
+
});
|
|
12592
|
+
const threadOf = (comment, batch, reading) => {
|
|
12593
|
+
const mine = reading.answers.filter((entry) => entry.comment === comment.id);
|
|
12594
|
+
return {
|
|
12595
|
+
id: comment.id,
|
|
12596
|
+
file: comment.anchor.path,
|
|
12597
|
+
side: comment.anchor.side,
|
|
12598
|
+
start: comment.anchor.start,
|
|
12599
|
+
end: comment.anchor.end,
|
|
12600
|
+
body: comment.body,
|
|
12601
|
+
state: stateOf$1(mine, Object.hasOwn(reading.settled, comment.id)),
|
|
12602
|
+
stale: batch.head !== reading.head,
|
|
12603
|
+
answers: mine.map(spoken$1)
|
|
12604
|
+
};
|
|
12605
|
+
};
|
|
12606
|
+
const threadsIn = (batches, reading) => batches.flatMap((batch) => batch.comments.map((comment) => threadOf(comment, batch, reading)));
|
|
12607
|
+
const idsIn = (batches) => batches.flatMap((batch) => batch.comments.map((comment) => comment.id));
|
|
12608
|
+
const isKnown = fn("Cli.isKnown")(function* (worktreePath, id) {
|
|
12609
|
+
const store = yield* Store;
|
|
12610
|
+
return idsIn(yield* store.inbox(worktreePath)).includes(id);
|
|
12611
|
+
});
|
|
12612
|
+
const listThreads = fn("Cli.listThreads")(function* (repo, branch) {
|
|
12613
|
+
const store = yield* Store;
|
|
12614
|
+
const worktree = yield* findBranch(repo, branch);
|
|
12615
|
+
const current = yield* store.state(worktree.path);
|
|
12616
|
+
return threadsIn(yield* store.inbox(worktree.path), {
|
|
12617
|
+
answers: yield* store.answers(worktree.path),
|
|
12618
|
+
settled: current.settled,
|
|
12619
|
+
head: worktree.head
|
|
12620
|
+
});
|
|
12621
|
+
});
|
|
12622
|
+
const answerComment = fn("Cli.answerComment")(function* (request) {
|
|
12623
|
+
const store = yield* Store;
|
|
12624
|
+
const worktree = yield* worktreeAt(request.worktree);
|
|
12625
|
+
if (!(yield* isKnown(worktree.path, request.id))) return yield* new UnknownComment({ id: request.id });
|
|
12626
|
+
yield* store.answer(worktree.path, {
|
|
12627
|
+
comment: request.id,
|
|
12628
|
+
body: request.body,
|
|
12629
|
+
head: worktree.head,
|
|
12630
|
+
asks: request.asks,
|
|
12631
|
+
at: request.at
|
|
12632
|
+
});
|
|
12633
|
+
return { answered: (yield* store.answers(worktree.path)).filter((entry) => entry.comment === request.id).length };
|
|
11413
12634
|
});
|
|
11414
|
-
const
|
|
12635
|
+
const settleThread = fn("Cli.settleThread")(function* (repo, branch, id, at) {
|
|
12636
|
+
const store = yield* Store;
|
|
11415
12637
|
const worktree = yield* findBranch(repo, branch);
|
|
11416
|
-
|
|
11417
|
-
|
|
11418
|
-
|
|
12638
|
+
if (!(yield* isKnown(worktree.path, id))) return yield* new UnknownComment({ id });
|
|
12639
|
+
const current = yield* store.state(worktree.path);
|
|
12640
|
+
yield* store.saveState(worktree.path, {
|
|
12641
|
+
...current,
|
|
12642
|
+
settled: {
|
|
12643
|
+
...current.settled,
|
|
12644
|
+
[id]: at
|
|
12645
|
+
}
|
|
12646
|
+
});
|
|
12647
|
+
return { settled: id };
|
|
11419
12648
|
});
|
|
11420
12649
|
//#endregion
|
|
11421
12650
|
//#region src/cli/parse.ts
|
|
@@ -11542,6 +12771,46 @@ const catalog = [
|
|
|
11542
12771
|
dataKey: "pending",
|
|
11543
12772
|
example: "adiff comment stage --repo . --branch cdr-1 --file src/api.ts --start 4 --end 4 --body \"why\""
|
|
11544
12773
|
},
|
|
12774
|
+
{
|
|
12775
|
+
name: "comment edit",
|
|
12776
|
+
about: "Reword a staged comment. It keeps its id and the lines it was written against",
|
|
12777
|
+
safety: "write",
|
|
12778
|
+
options: [
|
|
12779
|
+
repo,
|
|
12780
|
+
branch,
|
|
12781
|
+
{
|
|
12782
|
+
name: "id",
|
|
12783
|
+
required: true,
|
|
12784
|
+
value: "id",
|
|
12785
|
+
about: "The staged comment, as `review progress` reported it"
|
|
12786
|
+
},
|
|
12787
|
+
{
|
|
12788
|
+
name: "body",
|
|
12789
|
+
required: true,
|
|
12790
|
+
value: "text",
|
|
12791
|
+
about: "What it should say instead"
|
|
12792
|
+
}
|
|
12793
|
+
],
|
|
12794
|
+
dataKey: "pending",
|
|
12795
|
+
example: "adiff comment edit --repo . --branch add-teammate-invitations --id c1 --body \"why is this unused\""
|
|
12796
|
+
},
|
|
12797
|
+
{
|
|
12798
|
+
name: "comment drop",
|
|
12799
|
+
about: "Take a staged comment out of the review before it is sent",
|
|
12800
|
+
safety: "write",
|
|
12801
|
+
options: [
|
|
12802
|
+
repo,
|
|
12803
|
+
branch,
|
|
12804
|
+
{
|
|
12805
|
+
name: "id",
|
|
12806
|
+
required: true,
|
|
12807
|
+
value: "id",
|
|
12808
|
+
about: "The staged comment to withdraw"
|
|
12809
|
+
}
|
|
12810
|
+
],
|
|
12811
|
+
dataKey: "pending",
|
|
12812
|
+
example: "adiff comment drop --repo . --branch add-teammate-invitations --id c1"
|
|
12813
|
+
},
|
|
11545
12814
|
{
|
|
11546
12815
|
name: "comment take",
|
|
11547
12816
|
about: "Collect the comments this worktree has not been handed yet. Exactly-once",
|
|
@@ -11560,6 +12829,64 @@ const catalog = [
|
|
|
11560
12829
|
dataKey: "comments",
|
|
11561
12830
|
example: "adiff comment take --worktree . --wait 300"
|
|
11562
12831
|
},
|
|
12832
|
+
{
|
|
12833
|
+
name: "comment answer",
|
|
12834
|
+
about: "Say what was done about a comment, or ask the reviewer something back",
|
|
12835
|
+
safety: "write",
|
|
12836
|
+
options: [
|
|
12837
|
+
{
|
|
12838
|
+
name: "worktree",
|
|
12839
|
+
required: true,
|
|
12840
|
+
value: "path",
|
|
12841
|
+
about: "The worktree the comment was written against"
|
|
12842
|
+
},
|
|
12843
|
+
{
|
|
12844
|
+
name: "id",
|
|
12845
|
+
required: true,
|
|
12846
|
+
value: "id",
|
|
12847
|
+
about: "The comment being answered, as `comment take` reported it"
|
|
12848
|
+
},
|
|
12849
|
+
{
|
|
12850
|
+
name: "body",
|
|
12851
|
+
required: true,
|
|
12852
|
+
value: "text",
|
|
12853
|
+
about: "What was done, or what is being asked"
|
|
12854
|
+
},
|
|
12855
|
+
{
|
|
12856
|
+
name: "asks",
|
|
12857
|
+
required: false,
|
|
12858
|
+
value: "flag",
|
|
12859
|
+
about: "The answer needs a reply before the work continues"
|
|
12860
|
+
}
|
|
12861
|
+
],
|
|
12862
|
+
dataKey: "answered",
|
|
12863
|
+
example: "adiff comment answer --worktree . --id c1 --body \"dropped it, and the import with it\""
|
|
12864
|
+
},
|
|
12865
|
+
{
|
|
12866
|
+
name: "comment threads",
|
|
12867
|
+
about: "Every comment on a branch with its answers and whether it is settled",
|
|
12868
|
+
safety: "read",
|
|
12869
|
+
options: [repo, branch],
|
|
12870
|
+
dataKey: "threads",
|
|
12871
|
+
example: "adiff comment threads --repo . --branch add-teammate-invitations"
|
|
12872
|
+
},
|
|
12873
|
+
{
|
|
12874
|
+
name: "comment resolve",
|
|
12875
|
+
about: "Mark a comment settled. Only the reviewer who raised it can",
|
|
12876
|
+
safety: "write",
|
|
12877
|
+
options: [
|
|
12878
|
+
repo,
|
|
12879
|
+
branch,
|
|
12880
|
+
{
|
|
12881
|
+
name: "id",
|
|
12882
|
+
required: true,
|
|
12883
|
+
value: "id",
|
|
12884
|
+
about: "The comment to settle"
|
|
12885
|
+
}
|
|
12886
|
+
],
|
|
12887
|
+
dataKey: "settled",
|
|
12888
|
+
example: "adiff comment resolve --repo . --branch add-teammate-invitations --id c1"
|
|
12889
|
+
},
|
|
11563
12890
|
{
|
|
11564
12891
|
name: "file vouch",
|
|
11565
12892
|
about: "Toggle a file as reviewed. Lapses on its own when the file changes",
|
|
@@ -11589,26 +12916,26 @@ const catalog = [
|
|
|
11589
12916
|
example: "adiff review progress --repo . --branch cdr-1"
|
|
11590
12917
|
},
|
|
11591
12918
|
{
|
|
11592
|
-
name: "
|
|
11593
|
-
about: "Write the reading order for this worktree's diff: ordered
|
|
12919
|
+
name: "layers set",
|
|
12920
|
+
about: "Write the reading order for this worktree's diff: ordered layers over spans of files",
|
|
11594
12921
|
safety: "write",
|
|
11595
12922
|
options: [{
|
|
11596
12923
|
name: "worktree",
|
|
11597
12924
|
required: true,
|
|
11598
12925
|
value: "path",
|
|
11599
|
-
about: "The worktree the
|
|
12926
|
+
about: "The worktree the layers is about"
|
|
11600
12927
|
}, {
|
|
11601
12928
|
name: "json",
|
|
11602
12929
|
required: true,
|
|
11603
12930
|
value: "file|-",
|
|
11604
|
-
about: "The
|
|
12931
|
+
about: "The layers document, as a file path or - to read stdin"
|
|
11605
12932
|
}],
|
|
11606
|
-
dataKey: "
|
|
11607
|
-
example: "adiff
|
|
12933
|
+
dataKey: "layers",
|
|
12934
|
+
example: "adiff layers set --worktree . --json -"
|
|
11608
12935
|
},
|
|
11609
12936
|
{
|
|
11610
|
-
name: "
|
|
11611
|
-
about: "The
|
|
12937
|
+
name: "layers show",
|
|
12938
|
+
about: "The layers of a worktree, with the hunks no layer claims",
|
|
11612
12939
|
safety: "read",
|
|
11613
12940
|
options: [{
|
|
11614
12941
|
name: "worktree",
|
|
@@ -11616,8 +12943,8 @@ const catalog = [
|
|
|
11616
12943
|
value: "path",
|
|
11617
12944
|
about: "The worktree to read"
|
|
11618
12945
|
}],
|
|
11619
|
-
dataKey: "
|
|
11620
|
-
example: "adiff
|
|
12946
|
+
dataKey: "layers",
|
|
12947
|
+
example: "adiff layers show --worktree . --fields layers,uncovered"
|
|
11621
12948
|
},
|
|
11622
12949
|
{
|
|
11623
12950
|
name: "review open",
|
|
@@ -11671,17 +12998,22 @@ const ADVICE = {
|
|
|
11671
12998
|
},
|
|
11672
12999
|
UnknownWorktree: {
|
|
11673
13000
|
exit: 3,
|
|
11674
|
-
suggestion: "Run `adiff
|
|
13001
|
+
suggestion: "Run `adiff layers set` from inside a worktree of the repository under review.",
|
|
11675
13002
|
retriable: false
|
|
11676
13003
|
},
|
|
11677
|
-
|
|
13004
|
+
MalformedLayers: {
|
|
11678
13005
|
exit: 2,
|
|
11679
|
-
suggestion: "A
|
|
13006
|
+
suggestion: "A layers is {\"summary\":\"…\",\"layers\":[{\"title\":\"…\",\"spans\":[{\"path\":\"…\",\"start\":1,\"end\":9}]}]}.",
|
|
13007
|
+
retriable: false
|
|
13008
|
+
},
|
|
13009
|
+
NoLayers: {
|
|
13010
|
+
exit: 3,
|
|
13011
|
+
suggestion: "No layers has been written for this worktree. Write one with `adiff layers set`.",
|
|
11680
13012
|
retriable: false
|
|
11681
13013
|
},
|
|
11682
|
-
|
|
13014
|
+
UnknownComment: {
|
|
11683
13015
|
exit: 3,
|
|
11684
|
-
suggestion: "No
|
|
13016
|
+
suggestion: "No comment carries that id. `adiff comment take` reports the ids an agent can answer, and `adiff comment threads` reports every id on a branch.",
|
|
11685
13017
|
retriable: false
|
|
11686
13018
|
},
|
|
11687
13019
|
UnselectableRange: {
|
|
@@ -11725,6 +13057,254 @@ const failure = (cause) => {
|
|
|
11725
13057
|
};
|
|
11726
13058
|
};
|
|
11727
13059
|
//#endregion
|
|
13060
|
+
//#region src/cli/help.ts
|
|
13061
|
+
const NAME_ROOM = 18;
|
|
13062
|
+
const REACH = 5;
|
|
13063
|
+
const manifest = () => {
|
|
13064
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
13065
|
+
return Array.from({ length: REACH }, (_, layer) => join(here, ...Array(layer).fill(".."))).map((at) => join(at, "package.json")).find((path) => existsSync(path));
|
|
13066
|
+
};
|
|
13067
|
+
const version = () => {
|
|
13068
|
+
const path = manifest();
|
|
13069
|
+
if (path === void 0) return "unknown";
|
|
13070
|
+
const raw = readFileSync(path, "utf8");
|
|
13071
|
+
return JSON.parse(raw).version ?? "unknown";
|
|
13072
|
+
};
|
|
13073
|
+
const line = (command) => ` ${command.name.padEnd(NAME_ROOM)}${command.about}`;
|
|
13074
|
+
const banner = () => [
|
|
13075
|
+
`adiff ${version()}`,
|
|
13076
|
+
"",
|
|
13077
|
+
"Review the work an agent did in a git worktree, and hand your comments back.",
|
|
13078
|
+
"",
|
|
13079
|
+
" adiff review open --repo . open the terminal on this repository",
|
|
13080
|
+
" adiff comment take --worktree . collect the comments left for you",
|
|
13081
|
+
"",
|
|
13082
|
+
"adiff --help lists every command. adiff describe answers the same as JSON."
|
|
13083
|
+
].join("\n");
|
|
13084
|
+
const help = () => [
|
|
13085
|
+
"adiff, for reviewing an agent's work in a worktree",
|
|
13086
|
+
"",
|
|
13087
|
+
"Commands:",
|
|
13088
|
+
...catalog.map(line),
|
|
13089
|
+
"",
|
|
13090
|
+
"Run `adiff help <command>` for its options."
|
|
13091
|
+
].join("\n");
|
|
13092
|
+
const option = (spec) => ` --${spec.name.padEnd(16)}${spec.about}${spec.required ? " (required)" : ""}`;
|
|
13093
|
+
const helpFor = (name) => {
|
|
13094
|
+
const command = findCommand(name);
|
|
13095
|
+
if (command === void 0) return void 0;
|
|
13096
|
+
const options = command.options.length === 0 ? [] : [
|
|
13097
|
+
"",
|
|
13098
|
+
"Options:",
|
|
13099
|
+
...command.options.map(option)
|
|
13100
|
+
];
|
|
13101
|
+
return [
|
|
13102
|
+
`adiff ${command.name}`,
|
|
13103
|
+
"",
|
|
13104
|
+
command.about,
|
|
13105
|
+
...options
|
|
13106
|
+
].join("\n");
|
|
13107
|
+
};
|
|
13108
|
+
//#endregion
|
|
13109
|
+
//#region src/service/forge/error.ts
|
|
13110
|
+
var ForgeUnavailable = class extends TaggedError("ForgeUnavailable") {};
|
|
13111
|
+
//#endregion
|
|
13112
|
+
//#region src/service/forge/service.ts
|
|
13113
|
+
var Forge = class extends Service()("adiff/Forge") {};
|
|
13114
|
+
const LIMIT = "200";
|
|
13115
|
+
const TIMEOUT_MS = 4e3;
|
|
13116
|
+
const FIELDS = "headRefName,state,isDraft";
|
|
13117
|
+
const decode = decodeUnknownEffect(ArraySchema(Struct({
|
|
13118
|
+
headRefName: String$1,
|
|
13119
|
+
state: String$1,
|
|
13120
|
+
isDraft: Boolean
|
|
13121
|
+
})));
|
|
13122
|
+
const stateOf = (row) => {
|
|
13123
|
+
if (row.isDraft && row.state === "OPEN") return "draft";
|
|
13124
|
+
if (row.state === "MERGED") return "merged";
|
|
13125
|
+
if (row.state === "CLOSED") return "closed";
|
|
13126
|
+
return "open";
|
|
13127
|
+
};
|
|
13128
|
+
const ask = (repo) => callback((resume) => {
|
|
13129
|
+
execFile("gh", [
|
|
13130
|
+
"pr",
|
|
13131
|
+
"list",
|
|
13132
|
+
"--state",
|
|
13133
|
+
"all",
|
|
13134
|
+
"--limit",
|
|
13135
|
+
LIMIT,
|
|
13136
|
+
"--json",
|
|
13137
|
+
FIELDS
|
|
13138
|
+
], {
|
|
13139
|
+
cwd: repo,
|
|
13140
|
+
timeout: TIMEOUT_MS,
|
|
13141
|
+
encoding: "utf8"
|
|
13142
|
+
}, (error, stdout) => {
|
|
13143
|
+
if (error === null) return resume(succeed(stdout));
|
|
13144
|
+
resume(fail(new ForgeUnavailable({
|
|
13145
|
+
repo,
|
|
13146
|
+
reason: error.message
|
|
13147
|
+
})));
|
|
13148
|
+
});
|
|
13149
|
+
});
|
|
13150
|
+
const read = fn("Forge.read")(function* (repo, raw) {
|
|
13151
|
+
const parsed = yield* try_({
|
|
13152
|
+
try: () => JSON.parse(raw),
|
|
13153
|
+
catch: (cause) => new ForgeUnavailable({
|
|
13154
|
+
repo,
|
|
13155
|
+
reason: String(cause)
|
|
13156
|
+
})
|
|
13157
|
+
});
|
|
13158
|
+
return (yield* mapError(decode(parsed), (cause) => new ForgeUnavailable({
|
|
13159
|
+
repo,
|
|
13160
|
+
reason: String(cause)
|
|
13161
|
+
}))).map((row) => ({
|
|
13162
|
+
branch: row.headRefName,
|
|
13163
|
+
state: stateOf(row)
|
|
13164
|
+
}));
|
|
13165
|
+
});
|
|
13166
|
+
const pulls = fn("Forge.pulls")(function* (repo) {
|
|
13167
|
+
const raw = yield* ask(repo);
|
|
13168
|
+
return yield* read(repo, raw);
|
|
13169
|
+
});
|
|
13170
|
+
const ForgeLive = succeed$1(Forge)({ pulls });
|
|
13171
|
+
//#endregion
|
|
13172
|
+
//#region src/tui/gaps.ts
|
|
13173
|
+
const sourceLength = (source) => source.at(-1)?.trim() === "" ? source.length - 1 : source.length;
|
|
13174
|
+
const markerText = (hidden) => `⋯ ${hidden} lines hidden · press l`;
|
|
13175
|
+
const lastNewLine = (patch) => {
|
|
13176
|
+
const found = patch.rows.findLast((row) => isSome(row.newLine));
|
|
13177
|
+
return found === void 0 ? 0 : getOrElse(found.newLine, () => 0);
|
|
13178
|
+
};
|
|
13179
|
+
const spansOf = (patch, total) => {
|
|
13180
|
+
const leading = {
|
|
13181
|
+
lo: 1,
|
|
13182
|
+
hi: (patch.hunks[0]?.newStart ?? 1) - 1
|
|
13183
|
+
};
|
|
13184
|
+
const between = patch.hunks.slice(1).map((hunk) => ({
|
|
13185
|
+
lo: hunk.newStart - hunk.skipped,
|
|
13186
|
+
hi: hunk.newStart - 1
|
|
13187
|
+
}));
|
|
13188
|
+
const trailing = {
|
|
13189
|
+
lo: lastNewLine(patch) + 1,
|
|
13190
|
+
hi: total
|
|
13191
|
+
};
|
|
13192
|
+
return [
|
|
13193
|
+
leading,
|
|
13194
|
+
...between,
|
|
13195
|
+
trailing
|
|
13196
|
+
];
|
|
13197
|
+
};
|
|
13198
|
+
const linesFrom = (build, from, to) => build.full === void 0 || to < from ? [] : build.full.rows.filter((row) => match$2(row.newLine, {
|
|
13199
|
+
onNone: () => false,
|
|
13200
|
+
onSome: (line) => line >= from && line <= to
|
|
13201
|
+
}));
|
|
13202
|
+
const push = (made, row) => {
|
|
13203
|
+
made.rows.push({
|
|
13204
|
+
...row,
|
|
13205
|
+
index: made.rows.length
|
|
13206
|
+
});
|
|
13207
|
+
};
|
|
13208
|
+
const markGap = (made, index, hidden) => {
|
|
13209
|
+
made.gaps.push({
|
|
13210
|
+
index,
|
|
13211
|
+
hidden,
|
|
13212
|
+
row: made.rows.length
|
|
13213
|
+
});
|
|
13214
|
+
push(made, {
|
|
13215
|
+
kind: "context",
|
|
13216
|
+
oldLine: none(),
|
|
13217
|
+
newLine: none(),
|
|
13218
|
+
text: markerText(hidden)
|
|
13219
|
+
});
|
|
13220
|
+
};
|
|
13221
|
+
const openOf = (build, index, count) => {
|
|
13222
|
+
if (build.full === void 0) return 0;
|
|
13223
|
+
const asked = build.reveals.find((entry) => entry.gap === index)?.lines ?? 0;
|
|
13224
|
+
return Math.min(count, Math.max(0, asked));
|
|
13225
|
+
};
|
|
13226
|
+
const countOf = (span) => Math.max(0, span.hi - span.lo + 1);
|
|
13227
|
+
const openAbove = (made, build, index) => {
|
|
13228
|
+
const span = build.spans[index];
|
|
13229
|
+
if (span === void 0) return 0;
|
|
13230
|
+
const count = countOf(span);
|
|
13231
|
+
const open = openOf(build, index, count);
|
|
13232
|
+
const left = count - open;
|
|
13233
|
+
if (left > 0) markGap(made, index, left);
|
|
13234
|
+
for (const row of linesFrom(build, span.hi - open + 1, span.hi)) push(made, row);
|
|
13235
|
+
return left;
|
|
13236
|
+
};
|
|
13237
|
+
const openBelow = (made, build) => {
|
|
13238
|
+
const index = build.base.hunks.length;
|
|
13239
|
+
const span = build.spans[index];
|
|
13240
|
+
if (span === void 0) return;
|
|
13241
|
+
const count = countOf(span);
|
|
13242
|
+
const open = openOf(build, index, count);
|
|
13243
|
+
for (const row of linesFrom(build, span.lo, span.lo + open - 1)) push(made, row);
|
|
13244
|
+
if (count - open > 0) markGap(made, index, count - open);
|
|
13245
|
+
};
|
|
13246
|
+
const makeRows = (build) => {
|
|
13247
|
+
const made = {
|
|
13248
|
+
rows: [],
|
|
13249
|
+
hunks: [],
|
|
13250
|
+
gaps: []
|
|
13251
|
+
};
|
|
13252
|
+
for (const [index, hunk] of build.base.hunks.entries()) {
|
|
13253
|
+
const left = openAbove(made, build, index);
|
|
13254
|
+
const startRow = made.rows.length;
|
|
13255
|
+
for (const row of hunk.rows) push(made, row);
|
|
13256
|
+
made.hunks.push({
|
|
13257
|
+
...hunk,
|
|
13258
|
+
startRow,
|
|
13259
|
+
rows: made.rows.slice(startRow),
|
|
13260
|
+
skipped: index === 0 ? 0 : left
|
|
13261
|
+
});
|
|
13262
|
+
}
|
|
13263
|
+
openBelow(made, build);
|
|
13264
|
+
return made;
|
|
13265
|
+
};
|
|
13266
|
+
const compose = (build) => {
|
|
13267
|
+
const made = makeRows(build);
|
|
13268
|
+
return {
|
|
13269
|
+
patch: {
|
|
13270
|
+
...build.base,
|
|
13271
|
+
rows: made.rows,
|
|
13272
|
+
hunks: made.hunks
|
|
13273
|
+
},
|
|
13274
|
+
gaps: made.gaps
|
|
13275
|
+
};
|
|
13276
|
+
};
|
|
13277
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
13278
|
+
const keyOf$1 = (total, full, reveals) => [
|
|
13279
|
+
total,
|
|
13280
|
+
full === void 0 ? 0 : full.rows.length,
|
|
13281
|
+
reveals.map((entry) => `${entry.gap}-${entry.lines}`).join(",")
|
|
13282
|
+
].join(":");
|
|
13283
|
+
const shownOf = (state) => {
|
|
13284
|
+
const base = state.patches[state.patchIndex];
|
|
13285
|
+
if (base === void 0) return void 0;
|
|
13286
|
+
const full = state.full.find((patch) => patch.path === base.path);
|
|
13287
|
+
const total = sourceLength(state.source);
|
|
13288
|
+
const reveals = state.revealed.filter((entry) => entry.file === base.path);
|
|
13289
|
+
const key = keyOf$1(total, full, reveals);
|
|
13290
|
+
const known = cache.get(base);
|
|
13291
|
+
const found = known?.get(key);
|
|
13292
|
+
if (found !== void 0) return found;
|
|
13293
|
+
const made = compose({
|
|
13294
|
+
base,
|
|
13295
|
+
full,
|
|
13296
|
+
spans: spansOf(base, total),
|
|
13297
|
+
reveals
|
|
13298
|
+
});
|
|
13299
|
+
const map = known ?? /* @__PURE__ */ new Map();
|
|
13300
|
+
map.set(key, made);
|
|
13301
|
+
cache.set(base, map);
|
|
13302
|
+
return made;
|
|
13303
|
+
};
|
|
13304
|
+
const gapAtRow = (state, row) => shownOf(state)?.gaps.find((gap) => gap.row === row);
|
|
13305
|
+
const gapNumbered = (state, index) => shownOf(state)?.gaps.find((gap) => gap.index === index);
|
|
13306
|
+
const gapRowSet = (shown) => new Set(shown.gaps.map((gap) => gap.row));
|
|
13307
|
+
//#endregion
|
|
11728
13308
|
//#region src/tui/tree.ts
|
|
11729
13309
|
const add = (tree, input) => {
|
|
11730
13310
|
const id = tree.nodes.length;
|
|
@@ -11825,7 +13405,7 @@ const visit = (walk, id, depth) => {
|
|
|
11825
13405
|
fileIndex: void 0,
|
|
11826
13406
|
files: filesUnder(walk.tree, last.id)
|
|
11827
13407
|
});
|
|
11828
|
-
if (collapsed.some((
|
|
13408
|
+
if (collapsed.some((layer) => walk.closed.includes(layer.path))) return;
|
|
11829
13409
|
for (const child of last.children) visit(walk, child, depth + 1);
|
|
11830
13410
|
};
|
|
11831
13411
|
const flattenTree = (tree, closed) => {
|
|
@@ -11858,10 +13438,13 @@ const initialState = (branches) => ({
|
|
|
11858
13438
|
patches: [],
|
|
11859
13439
|
patchIndex: 0,
|
|
11860
13440
|
cursor: 0,
|
|
13441
|
+
stop: 0,
|
|
13442
|
+
opened: [],
|
|
11861
13443
|
anchorRow: 0,
|
|
11862
13444
|
selecting: false,
|
|
11863
13445
|
draft: "",
|
|
11864
13446
|
notice: "",
|
|
13447
|
+
waiting: "",
|
|
11865
13448
|
query: "",
|
|
11866
13449
|
paletteIndex: 0,
|
|
11867
13450
|
returnTo: "branches",
|
|
@@ -11871,46 +13454,127 @@ const initialState = (branches) => ({
|
|
|
11871
13454
|
pending: [],
|
|
11872
13455
|
sent: [],
|
|
11873
13456
|
pendingIndex: 0,
|
|
13457
|
+
editing: void 0,
|
|
11874
13458
|
viewport: 20,
|
|
11875
13459
|
context: 3,
|
|
11876
13460
|
top: 0,
|
|
11877
13461
|
source: [],
|
|
13462
|
+
full: [],
|
|
13463
|
+
revealed: [],
|
|
11878
13464
|
focus: "diff",
|
|
11879
13465
|
navOpen: true,
|
|
11880
|
-
|
|
11881
|
-
|
|
13466
|
+
wrap: false,
|
|
13467
|
+
pan: 0,
|
|
13468
|
+
layers: [],
|
|
13469
|
+
layersStale: false,
|
|
13470
|
+
pulls: {},
|
|
13471
|
+
layerIndex: 0,
|
|
13472
|
+
openLayers: [],
|
|
11882
13473
|
rail: "tree"
|
|
11883
13474
|
});
|
|
11884
|
-
const
|
|
11885
|
-
const
|
|
11886
|
-
|
|
11887
|
-
if (
|
|
11888
|
-
|
|
13475
|
+
const onLayers = (state) => state.rail === "layers" && state.layers.length > 0;
|
|
13476
|
+
const selectedLayer = (state) => state.layers[state.layerIndex];
|
|
13477
|
+
const proseFor = (state, path) => {
|
|
13478
|
+
if (!onLayers(state)) return [];
|
|
13479
|
+
const layer = selectedLayer(state);
|
|
13480
|
+
if (layer === void 0) return [];
|
|
13481
|
+
return layer.prose.filter((anchor) => anchor.path === path);
|
|
13482
|
+
};
|
|
13483
|
+
const layerFiles = (state, layerIndex) => {
|
|
13484
|
+
const layer = state.layers[layerIndex];
|
|
13485
|
+
if (layer === void 0) return [];
|
|
13486
|
+
return layer.files.flatMap((path) => {
|
|
11889
13487
|
const at = state.patches.findIndex((patch) => patch.path === path);
|
|
11890
13488
|
return at === -1 ? [] : [at];
|
|
11891
13489
|
});
|
|
11892
13490
|
};
|
|
11893
|
-
const
|
|
11894
|
-
const path = state.patches[fileIndex]?.path;
|
|
11895
|
-
const at = state.
|
|
11896
|
-
return at === -1 ? state.
|
|
11897
|
-
};
|
|
11898
|
-
const
|
|
11899
|
-
|
|
11900
|
-
|
|
11901
|
-
|
|
11902
|
-
|
|
13491
|
+
const layerHolding = (state, fileIndex) => {
|
|
13492
|
+
const path = state.patches[fileIndex]?.path;
|
|
13493
|
+
const at = state.layers.findIndex((layer) => layer.files.includes(path ?? ""));
|
|
13494
|
+
return at === -1 ? state.layerIndex : at;
|
|
13495
|
+
};
|
|
13496
|
+
const layerOpen = (state, layerIndex) => state.openLayers.includes(layerIndex);
|
|
13497
|
+
const chunked = (word, room) => word.length <= room ? [word] : [word.slice(0, room), ...chunked(word.slice(room), room)];
|
|
13498
|
+
const packed = (lines, word, room) => {
|
|
13499
|
+
const last = lines.at(-1);
|
|
13500
|
+
if (last === void 0 || last.length + 1 + word.length > room) return [...lines, word];
|
|
13501
|
+
return [...lines.slice(0, -1), `${last} ${word}`];
|
|
13502
|
+
};
|
|
13503
|
+
const wrapped = (text, room) => {
|
|
13504
|
+
const width = Math.max(1, room);
|
|
13505
|
+
return text.split(/\s+/).filter((word) => word.length > 0).flatMap((word) => chunked(word, width)).reduce((lines, word) => packed(lines, word, width), []);
|
|
13506
|
+
};
|
|
13507
|
+
const NO_NOTE = "no note";
|
|
13508
|
+
const noteRows$1 = (state, layerIndex, room) => {
|
|
13509
|
+
const lines = wrapped(state.layers[layerIndex]?.note ?? "", room);
|
|
13510
|
+
return (lines.length === 0 ? [NO_NOTE] : lines).map((text) => ({
|
|
13511
|
+
index: layerIndex,
|
|
13512
|
+
kind: "note",
|
|
13513
|
+
text,
|
|
13514
|
+
lead: false
|
|
13515
|
+
}));
|
|
13516
|
+
};
|
|
13517
|
+
const proseRow = (layerIndex, text) => ({
|
|
13518
|
+
index: layerIndex,
|
|
13519
|
+
kind: "note",
|
|
13520
|
+
text,
|
|
13521
|
+
lead: false
|
|
13522
|
+
});
|
|
13523
|
+
const proseRows$1 = (state, layerIndex, room) => {
|
|
13524
|
+
const blocks = state.layers[layerIndex]?.prose ?? [];
|
|
13525
|
+
const rows = [];
|
|
13526
|
+
for (const [at, block] of blocks.entries()) {
|
|
13527
|
+
if (at > 0) rows.push(proseRow(layerIndex, ""));
|
|
13528
|
+
for (const text of wrapped(block.markdown, room)) rows.push(proseRow(layerIndex, text));
|
|
13529
|
+
rows.push({
|
|
13530
|
+
index: layerIndex,
|
|
13531
|
+
kind: "file",
|
|
13532
|
+
text: clipEnd(block.path, Math.max(1, room - FILE_LEAD)),
|
|
13533
|
+
lead: false
|
|
13534
|
+
});
|
|
13535
|
+
}
|
|
13536
|
+
return rows;
|
|
13537
|
+
};
|
|
13538
|
+
const titleRows = (state, layerIndex, room) => wrapped(state.layers[layerIndex]?.title ?? "", room).map((text, at) => ({
|
|
13539
|
+
index: layerIndex,
|
|
13540
|
+
kind: "title",
|
|
13541
|
+
text,
|
|
13542
|
+
lead: at === 0
|
|
13543
|
+
}));
|
|
13544
|
+
const clipEnd = (text, room) => {
|
|
13545
|
+
if (text.length <= room) return text;
|
|
13546
|
+
const parts = text.split("/");
|
|
13547
|
+
const kept = [];
|
|
13548
|
+
for (const part of parts.toReversed()) {
|
|
13549
|
+
if ([part, ...kept].join("/").length + 2 > room) break;
|
|
13550
|
+
kept.unshift(part);
|
|
13551
|
+
}
|
|
13552
|
+
return `…/${kept.length === 0 ? parts.at(-1) ?? text : kept.join("/")}`;
|
|
13553
|
+
};
|
|
13554
|
+
const FILE_LEAD = 2;
|
|
13555
|
+
const fileRows = (state, layerIndex, room) => (state.layers[layerIndex]?.files ?? []).map((path) => ({
|
|
13556
|
+
index: layerIndex,
|
|
13557
|
+
kind: "file",
|
|
13558
|
+
text: clipEnd(path, Math.max(1, room - FILE_LEAD)),
|
|
13559
|
+
lead: false
|
|
13560
|
+
}));
|
|
13561
|
+
const layerRows = (state, titleRoom, noteRoom) => state.layers.flatMap((_, index) => layerOpen(state, index) ? [...titleRows(state, index, titleRoom), ...(state.layers[index]?.prose ?? []).length > 0 ? proseRows$1(state, index, noteRoom) : [...noteRows$1(state, index, noteRoom), ...fileRows(state, index, noteRoom)]] : titleRows(state, index, titleRoom));
|
|
13562
|
+
const railWindow = (rows, height, layerIndex) => {
|
|
13563
|
+
if (rows.length <= height) return {
|
|
13564
|
+
rows,
|
|
11903
13565
|
more: 0
|
|
11904
13566
|
};
|
|
11905
|
-
const
|
|
13567
|
+
const first = Math.max(0, rows.findIndex((row) => row.index === layerIndex));
|
|
13568
|
+
const block = rows.findLastIndex((row) => row.index === layerIndex) - first + 1;
|
|
13569
|
+
const wanted = block >= height ? first : first - Math.floor((height - block) / 2);
|
|
13570
|
+
const start = Math.max(0, Math.min(rows.length - height, wanted));
|
|
11906
13571
|
return {
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
more: titles.length - height
|
|
13572
|
+
rows: rows.slice(start, start + height),
|
|
13573
|
+
more: rows.length - height
|
|
11910
13574
|
};
|
|
11911
13575
|
};
|
|
11912
13576
|
const selectedBranch = (state) => state.branches[state.branchIndex];
|
|
11913
|
-
const selectedPatch = (state) => state
|
|
13577
|
+
const selectedPatch = (state) => shownOf(state)?.patch;
|
|
11914
13578
|
const treeOf = (state) => buildTree(state.patches.map((patch) => patch.path));
|
|
11915
13579
|
const treeRows = (state) => {
|
|
11916
13580
|
const tree = treeOf(state);
|
|
@@ -11946,23 +13610,7 @@ const commentsOn = (state, fileIndex) => {
|
|
|
11946
13610
|
if (patch === void 0) return 0;
|
|
11947
13611
|
return state.pending.filter((entry) => entry.file === patch.path).length;
|
|
11948
13612
|
};
|
|
11949
|
-
const
|
|
11950
|
-
const found = patch.rows.find((row) => isSome(row.newLine));
|
|
11951
|
-
return found === void 0 ? 1 : getOrElse(found.newLine, () => 1);
|
|
11952
|
-
};
|
|
11953
|
-
const lastShownLine = (patch) => {
|
|
11954
|
-
const found = patch.rows.findLast((row) => isSome(row.newLine));
|
|
11955
|
-
return found === void 0 ? 0 : getOrElse(found.newLine, () => 0);
|
|
11956
|
-
};
|
|
11957
|
-
const hiddenLines = (state) => {
|
|
11958
|
-
const patch = selectedPatch(state);
|
|
11959
|
-
if (patch === void 0) return 0;
|
|
11960
|
-
const between = patch.hunks.reduce((total, hunk) => total + hunk.skipped, 0);
|
|
11961
|
-
const above = Math.max(0, firstShownLine(patch) - 1);
|
|
11962
|
-
const lines = state.source.at(-1)?.trim() === "" ? state.source.length - 1 : state.source.length;
|
|
11963
|
-
const below = lines === 0 ? 0 : Math.max(0, lines - lastShownLine(patch));
|
|
11964
|
-
return between + above + below;
|
|
11965
|
-
};
|
|
13613
|
+
const hiddenLines = (state) => shownOf(state)?.gaps.reduce((total, gap) => total + gap.hidden, 0) ?? 0;
|
|
11966
13614
|
const markedRows = (state) => {
|
|
11967
13615
|
const patch = selectedPatch(state);
|
|
11968
13616
|
if (patch === void 0) return /* @__PURE__ */ new Set();
|
|
@@ -11982,7 +13630,13 @@ const lineOf = (row) => match$2(row.newLine, {
|
|
|
11982
13630
|
onNone: () => "-",
|
|
11983
13631
|
onSome: (line) => String(line)
|
|
11984
13632
|
});
|
|
13633
|
+
const editedComment = (state) => state.editing === void 0 ? void 0 : state.pending.find((entry) => entry.id === state.editing);
|
|
11985
13634
|
const composeTarget = (state) => {
|
|
13635
|
+
const edited = editedComment(state);
|
|
13636
|
+
if (edited !== void 0) {
|
|
13637
|
+
const span = edited.start === edited.end ? `${edited.start}` : `${edited.start}-${edited.end}`;
|
|
13638
|
+
return `Comment on ${edited.file}:${span}`;
|
|
13639
|
+
}
|
|
11986
13640
|
const patch = selectedPatch(state);
|
|
11987
13641
|
if (patch === void 0) return "";
|
|
11988
13642
|
const [from, to] = selectionRange(state);
|
|
@@ -11998,14 +13652,15 @@ const selectionReadout = (state) => {
|
|
|
11998
13652
|
const lines = to - from + 1;
|
|
11999
13653
|
return `${patch.path} ${lines} lines`;
|
|
12000
13654
|
};
|
|
13655
|
+
const WHOLE_FILE = 1e5;
|
|
12001
13656
|
const CONTEXT_STEPS = [
|
|
12002
13657
|
3,
|
|
12003
13658
|
10,
|
|
12004
13659
|
25,
|
|
12005
13660
|
60,
|
|
12006
|
-
|
|
13661
|
+
WHOLE_FILE
|
|
12007
13662
|
];
|
|
12008
|
-
const
|
|
13663
|
+
const layerContext = (current, delta) => {
|
|
12009
13664
|
const at = CONTEXT_STEPS.indexOf(current);
|
|
12010
13665
|
const next = Math.max(0, Math.min(CONTEXT_STEPS.length - 1, (at === -1 ? 0 : at) + delta));
|
|
12011
13666
|
return CONTEXT_STEPS[next] ?? current;
|
|
@@ -12030,24 +13685,59 @@ const rowAtSourceLine = (patch, line) => {
|
|
|
12030
13685
|
};
|
|
12031
13686
|
const lineOnSide = (row, side) => getOrUndefined$1(side === "old" ? row.oldLine : row.newLine);
|
|
12032
13687
|
const commentRowsIn = (state, fileIndex) => {
|
|
12033
|
-
const patch = state.patches[fileIndex];
|
|
13688
|
+
const patch = fileIndex === state.patchIndex ? selectedPatch(state) : state.patches[fileIndex];
|
|
12034
13689
|
if (patch === void 0) return [];
|
|
12035
13690
|
const notes = [...state.pending, ...state.sent].filter((entry) => entry.file === patch.path);
|
|
12036
13691
|
return patch.rows.filter((row) => notes.some((note) => lineOnSide(row, note.side) === note.end)).map((row) => row.index).toSorted((left, right) => left - right);
|
|
12037
13692
|
};
|
|
13693
|
+
const threadsAtRow = (state, row) => {
|
|
13694
|
+
const patch = selectedPatch(state);
|
|
13695
|
+
const here = patch?.rows[row];
|
|
13696
|
+
if (patch === void 0 || here === void 0) return [];
|
|
13697
|
+
return state.sent.filter((entry) => entry.file === patch.path && entry.id !== void 0 && lineOnSide(here, entry.side) === entry.end);
|
|
13698
|
+
};
|
|
13699
|
+
const stopsAtRow = (state, row) => 1 + threadsAtRow(state, row).length;
|
|
13700
|
+
const threadAtStop = (state) => state.stop === 0 ? void 0 : threadsAtRow(state, state.cursor)[state.stop - 1];
|
|
13701
|
+
const threadAtRow = (state, row) => {
|
|
13702
|
+
const patch = selectedPatch(state);
|
|
13703
|
+
const here = patch?.rows[row];
|
|
13704
|
+
if (patch === void 0 || here === void 0) return void 0;
|
|
13705
|
+
return state.sent.find((entry) => entry.file === patch.path && entry.id !== void 0 && lineOnSide(here, entry.side) === entry.end);
|
|
13706
|
+
};
|
|
13707
|
+
const openCommentRows = (state) => {
|
|
13708
|
+
const patch = selectedPatch(state);
|
|
13709
|
+
if (patch === void 0) return [];
|
|
13710
|
+
const open = [...state.pending, ...state.sent].filter((entry) => entry.file === patch.path && entry.settled !== true);
|
|
13711
|
+
return patch.rows.filter((row) => open.some((note) => lineOnSide(row, note.side) === note.end)).map((row) => row.index);
|
|
13712
|
+
};
|
|
12038
13713
|
const filesWithComments = (state) => state.patches.flatMap((patch, index) => [...state.pending, ...state.sent].some((entry) => entry.file === patch.path) ? [index] : []);
|
|
13714
|
+
const answerCount = (comments) => comments.reduce((total, entry) => total + (entry.answers?.length ?? 0), 0);
|
|
13715
|
+
const spokenSince = (seen, now) => Math.max(0, answerCount(now) - answerCount(seen));
|
|
12039
13716
|
const hunkStarts = (state) => {
|
|
12040
13717
|
const patch = selectedPatch(state);
|
|
12041
13718
|
return patch === void 0 ? [] : patch.hunks.map((hunk) => hunk.startRow);
|
|
12042
13719
|
};
|
|
13720
|
+
const changeAround = (state) => {
|
|
13721
|
+
const rows = selectedPatch(state)?.rows ?? [];
|
|
13722
|
+
const changed = (at) => {
|
|
13723
|
+
const row = rows[at];
|
|
13724
|
+
return row !== void 0 && row.kind !== "context";
|
|
13725
|
+
};
|
|
13726
|
+
if (!changed(state.cursor)) return void 0;
|
|
13727
|
+
let first = state.cursor;
|
|
13728
|
+
let last = state.cursor;
|
|
13729
|
+
while (changed(first - 1)) first -= 1;
|
|
13730
|
+
while (changed(last + 1)) last += 1;
|
|
13731
|
+
return [first, last];
|
|
13732
|
+
};
|
|
12043
13733
|
const nextUnreviewed = (state, from) => {
|
|
12044
13734
|
const order = fileOrder(state);
|
|
12045
13735
|
const start = Math.max(0, order.indexOf(from));
|
|
12046
13736
|
return [...order.slice(start + 1), ...order.slice(0, start + 1)].find((index) => !isReviewed(state, index));
|
|
12047
13737
|
};
|
|
12048
13738
|
const reviewedCount = (state) => `${state.vouched.length}/${state.patches.length} reviewed`;
|
|
12049
|
-
const fileOrder = (state) =>
|
|
12050
|
-
const
|
|
13739
|
+
const fileOrder = (state) => onLayers(state) ? layerFiles(state, state.layerIndex) : treeRows(state).flatMap((row) => row.fileIndex === void 0 ? [] : [row.fileIndex]);
|
|
13740
|
+
const layerFile = (state, delta) => {
|
|
12051
13741
|
const order = fileOrder(state);
|
|
12052
13742
|
const position = order.indexOf(state.patchIndex);
|
|
12053
13743
|
if (position === -1) return order[0] ?? state.patchIndex;
|
|
@@ -12112,12 +13802,38 @@ const buildReport = (state, around) => {
|
|
|
12112
13802
|
].join("\n");
|
|
12113
13803
|
};
|
|
12114
13804
|
//#endregion
|
|
13805
|
+
//#region src/tui/watch.ts
|
|
13806
|
+
const OUTBOX = "outbox.jsonl";
|
|
13807
|
+
const SETTLE_MS = 120;
|
|
13808
|
+
const answered = (name) => name !== null && name.endsWith(OUTBOX);
|
|
13809
|
+
const watchAnswers = (root, arrived) => {
|
|
13810
|
+
const branches = join(root, "branches");
|
|
13811
|
+
let timer;
|
|
13812
|
+
let watcher;
|
|
13813
|
+
try {
|
|
13814
|
+
mkdirSync(branches, { recursive: true });
|
|
13815
|
+
watcher = watch(branches, { recursive: true }, (_event, name) => {
|
|
13816
|
+
if (!answered(name)) return;
|
|
13817
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
13818
|
+
timer = setTimeout(arrived, SETTLE_MS);
|
|
13819
|
+
});
|
|
13820
|
+
watcher.on("error", () => void 0);
|
|
13821
|
+
} catch {
|
|
13822
|
+
watcher = void 0;
|
|
13823
|
+
}
|
|
13824
|
+
return { stop: () => {
|
|
13825
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
13826
|
+
watcher?.close();
|
|
13827
|
+
} };
|
|
13828
|
+
};
|
|
13829
|
+
//#endregion
|
|
12115
13830
|
//#region src/tui/command.ts
|
|
12116
13831
|
const command = (input) => ({
|
|
12117
13832
|
category: "Review",
|
|
12118
13833
|
hint: "",
|
|
12119
13834
|
listed: true,
|
|
12120
13835
|
whenStaged: false,
|
|
13836
|
+
whenLayers: false,
|
|
12121
13837
|
...input
|
|
12122
13838
|
});
|
|
12123
13839
|
const commands = [
|
|
@@ -12249,23 +13965,87 @@ const commands = [
|
|
|
12249
13965
|
screens: ["review"],
|
|
12250
13966
|
hint: "zoom"
|
|
12251
13967
|
}),
|
|
13968
|
+
command({
|
|
13969
|
+
action: "branch.first",
|
|
13970
|
+
title: "Go to the first worktree",
|
|
13971
|
+
category: "Branches",
|
|
13972
|
+
keys: ["g"],
|
|
13973
|
+
screens: ["branches"]
|
|
13974
|
+
}),
|
|
13975
|
+
command({
|
|
13976
|
+
action: "branch.last",
|
|
13977
|
+
title: "Go to the last worktree",
|
|
13978
|
+
category: "Branches",
|
|
13979
|
+
keys: ["G"],
|
|
13980
|
+
screens: ["branches"]
|
|
13981
|
+
}),
|
|
13982
|
+
command({
|
|
13983
|
+
action: "select.hunk",
|
|
13984
|
+
title: "Select the change under the cursor",
|
|
13985
|
+
keys: ["V"],
|
|
13986
|
+
screens: ["review"]
|
|
13987
|
+
}),
|
|
13988
|
+
command({
|
|
13989
|
+
action: "select.swap",
|
|
13990
|
+
title: "Grow the selection from its other end",
|
|
13991
|
+
keys: ["o"],
|
|
13992
|
+
screens: ["review"]
|
|
13993
|
+
}),
|
|
13994
|
+
command({
|
|
13995
|
+
action: "wrap.toggle",
|
|
13996
|
+
title: "Wrap long lines",
|
|
13997
|
+
category: "General",
|
|
13998
|
+
keys: ["w"],
|
|
13999
|
+
screens: ["review"],
|
|
14000
|
+
hint: "wrap"
|
|
14001
|
+
}),
|
|
14002
|
+
command({
|
|
14003
|
+
action: "pan.right",
|
|
14004
|
+
title: "Pan the diff right",
|
|
14005
|
+
keys: [">"],
|
|
14006
|
+
screens: ["review"]
|
|
14007
|
+
}),
|
|
14008
|
+
command({
|
|
14009
|
+
action: "pan.left",
|
|
14010
|
+
title: "Pan the diff left",
|
|
14011
|
+
keys: ["<"],
|
|
14012
|
+
screens: ["review"]
|
|
14013
|
+
}),
|
|
14014
|
+
command({
|
|
14015
|
+
action: "review.reload",
|
|
14016
|
+
title: "Read the branch again",
|
|
14017
|
+
category: "Review",
|
|
14018
|
+
keys: ["r"],
|
|
14019
|
+
screens: ["branches", "review"],
|
|
14020
|
+
hint: "reload"
|
|
14021
|
+
}),
|
|
14022
|
+
command({
|
|
14023
|
+
action: "thread.settle",
|
|
14024
|
+
title: "Settle the thread here",
|
|
14025
|
+
category: "Review",
|
|
14026
|
+
keys: ["d"],
|
|
14027
|
+
screens: ["review"],
|
|
14028
|
+
hint: "settle"
|
|
14029
|
+
}),
|
|
12252
14030
|
command({
|
|
12253
14031
|
action: "rail.toggle",
|
|
12254
|
-
title: "Switch between
|
|
14032
|
+
title: "Switch between layers and files",
|
|
12255
14033
|
category: "Files",
|
|
12256
14034
|
keys: ["s"],
|
|
12257
|
-
screens: ["review"]
|
|
14035
|
+
screens: ["review"],
|
|
14036
|
+
hint: "layers",
|
|
14037
|
+
whenLayers: true
|
|
12258
14038
|
}),
|
|
12259
14039
|
command({
|
|
12260
14040
|
action: "tree.collapse",
|
|
12261
|
-
title: "
|
|
14041
|
+
title: "Close the folder, layer, gap, or settled thread",
|
|
12262
14042
|
category: "Files",
|
|
12263
14043
|
keys: ["h"],
|
|
12264
14044
|
screens: ["review"]
|
|
12265
14045
|
}),
|
|
12266
14046
|
command({
|
|
12267
14047
|
action: "tree.expand",
|
|
12268
|
-
title: "
|
|
14048
|
+
title: "Open the folder, layer, gap, or settled thread",
|
|
12269
14049
|
category: "Files",
|
|
12270
14050
|
keys: ["l"],
|
|
12271
14051
|
screens: ["review"]
|
|
@@ -12347,6 +14127,22 @@ const commands = [
|
|
|
12347
14127
|
hint: "send",
|
|
12348
14128
|
listed: false
|
|
12349
14129
|
}),
|
|
14130
|
+
command({
|
|
14131
|
+
action: "pending.edit",
|
|
14132
|
+
title: "Reword this comment",
|
|
14133
|
+
category: "Review",
|
|
14134
|
+
keys: ["e"],
|
|
14135
|
+
screens: ["pending"],
|
|
14136
|
+
hint: "reword"
|
|
14137
|
+
}),
|
|
14138
|
+
command({
|
|
14139
|
+
action: "pending.drop",
|
|
14140
|
+
title: "Withdraw this comment",
|
|
14141
|
+
category: "Review",
|
|
14142
|
+
keys: ["X"],
|
|
14143
|
+
screens: ["pending"],
|
|
14144
|
+
hint: "withdraw"
|
|
14145
|
+
}),
|
|
12350
14146
|
command({
|
|
12351
14147
|
action: "pending.next",
|
|
12352
14148
|
title: "Next staged comment",
|
|
@@ -12436,7 +14232,7 @@ const displayKey = (key) => {
|
|
|
12436
14232
|
if (key.startsWith("ctrl+")) return `^${key.slice(5)}`;
|
|
12437
14233
|
return GLYPHS[key] ?? key;
|
|
12438
14234
|
};
|
|
12439
|
-
const hintsFor = (screen, staged) => commandsFor(screen).filter((entry) => entry.hint.length > 0).filter((entry) => !entry.whenStaged || staged > 0).map((entry) => ({
|
|
14235
|
+
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) => ({
|
|
12440
14236
|
key: displayKey(entry.keys[0] ?? ""),
|
|
12441
14237
|
hint: entry.hint,
|
|
12442
14238
|
press: entry.keys[0] ?? ""
|
|
@@ -12478,8 +14274,31 @@ const withCursorVisible = (state) => {
|
|
|
12478
14274
|
};
|
|
12479
14275
|
const moveCursor = (state, delta) => withCursorVisible({
|
|
12480
14276
|
...state,
|
|
14277
|
+
stop: 0,
|
|
12481
14278
|
cursor: clamp(state.cursor + delta, 0, lastRow(selectedPatch(state)))
|
|
12482
14279
|
});
|
|
14280
|
+
const stepStop = (state, delta) => {
|
|
14281
|
+
const here = stopsAtRow(state, state.cursor) - 1;
|
|
14282
|
+
if (delta > 0 && state.stop < here) return {
|
|
14283
|
+
...state,
|
|
14284
|
+
stop: state.stop + 1
|
|
14285
|
+
};
|
|
14286
|
+
if (delta < 0 && state.stop > 0) return {
|
|
14287
|
+
...state,
|
|
14288
|
+
stop: state.stop - 1
|
|
14289
|
+
};
|
|
14290
|
+
const row = clamp(state.cursor + delta, 0, lastRow(selectedPatch(state)));
|
|
14291
|
+
if (row === state.cursor) return state;
|
|
14292
|
+
const landing = delta < 0 ? stopsAtRow({
|
|
14293
|
+
...state,
|
|
14294
|
+
cursor: row
|
|
14295
|
+
}, row) - 1 : 0;
|
|
14296
|
+
return withCursorVisible({
|
|
14297
|
+
...state,
|
|
14298
|
+
cursor: row,
|
|
14299
|
+
stop: landing
|
|
14300
|
+
});
|
|
14301
|
+
};
|
|
12483
14302
|
const scrolled = (state, delta) => {
|
|
12484
14303
|
const highest = Math.max(0, rowsIn(state) - Math.max(1, state.viewport));
|
|
12485
14304
|
return {
|
|
@@ -12495,9 +14314,10 @@ const draggedTo = (state, from, to) => ({
|
|
|
12495
14314
|
});
|
|
12496
14315
|
const atRow = (state, row) => withCursorVisible({
|
|
12497
14316
|
...state,
|
|
14317
|
+
stop: 0,
|
|
12498
14318
|
cursor: clamp(row, 0, lastRow(selectedPatch(state)))
|
|
12499
14319
|
});
|
|
12500
|
-
const
|
|
14320
|
+
const layerHunk = (state, delta) => {
|
|
12501
14321
|
const starts = hunkStarts(state);
|
|
12502
14322
|
const target = delta > 0 ? starts.find((start) => start > state.cursor) : starts.findLast((start) => start < state.cursor);
|
|
12503
14323
|
return target === void 0 ? state : atRow(state, target);
|
|
@@ -12520,25 +14340,37 @@ const atComment = (state, file, delta) => {
|
|
|
12520
14340
|
const landing = delta > 0 ? rows[0] : rows.at(-1);
|
|
12521
14341
|
return landing === void 0 ? moved : atRow(moved, landing);
|
|
12522
14342
|
};
|
|
12523
|
-
const
|
|
12524
|
-
const
|
|
14343
|
+
const nothingOpen = (state) => {
|
|
14344
|
+
const any = commentRowsIn(state, state.patchIndex).length > 0;
|
|
14345
|
+
return withNotice(state, any ? "no open comment" : "no comments yet");
|
|
14346
|
+
};
|
|
14347
|
+
const layerComment = (state, delta) => {
|
|
14348
|
+
const here = openCommentRows(state);
|
|
12525
14349
|
const target = delta > 0 ? here.find((row) => row > state.cursor) : here.findLast((row) => row < state.cursor);
|
|
12526
14350
|
if (target !== void 0) return atRow(state, target);
|
|
12527
14351
|
const file = nextFileWithComments(state, delta);
|
|
12528
14352
|
if (file !== void 0) return atComment(state, file, delta);
|
|
12529
|
-
return here.length > 0 ? state :
|
|
14353
|
+
return here.length > 0 ? state : nothingOpen(state);
|
|
14354
|
+
};
|
|
14355
|
+
const PAN_STEP = 8;
|
|
14356
|
+
const panned = (state, delta) => {
|
|
14357
|
+
if (state.wrap) return withNotice(state, "wrapping is on, so there is nothing to pan");
|
|
14358
|
+
return {
|
|
14359
|
+
...state,
|
|
14360
|
+
pan: Math.max(0, state.pan + delta)
|
|
14361
|
+
};
|
|
12530
14362
|
};
|
|
12531
14363
|
const movePending = (state, delta) => ({
|
|
12532
14364
|
...state,
|
|
12533
14365
|
pendingIndex: clamp(state.pendingIndex + delta, 0, Math.max(0, state.pending.length - 1))
|
|
12534
14366
|
});
|
|
12535
|
-
const
|
|
12536
|
-
const
|
|
14367
|
+
const moveLayer = (state, delta) => {
|
|
14368
|
+
const layerIndex = clamp(state.layerIndex + delta, 0, Math.max(0, state.layers.length - 1));
|
|
12537
14369
|
const landed = {
|
|
12538
14370
|
...state,
|
|
12539
|
-
|
|
14371
|
+
layerIndex
|
|
12540
14372
|
};
|
|
12541
|
-
const patchIndex =
|
|
14373
|
+
const patchIndex = layerFiles(landed, layerIndex)[0] ?? landed.patchIndex;
|
|
12542
14374
|
return {
|
|
12543
14375
|
...landed,
|
|
12544
14376
|
patchIndex,
|
|
@@ -12548,18 +14380,18 @@ const moveStep = (state, delta) => {
|
|
|
12548
14380
|
selecting: false
|
|
12549
14381
|
};
|
|
12550
14382
|
};
|
|
12551
|
-
const inRail = (state, delta) =>
|
|
12552
|
-
const
|
|
14383
|
+
const inRail = (state, delta) => onLayers(state) ? moveLayer(state, delta) : moveFile(state, delta);
|
|
14384
|
+
const layerDown = (state, delta) => state.focus === "tree" ? inRail(state, delta) : stepStop(state, delta);
|
|
12553
14385
|
const toggleRail = (state) => {
|
|
12554
|
-
if (state.
|
|
12555
|
-
if (state.rail === "
|
|
14386
|
+
if (state.layers.length === 0) return withNotice(state, "no layers for this branch");
|
|
14387
|
+
if (state.rail === "layers") return {
|
|
12556
14388
|
...state,
|
|
12557
14389
|
rail: "tree"
|
|
12558
14390
|
};
|
|
12559
14391
|
return {
|
|
12560
14392
|
...state,
|
|
12561
|
-
rail: "
|
|
12562
|
-
|
|
14393
|
+
rail: "layers",
|
|
14394
|
+
layerIndex: layerHolding(state, state.patchIndex)
|
|
12563
14395
|
};
|
|
12564
14396
|
};
|
|
12565
14397
|
const foldDirectory = (state, shut) => {
|
|
@@ -12571,18 +14403,56 @@ const foldDirectory = (state, shut) => {
|
|
|
12571
14403
|
closed: shut ? [...closed, directory] : closed
|
|
12572
14404
|
};
|
|
12573
14405
|
};
|
|
14406
|
+
const foldLayer = (state, shut) => {
|
|
14407
|
+
const open = state.openLayers.filter((index) => index !== state.layerIndex);
|
|
14408
|
+
return {
|
|
14409
|
+
...state,
|
|
14410
|
+
openLayers: shut ? open : [...open, state.layerIndex]
|
|
14411
|
+
};
|
|
14412
|
+
};
|
|
14413
|
+
const foldThread = (state, shut, id) => {
|
|
14414
|
+
const rest = state.opened.filter((held) => held !== id);
|
|
14415
|
+
return {
|
|
14416
|
+
...state,
|
|
14417
|
+
opened: shut ? rest : [...rest, id]
|
|
14418
|
+
};
|
|
14419
|
+
};
|
|
14420
|
+
const fold = (state, shut) => {
|
|
14421
|
+
const thread = threadAtStop(state);
|
|
14422
|
+
if (thread?.id !== void 0 && thread.settled === true) return foldThread(state, shut, thread.id);
|
|
14423
|
+
return onLayers(state) ? foldLayer(state, shut) : foldDirectory(state, shut);
|
|
14424
|
+
};
|
|
12574
14425
|
const moveBranch = (state, delta) => ({
|
|
12575
14426
|
...state,
|
|
12576
14427
|
branchIndex: clamp(state.branchIndex + delta, 0, Math.max(0, state.branches.length - 1))
|
|
12577
14428
|
});
|
|
12578
14429
|
const moveFile = (state, delta) => ({
|
|
12579
14430
|
...state,
|
|
12580
|
-
patchIndex:
|
|
14431
|
+
patchIndex: layerFile(state, delta),
|
|
12581
14432
|
top: 0,
|
|
12582
14433
|
cursor: 0,
|
|
12583
14434
|
anchorRow: 0,
|
|
12584
14435
|
selecting: false
|
|
12585
14436
|
});
|
|
14437
|
+
const selectHunk = (state) => {
|
|
14438
|
+
const found = changeAround(state);
|
|
14439
|
+
if (found === void 0) return withNotice(state, "no change under the cursor");
|
|
14440
|
+
return withCursorVisible({
|
|
14441
|
+
...state,
|
|
14442
|
+
selecting: true,
|
|
14443
|
+
anchorRow: found[0],
|
|
14444
|
+
cursor: found[1]
|
|
14445
|
+
});
|
|
14446
|
+
};
|
|
14447
|
+
const swapEnds = (state) => state.selecting ? withCursorVisible({
|
|
14448
|
+
...state,
|
|
14449
|
+
anchorRow: state.cursor,
|
|
14450
|
+
cursor: state.anchorRow
|
|
14451
|
+
}) : state;
|
|
14452
|
+
const atBranch = (state, at) => ({
|
|
14453
|
+
...state,
|
|
14454
|
+
branchIndex: clamp(at, 0, Math.max(0, state.branches.length - 1))
|
|
14455
|
+
});
|
|
12586
14456
|
const startSelection = (state) => ({
|
|
12587
14457
|
...state,
|
|
12588
14458
|
selecting: true,
|
|
@@ -12639,29 +14509,35 @@ const movePalette = (state, delta) => ({
|
|
|
12639
14509
|
const paletteMatches = (state) => searchCommands(state.returnTo, state.query);
|
|
12640
14510
|
const paletteChoice = (state) => paletteMatches(state)[state.paletteIndex]?.action;
|
|
12641
14511
|
const transitions = {
|
|
14512
|
+
"branch.first": (state) => atBranch(state, 0),
|
|
14513
|
+
"branch.last": (state) => atBranch(state, state.branches.length - 1),
|
|
12642
14514
|
"branch.next": (state) => moveBranch(state, 1),
|
|
12643
14515
|
"branch.prev": (state) => moveBranch(state, -1),
|
|
12644
14516
|
"branch.open": (state) => state,
|
|
12645
|
-
"cursor.next": (state) =>
|
|
14517
|
+
"cursor.next": (state) => layerDown(state, 1),
|
|
12646
14518
|
"cursor.top": (state) => atRow(state, 0),
|
|
12647
14519
|
"cursor.bottom": (state) => atRow(state, lastRow(selectedPatch(state))),
|
|
12648
14520
|
"cursor.pageDown": (state) => moveCursor(state, Math.max(1, Math.floor(state.viewport / 2))),
|
|
12649
14521
|
"cursor.pageUp": (state) => moveCursor(state, -Math.max(1, Math.floor(state.viewport / 2))),
|
|
12650
14522
|
"context.more": (state) => state,
|
|
12651
14523
|
"context.less": (state) => state,
|
|
12652
|
-
"comment.next": (state) =>
|
|
12653
|
-
"comment.prev": (state) =>
|
|
12654
|
-
"hunk.next": (state) =>
|
|
12655
|
-
"hunk.prev": (state) =>
|
|
12656
|
-
"cursor.prev": (state) =>
|
|
14524
|
+
"comment.next": (state) => layerComment(state, 1),
|
|
14525
|
+
"comment.prev": (state) => layerComment(state, -1),
|
|
14526
|
+
"hunk.next": (state) => layerHunk(state, 1),
|
|
14527
|
+
"hunk.prev": (state) => layerHunk(state, -1),
|
|
14528
|
+
"cursor.prev": (state) => layerDown(state, -1),
|
|
12657
14529
|
"file.next": (state) => moveFile(state, 1),
|
|
12658
14530
|
"file.prev": (state) => moveFile(state, -1),
|
|
12659
14531
|
"select.start": startSelection,
|
|
14532
|
+
"select.hunk": selectHunk,
|
|
14533
|
+
"select.swap": swapEnds,
|
|
12660
14534
|
"compose.open": openCompose,
|
|
12661
14535
|
"compose.submit": (state) => state,
|
|
12662
14536
|
"compose.stage": (state) => state,
|
|
12663
14537
|
"pending.open": (state) => state,
|
|
12664
14538
|
"pending.submit": (state) => state,
|
|
14539
|
+
"pending.edit": (state) => state,
|
|
14540
|
+
"pending.drop": (state) => state,
|
|
12665
14541
|
"pending.next": (state) => movePending(state, 1),
|
|
12666
14542
|
"pending.prev": (state) => movePending(state, -1),
|
|
12667
14543
|
"compose.newline": (state) => ({
|
|
@@ -12678,11 +14554,20 @@ const transitions = {
|
|
|
12678
14554
|
navOpen: !state.navOpen,
|
|
12679
14555
|
focus: "diff"
|
|
12680
14556
|
}),
|
|
14557
|
+
"wrap.toggle": (state) => ({
|
|
14558
|
+
...state,
|
|
14559
|
+
wrap: !state.wrap,
|
|
14560
|
+
pan: 0
|
|
14561
|
+
}),
|
|
14562
|
+
"pan.right": (state) => panned(state, PAN_STEP),
|
|
14563
|
+
"pan.left": (state) => panned(state, -8),
|
|
14564
|
+
"review.reload": (state) => state,
|
|
14565
|
+
"thread.settle": (state) => state,
|
|
12681
14566
|
"rail.toggle": toggleRail,
|
|
12682
14567
|
"file.vouch": (state) => state,
|
|
12683
14568
|
"file.vouch.next": (state) => state,
|
|
12684
|
-
"tree.collapse": (state) =>
|
|
12685
|
-
"tree.expand": (state) =>
|
|
14569
|
+
"tree.collapse": (state) => fold(state, true),
|
|
14570
|
+
"tree.expand": (state) => fold(state, false),
|
|
12686
14571
|
"report.open": (state) => ({
|
|
12687
14572
|
...state,
|
|
12688
14573
|
screen: "report",
|
|
@@ -12707,10 +14592,40 @@ const withContext = (state, context, patches, cursor) => ({
|
|
|
12707
14592
|
...state,
|
|
12708
14593
|
context,
|
|
12709
14594
|
patches,
|
|
14595
|
+
revealed: [],
|
|
12710
14596
|
cursor,
|
|
12711
14597
|
anchorRow: cursor,
|
|
12712
14598
|
selecting: false
|
|
12713
14599
|
});
|
|
14600
|
+
const withFull = (state, full) => ({
|
|
14601
|
+
...state,
|
|
14602
|
+
full
|
|
14603
|
+
});
|
|
14604
|
+
const revealsAfter = (state, gap, lines) => {
|
|
14605
|
+
const path = state.patches[state.patchIndex]?.path ?? "";
|
|
14606
|
+
const others = state.revealed.filter((entry) => entry.file !== path || entry.gap !== gap);
|
|
14607
|
+
return lines <= 0 ? others : [...others, {
|
|
14608
|
+
file: path,
|
|
14609
|
+
gap,
|
|
14610
|
+
lines
|
|
14611
|
+
}];
|
|
14612
|
+
};
|
|
14613
|
+
const gapOpened = (state, gap, delta) => {
|
|
14614
|
+
const path = state.patches[state.patchIndex]?.path ?? "";
|
|
14615
|
+
const now = state.revealed.find((entry) => entry.file === path && entry.gap === gap)?.lines ?? 0;
|
|
14616
|
+
const opened = {
|
|
14617
|
+
...state,
|
|
14618
|
+
revealed: revealsAfter(state, gap, now + delta)
|
|
14619
|
+
};
|
|
14620
|
+
const wanted = gapNumbered(opened, gap)?.row ?? state.cursor;
|
|
14621
|
+
const landed = clamp(wanted, 0, lastRow(selectedPatch(opened)));
|
|
14622
|
+
return withCursorVisible({
|
|
14623
|
+
...opened,
|
|
14624
|
+
cursor: landed,
|
|
14625
|
+
anchorRow: landed,
|
|
14626
|
+
selecting: false
|
|
14627
|
+
});
|
|
14628
|
+
};
|
|
12714
14629
|
const withPending = (state, pending, screen) => ({
|
|
12715
14630
|
...state,
|
|
12716
14631
|
pending,
|
|
@@ -12718,25 +14633,36 @@ const withPending = (state, pending, screen) => ({
|
|
|
12718
14633
|
staged: pending.length,
|
|
12719
14634
|
screen
|
|
12720
14635
|
});
|
|
14636
|
+
const panBy = (state, delta) => state.wrap ? state : {
|
|
14637
|
+
...state,
|
|
14638
|
+
pan: Math.max(0, state.pan + delta)
|
|
14639
|
+
};
|
|
12721
14640
|
const withSent = (state, sent) => ({
|
|
12722
14641
|
...state,
|
|
12723
14642
|
sent
|
|
12724
14643
|
});
|
|
12725
|
-
const
|
|
14644
|
+
const withLayers = (state, told) => {
|
|
14645
|
+
const layers = told.layers;
|
|
12726
14646
|
const opened = {
|
|
12727
14647
|
...state,
|
|
12728
|
-
|
|
12729
|
-
|
|
12730
|
-
|
|
14648
|
+
layers,
|
|
14649
|
+
layersStale: told.stale,
|
|
14650
|
+
layerIndex: 0,
|
|
14651
|
+
openLayers: [],
|
|
14652
|
+
rail: layers.length === 0 ? "tree" : "layers"
|
|
12731
14653
|
};
|
|
12732
|
-
if (
|
|
14654
|
+
if (layers.length === 0) return opened;
|
|
12733
14655
|
return {
|
|
12734
14656
|
...opened,
|
|
12735
|
-
patchIndex:
|
|
14657
|
+
patchIndex: layerFiles(opened, 0)[0] ?? opened.patchIndex,
|
|
12736
14658
|
cursor: 0,
|
|
12737
14659
|
top: 0
|
|
12738
14660
|
};
|
|
12739
14661
|
};
|
|
14662
|
+
const withPulls = (state, pulls) => ({
|
|
14663
|
+
...state,
|
|
14664
|
+
pulls
|
|
14665
|
+
});
|
|
12740
14666
|
const withBranches = (state, branches) => ({
|
|
12741
14667
|
...state,
|
|
12742
14668
|
branches,
|
|
@@ -12750,10 +14676,22 @@ const withVouched = (state, vouched) => ({
|
|
|
12750
14676
|
...state,
|
|
12751
14677
|
vouched
|
|
12752
14678
|
});
|
|
14679
|
+
const restoredTo = (state, path, line) => {
|
|
14680
|
+
const index = state.patches.findIndex((patch) => patch.path === path);
|
|
14681
|
+
const patch = state.patches[index];
|
|
14682
|
+
if (patch === void 0) return state;
|
|
14683
|
+
return withCursorVisible({
|
|
14684
|
+
...state,
|
|
14685
|
+
patchIndex: index,
|
|
14686
|
+
cursor: line === void 0 ? 0 : rowAtSourceLine(patch, line)
|
|
14687
|
+
});
|
|
14688
|
+
};
|
|
12753
14689
|
const withPatches = (state, patches) => ({
|
|
12754
14690
|
...state,
|
|
12755
14691
|
screen: "review",
|
|
12756
14692
|
patches,
|
|
14693
|
+
full: [],
|
|
14694
|
+
revealed: [],
|
|
12757
14695
|
closed: crowdedOf(patches),
|
|
12758
14696
|
patchIndex: fileOrder({
|
|
12759
14697
|
...state,
|
|
@@ -12786,6 +14724,14 @@ const paletteClosed = (state) => ({
|
|
|
12786
14724
|
screen: state.returnTo,
|
|
12787
14725
|
query: ""
|
|
12788
14726
|
});
|
|
14727
|
+
const withWaiting = (state, waiting) => ({
|
|
14728
|
+
...state,
|
|
14729
|
+
waiting
|
|
14730
|
+
});
|
|
14731
|
+
const withNoticeHere = (state, notice) => ({
|
|
14732
|
+
...state,
|
|
14733
|
+
notice
|
|
14734
|
+
});
|
|
12789
14735
|
const withNotice = (state, notice) => ({
|
|
12790
14736
|
...state,
|
|
12791
14737
|
screen: "review",
|
|
@@ -12937,10 +14883,12 @@ const syntaxTheme = {
|
|
|
12937
14883
|
punctuation: { fg: inkFaint },
|
|
12938
14884
|
"punctuation.bracket": { fg: inkFaint },
|
|
12939
14885
|
"punctuation.delimiter": { fg: inkFaint },
|
|
14886
|
+
gap: { fg: inkFaint },
|
|
12940
14887
|
note: {
|
|
12941
14888
|
fg: "#9aa7c7",
|
|
12942
14889
|
italic: true
|
|
12943
14890
|
},
|
|
14891
|
+
prose: { fg: "#a9b4cc" },
|
|
12944
14892
|
"note.sent": {
|
|
12945
14893
|
fg: "#6d7893",
|
|
12946
14894
|
italic: true
|
|
@@ -12961,9 +14909,37 @@ const WASH = {
|
|
|
12961
14909
|
}
|
|
12962
14910
|
};
|
|
12963
14911
|
const NOTE_MIN = 24;
|
|
14912
|
+
const ANSWER_MARK = "↳";
|
|
12964
14913
|
const OVERSCAN = 2;
|
|
12965
14914
|
const SIGN_WIDTH = 2;
|
|
12966
14915
|
const SCROLL_ROWS = 3;
|
|
14916
|
+
const PAN_COLUMNS = 8;
|
|
14917
|
+
const WAYS = {
|
|
14918
|
+
up: {
|
|
14919
|
+
step: -1,
|
|
14920
|
+
across: false
|
|
14921
|
+
},
|
|
14922
|
+
down: {
|
|
14923
|
+
step: 1,
|
|
14924
|
+
across: false
|
|
14925
|
+
},
|
|
14926
|
+
left: {
|
|
14927
|
+
step: -1,
|
|
14928
|
+
across: true
|
|
14929
|
+
},
|
|
14930
|
+
right: {
|
|
14931
|
+
step: 1,
|
|
14932
|
+
across: true
|
|
14933
|
+
}
|
|
14934
|
+
};
|
|
14935
|
+
const notchesIn = (event) => Math.max(1, event.scroll?.delta ?? 1);
|
|
14936
|
+
const wheelTo = (event, handlers) => {
|
|
14937
|
+
const way = WAYS[event.scroll?.direction ?? ""];
|
|
14938
|
+
if (way === void 0) return;
|
|
14939
|
+
const step = way.step * notchesIn(event);
|
|
14940
|
+
if (way.across || event.modifiers?.shift === true) handlers.pan(step * PAN_COLUMNS);
|
|
14941
|
+
else handlers.scroll(step * SCROLL_ROWS);
|
|
14942
|
+
};
|
|
12967
14943
|
const SIGNS = {
|
|
12968
14944
|
added: {
|
|
12969
14945
|
text: " +",
|
|
@@ -12990,6 +14966,8 @@ var DiffView = class {
|
|
|
12990
14966
|
display = [];
|
|
12991
14967
|
starts = /* @__PURE__ */ new Map();
|
|
12992
14968
|
fitted = 1;
|
|
14969
|
+
wrapped = false;
|
|
14970
|
+
held = 0;
|
|
12993
14971
|
constructor(renderer) {
|
|
12994
14972
|
this.code = new CodeRenderable(renderer, {
|
|
12995
14973
|
id: "diff-code",
|
|
@@ -13056,10 +15034,7 @@ var DiffView = class {
|
|
|
13056
15034
|
return this.numbers;
|
|
13057
15035
|
}
|
|
13058
15036
|
listenTo(handlers) {
|
|
13059
|
-
this.numbers.onMouseScroll = (event) =>
|
|
13060
|
-
const size = Math.max(1, event.scroll?.delta ?? 1) * SCROLL_ROWS;
|
|
13061
|
-
handlers.scroll(event.scroll?.direction === "up" ? -size : size);
|
|
13062
|
-
};
|
|
15037
|
+
this.numbers.onMouseScroll = (event) => wheelTo(event, handlers);
|
|
13063
15038
|
this.numbers.onMouseDown = (event) => handlers.down(event.y);
|
|
13064
15039
|
this.numbers.onMouseDrag = (event) => handlers.drag(event.y);
|
|
13065
15040
|
this.numbers.onMouseDragEnd = (event) => handlers.dragEnd(event.y);
|
|
@@ -13085,36 +15060,114 @@ var DiffView = class {
|
|
|
13085
15060
|
rows() {
|
|
13086
15061
|
return this.fitted;
|
|
13087
15062
|
}
|
|
13088
|
-
show(patch, notes) {
|
|
13089
|
-
const room = notes.length === 0 ? NOTE_MIN : this.noteRoom();
|
|
13090
|
-
const key =
|
|
15063
|
+
show(patch, notes, gaps, prose = []) {
|
|
15064
|
+
const room = notes.length === 0 && prose.length === 0 ? NOTE_MIN : this.noteRoom();
|
|
15065
|
+
const key = keyOf(room, notes, prose);
|
|
13091
15066
|
if (patch === this.shown && key === this.noted) return;
|
|
13092
15067
|
this.pinnedText = "";
|
|
13093
15068
|
this.shown = patch;
|
|
13094
15069
|
this.noted = key;
|
|
13095
|
-
this.display = layout(
|
|
13096
|
-
|
|
13097
|
-
|
|
15070
|
+
this.display = layout({
|
|
15071
|
+
patch,
|
|
15072
|
+
notes,
|
|
15073
|
+
room,
|
|
15074
|
+
gaps,
|
|
15075
|
+
prose
|
|
15076
|
+
});
|
|
15077
|
+
this.starts = startsOf(this.display);
|
|
13098
15078
|
this.code.filetype = pathToFiletype(patch.path) ?? "text";
|
|
13099
|
-
this.
|
|
15079
|
+
this.feed();
|
|
13100
15080
|
this.numbers.setLineNumbers(lineNumbers(patch, this.display));
|
|
13101
|
-
this.numbers.setHideLineNumbers(
|
|
15081
|
+
this.numbers.setHideLineNumbers(bareOf(this.display));
|
|
13102
15082
|
this.numbers.setLineSigns(lineSigns(patch, this.display));
|
|
13103
15083
|
this.numbers.setLineColors(/* @__PURE__ */ new Map());
|
|
13104
|
-
|
|
15084
|
+
}
|
|
15085
|
+
feed() {
|
|
15086
|
+
const spans = noteSpans(this.display, this.held);
|
|
15087
|
+
this.code.content = textAt(this.display, this.held);
|
|
13105
15088
|
this.code.onHighlight = (highlights) => [...highlights.filter((highlight) => !spans.some(([from, to]) => highlight[0] < to && highlight[1] > from)), ...spans];
|
|
13106
15089
|
}
|
|
13107
|
-
|
|
13108
|
-
|
|
15090
|
+
setWrap(on) {
|
|
15091
|
+
if (on !== this.wrapped) {
|
|
15092
|
+
this.wrapped = on;
|
|
15093
|
+
this.code.wrapMode = on ? "word" : "none";
|
|
15094
|
+
this.code.requestRender();
|
|
15095
|
+
this.numbers.requestRender();
|
|
15096
|
+
}
|
|
15097
|
+
this.fitWrapWidth();
|
|
15098
|
+
}
|
|
15099
|
+
setPan(columns) {
|
|
15100
|
+
const wanted = this.wrapped ? 0 : Math.max(0, Math.min(this.code.maxScrollX, columns));
|
|
15101
|
+
if (wanted !== this.held) {
|
|
15102
|
+
this.held = wanted;
|
|
15103
|
+
this.feed();
|
|
15104
|
+
}
|
|
15105
|
+
if (this.code.scrollX !== wanted) this.code.scrollX = wanted;
|
|
15106
|
+
if (this.pinned.scrollX !== wanted) this.pinned.scrollX = wanted;
|
|
15107
|
+
}
|
|
15108
|
+
panned() {
|
|
15109
|
+
return this.code.scrollX;
|
|
15110
|
+
}
|
|
15111
|
+
fitWrapWidth() {
|
|
15112
|
+
const room = this.numbers.width - Math.max(0, this.code.x - this.numbers.x);
|
|
15113
|
+
const wanted = this.wrapped && room > 0 ? room : "100%";
|
|
15114
|
+
if (this.code.width !== wanted) this.code.width = wanted;
|
|
15115
|
+
}
|
|
15116
|
+
sources() {
|
|
15117
|
+
const reported = this.code.lineInfo?.lineSources;
|
|
15118
|
+
return this.wrapped && reported !== void 0 && reported.length > 0 ? reported : [];
|
|
15119
|
+
}
|
|
15120
|
+
lineAt(visual) {
|
|
15121
|
+
const sources = this.sources();
|
|
15122
|
+
if (sources.length === 0) return visual;
|
|
15123
|
+
return sources[Math.max(0, Math.min(sources.length - 1, visual))] ?? visual;
|
|
15124
|
+
}
|
|
15125
|
+
visualOf(line) {
|
|
15126
|
+
const sources = this.sources();
|
|
15127
|
+
if (sources.length === 0) return line;
|
|
15128
|
+
let low = 0;
|
|
15129
|
+
let high = sources.length;
|
|
15130
|
+
while (low < high) {
|
|
15131
|
+
const mid = low + high >> 1;
|
|
15132
|
+
if ((sources[mid] ?? 0) < line) low = mid + 1;
|
|
15133
|
+
else high = mid;
|
|
15134
|
+
}
|
|
15135
|
+
return low;
|
|
15136
|
+
}
|
|
15137
|
+
tallest() {
|
|
15138
|
+
return this.sources().length === 0 ? this.display.length : this.sources().length;
|
|
15139
|
+
}
|
|
15140
|
+
drawn() {
|
|
15141
|
+
return this.tallest();
|
|
15142
|
+
}
|
|
15143
|
+
rowAt(visual) {
|
|
15144
|
+
const line = this.lineAt(visual);
|
|
15145
|
+
const at = Math.max(0, Math.min(this.display.length - 1, line));
|
|
13109
15146
|
return this.display[at]?.row ?? 0;
|
|
13110
15147
|
}
|
|
13111
|
-
|
|
13112
|
-
return this.display[
|
|
15148
|
+
stopAt(visual) {
|
|
15149
|
+
return this.display[this.lineAt(visual)]?.stop ?? 0;
|
|
15150
|
+
}
|
|
15151
|
+
carries(visual) {
|
|
15152
|
+
const entry = this.display[this.lineAt(visual)];
|
|
15153
|
+
if (entry === void 0) return false;
|
|
15154
|
+
if (entry.prose) return false;
|
|
15155
|
+
return true;
|
|
15156
|
+
}
|
|
15157
|
+
isComment(visual) {
|
|
15158
|
+
const entry = this.display[this.lineAt(visual)];
|
|
15159
|
+
return entry?.comment === true || entry?.prose === true;
|
|
15160
|
+
}
|
|
15161
|
+
isRunOn(visual) {
|
|
15162
|
+
const sources = this.sources();
|
|
15163
|
+
if (sources.length === 0) return false;
|
|
15164
|
+
return visual > 0 && sources[visual] === sources[visual - 1];
|
|
13113
15165
|
}
|
|
13114
15166
|
scrollTo(row, cursor) {
|
|
13115
|
-
const highest = Math.max(0, this.
|
|
13116
|
-
const wanted = this.starts.get(row) ?? row;
|
|
13117
|
-
const
|
|
15167
|
+
const highest = Math.max(0, this.tallest() - this.rows());
|
|
15168
|
+
const wanted = this.visualOf(this.starts.get(row) ?? row);
|
|
15169
|
+
const line = this.starts.get(cursor);
|
|
15170
|
+
const at = line === void 0 ? void 0 : this.visualOf(line);
|
|
13118
15171
|
const kept = cursor >= row && cursor < row + this.rows() && at !== void 0 ? Math.max(wanted, at - this.rows() + 1) : wanted;
|
|
13119
15172
|
const clamped = Math.max(0, Math.min(highest, kept));
|
|
13120
15173
|
if (this.code.scrollY !== clamped) this.code.scrollY = clamped;
|
|
@@ -13122,11 +15175,12 @@ var DiffView = class {
|
|
|
13122
15175
|
}
|
|
13123
15176
|
paint(paintOf, from, rows) {
|
|
13124
15177
|
const colors = /* @__PURE__ */ new Map();
|
|
13125
|
-
const
|
|
13126
|
-
|
|
15178
|
+
const first = this.lineAt(Math.max(0, from - OVERSCAN));
|
|
15179
|
+
const last = Math.min(this.display.length, this.lineAt(from + rows + OVERSCAN) + 1);
|
|
15180
|
+
for (let index = first; index < last; index++) {
|
|
13127
15181
|
const entry = this.display[index];
|
|
13128
15182
|
if (entry === void 0) continue;
|
|
13129
|
-
const paint = entry.comment ? NOTE_PAINT : paintOf(entry.row);
|
|
15183
|
+
const paint = entry.comment || entry.prose ? NOTE_PAINT : paintOf(entry.row);
|
|
13130
15184
|
if (paint !== void 0) colors.set(index, paint);
|
|
13131
15185
|
}
|
|
13132
15186
|
this.numbers.setLineColors(colors);
|
|
@@ -13135,19 +15189,39 @@ var DiffView = class {
|
|
|
13135
15189
|
return WASH[kind];
|
|
13136
15190
|
}
|
|
13137
15191
|
};
|
|
13138
|
-
const
|
|
15192
|
+
const startsOf = (display) => {
|
|
15193
|
+
const starts = /* @__PURE__ */ new Map();
|
|
15194
|
+
for (const [index, entry] of display.entries()) if (!entry.comment && !starts.has(entry.row)) starts.set(entry.row, index);
|
|
15195
|
+
return starts;
|
|
15196
|
+
};
|
|
15197
|
+
const bareOf = (display) => new Set(display.flatMap((entry, index) => entry.comment || entry.gap || entry.prose ? [index] : []));
|
|
15198
|
+
const keyOf = (room, notes, prose) => [
|
|
15199
|
+
room,
|
|
15200
|
+
...notes.map((note) => `${note.side}${note.line}:${note.folded ? "-" : "+"}${note.body}`),
|
|
15201
|
+
...prose.map((entry) => `p${entry.line}${entry.after ? ">" : "<"}:${entry.markdown}`)
|
|
15202
|
+
].join("\0");
|
|
15203
|
+
const groupOf = (entry) => {
|
|
15204
|
+
if (entry.prose) return "prose";
|
|
15205
|
+
if (entry.gap) return "gap";
|
|
15206
|
+
if (!entry.comment) return void 0;
|
|
15207
|
+
if (entry.label) return "note.label";
|
|
15208
|
+
return entry.sent ? "note.sent" : "note";
|
|
15209
|
+
};
|
|
15210
|
+
const isChrome = (entry) => entry.comment || entry.gap || entry.prose;
|
|
15211
|
+
const heldAt = (entry, pan) => isChrome(entry) && pan > 0 ? `${" ".repeat(pan)}${entry.text}` : entry.text;
|
|
15212
|
+
const textAt = (display, pan) => display.map((entry) => heldAt(entry, pan)).join("\n");
|
|
15213
|
+
const noteSpans = (display, pan) => {
|
|
13139
15214
|
const spans = [];
|
|
13140
15215
|
let at = 0;
|
|
13141
15216
|
for (const entry of display) {
|
|
13142
|
-
|
|
13143
|
-
|
|
13144
|
-
|
|
13145
|
-
|
|
13146
|
-
|
|
13147
|
-
|
|
13148
|
-
|
|
13149
|
-
|
|
13150
|
-
at += entry.text.length + 1;
|
|
15217
|
+
const group = groupOf(entry);
|
|
15218
|
+
const width = heldAt(entry, pan).length;
|
|
15219
|
+
if (group !== void 0) spans.push([
|
|
15220
|
+
at,
|
|
15221
|
+
at + width,
|
|
15222
|
+
group
|
|
15223
|
+
]);
|
|
15224
|
+
at += width + 1;
|
|
13151
15225
|
}
|
|
13152
15226
|
return spans;
|
|
13153
15227
|
};
|
|
@@ -13166,50 +15240,92 @@ const wrap = (text, room) => {
|
|
|
13166
15240
|
}
|
|
13167
15241
|
return lines;
|
|
13168
15242
|
};
|
|
13169
|
-
const
|
|
13170
|
-
const
|
|
15243
|
+
const headOf = (note) => {
|
|
15244
|
+
const moved = note.stale ? ", the branch moved on" : "";
|
|
15245
|
+
if (note.settled) return `${marks().sent} settled${moved}`;
|
|
15246
|
+
if (note.asks) return `${marks().staged} asked back${moved}`;
|
|
15247
|
+
if (note.answers.length > 0) return `${marks().sent} answered${moved}`;
|
|
15248
|
+
if (note.sent) return `${marks().sent} sent${moved}`;
|
|
15249
|
+
return `${marks().staged} staged`;
|
|
15250
|
+
};
|
|
15251
|
+
const spokenLines = (body, room) => {
|
|
15252
|
+
return wrap(body.replaceAll("\n", " "), Math.max(NOTE_MIN, room - 2)).map((text, at) => at === 0 ? `${ANSWER_MARK} ${text}` : ` ${text}`);
|
|
15253
|
+
};
|
|
15254
|
+
const answerLines = (note, room) => note.answers.flatMap((body) => spokenLines(body, room));
|
|
15255
|
+
const noteLines = (note, room) => note.folded ? [`${headOf(note)} · press l`] : [
|
|
15256
|
+
headOf(note),
|
|
15257
|
+
...note.body.split("\n").flatMap((line) => wrap(line, room)),
|
|
15258
|
+
...answerLines(note, room)
|
|
15259
|
+
];
|
|
15260
|
+
const noteRows = (note, row, room, stop) => noteLines(note, room).map((line, index) => ({
|
|
13171
15261
|
text: `${marks().rule} ${line}`,
|
|
13172
15262
|
row,
|
|
15263
|
+
stop,
|
|
13173
15264
|
comment: true,
|
|
13174
15265
|
sent: note.sent,
|
|
13175
|
-
label: index === 0
|
|
15266
|
+
label: index === 0,
|
|
15267
|
+
gap: false,
|
|
15268
|
+
prose: false
|
|
13176
15269
|
}));
|
|
13177
|
-
const
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13189
|
-
return
|
|
13190
|
-
|
|
15270
|
+
const proseRows = (entry, row, room) => [...entry.markdown.split("\n").flatMap((line) => wrap(line, room - 2)), ""].map((line) => ({
|
|
15271
|
+
text: line.length === 0 ? "" : ` ${line}`,
|
|
15272
|
+
row,
|
|
15273
|
+
stop: 0,
|
|
15274
|
+
comment: false,
|
|
15275
|
+
sent: false,
|
|
15276
|
+
label: false,
|
|
15277
|
+
gap: false,
|
|
15278
|
+
prose: true
|
|
15279
|
+
}));
|
|
15280
|
+
const proseAt = (plan, row, after) => {
|
|
15281
|
+
const line = sideLineOf(row, "new");
|
|
15282
|
+
if (line === void 0) return [];
|
|
15283
|
+
return plan.prose.filter((entry) => entry.after === after && entry.line === line);
|
|
15284
|
+
};
|
|
15285
|
+
const notesAt = (plan, row) => plan.notes.filter((note) => sideLineOf(row, note.side) === note.line).flatMap((note, at) => noteRows(note, row.index, plan.room, at + 1));
|
|
15286
|
+
const codeRow = (plan, row) => ({
|
|
15287
|
+
text: row.text,
|
|
15288
|
+
row: row.index,
|
|
15289
|
+
stop: 0,
|
|
15290
|
+
comment: false,
|
|
15291
|
+
sent: false,
|
|
15292
|
+
label: false,
|
|
15293
|
+
gap: plan.gaps.has(row.index),
|
|
15294
|
+
prose: false
|
|
15295
|
+
});
|
|
15296
|
+
const rowsFor = (plan, row) => [
|
|
15297
|
+
...proseAt(plan, row, false).flatMap((entry) => proseRows(entry, row.index, plan.room)),
|
|
15298
|
+
codeRow(plan, row),
|
|
15299
|
+
...notesAt(plan, row),
|
|
15300
|
+
...proseAt(plan, row, true).flatMap((entry) => proseRows(entry, row.index, plan.room))
|
|
15301
|
+
];
|
|
15302
|
+
const layout = (plan) => plan.patch.rows.flatMap((row) => rowsFor(plan, row));
|
|
13191
15303
|
const lineNumbers = (patch, display) => {
|
|
13192
15304
|
const numbers = /* @__PURE__ */ new Map();
|
|
13193
15305
|
const rows = new Map(patch.rows.map((row) => [row.index, row]));
|
|
13194
15306
|
for (const [index, entry] of display.entries()) {
|
|
13195
|
-
const row = entry.comment ? void 0 : rows.get(entry.row);
|
|
15307
|
+
const row = entry.comment || entry.prose ? void 0 : rows.get(entry.row);
|
|
13196
15308
|
const line = row === void 0 ? void 0 : numberFor(row);
|
|
13197
15309
|
if (line !== void 0) numbers.set(index, line);
|
|
13198
15310
|
}
|
|
13199
15311
|
return numbers;
|
|
13200
15312
|
};
|
|
15313
|
+
const BARE_SIGN = {
|
|
15314
|
+
after: " ",
|
|
15315
|
+
afterColor: palette.accent
|
|
15316
|
+
};
|
|
15317
|
+
const signFor = (entry, rows) => {
|
|
15318
|
+
if (entry.comment || entry.prose) return BARE_SIGN;
|
|
15319
|
+
const row = rows.get(entry.row);
|
|
15320
|
+
const sign = row === void 0 ? void 0 : SIGNS[row.kind];
|
|
15321
|
+
return sign === void 0 ? BARE_SIGN : {
|
|
15322
|
+
after: sign.text,
|
|
15323
|
+
afterColor: sign.color
|
|
15324
|
+
};
|
|
15325
|
+
};
|
|
13201
15326
|
const lineSigns = (patch, display) => {
|
|
13202
|
-
const signs = /* @__PURE__ */ new Map();
|
|
13203
15327
|
const rows = new Map(patch.rows.map((row) => [row.index, row]));
|
|
13204
|
-
|
|
13205
|
-
const row = rows.get(entry.row);
|
|
13206
|
-
const sign = entry.comment || row === void 0 ? void 0 : SIGNS[row.kind];
|
|
13207
|
-
signs.set(index, {
|
|
13208
|
-
after: sign?.text ?? " ",
|
|
13209
|
-
afterColor: sign?.color ?? palette.accent
|
|
13210
|
-
});
|
|
13211
|
-
}
|
|
13212
|
-
return signs;
|
|
15328
|
+
return new Map(display.map((entry, index) => [index, signFor(entry, rows)]));
|
|
13213
15329
|
};
|
|
13214
15330
|
const sideLineOf = (row, side) => getOrUndefined$1(lineOn(row, side));
|
|
13215
15331
|
//#endregion
|
|
@@ -13222,6 +15338,8 @@ const FRAME_PAD = 1;
|
|
|
13222
15338
|
const MODAL_ROOM = 8;
|
|
13223
15339
|
const COMPOSE_CHROME = 3;
|
|
13224
15340
|
const COMPOSE_ACTION_ROWS = 2;
|
|
15341
|
+
const COMPOSE_PAD = 5;
|
|
15342
|
+
const COMPOSE_MIN_TEXT = 8;
|
|
13225
15343
|
const reportActions = () => t`${fg(palette.accent)("esc")} ${fg(palette.muted)("cancel")} ${fg(palette.accent)("^s")} ${fg(palette.muted)("copy and save")}`;
|
|
13226
15344
|
const actionsText = () => t`${fg(palette.accent)("esc")} ${fg(palette.muted)("cancel")} ${fg(palette.accent)("^a")} ${fg(palette.muted)("add to review")} ${fg(palette.accent)("^s")} ${fg(palette.muted)("comment now")}`;
|
|
13227
15345
|
const SNIPPET_LINES = 4;
|
|
@@ -13238,7 +15356,7 @@ const PANE_CHROME = 3;
|
|
|
13238
15356
|
const BRANCH_WIDTH = 82;
|
|
13239
15357
|
const BRANCH_NAME = 44;
|
|
13240
15358
|
const BRANCH_NAME_MIN = 12;
|
|
13241
|
-
const BRANCH_TAIL =
|
|
15359
|
+
const BRANCH_TAIL = 45;
|
|
13242
15360
|
const MODAL_MARGIN = 4;
|
|
13243
15361
|
const bodyRoom = (width) => Math.max(0, width - 2 - BODY_BORDER);
|
|
13244
15362
|
const treeWidth = (width) => {
|
|
@@ -13248,6 +15366,17 @@ const treeWidth = (width) => {
|
|
|
13248
15366
|
};
|
|
13249
15367
|
const homeWidth = (width) => Math.max(0, Math.min(BRANCH_WIDTH, width - 2));
|
|
13250
15368
|
const modalWidth = (width, wanted) => Math.max(0, Math.min(wanted, width - MODAL_MARGIN));
|
|
15369
|
+
const composeRoom = (width) => {
|
|
15370
|
+
const box = modalWidth(width, COMPOSE_WIDTH);
|
|
15371
|
+
return {
|
|
15372
|
+
box,
|
|
15373
|
+
text: Math.max(COMPOSE_MIN_TEXT, box - COMPOSE_PAD)
|
|
15374
|
+
};
|
|
15375
|
+
};
|
|
15376
|
+
const laidOut = (lines, room) => lines.flatMap((line) => {
|
|
15377
|
+
const parts = wrapped(line, room);
|
|
15378
|
+
return parts.length === 0 ? [""] : parts;
|
|
15379
|
+
});
|
|
13251
15380
|
const STICKY_MAX = 4;
|
|
13252
15381
|
const pickPaint = (view, kind, flags) => {
|
|
13253
15382
|
if (flags.cursor) return {
|
|
@@ -13258,11 +15387,16 @@ const pickPaint = (view, kind, flags) => {
|
|
|
13258
15387
|
gutter: SELECTION,
|
|
13259
15388
|
content: SELECTION
|
|
13260
15389
|
};
|
|
15390
|
+
if (flags.gap) return GAP_PAINT;
|
|
13261
15391
|
return view.washOf(kind);
|
|
13262
15392
|
};
|
|
13263
15393
|
const SELECTION = RGBA.fromHex(palette.selection);
|
|
13264
15394
|
const CURSOR = RGBA.fromHex(palette.cursor);
|
|
13265
15395
|
const ACCENT = RGBA.fromHex(palette.accent);
|
|
15396
|
+
const GAP_PAINT = {
|
|
15397
|
+
gutter: RGBA.fromHex(palette.overlay),
|
|
15398
|
+
content: RGBA.fromHex(palette.overlay)
|
|
15399
|
+
};
|
|
13266
15400
|
const bar = (renderer, id, color) => new TextRenderable(renderer, {
|
|
13267
15401
|
id,
|
|
13268
15402
|
content: "",
|
|
@@ -13445,18 +15579,21 @@ const makeComposeParts = (renderer) => ({
|
|
|
13445
15579
|
title: new TextRenderable(renderer, {
|
|
13446
15580
|
id: "compose-title",
|
|
13447
15581
|
content: "",
|
|
13448
|
-
fg: palette.ink
|
|
15582
|
+
fg: palette.ink,
|
|
15583
|
+
wrapMode: "none"
|
|
13449
15584
|
}),
|
|
13450
15585
|
body: new TextRenderable(renderer, {
|
|
13451
15586
|
id: "compose-body",
|
|
13452
15587
|
content: "",
|
|
13453
|
-
fg: palette.ink
|
|
15588
|
+
fg: palette.ink,
|
|
15589
|
+
wrapMode: "none"
|
|
13454
15590
|
}),
|
|
13455
15591
|
actions: new TextRenderable(renderer, {
|
|
13456
15592
|
id: "compose-actions",
|
|
13457
15593
|
content: "",
|
|
13458
15594
|
fg: palette.muted,
|
|
13459
|
-
marginTop: 1
|
|
15595
|
+
marginTop: 1,
|
|
15596
|
+
wrapMode: "none"
|
|
13460
15597
|
})
|
|
13461
15598
|
});
|
|
13462
15599
|
const makeCompose = (renderer) => new BoxRenderable(renderer, {
|
|
@@ -13487,38 +15624,79 @@ const waitingLabel = (branch) => {
|
|
|
13487
15624
|
if (branch.staged > 0) return `${branch.staged} staged`;
|
|
13488
15625
|
return branch.unread > 0 ? `${branch.unread} unread` : "";
|
|
13489
15626
|
};
|
|
13490
|
-
const
|
|
15627
|
+
const inRange = (state, row, from, to) => state.selecting && row >= from && row <= to;
|
|
15628
|
+
const notesOf = (comments, path, sent, opened = []) => comments.filter((entry) => entry.file === path).map((entry) => ({
|
|
15629
|
+
id: entry.id ?? "",
|
|
15630
|
+
folded: entry.settled === true && !(entry.id !== void 0 && opened.includes(entry.id)),
|
|
13491
15631
|
side: entry.side,
|
|
13492
15632
|
line: entry.end,
|
|
13493
15633
|
body: entry.body,
|
|
13494
|
-
sent
|
|
15634
|
+
sent,
|
|
15635
|
+
settled: entry.settled === true,
|
|
15636
|
+
stale: entry.stale === true,
|
|
15637
|
+
asks: entry.asks === true,
|
|
15638
|
+
answers: entry.answers ?? []
|
|
13495
15639
|
}));
|
|
13496
|
-
const notesFor = (state, path) => [...notesOf(state.sent, path, true), ...notesOf(state.pending, path, false)];
|
|
15640
|
+
const notesFor = (state, path) => [...notesOf(state.sent, path, true, state.opened), ...notesOf(state.pending, path, false)];
|
|
15641
|
+
const paired = (chunks) => {
|
|
15642
|
+
const chips = [];
|
|
15643
|
+
for (let at = 0; at < chunks.length; at += CHIP_CHUNKS) chips.push(chunks.slice(at, at + CHIP_CHUNKS));
|
|
15644
|
+
return chips;
|
|
15645
|
+
};
|
|
15646
|
+
const keptWithin = (chunks, room) => {
|
|
15647
|
+
const kept = [];
|
|
15648
|
+
let used = 0;
|
|
15649
|
+
for (const chip of paired(chunks).toReversed()) {
|
|
15650
|
+
const width = chip.reduce((total, chunk) => total + chunk.text.length, 0);
|
|
15651
|
+
if (used + width > room) break;
|
|
15652
|
+
kept.unshift(chip);
|
|
15653
|
+
used += width;
|
|
15654
|
+
}
|
|
15655
|
+
return kept.flat();
|
|
15656
|
+
};
|
|
15657
|
+
const CHIP_CHUNKS = 3;
|
|
13497
15658
|
const shortPath = (path) => {
|
|
13498
15659
|
const home = process.env["HOME"] ?? "";
|
|
13499
15660
|
return home.length > 0 && path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
13500
15661
|
};
|
|
15662
|
+
const HOME_PATH_MIN = 24;
|
|
15663
|
+
const HOME_PATH_CHROME = 10;
|
|
15664
|
+
const elide = (path, room) => {
|
|
15665
|
+
if (path.length <= room) return path;
|
|
15666
|
+
const parts = path.split("/").filter((part) => part.length > 0);
|
|
15667
|
+
const lead = path.startsWith("~") ? "~" : "";
|
|
15668
|
+
const tail = parts.slice(-2).join("/");
|
|
15669
|
+
const middled = `${path.startsWith("/") ? `/${parts[0] ?? ""}` : lead}/…/${tail}`;
|
|
15670
|
+
return middled.length <= room ? middled : `…/${tail}`;
|
|
15671
|
+
};
|
|
13501
15672
|
const contextLabel = (context) => {
|
|
13502
15673
|
if (context === 3) return "";
|
|
13503
15674
|
return context >= 1e5 ? "whole file" : `±${context}`;
|
|
13504
15675
|
};
|
|
13505
15676
|
const nameRoom = (pane) => Math.max(BRANCH_NAME_MIN, Math.min(BRANCH_NAME, pane - BRANCH_TAIL));
|
|
13506
|
-
const columns = (cells, room) => `${clip(cells.name, room).padEnd(room)}${cells.files.padStart(5)}${cells.added.padStart(8)}${cells.gone.padStart(8)} ${cells.state}`;
|
|
15677
|
+
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}`;
|
|
13507
15678
|
const branchHeading = (room) => ` ${columns({
|
|
13508
15679
|
name: "WORKTREE",
|
|
13509
15680
|
files: "FILES",
|
|
13510
15681
|
added: "+",
|
|
13511
15682
|
gone: "-",
|
|
15683
|
+
layers: "LAYERS",
|
|
13512
15684
|
state: "STATE"
|
|
13513
15685
|
}, room)}`;
|
|
13514
15686
|
const atHome = (state) => state.screen === "branches" || state.screen === "palette" && state.returnTo === "branches";
|
|
15687
|
+
const layersCell = (branch) => {
|
|
15688
|
+
if (branch.layers === 0) return "";
|
|
15689
|
+
return branch.stale ? `${branch.layers} stale` : `${branch.layers} layers`;
|
|
15690
|
+
};
|
|
15691
|
+
const stateCell = (state, branch) => [state.pulls[branch.branch] ?? "", waitingLabel(branch).trim()].filter((part) => part.length > 0).join(" ");
|
|
13515
15692
|
const branchCells = (branch, here, room) => ({
|
|
13516
15693
|
lead: `${here ? marks().cursor : " "} `,
|
|
13517
15694
|
name: clip(branch.branch, room).padEnd(room),
|
|
13518
15695
|
files: `${branch.files}`.padStart(5),
|
|
13519
15696
|
added: `+${branch.added}`.padStart(8),
|
|
13520
15697
|
gone: `-${branch.removed}`.padStart(8),
|
|
13521
|
-
|
|
15698
|
+
layers: layersCell(branch),
|
|
15699
|
+
state: ""
|
|
13522
15700
|
});
|
|
13523
15701
|
const headerParts = (state, branch, path) => [
|
|
13524
15702
|
branch,
|
|
@@ -13527,7 +15705,8 @@ const headerParts = (state, branch, path) => [
|
|
|
13527
15705
|
state.vouched.length === 0 ? "" : reviewedCount(state),
|
|
13528
15706
|
state.staged === 0 ? "" : `${state.staged} staged`,
|
|
13529
15707
|
contextLabel(state.context),
|
|
13530
|
-
hiddenLines(state) === 0 ? "" : `⋯ ${hiddenLines(state)} lines hidden
|
|
15708
|
+
hiddenLines(state) === 0 ? "" : `⋯ ${hiddenLines(state)} lines hidden`,
|
|
15709
|
+
state.pan === 0 ? "" : `→ ${state.pan} columns`
|
|
13531
15710
|
];
|
|
13532
15711
|
const fallbackScope = (state, top) => {
|
|
13533
15712
|
const scope = (selectedPatch(state)?.hunks.findLast((hunk) => hunk.startRow < top))?.scope ?? "";
|
|
@@ -13547,14 +15726,35 @@ const treeLine = (state, row, pane) => {
|
|
|
13547
15726
|
return `${treeMarks(state, row)}${clip(treeLabel(state, row), room).padEnd(room)}${tail}`;
|
|
13548
15727
|
};
|
|
13549
15728
|
const STEP_NUMBER = 3;
|
|
13550
|
-
const
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
const
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
15729
|
+
const STEP_LEAD = 8;
|
|
15730
|
+
const NOTE_LEAD = 10;
|
|
15731
|
+
const STEP_GAP = 1;
|
|
15732
|
+
const layerRoom = (state, pane) => {
|
|
15733
|
+
const tally = Math.max(1, ...state.layers.map((layer) => `${layer.files.length}`.length));
|
|
15734
|
+
return {
|
|
15735
|
+
title: Math.max(4, pane - PANE_CHROME - STEP_LEAD - STEP_GAP - tally),
|
|
15736
|
+
note: Math.max(4, pane - PANE_CHROME - NOTE_LEAD),
|
|
15737
|
+
tally
|
|
15738
|
+
};
|
|
15739
|
+
};
|
|
15740
|
+
const layerFold = (state, index) => {
|
|
15741
|
+
if (layerOpen(state, index)) return "▾";
|
|
15742
|
+
return (state.layers[index]?.note ?? "").length === 0 ? " " : "▸";
|
|
15743
|
+
};
|
|
15744
|
+
const layerHead = (state, row) => {
|
|
15745
|
+
if (!row.lead) return " ".repeat(STEP_LEAD);
|
|
15746
|
+
return `${row.index === state.layerIndex ? state.focus === "tree" ? "▸" : "·" : " "} ${layerFold(state, row.index)} ${`${row.index + 1}.`.padStart(STEP_NUMBER)} `;
|
|
15747
|
+
};
|
|
15748
|
+
const layerText = (state, row, room) => {
|
|
15749
|
+
if (row.kind === "file") return `${" ".repeat(NOTE_LEAD)}${marks().file} ${row.text}`;
|
|
15750
|
+
if (row.kind === "note") return `${" ".repeat(NOTE_LEAD)}${row.text}`;
|
|
15751
|
+
const tail = (row.lead ? `${state.layers[row.index]?.files.length ?? 0}` : "").padStart(room.tally + STEP_GAP);
|
|
15752
|
+
return `${layerHead(state, row)}${row.text.padEnd(room.title)}${tail}`;
|
|
15753
|
+
};
|
|
15754
|
+
const layerPaint = (state, row) => {
|
|
15755
|
+
if (row.kind === "file") return palette.ink;
|
|
15756
|
+
if (row.kind === "note") return palette.faint;
|
|
15757
|
+
return row.index === state.layerIndex ? palette.ink : palette.muted;
|
|
13558
15758
|
};
|
|
13559
15759
|
var Screen = class {
|
|
13560
15760
|
header;
|
|
@@ -13632,6 +15832,7 @@ var Screen = class {
|
|
|
13632
15832
|
this.mouse = mouse;
|
|
13633
15833
|
this.view.listenTo({
|
|
13634
15834
|
scroll: (delta) => this.mouse?.onScroll(delta),
|
|
15835
|
+
pan: (delta) => this.mouse?.onPan(delta),
|
|
13635
15836
|
down: (y) => {
|
|
13636
15837
|
this.dragFrom = this.rowAtY(y);
|
|
13637
15838
|
this.mouse?.onDrag(this.dragFrom, this.dragFrom, false);
|
|
@@ -13658,13 +15859,15 @@ var Screen = class {
|
|
|
13658
15859
|
}
|
|
13659
15860
|
update(state) {
|
|
13660
15861
|
this.shown = state;
|
|
13661
|
-
this.chips = hintsFor(state.screen, state.staged);
|
|
15862
|
+
this.chips = hintsFor(state.screen, state.staged, state.layers.length);
|
|
13662
15863
|
this.header.content = this.headerText(state);
|
|
13663
15864
|
this.footer.content = this.footerText(state);
|
|
13664
15865
|
this.list.content = this.listText(state);
|
|
13665
15866
|
const many = state.branches.length === 1 ? "1 worktree" : `${state.branches.length} worktrees`;
|
|
13666
|
-
|
|
13667
|
-
|
|
15867
|
+
const pane = homeWidth(this.renderer.width);
|
|
15868
|
+
const room = Math.max(HOME_PATH_MIN, pane - many.length - HOME_PATH_CHROME);
|
|
15869
|
+
this.landing.content = `${elide(shortPath(this.repo), room)} · ${many}`;
|
|
15870
|
+
this.landingKeys.content = this.homeKeys(state);
|
|
13668
15871
|
this.diffPane.visible = state.screen !== "branches" && !(state.screen === "palette" && state.returnTo === "branches");
|
|
13669
15872
|
if (this.diffPane.visible) this.paintDiff(state);
|
|
13670
15873
|
this.paintPane(state);
|
|
@@ -13708,10 +15911,16 @@ var Screen = class {
|
|
|
13708
15911
|
const readout = selectionReadout(state);
|
|
13709
15912
|
this.lead = readout.length === 0 ? 0 : readout.length + 3;
|
|
13710
15913
|
const lead = readout.length === 0 ? [] : [fg(palette.muted)(`${readout} `)];
|
|
13711
|
-
const
|
|
15914
|
+
const said = state.notice.length === 0 ? state.waiting : state.notice;
|
|
15915
|
+
const tail = said.length === 0 ? "" : ` ${said}`;
|
|
15916
|
+
const width = this.footer.width > 0 ? this.footer.width : this.renderer.width;
|
|
15917
|
+
const room = Math.max(0, width - this.lead - tail.length);
|
|
15918
|
+
const chips = keptWithin(this.chipRow().chunks, room);
|
|
15919
|
+
const colour = state.notice.length === 0 ? palette.accent : palette.attention;
|
|
15920
|
+
const notice = tail.length === 0 ? [] : [fg(colour)(tail)];
|
|
13712
15921
|
return new StyledText([
|
|
13713
15922
|
...lead,
|
|
13714
|
-
...
|
|
15923
|
+
...chips,
|
|
13715
15924
|
...notice
|
|
13716
15925
|
]);
|
|
13717
15926
|
}
|
|
@@ -13720,7 +15929,7 @@ var Screen = class {
|
|
|
13720
15929
|
}
|
|
13721
15930
|
listText(state) {
|
|
13722
15931
|
if (atHome(state)) return this.branchTable(state);
|
|
13723
|
-
if (
|
|
15932
|
+
if (onLayers(state)) return this.layerRail(state);
|
|
13724
15933
|
const height = Math.max(1, this.listPane.height - 1);
|
|
13725
15934
|
const pane = this.paneRoom();
|
|
13726
15935
|
const window = treeWindow(state, height);
|
|
@@ -13728,23 +15937,27 @@ var Screen = class {
|
|
|
13728
15937
|
const more = window.more > 0 ? [fg(palette.faint)(` … ${window.more} more`)] : [];
|
|
13729
15938
|
return new StyledText([...rows, ...more]);
|
|
13730
15939
|
}
|
|
13731
|
-
|
|
15940
|
+
layerRail(state) {
|
|
13732
15941
|
const height = Math.max(1, this.listPane.height - 1);
|
|
13733
|
-
const
|
|
13734
|
-
const window =
|
|
13735
|
-
const rows = window.
|
|
13736
|
-
const index = window.first + offset;
|
|
13737
|
-
const paint = index === state.stepIndex ? palette.ink : palette.muted;
|
|
13738
|
-
return fg(paint)(`${stepLine(state, index, pane)}\n`);
|
|
13739
|
-
});
|
|
15942
|
+
const room = layerRoom(state, this.paneRoom());
|
|
15943
|
+
const window = railWindow(layerRows(state, room.title, room.note), height, state.layerIndex);
|
|
15944
|
+
const rows = window.rows.map((row) => fg(layerPaint(state, row))(`${layerText(state, row, room)}\n`));
|
|
13740
15945
|
const more = window.more > 0 ? [fg(palette.faint)(` … ${window.more} more`)] : [];
|
|
13741
|
-
|
|
15946
|
+
const warn = state.layersStale ? [fg(palette.attention)(` stale, the branch moved on\n\n`)] : [];
|
|
15947
|
+
return new StyledText([
|
|
15948
|
+
...warn,
|
|
15949
|
+
...rows,
|
|
15950
|
+
...more
|
|
15951
|
+
]);
|
|
13742
15952
|
}
|
|
13743
15953
|
paintDiff(state) {
|
|
13744
|
-
const
|
|
13745
|
-
if (
|
|
15954
|
+
const shown = shownOf(state);
|
|
15955
|
+
if (shown === void 0) return;
|
|
15956
|
+
const patch = shown.patch;
|
|
13746
15957
|
this.paintSticky(state, state.top);
|
|
13747
|
-
this.view.
|
|
15958
|
+
this.view.setWrap(state.wrap);
|
|
15959
|
+
this.view.setPan(state.pan);
|
|
15960
|
+
this.view.show(patch, notesFor(state, patch.path), gapRowSet(shown), proseFor(state, patch.path));
|
|
13748
15961
|
this.view.fit(this.diffScroll.height);
|
|
13749
15962
|
const height = this.view.rows();
|
|
13750
15963
|
const top = this.view.scrollTo(state.top, state.cursor);
|
|
@@ -13828,7 +16041,8 @@ var Screen = class {
|
|
|
13828
16041
|
fg(palette.faint)(cells.files),
|
|
13829
16042
|
fg(palette.added)(cells.added),
|
|
13830
16043
|
fg(palette.removed)(cells.gone),
|
|
13831
|
-
fg(palette.
|
|
16044
|
+
fg(palette.accent)(` ${cells.layers.padStart(8)}`),
|
|
16045
|
+
fg(palette.attention)(` ${stateCell(state, branch)}\n`)
|
|
13832
16046
|
];
|
|
13833
16047
|
});
|
|
13834
16048
|
return new StyledText([...heading, ...rows]);
|
|
@@ -13846,10 +16060,23 @@ var Screen = class {
|
|
|
13846
16060
|
this.landingKeys.content = this.chipRow();
|
|
13847
16061
|
if (this.shown !== void 0) this.footer.content = this.footerText(this.shown);
|
|
13848
16062
|
}
|
|
16063
|
+
homeKeys(state) {
|
|
16064
|
+
const chips = this.chipRow().chunks;
|
|
16065
|
+
const said = state.notice.length === 0 ? state.waiting : state.notice;
|
|
16066
|
+
if (said.length === 0) return new StyledText(chips);
|
|
16067
|
+
const colour = state.notice.length === 0 ? palette.accent : palette.attention;
|
|
16068
|
+
return new StyledText([...chips, fg(colour)(` ${said}`)]);
|
|
16069
|
+
}
|
|
13849
16070
|
chipRow() {
|
|
13850
16071
|
return new StyledText(this.chips.flatMap((chip, index) => {
|
|
13851
|
-
const
|
|
13852
|
-
|
|
16072
|
+
const lit = index === this.hovered;
|
|
16073
|
+
const key = fg(palette.ink)(chip.key);
|
|
16074
|
+
const hint = fg(lit ? palette.ink : palette.faint)(` ${chip.hint}`);
|
|
16075
|
+
return [
|
|
16076
|
+
lit ? bg(palette.cursor)(key) : key,
|
|
16077
|
+
lit ? bg(palette.cursor)(hint) : hint,
|
|
16078
|
+
fg(palette.faint)(" ")
|
|
16079
|
+
];
|
|
13853
16080
|
}));
|
|
13854
16081
|
}
|
|
13855
16082
|
paintPane(state) {
|
|
@@ -13883,28 +16110,33 @@ var Screen = class {
|
|
|
13883
16110
|
paintReport(state) {
|
|
13884
16111
|
this.compose.visible = state.screen === "compose" || state.screen === "report";
|
|
13885
16112
|
if (state.screen !== "report") return;
|
|
13886
|
-
const
|
|
16113
|
+
const room = composeRoom(this.renderer.width);
|
|
16114
|
+
const lines = laidOut([
|
|
13887
16115
|
"What went wrong? Everything on screen is attached for you.",
|
|
13888
16116
|
"",
|
|
13889
16117
|
`${state.draft}▌`
|
|
13890
|
-
];
|
|
16118
|
+
], room.text);
|
|
13891
16119
|
this.composeTitle.content = "Report a bug";
|
|
13892
16120
|
this.composeBody.content = lines.join("\n");
|
|
13893
16121
|
this.composeActions.content = reportActions();
|
|
13894
|
-
const room = modalWidth(this.renderer.width, COMPOSE_WIDTH);
|
|
13895
16122
|
this.compose.height = lines.length + COMPOSE_ACTION_ROWS + COMPOSE_CHROME;
|
|
13896
|
-
this.compose.width = room;
|
|
13897
|
-
this.compose.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room) / 2));
|
|
16123
|
+
this.compose.width = room.box;
|
|
16124
|
+
this.compose.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room.box) / 2));
|
|
13898
16125
|
this.compose.top = Math.max(2, Math.floor(this.renderer.height / 4));
|
|
13899
16126
|
}
|
|
13900
16127
|
paintGutter(state, top, height) {
|
|
13901
16128
|
const [from, to] = selectionRange(state);
|
|
13902
16129
|
const marked = markedRows(state);
|
|
13903
|
-
const
|
|
13904
|
-
|
|
13905
|
-
|
|
13906
|
-
|
|
13907
|
-
|
|
16130
|
+
const drawn = this.view.drawn();
|
|
16131
|
+
const bare = (visual) => visual >= drawn || !this.view.carries(visual) || this.view.isRunOn(visual);
|
|
16132
|
+
const held = (visual) => {
|
|
16133
|
+
const row = this.view.rowAt(visual);
|
|
16134
|
+
const onCode = this.view.stopAt(visual) === 0;
|
|
16135
|
+
const standing = row === state.cursor && this.view.stopAt(visual) === state.stop;
|
|
16136
|
+
const within = onCode && inRange(state, row, from, to);
|
|
16137
|
+
return `${standing || within ? marks().cursor : " "}${onCode && marked.has(row) ? marks().comment : " "}`;
|
|
16138
|
+
};
|
|
16139
|
+
const rows = Array.from({ length: height }, (_, index) => bare(top + index) ? " " : held(top + index));
|
|
13908
16140
|
this.gutter.content = rows.join("\n");
|
|
13909
16141
|
}
|
|
13910
16142
|
paintSticky(state, top) {
|
|
@@ -13915,13 +16147,16 @@ var Screen = class {
|
|
|
13915
16147
|
linePaint(state) {
|
|
13916
16148
|
const [from, to] = selectionRange(state);
|
|
13917
16149
|
const selecting = state.selecting || state.screen === "compose";
|
|
13918
|
-
const
|
|
16150
|
+
const shown = shownOf(state);
|
|
16151
|
+
const rows = shown?.patch.rows ?? [];
|
|
16152
|
+
const gaps = shown === void 0 ? /* @__PURE__ */ new Set() : gapRowSet(shown);
|
|
13919
16153
|
return (row) => {
|
|
13920
16154
|
const kind = rows[row]?.kind;
|
|
13921
16155
|
if (kind === void 0) return void 0;
|
|
13922
16156
|
return pickPaint(this.view, kind, {
|
|
13923
16157
|
cursor: row === state.cursor,
|
|
13924
|
-
selected: selecting && row >= from && row <= to
|
|
16158
|
+
selected: selecting && row >= from && row <= to,
|
|
16159
|
+
gap: gaps.has(row)
|
|
13925
16160
|
});
|
|
13926
16161
|
};
|
|
13927
16162
|
}
|
|
@@ -13931,24 +16166,24 @@ var Screen = class {
|
|
|
13931
16166
|
this.composeBody.content = "";
|
|
13932
16167
|
return;
|
|
13933
16168
|
}
|
|
16169
|
+
const room = composeRoom(this.renderer.width);
|
|
13934
16170
|
const snippet = snippetOf(state, SNIPPET_LINES);
|
|
13935
16171
|
const more = selectionRange(state)[1] - selectionRange(state)[0] + 1 - snippet.length;
|
|
13936
16172
|
const tail = more > 0 ? [` … ${more} more lines`] : [];
|
|
13937
|
-
const
|
|
16173
|
+
const quoted = [...snippet, ...tail].map((line) => clip(line, room.text));
|
|
16174
|
+
const written = laidOut(`${state.draft}▌`.split("\n"), room.text);
|
|
13938
16175
|
const lines = [
|
|
13939
|
-
...
|
|
13940
|
-
...tail,
|
|
16176
|
+
...quoted,
|
|
13941
16177
|
"",
|
|
13942
16178
|
...written
|
|
13943
16179
|
];
|
|
13944
|
-
this.composeTitle.content = composeTarget(state);
|
|
16180
|
+
this.composeTitle.content = clip(composeTarget(state), room.text);
|
|
13945
16181
|
this.composeBody.content = lines.join("\n");
|
|
13946
16182
|
this.composeActions.content = actionsText();
|
|
13947
16183
|
const height = lines.length + COMPOSE_ACTION_ROWS + COMPOSE_CHROME;
|
|
13948
|
-
const room = modalWidth(this.renderer.width, COMPOSE_WIDTH);
|
|
13949
16184
|
this.compose.height = height;
|
|
13950
|
-
this.compose.width = room;
|
|
13951
|
-
this.compose.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room) / 2));
|
|
16185
|
+
this.compose.width = room.box;
|
|
16186
|
+
this.compose.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room.box) / 2));
|
|
13952
16187
|
this.compose.top = Math.max(2, Math.floor((this.renderer.height - height) / 2));
|
|
13953
16188
|
}
|
|
13954
16189
|
};
|
|
@@ -14005,29 +16240,61 @@ var App = class {
|
|
|
14005
16240
|
noticeMs;
|
|
14006
16241
|
sessionPath;
|
|
14007
16242
|
remembered = "";
|
|
16243
|
+
wrapKept = false;
|
|
14008
16244
|
keys = [];
|
|
14009
16245
|
fading;
|
|
16246
|
+
wheel = 0;
|
|
16247
|
+
sideways = 0;
|
|
16248
|
+
watching;
|
|
14010
16249
|
constructor(options) {
|
|
14011
16250
|
this.renderer = options.renderer;
|
|
14012
16251
|
this.repo = options.repo;
|
|
14013
16252
|
this.run = options.run;
|
|
14014
16253
|
this.noticeMs = options.noticeMs ?? 2200;
|
|
14015
16254
|
this.sessionPath = options.sessionPath;
|
|
16255
|
+
this.wrapKept = options.wrap === true;
|
|
14016
16256
|
const { branches, renderer } = options;
|
|
14017
|
-
this.state =
|
|
16257
|
+
this.state = {
|
|
16258
|
+
...initialState(branches),
|
|
16259
|
+
wrap: options.wrap === true
|
|
16260
|
+
};
|
|
14018
16261
|
this.screen = new Screen(renderer, options.repo);
|
|
14019
16262
|
this.screen.update(this.state);
|
|
14020
16263
|
this.screen.listen({
|
|
14021
|
-
onScroll: (delta) => this.
|
|
16264
|
+
onScroll: (delta) => this.onWheel(delta),
|
|
16265
|
+
onPan: (delta) => this.onPanWheel(delta),
|
|
14022
16266
|
onDrag: (from, to) => this.commit(draggedTo(this.measured(), from, to)),
|
|
14023
16267
|
onChip: (key) => this.dispatchTask(() => this.onKey(asKey(key)))
|
|
14024
16268
|
});
|
|
14025
16269
|
renderer.keyInput.on("keypress", (key) => this.dispatch(key));
|
|
16270
|
+
renderer.on("destroy", () => this.stopWatching());
|
|
14026
16271
|
renderer.on("destroy", () => this.stopFading());
|
|
14027
16272
|
renderer.on("frame", () => this.syncGeometry());
|
|
16273
|
+
renderer.setFrameCallback(async () => this.applyWheel());
|
|
14028
16274
|
const resume = options.resume;
|
|
16275
|
+
this.startWatching(options.storeRoot);
|
|
16276
|
+
this.dispatchTask(() => this.loadPulls());
|
|
14029
16277
|
if (resume !== void 0) this.dispatchTask(() => this.resume(resume));
|
|
14030
16278
|
}
|
|
16279
|
+
startWatching(root) {
|
|
16280
|
+
if (root === void 0) return;
|
|
16281
|
+
this.watching = watchAnswers(root, () => this.dispatchTask(() => this.noticeAnswers()));
|
|
16282
|
+
}
|
|
16283
|
+
stopWatching() {
|
|
16284
|
+
this.watching?.stop();
|
|
16285
|
+
this.watching = void 0;
|
|
16286
|
+
}
|
|
16287
|
+
async noticeAnswers() {
|
|
16288
|
+
const branch = selectedBranch(this.state);
|
|
16289
|
+
if (branch === void 0) return this.noticeOnList();
|
|
16290
|
+
const sent = await this.loadSent(branch.branch);
|
|
16291
|
+
const said = spokenSince(this.state.sent, sent);
|
|
16292
|
+
if (said === 0) return;
|
|
16293
|
+
this.commit(withWaiting(this.state, `${said} answered · press r`));
|
|
16294
|
+
}
|
|
16295
|
+
async noticeOnList() {
|
|
16296
|
+
this.commit(withWaiting(this.state, "the agent answered · press r"));
|
|
16297
|
+
}
|
|
14031
16298
|
dispatchTask(task) {
|
|
14032
16299
|
this.pending = this.pending.then(task).catch((cause) => this.fail(cause));
|
|
14033
16300
|
}
|
|
@@ -14048,6 +16315,11 @@ var App = class {
|
|
|
14048
16315
|
});
|
|
14049
16316
|
await this.loadSource();
|
|
14050
16317
|
}
|
|
16318
|
+
rememberWrap(next) {
|
|
16319
|
+
if (next.wrap === this.wrapKept) return;
|
|
16320
|
+
this.wrapKept = next.wrap;
|
|
16321
|
+
this.run(saveWrap(next.wrap)).catch(() => void 0);
|
|
16322
|
+
}
|
|
14051
16323
|
rememberPlace(next) {
|
|
14052
16324
|
if (this.sessionPath === void 0 || next.screen !== "review") return;
|
|
14053
16325
|
const session = sessionOf(next);
|
|
@@ -14068,6 +16340,23 @@ var App = class {
|
|
|
14068
16340
|
settled() {
|
|
14069
16341
|
return this.pending;
|
|
14070
16342
|
}
|
|
16343
|
+
onWheel(delta) {
|
|
16344
|
+
this.wheel += delta;
|
|
16345
|
+
this.renderer.requestRender();
|
|
16346
|
+
}
|
|
16347
|
+
onPanWheel(delta) {
|
|
16348
|
+
this.sideways += delta;
|
|
16349
|
+
this.renderer.requestRender();
|
|
16350
|
+
}
|
|
16351
|
+
applyWheel() {
|
|
16352
|
+
const down = this.wheel;
|
|
16353
|
+
const across = this.sideways;
|
|
16354
|
+
if (down === 0 && across === 0) return;
|
|
16355
|
+
this.wheel = 0;
|
|
16356
|
+
this.sideways = 0;
|
|
16357
|
+
const moved = down === 0 ? this.measured() : scrolled(this.measured(), down);
|
|
16358
|
+
this.commit(across === 0 ? moved : panBy(moved, across));
|
|
16359
|
+
}
|
|
14071
16360
|
syncGeometry() {
|
|
14072
16361
|
const rows = this.screen.viewportRows();
|
|
14073
16362
|
if (rows === this.state.viewport) return;
|
|
@@ -14086,6 +16375,7 @@ var App = class {
|
|
|
14086
16375
|
const appeared = next.notice.length > 0 && next.notice !== this.state.notice;
|
|
14087
16376
|
this.state = next;
|
|
14088
16377
|
this.rememberPlace(next);
|
|
16378
|
+
this.rememberWrap(next);
|
|
14089
16379
|
this.screen.update(next);
|
|
14090
16380
|
if (appeared) this.fade();
|
|
14091
16381
|
}
|
|
@@ -14120,15 +16410,34 @@ var App = class {
|
|
|
14120
16410
|
"rail.toggle": () => this.commitSynced("rail.toggle"),
|
|
14121
16411
|
"file.vouch": () => this.vouch(false),
|
|
14122
16412
|
"file.vouch.next": () => this.vouch(true),
|
|
16413
|
+
"thread.settle": () => this.settleHere(),
|
|
16414
|
+
"review.reload": () => this.state.screen === "branches" ? this.reloadList() : this.reloadBranch(),
|
|
14123
16415
|
"pending.open": () => this.openPending(),
|
|
16416
|
+
"pending.edit": () => this.editStagedComment(),
|
|
16417
|
+
"pending.drop": () => this.dropStagedComment(),
|
|
14124
16418
|
"pending.submit": () => this.sendReview(),
|
|
14125
16419
|
"report.open": () => this.commit(reduce(this.measured(), "report.open")),
|
|
14126
16420
|
back: () => this.goBack(),
|
|
14127
16421
|
"report.send": () => this.sendReport(),
|
|
14128
16422
|
"context.more": () => this.expand(1),
|
|
14129
|
-
"context.less": () => this.expand(-1)
|
|
16423
|
+
"context.less": () => this.expand(-1),
|
|
16424
|
+
"tree.expand": () => this.unfold(1),
|
|
16425
|
+
"tree.collapse": () => this.unfold(-1)
|
|
14130
16426
|
};
|
|
14131
16427
|
}
|
|
16428
|
+
async unfold(delta) {
|
|
16429
|
+
const gap = this.state.focus === "diff" ? gapAtRow(this.state, this.state.cursor) : void 0;
|
|
16430
|
+
const action = delta > 0 ? "tree.expand" : "tree.collapse";
|
|
16431
|
+
if (gap === void 0) return this.commit(reduce(this.measured(), action));
|
|
16432
|
+
if (delta > 0) await this.loadFull();
|
|
16433
|
+
this.commit(gapOpened(this.measured(), gap.index, delta * 10));
|
|
16434
|
+
}
|
|
16435
|
+
async loadFull() {
|
|
16436
|
+
const branch = selectedBranch(this.state);
|
|
16437
|
+
if (branch === void 0 || this.state.full.length > 0) return;
|
|
16438
|
+
const full = await this.run(listPatches(this.repo, branch.branch, WHOLE_FILE));
|
|
16439
|
+
this.commit(withFull(this.state, full));
|
|
16440
|
+
}
|
|
14132
16441
|
async onKey(key, forced) {
|
|
14133
16442
|
const action = forced ?? actionFor(this.state.screen, keyName(key));
|
|
14134
16443
|
this.remember(action, key);
|
|
@@ -14155,16 +16464,52 @@ var App = class {
|
|
|
14155
16464
|
sequence: ""
|
|
14156
16465
|
}, chosen);
|
|
14157
16466
|
}
|
|
16467
|
+
async readBranch(name) {
|
|
16468
|
+
const patches = await this.run(listPatches(this.repo, name));
|
|
16469
|
+
const progress = await this.run(reviewProgress(this.repo, name));
|
|
16470
|
+
const pending = await this.run(listPending(this.repo, name));
|
|
16471
|
+
const layers = await this.run(listLayers(this.repo, name));
|
|
16472
|
+
const sent = await this.loadSent(name);
|
|
16473
|
+
const opened = withVouched(withPatches(this.state, patches), progress.vouched);
|
|
16474
|
+
return withLayers(withSent(withPending(opened, pending, "review"), sent), layers);
|
|
16475
|
+
}
|
|
14158
16476
|
async openBranch() {
|
|
14159
16477
|
const branch = selectedBranch(this.state);
|
|
14160
16478
|
if (branch === void 0) return;
|
|
14161
|
-
|
|
14162
|
-
|
|
14163
|
-
|
|
14164
|
-
|
|
14165
|
-
const
|
|
16479
|
+
this.commit(await this.readBranch(branch.branch));
|
|
16480
|
+
await this.loadSource();
|
|
16481
|
+
}
|
|
16482
|
+
async settleHere() {
|
|
16483
|
+
const branch = selectedBranch(this.state);
|
|
16484
|
+
const id = (threadAtStop(this.state) ?? threadAtRow(this.state, this.state.cursor))?.id;
|
|
16485
|
+
if (branch === void 0 || id === void 0) return this.commit(withNotice(this.state, "no thread here"));
|
|
16486
|
+
await this.run(settleThread(this.repo, branch.branch, id, (/* @__PURE__ */ new Date()).toISOString()));
|
|
14166
16487
|
const sent = await this.loadSent(branch.branch);
|
|
14167
|
-
|
|
16488
|
+
const held = withSent({
|
|
16489
|
+
...this.state,
|
|
16490
|
+
opened: this.state.opened.filter((was) => was !== id)
|
|
16491
|
+
}, sent);
|
|
16492
|
+
this.commit(withNotice(held, "settled"));
|
|
16493
|
+
}
|
|
16494
|
+
async reloadList() {
|
|
16495
|
+
const here = selectedBranch(this.state)?.branch;
|
|
16496
|
+
const branches = await this.run(listBranches(this.repo));
|
|
16497
|
+
const read = withBranches(this.state, branches);
|
|
16498
|
+
const at = branches.findIndex((candidate) => candidate.branch === here);
|
|
16499
|
+
const kept = at === -1 ? read : {
|
|
16500
|
+
...read,
|
|
16501
|
+
branchIndex: at
|
|
16502
|
+
};
|
|
16503
|
+
this.commit(withWaiting(withNoticeHere(kept, "read the list again"), ""));
|
|
16504
|
+
this.dispatchTask(() => this.loadPulls());
|
|
16505
|
+
}
|
|
16506
|
+
async reloadBranch() {
|
|
16507
|
+
const branch = selectedBranch(this.state);
|
|
16508
|
+
if (branch === void 0) return;
|
|
16509
|
+
const path = selectedPatch(this.state)?.path;
|
|
16510
|
+
const line = sourceLineAt(this.state, this.state.cursor);
|
|
16511
|
+
const read = await this.readBranch(branch.branch);
|
|
16512
|
+
this.commit(withWaiting(withNotice(restoredTo(read, path, line), "read the branch again"), ""));
|
|
14168
16513
|
await this.loadSource();
|
|
14169
16514
|
}
|
|
14170
16515
|
async goBack() {
|
|
@@ -14222,6 +16567,8 @@ var App = class {
|
|
|
14222
16567
|
};
|
|
14223
16568
|
}
|
|
14224
16569
|
async stage() {
|
|
16570
|
+
const editing = this.state.editing;
|
|
16571
|
+
if (editing !== void 0) return this.restage(editing);
|
|
14225
16572
|
const request = this.request();
|
|
14226
16573
|
if (request === void 0) return this.commit(withNotice(this.state, "nothing to stage"));
|
|
14227
16574
|
await this.run(stageComment(request));
|
|
@@ -14230,9 +16577,33 @@ var App = class {
|
|
|
14230
16577
|
const next = withPending(this.state, pending, "review");
|
|
14231
16578
|
this.commit(withNotice(next, `${pending.length} staged`));
|
|
14232
16579
|
}
|
|
16580
|
+
async restage(id) {
|
|
16581
|
+
const branch = selectedBranch(this.state);
|
|
16582
|
+
if (branch === void 0) return;
|
|
16583
|
+
await this.run(editStaged({
|
|
16584
|
+
repo: this.repo,
|
|
16585
|
+
branch: branch.branch,
|
|
16586
|
+
id,
|
|
16587
|
+
body: this.state.draft
|
|
16588
|
+
}));
|
|
16589
|
+
const pending = await this.run(listPending(this.repo, branch.branch));
|
|
16590
|
+
const next = withPending({
|
|
16591
|
+
...this.state,
|
|
16592
|
+
editing: void 0,
|
|
16593
|
+
draft: ""
|
|
16594
|
+
}, pending, "pending");
|
|
16595
|
+
this.commit(withNoticeHere(next, "reworded"));
|
|
16596
|
+
}
|
|
14233
16597
|
loadSent(branch) {
|
|
14234
16598
|
return this.run(listSent(this.repo, branch));
|
|
14235
16599
|
}
|
|
16600
|
+
async loadPulls() {
|
|
16601
|
+
const asked = (await this.run(map(Forge, (service) => service))).pulls(this.repo);
|
|
16602
|
+
const pulls = await this.run(asked.pipe(catchTag("ForgeUnavailable", () => succeed([]))));
|
|
16603
|
+
if (pulls.length === 0) return;
|
|
16604
|
+
const found = Object.fromEntries(pulls.map((pull) => [pull.branch, pull.state]));
|
|
16605
|
+
this.commit(withPulls(this.state, found));
|
|
16606
|
+
}
|
|
14236
16607
|
async loadSource() {
|
|
14237
16608
|
const branch = selectedBranch(this.state);
|
|
14238
16609
|
const patch = selectedPatch(this.state);
|
|
@@ -14242,11 +16613,12 @@ var App = class {
|
|
|
14242
16613
|
}
|
|
14243
16614
|
async expand(delta) {
|
|
14244
16615
|
const branch = selectedBranch(this.state);
|
|
14245
|
-
const next =
|
|
16616
|
+
const next = layerContext(this.state.context, delta);
|
|
14246
16617
|
if (branch === void 0 || next === this.state.context) return;
|
|
14247
16618
|
const line = sourceLineAt(this.state, this.state.cursor);
|
|
14248
16619
|
const patches = await this.run(listPatches(this.repo, branch.branch, next));
|
|
14249
|
-
const
|
|
16620
|
+
const widened = withContext(this.state, next, patches, 0);
|
|
16621
|
+
const patch = selectedPatch(widened);
|
|
14250
16622
|
const cursor = patch === void 0 || line === void 0 ? 0 : rowAtSourceLine(patch, line);
|
|
14251
16623
|
this.commit(withContext(this.state, next, patches, cursor));
|
|
14252
16624
|
}
|
|
@@ -14257,6 +16629,30 @@ var App = class {
|
|
|
14257
16629
|
if (pending.length === 0) return this.commit(withNotice(this.state, "nothing staged"));
|
|
14258
16630
|
this.commit(withPending(this.state, pending, "pending"));
|
|
14259
16631
|
}
|
|
16632
|
+
editStagedComment() {
|
|
16633
|
+
const entry = this.state.pending[this.state.pendingIndex];
|
|
16634
|
+
if (entry?.id === void 0) return;
|
|
16635
|
+
this.commit({
|
|
16636
|
+
...this.state,
|
|
16637
|
+
screen: "compose",
|
|
16638
|
+
draft: entry.body,
|
|
16639
|
+
editing: entry.id
|
|
16640
|
+
});
|
|
16641
|
+
}
|
|
16642
|
+
async dropStagedComment() {
|
|
16643
|
+
const branch = selectedBranch(this.state);
|
|
16644
|
+
const entry = this.state.pending[this.state.pendingIndex];
|
|
16645
|
+
if (branch === void 0 || entry?.id === void 0) return;
|
|
16646
|
+
await this.run(dropStaged(this.repo, branch.branch, entry.id));
|
|
16647
|
+
const pending = await this.run(listPending(this.repo, branch.branch));
|
|
16648
|
+
const kept = withPending(this.state, pending, pending.length === 0 ? "review" : "pending");
|
|
16649
|
+
const at = Math.min(this.state.pendingIndex, Math.max(0, pending.length - 1));
|
|
16650
|
+
const said = pending.length === 0 ? "nothing staged" : `withdrawn — ${pending.length} left`;
|
|
16651
|
+
this.commit(withNoticeHere({
|
|
16652
|
+
...kept,
|
|
16653
|
+
pendingIndex: at
|
|
16654
|
+
}, said));
|
|
16655
|
+
}
|
|
14260
16656
|
async sendReview() {
|
|
14261
16657
|
const branch = selectedBranch(this.state);
|
|
14262
16658
|
if (branch === void 0) return;
|
|
@@ -14314,6 +16710,8 @@ const launch = fn("Tui.launch")(function* (repo, renderer, noticeMs, sessionPath
|
|
|
14314
16710
|
const context$2 = yield* context();
|
|
14315
16711
|
const branches = yield* listBranches(repo);
|
|
14316
16712
|
const resume = sessionPath === void 0 ? void 0 : yield* promise(() => readSession(sessionPath));
|
|
16713
|
+
const store = yield* Store;
|
|
16714
|
+
const settings = yield* store.settings();
|
|
14317
16715
|
return new App({
|
|
14318
16716
|
renderer,
|
|
14319
16717
|
repo,
|
|
@@ -14321,7 +16719,9 @@ const launch = fn("Tui.launch")(function* (repo, renderer, noticeMs, sessionPath
|
|
|
14321
16719
|
branches,
|
|
14322
16720
|
noticeMs,
|
|
14323
16721
|
sessionPath,
|
|
14324
|
-
resume
|
|
16722
|
+
resume,
|
|
16723
|
+
wrap: settings.wrap === true,
|
|
16724
|
+
storeRoot: store.root
|
|
14325
16725
|
});
|
|
14326
16726
|
});
|
|
14327
16727
|
const untilDestroyed = (renderer) => callback((resume) => {
|
|
@@ -14370,6 +16770,24 @@ const commentTake = fn("Main.commentTake")(function* (options) {
|
|
|
14370
16770
|
const comments = wait > 0 ? yield* awaitComments(worktree, Date.now() + wait * WAIT_UNIT) : yield* takeComments(worktree);
|
|
14371
16771
|
yield* answer(options, { comments });
|
|
14372
16772
|
});
|
|
16773
|
+
const commentAnswer = fn("Main.commentAnswer")(function* (options) {
|
|
16774
|
+
const report = yield* answerComment({
|
|
16775
|
+
worktree: yield* required(options, "worktree"),
|
|
16776
|
+
id: yield* required(options, "id"),
|
|
16777
|
+
body: yield* required(options, "body"),
|
|
16778
|
+
asks: options["asks"] !== void 0,
|
|
16779
|
+
at: options["at"] ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
16780
|
+
});
|
|
16781
|
+
yield* answer(options, { answered: report.answered });
|
|
16782
|
+
});
|
|
16783
|
+
const commentThreads = fn("Main.commentThreads")(function* (options) {
|
|
16784
|
+
const threads = yield* listThreads(yield* required(options, "repo"), yield* required(options, "branch"));
|
|
16785
|
+
yield* answer(options, { threads });
|
|
16786
|
+
});
|
|
16787
|
+
const commentResolve = fn("Main.commentResolve")(function* (options) {
|
|
16788
|
+
const report = yield* settleThread(yield* required(options, "repo"), yield* required(options, "branch"), yield* required(options, "id"), options["at"] ?? (/* @__PURE__ */ new Date()).toISOString());
|
|
16789
|
+
yield* answer(options, { settled: report.settled });
|
|
16790
|
+
});
|
|
14373
16791
|
const commentStage = fn("Main.commentStage")(function* (options) {
|
|
14374
16792
|
const report = yield* stageComment({
|
|
14375
16793
|
repo: yield* required(options, "repo"),
|
|
@@ -14384,6 +16802,19 @@ const commentStage = fn("Main.commentStage")(function* (options) {
|
|
|
14384
16802
|
});
|
|
14385
16803
|
yield* answer(options, { pending: report.pending });
|
|
14386
16804
|
});
|
|
16805
|
+
const commentEdit = fn("Main.commentEdit")(function* (options) {
|
|
16806
|
+
const report = yield* editStaged({
|
|
16807
|
+
repo: yield* required(options, "repo"),
|
|
16808
|
+
branch: yield* required(options, "branch"),
|
|
16809
|
+
id: yield* required(options, "id"),
|
|
16810
|
+
body: yield* required(options, "body")
|
|
16811
|
+
});
|
|
16812
|
+
yield* answer(options, { pending: report.pending });
|
|
16813
|
+
});
|
|
16814
|
+
const commentDrop = fn("Main.commentDrop")(function* (options) {
|
|
16815
|
+
const report = yield* dropStaged(yield* required(options, "repo"), yield* required(options, "branch"), yield* required(options, "id"));
|
|
16816
|
+
yield* answer(options, { pending: report.pending });
|
|
16817
|
+
});
|
|
14387
16818
|
const reviewSubmit = fn("Main.reviewSubmit")(function* (options) {
|
|
14388
16819
|
const report = yield* submitReview(yield* required(options, "repo"), yield* required(options, "branch"), options["id"] ?? randomUUID(), options["at"] ?? (/* @__PURE__ */ new Date()).toISOString());
|
|
14389
16820
|
yield* answer(options, { submitted: report.submitted });
|
|
@@ -14410,24 +16841,29 @@ const reviewStatus = fn("Main.reviewStatus")(function* (options) {
|
|
|
14410
16841
|
const documentAt = fn("Main.documentAt")(function* (source) {
|
|
14411
16842
|
return yield* tryPromise({
|
|
14412
16843
|
try: () => source === "-" ? text(process.stdin) : readFile(source, "utf8"),
|
|
14413
|
-
catch: (cause) => new
|
|
16844
|
+
catch: (cause) => new MalformedLayers({ reason: String(cause) })
|
|
14414
16845
|
});
|
|
14415
16846
|
});
|
|
14416
16847
|
const routes = {
|
|
14417
16848
|
"branch list": branchList,
|
|
14418
16849
|
"comment add": commentAdd,
|
|
14419
16850
|
"comment stage": commentStage,
|
|
16851
|
+
"comment edit": commentEdit,
|
|
16852
|
+
"comment drop": commentDrop,
|
|
14420
16853
|
"comment take": commentTake,
|
|
16854
|
+
"comment answer": commentAnswer,
|
|
16855
|
+
"comment threads": commentThreads,
|
|
16856
|
+
"comment resolve": commentResolve,
|
|
14421
16857
|
"review submit": reviewSubmit,
|
|
14422
16858
|
"review progress": reviewStatus,
|
|
14423
|
-
"
|
|
16859
|
+
"layers set": fn("Main.layersSet")(function* (options) {
|
|
14424
16860
|
const document = yield* documentAt(yield* required(options, "json"));
|
|
14425
|
-
const
|
|
14426
|
-
yield* answer(options, {
|
|
16861
|
+
const layers = yield* setLayers(yield* required(options, "worktree"), document, options["at"] ?? (/* @__PURE__ */ new Date()).toISOString());
|
|
16862
|
+
yield* answer(options, { layers });
|
|
14427
16863
|
}),
|
|
14428
|
-
"
|
|
14429
|
-
const
|
|
14430
|
-
yield* answer(options, {
|
|
16864
|
+
"layers show": fn("Main.layersShow")(function* (options) {
|
|
16865
|
+
const layers = yield* showLayers(yield* required(options, "worktree"));
|
|
16866
|
+
yield* answer(options, { layers });
|
|
14431
16867
|
}),
|
|
14432
16868
|
describe: fn("Main.describe")(function* (options) {
|
|
14433
16869
|
const wanted = options["command"];
|
|
@@ -14456,7 +16892,26 @@ const nameOf = (argv) => {
|
|
|
14456
16892
|
return findCommand(pair) === void 0 ? words[0] ?? "" : pair;
|
|
14457
16893
|
};
|
|
14458
16894
|
const argv = process.argv.slice(2);
|
|
14459
|
-
const
|
|
16895
|
+
const ASKS = {
|
|
16896
|
+
"--version": version,
|
|
16897
|
+
"-v": version,
|
|
16898
|
+
"--help": help,
|
|
16899
|
+
"-h": help
|
|
16900
|
+
};
|
|
16901
|
+
const spoken = (words) => {
|
|
16902
|
+
const [first, ...rest] = words;
|
|
16903
|
+
if (first === void 0) return banner();
|
|
16904
|
+
const asked = ASKS[first];
|
|
16905
|
+
if (asked !== void 0) return asked();
|
|
16906
|
+
if (first !== "help") return void 0;
|
|
16907
|
+
return rest.length === 0 ? help() : helpFor(rest.join(" ")) ?? help();
|
|
16908
|
+
};
|
|
16909
|
+
const said = spoken(argv);
|
|
16910
|
+
if (said !== void 0) {
|
|
16911
|
+
process.stdout.write(`${said}\n`);
|
|
16912
|
+
process.exit(0);
|
|
16913
|
+
}
|
|
16914
|
+
const layer = mergeAll(GitLive, ForgeLive, storeAt(process.env["ADIFF_ROOT"] ?? defaultRoot()));
|
|
14460
16915
|
const exit = await runPromiseExit(run(nameOf(argv), optionsFrom(argv)).pipe(provide(layer)));
|
|
14461
16916
|
if (isFailure(exit)) {
|
|
14462
16917
|
const reported = failure(squash(exit.cause));
|