@staix/vault-mem-ui 0.0.0-stage → 0.0.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 (64) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +96 -2
  4. package/THIRD_PARTY_NOTICES.md +164 -0
  5. package/bin/vmem-ui.ts +26 -0
  6. package/dist/panel.css +666 -0
  7. package/dist/panel.js +355 -0
  8. package/package.json +53 -4
  9. package/src/client/App.tsx +167 -0
  10. package/src/client/a11y.ts +54 -0
  11. package/src/client/acon.ts +46 -0
  12. package/src/client/components.tsx +243 -0
  13. package/src/client/data.ts +66 -0
  14. package/src/client/fake.ts +48 -0
  15. package/src/client/graph-export.tsx +21 -0
  16. package/src/client/host.ts +80 -0
  17. package/src/client/markdown/parse.ts +620 -0
  18. package/src/client/markdown/render.tsx +270 -0
  19. package/src/client/panel.css +666 -0
  20. package/src/client/panel.tsx +66 -0
  21. package/src/client/prefs.ts +76 -0
  22. package/src/client/standalone.ts +44 -0
  23. package/src/client/store.ts +201 -0
  24. package/src/client/views/assertions.tsx +109 -0
  25. package/src/client/views/common.ts +15 -0
  26. package/src/client/views/history.tsx +205 -0
  27. package/src/client/views/lint.tsx +27 -0
  28. package/src/client/views/log.tsx +64 -0
  29. package/src/client/views/note.tsx +128 -0
  30. package/src/client/views/notes.tsx +34 -0
  31. package/src/client/views/overview.tsx +74 -0
  32. package/src/client/views/promote.tsx +112 -0
  33. package/src/client/views/proposals.tsx +55 -0
  34. package/src/client/views/settings.tsx +57 -0
  35. package/src/client/write.ts +144 -0
  36. package/src/graph/decisionChains.ts +122 -0
  37. package/src/graph/derive.ts +338 -0
  38. package/src/graph/export.ts +44 -0
  39. package/src/graph/insights.ts +254 -0
  40. package/src/graph/labels.ts +67 -0
  41. package/src/graph/layout/client.ts +139 -0
  42. package/src/graph/layout/engine.ts +107 -0
  43. package/src/graph/layout/fa2.d.ts +8 -0
  44. package/src/graph/layout/protocol.ts +70 -0
  45. package/src/graph/layout/worker.ts +132 -0
  46. package/src/graph/model.ts +230 -0
  47. package/src/graph/positions.ts +41 -0
  48. package/src/graph/search.ts +54 -0
  49. package/src/graph/style.ts +301 -0
  50. package/src/graph/target.ts +38 -0
  51. package/src/graph/types.ts +64 -0
  52. package/src/graph/view/GraphView.tsx +279 -0
  53. package/src/graph/view/SidePanels.tsx +141 -0
  54. package/src/graph/view/cache.ts +42 -0
  55. package/src/graph/view/canvas.ts +309 -0
  56. package/src/graph/view/graph-snapshot.ts +75 -0
  57. package/src/graph/view/lod.ts +30 -0
  58. package/src/graph/view/motion.ts +4 -0
  59. package/src/graph/view/state.ts +240 -0
  60. package/src/plugin/assets.ts +33 -0
  61. package/src/plugin/graph.ts +71 -0
  62. package/src/plugin/index.ts +23 -0
  63. package/src/server/cli.ts +99 -0
  64. package/src/server/host.ts +287 -0
@@ -0,0 +1,27 @@
1
+ /** Lint: the vault's findings, errors before warnings, each one opening the note it names. */
2
+
3
+ import { Empty, List } from "../components.tsx";
4
+ import { list, str, type FindingRow } from "../data.ts";
5
+ import type { ViewProps } from "./common.ts";
6
+ import { vaultParam } from "./common.ts";
7
+
8
+ export function LintView({ reply, params, navigate }: ViewProps) {
9
+ const findings = list<FindingRow>(reply.findings);
10
+ const summary = str(reply.summary);
11
+ return (
12
+ <>
13
+ <p className="vmem-sub">{summary}</p>
14
+ <List
15
+ label="Lint findings"
16
+ items={findings.map((finding, index) => ({
17
+ key: `${finding.code}:${index}:${str(finding.message)}`,
18
+ title: str(finding.message),
19
+ sub: [str(finding.code), str(finding.path)].filter(Boolean).join(" · "),
20
+ chip: { text: str(finding.severity) || "warning", tone: finding.severity === "error" ? "err" : "warn" },
21
+ ...(finding.path ? { onOpen: () => navigate("note", { path: str(finding.path), ...vaultParam(params) }) } : {}),
22
+ }))}
23
+ empty={<Empty title="No lint findings" hint="The vault passes every check." />}
24
+ />
25
+ </>
26
+ );
27
+ }
@@ -0,0 +1,64 @@
1
+ /** Log: the vault's change log, newest first, with a type filter and a cursor for newer rows. */
2
+
3
+ import { useState } from "react";
4
+ import { Empty, List, Notice } from "../components.tsx";
5
+ import { list, str, when, type LogRow } from "../data.ts";
6
+ import type { ViewProps } from "./common.ts";
7
+ import { vaultParam } from "./common.ts";
8
+
9
+ export function LogView({ reply, params, navigate }: ViewProps) {
10
+ const rows = list<LogRow>(reply.rows);
11
+ const error = str(reply.error);
12
+ const cursor = str(reply.cursor);
13
+ const [type, setType] = useState(params.type ?? "");
14
+ return (
15
+ <>
16
+ {error ? <Notice tone="err">{error}</Notice> : null}
17
+ <form
18
+ className="vmem-bar"
19
+ role="search"
20
+ onSubmit={(event) => {
21
+ event.preventDefault();
22
+ const next = type.trim();
23
+ navigate("log", { ...(next ? { type: next } : {}), ...vaultParam(params) });
24
+ }}
25
+ >
26
+ <input
27
+ className="vmem-input"
28
+ type="search"
29
+ name="type"
30
+ value={type}
31
+ placeholder="Filter by type (e.g. LEARN)"
32
+ aria-label="Filter the log by type"
33
+ onChange={(event) => setType(event.currentTarget.value)}
34
+ />
35
+ <button type="submit" className="vmem-button">
36
+ Filter
37
+ </button>
38
+ {cursor ? (
39
+ <button
40
+ type="button"
41
+ className="vmem-button"
42
+ onClick={() => navigate("log", { since: cursor, ...(type.trim() ? { type: type.trim() } : {}), ...vaultParam(params) })}
43
+ >
44
+ Newer entries
45
+ </button>
46
+ ) : null}
47
+ </form>
48
+ <List
49
+ label="Log"
50
+ items={rows.map((row, index) => {
51
+ const path = str(row.dest) || str(row.source);
52
+ return {
53
+ key: `${index}:${str(row.at)}:${str(row.source)}`,
54
+ title: row.raw ?? `${str(row.type)} ${str(row.source)}${row.dest ? ` → ${str(row.dest)}` : ""}`,
55
+ sub: row.raw ? "unparsed line" : [when(row.at), str(row.project), str(row.note), row.agent ? "agent" : ""].filter(Boolean).join(" · "),
56
+ ...(path.startsWith("notes/") ? { onOpen: () => navigate("note", { path, ...vaultParam(params) }) } : {}),
57
+ };
58
+ })}
59
+ empty={<Empty title="Log is empty" hint="A write appends a line here." />}
60
+ />
61
+ {reply.more ? <p className="vmem-sub">Older entries exist; narrow the filter to see them.</p> : null}
62
+ </>
63
+ );
64
+ }
@@ -0,0 +1,128 @@
1
+ /** One note: its frontmatter, body and links, with delete, move and promote as previewed writes. */
2
+
3
+ import { useState } from "react";
4
+ import { Chip, Empty, Field, List, Notice } from "../components.tsx";
5
+ import { list, rec, str, type LinkRow } from "../data.ts";
6
+ import { Markdown } from "../markdown/render.tsx";
7
+ import type { ViewProps } from "./common.ts";
8
+ import { vaultParam } from "./common.ts";
9
+
10
+ export function NoteView({ reply, params, navigate, beginWrite }: ViewProps) {
11
+ const note = rec(reply.note);
12
+ const error = str(reply.error);
13
+ const orgVaults = list<string>(reply.orgVaults).map(str);
14
+ const [to, setTo] = useState("");
15
+ const [org, setOrg] = useState(orgVaults[0] ?? "");
16
+ const [topics, setTopics] = useState("");
17
+ const [again, setAgain] = useState(false);
18
+ if (error) return <Notice tone="err">{error}</Notice>;
19
+ if (!note.path) {
20
+ return <Empty title="No note selected" hint="Open a note from Search or from a link in another note." />;
21
+ }
22
+ const path = str(note.path);
23
+ const front = rec(note.frontmatter);
24
+ const links = rec(reply.links);
25
+ const out = list<LinkRow>(links.out);
26
+ const back = list<LinkRow>(links.in);
27
+ const dead = list<LinkRow>(links.dead);
28
+ const rows = [
29
+ ...out.map((link) => ({ key: `out:${str(link.resolved)}`, label: `→ ${str(link.resolved)}`, path: str(link.resolved) })),
30
+ ...back.map((link) => ({ key: `in:${str(link.source)}`, label: `← ${str(link.source)}`, path: str(link.source) })),
31
+ ...dead.map((link) => ({ key: `dead:${str(link.target)}`, label: `✕ ${str(link.target)}`, path: "" })),
32
+ ];
33
+ return (
34
+ <>
35
+ <header className="vmem-detail-head">
36
+ <p className="vmem-sub">
37
+ {str(front.type) || "note"}
38
+ {front.status ? <Chip text={str(front.status)} tone={str(front.status) === "superseded" ? "warn" : "neutral"} /> : null}
39
+ </p>
40
+ <h1 className="vmem-detail-title">{str(front.title) || path}</h1>
41
+ {front.description ? <p className="vmem-sub">{str(front.description)}</p> : null}
42
+ </header>
43
+ <div className="vmem-bar">
44
+ <button
45
+ type="button"
46
+ className="vmem-button vmem-button-danger"
47
+ onClick={() => beginWrite({ action: "delete", path, ...vaultParam(params) })}
48
+ >
49
+ Delete…
50
+ </button>
51
+ <button type="button" className="vmem-button" onClick={() => navigate("history", { path, ...vaultParam(params) })}>
52
+ History…
53
+ </button>
54
+ <form
55
+ className="vmem-inline"
56
+ onSubmit={(event) => {
57
+ event.preventDefault();
58
+ if (to.trim()) beginWrite({ action: "move", from: path, to: to.trim(), ...vaultParam(params) });
59
+ }}
60
+ >
61
+ <Field name="to" label="New stem" value={to} placeholder="new-stem" onChange={setTo} />
62
+ <button type="submit" className="vmem-button">
63
+ Move…
64
+ </button>
65
+ </form>
66
+ </div>
67
+ {orgVaults.length ? (
68
+ <form
69
+ className="vmem-inline vmem-promote-form"
70
+ onSubmit={(event) => {
71
+ event.preventDefault();
72
+ beginWrite({
73
+ action: "promote",
74
+ path,
75
+ to: org,
76
+ ...(topics.trim() ? { topics: topics.trim() } : {}),
77
+ ...(again ? { again: true } : {}),
78
+ ...vaultParam(params),
79
+ });
80
+ }}
81
+ >
82
+ <label className="vmem-label" htmlFor="vmem-org">
83
+ Org vault
84
+ </label>
85
+ <select id="vmem-org" className="vmem-input" value={org} onChange={(event) => setOrg(event.currentTarget.value)}>
86
+ {orgVaults.map((id) => (
87
+ <option key={id} value={id}>
88
+ {id}
89
+ </option>
90
+ ))}
91
+ </select>
92
+ <Field name="orgTopics" label="Topics (optional)" value={topics} placeholder="topic, topic" onChange={setTopics} />
93
+ <label className="vmem-check">
94
+ <input type="checkbox" checked={again} onChange={(event) => setAgain(event.currentTarget.checked)} /> promote again
95
+ </label>
96
+ <button type="submit" className="vmem-button">
97
+ Promote to org…
98
+ </button>
99
+ </form>
100
+ ) : null}
101
+ <section className="vmem-section" aria-label="Body">
102
+ <Markdown
103
+ text={str(note.body)}
104
+ links={reply.links}
105
+ onOpenNote={(path) => navigate("note", { path, ...vaultParam(params) })}
106
+ />
107
+ {note.truncated ? <Notice tone="warn">Truncated; open the file for the rest.</Notice> : null}
108
+ </section>
109
+ <section className="vmem-section" aria-label="Links">
110
+ <h2 className="vmem-card-title">
111
+ Links ({out.length} out, {back.length} in{dead.length ? `, ${dead.length} dead` : ""})
112
+ </h2>
113
+ <List
114
+ label="Links"
115
+ items={rows.map((row) => ({
116
+ key: row.key,
117
+ title: row.label,
118
+ ...(row.path ? { onOpen: () => navigate("note", { path: row.path, ...vaultParam(params) }) } : {}),
119
+ }))}
120
+ empty={<Empty title="No links" />}
121
+ />
122
+ </section>
123
+ <p className="vmem-sub vmem-footer">
124
+ {path} · sha256 {str(note.sha256).slice(0, 12)}
125
+ </p>
126
+ </>
127
+ );
128
+ }
@@ -0,0 +1,34 @@
1
+ /** Search / notes list: a query, or the newest notes when the query is empty. */
2
+
3
+ import { Empty, List, Notice, SearchForm } from "../components.tsx";
4
+ import { list, str, type NoteRow } from "../data.ts";
5
+ import type { ViewProps } from "./common.ts";
6
+ import { vaultParam } from "./common.ts";
7
+
8
+ export function NotesView({ reply, params, navigate }: ViewProps) {
9
+ const q = str(reply.q);
10
+ const notes = list<NoteRow>(reply.notes);
11
+ const error = str(reply.error);
12
+ return (
13
+ <>
14
+ <SearchForm value={q} onSubmit={(next) => navigate("notes", { ...(next ? { q: next } : {}), ...vaultParam(params) })} />
15
+ {error ? <Notice tone="err">{error}</Notice> : null}
16
+ <List
17
+ label={q ? `Results for ${q}` : "Notes"}
18
+ items={notes.map((note) => ({
19
+ key: note.path,
20
+ title: str(note.title) || note.path,
21
+ sub: [str(note.type), str(note.domain), str(note.description)].filter(Boolean).join(" · "),
22
+ onOpen: () => navigate("note", { path: note.path, ...vaultParam(params) }),
23
+ }))}
24
+ empty={
25
+ q ? (
26
+ <Empty title="No notes match" hint="Try fewer words: terms are combined with AND." />
27
+ ) : (
28
+ <Empty title="No notes" hint="This vault holds no notes yet, or the vault is not readable." />
29
+ )
30
+ }
31
+ />
32
+ </>
33
+ );
34
+ }
@@ -0,0 +1,74 @@
1
+ /** Overview: the registered vaults, what the shown vault holds, and the newest log lines. */
2
+
3
+ import { Empty, List, Notice, SearchForm } from "../components.tsx";
4
+ import { list, num, rec, str, type LogRow, type VaultRow } from "../data.ts";
5
+ import type { ViewProps } from "./common.ts";
6
+ import { vaultParam } from "./common.ts";
7
+
8
+ export function OverviewView({ reply, params, navigate }: ViewProps) {
9
+ const status = rec(reply.status);
10
+ const vaults = list<VaultRow>(status.vaults);
11
+ const shown = str(reply.vault);
12
+ const mocs = list<{ path?: string; title?: string; count?: number }>(reply.mocs);
13
+ const log = list<LogRow>(reply.log);
14
+ if (!vaults.length) {
15
+ return (
16
+ <>
17
+ <SearchForm value="" onSubmit={(q) => navigate("notes", q ? { q } : {})} />
18
+ <Empty title="No vault registered" hint="Run `vmem vaults add <id> <path>` to register one, then reload this panel." />
19
+ </>
20
+ );
21
+ }
22
+ return (
23
+ <>
24
+ <SearchForm value="" onSubmit={(q) => navigate("notes", { ...(q ? { q } : {}), ...vaultParam(params) })} />
25
+ <div className="vmem-cards">
26
+ <section className="vmem-card" aria-label="Vaults">
27
+ <h2 className="vmem-card-title">Vaults</h2>
28
+ <List
29
+ label="Vaults"
30
+ items={vaults.map((vault) => ({
31
+ key: vault.id,
32
+ title: vault.id,
33
+ sub: [vault.kind, vault.write ? `write ${vault.write}` : "", vault.health && vault.health !== "ok" ? vault.health : ""]
34
+ .filter(Boolean)
35
+ .join(" · "),
36
+ ...(vault.id === shown ? { chip: { text: "shown" } } : {}),
37
+ onOpen: () => navigate("overview", { vault: vault.id }),
38
+ }))}
39
+ />
40
+ </section>
41
+ <section className="vmem-card" aria-label="Notes and maps">
42
+ <h2 className="vmem-card-title">
43
+ {num(reply.noteCount)}
44
+ {reply.noteCountCapped ? "+" : ""} notes · maps
45
+ </h2>
46
+ <List
47
+ label="Maps"
48
+ items={mocs.slice(0, 8).map((moc) => ({
49
+ key: str(moc.path),
50
+ title: str(moc.title) || str(moc.path),
51
+ sub: `${num(moc.count)} links`,
52
+ onOpen: () => navigate("note", { path: str(moc.path), ...vaultParam(params) }),
53
+ }))}
54
+ empty={<Empty title="No maps yet" hint="A map note links the notes of one area; it appears here once it exists." />}
55
+ />
56
+ </section>
57
+ <section className="vmem-card" aria-label="Recent log">
58
+ <h2 className="vmem-card-title">Recent log</h2>
59
+ <List
60
+ label="Recent log"
61
+ items={log.map((row, index) => ({
62
+ key: `${index}:${str(row.at)}:${str(row.source)}`,
63
+ title: row.raw ?? `${str(row.type)} ${str(row.source)}${row.dest ? ` → ${str(row.dest)}` : ""}`,
64
+ sub: row.raw ? undefined : [str(row.at), str(row.project), row.agent ? "agent" : ""].filter(Boolean).join(" · "),
65
+ onOpen: () => navigate("log", { ...vaultParam(params) }),
66
+ }))}
67
+ empty={<Empty title="Log is empty" />}
68
+ />
69
+ </section>
70
+ </div>
71
+ {status.error ? <Notice tone="err">{str(status.error)}</Notice> : null}
72
+ </>
73
+ );
74
+ }
@@ -0,0 +1,112 @@
1
+ /** Promote: durable agent memories offered to the vault, with the fields a promotion needs. */
2
+
3
+ import { useState } from "react";
4
+ import { Chip, Empty, Field, List, Notice } from "../components.tsx";
5
+ import { list, num, rec, str, when, type CandidateRow } from "../data.ts";
6
+ import type { ViewProps } from "./common.ts";
7
+ import { vaultParam } from "./common.ts";
8
+
9
+ export function PromoteView({ reply, params, navigate, beginWrite }: ViewProps) {
10
+ const projects = list<{ candidates?: CandidateRow[] }>(reply.projects);
11
+ const all = projects.flatMap((project) => list<CandidateRow>(project.candidates));
12
+ const selected = all.find((candidate) => candidate.id === str(reply.selected));
13
+ const [values, setValues] = useState<Record<string, string>>({});
14
+ const unavailable = str(reply.unavailable);
15
+ const page = str(reply.page);
16
+ const nextPage = str(reply.nextPage);
17
+ const pageIndex = Number((page.split(":")[1] ?? "").trim());
18
+ const showFirst = Number.isSafeInteger(pageIndex) ? pageIndex > 0 : Boolean(params.page);
19
+ const field = (name: string) => values[name] ?? "";
20
+ const set = (name: string) => (value: string) => setValues((current) => ({ ...current, [name]: value }));
21
+
22
+ return (
23
+ <>
24
+ {unavailable ? <Notice tone="err">{unavailable}</Notice> : null}
25
+ {selected ? (
26
+ <form
27
+ className="vmem-card vmem-form"
28
+ aria-label={`Promote ${str(selected.title) || str(selected.kind)}`}
29
+ onSubmit={(event) => {
30
+ event.preventDefault();
31
+ const meta = Object.fromEntries(Object.entries(values).map(([key, value]) => [key, value.trim()]).filter(([, value]) => value));
32
+ beginWrite({
33
+ action: "promote-from-amem",
34
+ id: selected.id,
35
+ ...(selected.project ? { project: selected.project } : {}),
36
+ ...meta,
37
+ ...vaultParam(params),
38
+ });
39
+ }}
40
+ >
41
+ <h2 className="vmem-card-title">Promote: {str(selected.title) || str(selected.kind) || selected.id}</h2>
42
+ <Field name="domain" label="Domain" required value={field("domain")} onChange={set("domain")} />
43
+ <Field name="topics" label="Topics, comma separated" required value={field("topics")} onChange={set("topics")} />
44
+ <Field name="type" label="Type (optional)" value={field("type")} onChange={set("type")} />
45
+ <Field name="description" label="Description (optional)" value={field("description")} onChange={set("description")} />
46
+ <Field name="stem" label="File stem (needed when the title has no ASCII letters)" value={field("stem")} onChange={set("stem")} />
47
+ <div className="vmem-bar">
48
+ <button type="submit" className="vmem-button vmem-button-primary">
49
+ Preview promotion…
50
+ </button>
51
+ <button type="button" className="vmem-button" onClick={() => navigate("promote", { ...vaultParam(params) })}>
52
+ Clear selection
53
+ </button>
54
+ </div>
55
+ </form>
56
+ ) : null}
57
+ {nextPage || showFirst ? (
58
+ <div className="vmem-bar">
59
+ {showFirst ? (
60
+ <button type="button" className="vmem-button" onClick={() => navigate("promote", { ...vaultParam(params) })}>
61
+ First page
62
+ </button>
63
+ ) : null}
64
+ {nextPage ? (
65
+ <button
66
+ type="button"
67
+ className="vmem-button"
68
+ onClick={() => navigate("promote", { page: nextPage, ...vaultParam(params) })}
69
+ >
70
+ Next page
71
+ </button>
72
+ ) : null}
73
+ </div>
74
+ ) : null}
75
+ <List
76
+ label="Promotion candidates"
77
+ items={all.map((candidate) => {
78
+ const chosen = str(reply.selected) === candidate.id;
79
+ return {
80
+ key: candidate.id,
81
+ title: str(candidate.title) || str(candidate.kind) || candidate.id,
82
+ sub: [str(candidate.kind), str(candidate.project), when(num(candidate.at) || candidate.at)].filter(Boolean).join(" · "),
83
+ ...(chosen ? { chip: { text: "selected" } } : {}),
84
+ verbs: chosen ? undefined : (
85
+ <button
86
+ type="button"
87
+ className="vmem-button"
88
+ onClick={() =>
89
+ navigate("promote", {
90
+ id: candidate.id,
91
+ ...(candidate.project ? { project: candidate.project } : {}),
92
+ ...(page ? { page } : {}),
93
+ ...vaultParam(params),
94
+ })
95
+ }
96
+ >
97
+ Select
98
+ </button>
99
+ ),
100
+ };
101
+ })}
102
+ empty={
103
+ <Empty
104
+ title="No promotion candidates"
105
+ hint="Durable agent memories appear here when agent-mem marks them for the vault."
106
+ />
107
+ }
108
+ />
109
+ {all.length ? <Chip text={`${all.length} candidates`} /> : null}
110
+ </>
111
+ );
112
+ }
@@ -0,0 +1,55 @@
1
+ /** Proposal review through the provider's snapshot and confirmation-bound actions. */
2
+ import { useState } from "react";
3
+ import { Empty, List, Notice } from "../components.tsx";
4
+ import { list, rec, str } from "../data.ts";
5
+ import type { ViewProps } from "./common.ts";
6
+
7
+ const STATES = ["pending", "applied", "rejected", "apply_unknown"] as const;
8
+
9
+ export function ProposalsView({ reply, params, navigate, beginWrite }: ViewProps) {
10
+ const [message, setMessage] = useState("");
11
+ const page = rec(reply.page), selected = rec(reply.selected);
12
+ const vault = str(reply.vault), state = str(reply.state) || "pending";
13
+ const nav = (extra: Record<string, string>) => navigate("proposals", { ...(vault ? { vault } : {}), state, ...extra });
14
+ const items = list<Record<string, unknown>>(page.items);
15
+ const id = str(selected.id), selectedState = str(selected.state);
16
+ const issues = [...list<Record<string, unknown>>(page.issues), ...list<Record<string, unknown>>(selected.issues)];
17
+ return <>
18
+ <h1>Proposals</h1>
19
+ {str(reply.error) && <Notice tone="err">{str(reply.error)}</Notice>}
20
+ {issues.map((issue, index) => <Notice key={`${str(issue.code)}:${index}`} tone="warn">{str(issue.message)}</Notice>)}
21
+ <label className="vmem-label" htmlFor="proposal-state">State</label>
22
+ <select id="proposal-state" className="vmem-input" value={state} onChange={(event) => { setMessage(""); nav({ state: event.currentTarget.value }); }}>
23
+ {STATES.map((value) => <option key={value} value={value}>{value}</option>)}
24
+ </select>
25
+ <List label="Proposals" items={items.map((item) => ({ key: str(item.id), title: str(item.path) || str(item.id), sub: [str(item.id), str(item.state), str(item.createdAt)].filter(Boolean).join(" · "), onOpen: () => { setMessage(""); nav({ ...(params.page ? { page: params.page } : {}), id: str(item.id) }); } }))} empty={<Empty title="No proposals" />} />
26
+ <div className="vmem-bar">
27
+ {params.page && <button type="button" className="vmem-button" onClick={() => nav({})}>First page</button>}
28
+ {str(page.nextCursor) && <button type="button" className="vmem-button" onClick={() => nav({ page: str(page.nextCursor) })}>Next page</button>}
29
+ </div>
30
+ {id && <section className="vmem-card" aria-label="Selected proposal">
31
+ <h2 className="vmem-card-title">Proposal {id}</h2>
32
+ <p>{str(selected.path)} · {selectedState}</p>
33
+ {selectedState === "apply_unknown" && <p>Apply outcome is unknown. Reconcile before another decision: <code>vmem proposal reconcile {vault} {id}</code>.</p>}
34
+ {str(selected.agentLabelUnverified) && <p>Agent label (unverified): {str(selected.agentLabelUnverified)}</p>}
35
+ {str(selected.decisionReason) && <p>Decision reason: {str(selected.decisionReason)}</p>}
36
+ <pre className="vmem-body">{str(selected.content)}</pre>
37
+ {selected.truncated === true && <p>Proposal content is truncated. Read the rest before deciding: <code>vmem proposal show {vault} {id}{typeof selected.nextOffset === "number" ? ` --offset ${selected.nextOffset}` : ""}</code>.</p>}
38
+ {selectedState === "pending" && <>
39
+ <button type="button" className="vmem-button" onClick={() => beginWrite({ action: "proposal-apply", vault, id })}>Preview apply</button>
40
+ <form key={`${vault}:${id}`} className="vmem-form" onSubmit={(event) => {
41
+ event.preventDefault();
42
+ const reason = String(new FormData(event.currentTarget).get("reason") ?? "");
43
+ if (!reason.trim()) { setMessage("Enter a reason before previewing rejection."); return; }
44
+ if (new TextEncoder().encode(reason).length > 4096) { setMessage("Keep the reason within 4096 bytes, then preview again."); return; }
45
+ setMessage(""); beginWrite({ action: "proposal-reject", vault, id, reason });
46
+ }}>
47
+ <label className="vmem-label" htmlFor="proposal-reason">Rejection reason</label>
48
+ <textarea id="proposal-reason" name="reason" className="vmem-input" onChange={() => setMessage("")} />
49
+ <p role="status">{message}</p>
50
+ <button type="submit" className="vmem-button">Preview rejection</button>
51
+ </form>
52
+ </>}
53
+ </section>}
54
+ </>;
55
+ }
@@ -0,0 +1,57 @@
1
+ /** Settings are read and changed only through the provider's preview and confirmation flow. */
2
+ import { Notice } from "../components.tsx";
3
+ import { list, str } from "../data.ts";
4
+ import type { ViewProps } from "./common.ts";
5
+ import { useState } from "react";
6
+
7
+ export function SettingsView({ reply, beginWrite }: ViewProps) {
8
+ const [message, setMessage] = useState("");
9
+ const error = str(reply.error);
10
+ if (error) return <Notice tone="err">{error}</Notice>;
11
+ const vault = str(reply.vault);
12
+ if (!vault) return <Notice tone="err">No vault selected. Select a vault from Overview.</Notice>;
13
+ const defaults = {
14
+ defaultVault: str(reply.defaultVault), write: str(reply.write),
15
+ piiPatterns: list<string>(reply.piiPatterns), graphResolution: Number(reply.graphResolution),
16
+ enrichmentEnabled: reply.enrichmentEnabled === true,
17
+ };
18
+ return <form key={JSON.stringify([vault, defaults])} className="vmem-card vmem-form" aria-label="Vault settings" onChange={() => setMessage("")} onSubmit={(event) => {
19
+ event.preventDefault();
20
+ const form = new FormData(event.currentTarget);
21
+ const piiText = String(form.get("piiPatterns") ?? "");
22
+ const values = {
23
+ defaultVault: String(form.get("defaultVault") ?? ""),
24
+ write: String(form.get("write") ?? ""),
25
+ graphResolution: Number(form.get("graphResolution")),
26
+ enrichmentEnabled: form.has("enrichmentEnabled"),
27
+ };
28
+ const changes: Record<string, unknown> = Object.fromEntries(Object.entries(values).filter(([key, value]) =>
29
+ JSON.stringify(value) !== JSON.stringify(defaults[key as keyof typeof defaults])));
30
+ if (piiText !== defaults.piiPatterns.join("\n")) changes.piiPatterns = piiText.split(/\r?\n/).filter((line) => line.trim() !== "");
31
+ if (!Object.keys(changes).length) { setMessage("No values changed. Edit a setting, then preview again."); return; }
32
+ setMessage("");
33
+ beginWrite({ action: "settings", vault, changes });
34
+ }}>
35
+ <h1 className="vmem-card-title">Settings</h1>
36
+ <p>Vault: {vault}. Default vault: {defaults.defaultVault || "none"}{reply.defaultVaultExplicit === false ? " (automatic)" : ""}.</p>
37
+ <fieldset className="vmem-form"><legend>This vault ({vault})</legend>
38
+ <label className="vmem-label" htmlFor="settings-write">Write permission</label>
39
+ <select className="vmem-input" id="settings-write" name="write" defaultValue={defaults.write}>
40
+ <option value="mcp">MCP</option><option value="cli">CLI</option><option value="none">None</option>
41
+ </select>
42
+ <label className="vmem-label" htmlFor="settings-resolution">Graph community resolution (greater than 0, at most 100)</label>
43
+ <input className="vmem-input" id="settings-resolution" name="graphResolution" type="number" min="5e-324" max="100" step="any" required defaultValue={defaults.graphResolution} />
44
+ <label className="vmem-check"><input name="enrichmentEnabled" type="checkbox" defaultChecked={defaults.enrichmentEnabled} /> Enable enrichment</label>
45
+ </fieldset>
46
+ <fieldset className="vmem-form"><legend>All vaults</legend>
47
+ <label className="vmem-label" htmlFor="settings-default">Default vault ID</label>
48
+ <p id="settings-default-hint" className="vmem-sub">Current default: {defaults.defaultVault || "none"}. Enter a registered vault ID.</p>
49
+ <input className="vmem-input" id="settings-default" name="defaultVault" defaultValue={defaults.defaultVault} aria-describedby="settings-default-hint" required />
50
+ <label className="vmem-label" htmlFor="settings-pii">PII patterns, one per line</label>
51
+ <textarea className="vmem-input" id="settings-pii" name="piiPatterns" defaultValue={defaults.piiPatterns.join("\n")} rows={4} />
52
+ </fieldset>
53
+ <p className="vmem-sub">Changes are previewed before confirmation. Default vault and permission changes require a console and MCP server restart.</p>
54
+ {message && <p role="status">{message}</p>}
55
+ <button type="submit" className="vmem-button vmem-button-primary">Preview changes</button>
56
+ </form>;
57
+ }