pi-weave 0.1.1
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/LICENSE +21 -0
- package/README.md +122 -0
- package/package.json +69 -0
- package/skills/.gitkeep +0 -0
- package/skills/weave-explore/SKILL.md +64 -0
- package/skills/weave-notepad/SKILL.md +77 -0
- package/src/core/frontmatter.ts +119 -0
- package/src/core/git.ts +194 -0
- package/src/core/graph/build.ts +258 -0
- package/src/core/graph/current.ts +107 -0
- package/src/core/graph/model.ts +63 -0
- package/src/core/graph/wikilinks.ts +28 -0
- package/src/core/index.ts +25 -0
- package/src/core/languages.ts +76 -0
- package/src/core/mutex.ts +34 -0
- package/src/core/paths.ts +37 -0
- package/src/core/repoIndex.ts +404 -0
- package/src/core/slug.ts +28 -0
- package/src/core/summaries.ts +300 -0
- package/src/core/types.ts +155 -0
- package/src/core/vault.ts +254 -0
- package/src/core/workspace.ts +85 -0
- package/src/pi/index.ts +191 -0
- package/src/pi/summarize.ts +134 -0
- package/src/pi/tools/noteTool.ts +178 -0
- package/src/pi/tools/repoTool.ts +94 -0
- package/src/pi/viewer/browser.ts +29 -0
- package/src/pi/viewer/page.ts +1316 -0
- package/src/pi/viewer/server.ts +229 -0
- package/src/pi/viewer/tui/explorer.ts +597 -0
- package/src/pi/viewer/tui/model.ts +1011 -0
- package/src/pi/viewer/tui/run.ts +69 -0
- package/src/pi/viewer/tui/theme.ts +90 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* runWeaveViewTui — wires the WeaveExplorer into a pi session
|
|
3
|
+
* (weave-view-tui-design §2, §4.1, §3.2).
|
|
4
|
+
*
|
|
5
|
+
* Guards (interactive terminal only), builds the graph from disk in the
|
|
6
|
+
* handler, then hands a ready WeaveExplorer to `ctx.ui.custom` so the
|
|
7
|
+
* explorer owns input for its whole lifetime. After `done(null)` resolves,
|
|
8
|
+
* the workspace status line is refreshed. Dependencies are injected so the
|
|
9
|
+
* component never touches a real terminal directly.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
13
|
+
import {
|
|
14
|
+
buildCurrentGraph,
|
|
15
|
+
readNoteForView,
|
|
16
|
+
readOkfFileForView,
|
|
17
|
+
resolveVaultRoot,
|
|
18
|
+
type GraphModel,
|
|
19
|
+
} from "../../../core";
|
|
20
|
+
import { openNoteInEditor } from "../server";
|
|
21
|
+
import { WeaveExplorer, type WeaveLoaders, type WeaveTheme, type WeaveTui } from "./explorer";
|
|
22
|
+
import { getWorkspaceStatus, formatStatusLine } from "../../../core";
|
|
23
|
+
|
|
24
|
+
/** Open the in-terminal knowledge explorer. Returns when the explorer closes. */
|
|
25
|
+
export async function runWeaveViewTui(ctx: ExtensionCommandContext): Promise<void> {
|
|
26
|
+
// Guard: the TUI needs an interactive terminal (design §2).
|
|
27
|
+
if (!ctx.hasUI || ctx.mode !== "tui") {
|
|
28
|
+
ctx.ui.notify(
|
|
29
|
+
"pi-weave: '/weave-view tui' needs an interactive terminal — run /weave-view for the browser viewer.",
|
|
30
|
+
"warning",
|
|
31
|
+
);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const cwd = ctx.cwd;
|
|
36
|
+
const vaultRoot = resolveVaultRoot();
|
|
37
|
+
const model = await buildCurrentGraph(cwd, vaultRoot);
|
|
38
|
+
|
|
39
|
+
const loaders: WeaveLoaders = {
|
|
40
|
+
loadNote: (slug) => readNoteForView(vaultRoot, slug),
|
|
41
|
+
loadOkf: (rel) => readOkfFileForView(cwd, rel),
|
|
42
|
+
openNote: (slug) => openNoteInEditor(vaultRoot, slug),
|
|
43
|
+
rebuild: () => buildCurrentGraph(cwd, vaultRoot),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
await ctx.ui.custom(
|
|
47
|
+
(tui, theme, _keybindings, done) => {
|
|
48
|
+
const explorer = new WeaveExplorer({
|
|
49
|
+
model,
|
|
50
|
+
theme: theme as unknown as WeaveTheme,
|
|
51
|
+
tui: tui as unknown as WeaveTui,
|
|
52
|
+
loaders,
|
|
53
|
+
done,
|
|
54
|
+
rows: tui.terminal.rows,
|
|
55
|
+
});
|
|
56
|
+
return explorer;
|
|
57
|
+
},
|
|
58
|
+
// Full-screen, not an overlay (design §4.1).
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// Refresh the status line after close (a /weave-scan may have landed meanwhile).
|
|
62
|
+
const status = await getWorkspaceStatus(ctx.cwd);
|
|
63
|
+
ctx.ui.setStatus("weave", formatStatusLine(status));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Test seam: build the model the explorer opens with, without a terminal. */
|
|
67
|
+
export async function buildTuiModel(cwd: string, vaultRoot: string = resolveVaultRoot()): Promise<GraphModel> {
|
|
68
|
+
return buildCurrentGraph(cwd, vaultRoot);
|
|
69
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provenance & kind → glyph + theme color-slot maps for the weave-view TUI
|
|
3
|
+
* (weave-view-tui-design §7).
|
|
4
|
+
*
|
|
5
|
+
* Pure data: imports only core types. Theme slots are names only
|
|
6
|
+
* (`theme.fg(slot, …)` applies the actual color), so pi themes restyle
|
|
7
|
+
* everything — never hardcoded hex. Style-first per v2 P1: provenance is
|
|
8
|
+
* glyph + dimness, color is the weak secondary channel.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { NodeKind } from "../../../core/graph/model";
|
|
12
|
+
import type { NoteSource } from "../../../core/types";
|
|
13
|
+
|
|
14
|
+
/** Theme foreground color-slot names understood by pi's `Theme`. */
|
|
15
|
+
export type ThemeSlot =
|
|
16
|
+
| "accent"
|
|
17
|
+
| "success"
|
|
18
|
+
| "warning"
|
|
19
|
+
| "dim"
|
|
20
|
+
| "muted"
|
|
21
|
+
| "text";
|
|
22
|
+
|
|
23
|
+
/** Provenance rendering: glyph prefix, whole-row dimness, and theme slot. */
|
|
24
|
+
export interface ProvenanceStyle {
|
|
25
|
+
glyph: string;
|
|
26
|
+
/** When true, the whole row is rendered dim (generated knowledge). */
|
|
27
|
+
dim: boolean;
|
|
28
|
+
slot: ThemeSlot;
|
|
29
|
+
/** Word printed in the provenance cycle / header banner, e.g. "human". */
|
|
30
|
+
word: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The provenance cycle order for the `p` key: all → human → agent → generated → all. */
|
|
34
|
+
export const PROVENANCE_CYCLE: readonly (NoteSource | null)[] = [null, "human", "agent", "generated"];
|
|
35
|
+
|
|
36
|
+
export function provenanceStyle(prov: NoteSource | null): ProvenanceStyle {
|
|
37
|
+
switch (prov) {
|
|
38
|
+
case "human":
|
|
39
|
+
return { glyph: "●", dim: false, slot: "success", word: "human" };
|
|
40
|
+
case "agent":
|
|
41
|
+
return { glyph: "◐", dim: false, slot: "accent", word: "agent" };
|
|
42
|
+
case "generated":
|
|
43
|
+
return { glyph: "○", dim: true, slot: "dim", word: "generated" };
|
|
44
|
+
default:
|
|
45
|
+
// structural node — no provenance glyph; kind glyph leads.
|
|
46
|
+
return { glyph: "", dim: false, slot: "muted", word: "" };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface KindStyle {
|
|
51
|
+
glyph: string;
|
|
52
|
+
slot: ThemeSlot;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Kind → glyph + slot. Notes defer to their provenance glyph (trust-first). */
|
|
56
|
+
export function kindStyle(kind: NodeKind): KindStyle {
|
|
57
|
+
switch (kind) {
|
|
58
|
+
case "vault":
|
|
59
|
+
return { glyph: "◆", slot: "accent" };
|
|
60
|
+
case "note":
|
|
61
|
+
// provenance glyph leads; kind slot unused for the marker.
|
|
62
|
+
return { glyph: "", slot: "text" };
|
|
63
|
+
case "repository":
|
|
64
|
+
return { glyph: "■", slot: "accent" };
|
|
65
|
+
case "module":
|
|
66
|
+
return { glyph: "▪", slot: "success" };
|
|
67
|
+
case "package":
|
|
68
|
+
return { glyph: "▲", slot: "success" };
|
|
69
|
+
case "entryPoint":
|
|
70
|
+
return { glyph: "▹", slot: "warning" };
|
|
71
|
+
case "gitState":
|
|
72
|
+
return { glyph: "⎇", slot: "warning" };
|
|
73
|
+
case "external":
|
|
74
|
+
return { glyph: "↗", slot: "warning" };
|
|
75
|
+
case "file":
|
|
76
|
+
return { glyph: "·", slot: "dim" };
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Chevron shown for an expandable tree row. */
|
|
81
|
+
export function chevron(expanded: boolean, hasKids: boolean): string {
|
|
82
|
+
if (!hasKids) return " ";
|
|
83
|
+
return expanded ? "▾" : "▸";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Selection gutter marker. */
|
|
87
|
+
export const SELECTION_MARKER = "›";
|
|
88
|
+
|
|
89
|
+
/** Maximum length of the inline search/filter string (design §9.4). */
|
|
90
|
+
export const MAX_FILTER_LEN = 200;
|