@livx.cc/agentx 0.94.38 → 0.95.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.d.ts CHANGED
@@ -1316,4 +1316,35 @@ declare class CartesiaTTS {
1316
1316
  close(): void;
1317
1317
  }
1318
1318
 
1319
- export { Agent, type AgentDef, AgentOptions, AgentTool, type AskOptions, type Attempt, type AudioSink, type AudioSource, type AuthProvider, BodDbFilesystem, CartesiaTTS, CartesiaTTSOptions, ChatLike, ChatOptions, ChatResponse, type CommandInfo, ConsoleHostBridge, DEFAULT_DENY, DuplexAgent, DuplexAgentOptions, type DuplexTaskStatus, FakeAIClient, Hooks, HostBridge, JailOptions, JailedFilesystem, type LessonOptions, LessonOptionsDefaults, type LoadMemoryOpts, MEMORY_PROMPT, MessageContent, type Mount, MountFilesystem, NodeDiskFilesystem, OverlayFilesystem, type ReflectOptions, RunResult, SCRATCH_DIR, STT_SAMPLE_RATE, type ScheduledJob, type ScheduledJobSnapshot, Scheduler, type SchedulerOptions, Scratch, type ScratchOptions, ScriptedHostBridge, type SiblingResolver, type SkillInfo, SonioxSTT, SonioxSTTOptions, type SttLike, TTS_SAMPLE_RATE, type TaskRecord, type TaskToolOptions, ToolCall, type ToolSpec, type Trigger, type TriggerCron, type TriggerInterval, type TriggerOneOff, type TtsLike, UserQuestion, VOICE_MEMORY_PROMPT, VOICE_SYSTEM_PROMPT, VoiceEngine, VoiceEngineOptions, type VoiceState, type WebFetchOptions, type WebSearchOptions, type WorkerTier, applyEditsTool, askUserQuestionTool, checkpointTool, checkpointTools, compileSynthesizedTool, cronMatches, decodeDdgUrl, diskAgentOptions, expandCommand, expandEntry, expandTemplate, forComponent, fullAgentOptions, globTool, grepTool, htmlToText, idfWeights, lessonCapture, loadAgents, loadCommands, loadInstructions, loadMemory, loadSkills, makeAskTool, makeScheduleTools, makeTaskBatchTool, makeTaskTool, makeWebFetchTool, makeWebSearchTool, mkdirp, multiEditTool, nextCronAfter, parseCron, parseDdgHtml, raceAttempts, reflectOnRun, relevanceScore, repoIndex, repoMapTool, resolveAuth, rollbackTool, sandboxAgentOptions, scanCommands, scanSkills, slugify, tokenize, toolCall, topByRelevance, validateToolCode, webFetchTool, webSearchTool, writeFact, writeTool };
1319
+ declare function validateWorktreeSlug(slug: string): void;
1320
+ declare function worktreeBranchName(slug: string): string;
1321
+ interface WorktreeInfo {
1322
+ worktreePath: string;
1323
+ branch: string;
1324
+ headCommit: string;
1325
+ existed: boolean;
1326
+ baseBranch?: string;
1327
+ }
1328
+ declare function findGitRoot(from: string): string | null;
1329
+ declare function getOrCreateWorktree(repoRoot: string, slug: string): WorktreeInfo;
1330
+ declare function cleanupWorktree(repoRoot: string, slug: string, opts?: {
1331
+ force?: boolean;
1332
+ }): {
1333
+ removed: boolean;
1334
+ reason?: string;
1335
+ };
1336
+ interface WorktreeSession {
1337
+ originalCwd: string;
1338
+ worktreePath: string;
1339
+ slug: string;
1340
+ branch: string;
1341
+ headCommit: string;
1342
+ }
1343
+ declare function getWorktreeSession(): WorktreeSession | null;
1344
+ declare function enterWorktree(slug: string, cwd: string): WorktreeSession;
1345
+ declare function exitWorktree(): {
1346
+ removed: boolean;
1347
+ reason?: string;
1348
+ } | null;
1349
+
1350
+ export { Agent, type AgentDef, AgentOptions, AgentTool, type AskOptions, type Attempt, type AudioSink, type AudioSource, type AuthProvider, BodDbFilesystem, CartesiaTTS, CartesiaTTSOptions, ChatLike, ChatOptions, ChatResponse, type CommandInfo, ConsoleHostBridge, DEFAULT_DENY, DuplexAgent, DuplexAgentOptions, type DuplexTaskStatus, FakeAIClient, Hooks, HostBridge, JailOptions, JailedFilesystem, type LessonOptions, LessonOptionsDefaults, type LoadMemoryOpts, MEMORY_PROMPT, MessageContent, type Mount, MountFilesystem, NodeDiskFilesystem, OverlayFilesystem, type ReflectOptions, RunResult, SCRATCH_DIR, STT_SAMPLE_RATE, type ScheduledJob, type ScheduledJobSnapshot, Scheduler, type SchedulerOptions, Scratch, type ScratchOptions, ScriptedHostBridge, type SiblingResolver, type SkillInfo, SonioxSTT, SonioxSTTOptions, type SttLike, TTS_SAMPLE_RATE, type TaskRecord, type TaskToolOptions, ToolCall, type ToolSpec, type Trigger, type TriggerCron, type TriggerInterval, type TriggerOneOff, type TtsLike, UserQuestion, VOICE_MEMORY_PROMPT, VOICE_SYSTEM_PROMPT, VoiceEngine, VoiceEngineOptions, type VoiceState, type WebFetchOptions, type WebSearchOptions, type WorkerTier, type WorktreeInfo, type WorktreeSession, applyEditsTool, askUserQuestionTool, checkpointTool, checkpointTools, cleanupWorktree, compileSynthesizedTool, cronMatches, decodeDdgUrl, diskAgentOptions, enterWorktree, exitWorktree, expandCommand, expandEntry, expandTemplate, findGitRoot, forComponent, fullAgentOptions, getOrCreateWorktree, getWorktreeSession, globTool, grepTool, htmlToText, idfWeights, lessonCapture, loadAgents, loadCommands, loadInstructions, loadMemory, loadSkills, makeAskTool, makeScheduleTools, makeTaskBatchTool, makeTaskTool, makeWebFetchTool, makeWebSearchTool, mkdirp, multiEditTool, nextCronAfter, parseCron, parseDdgHtml, raceAttempts, reflectOnRun, relevanceScore, repoIndex, repoMapTool, resolveAuth, rollbackTool, sandboxAgentOptions, scanCommands, scanSkills, slugify, tokenize, toolCall, topByRelevance, validateToolCode, validateWorktreeSlug, webFetchTool, webSearchTool, worktreeBranchName, writeFact, writeTool };
package/dist/index.js CHANGED
@@ -5876,6 +5876,155 @@ function base64ToBytes(b64) {
5876
5876
  return out;
5877
5877
  }
5878
5878
 
5879
+ // src/worktree.ts
5880
+ import { spawnSync } from "child_process";
5881
+ import { symlinkSync, mkdirSync, statSync, readFileSync, rmSync } from "fs";
5882
+ import { join as join2 } from "path";
5883
+ var VALID_SEGMENT = /^[a-zA-Z0-9._-]+$/;
5884
+ var MAX_SLUG_LENGTH = 64;
5885
+ var GIT_NO_PROMPT_ENV = { GIT_TERMINAL_PROMPT: "0", GIT_ASKPASS: "" };
5886
+ function validateWorktreeSlug(slug2) {
5887
+ if (!slug2) throw new Error("worktree slug must not be empty");
5888
+ if (slug2.length > MAX_SLUG_LENGTH) throw new Error(`worktree slug must be \u2264${MAX_SLUG_LENGTH} chars (got ${slug2.length})`);
5889
+ for (const seg of slug2.split("/")) {
5890
+ if (seg === "." || seg === "..") throw new Error(`worktree slug must not contain "." or ".." segments`);
5891
+ if (!VALID_SEGMENT.test(seg)) throw new Error(`worktree slug segment "${seg}" contains invalid characters (allowed: a-z A-Z 0-9 . _ -)`);
5892
+ }
5893
+ }
5894
+ function flattenSlug(slug2) {
5895
+ return slug2.replaceAll("/", "+");
5896
+ }
5897
+ function worktreeBranchName(slug2) {
5898
+ return `worktree-${flattenSlug(slug2)}`;
5899
+ }
5900
+ function worktreesDir(repoRoot) {
5901
+ return join2(repoRoot, ".claude", "worktrees");
5902
+ }
5903
+ function worktreePathFor(repoRoot, slug2) {
5904
+ return join2(worktreesDir(repoRoot), flattenSlug(slug2));
5905
+ }
5906
+ function git(args, cwd) {
5907
+ const r = spawnSync("git", args, {
5908
+ cwd,
5909
+ stdio: ["ignore", "pipe", "pipe"],
5910
+ env: { ...process.env, ...GIT_NO_PROMPT_ENV }
5911
+ });
5912
+ return { ok: r.status === 0, stdout: (r.stdout ?? "").toString().trim(), stderr: (r.stderr ?? "").toString().trim() };
5913
+ }
5914
+ function findGitRoot(from) {
5915
+ const r = git(["rev-parse", "--show-toplevel"], from);
5916
+ return r.ok ? r.stdout : null;
5917
+ }
5918
+ function readWorktreeHead(worktreePath) {
5919
+ try {
5920
+ const gitFile = readFileSync(join2(worktreePath, ".git"), "utf-8").trim();
5921
+ const m = gitFile.match(/^gitdir:\s*(.+)$/);
5922
+ if (!m) return null;
5923
+ const headPath = join2(m[1], "HEAD");
5924
+ const head = readFileSync(headPath, "utf-8").trim();
5925
+ const refMatch = head.match(/^ref:\s*(.+)$/);
5926
+ if (!refMatch) return head.length === 40 ? head : null;
5927
+ const refPath = join2(m[1], "..", refMatch[1]);
5928
+ try {
5929
+ return readFileSync(refPath, "utf-8").trim();
5930
+ } catch {
5931
+ }
5932
+ const r = git(["rev-parse", "HEAD"], worktreePath);
5933
+ return r.ok ? r.stdout : null;
5934
+ } catch {
5935
+ return null;
5936
+ }
5937
+ }
5938
+ function getOrCreateWorktree(repoRoot, slug2) {
5939
+ validateWorktreeSlug(slug2);
5940
+ const worktreePath = worktreePathFor(repoRoot, slug2);
5941
+ const branch = worktreeBranchName(slug2);
5942
+ const existingHead = readWorktreeHead(worktreePath);
5943
+ if (existingHead) return { worktreePath, branch, headCommit: existingHead, existed: true };
5944
+ mkdirSync(worktreesDir(repoRoot), { recursive: true });
5945
+ const defaultBranch = git(["symbolic-ref", "--short", "refs/remotes/origin/HEAD"], repoRoot);
5946
+ let baseBranch = defaultBranch.ok ? defaultBranch.stdout.replace(/^origin\//, "") : "HEAD";
5947
+ const originRef = `origin/${baseBranch}`;
5948
+ const hasOrigin = git(["rev-parse", "--verify", originRef], repoRoot);
5949
+ if (!hasOrigin.ok) {
5950
+ const fetched = git(["fetch", "origin", baseBranch], repoRoot);
5951
+ if (!fetched.ok) baseBranch = "HEAD";
5952
+ }
5953
+ const base = baseBranch === "HEAD" ? "HEAD" : originRef;
5954
+ const r = git(["worktree", "add", "-B", branch, worktreePath, base], repoRoot);
5955
+ if (!r.ok) throw new Error(`failed to create worktree: ${r.stderr}`);
5956
+ const headSha = git(["rev-parse", "HEAD"], worktreePath);
5957
+ symlinkDirs(repoRoot, worktreePath, ["node_modules", ".bun"]);
5958
+ return { worktreePath, branch, headCommit: headSha.stdout, existed: false, baseBranch };
5959
+ }
5960
+ function symlinkDirs(repoRoot, worktreePath, dirs) {
5961
+ for (const dir of dirs) {
5962
+ const src = join2(repoRoot, dir);
5963
+ const dst = join2(worktreePath, dir);
5964
+ try {
5965
+ statSync(src);
5966
+ } catch {
5967
+ continue;
5968
+ }
5969
+ try {
5970
+ symlinkSync(src, dst, "dir");
5971
+ } catch (e) {
5972
+ if (e?.code !== "EEXIST") console.error(`[worktree] symlink ${dir}: ${e?.message ?? e}`);
5973
+ }
5974
+ }
5975
+ }
5976
+ function cleanupWorktree(repoRoot, slug2, opts) {
5977
+ validateWorktreeSlug(slug2);
5978
+ const worktreePath = worktreePathFor(repoRoot, slug2);
5979
+ const branch = worktreeBranchName(slug2);
5980
+ try {
5981
+ statSync(worktreePath);
5982
+ } catch {
5983
+ return { removed: false, reason: "not found" };
5984
+ }
5985
+ if (!opts?.force) {
5986
+ const status = git(["status", "--porcelain", "-uno"], worktreePath);
5987
+ if (status.ok && status.stdout) return { removed: false, reason: "uncommitted changes" };
5988
+ }
5989
+ for (const dir of ["node_modules", ".bun"]) {
5990
+ try {
5991
+ rmSync(join2(worktreePath, dir));
5992
+ } catch {
5993
+ }
5994
+ }
5995
+ const rm = git(["worktree", "remove", "--force", worktreePath], repoRoot);
5996
+ if (!rm.ok) return { removed: false, reason: rm.stderr };
5997
+ git(["branch", "-D", branch], repoRoot);
5998
+ return { removed: true };
5999
+ }
6000
+ var _session = null;
6001
+ function getWorktreeSession() {
6002
+ return _session;
6003
+ }
6004
+ function enterWorktree(slug2, cwd) {
6005
+ const repoRoot = findGitRoot(cwd);
6006
+ if (!repoRoot) throw new Error("--worktree requires a git repository");
6007
+ const info = getOrCreateWorktree(repoRoot, slug2);
6008
+ process.chdir(info.worktreePath);
6009
+ _session = {
6010
+ originalCwd: cwd,
6011
+ worktreePath: info.worktreePath,
6012
+ slug: slug2,
6013
+ branch: info.branch,
6014
+ headCommit: info.headCommit
6015
+ };
6016
+ return _session;
6017
+ }
6018
+ function exitWorktree() {
6019
+ if (!_session) return null;
6020
+ const repoRoot = findGitRoot(_session.originalCwd);
6021
+ if (!repoRoot) return null;
6022
+ process.chdir(_session.originalCwd);
6023
+ const result = cleanupWorktree(repoRoot, _session.slug);
6024
+ _session = null;
6025
+ return result;
6026
+ }
6027
+
5879
6028
  // src/index.ts
5880
6029
  import { MemFilesystem as MemFilesystem3, IndexedDbFilesystem, CommandExecutor as CommandExecutor2, registerHeadlessCommands as registerHeadlessCommands2 } from "@livx.cc/wcli/core";
5881
6030
  export {
@@ -5923,6 +6072,7 @@ export {
5923
6072
  buildMcpCatalog,
5924
6073
  checkpointTool,
5925
6074
  checkpointTools,
6075
+ cleanupWorktree,
5926
6076
  compileSynthesizedTool,
5927
6077
  composeHooks,
5928
6078
  contentText,
@@ -5931,12 +6081,17 @@ export {
5931
6081
  defaultTools,
5932
6082
  diskAgentOptions,
5933
6083
  editTool,
6084
+ enterWorktree,
5934
6085
  exitSessionTool,
6086
+ exitWorktree,
5935
6087
  expandCommand,
5936
6088
  expandEntry,
5937
6089
  expandTemplate,
6090
+ findGitRoot,
5938
6091
  forComponent,
5939
6092
  fullAgentOptions,
6093
+ getOrCreateWorktree,
6094
+ getWorktreeSession,
5940
6095
  globTool,
5941
6096
  grepTool,
5942
6097
  htmlToText,
@@ -5990,8 +6145,10 @@ export {
5990
6145
  toolsByName,
5991
6146
  topByRelevance,
5992
6147
  validateToolCode,
6148
+ validateWorktreeSlug,
5993
6149
  webFetchTool,
5994
6150
  webSearchTool,
6151
+ worktreeBranchName,
5995
6152
  writeFact,
5996
6153
  writeTool
5997
6154
  };