@geminilight/mindos 0.1.9 → 0.2.1
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/README.md +42 -12
- package/README_zh.md +38 -5
- package/app/README.md +1 -1
- package/app/app/api/init/route.ts +56 -0
- package/app/app/api/sync/route.ts +124 -0
- package/app/app/layout.tsx +10 -1
- package/app/app/register-sw.tsx +15 -0
- package/app/components/HomeContent.tsx +8 -2
- package/app/components/OnboardingView.tsx +161 -0
- package/app/components/SettingsModal.tsx +10 -1
- package/app/components/Sidebar.tsx +28 -4
- package/app/components/SyncStatusBar.tsx +273 -0
- package/app/components/renderers/AgentInspectorRenderer.tsx +8 -5
- package/app/components/settings/SyncTab.tsx +311 -0
- package/app/components/settings/types.ts +1 -1
- package/app/lib/agent/log.ts +44 -0
- package/app/lib/agent/tools.ts +39 -18
- package/app/lib/i18n.ts +80 -2
- package/app/lib/renderers/index.ts +13 -0
- package/app/lib/settings.ts +2 -2
- package/app/public/icons/icon-192.png +0 -0
- package/app/public/icons/icon-512.png +0 -0
- package/app/public/manifest.json +26 -0
- package/app/public/sw.js +66 -0
- package/bin/cli.js +214 -10
- package/bin/lib/config.js +12 -1
- package/bin/lib/mcp-install.js +225 -70
- package/bin/lib/startup.js +24 -1
- package/bin/lib/sync.js +367 -0
- package/mcp/src/index.ts +37 -10
- package/package.json +6 -2
- package/scripts/release.sh +56 -0
- package/scripts/setup.js +35 -6
- package/templates/README.md +1 -1
package/README.md
CHANGED
|
@@ -82,6 +82,7 @@ Static documents are hard to synchronize and weak as execution systems in real h
|
|
|
82
82
|
- **Reference Sync**: keep cross-file status and context aligned via links/backlinks.
|
|
83
83
|
- **Knowledge Graph**: visualize relationships and dependencies across notes.
|
|
84
84
|
- **Git Time Machine**: track every edit, audit history, and roll back safely.
|
|
85
|
+
- **Cross-Device Sync**: auto-commit, push, and pull via Git — edits on one device appear on all others within minutes.
|
|
85
86
|
|
|
86
87
|
<details>
|
|
87
88
|
<summary><strong>Coming Soon</strong></summary>
|
|
@@ -125,18 +126,17 @@ npm link # registers the `mindos` command globally
|
|
|
125
126
|
### 2. Interactive Setup
|
|
126
127
|
|
|
127
128
|
```bash
|
|
128
|
-
mindos onboard
|
|
129
|
+
mindos onboard
|
|
129
130
|
```
|
|
130
131
|
|
|
131
|
-
> `--install-daemon`: after setup, automatically installs and starts MindOS as a background OS service (survives terminal close, auto-restarts on crash).
|
|
132
|
-
|
|
133
132
|
The setup wizard will guide you through:
|
|
134
|
-
1. Knowledge base path → default
|
|
133
|
+
1. Knowledge base path → default `~/MindOS`
|
|
135
134
|
2. Choose template (en / zh / empty / custom)
|
|
136
135
|
3. Ports (Web UI + MCP)
|
|
137
136
|
4. Auth token (auto-generated or passphrase-seeded)
|
|
138
137
|
5. Web UI password (optional)
|
|
139
138
|
6. AI Provider (Anthropic / OpenAI) + API Key — or **skip** to configure later via `mindos config set`
|
|
139
|
+
7. Start mode — **Background service** (recommended, auto-starts on boot) or Foreground
|
|
140
140
|
|
|
141
141
|
Config is saved to `~/.mindos/config.json` automatically.
|
|
142
142
|
|
|
@@ -153,34 +153,50 @@ Or skip the wizard and edit `~/.mindos/config.json` manually (see Config Referen
|
|
|
153
153
|
|
|
154
154
|
```json
|
|
155
155
|
{
|
|
156
|
-
"mindRoot": "
|
|
156
|
+
"mindRoot": "~/MindOS",
|
|
157
157
|
"port": 3000,
|
|
158
158
|
"mcpPort": 8787,
|
|
159
159
|
"authToken": "",
|
|
160
160
|
"webPassword": "",
|
|
161
|
+
"startMode": "daemon",
|
|
161
162
|
"ai": {
|
|
162
163
|
"provider": "anthropic",
|
|
163
164
|
"providers": {
|
|
164
165
|
"anthropic": { "apiKey": "sk-ant-...", "model": "claude-sonnet-4-6" },
|
|
165
166
|
"openai": { "apiKey": "sk-...", "model": "gpt-5.4", "baseUrl": "" }
|
|
166
167
|
}
|
|
168
|
+
},
|
|
169
|
+
"sync": {
|
|
170
|
+
"enabled": true,
|
|
171
|
+
"provider": "git",
|
|
172
|
+
"remote": "origin",
|
|
173
|
+
"branch": "main",
|
|
174
|
+
"autoCommitInterval": 30,
|
|
175
|
+
"autoPullInterval": 300
|
|
167
176
|
}
|
|
168
177
|
}
|
|
169
178
|
```
|
|
170
179
|
|
|
171
180
|
| Field | Default | Description |
|
|
172
181
|
| :--- | :--- | :--- |
|
|
173
|
-
| `mindRoot` |
|
|
182
|
+
| `mindRoot` | `~/MindOS` | **Required**. Absolute path to the knowledge base root. |
|
|
174
183
|
| `port` | `3000` | Optional. Web app port. |
|
|
175
184
|
| `mcpPort` | `8787` | Optional. MCP server port. |
|
|
176
185
|
| `authToken` | — | Optional. Protects App `/api/*` and MCP `/mcp` with bearer token auth. For Agent / MCP clients. Recommended when exposed to a network. |
|
|
177
186
|
| `webPassword` | — | Optional. Protects the web UI with a login page. For browser access. Independent from `authToken`. |
|
|
187
|
+
| `startMode` | `start` | Start mode: `daemon` (background service, auto-starts on boot), `start` (foreground), or `dev`. |
|
|
178
188
|
| `ai.provider` | `anthropic` | Active provider: `anthropic` or `openai`. |
|
|
179
189
|
| `ai.providers.anthropic.apiKey` | — | Anthropic API key. |
|
|
180
190
|
| `ai.providers.anthropic.model` | `claude-sonnet-4-6` | Anthropic model ID. |
|
|
181
191
|
| `ai.providers.openai.apiKey` | — | OpenAI API key. |
|
|
182
192
|
| `ai.providers.openai.model` | `gpt-5.4` | OpenAI model ID. |
|
|
183
193
|
| `ai.providers.openai.baseUrl` | — | Optional. Custom endpoint for proxy or OpenAI-compatible APIs. |
|
|
194
|
+
| `sync.enabled` | `false` | Enable/disable automatic Git sync. |
|
|
195
|
+
| `sync.provider` | `git` | Sync provider (currently only `git`). |
|
|
196
|
+
| `sync.remote` | `origin` | Git remote name. |
|
|
197
|
+
| `sync.branch` | `main` | Git branch to sync. |
|
|
198
|
+
| `sync.autoCommitInterval` | `30` | Seconds after file change to auto-commit+push. |
|
|
199
|
+
| `sync.autoPullInterval` | `300` | Seconds between auto-pull from remote. |
|
|
184
200
|
|
|
185
201
|
Multiple providers can be configured simultaneously — switch between them by changing `ai.provider`. Shell env vars (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, etc.) take precedence over config file values.
|
|
186
202
|
|
|
@@ -190,7 +206,13 @@ Multiple providers can be configured simultaneously — switch between them by c
|
|
|
190
206
|
> If you want the MindOS GUI to be reachable from other devices, make sure the port is open in firewall/security-group settings and bound to an accessible host/network interface.
|
|
191
207
|
|
|
192
208
|
> [!TIP]
|
|
193
|
-
>
|
|
209
|
+
> If you chose "Background service" during onboard, MindOS is installed as a background OS service and starts automatically — no need to run `mindos start` manually. Run `mindos update` to upgrade to the latest version.
|
|
210
|
+
|
|
211
|
+
Open the Web UI in your browser:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
mindos open
|
|
215
|
+
```
|
|
194
216
|
|
|
195
217
|
### 3. Inject Your Personal Mind with MindOS Agent
|
|
196
218
|
|
|
@@ -386,12 +408,13 @@ MindOS/
|
|
|
386
408
|
├── mcp/ # MCP Server — HTTP adapter that maps tools to App API
|
|
387
409
|
├── skills/ # MindOS Skills (`mindos`, `mindos-zh`) — Workflow guides for Agents
|
|
388
410
|
├── templates/ # Preset templates (`en/`, `zh/`, `empty/`) — copied to knowledge base on onboard
|
|
389
|
-
├── bin/ # CLI entry point (`mindos onboard`, `mindos start`, `mindos
|
|
411
|
+
├── bin/ # CLI entry point (`mindos onboard`, `mindos start`, `mindos open`, `mindos sync`, `mindos token`)
|
|
390
412
|
├── scripts/ # Setup wizard and helper scripts
|
|
391
413
|
└── README.md
|
|
392
414
|
|
|
393
415
|
~/.mindos/ # User data directory (outside project, never committed)
|
|
394
|
-
├── config.json # All configuration (AI keys, port, auth token,
|
|
416
|
+
├── config.json # All configuration (AI keys, port, auth token, sync settings)
|
|
417
|
+
├── sync-state.json # Sync state (last sync time, conflicts)
|
|
395
418
|
└── my-mind/ # Your private knowledge base (default path, customizable on onboard)
|
|
396
419
|
```
|
|
397
420
|
|
|
@@ -401,17 +424,24 @@ MindOS/
|
|
|
401
424
|
|
|
402
425
|
| Command | Description |
|
|
403
426
|
| :--- | :--- |
|
|
404
|
-
| `mindos onboard` | Interactive setup (config, template
|
|
405
|
-
| `mindos onboard --install-daemon` | Setup + install & start as background OS service |
|
|
427
|
+
| `mindos onboard` | Interactive setup (config, template, start mode) |
|
|
406
428
|
| `mindos start` | Start app + MCP server (foreground, production mode) |
|
|
407
429
|
| `mindos start --daemon` | Install + start as a background OS service (survives terminal close, auto-restarts on crash) |
|
|
408
430
|
| `mindos dev` | Start app + MCP server (dev mode, hot reload) |
|
|
409
431
|
| `mindos dev --turbopack` | Dev mode with Turbopack (faster HMR) |
|
|
432
|
+
| `mindos open` | Open the Web UI in the default browser |
|
|
410
433
|
| `mindos stop` | Stop running MindOS processes |
|
|
411
434
|
| `mindos restart` | Stop then start again |
|
|
412
435
|
| `mindos build` | Manually build for production |
|
|
413
436
|
| `mindos mcp` | Start MCP server only |
|
|
414
|
-
| `mindos token` | Show
|
|
437
|
+
| `mindos token` | Show auth token and per-agent MCP config snippets |
|
|
438
|
+
| `mindos sync` | Show sync status (alias for `sync status`) |
|
|
439
|
+
| `mindos sync init` | Interactive setup for Git remote sync |
|
|
440
|
+
| `mindos sync status` | Show sync status: last sync, unpushed commits, conflicts |
|
|
441
|
+
| `mindos sync now` | Manually trigger a full sync (commit + push + pull) |
|
|
442
|
+
| `mindos sync on` | Enable automatic sync |
|
|
443
|
+
| `mindos sync off` | Disable automatic sync |
|
|
444
|
+
| `mindos sync conflicts` | List unresolved conflict files |
|
|
415
445
|
| `mindos gateway install` | Install background service (systemd on Linux, LaunchAgent on macOS) |
|
|
416
446
|
| `mindos gateway uninstall` | Remove background service |
|
|
417
447
|
| `mindos gateway start` | Start the background service |
|
package/README_zh.md
CHANGED
|
@@ -82,6 +82,7 @@ MindOS 是一个**人机协同心智系统**——基于本地优先的协作知
|
|
|
82
82
|
- **引用同步**:通过引用与反向链接保持跨文件状态一致。
|
|
83
83
|
- **知识图谱**:可视化笔记间关系与依赖。
|
|
84
84
|
- **Git 时光机**:记录修改历史,支持审计与安全回滚。
|
|
85
|
+
- **跨设备同步**:通过 Git 自动 commit、push、pull —— 一台设备的编辑几分钟内同步到所有设备。
|
|
85
86
|
|
|
86
87
|
<details>
|
|
87
88
|
<summary><strong>即将到来</strong></summary>
|
|
@@ -131,12 +132,13 @@ mindos onboard --install-daemon
|
|
|
131
132
|
> `--install-daemon`:配置完成后,自动将 MindOS 安装为后台 OS 服务(关闭终端仍运行,崩溃自动重启)。
|
|
132
133
|
|
|
133
134
|
配置向导将引导你完成:
|
|
134
|
-
1. 知识库路径 → 默认
|
|
135
|
+
1. 知识库路径 → 默认 `~/MindOS`
|
|
135
136
|
2. 选择模板(en / zh / empty / custom)
|
|
136
137
|
3. 端口配置(Web UI + MCP)
|
|
137
138
|
4. Auth token(自动生成或口令派生)
|
|
138
139
|
5. Web UI 访问密码(可选)
|
|
139
140
|
6. 配置 AI Provider(Anthropic / OpenAI)+ API Key — 或选择 **skip**,稍后通过 `mindos config set` 补填
|
|
141
|
+
7. 启动模式 — **后台服务**(推荐,开机自启)或前台运行
|
|
140
142
|
|
|
141
143
|
配置自动保存到 `~/.mindos/config.json`。
|
|
142
144
|
|
|
@@ -153,34 +155,50 @@ mindos onboard --install-daemon
|
|
|
153
155
|
|
|
154
156
|
```json
|
|
155
157
|
{
|
|
156
|
-
"mindRoot": "
|
|
158
|
+
"mindRoot": "~/MindOS",
|
|
157
159
|
"port": 3000,
|
|
158
160
|
"mcpPort": 8787,
|
|
159
161
|
"authToken": "",
|
|
160
162
|
"webPassword": "",
|
|
163
|
+
"startMode": "daemon",
|
|
161
164
|
"ai": {
|
|
162
165
|
"provider": "anthropic",
|
|
163
166
|
"providers": {
|
|
164
167
|
"anthropic": { "apiKey": "sk-ant-...", "model": "claude-sonnet-4-6" },
|
|
165
168
|
"openai": { "apiKey": "sk-...", "model": "gpt-5.4", "baseUrl": "" }
|
|
166
169
|
}
|
|
170
|
+
},
|
|
171
|
+
"sync": {
|
|
172
|
+
"enabled": true,
|
|
173
|
+
"provider": "git",
|
|
174
|
+
"remote": "origin",
|
|
175
|
+
"branch": "main",
|
|
176
|
+
"autoCommitInterval": 30,
|
|
177
|
+
"autoPullInterval": 300
|
|
167
178
|
}
|
|
168
179
|
}
|
|
169
180
|
```
|
|
170
181
|
|
|
171
182
|
| 字段 | 默认值 | 说明 |
|
|
172
183
|
| :--- | :--- | :--- |
|
|
173
|
-
| `mindRoot` |
|
|
184
|
+
| `mindRoot` | `~/MindOS` | **必填**。知识库根目录的绝对路径 |
|
|
174
185
|
| `port` | `3000` | 可选。Web 服务端口 |
|
|
175
186
|
| `mcpPort` | `8787` | 可选。MCP 服务端口 |
|
|
176
187
|
| `authToken` | — | 可选。保护 App `/api/*` 和 MCP `/mcp` 的 Bearer Token 认证。供 Agent / MCP 客户端使用,暴露到网络时建议设置 |
|
|
177
188
|
| `webPassword` | — | 可选。为 Web UI 添加登录密码保护。供浏览器访问,与 `authToken` 相互独立 |
|
|
189
|
+
| `startMode` | `start` | 启动模式:`daemon`(后台服务,开机自启)、`start`(前台)或 `dev` |
|
|
178
190
|
| `ai.provider` | `anthropic` | 当前使用的 provider:`anthropic` 或 `openai` |
|
|
179
191
|
| `ai.providers.anthropic.apiKey` | — | Anthropic API Key |
|
|
180
192
|
| `ai.providers.anthropic.model` | `claude-sonnet-4-6` | Anthropic 模型 ID |
|
|
181
193
|
| `ai.providers.openai.apiKey` | — | OpenAI API Key |
|
|
182
194
|
| `ai.providers.openai.model` | `gpt-5.4` | OpenAI 模型 ID |
|
|
183
195
|
| `ai.providers.openai.baseUrl` | — | 可选。用于代理或 OpenAI 兼容 API 的自定义接口地址 |
|
|
196
|
+
| `sync.enabled` | `false` | 启用/禁用 Git 自动同步 |
|
|
197
|
+
| `sync.provider` | `git` | 同步方式(目前仅支持 `git`) |
|
|
198
|
+
| `sync.remote` | `origin` | Git 远程仓库名 |
|
|
199
|
+
| `sync.branch` | `main` | 同步分支 |
|
|
200
|
+
| `sync.autoCommitInterval` | `30` | 文件变更后自动 commit+push 的延迟秒数 |
|
|
201
|
+
| `sync.autoPullInterval` | `300` | 自动从远程 pull 的间隔秒数 |
|
|
184
202
|
|
|
185
203
|
多个 provider 可以同时配置,切换时只需修改 `ai.provider` 字段,无需重新填写 API Key。Shell 环境变量(`ANTHROPIC_API_KEY`、`OPENAI_API_KEY` 等)优先级高于配置文件。
|
|
186
204
|
|
|
@@ -192,6 +210,12 @@ mindos onboard --install-daemon
|
|
|
192
210
|
> [!TIP]
|
|
193
211
|
> 使用 `--install-daemon` 时,MindOS 会作为后台 OS 服务安装并自动启动,无需手动执行 `mindos start`。如果跳过了该参数,运行 `mindos start` 手动启动,或运行 `mindos update` 升级到最新版本。
|
|
194
212
|
|
|
213
|
+
在浏览器中打开 Web UI:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
mindos open
|
|
217
|
+
```
|
|
218
|
+
|
|
195
219
|
### 3. 通过 MindOS Agent 注入你的个人心智
|
|
196
220
|
|
|
197
221
|
1. 打开 MindOS GUI 中内置的 Agent 对话面板。
|
|
@@ -386,12 +410,13 @@ MindOS/
|
|
|
386
410
|
├── mcp/ # MCP Server — 将工具映射到 App API 的 HTTP 适配器
|
|
387
411
|
├── skills/ # MindOS Skills(`mindos`、`mindos-zh`)— Agent 工作流指南
|
|
388
412
|
├── templates/ # 预设模板(`en/`、`zh/`、`empty/`)— onboard 时复制到知识库目录
|
|
389
|
-
├── bin/ # CLI 入口(`mindos onboard`、`mindos start`、`mindos
|
|
413
|
+
├── bin/ # CLI 入口(`mindos onboard`、`mindos start`、`mindos open`、`mindos sync`、`mindos token`)
|
|
390
414
|
├── scripts/ # 配置向导与辅助脚本
|
|
391
415
|
└── README.md
|
|
392
416
|
|
|
393
417
|
~/.mindos/ # 用户数据目录(项目外,不会被提交)
|
|
394
|
-
├── config.json # 所有配置(AI 密钥、端口、Auth token
|
|
418
|
+
├── config.json # 所有配置(AI 密钥、端口、Auth token、同步设置)
|
|
419
|
+
├── sync-state.json # 同步状态(最后同步时间、冲突文件)
|
|
395
420
|
└── my-mind/ # 你的私有知识库(默认路径,onboard 时可自定义)
|
|
396
421
|
```
|
|
397
422
|
|
|
@@ -407,11 +432,19 @@ MindOS/
|
|
|
407
432
|
| `mindos start --daemon` | 安装并以后台 OS 服务方式启动(关闭终端仍运行,崩溃自动重启) |
|
|
408
433
|
| `mindos dev` | 启动 app + MCP 服务(开发模式,热更新) |
|
|
409
434
|
| `mindos dev --turbopack` | 开发模式 + Turbopack(更快的 HMR) |
|
|
435
|
+
| `mindos open` | 在默认浏览器中打开 Web UI |
|
|
410
436
|
| `mindos stop` | 停止正在运行的 MindOS 进程 |
|
|
411
437
|
| `mindos restart` | 停止后重新启动 |
|
|
412
438
|
| `mindos build` | 手动构建生产版本 |
|
|
413
439
|
| `mindos mcp` | 仅启动 MCP 服务 |
|
|
414
440
|
| `mindos token` | 查看当前 Auth token 及 MCP 配置片段 |
|
|
441
|
+
| `mindos sync` | 查看同步状态(`sync status` 的别名) |
|
|
442
|
+
| `mindos sync init` | 交互式配置 Git 远程同步 |
|
|
443
|
+
| `mindos sync status` | 查看同步状态:最后同步时间、未推送提交、冲突 |
|
|
444
|
+
| `mindos sync now` | 手动触发完整同步(commit + push + pull) |
|
|
445
|
+
| `mindos sync on` | 启用自动同步 |
|
|
446
|
+
| `mindos sync off` | 禁用自动同步 |
|
|
447
|
+
| `mindos sync conflicts` | 列出未解决的冲突文件 |
|
|
415
448
|
| `mindos gateway install` | 安装后台服务(Linux 用 systemd,macOS 用 LaunchAgent) |
|
|
416
449
|
| `mindos gateway uninstall` | 卸载后台服务 |
|
|
417
450
|
| `mindos gateway start` | 启动后台服务 |
|
package/app/README.md
CHANGED
|
@@ -16,7 +16,7 @@ mindos dev # or: mindos start
|
|
|
16
16
|
|
|
17
17
|
```bash
|
|
18
18
|
npm install
|
|
19
|
-
MIND_ROOT
|
|
19
|
+
MIND_ROOT=~/MindOS ANTHROPIC_API_KEY=sk-ant-... npm run dev
|
|
20
20
|
# Or copy .env.local.example to app/.env.local and fill in values
|
|
21
21
|
```
|
|
22
22
|
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { getMindRoot } from '@/lib/fs';
|
|
5
|
+
|
|
6
|
+
function copyRecursive(src: string, dest: string) {
|
|
7
|
+
const stat = fs.statSync(src);
|
|
8
|
+
if (stat.isDirectory()) {
|
|
9
|
+
if (!fs.existsSync(dest)) fs.mkdirSync(dest, { recursive: true });
|
|
10
|
+
for (const entry of fs.readdirSync(src)) {
|
|
11
|
+
copyRecursive(path.join(src, entry), path.join(dest, entry));
|
|
12
|
+
}
|
|
13
|
+
} else {
|
|
14
|
+
// Skip if file already exists
|
|
15
|
+
if (fs.existsSync(dest)) return;
|
|
16
|
+
// Ensure parent directory exists
|
|
17
|
+
const dir = path.dirname(dest);
|
|
18
|
+
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
19
|
+
fs.copyFileSync(src, dest);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function POST(req: NextRequest) {
|
|
24
|
+
try {
|
|
25
|
+
const body = await req.json();
|
|
26
|
+
const template = body.template as string;
|
|
27
|
+
|
|
28
|
+
if (!['en', 'zh', 'empty'].includes(template)) {
|
|
29
|
+
return NextResponse.json({ error: 'Invalid template' }, { status: 400 });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Resolve template source directory
|
|
33
|
+
// templates/ is at the repo root (sibling of app/)
|
|
34
|
+
const repoRoot = path.resolve(process.cwd(), '..');
|
|
35
|
+
const templateDir = path.join(repoRoot, 'templates', template);
|
|
36
|
+
|
|
37
|
+
if (!fs.existsSync(templateDir)) {
|
|
38
|
+
return NextResponse.json({ error: `Template "${template}" not found` }, { status: 404 });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const mindRoot = getMindRoot();
|
|
42
|
+
if (!fs.existsSync(mindRoot)) {
|
|
43
|
+
fs.mkdirSync(mindRoot, { recursive: true });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
copyRecursive(templateDir, mindRoot);
|
|
47
|
+
|
|
48
|
+
return NextResponse.json({ ok: true, template });
|
|
49
|
+
} catch (e) {
|
|
50
|
+
console.error('[/api/init] Error:', e);
|
|
51
|
+
return NextResponse.json(
|
|
52
|
+
{ error: e instanceof Error ? e.message : String(e) },
|
|
53
|
+
{ status: 500 },
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export const dynamic = 'force-dynamic';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { homedir } from 'os';
|
|
7
|
+
|
|
8
|
+
const MINDOS_DIR = join(homedir(), '.mindos');
|
|
9
|
+
const CONFIG_PATH = join(MINDOS_DIR, 'config.json');
|
|
10
|
+
const SYNC_STATE_PATH = join(MINDOS_DIR, 'sync-state.json');
|
|
11
|
+
|
|
12
|
+
function loadConfig() {
|
|
13
|
+
try { return JSON.parse(readFileSync(CONFIG_PATH, 'utf-8')); } catch { return {}; }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function saveConfig(config: Record<string, unknown>) {
|
|
17
|
+
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + '\n', 'utf-8');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function loadSyncState() {
|
|
21
|
+
try { return JSON.parse(readFileSync(SYNC_STATE_PATH, 'utf-8')); } catch { return {}; }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function getRemoteUrl(cwd: string) {
|
|
25
|
+
try { return execSync('git remote get-url origin', { cwd, encoding: 'utf-8', stdio: 'pipe' }).trim(); } catch { return null; }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getBranch(cwd: string) {
|
|
29
|
+
try { return execSync('git rev-parse --abbrev-ref HEAD', { cwd, encoding: 'utf-8', stdio: 'pipe' }).trim(); } catch { return 'main'; }
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getUnpushedCount(cwd: string) {
|
|
33
|
+
try { return execSync('git rev-list --count @{u}..HEAD', { cwd, encoding: 'utf-8', stdio: 'pipe' }).trim(); } catch { return '?'; }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isGitRepo(dir: string) {
|
|
37
|
+
return existsSync(join(dir, '.git'));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export async function GET() {
|
|
41
|
+
const config = loadConfig();
|
|
42
|
+
const syncConfig = config.sync || {};
|
|
43
|
+
const state = loadSyncState();
|
|
44
|
+
const mindRoot = config.mindRoot;
|
|
45
|
+
|
|
46
|
+
if (!syncConfig.enabled) {
|
|
47
|
+
return NextResponse.json({ enabled: false });
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const remote = mindRoot && isGitRepo(mindRoot) ? getRemoteUrl(mindRoot) : null;
|
|
51
|
+
const branch = mindRoot && isGitRepo(mindRoot) ? getBranch(mindRoot) : null;
|
|
52
|
+
const unpushed = mindRoot && isGitRepo(mindRoot) ? getUnpushedCount(mindRoot) : '?';
|
|
53
|
+
|
|
54
|
+
return NextResponse.json({
|
|
55
|
+
enabled: true,
|
|
56
|
+
provider: syncConfig.provider || 'git',
|
|
57
|
+
remote: remote || '(not configured)',
|
|
58
|
+
branch: branch || 'main',
|
|
59
|
+
lastSync: state.lastSync || null,
|
|
60
|
+
lastPull: state.lastPull || null,
|
|
61
|
+
unpushed,
|
|
62
|
+
conflicts: state.conflicts || [],
|
|
63
|
+
lastError: state.lastError || null,
|
|
64
|
+
autoCommitInterval: syncConfig.autoCommitInterval || 30,
|
|
65
|
+
autoPullInterval: syncConfig.autoPullInterval || 300,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function POST(req: NextRequest) {
|
|
70
|
+
try {
|
|
71
|
+
const body = await req.json() as { action: string };
|
|
72
|
+
const config = loadConfig();
|
|
73
|
+
const mindRoot = config.mindRoot;
|
|
74
|
+
|
|
75
|
+
if (!mindRoot) {
|
|
76
|
+
return NextResponse.json({ error: 'No mindRoot configured' }, { status: 400 });
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
switch (body.action) {
|
|
80
|
+
case 'now': {
|
|
81
|
+
if (!isGitRepo(mindRoot)) {
|
|
82
|
+
return NextResponse.json({ error: 'Not a git repository' }, { status: 400 });
|
|
83
|
+
}
|
|
84
|
+
// Pull
|
|
85
|
+
try { execSync('git pull --rebase --autostash', { cwd: mindRoot, stdio: 'pipe' }); } catch {
|
|
86
|
+
try { execSync('git rebase --abort', { cwd: mindRoot, stdio: 'pipe' }); } catch {}
|
|
87
|
+
try { execSync('git pull --no-rebase', { cwd: mindRoot, stdio: 'pipe' }); } catch {}
|
|
88
|
+
}
|
|
89
|
+
// Commit + push
|
|
90
|
+
execSync('git add -A', { cwd: mindRoot, stdio: 'pipe' });
|
|
91
|
+
const status = execSync('git status --porcelain', { cwd: mindRoot, encoding: 'utf-8' }).trim();
|
|
92
|
+
if (status) {
|
|
93
|
+
const timestamp = new Date().toISOString().replace('T', ' ').slice(0, 19);
|
|
94
|
+
execSync(`git commit -m "auto-sync: ${timestamp}"`, { cwd: mindRoot, stdio: 'pipe' });
|
|
95
|
+
execSync('git push', { cwd: mindRoot, stdio: 'pipe' });
|
|
96
|
+
}
|
|
97
|
+
const state = loadSyncState();
|
|
98
|
+
state.lastSync = new Date().toISOString();
|
|
99
|
+
writeFileSync(SYNC_STATE_PATH, JSON.stringify(state, null, 2) + '\n');
|
|
100
|
+
return NextResponse.json({ ok: true });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
case 'on': {
|
|
104
|
+
if (!config.sync) config.sync = {};
|
|
105
|
+
config.sync.enabled = true;
|
|
106
|
+
saveConfig(config);
|
|
107
|
+
return NextResponse.json({ ok: true, enabled: true });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
case 'off': {
|
|
111
|
+
if (!config.sync) config.sync = {};
|
|
112
|
+
config.sync.enabled = false;
|
|
113
|
+
saveConfig(config);
|
|
114
|
+
return NextResponse.json({ ok: true, enabled: false });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
default:
|
|
118
|
+
return NextResponse.json({ error: `Unknown action: ${body.action}` }, { status: 400 });
|
|
119
|
+
}
|
|
120
|
+
} catch (err: unknown) {
|
|
121
|
+
const message = err instanceof Error ? err.message : 'Unknown error';
|
|
122
|
+
return NextResponse.json({ error: message }, { status: 500 });
|
|
123
|
+
}
|
|
124
|
+
}
|
package/app/app/layout.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import ShellLayout from '@/components/ShellLayout';
|
|
|
6
6
|
import { TooltipProvider } from '@/components/ui/tooltip';
|
|
7
7
|
import { LocaleProvider } from '@/lib/LocaleContext';
|
|
8
8
|
import ErrorBoundary from '@/components/ErrorBoundary';
|
|
9
|
+
import RegisterSW from './register-sw';
|
|
9
10
|
|
|
10
11
|
const geistSans = Geist({
|
|
11
12
|
variable: '--font-geist-sans',
|
|
@@ -39,7 +40,13 @@ const lora = Lora({
|
|
|
39
40
|
export const metadata: Metadata = {
|
|
40
41
|
title: 'MindOS',
|
|
41
42
|
description: 'Personal knowledge base',
|
|
42
|
-
icons: { icon: '/logo-square.svg' },
|
|
43
|
+
icons: { icon: '/logo-square.svg', apple: '/icons/icon-192.png' },
|
|
44
|
+
manifest: '/manifest.json',
|
|
45
|
+
other: {
|
|
46
|
+
'mobile-web-app-capable': 'yes',
|
|
47
|
+
'apple-mobile-web-app-capable': 'yes',
|
|
48
|
+
'apple-mobile-web-app-status-bar-style': 'black-translucent',
|
|
49
|
+
},
|
|
43
50
|
};
|
|
44
51
|
|
|
45
52
|
export const viewport = {
|
|
@@ -63,6 +70,7 @@ export default function RootLayout({
|
|
|
63
70
|
return (
|
|
64
71
|
<html lang="en" suppressHydrationWarning>
|
|
65
72
|
<head>
|
|
73
|
+
<meta name="theme-color" content="#c8871e" />
|
|
66
74
|
{/* Patch Node.removeChild/insertBefore to swallow errors caused by browser
|
|
67
75
|
extensions (translators, Grammarly, etc.) that mutate the DOM between SSR
|
|
68
76
|
and hydration. See: https://github.com/facebook/react/issues/17256 */}
|
|
@@ -90,6 +98,7 @@ export default function RootLayout({
|
|
|
90
98
|
</ShellLayout>
|
|
91
99
|
</ErrorBoundary>
|
|
92
100
|
</TooltipProvider>
|
|
101
|
+
<RegisterSW />
|
|
93
102
|
</LocaleProvider>
|
|
94
103
|
</body>
|
|
95
104
|
</html>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
export default function RegisterSW() {
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if ('serviceWorker' in navigator) {
|
|
8
|
+
navigator.serviceWorker.register('/sw.js').catch((err) => {
|
|
9
|
+
console.warn('[SW] Registration failed:', err);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
}, []);
|
|
13
|
+
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import Link from 'next/link';
|
|
4
|
-
import { FileText, Table, Clock, Sparkles, Puzzle, ArrowRight, FilePlus, Search, ChevronDown } from 'lucide-react';
|
|
4
|
+
import { FileText, Table, Clock, Sparkles, Puzzle, ArrowRight, FilePlus, Search, ChevronDown, Terminal } from 'lucide-react';
|
|
5
5
|
import { useState } from 'react';
|
|
6
6
|
import { useLocale } from '@/lib/LocaleContext';
|
|
7
7
|
import { encodePath, relativeTime } from '@/lib/utils';
|
|
8
8
|
import { getAllRenderers } from '@/lib/renderers/registry';
|
|
9
9
|
import '@/lib/renderers/index'; // registers all renderers
|
|
10
|
+
import OnboardingView from './OnboardingView';
|
|
10
11
|
|
|
11
12
|
interface RecentFile {
|
|
12
13
|
path: string;
|
|
@@ -21,7 +22,7 @@ const RENDERER_ENTRY: Record<string, string> = {
|
|
|
21
22
|
timeline: 'CHANGELOG.md',
|
|
22
23
|
backlinks: 'BACKLINKS.md',
|
|
23
24
|
summary: 'DAILY.md',
|
|
24
|
-
'agent-inspector': '
|
|
25
|
+
'agent-inspector': '.agent-log.json',
|
|
25
26
|
workflow: 'Workflow.md',
|
|
26
27
|
'diff-viewer': 'Agent-Diff.md',
|
|
27
28
|
'config-panel': 'CONFIG.json',
|
|
@@ -45,6 +46,11 @@ export default function HomeContent({ recent }: { recent: RecentFile[] }) {
|
|
|
45
46
|
const { t } = useLocale();
|
|
46
47
|
const [showAll, setShowAll] = useState(false);
|
|
47
48
|
|
|
49
|
+
// Empty knowledge base → show onboarding
|
|
50
|
+
if (recent.length === 0) {
|
|
51
|
+
return <OnboardingView />;
|
|
52
|
+
}
|
|
53
|
+
|
|
48
54
|
const formatTime = (mtime: number) => relativeTime(mtime, t.home.relativeTime);
|
|
49
55
|
|
|
50
56
|
const renderers = getAllRenderers();
|