@wagemule/daemon 0.1.6 → 0.1.7

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/main.cjs CHANGED
@@ -1802,8 +1802,10 @@ var KimiAdapter = class {
1802
1802
  const wmDir = import_node_path.default.join(input.cwd, ".wm");
1803
1803
  await (0, import_promises.mkdir)(wmDir, { recursive: true });
1804
1804
  const agentFile = import_node_path.default.join(wmDir, "kimi-agent.yaml");
1805
+ const systemPromptFile = import_node_path.default.join(wmDir, "kimi-system.md");
1805
1806
  const mcpConfigFile = import_node_path.default.join(wmDir, "kimi-mcp.json");
1806
- await (0, import_promises.writeFile)(agentFile, kimiAgentYaml(input.systemPrompt), "utf8");
1807
+ await (0, import_promises.writeFile)(systemPromptFile, input.systemPrompt, "utf8");
1808
+ await (0, import_promises.writeFile)(agentFile, kimiAgentYaml(), "utf8");
1807
1809
  await (0, import_promises.writeFile)(mcpConfigFile, JSON.stringify({ mcpServers: {} }, null, 2), "utf8");
1808
1810
  const args = [
1809
1811
  "--wire",
@@ -1927,12 +1929,13 @@ var KimiAdapter = class {
1927
1929
  }
1928
1930
  }
1929
1931
  };
1930
- function kimiAgentYaml(systemPrompt) {
1932
+ function kimiAgentYaml() {
1931
1933
  return [
1932
- "name: wm",
1933
- "description: Wage Mule platform agent",
1934
- "instructions: |-",
1935
- ...systemPrompt.split(/\r?\n/).map((line) => ` ${line}`),
1934
+ "version: 1",
1935
+ "agent:",
1936
+ " extend: default",
1937
+ " name: wm",
1938
+ " system_prompt_path: ./kimi-system.md",
1936
1939
  ""
1937
1940
  ].join("\n");
1938
1941
  }
@@ -3888,7 +3891,7 @@ var import_ws = __toESM(require("ws"));
3888
3891
  // package.json
3889
3892
  var package_default = {
3890
3893
  name: "@wagemule/daemon",
3891
- version: "0.1.6",
3894
+ version: "0.1.7",
3892
3895
  private: false,
3893
3896
  description: "Wage Mule local daemon for connecting local agent runtimes to Workspace Server.",
3894
3897
  main: "./dist/main.cjs",
@@ -4296,15 +4299,35 @@ ${stderr}`);
4296
4299
  function parseKimiModelConfig(configText) {
4297
4300
  const ids = [];
4298
4301
  let defaultModel;
4302
+ let section;
4299
4303
  for (const rawLine of configText.split(/\r?\n/)) {
4300
4304
  const line = stripYamlComment(rawLine).trim();
4301
4305
  if (!line) continue;
4302
- const model = line.match(/^(?:model|default_model)\s*=\s*["']?([^"']+)["']?\s*$/);
4303
- if (model) {
4304
- defaultModel = model[1]?.trim();
4306
+ const table = line.match(/^\[models\.([^\]]+)]$/);
4307
+ if (table) {
4308
+ section = `models.${unquote(table[1].trim())}`;
4309
+ pushUnique(ids, section.slice("models.".length));
4310
+ continue;
4311
+ }
4312
+ const anyTable = line.match(/^\[([^\]]+)]$/);
4313
+ if (anyTable) {
4314
+ section = anyTable[1]?.trim();
4315
+ continue;
4316
+ }
4317
+ const defaultModelLine = line.match(/^default_model\s*=\s*["']?([^"']+)["']?\s*$/);
4318
+ if (defaultModelLine) {
4319
+ defaultModel = defaultModelLine[1]?.trim();
4305
4320
  pushUnique(ids, defaultModel);
4306
4321
  continue;
4307
4322
  }
4323
+ if (section?.startsWith("models.")) continue;
4324
+ const model = line.match(/^model\s*=\s*["']?([^"']+)["']?\s*$/);
4325
+ if (model) {
4326
+ const value = model[1]?.trim();
4327
+ defaultModel ??= value;
4328
+ pushUnique(ids, value);
4329
+ continue;
4330
+ }
4308
4331
  const array = line.match(/^(?:models|available_models)\s*=\s*\[(.+)\]\s*$/);
4309
4332
  if (array) {
4310
4333
  for (const part of array[1].split(",")) pushUnique(ids, unquote(part.trim()));
@@ -5042,14 +5065,7 @@ var AgentProcessManager = class {
5042
5065
  } else if (message.type === "feishu:token:clear") {
5043
5066
  await this.replyFeishuTokenClear(message.requestId, message.agentId, message.config);
5044
5067
  } else if (message.type === "feishu:delegation:start" || message.type === "feishu:delegation:update") {
5045
- this.startFeishuDelegationSchedule(message.delegation, message.config);
5046
- this.options.sendToServer({
5047
- type: "feishu:delegation:result",
5048
- requestId: message.requestId,
5049
- delegationId: message.delegation.id,
5050
- agentId: message.delegation.delegate_agent_id,
5051
- ok: true
5052
- });
5068
+ await this.replyFeishuDelegationStart(message.requestId, message.delegation, message.config);
5053
5069
  } else if (message.type === "feishu:delegation:stop") {
5054
5070
  this.stopFeishuDelegationSchedule(message.delegationId);
5055
5071
  this.options.sendToServer({
@@ -5130,8 +5146,32 @@ var AgentProcessManager = class {
5130
5146
  });
5131
5147
  });
5132
5148
  }, intervalMs);
5149
+ timer.unref?.();
5133
5150
  this.feishuDelegationTimers.set(delegation.id, timer);
5134
5151
  }
5152
+ async replyFeishuDelegationStart(requestId, delegation, config) {
5153
+ try {
5154
+ const feishuConfig = { ...config, feishuDelegationEnabled: true };
5155
+ await this.ensureAgentWorkspace(delegation.delegate_agent_id, feishuConfig);
5156
+ this.startFeishuDelegationSchedule(delegation, feishuConfig);
5157
+ this.options.sendToServer({
5158
+ type: "feishu:delegation:result",
5159
+ requestId,
5160
+ delegationId: delegation.id,
5161
+ agentId: delegation.delegate_agent_id,
5162
+ ok: true
5163
+ });
5164
+ } catch (error) {
5165
+ this.options.sendToServer({
5166
+ type: "feishu:delegation:result",
5167
+ requestId,
5168
+ delegationId: delegation.id,
5169
+ agentId: delegation.delegate_agent_id,
5170
+ ok: false,
5171
+ error: error instanceof Error ? error.message : "feishu delegation start failed"
5172
+ });
5173
+ }
5174
+ }
5135
5175
  shouldSkipScheduledFeishuWake(agentId) {
5136
5176
  if (this.starting.has(agentId)) return true;
5137
5177
  const running = this.running.get(agentId);
@@ -5331,7 +5371,7 @@ var AgentProcessManager = class {
5331
5371
  if (running && !config?.feishuDelegationEnabled) return { workspace: running.workspace };
5332
5372
  const idle = this.idleConfigs.get(agentId);
5333
5373
  if (idle?.workspace && !config?.feishuDelegationEnabled) return { workspace: idle.workspace };
5334
- const effectiveConfig = config ?? idle?.config;
5374
+ const effectiveConfig = this.mergeWorkspaceConfig(config ?? idle?.config, running?.config, idle?.config);
5335
5375
  if (!effectiveConfig) return { missing: true };
5336
5376
  const workspace = await createAgentWorkspace({
5337
5377
  rootDir: this.options.rootDir,
@@ -5354,6 +5394,13 @@ var AgentProcessManager = class {
5354
5394
  this.idleConfigs.set(agentId, { config: effectiveConfig, sessionId: effectiveConfig.sessionId, workspace });
5355
5395
  return { workspace };
5356
5396
  }
5397
+ mergeWorkspaceConfig(config, runningConfig, idleConfig) {
5398
+ if (!config) return config;
5399
+ if (config.feishuDelegationEnabled || runningConfig?.feishuDelegationEnabled || idleConfig?.feishuDelegationEnabled) {
5400
+ return { ...config, feishuDelegationEnabled: true };
5401
+ }
5402
+ return config;
5403
+ }
5357
5404
  async replyWorkspaceInit(requestId, agentId, config) {
5358
5405
  try {
5359
5406
  const { workspace } = await this.ensureAgentWorkspace(agentId, config);