@leitwerk-dev/wiki 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +165 -2
- package/dist/LICENSE +13 -0
- package/dist/chunk-VDBICFJN.js +70 -0
- package/dist/chunk-VDBICFJN.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/instructions.d.ts +5 -0
- package/dist/instructions.d.ts.map +1 -0
- package/dist/integration.d.ts +22 -0
- package/dist/integration.d.ts.map +1 -0
- package/dist/integration.js +39 -0
- package/dist/integration.js.map +1 -0
- package/dist/model-D8KR8Be8.d.ts +50 -0
- package/dist/model.d.ts +48 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +422 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/routes.d.ts +6 -0
- package/dist/server/routes.d.ts.map +1 -0
- package/dist/server/schema.d.ts +178 -0
- package/dist/server/schema.d.ts.map +1 -0
- package/dist/server/store.d.ts +5 -0
- package/dist/server/store.d.ts.map +1 -0
- package/dist/server/test-fixture.d.ts +8 -0
- package/dist/server/test-fixture.d.ts.map +1 -0
- package/dist/server/tools.d.ts +5 -0
- package/dist/server/tools.d.ts.map +1 -0
- package/dist/store-qRZ3c4xC.d.ts +16 -0
- package/dist/store.d.ts +14 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/ui/WikiEntryEditor.svelte +156 -0
- package/dist/ui/WikiPage.svelte +334 -0
- package/dist/ui/index.d.ts +74 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +54 -0
- package/dist/ui/index.js.map +1 -0
- package/package.json +66 -5
- package/src/index.ts +3 -0
- package/src/instructions.ts +19 -0
- package/src/integration.ts +62 -0
- package/src/model.ts +96 -0
- package/src/server/index.ts +4 -0
- package/src/server/routes.ts +87 -0
- package/src/server/schema.ts +35 -0
- package/src/server/store.ts +201 -0
- package/src/server/test-fixture.ts +37 -0
- package/src/server/tools.ts +197 -0
- package/src/store.ts +30 -0
- package/src/ui/WikiEntryEditor.svelte +156 -0
- package/src/ui/WikiPage.svelte +334 -0
- package/src/ui/index.ts +132 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { tick, untrack } from "svelte";
|
|
3
|
+
import { parseWikiPageContent, type WikiPage } from "../index.js";
|
|
4
|
+
import type { WikiUiHost } from "./index.js";
|
|
5
|
+
|
|
6
|
+
let {
|
|
7
|
+
page,
|
|
8
|
+
host,
|
|
9
|
+
currentPage,
|
|
10
|
+
pages,
|
|
11
|
+
onSaved,
|
|
12
|
+
onCancel,
|
|
13
|
+
onReload,
|
|
14
|
+
}: {
|
|
15
|
+
page: WikiPage;
|
|
16
|
+
host: WikiUiHost;
|
|
17
|
+
currentPage: WikiPage | null;
|
|
18
|
+
pages: WikiPage[];
|
|
19
|
+
onSaved: (page: WikiPage) => void;
|
|
20
|
+
onCancel: () => void;
|
|
21
|
+
onReload: () => Promise<void>;
|
|
22
|
+
} = $props();
|
|
23
|
+
const initial = untrack(() => page);
|
|
24
|
+
const {
|
|
25
|
+
client: { editWikiPage },
|
|
26
|
+
renderMarkdownToHtml,
|
|
27
|
+
errorStatus,
|
|
28
|
+
} = untrack(() => host);
|
|
29
|
+
let title = $state(initial.title);
|
|
30
|
+
let markdown = $state(initial.markdown);
|
|
31
|
+
let applicability = $state(initial.applicability);
|
|
32
|
+
let status = $state(initial.status);
|
|
33
|
+
let evidence = $state(initial.evidence.map((item) => ({ ...item })));
|
|
34
|
+
let links = $state([...initial.links]);
|
|
35
|
+
let saving = $state(false);
|
|
36
|
+
let reloading = $state(false);
|
|
37
|
+
let error = $state<string | null>(null);
|
|
38
|
+
let conflict = $state(false);
|
|
39
|
+
let titleInput = $state<HTMLInputElement>();
|
|
40
|
+
let errorElement = $state<HTMLParagraphElement>();
|
|
41
|
+
const stale = $derived(!currentPage || currentPage.revision !== page.revision);
|
|
42
|
+
const missingLinks = $derived(links.filter((id) => !pages.some((entry) => entry.id === id)));
|
|
43
|
+
|
|
44
|
+
$effect(() => {
|
|
45
|
+
void tick().then(() => titleInput?.focus());
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
async function save(event: SubmitEvent) {
|
|
49
|
+
event.preventDefault();
|
|
50
|
+
if (saving || stale || conflict) return;
|
|
51
|
+
error = null;
|
|
52
|
+
try {
|
|
53
|
+
const content = parseWikiPageContent({
|
|
54
|
+
title,
|
|
55
|
+
markdown,
|
|
56
|
+
applicability,
|
|
57
|
+
status,
|
|
58
|
+
evidence,
|
|
59
|
+
links,
|
|
60
|
+
});
|
|
61
|
+
saving = true;
|
|
62
|
+
const result = await editWikiPage(page, content);
|
|
63
|
+
onSaved(result.page);
|
|
64
|
+
} catch (cause) {
|
|
65
|
+
error =
|
|
66
|
+
cause instanceof Error
|
|
67
|
+
? cause.message
|
|
68
|
+
: "Couldn't save this entry. Your draft has been kept.";
|
|
69
|
+
conflict = errorStatus(cause) === 409 || errorStatus(cause) === 404;
|
|
70
|
+
await tick();
|
|
71
|
+
errorElement?.focus();
|
|
72
|
+
} finally {
|
|
73
|
+
saving = false;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function reload() {
|
|
78
|
+
reloading = true;
|
|
79
|
+
try {
|
|
80
|
+
await onReload();
|
|
81
|
+
} finally {
|
|
82
|
+
reloading = false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
</script>
|
|
86
|
+
|
|
87
|
+
<form aria-label="Edit wiki entry" onsubmit={save}>
|
|
88
|
+
<h2>Edit entry</h2>
|
|
89
|
+
<p class="hint">Keep only reusable solutions that add knowledge beyond the current ticket and shared source requirement. Explain when another process can apply the solution, why it works, and its limitations.</p>
|
|
90
|
+
<p class="metadata">Editing revision {page.revision}. Saving creates a new revision.</p>
|
|
91
|
+
{#if stale || conflict}
|
|
92
|
+
<div class="notice" role="alert">
|
|
93
|
+
<p>This entry changed or was deleted while you were editing. Your draft has been kept. Reloading replaces it with the latest entry.</p>
|
|
94
|
+
<button type="button" class="ui-button" disabled={reloading} onclick={() => void reload()}>{reloading ? "Reloading…" : "Reload latest entry"}</button>
|
|
95
|
+
</div>
|
|
96
|
+
{/if}
|
|
97
|
+
{#if error}<p role="alert" tabindex="-1" bind:this={errorElement}>{error}</p>{/if}
|
|
98
|
+
<fieldset disabled={saving || reloading}>
|
|
99
|
+
<label for="wiki-edit-title">Title</label>
|
|
100
|
+
<input id="wiki-edit-title" bind:this={titleInput} bind:value={title} required />
|
|
101
|
+
<label for="wiki-edit-applicability">Applies when</label>
|
|
102
|
+
<textarea id="wiki-edit-applicability" bind:value={applicability} rows="3" required></textarea>
|
|
103
|
+
<label for="wiki-edit-markdown">Entry text (Markdown)</label>
|
|
104
|
+
<textarea id="wiki-edit-markdown" bind:value={markdown} rows="12" required></textarea>
|
|
105
|
+
<details><summary>Preview entry text</summary><div class="markdown">{@html renderMarkdownToHtml(markdown)}</div></details>
|
|
106
|
+
<label for="wiki-edit-status">Evidence status</label>
|
|
107
|
+
<select id="wiki-edit-status" bind:value={status}><option value="proposed">Proposed</option><option value="observed">Observed</option><option value="validated">Validated against cited evidence</option><option value="needs_revalidation">Needs revalidation</option></select>
|
|
108
|
+
<h3>Evidence</h3>
|
|
109
|
+
<p class="hint">Keep at least one observation and the commit inspected. Mark guidance that still needs checking as Needs revalidation.</p>
|
|
110
|
+
{#each evidence as item, index}
|
|
111
|
+
<section class="evidence-row" aria-label={`Evidence ${index + 1}`}>
|
|
112
|
+
<div class="evidence-fields">
|
|
113
|
+
<div><label for={`wiki-evidence-repository-${index}`}>Repository</label><input id={`wiki-evidence-repository-${index}`} bind:value={item.repository} required /></div>
|
|
114
|
+
<div><label for={`wiki-evidence-path-${index}`}>Path</label><input id={`wiki-evidence-path-${index}`} bind:value={item.path} required /></div>
|
|
115
|
+
</div>
|
|
116
|
+
<label for={`wiki-evidence-revision-${index}`}>Commit SHA</label><input id={`wiki-evidence-revision-${index}`} bind:value={item.revision} pattern={"([a-fA-F0-9]{40}|[a-fA-F0-9]{64})"} title="40 or 64 hexadecimal characters" required />
|
|
117
|
+
<label for={`wiki-evidence-observation-${index}`}>Observation</label><textarea id={`wiki-evidence-observation-${index}`} bind:value={item.observation} rows="3" required></textarea>
|
|
118
|
+
<button type="button" class="ui-button" aria-label={`Remove evidence ${index + 1}`} onclick={() => evidence = evidence.filter((_, i) => i !== index)}>Remove evidence</button>
|
|
119
|
+
</section>
|
|
120
|
+
{/each}
|
|
121
|
+
<button type="button" class="ui-button" onclick={() => evidence = [...evidence, { repository: "", path: "", revision: "", observation: "" }]}>Add evidence</button>
|
|
122
|
+
<h3>Related entries</h3>
|
|
123
|
+
{#each pages.filter((entry) => entry.id !== page.id) as related (related.id)}
|
|
124
|
+
<label class="related"><input type="checkbox" value={related.id} bind:group={links} />{related.title}</label>
|
|
125
|
+
{/each}
|
|
126
|
+
{#each missingLinks as id (id)}<label class="related"><input type="checkbox" value={id} bind:group={links} />{id} (entry unavailable; uncheck to remove)</label>{/each}
|
|
127
|
+
{#if pages.length <= 1 && !missingLinks.length}<p class="hint">No other entries in this wiki group.</p>{/if}
|
|
128
|
+
</fieldset>
|
|
129
|
+
<div class="actions">
|
|
130
|
+
<button class="ui-button" data-variant="primary" type="submit" disabled={saving || reloading || stale || conflict}>{saving ? "Saving…" : "Save changes"}</button>
|
|
131
|
+
<button class="ui-button" type="button" disabled={saving || reloading} onclick={onCancel}>Cancel editing</button>
|
|
132
|
+
</div>
|
|
133
|
+
</form>
|
|
134
|
+
|
|
135
|
+
<style>
|
|
136
|
+
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
|
|
137
|
+
h2 { margin-top: 0; font-size: 1.5rem; }
|
|
138
|
+
h3 { margin-top: var(--space-xl); }
|
|
139
|
+
label { display: block; font-weight: 600; margin: var(--space-md) 0 var(--space-xs); }
|
|
140
|
+
input, select, textarea { box-sizing: border-box; width: 100%; min-height: 44px; padding: var(--space-sm); border: 1px solid var(--chronicle-border-strong); border-radius: var(--radius-sm); background: var(--chronicle-panel-surface); color: var(--chronicle-text); font: inherit; caret-color: var(--chronicle-accent); }
|
|
141
|
+
textarea { resize: vertical; line-height: 1.6; }
|
|
142
|
+
input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 2px solid var(--chronicle-accent); outline-offset: 3px; }
|
|
143
|
+
.metadata, .hint { color: var(--chronicle-text-muted); line-height: 1.6; }
|
|
144
|
+
.metadata { font-size: 0.875rem; }
|
|
145
|
+
.notice { background: var(--chronicle-panel-muted); padding: var(--space-md); border-radius: var(--radius-sm); }
|
|
146
|
+
.evidence-row { padding-bottom: var(--space-md); margin-bottom: var(--space-md); border-bottom: 1px solid var(--chronicle-border); }
|
|
147
|
+
.evidence-row button { margin-top: var(--space-sm); }
|
|
148
|
+
.evidence-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-md); }
|
|
149
|
+
.related { display: flex; gap: var(--space-sm); align-items: center; min-height: 44px; font-weight: 400; }
|
|
150
|
+
.related input { width: 20px; min-height: 20px; flex: 0 0 20px; accent-color: var(--chronicle-accent); }
|
|
151
|
+
.actions { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin-top: var(--space-xl); }
|
|
152
|
+
details { margin-top: var(--space-sm); }
|
|
153
|
+
summary { cursor: pointer; padding: var(--space-sm) 0; min-height: 44px; box-sizing: border-box; }
|
|
154
|
+
.markdown { overflow-wrap: anywhere; }
|
|
155
|
+
@media (max-width: 760px) { .evidence-fields { grid-template-columns: minmax(0, 1fr); gap: 0; } }
|
|
156
|
+
</style>
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, tick, untrack } from "svelte";
|
|
3
|
+
import type { WikiPage, WikiTopic } from "../index.js";
|
|
4
|
+
import type { WikiUiHost } from "./index.js";
|
|
5
|
+
import WikiEntryEditor from "./WikiEntryEditor.svelte";
|
|
6
|
+
|
|
7
|
+
let {
|
|
8
|
+
topicId = "",
|
|
9
|
+
pageId = "",
|
|
10
|
+
reconnectCount = 0,
|
|
11
|
+
host,
|
|
12
|
+
}: { topicId?: string; pageId?: string; reconnectCount?: number; host: WikiUiHost } = $props();
|
|
13
|
+
const {
|
|
14
|
+
client,
|
|
15
|
+
renderMarkdownToHtml,
|
|
16
|
+
followLink,
|
|
17
|
+
navigate,
|
|
18
|
+
errorStatus,
|
|
19
|
+
onWikiUpdated,
|
|
20
|
+
PageHeader,
|
|
21
|
+
ExternalLink,
|
|
22
|
+
} = untrack(() => host);
|
|
23
|
+
const { deleteWikiGroup, deleteWikiPage, fetchWikiHistory, fetchWikiTopic, fetchWikiTopics } =
|
|
24
|
+
client;
|
|
25
|
+
let topics = $state<WikiTopic[]>([]);
|
|
26
|
+
let topic = $state<WikiTopic | null>(null);
|
|
27
|
+
let pages = $state<WikiPage[]>([]);
|
|
28
|
+
let history = $state<WikiPage[]>([]);
|
|
29
|
+
let historyLoading = $state(false);
|
|
30
|
+
let historyError = $state<string | null>(null);
|
|
31
|
+
let deleteError = $state<string | null>(null);
|
|
32
|
+
let deleteConflict = $state(false);
|
|
33
|
+
let indexLoaded = $state(false);
|
|
34
|
+
let search = $state("");
|
|
35
|
+
let status = $state("all");
|
|
36
|
+
let loading = $state(false);
|
|
37
|
+
let error = $state<string | null>(null);
|
|
38
|
+
let deleting = $state(false);
|
|
39
|
+
let confirmation = $state<WikiPage | null>(null);
|
|
40
|
+
let editing = $state<WikiPage | null>(null);
|
|
41
|
+
let editMessage = $state<string | null>(null);
|
|
42
|
+
let groupConfirmation = $state<WikiTopic | null>(null);
|
|
43
|
+
let deletingGroup = $state(false);
|
|
44
|
+
let groupDeleteError = $state<string | null>(null);
|
|
45
|
+
let groupDeleteConflict = $state(false);
|
|
46
|
+
let groupConfirmationHeading = $state<HTMLHeadingElement>();
|
|
47
|
+
let groupDeletionTrigger: HTMLButtonElement | undefined;
|
|
48
|
+
let editButton = $state<HTMLButtonElement>();
|
|
49
|
+
let generation = 0;
|
|
50
|
+
let historyGeneration = 0;
|
|
51
|
+
const selected = $derived(pages.find((page) => page.id === pageId) ?? null);
|
|
52
|
+
const filtered = $derived(
|
|
53
|
+
pages.filter(
|
|
54
|
+
(page) =>
|
|
55
|
+
(status === "all" || page.status === status) &&
|
|
56
|
+
`${page.title} ${page.applicability} ${page.markdown}`
|
|
57
|
+
.toLowerCase()
|
|
58
|
+
.includes(search.toLowerCase()),
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
const pagePath = (id: string) => `/wiki/${encodeURIComponent(topicId)}/${encodeURIComponent(id)}`;
|
|
62
|
+
const statusLabel = (value: WikiPage["status"]) =>
|
|
63
|
+
({
|
|
64
|
+
proposed: "Proposed",
|
|
65
|
+
observed: "Observed",
|
|
66
|
+
validated: "Validated against cited evidence",
|
|
67
|
+
needs_revalidation: "Needs revalidation",
|
|
68
|
+
})[value];
|
|
69
|
+
|
|
70
|
+
function resetEntry() {
|
|
71
|
+
historyGeneration++;
|
|
72
|
+
history = [];
|
|
73
|
+
historyLoading = false;
|
|
74
|
+
historyError = null;
|
|
75
|
+
deleteError = null;
|
|
76
|
+
deleteConflict = false;
|
|
77
|
+
confirmation = null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async function load() {
|
|
81
|
+
const request = ++generation;
|
|
82
|
+
const requestedTopic = topicId;
|
|
83
|
+
loading = true;
|
|
84
|
+
error = null;
|
|
85
|
+
try {
|
|
86
|
+
if (requestedTopic) {
|
|
87
|
+
const result = await fetchWikiTopic(requestedTopic);
|
|
88
|
+
if (request !== generation) return;
|
|
89
|
+
topic = result.topic;
|
|
90
|
+
pages = result.pages;
|
|
91
|
+
resetEntry();
|
|
92
|
+
} else {
|
|
93
|
+
const result = await fetchWikiTopics();
|
|
94
|
+
if (request !== generation) return;
|
|
95
|
+
topics = result.topics;
|
|
96
|
+
indexLoaded = true;
|
|
97
|
+
topic = null;
|
|
98
|
+
pages = [];
|
|
99
|
+
}
|
|
100
|
+
} catch (cause) {
|
|
101
|
+
if (request === generation) {
|
|
102
|
+
error = cause instanceof Error ? cause.message : "Wiki unavailable";
|
|
103
|
+
if (errorStatus(cause) === 404) {
|
|
104
|
+
topic = null;
|
|
105
|
+
pages = [];
|
|
106
|
+
resetEntry();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
} finally {
|
|
110
|
+
if (request === generation) loading = false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function loadHistory() {
|
|
115
|
+
if (historyLoading) return;
|
|
116
|
+
const requestedTopic = topicId,
|
|
117
|
+
requestedPage = pageId;
|
|
118
|
+
const request = ++historyGeneration;
|
|
119
|
+
historyLoading = true;
|
|
120
|
+
historyError = null;
|
|
121
|
+
try {
|
|
122
|
+
const result = await fetchWikiHistory(requestedTopic, requestedPage);
|
|
123
|
+
if (request === historyGeneration && requestedTopic === topicId && requestedPage === pageId)
|
|
124
|
+
history = result.revisions;
|
|
125
|
+
} catch (cause) {
|
|
126
|
+
if (request === historyGeneration && requestedTopic === topicId && requestedPage === pageId)
|
|
127
|
+
historyError = cause instanceof Error ? cause.message : "History unavailable";
|
|
128
|
+
} finally {
|
|
129
|
+
if (request === historyGeneration) historyLoading = false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async function removeEntry() {
|
|
134
|
+
if (!confirmation) return;
|
|
135
|
+
const target = confirmation;
|
|
136
|
+
deleting = true;
|
|
137
|
+
deleteError = null;
|
|
138
|
+
deleteConflict = false;
|
|
139
|
+
try {
|
|
140
|
+
await deleteWikiPage(target);
|
|
141
|
+
confirmation = null;
|
|
142
|
+
if (target.topicId === topicId) {
|
|
143
|
+
navigate(`/wiki/${topicId}`);
|
|
144
|
+
await load();
|
|
145
|
+
}
|
|
146
|
+
} catch (cause) {
|
|
147
|
+
if (target.topicId === topicId && target.id === pageId) {
|
|
148
|
+
deleteError = cause instanceof Error ? cause.message : "Deletion failed";
|
|
149
|
+
deleteConflict = errorStatus(cause) === 409;
|
|
150
|
+
}
|
|
151
|
+
} finally {
|
|
152
|
+
deleting = false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async function confirmGroupDeletion(target: WikiTopic, trigger: HTMLButtonElement) {
|
|
157
|
+
groupDeletionTrigger = trigger;
|
|
158
|
+
groupConfirmation = target;
|
|
159
|
+
groupDeleteError = null;
|
|
160
|
+
groupDeleteConflict = false;
|
|
161
|
+
await tick();
|
|
162
|
+
if (groupConfirmation?.id !== target.id) return;
|
|
163
|
+
groupConfirmationHeading?.focus();
|
|
164
|
+
groupConfirmationHeading?.scrollIntoView?.({ block: "nearest" });
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async function cancelGroupDeletion() {
|
|
168
|
+
groupConfirmation = null;
|
|
169
|
+
await tick();
|
|
170
|
+
groupDeletionTrigger?.focus();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function removeGroup() {
|
|
174
|
+
if (!groupConfirmation || deletingGroup) return;
|
|
175
|
+
const target = groupConfirmation;
|
|
176
|
+
deletingGroup = true;
|
|
177
|
+
groupDeleteError = null;
|
|
178
|
+
try {
|
|
179
|
+
await deleteWikiGroup(target);
|
|
180
|
+
groupConfirmation = null;
|
|
181
|
+
topics = topics.filter((item) => item.id !== target.id);
|
|
182
|
+
if (target.id === topicId) {
|
|
183
|
+
topic = null;
|
|
184
|
+
pages = [];
|
|
185
|
+
editing = null;
|
|
186
|
+
navigate("/wiki");
|
|
187
|
+
} else await load();
|
|
188
|
+
} catch (cause) {
|
|
189
|
+
groupDeleteError = cause instanceof Error ? cause.message : "Group deletion failed";
|
|
190
|
+
groupDeleteConflict = errorStatus(cause) === 409;
|
|
191
|
+
} finally {
|
|
192
|
+
deletingGroup = false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function refreshGroupDeletion() {
|
|
197
|
+
await load();
|
|
198
|
+
groupConfirmation = null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
async function reloadEditedEntry() {
|
|
202
|
+
const requestedTopic = topicId,
|
|
203
|
+
requestedPage = pageId;
|
|
204
|
+
await load();
|
|
205
|
+
if (requestedTopic === topicId && requestedPage === pageId && selected) editing = selected;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function savedEntry(page: WikiPage) {
|
|
209
|
+
if (editing?.topicId !== page.topicId || editing.id !== page.id) return;
|
|
210
|
+
pages = pages.map((current) => (current.id === page.id ? page : current));
|
|
211
|
+
finishEditing();
|
|
212
|
+
editMessage = "Entry saved.";
|
|
213
|
+
resetEntry();
|
|
214
|
+
void load();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function finishEditing() {
|
|
218
|
+
editing = null;
|
|
219
|
+
void tick().then(() => editButton?.focus());
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
$effect(() => {
|
|
223
|
+
void topicId;
|
|
224
|
+
void reconnectCount;
|
|
225
|
+
pages = [];
|
|
226
|
+
topic = null;
|
|
227
|
+
void load();
|
|
228
|
+
});
|
|
229
|
+
$effect(() => {
|
|
230
|
+
void pageId;
|
|
231
|
+
void topicId;
|
|
232
|
+
resetEntry();
|
|
233
|
+
editing = null;
|
|
234
|
+
editMessage = null;
|
|
235
|
+
groupConfirmation = null;
|
|
236
|
+
});
|
|
237
|
+
onMount(() =>
|
|
238
|
+
onWikiUpdated((updatedTopicId) => {
|
|
239
|
+
if (!topicId || updatedTopicId === topicId) void load();
|
|
240
|
+
}),
|
|
241
|
+
);
|
|
242
|
+
</script>
|
|
243
|
+
|
|
244
|
+
<div class="wiki-page" data-page="wiki">
|
|
245
|
+
<PageHeader title={topic?.title ?? "Solution wikis"} subtitle="Reusable solutions for other processes in this topic, beyond what the tickets already describe. Check the cited evidence before applying guidance.">
|
|
246
|
+
{#snippet actions()}<button class="ui-button" disabled={loading} onclick={() => void load()}>{loading ? "Refreshing…" : "Refresh"}</button>{#if topic}<button class="ui-button" disabled={loading || deletingGroup || !!editing} onclick={(event) => topic && void confirmGroupDeletion(topic, event.currentTarget)}>Delete wiki group…</button>{/if}{/snippet}
|
|
247
|
+
</PageHeader>
|
|
248
|
+
{#if error}<p role="alert">{error} <button class="ui-button" onclick={() => void load()}>Try again</button></p>{/if}
|
|
249
|
+
{#if loading && !topic && !topics.length}<p role="status">Loading solution wiki…</p>{/if}
|
|
250
|
+
{#if groupConfirmation}
|
|
251
|
+
<section class="confirmation group-confirmation" aria-label="Confirm wiki group deletion">
|
|
252
|
+
<h2 bind:this={groupConfirmationHeading} tabindex="-1">Delete “{groupConfirmation.title}” and all its entries?</h2>
|
|
253
|
+
<p>This removes the entire wiki group from browsing and future agent reads. It cannot be restored or erase context already read by a running agent. Processes and published tickets remain available.</p>
|
|
254
|
+
{#if groupDeleteError}<p role="alert">{groupDeleteError}</p>{/if}
|
|
255
|
+
<div class="entry-actions">
|
|
256
|
+
{#if groupDeleteConflict}<button class="ui-button" disabled={loading} onclick={() => void refreshGroupDeletion()}>Refresh group before deleting</button>
|
|
257
|
+
{:else}<button class="ui-button" data-variant="danger" disabled={deletingGroup} onclick={() => void removeGroup()}>{deletingGroup ? "Deleting group…" : groupDeleteError ? "Retry group deletion" : "Delete group and all entries"}</button>{/if}
|
|
258
|
+
<button class="ui-button" disabled={deletingGroup} onclick={() => void cancelGroupDeletion()}>Cancel</button>
|
|
259
|
+
</div>
|
|
260
|
+
</section>
|
|
261
|
+
{/if}
|
|
262
|
+
{#if !topicId}
|
|
263
|
+
{#if indexLoaded && !loading && !error && !topics.length}<p>No solution wikis yet. Start a process that shares solutions with a topic.</p>{/if}
|
|
264
|
+
<ul class="topic-list">{#each topics as item (item.id)}
|
|
265
|
+
<li><a href={`/wiki/${item.id}`} onclick={(event) => followLink(event, `/wiki/${item.id}`)}>{item.title}</a><button class="ui-button" aria-label={`Delete wiki group ${item.title}`} disabled={loading || deletingGroup} onclick={(event) => void confirmGroupDeletion(item, event.currentTarget)}>Delete group…</button></li>
|
|
266
|
+
{/each}</ul>
|
|
267
|
+
{:else if topic || editing}
|
|
268
|
+
<nav class="breadcrumbs" aria-label="Wiki navigation"><a href="/wiki" onclick={(event) => followLink(event, "/wiki")}>All solution wikis</a>{#if topic}<ExternalLink href={topic.url} label="Open topic source" />{/if}</nav>
|
|
269
|
+
<div class="wiki-layout">
|
|
270
|
+
<aside aria-label="Wiki entries">
|
|
271
|
+
<label for="wiki-search">Find an entry</label><input id="wiki-search" type="search" bind:value={search} placeholder="Search solutions" />
|
|
272
|
+
<label for="wiki-status">Evidence status</label><select id="wiki-status" bind:value={status}><option value="all">All entries</option><option value="needs_revalidation">Needs revalidation</option><option value="proposed">Proposed</option><option value="observed">Observed</option><option value="validated">Validated</option></select>
|
|
273
|
+
<ul>{#each filtered as page (page.id)}<li><a class:selected={page.id === pageId} aria-current={page.id === pageId ? "page" : undefined} href={pagePath(page.id)} onclick={(event) => followLink(event, pagePath(page.id))}>{page.title}<span>{statusLabel(page.status)}</span></a></li>{/each}</ul>
|
|
274
|
+
{#if !filtered.length}<p>{pages.length ? "No entries match these filters." : "No shared solutions yet."}</p>{/if}
|
|
275
|
+
</aside>
|
|
276
|
+
<article>
|
|
277
|
+
{#if editing}
|
|
278
|
+
{#key `${editing.topicId}:${editing.id}:${editing.revision}`}
|
|
279
|
+
<WikiEntryEditor {host} page={editing} currentPage={selected} {pages} onSaved={savedEntry} onCancel={finishEditing} onReload={reloadEditedEntry} />
|
|
280
|
+
{/key}
|
|
281
|
+
{:else if selected}
|
|
282
|
+
{#if editMessage}<p role="status">{editMessage}</p>{/if}
|
|
283
|
+
<h2>{selected.title}</h2><p class="metadata">{statusLabel(selected.status)} · Revision {selected.revision} · {new Date(selected.updatedAt).toLocaleString()}</p>
|
|
284
|
+
{#if selected.status === "needs_revalidation"}<p class="notice">Evidence or a linked entry changed. Revalidate this guidance before reuse.</p>{/if}
|
|
285
|
+
<h3>Applies when</h3><p>{selected.applicability}</p>
|
|
286
|
+
<div class="markdown">{@html renderMarkdownToHtml(selected.markdown)}</div>
|
|
287
|
+
<h3>Evidence</h3><ul class="evidence">{#each selected.evidence as evidence}<li><strong>{evidence.repository}</strong><p>{evidence.path} · <code>{evidence.revision}</code></p><p>{evidence.observation}</p></li>{/each}</ul>
|
|
288
|
+
<p><a href={`/processes/${selected.instanceId}`} onclick={(event) => followLink(event, `/processes/${selected.instanceId}`)}>Contributing process</a> · Source turn: {selected.turnRecordId}</p>
|
|
289
|
+
{#if selected.updatedBy}<p class="metadata">Edited by {selected.updatedBy.displayName ?? selected.updatedBy.id}</p>{/if}
|
|
290
|
+
{#if selected.links.length}<h3>Related entries</h3><ul>{#each selected.links as link}<li>{#if pages.some((page) => page.id === link)}<a href={pagePath(link)} onclick={(event) => followLink(event, pagePath(link))}>{pages.find((page) => page.id === link)?.title}</a>{:else}Entry removed; dependent guidance needs review.{/if}</li>{/each}</ul>{/if}
|
|
291
|
+
<div class="entry-actions"><button class="ui-button" bind:this={editButton} disabled={deleting || !!confirmation} onclick={() => { editing = selected; editMessage = null; }}>Edit entry</button><button class="ui-button" disabled={historyLoading} onclick={() => void loadHistory()}>{historyLoading ? "Loading history…" : "Show revision history"}</button><button class="ui-button" disabled={deleting} onclick={() => { deleteError = null; confirmation = selected; }}>Delete entry…</button></div>
|
|
292
|
+
{#if historyError}<p role="alert">{historyError} <button class="ui-button" disabled={historyLoading} onclick={() => void loadHistory()}>Retry history</button></p>{/if}
|
|
293
|
+
{#if confirmation}<section class="confirmation" aria-label="Confirm entry deletion"><h3>Delete “{confirmation.title}”?</h3><p>This removes the entry from browsing and future agent reads. It cannot erase context already read by a running agent.</p>{#if deleteError}<p role="alert">{deleteError}</p>{/if}{#if deleteConflict}<button class="ui-button" disabled={loading} onclick={() => void load()}>Refresh entry before deleting</button>{:else}<button class="ui-button" disabled={deleting} onclick={() => void removeEntry()}>{deleting ? "Deleting…" : deleteError ? "Retry deletion" : "Delete entry"}</button>{/if}<button class="ui-button" disabled={deleting} onclick={() => confirmation = null}>Cancel</button></section>{/if}
|
|
294
|
+
{#if history.length}<h3>Revision history</h3>{#each history as revision (revision.revision)}<details><summary>Revision {revision.revision} · {new Date(revision.updatedAt).toLocaleString()}</summary><div class="markdown">{@html renderMarkdownToHtml(revision.markdown)}</div></details>{/each}{/if}
|
|
295
|
+
{:else}<h2>{pageId ? "Entry unavailable" : "Shared solutions"}</h2><p>{pageId ? "This entry may have been deleted. Choose another entry from the index." : "Select an entry to read its solution, applicability, and supporting evidence."}</p>{/if}
|
|
296
|
+
</article>
|
|
297
|
+
</div>
|
|
298
|
+
{/if}
|
|
299
|
+
</div>
|
|
300
|
+
|
|
301
|
+
<style>
|
|
302
|
+
.wiki-page { width: 100%; max-width: 1200px; margin: 0 auto; padding: var(--space-xl); color: var(--chronicle-text); box-sizing: border-box; }
|
|
303
|
+
.breadcrumbs, .entry-actions { display: flex; flex-wrap: wrap; gap: var(--space-md); margin: var(--space-lg) 0; }
|
|
304
|
+
.wiki-layout { display: grid; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); gap: var(--space-2xl); }
|
|
305
|
+
aside { min-width: 0; }
|
|
306
|
+
label { display: block; font-weight: 600; margin: var(--space-md) 0 var(--space-xs); }
|
|
307
|
+
input, select { box-sizing: border-box; width: 100%; min-height: 44px; padding: var(--space-sm); border: 1px solid var(--chronicle-border-strong); border-radius: var(--radius-sm); background: var(--chronicle-panel-surface); color: var(--chronicle-text); font: inherit; }
|
|
308
|
+
aside ul, .topic-list { list-style: none; padding: 0; }
|
|
309
|
+
aside li, .topic-list li { border-bottom: 1px solid var(--chronicle-border); }
|
|
310
|
+
.topic-list li { display: flex; align-items: center; gap: var(--space-md); padding: var(--space-sm) 0; }
|
|
311
|
+
.topic-list a { flex: 1; min-width: 0; }
|
|
312
|
+
.topic-list button { flex-shrink: 0; }
|
|
313
|
+
.group-confirmation { margin: var(--space-lg) 0; }
|
|
314
|
+
aside a, .topic-list a { display: block; padding: var(--space-md) var(--space-xs); overflow-wrap: anywhere; }
|
|
315
|
+
aside a.selected { background: var(--chronicle-accent-soft); }
|
|
316
|
+
aside span { display: block; color: var(--chronicle-text-muted); font-size: 0.875rem; margin-top: var(--space-xs); }
|
|
317
|
+
article { min-width: 0; max-width: 75ch; overflow-wrap: anywhere; }
|
|
318
|
+
h2 { font-size: 1.5rem; margin-top: 0; }
|
|
319
|
+
h3 { margin-top: var(--space-xl); }
|
|
320
|
+
p, .markdown { line-height: 1.65; }
|
|
321
|
+
.metadata { color: var(--chronicle-text-muted); font-size: 0.875rem; }
|
|
322
|
+
.notice, .confirmation { background: var(--chronicle-panel-muted); padding: var(--space-md); border-radius: var(--radius-sm); }
|
|
323
|
+
.evidence { padding-left: var(--space-lg); }
|
|
324
|
+
.evidence p { margin: var(--space-xs) 0; }
|
|
325
|
+
.confirmation button { margin-right: var(--space-xs); }
|
|
326
|
+
details { border-bottom: 1px solid var(--chronicle-border); padding: var(--space-sm) 0; }
|
|
327
|
+
summary { cursor: pointer; min-height: 44px; }
|
|
328
|
+
:global(.wiki-page pre) { max-width: 100%; overflow-x: auto; padding: var(--space-sm); background: var(--chronicle-panel-muted); }
|
|
329
|
+
a { color: var(--chronicle-link); text-underline-offset: 0.2em; }
|
|
330
|
+
aside a:hover, .topic-list a:hover { background: var(--chronicle-panel-muted); }
|
|
331
|
+
input::placeholder { color: var(--chronicle-text-muted); }
|
|
332
|
+
:global(.wiki-page a:focus-visible), input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--chronicle-accent); outline-offset: 3px; }
|
|
333
|
+
@media (max-width: 760px) { .wiki-page { padding: var(--space-md); } .wiki-layout { grid-template-columns: minmax(0, 1fr); gap: var(--space-xl); } }
|
|
334
|
+
</style>
|
package/src/ui/index.ts
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { Component, Snippet } from "svelte";
|
|
2
|
+
import type { WikiPage, WikiPageContent, WikiTopic } from "../model.js";
|
|
3
|
+
|
|
4
|
+
/** Authenticated JSON transport supplied by the application. @internal */
|
|
5
|
+
export type WikiRequest = <T extends object>(input: {
|
|
6
|
+
/** @internal */ path: string;
|
|
7
|
+
/** @internal */ init?: RequestInit;
|
|
8
|
+
/** @internal */ malformed: string;
|
|
9
|
+
/** @internal */ error: string;
|
|
10
|
+
}) => Promise<T>;
|
|
11
|
+
|
|
12
|
+
/** @internal */
|
|
13
|
+
export interface WikiTopicsSnapshot {
|
|
14
|
+
/** @internal */
|
|
15
|
+
topics: WikiTopic[];
|
|
16
|
+
}
|
|
17
|
+
/** @internal */
|
|
18
|
+
export interface WikiTopicSnapshot {
|
|
19
|
+
/** @internal */
|
|
20
|
+
topic: WikiTopic;
|
|
21
|
+
/** @internal */
|
|
22
|
+
pages: WikiPage[];
|
|
23
|
+
}
|
|
24
|
+
/** @internal */
|
|
25
|
+
export interface WikiHistorySnapshot {
|
|
26
|
+
/** @internal */
|
|
27
|
+
revisions: WikiPage[];
|
|
28
|
+
}
|
|
29
|
+
/** @internal */
|
|
30
|
+
export interface WikiSavedPage {
|
|
31
|
+
/** @internal */
|
|
32
|
+
page: WikiPage;
|
|
33
|
+
}
|
|
34
|
+
/** @internal */
|
|
35
|
+
export interface WikiDeleted {
|
|
36
|
+
/** @internal */
|
|
37
|
+
deleted: boolean;
|
|
38
|
+
}
|
|
39
|
+
/** @internal */
|
|
40
|
+
export interface WikiClient {
|
|
41
|
+
/** @internal */
|
|
42
|
+
fetchWikiTopics(): Promise<WikiTopicsSnapshot>;
|
|
43
|
+
/** @internal */
|
|
44
|
+
fetchWikiTopic(topicId: string): Promise<WikiTopicSnapshot>;
|
|
45
|
+
/** @internal */
|
|
46
|
+
fetchWikiHistory(topicId: string, pageId: string): Promise<WikiHistorySnapshot>;
|
|
47
|
+
/** @internal */
|
|
48
|
+
deleteWikiPage(page: WikiPage): Promise<WikiDeleted>;
|
|
49
|
+
/** @internal */
|
|
50
|
+
editWikiPage(page: WikiPage, content: WikiPageContent): Promise<WikiSavedPage>;
|
|
51
|
+
/** @internal */
|
|
52
|
+
deleteWikiGroup(topic: WikiTopic): Promise<WikiDeleted>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** @internal */
|
|
56
|
+
export function createWikiClient(request: WikiRequest): WikiClient {
|
|
57
|
+
const topicPath = (id: string) => `/api/wiki/topics/${encodeURIComponent(id)}`;
|
|
58
|
+
const pagePath = (topicId: string, pageId: string) =>
|
|
59
|
+
`${topicPath(topicId)}/pages/${encodeURIComponent(pageId)}`;
|
|
60
|
+
return {
|
|
61
|
+
/** @internal */
|
|
62
|
+
fetchWikiTopics: () =>
|
|
63
|
+
request<WikiTopicsSnapshot>({
|
|
64
|
+
path: "/api/wiki/topics",
|
|
65
|
+
malformed: "Malformed wiki index",
|
|
66
|
+
error: "Couldn't load solution wikis",
|
|
67
|
+
}),
|
|
68
|
+
/** @internal */
|
|
69
|
+
fetchWikiTopic: (topicId: string) =>
|
|
70
|
+
request<WikiTopicSnapshot>({
|
|
71
|
+
path: topicPath(topicId),
|
|
72
|
+
malformed: "Malformed wiki",
|
|
73
|
+
error: "Couldn't load this wiki",
|
|
74
|
+
}),
|
|
75
|
+
/** @internal */
|
|
76
|
+
fetchWikiHistory: (topicId: string, pageId: string) =>
|
|
77
|
+
request<WikiHistorySnapshot>({
|
|
78
|
+
path: `${pagePath(topicId, pageId)}/history`,
|
|
79
|
+
malformed: "Malformed revision history",
|
|
80
|
+
error: "Couldn't load entry history",
|
|
81
|
+
}),
|
|
82
|
+
/** @internal */
|
|
83
|
+
deleteWikiPage: (page: WikiPage) =>
|
|
84
|
+
request<WikiDeleted>({
|
|
85
|
+
path: `${pagePath(page.topicId, page.id)}?revision=${page.revision}`,
|
|
86
|
+
init: { method: "DELETE" },
|
|
87
|
+
malformed: "Malformed deletion response",
|
|
88
|
+
error: "Couldn't delete this entry; refresh and try again",
|
|
89
|
+
}),
|
|
90
|
+
/** @internal */
|
|
91
|
+
editWikiPage: (page: WikiPage, content: WikiPageContent) =>
|
|
92
|
+
request<WikiSavedPage>({
|
|
93
|
+
path: pagePath(page.topicId, page.id),
|
|
94
|
+
init: {
|
|
95
|
+
method: "PUT",
|
|
96
|
+
headers: { "content-type": "application/json" },
|
|
97
|
+
body: JSON.stringify({ ...content, expectedRevision: page.revision }),
|
|
98
|
+
},
|
|
99
|
+
malformed: "Malformed edit response",
|
|
100
|
+
error: "Couldn't save this entry. Your draft has been kept.",
|
|
101
|
+
}),
|
|
102
|
+
/** @internal */
|
|
103
|
+
deleteWikiGroup: (topic: WikiTopic) =>
|
|
104
|
+
request<WikiDeleted>({
|
|
105
|
+
path: `${topicPath(topic.id)}?revision=${topic.revision ?? 1}`,
|
|
106
|
+
init: { method: "DELETE" },
|
|
107
|
+
malformed: "Malformed group deletion response",
|
|
108
|
+
error: "Couldn't delete this wiki group; refresh and try again",
|
|
109
|
+
}),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Stable application services supplied when mounting the wiki view. @internal */
|
|
114
|
+
export interface WikiUiHost {
|
|
115
|
+
/** @internal */ client: WikiClient;
|
|
116
|
+
/** Must return sanitized HTML. @internal */ renderMarkdownToHtml(markdown: string): string;
|
|
117
|
+
/** @internal */ navigate(path: string): void;
|
|
118
|
+
/** @internal */ followLink(event: MouseEvent, path: string): void;
|
|
119
|
+
/** @internal */ errorStatus(error: unknown): number | undefined;
|
|
120
|
+
/** @internal */ onWikiUpdated(listener: (topicId: string) => void): () => void;
|
|
121
|
+
/** @internal */ PageHeader: Component<{
|
|
122
|
+
/** @internal */ title: string;
|
|
123
|
+
/** @internal */ subtitle?: string | null;
|
|
124
|
+
/** @internal */ actions?: Snippet;
|
|
125
|
+
}>;
|
|
126
|
+
/** @internal */ ExternalLink: Component<{
|
|
127
|
+
/** @internal */
|
|
128
|
+
href: string;
|
|
129
|
+
/** @internal */
|
|
130
|
+
label: string;
|
|
131
|
+
}>;
|
|
132
|
+
}
|