gm-skill 2.0.1209 → 2.0.1211

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.
package/README.md CHANGED
@@ -35,7 +35,7 @@ An earlier generation fanned out fifteen per-platform downstream repos (gm-cc, g
35
35
 
36
36
  ## Version
37
37
 
38
- `2.0.1209` — auto-bumped from the canonical `gm` repo. Every push to `AnEntrypoint/gm` (or any cascading sibling crate) republishes this package.
38
+ `2.0.1211` — auto-bumped from the canonical `gm` repo. Every push to `AnEntrypoint/gm` (or any cascading sibling crate) republishes this package.
39
39
 
40
40
  ## Source of truth
41
41
 
package/gm.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm",
3
- "version": "2.0.1209",
3
+ "version": "2.0.1211",
4
4
  "description": "Spool-dispatch orchestration engine with unified state machine, skills, and automated git enforcement",
5
5
  "author": "AnEntrypoint",
6
6
  "license": "MIT",
@@ -320,6 +320,137 @@ function ensureBuildToolIgnores(cwd) {
320
320
  }
321
321
  }
322
322
 
323
+ const SPOOL_POLL_GATE_MARK = '__gm_spool_poll_gate__';
324
+
325
+ function spoolPollGateScript() {
326
+ return `#!/usr/bin/env node
327
+ // ${SPOOL_POLL_GATE_MARK}
328
+ // PreToolUse hook that blocks bash polling of .gm/exec-spool.
329
+ // Plugkit is synchronous from the agent's view; the Read tool is the canonical
330
+ // way to inspect response files. This hook denies Bash commands that try to
331
+ // poll or shell-read the spool directory.
332
+
333
+ const SPOOL_POLL_PATTERNS = [
334
+ /\\bsleep\\s+\\d+(?:\\.\\d+)?\\s*[;&]+\\s*(?:cat|ls|tail|head|find|test|grep)\\b[^|]*\\.gm[\\\\/](?:exec-spool|spool)/i,
335
+ /\\bStart-Sleep\\b[^;|]*?[;|]\\s*(?:Get-Content|Test-Path|Get-ChildItem|cat|ls|gci|gc|tp)\\b[^|]*\\.gm[\\\\/](?:exec-spool|spool)/i,
336
+ /\\b(?:cat|ls|tail|head|Get-Content|Test-Path|Get-ChildItem)\\b[^|]*\\.gm[\\\\/](?:exec-spool|spool)[^|]*?[;&|]+\\s*(?:sleep|Start-Sleep)\\b/i,
337
+ /\\bwhile\\b[^;]*?(?:!|-not)\\s*(?:-(?:f|e)\\s+|Test-Path\\s+)[^;]*?\\.gm[\\\\/](?:exec-spool|spool)/i,
338
+ /\\buntil\\b[^;]*?(?:-f|-e|Test-Path)\\s+[^;]*?\\.gm[\\\\/](?:exec-spool|spool)/i,
339
+ /\\bfor\\s+i\\s+in\\b[^;]*?;\\s*do\\b[^;]*?(?:sleep|Start-Sleep)[^;]*?\\.gm[\\\\/](?:exec-spool|spool)/i,
340
+ /\\b(?:cat|head|tail|less|more|type|Get-Content|gc)\\s+(?:-[A-Za-z]+\\s+)*['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]/i,
341
+ /\\b(?:ls|dir|Get-ChildItem|gci)\\s+(?:-[A-Za-z]+\\s+)*['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]/i,
342
+ /\\b(?:test|Test-Path|tp)\\s+(?:-[A-Za-z]+\\s+)?['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]/i,
343
+ ];
344
+
345
+ const SPOOL_POLL_REASON = 'spool polling and bash-reads of .gm/exec-spool/ are forbidden — plugkit is synchronous from your view, and the canonical way to inspect spool files is the Read tool. Use Read on .gm/exec-spool/out/<verb>-<N>.json directly. If the response file does not exist, the watcher is either dead (Read .gm/exec-spool/.status.json and check its mtime against now) or the verb is genuinely slow (Read .gm/exec-spool/.watcher.log for the dispatch trace). You are the state machine; plugkit serves the response the moment you write the request, and Read is how you observe the result.';
346
+
347
+ function stripHeredocsAndStringLiterals(command) {
348
+ let s = String(command);
349
+ s = s.replace(/<<-?\\s*'([A-Z_]+)'[\\s\\S]*?\\n\\1/g, '');
350
+ s = s.replace(/<<-?\\s*"?([A-Z_]+)"?[\\s\\S]*?\\n\\1/g, '');
351
+ s = s.replace(/\\$\\(cat\\s+<<-?\\s*'?([A-Z_]+)'?[\\s\\S]*?\\n\\1\\s*\\)/g, '');
352
+ s = s.replace(/-m\\s+(['"])(?:\\\\.|(?!\\1)[^\\\\])*\\1/g, '-m STR');
353
+ s = s.replace(/--message[= ]+(['"])(?:\\\\.|(?!\\1)[^\\\\])*\\1/g, '--message STR');
354
+ return s;
355
+ }
356
+
357
+ function isSpoolPollCommand(command) {
358
+ if (!command) return null;
359
+ const stripped = stripHeredocsAndStringLiterals(command);
360
+ for (const re of SPOOL_POLL_PATTERNS) {
361
+ if (re.test(stripped)) return re.source;
362
+ }
363
+ return null;
364
+ }
365
+
366
+ let raw = '';
367
+ process.stdin.setEncoding('utf8');
368
+ process.stdin.on('data', (chunk) => { raw += chunk; });
369
+ process.stdin.on('end', () => {
370
+ let event = {};
371
+ try { event = JSON.parse(raw || '{}'); } catch (_) { event = {}; }
372
+ const tool = event.tool_name || event.tool || '';
373
+ const input = event.tool_input || event.input || {};
374
+ if (tool !== 'Bash') {
375
+ process.stdout.write(JSON.stringify({ continue: true }));
376
+ process.exit(0);
377
+ }
378
+ const command = input.command || input.cmd || '';
379
+ const pattern = isSpoolPollCommand(command);
380
+ if (!pattern) {
381
+ process.stdout.write(JSON.stringify({ continue: true }));
382
+ process.exit(0);
383
+ }
384
+ try {
385
+ const fs = require('fs');
386
+ const path = require('path');
387
+ const os = require('os');
388
+ const day = new Date().toISOString().slice(0, 10);
389
+ const dir = path.join(process.env.GM_LOG_DIR || path.join(os.homedir(), '.claude', 'gm-log'), day);
390
+ fs.mkdirSync(dir, { recursive: true });
391
+ fs.appendFileSync(path.join(dir, 'hook.jsonl'), JSON.stringify({
392
+ ts: new Date().toISOString(),
393
+ sub: 'hook',
394
+ event: 'deviation.spool-poll',
395
+ pid: process.pid,
396
+ sess: process.env.CLAUDE_SESSION_ID || process.env.GM_SESSION_ID || '',
397
+ cwd: process.cwd(),
398
+ operation: 'bash',
399
+ pattern,
400
+ command_excerpt: String(command).slice(0, 200),
401
+ via: 'pre-tool-use-hook',
402
+ }) + '\\n');
403
+ } catch (_) {}
404
+ process.stdout.write(JSON.stringify({
405
+ decision: 'block',
406
+ reason: SPOOL_POLL_REASON,
407
+ }));
408
+ process.exit(2);
409
+ });
410
+ `;
411
+ }
412
+
413
+ function ensureSpoolPollGate(cwd) {
414
+ try {
415
+ const gmHooks = path.join(cwd, '.gm', 'hooks');
416
+ fs.mkdirSync(gmHooks, { recursive: true });
417
+ const gateScript = path.join(gmHooks, 'spool-poll-gate.js');
418
+ const want = spoolPollGateScript();
419
+ let need = true;
420
+ try {
421
+ const existing = fs.readFileSync(gateScript, 'utf8');
422
+ if (existing === want) need = false;
423
+ } catch (_) {}
424
+ if (need) fs.writeFileSync(gateScript, want);
425
+
426
+ const claudeDir = path.join(cwd, '.claude');
427
+ fs.mkdirSync(claudeDir, { recursive: true });
428
+ const settingsPath = path.join(claudeDir, 'settings.json');
429
+ let settings = {};
430
+ try {
431
+ const raw = fs.readFileSync(settingsPath, 'utf8');
432
+ settings = JSON.parse(raw || '{}');
433
+ } catch (_) { settings = {}; }
434
+ if (!settings.hooks || typeof settings.hooks !== 'object') settings.hooks = {};
435
+ if (!Array.isArray(settings.hooks.PreToolUse)) settings.hooks.PreToolUse = [];
436
+ const wantCommand = `node "\${CLAUDE_PROJECT_DIR}/.gm/hooks/spool-poll-gate.js"`;
437
+ let bashEntry = settings.hooks.PreToolUse.find(e => e && e.matcher === 'Bash');
438
+ if (!bashEntry) {
439
+ bashEntry = { matcher: 'Bash', hooks: [] };
440
+ settings.hooks.PreToolUse.push(bashEntry);
441
+ }
442
+ if (!Array.isArray(bashEntry.hooks)) bashEntry.hooks = [];
443
+ const already = bashEntry.hooks.some(h => h && typeof h.command === 'string' && h.command.includes('spool-poll-gate.js'));
444
+ if (!already) {
445
+ bashEntry.hooks.push({ type: 'command', command: wantCommand });
446
+ }
447
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
448
+ emitBootstrapEvent('info', 'Spool-poll gate ensured', { gateScript, settingsPath, hookAlreadyPresent: already });
449
+ } catch (e) {
450
+ emitBootstrapEvent('warn', 'ensureSpoolPollGate failed', { error: e.message });
451
+ }
452
+ }
453
+
323
454
  function writeSessionSidecar(sessionId) {
324
455
  try {
325
456
  const spool = path.join(process.cwd(), '.gm', 'exec-spool');
@@ -569,6 +700,7 @@ async function bootstrapPlugkit(sessionId, options) {
569
700
  writeSessionSidecar(sessionId);
570
701
  ensureManagedGitignore(process.cwd());
571
702
  ensureBuildToolIgnores(process.cwd());
703
+ ensureSpoolPollGate(process.cwd());
572
704
 
573
705
  const manifest = readManifest();
574
706
  let targetVersion = manifest.version;
@@ -764,4 +896,6 @@ module.exports = {
764
896
  ensureBuildToolIgnores,
765
897
  detectBuildToolConfigs,
766
898
  ensureManagedGitignore,
899
+ ensureSpoolPollGate,
900
+ spoolPollGateScript,
767
901
  };
@@ -192,15 +192,28 @@ const SPOOL_POLL_PATTERNS = [
192
192
  /\bwhile\b[^;]*?(?:!|-not)\s*(?:-(?:f|e)\s+|Test-Path\s+)[^;]*?\.gm[\\/](?:exec-spool|spool)/i,
193
193
  /\buntil\b[^;]*?(?:-f|-e|Test-Path)\s+[^;]*?\.gm[\\/](?:exec-spool|spool)/i,
194
194
  /\bfor\s+i\s+in\b[^;]*?;\s*do\b[^;]*?(?:sleep|Start-Sleep)[^;]*?\.gm[\\/](?:exec-spool|spool)/i,
195
+ /\b(?:cat|head|tail|less|more|type|Get-Content|gc)\s+(?:-[A-Za-z]+\s+)*['"]?[^'"|;&]*\.gm[\\/](?:exec-spool|spool)[\\/]/i,
196
+ /\b(?:ls|dir|Get-ChildItem|gci)\s+(?:-[A-Za-z]+\s+)*['"]?[^'"|;&]*\.gm[\\/](?:exec-spool|spool)[\\/]/i,
197
+ /\b(?:test|Test-Path|tp)\s+(?:-[A-Za-z]+\s+)?['"]?[^'"|;&]*\.gm[\\/](?:exec-spool|spool)[\\/]/i,
195
198
  ];
196
199
 
197
- const SPOOL_POLL_REASON = 'spool polling is forbidden — plugkit is synchronous from your view. Read the response file at .gm/exec-spool/out/<verb>-<N>.json directly with the Read tool. If it does not exist, the watcher is either dead (check .gm/exec-spool/.status.json mtime) or the verb is genuinely slow (read .gm/exec-spool/.watcher.log for the dispatch trace). Polling with sleep+cat/ls/Test-Path treats plugkit as an async worker; it is not. You are the state machine; plugkit serves the response the moment you write the request.';
200
+ const SPOOL_POLL_REASON = 'spool polling and bash-reads of .gm/exec-spool/ are forbidden — plugkit is synchronous from your view, and the canonical way to inspect spool files is the Read tool. Use Read on .gm/exec-spool/out/<verb>-<N>.json directly. If the response file does not exist, the watcher is either dead (Read .gm/exec-spool/.status.json and check its mtime against now) or the verb is genuinely slow (Read .gm/exec-spool/.watcher.log for the dispatch trace). Polling with sleep+cat/ls/Test-Path treats plugkit as an async worker; bare cat/ls of the spool dir treats it as a shell artifact. It is neither. You are the state machine; plugkit serves the response the moment you write the request, and Read is how you observe the result.';
201
+
202
+ function stripHeredocsAndStringLiterals(command) {
203
+ let s = String(command);
204
+ s = s.replace(/<<-?\s*'([A-Z_]+)'[\s\S]*?\n\1/g, '');
205
+ s = s.replace(/<<-?\s*"?([A-Z_]+)"?[\s\S]*?\n\1/g, '');
206
+ s = s.replace(/\$\(cat\s+<<-?\s*'?([A-Z_]+)'?[\s\S]*?\n\1\s*\)/g, '');
207
+ s = s.replace(/-m\s+(['"])(?:\\.|(?!\1)[^\\])*\1/g, '-m STR');
208
+ s = s.replace(/--message[= ]+(['"])(?:\\.|(?!\1)[^\\])*\1/g, '--message STR');
209
+ return s;
210
+ }
198
211
 
199
212
  function isSpoolPollCommand(command) {
200
213
  if (!command) return null;
201
- const s = String(command);
214
+ const stripped = stripHeredocsAndStringLiterals(command);
202
215
  for (const re of SPOOL_POLL_PATTERNS) {
203
- if (re.test(s)) return re.source;
216
+ if (re.test(stripped)) return re.source;
204
217
  }
205
218
  return null;
206
219
  }
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ const { isSpoolPollCommand, SPOOL_POLL_REASON, logDeviation } = require('./spool-dispatch.js');
3
+
4
+ let raw = '';
5
+ process.stdin.setEncoding('utf8');
6
+ process.stdin.on('data', (chunk) => { raw += chunk; });
7
+ process.stdin.on('end', () => {
8
+ let event = {};
9
+ try { event = JSON.parse(raw || '{}'); } catch (_) { event = {}; }
10
+ const tool = event.tool_name || event.tool || '';
11
+ const input = event.tool_input || event.input || {};
12
+ if (tool !== 'Bash') {
13
+ process.stdout.write(JSON.stringify({ continue: true }));
14
+ process.exit(0);
15
+ }
16
+ const command = input.command || input.cmd || '';
17
+ const pattern = isSpoolPollCommand(command);
18
+ if (!pattern) {
19
+ process.stdout.write(JSON.stringify({ continue: true }));
20
+ process.exit(0);
21
+ }
22
+ try {
23
+ logDeviation('deviation.spool-poll', {
24
+ operation: 'bash',
25
+ pattern,
26
+ command_excerpt: String(command).slice(0, 200),
27
+ via: 'pre-tool-use-hook',
28
+ });
29
+ } catch (_) {}
30
+ process.stdout.write(JSON.stringify({
31
+ decision: 'block',
32
+ reason: SPOOL_POLL_REASON,
33
+ }));
34
+ process.exit(2);
35
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-skill",
3
- "version": "2.0.1209",
3
+ "version": "2.0.1211",
4
4
  "description": "Canonical universal harness — AI-native software engineering via skill-driven orchestration; bootstraps plugkit for task execution and session isolation. Install in any AI coding agent host.",
5
5
  "author": "AnEntrypoint",
6
6
  "license": "MIT",
@@ -39,7 +39,7 @@
39
39
  "gm.json"
40
40
  ],
41
41
  "dependencies": {
42
- "gm-plugkit": "^2.0.1209"
42
+ "gm-plugkit": "^2.0.1211"
43
43
  },
44
44
  "engines": {
45
45
  "node": ">=16.0.0"