thumbgate 1.39.1 → 1.40.2

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 (199) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.well-known/llms.txt +2 -2
  3. package/.well-known/mcp/server-card.json +1 -1
  4. package/README.md +5 -4
  5. package/adapters/claude/.mcp.json +6 -2
  6. package/adapters/codex/config.toml +5 -0
  7. package/adapters/forge/forge.yaml +4 -4
  8. package/adapters/future-agi/.mcp.json +1 -1
  9. package/adapters/future-agi/config.toml +1 -1
  10. package/adapters/future-agi/opencode.json +1 -1
  11. package/adapters/herdr/herdr-plugin.toml +2 -2
  12. package/adapters/mcp/server-stdio.js +82 -7
  13. package/adapters/opencode/opencode.json +1 -1
  14. package/bin/cli.js +128 -15
  15. package/config/brand-standards.json +131 -0
  16. package/config/gates/default.json +18 -1
  17. package/config/github-about.json +1 -1
  18. package/config/mcp-allowlists.json +16 -3
  19. package/config/merge-quality-checks.json +1 -0
  20. package/config/post-deploy-marketing-pages.json +3 -3
  21. package/config/schemas/task-outcome-receipt.schema.json +9 -0
  22. package/openapi/openapi.yaml +7 -3
  23. package/package.json +98 -31
  24. package/public/about.html +2 -2
  25. package/public/admin.html +771 -0
  26. package/public/agent-manager.html +3 -3
  27. package/public/agents-cost-savings.html +1 -1
  28. package/public/ai-malpractice-prevention.html +12 -12
  29. package/public/architecture.html +0 -1
  30. package/public/assets/diagrams/decision.svg +3 -3
  31. package/public/blog/2026-10-05-why-3-days-of-triage-wont-save-ai-speed-code.html +1 -1
  32. package/public/blog/2026-10-09-your-code-got-a-third-author-governance.html +1 -1
  33. package/public/blog/git-at-agent-scale.html +2 -2
  34. package/public/blog/inside-your-boundary.html +1 -1
  35. package/public/blog/process-over-outcome-gates.html +1 -1
  36. package/public/case-studies.html +1 -2
  37. package/public/codex-enterprise.html +1 -1
  38. package/public/codex-plugin.html +1 -1
  39. package/public/dashboard.html +773 -481
  40. package/public/diagnostic.html +8 -3
  41. package/public/enterprise-governance.html +26 -174
  42. package/public/eval-scorecard.html +3 -4
  43. package/public/eval-scorecard.json +2 -2
  44. package/public/evaluations.html +0 -1
  45. package/public/founders.html +3 -3
  46. package/public/gaming-playbook.html +4 -4
  47. package/public/guide.html +3 -5
  48. package/public/index.html +181 -205
  49. package/public/install.html +12 -11
  50. package/public/js/buyer-intent.js +49 -8
  51. package/public/lessons.html +103 -46
  52. package/public/numbers.html +32 -33
  53. package/public/operator-framework.html +44 -72
  54. package/public/peter.html +3 -3
  55. package/public/platform-partners.html +1 -1
  56. package/public/pricing.html +61 -327
  57. package/public/pro.html +3 -1
  58. package/public/project-switcher.js +76 -0
  59. package/public/whitepaper.html +1 -2
  60. package/scripts/activation-quickstart.js +15 -3
  61. package/scripts/activation-tracker.js +280 -3
  62. package/scripts/agent-action-inventory.js +235 -143
  63. package/scripts/agent-operations-planner.js +1 -1
  64. package/scripts/agent-readiness.js +36 -6
  65. package/scripts/agentic-prompt-pipelines.js +901 -0
  66. package/scripts/analytics-report.js +363 -0
  67. package/scripts/analytics-window.js +7 -1
  68. package/scripts/async-job-runner.js +66 -11
  69. package/scripts/audit-trail.js +37 -24
  70. package/scripts/auto-context-packs.js +249 -0
  71. package/scripts/auto-promote-gates.js +37 -27
  72. package/scripts/backfill-lesson-scopes.js +122 -0
  73. package/scripts/billing-setup.js +137 -0
  74. package/scripts/billing.js +889 -132
  75. package/scripts/bot-detection.js +112 -0
  76. package/scripts/brand-standards-gate.js +571 -0
  77. package/scripts/chatgpt-ads-readiness-pack.js +1 -1
  78. package/scripts/check-update.js +236 -0
  79. package/scripts/cli-schema.js +1 -1
  80. package/scripts/commercial-offer.js +2 -2
  81. package/scripts/contextfs.js +9 -3
  82. package/scripts/conversion-rate-stats.js +442 -0
  83. package/scripts/cost-cli.js +147 -0
  84. package/scripts/creator-campaigns.js +239 -0
  85. package/scripts/cross-encoder-reranker.js +4 -0
  86. package/scripts/cuda-gate-batch.js +560 -0
  87. package/scripts/daemon-manager.js +108 -0
  88. package/scripts/dashboard-chat.js +11 -0
  89. package/scripts/dashboard.js +576 -169
  90. package/scripts/decision-journal.js +7 -4
  91. package/scripts/delegation-runtime.js +1036 -0
  92. package/scripts/dispatch-brief.js +159 -0
  93. package/scripts/distribution-surfaces.js +110 -0
  94. package/scripts/docker-sandbox-planner.js +3 -3
  95. package/scripts/egm-goldfish-packet.js +95 -0
  96. package/scripts/embeddinggemma-adapter.js +407 -0
  97. package/scripts/export-dpo-pairs.js +12 -7
  98. package/scripts/feedback-aggregate.js +4 -0
  99. package/scripts/feedback-attribution.js +6 -4
  100. package/scripts/feedback-history-distiller.js +18 -6
  101. package/scripts/feedback-loop.js +255 -89
  102. package/scripts/feedback-paths.js +8 -1
  103. package/scripts/feedback-sanitizer.js +5 -0
  104. package/scripts/feedback-scope.js +106 -0
  105. package/scripts/feedback-session.js +8 -2
  106. package/scripts/filesystem-search.js +13 -8
  107. package/scripts/financial-control-plane.js +707 -45
  108. package/scripts/funnel-analytics.js +35 -0
  109. package/scripts/gate-semantic-layer.js +292 -0
  110. package/scripts/gate-stats.js +8 -2
  111. package/scripts/gates-engine.js +694 -230
  112. package/scripts/generate-eval-scorecard.js +0 -1
  113. package/scripts/harness-tool-names.js +31 -5
  114. package/scripts/hybrid-feedback-context.js +5 -2
  115. package/scripts/implementation-notes.js +241 -0
  116. package/scripts/intent-router.js +518 -0
  117. package/scripts/intervention-policy.js +2 -1
  118. package/scripts/latency-budget.js +164 -0
  119. package/scripts/lesson-canonical.js +2 -2
  120. package/scripts/lesson-db.js +55 -14
  121. package/scripts/lesson-graph.js +2 -1
  122. package/scripts/lesson-retrieval.js +95 -9
  123. package/scripts/lesson-search.js +86 -22
  124. package/scripts/lesson-synthesis.js +21 -5
  125. package/scripts/mailer/index.js +17 -1
  126. package/scripts/mailer/resend-mailer.js +213 -179
  127. package/scripts/mcp-writeguard.js +158 -0
  128. package/scripts/migrate-project-scope.js +209 -0
  129. package/scripts/model-candidates.js +414 -0
  130. package/scripts/openrouter-armor-partnership-diode.js +2419 -0
  131. package/scripts/operational-dashboard.js +172 -0
  132. package/scripts/operational-integrity.js +436 -3
  133. package/scripts/operational-summary.js +190 -0
  134. package/scripts/operator-artifacts.js +622 -0
  135. package/scripts/optimize-context.js +17 -0
  136. package/scripts/override-audit.js +2 -0
  137. package/scripts/owner-admin.js +338 -0
  138. package/scripts/pr-manager.js +194 -1
  139. package/scripts/predictive-insights.js +449 -0
  140. package/scripts/profound-aeo-citation-engine.js +583 -0
  141. package/scripts/progressive-signoff.js +260 -0
  142. package/scripts/project-catalog.js +243 -0
  143. package/scripts/project-dashboard.js +61 -0
  144. package/scripts/project-evidence.js +172 -0
  145. package/scripts/project-identity.js +182 -0
  146. package/scripts/project-scope.js +381 -0
  147. package/scripts/prompt-guard.js +446 -52
  148. package/scripts/proof-report.js +232 -0
  149. package/scripts/provider-action-normalizer.js +14 -6
  150. package/scripts/pulse.js +80 -0
  151. package/scripts/rate-limiter.js +41 -0
  152. package/scripts/rrsi-doctor.js +2698 -0
  153. package/scripts/secret-redaction.js +171 -25
  154. package/scripts/secret-scanner.js +101 -42
  155. package/scripts/self-protection.js +2 -2
  156. package/scripts/seo-gsd.js +14 -14
  157. package/scripts/session-context-dedupe.js +66 -0
  158. package/scripts/session-report.js +120 -0
  159. package/scripts/settings-hierarchy.js +4 -2
  160. package/scripts/statusline-meta.js +34 -23
  161. package/scripts/subagent-profiles.js +79 -0
  162. package/scripts/task-outcomes.js +29 -2
  163. package/scripts/telemetry-analytics.js +238 -13
  164. package/scripts/third-author-cli.js +118 -0
  165. package/scripts/third-author-governance.js +437 -0
  166. package/scripts/thumbgate-dream.js +878 -0
  167. package/scripts/thumbgate-search.js +23 -9
  168. package/scripts/tool-kpi-tracker.js +5 -2
  169. package/scripts/tool-registry.js +42 -1
  170. package/scripts/triage-savings-calculator.js +1 -1
  171. package/scripts/vector-store.js +4 -1
  172. package/scripts/verified-lessons.js +270 -0
  173. package/scripts/verify-marketing-pages-deployed.js +2 -2
  174. package/scripts/workflow-sentinel.js +29 -10
  175. package/server.json +2 -2
  176. package/skills/thumbgate-daily-discoveries/SKILL.md +25 -41
  177. package/src/api/server.js +2371 -451
  178. package/src/feedback.js +21 -0
  179. package/src/hermes-sync-plane.js +2 -1
  180. package/src/index.js +2 -0
  181. package/src/lesson-search.js +9 -0
  182. package/src/mckinsey-top-company-ai-coding.js +493 -0
  183. package/src/mcp/server.js +3 -0
  184. package/src/mcp-writeguard.js +772 -11
  185. package/src/openshell-lovable-engine.js +1475 -0
  186. package/src/task-outcome.js +3 -0
  187. package/config/evals/agent-safety-eval.json +0 -447
  188. package/config/evals/retrieval-ranking-golden.json +0 -522
  189. package/config/progressive/01-wire-only.json +0 -11
  190. package/config/progressive/02-dashboard-empty-ok.json +0 -10
  191. package/config/progressive/03-one-lesson.json +0 -10
  192. package/config/progressive/04-warn-fires.json +0 -11
  193. package/config/progressive/05-strict-optional.json +0 -11
  194. package/config/progressive/README.md +0 -15
  195. package/public/assets/diagrams/agent-integration.png +0 -0
  196. package/public/assets/diagrams/thumbgate-architecture.png +0 -0
  197. package/scripts/install-thumbgate-daily-publish-launchd.sh +0 -83
  198. package/scripts/thumbgate-daily-discoveries-publish.js +0 -461
  199. package/scripts/thumbgate-daily-discoveries-publish.sh +0 -18
@@ -0,0 +1,172 @@
1
+ 'use strict';
2
+
3
+ const { resolveAnalyticsWindow } = require('./analytics-window');
4
+ const { getBillingSummaryLive } = require('./billing');
5
+ const { generateDashboard } = require('./dashboard');
6
+ const { getFeedbackPaths } = require('./feedback-loop');
7
+ const { resolveHostedBillingConfig } = require('./hosted-config');
8
+ const { loadOperatorConfig } = require('./operational-summary');
9
+
10
+ function normalizeText(value) {
11
+ if (value === undefined || value === null) return null;
12
+ const text = String(value).trim();
13
+ return text || null;
14
+ }
15
+
16
+ function shouldPreferHostedDashboard() {
17
+ return String(process.env.THUMBGATE_METRICS_SOURCE || '').trim().toLowerCase() !== 'local';
18
+ }
19
+
20
+ function resolveHostedDashboardConfig() {
21
+ const runtimeConfig = resolveHostedBillingConfig();
22
+ const operatorConfig = loadOperatorConfig();
23
+ // Match operational-summary's key priority chain so north-star and cfo
24
+ // authenticate against the same hosted deployment consistently. Prior to
25
+ // this change, north-star only read THUMBGATE_API_KEY, silently 401'ing
26
+ // on machines configured via operator.json or THUMBGATE_OPERATOR_KEY.
27
+ const apiKey = normalizeText(process.env.THUMBGATE_OPERATOR_KEY)
28
+ || operatorConfig.operatorKey
29
+ || normalizeText(process.env.THUMBGATE_API_KEY);
30
+ const apiBaseUrl = normalizeText(process.env.THUMBGATE_BILLING_API_BASE_URL)
31
+ || operatorConfig.baseUrl
32
+ || runtimeConfig.billingApiBaseUrl;
33
+ return {
34
+ apiBaseUrl,
35
+ apiKey,
36
+ };
37
+ }
38
+
39
+ async function buildOperationalDashboard(options = {}) {
40
+ const analyticsWindow = resolveAnalyticsWindow(options);
41
+ const feedbackDir = options.feedbackDir || getFeedbackPaths().FEEDBACK_DIR;
42
+ const billingSummary = await getBillingSummaryLive(analyticsWindow);
43
+
44
+ return generateDashboard(feedbackDir, {
45
+ analyticsWindow,
46
+ billingSummary,
47
+ billingSource: 'live',
48
+ billingFallbackReason: null,
49
+ });
50
+ }
51
+
52
+ function reportProgress(options, message) {
53
+ if (typeof options.onProgress === 'function') {
54
+ options.onProgress(message);
55
+ }
56
+ }
57
+
58
+ async function fetchHostedDashboard(options = {}, config = resolveHostedDashboardConfig()) {
59
+ const analyticsWindow = resolveAnalyticsWindow(options);
60
+ if (!shouldPreferHostedDashboard()) {
61
+ const err = new Error('Hosted operational dashboard is disabled.');
62
+ err.code = 'hosted_dashboard_disabled';
63
+ throw err;
64
+ }
65
+ if (!config.apiBaseUrl || !config.apiKey) {
66
+ const err = new Error('Hosted operational dashboard is not configured.');
67
+ err.code = 'hosted_dashboard_unconfigured';
68
+ throw err;
69
+ }
70
+
71
+ const requestUrl = new URL('/v1/dashboard', config.apiBaseUrl);
72
+ requestUrl.searchParams.set('window', analyticsWindow.window);
73
+ requestUrl.searchParams.set('timezone', analyticsWindow.timeZone);
74
+ requestUrl.searchParams.set('now', analyticsWindow.now);
75
+
76
+ reportProgress(options, `Fetching hosted dashboard (${analyticsWindow.window})…`);
77
+ const response = await fetch(requestUrl, {
78
+ method: 'GET',
79
+ headers: {
80
+ authorization: `Bearer ${config.apiKey}`,
81
+ accept: 'application/json',
82
+ },
83
+ });
84
+
85
+ if (!response.ok) {
86
+ const detail = await response.text().catch(() => '');
87
+ const err = new Error(`Hosted operational dashboard request failed (${response.status}): ${detail || 'unknown error'}`);
88
+ err.code = 'hosted_dashboard_http_error';
89
+ err.status = response.status;
90
+ throw err;
91
+ }
92
+
93
+ reportProgress(options, 'Parsing hosted dashboard payload…');
94
+ return response.json();
95
+ }
96
+
97
+ async function getOperationalDashboard(options = {}) {
98
+ const analyticsWindow = resolveAnalyticsWindow(options);
99
+ try {
100
+ reportProgress(options, 'Checking hosted operational dashboard…');
101
+ const data = await fetchHostedDashboard(options);
102
+ reportProgress(options, 'Hosted dashboard ready');
103
+ return {
104
+ source: 'hosted',
105
+ data,
106
+ fallbackReason: null,
107
+ hostedStatus: 200,
108
+ };
109
+ } catch (err) {
110
+ const reason = err && err.message ? err.message : 'hosted_dashboard_unavailable';
111
+ const status = err && typeof err.status === 'number' ? err.status : null;
112
+ const code = err && err.code ? err.code : null;
113
+
114
+ // Hosted deliberately disabled or never configured — local fallback is
115
+ // intentional, not a degraded state. Tag as plain 'local'.
116
+ if (code === 'hosted_dashboard_disabled' || code === 'hosted_dashboard_unconfigured') {
117
+ reportProgress(options, 'Building local dashboard…');
118
+ return {
119
+ source: 'local',
120
+ data: await buildOperationalDashboard(analyticsWindow),
121
+ fallbackReason: reason,
122
+ hostedStatus: null,
123
+ };
124
+ }
125
+
126
+ // Mirror operational-summary: auth failure is the dangerous case. A
127
+ // dashboard that silently shows $0 revenue (from the local ledger) when
128
+ // Stripe actually has paid customers is a lie the operator acts on.
129
+ // Refuse to guess — surface an actionable error.
130
+ if (status === 401 || status === 403) {
131
+ const authErr = new Error(
132
+ `Hosted operational dashboard rejected credentials (HTTP ${status}). ` +
133
+ `The operator key on this machine does not match the one on the ` +
134
+ `hosted deployment. Fix: set THUMBGATE_OPERATOR_KEY in this shell, ` +
135
+ `or update the operatorKey field in ~/.config/thumbgate/operator.json, ` +
136
+ `to match Railway's THUMBGATE_OPERATOR_KEY. ` +
137
+ `Running north-star without hosted auth would report local-only ` +
138
+ `data as ground truth, which may not reflect actual Stripe revenue. ` +
139
+ `Original response: ${reason}`
140
+ );
141
+ authErr.code = 'hosted_dashboard_unauthorized';
142
+ authErr.status = status;
143
+ throw authErr;
144
+ }
145
+
146
+ // Non-auth failure — local fallback is still useful for dev workflows,
147
+ // but tag the source so downstream renderers do not mistake it for
148
+ // verified hosted truth.
149
+ //
150
+ // Log only the status code (trusted) — the full reason contains upstream
151
+ // response text and is only returned structurally via fallbackReason.
152
+ console.warn(
153
+ `[operational-dashboard] Hosted dashboard unreachable (status=${status ?? 'network'}); ` +
154
+ `falling back to LOCAL-UNVERIFIED state. Numbers below may not reflect actual Stripe revenue.`
155
+ );
156
+ reportProgress(options, `Hosted failed (HTTP ${status ?? 'network'}); building local dashboard…`);
157
+ return {
158
+ source: 'local-unverified',
159
+ data: await buildOperationalDashboard(analyticsWindow),
160
+ fallbackReason: reason,
161
+ hostedStatus: status,
162
+ };
163
+ }
164
+ }
165
+
166
+ module.exports = {
167
+ buildOperationalDashboard,
168
+ fetchHostedDashboard,
169
+ getOperationalDashboard,
170
+ resolveHostedDashboardConfig,
171
+ shouldPreferHostedDashboard,
172
+ };
@@ -4,6 +4,7 @@
4
4
  const fs = require('fs');
5
5
  const path = require('path');
6
6
  const { execFileSync, spawnSync } = require('child_process');
7
+ const { normalizeCommandValue } = require('./harness-tool-names');
7
8
 
8
9
  const DEFAULT_BASE_BRANCH = 'main';
9
10
  const FIXED_GIT_BIN_CANDIDATES = [
@@ -653,10 +654,440 @@ function findOpenPrForBranch({ branchName, runner = runGh, env = process.env } =
653
654
  }
654
655
  }
655
656
 
657
+ const WRAPPERS = new Set('sudo doas env command builtin exec nohup time nice ionice setsid stdbuf xargs'.split(' '));
658
+ const WRAPPER_FLAGS = new Map([
659
+ ['sudo', new Set(['-u', '-g', '-h', '-p', '-r', '-t', '-C'])], ['doas', new Set(['-u'])],
660
+ ['env', new Set(['-u', '-C', '-S'])], ['nice', new Set(['-n'])], ['ionice', new Set(['-c', '-n', '-p'])],
661
+ ['xargs', new Set(['-n', '-P', '-I', '-L', '-s', '-d'])], ['stdbuf', new Set(['-i', '-o', '-e'])],
662
+ ]);
663
+ const CTRL_KW = new Set('then else elif do while until if { ('.split(' '));
664
+ const ASSIGN_KW = new Set(['export', 'local', 'declare', 'typeset']);
665
+ const UNSET_KW = new Set(['unset', 'remove-variable', 'rv']);
666
+ const READ_FLAGS = new Set(['-p', '-d', '-n', '-N', '-t', '-u']);
667
+ const SH_BINS = new Set(['bash', 'sh', 'zsh', 'dash', 'ksh']);
668
+ const PWSH_BINS = new Set(['powershell', 'pwsh']);
669
+ const PWSH_FLAGS = new Set('-executionpolicy -ep -windowstyle -w -inputformat -if -outputformat -of -configurationname'.split(' '));
670
+ const FIND_ARG_FLAGS = new Set('-name -iname -path -ipath -wholename -iwholename -regex -iregex -lname -ilname -samefile -type -xtype -maxdepth -mindepth -perm -links -user -group -uid -gid -size -inum -amin -atime -cmin -ctime -mmin -mtime -newer -anewer -cnewer -printf -fprintf -fprint -fls'.split(' '));
671
+ const RI_VAL_FLAGS = new Set(['-include', '-exclude', '-filter', '-stream', '-credential']);
672
+ const RI_PATH_FLAGS = new Set(['-path', '-literalpath', '-lp']);
673
+ const GIT_ARG_FLAGS = new Set(['-c', '-C', '--git-dir', '--work-tree', '--namespace', '--exec-path', '--super-prefix']);
674
+ const DEL_EXEC_BINS = new Set('rm unlink shred rmdir rd del erase remove-item ri'.split(' '));
675
+ const DIR_DEL_BINS = new Set(['rmdir', 'rd', 'del', 'erase']);
676
+ const WIN_SW_RE = /^(?:\/(?:s|q|f|p|a(?::?[a-z-]+)?))+$/i;
677
+ const WIN_S_RE = /\/s(?:$|\/|:)/i;
678
+ const PWSH_REC_RE = /^-(?:r|rec|recur|recurs|recurse)(?::\$?true)?$/i;
679
+ const VAR_ONLY_RE = /^(?:\$\{([A-Za-z_]\w*)(?::-)?\}|\$(?:env:)?([A-Za-z_]\w*)|%([A-Za-z_]\w*)%)([/\\*]*)$/i;
680
+ const VAR_HEAD_RE = /^(?:\$\{([A-Za-z_]\w*)\}|\$([A-Za-z_]\w*)|%([A-Za-z_]\w*)%)[/\\]/;
681
+
682
+ function fmtInput(cmd, max = 20000) {
683
+ return (Array.isArray(cmd) ? String(normalizeCommandValue(cmd)) : String(cmd || '')).slice(0, max).trim();
684
+ }
685
+
686
+ function isEscSlash(s, i) { return s[i] === '\\' && s[i + 1] === '\\'; }
687
+ function isWinQuotedSpan(s, qs) { return qs >= 0 && /^(?:[A-Za-z]:\\|\\\\)/.test(s.slice(qs + 1, qs + 5)); }
688
+ function isEscQuote(s, i, qs) {
689
+ return s[i] === '\\' && s[i + 1] === '"' && !isWinQuotedSpan(s, qs) && s.indexOf('"', i + 2) !== -1;
690
+ }
691
+ function isWinPathBefore(s, i) {
692
+ let k = i - 1;
693
+ while (k >= 0 && !/[\s;|&"']/.test(s[k])) {
694
+ if (s[k] === '\\' || (s[k] === ':' && k > 0 && /[A-Za-z]/.test(s[k - 1]))) return true;
695
+ k -= 1;
696
+ }
697
+ return false;
698
+ }
699
+
700
+ function isEscUnquoted(s, i) {
701
+ return s[i] === '\\' && i + 1 < s.length && /[;&|"' ]/.test(s[i + 1]) && !isWinPathBefore(s, i);
702
+ }
703
+
704
+ function stepQuotedSeg(s, i, q, qs) {
705
+ if (q === '"' && (isEscSlash(s, i) || isEscQuote(s, i, qs))) return { n: i + 1, q, qs };
706
+ return s[i] === q ? { n: i, q: null, qs: -1 } : { n: i, q, qs };
707
+ }
708
+
709
+ function delimLen(s, i) {
710
+ const c = s[i];
711
+ if (c === '\r' || c === '\n' || c === ';') return 1;
712
+ if (c === '&' || c === '|') return s[i + 1] === c ? 2 : 1;
713
+ return 0;
714
+ }
715
+
716
+ function splitSegs(cmd) {
717
+ const s = String(cmd || '');
718
+ const out = [];
719
+ let start = 0;
720
+ let q = null;
721
+ let qs = -1;
722
+ for (let i = 0; i < s.length; i += 1) {
723
+ if (q) { const st = stepQuotedSeg(s, i, q, qs); i = st.n; q = st.q; qs = st.qs; continue; }
724
+ if (isEscUnquoted(s, i)) { i += 1; continue; }
725
+ if (s[i] === '"' || s[i] === '\'') { q = s[i]; qs = i; continue; }
726
+ const dl = delimLen(s, i);
727
+ if (dl > 0) { out.push(s.slice(start, i)); i += dl - 1; start = i + 1; }
728
+ }
729
+ out.push(s.slice(start));
730
+ return out.map((x) => x.trim()).filter(Boolean);
731
+ }
732
+
733
+ function stepQuotedTok(s, i, b) {
734
+ if (b.q === '"' && isEscSlash(s, i)) { b.v += '\\'; return i + 1; }
735
+ if (b.q === '"' && isEscQuote(s, i, b.qs)) { b.v += '"'; return i + 1; }
736
+ if (s[i] === b.q) { b.q = null; b.qs = -1; return i; }
737
+ b.v += s[i];
738
+ return i;
739
+ }
740
+
741
+ function stepUnquotedTok(s, i, b) {
742
+ const c = s[i];
743
+ if (c === '"' || c === '\'') { b.q = c; b.qs = i; b.hq = true; if (c !== '\'') b.sq = false; return i; }
744
+ b.sq = false;
745
+ if (isEscUnquoted(s, i)) { b.v += s[i + 1]; return i + 1; }
746
+ b.v += c;
747
+ return i;
748
+ }
749
+
750
+ function flushTok(s, end, b, out) {
751
+ if (b.rs === -1) return;
752
+ out.push({ raw: s.slice(b.rs, end), value: b.v, hasQuotes: b.hq, singleQuoted: b.hq && b.sq });
753
+ b.rs = -1; b.v = ''; b.hq = false; b.sq = true;
754
+ }
755
+
756
+ function tokenize(seg) {
757
+ const s = String(seg || '').trim();
758
+ const out = [];
759
+ const b = { rs: -1, v: '', q: null, qs: -1, hq: false, sq: true };
760
+ for (let i = 0; i < s.length; i += 1) {
761
+ if (b.q) { i = stepQuotedTok(s, i, b); continue; }
762
+ if (/\s/.test(s[i])) { flushTok(s, i, b, out); continue; }
763
+ if (b.rs === -1) b.rs = i;
764
+ i = stepUnquotedTok(s, i, b);
765
+ }
766
+ flushTok(s, s.length, b, out);
767
+ return out;
768
+ }
769
+
770
+ function readSubAt(s, i) {
771
+ if (s[i] === '$' && s[i + 1] === '(') {
772
+ let d = 1;
773
+ let c = i + 2;
774
+ while (c < s.length && d > 0) { if (s[c] === '(') d += 1; else if (s[c] === ')') d -= 1; c += 1; }
775
+ return d === 0 ? { inner: s.slice(i + 2, c - 1).trim(), n: i + 1 } : null;
776
+ }
777
+ if (s[i] === '`') {
778
+ const end = s.indexOf('`', i + 1);
779
+ if (end !== -1) return { inner: s.slice(i + 1, end).trim(), n: end };
780
+ }
781
+ return null;
782
+ }
783
+
784
+ function stepSubQuote(c, i, q, qs) {
785
+ if (q === '\'') return c === '\'' ? { q: null, qs: -1 } : { q, qs };
786
+ if (c === '\'' && !q) return { q: '\'', qs: i };
787
+ if (c === '"') return q === '"' ? { q: null, qs: -1 } : { q: '"', qs: i };
788
+ return { q, qs };
789
+ }
790
+
791
+ function extractSubs(cmd) {
792
+ const s = String(cmd || '');
793
+ const out = [];
794
+ let q = null;
795
+ let qs = -1;
796
+ for (let i = 0; i < s.length; i += 1) {
797
+ if (q === '"' && (isEscSlash(s, i) || isEscQuote(s, i, qs))) { i += 1; continue; }
798
+ const wasSq = q === '\'';
799
+ const nxt = stepSubQuote(s[i], i, q, qs);
800
+ q = nxt.q;
801
+ qs = nxt.qs;
802
+ if (wasSq || q === '\'') continue;
803
+ const sub = readSubAt(s, i);
804
+ if (sub) { if (sub.inner) out.push(sub.inner); i = sub.n; }
805
+ }
806
+ return out;
807
+ }
808
+
809
+ function normBin(v) {
810
+ return (String(v || '').replace(/^\\/, '').trim().split(/[/\\]/).pop() || '').toLowerCase().replace(/\.exe$/i, '');
811
+ }
812
+
813
+ function bindVar(name, rhs, st) {
814
+ const k = name.toLowerCase();
815
+ const t = String(rhs || '').trim().replace(/^(['"])(.*)\1$/, '$2');
816
+ if (!t || t.toLowerCase() === '$null') { st.empty.add(k); st.bound.delete(k); } else { st.bound.add(k); st.empty.delete(k); }
817
+ }
818
+
819
+ function recAssign(txt, st) {
820
+ const eq = txt.indexOf('=');
821
+ if (eq <= 0) return false;
822
+ const name = txt.slice(0, eq).trim().replace(/^\$(?:env:)?/i, '');
823
+ if (!/^[A-Za-z_]\w*$/.test(name)) return false;
824
+ bindVar(name, txt.slice(eq + 1), st);
825
+ return true;
826
+ }
827
+
828
+ function recPwshAssign(toks, st) {
829
+ if (toks.length < 2 || toks[1].value !== '=') return false;
830
+ const name = toks[0].value.replace(/^\$(?:env:)?/i, '');
831
+ if (!/^[A-Za-z_]\w*$/.test(name)) return false;
832
+ bindVar(name, toks[2]?.raw || '', st);
833
+ return true;
834
+ }
835
+
836
+ function bindRead(toks, st) {
837
+ let any = false;
838
+ for (let i = 1; i < toks.length; i += 1) {
839
+ const v = toks[i].value;
840
+ if (READ_FLAGS.has(v)) { i += 1; continue; }
841
+ let target = '';
842
+ if (v === '-a') target = toks[++i]?.value || '';
843
+ else if (!v.startsWith('-')) target = v;
844
+ if (target && /^[A-Za-z_]\w*$/.test(target)) { bindVar(target, '1', st); any = true; }
845
+ }
846
+ if (!any) bindVar('reply', '1', st);
847
+ }
848
+
849
+ function bindUnset(toks, st) {
850
+ for (const t of toks.slice(1)) {
851
+ if (!t.value.startsWith('-')) bindVar(t.value.replace(/^\$(?:env:)?/i, ''), '', st);
852
+ }
853
+ }
854
+
855
+ function updateBuiltinState(toks, st) {
856
+ if (toks.length === 0 || recPwshAssign(toks, st)) return true;
857
+ const h = toks[0].value.toLowerCase();
858
+ if (h === 'for' && toks[1] && /^[A-Za-z_]\w*$/.test(toks[1].value)) { bindVar(toks[1].value, '1', st); return true; }
859
+ if (h === 'read') { bindRead(toks, st); return true; }
860
+ if (ASSIGN_KW.has(h)) { for (const t of toks.slice(1)) recAssign(t.value, st); return true; }
861
+ if (h === 'set' && toks[1] && recAssign(toks[1].value, st)) return true;
862
+ if (UNSET_KW.has(h)) { bindUnset(toks, st); return true; }
863
+ return false;
864
+ }
865
+
866
+ function stepEnvOpt(toks, c, st) {
867
+ const cur = toks[c].value;
868
+ if (recAssign(cur, st)) return c + 1;
869
+ if (cur === '-u' && c + 1 < toks.length) { bindVar(toks[c + 1].value, '', st); return c + 2; }
870
+ return -1;
871
+ }
872
+
873
+ function skipWrapperOpts(bin, toks, start, st) {
874
+ const twoArg = WRAPPER_FLAGS.get(bin);
875
+ let c = start;
876
+ while (c < toks.length) {
877
+ const cur = toks[c].value;
878
+ if (cur === '--') return c + 1;
879
+ if (bin === 'env') { const nxt = stepEnvOpt(toks, c, st); if (nxt !== -1) { c = nxt; continue; } }
880
+ if (!cur.startsWith('-')) break;
881
+ c += twoArg?.has(cur) && c + 1 < toks.length ? 2 : 1;
882
+ }
883
+ return c;
884
+ }
885
+
886
+ function stripPrefixes(toks, st) {
887
+ let i = 0;
888
+ while (i < toks.length) {
889
+ const w = toks[i].value;
890
+ if (CTRL_KW.has(w.toLowerCase()) || (/^\$?(?:env:)?[A-Za-z_]\w*=/i.test(toks[i].raw) && recAssign(w, st))) { i += 1; continue; }
891
+ const bin = normBin(w);
892
+ if (!WRAPPERS.has(bin)) break;
893
+ i = skipWrapperOpts(bin, toks, i + 1, st);
894
+ }
895
+ return toks.slice(i);
896
+ }
897
+
898
+ function joinPayload(args) {
899
+ if (args.length === 0) return '';
900
+ return args.length === 1 ? args[0].value.trim() : args.map((t) => t.raw).join(' ').trim();
901
+ }
902
+
903
+ function unwrapCmd(args) {
904
+ for (let i = 0; i < args.length; i += 1) {
905
+ const raw = args[i].value;
906
+ const lo = raw.toLowerCase();
907
+ if (/^\/[abd-jl-z]*[ck]+$/i.test(lo)) return joinPayload(args.slice(i + 1));
908
+ const m = /^\/[abd-jl-z]*[ck]+:?([\s\S]+)$/i.exec(raw);
909
+ if (m && !/^[a-z]+$/i.test(m[1])) { const t = joinPayload(args.slice(i + 1)); return t ? `${m[1]} ${t}` : m[1].trim(); }
910
+ if (!lo.startsWith('/')) break;
911
+ }
912
+ return null;
913
+ }
914
+
915
+ function unwrapPwsh(args) {
916
+ for (let i = 0; i < args.length; i += 1) {
917
+ const lo = args[i].value.toLowerCase();
918
+ if (lo === '-command' || lo === '-c') return joinPayload(args.slice(i + 1));
919
+ if (lo === '-file' || lo === '-f' || lo.startsWith('-enc')) return null;
920
+ if (PWSH_FLAGS.has(lo)) { i += 1; continue; }
921
+ if (!lo.startsWith('-')) return joinPayload(args.slice(i));
922
+ }
923
+ return null;
924
+ }
925
+
926
+ function unwrapSh(args) {
927
+ for (let i = 0; i < args.length; i += 1) {
928
+ const v = args[i].value;
929
+ if ((v === '-o' || v === '+o') && i + 1 < args.length) { i += 1; continue; }
930
+ if (/^-[A-ABD-Za-bd-z]*c[A-Za-z]*$/.test(v) && i + 1 < args.length) return args[i + 1].value.trim();
931
+ if (!v.startsWith('-') && !v.startsWith('+')) break;
932
+ }
933
+ return null;
934
+ }
935
+
936
+ function unwrapShell(bin, args) {
937
+ if (bin === 'cmd') return unwrapCmd(args);
938
+ if (PWSH_BINS.has(bin)) return unwrapPwsh(args);
939
+ return SH_BINS.has(bin) ? unwrapSh(args) : null;
940
+ }
941
+
942
+ function isBadTarget(tok, st) {
943
+ if (!tok) return false;
944
+ if (tok.hasQuotes && /^[/\\]*$/.test(tok.value)) return true;
945
+ if (tok.singleQuoted) return false;
946
+ const m1 = VAR_ONLY_RE.exec(tok.value);
947
+ if (m1) { const k = (m1[1] || m1[2] || m1[3] || '').toLowerCase(); return Boolean(k) && (!st.bound.has(k) || st.empty.has(k)); }
948
+ const m2 = VAR_HEAD_RE.exec(tok.value);
949
+ if (m2) { const k = (m2[1] || m2[2] || m2[3] || '').toLowerCase(); return Boolean(k) && st.empty.has(k); }
950
+ return false;
951
+ }
952
+
953
+ function applyRmFlag(v, f) {
954
+ if (v === '--recursive') f.r = true;
955
+ else if (v === '--force') f.f = true;
956
+ else if (!v.startsWith('--')) { if (/[rR]/.test(v)) f.r = true; if (/f/.test(v)) f.f = true; }
957
+ }
958
+
959
+ function checkRm(args, st) {
960
+ const f = { r: false, f: false };
961
+ let dd = false;
962
+ for (const t of args) {
963
+ const v = t.value;
964
+ if (!dd && v === '--') { dd = true; continue; }
965
+ if (!dd && /^-(?:recurse)(?::\$?true)?$/i.test(v)) return true;
966
+ if (!dd && v.startsWith('-') && v.length > 1 && !v.startsWith('-$')) { applyRmFlag(v, f); continue; }
967
+ if (isBadTarget(t, st)) return true;
968
+ }
969
+ return f.r && f.f;
970
+ }
971
+
972
+ function checkFindExec(slice, depth, st) {
973
+ const s = stripPrefixes(slice, st);
974
+ if (s.length === 0) return false;
975
+ const bin = normBin(s[0].value);
976
+ if (DEL_EXEC_BINS.has(bin)) return true;
977
+ const nested = unwrapShell(bin, s.slice(1));
978
+ return Boolean(nested && depth < 4 && evalCmd(nested, depth + 1, st));
979
+ }
980
+
981
+ function findExecEnd(args, start) {
982
+ let end = start;
983
+ while (end < args.length && args[end].value !== ';' && args[end].value !== '+') end += 1;
984
+ return end;
985
+ }
986
+
987
+ function checkFind(args, depth, st) {
988
+ for (let i = 0; i < args.length; i += 1) {
989
+ const lo = args[i].value.toLowerCase();
990
+ if (FIND_ARG_FLAGS.has(lo)) { i += 1; continue; }
991
+ if (lo === '-delete') return true;
992
+ if (lo === '-exec' || lo === '-execdir' || lo === '-ok' || lo === '-okdir') {
993
+ const end = findExecEnd(args, i + 1);
994
+ if (checkFindExec(args.slice(i + 1, end), depth, st)) return true;
995
+ i = end;
996
+ }
997
+ }
998
+ return false;
999
+ }
1000
+
1001
+ function checkDirDel(args, st) {
1002
+ for (const t of args) {
1003
+ const v = t.value;
1004
+ const sw = WIN_SW_RE.test(v);
1005
+ if ((sw && WIN_S_RE.test(v)) || PWSH_REC_RE.test(v)) return true;
1006
+ if (!v.startsWith('-') && !sw && isBadTarget(t, st)) return true;
1007
+ }
1008
+ return false;
1009
+ }
1010
+
1011
+ function checkRemoveItem(args, st) {
1012
+ for (let i = 0; i < args.length; i += 1) {
1013
+ const v = args[i].value;
1014
+ const lo = v.toLowerCase();
1015
+ if (PWSH_REC_RE.test(v)) return true;
1016
+ if (RI_VAL_FLAGS.has(lo)) { i += 1; continue; }
1017
+ if (RI_PATH_FLAGS.has(lo)) { if (isBadTarget(args[++i], st)) return true; continue; }
1018
+ if (!v.startsWith('-') && isBadTarget(args[i], st)) return true;
1019
+ }
1020
+ return false;
1021
+ }
1022
+
1023
+ function applyGitFlag(v, f) {
1024
+ if (v === '--force') f.f = true;
1025
+ else if (v === '--dry-run') f.n = true;
1026
+ else if (!v.startsWith('--')) { if (/f/.test(v)) f.f = true; if (/n/.test(v)) f.n = true; }
1027
+ }
1028
+
1029
+ function checkGitClean(tail, st) {
1030
+ const f = { f: false, n: false };
1031
+ let dd = false;
1032
+ for (let i = 0; i < tail.length; i += 1) {
1033
+ const v = tail[i].value;
1034
+ if (!dd && v === '--') { dd = true; continue; }
1035
+ if (!dd && (v === '-e' || v === '--exclude')) { i += 1; continue; }
1036
+ if (!dd && v.startsWith('-')) { applyGitFlag(v, f); continue; }
1037
+ if (isBadTarget(tail[i], st)) return true;
1038
+ }
1039
+ return f.f && !f.n;
1040
+ }
1041
+
1042
+ function checkGit(args, st) {
1043
+ for (let i = 0; i < args.length; i += 1) {
1044
+ if (GIT_ARG_FLAGS.has(args[i].value)) { i += 1; continue; }
1045
+ if (!args[i].value.startsWith('-')) {
1046
+ return args[i].value.toLowerCase() === 'clean' && checkGitClean(args.slice(i + 1), st);
1047
+ }
1048
+ }
1049
+ return false;
1050
+ }
1051
+
1052
+ function evalBin(bin, args, depth, st) {
1053
+ if (bin === 'rm') return checkRm(args, st);
1054
+ if (bin === 'find') return checkFind(args, depth, st);
1055
+ if (DIR_DEL_BINS.has(bin)) return checkDirDel(args, st);
1056
+ if (bin === 'remove-item' || bin === 'ri') return checkRemoveItem(args, st);
1057
+ if (bin === 'git') return checkGit(args, st);
1058
+ return (bin === 'unlink' || bin === 'shred') && args.some((t) => !t.value.startsWith('-') && isBadTarget(t, st));
1059
+ }
1060
+
1061
+ function evalSeg(seg, depth, st) {
1062
+ const raw = tokenize(seg);
1063
+ if (raw.length === 0 || updateBuiltinState(raw, st)) return false;
1064
+ const toks = stripPrefixes(raw, st);
1065
+ if (toks.length === 0 || updateBuiltinState(toks, st)) return false;
1066
+ const bin = normBin(toks[0].value);
1067
+ const args = toks.slice(1);
1068
+ const nested = unwrapShell(bin, args);
1069
+ if (nested !== null && depth < 4) return evalCmd(nested, depth + 1, st);
1070
+ return evalBin(bin, args, depth, st);
1071
+ }
1072
+
1073
+ function evalCmd(cmd, depth, parent) {
1074
+ const raw = fmtInput(cmd, 20000);
1075
+ if (!raw) return false;
1076
+ const st = { bound: new Set(parent?.bound || []), empty: new Set(parent?.empty || []) };
1077
+ for (const seg of splitSegs(raw)) {
1078
+ if (evalSeg(seg, depth, st)) return true;
1079
+ }
1080
+ return depth < 4 && extractSubs(raw).some((sub) => evalCmd(sub, depth + 1, st));
1081
+ }
1082
+
1083
+ function isDestructiveDeleteCommand(command) {
1084
+ return evalCmd(command, 0, null);
1085
+ }
1086
+
656
1087
  function classifyCommand(command) {
657
- const text = String(command || '').trim();
658
- const workflowRunMatch = text.match(/\bgh\s+workflow\s+run\s+([^\s]+)/i);
659
- const refMatch = text.match(/(?:--ref|-r)\s+([^\s]+)/i);
1088
+ const text = fmtInput(command, 100000);
1089
+ const workflowRunMatch = /\bgh\s+workflow\s+run\s+([^\s]+)/i.exec(text);
1090
+ const refMatch = /(?:--ref|-r)\s+([^\s]+)/i.exec(text);
660
1091
  const fieldArgs = [...text.matchAll(/(?:--field|-f)\s+([A-Za-z0-9_.-]+)=([^\s]+)/gi)]
661
1092
  .map((match) => ({ name: match[1], value: match[2] }));
662
1093
  return {
@@ -670,6 +1101,7 @@ function classifyCommand(command) {
670
1101
  isPublish: /\b(?:npm|yarn|pnpm)\s+publish\b/i.test(text),
671
1102
  isReleaseCreate: /\bgh\s+release\s+create\b/i.test(text),
672
1103
  isTagCreate: /\bgit\s+tag\b/i.test(text),
1104
+ isDestructiveDelete: isDestructiveDeleteCommand(command),
673
1105
  };
674
1106
  }
675
1107
 
@@ -991,6 +1423,7 @@ module.exports = {
991
1423
  assertSafeGitObjectId,
992
1424
  gitVerifyRef,
993
1425
  isSafeBranchName,
1426
+ isDestructiveDeleteCommand,
994
1427
  isSafeGitObjectId,
995
1428
  isSafeGitRevision,
996
1429
  isHeadReachableFrom,