@matelink/cli 2026.4.16 → 2026.4.17
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/bin/matecli.mjs +94 -2
- package/package.json +1 -1
package/bin/matecli.mjs
CHANGED
|
@@ -14,7 +14,7 @@ import fs from "node:fs";
|
|
|
14
14
|
import os from "node:os";
|
|
15
15
|
import path from "node:path";
|
|
16
16
|
import process from "node:process";
|
|
17
|
-
import { fileURLToPath } from "node:url";
|
|
17
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
18
18
|
|
|
19
19
|
const NUMERIC_CODE_LENGTH = 4;
|
|
20
20
|
const GROUP_SIZE = 4;
|
|
@@ -51,6 +51,7 @@ const DEFAULT_GATEWAY_SCOPES = [
|
|
|
51
51
|
"operator.approvals",
|
|
52
52
|
"operator.pairing",
|
|
53
53
|
].join(",");
|
|
54
|
+
const SESSION_CONTEXT_MIN_TOKENS = 1024;
|
|
54
55
|
const CLI_ENTRY = fileURLToPath(import.meta.url);
|
|
55
56
|
const CLI_LANGUAGE = detectCliLanguage();
|
|
56
57
|
const CLI_I18N = {
|
|
@@ -446,6 +447,18 @@ function resolveOpenClawConfigPath() {
|
|
|
446
447
|
return path.join(resolveOpenClawHome(), "openclaw.json");
|
|
447
448
|
}
|
|
448
449
|
|
|
450
|
+
function resolveOpenClawDistPath(fileName) {
|
|
451
|
+
return path.join(
|
|
452
|
+
resolveOpenClawHome(),
|
|
453
|
+
"extensions",
|
|
454
|
+
"memory-tdai",
|
|
455
|
+
"node_modules",
|
|
456
|
+
"openclaw",
|
|
457
|
+
"dist",
|
|
458
|
+
fileName,
|
|
459
|
+
);
|
|
460
|
+
}
|
|
461
|
+
|
|
449
462
|
function resolveTestNextIMStatePath() {
|
|
450
463
|
return path.join(resolveOpenClawHome(), "testnextim.state.json");
|
|
451
464
|
}
|
|
@@ -546,6 +559,21 @@ function resolveConfiguredWorkspaceRoot() {
|
|
|
546
559
|
return path.resolve(resolved);
|
|
547
560
|
}
|
|
548
561
|
|
|
562
|
+
let sessionStoreHelpersPromise = null;
|
|
563
|
+
|
|
564
|
+
async function loadSessionStoreHelpers() {
|
|
565
|
+
if (!sessionStoreHelpersPromise) {
|
|
566
|
+
sessionStoreHelpersPromise = Promise.all([
|
|
567
|
+
import(pathToFileURL(resolveOpenClawDistPath("session-utils-PHKOUUva.js")).href),
|
|
568
|
+
import(pathToFileURL(resolveOpenClawDistPath("store-DACjypj4.js")).href),
|
|
569
|
+
]).then(([sessionUtilsMod, storeMod]) => ({
|
|
570
|
+
loadSessionEntry: sessionUtilsMod.s,
|
|
571
|
+
updateSessionStoreEntry: storeMod.f,
|
|
572
|
+
}));
|
|
573
|
+
}
|
|
574
|
+
return sessionStoreHelpersPromise;
|
|
575
|
+
}
|
|
576
|
+
|
|
549
577
|
function normalizeWorkspaceRelativePath(rawName) {
|
|
550
578
|
const value = String(rawName ?? "").trim();
|
|
551
579
|
if (!value) {
|
|
@@ -814,6 +842,62 @@ async function callWorkspaceRpcLocal({
|
|
|
814
842
|
return null;
|
|
815
843
|
}
|
|
816
844
|
|
|
845
|
+
async function callSessionContextRpcLocal({
|
|
846
|
+
method,
|
|
847
|
+
params,
|
|
848
|
+
}) {
|
|
849
|
+
const sessionKey = String(params?.sessionKey ?? params?.key ?? "").trim();
|
|
850
|
+
if (!sessionKey) {
|
|
851
|
+
throw new Error("session key is required");
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
const { loadSessionEntry, updateSessionStoreEntry } = await loadSessionStoreHelpers();
|
|
855
|
+
const loaded = loadSessionEntry(sessionKey);
|
|
856
|
+
const resolvedSessionKey = String(loaded?.canonicalKey ?? sessionKey).trim() || sessionKey;
|
|
857
|
+
|
|
858
|
+
if (method === "session.context.get") {
|
|
859
|
+
return {
|
|
860
|
+
ok: true,
|
|
861
|
+
sessionKey: resolvedSessionKey,
|
|
862
|
+
contextTokens: Number.isFinite(loaded?.entry?.contextTokens)
|
|
863
|
+
? Math.max(0, Math.floor(loaded.entry.contextTokens))
|
|
864
|
+
: null,
|
|
865
|
+
storePath: loaded?.storePath ?? "",
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
if (method === "session.context.set") {
|
|
870
|
+
if (!loaded?.entry || !String(loaded?.storePath ?? "").trim()) {
|
|
871
|
+
throw new Error(`session not found: ${sessionKey}`);
|
|
872
|
+
}
|
|
873
|
+
const contextTokens = Math.max(
|
|
874
|
+
SESSION_CONTEXT_MIN_TOKENS,
|
|
875
|
+
Math.floor(Number(params?.contextTokens ?? 0) || 0),
|
|
876
|
+
);
|
|
877
|
+
const updated = await updateSessionStoreEntry({
|
|
878
|
+
storePath: loaded.storePath,
|
|
879
|
+
sessionKey: resolvedSessionKey,
|
|
880
|
+
update: async (existing) => ({
|
|
881
|
+
contextTokens,
|
|
882
|
+
updatedAt: Math.max(existing?.updatedAt ?? 0, Date.now()),
|
|
883
|
+
}),
|
|
884
|
+
});
|
|
885
|
+
if (!updated) {
|
|
886
|
+
throw new Error(`session not found: ${sessionKey}`);
|
|
887
|
+
}
|
|
888
|
+
return {
|
|
889
|
+
ok: true,
|
|
890
|
+
sessionKey: resolvedSessionKey,
|
|
891
|
+
contextTokens: Number.isFinite(updated?.contextTokens)
|
|
892
|
+
? Math.max(0, Math.floor(updated.contextTokens))
|
|
893
|
+
: contextTokens,
|
|
894
|
+
storePath: loaded.storePath,
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
return null;
|
|
899
|
+
}
|
|
900
|
+
|
|
817
901
|
function commandToString(command, args) {
|
|
818
902
|
return [command, ...args]
|
|
819
903
|
.map((part) => {
|
|
@@ -3037,12 +3121,20 @@ async function callGatewayRpcLocal({
|
|
|
3037
3121
|
return {
|
|
3038
3122
|
ok: true,
|
|
3039
3123
|
methods: ["sessions.list", "sessions.abort", "sessions.delete", "sessions.usage", "sessions.patch",
|
|
3040
|
-
"usage.cost", "
|
|
3124
|
+
"usage.cost", "session.context.get", "session.context.set",
|
|
3125
|
+
"memory.files.list", "memory.files.get", "memory.files.set", "agents.files.list", "agents.files.get", "agents.files.set",
|
|
3041
3126
|
"skills.status", "models.list", "chat.history", "chat.abort",
|
|
3042
3127
|
"config.get", "config.patch"],
|
|
3043
3128
|
};
|
|
3044
3129
|
}
|
|
3045
3130
|
|
|
3131
|
+
if (
|
|
3132
|
+
method === "session.context.get" ||
|
|
3133
|
+
method === "session.context.set"
|
|
3134
|
+
) {
|
|
3135
|
+
return callSessionContextRpcLocal({ method, params });
|
|
3136
|
+
}
|
|
3137
|
+
|
|
3046
3138
|
if (
|
|
3047
3139
|
method === "memory.files.list" ||
|
|
3048
3140
|
method === "memory.files.get" ||
|