在FocusNote今日日记中添加文本作为新要点。
Focus Note: 添加到 Daily Note 中是一项面向实际任务的技能,主要用于此技能将用户提供的文本添加到 FocusNote 中的今天的每日注中, 作为新的项目点;它如何工作;
从功能定位来看,该技能强调把分散的操作要求整理成清晰、可复用的处理流程,使用户能够围绕既定目标快速准备输入、选择执行方式并获得结构化结果。实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。
执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。该技能适合用于一次性任务,也可以接入自动化工作流,与其他技能或上层代理配合完成更完整的业务链路;在组合使用时,应明确每一步的输入输出关系,并避免不同步骤之间出现参数冲突。
该技能将用户提供的文本作为新项目符号(bullet point)添加至 FocusNote 中今天的每日笔记。
~/.lucia/documents-path.txt 读取 FocusNote 的文档路径YYYY-MM-DD 格式生成今日日期_structure.json 和 _metadata.json)~/.lucia/documents-path.txt)当用户请求将文本添加至其每日笔记时,请按以下步骤执行:
const fs = require("fs");
const path = require("path");
const os = require("os");
// 从 FocusNote 的配置文件中读取文档路径
const focusnoteConfigPath = path.join(
os.homedir(),
".lucia",
"documents-path.txt",
);
const documentsPath = fs.readFileSync(focusnoteConfigPath, "utf-8").trim();
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, "0");
const day = String(today.getDate()).padStart(2, "0");
const todayDocName = `${year}-${month}-${day}`;
const dailyNotePath = path.join(documentsPath, "notes", todayDocName); const structurePath = path.join(dailyNotePath, "_structure.json"); const metadataPath = path.join(dailyNotePath, "_metadata.json"); const nodesDir = path.join(dailyNotePath, ".nodes");
if (!fs.existsSync(dailyNotePath)) {
// 创建目录结构
fs.mkdirSync(dailyNotePath, { recursive: true });
fs.mkdirSync(nodesDir, { recursive: true });
// 创建元数据文件
const metadata = {
name: todayDocName,
createdAt: Date.now(),
updatedAt: Date.now(),
};
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
// 创建空的结构文件
const structure = {
rootNodeIds: [],
deletedNodeIds: [],
nodes: {},
};
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
}
const { v4: uuidv4 } = require("uuid"); // npm install uuid
// 生成唯一节点 ID
const nodeId = uuidv4();
const timestamp = Date.now();
// 构建 Lexical 格式的项目符号内容结构
const lexicalContent = {
root: {
children: [
{
children: [
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: userText, // 用户输入的文本
type: "text",
version: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "listitem",
version: 1,
value: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "list",
version: 1,
listType: "bullet",
start: 1,
tag: "ul",
},
],
direction: "ltr",
format: "",
indent: 0,
type: "root",
version: 1,
},
};
// 构建节点对象
const newNode = {
id: nodeId,
content: JSON.stringify(lexicalContent),
isFolded: false,
isTodo: false,
isDone: false,
isInProgress: false,
isBlurred: false,
backgroundColor: null,
createdAt: timestamp,
updatedAt: timestamp,
};
// 按节点 ID 的前两个字符进行分片
const shard = nodeId.substring(0, 2);
const shardDir = path.join(nodesDir, shard);
if (!fs.existsSync(shardDir)) {
fs.mkdirSync(shardDir, { recursive: true });
}
const nodeFilePath = path.join(shardDir, `node-${nodeId}.json`);
fs.writeFileSync(nodeFilePath, JSON.stringify(newNode, null, 2));
// 读取当前结构文件
const structure = JSON.parse(fs.readFileSync(structurePath, "utf-8"));
// 将新节点加入结构
structure.rootNodeIds.push(nodeId);
structure.nodes[nodeId] = {
parentId: null,
orderIndex: structure.rootNodeIds.length - 1,
childIds: [],
};
// 更新时间戳
structure.updatedAt = timestamp;
// 写入更新后的结构文件
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
以下是一个可直接使用的完整 Node.js 脚本:
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const os = require("os");
const { v4: uuidv4 } = require("uuid");
function addToDailyNote(userText) {
try {
// 步骤 1:读取文档路径
const focusnoteConfigPath = path.join(
os.homedir(),
".lucia",
"documents-path.txt",
);
if (!fs.existsSync(focusnoteConfigPath)) {
throw new Error(
"FocusNote 配置文件未找到。请确保 FocusNote 正在运行。",
);
}
const documentsPath = fs.readFileSync(focusnoteConfigPath, "utf-8").trim();
// 步骤 2:生成今日日期
const today = new Date();
const year = today.getFullYear();
const month = String(today.getMonth() + 1).padStart(2, "0");
const day = String(today.getDate()).padStart(2, "0");
const todayDocName = `${year}-${month}-${day}`;
// 步骤 3:设置路径
const dailyNotePath = path.join(documentsPath, "notes", todayDocName);
const structurePath = path.join(dailyNotePath, "_structure.json");
const metadataPath = path.join(dailyNotePath, "_metadata.json");
const nodesDir = path.join(dailyNotePath, ".nodes");
// 步骤 4:如需则创建每日笔记目录
if (!fs.existsSync(dailyNotePath)) {
fs.mkdirSync(dailyNotePath, { recursive: true });
fs.mkdirSync(nodesDir, { recursive: true });
const metadata = {
name: todayDocName,
createdAt: Date.now(),
updatedAt: Date.now(),
};
fs.writeFileSync(metadataPath, JSON.stringify(metadata, null, 2));
const structure = {
rootNodeIds: [],
deletedNodeIds: [],
nodes: {},
};
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
}
// 步骤 5:创建新的项目符号节点
const nodeId = uuidv4();
const timestamp = Date.now();
const lexicalContent = {
root: {
children: [
{
children: [
{
children: [
{
detail: 0,
format: 0,
mode: "normal",
style: "",
text: userText,
type: "text",
version: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "listitem",
version: 1,
value: 1,
},
],
direction: "ltr",
format: "",
indent: 0,
type: "list",
version: 1,
listType: "bullet",
start: 1,
tag: "ul",
},
],
direction: "ltr",
format: "",
indent: 0,
type: "root",
version: 1,
},
};
const newNode = {
id: nodeId,
content: JSON.stringify(lexicalContent),
isFolded: false,
isTodo: false,
isDone: false,
isInProgress: false,
isBlurred: false,
backgroundColor: null,
createdAt: timestamp,
updatedAt: timestamp,
};
// 步骤 6:保存节点文件
const shard = nodeId.substring(0, 2);
const shardDir = path.join(nodesDir, shard);
if (!fs.existsSync(shardDir)) {
fs.mkdirSync(shardDir, { recursive: true });
}
const nodeFilePath = path.join(shardDir, `node-${nodeId}.json`);
fs.writeFileSync(nodeFilePath, JSON.stringify(newNode, null, 2));
// 步骤 7:更新结构文件
const structure = JSON.parse(fs.readFileSync(structurePath, "utf-8"));
structure.rootNodeIds.push(nodeId);
structure.nodes[nodeId] = {
parentId: null,
orderIndex: structure.rootNodeIds.length - 1,
childIds: [],
};
structure.updatedAt = timestamp;
fs.writeFileSync(structurePath, JSON.stringify(structure, null, 2));
console.log(`✅ 已向 ${todayDocName} 添加项目符号:"${userText}"`);
return { success: true, documentName: todayDocName, nodeId };
} catch (error) {
console.error("❌ 向每日笔记添加内容时出错:", error.message);
return { success: false, error: error.message };
}
}
// 示例调用方式
if (require.main === module) {
const userText = process.argv.slice(2).join(" ") || "New bullet point";
addToDailyNote(userText);
}
module.exports = { addToDailyNote };
用户:“添加到我的每日笔记:完成了 OpenClaw 技能的实现”
助手:我将把该内容添加至您的每日笔记中。
# 运行脚本 node add-to-daily-note.js "Finished the OpenClaw skill implementation"
输出: ✅ 已向 2026-02-11 添加项目符号:"Finished the OpenClaw skill implementation"
用户:“添加一个提醒:明天给妈妈打电话”
助手:我将把该提醒添加至今天的笔记中。
node add-to-daily-note.js "Reminder to call mom tomorrow"
add-to-daily-note.js,置于您的 OpenClaw skills 目录下npm install uuidchmod +x add-to-daily-note.js~/.lucia/documents-path.txt 存在错误:“FocusNote 配置文件未找到”
~/.lucia/documents-path.txt 是否存在项目符号未在 FocusNote 中显示
.nodes/ 目录下是否已成功创建节点文件_structure.json 文件是否已正确更新相关专题
热门下载
相关下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 134.1万人学习
共49课时 | 82.6万人学习
最新文章