backlog-tiny-mcp 0.35.0__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.35.0.dist-info/METADATA +84 -0
- backlog_tiny_mcp-0.35.0.dist-info/RECORD +97 -0
- backlog_tiny_mcp-0.35.0.dist-info/WHEEL +4 -0
- backlog_tiny_mcp-0.35.0.dist-info/entry_points.txt +4 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { el } from "./dom.js";
|
|
2
|
+
import DOMPurify from "./vendor/purify.es.mjs";
|
|
3
|
+
|
|
4
|
+
let library;
|
|
5
|
+
let sequence = 0;
|
|
6
|
+
let queue = Promise.resolve();
|
|
7
|
+
const theme = matchMedia("(prefers-color-scheme: dark)");
|
|
8
|
+
function loadMermaid() {
|
|
9
|
+
library ||= new Promise((resolve, reject) => {
|
|
10
|
+
const script = document.createElement("script");
|
|
11
|
+
script.src = new URL("./vendor/mermaid.min.js", import.meta.url).href;
|
|
12
|
+
script.onload = () => resolve(globalThis.mermaid);
|
|
13
|
+
script.onerror = () => {
|
|
14
|
+
script.remove();
|
|
15
|
+
library = null;
|
|
16
|
+
reject(new Error("Could not load Mermaid"));
|
|
17
|
+
};
|
|
18
|
+
document.head.append(script);
|
|
19
|
+
});
|
|
20
|
+
return library;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class Diagram extends HTMLElement {
|
|
24
|
+
connectedCallback() {
|
|
25
|
+
if (!this.source) return;
|
|
26
|
+
this.onTheme = () => this.render();
|
|
27
|
+
theme.addEventListener("change", this.onTheme);
|
|
28
|
+
this.render();
|
|
29
|
+
}
|
|
30
|
+
disconnectedCallback() {
|
|
31
|
+
this.generation = (this.generation || 0) + 1;
|
|
32
|
+
theme.removeEventListener("change", this.onTheme);
|
|
33
|
+
}
|
|
34
|
+
render() {
|
|
35
|
+
const generation = (this.generation = (this.generation || 0) + 1);
|
|
36
|
+
const source = this.source;
|
|
37
|
+
const details = el(
|
|
38
|
+
"details",
|
|
39
|
+
{ class: "diagram-source" },
|
|
40
|
+
el("summary", {}, "Diagram source"),
|
|
41
|
+
el("pre", {}, el("code", {}, source)),
|
|
42
|
+
);
|
|
43
|
+
const status = el("p", { class: "muted", role: "status" }, "Rendering diagram…");
|
|
44
|
+
this.replaceChildren(status, details);
|
|
45
|
+
this.setAttribute("aria-busy", "true");
|
|
46
|
+
const current = () => this.isConnected && generation === this.generation;
|
|
47
|
+
// Mermaid configuration is global. Serialize initialization and rendering across blocks.
|
|
48
|
+
queue = queue.then(async () => {
|
|
49
|
+
if (!current()) return;
|
|
50
|
+
try {
|
|
51
|
+
const mermaid = await loadMermaid();
|
|
52
|
+
if (!current()) return;
|
|
53
|
+
mermaid.initialize({
|
|
54
|
+
startOnLoad: false,
|
|
55
|
+
securityLevel: "strict",
|
|
56
|
+
suppressErrorRendering: true,
|
|
57
|
+
theme: theme.matches ? "dark" : "default",
|
|
58
|
+
fontFamily: "system-ui, sans-serif",
|
|
59
|
+
htmlLabels: false,
|
|
60
|
+
flowchart: { htmlLabels: false },
|
|
61
|
+
layout: "dagre",
|
|
62
|
+
maxTextSize: 50000,
|
|
63
|
+
maxEdges: 500,
|
|
64
|
+
secure: [
|
|
65
|
+
"secure",
|
|
66
|
+
"securityLevel",
|
|
67
|
+
"startOnLoad",
|
|
68
|
+
"suppressErrorRendering",
|
|
69
|
+
"maxTextSize",
|
|
70
|
+
"maxEdges",
|
|
71
|
+
"htmlLabels",
|
|
72
|
+
"flowchart",
|
|
73
|
+
"theme",
|
|
74
|
+
"themeVariables",
|
|
75
|
+
"themeCSS",
|
|
76
|
+
"fontFamily",
|
|
77
|
+
"layout",
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
const { svg } = await mermaid.render(`backlog-diagram-${++sequence}`, source);
|
|
81
|
+
if (!current()) return;
|
|
82
|
+
const safe = DOMPurify.sanitize(svg, {
|
|
83
|
+
USE_PROFILES: { svg: true, svgFilters: true },
|
|
84
|
+
FORBID_TAGS: ["foreignObject"],
|
|
85
|
+
});
|
|
86
|
+
// An SVG image cannot execute scripts or turn diagram links into page navigation.
|
|
87
|
+
const img = el("img", {
|
|
88
|
+
class: "diagram-image",
|
|
89
|
+
alt: "Mermaid diagram. Source follows below.",
|
|
90
|
+
src: "data:image/svg+xml;charset=utf-8," + encodeURIComponent(safe),
|
|
91
|
+
});
|
|
92
|
+
const svgDocument = new DOMParser().parseFromString(safe, "image/svg+xml");
|
|
93
|
+
const viewBox = svgDocument.documentElement
|
|
94
|
+
.getAttribute("viewBox")
|
|
95
|
+
?.split(/[ ,]+/)
|
|
96
|
+
.map(Number);
|
|
97
|
+
if (viewBox?.length === 4 && Number.isFinite(viewBox[2]) && viewBox[2] > 0) {
|
|
98
|
+
img.width = Math.ceil(viewBox[2]);
|
|
99
|
+
svgDocument.documentElement.setAttribute("width", String(img.width));
|
|
100
|
+
svgDocument.documentElement.setAttribute("height", String(Math.ceil(viewBox[3])));
|
|
101
|
+
img.src =
|
|
102
|
+
"data:image/svg+xml;charset=utf-8," +
|
|
103
|
+
encodeURIComponent(new XMLSerializer().serializeToString(svgDocument));
|
|
104
|
+
}
|
|
105
|
+
status.replaceWith(
|
|
106
|
+
el(
|
|
107
|
+
"div",
|
|
108
|
+
{
|
|
109
|
+
class: "diagram-output",
|
|
110
|
+
tabIndex: 0,
|
|
111
|
+
role: "region",
|
|
112
|
+
"aria-label": "Mermaid diagram; scroll to see more",
|
|
113
|
+
},
|
|
114
|
+
img,
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
} catch {
|
|
118
|
+
if (!current()) return;
|
|
119
|
+
status.textContent = "Could not render this diagram. Check its Mermaid syntax below.";
|
|
120
|
+
status.className = "error";
|
|
121
|
+
details.open = true;
|
|
122
|
+
} finally {
|
|
123
|
+
if (current()) this.removeAttribute("aria-busy");
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
customElements.define("backlog-diagram", Diagram);
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export function el(tag, attributes = {}, ...children) {
|
|
2
|
+
const node = document.createElement(tag);
|
|
3
|
+
for (const [name, value] of Object.entries(attributes)) {
|
|
4
|
+
if (name.startsWith("on")) node.addEventListener(name.slice(2), value);
|
|
5
|
+
else if (name === "class") node.className = value;
|
|
6
|
+
else if (name in node) node[name] = value;
|
|
7
|
+
else node.setAttribute(name, value);
|
|
8
|
+
}
|
|
9
|
+
node.append(...children.filter((child) => child !== null && child !== undefined));
|
|
10
|
+
return node;
|
|
11
|
+
}
|
|
12
|
+
export const button = (text, action, className = "") =>
|
|
13
|
+
el("button", { type: "button", class: className, onclick: action }, text);
|
|
14
|
+
export const link = (text, href, className = "") => el("a", { href, class: className }, text);
|
|
15
|
+
export const select = (values, value, attributes = {}) => {
|
|
16
|
+
const node = el("select", attributes, ...values.map((v) => el("option", { value: v }, v)));
|
|
17
|
+
node.value = value;
|
|
18
|
+
return node;
|
|
19
|
+
};
|
|
20
|
+
export const field = (text, control) => el("label", {}, text, control);
|
|
21
|
+
export const date = (value) => (value ? new Date(value * 1000).toLocaleString() : "—");
|
|
22
|
+
export const projectRoute = (project, filters = new URLSearchParams()) => {
|
|
23
|
+
const params = new URLSearchParams(filters);
|
|
24
|
+
params.set("project", project);
|
|
25
|
+
return "/ui/?" + params;
|
|
26
|
+
};
|
|
27
|
+
export const taskRoute = (id, edit = false) => `/ui/${edit ? "?view=edit" : ""}#${id}`;
|
|
28
|
+
export const noteRoute = (id) => `/ui/#note${id}`;
|
|
29
|
+
export function memoryRoute(project = "", filters = new URLSearchParams()) {
|
|
30
|
+
const params = new URLSearchParams(filters);
|
|
31
|
+
const note = params.get("note");
|
|
32
|
+
params.delete("note");
|
|
33
|
+
params.set("view", "memory");
|
|
34
|
+
if (project) params.set("project", project);
|
|
35
|
+
else params.delete("project");
|
|
36
|
+
return "/ui/?" + params + (note ? `#note${note}` : "");
|
|
37
|
+
}
|
|
38
|
+
export function route(href = location.href) {
|
|
39
|
+
const url = new URL(href, "https://backlog.invalid/ui/");
|
|
40
|
+
const params = url.searchParams;
|
|
41
|
+
// Redirect saved links from the original hash router.
|
|
42
|
+
if (url.hash.startsWith("#/")) {
|
|
43
|
+
const [path, query = ""] = url.hash.slice(1).split("?");
|
|
44
|
+
const old = new URLSearchParams(query);
|
|
45
|
+
const task = path.match(/^\/t\/(\d+)(\/edit)?$/);
|
|
46
|
+
if (task) return { redirect: taskRoute(task[1], Boolean(task[2])) };
|
|
47
|
+
if (path === "/t/new") {
|
|
48
|
+
old.set("view", "new");
|
|
49
|
+
return { redirect: "/ui/?" + old };
|
|
50
|
+
}
|
|
51
|
+
const project = path.match(/^\/p\/([^/]+)\/([^/]+)$/);
|
|
52
|
+
if (project) {
|
|
53
|
+
try {
|
|
54
|
+
return {
|
|
55
|
+
redirect: projectRoute(
|
|
56
|
+
decodeURIComponent(project[1]) + "/" + decodeURIComponent(project[2]),
|
|
57
|
+
old,
|
|
58
|
+
),
|
|
59
|
+
};
|
|
60
|
+
} catch {
|
|
61
|
+
return { kind: "missing", params };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (path === "/") return { redirect: "/ui/" + (old.size ? "?" + old : "") };
|
|
65
|
+
}
|
|
66
|
+
const memory = url.hash.match(/^#note([1-9]\d*)$/);
|
|
67
|
+
if (memory && Number.isSafeInteger(Number(memory[1])))
|
|
68
|
+
return { kind: "memory", project: params.get("project") || "", id: Number(memory[1]), params };
|
|
69
|
+
const task = url.hash.match(/^#([1-9]\d*)$/);
|
|
70
|
+
if (task && Number.isSafeInteger(Number(task[1])))
|
|
71
|
+
return { kind: params.get("view") === "edit" ? "edit" : "task", id: Number(task[1]), params };
|
|
72
|
+
if (url.hash) return { kind: "missing", params };
|
|
73
|
+
if (params.get("view") === "memory") {
|
|
74
|
+
const note = params.get("note");
|
|
75
|
+
if (note !== null && (!/^[1-9]\d*$/.test(note) || !Number.isSafeInteger(Number(note))))
|
|
76
|
+
return { kind: "missing", params };
|
|
77
|
+
if (note) return { redirect: memoryRoute(params.get("project") || "", params) };
|
|
78
|
+
return {
|
|
79
|
+
kind: "memory",
|
|
80
|
+
project: params.get("project") || "",
|
|
81
|
+
id: note ? Number(note) : null,
|
|
82
|
+
params,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
if (params.get("view") === "tasks") return { kind: "tasks", project: params.get("project") || "", params };
|
|
86
|
+
if (params.get("view") === "stats") return { kind: "stats", project: params.get("project") || "", params };
|
|
87
|
+
if (params.get("view") === "assigned") return { kind: "assigned", params };
|
|
88
|
+
if (params.get("view") === "new") return { kind: "new", params };
|
|
89
|
+
if (params.get("view") === "settings" && params.get("project"))
|
|
90
|
+
return { kind: "settings", project: params.get("project"), params };
|
|
91
|
+
if (params.get("project")) return { kind: "board", project: params.get("project"), params };
|
|
92
|
+
return { kind: "projects", params };
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Accessible modal with one async action and an inline error state. */
|
|
96
|
+
export function modal({
|
|
97
|
+
title,
|
|
98
|
+
description = "",
|
|
99
|
+
content = [],
|
|
100
|
+
action = "Confirm",
|
|
101
|
+
danger = false,
|
|
102
|
+
onSubmit = async () => {},
|
|
103
|
+
}) {
|
|
104
|
+
return new Promise((resolve) => {
|
|
105
|
+
const heading = el("h2", { id: "modal-title" }, title);
|
|
106
|
+
const error = el("p", { class: "error modal-error", role: "alert", hidden: true });
|
|
107
|
+
const submit = el(
|
|
108
|
+
"button",
|
|
109
|
+
{ type: "submit", class: danger ? "primary destructive" : "primary" },
|
|
110
|
+
action,
|
|
111
|
+
);
|
|
112
|
+
const cancel = button("Cancel", () => dialog.close());
|
|
113
|
+
const form = el(
|
|
114
|
+
"form",
|
|
115
|
+
{ class: "modal-form" },
|
|
116
|
+
el(
|
|
117
|
+
"div",
|
|
118
|
+
{ class: "modal-heading" },
|
|
119
|
+
heading,
|
|
120
|
+
description ? el("p", { class: "muted" }, description) : null,
|
|
121
|
+
),
|
|
122
|
+
el("div", { class: "modal-content" }, ...content),
|
|
123
|
+
error,
|
|
124
|
+
el("div", { class: "modal-actions" }, cancel, submit),
|
|
125
|
+
);
|
|
126
|
+
const dialog = el("dialog", { class: "action-dialog", "aria-labelledby": "modal-title" }, form);
|
|
127
|
+
let confirmed = false,
|
|
128
|
+
pending = false;
|
|
129
|
+
form.onsubmit = async (event) => {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
if (pending) return;
|
|
132
|
+
pending = true;
|
|
133
|
+
submit.disabled = cancel.disabled = true;
|
|
134
|
+
error.hidden = true;
|
|
135
|
+
try {
|
|
136
|
+
await onSubmit();
|
|
137
|
+
confirmed = true;
|
|
138
|
+
dialog.close();
|
|
139
|
+
} catch (failure) {
|
|
140
|
+
error.textContent = failure.message;
|
|
141
|
+
error.hidden = false;
|
|
142
|
+
} finally {
|
|
143
|
+
pending = false;
|
|
144
|
+
submit.disabled = cancel.disabled = false;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
dialog.addEventListener("cancel", (event) => {
|
|
148
|
+
if (pending) event.preventDefault();
|
|
149
|
+
});
|
|
150
|
+
dialog.addEventListener(
|
|
151
|
+
"close",
|
|
152
|
+
() => {
|
|
153
|
+
dialog.remove();
|
|
154
|
+
resolve(confirmed);
|
|
155
|
+
},
|
|
156
|
+
{ once: true },
|
|
157
|
+
);
|
|
158
|
+
document.body.append(dialog);
|
|
159
|
+
dialog.showModal();
|
|
160
|
+
(danger ? cancel : form.querySelector("input,select,textarea") || cancel).focus();
|
|
161
|
+
});
|
|
162
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// A reload keeps its edit marker. Other tabs must acquire their own claim.
|
|
2
|
+
export function editClaim(task, { call, principal, endpoint = "/mcp" }) {
|
|
3
|
+
const lockKey = `backlog:edit-claim:${endpoint}:${principal}:${task.id}`;
|
|
4
|
+
const tabKey = "backlog:edit-tab";
|
|
5
|
+
let tab = sessionStorage.getItem(tabKey);
|
|
6
|
+
if (!tab) sessionStorage.setItem(tabKey, (tab = crypto.randomUUID()));
|
|
7
|
+
const key = `${lockKey}:${tab}`;
|
|
8
|
+
let lease = null,
|
|
9
|
+
unlock = null,
|
|
10
|
+
lockReady = null,
|
|
11
|
+
closing = null;
|
|
12
|
+
function stored() {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.parse(localStorage.getItem(key));
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
async function lock() {
|
|
20
|
+
if (!lockReady)
|
|
21
|
+
lockReady = new Promise((resolve, reject) => {
|
|
22
|
+
if (!navigator.locks)
|
|
23
|
+
return reject(new Error("This browser needs HTTPS to protect concurrent editing."));
|
|
24
|
+
navigator.locks
|
|
25
|
+
.request(lockKey, { ifAvailable: true }, async (held) => {
|
|
26
|
+
if (!held) {
|
|
27
|
+
reject(new Error("This task is open in another browser tab."));
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
await new Promise((done) => {
|
|
31
|
+
unlock = done;
|
|
32
|
+
resolve();
|
|
33
|
+
});
|
|
34
|
+
})
|
|
35
|
+
.catch(reject);
|
|
36
|
+
});
|
|
37
|
+
try {
|
|
38
|
+
await lockReady;
|
|
39
|
+
} catch (error) {
|
|
40
|
+
lockReady = null;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function clear() {
|
|
45
|
+
if (stored()?.token === lease?.token) localStorage.removeItem(key);
|
|
46
|
+
lease = null;
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
get token() {
|
|
50
|
+
return lease?.token;
|
|
51
|
+
},
|
|
52
|
+
async acquire(current) {
|
|
53
|
+
await lock();
|
|
54
|
+
const previous = stored();
|
|
55
|
+
if (previous?.tab === tab && current.assigned === previous.token) {
|
|
56
|
+
lease = previous;
|
|
57
|
+
return current;
|
|
58
|
+
}
|
|
59
|
+
lease = {
|
|
60
|
+
tab,
|
|
61
|
+
token: `${principal}:ui-edit-${crypto.randomUUID()}`,
|
|
62
|
+
previous: current.assigned || null,
|
|
63
|
+
};
|
|
64
|
+
// Persist before sending so an interrupted response can recover on reload.
|
|
65
|
+
localStorage.setItem(key, JSON.stringify(lease));
|
|
66
|
+
try {
|
|
67
|
+
return await call("task_claim", {
|
|
68
|
+
task: task.id,
|
|
69
|
+
expected: lease.previous,
|
|
70
|
+
assigned: lease.token,
|
|
71
|
+
temporary: true,
|
|
72
|
+
});
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const latest = await call("task_get", { id: task.id });
|
|
75
|
+
if (latest.assigned === lease.token) return latest;
|
|
76
|
+
clear();
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
saved() {
|
|
81
|
+
clear();
|
|
82
|
+
},
|
|
83
|
+
release() {
|
|
84
|
+
if (closing) return closing;
|
|
85
|
+
closing = (async () => {
|
|
86
|
+
try {
|
|
87
|
+
if (!lease) return;
|
|
88
|
+
const current = await call("task_get", { id: task.id });
|
|
89
|
+
if (current.assigned === lease.token)
|
|
90
|
+
await call("task_claim", {
|
|
91
|
+
task: task.id,
|
|
92
|
+
expected: lease.token,
|
|
93
|
+
assigned: null,
|
|
94
|
+
restore: true,
|
|
95
|
+
});
|
|
96
|
+
clear();
|
|
97
|
+
} finally {
|
|
98
|
+
unlock?.();
|
|
99
|
+
}
|
|
100
|
+
})();
|
|
101
|
+
return closing;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|