@senomas/pi-git-hat 0.1.0 → 0.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/README.md +8 -0
- package/git-hat.ts +35 -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,42 @@ 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
|
+
// Always allow rebase master/main (required to fix ancestry)
|
|
1316
|
+
if (/^git\s+rebase\s+(master|main)\b/.test(cmd)) {
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
// Require confirmation for git switch/checkout
|
|
1321
|
+
if (/^git\s+(switch|checkout)\b/.test(cmd)) {
|
|
1322
|
+
const confirmed = await ctx.ui.confirm(
|
|
1323
|
+
`Switch branches? Running: \`${cmd}\``,
|
|
1324
|
+
);
|
|
1325
|
+
if (!confirmed) {
|
|
1326
|
+
return { block: true, reason: "Branch switch cancelled by user." };
|
|
1327
|
+
}
|
|
1328
|
+
return;
|
|
1354
1329
|
}
|
|
1330
|
+
|
|
1331
|
+
return {
|
|
1332
|
+
block: true,
|
|
1333
|
+
reason: `\uD83D\uDCCB Planner: branch not based on ${ancestry.branch}. Run \`git rebase ${ancestry.branch}\` first.`,
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
// For known roles: require confirmation for git branch switching
|
|
1340
|
+
if (isBash) {
|
|
1341
|
+
const cmd = ((event.input as { command?: string }).command ?? "").trim();
|
|
1342
|
+
if (/^git\s+(switch|checkout)\b/.test(cmd)) {
|
|
1343
|
+
const confirmed = await ctx.ui.confirm(
|
|
1344
|
+
`Switch branches? Running: \`${cmd}\``,
|
|
1345
|
+
);
|
|
1346
|
+
if (!confirmed) {
|
|
1347
|
+
return { block: true, reason: "Branch switch cancelled by user." };
|
|
1355
1348
|
}
|
|
1349
|
+
return;
|
|
1356
1350
|
}
|
|
1357
1351
|
}
|
|
1358
1352
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@senomas/pi-git-hat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
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"],
|