@lornatang/dsh-caveman 0.1.0

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 (112) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +202 -0
  3. package/LICENSE-MIT +21 -0
  4. package/NOTICE +51 -0
  5. package/README.md +218 -0
  6. package/README.zh.md +218 -0
  7. package/cordis.patch.yml +3 -0
  8. package/examples/caveman-anthropic.patch.yml +14 -0
  9. package/examples/caveman-auto.patch.yml +15 -0
  10. package/lib/attribution.js +24 -0
  11. package/lib/blocks.js +80 -0
  12. package/lib/cavecrew-git.js +83 -0
  13. package/lib/cavecrew.js +67 -0
  14. package/lib/compression.js +434 -0
  15. package/lib/index.js +127 -0
  16. package/lib/memory.js +35 -0
  17. package/lib/mode.js +71 -0
  18. package/lib/native.js +357 -0
  19. package/lib/runtime.js +199 -0
  20. package/lib/skills.js +75 -0
  21. package/lib/stats.js +189 -0
  22. package/lib/types/attribution.d.ts +8 -0
  23. package/lib/types/blocks.d.ts +12 -0
  24. package/lib/types/cavecrew-git.d.ts +5 -0
  25. package/lib/types/cavecrew.d.ts +10 -0
  26. package/lib/types/compression.d.ts +50 -0
  27. package/lib/types/index.d.ts +30 -0
  28. package/lib/types/memory.d.ts +3 -0
  29. package/lib/types/mode.d.ts +33 -0
  30. package/lib/types/native.d.ts +43 -0
  31. package/lib/types/runtime.d.ts +23 -0
  32. package/lib/types/skills.d.ts +3 -0
  33. package/lib/types/stats.d.ts +6 -0
  34. package/package.json +129 -0
  35. package/presets/cavecrew.patch.yml +54 -0
  36. package/scripts/benchmark.mjs +79 -0
  37. package/scripts/caveman-cli.mjs +30 -0
  38. package/scripts/learn-binary.mjs +82 -0
  39. package/scripts/learn-checksums.json +29 -0
  40. package/vendor/caveman/LICENSE +202 -0
  41. package/vendor/caveman/LICENSE-MIT +21 -0
  42. package/vendor/caveman/NOTICE +49 -0
  43. package/vendor/caveman/agents/cavecrew-builder.md +46 -0
  44. package/vendor/caveman/agents/cavecrew-investigator.md +56 -0
  45. package/vendor/caveman/agents/cavecrew-reviewer.md +47 -0
  46. package/vendor/caveman/skills/activation-rule.mjs +43 -0
  47. package/vendor/caveman/skills/cavecrew/README.md +67 -0
  48. package/vendor/caveman/skills/cavecrew/SKILL.md +78 -0
  49. package/vendor/caveman/skills/caveman/README.md +68 -0
  50. package/vendor/caveman/skills/caveman/SKILL.md +89 -0
  51. package/vendor/caveman/skills/caveman-commit/README.md +44 -0
  52. package/vendor/caveman/skills/caveman-commit/SKILL.md +63 -0
  53. package/vendor/caveman/skills/caveman-compress/README.md +262 -0
  54. package/vendor/caveman/skills/caveman-compress/SECURITY.md +55 -0
  55. package/vendor/caveman/skills/caveman-compress/SKILL.md +114 -0
  56. package/vendor/caveman/skills/caveman-compress/scripts/__init__.py +9 -0
  57. package/vendor/caveman/skills/caveman-compress/scripts/__main__.py +3 -0
  58. package/vendor/caveman/skills/caveman-compress/scripts/benchmark.py +80 -0
  59. package/vendor/caveman/skills/caveman-compress/scripts/cli.py +94 -0
  60. package/vendor/caveman/skills/caveman-compress/scripts/compress.py +1331 -0
  61. package/vendor/caveman/skills/caveman-compress/scripts/detect.py +192 -0
  62. package/vendor/caveman/skills/caveman-compress/scripts/validate.py +440 -0
  63. package/vendor/caveman/skills/caveman-discover/SKILL.md +115 -0
  64. package/vendor/caveman/skills/caveman-evidence-review/SKILL.md +142 -0
  65. package/vendor/caveman/skills/caveman-explore/SKILL.md +42 -0
  66. package/vendor/caveman/skills/caveman-explore/package.json +12 -0
  67. package/vendor/caveman/skills/caveman-explore/tests/skill-file.test.mjs +44 -0
  68. package/vendor/caveman/skills/caveman-help/README.md +39 -0
  69. package/vendor/caveman/skills/caveman-help/SKILL.md +62 -0
  70. package/vendor/caveman/skills/caveman-learn/CLAUDE.md +32 -0
  71. package/vendor/caveman/skills/caveman-learn/README.md +38 -0
  72. package/vendor/caveman/skills/caveman-learn/SKILL.md +185 -0
  73. package/vendor/caveman/skills/caveman-learn/package.json +12 -0
  74. package/vendor/caveman/skills/caveman-learn/tests/index.js +1 -0
  75. package/vendor/caveman/skills/caveman-learn/tests/skill-file.test.mjs +54 -0
  76. package/vendor/caveman/skills/caveman-manage/SKILL.md +112 -0
  77. package/vendor/caveman/skills/caveman-optimize/SKILL.md +111 -0
  78. package/vendor/caveman/skills/caveman-review/README.md +33 -0
  79. package/vendor/caveman/skills/caveman-review/SKILL.md +53 -0
  80. package/vendor/caveman/skills/caveman-setup/SKILL.md +222 -0
  81. package/vendor/caveman/skills/caveman-stats/README.md +48 -0
  82. package/vendor/caveman/skills/caveman-stats/SKILL.md +17 -0
  83. package/vendor/caveman/skills/compile.mjs +298 -0
  84. package/vendor/caveman/skills/engine-mcp-tools.json +10 -0
  85. package/vendor/caveman/skills/generated/aider/pack.json +163 -0
  86. package/vendor/caveman/skills/generated/claude/pack.json +163 -0
  87. package/vendor/caveman/skills/generated/codex/pack.json +163 -0
  88. package/vendor/caveman/skills/generated/gemini/pack.json +163 -0
  89. package/vendor/caveman/skills/generated/hermes/pack.json +163 -0
  90. package/vendor/caveman/skills/generated/opencode/pack.json +163 -0
  91. package/vendor/caveman/skills/investigate-first/SKILL.md +16 -0
  92. package/vendor/caveman/skills/investigate-first/agents/openai.yaml +4 -0
  93. package/vendor/caveman/skills/lean-build/SKILL.md +18 -0
  94. package/vendor/caveman/skills/lean-build/agents/openai.yaml +4 -0
  95. package/vendor/caveman/skills/megacave/README.md +11 -0
  96. package/vendor/caveman/skills/megacave/SKILL.md +65 -0
  97. package/vendor/caveman/skills/migration/SKILL.md +17 -0
  98. package/vendor/caveman/skills/migration/agents/openai.yaml +4 -0
  99. package/vendor/caveman/skills/native/native-core.md +16 -0
  100. package/vendor/caveman/skills/registry.json +283 -0
  101. package/vendor/caveman/skills/safe-refactor/SKILL.md +16 -0
  102. package/vendor/caveman/skills/safe-refactor/agents/openai.yaml +4 -0
  103. package/vendor/caveman/skills/surgical-patch/SKILL.md +16 -0
  104. package/vendor/caveman/skills/surgical-patch/agents/openai.yaml +4 -0
  105. package/vendor/caveman/skills/ultracave/README.md +13 -0
  106. package/vendor/caveman/skills/ultracave/SKILL.md +63 -0
  107. package/vendor/caveman/skills/verbs-gate.mjs +213 -0
  108. package/vendor/caveman/skills/verify-and-stop/SKILL.md +16 -0
  109. package/vendor/caveman/skills/verify-and-stop/agents/openai.yaml +4 -0
  110. package/vendor/caveman/src/hooks/caveman-config.js +921 -0
  111. package/vendor/caveman/src/hooks/caveman-parse.js +342 -0
  112. package/vendor/caveman/src/hooks/package.json +3 -0
@@ -0,0 +1,342 @@
1
+ #!/usr/bin/env node
2
+ // caveman — shared mode-change parser (#602)
3
+ //
4
+ // Single source of truth for interpreting a user prompt as a caveman mode
5
+ // change. Extracted from caveman-mode-tracker.js so the Claude Code hook and
6
+ // the opencode plugin can't drift out of sync with each other. The tracker's
7
+ // regexes are the reference behavior — every pattern below is copied from it
8
+ // verbatim; don't tighten or loosen a match here without a matching change
9
+ // (and test) on the tracker side.
10
+ //
11
+ // parseModeChange(prompt, { getDefaultMode, skipNaturalLanguage, expandedTpl, unwrapQuotes })
12
+ // → { action: 'set', mode } — caller should activate `mode`
13
+ // → { action: 'clear' } — caller should deactivate (delete the flag)
14
+ // → { action: 'status' } — report the current mode without changing state
15
+ // → null — prompt does not change state
16
+ //
17
+ // Options:
18
+ // getDefaultMode — required; () => resolved default mode string.
19
+ // Injected rather than required directly so the
20
+ // caller controls resolution (cwd, env, etc.).
21
+ // skipNaturalLanguage — when true, skip deactivation/activation/brevity
22
+ // phrase matching entirely. Set this for prompt text
23
+ // that isn't the user's own words (e.g. a foreign
24
+ // slash-command envelope's <command-args>), so
25
+ // another command's arguments can't misfire our
26
+ // triggers.
27
+ // expandedTpl — when true, also recognize opencode's expanded
28
+ // command-template bodies (a typed "/ultracave"
29
+ // gets replaced by the command file's prose before
30
+ // this parser ever sees it). Claude Code prompts
31
+ // never take this shape, so Claude Code callers
32
+ // should leave this off.
33
+ // unwrapQuotes — when true, strip a single layer of matching quote
34
+ // characters wrapping the whole prompt (opencode's
35
+ // non-interactive `run` path delivers messages this
36
+ // way).
37
+
38
+ // Sibling require that tolerates the opencode install layout, where this
39
+ // file is copied next to a renamed `caveman-config.cjs` (the plugin dir is
40
+ // "type": "module", so a bare `.js` sibling would load as ESM). A plain
41
+ // `require('./caveman-config')` only auto-resolves the `.js` extension, so
42
+ // try that first (dev tree, standalone hook install) and fall back to the
43
+ // explicit `.cjs` name.
44
+ let cavemanConfig;
45
+ try {
46
+ cavemanConfig = require('./caveman-config');
47
+ } catch (e) {
48
+ cavemanConfig = require('./caveman-config.cjs');
49
+ }
50
+ const { VALID_MODES } = cavemanConfig;
51
+ // Maps the legacy level names (`/caveman ultra`, `/caveman wenyan-lite`, ...)
52
+ // onto the three skills. The stand-in covers a config module from before the
53
+ // three-skill model (#848 plugin-cache drift): current ids only.
54
+ const canonicalMode = cavemanConfig.canonicalMode
55
+ || ((m) => (VALID_MODES.includes(m) ? m : null));
56
+
57
+ // Each prose mode has its own command, bare or plugin-namespaced.
58
+ const MODE_COMMANDS = {
59
+ '/ultracave': 'ultracave', '/caveman:ultracave': 'ultracave',
60
+ '/megacave': 'megacave', '/caveman:megacave': 'megacave',
61
+ };
62
+
63
+ // Modes handled by their own slash commands (/caveman-commit, etc.) — not
64
+ // selectable via /caveman <arg>.
65
+ const INDEPENDENT_MODES = new Set(['commit', 'review', 'compress']);
66
+
67
+ // Natural-language triggers run over the whole prompt, so any pasted text that
68
+ // merely QUOTES them fired them — a bug report quoting the /caveman-help card's
69
+ // own line ("Say \"stop caveman\" or \"normal mode\".") switched caveman off
70
+ // mid-task (#838). #537's envelope unwrap closed the slash-command path; this
71
+ // is the prose path, which needs no envelope.
72
+ //
73
+ // Blank quoted spans before matching. A prompt-length cap looked like the fix
74
+ // and is worse on both sides: it still fires on any short quoted line, and it
75
+ // silently breaks the compound instructions people actually type ("turn off
76
+ // caveman and write the release notes for ..."). That failure is the dangerous
77
+ // direction — a false activation is a nuisance, but a deactivation that is
78
+ // dropped in silence leaves the user unable to escape the mode with no
79
+ // feedback explaining why.
80
+ //
81
+ // Only " and ` count as delimiters. Apostrophes are far too common in ordinary
82
+ // English ("don't stop caveman, it's useful") and pairing on them would blank
83
+ // the command itself.
84
+ const QUOTED_SPAN_REGEX = /(["`])(?:(?!\1).)*\1/g;
85
+
86
+ // A mode argument with punctuation glued to it ("/caveman ultra; still too
87
+ // verbose") matched no mode, left the mode untouched, and said nothing. Only
88
+ // parts[1] is ever read, so extra WORDS after the mode were already harmless;
89
+ // it is the trailing character that broke it. Modes are [a-z-] only, so
90
+ // stripping every trailing character outside that class is safe.
91
+ // Trailing punctuation only. A leading quote or bracket is stripped too so
92
+ // `/caveman "ultra"` resolves — asymmetric handling would leave a second,
93
+ // equally silent failure right next to the one being fixed.
94
+ // The span between an activation verb and "caveman" used to be any 40
95
+ // characters (`[^.]{0,40}`), which made ordinary prose an activation command:
96
+ // "i want to start building a caveman-themed game" is `want` … `caveman` with
97
+ // nothing but prose in between (#187). Real activation phrases only ever put
98
+ // determiners and particles in that gap ("turn on THE caveman mode", "switch
99
+ // TO caveman"), so the gap is a whitelist now rather than a length budget.
100
+ //
101
+ // "a"/"an" are deliberately absent. No genuine activation phrase needs one,
102
+ // and admitting them is exactly what makes "start a caveman fire" read as a
103
+ // command — the question guard catches that phrasing only while it happens to
104
+ // be spelled as a question.
105
+ const ACTIVATION_VERBS = '(?:activate|enable|start|turn on|use|switch to|want|give me)';
106
+ const ACTIVATION_GAP = '(?:\\s+(?:the|to|into|on|in|please|now|it|me|my|this|that|mode))*';
107
+ const ACTIVATION_VERB_PHRASE = new RegExp(
108
+ '\\b' + ACTIVATION_VERBS + '\\b' + ACTIVATION_GAP + '\\s+caveman\\b'
109
+ );
110
+ // "talk like caveman" / "talk like a caveman" — same tightening, but this one
111
+ // keeps the article: it is the idiomatic form of the phrase.
112
+ const ACTIVATION_TALK_LIKE = /\btalk\s+like\s+(?:a\s+|an\s+|the\s+)?caveman\b/;
113
+
114
+ // A negated activation is not an activation ("don't activate caveman"). This
115
+ // guard is deliberately ASYMMETRIC — the deactivation side keeps firing on
116
+ // "don't stop caveman", per the committed behavior in #838: a dropped
117
+ // deactivation is silent and leaves the user unable to escape the mode, while
118
+ // a spurious one costs a single "/caveman" to undo.
119
+ const NEGATOR = /\b(?:don['’]?t|do not|doesn['’]?t|does not|won['’]?t|will not|never|no need to|rather not)\b/;
120
+
121
+ // The negator does not reliably sit next to the verb it negates. In "don't
122
+ // want you to use caveman" it attaches to `want`, while the trigger that
123
+ // actually matches is the `use` inside the complement clause — so a fixed
124
+ // "negator, then up to N words, then the verb" window misses it, and widening
125
+ // that window far enough to catch it starts swallowing unrelated text.
126
+ //
127
+ // Scope the guard to the CLAUSE instead: a trigger is negated when a negator
128
+ // appears between the last clause boundary and the trigger itself. That is
129
+ // what keeps a later independent command alive — in "don't use vim, activate
130
+ // caveman" the comma ends the negated clause, so the activation still stands.
131
+ // Dashes and colons separate clauses the same way a comma does ("never mind
132
+ // the linter — turn on caveman"), so they end a negated clause too.
133
+ const CLAUSE_BOUNDARY = /[.;!?,:—–]|\s-+\s|\bbut\b|\bthen\b/g;
134
+
135
+ function negatedBefore(text, index) {
136
+ CLAUSE_BOUNDARY.lastIndex = 0;
137
+ let clauseStart = 0;
138
+ let m;
139
+ while ((m = CLAUSE_BOUNDARY.exec(text)) !== null) {
140
+ if (m.index >= index) break;
141
+ clauseStart = m.index + m[0].length;
142
+ }
143
+ return NEGATOR.test(text.slice(clauseStart, index));
144
+ }
145
+
146
+ // Every phrasing that means "switch caveman on". Kept as one list so the
147
+ // negation check applies uniformly — a guard on only the verb form would let
148
+ // "don't put caveman mode on" through.
149
+ const BREVITY_TRIGGER = /\b(less tokens|fewer tokens|be brief|be terse|shorter answers)\b(?!\s+(in|for|on|about|when|during|with)\b)/;
150
+ const ACTIVATION_TRIGGERS = [
151
+ ACTIVATION_VERB_PHRASE,
152
+ ACTIVATION_TALK_LIKE,
153
+ /\bcaveman\s+mode\s+(on|please|now)\b/,
154
+ /^caveman(\s+mode)?\s*[.!]*$/,
155
+ BREVITY_TRIGGER,
156
+ ].map(re => new RegExp(re.source, re.flags.includes('g') ? re.flags : re.flags + 'g'));
157
+
158
+ // True when any trigger matches outside a negated clause. Every match is
159
+ // examined, not just the first: the first may be negated while a later,
160
+ // independent one is not.
161
+ function wantsActivation(text) {
162
+ for (const re of ACTIVATION_TRIGGERS) {
163
+ re.lastIndex = 0;
164
+ let m;
165
+ while ((m = re.exec(text)) !== null) {
166
+ if (!negatedBefore(text, m.index)) return true;
167
+ if (m.index === re.lastIndex) re.lastIndex++;
168
+ }
169
+ }
170
+ return false;
171
+ }
172
+
173
+ function normalizeModeArg(arg) {
174
+ return (arg || '').replace(/^[^a-z0-9]+/, '').replace(/[^a-z0-9-]+$/, '');
175
+ }
176
+
177
+ // Resolve a /caveman argument to a verdict. An argument that resolves to
178
+ // nothing returns 'unresolved' rather than null, so the caller can say so
179
+ // instead of failing silently. 'unresolved' is additive: applyModeChange in the
180
+ // opencode plugin acts only on 'set'/'clear' and ignores anything else.
181
+ function resolveModeArg(rawArg, getDefaultMode) {
182
+ const arg = normalizeModeArg(rawArg);
183
+ if (!arg) {
184
+ // Only a genuinely ABSENT argument means "bare /caveman → activate at the
185
+ // default". An argument that was present but normalized away is punctuation
186
+ // like `/caveman ?` — plausibly someone asking for help, who should not be
187
+ // switched into the mode by it.
188
+ if (rawArg) return { action: 'unresolved' };
189
+ const configured = getDefaultMode();
190
+ const mode = configured === 'manual' ? 'caveman' : configured;
191
+ return mode === 'off' ? { action: 'clear' } : { action: 'set', mode };
192
+ }
193
+ if (arg === 'off' || arg === 'stop' || arg === 'disable') return { action: 'clear' };
194
+ if (arg === 'status') return { action: 'status' };
195
+ // An independent mode IS a real mode, just not reachable this way. Saying
196
+ // "not recognized" would deny a mode the user can see in the docs; name its
197
+ // own command instead. Echoing `arg` here is safe precisely because it
198
+ // matched this fixed whitelist — it is no longer free-form user text.
199
+ if (INDEPENDENT_MODES.has(arg)) return { action: 'unresolved', independentMode: arg };
200
+ // caveman/ultracave/megacave, or a legacy level name mapped onto one.
201
+ const mode = canonicalMode(arg);
202
+ if (mode && mode !== 'off') return { action: 'set', mode };
203
+ // Bogus argument: never silently overwrite with the default (#602). The
204
+ // rejected string is untrusted input and is deliberately NOT echoed back —
205
+ // it would land in model context.
206
+ return { action: 'unresolved' };
207
+ }
208
+
209
+ function parseModeChange(promptRaw, options) {
210
+ options = options || {};
211
+ const getDefaultMode = options.getDefaultMode || cavemanConfig.getDefaultMode;
212
+
213
+ let prompt = (promptRaw || '').trim();
214
+ if (options.unwrapQuotes) {
215
+ const wrapped = /^(["'`])([\s\S]*)\1$/.exec(prompt);
216
+ if (wrapped) prompt = wrapped[2].trim();
217
+ }
218
+ // Capture the first line before whitespace collapse. The expandedTpl
219
+ // templates (opencode's commands/caveman.md etc.) put $ARGUMENTS at the end
220
+ // of the first line, followed by a blank line and then fixed boilerplate
221
+ // ("If no argument given, use caveman. If \"off\", deactivate."). Collapsing
222
+ // all whitespace to single spaces (below) merges an EMPTY argument directly
223
+ // into that boilerplate, so a bare `/caveman` with no argument looked like
224
+ // the argument was the word "if" and got rejected as bogus. Extract the
225
+ // template argument from this uncollapsed first line instead.
226
+ const firstLine = prompt.toLowerCase().split(/\r?\n/, 1)[0];
227
+ // Collapse whitespace so phrase triggers still match multiline prompts —
228
+ // every regex below expects a single-line prompt (#598).
229
+ prompt = prompt.toLowerCase().replace(/\s+/g, ' ');
230
+ if (!prompt) return null;
231
+
232
+ // Deactivation intent — computed FIRST so "turn caveman mode off" never
233
+ // falls through to the activation patterns (#598), and applied with the
234
+ // highest priority: it's what the tracker's original unconditional
235
+ // end-of-function deactivation check amounted to.
236
+ // Matched against nlPrompt (quoted spans blanked, see QUOTED_SPAN_REGEX) so a
237
+ // prompt that CITES a trigger does not fire it. A prompt that starts with a
238
+ // slash is a command invocation: its own text must not toggle our mode,
239
+ // symmetric with the skipNaturalLanguage a foreign command envelope sets.
240
+ // opencode's expanded /caveman-help card lists the commands and quotes the
241
+ // triggers; its prose ("Activate caveman" once the backtick span is blanked)
242
+ // must not switch the mode. Checked before every trigger, deactivation too.
243
+ if (options.expandedTpl && /^show the caveman quick-reference card\b/.test(prompt)) return null;
244
+
245
+ const naturalLanguage = !options.skipNaturalLanguage && !prompt.startsWith('/');
246
+ const nlPrompt = naturalLanguage ? prompt.replace(QUOTED_SPAN_REGEX, ' ') : '';
247
+
248
+ const wantsOff = naturalLanguage && (
249
+ /\b(stop|disable|deactivate|quit|exit|kill)\s+(the\s+)?caveman\b/.test(nlPrompt) ||
250
+ /\bcaveman(\s+mode)?\s+(off|stop|disabled?)\b/.test(nlPrompt) ||
251
+ /\bturn\s+off\s+(the\s+)?caveman\b/.test(nlPrompt) ||
252
+ // "normal mode" only as a command (prompt-initial, optionally led by a
253
+ // switch-back verb) or with caveman context — never mid-sentence for
254
+ // e.g. vim's normal mode ("how do I exit vim normal mode").
255
+ /^(please\s+)?(go\s+(back\s+)?(to\s+)?|back\s+to\s+|switch\s+(back\s+)?to\s+|return\s+to\s+)?normal\s+mode\b/.test(nlPrompt) ||
256
+ (/\bnormal\s+mode\b/.test(nlPrompt) && /\bcaveman\b/.test(nlPrompt))
257
+ );
258
+ if (wantsOff) return { action: 'clear' };
259
+
260
+ // opencode expands a typed "/caveman <arg>", "/ultracave", "/megacave" (and
261
+ // the independent-mode commands) into the command file's prose before
262
+ // chat.message fires, so the literal slash-command branch below never sees
263
+ // the original text. Recover the mode from each template's fixed prefix
264
+ // instead. This MUST run before the generic NL-activation match below:
265
+ // "Activate caveman mode: ultra" would otherwise trip the "activate ...
266
+ // caveman" trigger and swallow the argument, activating at the default
267
+ // instead (#602). Claude Code prompts never take this shape, so gate behind
268
+ // expandedTpl (opencode-only).
269
+ if (options.expandedTpl) {
270
+ if (/^generate a commit message for the current staged changes\b/.test(prompt)) {
271
+ return { action: 'set', mode: 'commit' };
272
+ }
273
+ if (/^review the current diff\b/.test(prompt)) {
274
+ return { action: 'set', mode: 'review' };
275
+ }
276
+ if (/^compress the file at:/.test(prompt)) {
277
+ return { action: 'set', mode: 'compress' };
278
+ }
279
+ const own = /^activate (ultracave|megacave) mode\b/.exec(prompt);
280
+ if (own) return { action: 'set', mode: own[1] };
281
+ const tpl = /^activate caveman mode:[ \t]*(\S*)/.exec(firstLine);
282
+ if (tpl) return resolveModeArg(tpl[1], getDefaultMode);
283
+ }
284
+
285
+ if (naturalLanguage) {
286
+ // Questions about caveman are not activation commands
287
+ // ("what is caveman mode?", "does caveman lite drop articles?").
288
+ const isQuestion =
289
+ /^(what|whats|what's|how|why|when|where|who|does|do|did|is|are|can|could|would|should|tell me|explain)\b/.test(nlPrompt);
290
+
291
+ // Natural language activation (e.g. "activate caveman", "turn on caveman
292
+ // mode", "talk like caveman"). Also brevity requests ("less tokens",
293
+ // "be brief/terse", "fewer tokens", "shorter answers") — but not when
294
+ // scoped to a single section ("be brief in the summary"), which is a
295
+ // one-off instruction, not a session-wide mode switch.
296
+ if (!isQuestion) {
297
+ if (wantsActivation(nlPrompt)) {
298
+ const configured = getDefaultMode();
299
+ const mode = configured === 'manual' ? 'caveman' : configured;
300
+ // Mirrors the tracker exactly: a configured-off default makes this a
301
+ // no-op (leave whatever flag state already exists), NOT a clear —
302
+ // that's only what an explicit "/caveman" bare command does.
303
+ return mode !== 'off' ? { action: 'set', mode } : null;
304
+ }
305
+ }
306
+ }
307
+
308
+ // Match /caveman commands. Marketplace plugin installs surface commands
309
+ // namespaced as /caveman:caveman-<name> — accept both forms for every
310
+ // skill (#599: only compress and stats had the namespaced variant).
311
+ const parts = prompt.split(/\s+/);
312
+ const cmd = parts[0]; // /caveman, /ultracave, /caveman-commit, etc.
313
+ if (Object.prototype.hasOwnProperty.call(MODE_COMMANDS, cmd)) {
314
+ // Same off/status words /caveman takes; anything else is just the mode.
315
+ const arg = normalizeModeArg(parts[1]);
316
+ if (arg === 'off' || arg === 'stop' || arg === 'disable') return { action: 'clear' };
317
+ if (arg === 'status') return { action: 'status' };
318
+ return { action: 'set', mode: MODE_COMMANDS[cmd] };
319
+ }
320
+ if (prompt.startsWith('/caveman')) {
321
+ const arg = parts[1] || '';
322
+
323
+ if (cmd === '/caveman-commit' || cmd === '/caveman:caveman-commit') {
324
+ return { action: 'set', mode: 'commit' };
325
+ }
326
+ if (cmd === '/caveman-review' || cmd === '/caveman:caveman-review') {
327
+ return { action: 'set', mode: 'review' };
328
+ }
329
+ if (cmd === '/caveman-compress' || cmd === '/caveman:caveman-compress') {
330
+ return { action: 'set', mode: 'compress' };
331
+ }
332
+ if (cmd === '/caveman' || cmd === '/caveman:caveman') {
333
+ // Bare /caveman → activate at configured default; otherwise resolve the
334
+ // argument (punctuation-tolerant, bogus values reported not swallowed).
335
+ return resolveModeArg(arg, getDefaultMode);
336
+ }
337
+ }
338
+
339
+ return null;
340
+ }
341
+
342
+ module.exports = { parseModeChange, INDEPENDENT_MODES };
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }