Build and deploy apps through your company's DKOD: policy, templates, Deploy questions and Deliver, with a DKOD band above the prompt and the DKOD rules on…

<img src="assets/readme/hero-light.svg" width="100%" alt="DKOD plugin for Claude Code and Cursor. Keep your AI agent. Ship by your rules.">
<a href="#install"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/install-claude-code-dark.svg"><img src="assets/readme/install-claude-code-light.svg" height="76" alt="Install in Claude Code"></picture></a> <a href="#cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/install-cursor-dark.svg"><img src="assets/readme/install-cursor-light.svg" height="76" alt="Install in Cursor"></picture></a> <a href="https://dkod.ai"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/dkod-ai-dark.svg"><img src="assets/readme/dkod-ai-light.svg" height="76" alt="dkod.ai"></picture></a>
<a href="LICENSE"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/badge-license-dark.svg"><img src="assets/readme/badge-license-light.svg" alt="License: MIT"></picture></a> <a href="https://github.com/dkod-ai/dkod-plugin/commits/main"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/badge-version-dark.svg"><img src="assets/readme/badge-version-light.svg" alt="Plugin version"></picture></a> <a href="#install"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/badge-agents-dark.svg"><img src="assets/readme/badge-agents-light.svg" alt="Works in Claude Code and Cursor"></picture></a> <a href="#what-the-rules-check"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/badge-events-dark.svg"><img src="assets/readme/badge-events-light.svg" alt="Events: none sent"></picture></a> <a href="https://dashboard.dkod.app/docs"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/badge-docs-dark.svg"><img src="assets/readme/badge-docs-light.svg" alt="Docs: in the DKOD dashboard"></picture></a>
<a href="#what-it-adds"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/nav-adds-dark.svg"><img src="assets/readme/nav-adds-light.svg" alt="What it adds"></picture></a> <a href="#install"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/nav-install-dark.svg"><img src="assets/readme/nav-install-light.svg" alt="Install"></picture></a> <a href="#cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/nav-cursor-dark.svg"><img src="assets/readme/nav-cursor-light.svg" alt="Cursor"></picture></a> <a href="#cloud-sessions"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/nav-cloud-dark.svg"><img src="assets/readme/nav-cloud-light.svg" alt="Cloud sessions"></picture></a> <a href="#dkoder-and-guard"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/nav-guard-dark.svg"><img src="assets/readme/nav-guard-light.svg" alt="Dkoder and Guard"></picture></a> <a href="#what-the-rules-check"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/nav-rules-dark.svg"><img src="assets/readme/nav-rules-light.svg" alt="What the rules check"></picture></a> <a href="#limits"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/nav-limits-dark.svg"><img src="assets/readme/nav-limits-light.svg" alt="Limits"></picture></a>
<h2 id="what-it-adds"><sub><picture><img src="assets/readme/dot-yellow.svg" width="18" height="10" alt=""></picture>What it adds</sub><br><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/h-adds-dark.svg"><img src="assets/readme/h-adds-light.svg" alt="Three parts, one plugin."></picture></h2>
dkod: your org's policy, templates, Deploy questions, Deploy, build answers, Deliver and Remove.dkod: tells Claude how to use them, in the right order.<img src="assets/readme/band-light.svg" width="100%" alt="The Dkoder band above the Claude Code prompt. Before you sign in it is yellow and says: Sign in to DKOD for Deliver and your organization's Guard rules: type /mcp, pick dkod, then Authenticate. Signed in, it is cyan and says: on, Guard on, refund-admin, Deliver required.">
<h2 id="install"><sub><picture><img src="assets/readme/dot-cyan.svg" width="18" height="10" alt=""></picture>Install</sub><br><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/h-install-dark.svg"><img src="assets/readme/h-install-light.svg" alt="Ready in three steps."></picture></h2>
/plugin marketplace add dkod-ai/dkod-plugin
/plugin install dkod@dkod-ai
/mcp, pick dkod and choose Authenticate. You sign in with your company's own sign-in.<br>DKOD never sees a password.Until you sign in, the band above the prompt is yellow.
<h2 id="cursor"><sub><picture><img src="assets/readme/dot-violet.svg" width="18" height="10" alt=""></picture>Cursor</sub><br><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/h-cursor-dark.svg"><img src="assets/readme/h-cursor-light.svg" alt="One repository, two agents."></picture></h2>
The same repository is a Cursor plugin. In Cursor you get the dkod MCP server and the dkod skill. You do not get the band or the rules: those run only in Claude Code.
Your team admin can import dkod-ai/dkod-plugin as a team marketplace in the Cursor dashboard. To install it for yourself only, on macOS or Linux:
mkdir -p ~/.cursor/plugins/local/dkod
curl -fsSL https://github.com/dkod-ai/dkod-plugin/archive/refs/heads/main.tar.gz | tar -xz --strip-components 1 -C ~/.cursor/plugins/local/dkod
On Windows, in PowerShell:
curl.exe -fsSLo "$env:TEMP\dkod-plugin.tar.gz" https://github.com/dkod-ai/dkod-plugin/archive/refs/heads/main.tar.gz
mkdir -Force "$env:USERPROFILE\.cursor\plugins\local\dkod"
tar.exe -xzf "$env:TEMP\dkod-plugin.tar.gz" --strip-components 1 -C "$env:USERPROFILE\.cursor\plugins\local\dkod"
It needs no git, so a Mac without Apple's developer tools asks nothing. Do not run it with sudo: then root owns the folder, and the update cannot write to it.
Restart Cursor. Then open Settings → MCP, find DKOD and choose Connect. You sign in with your company's own sign-in.
Cursor does not update a plugin in ~/.cursor/plugins/local. The DKOD server tells the agent when your copy is old, and the agent runs the update. It needs no git: your DKOD dashboard serves the plugin, and the update script writes it over the folder. To update by hand:
node ~/.cursor/plugins/local/dkod/skills/dkod/scripts/dkod-update.mjs ~/.cursor/plugins/local/dkod https://<your DKOD dashboard>/api/v1/dkoder/bundle/cursor.json
With Python and no Node, run dkod-update.py from the same folder with python3 and the same two arguments. Cursor loads the new plugin by itself. A team marketplace with Enable Auto Refresh on updates by itself.
Cursor's Auto-review can stop each dkod tool call for approval. To allow the dkod tools, add them to mcpAllowlist in ~/.cursor/permissions.json:
{
"mcpAllowlist": ["plugin-dkod-dkod:*", "dkod:*"]
}
This list replaces the MCP allowlist in Cursor's settings, so copy those entries into the file too. Run Mode must be Auto-review, Allowlist or Run Everything. See Cursor permissions.
<h2 id="cloud-sessions"><sub><picture><img src="assets/readme/dot-mint.svg" width="18" height="10" alt=""></picture>Cloud sessions</sub><br><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/h-cloud-dark.svg"><img src="assets/readme/h-cloud-light.svg" alt="Add the server to the cloud."></picture></h2>
Plugins do not load in a cloud session, so add the DKOD MCP server to the cloud itself. The server gives the agent the dkod skill and its scripts through the dkoder.guide tool.
https://dashboard.dkod.app/api/v1/dkoder/mcp
The default Trusted network reaches your organization's storage on AWS, Google Cloud and Cloudflare R2.
<h2 id="dkoder-and-guard"><sub><picture><img src="assets/readme/dot-orange.svg" width="18" height="10" alt=""></picture>Dkoder and Guard</sub><br><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/h-guard-dark.svg"><img src="assets/readme/h-guard-light.svg" alt="The floor, plus your rules."></picture></h2>
| Dkoder | Guard | |
|---|---|---|
| What | This plugin, in your agent | Your organization's policy, as rules |
| Rules | The floor, the same for every organization | Your organization's own, from its governance repository |
| Needs | Nothing. Works signed out; the band asks you to sign in | Sign-in through /mcp, or your company's device install |
<h2 id="what-the-rules-check"><sub><picture><img src="assets/readme/dot-pink.svg" width="18" height="10" alt=""></picture>What the rules check</sub><br><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/h-rules-dark.svg"><img src="assets/readme/h-rules-light.svg" alt="App code ships through Deliver."></picture></h2>
The rules need to know your org: which GitHub owners are yours, which repository is the governance repository, and the org's own blocked commands. Dkoder gets those facts from DKOD when you sign in through /mcp, if your organization turned Guard on. Your company can also install Dkoder on its devices from the DKOD dashboard; that copy cannot be turned off. Then, in the org's repositories, the floor refuses:
git push, gh pr merge and GitHub API writes to an app repository. App code ships through Deliver.--no-verify, core.hooksPath).Guard adds your organization's own rules on top, such as blocked commands. A refusal says which one refused: the Dkoder floor, or a Guard rule of your organization.
Before you sign in, nothing names your org, so a repository with a remote is left alone. A folder with no remote still gets the secret check. This plugin sends no events and needs no install file.
<h2 id="limits"><sub><picture><img src="assets/readme/dot-coral.svg" width="18" height="10" alt=""></picture>Limits</sub><br><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/h-limits-dark.svg"><img src="assets/readme/h-limits-light.svg" alt="Guide rails, not a lock."></picture></h2>
[!IMPORTANT] The rules keep Claude on the Deliver path. They are not a security boundary against a person.
To stop direct pushes for real, protect the app repository on GitHub (branch protection or rulesets). DKOD's Deliver does not need a person to push.
<a href="https://dkod.ai"><picture><source media="(prefers-color-scheme: dark)" srcset="assets/readme/dkod-dark.svg"><img src="assets/readme/dkod-light.svg" height="30" alt="DKOD"></picture></a>
hooks/register.js 4721 lines1// Built by packages/dkoder-plugin/scripts/build-claude.ts from dkod-app. Do not edit: run `bun run --cwd packages/dkoder-plugin build:claude`.
2var MAX_DEPTH = 4;
3var MAX_LINE = 64 * 1024;
4var OPERATORS = ["&&", "||", ";;", "|&", ";", "|", "&", "(", ")", `
5`];
6function tokenize(line, subs) {
7 const out = [];
8 let word = "";
9 let inWord = false;
10 const flush = () => {
11 if (inWord)
12 out.push({ kind: "word", text: word });
13 word = "";
14 inWord = false;
15 };
16 let i = 0;
17 const n = Math.min(line.length, MAX_LINE);
18 const readParen = (start) => {
19 let depth = 1;
20 let j = start;
21 while (j < n && depth > 0) {
22 const c = line[j];
23 if (c === "\\") {
24 j += 2;
25 continue;
26 }
27 if (c === "'") {
28 const end = line.indexOf("'", j + 1);
29 j = end < 0 ? n : end + 1;
30 continue;
31 }
32 if (c === '"') {
33 j += 1;
34 while (j < n && line[j] !== '"')
35 j += line[j] === "\\" ? 2 : 1;
36 j += 1;
37 continue;
38 }
39 if (c === "(")
40 depth += 1;
41 else if (c === ")")
42 depth -= 1;
43 j += 1;
44 }
45 return j;
46 };
47 const readBacktick = (start) => {
48 let j = start;
49 while (j < n && line[j] !== "`")
50 j += line[j] === "\\" ? 2 : 1;
51 return j;
52 };
53 while (i < n) {
54 const c = line[i];
55 if (c === "\\") {
56 if (line[i + 1] === `
57`) {
58 i += 2;
59 continue;
60 }
61 word += line[i + 1] ?? "";
62 inWord = true;
63 i += 2;
64 continue;
65 }
66 if (c === "'") {
67 const end = line.indexOf("'", i + 1);
68 const stop = end < 0 ? n : end;
69 word += line.slice(i + 1, stop);
70 inWord = true;
71 i = stop + 1;
72 continue;
73 }
74 if (c === "$" && line[i + 1] === "'") {
75 let j = i + 2;
76 while (j < n && line[j] !== "'") {
77 if (line[j] === "\\" && j + 1 < n) {
78 const e = line[j + 1];
79 word += e === "n" ? `
80` : e === "t" ? "\t" : e;
81 j += 2;
82 } else {
83 word += line[j];
84 j += 1;
85 }
86 }
87 inWord = true;
88 i = j + 1;
89 continue;
90 }
91 if (c === '"') {
92 let j = i + 1;
93 while (j < n && line[j] !== '"') {
94 const d = line[j];
95 if (d === "\\" && j + 1 < n && '"\\$`\n'.includes(line[j + 1])) {
96 if (line[j + 1] !== `
97`)
98 word += line[j + 1];
99 j += 2;
100 continue;
101 }
102 if (d === "$" && line[j + 1] === "(") {
103 const end = readParen(j + 2);
104 subs.push(line.slice(j + 2, end - 1));
105 word += line.slice(j, end);
106 j = end;
107 continue;
108 }
109 if (d === "`") {
110 const end = readBacktick(j + 1);
111 subs.push(line.slice(j + 1, end));
112 word += line.slice(j, end + 1);
113 j = end + 1;
114 continue;
115 }
116 word += d;
117 j += 1;
118 }
119 inWord = true;
120 i = j + 1;
121 continue;
122 }
123 if (c === "$" && line[i + 1] === "(") {
124 const end = readParen(i + 2);
125 subs.push(line.slice(i + 2, end - 1));
126 word += line.slice(i, end);
127 inWord = true;
128 i = end;
129 continue;
130 }
131 if (c === "`") {
132 const end = readBacktick(i + 1);
133 subs.push(line.slice(i + 1, end));
134 word += line.slice(i, end + 1);
135 inWord = true;
136 i = end + 1;
137 continue;
138 }
139 if (c === "#" && !inWord) {
140 const end = line.indexOf(`
141`, i);
142 i = end < 0 ? n : end;
143 continue;
144 }
145 if (c === " " || c === "\t" || c === "\r") {
146 flush();
147 i += 1;
148 continue;
149 }
150 const op = OPERATORS.find((o) => line.startsWith(o, i));
151 if (op !== undefined) {
152 flush();
153 out.push({ kind: "op", text: op });
154 i += op.length;
155 continue;
156 }
157 if (c === ">" || c === "<") {
158 if (inWord && /^\d+$/.test(word)) {
159 word = "";
160 inWord = false;
161 }
162 flush();
163 if (line.startsWith("<<", i) && line[i + 2] !== "<") {
164 const m = /^<<(-?)[ \t]*(?:'([^'\n]*)'|"([^"\n]*)"|\\?([A-Za-z0-9_.-]+))/.exec(line.slice(i, i + 200));
165 if (m) {
166 const delim = m[2] ?? m[3] ?? m[4] ?? "";
167 const nl = line.indexOf(`
168`, i);
169 let bodyEnd = n;
170 if (nl >= 0) {
171 let k = nl + 1;
172 while (k < n) {
173 const e = line.indexOf(`
174`, k);
175 const stop = e < 0 ? n : e;
176 const text = m[1] === "-" ? line.slice(k, stop).replace(/^\t+/, "") : line.slice(k, stop);
177 if (text === delim) {
178 bodyEnd = stop;
179 break;
180 }
181 k = stop + 1;
182 }
183 const rest = line.slice(i + m[0].length, nl);
184 out.push(...tokenize(rest, subs));
185 out.push({ kind: "op", text: `
186` });
187 }
188 i = bodyEnd;
189 continue;
190 }
191 }
192 let j = i;
193 while (j < n && (line[j] === ">" || line[j] === "<" || line[j] === "&" || line[j] === "|" || line[j] === "-"))
194 j += 1;
195 const op = line.slice(i, j);
196 out.push({ kind: "op", text: "redirect", write: op.includes(">") && !op.endsWith("&") });
197 i = j;
198 continue;
199 }
200 word += c;
201 inWord = true;
202 i += 1;
203 }
204 flush();
205 return out;
206}
207var ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
208function programName(word) {
209 const slash = word.lastIndexOf("/");
210 return slash < 0 ? word : word.slice(slash + 1);
211}
212function joinCd(current, target) {
213 if (target.startsWith("/") || target.startsWith("~"))
214 return target;
215 if (current === "" || current === ".")
216 return target;
217 return `${current.replace(/\/$/, "")}/${target}`;
218}
219var KEYWORDS = new Set(["!", "if", "elif", "then", "else", "while", "until", "do", "time", "coproc"]);
220var SHELLS = new Set(["bash", "sh", "zsh", "dash", "ksh"]);
221function unwrap(argv, env) {
222 let a = argv;
223 for (let guard = 0;guard < 8 && a.length > 0; guard += 1) {
224 const prog = programName(a[0]);
225 if (prog === "env") {
226 let i = 1;
227 while (i < a.length && (a[i].startsWith("-") || ASSIGNMENT.test(a[i]))) {
228 if (ASSIGNMENT.test(a[i]))
229 env = [...env, a[i]];
230 if (a[i] === "-u" || a[i] === "-C" || a[i] === "-S")
231 i += 1;
232 i += 1;
233 }
234 a = a.slice(i);
235 continue;
236 }
237 if (prog === "command" || prog === "builtin" || prog === "exec" || prog === "nohup" || prog === "time" || prog === "nice") {
238 let i = 1;
239 while (i < a.length && a[i].startsWith("-"))
240 i += a[i] === "-n" && prog === "nice" ? 2 : 1;
241 a = a.slice(i);
242 continue;
243 }
244 if (prog === "sudo" || prog === "doas") {
245 let i = 1;
246 while (i < a.length && a[i].startsWith("-"))
247 i += ["-u", "-g", "-C", "-D", "-h", "-p", "-U"].includes(a[i]) ? 2 : 1;
248 a = a.slice(i);
249 continue;
250 }
251 if (prog === "timeout") {
252 let i = 1;
253 while (i < a.length && a[i].startsWith("-"))
254 i += a[i] === "-s" || a[i] === "-k" ? 2 : 1;
255 a = a.slice(i + 1);
256 continue;
257 }
258 if (prog === "xargs") {
259 let i = 1;
260 while (i < a.length && a[i].startsWith("-"))
261 i += ["-I", "-n", "-P", "-L", "-s", "-d", "-E"].includes(a[i]) ? 2 : 1;
262 a = a.slice(i);
263 continue;
264 }
265 if (SHELLS.has(prog)) {
266 const c = a.findIndex((w, i) => i > 0 && /^-[a-z]*c[a-z]*$/.test(w));
267 if (c > 0 && a[c + 1] !== undefined)
268 return { argv: a, env, script: a[c + 1] };
269 return { argv: a, env, script: null };
270 }
271 if (prog === "eval")
272 return { argv: a, env, script: a.slice(1).join(" ") };
273 break;
274 }
275 return { argv: a, env, script: null };
276}
277function parseCommands(line, depth = 0) {
278 if (depth > MAX_DEPTH)
279 return [];
280 const subs = [];
281 const tokens = tokenize(line, subs);
282 const out = [];
283 let cd = "";
284 let words = [];
285 let skipNext = false;
286 let writeNext = false;
287 let writes = [];
288 const end = () => {
289 const targets = writes;
290 writes = [];
291 if (words.length === 0)
292 return;
293 let i = 0;
294 const env = [];
295 while (i < words.length && ASSIGNMENT.test(words[i]))
296 env.push(words[i++]);
297 const raw = words.slice(i);
298 words = [];
299 if (raw.length === 0)
300 return;
301 const { argv, env: allEnv, script } = unwrap(raw, env);
302 if (argv.length === 0)
303 return;
304 if (programName(argv[0]) === "cd" || programName(argv[0]) === "pushd") {
305 const target = argv.slice(1).find((w) => !w.startsWith("-"));
306 cd = target === undefined ? "~" : joinCd(cd, target);
307 return;
308 }
309 out.push(targets.length > 0 ? { argv, env: allEnv, cd, writes: targets } : { argv, env: allEnv, cd });
310 if (script !== null) {
311 for (const inner of parseCommands(script, depth + 1))
312 out.push({ ...inner, cd: inner.cd === "" ? cd : joinCd(cd, inner.cd) });
313 }
314 };
315 for (const t of tokens) {
316 if (t.kind === "op") {
317 if (t.text === "redirect") {
318 skipNext = true;
319 writeNext = t.write === true;
320 continue;
321 }
322 end();
323 continue;
324 }
325 if (skipNext) {
326 skipNext = false;
327 if (writeNext)
328 writes.push(t.text);
329 continue;
330 }
331 if (t.text === "{" || t.text === "}") {
332 end();
333 continue;
334 }
335 if (words.length === 0 && KEYWORDS.has(t.text))
336 continue;
337 words.push(t.text);
338 }
339 end();
340 for (const body of subs)
341 for (const inner of parseCommands(body, depth + 1))
342 out.push(inner);
343 return out;
344}
345
346function literalMessage(word) {
347 if (!/[`$]/.test(word))
348 return word;
349 const t = word.trim();
350 const open = /^\$\(cat[ \t]*<<-?[ \t]*(?:'(\w+)'|"(\w+)"|(\w+))[ \t]*\n/.exec(t);
351 if (open !== null && t.endsWith(")")) {
352 const delim = open[1] ?? open[2] ?? open[3];
353 const lines = t.slice(open[0].length, -1).split(`
354`);
355 const end = lines.findIndex((l) => l.trim() === delim);
356 if (end >= 0 && lines.slice(end + 1).every((l) => l.trim() === "")) {
357 const body = lines.slice(0, end).join(`
358`);
359 return open[3] !== undefined && /[`$]/.test(body) ? null : body.replace(/\n+$/, "");
360 }
361 return null;
362 }
363 const printf = /^\$\(printf[ \t]+'%s\\n'((?:[ \t]+'[^']*')+)[ \t]*\)$/.exec(t);
364 if (printf !== null)
365 return [...printf[1].matchAll(/'([^']*)'/g)].map((m) => m[1]).join(`
366`).replace(/\n+$/, "");
367 return null;
368}
369var join = (a, b) => b === "" ? a : a === "" ? b : b.startsWith("/") || b.startsWith("~") ? b : `${a.replace(/\/$/, "")}/${b}`;
370var GIT_GLOBAL_VALUE = new Set(["-C", "-c", "--git-dir", "--work-tree", "--namespace", "--exec-path", "--config-env", "--super-prefix", "--list-cmds", "--attr-source"]);
371var GIT_GLOBAL_HARMLESS = new Set(["-C", "-P", "--no-pager", "--paginate", "-p", "--no-optional-locks", "--literal-pathspecs", "--glob-pathspecs", "--noglob-pathspecs", "--icase-pathspecs", "--no-replace-objects", "--no-lazy-fetch", "--no-advice", "--bare"]);
372var PUSH_VALUE = new Set(["-o", "--push-option", "--receive-pack", "--exec", "--repo", "--signed"]);
373var COMMIT_VALUE = new Set(["-m", "--message", "-F", "--file", "-C", "--reuse-message", "-c", "--reedit-message", "--author", "--date", "-t", "--template", "--fixup", "--squash", "--cleanup", "--trailer", "--pathspec-from-file"]);
374var GIT_BUILTINS = new Set("add am annotate apply archive bisect blame branch bundle cat-file check-attr check-ignore checkout cherry cherry-pick citool clean clone column commit commit-graph commit-tree config count-objects credential describe diff diff-files diff-index diff-tree difftool fetch for-each-ref format-patch fsck gc grep hash-object help init interpret-trailers log ls-files ls-remote ls-tree maintenance merge merge-base merge-file merge-tree mergetool mktag mktree mv name-rev notes pack-objects prune pull push range-diff read-tree rebase reflog remote repack replace request-pull rerere reset restore rev-list rev-parse revert rm send-pack shortlog show show-branch show-ref sparse-checkout stash status submodule switch symbolic-ref tag update-index update-ref var verify-commit verify-pack verify-tag version whatchanged worktree write-tree lfs".split(" "));
375var GH_GROUPS = new Set("alias api attestation auth browse cache co codespace completion config copilot extension gist gpg-key help issue label org pr preview project release repo ruleset run search secret ssh-key status variable workflow".split(" "));
376var HOOKS_PATH = /hookspath/i;
377var HARMLESS_GIT_ENV = /^GIT_(SSH_COMMAND|SSH|TERMINAL_PROMPT|ASKPASS|PAGER|EDITOR|SEQUENCE_EDITOR|TRACE[A-Z_]*|AUTHOR_[A-Z]+|COMMITTER_[A-Z]+|PROGRESS_DELAY|REDACT_COOKIES|CURL_VERBOSE|HTTP_LOW_SPEED_[A-Z]+|OPTIONAL_LOCKS|FLUSH)=/;
378var RISKY_ALIAS = /(^|\s)(push|send-pack|merge|api)(\s|$)|^!/;
379function pushAction(cmd, dir, rest, opaque, out) {
380 let force = false;
381 let remote = null;
382 let sawRemote = false;
383 for (let j = 0;j < rest.length; j += 1) {
384 const w = rest[j];
385 if (w === "--")
386 continue;
387 if (w.startsWith("--repo=")) {
388 remote = w.slice("--repo=".length);
389 sawRemote = true;
390 continue;
391 }
392 if (w === "--repo") {
393 remote = rest[j + 1] ?? null;
394 sawRemote = true;
395 j += 1;
396 continue;
397 }
398 if (w === "--no-verify") {
399 out.push({ kind: "hook-bypass", cmd, dir, how: "git push --no-verify" });
400 continue;
401 }
402 if (w === "--force" || w.startsWith("--force-with-lease") || w === "--force-if-includes" || w === "--mirror" || w === "--delete") {
403 force = true;
404 continue;
405 }
406 if (w.startsWith("--receive-pack") || w.startsWith("--exec"))
407 opaque = opaque ?? "a custom receive-pack";
408 if (/^-[A-Za-z]+$/.test(w)) {
409 if (w.includes("f") || w.includes("d"))
410 force = true;
411 if (PUSH_VALUE.has(w))
412 j += 1;
413 continue;
414 }
415 if (w.startsWith("-")) {
416 if (PUSH_VALUE.has(w))
417 j += 1;
418 continue;
419 }
420 if (!sawRemote) {
421 remote = w;
422 sawRemote = true;
423 continue;
424 }
425 if (w.startsWith("+") || w.startsWith(":"))
426 force = true;
427 }
428 out.push({ kind: "push", cmd, dir, remote, force, opaque });
429}
430var remoteKey = (dir, name) => `${dir.replace(/^\.\/?/, "").replace(/\/+$/, "")}\x00${name}`;
431var CLONE_VALUE = new Set(["-b", "--branch", "-o", "--origin", "--depth", "-c", "--config", "--reference", "--reference-if-able", "--template", "-u", "--upload-pack", "--separate-git-dir", "--filter", "-j", "--jobs", "--shallow-since", "--shallow-exclude", "--bundle-uri"]);
432function gitActions(cmd, depth, made = new Map) {
433 const out = [];
434 let dir = cmd.cd;
435 const direct = programName(cmd.argv[0] ?? "").slice("git-".length);
436 const a = direct === "" ? cmd.argv : ["git", direct, ...cmd.argv.slice(1)];
437 let opaque = null;
438 for (const e of cmd.env) {
439 if (/^GIT_CONFIG/.test(e) && HOOKS_PATH.test(e))
440 out.push({ kind: "hook-bypass", cmd, dir, how: "a hooks path set in the environment" });
441 if (/^GIT_/.test(e) && !HARMLESS_GIT_ENV.test(e))
442 opaque = opaque ?? `${e.split("=")[0]} in the environment`;
443 }
444 const local = new Map;
445 const prefix = ["git"];
446 let i = 1;
447 while (i < a.length && a[i].startsWith("-")) {
448 const opt = a[i];
449 const eq = opt.indexOf("=");
450 const name = eq < 0 ? opt : opt.slice(0, eq);
451 const value = eq < 0 ? a[i + 1] : opt.slice(eq + 1);
452 const width = GIT_GLOBAL_VALUE.has(name) && eq < 0 ? 2 : 1;
453 if (name === "-C" && value !== undefined)
454 dir = join(dir, value);
455 else
456 prefix.push(...a.slice(i, i + width));
457 if ((name === "-c" || name === "--config-env") && value !== undefined) {
458 if (HOOKS_PATH.test(value))
459 out.push({ kind: "hook-bypass", cmd, dir, how: "git -c core.hooksPath" });
460 const alias = /^alias\.([^=]+)=(.*)$/s.exec(value);
461 if (alias)
462 local.set(alias[1].toLowerCase(), alias[2]);
463 }
464 if (!GIT_GLOBAL_HARMLESS.has(name))
465 opaque = opaque ?? `git ${name}`;
466 i += width;
467 }
468 const sub = a[i];
469 const rest = a.slice(i + 1);
470 if (sub === undefined)
471 return out;
472 const inline = local.get(sub.toLowerCase());
473 if (inline !== undefined && !GIT_BUILTINS.has(sub)) {
474 out.push(...expandAlias("git", inline, prefix, rest, { ...cmd, cd: dir }, depth));
475 return out;
476 }
477 if (sub === "clone") {
478 let origin = "origin";
479 const pos = [];
480 for (let j = 0;j < rest.length; j += 1) {
481 const w = rest[j];
482 const eq = w.indexOf("=");
483 if (w === "-o" || w === "--origin")
484 origin = rest[j + 1] ?? origin;
485 else if (w.startsWith("--origin="))
486 origin = w.slice(eq + 1);
487 if (w.startsWith("-")) {
488 if (eq < 0 && CLONE_VALUE.has(w))
489 j += 1;
490 continue;
491 }
492 pos.push(w);
493 }
494 const [url, target] = pos;
495 if (url !== undefined) {
496 const base = target ?? url.replace(/\/+$/, "").replace(/\.git$/, "").split(/[/:]/).pop() ?? "";
497 if (base !== "")
498 made.set(remoteKey(join(dir, base), origin), url);
499 }
500 if (made.size === 0)
501 made.set("", "");
502 return out;
503 }
504 if (sub === "remote" && (rest[0] === "add" || rest[0] === "set-url")) {
505 const pos = rest.slice(1).filter((w) => !w.startsWith("-"));
506 made.set(remoteKey(dir, pos[0] ?? ""), pos[pos.length - 1] ?? "");
507 return out;
508 }
509 if (sub === "push") {
510 pushAction(cmd, dir, rest, opaque, out);
511 const p = out[out.length - 1];
512 if (p.kind === "push" && made.size > 0) {
513 p.lineRemote = true;
514 const url = made.get(remoteKey(dir, p.remote ?? "origin"));
515 if (url !== undefined)
516 p.also = [url];
517 }
518 return out;
519 }
520 if (sub === "send-pack") {
521 const remote = rest.find((w) => !w.startsWith("-")) ?? null;
522 out.push({ kind: "push", cmd, dir, remote, force: rest.includes("--force"), opaque });
523 return out;
524 }
525 if (sub === "commit") {
526 let all = false;
527 const paragraphs = [];
528 let elsewhere = false;
529 for (let j = 0;j < rest.length; j += 1) {
530 const w = rest[j];
531 if (w === "--no-verify") {
532 out.push({ kind: "hook-bypass", cmd, dir, how: "git commit --no-verify" });
533 continue;
534 }
535 if (w === "--all" || w === "--include" || w === "--only") {
536 all = true;
537 continue;
538 }
539 if (w === "--") {
540 if (j + 1 < rest.length)
541 all = true;
542 break;
543 }
544 if (/^-[A-Za-z]+$/.test(w)) {
545 for (let k = 1;k < w.length; k += 1) {
546 const ch = w[k];
547 if (ch === "n")
548 out.push({ kind: "hook-bypass", cmd, dir, how: "git commit -n" });
549 if (ch === "a" || ch === "i" || ch === "o")
550 all = true;
551 if (COMMIT_VALUE.has(`-${ch}`)) {
552 const value = k === w.length - 1 ? rest[j + 1] : w.slice(k + 1);
553 if (k === w.length - 1)
554 j += 1;
555 if (ch === "m")
556 paragraphs.push(value === undefined ? null : literalMessage(value));
557 else if (ch === "F" || ch === "C" || ch === "c")
558 elsewhere = true;
559 break;
560 }
561 }
562 continue;
563 }
564 if (w.startsWith("-")) {
565 const [flag, inline] = w.includes("=") ? [w.slice(0, w.indexOf("=")), w.slice(w.indexOf("=") + 1)] : [w, undefined];
566 const value = inline ?? (COMMIT_VALUE.has(flag) ? rest[j + 1] : undefined);
567 if (inline === undefined && COMMIT_VALUE.has(flag))
568 j += 1;
569 if (flag === "--message")
570 paragraphs.push(value === undefined ? null : literalMessage(value));
571 else if (flag === "--file" || flag === "--reuse-message" || flag === "--reedit-message" || flag === "--fixup" || flag === "--squash")
572 elsewhere = true;
573 continue;
574 }
575 all = true;
576 }
577 const message = elsewhere || paragraphs.length === 0 || paragraphs.includes(null) ? null : paragraphs.join(`
578
579`);
580 out.push({ kind: "commit", cmd, dir, all, message });
581 return out;
582 }
583 if (sub === "config") {
584 if (rest.some((w) => HOOKS_PATH.test(w)))
585 out.push({ kind: "hook-bypass", cmd, dir, how: "git config core.hooksPath" });
586 const key = rest.findIndex((w) => /^alias\./i.test(w));
587 if (key >= 0) {
588 const value = rest.slice(key + 1).join(" ");
589 if (RISKY_ALIAS.test(value.trim()))
590 out.push({ kind: "hook-bypass", cmd, dir, how: `a git alias for "${value.slice(0, 40)}"` });
591 }
592 return out;
593 }
594 if (["merge", "rebase", "am", "cherry-pick", "revert", "pull"].includes(sub) && rest.includes("--no-verify")) {
595 out.push({ kind: "hook-bypass", cmd, dir, how: `git ${sub} --no-verify` });
596 return out;
597 }
598 if (!GIT_BUILTINS.has(sub))
599 out.push({ kind: "alias", tool: "git", name: sub, prefix, args: rest, cmd, dir });
600 return out;
601}
602var MAX_ALIAS_DEPTH = 3;
603function expandAlias(tool, value, prefix, args, cmd, depth = 0) {
604 if (depth >= MAX_ALIAS_DEPTH)
605 return [{ kind: "hook-bypass", cmd, dir: cmd.cd, how: `a ${tool} alias nested too deep to read` }];
606 const quoted = args.map((w) => `'${w.replace(/'/g, `'\\''`)}'`).join(" ");
607 if (value.startsWith("!")) {
608 const inner = parseCommands(`${value.slice(1)} ${quoted}`).map((c) => ({ ...c, cd: join(cmd.cd, c.cd) }));
609 return actionsOf(inner, depth + 1);
610 }
611 const words = parseCommands(value)[0]?.argv ?? [];
612 const argv = [...prefix, ...words, ...args];
613 return actionsOf([{ argv, env: cmd.env, cd: cmd.cd }], depth + 1);
614}
615var REPO_ARG = /^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100}$/;
616function repoFromRef(ref) {
617 const url = /^https?:\/\/[^/]+\/(?:api\/v3\/)?(?:repos\/)?([^/\s]+)\/([^/\s#?]+)/.exec(ref);
618 if (url)
619 return `${url[1]}/${url[2].replace(/\.git$/, "")}`;
620 const host = /^(?:[^/\s]+\/)?([A-Za-z0-9][A-Za-z0-9-]{0,38}\/[A-Za-z0-9._-]{1,100})$/.exec(ref);
621 if (host && REPO_ARG.test(host[1]))
622 return host[1];
623 return null;
624}
625function rawPath(endpoint) {
626 let p = endpoint.trim().replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]*/i, "");
627 if (!endpoint.includes("://"))
628 p = p.replace(/^api\.github\.com(?::\d+)?/i, "");
629 try {
630 p = decodeURIComponent(p);
631 } catch {}
632 return p.replace(/[?#].*$/, "").replace(/\/{2,}/g, "/").replace(/^\//, "");
633}
634function apiPath(endpoint) {
635 return rawPath(endpoint).replace(/^api\/v3\//i, "");
636}
637function repoFromApiPath(endpoint) {
638 const m = /^repos\/([^/]+)\/([^/]+)/i.exec(apiPath(endpoint));
639 if (!m)
640 return null;
641 return m[1] === "{owner}" || m[2] === "{repo}" || m[1] === ":owner" || m[2] === ":repo" ? "current" : `${m[1]}/${m[2]}`;
642}
643var WRITE_METHODS = new Set(["POST", "PUT", "PATCH", "DELETE"]);
644var GH_REPO_WRITES = new Set(["delete", "edit", "rename", "archive", "unarchive", "sync", "set-default"]);
645var isDynamic = (w) => /[$`]/.test(w);
646function ghActions(cmd) {
647 const a = cmd.argv;
648 const dir = cmd.cd;
649 const envRepo = cmd.env.filter((e) => e.startsWith("GH_REPO=")).pop()?.slice("GH_REPO=".length) ?? null;
650 let repoFlag = envRepo !== null && envRepo !== "" ? envRepo : null;
651 const words = [];
652 for (let i = 1;i < a.length; i += 1) {
653 const w = a[i];
654 if (w === "-R" || w === "--repo") {
655 repoFlag = a[i + 1] ?? null;
656 i += 1;
657 continue;
658 }
659 if (w.startsWith("--repo=")) {
660 repoFlag = w.slice("--repo=".length);
661 continue;
662 }
663 if (/^-R./.test(w)) {
664 repoFlag = w.slice(w[2] === "=" ? 3 : 2);
665 continue;
666 }
667 words.push(w);
668 }
669 const repo = repoFlag === null ? null : isDynamic(repoFlag) ? "unknown" : repoFromRef(repoFlag) ?? repoFlag;
670 const targetRepo = (target) => target === undefined ? repo : isDynamic(target) ? "unknown" : repoFromRef(target) ?? repo;
671 const [group, verb] = words;
672 if (group === undefined)
673 return [];
674 if (group === "pr" && verb === "merge") {
675 const target = words.slice(2).find((w) => !w.startsWith("-"));
676 if (target !== undefined && isDynamic(target))
677 return [{ kind: "merge", cmd, dir, repo: "unknown" }];
678 const fromUrl = target !== undefined && target.includes("://") ? repoFromRef(target) : null;
679 return [{ kind: "merge", cmd, dir, repo: fromUrl ?? repo }];
680 }
681 if (group === "repo" && verb !== undefined && GH_REPO_WRITES.has(verb)) {
682 return [{ kind: "repo-write", cmd, dir, repo: targetRepo(words.slice(2).find((w) => !w.startsWith("-"))) }];
683 }
684 if (group === "repo" && verb === "create" && words.includes("--push")) {
685 return [{ kind: "repo-write", cmd, dir, repo: targetRepo(words.slice(2).find((w) => !w.startsWith("-"))) }];
686 }
687 if (group === "alias" && (verb === "set" || verb === "import")) {
688 const value = words.slice(3).filter((w) => !w.startsWith("-")).join(" ");
689 if (verb === "import" || RISKY_ALIAS.test(value.trim()) || words.includes("--shell") || words.includes("-s")) {
690 return [{ kind: "hook-bypass", cmd, dir, how: verb === "import" ? "gh alias import" : `a gh alias for "${value.slice(0, 40)}"` }];
691 }
692 return [];
693 }
694 if (group === "api") {
695 let method = null;
696 let hasFields = false;
697 let endpoint = null;
698 let mutation = false;
699 for (let i = 1;i < words.length; i += 1) {
700 const w = words[i];
701 if (w === "-X" || w === "--method") {
702 method = (words[i + 1] ?? "").toUpperCase();
703 i += 1;
704 continue;
705 }
706 if (w.startsWith("--method=")) {
707 method = w.slice("--method=".length).toUpperCase();
708 continue;
709 }
710 if (/^-X[A-Za-z]+$/.test(w)) {
711 method = w.slice(2).toUpperCase();
712 continue;
713 }
714 if (w === "-f" || w === "-F" || w === "--field" || w === "--raw-field" || w === "--input") {
715 hasFields = true;
716 if (/^query=\s*mutation\b/.test(words[i + 1] ?? ""))
717 mutation = true;
718 i += 1;
719 continue;
720 }
721 if (/^--(?:raw-)?field=/.test(w) || w.startsWith("--input=")) {
722 hasFields = true;
723 if (/=query=\s*mutation\b/.test(w))
724 mutation = true;
725 continue;
726 }
727 if (w === "-H" || w === "--header" || w === "-q" || w === "--jq" || w === "-t" || w === "--template" || w === "--cache" || w === "-p" || w === "--preview" || w === "--hostname") {
728 i += 1;
729 continue;
730 }
731 if (w.startsWith("-"))
732 continue;
733 if (endpoint === null)
734 endpoint = w;
735 }
736 const isWrite = method !== null ? WRITE_METHODS.has(method) : hasFields;
737 if (!isWrite || endpoint === null)
738 return [];
739 if (isDynamic(endpoint))
740 return [{ kind: "api-write", cmd, dir, repo: "unknown" }];
741 if (/^graphql\/?$/i.test(apiPath(endpoint)))
742 return mutation || hasFields ? [{ kind: "api-write", cmd, dir, repo }] : [];
743 const named = repoFromApiPath(endpoint);
744 if (named === null)
745 return /^[a-z]/i.test(apiPath(endpoint)) && !/^repos\b/i.test(apiPath(endpoint)) ? [] : [{ kind: "api-write", cmd, dir, repo: "unknown" }];
746 return [{ kind: "api-write", cmd, dir, repo: named === "current" ? repo : named }];
747 }
748 if (!GH_GROUPS.has(group))
749 return [{ kind: "alias", tool: "gh", name: group, prefix: ["gh", ...repoFlag !== null ? ["-R", repoFlag] : []], args: words.slice(1), cmd, dir }];
750 return [];
751}
752var HTTP_TOOLS = new Set(["curl", "wget", "http", "https", "xh", "xhs"]);
753function isGitHubApi(w) {
754 const m = /^(?:[a-z][a-z0-9+.-]*:\/\/)?(?:[^@/]*@)?([^/:?#]+)/i.exec(w.trim());
755 const host = (m?.[1] ?? "").toLowerCase().replace(/\.$/, "");
756 if (host === "api.github.com")
757 return true;
758 return /^[a-z][a-z0-9+.-]*:\/\//i.test(w.trim()) && /^api\/v3(\/|$)/i.test(rawPath(w));
759}
760var CURL_VALUE = new Set(["-H", "--header", "-o", "--output", "-u", "--user", "-A", "--user-agent", "-e", "--referer", "-b", "--cookie", "-c", "--cookie-jar", "-w", "--write-out", "-m", "--max-time", "--connect-timeout", "-x", "--proxy", "--retry", "-r", "--range", "-E", "--cert", "--cacert", "--key", "--resolve", "--connect-to", "--oauth2-bearer"]);
761var CURL_SHORT_VALUE = "HouAebcwmxrEK";
762function httpActions(cmd) {
763 const prog = programName(cmd.argv[0] ?? "");
764 const args = cmd.argv.slice(1);
765 let write = false;
766 let opaque = false;
767 const urls = [];
768 for (let i = 0;i < args.length; i += 1) {
769 const w = args[i];
770 if (prog === "curl") {
771 if (w === "--url") {
772 urls.push(args[i + 1] ?? "");
773 i += 1;
774 continue;
775 }
776 if (w.startsWith("--url=")) {
777 urls.push(w.slice(6));
778 continue;
779 }
780 if (w === "-K" || w === "--config") {
781 opaque = true;
782 i += 1;
783 continue;
784 }
785 if (w.startsWith("--config=")) {
786 opaque = true;
787 continue;
788 }
789 if (w === "--request" || w === "-X") {
790 write = write || WRITE_METHODS.has((args[i + 1] ?? "").toUpperCase());
791 i += 1;
792 continue;
793 }
794 if (w.startsWith("--request=")) {
795 write = write || WRITE_METHODS.has(w.slice(10).toUpperCase());
796 continue;
797 }
798 if (/^--(data|json|form|upload-file)/.test(w)) {
799 write = true;
800 if (!w.includes("="))
801 i += 1;
802 continue;
803 }
804 if (CURL_VALUE.has(w)) {
805 i += 1;
806 continue;
807 }
808 if (/^-[A-Za-z]/.test(w)) {
809 const body = w.slice(1);
810 for (let k = 0;k < body.length; k += 1) {
811 const ch = body[k];
812 const tail = body.slice(k + 1);
813 const value = tail !== "" ? tail : args[i + 1] ?? "";
814 if (ch === "X") {
815 write = write || WRITE_METHODS.has(value.toUpperCase());
816 if (tail === "")
817 i += 1;
818 break;
819 }
820 if (ch === "d" || ch === "F" || ch === "T") {
821 write = true;
822 if (tail === "")
823 i += 1;
824 break;
825 }
826 if (ch === "K") {
827 opaque = true;
828 if (tail === "")
829 i += 1;
830 break;
831 }
832 if (CURL_SHORT_VALUE.includes(ch)) {
833 if (tail === "")
834 i += 1;
835 break;
836 }
837 }
838 continue;
839 }
840 if (w.startsWith("-"))
841 continue;
842 urls.push(w);
843 } else if (prog === "wget") {
844 if (/^--method=/i.test(w))
845 write = write || WRITE_METHODS.has(w.slice(9).toUpperCase());
846 else if (w === "--method") {
847 write = write || WRITE_METHODS.has((args[i + 1] ?? "").toUpperCase());
848 i += 1;
849 } else if (/^--(post|body)-(data|file)/.test(w))
850 write = true;
851 else if (!w.startsWith("-"))
852 urls.push(w);
853 } else {
854 if (/^[A-Za-z]+$/.test(w) && WRITE_METHODS.has(w.toUpperCase())) {
855 write = true;
856 continue;
857 }
858 if (w.startsWith("-"))
859 continue;
860 if (isGitHubApi(w) || /^[a-z][a-z0-9+.-]*:\/\//i.test(w)) {
861 urls.push(w);
862 continue;
863 }
864 if (/^[^=:@]+(:=|==|=|@)/.test(w))
865 write = true;
866 }
867 }
868 if (opaque)
869 return [{ kind: "api-write", cmd, dir: cmd.cd, repo: "unknown" }];
870 const api = urls.filter(isGitHubApi);
871 if (!write || api.length === 0)
872 return [];
873 const out = [];
874 for (const u of api) {
875 const path = apiPath(u);
876 const repo = repoFromApiPath(u);
877 if (repo !== null && repo !== "current")
878 out.push({ kind: "api-write", cmd, dir: cmd.cd, repo });
879 else if (/^graphql\/?$/i.test(path) || !/^[a-z]/i.test(path) || /^repos\b/i.test(path))
880 out.push({ kind: "api-write", cmd, dir: cmd.cd, repo: "unknown" });
881 }
882 return out;
883}
884var EXPORTERS = new Set(["export", "declare", "typeset", "readonly", "local", "set"]);
885function actionsOf(cmds, depth = 0) {
886 const out = [];
887 const made = new Map;
888 const lineEnv = [];
889 for (const cmd of cmds) {
890 const prog = programName(cmd.argv[0] ?? "");
891 lineEnv.push(...cmd.env.filter((e) => e.startsWith("GH_REPO=")).filter(() => cmd.argv.length === 0));
892 if (EXPORTERS.has(prog))
893 lineEnv.push(...cmd.argv.slice(1).filter((w) => w.startsWith("GH_REPO=")));
894 if (prog === "git" || prog.startsWith("git-") && GIT_BUILTINS.has(prog.slice(4)))
895 out.push(...gitActions(cmd, depth, made));
896 else if (prog === "gh")
897 out.push(...ghActions(lineEnv.length > 0 ? { ...cmd, env: [...lineEnv, ...cmd.env] } : cmd));
898 else if (HTTP_TOOLS.has(prog))
899 out.push(...httpActions(cmd));
900 }
901 return out;
902}
903function repoFromRemoteUrl(url) {
904 const u = url.trim();
905 const full = /^(?:https?|ssh|git):\/\/(?:[^@/]+@)?[^/:]+(?::\d+)?\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/.exec(u);
906 if (full)
907 return `${full[1]}/${full[2]}`;
908 const scp = /^(?:[^@/:]+@)?[^/:]+:\/?([^/]+)\/([^/]+?)(?:\.git)?\/?$/.exec(u);
909 if (scp && !u.startsWith("/") && !u.startsWith("."))
910 return `${scp[1]}/${scp[2]}`;
911 return null;
912}
913
914var ENV_FILE_MAX_BYTES = 256 * 1024;
915var QUOTES = { "'": "single", '"': "double", "`": "backtick" };
916var ESCAPES = { n: `
917`, r: "\r", t: "\t", '"': '"', "\\": "\\" };
918var isBlank = (char) => char === " " || char === "\t";
919var isLetter = (char) => char !== undefined && (char >= "a" && char <= "z" || char >= "A" && char <= "Z");
920var isDigit = (char) => char !== undefined && char >= "0" && char <= "9";
921var isNameStart = (char) => isLetter(char) || char === "_";
922var isNameChar = (char) => isNameStart(char) || isDigit(char) || char === "." || char === "-";
923function parseEnvFile(input) {
924 if (input.length > ENV_FILE_MAX_BYTES || new TextEncoder().encode(input).length > ENV_FILE_MAX_BYTES)
925 return { ok: false, problem: "too_large" };
926 if (input.includes("\x00"))
927 return { ok: false, problem: "nul_byte" };
928 const text = (input.charCodeAt(0) === 65279 ? input.slice(1) : input).replace(/\r\n?/g, `
929`);
930 const found = new Map;
931 const skipped = [];
932 let pos = 0;
933 let line = 1;
934 const lineEnd = (from) => {
935 const at = text.indexOf(`
936`, from);
937 return at === -1 ? text.length : at;
938 };
939 const skipBlanks = (from) => {
940 let at = from;
941 while (isBlank(text[at]))
942 at += 1;
943 return at;
944 };
945 while (pos < text.length) {
946 const startLine = line;
947 let end = lineEnd(pos);
948 let at = skipBlanks(pos);
949 if (at < end && text[at] !== "#") {
950 if (text.startsWith("export", at) && isBlank(text[at + 6]))
951 at = skipBlanks(at + 6);
952 const nameFrom = at;
953 if (isNameStart(text[at]))
954 while (isNameChar(text[at]))
955 at += 1;
956 const name = text.slice(nameFrom, at);
957 at = skipBlanks(at);
958 if (name === "" || text[at] !== "=") {
959 skipped.push(startLine);
960 } else {
961 const afterEquals = at + 1;
962 at = skipBlanks(afterEquals);
963 const quote = QUOTES[text[at] ?? ""];
964 if (quote !== undefined) {
965 const mark = text[at];
966 let close = at + 1;
967 let value = "";
968 while (close < text.length && text[close] !== mark) {
969 const char = text[close];
970 if (char === `
971`)
972 line += 1;
973 if (quote === "double" && char === "\\" && close + 1 < text.length) {
974 const next = text[close + 1];
975 if (next === `
976`)
977 line += 1;
978 value += ESCAPES[next] ?? char + next;
979 close += 2;
980 } else {
981 value += char;
982 close += 1;
983 }
984 }
985 if (close >= text.length)
986 return { ok: false, problem: "open_quote", line: startLine };
987 end = lineEnd(close);
988 const rest = skipBlanks(close + 1);
989 if (rest >= end || text[rest] === "#")
990 found.set(name, { name, value, line: startLine, quote });
991 else
992 skipped.push(startLine);
993 } else {
994 let stop = end;
995 if (text[at] === "#" && at > afterEquals)
996 stop = at;
997 else
998 for (let i = at + 1;i < end; i += 1)
999 if (text[i] === "#" && isBlank(text[i - 1])) {
1000 stop = i;
1001 break;
1002 }
1003 while (stop > at && isBlank(text[stop - 1]))
1004 stop -= 1;
1005 found.set(name, { name, value: text.slice(at, stop), line: startLine, quote: "none" });
1006 }
1007 }
1008 }
1009 pos = end + 1;
1010 line += 1;
1011 }
1012 return { ok: true, entries: [...found.values()], skipped };
1013}
1014var isHostChar = (char) => isLetter(char) || isDigit(char) || char === "-" || char === "_";
1015function hasHost(text, host) {
1016 const numeric = isDigit(host[0]);
1017 for (let at = text.indexOf(host);at !== -1; at = text.indexOf(host, at + 1)) {
1018 const before = text[at - 1];
1019 const after = text[at + host.length];
1020 const startsClean = !isHostChar(before) && !(numeric && before === "." && isDigit(text[at - 2]));
1021 const endsClean = !isHostChar(after) && !(after === "." && (numeric ? isDigit(text[at + host.length + 1]) : true));
1022 if (startsClean && endsClean)
1023 return true;
1024 }
1025 return false;
1026}
1027function envValueIsLocal(value) {
1028 const text = value.toLowerCase();
1029 return hasHost(text, "localhost") || hasHost(text, "host.docker.internal") || hasHost(text, "127.0.0.1") || text.includes("[::1]") || text.trim() === "::1";
1030}
1031function envValueHasReference(entry) {
1032 if (entry.quote === "single")
1033 return false;
1034 const { value } = entry;
1035 const lastClose = value.lastIndexOf("}");
1036 for (let at = value.indexOf("${");at !== -1 && at < lastClose; at = value.indexOf("${", at + 1)) {
1037 if (value[at - 1] !== "\\" && isNameStart(value[at + 2]))
1038 return true;
1039 }
1040 return false;
1041}
1042
1043var EXTERNAL_DB_ENV = /^[A-Z][A-Z0-9_]*_DATABASE_URL(?:_UNPOOLED)?$/;
1044var EXTERNAL_DB_ENV_NAMES = new Set(["DATABASE_URL_UNPOOLED", "POSTGRES_URL", "POSTGRES_PRISMA_URL", "POSTGRES_URL_NON_POOLING", "POSTGRES_URL_NO_SSL"]);
1045var isExternalDatabaseEnvName = (name) => name.length <= 200 && (EXTERNAL_DB_ENV.test(name) || EXTERNAL_DB_ENV_NAMES.has(name));
1046var SEQ_TYPES = new Set(["smallint", "integer", "bigint"]);
1047var KINDS = new Set(["p", "u", "c", "f", "x"]);
1048
1049var DROP_RULES = new Set(["env_file", "secret_file", "key_store", "binary_not_scannable"]);
1050var GUESS_RULES = new Set(["secret_assignment"]);
1051var DIRS = [
1052 ["docs", new Set(["docs", "doc", "documentation", "openspec", "adr", "adrs", "rfcs"])],
1053 ["tests", new Set([
1054 "test",
1055 "tests",
1056 "__tests__",
1057 "spec",
1058 "specs",
1059 "e2e",
1060 "fixtures",
1061 "__fixtures__",
1062 "__mocks__",
1063 "mocks",
1064 "testdata",
1065 "test-data",
1066 "cypress",
1067 "playwright",
1068 "stories",
1069 ".storybook",
1070 "bench",
1071 "benchmarks",
1072 "examples",
1073 "example",
1074 "samples"
1075 ])],
1076 ["tooling", new Set([
1077 "scripts",
1078 "script",
1079 "tools",
1080 "hack",
1081 ".github",
1082 ".gitlab",
1083 ".circleci",
1084 ".buildkite",
1085 ".husky",
1086 ".claude",
1087 ".cursor",
1088 ".vscode",
1089 ".idea",
1090 ".devcontainer",
1091 ".dkod"
1092 ])],
1093 ["deploy", new Set([
1094 "infra",
1095 "infrastructure",
1096 "deploy",
1097 "deploys",
1098 "deployment",
1099 "deployments",
1100 "k8s",
1101 "kube",
1102 "kubernetes",
1103 "helm",
1104 "chart",
1105 "charts",
1106 "kustomize",
1107 "argocd",
1108 "argo",
1109 "terraform",
1110 "pulumi",
1111 "ansible",
1112 "manifests",
1113 "sealed-secrets",
1114 "sealedsecrets",
1115 "ops",
1116 "docker"
1117 ])]
1118];
1119var SCREAMING = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
1120var PUBLIC_PREFIXES = ["VITE_", "NEXT_PUBLIC_", "PUBLIC_", "EXPO_PUBLIC_", "REACT_APP_", "NUXT_PUBLIC_", "GATSBY_", "STORYBOOK_"];
1121var DKOD_PROVIDED = new Set(["PORT", "HOST", "HOSTNAME", "NODE_ENV"]);
1122var STRONG_LAST = new Set(["TOKEN", "SECRET", "PASSWORD", "PASSWD", "PWD", "PASS", "PASSPHRASE", "CREDENTIAL", "CREDENTIALS", "APIKEY", "SECRETKEY", "PRIVATEKEY"]);
1123var KEY_QUALIFIERS = new Set([
1124 "API",
1125 "SECRET",
1126 "ACCESS",
1127 "PRIVATE",
1128 "SIGNING",
1129 "SIGNATURE",
1130 "ENCRYPTION",
1131 "ENCRYPT",
1132 "CRYPTO",
1133 "CIPHER",
1134 "HMAC",
1135 "JWT",
1136 "LICENSE",
1137 "LICENCE",
1138 "AUTH",
1139 "CLIENT",
1140 "MASTER",
1141 "SERVICE",
1142 "ADMIN",
1143 "DEPLOY",
1144 "WEBHOOK",
1145 "SSH",
1146 "GPG",
1147 "PGP",
1148 "ROOT",
1149 "SHARED",
1150 "SERVER",
1151 "SUBSCRIPTION",
1152 "ROLE",
1153 "APP",
1154 "APPLICATION",
1155 "ACCOUNT",
1156 "INGEST",
1157 "WRITE",
1158 "MANAGEMENT"
1159]);
1160var NOT_CREDENTIAL_WORDS = new Set([
1161 "PUBLIC",
1162 "PUBLISHABLE",
1163 "STORAGE",
1164 "CACHE",
1165 "COOKIE",
1166 "HEADER",
1167 "PARAM",
1168 "FIELD",
1169 "PREFIX",
1170 "NAME",
1171 "LABEL",
1172 "I18N",
1173 "EVENT",
1174 "ROUTE",
1175 "PATH",
1176 "FILE",
1177 "DIR",
1178 "TYPE",
1179 "LENGTH",
1180 "TTL",
1181 "EXPIRY",
1182 "EXPIRES",
1183 "TIMEOUT",
1184 "MAX",
1185 "MIN",
1186 "LIMIT",
1187 "COUNT",
1188 "SIZE",
1189 "VERSION",
1190 "VERSIONS",
1191 "ENABLED",
1192 "DISABLED",
1193 "MODE",
1194 "PENDING",
1195 "DISMISSED",
1196 "STATS",
1197 "QUERY",
1198 "ID"
1199]);
1200var CONNECTION_WORDS = new Set(["DATABASE", "DB", "POSTGRES", "POSTGRESQL", "PG", "MYSQL", "MARIADB", "MONGO", "MONGODB", "REDIS", "VALKEY", "AMQP", "RABBITMQ", "CLOUDINARY"]);types/index.d.ts 15 lines1// DKOD Guard's band values (packages/dkoder-plugin/src/claude-band.ts), held by the host for the session.
2export type GuardPulse = { decision: 'allowed' | 'blocked' | 'declined'; text: string; at: number }
3
4declare module 'claude-code' {
5 interface PluginState {
6 'dkod': {
7 auth: 'checking' | 'ok' | 'signin' | 'offline' | 'device'
8 frame: number
9 pulse: GuardPulse | null
10 pulseFrame: number
11 status: string
12 }
13 }
14}
15