@senomas/pi-git-hat 0.1.0 → 0.2.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/README.md +8 -0
- package/git-hat.ts +42 -41
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
A [pi](https://github.com/earendil-works/pi) extension that maps git branches to roles (planner, implementor, reviewer, admin) and enforces role-based permissions.
|
|
6
6
|
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pi install npm:@senomas/pi-git-hat
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
No other dependencies needed. On first startup, role prompts and a default `roles.json` auto-seed into your project's `.pi/`.
|
|
14
|
+
|
|
7
15
|
## Features
|
|
8
16
|
|
|
9
17
|
- **Role-based branch switching** — `/hat` TUI to pick branches grouped by role
|
package/git-hat.ts
CHANGED
|
@@ -1289,46 +1289,11 @@ If the user asks you to make changes, tell them to switch to an appropriate bran
|
|
|
1289
1289
|
};
|
|
1290
1290
|
}
|
|
1291
1291
|
if (isBash) {
|
|
1292
|
-
const cmd = ((event.input as { command?: string }).command ?? "").trim();
|
|
1293
|
-
|
|
1294
|
-
// Allow: read-only commands
|
|
1295
|
-
if (
|
|
1296
|
-
/^(ls|cd|pwd|echo|date|which|whoami|uname|hostname|env|true|false|yes|time|seq|head|tail|wc|sort|uniq|jq|dirname|basename|cat|printf)\b/.test(
|
|
1297
|
-
cmd,
|
|
1298
|
-
)
|
|
1299
|
-
) {
|
|
1300
|
-
return;
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
// Allow: git read-only commands
|
|
1304
|
-
if (
|
|
1305
|
-
/^git\s+(status|log|diff|branch|show|grep|blame|describe|rev-parse|rev-list|shortlog|config|check-ignore|whatchanged|cherry|name-rev|ls-tree|ls-files|ls-remote|stash\s+list|tag)\b/.test(
|
|
1306
|
-
cmd,
|
|
1307
|
-
)
|
|
1308
|
-
) {
|
|
1309
|
-
return;
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
// Allow: git branch switching
|
|
1313
|
-
if (/^git\s+(switch|checkout)\b/.test(cmd)) {
|
|
1314
|
-
return;
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
// Allow: git add and git rebase --continue during an active rebase
|
|
1318
|
-
let rebasing = false;
|
|
1319
|
-
try {
|
|
1320
|
-
const gitDirResult = await pi.exec("git", ["rev-parse", "--git-dir"]);
|
|
1321
|
-
rebasing = existsSync(resolve(gitDirResult.stdout.trim(), "rebase-merge"));
|
|
1322
|
-
} catch { /* not a git repo */ }
|
|
1323
|
-
if (rebasing && /^git\s+(add|rebase\s+--continue)\b/.test(cmd)) {
|
|
1324
|
-
return;
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
1292
|
return {
|
|
1328
1293
|
block: true,
|
|
1329
1294
|
reason:
|
|
1330
1295
|
`\u2753 No role matched branch "${currentBranch ?? "no-git"}". ` +
|
|
1331
|
-
`
|
|
1296
|
+
`All bash commands are blocked. Switch to a matching branch via /hat (TUI selector).`,
|
|
1332
1297
|
};
|
|
1333
1298
|
}
|
|
1334
1299
|
return;
|
|
@@ -1346,13 +1311,49 @@ If the user asks you to make changes, tell them to switch to an appropriate bran
|
|
|
1346
1311
|
}
|
|
1347
1312
|
if (isBash) {
|
|
1348
1313
|
const cmd = ((event.input as { command?: string }).command ?? "").trim();
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1314
|
+
|
|
1315
|
+
// Require confirmation for git rebase (any target)
|
|
1316
|
+
if (/\bgit\s+rebase\b/.test(cmd)) {
|
|
1317
|
+
const confirmed = await ctx.ui.confirm(
|
|
1318
|
+
`Rebase onto master? Running: \`${cmd}\``,
|
|
1319
|
+
);
|
|
1320
|
+
if (!confirmed) {
|
|
1321
|
+
return { block: true, reason: "Rebase cancelled by user." };
|
|
1322
|
+
}
|
|
1323
|
+
return;
|
|
1354
1324
|
}
|
|
1325
|
+
|
|
1326
|
+
// Require confirmation for git switch/checkout
|
|
1327
|
+
if (/\bgit\s+(switch|checkout)\b/.test(cmd)) {
|
|
1328
|
+
const confirmed = await ctx.ui.confirm(
|
|
1329
|
+
`Switch branches? Running: \`${cmd}\``,
|
|
1330
|
+
);
|
|
1331
|
+
if (!confirmed) {
|
|
1332
|
+
return { block: true, reason: "Branch switch cancelled by user." };
|
|
1333
|
+
}
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
return {
|
|
1338
|
+
block: true,
|
|
1339
|
+
reason: `\uD83D\uDCCB Planner: branch not based on ${ancestry.branch}. Run \`git rebase ${ancestry.branch}\` first.`,
|
|
1340
|
+
};
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
// For known roles: require confirmation for git rebase/switch/checkout
|
|
1346
|
+
if (isBash) {
|
|
1347
|
+
const cmd = ((event.input as { command?: string }).command ?? "").trim();
|
|
1348
|
+
if (/\bgit\s+(rebase|switch|checkout)\b/.test(cmd)) {
|
|
1349
|
+
const action = /rebase/.test(cmd) ? "Rebase" : "Switch";
|
|
1350
|
+
const confirmed = await ctx.ui.confirm(
|
|
1351
|
+
`${action} branches? Running: \`${cmd}\``,
|
|
1352
|
+
);
|
|
1353
|
+
if (!confirmed) {
|
|
1354
|
+
return { block: true, reason: `${action} cancelled by user.` };
|
|
1355
1355
|
}
|
|
1356
|
+
return;
|
|
1356
1357
|
}
|
|
1357
1358
|
}
|
|
1358
1359
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senomas/pi-git-hat",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Pi extension for role-based Git branch workflows — wear different hats by switching branches",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": ["pi-package", "git", "workflow", "branching", "roles"],
|