@se-studio/skills 1.9.20 → 1.10.4

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.
@@ -0,0 +1,399 @@
1
+ /**
2
+ * Agent-neutral guard rules. Pure functions: no git, no fs, no process state.
3
+ * Entry points (git hooks, Claude Code adapter) live next to this file and call these.
4
+ *
5
+ * Overrides are read only from the *human's* environment (never from the command
6
+ * text an agent writes), so an agent cannot unlock a guard by prefixing a variable.
7
+ *
8
+ * Enforcement vs advice: checkCommit/checkPush run in git hooks and are the real
9
+ * guard (CI audits the rest). classifyShellCommand runs in an agent hook before a
10
+ * command executes; it reads the command text, so a script or alias that runs git
11
+ * out of sight gets past it. It stops the mistakes agents actually make.
12
+ */
13
+
14
+ import path from 'node:path';
15
+ import { scan } from './shell.mjs';
16
+
17
+ /** Branches nobody commits to directly: work happens on feature/* in a worktree. */
18
+ export const PROTECTED_COMMIT_BRANCHES = ['main', 'master', 'production', 'dev', 'develop'];
19
+
20
+ /** Production branches: pushing needs the human (AGENTS.md: ask + confirm). */
21
+ export const PROTECTED_PUSH_BRANCHES = ['main', 'master', 'production'];
22
+
23
+ export const OVERRIDE_COMMIT = 'SE_ALLOW_PROTECTED_COMMIT';
24
+ export const OVERRIDE_PUSH = 'SE_ALLOW_PROTECTED_PUSH';
25
+ export const OVERRIDE_PRIMARY_EDIT = 'SE_ALLOW_PRIMARY_EDIT';
26
+
27
+ const ZERO_SHA = /^0+$/;
28
+ const MAX_DEPTH = 5;
29
+
30
+ function isOn(env, name) {
31
+ return env[name] === '1';
32
+ }
33
+
34
+ /** CI runs the same checks as audits; the hooks are for local laptops. */
35
+ function inCi(env) {
36
+ return Boolean(env.CI) && env.CI !== 'false';
37
+ }
38
+
39
+ function branchOfRef(ref) {
40
+ return ref.startsWith('refs/heads/') ? ref.slice('refs/heads/'.length) : null;
41
+ }
42
+
43
+ /** @returns {{ ok: true } | { ok: false, reason: string }} */
44
+ export function checkCommit({ branch, env = {} }) {
45
+ if (inCi(env) || isOn(env, OVERRIDE_COMMIT)) return { ok: true };
46
+ if (branch && PROTECTED_COMMIT_BRANCHES.includes(branch)) {
47
+ return {
48
+ ok: false,
49
+ reason:
50
+ `Refusing to commit directly on "${branch}". ` +
51
+ 'Create a worktree and a feature/<scope>/<slug> branch (see AGENTS.md, "Parallel features"). ' +
52
+ `If the user explicitly asked to work in place, they can set ${OVERRIDE_COMMIT}=1.`,
53
+ };
54
+ }
55
+ return { ok: true };
56
+ }
57
+
58
+ /**
59
+ * @param {string} stdin pre-push stdin: "<local ref> <local sha> <remote ref> <remote sha>" per line
60
+ * @returns {{ ok: true } | { ok: false, reason: string }}
61
+ */
62
+ export function checkPush({ stdin, env = {} }) {
63
+ if (inCi(env) || isOn(env, OVERRIDE_PUSH)) return { ok: true };
64
+ const blocked = [];
65
+ for (const line of stdin.split('\n')) {
66
+ const [, localSha, remoteRef] = line.trim().split(/\s+/);
67
+ if (!remoteRef) continue;
68
+ const branch = branchOfRef(remoteRef);
69
+ if (branch && PROTECTED_PUSH_BRANCHES.includes(branch)) {
70
+ blocked.push(localSha && ZERO_SHA.test(localSha) ? `delete ${branch}` : branch);
71
+ }
72
+ }
73
+ if (blocked.length === 0) return { ok: true };
74
+ return {
75
+ ok: false,
76
+ reason:
77
+ `Refusing to push to production branch(es): ${blocked.join(', ')}. ` +
78
+ 'Promotion needs the user to ask for it and confirm (AGENTS.md, "Production"). ' +
79
+ `The user can allow one push with ${OVERRIDE_PUSH}=1.`,
80
+ };
81
+ }
82
+
83
+ // --- shell command classification -------------------------------------------------
84
+
85
+ const ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
86
+ const SHELLS = new Set(['sh', 'bash', 'zsh', 'dash', 'ksh']);
87
+ /** Shell keywords that precede a command word (`if x; then git ...`, `! git ...`). */
88
+ const KEYWORDS = new Set(['!', 'if', 'then', 'else', 'elif', 'do', 'while', 'until', 'coproc']);
89
+ const REDIRECTION = /^\d*(?:>>?|<|>&|&>)/;
90
+ const REDIRECTION_ONLY = /^\d*(?:>>?|<|>&|&>)$/;
91
+ /** Wrappers that run the next word as a command, with the flags that take a value. */
92
+ const WRAPPERS = {
93
+ env: ['-u', '-C', '-S'],
94
+ command: [],
95
+ builtin: [],
96
+ time: ['-f', '-o'],
97
+ nohup: [],
98
+ exec: ['-a'],
99
+ sudo: ['-u', '-g', '-h', '-p', '-C', '-U'],
100
+ nice: ['-n'],
101
+ stdbuf: ['-i', '-o', '-e'],
102
+ xargs: ['-I', '-n', '-L', '-P', '-s', '-d', '-E', '-a', '-R', '-S'],
103
+ npx: ['-p', '--package'],
104
+ bunx: [],
105
+ };
106
+ const GIT_GLOBAL_VALUE_FLAGS = [
107
+ '-C',
108
+ '-c',
109
+ '--git-dir',
110
+ '--work-tree',
111
+ '--namespace',
112
+ '--exec-path',
113
+ '--super-prefix',
114
+ '--config-env',
115
+ ];
116
+ const PUSH_VALUE_FLAGS = ['-o', '--push-option', '--repo', '--receive-pack', '--exec'];
117
+ const MERGE_VALUE_FLAGS = [
118
+ '-R',
119
+ '--repo',
120
+ '-t',
121
+ '--subject',
122
+ '-b',
123
+ '--body',
124
+ '-F',
125
+ '--body-file',
126
+ '-A',
127
+ '--author-email',
128
+ '--match-head-commit',
129
+ ];
130
+ /** Short options of `git commit` that consume the rest of the cluster or the next word. */
131
+ const COMMIT_VALUE_SHORTS = new Set(['m', 'F', 'C', 'c', 't', 'S', 'u']);
132
+ const DEPLOY_SCRIPT = /(^|\/)(cms-edit:deploy|deploy-cms-edit-host\.sh)$/;
133
+ const VERCEL_NON_DEPLOY = new Set(['-v', '--version', '-h', '--help']);
134
+
135
+ function skipFlags(args, valueFlags) {
136
+ let i = 0;
137
+ while (i < args.length && args[i].startsWith('-') && args[i] !== '-') {
138
+ if (args[i] === '--') {
139
+ i++;
140
+ break;
141
+ }
142
+ i += valueFlags.includes(args[i]) ? 2 : 1;
143
+ }
144
+ return args.slice(i);
145
+ }
146
+
147
+ /** Strip assignments and wrappers (env, xargs, npx, pnpm dlx, sh -c, eval) off an argv. */
148
+ function unwrap(argv, nested, notes) {
149
+ let args = [...argv];
150
+ for (;;) {
151
+ while (args.length && (ASSIGNMENT.test(args[0]) || KEYWORDS.has(args[0]))) args.shift();
152
+ while (args.length && REDIRECTION.test(args[0]))
153
+ args.splice(0, REDIRECTION_ONLY.test(args[0]) ? 2 : 1);
154
+ if (args.length === 0) return args;
155
+ const bin = path.basename(args[0]);
156
+ if (bin in WRAPPERS) {
157
+ args = skipFlags(args.slice(1), WRAPPERS[bin]);
158
+ } else if ((bin === 'pnpm' || bin === 'yarn') && ['dlx', 'exec'].includes(args[1])) {
159
+ args = skipFlags(args.slice(2), []);
160
+ } else if (bin === 'npm' && args[1] === 'exec') {
161
+ args = skipFlags(args.slice(2), ['-c']);
162
+ } else if (SHELLS.has(bin)) {
163
+ const rest = args.slice(1);
164
+ const flagIdx = rest.findIndex((a) => /^-[a-zA-Z]*c[a-zA-Z]*$/.test(a));
165
+ if (flagIdx < 0) {
166
+ // `bash script.sh ...` keeps its words so the script name is checked; a shell with no
167
+ // script reads commands from a pipe, heredoc or process substitution we cannot see.
168
+ if (!rest.some((a) => !a.startsWith('-') && !REDIRECTION.test(a))) {
169
+ notes.push(
170
+ 'A shell is reading commands from input that cannot be checked; confirm with the user.',
171
+ );
172
+ return [];
173
+ }
174
+ return args;
175
+ }
176
+ if (rest[flagIdx + 1] !== undefined) nested.push(rest[flagIdx + 1]);
177
+ return [];
178
+ } else if (bin === 'eval') {
179
+ nested.push(args.slice(1).join(' '));
180
+ return [];
181
+ } else {
182
+ return args;
183
+ }
184
+ }
185
+ }
186
+
187
+ /** Words we cannot resolve statically: substitutions and globs in a push argument. */
188
+ const UNRESOLVABLE = /[$`*]/;
189
+
190
+ function pushTargetsProduction(rest, currentBranch) {
191
+ const positional = [];
192
+ let repoFlag = false;
193
+ for (let i = 0; i < rest.length; i++) {
194
+ if (rest[i] === '--all' || rest[i] === '--mirror') return true; // includes every production branch
195
+ if (rest[i].startsWith('-')) {
196
+ if (rest[i] === '--repo' || rest[i].startsWith('--repo=')) repoFlag = true;
197
+ if (PUSH_VALUE_FLAGS.includes(rest[i])) i++;
198
+ } else {
199
+ positional.push(rest[i]);
200
+ }
201
+ }
202
+ // positional[0] is the remote unless --repo named it; the rest are refspecs.
203
+ const refspecs = repoFlag ? positional : positional.slice(1);
204
+ if (refspecs.length === 0) {
205
+ return Boolean(currentBranch) && PROTECTED_PUSH_BRANCHES.includes(currentBranch);
206
+ }
207
+ return refspecs.some((spec) => {
208
+ const dest = spec.includes(':') ? spec.split(':').pop() : spec;
209
+ const name = dest.replace(/^\+/, '').replace(/^refs\/heads\//, '');
210
+ return PROTECTED_PUSH_BRANCHES.includes(name);
211
+ });
212
+ }
213
+
214
+ /** `-n` anywhere in a short-flag cluster before a value-taking flag means --no-verify. */
215
+ function commitSkipsHooks(rest) {
216
+ for (let i = 0; i < rest.length; i++) {
217
+ const arg = rest[i];
218
+ if (arg === '--no-verify') return true;
219
+ if (arg === '--message' || arg === '--file') {
220
+ i++;
221
+ continue;
222
+ }
223
+ if (/^-[a-zA-Z]+$/.test(arg)) {
224
+ for (const ch of arg.slice(1)) {
225
+ if (ch === 'n') return true;
226
+ if (COMMIT_VALUE_SHORTS.has(ch)) {
227
+ if (ch === arg[arg.length - 1]) i++; // value is the next word
228
+ break;
229
+ }
230
+ }
231
+ }
232
+ }
233
+ return false;
234
+ }
235
+
236
+ function classifyGit(argv, ctx, escalate) {
237
+ let i = 1;
238
+ while (i < argv.length && argv[i].startsWith('-')) {
239
+ const flag = argv[i];
240
+ if (/^(-c|--config)/.test(flag) && /core\.hookspath/i.test(`${flag} ${argv[i + 1] ?? ''}`)) {
241
+ escalate(
242
+ 'deny',
243
+ 'Do not bypass git hooks (core.hooksPath override). Fix the failing check instead.',
244
+ );
245
+ }
246
+ i += GIT_GLOBAL_VALUE_FLAGS.includes(flag) ? 2 : 1;
247
+ }
248
+ const sub = argv[i];
249
+ const rest = argv.slice(i + 1);
250
+
251
+ if (
252
+ ['commit', 'push', 'merge'].includes(sub) &&
253
+ (rest.includes('--no-verify') || (sub === 'commit' && commitSkipsHooks(rest)))
254
+ ) {
255
+ escalate('deny', 'Do not bypass git hooks (--no-verify). Fix the failing check instead.');
256
+ }
257
+ if (sub === 'push') {
258
+ if (pushTargetsProduction(rest, ctx.currentBranch) && !isOn(ctx.env, OVERRIDE_PUSH)) {
259
+ escalate(
260
+ 'deny',
261
+ 'Pushing to a production branch needs the user to ask and confirm in this conversation. Stop and ask; do not retry.',
262
+ );
263
+ } else if (rest.some((a) => !a.startsWith('-') && UNRESOLVABLE.test(a))) {
264
+ escalate(
265
+ 'ask',
266
+ 'A push argument contains a substitution or glob that cannot be resolved here; confirm the target with the user.',
267
+ );
268
+ } else if (rest.includes('--force') || rest.includes('-f')) {
269
+ escalate('ask', 'Force-push rewrites remote history; confirm with the user.');
270
+ }
271
+ }
272
+ }
273
+
274
+ function classifyGh(argv, merges, escalate) {
275
+ let repo;
276
+ let i = 1;
277
+ while (i < argv.length && argv[i].startsWith('-')) {
278
+ if (argv[i] === '-R' || argv[i] === '--repo') repo = argv[i + 1];
279
+ i += ['-R', '--repo'].includes(argv[i]) ? 2 : 1;
280
+ }
281
+ const [area, action, ...rest] = argv.slice(i);
282
+ if (area === 'pr' && action === 'merge') {
283
+ let target;
284
+ let strategy = false;
285
+ for (let j = 0; j < rest.length; j++) {
286
+ const arg = rest[j];
287
+ if (arg.startsWith('--')) {
288
+ const name = arg.split('=')[0];
289
+ if (name === '--squash' || name === '--rebase') strategy = true;
290
+ if (name === '--repo' || name === '-R')
291
+ repo = arg.includes('=') ? arg.split('=')[1] : rest[j + 1];
292
+ if (MERGE_VALUE_FLAGS.includes(name) && !arg.includes('=')) j++;
293
+ } else if (/^-[A-Za-z]+$/.test(arg)) {
294
+ // A short cluster such as -sd: scan until a flag that takes a value, which ends the cluster.
295
+ for (const ch of arg.slice(1)) {
296
+ if (ch === 's' || ch === 'r') strategy = true;
297
+ if (MERGE_VALUE_FLAGS.includes(`-${ch}`)) {
298
+ if (ch === 'R' && arg.endsWith('R')) repo = rest[j + 1];
299
+ if (arg.endsWith(ch)) j++;
300
+ break;
301
+ }
302
+ }
303
+ } else if (target === undefined) {
304
+ target = arg;
305
+ }
306
+ }
307
+ merges.push({ target, repo });
308
+ if (strategy) {
309
+ escalate(
310
+ 'deny',
311
+ 'Merge with merge commits only: `gh pr merge <n> --merge --match-head-commit <sha>` (AGENTS.md, "How to merge"). Never squash or rebase.',
312
+ );
313
+ }
314
+ escalate(
315
+ 'ask',
316
+ 'Merging needs a `## Merge approval` PR comment at the head SHA and a real review (AGENTS.md). Confirm both exist.',
317
+ );
318
+ } else if (area === 'api' && argv.some((a) => /pulls\/[^/\s]+\/merge|mergePullRequest/.test(a))) {
319
+ escalate(
320
+ 'deny',
321
+ 'Merge through `gh pr merge` so the merge gate can check the PR; do not call the merge API directly.',
322
+ );
323
+ }
324
+ }
325
+
326
+ /**
327
+ * Classify a shell command an agent is about to run.
328
+ * @returns {{ decision: 'allow' | 'ask' | 'deny', reason?: string, merges: { target?: string, repo?: string }[] }}
329
+ */
330
+ export function classifyShellCommand(command, { currentBranch = null, env = {} } = {}, depth = 0) {
331
+ const ctx = { currentBranch, env };
332
+ let result = { decision: 'allow' };
333
+ const merges = [];
334
+ const escalate = (decision, reason) => {
335
+ const rank = { allow: 0, ask: 1, deny: 2 };
336
+ if (rank[decision] > rank[result.decision]) result = { decision, reason };
337
+ };
338
+ if (depth > MAX_DEPTH) {
339
+ escalate('ask', 'This command nests shells too deeply to check; confirm with the user.');
340
+ return { ...result, merges };
341
+ }
342
+
343
+ const nested = [];
344
+ const notes = [];
345
+ for (const raw of scan(command, nested)) {
346
+ const argv = unwrap(raw, nested, notes);
347
+ if (argv.length === 0) continue;
348
+ const bin = path.basename(argv[0]);
349
+
350
+ if (argv.some((tok) => DEPLOY_SCRIPT.test(tok))) {
351
+ escalate(
352
+ 'deny',
353
+ 'cms-edit hosts deploy from git (main). Never run a manual deploy (AGENTS.md, hosted MCP).',
354
+ );
355
+ }
356
+ if (bin === 'vercel' || bin === 'vc') {
357
+ const sub = argv.slice(1).find((a) => !a.startsWith('-'));
358
+ const bare = sub === undefined && !argv.slice(1).some((a) => VERCEL_NON_DEPLOY.has(a));
359
+ if (
360
+ bare ||
361
+ ['deploy', 'promote', 'rollback'].includes(sub) ||
362
+ argv.includes('--prod') ||
363
+ argv.includes('--production')
364
+ ) {
365
+ escalate(
366
+ 'deny',
367
+ 'Never run `vercel deploy/promote` directly: production ships from git (AGENTS.md, release verification).',
368
+ );
369
+ }
370
+ }
371
+ if (bin === 'git') classifyGit(argv, ctx, escalate);
372
+ if (bin === 'gh') classifyGh(argv, merges, escalate);
373
+ }
374
+
375
+ for (const note of notes) escalate('ask', note);
376
+ for (const inner of nested) {
377
+ const r = classifyShellCommand(inner, ctx, depth + 1);
378
+ merges.push(...r.merges);
379
+ escalate(r.decision, r.reason);
380
+ }
381
+ return { ...result, merges };
382
+ }
383
+
384
+ /**
385
+ * Should an agent's file edit be paused? Edits on a primary checkout that sits on an
386
+ * integration branch are only for maintenance; features go in a worktree.
387
+ */
388
+ export function classifyEdit({ isPrimaryCheckout, branch, env = {} }) {
389
+ if (isOn(env, OVERRIDE_PRIMARY_EDIT)) return { decision: 'allow' };
390
+ if (isPrimaryCheckout && branch && PROTECTED_COMMIT_BRANCHES.includes(branch)) {
391
+ return {
392
+ decision: 'ask',
393
+ reason:
394
+ `This is the primary checkout on "${branch}". Feature work belongs in a git worktree ` +
395
+ 'on feature/<scope>/<slug> (AGENTS.md). Confirm this is integration-branch maintenance.',
396
+ };
397
+ }
398
+ return { decision: 'allow' };
399
+ }
@@ -0,0 +1,168 @@
1
+ /**
2
+ * A small, quote-aware shell tokenizer for the agent guard. It is not a full shell:
3
+ * it understands quoting, separators (; & | newline and parentheses), heredocs, and
4
+ * collects the text of $( ), backticks, `sh -c` and `eval` so callers can classify
5
+ * those recursively. Anything cleverer (variables, aliases, functions, scripts that
6
+ * run git) is out of reach; the git hooks and CI audit remain the real enforcement.
7
+ */
8
+
9
+ const SEPARATORS = new Set([';', '&', '|', '\n', '(', ')']);
10
+
11
+ function readParen(text, start) {
12
+ let depth = 0;
13
+ let i = start;
14
+ for (; i < text.length; i++) {
15
+ if (text[i] === '(') depth++;
16
+ else if (text[i] === ')') {
17
+ depth--;
18
+ if (depth === 0) break;
19
+ }
20
+ }
21
+ return [text.slice(start + 1, i), i + 1];
22
+ }
23
+
24
+ function readBackticks(text, start) {
25
+ const end = text.indexOf('`', start + 1);
26
+ const close = end < 0 ? text.length : end;
27
+ return [text.slice(start + 1, close), close + 1];
28
+ }
29
+
30
+ function readHeredocDelimiter(text, from) {
31
+ const m = /^-?\s*(?:'([^']*)'|"([^"]*)"|([^\s;&|<>()]+))/.exec(text.slice(from));
32
+ if (!m) return null;
33
+ return { delimiter: m[1] ?? m[2] ?? m[3], length: m[0].length };
34
+ }
35
+
36
+ /**
37
+ * @param {string} text
38
+ * @param {string[]} nested receives the inner text of $( ), backticks (callers recurse into it)
39
+ * @returns {string[][]} one argv (unquoted words) per simple command
40
+ */
41
+ export function scan(text, nested = []) {
42
+ const commands = [];
43
+ let words = [];
44
+ let cur = '';
45
+ let inWord = false;
46
+ let quoted = false;
47
+ let i = 0;
48
+ const heredocs = [];
49
+
50
+ const endWord = () => {
51
+ if (inWord) {
52
+ words.push(cur);
53
+ cur = '';
54
+ inWord = false;
55
+ }
56
+ quoted = false;
57
+ };
58
+ const endCommand = () => {
59
+ endWord();
60
+ if (words.length) {
61
+ commands.push(words);
62
+ words = [];
63
+ }
64
+ };
65
+ const substitution = (reader) => {
66
+ const [inner, next] = reader(text, i);
67
+ nested.push(inner);
68
+ cur += text.slice(i, next);
69
+ inWord = true;
70
+ i = next;
71
+ };
72
+
73
+ while (i < text.length) {
74
+ const c = text[i];
75
+ if (c === "'") {
76
+ inWord = true;
77
+ quoted = true;
78
+ const close = text.indexOf("'", i + 1);
79
+ const end = close < 0 ? text.length : close;
80
+ cur += text.slice(i + 1, end);
81
+ i = end + 1;
82
+ } else if (c === '"') {
83
+ inWord = true;
84
+ quoted = true;
85
+ i++;
86
+ while (i < text.length && text[i] !== '"') {
87
+ if (text[i] === '\\' && i + 1 < text.length) {
88
+ cur += text[i + 1];
89
+ i += 2;
90
+ } else if (text[i] === '$' && text[i + 1] === '(') {
91
+ i++;
92
+ const [inner, next] = readParen(text, i);
93
+ nested.push(inner);
94
+ cur += `$(${inner})`;
95
+ i = next;
96
+ } else if (text[i] === '`') {
97
+ const [inner, next] = readBackticks(text, i);
98
+ nested.push(inner);
99
+ cur += `\`${inner}\``;
100
+ i = next;
101
+ } else {
102
+ cur += text[i++];
103
+ }
104
+ }
105
+ i++;
106
+ } else if (c === '\\') {
107
+ inWord = true;
108
+ quoted = true;
109
+ if (i + 1 < text.length) cur += text[i + 1];
110
+ i += 2;
111
+ } else if (c === '$' && text[i + 1] === '(') {
112
+ i++;
113
+ const [inner, next] = readParen(text, i);
114
+ nested.push(inner);
115
+ cur += `$(${inner})`;
116
+ inWord = true;
117
+ i = next;
118
+ } else if (c === '`') {
119
+ substitution(readBackticks);
120
+ } else if (c === '<' && text[i + 1] === '<' && text[i + 2] !== '<') {
121
+ endWord();
122
+ const heredoc = readHeredocDelimiter(text, i + 2);
123
+ if (heredoc) {
124
+ heredocs.push(heredoc.delimiter);
125
+ i += 2 + heredoc.length;
126
+ } else {
127
+ i += 2;
128
+ }
129
+ } else if (c === '\n' && heredocs.length) {
130
+ endCommand();
131
+ i++;
132
+ for (const delimiter of heredocs.splice(0)) {
133
+ while (i < text.length) {
134
+ const eol = text.indexOf('\n', i);
135
+ const line = text.slice(i, eol < 0 ? text.length : eol);
136
+ i = eol < 0 ? text.length : eol + 1;
137
+ if (line.trim() === delimiter) break;
138
+ }
139
+ }
140
+ } else if (c === '&' && (/[<>]$/.test(cur) || text[i + 1] === '>')) {
141
+ // Redirection operators `>&` / `&>` / `2>&1` are part of the word, not a separator.
142
+ inWord = true;
143
+ cur += c;
144
+ i++;
145
+ } else if (SEPARATORS.has(c)) {
146
+ endCommand();
147
+ i++;
148
+ } else if (/\s/.test(c)) {
149
+ // A bare `{` or `}` word is a group delimiter, so the command after it starts a new command.
150
+ if (inWord && !quoted && (cur === '{' || cur === '}')) {
151
+ cur = '';
152
+ inWord = false;
153
+ endCommand();
154
+ } else {
155
+ endWord();
156
+ }
157
+ i++;
158
+ } else if (c === '#' && !inWord) {
159
+ while (i < text.length && text[i] !== '\n') i++;
160
+ } else {
161
+ inWord = true;
162
+ cur += c;
163
+ i++;
164
+ }
165
+ }
166
+ endCommand();
167
+ return commands;
168
+ }