@infodb/p3 0.5.0 → 0.7.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 +1 -0
- package/dist/web/assets/{Outputs-C83ZDXvs.js → Outputs-CQi0oba1.js} +1 -1
- package/dist/web/assets/{RequestStatus-GmiWYEcL.js → RequestStatus-grC0F_SQ.js} +1 -1
- package/dist/web/assets/Tabs-BJRGzidj.js +1 -0
- package/dist/web/assets/{TagInput-CtM8HM8Z.js → TagInput-cIIwXAHA.js} +1 -1
- package/dist/web/assets/{TaskDrawer-D5v36QoF.js → TaskDrawer-CSZ7Z0JC.js} +1 -1
- package/dist/web/assets/{_requestId-DxwxbXY2.js → _requestId-C8WYk2kC.js} +2 -2
- package/dist/web/assets/{_requestId-BHUqLO-j.js → _requestId-Z3CBhTIL.js} +1 -1
- package/dist/web/assets/{appCtx-B-VRVOyv.js → appCtx-DCiGJFAe.js} +1 -1
- package/dist/web/assets/{board-DAaVR04x.js → board-DyfGX5h0.js} +1 -1
- package/dist/web/assets/{done-CaqB_qTH.js → done-Bhxqy7bH.js} +1 -1
- package/dist/web/assets/{index-BQYvKpjF.js → index-Bt13tvIX.js} +3 -3
- package/dist/web/assets/{new-DLVnRvrB.js → new-BRsIUNIb.js} +1 -1
- package/dist/web/assets/{preload-helper-B74h5i3O.js → preload-helper-B40dBmwL.js} +1 -1
- package/dist/web/assets/progressTree-DgrdDFih.js +1 -0
- package/dist/web/assets/{release-notes-MTLcOcvZ.js → release-notes-C3FdiM36.js} +1 -1
- package/dist/web/assets/{requestData-D-HXu-cy.js → requestData-w6fhCYmh.js} +1 -1
- package/dist/web/assets/{routes-CI4Qfkjs.js → routes-QNgQHe48.js} +1 -1
- package/dist/web/assets/{settings-CJMNgzi6.js → settings-CoKJahEe.js} +1 -1
- package/dist/web/index.html +3 -3
- package/docs/architecture.md +63 -6
- package/docs/development.md +7 -1
- package/docs/how-to-use.md +23 -6
- package/docs/installation.md +9 -6
- package/docs/publishing.md +3 -4
- package/lib/cli/help.js +3 -1
- package/lib/cli/main.js +3 -2
- package/lib/cli/project.js +1 -1
- package/lib/cli/requestCommands.js +19 -8
- package/lib/cli/showView.js +1 -1
- package/lib/core/hierarchy.js +50 -0
- package/lib/core/preflight/service.js +16 -1
- package/lib/core/requestOps.js +11 -1
- package/lib/core/store/collection.js +17 -6
- package/lib/core/store/normalize.js +3 -1
- package/lib/server/api/manifest.js +8 -1
- package/lib/server/api/routes.js +15 -3
- package/lib/shared/hierarchy.js +19 -4
- package/package.json +1 -1
- package/skills/p3/SKILL.md +7 -3
- package/dist/web/assets/Tabs-CJn0Qy7W.js +0 -1
- package/dist/web/assets/progressTree-wp9mH4VF.js +0 -1
|
@@ -97,7 +97,10 @@ export class MarkdownCollection {
|
|
|
97
97
|
async read(id) {
|
|
98
98
|
try {
|
|
99
99
|
const { data, body } = parseFrontmatter(await readFile(this.layout.path(id), "utf8"));
|
|
100
|
-
|
|
100
|
+
const item = this.opts.normalize(data, body, id);
|
|
101
|
+
const known = new Set(["body", ...this.opts.keyOrder, ...(this.opts.derived ?? []), ...Object.keys(item)]);
|
|
102
|
+
const extra = Object.fromEntries(Object.entries(data).filter(([k]) => !known.has(k)));
|
|
103
|
+
return { item, extra };
|
|
101
104
|
}
|
|
102
105
|
catch (e) {
|
|
103
106
|
return e.code === "ENOENT" ? { missing: true } : { error: String(e) };
|
|
@@ -113,7 +116,9 @@ export class MarkdownCollection {
|
|
|
113
116
|
}
|
|
114
117
|
/** 1件を読み直す。消えていれば除く */
|
|
115
118
|
async reload(id) {
|
|
116
|
-
|
|
119
|
+
this.apply(id, await this.read(id));
|
|
120
|
+
}
|
|
121
|
+
apply(id, r) {
|
|
117
122
|
if ("item" in r) {
|
|
118
123
|
this.put(id, r.item);
|
|
119
124
|
this.errors.delete(id);
|
|
@@ -142,7 +147,7 @@ export class MarkdownCollection {
|
|
|
142
147
|
path(id) {
|
|
143
148
|
return this.layout.path(id);
|
|
144
149
|
}
|
|
145
|
-
serialize(item) {
|
|
150
|
+
serialize(item, extra = {}) {
|
|
146
151
|
const { body, ...rest } = item;
|
|
147
152
|
const skip = new Set(["body", ...(this.opts.derived ?? [])]);
|
|
148
153
|
const ordered = {};
|
|
@@ -152,6 +157,9 @@ export class MarkdownCollection {
|
|
|
152
157
|
for (const [k, v] of Object.entries(rest))
|
|
153
158
|
if (!(k in ordered) && !skip.has(k))
|
|
154
159
|
ordered[k] = v;
|
|
160
|
+
for (const [k, v] of Object.entries(extra))
|
|
161
|
+
if (!(k in ordered) && !skip.has(k))
|
|
162
|
+
ordered[k] = v;
|
|
155
163
|
return stringifyFrontmatter(ordered, body);
|
|
156
164
|
}
|
|
157
165
|
/** 作る。省いた項目は normalize の既定値になる */
|
|
@@ -190,8 +198,11 @@ export class MarkdownCollection {
|
|
|
190
198
|
* 部分更新。expectedRev を渡すと楽観ロック(AI が古い状態を元に上書きするのを防ぐ)。
|
|
191
199
|
*/
|
|
192
200
|
async update(id, patch, opts = {}) {
|
|
193
|
-
//
|
|
194
|
-
|
|
201
|
+
// 外部での編集を取りこぼさないよう、更新の直前にディスクから読み直す。
|
|
202
|
+
// この版が知らない項目(新しい版の p3 が書いた項目)は消さずに書き戻す(古い版の更新で親子などが消えないように)
|
|
203
|
+
const r = await this.read(id);
|
|
204
|
+
this.apply(id, r);
|
|
205
|
+
const extra = "item" in r ? r.extra : {};
|
|
195
206
|
const cur = this.require(id);
|
|
196
207
|
if (opts.expectedRev !== undefined && opts.expectedRev !== cur.rev) {
|
|
197
208
|
throw new ConflictError(id, opts.expectedRev, cur.rev);
|
|
@@ -206,7 +217,7 @@ export class MarkdownCollection {
|
|
|
206
217
|
updatedBy: opts.actor ?? cur.updatedBy,
|
|
207
218
|
};
|
|
208
219
|
const next = this.opts.beforeWrite?.(cur, merged) ?? merged;
|
|
209
|
-
await writeFileAtomic(this.layout.path(id), this.serialize(next));
|
|
220
|
+
await writeFileAtomic(this.layout.path(id), this.serialize(next, extra));
|
|
210
221
|
this.put(id, next);
|
|
211
222
|
return next;
|
|
212
223
|
}
|
|
@@ -56,6 +56,8 @@ export function normalizeRequest(d, body, id) {
|
|
|
56
56
|
status: REQUEST_STATUSES.includes(status) ? status : "draft",
|
|
57
57
|
// 形の違う親もそのまま読む(直そうとせず、親子の問題として知らせる)
|
|
58
58
|
...(str(d.parent) ? { parent: str(d.parent) } : {}),
|
|
59
|
+
// 子の表示順は文字の並びとしてそのまま読む(重複・今は子でない ID は並べるときに除く。ファイルは書き換えない)
|
|
60
|
+
...(Array.isArray(d.childOrder) ? { childOrder: d.childOrder.filter((x) => typeof x === "string") } : {}),
|
|
59
61
|
...(str(d.splitFrom) ? { splitFrom: str(d.splitFrom) } : {}),
|
|
60
62
|
areas: strs(d.areas),
|
|
61
63
|
due: date(d.due),
|
|
@@ -71,7 +73,7 @@ export function normalizeRequest(d, body, id) {
|
|
|
71
73
|
};
|
|
72
74
|
}
|
|
73
75
|
export const REQUEST_KEY_ORDER = [
|
|
74
|
-
"id", "title", "status", "parent", "splitFrom", "due", "milestone", "tags", "areas", "workstreams", "lastPreflight",
|
|
76
|
+
"id", "title", "status", "parent", "childOrder", "splitFrom", "due", "milestone", "tags", "areas", "workstreams", "lastPreflight",
|
|
75
77
|
"rev", "createdAt", "updatedAt", "updatedBy",
|
|
76
78
|
];
|
|
77
79
|
export function normalizeProject(d) {
|
|
@@ -35,7 +35,7 @@ export const AI_MANIFEST = {
|
|
|
35
35
|
desc: "参照先(共有の定義)。GET は読めたかの状態と、ローカルの画面にだけこのマシンのパス。POST {name, role?, readFirst?, writable?, map?, path?}",
|
|
36
36
|
},
|
|
37
37
|
{ method: "PUT|DELETE", path: "/api/repos/:name/path", desc: "参照先のこのマシンのパス(個人設定)。このマシンのローカルの画面(Origin)からだけ" },
|
|
38
|
-
{ method: "GET", path: "/api/requests[?parent=<要望ID>]", desc: "
|
|
38
|
+
{ method: "GET", path: "/api/requests[?parent=<要望ID>]", desc: "要望の一覧と進捗(更新の新しい順。parent で直下の子だけを親の表示順に)" },
|
|
39
39
|
{ method: "POST", path: "/api/requests", desc: "要望の作成(parent で子の要望にする。省いた期限・マイルストーン・タグは親から写す)" },
|
|
40
40
|
{
|
|
41
41
|
method: "GET",
|
|
@@ -49,6 +49,13 @@ export const AI_MANIFEST = {
|
|
|
49
49
|
"status=resolved(対応済)は全タスクが完了のときだけ。done / rejected は人が決める。" +
|
|
50
50
|
"parent で親を付け替える(null で外す)。無い・自分・子孫・アーカイブ済みの親は 409 code: hierarchy_invalid(reason)、ほかの操作と重なれば 409 code: hierarchy_busy(やり直してよい)",
|
|
51
51
|
},
|
|
52
|
+
{
|
|
53
|
+
method: "PUT",
|
|
54
|
+
path: "/api/requests/:rid/child-order",
|
|
55
|
+
desc: "子の表示順の保存 {children: [直下の子の ID を全部、上から順に], rev?}(親の childOrder だけを書く。結果は {request, children})。" +
|
|
56
|
+
"重複・無い要望・直下の子でない・足りないは 409 code: child_order_invalid(reason・ids・今の並び children。子が変わっていれば読み直す)、rev が違えば 409 code: rev_conflict。" +
|
|
57
|
+
"表示の順で、実行の順・着手できるかは表さない",
|
|
58
|
+
},
|
|
52
59
|
{ method: "GET|POST", path: "/api/requests/:rid/tasks", desc: "要望のタスク(対応済の要望に未完了のタスクを足すと進行中に戻し reopened を返す。対応済の祖先も戻して reopenedAncestors、完了済の祖先は warnings の ancestor_done)" },
|
|
53
60
|
{ method: "GET|PATCH|DELETE", path: "/api/requests/:rid/tasks/:tid", desc: "タスク(GET は置き換えの印 superseded も返す。PATCH は rev で楽観ロック、null で項目を消す。置き換えられたタスクを作業中にすると warnings を添える)" },
|
|
54
61
|
{ method: "POST", path: "/api/requests/:rid/preflight", desc: "Preflight の実行 {engine?: codex|mock, note?: メモ}。前回の結果とまだ渡していないメモを引き継ぐ" },
|
package/lib/server/api/routes.js
CHANGED
|
@@ -17,7 +17,7 @@ import { UserConfigError } from "../../core/userConfig.js";
|
|
|
17
17
|
import { AI_MANIFEST } from "./manifest.js";
|
|
18
18
|
import { repoRoutes } from "./repoRoutes.js";
|
|
19
19
|
import { releaseNoteRoutes } from "./releaseNoteRoutes.js";
|
|
20
|
-
import { archiveTask, checkMilestoneRemoval, createRequest, createTask, updateRequest, updateTask } from "../../core/requestOps.js";
|
|
20
|
+
import { archiveTask, checkMilestoneRemoval, createRequest, createTask, orderChildren, updateRequest, updateTask } from "../../core/requestOps.js";
|
|
21
21
|
import { StaleInputError } from "../../core/preflight/input.js";
|
|
22
22
|
import { ChildConflictError, ChildDraftsChangedError, DraftConflictError, PulseInputError } from "../../core/preflight/service.js";
|
|
23
23
|
/**
|
|
@@ -59,6 +59,8 @@ const requestInput = z.object({
|
|
|
59
59
|
const requestPatch = requestInput
|
|
60
60
|
.partial()
|
|
61
61
|
.extend({ status: z.enum(REQUEST_STATUSES).optional(), rev: z.number().int().optional() });
|
|
62
|
+
/** 子の表示順: 直下の子の ID を全部、上から順に */
|
|
63
|
+
const childOrderInput = z.object({ children: z.array(z.string().min(1)), rev: z.number().int().optional() });
|
|
62
64
|
const projectPatch = z
|
|
63
65
|
.object({
|
|
64
66
|
name: z.string().min(1),
|
|
@@ -169,10 +171,13 @@ export function apiRoutes(ctx, opts = {}) {
|
|
|
169
171
|
app.route("/", releaseNoteRoutes(ctx));
|
|
170
172
|
// --- requests -------------------------------------------------------------
|
|
171
173
|
app.get("/requests", (c) => {
|
|
172
|
-
// ?parent=<ID>:
|
|
174
|
+
// ?parent=<ID>: 直下の子だけを、親の表示順(子の一覧・詳細と同じ)で。省くと更新の新しい順
|
|
173
175
|
const parent = c.req.query("parent");
|
|
174
176
|
const all = progress(ctx);
|
|
175
|
-
|
|
177
|
+
if (parent === undefined)
|
|
178
|
+
return c.json(all);
|
|
179
|
+
const rows = new Map(all.map((p) => [p.request.id, p]));
|
|
180
|
+
return c.json(hierarchyNow(ws).children(parent).flatMap((r) => rows.get(r.id) ?? []));
|
|
176
181
|
});
|
|
177
182
|
app.post("/requests", async (c) => {
|
|
178
183
|
const b = unnull(requestInput.parse(await c.req.json()));
|
|
@@ -197,6 +202,13 @@ export function apiRoutes(ctx, opts = {}) {
|
|
|
197
202
|
const { rev, ...patch } = requestPatch.parse(await c.req.json());
|
|
198
203
|
return c.json(await updateRequest(ctx, rid(c), unnull(patch), { expectedRev: expectedRev(c, { rev }), actor: actorOf(c) }));
|
|
199
204
|
});
|
|
205
|
+
/** 子の表示順(直下の子を全部、上から順に。CLI の request order と同じ操作) */
|
|
206
|
+
app.put("/requests/:rid/child-order", async (c) => {
|
|
207
|
+
const { children, rev } = childOrderInput.parse(await c.req.json());
|
|
208
|
+
const id = rid(c);
|
|
209
|
+
const r = await orderChildren(ctx, id, children, { expectedRev: expectedRev(c, { rev }), actor: actorOf(c) });
|
|
210
|
+
return c.json({ request: r, children: hierarchyNow(ws).children(id).map((k) => k.id) });
|
|
211
|
+
});
|
|
200
212
|
// --- tasks(要望の中) --------------------------------------------------------
|
|
201
213
|
app.get("/requests/:rid/tasks", (c) => {
|
|
202
214
|
const { status, area, q } = c.req.query();
|
package/lib/shared/hierarchy.js
CHANGED
|
@@ -6,8 +6,23 @@ import { REQUEST_ID } from "./refs.js";
|
|
|
6
6
|
/** 分割を検討する目安の想定タスク数(Preflight の評価で、これ以上なら分割する・しないの説明を必須にする) */
|
|
7
7
|
export const SPLIT_HINT_TASKS = 6;
|
|
8
8
|
const link = (r) => ({ id: r.id, title: r.title, status: r.status });
|
|
9
|
-
/** 作成日時の古い順 → ID
|
|
9
|
+
/** 作成日時の古い順 → ID(数を含む部分は数として比べる)。保存した順に無い子の並び */
|
|
10
10
|
export const byCreated = (a, b) => a.createdAt.localeCompare(b.createdAt) || a.id.localeCompare(b.id, undefined, { numeric: true });
|
|
11
|
+
/**
|
|
12
|
+
* 兄弟の並び(子の一覧・詳細・親で絞った一覧・進捗の木で共通)。order は親の childOrder。
|
|
13
|
+
* order にある今の子を order の順に先に並べ(重複は最初の1回)、order に無い子は作成日時の古い順 → ID で後ろに置く。
|
|
14
|
+
* order に残っている今は子でない ID(外した・付け替えた・アーカイブした・形の違う値)は無視する(ファイルは書き換えない)。
|
|
15
|
+
* 表示の順で、実行の順・着手できるかは表さない
|
|
16
|
+
*/
|
|
17
|
+
export function orderSiblings(kids, order) {
|
|
18
|
+
const pos = new Map();
|
|
19
|
+
for (const [i, id] of (order ?? []).entries())
|
|
20
|
+
if (!pos.has(id))
|
|
21
|
+
pos.set(id, i);
|
|
22
|
+
const listed = kids.filter((k) => pos.has(k.id)).sort((a, b) => pos.get(a.id) - pos.get(b.id));
|
|
23
|
+
const rest = kids.filter((k) => !pos.has(k.id)).sort(byCreated);
|
|
24
|
+
return [...listed, ...rest];
|
|
25
|
+
}
|
|
11
26
|
export class Hierarchy {
|
|
12
27
|
byId = new Map();
|
|
13
28
|
kids = new Map();
|
|
@@ -23,15 +38,15 @@ export class Hierarchy {
|
|
|
23
38
|
list.push(r);
|
|
24
39
|
this.kids.set(r.parent, list);
|
|
25
40
|
}
|
|
26
|
-
for (const list of this.kids
|
|
27
|
-
list.
|
|
41
|
+
for (const [pid, list] of this.kids)
|
|
42
|
+
this.kids.set(pid, orderSiblings(list, this.byId.get(pid)?.childOrder));
|
|
28
43
|
this.unreadable = new Set(src.unreadable ?? []);
|
|
29
44
|
this.archived = new Set(src.archived ?? []);
|
|
30
45
|
}
|
|
31
46
|
get(id) {
|
|
32
47
|
return this.byId.get(id);
|
|
33
48
|
}
|
|
34
|
-
/**
|
|
49
|
+
/** 直下の子(親の childOrder の順。無い子は作成日時の古い順 → ID。orderSiblings) */
|
|
35
50
|
children(id) {
|
|
36
51
|
return this.kids.get(id) ?? [];
|
|
37
52
|
}
|
package/package.json
CHANGED
package/skills/p3/SKILL.md
CHANGED
|
@@ -78,11 +78,15 @@ P3_ACTOR=ai:<エージェント名> p3 <コマンド> [引数] --json
|
|
|
78
78
|
`archive`)。拒否をタスクを偽って完了にする・ファイルを直接書き換えるなどで回避しない
|
|
79
79
|
7. コミットして push する。データのフォルダ(`whoami` の場所)がこの作業ツリーの中にあって git で管理されている(無視されていない)なら、
|
|
80
80
|
**要望のフォルダ(`<データのフォルダ>/requests/<要望ID>/`)の変更も実装と同じコミットに入れる**。要望とタスク・変更の記録が
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
コードと一緒に残り、後のレビュー(AI のレビューも)で、コードだけでなく「何を目的に頼まれ、何をしたか」を精査できる。
|
|
82
|
+
親子でつながる要望のフォルダも、まだコミットに入っていない変更があれば入れる: 子の要望なら**祖先の要望のフォルダ**(分割の採用・
|
|
83
|
+
子の順・状態は親に残る)、親を対応済にするときは**子孫の要望のフォルダ**(見送りにした子など、実装の無い要望)。それ以外の要望や
|
|
84
|
+
関係ない変更はまとめて add しない(`git status` でフォルダを確かめてから add する)。データのフォルダが外・別のリポジトリ・git で無視されている、または git の作業ツリー(worktree)で作業して
|
|
83
85
|
いてデータがメインの作業ツリーにあるときは、同じコミットには入らない(データの移動・写し・`git add -f` はしない。記録は p3 に
|
|
84
86
|
残り、コードとは成果物の URL で結ぶ)。commit・push に失敗したら、完了の記録はそのまま残し、公開できていないことをユーザーに
|
|
85
|
-
伝えてやり直す(完了を push
|
|
87
|
+
伝えてやり直す(完了を push できたことのように伝えない)。同じコミットに入れた要望のフォルダは、
|
|
88
|
+
マージするまで要望のブランチにしか無い。既定のブランチに切り替えると、その要望(子なら親の子の一覧からも)が消えたように見えるが、
|
|
89
|
+
データはブランチにある(作り直したり、別のブランチから写したりしない。親の詳細には `child_missing` が出る)
|
|
86
90
|
8. コミットや PR の URL を残すなら、後から `move T003 done --req <要望ID> --output <URL>` で足す(完了・記録・前の成果物はそのまま。
|
|
87
91
|
完了から戻さない)。要望のフォルダを同じコミットに入れているなら、この追記もコミットして同じブランチに push する(追記のコミット
|
|
88
92
|
自身の URL は残さなくてよい)。PR はユーザーに確認してから作る(本文に要望 ID とタスクの一覧)。作った PR の URL は最後のタスクに
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{G as t,d as n,lt as r}from"./appCtx-B-VRVOyv.js";var i=e(r(),1),a=t();function o({tabs:e,tab:t,unsaved:r,onSelect:o,label:s,prefix:c}){let l=(0,i.useRef)({});return(0,a.jsx)(`div`,{role:`tablist`,"aria-label":s,className:`flex gap-1 overflow-x-auto border-b border-slate-200 dark:border-slate-800`,onKeyDown:n=>{let r=e.findIndex(e=>e.id===t),i=n.key===`ArrowRight`?(r+1)%e.length:n.key===`ArrowLeft`?(r-1+e.length)%e.length:n.key===`Home`?0:n.key===`End`?e.length-1:-1;if(i<0)return;n.preventDefault();let a=e[i].id;o(a),l.current[a]?.focus()},children:e.map(e=>{let i=e.id===t;return(0,a.jsxs)(`button`,{ref:t=>{l.current[e.id]=t},type:`button`,role:`tab`,id:`${c}-tab-${e.id}`,"aria-selected":i,"aria-controls":`${c}-panel-${e.id}`,tabIndex:i?0:-1,title:e.hint,onClick:()=>o(e.id),className:n(`-mb-px flex shrink-0 items-center gap-1.5 border-b-2 px-3 py-2 font-medium whitespace-nowrap transition`,i?`border-indigo-600 text-indigo-700 dark:border-indigo-400 dark:text-indigo-300`:`border-transparent text-slate-500 hover:text-slate-800 dark:text-slate-400 dark:hover:text-slate-200`),children:[e.label,r?.[e.id]&&(0,a.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-400`,title:`保存していない変更があります`,children:[`●`,(0,a.jsx)(`span`,{className:`sr-only`,children:`(未保存)`})]})]},e.id)})})}function s({id:e,tab:t,prefix:n,className:r,children:i}){return(0,a.jsx)(`div`,{role:`tabpanel`,id:`${n}-panel-${e}`,"aria-labelledby":`${n}-tab-${e}`,hidden:e!==t,className:r,children:i})}export{o as n,s as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e,n,r){let i=new Map(e.map(e=>[e.request.id,e])),a=new Set(n.map(e=>e.request.id)),o=new Map;for(let e of n){o.set(e.request.id,e);let t=new Set([e.request.id]);for(let n=e.request.parent;n&&!t.has(n);n=i.get(n)?.request.parent){t.add(n);let e=i.get(n);if(!e)break;o.set(n,e)}}let s=new Map;n.forEach((e,t)=>s.set(e.request.id,t));let c=e=>{if(s.has(e))return s.get(e);s.set(e,2**53-1);let t=[...o.values()].filter(t=>t.request.parent===e).map(e=>c(e.request.id)),n=t.length?Math.min(...t):2**53-1;return s.set(e,n),n};for(let e of o.keys())c(e);let l=[...o.values()].sort((e,t)=>s.get(e.request.id)-s.get(t.request.id)),u=new Map,d=[];for(let e of l){let n=e.request.parent;n&&o.has(n)&&!t(i,e.request.id)?(u.get(n)??u.set(n,[]).get(n)).push(e):d.push(e)}let f=[],p=new Set,m=(e,t)=>{if(p.has(e.request.id))return;p.add(e.request.id);let n=u.get(e.request.id)??[],i=r.has(e.request.id);if(f.push({p:e,depth:t,context:!a.has(e.request.id),hasChildren:n.length>0,collapsed:i}),!i)for(let e of n)m(e,t+1)};for(let e of d)m(e,0);return f}function t(e,t){let n=new Set;for(let r=e.get(t)?.request.parent;r&&!n.has(r);r=e.get(r)?.request.parent){if(r===t)return!0;n.add(r)}return!1}function n(e,t){if(!t)return[...e];let n=new Set([t]);for(let t=!0;t;){t=!1;for(let r of e)r.parent&&n.has(r.parent)&&!n.has(r.id)&&(n.add(r.id),t=!0)}return e.filter(e=>!n.has(e.id))}export{e as n,n as t};
|