backlog-tiny-mcp 0.34.2__py3-none-any.whl
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.
- backlog_mcp/__init__.py +29 -0
- backlog_mcp/__main__.py +10 -0
- backlog_mcp/auth.py +199 -0
- backlog_mcp/backlog.py +696 -0
- backlog_mcp/cli.py +2046 -0
- backlog_mcp/client.py +320 -0
- backlog_mcp/computer.py +33 -0
- backlog_mcp/database.py +80 -0
- backlog_mcp/embeddings.py +900 -0
- backlog_mcp/global_rules.md +126 -0
- backlog_mcp/guidance.py +11 -0
- backlog_mcp/guide/index.md +11 -0
- backlog_mcp/guide/memory.md +27 -0
- backlog_mcp/guide/projects.md +16 -0
- backlog_mcp/guide/search.md +72 -0
- backlog_mcp/guide/tasks.md +40 -0
- backlog_mcp/guide/workflow.md +22 -0
- backlog_mcp/httpd.py +270 -0
- backlog_mcp/migrate.py +113 -0
- backlog_mcp/migrations/0001-initial.sql +194 -0
- backlog_mcp/migrations/0002-task-assignment.sql +2 -0
- backlog_mcp/migrations/0003-task-edit-claims.sql +5 -0
- backlog_mcp/migrations/0004-memory-visibility.sql +42 -0
- backlog_mcp/model/CITATION.bib +9 -0
- backlog_mcp/model/LICENSE +202 -0
- backlog_mcp/model/README.md +12 -0
- backlog_mcp/model/UPSTREAM.md +2053 -0
- backlog_mcp/model/config.json +12 -0
- backlog_mcp/model/model.safetensors +4 -0
- backlog_mcp/model/modules.json +14 -0
- backlog_mcp/model/provenance.json +16 -0
- backlog_mcp/model/tokenizer.json +1 -0
- backlog_mcp/models.py +581 -0
- backlog_mcp/names.py +35 -0
- backlog_mcp/paths.py +53 -0
- backlog_mcp/protocol_storage.py +104 -0
- backlog_mcp/queries.py +7 -0
- backlog_mcp/queries.sql +531 -0
- backlog_mcp/records.py +215 -0
- backlog_mcp/render.py +479 -0
- backlog_mcp/server.py +2864 -0
- backlog_mcp/skills/autopilot/SKILL.md +96 -0
- backlog_mcp/skills/planning/SKILL.md +106 -0
- backlog_mcp/skills/planning/references/splitting.md +45 -0
- backlog_mcp/skills/triage/SKILL.md +104 -0
- backlog_mcp/skills/triage/references/conventions.md +43 -0
- backlog_mcp/skills.py +56 -0
- backlog_mcp/static/agent-config.js +20 -0
- backlog_mcp/static/app.css +1950 -0
- backlog_mcp/static/app.js +1301 -0
- backlog_mcp/static/assignments.js +96 -0
- backlog_mcp/static/breadcrumbs.js +54 -0
- backlog_mcp/static/comment-composer.js +95 -0
- backlog_mcp/static/connect.css +98 -0
- backlog_mcp/static/connect.html +74 -0
- backlog_mcp/static/connect.js +160 -0
- backlog_mcp/static/credentials.js +72 -0
- backlog_mcp/static/diagrams.js +128 -0
- backlog_mcp/static/dom.js +162 -0
- backlog_mcp/static/editor-claim.js +104 -0
- backlog_mcp/static/editor.js +355 -0
- backlog_mcp/static/index.html +137 -0
- backlog_mcp/static/markdown.css +33 -0
- backlog_mcp/static/markdown.js +72 -0
- backlog_mcp/static/mcp.js +177 -0
- backlog_mcp/static/memory-append.js +34 -0
- backlog_mcp/static/memory-editor.js +173 -0
- backlog_mcp/static/memory.js +279 -0
- backlog_mcp/static/package.json +1 -0
- backlog_mcp/static/project-form.js +71 -0
- backlog_mcp/static/project-settings.js +225 -0
- backlog_mcp/static/scope.js +90 -0
- backlog_mcp/static/statistics.js +87 -0
- backlog_mcp/static/task-browser.js +100 -0
- backlog_mcp/static/task-pagination.js +94 -0
- backlog_mcp/static/task-picker.js +164 -0
- backlog_mcp/static/task-table.js +74 -0
- backlog_mcp/static/vendor/README.md +12 -0
- backlog_mcp/static/vendor/dompurify-LICENSE +202 -0
- backlog_mcp/static/vendor/highlight-LICENSE +29 -0
- backlog_mcp/static/vendor/highlight-dark.css +118 -0
- backlog_mcp/static/vendor/highlight-light.css +118 -0
- backlog_mcp/static/vendor/highlight.min.js +1262 -0
- backlog_mcp/static/vendor/marked-LICENSE +44 -0
- backlog_mcp/static/vendor/marked.esm.js +80 -0
- backlog_mcp/static/vendor/marked.esm.js.map +7 -0
- backlog_mcp/static/vendor/mermaid-LICENSE +21 -0
- backlog_mcp/static/vendor/mermaid.min.js +4376 -0
- backlog_mcp/static/vendor/purify.es.mjs +2722 -0
- backlog_mcp/static/vendor/purify.es.mjs.map +1 -0
- backlog_mcp/transaction.py +47 -0
- backlog_mcp/version.py +79 -0
- backlog_mcp/webui.py +63 -0
- backlog_tiny_mcp-0.34.2.dist-info/METADATA +84 -0
- backlog_tiny_mcp-0.34.2.dist-info/RECORD +97 -0
- backlog_tiny_mcp-0.34.2.dist-info/WHEEL +4 -0
- backlog_tiny_mcp-0.34.2.dist-info/entry_points.txt +4 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/** Minimal Streamable HTTP client. Credentials only leave through this endpoint. */
|
|
2
|
+
export class HttpError extends Error {
|
|
3
|
+
constructor(response) {
|
|
4
|
+
super(
|
|
5
|
+
response.status === 401
|
|
6
|
+
? "Sign in to continue. Check your credentials."
|
|
7
|
+
: `HTTP ${response.status}: ${response.statusText}`,
|
|
8
|
+
);
|
|
9
|
+
this.status = response.status;
|
|
10
|
+
this.schemes = [
|
|
11
|
+
...(response.headers.get("WWW-Authenticate") || "").matchAll(/(?:^|,)\s*(Basic|Bearer)\b/gi),
|
|
12
|
+
].map((m) => m[1].toLowerCase());
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export class RpcError extends Error {
|
|
16
|
+
constructor(error) {
|
|
17
|
+
super(error.message);
|
|
18
|
+
this.code = error.code;
|
|
19
|
+
this.data = error.data;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
export class ToolError extends Error {}
|
|
23
|
+
|
|
24
|
+
export class MCP {
|
|
25
|
+
constructor(endpoint, authorization = "", onElicit = null) {
|
|
26
|
+
this.url = new URL(endpoint, location.origin);
|
|
27
|
+
if (this.url.origin !== location.origin || this.url.username || this.url.password)
|
|
28
|
+
throw new Error("The MCP endpoint must use this origin.");
|
|
29
|
+
this.authorization = authorization;
|
|
30
|
+
this.onElicit = onElicit;
|
|
31
|
+
this.session = null;
|
|
32
|
+
this.counter = 0;
|
|
33
|
+
this.ready = null;
|
|
34
|
+
this.version = "2025-11-25";
|
|
35
|
+
this.abort = new AbortController();
|
|
36
|
+
}
|
|
37
|
+
close() {
|
|
38
|
+
this.abort.abort();
|
|
39
|
+
this.session = null;
|
|
40
|
+
this.ready = null;
|
|
41
|
+
}
|
|
42
|
+
async send(method, params = {}, notification = false) {
|
|
43
|
+
const id = notification ? undefined : ++this.counter;
|
|
44
|
+
const headers = {
|
|
45
|
+
"Content-Type": "application/json",
|
|
46
|
+
Accept: "application/json, text/event-stream",
|
|
47
|
+
"MCP-Protocol-Version": this.version,
|
|
48
|
+
};
|
|
49
|
+
if (this.authorization) headers.Authorization = this.authorization;
|
|
50
|
+
if (this.session) headers["Mcp-Session-Id"] = this.session;
|
|
51
|
+
const response = await fetch(this.url, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
headers,
|
|
54
|
+
credentials: "omit",
|
|
55
|
+
redirect: "error",
|
|
56
|
+
signal: this.abort.signal,
|
|
57
|
+
body: JSON.stringify({ jsonrpc: "2.0", id, method, params }),
|
|
58
|
+
});
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
if (response.status === 401 || response.status === 404) {
|
|
61
|
+
await response.body?.cancel();
|
|
62
|
+
throw new HttpError(response);
|
|
63
|
+
}
|
|
64
|
+
const body = await response.json().catch(() => null);
|
|
65
|
+
if (body?.error) throw new RpcError(body.error);
|
|
66
|
+
throw new HttpError(response);
|
|
67
|
+
}
|
|
68
|
+
const session = response.headers.get("Mcp-Session-Id");
|
|
69
|
+
if (session) this.session = session;
|
|
70
|
+
if (notification) {
|
|
71
|
+
await response.body?.cancel();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const match = (frame) => frame.id === id || (frame.id === null && frame.error);
|
|
75
|
+
const unwrap = (frame) => {
|
|
76
|
+
if (frame.error) throw new RpcError(frame.error);
|
|
77
|
+
return frame.result;
|
|
78
|
+
};
|
|
79
|
+
if (!(response.headers.get("Content-Type") || "").includes("text/event-stream")) {
|
|
80
|
+
const frame = await response.json();
|
|
81
|
+
if (!match(frame)) throw new Error("MCP returned an unexpected response ID.");
|
|
82
|
+
return unwrap(frame);
|
|
83
|
+
}
|
|
84
|
+
const reader = response.body.getReader();
|
|
85
|
+
const decoder = new TextDecoder();
|
|
86
|
+
let buffer = "",
|
|
87
|
+
data = [];
|
|
88
|
+
try {
|
|
89
|
+
while (true) {
|
|
90
|
+
const { value, done } = await reader.read();
|
|
91
|
+
buffer += decoder.decode(value || new Uint8Array(), { stream: !done });
|
|
92
|
+
let cut;
|
|
93
|
+
while ((cut = buffer.indexOf("\n")) >= 0) {
|
|
94
|
+
const line = buffer.slice(0, cut).replace(/\r$/, "");
|
|
95
|
+
buffer = buffer.slice(cut + 1);
|
|
96
|
+
if (line.startsWith("data:")) data.push(line.slice(5).replace(/^ /, ""));
|
|
97
|
+
if (line === "" && data.length) {
|
|
98
|
+
const text = data.join("\n");
|
|
99
|
+
data = [];
|
|
100
|
+
if (!text.trim()) continue;
|
|
101
|
+
const frame = JSON.parse(text);
|
|
102
|
+
if (frame.method === "elicitation/create" && frame.id !== undefined) {
|
|
103
|
+
const result = this.onElicit
|
|
104
|
+
? await this.onElicit(frame.params)
|
|
105
|
+
: { action: "decline" };
|
|
106
|
+
const reply = await fetch(this.url, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
headers: {
|
|
109
|
+
...headers,
|
|
110
|
+
...(this.session ? { "Mcp-Session-Id": this.session } : {}),
|
|
111
|
+
},
|
|
112
|
+
credentials: "omit",
|
|
113
|
+
redirect: "error",
|
|
114
|
+
signal: this.abort.signal,
|
|
115
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: frame.id, result }),
|
|
116
|
+
});
|
|
117
|
+
if (!reply.ok) throw new HttpError(reply);
|
|
118
|
+
await reply.body?.cancel();
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (match(frame)) return unwrap(frame);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (done) throw new Error("MCP stream ended without a reply.");
|
|
125
|
+
}
|
|
126
|
+
} finally {
|
|
127
|
+
await reader.cancel();
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
async initialize() {
|
|
131
|
+
if (!this.ready)
|
|
132
|
+
this.ready = (async () => {
|
|
133
|
+
const result = await this.send("initialize", {
|
|
134
|
+
protocolVersion: this.version,
|
|
135
|
+
capabilities: this.onElicit ? { elicitation: { form: {} } } : {},
|
|
136
|
+
clientInfo: { name: "backlog-web", version: "0.32.1" },
|
|
137
|
+
});
|
|
138
|
+
if (!["2025-11-25", "2025-06-18", "2025-03-26"].includes(result.protocolVersion))
|
|
139
|
+
throw new Error("Unsupported MCP protocol version.");
|
|
140
|
+
this.version = result.protocolVersion;
|
|
141
|
+
await this.send("notifications/initialized", {}, true);
|
|
142
|
+
})().catch((error) => {
|
|
143
|
+
this.ready = null;
|
|
144
|
+
throw error;
|
|
145
|
+
});
|
|
146
|
+
return this.ready;
|
|
147
|
+
}
|
|
148
|
+
async request(method, params = {}) {
|
|
149
|
+
await this.initialize();
|
|
150
|
+
let result;
|
|
151
|
+
const previous = this.session;
|
|
152
|
+
try {
|
|
153
|
+
result = await this.send(method, params);
|
|
154
|
+
} catch (error) {
|
|
155
|
+
if (!(error instanceof HttpError) || error.status !== 404) throw error;
|
|
156
|
+
// A concurrent request may already have replaced the expired session.
|
|
157
|
+
if (this.session === previous) {
|
|
158
|
+
this.session = null;
|
|
159
|
+
this.ready = null;
|
|
160
|
+
}
|
|
161
|
+
await this.initialize();
|
|
162
|
+
result = await this.send(method, params);
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
}
|
|
166
|
+
async call(name, args = {}) {
|
|
167
|
+
const result = await this.request("tools/call", { name, arguments: args });
|
|
168
|
+
const text = (result.content || [])
|
|
169
|
+
.filter((block) => block.type === "text")
|
|
170
|
+
.map((block) => block.text)
|
|
171
|
+
.join("\n");
|
|
172
|
+
if (result.isError) throw new ToolError(text || "The server refused this operation.");
|
|
173
|
+
if (text) return JSON.parse(text);
|
|
174
|
+
if (result.structuredContent) return result.structuredContent;
|
|
175
|
+
throw new Error("The tool returned no JSON data.");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { el, field, modal } from "./dom.js";
|
|
2
|
+
|
|
3
|
+
export async function appendNote(note, { call, refresh, principal }) {
|
|
4
|
+
const key = `backlog:memory-append:${document.documentElement.dataset.endpoint}:${principal}:${note.id}`;
|
|
5
|
+
let draft = "";
|
|
6
|
+
try {
|
|
7
|
+
draft = localStorage.getItem(key) || "";
|
|
8
|
+
} catch {}
|
|
9
|
+
const text = el("textarea", { rows: 6, required: true, value: draft });
|
|
10
|
+
const count = el("p", { class: "muted", role: "status" });
|
|
11
|
+
function update() {
|
|
12
|
+
const size = [...(note.body ? note.body + "\n\n" : ""), ...text.value].length;
|
|
13
|
+
count.textContent = `${size} / 1024 characters after appending`;
|
|
14
|
+
text.setCustomValidity(size > 1024 ? "The complete note must fit 1024 characters." : "");
|
|
15
|
+
try {
|
|
16
|
+
localStorage.setItem(key, text.value);
|
|
17
|
+
} catch {}
|
|
18
|
+
}
|
|
19
|
+
text.oninput = update;
|
|
20
|
+
update();
|
|
21
|
+
const saved = await modal({
|
|
22
|
+
title: "Append to note",
|
|
23
|
+
description: `${note.title} — ${note.project}`,
|
|
24
|
+
content: [field("Addition", text), count],
|
|
25
|
+
action: "Append",
|
|
26
|
+
onSubmit: async () => {
|
|
27
|
+
await call("memory_append", { id: note.id, text: text.value });
|
|
28
|
+
try {
|
|
29
|
+
localStorage.removeItem(key);
|
|
30
|
+
} catch {}
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
if (saved) await refresh();
|
|
34
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { el, button, link, field, select, memoryRoute } from "./dom.js";
|
|
2
|
+
|
|
3
|
+
export function memoryEditor(
|
|
4
|
+
project,
|
|
5
|
+
projects,
|
|
6
|
+
{ call, navigate, markdown, principal },
|
|
7
|
+
existing = null,
|
|
8
|
+
) {
|
|
9
|
+
const key = `backlog:memory-draft:${principal}:${existing ? "note:" + existing.id : project || "all"}`;
|
|
10
|
+
let saved;
|
|
11
|
+
try {
|
|
12
|
+
saved = JSON.parse(localStorage.getItem(key));
|
|
13
|
+
} catch {
|
|
14
|
+
saved = null;
|
|
15
|
+
}
|
|
16
|
+
existing ||= saved?.base || null;
|
|
17
|
+
const writable = projects.filter((p) => ["owner", "editor"].includes(p.role));
|
|
18
|
+
const names = writable.map((p) => p.full_name);
|
|
19
|
+
const initial = saved || (existing ? { ...existing, tags: existing.tags.join(", ") } : {});
|
|
20
|
+
let base = saved?.base || existing;
|
|
21
|
+
const scope = select(["", ...names], saved?.project || project, { required: true });
|
|
22
|
+
scope.options[0].text = "Choose a project";
|
|
23
|
+
scope.disabled = Boolean(existing);
|
|
24
|
+
const title = el("input", { required: true, value: initial.title || "" });
|
|
25
|
+
const body = el("textarea", { value: initial.body || "", rows: 8 });
|
|
26
|
+
const tags = el("input", { value: initial.tags || "", placeholder: "Comma-separated tags" });
|
|
27
|
+
const shared = el("input", { type: "checkbox", checked: initial.shared === true });
|
|
28
|
+
const globalScope = el("input", { type: "checkbox", checked: initial.global_scope === true });
|
|
29
|
+
const count = el("small", { class: "muted", "aria-live": "polite" });
|
|
30
|
+
const error = el("p", { class: "error", role: "alert", hidden: true });
|
|
31
|
+
const preview = el("div", { class: "markdown editor-preview", hidden: true });
|
|
32
|
+
const submit = el(
|
|
33
|
+
"button",
|
|
34
|
+
{ type: "submit", class: "primary", disabled: !names.length },
|
|
35
|
+
existing ? "Save changes" : "Add note",
|
|
36
|
+
);
|
|
37
|
+
const back = memoryRoute(project, new URLSearchParams(existing ? { note: existing.id } : {}));
|
|
38
|
+
const form = el(
|
|
39
|
+
"form",
|
|
40
|
+
{ class: "editor" },
|
|
41
|
+
link("← Memory", back),
|
|
42
|
+
el("h1", {}, existing ? "Edit note" : "Add note"),
|
|
43
|
+
el(
|
|
44
|
+
"p",
|
|
45
|
+
{ class: "muted" },
|
|
46
|
+
saved
|
|
47
|
+
? "Your saved draft has been restored."
|
|
48
|
+
: "Your draft is saved automatically in this browser.",
|
|
49
|
+
),
|
|
50
|
+
!names.length
|
|
51
|
+
? el("p", { class: "error" }, "You need editor access to a project to add a note.")
|
|
52
|
+
: null,
|
|
53
|
+
el(
|
|
54
|
+
"div",
|
|
55
|
+
{ class: "panel" },
|
|
56
|
+
field("Project", scope),
|
|
57
|
+
field("Title", title),
|
|
58
|
+
field("Tags", tags),
|
|
59
|
+
el("label", { class: "inline" }, shared, "Share with project members"),
|
|
60
|
+
el("label", { class: "inline" }, globalScope, "Available in all projects to the same people"),
|
|
61
|
+
field("Content", body),
|
|
62
|
+
count,
|
|
63
|
+
el(
|
|
64
|
+
"div",
|
|
65
|
+
{ class: "editor-tabs" },
|
|
66
|
+
button("Preview", () => {
|
|
67
|
+
preview.hidden = !preview.hidden;
|
|
68
|
+
preview.replaceChildren(markdown(body.value));
|
|
69
|
+
}),
|
|
70
|
+
),
|
|
71
|
+
preview,
|
|
72
|
+
),
|
|
73
|
+
error,
|
|
74
|
+
el(
|
|
75
|
+
"div",
|
|
76
|
+
{ class: "form-actions" },
|
|
77
|
+
submit,
|
|
78
|
+
link("Cancel", back, "button"),
|
|
79
|
+
button(
|
|
80
|
+
"Discard draft",
|
|
81
|
+
() => {
|
|
82
|
+
localStorage.removeItem(key);
|
|
83
|
+
navigate(back);
|
|
84
|
+
},
|
|
85
|
+
"quiet",
|
|
86
|
+
),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
function values() {
|
|
90
|
+
return {
|
|
91
|
+
project: scope.value,
|
|
92
|
+
title: title.value,
|
|
93
|
+
body: body.value,
|
|
94
|
+
tags: tags.value,
|
|
95
|
+
shared: shared.checked,
|
|
96
|
+
global_scope: globalScope.checked,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function update() {
|
|
100
|
+
const length = [...body.value].length;
|
|
101
|
+
count.textContent = `${length} / 1024 characters`;
|
|
102
|
+
body.setCustomValidity(length > 1024 ? "Use at most 1024 characters." : "");
|
|
103
|
+
title.setCustomValidity(title.value.trim() ? "" : "Enter a title.");
|
|
104
|
+
}
|
|
105
|
+
function persist() {
|
|
106
|
+
update();
|
|
107
|
+
try {
|
|
108
|
+
localStorage.setItem(key, JSON.stringify({ ...values(), base }));
|
|
109
|
+
} catch {
|
|
110
|
+
error.hidden = false;
|
|
111
|
+
error.textContent = "The browser could not save this draft.";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
form.addEventListener("input", persist);
|
|
115
|
+
form.addEventListener("change", persist);
|
|
116
|
+
update();
|
|
117
|
+
form.onsubmit = async (event) => {
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
persist();
|
|
120
|
+
if (!form.reportValidity()) return;
|
|
121
|
+
submit.disabled = true;
|
|
122
|
+
error.hidden = true;
|
|
123
|
+
try {
|
|
124
|
+
const data = values();
|
|
125
|
+
if (existing) {
|
|
126
|
+
const current = await call("memory_get", { id: existing.id });
|
|
127
|
+
if (
|
|
128
|
+
["title", "body", "tags", "shared", "global_scope", "updated_at"].some(
|
|
129
|
+
(k) => JSON.stringify(current[k]) !== JSON.stringify(base[k]),
|
|
130
|
+
)
|
|
131
|
+
)
|
|
132
|
+
throw new Error(
|
|
133
|
+
"This note changed while you were editing. Your draft is saved. Copy your changes, then discard the draft and reopen the note to review the latest version.",
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
const { shared: shareEntry, global_scope: globalEntry, ...content } = data;
|
|
137
|
+
let note = await call("memory_save", {
|
|
138
|
+
...content,
|
|
139
|
+
title: data.title.trim(),
|
|
140
|
+
tags: [
|
|
141
|
+
...new Set(
|
|
142
|
+
data.tags
|
|
143
|
+
.split(",")
|
|
144
|
+
.map((t) => t.trim())
|
|
145
|
+
.filter(Boolean),
|
|
146
|
+
),
|
|
147
|
+
],
|
|
148
|
+
...(existing ? { id: existing.id } : { create_only: true }),
|
|
149
|
+
});
|
|
150
|
+
existing = base = note;
|
|
151
|
+
scope.disabled = true;
|
|
152
|
+
persist();
|
|
153
|
+
if (note.shared !== shareEntry || Boolean(note.global_scope) !== globalEntry) {
|
|
154
|
+
note = await call("memory_sharing", {
|
|
155
|
+
id: note.id, shared: shareEntry, global_scope: globalEntry,
|
|
156
|
+
});
|
|
157
|
+
existing = base = note;
|
|
158
|
+
}
|
|
159
|
+
try {
|
|
160
|
+
localStorage.removeItem(key);
|
|
161
|
+
} catch {
|
|
162
|
+
/* The note was saved successfully. */
|
|
163
|
+
}
|
|
164
|
+
navigate(memoryRoute(note.project, new URLSearchParams({ note: note.id })));
|
|
165
|
+
} catch (failure) {
|
|
166
|
+
error.textContent = failure.message;
|
|
167
|
+
error.hidden = false;
|
|
168
|
+
} finally {
|
|
169
|
+
submit.disabled = false;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
return form;
|
|
173
|
+
}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { scopeArgs, scopeControls, scopeLabel } from "./scope.js";
|
|
2
|
+
import { appendNote } from "./memory-append.js";
|
|
3
|
+
import { el, button, link, field, select, date, projectRoute, memoryRoute, modal } from "./dom.js";
|
|
4
|
+
import { memoryEditor } from "./memory-editor.js";
|
|
5
|
+
|
|
6
|
+
export async function memoryPage(target, actions) {
|
|
7
|
+
const { call, navigate, markdown } = actions;
|
|
8
|
+
const params = target.params;
|
|
9
|
+
if (
|
|
10
|
+
(params.get("create") === "true" && !target.id) ||
|
|
11
|
+
(params.get("edit") === "true" && target.id)
|
|
12
|
+
) {
|
|
13
|
+
const projects = await call("project_list", { all_computers: true });
|
|
14
|
+
const note = target.id ? await call("memory_get", { id: target.id }) : null;
|
|
15
|
+
return memoryEditor(note?.project || target.project, projects.items, actions, note);
|
|
16
|
+
}
|
|
17
|
+
const offset = 0;
|
|
18
|
+
const limit = 25;
|
|
19
|
+
const args = { ...scopeArgs(params), limit, offset };
|
|
20
|
+
if (params.get("shared") === "true") args.shared = true;
|
|
21
|
+
if (params.get("shared") === "false") args.shared = false;
|
|
22
|
+
if (params.get("tag")) args.tag = params.get("tag");
|
|
23
|
+
const [notes, projects] = await Promise.all([
|
|
24
|
+
call("memory_list", args),
|
|
25
|
+
call("project_list", { all_computers: true }),
|
|
26
|
+
]);
|
|
27
|
+
const scope = scopeControls(params, projects.items);
|
|
28
|
+
const visibility = select(["", "true", "false"], params.get("shared") || "", {
|
|
29
|
+
"aria-label": "Memory visibility",
|
|
30
|
+
});
|
|
31
|
+
["All notes", "Shared only", "Personal only"].forEach(
|
|
32
|
+
(label, i) => (visibility.options[i].text = label),
|
|
33
|
+
);
|
|
34
|
+
const tag = el("input", {
|
|
35
|
+
value: params.get("tag") || "",
|
|
36
|
+
placeholder: "Any tag",
|
|
37
|
+
"aria-label": "Memory tag",
|
|
38
|
+
});
|
|
39
|
+
const change = (updates) => {
|
|
40
|
+
const p = new URLSearchParams(params);
|
|
41
|
+
for (const [key, value] of Object.entries(updates)) {
|
|
42
|
+
if (value === null || value === "") p.delete(key);
|
|
43
|
+
else p.set(key, String(value));
|
|
44
|
+
}
|
|
45
|
+
return memoryRoute(p.get("project") || "", p);
|
|
46
|
+
};
|
|
47
|
+
const filters = el(
|
|
48
|
+
"form",
|
|
49
|
+
{ class: "memory-filters" },
|
|
50
|
+
scope.element,
|
|
51
|
+
field("Visibility", visibility),
|
|
52
|
+
field("Tag", tag),
|
|
53
|
+
el("button", { type: "submit" }, "Apply filters"),
|
|
54
|
+
);
|
|
55
|
+
filters.onsubmit = (event) => {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
const next = scope.apply(new URLSearchParams(params));
|
|
58
|
+
next.delete("note");
|
|
59
|
+
for (const [key, value] of Object.entries({
|
|
60
|
+
shared: visibility.value,
|
|
61
|
+
tag: tag.value.trim(),
|
|
62
|
+
})) {
|
|
63
|
+
if (value) next.set(key, value);
|
|
64
|
+
else next.delete(key);
|
|
65
|
+
}
|
|
66
|
+
navigate(memoryRoute(next.get("project") || "", next));
|
|
67
|
+
};
|
|
68
|
+
function noteItem(note) {
|
|
69
|
+
const item = link("", change({ note: note.id }), "memory-item");
|
|
70
|
+
if (note.id === target.id) item.setAttribute("aria-current", "page");
|
|
71
|
+
item.append(
|
|
72
|
+
el(
|
|
73
|
+
"div",
|
|
74
|
+
{ class: "memory-item-meta" },
|
|
75
|
+
`Note ${note.id}`,
|
|
76
|
+
...(note.shared ? [el("span", { class: "tag" }, "Shared")] : []),
|
|
77
|
+
...(note.global_scope ? [el("span", { class: "tag" }, "All projects")] : []),
|
|
78
|
+
),
|
|
79
|
+
el("strong", {}, note.title),
|
|
80
|
+
el("p", {}, note.snippet || "No preview available."),
|
|
81
|
+
el("small", {}, note.project),
|
|
82
|
+
);
|
|
83
|
+
return item;
|
|
84
|
+
}
|
|
85
|
+
const list = el(
|
|
86
|
+
"nav",
|
|
87
|
+
{ class: "memory-list", "aria-label": "Memory notes" },
|
|
88
|
+
...notes.items.map(noteItem),
|
|
89
|
+
);
|
|
90
|
+
if (!notes.items.length)
|
|
91
|
+
list.append(
|
|
92
|
+
el(
|
|
93
|
+
"div",
|
|
94
|
+
{ class: "memory-empty" },
|
|
95
|
+
el("strong", {}, "No notes found"),
|
|
96
|
+
el("p", { class: "muted" }, "Choose another project or change the filters."),
|
|
97
|
+
),
|
|
98
|
+
);
|
|
99
|
+
let nextOffset = notes.items.length;
|
|
100
|
+
let total = notes.count;
|
|
101
|
+
let loading = false;
|
|
102
|
+
let disposed = false;
|
|
103
|
+
const seen = new Set(notes.items.map((note) => note.id));
|
|
104
|
+
const sentinel = el("div", { class: "memory-pagination", role: "status", "aria-live": "polite" });
|
|
105
|
+
const observer = new IntersectionObserver(
|
|
106
|
+
(entries) => {
|
|
107
|
+
if (entries.some((entry) => entry.isIntersecting)) loadMore();
|
|
108
|
+
},
|
|
109
|
+
{ rootMargin: "200px" },
|
|
110
|
+
);
|
|
111
|
+
function state() {
|
|
112
|
+
sentinel.replaceChildren(
|
|
113
|
+
el(
|
|
114
|
+
"span",
|
|
115
|
+
{ class: "muted" },
|
|
116
|
+
nextOffset < total
|
|
117
|
+
? `${seen.size} of ${total} notes · Scroll for more`
|
|
118
|
+
: `${seen.size} notes · All loaded`,
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
async function loadMore() {
|
|
123
|
+
if (loading || disposed || nextOffset >= total || !list.isConnected) return;
|
|
124
|
+
loading = true;
|
|
125
|
+
list.setAttribute("aria-busy", "true");
|
|
126
|
+
observer.unobserve(sentinel);
|
|
127
|
+
sentinel.replaceChildren(el("span", {}, "Loading more notes…"));
|
|
128
|
+
try {
|
|
129
|
+
const page = await call("memory_list", { ...args, offset: nextOffset });
|
|
130
|
+
if (disposed || !list.isConnected) return;
|
|
131
|
+
nextOffset += page.items.length;
|
|
132
|
+
total = page.count;
|
|
133
|
+
for (const note of page.items) {
|
|
134
|
+
if (seen.has(note.id)) continue;
|
|
135
|
+
seen.add(note.id);
|
|
136
|
+
list.insertBefore(noteItem(note), sentinel);
|
|
137
|
+
}
|
|
138
|
+
if (!page.items.length) total = nextOffset;
|
|
139
|
+
state();
|
|
140
|
+
if (nextOffset < total) observer.observe(sentinel);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
if (!disposed && list.isConnected)
|
|
143
|
+
sentinel.replaceChildren(
|
|
144
|
+
el("span", { class: "error" }, `Could not load more notes: ${error.message}`),
|
|
145
|
+
button("Retry", loadMore),
|
|
146
|
+
);
|
|
147
|
+
} finally {
|
|
148
|
+
loading = false;
|
|
149
|
+
list.removeAttribute("aria-busy");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
state();
|
|
153
|
+
list.append(sentinel);
|
|
154
|
+
const detail = el("article", { class: "panel memory-detail" });
|
|
155
|
+
if (target.id) {
|
|
156
|
+
try {
|
|
157
|
+
const note = await call("memory_get", { id: target.id });
|
|
158
|
+
const canEdit = projects.items.some(
|
|
159
|
+
(p) => p.full_name === note.project && ["owner", "editor"].includes(p.role),
|
|
160
|
+
);
|
|
161
|
+
const remove = button(
|
|
162
|
+
"Delete note",
|
|
163
|
+
async () => {
|
|
164
|
+
const confirmed = await modal({
|
|
165
|
+
title: "Delete note?",
|
|
166
|
+
description: `${note.title} — ${note.project}`,
|
|
167
|
+
content: [el("p", {}, "This permanently deletes the note.")],
|
|
168
|
+
action: "Delete note",
|
|
169
|
+
danger: true,
|
|
170
|
+
});
|
|
171
|
+
if (!confirmed) return;
|
|
172
|
+
remove.disabled = true;
|
|
173
|
+
try {
|
|
174
|
+
const result = await call("memory_delete", { id: note.id });
|
|
175
|
+
if (result.deleted) navigate(change({ note: null }));
|
|
176
|
+
} catch (error) {
|
|
177
|
+
actions.notify(error);
|
|
178
|
+
} finally {
|
|
179
|
+
remove.disabled = false;
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
"destructive",
|
|
183
|
+
);
|
|
184
|
+
detail.append(
|
|
185
|
+
link("← Back to notes", change({ note: null }), "memory-back"),
|
|
186
|
+
el("div", { class: "eyebrow" }, `Memory · ${note.id}`),
|
|
187
|
+
el(
|
|
188
|
+
"div",
|
|
189
|
+
{ class: "row spread memory-title" },
|
|
190
|
+
el("h2", {}, note.title),
|
|
191
|
+
canEdit
|
|
192
|
+
? link(
|
|
193
|
+
"Edit note",
|
|
194
|
+
memoryRoute(note.project, new URLSearchParams({ note: note.id, edit: "true" })),
|
|
195
|
+
"button",
|
|
196
|
+
)
|
|
197
|
+
: null,
|
|
198
|
+
canEdit ? button("Append to note", () => appendNote(note, actions)) : null,
|
|
199
|
+
canEdit ? remove : null,
|
|
200
|
+
),
|
|
201
|
+
el(
|
|
202
|
+
"div",
|
|
203
|
+
{ class: "memory-detail-meta" },
|
|
204
|
+
link(note.project, projectRoute(note.project)),
|
|
205
|
+
el("span", { class: "tag" }, note.shared ? "Project members" : "Personal"),
|
|
206
|
+
...(note.global_scope ? [el("span", { class: "tag" }, "All projects")] : []),
|
|
207
|
+
),
|
|
208
|
+
el(
|
|
209
|
+
"div",
|
|
210
|
+
{ class: "memory-tags" },
|
|
211
|
+
...(note.tags || []).map((t) => el("span", { class: "tag" }, t)),
|
|
212
|
+
),
|
|
213
|
+
el("div", { class: "markdown memory-body" }, markdown(note.body || "No content.")),
|
|
214
|
+
el(
|
|
215
|
+
"dl",
|
|
216
|
+
{ class: "memory-audit" },
|
|
217
|
+
el("dt", {}, "Updated"),
|
|
218
|
+
el("dd", {}, `${date(note.updated_at)} · ${note.updated_by || "—"}`),
|
|
219
|
+
el("dt", {}, "Created"),
|
|
220
|
+
el("dd", {}, `${date(note.created_at)} · ${note.created_by || "—"}`),
|
|
221
|
+
),
|
|
222
|
+
);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
detail.append(
|
|
225
|
+
link("← Back to notes", change({ note: null }), "memory-back"),
|
|
226
|
+
el("h2", {}, "Could not load this note"),
|
|
227
|
+
el("p", { class: "error", role: "alert" }, error.message),
|
|
228
|
+
button("Try again", () => navigate(change({ note: target.id }))),
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
} else
|
|
232
|
+
detail.append(
|
|
233
|
+
el(
|
|
234
|
+
"div",
|
|
235
|
+
{ class: "memory-placeholder" },
|
|
236
|
+
el("h2", {}, "Select a note"),
|
|
237
|
+
el("p", { class: "muted" }, "Read project context, decisions, and shared agreements."),
|
|
238
|
+
),
|
|
239
|
+
);
|
|
240
|
+
const page = el(
|
|
241
|
+
"section",
|
|
242
|
+
{ class: `memory-page${target.id ? " has-selection" : ""}` },
|
|
243
|
+
el("div", { class: "eyebrow" }, "Knowledge"),
|
|
244
|
+
el(
|
|
245
|
+
"div",
|
|
246
|
+
{ class: "row spread" },
|
|
247
|
+
el("h1", {}, "Memory"),
|
|
248
|
+
el(
|
|
249
|
+
"div",
|
|
250
|
+
{ class: "row" },
|
|
251
|
+
link(
|
|
252
|
+
"Add note",
|
|
253
|
+
memoryRoute(target.project, new URLSearchParams({ create: "true" })),
|
|
254
|
+
"button primary",
|
|
255
|
+
),
|
|
256
|
+
link(
|
|
257
|
+
target.project ? "Back to tasks" : "Projects",
|
|
258
|
+
target.project ? projectRoute(target.project) : "/ui/",
|
|
259
|
+
"button",
|
|
260
|
+
),
|
|
261
|
+
),
|
|
262
|
+
),
|
|
263
|
+
el(
|
|
264
|
+
"p",
|
|
265
|
+
{ class: "subtitle" },
|
|
266
|
+
`${notes.count} notes · ${scopeLabel(params, actions.principal)}`,
|
|
267
|
+
),
|
|
268
|
+
filters,
|
|
269
|
+
el("div", { class: "memory-layout" }, el("aside", { class: "memory-sidebar" }, list), detail),
|
|
270
|
+
);
|
|
271
|
+
page.mount = () => {
|
|
272
|
+
if (nextOffset < total) observer.observe(sentinel);
|
|
273
|
+
};
|
|
274
|
+
page.dispose = () => {
|
|
275
|
+
disposed = true;
|
|
276
|
+
observer.disconnect();
|
|
277
|
+
};
|
|
278
|
+
return page;
|
|
279
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module","private":true}
|