gm-skill 2.0.1209 → 2.0.1210

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.1210` — 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.1210",
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,127 @@ 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 isSpoolPollCommand(command) {
348
+ if (!command) return null;
349
+ const s = String(command);
350
+ for (const re of SPOOL_POLL_PATTERNS) {
351
+ if (re.test(s)) return re.source;
352
+ }
353
+ return null;
354
+ }
355
+
356
+ let raw = '';
357
+ process.stdin.setEncoding('utf8');
358
+ process.stdin.on('data', (chunk) => { raw += chunk; });
359
+ process.stdin.on('end', () => {
360
+ let event = {};
361
+ try { event = JSON.parse(raw || '{}'); } catch (_) { event = {}; }
362
+ const tool = event.tool_name || event.tool || '';
363
+ const input = event.tool_input || event.input || {};
364
+ if (tool !== 'Bash') {
365
+ process.stdout.write(JSON.stringify({ continue: true }));
366
+ process.exit(0);
367
+ }
368
+ const command = input.command || input.cmd || '';
369
+ const pattern = isSpoolPollCommand(command);
370
+ if (!pattern) {
371
+ process.stdout.write(JSON.stringify({ continue: true }));
372
+ process.exit(0);
373
+ }
374
+ try {
375
+ const fs = require('fs');
376
+ const path = require('path');
377
+ const os = require('os');
378
+ const day = new Date().toISOString().slice(0, 10);
379
+ const dir = path.join(process.env.GM_LOG_DIR || path.join(os.homedir(), '.claude', 'gm-log'), day);
380
+ fs.mkdirSync(dir, { recursive: true });
381
+ fs.appendFileSync(path.join(dir, 'hook.jsonl'), JSON.stringify({
382
+ ts: new Date().toISOString(),
383
+ sub: 'hook',
384
+ event: 'deviation.spool-poll',
385
+ pid: process.pid,
386
+ sess: process.env.CLAUDE_SESSION_ID || process.env.GM_SESSION_ID || '',
387
+ cwd: process.cwd(),
388
+ operation: 'bash',
389
+ pattern,
390
+ command_excerpt: String(command).slice(0, 200),
391
+ via: 'pre-tool-use-hook',
392
+ }) + '\\n');
393
+ } catch (_) {}
394
+ process.stdout.write(JSON.stringify({
395
+ decision: 'block',
396
+ reason: SPOOL_POLL_REASON,
397
+ }));
398
+ process.exit(2);
399
+ });
400
+ `;
401
+ }
402
+
403
+ function ensureSpoolPollGate(cwd) {
404
+ try {
405
+ const gmHooks = path.join(cwd, '.gm', 'hooks');
406
+ fs.mkdirSync(gmHooks, { recursive: true });
407
+ const gateScript = path.join(gmHooks, 'spool-poll-gate.js');
408
+ const want = spoolPollGateScript();
409
+ let need = true;
410
+ try {
411
+ const existing = fs.readFileSync(gateScript, 'utf8');
412
+ if (existing === want) need = false;
413
+ } catch (_) {}
414
+ if (need) fs.writeFileSync(gateScript, want);
415
+
416
+ const claudeDir = path.join(cwd, '.claude');
417
+ fs.mkdirSync(claudeDir, { recursive: true });
418
+ const settingsPath = path.join(claudeDir, 'settings.json');
419
+ let settings = {};
420
+ try {
421
+ const raw = fs.readFileSync(settingsPath, 'utf8');
422
+ settings = JSON.parse(raw || '{}');
423
+ } catch (_) { settings = {}; }
424
+ if (!settings.hooks || typeof settings.hooks !== 'object') settings.hooks = {};
425
+ if (!Array.isArray(settings.hooks.PreToolUse)) settings.hooks.PreToolUse = [];
426
+ const wantCommand = `node "\${CLAUDE_PROJECT_DIR}/.gm/hooks/spool-poll-gate.js"`;
427
+ let bashEntry = settings.hooks.PreToolUse.find(e => e && e.matcher === 'Bash');
428
+ if (!bashEntry) {
429
+ bashEntry = { matcher: 'Bash', hooks: [] };
430
+ settings.hooks.PreToolUse.push(bashEntry);
431
+ }
432
+ if (!Array.isArray(bashEntry.hooks)) bashEntry.hooks = [];
433
+ const already = bashEntry.hooks.some(h => h && typeof h.command === 'string' && h.command.includes('spool-poll-gate.js'));
434
+ if (!already) {
435
+ bashEntry.hooks.push({ type: 'command', command: wantCommand });
436
+ }
437
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
438
+ emitBootstrapEvent('info', 'Spool-poll gate ensured', { gateScript, settingsPath, hookAlreadyPresent: already });
439
+ } catch (e) {
440
+ emitBootstrapEvent('warn', 'ensureSpoolPollGate failed', { error: e.message });
441
+ }
442
+ }
443
+
323
444
  function writeSessionSidecar(sessionId) {
324
445
  try {
325
446
  const spool = path.join(process.cwd(), '.gm', 'exec-spool');
@@ -569,6 +690,7 @@ async function bootstrapPlugkit(sessionId, options) {
569
690
  writeSessionSidecar(sessionId);
570
691
  ensureManagedGitignore(process.cwd());
571
692
  ensureBuildToolIgnores(process.cwd());
693
+ ensureSpoolPollGate(process.cwd());
572
694
 
573
695
  const manifest = readManifest();
574
696
  let targetVersion = manifest.version;
@@ -764,4 +886,6 @@ module.exports = {
764
886
  ensureBuildToolIgnores,
765
887
  detectBuildToolConfigs,
766
888
  ensureManagedGitignore,
889
+ ensureSpoolPollGate,
890
+ spoolPollGateScript,
767
891
  };
@@ -192,9 +192,12 @@ 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.';
198
201
 
199
202
  function isSpoolPollCommand(command) {
200
203
  if (!command) return null;
@@ -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.1210",
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.1210"
43
43
  },
44
44
  "engines": {
45
45
  "node": ">=16.0.0"