juanirm

Logseq

知识管理v1.0.0
作者:juanirm更新于 2026-05-17logseq@clawhub_juanirm/logseq
资料整理信息检索笔记整理#Database

据 AlphaMoat 统计,截至 2026-09,Logseq 累计下载 4,720 次、获 6 个星标,在全部 5,078 个 AI 技能中排名第 2,004 位,在「知识管理」分类(442 个)中排名第 189 位。

累计安装
149
累计下载
4,720
星标
6
全站排名
#2,004
全站前 40% · 「知识管理」前 43%
平台累计安装累计下载星标评论
ClawHub ↗1494,3136-
SkillHub ↗1484,7206—

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

该技能可访问页面和区块内容、执行 Datalog 查询、创建或更新页面及区块,并可能删除页面或批量修改内容。它依赖正在运行并启用 API 的 Logseq 实例,外部脚本通常还需要桥接或代理;宽泛的本地 HTTP/IPC 桥可能暴露笔记。应限制为可信本地图谱和白名单操作,避免开放通用桥接;执行删除或批量更改前先备份并取得确认。 API 主要面向插件,外部脚本需配置合适连接方式。

资料发布于 2026-10-29

可以用来做什么

  • 检索图谱中的页面、区块或待办任务
  • 整理查询结果并草拟页面或区块更新
  • 为本地 Logseq 自动化规划受限的只读桥接方式

什么时候用

  • Logseq 正在本机运行且 API 已安全启用时
  • 桥接仅限可信本地环境和明确允许的操作时
  • 删除或批量变更前已有备份并确认变更时

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

只读取指定 Logseq 页面并汇总其内容,不修改或删除页面、区块,也不要建立通用 HTTP/IPC 桥接。

月度数据趋势

累计下载4,720
3,7304,2624,7932026-05 · 累计下载 3,8032026-07 · 累计下载 4,2092026-08 · 累计下载 4,2672026-09 · 累计下载 4,72026-0526-09
星标6
5672026-05 · 星标 62026-07 · 星标 62026-08 · 星标 62026-09 · 星标 626-0526-09

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-094,720—6
2026-084,267+1.4%6
2026-074,209—6
2026-053,803—6

SKILL.md 原文

以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。

7.4 KB · ClawHub v1.0.0
---
name: logseq
description: Provide commands for interacting with a local Logseq instance through its Plugin API. Use for creating pages, inserting blocks, querying the graph database, managing tasks, retrieving content, or automating workflows in Logseq. Only works with a locally running instance with the API enabled; default port or set path expected for [$API accessible skill].
---

# Logseq Plugin API

Interact with your local Logseq instance through its JavaScript Plugin API. This skill enables reading, writing, querying, and automating workflows in your Logseq graph.

## Prerequisites
展开全部(共 248 行)

**Logseq must be running locally** with a plugin that exposes the API. The standard way is:

1. **Install a bridge plugin** that exposes `logseq` API via HTTP (e.g., via a custom plugin or localhost endpoint)
2. **Alternative**: Use Node.js with `@logseq/libs` package to script against the running Logseq instance

The API is primarily designed for in-browser plugins, so accessing it from external scripts requires a bridge/proxy.

## Core API Namespaces

The Logseq Plugin API is organized into these main proxies:

### `logseq.App`
Application-level operations: getting app info, user configs, current graph, commands, UI state, external links.

**Key methods:**
- `getInfo()` - Get app version and info
- `getUserConfigs()` - Get user preferences (theme, format, language, etc.)
- `getCurrentGraph()` - Get current graph info (name, path, URL)
- `registerCommand(type, opts, action)` - Register custom commands
- `pushState(route, params, query)` - Navigate to routes

### `logseq.Editor`
Block and page editing operations: creating, updating, moving, querying content.

**Key methods:**
- `getBlock(uuid)` - Get block by UUID
- `getCurrentPage()` - Get current page entity
- `getCurrentPageBlocksTree()` - Get all blocks on current page
- `getPageBlocksTree(page)` - Get all blocks for a specific page
- `insertBlock(target, content, opts)` - Insert a new block
- `updateBlock(uuid, content)` - Update block content
- `createPage(pageName, properties, opts)` - Create a new page
- `deletePage(pageName)` - Delete a page
- `getPageLinkedReferences(page)` - Get backlinks to a page
- `registerSlashCommand(tag, action)` - Add custom slash commands

### `logseq.DB`
Database queries using Datalog.

**Key methods:**
- `q(query, ...inputs)` - Run Datalog query
- `datascriptQuery(query, ...inputs)` - Direct Datascript query

### `logseq.UI`
UI operations: messages, dialogs, main UI visibility.

**Key methods:**
- `showMsg(content, status)` - Show toast notification
- `queryElementById(id)` - Query DOM elements

### `logseq.Git`
Git operations for the current graph.

**Key methods:**
- `execCommand(args)` - Execute git command

### `logseq.Assets`
Asset management.

**Key methods:**
- `listFilesOfCurrentGraph(path)` - List files in graph

## Common Workflows

### Read Content

```javascript
// Get current page
const page = await logseq.Editor.getCurrentPage();

// Get all blocks on a page
const blocks = await logseq.Editor.getPageBlocksTree('Daily Notes');

// Get a specific block
const block = await logseq.Editor.getBlock('block-uuid-here');

// Query with Datalog
const results = await logseq.DB.q(`
  [:find (pull ?b [*])
   :where [?b :block/marker "TODO"]]
`);
```

### Write Content

```javascript
// Create a new page
await logseq.Editor.createPage('Project Notes', {
  tags: 'project',
  status: 'active'
}, { redirect: false });

// Insert a block
const block = await logseq.Editor.insertBlock(
  'target-block-uuid',
  '- New task item',
  { before: false, sibling: true }
);

// Update a block
await logseq.Editor.updateBlock('block-uuid', 'Updated content');

// Batch insert multiple blocks
const blocks = [
  { content: 'First item' },
  { content: 'Second item', children: [
    { content: 'Nested item' }
  ]}
];
await logseq.Editor.insertBatchBlock('parent-uuid', blocks, { sibling: false });
```

### Task Management

```javascript
// Find all TODO items
const todos = await logseq.DB.q(`
  [:find (pull ?b [*])
   :where
   [?b :block/marker ?marker]
   [(contains? #{"TODO" "DOING"} ?marker)]]
`);

// Mark task as DONE
await logseq.Editor.updateBlock('task-uuid', 'DONE Task content');

// Get tasks on current page
const page = await logseq.Editor.getCurrentPage();
const blocks = await logseq.Editor.getPageBlocksTree(page.name);
const tasks = blocks.filter(b => b.marker === 'TODO' || b.marker === 'DOING');
```

### Navigation and UI

```javascript
// Navigate to a page
logseq.App.pushState('page', { name: 'Project Notes' });

// Show notification
logseq.UI.showMsg('✅ Task completed!', 'success');

// Get app config
const configs = await logseq.App.getUserConfigs();
console.log('Theme:', configs.preferredThemeMode);
console.log('Format:', configs.preferredFormat);
```

## Implementation Approaches

Since Logseq's Plugin API is browser-based, you have several options:

### Option 1: Bridge Plugin
Create a minimal Logseq plugin that exposes API calls via HTTP:

```javascript
// In Logseq plugin (index.js)
logseq.ready(() => {
  // Expose API endpoints
  logseq.provideModel({
    async handleAPICall({ method, args }) {
      return await logseq.Editor[method](...args);
    }
  });
});

// Then call from external script via HTTP POST
```

### Option 2: Node.js Script with @logseq/libs
For automation scripts, use the `@logseq/libs` package:

```bash
npm install @logseq/libs
```

**Note:** This requires a running Logseq instance and proper connection setup.

### Option 3: Direct Plugin Development
Develop a full Logseq plugin following the plugin samples at:
https://github.com/logseq/logseq-plugin-samples

## API Reference

For complete API documentation, see:
- **API Docs**: https://logseq.github.io/plugins/
- **Plugin Samples**: https://github.com/logseq/logseq-plugin-samples
- **Type Definitions**: `references/api-types.md` (extracted from `@logseq/libs`)

## Key Data Structures

### BlockEntity
```typescript
{
  id: number,           // Entity ID
  uuid: string,         // Block UUID
  content: string,      // Block content
  format: 'markdown' | 'org',
  page: { id: number }, // Parent page
  parent: { id: number }, // Parent block
  left: { id: number }, // Previous sibling
  properties: {},       // Block properties
  marker?: string,      // TODO/DOING/DONE
  children?: []         // Child blocks
}
```

### PageEntity
```typescript
{
  id: number,
  uuid: string,
  name: string,              // Page name (lowercase)
  originalName: string,       // Original case
  'journal?': boolean,
  properties: {},
  journalDay?: number,       // YYYYMMDD for journals
}
```

## Tips & Best Practices

1. **Always check for null**: API methods may return `null` if entity doesn't exist
2. **Use UUIDs over IDs**: Block UUIDs are stable, entity IDs can change
3. **Batch operations**: Use `insertBatchBlock` for multiple inserts
4. **Query efficiently**: Datalog queries are powerful but can be slow on large graphs
5. **Properties are objects**: Access with `block.properties.propertyName`
6. **Format matters**: Respect user's preferred format (markdown vs org-mode)
7. **Async all the way**: All API calls return Promises

## Common Gotchas

- **Page names are lowercase**: When querying, use lowercase page names
- **Journal pages**: Use `journalDay` format (YYYYMMDD) not date strings
- **Block hierarchy**: Respect parent/child relationships when inserting
- **Format differences**: Markdown uses `-` for bullets, Org uses `*`
- **Properties syntax**: Different between markdown (`prop::`) and org (`:PROPERTIES:`)

「知识管理」分类下的热门技能

数据月份:2026-09 · 下载/星标/安装数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。