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
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
2
|
+
import { colors as c } from "./printer.js";
|
|
3
|
+
import { cleanText } from "./native-terminal-components.js";
|
|
4
|
+
/** Fit both ends without counting ANSI styling or splitting wide characters. */
|
|
5
|
+
export function terminalRow(left, right, width) {
|
|
6
|
+
const available = Math.max(1, width);
|
|
7
|
+
if (!right || available < 54)
|
|
8
|
+
return truncateToWidth(left, available);
|
|
9
|
+
const tail = truncateToWidth(right, Math.min(Math.floor(available * 0.4), visibleWidth(right)));
|
|
10
|
+
const head = truncateToWidth(left, Math.max(1, available - visibleWidth(tail) - 2));
|
|
11
|
+
return head + " ".repeat(Math.max(1, available - visibleWidth(head) - visibleWidth(tail))) + tail;
|
|
12
|
+
}
|
|
13
|
+
export function conversationWelcome(width, readOnly) {
|
|
14
|
+
const lines = readOnly ? [
|
|
15
|
+
c.cyan(" 成员对话 · 只读"),
|
|
16
|
+
" 这里展示成员自己的消息与执行记录。",
|
|
17
|
+
c.dim(" /main 返回总控 · Ctrl+K 切换会话"),
|
|
18
|
+
] : [
|
|
19
|
+
c.cyan(" Lemma · 从一个目标开始"),
|
|
20
|
+
" 直接提问,或描述需要团队协作完成的任务。",
|
|
21
|
+
c.dim(" /agent 添加成员 /sessions 管理对话"),
|
|
22
|
+
c.dim(" /tasks 查看成果 /task 恢复受阻任务"),
|
|
23
|
+
c.dim(" Enter 发送 · Ctrl+J 换行 · /help 命令"),
|
|
24
|
+
];
|
|
25
|
+
return ["", ...lines.map((line) => truncateToWidth(line, Math.max(1, width))), ""];
|
|
26
|
+
}
|
|
27
|
+
export const terminalLabel = (value, limit = 100) => cleanText(String(value ?? "")).replace(/\s+/g, " ").slice(0, limit);
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { ConversationTranscript } from "@earendil-works/pi-durable";
|
|
2
|
+
import { toViewItem, toViewLive } from "./view.js";
|
|
3
|
+
import { transcriptSummary } from "./digest.js";
|
|
4
|
+
import { MemberIdentity } from "./api-member.js";
|
|
5
|
+
const HISTORY_PAGE_SIZE = 250;
|
|
6
|
+
/** 两个原生订阅共用一个清理函数;切换后不再向旧视图发送任何更新。 */
|
|
7
|
+
export async function watchTerminalState(options) {
|
|
8
|
+
const { harness, conversation, context } = options;
|
|
9
|
+
let stopped = false;
|
|
10
|
+
let conversationWatch;
|
|
11
|
+
let graphWatch;
|
|
12
|
+
const transcript = new ConversationTranscript((query, limit, ctx) => conversation.entries(query, limit, undefined, ctx), { pageSize: HISTORY_PAGE_SIZE });
|
|
13
|
+
const projected = new WeakMap();
|
|
14
|
+
let latestView;
|
|
15
|
+
let loading;
|
|
16
|
+
const report = (error) => {
|
|
17
|
+
if (stopped)
|
|
18
|
+
return;
|
|
19
|
+
try {
|
|
20
|
+
options.onError?.(error);
|
|
21
|
+
}
|
|
22
|
+
catch { /* 错误提示不能中断 Durable 的订阅。 */ }
|
|
23
|
+
};
|
|
24
|
+
const publish = (callback) => { if (!stopped) {
|
|
25
|
+
try {
|
|
26
|
+
callback();
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
report(error);
|
|
30
|
+
}
|
|
31
|
+
} };
|
|
32
|
+
const stop = async () => {
|
|
33
|
+
if (stopped)
|
|
34
|
+
return;
|
|
35
|
+
stopped = true;
|
|
36
|
+
await Promise.allSettled([conversationWatch?.stop(), graphWatch?.stop()]);
|
|
37
|
+
};
|
|
38
|
+
const renderConversation = (view, merged = transcript.merge(view)) => {
|
|
39
|
+
if (stopped)
|
|
40
|
+
return;
|
|
41
|
+
latestView = view;
|
|
42
|
+
// Durable owns paging and entry identity. Keep loaded history, including reset dividers,
|
|
43
|
+
// in the display only; viewing it never adds entries to the model's context.
|
|
44
|
+
const items = [];
|
|
45
|
+
for (const row of merged.items) {
|
|
46
|
+
if (row.kind !== "entry")
|
|
47
|
+
continue;
|
|
48
|
+
const entry = row.entry;
|
|
49
|
+
let display = projected.get(entry);
|
|
50
|
+
if (!display) {
|
|
51
|
+
const item = toViewItem(entry);
|
|
52
|
+
if (!item)
|
|
53
|
+
continue;
|
|
54
|
+
display = { ...item, message: entry.model?.[0] };
|
|
55
|
+
projected.set(entry, display);
|
|
56
|
+
}
|
|
57
|
+
items.push(display);
|
|
58
|
+
}
|
|
59
|
+
const live = toViewLive(view.docs["pi.live"], view.docs["pi.inbox"]);
|
|
60
|
+
if (view.entries.at(-1)?.kind === "pi.reset")
|
|
61
|
+
live.runFailure = undefined;
|
|
62
|
+
const raw = view.docs["pi.live"];
|
|
63
|
+
const partialMessage = raw?.generation?.message;
|
|
64
|
+
const tools = [...live.tools, ...(raw?.nestedTools ?? []).map((slot) => ({
|
|
65
|
+
callId: slot.callId, name: slot.name, status: slot.status, output: slot.output ?? slot.summary?.error ?? "",
|
|
66
|
+
details: slot.details, args: slot.arguments, isError: slot.summary?.isError,
|
|
67
|
+
}))];
|
|
68
|
+
for (const block of partialMessage?.content ?? [])
|
|
69
|
+
if (block.type === "toolCall" && block.name && !tools.some((tool) => tool.callId === block.id))
|
|
70
|
+
tools.push({
|
|
71
|
+
callId: block.id, name: block.name, args: block.arguments, argsComplete: false, status: "pending", output: "",
|
|
72
|
+
});
|
|
73
|
+
publish(() => options.onConversation({ items, live, partialMessage, tools, history: {
|
|
74
|
+
hasEarlier: merged.items.some((row) => row.kind !== "entry"), loading: !!loading, loadEarlier,
|
|
75
|
+
} }));
|
|
76
|
+
};
|
|
77
|
+
function loadEarlier() {
|
|
78
|
+
if (stopped || !latestView)
|
|
79
|
+
return Promise.resolve();
|
|
80
|
+
if (loading)
|
|
81
|
+
return loading;
|
|
82
|
+
const current = transcript.merge(latestView);
|
|
83
|
+
const gap = current.items.findLast((row) => row.kind === "gap");
|
|
84
|
+
if (!gap && !current.items.some((row) => row.kind === "earlier"))
|
|
85
|
+
return Promise.resolve();
|
|
86
|
+
loading = Promise.resolve().then(async () => {
|
|
87
|
+
try {
|
|
88
|
+
if (gap?.kind === "gap")
|
|
89
|
+
await transcript.fillGap(gap, context);
|
|
90
|
+
else
|
|
91
|
+
await transcript.loadEarlier(context);
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
loading = undefined;
|
|
95
|
+
if (!stopped && latestView)
|
|
96
|
+
renderConversation(latestView);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
renderConversation(latestView);
|
|
100
|
+
return loading;
|
|
101
|
+
}
|
|
102
|
+
const renderGraph = (graph) => publish(() => options.onTasks(Object.values(graph.tasks).map((node) => ({
|
|
103
|
+
id: String(node.id), kind: node.kind, status: node.state.status, conversationId: String(node.conversationId),
|
|
104
|
+
...(node.owner === undefined ? {} : { owner: String(node.owner) }),
|
|
105
|
+
label: `${node.kind}${node.background ? " · 后台" : ""}${node.abortRequested ? " · 正在中止" : ""}${node.blocked ? ` · ${node.blocked}` : ""}`,
|
|
106
|
+
}))));
|
|
107
|
+
try {
|
|
108
|
+
conversationWatch = await conversation.watch(context, { min: HISTORY_PAGE_SIZE, max: HISTORY_PAGE_SIZE * 2 });
|
|
109
|
+
graphWatch = await harness.watchTaskGraph(context);
|
|
110
|
+
renderConversation(conversationWatch.value);
|
|
111
|
+
renderGraph(graphWatch.value);
|
|
112
|
+
conversationWatch.start(async (call) => { if (call.kind === "value")
|
|
113
|
+
renderConversation(call.value); });
|
|
114
|
+
graphWatch.start(async (call) => { if (call.kind === "value")
|
|
115
|
+
renderGraph(call.value); });
|
|
116
|
+
return stop;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
await stop();
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
/** 同一存储内的总控、子负责人和 API 成员;读取不会启动任务或复制上下文。 */
|
|
124
|
+
export async function listNativeConversations(harness, root, context) {
|
|
125
|
+
const records = await harness.commit(async (tx) => {
|
|
126
|
+
const [main, recent] = await Promise.all([tx.conversation(root.id), tx.scanConversations({ order: "descending" }, 99)]);
|
|
127
|
+
return [...(main ? [main] : []), ...recent.items.filter((record) => String(record.id) !== String(root.id))];
|
|
128
|
+
}, context);
|
|
129
|
+
const summaries = await Promise.all(records.map(async (record) => {
|
|
130
|
+
const child = await harness.conversation(record.id, context);
|
|
131
|
+
if (!child)
|
|
132
|
+
return undefined;
|
|
133
|
+
const [agent, stats, identity] = await Promise.all([child.agent(context), transcriptSummary(harness, child), harness.snapshot(MemberIdentity, child.id, context)]);
|
|
134
|
+
const summary = stats.first?.slice(0, 100) ?? "尚无消息";
|
|
135
|
+
const isRoot = String(record.id) === String(root.id);
|
|
136
|
+
return {
|
|
137
|
+
id: String(record.id), title: isRoot ? "总调度" : identity?.name ? `${identity.name} · ${summary}` : summary,
|
|
138
|
+
parentId: isRoot ? undefined : String(record.owner?.conversationId ?? record.parent?.conversationId ?? root.id),
|
|
139
|
+
workdir: agent.cwd,
|
|
140
|
+
createdAt: stats.firstAt, lastAt: stats.lastAt, messageCount: stats.messageCount, searchText: stats.text,
|
|
141
|
+
detail: `${isRoot ? "主对话" : `所属对话 ${record.owner?.conversationId ?? record.parent?.conversationId ?? "独立"}`} · CID:${record.id}${agent.model ? ` · ${agent.model.modelId}` : ""}${agent.cwd ? ` · ${agent.cwd}` : ""}`,
|
|
142
|
+
};
|
|
143
|
+
}));
|
|
144
|
+
return summaries.filter((item) => item !== undefined).sort((a, b) => Number(b.id === String(root.id)) - Number(a.id === String(root.id)));
|
|
145
|
+
}
|