@carecard/auth-util 3.1.15 → 3.2.0
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/.agents/skills/carecard-workspace-standards/SKILL.md +30 -17
- package/.agents/skills/github-pr-create-update/SKILL.md +63 -84
- package/.agents/skills/github-pr-merge-cleanup/SKILL.md +103 -79
- package/.agents/skills/npm-package-flow/SKILL.md +75 -0
- package/.agents/skills/npm-package-flow/agents/openai.yaml +5 -0
- package/.agents/skills/pkg-auth-util-auth-crypto-library/SKILL.md +8 -5
- package/.agents/skills/software-design-patterns-and-clean-code/SKILL.md +1 -1
- package/package.json +7 -7
- package/readme.md +13 -0
- package/.prettierignore +0 -17
- package/.prettierrc.cjs +0 -32
- package/jest.config.js +0 -16
- package/scripts/rename-cjs.js +0 -13
- package/src/cryptoUtilAuth.ts +0 -111
- package/src/index.ts +0 -6
- package/src/jwtUtilAuth.ts +0 -85
- package/src/keyGen.ts +0 -14
- package/src/pwdUtilAuth.ts +0 -78
- package/src/strEncryptUtil.ts +0 -159
- package/src/stringUtilAuth.ts +0 -102
- package/tests/cryptoUtilAuth.test.ts +0 -97
- package/tests/index.test.ts +0 -157
- package/tests/indexStringUtilAuth.test.ts +0 -95
- package/tests/jwtUtilAuth.test.ts +0 -33
- package/tests/keyGen.test.ts +0 -26
- package/tests/keys/keys.ts +0 -24
- package/tests/pwdUtilAuth.test.ts +0 -40
- package/tsconfig.base.json +0 -14
- package/tsconfig.cjs.json +0 -7
- package/tsconfig.esm.json +0 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: carecard-workspace-standards
|
|
3
|
-
description: Follow the shared SO_CareCardCa/CareCard workspace coding, testing, repository, dependency, shared package, frontend, database, API response, and security standards. Use before modifying, testing, reviewing, or debugging any
|
|
3
|
+
description: 'Follow the shared SO_CareCardCa/CareCard workspace coding, testing, repository, dependency, shared package, frontend, database, API response, and security standards. Use before modifying, testing, reviewing, or debugging any ms-*, pkg-*, app-*, website, dashboard, or other CareCard repository in this workspace, especially when choosing validation commands, package boundaries, TypeScript types, dependencies, API contracts, database logic, service patterns, or frontend architecture.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# CareCard Workspace Standards
|
|
@@ -23,7 +23,7 @@ Use before modifying, testing, reviewing, or debugging any CareCard workspace re
|
|
|
23
23
|
|
|
24
24
|
- `.agents/config.toml`
|
|
25
25
|
- `.agents/skills`
|
|
26
|
-
- `
|
|
26
|
+
- `ms-*` services
|
|
27
27
|
- `pkg-*` packages
|
|
28
28
|
- `app-*` frontends
|
|
29
29
|
- `.husky` and `.junie` validation guidance
|
|
@@ -43,8 +43,8 @@ Use before modifying, testing, reviewing, or debugging any CareCard workspace re
|
|
|
43
43
|
|
|
44
44
|
## Safety Constraints
|
|
45
45
|
|
|
46
|
-
- Do not edit generated output, dependency folders, logs, coverage, dist, or build artifacts unless the task
|
|
47
|
-
- Do not revert or overwrite user changes; stage only
|
|
46
|
+
- Do not edit generated output, dependency folders, logs, coverage, dist, or build artifacts unless the task requires it.
|
|
47
|
+
- Do not revert or overwrite user changes; stage only requested skill or instruction files.
|
|
48
48
|
- Never suppress errors, lint failures, type failures, security failures, or failing tests; fix the underlying issue or report the blocker.
|
|
49
49
|
- Do not log or expose secrets, JWTs, passwords, credentials, private keys, sensitive personal data, SQL internals, or stack traces.
|
|
50
50
|
|
|
@@ -52,7 +52,7 @@ Use before modifying, testing, reviewing, or debugging any CareCard workspace re
|
|
|
52
52
|
|
|
53
53
|
Treat `/Users/pankajpriscilla/SO_CareCardCa` as a collection of independent Git
|
|
54
54
|
repositories, not as one monorepo. Work from the specific child repository
|
|
55
|
-
being changed. Each `
|
|
55
|
+
being changed. Each `ms-*`, `pkg-*`, and `app-*` directory has its own package
|
|
56
56
|
scripts, Git status, test commands, style, naming, structure, test framework,
|
|
57
57
|
and Husky hooks.
|
|
58
58
|
|
|
@@ -128,11 +128,11 @@ config.
|
|
|
128
128
|
|
|
129
129
|
## Remote Git Operations Guardrail
|
|
130
130
|
|
|
131
|
-
Do not run remote Git or GitHub operations unless the current user request explicitly asks for
|
|
131
|
+
Do not run remote Git or GitHub operations unless the current user request explicitly asks for them. This includes `git fetch`, `git pull`, `git push`, `git push --delete`, remote branch cleanup, GitHub API calls, and any `gh pr` command that creates, updates, readies, merges, closes, or cleans up a pull request. Do not infer permission from branch names, validation needs, prior workflow habits, or convenience; ask first when remote state would help but was not requested.
|
|
132
132
|
|
|
133
133
|
## Commit Continuation Rule
|
|
134
134
|
|
|
135
|
-
Do not amend
|
|
135
|
+
Do not amend commits unless the user explicitly asks. If
|
|
136
136
|
hooks, formatters, tests, docs, skills, validation, or review follow-up create
|
|
137
137
|
additional changes after a commit already exists, keep history additive by
|
|
138
138
|
making a new commit in the affected repository.
|
|
@@ -183,11 +183,11 @@ build artifacts, logs, or `.DS_Store`.
|
|
|
183
183
|
`notFound404`, `appErrorHandler`, error throw helpers, case converters, and
|
|
184
184
|
`ApiErrorType`.
|
|
185
185
|
- Do not create or maintain duplicated common response or error helpers inside
|
|
186
|
-
each `
|
|
186
|
+
each `ms-*` service.
|
|
187
187
|
- Keep service-local response code limited to service-specific mapping or
|
|
188
188
|
wiring.
|
|
189
189
|
- Add broadly useful shared functionality to the relevant `pkg-*` package
|
|
190
|
-
instead of duplicating it locally in an `
|
|
190
|
+
instead of duplicating it locally in an `ms-*` or `app-*` project.
|
|
191
191
|
- When changing a `pkg-*` package, write package tests first, increase that
|
|
192
192
|
package's minor version in `package.json`, run `npm install` in the package,
|
|
193
193
|
update consuming projects to the new package version, run `npm install` in
|
|
@@ -206,10 +206,10 @@ build artifacts, logs, or `.DS_Store`.
|
|
|
206
206
|
|
|
207
207
|
## Backend Microservices
|
|
208
208
|
|
|
209
|
-
Most JavaScript `
|
|
209
|
+
Most JavaScript `ms-*` services use CommonJS, Mocha, Supertest, Docker Compose
|
|
210
210
|
database tests, `@carecard/*` packages, and `sub-apps`
|
|
211
|
-
controller/router/model patterns. TypeScript services such as `
|
|
212
|
-
and `
|
|
211
|
+
controller/router/model patterns. TypeScript services such as `ms-contact-us`
|
|
212
|
+
and `ms-template-ts` use Jest or TypeScript tooling and should keep their
|
|
213
213
|
existing TypeScript style.
|
|
214
214
|
|
|
215
215
|
- Keep environment-specific files explicit: `.env.development`, `.env.test`,
|
|
@@ -283,9 +283,9 @@ existing TypeScript style.
|
|
|
283
283
|
- Keep tests readable and domain-specific.
|
|
284
284
|
- Tests must cover desired or happy paths and prevention or rejection of
|
|
285
285
|
undesired behavior.
|
|
286
|
-
- JavaScript `
|
|
286
|
+
- JavaScript `ms-*` services usually use Mocha, Supertest,
|
|
287
287
|
`test/index.test.js`, and Docker-backed PostgreSQL scripts.
|
|
288
|
-
- TypeScript `
|
|
288
|
+
- TypeScript `ms-*` services usually use Jest and `tests/index.test.ts`.
|
|
289
289
|
- `pkg-*` packages usually use Mocha plus TypeScript type tests where present.
|
|
290
290
|
- `app-dashboard` uses Vitest, React Testing Library, mock API tests, and
|
|
291
291
|
Selenium for end-to-end flows.
|
|
@@ -306,8 +306,8 @@ existing TypeScript style.
|
|
|
306
306
|
## Dashboard Frontend
|
|
307
307
|
|
|
308
308
|
`app-dashboard` is a Next.js App Router TypeScript app using MUI, React Query,
|
|
309
|
-
`next-intl`, and shared CareCard utilities. It consumes `
|
|
310
|
-
`
|
|
309
|
+
`next-intl`, and shared CareCard utilities. It consumes `ms-auth`,
|
|
310
|
+
`ms-institutions`, `ms-contact-us`, and `ms-user-profiles` through service
|
|
311
311
|
modules.
|
|
312
312
|
|
|
313
313
|
- Keep backend URL definitions centralized in `src/services/api.routes.ts`.
|
|
@@ -366,12 +366,25 @@ the authenticated dashboard.
|
|
|
366
366
|
- Keep CareCard package usage consistent with the service or app being changed.
|
|
367
367
|
- When standardizing response or error behavior, prefer `@carecard/common-util`
|
|
368
368
|
`3.1.15` because it contains response and error functions aligned with
|
|
369
|
-
`
|
|
369
|
+
`ms-auth`.
|
|
370
370
|
- If package version changes are required, update lockfiles and verify affected
|
|
371
371
|
services or apps.
|
|
372
372
|
- Avoid broad dependency upgrades as part of feature or refactor work unless
|
|
373
373
|
the task is specifically about dependencies.
|
|
374
374
|
|
|
375
|
+
## Auth Service RLS Contract
|
|
376
|
+
|
|
377
|
+
- `ms-auth` follows the shared PostgreSQL/RLS pattern from `ms-template-js`: auth tables live in the `carecard` schema, RLS is enabled and forced on every auth table, and application runtime queries use the unprivileged database role.
|
|
378
|
+
- Auth table policies allow normal JWT users to access only self-owned rows. Do not add redundant `user_id = <jwt sub>` SQL predicates to duplicate self-row checks when RLS owns the authorization decision.
|
|
379
|
+
- A JWT payload containing `roles: ["ad"]` is the auth-service super-admin signal and can perform any action on auth tables. Dashboard code may map that role to `super_admin`, but backend auth RLS must not require a separate database role row for that bypass.
|
|
380
|
+
- Public auth flows such as registration, login, confirmation, recovery, visitor creation, and service user lookup must use narrow system contexts (`system_create`, `system_login`, `system_confirm`, `system_recovery`, `system_visitor`, `system_service`) instead of privileged runtime queries.
|
|
381
|
+
|
|
382
|
+
- `ms-auth` controller exports use concise action names such as `loginUser`,
|
|
383
|
+
`registerUser`, `getUserDetail`, and `renewJwt`; route middleware and router
|
|
384
|
+
placement express whether a flow is public, authenticated, admin-only, or
|
|
385
|
+
service-only, so avoid `public`, `protected`, `admin`, or `Handler` suffixes
|
|
386
|
+
in new controller names.
|
|
387
|
+
|
|
375
388
|
## Security Requirements
|
|
376
389
|
|
|
377
390
|
- Treat authentication, authorization, JWT, password, email confirmation,
|
|
@@ -1,70 +1,57 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: github-pr-create-update
|
|
3
|
-
description: Use only when the user explicitly asks for remote Git or GitHub PR work: pushing a branch, creating or updating a PR, or marking a PR ready from the current repository branch.
|
|
3
|
+
description: 'Use only when the user explicitly asks for remote Git or GitHub PR work: pushing a branch, creating or updating a PR, or marking a PR ready from the current repository branch into development or main.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Pull Request Create
|
|
7
7
|
|
|
8
8
|
## Purpose
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
After the user explicitly asks for remote Git or GitHub PR work, create,
|
|
11
|
+
update, verify, push, and mark ready a GitHub pull request from the current
|
|
12
|
+
repository branch into `development`, or into `main` when `development` is
|
|
13
|
+
absent.
|
|
11
14
|
|
|
12
15
|
## When To Use
|
|
13
16
|
|
|
14
|
-
- Use only when the user explicitly asks to create, update, push for, or mark
|
|
17
|
+
- Use only when the user explicitly asks to create, update, push for, or mark
|
|
18
|
+
ready a GitHub pull request from the current repository branch.
|
|
15
19
|
|
|
16
20
|
## When Not To Use
|
|
17
21
|
|
|
18
|
-
- Do not use for merging or deleting an already-approved pull request; use the
|
|
22
|
+
- Do not use for merging or deleting an already-approved pull request; use the
|
|
23
|
+
merge cleanup skill.
|
|
19
24
|
- Do not use for ordinary local commits that do not involve GitHub PR work.
|
|
20
25
|
|
|
21
26
|
## Remote Git Operations Guardrail
|
|
22
27
|
|
|
23
|
-
Do not run remote Git or GitHub operations unless the current user request
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
## Coding Principles
|
|
32
|
-
|
|
33
|
-
- Preserve the repository structure, naming style, module system, and local helper patterns.
|
|
34
|
-
- Prefer readable, maintainable code with meaningful function, variable, file, and test names.
|
|
35
|
-
- Avoid new dependencies unless the existing stack cannot reasonably solve the task and the user confirms the tradeoff.
|
|
36
|
-
|
|
37
|
-
## Testing Expectations
|
|
38
|
-
|
|
39
|
-
- Run repository validation before PR creation or merge when code behavior changed.
|
|
40
|
-
- Confirm the branch is clean except intended changes before finishing.
|
|
41
|
-
|
|
42
|
-
## Safety Constraints
|
|
43
|
-
|
|
44
|
-
- Do not edit generated output, dependency folders, logs, coverage, dist, or build artifacts unless the task explicitly requires it.
|
|
45
|
-
- Do not revert or overwrite user changes; stage only files related to the requested skill or instruction update.
|
|
46
|
-
- Never suppress errors, lint failures, type failures, security failures, or failing tests; fix the underlying issue or report the blocker.
|
|
47
|
-
|
|
48
|
-
## Commit Continuation Rule
|
|
49
|
-
|
|
50
|
-
Do not amend existing commits unless the user explicitly asks for an amend. If
|
|
51
|
-
hook, formatter, documentation, skill, validation, or review follow-up changes
|
|
52
|
-
appear after a commit, stage only the intended files and make a new commit with
|
|
53
|
-
a clear message.
|
|
28
|
+
Do not run remote Git or GitHub operations unless the current user request
|
|
29
|
+
explicitly asks for them. This includes `git fetch`, `git pull`, `git push`,
|
|
30
|
+
`git push --delete`, remote branch cleanup, GitHub API calls, and any `gh pr`
|
|
31
|
+
command that creates, updates, readies, merges, closes, or cleans up a pull
|
|
32
|
+
request. Do not infer permission from branch names, validation needs, prior
|
|
33
|
+
workflow habits, or convenience; ask first when remote state would help but was
|
|
34
|
+
not requested.
|
|
54
35
|
|
|
55
36
|
## Scope
|
|
56
37
|
|
|
57
38
|
Use this skill from the root of the repository whose current branch contains
|
|
58
|
-
the intended PR changes. The repository must have `origin/development
|
|
59
|
-
GitHub CLI must be available and authenticated.
|
|
39
|
+
the intended PR changes. The repository must have `origin/development` or
|
|
40
|
+
`origin/main`, and GitHub CLI must be available and authenticated.
|
|
41
|
+
|
|
42
|
+
Default terms:
|
|
43
|
+
|
|
44
|
+
- Base branch: `development` when `origin/development` exists; otherwise
|
|
45
|
+
`main` when `origin/main` exists.
|
|
46
|
+
- Source branch: the current branch unless the user names another branch.
|
|
60
47
|
|
|
61
48
|
Do not continue automatically when:
|
|
62
49
|
|
|
63
|
-
- The
|
|
50
|
+
- The source branch is `development`, `main`, `master`, or detached.
|
|
64
51
|
- The working tree has uncommitted changes. Explain that a PR only includes
|
|
65
52
|
committed changes and ask the user whether to commit or stash them.
|
|
66
53
|
- `gh auth status` fails.
|
|
67
|
-
- `origin/development`
|
|
54
|
+
- Neither `origin/development` nor `origin/main` exists.
|
|
68
55
|
|
|
69
56
|
## Workflow
|
|
70
57
|
|
|
@@ -80,30 +67,26 @@ Do not continue automatically when:
|
|
|
80
67
|
gh auth status
|
|
81
68
|
```
|
|
82
69
|
|
|
83
|
-
2.
|
|
84
|
-
|
|
70
|
+
2. Select the pull request base branch. Prefer `development`; use `main` only
|
|
71
|
+
when `origin/development` is absent:
|
|
85
72
|
|
|
86
73
|
```sh
|
|
87
|
-
git
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
git fetch origin
|
|
74
|
+
if git ls-remote --exit-code --heads origin development >/dev/null 2>&1; then
|
|
75
|
+
base="development"
|
|
76
|
+
elif git ls-remote --exit-code --heads origin main >/dev/null 2>&1; then
|
|
77
|
+
base="main"
|
|
78
|
+
else
|
|
79
|
+
echo "No origin/development or origin/main branch exists."
|
|
80
|
+
exit 1
|
|
81
|
+
fi
|
|
82
|
+
git fetch origin "$base" --prune
|
|
96
83
|
```
|
|
97
84
|
|
|
98
|
-
|
|
99
|
-
checked out in another worktree, do not force it. Continue using
|
|
100
|
-
`origin/development` for validation.
|
|
101
|
-
|
|
102
|
-
3. Check whether the current branch can merge with latest development without
|
|
85
|
+
3. Check whether the current branch can merge with the latest base without
|
|
103
86
|
changing the worktree:
|
|
104
87
|
|
|
105
88
|
```sh
|
|
106
|
-
if git merge-tree --write-tree HEAD origin
|
|
89
|
+
if git merge-tree --write-tree HEAD "origin/$base" >/tmp/pull-request-create-merge-tree.out
|
|
107
90
|
then
|
|
108
91
|
merge_conflict_detected=false
|
|
109
92
|
else
|
|
@@ -111,11 +94,11 @@ Do not continue automatically when:
|
|
|
111
94
|
fi
|
|
112
95
|
```
|
|
113
96
|
|
|
114
|
-
4. If a merge conflict is detected, try rebasing on latest
|
|
97
|
+
4. If a merge conflict is detected, try rebasing on the latest base:
|
|
115
98
|
|
|
116
99
|
```sh
|
|
117
100
|
if [ "$merge_conflict_detected" = true ]; then
|
|
118
|
-
if git rebase origin
|
|
101
|
+
if git rebase "origin/$base"; then
|
|
119
102
|
git push --force-with-lease -u origin "$branch"
|
|
120
103
|
else
|
|
121
104
|
git rebase --abort
|
|
@@ -127,62 +110,58 @@ Do not continue automatically when:
|
|
|
127
110
|
fi
|
|
128
111
|
```
|
|
129
112
|
|
|
130
|
-
Do not
|
|
131
|
-
|
|
113
|
+
Do not use `--no-verify`; pre-push hooks must run. Do not resolve rebase
|
|
114
|
+
conflicts unless the user explicitly asks.
|
|
132
115
|
|
|
133
|
-
5.
|
|
116
|
+
5. Verify the remote branch matches local `HEAD`:
|
|
134
117
|
|
|
135
118
|
```sh
|
|
136
|
-
git
|
|
137
|
-
git
|
|
119
|
+
local_sha="$(git rev-parse HEAD)"
|
|
120
|
+
remote_sha="$(git ls-remote --heads origin "$branch" | awk '{print $1}')"
|
|
121
|
+
test "$local_sha" = "$remote_sha"
|
|
138
122
|
```
|
|
139
123
|
|
|
140
|
-
|
|
141
|
-
such as `draft`, `[draft]`, `Draft:`, and `WIP`. Do not leave a generic title
|
|
142
|
-
such as "updates", "changes", or "draft PR".
|
|
124
|
+
6. Inspect the branch changes before writing the PR title:
|
|
143
125
|
|
|
144
|
-
|
|
126
|
+
```sh
|
|
127
|
+
git log --reverse --format='%s' "origin/$base..HEAD"
|
|
128
|
+
git diff --stat "origin/$base...HEAD"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
7. Reuse an existing open PR for this exact branch/base pair when present:
|
|
145
132
|
|
|
146
133
|
```sh
|
|
147
134
|
pr_number="$(gh pr list \
|
|
148
135
|
--head "$branch" \
|
|
149
|
-
--base
|
|
136
|
+
--base "$base" \
|
|
150
137
|
--state open \
|
|
151
138
|
--json number \
|
|
152
139
|
--jq '.[0].number // empty')"
|
|
153
140
|
```
|
|
154
141
|
|
|
155
|
-
|
|
156
|
-
number:
|
|
142
|
+
8. If there is no PR, create one against the selected base and capture the new
|
|
143
|
+
PR number:
|
|
157
144
|
|
|
158
145
|
```sh
|
|
159
146
|
pr_url="$(gh pr create \
|
|
160
|
-
--base
|
|
147
|
+
--base "$base" \
|
|
161
148
|
--head "$branch" \
|
|
162
149
|
--title "$title" \
|
|
163
150
|
--body "$body")"
|
|
164
151
|
pr_number="$(gh pr view "$pr_url" --json number --jq '.number')"
|
|
165
152
|
```
|
|
166
153
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
8. If a PR exists, mark it ready when it is a draft:
|
|
154
|
+
9. If a PR exists, mark it ready when it is a draft, then keep the title
|
|
155
|
+
descriptive:
|
|
171
156
|
|
|
172
157
|
```sh
|
|
173
158
|
is_draft="$(gh pr view "$pr_number" --json isDraft --jq '.isDraft')"
|
|
174
159
|
if [ "$is_draft" = "true" ]; then
|
|
175
160
|
gh pr ready "$pr_number"
|
|
176
161
|
fi
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
9. Update the PR title after create/reuse so it is descriptive and contains no
|
|
180
|
-
draft wording:
|
|
181
|
-
|
|
182
|
-
```sh
|
|
183
162
|
gh pr edit "$pr_number" --title "$title"
|
|
184
163
|
```
|
|
185
164
|
|
|
186
|
-
10. Final response should include the PR URL,
|
|
187
|
-
whether an existing PR was reused or marked ready,
|
|
188
|
-
could not be run.
|
|
165
|
+
10. Final response should include the PR URL, selected base branch, whether a
|
|
166
|
+
rebase was performed, whether an existing PR was reused or marked ready,
|
|
167
|
+
and any validation that could not be run.
|
|
@@ -1,56 +1,38 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: github-pr-merge-cleanup
|
|
3
|
-
description: Use only when the user explicitly asks for remote Git or GitHub PR work: reviewing
|
|
3
|
+
description: 'Use only when the user explicitly asks for remote Git or GitHub PR work: pushing a branch, creating a missing PR, reviewing mergeability, validating, merging, deleting, or cleaning up a pull request branch.'
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Pull Request Merge Close
|
|
7
7
|
|
|
8
8
|
## Purpose
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
After the user explicitly asks for remote Git or GitHub PR work, push the
|
|
11
|
+
branch, create a missing PR when needed, review, validate, merge, delete the
|
|
12
|
+
branch when allowed, and clean local state for a GitHub pull request targeting
|
|
13
|
+
`development`, or `main` when `development` is absent.
|
|
11
14
|
|
|
12
15
|
## When To Use
|
|
13
16
|
|
|
14
|
-
- Use only when the user explicitly asks to review mergeability,
|
|
17
|
+
- Use only when the user explicitly asks to push, review mergeability,
|
|
18
|
+
validate, merge, close, or clean up a GitHub pull request branch.
|
|
15
19
|
|
|
16
20
|
## When Not To Use
|
|
17
21
|
|
|
18
|
-
- Do not use for
|
|
19
|
-
|
|
22
|
+
- Do not use for PR-only creation/update work without a merge request; use the
|
|
23
|
+
PR create/update skill.
|
|
24
|
+
- Do not use when the user only asks for local code changes without PR merge
|
|
25
|
+
work.
|
|
20
26
|
|
|
21
27
|
## Remote Git Operations Guardrail
|
|
22
28
|
|
|
23
|
-
Do not run remote Git or GitHub operations unless the current user request
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
## Coding Principles
|
|
32
|
-
|
|
33
|
-
- Preserve the repository structure, naming style, module system, and local helper patterns.
|
|
34
|
-
- Prefer readable, maintainable code with meaningful function, variable, file, and test names.
|
|
35
|
-
- Avoid new dependencies unless the existing stack cannot reasonably solve the task and the user confirms the tradeoff.
|
|
36
|
-
|
|
37
|
-
## Testing Expectations
|
|
38
|
-
|
|
39
|
-
- Run repository validation before PR creation or merge when code behavior changed.
|
|
40
|
-
- Confirm the branch is clean except intended changes before finishing.
|
|
41
|
-
|
|
42
|
-
## Safety Constraints
|
|
43
|
-
|
|
44
|
-
- Do not edit generated output, dependency folders, logs, coverage, dist, or build artifacts unless the task explicitly requires it.
|
|
45
|
-
- Do not revert or overwrite user changes; stage only files related to the requested skill or instruction update.
|
|
46
|
-
- Never suppress errors, lint failures, type failures, security failures, or failing tests; fix the underlying issue or report the blocker.
|
|
47
|
-
|
|
48
|
-
## Commit Continuation Rule
|
|
49
|
-
|
|
50
|
-
Do not amend existing commits unless the user explicitly asks for an amend. If
|
|
51
|
-
hook, formatter, documentation, skill, validation, or review follow-up changes
|
|
52
|
-
appear after a commit, stage only the intended files and make a new commit with
|
|
53
|
-
a clear message.
|
|
29
|
+
Do not run remote Git or GitHub operations unless the current user request
|
|
30
|
+
explicitly asks for them. This includes `git fetch`, `git pull`, `git push`,
|
|
31
|
+
`git push --delete`, remote branch cleanup, GitHub API calls, and any `gh pr`
|
|
32
|
+
command that creates, updates, readies, merges, closes, or cleans up a pull
|
|
33
|
+
request. Do not infer permission from branch names, validation needs, prior
|
|
34
|
+
workflow habits, or convenience; ask first when remote state would help but was
|
|
35
|
+
not requested.
|
|
54
36
|
|
|
55
37
|
## Scope
|
|
56
38
|
|
|
@@ -60,8 +42,8 @@ branch available locally or on `origin`.
|
|
|
60
42
|
|
|
61
43
|
Default terms:
|
|
62
44
|
|
|
63
|
-
- Base branch: `development` when `origin/development` exists, otherwise
|
|
64
|
-
|
|
45
|
+
- Base branch: `development` when `origin/development` exists, otherwise
|
|
46
|
+
`main` when `origin/main` exists.
|
|
65
47
|
- Target branch: the current branch unless the user names another branch.
|
|
66
48
|
- Pull request: the open PR whose head is the target branch and whose base is
|
|
67
49
|
the base branch.
|
|
@@ -72,35 +54,86 @@ Do not continue automatically when:
|
|
|
72
54
|
- The target branch is detached or is the base branch.
|
|
73
55
|
- The working tree has uncommitted changes that are not part of the requested
|
|
74
56
|
PR cleanup.
|
|
75
|
-
-
|
|
57
|
+
- Neither `origin/development` nor `origin/main` exists.
|
|
76
58
|
- A rebase or validation fix would require behavior changes instead of coding
|
|
77
59
|
criteria cleanup.
|
|
78
60
|
|
|
61
|
+
If no open pull request exists for the target branch and selected base, create
|
|
62
|
+
one as part of the merge workflow when the user requested push/PR/merge
|
|
63
|
+
completion.
|
|
64
|
+
|
|
79
65
|
## Workflow
|
|
80
66
|
|
|
81
|
-
1. Capture the base branch, target branch,
|
|
67
|
+
1. Capture the base branch, target branch, and authentication state:
|
|
82
68
|
|
|
83
69
|
```sh
|
|
84
70
|
gh auth status
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
if git ls-remote --exit-code --heads origin development >/dev/null 2>&1; then
|
|
72
|
+
base="development"
|
|
73
|
+
elif git ls-remote --exit-code --heads origin main >/dev/null 2>&1; then
|
|
74
|
+
base="main"
|
|
75
|
+
else
|
|
76
|
+
echo "No origin/development or origin/main branch exists."
|
|
77
|
+
exit 1
|
|
78
|
+
fi
|
|
88
79
|
target_branch="$(git branch --show-current)"
|
|
89
80
|
test -n "$target_branch"
|
|
90
81
|
test "$target_branch" != "$base"
|
|
91
82
|
git status --short
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
If the user names a target branch, use that branch instead of the current
|
|
86
|
+
branch. If the target branch is not local but exists on `origin`, create a
|
|
87
|
+
local branch from the remote head before continuing:
|
|
88
|
+
|
|
89
|
+
```sh
|
|
90
|
+
if ! git show-ref --verify --quiet "refs/heads/$target_branch"; then
|
|
91
|
+
git fetch origin "$target_branch:$target_branch"
|
|
92
|
+
fi
|
|
93
|
+
git switch "$target_branch"
|
|
92
94
|
git fetch origin "$base" --prune
|
|
93
|
-
pr_number="$(gh pr list --head "$target_branch" --base "$base" --state open --json number --jq '.[0].number // empty')"
|
|
94
|
-
test -n "$pr_number"
|
|
95
|
-
protected="$(gh api "repos/{owner}/{repo}/branches/$target_branch" --jq '.protected' 2>/dev/null || echo false)"
|
|
96
95
|
```
|
|
97
96
|
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
2. Push the target branch to the same remote branch name. Do not use
|
|
98
|
+
`--no-verify`; pre-push hooks must run.
|
|
100
99
|
|
|
101
|
-
|
|
100
|
+
```sh
|
|
101
|
+
git push -u origin "$target_branch"
|
|
102
|
+
local_sha="$(git rev-parse HEAD)"
|
|
103
|
+
remote_sha="$(git ls-remote --heads origin "$target_branch" | awk '{print $1}')"
|
|
104
|
+
test "$local_sha" = "$remote_sha"
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
3. Reuse an existing open PR for this exact branch/base pair, or create one
|
|
108
|
+
when none exists:
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
pr_number="$(gh pr list \
|
|
112
|
+
--head "$target_branch" \
|
|
113
|
+
--base "$base" \
|
|
114
|
+
--state open \
|
|
115
|
+
--json number \
|
|
116
|
+
--jq '.[0].number // empty')"
|
|
117
|
+
|
|
118
|
+
if [ -z "$pr_number" ]; then
|
|
119
|
+
git log --reverse --format='%s' "origin/$base..HEAD"
|
|
120
|
+
git diff --stat "origin/$base...HEAD"
|
|
121
|
+
pr_url="$(gh pr create \
|
|
122
|
+
--base "$base" \
|
|
123
|
+
--head "$target_branch" \
|
|
124
|
+
--title "$title" \
|
|
125
|
+
--body "$body")"
|
|
126
|
+
pr_number="$(gh pr view "$pr_url" --json number --jq '.number')"
|
|
127
|
+
fi
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
4. Mark draft PRs ready and check mergeability before changing history:
|
|
102
131
|
|
|
103
132
|
```sh
|
|
133
|
+
is_draft="$(gh pr view "$pr_number" --json isDraft --jq '.isDraft')"
|
|
134
|
+
if [ "$is_draft" = "true" ]; then
|
|
135
|
+
gh pr ready "$pr_number"
|
|
136
|
+
fi
|
|
104
137
|
gh pr view "$pr_number" --json mergeStateStatus,mergeable,headRefName,baseRefName
|
|
105
138
|
if git merge-tree --write-tree HEAD "origin/$base" >/tmp/pull-request-merge-close-merge-tree.out
|
|
106
139
|
then
|
|
@@ -110,7 +143,7 @@ Do not continue automatically when:
|
|
|
110
143
|
fi
|
|
111
144
|
```
|
|
112
145
|
|
|
113
|
-
|
|
146
|
+
5. If a merge conflict is detected, rebase the target branch on the fresh base
|
|
114
147
|
branch. Abort and stop if the rebase conflicts:
|
|
115
148
|
|
|
116
149
|
```sh
|
|
@@ -125,33 +158,14 @@ Do not continue automatically when:
|
|
|
125
158
|
fi
|
|
126
159
|
```
|
|
127
160
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
4. Load and apply all relevant repository skills before merging:
|
|
131
|
-
- Read the repository's `.agents/skills/**/SKILL.md` files that apply to the
|
|
132
|
-
changed code, plus shared workspace standards when present.
|
|
133
|
-
- Compare the target branch against the base with
|
|
134
|
-
`git diff --stat "origin/$base...HEAD"` and inspect changed files.
|
|
135
|
-
- Check whether the target branch satisfies the applicable coding,
|
|
136
|
-
architecture, validation, security, and style criteria from those skills.
|
|
137
|
-
- Run the validation commands required by the skills and repository hooks.
|
|
138
|
-
- If criteria are not met and the fix does not change functionality, make the
|
|
139
|
-
minimal cleanup, stage only intended files, commit to the target branch,
|
|
140
|
-
and push the target branch.
|
|
141
|
-
- If meeting the criteria would change behavior, stop and report the gap.
|
|
142
|
-
|
|
143
|
-
5. Confirm the PR is still mergeable after validation changes:
|
|
144
|
-
|
|
145
|
-
```sh
|
|
146
|
-
git fetch origin "$base" --prune
|
|
147
|
-
git merge-tree --write-tree HEAD "origin/$base" >/tmp/pull-request-merge-close-final-merge-tree.out
|
|
148
|
-
gh pr checks "$pr_number"
|
|
149
|
-
```
|
|
161
|
+
6. Load and apply all relevant repository skills before merging, then confirm
|
|
162
|
+
the PR is still mergeable after any validation changes.
|
|
150
163
|
|
|
151
|
-
|
|
164
|
+
7. Merge the PR with GitHub CLI. Delete the remote target branch only when it is
|
|
152
165
|
not protected:
|
|
153
166
|
|
|
154
167
|
```sh
|
|
168
|
+
protected="$(gh api "repos/{owner}/{repo}/branches/$target_branch" --jq '.protected' 2>/dev/null || echo false)"
|
|
155
169
|
if [ "$protected" = true ]; then
|
|
156
170
|
gh pr merge "$pr_number" --squash --admin
|
|
157
171
|
else
|
|
@@ -159,17 +173,27 @@ Do not continue automatically when:
|
|
|
159
173
|
fi
|
|
160
174
|
```
|
|
161
175
|
|
|
162
|
-
|
|
176
|
+
8. If the merge succeeded and the remote branch still exists while unprotected,
|
|
177
|
+
delete it explicitly:
|
|
163
178
|
|
|
164
179
|
```sh
|
|
165
|
-
git
|
|
180
|
+
if [ "$protected" != true ] && git ls-remote --exit-code --heads origin "$target_branch" >/dev/null 2>&1; then
|
|
181
|
+
git push origin --delete "$target_branch"
|
|
182
|
+
fi
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
9. Clean up the local repository after merge:
|
|
186
|
+
|
|
187
|
+
```sh
|
|
188
|
+
git fetch origin --prune
|
|
166
189
|
git switch "$base"
|
|
167
190
|
git pull --ff-only origin "$base"
|
|
168
191
|
git branch -d "$target_branch" || git branch -D "$target_branch"
|
|
169
192
|
git ls-remote --heads origin "$target_branch"
|
|
170
193
|
```
|
|
171
194
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
195
|
+
10. Final response should include the PR URL, selected base branch, whether a
|
|
196
|
+
rebase was performed, what validation and skill checks ran, whether any
|
|
197
|
+
cleanup commit was added, whether the remote target branch was deleted or
|
|
198
|
+
protected, whether the local target branch was deleted, and whether local
|
|
199
|
+
base branch is up to date.
|