@wagemule/daemon 0.1.6 → 0.1.8

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.8",
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",
@@ -3984,30 +3987,7 @@ var ServerConnection = class {
3984
3987
  ws.on("open", () => {
3985
3988
  this.reconnectAttempt = 0;
3986
3989
  this.log(`socket open url=${redactUrl(url)}`);
3987
- this.send({
3988
- type: "ready",
3989
- capabilities: [
3990
- "agent:start",
3991
- "agent:stop",
3992
- "agent:deliver",
3993
- "agent:reset-workspace",
3994
- "agent:diagnostic",
3995
- "workspace:list",
3996
- "workspace:read",
3997
- "agent:skills:list",
3998
- "machine:runtime_models:detect",
3999
- "machine:workspace:scan",
4000
- "machine:workspace:delete",
4001
- "reminder-cache"
4002
- ],
4003
- runtimes: supportedRuntimeIds,
4004
- runningAgents: this.options.runningAgentsProvider?.() ?? [],
4005
- wakeableAgents: this.options.wakeableAgentsProvider?.() ?? [],
4006
- hostname: import_node_os6.default.hostname() || "local",
4007
- name: this.options.name,
4008
- os: `${process.platform}/${process.arch}`,
4009
- daemonVersion: this.options.daemonVersion ?? package_default.version
4010
- });
3990
+ void this.sendReady();
4011
3991
  });
4012
3992
  ws.on("message", (raw) => {
4013
3993
  const msg = JSON.parse(String(raw));
@@ -4033,6 +4013,42 @@ var ServerConnection = class {
4033
4013
  this.scheduleReconnect();
4034
4014
  });
4035
4015
  }
4016
+ async sendReady() {
4017
+ this.send({
4018
+ type: "ready",
4019
+ capabilities: [
4020
+ "agent:start",
4021
+ "agent:stop",
4022
+ "agent:deliver",
4023
+ "agent:reset-workspace",
4024
+ "agent:diagnostic",
4025
+ "workspace:list",
4026
+ "workspace:read",
4027
+ "agent:skills:list",
4028
+ "machine:runtime_models:detect",
4029
+ "machine:workspace:scan",
4030
+ "machine:workspace:delete",
4031
+ "reminder-cache"
4032
+ ],
4033
+ runtimes: await this.detectAvailableRuntimes(),
4034
+ runningAgents: this.options.runningAgentsProvider?.() ?? [],
4035
+ wakeableAgents: this.options.wakeableAgentsProvider?.() ?? [],
4036
+ hostname: import_node_os6.default.hostname() || "local",
4037
+ name: this.options.name,
4038
+ os: `${process.platform}/${process.arch}`,
4039
+ daemonVersion: this.options.daemonVersion ?? package_default.version
4040
+ });
4041
+ }
4042
+ async detectAvailableRuntimes() {
4043
+ if (this.options.runtimesProvider) return this.options.runtimesProvider();
4044
+ try {
4045
+ const results = await doctorRuntimes(supportedRuntimeIds);
4046
+ return results.filter((result) => result.detected).map((result) => result.runtime);
4047
+ } catch (error) {
4048
+ this.log(`runtime detection failed ${error instanceof Error ? error.message : String(error)}`);
4049
+ return [];
4050
+ }
4051
+ }
4036
4052
  scheduleReconnect() {
4037
4053
  if (this.stopped || this.reconnectTimer) return;
4038
4054
  const delay = this.nextReconnectDelayMs();
@@ -4296,15 +4312,35 @@ ${stderr}`);
4296
4312
  function parseKimiModelConfig(configText) {
4297
4313
  const ids = [];
4298
4314
  let defaultModel;
4315
+ let section;
4299
4316
  for (const rawLine of configText.split(/\r?\n/)) {
4300
4317
  const line = stripYamlComment(rawLine).trim();
4301
4318
  if (!line) continue;
4302
- const model = line.match(/^(?:model|default_model)\s*=\s*["']?([^"']+)["']?\s*$/);
4303
- if (model) {
4304
- defaultModel = model[1]?.trim();
4319
+ const table = line.match(/^\[models\.([^\]]+)]$/);
4320
+ if (table) {
4321
+ section = `models.${unquote(table[1].trim())}`;
4322
+ pushUnique(ids, section.slice("models.".length));
4323
+ continue;
4324
+ }
4325
+ const anyTable = line.match(/^\[([^\]]+)]$/);
4326
+ if (anyTable) {
4327
+ section = anyTable[1]?.trim();
4328
+ continue;
4329
+ }
4330
+ const defaultModelLine = line.match(/^default_model\s*=\s*["']?([^"']+)["']?\s*$/);
4331
+ if (defaultModelLine) {
4332
+ defaultModel = defaultModelLine[1]?.trim();
4305
4333
  pushUnique(ids, defaultModel);
4306
4334
  continue;
4307
4335
  }
4336
+ if (section?.startsWith("models.")) continue;
4337
+ const model = line.match(/^model\s*=\s*["']?([^"']+)["']?\s*$/);
4338
+ if (model) {
4339
+ const value = model[1]?.trim();
4340
+ defaultModel ??= value;
4341
+ pushUnique(ids, value);
4342
+ continue;
4343
+ }
4308
4344
  const array = line.match(/^(?:models|available_models)\s*=\s*\[(.+)\]\s*$/);
4309
4345
  if (array) {
4310
4346
  for (const part of array[1].split(",")) pushUnique(ids, unquote(part.trim()));
@@ -5042,14 +5078,7 @@ var AgentProcessManager = class {
5042
5078
  } else if (message.type === "feishu:token:clear") {
5043
5079
  await this.replyFeishuTokenClear(message.requestId, message.agentId, message.config);
5044
5080
  } 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
- });
5081
+ await this.replyFeishuDelegationStart(message.requestId, message.delegation, message.config);
5053
5082
  } else if (message.type === "feishu:delegation:stop") {
5054
5083
  this.stopFeishuDelegationSchedule(message.delegationId);
5055
5084
  this.options.sendToServer({
@@ -5130,8 +5159,32 @@ var AgentProcessManager = class {
5130
5159
  });
5131
5160
  });
5132
5161
  }, intervalMs);
5162
+ timer.unref?.();
5133
5163
  this.feishuDelegationTimers.set(delegation.id, timer);
5134
5164
  }
5165
+ async replyFeishuDelegationStart(requestId, delegation, config) {
5166
+ try {
5167
+ const feishuConfig = { ...config, feishuDelegationEnabled: true };
5168
+ await this.ensureAgentWorkspace(delegation.delegate_agent_id, feishuConfig);
5169
+ this.startFeishuDelegationSchedule(delegation, feishuConfig);
5170
+ this.options.sendToServer({
5171
+ type: "feishu:delegation:result",
5172
+ requestId,
5173
+ delegationId: delegation.id,
5174
+ agentId: delegation.delegate_agent_id,
5175
+ ok: true
5176
+ });
5177
+ } catch (error) {
5178
+ this.options.sendToServer({
5179
+ type: "feishu:delegation:result",
5180
+ requestId,
5181
+ delegationId: delegation.id,
5182
+ agentId: delegation.delegate_agent_id,
5183
+ ok: false,
5184
+ error: error instanceof Error ? error.message : "feishu delegation start failed"
5185
+ });
5186
+ }
5187
+ }
5135
5188
  shouldSkipScheduledFeishuWake(agentId) {
5136
5189
  if (this.starting.has(agentId)) return true;
5137
5190
  const running = this.running.get(agentId);
@@ -5331,7 +5384,7 @@ var AgentProcessManager = class {
5331
5384
  if (running && !config?.feishuDelegationEnabled) return { workspace: running.workspace };
5332
5385
  const idle = this.idleConfigs.get(agentId);
5333
5386
  if (idle?.workspace && !config?.feishuDelegationEnabled) return { workspace: idle.workspace };
5334
- const effectiveConfig = config ?? idle?.config;
5387
+ const effectiveConfig = this.mergeWorkspaceConfig(config ?? idle?.config, running?.config, idle?.config);
5335
5388
  if (!effectiveConfig) return { missing: true };
5336
5389
  const workspace = await createAgentWorkspace({
5337
5390
  rootDir: this.options.rootDir,
@@ -5354,6 +5407,13 @@ var AgentProcessManager = class {
5354
5407
  this.idleConfigs.set(agentId, { config: effectiveConfig, sessionId: effectiveConfig.sessionId, workspace });
5355
5408
  return { workspace };
5356
5409
  }
5410
+ mergeWorkspaceConfig(config, runningConfig, idleConfig) {
5411
+ if (!config) return config;
5412
+ if (config.feishuDelegationEnabled || runningConfig?.feishuDelegationEnabled || idleConfig?.feishuDelegationEnabled) {
5413
+ return { ...config, feishuDelegationEnabled: true };
5414
+ }
5415
+ return config;
5416
+ }
5357
5417
  async replyWorkspaceInit(requestId, agentId, config) {
5358
5418
  try {
5359
5419
  const { workspace } = await this.ensureAgentWorkspace(agentId, config);