@kaynooo/cli-git 0.0.0-stage → 0.5.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/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@kaynooo/cli-git",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "type": "module",
4
+ "version": "0.5.1",
5
+ "description": "gst and gc: a repository's state in one call, and a commit of exactly the paths given, its message checked before anything is staged.",
6
+ "author": "Kaynooo <contact@kaynooo.fr>",
7
+ "license": "MIT",
8
+ "homepage": "https://git.kaynooo.fr/kaynooo/cli/src/branch/main/packages/git#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://git.kaynooo.fr/kaynooo/cli.git",
12
+ "directory": "packages/git"
13
+ },
14
+ "bugs": "https://git.kaynooo.fr/kaynooo/cli/issues",
15
+ "keywords": [
16
+ "claude-code",
17
+ "cli",
18
+ "git",
19
+ "status",
20
+ "commit"
21
+ ],
22
+ "exports": {
23
+ "./message": "./src/message.ts"
24
+ },
25
+ "bin": {
26
+ "gst": "./dist/gst.js",
27
+ "gc": "./dist/gc.js"
28
+ },
29
+ "files": [
30
+ "dist",
31
+ "src/message.ts"
32
+ ],
33
+ "engines": {
34
+ "bun": ">=1.4.3"
35
+ },
36
+ "publishConfig": {
37
+ "registry": "https://git.kaynooo.fr/api/packages/kaynooo/npm/"
38
+ },
39
+ "scripts": {
40
+ "build": "$npm_execpath build src/gst.ts src/gc.ts --target bun --outdir dist",
41
+ "gst": "$npm_execpath src/gst.ts",
42
+ "gc": "$npm_execpath src/gc.ts"
43
+ },
44
+ "devDependencies": {
45
+ "@kaynooo/cli-kit": "0.17.0"
46
+ }
47
+ }
package/src/message.ts ADDED
@@ -0,0 +1,77 @@
1
+ const CONVENTIONAL = /^(?:feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\([^()\n]+\))?!?: \S/
2
+ const MAX_TITLE = 100
3
+ // Titles git writes itself.
4
+ const GIT_MADE = /^(?:Merge |Revert "|fixup! |squash! |amend! )/
5
+
6
+ // `#12 - <title>`, or `owner/repo#12 - <title>` for a ticket of another repository.
7
+ export const TICKET = /^(?:[\w.-]+\/[\w.-]+)?#\d+ - /
8
+ // A breaking change is the one place a body gives full details.
9
+ const BREAKING = /^BREAKING[ -]CHANGE: /
10
+ const BREAKING_TITLE = /^[a-z]+(?:\([^()\n]+\))?!: /
11
+ const TRAILER = /^(?:co-authored-by|signed-off-by|reviewed-by|acked-by|tested-by|reported-by|suggested-by|helped-by|change-id):|^\W*generated with \W*claude/i
12
+ const BULLET = /^\s*(?:[-*+]|\d+[.)])\s/
13
+ const SENTENCE_END = /[.!?:;)\]`'"]$/
14
+ const LOWER_START = /^\p{Ll}/u
15
+
16
+ // The whole rule, so a refusal needs no other read.
17
+ export const RULE = 'The rule: a `type(scope): title` line, `!` after the scope for a breaking change, type and scope taken from the repository\'s history; then optionally a blank line and one or two lines on what changed, never a bullet list or a hard-wrapped sentence; then a blank line and one line per ticket, its title copied verbatim, `#<n> - <title>` (`owner/repo#<n> - <title>` for another repository). The message ends there: no Co-Authored-By, Signed-off-by or "Generated with" trailer. Only a breaking change gives full details.'
18
+
19
+ export const TITLE = `The title is no Conventional Commit. ${RULE}`
20
+ export const TITLE_TOO_LONG = `The title runs past ${MAX_TITLE} characters: shorten it and move the detail to the body. ${RULE}`
21
+ export const TITLE_LINE = `The title takes one line and a blank line follows it. ${RULE}`
22
+ export const TRAILERS = `No trailers, ever: no Co-Authored-By, Signed-off-by or "Generated with" line, no --signoff or --trailer. ${RULE}`
23
+ export const BULLETS = `The body names what changed in a line or two, never a bullet list narrating the diff. ${RULE}`
24
+ export const TOO_LONG = `The body holds at most two lines besides the ticket lines; what goes beyond belongs in the reply. ${RULE}`
25
+ export const WRAPPED = `A body sentence stays on one line however long it runs: never hard-wrap it. ${RULE}`
26
+
27
+ // Where a refused `git commit` is pointed, gc building the message from its parts.
28
+ export const USE_GC = 'Commit with `gc`, which stages exactly the paths given once the message keeps the rule: `gc \'fix(api): retry a timed-out fetch\' -m \'A 502 is retried once before failing.\' --ticket \'#12 - [UC3] Retry failed fetches\' -- src/api.ts`.'
29
+
30
+ function isDescription(line: string | undefined): boolean {
31
+ return line !== undefined && line !== '' && !TICKET.test(line)
32
+ }
33
+
34
+ // Which commit message rule the message breaks, as the sentence to show, or null when it keeps them all.
35
+ export function commitMessageViolation(message: string): string | null {
36
+ const lines = message.split('\n').map(line => line.trimEnd())
37
+
38
+ while (lines[0] === '')
39
+ lines.shift()
40
+
41
+ while (lines.at(-1) === '')
42
+ lines.pop()
43
+
44
+ const [title = '', second, ...body] = lines
45
+
46
+ if (title === '')
47
+ return null
48
+
49
+ if (lines.some(line => TRAILER.test(line)))
50
+ return TRAILERS
51
+
52
+ if (!CONVENTIONAL.test(title) && !GIT_MADE.test(title))
53
+ return TITLE
54
+
55
+ if (second !== undefined && second !== '')
56
+ return TITLE_LINE
57
+
58
+ if (!GIT_MADE.test(title) && title.length > MAX_TITLE)
59
+ return TITLE_TOO_LONG
60
+
61
+ if (BREAKING_TITLE.test(title))
62
+ return null
63
+
64
+ const footer = body.findIndex(line => BREAKING.test(line))
65
+ const described = footer === -1 ? body : body.slice(0, footer)
66
+ const descriptions = described.filter(isDescription)
67
+
68
+ if (descriptions.some(line => BULLET.test(line)))
69
+ return BULLETS
70
+
71
+ if (descriptions.length > 2)
72
+ return TOO_LONG
73
+
74
+ const isWrapped = described.some((line, i) => isDescription(line) && isDescription(described[i + 1]) && !SENTENCE_END.test(line) && LOWER_START.test(described[i + 1] ?? ''))
75
+
76
+ return isWrapped ? WRAPPED : null
77
+ }