@eliya-oss/agent-diff 0.1.0-alpha.2 → 0.1.0-alpha.21
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 +130 -0
- package/README.md +23 -10
- package/bin/adiff.js +76 -2
- package/dist/main.js +2938 -360
- 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**
|
|
@@ -5066,6 +5132,19 @@ const MinimumLogLevel = /*#__PURE__*/ Reference("effect/References/MinimumLogLev
|
|
|
5066
5132
|
//#endregion
|
|
5067
5133
|
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/internal/tracer.js
|
|
5068
5134
|
/** @internal */
|
|
5135
|
+
const addSpanStackTrace = (options) => {
|
|
5136
|
+
if (options?.captureStackTrace === false) return options;
|
|
5137
|
+
else if (options?.captureStackTrace !== void 0 && typeof options.captureStackTrace !== "boolean") return options;
|
|
5138
|
+
const limit = getStackTraceLimit();
|
|
5139
|
+
setStackTraceLimit(3);
|
|
5140
|
+
const traceError = /* @__PURE__ */ new Error();
|
|
5141
|
+
setStackTraceLimit(limit);
|
|
5142
|
+
return {
|
|
5143
|
+
...options,
|
|
5144
|
+
captureStackTrace: spanCleaner(() => traceError.stack)
|
|
5145
|
+
};
|
|
5146
|
+
};
|
|
5147
|
+
/** @internal */
|
|
5069
5148
|
const makeStackCleaner = (line) => (stack) => {
|
|
5070
5149
|
let cache;
|
|
5071
5150
|
return () => {
|
|
@@ -5079,6 +5158,7 @@ const makeStackCleaner = (line) => (stack) => {
|
|
|
5079
5158
|
}
|
|
5080
5159
|
};
|
|
5081
5160
|
};
|
|
5161
|
+
const spanCleaner = /*#__PURE__*/ makeStackCleaner(3);
|
|
5082
5162
|
//#endregion
|
|
5083
5163
|
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/internal/effect.js
|
|
5084
5164
|
/** @internal */
|
|
@@ -5435,8 +5515,22 @@ const failCauseSync$1 = (evaluate) => suspend(() => failCause$1(internalCall(eva
|
|
|
5435
5515
|
/** @internal */
|
|
5436
5516
|
const die = (defect) => exitDie(defect);
|
|
5437
5517
|
/** @internal */
|
|
5518
|
+
const failSync = (error) => suspend(() => fail$2(internalCall(error)));
|
|
5519
|
+
/** @internal */
|
|
5438
5520
|
const void_$2 = /*#__PURE__*/ succeed$2(void 0);
|
|
5439
5521
|
/** @internal */
|
|
5522
|
+
const try_$1 = (options) => {
|
|
5523
|
+
const evaluate = typeof options === "function" ? options : options.try;
|
|
5524
|
+
const catcher = typeof options === "function" ? (cause) => new UnknownError(cause, "An error occurred in Effect.try") : options.catch;
|
|
5525
|
+
return suspend(() => {
|
|
5526
|
+
try {
|
|
5527
|
+
return succeed$2(internalCall(evaluate));
|
|
5528
|
+
} catch (err) {
|
|
5529
|
+
return fail$2(internalCall(() => catcher(err)));
|
|
5530
|
+
}
|
|
5531
|
+
});
|
|
5532
|
+
};
|
|
5533
|
+
/** @internal */
|
|
5440
5534
|
const promise$1 = (evaluate) => callbackOptions(function(resume, signal) {
|
|
5441
5535
|
internalCall(() => evaluate(signal)).then((a) => resume(succeed$2(a)), (e) => resume(die(e)));
|
|
5442
5536
|
}, evaluate.length !== 0);
|
|
@@ -5504,6 +5598,8 @@ const callback$1 = (register) => callbackOptions(register, register.length >= 2)
|
|
|
5504
5598
|
/** @internal */
|
|
5505
5599
|
const never = /*#__PURE__*/ callback$1(constVoid);
|
|
5506
5600
|
/** @internal */
|
|
5601
|
+
const gen$1 = (...args) => suspend(() => fromIteratorUnsafe(args.length === 1 ? args[0]() : args[1].call(args[0].self)));
|
|
5602
|
+
/** @internal */
|
|
5507
5603
|
const fnUntraced = (body, ...pipeables) => {
|
|
5508
5604
|
const fn = pipeables.length === 0 ? function() {
|
|
5509
5605
|
return suspend(() => fromIteratorUnsafe(body.apply(this, arguments)));
|
|
@@ -5555,6 +5651,40 @@ const makeFn = (name, bodyOrOptions, defError, pipeables, addSpan, spanOptions)
|
|
|
5555
5651
|
}));
|
|
5556
5652
|
});
|
|
5557
5653
|
};
|
|
5654
|
+
/** @internal */
|
|
5655
|
+
const fnUntracedEager$1 = (body, ...pipeables) => defineFunctionLength(body.length, pipeables.length === 0 ? function() {
|
|
5656
|
+
return fromIteratorEagerUnsafe(() => body.apply(this, arguments));
|
|
5657
|
+
} : function() {
|
|
5658
|
+
let effect = fromIteratorEagerUnsafe(() => body.apply(this, arguments));
|
|
5659
|
+
for (const pipeable of pipeables) effect = pipeable(effect);
|
|
5660
|
+
return effect;
|
|
5661
|
+
});
|
|
5662
|
+
const fromIteratorEagerUnsafe = (evaluate) => {
|
|
5663
|
+
try {
|
|
5664
|
+
const iterator = evaluate();
|
|
5665
|
+
let value = void 0;
|
|
5666
|
+
while (true) {
|
|
5667
|
+
const state = iterator.next(value);
|
|
5668
|
+
if (state.done) return succeed$2(state.value);
|
|
5669
|
+
const primitive = state.value;
|
|
5670
|
+
if (primitive && primitive._tag === "Success") {
|
|
5671
|
+
value = primitive.value;
|
|
5672
|
+
continue;
|
|
5673
|
+
} else if (primitive && primitive._tag === "Failure") return state.value;
|
|
5674
|
+
else {
|
|
5675
|
+
let isFirstExecution = true;
|
|
5676
|
+
return suspend(() => {
|
|
5677
|
+
if (isFirstExecution) {
|
|
5678
|
+
isFirstExecution = false;
|
|
5679
|
+
return flatMap$1(state.value, (value) => fromIteratorUnsafe(iterator, value));
|
|
5680
|
+
} else return suspend(() => fromIteratorUnsafe(evaluate()));
|
|
5681
|
+
});
|
|
5682
|
+
}
|
|
5683
|
+
}
|
|
5684
|
+
} catch (error) {
|
|
5685
|
+
return die(error);
|
|
5686
|
+
}
|
|
5687
|
+
};
|
|
5558
5688
|
const fromIteratorUnsafe = /*#__PURE__*/ makePrimitive({
|
|
5559
5689
|
op: "Iterator",
|
|
5560
5690
|
single: false,
|
|
@@ -5671,6 +5801,13 @@ const OnFailureProto = /*#__PURE__*/ makePrimitiveProto({
|
|
|
5671
5801
|
}
|
|
5672
5802
|
});
|
|
5673
5803
|
/** @internal */
|
|
5804
|
+
const catchCauseFilter = /*#__PURE__*/ dual(3, (self, filter, f) => catchCause$1(self, (cause) => {
|
|
5805
|
+
const eb = filter(cause);
|
|
5806
|
+
return isFailure$1(eb) ? failCause$1(eb.failure) : internalCall(() => f(eb.success, cause));
|
|
5807
|
+
}));
|
|
5808
|
+
/** @internal */
|
|
5809
|
+
const catch_ = /*#__PURE__*/ dual(2, (self, f) => catchCauseFilter(self, findError, (e) => f(e)));
|
|
5810
|
+
/** @internal */
|
|
5674
5811
|
const catchIf = /*#__PURE__*/ dual((args) => isEffect(args[0]), (self, predicate, f, orElse) => catchCause$1(self, (cause) => {
|
|
5675
5812
|
const error = findError(cause);
|
|
5676
5813
|
if (isFailure$1(error)) return failCause$1(error.failure);
|
|
@@ -5683,6 +5820,8 @@ const catchTag$1 = /*#__PURE__*/ dual((args) => isEffect(args[0]), (self, k, f,
|
|
|
5683
5820
|
return catchIf(self, pred, f, orElse);
|
|
5684
5821
|
});
|
|
5685
5822
|
/** @internal */
|
|
5823
|
+
const mapError$1 = /*#__PURE__*/ dual(2, (self, f) => catch_(self, (error) => failSync(() => f(error))));
|
|
5824
|
+
/** @internal */
|
|
5686
5825
|
const exit$2 = (self) => effectIsExit(self) ? exitSucceed(self) : exitPrimitive(self);
|
|
5687
5826
|
const exitPrimitive = /*#__PURE__*/ makePrimitive({
|
|
5688
5827
|
op: "Exit",
|
|
@@ -6118,6 +6257,14 @@ const makeSpanUnsafe = (fiber, name, options) => {
|
|
|
6118
6257
|
}
|
|
6119
6258
|
return span;
|
|
6120
6259
|
};
|
|
6260
|
+
const provideSpanStackFrame = (name, stack) => {
|
|
6261
|
+
stack = typeof stack === "function" ? stack : constUndefined;
|
|
6262
|
+
return updateService(CurrentStackFrame, (parent) => ({
|
|
6263
|
+
name,
|
|
6264
|
+
stack,
|
|
6265
|
+
parent
|
|
6266
|
+
}));
|
|
6267
|
+
};
|
|
6121
6268
|
/** @internal */
|
|
6122
6269
|
const useSpan = (name, ...args) => {
|
|
6123
6270
|
const options = args.length === 1 ? void 0 : args[0];
|
|
@@ -6133,6 +6280,32 @@ const useSpan = (name, ...args) => {
|
|
|
6133
6280
|
};
|
|
6134
6281
|
const provideParentSpan = /*#__PURE__*/ provideService(ParentSpan);
|
|
6135
6282
|
/** @internal */
|
|
6283
|
+
const withParentSpan = function() {
|
|
6284
|
+
const dataFirst = isEffect(arguments[0]);
|
|
6285
|
+
const span = dataFirst ? arguments[1] : arguments[0];
|
|
6286
|
+
let options = dataFirst ? arguments[2] : arguments[1];
|
|
6287
|
+
let provideStackFrame = identity;
|
|
6288
|
+
if (span._tag === "Span") {
|
|
6289
|
+
options = addSpanStackTrace(options);
|
|
6290
|
+
provideStackFrame = provideSpanStackFrame(span.name, options?.captureStackTrace);
|
|
6291
|
+
}
|
|
6292
|
+
if (dataFirst) return provideParentSpan(provideStackFrame(arguments[0]), span);
|
|
6293
|
+
return (self) => provideParentSpan(provideStackFrame(self), span);
|
|
6294
|
+
};
|
|
6295
|
+
/** @internal */
|
|
6296
|
+
const withSpan$1 = function() {
|
|
6297
|
+
const dataFirst = typeof arguments[0] !== "string";
|
|
6298
|
+
const name = dataFirst ? arguments[1] : arguments[0];
|
|
6299
|
+
const traceOptions = addSpanStackTrace(arguments[2]);
|
|
6300
|
+
if (dataFirst) {
|
|
6301
|
+
const self = arguments[0];
|
|
6302
|
+
return useSpan(name, arguments[2], (span) => withParentSpan(self, span, traceOptions));
|
|
6303
|
+
}
|
|
6304
|
+
const fnArg = typeof arguments[1] === "function" ? arguments[1] : void 0;
|
|
6305
|
+
const options = fnArg ? void 0 : arguments[1];
|
|
6306
|
+
return (self, ...args) => useSpan(name, fnArg ? fnArg(...args) : options, (span) => withParentSpan(self, span, traceOptions));
|
|
6307
|
+
};
|
|
6308
|
+
/** @internal */
|
|
6136
6309
|
const ClockRef = /*#__PURE__*/ Reference("effect/Clock", { defaultValue: () => new ClockImpl() });
|
|
6137
6310
|
const MAX_TIMER_MILLIS = 2 ** 31 - 1;
|
|
6138
6311
|
var ClockImpl = class {
|
|
@@ -6344,6 +6517,39 @@ const map$1 = causeMap;
|
|
|
6344
6517
|
const squash = causeSquash;
|
|
6345
6518
|
Service()("effect/Cause/StackTrace");
|
|
6346
6519
|
Service()("effect/Cause/InterruptorStackTrace");
|
|
6520
|
+
//#endregion
|
|
6521
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/Exit.js
|
|
6522
|
+
/**
|
|
6523
|
+
* Creates a failed Exit from a Cause.
|
|
6524
|
+
*
|
|
6525
|
+
* **When to use**
|
|
6526
|
+
*
|
|
6527
|
+
* Use when you already have a `Cause<E>` and want to wrap it in an Exit
|
|
6528
|
+
* for advanced error handling where you need full control over the Cause
|
|
6529
|
+
* structure.
|
|
6530
|
+
*
|
|
6531
|
+
* **Details**
|
|
6532
|
+
*
|
|
6533
|
+
* Returns a `Failure<never, E>`. If you only have an error value, use
|
|
6534
|
+
* {@link fail} instead.
|
|
6535
|
+
*
|
|
6536
|
+
* **Example** (Creating a failed Exit from a Cause)
|
|
6537
|
+
*
|
|
6538
|
+
* ```ts
|
|
6539
|
+
* import { Cause, Exit } from "effect"
|
|
6540
|
+
*
|
|
6541
|
+
* const cause = Cause.fail("Something went wrong")
|
|
6542
|
+
* const exit = Exit.failCause(cause)
|
|
6543
|
+
* console.log(Exit.isFailure(exit)) // true
|
|
6544
|
+
* ```
|
|
6545
|
+
*
|
|
6546
|
+
* @see {@link fail} to create a Failure from a plain error value
|
|
6547
|
+
* @see {@link die} to create a Failure from a defect
|
|
6548
|
+
*
|
|
6549
|
+
* @category constructors
|
|
6550
|
+
* @since 2.0.0
|
|
6551
|
+
*/
|
|
6552
|
+
const failCause = exitFailCause;
|
|
6347
6553
|
/**
|
|
6348
6554
|
* Creates a failed Exit from a typed error value.
|
|
6349
6555
|
*
|
|
@@ -7390,6 +7596,57 @@ const void_ = void_$2;
|
|
|
7390
7596
|
*/
|
|
7391
7597
|
const callback = callback$1;
|
|
7392
7598
|
/**
|
|
7599
|
+
* Provides a way to write effectful code using generator functions, simplifying
|
|
7600
|
+
* control flow and error handling.
|
|
7601
|
+
*
|
|
7602
|
+
* **When to use**
|
|
7603
|
+
*
|
|
7604
|
+
* Use when you want to write effectful code that looks and behaves like
|
|
7605
|
+
* synchronous code, while still handling asynchronous tasks, errors, and complex
|
|
7606
|
+
* control flow such as loops and conditions.
|
|
7607
|
+
*
|
|
7608
|
+
* Generator functions work similarly to `async/await` but keep errors,
|
|
7609
|
+
* requirements, and interruption in the Effect type. You can `yield*` values
|
|
7610
|
+
* from effects and return the final result at the end.
|
|
7611
|
+
*
|
|
7612
|
+
* **Example** (Sequencing effects with generators)
|
|
7613
|
+
*
|
|
7614
|
+
* ```ts
|
|
7615
|
+
* import { Data, Effect } from "effect"
|
|
7616
|
+
*
|
|
7617
|
+
* class DiscountRateError extends Data.TaggedError("DiscountRateError")<{}> {}
|
|
7618
|
+
*
|
|
7619
|
+
* const addServiceCharge = (amount: number) => amount + 1
|
|
7620
|
+
*
|
|
7621
|
+
* const applyDiscount = (
|
|
7622
|
+
* total: number,
|
|
7623
|
+
* discountRate: number
|
|
7624
|
+
* ): Effect.Effect<number, DiscountRateError> =>
|
|
7625
|
+
* discountRate === 0
|
|
7626
|
+
* ? Effect.fail(new DiscountRateError())
|
|
7627
|
+
* : Effect.succeed(total - (total * discountRate) / 100)
|
|
7628
|
+
*
|
|
7629
|
+
* const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
|
|
7630
|
+
*
|
|
7631
|
+
* const fetchDiscountRate = Effect.promise(() => Promise.resolve(5))
|
|
7632
|
+
*
|
|
7633
|
+
* export const program = Effect.gen(function*() {
|
|
7634
|
+
* const transactionAmount = yield* fetchTransactionAmount
|
|
7635
|
+
* const discountRate = yield* fetchDiscountRate
|
|
7636
|
+
* const discountedAmount = yield* applyDiscount(
|
|
7637
|
+
* transactionAmount,
|
|
7638
|
+
* discountRate
|
|
7639
|
+
* )
|
|
7640
|
+
* const finalAmount = addServiceCharge(discountedAmount)
|
|
7641
|
+
* return `Final amount to charge: ${finalAmount}`
|
|
7642
|
+
* })
|
|
7643
|
+
* ```
|
|
7644
|
+
*
|
|
7645
|
+
* @category constructors
|
|
7646
|
+
* @since 2.0.0
|
|
7647
|
+
*/
|
|
7648
|
+
const gen = gen$1;
|
|
7649
|
+
/**
|
|
7393
7650
|
* Creates an `Effect` that represents a recoverable error.
|
|
7394
7651
|
*
|
|
7395
7652
|
* **When to use**
|
|
@@ -7448,6 +7705,7 @@ const fail = fail$2;
|
|
|
7448
7705
|
* @since 2.0.0
|
|
7449
7706
|
*/
|
|
7450
7707
|
const failCauseSync = failCauseSync$1;
|
|
7708
|
+
const try_ = try_$1;
|
|
7451
7709
|
/**
|
|
7452
7710
|
* Chains effects to produce new `Effect` instances, useful for combining
|
|
7453
7711
|
* operations that depend on previous results.
|
|
@@ -7516,6 +7774,49 @@ const failCauseSync = failCauseSync$1;
|
|
|
7516
7774
|
*/
|
|
7517
7775
|
const flatMap = flatMap$1;
|
|
7518
7776
|
/**
|
|
7777
|
+
* Transforms an effect to encapsulate both failure and success using the `Exit`
|
|
7778
|
+
* data type.
|
|
7779
|
+
*
|
|
7780
|
+
* **When to use**
|
|
7781
|
+
*
|
|
7782
|
+
* Use when you need to inspect the full outcome, including typed failures, defects,
|
|
7783
|
+
* and interruptions.
|
|
7784
|
+
*
|
|
7785
|
+
* **Details**
|
|
7786
|
+
*
|
|
7787
|
+
* `exit` wraps an effect's success or failure inside an `Exit` type, allowing
|
|
7788
|
+
* you to handle both cases explicitly.
|
|
7789
|
+
*
|
|
7790
|
+
* The resulting effect cannot fail because the failure is encapsulated within
|
|
7791
|
+
* the `Exit.Failure` type. The error type is set to `never`, indicating that
|
|
7792
|
+
* the effect is structured to never fail directly.
|
|
7793
|
+
*
|
|
7794
|
+
* **Example** (Capturing completion as Exit)
|
|
7795
|
+
*
|
|
7796
|
+
* ```ts
|
|
7797
|
+
* import { Effect } from "effect"
|
|
7798
|
+
*
|
|
7799
|
+
* const success = Effect.succeed(42)
|
|
7800
|
+
* const failure = Effect.fail("Something went wrong")
|
|
7801
|
+
*
|
|
7802
|
+
* const program1 = Effect.exit(success)
|
|
7803
|
+
* const program2 = Effect.exit(failure)
|
|
7804
|
+
*
|
|
7805
|
+
* Effect.runPromise(program1).then(console.log)
|
|
7806
|
+
* // { _id: 'Exit', _tag: 'Success', value: 42 }
|
|
7807
|
+
*
|
|
7808
|
+
* Effect.runPromise(program2).then(console.log)
|
|
7809
|
+
* // { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: 'Something went wrong' } }
|
|
7810
|
+
* ```
|
|
7811
|
+
*
|
|
7812
|
+
* @see {@link option} for a version that uses `Option` instead.
|
|
7813
|
+
* @see {@link result} for a version that uses `Result` instead.
|
|
7814
|
+
*
|
|
7815
|
+
* @category outcome encapsulation
|
|
7816
|
+
* @since 2.0.0
|
|
7817
|
+
*/
|
|
7818
|
+
const exit$1 = exit$2;
|
|
7819
|
+
/**
|
|
7519
7820
|
* Transforms the value inside an effect by applying a function to it.
|
|
7520
7821
|
*
|
|
7521
7822
|
* **When to use**
|
|
@@ -7658,6 +7959,45 @@ const catchTag = catchTag$1;
|
|
|
7658
7959
|
*/
|
|
7659
7960
|
const catchCause = catchCause$1;
|
|
7660
7961
|
/**
|
|
7962
|
+
* Transforms the failure value of an effect without changing its success value.
|
|
7963
|
+
*
|
|
7964
|
+
* **When to use**
|
|
7965
|
+
*
|
|
7966
|
+
* Use to translate an `Effect`'s typed failures while leaving successful values
|
|
7967
|
+
* unchanged.
|
|
7968
|
+
*
|
|
7969
|
+
* **Details**
|
|
7970
|
+
*
|
|
7971
|
+
* Only the failure channel is transformed. The success channel and requirements
|
|
7972
|
+
* are preserved.
|
|
7973
|
+
*
|
|
7974
|
+
* **Example** (Transforming the error channel)
|
|
7975
|
+
*
|
|
7976
|
+
* ```ts
|
|
7977
|
+
* import { Data, Effect } from "effect"
|
|
7978
|
+
*
|
|
7979
|
+
* class TaskError extends Data.TaggedError("TaskError")<{ readonly message: string }> {}
|
|
7980
|
+
*
|
|
7981
|
+
* // ┌─── Effect<number, string, never>
|
|
7982
|
+
* // ▼
|
|
7983
|
+
* const simulatedTask = Effect.fail("Oh no!").pipe(Effect.as(1))
|
|
7984
|
+
*
|
|
7985
|
+
* // ┌─── Effect<number, TaskError, never>
|
|
7986
|
+
* // ▼
|
|
7987
|
+
* const mapped = Effect.mapError(
|
|
7988
|
+
* simulatedTask,
|
|
7989
|
+
* (message) => new TaskError({ message })
|
|
7990
|
+
* )
|
|
7991
|
+
* ```
|
|
7992
|
+
*
|
|
7993
|
+
* @see {@link map} for a version that operates on the success channel.
|
|
7994
|
+
* @see {@link mapBoth} for a version that operates on both channels.
|
|
7995
|
+
*
|
|
7996
|
+
* @category error handling
|
|
7997
|
+
* @since 2.0.0
|
|
7998
|
+
*/
|
|
7999
|
+
const mapError = mapError$1;
|
|
8000
|
+
/**
|
|
7661
8001
|
* Returns an effect that suspends the current fiber for the specified duration
|
|
7662
8002
|
* without blocking a JavaScript thread.
|
|
7663
8003
|
*
|
|
@@ -7766,6 +8106,28 @@ const context = context$1;
|
|
|
7766
8106
|
*/
|
|
7767
8107
|
const provide = provide$1;
|
|
7768
8108
|
/**
|
|
8109
|
+
* Wraps the effect with a child span for tracing.
|
|
8110
|
+
*
|
|
8111
|
+
* **Example** (Wrapping an effect in a child span)
|
|
8112
|
+
*
|
|
8113
|
+
* ```ts
|
|
8114
|
+
* import { Effect } from "effect"
|
|
8115
|
+
*
|
|
8116
|
+
* const task = Effect.gen(function*() {
|
|
8117
|
+
* yield* Effect.log("Executing task")
|
|
8118
|
+
* return "result"
|
|
8119
|
+
* })
|
|
8120
|
+
*
|
|
8121
|
+
* const traced = Effect.withSpan(task, "my-task", {
|
|
8122
|
+
* attributes: { version: "1.0" }
|
|
8123
|
+
* })
|
|
8124
|
+
* ```
|
|
8125
|
+
*
|
|
8126
|
+
* @category tracing
|
|
8127
|
+
* @since 2.0.0
|
|
8128
|
+
*/
|
|
8129
|
+
const withSpan = withSpan$1;
|
|
8130
|
+
/**
|
|
7769
8131
|
* Executes an effect as a Promise with the provided services.
|
|
7770
8132
|
*
|
|
7771
8133
|
* **When to use**
|
|
@@ -8107,6 +8469,32 @@ const mapEager = mapEager$1;
|
|
|
8107
8469
|
* @since 4.0.0
|
|
8108
8470
|
*/
|
|
8109
8471
|
const flatMapEager = flatMapEager$1;
|
|
8472
|
+
/**
|
|
8473
|
+
* Creates untraced function effects with eager evaluation optimization.
|
|
8474
|
+
*
|
|
8475
|
+
* **Details**
|
|
8476
|
+
*
|
|
8477
|
+
* Executes generator functions eagerly when all yielded effects are synchronous,
|
|
8478
|
+
* stopping at the first async effect and deferring to normal execution.
|
|
8479
|
+
*
|
|
8480
|
+
* **Example** (Defining eager untraced effect functions)
|
|
8481
|
+
*
|
|
8482
|
+
* ```ts
|
|
8483
|
+
* import { Effect } from "effect"
|
|
8484
|
+
*
|
|
8485
|
+
* const computation = Effect.fnUntracedEager(function*() {
|
|
8486
|
+
* yield* Effect.succeed(1)
|
|
8487
|
+
* yield* Effect.succeed(2)
|
|
8488
|
+
* return "computed eagerly"
|
|
8489
|
+
* })
|
|
8490
|
+
*
|
|
8491
|
+
* const effect = computation() // Executed immediately if all effects are sync
|
|
8492
|
+
* ```
|
|
8493
|
+
*
|
|
8494
|
+
* @category eager
|
|
8495
|
+
* @since 4.0.0
|
|
8496
|
+
*/
|
|
8497
|
+
const fnUntracedEager = fnUntracedEager$1;
|
|
8110
8498
|
//#endregion
|
|
8111
8499
|
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/internal/schema/annotations.js
|
|
8112
8500
|
/** @internal */
|
|
@@ -8307,6 +8695,72 @@ var Pointer = class extends Base$1 {
|
|
|
8307
8695
|
}
|
|
8308
8696
|
};
|
|
8309
8697
|
/**
|
|
8698
|
+
* Represents a schema issue produced when a required key or tuple index is missing from the input.
|
|
8699
|
+
*
|
|
8700
|
+
* **When to use**
|
|
8701
|
+
*
|
|
8702
|
+
* Use when you need to detect absent fields in struct/tuple validation.
|
|
8703
|
+
*
|
|
8704
|
+
* **Details**
|
|
8705
|
+
*
|
|
8706
|
+
* - Has no `actual` value — {@link getActual} returns `Option.none()`.
|
|
8707
|
+
* - `annotations` may contain a custom `messageMissingKey` for formatting.
|
|
8708
|
+
*
|
|
8709
|
+
* @see {@link Pointer} — wraps this issue with the missing key's path
|
|
8710
|
+
* @see {@link UnexpectedKey} — the opposite case (extra key present)
|
|
8711
|
+
*
|
|
8712
|
+
* @category models
|
|
8713
|
+
* @since 4.0.0
|
|
8714
|
+
*/
|
|
8715
|
+
var MissingKey = class extends Base$1 {
|
|
8716
|
+
_tag = "MissingKey";
|
|
8717
|
+
/**
|
|
8718
|
+
* The metadata for the issue.
|
|
8719
|
+
*/
|
|
8720
|
+
annotations;
|
|
8721
|
+
constructor(annotations) {
|
|
8722
|
+
super();
|
|
8723
|
+
this.annotations = annotations;
|
|
8724
|
+
}
|
|
8725
|
+
};
|
|
8726
|
+
/**
|
|
8727
|
+
* Represents a schema issue produced when an input object or tuple contains a key/index not
|
|
8728
|
+
* declared by the schema.
|
|
8729
|
+
*
|
|
8730
|
+
* **When to use**
|
|
8731
|
+
*
|
|
8732
|
+
* Use when you need to detect excess properties during strict struct/tuple
|
|
8733
|
+
* validation.
|
|
8734
|
+
*
|
|
8735
|
+
* **Details**
|
|
8736
|
+
*
|
|
8737
|
+
* - `actual` is the raw value at the unexpected key (plain `unknown`).
|
|
8738
|
+
* - `ast` is the schema that was being validated against.
|
|
8739
|
+
* - `annotations` on `ast` may contain a custom `messageUnexpectedKey`.
|
|
8740
|
+
*
|
|
8741
|
+
* @see {@link MissingKey} — the opposite case (required key absent)
|
|
8742
|
+
* @see {@link Pointer} — wraps this issue with the unexpected key's path
|
|
8743
|
+
*
|
|
8744
|
+
* @category models
|
|
8745
|
+
* @since 4.0.0
|
|
8746
|
+
*/
|
|
8747
|
+
var UnexpectedKey = class extends Base$1 {
|
|
8748
|
+
_tag = "UnexpectedKey";
|
|
8749
|
+
/**
|
|
8750
|
+
* The schema that caused the issue.
|
|
8751
|
+
*/
|
|
8752
|
+
ast;
|
|
8753
|
+
/**
|
|
8754
|
+
* The input value that caused the issue.
|
|
8755
|
+
*/
|
|
8756
|
+
actual;
|
|
8757
|
+
constructor(ast, actual) {
|
|
8758
|
+
super();
|
|
8759
|
+
this.ast = ast;
|
|
8760
|
+
this.actual = actual;
|
|
8761
|
+
}
|
|
8762
|
+
};
|
|
8763
|
+
/**
|
|
8310
8764
|
* Represents a schema issue that groups multiple child issues under a single schema node.
|
|
8311
8765
|
*
|
|
8312
8766
|
* **When to use**
|
|
@@ -9415,20 +9869,514 @@ function numberToJson(checks) {
|
|
|
9415
9869
|
* @since 4.0.0
|
|
9416
9870
|
*/
|
|
9417
9871
|
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
9872
|
/**
|
|
9423
|
-
*
|
|
9873
|
+
* AST node matching any `boolean` value (`true` or `false`).
|
|
9874
|
+
*
|
|
9875
|
+
* @see {@link boolean}
|
|
9876
|
+
* @see {@link isBoolean}
|
|
9877
|
+
*
|
|
9878
|
+
* @category models
|
|
9879
|
+
* @since 4.0.0
|
|
9880
|
+
*/
|
|
9881
|
+
var Boolean$1 = class extends Base {
|
|
9882
|
+
_tag = "Boolean";
|
|
9883
|
+
/** @internal */
|
|
9884
|
+
getParser() {
|
|
9885
|
+
return fromRefinement(this, isBoolean);
|
|
9886
|
+
}
|
|
9887
|
+
/** @internal */
|
|
9888
|
+
getExpected() {
|
|
9889
|
+
return "boolean";
|
|
9890
|
+
}
|
|
9891
|
+
};
|
|
9892
|
+
/**
|
|
9893
|
+
* Provides the singleton {@link Boolean} AST instance.
|
|
9894
|
+
*
|
|
9895
|
+
* **When to use**
|
|
9896
|
+
*
|
|
9897
|
+
* Use to reuse the standard AST node that accepts either `true` or `false` when
|
|
9898
|
+
* constructing schema ASTs directly.
|
|
9899
|
+
*
|
|
9900
|
+
* @see {@link Boolean} for the AST node class
|
|
9901
|
+
* @see {@link Literal} for exact boolean literal AST nodes
|
|
9902
|
+
*
|
|
9903
|
+
* @category constructors
|
|
9904
|
+
* @since 4.0.0
|
|
9905
|
+
*/
|
|
9906
|
+
const boolean = /*#__PURE__*/ new Boolean$1();
|
|
9907
|
+
/**
|
|
9908
|
+
* AST node for array-like types — both tuples and arrays.
|
|
9909
|
+
*
|
|
9910
|
+
* **When to use**
|
|
9911
|
+
*
|
|
9912
|
+
* Use when constructing or inspecting AST nodes for tuple or array-like schemas,
|
|
9913
|
+
* including rest elements.
|
|
9914
|
+
*
|
|
9915
|
+
* **Details**
|
|
9916
|
+
*
|
|
9917
|
+
* - `elements` — positional element types (tuple elements). An element is
|
|
9918
|
+
* optional if its {@link Context.isOptional} is `true`.
|
|
9919
|
+
* - `rest` — the rest/variadic element types. When non-empty, the first
|
|
9920
|
+
* entry is the "spread" type (e.g. `...Array<string>`), and subsequent
|
|
9921
|
+
* entries are trailing positional elements after the spread.
|
|
9922
|
+
* - `isMutable` — whether the resulting array is `readonly` (`false`) or
|
|
9923
|
+
* mutable (`true`).
|
|
9924
|
+
*
|
|
9925
|
+
* **Gotchas**
|
|
9926
|
+
*
|
|
9927
|
+
* Construction enforces TypeScript ordering rules: a required element
|
|
9928
|
+
* cannot follow an optional one, and an optional element cannot follow a
|
|
9929
|
+
* rest element.
|
|
9930
|
+
*
|
|
9931
|
+
* **Example** (Inspecting a tuple AST)
|
|
9932
|
+
*
|
|
9933
|
+
* ```ts
|
|
9934
|
+
* import { Schema, SchemaAST } from "effect"
|
|
9935
|
+
*
|
|
9936
|
+
* const schema = Schema.Tuple([Schema.String, Schema.Number])
|
|
9937
|
+
* const ast = schema.ast
|
|
9938
|
+
*
|
|
9939
|
+
* if (SchemaAST.isArrays(ast)) {
|
|
9940
|
+
* console.log(ast.elements.length) // 2
|
|
9941
|
+
* console.log(ast.rest.length) // 0
|
|
9942
|
+
* }
|
|
9943
|
+
* ```
|
|
9944
|
+
*
|
|
9945
|
+
* @see {@link isArrays}
|
|
9946
|
+
* @see {@link Objects}
|
|
9947
|
+
* @category models
|
|
9948
|
+
* @since 4.0.0
|
|
9949
|
+
*/
|
|
9950
|
+
var Arrays = class Arrays extends Base {
|
|
9951
|
+
_tag = "Arrays";
|
|
9952
|
+
isMutable;
|
|
9953
|
+
elements;
|
|
9954
|
+
rest;
|
|
9955
|
+
encodingChecks;
|
|
9956
|
+
constructor(isMutable, elements, rest, annotations, checks, encoding, context, encodingChecks) {
|
|
9957
|
+
super(annotations, checks, encoding, context);
|
|
9958
|
+
this.isMutable = isMutable;
|
|
9959
|
+
this.elements = elements;
|
|
9960
|
+
this.rest = rest;
|
|
9961
|
+
this.encodingChecks = encodingChecks;
|
|
9962
|
+
const i = elements.findIndex(isOptional);
|
|
9963
|
+
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)");
|
|
9964
|
+
if (rest.length > 1 && rest.slice(1).some(isOptional)) throw new Error("An optional element cannot follow a rest element. ts(1266)");
|
|
9965
|
+
}
|
|
9966
|
+
/** @internal */
|
|
9967
|
+
getParser(recur) {
|
|
9968
|
+
const ast = this;
|
|
9969
|
+
const elements = ast.elements.map((ast) => ({
|
|
9970
|
+
ast,
|
|
9971
|
+
parser: recur(ast)
|
|
9972
|
+
}));
|
|
9973
|
+
const rest = ast.rest.map((ast) => ({
|
|
9974
|
+
ast,
|
|
9975
|
+
parser: recur(ast)
|
|
9976
|
+
}));
|
|
9977
|
+
const elementLen = elements.length;
|
|
9978
|
+
const [head, ...tail] = rest;
|
|
9979
|
+
const tailLen = tail.length;
|
|
9980
|
+
function getParser(tailThreshold, index) {
|
|
9981
|
+
if (index < elementLen) return elements[index];
|
|
9982
|
+
else if (index >= tailThreshold) return tail[index - tailThreshold];
|
|
9983
|
+
return head;
|
|
9984
|
+
}
|
|
9985
|
+
return fnUntracedEager(function* (oinput, options) {
|
|
9986
|
+
if (oinput._tag === "None") return oinput;
|
|
9987
|
+
const input = oinput.value;
|
|
9988
|
+
if (!Array.isArray(input)) return yield* fail(new InvalidType(ast, oinput));
|
|
9989
|
+
const len = input.length;
|
|
9990
|
+
const state = {
|
|
9991
|
+
ast,
|
|
9992
|
+
getParser,
|
|
9993
|
+
oinput,
|
|
9994
|
+
len,
|
|
9995
|
+
tailThreshold: resolveTailThreshold(len, elementLen, tailLen),
|
|
9996
|
+
output: new globalThis.Array(len),
|
|
9997
|
+
issues: void 0,
|
|
9998
|
+
options
|
|
9999
|
+
};
|
|
10000
|
+
const concurrency = resolveConcurrency(options?.concurrency);
|
|
10001
|
+
const eff = parseArray(state, input, {
|
|
10002
|
+
concurrency: concurrency?.concurrency,
|
|
10003
|
+
end: ast.rest.length === 0 ? elementLen : Math.max(len, elementLen + tailLen)
|
|
10004
|
+
});
|
|
10005
|
+
if (eff) yield* eff;
|
|
10006
|
+
if (ast.rest.length === 0 && len > elementLen) for (let i = elementLen; i <= len - 1; i++) {
|
|
10007
|
+
const issue = new Pointer([i], new UnexpectedKey(ast, input[i]));
|
|
10008
|
+
if (options.errors === "all") if (state.issues) state.issues.push(issue);
|
|
10009
|
+
else state.issues = [issue];
|
|
10010
|
+
else return yield* fail(new Composite(ast, oinput, [issue]));
|
|
10011
|
+
}
|
|
10012
|
+
if (state.issues) return yield* fail(new Composite(ast, oinput, state.issues));
|
|
10013
|
+
return some(state.output);
|
|
10014
|
+
});
|
|
10015
|
+
}
|
|
10016
|
+
_rebuild(recur, checks, encodingChecks) {
|
|
10017
|
+
const elements = mapOrSame(this.elements, recur);
|
|
10018
|
+
const rest = mapOrSame(this.rest, recur);
|
|
10019
|
+
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);
|
|
10020
|
+
}
|
|
10021
|
+
/** @internal */
|
|
10022
|
+
recur(recur) {
|
|
10023
|
+
return this._rebuild(recur, this.checks, this.encodingChecks);
|
|
10024
|
+
}
|
|
10025
|
+
/** @internal */
|
|
10026
|
+
flip(recur) {
|
|
10027
|
+
return this._rebuild(recur, this.encodingChecks, this.checks);
|
|
10028
|
+
}
|
|
10029
|
+
/** @internal */
|
|
10030
|
+
getExpected() {
|
|
10031
|
+
return "array";
|
|
10032
|
+
}
|
|
10033
|
+
};
|
|
10034
|
+
const parseArray = /*#__PURE__*/ iterateEager()({
|
|
10035
|
+
onItem(s, item, i) {
|
|
10036
|
+
const value = i < s.len ? some(item) : none();
|
|
10037
|
+
return s.getParser(s.tailThreshold, i).parser(value, s.options);
|
|
10038
|
+
},
|
|
10039
|
+
step(s, _, exit, i) {
|
|
10040
|
+
if (exit._tag === "Failure") return wrapPropertyKeyIssue(s, s.ast, i, exit);
|
|
10041
|
+
else if (exit.value._tag === "Some") s.output[i] = exit.value.value;
|
|
10042
|
+
else {
|
|
10043
|
+
const p = s.getParser(s.tailThreshold, i);
|
|
10044
|
+
if (isOptional(p.ast)) return;
|
|
10045
|
+
const issue = new Pointer([i], new MissingKey(p.ast.context?.annotations));
|
|
10046
|
+
if (s.options.errors === "all") if (s.issues) s.issues.push(issue);
|
|
10047
|
+
else s.issues = [issue];
|
|
10048
|
+
else return fail$1(new Composite(s.ast, s.oinput, [issue]));
|
|
10049
|
+
}
|
|
10050
|
+
}
|
|
10051
|
+
});
|
|
10052
|
+
function resolveTailThreshold(inputLen, elementLen, tailLen) {
|
|
10053
|
+
return Math.max(elementLen, inputLen - tailLen);
|
|
10054
|
+
}
|
|
10055
|
+
const resolveConcurrency = (value) => {
|
|
10056
|
+
value = value === "unbounded" ? Infinity : value ?? 1;
|
|
10057
|
+
return value > 1 ? { concurrency: value } : void 0;
|
|
10058
|
+
};
|
|
10059
|
+
const wrapPropertyKeyIssue = (s, ast, key, exit) => {
|
|
10060
|
+
if (exit.cause.reasons.length === 0) return exit;
|
|
10061
|
+
const issue = getSchemaIssue(exit.cause);
|
|
10062
|
+
if (issue === void 0) return failCause(map$1(exit.cause, (issue) => new Composite(ast, s.oinput, [new Pointer([key], issue)])));
|
|
10063
|
+
const pointer = new Pointer([key], issue);
|
|
10064
|
+
if (s.options.errors === "all") if (s.issues) s.issues.push(pointer);
|
|
10065
|
+
else s.issues = [pointer];
|
|
10066
|
+
else return fail$1(new Composite(ast, s.oinput, [pointer]));
|
|
10067
|
+
};
|
|
10068
|
+
/**
|
|
10069
|
+
* floating point or integer, with optional exponent
|
|
9424
10070
|
* @internal
|
|
9425
10071
|
*/
|
|
9426
10072
|
const FINITE_PATTERN = "[+-]?\\d*\\.?\\d+(?:[Ee][+-]?\\d+)?";
|
|
10073
|
+
/**
|
|
10074
|
+
* Returns the object keys that match the index signature parameter schema.
|
|
10075
|
+
* @internal
|
|
10076
|
+
*/
|
|
10077
|
+
function getIndexSignatureKeys(input, parameter, options = defaultParseOptions) {
|
|
10078
|
+
let stringKeys;
|
|
10079
|
+
let symbolKeys;
|
|
10080
|
+
function go(parameter) {
|
|
10081
|
+
switch (parameter._tag) {
|
|
10082
|
+
case "String":
|
|
10083
|
+
case "TemplateLiteral": return (stringKeys ??= Object.keys(input)).filter((k) => parameter.matchPart(k, options) !== void 0);
|
|
10084
|
+
case "Number": return (stringKeys ??= Object.keys(input)).filter((k) => parameter.matchKey(k, options) !== void 0);
|
|
10085
|
+
case "Symbol": return (symbolKeys ??= Object.getOwnPropertySymbols(input)).filter((k) => parameter.matchKey(k, options) !== void 0);
|
|
10086
|
+
case "Union": return [...new Set(parameter.types.flatMap(go))];
|
|
10087
|
+
default: return [];
|
|
10088
|
+
}
|
|
10089
|
+
}
|
|
10090
|
+
return go(parameterFromPropertyKey(toEncoded(parameter)));
|
|
10091
|
+
}
|
|
10092
|
+
/**
|
|
10093
|
+
* Represents a named property within an {@link Objects} node.
|
|
10094
|
+
*
|
|
10095
|
+
* **Details**
|
|
10096
|
+
*
|
|
10097
|
+
* Pairs a `name` (any `PropertyKey`) with a `type` ({@link AST}). The
|
|
10098
|
+
* property's optionality and mutability are determined by the `type`'s
|
|
10099
|
+
* {@link Context}.
|
|
10100
|
+
*
|
|
10101
|
+
* @see {@link Objects}
|
|
10102
|
+
* @category models
|
|
10103
|
+
* @since 3.10.0
|
|
10104
|
+
*/
|
|
10105
|
+
var PropertySignature = class {
|
|
10106
|
+
name;
|
|
10107
|
+
type;
|
|
10108
|
+
constructor(name, type) {
|
|
10109
|
+
this.name = name;
|
|
10110
|
+
this.type = type;
|
|
10111
|
+
}
|
|
10112
|
+
};
|
|
10113
|
+
function isIndexSignatureParameterSide(ast) {
|
|
10114
|
+
switch (ast._tag) {
|
|
10115
|
+
case "String":
|
|
10116
|
+
case "Number":
|
|
10117
|
+
case "Symbol":
|
|
10118
|
+
case "TemplateLiteral": return true;
|
|
10119
|
+
case "Union": return ast.types.every(isIndexSignatureParameterSide);
|
|
10120
|
+
default: return false;
|
|
10121
|
+
}
|
|
10122
|
+
}
|
|
10123
|
+
function isIndexSignatureParameter(ast) {
|
|
10124
|
+
return isIndexSignatureParameterSide(ast) && isIndexSignatureParameterSide(toEncoded(ast));
|
|
10125
|
+
}
|
|
10126
|
+
/**
|
|
10127
|
+
* Represents an index signature entry within an {@link Objects} node.
|
|
10128
|
+
*
|
|
10129
|
+
* **When to use**
|
|
10130
|
+
*
|
|
10131
|
+
* Use when constructing or inspecting object AST entries for record-like keys
|
|
10132
|
+
* and values.
|
|
10133
|
+
*
|
|
10134
|
+
* **Details**
|
|
10135
|
+
*
|
|
10136
|
+
* - `parameter` — the key type AST (e.g. {@link String} for `string` keys,
|
|
10137
|
+
* {@link TemplateLiteral} for patterned keys).
|
|
10138
|
+
* - `type` — the value type SchemaAST.
|
|
10139
|
+
* - `merge` — optional {@link KeyValueCombiner} for handling duplicate keys.
|
|
10140
|
+
*
|
|
10141
|
+
* **Gotchas**
|
|
10142
|
+
*
|
|
10143
|
+
* Using `Schema.optionalKey` on the value type is not allowed for index
|
|
10144
|
+
* signatures (throws at construction); use `Schema.optional` instead.
|
|
10145
|
+
*
|
|
10146
|
+
* @see {@link Objects}
|
|
10147
|
+
* @see {@link PropertySignature}
|
|
10148
|
+
* @category models
|
|
10149
|
+
* @since 3.10.0
|
|
10150
|
+
*/
|
|
10151
|
+
var IndexSignature = class {
|
|
10152
|
+
parameter;
|
|
10153
|
+
type;
|
|
10154
|
+
merge;
|
|
10155
|
+
constructor(parameter, type, merge) {
|
|
10156
|
+
if (!isIndexSignatureParameter(parameter)) throw new Error(`Invalid index signature parameter ${parameter._tag}`);
|
|
10157
|
+
this.parameter = parameter;
|
|
10158
|
+
this.type = type;
|
|
10159
|
+
this.merge = merge;
|
|
10160
|
+
if (isOptional(type) && !containsUndefined(type)) throw new Error("Cannot use `Schema.optionalKey` with index signatures, use `Schema.optional` instead.");
|
|
10161
|
+
}
|
|
10162
|
+
};
|
|
10163
|
+
/**
|
|
10164
|
+
* AST node for object-like schemas, including structs and records.
|
|
10165
|
+
*
|
|
10166
|
+
* **When to use**
|
|
10167
|
+
*
|
|
10168
|
+
* Use when constructing or inspecting AST nodes for structs or records rather
|
|
10169
|
+
* than array-like schemas.
|
|
10170
|
+
*
|
|
10171
|
+
* **Details**
|
|
10172
|
+
*
|
|
10173
|
+
* - `propertySignatures` — named properties with their types (struct fields).
|
|
10174
|
+
* - `indexSignatures` — index signature entries (record patterns), each with
|
|
10175
|
+
* a `parameter` AST for matching keys and a `type` AST for values.
|
|
10176
|
+
*
|
|
10177
|
+
* An `Objects` node with no properties and no index signatures performs only a
|
|
10178
|
+
* non-nullish check: it accepts any value except `null` and `undefined`,
|
|
10179
|
+
* including primitive values.
|
|
10180
|
+
*
|
|
10181
|
+
* **Gotchas**
|
|
10182
|
+
*
|
|
10183
|
+
* Duplicate property names throw at construction time.
|
|
10184
|
+
*
|
|
10185
|
+
* **Example** (Inspecting a struct AST)
|
|
10186
|
+
*
|
|
10187
|
+
* ```ts
|
|
10188
|
+
* import { Schema, SchemaAST } from "effect"
|
|
10189
|
+
*
|
|
10190
|
+
* const schema = Schema.Struct({ name: Schema.String })
|
|
10191
|
+
* const ast = schema.ast
|
|
10192
|
+
*
|
|
10193
|
+
* if (SchemaAST.isObjects(ast)) {
|
|
10194
|
+
* for (const ps of ast.propertySignatures) {
|
|
10195
|
+
* console.log(ps.name, ps.type._tag)
|
|
10196
|
+
* }
|
|
10197
|
+
* // "name" "String"
|
|
10198
|
+
* }
|
|
10199
|
+
* ```
|
|
10200
|
+
*
|
|
10201
|
+
* @see {@link isObjects}
|
|
10202
|
+
* @see {@link PropertySignature}
|
|
10203
|
+
* @see {@link IndexSignature}
|
|
10204
|
+
* @see {@link Arrays}
|
|
10205
|
+
* @category models
|
|
10206
|
+
* @since 4.0.0
|
|
10207
|
+
*/
|
|
10208
|
+
var Objects = class Objects extends Base {
|
|
10209
|
+
_tag = "Objects";
|
|
10210
|
+
propertySignatures;
|
|
10211
|
+
indexSignatures;
|
|
10212
|
+
encodingChecks;
|
|
10213
|
+
constructor(propertySignatures, indexSignatures, annotations, checks, encoding, context, encodingChecks) {
|
|
10214
|
+
super(annotations, checks, encoding, context);
|
|
10215
|
+
this.propertySignatures = propertySignatures;
|
|
10216
|
+
this.indexSignatures = indexSignatures;
|
|
10217
|
+
this.encodingChecks = encodingChecks;
|
|
10218
|
+
const duplicates = propertySignatures.map((ps) => ps.name).filter((name, i, arr) => arr.indexOf(name) !== i);
|
|
10219
|
+
if (duplicates.length > 0) throw new Error(`Duplicate identifiers: ${JSON.stringify(duplicates)}. ts(2300)`);
|
|
10220
|
+
}
|
|
10221
|
+
/** @internal */
|
|
10222
|
+
getParser(recur) {
|
|
10223
|
+
const ast = this;
|
|
10224
|
+
const expectedKeys = [];
|
|
10225
|
+
const expectedKeysSet = /* @__PURE__ */ new Set();
|
|
10226
|
+
const properties = [];
|
|
10227
|
+
for (const ps of ast.propertySignatures) {
|
|
10228
|
+
expectedKeys.push(ps.name);
|
|
10229
|
+
expectedKeysSet.add(ps.name);
|
|
10230
|
+
properties.push({
|
|
10231
|
+
ps,
|
|
10232
|
+
parser: recur(ps.type),
|
|
10233
|
+
name: ps.name,
|
|
10234
|
+
type: ps.type
|
|
10235
|
+
});
|
|
10236
|
+
}
|
|
10237
|
+
const indexCount = ast.indexSignatures.length;
|
|
10238
|
+
if (ast.propertySignatures.length === 0 && ast.indexSignatures.length === 0) return fromRefinement(ast, isNotNullish);
|
|
10239
|
+
const parseIndexes = indexCount > 0 ? iterateEager()({
|
|
10240
|
+
onItem: fnUntracedEager(function* (s, [key, is]) {
|
|
10241
|
+
const effKey = recur(parameterFromPropertyKey(is.parameter))(some(key), s.options);
|
|
10242
|
+
const exitKey = effectIsExit(effKey) ? effKey : yield* exit$1(effKey);
|
|
10243
|
+
if (exitKey._tag === "Failure") {
|
|
10244
|
+
const eff = wrapPropertyKeyIssue(s, ast, key, exitKey);
|
|
10245
|
+
if (eff) yield* eff;
|
|
10246
|
+
return;
|
|
10247
|
+
}
|
|
10248
|
+
const value = some(s.input[key]);
|
|
10249
|
+
const effValue = recur(is.type)(value, s.options);
|
|
10250
|
+
const exitValue = effectIsExit(effValue) ? effValue : yield* exit$1(effValue);
|
|
10251
|
+
if (exitValue._tag === "Failure") {
|
|
10252
|
+
const eff = wrapPropertyKeyIssue(s, ast, key, exitValue);
|
|
10253
|
+
if (eff) yield* eff;
|
|
10254
|
+
return;
|
|
10255
|
+
} else if (exitKey.value._tag === "Some" && exitValue.value._tag === "Some") {
|
|
10256
|
+
const k2 = exitKey.value.value;
|
|
10257
|
+
if (expectedKeysSet.has(key) || expectedKeysSet.has(k2)) return;
|
|
10258
|
+
const v2 = exitValue.value.value;
|
|
10259
|
+
if (is.merge && is.merge.decode && Object.hasOwn(s.out, k2)) {
|
|
10260
|
+
const [k, v] = is.merge.decode.combine([k2, s.out[k2]], [k2, v2]);
|
|
10261
|
+
assignProperty(s.out, k, v);
|
|
10262
|
+
} else assignProperty(s.out, k2, v2);
|
|
10263
|
+
}
|
|
10264
|
+
}),
|
|
10265
|
+
step: (_s, _, exit) => exit._tag === "Failure" ? exit : void 0
|
|
10266
|
+
}) : void 0;
|
|
10267
|
+
return fnUntracedEager(function* (oinput, options) {
|
|
10268
|
+
if (oinput._tag === "None") return oinput;
|
|
10269
|
+
const input = oinput.value;
|
|
10270
|
+
if (!(typeof input === "object" && input !== null && !Array.isArray(input))) return yield* fail(new InvalidType(ast, oinput));
|
|
10271
|
+
const out = {};
|
|
10272
|
+
const state = {
|
|
10273
|
+
ast,
|
|
10274
|
+
oinput,
|
|
10275
|
+
input,
|
|
10276
|
+
out,
|
|
10277
|
+
issues: void 0,
|
|
10278
|
+
options
|
|
10279
|
+
};
|
|
10280
|
+
const errorsAllOption = options.errors === "all";
|
|
10281
|
+
const onExcessPropertyError = options.onExcessProperty === "error";
|
|
10282
|
+
const onExcessPropertyPreserve = options.onExcessProperty === "preserve";
|
|
10283
|
+
let inputKeys;
|
|
10284
|
+
if (ast.indexSignatures.length === 0 && (onExcessPropertyError || onExcessPropertyPreserve)) {
|
|
10285
|
+
inputKeys = Reflect.ownKeys(input);
|
|
10286
|
+
for (let i = 0; i < inputKeys.length; i++) {
|
|
10287
|
+
const key = inputKeys[i];
|
|
10288
|
+
if (!expectedKeysSet.has(key)) if (onExcessPropertyError) {
|
|
10289
|
+
const issue = new Pointer([key], new UnexpectedKey(ast, input[key]));
|
|
10290
|
+
if (errorsAllOption) {
|
|
10291
|
+
if (state.issues) state.issues.push(issue);
|
|
10292
|
+
else state.issues = [issue];
|
|
10293
|
+
continue;
|
|
10294
|
+
} else return yield* fail(new Composite(ast, oinput, [issue]));
|
|
10295
|
+
} else assignProperty(out, key, input[key]);
|
|
10296
|
+
}
|
|
10297
|
+
}
|
|
10298
|
+
const concurrency = resolveConcurrency(options?.concurrency);
|
|
10299
|
+
const eff = parseProperties(state, properties, concurrency);
|
|
10300
|
+
if (eff) yield* eff;
|
|
10301
|
+
if (parseIndexes) {
|
|
10302
|
+
const keyPairs = empty$1();
|
|
10303
|
+
for (let i = 0; i < indexCount; i++) {
|
|
10304
|
+
const is = ast.indexSignatures[i];
|
|
10305
|
+
const keys = getIndexSignatureKeys(input, is.parameter, options);
|
|
10306
|
+
for (let j = 0; j < keys.length; j++) {
|
|
10307
|
+
const key = keys[j];
|
|
10308
|
+
keyPairs.push([key, is]);
|
|
10309
|
+
}
|
|
10310
|
+
}
|
|
10311
|
+
const eff = parseIndexes(state, keyPairs, concurrency);
|
|
10312
|
+
if (eff) yield* eff;
|
|
10313
|
+
}
|
|
10314
|
+
if (state.issues) return yield* fail(new Composite(ast, oinput, state.issues));
|
|
10315
|
+
if (options.propertyOrder === "original") {
|
|
10316
|
+
const keys = (inputKeys ?? Reflect.ownKeys(input)).concat(expectedKeys);
|
|
10317
|
+
const preserved = {};
|
|
10318
|
+
for (const key of keys) if (Object.hasOwn(out, key)) assignProperty(preserved, key, out[key]);
|
|
10319
|
+
return some(preserved);
|
|
10320
|
+
}
|
|
10321
|
+
return some(out);
|
|
10322
|
+
});
|
|
10323
|
+
}
|
|
10324
|
+
_rebuild(recur, recurParameter, flipMerge, checks, encodingChecks) {
|
|
10325
|
+
const props = mapOrSame(this.propertySignatures, (ps) => {
|
|
10326
|
+
const t = recur(ps.type);
|
|
10327
|
+
return t === ps.type ? ps : new PropertySignature(ps.name, t);
|
|
10328
|
+
});
|
|
10329
|
+
const indexes = mapOrSame(this.indexSignatures, (is) => {
|
|
10330
|
+
const p = recurParameter(is.parameter);
|
|
10331
|
+
const t = recur(is.type);
|
|
10332
|
+
const merge = flipMerge ? is.merge?.flip() : is.merge;
|
|
10333
|
+
return p === is.parameter && t === is.type && merge === is.merge ? is : new IndexSignature(p, t, merge);
|
|
10334
|
+
});
|
|
10335
|
+
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);
|
|
10336
|
+
}
|
|
10337
|
+
/** @internal */
|
|
10338
|
+
flip(recur) {
|
|
10339
|
+
return this._rebuild(recur, recur, true, this.encodingChecks, this.checks);
|
|
10340
|
+
}
|
|
10341
|
+
/** @internal */
|
|
10342
|
+
recur(recur, recurParameter = recur) {
|
|
10343
|
+
return this._rebuild(recur, recurParameter, false, this.checks, this.encodingChecks);
|
|
10344
|
+
}
|
|
10345
|
+
/** @internal */
|
|
10346
|
+
getExpected() {
|
|
10347
|
+
if (this.propertySignatures.length === 0 && this.indexSignatures.length === 0) return "object | array";
|
|
10348
|
+
return "object";
|
|
10349
|
+
}
|
|
10350
|
+
};
|
|
10351
|
+
const parseProperties = /*#__PURE__*/ iterateEager()({
|
|
10352
|
+
onItem(s, p) {
|
|
10353
|
+
const value = Object.hasOwn(s.input, p.name) ? some(s.input[p.name]) : none();
|
|
10354
|
+
return p.parser(value, s.options);
|
|
10355
|
+
},
|
|
10356
|
+
step(s, p, exit) {
|
|
10357
|
+
if (exit._tag === "Failure") return wrapPropertyKeyIssue(s, s.ast, p.name, exit);
|
|
10358
|
+
else if (exit.value._tag === "Some") assignProperty(s.out, p.name, exit.value.value);
|
|
10359
|
+
else if (!isOptional(p.type)) {
|
|
10360
|
+
const issue = new Pointer([p.name], new MissingKey(p.type.context?.annotations));
|
|
10361
|
+
if (s.options.errors === "all") {
|
|
10362
|
+
if (s.issues) s.issues.push(issue);
|
|
10363
|
+
else s.issues = [issue];
|
|
10364
|
+
return;
|
|
10365
|
+
} else return fail$1(new Composite(s.ast, s.oinput, [issue]));
|
|
10366
|
+
}
|
|
10367
|
+
}
|
|
10368
|
+
});
|
|
9427
10369
|
function combineChecks(a, b) {
|
|
9428
10370
|
if (!a) return b;
|
|
9429
10371
|
if (!b) return a;
|
|
9430
10372
|
return [...a, ...b];
|
|
9431
10373
|
}
|
|
10374
|
+
/** @internal */
|
|
10375
|
+
function struct(fields, checks, annotations) {
|
|
10376
|
+
return new Objects(Reflect.ownKeys(fields).map((key) => {
|
|
10377
|
+
return new PropertySignature(key, fields[key].ast);
|
|
10378
|
+
}), [], annotations, checks);
|
|
10379
|
+
}
|
|
9432
10380
|
function getCandidateTypes(ast) {
|
|
9433
10381
|
switch (ast._tag) {
|
|
9434
10382
|
case "Null": return ["null"];
|
|
@@ -10072,6 +11020,14 @@ const flip = /*#__PURE__*/ memoize((ast) => {
|
|
|
10072
11020
|
const out = ast;
|
|
10073
11021
|
return out.flip?.(flip) ?? out.recur?.(flip) ?? out;
|
|
10074
11022
|
});
|
|
11023
|
+
/** @internal */
|
|
11024
|
+
function containsUndefined(ast) {
|
|
11025
|
+
switch (ast._tag) {
|
|
11026
|
+
case "Undefined": return true;
|
|
11027
|
+
case "Union": return ast.types.some(containsUndefined);
|
|
11028
|
+
default: return false;
|
|
11029
|
+
}
|
|
11030
|
+
}
|
|
10075
11031
|
function fromConst(ast, value) {
|
|
10076
11032
|
const succeed = succeedSome(value);
|
|
10077
11033
|
return (oinput) => {
|
|
@@ -10298,6 +11254,35 @@ function make$2(schema) {
|
|
|
10298
11254
|
throw new Error(issue.toString(), { cause: issue });
|
|
10299
11255
|
};
|
|
10300
11256
|
}
|
|
11257
|
+
/**
|
|
11258
|
+
* Creates an effectful decoder for `unknown` input.
|
|
11259
|
+
*
|
|
11260
|
+
* **When to use**
|
|
11261
|
+
*
|
|
11262
|
+
* Use when you need to decode untyped boundary input in an `Effect` whose
|
|
11263
|
+
* failure channel is `SchemaIssue.Issue`, while preserving transformations
|
|
11264
|
+
* and service requirements.
|
|
11265
|
+
*
|
|
11266
|
+
* **Details**
|
|
11267
|
+
*
|
|
11268
|
+
* The returned function succeeds with the schema's decoded `Type` or fails with a
|
|
11269
|
+
* `SchemaIssue.Issue`. Decoding service requirements are preserved in the returned
|
|
11270
|
+
* `Effect`. Parse options may be provided when creating the decoder and overridden
|
|
11271
|
+
* when applying it.
|
|
11272
|
+
*
|
|
11273
|
+
* @see {@link decodeEffect} for input already typed as the schema's `Encoded` type
|
|
11274
|
+
*
|
|
11275
|
+
* @category decoding
|
|
11276
|
+
* @since 4.0.0
|
|
11277
|
+
*/
|
|
11278
|
+
function decodeUnknownEffect$1(schema, options) {
|
|
11279
|
+
const parser = run$1(schema.ast);
|
|
11280
|
+
return options === void 0 ? parser : (input, overrideOptions) => parser(input, mergeParseOptions(options, overrideOptions));
|
|
11281
|
+
}
|
|
11282
|
+
const mergeParseOptions = (options, overrideOptions) => overrideOptions === void 0 ? options : {
|
|
11283
|
+
...options,
|
|
11284
|
+
...overrideOptions
|
|
11285
|
+
};
|
|
10301
11286
|
/** @internal */
|
|
10302
11287
|
function run$1(ast) {
|
|
10303
11288
|
const parser = recur(ast);
|
|
@@ -10404,31 +11389,160 @@ function make$1(ast, options) {
|
|
|
10404
11389
|
function fromIssueEffect(self) {
|
|
10405
11390
|
return catchCause(self, (cause) => failCauseSync(() => map$1(cause, (issue) => new SchemaError(issue))));
|
|
10406
11391
|
}
|
|
11392
|
+
//#endregion
|
|
11393
|
+
//#region node_modules/.pnpm/effect@4.0.0-beta.102/node_modules/effect/dist/Struct.js
|
|
11394
|
+
/**
|
|
11395
|
+
* Wraps a plain function as a {@link Lambda} value so it can be used with
|
|
11396
|
+
* {@link map}, {@link mapPick}, and {@link mapOmit}.
|
|
11397
|
+
*
|
|
11398
|
+
* **When to use**
|
|
11399
|
+
*
|
|
11400
|
+
* Use to create a typed lambda for struct mapping APIs that need type-level
|
|
11401
|
+
* input and output tracking.
|
|
11402
|
+
*
|
|
11403
|
+
* **Details**
|
|
11404
|
+
*
|
|
11405
|
+
* The type parameter `L` encodes both the input and output types at the type
|
|
11406
|
+
* level, allowing the compiler to track how struct value types change. At
|
|
11407
|
+
* runtime, the returned value is the same function; `lambda` only adjusts the
|
|
11408
|
+
* type.
|
|
11409
|
+
*
|
|
11410
|
+
* **Example** (Wrapping values in arrays)
|
|
11411
|
+
*
|
|
11412
|
+
* ```ts
|
|
11413
|
+
* import { pipe, Struct } from "effect"
|
|
11414
|
+
*
|
|
11415
|
+
* interface AsArray extends Struct.Lambda {
|
|
11416
|
+
* <A>(self: A): Array<A>
|
|
11417
|
+
* readonly "~lambda.out": Array<this["~lambda.in"]>
|
|
11418
|
+
* }
|
|
11419
|
+
*
|
|
11420
|
+
* const asArray = Struct.lambda<AsArray>((a) => [a])
|
|
11421
|
+
* const result = pipe({ x: 1, y: "hello" }, Struct.map(asArray))
|
|
11422
|
+
* console.log(result) // { x: [1], y: ["hello"] }
|
|
11423
|
+
* ```
|
|
11424
|
+
*
|
|
11425
|
+
* @see {@link Lambda} – the type-level interface
|
|
11426
|
+
* @see {@link map} – apply a lambda to all struct values
|
|
11427
|
+
* @category Lambda
|
|
11428
|
+
* @since 4.0.0
|
|
11429
|
+
*/
|
|
11430
|
+
const lambda = (f) => f;
|
|
11431
|
+
/**
|
|
11432
|
+
* Decodes an `unknown` input against a schema, returning an `Effect` that
|
|
11433
|
+
* succeeds with the decoded value or fails with a {@link SchemaError}.
|
|
11434
|
+
*
|
|
11435
|
+
* **When to use**
|
|
11436
|
+
*
|
|
11437
|
+
* Use when you need to decode unknown input in an `Effect` whose failure
|
|
11438
|
+
* channel is `SchemaError`.
|
|
11439
|
+
*
|
|
11440
|
+
* **Details**
|
|
11441
|
+
*
|
|
11442
|
+
* Prefer {@link decodeEffect} when the input is already typed as the schema's
|
|
11443
|
+
* `Encoded` type.
|
|
11444
|
+
* Options may be provided either when creating the decoder or when applying it;
|
|
11445
|
+
* application options override creation options.
|
|
11446
|
+
*
|
|
11447
|
+
* @see {@link SchemaParser.decodeUnknownEffect} for the adapter that fails with `SchemaIssue.Issue` directly
|
|
11448
|
+
*
|
|
11449
|
+
* @category decoding
|
|
11450
|
+
* @since 4.0.0
|
|
11451
|
+
*/
|
|
11452
|
+
function decodeUnknownEffect(schema, options) {
|
|
11453
|
+
const parser = decodeUnknownEffect$1(schema, options);
|
|
11454
|
+
return (input, options) => {
|
|
11455
|
+
return fromIssueEffect(parser(input, options));
|
|
11456
|
+
};
|
|
11457
|
+
}
|
|
11458
|
+
/**
|
|
11459
|
+
* Creates a schema from an AST (Abstract Syntax Tree) node.
|
|
11460
|
+
*
|
|
11461
|
+
* **Details**
|
|
11462
|
+
*
|
|
11463
|
+
* This is the fundamental constructor for all schemas in the Effect Schema
|
|
11464
|
+
* library. It takes an AST node and wraps it in a fully-typed schema that
|
|
11465
|
+
* preserves all type information and provides the complete schema API.
|
|
11466
|
+
*
|
|
11467
|
+
* The `make` function is used internally to create all primitive schemas like
|
|
11468
|
+
* `String`, `Number`, `Boolean`, etc., as well as more complex schemas. It's
|
|
11469
|
+
* the bridge between the untyped AST representation and the strongly-typed
|
|
11470
|
+
* schema.
|
|
11471
|
+
*
|
|
11472
|
+
* @category constructors
|
|
11473
|
+
* @since 3.10.0
|
|
11474
|
+
*/
|
|
11475
|
+
const make = make$1;
|
|
11476
|
+
/**
|
|
11477
|
+
* Schema for `string` values. Validates that the input is `typeof` `"string"`.
|
|
11478
|
+
*
|
|
11479
|
+
* @category schemas
|
|
11480
|
+
* @since 4.0.0
|
|
11481
|
+
*/
|
|
11482
|
+
const String$1 = /*#__PURE__*/ make(string);
|
|
11483
|
+
/**
|
|
11484
|
+
* Schema for `boolean` values. Validates that the input is `typeof` `"boolean"`.
|
|
11485
|
+
*
|
|
11486
|
+
* **When to use**
|
|
11487
|
+
*
|
|
11488
|
+
* Use to validate values that are already JavaScript booleans.
|
|
11489
|
+
*
|
|
11490
|
+
* @see {@link BooleanFromBit} for a schema that decodes bit literals `0` or `1` into a boolean
|
|
11491
|
+
*
|
|
11492
|
+
* @category boolean
|
|
11493
|
+
* @since 4.0.0
|
|
11494
|
+
*/
|
|
11495
|
+
const Boolean = /*#__PURE__*/ make(boolean);
|
|
11496
|
+
function makeStruct(ast, fields) {
|
|
11497
|
+
return make(ast, {
|
|
11498
|
+
fields,
|
|
11499
|
+
mapFields(f, options) {
|
|
11500
|
+
const fields = f(this.fields);
|
|
11501
|
+
return makeStruct(struct(fields, options?.unsafePreserveChecks ? this.ast.checks : void 0), fields);
|
|
11502
|
+
}
|
|
11503
|
+
});
|
|
11504
|
+
}
|
|
10407
11505
|
/**
|
|
10408
|
-
*
|
|
11506
|
+
* Defines a struct schema from a map of field schemas.
|
|
10409
11507
|
*
|
|
10410
11508
|
* **Details**
|
|
10411
11509
|
*
|
|
10412
|
-
*
|
|
10413
|
-
*
|
|
10414
|
-
* preserves all type information and provides the complete schema API.
|
|
11510
|
+
* Each field value is a schema. Use {@link optionalKey} or {@link optional} to
|
|
11511
|
+
* mark fields as optional, and {@link mutableKey} to mark them as mutable.
|
|
10415
11512
|
*
|
|
10416
|
-
* The `
|
|
10417
|
-
*
|
|
10418
|
-
*
|
|
10419
|
-
*
|
|
11513
|
+
* The resulting schema's `Type` is a readonly object type with the fields'
|
|
11514
|
+
* decoded types. The `Encoded` form mirrors the field schemas' encoded types.
|
|
11515
|
+
*
|
|
11516
|
+
* **Example** (Defining a basic struct)
|
|
11517
|
+
*
|
|
11518
|
+
* ```ts
|
|
11519
|
+
* import { Schema } from "effect"
|
|
11520
|
+
*
|
|
11521
|
+
* const Person = Schema.Struct({
|
|
11522
|
+
* name: Schema.String,
|
|
11523
|
+
* age: Schema.Number,
|
|
11524
|
+
* email: Schema.optionalKey(Schema.String)
|
|
11525
|
+
* })
|
|
11526
|
+
*
|
|
11527
|
+
* // { readonly name: string; readonly age: number; readonly email?: string }
|
|
11528
|
+
* type Person = typeof Person.Type
|
|
11529
|
+
*
|
|
11530
|
+
* const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
|
|
11531
|
+
* console.log(alice)
|
|
11532
|
+
* // { name: 'Alice', age: 30 }
|
|
11533
|
+
* ```
|
|
10420
11534
|
*
|
|
10421
11535
|
* @category constructors
|
|
10422
11536
|
* @since 3.10.0
|
|
10423
11537
|
*/
|
|
10424
|
-
|
|
11538
|
+
function Struct(fields) {
|
|
11539
|
+
return makeStruct(struct(fields, void 0), fields);
|
|
11540
|
+
}
|
|
10425
11541
|
/**
|
|
10426
|
-
*
|
|
10427
|
-
*
|
|
10428
|
-
* @category schemas
|
|
11542
|
+
* @category constructors
|
|
10429
11543
|
* @since 4.0.0
|
|
10430
11544
|
*/
|
|
10431
|
-
const
|
|
11545
|
+
const ArraySchema = /*#__PURE__*/ lambda((schema) => make(new Arrays(false, [], [schema.ast]), { value: schema }));
|
|
10432
11546
|
/**
|
|
10433
11547
|
* Adds a nominal brand to a schema, intersecting the output type with
|
|
10434
11548
|
* `Brand.Brand<B>` to prevent accidental mixing of structurally identical types.
|
|
@@ -10524,6 +11638,7 @@ const openHunk = (draft, line) => {
|
|
|
10524
11638
|
marker: line,
|
|
10525
11639
|
scope: (header?.[3] ?? "").trim(),
|
|
10526
11640
|
startRow: draft.rows.length,
|
|
11641
|
+
newStart: draft.newLine,
|
|
10527
11642
|
rows: [],
|
|
10528
11643
|
skipped: draft.hunks.length === 0 ? 0 : Math.max(0, draft.newLine - previousNew)
|
|
10529
11644
|
});
|
|
@@ -10792,7 +11907,8 @@ var StoreUnreadable = class extends TaggedError("StoreUnreadable") {};
|
|
|
10792
11907
|
const emptyBranchState = {
|
|
10793
11908
|
vouches: {},
|
|
10794
11909
|
consumed: 0,
|
|
10795
|
-
pending: []
|
|
11910
|
+
pending: [],
|
|
11911
|
+
settled: {}
|
|
10796
11912
|
};
|
|
10797
11913
|
//#endregion
|
|
10798
11914
|
//#region src/service/store/paths.ts
|
|
@@ -10801,8 +11917,10 @@ const slugOf = (worktreePath) => worktreePath.replace(NON_SLUG, "-");
|
|
|
10801
11917
|
const defaultRoot = () => join(homedir(), ".adiff");
|
|
10802
11918
|
const branchDir = (root, worktreePath) => join(root, "branches", slugOf(worktreePath));
|
|
10803
11919
|
const inboxPath = (root, worktreePath) => join(branchDir(root, worktreePath), "inbox.jsonl");
|
|
11920
|
+
const outboxPath = (root, worktreePath) => join(branchDir(root, worktreePath), "outbox.jsonl");
|
|
10804
11921
|
const statePath = (root, worktreePath) => join(branchDir(root, worktreePath), "state.json");
|
|
10805
|
-
const
|
|
11922
|
+
const layersPath = (root, worktreePath) => join(branchDir(root, worktreePath), "layers.json");
|
|
11923
|
+
const settingsPath = (root) => join(root, "settings.json");
|
|
10806
11924
|
const reportsDir = (root) => join(root, "reports");
|
|
10807
11925
|
const reportPath = (root, stamp) => join(reportsDir(root), `${stamp}.md`);
|
|
10808
11926
|
//#endregion
|
|
@@ -10827,7 +11945,12 @@ const readOptional = fn("Store.readOptional")(function* (path) {
|
|
|
10827
11945
|
}).pipe(map(some), catchTag("StoreUnreadable", () => missing));
|
|
10828
11946
|
});
|
|
10829
11947
|
const missing = succeed(none());
|
|
11948
|
+
const parseSettings = (raw) => {
|
|
11949
|
+
const parsed = JSON.parse(raw);
|
|
11950
|
+
return typeof parsed.wrap === "boolean" ? { wrap: parsed.wrap } : {};
|
|
11951
|
+
};
|
|
10830
11952
|
const parseBatches = (raw) => raw.split("\n").filter((line) => line.trim().length > 0).map((line) => JSON.parse(line));
|
|
11953
|
+
const parseAnswers = (raw) => raw.split("\n").filter((line) => line.trim().length > 0).map((line) => JSON.parse(line));
|
|
10831
11954
|
const parseState = (raw) => ({
|
|
10832
11955
|
...emptyBranchState,
|
|
10833
11956
|
...JSON.parse(raw)
|
|
@@ -10843,6 +11966,26 @@ const cursorOps = (state, saveState, inbox) => {
|
|
|
10843
11966
|
});
|
|
10844
11967
|
return pending;
|
|
10845
11968
|
}),
|
|
11969
|
+
restage: fn("Store.restage")(function* (worktreePath, comment) {
|
|
11970
|
+
const current = yield* state(worktreePath);
|
|
11971
|
+
if (!current.pending.some((entry) => entry.id === comment.id)) return none();
|
|
11972
|
+
const pending = current.pending.map((entry) => entry.id === comment.id ? comment : entry);
|
|
11973
|
+
yield* saveState(worktreePath, {
|
|
11974
|
+
...current,
|
|
11975
|
+
pending
|
|
11976
|
+
});
|
|
11977
|
+
return some(pending);
|
|
11978
|
+
}),
|
|
11979
|
+
unstage: fn("Store.unstage")(function* (worktreePath, id) {
|
|
11980
|
+
const current = yield* state(worktreePath);
|
|
11981
|
+
if (!current.pending.some((entry) => entry.id === id)) return none();
|
|
11982
|
+
const pending = current.pending.filter((entry) => entry.id !== id);
|
|
11983
|
+
yield* saveState(worktreePath, {
|
|
11984
|
+
...current,
|
|
11985
|
+
pending
|
|
11986
|
+
});
|
|
11987
|
+
return some(pending);
|
|
11988
|
+
}),
|
|
10846
11989
|
take: fn("Store.take")(function* (worktreePath) {
|
|
10847
11990
|
const batches = yield* inbox(worktreePath);
|
|
10848
11991
|
const current = yield* state(worktreePath);
|
|
@@ -10855,14 +11998,70 @@ const cursorOps = (state, saveState, inbox) => {
|
|
|
10855
11998
|
})
|
|
10856
11999
|
};
|
|
10857
12000
|
};
|
|
10858
|
-
const
|
|
12001
|
+
const settingsOps = (root) => {
|
|
12002
|
+
return {
|
|
12003
|
+
settings: gen(function* () {
|
|
12004
|
+
const raw = yield* readOptional(settingsPath(root));
|
|
12005
|
+
return match$2(raw, {
|
|
12006
|
+
onNone: () => ({}),
|
|
12007
|
+
onSome: parseSettings
|
|
12008
|
+
});
|
|
12009
|
+
}).pipe(withSpan("Store.settings")),
|
|
12010
|
+
saveSettings: fn("Store.saveSettings")(function* (next) {
|
|
12011
|
+
const path = settingsPath(root);
|
|
12012
|
+
yield* ensureDir(root);
|
|
12013
|
+
yield* tryPromise({
|
|
12014
|
+
try: () => writeFile(path, JSON.stringify(next), "utf8"),
|
|
12015
|
+
catch: (cause) => new StoreUnwritable({
|
|
12016
|
+
path,
|
|
12017
|
+
reason: String(cause)
|
|
12018
|
+
})
|
|
12019
|
+
});
|
|
12020
|
+
})
|
|
12021
|
+
};
|
|
12022
|
+
};
|
|
12023
|
+
const reportOps = (root) => fn("Store.saveReport")(function* (stamp, text) {
|
|
12024
|
+
const path = reportPath(root, stamp);
|
|
12025
|
+
yield* ensureDir(reportsDir(root));
|
|
12026
|
+
yield* tryPromise({
|
|
12027
|
+
try: () => writeFile(path, text, "utf8"),
|
|
12028
|
+
catch: (cause) => new StoreUnwritable({
|
|
12029
|
+
path,
|
|
12030
|
+
reason: String(cause)
|
|
12031
|
+
})
|
|
12032
|
+
});
|
|
12033
|
+
return path;
|
|
12034
|
+
});
|
|
12035
|
+
const answerOps = (root) => {
|
|
12036
|
+
return {
|
|
12037
|
+
answer: fn("Store.answer")(function* (worktreePath, entry) {
|
|
12038
|
+
const path = outboxPath(root, worktreePath);
|
|
12039
|
+
yield* ensureDir(branchDir(root, worktreePath));
|
|
12040
|
+
yield* tryPromise({
|
|
12041
|
+
try: () => appendFile(path, `${JSON.stringify(entry)}\n`, "utf8"),
|
|
12042
|
+
catch: (cause) => new StoreUnwritable({
|
|
12043
|
+
path,
|
|
12044
|
+
reason: String(cause)
|
|
12045
|
+
})
|
|
12046
|
+
});
|
|
12047
|
+
}),
|
|
12048
|
+
answers: fn("Store.answers")(function* (worktreePath) {
|
|
12049
|
+
const raw = yield* readOptional(outboxPath(root, worktreePath));
|
|
12050
|
+
return match$2(raw, {
|
|
12051
|
+
onNone: () => [],
|
|
12052
|
+
onSome: parseAnswers
|
|
12053
|
+
});
|
|
12054
|
+
})
|
|
12055
|
+
};
|
|
12056
|
+
};
|
|
12057
|
+
const layersOps = (root) => {
|
|
10859
12058
|
return {
|
|
10860
|
-
|
|
10861
|
-
const raw = yield* readOptional(
|
|
12059
|
+
layers: fn("Store.layers")(function* (worktreePath) {
|
|
12060
|
+
const raw = yield* readOptional(layersPath(root, worktreePath));
|
|
10862
12061
|
return map$4(raw, (text) => JSON.parse(text));
|
|
10863
12062
|
}),
|
|
10864
|
-
|
|
10865
|
-
const path =
|
|
12063
|
+
saveLayers: fn("Store.saveLayers")(function* (worktreePath, next) {
|
|
12064
|
+
const path = layersPath(root, worktreePath);
|
|
10866
12065
|
yield* ensureDir(branchDir(root, worktreePath));
|
|
10867
12066
|
yield* tryPromise({
|
|
10868
12067
|
try: () => writeFile(path, JSON.stringify(next, void 0, 2), "utf8"),
|
|
@@ -10911,18 +12110,6 @@ const makeStore = (root) => {
|
|
|
10911
12110
|
})
|
|
10912
12111
|
});
|
|
10913
12112
|
});
|
|
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
12113
|
const cursors = cursorOps(state, saveState, inbox);
|
|
10927
12114
|
return {
|
|
10928
12115
|
root,
|
|
@@ -10930,8 +12117,10 @@ const makeStore = (root) => {
|
|
|
10930
12117
|
inbox,
|
|
10931
12118
|
state,
|
|
10932
12119
|
saveState,
|
|
10933
|
-
saveReport,
|
|
10934
|
-
...
|
|
12120
|
+
saveReport: reportOps(root),
|
|
12121
|
+
...settingsOps(root),
|
|
12122
|
+
...answerOps(root),
|
|
12123
|
+
...layersOps(root),
|
|
10935
12124
|
...cursors
|
|
10936
12125
|
};
|
|
10937
12126
|
};
|
|
@@ -10941,16 +12130,18 @@ storeAt(defaultRoot());
|
|
|
10941
12130
|
//#region src/cli/error.ts
|
|
10942
12131
|
var UnknownBranch = class extends TaggedError("UnknownBranch") {};
|
|
10943
12132
|
var UnknownFile = class extends TaggedError("UnknownFile") {};
|
|
12133
|
+
var UnknownComment = class extends TaggedError("UnknownComment") {};
|
|
10944
12134
|
var UnselectableRange = class extends TaggedError("UnselectableRange") {};
|
|
10945
12135
|
var UnknownCommand = class extends TaggedError("UnknownCommand") {};
|
|
10946
12136
|
var MissingOption = class extends TaggedError("MissingOption") {};
|
|
10947
12137
|
var EmptyReview = class extends TaggedError("EmptyReview") {};
|
|
10948
12138
|
var UnknownWorktree = class extends TaggedError("UnknownWorktree") {};
|
|
10949
|
-
var
|
|
10950
|
-
var
|
|
12139
|
+
var MalformedLayers = class extends TaggedError("MalformedLayers") {};
|
|
12140
|
+
var NoLayers = class extends TaggedError("NoLayers") {};
|
|
10951
12141
|
//#endregion
|
|
10952
12142
|
//#region src/cli/commands.ts
|
|
10953
12143
|
const CONTEXT = 3;
|
|
12144
|
+
const WHOLE_FILE$1 = 1e5;
|
|
10954
12145
|
const POLL = "500 millis";
|
|
10955
12146
|
const findBranch = fn("Cli.findBranch")(function* (repo, branch) {
|
|
10956
12147
|
const worktrees = yield* (yield* Git).worktrees(repo);
|
|
@@ -10961,8 +12152,8 @@ const findBranch = fn("Cli.findBranch")(function* (repo, branch) {
|
|
|
10961
12152
|
known: worktrees.map((w) => w.branch)
|
|
10962
12153
|
}) : succeed(found);
|
|
10963
12154
|
});
|
|
10964
|
-
const patchesOf = fn("Cli.patchesOf")(function* (worktree) {
|
|
10965
|
-
const raw = yield* (yield* Git).diff(worktree,
|
|
12155
|
+
const patchesOf = fn("Cli.patchesOf")(function* (worktree, context = CONTEXT) {
|
|
12156
|
+
const raw = yield* (yield* Git).diff(worktree, context);
|
|
10966
12157
|
return parsePatches(raw);
|
|
10967
12158
|
});
|
|
10968
12159
|
const findPatch = (patches, file) => fromNullishOr(patches.find((patch) => patch.path === file));
|
|
@@ -10974,9 +12165,18 @@ const waitingOn = fn("Cli.waitingOn")(function* (worktree) {
|
|
|
10974
12165
|
const store = yield* Store;
|
|
10975
12166
|
const state = yield* store.state(worktree.path);
|
|
10976
12167
|
const batches = yield* store.inbox(worktree.path);
|
|
12168
|
+
const told = yield* store.layers(worktree.path);
|
|
10977
12169
|
return {
|
|
10978
12170
|
staged: state.pending.length,
|
|
10979
|
-
unread: Math.max(0, batches.length - state.consumed)
|
|
12171
|
+
unread: Math.max(0, batches.length - state.consumed),
|
|
12172
|
+
layers: match$2(told, {
|
|
12173
|
+
onNone: () => 0,
|
|
12174
|
+
onSome: (layers) => layers.layers.length
|
|
12175
|
+
}),
|
|
12176
|
+
stale: match$2(told, {
|
|
12177
|
+
onNone: () => false,
|
|
12178
|
+
onSome: (layers) => layers.head !== worktree.head
|
|
12179
|
+
})
|
|
10980
12180
|
};
|
|
10981
12181
|
});
|
|
10982
12182
|
const listBranches = fn("Cli.listBranches")(function* (repo) {
|
|
@@ -10994,7 +12194,9 @@ const listBranches = fn("Cli.listBranches")(function* (repo) {
|
|
|
10994
12194
|
added: stat.added,
|
|
10995
12195
|
removed: stat.removed,
|
|
10996
12196
|
staged: waiting.staged,
|
|
10997
|
-
unread: waiting.unread
|
|
12197
|
+
unread: waiting.unread,
|
|
12198
|
+
layers: waiting.layers,
|
|
12199
|
+
stale: waiting.stale
|
|
10998
12200
|
});
|
|
10999
12201
|
}
|
|
11000
12202
|
return summaries.filter((summary) => summary.files > 0);
|
|
@@ -11041,7 +12243,7 @@ const reviewProgress = fn("Cli.reviewProgress")(function* (repo, branch) {
|
|
|
11041
12243
|
});
|
|
11042
12244
|
const anchorRequest = fn("Cli.anchorRequest")(function* (request) {
|
|
11043
12245
|
const worktree = yield* findBranch(request.repo, request.branch);
|
|
11044
|
-
const patches = yield* patchesOf(worktree);
|
|
12246
|
+
const patches = yield* patchesOf(worktree, WHOLE_FILE$1);
|
|
11045
12247
|
const resolved = yield* match$2(findPatch(patches, request.file), {
|
|
11046
12248
|
onNone: () => new UnknownFile({
|
|
11047
12249
|
file: request.file,
|
|
@@ -11076,10 +12278,30 @@ const stageComment = fn("Cli.stageComment")(function* (request) {
|
|
|
11076
12278
|
};
|
|
11077
12279
|
return { pending: (yield* store.stage(worktree.path, entry)).length };
|
|
11078
12280
|
});
|
|
12281
|
+
const editStaged = fn("Cli.editStaged")(function* (request) {
|
|
12282
|
+
const store = yield* Store;
|
|
12283
|
+
const worktree = yield* findBranch(request.repo, request.branch);
|
|
12284
|
+
const current = yield* store.state(worktree.path);
|
|
12285
|
+
const found = current.pending.find((entry) => entry.id === request.id);
|
|
12286
|
+
if (found === void 0) return yield* new UnknownComment({ id: request.id });
|
|
12287
|
+
const pending = yield* store.restage(worktree.path, {
|
|
12288
|
+
...found,
|
|
12289
|
+
body: request.body
|
|
12290
|
+
});
|
|
12291
|
+
return { pending: getOrElse(pending, () => current.pending).length };
|
|
12292
|
+
});
|
|
12293
|
+
const dropStaged = fn("Cli.dropStaged")(function* (repo, branch, id) {
|
|
12294
|
+
const store = yield* Store;
|
|
12295
|
+
const worktree = yield* findBranch(repo, branch);
|
|
12296
|
+
const pending = yield* store.unstage(worktree.path, id);
|
|
12297
|
+
if (isNone(pending)) return yield* new UnknownComment({ id });
|
|
12298
|
+
return { pending: pending.value.length };
|
|
12299
|
+
});
|
|
11079
12300
|
const listPending = fn("Cli.listPending")(function* (repo, branch) {
|
|
11080
12301
|
const store = yield* Store;
|
|
11081
12302
|
const worktree = yield* findBranch(repo, branch);
|
|
11082
12303
|
return (yield* store.state(worktree.path)).pending.map((entry) => ({
|
|
12304
|
+
id: entry.id,
|
|
11083
12305
|
file: entry.anchor.path,
|
|
11084
12306
|
side: entry.anchor.side,
|
|
11085
12307
|
start: entry.anchor.start,
|
|
@@ -11087,16 +12309,28 @@ const listPending = fn("Cli.listPending")(function* (repo, branch) {
|
|
|
11087
12309
|
body: entry.body
|
|
11088
12310
|
}));
|
|
11089
12311
|
});
|
|
11090
|
-
const
|
|
11091
|
-
|
|
11092
|
-
const
|
|
11093
|
-
return
|
|
12312
|
+
const bodyOf = (entry) => entry.body;
|
|
12313
|
+
const sentOf = (comment, spoken, settled, head) => {
|
|
12314
|
+
const mine = spoken.filter((entry) => entry.comment === comment.id);
|
|
12315
|
+
return {
|
|
12316
|
+
id: comment.id,
|
|
11094
12317
|
file: comment.file,
|
|
11095
12318
|
side: comment.side,
|
|
11096
12319
|
start: comment.start,
|
|
11097
12320
|
end: comment.end,
|
|
11098
|
-
body: comment.body
|
|
11099
|
-
|
|
12321
|
+
body: comment.body,
|
|
12322
|
+
settled: Object.hasOwn(settled, comment.id),
|
|
12323
|
+
stale: comment.head !== head,
|
|
12324
|
+
asks: mine.at(-1)?.asks === true,
|
|
12325
|
+
answers: mine.map(bodyOf)
|
|
12326
|
+
};
|
|
12327
|
+
};
|
|
12328
|
+
const listSent = fn("Cli.listSent")(function* (repo, branch) {
|
|
12329
|
+
const store = yield* Store;
|
|
12330
|
+
const worktree = yield* findBranch(repo, branch);
|
|
12331
|
+
const spoken = yield* store.answers(worktree.path);
|
|
12332
|
+
const current = yield* store.state(worktree.path);
|
|
12333
|
+
return flatten(yield* store.inbox(worktree.path)).map((comment) => sentOf(comment, spoken, current.settled, worktree.head));
|
|
11100
12334
|
});
|
|
11101
12335
|
const submitReview = fn("Cli.submitReview")(function* (repo, branch, id, at) {
|
|
11102
12336
|
const store = yield* Store;
|
|
@@ -11124,7 +12358,7 @@ const submitReview = fn("Cli.submitReview")(function* (repo, branch, id, at) {
|
|
|
11124
12358
|
const submitComment = fn("Cli.submitComment")(function* (request) {
|
|
11125
12359
|
const store = yield* Store;
|
|
11126
12360
|
const worktree = yield* findBranch(request.repo, request.branch);
|
|
11127
|
-
const patches = yield* patchesOf(worktree);
|
|
12361
|
+
const patches = yield* patchesOf(worktree, WHOLE_FILE$1);
|
|
11128
12362
|
const patch = findPatch(patches, request.file);
|
|
11129
12363
|
const resolved = yield* match$2(patch, {
|
|
11130
12364
|
onNone: () => new UnknownFile({
|
|
@@ -11164,6 +12398,7 @@ const listPatches = fn("Cli.listPatches")(function* (repo, branch, context = CON
|
|
|
11164
12398
|
return parsePatches(yield* git.diff(worktree, context));
|
|
11165
12399
|
});
|
|
11166
12400
|
const flatten = (batches) => batches.flatMap((batch) => batch.comments.map((comment) => ({
|
|
12401
|
+
id: comment.id,
|
|
11167
12402
|
at: batch.at,
|
|
11168
12403
|
head: batch.head,
|
|
11169
12404
|
file: comment.anchor.path,
|
|
@@ -11188,19 +12423,28 @@ const fileSource = fn("Cli.fileSource")(function* (repo, branch, file) {
|
|
|
11188
12423
|
const found = yield* git.source(worktree, file);
|
|
11189
12424
|
return getOrElse(found, () => []);
|
|
11190
12425
|
});
|
|
12426
|
+
const saveWrap = fn("Cli.saveWrap")(function* (wrap) {
|
|
12427
|
+
const store = yield* Store;
|
|
12428
|
+
const current = yield* store.settings;
|
|
12429
|
+
yield* store.saveSettings({
|
|
12430
|
+
...current,
|
|
12431
|
+
wrap
|
|
12432
|
+
});
|
|
12433
|
+
});
|
|
11191
12434
|
//#endregion
|
|
11192
|
-
//#region src/domain/
|
|
11193
|
-
const REMAINDER_TITLE = "not in any
|
|
12435
|
+
//#region src/domain/layers/model.ts
|
|
12436
|
+
const REMAINDER_TITLE = "not in any layer";
|
|
11194
12437
|
//#endregion
|
|
11195
|
-
//#region src/domain/
|
|
12438
|
+
//#region src/domain/layers/coverage.ts
|
|
11196
12439
|
const codeBlockOf$1 = (span) => ({
|
|
11197
12440
|
kind: "code",
|
|
11198
12441
|
path: span.path,
|
|
11199
12442
|
start: span.start,
|
|
11200
12443
|
end: span.end
|
|
11201
12444
|
});
|
|
11202
|
-
const codeBlocks = (
|
|
11203
|
-
const
|
|
12445
|
+
const codeBlocks = (layer) => layer.blocks.filter((block) => block.kind === "code");
|
|
12446
|
+
const noteOf = (layer) => layer.blocks.filter((block) => block.kind === "prose").map((block) => block.markdown.trim()).filter((markdown) => markdown.length > 0).join(" ");
|
|
12447
|
+
const spansOf$1 = (layers) => layers.flatMap((layer) => codeBlocks(layer).map(({ path, start, end }) => ({
|
|
11204
12448
|
path,
|
|
11205
12449
|
start,
|
|
11206
12450
|
end
|
|
@@ -11217,8 +12461,8 @@ const spanOfHunk = (patch, hunk) => {
|
|
|
11217
12461
|
});
|
|
11218
12462
|
};
|
|
11219
12463
|
const overlaps = (a, b) => a.path === b.path && a.start <= b.end && a.end >= b.start;
|
|
11220
|
-
const coverage = (patches,
|
|
11221
|
-
const claimed = spansOf(
|
|
12464
|
+
const coverage = (patches, layers) => {
|
|
12465
|
+
const claimed = spansOf$1(layers);
|
|
11222
12466
|
const hunks = patches.flatMap((patch) => patch.hunks.flatMap((hunk) => match$2(spanOfHunk(patch, hunk), {
|
|
11223
12467
|
onNone: () => [],
|
|
11224
12468
|
onSome: (s) => [s]
|
|
@@ -11230,9 +12474,9 @@ const coverage = (patches, steps) => {
|
|
|
11230
12474
|
missing
|
|
11231
12475
|
};
|
|
11232
12476
|
};
|
|
11233
|
-
const withFullCoverage = (patches,
|
|
11234
|
-
const gap = coverage(patches,
|
|
11235
|
-
if (gap.missing.length === 0) return
|
|
12477
|
+
const withFullCoverage = (patches, layers) => {
|
|
12478
|
+
const gap = coverage(patches, layers.layers);
|
|
12479
|
+
if (gap.missing.length === 0) return layers;
|
|
11236
12480
|
const remainder = {
|
|
11237
12481
|
title: REMAINDER_TITLE,
|
|
11238
12482
|
blocks: [{
|
|
@@ -11241,21 +12485,48 @@ const withFullCoverage = (patches, story) => {
|
|
|
11241
12485
|
}, ...gap.missing.map((span) => codeBlockOf$1(span))]
|
|
11242
12486
|
};
|
|
11243
12487
|
return {
|
|
11244
|
-
...
|
|
11245
|
-
|
|
12488
|
+
...layers,
|
|
12489
|
+
layers: [...layers.layers, remainder]
|
|
11246
12490
|
};
|
|
11247
12491
|
};
|
|
12492
|
+
const proseAnchors = (layer) => {
|
|
12493
|
+
const anchors = [];
|
|
12494
|
+
let pending = [];
|
|
12495
|
+
let last;
|
|
12496
|
+
for (const block of layer.blocks) {
|
|
12497
|
+
if (block.kind === "prose") {
|
|
12498
|
+
const markdown = block.markdown.trim();
|
|
12499
|
+
if (markdown.length > 0) pending.push(markdown);
|
|
12500
|
+
continue;
|
|
12501
|
+
}
|
|
12502
|
+
for (const markdown of pending) anchors.push({
|
|
12503
|
+
path: block.path,
|
|
12504
|
+
line: block.start,
|
|
12505
|
+
markdown,
|
|
12506
|
+
after: false
|
|
12507
|
+
});
|
|
12508
|
+
pending = [];
|
|
12509
|
+
last = block;
|
|
12510
|
+
}
|
|
12511
|
+
if (last === void 0) return anchors;
|
|
12512
|
+
return [...anchors, ...pending.map((markdown) => ({
|
|
12513
|
+
path: last.path,
|
|
12514
|
+
line: last.end,
|
|
12515
|
+
markdown,
|
|
12516
|
+
after: true
|
|
12517
|
+
}))];
|
|
12518
|
+
};
|
|
11248
12519
|
//#endregion
|
|
11249
|
-
//#region src/domain/
|
|
11250
|
-
const statusOf = (patches,
|
|
11251
|
-
const gap = coverage(patches,
|
|
12520
|
+
//#region src/domain/layers/version.ts
|
|
12521
|
+
const statusOf = (patches, layers, branchHead) => {
|
|
12522
|
+
const gap = coverage(patches, layers.layers);
|
|
11252
12523
|
const present = new Set(patches.map((patch) => patch.path));
|
|
11253
|
-
const mentioned = new Set(spansOf(
|
|
12524
|
+
const mentioned = new Set(spansOf$1(layers.layers).map((span) => span.path));
|
|
11254
12525
|
return {
|
|
11255
|
-
version:
|
|
11256
|
-
parent:
|
|
11257
|
-
stale:
|
|
11258
|
-
|
|
12526
|
+
version: layers.version,
|
|
12527
|
+
parent: layers.parent,
|
|
12528
|
+
stale: layers.head !== branchHead,
|
|
12529
|
+
layersHead: layers.head,
|
|
11259
12530
|
branchHead,
|
|
11260
12531
|
uncovered: gap.missing,
|
|
11261
12532
|
vanished: [...mentioned].filter((path) => !present.has(path)),
|
|
@@ -11264,9 +12535,10 @@ const statusOf = (patches, story, branchHead) => {
|
|
|
11264
12535
|
};
|
|
11265
12536
|
};
|
|
11266
12537
|
//#endregion
|
|
11267
|
-
//#region src/cli/
|
|
12538
|
+
//#region src/cli/layers.ts
|
|
12539
|
+
const STALE_ADVICE = "These layers describe an older commit. Read the diff again and write a new revision with layers set.";
|
|
11268
12540
|
const unique = (paths) => [...new Set(paths)];
|
|
11269
|
-
const
|
|
12541
|
+
const spansOfLayer = (layer) => codeBlocks(layer).map(({ path, start, end }) => ({
|
|
11270
12542
|
path,
|
|
11271
12543
|
start,
|
|
11272
12544
|
end
|
|
@@ -11286,20 +12558,20 @@ const codeBlockOf = (span) => ({
|
|
|
11286
12558
|
start: span.start,
|
|
11287
12559
|
end: span.end
|
|
11288
12560
|
});
|
|
11289
|
-
const blocksOf = (
|
|
11290
|
-
if (Array.isArray(
|
|
11291
|
-
const note = typeof
|
|
12561
|
+
const blocksOf = (layer) => {
|
|
12562
|
+
if (Array.isArray(layer.blocks)) return layer.blocks.filter(isBlock);
|
|
12563
|
+
const note = typeof layer.note === "string" ? [{
|
|
11292
12564
|
kind: "prose",
|
|
11293
|
-
markdown:
|
|
12565
|
+
markdown: layer.note
|
|
11294
12566
|
}] : [];
|
|
11295
|
-
const spans = Array.isArray(
|
|
12567
|
+
const spans = Array.isArray(layer.spans) ? layer.spans.filter(isSpan) : [];
|
|
11296
12568
|
return [...note, ...spans.map(codeBlockOf)];
|
|
11297
12569
|
};
|
|
11298
|
-
const
|
|
11299
|
-
const
|
|
11300
|
-
const title = typeof
|
|
11301
|
-
if (
|
|
11302
|
-
const blocks = blocksOf(
|
|
12570
|
+
const layerOf = (value) => {
|
|
12571
|
+
const layer = value;
|
|
12572
|
+
const title = typeof layer?.title === "string" ? layer.title.trim() : "";
|
|
12573
|
+
if (layer === void 0 || title.length === 0) return none();
|
|
12574
|
+
const blocks = blocksOf(layer);
|
|
11303
12575
|
return blocks.length === 0 ? none() : some({
|
|
11304
12576
|
title,
|
|
11305
12577
|
blocks
|
|
@@ -11313,54 +12585,57 @@ const parsed = (text) => {
|
|
|
11313
12585
|
return none();
|
|
11314
12586
|
}
|
|
11315
12587
|
};
|
|
11316
|
-
const
|
|
12588
|
+
const readLayers = fn("Cli.readLayers")(function* (text) {
|
|
11317
12589
|
const document = yield* match$2(parsed(text), {
|
|
11318
|
-
onNone: () => new
|
|
12590
|
+
onNone: () => new MalformedLayers({ reason: "the layers is not a JSON object" }),
|
|
11319
12591
|
onSome: succeed
|
|
11320
12592
|
});
|
|
11321
|
-
const raw = document["
|
|
11322
|
-
const
|
|
12593
|
+
const raw = document["layers"];
|
|
12594
|
+
const layers = (Array.isArray(raw) ? raw : []).flatMap((entry) => match$2(layerOf(entry), {
|
|
11323
12595
|
onNone: () => [],
|
|
11324
|
-
onSome: (
|
|
12596
|
+
onSome: (layer) => [layer]
|
|
11325
12597
|
}));
|
|
11326
|
-
if (
|
|
12598
|
+
if (layers.length === 0) return yield* new MalformedLayers({ reason: "every layer needs a title and at least one span or block" });
|
|
11327
12599
|
const summary = document["summary"];
|
|
11328
12600
|
return {
|
|
11329
12601
|
summary: typeof summary === "string" ? summary : "",
|
|
11330
|
-
|
|
12602
|
+
layers
|
|
11331
12603
|
};
|
|
11332
12604
|
});
|
|
11333
12605
|
const fromStored = (stored) => ({
|
|
11334
12606
|
...stored,
|
|
11335
12607
|
parent: fromNullishOr(stored.parent)
|
|
11336
12608
|
});
|
|
11337
|
-
const toStored = (
|
|
11338
|
-
...
|
|
11339
|
-
parent: getOrUndefined$1(
|
|
12609
|
+
const toStored = (layers) => ({
|
|
12610
|
+
...layers,
|
|
12611
|
+
parent: getOrUndefined$1(layers.parent)
|
|
11340
12612
|
});
|
|
11341
|
-
const
|
|
12613
|
+
const reportedLayers = (patches, layers) => {
|
|
11342
12614
|
const present = new Set(patches.map((patch) => patch.path));
|
|
11343
|
-
return withFullCoverage(patches,
|
|
11344
|
-
title:
|
|
11345
|
-
|
|
11346
|
-
|
|
12615
|
+
return withFullCoverage(patches, layers).layers.map((layer) => ({
|
|
12616
|
+
title: layer.title,
|
|
12617
|
+
note: noteOf(layer),
|
|
12618
|
+
files: unique(spansOfLayer(layer).map((span) => span.path)).filter((path) => present.has(path)),
|
|
12619
|
+
spans: spansOfLayer(layer),
|
|
12620
|
+
prose: proseAnchors(layer).filter((anchor) => present.has(anchor.path))
|
|
11347
12621
|
}));
|
|
11348
12622
|
};
|
|
11349
|
-
const reportOf = (patches,
|
|
11350
|
-
const status = statusOf(patches,
|
|
12623
|
+
const reportOf = (patches, layers, branchHead) => {
|
|
12624
|
+
const status = statusOf(patches, layers, branchHead);
|
|
11351
12625
|
return {
|
|
11352
12626
|
version: status.version,
|
|
11353
12627
|
parent: getOrUndefined$1(status.parent),
|
|
11354
|
-
head: status.
|
|
12628
|
+
head: status.layersHead,
|
|
11355
12629
|
branchHead: status.branchHead,
|
|
11356
12630
|
stale: status.stale,
|
|
11357
|
-
|
|
11358
|
-
|
|
12631
|
+
...status.stale ? { advice: STALE_ADVICE } : {},
|
|
12632
|
+
written: layers.written,
|
|
12633
|
+
summary: layers.summary,
|
|
11359
12634
|
covered: status.covered,
|
|
11360
12635
|
total: status.total,
|
|
11361
12636
|
uncovered: status.uncovered,
|
|
11362
12637
|
vanished: status.vanished,
|
|
11363
|
-
|
|
12638
|
+
layers: reportedLayers(patches, layers)
|
|
11364
12639
|
};
|
|
11365
12640
|
};
|
|
11366
12641
|
const resolve = (path) => realpath(path).catch(() => path);
|
|
@@ -11376,17 +12651,17 @@ const worktreeAt = fn("Cli.worktreeAt")(function* (worktreePath) {
|
|
|
11376
12651
|
known: worktrees.map((entry) => entry.path)
|
|
11377
12652
|
}) : succeed(found);
|
|
11378
12653
|
});
|
|
11379
|
-
const
|
|
12654
|
+
const storedLayers = fn("Cli.storedLayers")(function* (worktree) {
|
|
11380
12655
|
const store = yield* Store;
|
|
11381
|
-
return map$4(yield* store.
|
|
12656
|
+
return map$4(yield* store.layers(worktree.path), fromStored);
|
|
11382
12657
|
});
|
|
11383
|
-
const
|
|
12658
|
+
const setLayers = fn("Cli.setLayers")(function* (worktreePath, text, written) {
|
|
11384
12659
|
const store = yield* Store;
|
|
11385
12660
|
const worktree = yield* worktreeAt(worktreePath);
|
|
11386
|
-
const input = yield*
|
|
12661
|
+
const input = yield* readLayers(text);
|
|
11387
12662
|
const patches = yield* patchesOf(worktree);
|
|
11388
|
-
const previous = yield*
|
|
11389
|
-
const
|
|
12663
|
+
const previous = yield* storedLayers(worktree);
|
|
12664
|
+
const layers = {
|
|
11390
12665
|
version: match$2(previous, {
|
|
11391
12666
|
onNone: () => 1,
|
|
11392
12667
|
onSome: (old) => old.version + 1
|
|
@@ -11396,26 +12671,103 @@ const setStory = fn("Cli.setStory")(function* (worktreePath, text, written) {
|
|
|
11396
12671
|
base: worktree.base,
|
|
11397
12672
|
written,
|
|
11398
12673
|
summary: input.summary,
|
|
11399
|
-
|
|
12674
|
+
layers: input.layers
|
|
11400
12675
|
};
|
|
11401
|
-
yield* store.
|
|
11402
|
-
return reportOf(patches,
|
|
12676
|
+
yield* store.saveLayers(worktree.path, toStored(layers));
|
|
12677
|
+
return reportOf(patches, layers, worktree.head);
|
|
11403
12678
|
});
|
|
11404
|
-
const
|
|
12679
|
+
const showLayers = fn("Cli.showLayers")(function* (worktreePath) {
|
|
11405
12680
|
const worktree = yield* worktreeAt(worktreePath);
|
|
11406
12681
|
const patches = yield* patchesOf(worktree);
|
|
11407
|
-
const found = yield*
|
|
11408
|
-
const
|
|
11409
|
-
onNone: () => new
|
|
12682
|
+
const found = yield* storedLayers(worktree);
|
|
12683
|
+
const layers = yield* match$2(found, {
|
|
12684
|
+
onNone: () => new NoLayers({ worktree: worktree.path }),
|
|
11410
12685
|
onSome: succeed
|
|
11411
12686
|
});
|
|
11412
|
-
return reportOf(patches,
|
|
12687
|
+
return reportOf(patches, layers, worktree.head);
|
|
12688
|
+
});
|
|
12689
|
+
const listLayers = fn("Cli.listLayers")(function* (repo, branch) {
|
|
12690
|
+
const worktree = yield* findBranch(repo, branch);
|
|
12691
|
+
const found = yield* storedLayers(worktree);
|
|
12692
|
+
if (isNone(found)) return {
|
|
12693
|
+
layers: [],
|
|
12694
|
+
stale: false
|
|
12695
|
+
};
|
|
12696
|
+
const patches = yield* patchesOf(worktree);
|
|
12697
|
+
return {
|
|
12698
|
+
layers: reportedLayers(patches, found.value),
|
|
12699
|
+
stale: found.value.head !== worktree.head
|
|
12700
|
+
};
|
|
12701
|
+
});
|
|
12702
|
+
//#endregion
|
|
12703
|
+
//#region src/cli/threads.ts
|
|
12704
|
+
const stateOf$1 = (answers, isSettled) => {
|
|
12705
|
+
if (isSettled) return "done";
|
|
12706
|
+
const last = answers.at(-1);
|
|
12707
|
+
if (last === void 0) return "submitted";
|
|
12708
|
+
return last.asks ? "question" : "answered";
|
|
12709
|
+
};
|
|
12710
|
+
const spoken$1 = (entry) => ({
|
|
12711
|
+
body: entry.body,
|
|
12712
|
+
at: entry.at,
|
|
12713
|
+
asks: entry.asks
|
|
12714
|
+
});
|
|
12715
|
+
const threadOf = (comment, batch, reading) => {
|
|
12716
|
+
const mine = reading.answers.filter((entry) => entry.comment === comment.id);
|
|
12717
|
+
return {
|
|
12718
|
+
id: comment.id,
|
|
12719
|
+
file: comment.anchor.path,
|
|
12720
|
+
side: comment.anchor.side,
|
|
12721
|
+
start: comment.anchor.start,
|
|
12722
|
+
end: comment.anchor.end,
|
|
12723
|
+
body: comment.body,
|
|
12724
|
+
state: stateOf$1(mine, Object.hasOwn(reading.settled, comment.id)),
|
|
12725
|
+
stale: batch.head !== reading.head,
|
|
12726
|
+
answers: mine.map(spoken$1)
|
|
12727
|
+
};
|
|
12728
|
+
};
|
|
12729
|
+
const threadsIn = (batches, reading) => batches.flatMap((batch) => batch.comments.map((comment) => threadOf(comment, batch, reading)));
|
|
12730
|
+
const idsIn = (batches) => batches.flatMap((batch) => batch.comments.map((comment) => comment.id));
|
|
12731
|
+
const isKnown = fn("Cli.isKnown")(function* (worktreePath, id) {
|
|
12732
|
+
const store = yield* Store;
|
|
12733
|
+
return idsIn(yield* store.inbox(worktreePath)).includes(id);
|
|
12734
|
+
});
|
|
12735
|
+
const listThreads = fn("Cli.listThreads")(function* (repo, branch) {
|
|
12736
|
+
const store = yield* Store;
|
|
12737
|
+
const worktree = yield* findBranch(repo, branch);
|
|
12738
|
+
const current = yield* store.state(worktree.path);
|
|
12739
|
+
return threadsIn(yield* store.inbox(worktree.path), {
|
|
12740
|
+
answers: yield* store.answers(worktree.path),
|
|
12741
|
+
settled: current.settled,
|
|
12742
|
+
head: worktree.head
|
|
12743
|
+
});
|
|
12744
|
+
});
|
|
12745
|
+
const answerComment = fn("Cli.answerComment")(function* (request) {
|
|
12746
|
+
const store = yield* Store;
|
|
12747
|
+
const worktree = yield* worktreeAt(request.worktree);
|
|
12748
|
+
if (!(yield* isKnown(worktree.path, request.id))) return yield* new UnknownComment({ id: request.id });
|
|
12749
|
+
yield* store.answer(worktree.path, {
|
|
12750
|
+
comment: request.id,
|
|
12751
|
+
body: request.body,
|
|
12752
|
+
head: worktree.head,
|
|
12753
|
+
asks: request.asks,
|
|
12754
|
+
at: request.at
|
|
12755
|
+
});
|
|
12756
|
+
return { answered: (yield* store.answers(worktree.path)).filter((entry) => entry.comment === request.id).length };
|
|
11413
12757
|
});
|
|
11414
|
-
const
|
|
12758
|
+
const settleThread = fn("Cli.settleThread")(function* (repo, branch, id, at) {
|
|
12759
|
+
const store = yield* Store;
|
|
11415
12760
|
const worktree = yield* findBranch(repo, branch);
|
|
11416
|
-
|
|
11417
|
-
|
|
11418
|
-
|
|
12761
|
+
if (!(yield* isKnown(worktree.path, id))) return yield* new UnknownComment({ id });
|
|
12762
|
+
const current = yield* store.state(worktree.path);
|
|
12763
|
+
yield* store.saveState(worktree.path, {
|
|
12764
|
+
...current,
|
|
12765
|
+
settled: {
|
|
12766
|
+
...current.settled,
|
|
12767
|
+
[id]: at
|
|
12768
|
+
}
|
|
12769
|
+
});
|
|
12770
|
+
return { settled: id };
|
|
11419
12771
|
});
|
|
11420
12772
|
//#endregion
|
|
11421
12773
|
//#region src/cli/parse.ts
|
|
@@ -11542,6 +12894,46 @@ const catalog = [
|
|
|
11542
12894
|
dataKey: "pending",
|
|
11543
12895
|
example: "adiff comment stage --repo . --branch cdr-1 --file src/api.ts --start 4 --end 4 --body \"why\""
|
|
11544
12896
|
},
|
|
12897
|
+
{
|
|
12898
|
+
name: "comment edit",
|
|
12899
|
+
about: "Reword a staged comment. It keeps its id and the lines it was written against",
|
|
12900
|
+
safety: "write",
|
|
12901
|
+
options: [
|
|
12902
|
+
repo,
|
|
12903
|
+
branch,
|
|
12904
|
+
{
|
|
12905
|
+
name: "id",
|
|
12906
|
+
required: true,
|
|
12907
|
+
value: "id",
|
|
12908
|
+
about: "The staged comment, as `review progress` reported it"
|
|
12909
|
+
},
|
|
12910
|
+
{
|
|
12911
|
+
name: "body",
|
|
12912
|
+
required: true,
|
|
12913
|
+
value: "text",
|
|
12914
|
+
about: "What it should say instead"
|
|
12915
|
+
}
|
|
12916
|
+
],
|
|
12917
|
+
dataKey: "pending",
|
|
12918
|
+
example: "adiff comment edit --repo . --branch add-teammate-invitations --id c1 --body \"why is this unused\""
|
|
12919
|
+
},
|
|
12920
|
+
{
|
|
12921
|
+
name: "comment drop",
|
|
12922
|
+
about: "Take a staged comment out of the review before it is sent",
|
|
12923
|
+
safety: "write",
|
|
12924
|
+
options: [
|
|
12925
|
+
repo,
|
|
12926
|
+
branch,
|
|
12927
|
+
{
|
|
12928
|
+
name: "id",
|
|
12929
|
+
required: true,
|
|
12930
|
+
value: "id",
|
|
12931
|
+
about: "The staged comment to withdraw"
|
|
12932
|
+
}
|
|
12933
|
+
],
|
|
12934
|
+
dataKey: "pending",
|
|
12935
|
+
example: "adiff comment drop --repo . --branch add-teammate-invitations --id c1"
|
|
12936
|
+
},
|
|
11545
12937
|
{
|
|
11546
12938
|
name: "comment take",
|
|
11547
12939
|
about: "Collect the comments this worktree has not been handed yet. Exactly-once",
|
|
@@ -11560,6 +12952,64 @@ const catalog = [
|
|
|
11560
12952
|
dataKey: "comments",
|
|
11561
12953
|
example: "adiff comment take --worktree . --wait 300"
|
|
11562
12954
|
},
|
|
12955
|
+
{
|
|
12956
|
+
name: "comment answer",
|
|
12957
|
+
about: "Say what was done about a comment, or ask the reviewer something back",
|
|
12958
|
+
safety: "write",
|
|
12959
|
+
options: [
|
|
12960
|
+
{
|
|
12961
|
+
name: "worktree",
|
|
12962
|
+
required: true,
|
|
12963
|
+
value: "path",
|
|
12964
|
+
about: "The worktree the comment was written against"
|
|
12965
|
+
},
|
|
12966
|
+
{
|
|
12967
|
+
name: "id",
|
|
12968
|
+
required: true,
|
|
12969
|
+
value: "id",
|
|
12970
|
+
about: "The comment being answered, as `comment take` reported it"
|
|
12971
|
+
},
|
|
12972
|
+
{
|
|
12973
|
+
name: "body",
|
|
12974
|
+
required: true,
|
|
12975
|
+
value: "text",
|
|
12976
|
+
about: "What was done, or what is being asked"
|
|
12977
|
+
},
|
|
12978
|
+
{
|
|
12979
|
+
name: "asks",
|
|
12980
|
+
required: false,
|
|
12981
|
+
value: "flag",
|
|
12982
|
+
about: "The answer needs a reply before the work continues"
|
|
12983
|
+
}
|
|
12984
|
+
],
|
|
12985
|
+
dataKey: "answered",
|
|
12986
|
+
example: "adiff comment answer --worktree . --id c1 --body \"dropped it, and the import with it\""
|
|
12987
|
+
},
|
|
12988
|
+
{
|
|
12989
|
+
name: "comment threads",
|
|
12990
|
+
about: "Every comment on a branch with its answers and whether it is settled",
|
|
12991
|
+
safety: "read",
|
|
12992
|
+
options: [repo, branch],
|
|
12993
|
+
dataKey: "threads",
|
|
12994
|
+
example: "adiff comment threads --repo . --branch add-teammate-invitations"
|
|
12995
|
+
},
|
|
12996
|
+
{
|
|
12997
|
+
name: "comment resolve",
|
|
12998
|
+
about: "Mark a comment settled. Only the reviewer who raised it can",
|
|
12999
|
+
safety: "write",
|
|
13000
|
+
options: [
|
|
13001
|
+
repo,
|
|
13002
|
+
branch,
|
|
13003
|
+
{
|
|
13004
|
+
name: "id",
|
|
13005
|
+
required: true,
|
|
13006
|
+
value: "id",
|
|
13007
|
+
about: "The comment to settle"
|
|
13008
|
+
}
|
|
13009
|
+
],
|
|
13010
|
+
dataKey: "settled",
|
|
13011
|
+
example: "adiff comment resolve --repo . --branch add-teammate-invitations --id c1"
|
|
13012
|
+
},
|
|
11563
13013
|
{
|
|
11564
13014
|
name: "file vouch",
|
|
11565
13015
|
about: "Toggle a file as reviewed. Lapses on its own when the file changes",
|
|
@@ -11589,26 +13039,26 @@ const catalog = [
|
|
|
11589
13039
|
example: "adiff review progress --repo . --branch cdr-1"
|
|
11590
13040
|
},
|
|
11591
13041
|
{
|
|
11592
|
-
name: "
|
|
11593
|
-
about: "Write the reading order for this worktree's diff: ordered
|
|
13042
|
+
name: "layers set",
|
|
13043
|
+
about: "Write the reading order for this worktree's diff: ordered layers over spans of files",
|
|
11594
13044
|
safety: "write",
|
|
11595
13045
|
options: [{
|
|
11596
13046
|
name: "worktree",
|
|
11597
13047
|
required: true,
|
|
11598
13048
|
value: "path",
|
|
11599
|
-
about: "The worktree the
|
|
13049
|
+
about: "The worktree the layers is about"
|
|
11600
13050
|
}, {
|
|
11601
13051
|
name: "json",
|
|
11602
13052
|
required: true,
|
|
11603
13053
|
value: "file|-",
|
|
11604
|
-
about: "The
|
|
13054
|
+
about: "The layers document, as a file path or - to read stdin"
|
|
11605
13055
|
}],
|
|
11606
|
-
dataKey: "
|
|
11607
|
-
example: "adiff
|
|
13056
|
+
dataKey: "layers",
|
|
13057
|
+
example: "adiff layers set --worktree . --json -"
|
|
11608
13058
|
},
|
|
11609
13059
|
{
|
|
11610
|
-
name: "
|
|
11611
|
-
about: "The
|
|
13060
|
+
name: "layers show",
|
|
13061
|
+
about: "The layers of a worktree, with the hunks no layer claims",
|
|
11612
13062
|
safety: "read",
|
|
11613
13063
|
options: [{
|
|
11614
13064
|
name: "worktree",
|
|
@@ -11616,8 +13066,8 @@ const catalog = [
|
|
|
11616
13066
|
value: "path",
|
|
11617
13067
|
about: "The worktree to read"
|
|
11618
13068
|
}],
|
|
11619
|
-
dataKey: "
|
|
11620
|
-
example: "adiff
|
|
13069
|
+
dataKey: "layers",
|
|
13070
|
+
example: "adiff layers show --worktree . --fields layers,uncovered"
|
|
11621
13071
|
},
|
|
11622
13072
|
{
|
|
11623
13073
|
name: "review open",
|
|
@@ -11671,17 +13121,22 @@ const ADVICE = {
|
|
|
11671
13121
|
},
|
|
11672
13122
|
UnknownWorktree: {
|
|
11673
13123
|
exit: 3,
|
|
11674
|
-
suggestion: "Run `adiff
|
|
13124
|
+
suggestion: "Run `adiff layers set` from inside a worktree of the repository under review.",
|
|
11675
13125
|
retriable: false
|
|
11676
13126
|
},
|
|
11677
|
-
|
|
13127
|
+
MalformedLayers: {
|
|
11678
13128
|
exit: 2,
|
|
11679
|
-
suggestion: "A
|
|
13129
|
+
suggestion: "A layers is {\"summary\":\"…\",\"layers\":[{\"title\":\"…\",\"spans\":[{\"path\":\"…\",\"start\":1,\"end\":9}]}]}.",
|
|
13130
|
+
retriable: false
|
|
13131
|
+
},
|
|
13132
|
+
NoLayers: {
|
|
13133
|
+
exit: 3,
|
|
13134
|
+
suggestion: "No layers has been written for this worktree. Write one with `adiff layers set`.",
|
|
11680
13135
|
retriable: false
|
|
11681
13136
|
},
|
|
11682
|
-
|
|
13137
|
+
UnknownComment: {
|
|
11683
13138
|
exit: 3,
|
|
11684
|
-
suggestion: "No
|
|
13139
|
+
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
13140
|
retriable: false
|
|
11686
13141
|
},
|
|
11687
13142
|
UnselectableRange: {
|
|
@@ -11725,6 +13180,254 @@ const failure = (cause) => {
|
|
|
11725
13180
|
};
|
|
11726
13181
|
};
|
|
11727
13182
|
//#endregion
|
|
13183
|
+
//#region src/cli/help.ts
|
|
13184
|
+
const NAME_ROOM = 18;
|
|
13185
|
+
const REACH = 5;
|
|
13186
|
+
const manifest = () => {
|
|
13187
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
13188
|
+
return Array.from({ length: REACH }, (_, layer) => join(here, ...Array(layer).fill(".."))).map((at) => join(at, "package.json")).find((path) => existsSync(path));
|
|
13189
|
+
};
|
|
13190
|
+
const version = () => {
|
|
13191
|
+
const path = manifest();
|
|
13192
|
+
if (path === void 0) return "unknown";
|
|
13193
|
+
const raw = readFileSync(path, "utf8");
|
|
13194
|
+
return JSON.parse(raw).version ?? "unknown";
|
|
13195
|
+
};
|
|
13196
|
+
const line = (command) => ` ${command.name.padEnd(NAME_ROOM)}${command.about}`;
|
|
13197
|
+
const banner = () => [
|
|
13198
|
+
`adiff ${version()}`,
|
|
13199
|
+
"",
|
|
13200
|
+
"Review the work an agent did in a git worktree, and hand your comments back.",
|
|
13201
|
+
"",
|
|
13202
|
+
" adiff review open --repo . open the terminal on this repository",
|
|
13203
|
+
" adiff comment take --worktree . collect the comments left for you",
|
|
13204
|
+
"",
|
|
13205
|
+
"adiff --help lists every command. adiff describe answers the same as JSON."
|
|
13206
|
+
].join("\n");
|
|
13207
|
+
const help = () => [
|
|
13208
|
+
"adiff, for reviewing an agent's work in a worktree",
|
|
13209
|
+
"",
|
|
13210
|
+
"Commands:",
|
|
13211
|
+
...catalog.map(line),
|
|
13212
|
+
"",
|
|
13213
|
+
"Run `adiff help <command>` for its options."
|
|
13214
|
+
].join("\n");
|
|
13215
|
+
const option = (spec) => ` --${spec.name.padEnd(16)}${spec.about}${spec.required ? " (required)" : ""}`;
|
|
13216
|
+
const helpFor = (name) => {
|
|
13217
|
+
const command = findCommand(name);
|
|
13218
|
+
if (command === void 0) return void 0;
|
|
13219
|
+
const options = command.options.length === 0 ? [] : [
|
|
13220
|
+
"",
|
|
13221
|
+
"Options:",
|
|
13222
|
+
...command.options.map(option)
|
|
13223
|
+
];
|
|
13224
|
+
return [
|
|
13225
|
+
`adiff ${command.name}`,
|
|
13226
|
+
"",
|
|
13227
|
+
command.about,
|
|
13228
|
+
...options
|
|
13229
|
+
].join("\n");
|
|
13230
|
+
};
|
|
13231
|
+
//#endregion
|
|
13232
|
+
//#region src/service/forge/error.ts
|
|
13233
|
+
var ForgeUnavailable = class extends TaggedError("ForgeUnavailable") {};
|
|
13234
|
+
//#endregion
|
|
13235
|
+
//#region src/service/forge/service.ts
|
|
13236
|
+
var Forge = class extends Service()("adiff/Forge") {};
|
|
13237
|
+
const LIMIT = "200";
|
|
13238
|
+
const TIMEOUT_MS = 4e3;
|
|
13239
|
+
const FIELDS = "headRefName,state,isDraft";
|
|
13240
|
+
const decode = decodeUnknownEffect(ArraySchema(Struct({
|
|
13241
|
+
headRefName: String$1,
|
|
13242
|
+
state: String$1,
|
|
13243
|
+
isDraft: Boolean
|
|
13244
|
+
})));
|
|
13245
|
+
const stateOf = (row) => {
|
|
13246
|
+
if (row.isDraft && row.state === "OPEN") return "draft";
|
|
13247
|
+
if (row.state === "MERGED") return "merged";
|
|
13248
|
+
if (row.state === "CLOSED") return "closed";
|
|
13249
|
+
return "open";
|
|
13250
|
+
};
|
|
13251
|
+
const ask = (repo) => callback((resume) => {
|
|
13252
|
+
execFile("gh", [
|
|
13253
|
+
"pr",
|
|
13254
|
+
"list",
|
|
13255
|
+
"--state",
|
|
13256
|
+
"all",
|
|
13257
|
+
"--limit",
|
|
13258
|
+
LIMIT,
|
|
13259
|
+
"--json",
|
|
13260
|
+
FIELDS
|
|
13261
|
+
], {
|
|
13262
|
+
cwd: repo,
|
|
13263
|
+
timeout: TIMEOUT_MS,
|
|
13264
|
+
encoding: "utf8"
|
|
13265
|
+
}, (error, stdout) => {
|
|
13266
|
+
if (error === null) return resume(succeed(stdout));
|
|
13267
|
+
resume(fail(new ForgeUnavailable({
|
|
13268
|
+
repo,
|
|
13269
|
+
reason: error.message
|
|
13270
|
+
})));
|
|
13271
|
+
});
|
|
13272
|
+
});
|
|
13273
|
+
const read = fn("Forge.read")(function* (repo, raw) {
|
|
13274
|
+
const parsed = yield* try_({
|
|
13275
|
+
try: () => JSON.parse(raw),
|
|
13276
|
+
catch: (cause) => new ForgeUnavailable({
|
|
13277
|
+
repo,
|
|
13278
|
+
reason: String(cause)
|
|
13279
|
+
})
|
|
13280
|
+
});
|
|
13281
|
+
return (yield* mapError(decode(parsed), (cause) => new ForgeUnavailable({
|
|
13282
|
+
repo,
|
|
13283
|
+
reason: String(cause)
|
|
13284
|
+
}))).map((row) => ({
|
|
13285
|
+
branch: row.headRefName,
|
|
13286
|
+
state: stateOf(row)
|
|
13287
|
+
}));
|
|
13288
|
+
});
|
|
13289
|
+
const pulls = fn("Forge.pulls")(function* (repo) {
|
|
13290
|
+
const raw = yield* ask(repo);
|
|
13291
|
+
return yield* read(repo, raw);
|
|
13292
|
+
});
|
|
13293
|
+
const ForgeLive = succeed$1(Forge)({ pulls });
|
|
13294
|
+
//#endregion
|
|
13295
|
+
//#region src/tui/gaps.ts
|
|
13296
|
+
const sourceLength = (source) => source.at(-1)?.trim() === "" ? source.length - 1 : source.length;
|
|
13297
|
+
const markerText = (hidden) => `⋯ ${hidden} lines hidden · press l`;
|
|
13298
|
+
const lastNewLine = (patch) => {
|
|
13299
|
+
const found = patch.rows.findLast((row) => isSome(row.newLine));
|
|
13300
|
+
return found === void 0 ? 0 : getOrElse(found.newLine, () => 0);
|
|
13301
|
+
};
|
|
13302
|
+
const spansOf = (patch, total) => {
|
|
13303
|
+
const leading = {
|
|
13304
|
+
lo: 1,
|
|
13305
|
+
hi: (patch.hunks[0]?.newStart ?? 1) - 1
|
|
13306
|
+
};
|
|
13307
|
+
const between = patch.hunks.slice(1).map((hunk) => ({
|
|
13308
|
+
lo: hunk.newStart - hunk.skipped,
|
|
13309
|
+
hi: hunk.newStart - 1
|
|
13310
|
+
}));
|
|
13311
|
+
const trailing = {
|
|
13312
|
+
lo: lastNewLine(patch) + 1,
|
|
13313
|
+
hi: total
|
|
13314
|
+
};
|
|
13315
|
+
return [
|
|
13316
|
+
leading,
|
|
13317
|
+
...between,
|
|
13318
|
+
trailing
|
|
13319
|
+
];
|
|
13320
|
+
};
|
|
13321
|
+
const linesFrom = (build, from, to) => build.full === void 0 || to < from ? [] : build.full.rows.filter((row) => match$2(row.newLine, {
|
|
13322
|
+
onNone: () => false,
|
|
13323
|
+
onSome: (line) => line >= from && line <= to
|
|
13324
|
+
}));
|
|
13325
|
+
const push = (made, row) => {
|
|
13326
|
+
made.rows.push({
|
|
13327
|
+
...row,
|
|
13328
|
+
index: made.rows.length
|
|
13329
|
+
});
|
|
13330
|
+
};
|
|
13331
|
+
const markGap = (made, index, hidden) => {
|
|
13332
|
+
made.gaps.push({
|
|
13333
|
+
index,
|
|
13334
|
+
hidden,
|
|
13335
|
+
row: made.rows.length
|
|
13336
|
+
});
|
|
13337
|
+
push(made, {
|
|
13338
|
+
kind: "context",
|
|
13339
|
+
oldLine: none(),
|
|
13340
|
+
newLine: none(),
|
|
13341
|
+
text: markerText(hidden)
|
|
13342
|
+
});
|
|
13343
|
+
};
|
|
13344
|
+
const openOf = (build, index, count) => {
|
|
13345
|
+
if (build.full === void 0) return 0;
|
|
13346
|
+
const asked = build.reveals.find((entry) => entry.gap === index)?.lines ?? 0;
|
|
13347
|
+
return Math.min(count, Math.max(0, asked));
|
|
13348
|
+
};
|
|
13349
|
+
const countOf = (span) => Math.max(0, span.hi - span.lo + 1);
|
|
13350
|
+
const openAbove = (made, build, index) => {
|
|
13351
|
+
const span = build.spans[index];
|
|
13352
|
+
if (span === void 0) return 0;
|
|
13353
|
+
const count = countOf(span);
|
|
13354
|
+
const open = openOf(build, index, count);
|
|
13355
|
+
const left = count - open;
|
|
13356
|
+
if (left > 0) markGap(made, index, left);
|
|
13357
|
+
for (const row of linesFrom(build, span.hi - open + 1, span.hi)) push(made, row);
|
|
13358
|
+
return left;
|
|
13359
|
+
};
|
|
13360
|
+
const openBelow = (made, build) => {
|
|
13361
|
+
const index = build.base.hunks.length;
|
|
13362
|
+
const span = build.spans[index];
|
|
13363
|
+
if (span === void 0) return;
|
|
13364
|
+
const count = countOf(span);
|
|
13365
|
+
const open = openOf(build, index, count);
|
|
13366
|
+
for (const row of linesFrom(build, span.lo, span.lo + open - 1)) push(made, row);
|
|
13367
|
+
if (count - open > 0) markGap(made, index, count - open);
|
|
13368
|
+
};
|
|
13369
|
+
const makeRows = (build) => {
|
|
13370
|
+
const made = {
|
|
13371
|
+
rows: [],
|
|
13372
|
+
hunks: [],
|
|
13373
|
+
gaps: []
|
|
13374
|
+
};
|
|
13375
|
+
for (const [index, hunk] of build.base.hunks.entries()) {
|
|
13376
|
+
const left = openAbove(made, build, index);
|
|
13377
|
+
const startRow = made.rows.length;
|
|
13378
|
+
for (const row of hunk.rows) push(made, row);
|
|
13379
|
+
made.hunks.push({
|
|
13380
|
+
...hunk,
|
|
13381
|
+
startRow,
|
|
13382
|
+
rows: made.rows.slice(startRow),
|
|
13383
|
+
skipped: index === 0 ? 0 : left
|
|
13384
|
+
});
|
|
13385
|
+
}
|
|
13386
|
+
openBelow(made, build);
|
|
13387
|
+
return made;
|
|
13388
|
+
};
|
|
13389
|
+
const compose = (build) => {
|
|
13390
|
+
const made = makeRows(build);
|
|
13391
|
+
return {
|
|
13392
|
+
patch: {
|
|
13393
|
+
...build.base,
|
|
13394
|
+
rows: made.rows,
|
|
13395
|
+
hunks: made.hunks
|
|
13396
|
+
},
|
|
13397
|
+
gaps: made.gaps
|
|
13398
|
+
};
|
|
13399
|
+
};
|
|
13400
|
+
const cache = /* @__PURE__ */ new WeakMap();
|
|
13401
|
+
const keyOf$1 = (total, full, reveals) => [
|
|
13402
|
+
total,
|
|
13403
|
+
full === void 0 ? 0 : full.rows.length,
|
|
13404
|
+
reveals.map((entry) => `${entry.gap}-${entry.lines}`).join(",")
|
|
13405
|
+
].join(":");
|
|
13406
|
+
const shownOf = (state) => {
|
|
13407
|
+
const base = state.patches[state.patchIndex];
|
|
13408
|
+
if (base === void 0) return void 0;
|
|
13409
|
+
const full = state.full.find((patch) => patch.path === base.path);
|
|
13410
|
+
const total = sourceLength(state.source);
|
|
13411
|
+
const reveals = state.revealed.filter((entry) => entry.file === base.path);
|
|
13412
|
+
const key = keyOf$1(total, full, reveals);
|
|
13413
|
+
const known = cache.get(base);
|
|
13414
|
+
const found = known?.get(key);
|
|
13415
|
+
if (found !== void 0) return found;
|
|
13416
|
+
const made = compose({
|
|
13417
|
+
base,
|
|
13418
|
+
full,
|
|
13419
|
+
spans: spansOf(base, total),
|
|
13420
|
+
reveals
|
|
13421
|
+
});
|
|
13422
|
+
const map = known ?? /* @__PURE__ */ new Map();
|
|
13423
|
+
map.set(key, made);
|
|
13424
|
+
cache.set(base, map);
|
|
13425
|
+
return made;
|
|
13426
|
+
};
|
|
13427
|
+
const gapAtRow = (state, row) => shownOf(state)?.gaps.find((gap) => gap.row === row);
|
|
13428
|
+
const gapNumbered = (state, index) => shownOf(state)?.gaps.find((gap) => gap.index === index);
|
|
13429
|
+
const gapRowSet = (shown) => new Set(shown.gaps.map((gap) => gap.row));
|
|
13430
|
+
//#endregion
|
|
11728
13431
|
//#region src/tui/tree.ts
|
|
11729
13432
|
const add = (tree, input) => {
|
|
11730
13433
|
const id = tree.nodes.length;
|
|
@@ -11825,7 +13528,7 @@ const visit = (walk, id, depth) => {
|
|
|
11825
13528
|
fileIndex: void 0,
|
|
11826
13529
|
files: filesUnder(walk.tree, last.id)
|
|
11827
13530
|
});
|
|
11828
|
-
if (collapsed.some((
|
|
13531
|
+
if (collapsed.some((layer) => walk.closed.includes(layer.path))) return;
|
|
11829
13532
|
for (const child of last.children) visit(walk, child, depth + 1);
|
|
11830
13533
|
};
|
|
11831
13534
|
const flattenTree = (tree, closed) => {
|
|
@@ -11858,10 +13561,13 @@ const initialState = (branches) => ({
|
|
|
11858
13561
|
patches: [],
|
|
11859
13562
|
patchIndex: 0,
|
|
11860
13563
|
cursor: 0,
|
|
13564
|
+
stop: 0,
|
|
13565
|
+
opened: [],
|
|
11861
13566
|
anchorRow: 0,
|
|
11862
13567
|
selecting: false,
|
|
11863
13568
|
draft: "",
|
|
11864
13569
|
notice: "",
|
|
13570
|
+
waiting: "",
|
|
11865
13571
|
query: "",
|
|
11866
13572
|
paletteIndex: 0,
|
|
11867
13573
|
returnTo: "branches",
|
|
@@ -11871,46 +13577,127 @@ const initialState = (branches) => ({
|
|
|
11871
13577
|
pending: [],
|
|
11872
13578
|
sent: [],
|
|
11873
13579
|
pendingIndex: 0,
|
|
13580
|
+
editing: void 0,
|
|
11874
13581
|
viewport: 20,
|
|
11875
13582
|
context: 3,
|
|
11876
13583
|
top: 0,
|
|
11877
13584
|
source: [],
|
|
13585
|
+
full: [],
|
|
13586
|
+
revealed: [],
|
|
11878
13587
|
focus: "diff",
|
|
11879
13588
|
navOpen: true,
|
|
11880
|
-
|
|
11881
|
-
|
|
13589
|
+
wrap: false,
|
|
13590
|
+
pan: 0,
|
|
13591
|
+
layers: [],
|
|
13592
|
+
layersStale: false,
|
|
13593
|
+
pulls: {},
|
|
13594
|
+
layerIndex: 0,
|
|
13595
|
+
openLayers: [],
|
|
11882
13596
|
rail: "tree"
|
|
11883
13597
|
});
|
|
11884
|
-
const
|
|
11885
|
-
const
|
|
11886
|
-
|
|
11887
|
-
if (
|
|
11888
|
-
|
|
13598
|
+
const onLayers = (state) => state.rail === "layers" && state.layers.length > 0;
|
|
13599
|
+
const selectedLayer = (state) => state.layers[state.layerIndex];
|
|
13600
|
+
const proseFor = (state, path) => {
|
|
13601
|
+
if (!onLayers(state)) return [];
|
|
13602
|
+
const layer = selectedLayer(state);
|
|
13603
|
+
if (layer === void 0) return [];
|
|
13604
|
+
return layer.prose.filter((anchor) => anchor.path === path);
|
|
13605
|
+
};
|
|
13606
|
+
const layerFiles = (state, layerIndex) => {
|
|
13607
|
+
const layer = state.layers[layerIndex];
|
|
13608
|
+
if (layer === void 0) return [];
|
|
13609
|
+
return layer.files.flatMap((path) => {
|
|
11889
13610
|
const at = state.patches.findIndex((patch) => patch.path === path);
|
|
11890
13611
|
return at === -1 ? [] : [at];
|
|
11891
13612
|
});
|
|
11892
13613
|
};
|
|
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
|
-
|
|
13614
|
+
const layerHolding = (state, fileIndex) => {
|
|
13615
|
+
const path = state.patches[fileIndex]?.path;
|
|
13616
|
+
const at = state.layers.findIndex((layer) => layer.files.includes(path ?? ""));
|
|
13617
|
+
return at === -1 ? state.layerIndex : at;
|
|
13618
|
+
};
|
|
13619
|
+
const layerOpen = (state, layerIndex) => state.openLayers.includes(layerIndex);
|
|
13620
|
+
const chunked = (word, room) => word.length <= room ? [word] : [word.slice(0, room), ...chunked(word.slice(room), room)];
|
|
13621
|
+
const packed = (lines, word, room) => {
|
|
13622
|
+
const last = lines.at(-1);
|
|
13623
|
+
if (last === void 0 || last.length + 1 + word.length > room) return [...lines, word];
|
|
13624
|
+
return [...lines.slice(0, -1), `${last} ${word}`];
|
|
13625
|
+
};
|
|
13626
|
+
const wrapped = (text, room) => {
|
|
13627
|
+
const width = Math.max(1, room);
|
|
13628
|
+
return text.split(/\s+/).filter((word) => word.length > 0).flatMap((word) => chunked(word, width)).reduce((lines, word) => packed(lines, word, width), []);
|
|
13629
|
+
};
|
|
13630
|
+
const NO_NOTE = "no note";
|
|
13631
|
+
const noteRows$1 = (state, layerIndex, room) => {
|
|
13632
|
+
const lines = wrapped(state.layers[layerIndex]?.note ?? "", room);
|
|
13633
|
+
return (lines.length === 0 ? [NO_NOTE] : lines).map((text) => ({
|
|
13634
|
+
index: layerIndex,
|
|
13635
|
+
kind: "note",
|
|
13636
|
+
text,
|
|
13637
|
+
lead: false
|
|
13638
|
+
}));
|
|
13639
|
+
};
|
|
13640
|
+
const proseRow = (layerIndex, text) => ({
|
|
13641
|
+
index: layerIndex,
|
|
13642
|
+
kind: "note",
|
|
13643
|
+
text,
|
|
13644
|
+
lead: false
|
|
13645
|
+
});
|
|
13646
|
+
const proseRows$1 = (state, layerIndex, room) => {
|
|
13647
|
+
const blocks = state.layers[layerIndex]?.prose ?? [];
|
|
13648
|
+
const rows = [];
|
|
13649
|
+
for (const [at, block] of blocks.entries()) {
|
|
13650
|
+
if (at > 0) rows.push(proseRow(layerIndex, ""));
|
|
13651
|
+
for (const text of wrapped(block.markdown, room)) rows.push(proseRow(layerIndex, text));
|
|
13652
|
+
rows.push({
|
|
13653
|
+
index: layerIndex,
|
|
13654
|
+
kind: "file",
|
|
13655
|
+
text: clipEnd(block.path, Math.max(1, room - FILE_LEAD)),
|
|
13656
|
+
lead: false
|
|
13657
|
+
});
|
|
13658
|
+
}
|
|
13659
|
+
return rows;
|
|
13660
|
+
};
|
|
13661
|
+
const titleRows = (state, layerIndex, room) => wrapped(state.layers[layerIndex]?.title ?? "", room).map((text, at) => ({
|
|
13662
|
+
index: layerIndex,
|
|
13663
|
+
kind: "title",
|
|
13664
|
+
text,
|
|
13665
|
+
lead: at === 0
|
|
13666
|
+
}));
|
|
13667
|
+
const clipEnd = (text, room) => {
|
|
13668
|
+
if (text.length <= room) return text;
|
|
13669
|
+
const parts = text.split("/");
|
|
13670
|
+
const kept = [];
|
|
13671
|
+
for (const part of parts.toReversed()) {
|
|
13672
|
+
if ([part, ...kept].join("/").length + 2 > room) break;
|
|
13673
|
+
kept.unshift(part);
|
|
13674
|
+
}
|
|
13675
|
+
return `…/${kept.length === 0 ? parts.at(-1) ?? text : kept.join("/")}`;
|
|
13676
|
+
};
|
|
13677
|
+
const FILE_LEAD = 2;
|
|
13678
|
+
const fileRows = (state, layerIndex, room) => (state.layers[layerIndex]?.files ?? []).map((path) => ({
|
|
13679
|
+
index: layerIndex,
|
|
13680
|
+
kind: "file",
|
|
13681
|
+
text: clipEnd(path, Math.max(1, room - FILE_LEAD)),
|
|
13682
|
+
lead: false
|
|
13683
|
+
}));
|
|
13684
|
+
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));
|
|
13685
|
+
const railWindow = (rows, height, layerIndex) => {
|
|
13686
|
+
if (rows.length <= height) return {
|
|
13687
|
+
rows,
|
|
11903
13688
|
more: 0
|
|
11904
13689
|
};
|
|
11905
|
-
const
|
|
13690
|
+
const first = Math.max(0, rows.findIndex((row) => row.index === layerIndex));
|
|
13691
|
+
const block = rows.findLastIndex((row) => row.index === layerIndex) - first + 1;
|
|
13692
|
+
const wanted = block >= height ? first : first - Math.floor((height - block) / 2);
|
|
13693
|
+
const start = Math.max(0, Math.min(rows.length - height, wanted));
|
|
11906
13694
|
return {
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
more: titles.length - height
|
|
13695
|
+
rows: rows.slice(start, start + height),
|
|
13696
|
+
more: rows.length - height
|
|
11910
13697
|
};
|
|
11911
13698
|
};
|
|
11912
13699
|
const selectedBranch = (state) => state.branches[state.branchIndex];
|
|
11913
|
-
const selectedPatch = (state) => state
|
|
13700
|
+
const selectedPatch = (state) => shownOf(state)?.patch;
|
|
11914
13701
|
const treeOf = (state) => buildTree(state.patches.map((patch) => patch.path));
|
|
11915
13702
|
const treeRows = (state) => {
|
|
11916
13703
|
const tree = treeOf(state);
|
|
@@ -11946,23 +13733,7 @@ const commentsOn = (state, fileIndex) => {
|
|
|
11946
13733
|
if (patch === void 0) return 0;
|
|
11947
13734
|
return state.pending.filter((entry) => entry.file === patch.path).length;
|
|
11948
13735
|
};
|
|
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
|
-
};
|
|
13736
|
+
const hiddenLines = (state) => shownOf(state)?.gaps.reduce((total, gap) => total + gap.hidden, 0) ?? 0;
|
|
11966
13737
|
const markedRows = (state) => {
|
|
11967
13738
|
const patch = selectedPatch(state);
|
|
11968
13739
|
if (patch === void 0) return /* @__PURE__ */ new Set();
|
|
@@ -11976,13 +13747,19 @@ const snippetOf = (state, limit) => {
|
|
|
11976
13747
|
const patch = selectedPatch(state);
|
|
11977
13748
|
if (patch === void 0) return [];
|
|
11978
13749
|
const [from, to] = selectionRange(state);
|
|
11979
|
-
return patch.rows.slice(from, to + 1).slice(0, limit).map((row) => `${
|
|
13750
|
+
return patch.rows.slice(from, to + 1).slice(0, limit).map((row) => `${lineOf(row).padStart(4)} ${row.text}`);
|
|
11980
13751
|
};
|
|
11981
13752
|
const lineOf = (row) => match$2(row.newLine, {
|
|
11982
13753
|
onNone: () => "-",
|
|
11983
13754
|
onSome: (line) => String(line)
|
|
11984
13755
|
});
|
|
13756
|
+
const editedComment = (state) => state.editing === void 0 ? void 0 : state.pending.find((entry) => entry.id === state.editing);
|
|
11985
13757
|
const composeTarget = (state) => {
|
|
13758
|
+
const edited = editedComment(state);
|
|
13759
|
+
if (edited !== void 0) {
|
|
13760
|
+
const span = edited.start === edited.end ? `${edited.start}` : `${edited.start}-${edited.end}`;
|
|
13761
|
+
return `Comment on ${edited.file}:${span}`;
|
|
13762
|
+
}
|
|
11986
13763
|
const patch = selectedPatch(state);
|
|
11987
13764
|
if (patch === void 0) return "";
|
|
11988
13765
|
const [from, to] = selectionRange(state);
|
|
@@ -11998,14 +13775,15 @@ const selectionReadout = (state) => {
|
|
|
11998
13775
|
const lines = to - from + 1;
|
|
11999
13776
|
return `${patch.path} ${lines} lines`;
|
|
12000
13777
|
};
|
|
13778
|
+
const WHOLE_FILE = 1e5;
|
|
12001
13779
|
const CONTEXT_STEPS = [
|
|
12002
13780
|
3,
|
|
12003
13781
|
10,
|
|
12004
13782
|
25,
|
|
12005
13783
|
60,
|
|
12006
|
-
|
|
13784
|
+
WHOLE_FILE
|
|
12007
13785
|
];
|
|
12008
|
-
const
|
|
13786
|
+
const layerContext = (current, delta) => {
|
|
12009
13787
|
const at = CONTEXT_STEPS.indexOf(current);
|
|
12010
13788
|
const next = Math.max(0, Math.min(CONTEXT_STEPS.length - 1, (at === -1 ? 0 : at) + delta));
|
|
12011
13789
|
return CONTEXT_STEPS[next] ?? current;
|
|
@@ -12030,24 +13808,59 @@ const rowAtSourceLine = (patch, line) => {
|
|
|
12030
13808
|
};
|
|
12031
13809
|
const lineOnSide = (row, side) => getOrUndefined$1(side === "old" ? row.oldLine : row.newLine);
|
|
12032
13810
|
const commentRowsIn = (state, fileIndex) => {
|
|
12033
|
-
const patch = state.patches[fileIndex];
|
|
13811
|
+
const patch = fileIndex === state.patchIndex ? selectedPatch(state) : state.patches[fileIndex];
|
|
12034
13812
|
if (patch === void 0) return [];
|
|
12035
13813
|
const notes = [...state.pending, ...state.sent].filter((entry) => entry.file === patch.path);
|
|
12036
13814
|
return patch.rows.filter((row) => notes.some((note) => lineOnSide(row, note.side) === note.end)).map((row) => row.index).toSorted((left, right) => left - right);
|
|
12037
13815
|
};
|
|
13816
|
+
const threadsAtRow = (state, row) => {
|
|
13817
|
+
const patch = selectedPatch(state);
|
|
13818
|
+
const here = patch?.rows[row];
|
|
13819
|
+
if (patch === void 0 || here === void 0) return [];
|
|
13820
|
+
return state.sent.filter((entry) => entry.file === patch.path && entry.id !== void 0 && lineOnSide(here, entry.side) === entry.end);
|
|
13821
|
+
};
|
|
13822
|
+
const stopsAtRow = (state, row) => 1 + threadsAtRow(state, row).length;
|
|
13823
|
+
const threadAtStop = (state) => state.stop === 0 ? void 0 : threadsAtRow(state, state.cursor)[state.stop - 1];
|
|
13824
|
+
const threadAtRow = (state, row) => {
|
|
13825
|
+
const patch = selectedPatch(state);
|
|
13826
|
+
const here = patch?.rows[row];
|
|
13827
|
+
if (patch === void 0 || here === void 0) return void 0;
|
|
13828
|
+
return state.sent.find((entry) => entry.file === patch.path && entry.id !== void 0 && lineOnSide(here, entry.side) === entry.end);
|
|
13829
|
+
};
|
|
13830
|
+
const openCommentRows = (state) => {
|
|
13831
|
+
const patch = selectedPatch(state);
|
|
13832
|
+
if (patch === void 0) return [];
|
|
13833
|
+
const open = [...state.pending, ...state.sent].filter((entry) => entry.file === patch.path && entry.settled !== true);
|
|
13834
|
+
return patch.rows.filter((row) => open.some((note) => lineOnSide(row, note.side) === note.end)).map((row) => row.index);
|
|
13835
|
+
};
|
|
12038
13836
|
const filesWithComments = (state) => state.patches.flatMap((patch, index) => [...state.pending, ...state.sent].some((entry) => entry.file === patch.path) ? [index] : []);
|
|
13837
|
+
const answerCount = (comments) => comments.reduce((total, entry) => total + (entry.answers?.length ?? 0), 0);
|
|
13838
|
+
const spokenSince = (seen, now) => Math.max(0, answerCount(now) - answerCount(seen));
|
|
12039
13839
|
const hunkStarts = (state) => {
|
|
12040
13840
|
const patch = selectedPatch(state);
|
|
12041
13841
|
return patch === void 0 ? [] : patch.hunks.map((hunk) => hunk.startRow);
|
|
12042
13842
|
};
|
|
13843
|
+
const changeAround = (state) => {
|
|
13844
|
+
const rows = selectedPatch(state)?.rows ?? [];
|
|
13845
|
+
const changed = (at) => {
|
|
13846
|
+
const row = rows[at];
|
|
13847
|
+
return row !== void 0 && row.kind !== "context";
|
|
13848
|
+
};
|
|
13849
|
+
if (!changed(state.cursor)) return void 0;
|
|
13850
|
+
let first = state.cursor;
|
|
13851
|
+
let last = state.cursor;
|
|
13852
|
+
while (changed(first - 1)) first -= 1;
|
|
13853
|
+
while (changed(last + 1)) last += 1;
|
|
13854
|
+
return [first, last];
|
|
13855
|
+
};
|
|
12043
13856
|
const nextUnreviewed = (state, from) => {
|
|
12044
13857
|
const order = fileOrder(state);
|
|
12045
13858
|
const start = Math.max(0, order.indexOf(from));
|
|
12046
13859
|
return [...order.slice(start + 1), ...order.slice(0, start + 1)].find((index) => !isReviewed(state, index));
|
|
12047
13860
|
};
|
|
12048
13861
|
const reviewedCount = (state) => `${state.vouched.length}/${state.patches.length} reviewed`;
|
|
12049
|
-
const fileOrder = (state) =>
|
|
12050
|
-
const
|
|
13862
|
+
const fileOrder = (state) => onLayers(state) ? layerFiles(state, state.layerIndex) : treeRows(state).flatMap((row) => row.fileIndex === void 0 ? [] : [row.fileIndex]);
|
|
13863
|
+
const layerFile = (state, delta) => {
|
|
12051
13864
|
const order = fileOrder(state);
|
|
12052
13865
|
const position = order.indexOf(state.patchIndex);
|
|
12053
13866
|
if (position === -1) return order[0] ?? state.patchIndex;
|
|
@@ -12112,12 +13925,38 @@ const buildReport = (state, around) => {
|
|
|
12112
13925
|
].join("\n");
|
|
12113
13926
|
};
|
|
12114
13927
|
//#endregion
|
|
13928
|
+
//#region src/tui/watch.ts
|
|
13929
|
+
const OUTBOX = "outbox.jsonl";
|
|
13930
|
+
const SETTLE_MS = 120;
|
|
13931
|
+
const answered = (name) => name !== null && name.endsWith(OUTBOX);
|
|
13932
|
+
const watchAnswers = (root, arrived) => {
|
|
13933
|
+
const branches = join(root, "branches");
|
|
13934
|
+
let timer;
|
|
13935
|
+
let watcher;
|
|
13936
|
+
try {
|
|
13937
|
+
mkdirSync(branches, { recursive: true });
|
|
13938
|
+
watcher = watch(branches, { recursive: true }, (_event, name) => {
|
|
13939
|
+
if (!answered(name)) return;
|
|
13940
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
13941
|
+
timer = setTimeout(arrived, SETTLE_MS);
|
|
13942
|
+
});
|
|
13943
|
+
watcher.on("error", () => void 0);
|
|
13944
|
+
} catch {
|
|
13945
|
+
watcher = void 0;
|
|
13946
|
+
}
|
|
13947
|
+
return { stop: () => {
|
|
13948
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
13949
|
+
watcher?.close();
|
|
13950
|
+
} };
|
|
13951
|
+
};
|
|
13952
|
+
//#endregion
|
|
12115
13953
|
//#region src/tui/command.ts
|
|
12116
13954
|
const command = (input) => ({
|
|
12117
13955
|
category: "Review",
|
|
12118
13956
|
hint: "",
|
|
12119
13957
|
listed: true,
|
|
12120
13958
|
whenStaged: false,
|
|
13959
|
+
whenLayers: false,
|
|
12121
13960
|
...input
|
|
12122
13961
|
});
|
|
12123
13962
|
const commands = [
|
|
@@ -12249,23 +14088,87 @@ const commands = [
|
|
|
12249
14088
|
screens: ["review"],
|
|
12250
14089
|
hint: "zoom"
|
|
12251
14090
|
}),
|
|
14091
|
+
command({
|
|
14092
|
+
action: "branch.first",
|
|
14093
|
+
title: "Go to the first worktree",
|
|
14094
|
+
category: "Branches",
|
|
14095
|
+
keys: ["g"],
|
|
14096
|
+
screens: ["branches"]
|
|
14097
|
+
}),
|
|
14098
|
+
command({
|
|
14099
|
+
action: "branch.last",
|
|
14100
|
+
title: "Go to the last worktree",
|
|
14101
|
+
category: "Branches",
|
|
14102
|
+
keys: ["G"],
|
|
14103
|
+
screens: ["branches"]
|
|
14104
|
+
}),
|
|
14105
|
+
command({
|
|
14106
|
+
action: "select.hunk",
|
|
14107
|
+
title: "Select the change under the cursor",
|
|
14108
|
+
keys: ["V"],
|
|
14109
|
+
screens: ["review"]
|
|
14110
|
+
}),
|
|
14111
|
+
command({
|
|
14112
|
+
action: "select.swap",
|
|
14113
|
+
title: "Grow the selection from its other end",
|
|
14114
|
+
keys: ["o"],
|
|
14115
|
+
screens: ["review"]
|
|
14116
|
+
}),
|
|
14117
|
+
command({
|
|
14118
|
+
action: "wrap.toggle",
|
|
14119
|
+
title: "Wrap long lines",
|
|
14120
|
+
category: "General",
|
|
14121
|
+
keys: ["w"],
|
|
14122
|
+
screens: ["review"],
|
|
14123
|
+
hint: "wrap"
|
|
14124
|
+
}),
|
|
14125
|
+
command({
|
|
14126
|
+
action: "pan.right",
|
|
14127
|
+
title: "Pan the diff right",
|
|
14128
|
+
keys: [">"],
|
|
14129
|
+
screens: ["review"]
|
|
14130
|
+
}),
|
|
14131
|
+
command({
|
|
14132
|
+
action: "pan.left",
|
|
14133
|
+
title: "Pan the diff left",
|
|
14134
|
+
keys: ["<"],
|
|
14135
|
+
screens: ["review"]
|
|
14136
|
+
}),
|
|
14137
|
+
command({
|
|
14138
|
+
action: "review.reload",
|
|
14139
|
+
title: "Read the branch again",
|
|
14140
|
+
category: "Review",
|
|
14141
|
+
keys: ["r"],
|
|
14142
|
+
screens: ["branches", "review"],
|
|
14143
|
+
hint: "reload"
|
|
14144
|
+
}),
|
|
14145
|
+
command({
|
|
14146
|
+
action: "thread.settle",
|
|
14147
|
+
title: "Settle the thread here",
|
|
14148
|
+
category: "Review",
|
|
14149
|
+
keys: ["d"],
|
|
14150
|
+
screens: ["review"],
|
|
14151
|
+
hint: "settle"
|
|
14152
|
+
}),
|
|
12252
14153
|
command({
|
|
12253
14154
|
action: "rail.toggle",
|
|
12254
|
-
title: "Switch between
|
|
14155
|
+
title: "Switch between layers and files",
|
|
12255
14156
|
category: "Files",
|
|
12256
14157
|
keys: ["s"],
|
|
12257
|
-
screens: ["review"]
|
|
14158
|
+
screens: ["review"],
|
|
14159
|
+
hint: "layers",
|
|
14160
|
+
whenLayers: true
|
|
12258
14161
|
}),
|
|
12259
14162
|
command({
|
|
12260
14163
|
action: "tree.collapse",
|
|
12261
|
-
title: "
|
|
14164
|
+
title: "Close the folder, layer, gap, or settled thread",
|
|
12262
14165
|
category: "Files",
|
|
12263
14166
|
keys: ["h"],
|
|
12264
14167
|
screens: ["review"]
|
|
12265
14168
|
}),
|
|
12266
14169
|
command({
|
|
12267
14170
|
action: "tree.expand",
|
|
12268
|
-
title: "
|
|
14171
|
+
title: "Open the folder, layer, gap, or settled thread",
|
|
12269
14172
|
category: "Files",
|
|
12270
14173
|
keys: ["l"],
|
|
12271
14174
|
screens: ["review"]
|
|
@@ -12347,6 +14250,22 @@ const commands = [
|
|
|
12347
14250
|
hint: "send",
|
|
12348
14251
|
listed: false
|
|
12349
14252
|
}),
|
|
14253
|
+
command({
|
|
14254
|
+
action: "pending.edit",
|
|
14255
|
+
title: "Reword this comment",
|
|
14256
|
+
category: "Review",
|
|
14257
|
+
keys: ["e"],
|
|
14258
|
+
screens: ["pending"],
|
|
14259
|
+
hint: "reword"
|
|
14260
|
+
}),
|
|
14261
|
+
command({
|
|
14262
|
+
action: "pending.drop",
|
|
14263
|
+
title: "Withdraw this comment",
|
|
14264
|
+
category: "Review",
|
|
14265
|
+
keys: ["X"],
|
|
14266
|
+
screens: ["pending"],
|
|
14267
|
+
hint: "withdraw"
|
|
14268
|
+
}),
|
|
12350
14269
|
command({
|
|
12351
14270
|
action: "pending.next",
|
|
12352
14271
|
title: "Next staged comment",
|
|
@@ -12436,7 +14355,7 @@ const displayKey = (key) => {
|
|
|
12436
14355
|
if (key.startsWith("ctrl+")) return `^${key.slice(5)}`;
|
|
12437
14356
|
return GLYPHS[key] ?? key;
|
|
12438
14357
|
};
|
|
12439
|
-
const hintsFor = (screen, staged) => commandsFor(screen).filter((entry) => entry.hint.length > 0).filter((entry) => !entry.whenStaged || staged > 0).map((entry) => ({
|
|
14358
|
+
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
14359
|
key: displayKey(entry.keys[0] ?? ""),
|
|
12441
14360
|
hint: entry.hint,
|
|
12442
14361
|
press: entry.keys[0] ?? ""
|
|
@@ -12478,8 +14397,31 @@ const withCursorVisible = (state) => {
|
|
|
12478
14397
|
};
|
|
12479
14398
|
const moveCursor = (state, delta) => withCursorVisible({
|
|
12480
14399
|
...state,
|
|
14400
|
+
stop: 0,
|
|
12481
14401
|
cursor: clamp(state.cursor + delta, 0, lastRow(selectedPatch(state)))
|
|
12482
14402
|
});
|
|
14403
|
+
const stepStop = (state, delta) => {
|
|
14404
|
+
const here = stopsAtRow(state, state.cursor) - 1;
|
|
14405
|
+
if (delta > 0 && state.stop < here) return {
|
|
14406
|
+
...state,
|
|
14407
|
+
stop: state.stop + 1
|
|
14408
|
+
};
|
|
14409
|
+
if (delta < 0 && state.stop > 0) return {
|
|
14410
|
+
...state,
|
|
14411
|
+
stop: state.stop - 1
|
|
14412
|
+
};
|
|
14413
|
+
const row = clamp(state.cursor + delta, 0, lastRow(selectedPatch(state)));
|
|
14414
|
+
if (row === state.cursor) return state;
|
|
14415
|
+
const landing = delta < 0 ? stopsAtRow({
|
|
14416
|
+
...state,
|
|
14417
|
+
cursor: row
|
|
14418
|
+
}, row) - 1 : 0;
|
|
14419
|
+
return withCursorVisible({
|
|
14420
|
+
...state,
|
|
14421
|
+
cursor: row,
|
|
14422
|
+
stop: landing
|
|
14423
|
+
});
|
|
14424
|
+
};
|
|
12483
14425
|
const scrolled = (state, delta) => {
|
|
12484
14426
|
const highest = Math.max(0, rowsIn(state) - Math.max(1, state.viewport));
|
|
12485
14427
|
return {
|
|
@@ -12495,9 +14437,10 @@ const draggedTo = (state, from, to) => ({
|
|
|
12495
14437
|
});
|
|
12496
14438
|
const atRow = (state, row) => withCursorVisible({
|
|
12497
14439
|
...state,
|
|
14440
|
+
stop: 0,
|
|
12498
14441
|
cursor: clamp(row, 0, lastRow(selectedPatch(state)))
|
|
12499
14442
|
});
|
|
12500
|
-
const
|
|
14443
|
+
const layerHunk = (state, delta) => {
|
|
12501
14444
|
const starts = hunkStarts(state);
|
|
12502
14445
|
const target = delta > 0 ? starts.find((start) => start > state.cursor) : starts.findLast((start) => start < state.cursor);
|
|
12503
14446
|
return target === void 0 ? state : atRow(state, target);
|
|
@@ -12520,25 +14463,37 @@ const atComment = (state, file, delta) => {
|
|
|
12520
14463
|
const landing = delta > 0 ? rows[0] : rows.at(-1);
|
|
12521
14464
|
return landing === void 0 ? moved : atRow(moved, landing);
|
|
12522
14465
|
};
|
|
12523
|
-
const
|
|
12524
|
-
const
|
|
14466
|
+
const nothingOpen = (state) => {
|
|
14467
|
+
const any = commentRowsIn(state, state.patchIndex).length > 0;
|
|
14468
|
+
return withNotice(state, any ? "no open comment" : "no comments yet");
|
|
14469
|
+
};
|
|
14470
|
+
const layerComment = (state, delta) => {
|
|
14471
|
+
const here = openCommentRows(state);
|
|
12525
14472
|
const target = delta > 0 ? here.find((row) => row > state.cursor) : here.findLast((row) => row < state.cursor);
|
|
12526
14473
|
if (target !== void 0) return atRow(state, target);
|
|
12527
14474
|
const file = nextFileWithComments(state, delta);
|
|
12528
14475
|
if (file !== void 0) return atComment(state, file, delta);
|
|
12529
|
-
return here.length > 0 ? state :
|
|
14476
|
+
return here.length > 0 ? state : nothingOpen(state);
|
|
14477
|
+
};
|
|
14478
|
+
const PAN_STEP = 8;
|
|
14479
|
+
const panned = (state, delta) => {
|
|
14480
|
+
if (state.wrap) return withNotice(state, "wrapping is on, so there is nothing to pan");
|
|
14481
|
+
return {
|
|
14482
|
+
...state,
|
|
14483
|
+
pan: Math.max(0, state.pan + delta)
|
|
14484
|
+
};
|
|
12530
14485
|
};
|
|
12531
14486
|
const movePending = (state, delta) => ({
|
|
12532
14487
|
...state,
|
|
12533
14488
|
pendingIndex: clamp(state.pendingIndex + delta, 0, Math.max(0, state.pending.length - 1))
|
|
12534
14489
|
});
|
|
12535
|
-
const
|
|
12536
|
-
const
|
|
14490
|
+
const moveLayer = (state, delta) => {
|
|
14491
|
+
const layerIndex = clamp(state.layerIndex + delta, 0, Math.max(0, state.layers.length - 1));
|
|
12537
14492
|
const landed = {
|
|
12538
14493
|
...state,
|
|
12539
|
-
|
|
14494
|
+
layerIndex
|
|
12540
14495
|
};
|
|
12541
|
-
const patchIndex =
|
|
14496
|
+
const patchIndex = layerFiles(landed, layerIndex)[0] ?? landed.patchIndex;
|
|
12542
14497
|
return {
|
|
12543
14498
|
...landed,
|
|
12544
14499
|
patchIndex,
|
|
@@ -12548,18 +14503,18 @@ const moveStep = (state, delta) => {
|
|
|
12548
14503
|
selecting: false
|
|
12549
14504
|
};
|
|
12550
14505
|
};
|
|
12551
|
-
const inRail = (state, delta) =>
|
|
12552
|
-
const
|
|
14506
|
+
const inRail = (state, delta) => onLayers(state) ? moveLayer(state, delta) : moveFile(state, delta);
|
|
14507
|
+
const layerDown = (state, delta) => state.focus === "tree" ? inRail(state, delta) : stepStop(state, delta);
|
|
12553
14508
|
const toggleRail = (state) => {
|
|
12554
|
-
if (state.
|
|
12555
|
-
if (state.rail === "
|
|
14509
|
+
if (state.layers.length === 0) return withNotice(state, "no layers for this branch");
|
|
14510
|
+
if (state.rail === "layers") return {
|
|
12556
14511
|
...state,
|
|
12557
14512
|
rail: "tree"
|
|
12558
14513
|
};
|
|
12559
14514
|
return {
|
|
12560
14515
|
...state,
|
|
12561
|
-
rail: "
|
|
12562
|
-
|
|
14516
|
+
rail: "layers",
|
|
14517
|
+
layerIndex: layerHolding(state, state.patchIndex)
|
|
12563
14518
|
};
|
|
12564
14519
|
};
|
|
12565
14520
|
const foldDirectory = (state, shut) => {
|
|
@@ -12571,18 +14526,56 @@ const foldDirectory = (state, shut) => {
|
|
|
12571
14526
|
closed: shut ? [...closed, directory] : closed
|
|
12572
14527
|
};
|
|
12573
14528
|
};
|
|
14529
|
+
const foldLayer = (state, shut) => {
|
|
14530
|
+
const open = state.openLayers.filter((index) => index !== state.layerIndex);
|
|
14531
|
+
return {
|
|
14532
|
+
...state,
|
|
14533
|
+
openLayers: shut ? open : [...open, state.layerIndex]
|
|
14534
|
+
};
|
|
14535
|
+
};
|
|
14536
|
+
const foldThread = (state, shut, id) => {
|
|
14537
|
+
const rest = state.opened.filter((held) => held !== id);
|
|
14538
|
+
return {
|
|
14539
|
+
...state,
|
|
14540
|
+
opened: shut ? rest : [...rest, id]
|
|
14541
|
+
};
|
|
14542
|
+
};
|
|
14543
|
+
const fold = (state, shut) => {
|
|
14544
|
+
const thread = threadAtStop(state);
|
|
14545
|
+
if (thread?.id !== void 0 && thread.settled === true) return foldThread(state, shut, thread.id);
|
|
14546
|
+
return onLayers(state) ? foldLayer(state, shut) : foldDirectory(state, shut);
|
|
14547
|
+
};
|
|
12574
14548
|
const moveBranch = (state, delta) => ({
|
|
12575
14549
|
...state,
|
|
12576
14550
|
branchIndex: clamp(state.branchIndex + delta, 0, Math.max(0, state.branches.length - 1))
|
|
12577
14551
|
});
|
|
12578
14552
|
const moveFile = (state, delta) => ({
|
|
12579
14553
|
...state,
|
|
12580
|
-
patchIndex:
|
|
14554
|
+
patchIndex: layerFile(state, delta),
|
|
12581
14555
|
top: 0,
|
|
12582
14556
|
cursor: 0,
|
|
12583
14557
|
anchorRow: 0,
|
|
12584
14558
|
selecting: false
|
|
12585
14559
|
});
|
|
14560
|
+
const selectHunk = (state) => {
|
|
14561
|
+
const found = changeAround(state);
|
|
14562
|
+
if (found === void 0) return withNotice(state, "no change under the cursor");
|
|
14563
|
+
return withCursorVisible({
|
|
14564
|
+
...state,
|
|
14565
|
+
selecting: true,
|
|
14566
|
+
anchorRow: found[0],
|
|
14567
|
+
cursor: found[1]
|
|
14568
|
+
});
|
|
14569
|
+
};
|
|
14570
|
+
const swapEnds = (state) => state.selecting ? withCursorVisible({
|
|
14571
|
+
...state,
|
|
14572
|
+
anchorRow: state.cursor,
|
|
14573
|
+
cursor: state.anchorRow
|
|
14574
|
+
}) : state;
|
|
14575
|
+
const atBranch = (state, at) => ({
|
|
14576
|
+
...state,
|
|
14577
|
+
branchIndex: clamp(at, 0, Math.max(0, state.branches.length - 1))
|
|
14578
|
+
});
|
|
12586
14579
|
const startSelection = (state) => ({
|
|
12587
14580
|
...state,
|
|
12588
14581
|
selecting: true,
|
|
@@ -12639,29 +14632,35 @@ const movePalette = (state, delta) => ({
|
|
|
12639
14632
|
const paletteMatches = (state) => searchCommands(state.returnTo, state.query);
|
|
12640
14633
|
const paletteChoice = (state) => paletteMatches(state)[state.paletteIndex]?.action;
|
|
12641
14634
|
const transitions = {
|
|
14635
|
+
"branch.first": (state) => atBranch(state, 0),
|
|
14636
|
+
"branch.last": (state) => atBranch(state, state.branches.length - 1),
|
|
12642
14637
|
"branch.next": (state) => moveBranch(state, 1),
|
|
12643
14638
|
"branch.prev": (state) => moveBranch(state, -1),
|
|
12644
14639
|
"branch.open": (state) => state,
|
|
12645
|
-
"cursor.next": (state) =>
|
|
14640
|
+
"cursor.next": (state) => layerDown(state, 1),
|
|
12646
14641
|
"cursor.top": (state) => atRow(state, 0),
|
|
12647
14642
|
"cursor.bottom": (state) => atRow(state, lastRow(selectedPatch(state))),
|
|
12648
14643
|
"cursor.pageDown": (state) => moveCursor(state, Math.max(1, Math.floor(state.viewport / 2))),
|
|
12649
14644
|
"cursor.pageUp": (state) => moveCursor(state, -Math.max(1, Math.floor(state.viewport / 2))),
|
|
12650
14645
|
"context.more": (state) => state,
|
|
12651
14646
|
"context.less": (state) => state,
|
|
12652
|
-
"comment.next": (state) =>
|
|
12653
|
-
"comment.prev": (state) =>
|
|
12654
|
-
"hunk.next": (state) =>
|
|
12655
|
-
"hunk.prev": (state) =>
|
|
12656
|
-
"cursor.prev": (state) =>
|
|
14647
|
+
"comment.next": (state) => layerComment(state, 1),
|
|
14648
|
+
"comment.prev": (state) => layerComment(state, -1),
|
|
14649
|
+
"hunk.next": (state) => layerHunk(state, 1),
|
|
14650
|
+
"hunk.prev": (state) => layerHunk(state, -1),
|
|
14651
|
+
"cursor.prev": (state) => layerDown(state, -1),
|
|
12657
14652
|
"file.next": (state) => moveFile(state, 1),
|
|
12658
14653
|
"file.prev": (state) => moveFile(state, -1),
|
|
12659
14654
|
"select.start": startSelection,
|
|
14655
|
+
"select.hunk": selectHunk,
|
|
14656
|
+
"select.swap": swapEnds,
|
|
12660
14657
|
"compose.open": openCompose,
|
|
12661
14658
|
"compose.submit": (state) => state,
|
|
12662
14659
|
"compose.stage": (state) => state,
|
|
12663
14660
|
"pending.open": (state) => state,
|
|
12664
14661
|
"pending.submit": (state) => state,
|
|
14662
|
+
"pending.edit": (state) => state,
|
|
14663
|
+
"pending.drop": (state) => state,
|
|
12665
14664
|
"pending.next": (state) => movePending(state, 1),
|
|
12666
14665
|
"pending.prev": (state) => movePending(state, -1),
|
|
12667
14666
|
"compose.newline": (state) => ({
|
|
@@ -12678,11 +14677,20 @@ const transitions = {
|
|
|
12678
14677
|
navOpen: !state.navOpen,
|
|
12679
14678
|
focus: "diff"
|
|
12680
14679
|
}),
|
|
14680
|
+
"wrap.toggle": (state) => ({
|
|
14681
|
+
...state,
|
|
14682
|
+
wrap: !state.wrap,
|
|
14683
|
+
pan: 0
|
|
14684
|
+
}),
|
|
14685
|
+
"pan.right": (state) => panned(state, PAN_STEP),
|
|
14686
|
+
"pan.left": (state) => panned(state, -8),
|
|
14687
|
+
"review.reload": (state) => state,
|
|
14688
|
+
"thread.settle": (state) => state,
|
|
12681
14689
|
"rail.toggle": toggleRail,
|
|
12682
14690
|
"file.vouch": (state) => state,
|
|
12683
14691
|
"file.vouch.next": (state) => state,
|
|
12684
|
-
"tree.collapse": (state) =>
|
|
12685
|
-
"tree.expand": (state) =>
|
|
14692
|
+
"tree.collapse": (state) => fold(state, true),
|
|
14693
|
+
"tree.expand": (state) => fold(state, false),
|
|
12686
14694
|
"report.open": (state) => ({
|
|
12687
14695
|
...state,
|
|
12688
14696
|
screen: "report",
|
|
@@ -12707,10 +14715,40 @@ const withContext = (state, context, patches, cursor) => ({
|
|
|
12707
14715
|
...state,
|
|
12708
14716
|
context,
|
|
12709
14717
|
patches,
|
|
14718
|
+
revealed: [],
|
|
12710
14719
|
cursor,
|
|
12711
14720
|
anchorRow: cursor,
|
|
12712
14721
|
selecting: false
|
|
12713
14722
|
});
|
|
14723
|
+
const withFull = (state, full) => ({
|
|
14724
|
+
...state,
|
|
14725
|
+
full
|
|
14726
|
+
});
|
|
14727
|
+
const revealsAfter = (state, gap, lines) => {
|
|
14728
|
+
const path = state.patches[state.patchIndex]?.path ?? "";
|
|
14729
|
+
const others = state.revealed.filter((entry) => entry.file !== path || entry.gap !== gap);
|
|
14730
|
+
return lines <= 0 ? others : [...others, {
|
|
14731
|
+
file: path,
|
|
14732
|
+
gap,
|
|
14733
|
+
lines
|
|
14734
|
+
}];
|
|
14735
|
+
};
|
|
14736
|
+
const gapOpened = (state, gap, delta) => {
|
|
14737
|
+
const path = state.patches[state.patchIndex]?.path ?? "";
|
|
14738
|
+
const now = state.revealed.find((entry) => entry.file === path && entry.gap === gap)?.lines ?? 0;
|
|
14739
|
+
const opened = {
|
|
14740
|
+
...state,
|
|
14741
|
+
revealed: revealsAfter(state, gap, now + delta)
|
|
14742
|
+
};
|
|
14743
|
+
const wanted = gapNumbered(opened, gap)?.row ?? state.cursor;
|
|
14744
|
+
const landed = clamp(wanted, 0, lastRow(selectedPatch(opened)));
|
|
14745
|
+
return withCursorVisible({
|
|
14746
|
+
...opened,
|
|
14747
|
+
cursor: landed,
|
|
14748
|
+
anchorRow: landed,
|
|
14749
|
+
selecting: false
|
|
14750
|
+
});
|
|
14751
|
+
};
|
|
12714
14752
|
const withPending = (state, pending, screen) => ({
|
|
12715
14753
|
...state,
|
|
12716
14754
|
pending,
|
|
@@ -12718,25 +14756,36 @@ const withPending = (state, pending, screen) => ({
|
|
|
12718
14756
|
staged: pending.length,
|
|
12719
14757
|
screen
|
|
12720
14758
|
});
|
|
14759
|
+
const panBy = (state, delta) => state.wrap ? state : {
|
|
14760
|
+
...state,
|
|
14761
|
+
pan: Math.max(0, state.pan + delta)
|
|
14762
|
+
};
|
|
12721
14763
|
const withSent = (state, sent) => ({
|
|
12722
14764
|
...state,
|
|
12723
14765
|
sent
|
|
12724
14766
|
});
|
|
12725
|
-
const
|
|
14767
|
+
const withLayers = (state, told) => {
|
|
14768
|
+
const layers = told.layers;
|
|
12726
14769
|
const opened = {
|
|
12727
14770
|
...state,
|
|
12728
|
-
|
|
12729
|
-
|
|
12730
|
-
|
|
14771
|
+
layers,
|
|
14772
|
+
layersStale: told.stale,
|
|
14773
|
+
layerIndex: 0,
|
|
14774
|
+
openLayers: [],
|
|
14775
|
+
rail: layers.length === 0 ? "tree" : "layers"
|
|
12731
14776
|
};
|
|
12732
|
-
if (
|
|
14777
|
+
if (layers.length === 0) return opened;
|
|
12733
14778
|
return {
|
|
12734
14779
|
...opened,
|
|
12735
|
-
patchIndex:
|
|
14780
|
+
patchIndex: layerFiles(opened, 0)[0] ?? opened.patchIndex,
|
|
12736
14781
|
cursor: 0,
|
|
12737
14782
|
top: 0
|
|
12738
14783
|
};
|
|
12739
14784
|
};
|
|
14785
|
+
const withPulls = (state, pulls) => ({
|
|
14786
|
+
...state,
|
|
14787
|
+
pulls
|
|
14788
|
+
});
|
|
12740
14789
|
const withBranches = (state, branches) => ({
|
|
12741
14790
|
...state,
|
|
12742
14791
|
branches,
|
|
@@ -12750,10 +14799,22 @@ const withVouched = (state, vouched) => ({
|
|
|
12750
14799
|
...state,
|
|
12751
14800
|
vouched
|
|
12752
14801
|
});
|
|
14802
|
+
const restoredTo = (state, path, line) => {
|
|
14803
|
+
const index = state.patches.findIndex((patch) => patch.path === path);
|
|
14804
|
+
const patch = state.patches[index];
|
|
14805
|
+
if (patch === void 0) return state;
|
|
14806
|
+
return withCursorVisible({
|
|
14807
|
+
...state,
|
|
14808
|
+
patchIndex: index,
|
|
14809
|
+
cursor: line === void 0 ? 0 : rowAtSourceLine(patch, line)
|
|
14810
|
+
});
|
|
14811
|
+
};
|
|
12753
14812
|
const withPatches = (state, patches) => ({
|
|
12754
14813
|
...state,
|
|
12755
14814
|
screen: "review",
|
|
12756
14815
|
patches,
|
|
14816
|
+
full: [],
|
|
14817
|
+
revealed: [],
|
|
12757
14818
|
closed: crowdedOf(patches),
|
|
12758
14819
|
patchIndex: fileOrder({
|
|
12759
14820
|
...state,
|
|
@@ -12786,6 +14847,14 @@ const paletteClosed = (state) => ({
|
|
|
12786
14847
|
screen: state.returnTo,
|
|
12787
14848
|
query: ""
|
|
12788
14849
|
});
|
|
14850
|
+
const withWaiting = (state, waiting) => ({
|
|
14851
|
+
...state,
|
|
14852
|
+
waiting
|
|
14853
|
+
});
|
|
14854
|
+
const withNoticeHere = (state, notice) => ({
|
|
14855
|
+
...state,
|
|
14856
|
+
notice
|
|
14857
|
+
});
|
|
12789
14858
|
const withNotice = (state, notice) => ({
|
|
12790
14859
|
...state,
|
|
12791
14860
|
screen: "review",
|
|
@@ -12937,10 +15006,12 @@ const syntaxTheme = {
|
|
|
12937
15006
|
punctuation: { fg: inkFaint },
|
|
12938
15007
|
"punctuation.bracket": { fg: inkFaint },
|
|
12939
15008
|
"punctuation.delimiter": { fg: inkFaint },
|
|
15009
|
+
gap: { fg: inkFaint },
|
|
12940
15010
|
note: {
|
|
12941
15011
|
fg: "#9aa7c7",
|
|
12942
15012
|
italic: true
|
|
12943
15013
|
},
|
|
15014
|
+
prose: { fg: "#a9b4cc" },
|
|
12944
15015
|
"note.sent": {
|
|
12945
15016
|
fg: "#6d7893",
|
|
12946
15017
|
italic: true
|
|
@@ -12961,9 +15032,37 @@ const WASH = {
|
|
|
12961
15032
|
}
|
|
12962
15033
|
};
|
|
12963
15034
|
const NOTE_MIN = 24;
|
|
15035
|
+
const ANSWER_MARK = "↳";
|
|
12964
15036
|
const OVERSCAN = 2;
|
|
12965
15037
|
const SIGN_WIDTH = 2;
|
|
12966
15038
|
const SCROLL_ROWS = 3;
|
|
15039
|
+
const PAN_COLUMNS = 8;
|
|
15040
|
+
const WAYS = {
|
|
15041
|
+
up: {
|
|
15042
|
+
step: -1,
|
|
15043
|
+
across: false
|
|
15044
|
+
},
|
|
15045
|
+
down: {
|
|
15046
|
+
step: 1,
|
|
15047
|
+
across: false
|
|
15048
|
+
},
|
|
15049
|
+
left: {
|
|
15050
|
+
step: -1,
|
|
15051
|
+
across: true
|
|
15052
|
+
},
|
|
15053
|
+
right: {
|
|
15054
|
+
step: 1,
|
|
15055
|
+
across: true
|
|
15056
|
+
}
|
|
15057
|
+
};
|
|
15058
|
+
const notchesIn = (event) => Math.max(1, event.scroll?.delta ?? 1);
|
|
15059
|
+
const wheelTo = (event, handlers) => {
|
|
15060
|
+
const way = WAYS[event.scroll?.direction ?? ""];
|
|
15061
|
+
if (way === void 0) return;
|
|
15062
|
+
const step = way.step * notchesIn(event);
|
|
15063
|
+
if (way.across || event.modifiers?.shift === true) handlers.pan(step * PAN_COLUMNS);
|
|
15064
|
+
else handlers.scroll(step * SCROLL_ROWS);
|
|
15065
|
+
};
|
|
12967
15066
|
const SIGNS = {
|
|
12968
15067
|
added: {
|
|
12969
15068
|
text: " +",
|
|
@@ -12990,6 +15089,8 @@ var DiffView = class {
|
|
|
12990
15089
|
display = [];
|
|
12991
15090
|
starts = /* @__PURE__ */ new Map();
|
|
12992
15091
|
fitted = 1;
|
|
15092
|
+
wrapped = false;
|
|
15093
|
+
held = 0;
|
|
12993
15094
|
constructor(renderer) {
|
|
12994
15095
|
this.code = new CodeRenderable(renderer, {
|
|
12995
15096
|
id: "diff-code",
|
|
@@ -13056,10 +15157,7 @@ var DiffView = class {
|
|
|
13056
15157
|
return this.numbers;
|
|
13057
15158
|
}
|
|
13058
15159
|
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
|
-
};
|
|
15160
|
+
this.numbers.onMouseScroll = (event) => wheelTo(event, handlers);
|
|
13063
15161
|
this.numbers.onMouseDown = (event) => handlers.down(event.y);
|
|
13064
15162
|
this.numbers.onMouseDrag = (event) => handlers.drag(event.y);
|
|
13065
15163
|
this.numbers.onMouseDragEnd = (event) => handlers.dragEnd(event.y);
|
|
@@ -13085,36 +15183,114 @@ var DiffView = class {
|
|
|
13085
15183
|
rows() {
|
|
13086
15184
|
return this.fitted;
|
|
13087
15185
|
}
|
|
13088
|
-
show(patch, notes) {
|
|
13089
|
-
const room = notes.length === 0 ? NOTE_MIN : this.noteRoom();
|
|
13090
|
-
const key =
|
|
15186
|
+
show(patch, notes, gaps, prose = []) {
|
|
15187
|
+
const room = notes.length === 0 && prose.length === 0 ? NOTE_MIN : this.noteRoom();
|
|
15188
|
+
const key = keyOf(room, notes, prose);
|
|
13091
15189
|
if (patch === this.shown && key === this.noted) return;
|
|
13092
15190
|
this.pinnedText = "";
|
|
13093
15191
|
this.shown = patch;
|
|
13094
15192
|
this.noted = key;
|
|
13095
|
-
this.display = layout(
|
|
13096
|
-
|
|
13097
|
-
|
|
15193
|
+
this.display = layout({
|
|
15194
|
+
patch,
|
|
15195
|
+
notes,
|
|
15196
|
+
room,
|
|
15197
|
+
gaps,
|
|
15198
|
+
prose
|
|
15199
|
+
});
|
|
15200
|
+
this.starts = startsOf(this.display);
|
|
13098
15201
|
this.code.filetype = pathToFiletype(patch.path) ?? "text";
|
|
13099
|
-
this.
|
|
15202
|
+
this.feed();
|
|
13100
15203
|
this.numbers.setLineNumbers(lineNumbers(patch, this.display));
|
|
13101
|
-
this.numbers.setHideLineNumbers(
|
|
15204
|
+
this.numbers.setHideLineNumbers(bareOf(this.display));
|
|
13102
15205
|
this.numbers.setLineSigns(lineSigns(patch, this.display));
|
|
13103
15206
|
this.numbers.setLineColors(/* @__PURE__ */ new Map());
|
|
13104
|
-
|
|
15207
|
+
}
|
|
15208
|
+
feed() {
|
|
15209
|
+
const spans = noteSpans(this.display, this.held);
|
|
15210
|
+
this.code.content = textAt(this.display, this.held);
|
|
13105
15211
|
this.code.onHighlight = (highlights) => [...highlights.filter((highlight) => !spans.some(([from, to]) => highlight[0] < to && highlight[1] > from)), ...spans];
|
|
13106
15212
|
}
|
|
13107
|
-
|
|
13108
|
-
|
|
15213
|
+
setWrap(on) {
|
|
15214
|
+
if (on !== this.wrapped) {
|
|
15215
|
+
this.wrapped = on;
|
|
15216
|
+
this.code.wrapMode = on ? "word" : "none";
|
|
15217
|
+
this.code.requestRender();
|
|
15218
|
+
this.numbers.requestRender();
|
|
15219
|
+
}
|
|
15220
|
+
this.fitWrapWidth();
|
|
15221
|
+
}
|
|
15222
|
+
setPan(columns) {
|
|
15223
|
+
const wanted = this.wrapped ? 0 : Math.max(0, Math.min(this.code.maxScrollX, columns));
|
|
15224
|
+
if (wanted !== this.held) {
|
|
15225
|
+
this.held = wanted;
|
|
15226
|
+
this.feed();
|
|
15227
|
+
}
|
|
15228
|
+
if (this.code.scrollX !== wanted) this.code.scrollX = wanted;
|
|
15229
|
+
if (this.pinned.scrollX !== wanted) this.pinned.scrollX = wanted;
|
|
15230
|
+
}
|
|
15231
|
+
panned() {
|
|
15232
|
+
return this.code.scrollX;
|
|
15233
|
+
}
|
|
15234
|
+
fitWrapWidth() {
|
|
15235
|
+
const room = this.numbers.width - Math.max(0, this.code.x - this.numbers.x);
|
|
15236
|
+
const wanted = this.wrapped && room > 0 ? room : "100%";
|
|
15237
|
+
if (this.code.width !== wanted) this.code.width = wanted;
|
|
15238
|
+
}
|
|
15239
|
+
sources() {
|
|
15240
|
+
const reported = this.code.lineInfo?.lineSources;
|
|
15241
|
+
return this.wrapped && reported !== void 0 && reported.length > 0 ? reported : [];
|
|
15242
|
+
}
|
|
15243
|
+
lineAt(visual) {
|
|
15244
|
+
const sources = this.sources();
|
|
15245
|
+
if (sources.length === 0) return visual;
|
|
15246
|
+
return sources[Math.max(0, Math.min(sources.length - 1, visual))] ?? visual;
|
|
15247
|
+
}
|
|
15248
|
+
visualOf(line) {
|
|
15249
|
+
const sources = this.sources();
|
|
15250
|
+
if (sources.length === 0) return line;
|
|
15251
|
+
let low = 0;
|
|
15252
|
+
let high = sources.length;
|
|
15253
|
+
while (low < high) {
|
|
15254
|
+
const mid = low + high >> 1;
|
|
15255
|
+
if ((sources[mid] ?? 0) < line) low = mid + 1;
|
|
15256
|
+
else high = mid;
|
|
15257
|
+
}
|
|
15258
|
+
return low;
|
|
15259
|
+
}
|
|
15260
|
+
tallest() {
|
|
15261
|
+
return this.sources().length === 0 ? this.display.length : this.sources().length;
|
|
15262
|
+
}
|
|
15263
|
+
drawn() {
|
|
15264
|
+
return this.tallest();
|
|
15265
|
+
}
|
|
15266
|
+
rowAt(visual) {
|
|
15267
|
+
const line = this.lineAt(visual);
|
|
15268
|
+
const at = Math.max(0, Math.min(this.display.length - 1, line));
|
|
13109
15269
|
return this.display[at]?.row ?? 0;
|
|
13110
15270
|
}
|
|
13111
|
-
|
|
13112
|
-
return this.display[
|
|
15271
|
+
stopAt(visual) {
|
|
15272
|
+
return this.display[this.lineAt(visual)]?.stop ?? 0;
|
|
15273
|
+
}
|
|
15274
|
+
carries(visual) {
|
|
15275
|
+
const entry = this.display[this.lineAt(visual)];
|
|
15276
|
+
if (entry === void 0) return false;
|
|
15277
|
+
if (entry.prose) return false;
|
|
15278
|
+
return true;
|
|
15279
|
+
}
|
|
15280
|
+
isComment(visual) {
|
|
15281
|
+
const entry = this.display[this.lineAt(visual)];
|
|
15282
|
+
return entry?.comment === true || entry?.prose === true;
|
|
15283
|
+
}
|
|
15284
|
+
isRunOn(visual) {
|
|
15285
|
+
const sources = this.sources();
|
|
15286
|
+
if (sources.length === 0) return false;
|
|
15287
|
+
return visual > 0 && sources[visual] === sources[visual - 1];
|
|
13113
15288
|
}
|
|
13114
15289
|
scrollTo(row, cursor) {
|
|
13115
|
-
const highest = Math.max(0, this.
|
|
13116
|
-
const wanted = this.starts.get(row) ?? row;
|
|
13117
|
-
const
|
|
15290
|
+
const highest = Math.max(0, this.tallest() - this.rows());
|
|
15291
|
+
const wanted = this.visualOf(this.starts.get(row) ?? row);
|
|
15292
|
+
const line = this.starts.get(cursor);
|
|
15293
|
+
const at = line === void 0 ? void 0 : this.visualOf(line);
|
|
13118
15294
|
const kept = cursor >= row && cursor < row + this.rows() && at !== void 0 ? Math.max(wanted, at - this.rows() + 1) : wanted;
|
|
13119
15295
|
const clamped = Math.max(0, Math.min(highest, kept));
|
|
13120
15296
|
if (this.code.scrollY !== clamped) this.code.scrollY = clamped;
|
|
@@ -13122,11 +15298,12 @@ var DiffView = class {
|
|
|
13122
15298
|
}
|
|
13123
15299
|
paint(paintOf, from, rows) {
|
|
13124
15300
|
const colors = /* @__PURE__ */ new Map();
|
|
13125
|
-
const
|
|
13126
|
-
|
|
15301
|
+
const first = this.lineAt(Math.max(0, from - OVERSCAN));
|
|
15302
|
+
const last = Math.min(this.display.length, this.lineAt(from + rows + OVERSCAN) + 1);
|
|
15303
|
+
for (let index = first; index < last; index++) {
|
|
13127
15304
|
const entry = this.display[index];
|
|
13128
15305
|
if (entry === void 0) continue;
|
|
13129
|
-
const paint = entry.comment ? NOTE_PAINT : paintOf(entry.row);
|
|
15306
|
+
const paint = entry.comment || entry.prose ? NOTE_PAINT : paintOf(entry.row);
|
|
13130
15307
|
if (paint !== void 0) colors.set(index, paint);
|
|
13131
15308
|
}
|
|
13132
15309
|
this.numbers.setLineColors(colors);
|
|
@@ -13135,19 +15312,39 @@ var DiffView = class {
|
|
|
13135
15312
|
return WASH[kind];
|
|
13136
15313
|
}
|
|
13137
15314
|
};
|
|
13138
|
-
const
|
|
15315
|
+
const startsOf = (display) => {
|
|
15316
|
+
const starts = /* @__PURE__ */ new Map();
|
|
15317
|
+
for (const [index, entry] of display.entries()) if (!entry.comment && !starts.has(entry.row)) starts.set(entry.row, index);
|
|
15318
|
+
return starts;
|
|
15319
|
+
};
|
|
15320
|
+
const bareOf = (display) => new Set(display.flatMap((entry, index) => entry.comment || entry.gap || entry.prose ? [index] : []));
|
|
15321
|
+
const keyOf = (room, notes, prose) => [
|
|
15322
|
+
room,
|
|
15323
|
+
...notes.map((note) => `${note.side}${note.line}:${note.folded ? "-" : "+"}${note.body}`),
|
|
15324
|
+
...prose.map((entry) => `p${entry.line}${entry.after ? ">" : "<"}:${entry.markdown}`)
|
|
15325
|
+
].join("\0");
|
|
15326
|
+
const groupOf = (entry) => {
|
|
15327
|
+
if (entry.prose) return "prose";
|
|
15328
|
+
if (entry.gap) return "gap";
|
|
15329
|
+
if (!entry.comment) return void 0;
|
|
15330
|
+
if (entry.label) return "note.label";
|
|
15331
|
+
return entry.sent ? "note.sent" : "note";
|
|
15332
|
+
};
|
|
15333
|
+
const isChrome = (entry) => entry.comment || entry.gap || entry.prose;
|
|
15334
|
+
const heldAt = (entry, pan) => isChrome(entry) && pan > 0 ? `${" ".repeat(pan)}${entry.text}` : entry.text;
|
|
15335
|
+
const textAt = (display, pan) => display.map((entry) => heldAt(entry, pan)).join("\n");
|
|
15336
|
+
const noteSpans = (display, pan) => {
|
|
13139
15337
|
const spans = [];
|
|
13140
15338
|
let at = 0;
|
|
13141
15339
|
for (const entry of display) {
|
|
13142
|
-
|
|
13143
|
-
|
|
13144
|
-
|
|
13145
|
-
|
|
13146
|
-
|
|
13147
|
-
|
|
13148
|
-
|
|
13149
|
-
|
|
13150
|
-
at += entry.text.length + 1;
|
|
15340
|
+
const group = groupOf(entry);
|
|
15341
|
+
const width = heldAt(entry, pan).length;
|
|
15342
|
+
if (group !== void 0) spans.push([
|
|
15343
|
+
at,
|
|
15344
|
+
at + width,
|
|
15345
|
+
group
|
|
15346
|
+
]);
|
|
15347
|
+
at += width + 1;
|
|
13151
15348
|
}
|
|
13152
15349
|
return spans;
|
|
13153
15350
|
};
|
|
@@ -13166,50 +15363,92 @@ const wrap = (text, room) => {
|
|
|
13166
15363
|
}
|
|
13167
15364
|
return lines;
|
|
13168
15365
|
};
|
|
13169
|
-
const
|
|
13170
|
-
const
|
|
15366
|
+
const headOf = (note) => {
|
|
15367
|
+
const moved = note.stale ? ", the branch moved on" : "";
|
|
15368
|
+
if (note.settled) return `${marks().sent} settled${moved}`;
|
|
15369
|
+
if (note.asks) return `${marks().staged} asked back${moved}`;
|
|
15370
|
+
if (note.answers.length > 0) return `${marks().sent} answered${moved}`;
|
|
15371
|
+
if (note.sent) return `${marks().sent} sent${moved}`;
|
|
15372
|
+
return `${marks().staged} staged`;
|
|
15373
|
+
};
|
|
15374
|
+
const spokenLines = (body, room) => {
|
|
15375
|
+
return wrap(body.replaceAll("\n", " "), Math.max(NOTE_MIN, room - 2)).map((text, at) => at === 0 ? `${ANSWER_MARK} ${text}` : ` ${text}`);
|
|
15376
|
+
};
|
|
15377
|
+
const answerLines = (note, room) => note.answers.flatMap((body) => spokenLines(body, room));
|
|
15378
|
+
const noteLines = (note, room) => note.folded ? [`${headOf(note)} · press l`] : [
|
|
15379
|
+
headOf(note),
|
|
15380
|
+
...note.body.split("\n").flatMap((line) => wrap(line, room)),
|
|
15381
|
+
...answerLines(note, room)
|
|
15382
|
+
];
|
|
15383
|
+
const noteRows = (note, row, room, stop) => noteLines(note, room).map((line, index) => ({
|
|
13171
15384
|
text: `${marks().rule} ${line}`,
|
|
13172
15385
|
row,
|
|
15386
|
+
stop,
|
|
13173
15387
|
comment: true,
|
|
13174
15388
|
sent: note.sent,
|
|
13175
|
-
label: index === 0
|
|
15389
|
+
label: index === 0,
|
|
15390
|
+
gap: false,
|
|
15391
|
+
prose: false
|
|
13176
15392
|
}));
|
|
13177
|
-
const
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13189
|
-
return
|
|
13190
|
-
|
|
15393
|
+
const proseRows = (entry, row, room) => [...entry.markdown.split("\n").flatMap((line) => wrap(line, room - 2)), ""].map((line) => ({
|
|
15394
|
+
text: line.length === 0 ? "" : ` ${line}`,
|
|
15395
|
+
row,
|
|
15396
|
+
stop: 0,
|
|
15397
|
+
comment: false,
|
|
15398
|
+
sent: false,
|
|
15399
|
+
label: false,
|
|
15400
|
+
gap: false,
|
|
15401
|
+
prose: true
|
|
15402
|
+
}));
|
|
15403
|
+
const proseAt = (plan, row, after) => {
|
|
15404
|
+
const line = sideLineOf(row, "new");
|
|
15405
|
+
if (line === void 0) return [];
|
|
15406
|
+
return plan.prose.filter((entry) => entry.after === after && entry.line === line);
|
|
15407
|
+
};
|
|
15408
|
+
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));
|
|
15409
|
+
const codeRow = (plan, row) => ({
|
|
15410
|
+
text: row.text,
|
|
15411
|
+
row: row.index,
|
|
15412
|
+
stop: 0,
|
|
15413
|
+
comment: false,
|
|
15414
|
+
sent: false,
|
|
15415
|
+
label: false,
|
|
15416
|
+
gap: plan.gaps.has(row.index),
|
|
15417
|
+
prose: false
|
|
15418
|
+
});
|
|
15419
|
+
const rowsFor = (plan, row) => [
|
|
15420
|
+
...proseAt(plan, row, false).flatMap((entry) => proseRows(entry, row.index, plan.room)),
|
|
15421
|
+
codeRow(plan, row),
|
|
15422
|
+
...notesAt(plan, row),
|
|
15423
|
+
...proseAt(plan, row, true).flatMap((entry) => proseRows(entry, row.index, plan.room))
|
|
15424
|
+
];
|
|
15425
|
+
const layout = (plan) => plan.patch.rows.flatMap((row) => rowsFor(plan, row));
|
|
13191
15426
|
const lineNumbers = (patch, display) => {
|
|
13192
15427
|
const numbers = /* @__PURE__ */ new Map();
|
|
13193
15428
|
const rows = new Map(patch.rows.map((row) => [row.index, row]));
|
|
13194
15429
|
for (const [index, entry] of display.entries()) {
|
|
13195
|
-
const row = entry.comment ? void 0 : rows.get(entry.row);
|
|
15430
|
+
const row = entry.comment || entry.prose ? void 0 : rows.get(entry.row);
|
|
13196
15431
|
const line = row === void 0 ? void 0 : numberFor(row);
|
|
13197
15432
|
if (line !== void 0) numbers.set(index, line);
|
|
13198
15433
|
}
|
|
13199
15434
|
return numbers;
|
|
13200
15435
|
};
|
|
15436
|
+
const BARE_SIGN = {
|
|
15437
|
+
after: " ",
|
|
15438
|
+
afterColor: palette.accent
|
|
15439
|
+
};
|
|
15440
|
+
const signFor = (entry, rows) => {
|
|
15441
|
+
if (entry.comment || entry.prose) return BARE_SIGN;
|
|
15442
|
+
const row = rows.get(entry.row);
|
|
15443
|
+
const sign = row === void 0 ? void 0 : SIGNS[row.kind];
|
|
15444
|
+
return sign === void 0 ? BARE_SIGN : {
|
|
15445
|
+
after: sign.text,
|
|
15446
|
+
afterColor: sign.color
|
|
15447
|
+
};
|
|
15448
|
+
};
|
|
13201
15449
|
const lineSigns = (patch, display) => {
|
|
13202
|
-
const signs = /* @__PURE__ */ new Map();
|
|
13203
15450
|
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;
|
|
15451
|
+
return new Map(display.map((entry, index) => [index, signFor(entry, rows)]));
|
|
13213
15452
|
};
|
|
13214
15453
|
const sideLineOf = (row, side) => getOrUndefined$1(lineOn(row, side));
|
|
13215
15454
|
//#endregion
|
|
@@ -13222,6 +15461,8 @@ const FRAME_PAD = 1;
|
|
|
13222
15461
|
const MODAL_ROOM = 8;
|
|
13223
15462
|
const COMPOSE_CHROME = 3;
|
|
13224
15463
|
const COMPOSE_ACTION_ROWS = 2;
|
|
15464
|
+
const COMPOSE_PAD = 5;
|
|
15465
|
+
const COMPOSE_MIN_TEXT = 8;
|
|
13225
15466
|
const reportActions = () => t`${fg(palette.accent)("esc")} ${fg(palette.muted)("cancel")} ${fg(palette.accent)("^s")} ${fg(palette.muted)("copy and save")}`;
|
|
13226
15467
|
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
15468
|
const SNIPPET_LINES = 4;
|
|
@@ -13238,7 +15479,7 @@ const PANE_CHROME = 3;
|
|
|
13238
15479
|
const BRANCH_WIDTH = 82;
|
|
13239
15480
|
const BRANCH_NAME = 44;
|
|
13240
15481
|
const BRANCH_NAME_MIN = 12;
|
|
13241
|
-
const BRANCH_TAIL =
|
|
15482
|
+
const BRANCH_TAIL = 45;
|
|
13242
15483
|
const MODAL_MARGIN = 4;
|
|
13243
15484
|
const bodyRoom = (width) => Math.max(0, width - 2 - BODY_BORDER);
|
|
13244
15485
|
const treeWidth = (width) => {
|
|
@@ -13248,6 +15489,17 @@ const treeWidth = (width) => {
|
|
|
13248
15489
|
};
|
|
13249
15490
|
const homeWidth = (width) => Math.max(0, Math.min(BRANCH_WIDTH, width - 2));
|
|
13250
15491
|
const modalWidth = (width, wanted) => Math.max(0, Math.min(wanted, width - MODAL_MARGIN));
|
|
15492
|
+
const composeRoom = (width) => {
|
|
15493
|
+
const box = modalWidth(width, COMPOSE_WIDTH);
|
|
15494
|
+
return {
|
|
15495
|
+
box,
|
|
15496
|
+
text: Math.max(COMPOSE_MIN_TEXT, box - COMPOSE_PAD)
|
|
15497
|
+
};
|
|
15498
|
+
};
|
|
15499
|
+
const laidOut = (lines, room) => lines.flatMap((line) => {
|
|
15500
|
+
const parts = wrapped(line, room);
|
|
15501
|
+
return parts.length === 0 ? [""] : parts;
|
|
15502
|
+
});
|
|
13251
15503
|
const STICKY_MAX = 4;
|
|
13252
15504
|
const pickPaint = (view, kind, flags) => {
|
|
13253
15505
|
if (flags.cursor) return {
|
|
@@ -13258,11 +15510,16 @@ const pickPaint = (view, kind, flags) => {
|
|
|
13258
15510
|
gutter: SELECTION,
|
|
13259
15511
|
content: SELECTION
|
|
13260
15512
|
};
|
|
15513
|
+
if (flags.gap) return GAP_PAINT;
|
|
13261
15514
|
return view.washOf(kind);
|
|
13262
15515
|
};
|
|
13263
15516
|
const SELECTION = RGBA.fromHex(palette.selection);
|
|
13264
15517
|
const CURSOR = RGBA.fromHex(palette.cursor);
|
|
13265
15518
|
const ACCENT = RGBA.fromHex(palette.accent);
|
|
15519
|
+
const GAP_PAINT = {
|
|
15520
|
+
gutter: RGBA.fromHex(palette.overlay),
|
|
15521
|
+
content: RGBA.fromHex(palette.overlay)
|
|
15522
|
+
};
|
|
13266
15523
|
const bar = (renderer, id, color) => new TextRenderable(renderer, {
|
|
13267
15524
|
id,
|
|
13268
15525
|
content: "",
|
|
@@ -13445,18 +15702,21 @@ const makeComposeParts = (renderer) => ({
|
|
|
13445
15702
|
title: new TextRenderable(renderer, {
|
|
13446
15703
|
id: "compose-title",
|
|
13447
15704
|
content: "",
|
|
13448
|
-
fg: palette.ink
|
|
15705
|
+
fg: palette.ink,
|
|
15706
|
+
wrapMode: "none"
|
|
13449
15707
|
}),
|
|
13450
15708
|
body: new TextRenderable(renderer, {
|
|
13451
15709
|
id: "compose-body",
|
|
13452
15710
|
content: "",
|
|
13453
|
-
fg: palette.ink
|
|
15711
|
+
fg: palette.ink,
|
|
15712
|
+
wrapMode: "none"
|
|
13454
15713
|
}),
|
|
13455
15714
|
actions: new TextRenderable(renderer, {
|
|
13456
15715
|
id: "compose-actions",
|
|
13457
15716
|
content: "",
|
|
13458
15717
|
fg: palette.muted,
|
|
13459
|
-
marginTop: 1
|
|
15718
|
+
marginTop: 1,
|
|
15719
|
+
wrapMode: "none"
|
|
13460
15720
|
})
|
|
13461
15721
|
});
|
|
13462
15722
|
const makeCompose = (renderer) => new BoxRenderable(renderer, {
|
|
@@ -13487,38 +15747,79 @@ const waitingLabel = (branch) => {
|
|
|
13487
15747
|
if (branch.staged > 0) return `${branch.staged} staged`;
|
|
13488
15748
|
return branch.unread > 0 ? `${branch.unread} unread` : "";
|
|
13489
15749
|
};
|
|
13490
|
-
const
|
|
15750
|
+
const inRange = (state, row, from, to) => state.selecting && row >= from && row <= to;
|
|
15751
|
+
const notesOf = (comments, path, sent, opened = []) => comments.filter((entry) => entry.file === path).map((entry) => ({
|
|
15752
|
+
id: entry.id ?? "",
|
|
15753
|
+
folded: entry.settled === true && !(entry.id !== void 0 && opened.includes(entry.id)),
|
|
13491
15754
|
side: entry.side,
|
|
13492
15755
|
line: entry.end,
|
|
13493
15756
|
body: entry.body,
|
|
13494
|
-
sent
|
|
15757
|
+
sent,
|
|
15758
|
+
settled: entry.settled === true,
|
|
15759
|
+
stale: entry.stale === true,
|
|
15760
|
+
asks: entry.asks === true,
|
|
15761
|
+
answers: entry.answers ?? []
|
|
13495
15762
|
}));
|
|
13496
|
-
const notesFor = (state, path) => [...notesOf(state.sent, path, true), ...notesOf(state.pending, path, false)];
|
|
15763
|
+
const notesFor = (state, path) => [...notesOf(state.sent, path, true, state.opened), ...notesOf(state.pending, path, false)];
|
|
15764
|
+
const paired = (chunks) => {
|
|
15765
|
+
const chips = [];
|
|
15766
|
+
for (let at = 0; at < chunks.length; at += CHIP_CHUNKS) chips.push(chunks.slice(at, at + CHIP_CHUNKS));
|
|
15767
|
+
return chips;
|
|
15768
|
+
};
|
|
15769
|
+
const keptWithin = (chunks, room) => {
|
|
15770
|
+
const kept = [];
|
|
15771
|
+
let used = 0;
|
|
15772
|
+
for (const chip of paired(chunks).toReversed()) {
|
|
15773
|
+
const width = chip.reduce((total, chunk) => total + chunk.text.length, 0);
|
|
15774
|
+
if (used + width > room) break;
|
|
15775
|
+
kept.unshift(chip);
|
|
15776
|
+
used += width;
|
|
15777
|
+
}
|
|
15778
|
+
return kept.flat();
|
|
15779
|
+
};
|
|
15780
|
+
const CHIP_CHUNKS = 3;
|
|
13497
15781
|
const shortPath = (path) => {
|
|
13498
15782
|
const home = process.env["HOME"] ?? "";
|
|
13499
15783
|
return home.length > 0 && path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
13500
15784
|
};
|
|
15785
|
+
const HOME_PATH_MIN = 24;
|
|
15786
|
+
const HOME_PATH_CHROME = 10;
|
|
15787
|
+
const elide = (path, room) => {
|
|
15788
|
+
if (path.length <= room) return path;
|
|
15789
|
+
const parts = path.split("/").filter((part) => part.length > 0);
|
|
15790
|
+
const lead = path.startsWith("~") ? "~" : "";
|
|
15791
|
+
const tail = parts.slice(-2).join("/");
|
|
15792
|
+
const middled = `${path.startsWith("/") ? `/${parts[0] ?? ""}` : lead}/…/${tail}`;
|
|
15793
|
+
return middled.length <= room ? middled : `…/${tail}`;
|
|
15794
|
+
};
|
|
13501
15795
|
const contextLabel = (context) => {
|
|
13502
15796
|
if (context === 3) return "";
|
|
13503
15797
|
return context >= 1e5 ? "whole file" : `±${context}`;
|
|
13504
15798
|
};
|
|
13505
15799
|
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}`;
|
|
15800
|
+
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
15801
|
const branchHeading = (room) => ` ${columns({
|
|
13508
15802
|
name: "WORKTREE",
|
|
13509
15803
|
files: "FILES",
|
|
13510
15804
|
added: "+",
|
|
13511
15805
|
gone: "-",
|
|
15806
|
+
layers: "LAYERS",
|
|
13512
15807
|
state: "STATE"
|
|
13513
15808
|
}, room)}`;
|
|
13514
15809
|
const atHome = (state) => state.screen === "branches" || state.screen === "palette" && state.returnTo === "branches";
|
|
15810
|
+
const layersCell = (branch) => {
|
|
15811
|
+
if (branch.layers === 0) return "";
|
|
15812
|
+
return branch.stale ? `${branch.layers} stale` : `${branch.layers} layers`;
|
|
15813
|
+
};
|
|
15814
|
+
const stateCell = (state, branch) => [state.pulls[branch.branch] ?? "", waitingLabel(branch).trim()].filter((part) => part.length > 0).join(" ");
|
|
13515
15815
|
const branchCells = (branch, here, room) => ({
|
|
13516
15816
|
lead: `${here ? marks().cursor : " "} `,
|
|
13517
15817
|
name: clip(branch.branch, room).padEnd(room),
|
|
13518
15818
|
files: `${branch.files}`.padStart(5),
|
|
13519
15819
|
added: `+${branch.added}`.padStart(8),
|
|
13520
15820
|
gone: `-${branch.removed}`.padStart(8),
|
|
13521
|
-
|
|
15821
|
+
layers: layersCell(branch),
|
|
15822
|
+
state: ""
|
|
13522
15823
|
});
|
|
13523
15824
|
const headerParts = (state, branch, path) => [
|
|
13524
15825
|
branch,
|
|
@@ -13527,7 +15828,8 @@ const headerParts = (state, branch, path) => [
|
|
|
13527
15828
|
state.vouched.length === 0 ? "" : reviewedCount(state),
|
|
13528
15829
|
state.staged === 0 ? "" : `${state.staged} staged`,
|
|
13529
15830
|
contextLabel(state.context),
|
|
13530
|
-
hiddenLines(state) === 0 ? "" : `⋯ ${hiddenLines(state)} lines hidden
|
|
15831
|
+
hiddenLines(state) === 0 ? "" : `⋯ ${hiddenLines(state)} lines hidden`,
|
|
15832
|
+
state.pan === 0 ? "" : `→ ${state.pan} columns`
|
|
13531
15833
|
];
|
|
13532
15834
|
const fallbackScope = (state, top) => {
|
|
13533
15835
|
const scope = (selectedPatch(state)?.hunks.findLast((hunk) => hunk.startRow < top))?.scope ?? "";
|
|
@@ -13547,14 +15849,35 @@ const treeLine = (state, row, pane) => {
|
|
|
13547
15849
|
return `${treeMarks(state, row)}${clip(treeLabel(state, row), room).padEnd(room)}${tail}`;
|
|
13548
15850
|
};
|
|
13549
15851
|
const STEP_NUMBER = 3;
|
|
13550
|
-
const
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
const
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
15852
|
+
const STEP_LEAD = 8;
|
|
15853
|
+
const NOTE_LEAD = 10;
|
|
15854
|
+
const STEP_GAP = 1;
|
|
15855
|
+
const layerRoom = (state, pane) => {
|
|
15856
|
+
const tally = Math.max(1, ...state.layers.map((layer) => `${layer.files.length}`.length));
|
|
15857
|
+
return {
|
|
15858
|
+
title: Math.max(4, pane - PANE_CHROME - STEP_LEAD - STEP_GAP - tally),
|
|
15859
|
+
note: Math.max(4, pane - PANE_CHROME - NOTE_LEAD),
|
|
15860
|
+
tally
|
|
15861
|
+
};
|
|
15862
|
+
};
|
|
15863
|
+
const layerFold = (state, index) => {
|
|
15864
|
+
if (layerOpen(state, index)) return "▾";
|
|
15865
|
+
return (state.layers[index]?.note ?? "").length === 0 ? " " : "▸";
|
|
15866
|
+
};
|
|
15867
|
+
const layerHead = (state, row) => {
|
|
15868
|
+
if (!row.lead) return " ".repeat(STEP_LEAD);
|
|
15869
|
+
return `${row.index === state.layerIndex ? state.focus === "tree" ? "▸" : "·" : " "} ${layerFold(state, row.index)} ${`${row.index + 1}.`.padStart(STEP_NUMBER)} `;
|
|
15870
|
+
};
|
|
15871
|
+
const layerText = (state, row, room) => {
|
|
15872
|
+
if (row.kind === "file") return `${" ".repeat(NOTE_LEAD)}${marks().file} ${row.text}`;
|
|
15873
|
+
if (row.kind === "note") return `${" ".repeat(NOTE_LEAD)}${row.text}`;
|
|
15874
|
+
const tail = (row.lead ? `${state.layers[row.index]?.files.length ?? 0}` : "").padStart(room.tally + STEP_GAP);
|
|
15875
|
+
return `${layerHead(state, row)}${row.text.padEnd(room.title)}${tail}`;
|
|
15876
|
+
};
|
|
15877
|
+
const layerPaint = (state, row) => {
|
|
15878
|
+
if (row.kind === "file") return palette.ink;
|
|
15879
|
+
if (row.kind === "note") return palette.faint;
|
|
15880
|
+
return row.index === state.layerIndex ? palette.ink : palette.muted;
|
|
13558
15881
|
};
|
|
13559
15882
|
var Screen = class {
|
|
13560
15883
|
header;
|
|
@@ -13632,6 +15955,7 @@ var Screen = class {
|
|
|
13632
15955
|
this.mouse = mouse;
|
|
13633
15956
|
this.view.listenTo({
|
|
13634
15957
|
scroll: (delta) => this.mouse?.onScroll(delta),
|
|
15958
|
+
pan: (delta) => this.mouse?.onPan(delta),
|
|
13635
15959
|
down: (y) => {
|
|
13636
15960
|
this.dragFrom = this.rowAtY(y);
|
|
13637
15961
|
this.mouse?.onDrag(this.dragFrom, this.dragFrom, false);
|
|
@@ -13658,13 +15982,15 @@ var Screen = class {
|
|
|
13658
15982
|
}
|
|
13659
15983
|
update(state) {
|
|
13660
15984
|
this.shown = state;
|
|
13661
|
-
this.chips = hintsFor(state.screen, state.staged);
|
|
15985
|
+
this.chips = hintsFor(state.screen, state.staged, state.layers.length);
|
|
13662
15986
|
this.header.content = this.headerText(state);
|
|
13663
15987
|
this.footer.content = this.footerText(state);
|
|
13664
15988
|
this.list.content = this.listText(state);
|
|
13665
15989
|
const many = state.branches.length === 1 ? "1 worktree" : `${state.branches.length} worktrees`;
|
|
13666
|
-
|
|
13667
|
-
|
|
15990
|
+
const pane = homeWidth(this.renderer.width);
|
|
15991
|
+
const room = Math.max(HOME_PATH_MIN, pane - many.length - HOME_PATH_CHROME);
|
|
15992
|
+
this.landing.content = `${elide(shortPath(this.repo), room)} · ${many}`;
|
|
15993
|
+
this.landingKeys.content = this.homeKeys(state);
|
|
13668
15994
|
this.diffPane.visible = state.screen !== "branches" && !(state.screen === "palette" && state.returnTo === "branches");
|
|
13669
15995
|
if (this.diffPane.visible) this.paintDiff(state);
|
|
13670
15996
|
this.paintPane(state);
|
|
@@ -13708,10 +16034,16 @@ var Screen = class {
|
|
|
13708
16034
|
const readout = selectionReadout(state);
|
|
13709
16035
|
this.lead = readout.length === 0 ? 0 : readout.length + 3;
|
|
13710
16036
|
const lead = readout.length === 0 ? [] : [fg(palette.muted)(`${readout} `)];
|
|
13711
|
-
const
|
|
16037
|
+
const said = state.notice.length === 0 ? state.waiting : state.notice;
|
|
16038
|
+
const tail = said.length === 0 ? "" : ` ${said}`;
|
|
16039
|
+
const width = this.footer.width > 0 ? this.footer.width : this.renderer.width;
|
|
16040
|
+
const room = Math.max(0, width - this.lead - tail.length);
|
|
16041
|
+
const chips = keptWithin(this.chipRow().chunks, room);
|
|
16042
|
+
const colour = state.notice.length === 0 ? palette.accent : palette.attention;
|
|
16043
|
+
const notice = tail.length === 0 ? [] : [fg(colour)(tail)];
|
|
13712
16044
|
return new StyledText([
|
|
13713
16045
|
...lead,
|
|
13714
|
-
...
|
|
16046
|
+
...chips,
|
|
13715
16047
|
...notice
|
|
13716
16048
|
]);
|
|
13717
16049
|
}
|
|
@@ -13720,7 +16052,7 @@ var Screen = class {
|
|
|
13720
16052
|
}
|
|
13721
16053
|
listText(state) {
|
|
13722
16054
|
if (atHome(state)) return this.branchTable(state);
|
|
13723
|
-
if (
|
|
16055
|
+
if (onLayers(state)) return this.layerRail(state);
|
|
13724
16056
|
const height = Math.max(1, this.listPane.height - 1);
|
|
13725
16057
|
const pane = this.paneRoom();
|
|
13726
16058
|
const window = treeWindow(state, height);
|
|
@@ -13728,23 +16060,27 @@ var Screen = class {
|
|
|
13728
16060
|
const more = window.more > 0 ? [fg(palette.faint)(` … ${window.more} more`)] : [];
|
|
13729
16061
|
return new StyledText([...rows, ...more]);
|
|
13730
16062
|
}
|
|
13731
|
-
|
|
16063
|
+
layerRail(state) {
|
|
13732
16064
|
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
|
-
});
|
|
16065
|
+
const room = layerRoom(state, this.paneRoom());
|
|
16066
|
+
const window = railWindow(layerRows(state, room.title, room.note), height, state.layerIndex);
|
|
16067
|
+
const rows = window.rows.map((row) => fg(layerPaint(state, row))(`${layerText(state, row, room)}\n`));
|
|
13740
16068
|
const more = window.more > 0 ? [fg(palette.faint)(` … ${window.more} more`)] : [];
|
|
13741
|
-
|
|
16069
|
+
const warn = state.layersStale ? [fg(palette.attention)(` stale, the branch moved on\n\n`)] : [];
|
|
16070
|
+
return new StyledText([
|
|
16071
|
+
...warn,
|
|
16072
|
+
...rows,
|
|
16073
|
+
...more
|
|
16074
|
+
]);
|
|
13742
16075
|
}
|
|
13743
16076
|
paintDiff(state) {
|
|
13744
|
-
const
|
|
13745
|
-
if (
|
|
16077
|
+
const shown = shownOf(state);
|
|
16078
|
+
if (shown === void 0) return;
|
|
16079
|
+
const patch = shown.patch;
|
|
13746
16080
|
this.paintSticky(state, state.top);
|
|
13747
|
-
this.view.
|
|
16081
|
+
this.view.setWrap(state.wrap);
|
|
16082
|
+
this.view.setPan(state.pan);
|
|
16083
|
+
this.view.show(patch, notesFor(state, patch.path), gapRowSet(shown), proseFor(state, patch.path));
|
|
13748
16084
|
this.view.fit(this.diffScroll.height);
|
|
13749
16085
|
const height = this.view.rows();
|
|
13750
16086
|
const top = this.view.scrollTo(state.top, state.cursor);
|
|
@@ -13828,7 +16164,8 @@ var Screen = class {
|
|
|
13828
16164
|
fg(palette.faint)(cells.files),
|
|
13829
16165
|
fg(palette.added)(cells.added),
|
|
13830
16166
|
fg(palette.removed)(cells.gone),
|
|
13831
|
-
fg(palette.
|
|
16167
|
+
fg(palette.accent)(` ${cells.layers.padStart(8)}`),
|
|
16168
|
+
fg(palette.attention)(` ${stateCell(state, branch)}\n`)
|
|
13832
16169
|
];
|
|
13833
16170
|
});
|
|
13834
16171
|
return new StyledText([...heading, ...rows]);
|
|
@@ -13846,10 +16183,23 @@ var Screen = class {
|
|
|
13846
16183
|
this.landingKeys.content = this.chipRow();
|
|
13847
16184
|
if (this.shown !== void 0) this.footer.content = this.footerText(this.shown);
|
|
13848
16185
|
}
|
|
16186
|
+
homeKeys(state) {
|
|
16187
|
+
const chips = this.chipRow().chunks;
|
|
16188
|
+
const said = state.notice.length === 0 ? state.waiting : state.notice;
|
|
16189
|
+
if (said.length === 0) return new StyledText(chips);
|
|
16190
|
+
const colour = state.notice.length === 0 ? palette.accent : palette.attention;
|
|
16191
|
+
return new StyledText([...chips, fg(colour)(` ${said}`)]);
|
|
16192
|
+
}
|
|
13849
16193
|
chipRow() {
|
|
13850
16194
|
return new StyledText(this.chips.flatMap((chip, index) => {
|
|
13851
|
-
const
|
|
13852
|
-
|
|
16195
|
+
const lit = index === this.hovered;
|
|
16196
|
+
const key = fg(palette.ink)(chip.key);
|
|
16197
|
+
const hint = fg(lit ? palette.ink : palette.faint)(` ${chip.hint}`);
|
|
16198
|
+
return [
|
|
16199
|
+
lit ? bg(palette.cursor)(key) : key,
|
|
16200
|
+
lit ? bg(palette.cursor)(hint) : hint,
|
|
16201
|
+
fg(palette.faint)(" ")
|
|
16202
|
+
];
|
|
13853
16203
|
}));
|
|
13854
16204
|
}
|
|
13855
16205
|
paintPane(state) {
|
|
@@ -13883,28 +16233,33 @@ var Screen = class {
|
|
|
13883
16233
|
paintReport(state) {
|
|
13884
16234
|
this.compose.visible = state.screen === "compose" || state.screen === "report";
|
|
13885
16235
|
if (state.screen !== "report") return;
|
|
13886
|
-
const
|
|
16236
|
+
const room = composeRoom(this.renderer.width);
|
|
16237
|
+
const lines = laidOut([
|
|
13887
16238
|
"What went wrong? Everything on screen is attached for you.",
|
|
13888
16239
|
"",
|
|
13889
16240
|
`${state.draft}▌`
|
|
13890
|
-
];
|
|
16241
|
+
], room.text);
|
|
13891
16242
|
this.composeTitle.content = "Report a bug";
|
|
13892
16243
|
this.composeBody.content = lines.join("\n");
|
|
13893
16244
|
this.composeActions.content = reportActions();
|
|
13894
|
-
const room = modalWidth(this.renderer.width, COMPOSE_WIDTH);
|
|
13895
16245
|
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));
|
|
16246
|
+
this.compose.width = room.box;
|
|
16247
|
+
this.compose.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room.box) / 2));
|
|
13898
16248
|
this.compose.top = Math.max(2, Math.floor(this.renderer.height / 4));
|
|
13899
16249
|
}
|
|
13900
16250
|
paintGutter(state, top, height) {
|
|
13901
16251
|
const [from, to] = selectionRange(state);
|
|
13902
16252
|
const marked = markedRows(state);
|
|
13903
|
-
const
|
|
13904
|
-
|
|
13905
|
-
|
|
13906
|
-
|
|
13907
|
-
|
|
16253
|
+
const drawn = this.view.drawn();
|
|
16254
|
+
const bare = (visual) => visual >= drawn || !this.view.carries(visual) || this.view.isRunOn(visual);
|
|
16255
|
+
const held = (visual) => {
|
|
16256
|
+
const row = this.view.rowAt(visual);
|
|
16257
|
+
const onCode = this.view.stopAt(visual) === 0;
|
|
16258
|
+
const standing = row === state.cursor && this.view.stopAt(visual) === state.stop;
|
|
16259
|
+
const within = onCode && inRange(state, row, from, to);
|
|
16260
|
+
return `${standing || within ? marks().cursor : " "}${onCode && marked.has(row) ? marks().comment : " "}`;
|
|
16261
|
+
};
|
|
16262
|
+
const rows = Array.from({ length: height }, (_, index) => bare(top + index) ? " " : held(top + index));
|
|
13908
16263
|
this.gutter.content = rows.join("\n");
|
|
13909
16264
|
}
|
|
13910
16265
|
paintSticky(state, top) {
|
|
@@ -13915,13 +16270,16 @@ var Screen = class {
|
|
|
13915
16270
|
linePaint(state) {
|
|
13916
16271
|
const [from, to] = selectionRange(state);
|
|
13917
16272
|
const selecting = state.selecting || state.screen === "compose";
|
|
13918
|
-
const
|
|
16273
|
+
const shown = shownOf(state);
|
|
16274
|
+
const rows = shown?.patch.rows ?? [];
|
|
16275
|
+
const gaps = shown === void 0 ? /* @__PURE__ */ new Set() : gapRowSet(shown);
|
|
13919
16276
|
return (row) => {
|
|
13920
16277
|
const kind = rows[row]?.kind;
|
|
13921
16278
|
if (kind === void 0) return void 0;
|
|
13922
16279
|
return pickPaint(this.view, kind, {
|
|
13923
16280
|
cursor: row === state.cursor,
|
|
13924
|
-
selected: selecting && row >= from && row <= to
|
|
16281
|
+
selected: selecting && row >= from && row <= to,
|
|
16282
|
+
gap: gaps.has(row)
|
|
13925
16283
|
});
|
|
13926
16284
|
};
|
|
13927
16285
|
}
|
|
@@ -13931,24 +16289,24 @@ var Screen = class {
|
|
|
13931
16289
|
this.composeBody.content = "";
|
|
13932
16290
|
return;
|
|
13933
16291
|
}
|
|
16292
|
+
const room = composeRoom(this.renderer.width);
|
|
13934
16293
|
const snippet = snippetOf(state, SNIPPET_LINES);
|
|
13935
16294
|
const more = selectionRange(state)[1] - selectionRange(state)[0] + 1 - snippet.length;
|
|
13936
16295
|
const tail = more > 0 ? [` … ${more} more lines`] : [];
|
|
13937
|
-
const
|
|
16296
|
+
const quoted = [...snippet, ...tail].map((line) => clip(line, room.text));
|
|
16297
|
+
const written = laidOut(`${state.draft}▌`.split("\n"), room.text);
|
|
13938
16298
|
const lines = [
|
|
13939
|
-
...
|
|
13940
|
-
...tail,
|
|
16299
|
+
...quoted,
|
|
13941
16300
|
"",
|
|
13942
16301
|
...written
|
|
13943
16302
|
];
|
|
13944
|
-
this.composeTitle.content = composeTarget(state);
|
|
16303
|
+
this.composeTitle.content = clip(composeTarget(state), room.text);
|
|
13945
16304
|
this.composeBody.content = lines.join("\n");
|
|
13946
16305
|
this.composeActions.content = actionsText();
|
|
13947
16306
|
const height = lines.length + COMPOSE_ACTION_ROWS + COMPOSE_CHROME;
|
|
13948
|
-
const room = modalWidth(this.renderer.width, COMPOSE_WIDTH);
|
|
13949
16307
|
this.compose.height = height;
|
|
13950
|
-
this.compose.width = room;
|
|
13951
|
-
this.compose.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room) / 2));
|
|
16308
|
+
this.compose.width = room.box;
|
|
16309
|
+
this.compose.left = Math.max(FRAME_PAD, Math.floor((this.renderer.width - room.box) / 2));
|
|
13952
16310
|
this.compose.top = Math.max(2, Math.floor((this.renderer.height - height) / 2));
|
|
13953
16311
|
}
|
|
13954
16312
|
};
|
|
@@ -14005,29 +16363,61 @@ var App = class {
|
|
|
14005
16363
|
noticeMs;
|
|
14006
16364
|
sessionPath;
|
|
14007
16365
|
remembered = "";
|
|
16366
|
+
wrapKept = false;
|
|
14008
16367
|
keys = [];
|
|
14009
16368
|
fading;
|
|
16369
|
+
wheel = 0;
|
|
16370
|
+
sideways = 0;
|
|
16371
|
+
watching;
|
|
14010
16372
|
constructor(options) {
|
|
14011
16373
|
this.renderer = options.renderer;
|
|
14012
16374
|
this.repo = options.repo;
|
|
14013
16375
|
this.run = options.run;
|
|
14014
16376
|
this.noticeMs = options.noticeMs ?? 2200;
|
|
14015
16377
|
this.sessionPath = options.sessionPath;
|
|
16378
|
+
this.wrapKept = options.wrap === true;
|
|
14016
16379
|
const { branches, renderer } = options;
|
|
14017
|
-
this.state =
|
|
16380
|
+
this.state = {
|
|
16381
|
+
...initialState(branches),
|
|
16382
|
+
wrap: options.wrap === true
|
|
16383
|
+
};
|
|
14018
16384
|
this.screen = new Screen(renderer, options.repo);
|
|
14019
16385
|
this.screen.update(this.state);
|
|
14020
16386
|
this.screen.listen({
|
|
14021
|
-
onScroll: (delta) => this.
|
|
16387
|
+
onScroll: (delta) => this.onWheel(delta),
|
|
16388
|
+
onPan: (delta) => this.onPanWheel(delta),
|
|
14022
16389
|
onDrag: (from, to) => this.commit(draggedTo(this.measured(), from, to)),
|
|
14023
16390
|
onChip: (key) => this.dispatchTask(() => this.onKey(asKey(key)))
|
|
14024
16391
|
});
|
|
14025
16392
|
renderer.keyInput.on("keypress", (key) => this.dispatch(key));
|
|
16393
|
+
renderer.on("destroy", () => this.stopWatching());
|
|
14026
16394
|
renderer.on("destroy", () => this.stopFading());
|
|
14027
16395
|
renderer.on("frame", () => this.syncGeometry());
|
|
16396
|
+
renderer.setFrameCallback(async () => this.applyWheel());
|
|
14028
16397
|
const resume = options.resume;
|
|
16398
|
+
this.startWatching(options.storeRoot);
|
|
16399
|
+
this.dispatchTask(() => this.loadPulls());
|
|
14029
16400
|
if (resume !== void 0) this.dispatchTask(() => this.resume(resume));
|
|
14030
16401
|
}
|
|
16402
|
+
startWatching(root) {
|
|
16403
|
+
if (root === void 0) return;
|
|
16404
|
+
this.watching = watchAnswers(root, () => this.dispatchTask(() => this.noticeAnswers()));
|
|
16405
|
+
}
|
|
16406
|
+
stopWatching() {
|
|
16407
|
+
this.watching?.stop();
|
|
16408
|
+
this.watching = void 0;
|
|
16409
|
+
}
|
|
16410
|
+
async noticeAnswers() {
|
|
16411
|
+
const branch = selectedBranch(this.state);
|
|
16412
|
+
if (branch === void 0) return this.noticeOnList();
|
|
16413
|
+
const sent = await this.loadSent(branch.branch);
|
|
16414
|
+
const said = spokenSince(this.state.sent, sent);
|
|
16415
|
+
if (said === 0) return;
|
|
16416
|
+
this.commit(withWaiting(this.state, `${said} answered · press r`));
|
|
16417
|
+
}
|
|
16418
|
+
async noticeOnList() {
|
|
16419
|
+
this.commit(withWaiting(this.state, "the agent answered · press r"));
|
|
16420
|
+
}
|
|
14031
16421
|
dispatchTask(task) {
|
|
14032
16422
|
this.pending = this.pending.then(task).catch((cause) => this.fail(cause));
|
|
14033
16423
|
}
|
|
@@ -14048,6 +16438,11 @@ var App = class {
|
|
|
14048
16438
|
});
|
|
14049
16439
|
await this.loadSource();
|
|
14050
16440
|
}
|
|
16441
|
+
rememberWrap(next) {
|
|
16442
|
+
if (next.wrap === this.wrapKept) return;
|
|
16443
|
+
this.wrapKept = next.wrap;
|
|
16444
|
+
this.run(saveWrap(next.wrap)).catch(() => void 0);
|
|
16445
|
+
}
|
|
14051
16446
|
rememberPlace(next) {
|
|
14052
16447
|
if (this.sessionPath === void 0 || next.screen !== "review") return;
|
|
14053
16448
|
const session = sessionOf(next);
|
|
@@ -14068,6 +16463,23 @@ var App = class {
|
|
|
14068
16463
|
settled() {
|
|
14069
16464
|
return this.pending;
|
|
14070
16465
|
}
|
|
16466
|
+
onWheel(delta) {
|
|
16467
|
+
this.wheel += delta;
|
|
16468
|
+
this.renderer.requestRender();
|
|
16469
|
+
}
|
|
16470
|
+
onPanWheel(delta) {
|
|
16471
|
+
this.sideways += delta;
|
|
16472
|
+
this.renderer.requestRender();
|
|
16473
|
+
}
|
|
16474
|
+
applyWheel() {
|
|
16475
|
+
const down = this.wheel;
|
|
16476
|
+
const across = this.sideways;
|
|
16477
|
+
if (down === 0 && across === 0) return;
|
|
16478
|
+
this.wheel = 0;
|
|
16479
|
+
this.sideways = 0;
|
|
16480
|
+
const moved = down === 0 ? this.measured() : scrolled(this.measured(), down);
|
|
16481
|
+
this.commit(across === 0 ? moved : panBy(moved, across));
|
|
16482
|
+
}
|
|
14071
16483
|
syncGeometry() {
|
|
14072
16484
|
const rows = this.screen.viewportRows();
|
|
14073
16485
|
if (rows === this.state.viewport) return;
|
|
@@ -14086,6 +16498,7 @@ var App = class {
|
|
|
14086
16498
|
const appeared = next.notice.length > 0 && next.notice !== this.state.notice;
|
|
14087
16499
|
this.state = next;
|
|
14088
16500
|
this.rememberPlace(next);
|
|
16501
|
+
this.rememberWrap(next);
|
|
14089
16502
|
this.screen.update(next);
|
|
14090
16503
|
if (appeared) this.fade();
|
|
14091
16504
|
}
|
|
@@ -14120,15 +16533,34 @@ var App = class {
|
|
|
14120
16533
|
"rail.toggle": () => this.commitSynced("rail.toggle"),
|
|
14121
16534
|
"file.vouch": () => this.vouch(false),
|
|
14122
16535
|
"file.vouch.next": () => this.vouch(true),
|
|
16536
|
+
"thread.settle": () => this.settleHere(),
|
|
16537
|
+
"review.reload": () => this.state.screen === "branches" ? this.reloadList() : this.reloadBranch(),
|
|
14123
16538
|
"pending.open": () => this.openPending(),
|
|
16539
|
+
"pending.edit": () => this.editStagedComment(),
|
|
16540
|
+
"pending.drop": () => this.dropStagedComment(),
|
|
14124
16541
|
"pending.submit": () => this.sendReview(),
|
|
14125
16542
|
"report.open": () => this.commit(reduce(this.measured(), "report.open")),
|
|
14126
16543
|
back: () => this.goBack(),
|
|
14127
16544
|
"report.send": () => this.sendReport(),
|
|
14128
16545
|
"context.more": () => this.expand(1),
|
|
14129
|
-
"context.less": () => this.expand(-1)
|
|
16546
|
+
"context.less": () => this.expand(-1),
|
|
16547
|
+
"tree.expand": () => this.unfold(1),
|
|
16548
|
+
"tree.collapse": () => this.unfold(-1)
|
|
14130
16549
|
};
|
|
14131
16550
|
}
|
|
16551
|
+
async unfold(delta) {
|
|
16552
|
+
const gap = this.state.focus === "diff" ? gapAtRow(this.state, this.state.cursor) : void 0;
|
|
16553
|
+
const action = delta > 0 ? "tree.expand" : "tree.collapse";
|
|
16554
|
+
if (gap === void 0) return this.commit(reduce(this.measured(), action));
|
|
16555
|
+
if (delta > 0) await this.loadFull();
|
|
16556
|
+
this.commit(gapOpened(this.measured(), gap.index, delta * 10));
|
|
16557
|
+
}
|
|
16558
|
+
async loadFull() {
|
|
16559
|
+
const branch = selectedBranch(this.state);
|
|
16560
|
+
if (branch === void 0 || this.state.full.length > 0) return;
|
|
16561
|
+
const full = await this.run(listPatches(this.repo, branch.branch, WHOLE_FILE));
|
|
16562
|
+
this.commit(withFull(this.state, full));
|
|
16563
|
+
}
|
|
14132
16564
|
async onKey(key, forced) {
|
|
14133
16565
|
const action = forced ?? actionFor(this.state.screen, keyName(key));
|
|
14134
16566
|
this.remember(action, key);
|
|
@@ -14155,16 +16587,52 @@ var App = class {
|
|
|
14155
16587
|
sequence: ""
|
|
14156
16588
|
}, chosen);
|
|
14157
16589
|
}
|
|
16590
|
+
async readBranch(name) {
|
|
16591
|
+
const patches = await this.run(listPatches(this.repo, name));
|
|
16592
|
+
const progress = await this.run(reviewProgress(this.repo, name));
|
|
16593
|
+
const pending = await this.run(listPending(this.repo, name));
|
|
16594
|
+
const layers = await this.run(listLayers(this.repo, name));
|
|
16595
|
+
const sent = await this.loadSent(name);
|
|
16596
|
+
const opened = withVouched(withPatches(this.state, patches), progress.vouched);
|
|
16597
|
+
return withLayers(withSent(withPending(opened, pending, "review"), sent), layers);
|
|
16598
|
+
}
|
|
14158
16599
|
async openBranch() {
|
|
14159
16600
|
const branch = selectedBranch(this.state);
|
|
14160
16601
|
if (branch === void 0) return;
|
|
14161
|
-
|
|
14162
|
-
|
|
14163
|
-
|
|
14164
|
-
|
|
14165
|
-
const
|
|
16602
|
+
this.commit(await this.readBranch(branch.branch));
|
|
16603
|
+
await this.loadSource();
|
|
16604
|
+
}
|
|
16605
|
+
async settleHere() {
|
|
16606
|
+
const branch = selectedBranch(this.state);
|
|
16607
|
+
const id = (threadAtStop(this.state) ?? threadAtRow(this.state, this.state.cursor))?.id;
|
|
16608
|
+
if (branch === void 0 || id === void 0) return this.commit(withNotice(this.state, "no thread here"));
|
|
16609
|
+
await this.run(settleThread(this.repo, branch.branch, id, (/* @__PURE__ */ new Date()).toISOString()));
|
|
14166
16610
|
const sent = await this.loadSent(branch.branch);
|
|
14167
|
-
|
|
16611
|
+
const held = withSent({
|
|
16612
|
+
...this.state,
|
|
16613
|
+
opened: this.state.opened.filter((was) => was !== id)
|
|
16614
|
+
}, sent);
|
|
16615
|
+
this.commit(withNotice(held, "settled"));
|
|
16616
|
+
}
|
|
16617
|
+
async reloadList() {
|
|
16618
|
+
const here = selectedBranch(this.state)?.branch;
|
|
16619
|
+
const branches = await this.run(listBranches(this.repo));
|
|
16620
|
+
const read = withBranches(this.state, branches);
|
|
16621
|
+
const at = branches.findIndex((candidate) => candidate.branch === here);
|
|
16622
|
+
const kept = at === -1 ? read : {
|
|
16623
|
+
...read,
|
|
16624
|
+
branchIndex: at
|
|
16625
|
+
};
|
|
16626
|
+
this.commit(withWaiting(withNoticeHere(kept, "read the list again"), ""));
|
|
16627
|
+
this.dispatchTask(() => this.loadPulls());
|
|
16628
|
+
}
|
|
16629
|
+
async reloadBranch() {
|
|
16630
|
+
const branch = selectedBranch(this.state);
|
|
16631
|
+
if (branch === void 0) return;
|
|
16632
|
+
const path = selectedPatch(this.state)?.path;
|
|
16633
|
+
const line = sourceLineAt(this.state, this.state.cursor);
|
|
16634
|
+
const read = await this.readBranch(branch.branch);
|
|
16635
|
+
this.commit(withWaiting(withNotice(restoredTo(read, path, line), "read the branch again"), ""));
|
|
14168
16636
|
await this.loadSource();
|
|
14169
16637
|
}
|
|
14170
16638
|
async goBack() {
|
|
@@ -14222,6 +16690,8 @@ var App = class {
|
|
|
14222
16690
|
};
|
|
14223
16691
|
}
|
|
14224
16692
|
async stage() {
|
|
16693
|
+
const editing = this.state.editing;
|
|
16694
|
+
if (editing !== void 0) return this.restage(editing);
|
|
14225
16695
|
const request = this.request();
|
|
14226
16696
|
if (request === void 0) return this.commit(withNotice(this.state, "nothing to stage"));
|
|
14227
16697
|
await this.run(stageComment(request));
|
|
@@ -14230,9 +16700,33 @@ var App = class {
|
|
|
14230
16700
|
const next = withPending(this.state, pending, "review");
|
|
14231
16701
|
this.commit(withNotice(next, `${pending.length} staged`));
|
|
14232
16702
|
}
|
|
16703
|
+
async restage(id) {
|
|
16704
|
+
const branch = selectedBranch(this.state);
|
|
16705
|
+
if (branch === void 0) return;
|
|
16706
|
+
await this.run(editStaged({
|
|
16707
|
+
repo: this.repo,
|
|
16708
|
+
branch: branch.branch,
|
|
16709
|
+
id,
|
|
16710
|
+
body: this.state.draft
|
|
16711
|
+
}));
|
|
16712
|
+
const pending = await this.run(listPending(this.repo, branch.branch));
|
|
16713
|
+
const next = withPending({
|
|
16714
|
+
...this.state,
|
|
16715
|
+
editing: void 0,
|
|
16716
|
+
draft: ""
|
|
16717
|
+
}, pending, "pending");
|
|
16718
|
+
this.commit(withNoticeHere(next, "reworded"));
|
|
16719
|
+
}
|
|
14233
16720
|
loadSent(branch) {
|
|
14234
16721
|
return this.run(listSent(this.repo, branch));
|
|
14235
16722
|
}
|
|
16723
|
+
async loadPulls() {
|
|
16724
|
+
const asked = (await this.run(map(Forge, (service) => service))).pulls(this.repo);
|
|
16725
|
+
const pulls = await this.run(asked.pipe(catchTag("ForgeUnavailable", () => succeed([]))));
|
|
16726
|
+
if (pulls.length === 0) return;
|
|
16727
|
+
const found = Object.fromEntries(pulls.map((pull) => [pull.branch, pull.state]));
|
|
16728
|
+
this.commit(withPulls(this.state, found));
|
|
16729
|
+
}
|
|
14236
16730
|
async loadSource() {
|
|
14237
16731
|
const branch = selectedBranch(this.state);
|
|
14238
16732
|
const patch = selectedPatch(this.state);
|
|
@@ -14242,11 +16736,12 @@ var App = class {
|
|
|
14242
16736
|
}
|
|
14243
16737
|
async expand(delta) {
|
|
14244
16738
|
const branch = selectedBranch(this.state);
|
|
14245
|
-
const next =
|
|
16739
|
+
const next = layerContext(this.state.context, delta);
|
|
14246
16740
|
if (branch === void 0 || next === this.state.context) return;
|
|
14247
16741
|
const line = sourceLineAt(this.state, this.state.cursor);
|
|
14248
16742
|
const patches = await this.run(listPatches(this.repo, branch.branch, next));
|
|
14249
|
-
const
|
|
16743
|
+
const widened = withContext(this.state, next, patches, 0);
|
|
16744
|
+
const patch = selectedPatch(widened);
|
|
14250
16745
|
const cursor = patch === void 0 || line === void 0 ? 0 : rowAtSourceLine(patch, line);
|
|
14251
16746
|
this.commit(withContext(this.state, next, patches, cursor));
|
|
14252
16747
|
}
|
|
@@ -14257,6 +16752,30 @@ var App = class {
|
|
|
14257
16752
|
if (pending.length === 0) return this.commit(withNotice(this.state, "nothing staged"));
|
|
14258
16753
|
this.commit(withPending(this.state, pending, "pending"));
|
|
14259
16754
|
}
|
|
16755
|
+
editStagedComment() {
|
|
16756
|
+
const entry = this.state.pending[this.state.pendingIndex];
|
|
16757
|
+
if (entry?.id === void 0) return;
|
|
16758
|
+
this.commit({
|
|
16759
|
+
...this.state,
|
|
16760
|
+
screen: "compose",
|
|
16761
|
+
draft: entry.body,
|
|
16762
|
+
editing: entry.id
|
|
16763
|
+
});
|
|
16764
|
+
}
|
|
16765
|
+
async dropStagedComment() {
|
|
16766
|
+
const branch = selectedBranch(this.state);
|
|
16767
|
+
const entry = this.state.pending[this.state.pendingIndex];
|
|
16768
|
+
if (branch === void 0 || entry?.id === void 0) return;
|
|
16769
|
+
await this.run(dropStaged(this.repo, branch.branch, entry.id));
|
|
16770
|
+
const pending = await this.run(listPending(this.repo, branch.branch));
|
|
16771
|
+
const kept = withPending(this.state, pending, pending.length === 0 ? "review" : "pending");
|
|
16772
|
+
const at = Math.min(this.state.pendingIndex, Math.max(0, pending.length - 1));
|
|
16773
|
+
const said = pending.length === 0 ? "nothing staged" : `withdrawn — ${pending.length} left`;
|
|
16774
|
+
this.commit(withNoticeHere({
|
|
16775
|
+
...kept,
|
|
16776
|
+
pendingIndex: at
|
|
16777
|
+
}, said));
|
|
16778
|
+
}
|
|
14260
16779
|
async sendReview() {
|
|
14261
16780
|
const branch = selectedBranch(this.state);
|
|
14262
16781
|
if (branch === void 0) return;
|
|
@@ -14314,6 +16833,8 @@ const launch = fn("Tui.launch")(function* (repo, renderer, noticeMs, sessionPath
|
|
|
14314
16833
|
const context$2 = yield* context();
|
|
14315
16834
|
const branches = yield* listBranches(repo);
|
|
14316
16835
|
const resume = sessionPath === void 0 ? void 0 : yield* promise(() => readSession(sessionPath));
|
|
16836
|
+
const store = yield* Store;
|
|
16837
|
+
const settings = yield* store.settings;
|
|
14317
16838
|
return new App({
|
|
14318
16839
|
renderer,
|
|
14319
16840
|
repo,
|
|
@@ -14321,7 +16842,9 @@ const launch = fn("Tui.launch")(function* (repo, renderer, noticeMs, sessionPath
|
|
|
14321
16842
|
branches,
|
|
14322
16843
|
noticeMs,
|
|
14323
16844
|
sessionPath,
|
|
14324
|
-
resume
|
|
16845
|
+
resume,
|
|
16846
|
+
wrap: settings.wrap === true,
|
|
16847
|
+
storeRoot: store.root
|
|
14325
16848
|
});
|
|
14326
16849
|
});
|
|
14327
16850
|
const untilDestroyed = (renderer) => callback((resume) => {
|
|
@@ -14370,6 +16893,24 @@ const commentTake = fn("Main.commentTake")(function* (options) {
|
|
|
14370
16893
|
const comments = wait > 0 ? yield* awaitComments(worktree, Date.now() + wait * WAIT_UNIT) : yield* takeComments(worktree);
|
|
14371
16894
|
yield* answer(options, { comments });
|
|
14372
16895
|
});
|
|
16896
|
+
const commentAnswer = fn("Main.commentAnswer")(function* (options) {
|
|
16897
|
+
const report = yield* answerComment({
|
|
16898
|
+
worktree: yield* required(options, "worktree"),
|
|
16899
|
+
id: yield* required(options, "id"),
|
|
16900
|
+
body: yield* required(options, "body"),
|
|
16901
|
+
asks: options["asks"] !== void 0,
|
|
16902
|
+
at: options["at"] ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
16903
|
+
});
|
|
16904
|
+
yield* answer(options, { answered: report.answered });
|
|
16905
|
+
});
|
|
16906
|
+
const commentThreads = fn("Main.commentThreads")(function* (options) {
|
|
16907
|
+
const threads = yield* listThreads(yield* required(options, "repo"), yield* required(options, "branch"));
|
|
16908
|
+
yield* answer(options, { threads });
|
|
16909
|
+
});
|
|
16910
|
+
const commentResolve = fn("Main.commentResolve")(function* (options) {
|
|
16911
|
+
const report = yield* settleThread(yield* required(options, "repo"), yield* required(options, "branch"), yield* required(options, "id"), options["at"] ?? (/* @__PURE__ */ new Date()).toISOString());
|
|
16912
|
+
yield* answer(options, { settled: report.settled });
|
|
16913
|
+
});
|
|
14373
16914
|
const commentStage = fn("Main.commentStage")(function* (options) {
|
|
14374
16915
|
const report = yield* stageComment({
|
|
14375
16916
|
repo: yield* required(options, "repo"),
|
|
@@ -14384,6 +16925,19 @@ const commentStage = fn("Main.commentStage")(function* (options) {
|
|
|
14384
16925
|
});
|
|
14385
16926
|
yield* answer(options, { pending: report.pending });
|
|
14386
16927
|
});
|
|
16928
|
+
const commentEdit = fn("Main.commentEdit")(function* (options) {
|
|
16929
|
+
const report = yield* editStaged({
|
|
16930
|
+
repo: yield* required(options, "repo"),
|
|
16931
|
+
branch: yield* required(options, "branch"),
|
|
16932
|
+
id: yield* required(options, "id"),
|
|
16933
|
+
body: yield* required(options, "body")
|
|
16934
|
+
});
|
|
16935
|
+
yield* answer(options, { pending: report.pending });
|
|
16936
|
+
});
|
|
16937
|
+
const commentDrop = fn("Main.commentDrop")(function* (options) {
|
|
16938
|
+
const report = yield* dropStaged(yield* required(options, "repo"), yield* required(options, "branch"), yield* required(options, "id"));
|
|
16939
|
+
yield* answer(options, { pending: report.pending });
|
|
16940
|
+
});
|
|
14387
16941
|
const reviewSubmit = fn("Main.reviewSubmit")(function* (options) {
|
|
14388
16942
|
const report = yield* submitReview(yield* required(options, "repo"), yield* required(options, "branch"), options["id"] ?? randomUUID(), options["at"] ?? (/* @__PURE__ */ new Date()).toISOString());
|
|
14389
16943
|
yield* answer(options, { submitted: report.submitted });
|
|
@@ -14410,24 +16964,29 @@ const reviewStatus = fn("Main.reviewStatus")(function* (options) {
|
|
|
14410
16964
|
const documentAt = fn("Main.documentAt")(function* (source) {
|
|
14411
16965
|
return yield* tryPromise({
|
|
14412
16966
|
try: () => source === "-" ? text(process.stdin) : readFile(source, "utf8"),
|
|
14413
|
-
catch: (cause) => new
|
|
16967
|
+
catch: (cause) => new MalformedLayers({ reason: String(cause) })
|
|
14414
16968
|
});
|
|
14415
16969
|
});
|
|
14416
16970
|
const routes = {
|
|
14417
16971
|
"branch list": branchList,
|
|
14418
16972
|
"comment add": commentAdd,
|
|
14419
16973
|
"comment stage": commentStage,
|
|
16974
|
+
"comment edit": commentEdit,
|
|
16975
|
+
"comment drop": commentDrop,
|
|
14420
16976
|
"comment take": commentTake,
|
|
16977
|
+
"comment answer": commentAnswer,
|
|
16978
|
+
"comment threads": commentThreads,
|
|
16979
|
+
"comment resolve": commentResolve,
|
|
14421
16980
|
"review submit": reviewSubmit,
|
|
14422
16981
|
"review progress": reviewStatus,
|
|
14423
|
-
"
|
|
16982
|
+
"layers set": fn("Main.layersSet")(function* (options) {
|
|
14424
16983
|
const document = yield* documentAt(yield* required(options, "json"));
|
|
14425
|
-
const
|
|
14426
|
-
yield* answer(options, {
|
|
16984
|
+
const layers = yield* setLayers(yield* required(options, "worktree"), document, options["at"] ?? (/* @__PURE__ */ new Date()).toISOString());
|
|
16985
|
+
yield* answer(options, { layers });
|
|
14427
16986
|
}),
|
|
14428
|
-
"
|
|
14429
|
-
const
|
|
14430
|
-
yield* answer(options, {
|
|
16987
|
+
"layers show": fn("Main.layersShow")(function* (options) {
|
|
16988
|
+
const layers = yield* showLayers(yield* required(options, "worktree"));
|
|
16989
|
+
yield* answer(options, { layers });
|
|
14431
16990
|
}),
|
|
14432
16991
|
describe: fn("Main.describe")(function* (options) {
|
|
14433
16992
|
const wanted = options["command"];
|
|
@@ -14437,7 +16996,7 @@ const routes = {
|
|
|
14437
16996
|
name: asked,
|
|
14438
16997
|
known: commandNames
|
|
14439
16998
|
});
|
|
14440
|
-
yield* answer(options, { commands: found === void 0 ? catalog : [found] });
|
|
16999
|
+
return yield* answer(options, { commands: found === void 0 ? catalog : [found] });
|
|
14441
17000
|
})
|
|
14442
17001
|
};
|
|
14443
17002
|
const run = fn("Main.run")(function* (name, options) {
|
|
@@ -14456,7 +17015,26 @@ const nameOf = (argv) => {
|
|
|
14456
17015
|
return findCommand(pair) === void 0 ? words[0] ?? "" : pair;
|
|
14457
17016
|
};
|
|
14458
17017
|
const argv = process.argv.slice(2);
|
|
14459
|
-
const
|
|
17018
|
+
const ASKS = {
|
|
17019
|
+
"--version": version,
|
|
17020
|
+
"-v": version,
|
|
17021
|
+
"--help": help,
|
|
17022
|
+
"-h": help
|
|
17023
|
+
};
|
|
17024
|
+
const spoken = (words) => {
|
|
17025
|
+
const [first, ...rest] = words;
|
|
17026
|
+
if (first === void 0) return banner();
|
|
17027
|
+
const asked = ASKS[first];
|
|
17028
|
+
if (asked !== void 0) return asked();
|
|
17029
|
+
if (first !== "help") return void 0;
|
|
17030
|
+
return rest.length === 0 ? help() : helpFor(rest.join(" ")) ?? help();
|
|
17031
|
+
};
|
|
17032
|
+
const said = spoken(argv);
|
|
17033
|
+
if (said !== void 0) {
|
|
17034
|
+
process.stdout.write(`${said}\n`);
|
|
17035
|
+
process.exit(0);
|
|
17036
|
+
}
|
|
17037
|
+
const layer = mergeAll(GitLive, ForgeLive, storeAt(process.env["ADIFF_ROOT"] ?? defaultRoot()));
|
|
14460
17038
|
const exit = await runPromiseExit(run(nameOf(argv), optionsFrom(argv)).pipe(provide(layer)));
|
|
14461
17039
|
if (isFailure(exit)) {
|
|
14462
17040
|
const reported = failure(squash(exit.cause));
|