@lesscap/baton-cli 0.7.6 → 0.7.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.
Files changed (2) hide show
  1. package/dist/baton.mjs +43 -8
  2. package/package.json +1 -1
package/dist/baton.mjs CHANGED
@@ -5390,6 +5390,20 @@ var labelAttachments = (attachments) => {
5390
5390
  // ../shared/src/domain/channel.ts
5391
5391
  var isMessageFor = (msg, name) => !msg.to || msg.to.length === 0 || msg.to.includes(name);
5392
5392
 
5393
+ // ../shared/src/domain/service.ts
5394
+ var SERVICE_PUBLIC_URL_MAX_LENGTH = 2048;
5395
+ var SERVICE_NOTE_MAX_LENGTH = 500;
5396
+ var isServicePublicUrl = (value) => {
5397
+ if (value.length === 0 || value.length > SERVICE_PUBLIC_URL_MAX_LENGTH) return false;
5398
+ try {
5399
+ const url = new URL(value);
5400
+ return url.protocol === "http:" || url.protocol === "https:";
5401
+ } catch {
5402
+ return false;
5403
+ }
5404
+ };
5405
+ var isServiceNote = (value) => value.length > 0 && value.length <= SERVICE_NOTE_MAX_LENGTH;
5406
+
5393
5407
  // ../shared/src/domain/session-event.ts
5394
5408
  var agentMessageText = (payload) => {
5395
5409
  if (typeof payload !== "object" || payload === null) return null;
@@ -6365,21 +6379,32 @@ var runCommand2 = defineCommand({
6365
6379
  meta: { name: "run", description: "run a service on the current worker" },
6366
6380
  args: {
6367
6381
  name: { type: "positional", required: true, description: "service name" },
6382
+ "public-url": { type: "string", description: "public HTTP(S) URL for this service" },
6383
+ note: { type: "string", description: "short note describing this service" },
6368
6384
  ...common
6369
6385
  },
6370
6386
  run: async ({ args, rawArgs }) => {
6371
6387
  const separator = rawArgs.indexOf("--");
6372
6388
  const argv = separator === -1 ? [] : rawArgs.slice(separator + 1);
6373
6389
  if (argv.length === 0) throw new Error("command required after `--`");
6390
+ const publicUrl = args["public-url"]?.trim() || void 0;
6391
+ const note = args.note?.trim() || void 0;
6392
+ if (publicUrl && !isServicePublicUrl(publicUrl))
6393
+ throw new Error("--public-url must be an absolute HTTP(S) URL");
6394
+ if (note && !isServiceNote(note))
6395
+ throw new Error("service note must be 500 characters or fewer");
6374
6396
  const context = currentContext();
6375
6397
  const result = await clientFor(args).services.run(context.workerId, {
6376
6398
  sessionId: context.sessionId,
6377
6399
  name: args.name,
6378
- argv
6400
+ argv,
6401
+ ...publicUrl ? { publicUrl } : {},
6402
+ ...note ? { note } : {}
6379
6403
  });
6380
6404
  if (!result.ok) throw new Error(result.error);
6381
6405
  if (args.json) return console.log(toJson(result));
6382
6406
  console.log(`running W-${context.workerId}/${args.name}`);
6407
+ if (publicUrl) console.log(`public: ${publicUrl}`);
6383
6408
  if (result.logPath) console.log(`logs: ${result.logPath}`);
6384
6409
  }
6385
6410
  });
@@ -8071,7 +8096,13 @@ var createServiceSupervisor = (deps) => {
8071
8096
  const { getSession, sendReport, cfg, log } = deps;
8072
8097
  const entries = /* @__PURE__ */ new Map();
8073
8098
  let reportQueue = Promise.resolve();
8074
- const snapshot = () => [...entries.values()].filter((entry) => entry.appPid !== void 0).map(({ sessionId, name, startedAt }) => ({ sessionId, name, startedAt }));
8099
+ const snapshot = () => [...entries.values()].filter((entry) => entry.appPid !== void 0).map(({ sessionId, name, startedAt, publicUrl, note }) => ({
8100
+ sessionId,
8101
+ name,
8102
+ startedAt,
8103
+ ...publicUrl ? { publicUrl } : {},
8104
+ ...note ? { note } : {}
8105
+ }));
8075
8106
  const report = (result) => {
8076
8107
  const body = { services: snapshot(), ...result ? { result } : {} };
8077
8108
  const request2 = reportQueue.then(() => sendReport(body)).then(() => {
@@ -8093,7 +8124,7 @@ var createServiceSupervisor = (deps) => {
8093
8124
  }
8094
8125
  if (entry.appPid) killPidGroup(entry.appPid, "SIGKILL");
8095
8126
  };
8096
- const runOne = async (requestId, sessionId, name, argv) => {
8127
+ const runOne = async (requestId, sessionId, name, argv, publicUrl, note) => {
8097
8128
  if (entries.has(name))
8098
8129
  return report({
8099
8130
  requestId,
@@ -8117,7 +8148,9 @@ var createServiceSupervisor = (deps) => {
8117
8148
  wrapper,
8118
8149
  sessionId,
8119
8150
  name,
8120
- startedAt: Date.now()
8151
+ startedAt: Date.now(),
8152
+ publicUrl,
8153
+ note
8121
8154
  };
8122
8155
  entries.set(name, entry);
8123
8156
  wrapper.once("exit", (code) => {
@@ -8134,14 +8167,16 @@ var createServiceSupervisor = (deps) => {
8134
8167
  workerId: cfg.workerId,
8135
8168
  sessionId,
8136
8169
  name,
8137
- startedAt: entry.startedAt
8170
+ startedAt: entry.startedAt,
8171
+ ...publicUrl ? { publicUrl } : {},
8172
+ ...note ? { note } : {}
8138
8173
  };
8139
8174
  log(`service ${name} started in ${session2.worktreePath}`);
8140
8175
  await report({ requestId, ok: true, service: service2, logPath });
8141
8176
  };
8142
- const run = async (requestId, sessionId, name, argv) => {
8177
+ const run = async (requestId, sessionId, name, argv, publicUrl, note) => {
8143
8178
  try {
8144
- await runOne(requestId, sessionId, name, argv);
8179
+ await runOne(requestId, sessionId, name, argv, publicUrl, note);
8145
8180
  } catch (error) {
8146
8181
  await report({ requestId, ok: false, error: String(error), status: 500 });
8147
8182
  }
@@ -8639,7 +8674,7 @@ var runWorkerDaemon = async (cfg, client, signal) => {
8639
8674
  terminals.open(cmd.sessionId, cmd.agentSessionId, cmd.worktreePath);
8640
8675
  else terminals.close(cmd.sessionId);
8641
8676
  } else if (cmd.cmd === "service.run")
8642
- void services.run(cmd.requestId, cmd.sessionId, cmd.name, cmd.argv).catch((err) => log(`service run failed: ${String(err)}`));
8677
+ void services.run(cmd.requestId, cmd.sessionId, cmd.name, cmd.argv, cmd.publicUrl, cmd.note).catch((err) => log(`service run failed: ${String(err)}`));
8643
8678
  else if (cmd.cmd === "service.stop")
8644
8679
  void services.stop(cmd.requestId, cmd.name).catch((err) => log(`service stop failed: ${String(err)}`));
8645
8680
  } catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lesscap/baton-cli",
3
- "version": "0.7.6",
3
+ "version": "0.7.7",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"