@lesscap/baton-cli 0.2.4 → 0.2.5

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 +35 -13
  2. package/package.json +1 -1
package/dist/baton.mjs CHANGED
@@ -768,7 +768,11 @@ var common = {
768
768
  },
769
769
  json: { type: "boolean", description: "output JSON" }
770
770
  };
771
- var clientFor = (args) => createClient(resolveBaseUrl(args.url));
771
+ var clientFor = (args) => {
772
+ const envAuth = process.env.BATON_TOKEN ?? (process.env.BATON_USER && process.env.BATON_PASS);
773
+ const cfgToken = envAuth ? void 0 : loadProjectConfigOrNull(projectConfigPath())?.worker?.apiToken;
774
+ return createClient(resolveBaseUrl(args.url), cfgToken ? { bearer: cfgToken } : void 0);
775
+ };
772
776
  var resolveProjectId = (args) => {
773
777
  if (args.project !== void 0 && args.project !== "") return Number(args.project);
774
778
  const cfg = loadProjectConfigOrNull(projectConfigPath());
@@ -783,6 +787,10 @@ var resolveWorkspaceId = (args) => {
783
787
  "no workspace in scope. pass --workspace <id> or run `baton init` in this directory."
784
788
  );
785
789
  };
790
+ var parseWorkerHandle = (handle) => {
791
+ const m = handle.trim().match(/^(?:[wW]-)?(\d+)$/);
792
+ return m ? Number(m[1]) : null;
793
+ };
786
794
  var parseIssueUrl = (url) => {
787
795
  const m = url.match(/^https:\/\/github\.com\/[^/]+\/[^/]+\/issues\/(\d+)/);
788
796
  if (!m)
@@ -863,7 +871,7 @@ var fmtComment = (c) => `${c.workerId !== void 0 ? `worker#${c.workerId}` : "you
863
871
  var fmtSession = (s) => `${s.id} ${s.name} ${s.attached ? "[active]" : "[inactive]"} ${s.worktreePath ?? "(pending)"}`;
864
872
  var fmtWorker = (w) => {
865
873
  const offline = w.alive === false ? " [offline]" : "";
866
- return `${w.id} ${w.name} ${w.hostname}${offline}`;
874
+ return `W-${w.id} ${w.name} ${w.hostname}${offline}`;
867
875
  };
868
876
  var renderOne = (item, fmt, json) => json ? toJson(item) : fmt(item);
869
877
  var renderList = (items, fmt, json) => {
@@ -1113,7 +1121,10 @@ var resolveSession = async (client, projectId, handle) => {
1113
1121
 
1114
1122
  // src/commands/session/abort.ts
1115
1123
  var sessionAbortCommand = defineCommand({
1116
- meta: { name: "abort", description: "interrupt the in-flight turn (like Esc); keeps the session" },
1124
+ meta: {
1125
+ name: "abort",
1126
+ description: "interrupt the in-flight turn (like Esc); keeps the session"
1127
+ },
1117
1128
  args: {
1118
1129
  session: { type: "positional", required: true, description: "session int id or name" },
1119
1130
  project: { type: "string", description: "project id (overrides .baton.json)" },
@@ -1129,7 +1140,10 @@ var sessionAbortCommand = defineCommand({
1129
1140
 
1130
1141
  // src/commands/session/clear.ts
1131
1142
  var sessionClearCommand = defineCommand({
1132
- meta: { name: "clear", description: "reset the conversation context (keeps the session + worktree)" },
1143
+ meta: {
1144
+ name: "clear",
1145
+ description: "reset the conversation context (keeps the session + worktree)"
1146
+ },
1133
1147
  args: {
1134
1148
  session: { type: "positional", required: true, description: "session int id or name" },
1135
1149
  project: { type: "string", description: "project id (overrides .baton.json)" },
@@ -1148,16 +1162,24 @@ var sessionCreateCommand = defineCommand({
1148
1162
  meta: { name: "create", description: "create + start a session on a worker" },
1149
1163
  args: {
1150
1164
  name: { type: "positional", required: true, description: "session name" },
1151
- worker: { type: "string", description: "worker id (default: this machine's worker)" },
1152
- project: { type: "string", description: "project id (overrides .baton.json)" },
1165
+ worker: {
1166
+ type: "string",
1167
+ description: "worker handle: W-N or int id (default: this machine's worker)"
1168
+ },
1169
+ project: {
1170
+ type: "string",
1171
+ description: "project id (default: the worker's own project, else .baton.json)"
1172
+ },
1153
1173
  ...common
1154
1174
  },
1155
1175
  run: async ({ args }) => {
1156
1176
  const c = clientFor(args);
1157
- const projectId = resolveProjectId(args);
1158
- const workerId = args.worker ? Number(args.worker) : loadProjectConfigOrNull(projectConfigPath())?.worker?.id;
1159
- if (!workerId)
1160
- throw new Error("no worker id \u2014 pass --worker or run `baton worker register` first");
1177
+ const workerId = args.worker ? parseWorkerHandle(args.worker) : loadProjectConfigOrNull(projectConfigPath())?.worker?.id ?? null;
1178
+ if (workerId === null)
1179
+ throw new Error(
1180
+ "no worker \u2014 pass --worker <W-N|id> or run `baton worker register` first (names need --project)"
1181
+ );
1182
+ const projectId = args.project !== void 0 && args.project !== "" ? Number(args.project) : args.worker ? (await c.workers.get(workerId)).projectId : resolveProjectId(args);
1161
1183
  const s = await c.sessions.create({ projectId, workerId, name: args.name });
1162
1184
  console.log(renderOne(s, fmtSession, Boolean(args.json)));
1163
1185
  }
@@ -2750,9 +2772,9 @@ var readOrCreateMachineId = (path = machineIdPath()) => {
2750
2772
 
2751
2773
  // src/commands/worker.ts
2752
2774
  var resolveWorker = async (client, projectId, handle) => {
2753
- const asInt = Number(handle);
2754
- if (Number.isInteger(asInt) && asInt > 0) {
2755
- const byId = await client.workers.get(asInt).catch(() => null);
2775
+ const asId = parseWorkerHandle(handle);
2776
+ if (asId !== null) {
2777
+ const byId = await client.workers.get(asId).catch(() => null);
2756
2778
  if (byId) return { id: byId.id, name: byId.name };
2757
2779
  }
2758
2780
  const byName = await client.workers.findByName(projectId, handle);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lesscap/baton-cli",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "type": "module",
5
5
  "description": "baton CLI — register/run a worker, manage projects/requirements/tasks/sessions",
6
6
  "bin": {