@agentvalet/register 0.1.2 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +49 -1
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -189,7 +189,7 @@ async function saveOutput(opts) {
189
189
  }
190
190
 
191
191
  // src/commands/refresh.ts
192
- import { readFileSync, writeFileSync, mkdirSync, statSync } from "fs";
192
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, statSync } from "fs";
193
193
  import { createSign, createPrivateKey } from "crypto";
194
194
  import { dirname as dirname2, resolve as resolve2 } from "path";
195
195
 
@@ -317,10 +317,58 @@ Run 'agentvalet-register' first to create it.`);
317
317
  const content = generatePermissionsFile(agentId, ownerId, platforms);
318
318
  mkdirSync(dirname2(outputPath), { recursive: true });
319
319
  writeFileSync(outputPath, content, "utf-8");
320
+ ensureClaudeMd(options.outputPath);
321
+ ensureHook();
320
322
  if (!options.quiet) {
321
323
  console.log(`Permissions refreshed \u2192 ${outputPath} (${platforms.length} platform${platforms.length !== 1 ? "s" : ""})`);
322
324
  }
323
325
  }
326
+ function ensureClaudeMd(permissionsRelativePath) {
327
+ const importLine = `@${permissionsRelativePath.replace(/\\/g, "/").replace(/^\.\//, "")}`;
328
+ const claudeMdPath = resolve2("CLAUDE.md");
329
+ if (!existsSync(claudeMdPath)) {
330
+ writeFileSync(
331
+ claudeMdPath,
332
+ `# Agent Instructions
333
+
334
+ @.claude/agentvalet-permissions.md
335
+ `,
336
+ "utf-8"
337
+ );
338
+ return;
339
+ }
340
+ const existing = readFileSync(claudeMdPath, "utf-8");
341
+ if (existing.includes(importLine) || existing.includes("@.claude/agentvalet-permissions.md")) {
342
+ return;
343
+ }
344
+ writeFileSync(claudeMdPath, `${existing.trimEnd()}
345
+
346
+ ${importLine}
347
+ `, "utf-8");
348
+ }
349
+ var HOOK_COMMAND = "npx @agentvalet/register refresh --if-stale --quiet 2>/dev/null || true";
350
+ var HOOK_MARKER = "agentvalet/register refresh";
351
+ function ensureHook() {
352
+ const settingsPath = resolve2(".claude/settings.local.json");
353
+ let settings = {};
354
+ if (existsSync(settingsPath)) {
355
+ try {
356
+ settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
357
+ } catch {
358
+ return;
359
+ }
360
+ }
361
+ const hooks = settings.hooks ?? {};
362
+ const ups = hooks.UserPromptSubmit ?? [];
363
+ const alreadyWired = ups.some(
364
+ (entry) => entry.hooks?.some((h) => h.command?.includes(HOOK_MARKER))
365
+ );
366
+ if (alreadyWired) return;
367
+ const newEntry = { matcher: "", hooks: [{ type: "command", command: HOOK_COMMAND }] };
368
+ settings.hooks = { ...hooks, UserPromptSubmit: [...ups, newEntry] };
369
+ mkdirSync(dirname2(settingsPath), { recursive: true });
370
+ writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
371
+ }
324
372
 
325
373
  // src/index.ts
326
374
  function collectScope(value, previous) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentvalet/register",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Self-register AI agents with AgentValet",
5
5
  "type": "module",
6
6
  "bin": {