granite-mem 0.1.2 → 0.1.3
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 +4 -3
- package/dist/index.js +53 -36
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -77,7 +77,7 @@ npm run build
|
|
|
77
77
|
npm link
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
Create
|
|
80
|
+
Create the default vault in `~/.granite` and start capturing:
|
|
81
81
|
|
|
82
82
|
```bash
|
|
83
83
|
mem init
|
|
@@ -153,8 +153,9 @@ Granite keeps the source of truth boring and durable:
|
|
|
153
153
|
|
|
154
154
|
- notes are Markdown files
|
|
155
155
|
- metadata lives in YAML frontmatter
|
|
156
|
-
- vault
|
|
157
|
-
-
|
|
156
|
+
- the default vault lives in `~/.granite`
|
|
157
|
+
- vault configuration lives in `~/.granite/granite.yml`
|
|
158
|
+
- full-text search and link resolution are backed by a local SQLite index in `~/.granite/index.db`
|
|
158
159
|
- the index can be rebuilt from the files at any time
|
|
159
160
|
|
|
160
161
|
This keeps the system transparent, portable, and inspectable.
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
import { Command } from "commander";
|
|
5
5
|
|
|
6
6
|
// src/commands/init.ts
|
|
7
|
-
import
|
|
8
|
-
import
|
|
7
|
+
import fs3 from "fs";
|
|
8
|
+
import path3 from "path";
|
|
9
9
|
|
|
10
10
|
// src/core/config.ts
|
|
11
11
|
import fs from "fs";
|
|
@@ -116,59 +116,76 @@ function loadConfig(vaultRoot) {
|
|
|
116
116
|
return parsed;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
// src/core/vault.ts
|
|
120
|
+
import fs2 from "fs";
|
|
121
|
+
import os from "os";
|
|
122
|
+
import path2 from "path";
|
|
123
|
+
var DEFAULT_VAULT_DIRNAME = ".granite";
|
|
124
|
+
function hasVaultConfig(dir) {
|
|
125
|
+
return fs2.existsSync(path2.join(dir, CONFIG_FILENAME));
|
|
126
|
+
}
|
|
127
|
+
function getDefaultVaultRoot(homeDir = os.homedir()) {
|
|
128
|
+
return path2.resolve(homeDir, DEFAULT_VAULT_DIRNAME);
|
|
129
|
+
}
|
|
130
|
+
function findVaultRoot(from) {
|
|
131
|
+
let dir = from ? path2.resolve(from) : process.cwd();
|
|
132
|
+
while (true) {
|
|
133
|
+
if (hasVaultConfig(dir)) {
|
|
134
|
+
return dir;
|
|
135
|
+
}
|
|
136
|
+
const parent = path2.dirname(dir);
|
|
137
|
+
if (parent === dir) break;
|
|
138
|
+
dir = parent;
|
|
139
|
+
}
|
|
140
|
+
const defaultVaultRoot = getDefaultVaultRoot();
|
|
141
|
+
return hasVaultConfig(defaultVaultRoot) ? defaultVaultRoot : null;
|
|
142
|
+
}
|
|
143
|
+
function requireVaultRoot(from) {
|
|
144
|
+
const root = findVaultRoot(from);
|
|
145
|
+
if (!root) {
|
|
146
|
+
throw new Error(`No Granite vault found. Run "mem init" to create ${getDefaultVaultRoot()}.`);
|
|
147
|
+
}
|
|
148
|
+
return root;
|
|
149
|
+
}
|
|
150
|
+
function getIndexDbPath(vaultRoot) {
|
|
151
|
+
if (path2.basename(path2.resolve(vaultRoot)) === DEFAULT_VAULT_DIRNAME) {
|
|
152
|
+
return path2.join(vaultRoot, "index.db");
|
|
153
|
+
}
|
|
154
|
+
return path2.join(vaultRoot, ".granite", "index.db");
|
|
155
|
+
}
|
|
156
|
+
|
|
119
157
|
// src/commands/init.ts
|
|
120
|
-
function initVault(dir) {
|
|
121
|
-
const targetDir =
|
|
122
|
-
|
|
158
|
+
function initVault(dir = getDefaultVaultRoot()) {
|
|
159
|
+
const targetDir = path3.resolve(dir);
|
|
160
|
+
fs3.mkdirSync(targetDir, { recursive: true });
|
|
161
|
+
if (fs3.existsSync(path3.join(targetDir, CONFIG_FILENAME))) {
|
|
123
162
|
console.error(`Vault already exists in ${targetDir}`);
|
|
124
163
|
process.exit(1);
|
|
125
164
|
}
|
|
126
165
|
writeDefaultConfig(targetDir);
|
|
127
|
-
|
|
166
|
+
fs3.mkdirSync(path3.dirname(getIndexDbPath(targetDir)), { recursive: true });
|
|
128
167
|
const config = loadConfig(targetDir);
|
|
129
168
|
for (const typeConfig of Object.values(config.note_types)) {
|
|
130
|
-
|
|
169
|
+
fs3.mkdirSync(path3.join(targetDir, typeConfig.folder), { recursive: true });
|
|
131
170
|
}
|
|
132
171
|
console.log(`Vault initialized in ${targetDir}`);
|
|
133
172
|
console.log("");
|
|
134
173
|
console.log("Created:");
|
|
135
174
|
console.log(` ${CONFIG_FILENAME}`);
|
|
136
|
-
|
|
175
|
+
const indexDir = path3.relative(targetDir, path3.dirname(getIndexDbPath(targetDir)));
|
|
176
|
+
if (indexDir) {
|
|
177
|
+
console.log(` ${indexDir}/`);
|
|
178
|
+
}
|
|
137
179
|
for (const [name, typeConfig] of Object.entries(config.note_types)) {
|
|
138
180
|
console.log(` ${typeConfig.folder}/ (${name})`);
|
|
139
181
|
}
|
|
140
182
|
console.log("");
|
|
141
|
-
console.log('Next: mem new
|
|
183
|
+
console.log('Next: mem new "My first note" --type fleeting');
|
|
142
184
|
}
|
|
143
185
|
|
|
144
186
|
// src/commands/new.ts
|
|
145
187
|
import fs6 from "fs";
|
|
146
188
|
|
|
147
|
-
// src/core/vault.ts
|
|
148
|
-
import fs3 from "fs";
|
|
149
|
-
import path3 from "path";
|
|
150
|
-
function findVaultRoot(from) {
|
|
151
|
-
let dir = from ? path3.resolve(from) : process.cwd();
|
|
152
|
-
while (true) {
|
|
153
|
-
if (fs3.existsSync(path3.join(dir, CONFIG_FILENAME))) {
|
|
154
|
-
return dir;
|
|
155
|
-
}
|
|
156
|
-
const parent = path3.dirname(dir);
|
|
157
|
-
if (parent === dir) return null;
|
|
158
|
-
dir = parent;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
function requireVaultRoot(from) {
|
|
162
|
-
const root = findVaultRoot(from);
|
|
163
|
-
if (!root) {
|
|
164
|
-
throw new Error('Not inside a Granite vault. Run "mem init" to create one.');
|
|
165
|
-
}
|
|
166
|
-
return root;
|
|
167
|
-
}
|
|
168
|
-
function getIndexDbPath(vaultRoot) {
|
|
169
|
-
return path3.join(vaultRoot, ".granite", "index.db");
|
|
170
|
-
}
|
|
171
|
-
|
|
172
189
|
// src/core/note.ts
|
|
173
190
|
import fs4 from "fs";
|
|
174
191
|
import path4 from "path";
|
|
@@ -1945,8 +1962,8 @@ function printRecommendations(vaultRoot, config, filepath, strategy) {
|
|
|
1945
1962
|
// src/index.ts
|
|
1946
1963
|
var program = new Command();
|
|
1947
1964
|
program.name("mem").description("Granite \u2014 a local-first markdown memory system").version("0.1.0");
|
|
1948
|
-
program.command("init").description("Initialize
|
|
1949
|
-
initVault(
|
|
1965
|
+
program.command("init").description("Initialize the default vault in ~/.granite").action(() => {
|
|
1966
|
+
initVault();
|
|
1950
1967
|
});
|
|
1951
1968
|
program.command("new").description("Create a new note").argument("<title>", "Note title").option("-t, --type <type>", "Note type (e.g. fleeting, permanent, reference)").option("--source <source>", "Set source (human, agent, extraction)").option("--status <status>", "Set status (inbox, active, archived)").option("--json", "Output as JSON (agent-friendly)").action((title, options) => {
|
|
1952
1969
|
newNote(title, options);
|