gm-plugkit 2.0.1220 → 2.0.1221

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-plugkit",
3
- "version": "2.0.1220",
3
+ "version": "2.0.1221",
4
4
  "description": "Bootstrap and daemon-spawn tool for gm plugkit binary. Downloads the correct platform binary, verifies SHA256, and starts the spool watcher daemon. Includes plugkit-wasm-wrapper for WASM-based spool watching.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -49,7 +49,7 @@ const SPOOL_POLL_PATTERNS = [
49
49
  /\\b(?:test|Test-Path|tp)\\s+(?:-[A-Za-z]+\\s+)?['"]?[^'"|;&]*\\.gm[\\\\/](?:exec-spool|spool)[\\\\/]/i,
50
50
  ];
51
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.';
52
+ const SPOOL_POLL_REASON = 'spool polling and bash-reads of .gm/exec-spool/ are forbidden — plugkit is synchronous from your view, and the Read tool is the canonical way to inspect spool files. Specific replacements:\\n\\n- Instead of \`cat .gm/exec-spool/.status.json\` → use the Read tool: \`Read .gm/exec-spool/.status.json\`\\n- Instead of \`ls .gm/exec-spool/out/\` → check the specific response file you wrote, e.g. \`Read .gm/exec-spool/out/<verb>-<N>.json\`\\n- Instead of \`cat .gm/exec-spool/.watcher.log\` use the Read tool with offset for tailing\\n- Instead of \`sleep N; cat .gm/exec-spool/<...>\` → just Read the response file directly; if it doesn\\'t exist yet, the watcher is dead (Read .gm/exec-spool/.status.json fresh ts means alive) or the verb is slow (Read .gm/exec-spool/.watcher.log for the dispatch trace)\\n\\nYou are the state machine. Plugkit serves the response the moment you write the request file. If you find yourself thinking "let me just check whether the file is there yet" — use Read. If you find yourself thinking "the watcher might have died" — Read .gm/exec-spool/.status.json. Bash on .gm/exec-spool/ is wrong every single time.';
53
53
 
54
54
  function stripHeredocsAndStringLiterals(command) {
55
55
  let s = String(command);
@@ -282,11 +282,29 @@ function dispatchVerbToWasmInternal(instance, verb, body) {
282
282
  }
283
283
  }
284
284
 
285
- function tryAutoRecallForTurnEntry(instance, sess, cwd) {
285
+ const AUTO_RECALL_STOPWORDS = new Set([
286
+ 'the','a','an','and','or','but','if','then','else','for','of','to','in','on','at','by','with','from','as','is','are','was','were','be','been','being','have','has','had','do','does','did','will','would','should','could','can','may','might','must','shall',
287
+ 'look','check','see','use','make','run','get','set','put','take','give','find','show','tell','let','keep','try','add','new','old','this','that','these','those','it','its','their','there','here','about','into','over','under','also','just','some','any','all','more','less','most','past','minutes','minute','hours','hour','seconds','second','days','day',
288
+ ]);
289
+
290
+ function deriveFallbackQuery(prompt) {
286
291
  try {
287
- const prompt = readUserPromptForRecall(cwd);
288
- if (!prompt) return null;
289
- const out = dispatchVerbToWasmInternal(instance, 'auto-recall', prompt);
292
+ const tokens = String(prompt).toLowerCase().split(/[^a-z0-9_]+/).filter(Boolean);
293
+ const freq = new Map();
294
+ for (const t of tokens) {
295
+ if (t.length < 4) continue;
296
+ if (AUTO_RECALL_STOPWORDS.has(t)) continue;
297
+ freq.set(t, (freq.get(t) || 0) + 1);
298
+ }
299
+ const ranked = Array.from(freq.entries()).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
300
+ const top = ranked.slice(0, 3).map(([w]) => w);
301
+ return top.join(' ');
302
+ } catch (_) { return ''; }
303
+ }
304
+
305
+ function dispatchAutoRecall(instance, queryPrompt) {
306
+ try {
307
+ const out = dispatchVerbToWasmInternal(instance, 'auto-recall', queryPrompt);
290
308
  if (!out) return null;
291
309
  let parsed;
292
310
  try { parsed = JSON.parse(out); } catch (_) { return null; }
@@ -297,8 +315,42 @@ function tryAutoRecallForTurnEntry(instance, sess, cwd) {
297
315
  }
298
316
  if (!inner || typeof inner !== 'object') return null;
299
317
  const hits = Array.isArray(inner.results) ? inner.results : (Array.isArray(inner.hits) ? inner.hits : []);
300
- const payload = { query: inner.query || '', hits, fired_at: new Date().toISOString(), turn_entry: true };
301
- logEvent('plugkit', 'auto_recall.turn-entry', { sess, query: payload.query, count: hits.length });
318
+ return { query: inner.query || '', hits };
319
+ } catch (_) { return null; }
320
+ }
321
+
322
+ function tryAutoRecallForTurnEntry(instance, sess, cwd) {
323
+ try {
324
+ const prompt = readUserPromptForRecall(cwd);
325
+ if (!prompt) return null;
326
+ const primary = dispatchAutoRecall(instance, prompt);
327
+ const fallbackQuery = deriveFallbackQuery(prompt);
328
+ let fallback = null;
329
+ if (fallbackQuery && fallbackQuery !== (primary && primary.query)) {
330
+ fallback = dispatchAutoRecall(instance, fallbackQuery);
331
+ }
332
+ const seen = new Set();
333
+ const merged = [];
334
+ for (const src of [primary, fallback]) {
335
+ if (!src || !Array.isArray(src.hits)) continue;
336
+ for (const h of src.hits) {
337
+ const id = h && (h.id || h.hash || h.key || JSON.stringify(h));
338
+ if (id && seen.has(id)) continue;
339
+ if (id) seen.add(id);
340
+ merged.push(h);
341
+ }
342
+ }
343
+ const queries = [];
344
+ if (primary && primary.query) queries.push(primary.query);
345
+ if (fallback && fallback.query && !queries.includes(fallback.query)) queries.push(fallback.query);
346
+ const payload = {
347
+ query: (primary && primary.query) || '',
348
+ queries,
349
+ hits: merged.slice(0, 20),
350
+ fired_at: new Date().toISOString(),
351
+ turn_entry: true,
352
+ };
353
+ logEvent('plugkit', 'auto_recall.turn-entry', { sess, queries, count: merged.length });
302
354
  return payload;
303
355
  } catch (e) {
304
356
  logEvent('plugkit', 'auto_recall.error', { sess, error: String(e && e.message || e) });