@wbohui123/blueprint-studio 0.0.0-stage → 2.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/LICENSE +661 -0
- package/README.md +72 -2
- package/package.json +33 -4
- package/src/DeepSeek/344/275/231/351/242/235.js +33 -0
- package/src/index.js +5307 -0
- package/src//344/272/247/347/211/251.js +386 -0
- package/src//344/273/273/345/212/241/345/273/212/351/242/204/350/247/210.js +119 -0
- package/src//344/274/232/350/257/235/345/277/253/347/205/247/350/257/273/345/217/226.js +14 -0
- package/src//345/200/237/346/235/245/347/232/204//344/272/247/347/211/251.js +87 -0
- package/src//345/200/237/346/235/245/347/232/204//345/252/222/344/275/223/346/234/215/345/212/241.js +485 -0
- package/src//345/200/237/346/235/245/347/232/204//345/274/200/347/273/210/347/253/257.js +44 -0
- package/src//345/200/237/346/235/245/347/232/204//346/235/202/351/241/271.js +67 -0
- package/src//345/200/237/346/235/245/347/232/204//346/256/213/347/225/231/350/277/233/347/250/213.js +181 -0
- package/src//345/200/237/346/235/245/347/232/204//346/266/210/346/201/257/345/215/217/350/256/256.js +48 -0
- package/src//345/200/237/346/235/245/347/232/204//347/225/231/344/270/213/347/232/204/350/277/233/347/250/213.js +35 -0
- package/src//345/200/237/346/235/245/347/232/204//347/273/210/347/253/257.js +20 -0
- package/src//345/200/237/346/235/245/347/232/204//350/243/205/346/217/220/344/276/233/346/226/271.js +26 -0
- package/src//345/200/237/346/235/245/347/232/204//350/267/257/345/276/204.js +21 -0
- package/src//345/200/237/346/235/245/347/232/204//351/227/256/347/255/224.js +48 -0
- package/src//345/200/237/346/235/245/347/232/204//351/241/271/347/233/256/345/210/240/351/231/244/347/212/266/346/200/201.js +5 -0
- package/src//345/200/237/346/235/245/347/232/204//351/241/271/347/233/256/345/220/215/347/247/260.js +116 -0
- package/src//345/200/237/346/235/245/347/232/204//351/241/271/347/233/256/345/255/230/345/202/250.js +92 -0
- package/src//345/200/237/346/235/245/347/232/204//351/241/271/347/233/256/351/231/204/344/273/266.js +55 -0
- package/src//345/201/234/346/255/242/345/220/216/345/217/260.js +18 -0
- package/src//345/212/251/347/220/206.js +157 -0
- package/src//345/220/215/345/206/214/350/247/206/345/233/276.js +251 -0
- package/src//345/220/215/345/206/214/350/257/273/347/274/223/345/255/230.js +70 -0
- package/src//345/233/236/350/257/235/346/217/220/351/206/222.js +38 -0
- package/src//345/233/276/347/272/270/345/256/236/346/227/266.js +91 -0
- package/src//345/244/226/351/203/250run/344/272/247/347/211/251.js +75 -0
- package/src//345/244/226/351/203/250run/350/247/206/345/233/276.js +86 -0
- package/src//345/244/226/351/203/250/345/215/217/345/212/251.js +101 -0
- package/src//345/252/222/344/275/223/350/256/276/347/275/256.js +12 -0
- package/src//345/255/220/344/273/243/347/220/206.js +337 -0
- package/src//345/256/236/346/227/266/350/276/223/345/207/272.js +90 -0
- package/src//345/267/245/344/275/234/346/227/266/351/227/264.js +170 -0
- package/src//345/271/263/345/217/260/345/205/245/345/217/243.js +703 -0
- package/src//346/211/247/350/241/214/350/203/275/345/212/233.js +2 -0
- package/src//346/214/201/347/273/255/347/233/256/346/240/207.js +3 -0
- package/src//346/217/220/347/244/272/347/273/237/350/256/241.js +24 -0
- package/src//346/226/207/344/273/266/345/244/271.js +26 -0
- package/src//346/226/260/345/220/215/345/206/214.js +145 -0
- package/src//346/226/260/351/241/271/347/233/256.js +203 -0
- package/src//346/227/247/345/212/237/350/203/275/346/241/251.js +34 -0
- package/src//346/235/220/346/226/231.js +97 -0
- package/src//346/240/221/346/221/230/350/246/201/347/233/230.js +37 -0
- package/src//346/240/221/350/264/246/346/234/254.js +11 -0
- package/src//347/225/214/351/235/242/350/257/255/350/250/200.js +25 -0
- package/src//347/273/210/347/253/257.js +128 -0
- package/src//350/212/202/347/202/271/344/277/241/346/201/257.js +56 -0
- package/src//350/256/260/345/277/206/345/205/245/345/217/243.js +51 -0
- package/src//350/275/257/344/273/266.js +227 -0
- package/src//350/277/220/350/241/214/347/212/266/346/200/201.js +38 -0
- package/src//350/277/236/346/216/245.js +385 -0
- package/src//351/227/256/347/255/224/351/223/276.js +160 -0
- package/src//351/241/271/347/233/256/345/210/206/347/273/204.js +67 -0
- package/src//351/241/271/347/233/256/345/220/215/347/247/260/345/205/245/345/217/243.js +23 -0
- package/src//351/241/271/347/233/256/345/255/230/345/202/250/345/205/245/345/217/243.js +30 -0
- package/src//351/241/271/347/233/256/346/223/215/344/275/234.js +34 -0
- package/src//351/241/271/347/233/256/350/207/252/345/212/250/345/201/234/346/255/242.js +107 -0
- package/src//351/241/271/347/233/256/350/256/241/351/207/217.js +114 -0
- package/src//351/242/204/350/247/210.js +157 -0
- package/viewer//347/225/214/351/235/242/350/257/255/350/250/200.js +97 -0
- package/viewer//350/213/261/346/226/207.json +1535 -0
- package//345/215/225/344/273/267.json +126 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** 字符统计只读原生账本;文件来源不参与实际请求计数。 */
|
|
2
|
+
import { foldSurface, deriveEventMessage } from '@deepseek-ai/dsh-session'
|
|
3
|
+
import { 消息来自, 是上下文消息 } from './借来的/消息协议.js'
|
|
4
|
+
|
|
5
|
+
export const 字符数 = text => [...String(text || '')].length
|
|
6
|
+
const 正文 = message => (message?.content || []).filter(b => b.type === 'text').map(b => b.text).join('\n')
|
|
7
|
+
|
|
8
|
+
export function 请求提示统计(events) {
|
|
9
|
+
const index = events.findLastIndex(e => e.type === 'request/header')
|
|
10
|
+
if (index < 0) return null
|
|
11
|
+
const request = events[index]
|
|
12
|
+
const tools = request.data.header.tools || []
|
|
13
|
+
let 动态提示 = null
|
|
14
|
+
try {
|
|
15
|
+
// 使用请求当时的活动 surface,替换前的阶段与后来的消息都不计入。
|
|
16
|
+
const prefix = events.slice(0, index + 1)
|
|
17
|
+
const messages = foldSurface(prefix).nodes.map(seq => deriveEventMessage(prefix[seq])).filter(Boolean)
|
|
18
|
+
动态提示 = messages.filter(m => 是上下文消息(m)
|
|
19
|
+
&& !消息来自(m, 'compact-checkpoint') && !消息来自(m, 'compact-basic'))
|
|
20
|
+
.reduce((sum, m) => sum + 字符数(正文(m)), 0)
|
|
21
|
+
} catch { /* 旧格式或不完整账本不能重建时明示未知,不把全历史相加。 */ }
|
|
22
|
+
return { 工具定义: tools.length ? 字符数(JSON.stringify(tools)) : 0, 工具数: tools.length,
|
|
23
|
+
动态提示, 请求序号: request.seq, turn: request.data.turn, step: request.data.step }
|
|
24
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { readdir, realpath } from 'node:fs/promises'
|
|
2
|
+
import { resolve, relative, sep } from 'node:path'
|
|
3
|
+
import { 允许预览路径 } from './借来的/产物.js'
|
|
4
|
+
|
|
5
|
+
/** 只读根内一个目录的直属条目。后代的数量、深度和读取权限不影响这一层。 */
|
|
6
|
+
export async function 列目录(root, position = '') {
|
|
7
|
+
const 位 = String(position ?? '')
|
|
8
|
+
if (位.startsWith('/') || 位.includes('\\') || 位.split('/').includes('..') || 位.includes('\0'))
|
|
9
|
+
throw new Error('目录位置必须在当前文件夹里面')
|
|
10
|
+
const 根 = await realpath(root)
|
|
11
|
+
const dir = await realpath(resolve(根, 位 || '.'))
|
|
12
|
+
if (dir !== 根 && !dir.startsWith(根 + sep)) throw new Error('目录位置指到了当前文件夹外面')
|
|
13
|
+
const paths = [relative(根, resolve(根, 位 || '.')), relative(根, dir)].map(value => value.split(sep).join('/'))
|
|
14
|
+
if (paths.some(value => value.split('/').some(part => /^\.git$/i.test(part)))) throw new Error('Git 管理目录不提供浏览')
|
|
15
|
+
const native = paths.some(value => value.split('/').includes('.agents'))
|
|
16
|
+
if (native && paths.some(value => !允许预览路径(value, { includeWorktreeParents: true, includeTemporary: true, includeEvidence: true })))
|
|
17
|
+
throw new Error('这里只浏览原生工作树的普通目录')
|
|
18
|
+
const ents = await readdir(dir, { withFileTypes: true })
|
|
19
|
+
const inAgents = paths.some(value => value.split('/').at(-1) === '.agents')
|
|
20
|
+
const 树 = ents.filter(d => d.name !== '.DS_Store' && !/^\.git$/i.test(d.name)
|
|
21
|
+
&& (!inAgents || (d.name === 'worktrees' && d.isDirectory()))
|
|
22
|
+
&& (!native || 允许预览路径(relative(根, resolve(dir, d.name)).split(sep).join('/'), { includeWorktreeParents: true, includeTemporary: true, includeEvidence: true })))
|
|
23
|
+
.map(d => ({ 名: d.name, 夹: d.isDirectory() }))
|
|
24
|
+
树.sort((a, b) => a.夹 !== b.夹 ? (a.夹 ? -1 : 1) : a.名.localeCompare(b.名, 'zh', { numeric: true }))
|
|
25
|
+
return { 位置: 位, 树, 数: 树.length }
|
|
26
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 名册(11-22 自由蓝图):界面读项目的 `系统文档/信息.db`(@wbohui123/blueprint-defaults 的内核)。
|
|
3
|
+
* 只有节点、全部平级:一个节点有编号、类型、名字、描述、接在谁后面(上一层,null=根)、同一层里的先后(序)、会话、专家(大师)。
|
|
4
|
+
*
|
|
5
|
+
* - `树Of(根, 在跑)`:给图纸的那一份(工单 2.5):`{ 根们: [编号…], 节点们: { 编号: { 编号, 类型, 名字, 描述, 上一层, 序, 下一层们, 状态, 会话, 大师 } }, 方案们 }`。
|
|
6
|
+
* 方案们(段二 2.4):节点用 propose_nodes 摆出来、还待定的分工方案:`[{ 号, 提的, 节点们: [{ 键, 名字, 类型, 大师?, 描述, 接在? }], 时间 }]`,图上画成灰的。
|
|
7
|
+
* 收件们(段二 2.6):节点停下时宿主自动放进你收件箱、还待你的:`[{ 号, 节点, 类(答/定/看), 内容, 时间 }]`。
|
|
8
|
+
* 模型(段二 2.8):这个项目的默认模型 `{ provider, model, reasoningEffort? }`,没设是 null(照 dsh 的默认)。
|
|
9
|
+
* 版本数(段三 2.3):这个位置开过几个会话(每个会话一版);版本们本身只在版本框打开时另取。
|
|
10
|
+
* 当前版(11-24,卡上的版本钮):图上现在用的是第几版;会话清空了(刚重置、还没开始)算下一版。
|
|
11
|
+
* 队员(11-27):节点自己开的子 agent(内核 队员.js)也在 节点们 里,编号像 N5.1,带 `队员: true`、`由`(dsh/codex/claude-code),挂在开它的节点的 下一层们 后面。
|
|
12
|
+
* 标记(11-27):用户在卡上按亮的标记(true/false),卡画成提醒的黄色;只管颜色,状态照旧。
|
|
13
|
+
* 缩略(段四 2.3):这个节点现在在干什么、做到哪(11-30 起机器取它每轮最后说的第一段,原来影子写);还没有是空串,卡上就写描述。
|
|
14
|
+
* 总管(段五 2.4):`{ 编号, 会话, 状态 }` 或 null。11-23 晚起是总 agent=最上面一排第一个节点(撤了 superagent),收件箱贴在它下面、对总管说送给它。
|
|
15
|
+
* 状态五个(段二 2.7,照原来那套、撤了"等节点"):没开始/在做/等你/停了/交了,`状态表` 算。此刻在不在跑由调用方给(`在跑(节)`),这里不碰 dsh。
|
|
16
|
+
* - `读名册(根)`:一个节点一行,给还在读旧名册的地方(对话页、项目分组起会话标题、问答链)。
|
|
17
|
+
*/
|
|
18
|
+
import { 换模型 } from '../../blueprint-host/src/模型.js'
|
|
19
|
+
import { 队员们, 开信息库, 信息库路径, 节点们 as 全部节点, 根们 as 全部根, 下一层们 as 下面Of, 待定方案们, 待你的, 事件们, 项目信息, 记项目信息, 版本们, 待总管的, 总管Of } from '../../blueprint-defaults/src/index.js'
|
|
20
|
+
|
|
21
|
+
export const 文档夹名 = '系统文档'
|
|
22
|
+
export const 名册文件名 = '信息.db'
|
|
23
|
+
export const 名册路径 = 根 => 信息库路径(根)
|
|
24
|
+
|
|
25
|
+
/** 节点的四种类型(工单第〇节:plan 是专家的一种,类型 `专家`、大师 `plan`)。 */
|
|
26
|
+
export const 类型们 = Object.freeze(['普通', '专家', 'codex', 'claude-code'])
|
|
27
|
+
/** 外部节点:交给 Codex/Claude Code 的程序跑,没有 dsh 会话。 */
|
|
28
|
+
export const 是外部类型 = 类型 => 类型 === 'codex' || 类型 === 'claude-code'
|
|
29
|
+
|
|
30
|
+
/** 节点的状态(段二 2.7 五个;段五加回「等节点」:它有一件交给总管、总管还没回,界面写「等总管」)。 */
|
|
31
|
+
export const 状态们 = Object.freeze(['没开始', '在做', '等你', '等节点', '停了', '交了'])
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 一个项目的状态表:节 → 状态。照节点 `会话` 指向的那一版算(段三 2.3):只看这个位置最后一次重置、切版本以后的开始/暂停。
|
|
35
|
+
* - 在做:此刻在跑(`在跑(节)`:dsh 会话在跑;外部节点看它的进程)。
|
|
36
|
+
* - 没开始:还没跑过——没有会话(或者会话开了、一轮都没跑过:点卡进对话会先开好会话,11-23 真跑卡上误写成"交了"),
|
|
37
|
+
* 最后一次重置以后没点过开始,外部节点也没有(重置前的)跑过的记录(「外部」那一栏里只存了模型不算)。
|
|
38
|
+
* `跑过(节)`:这个节点现在那一版的 dsh 会话跑过没有;不知道就当跑过(照旧)。
|
|
39
|
+
* - 等你:没在跑,收件箱里有它放的、还待你的一件,或者它提的分工方案还待定。
|
|
40
|
+
* - 等节点:没在跑,它放的一件交给了总管、总管还没回(段五)。
|
|
41
|
+
* - 停了:没在跑,这一版最后一个开始/暂停是暂停(你把这一轮停在半路);或者 dsh 会话最后一轮没善终
|
|
42
|
+
* (`断了(节)`:在对话里按停、出错、重启切断——这些不经过卡上的暂停,不记暂停事件,11-24 真跑卡上误写成"交了")。
|
|
43
|
+
* - 交了:没在跑、跑过,以上都不是(这一轮自己做完停下了)。
|
|
44
|
+
*/
|
|
45
|
+
export function 状态表(库, 在跑 = () => false, 跑过 = () => true, 断了 = () => false) {
|
|
46
|
+
const 等你的 = new Set([...待你的(库).map(件 => String(件.节点)), ...待定方案们(库).map(方 => String(方.提的))])
|
|
47
|
+
const 等总管的 = new Set(待总管的(库).map(件 => String(件.节点)))
|
|
48
|
+
return 节 => {
|
|
49
|
+
if (在跑(节)) return '在做'
|
|
50
|
+
const 最后一次 = 种类 => 事件们(库, { 种类, 节点: 节.编号, 最近: 1 })[0]
|
|
51
|
+
const 重置 = 最后一次(['重置']), 换版 = 最后一次(['重置', '切版本'])
|
|
52
|
+
const 最后 = 事件们(库, { 种类: ['开始', '暂停'], 节点: 节.编号, 从: 换版?.序 || 0, 最近: 1 })[0]
|
|
53
|
+
const 重置后开过 = !!最后 || 事件们(库, { 种类: ['开始'], 节点: 节.编号, 从: 重置?.序 || 0, 最近: 1 }).length > 0
|
|
54
|
+
const 外部跑过 = !!(节.外部?.attempt || 节.外部?.startedAt || 节.外部?.state)
|
|
55
|
+
if ((!节.会话 || !跑过(节)) && !重置后开过 && !(外部跑过 && !重置)) return '没开始'
|
|
56
|
+
if (等你的.has(String(节.编号))) return '等你'
|
|
57
|
+
if (等总管的.has(String(节.编号))) return '等节点'
|
|
58
|
+
return 最后?.种类 === '暂停' || 断了(节) ? '停了' : '交了'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** 项目的默认模型(段二 2.8):存在项目信息键 `模型`,一段 JSON `{ provider, model, reasoningEffort? }`;没设、读不懂 → null。 */
|
|
63
|
+
export function 项目模型(库) {
|
|
64
|
+
try {
|
|
65
|
+
const 值 = JSON.parse(项目信息(库, '模型') || 'null')
|
|
66
|
+
return 值?.provider && 值?.model ? { provider: String(值.provider), model: String(值.model), ...(值.reasoningEffort ? { reasoningEffort: String(值.reasoningEffort) } : {}) } : null
|
|
67
|
+
} catch { return null }
|
|
68
|
+
}
|
|
69
|
+
/** 设项目的默认模型:provider、model 必须有,reasoningEffort 可选。回存下的那份。已经开着会话的节点换不换由调用方接着调 `换开着的`。 */
|
|
70
|
+
export function 设项目模型(库, { provider, model, reasoningEffort } = {}) {
|
|
71
|
+
const 名 = 值 => typeof 值 === 'string' && 值.trim() && 值.length <= 200 && !/[\x00-\x1f]/.test(值) ? 值.trim() : ''
|
|
72
|
+
const 存 = { provider: 名(provider), model: 名(model), ...(名(reasoningEffort) ? { reasoningEffort: 名(reasoningEffort) } : {}) }
|
|
73
|
+
if (!存.provider || !存.model) throw new Error('模型要写 provider 和 model')
|
|
74
|
+
记项目信息(库, '模型', JSON.stringify(存))
|
|
75
|
+
return 存
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 项目模型改了以后,已经开着会话的 dsh 节点下一轮换成它(宿主的 `换模型`)。回换了的编号们;换不成就报出来,说清模型已经存下了。 */
|
|
79
|
+
export async function 换开着的(根, 模型) {
|
|
80
|
+
try { return await 换模型(根, 模型) } catch (error) { throw new Error(`模型存下了,已经开着会话的节点没换成:${error.message}`) }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** 内核回的一排(节点或编号,内核已按序排)→ 编号们。 */
|
|
84
|
+
const 排好 = 们 => (们 || []).map(节 => typeof 节 === 'string' ? 节 : String(节?.编号 ?? ''))
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 等你什么(11-25):状态是「等你」时,是要你回答(收件「答」:它问了问题)还是要你确认(收件「定」:它交出东西请你看;分工方案待定也算)。
|
|
88
|
+
* 回 编号 → '回答'|'确认'|''。树和节点信息卡共用。
|
|
89
|
+
*/
|
|
90
|
+
export function 等你什么表(库) {
|
|
91
|
+
const 等答 = new Set(), 等定 = new Set()
|
|
92
|
+
for (const 件 of 待你的(库)) (件.类 === '答' ? 等答 : 等定).add(String(件.节点))
|
|
93
|
+
for (const 方 of 待定方案们(库)) 等定.add(String(方.提的))
|
|
94
|
+
return 号 => 等答.has(String(号)) ? '回答' : 等定.has(String(号)) ? '确认' : ''
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 给图纸的一份;不是 Blueprint 项目 → null。 */
|
|
98
|
+
export function 树Of(根, 在跑 = () => false, 跑过 = () => true, 断了 = () => false) {
|
|
99
|
+
const 库 = 开信息库(String(根))
|
|
100
|
+
if (!库) return null
|
|
101
|
+
const 节点们 = {}, 状态Of = 状态表(库, 在跑, 跑过, 断了)
|
|
102
|
+
const 等你什么Of = 等你什么表(库)
|
|
103
|
+
for (const 节 of 全部节点(库)) {
|
|
104
|
+
const 版们 = 版本们(库, 节.编号)
|
|
105
|
+
节点们[节.编号] = {
|
|
106
|
+
编号: 节.编号, 类型: 节.类型 || '普通', 名字: 节.名字 || '', 描述: 节.描述 || '',
|
|
107
|
+
上一层: 节.上一层 ?? null, 序: Number(节.序) || 0,
|
|
108
|
+
下一层们: 排好(下面Of(库, 节.编号)),
|
|
109
|
+
状态: 状态Of(节),
|
|
110
|
+
...(状态Of(节) === '等你' && 等你什么Of(String(节.编号)) ? { 等你什么: 等你什么Of(String(节.编号)) } : {}),
|
|
111
|
+
会话: 节.会话 || '', 大师: 节.专家 || '', 版本数: 版们.length, 当前版: 版们.find(版 => 版.当前)?.第几版 || 版们.length + 1, 缩略: 节.缩略 || '', 标记: !!节.标记,
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// 队员(11-27,内核 队员.js):节点自己开的子 agent,挂在开它的节点(或队员)后面,排在那个节点自己的下一层后面。
|
|
115
|
+
// 状态照它自己的会话:在跑是在做;最后一次正常收尾是交了;别的收尾(按了停、出错、撞上限)、没记到收尾就不在跑了(重启切断)都是停了。
|
|
116
|
+
// 卡上只有开始、暂停、删除(用户:「只能删除或者开始暂停」),没有版本、标记、换类型。
|
|
117
|
+
for (const 员 of 队员们(库)) {
|
|
118
|
+
const 跑着 = 在跑({ 类型: 员.由 === 'dsh' ? '普通' : 员.由, 会话: 员.会话, 编号: 员.编号 })
|
|
119
|
+
节点们[员.编号] = {
|
|
120
|
+
编号: 员.编号, 类型: 员.由 === 'dsh' ? '普通' : 员.由, 名字: 员.名字 || 员.编号, 描述: '', 上一层: 员.父, 序: 0, 下一层们: [],
|
|
121
|
+
状态: 跑着 ? '在做' : 员.结束 === 'completed' ? '交了' : '停了',
|
|
122
|
+
会话: 员.会话, 大师: '', 版本数: 0, 当前版: 1, 缩略: '', 标记: false, 队员: true, 由: 员.由,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
for (const 员 of 队员们(库)) 节点们[员.父]?.下一层们.push(员.编号)
|
|
126
|
+
const 方案们 = 待定方案们(库).map(方 => ({ 号: 方.号, 提的: 方.提的, 节点们: 方.节点们 || [], 时间: 方.时间 }))
|
|
127
|
+
const 收件们 = 待你的(库).map(件 => ({ 号: 件.号, 节点: 件.节点, 类: 件.类, 内容: 件.内容 || '', 时间: 件.时间 }))
|
|
128
|
+
const 管 = 总管Of(库)
|
|
129
|
+
const 总管 = 管 ? { 编号: 管.编号, 会话: 管.会话 || '', 状态: 状态Of(管) } : null
|
|
130
|
+
return { 根们: 排好(全部根(库)), 节点们, 方案们, 收件们, 模型: 项目模型(库), 总管 }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** 一个节点一行;没有 信息.db 不是 Blueprint 项目 → null。零节点的项目 rows 是空的。 */
|
|
134
|
+
export async function 读名册(根) {
|
|
135
|
+
const 库 = 开信息库(String(根))
|
|
136
|
+
if (!库) return null
|
|
137
|
+
return { rows: 全部节点(库).map(节 => ({
|
|
138
|
+
id: 节.编号, kind: 节.类型 || '普通', 类型: 节.类型 || '普通', role: 'dock', name: 节.名字 || '', goal: 节.描述 || '',
|
|
139
|
+
parent: 节.上一层 ?? null, session: 节.会话 || '', expert: 节.专家 || '', order: Number(节.序) || 0,
|
|
140
|
+
gave: 排好(下面Of(库, 节.编号)), status: '开工', state: '', waiting: [], wait: null,
|
|
141
|
+
})) }
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/** 旧名册有进程内的变更通知;新库没有。项目分组还有 session/created 和项目存储两路触发,这里不另听。 */
|
|
145
|
+
export const 听名册 = () => () => {}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 项目这一层(11-22 自由蓝图):一张蓝图=一个文件夹。
|
|
3
|
+
* - 新项目:在保存位置新建一个空文件夹(自己一个 git 仓库)+ `系统文档/信息.db`(零节点)。不开会话、不发话,打开就是一张空画布。
|
|
4
|
+
* - 打开已有文件夹:只在里面建 `系统文档/` 和信息库,别的文件一个不动。已经是 Blueprint 项目的,直接拿来用。
|
|
5
|
+
* - 删除项目:停稳项目里的会话,再交给系统回收站。只删在保存位置里建的项目;打开的已有文件夹不挪进回收站(那是用户自己的文件夹)。
|
|
6
|
+
*/
|
|
7
|
+
import { execFile } from 'node:child_process'
|
|
8
|
+
import { promisify } from 'node:util'
|
|
9
|
+
import { existsSync } from 'node:fs'
|
|
10
|
+
import { appendFile, lstat, mkdir, readFile, realpath, stat, writeFile } from 'node:fs/promises'
|
|
11
|
+
import { basename, dirname, isAbsolute, join, parse, resolve } from 'node:path'
|
|
12
|
+
import { homedir } from 'node:os'
|
|
13
|
+
import { 开信息库, 关信息库, 信息库路径, 节点们 } from '../../blueprint-defaults/src/index.js'
|
|
14
|
+
import { 写子代理设置 } from '../../blueprint-defaults/src/外部agent/开关.js'
|
|
15
|
+
import { 初始化项目名称 } from './借来的/项目名称.js'
|
|
16
|
+
import { 删除中的项目 } from './借来的/项目删除状态.js'
|
|
17
|
+
import { 关闭节点终端 } from './借来的/终端.js'
|
|
18
|
+
|
|
19
|
+
const 文档夹名 = '系统文档'
|
|
20
|
+
const service = (ctx, name) => ctx.get?.(name) || ctx.root?.get?.(name)
|
|
21
|
+
const run = promisify(execFile)
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 项目文件夹自己是一个 git 仓库(11-14)。dsh 的 workspace-changes 每轮开头对 `git rev-parse` 找到的整个工作树拍快照,连没纳入 git 的文件;
|
|
25
|
+
* 项目放在别的大仓库里面时,扫的是外面那个仓库(第一次真跑:两万多个文件撞上 30 秒超时)。在项目里 git init,快照只扫这个项目。
|
|
26
|
+
* 信息.db 变得很勤、又是二进制,写进 .gitignore;系统文档整个写进 .git/info/exclude(模型看不到,重写 .gitignore 也冲不掉)。
|
|
27
|
+
* 已经是仓库的不动;没有 git、建不成,照样建项目。
|
|
28
|
+
*/
|
|
29
|
+
export const 项目忽略 = '# Blueprint 建项目时写的:节点状态库变得很勤、又是二进制,不进 dsh 每轮的快照和改动。\n系统文档/信息.db*\n'
|
|
30
|
+
export const 项目排除 = '\n# Blueprint 建项目时写的:系统文档是程序记账,不进 dsh 每轮的快照和改动卡。\n系统文档/\n'
|
|
31
|
+
export async function 建项目仓库(根, { git = 'git' } = {}) {
|
|
32
|
+
if (existsSync(join(根, '.git'))) return false
|
|
33
|
+
try {
|
|
34
|
+
await run(git, ['init', '-q'], { cwd: 根, timeout: 15_000 })
|
|
35
|
+
if (!existsSync(join(根, '.gitignore'))) await writeFile(join(根, '.gitignore'), 项目忽略)
|
|
36
|
+
await mkdir(join(根, '.git', 'info'), { recursive: true })
|
|
37
|
+
await appendFile(join(根, '.git', 'info', 'exclude'), 项目排除)
|
|
38
|
+
return true
|
|
39
|
+
} catch (error) {
|
|
40
|
+
console.log(`Blueprint: ⚠️ 项目里没建成 git 仓库,dsh 每轮的快照会扫到外面 —— ${error.message}`)
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** 文件夹里立起一张蓝图:项目名、信息库(零节点)、外部 agent 的开关(给了就用,没给沿用上次保存的默认)。 */
|
|
46
|
+
async function 立项(根, 名字, { 子代理, Agent默认 } = {}) {
|
|
47
|
+
await mkdir(join(根, 文档夹名), { recursive: true })
|
|
48
|
+
await 初始化项目名称(根, 名字)
|
|
49
|
+
开信息库(根, { 新建: true, 项目名: 名字 })
|
|
50
|
+
const 选 = 子代理 || await Agent默认?.read().then(默认 => 默认.设过 ? 默认 : null, () => null)
|
|
51
|
+
if (选) await 写子代理设置(根, 选)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 新项目:`项目夹/名字` 新建一个空文件夹(已经有了就拒,不悄悄改名)。回项目文件夹。 */
|
|
55
|
+
export async function 建项目(项目夹, 名字, options = {}) {
|
|
56
|
+
const 根 = join(项目夹, 名字)
|
|
57
|
+
if (existsSync(根)) throw new Error(`已经有一个叫「${名字}」的文件夹了(${根})—— 换个名字`)
|
|
58
|
+
await mkdir(根)
|
|
59
|
+
await 建项目仓库(根)
|
|
60
|
+
await 立项(根, 名字, options)
|
|
61
|
+
return 根
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** 没给名字时的文件夹名:新项目、新项目 2、新项目 3…… */
|
|
65
|
+
export function 空名字(项目夹, 底 = '新项目') {
|
|
66
|
+
for (let i = 1; ; i++) { const 名 = i === 1 ? 底 : `${底} ${i}`; if (!existsSync(join(项目夹, 名))) return 名 }
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 打开已有文件夹:完整路径、在、是文件夹、不是根目录和家目录(`禁止们` 再加别的,比如数据根)、不在另一个项目里面。
|
|
71
|
+
* 已经是 Blueprint 项目的直接回;不是的只建 `系统文档/` 和信息库。回 { 根, 新立 }。
|
|
72
|
+
*/
|
|
73
|
+
export async function 打开文件夹(路径, { 禁止们 = [], ...options } = {}) {
|
|
74
|
+
const 写的 = typeof 路径 === 'string' ? 路径.trim() : ''
|
|
75
|
+
if (!写的 || 写的.length > 4096 || /[\x00-\x1f]/.test(写的)) throw new Error('请选择有效的文件夹路径')
|
|
76
|
+
if (!isAbsolute(写的)) throw new Error('请用文件夹的完整路径')
|
|
77
|
+
let 根
|
|
78
|
+
try { 根 = await realpath(resolve(写的)) } catch { throw new Error(`找不到这个文件夹:${写的}`) }
|
|
79
|
+
if (!(await stat(根)).isDirectory()) throw new Error(`${根} 不是一个文件夹`)
|
|
80
|
+
const 挡 = await Promise.all([homedir(), ...禁止们].map(p => realpath(p).catch(() => resolve(p))))
|
|
81
|
+
if (根 === parse(根).root || 挡.includes(根)) throw new Error('请选择一个专门的项目文件夹,不要选根目录、家目录或 Blueprint 自己的数据目录')
|
|
82
|
+
if (existsSync(信息库路径(根))) return { 根, 新立: false }
|
|
83
|
+
for (let 上 = dirname(根); 上 !== dirname(上); 上 = dirname(上))
|
|
84
|
+
if (existsSync(信息库路径(上))) throw new Error(`这个文件夹在另一个项目(${上})里面 —— 直接打开那个项目`)
|
|
85
|
+
await 立项(根, basename(根), options)
|
|
86
|
+
await 排除系统文档(根)
|
|
87
|
+
return { 根, 新立: true }
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 已经是 git 仓库的文件夹:把 `系统文档/` 写进本机的 `.git/info/exclude`(不进提交、不改用户的文件),免得程序记账出现在 dsh 每轮的改动卡上。 */
|
|
91
|
+
async function 排除系统文档(根) {
|
|
92
|
+
const 信息夹 = join(根, '.git', 'info')
|
|
93
|
+
try {
|
|
94
|
+
if (!(await stat(join(根, '.git'))).isDirectory()) return
|
|
95
|
+
await mkdir(信息夹, { recursive: true })
|
|
96
|
+
const 路径 = join(信息夹, 'exclude')
|
|
97
|
+
const 有了 = existsSync(路径) ? (await readFile(路径, 'utf8')).split('\n').some(行 => 行.trim() === '系统文档/') : false
|
|
98
|
+
if (!有了) await appendFile(路径, 项目排除)
|
|
99
|
+
} catch {}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ── 删除项目 ──────────────────────────────────────────────────────────────
|
|
103
|
+
|
|
104
|
+
const requests = new Map()
|
|
105
|
+
/** 移进系统的废纸篓/回收站(11-30 加 Windows):Windows 用系统自带的 VisualBasic 文件接口,路径经环境变量传,不拼进命令。 */
|
|
106
|
+
async function 系统回收站(root) {
|
|
107
|
+
if (process.platform === 'darwin') return void await run('/usr/bin/trash', ['-s', root])
|
|
108
|
+
if (process.platform === 'win32') {
|
|
109
|
+
const 脚本 = "Add-Type -AssemblyName Microsoft.VisualBasic; [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteDirectory($env:BLUEPRINT_TRASH_PATH, 'OnlyErrorDialogs', 'SendToRecycleBin')"
|
|
110
|
+
await run('powershell.exe', ['-NoProfile', '-NonInteractive', '-Command', 脚本], { env: { ...process.env, BLUEPRINT_TRASH_PATH: root }, windowsHide: true })
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
throw new Error('此部署暂不支持系统回收站,项目文件未移动')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** 只删保存位置里的 Blueprint 项目文件夹(`projectRoot` 是它所在的保存位置;不在保存位置里的=打开的已有文件夹,不删)。 */
|
|
117
|
+
async function 验项目(root, projectRoot) {
|
|
118
|
+
const [canonical, info] = await Promise.all([realpath(root), lstat(root)])
|
|
119
|
+
if (!info.isDirectory() || info.isSymbolicLink() || canonical !== resolve(root)) throw new Error('只能删除完整的 Blueprint 项目目录,不能移动符号链接')
|
|
120
|
+
if (!projectRoot) throw new Error('这是打开的已有文件夹,不挪进回收站:要删,在访达里自己删')
|
|
121
|
+
if (dirname(canonical) !== await realpath(projectRoot)) throw new Error('只能删除项目目录下的完整 Blueprint 项目')
|
|
122
|
+
const 库 = 开信息库(root)
|
|
123
|
+
if (!库) throw new Error('这个文件夹不是 Blueprint 项目')
|
|
124
|
+
return { 库, dev: info.dev, ino: info.ino }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** 这个项目的所有 agent:工作目录在项目里的,或者没有工作目录、顺着父会话认回到项目里的。 */
|
|
128
|
+
function 项目Actors(ctx, root, sessions) {
|
|
129
|
+
return [...ctx.root.agents.list()].filter(actor => {
|
|
130
|
+
let session = actor.session
|
|
131
|
+
const seen = new Set()
|
|
132
|
+
while (session && !seen.has(session.id)) {
|
|
133
|
+
if (session.header?.cwd) return resolve(session.header.cwd) === root
|
|
134
|
+
if (sessions.has(session.id)) return true
|
|
135
|
+
seen.add(session.id)
|
|
136
|
+
const parent = session.header?.parentSession
|
|
137
|
+
session = ctx.root.agents.get(parent)?.session || ctx.sessions.get(parent)
|
|
138
|
+
}
|
|
139
|
+
return false
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function 停稳项目(ctx, root, sessionIds) {
|
|
144
|
+
const handled = new Set()
|
|
145
|
+
for (let pass = 0; pass < 5; pass++) {
|
|
146
|
+
const fresh = 项目Actors(ctx, root, sessionIds).filter(actor => !handled.has(actor))
|
|
147
|
+
if (!fresh.length) return
|
|
148
|
+
for (const actor of fresh) { handled.add(actor); sessionIds.add(actor.session.id); actor.cancel({ kind: 'user' }, { keepInbox: true }) }
|
|
149
|
+
await Promise.all(fresh.map(actor => actor.whenIdle?.()))
|
|
150
|
+
await 关闭节点终端(ctx, fresh, '用户删除项目,关闭所属终端')
|
|
151
|
+
await Promise.all(fresh.map(actor => ctx.sessions.flush?.(actor.session)))
|
|
152
|
+
}
|
|
153
|
+
throw new Error('项目仍有新执行产生,请稍后重试删除')
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** 用户确认后停稳整个项目,再交给 macOS 原生回收站;会话日志保留。项目按文件夹认(零节点的项目没有会话)。 */
|
|
157
|
+
export function 删除项目(ctx, directory, payload, { projectRoot, beforeMove = async () => {}, trash = 系统回收站 } = {}) {
|
|
158
|
+
const { projectPath, requestId } = payload || {}
|
|
159
|
+
if (!directory || !projectPath || typeof requestId !== 'string' || !requestId || requestId.length > 200)
|
|
160
|
+
throw new Error('删除缺少项目目录或请求编号')
|
|
161
|
+
const root = resolve(directory)
|
|
162
|
+
if (resolve(projectPath) !== root) throw new Error('项目路径对不上,请刷新后重试')
|
|
163
|
+
const key = JSON.stringify([root, requestId])
|
|
164
|
+
if (requests.has(key)) return requests.get(key)
|
|
165
|
+
if (删除中的项目.has(root)) throw new Error('项目正在移入回收站,请等待完成')
|
|
166
|
+
删除中的项目.add(root)
|
|
167
|
+
const task = (async () => {
|
|
168
|
+
const original = await 验项目(root, projectRoot)
|
|
169
|
+
const registry = service(ctx, 'workspaceRegistry')
|
|
170
|
+
if (!registry?.list || !registry?.delete || !registry?.create) throw new Error('工作区服务不可用,项目文件未移动')
|
|
171
|
+
const sessionIds = new Set(节点们(original.库).map(节 => 节.会话).filter(Boolean))
|
|
172
|
+
await 停稳项目(ctx, root, sessionIds)
|
|
173
|
+
await beforeMove([...sessionIds])
|
|
174
|
+
const current = await 验项目(root, projectRoot)
|
|
175
|
+
if (current.dev !== original.dev || current.ino !== original.ino) throw new Error('项目目录已被替换,未移动文件')
|
|
176
|
+
const removed = []
|
|
177
|
+
try {
|
|
178
|
+
for (const workspace of registry.list()) {
|
|
179
|
+
if (await realpath(workspace.path).catch(() => '') !== root) continue
|
|
180
|
+
removed.push({ path: workspace.path, title: workspace.title, sessionIds: [...workspace.sessionIds] })
|
|
181
|
+
await registry.delete(workspace.id)
|
|
182
|
+
}
|
|
183
|
+
关信息库(root) // 先关掉 信息.db 的连接,再整个文件夹挪走
|
|
184
|
+
await trash(root)
|
|
185
|
+
if (await lstat(root).then(() => true, () => false)) throw new Error('系统未完成文件夹移动')
|
|
186
|
+
} catch (error) {
|
|
187
|
+
if (await lstat(root).then(() => true, () => false)) {
|
|
188
|
+
try {
|
|
189
|
+
for (const record of removed) {
|
|
190
|
+
const workspace = await registry.create(record.path, record.title || basename(record.path))
|
|
191
|
+
for (const id of record.sessionIds) await workspace.attachSession(id)
|
|
192
|
+
}
|
|
193
|
+
} catch (restoreError) { throw new AggregateError([error, restoreError], '项目文件仍在原位,工作区登记恢复失败,请刷新项目列表') }
|
|
194
|
+
throw new Error(`未移入回收站,项目文件仍在原位,执行已停下:${error.message}`)
|
|
195
|
+
}
|
|
196
|
+
throw error
|
|
197
|
+
}
|
|
198
|
+
return { trashed: true, projectPath: root, sessionIds: [...sessionIds] }
|
|
199
|
+
})()
|
|
200
|
+
requests.set(key, task)
|
|
201
|
+
task.then(() => { while (requests.size > 64) requests.delete(requests.keys().next().value) }, () => requests.delete(key))
|
|
202
|
+
return task.finally(() => 删除中的项目.delete(root))
|
|
203
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 旧功能的桩(2026-11-09 搬回 Blueprint 前端):新系统里没有这些功能,接口和界面留着(他「保留所有前端」),
|
|
3
|
+
* 这里只回一个不让调用方崩的值。以后要哪个,再接新系统。
|
|
4
|
+
* 出处:旧 node 的 回答、人工审核、条件等待、纸条等待、会话(续工)、重启、项目隔离;旧 context 的 公共前缀。
|
|
5
|
+
* 协作方式(co-create/solo)11-22 撤了。
|
|
6
|
+
*/
|
|
7
|
+
const 没有 = 功能 => { throw new Error(`新系统里没有${功能}`) }
|
|
8
|
+
|
|
9
|
+
// 人工审核、自动批准(权限审批:新版默认全权限、不审批)、条件等待
|
|
10
|
+
export const 读人工审核 = async () => ({ enabled: true, mode: '', solo: false })
|
|
11
|
+
export const 自动批准 = async () => null
|
|
12
|
+
export const 复查项目等待 = async () => 0
|
|
13
|
+
|
|
14
|
+
// 纸条、续工、重启
|
|
15
|
+
export const 停下等回条 = async () => ({ stopped: false, waitingForNotes: [] })
|
|
16
|
+
export const 准备节点续工 = async (_ctx, _root, id) => ({ id, resumable: true, completed: false, waitingForChildren: [] })
|
|
17
|
+
export const 重启节点 = async () => 没有('节点重启:要重做,对 Producer 说')
|
|
18
|
+
|
|
19
|
+
// 项目隔离:终端不再套项目沙箱
|
|
20
|
+
export const 在项目终端执行域 = (_ctx, _agent, fn) => fn()
|
|
21
|
+
|
|
22
|
+
// 外部节点(类型是 codex/claude-code,交给它们的程序跑):实现在 defaults 的 外部agent/外部worker.js。这里只把旧名字对上,index.js 里用的地方不用改。
|
|
23
|
+
// 用整包导入再取名字:那边的函数改名、撤掉时这里退成空的,不会让整个后台起不来。
|
|
24
|
+
import * as 外部 from '../../blueprint-defaults/src/外部agent/外部worker.js'
|
|
25
|
+
export const 外部run清单 = (...参数) => 外部.外部worker清单?.(...参数) ?? []
|
|
26
|
+
export const 听外部run变化 = fn => 外部.听外部worker变化?.(fn) ?? (() => {})
|
|
27
|
+
export const 停外部run = (...参数) => 外部.停外部worker?.(...参数)
|
|
28
|
+
export const 停项目外部run = async (...参数) => await 外部.停项目外部worker?.(...参数) ?? []
|
|
29
|
+
/** 这个外部节点的程序此刻在不在跑。 */
|
|
30
|
+
export const 外部在跑 = (根, 编号) => !!外部.外部worker在跑?.(根, 编号)
|
|
31
|
+
|
|
32
|
+
// 旧的公共前缀由宿主拼了(每个节点的开场)
|
|
33
|
+
export const 拼公共前缀 = () => ''
|
|
34
|
+
export const 节点提示身份 = s => s
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/** 界面的只读材料浏览:只列一层目录,只读取当前页文件的元数据。 */
|
|
2
|
+
import { readdir, stat, open } from 'node:fs/promises'
|
|
3
|
+
import { join } from 'node:path'
|
|
4
|
+
import { 检查产物 } from './借来的/产物.js'
|
|
5
|
+
import { 产物路径, 产物类型, 安全产物文件 } from './产物.js'
|
|
6
|
+
|
|
7
|
+
const options = {any:true, includeTemporary:true, includeEvidence:true}
|
|
8
|
+
const processRoots = ['.blueprint-tmp', '.blueprint-evidence']
|
|
9
|
+
const pageNumber = (value, fallback, max) => {
|
|
10
|
+
if (value === undefined || value === null || value === '') return fallback
|
|
11
|
+
const number = Number(value)
|
|
12
|
+
if (!Number.isSafeInteger(number) || number < 0) throw new Error('分页参数无效')
|
|
13
|
+
return Math.min(number, max)
|
|
14
|
+
}
|
|
15
|
+
export function 材料分页(items, {offset, limit, query = '', kind = ''} = {}) {
|
|
16
|
+
const search = String(query).trim().toLocaleLowerCase()
|
|
17
|
+
const filtered = items.filter(item => (!kind || item.directory || item.kind === kind)
|
|
18
|
+
&& (!search || `${item.title} ${item.path} ${item.nodeName || ''}`.toLocaleLowerCase().includes(search)))
|
|
19
|
+
const start = pageNumber(offset, 0, Number.MAX_SAFE_INTEGER), size = Math.max(1, pageNumber(limit, 60, 100))
|
|
20
|
+
return {items:filtered.slice(start, start + size), total:filtered.length, offset:start, limit:size, more:start + size < filtered.length}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function head(file, size = 2048) {
|
|
24
|
+
const handle = await open(file, 'r')
|
|
25
|
+
try {
|
|
26
|
+
const buffer = Buffer.alloc(size), {bytesRead} = await handle.read(buffer, 0, size, 0)
|
|
27
|
+
return buffer.subarray(0, bytesRead).toString('utf8')
|
|
28
|
+
} finally { await handle.close() }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function metadata(root, entry, session) {
|
|
32
|
+
const checked = await 检查产物(root, {entry:entry.path}, options)
|
|
33
|
+
const file = await 安全产物文件(root, checked.path), info = await stat(file)
|
|
34
|
+
const kind = 产物类型(checked.path)
|
|
35
|
+
const item = {...checked, kind:checked.directory && kind !== 'playable' ? 'file' : kind, session,
|
|
36
|
+
id:checked.path, available:true, modified:info.mtimeMs, size:info.size, history:[], declared:false}
|
|
37
|
+
if (checked.directory) {
|
|
38
|
+
try {
|
|
39
|
+
const explanation = await 检查产物(root, {entry:join(checked.path, '说明.md')}, options)
|
|
40
|
+
item.description = (await head(await 安全产物文件(root, explanation.path))).split(/\r?\n/)[0].replace(/^#+\s*/, '')
|
|
41
|
+
item.explanationPath = explanation.path
|
|
42
|
+
} catch { /* 未上架和临时文件夹仍可浏览。 */ }
|
|
43
|
+
}
|
|
44
|
+
return item
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 有界缓存只保存目录名;不会递归扫描、解码图片、运行工程或生成缩略图。 */
|
|
48
|
+
export function 创建材料目录({ttl = 5000, maxEntries = 128, now = Date.now, readDirectory = readdir} = {}) {
|
|
49
|
+
const cache = new Map(), pending = new Map()
|
|
50
|
+
const remember = (key, value) => {
|
|
51
|
+
cache.delete(key); cache.set(key, value)
|
|
52
|
+
while (cache.size > maxEntries) cache.delete(cache.keys().next().value)
|
|
53
|
+
}
|
|
54
|
+
async function entries(root, path) {
|
|
55
|
+
const checked = await 检查产物(root, {entry:path}, options)
|
|
56
|
+
if (!checked.directory) throw new Error('请选择材料目录')
|
|
57
|
+
const file = await 安全产物文件(root, checked.path), key = root + '\0' + checked.path
|
|
58
|
+
const stamp = (await stat(file)).mtimeMs, cached = cache.get(key)
|
|
59
|
+
if (cached && cached.stamp === stamp && now() - cached.time < ttl) return cached.items
|
|
60
|
+
if (pending.has(key)) return pending.get(key)
|
|
61
|
+
const task = (async () => {
|
|
62
|
+
const names = await readDirectory(file, {withFileTypes:true})
|
|
63
|
+
const items = names.filter(entry => !entry.isSymbolicLink() && (entry.isDirectory() || entry.isFile()))
|
|
64
|
+
.map(entry => ({path:checked.path + '/' + entry.name, title:entry.name, directory:entry.isDirectory(), kind:entry.isDirectory() ? 'file' : 产物类型(entry.name)}))
|
|
65
|
+
.filter(entry => 产物路径(root, entry.path, options))
|
|
66
|
+
.sort((a, b) => Number(b.directory) - Number(a.directory) || a.title.localeCompare(b.title, 'zh-CN', {numeric:true}))
|
|
67
|
+
remember(key, {stamp, time:now(), items})
|
|
68
|
+
return items
|
|
69
|
+
})()
|
|
70
|
+
pending.set(key, task)
|
|
71
|
+
try { return await task } finally { pending.delete(key) }
|
|
72
|
+
}
|
|
73
|
+
return async function list(root, {session, view = 'assets', path = '', ...filter} = {}) {
|
|
74
|
+
if (!['assets','process','used'].includes(view)) throw new Error('材料范围无效')
|
|
75
|
+
const normalized = path ? 产物路径(root, path, options)?.path : ''
|
|
76
|
+
if (path && !normalized) throw new Error('材料路径无效')
|
|
77
|
+
if (normalized && view === 'assets' && normalized !== '素材' && !normalized.startsWith('素材/')) throw new Error('请选择素材目录')
|
|
78
|
+
if (normalized && view === 'process' && !processRoots.some(p => normalized === p || normalized.startsWith(p + '/'))) throw new Error('请选择过程材料目录')
|
|
79
|
+
const selected = normalized || (view === 'assets' ? '素材' : '')
|
|
80
|
+
let candidates
|
|
81
|
+
try {
|
|
82
|
+
candidates = selected ? await entries(root, selected) : (await Promise.all(processRoots.map(async path => {
|
|
83
|
+
try {
|
|
84
|
+
await 检查产物(root, {entry:path}, options)
|
|
85
|
+
return {path, title:path === '.blueprint-tmp' ? '临时材料' : '网页与来源记录', directory:true, kind:'file'}
|
|
86
|
+
} catch { return null }
|
|
87
|
+
}))).filter(Boolean)
|
|
88
|
+
} catch (error) {
|
|
89
|
+
if (error.code !== 'ENOENT') throw error
|
|
90
|
+
candidates = []
|
|
91
|
+
}
|
|
92
|
+
const page = 材料分页(candidates, filter)
|
|
93
|
+
// 单页最多 100 项,文件读取限定在这一页;某个文件正在移动时不妨碍其余入口。
|
|
94
|
+
const items = (await Promise.all(page.items.map(entry => metadata(root, entry, session).catch(() => null)))).filter(Boolean)
|
|
95
|
+
return {...page, items, path:selected, view, shared:true}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
/** 画树用的瘦账落盘(2026-10-15):重启后第一次打开项目,不再把每个节点的账本整份解开。
|
|
5
|
+
钥匙是原生 persistence 给的账本版本号(文件身份+大小+修改时刻):版本号一字不差才用,差一点就当没有。
|
|
6
|
+
`格式` 是瘦账长相的指纹,`瘦一条()`/`瘦身()` 一改,旧摘要自动作废。
|
|
7
|
+
账本永远是准的那一份;这里丢了、坏了、写不进去,都只是回到现读。 */
|
|
8
|
+
export function 创建树摘要盘(目录, 格式) {
|
|
9
|
+
const 文件 = id => /^[A-Za-z0-9_-]+$/.test(id) ? join(目录, id + '.json') : null
|
|
10
|
+
let 报过 = false
|
|
11
|
+
return {
|
|
12
|
+
async 读(id, 版) {
|
|
13
|
+
const f = 文件(String(id))
|
|
14
|
+
if (!f || 版 == null) return null
|
|
15
|
+
let x
|
|
16
|
+
try { x = JSON.parse(await readFile(f, 'utf8')) } catch { return null }
|
|
17
|
+
if (x?.格式 !== 格式 || x.版 !== String(版) || !Array.isArray(x.瘦) || !Number.isInteger(x.总数)) return null
|
|
18
|
+
const 瘦 = x.瘦
|
|
19
|
+
瘦.总数 = x.总数
|
|
20
|
+
return { 瘦, 继承: x.继承 }
|
|
21
|
+
},
|
|
22
|
+
async 写(id, 版, 继承, 瘦) {
|
|
23
|
+
const f = 文件(String(id))
|
|
24
|
+
if (!f || 版 == null) return
|
|
25
|
+
const 临时 = `${f}.${process.pid}.${Date.now()}.tmp`
|
|
26
|
+
try {
|
|
27
|
+
const 文 = JSON.stringify({ 格式, 版: String(版), 继承, 总数: 瘦.总数, 瘦 }) // 先定下这一刻的样子,再等盘
|
|
28
|
+
await mkdir(目录, { recursive: true })
|
|
29
|
+
await writeFile(临时, 文)
|
|
30
|
+
await rename(临时, f)
|
|
31
|
+
} catch (error) {
|
|
32
|
+
await rm(临时, { force: true }).catch(() => {})
|
|
33
|
+
if (!报过) { 报过 = true; console.log(`Blueprint studio: 画树摘要存不进 ${目录} —— ${error?.message || error}(照常现读)`) }
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { interruptedTurnClosers } from '@deepseek-ai/dsh-session'
|
|
2
|
+
|
|
3
|
+
/** 树只读经原生 persistence 校验的事件,不为展示恢复一个完整 Session。 */
|
|
4
|
+
export async function 读树账本(persistence, id) {
|
|
5
|
+
const handle = await persistence.open(id, 'read')
|
|
6
|
+
try {
|
|
7
|
+
const { events } = await handle.read(0)
|
|
8
|
+
return { inheritedEventCount: handle.inheritedEventCount,
|
|
9
|
+
events: [...events, ...interruptedTurnClosers(events)] }
|
|
10
|
+
} finally { await handle.close() }
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* 服务端的界面语言:服务端拼给界面看的句子(砖上状态句、运行列表)跟界面同一种语言。
|
|
2
|
+
页面接上 dsh 的语言后报上来(POST /api/ui-language),这里记住;没报过时是中文。
|
|
3
|
+
翻译用和界面同一份机制和英文表;只在给界面的那一层包 译(),模型读的文字不经这里。 */
|
|
4
|
+
import { readFileSync, existsSync } from 'node:fs'
|
|
5
|
+
import { fileURLToPath } from 'node:url'
|
|
6
|
+
|
|
7
|
+
// 机制和英文表在仓库的 viewer/;装成插件时打包脚本把这两份放进本包的 viewer/(11-21)。本包有就用本包的。
|
|
8
|
+
const 本包 = new URL('../viewer/', import.meta.url)
|
|
9
|
+
const 夹 = existsSync(fileURLToPath(new URL('界面语言.js', 本包))) ? 本包 : new URL('../../../../viewer/', import.meta.url)
|
|
10
|
+
const { 译, 译境, 登记英文, 接上语言 } = await import(new URL('界面语言.js', 夹).href)
|
|
11
|
+
|
|
12
|
+
export { 译, 译境 }
|
|
13
|
+
|
|
14
|
+
let 现在 = 'zh'
|
|
15
|
+
const 听众 = new Set()
|
|
16
|
+
接上语言({ locale: { getLocale: () => ({ active: 现在 }), subscribe: fn => { 听众.add(fn); return () => 听众.delete(fn) } }, effect: fn => fn() })
|
|
17
|
+
登记英文(JSON.parse(readFileSync(new URL('英文.json', 夹), 'utf8')))
|
|
18
|
+
|
|
19
|
+
export const 服务端语言 = () => 现在
|
|
20
|
+
|
|
21
|
+
export function 设界面语言(语) {
|
|
22
|
+
if (语 !== 'zh' && 语 !== 'en') throw new Error('语言只认 zh 或 en')
|
|
23
|
+
if (语 !== 现在) { 现在 = 语; for (const fn of [...听众]) fn() }
|
|
24
|
+
return 现在
|
|
25
|
+
}
|