dwclaw-cli 1.0.0 → 1.2.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.
package/dist/bundle.js CHANGED
@@ -16339,11 +16339,11 @@ var require_commands_queue = __commonJS({
16339
16339
  return;
16340
16340
  }
16341
16341
  ;
16342
- return new Promise((resolve10) => {
16342
+ return new Promise((resolve11) => {
16343
16343
  const onEmpty = () => {
16344
16344
  if (timeoutId)
16345
16345
  clearTimeout(timeoutId);
16346
- resolve10();
16346
+ resolve11();
16347
16347
  };
16348
16348
  let timeoutId;
16349
16349
  const timeoutMs = options?.timeoutMs;
@@ -16356,7 +16356,7 @@ var require_commands_queue = __commonJS({
16356
16356
  (0, enterprise_maintenance_manager_1.dbgMaintenance)(`Flushing ${pendingCount} commands that timed out waiting for reply`);
16357
16357
  this.#flushWaitingForReply(new errors_1.TimeoutError());
16358
16358
  }
16359
- resolve10();
16359
+ resolve11();
16360
16360
  }, timeoutMs);
16361
16361
  }
16362
16362
  this.#waitingForReply.events.once("empty", onEmpty);
@@ -16368,14 +16368,14 @@ var require_commands_queue = __commonJS({
16368
16368
  } else if (options?.abortSignal?.aborted) {
16369
16369
  return Promise.reject(new errors_1.AbortError());
16370
16370
  }
16371
- return new Promise((resolve10, reject) => {
16371
+ return new Promise((resolve11, reject) => {
16372
16372
  let node;
16373
16373
  const value = {
16374
16374
  args,
16375
16375
  chainId: options?.chainId,
16376
16376
  abort: void 0,
16377
16377
  timeout: void 0,
16378
- resolve: resolve10,
16378
+ resolve: resolve11,
16379
16379
  reject,
16380
16380
  channelsCounter: void 0,
16381
16381
  typeMapping: options?.typeMapping
@@ -16410,7 +16410,7 @@ var require_commands_queue = __commonJS({
16410
16410
  });
16411
16411
  }
16412
16412
  #addPubSubCommand(command, asap = false, chainId) {
16413
- return new Promise((resolve10, reject) => {
16413
+ return new Promise((resolve11, reject) => {
16414
16414
  this.#toWrite.add({
16415
16415
  args: command.args,
16416
16416
  chainId,
@@ -16418,7 +16418,7 @@ var require_commands_queue = __commonJS({
16418
16418
  timeout: void 0,
16419
16419
  resolve() {
16420
16420
  command.resolve();
16421
- resolve10();
16421
+ resolve11();
16422
16422
  },
16423
16423
  reject(err) {
16424
16424
  command.reject?.();
@@ -16438,8 +16438,8 @@ var require_commands_queue = __commonJS({
16438
16438
  return;
16439
16439
  const firstElement = typeof reply[0] === "string" ? Buffer.from(reply[0]) : reply[0];
16440
16440
  if (PONG.equals(firstElement)) {
16441
- const { resolve: resolve10, typeMapping } = this.#waitingForReply.shift(), buffer = reply[1].length === 0 ? reply[0] : reply[1];
16442
- resolve10(typeMapping?.[decoder_1.RESP_TYPES.SIMPLE_STRING] === Buffer ? buffer : buffer.toString());
16441
+ const { resolve: resolve11, typeMapping } = this.#waitingForReply.shift(), buffer = reply[1].length === 0 ? reply[0] : reply[1];
16442
+ resolve11(typeMapping?.[decoder_1.RESP_TYPES.SIMPLE_STRING] === Buffer ? buffer : buffer.toString());
16443
16443
  return;
16444
16444
  }
16445
16445
  }
@@ -16463,12 +16463,12 @@ var require_commands_queue = __commonJS({
16463
16463
  if (!command)
16464
16464
  return;
16465
16465
  if (command && this.#respVersion === 2) {
16466
- const { resolve: resolve10 } = command;
16466
+ const { resolve: resolve11 } = command;
16467
16467
  command.resolve = () => {
16468
16468
  if (!this.#pubSub.isActive) {
16469
16469
  this.#resetDecoderCallbacks();
16470
16470
  }
16471
- resolve10();
16471
+ resolve11();
16472
16472
  };
16473
16473
  }
16474
16474
  return this.#addPubSubCommand(command);
@@ -16504,7 +16504,7 @@ var require_commands_queue = __commonJS({
16504
16504
  return this.#pubSub.listeners[type];
16505
16505
  }
16506
16506
  monitor(callback, options) {
16507
- return new Promise((resolve10, reject) => {
16507
+ return new Promise((resolve11, reject) => {
16508
16508
  const typeMapping = options?.typeMapping ?? {};
16509
16509
  this.#toWrite.add({
16510
16510
  args: ["MONITOR"],
@@ -16519,7 +16519,7 @@ var require_commands_queue = __commonJS({
16519
16519
  this.decoder.onReply = callback;
16520
16520
  }
16521
16521
  this.decoder.getTypeMapping = () => typeMapping;
16522
- resolve10();
16522
+ resolve11();
16523
16523
  },
16524
16524
  reject,
16525
16525
  channelsCounter: void 0,
@@ -16533,7 +16533,7 @@ var require_commands_queue = __commonJS({
16533
16533
  }
16534
16534
  #resetFallbackOnReply;
16535
16535
  async reset(chainId, typeMapping) {
16536
- return new Promise((resolve10, reject) => {
16536
+ return new Promise((resolve11, reject) => {
16537
16537
  this.#resetFallbackOnReply = this.decoder.onReply;
16538
16538
  this.decoder.onReply = ((reply) => {
16539
16539
  if (typeof reply === "string" && reply === "RESET" || reply instanceof Buffer && RESET.equals(reply)) {
@@ -16550,7 +16550,7 @@ var require_commands_queue = __commonJS({
16550
16550
  chainId,
16551
16551
  abort: void 0,
16552
16552
  timeout: void 0,
16553
- resolve: resolve10,
16553
+ resolve: resolve11,
16554
16554
  reject,
16555
16555
  channelsCounter: void 0,
16556
16556
  typeMapping
@@ -17870,7 +17870,7 @@ var require_pool = __commonJS({
17870
17870
  this._self.#returnClient(node);
17871
17871
  }
17872
17872
  execute(fn) {
17873
- return new Promise((resolve10, reject) => {
17873
+ return new Promise((resolve11, reject) => {
17874
17874
  const client2 = this._self.#idleClients.shift(), { tail } = this._self.#tasksQueue;
17875
17875
  if (!client2) {
17876
17876
  let timeout;
@@ -17883,7 +17883,7 @@ var require_pool = __commonJS({
17883
17883
  const task = this._self.#tasksQueue.push({
17884
17884
  timeout,
17885
17885
  // @ts-ignore
17886
- resolve: resolve10,
17886
+ resolve: resolve11,
17887
17887
  reject,
17888
17888
  fn
17889
17889
  });
@@ -17893,15 +17893,15 @@ var require_pool = __commonJS({
17893
17893
  return;
17894
17894
  }
17895
17895
  const node = this._self.#clientsInUse.push(client2);
17896
- this._self.#executeTask(node, resolve10, reject, fn);
17896
+ this._self.#executeTask(node, resolve11, reject, fn);
17897
17897
  });
17898
17898
  }
17899
- #executeTask(node, resolve10, reject, fn) {
17899
+ #executeTask(node, resolve11, reject, fn) {
17900
17900
  const result = fn(node.value);
17901
17901
  if (result instanceof Promise) {
17902
- result.then(resolve10, reject).finally(() => this.#returnClient(node));
17902
+ result.then(resolve11, reject).finally(() => this.#returnClient(node));
17903
17903
  } else {
17904
- resolve10(result);
17904
+ resolve11(result);
17905
17905
  this.#returnClient(node);
17906
17906
  }
17907
17907
  }
@@ -18948,20 +18948,20 @@ var require_client = __commonJS({
18948
18948
  * Close the client. Wait for pending commands.
18949
18949
  */
18950
18950
  close() {
18951
- return new Promise((resolve10) => {
18951
+ return new Promise((resolve11) => {
18952
18952
  clearTimeout(this._self.#pingTimer);
18953
18953
  this._self.#socket.close();
18954
18954
  this._self.#clientSideCache?.onClose();
18955
18955
  if (this._self.#queue.isEmpty()) {
18956
18956
  this._self.#socket.destroySocket();
18957
- return resolve10();
18957
+ return resolve11();
18958
18958
  }
18959
18959
  const maybeClose = () => {
18960
18960
  if (!this._self.#queue.isEmpty())
18961
18961
  return;
18962
18962
  this._self.#socket.off("data", maybeClose);
18963
18963
  this._self.#socket.destroySocket();
18964
- resolve10();
18964
+ resolve11();
18965
18965
  };
18966
18966
  this._self.#socket.on("data", maybeClose);
18967
18967
  this._self.#credentialsSubscription?.dispose();
@@ -20605,9 +20605,9 @@ var require_wait_queue = __commonJS({
20605
20605
  #list = new linked_list_1.SinglyLinkedList();
20606
20606
  #queue = new linked_list_1.SinglyLinkedList();
20607
20607
  push(value) {
20608
- const resolve10 = this.#queue.shift();
20609
- if (resolve10 !== void 0) {
20610
- resolve10(value);
20608
+ const resolve11 = this.#queue.shift();
20609
+ if (resolve11 !== void 0) {
20610
+ resolve11(value);
20611
20611
  return;
20612
20612
  }
20613
20613
  this.#list.push(value);
@@ -20616,7 +20616,7 @@ var require_wait_queue = __commonJS({
20616
20616
  return this.#list.shift();
20617
20617
  }
20618
20618
  wait() {
20619
- return new Promise((resolve10) => this.#queue.push(resolve10));
20619
+ return new Promise((resolve11) => this.#queue.push(resolve11));
20620
20620
  }
20621
20621
  };
20622
20622
  exports2.WaitQueue = WaitQueue;
@@ -28870,11 +28870,11 @@ var require_tracked_promise = __commonJS({
28870
28870
  value;
28871
28871
  constructor(executor) {
28872
28872
  this.state = "pending";
28873
- this.promise = new Promise((resolve10, reject) => {
28873
+ this.promise = new Promise((resolve11, reject) => {
28874
28874
  executor((value) => {
28875
28875
  this.state = "fulfilled";
28876
28876
  this.value = value;
28877
- resolve10(value);
28877
+ resolve11(value);
28878
28878
  }, (error) => {
28879
28879
  this.state = "rejected";
28880
28880
  this.error = error;
@@ -28978,7 +28978,7 @@ var require_runner = __commonJS({
28978
28978
  }
28979
28979
  };
28980
28980
  const runTask = (date) => {
28981
- return new Promise(async (resolve10) => {
28981
+ return new Promise(async (resolve11) => {
28982
28982
  const execution = {
28983
28983
  id: (0, create_id_1.createID)("exec"),
28984
28984
  reason: "scheduled"
@@ -29003,18 +29003,18 @@ var require_runner = __commonJS({
29003
29003
  execution.error = error;
29004
29004
  this.onError(date, error, execution);
29005
29005
  }
29006
- resolve10(true);
29006
+ resolve11(true);
29007
29007
  }, randomDelay);
29008
29008
  }
29009
29009
  });
29010
29010
  };
29011
29011
  const checkAndRun = (date) => {
29012
- return new tracked_promise_1.TrackedPromise(async (resolve10, reject) => {
29012
+ return new tracked_promise_1.TrackedPromise(async (resolve11, reject) => {
29013
29013
  try {
29014
29014
  if (this.timeMatcher.match(date)) {
29015
29015
  await runTask(date);
29016
29016
  }
29017
- resolve10(true);
29017
+ resolve11(true);
29018
29018
  } catch (err) {
29019
29019
  reject(err);
29020
29020
  }
@@ -29679,14 +29679,14 @@ var require_inline_scheduled_task = __commonJS({
29679
29679
  this.emitter.emit("task:destroyed", this.createContext(/* @__PURE__ */ new Date()));
29680
29680
  }
29681
29681
  execute() {
29682
- return new Promise((resolve10, reject) => {
29682
+ return new Promise((resolve11, reject) => {
29683
29683
  const onFail = (context) => {
29684
29684
  this.off("execution:finished", onFail);
29685
29685
  reject(context.execution?.error);
29686
29686
  };
29687
29687
  const onFinished = (context) => {
29688
29688
  this.off("execution:failed", onFail);
29689
- resolve10(context.execution?.result);
29689
+ resolve11(context.execution?.result);
29690
29690
  };
29691
29691
  this.once("execution:finished", onFinished);
29692
29692
  this.once("execution:failed", onFail);
@@ -29877,9 +29877,9 @@ var require_background_scheduled_task = __commonJS({
29877
29877
  return null;
29878
29878
  }
29879
29879
  start() {
29880
- return new Promise((resolve10, reject) => {
29880
+ return new Promise((resolve11, reject) => {
29881
29881
  if (this.forkProcess) {
29882
- return resolve10(void 0);
29882
+ return resolve11(void 0);
29883
29883
  }
29884
29884
  const timeout = setTimeout(() => {
29885
29885
  reject(new Error("Start operation timed out"));
@@ -29918,7 +29918,7 @@ var require_background_scheduled_task = __commonJS({
29918
29918
  this.once("task:started", () => {
29919
29919
  this.stateMachine.changeState("idle");
29920
29920
  clearTimeout(timeout);
29921
- resolve10(void 0);
29921
+ resolve11(void 0);
29922
29922
  });
29923
29923
  this.forkProcess.send({
29924
29924
  command: "task:start",
@@ -29932,9 +29932,9 @@ var require_background_scheduled_task = __commonJS({
29932
29932
  });
29933
29933
  }
29934
29934
  stop() {
29935
- return new Promise((resolve10, reject) => {
29935
+ return new Promise((resolve11, reject) => {
29936
29936
  if (!this.forkProcess) {
29937
- return resolve10(void 0);
29937
+ return resolve11(void 0);
29938
29938
  }
29939
29939
  const timeoutId = setTimeout(() => {
29940
29940
  clearTimeout(timeoutId);
@@ -29944,7 +29944,7 @@ var require_background_scheduled_task = __commonJS({
29944
29944
  clearTimeout(timeoutId);
29945
29945
  this.off("task:stopped", onStopped);
29946
29946
  this.forkProcess = void 0;
29947
- resolve10(void 0);
29947
+ resolve11(void 0);
29948
29948
  };
29949
29949
  const onStopped = () => {
29950
29950
  cleanupAndResolve();
@@ -29959,9 +29959,9 @@ var require_background_scheduled_task = __commonJS({
29959
29959
  return this.stateMachine.state;
29960
29960
  }
29961
29961
  destroy() {
29962
- return new Promise((resolve10, reject) => {
29962
+ return new Promise((resolve11, reject) => {
29963
29963
  if (!this.forkProcess) {
29964
- return resolve10(void 0);
29964
+ return resolve11(void 0);
29965
29965
  }
29966
29966
  const timeoutId = setTimeout(() => {
29967
29967
  clearTimeout(timeoutId);
@@ -29970,7 +29970,7 @@ var require_background_scheduled_task = __commonJS({
29970
29970
  const onDestroy = () => {
29971
29971
  clearTimeout(timeoutId);
29972
29972
  this.off("task:destroyed", onDestroy);
29973
- resolve10(void 0);
29973
+ resolve11(void 0);
29974
29974
  };
29975
29975
  this.once("task:destroyed", onDestroy);
29976
29976
  this.forkProcess.send({
@@ -29979,7 +29979,7 @@ var require_background_scheduled_task = __commonJS({
29979
29979
  });
29980
29980
  }
29981
29981
  execute() {
29982
- return new Promise((resolve10, reject) => {
29982
+ return new Promise((resolve11, reject) => {
29983
29983
  if (!this.forkProcess) {
29984
29984
  return reject(new Error("Cannot execute background task because it hasn't been started yet. Please initialize the task using the start() method before attempting to execute it."));
29985
29985
  }
@@ -29994,7 +29994,7 @@ var require_background_scheduled_task = __commonJS({
29994
29994
  };
29995
29995
  const onFinished = (context) => {
29996
29996
  cleanupListeners();
29997
- resolve10(context.execution?.result);
29997
+ resolve11(context.execution?.result);
29998
29998
  };
29999
29999
  const onFail = (context) => {
30000
30000
  cleanupListeners();
@@ -30127,11 +30127,11 @@ var require_package3 = __commonJS({
30127
30127
  "package.json"(exports2, module2) {
30128
30128
  module2.exports = {
30129
30129
  packageManager: "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39",
30130
- name: "dwclaw",
30131
- version: "1.0.0",
30130
+ name: "dwclaw-cli",
30131
+ version: "1.2.0",
30132
30132
  description: "AI Agent \u7BA1\u7406\u6846\u67B6 - \u652F\u6301\u98DE\u4E66 Channel\u3001\u56E2\u961F\u534F\u4F5C\u3001\u5B9A\u65F6\u4EFB\u52A1\u3001Web \u7BA1\u7406\u754C\u9762",
30133
30133
  bin: {
30134
- dwclaw: "./dist/main.js"
30134
+ duclaw: "./dist/main.js"
30135
30135
  },
30136
30136
  files: [
30137
30137
  "dist/",
@@ -30140,7 +30140,7 @@ var require_package3 = __commonJS({
30140
30140
  "docker/Dockerfile",
30141
30141
  "docker/docker-compose.yml",
30142
30142
  "docker/entrypoint.sh",
30143
- "docker/agent-template.json",
30143
+ "docker/duclaw.json",
30144
30144
  "docker/.env"
30145
30145
  ],
30146
30146
  scripts: {
@@ -30181,10 +30181,180 @@ var require_package3 = __commonJS({
30181
30181
  }
30182
30182
  });
30183
30183
 
30184
- // src/config/LoadEnv.ts
30185
- var import_dotenv = __toESM(require_main());
30184
+ // src/cli/index.ts
30186
30185
  var import_fs = require("fs");
30187
30186
  var import_path = require("path");
30187
+ var import_os = require("os");
30188
+ var DUCLAW_HOME = (0, import_path.join)((0, import_os.homedir)(), ".duclaw");
30189
+ function handleCliCommand(args) {
30190
+ const command = args[0];
30191
+ switch (command) {
30192
+ case "init":
30193
+ return handleInit(args);
30194
+ case "start":
30195
+ return handleStart();
30196
+ case "--help":
30197
+ case "-h":
30198
+ printHelp();
30199
+ return 0;
30200
+ case "--version":
30201
+ case "-v":
30202
+ printVersion();
30203
+ return 0;
30204
+ default:
30205
+ return checkAndGuideInit();
30206
+ }
30207
+ }
30208
+ function handleInit(args) {
30209
+ const targetDir = args[1] ? (0, import_path.resolve)(args[1]) : process.cwd();
30210
+ console.log(`
30211
+ duclaw \u521D\u59CB\u5316
30212
+ `);
30213
+ console.log(` \u76EE\u6807\u76EE\u5F55: ${targetDir}
30214
+ `);
30215
+ if (!(0, import_fs.existsSync)(targetDir)) {
30216
+ (0, import_fs.mkdirSync)(targetDir, { recursive: true });
30217
+ }
30218
+ const configPath = (0, import_path.resolve)(targetDir, "duclaw.json");
30219
+ if ((0, import_fs.existsSync)(configPath)) {
30220
+ console.log(` [\u8DF3\u8FC7] duclaw.json \u5DF2\u5B58\u5728`);
30221
+ } else {
30222
+ const configTemplate = getDuclawTemplate();
30223
+ (0, import_fs.writeFileSync)(configPath, JSON.stringify(configTemplate, null, 4), "utf-8");
30224
+ console.log(` [\u521B\u5EFA] duclaw.json`);
30225
+ }
30226
+ const envPath = (0, import_path.resolve)(targetDir, ".env");
30227
+ if ((0, import_fs.existsSync)(envPath)) {
30228
+ console.log(` [\u8DF3\u8FC7] .env \u5DF2\u5B58\u5728`);
30229
+ } else {
30230
+ const envTemplate = getEnvTemplate();
30231
+ (0, import_fs.writeFileSync)(envPath, envTemplate, "utf-8");
30232
+ console.log(` [\u521B\u5EFA] .env`);
30233
+ }
30234
+ const skillsDir = (0, import_path.resolve)(targetDir, "skills");
30235
+ if (!(0, import_fs.existsSync)(skillsDir)) {
30236
+ (0, import_fs.mkdirSync)(skillsDir, { recursive: true });
30237
+ console.log(` [\u521B\u5EFA] skills/ \u76EE\u5F55`);
30238
+ } else {
30239
+ console.log(` [\u8DF3\u8FC7] skills/ \u76EE\u5F55\u5DF2\u5B58\u5728`);
30240
+ }
30241
+ const cronDir = (0, import_path.join)(DUCLAW_HOME, "cron");
30242
+ if (!(0, import_fs.existsSync)(cronDir)) {
30243
+ (0, import_fs.mkdirSync)(cronDir, { recursive: true });
30244
+ console.log(` [\u521B\u5EFA] ~/.duclaw/cron/ \u76EE\u5F55`);
30245
+ }
30246
+ const jobsPath = (0, import_path.join)(cronDir, "jobs.json");
30247
+ if (!(0, import_fs.existsSync)(jobsPath)) {
30248
+ (0, import_fs.writeFileSync)(jobsPath, "[]", "utf-8");
30249
+ console.log(` [\u521B\u5EFA] ~/.duclaw/cron/jobs.json`);
30250
+ }
30251
+ console.log(`
30252
+ \u521D\u59CB\u5316\u5B8C\u6210\uFF01\u63A5\u4E0B\u6765\uFF1A`);
30253
+ console.log(` 1. \u7F16\u8F91 ${configPath} \u914D\u7F6E\u4F60\u7684 Channel\uFF08\u5982\u98DE\u4E66 appId/appSecret\uFF09`);
30254
+ console.log(` 2. \u7F16\u8F91 ${envPath} \u914D\u7F6E Anthropic \u517C\u5BB9\u7684 LLM API\uFF1A`);
30255
+ console.log(` - ANTHROPIC_BASE_URL \uFF08API \u5730\u5740\uFF09`);
30256
+ console.log(` - ANTHROPIC_AUTH_TOKEN \uFF08API Key\uFF09`);
30257
+ console.log(` - ANTHROPIC_MODEL \uFF08\u6A21\u578B\u540D\u79F0\uFF09`);
30258
+ console.log(` - REDIS_URL \uFF08Redis \u8FDE\u63A5\u5730\u5740\uFF09`);
30259
+ console.log(` 3. \u8FD0\u884C duclaw start \u542F\u52A8\u670D\u52A1
30260
+ `);
30261
+ return 0;
30262
+ }
30263
+ function handleStart() {
30264
+ return void 0;
30265
+ }
30266
+ function checkAndGuideInit() {
30267
+ const cwd = process.cwd();
30268
+ const configPath = (0, import_path.resolve)(cwd, "duclaw.json");
30269
+ if (!(0, import_fs.existsSync)(configPath)) {
30270
+ console.log(`
30271
+ \u672A\u627E\u5230 duclaw.json \u914D\u7F6E\u6587\u4EF6\u3002`);
30272
+ console.log(`
30273
+ \u8BF7\u5148\u8FD0\u884C\u521D\u59CB\u5316\u547D\u4EE4\uFF1A`);
30274
+ console.log(` duclaw init
30275
+ `);
30276
+ return 1;
30277
+ }
30278
+ return void 0;
30279
+ }
30280
+ function printHelp() {
30281
+ console.log(`
30282
+ duclaw - AI Agent \u7BA1\u7406\u6846\u67B6
30283
+
30284
+ \u547D\u4EE4:
30285
+ init [\u76EE\u5F55] \u521D\u59CB\u5316\u9879\u76EE\uFF08\u751F\u6210 duclaw.json \u548C .env \u6A21\u677F\uFF09
30286
+ start \u542F\u52A8\u670D\u52A1\uFF08\u9ED8\u8BA4\u547D\u4EE4\uFF09
30287
+ --help, -h \u663E\u793A\u5E2E\u52A9
30288
+ --version, -v \u663E\u793A\u7248\u672C
30289
+
30290
+ \u4F7F\u7528\u793A\u4F8B:
30291
+ duclaw init # \u5728\u5F53\u524D\u76EE\u5F55\u521D\u59CB\u5316
30292
+ duclaw init ./my-agent # \u5728\u6307\u5B9A\u76EE\u5F55\u521D\u59CB\u5316
30293
+ duclaw start # \u542F\u52A8\u670D\u52A1
30294
+ duclaw # \u7B49\u540C\u4E8E start
30295
+
30296
+ \u5FEB\u901F\u5F00\u59CB:
30297
+ 1. duclaw init
30298
+ 2. \u7F16\u8F91 duclaw.json \u914D\u7F6E Channel
30299
+ 3. \u7F16\u8F91 .env \u914D\u7F6E Anthropic API Key \u548C Redis
30300
+ 4. duclaw start
30301
+ `);
30302
+ }
30303
+ function printVersion() {
30304
+ try {
30305
+ const pkgRoot = (0, import_path.resolve)(__dirname_m, "..", "..");
30306
+ const pkgContent = (0, import_fs.readFileSync)((0, import_path.resolve)(pkgRoot, "package.json"), "utf-8");
30307
+ const pkg = JSON.parse(pkgContent);
30308
+ console.log(`duclaw v${pkg.version}`);
30309
+ } catch {
30310
+ console.log(`duclaw (version unknown)`);
30311
+ }
30312
+ }
30313
+ function getDuclawTemplate() {
30314
+ return {
30315
+ channels: {
30316
+ feishu: {
30317
+ enabled: false,
30318
+ appId: "YOUR_FEISHU_APP_ID",
30319
+ appSecret: "YOUR_FEISHU_APP_SECRET"
30320
+ }
30321
+ }
30322
+ };
30323
+ }
30324
+ function getEnvTemplate() {
30325
+ return `# ====== LLM \u914D\u7F6E\uFF08\u5FC5\u586B\uFF09======
30326
+ # Anthropic \u517C\u5BB9\u7684 API \u914D\u7F6E
30327
+ export ANTHROPIC_BASE_URL="https://api.anthropic.com"
30328
+ export ANTHROPIC_AUTH_TOKEN="your-api-key-here"
30329
+ export ANTHROPIC_MODEL="claude-sonnet-4-20250514"
30330
+ # \u5982\u679C API \u4F7F\u7528 Bearer Token \u98CE\u683C\uFF0C\u53D6\u6D88\u4E0B\u9762\u7684\u6CE8\u91CA
30331
+ # export ANTHROPIC_AUTH_STYLE="bearer"
30332
+
30333
+ # ====== Redis \u914D\u7F6E\uFF08\u5FC5\u586B\uFF09======
30334
+ export REDIS_URL="redis://localhost:6379"
30335
+
30336
+ # ====== \u963F\u91CC\u4E91 OSS \u914D\u7F6E\uFF08\u6309\u9700\u586B\u5199\uFF0C\u7528\u4E8E\u6587\u4EF6\u5B58\u50A8\uFF09======
30337
+ # export OSS_ENDPOINT="oss-cn-shenzhen"
30338
+ # export OSS_BUCKET="your-bucket-name"
30339
+ # export OSS_ACCESS_KEY_ID="your-access-key-id"
30340
+ # export OSS_ACCESS_KEY_SECRET="your-access-key-secret"
30341
+
30342
+ # ====== \u8DEF\u5F84\u914D\u7F6E\uFF08\u9ED8\u8BA4 ~/.duclaw/\uFF0C\u901A\u5E38\u65E0\u9700\u4FEE\u6539\uFF09======
30343
+ # export JOB_PATH="~/.duclaw/cron/jobs.json"
30344
+ # export JOB_HISTORY_DIR="~/.duclaw/cron"
30345
+ # export APP_TEMP_DIR="~/.duclaw/data"
30346
+
30347
+ # ====== \u56FE\u7247\u7406\u89E3\u5DE5\u5177 LLM \u914D\u7F6E\uFF08\u6309\u9700\u586B\u5199\uFF09======
30348
+ # export TOOL_IMAGE_ANTHROPIC_AUTH_TOKEN="your-api-key"
30349
+ # export TOOL_IMAGE_ANTHROPIC_BASE_URL="https://api.anthropic.com"
30350
+ # export TOOL_IMAGE_ANTHROPIC_MODEL="claude-sonnet-4-20250514"
30351
+ `;
30352
+ }
30353
+
30354
+ // src/config/LoadEnv.ts
30355
+ var import_dotenv = __toESM(require_main());
30356
+ var import_fs2 = require("fs");
30357
+ var import_path2 = require("path");
30188
30358
  var loadEnv = () => {
30189
30359
  const nodeEnv = process.env.NODE_ENV || "development";
30190
30360
  const isProd = nodeEnv === "production";
@@ -30197,7 +30367,7 @@ var loadEnv = () => {
30197
30367
  // 环境特定(如 .env.development)
30198
30368
  `.env.${nodeEnv}.local`
30199
30369
  // 本地环境特定(最高优先级)
30200
- ].map((file) => (0, import_path.resolve)(process.cwd(), file)).filter((file) => (0, import_fs.existsSync)(file));
30370
+ ].map((file) => (0, import_path2.resolve)(process.cwd(), file)).filter((file) => (0, import_fs2.existsSync)(file));
30201
30371
  if (isProd) {
30202
30372
  console.log("[loadEnv] Production: \u4F18\u5148\u4F7F\u7528\u7CFB\u7EDF\u73AF\u5883\u53D8\u91CF");
30203
30373
  envFiles.forEach((file) => {
@@ -30212,14 +30382,14 @@ var loadEnv = () => {
30212
30382
  };
30213
30383
 
30214
30384
  // src/config/LoadConfig.ts
30215
- var import_fs2 = require("fs");
30216
- var import_path2 = require("path");
30217
- var loadConfig = (filename = "agent-template.json", currentDir = __dirname_m) => {
30218
- const filePath = (0, import_path2.join)(currentDir, filename);
30219
- if ((0, import_fs2.existsSync)(filePath)) {
30220
- return JSON.parse((0, import_fs2.readFileSync)(filePath, "utf8"));
30385
+ var import_fs3 = require("fs");
30386
+ var import_path3 = require("path");
30387
+ var loadConfig = (filename = "duclaw.json", currentDir = process.cwd()) => {
30388
+ const filePath = (0, import_path3.join)(currentDir, filename);
30389
+ if ((0, import_fs3.existsSync)(filePath)) {
30390
+ return JSON.parse((0, import_fs3.readFileSync)(filePath, "utf8"));
30221
30391
  }
30222
- const parentDir = (0, import_path2.dirname)(currentDir);
30392
+ const parentDir = (0, import_path3.dirname)(currentDir);
30223
30393
  if (parentDir === currentDir) {
30224
30394
  throw new Error(`Config file "${filename}" not found`);
30225
30395
  }
@@ -30506,7 +30676,7 @@ var safeJSON = (text2) => {
30506
30676
  };
30507
30677
 
30508
30678
  // node_modules/.pnpm/@anthropic-ai+sdk@0.78.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/internal/utils/sleep.mjs
30509
- var sleep = (ms) => new Promise((resolve10) => setTimeout(resolve10, ms));
30679
+ var sleep = (ms) => new Promise((resolve11) => setTimeout(resolve11, ms));
30510
30680
 
30511
30681
  // node_modules/.pnpm/@anthropic-ai+sdk@0.78.0_zod@4.3.6/node_modules/@anthropic-ai/sdk/version.mjs
30512
30682
  var VERSION = "0.78.0";
@@ -31205,8 +31375,8 @@ function addRequestID(value, response) {
31205
31375
  var _APIPromise_client;
31206
31376
  var APIPromise = class _APIPromise extends Promise {
31207
31377
  constructor(client2, responsePromise, parseResponse = defaultParseResponse) {
31208
- super((resolve10) => {
31209
- resolve10(null);
31378
+ super((resolve11) => {
31379
+ resolve11(null);
31210
31380
  });
31211
31381
  this.responsePromise = responsePromise;
31212
31382
  this.parseResponse = parseResponse;
@@ -32243,12 +32413,12 @@ var BetaMessageStream = class _BetaMessageStream {
32243
32413
  }
32244
32414
  return this._emit("error", new AnthropicError(String(error)));
32245
32415
  });
32246
- __classPrivateFieldSet(this, _BetaMessageStream_connectedPromise, new Promise((resolve10, reject) => {
32247
- __classPrivateFieldSet(this, _BetaMessageStream_resolveConnectedPromise, resolve10, "f");
32416
+ __classPrivateFieldSet(this, _BetaMessageStream_connectedPromise, new Promise((resolve11, reject) => {
32417
+ __classPrivateFieldSet(this, _BetaMessageStream_resolveConnectedPromise, resolve11, "f");
32248
32418
  __classPrivateFieldSet(this, _BetaMessageStream_rejectConnectedPromise, reject, "f");
32249
32419
  }), "f");
32250
- __classPrivateFieldSet(this, _BetaMessageStream_endPromise, new Promise((resolve10, reject) => {
32251
- __classPrivateFieldSet(this, _BetaMessageStream_resolveEndPromise, resolve10, "f");
32420
+ __classPrivateFieldSet(this, _BetaMessageStream_endPromise, new Promise((resolve11, reject) => {
32421
+ __classPrivateFieldSet(this, _BetaMessageStream_resolveEndPromise, resolve11, "f");
32252
32422
  __classPrivateFieldSet(this, _BetaMessageStream_rejectEndPromise, reject, "f");
32253
32423
  }), "f");
32254
32424
  __classPrivateFieldGet(this, _BetaMessageStream_connectedPromise, "f").catch(() => {
@@ -32418,11 +32588,11 @@ var BetaMessageStream = class _BetaMessageStream {
32418
32588
  * const message = await stream.emitted('message') // rejects if the stream errors
32419
32589
  */
32420
32590
  emitted(event) {
32421
- return new Promise((resolve10, reject) => {
32591
+ return new Promise((resolve11, reject) => {
32422
32592
  __classPrivateFieldSet(this, _BetaMessageStream_catchingPromiseCreated, true, "f");
32423
32593
  if (event !== "error")
32424
32594
  this.once("error", reject);
32425
- this.once(event, resolve10);
32595
+ this.once(event, resolve11);
32426
32596
  });
32427
32597
  }
32428
32598
  async done() {
@@ -32765,7 +32935,7 @@ var BetaMessageStream = class _BetaMessageStream {
32765
32935
  if (done) {
32766
32936
  return { value: void 0, done: true };
32767
32937
  }
32768
- return new Promise((resolve10, reject) => readQueue.push({ resolve: resolve10, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: void 0, done: true });
32938
+ return new Promise((resolve11, reject) => readQueue.push({ resolve: resolve11, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: void 0, done: true });
32769
32939
  }
32770
32940
  const chunk = pushQueue.shift();
32771
32941
  return { value: chunk, done: false };
@@ -32837,13 +33007,13 @@ var _BetaToolRunner_iterationCount;
32837
33007
  var _BetaToolRunner_checkAndCompact;
32838
33008
  var _BetaToolRunner_generateToolResponse;
32839
33009
  function promiseWithResolvers() {
32840
- let resolve10;
33010
+ let resolve11;
32841
33011
  let reject;
32842
33012
  const promise = new Promise((res, rej) => {
32843
- resolve10 = res;
33013
+ resolve11 = res;
32844
33014
  reject = rej;
32845
33015
  });
32846
- return { promise, resolve: resolve10, reject };
33016
+ return { promise, resolve: resolve11, reject };
32847
33017
  }
32848
33018
  var BetaToolRunner = class {
32849
33019
  constructor(client2, params, options) {
@@ -33861,12 +34031,12 @@ var MessageStream = class _MessageStream {
33861
34031
  }
33862
34032
  return this._emit("error", new AnthropicError(String(error)));
33863
34033
  });
33864
- __classPrivateFieldSet(this, _MessageStream_connectedPromise, new Promise((resolve10, reject) => {
33865
- __classPrivateFieldSet(this, _MessageStream_resolveConnectedPromise, resolve10, "f");
34034
+ __classPrivateFieldSet(this, _MessageStream_connectedPromise, new Promise((resolve11, reject) => {
34035
+ __classPrivateFieldSet(this, _MessageStream_resolveConnectedPromise, resolve11, "f");
33866
34036
  __classPrivateFieldSet(this, _MessageStream_rejectConnectedPromise, reject, "f");
33867
34037
  }), "f");
33868
- __classPrivateFieldSet(this, _MessageStream_endPromise, new Promise((resolve10, reject) => {
33869
- __classPrivateFieldSet(this, _MessageStream_resolveEndPromise, resolve10, "f");
34038
+ __classPrivateFieldSet(this, _MessageStream_endPromise, new Promise((resolve11, reject) => {
34039
+ __classPrivateFieldSet(this, _MessageStream_resolveEndPromise, resolve11, "f");
33870
34040
  __classPrivateFieldSet(this, _MessageStream_rejectEndPromise, reject, "f");
33871
34041
  }), "f");
33872
34042
  __classPrivateFieldGet(this, _MessageStream_connectedPromise, "f").catch(() => {
@@ -34036,11 +34206,11 @@ var MessageStream = class _MessageStream {
34036
34206
  * const message = await stream.emitted('message') // rejects if the stream errors
34037
34207
  */
34038
34208
  emitted(event) {
34039
- return new Promise((resolve10, reject) => {
34209
+ return new Promise((resolve11, reject) => {
34040
34210
  __classPrivateFieldSet(this, _MessageStream_catchingPromiseCreated, true, "f");
34041
34211
  if (event !== "error")
34042
34212
  this.once("error", reject);
34043
- this.once(event, resolve10);
34213
+ this.once(event, resolve11);
34044
34214
  });
34045
34215
  }
34046
34216
  async done() {
@@ -34358,7 +34528,7 @@ var MessageStream = class _MessageStream {
34358
34528
  if (done) {
34359
34529
  return { value: void 0, done: true };
34360
34530
  }
34361
- return new Promise((resolve10, reject) => readQueue.push({ resolve: resolve10, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: void 0, done: true });
34531
+ return new Promise((resolve11, reject) => readQueue.push({ resolve: resolve11, reject })).then((chunk2) => chunk2 ? { value: chunk2, done: false } : { value: void 0, done: true });
34362
34532
  }
34363
34533
  const chunk = pushQueue.shift();
34364
34534
  return { value: chunk, done: false };
@@ -35531,15 +35701,15 @@ var dateTool = {
35531
35701
  var import_dayjs = __toESM(require_dayjs_min());
35532
35702
  var import_utc = __toESM(require_utc());
35533
35703
  var import_timezone = __toESM(require_timezone());
35534
- var import_fs3 = require("fs");
35535
- var import_path10 = __toESM(require("path"));
35704
+ var import_fs4 = require("fs");
35705
+ var import_path11 = __toESM(require("path"));
35536
35706
  import_dayjs.default.extend(import_utc.default);
35537
35707
  import_dayjs.default.extend(import_timezone.default);
35538
35708
  var getGoalDir = () => {
35539
- return import_path10.default.join(process.cwd(), ".tasks");
35709
+ return import_path11.default.join(process.cwd(), ".tasks");
35540
35710
  };
35541
35711
  var getGoalPath = (goalId) => {
35542
- return import_path10.default.join(getGoalDir(), `${goalId}.json`);
35712
+ return import_path11.default.join(getGoalDir(), `${goalId}.json`);
35543
35713
  };
35544
35714
  var createGoal = (subject, description) => {
35545
35715
  const goalId = generateId(subject);
@@ -35552,7 +35722,7 @@ var createGoal = (subject, description) => {
35552
35722
  createdAt: (0, import_dayjs.default)().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss"),
35553
35723
  updateAt: (0, import_dayjs.default)().tz("Asia/Shanghai").format("YYYY-MM-DD HH:mm:ss")
35554
35724
  };
35555
- (0, import_fs3.writeFileSync)(`${getGoalPath(goalId)}`, JSON.stringify(goal, null, ` `), `utf-8`);
35725
+ (0, import_fs4.writeFileSync)(`${getGoalPath(goalId)}`, JSON.stringify(goal, null, ` `), `utf-8`);
35556
35726
  return goal;
35557
35727
  };
35558
35728
  var getGoalById = (id) => {
@@ -35567,11 +35737,11 @@ var getGoalBySubject = (subject) => {
35567
35737
  };
35568
35738
  var listGoal = () => {
35569
35739
  const goalDir = getGoalDir();
35570
- const files = (0, import_fs3.readdirSync)(goalDir);
35740
+ const files = (0, import_fs4.readdirSync)(goalDir);
35571
35741
  let goals = [];
35572
35742
  for (let file of files) {
35573
35743
  if (file.endsWith(`.json`)) {
35574
- const text2 = (0, import_fs3.readFileSync)(import_path10.default.join(goalDir, file), `utf-8`);
35744
+ const text2 = (0, import_fs4.readFileSync)(import_path11.default.join(goalDir, file), `utf-8`);
35575
35745
  const goal = JSON.parse(text2);
35576
35746
  goals.push(goal);
35577
35747
  }
@@ -35586,13 +35756,13 @@ var updateGoal = (id, goal) => {
35586
35756
  id
35587
35757
  // 确保 id 不被覆盖
35588
35758
  };
35589
- (0, import_fs3.writeFileSync)(getGoalPath(id), JSON.stringify(merged, null, " "), "utf-8");
35759
+ (0, import_fs4.writeFileSync)(getGoalPath(id), JSON.stringify(merged, null, " "), "utf-8");
35590
35760
  return { ...merged };
35591
35761
  };
35592
35762
  var deleteGoal = (id) => {
35593
35763
  const goalPath = getGoalPath(id);
35594
- if (!(0, import_fs3.existsSync)(goalPath)) return false;
35595
- (0, import_fs3.unlinkSync)(goalPath);
35764
+ if (!(0, import_fs4.existsSync)(goalPath)) return false;
35765
+ (0, import_fs4.unlinkSync)(goalPath);
35596
35766
  return true;
35597
35767
  };
35598
35768
  var generateId = (subject) => {
@@ -37572,29 +37742,29 @@ var sendMessage = {
37572
37742
  };
37573
37743
 
37574
37744
  // src/cron/jobs.ts
37575
- var import_fs4 = require("fs");
37745
+ var import_fs5 = require("fs");
37576
37746
  var import_crypto3 = require("crypto");
37577
- var import_path11 = __toESM(require("path"));
37747
+ var import_path12 = __toESM(require("path"));
37748
+ var import_os2 = require("os");
37749
+ var DUCLAW_HOME2 = import_path12.default.join((0, import_os2.homedir)(), ".duclaw");
37578
37750
  var getJobPath = () => {
37579
- return process.env.JOB_PATH || `/Users/duzicong/code/duzicong/agent-template-ts/.claude/cron/jobs.json`;
37751
+ return process.env.JOB_PATH || import_path12.default.join(DUCLAW_HOME2, "cron", "jobs.json");
37580
37752
  };
37581
37753
  var getJobHistoryPath = (date, title) => {
37582
- if (process.env.JOB_HISTORY_DIR) {
37583
- return import_path11.default.join(process.env.JOB_HISTORY_DIR, date, title);
37584
- }
37585
- return `/Users/duzicong/code/duzicong/agent-template-ts/cron/${date}/${title}`;
37754
+ const historyDir = process.env.JOB_HISTORY_DIR || import_path12.default.join(DUCLAW_HOME2, "cron");
37755
+ return import_path12.default.join(historyDir, date, title);
37586
37756
  };
37587
37757
  var createJob = (title, description, syntax, userRequest) => {
37588
37758
  const jsonsPath = getJobPath();
37589
- if (!(0, import_fs4.existsSync)(jsonsPath)) {
37759
+ if (!(0, import_fs5.existsSync)(jsonsPath)) {
37590
37760
  const content = `{
37591
37761
  "jobs": [
37592
37762
 
37593
37763
  ]
37594
37764
  }`;
37595
- (0, import_fs4.writeFileSync)(jsonsPath, content, `utf-8`);
37765
+ (0, import_fs5.writeFileSync)(jsonsPath, content, `utf-8`);
37596
37766
  }
37597
- const text2 = (0, import_fs4.readFileSync)(getJobPath(), `utf-8`);
37767
+ const text2 = (0, import_fs5.readFileSync)(getJobPath(), `utf-8`);
37598
37768
  const obj = JSON.parse(text2);
37599
37769
  let jobs = obj.jobs || [];
37600
37770
  const createJob2 = {
@@ -37615,7 +37785,7 @@ var createJob = (title, description, syntax, userRequest) => {
37615
37785
  ...jobs,
37616
37786
  createJob2
37617
37787
  ];
37618
- (0, import_fs4.writeFileSync)(getJobPath(), JSON.stringify({ jobs }, null, " "), `utf-8`);
37788
+ (0, import_fs5.writeFileSync)(getJobPath(), JSON.stringify({ jobs }, null, " "), `utf-8`);
37619
37789
  return { ...createJob2 };
37620
37790
  };
37621
37791
  var updateJob = (id, syntax, title, description) => {
@@ -37627,11 +37797,11 @@ var updateJob = (id, syntax, title, description) => {
37627
37797
  job.schedule.syntax = syntax;
37628
37798
  job.title = title;
37629
37799
  job.description = description;
37630
- (0, import_fs4.writeFileSync)(getJobPath(), JSON.stringify(jobs, null, " "));
37800
+ (0, import_fs5.writeFileSync)(getJobPath(), JSON.stringify(jobs, null, " "));
37631
37801
  return { ...job };
37632
37802
  };
37633
37803
  var listJobs = () => {
37634
- const text2 = (0, import_fs4.readFileSync)(getJobPath(), `utf-8`);
37804
+ const text2 = (0, import_fs5.readFileSync)(getJobPath(), `utf-8`);
37635
37805
  if (!text2) {
37636
37806
  return [];
37637
37807
  }
@@ -37641,7 +37811,7 @@ var listJobs = () => {
37641
37811
  };
37642
37812
  var deleteJob = (id, title) => {
37643
37813
  const jobPath = getJobPath();
37644
- const text2 = (0, import_fs4.readFileSync)(jobPath, `utf-8`);
37814
+ const text2 = (0, import_fs5.readFileSync)(jobPath, `utf-8`);
37645
37815
  const obj = JSON.parse(text2);
37646
37816
  let jobs = obj.jobs || [];
37647
37817
  let isJobExist = false;
@@ -37663,7 +37833,7 @@ var deleteJob = (id, title) => {
37663
37833
  ;
37664
37834
  jobs = jobs.filter((j) => j.title !== title);
37665
37835
  }
37666
- (0, import_fs4.writeFileSync)(jobPath, JSON.stringify({ jobs }, null, " "), `utf-8`);
37836
+ (0, import_fs5.writeFileSync)(jobPath, JSON.stringify({ jobs }, null, " "), `utf-8`);
37667
37837
  if (targetJob) {
37668
37838
  return { ...targetJob };
37669
37839
  }
@@ -37681,7 +37851,7 @@ var getJobExecuteHistory = (id, title) => {
37681
37851
  const lastRunTime = "2026-03-17T21:00:28";
37682
37852
  const dateStr = lastRunTime.split("T")[0];
37683
37853
  const historyFilePath = getJobHistoryPath(dateStr, findJob.title);
37684
- const text2 = (0, import_fs4.readFileSync)(historyFilePath, `utf-8`);
37854
+ const text2 = (0, import_fs5.readFileSync)(historyFilePath, `utf-8`);
37685
37855
  const list = JSON.parse(text2) || [];
37686
37856
  console.log(`[jobs] \u83B7\u53D6\u5B9A\u65F6\u4EFB\u52A1\u7684\u5386\u53F2\u6267\u884C\u6D88\u606F\uFF0C\u5F53\u524D\u6267\u884C\u5386\u53F2\u5728 ${historyFilePath}`);
37687
37857
  return list;
@@ -37767,7 +37937,7 @@ var cronDelete = {
37767
37937
  };
37768
37938
 
37769
37939
  // src/cron/cron.ts
37770
- var import_fs5 = require("fs");
37940
+ var import_fs6 = require("fs");
37771
37941
 
37772
37942
  // node_modules/.pnpm/chokidar@5.0.0/node_modules/chokidar/index.js
37773
37943
  var import_node_events = require("node:events");
@@ -38514,9 +38684,9 @@ var NodeFsHandler = class {
38514
38684
  if (this.fsw.closed) {
38515
38685
  return;
38516
38686
  }
38517
- const dirname7 = sp.dirname(file);
38687
+ const dirname8 = sp.dirname(file);
38518
38688
  const basename4 = sp.basename(file);
38519
- const parent = this.fsw._getWatchedDir(dirname7);
38689
+ const parent = this.fsw._getWatchedDir(dirname8);
38520
38690
  let prevStats = stats;
38521
38691
  if (parent.has(basename4))
38522
38692
  return;
@@ -38543,7 +38713,7 @@ var NodeFsHandler = class {
38543
38713
  prevStats = newStats2;
38544
38714
  }
38545
38715
  } catch (error) {
38546
- this.fsw._remove(dirname7, basename4);
38716
+ this.fsw._remove(dirname8, basename4);
38547
38717
  }
38548
38718
  } else if (parent.has(basename4)) {
38549
38719
  const at = newStats.atimeMs;
@@ -38640,7 +38810,7 @@ var NodeFsHandler = class {
38640
38810
  this._addToNodeFs(path9, initialAdd, wh, depth + 1);
38641
38811
  }
38642
38812
  }).on(EV.ERROR, this._boundHandleError);
38643
- return new Promise((resolve10, reject) => {
38813
+ return new Promise((resolve11, reject) => {
38644
38814
  if (!stream)
38645
38815
  return reject();
38646
38816
  stream.once(STR_END, () => {
@@ -38649,7 +38819,7 @@ var NodeFsHandler = class {
38649
38819
  return;
38650
38820
  }
38651
38821
  const wasThrottled = throttler ? throttler.clear() : false;
38652
- resolve10(void 0);
38822
+ resolve11(void 0);
38653
38823
  previous.getChildren().filter((item) => {
38654
38824
  return item !== directory && !current.has(item);
38655
38825
  }).forEach((item) => {
@@ -39590,14 +39760,14 @@ var loadAndScheduleJobs = () => {
39590
39760
  console.log(`[cron] \u5F53\u524D\u5171 ${scheduledTasks.size} \u4E2A\u6D3B\u8DC3\u4EFB\u52A1`);
39591
39761
  };
39592
39762
  var updateJobLastRunTime = (jobId) => {
39593
- const text2 = (0, import_fs5.readFileSync)(getJobPath(), `utf-8`);
39763
+ const text2 = (0, import_fs6.readFileSync)(getJobPath(), `utf-8`);
39594
39764
  const obj = JSON.parse(text2);
39595
39765
  const jobs = obj.jobs || [];
39596
39766
  const job = jobs.find((j) => j.id === jobId);
39597
39767
  if (job) {
39598
39768
  job.schedule.lastRunTime = (/* @__PURE__ */ new Date()).toLocaleString("sv-SE", { timeZone: "Asia/Shanghai" }).replace(" ", "T");
39599
39769
  suppressWatch = true;
39600
- (0, import_fs5.writeFileSync)(getJobPath(), JSON.stringify({ jobs }, null, " "), `utf-8`);
39770
+ (0, import_fs6.writeFileSync)(getJobPath(), JSON.stringify({ jobs }, null, " "), `utf-8`);
39601
39771
  }
39602
39772
  };
39603
39773
  var getCronTools = () => {
@@ -39722,13 +39892,13 @@ var saveResultToFile = (job, cronResp) => {
39722
39892
  const safeTitle = sanitizeTitle(job.title);
39723
39893
  const dirPath = `./cron/${yyyyMMdd}/${safeTitle}`;
39724
39894
  const filePath = `${dirPath}/history.json`;
39725
- if (!(0, import_fs5.existsSync)(dirPath)) {
39726
- (0, import_fs5.mkdirSync)(dirPath, { recursive: true });
39895
+ if (!(0, import_fs6.existsSync)(dirPath)) {
39896
+ (0, import_fs6.mkdirSync)(dirPath, { recursive: true });
39727
39897
  }
39728
39898
  let history = [];
39729
- if ((0, import_fs5.existsSync)(filePath)) {
39899
+ if ((0, import_fs6.existsSync)(filePath)) {
39730
39900
  try {
39731
- const content = (0, import_fs5.readFileSync)(filePath, "utf-8");
39901
+ const content = (0, import_fs6.readFileSync)(filePath, "utf-8");
39732
39902
  history = JSON.parse(content);
39733
39903
  } catch {
39734
39904
  history = [];
@@ -39738,7 +39908,7 @@ var saveResultToFile = (job, cronResp) => {
39738
39908
  timestamp: now.toLocaleString("sv-SE", { timeZone: "Asia/Shanghai" }).replace(" ", "T"),
39739
39909
  result: cronResp
39740
39910
  });
39741
- (0, import_fs5.writeFileSync)(filePath, JSON.stringify(history, null, " "), "utf-8");
39911
+ (0, import_fs6.writeFileSync)(filePath, JSON.stringify(history, null, " "), "utf-8");
39742
39912
  return filePath;
39743
39913
  };
39744
39914
 
@@ -39850,8 +40020,8 @@ var cronUpdate = {
39850
40020
  };
39851
40021
 
39852
40022
  // src/tools/tools/ImageUnderstand.ts
39853
- var import_fs6 = __toESM(require("fs"));
39854
- var import_path12 = __toESM(require("path"));
40023
+ var import_fs7 = __toESM(require("fs"));
40024
+ var import_path13 = __toESM(require("path"));
39855
40025
 
39856
40026
  // src/types/builders.ts
39857
40027
  var text = (text2) => ({
@@ -39906,7 +40076,7 @@ var guessMediaTypeFromHeader = (contentType) => {
39906
40076
  return null;
39907
40077
  };
39908
40078
  var guessMediaTypeFromExt = (filePath) => {
39909
- const ext = import_path12.default.extname(filePath).toLowerCase();
40079
+ const ext = import_path13.default.extname(filePath).toLowerCase();
39910
40080
  if (ext === ".jpg" || ext === ".jpeg") return "image/jpeg";
39911
40081
  if (ext === ".png") return "image/png";
39912
40082
  if (ext === ".gif") return "image/gif";
@@ -39926,9 +40096,9 @@ var resolveImageBlock = async (input) => {
39926
40096
  return imageBase64(base64Data, mediaType2);
39927
40097
  }
39928
40098
  if (input.startsWith("/") || input.startsWith(".") || /^[A-Za-z]:[\\/]/.test(input)) {
39929
- if (!import_fs6.default.existsSync(input)) throw new Error(`[ImageUnderstand] \u672C\u5730\u6587\u4EF6\u4E0D\u5B58\u5728: ${input}`);
40099
+ if (!import_fs7.default.existsSync(input)) throw new Error(`[ImageUnderstand] \u672C\u5730\u6587\u4EF6\u4E0D\u5B58\u5728: ${input}`);
39930
40100
  console.log(`[ImageUnderstand] \u8BFB\u53D6\u672C\u5730\u6587\u4EF6: ${input}`);
39931
- const buffer = import_fs6.default.readFileSync(input);
40101
+ const buffer = import_fs7.default.readFileSync(input);
39932
40102
  const base64Data = buffer.toString("base64");
39933
40103
  const mediaType2 = guessMediaTypeFromExt(input) ?? guessMediaTypeFromData(base64Data) ?? "image/png";
39934
40104
  console.log(`[ImageUnderstand] \u63A8\u65AD\u5A92\u4F53\u7C7B\u578B: ${mediaType2}`);
@@ -39986,45 +40156,45 @@ var imageUnderstand = {
39986
40156
  };
39987
40157
 
39988
40158
  // src/skill/SkillRegistry.ts
39989
- var import_fs7 = require("fs");
39990
- var import_os = require("os");
39991
- var import_path13 = __toESM(require("path"));
40159
+ var import_fs8 = require("fs");
40160
+ var import_os3 = require("os");
40161
+ var import_path14 = __toESM(require("path"));
39992
40162
  var getSkillPaths = () => {
39993
40163
  const paths = [];
39994
40164
  let currentDir = __dirname_m;
39995
40165
  let projectRoot = "";
39996
40166
  while (currentDir !== "/") {
39997
- const claudePath = (0, import_path13.join)(currentDir, ".claude");
39998
- if ((0, import_fs7.existsSync)(claudePath) && (0, import_fs7.statSync)(claudePath).isDirectory()) {
40167
+ const claudePath = (0, import_path14.join)(currentDir, ".claude");
40168
+ if ((0, import_fs8.existsSync)(claudePath) && (0, import_fs8.statSync)(claudePath).isDirectory()) {
39999
40169
  projectRoot = currentDir;
40000
- const skillsPath = (0, import_path13.join)(claudePath, "skills");
40001
- if ((0, import_fs7.existsSync)(skillsPath)) {
40170
+ const skillsPath = (0, import_path14.join)(claudePath, "skills");
40171
+ if ((0, import_fs8.existsSync)(skillsPath)) {
40002
40172
  paths.push(skillsPath);
40003
40173
  }
40004
40174
  break;
40005
40175
  }
40006
- const parentDir = (0, import_path13.dirname)(currentDir);
40176
+ const parentDir = (0, import_path14.dirname)(currentDir);
40007
40177
  if (parentDir === currentDir) break;
40008
40178
  currentDir = parentDir;
40009
40179
  }
40010
40180
  if (projectRoot) {
40011
- const rootSkillsPath = (0, import_path13.join)(projectRoot, "skills");
40012
- if ((0, import_fs7.existsSync)(rootSkillsPath) && (0, import_fs7.statSync)(rootSkillsPath).isDirectory()) {
40181
+ const rootSkillsPath = (0, import_path14.join)(projectRoot, "skills");
40182
+ if ((0, import_fs8.existsSync)(rootSkillsPath) && (0, import_fs8.statSync)(rootSkillsPath).isDirectory()) {
40013
40183
  paths.push(rootSkillsPath);
40014
40184
  }
40015
40185
  }
40016
- const globalSkillsPath = (0, import_path13.join)((0, import_os.homedir)(), ".agents", "skills");
40017
- if ((0, import_fs7.existsSync)(globalSkillsPath) && (0, import_fs7.statSync)(globalSkillsPath).isDirectory()) {
40186
+ const globalSkillsPath = (0, import_path14.join)((0, import_os3.homedir)(), ".agents", "skills");
40187
+ if ((0, import_fs8.existsSync)(globalSkillsPath) && (0, import_fs8.statSync)(globalSkillsPath).isDirectory()) {
40018
40188
  paths.push(globalSkillsPath);
40019
40189
  }
40020
40190
  return paths;
40021
40191
  };
40022
40192
  var getDirectories = (dirPath) => {
40023
- return (0, import_fs7.readdirSync)(dirPath).filter((name) => (0, import_fs7.statSync)((0, import_path13.join)(dirPath, name)).isDirectory());
40193
+ return (0, import_fs8.readdirSync)(dirPath).filter((name) => (0, import_fs8.statSync)((0, import_path14.join)(dirPath, name)).isDirectory());
40024
40194
  };
40025
40195
  var parseSkill = (mdPath, skillDir) => {
40026
- if (!(0, import_fs7.existsSync)(mdPath)) return null;
40027
- const raw2 = (0, import_fs7.readFileSync)(mdPath, "utf-8");
40196
+ if (!(0, import_fs8.existsSync)(mdPath)) return null;
40197
+ const raw2 = (0, import_fs8.readFileSync)(mdPath, "utf-8");
40028
40198
  let name = "";
40029
40199
  let description = "";
40030
40200
  let body = raw2;
@@ -40040,7 +40210,7 @@ var parseSkill = (mdPath, skillDir) => {
40040
40210
  }
40041
40211
  }
40042
40212
  if (!name) {
40043
- name = import_path13.default.basename(import_path13.default.dirname(mdPath));
40213
+ name = import_path14.default.basename(import_path14.default.dirname(mdPath));
40044
40214
  }
40045
40215
  if (!description && body) {
40046
40216
  description = body.split("\n")[0].replace(/^#+\s*/, "").trim();
@@ -40065,8 +40235,8 @@ var loadSkill = () => {
40065
40235
  for (const skillPath of skillPaths) {
40066
40236
  const dirs = getDirectories(skillPath);
40067
40237
  for (const skillName of dirs) {
40068
- const eachSkillPath = (0, import_path13.join)(skillPath, skillName);
40069
- const eachSkillMdPath = (0, import_path13.join)(eachSkillPath, "SKILL.md");
40238
+ const eachSkillPath = (0, import_path14.join)(skillPath, skillName);
40239
+ const eachSkillMdPath = (0, import_path14.join)(eachSkillPath, "SKILL.md");
40070
40240
  const skill = parseSkill(eachSkillMdPath, eachSkillPath);
40071
40241
  if (skill && !seen.has(skill.name)) {
40072
40242
  seen.add(skill.name);
@@ -40418,12 +40588,12 @@ var create_mailbox_table = () => {
40418
40588
  };
40419
40589
 
40420
40590
  // src/team/TeamMember.ts
40421
- var import_fs9 = require("fs");
40422
- var import_path15 = __toESM(require("path"));
40591
+ var import_fs10 = require("fs");
40592
+ var import_path16 = __toESM(require("path"));
40423
40593
 
40424
40594
  // src/team/Team.ts
40425
- var import_path14 = __toESM(require("path"));
40426
- var import_fs8 = require("fs");
40595
+ var import_path15 = __toESM(require("path"));
40596
+ var import_fs9 = require("fs");
40427
40597
  var getTeamBaseDir = () => {
40428
40598
  return `~/.duclaw/team`;
40429
40599
  };
@@ -40436,22 +40606,22 @@ var getTeamJsonPath = (teamName) => {
40436
40606
  var createTeam = (teamDefinition) => {
40437
40607
  if (!teamDefinition) throw new Error(`[createTeam] teamDefinition\u4E0D\u80FD\u4E3A\u7A7A`);
40438
40608
  const { id, name, goalId, teamMembers } = teamDefinition;
40439
- const teamPath = import_path14.default.join(getTeamWorkSpaceDir(name));
40440
- (0, import_fs8.mkdirSync)(teamPath, { recursive: true });
40441
- (0, import_fs8.writeFileSync)(`${teamPath}/team.json`, JSON.stringify(teamDefinition, null, " "), "utf-8");
40609
+ const teamPath = import_path15.default.join(getTeamWorkSpaceDir(name));
40610
+ (0, import_fs9.mkdirSync)(teamPath, { recursive: true });
40611
+ (0, import_fs9.writeFileSync)(`${teamPath}/team.json`, JSON.stringify(teamDefinition, null, " "), "utf-8");
40442
40612
  return teamDefinition;
40443
40613
  };
40444
40614
  var getTeam = (name) => {
40445
40615
  const teamJsonPath = getTeamJsonPath(name);
40446
- if (!(0, import_fs8.existsSync)(teamJsonPath)) return null;
40447
- const text2 = (0, import_fs8.readFileSync)(teamJsonPath, `utf-8`);
40616
+ if (!(0, import_fs9.existsSync)(teamJsonPath)) return null;
40617
+ const text2 = (0, import_fs9.readFileSync)(teamJsonPath, `utf-8`);
40448
40618
  const obj = JSON.parse(text2) || {};
40449
40619
  const team = obj;
40450
40620
  return team;
40451
40621
  };
40452
40622
  var listTeams = () => {
40453
40623
  const baseDir = getTeamBaseDir();
40454
- const teamnames = (0, import_fs8.readdirSync)(import_path14.default.join(baseDir, `workspace`));
40624
+ const teamnames = (0, import_fs9.readdirSync)(import_path15.default.join(baseDir, `workspace`));
40455
40625
  const teams = [];
40456
40626
  for (const teamname of teamnames) {
40457
40627
  const team = getTeam(teamname);
@@ -40468,10 +40638,10 @@ var getTeamById = (id) => {
40468
40638
  return team;
40469
40639
  };
40470
40640
  var deleteTeam = (name) => {
40471
- if (!(0, import_fs8.existsSync)(getTeamJsonPath(name))) {
40641
+ if (!(0, import_fs9.existsSync)(getTeamJsonPath(name))) {
40472
40642
  throw new Error(`[deleteTeam] \u4E0D\u5B58\u5728\u5BF9\u5E94\u7684\u56E2\u961F${name}\u7684team.json\u6587\u4EF6`);
40473
40643
  }
40474
- (0, import_fs8.rmSync)(getTeamJsonPath(name));
40644
+ (0, import_fs9.rmSync)(getTeamJsonPath(name));
40475
40645
  };
40476
40646
 
40477
40647
  // src/team/workspace/workspace.ts
@@ -40499,8 +40669,8 @@ var createTeamMember = (teamMemberDefinition) => {
40499
40669
  const { id, name, teamId, mailBoxId, workspaceId } = teamMemberDefinition;
40500
40670
  const team = getTeamById(teamMemberDefinition.teamId);
40501
40671
  if (!team) throw new Error(`[createTeamMember] \u627E\u4E0D\u5230\u5BF9\u5E94\u7684team: ${teamId}`);
40502
- const memberPath = import_path15.default.join(getTeamWorkSpaceDir(team.name), name);
40503
- (0, import_fs9.mkdirSync)(memberPath, { recursive: true });
40672
+ const memberPath = import_path16.default.join(getTeamWorkSpaceDir(team.name), name);
40673
+ (0, import_fs10.mkdirSync)(memberPath, { recursive: true });
40504
40674
  const workspace = {
40505
40675
  id: getWorkspaceId(team.name, teamMemberDefinition.name),
40506
40676
  teamName: team.name,
@@ -40512,12 +40682,12 @@ var createTeamMember = (teamMemberDefinition) => {
40512
40682
  team.teamMembers = [];
40513
40683
  }
40514
40684
  team.teamMembers.push(teamMemberDefinition);
40515
- (0, import_fs9.writeFileSync)(getTeamJsonPath(team.name), JSON.stringify(team, null, " "), "utf-8");
40685
+ (0, import_fs10.writeFileSync)(getTeamJsonPath(team.name), JSON.stringify(team, null, " "), "utf-8");
40516
40686
  return teamMemberDefinition;
40517
40687
  };
40518
40688
  var listTeamMember = (teamName) => {
40519
40689
  const teamJsonPath = getTeamJsonPath(teamName);
40520
- const text2 = (0, import_fs9.readFileSync)(teamJsonPath, `utf-8`);
40690
+ const text2 = (0, import_fs10.readFileSync)(teamJsonPath, `utf-8`);
40521
40691
  const team = JSON.parse(text2);
40522
40692
  if (!team) throw new Error(`[listTeamMember] \u627E\u4E0D\u5230\u5BF9\u5E94\u7684team: ${teamName}`);
40523
40693
  if (!team.teamMembers) return [];
@@ -40552,7 +40722,7 @@ var deleteTeamMemberById = (teamName, memberId) => {
40552
40722
  const workspaceId = team.teamMembers[memberIdx].workspaceId;
40553
40723
  let newTeamMember = team.teamMembers.filter((_, index) => index !== memberIdx);
40554
40724
  team.teamMembers = newTeamMember;
40555
- (0, import_fs9.writeFileSync)(getTeamJsonPath(teamName), JSON.stringify(team, null, ` `));
40725
+ (0, import_fs10.writeFileSync)(getTeamJsonPath(teamName), JSON.stringify(team, null, ` `));
40556
40726
  deleteWorkspace(workspaceId);
40557
40727
  };
40558
40728
 
@@ -40952,7 +41122,7 @@ var bashTool = {
40952
41122
  if (rejection) return `[bash] ${rejection}`;
40953
41123
  }
40954
41124
  const cwd = explicitCwd || getEffectiveCwd(userRequest);
40955
- return new Promise((resolve10) => {
41125
+ return new Promise((resolve11) => {
40956
41126
  const options = {
40957
41127
  timeout,
40958
41128
  maxBuffer: 1024 * 1024,
@@ -40984,7 +41154,7 @@ ${trimmed}`;
40984
41154
  if (!output) {
40985
41155
  output = "[bash] \u547D\u4EE4\u6267\u884C\u6210\u529F\uFF08\u65E0\u8F93\u51FA\uFF09";
40986
41156
  }
40987
- resolve10(output);
41157
+ resolve11(output);
40988
41158
  });
40989
41159
  });
40990
41160
  }
@@ -41592,10 +41762,10 @@ var downloadMessageResource = async (messageId, fileKey, type) => {
41592
41762
  throw error;
41593
41763
  }
41594
41764
  const readable = response.getReadableStream();
41595
- return new Promise((resolve10, reject) => {
41765
+ return new Promise((resolve11, reject) => {
41596
41766
  const chunks = [];
41597
41767
  readable.on("data", (chunk) => chunks.push(chunk));
41598
- readable.on("end", () => resolve10(Buffer.concat(chunks)));
41768
+ readable.on("end", () => resolve11(Buffer.concat(chunks)));
41599
41769
  readable.on("error", reject);
41600
41770
  });
41601
41771
  };
@@ -44863,7 +45033,7 @@ var responseViaResponseObject = async (res, outgoing, options = {}) => {
44863
45033
  });
44864
45034
  if (!chunk) {
44865
45035
  if (i === 1) {
44866
- await new Promise((resolve10) => setTimeout(resolve10));
45036
+ await new Promise((resolve11) => setTimeout(resolve11));
44867
45037
  maxReadCount = 3;
44868
45038
  continue;
44869
45039
  }
@@ -45080,8 +45250,8 @@ var _baseMimes = {
45080
45250
  var baseMimes = _baseMimes;
45081
45251
 
45082
45252
  // node_modules/.pnpm/@hono+node-server@1.19.11_hono@4.12.9/node_modules/@hono/node-server/dist/serve-static.mjs
45083
- var import_fs10 = require("fs");
45084
- var import_path16 = require("path");
45253
+ var import_fs11 = require("fs");
45254
+ var import_path17 = require("path");
45085
45255
  var import_process = require("process");
45086
45256
  var import_stream2 = require("stream");
45087
45257
  var COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
@@ -45121,7 +45291,7 @@ var createStreamBody = (stream) => {
45121
45291
  var getStats = (path9) => {
45122
45292
  let stats;
45123
45293
  try {
45124
- stats = (0, import_fs10.statSync)(path9);
45294
+ stats = (0, import_fs11.statSync)(path9);
45125
45295
  } catch {
45126
45296
  }
45127
45297
  return stats;
@@ -45143,7 +45313,7 @@ var tryDecodeURI2 = (str) => tryDecode2(str, decodeURI);
45143
45313
  var serveStatic = (options = { root: "" }) => {
45144
45314
  const root = options.root || "";
45145
45315
  const optionPath = options.path;
45146
- if (root !== "" && !(0, import_fs10.existsSync)(root)) {
45316
+ if (root !== "" && !(0, import_fs11.existsSync)(root)) {
45147
45317
  console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
45148
45318
  }
45149
45319
  return async (c, next) => {
@@ -45164,14 +45334,14 @@ var serveStatic = (options = { root: "" }) => {
45164
45334
  return next();
45165
45335
  }
45166
45336
  }
45167
- let path9 = (0, import_path16.join)(
45337
+ let path9 = (0, import_path17.join)(
45168
45338
  root,
45169
45339
  !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
45170
45340
  );
45171
45341
  let stats = getStats(path9);
45172
45342
  if (stats && stats.isDirectory()) {
45173
45343
  const indexFile = options.index ?? "index.html";
45174
- path9 = (0, import_path16.join)(path9, indexFile);
45344
+ path9 = (0, import_path17.join)(path9, indexFile);
45175
45345
  stats = getStats(path9);
45176
45346
  }
45177
45347
  if (!stats) {
@@ -45207,7 +45377,7 @@ var serveStatic = (options = { root: "" }) => {
45207
45377
  result = c.body(null);
45208
45378
  } else if (!range) {
45209
45379
  c.header("Content-Length", size.toString());
45210
- result = c.body(createStreamBody((0, import_fs10.createReadStream)(path9)), 200);
45380
+ result = c.body(createStreamBody((0, import_fs11.createReadStream)(path9)), 200);
45211
45381
  } else {
45212
45382
  c.header("Accept-Ranges", "bytes");
45213
45383
  c.header("Date", stats.birthtime.toUTCString());
@@ -45218,7 +45388,7 @@ var serveStatic = (options = { root: "" }) => {
45218
45388
  end = size - 1;
45219
45389
  }
45220
45390
  const chunksize = end - start + 1;
45221
- const stream = (0, import_fs10.createReadStream)(path9, { start, end });
45391
+ const stream = (0, import_fs11.createReadStream)(path9, { start, end });
45222
45392
  c.header("Content-Length", chunksize.toString());
45223
45393
  c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
45224
45394
  result = c.body(createStreamBody(stream), 206);
@@ -45319,12 +45489,12 @@ var cors = (options) => {
45319
45489
  // src/git/worktree.ts
45320
45490
  var import_child_process2 = require("child_process");
45321
45491
  var import_util = require("util");
45322
- var import_path17 = __toESM(require("path"));
45323
- var import_fs11 = require("fs");
45492
+ var import_path18 = __toESM(require("path"));
45493
+ var import_fs12 = require("fs");
45324
45494
  var execFileAsync = (0, import_util.promisify)(import_child_process2.execFile);
45325
45495
  var getProjectRoot = () => process.cwd();
45326
- var getWorktreeBaseDir = () => import_path17.default.join(getProjectRoot(), ".worktrees");
45327
- var getWorktreePath = (goalId, taskId) => import_path17.default.join(getWorktreeBaseDir(), goalId, taskId);
45496
+ var getWorktreeBaseDir = () => import_path18.default.join(getProjectRoot(), ".worktrees");
45497
+ var getWorktreePath = (goalId, taskId) => import_path18.default.join(getWorktreeBaseDir(), goalId, taskId);
45328
45498
  var getBranchName = (taskId) => `task/${taskId}`;
45329
45499
  async function git(args, cwd) {
45330
45500
  const { stdout } = await execFileAsync("git", args, {
@@ -45336,14 +45506,14 @@ async function git(args, cwd) {
45336
45506
  async function createWorktree(taskId, goalId, baseBranch = "main") {
45337
45507
  const wtPath = getWorktreePath(goalId, taskId);
45338
45508
  const branch = getBranchName(taskId);
45339
- const parentDir = import_path17.default.dirname(wtPath);
45340
- if (!(0, import_fs11.existsSync)(parentDir)) {
45341
- (0, import_fs11.mkdirSync)(parentDir, { recursive: true });
45509
+ const parentDir = import_path18.default.dirname(wtPath);
45510
+ if (!(0, import_fs12.existsSync)(parentDir)) {
45511
+ (0, import_fs12.mkdirSync)(parentDir, { recursive: true });
45342
45512
  }
45343
45513
  await git(["worktree", "add", "-b", branch, wtPath, baseBranch]);
45344
45514
  return {
45345
45515
  branch,
45346
- path: import_path17.default.relative(getProjectRoot(), wtPath),
45516
+ path: import_path18.default.relative(getProjectRoot(), wtPath),
45347
45517
  baseBranch,
45348
45518
  createdAt: getDate()
45349
45519
  };
@@ -45351,7 +45521,7 @@ async function createWorktree(taskId, goalId, baseBranch = "main") {
45351
45521
  async function deleteWorktree(taskId, goalId) {
45352
45522
  const wtPath = getWorktreePath(goalId, taskId);
45353
45523
  const branch = getBranchName(taskId);
45354
- if ((0, import_fs11.existsSync)(wtPath)) {
45524
+ if ((0, import_fs12.existsSync)(wtPath)) {
45355
45525
  await git(["worktree", "remove", wtPath, "--force"]);
45356
45526
  }
45357
45527
  try {
@@ -45442,8 +45612,8 @@ async function listWorktrees() {
45442
45612
  const fullBranch = branchLine.replace("branch refs/heads/", "");
45443
45613
  if (!fullBranch.startsWith("task/")) continue;
45444
45614
  const taskId = fullBranch.replace("task/", "");
45445
- const relPath = import_path17.default.relative(getProjectRoot(), wtPath);
45446
- const parts = relPath.split(import_path17.default.sep);
45615
+ const relPath = import_path18.default.relative(getProjectRoot(), wtPath);
45616
+ const parts = relPath.split(import_path18.default.sep);
45447
45617
  const worktreeIdx = parts.indexOf(".worktrees");
45448
45618
  const goalId = worktreeIdx >= 0 && parts.length > worktreeIdx + 1 ? parts[worktreeIdx + 1] : "";
45449
45619
  worktrees.push({
@@ -46227,6 +46397,10 @@ function startServer(port = 3e3) {
46227
46397
  }
46228
46398
 
46229
46399
  // src/main.ts
46400
+ var cliResult = handleCliCommand(process.argv.slice(2));
46401
+ if (cliResult !== void 0) {
46402
+ process.exit(cliResult);
46403
+ }
46230
46404
  async function main() {
46231
46405
  loadEnv();
46232
46406
  const cfg = loadConfig();