@agentvalet/register 0.1.3 → 0.1.5
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/dist/index.js +49 -18
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -245,6 +245,10 @@ To refresh this file: \`agentvalet-register refresh\`
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
// src/commands/refresh.ts
|
|
248
|
+
var CLAUDE_START = "<!-- agentvalet:start -->";
|
|
249
|
+
var CLAUDE_END = "<!-- agentvalet:end -->";
|
|
250
|
+
var HOOK_COMMAND = "npx @agentvalet/register refresh --if-stale --quiet 2>/dev/null || true";
|
|
251
|
+
var HOOK_MARKER = "agentvalet/register refresh";
|
|
248
252
|
function base64url(input) {
|
|
249
253
|
return Buffer.from(input).toString("base64url");
|
|
250
254
|
}
|
|
@@ -274,9 +278,10 @@ async function runRefresh(options) {
|
|
|
274
278
|
if (options.ifStale) {
|
|
275
279
|
try {
|
|
276
280
|
const stat = statSync(outputPath);
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
281
|
+
const fileIsFresh = Date.now() - stat.mtimeMs < 36e5;
|
|
282
|
+
const claudeMdPath = resolve2("CLAUDE.md");
|
|
283
|
+
const claudeMdHasBlock = existsSync(claudeMdPath) && readFileSync(claudeMdPath, "utf-8").includes(CLAUDE_START);
|
|
284
|
+
if (fileIsFresh && claudeMdHasBlock) return;
|
|
280
285
|
} catch {
|
|
281
286
|
}
|
|
282
287
|
}
|
|
@@ -317,33 +322,59 @@ Run 'agentvalet-register' first to create it.`);
|
|
|
317
322
|
const content = generatePermissionsFile(agentId, ownerId, platforms);
|
|
318
323
|
mkdirSync(dirname2(outputPath), { recursive: true });
|
|
319
324
|
writeFileSync(outputPath, content, "utf-8");
|
|
320
|
-
|
|
325
|
+
embedInClaudeMd(content);
|
|
326
|
+
ensureHook();
|
|
321
327
|
if (!options.quiet) {
|
|
322
328
|
console.log(`Permissions refreshed \u2192 ${outputPath} (${platforms.length} platform${platforms.length !== 1 ? "s" : ""})`);
|
|
323
329
|
}
|
|
324
330
|
}
|
|
325
|
-
function
|
|
326
|
-
const importLine = `@${permissionsRelativePath.replace(/\\/g, "/").replace(/^\.\//, "")}`;
|
|
331
|
+
function embedInClaudeMd(permissionsContent) {
|
|
327
332
|
const claudeMdPath = resolve2("CLAUDE.md");
|
|
333
|
+
const block = `${CLAUDE_START}
|
|
334
|
+
${permissionsContent.trimEnd()}
|
|
335
|
+
${CLAUDE_END}`;
|
|
328
336
|
if (!existsSync(claudeMdPath)) {
|
|
329
|
-
writeFileSync(
|
|
330
|
-
claudeMdPath,
|
|
331
|
-
`# Agent Instructions
|
|
337
|
+
writeFileSync(claudeMdPath, `# Agent Instructions
|
|
332
338
|
|
|
333
|
-
|
|
334
|
-
`,
|
|
335
|
-
"utf-8"
|
|
336
|
-
);
|
|
339
|
+
${block}
|
|
340
|
+
`, "utf-8");
|
|
337
341
|
return;
|
|
338
342
|
}
|
|
339
343
|
const existing = readFileSync(claudeMdPath, "utf-8");
|
|
340
|
-
if (existing.includes(
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
+
if (existing.includes(CLAUDE_START)) {
|
|
345
|
+
const replaced = existing.replace(
|
|
346
|
+
new RegExp(`${CLAUDE_START}[\\s\\S]*?${CLAUDE_END}`, "m"),
|
|
347
|
+
block
|
|
348
|
+
);
|
|
349
|
+
writeFileSync(claudeMdPath, replaced, "utf-8");
|
|
350
|
+
} else {
|
|
351
|
+
const cleaned = existing.replace(/^@\.claude\/agentvalet-permissions\.md\s*$/m, "").trimEnd();
|
|
352
|
+
writeFileSync(claudeMdPath, `${cleaned}
|
|
344
353
|
|
|
345
|
-
${
|
|
354
|
+
${block}
|
|
346
355
|
`, "utf-8");
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function ensureHook() {
|
|
359
|
+
const settingsPath = resolve2(".claude/settings.local.json");
|
|
360
|
+
let settings = {};
|
|
361
|
+
if (existsSync(settingsPath)) {
|
|
362
|
+
try {
|
|
363
|
+
settings = JSON.parse(readFileSync(settingsPath, "utf-8"));
|
|
364
|
+
} catch {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
const hooks = settings.hooks ?? {};
|
|
369
|
+
const ups = hooks.UserPromptSubmit ?? [];
|
|
370
|
+
const alreadyWired = ups.some(
|
|
371
|
+
(entry) => entry.hooks?.some((h) => h.command?.includes(HOOK_MARKER))
|
|
372
|
+
);
|
|
373
|
+
if (alreadyWired) return;
|
|
374
|
+
const newEntry = { matcher: "", hooks: [{ type: "command", command: HOOK_COMMAND }] };
|
|
375
|
+
settings.hooks = { ...hooks, UserPromptSubmit: [...ups, newEntry] };
|
|
376
|
+
mkdirSync(dirname2(settingsPath), { recursive: true });
|
|
377
|
+
writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + "\n", "utf-8");
|
|
347
378
|
}
|
|
348
379
|
|
|
349
380
|
// src/index.ts
|