@williamthorsen/toolbelt.git 0.3.0 → 0.3.1

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/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## 0.3.1 — 2026-09-06
6
+
7
+ ### Bug fixes
8
+
9
+ - Point every package bin at a committed wrapper (#296)
10
+
11
+ - Points the `tb-git`, `tb-jira`, and `tb-secret` commands at committed wrappers under each package's `bin/`, so the target exists when the package manager links the command rather than only after a build.
12
+
13
+ - Fix piped-stdin reads and unhandled EPIPE in the CLIs (#301)
14
+
15
+ - Fixes an issue where `tb-secret set` and `tb-jira auth set` failed with `EAGAIN: resource temporarily unavailable` when the producer of a piped credential delayed its first byte, as `tb-secret get`, `op read`, and `gh auth token` all do.
16
+ - Stops `tb-secret`, `tb-jira`, and `tb-git` from crashing with an unhandled `EPIPE` when the reader on their stdout or stderr exits first, so that `tb-secret get | head -1` ends quietly, as a program that ignores `SIGPIPE` does.
17
+
18
+ ### Documentation
19
+
20
+ - Repair reduced object relatives in the READMEs and AGENTS.md (#263)
21
+
22
+ Repairs the reduced object relative in `AGENTS.md`, the root `README.md`, and the package READMEs.
23
+
24
+ - Repair the repository's prose and record every rejection's ground (#290)
25
+
26
+ Applies one repo-wide `revise-prose` sweep across the repository's READMEs, `AGENTS.md`, source comments, doc descriptions, and test names.
27
+
5
28
  ## 0.3.0 — 2026-08-30
6
29
 
7
30
  ### Features
package/README.md CHANGED
@@ -3,13 +3,18 @@
3
3
  Utilities for working with git.
4
4
 
5
5
  <!-- section:release-notes -->
6
- ## Release notes — v0.3.0 (2026-08-30)
6
+ ## Release notes — v0.3.1 (2026-09-06)
7
7
 
8
- ### Features
8
+ ### Bug fixes
9
9
 
10
- - Add a tb-git CLI for branch-number and ticket-ref (#250)
10
+ - Point every package bin at a committed wrapper (#296)
11
11
 
12
- Adds a `tb-git` command to `@williamthorsen/toolbelt.git`, enabling the use of `deriveBranchNumber` and `findBranchTicketRef` on the command line. `tb-git branch-number` prints the number derived from a branch name; `tb-git ticket-ref` prints the ID of the ticket encoded by the name, or the whole ref when the `--json` option is used. Both take an optional branch name and otherwise use the checked-out branch.
12
+ - Points the `tb-git`, `tb-jira`, and `tb-secret` commands at committed wrappers under each package's `bin/`, so the target exists when the package manager links the command rather than only after a build.
13
+
14
+ - Fix piped-stdin reads and unhandled EPIPE in the CLIs (#301)
15
+
16
+ - Fixes an issue where `tb-secret set` and `tb-jira auth set` failed with `EAGAIN: resource temporarily unavailable` when the producer of a piped credential delayed its first byte, as `tb-secret get`, `op read`, and `gh auth token` all do.
17
+ - Stops `tb-secret`, `tb-jira`, and `tb-git` from crashing with an unhandled `EPIPE` when the reader on their stdout or stderr exits first, so that `tb-secret get | head -1` ends quietly, as a program that ignores `SIGPIPE` does.
13
18
  <!-- /section:release-notes -->
14
19
 
15
20
  ## Installation
@@ -49,7 +54,7 @@ tb-git branch-number 232_add-widget --min 3000 --max 3999
49
54
  # 3232
50
55
  ```
51
56
 
52
- A negative offset takes the `=` form, `--offset=-3`: a bare `-3` reads as an option rather than as the value.
57
+ A negative offset takes the `=` form, `--offset=-3`: A bare `-3` reads as an option rather than as the value.
53
58
 
54
59
  ### `tb-git ticket-ref [<branch>] [options]`
55
60
 
@@ -80,7 +85,7 @@ With no `<branch>`, both subcommands resolve the checked-out branch with `git br
80
85
  | `1` | `ticket-ref` found no ticket in the branch name; both streams are empty |
81
86
  | `2` | Usage or validation error, with the message on stderr |
82
87
 
83
- A bound, offset, or key rejected by the library exits `2` carrying the message it raises. So does an empty option value, so `--min "$PORT_MIN"` with `PORT_MIN` unset fails instead of bounding at `0`.
88
+ A bound, offset, or key rejected by the library exits `2` carrying the message that it raises. So does an empty option value, so `--min "$PORT_MIN"` with `PORT_MIN` unset fails instead of bounding at `0`.
84
89
 
85
90
  ```sh
86
91
  if ref=$(tb-git ticket-ref); then
@@ -115,7 +120,7 @@ findBranchTicketRef('232_add-widget');
115
120
 
116
121
  A ref must begin a segment. `/` and `_` both delimit one, so an author prefix and a worktree-safe spelling parse alike, and the leftmost segment carrying a ref wins. Anchoring to a segment is what keeps a kebab-case description from reading as a ticket: `feat/add-widget-2` encodes none, because `widget` follows a hyphen rather than a separator.
117
122
 
118
- Two forms are recognized, each taking an optional `.N` revisit suffix. A **keyed** ref is a Jira-style key and number, the key matching Jira's own rule of a letter followed by letters and digits. A **bare-numeric** ref is the number alone. `id` and `key` are emitted uppercased, since a branch name may be lowercase but the ticket it names is `MAC-22`.
123
+ Two forms are recognized, each taking an optional `.N` revisit suffix. A **keyed** ref is a Jira-style key and number, the key matching Jira's own rule of a letter followed by letters and digits. A **bare-numeric** ref is the number alone. `id` and `key` are emitted uppercased, since a branch name may be lowercase but the ticket that it names is `MAC-22`.
119
124
 
120
125
  By default a key must be uppercase, which is what Jira permits and the only property separating a real key from an ordinary word: without it, `feat-2` would read as ticket `FEAT-2`. Declaring the project's own key through `key` is both more permissive and more precise, since it then matches in any casing and is the only key that matches at all.
121
126
 
@@ -152,7 +157,7 @@ deriveBranchNumber('main');
152
157
  // 663286764
153
158
  ```
154
159
 
155
- The number is the ticket's when the branch names one, and a [`hashString`](https://github.com/williamthorsen/toolbelt/tree/main/packages/strings#hashstring) digest of the whole name when it does not, so every branch yields something. `min`, `max`, and `offset` are `hashString`'s, and apply to both paths alike: the two land in one range, and `offset` stays a pure rotation.
160
+ The number is the ticket's when the branch names one, and a [`hashString`](https://github.com/williamthorsen/toolbelt/tree/main/packages/strings#hashstring) digest of the whole name when it does not, so every branch yields something. `min`, `max`, and `offset` are `hashString`'s, and apply to both paths alike: The two land in one range, and `offset` stays a pure rotation.
156
161
 
157
162
  ```ts
158
163
  deriveBranchNumber('232_add-widget', { min: 3000, max: 3999 });
package/bin/tb-git.js ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+
3
+ // Imports only node builtins: a top-level import resolves before the gate below runs, so an unresolvable
4
+ // dependency would replace this file's build-first message with ERR_MODULE_NOT_FOUND.
5
+ import { existsSync } from 'node:fs';
6
+
7
+ // Thin wrapper so pnpm can link the bin at install time, before `dist/` exists. The real entry point loads
8
+ // at runtime from the build output.
9
+ const entryPoint = new URL('../dist/esm/bin/tb-git.js', import.meta.url);
10
+
11
+ // Gate on the entry file itself: Node raises ERR_MODULE_NOT_FOUND for any unresolved module in the graph,
12
+ // so keying the build-first message off the error code would also fire when the build is present and one
13
+ // of its imports is missing.
14
+ if (!existsSync(entryPoint)) {
15
+ process.stderr.write(
16
+ 'tb-git: build output not found. In a source checkout, run `nmr build`; otherwise reinstall the package.\n',
17
+ );
18
+ process.exit(1);
19
+ }
20
+
21
+ try {
22
+ await import(entryPoint.href);
23
+ } catch (error) {
24
+ const message = error instanceof Error ? error.message : String(error);
25
+ process.stderr.write(`tb-git: failed to load: ${message}\n`);
26
+ process.exit(1);
27
+ }
@@ -1,4 +1,14 @@
1
1
  import { type BranchTicketRefOptions } from './findBranchTicketRef.js';
2
+ /**
3
+ * Derives a number from a branch name: the number of the ticket encoded by the name, or a hash of the name
4
+ * when it encodes none, so a branch always yields a stable number. `min` and `max` bound the result
5
+ * inclusively, and `offset` rotates it, wrapping at the bounds. Throws a RangeError on a malformed `key`,
6
+ * or on a bound or offset rejected by hashString.
7
+ *
8
+ * @category Git
9
+ * @experimental
10
+ * @stage candidate
11
+ */
2
12
  export declare function deriveBranchNumber(branch: string, options?: DeriveBranchNumberOptions): number;
3
13
  export interface DeriveBranchNumberOptions extends BranchTicketRefOptions {
4
14
  readonly max?: number | undefined;
@@ -1,10 +1,24 @@
1
+ /**
2
+ * Finds the ticket ref encoded by a branch name, or `undefined` when it encodes none. A ref must begin a
3
+ * `/`- or `_`-delimited segment, and the leftmost segment containing one wins. A key must be uppercase,
4
+ * unless `key` names the project's own key, which then matches in any casing and is the only key that
5
+ * does; a bare-numeric ref is found either way. Throws a RangeError if `key` is not a well-formed key.
6
+ *
7
+ * @category Git
8
+ * @experimental
9
+ * @stage candidate
10
+ */
1
11
  export declare function findBranchTicketRef(branch: string, options?: BranchTicketRefOptions): BranchTicketRef | undefined;
2
12
  export interface BranchTicketRef {
13
+ /** The canonical ID: an uppercased key and number (`MAC-22`), or the number alone for a bare-numeric ref. */
3
14
  readonly id: string;
15
+ /** The uppercased project key, absent for a bare-numeric ref. */
4
16
  readonly key?: string | undefined;
5
17
  readonly number: number;
18
+ /** The revisit ordinal, present when the ref has a `.N` suffix. */
6
19
  readonly revisit?: number | undefined;
7
20
  }
8
21
  export interface BranchTicketRefOptions {
22
+ /** The project's own key, which then matches in any casing and displaces the uppercase-key rule. */
9
23
  readonly key?: string | undefined;
10
24
  }
@@ -5,7 +5,7 @@ export function findBranchTicketRef(branch, options = {}) {
5
5
  const { key: declaredKey } = options;
6
6
  if (declaredKey !== undefined && !KEY_PATTERN.test(declaredKey)) {
7
7
  const received = `Received ${JSON.stringify(declaredKey)}.`;
8
- throw new RangeError(`Invalid key: a key must be a letter followed by letters or digits. ${received}`);
8
+ throw new RangeError(`Invalid key: A key must be a letter followed by letters or digits. ${received}`);
9
9
  }
10
10
  for (const segment of branch.split(SEGMENT_SEPARATOR)) {
11
11
  const groups = REF_PATTERN.exec(segment)?.groups;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Finds the manifest of the package owning a directory, ascending to the first `package.json` declaring a
3
+ * `name`. One declaring none is a marker manifest, such as the `{"type": "commonjs"}` file left in `dist/`
4
+ * by a dual-format build, and the ascent passes over it, so the answer is the owning package rather than
5
+ * the nearest manifest. Throws where no ancestor declares a name.
6
+ *
7
+ * @internal
8
+ */
1
9
  export declare function findOwningManifest(startDir: string): OwningManifest;
2
10
  export interface OwningManifest {
3
11
  readonly manifest: {
@@ -1 +1,8 @@
1
+ /**
2
+ * Resolves the branch checked out in the current directory. Throws when git is absent, the directory is
3
+ * not a repository, or HEAD names no branch, since each leaves the caller without the name that it asked
4
+ * to derive from.
5
+ *
6
+ * @internal
7
+ */
1
8
  export declare function resolveCheckedOutBranch(): string;
@@ -1 +1,8 @@
1
+ /**
2
+ * Reads the version declared by the package owning a directory, defaulting to this module's own, which is
3
+ * this package whether it runs from source under the test runner or from the build output once installed.
4
+ * Throws where the owning manifest declares no string version.
5
+ *
6
+ * @internal
7
+ */
1
8
  export declare function resolveSelfVersion(fromDir?: string): string;
@@ -1,8 +1,16 @@
1
+ /**
2
+ * Runs the `tb-git` command line, returning what to write and exit with rather than doing either, so the
3
+ * whole surface is exercisable without a process. Every failure is reported through the result: Nothing throws.
4
+ *
5
+ * @internal
6
+ */
1
7
  export declare function runTbGit(args: string[], effects: TbGitEffects): TbGitResult;
8
+ /** The effects deferred to the entry point, which keeps the runner free of I/O. */
2
9
  export interface TbGitEffects {
3
10
  readonly resolveBranch: () => string;
4
11
  readonly resolveVersion: () => string;
5
12
  }
13
+ /** What the caller should write to each stream and exit with. */
6
14
  export interface TbGitResult {
7
15
  readonly exitCode: number;
8
16
  readonly stderr: string;
@@ -1,2 +1 @@
1
- #!/usr/bin/env node
2
1
  export {};
@@ -1,7 +1,12 @@
1
- #!/usr/bin/env node
2
1
  import { resolveCheckedOutBranch } from "./resolveCheckedOutBranch.js";
3
2
  import { resolveSelfVersion } from "./resolveSelfVersion.js";
4
3
  import { runTbGit } from "./runTbGit.js";
4
+ for (const stream of [process.stdout, process.stderr]) {
5
+ stream.on('error', (error) => {
6
+ if (error.code !== 'EPIPE')
7
+ throw error;
8
+ });
9
+ }
5
10
  const { exitCode, stderr, stdout } = runTbGit(process.argv.slice(2), {
6
11
  resolveBranch: resolveCheckedOutBranch,
7
12
  resolveVersion: resolveSelfVersion,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@williamthorsen/toolbelt.git",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Utilities for working with git",
5
5
  "keywords": [
6
6
  "esm",
@@ -37,17 +37,18 @@
37
37
  }
38
38
  },
39
39
  "bin": {
40
- "tb-git": "./dist/esm/bin/tb-git.js"
40
+ "tb-git": "./bin/tb-git.js"
41
41
  },
42
42
  "files": [
43
- "dist/*",
44
- "CHANGELOG.md"
43
+ "bin/*",
44
+ "CHANGELOG.md",
45
+ "dist/*"
45
46
  ],
46
47
  "dependencies": {
47
- "@williamthorsen/toolbelt.strings": "7.1.0"
48
+ "@williamthorsen/toolbelt.strings": "7.2.0"
48
49
  },
49
50
  "devDependencies": {
50
- "@williamthorsen/toolbelt.filesystem": "0.8.2"
51
+ "@williamthorsen/toolbelt.filesystem": "0.8.3"
51
52
  },
52
53
  "engines": {
53
54
  "node": ">=24.0.0"