@lesscap/baton-cli 0.2.7 → 0.2.9

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 (3) hide show
  1. package/LICENSE +21 -0
  2. package/dist/baton.mjs +43 -89
  3. package/package.json +11 -12
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 bencode
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/baton.mjs CHANGED
@@ -700,6 +700,7 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
700
700
  import { join } from "node:path";
701
701
  var PROJECT_CONFIG_NAME = ".baton.json";
702
702
  var projectConfigPath = (cwd = process.cwd()) => join(cwd, PROJECT_CONFIG_NAME);
703
+ var configPathFromArgs = (args, cwd) => args.config ?? projectConfigPath(cwd);
703
704
  var loadProjectConfig = (path) => {
704
705
  try {
705
706
  return JSON.parse(readFileSync(path, "utf8"));
@@ -798,12 +799,6 @@ var parseWorkerHandle = (handle) => {
798
799
  const m = handle.trim().match(/^(?:[wW]-)?(\d+)$/);
799
800
  return m ? Number(m[1]) : null;
800
801
  };
801
- var parseIssueUrl = (url) => {
802
- const m = url.match(/^https:\/\/github\.com\/[^/]+\/[^/]+\/issues\/(\d+)/);
803
- if (!m)
804
- throw new Error(`expected a GitHub issue url (https://github.com/o/r/issues/N), got "${url}"`);
805
- return { source: "github", number: Number(m[1]), url: url.split(/[?#]/)[0] };
806
- };
807
802
  var splitCsv = (s) => s ? s.split(",").map((x) => x.trim()).filter(Boolean) : void 0;
808
803
 
809
804
  // src/commands/init.ts
@@ -979,7 +974,6 @@ var requirement = defineCommand({
979
974
  project: { type: "string", description: "project id (overrides .baton.json)" },
980
975
  desc: { type: "string", description: "description" },
981
976
  body: { type: "string", description: "requirement body (markdown)" },
982
- github: { type: "string", description: "link a GitHub issue url (light association)" },
983
977
  ...common
984
978
  },
985
979
  run: async ({ args }) => {
@@ -990,8 +984,7 @@ var requirement = defineCommand({
990
984
  projectId: resolveProjectId(args),
991
985
  title: args.title,
992
986
  description: args.desc,
993
- body: args.body,
994
- external: args.github ? parseIssueUrl(args.github) : void 0
987
+ body: args.body
995
988
  },
996
989
  Boolean(args.json)
997
990
  )
@@ -1018,41 +1011,6 @@ var requirement = defineCommand({
1018
1011
  console.log(await updateRequirement(c, id, patch2, Boolean(args.json)));
1019
1012
  }
1020
1013
  }),
1021
- link: defineCommand({
1022
- meta: { name: "link", description: "link a requirement to a GitHub issue url" },
1023
- args: {
1024
- code: { type: "positional", required: true, description: "requirement code (R-N)" },
1025
- // Named `issue` (not `url`) — `url` would collide with the common --url flag.
1026
- issue: { type: "positional", required: true, description: "GitHub issue url" },
1027
- project: { type: "string", description: "project id (overrides .baton.json)" },
1028
- ...common
1029
- },
1030
- run: async ({ args }) => {
1031
- const c = clientFor(args);
1032
- const id = await resolveByCode(c, resolveProjectId(args), args.code);
1033
- console.log(
1034
- await updateRequirement(
1035
- c,
1036
- id,
1037
- { external: parseIssueUrl(args.issue) },
1038
- Boolean(args.json)
1039
- )
1040
- );
1041
- }
1042
- }),
1043
- unlink: defineCommand({
1044
- meta: { name: "unlink", description: "clear a requirement\u2019s GitHub issue association" },
1045
- args: {
1046
- code: { type: "positional", required: true, description: "requirement code (R-N)" },
1047
- project: { type: "string", description: "project id (overrides .baton.json)" },
1048
- ...common
1049
- },
1050
- run: async ({ args }) => {
1051
- const c = clientFor(args);
1052
- const id = await resolveByCode(c, resolveProjectId(args), args.code);
1053
- console.log(await updateRequirement(c, id, { external: null }, Boolean(args.json)));
1054
- }
1055
- }),
1056
1014
  ls: defineCommand({
1057
1015
  meta: { name: "ls", description: "list requirements in a project" },
1058
1016
  args: {
@@ -2337,7 +2295,6 @@ var task = defineCommand({
2337
2295
  project: { type: "string", description: "project id (overrides .baton.json)" },
2338
2296
  body: { type: "string", description: "task body (markdown)" },
2339
2297
  deps: { type: "string", description: "comma-separated dependency task codes (T-N,T-N)" },
2340
- github: { type: "string", description: "link a GitHub issue url (light association)" },
2341
2298
  ...common
2342
2299
  },
2343
2300
  run: async ({ args }) => {
@@ -2355,8 +2312,7 @@ var task = defineCommand({
2355
2312
  requirementId,
2356
2313
  title: args.title,
2357
2314
  body: args.body,
2358
- dependsOn: dependsOn.length ? dependsOn : void 0,
2359
- external: args.github ? parseIssueUrl(args.github) : void 0
2315
+ dependsOn: dependsOn.length ? dependsOn : void 0
2360
2316
  },
2361
2317
  Boolean(args.json)
2362
2318
  )
@@ -2383,36 +2339,6 @@ var task = defineCommand({
2383
2339
  console.log(await updateTask(c, id, patch2, Boolean(args.json)));
2384
2340
  }
2385
2341
  }),
2386
- link: defineCommand({
2387
- meta: { name: "link", description: "link a task to a GitHub issue url" },
2388
- args: {
2389
- code: { type: "positional", required: true, description: "task code (T-N)" },
2390
- // Named `issue` (not `url`) — `url` would collide with the common --url flag.
2391
- issue: { type: "positional", required: true, description: "GitHub issue url" },
2392
- project: { type: "string", description: "project id (overrides .baton.json)" },
2393
- ...common
2394
- },
2395
- run: async ({ args }) => {
2396
- const c = clientFor(args);
2397
- const id = await resolveTaskByCode(c, resolveProjectId(args), args.code);
2398
- console.log(
2399
- await updateTask(c, id, { external: parseIssueUrl(args.issue) }, Boolean(args.json))
2400
- );
2401
- }
2402
- }),
2403
- unlink: defineCommand({
2404
- meta: { name: "unlink", description: "clear a task\u2019s GitHub issue association" },
2405
- args: {
2406
- code: { type: "positional", required: true, description: "task code (T-N)" },
2407
- project: { type: "string", description: "project id (overrides .baton.json)" },
2408
- ...common
2409
- },
2410
- run: async ({ args }) => {
2411
- const c = clientFor(args);
2412
- const id = await resolveTaskByCode(c, resolveProjectId(args), args.code);
2413
- console.log(await updateTask(c, id, { external: null }, Boolean(args.json)));
2414
- }
2415
- }),
2416
2342
  ls: defineCommand({
2417
2343
  meta: { name: "ls", description: "list tasks in a requirement" },
2418
2344
  args: {
@@ -2594,6 +2520,14 @@ import { dirname, isAbsolute as isAbsolute2, resolve } from "node:path";
2594
2520
  var createWorktree = (input) => {
2595
2521
  if (existsSync4(input.worktreePath))
2596
2522
  throw new Error(`worktree path already exists: ${input.worktreePath}`);
2523
+ const head = spawnSync2("git", ["-C", input.repo, "rev-parse", "--verify", "-q", "HEAD"], {
2524
+ stdio: "pipe",
2525
+ encoding: "utf8"
2526
+ });
2527
+ if (head.status !== 0)
2528
+ throw new Error(
2529
+ `repo has no commits (unborn HEAD) \u2014 create an initial commit before starting sessions`
2530
+ );
2597
2531
  mkdirSync(dirname(input.worktreePath), { recursive: true });
2598
2532
  const branch = `baton/${input.sessionCode}`;
2599
2533
  const r = spawnSync2(
@@ -2870,6 +2804,10 @@ var worker = defineCommand({
2870
2804
  args: {
2871
2805
  project: { type: "string", description: "project id (overrides .baton.json)" },
2872
2806
  name: { type: "string", description: "worker display name (default: hostname)" },
2807
+ config: {
2808
+ type: "string",
2809
+ description: "path to the worker config file (default: ./.baton.json)"
2810
+ },
2873
2811
  ...common
2874
2812
  },
2875
2813
  run: async ({ args }) => {
@@ -2883,13 +2821,17 @@ var worker = defineCommand({
2883
2821
  const hostname = osHostname();
2884
2822
  const machineId = readOrCreateMachineId();
2885
2823
  const name = args.name ?? hostname;
2886
- const { out, configPath } = await registerWorker(c, {
2887
- projectId: resolveProjectId(args),
2888
- name,
2889
- server,
2890
- hostname,
2891
- machineId
2892
- });
2824
+ const { out, configPath } = await registerWorker(
2825
+ c,
2826
+ {
2827
+ projectId: resolveProjectId(args),
2828
+ name,
2829
+ server,
2830
+ hostname,
2831
+ machineId
2832
+ },
2833
+ configPathFromArgs(args)
2834
+ );
2893
2835
  if (args.json) {
2894
2836
  console.log(toJson({ ...out, configPath, machineIdPath: machineIdPath() }));
2895
2837
  return;
@@ -2906,9 +2848,15 @@ var worker = defineCommand({
2906
2848
  name: "run",
2907
2849
  description: "run the persistent worker daemon (listens for session create/delete commands)"
2908
2850
  },
2909
- args: { ...common },
2910
- run: async () => {
2911
- const cfg = viewWorker(loadProjectConfig(projectConfigPath()));
2851
+ args: {
2852
+ config: {
2853
+ type: "string",
2854
+ description: "path to the worker config file (default: ./.baton.json)"
2855
+ },
2856
+ ...common
2857
+ },
2858
+ run: async ({ args }) => {
2859
+ const cfg = viewWorker(loadProjectConfig(configPathFromArgs(args)));
2912
2860
  const client = createClient(cfg.server, { bearer: cfg.apiToken });
2913
2861
  const ac = new AbortController();
2914
2862
  const stop = () => ac.abort();
@@ -2977,11 +2925,17 @@ var worker = defineCommand({
2977
2925
  }),
2978
2926
  whoami: defineCommand({
2979
2927
  meta: { name: "whoami", description: "show local worker config from .baton.json" },
2980
- args: { ...common },
2928
+ args: {
2929
+ config: {
2930
+ type: "string",
2931
+ description: "path to the worker config file (default: ./.baton.json)"
2932
+ },
2933
+ ...common
2934
+ },
2981
2935
  run: ({ args }) => {
2982
2936
  const cfg = (() => {
2983
2937
  try {
2984
- return loadProjectConfig(projectConfigPath());
2938
+ return loadProjectConfig(configPathFromArgs(args));
2985
2939
  } catch {
2986
2940
  return null;
2987
2941
  }
package/package.json CHANGED
@@ -1,32 +1,31 @@
1
1
  {
2
2
  "name": "@lesscap/baton-cli",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "baton CLI — register/run a worker, manage projects/requirements/tasks/sessions",
7
7
  "bin": {
8
- "baton": "./dist/baton.mjs"
8
+ "baton": "dist/baton.mjs"
9
9
  },
10
10
  "files": [
11
11
  "dist"
12
12
  ],
13
- "scripts": {
14
- "baton": "tsx src/index.ts",
15
- "build": "esbuild src/index.ts --bundle --platform=node --format=esm --packages=bundle --external:@anthropic-ai/claude-agent-sdk --banner:js=\"#!/usr/bin/env node\" --outfile=dist/baton.mjs && chmod +x dist/baton.mjs",
16
- "prepublishOnly": "pnpm build",
17
- "typecheck": "tsc --noEmit -p tsconfig.json",
18
- "test": "tsx --test 'src/**/*.test.ts'"
19
- },
20
13
  "devDependencies": {
21
- "@baton/shared": "workspace:*",
22
14
  "@types/node": "^25.9.1",
23
15
  "citty": "^0.2.2",
24
16
  "esbuild": "^0.28.0",
25
17
  "eventsource": "^4.1.0",
26
18
  "tsx": "^4.22.4",
27
- "typescript": "^6.0.3"
19
+ "typescript": "^6.0.3",
20
+ "@baton/shared": "0.0.0"
28
21
  },
29
22
  "dependencies": {
30
23
  "@anthropic-ai/claude-agent-sdk": "^0.3.161"
24
+ },
25
+ "scripts": {
26
+ "baton": "tsx src/index.ts",
27
+ "build": "esbuild src/index.ts --bundle --platform=node --format=esm --packages=bundle --external:@anthropic-ai/claude-agent-sdk --banner:js=\"#!/usr/bin/env node\" --outfile=dist/baton.mjs && chmod +x dist/baton.mjs",
28
+ "typecheck": "tsc --noEmit -p tsconfig.json",
29
+ "test": "tsx --test 'src/**/*.test.ts'"
31
30
  }
32
- }
31
+ }