@dsmm/dsmm 0.3.9 → 0.3.11

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.
Files changed (126) hide show
  1. package/README.md +9 -5
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +6 -10
  3. package/agent-presets/dsmm-clarifier/agent.cordis.yml +10 -14
  4. package/agent-presets/dsmm-code-search/agent.cordis.yml +10 -14
  5. package/agent-presets/dsmm-coding/agent.cordis.yml +10 -14
  6. package/agent-presets/dsmm-complex/agent.cordis.yml +10 -14
  7. package/agent-presets/dsmm-creative/agent.cordis.yml +10 -14
  8. package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +10 -14
  9. package/agent-presets/dsmm-deep/agent.cordis.yml +10 -14
  10. package/agent-presets/dsmm-doc-search/agent.cordis.yml +10 -14
  11. package/agent-presets/dsmm-documenting/agent.cordis.yml +10 -14
  12. package/agent-presets/dsmm-frontend/agent.cordis.yml +10 -14
  13. package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +10 -14
  14. package/agent-presets/dsmm-media-reader/agent.cordis.yml +10 -14
  15. package/agent-presets/dsmm-normal-task/agent.cordis.yml +10 -14
  16. package/agent-presets/dsmm-oracle/agent.cordis.yml +10 -14
  17. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +10 -14
  18. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +8 -12
  19. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +10 -14
  20. package/agent-presets/dsmm-planner/agent.cordis.yml +10 -14
  21. package/agent-presets/dsmm-quick/agent.cordis.yml +10 -14
  22. package/agent-presets/dsmm-research/agent.cordis.yml +10 -14
  23. package/agent-presets/dsmm-reviewer/agent.cordis.yml +10 -14
  24. package/docs/agent-presets.md +3 -3
  25. package/docs/compatibility.md +2 -2
  26. package/docs/deferred-native-approval-risk.md +11 -1
  27. package/docs/design.md +1 -1
  28. package/docs/lsp.md +6 -2
  29. package/docs/maintenance.md +65 -0
  30. package/docs/model-routing.md +1 -1
  31. package/docs/native-permissions.md +23 -1
  32. package/docs/profiles.md +1 -1
  33. package/docs/releasing.md +51 -32
  34. package/docs/roadmap.md +3 -3
  35. package/docs/runtime-recovery.md +1 -1
  36. package/docs/safety-guards.md +23 -5
  37. package/docs/settings-status.md +1 -1
  38. package/lib/child-capture.js +5 -1
  39. package/lib/client/deployment-locales.js +1 -0
  40. package/lib/client/permission-locales.js +8 -8
  41. package/lib/client.js +18 -17
  42. package/lib/command-approval.d.ts +50 -0
  43. package/lib/command-approval.js +148 -0
  44. package/lib/core-permissions.d.ts +2 -1
  45. package/lib/core-permissions.js +6 -3
  46. package/lib/guards.d.ts +2 -1
  47. package/lib/guards.js +45 -8
  48. package/lib/index.d.ts +1 -1
  49. package/lib/index.js +4 -2
  50. package/lib/lsp.js +1 -1
  51. package/lib/permission-control.d.ts +5 -2
  52. package/lib/permission-control.js +46 -24
  53. package/lib/permission-controller.d.ts +2 -0
  54. package/lib/permission-controller.js +13 -8
  55. package/lib/permission-native-command.d.ts +2 -0
  56. package/lib/permission-native-command.js +9 -4
  57. package/lib/permission-native-rules.d.ts +2 -2
  58. package/lib/permission-native-rules.js +18 -13
  59. package/lib/permission-shell.d.ts +1 -1
  60. package/lib/permission-shell.js +2 -2
  61. package/lib/profile-diagnostics.js +1 -1
  62. package/lib/profiles.js +2 -1
  63. package/lib/prompt-content.js +2 -2
  64. package/lib/roles.js +2 -2
  65. package/lib/settings.d.ts +2 -0
  66. package/lib/settings.js +10 -0
  67. package/lib/shell-command.d.ts +16 -0
  68. package/lib/shell-command.js +443 -119
  69. package/package.json +38 -38
  70. package/patches/ocmm-lsp-mcp.example.cordis.patch.yml +1 -1
  71. package/prompts/deepwork.md +2 -2
  72. package/prompts/source/shared/dsh-host-contract.md +2 -2
  73. package/prompts/source/shared/locale.md +2 -2
  74. package/prompts/source/terminal/builder.md +2 -2
  75. package/prompts/source/terminal/clarifier.md +6 -6
  76. package/prompts/source/terminal/code-search.md +6 -6
  77. package/prompts/source/terminal/coding.md +6 -6
  78. package/prompts/source/terminal/complex.md +6 -6
  79. package/prompts/source/terminal/creative.md +6 -6
  80. package/prompts/source/terminal/cross-cutting.md +6 -6
  81. package/prompts/source/terminal/deep.md +6 -6
  82. package/prompts/source/terminal/doc-search.md +6 -6
  83. package/prompts/source/terminal/documenting.md +6 -6
  84. package/prompts/source/terminal/frontend.md +6 -6
  85. package/prompts/source/terminal/hard-reasoning.md +6 -6
  86. package/prompts/source/terminal/media-reader.md +6 -6
  87. package/prompts/source/terminal/normal-task.md +6 -6
  88. package/prompts/source/terminal/oracle-2nd.md +6 -6
  89. package/prompts/source/terminal/oracle.md +6 -6
  90. package/prompts/source/terminal/orchestrator.md +4 -4
  91. package/prompts/source/terminal/plan-critic.md +6 -6
  92. package/prompts/source/terminal/planner.md +6 -6
  93. package/prompts/source/terminal/quick.md +6 -6
  94. package/prompts/source/terminal/research.md +6 -6
  95. package/prompts/source/terminal/reviewer.md +6 -6
  96. package/skills/ast-grep/SKILL.md +3 -3
  97. package/skills/ast-grep/SOURCE +1 -1
  98. package/skills/ast-grep/install.ps1 +1 -1
  99. package/skills/ast-grep/install.sh +1 -1
  100. package/skills/ast-grep/scripts/ast_grep_helper.py +10 -10
  101. package/skills/ast-grep/tests/smoke.sh +11 -11
  102. package/skills/ast-grep/tests/test_resolver.py +4 -23
  103. package/skills/brainstorming/SKILL.md +3 -3
  104. package/skills/coding-agent-sessions/NOTICE.md +2 -2
  105. package/skills/coding-agent-sessions/SKILL.md +3 -3
  106. package/skills/debugging/SKILL.md +3 -3
  107. package/skills/debugging/references/methodology/03-flaky-triage.md +1 -1
  108. package/skills/debugging/references/scripts/dap.mjs +3 -3
  109. package/skills/debugging/references/tools/playwright-cli.md +3 -3
  110. package/skills/dispatching-parallel-agents/SKILL.md +3 -3
  111. package/skills/frontend/ATTRIBUTION.md +4 -4
  112. package/skills/frontend/SKILL.md +3 -3
  113. package/skills/frontend/references/perfection/README.md +4 -4
  114. package/skills/frontend/references/perfection/react-perf-tooling.md +4 -4
  115. package/skills/git-master/SKILL.md +3 -3
  116. package/skills/git-master/agents/openai.yaml +1 -1
  117. package/skills/init-deep/SKILL.md +3 -3
  118. package/skills/receiving-code-review/SKILL.md +3 -3
  119. package/skills/remove-ai-slops/SKILL.md +3 -3
  120. package/skills/requesting-code-review/SKILL.md +3 -3
  121. package/skills/subagent-driven-development/SKILL.md +3 -3
  122. package/skills/using-git-worktrees/SKILL.md +4 -4
  123. package/skills/writing-plans/SKILL.md +3 -3
  124. package/docs/migration-from-ocmm.md +0 -57
  125. package/docs/skill-sync.md +0 -94
  126. package/prompts/source/manifest.json +0 -3168
@@ -36,27 +36,6 @@ const GIT_GLOBAL_OPTIONS_WITH_VALUE = new Set([
36
36
  "--super-prefix",
37
37
  "--work-tree"
38
38
  ]);
39
- const CONFIG_WRITE_OPTIONS = new Set([
40
- "--add",
41
- "--replace-all",
42
- "--unset",
43
- "--unset-all",
44
- "--rename-section",
45
- "--remove-section",
46
- "--edit"
47
- ]);
48
- const CONFIG_QUERY_OPTIONS = new Set([
49
- "--get",
50
- "--get-all",
51
- "--get-regexp",
52
- "--get-urlmatch",
53
- "--list",
54
- "-l",
55
- "--show-origin",
56
- "--show-scope",
57
- "--name-only"
58
- ]);
59
- const CONFIG_OPTIONS_WITH_VALUE = new Set(["--file", "-f", "--blob", "--type", "--default", "--comment"]);
60
39
  const ENV_OPTIONS_WITH_VALUE = new Set(["-u", "--unset", "-C", "--chdir", "-a", "--argv0", "-f", "--file", "-S", "--split-string"]);
61
40
  const ENV_SHORT_OPTIONS_WITH_ATTACHED_VALUE = new Set(["-C", "-u", "-a", "-f", "-S"]);
62
41
  const ENV_LONG_OPTIONS_WITH_ATTACHED_VALUE = new Set(["--unset", "--chdir", "--argv0", "--file", "--split-string", "--default-signal", "--ignore-signal", "--block-signal"]);
@@ -169,7 +148,11 @@ export function parseShellCommand(input, dialect) {
169
148
  continue;
170
149
  }
171
150
  if (state === "single-quoted") {
172
- if (char === "'")
151
+ if (char === "'" && dialect === "powershell" && input[index + 1] === "'") {
152
+ appendWord("'");
153
+ index += 1;
154
+ }
155
+ else if (char === "'")
173
156
  state = "unquoted";
174
157
  else
175
158
  appendWord(char);
@@ -328,142 +311,483 @@ function skipEnv(words, start) {
328
311
  }
329
312
  return undefined;
330
313
  }
331
- function gitSubcommand(words, start) {
332
- let index = start + 1;
333
- while (index < words.length) {
314
+ function gitSubcommand(words) {
315
+ let known = true;
316
+ for (let index = 1; index < words.length; index += 1) {
334
317
  const option = words[index] ?? "";
318
+ if (["--help", "-h", "--version", "-v", "--html-path", "--man-path", "--info-path", "--exec-path"].includes(option))
319
+ return undefined;
335
320
  if (option === "--") {
336
- index += 1;
321
+ known = false;
337
322
  continue;
338
323
  }
339
324
  if (GIT_GLOBAL_OPTIONS_WITH_VALUE.has(option)) {
340
325
  if (index + 1 >= words.length)
341
326
  return undefined;
342
- index += 2;
327
+ if (option === "--config-env")
328
+ known = false;
329
+ index += 1;
343
330
  continue;
344
331
  }
345
332
  if (/^-[Cc].+/u.test(option) || [...GIT_GLOBAL_OPTIONS_WITH_VALUE].some((name) => option.startsWith(`${name}=`))) {
346
- index += 1;
333
+ if (option.startsWith("--config-env="))
334
+ known = false;
347
335
  continue;
348
336
  }
349
337
  if (option.startsWith("-")) {
350
- index += 1;
338
+ if (!["-p", "--paginate", "-P", "--no-pager", "--bare", "--no-replace-objects", "--literal-pathspecs", "--glob-pathspecs", "--noglob-pathspecs", "--icase-pathspecs", "--no-optional-locks", "--no-lazy-fetch", "--no-advice"].includes(option))
339
+ known = false;
351
340
  continue;
352
341
  }
353
- return { name: lower(option), args: words.slice(index + 1) };
342
+ return { name: option, args: words.slice(index + 1), globalOptions: words.slice(1, index), known };
354
343
  }
355
344
  return undefined;
356
345
  }
357
- function configWrites(args) {
358
- const options = args.map(lower);
359
- if (options.some((option) => CONFIG_WRITE_OPTIONS.has(option) || [...CONFIG_WRITE_OPTIONS].some((name) => option.startsWith(`${name}=`))))
360
- return true;
361
- if (options.some((option) => CONFIG_QUERY_OPTIONS.has(option)))
362
- return false;
363
- const positional = [];
346
+ /** Git options are case-sensitive; only declared value-taking options consume operands. */
347
+ function gitOptions(args, syntax) {
348
+ const flags = new Set((`${syntax.flags ?? ""} -h --help`).split(/\s+/u));
349
+ const values = new Set((syntax.values ?? "").split(/\s+/u));
350
+ const optional = new Set((syntax.optional ?? "").split(/\s+/u));
351
+ const lastValue = new Set((syntax.lastValue ?? "").split(/\s+/u));
352
+ const result = { flags: new Set(), values: new Map(), positional: [], boundary: undefined, known: true };
353
+ const aliases = { "-f": "--force", "-d": "--delete", "-W": "--worktree", "-S": "--staged" };
354
+ if (syntax.dryRunShort)
355
+ aliases["-n"] = "--dry-run";
356
+ const save = (name, value) => {
357
+ const positive = name.startsWith("--no-") ? `--${name.slice(5)}` : aliases[name] ?? name;
358
+ if (syntax.flagAliases?.includes(positive)) {
359
+ for (const alias of syntax.flagAliases) {
360
+ result.flags.delete(alias);
361
+ if (alias.startsWith("--"))
362
+ result.flags.delete(`--no-${alias.slice(2)}`);
363
+ }
364
+ }
365
+ if (name.startsWith("--no-") && (flags.has(positive) || optional.has(positive))) {
366
+ result.flags.delete(positive);
367
+ for (const [short, long] of Object.entries(aliases))
368
+ if (long === positive)
369
+ result.flags.delete(short);
370
+ }
371
+ else if (name.startsWith("--") || flags.has(positive))
372
+ result.flags.delete(`--no-${positive.slice(2)}`);
373
+ result.flags.add(name);
374
+ if (value !== undefined)
375
+ result.values.set(name, [...(result.values.get(name) ?? []), value]);
376
+ };
364
377
  for (let index = 0; index < args.length; index += 1) {
365
- const argument = args[index] ?? "";
366
- const option = lower(argument);
367
- if (argument === "--") {
368
- positional.push(...args.slice(index + 1));
378
+ const word = args[index] ?? "";
379
+ if (word === "--") {
380
+ result.boundary = result.positional.length;
381
+ result.positional.push(...args.slice(index + 1));
369
382
  break;
370
383
  }
371
- if (CONFIG_OPTIONS_WITH_VALUE.has(option)) {
372
- index += 1;
384
+ if (!word.startsWith("-") || word === "-") {
385
+ result.positional.push(word);
373
386
  continue;
374
387
  }
375
- if ([...CONFIG_OPTIONS_WITH_VALUE].some((name) => option.startsWith(`${name}=`)))
376
- continue;
377
- if (argument.startsWith("-"))
388
+ if (word.startsWith("--")) {
389
+ const equals = word.indexOf("=");
390
+ const name = equals < 0 ? word : word.slice(0, equals);
391
+ if (values.has(name) || lastValue.has(name)) {
392
+ const value = equals < 0 ? args[++index] : word.slice(equals + 1);
393
+ if (value === undefined && !lastValue.has(name))
394
+ result.known = false;
395
+ save(name, value);
396
+ }
397
+ else if (optional.has(name))
398
+ save(name, equals < 0 ? undefined : word.slice(equals + 1));
399
+ else if (equals < 0 && (flags.has(name) || name.startsWith("--no-") && (flags.has(`--${name.slice(5)}`) || optional.has(`--${name.slice(5)}`))))
400
+ save(name);
401
+ else
402
+ result.known = false;
378
403
  continue;
379
- positional.push(argument);
404
+ }
405
+ for (let offset = 1; offset < word.length; offset += 1) {
406
+ const name = `-${word[offset] ?? ""}`;
407
+ if (values.has(name) || optional.has(name)) {
408
+ const attached = word.slice(offset + 1);
409
+ const value = attached || (values.has(name) ? args[++index] : undefined);
410
+ if (values.has(name) && value === undefined)
411
+ result.known = false;
412
+ save(name, value);
413
+ break;
414
+ }
415
+ if (flags.has(name))
416
+ save(name);
417
+ else {
418
+ result.known = false;
419
+ break;
420
+ }
421
+ }
380
422
  }
381
- return positional.length >= 2;
423
+ return result;
382
424
  }
383
- function firstAction(args, optionsWithValue) {
384
- for (let index = 0; index < args.length; index += 1) {
385
- const argument = args[index] ?? "";
386
- if (argument === "--")
387
- return args[index + 1];
388
- if (optionsWithValue.includes(lower(argument))) {
389
- index += 1;
390
- continue;
425
+ const LIST_SYNTAX = {
426
+ flags: "--list -l -a --all -r --remotes -v --verbose -q --quiet --ignore-case -i --no-column --no-contains --no-merged",
427
+ values: "--format --sort --points-at",
428
+ optional: "--column --color --abbrev",
429
+ lastValue: "--contains --no-contains --merged --no-merged"
430
+ };
431
+ const MESSAGE_VALUES = "-m --message -F --file -C --reuse-message -c --reedit-message --author --date --cleanup --trailer --template -t --pathspec-from-file";
432
+ const COMMIT_SYNTAX = {
433
+ flags: "-a --all -p --patch -s --signoff -n --no-verify -q --quiet -v --verbose -e --edit --no-edit --amend --reset-author --allow-empty --allow-empty-message --no-post-rewrite -i --include -o --only --dry-run --short --porcelain --long -z --null --branch --no-status --status --no-gpg-sign --pathspec-file-nul",
434
+ values: `${MESSAGE_VALUES} --fixup --squash`, optional: "-S --gpg-sign --untracked-files -u"
435
+ };
436
+ function gitActions(name, args) {
437
+ let parsed;
438
+ const result = [];
439
+ const emit = (action, high = false) => { result.push({ action: `${name}.${action}`, risk: high ? "high-risk" : "write", known: parsed.known }); };
440
+ const has = (...options) => options.some((option) => parsed.flags.has(option));
441
+ const unknown = () => [{ action: `${name}.unknown`, risk: "write", known: false }];
442
+ const query = () => parsed.known ? [] : unknown();
443
+ const help = () => has("-h", "--help");
444
+ const dryRun = () => has("-n", "--dry-run");
445
+ if (name === "branch") {
446
+ parsed = gitOptions(args, {
447
+ flags: `${LIST_SYNTAX.flags} -d --delete -D -m --move -M -c --copy -C -f --force --show-current --edit-description --unset-upstream --create-reflog --no-track -t`,
448
+ values: `${LIST_SYNTAX.values} -u --set-upstream-to`, optional: `${LIST_SYNTAX.optional} --track`, lastValue: LIST_SYNTAX.lastValue
449
+ });
450
+ if (help())
451
+ return [];
452
+ const force = has("-f", "--force");
453
+ if (has("-D", "-d", "--delete"))
454
+ emit(has("-D") || force ? "force-delete" : "delete", true);
455
+ else if (has("-C", "-c", "--copy"))
456
+ emit(has("-C") || force ? "force-copy" : "copy", has("-C") || force);
457
+ else if (has("-M", "-m", "--move"))
458
+ emit(has("-M") || force ? "force-rename" : "rename", has("-M") || force);
459
+ else if (has("-u", "--set-upstream-to", "--unset-upstream"))
460
+ emit(has("--unset-upstream") ? "unset-upstream" : "set-upstream");
461
+ else if (has("--edit-description"))
462
+ emit("edit-description");
463
+ else if (force && parsed.positional.length > 0)
464
+ emit("force-update", true);
465
+ else if (has("--show-current", "--list", "-l", "-a", "--all", "-r", "--remotes", "--contains", "--no-contains", "--merged", "--no-merged", "--points-at") || parsed.positional.length === 0)
466
+ return query();
467
+ else
468
+ emit("create");
469
+ return result;
470
+ }
471
+ if (name === "tag") {
472
+ parsed = gitOptions(args, { flags: `${LIST_SYNTAX.flags} -d --delete -f --force -a --annotate -s --sign -v --verify --create-reflog --no-sign`, values: "--format --sort --points-at -m --message -F --file -u --local-user", optional: `${LIST_SYNTAX.optional} -n`, lastValue: LIST_SYNTAX.lastValue });
473
+ if (help())
474
+ return [];
475
+ if (has("-d", "--delete"))
476
+ emit("delete", true);
477
+ else if (has("-f", "--force") && parsed.positional.length > 0)
478
+ emit("force-update", true);
479
+ else if (has("-m", "--message", "-F", "--file", "-a", "--annotate", "-s", "--sign", "-u", "--local-user"))
480
+ emit("create");
481
+ else if (has("--list", "-l", "-v", "--verify", "--contains", "--no-contains", "--merged", "--no-merged", "--points-at", "-n") || parsed.positional.length === 0)
482
+ return query();
483
+ else
484
+ emit("create");
485
+ return result;
486
+ }
487
+ if (name === "remote") {
488
+ parsed = gitOptions(args, { flags: "-v --verbose -f --fetch --tags --no-tags -a --auto -d --delete --add --push --all -n --dry-run -p --prune", values: "-t --track -m --master", optional: "--mirror", dryRunShort: true });
489
+ if (help())
490
+ return [];
491
+ const action = parsed.positional[0];
492
+ if (action === undefined || ["show", "get-url"].includes(action))
493
+ return query();
494
+ if (!["add", "rename", "remove", "rm", "set-head", "set-branches", "set-url", "update", "prune"].includes(action))
495
+ return unknown();
496
+ if (action === "prune" && dryRun())
497
+ return [];
498
+ emit(action === "rm" ? "remove" : action);
499
+ return result;
500
+ }
501
+ if (name === "stash") {
502
+ parsed = gitOptions(args, { flags: "-p --patch -S --staged -k --keep-index --no-keep-index -u --include-untracked -a --all -q --quiet --index --pathspec-file-nul --only-untracked --stat --numstat --shortstat --name-only --name-status --summary --oneline -f --force", values: "-m --message --pathspec-from-file --format -n --max-count --skip --since --until --grep --author -U --unified", optional: "--pretty" });
503
+ if (help())
504
+ return [];
505
+ const first = parsed.positional[0];
506
+ if (first === "list" || first === "show")
507
+ return query();
508
+ const action = first === undefined || parsed.boundary === 0 ? "push" : first;
509
+ if (!["push", "save", "apply", "pop", "branch", "create", "store", "drop", "clear"].includes(action))
510
+ return unknown();
511
+ emit(action, action === "drop" || action === "clear");
512
+ return result;
513
+ }
514
+ if (name === "worktree") {
515
+ parsed = gitOptions(args, { flags: "-f --force -d --detach --checkout --no-checkout --lock --porcelain -z -v --verbose -n --dry-run --orphan --relative-paths --no-relative-paths --guess-remote --no-guess-remote --quiet -q", values: "-b -B --reason --expire", dryRunShort: true });
516
+ if (help())
517
+ return [];
518
+ const action = parsed.positional[0];
519
+ if (action === "list")
520
+ return query();
521
+ if (action === "prune" && dryRun())
522
+ return [];
523
+ if (action === undefined || !["add", "move", "lock", "unlock", "repair", "remove", "prune"].includes(action))
524
+ return unknown();
525
+ emit(action, action === "remove" || action === "prune");
526
+ return result;
527
+ }
528
+ if (name === "submodule") {
529
+ parsed = gitOptions(args, { flags: "-q --quiet --cached --files --recursive --force -f --init --remote -N --no-fetch --checkout --merge --rebase --recommend-shallow --no-recommend-shallow --single-branch --no-single-branch --progress --all --default", values: "-b --branch --name --reference --depth -j --jobs --filter --ref-format --super-prefix --separate-git-dir -n --summary-limit", optional: "--recurse-submodules" });
530
+ if (help())
531
+ return [];
532
+ const action = parsed.positional[0];
533
+ if (action === undefined || ["status", "summary"].includes(action))
534
+ return query();
535
+ if (!["add", "init", "deinit", "update", "sync", "set-branch", "set-url", "foreach"].includes(action))
536
+ return unknown();
537
+ if (action === "foreach")
538
+ parsed.known = false;
539
+ emit(action);
540
+ return result;
541
+ }
542
+ if (name === "commit") {
543
+ parsed = gitOptions(args, COMMIT_SYNTAX);
544
+ if (help() || has("--dry-run", "--short", "--porcelain", "--long"))
545
+ return [];
546
+ emit(has("--amend") ? "amend" : "create", has("--amend"));
547
+ return result;
548
+ }
549
+ if (name === "push") {
550
+ parsed = gitOptions(args, { flags: "-f --force --force-if-includes -d --delete --mirror -n --dry-run --all --branches --tags --follow-tags --prune --atomic --porcelain --quiet -q --verbose -v --progress --no-verify --set-upstream -u --no-force --no-force-with-lease --no-force-if-includes --no-signed --ipv4 -4 --ipv6 -6", values: "--repo --receive-pack --exec -o --push-option", optional: "--force-with-lease --signed --recurse-submodules", dryRunShort: true });
551
+ if (help() || dryRun())
552
+ return [];
553
+ const refspecs = parsed.positional.slice(has("--repo") ? 0 : 1);
554
+ if (has("-f", "--force") || refspecs.some((ref) => ref.startsWith("+")))
555
+ emit("force", true);
556
+ if (has("--force-with-lease"))
557
+ emit("force-with-lease", true);
558
+ if (has("--force-if-includes"))
559
+ emit("force-if-includes", true);
560
+ if (has("-d", "--delete") || refspecs.some((ref) => /^\+?:.+/u.test(ref)))
561
+ emit("delete", true);
562
+ if (has("--mirror"))
563
+ emit("mirror", true);
564
+ if (result.length === 0)
565
+ emit("update");
566
+ if (has("--receive-pack", "--exec"))
567
+ return result.map((action) => ({ ...action, known: false }));
568
+ return result;
569
+ }
570
+ if (name === "reset") {
571
+ parsed = gitOptions(args, { flags: "--hard --soft --mixed --merge --keep -q --quiet -p --patch -N --intent-to-add --no-refresh --refresh --pathspec-file-nul", values: "--pathspec-from-file --inter-hunk-context --unified -U" });
572
+ if (help())
573
+ return [];
574
+ emit(has("--hard") ? "hard" : "update", has("--hard"));
575
+ return result;
576
+ }
577
+ if (name === "clean") {
578
+ parsed = gitOptions(args, { flags: "-f --force -d -x -X -i --interactive -n --dry-run -q --quiet", values: "-e --exclude", dryRunShort: true });
579
+ if (help() || dryRun())
580
+ return [];
581
+ emit("remove", true);
582
+ return result;
583
+ }
584
+ if (name === "rebase") {
585
+ parsed = gitOptions(args, { flags: "--continue --skip --abort --quit --edit-todo --show-current-patch --apply --merge -m --interactive -i --keep-empty --no-keep-empty --reapply-cherry-picks --no-reapply-cherry-picks --fork-point --no-fork-point --root --update-refs --no-update-refs --autosquash --no-autosquash --autostash --no-autostash --signoff --no-verify --verify --no-gpg-sign --force-rebase -f --no-ff --no-stat --stat -n --quiet -q --verbose -v --reschedule-failed-exec --no-reschedule-failed-exec --reset-author-date --committer-date-is-author-date --ignore-date --keep-base", values: "--onto --exec -x --strategy -s --strategy-option -X --whitespace --empty", optional: "--rebase-merges -r --gpg-sign -S" });
586
+ if (help() || has("--show-current-patch"))
587
+ return [];
588
+ const action = ["continue", "skip", "abort", "quit", "edit-todo"].find((value) => has(`--${value}`)) ?? "start";
589
+ emit(action, true);
590
+ if (has("--exec", "-x"))
591
+ return result.map((item) => ({ ...item, known: false }));
592
+ return result;
593
+ }
594
+ if (name === "checkout" || name === "switch" || name === "restore") {
595
+ const common = "-m --merge -q --quiet --progress --no-progress --recurse-submodules --no-recurse-submodules";
596
+ const syntax = name === "restore"
597
+ ? { flags: `${common} -p --patch --ignore-skip-worktree-bits --ours --theirs -2 -3 --overlay --no-overlay --pathspec-file-nul -S --staged -W --worktree --ignore-unmerged`, values: "--source -s --conflict --pathspec-from-file -U --unified --inter-hunk-context", optional: "--recurse-submodules" }
598
+ : name === "checkout"
599
+ ? { flags: `${common} -f --force --detach -d --guess --no-guess -t --no-track -p --patch --ignore-skip-worktree-bits --ignore-other-worktrees --overwrite-ignore --no-overwrite-ignore --ours --theirs -2 -3 --overlay --no-overlay --pathspec-file-nul -l`, values: "-b -B --conflict --pathspec-from-file --orphan", optional: "--recurse-submodules --track" }
600
+ : { flags: `${common} -f --force --discard-changes --detach -d --guess --no-guess -t --no-track --ignore-other-worktrees --overwrite-ignore --no-overwrite-ignore`, values: "-c -C --create --force-create --conflict --orphan", optional: "--recurse-submodules --track", flagAliases: ["-f", "--force", "--discard-changes"] };
601
+ parsed = gitOptions(args, syntax);
602
+ if (help())
603
+ return [];
604
+ if (name === "restore") {
605
+ const worktree = has("-W", "--worktree") || !has("-S", "--staged");
606
+ emit(worktree ? "worktree" : "staged", worktree);
607
+ }
608
+ else {
609
+ const paths = parsed.boundary === undefined ? parsed.positional.length > 1 : parsed.positional.length > parsed.boundary;
610
+ const discard = has("-f", "--force", "--discard-changes", name === "checkout" ? "-B" : "-C", "--force-create") || (name === "checkout" && (paths || has("--pathspec-from-file", "-p", "--patch", "--ours", "--theirs", "-2", "-3")));
611
+ emit(discard ? "discard" : has("-b", "-c", "--create", "--orphan") ? "create" : "switch", discard);
612
+ // A lone checkout operand can be a branch or a path; no repository lookup is made.
613
+ if (name === "checkout" && !discard && !has("-b", "--orphan", "--detach", "-t", "--track")) {
614
+ if (parsed.boundary === undefined)
615
+ return unknown();
616
+ result[0].known = false;
617
+ }
391
618
  }
392
- if (argument.startsWith("-"))
393
- continue;
394
- return argument;
619
+ return result;
395
620
  }
396
- return undefined;
397
- }
398
- function replaceWrites(args) {
399
- const options = args.map(lower);
400
- if (options.some((option) => option === "-d" || option === "--delete" || option === "-e" || option === "--edit" || option === "-g" || option === "--graft"))
401
- return true;
402
- if (options.some((option) => option === "-l" || option === "--list"))
403
- return false;
404
- return args.filter((argument) => !argument.startsWith("-")).length >= 2;
405
- }
406
- function symbolicRefWrites(args) {
407
- const options = args.map(lower);
408
- if (options.some((option) => option === "-d" || option === "--delete"))
409
- return true;
410
- return args.filter((argument) => !argument.startsWith("-")).length >= 2;
621
+ if (name === "config") {
622
+ parsed = gitOptions(args, { flags: "--add --replace-all --unset --unset-all --rename-section --remove-section --edit -e --get --get-all --get-regexp --get-urlmatch --list -l --global --system --local --worktree --null -z --name-only --show-origin --show-scope --includes --no-includes --bool --int --bool-or-int --bool-or-str --path --expiry-date --fixed-value --append --all", values: "--file -f --blob --type --default --comment --value --url" });
623
+ if (help())
624
+ return [];
625
+ const action = ["add", "replace-all", "unset", "unset-all", "rename-section", "remove-section", "edit"].find((value) => has(`--${value}`)) ?? (has("-e") ? "edit" : undefined);
626
+ if (action !== undefined)
627
+ emit(action);
628
+ else if (["set", "unset", "rename-section", "remove-section", "edit"].includes(parsed.positional[0] ?? ""))
629
+ emit(has("--append") ? "add" : parsed.positional[0] === "unset" && has("--all") ? "unset-all" : parsed.positional[0] ?? "set");
630
+ else if (has("--get", "--get-all", "--get-regexp", "--get-urlmatch", "--list", "-l") || ["get", "list"].includes(parsed.positional[0] ?? "") || parsed.positional.length < 2)
631
+ return query();
632
+ else
633
+ emit("set");
634
+ // Non-default config stores/scopes are protected, but not generalized to other targets.
635
+ if (has("--file", "-f", "--blob", "--global", "--system", "--worktree"))
636
+ return result.map((item) => ({ ...item, known: false }));
637
+ return result;
638
+ }
639
+ if (name === "notes") {
640
+ parsed = gitOptions(args, { flags: "-f --force --allow-empty --stdin -n --dry-run -v --verbose --ignore-missing --abort --commit", values: "--ref -r -m --message -F --file -c --reedit-message -C --reuse-message -s --strategy --separator", optional: "--stripspace", dryRunShort: true });
641
+ if (help())
642
+ return [];
643
+ const action = parsed.positional[0];
644
+ if (action === undefined || ["list", "show", "get-ref"].includes(action))
645
+ return query();
646
+ if (!["add", "append", "copy", "edit", "merge", "prune", "remove"].includes(action))
647
+ return unknown();
648
+ if (action === "prune" && dryRun())
649
+ return [];
650
+ emit(action === "merge" && has("--abort", "--commit") ? `merge-${has("--abort") ? "abort" : "commit"}` : action);
651
+ return result;
652
+ }
653
+ if (name === "replace") {
654
+ parsed = gitOptions(args, { flags: "-f --force -d --delete -e --edit -g --graft -l --list --convert-graft-file --raw", values: "--format" });
655
+ if (help())
656
+ return [];
657
+ if (has("-d", "--delete", "-e", "--edit", "-g", "--graft", "--convert-graft-file"))
658
+ emit(has("-d", "--delete") ? "delete" : has("-e", "--edit") ? "edit" : has("--convert-graft-file") ? "convert-graft-file" : "graft", true);
659
+ else if (has("-l", "--list") || parsed.positional.length < 2)
660
+ return query();
661
+ else
662
+ emit("create", true);
663
+ return result;
664
+ }
665
+ if (name === "symbolic-ref" || name === "update-ref") {
666
+ parsed = gitOptions(args, { flags: "-d --delete -q --quiet --short --no-recurse --recurse --stdin -z --no-deref --create-reflog --batch-updates", values: "-m" });
667
+ if (help())
668
+ return [];
669
+ if (name === "symbolic-ref" && !has("-d", "--delete") && parsed.positional.length < 2)
670
+ return query();
671
+ emit(has("-d", "--delete") ? "delete" : has("--stdin") ? "transaction" : "write", true);
672
+ if (has("--stdin"))
673
+ result[0].known = false;
674
+ return result;
675
+ }
676
+ if (name === "reflog") {
677
+ parsed = gitOptions(args, { flags: "--all --single-worktree --updateref --rewrite --stale-fix -n --dry-run --verbose", values: "--expire --expire-unreachable", dryRunShort: true });
678
+ if (help())
679
+ return [];
680
+ const action = parsed.positional[0];
681
+ if (action === undefined || ["show", "list", "exists"].includes(action))
682
+ return query();
683
+ if (!["delete", "expire", "drop", "write"].includes(action))
684
+ return unknown();
685
+ if (["delete", "expire"].includes(action) && dryRun())
686
+ return [];
687
+ emit(action, action !== "write");
688
+ return result;
689
+ }
690
+ if (name === "filter-branch") {
691
+ parsed = gitOptions(args, { flags: "-f --force --prune-empty --remap-to-ancestor --state-branch", values: "--setup --subdirectory-filter --env-filter --tree-filter --index-filter --parent-filter --msg-filter --commit-filter --tag-name-filter --original -d --state-branch" });
692
+ if (help())
693
+ return [];
694
+ emit("rewrite", true);
695
+ return result.map((action) => ({ ...action, known: false }));
696
+ }
697
+ if (!GIT_WRITE_COMMANDS.has(name))
698
+ return [];
699
+ const syntax = {
700
+ add: { flags: "-n --dry-run -v --verbose -f --force -i --interactive -p --patch -e --edit -u --update -A --all --no-all --ignore-removal -N --intent-to-add --refresh --ignore-errors --ignore-missing --renormalize --sparse --pathspec-file-nul", values: "--chmod --pathspec-from-file", dryRunShort: true },
701
+ rm: { flags: "-f --force -n --dry-run -r --cached --ignore-unmatch --sparse -q --quiet --pathspec-file-nul", values: "--pathspec-from-file", dryRunShort: true },
702
+ mv: { flags: "-f --force -n --dry-run -k -v --verbose --sparse", dryRunShort: true },
703
+ apply: { flags: "--stat --numstat --summary --check --apply --index --cached --intent-to-add -3 --3way --reverse -R --reject --allow-overlap --inaccurate-eof --verbose -v --quiet -q --recount --allow-empty --unsafe-paths --ignore-space-change --ignore-whitespace", values: "--directory --include --exclude --whitespace -p -C --build-fake-ancestor" },
704
+ fetch: { flags: "--all --append -a --atomic --force -f --multiple --prune -p --prune-tags -P --no-tags -n --tags -t --dry-run --quiet -q --verbose -v --update-head-ok -u --keep -k --unshallow --update-shallow --refetch --no-write-fetch-head --write-fetch-head --no-recurse-submodules --ipv4 -4 --ipv6 -6", values: "--depth --deepen --shallow-since --shallow-exclude --upload-pack --server-option -o --jobs -j --negotiation-tip", optional: "--recurse-submodules --filter" },
705
+ merge: { flags: "--abort --continue --quit --commit --no-commit --edit -e --no-edit --ff --no-ff --ff-only --squash --no-squash --stat --no-stat -n --log --no-log --signoff --no-signoff --no-verify --verify --allow-unrelated-histories --autostash --no-autostash -q --quiet -v --verbose", values: "-m --message -F --file -s --strategy -X --strategy-option --into-name", optional: "-S --gpg-sign --log" },
706
+ init: { flags: "-q --quiet --bare", values: "--template --separate-git-dir --object-format --ref-format -b --initial-branch", optional: "--shared" },
707
+ clone: { flags: "--bare --mirror --local -l --no-local --no-hardlinks --shared -s --dissociate --quiet -q --verbose -v --progress --no-checkout -n --reject-shallow --no-reject-shallow --single-branch --no-single-branch --no-tags --shallow-submodules --no-shallow-submodules --remote-submodules --sparse --also-filter-submodules", values: "--template --reference --reference-if-able --origin -o --branch -b --revision --upload-pack -u --depth --shallow-since --shallow-exclude --separate-git-dir --config -c --filter --jobs -j --server-option --ref-format", optional: "--recurse-submodules --recursive" },
708
+ pull: { flags: "--ff --no-ff --ff-only --commit --no-commit --edit -e --no-edit --squash --no-squash --all --append -a --force -f --prune -p --tags -t --no-tags -n --dry-run --quiet -q --verbose -v --unshallow --update-shallow --autostash --no-autostash --no-rebase --allow-unrelated-histories --no-verify --signoff", values: "--depth --deepen --shallow-since --shallow-exclude --upload-pack --server-option --jobs -j -s --strategy -X --strategy-option", optional: "--rebase -r --recurse-submodules -S --gpg-sign" },
709
+ am: { flags: "--continue --skip --abort --quit --resolved -r --interactive -i --signoff -s --keep -k --keep-non-patch -b --keep-cr --no-keep-cr --3way -3 --no-3way --quiet -q --utf8 -u --no-utf8 --scissors --no-scissors --reject --ignore-space-change --ignore-whitespace --no-verify", values: "--patch-format --directory --include --exclude --whitespace -p -C --empty", optional: "--show-current-patch --gpg-sign -S" },
710
+ "cherry-pick": { flags: "--continue --skip --abort --quit --no-commit -n --edit -e --signoff -s --ff --allow-empty --allow-empty-message --keep-redundant-commits --rerere-autoupdate --no-rerere-autoupdate -x", values: "--mainline -m --strategy --strategy-option -X --empty", optional: "--gpg-sign -S" },
711
+ revert: { flags: "--continue --skip --abort --quit --no-commit -n --edit -e --no-edit --signoff -s --rerere-autoupdate --no-rerere-autoupdate", values: "--mainline -m --strategy --strategy-option -X", optional: "--gpg-sign -S" }
712
+ };
713
+ parsed = gitOptions(args, syntax[name] ?? {});
714
+ if (help())
715
+ return [];
716
+ if ((["add", "rm", "mv"].includes(name) && dryRun()) || (["fetch", "pull"].includes(name) && has("--dry-run")) || (name === "apply" && has("--check", "--stat", "--numstat", "--summary") && !has("--apply", "--build-fake-ancestor")) || (name === "am" && has("--show-current-patch")))
717
+ return [];
718
+ emit(["am", "merge", "cherry-pick", "revert"].includes(name) ? ["continue", "skip", "abort", "quit"].find((value) => has(`--${value}`)) ?? "start" : "write");
719
+ if (has("--upload-pack"))
720
+ return result.map((action) => ({ ...action, known: false }));
721
+ return result;
411
722
  }
412
- export function classifyKnownGitWrite(input, dialect) {
723
+ /** Pure, finite Git classification; this is not a shell AST or an authorization grant. */
724
+ export function evaluateGitCommand(input, dialect) {
725
+ const actions = [];
726
+ const seen = new Set();
727
+ // The tokenizer deliberately does not model expansion, control flow, or shell state.
728
+ let staticShell = !/[\$(){}*?\[\]]/u.test(input) && !(dialect === "posix" && input.includes("`")) && !(dialect === "powershell" && /@\w/u.test(input));
729
+ // POSIX tilde expansion and quote-dependent backslashes are not represented in context.
730
+ if (dialect === "posix" && /[~\\]/u.test(input))
731
+ staticShell = false;
413
732
  for (const segment of parseShellCommand(input, dialect)) {
414
733
  const start = commandStart(segment.words, dialect);
415
- if (start === undefined)
734
+ if (start === undefined) {
735
+ staticShell = false;
416
736
  continue;
737
+ }
417
738
  let commandWords = segment.words.slice(start);
418
- let executable = commandWords[0] ?? "";
419
- while (isNamedExecutable(executable, "env", dialect)) {
739
+ const environment = [...segment.words.slice(0, start)];
740
+ let wrapperKnown = true;
741
+ while (isNamedExecutable(commandWords[0] ?? "", "env", dialect)) {
420
742
  const unwrapped = skipEnv(commandWords, 0);
421
743
  if (unwrapped === undefined) {
422
- executable = "";
744
+ commandWords = [];
423
745
  break;
424
746
  }
425
- commandWords = unwrapped;
426
- executable = commandWords[0] ?? "";
427
- }
428
- if (!isNamedExecutable(executable, "git", dialect))
429
- continue;
430
- const subcommand = gitSubcommand(commandWords, 0);
431
- if (subcommand === undefined)
432
- continue;
433
- if (subcommand.name === "config") {
434
- if (configWrites(subcommand.args))
435
- return "config";
436
- continue;
437
- }
438
- if (subcommand.name === "notes") {
439
- const action = lower(firstAction(subcommand.args, ["--ref", "-r"]) ?? "");
440
- if (["add", "append", "copy", "edit", "merge", "prune", "remove"].includes(action))
441
- return `notes ${action}`;
442
- continue;
443
- }
444
- if (subcommand.name === "replace") {
445
- if (replaceWrites(subcommand.args))
446
- return "replace";
447
- continue;
448
- }
449
- if (subcommand.name === "update-ref")
450
- return "update-ref";
451
- if (subcommand.name === "symbolic-ref") {
452
- if (symbolicRefWrites(subcommand.args))
453
- return "symbolic-ref";
454
- continue;
455
- }
456
- if (subcommand.name === "reset" && subcommand.args.some((argument) => lower(argument) === "--hard"))
457
- return "reset --hard";
458
- if (subcommand.name === "stash") {
459
- const action = lower(subcommand.args[0] ?? "");
460
- if (action === "pop" || action === "drop" || action === "clear")
461
- return `stash ${action}`;
747
+ // Keep the wrapper's literal spelling, including options affecting cwd/env.
748
+ const prefixLength = commandWords.length - unwrapped.length;
749
+ const literal = prefixLength > 0 && unwrapped.every((word, index) => word === commandWords[prefixLength + index]);
750
+ const prefix = literal ? commandWords.slice(0, prefixLength) : commandWords;
751
+ environment.push(...prefix);
752
+ wrapperKnown = wrapperKnown && literal && !prefix.some((word) => /^(-[iv]*[fS]|--(?:file|split-string))(?:=|.|$)/u.test(word));
753
+ commandWords = [...unwrapped];
754
+ }
755
+ const executable = commandWords[0] ?? "";
756
+ if (!isNamedExecutable(executable, "git", dialect)) {
757
+ staticShell = false;
758
+ continue;
759
+ }
760
+ const invocation = gitSubcommand(commandWords);
761
+ if (invocation === undefined)
762
+ continue;
763
+ const context = { executable, globalOptions: invocation.globalOptions, environment };
764
+ const operatorsKnown = segment.tokens.every((token, index) => token.kind === "word" || dialect === "powershell" && token.value === "&" && index === 0);
765
+ const reusable = staticShell && operatorsKnown && invocation.known && wrapperKnown;
766
+ for (const action of gitActions(invocation.name, invocation.args)) {
767
+ const item = { ruleId: `git.${action.action}`, action: action.action, risk: action.risk, reusable: reusable && action.known, context };
768
+ const key = JSON.stringify(item);
769
+ if (!seen.has(key)) {
770
+ seen.add(key);
771
+ actions.push(item);
772
+ }
462
773
  }
463
- if (GIT_WRITE_COMMANDS.has(subcommand.name))
464
- return subcommand.name;
774
+ if (!operatorsKnown)
775
+ staticShell = false;
465
776
  }
466
- return undefined;
777
+ return actions;
778
+ }
779
+ export function classifyKnownGitWrite(input, dialect) {
780
+ const first = evaluateGitCommand(input, dialect)[0];
781
+ if (first === undefined)
782
+ return undefined;
783
+ if (first.action === "reset.hard")
784
+ return "reset --hard";
785
+ const [name, action] = first.action.split(".");
786
+ if (name === "notes")
787
+ return `notes ${action?.split("-")[0] ?? ""}`;
788
+ if (name === "stash" && ["pop", "drop", "clear"].includes(action ?? ""))
789
+ return `stash ${action}`;
790
+ return name;
467
791
  }
468
792
  export function classifyShellDialectViolation(input, dialect) {
469
793
  for (const segment of parseShellCommand(input, dialect)) {