@ftrdotdev/pi-tracker 0.6.0 → 0.8.0
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/README.md +183 -60
- package/package.json +23 -11
- package/src/compaction/candidate.test.ts +9 -6
- package/src/compaction/candidate.ts +32 -2
- package/src/compaction/classifier.test.ts +67 -60
- package/src/compaction/classifier.ts +24 -22
- package/src/compaction/completion.test.ts +127 -49
- package/src/compaction/completion.ts +1 -3
- package/src/compaction/decision-record.test.ts +91 -0
- package/src/compaction/decision-record.ts +101 -0
- package/src/compaction/digest.test.ts +104 -9
- package/src/compaction/digest.ts +96 -9
- package/src/compaction/footprint.test.ts +135 -0
- package/src/compaction/footprint.ts +387 -0
- package/src/compaction/observations.test.ts +199 -0
- package/src/compaction/observations.ts +348 -0
- package/src/compaction/rules.test.ts +253 -0
- package/src/compaction/rules.ts +188 -0
- package/src/compaction/settings.test.ts +105 -49
- package/src/compaction/settings.ts +53 -31
- package/src/compaction/settle.test.ts +370 -0
- package/src/compaction/settle.ts +109 -53
- package/src/core/deps.test.ts +1 -1
- package/src/core/domain.test.ts +42 -9
- package/src/core/domain.ts +73 -8
- package/src/core/persistence.test.ts +7 -7
- package/src/core/store.test.ts +116 -50
- package/src/core/store.ts +92 -31
- package/src/index.test.ts +209 -68
- package/src/index.ts +170 -48
- package/src/presentation/tool-metadata.test.ts +263 -48
- package/src/presentation/tool-metadata.ts +325 -102
- package/src/presentation/ui.test.ts +122 -7
- package/src/presentation/ui.ts +81 -18
- package/src/presentation/vim-settings.test.ts +98 -0
- package/src/presentation/vim-settings.ts +59 -0
package/src/core/store.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { Context, Effect, Layer, Ref, Result, Schema } from "effect";
|
|
2
2
|
import { blockersOf, cyclePath, dependentsOf, formatItemRef, parseItemRef } from "./deps.ts";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
TodoItem,
|
|
5
|
+
TodoList,
|
|
6
|
+
TrackerState,
|
|
7
|
+
emptyState,
|
|
8
|
+
type DeclaredProduct,
|
|
9
|
+
type DeclaredReference,
|
|
10
|
+
} from "./domain.ts";
|
|
4
11
|
|
|
5
12
|
// --------------------------------------------------------------------------
|
|
6
13
|
// Errors
|
|
@@ -158,17 +165,40 @@ const withItems = (list: TodoList, items: readonly TodoItem[]): TodoList =>
|
|
|
158
165
|
// --------------------------------------------------------------------------
|
|
159
166
|
|
|
160
167
|
/**
|
|
161
|
-
* How a caller declares an item to create: the bare
|
|
162
|
-
* also carries
|
|
168
|
+
* How a caller declares an item to create: the bare title, or an object that
|
|
169
|
+
* also carries a description, the declared references and products, and the
|
|
170
|
+
* ids of the same-list items this one waits for.
|
|
163
171
|
*/
|
|
164
|
-
export type ItemSpec =
|
|
172
|
+
export type ItemSpec =
|
|
173
|
+
| string
|
|
174
|
+
| {
|
|
175
|
+
readonly title: string;
|
|
176
|
+
readonly description?: string;
|
|
177
|
+
readonly refs?: readonly DeclaredReference[];
|
|
178
|
+
readonly produces?: readonly DeclaredProduct[];
|
|
179
|
+
readonly deps?: readonly string[];
|
|
180
|
+
};
|
|
165
181
|
|
|
166
|
-
/** Trim a spec's
|
|
182
|
+
/** Trim a spec's title and settle its description, declarations, and deps. */
|
|
167
183
|
const normalizeSpec = (
|
|
168
184
|
spec: ItemSpec,
|
|
169
|
-
): {
|
|
170
|
-
|
|
171
|
-
|
|
185
|
+
): {
|
|
186
|
+
readonly title: string;
|
|
187
|
+
readonly description: string;
|
|
188
|
+
readonly refs: readonly DeclaredReference[];
|
|
189
|
+
readonly produces: readonly DeclaredProduct[];
|
|
190
|
+
readonly deps: readonly string[];
|
|
191
|
+
} => {
|
|
192
|
+
if (typeof spec === "string") {
|
|
193
|
+
return { title: spec.trim(), description: "", refs: [], produces: [], deps: [] };
|
|
194
|
+
}
|
|
195
|
+
return {
|
|
196
|
+
title: spec.title.trim(),
|
|
197
|
+
description: spec.description ?? "",
|
|
198
|
+
refs: spec.refs ?? [],
|
|
199
|
+
produces: spec.produces ?? [],
|
|
200
|
+
deps: spec.deps ?? [],
|
|
201
|
+
};
|
|
172
202
|
};
|
|
173
203
|
|
|
174
204
|
/**
|
|
@@ -260,7 +290,12 @@ const dependedOnError = (list: TodoList, index: number, itemId: string): Tracker
|
|
|
260
290
|
};
|
|
261
291
|
|
|
262
292
|
export interface UpdateItemPatch {
|
|
263
|
-
readonly
|
|
293
|
+
readonly title?: string;
|
|
294
|
+
readonly description?: string;
|
|
295
|
+
/** Replacement declaration list; `[]` clears it. */
|
|
296
|
+
readonly refs?: readonly DeclaredReference[];
|
|
297
|
+
/** Replacement product list; `[]` clears it. */
|
|
298
|
+
readonly produces?: readonly DeclaredProduct[];
|
|
264
299
|
readonly done?: boolean;
|
|
265
300
|
/** Replacement dependency set (same-list `listName:id` refs); `[]` clears it. */
|
|
266
301
|
readonly deps?: readonly string[];
|
|
@@ -268,7 +303,7 @@ export interface UpdateItemPatch {
|
|
|
268
303
|
|
|
269
304
|
/**
|
|
270
305
|
* An `UpdateItemPatch` that targets an item by id within a single list
|
|
271
|
-
* (mirrors `
|
|
306
|
+
* (mirrors `add_items`'s `list_id + items` shape: the list is factored out,
|
|
272
307
|
* the patches name their item).
|
|
273
308
|
*/
|
|
274
309
|
export interface UpdateItemInListPatch extends UpdateItemPatch {
|
|
@@ -297,7 +332,7 @@ export class TrackerStore extends Context.Service<
|
|
|
297
332
|
readonly setActiveList: (listId: number | null) => Effect.Effect<void, TrackerError>;
|
|
298
333
|
readonly addItem: (
|
|
299
334
|
listId: number,
|
|
300
|
-
|
|
335
|
+
spec: ItemSpec,
|
|
301
336
|
deps?: readonly string[],
|
|
302
337
|
) => Effect.Effect<TodoItem, TrackerError>;
|
|
303
338
|
readonly addItems: (
|
|
@@ -348,10 +383,10 @@ export class TrackerStore extends Context.Service<
|
|
|
348
383
|
});
|
|
349
384
|
}
|
|
350
385
|
const initialSpecs = (options.initialItems ?? []).map(normalizeSpec);
|
|
351
|
-
if (initialSpecs.some((spec) => spec.
|
|
386
|
+
if (initialSpecs.some((spec) => spec.title === "")) {
|
|
352
387
|
return yield* new TrackerError({
|
|
353
388
|
reason: "EmptyText",
|
|
354
|
-
message: "Item
|
|
389
|
+
message: "Item title must not be empty",
|
|
355
390
|
});
|
|
356
391
|
}
|
|
357
392
|
const activate = options.activate ?? true;
|
|
@@ -370,7 +405,15 @@ export class TrackerStore extends Context.Service<
|
|
|
370
405
|
}
|
|
371
406
|
const items = initialSpecs.map(
|
|
372
407
|
(spec, index) =>
|
|
373
|
-
new TodoItem({
|
|
408
|
+
new TodoItem({
|
|
409
|
+
id: index + 1,
|
|
410
|
+
title: spec.title,
|
|
411
|
+
description: spec.description,
|
|
412
|
+
refs: [...spec.refs],
|
|
413
|
+
produces: [...spec.produces],
|
|
414
|
+
done: false,
|
|
415
|
+
deps: [...spec.deps],
|
|
416
|
+
}),
|
|
374
417
|
);
|
|
375
418
|
const list = new TodoList({
|
|
376
419
|
id: s.nextListId,
|
|
@@ -444,19 +487,19 @@ export class TrackerStore extends Context.Service<
|
|
|
444
487
|
});
|
|
445
488
|
|
|
446
489
|
/**
|
|
447
|
-
* Append items to a list, assigning ids from the list counter. Accepts
|
|
448
|
-
* bare
|
|
449
|
-
* created by this same call.
|
|
490
|
+
* Append items to a list, assigning ids from the list counter. Accepts a
|
|
491
|
+
* bare title or item objects `{title, description?, refs?, produces?,
|
|
492
|
+
* deps?}`; a dependency may name an item created by this same call.
|
|
450
493
|
*/
|
|
451
494
|
const addItems = Effect.fn("TrackerStore.addItems")(function* (
|
|
452
495
|
listId: number,
|
|
453
496
|
items: readonly ItemSpec[],
|
|
454
497
|
) {
|
|
455
498
|
const specs = items.map(normalizeSpec);
|
|
456
|
-
if (specs.some((spec) => spec.
|
|
499
|
+
if (specs.some((spec) => spec.title === "")) {
|
|
457
500
|
return yield* new TrackerError({
|
|
458
501
|
reason: "EmptyText",
|
|
459
|
-
message: "Item
|
|
502
|
+
message: "Item title must not be empty",
|
|
460
503
|
});
|
|
461
504
|
}
|
|
462
505
|
return yield* mutate(
|
|
@@ -478,7 +521,10 @@ export class TrackerStore extends Context.Service<
|
|
|
478
521
|
const added = specs.map((spec) => {
|
|
479
522
|
const item = new TodoItem({
|
|
480
523
|
id: nextId,
|
|
481
|
-
|
|
524
|
+
title: spec.title,
|
|
525
|
+
description: spec.description,
|
|
526
|
+
refs: [...spec.refs],
|
|
527
|
+
produces: [...spec.produces],
|
|
482
528
|
done: false,
|
|
483
529
|
deps: [...spec.deps],
|
|
484
530
|
});
|
|
@@ -500,10 +546,11 @@ export class TrackerStore extends Context.Service<
|
|
|
500
546
|
|
|
501
547
|
const addItem = Effect.fn("TrackerStore.addItem")(function* (
|
|
502
548
|
listId: number,
|
|
503
|
-
|
|
549
|
+
spec: ItemSpec,
|
|
504
550
|
deps: readonly string[] = [],
|
|
505
551
|
) {
|
|
506
|
-
const
|
|
552
|
+
const resolved: ItemSpec = typeof spec === "string" ? { title: spec, deps } : spec;
|
|
553
|
+
const [item] = yield* addItems(listId, [resolved]);
|
|
507
554
|
return item!;
|
|
508
555
|
});
|
|
509
556
|
|
|
@@ -511,11 +558,11 @@ export class TrackerStore extends Context.Service<
|
|
|
511
558
|
itemId: string,
|
|
512
559
|
patch: UpdateItemPatch,
|
|
513
560
|
) {
|
|
514
|
-
const trimmed = patch.
|
|
515
|
-
if (patch.
|
|
561
|
+
const trimmed = patch.title === undefined ? undefined : patch.title.trim();
|
|
562
|
+
if (patch.title !== undefined && trimmed === "") {
|
|
516
563
|
return yield* new TrackerError({
|
|
517
564
|
reason: "EmptyText",
|
|
518
|
-
message: "Item
|
|
565
|
+
message: "Item title must not be empty",
|
|
519
566
|
});
|
|
520
567
|
}
|
|
521
568
|
return yield* mutate(
|
|
@@ -532,13 +579,23 @@ export class TrackerStore extends Context.Service<
|
|
|
532
579
|
const blocked = blockedError(list, resolved.index);
|
|
533
580
|
if (blocked !== null) return [Result.fail(blocked), s];
|
|
534
581
|
}
|
|
535
|
-
if (
|
|
582
|
+
if (
|
|
583
|
+
patch.title === undefined &&
|
|
584
|
+
patch.description === undefined &&
|
|
585
|
+
patch.refs === undefined &&
|
|
586
|
+
patch.produces === undefined &&
|
|
587
|
+
patch.done === undefined &&
|
|
588
|
+
patch.deps === undefined
|
|
589
|
+
) {
|
|
536
590
|
// No-op patch: return the current item, leave state untouched.
|
|
537
591
|
return [Result.succeed(item), s];
|
|
538
592
|
}
|
|
539
593
|
const next = new TodoItem({
|
|
540
594
|
id: item.id,
|
|
541
|
-
|
|
595
|
+
title: trimmed ?? item.title,
|
|
596
|
+
description: patch.description ?? item.description,
|
|
597
|
+
refs: patch.refs === undefined ? item.refs : [...patch.refs],
|
|
598
|
+
produces: patch.produces === undefined ? item.produces : [...patch.produces],
|
|
542
599
|
done: patch.done ?? item.done,
|
|
543
600
|
deps: patch.deps === undefined ? item.deps : [...patch.deps],
|
|
544
601
|
});
|
|
@@ -567,13 +624,13 @@ export class TrackerStore extends Context.Service<
|
|
|
567
624
|
listId: number,
|
|
568
625
|
patches: readonly UpdateItemInListPatch[],
|
|
569
626
|
) {
|
|
570
|
-
// Reject empty replacement
|
|
627
|
+
// Reject empty replacement titles up front so the whole batch fails
|
|
571
628
|
// before touching the state (atomicity).
|
|
572
629
|
for (const patch of patches) {
|
|
573
|
-
if (patch.
|
|
630
|
+
if (patch.title !== undefined && patch.title.trim() === "") {
|
|
574
631
|
return yield* new TrackerError({
|
|
575
632
|
reason: "EmptyText",
|
|
576
|
-
message: "Item
|
|
633
|
+
message: "Item title must not be empty",
|
|
577
634
|
});
|
|
578
635
|
}
|
|
579
636
|
}
|
|
@@ -649,7 +706,11 @@ export class TrackerStore extends Context.Service<
|
|
|
649
706
|
at === target
|
|
650
707
|
? new TodoItem({
|
|
651
708
|
id: current.id,
|
|
652
|
-
|
|
709
|
+
title: patch.title === undefined ? current.title : patch.title.trim(),
|
|
710
|
+
description: patch.description ?? current.description,
|
|
711
|
+
refs: patch.refs === undefined ? current.refs : [...patch.refs],
|
|
712
|
+
produces:
|
|
713
|
+
patch.produces === undefined ? current.produces : [...patch.produces],
|
|
653
714
|
done: patch.done ?? current.done,
|
|
654
715
|
deps: patch.deps === undefined ? current.deps : [...patch.deps],
|
|
655
716
|
})
|