@geminilight/mindos 0.5.56 → 0.5.58
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/app/app/api/file/route.ts +43 -1
- package/app/app/view/[...path]/page.tsx +3 -3
- package/app/components/DirView.tsx +96 -9
- package/app/components/FileTree.tsx +245 -27
- package/app/components/ask/AskContent.tsx +297 -67
- package/app/hooks/useComposerVerticalResize.ts +74 -0
- package/app/lib/actions.ts +53 -25
- package/app/lib/core/create-space.ts +36 -0
- package/app/lib/core/fs-ops.ts +78 -1
- package/app/lib/core/index.ts +8 -0
- package/app/lib/core/types.ts +7 -0
- package/app/lib/fs.ts +78 -5
- package/app/lib/i18n-en.ts +15 -0
- package/app/lib/i18n-zh.ts +15 -0
- package/app/next-env.d.ts +1 -1
- package/app/next.config.ts +1 -0
- package/bin/cli.js +5 -1
- package/bin/lib/utils.js +6 -2
- package/mcp/README.md +4 -2
- package/mcp/package.json +1 -1
- package/mcp/src/index.ts +50 -0
- package/package.json +2 -1
- package/scripts/release.sh +7 -0
- package/scripts/verify-standalone.mjs +129 -0
- package/skills/mindos/SKILL.md +15 -1
- package/skills/mindos-zh/SKILL.md +15 -1
package/app/lib/core/fs-ops.ts
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
import { resolveSafe, assertWithinRoot } from './security';
|
|
4
4
|
import { MindOSError, ErrorCodes } from '@/lib/errors';
|
|
5
|
-
import { scaffoldIfNewSpace } from './space-scaffold';
|
|
5
|
+
import { scaffoldIfNewSpace, cleanDirName, INSTRUCTION_TEMPLATE, README_TEMPLATE } from './space-scaffold';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Reads the content of a file given a relative path from mindRoot.
|
|
@@ -55,6 +55,48 @@ export function deleteFile(mindRoot: string, filePath: string): void {
|
|
|
55
55
|
fs.unlinkSync(resolved);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Recursively deletes a directory and all its contents.
|
|
60
|
+
* Throws if the path does not exist, is outside mindRoot, or is not a directory.
|
|
61
|
+
*/
|
|
62
|
+
export function deleteDirectory(mindRoot: string, dirPath: string): void {
|
|
63
|
+
const resolved = resolveSafe(mindRoot, dirPath);
|
|
64
|
+
if (!fs.existsSync(resolved)) {
|
|
65
|
+
throw new MindOSError(ErrorCodes.FILE_NOT_FOUND, `Directory not found: ${dirPath}`, { dirPath });
|
|
66
|
+
}
|
|
67
|
+
if (!fs.statSync(resolved).isDirectory()) {
|
|
68
|
+
throw new MindOSError(ErrorCodes.INVALID_PATH, `Not a directory: ${dirPath}`, { dirPath });
|
|
69
|
+
}
|
|
70
|
+
fs.rmSync(resolved, { recursive: true, force: true });
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Converts an existing directory into a Space by creating INSTRUCTION.md
|
|
75
|
+
* (and README.md if missing). Idempotent — skips files that already exist.
|
|
76
|
+
*/
|
|
77
|
+
export function convertToSpace(mindRoot: string, dirPath: string): void {
|
|
78
|
+
const resolved = resolveSafe(mindRoot, dirPath);
|
|
79
|
+
if (!fs.existsSync(resolved)) {
|
|
80
|
+
throw new MindOSError(ErrorCodes.FILE_NOT_FOUND, `Directory not found: ${dirPath}`, { dirPath });
|
|
81
|
+
}
|
|
82
|
+
if (!fs.statSync(resolved).isDirectory()) {
|
|
83
|
+
throw new MindOSError(ErrorCodes.INVALID_PATH, `Not a directory: ${dirPath}`, { dirPath });
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const dirName = path.basename(resolved);
|
|
87
|
+
const name = cleanDirName(dirName);
|
|
88
|
+
|
|
89
|
+
const instructionPath = path.join(resolved, 'INSTRUCTION.md');
|
|
90
|
+
if (!fs.existsSync(instructionPath)) {
|
|
91
|
+
fs.writeFileSync(instructionPath, INSTRUCTION_TEMPLATE(name), 'utf-8');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const readmePath = path.join(resolved, 'README.md');
|
|
95
|
+
if (!fs.existsSync(readmePath)) {
|
|
96
|
+
fs.writeFileSync(readmePath, README_TEMPLATE(name), 'utf-8');
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
58
100
|
/**
|
|
59
101
|
* Renames a file within its current directory.
|
|
60
102
|
* newName must be a plain filename (no path separators).
|
|
@@ -79,6 +121,41 @@ export function renameFile(mindRoot: string, oldPath: string, newName: string):
|
|
|
79
121
|
return path.relative(root, newResolved);
|
|
80
122
|
}
|
|
81
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Renames a directory (Mind Space) under mindRoot. `newName` must be a single segment (no `/` or `\\`).
|
|
126
|
+
* Does not rewrite links inside markdown files.
|
|
127
|
+
*/
|
|
128
|
+
export function renameSpaceDirectory(mindRoot: string, spacePath: string, newName: string): string {
|
|
129
|
+
const trimmedName = newName.trim();
|
|
130
|
+
if (!trimmedName || trimmedName.includes('/') || trimmedName.includes('\\')) {
|
|
131
|
+
throw new MindOSError(ErrorCodes.INVALID_PATH, 'Invalid space name: must not contain path separators', { newName });
|
|
132
|
+
}
|
|
133
|
+
const normalized = spacePath.replace(/\/+$/g, '').trim();
|
|
134
|
+
if (!normalized) {
|
|
135
|
+
throw new MindOSError(ErrorCodes.INVALID_PATH, 'Space path is required', { spacePath });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const root = path.resolve(mindRoot);
|
|
139
|
+
const oldResolved = resolveSafe(mindRoot, normalized);
|
|
140
|
+
if (!fs.existsSync(oldResolved)) {
|
|
141
|
+
throw new MindOSError(ErrorCodes.FILE_NOT_FOUND, `Space not found: ${normalized}`, { spacePath: normalized });
|
|
142
|
+
}
|
|
143
|
+
if (!fs.statSync(oldResolved).isDirectory()) {
|
|
144
|
+
throw new MindOSError(ErrorCodes.INVALID_PATH, `Not a directory: ${normalized}`, { spacePath: normalized });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const parentDir = path.dirname(oldResolved);
|
|
148
|
+
const newResolved = path.join(parentDir, trimmedName);
|
|
149
|
+
assertWithinRoot(newResolved, root);
|
|
150
|
+
|
|
151
|
+
if (fs.existsSync(newResolved)) {
|
|
152
|
+
throw new MindOSError(ErrorCodes.FILE_ALREADY_EXISTS, 'A space with that name already exists', { newName: trimmedName });
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
fs.renameSync(oldResolved, newResolved);
|
|
156
|
+
return path.relative(root, newResolved);
|
|
157
|
+
}
|
|
158
|
+
|
|
82
159
|
/**
|
|
83
160
|
* Moves a file from one path to another within mindRoot.
|
|
84
161
|
* Returns the new path and a list of files that referenced the old path.
|
package/app/lib/core/index.ts
CHANGED
|
@@ -22,7 +22,10 @@ export {
|
|
|
22
22
|
writeFile,
|
|
23
23
|
createFile,
|
|
24
24
|
deleteFile,
|
|
25
|
+
deleteDirectory,
|
|
26
|
+
convertToSpace,
|
|
25
27
|
renameFile,
|
|
28
|
+
renameSpaceDirectory,
|
|
26
29
|
moveFile,
|
|
27
30
|
getRecentlyModified,
|
|
28
31
|
} from './fs-ops';
|
|
@@ -56,3 +59,8 @@ export { findBacklinks } from './backlinks';
|
|
|
56
59
|
|
|
57
60
|
// Git
|
|
58
61
|
export { isGitRepo, gitLog, gitShowFile } from './git';
|
|
62
|
+
|
|
63
|
+
// Mind Space
|
|
64
|
+
export { createSpaceFilesystem } from './create-space';
|
|
65
|
+
export { summarizeTopLevelSpaces } from './list-spaces';
|
|
66
|
+
export type { MindSpaceSummary } from './list-spaces';
|
package/app/lib/core/types.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export interface SpacePreview {
|
|
2
|
+
instructionLines: string[];
|
|
3
|
+
readmeLines: string[];
|
|
4
|
+
}
|
|
5
|
+
|
|
1
6
|
export interface FileNode {
|
|
2
7
|
name: string;
|
|
3
8
|
path: string;
|
|
@@ -5,6 +10,8 @@ export interface FileNode {
|
|
|
5
10
|
children?: FileNode[];
|
|
6
11
|
extension?: string;
|
|
7
12
|
mtime?: number;
|
|
13
|
+
isSpace?: boolean;
|
|
14
|
+
spacePreview?: SpacePreview;
|
|
8
15
|
}
|
|
9
16
|
|
|
10
17
|
export interface SearchResult {
|
package/app/lib/fs.ts
CHANGED
|
@@ -7,7 +7,10 @@ import {
|
|
|
7
7
|
writeFile as coreWriteFile,
|
|
8
8
|
createFile as coreCreateFile,
|
|
9
9
|
deleteFile as coreDeleteFile,
|
|
10
|
+
deleteDirectory as coreDeleteDirectory,
|
|
11
|
+
convertToSpace as coreConvertToSpace,
|
|
10
12
|
renameFile as coreRenameFile,
|
|
13
|
+
renameSpaceDirectory as coreRenameSpaceDirectory,
|
|
11
14
|
moveFile as coreMoveFile,
|
|
12
15
|
readLines as coreReadLines,
|
|
13
16
|
insertLines as coreInsertLines,
|
|
@@ -21,8 +24,10 @@ import {
|
|
|
21
24
|
gitLog as coreGitLog,
|
|
22
25
|
gitShowFile as coreGitShowFile,
|
|
23
26
|
invalidateSearchIndex,
|
|
27
|
+
summarizeTopLevelSpaces,
|
|
24
28
|
} from './core';
|
|
25
|
-
import {
|
|
29
|
+
import type { MindSpaceSummary } from './core';
|
|
30
|
+
import { FileNode, SpacePreview } from './core/types';
|
|
26
31
|
import { SearchMatch } from './types';
|
|
27
32
|
import { effectiveSopRoot } from './settings';
|
|
28
33
|
|
|
@@ -77,8 +82,31 @@ function ensureCache(): FileTreeCache {
|
|
|
77
82
|
|
|
78
83
|
// ─── Internal builders ────────────────────────────────────────────────────────
|
|
79
84
|
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
const SPACE_PREVIEW_MAX_LINES = 3;
|
|
86
|
+
|
|
87
|
+
function extractBodyLines(filePath: string, maxLines: number): string[] {
|
|
88
|
+
try {
|
|
89
|
+
const content = fs.readFileSync(filePath, 'utf-8');
|
|
90
|
+
const bodyLines: string[] = [];
|
|
91
|
+
for (const line of content.split('\n')) {
|
|
92
|
+
const trimmed = line.trim();
|
|
93
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
94
|
+
bodyLines.push(trimmed);
|
|
95
|
+
if (bodyLines.length >= maxLines) break;
|
|
96
|
+
}
|
|
97
|
+
return bodyLines;
|
|
98
|
+
} catch { return []; }
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function buildSpacePreview(dirAbsPath: string) {
|
|
102
|
+
return {
|
|
103
|
+
instructionLines: extractBodyLines(path.join(dirAbsPath, 'INSTRUCTION.md'), SPACE_PREVIEW_MAX_LINES),
|
|
104
|
+
readmeLines: extractBodyLines(path.join(dirAbsPath, 'README.md'), SPACE_PREVIEW_MAX_LINES),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function buildFileTree(dirPath: string, rootOverride?: string): FileNode[] {
|
|
109
|
+
const root = rootOverride ?? getMindRoot();
|
|
82
110
|
let entries: fs.Dirent[];
|
|
83
111
|
try {
|
|
84
112
|
entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
@@ -94,9 +122,15 @@ function buildFileTree(dirPath: string): FileNode[] {
|
|
|
94
122
|
|
|
95
123
|
if (entry.isDirectory()) {
|
|
96
124
|
if (IGNORED_DIRS.has(entry.name)) continue;
|
|
97
|
-
const children = buildFileTree(fullPath);
|
|
125
|
+
const children = buildFileTree(fullPath, root);
|
|
98
126
|
if (children.length > 0) {
|
|
99
|
-
|
|
127
|
+
const hasInstruction = children.some(c => c.type === 'file' && c.name === 'INSTRUCTION.md');
|
|
128
|
+
const node: FileNode = { name: entry.name, path: relativePath, type: 'directory', children };
|
|
129
|
+
if (hasInstruction) {
|
|
130
|
+
node.isSpace = true;
|
|
131
|
+
node.spacePreview = buildSpacePreview(fullPath);
|
|
132
|
+
}
|
|
133
|
+
nodes.push(node);
|
|
100
134
|
}
|
|
101
135
|
} else if (entry.isFile()) {
|
|
102
136
|
const ext = path.extname(entry.name).toLowerCase();
|
|
@@ -114,6 +148,11 @@ function buildFileTree(dirPath: string): FileNode[] {
|
|
|
114
148
|
return nodes;
|
|
115
149
|
}
|
|
116
150
|
|
|
151
|
+
/** Exposed for testing only — builds a file tree from an arbitrary root path. */
|
|
152
|
+
export function buildFileTreeForTest(rootPath: string): FileNode[] {
|
|
153
|
+
return buildFileTree(rootPath, rootPath);
|
|
154
|
+
}
|
|
155
|
+
|
|
117
156
|
function buildAllFiles(dirPath: string): string[] {
|
|
118
157
|
const root = getMindRoot();
|
|
119
158
|
let entries: fs.Dirent[];
|
|
@@ -146,6 +185,20 @@ export function getFileTree(): FileNode[] {
|
|
|
146
185
|
return ensureCache().tree;
|
|
147
186
|
}
|
|
148
187
|
|
|
188
|
+
/** Top-level Mind Spaces (same cached tree as home Spaces grid). */
|
|
189
|
+
export function listMindSpaces(): MindSpaceSummary[] {
|
|
190
|
+
return summarizeTopLevelSpaces(getMindRoot(), ensureCache().tree);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Returns space preview (INSTRUCTION + README excerpts) for a directory, or null if not a space. */
|
|
194
|
+
export function getSpacePreview(dirPath: string): SpacePreview | null {
|
|
195
|
+
const root = getMindRoot();
|
|
196
|
+
const abs = path.join(root, dirPath);
|
|
197
|
+
const instructionPath = path.join(abs, 'INSTRUCTION.md');
|
|
198
|
+
if (!fs.existsSync(instructionPath)) return null;
|
|
199
|
+
return buildSpacePreview(abs);
|
|
200
|
+
}
|
|
201
|
+
|
|
149
202
|
/** Returns cached list of all file paths (relative to MIND_ROOT). */
|
|
150
203
|
export function collectAllFiles(): string[] {
|
|
151
204
|
return ensureCache().allFiles;
|
|
@@ -251,6 +304,25 @@ export function renameFile(oldPath: string, newName: string): string {
|
|
|
251
304
|
return result;
|
|
252
305
|
}
|
|
253
306
|
|
|
307
|
+
/** Renames a Space directory under MIND_ROOT. newName must be a single path segment. */
|
|
308
|
+
export function renameSpace(spacePath: string, newName: string): string {
|
|
309
|
+
const result = coreRenameSpaceDirectory(getMindRoot(), spacePath, newName);
|
|
310
|
+
invalidateCache();
|
|
311
|
+
return result;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** Recursively deletes a directory under MIND_ROOT. */
|
|
315
|
+
export function deleteDirectory(dirPath: string): void {
|
|
316
|
+
coreDeleteDirectory(getMindRoot(), dirPath);
|
|
317
|
+
invalidateCache();
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** Converts a regular folder into a Space by adding INSTRUCTION.md + README.md. */
|
|
321
|
+
export function convertToSpace(dirPath: string): void {
|
|
322
|
+
coreConvertToSpace(getMindRoot(), dirPath);
|
|
323
|
+
invalidateCache();
|
|
324
|
+
}
|
|
325
|
+
|
|
254
326
|
// ─── Public API: Line-level operations (delegated to @mindos/core) ───────────
|
|
255
327
|
|
|
256
328
|
export function readLines(filePath: string): string[] {
|
|
@@ -471,6 +543,7 @@ export function gitShowFile(filePath: string, commit: string): string {
|
|
|
471
543
|
|
|
472
544
|
import type { BacklinkEntry } from './core/types';
|
|
473
545
|
export type { BacklinkEntry } from './core/types';
|
|
546
|
+
export type { MindSpaceSummary } from './core';
|
|
474
547
|
|
|
475
548
|
export function findBacklinks(targetPath: string): BacklinkEntry[] {
|
|
476
549
|
return coreFindBacklinks(getMindRoot(), targetPath);
|
package/app/lib/i18n-en.ts
CHANGED
|
@@ -97,6 +97,11 @@ export const en = {
|
|
|
97
97
|
placeholder: 'Ask a question... or type @ to attach a file',
|
|
98
98
|
emptyPrompt: 'Ask anything about your knowledge base',
|
|
99
99
|
send: 'send',
|
|
100
|
+
newlineHint: 'new line',
|
|
101
|
+
panelComposerResize: 'Drag up to enlarge the input area',
|
|
102
|
+
panelComposerFooter: 'Resize height',
|
|
103
|
+
panelComposerResetHint: 'Double-click to reset height',
|
|
104
|
+
panelComposerKeyboard: 'Arrow keys adjust height; Home/End min/max',
|
|
100
105
|
attachFile: 'attach file',
|
|
101
106
|
attachCurrent: 'attach current file',
|
|
102
107
|
stopTitle: 'Stop',
|
|
@@ -273,6 +278,16 @@ export const en = {
|
|
|
273
278
|
enterFileName: 'Enter a file name',
|
|
274
279
|
failed: 'Failed',
|
|
275
280
|
confirmDelete: (name: string) => `Delete "${name}"? This cannot be undone.`,
|
|
281
|
+
rules: 'Rules',
|
|
282
|
+
about: 'About',
|
|
283
|
+
viewAll: 'View all',
|
|
284
|
+
editRules: 'Edit Rules',
|
|
285
|
+
renameSpace: 'Rename Space',
|
|
286
|
+
deleteSpace: 'Delete Space',
|
|
287
|
+
confirmDeleteSpace: (name: string) => `Delete space "${name}" and all its files? This cannot be undone.`,
|
|
288
|
+
convertToSpace: 'Convert to Space',
|
|
289
|
+
deleteFolder: 'Delete Folder',
|
|
290
|
+
confirmDeleteFolder: (name: string) => `Delete folder "${name}" and all its contents? This cannot be undone.`,
|
|
276
291
|
},
|
|
277
292
|
dirView: {
|
|
278
293
|
gridView: 'Grid view',
|
package/app/lib/i18n-zh.ts
CHANGED
|
@@ -122,6 +122,11 @@ export const zh = {
|
|
|
122
122
|
placeholder: '输入问题,或输入 @ 添加附件文件',
|
|
123
123
|
emptyPrompt: '可以问任何关于知识库的问题',
|
|
124
124
|
send: '发送',
|
|
125
|
+
newlineHint: '换行',
|
|
126
|
+
panelComposerResize: '向上拖拽以拉高输入区',
|
|
127
|
+
panelComposerFooter: '拉高输入区',
|
|
128
|
+
panelComposerResetHint: '双击恢复默认高度',
|
|
129
|
+
panelComposerKeyboard: '方向键调节高度;Home/End 最小或最大',
|
|
125
130
|
attachFile: '附加文件',
|
|
126
131
|
attachCurrent: '附加当前文件',
|
|
127
132
|
stopTitle: '停止',
|
|
@@ -297,6 +302,16 @@ export const zh = {
|
|
|
297
302
|
enterFileName: '请输入文件名',
|
|
298
303
|
failed: '操作失败',
|
|
299
304
|
confirmDelete: (name: string) => `确定删除「${name}」?此操作不可撤销。`,
|
|
305
|
+
rules: '规则',
|
|
306
|
+
about: '说明',
|
|
307
|
+
viewAll: '查看全部',
|
|
308
|
+
editRules: '编辑规则',
|
|
309
|
+
renameSpace: '重命名空间',
|
|
310
|
+
deleteSpace: '删除空间',
|
|
311
|
+
confirmDeleteSpace: (name: string) => `删除空间「${name}」及其所有文件?此操作不可撤销。`,
|
|
312
|
+
convertToSpace: '转为空间',
|
|
313
|
+
deleteFolder: '删除文件夹',
|
|
314
|
+
confirmDeleteFolder: (name: string) => `删除文件夹「${name}」及其所有内容?此操作不可撤销。`,
|
|
300
315
|
},
|
|
301
316
|
dirView: {
|
|
302
317
|
gridView: '网格视图',
|
package/app/next-env.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="next" />
|
|
2
2
|
/// <reference types="next/image-types/global" />
|
|
3
|
-
import "./.next/
|
|
3
|
+
import "./.next/types/routes.d.ts";
|
|
4
4
|
|
|
5
5
|
// NOTE: This file should not be edited
|
|
6
6
|
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
package/app/next.config.ts
CHANGED
|
@@ -4,6 +4,7 @@ import path from "path";
|
|
|
4
4
|
const nextConfig: NextConfig = {
|
|
5
5
|
transpilePackages: ['github-slugger'],
|
|
6
6
|
serverExternalPackages: ['chokidar', 'openai', '@mariozechner/pi-ai', '@mariozechner/pi-agent-core'],
|
|
7
|
+
output: 'standalone',
|
|
7
8
|
outputFileTracingRoot: path.join(__dirname),
|
|
8
9
|
turbopack: {
|
|
9
10
|
root: path.join(__dirname),
|
package/bin/cli.js
CHANGED
|
@@ -394,7 +394,11 @@ const commands = {
|
|
|
394
394
|
startSyncDaemon(mindRoot).catch(() => {});
|
|
395
395
|
}
|
|
396
396
|
await printStartupInfo(webPort, mcpPort);
|
|
397
|
-
run(
|
|
397
|
+
run(
|
|
398
|
+
`${NEXT_BIN} start -p ${webPort} ${extra}`,
|
|
399
|
+
resolve(ROOT, 'app'),
|
|
400
|
+
process.env.HOSTNAME ? undefined : { HOSTNAME: '127.0.0.1' }
|
|
401
|
+
);
|
|
398
402
|
},
|
|
399
403
|
|
|
400
404
|
// ── build ──────────────────────────────────────────────────────────────────
|
package/bin/lib/utils.js
CHANGED
|
@@ -3,9 +3,13 @@ import { resolve } from 'node:path';
|
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
4
|
import { ROOT } from './constants.js';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @param {Record<string, string | undefined>} [envPatch] merged into process.env (for child only)
|
|
8
|
+
*/
|
|
9
|
+
export function run(command, cwd = ROOT, envPatch) {
|
|
7
10
|
try {
|
|
8
|
-
|
|
11
|
+
const env = envPatch ? { ...process.env, ...envPatch } : process.env;
|
|
12
|
+
execSync(command, { cwd, stdio: 'inherit', env });
|
|
9
13
|
} catch (err) {
|
|
10
14
|
process.exit(err.status || 1);
|
|
11
15
|
}
|
package/mcp/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MindOS MCP Server
|
|
2
2
|
|
|
3
|
-
Pure HTTP client wrapper that maps
|
|
3
|
+
Pure HTTP client wrapper that maps 22 MCP tools to the App REST API via `fetch`. Zero business logic — all operations are delegated to the App.
|
|
4
4
|
|
|
5
5
|
## Architecture
|
|
6
6
|
|
|
@@ -41,7 +41,7 @@ MCP_TRANSPORT=stdio mindos mcp # stdio mode
|
|
|
41
41
|
| `MCP_PORT` | `8781` | HTTP listen port (configurable via `mindos onboard`) |
|
|
42
42
|
| `MCP_ENDPOINT` | `/mcp` | HTTP endpoint path |
|
|
43
43
|
|
|
44
|
-
## MCP Tools (
|
|
44
|
+
## MCP Tools (22)
|
|
45
45
|
|
|
46
46
|
| Tool | App API | Description |
|
|
47
47
|
|------|---------|-------------|
|
|
@@ -49,6 +49,8 @@ MCP_TRANSPORT=stdio mindos mcp # stdio mode
|
|
|
49
49
|
| `mindos_read_file` | `GET /api/file?path=...` | Read file content (with offset/limit pagination) |
|
|
50
50
|
| `mindos_write_file` | `POST /api/file` op=save_file | Overwrite file content |
|
|
51
51
|
| `mindos_create_file` | `POST /api/file` op=create_file | Create a new .md or .csv file |
|
|
52
|
+
| `mindos_create_space` | `POST /api/file` op=create_space | Create a Mind Space (README + INSTRUCTION scaffold) |
|
|
53
|
+
| `mindos_rename_space` | `POST /api/file` op=rename_space | Rename a Space directory (folder only) |
|
|
52
54
|
| `mindos_delete_file` | `POST /api/file` op=delete_file | Delete a file |
|
|
53
55
|
| `mindos_rename_file` | `POST /api/file` op=rename_file | Rename a file (same directory) |
|
|
54
56
|
| `mindos_move_file` | `POST /api/file` op=move_file | Move a file to a new path |
|
package/mcp/package.json
CHANGED
package/mcp/src/index.ts
CHANGED
|
@@ -173,6 +173,56 @@ server.registerTool("mindos_create_file", {
|
|
|
173
173
|
} catch (e) { logOp("mindos_create_file", { path }, "error", String(e)); return error(String(e)); }
|
|
174
174
|
});
|
|
175
175
|
|
|
176
|
+
// ── mindos_create_space ─────────────────────────────────────────────────────
|
|
177
|
+
|
|
178
|
+
server.registerTool("mindos_create_space", {
|
|
179
|
+
title: "Create Mind Space",
|
|
180
|
+
description:
|
|
181
|
+
"Create a new Mind Space (top-level or under parent_path): directory + README.md + INSTRUCTION.md scaffold. Use this instead of create_file when adding a new cognitive zone to the knowledge base.",
|
|
182
|
+
inputSchema: z.object({
|
|
183
|
+
name: z.string().min(1).describe("Space directory name (no path separators)"),
|
|
184
|
+
description: z.string().default("").describe("Short purpose text stored in README.md"),
|
|
185
|
+
parent_path: z.string().default("").describe("Optional parent directory under MIND_ROOT (empty = top-level Space)"),
|
|
186
|
+
}),
|
|
187
|
+
}, async ({ name, description, parent_path }) => {
|
|
188
|
+
try {
|
|
189
|
+
const json = await post("/api/file", {
|
|
190
|
+
op: "create_space",
|
|
191
|
+
path: "_",
|
|
192
|
+
name,
|
|
193
|
+
description,
|
|
194
|
+
parent_path,
|
|
195
|
+
});
|
|
196
|
+
const p = json.path as string;
|
|
197
|
+
logOp("mindos_create_space", { name, parent_path }, "ok", p);
|
|
198
|
+
return ok(`Created Mind Space at "${p}"`);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
logOp("mindos_create_space", { name, parent_path }, "error", String(e));
|
|
201
|
+
return error(String(e));
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
// ── mindos_rename_space ─────────────────────────────────────────────────────
|
|
206
|
+
|
|
207
|
+
server.registerTool("mindos_rename_space", {
|
|
208
|
+
title: "Rename Mind Space",
|
|
209
|
+
description:
|
|
210
|
+
"Rename a Space directory (relative path to the folder, e.g. Notes or Work/Notes). Only the final folder name changes; new_name must be a single segment. Does not rewrite links inside files.",
|
|
211
|
+
inputSchema: z.object({
|
|
212
|
+
path: z.string().min(1).describe("Relative path to the space directory to rename"),
|
|
213
|
+
new_name: z.string().min(1).describe("New folder name only (no slashes)"),
|
|
214
|
+
}),
|
|
215
|
+
}, async ({ path: spacePath, new_name }) => {
|
|
216
|
+
try {
|
|
217
|
+
const json = await post("/api/file", { op: "rename_space", path: spacePath, new_name });
|
|
218
|
+
logOp("mindos_rename_space", { path: spacePath, new_name }, "ok", String(json.newPath));
|
|
219
|
+
return ok(`Renamed space "${spacePath}" → "${json.newPath}"`);
|
|
220
|
+
} catch (e) {
|
|
221
|
+
logOp("mindos_rename_space", { path: spacePath, new_name }, "error", String(e));
|
|
222
|
+
return error(String(e));
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
176
226
|
// ── mindos_delete_file ──────────────────────────────────────────────────────
|
|
177
227
|
|
|
178
228
|
server.registerTool("mindos_delete_file", {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geminilight/mindos",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.58",
|
|
4
4
|
"description": "MindOS — Human-Agent Collaborative Mind System. Local-first knowledge base that syncs your mind to all AI Agents via MCP.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mindos",
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"start": "mindos start",
|
|
65
65
|
"mcp": "mindos mcp",
|
|
66
66
|
"test": "cd app && npx vitest run",
|
|
67
|
+
"verify:standalone": "node scripts/verify-standalone.mjs",
|
|
67
68
|
"release": "bash scripts/release.sh"
|
|
68
69
|
},
|
|
69
70
|
"engines": {
|
package/scripts/release.sh
CHANGED
|
@@ -28,6 +28,13 @@ else
|
|
|
28
28
|
exit 1
|
|
29
29
|
fi
|
|
30
30
|
cd ..
|
|
31
|
+
echo "🩺 Verifying standalone server (/api/health)..."
|
|
32
|
+
if node scripts/verify-standalone.mjs; then
|
|
33
|
+
echo " ✅ Standalone smoke OK"
|
|
34
|
+
else
|
|
35
|
+
echo "❌ Standalone verify failed (trace / serverExternalPackages?)"
|
|
36
|
+
exit 1
|
|
37
|
+
fi
|
|
31
38
|
# Restore any files modified by next build (e.g. next-env.d.ts)
|
|
32
39
|
git checkout -- . 2>/dev/null || true
|
|
33
40
|
echo ""
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Smoke-test Next standalone server: merge static/public, spawn server.js, GET /api/health.
|
|
4
|
+
* Catches missing serverExternalPackages / file-trace gaps (MODULE_NOT_FOUND at startup).
|
|
5
|
+
*
|
|
6
|
+
* Run from repo root after: cd app && ./node_modules/.bin/next build
|
|
7
|
+
* node scripts/verify-standalone.mjs
|
|
8
|
+
*
|
|
9
|
+
* @see wiki/specs/spec-desktop-standalone-runtime.md
|
|
10
|
+
*/
|
|
11
|
+
import { spawn } from 'child_process';
|
|
12
|
+
import http from 'http';
|
|
13
|
+
import { existsSync } from 'fs';
|
|
14
|
+
import path from 'path';
|
|
15
|
+
import { fileURLToPath } from 'url';
|
|
16
|
+
import { materializeStandaloneAssets } from '../desktop/scripts/prepare-mindos-bundle.mjs';
|
|
17
|
+
|
|
18
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
|
+
const root = path.resolve(__dirname, '..');
|
|
20
|
+
const appDir = path.join(root, 'app');
|
|
21
|
+
const serverJs = path.join(appDir, '.next', 'standalone', 'server.js');
|
|
22
|
+
|
|
23
|
+
if (!existsSync(serverJs)) {
|
|
24
|
+
console.error(
|
|
25
|
+
`[verify-standalone] Missing ${serverJs}\nBuild first: cd app && ./node_modules/.bin/next build`
|
|
26
|
+
);
|
|
27
|
+
process.exit(1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
materializeStandaloneAssets(appDir);
|
|
32
|
+
} catch (e) {
|
|
33
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const port = 31000 + Math.floor(Math.random() * 5000);
|
|
38
|
+
const nodeBin = process.execPath;
|
|
39
|
+
|
|
40
|
+
function waitHealth(timeoutMs) {
|
|
41
|
+
const deadline = Date.now() + timeoutMs;
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const tick = () => {
|
|
44
|
+
if (Date.now() > deadline) {
|
|
45
|
+
reject(new Error(`Timeout waiting for http://127.0.0.1:${port}/api/health`));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const req = http.get(
|
|
49
|
+
`http://127.0.0.1:${port}/api/health`,
|
|
50
|
+
{ timeout: 2000 },
|
|
51
|
+
(res) => {
|
|
52
|
+
let body = '';
|
|
53
|
+
res.on('data', (c) => {
|
|
54
|
+
body += c;
|
|
55
|
+
});
|
|
56
|
+
res.on('end', () => {
|
|
57
|
+
if (res.statusCode === 200) {
|
|
58
|
+
try {
|
|
59
|
+
const j = JSON.parse(body);
|
|
60
|
+
if (j.ok === true && j.service === 'mindos') {
|
|
61
|
+
resolve();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
} catch {
|
|
65
|
+
/* fall through */
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
setTimeout(tick, 300);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
);
|
|
72
|
+
req.on('error', () => {
|
|
73
|
+
setTimeout(tick, 300);
|
|
74
|
+
});
|
|
75
|
+
req.on('timeout', () => {
|
|
76
|
+
req.destroy();
|
|
77
|
+
setTimeout(tick, 300);
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
tick();
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let stderr = '';
|
|
85
|
+
const child = spawn(nodeBin, [serverJs], {
|
|
86
|
+
cwd: appDir,
|
|
87
|
+
env: {
|
|
88
|
+
...process.env,
|
|
89
|
+
NODE_ENV: 'production',
|
|
90
|
+
PORT: String(port),
|
|
91
|
+
/** Next binds to machine hostname by default; Desktop health checks use 127.0.0.1 */
|
|
92
|
+
HOSTNAME: '127.0.0.1',
|
|
93
|
+
},
|
|
94
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
child.stderr?.on('data', (c) => {
|
|
98
|
+
stderr += c.toString();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
function killChild() {
|
|
102
|
+
try {
|
|
103
|
+
child.kill('SIGTERM');
|
|
104
|
+
} catch {
|
|
105
|
+
/* ignore */
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function main() {
|
|
110
|
+
try {
|
|
111
|
+
await waitHealth(90_000);
|
|
112
|
+
console.log(`[verify-standalone] OK (port ${port})`);
|
|
113
|
+
return 0;
|
|
114
|
+
} catch (e) {
|
|
115
|
+
console.error(e instanceof Error ? e.message : String(e));
|
|
116
|
+
if (stderr.trim()) console.error('--- server stderr (tail) ---\n', stderr.slice(-4000));
|
|
117
|
+
return 1;
|
|
118
|
+
} finally {
|
|
119
|
+
killChild();
|
|
120
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
child.on('error', (err) => {
|
|
125
|
+
console.error('[verify-standalone] spawn failed:', err.message);
|
|
126
|
+
process.exit(1);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
main().then((code) => process.exit(code));
|