agent-loft 0.2.56 → 0.2.58

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-loft",
3
- "version": "0.2.56",
3
+ "version": "0.2.58",
4
4
  "type": "module",
5
5
  "description": "多个 agent 的工作台:把本机 Claude Code / Codex 放到一处统一管理,用飞书和 Web 页面随时驱动——会话、审批、模型切换都共用",
6
6
  "keywords": [
@@ -107,7 +107,50 @@ export class CodexDriver implements AgentDriver {
107
107
 
108
108
  async sessionTitle(id: string): Promise<string | undefined> {
109
109
  const res = await appServer.call<{ thread: Thread }>("thread/read", { threadId: id, includeTurns: false });
110
- return res.thread.name?.replace(/\s+/g, " ").trim() || undefined;
110
+ const name = res.thread.name?.replace(/\s+/g, " ").trim();
111
+ if (name) return name;
112
+ // app-server 不会自动起名(Codex App / TUI 是在客户端自己生成的),开了设置就由这边生成一次
113
+ const c = config().agents.codex;
114
+ if (!c.autoTitle || this.titled.has(id)) return undefined;
115
+ this.titled.add(id);
116
+ return this.generateTitle(id, c.titleModel).catch((err) => {
117
+ console.error("[codex] 生成会话名称失败:", err instanceof Error ? err.message : err);
118
+ return undefined;
119
+ });
120
+ }
121
+
122
+ /** 本进程里已经生成过(或试过)名称的线程:失败了也不反复重试,每轮结束都会来问 */
123
+ private titled = new Set<string>();
124
+
125
+ /** 按第一轮的问答起个短标题,写回线程(thread/name/set),Codex App 里也能看到 */
126
+ private async generateTitle(id: string, model: string): Promise<string | undefined> {
127
+ const res = await appServer.call<{ thread: { turns?: { items?: HistoryItem[] }[] } }>("thread/read", { threadId: id, includeTurns: true });
128
+ const items = res.thread.turns?.[0]?.items ?? [];
129
+ const user = items
130
+ .filter((i) => i.type === "userMessage")
131
+ .flatMap((i) => (i.content ?? []).map((c) => (c.type === "text" ? (c.text ?? "") : "")))
132
+ .join("\n");
133
+ const question = splitAttachmentNote(stripContext(user)).text.trim();
134
+ if (!question) return undefined;
135
+ const answer = items
136
+ .filter((i) => i.type === "agentMessage" && i.phase !== "commentary" && i.text)
137
+ .map((i) => i.text)
138
+ .join("\n\n");
139
+ const out = (await this.complete({
140
+ system: "你给对话起标题。根据用户的第一条消息(和助手的回复)概括这次对话在做什么,输出一个简短的标题:和用户用同一种语言,中文不超过 15 个字,不加引号、句号和表情。",
141
+ prompt: `用户:\n${question.slice(0, 2000)}${answer ? `\n\n助手:\n${answer.slice(0, 1500)}` : ""}`,
142
+ schema: { type: "object", properties: { title: { type: "string" } }, required: ["title"], additionalProperties: false },
143
+ ...(model ? { model } : {}),
144
+ timeoutMs: 60_000,
145
+ })) as { title?: unknown };
146
+ const title = String(out?.title ?? "")
147
+ .replace(/\s+/g, " ")
148
+ .replace(/^["'“”‘’「」《》]+|["'“”‘’「」《》。.]+$/g, "")
149
+ .trim()
150
+ .slice(0, 80);
151
+ if (!title) return undefined;
152
+ await appServer.call("thread/name/set", { threadId: id, name: title });
153
+ return title;
111
154
  }
112
155
 
113
156
  async readHistory(id: string): Promise<HistoryMessage[]> {
@@ -52,6 +52,10 @@ export type AppConfig = {
52
52
  defaultEffort: string;
53
53
  /** 同 claude.models */
54
54
  models: string[];
55
+ /** app-server 不会给线程起名(那是 Codex App / TUI 自己做的),开了就由这边在第一轮后生成 */
56
+ autoTitle: boolean;
57
+ /** 生成会话名称用的模型,空 = Codex 默认模型 */
58
+ titleModel: string;
55
59
  };
56
60
  };
57
61
  web: {
@@ -126,6 +130,8 @@ export function defaultConfig(): AppConfig {
126
130
  defaultModel: "",
127
131
  defaultEffort: "",
128
132
  models: [],
133
+ autoTitle: false,
134
+ titleModel: "",
129
135
  },
130
136
  },
131
137
  web: { enabled: true, host: "0.0.0.0", port: 8800, passwordHash: "", trustedProxies: ["127.0.0.1", "::1"], quotaRefreshMin: 10, quotaEnabled: true },
@@ -64,6 +64,7 @@
64
64
 
65
65
  .settings-page .row > .grow {
66
66
  flex: 1;
67
+ min-width: 0;
67
68
  }
68
69
 
69
70
  .section {
@@ -266,6 +267,34 @@
266
267
  }
267
268
 
268
269
  /* 设置 → Agent:输入框可选模型 */
270
+ .model-check-summary {
271
+ display: flex;
272
+ align-items: center;
273
+ justify-content: space-between;
274
+ gap: 8px;
275
+ cursor: pointer;
276
+ list-style: none;
277
+ }
278
+
279
+ .model-check-summary::-webkit-details-marker {
280
+ display: none;
281
+ }
282
+
283
+ .model-check-summary svg {
284
+ width: 14px;
285
+ height: 14px;
286
+ flex-shrink: 0;
287
+ color: var(--fg-faint);
288
+ }
289
+
290
+ .model-check-dropdown[open] > summary svg {
291
+ transform: rotate(180deg);
292
+ }
293
+
294
+ .model-check-dropdown[open] > .model-checks {
295
+ margin-top: 6px;
296
+ }
297
+
269
298
  .model-checks {
270
299
  display: flex;
271
300
  flex-direction: column;
@@ -273,6 +302,8 @@
273
302
  border: 1px solid var(--border);
274
303
  border-radius: 10px;
275
304
  padding: 6px;
305
+ max-height: 280px;
306
+ overflow-y: auto;
276
307
  }
277
308
 
278
309
  .model-checks > small {
@@ -300,10 +331,12 @@
300
331
  }
301
332
 
302
333
  .model-check .t {
303
- white-space: nowrap;
334
+ min-width: 0;
335
+ overflow-wrap: anywhere;
304
336
  }
305
337
 
306
338
  .model-check .s {
339
+ min-width: 0;
307
340
  margin-left: auto;
308
341
  font-size: 12px;
309
342
  color: var(--fg-faint);
@@ -295,18 +295,12 @@ button.conv-group:hover {
295
295
  white-space: nowrap;
296
296
  }
297
297
 
298
- /* 放不下:尾巴淡出,代替省略号(.clip 由 sidebar.js 量过后加) */
298
+ /* 放不下:只在右侧淡出,悬停滚动时也保持左侧清晰(.clip 由 sidebar.js 量过后加) */
299
299
  .conv-item .title.clip {
300
300
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
301
301
  mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
302
302
  }
303
303
 
304
- /* 跑马灯滚动时两头都淡出 */
305
- .conv-item .title.clip.marquee {
306
- -webkit-mask-image: linear-gradient(to right, transparent, #000 16px, #000 calc(100% - 16px), transparent);
307
- mask-image: linear-gradient(to right, transparent, #000 16px, #000 calc(100% - 16px), transparent);
308
- }
309
-
310
304
  .conv-item > .dot,
311
305
  .conv-item > .conv-spin {
312
306
  margin-left: auto;
@@ -383,7 +377,7 @@ button.conv-group:hover {
383
377
  width: 14px;
384
378
  height: 14px;
385
379
  margin-left: auto;
386
- color: var(--fg-soft);
380
+ color: var(--fg-faint);
387
381
  }
388
382
 
389
383
  .conv-item .task-mark svg {
@@ -414,8 +408,8 @@ button.conv-group:hover {
414
408
  display: inline-grid;
415
409
  }
416
410
 
417
- .conv-item:hover .expert-mark + .task-mark {
418
- margin-left: 0;
411
+ .conv-item:hover .task-mark {
412
+ display: none;
419
413
  }
420
414
  }
421
415
 
package/web/css/tasks.css CHANGED
@@ -24,10 +24,6 @@
24
24
  background: var(--bg-hover);
25
25
  }
26
26
 
27
- .conv-item .task-mark {
28
- color: var(--fg-soft);
29
- }
30
-
31
27
  /* 任务页不要输入框,也不要「回到底部」 */
32
28
  .main.tasks-view .composer-wrap,
33
29
  .main.tasks-view .to-bottom {
@@ -1,4 +1,4 @@
1
- import { fill, h, toast } from "../lib/dom.js";
1
+ import { fill, h, icon, toast } from "../lib/dom.js";
2
2
  import { api } from "../lib/api.js";
3
3
  import { copyText } from "../lib/markdown.js";
4
4
  import { desktopQuota, S } from "../state.js";
@@ -14,12 +14,32 @@ import { modelPicker } from "./commands.js";
14
14
  */
15
15
  function modelChecklist(agent, selected) {
16
16
  const box = h("div", { class: "model-checks" }, h("small", {}, "正在读取模型列表…"));
17
+ const summaryText = h("span", {}, "正在读取模型列表…");
18
+ const summary = h("summary", { class: "input model-check-summary" }, summaryText, icon("down"));
19
+ const dropdown = h("details", { class: "model-check-dropdown" }, summary, box);
17
20
  let boxes = null;
21
+ const syncSummary = () => {
22
+ const count = boxes.filter((b) => b.el.checked).length;
23
+ summaryText.textContent = count === boxes.length ? `全部模型(${count} 个)` : `已选 ${count} / ${boxes.length} 个模型`;
24
+ };
25
+ box.addEventListener("change", syncSummary);
26
+ dropdown.addEventListener("keydown", (e) => {
27
+ if (e.key === "Escape" && dropdown.open) {
28
+ e.preventDefault();
29
+ e.stopPropagation();
30
+ dropdown.open = false;
31
+ summary.focus();
32
+ }
33
+ });
18
34
  api(`/api/agents/${agent}/models`)
19
35
  .then((data) => {
20
36
  const models = data?.models ?? [];
21
- if (!models.length) return fill(box, h("small", {}, "没读到模型列表"));
37
+ if (!models.length) {
38
+ summaryText.textContent = "没读到模型列表";
39
+ return fill(box, h("small", {}, "没读到模型列表,保留原来的选择"));
40
+ }
22
41
  boxes = models.map((m) => ({ id: m.id, el: h("input", { type: "checkbox", checked: !selected.length || selected.includes(m.id) }) }));
42
+ syncSummary();
23
43
  fill(
24
44
  box,
25
45
  boxes.map(({ el }, i) => {
@@ -35,9 +55,12 @@ function modelChecklist(agent, selected) {
35
55
  h("small", {}, "只影响输入框里的模型选择列表;全部勾上 = 以后新出的模型也自动显示"),
36
56
  );
37
57
  })
38
- .catch((err) => fill(box, h("small", {}, err.status === 409 ? err.message : `读取模型列表失败:${err.message ?? err}`)));
58
+ .catch((err) => {
59
+ summaryText.textContent = "读取模型列表失败";
60
+ fill(box, h("small", {}, err.status === 409 ? err.message : `读取模型列表失败:${err.message ?? err}`));
61
+ });
39
62
  return {
40
- el: box,
63
+ el: dropdown,
41
64
  /** 列表没读到时原样保留;null = 一个都没勾 */
42
65
  value: () => {
43
66
  if (!boxes) return selected;
@@ -149,6 +172,13 @@ export function agentsTab(cfg, page) {
149
172
  );
150
173
  const codexPick = modelPicker("codex", a.codex.defaultModel, a.codex.defaultEffort, "跟随 config.toml");
151
174
  const codexModels = modelChecklist("codex", a.codex.models ?? []);
175
+ // 自动生成会话名称:一行,勾上才显示后面的模型选择
176
+ const titleOn = h("input", { type: "checkbox", checked: !!a.codex.autoTitle });
177
+ const titlePick = modelPicker("codex", a.codex.titleModel ?? "", "", "跟随 config.toml");
178
+ const titleModelEl = h("div", { class: "grow field" }, titlePick.modelEl);
179
+ const syncTitle = () => (titleModelEl.hidden = !titleOn.checked);
180
+ titleOn.addEventListener("change", syncTitle);
181
+ syncTitle();
152
182
  // 一组勾选框不能放进 <label>(点哪都会切到第一个),所以不用 field()
153
183
  const checksField = (list) => h("div", { class: "field" }, h("span", {}, "输入框可选模型"), list.el);
154
184
  // 两个 agent 一起保存:整组算一张表单
@@ -174,6 +204,7 @@ export function agentsTab(cfg, page) {
174
204
  field("默认模型", codexPick.modelEl),
175
205
  field("默认思考程度", codexPick.effortEl),
176
206
  checksField(codexModels),
207
+ h("div", { class: "row title-row" }, h("label", { class: "check" }, titleOn, "自动生成会话名称"), titleModelEl),
177
208
  ),
178
209
  h(
179
210
  "div",
@@ -201,6 +232,8 @@ export function agentsTab(cfg, page) {
201
232
  defaultModel: codexPick.model(),
202
233
  defaultEffort: codexPick.effort(),
203
234
  models: codexList,
235
+ autoTitle: titleOn.checked,
236
+ titleModel: titlePick.model(),
204
237
  },
205
238
  },
206
239
  });
@@ -3,7 +3,8 @@ import { api } from "../lib/api.js";
3
3
  import { confirmDialog, modal, showMenu } from "../lib/overlay.js";
4
4
  import { S } from "../state.js";
5
5
  import { expertIcon, reloadExperts } from "../views/experts.js";
6
- import { agentCatalog } from "../views/topbar.js";
6
+ import { agentCatalog, baseName } from "../views/topbar.js";
7
+ import { changeCwd } from "../views/conv-actions.js";
7
8
 
8
9
  // ---------- 专家(设置里的一页) ----------
9
10
  // 专家 = 一份配置:引擎、提示词、权限、技能、MCP、子智能体。新建对话、定时任务时选,对话中途不能换。
@@ -153,7 +154,21 @@ function openEditor(data, e, reload, preset) {
153
154
  h("option", { value: "claude_code", selected: src.basePrompt === "claude_code" }, "追加在 Claude Code 原装提示词后面(写代码、干活更稳,每轮多约 1.6 万 token)"),
154
155
  );
155
156
  const perms = permChecks(src);
156
- const cwd = h("input", { value: src.cwd ?? "", placeholder: `留空就是工作区根目录(${S.workspaceRoot ?? ""})`, spellcheck: "false" });
157
+ let cwd = src.cwd ?? "";
158
+ const cwdBtn = h("button", { type: "button", class: "btn task-cwd" });
159
+ const showCwd = () => {
160
+ cwdBtn.textContent = cwd ? baseName(cwd) : `${baseName(S.workspaceRoot) || "工作区"}(工作区根目录)`;
161
+ cwdBtn.title = cwd || S.workspaceRoot || "";
162
+ };
163
+ showCwd();
164
+ cwdBtn.onclick = () =>
165
+ changeCwd({
166
+ current: cwd || S.workspaceRoot || "",
167
+ onPick: (p) => {
168
+ cwd = p === S.workspaceRoot ? "" : p;
169
+ showCwd();
170
+ },
171
+ });
157
172
  const memory = h("input", { type: "checkbox", checked: src.memory !== false });
158
173
  const welcome = h("input", { value: src.welcome ?? "", maxlength: "500", placeholder: "新对话页上的那句话,比如:想了解哪只股票?" });
159
174
  const quick = h("textarea", { rows: 4, placeholder: "一行一个,新对话页上点一下就填进输入框。可以写成「标题|提示词」,提示词里的 ___ 是要用户填的空" });
@@ -192,7 +207,7 @@ function openEditor(data, e, reload, preset) {
192
207
  void models.load(eng);
193
208
  };
194
209
  const sync = () => (cwdField.hidden = perms.access() === "web");
195
- const cwdField = field("默认工作目录", cwd, "新建对话、定时任务时默认在这个目录里(可以再改)。相对路径按工作区根目录算");
210
+ const cwdField = field("默认工作目录", cwdBtn, "新建对话、定时任务时默认在这个目录里(可以再改)。点击选择目录,默认使用工作区根目录");
196
211
  const baseField = field("基础提示词", basePrompt);
197
212
  const subField = field("子智能体", subBox, "主专家可以把子任务派给它们(Agent 工具)。子智能体的权限不能超过主专家,只支持 Claude 专家");
198
213
  engine.onchange = renderEngineParts;
@@ -239,7 +254,7 @@ function openEditor(data, e, reload, preset) {
239
254
  prompt: prompt.value,
240
255
  basePrompt: basePrompt.value,
241
256
  access: perms.access(),
242
- cwd: cwd.value,
257
+ cwd,
243
258
  webSearch: perms.checked("webSearch"),
244
259
  webFetch: perms.checked("webFetch"),
245
260
  skills: skills.value(),
@@ -32,7 +32,7 @@ export async function conversationTab(cfg, page) {
32
32
  allowBox,
33
33
  );
34
34
  const allowlist = await api("/api/claude/allowlist");
35
- const allowText = h("textarea", { rows: 8 });
35
+ const allowText = h("textarea", { class: "input", rows: 8 });
36
36
  allowText.value = allowlist.join("\n");
37
37
  fill(
38
38
  allowBox,
@@ -75,7 +75,7 @@ export async function memoryTab(panel) {
75
75
  toast("已保存,之后的对话会用上");
76
76
  });
77
77
 
78
- const newItem = h("input", { maxlength: mem.limits.item, style: { flex: "1", minWidth: "0" }, placeholder: "手动加一条,比如:我的软路由是 iStoreOS,地址 192.168.8.2" });
78
+ const newItem = h("input", { class: "input", maxlength: mem.limits.item, style: { flex: "1", minWidth: "0" }, placeholder: "手动加一条,比如:我的软路由是 iStoreOS,地址 192.168.8.2" });
79
79
  const addBtn = h("button", { class: "btn" }, "添加");
80
80
  addBtn.onclick = run(addBtn, async () => {
81
81
  if (!newItem.value.trim()) return false;
@@ -92,7 +92,7 @@ export async function memoryTab(panel) {
92
92
  const edit = h("button", { class: "btn small" }, "编辑");
93
93
  const del = h("button", { class: "btn small danger" }, "删除");
94
94
  edit.onclick = () => {
95
- const input = h("textarea", { rows: 2, maxlength: mem.limits.item });
95
+ const input = h("textarea", { class: "input", rows: 2, maxlength: mem.limits.item });
96
96
  input.value = it.text;
97
97
  const ok = h("button", { class: "btn small primary" }, "保存");
98
98
  ok.onclick = run(ok, () => api(`/api/account/memory/items/${it.id}`, { method: "PATCH", body: { text: input.value } }));
@@ -134,7 +134,7 @@ function embeddersSection(cfg) {
134
134
  const box = h("div", { class: "section", "data-form": "" });
135
135
  let list = [...cfg.servers.embedders];
136
136
  const rows = h("div", {});
137
- const input = h("input", { placeholder: "https://loft.example.com", autocapitalize: "off", spellcheck: "false" });
137
+ const input = h("input", { class: "input grow", placeholder: "https://loft.example.com", autocapitalize: "off", spellcheck: "false" });
138
138
 
139
139
  const render = () => {
140
140
  fill(