@heyamiko/amiko-cli 0.9.9-beta.1 → 0.9.9-beta.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/dist/index.js +69 -29
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22013,7 +22013,7 @@ function registerNotificationsCommand(program2) {
|
|
|
22013
22013
|
}
|
|
22014
22014
|
|
|
22015
22015
|
// src/commands/memory.ts
|
|
22016
|
-
import { existsSync as existsSync3, readFileSync as readFileSync2, statSync } from "node:fs";
|
|
22016
|
+
import { existsSync as existsSync3, readdirSync, readFileSync as readFileSync2, statSync } from "node:fs";
|
|
22017
22017
|
import { dirname, isAbsolute, normalize, resolve as resolve2 } from "node:path";
|
|
22018
22018
|
var VALID_CATEGORIES = ["fact", "preference", "pattern", "decision", "context"];
|
|
22019
22019
|
var VALID_SOURCES = ["chat", "file", "manual"];
|
|
@@ -22184,13 +22184,18 @@ function registerMemoryCommand(program2) {
|
|
|
22184
22184
|
fail(e instanceof Error ? e.message : String(e));
|
|
22185
22185
|
}
|
|
22186
22186
|
});
|
|
22187
|
-
memory.command("sync").description("Sync MEMORY.md
|
|
22187
|
+
memory.command("sync").description("Sync MEMORY.md, its referenced files, and every .md under <workspace>/memory/ (one-way: local → server)").option("--path <dir>", `Workspace dir (default ${DEFAULT_WORKSPACE}). Looks for MEMORY.md, memory/MEMORY.md, and memory/**/*.md`).option("--dry-run", "Print what would be synced without uploading").option("--prune", "Delete server-side memory files that no longer exist locally").option("--json", "Output as JSON").action(async (opts) => {
|
|
22188
22188
|
const root = resolve2(opts.path || DEFAULT_WORKSPACE);
|
|
22189
|
-
const
|
|
22190
|
-
|
|
22191
|
-
|
|
22192
|
-
|
|
22193
|
-
const
|
|
22189
|
+
const candidateIndexes = [
|
|
22190
|
+
resolve2(root, "MEMORY.md"),
|
|
22191
|
+
resolve2(root, "memory", "MEMORY.md")
|
|
22192
|
+
].filter((p) => existsSync3(p));
|
|
22193
|
+
const memoryDir = resolve2(root, "memory");
|
|
22194
|
+
const memoryDirExists = existsSync3(memoryDir) && statSync(memoryDir).isDirectory();
|
|
22195
|
+
if (!candidateIndexes.length && !memoryDirExists) {
|
|
22196
|
+
fail(`No MEMORY.md or memory/ folder found under ${root}. Expected ${root}/MEMORY.md or ${root}/memory/.`);
|
|
22197
|
+
}
|
|
22198
|
+
const collected = collectMemoryFiles(root, candidateIndexes, memoryDirExists ? memoryDir : null);
|
|
22194
22199
|
if (collected.errors.length && !opts.json) {
|
|
22195
22200
|
for (const e of collected.errors)
|
|
22196
22201
|
console.error(error(e));
|
|
@@ -22273,37 +22278,72 @@ function registerMemoryCommand(program2) {
|
|
|
22273
22278
|
}
|
|
22274
22279
|
});
|
|
22275
22280
|
}
|
|
22276
|
-
function collectMemoryFiles(root,
|
|
22281
|
+
function collectMemoryFiles(root, indexPaths, memoryDir) {
|
|
22277
22282
|
const errors2 = [];
|
|
22278
22283
|
const seen = new Set;
|
|
22279
22284
|
const files = [];
|
|
22280
|
-
const
|
|
22281
|
-
|
|
22282
|
-
|
|
22283
|
-
pushFile(files, seen, indexPath, indexContent, root);
|
|
22284
|
-
const indexDir = dirname(indexPath);
|
|
22285
|
-
for (const ref of extractMarkdownLinks(indexContent)) {
|
|
22286
|
-
if (isExternal(ref))
|
|
22287
|
-
continue;
|
|
22288
|
-
const abs = normalize(isAbsolute(ref) ? ref : resolve2(indexDir, ref));
|
|
22289
|
-
if (!abs.startsWith(root)) {
|
|
22290
|
-
errors2.push(`Skipping ${ref}: outside workspace ${root}`);
|
|
22285
|
+
for (const indexPath of indexPaths) {
|
|
22286
|
+
const indexContent = safeRead(indexPath, errors2);
|
|
22287
|
+
if (indexContent === null)
|
|
22291
22288
|
continue;
|
|
22289
|
+
pushFile(files, seen, indexPath, indexContent, root);
|
|
22290
|
+
const indexDir = dirname(indexPath);
|
|
22291
|
+
for (const ref of extractMarkdownLinks(indexContent)) {
|
|
22292
|
+
if (isExternal(ref))
|
|
22293
|
+
continue;
|
|
22294
|
+
const abs = normalize(isAbsolute(ref) ? ref : resolve2(indexDir, ref));
|
|
22295
|
+
if (!abs.startsWith(root)) {
|
|
22296
|
+
errors2.push(`Skipping ${ref}: outside workspace ${root}`);
|
|
22297
|
+
continue;
|
|
22298
|
+
}
|
|
22299
|
+
if (!existsSync3(abs)) {
|
|
22300
|
+
errors2.push(`Referenced file missing: ${ref}`);
|
|
22301
|
+
continue;
|
|
22302
|
+
}
|
|
22303
|
+
const st = statSync(abs);
|
|
22304
|
+
if (!st.isFile())
|
|
22305
|
+
continue;
|
|
22306
|
+
const content = safeRead(abs, errors2);
|
|
22307
|
+
if (content === null)
|
|
22308
|
+
continue;
|
|
22309
|
+
pushFile(files, seen, abs, content, root);
|
|
22292
22310
|
}
|
|
22293
|
-
|
|
22294
|
-
|
|
22295
|
-
|
|
22311
|
+
}
|
|
22312
|
+
if (memoryDir) {
|
|
22313
|
+
for (const abs of walkMarkdown(memoryDir, errors2)) {
|
|
22314
|
+
const content = safeRead(abs, errors2);
|
|
22315
|
+
if (content === null)
|
|
22316
|
+
continue;
|
|
22317
|
+
pushFile(files, seen, abs, content, root);
|
|
22296
22318
|
}
|
|
22297
|
-
const st = statSync(abs);
|
|
22298
|
-
if (!st.isFile())
|
|
22299
|
-
continue;
|
|
22300
|
-
const content = safeRead(abs, errors2);
|
|
22301
|
-
if (content === null)
|
|
22302
|
-
continue;
|
|
22303
|
-
pushFile(files, seen, abs, content, root);
|
|
22304
22319
|
}
|
|
22305
22320
|
return { files, errors: errors2 };
|
|
22306
22321
|
}
|
|
22322
|
+
function walkMarkdown(dir, errors2) {
|
|
22323
|
+
const out = [];
|
|
22324
|
+
let names;
|
|
22325
|
+
try {
|
|
22326
|
+
names = readdirSync(dir);
|
|
22327
|
+
} catch (e) {
|
|
22328
|
+
errors2.push(`Failed to read ${dir}: ${e instanceof Error ? e.message : String(e)}`);
|
|
22329
|
+
return out;
|
|
22330
|
+
}
|
|
22331
|
+
for (const name of names) {
|
|
22332
|
+
const abs = resolve2(dir, name);
|
|
22333
|
+
let st;
|
|
22334
|
+
try {
|
|
22335
|
+
st = statSync(abs);
|
|
22336
|
+
} catch {
|
|
22337
|
+
continue;
|
|
22338
|
+
}
|
|
22339
|
+
if (st.isDirectory()) {
|
|
22340
|
+
out.push(...walkMarkdown(abs, errors2));
|
|
22341
|
+
} else if (st.isFile() && name.toLowerCase().endsWith(".md")) {
|
|
22342
|
+
out.push(abs);
|
|
22343
|
+
}
|
|
22344
|
+
}
|
|
22345
|
+
return out;
|
|
22346
|
+
}
|
|
22307
22347
|
function pushFile(files, seen, abs, content, root) {
|
|
22308
22348
|
const key = relativeKey(abs, root);
|
|
22309
22349
|
if (seen.has(key))
|