lemma-agent 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +121 -2
- package/bin/lemma.mjs +42 -0
- package/dist/acceptance.js +63 -0
- package/dist/admin.js +1482 -0
- package/dist/agents.js +245 -0
- package/dist/api-member.js +537 -0
- package/dist/app.js +161 -0
- package/dist/board.js +185 -0
- package/dist/business-tools.js +153 -0
- package/dist/change-ops.js +91 -0
- package/dist/changes.js +46 -0
- package/dist/cli-runner.js +106 -0
- package/dist/code-tools.js +396 -0
- package/dist/coding-benchmark-fixtures.js +1049 -0
- package/dist/coding-benchmark-suite.js +1252 -0
- package/dist/collaboration-benchmark.js +349 -0
- package/dist/config.js +392 -0
- package/dist/context-benchmark.js +91 -0
- package/dist/conventions.js +282 -0
- package/dist/conversation.js +39 -0
- package/dist/credentials.js +44 -0
- package/dist/deliverables.js +43 -0
- package/dist/digest.js +129 -0
- package/dist/dispatch.js +801 -0
- package/dist/execution-settings.js +24 -0
- package/dist/git-workbench.js +800 -0
- package/dist/git.js +149 -0
- package/dist/integration-git.js +108 -0
- package/dist/integrations.js +557 -0
- package/dist/jobs.js +100 -0
- package/dist/lead.js +263 -0
- package/dist/learning.js +36 -0
- package/dist/main.js +1402 -0
- package/dist/mcp-settings.js +45 -0
- package/dist/mcp-tools.js +102 -0
- package/dist/member-settings.js +245 -0
- package/dist/model-selection.js +48 -0
- package/dist/models.js +145 -0
- package/dist/native-selectors.js +45 -0
- package/dist/native-terminal-components.js +100 -0
- package/dist/ood-benchmark.js +660 -0
- package/dist/operations.js +21 -0
- package/dist/printer.js +113 -0
- package/dist/repair.js +102 -0
- package/dist/resources.js +31 -0
- package/dist/result-summary.js +8 -0
- package/dist/results.js +41 -0
- package/dist/scope.js +114 -0
- package/dist/sessions.js +95 -0
- package/dist/settings.js +30 -0
- package/dist/task-commands.js +37 -0
- package/dist/task-lifecycle.js +49 -0
- package/dist/task-readiness.js +22 -0
- package/dist/task-recovery.js +116 -0
- package/dist/task-review.js +70 -0
- package/dist/task-workflow.js +424 -0
- package/dist/terminal-layout.js +27 -0
- package/dist/terminal-state.js +145 -0
- package/dist/terminal.js +800 -0
- package/dist/tool-settings.js +111 -0
- package/dist/tools.js +1043 -0
- package/dist/ux-telemetry.js +127 -0
- package/dist/view.js +114 -0
- package/package.json +79 -6
- package/web/index.html +136 -0
- package/web/js/conversations.js +312 -0
- package/web/js/dag.js +495 -0
- package/web/js/drawer.js +139 -0
- package/web/js/editors.js +424 -0
- package/web/js/gitlens.js +844 -0
- package/web/js/main.js +152 -0
- package/web/js/sankey.js +476 -0
- package/web/js/store.js +291 -0
- package/web/js/ticket.js +151 -0
- package/web/js/timeline.js +183 -0
- package/web/js/topology.js +454 -0
- package/web/js/util.js +232 -0
- package/web/js/views.js +1496 -0
- package/web/style.css +5299 -0
package/web/js/util.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// 公共小工具:DOM、格式化、极简 Markdown、提示。
|
|
2
|
+
export const $ = (sel, root = document) => root.querySelector(sel);
|
|
3
|
+
export const $$ = (sel, root = document) => [...root.querySelectorAll(sel)];
|
|
4
|
+
|
|
5
|
+
export const AGENT_LABEL = { claude: "Claude", codex: "Codex", gemini: "Gemini", deepseek: "DeepSeek", lead: "子调度", integration: "联合集成" };
|
|
6
|
+
export const KINDS = ["claude", "codex", "gemini", "deepseek"];
|
|
7
|
+
const BUILTIN_KINDS = [...KINDS];
|
|
8
|
+
export function setAgentLabels(agents = []) {
|
|
9
|
+
KINDS.splice(0, KINDS.length, ...new Set([...BUILTIN_KINDS, ...agents.map((agent) => agent.kind).filter((id) => /^[a-z][a-z0-9_]{0,47}$/.test(id) && !["__proto__", "constructor", "prototype", "lead", "integration"].includes(id))]));
|
|
10
|
+
for (const id of Object.keys(AGENT_LABEL)) { if (id !== "lead" && id !== "integration" && !BUILTIN_KINDS.includes(id)) delete AGENT_LABEL[id]; }
|
|
11
|
+
for (const agent of agents) if (KINDS.includes(agent.kind)) AGENT_LABEL[agent.kind] = agent.label || agent.kind;
|
|
12
|
+
}
|
|
13
|
+
export const SLOT_LABEL = { pending: "排队", running: "执行中", sleeping: "等待中", waiting: "等待中", done: "完成" };
|
|
14
|
+
export const STATUS_LABEL = { open: "无结果", running: "执行中", done: "完成", error: "失败", aborted: "已中止", interrupted: "被中断" };
|
|
15
|
+
export const FAILURE_LABEL = {
|
|
16
|
+
model_error: "模型出错",
|
|
17
|
+
no_model: "没有可用模型",
|
|
18
|
+
aborted: "已中止",
|
|
19
|
+
faulted: "内部错误",
|
|
20
|
+
interrupted: "进程中断",
|
|
21
|
+
restart_limit: "反复崩溃,已放弃",
|
|
22
|
+
turn_limit: "达到轮数上限",
|
|
23
|
+
nothing_to_answer: "没有需要回答的内容",
|
|
24
|
+
orphaned: "任务定义缺失",
|
|
25
|
+
reset: "上下文已重置",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function esc(s) {
|
|
29
|
+
return String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" })[c]);
|
|
30
|
+
}
|
|
31
|
+
export function el(tag, cls, html) {
|
|
32
|
+
const node = document.createElement(tag);
|
|
33
|
+
if (cls) node.className = cls;
|
|
34
|
+
if (html !== undefined) node.innerHTML = html;
|
|
35
|
+
return node;
|
|
36
|
+
}
|
|
37
|
+
export function kindOf(toolName) {
|
|
38
|
+
return String(toolName ?? "").replace(/^ask_/, "");
|
|
39
|
+
}
|
|
40
|
+
export function agentColor(kind) {
|
|
41
|
+
if (kind === "lead" || kind === "integration") return "var(--lead)";
|
|
42
|
+
if (BUILTIN_KINDS.includes(kind)) return `var(--${kind})`;
|
|
43
|
+
const hash = [...String(kind)].reduce((sum, character) => (sum * 31 + character.charCodeAt(0)) >>> 0, 0);
|
|
44
|
+
return `hsl(${hash % 360} 55% 48%)`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
48
|
+
export function clock(ts) {
|
|
49
|
+
if (!ts) return "";
|
|
50
|
+
const d = new Date(ts);
|
|
51
|
+
return `${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
52
|
+
}
|
|
53
|
+
export function stamp(ts) {
|
|
54
|
+
if (!ts) return "—";
|
|
55
|
+
const d = new Date(ts);
|
|
56
|
+
const today = new Date();
|
|
57
|
+
const sameDay = d.toDateString() === today.toDateString();
|
|
58
|
+
return sameDay ? `${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}` : `${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
59
|
+
}
|
|
60
|
+
export function duration(ms) {
|
|
61
|
+
if (ms === undefined || ms === null || Number.isNaN(ms)) return "—";
|
|
62
|
+
const s = Math.max(0, Math.round(ms / 1000));
|
|
63
|
+
if (s < 60) return `${s}s`;
|
|
64
|
+
if (s < 3600) return `${Math.floor(s / 60)}m${pad(s % 60)}s`;
|
|
65
|
+
return `${Math.floor(s / 3600)}h${pad(Math.floor((s % 3600) / 60))}m`;
|
|
66
|
+
}
|
|
67
|
+
export function ago(ts) {
|
|
68
|
+
if (!ts) return "—";
|
|
69
|
+
const s = (Date.now() - ts) / 1000;
|
|
70
|
+
if (s < 60) return "刚刚";
|
|
71
|
+
if (s < 3600) return `${Math.floor(s / 60)} 分钟前`;
|
|
72
|
+
if (s < 86400) return `${Math.floor(s / 3600)} 小时前`;
|
|
73
|
+
return `${Math.floor(s / 86400)} 天前`;
|
|
74
|
+
}
|
|
75
|
+
export function money(v) {
|
|
76
|
+
if (v === undefined || v === null) return "—";
|
|
77
|
+
if (v === 0) return "$0";
|
|
78
|
+
return v < 0.01 ? `$${v.toFixed(4)}` : `$${v.toFixed(2)}`;
|
|
79
|
+
}
|
|
80
|
+
export function num(v) {
|
|
81
|
+
return Number(v ?? 0).toLocaleString();
|
|
82
|
+
}
|
|
83
|
+
export function short(text, max) {
|
|
84
|
+
const t = String(text ?? "").replace(/\s+/g, " ").trim();
|
|
85
|
+
return t.length > max ? `${t.slice(0, max)}…` : t;
|
|
86
|
+
}
|
|
87
|
+
/** 按中英文显示宽度截断(全角/中文按 2 格计算),防止 SVG 固定框内文字溢出 */
|
|
88
|
+
export function clipDisplay(text, maxCols) {
|
|
89
|
+
const t = String(text ?? "").replace(/\s+/g, " ").trim();
|
|
90
|
+
let used = 0;
|
|
91
|
+
let out = "";
|
|
92
|
+
for (const ch of t) {
|
|
93
|
+
const w = ch.codePointAt(0) > 0x2e7f ? 2 : 1;
|
|
94
|
+
if (used + w > maxCols) return out ? `${out}…` : "…";
|
|
95
|
+
used += w;
|
|
96
|
+
out += ch;
|
|
97
|
+
}
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ---------- 提示 / 复制 / 请求 ----------
|
|
102
|
+
let toastTimer;
|
|
103
|
+
export function toast(text) {
|
|
104
|
+
const t = $("#toast");
|
|
105
|
+
t.textContent = text;
|
|
106
|
+
t.classList.add("show");
|
|
107
|
+
clearTimeout(toastTimer);
|
|
108
|
+
toastTimer = setTimeout(() => t.classList.remove("show"), 1800);
|
|
109
|
+
}
|
|
110
|
+
export async function copy(text) {
|
|
111
|
+
try {
|
|
112
|
+
await navigator.clipboard.writeText(text);
|
|
113
|
+
toast("已复制");
|
|
114
|
+
} catch {
|
|
115
|
+
toast(text);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
let conversationScope;
|
|
119
|
+
let conversationVersion = 0;
|
|
120
|
+
export function setConversationScope(id) {
|
|
121
|
+
if (id !== conversationScope) { conversationScope = id; conversationVersion++; }
|
|
122
|
+
}
|
|
123
|
+
export async function getJson(path) {
|
|
124
|
+
const version = conversationVersion;
|
|
125
|
+
const scoped = conversationScope && path.startsWith("/api/") ? `${path}${path.includes("?") ? "&" : "?"}conversation=${encodeURIComponent(conversationScope)}` : path;
|
|
126
|
+
const res = await fetch(scoped);
|
|
127
|
+
const data = await res.json().catch(() => ({}));
|
|
128
|
+
if (version !== conversationVersion) throw new Error("对话已切换,忽略旧数据");
|
|
129
|
+
if (!res.ok) throw new Error(data.error || res.statusText);
|
|
130
|
+
return data;
|
|
131
|
+
}
|
|
132
|
+
export async function post(path, body = {}) {
|
|
133
|
+
const res = await fetch(path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ ...(conversationScope ? { expectedSession: conversationScope } : {}), ...body }) });
|
|
134
|
+
const data = await res.json().catch(() => ({}));
|
|
135
|
+
if (!res.ok) throw Object.assign(new Error(data.error || res.statusText), { code: data.code, ahead: data.ahead, behind: data.behind, gate: data.gate });
|
|
136
|
+
return data;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ---------- 工具结果解析(与后端 parseToolResult 对应) ----------
|
|
140
|
+
export function parseResult(item) {
|
|
141
|
+
let body = item.text ?? "";
|
|
142
|
+
const meta = {};
|
|
143
|
+
const footer = body.match(/\n*\[(agent: [^\]]+)\]\s*$/);
|
|
144
|
+
if (footer) {
|
|
145
|
+
body = body.slice(0, footer.index);
|
|
146
|
+
for (const part of footer[1].split("|")) {
|
|
147
|
+
const [k, ...v] = part.split(":");
|
|
148
|
+
meta[k.trim()] = v.join(":").trim();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
let status = item.isError ? "error" : "done";
|
|
152
|
+
const harness = (item.text ?? "").match(/<harness>([\s\S]*?)<\/harness>\s*$/);
|
|
153
|
+
if (harness) {
|
|
154
|
+
if (/aborted/i.test(harness[1])) {
|
|
155
|
+
status = "aborted";
|
|
156
|
+
body = "这项任务被中止了,CLI 进程已结束。";
|
|
157
|
+
} else {
|
|
158
|
+
if (/interrupted/i.test(harness[1])) status = "interrupted";
|
|
159
|
+
body = harness[1]
|
|
160
|
+
.split("\n")
|
|
161
|
+
.map((l) => l.trim().replace(/^\[(error|info|warning)\]\s*/, ""))
|
|
162
|
+
.filter(Boolean)
|
|
163
|
+
.join("\n");
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
const d = item.details ?? {};
|
|
167
|
+
const seconds = meta["耗时"] ? Number.parseFloat(meta["耗时"]) : undefined;
|
|
168
|
+
return {
|
|
169
|
+
status,
|
|
170
|
+
body: body.trim(),
|
|
171
|
+
sessionId: d.sessionId ?? meta["session_id"],
|
|
172
|
+
durationMs: d.durationMs ?? (seconds !== undefined ? seconds * 1000 : undefined),
|
|
173
|
+
cost: d.costUsd ?? (meta["花费"] ? Number.parseFloat(meta["花费"].replace("$", "")) : undefined),
|
|
174
|
+
cwd: d.cwd,
|
|
175
|
+
exitCode: d.exitCode,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ---------- 极简 Markdown(先转义,再加格式,不允许任何原始 HTML) ----------
|
|
180
|
+
function inline(text) {
|
|
181
|
+
return esc(text)
|
|
182
|
+
.replace(/`([^`]+)`/g, "<code>$1</code>")
|
|
183
|
+
.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>")
|
|
184
|
+
.replace(/(^|[^*])\*([^*\s][^*]*)\*/g, "$1<em>$2</em>")
|
|
185
|
+
.replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>');
|
|
186
|
+
}
|
|
187
|
+
export function markdown(src) {
|
|
188
|
+
const lines = String(src ?? "").replace(/\r\n/g, "\n").split("\n");
|
|
189
|
+
const out = [];
|
|
190
|
+
let i = 0;
|
|
191
|
+
while (i < lines.length) {
|
|
192
|
+
const line = lines[i];
|
|
193
|
+
if (/^```/.test(line)) {
|
|
194
|
+
const code = [];
|
|
195
|
+
i++;
|
|
196
|
+
while (i < lines.length && !/^```/.test(lines[i])) code.push(lines[i++]);
|
|
197
|
+
i++;
|
|
198
|
+
out.push(`<pre><code>${esc(code.join("\n"))}</code></pre>`);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const h = line.match(/^(#{1,4})\s+(.*)$/);
|
|
202
|
+
if (h) {
|
|
203
|
+
out.push(`<h${h[1].length}>${inline(h[2])}</h${h[1].length}>`);
|
|
204
|
+
i++;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (/^\s*[-*]\s+/.test(line) || /^\s*\d+[.)]\s+/.test(line)) {
|
|
208
|
+
const ordered = /^\s*\d+[.)]\s+/.test(line);
|
|
209
|
+
const items = [];
|
|
210
|
+
while (i < lines.length && (ordered ? /^\s*\d+[.)]\s+/ : /^\s*[-*]\s+/).test(lines[i])) {
|
|
211
|
+
items.push(`<li>${inline(lines[i].replace(/^\s*(?:[-*]|\d+[.)])\s+/, ""))}</li>`);
|
|
212
|
+
i++;
|
|
213
|
+
}
|
|
214
|
+
out.push(ordered ? `<ol>${items.join("")}</ol>` : `<ul>${items.join("")}</ul>`);
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (/^>\s?/.test(line)) {
|
|
218
|
+
const quote = [];
|
|
219
|
+
while (i < lines.length && /^>\s?/.test(lines[i])) quote.push(lines[i++].replace(/^>\s?/, ""));
|
|
220
|
+
out.push(`<blockquote>${inline(quote.join(" "))}</blockquote>`);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (!line.trim()) {
|
|
224
|
+
i++;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const para = [];
|
|
228
|
+
while (i < lines.length && lines[i].trim() && !/^(```|#{1,4}\s|\s*[-*]\s|\s*\d+[.)]\s|>)/.test(lines[i])) para.push(lines[i++]);
|
|
229
|
+
out.push(`<p>${para.map(inline).join("<br>")}</p>`);
|
|
230
|
+
}
|
|
231
|
+
return out.join("");
|
|
232
|
+
}
|