gm-skill 2.0.1212 → 2.0.1214

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.1212` — auto-bumped from the canonical `gm` repo. Every push to `AnEntrypoint/gm` (or any cascading sibling crate) republishes this package.
38
+ `2.0.1214` — 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
 
@@ -27,6 +27,134 @@ const ORCHESTRATOR_VERBS = new Set(['instruction', 'transition', 'phase-status',
27
27
  const TURN_IDLE_MS = 30_000;
28
28
  const _turns = new Map();
29
29
 
30
+ const SPOOL_POLL_GATE_MARK = '__gm_spool_poll_gate__';
31
+
32
+ function spoolPollGateScript() {
33
+ return `#!/usr/bin/env node
34
+ // ${SPOOL_POLL_GATE_MARK}
35
+ // PreToolUse hook that blocks bash polling of .gm/exec-spool.
36
+ // Plugkit is synchronous from the agent's view; the Read tool is the canonical
37
+ // way to inspect response files. This hook denies Bash commands that try to
38
+ // poll or shell-read the spool directory.
39
+
40
+ const SPOOL_POLL_PATTERNS = [
41
+ /\\bsleep\\s+\\d+(?:\\.\\d+)?\\s*[;&]+\\s*(?:cat|ls|tail|head|find|test|grep)\\b[^|]*\\.gm[\\\\/](?:exec-spool|spool)/i,
42
+ /\\bStart-Sleep\\b[^;|]*?[;|]\\s*(?:Get-Content|Test-Path|Get-ChildItem|cat|ls|gci|gc|tp)\\b[^|]*\\.gm[\\\\/](?:exec-spool|spool)/i,
43
+ /\\b(?:cat|ls|tail|head|Get-Content|Test-Path|Get-ChildItem)\\b[^|]*\\.gm[\\\\/](?:exec-spool|spool)[^|]*?[;&|]+\\s*(?:sleep|Start-Sleep)\\b/i,
44
+ /\\bwhile\\b[^;]*?(?:!|-not)\\s*(?:-(?:f|e)\\s+|Test-Path\\s+)[^;]*?\\.gm[\\\\/](?:exec-spool|spool)/i,
45
+ /\\buntil\\b[^;]*?(?:-f|-e|Test-Path)\\s+[^;]*?\\.gm[\\\\/](?:exec-spool|spool)/i,
46
+ /\\bfor\\s+i\\s+in\\b[^;]*?;\\s*do\\b[^;]*?(?:sleep|Start-Sleep)[^;]*?\\.gm[\\\\/](?:exec-spool|spool)/i,
47
+ /\\b(?:cat|head|tail|less|more|type|Get-Content|gc)\\s+(?:-[A-Za-z]+\\s+)*['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]/i,
48
+ /\\b(?:ls|dir|Get-ChildItem|gci)\\s+(?:-[A-Za-z]+\\s+)*['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]/i,
49
+ /\\b(?:test|Test-Path|tp)\\s+(?:-[A-Za-z]+\\s+)?['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]/i,
50
+ ];
51
+
52
+ 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.';
53
+
54
+ function stripHeredocsAndStringLiterals(command) {
55
+ let s = String(command);
56
+ s = s.replace(/<<-?\\s*'([A-Z_]+)'[\\s\\S]*?\\n\\1/g, '');
57
+ s = s.replace(/<<-?\\s*"?([A-Z_]+)"?[\\s\\S]*?\\n\\1/g, '');
58
+ s = s.replace(/\\$\\(cat\\s+<<-?\\s*'?([A-Z_]+)'?[\\s\\S]*?\\n\\1\\s*\\)/g, '');
59
+ s = s.replace(/-m\\s+(['"])(?:\\\\.|(?!\\1)[^\\\\])*\\1/g, '-m STR');
60
+ s = s.replace(/--message[= ]+(['"])(?:\\\\.|(?!\\1)[^\\\\])*\\1/g, '--message STR');
61
+ return s;
62
+ }
63
+
64
+ function isSpoolPollCommand(command) {
65
+ if (!command) return null;
66
+ const stripped = stripHeredocsAndStringLiterals(command);
67
+ for (const re of SPOOL_POLL_PATTERNS) {
68
+ if (re.test(stripped)) return re.source;
69
+ }
70
+ return null;
71
+ }
72
+
73
+ let raw = '';
74
+ process.stdin.setEncoding('utf8');
75
+ process.stdin.on('data', (chunk) => { raw += chunk; });
76
+ process.stdin.on('end', () => {
77
+ let event = {};
78
+ try { event = JSON.parse(raw || '{}'); } catch (_) { event = {}; }
79
+ const tool = event.tool_name || event.tool || '';
80
+ const input = event.tool_input || event.input || {};
81
+ if (tool !== 'Bash') {
82
+ process.stdout.write(JSON.stringify({ continue: true }));
83
+ process.exit(0);
84
+ }
85
+ const command = input.command || input.cmd || '';
86
+ const pattern = isSpoolPollCommand(command);
87
+ if (!pattern) {
88
+ process.stdout.write(JSON.stringify({ continue: true }));
89
+ process.exit(0);
90
+ }
91
+ try {
92
+ const fs = require('fs');
93
+ const path = require('path');
94
+ const os = require('os');
95
+ const day = new Date().toISOString().slice(0, 10);
96
+ const dir = path.join(process.env.GM_LOG_DIR || path.join(os.homedir(), '.claude', 'gm-log'), day);
97
+ fs.mkdirSync(dir, { recursive: true });
98
+ fs.appendFileSync(path.join(dir, 'hook.jsonl'), JSON.stringify({
99
+ ts: new Date().toISOString(),
100
+ sub: 'hook',
101
+ event: 'deviation.spool-poll',
102
+ pid: process.pid,
103
+ sess: process.env.CLAUDE_SESSION_ID || process.env.GM_SESSION_ID || '',
104
+ cwd: process.cwd(),
105
+ operation: 'bash',
106
+ pattern,
107
+ command_excerpt: String(command).slice(0, 200),
108
+ via: 'pre-tool-use-hook',
109
+ }) + '\\n');
110
+ } catch (_) {}
111
+ process.stdout.write(JSON.stringify({
112
+ decision: 'block',
113
+ reason: SPOOL_POLL_REASON,
114
+ }));
115
+ process.exit(2);
116
+ });
117
+ `;
118
+ }
119
+
120
+ function ensureSpoolPollGate(cwd) {
121
+ try {
122
+ const gmHooks = path.join(cwd, '.gm', 'hooks');
123
+ fs.mkdirSync(gmHooks, { recursive: true });
124
+ const gateScript = path.join(gmHooks, 'spool-poll-gate.js');
125
+ const want = spoolPollGateScript();
126
+ let need = true;
127
+ try {
128
+ const existing = fs.readFileSync(gateScript, 'utf8');
129
+ if (existing === want) need = false;
130
+ } catch (_) {}
131
+ if (need) fs.writeFileSync(gateScript, want);
132
+
133
+ const claudeDir = path.join(cwd, '.claude');
134
+ fs.mkdirSync(claudeDir, { recursive: true });
135
+ const settingsPath = path.join(claudeDir, 'settings.json');
136
+ let settings = {};
137
+ try {
138
+ const rawSettings = fs.readFileSync(settingsPath, 'utf8');
139
+ settings = JSON.parse(rawSettings || '{}');
140
+ } catch (_) { settings = {}; }
141
+ if (!settings.hooks || typeof settings.hooks !== 'object') settings.hooks = {};
142
+ if (!Array.isArray(settings.hooks.PreToolUse)) settings.hooks.PreToolUse = [];
143
+ const wantCommand = `node "\${CLAUDE_PROJECT_DIR}/.gm/hooks/spool-poll-gate.js"`;
144
+ let bashEntry = settings.hooks.PreToolUse.find(e => e && e.matcher === 'Bash');
145
+ if (!bashEntry) {
146
+ bashEntry = { matcher: 'Bash', hooks: [] };
147
+ settings.hooks.PreToolUse.push(bashEntry);
148
+ }
149
+ if (!Array.isArray(bashEntry.hooks)) bashEntry.hooks = [];
150
+ const already = bashEntry.hooks.some(h => h && typeof h.command === 'string' && h.command.includes('spool-poll-gate.js'));
151
+ if (!already) {
152
+ bashEntry.hooks.push({ type: 'command', command: wantCommand });
153
+ }
154
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
155
+ } catch (_) {}
156
+ }
157
+
30
158
  function applyDisciplineSigil(rawBody) {
31
159
  let parsed;
32
160
  try { parsed = JSON.parse(rawBody); } catch (_) { return rawBody; }
@@ -161,7 +289,12 @@ function emitOrchestratorEvents(verb, taskBase, resultStr) {
161
289
  break;
162
290
  case 'residual-scan':
163
291
  if (data.scan === 'fired') logEvent('plugkit', 'residual.fired', { task: taskBase, marker: data.marker });
164
- else logEvent('plugkit', 'residual.skipped', { task: taskBase, reason: data.reason });
292
+ else {
293
+ logEvent('plugkit', 'residual.skipped', { task: taskBase, reason: data.reason });
294
+ if (data.deviation_kind === 'residual-premature') {
295
+ logEvent('hook', 'deviation.residual-premature', { task: taskBase, reason: data.reason });
296
+ }
297
+ }
165
298
  break;
166
299
  case 'auto-recall':
167
300
  logEvent('plugkit', 'auto_recall.hits', { task: taskBase, count: Array.isArray(data.hits) ? data.hits.length : 0 });
@@ -319,6 +452,17 @@ function runPlaywriter(pw, args, timeoutMs) {
319
452
  });
320
453
  }
321
454
 
455
+ function scrubBrowserRunnerText(s) {
456
+ if (!s || typeof s !== 'string') return s;
457
+ let t = s;
458
+ t = t.replace(/playwriter/gi, 'managed browser session');
459
+ t = t.replace(/Click the[^.\n]*?extension[^.\n]*?icon[^.\n]*?\.?/gi, '');
460
+ t = t.replace(/(connected\s+)?browser\s+extension(\s+is)?\s+not\s+connected\b[^.\n]*\.?/gi, '');
461
+ t = t.replace(/no\s+connected\s+browsers?\b[^.\n]*\.?/gi, '');
462
+ t = t.replace(/Install via:[^\n]*managed browser session[^\n]*/gi, '');
463
+ return t;
464
+ }
465
+
322
466
  function getOrCreateBrowserSession(cwd, claudeSessionId, pw) {
323
467
  migrateLegacyBrowserState(cwd);
324
468
  const portsFile = browserPortsFile(cwd);
@@ -352,7 +496,7 @@ function getOrCreateBrowserSession(cwd, claudeSessionId, pw) {
352
496
  }
353
497
  if (!alive) throw new Error(`Chrome failed to open debug port ${port}`);
354
498
  const newR = runPlaywriter(pw, ['session', 'new', `--direct=localhost:${port}`], 30000);
355
- if (newR.status !== 0) throw new Error(`playwriter session new failed: ${newR.stderr || newR.stdout || 'unknown'}`);
499
+ if (newR.status !== 0) throw new Error(`managed browser session start failed: ${scrubBrowserRunnerText(newR.stderr || newR.stdout || 'unknown')}`);
356
500
  const stripAnsi = (s) => s.replace(/\x1b\[[0-9;]*m/g, '');
357
501
  const out = stripAnsi(newR.stdout || '').trim();
358
502
  let pwSessionId = null;
@@ -365,7 +509,7 @@ function getOrCreateBrowserSession(cwd, claudeSessionId, pw) {
365
509
  if (!pwSessionId) {
366
510
  try { const j = JSON.parse(out); pwSessionId = j.id || j.session_id || j.session; } catch (_) {}
367
511
  }
368
- if (!pwSessionId) throw new Error(`could not parse playwriter session id from: ${out}`);
512
+ if (!pwSessionId) throw new Error(`could not parse managed browser session id from: ${scrubBrowserRunnerText(out)}`);
369
513
  ports[claudeSessionId] = { port, profileDir, pid: chromePid };
370
514
  sessions[claudeSessionId] = [pwSessionId];
371
515
  writeJsonFile(portsFile, ports);
@@ -952,14 +1096,19 @@ function makeHostFunctions(instanceRef) {
952
1096
  const cwd = readWasmStr(instanceRef.value, cwdPtr, cwdLen) || process.cwd();
953
1097
  const sessionId = readWasmStr(instanceRef.value, sidPtr, sidLen) || 'default';
954
1098
  const pw = findPlaywriter();
955
- if (!pw) return writeWasmJson(instanceRef.value, { ok: false, error: 'playwriter not found. Install via: npm i -g playwriter' });
1099
+ if (!pw) return writeWasmJson(instanceRef.value, { ok: false, error: 'managed browser session runner not available' });
956
1100
  if (body.startsWith('session ')) {
957
1101
  const parts = body.slice(8).trim().split(/\s+/);
958
- const r = runPlaywriter(pw, ['session', ...parts], 30000);
1102
+ const ports = readJsonFile(browserPortsFile(cwd), {});
1103
+ const existing = ports[sessionId];
1104
+ const directArgs = (existing && existing.port && isPortAliveSync(existing.port))
1105
+ ? [`--direct=localhost:${existing.port}`]
1106
+ : [];
1107
+ const r = runPlaywriter(pw, ['session', ...parts, ...directArgs], 30000);
959
1108
  return writeWasmJson(instanceRef.value, {
960
1109
  ok: r.status === 0,
961
- stdout: r.stdout || '',
962
- stderr: r.stderr || '',
1110
+ stdout: scrubBrowserRunnerText(r.stdout || ''),
1111
+ stderr: scrubBrowserRunnerText(r.stderr || ''),
963
1112
  exit_code: r.status === null ? -1 : r.status,
964
1113
  });
965
1114
  }
@@ -967,13 +1116,13 @@ function makeHostFunctions(instanceRef) {
967
1116
  const r = runPlaywriter(pw, ['-s', pwSessionId, '--timeout', '14000', '-e', body], 60000);
968
1117
  return writeWasmJson(instanceRef.value, {
969
1118
  ok: r.status === 0,
970
- stdout: r.stdout || '',
971
- stderr: r.stderr || '',
1119
+ stdout: scrubBrowserRunnerText(r.stdout || ''),
1120
+ stderr: scrubBrowserRunnerText(r.stderr || ''),
972
1121
  exit_code: r.status === null ? -1 : r.status,
973
1122
  session_id: pwSessionId,
974
1123
  });
975
1124
  } catch (e) {
976
- return writeWasmJson(instanceRef.value, { ok: false, error: e.message });
1125
+ return writeWasmJson(instanceRef.value, { ok: false, error: scrubBrowserRunnerText(e.message) });
977
1126
  }
978
1127
  },
979
1128
 
@@ -1778,6 +1927,7 @@ async function tryInstantiate(wasmPath) {
1778
1927
 
1779
1928
  if (args[0] === 'spool') {
1780
1929
  const projectDir = process.env.CLAUDE_PROJECT_DIR || process.cwd();
1930
+ ensureSpoolPollGate(projectDir);
1781
1931
  const spoolDir = path.join(projectDir, '.gm', 'exec-spool');
1782
1932
  await runSpoolWatcher(instance, spoolDir);
1783
1933
  } else if (args[0] === 'dispatch') {
package/gm.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm",
3
- "version": "2.0.1212",
3
+ "version": "2.0.1214",
4
4
  "description": "Spool-dispatch orchestration engine with unified state machine, skills, and automated git enforcement",
5
5
  "author": "AnEntrypoint",
6
6
  "license": "MIT",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-skill",
3
- "version": "2.0.1212",
3
+ "version": "2.0.1214",
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.1212"
42
+ "gm-plugkit": "^2.0.1214"
43
43
  },
44
44
  "engines": {
45
45
  "node": ">=16.0.0"