jbc-dssi 1.1.78 → 1.1.79
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 +1 -1
- package/vendor/dssAgent/bridge/index.js +102 -0
package/package.json
CHANGED
|
@@ -48,6 +48,20 @@ const CONVENTIONS_FILE_NAME = 'AGENTS.md';
|
|
|
48
48
|
/** 约定集正文上限:与核心记忆同一口径(够写,挡住整本书)。 */
|
|
49
49
|
const CONVENTIONS_MAX_CHARS = 20000;
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* 焦点记忆(2026-11-06 老谢定):**映射工作区 `ACTIVE.md`**。
|
|
53
|
+
*
|
|
54
|
+
* 为什么是这篇:契约 v1.4 里 `ACTIVE.md` 就是"当前焦点:任务/下一步/阻塞(≤500 字)",
|
|
55
|
+
* 每个会话更新。手机端「记忆库 → 焦点记忆」编辑的就是它 —— 与核心记忆同一套"只发正文、
|
|
56
|
+
* 头由电脑侧维护"的口径(它是极简头 5 字段:id/type/importance/updated_at/status)。
|
|
57
|
+
*
|
|
58
|
+
* 与约定集的区别:约定集是长期默契(AGENTS.md,无头);焦点是**会过期的当前任务**
|
|
59
|
+
* (有头、可清空)—— 所以这里允许空正文,而核心记忆/约定集不允许。
|
|
60
|
+
*/
|
|
61
|
+
const FOCUS_FILE_NAME = 'ACTIVE.md';
|
|
62
|
+
/** 契约里 ACTIVE.md ≤500 字;这里放宽到 2000,挡住"把整本书贴进来"又不卡正常使用。 */
|
|
63
|
+
const FOCUS_MAX_CHARS = 2000;
|
|
64
|
+
|
|
51
65
|
/**
|
|
52
66
|
* 记忆分档(2026-10-24 老谢定,契约 v1.3)—— **6 档,全部由 importance 现算**。
|
|
53
67
|
*
|
|
@@ -1516,6 +1530,81 @@ export function createDssAgentEngine({
|
|
|
1516
1530
|
};
|
|
1517
1531
|
}
|
|
1518
1532
|
|
|
1533
|
+
/**
|
|
1534
|
+
* 读取「焦点记忆」正文 —— 文件是工作区 `ACTIVE.md`(极简头 5 字段)。
|
|
1535
|
+
*
|
|
1536
|
+
* 与核心记忆同口径:手机端只收正文,头字段不下发;空文件/无文件 → exists:false。
|
|
1537
|
+
*/
|
|
1538
|
+
async function readFocus(payload = {}) {
|
|
1539
|
+
await start();
|
|
1540
|
+
const entityId = resolveEntityId(payload);
|
|
1541
|
+
const path = join(entityDir(entityId), FOCUS_FILE_NAME);
|
|
1542
|
+
let raw = '';
|
|
1543
|
+
try {
|
|
1544
|
+
raw = await fs.readFile(path, 'utf8');
|
|
1545
|
+
} catch (err) {
|
|
1546
|
+
if (err?.code === 'ENOENT') {
|
|
1547
|
+
return { entityId, fileName: FOCUS_FILE_NAME, text: '', chars: 0, exists: false };
|
|
1548
|
+
}
|
|
1549
|
+
throw new Error(`读取焦点记忆失败:${err?.message ?? err}`);
|
|
1550
|
+
}
|
|
1551
|
+
const { body, header } = splitContractHeader(raw);
|
|
1552
|
+
let updatedAt = headerValue(header, 'updated_at', '最新更新时间');
|
|
1553
|
+
if (!updatedAt) {
|
|
1554
|
+
try {
|
|
1555
|
+
updatedAt = isoStamp(new Date((await fs.stat(path)).mtimeMs));
|
|
1556
|
+
} catch {
|
|
1557
|
+
// mtime 读不到就不显示时间
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
return {
|
|
1561
|
+
entityId,
|
|
1562
|
+
fileName: FOCUS_FILE_NAME,
|
|
1563
|
+
text: body,
|
|
1564
|
+
chars: countChars(body),
|
|
1565
|
+
exists: true,
|
|
1566
|
+
...(updatedAt ? { updatedAt } : {}),
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
/**
|
|
1571
|
+
* 保存「焦点记忆」正文(工作区 `ACTIVE.md`)。
|
|
1572
|
+
*
|
|
1573
|
+
* 与核心记忆/约定集的区别:**允许清空** —— 焦点是"当前任务",做完了就该能清掉;
|
|
1574
|
+
* 清空后仍然保留契约头(文件不消失),这样下次读取仍然是 exists:true、正文为空。
|
|
1575
|
+
* 原子写(tmp + rename),超长拒绝。
|
|
1576
|
+
*/
|
|
1577
|
+
async function writeFocus(payload = {}) {
|
|
1578
|
+
await start();
|
|
1579
|
+
const entityId = resolveEntityId(payload);
|
|
1580
|
+
const text = typeof payload.text === 'string' ? payload.text : '';
|
|
1581
|
+
if (text.length > FOCUS_MAX_CHARS) {
|
|
1582
|
+
throw new Error(`焦点记忆最多 ${FOCUS_MAX_CHARS} 字`);
|
|
1583
|
+
}
|
|
1584
|
+
const path = join(entityDir(entityId), FOCUS_FILE_NAME);
|
|
1585
|
+
let oldHeader = null;
|
|
1586
|
+
try {
|
|
1587
|
+
oldHeader = splitContractHeader(await fs.readFile(path, 'utf8')).header;
|
|
1588
|
+
} catch (err) {
|
|
1589
|
+
if (err?.code !== 'ENOENT') throw new Error(`读取焦点记忆失败:${err?.message ?? err}`);
|
|
1590
|
+
}
|
|
1591
|
+
// ACTIVE.md 的极简头:缺省 importance 70(焦点不是核心身份)、status draft(会过期的当前任务)
|
|
1592
|
+
const header = buildContractHeader(oldHeader, FOCUS_FILE_NAME, { importance: '70', status: 'draft' })
|
|
1593
|
+
.replace(/\n+$/u, '');
|
|
1594
|
+
const body = text.replace(/\r\n/gu, '\n').replace(/\s+$/u, text.trim() === '' ? '' : '\n');
|
|
1595
|
+
const content = `---\n${header}\n---\n\n${body}`;
|
|
1596
|
+
const tmp = `${path}.tmp-${process.pid}`;
|
|
1597
|
+
await fs.writeFile(tmp, content, 'utf8');
|
|
1598
|
+
await fs.rename(tmp, path);
|
|
1599
|
+
log?.(`[dssAgent] 焦点记忆已保存 entity=${entityId} chars=${Array.from(body).length}`);
|
|
1600
|
+
return {
|
|
1601
|
+
entityId,
|
|
1602
|
+
fileName: FOCUS_FILE_NAME,
|
|
1603
|
+
chars: countChars(body),
|
|
1604
|
+
updatedAt: isoStamp(new Date()),
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1519
1608
|
/** 核心记忆文件位置:优先中文新名,兼容旧名 MEMORY.md;都没有时按新名创建。 */
|
|
1520
1609
|
async function memoryFile(entityId) {
|
|
1521
1610
|
const dir = entityDir(entityId);
|
|
@@ -2711,6 +2800,16 @@ export function createDssAgentEngine({
|
|
|
2711
2800
|
return await readConventions(payload);
|
|
2712
2801
|
case 'write_conventions':
|
|
2713
2802
|
return await writeConventions(payload);
|
|
2803
|
+
/*
|
|
2804
|
+
* 焦点记忆(2026-11-06 老谢定):手机端「记忆库 → 焦点记忆」。
|
|
2805
|
+
* read_focus {entityId?} → { text, chars, fileName, exists, updatedAt }
|
|
2806
|
+
* write_focus {entityId?, text} → { chars, fileName, updatedAt }(允许清空)
|
|
2807
|
+
* 读写的是**工作区 ACTIVE.md**(极简头 5 字段,头由电脑侧维护)。
|
|
2808
|
+
*/
|
|
2809
|
+
case 'read_focus':
|
|
2810
|
+
return await readFocus(payload);
|
|
2811
|
+
case 'write_focus':
|
|
2812
|
+
return await writeFocus(payload);
|
|
2714
2813
|
/*
|
|
2715
2814
|
* 记忆文档(「高频习惯」/「更多记忆」):手机端列表页 + 文档详情页。
|
|
2716
2815
|
* list_memory_docs {entityId?, category:'high'|'mid'|'low'|'fading'|'dormant'}
|
|
@@ -2816,6 +2915,9 @@ export function createDssAgentEngine({
|
|
|
2816
2915
|
/** 约定集读写(= 工作区 AGENTS.md,运行层由 DSH 自动加载)。 */
|
|
2817
2916
|
readConventions,
|
|
2818
2917
|
writeConventions,
|
|
2918
|
+
/** 焦点记忆读写(= 工作区 ACTIVE.md,极简头 5 字段,允许清空)。 */
|
|
2919
|
+
readFocus,
|
|
2920
|
+
writeFocus,
|
|
2819
2921
|
/** 记忆文档(高频习惯 / 更多记忆):列表、读、写。 */
|
|
2820
2922
|
listMemoryDocs,
|
|
2821
2923
|
readMemoryDoc,
|