@aliyunrds/ctxdb 0.0.8-beta.2 → 0.0.8-beta.4
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/{chunk-BWPFGTF7.js → chunk-R6TLOWVZ.js} +11 -0
- package/dist/{chunk-52IAVJRK.js → chunk-WBFP2KGQ.js} +1 -1
- package/dist/{chunk-73OY44GY.js → chunk-ZIG7FIPN.js} +2 -2
- package/dist/cli/main.js +125 -19
- package/dist/hooks/session-start.js +3 -3
- package/dist/hooks/stop.js +7 -2
- package/dist/hooks/user-prompt-submit.js +3 -3
- package/package.json +1 -1
|
@@ -281,6 +281,16 @@ function agentHomeDir(agent) {
|
|
|
281
281
|
return join3(homedir2(), ".claude");
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
+
var AGENT_VARIANT_HOMES = {
|
|
285
|
+
qoderwork: [".qoderworkcn"]
|
|
286
|
+
};
|
|
287
|
+
function agentHomeDirs(agent) {
|
|
288
|
+
const primary = agentHomeDir(agent);
|
|
289
|
+
const variants = (AGENT_VARIANT_HOMES[agent] ?? []).map(
|
|
290
|
+
(name) => join3(homedir2(), name)
|
|
291
|
+
);
|
|
292
|
+
return [primary, ...variants];
|
|
293
|
+
}
|
|
284
294
|
function agentFromEnv(env = process.env) {
|
|
285
295
|
return isAgentSlug(env.CTXDB_AGENT) ? env.CTXDB_AGENT : "default";
|
|
286
296
|
}
|
|
@@ -505,6 +515,7 @@ export {
|
|
|
505
515
|
isBuiltinAgent,
|
|
506
516
|
isAgentSlug,
|
|
507
517
|
agentHomeDir,
|
|
518
|
+
agentHomeDirs,
|
|
508
519
|
agentFromEnv,
|
|
509
520
|
agentFromArgvWithFallback,
|
|
510
521
|
configDir,
|
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
isConnectionError,
|
|
7
7
|
resetCircuit,
|
|
8
8
|
tripCircuit
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-WBFP2KGQ.js";
|
|
10
10
|
import {
|
|
11
11
|
CtxdbError
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-R6TLOWVZ.js";
|
|
13
13
|
|
|
14
14
|
// src/lib/recall-orchestrator.ts
|
|
15
15
|
import {
|
package/dist/cli/main.js
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
SUPPORTED_AGENTS,
|
|
23
23
|
agentFromEnv,
|
|
24
24
|
agentHomeDir,
|
|
25
|
+
agentHomeDirs,
|
|
25
26
|
configuredAgents,
|
|
26
27
|
isAgentSlug,
|
|
27
28
|
isBuiltinAgent,
|
|
@@ -30,7 +31,7 @@ import {
|
|
|
30
31
|
removeAgent,
|
|
31
32
|
save,
|
|
32
33
|
writeInstalledPkgVersion
|
|
33
|
-
} from "../chunk-
|
|
34
|
+
} from "../chunk-R6TLOWVZ.js";
|
|
34
35
|
|
|
35
36
|
// src/cli/util.ts
|
|
36
37
|
var BOOLEAN_FLAGS = /* @__PURE__ */ new Set([
|
|
@@ -379,6 +380,32 @@ async function runSetup(options) {
|
|
|
379
380
|
if (agent === "codex") {
|
|
380
381
|
steps.push(enableCodexHooksFeature());
|
|
381
382
|
}
|
|
383
|
+
const primaryHome = agentHomeDir(agent);
|
|
384
|
+
const variantHomes = agentHomeDirs(agent).filter((d) => d !== primaryHome && existsSync(d));
|
|
385
|
+
for (const vHome of variantHomes) {
|
|
386
|
+
const tag = vHome.split("/").pop() ?? vHome;
|
|
387
|
+
if (installSkill) {
|
|
388
|
+
const vr = installSkillsTo(join(vHome, "skills"), agent);
|
|
389
|
+
steps.push(...vr.steps.map((s) => ({ ...s, step: `${tag}:${s.step}` })));
|
|
390
|
+
}
|
|
391
|
+
try {
|
|
392
|
+
const vPath = join(vHome, "settings.json");
|
|
393
|
+
backupSettingsFile(vPath);
|
|
394
|
+
const vRemoved = stripCtxdbHooksFromFile(vPath);
|
|
395
|
+
appendHooksToFile(vPath, agent, hookPaths);
|
|
396
|
+
steps.push({
|
|
397
|
+
step: `${tag}:append-hooks`,
|
|
398
|
+
ok: true,
|
|
399
|
+
detail: vRemoved > 0 ? `replaced ${vRemoved} stale` : void 0
|
|
400
|
+
});
|
|
401
|
+
} catch (err) {
|
|
402
|
+
steps.push({
|
|
403
|
+
step: `${tag}:settings-update`,
|
|
404
|
+
ok: false,
|
|
405
|
+
detail: err?.message ?? String(err)
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
}
|
|
382
409
|
}
|
|
383
410
|
if (validate) {
|
|
384
411
|
if (!cfg.apiKey || !cfg.baseUrl) {
|
|
@@ -471,6 +498,44 @@ function runRemove(agent, options = {}) {
|
|
|
471
498
|
});
|
|
472
499
|
}
|
|
473
500
|
}
|
|
501
|
+
const primaryHome = agentHomeDir(agent);
|
|
502
|
+
const variantHomes = agentHomeDirs(agent).filter((d) => d !== primaryHome && existsSync(d));
|
|
503
|
+
for (const vHome of variantHomes) {
|
|
504
|
+
const tag = vHome.split("/").pop() ?? vHome;
|
|
505
|
+
const vPath = join(vHome, "settings.json");
|
|
506
|
+
if (existsSync(vPath)) {
|
|
507
|
+
try {
|
|
508
|
+
backupSettingsFile(vPath);
|
|
509
|
+
const vRemoved = stripCtxdbHooksFromFile(vPath);
|
|
510
|
+
steps.push({
|
|
511
|
+
step: `${tag}:remove-hooks`,
|
|
512
|
+
ok: true,
|
|
513
|
+
detail: `removed ${vRemoved} entries`
|
|
514
|
+
});
|
|
515
|
+
} catch (err) {
|
|
516
|
+
steps.push({
|
|
517
|
+
step: `${tag}:remove-hooks`,
|
|
518
|
+
ok: false,
|
|
519
|
+
detail: err?.message ?? String(err)
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
const vSkillRoot = join(vHome, "skills");
|
|
524
|
+
for (const d of [...SKILL_DIRS, ...LEGACY_SKILL_DIRS]) {
|
|
525
|
+
const sp = join(vSkillRoot, d);
|
|
526
|
+
if (!existsSync(sp)) continue;
|
|
527
|
+
try {
|
|
528
|
+
rmSync(sp, { recursive: true, force: true });
|
|
529
|
+
steps.push({ step: `${tag}:remove-skill-dir`, ok: true, detail: sp });
|
|
530
|
+
} catch (err) {
|
|
531
|
+
steps.push({
|
|
532
|
+
step: `${tag}:remove-skill-dir`,
|
|
533
|
+
ok: false,
|
|
534
|
+
detail: `${sp}: ${err?.message ?? String(err)}`
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
474
539
|
}
|
|
475
540
|
try {
|
|
476
541
|
const r = removeAgent(agent, void 0, {
|
|
@@ -505,15 +570,16 @@ function runRemove(agent, options = {}) {
|
|
|
505
570
|
return { ok: steps.every((s) => s.ok), steps };
|
|
506
571
|
}
|
|
507
572
|
function checkAgentHome(agent) {
|
|
508
|
-
const
|
|
509
|
-
if (
|
|
573
|
+
const dirs = agentHomeDirs(agent).filter((d) => existsSync(d));
|
|
574
|
+
if (dirs.length === 0) {
|
|
575
|
+
const primary = agentHomeDir(agent);
|
|
510
576
|
return {
|
|
511
577
|
step: "check-agent-home",
|
|
512
578
|
ok: false,
|
|
513
|
-
detail: `${
|
|
579
|
+
detail: `${primary} not found; install or start ${agent} once before running ctxdb setup --agent ${agent}`
|
|
514
580
|
};
|
|
515
581
|
}
|
|
516
|
-
return { step: "check-agent-home", ok: true, detail:
|
|
582
|
+
return { step: "check-agent-home", ok: true, detail: dirs.join(", ") };
|
|
517
583
|
}
|
|
518
584
|
function runTeardown(options = {}) {
|
|
519
585
|
const steps = [];
|
|
@@ -640,10 +706,17 @@ function checkHookNodePaths(agent) {
|
|
|
640
706
|
nodePaths.add(h.command);
|
|
641
707
|
} else {
|
|
642
708
|
const cmd = h.command;
|
|
643
|
-
|
|
644
|
-
if (
|
|
645
|
-
|
|
709
|
+
let nodePath;
|
|
710
|
+
if (cmd.startsWith('"')) {
|
|
711
|
+
const closeQuote = cmd.indexOf('"', 1);
|
|
712
|
+
if (closeQuote > 1) nodePath = cmd.slice(1, closeQuote);
|
|
713
|
+
} else {
|
|
714
|
+
const parts = cmd.split(" ");
|
|
715
|
+
if (parts.length >= 2 && !parts[0].endsWith(".js") && !parts[0].endsWith(".ts")) {
|
|
716
|
+
nodePath = parts[0];
|
|
717
|
+
}
|
|
646
718
|
}
|
|
719
|
+
if (nodePath) nodePaths.add(nodePath);
|
|
647
720
|
}
|
|
648
721
|
}
|
|
649
722
|
}
|
|
@@ -670,14 +743,18 @@ function checkHookNodePaths(agent) {
|
|
|
670
743
|
return { installed: true, nodePaths: paths, nodeOk: true, detail: `${paths[0]} (${goodVersion})` };
|
|
671
744
|
}
|
|
672
745
|
var SETTINGS_BACKUP_KEEP = 5;
|
|
673
|
-
function
|
|
674
|
-
|
|
675
|
-
if (!path || !existsSync(path)) return;
|
|
746
|
+
function backupSettingsFile(path) {
|
|
747
|
+
if (!existsSync(path)) return;
|
|
676
748
|
const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[-:T.]/g, "").replace(/Z$/, "");
|
|
677
749
|
const bak = `${path}.bak-ctxdb-${ts}`;
|
|
678
750
|
copyFileSync(path, bak);
|
|
679
751
|
rotateBackups(`${path}.bak-ctxdb-`, SETTINGS_BACKUP_KEEP);
|
|
680
752
|
}
|
|
753
|
+
function backupSettingsJson(agent) {
|
|
754
|
+
const path = hookConfigPath(agent);
|
|
755
|
+
if (!path) return;
|
|
756
|
+
backupSettingsFile(path);
|
|
757
|
+
}
|
|
681
758
|
function rotateBackups(prefix, keep) {
|
|
682
759
|
const dir = dirname(prefix);
|
|
683
760
|
const baseName = prefix.slice(dir.length + 1);
|
|
@@ -713,9 +790,8 @@ function rotateBackups(prefix, keep) {
|
|
|
713
790
|
}
|
|
714
791
|
}
|
|
715
792
|
}
|
|
716
|
-
function
|
|
717
|
-
|
|
718
|
-
if (!path || !existsSync(path)) return 0;
|
|
793
|
+
function stripCtxdbHooksFromFile(path) {
|
|
794
|
+
if (!existsSync(path)) return 0;
|
|
719
795
|
let data;
|
|
720
796
|
try {
|
|
721
797
|
data = JSON.parse(readFileSync(path, "utf-8"));
|
|
@@ -736,6 +812,11 @@ function stripCtxdbHooks(agent) {
|
|
|
736
812
|
writeFileSync(path, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
737
813
|
return removed;
|
|
738
814
|
}
|
|
815
|
+
function stripCtxdbHooks(agent) {
|
|
816
|
+
const path = hookConfigPath(agent);
|
|
817
|
+
if (!path) return 0;
|
|
818
|
+
return stripCtxdbHooksFromFile(path);
|
|
819
|
+
}
|
|
739
820
|
function locateHookPaths() {
|
|
740
821
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
741
822
|
const pkgRoot = walkUpToPackageJson(here, "@aliyunrds/ctxdb");
|
|
@@ -819,6 +900,7 @@ function copySkillDir(src, dest, agent) {
|
|
|
819
900
|
var SKILL_INSTALL_TARGETS = {
|
|
820
901
|
qoder: join(homedir(), ".qoder", "skills"),
|
|
821
902
|
qoderwork: join(homedir(), ".qoderwork", "skills"),
|
|
903
|
+
qoderworkcn: join(homedir(), ".qoderworkcn", "skills"),
|
|
822
904
|
codex: join(homedir(), ".codex", "skills"),
|
|
823
905
|
claude: join(homedir(), ".claude", "skills"),
|
|
824
906
|
openclaw: join(homedir(), ".openclaw", "skills"),
|
|
@@ -855,9 +937,7 @@ function installSkillsTo(targetRoot, agent = "default") {
|
|
|
855
937
|
}
|
|
856
938
|
return { ok: true, steps };
|
|
857
939
|
}
|
|
858
|
-
function
|
|
859
|
-
const path = hookConfigPath(agent);
|
|
860
|
-
if (!path) return;
|
|
940
|
+
function appendHooksToFile(path, agent, hookPaths) {
|
|
861
941
|
let data = {};
|
|
862
942
|
if (existsSync(path)) {
|
|
863
943
|
try {
|
|
@@ -873,6 +953,11 @@ function appendHooks(agent, hookPaths) {
|
|
|
873
953
|
mkdirSync(dirname(path), { recursive: true });
|
|
874
954
|
writeFileSync(path, JSON.stringify(data, null, 2) + "\n", "utf-8");
|
|
875
955
|
}
|
|
956
|
+
function appendHooks(agent, hookPaths) {
|
|
957
|
+
const path = hookConfigPath(agent);
|
|
958
|
+
if (!path) return;
|
|
959
|
+
appendHooksToFile(path, agent, hookPaths);
|
|
960
|
+
}
|
|
876
961
|
var ENTRY_MARKER_KEY = "_ctxdb";
|
|
877
962
|
var ENTRY_MARKER_VALUE = "@aliyunrds/ctxdb";
|
|
878
963
|
var ENTRY_AGENT_KEY = "_ctxdbAgent";
|
|
@@ -882,7 +967,7 @@ var TOOL_SCOPED_EVENTS = /* @__PURE__ */ new Set(["PreToolUse", "PostToolUse"]);
|
|
|
882
967
|
function appendOne(hooks, event, command, agent) {
|
|
883
968
|
if (!Array.isArray(hooks[event])) hooks[event] = [];
|
|
884
969
|
const useExecForm = agent === "claude";
|
|
885
|
-
const shellCmd = `${process.execPath} ${command} --agent=${agent}`;
|
|
970
|
+
const shellCmd = process.platform === "win32" ? `"${process.execPath.replace(/\\/g, "/")}" "${command.replace(/\\/g, "/")}" --agent=${agent}` : `${process.execPath} ${command} --agent=${agent}`;
|
|
886
971
|
const dup = hooks[event].some(
|
|
887
972
|
(entry2) => Array.isArray(entry2?.hooks) && entry2.hooks.some(
|
|
888
973
|
(h) => h?.type === "command" && (Array.isArray(h.args) && h.args[0] === command || typeof h.command === "string" && h.command.includes(command))
|
|
@@ -1193,6 +1278,27 @@ function upgradeOneAgent(agent) {
|
|
|
1193
1278
|
if (agent === "codex") {
|
|
1194
1279
|
steps.push(enableCodexHooksFeature());
|
|
1195
1280
|
}
|
|
1281
|
+
const primaryHome = agentHomeDir(agent);
|
|
1282
|
+
const variantHomes = agentHomeDirs(agent).filter((d) => d !== primaryHome && existsSync(d));
|
|
1283
|
+
for (const vHome of variantHomes) {
|
|
1284
|
+
const tag = vHome.split("/").pop() ?? vHome;
|
|
1285
|
+
const vSkillRoot = join(vHome, "skills");
|
|
1286
|
+
const vr = installSkillsTo(vSkillRoot, agent);
|
|
1287
|
+
steps.push(...vr.steps.map((s) => ({ ...s, step: `${tag}:${s.step}` })));
|
|
1288
|
+
try {
|
|
1289
|
+
const vPath = join(vHome, "settings.json");
|
|
1290
|
+
backupSettingsFile(vPath);
|
|
1291
|
+
const vRemoved = stripCtxdbHooksFromFile(vPath);
|
|
1292
|
+
appendHooksToFile(vPath, agent, hookPaths);
|
|
1293
|
+
steps.push({
|
|
1294
|
+
step: `${tag}:refresh-hooks`,
|
|
1295
|
+
ok: true,
|
|
1296
|
+
detail: vRemoved > 0 ? `replaced ${vRemoved} stale` : void 0
|
|
1297
|
+
});
|
|
1298
|
+
} catch (err) {
|
|
1299
|
+
steps.push({ step: `${tag}:refresh-hooks`, ok: false, detail: err?.message ?? String(err) });
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1196
1302
|
}
|
|
1197
1303
|
return { ok: steps.every((s) => s.ok), steps };
|
|
1198
1304
|
}
|
|
@@ -1385,7 +1491,7 @@ var PACKAGE_NAME = "@aliyunrds/ctxdb";
|
|
|
1385
1491
|
var NPM_VIEW_TIMEOUT_MS = 1e4;
|
|
1386
1492
|
function detectInstallMethod() {
|
|
1387
1493
|
const dir = dirname2(fileURLToPath2(import.meta.url));
|
|
1388
|
-
return dir.includes("/node_modules/") ? "npm" : "unknown";
|
|
1494
|
+
return dir.includes("/node_modules/") || dir.includes("\\node_modules\\") ? "npm" : "unknown";
|
|
1389
1495
|
}
|
|
1390
1496
|
function checkLatestVersion(currentVersion) {
|
|
1391
1497
|
const result = spawnSync("npm", ["view", PACKAGE_NAME, "version"], {
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import {
|
|
3
3
|
fetchKbCatalogBlock,
|
|
4
4
|
recallTurn
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-ZIG7FIPN.js";
|
|
6
6
|
import "../chunk-6S5RJYBC.js";
|
|
7
7
|
import {
|
|
8
8
|
isCircuitOpen
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-WBFP2KGQ.js";
|
|
10
10
|
import {
|
|
11
11
|
HttpClient,
|
|
12
12
|
agentFromArgvWithFallback,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
isComplete,
|
|
15
15
|
load,
|
|
16
16
|
setDebug
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-R6TLOWVZ.js";
|
|
18
18
|
|
|
19
19
|
// src/hooks/session-start.ts
|
|
20
20
|
import { pathToFileURL } from "url";
|
package/dist/hooks/stop.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
isConnectionError,
|
|
5
5
|
resetCircuit,
|
|
6
6
|
tripCircuit
|
|
7
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-WBFP2KGQ.js";
|
|
8
8
|
import {
|
|
9
9
|
CtxdbError,
|
|
10
10
|
HttpClient,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
isDebug,
|
|
14
14
|
load,
|
|
15
15
|
setDebug
|
|
16
|
-
} from "../chunk-
|
|
16
|
+
} from "../chunk-R6TLOWVZ.js";
|
|
17
17
|
|
|
18
18
|
// src/lib/capture-orchestrator.ts
|
|
19
19
|
import {
|
|
@@ -337,6 +337,11 @@ async function captureTurn(transcriptPath, cfg, client, agent = "default") {
|
|
|
337
337
|
if (!turn.some((m) => m.role === "user")) {
|
|
338
338
|
return { captured: false, reason: "no_user_in_turn", messageCount: 0 };
|
|
339
339
|
}
|
|
340
|
+
const AUTOMATED_REVIEW_PREFIX = "[SYSTEM: This is an automated background review task. It is NOT a user message.";
|
|
341
|
+
const userMsgs = turn.filter((m) => m.role === "user");
|
|
342
|
+
if (userMsgs.every((m) => m.content.startsWith(AUTOMATED_REVIEW_PREFIX))) {
|
|
343
|
+
return { captured: false, reason: "automated_review_skip", messageCount: 0 };
|
|
344
|
+
}
|
|
340
345
|
const turnRows = selectTurnRows(rows);
|
|
341
346
|
if (dbg) debug("capture", "current turn rows", summarizeTranscriptRows(turnRows));
|
|
342
347
|
const kb = isKnowledgeBaseUploadTurn(toKbDetectionMessages(turnRows));
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
import {
|
|
3
3
|
fetchKbCatalogBlock,
|
|
4
4
|
recallTurn
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-ZIG7FIPN.js";
|
|
6
6
|
import "../chunk-6S5RJYBC.js";
|
|
7
7
|
import {
|
|
8
8
|
isCircuitOpen
|
|
9
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-WBFP2KGQ.js";
|
|
10
10
|
import {
|
|
11
11
|
HttpClient,
|
|
12
12
|
agentFromArgvWithFallback,
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
isComplete,
|
|
15
15
|
load,
|
|
16
16
|
setDebug
|
|
17
|
-
} from "../chunk-
|
|
17
|
+
} from "../chunk-R6TLOWVZ.js";
|
|
18
18
|
|
|
19
19
|
// src/hooks/user-prompt-submit.ts
|
|
20
20
|
import { pathToFileURL } from "url";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aliyunrds/ctxdb",
|
|
3
|
-
"version": "0.0.8-beta.
|
|
3
|
+
"version": "0.0.8-beta.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Unified access layer for RDS ContextDatabase: `ctxdb` CLI (memory + KB ops), one-shot `setup --agent <qoder|codex|claude>` installer, per-agent config, hooks, and SKILL.md.",
|
|
6
6
|
"license": "Apache-2.0",
|