open-think 0.4.0 → 0.4.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/dist/index.js +73 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -39,8 +39,8 @@ import {
|
|
|
39
39
|
} from "./chunk-HUBRLTY3.js";
|
|
40
40
|
|
|
41
41
|
// src/index.ts
|
|
42
|
-
import
|
|
43
|
-
import
|
|
42
|
+
import fs14 from "fs";
|
|
43
|
+
import path8 from "path";
|
|
44
44
|
import { Command as Command21 } from "commander";
|
|
45
45
|
|
|
46
46
|
// src/commands/log.ts
|
|
@@ -1648,8 +1648,18 @@ var GitSyncAdapter = class {
|
|
|
1648
1648
|
}
|
|
1649
1649
|
async push(cortex) {
|
|
1650
1650
|
const result = { pushed: 0, pulled: 0, errors: [] };
|
|
1651
|
-
|
|
1652
|
-
|
|
1651
|
+
try {
|
|
1652
|
+
ensureRepoCloned();
|
|
1653
|
+
fetchBranch(cortex);
|
|
1654
|
+
} catch (err) {
|
|
1655
|
+
result.errors.push(err instanceof Error ? err.message : String(err));
|
|
1656
|
+
return result;
|
|
1657
|
+
}
|
|
1658
|
+
this.pushMemories(cortex, result);
|
|
1659
|
+
this.pushLongTermEvents(cortex, result);
|
|
1660
|
+
return result;
|
|
1661
|
+
}
|
|
1662
|
+
pushMemories(cortex, result) {
|
|
1653
1663
|
const cursorStr = getSyncCursor(cortex, "git", "push");
|
|
1654
1664
|
const lastVersion = cursorStr ? parseInt(cursorStr, 10) : 0;
|
|
1655
1665
|
const branchFiles = listBranchFiles(cortex, ".jsonl");
|
|
@@ -1657,11 +1667,11 @@ var GitSyncAdapter = class {
|
|
|
1657
1667
|
this.ensureMigrated(cortex, branchFiles);
|
|
1658
1668
|
} catch (err) {
|
|
1659
1669
|
result.errors.push(`Migration failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
1660
|
-
return
|
|
1670
|
+
return;
|
|
1661
1671
|
}
|
|
1662
1672
|
const currentFiles = branchFiles.some((f) => /^\d{6}\.jsonl$/.test(f)) ? branchFiles : listBranchFiles(cortex, ".jsonl");
|
|
1663
1673
|
const newMemories = getMemoriesBySyncVersion(cortex, lastVersion);
|
|
1664
|
-
if (newMemories.length === 0) return
|
|
1674
|
+
if (newMemories.length === 0) return;
|
|
1665
1675
|
const targetFile = this.determineBucketFile(cortex, currentFiles);
|
|
1666
1676
|
const newLines = newMemories.map((m) => {
|
|
1667
1677
|
let decisions = [];
|
|
@@ -1687,12 +1697,10 @@ var GitSyncAdapter = class {
|
|
|
1687
1697
|
try {
|
|
1688
1698
|
appendAndCommit(cortex, newLines, commitMsg, 3, targetFile);
|
|
1689
1699
|
setSyncCursor(cortex, "git", "push", String(maxVersion));
|
|
1690
|
-
result.pushed
|
|
1700
|
+
result.pushed += newMemories.length;
|
|
1691
1701
|
} catch (err) {
|
|
1692
1702
|
result.errors.push(err instanceof Error ? err.message : String(err));
|
|
1693
1703
|
}
|
|
1694
|
-
this.pushLongTermEvents(cortex, result);
|
|
1695
|
-
return result;
|
|
1696
1704
|
}
|
|
1697
1705
|
pushLongTermEvents(cortex, result) {
|
|
1698
1706
|
const cursorStr = getSyncCursor(cortex, "git", "push_lt");
|
|
@@ -1766,6 +1774,11 @@ var GitSyncAdapter = class {
|
|
|
1766
1774
|
result.errors.push(err instanceof Error ? err.message : String(err));
|
|
1767
1775
|
return result;
|
|
1768
1776
|
}
|
|
1777
|
+
this.pullMemories(cortex, result);
|
|
1778
|
+
this.pullLongTermEvents(cortex, result);
|
|
1779
|
+
return result;
|
|
1780
|
+
}
|
|
1781
|
+
pullMemories(cortex, result) {
|
|
1769
1782
|
const config = getConfig();
|
|
1770
1783
|
const onboardingDepth = config.cortex?.onboardingDepth ?? 1500;
|
|
1771
1784
|
const bucketSize = config.cortex?.bucketSize ?? 500;
|
|
@@ -1775,7 +1788,7 @@ var GitSyncAdapter = class {
|
|
|
1775
1788
|
if (memoriesRaw) {
|
|
1776
1789
|
this.processMemories(cortex, memoriesRaw, result);
|
|
1777
1790
|
}
|
|
1778
|
-
return
|
|
1791
|
+
return;
|
|
1779
1792
|
}
|
|
1780
1793
|
const pullCursor = getSyncCursor(cortex, "git", "pull_file");
|
|
1781
1794
|
let filesToRead;
|
|
@@ -1805,8 +1818,6 @@ var GitSyncAdapter = class {
|
|
|
1805
1818
|
if (lastReadFile) {
|
|
1806
1819
|
setSyncCursor(cortex, "git", "pull_file", lastReadFile);
|
|
1807
1820
|
}
|
|
1808
|
-
this.pullLongTermEvents(cortex, result);
|
|
1809
|
-
return result;
|
|
1810
1821
|
}
|
|
1811
1822
|
pullLongTermEvents(cortex, result) {
|
|
1812
1823
|
const raw = readFileFromBranch(cortex, LONG_TERM_FILE);
|
|
@@ -3185,31 +3196,72 @@ configCommand.addCommand(new Command17("set").argument("<key>", "Config key (e.g
|
|
|
3185
3196
|
}));
|
|
3186
3197
|
|
|
3187
3198
|
// src/commands/update.ts
|
|
3199
|
+
import fs12 from "fs";
|
|
3200
|
+
import path7 from "path";
|
|
3188
3201
|
import { Command as Command18 } from "commander";
|
|
3189
3202
|
import { execFileSync as execFileSync2 } from "child_process";
|
|
3190
3203
|
import chalk18 from "chalk";
|
|
3204
|
+
function getInstalledVersion2() {
|
|
3205
|
+
try {
|
|
3206
|
+
const npmRoot = execFileSync2("npm", ["root", "-g"], { encoding: "utf-8" }).trim();
|
|
3207
|
+
const pkgPath = path7.join(npmRoot, "open-think", "package.json");
|
|
3208
|
+
if (!fs12.existsSync(pkgPath)) return null;
|
|
3209
|
+
const pkg = JSON.parse(fs12.readFileSync(pkgPath, "utf-8"));
|
|
3210
|
+
return typeof pkg.version === "string" ? pkg.version : null;
|
|
3211
|
+
} catch {
|
|
3212
|
+
return null;
|
|
3213
|
+
}
|
|
3214
|
+
}
|
|
3215
|
+
function getLatestPublishedVersion() {
|
|
3216
|
+
try {
|
|
3217
|
+
const v = execFileSync2("npm", ["view", "open-think", "version"], {
|
|
3218
|
+
encoding: "utf-8",
|
|
3219
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
3220
|
+
}).trim();
|
|
3221
|
+
return v || null;
|
|
3222
|
+
} catch {
|
|
3223
|
+
return null;
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3191
3226
|
var updateCommand = new Command18("update").description("Update think to the latest version").action(() => {
|
|
3192
3227
|
console.log(chalk18.cyan("Checking for updates..."));
|
|
3228
|
+
const before = getInstalledVersion2();
|
|
3229
|
+
const latest = getLatestPublishedVersion();
|
|
3230
|
+
if (before && latest && before === latest) {
|
|
3231
|
+
console.log(chalk18.dim(`Already up to date (open-think@${before}).`));
|
|
3232
|
+
return;
|
|
3233
|
+
}
|
|
3193
3234
|
try {
|
|
3194
|
-
|
|
3235
|
+
execFileSync2("npm", ["install", "-g", "--prefer-online", "open-think@latest"], {
|
|
3195
3236
|
encoding: "utf-8",
|
|
3196
3237
|
stdio: ["pipe", "pipe", "pipe"]
|
|
3197
3238
|
});
|
|
3198
|
-
const match = result.match(/open-think@(\S+)/);
|
|
3199
|
-
const version = match ? match[1] : "latest";
|
|
3200
|
-
console.log(chalk18.green("\u2713") + ` Updated to open-think@${version}`);
|
|
3201
3239
|
} catch (err) {
|
|
3202
3240
|
const message = err instanceof Error ? err.message : String(err);
|
|
3203
3241
|
console.error(chalk18.red("Update failed. Try manually: npm install -g open-think@latest"));
|
|
3204
3242
|
if (message.includes("EACCES")) {
|
|
3205
3243
|
console.error(chalk18.dim(" You may need to run with sudo or fix npm permissions."));
|
|
3206
3244
|
}
|
|
3245
|
+
return;
|
|
3246
|
+
}
|
|
3247
|
+
const after = getInstalledVersion2();
|
|
3248
|
+
if (after && latest && after === latest) {
|
|
3249
|
+
console.log(chalk18.green("\u2713") + ` Updated to open-think@${after}`);
|
|
3250
|
+
} else if (after && before && after !== before) {
|
|
3251
|
+
console.log(chalk18.green("\u2713") + ` Updated to open-think@${after}${latest ? chalk18.dim(` (registry says latest is ${latest})`) : ""}`);
|
|
3252
|
+
} else if (after && latest && after !== latest) {
|
|
3253
|
+
console.error(chalk18.yellow("\u26A0") + ` npm reported success but installed version is ${after}, expected ${latest}.`);
|
|
3254
|
+
console.error(chalk18.dim(" Try: npm cache clean --force && npm install -g open-think@latest"));
|
|
3255
|
+
} else if (after) {
|
|
3256
|
+
console.log(chalk18.dim(`Installed version: open-think@${after} (could not verify against registry).`));
|
|
3257
|
+
} else {
|
|
3258
|
+
console.error(chalk18.yellow("\u26A0") + " Could not locate the installed package to verify the update.");
|
|
3207
3259
|
}
|
|
3208
3260
|
});
|
|
3209
3261
|
|
|
3210
3262
|
// src/commands/migrate-data.ts
|
|
3211
3263
|
import { Command as Command19 } from "commander";
|
|
3212
|
-
import
|
|
3264
|
+
import fs13 from "fs";
|
|
3213
3265
|
import chalk19 from "chalk";
|
|
3214
3266
|
var migrateDataCommand = new Command19("migrate-data").description("Import existing memories from git into local SQLite (one-time migration)").action(async () => {
|
|
3215
3267
|
const config = getConfig();
|
|
@@ -3247,8 +3299,8 @@ var migrateDataCommand = new Command19("migrate-data").description("Import exist
|
|
|
3247
3299
|
if (wasInserted) inserted++;
|
|
3248
3300
|
}
|
|
3249
3301
|
const ltPath = getLongtermPath(cortex);
|
|
3250
|
-
if (
|
|
3251
|
-
const ltContent =
|
|
3302
|
+
if (fs13.existsSync(ltPath)) {
|
|
3303
|
+
const ltContent = fs13.readFileSync(ltPath, "utf-8").trim();
|
|
3252
3304
|
if (ltContent) {
|
|
3253
3305
|
setLongtermSummary(cortex, ltContent);
|
|
3254
3306
|
console.log(chalk19.green(" \u2713") + " Long-term summary migrated");
|
|
@@ -3627,8 +3679,8 @@ longTermCommand.addCommand(new Command20("record").description("Manually record
|
|
|
3627
3679
|
// src/index.ts
|
|
3628
3680
|
function readPackageVersion() {
|
|
3629
3681
|
try {
|
|
3630
|
-
const pkgPath =
|
|
3631
|
-
return JSON.parse(
|
|
3682
|
+
const pkgPath = path8.join(import.meta.dirname, "..", "package.json");
|
|
3683
|
+
return JSON.parse(fs14.readFileSync(pkgPath, "utf-8")).version ?? "0.0.0";
|
|
3632
3684
|
} catch {
|
|
3633
3685
|
return "0.0.0";
|
|
3634
3686
|
}
|