pi-weave 0.1.6 → 0.1.8

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 (96) hide show
  1. package/README.md +114 -37
  2. package/package.json +16 -4
  3. package/src/core/cache/workspace.ts +466 -0
  4. package/src/core/frontmatter.ts +217 -23
  5. package/src/core/git.ts +19 -0
  6. package/src/core/graph/build.ts +37 -4
  7. package/src/core/graph/current.ts +41 -28
  8. package/src/core/graph/mentions.ts +170 -0
  9. package/src/core/graph/model.ts +24 -0
  10. package/src/core/index.ts +12 -0
  11. package/src/core/openInEditor.ts +69 -0
  12. package/src/core/types.ts +40 -0
  13. package/src/core/vault.ts +477 -43
  14. package/src/core/view/cluster.ts +262 -0
  15. package/src/core/view/detail.ts +118 -0
  16. package/src/core/view/focus.ts +109 -0
  17. package/src/core/view/health.ts +156 -0
  18. package/src/core/view/index.ts +15 -0
  19. package/src/core/view/links.ts +105 -0
  20. package/src/core/view/time.ts +47 -0
  21. package/src/core/view/tree.ts +269 -0
  22. package/src/core/view/types.ts +39 -0
  23. package/src/pi/index.ts +102 -19
  24. package/src/pi/viewer/tui/bodyStore.ts +98 -0
  25. package/src/pi/viewer/tui/branding.ts +154 -0
  26. package/src/pi/viewer/tui/explorer.ts +20 -31
  27. package/src/pi/viewer/tui/model.ts +46 -667
  28. package/src/pi/viewer/tui/openNote.ts +11 -0
  29. package/src/pi/viewer/tui/run.ts +13 -4
  30. package/src/pi/viewer/tui/surface/base.ts +182 -0
  31. package/src/pi/viewer/tui/surface/detail.ts +315 -0
  32. package/src/pi/viewer/tui/surface/explore.ts +206 -0
  33. package/src/pi/viewer/tui/surface/focus.ts +139 -0
  34. package/src/pi/viewer/tui/surface/health.ts +102 -0
  35. package/src/pi/viewer/tui/workspace.ts +381 -0
  36. package/src/pi/viewer/tui/workspaceRoot.ts +530 -0
  37. package/src/pi/viewer/web/run.ts +331 -0
  38. package/src/web/client/api.dom.ts +40 -0
  39. package/src/web/client/api.ts +472 -0
  40. package/src/web/client/bootstrap.ts +58 -0
  41. package/src/web/client/context/context.model.ts +313 -0
  42. package/src/web/client/dist/app.js +751 -0
  43. package/src/web/client/graph/Graph.tsx +158 -0
  44. package/src/web/client/graph/column.model.ts +431 -0
  45. package/src/web/client/graph/graph.model.ts +538 -0
  46. package/src/web/client/graph/positions.ts +339 -0
  47. package/src/web/client/graph/project.ts +153 -0
  48. package/src/web/client/graph/renderer.dom.ts +52 -0
  49. package/src/web/client/graph/renderer.ts +279 -0
  50. package/src/web/client/graph/scheme.ts +44 -0
  51. package/src/web/client/live.model.ts +275 -0
  52. package/src/web/client/live.ts +151 -0
  53. package/src/web/client/main.tsx +27 -0
  54. package/src/web/client/note/Editor.tsx +102 -0
  55. package/src/web/client/note/Note.tsx +113 -0
  56. package/src/web/client/note/editor.controller.ts +151 -0
  57. package/src/web/client/note/editor.model.ts +636 -0
  58. package/src/web/client/note/note.model.ts +738 -0
  59. package/src/web/client/search/SearchPalette.tsx +105 -0
  60. package/src/web/client/search/search.model.ts +588 -0
  61. package/src/web/client/search/search.ts +107 -0
  62. package/src/web/client/shell/Columns.tsx +161 -0
  63. package/src/web/client/shell/ContextRail.tsx +87 -0
  64. package/src/web/client/shell/Divider.tsx +44 -0
  65. package/src/web/client/shell/FocusTrap.tsx +56 -0
  66. package/src/web/client/shell/Header.tsx +54 -0
  67. package/src/web/client/shell/HelpOverlay.tsx +70 -0
  68. package/src/web/client/shell/Shell.tsx +193 -0
  69. package/src/web/client/shell/StatusBar.tsx +28 -0
  70. package/src/web/client/shell/cssvars.ts +70 -0
  71. package/src/web/client/shell/drag.model.ts +170 -0
  72. package/src/web/client/shell/focus.model.ts +100 -0
  73. package/src/web/client/shell/keys.model.ts +453 -0
  74. package/src/web/client/shell/keys.ts +59 -0
  75. package/src/web/client/shell/layout.model.ts +526 -0
  76. package/src/web/client/shell/shell.model.ts +333 -0
  77. package/src/web/client/shell/theme.ts +477 -0
  78. package/src/web/client/shell/viewport.ts +29 -0
  79. package/src/web/client/state.ts +78 -0
  80. package/src/web/client/tree/Tree.tsx +138 -0
  81. package/src/web/client/tree/tree.model.ts +674 -0
  82. package/src/web/client/workspace.ts +214 -0
  83. package/src/web/server/page.ts +256 -0
  84. package/src/web/server/routes.ts +975 -0
  85. package/src/web/server/security.ts +361 -0
  86. package/src/web/server/server.ts +275 -0
  87. package/src/web/server/sse.ts +321 -0
  88. package/src/web/server/watcher.ts +507 -0
  89. package/src/web/shared/graph.ts +206 -0
  90. package/src/web/shared/layout.ts +497 -0
  91. package/src/web/shared/metrics.ts +136 -0
  92. package/src/web/shared/view.ts +200 -0
  93. package/src/web/shared/wire.ts +358 -0
  94. package/src/pi/viewer/browser.ts +0 -29
  95. package/src/pi/viewer/page.ts +0 -1316
  96. package/src/pi/viewer/server.ts +0 -229
@@ -0,0 +1,206 @@
1
+ /**
2
+ * The graph shapes as they appear **on the wire** (weave-workspace §5.3).
3
+ *
4
+ * ## Why these are declared here and not imported from core
5
+ *
6
+ * They used to be `import type { GraphModel } from "../../core/graph/model"`,
7
+ * and that single line was an architectural violation with a build failure
8
+ * attached to it.
9
+ *
10
+ * The reasoning that put it there was: "`import type` erases at compile time,
11
+ * so it cannot drag `node:fs` into the browser bundle." That is true, and it
12
+ * is also not the whole story. Type erasure protects the **bundle**; it does
13
+ * nothing for the **typecheck**. To resolve `GraphModel`, TypeScript must load
14
+ * `src/core/graph/model.ts`, which imports `../types`, and the compiler walks
15
+ * that whole graph — under `tsconfig.web.json`, which deliberately has
16
+ * `"types": []` and no node lib, so every `node:fs` in the transitive closure
17
+ * is an error. The client tier was importing core in every sense that
18
+ * mattered except the one the rule was written to check.
19
+ *
20
+ * So the tier rule is now literal rather than aspirational: **nothing under
21
+ * `src/web/shared/` imports `src/core` at all**, not even as a type. That is
22
+ * stricter than the §2 table as written (which permits core types here), and
23
+ * it is the version worth having, because "types only" is a distinction the
24
+ * compiler does not make when resolving a project.
25
+ *
26
+ * ## The contract is deliberately a copy, not an alias
27
+ *
28
+ * This is not duplication for its own sake — it is the wire format being
29
+ * honest about what it is. `GraphModel` is an *internal* core type, free to
30
+ * change shape when core needs it to. What crosses an HTTP boundary is a
31
+ * *contract*, and a contract that silently reshapes itself whenever an
32
+ * internal type is refactored is not a contract. Declaring it separately
33
+ * means a core change that would break the client is a visible, deliberate
34
+ * edit here rather than an invisible one.
35
+ *
36
+ * The obvious risk of a copy is drift, so drift is a **compile error**:
37
+ * `tests/web/wire.contract.test.ts` asserts mutual assignability between
38
+ * every type here and its core counterpart. That test is Node-side, where
39
+ * importing core is legal and free. Add a field to `GraphNode` in core and
40
+ * that test fails to compile until this file agrees — which is exactly the
41
+ * moment a human should be deciding whether the new field belongs on the
42
+ * wire.
43
+ *
44
+ * Isomorphic: no `node:*`, no DOM, no `src/core`, no `src/pi`.
45
+ */
46
+
47
+ /**
48
+ * Where a piece of knowledge came from. Drives trust display (design §13).
49
+ *
50
+ * Mirrors `NoteSource` in `src/core/types.ts`.
51
+ */
52
+ export type WireNoteSource = "human" | "agent" | "generated";
53
+
54
+ /** Mirrors `StalenessState` in `src/core/types.ts`. */
55
+ export type WireStalenessState = "missing" | "fresh" | "stale";
56
+
57
+ /** Mirrors `StalenessReport` in `src/core/types.ts`. */
58
+ export interface WireStalenessReport {
59
+ state: WireStalenessState;
60
+ reasons: string[];
61
+ }
62
+
63
+ /** Mirrors `NodeKind` in `src/core/graph/model.ts`. */
64
+ export type WireNodeKind =
65
+ | "vault"
66
+ | "note"
67
+ | "repository"
68
+ | "module"
69
+ | "package"
70
+ | "entryPoint"
71
+ | "gitState"
72
+ | "external"
73
+ | "file";
74
+
75
+ /** Mirrors `EdgeKind` in `src/core/graph/model.ts`. */
76
+ export type WireEdgeKind = "contains" | "anchored-at" | "links-to" | "mentions";
77
+
78
+ /**
79
+ * Every node kind. The graph legend and the table tests iterate this.
80
+ *
81
+ * A runtime value, unlike everything else in this file, because a renderer
82
+ * needs to enumerate kinds to build a legend and a `type` cannot be iterated.
83
+ * The contract test pins it against core's `NODE_KINDS` element-for-element,
84
+ * so a kind added to core and not here is a failing test rather than a
85
+ * legend that quietly omits a colour.
86
+ */
87
+ export const WIRE_NODE_KINDS: readonly WireNodeKind[] = [
88
+ "vault",
89
+ "note",
90
+ "repository",
91
+ "module",
92
+ "package",
93
+ "entryPoint",
94
+ "gitState",
95
+ "external",
96
+ "file",
97
+ ];
98
+
99
+ /** Every edge kind. Same reasoning as {@link WIRE_NODE_KINDS}. */
100
+ export const WIRE_EDGE_KINDS: readonly WireEdgeKind[] = ["contains", "anchored-at", "links-to", "mentions"];
101
+
102
+ /**
103
+ * A single graph node. `id` is stable: derived from slugs and paths only.
104
+ *
105
+ * Mirrors `GraphNode` in `src/core/graph/model.ts`.
106
+ */
107
+ export interface WireGraphNode {
108
+ id: string;
109
+ kind: WireNodeKind;
110
+ label: string;
111
+ /** Trust provenance for knowledge nodes; `null` for structural nodes. */
112
+ provenance: WireNoteSource | null;
113
+ /** Pre-formatted side-panel payload. Display-only by contract. */
114
+ detail: Record<string, string>;
115
+ }
116
+
117
+ /** Mirrors `GraphEdge` in `src/core/graph/model.ts`. */
118
+ export interface WireGraphEdge {
119
+ source: string;
120
+ target: string;
121
+ kind: WireEdgeKind;
122
+ }
123
+
124
+ /**
125
+ * The authoritative node/edge data, as delivered to the browser.
126
+ *
127
+ * Mirrors `GraphModel` in `src/core/graph/model.ts`, **narrowed by one
128
+ * field**: core's `danglingLinks` (§4.2) is not repeated here.
129
+ *
130
+ * §2.1 allows a wire type to be deliberately narrower than its core
131
+ * counterpart provided the narrowing is *declared* rather than discovered,
132
+ * and this is that declaration. The reason is `GraphPayload` (§5.3): the
133
+ * payload already hoists that index to its own top level as `dangling`, so
134
+ * mirroring it inside `model` as well would put the same map on the wire
135
+ * twice and give the client two places to read one fact from.
136
+ *
137
+ * Two things keep the narrowing honest rather than aspirational.
138
+ * `tests/web/wire.contract.test.ts` asserts
139
+ * `Exact<WireGraphModel, Omit<GraphModel, "danglingLinks">>` — still mutual
140
+ * assignability, merely against an explicitly reduced core type, so a
141
+ * *second* core field added and forgotten still fails to compile. And
142
+ * `toGraphPayload` strips the key at the single point that builds the
143
+ * payload, because TypeScript's structural typing would otherwise let the
144
+ * extra property ride along into `JSON.stringify`.
145
+ */
146
+ export interface WireGraphModel {
147
+ /**
148
+ * Data-as-of marker derived from inputs (max note `updated` / index stamp),
149
+ * so two builds of unchanged inputs produce byte-identical JSON. That is
150
+ * the property `GraphPayload.stamp` and the `304` path depend on.
151
+ */
152
+ generatedAt: string;
153
+ staleness: WireStalenessReport | null;
154
+ nodes: WireGraphNode[];
155
+ edges: WireGraphEdge[];
156
+ }
157
+
158
+ /**
159
+ * The core `GraphModel` keys {@link WireGraphModel} deliberately omits.
160
+ *
161
+ * A runtime value rather than only a comment, for the same reason
162
+ * {@link WIRE_NODE_KINDS} is one: the server has to actually delete these
163
+ * keys before serializing, and a hand-written second list of them at the
164
+ * emit site is a list that drifts. `toGraphPayload` iterates this.
165
+ */
166
+ export const WIRE_MODEL_OMITTED_KEYS: readonly string[] = ["danglingLinks"];
167
+
168
+ /**
169
+ * One note, read live for the note column.
170
+ *
171
+ * Mirrors `ViewNote` in `src/core/graph/current.ts`.
172
+ */
173
+ export interface WireViewNote {
174
+ slug: string;
175
+ title: string;
176
+ body: string;
177
+ created: string;
178
+ updated: string;
179
+ tags: string[];
180
+ source: WireNoteSource;
181
+ }
182
+
183
+ /** Mirrors `NoteMeta` in `src/core/types.ts`. */
184
+ export interface WireNoteMeta {
185
+ title: string;
186
+ /** ISO-8601 timestamps. */
187
+ created: string;
188
+ updated: string;
189
+ tags: string[];
190
+ source: WireNoteSource;
191
+ }
192
+
193
+ /** Mirrors `NoteSummary` in `src/core/types.ts`. */
194
+ export interface WireNoteSummary extends WireNoteMeta {
195
+ /** File-name slug (no extension). Stable identity of the note. */
196
+ slug: string;
197
+ /** Size of the Markdown body in characters. */
198
+ bodyLength: number;
199
+ }
200
+
201
+ /** Mirrors `NoteSearchHit` in `src/core/types.ts`. */
202
+ export interface WireNoteSearchHit {
203
+ summary: WireNoteSummary;
204
+ score: number;
205
+ snippet: string;
206
+ }