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.
Files changed (97) hide show
  1. backlog_mcp/__init__.py +29 -0
  2. backlog_mcp/__main__.py +10 -0
  3. backlog_mcp/auth.py +199 -0
  4. backlog_mcp/backlog.py +696 -0
  5. backlog_mcp/cli.py +2046 -0
  6. backlog_mcp/client.py +320 -0
  7. backlog_mcp/computer.py +33 -0
  8. backlog_mcp/database.py +80 -0
  9. backlog_mcp/embeddings.py +900 -0
  10. backlog_mcp/global_rules.md +126 -0
  11. backlog_mcp/guidance.py +11 -0
  12. backlog_mcp/guide/index.md +11 -0
  13. backlog_mcp/guide/memory.md +27 -0
  14. backlog_mcp/guide/projects.md +16 -0
  15. backlog_mcp/guide/search.md +72 -0
  16. backlog_mcp/guide/tasks.md +40 -0
  17. backlog_mcp/guide/workflow.md +22 -0
  18. backlog_mcp/httpd.py +270 -0
  19. backlog_mcp/migrate.py +113 -0
  20. backlog_mcp/migrations/0001-initial.sql +194 -0
  21. backlog_mcp/migrations/0002-task-assignment.sql +2 -0
  22. backlog_mcp/migrations/0003-task-edit-claims.sql +5 -0
  23. backlog_mcp/migrations/0004-memory-visibility.sql +42 -0
  24. backlog_mcp/model/CITATION.bib +9 -0
  25. backlog_mcp/model/LICENSE +202 -0
  26. backlog_mcp/model/README.md +12 -0
  27. backlog_mcp/model/UPSTREAM.md +2053 -0
  28. backlog_mcp/model/config.json +12 -0
  29. backlog_mcp/model/model.safetensors +4 -0
  30. backlog_mcp/model/modules.json +14 -0
  31. backlog_mcp/model/provenance.json +16 -0
  32. backlog_mcp/model/tokenizer.json +1 -0
  33. backlog_mcp/models.py +581 -0
  34. backlog_mcp/names.py +35 -0
  35. backlog_mcp/paths.py +53 -0
  36. backlog_mcp/protocol_storage.py +104 -0
  37. backlog_mcp/queries.py +7 -0
  38. backlog_mcp/queries.sql +531 -0
  39. backlog_mcp/records.py +215 -0
  40. backlog_mcp/render.py +479 -0
  41. backlog_mcp/server.py +2864 -0
  42. backlog_mcp/skills/autopilot/SKILL.md +96 -0
  43. backlog_mcp/skills/planning/SKILL.md +106 -0
  44. backlog_mcp/skills/planning/references/splitting.md +45 -0
  45. backlog_mcp/skills/triage/SKILL.md +104 -0
  46. backlog_mcp/skills/triage/references/conventions.md +43 -0
  47. backlog_mcp/skills.py +56 -0
  48. backlog_mcp/static/agent-config.js +20 -0
  49. backlog_mcp/static/app.css +1950 -0
  50. backlog_mcp/static/app.js +1301 -0
  51. backlog_mcp/static/assignments.js +96 -0
  52. backlog_mcp/static/breadcrumbs.js +54 -0
  53. backlog_mcp/static/comment-composer.js +95 -0
  54. backlog_mcp/static/connect.css +98 -0
  55. backlog_mcp/static/connect.html +74 -0
  56. backlog_mcp/static/connect.js +160 -0
  57. backlog_mcp/static/credentials.js +72 -0
  58. backlog_mcp/static/diagrams.js +128 -0
  59. backlog_mcp/static/dom.js +162 -0
  60. backlog_mcp/static/editor-claim.js +104 -0
  61. backlog_mcp/static/editor.js +355 -0
  62. backlog_mcp/static/index.html +137 -0
  63. backlog_mcp/static/markdown.css +33 -0
  64. backlog_mcp/static/markdown.js +72 -0
  65. backlog_mcp/static/mcp.js +177 -0
  66. backlog_mcp/static/memory-append.js +34 -0
  67. backlog_mcp/static/memory-editor.js +173 -0
  68. backlog_mcp/static/memory.js +279 -0
  69. backlog_mcp/static/package.json +1 -0
  70. backlog_mcp/static/project-form.js +71 -0
  71. backlog_mcp/static/project-settings.js +225 -0
  72. backlog_mcp/static/scope.js +90 -0
  73. backlog_mcp/static/statistics.js +87 -0
  74. backlog_mcp/static/task-browser.js +100 -0
  75. backlog_mcp/static/task-pagination.js +94 -0
  76. backlog_mcp/static/task-picker.js +164 -0
  77. backlog_mcp/static/task-table.js +74 -0
  78. backlog_mcp/static/vendor/README.md +12 -0
  79. backlog_mcp/static/vendor/dompurify-LICENSE +202 -0
  80. backlog_mcp/static/vendor/highlight-LICENSE +29 -0
  81. backlog_mcp/static/vendor/highlight-dark.css +118 -0
  82. backlog_mcp/static/vendor/highlight-light.css +118 -0
  83. backlog_mcp/static/vendor/highlight.min.js +1262 -0
  84. backlog_mcp/static/vendor/marked-LICENSE +44 -0
  85. backlog_mcp/static/vendor/marked.esm.js +80 -0
  86. backlog_mcp/static/vendor/marked.esm.js.map +7 -0
  87. backlog_mcp/static/vendor/mermaid-LICENSE +21 -0
  88. backlog_mcp/static/vendor/mermaid.min.js +4376 -0
  89. backlog_mcp/static/vendor/purify.es.mjs +2722 -0
  90. backlog_mcp/static/vendor/purify.es.mjs.map +1 -0
  91. backlog_mcp/transaction.py +47 -0
  92. backlog_mcp/version.py +79 -0
  93. backlog_mcp/webui.py +63 -0
  94. backlog_tiny_mcp-0.34.2.dist-info/METADATA +84 -0
  95. backlog_tiny_mcp-0.34.2.dist-info/RECORD +97 -0
  96. backlog_tiny_mcp-0.34.2.dist-info/WHEEL +4 -0
  97. backlog_tiny_mcp-0.34.2.dist-info/entry_points.txt +4 -0
@@ -0,0 +1,71 @@
1
+ import { el, field, modal, projectRoute } from "./dom.js";
2
+
3
+ export async function createProject({ call, navigate, principal }) {
4
+ const name = el("input", { required: true, maxLength: 200 });
5
+ const description = el("textarea", { rows: 3 });
6
+ const language = el("input", { placeholder: "No preference" });
7
+ const root = el("input", {
8
+ placeholder: "Leave empty for a project without local files",
9
+ pattern: "(/.*)?",
10
+ });
11
+ let created;
12
+ const saved = await modal({
13
+ title: "New project",
14
+ description: `Binding belongs to ${principal}. Enter an absolute path on that computer, not a browser folder. Leave it empty if no local path is needed.`,
15
+ content: [
16
+ field("Name", name),
17
+ field("Description", description),
18
+ field("Preferred language", language),
19
+ field("Directory", root),
20
+ ],
21
+ action: "Create project",
22
+ onSubmit: async () => {
23
+ created = await call("project_save", {
24
+ root: root.value.trim(),
25
+ name: name.value.trim(),
26
+ description: description.value,
27
+ preferred_language: language.value.trim() || null,
28
+ });
29
+ },
30
+ });
31
+ if (saved) navigate(projectRoute(created.full_name));
32
+ }
33
+
34
+ export async function editProject(project, current, { call }) {
35
+ const name = el("input", { required: true, value: current.name });
36
+ const description = el("textarea", { rows: 3, value: current.description || "" });
37
+ const language = el("input", {
38
+ value: current.preferred_language || "",
39
+ placeholder: "No preference",
40
+ });
41
+ let saved;
42
+ await modal({
43
+ title: "Edit project",
44
+ action: "Save changes",
45
+ content: [
46
+ field("Name", name),
47
+ field("Description", description),
48
+ field("Preferred language", language),
49
+ ],
50
+ onSubmit: async () => {
51
+ saved = await call("project_save", {
52
+ project,
53
+ name: name.value.trim(),
54
+ description: description.value,
55
+ preferred_language: language.value.trim() || null,
56
+ });
57
+ },
58
+ });
59
+ return saved;
60
+ }
61
+
62
+ export async function addBinding(project, { call, principal }) {
63
+ const root = el("input", { placeholder: "No local path", pattern: "(/.*)?" });
64
+ return modal({
65
+ title: "Add computer binding",
66
+ description: `This binding belongs to ${principal}. Enter an absolute path on that computer. Other bindings are kept. An empty path means no local files.`,
67
+ content: [field("Directory", root)],
68
+ action: "Add binding",
69
+ onSubmit: () => call("project_save", { project, root: root.value.trim() }),
70
+ });
71
+ }
@@ -0,0 +1,225 @@
1
+ import { editProject, addBinding } from "./project-form.js";
2
+ import { el, button, field, select, projectRoute, modal } from "./dom.js";
3
+
4
+ export async function projectSettings(project, actions) {
5
+ const { call, navigate, principal, notify } = actions;
6
+ const [summary, access] = await Promise.all([
7
+ call("project_board", { project }),
8
+ call("project_members", { project }),
9
+ ]);
10
+ const title = el("h1", {}, summary.project.name);
11
+ const description = el("p", { class: "muted" }, summary.project.description || "No description.");
12
+ const language = el(
13
+ "p",
14
+ {},
15
+ `Preferred language: ${summary.project.preferred_language || "No preference"}`,
16
+ );
17
+ const owner = summary.project.role === "owner";
18
+ const members = el("div", { class: "project-members" });
19
+ const bindings = el("div", { class: "project-bindings" });
20
+ let disposed = false;
21
+ function show(data) {
22
+ if (disposed) return;
23
+ members.replaceChildren(
24
+ ...data.items.map((member) =>
25
+ el(
26
+ "div",
27
+ { class: "member-row" },
28
+ el("strong", {}, member.principal),
29
+ el("span", { class: "tag" }, member.role),
30
+ owner && member.role !== "owner" ? button("Change role", () => share(member)) : null,
31
+ ),
32
+ ),
33
+ );
34
+ bindings.replaceChildren(
35
+ ...(data.roots || []).map((binding) => {
36
+ const colon = binding.indexOf(":");
37
+ const actor = binding.slice(0, colon);
38
+ const at = actor.lastIndexOf("@");
39
+ return el(
40
+ "div",
41
+ { class: "binding-row" },
42
+ el(
43
+ "div",
44
+ {},
45
+ el("span", { class: "muted" }, "Principal"),
46
+ el("strong", {}, decodeURIComponent(actor.slice(0, at))),
47
+ ),
48
+ el(
49
+ "div",
50
+ {},
51
+ el("span", { class: "muted" }, "Computer"),
52
+ el("span", {}, decodeURIComponent(actor.slice(at + 1))),
53
+ ),
54
+ el(
55
+ "div",
56
+ {},
57
+ el("span", { class: "muted" }, "Path"),
58
+ el("code", {}, binding.slice(colon + 1) || "No local path"),
59
+ ),
60
+ );
61
+ }),
62
+ );
63
+ if (!bindings.childElementCount)
64
+ bindings.append(el("p", { class: "muted" }, "No computer bindings yet."));
65
+ }
66
+ async function share(member) {
67
+ const username = el("input", {
68
+ required: true,
69
+ value: member?.principal || "",
70
+ placeholder: "Username or user@computer",
71
+ readOnly: Boolean(member),
72
+ });
73
+ const role = select(["reader", "editor"], member?.role || "reader");
74
+ await modal({
75
+ title: member ? "Change project role" : "Share project",
76
+ description:
77
+ "Readers can view the project. Editors can change its content. The user must have an account on this server.",
78
+ content: [field("Principal", username), field("Role", role)],
79
+ action: member ? "Save role" : "Grant access",
80
+ onSubmit: async () => {
81
+ const data = await call("project_share", {
82
+ project,
83
+ principal: username.value.trim(),
84
+ role: role.value,
85
+ });
86
+ show(data);
87
+ },
88
+ });
89
+ }
90
+ function changeView(view) {
91
+ try {
92
+ localStorage.setItem(
93
+ `backlog:board-view:${document.documentElement.dataset.endpoint}:${principal}`,
94
+ view,
95
+ );
96
+ } catch {
97
+ /* Explicit navigation still works without browser storage. */
98
+ }
99
+ navigate(projectRoute(project, new URLSearchParams({ view })));
100
+ }
101
+ const active = button("Settings", () => {});
102
+ active.setAttribute("aria-pressed", "true");
103
+ const archiveState = el(
104
+ "p",
105
+ {},
106
+ summary.project.archived ? "Archived project" : "Active project",
107
+ );
108
+ const archive = button(
109
+ summary.project.archived ? "Restore project" : "Archive project",
110
+ async () => {
111
+ archive.disabled = true;
112
+ try {
113
+ const saved = await call("project_save", { project, archived: !summary.project.archived });
114
+ summary.project.archived = saved.archived;
115
+ archive.textContent = saved.archived ? "Restore project" : "Archive project";
116
+ archiveState.textContent = saved.archived ? "Archived project" : "Active project";
117
+ } catch (error) {
118
+ notify(error);
119
+ } finally {
120
+ archive.disabled = false;
121
+ }
122
+ },
123
+ );
124
+ const remove = button(
125
+ "Delete project",
126
+ async () => {
127
+ remove.disabled = true;
128
+ try {
129
+ const result = await call("project_delete", { project });
130
+ if (result.deleted) navigate("/ui/");
131
+ } catch (error) {
132
+ notify(error);
133
+ } finally {
134
+ remove.disabled = false;
135
+ }
136
+ },
137
+ "destructive",
138
+ );
139
+ const page = el(
140
+ "section",
141
+ { class: "project-settings" },
142
+ el("div", { class: "eyebrow" }, "Project settings"),
143
+ title,
144
+ el(
145
+ "nav",
146
+ { class: "view-switch", "aria-label": "Project view" },
147
+ button("Kanban", () => changeView("kanban")),
148
+ button("Table", () => changeView("table")),
149
+ active,
150
+ ),
151
+ el(
152
+ "section",
153
+ { class: "panel" },
154
+ el(
155
+ "div",
156
+ { class: "row spread" },
157
+ el("h2", {}, "Project info"),
158
+ summary.project.role !== "reader"
159
+ ? button("Edit project", async () => {
160
+ const saved = await editProject(project, summary.project, actions);
161
+ if (!saved || disposed) return;
162
+ Object.assign(summary.project, saved);
163
+ title.textContent = saved.name;
164
+ description.textContent = saved.description || "No description.";
165
+ language.textContent = `Preferred language: ${saved.preferred_language || "No preference"}`;
166
+ })
167
+ : null,
168
+ ),
169
+ el("p", {}, el("strong", {}, project)),
170
+ description,
171
+ language,
172
+ el("p", {}, `Your role: ${summary.project.role}`),
173
+ archiveState,
174
+ ),
175
+ el(
176
+ "section",
177
+ { class: "panel" },
178
+ el(
179
+ "div",
180
+ { class: "row spread" },
181
+ el("h2", {}, "Members"),
182
+ owner ? button("Share project", () => share(), "primary") : null,
183
+ ),
184
+ members,
185
+ owner ? null : el("p", { class: "muted" }, "Only the project owner can manage access."),
186
+ ),
187
+ el(
188
+ "section",
189
+ { class: "panel" },
190
+ el(
191
+ "div",
192
+ { class: "row spread" },
193
+ el("h2", {}, "Computer bindings"),
194
+ button("Add binding", async () => {
195
+ if (await addBinding(project, actions)) {
196
+ try {
197
+ show(await call("project_members", { project }));
198
+ } catch (error) {
199
+ notify(error);
200
+ }
201
+ }
202
+ }),
203
+ ),
204
+ bindings,
205
+ ),
206
+ summary.project.role !== "reader"
207
+ ? el(
208
+ "section",
209
+ { class: "panel" },
210
+ el("h2", {}, "Project lifecycle"),
211
+ el(
212
+ "p",
213
+ { class: "muted" },
214
+ "Archiving keeps tasks and notes. Deletion permanently removes the project and all its tasks and notes.",
215
+ ),
216
+ el("div", { class: "row" }, archive, owner ? remove : null),
217
+ )
218
+ : null,
219
+ );
220
+ page.dispose = () => {
221
+ disposed = true;
222
+ };
223
+ show(access);
224
+ return page;
225
+ }
@@ -0,0 +1,90 @@
1
+ import { el, field, select } from "./dom.js";
2
+
3
+ export function scopeKind(params) {
4
+ const kind = params.get("scope");
5
+ if (["all", "current", "computer", "project"].includes(kind)) return kind;
6
+ return params.get("project") ? "project" : params.get("computer") ? "computer" : "all";
7
+ }
8
+ export function scopeArgs(params) {
9
+ switch (scopeKind(params)) {
10
+ case "project":
11
+ if (!params.get("project")) throw new Error("Choose a project.");
12
+ return { project: params.get("project") };
13
+ case "current":
14
+ return { all_projects: true };
15
+ case "computer":
16
+ if (!params.get("computer")?.trim()) throw new Error("Enter a computer name.");
17
+ return { computer: params.get("computer").trim() };
18
+ default:
19
+ return { all_computers: true };
20
+ }
21
+ }
22
+ export function scopeLabel(params, principal) {
23
+ switch (scopeKind(params)) {
24
+ case "project":
25
+ return `Project: ${params.get("project")}`;
26
+ case "current":
27
+ return `Projects on this computer (${principal})`;
28
+ case "computer":
29
+ return `Projects on computer: ${params.get("computer")}`;
30
+ default:
31
+ return "All accessible projects on all computers";
32
+ }
33
+ }
34
+ export function scopeControls(params, projects, { allowProject = true } = {}) {
35
+ const kinds = allowProject
36
+ ? ["all", "current", "computer", "project"]
37
+ : ["all", "current", "computer"];
38
+ const mode = select(kinds, scopeKind(params), { "aria-label": "Scope" });
39
+ const labels = {
40
+ all: "All computers",
41
+ current: "This computer",
42
+ computer: "Named computer",
43
+ project: "One project",
44
+ };
45
+ for (const option of mode.options) option.textContent = labels[option.value];
46
+ const project = select(
47
+ [
48
+ "",
49
+ ...new Set([
50
+ ...projects.map((p) => p.full_name),
51
+ ...(params.get("project") ? [params.get("project")] : []),
52
+ ]),
53
+ ],
54
+ params.get("project") || "",
55
+ { "aria-label": "Scope project" },
56
+ );
57
+ project.options[0].textContent = "Choose a project";
58
+ const computer = el("input", {
59
+ value: params.get("computer") || "",
60
+ "aria-label": "Scope computer",
61
+ placeholder: "Computer name",
62
+ });
63
+ const projectField = field("Project", project),
64
+ computerField = field("Computer", computer);
65
+ const element = el(
66
+ "div",
67
+ { class: "scope-controls" },
68
+ field("Scope", mode),
69
+ projectField,
70
+ computerField,
71
+ );
72
+ function sync() {
73
+ projectField.hidden = project.disabled = mode.value !== "project";
74
+ project.required = !project.disabled;
75
+ computerField.hidden = computer.disabled = mode.value !== "computer";
76
+ computer.required = !computer.disabled;
77
+ }
78
+ mode.onchange = sync;
79
+ sync();
80
+ return {
81
+ element,
82
+ apply(params) {
83
+ for (const key of ["scope", "project", "computer", "offset"]) params.delete(key);
84
+ params.set("scope", mode.value);
85
+ if (mode.value === "project") params.set("project", project.value);
86
+ if (mode.value === "computer") params.set("computer", computer.value.trim());
87
+ return params;
88
+ },
89
+ };
90
+ }
@@ -0,0 +1,87 @@
1
+ import { el, link } from "./dom.js";
2
+ import { scopeArgs, scopeControls, scopeLabel } from "./scope.js";
3
+
4
+ export async function statisticsPage(target, { call, navigate, principal }) {
5
+ const [stats, projects] = await Promise.all([
6
+ call("stats", scopeArgs(target.params)),
7
+ call("project_list", { all_computers: true }),
8
+ ]);
9
+ const scope = scopeControls(target.params, projects.items);
10
+ const breakdown = (title, values) =>
11
+ el(
12
+ "section",
13
+ { class: "panel" },
14
+ el("h2", {}, title),
15
+ Object.keys(values).length
16
+ ? el(
17
+ "dl",
18
+ { class: "stats-breakdown" },
19
+ ...Object.entries(values).flatMap(([key, count]) => [
20
+ el("dt", {}, key),
21
+ el("dd", {}, String(count)),
22
+ ]),
23
+ )
24
+ : el("p", { class: "muted" }, "No data."),
25
+ );
26
+ return el(
27
+ "section",
28
+ { class: "statistics-page" },
29
+ el(
30
+ "div",
31
+ { class: "row spread" },
32
+ el("h1", {}, "Statistics"),
33
+ link("Projects", "/ui/", "button"),
34
+ ),
35
+ el(
36
+ "form",
37
+ {
38
+ class: "row",
39
+ onsubmit: (event) => {
40
+ event.preventDefault();
41
+ const p = scope.apply(new URLSearchParams({ view: "stats" }));
42
+ navigate(`/ui/?${p}`);
43
+ },
44
+ },
45
+ scope.element,
46
+ el("button", { type: "submit" }, "Apply scope"),
47
+ ),
48
+ el("p", { class: "muted scope-description" }, scopeLabel(target.params, principal)),
49
+ el(
50
+ "div",
51
+ { class: "stats-totals" },
52
+ ...[
53
+ ["Total tasks", stats.total],
54
+ ["Open", stats.open],
55
+ ["Closed", stats.closed],
56
+ ["Notes", stats.memory],
57
+ ].map(([title, count]) =>
58
+ el("div", { class: "panel" }, el("span", {}, title), el("strong", {}, String(count))),
59
+ ),
60
+ ),
61
+ el(
62
+ "p",
63
+ { class: "muted" },
64
+ "Counts include all matches, not just loaded pages. Closed means done or cancelled; deleted tasks are counted separately by status. Notes include shared notes.",
65
+ ),
66
+ el(
67
+ "div",
68
+ { class: "stats-groups" },
69
+ breakdown("By status", stats.by_status),
70
+ breakdown("By priority", stats.by_priority),
71
+ ),
72
+ el(
73
+ "section",
74
+ { class: "panel" },
75
+ el("h2", {}, "Tags"),
76
+ ...(stats.tags.length
77
+ ? stats.tags.map((tag) => {
78
+ const params = new URLSearchParams(target.params);
79
+ params.set("view", "tasks");
80
+ params.set("status", "all");
81
+ params.set("tag", tag);
82
+ return link(tag, `/ui/?${params}`, "tag");
83
+ })
84
+ : [el("p", { class: "muted" }, "No tags.")]),
85
+ ),
86
+ );
87
+ }
@@ -0,0 +1,100 @@
1
+ import { el, field, select, link } from "./dom.js";
2
+ import { scopeArgs, scopeControls, scopeLabel } from "./scope.js";
3
+ import { taskTable } from "./task-table.js";
4
+ import { taskPagination } from "./task-pagination.js";
5
+
6
+ export async function taskBrowser(target, { call, navigate, principal }) {
7
+ const p = target.params;
8
+ const statuses = ["todo", "doing", "blocked", "done", "cancelled", "deleted"];
9
+ const args = {
10
+ ...scopeArgs(p),
11
+ limit: 50,
12
+ order: p.get("order") === "recent" ? "recent" : "backlog",
13
+ };
14
+ if (p.get("status") === "all") args.status = statuses;
15
+ else if (statuses.includes(p.get("status"))) args.status = [p.get("status")];
16
+ if (["urgent", "high", "normal", "low"].includes(p.get("priority")))
17
+ args.priority = p.get("priority");
18
+ if (p.get("tag")) args.tag = p.get("tag");
19
+ const [data, projects] = await Promise.all([
20
+ call("task_list", args),
21
+ call("project_list", { all_computers: true }),
22
+ ]);
23
+ const scope = scopeControls(p, projects.items);
24
+ const status = select(["", "all", ...statuses], p.get("status") || "", {
25
+ "aria-label": "Task status",
26
+ });
27
+ status.options[0].textContent = "Open tasks";
28
+ status.options[1].textContent = "All statuses";
29
+ const priority = select(["", "urgent", "high", "normal", "low"], p.get("priority") || "", {
30
+ "aria-label": "Task priority",
31
+ });
32
+ priority.options[0].textContent = "All priorities";
33
+ const tag = el("input", {
34
+ value: p.get("tag") || "",
35
+ placeholder: "Any tag",
36
+ "aria-label": "Task tag",
37
+ });
38
+ const order = select(["backlog", "recent"], args.order, { "aria-label": "Task order" });
39
+ const count = el("p", { class: "muted" });
40
+ const table = taskTable([], { showProject: true });
41
+ const pager = taskPagination({
42
+ sources: [{ args, page: data }],
43
+ root: table,
44
+ call,
45
+ append: (items) => table.appendTasks(items),
46
+ changed: (shown, total) => {
47
+ count.textContent = `${shown} of ${total} tasks shown`;
48
+ },
49
+ });
50
+ table.append(pager.sentinel);
51
+ const page = el(
52
+ "section",
53
+ { class: "board-page task-browser" },
54
+ el(
55
+ "div",
56
+ {},
57
+ el(
58
+ "div",
59
+ { class: "row spread" },
60
+ el("h1", {}, "All tasks"),
61
+ link("Projects", "/ui/", "button"),
62
+ ),
63
+ el(
64
+ "form",
65
+ {
66
+ class: "task-browser-filters",
67
+ onsubmit: (event) => {
68
+ event.preventDefault();
69
+ const params = scope.apply(new URLSearchParams({ view: "tasks" }));
70
+ for (const [key, value] of Object.entries({
71
+ status: status.value,
72
+ priority: priority.value,
73
+ tag: tag.value.trim(),
74
+ order: order.value,
75
+ }))
76
+ if (value) params.set(key, value);
77
+ navigate(`/ui/?${params}`);
78
+ },
79
+ },
80
+ scope.element,
81
+ field("Status", status),
82
+ field("Priority", priority),
83
+ field("Tag", tag),
84
+ field("Order", order),
85
+ el("button", { type: "submit" }, "Apply filters"),
86
+ ),
87
+ el("p", { class: "muted" }, scopeLabel(p, principal)),
88
+ count,
89
+ ),
90
+ el(
91
+ "section",
92
+ { class: "board-results" },
93
+ table,
94
+ el("p", { class: "muted" }, "Tasks load as you scroll. Filters apply to every page."),
95
+ ),
96
+ );
97
+ page.mount = () => pager.mount();
98
+ page.dispose = () => pager.dispose();
99
+ return page;
100
+ }
@@ -0,0 +1,94 @@
1
+ import { el, button } from "./dom.js";
2
+
3
+ // Sources are consumed in order, so completed tasks never precede unloaded open tasks.
4
+ export function taskPagination({ sources, root, call, append, changed }) {
5
+ const seen = new Set();
6
+ let index = 0,
7
+ loading = false,
8
+ disposed = false;
9
+ const streams = sources.map(({ args, page }) => ({
10
+ args,
11
+ buffer: page.items,
12
+ offset: page.items.length,
13
+ total: page.count,
14
+ }));
15
+ const sentinel = el("div", {
16
+ class: "task-pagination",
17
+ role: "status",
18
+ "aria-live": "polite",
19
+ });
20
+ const observer = new IntersectionObserver(
21
+ (entries) => {
22
+ if (entries.some((entry) => entry.isIntersecting)) loadMore();
23
+ },
24
+ { root, rootMargin: "0px 0px 200px 0px" },
25
+ );
26
+ function flush() {
27
+ while (index < streams.length) {
28
+ const stream = streams[index];
29
+ const fresh = stream.buffer.filter((task) => {
30
+ if (seen.has(task.id)) return false;
31
+ seen.add(task.id);
32
+ return true;
33
+ });
34
+ append(fresh);
35
+ stream.buffer = [];
36
+ if (stream.offset < stream.total) break;
37
+ index++;
38
+ }
39
+ const total = streams.reduce((sum, stream) => sum + stream.total, 0);
40
+ changed(seen.size, total);
41
+ sentinel.replaceChildren(
42
+ el(
43
+ "span",
44
+ { class: "muted" },
45
+ index < streams.length
46
+ ? `${seen.size} of ${total} tasks · Scroll for more`
47
+ : seen.size
48
+ ? `${seen.size} tasks · All loaded`
49
+ : "No tasks",
50
+ ),
51
+ );
52
+ }
53
+ async function loadMore() {
54
+ if (loading || disposed || index >= streams.length || !sentinel.isConnected) return;
55
+ loading = true;
56
+ observer.unobserve(sentinel);
57
+ root.setAttribute("aria-busy", "true");
58
+ sentinel.replaceChildren(el("span", {}, "Loading more tasks…"));
59
+ const stream = streams[index];
60
+ try {
61
+ const page = await call("task_list", {
62
+ ...stream.args,
63
+ offset: stream.offset,
64
+ });
65
+ if (disposed || !sentinel.isConnected) return;
66
+ stream.offset += page.items.length;
67
+ stream.total = page.items.length ? page.count : stream.offset;
68
+ stream.buffer = page.items;
69
+ flush();
70
+ } catch (error) {
71
+ if (!disposed && sentinel.isConnected)
72
+ sentinel.replaceChildren(
73
+ el("span", { class: "error" }, `Could not load more tasks: ${error.message}`),
74
+ button("Retry", loadMore),
75
+ );
76
+ return;
77
+ } finally {
78
+ loading = false;
79
+ root.removeAttribute("aria-busy");
80
+ }
81
+ if (!disposed && index < streams.length) observer.observe(sentinel);
82
+ }
83
+ flush();
84
+ return {
85
+ sentinel,
86
+ mount() {
87
+ if (!disposed && index < streams.length) observer.observe(sentinel);
88
+ },
89
+ dispose() {
90
+ disposed = true;
91
+ observer.disconnect();
92
+ },
93
+ };
94
+ }