@staff0rd/assist 0.282.0 → 0.282.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/dist/index.js +50 -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.282.
|
|
9
|
+
version: "0.282.1",
|
|
10
10
|
type: "module",
|
|
11
11
|
main: "dist/index.js",
|
|
12
12
|
bin: {
|
|
@@ -7273,6 +7273,47 @@ 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: "git commit",
|
|
7284
|
+
message: `Do not run 'git commit' directly. Use 'assist commit "<message>"' instead.`
|
|
7285
|
+
}
|
|
7286
|
+
];
|
|
7287
|
+
function matchesBuiltinDeny(part) {
|
|
7288
|
+
return BUILTIN_DENIES.find(
|
|
7289
|
+
(rule) => part === rule.pattern || part.startsWith(`${rule.pattern} `)
|
|
7290
|
+
);
|
|
7291
|
+
}
|
|
7292
|
+
function findBuiltinDeny(parts) {
|
|
7293
|
+
const rule = parts.map(matchesBuiltinDeny).find(Boolean);
|
|
7294
|
+
if (!rule) return void 0;
|
|
7295
|
+
return {
|
|
7296
|
+
permissionDecision: "deny",
|
|
7297
|
+
permissionDecisionReason: rule.message
|
|
7298
|
+
};
|
|
7299
|
+
}
|
|
7300
|
+
function rawDenyRegex(pattern2) {
|
|
7301
|
+
const tokens = pattern2.trim().split(/\s+/).map((token) => token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("\\s+");
|
|
7302
|
+
return new RegExp(`(?<=^|\\s)${tokens}(?=\\s|$)`);
|
|
7303
|
+
}
|
|
7304
|
+
var RAW_BUILTIN_DENIES = BUILTIN_DENIES.map((rule) => ({
|
|
7305
|
+
...rule,
|
|
7306
|
+
regex: rawDenyRegex(rule.pattern)
|
|
7307
|
+
}));
|
|
7308
|
+
function findBuiltinDenyRaw(rawCommand) {
|
|
7309
|
+
const rule = RAW_BUILTIN_DENIES.find((r) => r.regex.test(rawCommand));
|
|
7310
|
+
if (!rule) return void 0;
|
|
7311
|
+
return {
|
|
7312
|
+
permissionDecision: "deny",
|
|
7313
|
+
permissionDecisionReason: rule.message
|
|
7314
|
+
};
|
|
7315
|
+
}
|
|
7316
|
+
|
|
7276
7317
|
// src/commands/cliHook/logDeniedToolCall.ts
|
|
7277
7318
|
import { mkdirSync as mkdirSync8 } from "fs";
|
|
7278
7319
|
import { homedir as homedir7 } from "os";
|
|
@@ -7591,31 +7632,6 @@ function matchesConfigDeny(command) {
|
|
|
7591
7632
|
);
|
|
7592
7633
|
}
|
|
7593
7634
|
|
|
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
7635
|
// src/commands/cliHook/resolvePermission.ts
|
|
7620
7636
|
var SUBCOMMAND_READS = [
|
|
7621
7637
|
{
|
|
@@ -7699,7 +7715,7 @@ function tryParseInput(raw) {
|
|
|
7699
7715
|
function decide(toolName, rawCommand) {
|
|
7700
7716
|
const result = splitCompound(rawCommand);
|
|
7701
7717
|
if (result.ok) return resolvePermission(toolName, result.parts);
|
|
7702
|
-
return findDeny(toolName, [rawCommand]);
|
|
7718
|
+
return findBuiltinDenyRaw(rawCommand) ?? findDeny(toolName, [rawCommand]);
|
|
7703
7719
|
}
|
|
7704
7720
|
async function cliHook() {
|
|
7705
7721
|
const input = tryParseInput(await readStdin());
|
|
@@ -7726,17 +7742,20 @@ async function cliHook() {
|
|
|
7726
7742
|
}
|
|
7727
7743
|
|
|
7728
7744
|
// src/commands/cliHook/cliHookCheck.ts
|
|
7729
|
-
function
|
|
7730
|
-
|
|
7731
|
-
|
|
7732
|
-
console.log(`denied: ${denied.permissionDecisionReason}`);
|
|
7745
|
+
function reportDecision(decision) {
|
|
7746
|
+
if (!decision) return false;
|
|
7747
|
+
console.log(`denied: ${decision.permissionDecisionReason}`);
|
|
7733
7748
|
process.exitCode = 1;
|
|
7734
7749
|
return true;
|
|
7735
7750
|
}
|
|
7751
|
+
function reportDeny(toolName, parts) {
|
|
7752
|
+
return reportDecision(findDeny(toolName, parts));
|
|
7753
|
+
}
|
|
7736
7754
|
function cliHookCheck(command, toolName = "Bash") {
|
|
7737
7755
|
const trimmed = command.trim();
|
|
7738
7756
|
const result = splitCompound(trimmed);
|
|
7739
7757
|
if (!result.ok) {
|
|
7758
|
+
if (reportDecision(findBuiltinDenyRaw(trimmed))) return;
|
|
7740
7759
|
if (reportDeny(toolName, [trimmed])) return;
|
|
7741
7760
|
console.log(`not approved (${result.error})`);
|
|
7742
7761
|
process.exitCode = 1;
|