@novis10813/secondbrain-cli 0.1.0 → 0.1.2
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 +71 -81
- package/dist/commands/backlinks.d.ts.map +1 -1
- package/dist/commands/backlinks.js +16 -33
- package/dist/commands/backlinks.js.map +1 -1
- package/dist/commands/capture.d.ts.map +1 -1
- package/dist/commands/capture.js +71 -57
- package/dist/commands/capture.js.map +1 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +5 -20
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/get.js +27 -26
- package/dist/commands/get.js.map +1 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +21 -4
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/migrate.d.ts +3 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +22 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/open.d.ts +3 -0
- package/dist/commands/open.d.ts.map +1 -0
- package/dist/commands/open.js +28 -0
- package/dist/commands/open.js.map +1 -0
- package/dist/commands/orphans.d.ts.map +1 -1
- package/dist/commands/orphans.js +9 -27
- package/dist/commands/orphans.js.map +1 -1
- package/dist/commands/outlinks.d.ts +3 -0
- package/dist/commands/outlinks.d.ts.map +1 -0
- package/dist/commands/outlinks.js +48 -0
- package/dist/commands/outlinks.js.map +1 -0
- package/dist/commands/search.d.ts +2 -0
- package/dist/commands/search.d.ts.map +1 -1
- package/dist/commands/search.js +57 -39
- package/dist/commands/search.js.map +1 -1
- package/dist/commands/stats.d.ts.map +1 -1
- package/dist/commands/stats.js +4 -18
- package/dist/commands/stats.js.map +1 -1
- package/dist/commands/sync.d.ts.map +1 -1
- package/dist/commands/sync.js +3 -17
- package/dist/commands/sync.js.map +1 -1
- package/dist/commands/template.d.ts +3 -0
- package/dist/commands/template.d.ts.map +1 -0
- package/dist/commands/template.js +63 -0
- package/dist/commands/template.js.map +1 -0
- package/dist/commands/vault.d.ts +3 -0
- package/dist/commands/vault.d.ts.map +1 -0
- package/dist/commands/vault.js +233 -0
- package/dist/commands/vault.js.map +1 -0
- package/dist/index.js +13 -1
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +134 -10
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/config.d.ts +3 -1
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +12 -0
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/database.d.ts +58 -14
- package/dist/utils/database.d.ts.map +1 -1
- package/dist/utils/database.js +627 -207
- package/dist/utils/database.js.map +1 -1
- package/dist/utils/global-config.d.ts +53 -0
- package/dist/utils/global-config.d.ts.map +1 -0
- package/dist/utils/global-config.js +144 -0
- package/dist/utils/global-config.js.map +1 -0
- package/dist/utils/parser.d.ts +95 -2
- package/dist/utils/parser.d.ts.map +1 -1
- package/dist/utils/parser.js +466 -39
- package/dist/utils/parser.js.map +1 -1
- package/dist/utils/placeholder.d.ts +37 -0
- package/dist/utils/placeholder.d.ts.map +1 -0
- package/dist/utils/placeholder.js +113 -0
- package/dist/utils/placeholder.js.map +1 -0
- package/dist/utils/position.d.ts +10 -0
- package/dist/utils/position.d.ts.map +1 -0
- package/dist/utils/position.js +24 -0
- package/dist/utils/position.js.map +1 -0
- package/dist/utils/sqlite-adapter.d.ts +8 -0
- package/dist/utils/sqlite-adapter.d.ts.map +1 -0
- package/dist/utils/sqlite-adapter.js +14 -0
- package/dist/utils/sqlite-adapter.js.map +1 -0
- package/dist/utils/template.d.ts +2 -2
- package/dist/utils/template.d.ts.map +1 -1
- package/dist/utils/template.js +8 -3
- package/dist/utils/template.js.map +1 -1
- package/dist/utils/vault-resolve.d.ts +23 -0
- package/dist/utils/vault-resolve.d.ts.map +1 -0
- package/dist/utils/vault-resolve.js +86 -0
- package/dist/utils/vault-resolve.js.map +1 -0
- package/dist/utils/vault.d.ts +77 -10
- package/dist/utils/vault.d.ts.map +1 -1
- package/dist/utils/vault.js +262 -98
- package/dist/utils/vault.js.map +1 -1
- package/package.json +9 -3
package/dist/commands/get.js
CHANGED
|
@@ -2,42 +2,43 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createGetCommand = createGetCommand;
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const vault_resolve_js_1 = require("../utils/vault-resolve.js");
|
|
6
|
+
const parser_js_1 = require("../utils/parser.js");
|
|
7
7
|
function createGetCommand() {
|
|
8
8
|
const command = new commander_1.Command('get')
|
|
9
|
-
.description('Get a note by ID')
|
|
10
|
-
.argument('<id>', '
|
|
9
|
+
.description('Get a note by path or ID')
|
|
10
|
+
.argument('<path-or-id>', 'File path (e.g. note.md or folder/note.md) or basename')
|
|
11
11
|
.option('-f, --format <format>', 'Output format (json|text)', 'json')
|
|
12
|
-
.action((
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
.action(async (pathOrId, options) => {
|
|
13
|
+
await (0, vault_resolve_js_1.withVault)((vault) => {
|
|
14
|
+
const file = vault.resolvePathOrBasename(pathOrId);
|
|
15
|
+
const resolvedPath = file?.path ?? null;
|
|
16
|
+
if (!resolvedPath) {
|
|
17
|
+
throw new Error('Note not found');
|
|
18
18
|
}
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const note = vault.getNoteById(id);
|
|
23
|
-
if (!note) {
|
|
24
|
-
console.error('❌ Note not found');
|
|
25
|
-
process.exit(1);
|
|
19
|
+
const content = vault.readNote(resolvedPath);
|
|
20
|
+
if (content === null) {
|
|
21
|
+
throw new Error('File not found on disk');
|
|
26
22
|
}
|
|
23
|
+
const parsed = parser_js_1.NoteParser.parse(content);
|
|
24
|
+
const cache = file ? vault.getFileCache(file) : null;
|
|
27
25
|
if (options.format === 'json') {
|
|
28
|
-
console.log(JSON.stringify(
|
|
26
|
+
console.log(JSON.stringify({
|
|
27
|
+
path: resolvedPath,
|
|
28
|
+
title: parsed.title,
|
|
29
|
+
content: parsed.content,
|
|
30
|
+
frontmatter: parsed.frontmatter,
|
|
31
|
+
tags: parsed.tags.map(t => t.name),
|
|
32
|
+
links: cache?.links?.map(l => l.link) ?? [],
|
|
33
|
+
headings: parsed.headings
|
|
34
|
+
}, null, 2));
|
|
29
35
|
}
|
|
30
36
|
else {
|
|
31
|
-
console.log(
|
|
37
|
+
console.log(parsed.title);
|
|
32
38
|
console.log('─'.repeat(40));
|
|
33
|
-
console.log(
|
|
39
|
+
console.log(parsed.content);
|
|
34
40
|
}
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
console.error('❌ Failed to get note:', error instanceof Error ? error.message : String(error));
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
+
});
|
|
41
42
|
});
|
|
42
43
|
return command;
|
|
43
44
|
}
|
package/dist/commands/get.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/commands/get.ts"],"names":[],"mappings":";;AAIA,4CAwCC;AA5CD,yCAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/commands/get.ts"],"names":[],"mappings":";;AAIA,4CAwCC;AA5CD,yCAAoC;AACpC,gEAAsD;AACtD,kDAAgD;AAEhD,SAAgB,gBAAgB;IAC9B,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,KAAK,CAAC;SAC/B,WAAW,CAAC,0BAA0B,CAAC;SACvC,QAAQ,CAAC,cAAc,EAAE,wDAAwD,CAAC;SAClF,MAAM,CAAC,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,CAAC;SACpE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;QAClC,MAAM,IAAA,4BAAS,EAAC,CAAC,KAAK,EAAE,EAAE;YACxB,MAAM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,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC5B,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAQpC,wBAAgB,iBAAiB,IAAI,OAAO,CA6C3C"}
|
package/dist/commands/init.js
CHANGED
|
@@ -3,20 +3,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createInitCommand = createInitCommand;
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
5
|
const config_js_1 = require("../utils/config.js");
|
|
6
|
+
const global_config_js_1 = require("../utils/global-config.js");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const os_1 = require("os");
|
|
9
|
+
const DEFAULT_VAULT_PATH = (0, path_1.join)((0, os_1.homedir)(), 'vault');
|
|
6
10
|
function createInitCommand() {
|
|
7
11
|
const command = new commander_1.Command('init')
|
|
8
|
-
.description('Initialize a new SecondBrain vault')
|
|
12
|
+
.description('Initialize a new SecondBrain vault (alias for `sb vault init`)')
|
|
9
13
|
.option('-p, --path <path>', 'Vault path', process.cwd())
|
|
10
|
-
.
|
|
14
|
+
.argument('[path]', 'Vault path')
|
|
15
|
+
.action((path, options) => {
|
|
11
16
|
try {
|
|
12
|
-
const
|
|
17
|
+
const vaultPath = (0, path_1.resolve)(path ?? options?.path ?? DEFAULT_VAULT_PATH);
|
|
18
|
+
const configManager = new config_js_1.ConfigManager(vaultPath);
|
|
19
|
+
const globalConfig = new global_config_js_1.GlobalConfigManager();
|
|
13
20
|
if (configManager.isInitialized()) {
|
|
14
|
-
console.log('⚠️ Vault already initialized at:',
|
|
21
|
+
console.log('⚠️ Vault already initialized at:', vaultPath);
|
|
22
|
+
// 確保已註冊到全域設定
|
|
23
|
+
const entry = globalConfig.addVault(vaultPath);
|
|
24
|
+
if (entry) {
|
|
25
|
+
console.log(`✅ Registered as "${entry.name}" in global config`);
|
|
26
|
+
}
|
|
15
27
|
return;
|
|
16
28
|
}
|
|
17
29
|
const config = configManager.init();
|
|
30
|
+
const entry = globalConfig.addVault(vaultPath);
|
|
18
31
|
console.log('✅ SecondBrain vault initialized!');
|
|
19
32
|
console.log('Vault path:', config.vaultPath);
|
|
33
|
+
console.log('Vault name:', entry?.name ?? 'unknown');
|
|
20
34
|
console.log('Daily notes:', config.dailyNotesFolder);
|
|
21
35
|
console.log('Templates:', config.templatesFolder);
|
|
22
36
|
console.log();
|
|
@@ -24,6 +38,9 @@ function createInitCommand() {
|
|
|
24
38
|
console.log(' 1. Create notes in your vault');
|
|
25
39
|
console.log(' 2. Run `sb sync` to index existing notes');
|
|
26
40
|
console.log(' 3. Use `sb capture` to create new notes');
|
|
41
|
+
console.log();
|
|
42
|
+
console.log('To use this vault:');
|
|
43
|
+
console.log(` eval $(sb vault use ${entry?.name ?? vaultPath})`);
|
|
27
44
|
}
|
|
28
45
|
catch (error) {
|
|
29
46
|
console.error('❌ Failed to initialize vault:', error instanceof Error ? error.message : String(error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":";;AAQA,8CA6CC;AArDD,yCAAoC;AACpC,kDAAmD;AACnD,gEAAgE;AAChE,+BAAqC;AACrC,2BAA6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,KAAK,EAAE,IAAI,IAAI,SAAS,CAAC,CAAC;YACrD,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;YACrD,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,MAAM,CAAC,eAAe,CAAC,CAAC;YAClD,OAAO,CAAC,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;YAC3B,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;YAC/C,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;YAC1D,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;YACzD,OAAO,CAAC,GAAG,EAAE,CAAC;YACd,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;YAClC,OAAO,CAAC,GAAG,CAAC,yBAAyB,KAAK,EAAE,IAAI,IAAI,SAAS,GAAG,CAAC,CAAC;QACpE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,+BAA+B,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;YACvG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.d.ts","sourceRoot":"","sources":["../../src/commands/migrate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wBAAgB,oBAAoB,IAAI,OAAO,CAgB9C"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createMigrateCommand = createMigrateCommand;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const vault_resolve_js_1 = require("../utils/vault-resolve.js");
|
|
6
|
+
function createMigrateCommand() {
|
|
7
|
+
const command = new commander_1.Command('migrate')
|
|
8
|
+
.description('Migrate data from old schema (notes table) to new schema (files + content_metadata)')
|
|
9
|
+
.action(async () => {
|
|
10
|
+
await (0, vault_resolve_js_1.withVault)((vault) => {
|
|
11
|
+
const result = vault.migrateFromOldSchema();
|
|
12
|
+
console.log('✅ Migration complete');
|
|
13
|
+
console.log(`Migrated: ${result.migrated}`);
|
|
14
|
+
console.log(`Skipped (already in new schema): ${result.skipped}`);
|
|
15
|
+
if (result.errors > 0) {
|
|
16
|
+
console.log(`Errors: ${result.errors}`);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
return command;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=migrate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate.js","sourceRoot":"","sources":["../../src/commands/migrate.ts"],"names":[],"mappings":";;AAGA,oDAgBC;AAnBD,yCAAoC;AACpC,gEAAsD;AAEtD,SAAgB,oBAAoB;IAClC,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,SAAS,CAAC;SACnC,WAAW,CAAC,qFAAqF,CAAC;SAClG,MAAM,CAAC,KAAK,IAAI,EAAE;QACjB,MAAM,IAAA,4BAAS,EAAC,CAAC,KAAK,EAAE,EAAE;YACxB,MAAM,MAAM,GAAG,KAAK,CAAC,oBAAoB,EAAE,CAAC;YAC5C,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;YACpC,OAAO,CAAC,GAAG,CAAC,aAAa,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC5C,OAAO,CAAC,GAAG,CAAC,oCAAoC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;YAClE,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACtB,OAAO,CAAC,GAAG,CAAC,WAAW,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;YAC1C,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open.d.ts","sourceRoot":"","sources":["../../src/commands/open.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wBAAgB,iBAAiB,IAAI,OAAO,CAqB3C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOpenCommand = createOpenCommand;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const vault_resolve_js_1 = require("../utils/vault-resolve.js");
|
|
6
|
+
function createOpenCommand() {
|
|
7
|
+
const command = new commander_1.Command('open')
|
|
8
|
+
.description('Resolve a link to a file and position for editor navigation (path:line:col)')
|
|
9
|
+
.argument('<linkpath>', 'Obsidian-style link (e.g. note, note#heading, note#^block-id)')
|
|
10
|
+
.option('-s, --source <path>', 'Source file path for relative link resolution', '')
|
|
11
|
+
.option('-f, --format <format>', 'Output format (position|json)', 'position')
|
|
12
|
+
.action(async (linkpath, options) => {
|
|
13
|
+
await (0, vault_resolve_js_1.withVault)((vault) => {
|
|
14
|
+
const result = vault.resolveLinkToPosition(linkpath, options.source ?? '');
|
|
15
|
+
if (!result) {
|
|
16
|
+
throw new Error('Link not found');
|
|
17
|
+
}
|
|
18
|
+
if (options.format === 'json') {
|
|
19
|
+
console.log(JSON.stringify(result, null, 2));
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
console.log(`${result.path}:${result.line}:${result.col}`);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
return command;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=open.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open.js","sourceRoot":"","sources":["../../src/commands/open.ts"],"names":[],"mappings":";;AAGA,8CAqBC;AAxBD,yCAAoC;AACpC,gEAAsD;AAEtD,SAAgB,iBAAiB;IAC/B,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,MAAM,CAAC;SAChC,WAAW,CAAC,6EAA6E,CAAC;SAC1F,QAAQ,CAAC,YAAY,EAAE,+DAA+D,CAAC;SACvF,MAAM,CAAC,qBAAqB,EAAE,+CAA+C,EAAE,EAAE,CAAC;SAClF,MAAM,CAAC,uBAAuB,EAAE,+BAA+B,EAAE,UAAU,CAAC;SAC5E,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;QAClC,MAAM,IAAA,4BAAS,EAAC,CAAC,KAAK,EAAE,EAAE;YACxB,MAAM,MAAM,GAAG,KAAK,CAAC,qBAAqB,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;YAC3E,IAAI,CAAC,MAAM,EAAE,CAAC;gBACZ,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;YACpC,CAAC;YACD,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;gBAC9B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/C,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orphans.d.ts","sourceRoot":"","sources":["../../src/commands/orphans.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"orphans.d.ts","sourceRoot":"","sources":["../../src/commands/orphans.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wBAAgB,oBAAoB,IAAI,OAAO,CA+B9C"}
|
package/dist/commands/orphans.js
CHANGED
|
@@ -2,31 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createOrphansCommand = createOrphansCommand;
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
|
-
const
|
|
6
|
-
const vault_js_1 = require("../utils/vault.js");
|
|
5
|
+
const vault_resolve_js_1 = require("../utils/vault-resolve.js");
|
|
7
6
|
function createOrphansCommand() {
|
|
8
7
|
const command = new commander_1.Command('orphans')
|
|
9
8
|
.description('Find notes with no links (orphans)')
|
|
10
9
|
.option('-f, --format <format>', 'Output format (json|text)', 'text')
|
|
11
|
-
.action((options) => {
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
if (!vaultPath) {
|
|
15
|
-
console.error('❌ Not in a SecondBrain vault. Run `sb init` first.');
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
const configManager = new config_js_1.ConfigManager(vaultPath);
|
|
19
|
-
const config = configManager.getConfig();
|
|
20
|
-
const vault = new vault_js_1.VaultManager(config);
|
|
21
|
-
const orphans = vault.getOrphans();
|
|
10
|
+
.action(async (options) => {
|
|
11
|
+
await (0, vault_resolve_js_1.withVault)((vault) => {
|
|
12
|
+
const orphans = vault.getOrphanFiles();
|
|
22
13
|
if (options.format === 'json') {
|
|
23
14
|
console.log(JSON.stringify({
|
|
24
15
|
count: orphans.length,
|
|
25
16
|
orphans: orphans.map(o => ({
|
|
26
|
-
id: o.id,
|
|
27
|
-
title: o.title,
|
|
28
17
|
path: o.path,
|
|
29
|
-
|
|
18
|
+
basename: o.basename
|
|
30
19
|
}))
|
|
31
20
|
}, null, 2));
|
|
32
21
|
}
|
|
@@ -36,21 +25,14 @@ function createOrphansCommand() {
|
|
|
36
25
|
}
|
|
37
26
|
else {
|
|
38
27
|
console.log(`⚠️ Found ${orphans.length} orphan note(s):\n`);
|
|
39
|
-
orphans.forEach((
|
|
40
|
-
console.log(`${i + 1}. ${
|
|
41
|
-
console.log(` Path: ${
|
|
42
|
-
console.log(` ID: ${note.id}`);
|
|
43
|
-
console.log(` Tags: ${note.tags.join(', ') || 'none'}`);
|
|
28
|
+
orphans.forEach((file, i) => {
|
|
29
|
+
console.log(`${i + 1}. ${file.basename}`);
|
|
30
|
+
console.log(` Path: ${file.path}`);
|
|
44
31
|
console.log();
|
|
45
32
|
});
|
|
46
33
|
}
|
|
47
34
|
}
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
console.error('❌ Failed to get orphans:', error instanceof Error ? error.message : String(error));
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
35
|
+
});
|
|
54
36
|
});
|
|
55
37
|
return command;
|
|
56
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orphans.js","sourceRoot":"","sources":["../../src/commands/orphans.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"orphans.js","sourceRoot":"","sources":["../../src/commands/orphans.ts"],"names":[],"mappings":";;AAGA,oDA+BC;AAlCD,yCAAoC;AACpC,gEAAsD;AAEtD,SAAgB,oBAAoB;IAClC,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,SAAS,CAAC;SACnC,WAAW,CAAC,oCAAoC,CAAC;SACjD,MAAM,CAAC,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,CAAC;SACpE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,MAAM,IAAA,4BAAS,EAAC,CAAC,KAAK,EAAE,EAAE;YACxB,MAAM,OAA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AI,OAAO,CA0C/C"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOutlinksCommand = createOutlinksCommand;
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const vault_resolve_js_1 = require("../utils/vault-resolve.js");
|
|
6
|
+
function createOutlinksCommand() {
|
|
7
|
+
const command = new commander_1.Command('outlinks')
|
|
8
|
+
.description('Get outgoing links from a note (files this note links to)')
|
|
9
|
+
.argument('<path-or-id>', 'File path or basename')
|
|
10
|
+
.option('-f, --format <format>', 'Output format (json|text)', 'json')
|
|
11
|
+
.action(async (pathOrId, options) => {
|
|
12
|
+
await (0, vault_resolve_js_1.withVault)((vault) => {
|
|
13
|
+
const file = vault.resolvePathOrBasename(pathOrId);
|
|
14
|
+
const resolvedPath = file?.path ?? null;
|
|
15
|
+
if (!resolvedPath) {
|
|
16
|
+
throw new Error('Note not found');
|
|
17
|
+
}
|
|
18
|
+
const outlinks = vault.getOutlinksByPath(resolvedPath);
|
|
19
|
+
const title = file?.basename ?? resolvedPath.replace(/\.md$/, '');
|
|
20
|
+
if (options.format === 'json') {
|
|
21
|
+
console.log(JSON.stringify({
|
|
22
|
+
path: resolvedPath,
|
|
23
|
+
title,
|
|
24
|
+
outlinkCount: outlinks.length,
|
|
25
|
+
outlinks: outlinks.map(o => ({
|
|
26
|
+
path: o.path,
|
|
27
|
+
basename: o.basename
|
|
28
|
+
}))
|
|
29
|
+
}, null, 2));
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
console.log(`Outlinks from "${title}":\n`);
|
|
33
|
+
if (outlinks.length === 0) {
|
|
34
|
+
console.log('No outlinks found');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
outlinks.forEach((o, i) => {
|
|
38
|
+
console.log(`${i + 1}. ${o.basename}`);
|
|
39
|
+
console.log(` Path: ${o.path}`);
|
|
40
|
+
console.log();
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
return command;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=outlinks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"outlinks.js","sourceRoot":"","sources":["../../src/commands/outlinks.ts"],"names":[],"mappings":";;AAGA,sDA0CC;AA7CD,yCAAoC;AACpC,gEAAsD;AAEtD,SAAgB,qBAAqB;IACnC,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,UAAU,CAAC;SACpC,WAAW,CAAC,2DAA2D,CAAC;SACxE,QAAQ,CAAC,cAAc,EAAE,uBAAuB,CAAC;SACjD,MAAM,CAAC,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,CAAC;SACpE,MAAM,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;QAClC,MAAM,IAAA,4BAAS,EAAC,CAAC,KAAK,EAAE,EAAE;YACxB,MAAM,IAAI,GAAG,KAAK,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;YACnD,MAAM,YAAY,GAAG,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC;YACxC,IAAI,CAAC,YAAY,EAAE,CAAC;gBAClB,MAAM,IAAI,KAAK,CAAC,gBAAgB,CAAC,CAAC;YACpC,CAAC;YAED,MAAM,QAAQ,GAAG,KAAK,CAAC,iBAAiB,CAAC,YAAY,CAAC,CAAC;YACrD,MAAM,KAAK,GAAG,IAAI,EAAE,QAAQ,IAAI,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YAElE,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;gBAC9B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC;oBACzB,IAAI,EAAE,YAAY;oBAClB,KAAK;oBACL,YAAY,EAAE,QAAQ,CAAC,MAAM;oBAC7B,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;wBAC3B,IAAI,EAAE,CAAC,CAAC,IAAI;wBACZ,QAAQ,EAAE,CAAC,CAAC,QAAQ;qBACrB,CAAC,CAAC;iBACJ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACf,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,MAAM,CAAC,CAAC;gBAC3C,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAC1B,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,CAAC;gBACnC,CAAC;qBAAM,CAAC;oBACN,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;wBACxB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;wBACvC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;wBAClC,OAAO,CAAC,GAAG,EAAE,CAAC;oBAChB,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
|
+
/** Parse --modified-after / --modified-before value to unix ms. ISO 8601 or digits (ms). */
|
|
3
|
+
export declare function parseDateOption(value: string | undefined): number | undefined;
|
|
2
4
|
export declare function createSearchCommand(): Command;
|
|
3
5
|
//# sourceMappingURL=search.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAS7E;AAED,wBAAgB,mBAAmB,IAAI,OAAO,CAkE7C"}
|
package/dist/commands/search.js
CHANGED
|
@@ -1,63 +1,81 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseDateOption = parseDateOption;
|
|
3
4
|
exports.createSearchCommand = createSearchCommand;
|
|
4
5
|
const commander_1 = require("commander");
|
|
5
|
-
const
|
|
6
|
-
|
|
6
|
+
const vault_resolve_js_1 = require("../utils/vault-resolve.js");
|
|
7
|
+
/** Parse --modified-after / --modified-before value to unix ms. ISO 8601 or digits (ms). */
|
|
8
|
+
function parseDateOption(value) {
|
|
9
|
+
if (value === undefined || value === '')
|
|
10
|
+
return undefined;
|
|
11
|
+
const s = String(value).trim();
|
|
12
|
+
if (/^\d+$/.test(s)) {
|
|
13
|
+
const n = parseInt(s, 10);
|
|
14
|
+
return Number.isFinite(n) ? n : undefined;
|
|
15
|
+
}
|
|
16
|
+
const ms = Date.parse(s);
|
|
17
|
+
return Number.isFinite(ms) ? ms : undefined;
|
|
18
|
+
}
|
|
7
19
|
function createSearchCommand() {
|
|
8
20
|
const command = new commander_1.Command('search')
|
|
9
|
-
.description('Search notes')
|
|
10
|
-
.argument('
|
|
21
|
+
.description('Search notes by path/basename and tags')
|
|
22
|
+
.argument('[query]', 'Search query (path/basename); omit for tag-only or path-only search', '')
|
|
11
23
|
.option('-t, --tags <tags>', 'Filter by tags (comma-separated)')
|
|
24
|
+
.option('-p, --path <pathPrefix>', 'Restrict to files under this path prefix (e.g. Daily/ or Projects)')
|
|
12
25
|
.option('-l, --limit <limit>', 'Maximum results', '20')
|
|
26
|
+
.option('--links-to <path>', 'Only files that link to this path or basename')
|
|
27
|
+
.option('--heading <text>', 'Only files that contain a heading matching this text')
|
|
28
|
+
.option('--modified-after <date>', 'Only files modified after date (ISO 8601 or unix ms)')
|
|
29
|
+
.option('--modified-before <date>', 'Only files modified before date (ISO 8601 or unix ms)')
|
|
13
30
|
.option('-f, --format <format>', 'Output format (json|text)', 'json')
|
|
14
|
-
.action((query, options) => {
|
|
15
|
-
|
|
16
|
-
const vaultPath = config_js_1.ConfigManager.findVaultPath();
|
|
17
|
-
if (!vaultPath) {
|
|
18
|
-
console.error('❌ Not in a SecondBrain vault. Run `sb init` first.');
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
const configManager = new config_js_1.ConfigManager(vaultPath);
|
|
22
|
-
const config = configManager.getConfig();
|
|
23
|
-
const vault = new vault_js_1.VaultManager(config);
|
|
31
|
+
.action(async (query, options) => {
|
|
32
|
+
await (0, vault_resolve_js_1.withVault)((vault) => {
|
|
24
33
|
const tags = options.tags ? options.tags.split(',').map((t) => t.trim()) : undefined;
|
|
25
34
|
const limit = parseInt(options.limit);
|
|
26
|
-
const
|
|
35
|
+
const pathPrefix = options.path?.trim() || undefined;
|
|
36
|
+
const headingQuery = options.heading?.trim() || undefined;
|
|
37
|
+
const modifiedAfter = parseDateOption(options.modifiedAfter);
|
|
38
|
+
const modifiedBefore = parseDateOption(options.modifiedBefore);
|
|
39
|
+
let linksToPath;
|
|
40
|
+
if (options.linksTo?.trim()) {
|
|
41
|
+
const file = vault.resolvePathOrBasename(options.linksTo.trim());
|
|
42
|
+
linksToPath = file?.path ?? undefined;
|
|
43
|
+
if (!linksToPath) {
|
|
44
|
+
throw new Error(`Note not found for --links-to: ${options.linksTo.trim()}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const results = vault.searchFiles(query ?? '', tags, limit, pathPrefix, linksToPath, headingQuery, modifiedAfter, modifiedBefore);
|
|
27
48
|
if (options.format === 'json') {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
excerpt: note.content.substring(0, 200) + (note.content.length > 200 ? '...' : ''),
|
|
33
|
-
tags: note.tags,
|
|
34
|
-
linksCount: note.links.length,
|
|
35
|
-
backlinksCount: note.backlinks.length
|
|
49
|
+
const output = results.map(({ file, tags: fileTags }) => ({
|
|
50
|
+
path: file.path,
|
|
51
|
+
basename: file.basename,
|
|
52
|
+
tags: fileTags
|
|
36
53
|
}));
|
|
37
54
|
console.log(JSON.stringify({
|
|
38
|
-
query,
|
|
39
|
-
filters: {
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
query: query ?? '',
|
|
56
|
+
filters: {
|
|
57
|
+
tags,
|
|
58
|
+
limit,
|
|
59
|
+
path: pathPrefix,
|
|
60
|
+
linksTo: linksToPath,
|
|
61
|
+
heading: headingQuery,
|
|
62
|
+
modifiedAfter: modifiedAfter ?? undefined,
|
|
63
|
+
modifiedBefore: modifiedBefore ?? undefined
|
|
64
|
+
},
|
|
65
|
+
results: output,
|
|
66
|
+
total: output.length
|
|
42
67
|
}, null, 2));
|
|
43
68
|
}
|
|
44
69
|
else {
|
|
45
|
-
// Text format
|
|
46
70
|
console.log(`Search results for "${query}":\n`);
|
|
47
|
-
|
|
48
|
-
console.log(`${i + 1}. ${
|
|
49
|
-
console.log(` Path: ${
|
|
50
|
-
console.log(` Tags: ${
|
|
51
|
-
console.log(` ID: ${note.id}`);
|
|
71
|
+
results.forEach(({ file, tags: fileTags }, i) => {
|
|
72
|
+
console.log(`${i + 1}. ${file.basename}`);
|
|
73
|
+
console.log(` Path: ${file.path}`);
|
|
74
|
+
console.log(` Tags: ${fileTags.join(', ') || 'none'}`);
|
|
52
75
|
console.log();
|
|
53
76
|
});
|
|
54
77
|
}
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
console.error('❌ Search failed:', error instanceof Error ? error.message : String(error));
|
|
59
|
-
process.exit(1);
|
|
60
|
-
}
|
|
78
|
+
});
|
|
61
79
|
});
|
|
62
80
|
return command;
|
|
63
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":";;AAIA,
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":";;AAIA,0CASC;AAED,kDAkEC;AAjFD,yCAAoC;AACpC,gEAAsD;AAEtD,4FAA4F;AAC5F,SAAgB,eAAe,CAAC,KAAyB;IACvD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IAC1D,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/B,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QACpB,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC1B,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5C,CAAC;IACD,MAAM,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzB,OAAO,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9C,CAAC;AAED,SAAgB,mBAAmB;IACjC,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,QAAQ,CAAC;SAClC,WAAW,CAAC,wCAAwC,CAAC;SACrD,QAAQ,CAAC,SAAS,EAAE,qEAAqE,EAAE,EAAE,CAAC;SAC9F,MAAM,CAAC,mBAAmB,EAAE,kCAAkC,CAAC;SAC/D,MAAM,CAAC,yBAAyB,EAAE,oEAAoE,CAAC;SACvG,MAAM,CAAC,qBAAqB,EAAE,iBAAiB,EAAE,I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G,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;oBAC1C,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;oBACrC,OAAO,CAAC,GAAG,CAAC,YAAY,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,MAAM,EAAE,CAAC,CAAC;oBACzD,OAAO,CAAC,GAAG,EAAE,CAAC;gBAChB,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/commands/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"stats.d.ts","sourceRoot":"","sources":["../../src/commands/stats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wBAAgB,kBAAkB,IAAI,OAAO,CAuB5C"}
|
package/dist/commands/stats.js
CHANGED
|
@@ -2,22 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStatsCommand = createStatsCommand;
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
|
-
const
|
|
6
|
-
const vault_js_1 = require("../utils/vault.js");
|
|
5
|
+
const vault_resolve_js_1 = require("../utils/vault-resolve.js");
|
|
7
6
|
function createStatsCommand() {
|
|
8
7
|
const command = new commander_1.Command('stats')
|
|
9
8
|
.description('Show vault statistics')
|
|
10
9
|
.option('-f, --format <format>', 'Output format (json|text)', 'text')
|
|
11
|
-
.action((options) => {
|
|
12
|
-
|
|
13
|
-
const vaultPath = config_js_1.ConfigManager.findVaultPath();
|
|
14
|
-
if (!vaultPath) {
|
|
15
|
-
console.error('❌ Not in a SecondBrain vault. Run `sb init` first.');
|
|
16
|
-
process.exit(1);
|
|
17
|
-
}
|
|
18
|
-
const configManager = new config_js_1.ConfigManager(vaultPath);
|
|
19
|
-
const config = configManager.getConfig();
|
|
20
|
-
const vault = new vault_js_1.VaultManager(config);
|
|
10
|
+
.action(async (options) => {
|
|
11
|
+
await (0, vault_resolve_js_1.withVault)((vault) => {
|
|
21
12
|
const stats = vault.getStats();
|
|
22
13
|
if (options.format === 'json') {
|
|
23
14
|
console.log(JSON.stringify(stats, null, 2));
|
|
@@ -32,12 +23,7 @@ function createStatsCommand() {
|
|
|
32
23
|
console.log('⚠️ Run `sb orphans` to see disconnected notes');
|
|
33
24
|
}
|
|
34
25
|
}
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
console.error('❌ Failed to get stats:', error instanceof Error ? error.message : String(error));
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
26
|
+
});
|
|
41
27
|
});
|
|
42
28
|
return command;
|
|
43
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stats.js","sourceRoot":"","sources":["../../src/commands/stats.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"stats.js","sourceRoot":"","sources":["../../src/commands/stats.ts"],"names":[],"mappings":";;AAGA,gDAuBC;AA1BD,yCAAoC;AACpC,gEAAsD;AAEtD,SAAgB,kBAAkB;IAChC,MAAM,OAAO,GAAG,IAAI,mBAAO,CAAC,OAAO,CAAC;SACjC,WAAW,CAAC,uBAAuB,CAAC;SACpC,MAAM,CAAC,uBAAuB,EAAE,2BAA2B,EAAE,MAAM,CAAC;SACpE,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;QACxB,MAAM,IAAA,4BAAS,EAAC,CAAC,KAAK,EAAE,EAAE;YACxB,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,EAAE,CAAC;YAC/B,IAAI,OAAO,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;gBAC9B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAC9C,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;gBACrC,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;gBAC9C,OAAO,CAAC,GAAG,CAAC,cAAc,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;gBAC9C,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;gBAC5C,IAAI,KAAK,CAAC,OAAO,GAAG,CAAC,EAAE,CAAC;oBACtB,OAAO,CAAC,GAAG,EAAE,CAAC;oBACd,OAAO,CAAC,GAAG,CAAC,gDAAgD,CAAC,CAAC;gBAChE,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEL,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../../src/commands/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wBAAgB,iBAAiB,IAAI,OAAO,CAqB3C"}
|