@staff0rd/assist 0.282.0 → 0.283.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/dist/index.js +54 -31
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { Command } from "commander";
|
|
|
6
6
|
// package.json
|
|
7
7
|
var package_default = {
|
|
8
8
|
name: "@staff0rd/assist",
|
|
9
|
-
version: "0.
|
|
9
|
+
version: "0.283.0",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -7273,6 +7273,51 @@ function stripEnvPrefix(parts) {
|
|
|
7273
7273
|
return i > 0 ? parts.slice(i) : parts;
|
|
7274
7274
|
}
|
|
7275
7275
|
|
|
7276
|
+
// src/commands/cliHook/findBuiltinDeny.ts
|
|
7277
|
+
var BUILTIN_DENIES = [
|
|
7278
|
+
{
|
|
7279
|
+
pattern: "gh pr create",
|
|
7280
|
+
message: "Do not run 'gh pr create' directly. Use 'assist prs raise --title <title> --what <what> --why <why>' instead \u2014 it assembles and validates the body before delegating to gh. Before running it, get explicit approval via the AskUserQuestion tool, regardless of permission mode, with the full proposed title and body in the approve option's preview field so the user actually sees them."
|
|
7281
|
+
},
|
|
7282
|
+
{
|
|
7283
|
+
pattern: "gh pr edit",
|
|
7284
|
+
message: "Do not run 'gh pr edit' directly. Use 'assist prs edit [--title <title>] [--what <what>] [--why <why>] [--how <how>]' instead \u2014 it assembles and validates the body before delegating to gh. Before running it, get explicit approval via the AskUserQuestion tool, regardless of permission mode, with the full proposed title and body in the approve option's preview field so the user actually sees them."
|
|
7285
|
+
},
|
|
7286
|
+
{
|
|
7287
|
+
pattern: "git commit",
|
|
7288
|
+
message: `Do not run 'git commit' directly. Use 'assist commit "<message>"' instead.`
|
|
7289
|
+
}
|
|
7290
|
+
];
|
|
7291
|
+
function matchesBuiltinDeny(part) {
|
|
7292
|
+
return BUILTIN_DENIES.find(
|
|
7293
|
+
(rule) => part === rule.pattern || part.startsWith(`${rule.pattern} `)
|
|
7294
|
+
);
|
|
7295
|
+
}
|
|
7296
|
+
function findBuiltinDeny(parts) {
|
|
7297
|
+
const rule = parts.map(matchesBuiltinDeny).find(Boolean);
|
|
7298
|
+
if (!rule) return void 0;
|
|
7299
|
+
return {
|
|
7300
|
+
permissionDecision: "deny",
|
|
7301
|
+
permissionDecisionReason: rule.message
|
|
7302
|
+
};
|
|
7303
|
+
}
|
|
7304
|
+
function rawDenyRegex(pattern2) {
|
|
7305
|
+
const tokens = pattern2.trim().split(/\s+/).map((token) => token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("\\s+");
|
|
7306
|
+
return new RegExp(`(?<=^|\\s)${tokens}(?=\\s|$)`);
|
|
7307
|
+
}
|
|
7308
|
+
var RAW_BUILTIN_DENIES = BUILTIN_DENIES.map((rule) => ({
|
|
7309
|
+
...rule,
|
|
7310
|
+
regex: rawDenyRegex(rule.pattern)
|
|
7311
|
+
}));
|
|
7312
|
+
function findBuiltinDenyRaw(rawCommand) {
|
|
7313
|
+
const rule = RAW_BUILTIN_DENIES.find((r) => r.regex.test(rawCommand));
|
|
7314
|
+
if (!rule) return void 0;
|
|
7315
|
+
return {
|
|
7316
|
+
permissionDecision: "deny",
|
|
7317
|
+
permissionDecisionReason: rule.message
|
|
7318
|
+
};
|
|
7319
|
+
}
|
|
7320
|
+
|
|
7276
7321
|
// src/commands/cliHook/logDeniedToolCall.ts
|
|
7277
7322
|
import { mkdirSync as mkdirSync8 } from "fs";
|
|
7278
7323
|
import { homedir as homedir7 } from "os";
|
|
@@ -7591,31 +7636,6 @@ function matchesConfigDeny(command) {
|
|
|
7591
7636
|
);
|
|
7592
7637
|
}
|
|
7593
7638
|
|
|
7594
|
-
// src/commands/cliHook/findBuiltinDeny.ts
|
|
7595
|
-
var BUILTIN_DENIES = [
|
|
7596
|
-
{
|
|
7597
|
-
pattern: "gh pr create",
|
|
7598
|
-
message: "Do not run 'gh pr create' directly. Use 'assist prs raise --title <title> --what <what> --why <why>' instead \u2014 it assembles and validates the body before delegating to gh. Before running it, get explicit approval via the AskUserQuestion tool, regardless of permission mode, with the full proposed title and body in the approve option's preview field so the user actually sees them."
|
|
7599
|
-
},
|
|
7600
|
-
{
|
|
7601
|
-
pattern: "git commit",
|
|
7602
|
-
message: `Do not run 'git commit' directly. Use 'assist commit "<message>"' instead.`
|
|
7603
|
-
}
|
|
7604
|
-
];
|
|
7605
|
-
function matchesBuiltinDeny(part) {
|
|
7606
|
-
return BUILTIN_DENIES.find(
|
|
7607
|
-
(rule) => part === rule.pattern || part.startsWith(`${rule.pattern} `)
|
|
7608
|
-
);
|
|
7609
|
-
}
|
|
7610
|
-
function findBuiltinDeny(parts) {
|
|
7611
|
-
const rule = parts.map(matchesBuiltinDeny).find(Boolean);
|
|
7612
|
-
if (!rule) return void 0;
|
|
7613
|
-
return {
|
|
7614
|
-
permissionDecision: "deny",
|
|
7615
|
-
permissionDecisionReason: rule.message
|
|
7616
|
-
};
|
|
7617
|
-
}
|
|
7618
|
-
|
|
7619
7639
|
// src/commands/cliHook/resolvePermission.ts
|
|
7620
7640
|
var SUBCOMMAND_READS = [
|
|
7621
7641
|
{
|
|
@@ -7699,7 +7719,7 @@ function tryParseInput(raw) {
|
|
|
7699
7719
|
function decide(toolName, rawCommand) {
|
|
7700
7720
|
const result = splitCompound(rawCommand);
|
|
7701
7721
|
if (result.ok) return resolvePermission(toolName, result.parts);
|
|
7702
|
-
return findDeny(toolName, [rawCommand]);
|
|
7722
|
+
return findBuiltinDenyRaw(rawCommand) ?? findDeny(toolName, [rawCommand]);
|
|
7703
7723
|
}
|
|
7704
7724
|
async function cliHook() {
|
|
7705
7725
|
const input = tryParseInput(await readStdin());
|
|
@@ -7726,17 +7746,20 @@ async function cliHook() {
|
|
|
7726
7746
|
}
|
|
7727
7747
|
|
|
7728
7748
|
// src/commands/cliHook/cliHookCheck.ts
|
|
7729
|
-
function
|
|
7730
|
-
|
|
7731
|
-
|
|
7732
|
-
console.log(`denied: ${denied.permissionDecisionReason}`);
|
|
7749
|
+
function reportDecision(decision) {
|
|
7750
|
+
if (!decision) return false;
|
|
7751
|
+
console.log(`denied: ${decision.permissionDecisionReason}`);
|
|
7733
7752
|
process.exitCode = 1;
|
|
7734
7753
|
return true;
|
|
7735
7754
|
}
|
|
7755
|
+
function reportDeny(toolName, parts) {
|
|
7756
|
+
return reportDecision(findDeny(toolName, parts));
|
|
7757
|
+
}
|
|
7736
7758
|
function cliHookCheck(command, toolName = "Bash") {
|
|
7737
7759
|
const trimmed = command.trim();
|
|
7738
7760
|
const result = splitCompound(trimmed);
|
|
7739
7761
|
if (!result.ok) {
|
|
7762
|
+
if (reportDecision(findBuiltinDenyRaw(trimmed))) return;
|
|
7740
7763
|
if (reportDeny(toolName, [trimmed])) return;
|
|
7741
7764
|
console.log(`not approved (${result.error})`);
|
|
7742
7765
|
process.exitCode = 1;
|