@modootoday/pmcp 0.17.2 → 0.17.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.
@@ -612,7 +612,7 @@
612
612
  },
613
613
  {
614
614
  "name": "pmcp",
615
- "version": "0.17.2",
615
+ "version": "0.17.4",
616
616
  "description": "Find package skills and use native runtime project configuration.",
617
617
  "source": { "source": "local", "path": "./plugins/pmcp" },
618
618
  "policy": { "installation": "AVAILABLE", "authentication": "ON_USE" },
@@ -445,7 +445,7 @@
445
445
  },
446
446
  {
447
447
  "name": "pmcp",
448
- "version": "0.17.2",
448
+ "version": "0.17.4",
449
449
  "description": "Find package skills and use native runtime project configuration.",
450
450
  "source": "./plugins/pmcp"
451
451
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcp",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "description": "Find package skills and use native runtime project configuration.",
5
5
  "author": { "name": "modootoday" },
6
6
  "license": "Elastic-2.0",
package/dist/cli.js CHANGED
@@ -9225,6 +9225,30 @@ function flatMetadata(metadata2) {
9225
9225
  }
9226
9226
  return flat;
9227
9227
  }
9228
+ function namedFirst(result, entries, intent) {
9229
+ const text3 = intent.toLowerCase();
9230
+ const named2 = entries.filter((entry2) => {
9231
+ const slug = entry2.slug.toLowerCase();
9232
+ if (slug.length < 4) return false;
9233
+ const at = text3.indexOf(slug);
9234
+ if (at === -1) return false;
9235
+ const before = text3[at - 1] ?? " ";
9236
+ const after = text3[at + slug.length] ?? " ";
9237
+ return !/[a-z0-9-]/.test(before) && !/[a-z0-9-]/.test(after);
9238
+ });
9239
+ if (named2.length === 0) return result;
9240
+ const top = result.matches[0]?.score ?? 1;
9241
+ const names = new Set(named2.map((entry2) => entry2.name));
9242
+ const first = named2.map((entry2) => ({
9243
+ name: entry2.name,
9244
+ package: entry2.package,
9245
+ description: entry2.description,
9246
+ score: result.matches.find((m) => m.name === entry2.name)?.score ?? top
9247
+ }));
9248
+ const rest = result.matches.filter((match) => !names.has(match.name));
9249
+ const size = Math.max(result.matches.length, first.length);
9250
+ return { ...result, matches: [...first, ...rest].slice(0, size) };
9251
+ }
9228
9252
  function createSkillTools(options2) {
9229
9253
  const load = options2.loadCatalog ?? readCatalog;
9230
9254
  let entries = null;
@@ -9240,7 +9264,14 @@ function createSkillTools(options2) {
9240
9264
  });
9241
9265
  return entries;
9242
9266
  };
9243
- const byName = (name) => catalog().find((candidate2) => candidate2.name === name) ?? null;
9267
+ const byName = (name) => {
9268
+ const all = catalog();
9269
+ const exact = all.find((candidate2) => candidate2.name === name);
9270
+ if (exact) return exact;
9271
+ const suffix = `/${name.replace(/^\/+/, "")}`;
9272
+ const short = all.filter((candidate2) => candidate2.name.endsWith(suffix));
9273
+ return short.length === 1 ? short[0] : null;
9274
+ };
9244
9275
  return {
9245
9276
  /**
9246
9277
  * Grouped, and without bodies. The cheap overview and the search's miss
@@ -9301,7 +9332,8 @@ function createSkillTools(options2) {
9301
9332
  embedder: options2.embedder,
9302
9333
  cache: options2.cache,
9303
9334
  vectors: options2.vectors
9304
- }).then((result) => {
9335
+ }).then((ranked) => {
9336
+ const result = namedFirst(ranked, scoped, intent);
9305
9337
  const marked = result.matches.map((match) => {
9306
9338
  const entry2 = byName(match.name) ?? void 0;
9307
9339
  return {
@@ -9855,7 +9887,7 @@ function registerMailboxTools(server, service) {
9855
9887
 
9856
9888
  // src/mcp.ts
9857
9889
  var SERVER_NAME = "pmcp";
9858
- var SERVER_VERSION = "0.17.2";
9890
+ var SERVER_VERSION = "0.17.4";
9859
9891
  function registerSkillTools(server, tools) {
9860
9892
  registerCatalogTool(server, tools);
9861
9893
  registerFindTool(server, tools);
@@ -12594,13 +12626,19 @@ function evaluateShellHook(root, policy, tool, payload) {
12594
12626
  if (typeof name !== "string") {
12595
12627
  return denied();
12596
12628
  }
12597
- if (!shellNames[tool].includes(name)) {
12629
+ const afterEdit = policy.event === "after_edit";
12630
+ if (afterEdit && tool !== "codex") {
12631
+ return denied();
12632
+ }
12633
+ const matches2 = afterEdit ? name === "apply_patch" : shellNames[tool].includes(name);
12634
+ if (!matches2) {
12598
12635
  return { decision: "allow" };
12599
12636
  }
12600
12637
  const command3 = scalar(
12601
12638
  input[tool === "antigravity" ? "CommandLine" : "command"]
12602
12639
  );
12603
- if (command3 === void 0 || command3.length > 65536) {
12640
+ const limit = afterEdit ? 16 * 1024 * 1024 : 65536;
12641
+ if (command3 === void 0 || command3.length > limit) {
12604
12642
  return denied();
12605
12643
  }
12606
12644
  const cwd = scalar(input["Cwd"]) ?? scalar(value["cwd"]) ?? root;
@@ -12620,7 +12658,7 @@ function evaluateShellHook(root, policy, tool, payload) {
12620
12658
  env: { PATH: process.env["PATH"], LANG: "C.UTF-8" },
12621
12659
  input: JSON.stringify({
12622
12660
  runtime: tool,
12623
- event: "before_shell",
12661
+ event: afterEdit ? "after_edit" : "before_shell",
12624
12662
  command: command3,
12625
12663
  cwd
12626
12664
  }),
@@ -12646,7 +12684,14 @@ function evaluateShellHook(root, policy, tool, payload) {
12646
12684
  return denied();
12647
12685
  }
12648
12686
  }
12649
- function nativeHookDecision(tool, decision) {
12687
+ function nativeHookDecision(tool, decision, event) {
12688
+ if (tool === "codex" && event === "after_edit") {
12689
+ if (decision.decision === "allow") return {};
12690
+ return {
12691
+ decision: "block",
12692
+ reason: decision.reason ?? "Edit guard failed validation or execution"
12693
+ };
12694
+ }
12650
12695
  if (tool === "codex") {
12651
12696
  return {
12652
12697
  hookSpecificOutput: {
@@ -12659,7 +12704,8 @@ function nativeHookDecision(tool, decision) {
12659
12704
  return decision;
12660
12705
  }
12661
12706
  async function main() {
12662
- const [, , , tool, file2, integrity2] = process.argv;
12707
+ const [, , , tool, file2, integrity2, event] = process.argv;
12708
+ const afterEdit = event === "after_edit";
12663
12709
  const supported = tool === "codex" || tool === "gemini" || tool === "antigravity";
12664
12710
  if (!supported) {
12665
12711
  process.exitCode = 2;
@@ -12667,6 +12713,9 @@ async function main() {
12667
12713
  }
12668
12714
  let decision = denied();
12669
12715
  try {
12716
+ if (event !== void 0 && !afterEdit) {
12717
+ throw new Error("Unknown hook event");
12718
+ }
12670
12719
  if (!file2) {
12671
12720
  throw new Error("Missing hook policy");
12672
12721
  }
@@ -12677,7 +12726,7 @@ async function main() {
12677
12726
  throw new Error("Hook integrity mismatch");
12678
12727
  }
12679
12728
  const policy = JSON.parse(bytes.toString("utf8"));
12680
- if (!policy.targets.includes(tool)) {
12729
+ if (!policy.targets.includes(tool) || policy.event !== event) {
12681
12730
  throw new Error("Hook target mismatch");
12682
12731
  }
12683
12732
  const chunks = [];
@@ -12685,7 +12734,7 @@ async function main() {
12685
12734
  for await (const chunk of process.stdin) {
12686
12735
  const bytes2 = Buffer.from(chunk);
12687
12736
  size += bytes2.length;
12688
- if (size > 131072) {
12737
+ if (size > (afterEdit ? 16 * 1024 * 1024 : 131072)) {
12689
12738
  throw new Error("Hook input too large");
12690
12739
  }
12691
12740
  chunks.push(bytes2);
@@ -12707,7 +12756,7 @@ async function main() {
12707
12756
  decision = denied();
12708
12757
  }
12709
12758
  process.stdout.write(
12710
- `${JSON.stringify(nativeHookDecision(tool, decision))}
12759
+ `${JSON.stringify(nativeHookDecision(tool, decision, afterEdit ? "after_edit" : void 0))}
12711
12760
  `
12712
12761
  );
12713
12762
  }
@@ -12735,6 +12784,11 @@ var native = {
12735
12784
  matcher: "run_command"
12736
12785
  }
12737
12786
  };
12787
+ var editNative = {
12788
+ file: ".codex/hooks.json",
12789
+ key: ["hooks", "PostToolUse"],
12790
+ matcher: "^apply_patch$"
12791
+ };
12738
12792
  function object4(value) {
12739
12793
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
12740
12794
  throw new ProjectError(
@@ -12808,8 +12862,12 @@ function hookOutputs(spec) {
12808
12862
  if (!spec.tools.has(tool)) {
12809
12863
  continue;
12810
12864
  }
12811
- const target2 = native[tool];
12812
- const command3 = `d="$PWD"; while [ ! -f "$d/pmcp.toml" ]; do [ "$d" = / ] && exit 1; d=$(dirname "$d"); done; exec node "$d/${ADAPTER}" --pmcp-shell-hook ${tool} "$d/${policyFile}" ${integrity2}`;
12865
+ if (hook.event === "after_edit" && tool !== "codex") {
12866
+ throw new ProjectError("Edit hooks currently support codex only");
12867
+ }
12868
+ const target2 = hook.event === "after_edit" ? editNative : native[tool];
12869
+ const eventArgument = hook.event === "after_edit" ? " after_edit" : "";
12870
+ const command3 = `d="$PWD"; while [ ! -f "$d/pmcp.toml" ]; do [ "$d" = / ] && exit 1; d=$(dirname "$d"); done; exec node "$d/${ADAPTER}" --pmcp-shell-hook ${tool} "$d/${policyFile}" ${integrity2}${eventArgument}`;
12813
12871
  const timeout = tool === "gemini" ? hook.timeoutMs + 2e3 : Math.ceil(hook.timeoutMs / 1e3) + 2;
12814
12872
  const value = {
12815
12873
  matcher: target2.matcher,
@@ -12829,7 +12887,7 @@ function hookOutputs(spec) {
12829
12887
  const same2 = (left, right) => JSON.stringify(left) === JSON.stringify(right);
12830
12888
  for (const path of /* @__PURE__ */ new Set([...desired.keys(), ...previous.keys()])) {
12831
12889
  const parts = splitKeyed(path);
12832
- if (!parts || !Object.values(native).some(
12890
+ if (!parts || ![...Object.values(native), editNative].some(
12833
12891
  (entry2) => entry2.file === parts.file && entry2.key.join(".") === parts.key.join(".")
12834
12892
  )) {
12835
12893
  throw new ProjectError("Unknown managed hook path in pmcp.lock");
@@ -13536,11 +13594,18 @@ function readHooks(path, root, raw) {
13536
13594
  return fail2("must be a table");
13537
13595
  }
13538
13596
  const table2 = raw;
13539
- if (Object.keys(table2).some((key) => key !== "shell") || !Array.isArray(table2["shell"])) {
13540
- return fail2("only [[hooks.shell]] declarations are supported");
13597
+ if (Object.keys(table2).some((key) => key !== "shell" && key !== "edit") || !["shell", "edit"].some((key) => table2[key] !== void 0) || ["shell", "edit"].some(
13598
+ (key) => table2[key] !== void 0 && !Array.isArray(table2[key])
13599
+ )) {
13600
+ return fail2(
13601
+ "only [[hooks.shell]] and [[hooks.edit]] declarations are supported"
13602
+ );
13541
13603
  }
13542
13604
  const names = /* @__PURE__ */ new Set();
13543
- return table2["shell"].map((value) => {
13605
+ const entries = ["shell", "edit"].flatMap(
13606
+ (kind2) => (table2[kind2] ?? []).map((value) => ({ kind: kind2, value }))
13607
+ );
13608
+ return entries.map(({ kind: kind2, value }) => {
13544
13609
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
13545
13610
  return fail2("shell entry must be a table");
13546
13611
  }
@@ -13567,6 +13632,9 @@ function readHooks(path, root, raw) {
13567
13632
  ) || new Set(targets).size !== targets.length) {
13568
13633
  return fail2("targets must select unique supported shell adapters");
13569
13634
  }
13635
+ if (kind2 === "edit" && targets.some((tool) => tool !== "codex")) {
13636
+ return fail2("edit hooks currently support codex only");
13637
+ }
13570
13638
  if (typeof timeoutMs !== "number" || !Number.isSafeInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 6e4) {
13571
13639
  return fail2("timeout_ms must be an integer from 100 to 60000");
13572
13640
  }
@@ -13582,7 +13650,8 @@ function readHooks(path, root, raw) {
13582
13650
  name,
13583
13651
  command: command3,
13584
13652
  targets,
13585
- timeoutMs
13653
+ timeoutMs,
13654
+ ...kind2 === "edit" ? { event: "after_edit" } : {}
13586
13655
  };
13587
13656
  }).sort((a, b) => a.name.localeCompare(b.name, "en"));
13588
13657
  }
@@ -16157,7 +16226,7 @@ function dispatch(argv, options2 = {}) {
16157
16226
  }
16158
16227
  return run(command3, rest, { ui, env, cwd });
16159
16228
  }
16160
- var VERSION = "0.17.2";
16229
+ var VERSION = "0.17.4";
16161
16230
  async function defaultEntry(options2, context) {
16162
16231
  const terminal = options2.terminal ?? {
16163
16232
  stdin: process.stdin.isTTY === true,
@@ -5,6 +5,7 @@ interface ShellHookSpec {
5
5
  readonly command: readonly string[];
6
6
  readonly targets: readonly HookTool[];
7
7
  readonly timeoutMs: number;
8
+ readonly event?: "after_edit";
8
9
  }
9
10
 
10
11
  export type { HookTool as H, ShellHookSpec as S };
package/dist/http.js CHANGED
@@ -1611,6 +1611,30 @@ function flatMetadata(metadata) {
1611
1611
  }
1612
1612
  return flat;
1613
1613
  }
1614
+ function namedFirst(result, entries, intent) {
1615
+ const text = intent.toLowerCase();
1616
+ const named = entries.filter((entry) => {
1617
+ const slug = entry.slug.toLowerCase();
1618
+ if (slug.length < 4) return false;
1619
+ const at = text.indexOf(slug);
1620
+ if (at === -1) return false;
1621
+ const before = text[at - 1] ?? " ";
1622
+ const after = text[at + slug.length] ?? " ";
1623
+ return !/[a-z0-9-]/.test(before) && !/[a-z0-9-]/.test(after);
1624
+ });
1625
+ if (named.length === 0) return result;
1626
+ const top = result.matches[0]?.score ?? 1;
1627
+ const names = new Set(named.map((entry) => entry.name));
1628
+ const first = named.map((entry) => ({
1629
+ name: entry.name,
1630
+ package: entry.package,
1631
+ description: entry.description,
1632
+ score: result.matches.find((m) => m.name === entry.name)?.score ?? top
1633
+ }));
1634
+ const rest = result.matches.filter((match) => !names.has(match.name));
1635
+ const size = Math.max(result.matches.length, first.length);
1636
+ return { ...result, matches: [...first, ...rest].slice(0, size) };
1637
+ }
1614
1638
  function createSkillTools(options) {
1615
1639
  const load = options.loadCatalog ?? readCatalog;
1616
1640
  let entries = null;
@@ -1626,7 +1650,14 @@ function createSkillTools(options) {
1626
1650
  });
1627
1651
  return entries;
1628
1652
  };
1629
- const byName = (name) => catalog().find((candidate) => candidate.name === name) ?? null;
1653
+ const byName = (name) => {
1654
+ const all = catalog();
1655
+ const exact = all.find((candidate) => candidate.name === name);
1656
+ if (exact) return exact;
1657
+ const suffix = `/${name.replace(/^\/+/, "")}`;
1658
+ const short = all.filter((candidate) => candidate.name.endsWith(suffix));
1659
+ return short.length === 1 ? short[0] : null;
1660
+ };
1630
1661
  return {
1631
1662
  /**
1632
1663
  * Grouped, and without bodies. The cheap overview and the search's miss
@@ -1687,7 +1718,8 @@ function createSkillTools(options) {
1687
1718
  embedder: options.embedder,
1688
1719
  cache: options.cache,
1689
1720
  vectors: options.vectors
1690
- }).then((result) => {
1721
+ }).then((ranked) => {
1722
+ const result = namedFirst(ranked, scoped, intent);
1691
1723
  const marked = result.matches.map((match) => {
1692
1724
  const entry = byName(match.name) ?? void 0;
1693
1725
  return {
@@ -2290,7 +2322,7 @@ function registerMailboxTools(server, service) {
2290
2322
 
2291
2323
  // src/mcp.ts
2292
2324
  var SERVER_NAME = "pmcp";
2293
- var SERVER_VERSION = "0.17.2";
2325
+ var SERVER_VERSION = "0.17.4";
2294
2326
  function registerSkillTools(server, tools) {
2295
2327
  registerCatalogTool(server, tools);
2296
2328
  registerFindTool(server, tools);
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { E as EntryVectorStore, e as encodeEntries, l as loadEmbedder, o as open
5
5
  export { D as DEFAULT_MODEL_ID, a as EmbeddingModel, b as EncoderDtype, E as EncoderOptions, c as EncoderSpec, R as ResolvedEncoder, e as embeddingModels, d as encoderSpec, r as resolveEncoder } from './encoder-DGRy9skC.js';
6
6
  import { P as ProjectConfig } from './config-BkSpjUG6.js';
7
7
  export { C as CONFIG_FILE, a as CatalogSection, b as ConfigError, E as EmbeddingSection, f as findConfig, r as readConfig } from './config-BkSpjUG6.js';
8
- import { S as ShellHookSpec } from './hook-spec-PRSnYGLV.js';
8
+ import { S as ShellHookSpec } from './hook-spec-CSJJySsH.js';
9
9
  import { McpServer } from '@modelcontextprotocol/server';
10
10
  import { M as MailboxService } from './service-qpCsOXkQ.js';
11
11
  import 'zod';
@@ -275,7 +275,7 @@ declare function resolveSkillFileUri(uri: string, entries: readonly SkillEntry[]
275
275
 
276
276
  /** Reported to the host on connect. */
277
277
  declare const SERVER_NAME = "pmcp";
278
- declare const SERVER_VERSION = "0.17.2";
278
+ declare const SERVER_VERSION = "0.17.4";
279
279
  /**
280
280
  * Registers the skill_* tools on a server.
281
281
  *
package/dist/index.js CHANGED
@@ -1790,13 +1790,19 @@ function evaluateShellHook(root, policy, tool, payload) {
1790
1790
  if (typeof name !== "string") {
1791
1791
  return denied();
1792
1792
  }
1793
- if (!shellNames[tool].includes(name)) {
1793
+ const afterEdit = policy.event === "after_edit";
1794
+ if (afterEdit && tool !== "codex") {
1795
+ return denied();
1796
+ }
1797
+ const matches2 = afterEdit ? name === "apply_patch" : shellNames[tool].includes(name);
1798
+ if (!matches2) {
1794
1799
  return { decision: "allow" };
1795
1800
  }
1796
1801
  const command = scalar(
1797
1802
  input[tool === "antigravity" ? "CommandLine" : "command"]
1798
1803
  );
1799
- if (command === void 0 || command.length > 65536) {
1804
+ const limit = afterEdit ? 16 * 1024 * 1024 : 65536;
1805
+ if (command === void 0 || command.length > limit) {
1800
1806
  return denied();
1801
1807
  }
1802
1808
  const cwd = scalar(input["Cwd"]) ?? scalar(value["cwd"]) ?? root;
@@ -1816,7 +1822,7 @@ function evaluateShellHook(root, policy, tool, payload) {
1816
1822
  env: { PATH: process.env["PATH"], LANG: "C.UTF-8" },
1817
1823
  input: JSON.stringify({
1818
1824
  runtime: tool,
1819
- event: "before_shell",
1825
+ event: afterEdit ? "after_edit" : "before_shell",
1820
1826
  command,
1821
1827
  cwd
1822
1828
  }),
@@ -1842,7 +1848,14 @@ function evaluateShellHook(root, policy, tool, payload) {
1842
1848
  return denied();
1843
1849
  }
1844
1850
  }
1845
- function nativeHookDecision(tool, decision) {
1851
+ function nativeHookDecision(tool, decision, event) {
1852
+ if (tool === "codex" && event === "after_edit") {
1853
+ if (decision.decision === "allow") return {};
1854
+ return {
1855
+ decision: "block",
1856
+ reason: decision.reason ?? "Edit guard failed validation or execution"
1857
+ };
1858
+ }
1846
1859
  if (tool === "codex") {
1847
1860
  return {
1848
1861
  hookSpecificOutput: {
@@ -1855,7 +1868,8 @@ function nativeHookDecision(tool, decision) {
1855
1868
  return decision;
1856
1869
  }
1857
1870
  async function main() {
1858
- const [, , , tool, file, integrity] = process.argv;
1871
+ const [, , , tool, file, integrity, event] = process.argv;
1872
+ const afterEdit = event === "after_edit";
1859
1873
  const supported = tool === "codex" || tool === "gemini" || tool === "antigravity";
1860
1874
  if (!supported) {
1861
1875
  process.exitCode = 2;
@@ -1863,6 +1877,9 @@ async function main() {
1863
1877
  }
1864
1878
  let decision = denied();
1865
1879
  try {
1880
+ if (event !== void 0 && !afterEdit) {
1881
+ throw new Error("Unknown hook event");
1882
+ }
1866
1883
  if (!file) {
1867
1884
  throw new Error("Missing hook policy");
1868
1885
  }
@@ -1873,7 +1890,7 @@ async function main() {
1873
1890
  throw new Error("Hook integrity mismatch");
1874
1891
  }
1875
1892
  const policy = JSON.parse(bytes.toString("utf8"));
1876
- if (!policy.targets.includes(tool)) {
1893
+ if (!policy.targets.includes(tool) || policy.event !== event) {
1877
1894
  throw new Error("Hook target mismatch");
1878
1895
  }
1879
1896
  const chunks = [];
@@ -1881,7 +1898,7 @@ async function main() {
1881
1898
  for await (const chunk of process.stdin) {
1882
1899
  const bytes2 = Buffer.from(chunk);
1883
1900
  size += bytes2.length;
1884
- if (size > 131072) {
1901
+ if (size > (afterEdit ? 16 * 1024 * 1024 : 131072)) {
1885
1902
  throw new Error("Hook input too large");
1886
1903
  }
1887
1904
  chunks.push(bytes2);
@@ -1903,7 +1920,7 @@ async function main() {
1903
1920
  decision = denied();
1904
1921
  }
1905
1922
  process.stdout.write(
1906
- `${JSON.stringify(nativeHookDecision(tool, decision))}
1923
+ `${JSON.stringify(nativeHookDecision(tool, decision, afterEdit ? "after_edit" : void 0))}
1907
1924
  `
1908
1925
  );
1909
1926
  }
@@ -1924,11 +1941,18 @@ function readHooks(path, root, raw) {
1924
1941
  return fail2("must be a table");
1925
1942
  }
1926
1943
  const table2 = raw;
1927
- if (Object.keys(table2).some((key) => key !== "shell") || !Array.isArray(table2["shell"])) {
1928
- return fail2("only [[hooks.shell]] declarations are supported");
1944
+ if (Object.keys(table2).some((key) => key !== "shell" && key !== "edit") || !["shell", "edit"].some((key) => table2[key] !== void 0) || ["shell", "edit"].some(
1945
+ (key) => table2[key] !== void 0 && !Array.isArray(table2[key])
1946
+ )) {
1947
+ return fail2(
1948
+ "only [[hooks.shell]] and [[hooks.edit]] declarations are supported"
1949
+ );
1929
1950
  }
1930
1951
  const names = /* @__PURE__ */ new Set();
1931
- return table2["shell"].map((value) => {
1952
+ const entries = ["shell", "edit"].flatMap(
1953
+ (kind2) => (table2[kind2] ?? []).map((value) => ({ kind: kind2, value }))
1954
+ );
1955
+ return entries.map(({ kind: kind2, value }) => {
1932
1956
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
1933
1957
  return fail2("shell entry must be a table");
1934
1958
  }
@@ -1955,6 +1979,9 @@ function readHooks(path, root, raw) {
1955
1979
  ) || new Set(targets).size !== targets.length) {
1956
1980
  return fail2("targets must select unique supported shell adapters");
1957
1981
  }
1982
+ if (kind2 === "edit" && targets.some((tool) => tool !== "codex")) {
1983
+ return fail2("edit hooks currently support codex only");
1984
+ }
1958
1985
  if (typeof timeoutMs !== "number" || !Number.isSafeInteger(timeoutMs) || timeoutMs < 100 || timeoutMs > 6e4) {
1959
1986
  return fail2("timeout_ms must be an integer from 100 to 60000");
1960
1987
  }
@@ -1970,7 +1997,8 @@ function readHooks(path, root, raw) {
1970
1997
  name,
1971
1998
  command,
1972
1999
  targets,
1973
- timeoutMs
2000
+ timeoutMs,
2001
+ ...kind2 === "edit" ? { event: "after_edit" } : {}
1974
2002
  };
1975
2003
  }).sort((a, b) => a.name.localeCompare(b.name, "en"));
1976
2004
  }
@@ -2579,6 +2607,11 @@ var native = {
2579
2607
  matcher: "run_command"
2580
2608
  }
2581
2609
  };
2610
+ var editNative = {
2611
+ file: ".codex/hooks.json",
2612
+ key: ["hooks", "PostToolUse"],
2613
+ matcher: "^apply_patch$"
2614
+ };
2582
2615
  function object4(value) {
2583
2616
  if (value === null || typeof value !== "object" || Array.isArray(value)) {
2584
2617
  throw new ProjectError(
@@ -2652,8 +2685,12 @@ function hookOutputs(spec) {
2652
2685
  if (!spec.tools.has(tool)) {
2653
2686
  continue;
2654
2687
  }
2655
- const target = native[tool];
2656
- const command = `d="$PWD"; while [ ! -f "$d/pmcp.toml" ]; do [ "$d" = / ] && exit 1; d=$(dirname "$d"); done; exec node "$d/${ADAPTER}" --pmcp-shell-hook ${tool} "$d/${policyFile}" ${integrity}`;
2688
+ if (hook.event === "after_edit" && tool !== "codex") {
2689
+ throw new ProjectError("Edit hooks currently support codex only");
2690
+ }
2691
+ const target = hook.event === "after_edit" ? editNative : native[tool];
2692
+ const eventArgument = hook.event === "after_edit" ? " after_edit" : "";
2693
+ const command = `d="$PWD"; while [ ! -f "$d/pmcp.toml" ]; do [ "$d" = / ] && exit 1; d=$(dirname "$d"); done; exec node "$d/${ADAPTER}" --pmcp-shell-hook ${tool} "$d/${policyFile}" ${integrity}${eventArgument}`;
2657
2694
  const timeout = tool === "gemini" ? hook.timeoutMs + 2e3 : Math.ceil(hook.timeoutMs / 1e3) + 2;
2658
2695
  const value = {
2659
2696
  matcher: target.matcher,
@@ -2673,7 +2710,7 @@ function hookOutputs(spec) {
2673
2710
  const same2 = (left, right) => JSON.stringify(left) === JSON.stringify(right);
2674
2711
  for (const path of /* @__PURE__ */ new Set([...desired.keys(), ...previous.keys()])) {
2675
2712
  const parts = splitKeyed(path);
2676
- if (!parts || !Object.values(native).some(
2713
+ if (!parts || ![...Object.values(native), editNative].some(
2677
2714
  (entry) => entry.file === parts.file && entry.key.join(".") === parts.key.join(".")
2678
2715
  )) {
2679
2716
  throw new ProjectError("Unknown managed hook path in pmcp.lock");
@@ -4058,6 +4095,30 @@ function flatMetadata(metadata) {
4058
4095
  }
4059
4096
  return flat;
4060
4097
  }
4098
+ function namedFirst(result, entries, intent) {
4099
+ const text = intent.toLowerCase();
4100
+ const named2 = entries.filter((entry) => {
4101
+ const slug = entry.slug.toLowerCase();
4102
+ if (slug.length < 4) return false;
4103
+ const at = text.indexOf(slug);
4104
+ if (at === -1) return false;
4105
+ const before = text[at - 1] ?? " ";
4106
+ const after = text[at + slug.length] ?? " ";
4107
+ return !/[a-z0-9-]/.test(before) && !/[a-z0-9-]/.test(after);
4108
+ });
4109
+ if (named2.length === 0) return result;
4110
+ const top = result.matches[0]?.score ?? 1;
4111
+ const names = new Set(named2.map((entry) => entry.name));
4112
+ const first = named2.map((entry) => ({
4113
+ name: entry.name,
4114
+ package: entry.package,
4115
+ description: entry.description,
4116
+ score: result.matches.find((m) => m.name === entry.name)?.score ?? top
4117
+ }));
4118
+ const rest = result.matches.filter((match) => !names.has(match.name));
4119
+ const size = Math.max(result.matches.length, first.length);
4120
+ return { ...result, matches: [...first, ...rest].slice(0, size) };
4121
+ }
4061
4122
  function createSkillTools(options) {
4062
4123
  const load = options.loadCatalog ?? readCatalog;
4063
4124
  let entries = null;
@@ -4073,7 +4134,14 @@ function createSkillTools(options) {
4073
4134
  });
4074
4135
  return entries;
4075
4136
  };
4076
- const byName = (name) => catalog().find((candidate) => candidate.name === name) ?? null;
4137
+ const byName = (name) => {
4138
+ const all = catalog();
4139
+ const exact = all.find((candidate) => candidate.name === name);
4140
+ if (exact) return exact;
4141
+ const suffix = `/${name.replace(/^\/+/, "")}`;
4142
+ const short = all.filter((candidate) => candidate.name.endsWith(suffix));
4143
+ return short.length === 1 ? short[0] : null;
4144
+ };
4077
4145
  return {
4078
4146
  /**
4079
4147
  * Grouped, and without bodies. The cheap overview and the search's miss
@@ -4134,7 +4202,8 @@ function createSkillTools(options) {
4134
4202
  embedder: options.embedder,
4135
4203
  cache: options.cache,
4136
4204
  vectors: options.vectors
4137
- }).then((result) => {
4205
+ }).then((ranked) => {
4206
+ const result = namedFirst(ranked, scoped, intent);
4138
4207
  const marked = result.matches.map((match) => {
4139
4208
  const entry = byName(match.name) ?? void 0;
4140
4209
  return {
@@ -4837,7 +4906,7 @@ function registerMailboxTools(server, service) {
4837
4906
 
4838
4907
  // src/mcp.ts
4839
4908
  var SERVER_NAME = "pmcp";
4840
- var SERVER_VERSION = "0.17.2";
4909
+ var SERVER_VERSION = "0.17.4";
4841
4910
  function registerSkillTools(server, tools) {
4842
4911
  registerCatalogTool(server, tools);
4843
4912
  registerFindTool(server, tools);
@@ -1,4 +1,4 @@
1
- import { S as ShellHookSpec, H as HookTool } from '../hook-spec-PRSnYGLV.js';
1
+ import { S as ShellHookSpec, H as HookTool } from '../hook-spec-CSJJySsH.js';
2
2
 
3
3
  type Decision = {
4
4
  readonly decision: "allow" | "deny";
@@ -6,6 +6,6 @@ type Decision = {
6
6
  };
7
7
  declare function guardPath(root: string, command: readonly string[]): string;
8
8
  declare function evaluateShellHook(root: string, policy: ShellHookSpec, tool: HookTool, payload: unknown): Decision;
9
- declare function nativeHookDecision(tool: HookTool, decision: Decision): object;
9
+ declare function nativeHookDecision(tool: HookTool, decision: Decision, event?: ShellHookSpec["event"]): object;
10
10
 
11
11
  export { evaluateShellHook, guardPath, nativeHookDecision };
@@ -63,13 +63,19 @@ function evaluateShellHook(root, policy, tool, payload) {
63
63
  if (typeof name !== "string") {
64
64
  return denied();
65
65
  }
66
- if (!shellNames[tool].includes(name)) {
66
+ const afterEdit = policy.event === "after_edit";
67
+ if (afterEdit && tool !== "codex") {
68
+ return denied();
69
+ }
70
+ const matches = afterEdit ? name === "apply_patch" : shellNames[tool].includes(name);
71
+ if (!matches) {
67
72
  return { decision: "allow" };
68
73
  }
69
74
  const command = scalar(
70
75
  input[tool === "antigravity" ? "CommandLine" : "command"]
71
76
  );
72
- if (command === void 0 || command.length > 65536) {
77
+ const limit = afterEdit ? 16 * 1024 * 1024 : 65536;
78
+ if (command === void 0 || command.length > limit) {
73
79
  return denied();
74
80
  }
75
81
  const cwd = scalar(input["Cwd"]) ?? scalar(value["cwd"]) ?? root;
@@ -89,7 +95,7 @@ function evaluateShellHook(root, policy, tool, payload) {
89
95
  env: { PATH: process.env["PATH"], LANG: "C.UTF-8" },
90
96
  input: JSON.stringify({
91
97
  runtime: tool,
92
- event: "before_shell",
98
+ event: afterEdit ? "after_edit" : "before_shell",
93
99
  command,
94
100
  cwd
95
101
  }),
@@ -115,7 +121,14 @@ function evaluateShellHook(root, policy, tool, payload) {
115
121
  return denied();
116
122
  }
117
123
  }
118
- function nativeHookDecision(tool, decision) {
124
+ function nativeHookDecision(tool, decision, event) {
125
+ if (tool === "codex" && event === "after_edit") {
126
+ if (decision.decision === "allow") return {};
127
+ return {
128
+ decision: "block",
129
+ reason: decision.reason ?? "Edit guard failed validation or execution"
130
+ };
131
+ }
119
132
  if (tool === "codex") {
120
133
  return {
121
134
  hookSpecificOutput: {
@@ -128,7 +141,8 @@ function nativeHookDecision(tool, decision) {
128
141
  return decision;
129
142
  }
130
143
  async function main() {
131
- const [, , , tool, file, integrity] = process.argv;
144
+ const [, , , tool, file, integrity, event] = process.argv;
145
+ const afterEdit = event === "after_edit";
132
146
  const supported = tool === "codex" || tool === "gemini" || tool === "antigravity";
133
147
  if (!supported) {
134
148
  process.exitCode = 2;
@@ -136,6 +150,9 @@ async function main() {
136
150
  }
137
151
  let decision = denied();
138
152
  try {
153
+ if (event !== void 0 && !afterEdit) {
154
+ throw new Error("Unknown hook event");
155
+ }
139
156
  if (!file) {
140
157
  throw new Error("Missing hook policy");
141
158
  }
@@ -146,7 +163,7 @@ async function main() {
146
163
  throw new Error("Hook integrity mismatch");
147
164
  }
148
165
  const policy = JSON.parse(bytes.toString("utf8"));
149
- if (!policy.targets.includes(tool)) {
166
+ if (!policy.targets.includes(tool) || policy.event !== event) {
150
167
  throw new Error("Hook target mismatch");
151
168
  }
152
169
  const chunks = [];
@@ -154,7 +171,7 @@ async function main() {
154
171
  for await (const chunk of process.stdin) {
155
172
  const bytes2 = Buffer.from(chunk);
156
173
  size += bytes2.length;
157
- if (size > 131072) {
174
+ if (size > (afterEdit ? 16 * 1024 * 1024 : 131072)) {
158
175
  throw new Error("Hook input too large");
159
176
  }
160
177
  chunks.push(bytes2);
@@ -176,7 +193,7 @@ async function main() {
176
193
  decision = denied();
177
194
  }
178
195
  process.stdout.write(
179
- `${JSON.stringify(nativeHookDecision(tool, decision))}
196
+ `${JSON.stringify(nativeHookDecision(tool, decision, afterEdit ? "after_edit" : void 0))}
180
197
  `
181
198
  );
182
199
  }
package/dist/stdio.js CHANGED
@@ -1258,6 +1258,30 @@ function flatMetadata(metadata) {
1258
1258
  }
1259
1259
  return flat;
1260
1260
  }
1261
+ function namedFirst(result, entries, intent) {
1262
+ const text = intent.toLowerCase();
1263
+ const named = entries.filter((entry) => {
1264
+ const slug = entry.slug.toLowerCase();
1265
+ if (slug.length < 4) return false;
1266
+ const at = text.indexOf(slug);
1267
+ if (at === -1) return false;
1268
+ const before = text[at - 1] ?? " ";
1269
+ const after = text[at + slug.length] ?? " ";
1270
+ return !/[a-z0-9-]/.test(before) && !/[a-z0-9-]/.test(after);
1271
+ });
1272
+ if (named.length === 0) return result;
1273
+ const top = result.matches[0]?.score ?? 1;
1274
+ const names = new Set(named.map((entry) => entry.name));
1275
+ const first = named.map((entry) => ({
1276
+ name: entry.name,
1277
+ package: entry.package,
1278
+ description: entry.description,
1279
+ score: result.matches.find((m) => m.name === entry.name)?.score ?? top
1280
+ }));
1281
+ const rest = result.matches.filter((match) => !names.has(match.name));
1282
+ const size = Math.max(result.matches.length, first.length);
1283
+ return { ...result, matches: [...first, ...rest].slice(0, size) };
1284
+ }
1261
1285
  function createSkillTools(options) {
1262
1286
  const load = options.loadCatalog ?? readCatalog;
1263
1287
  let entries = null;
@@ -1273,7 +1297,14 @@ function createSkillTools(options) {
1273
1297
  });
1274
1298
  return entries;
1275
1299
  };
1276
- const byName = (name) => catalog().find((candidate) => candidate.name === name) ?? null;
1300
+ const byName = (name) => {
1301
+ const all = catalog();
1302
+ const exact = all.find((candidate) => candidate.name === name);
1303
+ if (exact) return exact;
1304
+ const suffix = `/${name.replace(/^\/+/, "")}`;
1305
+ const short = all.filter((candidate) => candidate.name.endsWith(suffix));
1306
+ return short.length === 1 ? short[0] : null;
1307
+ };
1277
1308
  return {
1278
1309
  /**
1279
1310
  * Grouped, and without bodies. The cheap overview and the search's miss
@@ -1334,7 +1365,8 @@ function createSkillTools(options) {
1334
1365
  embedder: options.embedder,
1335
1366
  cache: options.cache,
1336
1367
  vectors: options.vectors
1337
- }).then((result) => {
1368
+ }).then((ranked) => {
1369
+ const result = namedFirst(ranked, scoped, intent);
1338
1370
  const marked = result.matches.map((match) => {
1339
1371
  const entry = byName(match.name) ?? void 0;
1340
1372
  return {
@@ -1937,7 +1969,7 @@ function registerMailboxTools(server, service) {
1937
1969
 
1938
1970
  // src/mcp.ts
1939
1971
  var SERVER_NAME = "pmcp";
1940
- var SERVER_VERSION = "0.17.2";
1972
+ var SERVER_VERSION = "0.17.4";
1941
1973
  function registerSkillTools(server, tools) {
1942
1974
  registerCatalogTool(server, tools);
1943
1975
  registerFindTool(server, tools);
@@ -215,6 +215,29 @@ contain no trust bypass. Grok can load Claude project hooks, so this first scope
215
215
  does not generate a second Grok guard. Hooks do not force pmcp catalog use,
216
216
  inject reminders or replace the runtime's execution sandbox.
217
217
 
218
+ ## Operator edit guards
219
+
220
+ Codex edit guards run after apply_patch through native PostToolUse hooks:
221
+
222
+ ```toml
223
+ [[hooks.edit]]
224
+ name = "edit-policy"
225
+ command = ["node", ".agents/guards/edit-policy.mjs"]
226
+ targets = ["codex"]
227
+ timeout_ms = 15000
228
+ ```
229
+
230
+ The guard receives runtime=codex, event=after_edit, the patch in command and cwd.
231
+ It returns the same allow/deny response as a shell guard. A denial becomes
232
+ native blocking feedback with the reason; the completed file edit remains on disk
233
+ for correction. Other tools do not invoke this guard. Edit targets currently
234
+ support Codex only, and names must be unique across shell and edit declarations.
235
+
236
+ Run pmcp project after declaring or changing the guard, then review and trust
237
+ the generated native definition in /hooks. Peer entries and shell guards are
238
+ preserved. Fingerprints and failure handling follow the shell-guard contract.
239
+ See the [native hooks documentation](https://learn.chatgpt.com/docs/hooks).
240
+
218
241
  ## Native memory metadata
219
242
 
220
243
  ```sh
package/docs/skills.md CHANGED
@@ -9,7 +9,9 @@ Skills are discovered by filename, including `skills/`, `.agents/skills/`,
9
9
  `lib/skill/` layouts
10
10
  within the discovery depth. A skill needs a frontmatter `description` for search.
11
11
 
12
- `skill_find` accepts a problem description and returns matching skills.
12
+ `skill_find` accepts a problem description and returns matching skills; a skill whose short
13
+ name appears in the request as a whole word is listed first. The other tools take a skill's
14
+ full name, or a short name that belongs to exactly one skill, and answer with the full name.
13
15
  `skill_call` opens the selected document and lists the reference, script and asset
14
16
  files it carries as a text list. It attaches no resource links, because some clients ask
15
17
  the user to create every linked file as an attachment. Local MCP reading requires no login.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcp",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "mcpServers": {
5
5
  "pmcp": {
6
6
  "type": "stdio",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modootoday/pmcp",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "license": "Elastic-2.0",
5
5
  "author": "modootoday",
6
6
  "description": "Use the skills your packages already ship, and keep your AI tools' project configuration in one place.",
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "pmcp",
4
- "version": "0.17.2",
4
+ "version": "0.17.4",
5
5
  "description": "Find package skills and use native runtime project configuration.",
6
6
  "author": { "name": "modootoday" },
7
7
  "license": "Elastic-2.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcp",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "description": "Find package skills and use native runtime project configuration.",
5
5
  "author": { "name": "modootoday" },
6
6
  "license": "Elastic-2.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcp",
3
- "version": "0.17.2",
3
+ "version": "0.17.4",
4
4
  "mcpServers": {
5
5
  "pmcp": {
6
6
  "type": "stdio",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
3
3
  "name": "pmcp",
4
- "version": "0.17.2",
4
+ "version": "0.17.4",
5
5
  "description": "Find package skills and use native runtime project configuration.",
6
6
  "author": { "name": "modootoday" },
7
7
  "license": "Elastic-2.0",