@oked/sdk 0.6.15 → 0.6.16
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/classify.js +75 -0
- package/package.json +2 -2
package/dist/classify.js
CHANGED
|
@@ -866,6 +866,76 @@ function classifyEnvStage(stage) {
|
|
|
866
866
|
}
|
|
867
867
|
return "safe"; // `env` / `env -u X` with no command just prints the environment
|
|
868
868
|
}
|
|
869
|
+
// git global options that consume a following argument token (`-C dir`,
|
|
870
|
+
// `-c key=value`, `--git-dir dir`, …). The `--opt=value` forms are one token.
|
|
871
|
+
const GIT_GLOBAL_ARG_OPTS = new Set([
|
|
872
|
+
"-C", "-c", "--git-dir", "--work-tree", "--namespace", "--config-env", "--super-prefix",
|
|
873
|
+
]);
|
|
874
|
+
/**
|
|
875
|
+
* `git [global options] <subcommand> [args]`: global options such as `-C dir`,
|
|
876
|
+
* `-c key=value`, `--git-dir=…` and `--no-pager` come BEFORE the subcommand, so
|
|
877
|
+
* the `^git\s+push` / `^git\s+branch -D` patterns never saw them
|
|
878
|
+
* (`git -C repo push --force origin main` was safe). Strips the global options
|
|
879
|
+
* and classifies `git <subcommand> [args]` by the same rules. A `-c alias.*`
|
|
880
|
+
* can define a shell command, so it gets a `review` floor. Returns null if the
|
|
881
|
+
* stage is not a git call with global options.
|
|
882
|
+
*/
|
|
883
|
+
function classifyGitGlobalOptsStage(stage, ephemeralVars) {
|
|
884
|
+
const lead = /^git[ \t]+(?=-)/.exec(stage);
|
|
885
|
+
if (!lead)
|
|
886
|
+
return null;
|
|
887
|
+
const readToken = (from) => {
|
|
888
|
+
let i = from;
|
|
889
|
+
let quote = null;
|
|
890
|
+
while (i < stage.length) {
|
|
891
|
+
const ch = stage[i];
|
|
892
|
+
if (quote) {
|
|
893
|
+
if (ch === quote)
|
|
894
|
+
quote = null;
|
|
895
|
+
i++;
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
if (ch === '"' || ch === "'") {
|
|
899
|
+
quote = ch;
|
|
900
|
+
i++;
|
|
901
|
+
continue;
|
|
902
|
+
}
|
|
903
|
+
if (/\s/.test(ch))
|
|
904
|
+
break;
|
|
905
|
+
i++;
|
|
906
|
+
}
|
|
907
|
+
return i;
|
|
908
|
+
};
|
|
909
|
+
let floor = "safe";
|
|
910
|
+
let i = lead[0].length;
|
|
911
|
+
while (i < stage.length) {
|
|
912
|
+
while (i < stage.length && /\s/.test(stage[i]))
|
|
913
|
+
i++;
|
|
914
|
+
if (i >= stage.length)
|
|
915
|
+
break;
|
|
916
|
+
const start = i;
|
|
917
|
+
i = readToken(i);
|
|
918
|
+
const tok = stage.slice(start, i);
|
|
919
|
+
if (!tok.startsWith("-")) {
|
|
920
|
+
const inner = classifyBashCommand(`git ${stage.slice(start).trim()}`, ephemeralVars);
|
|
921
|
+
return maxTier(floor, inner);
|
|
922
|
+
}
|
|
923
|
+
let value = "";
|
|
924
|
+
if (GIT_GLOBAL_ARG_OPTS.has(tok)) {
|
|
925
|
+
while (i < stage.length && /\s/.test(stage[i]))
|
|
926
|
+
i++;
|
|
927
|
+
const vStart = i;
|
|
928
|
+
i = readToken(i);
|
|
929
|
+
value = unquote(stage.slice(vStart, i));
|
|
930
|
+
}
|
|
931
|
+
else if (tok.startsWith("-c") && tok.length > 2) {
|
|
932
|
+
value = unquote(tok.slice(2)); // `-ckey=value`
|
|
933
|
+
}
|
|
934
|
+
if ((tok === "-c" || tok.startsWith("-c")) && /^alias\./i.test(value))
|
|
935
|
+
floor = "review";
|
|
936
|
+
}
|
|
937
|
+
return floor; // `git -C dir` with no subcommand prints help
|
|
938
|
+
}
|
|
869
939
|
// ssh options that consume a following argument token (the rest are flags).
|
|
870
940
|
const SSH_ARG_OPTS = new Set([
|
|
871
941
|
"-b", "-c", "-D", "-E", "-e", "-F", "-I", "-i", "-J", "-L", "-l", "-m",
|
|
@@ -1070,6 +1140,11 @@ function classifyStageShellEffects(stage, ephemeralVars = new Set()) {
|
|
|
1070
1140
|
// NOT a deletion — that's the false positive DELETE_COMMAND_RE avoids.
|
|
1071
1141
|
if (isEphemeralOnlyDeletion(stage, ephemeralVars))
|
|
1072
1142
|
return "warning";
|
|
1143
|
+
// `git -C repo …` / `git -c k=v …`: classify the subcommand without the
|
|
1144
|
+
// global options, so the git patterns below and in the full scan apply.
|
|
1145
|
+
const gitTier = classifyGitGlobalOptsStage(stage, ephemeralVars);
|
|
1146
|
+
if (gitTier !== null)
|
|
1147
|
+
return gitTier;
|
|
1073
1148
|
// rmdir removes only EMPTY folders (it fails on a folder with files), so no
|
|
1074
1149
|
// data is lost and `mkdir` undoes it: a reversible local change.
|
|
1075
1150
|
const deleteStage = stage.replace(DELETE_LEAD, "");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oked/sdk",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.16",
|
|
4
4
|
"description": "OKed SDK - human approval layer for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"access": "public"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@oked/receipt-core": "0.6.
|
|
48
|
+
"@oked/receipt-core": "0.6.16"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@types/node": "^22.13.10",
|