@aliyunrds/ctxdb 1.0.7 → 1.0.8-beta.0

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.
@@ -1,4 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ DISTRIBUTION_MANIFEST
4
+ } from "./chunk-R67JELM7.js";
2
5
 
3
6
  // src/lib/logger.ts
4
7
  import { appendFileSync, mkdirSync } from "fs";
@@ -43,21 +46,27 @@ ${s}`;
43
46
  import { readFileSync } from "fs";
44
47
  import { dirname as dirname2, join as join2 } from "path";
45
48
  import { fileURLToPath } from "url";
46
- function findPackageVersion() {
49
+ var PACKAGE_NAMES = /* @__PURE__ */ new Set([
50
+ "@aliyunrds/ctxdb",
51
+ "@ali/ctxdb-internal"
52
+ ]);
53
+ function findPackageIdentity() {
47
54
  let dir = dirname2(fileURLToPath(import.meta.url));
48
55
  for (let i = 0; i < 5; i++) {
49
56
  try {
50
57
  const pkg = JSON.parse(readFileSync(join2(dir, "package.json"), "utf-8"));
51
- if (pkg.name === "@aliyunrds/ctxdb" && typeof pkg.version === "string") {
52
- return pkg.version;
58
+ if (PACKAGE_NAMES.has(pkg.name) && typeof pkg.version === "string") {
59
+ return { name: pkg.name, version: pkg.version };
53
60
  }
54
61
  } catch {
55
62
  }
56
63
  dir = dirname2(dir);
57
64
  }
58
- return "0.0.0";
65
+ return { name: "@aliyunrds/ctxdb", version: "0.0.0" };
59
66
  }
60
- var PACKAGE_VERSION = findPackageVersion();
67
+ var PACKAGE_IDENTITY = findPackageIdentity();
68
+ var PACKAGE_NAME = PACKAGE_IDENTITY.name;
69
+ var PACKAGE_VERSION = PACKAGE_IDENTITY.version;
61
70
 
62
71
  // src/lib/http-client.ts
63
72
  var DEFAULT_TIMEOUT_MS = 3e4;
@@ -143,18 +152,23 @@ var HttpClient = class {
143
152
  userAgent;
144
153
  extraHeaders;
145
154
  fetchImpl;
155
+ authorizationProvider;
146
156
  constructor(opts) {
147
157
  this.baseUrl = opts.baseUrl.replace(/\/+$/, "");
148
- this.apiKey = opts.apiKey;
158
+ if (!opts.apiKey && !opts.authorizationProvider) {
159
+ throw new Error("HttpClient requires apiKey or authorizationProvider");
160
+ }
161
+ this.apiKey = opts.apiKey ?? "";
162
+ this.authorizationProvider = opts.authorizationProvider;
149
163
  this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
150
164
  this.userAgent = opts.userAgent ?? `ctxdb-cli/${PACKAGE_VERSION}`;
151
165
  this.extraHeaders = { ...opts.extraHeaders ?? {} };
152
166
  const f = opts.fetchImpl ?? globalThis.fetch.bind(globalThis);
153
167
  this.fetchImpl = f;
154
168
  }
155
- buildHeaders(contentType, requestHeaders = {}) {
169
+ async buildHeaders(authorization, contentType, requestHeaders = {}) {
156
170
  const h = {
157
- Authorization: `Token ${this.apiKey}`,
171
+ Authorization: `${authorization.scheme} ${authorization.value}`,
158
172
  "User-Agent": this.userAgent,
159
173
  Connection: "close",
160
174
  ...this.extraHeaders,
@@ -164,7 +178,13 @@ var HttpClient = class {
164
178
  return h;
165
179
  }
166
180
  async doRequest(method, path, init = {}) {
167
- let url = `${this.baseUrl}${path}`;
181
+ const authorization = this.authorizationProvider ? await this.authorizationProvider.resolve() : {
182
+ scheme: "Token",
183
+ value: this.apiKey,
184
+ baseUrl: this.baseUrl,
185
+ expiresAt: null
186
+ };
187
+ let url = `${authorization.baseUrl.replace(/\/+$/, "")}${path}`;
168
188
  if (init.params) {
169
189
  const qs = new URLSearchParams();
170
190
  for (const [k, v] of Object.entries(init.params)) {
@@ -187,7 +207,11 @@ var HttpClient = class {
187
207
  try {
188
208
  resp = await this.fetchImpl(url, {
189
209
  method,
190
- headers: this.buildHeaders(init.contentType, init.headers),
210
+ headers: await this.buildHeaders(
211
+ authorization,
212
+ init.contentType,
213
+ init.headers
214
+ ),
191
215
  body: init.body,
192
216
  signal: controller.signal
193
217
  });
@@ -257,9 +281,33 @@ var HttpClient = class {
257
281
  headers: options.headers
258
282
  });
259
283
  }
284
+ patchJson(path, body, params, options = {}) {
285
+ return this.doRequest("PATCH", path, {
286
+ body: JSON.stringify(body),
287
+ contentType: "application/json",
288
+ params,
289
+ timeoutMs: options.timeoutMs,
290
+ headers: options.headers
291
+ });
292
+ }
260
293
  delete(path, params) {
261
294
  return this.doRequest("DELETE", path, { params });
262
295
  }
296
+ /**
297
+ * DELETE with a JSON body. ContextDB batch deletes use the
298
+ * `DELETE /v1/{resource}/batch` shape with an `{"ids": [...]}` body
299
+ * (server contract) — the plain `delete()` above only supports query
300
+ * params.
301
+ */
302
+ deleteJson(path, body, params, options = {}) {
303
+ return this.doRequest("DELETE", path, {
304
+ body: JSON.stringify(body),
305
+ contentType: "application/json",
306
+ params,
307
+ timeoutMs: options.timeoutMs,
308
+ headers: options.headers
309
+ });
310
+ }
263
311
  /**
264
312
  * POST multipart/form-data using runtime-native FormData.
265
313
  *
@@ -343,7 +391,7 @@ function parseErrorResponse(text, fallback) {
343
391
  import { homedir as homedir2 } from "os";
344
392
  import { delimiter, join as join3, sep } from "path";
345
393
  import { accessSync, constants, existsSync, statSync } from "fs";
346
- var SUPPORTED_AGENTS = ["qoder", "qoderwork", "qwenwork", "codex", "claude", "opencode", "hermes"];
394
+ var SUPPORTED_AGENTS = ["qoder", "qoderwork", "qwenwork", "codex", "claude", "opencode", "hermes", "workbuddy"];
347
395
  function isBuiltinAgent(v) {
348
396
  return typeof v === "string" && SUPPORTED_AGENTS.includes(v);
349
397
  }
@@ -367,6 +415,8 @@ function agentHomeDir(agent, home = homedir2()) {
367
415
  return join3(home, ".config", "opencode");
368
416
  case "hermes":
369
417
  return join3(home, ".hermes");
418
+ case "workbuddy":
419
+ return join3(home, ".workbuddy");
370
420
  }
371
421
  }
372
422
  var AGENT_VARIANT_HOMES = {
@@ -518,9 +568,9 @@ function agentFromArgvWithFallback(argv = process.argv.slice(2), env = process.e
518
568
  }
519
569
 
520
570
  // src/lib/config.ts
521
- import { readFileSync as readFileSync2, existsSync as existsSync3, unlinkSync as unlinkSync2 } from "fs";
522
- import { homedir as homedir3 } from "os";
523
- import { join as join4 } from "path";
571
+ import { readFileSync as readFileSync3, existsSync as existsSync4, unlinkSync as unlinkSync3 } from "fs";
572
+ import { homedir as homedir4 } from "os";
573
+ import { dirname as dirname5, join as join5 } from "path";
524
574
 
525
575
  // src/lib/secure-file.ts
526
576
  import {
@@ -621,16 +671,142 @@ function secureAtomicWrite(target, content, options = {}) {
621
671
  import { createHmac, randomBytes as randomBytes2 } from "crypto";
622
672
  var PROCESS_FINGERPRINT_KEY = randomBytes2(32);
623
673
 
674
+ // src/credentials/local-credential-provider.ts
675
+ import {
676
+ closeSync as closeSync2,
677
+ existsSync as existsSync3,
678
+ mkdirSync as mkdirSync3,
679
+ openSync as openSync2,
680
+ readFileSync as readFileSync2,
681
+ statSync as statSync2,
682
+ unlinkSync as unlinkSync2,
683
+ writeFileSync as writeFileSync2
684
+ } from "fs";
685
+ import { homedir as homedir3 } from "os";
686
+ import { dirname as dirname4, join as join4 } from "path";
687
+ import { setTimeout as delay } from "timers/promises";
688
+
689
+ // src/credentials/types.ts
690
+ var ACTIVE_CONTEXTDB_CREDENTIAL = "contextdb/active";
691
+
692
+ // src/credentials/local-credential-provider.ts
693
+ var DOCUMENT_VERSION = 1;
694
+ var STALE_LOCK_MS = 10 * 60 * 1e3;
695
+ function defaultCredentialsPath() {
696
+ return join4(homedir3(), ".ctxdb", "credentials.json");
697
+ }
698
+ function emptyDocument() {
699
+ return { version: DOCUMENT_VERSION, records: {} };
700
+ }
701
+ function normalizeOrigin(value, field) {
702
+ if (typeof value !== "string" || !value) {
703
+ throw new Error(`credentials: ${field} must be a non-empty URL`);
704
+ }
705
+ let url;
706
+ try {
707
+ url = new URL(value);
708
+ } catch {
709
+ throw new Error(`credentials: ${field} must be a valid URL`);
710
+ }
711
+ if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) {
712
+ throw new Error(`credentials: ${field} must be an HTTP(S) origin`);
713
+ }
714
+ return url.toString().replace(/\/$/, "");
715
+ }
716
+ function parseRecord(value) {
717
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
718
+ throw new Error("credentials: record must be an object");
719
+ }
720
+ const raw = value;
721
+ if (raw.kind !== "api-key") {
722
+ throw new Error(`credentials: unsupported record kind ${String(raw.kind)}`);
723
+ }
724
+ const payload = raw.payload;
725
+ const metadata = raw.metadata;
726
+ if (!payload || typeof payload !== "object" || Array.isArray(payload)) {
727
+ throw new Error("credentials: api-key payload must be an object");
728
+ }
729
+ if (!metadata || typeof metadata !== "object" || Array.isArray(metadata)) {
730
+ throw new Error("credentials: api-key metadata must be an object");
731
+ }
732
+ const body = payload;
733
+ const meta = metadata;
734
+ if (typeof body.api_key !== "string" || !body.api_key) {
735
+ throw new Error("credentials: api_key must be a non-empty string");
736
+ }
737
+ if (meta.authorization_method !== "browser-loopback" && meta.authorization_method !== "device-code") {
738
+ throw new Error("credentials: authorization_method is invalid");
739
+ }
740
+ if (typeof meta.issued_at !== "string" || !Number.isFinite(Date.parse(meta.issued_at))) {
741
+ throw new Error("credentials: issued_at is invalid");
742
+ }
743
+ return {
744
+ kind: "api-key",
745
+ payload: {
746
+ apiKey: body.api_key,
747
+ baseUrl: normalizeOrigin(body.base_url, "base_url"),
748
+ loginServer: normalizeOrigin(body.login_server, "login_server")
749
+ },
750
+ metadata: {
751
+ authorizationMethod: meta.authorization_method,
752
+ issuedAt: meta.issued_at
753
+ }
754
+ };
755
+ }
756
+ function parseDocument(text) {
757
+ let raw;
758
+ try {
759
+ raw = JSON.parse(text);
760
+ } catch {
761
+ throw new Error("credentials: credentials.json is not valid JSON");
762
+ }
763
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
764
+ throw new Error("credentials: document must be an object");
765
+ }
766
+ const document = raw;
767
+ if (document.version !== DOCUMENT_VERSION) {
768
+ throw new Error(`credentials: unsupported document version ${String(document.version)}`);
769
+ }
770
+ if (!document.records || typeof document.records !== "object" || Array.isArray(document.records)) {
771
+ throw new Error("credentials: records must be an object");
772
+ }
773
+ const records = document.records;
774
+ const unknown = Object.keys(records).filter((key) => key !== ACTIVE_CONTEXTDB_CREDENTIAL);
775
+ if (unknown.length > 0) {
776
+ throw new Error(`credentials: unsupported record key ${unknown[0]}`);
777
+ }
778
+ const active = records[ACTIVE_CONTEXTDB_CREDENTIAL];
779
+ return {
780
+ version: DOCUMENT_VERSION,
781
+ records: active === void 0 ? {} : { [ACTIVE_CONTEXTDB_CREDENTIAL]: parseRecord(active) }
782
+ };
783
+ }
784
+ function assertOwnerOnly(path) {
785
+ if (process.platform === "win32" || !existsSync3(path)) return;
786
+ const mode = statSync2(path).mode & 511;
787
+ if ((mode & 63) !== 0) {
788
+ throw new Error(`credentials: ${path} must be owner-only (run chmod 600)`);
789
+ }
790
+ }
791
+ function readDocument(path) {
792
+ if (!existsSync3(path)) return emptyDocument();
793
+ assertOwnerOnly(path);
794
+ return parseDocument(readFileSync2(path, "utf8"));
795
+ }
796
+ function readActiveCredentialSync(path = defaultCredentialsPath()) {
797
+ return readDocument(path).records[ACTIVE_CONTEXTDB_CREDENTIAL];
798
+ }
799
+
624
800
  // src/lib/config.ts
625
801
  import {
626
802
  resolveDebugPolicy
627
803
  } from "@aliyunrds/ctxdb-shared";
628
804
  function defaultConfigPath() {
629
- return join4(homedir3(), ".ctxdb", "ctxdb.json");
805
+ return join5(homedir4(), ".ctxdb", "ctxdb.json");
630
806
  }
631
- var DEFAULT_CONFIG_PATH = join4(homedir3(), ".ctxdb", "ctxdb.json");
807
+ var DEFAULT_CONFIG_PATH = join5(homedir4(), ".ctxdb", "ctxdb.json");
632
808
  function configDir() {
633
- return join4(homedir3(), ".ctxdb");
809
+ return join5(homedir4(), ".ctxdb");
634
810
  }
635
811
  var DEFAULT_BASE_URL = "https://context-database.aliyuncs.com";
636
812
  var DEFAULT_USER_ID = "default";
@@ -667,9 +843,9 @@ function coerceKbCatalogInjection(v) {
667
843
  return DEFAULT_KB_CATALOG_INJECTION;
668
844
  }
669
845
  function readRaw(path) {
670
- if (!existsSync3(path)) return {};
846
+ if (!existsSync4(path)) return {};
671
847
  try {
672
- const parsed = JSON.parse(readFileSync2(path, "utf-8"));
848
+ const parsed = JSON.parse(readFileSync3(path, "utf-8"));
673
849
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
674
850
  return parsed;
675
851
  }
@@ -742,7 +918,15 @@ function load(options = {}) {
742
918
  );
743
919
  } catch {
744
920
  }
745
- return applyEnv(configFromDisk({}), env);
921
+ const cfg2 = configFromDisk({});
922
+ const managed2 = !DISTRIBUTION_MANIFEST.capabilities.managedCredentials || options.managedCredentials === false ? void 0 : readActiveCredentialSync(
923
+ options.credentialsPath ?? join5(dirname5(path), "credentials.json")
924
+ );
925
+ if (managed2) {
926
+ cfg2.apiKey = managed2.payload.apiKey;
927
+ cfg2.baseUrl = managed2.payload.baseUrl;
928
+ }
929
+ return applyEnv(cfg2, env);
746
930
  }
747
931
  const agentRaw = agentRawFromFile(raw, agent);
748
932
  if (agent !== "default") {
@@ -755,7 +939,15 @@ function load(options = {}) {
755
939
  }
756
940
  }
757
941
  }
758
- return applyEnv(configFromDisk(agentRaw), env);
942
+ const cfg = configFromDisk(agentRaw);
943
+ const managed = !DISTRIBUTION_MANIFEST.capabilities.managedCredentials || options.managedCredentials === false ? void 0 : readActiveCredentialSync(
944
+ options.credentialsPath ?? join5(dirname5(path), "credentials.json")
945
+ );
946
+ if (managed) {
947
+ cfg.apiKey = managed.payload.apiKey;
948
+ cfg.baseUrl = managed.payload.baseUrl;
949
+ }
950
+ return applyEnv(cfg, env);
759
951
  }
760
952
  function configToDisk(cfg) {
761
953
  return {
@@ -777,7 +969,7 @@ function configToDisk(cfg) {
777
969
  }
778
970
  function removeAgent(agent, path, options = {}) {
779
971
  const target = path ?? defaultConfigPath();
780
- if (!existsSync3(target)) {
972
+ if (!existsSync4(target)) {
781
973
  return { removed: false, remainingAgents: [], fileDeleted: false };
782
974
  }
783
975
  const raw = readRaw(target);
@@ -796,7 +988,7 @@ function removeAgent(agent, path, options = {}) {
796
988
  const remaining = Object.keys(agents);
797
989
  if (remaining.length === 0 && !options.keepEmptyShell) {
798
990
  try {
799
- unlinkSync2(target);
991
+ unlinkSync3(target);
800
992
  return { removed: true, remainingAgents: [], fileDeleted: true };
801
993
  } catch {
802
994
  }
@@ -812,12 +1004,14 @@ function save(cfg, path, options = {}) {
812
1004
  const raw = readRaw(target);
813
1005
  const validRaw = isV2Schema(raw) ? raw : {};
814
1006
  const existingAgents = validRaw.agents && typeof validRaw.agents === "object" && !Array.isArray(validRaw.agents) ? { ...validRaw.agents } : {};
1007
+ const serialized = configToDisk(cfg);
1008
+ if (options.omitApiKey) delete serialized.api_key;
815
1009
  const onDisk = {
816
1010
  ...validRaw,
817
1011
  version: 2,
818
1012
  agents: {
819
1013
  ...existingAgents,
820
- [agent]: configToDisk(cfg)
1014
+ [agent]: serialized
821
1015
  }
822
1016
  };
823
1017
  delete onDisk.default_agent;
@@ -868,6 +1062,7 @@ export {
868
1062
  setDebug,
869
1063
  isDebug,
870
1064
  debug,
1065
+ PACKAGE_NAME,
871
1066
  PACKAGE_VERSION,
872
1067
  CtxdbError,
873
1068
  HttpClient,
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  fetchKbCatalogBlock,
4
4
  recallTurn
5
- } from "./chunk-DPLMBHLU.js";
5
+ } from "./chunk-WSMZOFZQ.js";
6
6
 
7
7
  // src/lib/user-prompt-submit-compose.ts
8
8
  async function composeUserPromptSubmit(cfg, agent, client, prompt, sessionId = null) {
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  CtxdbError
4
- } from "./chunk-S5W4FQ7M.js";
4
+ } from "./chunk-AAZLOCVB.js";
5
5
 
6
6
  // src/lib/kb.ts
7
7
  import {
@@ -4,12 +4,12 @@ import {
4
4
  isConnectionError,
5
5
  resetCircuit,
6
6
  tripCircuit
7
- } from "./chunk-X2BX6LR6.js";
7
+ } from "./chunk-NJJBT52C.js";
8
8
  import {
9
9
  CtxdbError,
10
10
  debug,
11
11
  isDebug
12
- } from "./chunk-S5W4FQ7M.js";
12
+ } from "./chunk-AAZLOCVB.js";
13
13
 
14
14
  // src/lib/capture-orchestrator.ts
15
15
  import {
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  configDir
4
- } from "./chunk-S5W4FQ7M.js";
4
+ } from "./chunk-AAZLOCVB.js";
5
5
 
6
6
  // src/lib/circuit.ts
7
7
  import { statSync, writeFileSync, unlinkSync, mkdirSync, readdirSync, readFileSync } from "fs";
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ define_CTXDB_DISTRIBUTION_MANIFEST_default
4
+ } from "./chunk-VIG4SYLU.js";
5
+
6
+ // src/lib/distribution-capabilities.ts
7
+ var PUBLIC_DISTRIBUTION = {
8
+ id: "public",
9
+ packageName: "@aliyunrds/ctxdb",
10
+ packageRegistry: null,
11
+ capabilities: {
12
+ interactiveLogin: false,
13
+ managedCredentials: false
14
+ }
15
+ };
16
+ var DISTRIBUTION_MANIFEST = typeof define_CTXDB_DISTRIBUTION_MANIFEST_default === "undefined" ? PUBLIC_DISTRIBUTION : define_CTXDB_DISTRIBUTION_MANIFEST_default;
17
+
18
+ export {
19
+ DISTRIBUTION_MANIFEST
20
+ };
@@ -1,11 +1,13 @@
1
1
  #!/usr/bin/env node
2
+ import {
3
+ DISTRIBUTION_MANIFEST
4
+ } from "./chunk-R67JELM7.js";
2
5
 
3
6
  // src/lib/self-update.ts
4
7
  import { spawnSync } from "child_process";
5
8
  import { fileURLToPath } from "url";
6
9
  import { dirname } from "path";
7
10
  import semver from "semver";
8
- var PACKAGE_NAME = "@aliyunrds/ctxdb";
9
11
  var NPM_VIEW_TIMEOUT_MS = 1e4;
10
12
  function npmCommand(platform = process.platform) {
11
13
  return platform === "win32" ? "npm.cmd" : "npm";
@@ -17,6 +19,9 @@ function detectInstallMethod() {
17
19
  const dir = dirname(fileURLToPath(import.meta.url));
18
20
  return dir.includes("/node_modules/") || dir.includes("\\node_modules\\") ? "npm" : "unknown";
19
21
  }
22
+ function registryArgs(registry) {
23
+ return registry ? ["--registry", registry] : [];
24
+ }
20
25
  function checkLatestVersion(currentVersion, options = {}) {
21
26
  const current = semver.valid(currentVersion);
22
27
  if (!current) {
@@ -29,12 +34,18 @@ function checkLatestVersion(currentVersion, options = {}) {
29
34
  }
30
35
  const platform = options.platform ?? process.platform;
31
36
  const run = options.spawnSyncFn ?? spawnSync;
32
- const result = run(npmCommand(platform), ["view", PACKAGE_NAME, "version"], {
33
- encoding: "utf-8",
34
- timeout: options.timeoutMs ?? NPM_VIEW_TIMEOUT_MS,
35
- stdio: ["ignore", "pipe", "pipe"],
36
- shell: platform === "win32"
37
- });
37
+ const packageName = options.packageName ?? DISTRIBUTION_MANIFEST.packageName;
38
+ const registry = options.registry === void 0 ? DISTRIBUTION_MANIFEST.packageRegistry : options.registry;
39
+ const result = run(
40
+ npmCommand(platform),
41
+ ["view", packageName, "version", ...registryArgs(registry)],
42
+ {
43
+ encoding: "utf-8",
44
+ timeout: options.timeoutMs ?? NPM_VIEW_TIMEOUT_MS,
45
+ stdio: ["ignore", "pipe", "pipe"],
46
+ shell: platform === "win32"
47
+ }
48
+ );
38
49
  if (result.status !== 0 || !result.stdout?.trim()) {
39
50
  return {
40
51
  latest: null,
@@ -82,7 +93,9 @@ function runSelfUpdate(currentVersion, passthroughArgs = [], options = {}) {
82
93
  error: "ctxdb was not installed via npm. Update manually with your package manager."
83
94
  };
84
95
  }
85
- const check = checkLatestVersion(currentVersion);
96
+ const packageName = options.packageName ?? DISTRIBUTION_MANIFEST.packageName;
97
+ const registry = options.registry === void 0 ? DISTRIBUTION_MANIFEST.packageRegistry : options.registry;
98
+ const check = checkLatestVersion(currentVersion, { packageName, registry });
86
99
  if (check.error) {
87
100
  return {
88
101
  ok: false,
@@ -98,13 +111,17 @@ function runSelfUpdate(currentVersion, passthroughArgs = [], options = {}) {
98
111
  );
99
112
  return { ok: true, updated: false, fromVersion: currentVersion };
100
113
  }
101
- process.stderr.write(`ctxdb: updating ${PACKAGE_NAME} v${currentVersion} \u2192 v${check.latest}...
114
+ process.stderr.write(`ctxdb: updating ${packageName} v${currentVersion} \u2192 v${check.latest}...
102
115
  `);
103
- const install = spawnSync(npmCommand(), ["install", "-g", `${PACKAGE_NAME}@${check.latest}`], {
104
- stdio: "inherit",
105
- encoding: "utf-8",
106
- shell: process.platform === "win32"
107
- });
116
+ const install = spawnSync(
117
+ npmCommand(),
118
+ ["install", "-g", `${packageName}@${check.latest}`, ...registryArgs(registry)],
119
+ {
120
+ stdio: "inherit",
121
+ encoding: "utf-8",
122
+ shell: process.platform === "win32"
123
+ }
124
+ );
108
125
  if (install.status !== 0) {
109
126
  return {
110
127
  ok: false,
@@ -153,10 +170,11 @@ var NOTIFICATION_THROTTLE_MS = 3 * SUCCESS_TTL_MS;
153
170
  var LOCK_STALE_AFTER_MS = 10 * 60 * 1e3;
154
171
  function versionCheckPaths(home = homedir()) {
155
172
  const cacheDir = join(home, ".ctxdb", "cache");
173
+ const distributionSuffix = DISTRIBUTION_MANIFEST.id === "public" ? "" : `-${DISTRIBUTION_MANIFEST.id}`;
156
174
  return {
157
175
  cacheDir,
158
- statePath: join(cacheDir, "version-check.json"),
159
- lockPath: join(cacheDir, "version-check.lock")
176
+ statePath: join(cacheDir, `version-check${distributionSuffix}.json`),
177
+ lockPath: join(cacheDir, `version-check${distributionSuffix}.lock`)
160
178
  };
161
179
  }
162
180
  function createInitialVersionCheckState(currentVersion) {
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+
3
+ // <define:__CTXDB_DISTRIBUTION_MANIFEST__>
4
+ var define_CTXDB_DISTRIBUTION_MANIFEST_default = { id: "public", packageName: "@aliyunrds/ctxdb", packageRegistry: null, capabilities: { interactiveLogin: false, managedCredentials: false } };
5
+
6
+ export {
7
+ define_CTXDB_DISTRIBUTION_MANIFEST_default
8
+ };
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  listKnowledgeBases
4
- } from "./chunk-QVXDI77N.js";
4
+ } from "./chunk-CAXRYH6E.js";
5
5
  import {
6
6
  isConnectionError,
7
7
  resetCircuit,
8
8
  tripCircuit
9
- } from "./chunk-X2BX6LR6.js";
9
+ } from "./chunk-NJJBT52C.js";
10
10
  import {
11
11
  CtxdbError
12
- } from "./chunk-S5W4FQ7M.js";
12
+ } from "./chunk-AAZLOCVB.js";
13
13
 
14
14
  // src/lib/kb-catalog.ts
15
15
  function sanitizeKeyEntities(raw) {