@serviceme/devtools-cli 0.1.7 → 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/cli.js CHANGED
@@ -312,7 +312,9 @@ var init_metadata = __esm({
312
312
  json: 1,
313
313
  env: 1,
314
314
  image: 1,
315
- project: 1
315
+ project: 1,
316
+ skills: 1,
317
+ agents: 1
316
318
  };
317
319
  }
318
320
  });
@@ -357,10 +359,10 @@ var init_AgentCatalogClient = __esm({
357
359
  }
358
360
  async getCatalog() {
359
361
  if (!this.baseUrl) {
360
- return {
361
- agents: [],
362
- fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
363
- };
362
+ throw createServicemeError(
363
+ "workspace_not_found",
364
+ "Agent catalog baseUrl is not configured."
365
+ );
364
366
  }
365
367
  const response = await this.fetchImpl(
366
368
  `${this.baseUrl}/api/v1/marketplace/agents`
@@ -909,6 +911,9 @@ async function copilotPrompt(options2) {
909
911
  }
910
912
  return { output, exitCode: 0 };
911
913
  } catch (error) {
914
+ if (error instanceof ServicemeProtocolError) {
915
+ throw error;
916
+ }
912
917
  const err = error;
913
918
  if (err.code === "ETIMEDOUT") {
914
919
  throw createServicemeError(
@@ -978,11 +983,13 @@ var init_environmentInspector = __esm({
978
983
  ERROR_CODE_NOT_FOUND = 127;
979
984
  ERROR_CODE_TIMEOUT = "ETIMEDOUT";
980
985
  EnvironmentInspector = class {
986
+ constructor(options2 = {}) {
987
+ this.runCommandFn = options2.runCommand ?? runCommand;
988
+ this.platform = options2.platform ?? process.platform;
989
+ }
981
990
  async checkEnvironment() {
982
991
  const results = await Promise.all(
983
- KNOWN_ENVIRONMENT_TOOLS.map(
984
- async (tool) => [tool, await this.checkTool(tool)]
985
- )
992
+ KNOWN_ENVIRONMENT_TOOLS.map(async (tool) => [tool, await this.checkTool(tool)])
986
993
  );
987
994
  return Object.fromEntries(results);
988
995
  }
@@ -1010,8 +1017,8 @@ var init_environmentInspector = __esm({
1010
1017
  }
1011
1018
  async getToolPath(toolName) {
1012
1019
  try {
1013
- const isWindows = process.platform === "win32";
1014
- const result = await runCommand(isWindows ? "where" : "which", {
1020
+ const isWindows = this.platform === "win32";
1021
+ const result = await this.runCommandFn(isWindows ? "where" : "which", {
1015
1022
  args: [toolName],
1016
1023
  timeoutMs: this.getToolTimeout(toolName)
1017
1024
  });
@@ -1028,14 +1035,12 @@ var init_environmentInspector = __esm({
1028
1035
  */
1029
1036
  async getToolShimPath(toolName) {
1030
1037
  try {
1031
- const result = await runCommand("where", {
1038
+ const result = await this.runCommandFn("where", {
1032
1039
  args: [toolName],
1033
1040
  timeoutMs: this.getToolTimeout(toolName)
1034
1041
  });
1035
1042
  const candidates = result.stdout.split(/\r?\n/).map((line2) => line2.trim()).filter((line2) => line2.length > 0);
1036
- const cmdShim = candidates.find(
1037
- (line2) => line2.toLowerCase().endsWith(".cmd")
1038
- );
1043
+ const cmdShim = candidates.find((line2) => line2.toLowerCase().endsWith(".cmd"));
1039
1044
  return cmdShim ?? candidates[0];
1040
1045
  } catch {
1041
1046
  return void 0;
@@ -1043,16 +1048,16 @@ var init_environmentInspector = __esm({
1043
1048
  }
1044
1049
  async getToolVersion(toolName) {
1045
1050
  const invocation = await this.getVersionInvocation(toolName);
1046
- const result = await runCommand(invocation.command, {
1051
+ const result = await this.runCommandFn(invocation.command, {
1047
1052
  args: invocation.args,
1048
1053
  timeoutMs: this.getToolTimeout(toolName)
1049
1054
  });
1050
1055
  return this.parseVersion(toolName, result.stdout || result.stderr);
1051
1056
  }
1052
1057
  async checkNvm() {
1053
- if (process.platform === "win32") {
1058
+ if (this.platform === "win32") {
1054
1059
  try {
1055
- const result = await runCommand("cmd.exe", {
1060
+ const result = await this.runCommandFn("cmd.exe", {
1056
1061
  args: ["/c", "nvm version"],
1057
1062
  timeoutMs: this.getToolTimeout("nvm")
1058
1063
  });
@@ -1069,7 +1074,7 @@ var init_environmentInspector = __esm({
1069
1074
  }
1070
1075
  }
1071
1076
  try {
1072
- const result = await runCommand("/bin/bash", {
1077
+ const result = await this.runCommandFn("/bin/bash", {
1073
1078
  args: [
1074
1079
  "-lc",
1075
1080
  'export NVM_DIR="$HOME/.nvm"; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; nvm --version'
@@ -1097,7 +1102,7 @@ var init_environmentInspector = __esm({
1097
1102
  };
1098
1103
  }
1099
1104
  try {
1100
- const result = await runCommand("dotnet", {
1105
+ const result = await this.runCommandFn("dotnet", {
1101
1106
  args: ["nuget", "list", "source"],
1102
1107
  timeoutMs: this.getToolTimeout("nuget")
1103
1108
  });
@@ -1118,7 +1123,7 @@ var init_environmentInspector = __esm({
1118
1123
  }
1119
1124
  }
1120
1125
  async getVersionInvocation(toolName) {
1121
- const isWindows = process.platform === "win32";
1126
+ const isWindows = this.platform === "win32";
1122
1127
  if (isWindows && ["npm", "pnpm", "nrm"].includes(toolName)) {
1123
1128
  const shim = await this.getToolShimPath(toolName);
1124
1129
  if (shim) {
@@ -11264,7 +11269,7 @@ var require_yauzl = __commonJS({
11264
11269
  var Transform = require("stream").Transform;
11265
11270
  var PassThrough = require("stream").PassThrough;
11266
11271
  var Writable = require("stream").Writable;
11267
- exports2.open = open2;
11272
+ exports2.open = open;
11268
11273
  exports2.fromFd = fromFd;
11269
11274
  exports2.fromBuffer = fromBuffer;
11270
11275
  exports2.fromRandomAccessReader = fromRandomAccessReader;
@@ -11276,7 +11281,7 @@ var require_yauzl = __commonJS({
11276
11281
  exports2.Entry = Entry;
11277
11282
  exports2.LocalFileHeader = LocalFileHeader;
11278
11283
  exports2.RandomAccessReader = RandomAccessReader;
11279
- function open2(path15, options2, callback) {
11284
+ function open(path15, options2, callback) {
11280
11285
  if (typeof options2 === "function") {
11281
11286
  callback = options2;
11282
11287
  options2 = null;
@@ -12004,49 +12009,42 @@ var init_fileUtils = __esm({
12004
12009
  import_yauzl = __toESM(require_yauzl());
12005
12010
  unzipFile = (zipPath, dest) => {
12006
12011
  return new Promise((resolve, reject) => {
12007
- (0, import_yauzl.open)(
12008
- zipPath,
12009
- { lazyEntries: true },
12010
- (err, zipfile) => {
12011
- if (err) return reject(err);
12012
- if (!zipfile) return reject(new Error("Failed to open zip file."));
12013
- zipfile.readEntry();
12014
- zipfile.on("entry", (entry) => {
12015
- if (/\/$/.test(entry.fileName)) {
12016
- void (0, import_promises.mkdir)((0, import_node_path.join)(dest, entry.fileName), { recursive: true }).then(() => {
12017
- zipfile.readEntry();
12018
- }).catch(reject);
12019
- } else {
12020
- const outputPath = (0, import_node_path.join)(dest, entry.fileName);
12021
- void (0, import_promises.mkdir)((0, import_node_path.dirname)(outputPath), { recursive: true }).then(() => {
12022
- zipfile.openReadStream(
12023
- entry,
12024
- (streamError, readStream) => {
12025
- if (streamError) return reject(streamError);
12026
- if (!readStream)
12027
- return reject(
12028
- new Error("Failed to open zip entry stream.")
12029
- );
12030
- const writeStream = (0, import_node_fs.createWriteStream)(outputPath);
12031
- readStream.on("error", reject);
12032
- writeStream.on("error", reject);
12033
- writeStream.on("close", () => {
12034
- zipfile.readEntry();
12035
- });
12036
- readStream.pipe(writeStream);
12037
- }
12038
- );
12039
- }).catch(reject);
12040
- }
12041
- });
12042
- zipfile.on("end", () => {
12043
- resolve();
12044
- });
12045
- zipfile.on("error", (zipError) => {
12046
- reject(zipError);
12047
- });
12048
- }
12049
- );
12012
+ import_yauzl.default.open(zipPath, { lazyEntries: true }, (err, zipfile) => {
12013
+ if (err) return reject(err);
12014
+ if (!zipfile) return reject(new Error("Failed to open zip file."));
12015
+ zipfile.readEntry();
12016
+ zipfile.on("entry", (entry) => {
12017
+ if (/\/$/.test(entry.fileName)) {
12018
+ void (0, import_promises.mkdir)((0, import_node_path.join)(dest, entry.fileName), { recursive: true }).then(() => {
12019
+ zipfile.readEntry();
12020
+ }).catch(reject);
12021
+ } else {
12022
+ const outputPath = (0, import_node_path.join)(dest, entry.fileName);
12023
+ void (0, import_promises.mkdir)((0, import_node_path.dirname)(outputPath), { recursive: true }).then(() => {
12024
+ zipfile.openReadStream(
12025
+ entry,
12026
+ (streamError, readStream) => {
12027
+ if (streamError) return reject(streamError);
12028
+ if (!readStream) return reject(new Error("Failed to open zip entry stream."));
12029
+ const writeStream = (0, import_node_fs.createWriteStream)(outputPath);
12030
+ readStream.on("error", reject);
12031
+ writeStream.on("error", reject);
12032
+ writeStream.on("close", () => {
12033
+ zipfile.readEntry();
12034
+ });
12035
+ readStream.pipe(writeStream);
12036
+ }
12037
+ );
12038
+ }).catch(reject);
12039
+ }
12040
+ });
12041
+ zipfile.on("end", () => {
12042
+ resolve();
12043
+ });
12044
+ zipfile.on("error", (zipError) => {
12045
+ reject(zipError);
12046
+ });
12047
+ });
12050
12048
  });
12051
12049
  };
12052
12050
  tryLstat = async (targetPath) => {
@@ -12070,11 +12068,7 @@ var init_fileUtils = __esm({
12070
12068
  await (0, import_promises.mkdir)(destPath, { recursive: true });
12071
12069
  const children = await (0, import_promises.readdir)(sourcePath);
12072
12070
  for (const child of children) {
12073
- await mergeEntry(
12074
- (0, import_node_path.join)(sourcePath, child),
12075
- (0, import_node_path.join)(destPath, child),
12076
- overwrite
12077
- );
12071
+ await mergeEntry((0, import_node_path.join)(sourcePath, child), (0, import_node_path.join)(destPath, child), overwrite);
12078
12072
  }
12079
12073
  await (0, import_promises.rm)(sourcePath, { recursive: true, force: true });
12080
12074
  return;
@@ -12178,23 +12172,15 @@ var init_projectTools = __esm({
12178
12172
  }
12179
12173
  async makeScriptsExecutable(workspacePath) {
12180
12174
  const isWindows = process.platform === "win32";
12181
- const scripts = await this.findScripts(
12182
- workspacePath,
12183
- isWindows ? [".ps1", ".bat"] : [".sh"]
12184
- );
12175
+ const scripts = await this.findScripts(workspacePath, isWindows ? [".ps1", ".bat"] : [".sh"]);
12185
12176
  let updatedCount = 0;
12186
12177
  if (isWindows) {
12187
- for (const scriptPath of scripts.filter(
12188
- (script) => script.endsWith(".ps1")
12189
- )) {
12178
+ for (const scriptPath of scripts.filter((script) => script.endsWith(".ps1"))) {
12190
12179
  try {
12191
- await runCommand(
12192
- `powershell -Command "Unblock-File -Path '${scriptPath}'"`,
12193
- {
12194
- cwd: workspacePath,
12195
- shell: true
12196
- }
12197
- );
12180
+ await runCommand(`powershell -Command "Unblock-File -Path '${scriptPath}'"`, {
12181
+ cwd: workspacePath,
12182
+ shell: true
12183
+ });
12198
12184
  updatedCount += 1;
12199
12185
  } catch {
12200
12186
  }
@@ -12259,11 +12245,7 @@ var init_projectTools = __esm({
12259
12245
  if (await this.pathExists(presetManifestPath)) {
12260
12246
  return;
12261
12247
  }
12262
- const projectModePath = path3.join(
12263
- workspacePath,
12264
- ".ms-scaffold",
12265
- "project-mode.json"
12266
- );
12248
+ const projectModePath = path3.join(workspacePath, ".ms-scaffold", "project-mode.json");
12267
12249
  if (!await this.pathExists(projectModePath)) {
12268
12250
  return;
12269
12251
  }
@@ -12317,9 +12299,7 @@ var init_projectTools = __esm({
12317
12299
  if (directoryNames.length === 1) {
12318
12300
  return directoryNames[0] ?? null;
12319
12301
  }
12320
- const exactMatch = directoryNames.find(
12321
- (directoryName) => directoryName === expectedDirName
12322
- );
12302
+ const exactMatch = directoryNames.find((directoryName) => directoryName === expectedDirName);
12323
12303
  if (exactMatch) {
12324
12304
  return exactMatch;
12325
12305
  }
@@ -12576,10 +12556,8 @@ var init_GithubCopilotCliExecutor = __esm({
12576
12556
  windowsHide: true
12577
12557
  });
12578
12558
  if (child.pid) {
12579
- writeDiagnostic(
12580
- `[GithubCopilotCliExecutor] spawned child PID=${child.pid}
12581
- `
12582
- );
12559
+ writeDiagnostic(`[GithubCopilotCliExecutor] spawned child PID=${child.pid}
12560
+ `);
12583
12561
  }
12584
12562
  const timeoutMs = execution.timeoutMs;
12585
12563
  const timer = timeoutMs != null ? setTimeout(() => {
@@ -12597,15 +12575,13 @@ var init_GithubCopilotCliExecutor = __esm({
12597
12575
  child.stdout.on("data", (chunk) => {
12598
12576
  const data = chunk.toString();
12599
12577
  stdoutBuf += data;
12600
- if (stdoutBuf.length > MAX_OUTPUT_BYTES)
12601
- stdoutBuf = stdoutBuf.slice(-MAX_OUTPUT_BYTES);
12578
+ if (stdoutBuf.length > MAX_OUTPUT_BYTES) stdoutBuf = stdoutBuf.slice(-MAX_OUTPUT_BYTES);
12602
12579
  onOutput("stdout", data);
12603
12580
  });
12604
12581
  child.stderr.on("data", (chunk) => {
12605
12582
  const data = chunk.toString();
12606
12583
  stderrBuf += data;
12607
- if (stderrBuf.length > MAX_OUTPUT_BYTES)
12608
- stderrBuf = stderrBuf.slice(-MAX_OUTPUT_BYTES);
12584
+ if (stderrBuf.length > MAX_OUTPUT_BYTES) stderrBuf = stderrBuf.slice(-MAX_OUTPUT_BYTES);
12609
12585
  onOutput("stderr", data);
12610
12586
  });
12611
12587
  child.on("close", (code) => {
@@ -12959,10 +12935,7 @@ function isRecord3(value) {
12959
12935
  }
12960
12936
  function requireNonEmptyString(payload, field, taskType) {
12961
12937
  if (!isRecord3(payload) || typeof payload[field] !== "string" || !payload[field].trim()) {
12962
- throw createServicemeError(
12963
- "invalid_payload",
12964
- `${taskType} payload ${field} is required`
12965
- );
12938
+ throw createServicemeError("invalid_payload", `${taskType} payload ${field} is required`);
12966
12939
  }
12967
12940
  }
12968
12941
  function validateTaskPayload(taskType, payload) {
@@ -13143,9 +13116,7 @@ var init_TaskExecutionEngine = __esm({
13143
13116
  if (policy === "reject") {
13144
13117
  const existingIds = this.taskExecutions.get(snapshot.taskId);
13145
13118
  if (existingIds && existingIds.size > 0) {
13146
- throw new Error(
13147
- `TASK_ALREADY_RUNNING: Task ${snapshot.taskId} is already running`
13148
- );
13119
+ throw new Error(`TASK_ALREADY_RUNNING: Task ${snapshot.taskId} is already running`);
13149
13120
  }
13150
13121
  }
13151
13122
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -13469,7 +13440,7 @@ var init_SchedulerDaemon = __esm({
13469
13440
  TICK_INTERVAL = 1e3;
13470
13441
  MIN_SCHEDULE_INTERVAL = 1e3;
13471
13442
  SchedulerDaemon = class {
13472
- constructor(workspacePath) {
13443
+ constructor(workspacePath, options2 = {}) {
13473
13444
  this.tickTimer = null;
13474
13445
  this.watcher = null;
13475
13446
  this.running = false;
@@ -13482,6 +13453,7 @@ var init_SchedulerDaemon = __esm({
13482
13453
  this.logManager = new TaskLogManager(workspacePath);
13483
13454
  this.pidManager = new PidManager(workspacePath);
13484
13455
  this.logger = new DaemonLogger(workspacePath);
13456
+ this.getExecutor = options2.getExecutor ?? getExecutor;
13485
13457
  }
13486
13458
  start() {
13487
13459
  if (this.running) return;
@@ -13587,7 +13559,7 @@ var init_SchedulerDaemon = __esm({
13587
13559
  this.workspacePath
13588
13560
  );
13589
13561
  validateTaskPayload(task.taskType, executionPayload);
13590
- const executor = getExecutor(task.taskType);
13562
+ const executor = this.getExecutor(task.taskType);
13591
13563
  const result = await executor.execute(executionPayload);
13592
13564
  const finishedAt = (/* @__PURE__ */ new Date()).toISOString();
13593
13565
  const durationMs = Date.now() - startMs;
@@ -13681,10 +13653,10 @@ var init_SkillCatalogClient = __esm({
13681
13653
  }
13682
13654
  async getCatalog() {
13683
13655
  if (!this.baseUrl) {
13684
- return {
13685
- skills: [],
13686
- fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
13687
- };
13656
+ throw createServicemeError(
13657
+ "workspace_not_found",
13658
+ "Skill catalog baseUrl is not configured."
13659
+ );
13688
13660
  }
13689
13661
  const response = await this.fetchImpl(
13690
13662
  `${this.baseUrl}/api/v1/marketplace/skills`
@@ -13986,10 +13958,7 @@ function parseArgs(argv) {
13986
13958
  const withoutPrefix = token2.slice(2);
13987
13959
  const eqIndex = withoutPrefix.indexOf("=");
13988
13960
  if (eqIndex >= 0) {
13989
- flags.set(
13990
- withoutPrefix.slice(0, eqIndex),
13991
- withoutPrefix.slice(eqIndex + 1)
13992
- );
13961
+ flags.set(withoutPrefix.slice(0, eqIndex), withoutPrefix.slice(eqIndex + 1));
13993
13962
  continue;
13994
13963
  }
13995
13964
  const next = argv[index + 1];
@@ -14045,10 +14014,7 @@ async function runAgentCommand(parsed) {
14045
14014
  const action = parsed.positionals[1];
14046
14015
  const workspacePath = getStringFlag(parsed, "workspacePath");
14047
14016
  if (!workspacePath) {
14048
- throw createServicemeError(
14049
- "invalid_params",
14050
- "Expected --workspacePath <path>."
14051
- );
14017
+ throw createServicemeError("invalid_params", "Expected --workspacePath <path>.");
14052
14018
  }
14053
14019
  const store = new AgentStore({
14054
14020
  workspacePath,
@@ -14066,9 +14032,7 @@ async function runAgentCommand(parsed) {
14066
14032
  writeSuccess(await handleList(store));
14067
14033
  return;
14068
14034
  case "install":
14069
- writeSuccess(
14070
- await handleInstall(store, parsed, catalogClient)
14071
- );
14035
+ writeSuccess(await handleInstall(store, parsed, catalogClient));
14072
14036
  return;
14073
14037
  case "uninstall":
14074
14038
  writeSuccess(await handleUninstall(store, workspacePath, parsed));
@@ -14080,9 +14044,7 @@ async function runAgentCommand(parsed) {
14080
14044
  writeSuccess(await handleMarketplace(store, catalogClient));
14081
14045
  return;
14082
14046
  case "permissions":
14083
- writeSuccess(
14084
- await handlePermissions(store, reconciler, workspacePath, parsed)
14085
- );
14047
+ writeSuccess(await handlePermissions(store, reconciler, workspacePath, parsed));
14086
14048
  return;
14087
14049
  default:
14088
14050
  throw new Error(
@@ -14103,10 +14065,7 @@ async function handleList(store) {
14103
14065
  async function handleInstall(store, parsed, catalogClient) {
14104
14066
  const remoteId = getStringFlag(parsed, "id");
14105
14067
  if (!remoteId) {
14106
- throw createServicemeError(
14107
- "invalid_params",
14108
- "Expected --id <remoteAgentId>."
14109
- );
14068
+ throw createServicemeError("invalid_params", "Expected --id <remoteAgentId>.");
14110
14069
  }
14111
14070
  const agentId = normalizeAgentIdOrThrow(store, remoteId);
14112
14071
  if (!getBooleanFlag(parsed, "confirmed")) {
@@ -14170,19 +14129,13 @@ async function handleInstall(store, parsed, catalogClient) {
14170
14129
  async function handleUninstall(store, workspacePath, parsed) {
14171
14130
  const remoteId = getStringFlag(parsed, "id");
14172
14131
  if (!remoteId) {
14173
- throw createServicemeError(
14174
- "invalid_params",
14175
- "Expected --id <remoteAgentId>."
14176
- );
14132
+ throw createServicemeError("invalid_params", "Expected --id <remoteAgentId>.");
14177
14133
  }
14178
14134
  const agentId = normalizeAgentIdOrThrow(store, remoteId);
14179
- await fs12.rm(
14180
- path10.join(workspacePath, ".github", "agents", `${agentId}.agent.md`),
14181
- {
14182
- recursive: true,
14183
- force: true
14184
- }
14185
- );
14135
+ await fs12.rm(path10.join(workspacePath, ".github", "agents", `${agentId}.agent.md`), {
14136
+ recursive: true,
14137
+ force: true
14138
+ });
14186
14139
  await fs12.rm(path10.join(workspacePath, ".github", "agents", agentId), {
14187
14140
  recursive: true,
14188
14141
  force: true
@@ -14211,22 +14164,11 @@ async function handleMove(store, workspacePath, parsed) {
14211
14164
  );
14212
14165
  }
14213
14166
  if (to !== "workspace" && to !== "user") {
14214
- throw createServicemeError(
14215
- "invalid_params",
14216
- "Expected --to value to be workspace or user."
14217
- );
14167
+ throw createServicemeError("invalid_params", "Expected --to value to be workspace or user.");
14218
14168
  }
14219
14169
  const agentId = normalizeAgentIdOrThrow(store, remoteId);
14220
- const workspaceFlatPath = path10.join(
14221
- workspacePath,
14222
- ".github",
14223
- "agents",
14224
- `${agentId}.agent.md`
14225
- );
14226
- const userFlatPath = path10.join(
14227
- store.getUserAgentsRootPath(),
14228
- `${agentId}.agent.md`
14229
- );
14170
+ const workspaceFlatPath = path10.join(workspacePath, ".github", "agents", `${agentId}.agent.md`);
14171
+ const userFlatPath = path10.join(store.getUserAgentsRootPath(), `${agentId}.agent.md`);
14230
14172
  if (to === "user") {
14231
14173
  await moveEntry(workspaceFlatPath, userFlatPath);
14232
14174
  return {
@@ -14294,16 +14236,10 @@ async function handlePermissions(store, reconciler, workspacePath, parsed) {
14294
14236
  const remoteId = getStringFlag(parsed, "id");
14295
14237
  const scopeFlag = getStringFlag(parsed, "scope");
14296
14238
  if (!remoteId) {
14297
- throw createServicemeError(
14298
- "invalid_params",
14299
- "Expected --id <remoteAgentId>."
14300
- );
14239
+ throw createServicemeError("invalid_params", "Expected --id <remoteAgentId>.");
14301
14240
  }
14302
14241
  if (scopeFlag !== void 0 && scopeFlag !== "workspace" && scopeFlag !== "user") {
14303
- throw createServicemeError(
14304
- "invalid_params",
14305
- "Expected --scope value to be workspace or user."
14306
- );
14242
+ throw createServicemeError("invalid_params", "Expected --scope value to be workspace or user.");
14307
14243
  }
14308
14244
  const agentId = normalizeAgentIdOrThrow(store, remoteId);
14309
14245
  const requestedScope = scopeFlag ?? "workspace";
@@ -14337,10 +14273,7 @@ async function readAgentContent(store, workspacePath, agentId, scope) {
14337
14273
  } catch {
14338
14274
  }
14339
14275
  }
14340
- throw createServicemeError(
14341
- "not_found",
14342
- `Agent file not found for ${agentId} in ${scope} scope.`
14343
- );
14276
+ throw createServicemeError("not_found", `Agent file not found for ${agentId} in ${scope} scope.`);
14344
14277
  }
14345
14278
 
14346
14279
  // src/commands/bridge.ts
@@ -14352,7 +14285,7 @@ init_src();
14352
14285
 
14353
14286
  // src/version.ts
14354
14287
  var SERVICEME_CLI_NAME = "serviceme";
14355
- var SERVICEME_CLI_VERSION = "0.1.7";
14288
+ var SERVICEME_CLI_VERSION = "0.1.8";
14356
14289
 
14357
14290
  // src/bridge/AgentBridgeHandler.ts
14358
14291
  var fs13 = __toESM(require("fs/promises"));
@@ -14360,6 +14293,18 @@ var os3 = __toESM(require("os"));
14360
14293
  var path11 = __toESM(require("path"));
14361
14294
  init_src2();
14362
14295
  init_src();
14296
+
14297
+ // src/bridge/marketplaceEnv.ts
14298
+ var SERVICEME_MARKETPLACE_BASE_URL_ENV = "SERVICEME_MARKETPLACE_BASE_URL";
14299
+ function readMarketplaceBaseUrl() {
14300
+ const raw = process.env[SERVICEME_MARKETPLACE_BASE_URL_ENV];
14301
+ if (typeof raw !== "string" || raw.length === 0) {
14302
+ return void 0;
14303
+ }
14304
+ return raw;
14305
+ }
14306
+
14307
+ // src/bridge/AgentBridgeHandler.ts
14363
14308
  function normalizeAgentIdOrThrow2(store, remoteId) {
14364
14309
  try {
14365
14310
  return store.normalizeRemoteAgentId(remoteId);
@@ -14402,10 +14347,7 @@ var AgentBridgeHandler = class {
14402
14347
  context.workspacePath,
14403
14348
  context.store.getWorkspaceAgentsRootPath(),
14404
14349
  `${agentId}.agent.md`
14405
- ) : path11.join(
14406
- context.store.getUserAgentsRootPath(),
14407
- `${agentId}.agent.md`
14408
- ) : void 0,
14350
+ ) : path11.join(context.store.getUserAgentsRootPath(), `${agentId}.agent.md`) : void 0,
14409
14351
  canPublish: agent.canPublish,
14410
14352
  workspaceState: this.makeScopeState(
14411
14353
  "workspace",
@@ -14419,10 +14361,7 @@ var AgentBridgeHandler = class {
14419
14361
  userState: this.makeScopeState(
14420
14362
  "user",
14421
14363
  userInstalled,
14422
- path11.join(
14423
- context.store.getUserAgentsRootPath(),
14424
- `${agentId}.agent.md`
14425
- )
14364
+ path11.join(context.store.getUserAgentsRootPath(), `${agentId}.agent.md`)
14426
14365
  )
14427
14366
  });
14428
14367
  }
@@ -14459,10 +14398,7 @@ var AgentBridgeHandler = class {
14459
14398
  userState: this.makeScopeState(
14460
14399
  "user",
14461
14400
  userSet.has(agentId),
14462
- path11.join(
14463
- context.store.getUserAgentsRootPath(),
14464
- `${agentId}.agent.md`
14465
- )
14401
+ path11.join(context.store.getUserAgentsRootPath(), `${agentId}.agent.md`)
14466
14402
  )
14467
14403
  });
14468
14404
  }
@@ -14482,10 +14418,7 @@ var AgentBridgeHandler = class {
14482
14418
  hasConflict: false,
14483
14419
  tools: [],
14484
14420
  source: "local",
14485
- localAgentPath: path11.join(
14486
- context.store.getUserAgentsRootPath(),
14487
- `${agentId}.agent.md`
14488
- ),
14421
+ localAgentPath: path11.join(context.store.getUserAgentsRootPath(), `${agentId}.agent.md`),
14489
14422
  workspaceState: this.makeScopeState(
14490
14423
  "workspace",
14491
14424
  workspaceSet.has(agentId),
@@ -14498,18 +14431,12 @@ var AgentBridgeHandler = class {
14498
14431
  userState: this.makeScopeState(
14499
14432
  "user",
14500
14433
  true,
14501
- path11.join(
14502
- context.store.getUserAgentsRootPath(),
14503
- `${agentId}.agent.md`
14504
- )
14434
+ path11.join(context.store.getUserAgentsRootPath(), `${agentId}.agent.md`)
14505
14435
  )
14506
14436
  });
14507
14437
  }
14508
14438
  return {
14509
- configPath: path11.join(
14510
- context.workspacePath,
14511
- context.store.getWorkspaceStateFilePath()
14512
- ),
14439
+ configPath: path11.join(context.workspacePath, context.store.getWorkspaceStateFilePath()),
14513
14440
  userAgentsPath: context.userAgentsRoot,
14514
14441
  agents: [...byId.values()].sort((a, b) => a.id.localeCompare(b.id)),
14515
14442
  installedAgentIds: [.../* @__PURE__ */ new Set([...workspaceAgentIds, ...userAgentIds])],
@@ -14556,7 +14483,10 @@ var AgentBridgeHandler = class {
14556
14483
  workspacePath: resolvedWorkspacePath,
14557
14484
  userAgentsRoot
14558
14485
  });
14559
- const catalogClient = new AgentCatalogClient();
14486
+ const marketplaceBaseUrl = readMarketplaceBaseUrl();
14487
+ const catalogClient = new AgentCatalogClient(
14488
+ marketplaceBaseUrl ? { baseUrl: marketplaceBaseUrl } : {}
14489
+ );
14560
14490
  const reconciler = new AgentReconciler({
14561
14491
  agentStore: store,
14562
14492
  catalogClient
@@ -14654,10 +14584,7 @@ tools:
14654
14584
  );
14655
14585
  }
14656
14586
  async readAgentContent(context, agentId, scope) {
14657
- const root2 = scope === "workspace" ? path11.join(
14658
- context.workspacePath,
14659
- context.store.getWorkspaceAgentsRootPath()
14660
- ) : context.store.getUserAgentsRootPath();
14587
+ const root2 = scope === "workspace" ? path11.join(context.workspacePath, context.store.getWorkspaceAgentsRootPath()) : context.store.getUserAgentsRootPath();
14661
14588
  const candidates = [
14662
14589
  path11.join(root2, `${agentId}.agent.md`),
14663
14590
  path11.join(root2, agentId, `${agentId}.agent.md`)
@@ -14730,18 +14657,12 @@ var SkillBridgeHandler = class {
14730
14657
  hasScripts: skill.hasScripts,
14731
14658
  hasHooks: skill.hasHooks,
14732
14659
  source: skill.source,
14733
- localSkillPath: workspaceInstalled || userInstalled ? workspaceInstalled ? path12.join(
14734
- context.workspacePath,
14735
- context.store.getWorkspaceSkillPath(skillId)
14736
- ) : context.store.getUserSkillPath(skillId) : void 0,
14660
+ localSkillPath: workspaceInstalled || userInstalled ? workspaceInstalled ? path12.join(context.workspacePath, context.store.getWorkspaceSkillPath(skillId)) : context.store.getUserSkillPath(skillId) : void 0,
14737
14661
  canPublish: skill.canPublish,
14738
14662
  workspaceState: this.makeScopeState(
14739
14663
  "workspace",
14740
14664
  workspaceInstalled,
14741
- path12.join(
14742
- context.workspacePath,
14743
- context.store.getWorkspaceSkillPath(skillId)
14744
- )
14665
+ path12.join(context.workspacePath, context.store.getWorkspaceSkillPath(skillId))
14745
14666
  ),
14746
14667
  userState: this.makeScopeState(
14747
14668
  "user",
@@ -14772,10 +14693,7 @@ var SkillBridgeHandler = class {
14772
14693
  workspaceState: this.makeScopeState(
14773
14694
  "workspace",
14774
14695
  true,
14775
- path12.join(
14776
- context.workspacePath,
14777
- context.store.getWorkspaceSkillPath(skillId)
14778
- )
14696
+ path12.join(context.workspacePath, context.store.getWorkspaceSkillPath(skillId))
14779
14697
  ),
14780
14698
  userState: this.makeScopeState(
14781
14699
  "user",
@@ -14803,23 +14721,13 @@ var SkillBridgeHandler = class {
14803
14721
  workspaceState: this.makeScopeState(
14804
14722
  "workspace",
14805
14723
  workspaceSet.has(skillId),
14806
- path12.join(
14807
- context.workspacePath,
14808
- context.store.getWorkspaceSkillPath(skillId)
14809
- )
14724
+ path12.join(context.workspacePath, context.store.getWorkspaceSkillPath(skillId))
14810
14725
  ),
14811
- userState: this.makeScopeState(
14812
- "user",
14813
- true,
14814
- context.store.getUserSkillPath(skillId)
14815
- )
14726
+ userState: this.makeScopeState("user", true, context.store.getUserSkillPath(skillId))
14816
14727
  });
14817
14728
  }
14818
14729
  return {
14819
- configPath: path12.join(
14820
- context.workspacePath,
14821
- context.store.getWorkspaceMarkerPath()
14822
- ),
14730
+ configPath: path12.join(context.workspacePath, context.store.getWorkspaceMarkerPath()),
14823
14731
  userSkillsPath: context.userSkillsRoot,
14824
14732
  skills: [...byId.values()].sort((a, b) => a.id.localeCompare(b.id)),
14825
14733
  enabledSkillIds: [],
@@ -14873,10 +14781,7 @@ var SkillBridgeHandler = class {
14873
14781
  skills: workspaceSkillIds.map((skillId) => ({
14874
14782
  id: skillId,
14875
14783
  displayName: skillId,
14876
- path: path12.join(
14877
- context.workspacePath,
14878
- context.store.getWorkspaceSkillPath(skillId)
14879
- )
14784
+ path: path12.join(context.workspacePath, context.store.getWorkspaceSkillPath(skillId))
14880
14785
  }))
14881
14786
  };
14882
14787
  }
@@ -14887,7 +14792,10 @@ var SkillBridgeHandler = class {
14887
14792
  workspacePath: resolvedWorkspacePath,
14888
14793
  userSkillsRoot
14889
14794
  });
14890
- const catalogClient = new SkillCatalogClient();
14795
+ const marketplaceBaseUrl = readMarketplaceBaseUrl();
14796
+ const catalogClient = new SkillCatalogClient(
14797
+ marketplaceBaseUrl ? { baseUrl: marketplaceBaseUrl } : {}
14798
+ );
14891
14799
  const reconciler = new SkillReconciler({
14892
14800
  skillStore: store,
14893
14801
  catalogClient
@@ -14974,9 +14882,7 @@ var TaskBridgeHandler = class {
14974
14882
  constructor(logger, emitEvent) {
14975
14883
  this.logger = logger;
14976
14884
  this.emitEvent = emitEvent;
14977
- this.engine = new TaskExecutionEngine(
14978
- (taskType) => getExecutor(taskType)
14979
- );
14885
+ this.engine = new TaskExecutionEngine((taskType) => getExecutor(taskType));
14980
14886
  this.engine.setListener({
14981
14887
  onStarted: (params) => this.emitEvent("task.started", params),
14982
14888
  onOutput: (params) => this.emitEvent("task.output", params),
@@ -15113,10 +15019,7 @@ var BridgeServer = class {
15113
15019
  } catch (err) {
15114
15020
  const message = err instanceof Error ? err.message : String(err);
15115
15021
  if (message.includes("TASK_ALREADY_RUNNING")) {
15116
- this.writeError(
15117
- request.id,
15118
- createServicemeError("task_already_running", message)
15119
- );
15022
+ this.writeError(request.id, createServicemeError("task_already_running", message));
15120
15023
  } else {
15121
15024
  this.writeError(request.id, err);
15122
15025
  }
@@ -15136,9 +15039,7 @@ var BridgeServer = class {
15136
15039
  }
15137
15040
  case "skill.marketplace-state": {
15138
15041
  const skillRequest = request;
15139
- const result = await this.skillHandler.getMarketplaceState(
15140
- skillRequest.params
15141
- );
15042
+ const result = await this.skillHandler.getMarketplaceState(skillRequest.params);
15142
15043
  this.writeSuccess(request.id, result);
15143
15044
  return;
15144
15045
  }
@@ -15156,17 +15057,13 @@ var BridgeServer = class {
15156
15057
  }
15157
15058
  case "skill.publishable": {
15158
15059
  const skillRequest = request;
15159
- const result = await this.skillHandler.publishable(
15160
- skillRequest.params
15161
- );
15060
+ const result = await this.skillHandler.publishable(skillRequest.params);
15162
15061
  this.writeSuccess(request.id, result);
15163
15062
  return;
15164
15063
  }
15165
15064
  case "agent.marketplace-state": {
15166
15065
  const agentRequest = request;
15167
- const result = await this.agentHandler.getMarketplaceState(
15168
- agentRequest.params
15169
- );
15066
+ const result = await this.agentHandler.getMarketplaceState(agentRequest.params);
15170
15067
  this.writeSuccess(request.id, result);
15171
15068
  return;
15172
15069
  }
@@ -15178,19 +15075,14 @@ var BridgeServer = class {
15178
15075
  }
15179
15076
  case "agent.permissions": {
15180
15077
  const agentRequest = request;
15181
- const result = await this.agentHandler.permissions(
15182
- agentRequest.params
15183
- );
15078
+ const result = await this.agentHandler.permissions(agentRequest.params);
15184
15079
  this.writeSuccess(request.id, result);
15185
15080
  return;
15186
15081
  }
15187
15082
  default:
15188
15083
  this.writeError(
15189
15084
  request.id,
15190
- createServicemeError(
15191
- "invalid_params",
15192
- "Unsupported bridge method."
15193
- )
15085
+ createServicemeError("invalid_params", "Unsupported bridge method.")
15194
15086
  );
15195
15087
  }
15196
15088
  } catch (error) {
@@ -15293,10 +15185,7 @@ async function runEnvCommand(parsed) {
15293
15185
  const tool = getStringFlag(parsed, "tool");
15294
15186
  if (tool) {
15295
15187
  if (!isKnownEnvironmentTool(tool)) {
15296
- throw createServicemeError(
15297
- "invalid_params",
15298
- `Unsupported environment tool: ${tool}`
15299
- );
15188
+ throw createServicemeError("invalid_params", `Unsupported environment tool: ${tool}`);
15300
15189
  }
15301
15190
  writeSuccess(await inspector.checkTool(tool));
15302
15191
  return;
@@ -15326,10 +15215,7 @@ async function runImageCommand(parsed) {
15326
15215
  case "compress": {
15327
15216
  const format = getStringFlag(parsed, "format");
15328
15217
  if (format && !IMAGE_FORMATS.has(format)) {
15329
- throw createServicemeError(
15330
- "invalid_params",
15331
- `Unsupported image format: ${format}`
15332
- );
15218
+ throw createServicemeError("invalid_params", `Unsupported image format: ${format}`);
15333
15219
  }
15334
15220
  const options2 = {
15335
15221
  quality: Number(getStringFlag(parsed, "quality") ?? "75"),
@@ -15342,9 +15228,7 @@ async function runImageCommand(parsed) {
15342
15228
  return;
15343
15229
  }
15344
15230
  default:
15345
- throw new Error(
15346
- "Unsupported image command. Use validate, info, or compress."
15347
- );
15231
+ throw new Error("Unsupported image command. Use validate, info, or compress.");
15348
15232
  }
15349
15233
  }
15350
15234
 
@@ -15391,10 +15275,7 @@ async function runJsonCommand(parsed) {
15391
15275
  }
15392
15276
  case "format":
15393
15277
  writeSuccess({
15394
- output: jsonTools.format(
15395
- input,
15396
- Number(getStringFlag(parsed, "indent") ?? "2")
15397
- )
15278
+ output: jsonTools.format(input, Number(getStringFlag(parsed, "indent") ?? "2"))
15398
15279
  });
15399
15280
  return;
15400
15281
  case "minify":
@@ -15406,9 +15287,7 @@ async function runJsonCommand(parsed) {
15406
15287
  writeSuccess(jsonTools.validate(input));
15407
15288
  return;
15408
15289
  default:
15409
- throw new Error(
15410
- "Unsupported json command. Use sort, format, minify, or validate."
15411
- );
15290
+ throw new Error("Unsupported json command. Use sort, format, minify, or validate.");
15412
15291
  }
15413
15292
  }
15414
15293
 
@@ -15420,10 +15299,7 @@ async function runProjectCommand(parsed) {
15420
15299
  const action = parsed.positionals[1];
15421
15300
  const workspacePath = getStringFlag(parsed, "workspacePath");
15422
15301
  if (!workspacePath) {
15423
- throw createServicemeError(
15424
- "invalid_params",
15425
- "Expected --workspacePath <path>."
15426
- );
15302
+ throw createServicemeError("invalid_params", "Expected --workspacePath <path>.");
15427
15303
  }
15428
15304
  switch (action) {
15429
15305
  case "extract-template": {
@@ -15442,21 +15318,13 @@ async function runProjectCommand(parsed) {
15442
15318
  projectFilePattern
15443
15319
  };
15444
15320
  writeSuccess(
15445
- await projectTools.extractTemplate(
15446
- zipPath,
15447
- workspacePath,
15448
- tempExtractDir,
15449
- input
15450
- )
15321
+ await projectTools.extractTemplate(zipPath, workspacePath, tempExtractDir, input)
15451
15322
  );
15452
15323
  return;
15453
15324
  }
15454
15325
  case "install-deps":
15455
15326
  writeSuccess(
15456
- await projectTools.installDependencies(
15457
- workspacePath,
15458
- getStringFlag(parsed, "command")
15459
- )
15327
+ await projectTools.installDependencies(workspacePath, getStringFlag(parsed, "command"))
15460
15328
  );
15461
15329
  return;
15462
15330
  case "make-scripts-executable":
@@ -15467,10 +15335,7 @@ async function runProjectCommand(parsed) {
15467
15335
  return;
15468
15336
  case "scaffold-prune":
15469
15337
  writeSuccess(
15470
- await projectTools.runScaffoldPrune(
15471
- workspacePath,
15472
- getStringFlag(parsed, "preset")
15473
- )
15338
+ await projectTools.runScaffoldPrune(workspacePath, getStringFlag(parsed, "preset"))
15474
15339
  );
15475
15340
  return;
15476
15341
  default:
@@ -15525,26 +15390,17 @@ async function runScheduleCommand(parsed) {
15525
15390
  function requireWorkspace(parsed) {
15526
15391
  const wp = getStringFlag(parsed, "workspacePath");
15527
15392
  if (!wp) {
15528
- throw createServicemeError(
15529
- "invalid_params",
15530
- "Missing required flag: --workspacePath"
15531
- );
15393
+ throw createServicemeError("invalid_params", "Missing required flag: --workspacePath");
15532
15394
  }
15533
15395
  if (!fs16.existsSync(wp)) {
15534
- throw createServicemeError(
15535
- "workspace_not_found",
15536
- `Workspace path does not exist: ${wp}`
15537
- );
15396
+ throw createServicemeError("workspace_not_found", `Workspace path does not exist: ${wp}`);
15538
15397
  }
15539
15398
  return wp;
15540
15399
  }
15541
15400
  function requireId(parsed) {
15542
15401
  const id = getStringFlag(parsed, "id");
15543
15402
  if (!id) {
15544
- throw createServicemeError(
15545
- "invalid_params",
15546
- "Missing required flag: --id <task-id>"
15547
- );
15403
+ throw createServicemeError("invalid_params", "Missing required flag: --id <task-id>");
15548
15404
  }
15549
15405
  return id;
15550
15406
  }
@@ -15565,10 +15421,7 @@ function parsePayload(parsed, taskType) {
15565
15421
  try {
15566
15422
  return JSON.parse(payloadJson);
15567
15423
  } catch {
15568
- throw createServicemeError(
15569
- "invalid_payload",
15570
- "Invalid --payload-json: must be valid JSON"
15571
- );
15424
+ throw createServicemeError("invalid_payload", "Invalid --payload-json: must be valid JSON");
15572
15425
  }
15573
15426
  }
15574
15427
  switch (taskType) {
@@ -15617,10 +15470,7 @@ function parsePayload(parsed, taskType) {
15617
15470
  };
15618
15471
  }
15619
15472
  default:
15620
- throw createServicemeError(
15621
- "invalid_payload",
15622
- `Unknown task type: ${taskType}`
15623
- );
15473
+ throw createServicemeError("invalid_payload", `Unknown task type: ${taskType}`);
15624
15474
  }
15625
15475
  }
15626
15476
  function parseScheduleType(schedule) {
@@ -15630,9 +15480,7 @@ function parseScheduleType(schedule) {
15630
15480
  function validateSchedule(schedule) {
15631
15481
  const scheduleType = parseScheduleType(schedule);
15632
15482
  if (scheduleType === "interval") {
15633
- const match = /^every\s+(\d+)\s*(s|sec|m|min|h|hr|d|day)s?$/i.exec(
15634
- schedule
15635
- );
15483
+ const match = /^every\s+(\d+)\s*(s|sec|m|min|h|hr|d|day)s?$/i.exec(schedule);
15636
15484
  if (!match) {
15637
15485
  throw createServicemeError(
15638
15486
  "invalid_schedule",
@@ -15663,11 +15511,7 @@ function filterFields(obj, fields) {
15663
15511
  async function handleCreate(parsed) {
15664
15512
  const wp = requireWorkspace(parsed);
15665
15513
  const name = getStringFlag(parsed, "name");
15666
- if (!name)
15667
- throw createServicemeError(
15668
- "invalid_params",
15669
- "Missing required flag: --name"
15670
- );
15514
+ if (!name) throw createServicemeError("invalid_params", "Missing required flag: --name");
15671
15515
  const typeStr = getStringFlag(parsed, "type");
15672
15516
  if (!typeStr)
15673
15517
  throw createServicemeError(
@@ -15682,11 +15526,7 @@ async function handleCreate(parsed) {
15682
15526
  );
15683
15527
  }
15684
15528
  const schedule = getStringFlag(parsed, "schedule");
15685
- if (!schedule)
15686
- throw createServicemeError(
15687
- "invalid_params",
15688
- "Missing required flag: --schedule"
15689
- );
15529
+ if (!schedule) throw createServicemeError("invalid_params", "Missing required flag: --schedule");
15690
15530
  validateSchedule(schedule);
15691
15531
  const payload = parsePayload(parsed, taskType);
15692
15532
  const description = getStringFlag(parsed, "description");
@@ -15748,16 +15588,10 @@ function handleGet(parsed) {
15748
15588
  const mgr = new TaskConfigManager(wp);
15749
15589
  const task = mgr.getTask(id);
15750
15590
  if (!task) {
15751
- throw createServicemeError(
15752
- "task_not_found",
15753
- `Task '${id}' does not exist in this workspace`
15754
- );
15591
+ throw createServicemeError("task_not_found", `Task '${id}' does not exist in this workspace`);
15755
15592
  }
15756
15593
  const fields = getStringFlag(parsed, "fields");
15757
- const result = filterFields(
15758
- task,
15759
- fields
15760
- );
15594
+ const result = filterFields(task, fields);
15761
15595
  writeSuccess({ task: result });
15762
15596
  }
15763
15597
  async function handleEdit(parsed) {
@@ -15766,10 +15600,7 @@ async function handleEdit(parsed) {
15766
15600
  const mgr = new TaskConfigManager(wp);
15767
15601
  const existing = mgr.getTask(id);
15768
15602
  if (!existing) {
15769
- throw createServicemeError(
15770
- "task_not_found",
15771
- `Task '${id}' does not exist in this workspace`
15772
- );
15603
+ throw createServicemeError("task_not_found", `Task '${id}' does not exist in this workspace`);
15773
15604
  }
15774
15605
  const input = {};
15775
15606
  const name = getStringFlag(parsed, "name");
@@ -15791,10 +15622,7 @@ async function handleEdit(parsed) {
15791
15622
  try {
15792
15623
  input.payload = JSON.parse(payloadJson);
15793
15624
  } catch {
15794
- throw createServicemeError(
15795
- "invalid_payload",
15796
- "Invalid --payload-json: must be valid JSON"
15797
- );
15625
+ throw createServicemeError("invalid_payload", "Invalid --payload-json: must be valid JSON");
15798
15626
  }
15799
15627
  }
15800
15628
  if (getBooleanFlag(parsed, "dry-run")) {
@@ -15817,10 +15645,7 @@ function handleDelete(parsed) {
15817
15645
  const mgr = new TaskConfigManager(wp);
15818
15646
  const existing = mgr.getTask(id);
15819
15647
  if (!existing) {
15820
- throw createServicemeError(
15821
- "task_not_found",
15822
- `Task '${id}' does not exist in this workspace`
15823
- );
15648
+ throw createServicemeError("task_not_found", `Task '${id}' does not exist in this workspace`);
15824
15649
  }
15825
15650
  if (getBooleanFlag(parsed, "dry-run")) {
15826
15651
  writeSuccess({ action: "delete", task: existing });
@@ -15834,19 +15659,13 @@ function handleToggle(parsed) {
15834
15659
  const id = requireId(parsed);
15835
15660
  const enabledStr = getStringFlag(parsed, "enabled");
15836
15661
  if (enabledStr === void 0) {
15837
- throw createServicemeError(
15838
- "invalid_params",
15839
- "Missing required flag: --enabled <true|false>"
15840
- );
15662
+ throw createServicemeError("invalid_params", "Missing required flag: --enabled <true|false>");
15841
15663
  }
15842
15664
  const enabled = enabledStr !== "false";
15843
15665
  const mgr = new TaskConfigManager(wp);
15844
15666
  const existing = mgr.getTask(id);
15845
15667
  if (!existing) {
15846
- throw createServicemeError(
15847
- "task_not_found",
15848
- `Task '${id}' does not exist in this workspace`
15849
- );
15668
+ throw createServicemeError("task_not_found", `Task '${id}' does not exist in this workspace`);
15850
15669
  }
15851
15670
  const task = mgr.toggleTask(id, enabled);
15852
15671
  writeSuccess({ task });
@@ -15857,17 +15676,10 @@ async function handleTrigger(parsed) {
15857
15676
  const mgr = new TaskConfigManager(wp);
15858
15677
  const task = mgr.getTask(id);
15859
15678
  if (!task) {
15860
- throw createServicemeError(
15861
- "task_not_found",
15862
- `Task '${id}' does not exist in this workspace`
15863
- );
15679
+ throw createServicemeError("task_not_found", `Task '${id}' does not exist in this workspace`);
15864
15680
  }
15865
15681
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
15866
- const executionPayload = resolveTaskExecutionPayload(
15867
- task.taskType,
15868
- task.payload,
15869
- wp
15870
- );
15682
+ const executionPayload = resolveTaskExecutionPayload(task.taskType, task.payload, wp);
15871
15683
  validateTaskPayload(task.taskType, executionPayload);
15872
15684
  const executor = getExecutor(task.taskType);
15873
15685
  const result = await executor.execute(executionPayload);
@@ -15892,9 +15704,7 @@ function handleLogs(parsed) {
15892
15704
  const fields = getStringFlag(parsed, "fields");
15893
15705
  const logMgr = new TaskLogManager(wp);
15894
15706
  const { logs, total } = logMgr.getLogs({ taskId, limit });
15895
- const result = logs.map(
15896
- (l) => filterFields(l, fields)
15897
- );
15707
+ const result = logs.map((l) => filterFields(l, fields));
15898
15708
  writeSuccess({ logs: result, total });
15899
15709
  }
15900
15710
  function writeDescribe(action) {
@@ -16097,16 +15907,10 @@ async function runSchedulerCommand(parsed) {
16097
15907
  function requireWorkspace2(parsed) {
16098
15908
  const wp = getStringFlag(parsed, "workspacePath");
16099
15909
  if (!wp) {
16100
- throw createServicemeError(
16101
- "invalid_params",
16102
- "Missing required flag: --workspacePath"
16103
- );
15910
+ throw createServicemeError("invalid_params", "Missing required flag: --workspacePath");
16104
15911
  }
16105
15912
  if (!fs17.existsSync(wp)) {
16106
- throw createServicemeError(
16107
- "workspace_not_found",
16108
- `Workspace path does not exist: ${wp}`
16109
- );
15913
+ throw createServicemeError("workspace_not_found", `Workspace path does not exist: ${wp}`);
16110
15914
  }
16111
15915
  return wp;
16112
15916
  }
@@ -16124,10 +15928,7 @@ function handleStart(parsed) {
16124
15928
  }
16125
15929
  const cliPath = process.argv[1];
16126
15930
  if (!cliPath) {
16127
- throw createServicemeError(
16128
- "internal_error",
16129
- "Cannot determine CLI path for daemon spawn"
16130
- );
15931
+ throw createServicemeError("internal_error", "Cannot determine CLI path for daemon spawn");
16131
15932
  }
16132
15933
  const logPath = path13.join(wp, ".serviceme", "scheduler.log");
16133
15934
  const logDir = path13.dirname(logPath);
@@ -16135,15 +15936,7 @@ function handleStart(parsed) {
16135
15936
  fs17.mkdirSync(logDir, { recursive: true });
16136
15937
  }
16137
15938
  const spawnCmd = process.execPath;
16138
- const spawnArgs = [
16139
- cliPath,
16140
- "scheduler",
16141
- "__daemon",
16142
- "--workspacePath",
16143
- wp,
16144
- "--logPath",
16145
- logPath
16146
- ];
15939
+ const spawnArgs = [cliPath, "scheduler", "__daemon", "--workspacePath", wp, "--logPath", logPath];
16147
15940
  if (process.platform === "win32") {
16148
15941
  fs17.appendFileSync(
16149
15942
  logPath,
@@ -16171,10 +15964,7 @@ function handleStart(parsed) {
16171
15964
  child.unref();
16172
15965
  const pid = child.pid;
16173
15966
  if (pid === void 0) {
16174
- throw createServicemeError(
16175
- "internal_error",
16176
- "Failed to spawn daemon process"
16177
- );
15967
+ throw createServicemeError("internal_error", "Failed to spawn daemon process");
16178
15968
  }
16179
15969
  pidMgr.writePid(pid);
16180
15970
  writeSuccess({ pid, status: "started", workspacePath: wp });
@@ -16356,10 +16146,7 @@ async function runSkillCommand(parsed) {
16356
16146
  const action = parsed.positionals[1];
16357
16147
  const workspacePath = getStringFlag(parsed, "workspacePath");
16358
16148
  if (!workspacePath) {
16359
- throw createServicemeError(
16360
- "invalid_params",
16361
- "Expected --workspacePath <path>."
16362
- );
16149
+ throw createServicemeError("invalid_params", "Expected --workspacePath <path>.");
16363
16150
  }
16364
16151
  const store = new SkillStore({
16365
16152
  workspacePath,
@@ -16377,9 +16164,7 @@ async function runSkillCommand(parsed) {
16377
16164
  writeSuccess(await handleList3(store));
16378
16165
  return;
16379
16166
  case "install":
16380
- writeSuccess(
16381
- await handleInstall2(store, workspacePath, parsed, catalogClient)
16382
- );
16167
+ writeSuccess(await handleInstall2(store, workspacePath, parsed, catalogClient));
16383
16168
  return;
16384
16169
  case "uninstall":
16385
16170
  writeSuccess(await handleUninstall2(store, workspacePath, parsed));
@@ -16415,13 +16200,10 @@ async function handleList3(store) {
16415
16200
  ]
16416
16201
  };
16417
16202
  }
16418
- async function handleInstall2(store, workspacePath, parsed, catalogClient) {
16203
+ async function handleInstall2(store, _workspacePath, parsed, catalogClient) {
16419
16204
  const remoteId = getStringFlag(parsed, "id");
16420
16205
  if (!remoteId) {
16421
- throw createServicemeError(
16422
- "invalid_params",
16423
- "Expected --id <remoteSkillId>."
16424
- );
16206
+ throw createServicemeError("invalid_params", "Expected --id <remoteSkillId>.");
16425
16207
  }
16426
16208
  const skillId = normalizeSkillIdOrThrow2(store, remoteId);
16427
16209
  if (!getBooleanFlag(parsed, "confirmed")) {
@@ -16479,10 +16261,7 @@ async function handleInstall2(store, workspacePath, parsed, catalogClient) {
16479
16261
  async function handleUninstall2(store, workspacePath, parsed) {
16480
16262
  const remoteId = getStringFlag(parsed, "id");
16481
16263
  if (!remoteId) {
16482
- throw createServicemeError(
16483
- "invalid_params",
16484
- "Expected --id <remoteSkillId>."
16485
- );
16264
+ throw createServicemeError("invalid_params", "Expected --id <remoteSkillId>.");
16486
16265
  }
16487
16266
  const skillId = normalizeSkillIdOrThrow2(store, remoteId);
16488
16267
  await fs18.rm(path14.join(workspacePath, store.getWorkspaceSkillPath(skillId)), {
@@ -16508,16 +16287,10 @@ async function handleMove2(store, workspacePath, parsed) {
16508
16287
  );
16509
16288
  }
16510
16289
  if (to !== "workspace" && to !== "user") {
16511
- throw createServicemeError(
16512
- "invalid_params",
16513
- "Expected --to value to be workspace or user."
16514
- );
16290
+ throw createServicemeError("invalid_params", "Expected --to value to be workspace or user.");
16515
16291
  }
16516
16292
  const skillId = normalizeSkillIdOrThrow2(store, remoteId);
16517
- const workspacePathForSkill = path14.join(
16518
- workspacePath,
16519
- store.getWorkspaceSkillPath(skillId)
16520
- );
16293
+ const workspacePathForSkill = path14.join(workspacePath, store.getWorkspaceSkillPath(skillId));
16521
16294
  const userPathForSkill = store.getUserSkillPath(skillId);
16522
16295
  if (to === "user") {
16523
16296
  await moveDirectory(workspacePathForSkill, userPathForSkill);
@@ -16595,10 +16368,7 @@ async function handleMarketplace2(store, catalogClient) {
16595
16368
  async function handleFind(store, catalogClient, parsed) {
16596
16369
  const query = getStringFlag(parsed, "query") ?? getStringFlag(parsed, "q");
16597
16370
  if (!query) {
16598
- throw createServicemeError(
16599
- "invalid_params",
16600
- "Expected --query <text> or --q <text>."
16601
- );
16371
+ throw createServicemeError("invalid_params", "Expected --query <text> or --q <text>.");
16602
16372
  }
16603
16373
  const marketplace = await handleMarketplace2(store, catalogClient);
16604
16374
  const loweredQuery = query.toLowerCase();
@@ -16626,10 +16396,7 @@ async function handleReconcile(store, reconciler) {
16626
16396
  }
16627
16397
  const firstWorkspaceSkillId = workspaceSkillIds[0];
16628
16398
  if (!firstWorkspaceSkillId) {
16629
- throw createServicemeError(
16630
- "not_found",
16631
- "No workspace skill id available for gate check."
16632
- );
16399
+ throw createServicemeError("not_found", "No workspace skill id available for gate check.");
16633
16400
  }
16634
16401
  const gateCheck = await reconciler.mutate({
16635
16402
  skillId: firstWorkspaceSkillId,