cognitune 0.2.1 → 0.3.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.
Files changed (77) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +2 -0
  3. package/SETUP.md +111 -0
  4. package/dist/cli.js +153 -14
  5. package/dist/web/assets/{Map-DyU40kFC.js → Map-pFoOaroM.js} +1 -1
  6. package/dist/web/assets/{Practice-Xw4Aap9n.js → Practice-DJ_GeEEw.js} +3 -3
  7. package/dist/web/assets/{_baseUniq-Sb6_kXmC.js → _baseUniq-Cgcxu-ug.js} +1 -1
  8. package/dist/web/assets/{architectureDiagram-UYN6MBPD-x3eTjV-t.js → architectureDiagram-UYN6MBPD-F11egvO5.js} +1 -1
  9. package/dist/web/assets/{blockDiagram-ZHA2E4KO-agwz5ZWE.js → blockDiagram-ZHA2E4KO-DcLwUr6e.js} +1 -1
  10. package/dist/web/assets/{c4Diagram-6F5ED5ID-CJxB9Ung.js → c4Diagram-6F5ED5ID-DoK6LsEW.js} +1 -1
  11. package/dist/web/assets/channel-cS78OL1L.js +1 -0
  12. package/dist/web/assets/{chunk-5HRBRIJM-f0vN99nH.js → chunk-5HRBRIJM-BZZC4mrX.js} +1 -1
  13. package/dist/web/assets/{chunk-7U56Z5CX-BM--ABPc.js → chunk-7U56Z5CX-CRQL1BaD.js} +1 -1
  14. package/dist/web/assets/{chunk-ASOPGD6M-CR8uj1YE.js → chunk-ASOPGD6M-MyeXPUAo.js} +1 -1
  15. package/dist/web/assets/{chunk-KFBOBJHC-5IsURXrq.js → chunk-KFBOBJHC-ivtJnQTl.js} +1 -1
  16. package/dist/web/assets/{chunk-T2TOU4HS-Byx0enoR.js → chunk-T2TOU4HS-DfaWwXAy.js} +1 -1
  17. package/dist/web/assets/{chunk-TMUBEWPD-BIF411CX.js → chunk-TMUBEWPD-1vGEp44G.js} +1 -1
  18. package/dist/web/assets/classDiagram-LNE6IOMH-BV-X_A98.js +1 -0
  19. package/dist/web/assets/classDiagram-v2-MQ7JQ4JX-BV-X_A98.js +1 -0
  20. package/dist/web/assets/clone-CX7XQP1C.js +1 -0
  21. package/dist/web/assets/{dagre-4EVJKHTY-1RD8lskl.js → dagre-4EVJKHTY-BzJqGMK1.js} +1 -1
  22. package/dist/web/assets/{diagram-QW4FP2JN-PO1Q65My.js → diagram-QW4FP2JN-DserUmhH.js} +1 -1
  23. package/dist/web/assets/{erDiagram-6RL3IURR-Cr2hBiWe.js → erDiagram-6RL3IURR-BeMwcZZW.js} +1 -1
  24. package/dist/web/assets/{flowDiagram-7ASYPVHJ-ClDedrj1.js → flowDiagram-7ASYPVHJ-C2Qt1H4b.js} +1 -1
  25. package/dist/web/assets/{ganttDiagram-NTVNEXSI-D13tzRyI.js → ganttDiagram-NTVNEXSI-DjG6T96W.js} +1 -1
  26. package/dist/web/assets/{gitGraph-YCYPL57B-BsavMmM6.js → gitGraph-YCYPL57B-C92c8R4j.js} +1 -1
  27. package/dist/web/assets/{gitGraphDiagram-NRZ2UAAF-DIucBoe8.js → gitGraphDiagram-NRZ2UAAF-C0OK2-pl.js} +1 -1
  28. package/dist/web/assets/{graph-CClVjaHZ.js → graph-jcgmh1Ot.js} +1 -1
  29. package/dist/web/assets/{index-Cv-pFH6x.js → index-B05Rh3LW.js} +1 -1
  30. package/dist/web/assets/{index-D91GOqgw.js → index-BD8q1ij7.js} +1 -1
  31. package/dist/web/assets/{index-Dls_C4WS.js → index-BJepU7_w.js} +1 -1
  32. package/dist/web/assets/{index-CS1X9Gl5.js → index-BPFm8xBn.js} +1 -1
  33. package/dist/web/assets/{index-DBSUkj1m.js → index-BTAmHv-d.js} +1 -1
  34. package/dist/web/assets/index-Bs71achu.js +509 -0
  35. package/dist/web/assets/{index-DUIbUB4M.js → index-BtCLkneo.js} +1 -1
  36. package/dist/web/assets/{index-DkYraAal.js → index-CW1WHdXq.js} +1 -1
  37. package/dist/web/assets/{index-DDrV_F4m.js → index-CfFkiEw9.js} +1 -1
  38. package/dist/web/assets/{index-SjGg9_vE.js → index-D-9XGv5u.js} +1 -1
  39. package/dist/web/assets/{index-o9r5KATO.js → index-D3Zk0Btz.js} +1 -1
  40. package/dist/web/assets/{index-2r9n9DTs.js → index-D5AcpGl_.js} +1 -1
  41. package/dist/web/assets/{index-D45gW5O5.js → index-D8PR6AHG.js} +1 -1
  42. package/dist/web/assets/{index-DRtWlWMo.js → index-DB9Tltht.js} +1 -1
  43. package/dist/web/assets/{index-B_vWzZYC.js → index-DIV7qBvA.js} +1 -1
  44. package/dist/web/assets/{index-CMZRuo_o.js → index-DJ7YtDlC.js} +1 -1
  45. package/dist/web/assets/{index-ByIxB7D0.js → index-DM-V8yrZ.js} +1 -1
  46. package/dist/web/assets/index-DajatLhQ.css +1 -0
  47. package/dist/web/assets/{index-DxsK976j.js → index-DgTHE4KH.js} +1 -1
  48. package/dist/web/assets/{index-B3eGs35g.js → index-DgVZUoYY.js} +1 -1
  49. package/dist/web/assets/{index-BqYXODG4.js → index-H4qir-5V.js} +1 -1
  50. package/dist/web/assets/{index-eIlS8nUF.js → index-HBtEhFV8.js} +1 -1
  51. package/dist/web/assets/{index-BOSsA0NJ.js → index-TRTMCU2f.js} +1 -1
  52. package/dist/web/assets/{index-6LcRt5Lv.js → index-a7yJqPRD.js} +1 -1
  53. package/dist/web/assets/{infoDiagram-A4XQUW5V-DAnVWlAh.js → infoDiagram-A4XQUW5V-DqkPyvzP.js} +1 -1
  54. package/dist/web/assets/{journeyDiagram-G5WM74LC-pfkLfgwO.js → journeyDiagram-G5WM74LC-CPoGO9lU.js} +1 -1
  55. package/dist/web/assets/{kanban-definition-QRCXZQQD-ntmo18GF.js → kanban-definition-QRCXZQQD-DhYcbXpZ.js} +1 -1
  56. package/dist/web/assets/{layout-B4CWy8Hm.js → layout-D3h_RNbG.js} +1 -1
  57. package/dist/web/assets/{mermaid.core-lBUDS75V.js → mermaid.core-QonkHgY_.js} +4 -4
  58. package/dist/web/assets/{min-DbZdLDS_.js → min-u5yV8FH_.js} +1 -1
  59. package/dist/web/assets/{mindmap-definition-GWI6TPTV-Bl9WyGjM.js → mindmap-definition-GWI6TPTV-7qne4US6.js} +1 -1
  60. package/dist/web/assets/{pieDiagram-YF2LJOPJ-DnH09lh-.js → pieDiagram-YF2LJOPJ-CYjuzLxS.js} +1 -1
  61. package/dist/web/assets/{quadrantDiagram-OS5C2QUG-BxEAU4LU.js → quadrantDiagram-OS5C2QUG-iNs3hmmI.js} +1 -1
  62. package/dist/web/assets/{requirementDiagram-MIRIMTAZ-QAvHb6Mc.js → requirementDiagram-MIRIMTAZ-tDYOd2xQ.js} +1 -1
  63. package/dist/web/assets/{sankeyDiagram-Y46BX6SQ-eS48EBnq.js → sankeyDiagram-Y46BX6SQ-Ce34Wa1G.js} +1 -1
  64. package/dist/web/assets/{sequenceDiagram-G6AWOVSC-CzMqlsbJ.js → sequenceDiagram-G6AWOVSC-i7VCqMq3.js} +1 -1
  65. package/dist/web/assets/{stateDiagram-MAYHULR4-xkap43Xx.js → stateDiagram-MAYHULR4-BSREATU6.js} +1 -1
  66. package/dist/web/assets/stateDiagram-v2-4JROLMXI-CtOZAypx.js +1 -0
  67. package/dist/web/assets/{timeline-definition-U7ZMHBDA-BAuokBbp.js → timeline-definition-U7ZMHBDA-DgAweJ73.js} +1 -1
  68. package/dist/web/assets/{xychartDiagram-6QU3TZC5-Cnc3AQRt.js → xychartDiagram-6QU3TZC5-DxWMJtPc.js} +1 -1
  69. package/dist/web/index.html +2 -2
  70. package/package.json +2 -1
  71. package/dist/web/assets/channel-BBLQ9UF8.js +0 -1
  72. package/dist/web/assets/classDiagram-LNE6IOMH-BtyOxYYt.js +0 -1
  73. package/dist/web/assets/classDiagram-v2-MQ7JQ4JX-BtyOxYYt.js +0 -1
  74. package/dist/web/assets/clone-qT-pKr2u.js +0 -1
  75. package/dist/web/assets/index-Biw9rLAa.css +0 -1
  76. package/dist/web/assets/index-ChTnBaTd.js +0 -493
  77. package/dist/web/assets/stateDiagram-v2-4JROLMXI-T7PcvgVe.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.0 (2026-11-18)
4
+
5
+ New:
6
+
7
+ - **Lens follow-ups.** "Ask more about this" at the end of a lens adds the answer to the same
8
+ lens instead of making a new one. Ticked files can come along as extra context; new terms and
9
+ gotchas join the lens's lists, and the markdown export includes the follow-ups.
10
+ - **Weak spots page.** A Weak spots tab in the Library: quiz yourself on one weak spot, or
11
+ dismiss one the grader got wrong. Today links to it.
12
+ - **Walk "Try again".** A block you didn't get right can be answered again; a right answer
13
+ clears its weak spot.
14
+ - **Jobs in the status bar.** Running jobs show at the bottom of the window, and a job that
15
+ finishes after you left its page shows a "ready · open" link.
16
+ - **Tutor chat** is restyled as chat bubbles with timestamps, and "line 42" / "lines 64-71" in a
17
+ hint jump the code pane to those lines.
18
+ - Teach-back and the tutor, started from the Changes page, now see the diff (only lens and quiz
19
+ did before). The tutor sees it on every turn.
20
+ - A review card links back to the lens or quiz it came from.
21
+ - `.claude` folders show in the Explore file tree, so session notes can be ticked as context.
22
+
23
+ Fixes:
24
+
25
+ - The tutor's replies rendered at 17px next to 14px user messages: the serif reading-font rule
26
+ out-ranked the chat styles. Both now match.
27
+ - The lens page flickered while a job ran: every mermaid diagram and code block was remounted
28
+ twice a second. Markdown rendering now keeps them mounted.
29
+ - Syntax highlighting now works in the Changes diff view, in fenced code blocks inside lens and
30
+ quiz prose, and in bug hunt's code copy (each was plain text before, for different reasons).
31
+ - File-chip lists on the quiz, teach-back and tutor pages collapse to 6 + "N more", like the
32
+ lens page.
33
+ - The Library's tabs fit on one row instead of scrolling sideways (a narrow window wraps them),
34
+ and a path stop's button says what it starts ("Start the lens") instead of "Do this stop".
35
+
36
+ ## 0.2.2 (2026-11-10)
37
+
38
+ Release workflow fix, no feature changes:
39
+
40
+ - `npm publish` is now followed by a check against the registry: if it reports failure but the
41
+ version is actually live (seen once, as a retry conflict with a leftover staged version), the
42
+ release still completes instead of falsely failing before the GitHub Release step.
43
+
3
44
  ## 0.2.1 (2026-11-10)
4
45
 
5
46
  Repo housekeeping, no feature changes:
package/README.md CHANGED
@@ -10,6 +10,8 @@ npx cognitune ./my-repo
10
10
  npx cognitune --demo # a sample repo and canned answers: see every page in a minute, no model needed
11
11
  ```
12
12
 
13
+ Full install/setup guide (model backends, data layout, a shell shortcut): [SETUP.md](SETUP.md).
14
+
13
15
  | | |
14
16
  |---|---|
15
17
  | ![Open a folder](assets/screenshots/projects.png) | ![A lens over real code](assets/screenshots/lens.png) |
package/SETUP.md ADDED
@@ -0,0 +1,111 @@
1
+ # Setup
2
+
3
+ ## 1. Install
4
+
5
+ ```bash
6
+ # No install — always runs the latest published version
7
+ npx cognitune ./my-repo
8
+
9
+ # Or install once, then just run `cognitune` from anywhere
10
+ npm install -g cognitune
11
+ ```
12
+
13
+ Needs Node >= 20 (`node -v` to check).
14
+
15
+ ## 2. Pick a model backend
16
+
17
+ cognitune drives a coding CLI you already use — it never asks for or stores a key itself. It
18
+ picks the first one it finds, in this order, or you can pin one in Settings:
19
+
20
+ | Backend | One-time setup | Used as |
21
+ |---|---|---|
22
+ | Claude Code (default) | already logged into `claude` | `claude -p`, read-only tools |
23
+ | OpenAI Codex | `codex login` | `codex exec -`, sandboxed read-only |
24
+ | GitHub Copilot | Copilot login, or `export COPILOT_GITHUB_TOKEN=...` | `copilot -p -s`, read-only |
25
+ | Anthropic API directly | `export ANTHROPIC_API_KEY=...` | Messages API |
26
+
27
+ No model set up yet? Run with `--demo` first — canned answers, no login needed, good for a
28
+ first look at every page.
29
+
30
+ ## 3. Run it on a project
31
+
32
+ Say your code lives under a workspace folder, like:
33
+
34
+ ```
35
+ ~/repos/
36
+ ├── awesome-app/
37
+ │ ├── src/
38
+ │ └── package.json
39
+ └── another-project/
40
+ ```
41
+
42
+ Point cognitune at the one you want to understand:
43
+
44
+ ```bash
45
+ cd ~/repos/awesome-app
46
+ cognitune . # opens the browser automatically at http://127.0.0.1:4711
47
+
48
+ # or from anywhere, without cd'ing in first:
49
+ cognitune ~/repos/awesome-app
50
+ ```
51
+
52
+ Your source files are only ever read, never written — practice and bug-hunt exercises work on
53
+ a throwaway copy.
54
+
55
+ ### CLI flags
56
+
57
+ ```
58
+ cognitune [folder] [--port 4711] [--host 127.0.0.1] [--no-open] [--demo]
59
+ ```
60
+
61
+ ## 4. Shell shortcut
62
+
63
+ The CLI is already just `cognitune`, so the shortcut worth having is "run it on wherever I
64
+ currently am":
65
+
66
+ ```bash
67
+ # ~/.bashrc (or ~/.zshrc)
68
+ alias cg='cognitune .'
69
+ ```
70
+
71
+ ```bash
72
+ cd ~/repos/awesome-app && cg
73
+ ```
74
+
75
+ ## 5. Where your data lives
76
+
77
+ Everything cognitune makes is plain JSON files under one home folder — nothing is written
78
+ anywhere else on disk:
79
+
80
+ ```
81
+ ~/.cognitune/ (change with COGNITUNE_HOME)
82
+ ├── settings.json model backend, storage limits
83
+ ├── projects.json known projects (path, id, last opened)
84
+ ├── cache/ model replies, reused on an unchanged file
85
+ ├── archive/ forgotten projects (kept storage.archiveDays, default 30)
86
+ └── projects/
87
+ └── <project-id>/
88
+ ├── lenses/ one file per lens you've made
89
+ ├── quizzes/
90
+ ├── practice/
91
+ ├── teachbacks/
92
+ ├── hunts/ bug-hunt exercises
93
+ ├── walks/ walkthrough progress
94
+ ├── threads/ tutor chat history
95
+ ├── cards/ spaced-repetition review cards
96
+ ├── misconceptions/ weak-spot beliefs behind wrong answers
97
+ ├── notes/ margin notes pinned to lines
98
+ ├── paths/ learning-path progress
99
+ ├── contexts/ extra folders added to this project
100
+ └── archive/ this project's own deleted items
101
+ ```
102
+
103
+ Settings > Storage shows the size of each folder and has a one-click cleanup; nothing grows
104
+ without a cap (see the README's "Your files are safe" section for the exact limits).
105
+
106
+ ## Troubleshooting
107
+
108
+ - **Port already in use** — `cognitune --port 4799` (or whatever's free).
109
+ - **"No model found"** — none of the four backends above are set up; use `--demo` to confirm
110
+ the UI itself works, then set one up.
111
+ - **Try it with no real project yet** — `cognitune --demo` opens a small bundled sample repo.
package/dist/cli.js CHANGED
@@ -157,6 +157,15 @@ var FakeAgent = class {
157
157
  ]
158
158
  };
159
159
  }
160
+ case "lensMore": {
161
+ const q = /^FOLLOW-UP QUESTION: (.*)$/m.exec(prompt)?.[1] ?? "";
162
+ return {
163
+ answer: `Fake answer to "${q}": line 3 is where it happens.`,
164
+ deepDives: [{ title: "Line 3 answers the follow-up", file, line: 3, startLine: 2, endLine: 5, body: "The fake step for the follow-up." }],
165
+ concepts: [{ term: "Follow-up term", explain: "A term the first lesson did not define." }],
166
+ gotchas: ["Line 4 is easy to miss."]
167
+ };
168
+ }
160
169
  case "walkPlan":
161
170
  return { blocks: [1, 2].map((i) => ({ startLine: i, endLine: i + 2, title: `Block ${i} does one thing`, covers: ["a fact"], example: "n = 3", question: "what happens for n = 3?" })) };
162
171
  case "walkBlocks": {
@@ -1267,7 +1276,7 @@ function listFiles(root) {
1267
1276
  return;
1268
1277
  }
1269
1278
  for (const e of entries) {
1270
- if (e.name.startsWith(".") && e.name !== ".github") continue;
1279
+ if (e.name.startsWith(".") && e.name !== ".github" && e.name !== ".claude") continue;
1271
1280
  const p = join6(dir, e.name);
1272
1281
  if (e.isDirectory()) {
1273
1282
  if (!SKIP_DIRS.has(e.name)) walk2(p);
@@ -1922,6 +1931,42 @@ ${x.diff}
1922
1931
  ` : ""}${x.notes ? `THE LEARNER'S NOTES:
1923
1932
  ${x.notes}
1924
1933
 
1934
+ ` : ""}CODE:
1935
+ ${files}`;
1936
+ }
1937
+ function lensMoreSystem(depth = "standard") {
1938
+ const d = DEPTH[depth];
1939
+ return `TASK: lensMore
1940
+ You add to an existing "lens" (a lesson that teaches code). The learner read it and asked a FOLLOW-UP question.
1941
+ Answer that question, building on what the lesson already says; do not repeat it. If the answer needs code walked
1942
+ through, add new steps that point at real lines. If the question is about files that are new to the lesson, use them.
1943
+
1944
+ ${TEACH}
1945
+ ${STYLE}
1946
+
1947
+ JSON shape:
1948
+ {
1949
+ "answer": "markdown: the direct answer to the follow-up, 1-4 short paragraphs or a list",
1950
+ "deepDives": [{
1951
+ "title": "the idea of this step as a claim",
1952
+ "file": "relative/path", "startLine": 10, "endLine": 24, "line": 12, // a SHORT range (3-25 lines)
1953
+ "body": "markdown, up to ${d.words} words, in short paragraphs",
1954
+ "pitfall": "optional: a mistake people make here",
1955
+ "check": {"q": "a question that needs reasoning", "a": "the answer, 1-2 sentences"}
1956
+ }], // 0-4 items; empty when the answer alone is enough
1957
+ "concepts": [{"term": "name", "explain": "1-2 plain sentences", "example": "tiny example", "file": "relative/path", "line": 12}], // 0-3 terms the lesson does NOT already define
1958
+ "gotchas": ["a NEW trap, 1 sentence, with the line"] // 0-3 items, not already in the lesson
1959
+ }`;
1960
+ }
1961
+ function lensMorePrompt(question, lesson, files, notes) {
1962
+ return `FOLLOW-UP QUESTION: ${question}
1963
+
1964
+ THE LESSON SO FAR (do not repeat it):
1965
+ ${lesson}
1966
+
1967
+ ${notes ? `THE LEARNER'S NOTES:
1968
+ ${notes}
1969
+
1925
1970
  ` : ""}CODE:
1926
1971
  ${files}`;
1927
1972
  }
@@ -2037,11 +2082,14 @@ ${STYLE}
2037
2082
  JSON shape:
2038
2083
  { "score": 4, "summary": "1-2 sentences", "right": ["..."], "missing": ["..."], "wrong": ["..."] }`;
2039
2084
  }
2040
- function teachbackPrompt(text2, files) {
2085
+ function teachbackPrompt(text2, files, diff) {
2041
2086
  return `THE LEARNER'S EXPLANATION:
2042
2087
  ${text2}
2043
2088
 
2044
- CODE:
2089
+ ${diff ? `THE CHANGE THEY ARE EXPLAINING (unified diff):
2090
+ ${diff}
2091
+
2092
+ ` : ""}CODE:
2045
2093
  ${files}`;
2046
2094
  }
2047
2095
  function tutorSystem(level, tell) {
@@ -2057,7 +2105,7 @@ Return ONLY one JSON object inside a single \`\`\`json fence.
2057
2105
  JSON shape:
2058
2106
  { "reply": "markdown" }`;
2059
2107
  }
2060
- function tutorPrompt(history, files, notes) {
2108
+ function tutorPrompt(history, files, notes, diff) {
2061
2109
  const h = history.map((m) => `${m.role === "user" ? "LEARNER" : "TUTOR"}: ${m.text}`).join("\n\n");
2062
2110
  return `CONVERSATION SO FAR:
2063
2111
  ${h}
@@ -2065,6 +2113,9 @@ ${h}
2065
2113
  ${notes ? `THE LEARNER'S NOTES:
2066
2114
  ${notes}
2067
2115
 
2116
+ ` : ""}${diff ? `THE CHANGE BEING DISCUSSED (unified diff):
2117
+ ${diff}
2118
+
2068
2119
  ` : ""}CODE:
2069
2120
  ${files}`;
2070
2121
  }
@@ -2253,6 +2304,7 @@ var SCHEMAS = {
2253
2304
  }),
2254
2305
  lensIntro: z.object({ summary: text, intuition: text.optional() }),
2255
2306
  lensSteps: z.object({ steps: z.array(z.object({ body: text })).min(1) }),
2307
+ lensMore: z.object({ answer: text.min(1), deepDives: z.array(z.object({ title: text, body: text })).optional() }),
2256
2308
  plan: z.object({ outline: text.min(10) }),
2257
2309
  lensSketch: z.object({ differences: z.array(text).min(1) }),
2258
2310
  lensTrace: z.object({
@@ -2441,6 +2493,61 @@ ${old.deepDives.map((d) => `- ${d.title}`).join("\n")}` : void 0,
2441
2493
  if (old) this.store.archive(project.id, "lenses", old.id);
2442
2494
  return lens;
2443
2495
  }
2496
+ /**
2497
+ * A follow-up question on a lens, answered on top of it: the reply becomes a new follow-up section,
2498
+ * its new terms and traps join the lens's own lists, and any extra files join the lens.
2499
+ */
2500
+ async lensMore(project, id, req) {
2501
+ const ws = new Workspace(project);
2502
+ const l = this.store.get(project.id, "lenses", id);
2503
+ if (!l) throw new Error("lens not found");
2504
+ const question = (req.question ?? "").trim().slice(0, 4e3);
2505
+ if (!question) throw new Error("ask a question first");
2506
+ const extra = [...new Set((req.files ?? []).map((f) => ws.guard(f)))].filter((f) => !l.files.includes(f));
2507
+ const files = [...l.files, ...extra];
2508
+ const lesson = [
2509
+ `Title: ${l.title}`,
2510
+ l.tldr && `Idea: ${l.tldr}`,
2511
+ `Summary: ${l.summary}`,
2512
+ l.concepts.length && `Terms already defined: ${l.concepts.map((c) => c.term).join(", ")}`,
2513
+ `Steps:
2514
+ ${l.deepDives.map((d) => `- ${d.title}`).join("\n")}`,
2515
+ l.gotchas?.length && `Gotchas:
2516
+ ${l.gotchas.map((g) => `- ${g}`).join("\n")}`,
2517
+ ...(l.followUps ?? []).map((f) => `Earlier follow-up: ${f.question}
2518
+ Answer: ${f.answer.slice(0, 1200)}`)
2519
+ ].filter(Boolean).join("\n\n").slice(0, 12e3);
2520
+ const raw = await this.ask(
2521
+ ws,
2522
+ ["lensMore"],
2523
+ lensMoreSystem(l.depth),
2524
+ lensMorePrompt(question, lesson, this.bundle(ws, files), this.notes(ws, files))
2525
+ );
2526
+ const known = new Set(l.concepts.map((c) => c.term.toLowerCase()));
2527
+ const concepts = arr(raw.concepts).map((c) => {
2528
+ const o = c;
2529
+ return { term: str(o.term, 120), explain: str(o.explain), example: str(o.example, 1e3) || void 0, file: ws.absFromRel(str(o.file, 500)), line: num(o.line) };
2530
+ }).filter((c) => c.term && !known.has(c.term.toLowerCase())).slice(0, 3);
2531
+ const gotchas = strs(raw.gotchas, 400, 3).filter((g) => !l.gotchas?.includes(g));
2532
+ const next = {
2533
+ ...l,
2534
+ files,
2535
+ fileHashes: { ...this.hashes(ws, extra), ...l.fileHashes },
2536
+ concepts: [...l.concepts, ...concepts],
2537
+ gotchas: [...l.gotchas ?? [], ...gotchas],
2538
+ followUps: [
2539
+ ...l.followUps ?? [],
2540
+ {
2541
+ at: now(),
2542
+ question,
2543
+ files: extra,
2544
+ answer: str(raw.answer, 12e3),
2545
+ deepDives: arr(raw.deepDives).map((d) => cleanDive(d, ws)).filter((d) => d.title || d.body).slice(0, 4)
2546
+ }
2547
+ ]
2548
+ };
2549
+ return this.store.put(project.id, "lenses", next);
2550
+ }
2444
2551
  /**
2445
2552
  * A lens in parts instead of one call: the planner outlines (title, tldr, every step with its lines and
2446
2553
  * what it must cover), then the writer fills in the opening and the steps, a few steps per call, side by
@@ -2512,7 +2619,8 @@ ${old.deepDives.map((d) => `- ${d.title}`).join("\n")}` : void 0,
2512
2619
  async quiz(project, req) {
2513
2620
  const ws = new Workspace(project);
2514
2621
  const lens = req.lensId ? this.store.get(project.id, "lenses", req.lensId) : void 0;
2515
- const weak = req.weak ? openMisconceptions(this.store, project.id).slice(0, 6) : [];
2622
+ const pick = req.weakIds?.length ? new Set(req.weakIds) : void 0;
2623
+ const weak = req.weak ? openMisconceptions(this.store, project.id).filter((m) => !pick || pick.has(m.id)).slice(0, 6) : [];
2516
2624
  if (req.weak && !weak.length) throw new Error("no open weak spots: nothing to aim at yet");
2517
2625
  const weakFiles = weak.map((m) => m.file).filter((f) => !!f);
2518
2626
  const files = [...new Set((req.files.length ? req.files : lens?.files ?? weakFiles).map((f) => ws.guard(f)))];
@@ -2683,7 +2791,12 @@ ${this.bundle(ws, paths.filter((f) => DATA.test(f)))}` : "");
2683
2791
  if (!files.length) throw new Error("pick at least one file");
2684
2792
  const text2 = (req.text ?? "").trim().slice(0, 2e4);
2685
2793
  if (text2.length < 20) throw new Error("write a few sentences first");
2686
- const raw = await this.ask(ws, ["teachback"], teachbackSystem(), teachbackPrompt(text2, this.bundle(ws, files)));
2794
+ const raw = await this.ask(
2795
+ ws,
2796
+ ["teachback"],
2797
+ teachbackSystem(),
2798
+ teachbackPrompt(text2, this.bundle(ws, files), this.diffText(ws, req.diff, files))
2799
+ );
2687
2800
  const t = {
2688
2801
  id: newId(),
2689
2802
  projectId: project.id,
@@ -2691,6 +2804,7 @@ ${this.bundle(ws, paths.filter((f) => DATA.test(f)))}` : "");
2691
2804
  files,
2692
2805
  fileHashes: this.hashes(ws, files),
2693
2806
  text: text2,
2807
+ diff: req.diff,
2694
2808
  grade: {
2695
2809
  score: Math.min(5, Math.max(1, num(raw.score) ?? 1)),
2696
2810
  summary: str(raw.summary, 800),
@@ -2710,7 +2824,7 @@ ${this.bundle(ws, paths.filter((f) => DATA.test(f)))}` : "");
2710
2824
  if (!files.length) throw new Error("pick at least one file");
2711
2825
  const text2 = (req.text ?? "").trim();
2712
2826
  if (!text2) throw new Error("ask a question first");
2713
- const t = { id: newId(), projectId: project.id, createdAt: now(), title: text2.split("\n")[0].slice(0, 80), files, messages: [] };
2827
+ const t = { id: newId(), projectId: project.id, createdAt: now(), title: text2.split("\n")[0].slice(0, 80), files, diff: req.diff, messages: [] };
2714
2828
  return this.tutorTurn(project, t, text2, false);
2715
2829
  }
2716
2830
  async tutorReply(project, id, text2, tell) {
@@ -2724,7 +2838,12 @@ ${this.bundle(ws, paths.filter((f) => DATA.test(f)))}` : "");
2724
2838
  t.messages.push({ role: "user", text: text2.slice(0, 8e3), at: now() });
2725
2839
  const since = t.messages.slice(t.messages.map((m) => m.hintLevel === 4).lastIndexOf(true) + 1);
2726
2840
  const level = Math.min(3, since.filter((m) => m.role === "tutor").length + 1);
2727
- const raw = await this.ask(ws, ["tutor"], tutorSystem(level, tell), tutorPrompt(t.messages, this.bundle(ws, t.files), this.notes(ws, t.files)));
2841
+ const raw = await this.ask(
2842
+ ws,
2843
+ ["tutor"],
2844
+ tutorSystem(level, tell),
2845
+ tutorPrompt(t.messages, this.bundle(ws, t.files), this.notes(ws, t.files), this.diffText(ws, t.diff, t.files))
2846
+ );
2728
2847
  t.messages.push({ role: "tutor", text: str(raw.reply, 8e3), at: now(), hintLevel: tell ? 4 : level });
2729
2848
  if (t.messages.length > THREAD_MESSAGE_CAP) t.messages = [t.messages[0], ...t.messages.slice(-(THREAD_MESSAGE_CAP - 1))];
2730
2849
  return this.store.put(project.id, "threads", t);
@@ -3048,19 +3167,31 @@ function lensMarkdown(l, ws) {
3048
3167
  });
3049
3168
  out.push("");
3050
3169
  }
3051
- if (l.deepDives.length) {
3052
- out.push("## Deep dives", "");
3053
- for (const d of l.deepDives) {
3170
+ const dives = (list, h) => {
3171
+ for (const d of list) {
3054
3172
  const where = d.file ? ` (${ws.rel(d.file)}${d.startLine ? `:${d.startLine}-${d.endLine}` : d.line ? `:${d.line}` : ""})` : "";
3055
- out.push(`### ${d.title}${where}`, "", d.body, "");
3173
+ out.push(`${h} ${d.title}${where}`, "", d.body, "");
3056
3174
  if (d.pitfall) out.push(`> **Pitfall:** ${d.pitfall}`, "");
3057
3175
  if (d.check) out.push(`<details><summary>Check yourself: ${d.check.q}</summary>
3058
3176
 
3059
3177
  ${d.check.a}
3060
3178
  </details>`, "");
3061
3179
  }
3180
+ };
3181
+ if (l.deepDives.length) {
3182
+ out.push("## Deep dives", "");
3183
+ dives(l.deepDives, "###");
3062
3184
  }
3063
3185
  if (l.gotchas?.length) out.push("## Gotchas", "", ...l.gotchas.map((g) => `- ${g}`), "");
3186
+ if (l.followUps?.length) {
3187
+ out.push("## Follow-ups", "");
3188
+ for (const f of l.followUps) {
3189
+ out.push(`### ${f.question}`, "");
3190
+ if (f.files.length) out.push(`*Added context:* ${f.files.map((p) => `\`${ws.rel(p)}\``).join(", ")}`, "");
3191
+ out.push(f.answer, "");
3192
+ dives(f.deepDives, "####");
3193
+ }
3194
+ }
3064
3195
  if (l.nextSteps?.length) out.push("## Read next", "", ...l.nextSteps.map((n) => `- \`${ws.rel(n.file)}\`: ${n.why}`), "");
3065
3196
  return out.join("\n");
3066
3197
  }
@@ -3203,6 +3334,14 @@ function createApi(store2, opts2 = {}) {
3203
3334
  if (!store2.get(p.id, "lenses", id)) return fail(c, 404, "lens not found");
3204
3335
  return startJob(c, "lens", p, (l) => l.lens(p, { files: [], kind: "", refreshOf: id }));
3205
3336
  });
3337
+ api.post("/projects/:pid/lenses/:id/more", async (c) => {
3338
+ const p = project(c);
3339
+ const id = c.req.param("id");
3340
+ if (!store2.get(p.id, "lenses", id)) return fail(c, 404, "lens not found");
3341
+ const req = await body(c);
3342
+ if (!req.question?.trim()) return fail(c, 400, "ask a question first");
3343
+ return startJob(c, "lens", p, (l) => l.lensMore(p, id, { question: req.question, files: req.files }));
3344
+ });
3206
3345
  api.get("/projects/:pid/lenses/:id/export", (c) => {
3207
3346
  const p = project(c);
3208
3347
  const l = store2.get(p.id, "lenses", c.req.param("id"));
@@ -3318,13 +3457,13 @@ function createApi(store2, opts2 = {}) {
3318
3457
  api.post("/projects/:pid/teachbacks", async (c) => {
3319
3458
  const p = project(c);
3320
3459
  const req = await body(c);
3321
- return startJob(c, "teachback", p, (l) => l.teachback(p, { files: req.files ?? [], text: req.text ?? "" }));
3460
+ return startJob(c, "teachback", p, (l) => l.teachback(p, { files: req.files ?? [], text: req.text ?? "", diff: req.diff }));
3322
3461
  });
3323
3462
  crud("threads", "threads");
3324
3463
  api.post("/projects/:pid/threads", async (c) => {
3325
3464
  const p = project(c);
3326
3465
  const req = await body(c);
3327
- return startJob(c, "tutor", p, (l) => l.startThread(p, { files: req.files ?? [], text: req.text ?? "" }));
3466
+ return startJob(c, "tutor", p, (l) => l.startThread(p, { files: req.files ?? [], text: req.text ?? "", diff: req.diff }));
3328
3467
  });
3329
3468
  api.post("/projects/:pid/threads/:id/messages", async (c) => {
3330
3469
  const p = project(c);
@@ -1 +1 @@
1
- import{u as $t,a as Tt,b as ft,r as L,t as Ft,j as _,S as Pt,E as ct,M as Lt,F as Ot,d as ut,s as Dt,B as Ct,e as ht}from"./index-ChTnBaTd.js";var Bt={value:()=>{}};function yt(){for(var t=0,e=arguments.length,n={},i;t<e;++t){if(!(i=arguments[t]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new U(n)}function U(t){this._=t}function Wt(t,e){return t.trim().split(/^|\s+/).map(function(n){var i="",r=n.indexOf(".");if(r>=0&&(i=n.slice(r+1),n=n.slice(0,r)),n&&!e.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}U.prototype=yt.prototype={constructor:U,on:function(t,e){var n=this._,i=Wt(t+"",n),r,o=-1,f=i.length;if(arguments.length<2){for(;++o<f;)if((r=(t=i[o]).type)&&(r=Yt(n[r],t.name)))return r;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++o<f;)if(r=(t=i[o]).type)n[r]=dt(n[r],t.name,e);else if(e==null)for(r in n)n[r]=dt(n[r],t.name,null);return this},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new U(t)},call:function(t,e){if((r=arguments.length-2)>0)for(var n=new Array(r),i=0,r,o;i<r;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(o=this._[t],i=0,r=o.length;i<r;++i)o[i].value.apply(e,n)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var i=this._[t],r=0,o=i.length;r<o;++r)i[r].value.apply(e,n)}};function Yt(t,e){for(var n=0,i=t.length,r;n<i;++n)if((r=t[n]).name===e)return r.value}function dt(t,e,n){for(var i=0,r=t.length;i<r;++i)if(t[i].name===e){t[i]=Bt,t=t.slice(0,i).concat(t.slice(i+1));break}return n!=null&&t.push({name:e,value:n}),t}var Y=0,R=0,H=0,mt=1e3,V,J,q=0,B=0,G=0,Q=typeof performance=="object"&&performance.now?performance:Date,wt=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function _t(){return B||(wt(Xt),B=Q.now()+G)}function Xt(){B=0}function tt(){this._call=this._time=this._next=null}tt.prototype=Nt.prototype={constructor:tt,restart:function(t,e,n){if(typeof t!="function")throw new TypeError("callback is not a function");n=(n==null?_t():+n)+(e==null?0:+e),!this._next&&J!==this&&(J?J._next=this:V=this,J=this),this._call=t,this._time=n,et()},stop:function(){this._call&&(this._call=null,this._time=1/0,et())}};function Nt(t,e,n){var i=new tt;return i.restart(t,e,n),i}function Ht(){_t(),++Y;for(var t=V,e;t;)(e=B-t._time)>=0&&t._call.call(void 0,e),t=t._next;--Y}function xt(){B=(q=Q.now())+G,Y=R=0;try{Ht()}finally{Y=0,Jt(),B=0}}function Rt(){var t=Q.now(),e=t-q;e>mt&&(G-=e,q=t)}function Jt(){for(var t,e=V,n,i=1/0;e;)e._call?(i>e._time&&(i=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:V=n);J=t,et(i)}function et(t){if(!Y){R&&(R=clearTimeout(R));var e=t-B;e>24?(t<1/0&&(R=setTimeout(xt,Math.ceil(t-Q.now()-G)+1)),H&&(H=clearInterval(H))):(H||(q=Q.now(),H=setInterval(Rt,mt)),Y=1,wt(xt))}}function Qt(t){const e=+this._x.call(null,t),n=+this._y.call(null,t);return Mt(this.cover(e,n),e,n,t)}function Mt(t,e,n,i){if(isNaN(e)||isNaN(n))return t;var r,o=t._root,f={data:i},s=t._x0,u=t._y0,l=t._x1,p=t._y1,m,y,h,w,c,a,x,v;if(!o)return t._root=f,t;for(;o.length;)if((c=e>=(m=(s+l)/2))?s=m:l=m,(a=n>=(y=(u+p)/2))?u=y:p=y,r=o,!(o=o[x=a<<1|c]))return r[x]=f,t;if(h=+t._x.call(null,o.data),w=+t._y.call(null,o.data),e===h&&n===w)return f.next=o,r?r[x]=f:t._root=f,t;do r=r?r[x]=new Array(4):t._root=new Array(4),(c=e>=(m=(s+l)/2))?s=m:l=m,(a=n>=(y=(u+p)/2))?u=y:p=y;while((x=a<<1|c)===(v=(w>=y)<<1|h>=m));return r[v]=o,r[x]=f,t}function Kt(t){Array.isArray(t)||(t=Array.from(t));const e=t.length,n=new Float64Array(e),i=new Float64Array(e);let r=1/0,o=r,f=-r,s=f;for(let u=0,l,p,m;u<e;++u){if(isNaN(p=+this._x.call(null,l=t[u]))||isNaN(m=+this._y.call(null,l))){n[u]=NaN;continue}n[u]=p,i[u]=m,p<r&&(r=p),p>f&&(f=p),m<o&&(o=m),m>s&&(s=m)}if(r>f||o>s)return this;this.cover(r,o).cover(f,s);for(let u=0;u<e;++u)Mt(this,n[u],i[u],t[u]);return this}function Ut(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,i=this._y0,r=this._x1,o=this._y1;if(isNaN(n))r=(n=Math.floor(t))+1,o=(i=Math.floor(e))+1;else{for(var f=r-n||1,s=this._root,u,l;n>t||t>=r||i>e||e>=o;)switch(l=(e<i)<<1|t<n,u=new Array(4),u[l]=s,s=u,f*=2,l){case 0:r=n+f,o=i+f;break;case 1:n=r-f,o=i+f;break;case 2:r=n+f,i=o-f;break;case 3:n=r-f,i=o-f;break}this._root&&this._root.length&&(this._root=s)}return this._x0=n,this._y0=i,this._x1=r,this._y1=o,this}function Vt(){var t=[];return this.visit(function(e){if(!e.length)do t.push(e.data);while(e=e.next)}),t}function qt(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function S(t,e,n,i,r){this.node=t,this.x0=e,this.y0=n,this.x1=i,this.y1=r}function Gt(t,e,n){var i,r=this._x0,o=this._y0,f,s,u,l,p=this._x1,m=this._y1,y=[],h=this._root,w,c;for(h&&y.push(new S(h,r,o,p,m)),n==null?n=1/0:(r=t-n,o=e-n,p=t+n,m=e+n,n*=n);w=y.pop();)if(!(!(h=w.node)||(f=w.x0)>p||(s=w.y0)>m||(u=w.x1)<r||(l=w.y1)<o))if(h.length){var a=(f+u)/2,x=(s+l)/2;y.push(new S(h[3],a,x,u,l),new S(h[2],f,x,a,l),new S(h[1],a,s,u,x),new S(h[0],f,s,a,x)),(c=(e>=x)<<1|t>=a)&&(w=y[y.length-1],y[y.length-1]=y[y.length-1-c],y[y.length-1-c]=w)}else{var v=t-+this._x.call(null,h.data),N=e-+this._y.call(null,h.data),g=v*v+N*N;if(g<n){var M=Math.sqrt(n=g);r=t-M,o=e-M,p=t+M,m=e+M,i=h.data}}return i}function Zt(t){if(isNaN(p=+this._x.call(null,t))||isNaN(m=+this._y.call(null,t)))return this;var e,n=this._root,i,r,o,f=this._x0,s=this._y0,u=this._x1,l=this._y1,p,m,y,h,w,c,a,x;if(!n)return this;if(n.length)for(;;){if((w=p>=(y=(f+u)/2))?f=y:u=y,(c=m>=(h=(s+l)/2))?s=h:l=h,e=n,!(n=n[a=c<<1|w]))return this;if(!n.length)break;(e[a+1&3]||e[a+2&3]||e[a+3&3])&&(i=e,x=a)}for(;n.data!==t;)if(r=n,!(n=n.next))return this;return(o=n.next)&&delete n.next,r?(o?r.next=o:delete r.next,this):e?(o?e[a]=o:delete e[a],(n=e[0]||e[1]||e[2]||e[3])&&n===(e[3]||e[2]||e[1]||e[0])&&!n.length&&(i?i[x]=n:this._root=n),this):(this._root=o,this)}function te(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this}function ee(){return this._root}function ne(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function re(t){var e=[],n,i=this._root,r,o,f,s,u;for(i&&e.push(new S(i,this._x0,this._y0,this._x1,this._y1));n=e.pop();)if(!t(i=n.node,o=n.x0,f=n.y0,s=n.x1,u=n.y1)&&i.length){var l=(o+s)/2,p=(f+u)/2;(r=i[3])&&e.push(new S(r,l,p,s,u)),(r=i[2])&&e.push(new S(r,o,p,l,u)),(r=i[1])&&e.push(new S(r,l,f,s,p)),(r=i[0])&&e.push(new S(r,o,f,l,p))}return this}function ie(t){var e=[],n=[],i;for(this._root&&e.push(new S(this._root,this._x0,this._y0,this._x1,this._y1));i=e.pop();){var r=i.node;if(r.length){var o,f=i.x0,s=i.y0,u=i.x1,l=i.y1,p=(f+u)/2,m=(s+l)/2;(o=r[0])&&e.push(new S(o,f,s,p,m)),(o=r[1])&&e.push(new S(o,p,s,u,m)),(o=r[2])&&e.push(new S(o,f,m,p,l)),(o=r[3])&&e.push(new S(o,p,m,u,l))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this}function oe(t){return t[0]}function se(t){return arguments.length?(this._x=t,this):this._x}function ae(t){return t[1]}function le(t){return arguments.length?(this._y=t,this):this._y}function nt(t,e,n){var i=new rt(e??oe,n??ae,NaN,NaN,NaN,NaN);return t==null?i:i.addAll(t)}function rt(t,e,n,i,r,o){this._x=t,this._y=e,this._x0=n,this._y0=i,this._x1=r,this._y1=o,this._root=void 0}function gt(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var I=nt.prototype=rt.prototype;I.copy=function(){var t=new rt(this._x,this._y,this._x0,this._y0,this._x1,this._y1),e=this._root,n,i;if(!e)return t;if(!e.length)return t._root=gt(e),t;for(n=[{source:e,target:t._root=new Array(4)}];e=n.pop();)for(var r=0;r<4;++r)(i=e.source[r])&&(i.length?n.push({source:i,target:e.target[r]=new Array(4)}):e.target[r]=gt(i));return t};I.add=Qt;I.addAll=Kt;I.cover=Ut;I.data=Vt;I.extent=qt;I.find=Gt;I.remove=Zt;I.removeAll=te;I.root=ee;I.size=ne;I.visit=re;I.visitAfter=ie;I.x=se;I.y=le;function fe(t,e){var n,i=1;t==null&&(t=0),e==null&&(e=0);function r(){var o,f=n.length,s,u=0,l=0;for(o=0;o<f;++o)s=n[o],u+=s.x,l+=s.y;for(u=(u/f-t)*i,l=(l/f-e)*i,o=0;o<f;++o)s=n[o],s.x-=u,s.y-=l}return r.initialize=function(o){n=o},r.x=function(o){return arguments.length?(t=+o,r):t},r.y=function(o){return arguments.length?(e=+o,r):e},r.strength=function(o){return arguments.length?(i=+o,r):i},r}function z(t){return function(){return t}}function D(t){return(t()-.5)*1e-6}function ce(t){return t.x+t.vx}function ue(t){return t.y+t.vy}function he(t){var e,n,i,r=1,o=1;typeof t!="function"&&(t=z(t==null?1:+t));function f(){for(var l,p=e.length,m,y,h,w,c,a,x=0;x<o;++x)for(m=nt(e,ce,ue).visitAfter(s),l=0;l<p;++l)y=e[l],c=n[y.index],a=c*c,h=y.x+y.vx,w=y.y+y.vy,m.visit(v);function v(N,g,M,A,b){var k=N.data,E=N.r,j=c+E;if(k){if(k.index>y.index){var $=h-k.x-k.vx,T=w-k.y-k.vy,F=$*$+T*T;F<j*j&&($===0&&($=D(i),F+=$*$),T===0&&(T=D(i),F+=T*T),F=(j-(F=Math.sqrt(F)))/F*r,y.vx+=($*=F)*(j=(E*=E)/(a+E)),y.vy+=(T*=F)*j,k.vx-=$*(j=1-j),k.vy-=T*j)}return}return g>h+j||A<h-j||M>w+j||b<w-j}}function s(l){if(l.data)return l.r=n[l.data.index];for(var p=l.r=0;p<4;++p)l[p]&&l[p].r>l.r&&(l.r=l[p].r)}function u(){if(e){var l,p=e.length,m;for(n=new Array(p),l=0;l<p;++l)m=e[l],n[m.index]=+t(m,l,e)}}return f.initialize=function(l,p){e=l,i=p,u()},f.iterations=function(l){return arguments.length?(o=+l,f):o},f.strength=function(l){return arguments.length?(r=+l,f):r},f.radius=function(l){return arguments.length?(t=typeof l=="function"?l:z(+l),u(),f):t},f}function de(t){return t.index}function pt(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function xe(t){var e=de,n=m,i,r=z(30),o,f,s,u,l,p=1;t==null&&(t=[]);function m(a){return 1/Math.min(s[a.source.index],s[a.target.index])}function y(a){for(var x=0,v=t.length;x<p;++x)for(var N=0,g,M,A,b,k,E,j;N<v;++N)g=t[N],M=g.source,A=g.target,b=A.x+A.vx-M.x-M.vx||D(l),k=A.y+A.vy-M.y-M.vy||D(l),E=Math.sqrt(b*b+k*k),E=(E-o[N])/E*a*i[N],b*=E,k*=E,A.vx-=b*(j=u[N]),A.vy-=k*j,M.vx+=b*(j=1-j),M.vy+=k*j}function h(){if(f){var a,x=f.length,v=t.length,N=new Map(f.map((M,A)=>[e(M,A,f),M])),g;for(a=0,s=new Array(x);a<v;++a)g=t[a],g.index=a,typeof g.source!="object"&&(g.source=pt(N,g.source)),typeof g.target!="object"&&(g.target=pt(N,g.target)),s[g.source.index]=(s[g.source.index]||0)+1,s[g.target.index]=(s[g.target.index]||0)+1;for(a=0,u=new Array(v);a<v;++a)g=t[a],u[a]=s[g.source.index]/(s[g.source.index]+s[g.target.index]);i=new Array(v),w(),o=new Array(v),c()}}function w(){if(f)for(var a=0,x=t.length;a<x;++a)i[a]=+n(t[a],a,t)}function c(){if(f)for(var a=0,x=t.length;a<x;++a)o[a]=+r(t[a],a,t)}return y.initialize=function(a,x){f=a,l=x,h()},y.links=function(a){return arguments.length?(t=a,h(),y):t},y.id=function(a){return arguments.length?(e=a,y):e},y.iterations=function(a){return arguments.length?(p=+a,y):p},y.strength=function(a){return arguments.length?(n=typeof a=="function"?a:z(+a),w(),y):n},y.distance=function(a){return arguments.length?(r=typeof a=="function"?a:z(+a),c(),y):r},y}const ge=1664525,pe=1013904223,vt=4294967296;function ve(){let t=1;return()=>(t=(ge*t+pe)%vt)/vt}function ye(t){return t.x}function me(t){return t.y}var we=10,_e=Math.PI*(3-Math.sqrt(5));function Ne(t){var e,n=1,i=.001,r=1-Math.pow(i,1/300),o=0,f=.6,s=new Map,u=Nt(m),l=yt("tick","end"),p=ve();t==null&&(t=[]);function m(){y(),l.call("tick",e),n<i&&(u.stop(),l.call("end",e))}function y(c){var a,x=t.length,v;c===void 0&&(c=1);for(var N=0;N<c;++N)for(n+=(o-n)*r,s.forEach(function(g){g(n)}),a=0;a<x;++a)v=t[a],v.fx==null?v.x+=v.vx*=f:(v.x=v.fx,v.vx=0),v.fy==null?v.y+=v.vy*=f:(v.y=v.fy,v.vy=0);return e}function h(){for(var c=0,a=t.length,x;c<a;++c){if(x=t[c],x.index=c,x.fx!=null&&(x.x=x.fx),x.fy!=null&&(x.y=x.fy),isNaN(x.x)||isNaN(x.y)){var v=we*Math.sqrt(.5+c),N=c*_e;x.x=v*Math.cos(N),x.y=v*Math.sin(N)}(isNaN(x.vx)||isNaN(x.vy))&&(x.vx=x.vy=0)}}function w(c){return c.initialize&&c.initialize(t,p),c}return h(),e={tick:y,restart:function(){return u.restart(m),e},stop:function(){return u.stop(),e},nodes:function(c){return arguments.length?(t=c,h(),s.forEach(w),e):t},alpha:function(c){return arguments.length?(n=+c,e):n},alphaMin:function(c){return arguments.length?(i=+c,e):i},alphaDecay:function(c){return arguments.length?(r=+c,e):+r},alphaTarget:function(c){return arguments.length?(o=+c,e):o},velocityDecay:function(c){return arguments.length?(f=1-c,e):1-f},randomSource:function(c){return arguments.length?(p=c,s.forEach(w),e):p},force:function(c,a){return arguments.length>1?(a==null?s.delete(c):s.set(c,w(a)),e):s.get(c)},find:function(c,a,x){var v=0,N=t.length,g,M,A,b,k;for(x==null?x=1/0:x*=x,v=0;v<N;++v)b=t[v],g=c-b.x,M=a-b.y,A=g*g+M*M,A<x&&(k=b,x=A);return k},on:function(c,a){return arguments.length>1?(l.on(c,a),e):l.on(c)}}}function Me(){var t,e,n,i,r=z(-30),o,f=1,s=1/0,u=.81;function l(h){var w,c=t.length,a=nt(t,ye,me).visitAfter(m);for(i=h,w=0;w<c;++w)e=t[w],a.visit(y)}function p(){if(t){var h,w=t.length,c;for(o=new Array(w),h=0;h<w;++h)c=t[h],o[c.index]=+r(c,h,t)}}function m(h){var w=0,c,a,x=0,v,N,g;if(h.length){for(v=N=g=0;g<4;++g)(c=h[g])&&(a=Math.abs(c.value))&&(w+=c.value,x+=a,v+=a*c.x,N+=a*c.y);h.x=v/x,h.y=N/x}else{c=h,c.x=c.data.x,c.y=c.data.y;do w+=o[c.data.index];while(c=c.next)}h.value=w}function y(h,w,c,a){if(!h.value)return!0;var x=h.x-e.x,v=h.y-e.y,N=a-w,g=x*x+v*v;if(N*N/u<g)return g<s&&(x===0&&(x=D(n),g+=x*x),v===0&&(v=D(n),g+=v*v),g<f&&(g=Math.sqrt(f*g)),e.vx+=x*h.value*i/g,e.vy+=v*h.value*i/g),!0;if(h.length||g>=s)return;(h.data!==e||h.next)&&(x===0&&(x=D(n),g+=x*x),v===0&&(v=D(n),g+=v*v),g<f&&(g=Math.sqrt(f*g)));do h.data!==e&&(N=o[h.data.index]*i/g,e.vx+=x*N,e.vy+=v*N);while(h=h.next)}return l.initialize=function(h,w){t=h,n=w,p()},l.strength=function(h){return arguments.length?(r=typeof h=="function"?h:z(+h),p(),l):r},l.distanceMin=function(h){return arguments.length?(f=h*h,l):Math.sqrt(f)},l.distanceMax=function(h){return arguments.length?(s=h*h,l):Math.sqrt(s)},l.theta=function(h){return arguments.length?(u=h*h,l):Math.sqrt(u)},l}function je(t){var e=z(.1),n,i,r;typeof t!="function"&&(t=z(t==null?0:+t));function o(s){for(var u=0,l=n.length,p;u<l;++u)p=n[u],p.vx+=(r[u]-p.x)*i[u]*s}function f(){if(n){var s,u=n.length;for(i=new Array(u),r=new Array(u),s=0;s<u;++s)i[s]=isNaN(r[s]=+t(n[s],s,n))?0:+e(n[s],s,n)}}return o.initialize=function(s){n=s,f()},o.strength=function(s){return arguments.length?(e=typeof s=="function"?s:z(+s),f(),o):e},o.x=function(s){return arguments.length?(t=typeof s=="function"?s:z(+s),f(),o):t},o}function be(t){var e=z(.1),n,i,r;typeof t!="function"&&(t=z(t==null?0:+t));function o(s){for(var u=0,l=n.length,p;u<l;++u)p=n[u],p.vy+=(r[u]-p.y)*i[u]*s}function f(){if(n){var s,u=n.length;for(i=new Array(u),r=new Array(u),s=0;s<u;++s)i[s]=isNaN(r[s]=+t(n[s],s,n))?0:+e(n[s],s,n)}}return o.initialize=function(s){n=s,f()},o.strength=function(s){return arguments.length?(e=typeof s=="function"?s:z(+s),f(),o):e},o.y=function(s){return arguments.length?(t=typeof s=="function"?s:z(+s),f(),o):t},o}const Z={new:"rgb(var(--muted) / 0.45)",seen:"rgb(var(--accent) / 0.45)",understood:"rgb(var(--good))",fading:"rgb(var(--warn) / 0.7)",stale:"rgb(var(--warn))"};function ke(t){const e=t.nodes.map(r=>({id:r.path,fanIn:r.fanIn,fanOut:r.fanOut,r:Math.min(18,4+Math.sqrt(r.fanIn)*2.5)})),n=new Map(e.map(r=>[r.id,r])),i=t.edges.map(r=>({source:r.from,target:r.to}));return Ne(e).force("link",xe(i).id(r=>r.id).distance(60).strength(.3)).force("charge",Me().strength(-170)).force("center",fe(0,0)).force("x",je(0).strength(.07)).force("y",be(0).strength(.07)).force("collide",he().radius(r=>r.r+3)).stop().tick(300),{nodes:e,links:t.edges.map(r=>({s:n.get(r.from),t:n.get(r.to)}))}}function Ae(t,e,n){if(!e.size)return t;const i=new Set([...e].filter(r=>t.nodes.some(o=>o.path===r)));if(n)for(const r of t.edges)e.has(r.from)&&i.add(r.to),e.has(r.to)&&i.add(r.from);return{nodes:t.nodes.filter(r=>i.has(r.path)),edges:t.edges.filter(r=>i.has(r.from)&&i.has(r.to))}}function ze(){var lt;const{project:t,rel:e,setOpenFile:n,setSelected:i}=$t(),r=Tt(),o=ft({queryKey:["graph",t.id],queryFn:()=>ht(`/projects/${t.id}/graph`)}),f=ft({queryKey:["progress",t.id],queryFn:()=>ht(`/projects/${t.id}/progress`)}),s=L.useMemo(()=>new Map((f.data??[]).map(d=>[d.path,d.level])),[f.data]),u=`gl.map.${t.id}`,[l,p]=L.useState(()=>{try{return new Set(JSON.parse(sessionStorage.getItem(u)??"[]"))}catch{return new Set}}),[m,y]=L.useState(!0),[h,w]=L.useState(null);L.useEffect(()=>{try{sessionStorage.setItem(u,JSON.stringify([...l]))}catch{}},[u,l]);const c=L.useMemo(()=>o.data?Ae(o.data,l,m):null,[o.data,l,m]),a=L.useMemo(()=>c?ke(c):null,[c]),x=L.useMemo(()=>o.data?Ft(t.root,o.data.nodes.map(d=>d.path).sort()):[],[o.data,t.root]),[v,N]=L.useState(null),g=v??h;L.useEffect(()=>{A({x:0,y:0,k:1})},[c]);const[M,A]=L.useState({x:0,y:0,k:1}),b=L.useRef(null);if(o.isLoading)return _.jsx("div",{className:"p-8",children:_.jsx(Pt,{})});if(!((lt=o.data)!=null&&lt.nodes.length)||!a)return _.jsx(ct,{icon:_.jsx(Lt,{className:"h-6 w-6"}),title:"No imports found",children:"The map reads import lines in TypeScript, JavaScript and Python files. This folder has none that point to other files in it."});const k=[...a.nodes].sort((d,P)=>P.fanIn-d.fanIn).slice(0,15),E=new Set((a.nodes.length<=25?a.nodes:k.slice(0,8)).map(d=>d.id)),j=new Set;if(g)for(const d of a.links)d.s.id===g&&j.add(d.t.id),d.t.id===g&&j.add(d.s.id);const $=a.nodes.map(d=>d.x??0),T=a.nodes.map(d=>d.y??0),F=40,jt=380,bt=280,kt=Math.max(...$)-Math.min(...$)+F*2,At=Math.max(...T)-Math.min(...T)+F*2,St=(Math.max(...$)+Math.min(...$))/2,zt=(Math.max(...T)+Math.min(...T))/2,it=Math.max(kt,jt),ot=Math.max(At,bt),X={x:St-it/2,y:zt-ot/2,w:it,h:ot},It=`${X.x+M.x} ${X.y+M.y} ${X.w/M.k} ${X.h/M.k}`,st=d=>{n(d),i([d]),r(`/p/${t.id}/explore`)},at=_.jsxs("div",{className:"flex h-full flex-col bg-panel",children:[_.jsxs("div",{className:"border-b border-line px-3 py-2.5",children:[_.jsx("div",{className:"text-sm font-semibold",children:"Show only"}),_.jsx("div",{className:"text-[12px] text-muted",children:l.size?`${l.size} file${l.size===1?"":"s"} ticked`:"Tick folders or files; none ticked shows all."}),_.jsxs("div",{className:"mt-2 flex items-center gap-3 text-xs",children:[_.jsxs("label",{className:"flex cursor-pointer items-center gap-1.5",children:[_.jsx("input",{type:"checkbox",className:"accent-[rgb(var(--accent))]",checked:m,onChange:d=>y(d.target.checked)}),"with direct imports and importers"]}),l.size>0&&_.jsx("button",{className:"ml-auto text-muted hover:text-ink",onClick:()=>p(new Set),children:"clear"})]})]}),_.jsx("div",{className:"min-h-0 flex-1",children:_.jsx(Ot,{roots:x,selected:[...l],onToggle:(d,P)=>{const O=new Set(l);for(const C of d)P?O.add(C):O.delete(C);p(O)},openFile:h,onOpen:d=>w(h===d?null:d),levels:s})})]});if(!a.nodes.length)return _.jsx(ut,{id:"map-tree",collapsible:!0,initial:280,className:"h-full",left:at,right:_.jsx(ct,{title:"Nothing to show",children:"None of the ticked files import or are imported by another file here."})});const Et=_.jsxs("div",{className:"flex h-full",children:[_.jsxs("div",{className:"relative min-w-0 flex-1 bg-panel",children:[_.jsxs("svg",{className:"h-full w-full cursor-grab active:cursor-grabbing",viewBox:It,onWheel:d=>A(P=>({...P,k:Math.min(8,Math.max(.3,P.k*(d.deltaY<0?1.15:1/1.15)))})),onMouseDown:d=>b.current={x:d.clientX,y:d.clientY},onMouseUp:()=>b.current=null,onMouseLeave:()=>b.current=null,onMouseMove:d=>{if(!b.current)return;const P=d.currentTarget.getBoundingClientRect(),O=X.w/M.k/P.width,C=(d.clientX-b.current.x)*O,K=(d.clientY-b.current.y)*O;b.current={x:d.clientX,y:d.clientY},A(W=>({...W,x:W.x-C,y:W.y-K}))},children:[_.jsx("defs",{children:_.jsx("marker",{id:"arrow",viewBox:"0 0 10 10",refX:"10",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto-start-reverse",children:_.jsx("path",{d:"M0,0 L10,5 L0,10 z",fill:"rgb(var(--muted) / 0.5)"})})}),a.links.map((d,P)=>{const O=g&&(d.s.id===g||d.t.id===g),C=(d.t.x??0)-(d.s.x??0),K=(d.t.y??0)-(d.s.y??0),W=Math.hypot(C,K)||1;return _.jsx("line",{x1:d.s.x,y1:d.s.y,x2:(d.t.x??0)-C/W*(d.t.r+2),y2:(d.t.y??0)-K/W*(d.t.r+2),stroke:O?"rgb(var(--accent))":"rgb(var(--muted) / 0.25)",strokeWidth:O?1.5:.8,markerEnd:"url(#arrow)"},P)}),a.nodes.map(d=>{const P=g&&d.id!==g&&!j.has(d.id);return _.jsxs("g",{transform:`translate(${d.x},${d.y})`,opacity:P?.25:1,className:"cursor-pointer",onMouseEnter:()=>N(d.id),onMouseLeave:()=>N(null),onClick:()=>st(d.id),children:[_.jsx("circle",{r:d.r,fill:Z[s.get(d.id)??"new"],stroke:"rgb(var(--panel))",strokeWidth:1.5}),(E.has(d.id)||d.id===g)&&_.jsx("text",{y:-d.r-4,textAnchor:"middle",className:"fill-ink font-mono",fontSize:10,paintOrder:"stroke",stroke:"rgb(var(--panel))",strokeWidth:3,strokeLinejoin:"round",children:d.id.split("/").pop()})]},d.id)})]}),_.jsxs("div",{className:"pointer-events-none absolute bottom-3 left-3 flex flex-wrap gap-2 text-[12px] text-muted",children:[["new","seen","understood","fading","stale"].map(d=>_.jsxs("span",{className:"flex items-center gap-1",children:[_.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{background:Z[d]}}),d]},d)),_.jsx("span",{children:"· size = imported by · scroll to zoom, drag to move"})]}),g&&_.jsx("div",{className:"absolute left-3 top-3 rounded-md bg-raised px-2 py-1 font-mono text-xs",children:e(g)})]}),_.jsxs("aside",{className:"w-[300px] shrink-0 overflow-auto border-l border-line bg-panel p-4",children:[_.jsx("h1",{className:"text-base font-semibold",children:"Map"}),_.jsxs("p",{className:"text-xs text-muted",children:[a.nodes.length,l.size?` of ${o.data.nodes.length}`:""," files, ",a.links.length," imports. Files many others import are a good place to start.",h&&" Click a file in the tree again to unpin it."]}),_.jsx("div",{className:"label mt-4",children:"Most depended on"}),_.jsx("ol",{className:"space-y-1",children:k.map(d=>_.jsx("li",{children:_.jsxs("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-left hover:bg-raised",onMouseEnter:()=>N(d.id),onMouseLeave:()=>N(null),onClick:()=>st(d.id),children:[_.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full",style:{background:Z[s.get(d.id)??"new"]}}),_.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[13px]",title:e(d.id),children:Dt(e(d.id),30)}),_.jsx(Ct,{children:d.fanIn})]})},d.id))})]})]});return _.jsx(ut,{id:"map-tree",collapsible:!0,initial:280,className:"h-full",left:at,right:Et})}export{ze as MapPage};
1
+ import{u as $t,a as Tt,b as ft,r as L,t as Ft,j as _,S as Pt,E as ct,M as Lt,F as Ot,d as ut,s as Dt,B as Ct,e as ht}from"./index-Bs71achu.js";var Bt={value:()=>{}};function yt(){for(var t=0,e=arguments.length,n={},i;t<e;++t){if(!(i=arguments[t]+"")||i in n||/[\s.]/.test(i))throw new Error("illegal type: "+i);n[i]=[]}return new U(n)}function U(t){this._=t}function Wt(t,e){return t.trim().split(/^|\s+/).map(function(n){var i="",r=n.indexOf(".");if(r>=0&&(i=n.slice(r+1),n=n.slice(0,r)),n&&!e.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:i}})}U.prototype=yt.prototype={constructor:U,on:function(t,e){var n=this._,i=Wt(t+"",n),r,o=-1,f=i.length;if(arguments.length<2){for(;++o<f;)if((r=(t=i[o]).type)&&(r=Yt(n[r],t.name)))return r;return}if(e!=null&&typeof e!="function")throw new Error("invalid callback: "+e);for(;++o<f;)if(r=(t=i[o]).type)n[r]=dt(n[r],t.name,e);else if(e==null)for(r in n)n[r]=dt(n[r],t.name,null);return this},copy:function(){var t={},e=this._;for(var n in e)t[n]=e[n].slice();return new U(t)},call:function(t,e){if((r=arguments.length-2)>0)for(var n=new Array(r),i=0,r,o;i<r;++i)n[i]=arguments[i+2];if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(o=this._[t],i=0,r=o.length;i<r;++i)o[i].value.apply(e,n)},apply:function(t,e,n){if(!this._.hasOwnProperty(t))throw new Error("unknown type: "+t);for(var i=this._[t],r=0,o=i.length;r<o;++r)i[r].value.apply(e,n)}};function Yt(t,e){for(var n=0,i=t.length,r;n<i;++n)if((r=t[n]).name===e)return r.value}function dt(t,e,n){for(var i=0,r=t.length;i<r;++i)if(t[i].name===e){t[i]=Bt,t=t.slice(0,i).concat(t.slice(i+1));break}return n!=null&&t.push({name:e,value:n}),t}var Y=0,R=0,H=0,mt=1e3,V,J,q=0,B=0,G=0,Q=typeof performance=="object"&&performance.now?performance:Date,wt=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(t){setTimeout(t,17)};function _t(){return B||(wt(Xt),B=Q.now()+G)}function Xt(){B=0}function tt(){this._call=this._time=this._next=null}tt.prototype=Nt.prototype={constructor:tt,restart:function(t,e,n){if(typeof t!="function")throw new TypeError("callback is not a function");n=(n==null?_t():+n)+(e==null?0:+e),!this._next&&J!==this&&(J?J._next=this:V=this,J=this),this._call=t,this._time=n,et()},stop:function(){this._call&&(this._call=null,this._time=1/0,et())}};function Nt(t,e,n){var i=new tt;return i.restart(t,e,n),i}function Ht(){_t(),++Y;for(var t=V,e;t;)(e=B-t._time)>=0&&t._call.call(void 0,e),t=t._next;--Y}function xt(){B=(q=Q.now())+G,Y=R=0;try{Ht()}finally{Y=0,Jt(),B=0}}function Rt(){var t=Q.now(),e=t-q;e>mt&&(G-=e,q=t)}function Jt(){for(var t,e=V,n,i=1/0;e;)e._call?(i>e._time&&(i=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:V=n);J=t,et(i)}function et(t){if(!Y){R&&(R=clearTimeout(R));var e=t-B;e>24?(t<1/0&&(R=setTimeout(xt,Math.ceil(t-Q.now()-G)+1)),H&&(H=clearInterval(H))):(H||(q=Q.now(),H=setInterval(Rt,mt)),Y=1,wt(xt))}}function Qt(t){const e=+this._x.call(null,t),n=+this._y.call(null,t);return Mt(this.cover(e,n),e,n,t)}function Mt(t,e,n,i){if(isNaN(e)||isNaN(n))return t;var r,o=t._root,f={data:i},s=t._x0,u=t._y0,l=t._x1,p=t._y1,m,y,h,w,c,a,x,v;if(!o)return t._root=f,t;for(;o.length;)if((c=e>=(m=(s+l)/2))?s=m:l=m,(a=n>=(y=(u+p)/2))?u=y:p=y,r=o,!(o=o[x=a<<1|c]))return r[x]=f,t;if(h=+t._x.call(null,o.data),w=+t._y.call(null,o.data),e===h&&n===w)return f.next=o,r?r[x]=f:t._root=f,t;do r=r?r[x]=new Array(4):t._root=new Array(4),(c=e>=(m=(s+l)/2))?s=m:l=m,(a=n>=(y=(u+p)/2))?u=y:p=y;while((x=a<<1|c)===(v=(w>=y)<<1|h>=m));return r[v]=o,r[x]=f,t}function Kt(t){Array.isArray(t)||(t=Array.from(t));const e=t.length,n=new Float64Array(e),i=new Float64Array(e);let r=1/0,o=r,f=-r,s=f;for(let u=0,l,p,m;u<e;++u){if(isNaN(p=+this._x.call(null,l=t[u]))||isNaN(m=+this._y.call(null,l))){n[u]=NaN;continue}n[u]=p,i[u]=m,p<r&&(r=p),p>f&&(f=p),m<o&&(o=m),m>s&&(s=m)}if(r>f||o>s)return this;this.cover(r,o).cover(f,s);for(let u=0;u<e;++u)Mt(this,n[u],i[u],t[u]);return this}function Ut(t,e){if(isNaN(t=+t)||isNaN(e=+e))return this;var n=this._x0,i=this._y0,r=this._x1,o=this._y1;if(isNaN(n))r=(n=Math.floor(t))+1,o=(i=Math.floor(e))+1;else{for(var f=r-n||1,s=this._root,u,l;n>t||t>=r||i>e||e>=o;)switch(l=(e<i)<<1|t<n,u=new Array(4),u[l]=s,s=u,f*=2,l){case 0:r=n+f,o=i+f;break;case 1:n=r-f,o=i+f;break;case 2:r=n+f,i=o-f;break;case 3:n=r-f,i=o-f;break}this._root&&this._root.length&&(this._root=s)}return this._x0=n,this._y0=i,this._x1=r,this._y1=o,this}function Vt(){var t=[];return this.visit(function(e){if(!e.length)do t.push(e.data);while(e=e.next)}),t}function qt(t){return arguments.length?this.cover(+t[0][0],+t[0][1]).cover(+t[1][0],+t[1][1]):isNaN(this._x0)?void 0:[[this._x0,this._y0],[this._x1,this._y1]]}function S(t,e,n,i,r){this.node=t,this.x0=e,this.y0=n,this.x1=i,this.y1=r}function Gt(t,e,n){var i,r=this._x0,o=this._y0,f,s,u,l,p=this._x1,m=this._y1,y=[],h=this._root,w,c;for(h&&y.push(new S(h,r,o,p,m)),n==null?n=1/0:(r=t-n,o=e-n,p=t+n,m=e+n,n*=n);w=y.pop();)if(!(!(h=w.node)||(f=w.x0)>p||(s=w.y0)>m||(u=w.x1)<r||(l=w.y1)<o))if(h.length){var a=(f+u)/2,x=(s+l)/2;y.push(new S(h[3],a,x,u,l),new S(h[2],f,x,a,l),new S(h[1],a,s,u,x),new S(h[0],f,s,a,x)),(c=(e>=x)<<1|t>=a)&&(w=y[y.length-1],y[y.length-1]=y[y.length-1-c],y[y.length-1-c]=w)}else{var v=t-+this._x.call(null,h.data),N=e-+this._y.call(null,h.data),g=v*v+N*N;if(g<n){var M=Math.sqrt(n=g);r=t-M,o=e-M,p=t+M,m=e+M,i=h.data}}return i}function Zt(t){if(isNaN(p=+this._x.call(null,t))||isNaN(m=+this._y.call(null,t)))return this;var e,n=this._root,i,r,o,f=this._x0,s=this._y0,u=this._x1,l=this._y1,p,m,y,h,w,c,a,x;if(!n)return this;if(n.length)for(;;){if((w=p>=(y=(f+u)/2))?f=y:u=y,(c=m>=(h=(s+l)/2))?s=h:l=h,e=n,!(n=n[a=c<<1|w]))return this;if(!n.length)break;(e[a+1&3]||e[a+2&3]||e[a+3&3])&&(i=e,x=a)}for(;n.data!==t;)if(r=n,!(n=n.next))return this;return(o=n.next)&&delete n.next,r?(o?r.next=o:delete r.next,this):e?(o?e[a]=o:delete e[a],(n=e[0]||e[1]||e[2]||e[3])&&n===(e[3]||e[2]||e[1]||e[0])&&!n.length&&(i?i[x]=n:this._root=n),this):(this._root=o,this)}function te(t){for(var e=0,n=t.length;e<n;++e)this.remove(t[e]);return this}function ee(){return this._root}function ne(){var t=0;return this.visit(function(e){if(!e.length)do++t;while(e=e.next)}),t}function re(t){var e=[],n,i=this._root,r,o,f,s,u;for(i&&e.push(new S(i,this._x0,this._y0,this._x1,this._y1));n=e.pop();)if(!t(i=n.node,o=n.x0,f=n.y0,s=n.x1,u=n.y1)&&i.length){var l=(o+s)/2,p=(f+u)/2;(r=i[3])&&e.push(new S(r,l,p,s,u)),(r=i[2])&&e.push(new S(r,o,p,l,u)),(r=i[1])&&e.push(new S(r,l,f,s,p)),(r=i[0])&&e.push(new S(r,o,f,l,p))}return this}function ie(t){var e=[],n=[],i;for(this._root&&e.push(new S(this._root,this._x0,this._y0,this._x1,this._y1));i=e.pop();){var r=i.node;if(r.length){var o,f=i.x0,s=i.y0,u=i.x1,l=i.y1,p=(f+u)/2,m=(s+l)/2;(o=r[0])&&e.push(new S(o,f,s,p,m)),(o=r[1])&&e.push(new S(o,p,s,u,m)),(o=r[2])&&e.push(new S(o,f,m,p,l)),(o=r[3])&&e.push(new S(o,p,m,u,l))}n.push(i)}for(;i=n.pop();)t(i.node,i.x0,i.y0,i.x1,i.y1);return this}function oe(t){return t[0]}function se(t){return arguments.length?(this._x=t,this):this._x}function ae(t){return t[1]}function le(t){return arguments.length?(this._y=t,this):this._y}function nt(t,e,n){var i=new rt(e??oe,n??ae,NaN,NaN,NaN,NaN);return t==null?i:i.addAll(t)}function rt(t,e,n,i,r,o){this._x=t,this._y=e,this._x0=n,this._y0=i,this._x1=r,this._y1=o,this._root=void 0}function gt(t){for(var e={data:t.data},n=e;t=t.next;)n=n.next={data:t.data};return e}var I=nt.prototype=rt.prototype;I.copy=function(){var t=new rt(this._x,this._y,this._x0,this._y0,this._x1,this._y1),e=this._root,n,i;if(!e)return t;if(!e.length)return t._root=gt(e),t;for(n=[{source:e,target:t._root=new Array(4)}];e=n.pop();)for(var r=0;r<4;++r)(i=e.source[r])&&(i.length?n.push({source:i,target:e.target[r]=new Array(4)}):e.target[r]=gt(i));return t};I.add=Qt;I.addAll=Kt;I.cover=Ut;I.data=Vt;I.extent=qt;I.find=Gt;I.remove=Zt;I.removeAll=te;I.root=ee;I.size=ne;I.visit=re;I.visitAfter=ie;I.x=se;I.y=le;function fe(t,e){var n,i=1;t==null&&(t=0),e==null&&(e=0);function r(){var o,f=n.length,s,u=0,l=0;for(o=0;o<f;++o)s=n[o],u+=s.x,l+=s.y;for(u=(u/f-t)*i,l=(l/f-e)*i,o=0;o<f;++o)s=n[o],s.x-=u,s.y-=l}return r.initialize=function(o){n=o},r.x=function(o){return arguments.length?(t=+o,r):t},r.y=function(o){return arguments.length?(e=+o,r):e},r.strength=function(o){return arguments.length?(i=+o,r):i},r}function z(t){return function(){return t}}function D(t){return(t()-.5)*1e-6}function ce(t){return t.x+t.vx}function ue(t){return t.y+t.vy}function he(t){var e,n,i,r=1,o=1;typeof t!="function"&&(t=z(t==null?1:+t));function f(){for(var l,p=e.length,m,y,h,w,c,a,x=0;x<o;++x)for(m=nt(e,ce,ue).visitAfter(s),l=0;l<p;++l)y=e[l],c=n[y.index],a=c*c,h=y.x+y.vx,w=y.y+y.vy,m.visit(v);function v(N,g,M,A,b){var k=N.data,E=N.r,j=c+E;if(k){if(k.index>y.index){var $=h-k.x-k.vx,T=w-k.y-k.vy,F=$*$+T*T;F<j*j&&($===0&&($=D(i),F+=$*$),T===0&&(T=D(i),F+=T*T),F=(j-(F=Math.sqrt(F)))/F*r,y.vx+=($*=F)*(j=(E*=E)/(a+E)),y.vy+=(T*=F)*j,k.vx-=$*(j=1-j),k.vy-=T*j)}return}return g>h+j||A<h-j||M>w+j||b<w-j}}function s(l){if(l.data)return l.r=n[l.data.index];for(var p=l.r=0;p<4;++p)l[p]&&l[p].r>l.r&&(l.r=l[p].r)}function u(){if(e){var l,p=e.length,m;for(n=new Array(p),l=0;l<p;++l)m=e[l],n[m.index]=+t(m,l,e)}}return f.initialize=function(l,p){e=l,i=p,u()},f.iterations=function(l){return arguments.length?(o=+l,f):o},f.strength=function(l){return arguments.length?(r=+l,f):r},f.radius=function(l){return arguments.length?(t=typeof l=="function"?l:z(+l),u(),f):t},f}function de(t){return t.index}function pt(t,e){var n=t.get(e);if(!n)throw new Error("node not found: "+e);return n}function xe(t){var e=de,n=m,i,r=z(30),o,f,s,u,l,p=1;t==null&&(t=[]);function m(a){return 1/Math.min(s[a.source.index],s[a.target.index])}function y(a){for(var x=0,v=t.length;x<p;++x)for(var N=0,g,M,A,b,k,E,j;N<v;++N)g=t[N],M=g.source,A=g.target,b=A.x+A.vx-M.x-M.vx||D(l),k=A.y+A.vy-M.y-M.vy||D(l),E=Math.sqrt(b*b+k*k),E=(E-o[N])/E*a*i[N],b*=E,k*=E,A.vx-=b*(j=u[N]),A.vy-=k*j,M.vx+=b*(j=1-j),M.vy+=k*j}function h(){if(f){var a,x=f.length,v=t.length,N=new Map(f.map((M,A)=>[e(M,A,f),M])),g;for(a=0,s=new Array(x);a<v;++a)g=t[a],g.index=a,typeof g.source!="object"&&(g.source=pt(N,g.source)),typeof g.target!="object"&&(g.target=pt(N,g.target)),s[g.source.index]=(s[g.source.index]||0)+1,s[g.target.index]=(s[g.target.index]||0)+1;for(a=0,u=new Array(v);a<v;++a)g=t[a],u[a]=s[g.source.index]/(s[g.source.index]+s[g.target.index]);i=new Array(v),w(),o=new Array(v),c()}}function w(){if(f)for(var a=0,x=t.length;a<x;++a)i[a]=+n(t[a],a,t)}function c(){if(f)for(var a=0,x=t.length;a<x;++a)o[a]=+r(t[a],a,t)}return y.initialize=function(a,x){f=a,l=x,h()},y.links=function(a){return arguments.length?(t=a,h(),y):t},y.id=function(a){return arguments.length?(e=a,y):e},y.iterations=function(a){return arguments.length?(p=+a,y):p},y.strength=function(a){return arguments.length?(n=typeof a=="function"?a:z(+a),w(),y):n},y.distance=function(a){return arguments.length?(r=typeof a=="function"?a:z(+a),c(),y):r},y}const ge=1664525,pe=1013904223,vt=4294967296;function ve(){let t=1;return()=>(t=(ge*t+pe)%vt)/vt}function ye(t){return t.x}function me(t){return t.y}var we=10,_e=Math.PI*(3-Math.sqrt(5));function Ne(t){var e,n=1,i=.001,r=1-Math.pow(i,1/300),o=0,f=.6,s=new Map,u=Nt(m),l=yt("tick","end"),p=ve();t==null&&(t=[]);function m(){y(),l.call("tick",e),n<i&&(u.stop(),l.call("end",e))}function y(c){var a,x=t.length,v;c===void 0&&(c=1);for(var N=0;N<c;++N)for(n+=(o-n)*r,s.forEach(function(g){g(n)}),a=0;a<x;++a)v=t[a],v.fx==null?v.x+=v.vx*=f:(v.x=v.fx,v.vx=0),v.fy==null?v.y+=v.vy*=f:(v.y=v.fy,v.vy=0);return e}function h(){for(var c=0,a=t.length,x;c<a;++c){if(x=t[c],x.index=c,x.fx!=null&&(x.x=x.fx),x.fy!=null&&(x.y=x.fy),isNaN(x.x)||isNaN(x.y)){var v=we*Math.sqrt(.5+c),N=c*_e;x.x=v*Math.cos(N),x.y=v*Math.sin(N)}(isNaN(x.vx)||isNaN(x.vy))&&(x.vx=x.vy=0)}}function w(c){return c.initialize&&c.initialize(t,p),c}return h(),e={tick:y,restart:function(){return u.restart(m),e},stop:function(){return u.stop(),e},nodes:function(c){return arguments.length?(t=c,h(),s.forEach(w),e):t},alpha:function(c){return arguments.length?(n=+c,e):n},alphaMin:function(c){return arguments.length?(i=+c,e):i},alphaDecay:function(c){return arguments.length?(r=+c,e):+r},alphaTarget:function(c){return arguments.length?(o=+c,e):o},velocityDecay:function(c){return arguments.length?(f=1-c,e):1-f},randomSource:function(c){return arguments.length?(p=c,s.forEach(w),e):p},force:function(c,a){return arguments.length>1?(a==null?s.delete(c):s.set(c,w(a)),e):s.get(c)},find:function(c,a,x){var v=0,N=t.length,g,M,A,b,k;for(x==null?x=1/0:x*=x,v=0;v<N;++v)b=t[v],g=c-b.x,M=a-b.y,A=g*g+M*M,A<x&&(k=b,x=A);return k},on:function(c,a){return arguments.length>1?(l.on(c,a),e):l.on(c)}}}function Me(){var t,e,n,i,r=z(-30),o,f=1,s=1/0,u=.81;function l(h){var w,c=t.length,a=nt(t,ye,me).visitAfter(m);for(i=h,w=0;w<c;++w)e=t[w],a.visit(y)}function p(){if(t){var h,w=t.length,c;for(o=new Array(w),h=0;h<w;++h)c=t[h],o[c.index]=+r(c,h,t)}}function m(h){var w=0,c,a,x=0,v,N,g;if(h.length){for(v=N=g=0;g<4;++g)(c=h[g])&&(a=Math.abs(c.value))&&(w+=c.value,x+=a,v+=a*c.x,N+=a*c.y);h.x=v/x,h.y=N/x}else{c=h,c.x=c.data.x,c.y=c.data.y;do w+=o[c.data.index];while(c=c.next)}h.value=w}function y(h,w,c,a){if(!h.value)return!0;var x=h.x-e.x,v=h.y-e.y,N=a-w,g=x*x+v*v;if(N*N/u<g)return g<s&&(x===0&&(x=D(n),g+=x*x),v===0&&(v=D(n),g+=v*v),g<f&&(g=Math.sqrt(f*g)),e.vx+=x*h.value*i/g,e.vy+=v*h.value*i/g),!0;if(h.length||g>=s)return;(h.data!==e||h.next)&&(x===0&&(x=D(n),g+=x*x),v===0&&(v=D(n),g+=v*v),g<f&&(g=Math.sqrt(f*g)));do h.data!==e&&(N=o[h.data.index]*i/g,e.vx+=x*N,e.vy+=v*N);while(h=h.next)}return l.initialize=function(h,w){t=h,n=w,p()},l.strength=function(h){return arguments.length?(r=typeof h=="function"?h:z(+h),p(),l):r},l.distanceMin=function(h){return arguments.length?(f=h*h,l):Math.sqrt(f)},l.distanceMax=function(h){return arguments.length?(s=h*h,l):Math.sqrt(s)},l.theta=function(h){return arguments.length?(u=h*h,l):Math.sqrt(u)},l}function je(t){var e=z(.1),n,i,r;typeof t!="function"&&(t=z(t==null?0:+t));function o(s){for(var u=0,l=n.length,p;u<l;++u)p=n[u],p.vx+=(r[u]-p.x)*i[u]*s}function f(){if(n){var s,u=n.length;for(i=new Array(u),r=new Array(u),s=0;s<u;++s)i[s]=isNaN(r[s]=+t(n[s],s,n))?0:+e(n[s],s,n)}}return o.initialize=function(s){n=s,f()},o.strength=function(s){return arguments.length?(e=typeof s=="function"?s:z(+s),f(),o):e},o.x=function(s){return arguments.length?(t=typeof s=="function"?s:z(+s),f(),o):t},o}function be(t){var e=z(.1),n,i,r;typeof t!="function"&&(t=z(t==null?0:+t));function o(s){for(var u=0,l=n.length,p;u<l;++u)p=n[u],p.vy+=(r[u]-p.y)*i[u]*s}function f(){if(n){var s,u=n.length;for(i=new Array(u),r=new Array(u),s=0;s<u;++s)i[s]=isNaN(r[s]=+t(n[s],s,n))?0:+e(n[s],s,n)}}return o.initialize=function(s){n=s,f()},o.strength=function(s){return arguments.length?(e=typeof s=="function"?s:z(+s),f(),o):e},o.y=function(s){return arguments.length?(t=typeof s=="function"?s:z(+s),f(),o):t},o}const Z={new:"rgb(var(--muted) / 0.45)",seen:"rgb(var(--accent) / 0.45)",understood:"rgb(var(--good))",fading:"rgb(var(--warn) / 0.7)",stale:"rgb(var(--warn))"};function ke(t){const e=t.nodes.map(r=>({id:r.path,fanIn:r.fanIn,fanOut:r.fanOut,r:Math.min(18,4+Math.sqrt(r.fanIn)*2.5)})),n=new Map(e.map(r=>[r.id,r])),i=t.edges.map(r=>({source:r.from,target:r.to}));return Ne(e).force("link",xe(i).id(r=>r.id).distance(60).strength(.3)).force("charge",Me().strength(-170)).force("center",fe(0,0)).force("x",je(0).strength(.07)).force("y",be(0).strength(.07)).force("collide",he().radius(r=>r.r+3)).stop().tick(300),{nodes:e,links:t.edges.map(r=>({s:n.get(r.from),t:n.get(r.to)}))}}function Ae(t,e,n){if(!e.size)return t;const i=new Set([...e].filter(r=>t.nodes.some(o=>o.path===r)));if(n)for(const r of t.edges)e.has(r.from)&&i.add(r.to),e.has(r.to)&&i.add(r.from);return{nodes:t.nodes.filter(r=>i.has(r.path)),edges:t.edges.filter(r=>i.has(r.from)&&i.has(r.to))}}function ze(){var lt;const{project:t,rel:e,setOpenFile:n,setSelected:i}=$t(),r=Tt(),o=ft({queryKey:["graph",t.id],queryFn:()=>ht(`/projects/${t.id}/graph`)}),f=ft({queryKey:["progress",t.id],queryFn:()=>ht(`/projects/${t.id}/progress`)}),s=L.useMemo(()=>new Map((f.data??[]).map(d=>[d.path,d.level])),[f.data]),u=`gl.map.${t.id}`,[l,p]=L.useState(()=>{try{return new Set(JSON.parse(sessionStorage.getItem(u)??"[]"))}catch{return new Set}}),[m,y]=L.useState(!0),[h,w]=L.useState(null);L.useEffect(()=>{try{sessionStorage.setItem(u,JSON.stringify([...l]))}catch{}},[u,l]);const c=L.useMemo(()=>o.data?Ae(o.data,l,m):null,[o.data,l,m]),a=L.useMemo(()=>c?ke(c):null,[c]),x=L.useMemo(()=>o.data?Ft(t.root,o.data.nodes.map(d=>d.path).sort()):[],[o.data,t.root]),[v,N]=L.useState(null),g=v??h;L.useEffect(()=>{A({x:0,y:0,k:1})},[c]);const[M,A]=L.useState({x:0,y:0,k:1}),b=L.useRef(null);if(o.isLoading)return _.jsx("div",{className:"p-8",children:_.jsx(Pt,{})});if(!((lt=o.data)!=null&&lt.nodes.length)||!a)return _.jsx(ct,{icon:_.jsx(Lt,{className:"h-6 w-6"}),title:"No imports found",children:"The map reads import lines in TypeScript, JavaScript and Python files. This folder has none that point to other files in it."});const k=[...a.nodes].sort((d,P)=>P.fanIn-d.fanIn).slice(0,15),E=new Set((a.nodes.length<=25?a.nodes:k.slice(0,8)).map(d=>d.id)),j=new Set;if(g)for(const d of a.links)d.s.id===g&&j.add(d.t.id),d.t.id===g&&j.add(d.s.id);const $=a.nodes.map(d=>d.x??0),T=a.nodes.map(d=>d.y??0),F=40,jt=380,bt=280,kt=Math.max(...$)-Math.min(...$)+F*2,At=Math.max(...T)-Math.min(...T)+F*2,St=(Math.max(...$)+Math.min(...$))/2,zt=(Math.max(...T)+Math.min(...T))/2,it=Math.max(kt,jt),ot=Math.max(At,bt),X={x:St-it/2,y:zt-ot/2,w:it,h:ot},It=`${X.x+M.x} ${X.y+M.y} ${X.w/M.k} ${X.h/M.k}`,st=d=>{n(d),i([d]),r(`/p/${t.id}/explore`)},at=_.jsxs("div",{className:"flex h-full flex-col bg-panel",children:[_.jsxs("div",{className:"border-b border-line px-3 py-2.5",children:[_.jsx("div",{className:"text-sm font-semibold",children:"Show only"}),_.jsx("div",{className:"text-[12px] text-muted",children:l.size?`${l.size} file${l.size===1?"":"s"} ticked`:"Tick folders or files; none ticked shows all."}),_.jsxs("div",{className:"mt-2 flex items-center gap-3 text-xs",children:[_.jsxs("label",{className:"flex cursor-pointer items-center gap-1.5",children:[_.jsx("input",{type:"checkbox",className:"accent-[rgb(var(--accent))]",checked:m,onChange:d=>y(d.target.checked)}),"with direct imports and importers"]}),l.size>0&&_.jsx("button",{className:"ml-auto text-muted hover:text-ink",onClick:()=>p(new Set),children:"clear"})]})]}),_.jsx("div",{className:"min-h-0 flex-1",children:_.jsx(Ot,{roots:x,selected:[...l],onToggle:(d,P)=>{const O=new Set(l);for(const C of d)P?O.add(C):O.delete(C);p(O)},openFile:h,onOpen:d=>w(h===d?null:d),levels:s})})]});if(!a.nodes.length)return _.jsx(ut,{id:"map-tree",collapsible:!0,initial:280,className:"h-full",left:at,right:_.jsx(ct,{title:"Nothing to show",children:"None of the ticked files import or are imported by another file here."})});const Et=_.jsxs("div",{className:"flex h-full",children:[_.jsxs("div",{className:"relative min-w-0 flex-1 bg-panel",children:[_.jsxs("svg",{className:"h-full w-full cursor-grab active:cursor-grabbing",viewBox:It,onWheel:d=>A(P=>({...P,k:Math.min(8,Math.max(.3,P.k*(d.deltaY<0?1.15:1/1.15)))})),onMouseDown:d=>b.current={x:d.clientX,y:d.clientY},onMouseUp:()=>b.current=null,onMouseLeave:()=>b.current=null,onMouseMove:d=>{if(!b.current)return;const P=d.currentTarget.getBoundingClientRect(),O=X.w/M.k/P.width,C=(d.clientX-b.current.x)*O,K=(d.clientY-b.current.y)*O;b.current={x:d.clientX,y:d.clientY},A(W=>({...W,x:W.x-C,y:W.y-K}))},children:[_.jsx("defs",{children:_.jsx("marker",{id:"arrow",viewBox:"0 0 10 10",refX:"10",refY:"5",markerWidth:"5",markerHeight:"5",orient:"auto-start-reverse",children:_.jsx("path",{d:"M0,0 L10,5 L0,10 z",fill:"rgb(var(--muted) / 0.5)"})})}),a.links.map((d,P)=>{const O=g&&(d.s.id===g||d.t.id===g),C=(d.t.x??0)-(d.s.x??0),K=(d.t.y??0)-(d.s.y??0),W=Math.hypot(C,K)||1;return _.jsx("line",{x1:d.s.x,y1:d.s.y,x2:(d.t.x??0)-C/W*(d.t.r+2),y2:(d.t.y??0)-K/W*(d.t.r+2),stroke:O?"rgb(var(--accent))":"rgb(var(--muted) / 0.25)",strokeWidth:O?1.5:.8,markerEnd:"url(#arrow)"},P)}),a.nodes.map(d=>{const P=g&&d.id!==g&&!j.has(d.id);return _.jsxs("g",{transform:`translate(${d.x},${d.y})`,opacity:P?.25:1,className:"cursor-pointer",onMouseEnter:()=>N(d.id),onMouseLeave:()=>N(null),onClick:()=>st(d.id),children:[_.jsx("circle",{r:d.r,fill:Z[s.get(d.id)??"new"],stroke:"rgb(var(--panel))",strokeWidth:1.5}),(E.has(d.id)||d.id===g)&&_.jsx("text",{y:-d.r-4,textAnchor:"middle",className:"fill-ink font-mono",fontSize:10,paintOrder:"stroke",stroke:"rgb(var(--panel))",strokeWidth:3,strokeLinejoin:"round",children:d.id.split("/").pop()})]},d.id)})]}),_.jsxs("div",{className:"pointer-events-none absolute bottom-3 left-3 flex flex-wrap gap-2 text-[12px] text-muted",children:[["new","seen","understood","fading","stale"].map(d=>_.jsxs("span",{className:"flex items-center gap-1",children:[_.jsx("span",{className:"h-2.5 w-2.5 rounded-full",style:{background:Z[d]}}),d]},d)),_.jsx("span",{children:"· size = imported by · scroll to zoom, drag to move"})]}),g&&_.jsx("div",{className:"absolute left-3 top-3 rounded-md bg-raised px-2 py-1 font-mono text-xs",children:e(g)})]}),_.jsxs("aside",{className:"w-[300px] shrink-0 overflow-auto border-l border-line bg-panel p-4",children:[_.jsx("h1",{className:"text-base font-semibold",children:"Map"}),_.jsxs("p",{className:"text-xs text-muted",children:[a.nodes.length,l.size?` of ${o.data.nodes.length}`:""," files, ",a.links.length," imports. Files many others import are a good place to start.",h&&" Click a file in the tree again to unpin it."]}),_.jsx("div",{className:"label mt-4",children:"Most depended on"}),_.jsx("ol",{className:"space-y-1",children:k.map(d=>_.jsx("li",{children:_.jsxs("button",{className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-left hover:bg-raised",onMouseEnter:()=>N(d.id),onMouseLeave:()=>N(null),onClick:()=>st(d.id),children:[_.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full",style:{background:Z[s.get(d.id)??"new"]}}),_.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-[13px]",title:e(d.id),children:Dt(e(d.id),30)}),_.jsx(Ct,{children:d.fanIn})]})},d.id))})]})]});return _.jsx(ut,{id:"map-tree",collapsible:!0,initial:280,className:"h-full",left:at,right:Et})}export{ze as MapPage};