@ycodium-ai/agent-claude 0.2.5357 → 0.2.5374

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.
Files changed (2) hide show
  1. package/dist/index.js +280 -262
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import * as NodePath21 from "node:path";
3
3
  import { definePlugin } from "@ycodium-ai/plugin-api";
4
4
 
5
5
  // ../../packages/plugin-api/src/version.ts
6
- var PLUGIN_API_VERSION = 167;
6
+ var PLUGIN_API_VERSION = 169;
7
7
 
8
8
  // src/index.ts
9
9
  import {
@@ -24,7 +24,14 @@ var CLAUDE_CARD = {
24
24
  commandName: "claude",
25
25
  launchArgs: "",
26
26
  // Claude 的隔离走 CLAUDE_CONFIG_DIR,不注入 HOME(钥匙串查找跟着 HOME)。
27
- homeEnvVar: "",
27
+ homeEnvVar: "CLAUDE_CONFIG_DIR",
28
+ // 会话、配置、技能都在 CLAUDE_CONFIG_DIR;登录另由 CLAUDE_SECURESTORAGE_CONFIG_DIR 定位,
29
+ // 两个实例因此能共用会话目录、各登各的账号。
30
+ homeLayout: {
31
+ accountConfigKey: "credentialsPath",
32
+ transcriptSubdir: "projects",
33
+ accountEnvVar: "CLAUDE_SECURESTORAGE_CONFIG_DIR"
34
+ },
28
35
  // 设置表单里留空的格子此刻会用什么,见 index.ts 的同名命令。
29
36
  effectiveCommand: "effectiveConfig",
30
37
  // 写的是凭据目录(`credentialsPath`),不是共用工作目录:写错字段等于把两个账号的会话历史
@@ -34,6 +41,9 @@ var CLAUDE_CARD = {
34
41
  defaultDirectory: "~/.claude",
35
42
  brandAliases: ["claude-code"]
36
43
  },
44
+ // resume 优先于 sessionId:fork 过的会话只有 resume 能进去;顺序与 session-import 认原生会话的一致。
45
+ resumeCommand: { cursorKeys: ["resume", "sessionId"], command: "claude --resume {id}" },
46
+ repositoryInstructionsFile: "CLAUDE.md",
37
47
  environment: [],
38
48
  install: {
39
49
  kind: "vendorScript",
@@ -204,8 +214,253 @@ var CLAUDE_CARD = {
204
214
  }
205
215
  };
206
216
 
217
+ // src/claudeAccount.ts
218
+ import * as NodeOS3 from "node:os";
219
+ import * as NodePath3 from "node:path";
220
+
221
+ // ../../packages/ycodium-credential-account/src/credentialAccount.ts
222
+ import * as NodeFS from "node:fs";
223
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
224
+ var parseJsonRecord = (raw) => {
225
+ let parsed;
226
+ try {
227
+ parsed = JSON.parse(raw);
228
+ } catch {
229
+ return void 0;
230
+ }
231
+ return isRecord(parsed) ? parsed : void 0;
232
+ };
233
+ var directoryExists = (homePath) => {
234
+ try {
235
+ return NodeFS.statSync(homePath).isDirectory();
236
+ } catch {
237
+ return false;
238
+ }
239
+ };
240
+ var readCredentialFile = (path) => {
241
+ try {
242
+ return NodeFS.readFileSync(path, "utf8");
243
+ } catch {
244
+ return void 0;
245
+ }
246
+ };
247
+ var accountWithoutIdentity = (state, exists) => ({
248
+ state,
249
+ directoryExists: exists,
250
+ email: void 0,
251
+ name: void 0,
252
+ expiresAt: void 0
253
+ });
254
+ var epochMillisToIso = (value) => {
255
+ if (value === void 0 || !Number.isFinite(value)) return void 0;
256
+ const date = new Date(value);
257
+ return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
258
+ };
259
+
260
+ // ../../packages/ycodium-instance-config/src/homePath.ts
261
+ import * as NodeOS from "node:os";
262
+ import * as NodePath from "node:path";
263
+ import { mergeLaunchEnv } from "@ycodium-ai/plugin-api/executor";
264
+ function expandHomePath(value) {
265
+ if (value === "~") return NodeOS.homedir();
266
+ if (value.startsWith("~/") || value.startsWith("~\\")) {
267
+ return NodePath.join(NodeOS.homedir(), value.slice(2));
268
+ }
269
+ return value;
270
+ }
271
+
272
+ // src/claudeHome.ts
273
+ import * as NodeOS2 from "node:os";
274
+ import * as NodePath2 from "node:path";
275
+
276
+ // ../../packages/ycodium-duration-format/src/durationFormat.ts
277
+ function formatCoarseWait(waitMs) {
278
+ const totalMinutes = Math.max(1, Math.ceil(waitMs / 6e4));
279
+ const days = Math.floor(totalMinutes / (24 * 60));
280
+ const hours = Math.floor(totalMinutes % (24 * 60) / 60);
281
+ const minutes = totalMinutes % 60;
282
+ if (days > 0) return hours === 0 ? `${String(days)}d` : `${String(days)}d ${String(hours)}h`;
283
+ if (hours === 0) return `${String(totalMinutes)}m`;
284
+ return minutes === 0 ? `${String(hours)}h` : `${String(hours)}h ${String(minutes)}m`;
285
+ }
286
+
287
+ // src/usageLimit.ts
288
+ var WINDOW_NAMES = {
289
+ five_hour: "5-hour",
290
+ seven_day: "7-day",
291
+ seven_day_opus: "7-day Opus",
292
+ seven_day_sonnet: "7-day Sonnet",
293
+ overage: "overage"
294
+ };
295
+ var MAX_CREDIBLE_WAIT_MS = 30 * 24 * 60 * 60 * 1e3;
296
+ var isBlockingRateLimit = (info) => info.status === "rejected" && info.overageStatus !== "allowed" && info.overageStatus !== "allowed_warning" && info.isUsingOverage !== true && info.overageInUse !== true;
297
+ var isClearingRateLimit = (info) => info.status === "allowed" || info.status === "allowed_warning" || info.overageStatus === "allowed" || info.overageStatus === "allowed_warning" || info.isUsingOverage === true || info.overageInUse === true;
298
+ var rateLimitKey = (info) => `${info.rateLimitType ?? "unknown"}:${String(info.resetsAt ?? "unknown")}`;
299
+ var waitUntil = (resetsAtSeconds, nowMs) => {
300
+ if (resetsAtSeconds === void 0 || !Number.isFinite(nowMs)) return void 0;
301
+ const waitMs = resetsAtSeconds * 1e3 - nowMs;
302
+ return waitMs > 0 && waitMs <= MAX_CREDIBLE_WAIT_MS ? formatCoarseWait(waitMs) : void 0;
303
+ };
304
+ var describeUsageLimitPause = (info, nowMs) => {
305
+ const name = info.rateLimitType === void 0 ? void 0 : WINDOW_NAMES[info.rateLimitType];
306
+ const wait = waitUntil(info.resetsAt, nowMs);
307
+ return `Claude usage limit reached. This turn is paused until the ${name === void 0 ? "" : `${name} `}limit resets${wait === void 0 ? "" : ` in ${wait}`}.`;
308
+ };
309
+ var describeUsageLimitFailure = (rejected, nowMs) => {
310
+ let name;
311
+ let wait;
312
+ let latestResetSeconds = Number.NEGATIVE_INFINITY;
313
+ for (const [type4, resetsAt] of rejected) {
314
+ const label = WINDOW_NAMES[type4];
315
+ const reachable = waitUntil(resetsAt, nowMs);
316
+ if (label === void 0 || reachable === void 0 || resetsAt === void 0) continue;
317
+ if (resetsAt <= latestResetSeconds) continue;
318
+ latestResetSeconds = resetsAt;
319
+ name = label;
320
+ wait = reachable;
321
+ }
322
+ return name === void 0 ? "Claude usage limit reached. Send the message again once the limit resets." : `Claude usage limit reached. The ${name} limit resets in ${wait}. Send the message again once it resets.`;
323
+ };
324
+
325
+ // src/claudeHome.ts
326
+ var CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE = "CLAUDE_SECURESTORAGE_CONFIG_DIR";
327
+ function resolveClaudeHomePath(homePath) {
328
+ const trimmed = homePath.trim();
329
+ return NodePath2.resolve(trimmed.length > 0 ? expandHomePath(trimmed) : NodeOS2.homedir());
330
+ }
331
+ function claudeContinuationKey(homePath) {
332
+ return `claude:home:${resolveClaudeHomePath(homePath)}`;
333
+ }
334
+ function resolveClaudeConfigDirPath(homePath, environment, cwd) {
335
+ const trimmed = homePath.trim();
336
+ if (trimmed.length > 0) {
337
+ return NodePath2.resolve(expandHomePath(trimmed));
338
+ }
339
+ const environmentConfigDir = environment.CLAUDE_CONFIG_DIR?.trim() ?? "";
340
+ if (environmentConfigDir.length > 0) {
341
+ return cwd ? NodePath2.resolve(cwd, environmentConfigDir) : NodePath2.resolve(environmentConfigDir);
342
+ }
343
+ return NodePath2.join(NodeOS2.homedir(), ".claude");
344
+ }
345
+ function resolveClaudeCredentialsDirPath(credentialsPath) {
346
+ const trimmed = credentialsPath.trim();
347
+ if (trimmed.length === 0) return null;
348
+ return NodePath2.resolve(expandHomePath(trimmed));
349
+ }
350
+ function resolveClaudeHomeLayout(input) {
351
+ return {
352
+ configDirPath: input.homePath.trim().length > 0 ? resolveClaudeHomePath(input.homePath) : void 0,
353
+ credentialsDirPath: resolveClaudeCredentialsDirPath(input.credentialsPath) ?? void 0
354
+ };
355
+ }
356
+ function claudeHomeVariables(layout) {
357
+ return {
358
+ ...layout.configDirPath === void 0 ? {} : { CLAUDE_CONFIG_DIR: layout.configDirPath },
359
+ ...layout.credentialsDirPath === void 0 ? {} : { [CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE]: layout.credentialsDirPath }
360
+ };
361
+ }
362
+ function makeClaudeEnvironment(config, baseEnv) {
363
+ const resolvedBaseEnv = { ...baseEnv ?? process.env };
364
+ const variables = claudeHomeVariables(
365
+ resolveClaudeHomeLayout({
366
+ homePath: config.homePath,
367
+ credentialsPath: config.credentialsPath
368
+ })
369
+ );
370
+ if (Object.keys(variables).length === 0) return resolvedBaseEnv;
371
+ return { ...resolvedBaseEnv, ...variables };
372
+ }
373
+ var quoteLiteral = (value) => JSON.stringify(value);
374
+ function claudeSignedOutMessage(input) {
375
+ const variables = [];
376
+ const configDir = input.configDir?.trim() ?? "";
377
+ if (configDir.length > 0) {
378
+ variables.push(
379
+ `CLAUDE_CONFIG_DIR set to ${quoteLiteral(NodePath2.resolve(input.cwd, configDir))}`
380
+ );
381
+ }
382
+ const credentialsDir = input.credentialsDir?.trim() ?? "";
383
+ if (credentialsDir.length > 0) {
384
+ variables.push(
385
+ `${CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE} set to ${quoteLiteral(NodePath2.resolve(input.cwd, credentialsDir))}`
386
+ );
387
+ }
388
+ const withVariables = variables.length > 0 ? `, with ${variables.join(" and ")}` : "";
389
+ return `Claude could not authenticate. For subscription login, run \`claude auth login\` on this machine${withVariables}, then start a new thread. For API-key authentication, check this instance's configured credentials.`;
390
+ }
391
+ function claudeFailureHint(input) {
392
+ if (input.authenticationFailed) {
393
+ return {
394
+ category: "auth",
395
+ text: claudeSignedOutMessage({
396
+ configDir: input.environment.CLAUDE_CONFIG_DIR,
397
+ credentialsDir: input.environment[CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE],
398
+ cwd: input.cwd
399
+ })
400
+ };
401
+ }
402
+ const limit = input.usageLimit;
403
+ if (limit !== void 0 && (limit.rejected.size > 0 || limit.latestAssistantRateLimited)) {
404
+ return {
405
+ category: limit.rejected.size > 0 ? "quota" : "rate-limit",
406
+ text: describeUsageLimitFailure(limit.rejected, limit.nowMs)
407
+ };
408
+ }
409
+ return void 0;
410
+ }
411
+
412
+ // src/claudeAccount.ts
413
+ var OAUTH_KEY = "claudeAiOauth";
414
+ function resolveClaudeAccountDirectory(credentialsDirPath) {
415
+ return credentialsDirPath ?? NodePath3.join(NodeOS3.homedir(), ".claude");
416
+ }
417
+ function claudeCredentialCandidatePaths(input) {
418
+ return input.credentialsDirPath === null ? [
419
+ NodePath3.join(input.homePath, ".claude", ".credentials.json"),
420
+ NodePath3.join(input.homePath, ".credentials.json")
421
+ ] : [NodePath3.join(input.credentialsDirPath, ".credentials.json")];
422
+ }
423
+ function readClaudeAccount(credentialsDirPath, credentialCandidates) {
424
+ const accountDirectory = resolveClaudeAccountDirectory(credentialsDirPath);
425
+ const exists = directoryExists(accountDirectory);
426
+ const candidates = credentialCandidates ?? claudeCredentialCandidatePaths({
427
+ homePath: NodeOS3.homedir(),
428
+ credentialsDirPath
429
+ });
430
+ let raw;
431
+ for (const candidate of candidates) {
432
+ raw = readCredentialFile(candidate);
433
+ if (raw !== void 0) break;
434
+ }
435
+ if (raw === void 0) return accountWithoutIdentity("signed-out", exists);
436
+ const parsed = parseJsonRecord(raw);
437
+ const oauth = parsed === void 0 ? void 0 : parsed[OAUTH_KEY];
438
+ if (!isRecord(oauth) || typeof oauth["accessToken"] !== "string" || oauth["accessToken"].trim().length === 0) {
439
+ return accountWithoutIdentity("unreadable", exists);
440
+ }
441
+ const expiresAtMs = typeof oauth["expiresAt"] === "number" && Number.isFinite(oauth["expiresAt"]) ? oauth["expiresAt"] : void 0;
442
+ const expiresAt = epochMillisToIso(expiresAtMs);
443
+ const expired = expiresAt !== void 0 && expiresAtMs !== void 0 && expiresAtMs <= Date.now();
444
+ return {
445
+ state: expired ? "expired" : "signed-in",
446
+ directoryExists: exists,
447
+ email: void 0,
448
+ name: void 0,
449
+ expiresAt
450
+ };
451
+ }
452
+ var probeClaudeAccount = (accountPath) => {
453
+ const credentialsDirPath = resolveClaudeCredentialsDirPath(accountPath);
454
+ const account = readClaudeAccount(credentialsDirPath);
455
+ return {
456
+ accountPath: resolveClaudeAccountDirectory(credentialsDirPath),
457
+ state: account.state,
458
+ ...account.expiresAt === void 0 ? {} : { expiresAt: account.expiresAt }
459
+ };
460
+ };
461
+
207
462
  // src/liveHistory.ts
208
- import * as NodePath4 from "node:path";
463
+ import * as NodePath7 from "node:path";
209
464
  import * as NodeProcess2 from "node:process";
210
465
 
211
466
  // ../../packages/ycodium-jsonl-stream/src/historyErrors.ts
@@ -217,9 +472,9 @@ var NativeHistoryPendingError = class extends Error {
217
472
  };
218
473
 
219
474
  // ../../packages/ycodium-jsonl-stream/src/historyWaiting.ts
220
- import * as NodeFS from "node:fs";
475
+ import * as NodeFS2 from "node:fs";
221
476
  import * as NodeFSP from "node:fs/promises";
222
- import * as NodePath from "node:path";
477
+ import * as NodePath4 from "node:path";
223
478
  var pending = (error) => error instanceof NativeHistoryPendingError || error !== null && typeof error === "object" && "code" in error && error.code === "ENOENT";
224
479
  var waitForJsonlHistory = (input) => {
225
480
  const controller = new AbortController();
@@ -266,14 +521,14 @@ var waitForJsonlHistory = (input) => {
266
521
  ...input.signal ? [input.signal] : [],
267
522
  ...options.signal ? [options.signal] : []
268
523
  ]);
269
- let root = NodePath.resolve(input.root);
524
+ let root = NodePath4.resolve(input.root);
270
525
  while (true) {
271
526
  try {
272
527
  if ((await NodeFSP.stat(root)).isDirectory()) break;
273
528
  } catch (error2) {
274
529
  if (!pending(error2)) throw error2;
275
530
  }
276
- const parent = NodePath.dirname(root);
531
+ const parent = NodePath4.dirname(root);
277
532
  if (parent === root) throw new NativeHistoryPendingError();
278
533
  root = parent;
279
534
  }
@@ -285,8 +540,8 @@ var waitForJsonlHistory = (input) => {
285
540
  wake?.();
286
541
  wake = void 0;
287
542
  };
288
- const watcher = NodeFS.watch(root, { recursive: true, signal }, (_event, name) => {
289
- if (name == null || input.accepts(NodePath.resolve(root, String(name)))) notify();
543
+ const watcher = NodeFS2.watch(root, { recursive: true, signal }, (_event, name) => {
544
+ if (name == null || input.accepts(NodePath4.resolve(root, String(name)))) notify();
290
545
  });
291
546
  watcher.on("error", (cause) => {
292
547
  error = cause;
@@ -345,8 +600,8 @@ var waitForJsonlHistory = (input) => {
345
600
  };
346
601
 
347
602
  // ../../packages/ycodium-jsonl-stream/src/history.ts
348
- import * as NodeFS2 from "node:fs";
349
- import * as NodePath2 from "node:path";
603
+ import * as NodeFS3 from "node:fs";
604
+ import * as NodePath5 from "node:path";
350
605
 
351
606
  // ../../packages/ycodium-jsonl-stream/src/historyFile.ts
352
607
  import * as NodeFSP2 from "node:fs/promises";
@@ -1311,11 +1566,11 @@ async function openJsonlHistory(path, layout, signal) {
1311
1566
  wake?.();
1312
1567
  wake = void 0;
1313
1568
  };
1314
- const watcher = NodeFS2.watch(
1315
- NodePath2.dirname(path),
1569
+ const watcher = NodeFS3.watch(
1570
+ NodePath5.dirname(path),
1316
1571
  { signal: readSignal },
1317
1572
  (_event, file) => {
1318
- if (file == null || String(file) === NodePath2.basename(path)) notify();
1573
+ if (file == null || String(file) === NodePath5.basename(path)) notify();
1319
1574
  }
1320
1575
  );
1321
1576
  watcher.on("error", (error) => {
@@ -1451,7 +1706,7 @@ async function openJsonlHistory(path, layout, signal) {
1451
1706
  }
1452
1707
 
1453
1708
  // ../../packages/ycodium-jsonl-stream/src/claudeSessions.ts
1454
- import * as NodePath3 from "node:path";
1709
+ import * as NodePath6 from "node:path";
1455
1710
  import * as NodeProcess from "node:process";
1456
1711
  var PREVIEW_LIMIT = 200;
1457
1712
  var CLAUDE_MAX_SCANNED_FILES = 200;
@@ -1553,7 +1808,7 @@ async function listClaudeTranscriptFiles(fs2, transcriptDir, directory) {
1553
1808
  const scanned = matched.length > 0 ? matched : dirs;
1554
1809
  const found = [];
1555
1810
  for (const dir of scanned) {
1556
- const projectDir = NodePath3.join(transcriptDir, dir);
1811
+ const projectDir = NodePath6.join(transcriptDir, dir);
1557
1812
  let names;
1558
1813
  try {
1559
1814
  names = (await fs2.readDir(projectDir)).filter((entry) => entry.type === "file" && entry.name.endsWith(CLAUDE_TRANSCRIPT_SUFFIX)).map((entry) => entry.name);
@@ -1563,12 +1818,12 @@ async function listClaudeTranscriptFiles(fs2, transcriptDir, directory) {
1563
1818
  for (const name of names) {
1564
1819
  let stat5;
1565
1820
  try {
1566
- stat5 = await fs2.stat(NodePath3.join(projectDir, name));
1821
+ stat5 = await fs2.stat(NodePath6.join(projectDir, name));
1567
1822
  } catch {
1568
1823
  continue;
1569
1824
  }
1570
1825
  found.push({
1571
- path: NodePath3.join(projectDir, name),
1826
+ path: NodePath6.join(projectDir, name),
1572
1827
  sessionId: name.slice(0, -CLAUDE_TRANSCRIPT_SUFFIX.length),
1573
1828
  size: stat5.size,
1574
1829
  mtimeMs: Number.isFinite(stat5.mtimeMs) ? stat5.mtimeMs : 0
@@ -1579,7 +1834,7 @@ async function listClaudeTranscriptFiles(fs2, transcriptDir, directory) {
1579
1834
  }
1580
1835
  async function readClaudeLiveSessionIds(fs2, configDir) {
1581
1836
  const live = /* @__PURE__ */ new Set();
1582
- const markerDir = NodePath3.join(configDir, "sessions");
1837
+ const markerDir = NodePath6.join(configDir, "sessions");
1583
1838
  let entries;
1584
1839
  try {
1585
1840
  entries = (await fs2.readDir(markerDir)).filter((entry) => entry.type === "file" && entry.name.endsWith(".json")).map((entry) => entry.name);
@@ -1589,7 +1844,7 @@ async function readClaudeLiveSessionIds(fs2, configDir) {
1589
1844
  for (const entry of entries) {
1590
1845
  let marker;
1591
1846
  try {
1592
- marker = JSON.parse(await fs2.readFile(NodePath3.join(markerDir, entry)));
1847
+ marker = JSON.parse(await fs2.readFile(NodePath6.join(markerDir, entry)));
1593
1848
  } catch {
1594
1849
  continue;
1595
1850
  }
@@ -1729,13 +1984,13 @@ var openClaudeHistory = (input) => {
1729
1984
  for (const id2 of [input.nativeSessionId, input.parentNativeSessionId])
1730
1985
  if (!/^[A-Za-z0-9_-]+$/u.test(id2)) throw new Error("Invalid native session identifier.");
1731
1986
  const name = input.nativeSessionId.startsWith("agent-") ? input.nativeSessionId : `agent-${input.nativeSessionId}`;
1732
- if (input.parentTranscriptPath !== void 0 && (!NodePath4.isAbsolute(input.parentTranscriptPath) || NodePath4.basename(input.parentTranscriptPath) !== `${input.parentNativeSessionId}.jsonl`))
1987
+ if (input.parentTranscriptPath !== void 0 && (!NodePath7.isAbsolute(input.parentTranscriptPath) || NodePath7.basename(input.parentTranscriptPath) !== `${input.parentNativeSessionId}.jsonl`))
1733
1988
  throw new Error("Native transcript path does not match the recorded session.");
1734
- const projectDir = input.parentTranscriptPath === void 0 ? NodePath4.join(input.transcriptDir, encodeClaudeProjectDirName(input.cwd)) : NodePath4.dirname(input.parentTranscriptPath);
1735
- const path = NodePath4.join(projectDir, input.parentNativeSessionId, "subagents", `${name}.jsonl`);
1989
+ const projectDir = input.parentTranscriptPath === void 0 ? NodePath7.join(input.transcriptDir, encodeClaudeProjectDirName(input.cwd)) : NodePath7.dirname(input.parentTranscriptPath);
1990
+ const path = NodePath7.join(projectDir, input.parentNativeSessionId, "subagents", `${name}.jsonl`);
1736
1991
  return waitForJsonlHistory({
1737
1992
  root: input.parentTranscriptPath === void 0 ? input.transcriptDir : projectDir,
1738
- accepts: (changed) => changed === path || path.startsWith(changed + NodePath4.sep),
1993
+ accepts: (changed) => changed === path || path.startsWith(changed + NodePath7.sep),
1739
1994
  open: (signal) => openJsonlHistory(path, claudeHistoryLayout(input), signal),
1740
1995
  ...input.signal === void 0 ? {} : { signal: input.signal }
1741
1996
  });
@@ -21190,90 +21445,6 @@ import {
21190
21445
  isOperationCleanupError
21191
21446
  } from "@ycodium-ai/plugin-api/process-operation";
21192
21447
 
21193
- // src/claudeAccount.ts
21194
- import * as NodeOS from "node:os";
21195
- import * as NodePath5 from "node:path";
21196
-
21197
- // ../../packages/ycodium-credential-account/src/credentialAccount.ts
21198
- import * as NodeFS3 from "node:fs";
21199
- var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
21200
- var parseJsonRecord = (raw) => {
21201
- let parsed;
21202
- try {
21203
- parsed = JSON.parse(raw);
21204
- } catch {
21205
- return void 0;
21206
- }
21207
- return isRecord(parsed) ? parsed : void 0;
21208
- };
21209
- var directoryExists = (homePath) => {
21210
- try {
21211
- return NodeFS3.statSync(homePath).isDirectory();
21212
- } catch {
21213
- return false;
21214
- }
21215
- };
21216
- var readCredentialFile = (path) => {
21217
- try {
21218
- return NodeFS3.readFileSync(path, "utf8");
21219
- } catch {
21220
- return void 0;
21221
- }
21222
- };
21223
- var accountWithoutIdentity = (state, exists) => ({
21224
- state,
21225
- directoryExists: exists,
21226
- email: void 0,
21227
- name: void 0,
21228
- expiresAt: void 0
21229
- });
21230
- var epochMillisToIso = (value) => {
21231
- if (value === void 0 || !Number.isFinite(value)) return void 0;
21232
- const date = new Date(value);
21233
- return Number.isNaN(date.getTime()) ? void 0 : date.toISOString();
21234
- };
21235
-
21236
- // src/claudeAccount.ts
21237
- var OAUTH_KEY = "claudeAiOauth";
21238
- function resolveClaudeAccountDirectory(credentialsDirPath) {
21239
- return credentialsDirPath ?? NodePath5.join(NodeOS.homedir(), ".claude");
21240
- }
21241
- function claudeCredentialCandidatePaths(input) {
21242
- return input.credentialsDirPath === null ? [
21243
- NodePath5.join(input.homePath, ".claude", ".credentials.json"),
21244
- NodePath5.join(input.homePath, ".credentials.json")
21245
- ] : [NodePath5.join(input.credentialsDirPath, ".credentials.json")];
21246
- }
21247
- function readClaudeAccount(credentialsDirPath, credentialCandidates) {
21248
- const accountDirectory = resolveClaudeAccountDirectory(credentialsDirPath);
21249
- const exists = directoryExists(accountDirectory);
21250
- const candidates = credentialCandidates ?? claudeCredentialCandidatePaths({
21251
- homePath: NodeOS.homedir(),
21252
- credentialsDirPath
21253
- });
21254
- let raw;
21255
- for (const candidate of candidates) {
21256
- raw = readCredentialFile(candidate);
21257
- if (raw !== void 0) break;
21258
- }
21259
- if (raw === void 0) return accountWithoutIdentity("signed-out", exists);
21260
- const parsed = parseJsonRecord(raw);
21261
- const oauth = parsed === void 0 ? void 0 : parsed[OAUTH_KEY];
21262
- if (!isRecord(oauth) || typeof oauth["accessToken"] !== "string" || oauth["accessToken"].trim().length === 0) {
21263
- return accountWithoutIdentity("unreadable", exists);
21264
- }
21265
- const expiresAtMs = typeof oauth["expiresAt"] === "number" && Number.isFinite(oauth["expiresAt"]) ? oauth["expiresAt"] : void 0;
21266
- const expiresAt = epochMillisToIso(expiresAtMs);
21267
- const expired = expiresAt !== void 0 && expiresAtMs !== void 0 && expiresAtMs <= Date.now();
21268
- return {
21269
- state: expired ? "expired" : "signed-in",
21270
- directoryExists: exists,
21271
- email: void 0,
21272
- name: void 0,
21273
- expiresAt
21274
- };
21275
- }
21276
-
21277
21448
  // src/usageRead/quota.ts
21278
21449
  import * as NodeFS4 from "node:fs";
21279
21450
  import * as NodePath8 from "node:path";
@@ -21281,160 +21452,6 @@ import { mergeLaunchEnv as mergeLaunchEnv2, setsOwnModelConnection } from "@ycod
21281
21452
  import {
21282
21453
  parseRetryAfterMs
21283
21454
  } from "@ycodium-ai/plugin-api/usage";
21284
-
21285
- // ../../packages/ycodium-instance-config/src/homePath.ts
21286
- import * as NodeOS2 from "node:os";
21287
- import * as NodePath6 from "node:path";
21288
- import { mergeLaunchEnv } from "@ycodium-ai/plugin-api/executor";
21289
- function expandHomePath(value) {
21290
- if (value === "~") return NodeOS2.homedir();
21291
- if (value.startsWith("~/") || value.startsWith("~\\")) {
21292
- return NodePath6.join(NodeOS2.homedir(), value.slice(2));
21293
- }
21294
- return value;
21295
- }
21296
-
21297
- // src/claudeHome.ts
21298
- import * as NodeOS3 from "node:os";
21299
- import * as NodePath7 from "node:path";
21300
-
21301
- // ../../packages/ycodium-duration-format/src/durationFormat.ts
21302
- function formatCoarseWait(waitMs) {
21303
- const totalMinutes = Math.max(1, Math.ceil(waitMs / 6e4));
21304
- const days = Math.floor(totalMinutes / (24 * 60));
21305
- const hours = Math.floor(totalMinutes % (24 * 60) / 60);
21306
- const minutes = totalMinutes % 60;
21307
- if (days > 0) return hours === 0 ? `${String(days)}d` : `${String(days)}d ${String(hours)}h`;
21308
- if (hours === 0) return `${String(totalMinutes)}m`;
21309
- return minutes === 0 ? `${String(hours)}h` : `${String(hours)}h ${String(minutes)}m`;
21310
- }
21311
-
21312
- // src/usageLimit.ts
21313
- var WINDOW_NAMES = {
21314
- five_hour: "5-hour",
21315
- seven_day: "7-day",
21316
- seven_day_opus: "7-day Opus",
21317
- seven_day_sonnet: "7-day Sonnet",
21318
- overage: "overage"
21319
- };
21320
- var MAX_CREDIBLE_WAIT_MS = 30 * 24 * 60 * 60 * 1e3;
21321
- var isBlockingRateLimit = (info) => info.status === "rejected" && info.overageStatus !== "allowed" && info.overageStatus !== "allowed_warning" && info.isUsingOverage !== true && info.overageInUse !== true;
21322
- var isClearingRateLimit = (info) => info.status === "allowed" || info.status === "allowed_warning" || info.overageStatus === "allowed" || info.overageStatus === "allowed_warning" || info.isUsingOverage === true || info.overageInUse === true;
21323
- var rateLimitKey = (info) => `${info.rateLimitType ?? "unknown"}:${String(info.resetsAt ?? "unknown")}`;
21324
- var waitUntil = (resetsAtSeconds, nowMs) => {
21325
- if (resetsAtSeconds === void 0 || !Number.isFinite(nowMs)) return void 0;
21326
- const waitMs = resetsAtSeconds * 1e3 - nowMs;
21327
- return waitMs > 0 && waitMs <= MAX_CREDIBLE_WAIT_MS ? formatCoarseWait(waitMs) : void 0;
21328
- };
21329
- var describeUsageLimitPause = (info, nowMs) => {
21330
- const name = info.rateLimitType === void 0 ? void 0 : WINDOW_NAMES[info.rateLimitType];
21331
- const wait = waitUntil(info.resetsAt, nowMs);
21332
- return `Claude usage limit reached. This turn is paused until the ${name === void 0 ? "" : `${name} `}limit resets${wait === void 0 ? "" : ` in ${wait}`}.`;
21333
- };
21334
- var describeUsageLimitFailure = (rejected, nowMs) => {
21335
- let name;
21336
- let wait;
21337
- let latestResetSeconds = Number.NEGATIVE_INFINITY;
21338
- for (const [type4, resetsAt] of rejected) {
21339
- const label = WINDOW_NAMES[type4];
21340
- const reachable = waitUntil(resetsAt, nowMs);
21341
- if (label === void 0 || reachable === void 0 || resetsAt === void 0) continue;
21342
- if (resetsAt <= latestResetSeconds) continue;
21343
- latestResetSeconds = resetsAt;
21344
- name = label;
21345
- wait = reachable;
21346
- }
21347
- return name === void 0 ? "Claude usage limit reached. Send the message again once the limit resets." : `Claude usage limit reached. The ${name} limit resets in ${wait}. Send the message again once it resets.`;
21348
- };
21349
-
21350
- // src/claudeHome.ts
21351
- var CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE = "CLAUDE_SECURESTORAGE_CONFIG_DIR";
21352
- function resolveClaudeHomePath(homePath) {
21353
- const trimmed = homePath.trim();
21354
- return NodePath7.resolve(trimmed.length > 0 ? expandHomePath(trimmed) : NodeOS3.homedir());
21355
- }
21356
- function claudeContinuationKey(homePath) {
21357
- return `claude:home:${resolveClaudeHomePath(homePath)}`;
21358
- }
21359
- function resolveClaudeConfigDirPath(homePath, environment, cwd) {
21360
- const trimmed = homePath.trim();
21361
- if (trimmed.length > 0) {
21362
- return NodePath7.resolve(expandHomePath(trimmed));
21363
- }
21364
- const environmentConfigDir = environment.CLAUDE_CONFIG_DIR?.trim() ?? "";
21365
- if (environmentConfigDir.length > 0) {
21366
- return cwd ? NodePath7.resolve(cwd, environmentConfigDir) : NodePath7.resolve(environmentConfigDir);
21367
- }
21368
- return NodePath7.join(NodeOS3.homedir(), ".claude");
21369
- }
21370
- function resolveClaudeCredentialsDirPath(credentialsPath) {
21371
- const trimmed = credentialsPath.trim();
21372
- if (trimmed.length === 0) return null;
21373
- return NodePath7.resolve(expandHomePath(trimmed));
21374
- }
21375
- function resolveClaudeHomeLayout(input) {
21376
- return {
21377
- configDirPath: input.homePath.trim().length > 0 ? resolveClaudeHomePath(input.homePath) : void 0,
21378
- credentialsDirPath: resolveClaudeCredentialsDirPath(input.credentialsPath) ?? void 0
21379
- };
21380
- }
21381
- function claudeHomeVariables(layout) {
21382
- return {
21383
- ...layout.configDirPath === void 0 ? {} : { CLAUDE_CONFIG_DIR: layout.configDirPath },
21384
- ...layout.credentialsDirPath === void 0 ? {} : { [CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE]: layout.credentialsDirPath }
21385
- };
21386
- }
21387
- function makeClaudeEnvironment(config, baseEnv) {
21388
- const resolvedBaseEnv = { ...baseEnv ?? process.env };
21389
- const variables = claudeHomeVariables(
21390
- resolveClaudeHomeLayout({
21391
- homePath: config.homePath,
21392
- credentialsPath: config.credentialsPath
21393
- })
21394
- );
21395
- if (Object.keys(variables).length === 0) return resolvedBaseEnv;
21396
- return { ...resolvedBaseEnv, ...variables };
21397
- }
21398
- var quoteLiteral = (value) => JSON.stringify(value);
21399
- function claudeSignedOutMessage(input) {
21400
- const variables = [];
21401
- const configDir = input.configDir?.trim() ?? "";
21402
- if (configDir.length > 0) {
21403
- variables.push(
21404
- `CLAUDE_CONFIG_DIR set to ${quoteLiteral(NodePath7.resolve(input.cwd, configDir))}`
21405
- );
21406
- }
21407
- const credentialsDir = input.credentialsDir?.trim() ?? "";
21408
- if (credentialsDir.length > 0) {
21409
- variables.push(
21410
- `${CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE} set to ${quoteLiteral(NodePath7.resolve(input.cwd, credentialsDir))}`
21411
- );
21412
- }
21413
- const withVariables = variables.length > 0 ? `, with ${variables.join(" and ")}` : "";
21414
- return `Claude could not authenticate. For subscription login, run \`claude auth login\` on this machine${withVariables}, then start a new thread. For API-key authentication, check this instance's configured credentials.`;
21415
- }
21416
- function claudeFailureHint(input) {
21417
- if (input.authenticationFailed) {
21418
- return {
21419
- category: "auth",
21420
- text: claudeSignedOutMessage({
21421
- configDir: input.environment.CLAUDE_CONFIG_DIR,
21422
- credentialsDir: input.environment[CLAUDE_CREDENTIALS_DIR_ENVIRONMENT_VARIABLE],
21423
- cwd: input.cwd
21424
- })
21425
- };
21426
- }
21427
- const limit = input.usageLimit;
21428
- if (limit !== void 0 && (limit.rejected.size > 0 || limit.latestAssistantRateLimited)) {
21429
- return {
21430
- category: limit.rejected.size > 0 ? "quota" : "rate-limit",
21431
- text: describeUsageLimitFailure(limit.rejected, limit.nowMs)
21432
- };
21433
- }
21434
- return void 0;
21435
- }
21436
-
21437
- // src/usageRead/quota.ts
21438
21455
  var CLAUDE_QUOTA_URL = "https://api.anthropic.com/api/oauth/usage";
21439
21456
  var REQUEST_TIMEOUT_MS = 1e4;
21440
21457
  var HOUR_MS = 60 * 60 * 1e3;
@@ -30036,6 +30053,7 @@ var executors = [
30036
30053
  host.log.info("createInstance");
30037
30054
  return createClaudeInstance(config, host, capturedAttachments, void 0, capturedCache);
30038
30055
  },
30056
+ probeAccount: async ({ accountPath }) => probeClaudeAccount(accountPath),
30039
30057
  // 厂商脚本装,宿主卸不了;登录要在那台机器的终端里跑 `claude auth login`,宿主只回这条命令。
30040
30058
  lifecycle: [
30041
30059
  { kind: "install", reversible: false },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-claude",
3
- "version": "0.2.5357",
3
+ "version": "0.2.5374",
4
4
  "description": "Claude executor: Claude Code CLI via @anthropic-ai/claude-agent-sdk.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -24,11 +24,11 @@
24
24
  "@types/node": "24.12.4",
25
25
  "esbuild": "0.28.1",
26
26
  "vite-plus": "0.2.2",
27
- "@ycodium-ai/plugin-api": "0.2.5357",
27
+ "@ycodium-ai/plugin-api": "0.2.5374",
28
28
  "ycodium-composer-tokens": "0.0.0",
29
- "ycodium-executor-testing": "0.0.0",
30
- "ycodium-duration-format": "0.0.0",
31
29
  "ycodium-credential-account": "0.0.0",
30
+ "ycodium-duration-format": "0.0.0",
31
+ "ycodium-executor-testing": "0.0.0",
32
32
  "ycodium-instance-config": "0.0.0",
33
33
  "ycodium-jsonl-stream": "0.0.0",
34
34
  "ycodium-text-generation": "0.0.0",