@agentvalet/register 0.1.5 → 0.1.7
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 +32 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -157,7 +157,9 @@ function parseEvent(data) {
|
|
|
157
157
|
if (data.status === "approved") {
|
|
158
158
|
const agentId = data.agent_id ?? data.agentId;
|
|
159
159
|
if (!agentId) return null;
|
|
160
|
-
|
|
160
|
+
const ownerId = data.owner_id ?? data.ownerId ?? "";
|
|
161
|
+
const grantedPlatforms = data.granted_platforms ?? [];
|
|
162
|
+
return { status: "approved", agentId, ownerId, privateKey: "", grantedPlatforms };
|
|
161
163
|
}
|
|
162
164
|
if (data.status === "rejected") return { status: "rejected" };
|
|
163
165
|
if (data.status === "timeout" || data.status === "expired") return { status: "expired" };
|
|
@@ -273,6 +275,14 @@ function parseEnvFile(content) {
|
|
|
273
275
|
}
|
|
274
276
|
return result;
|
|
275
277
|
}
|
|
278
|
+
function writePermissionsFromEvent(agentId, ownerId, platforms, outputPath = "./.claude/agentvalet-permissions.md") {
|
|
279
|
+
const content = generatePermissionsFile(agentId, ownerId, platforms);
|
|
280
|
+
const resolvedPath = resolve2(outputPath);
|
|
281
|
+
mkdirSync(dirname2(resolvedPath), { recursive: true });
|
|
282
|
+
writeFileSync(resolvedPath, content, "utf-8");
|
|
283
|
+
embedInClaudeMd(content);
|
|
284
|
+
ensureHook();
|
|
285
|
+
}
|
|
276
286
|
async function runRefresh(options) {
|
|
277
287
|
const outputPath = resolve2(options.outputPath);
|
|
278
288
|
if (options.ifStale) {
|
|
@@ -280,8 +290,12 @@ async function runRefresh(options) {
|
|
|
280
290
|
const stat = statSync(outputPath);
|
|
281
291
|
const fileIsFresh = Date.now() - stat.mtimeMs < 36e5;
|
|
282
292
|
const claudeMdPath = resolve2("CLAUDE.md");
|
|
283
|
-
const
|
|
284
|
-
|
|
293
|
+
const claudeMd = existsSync(claudeMdPath) ? readFileSync(claudeMdPath, "utf-8") : "";
|
|
294
|
+
const blockStart = claudeMd.indexOf(CLAUDE_START);
|
|
295
|
+
const blockEnd = claudeMd.indexOf(CLAUDE_END);
|
|
296
|
+
const blockContent = blockStart !== -1 && blockEnd !== -1 ? claudeMd.slice(blockStart, blockEnd) : "";
|
|
297
|
+
const blockHasPlatforms = blockContent.includes("### ");
|
|
298
|
+
if (fileIsFresh && blockHasPlatforms) return;
|
|
285
299
|
} catch {
|
|
286
300
|
}
|
|
287
301
|
}
|
|
@@ -477,13 +491,14 @@ Approve at: https://agentvalet.ai/registrations
|
|
|
477
491
|
}
|
|
478
492
|
process.exit(2);
|
|
479
493
|
}
|
|
480
|
-
const { agentId, privateKey } = result;
|
|
494
|
+
const { agentId, privateKey, grantedPlatforms } = result;
|
|
495
|
+
const resolvedOwnerId = result.ownerId || ownerId;
|
|
481
496
|
let keyPath;
|
|
482
497
|
let envPath;
|
|
483
498
|
try {
|
|
484
499
|
({ keyPath, envPath } = await saveOutput({
|
|
485
500
|
agentId,
|
|
486
|
-
ownerId,
|
|
501
|
+
ownerId: resolvedOwnerId,
|
|
487
502
|
privateKey: privateKey ?? "",
|
|
488
503
|
apiUrl: opts.apiUrl,
|
|
489
504
|
keyFilePath: opts.keyPath,
|
|
@@ -512,19 +527,20 @@ Source the env file before calling any tool:`);
|
|
|
512
527
|
}
|
|
513
528
|
if (keyWritten) {
|
|
514
529
|
try {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
530
|
+
if (grantedPlatforms && grantedPlatforms.length > 0) {
|
|
531
|
+
writePermissionsFromEvent(agentId, resolvedOwnerId, grantedPlatforms);
|
|
532
|
+
if (!isJson) console.log(chalk2.gray(`Permissions: .claude/agentvalet-permissions.md`));
|
|
533
|
+
} else {
|
|
534
|
+
await runRefresh({
|
|
535
|
+
envFile: opts.output,
|
|
536
|
+
outputPath: ".claude/agentvalet-permissions.md",
|
|
537
|
+
ifStale: false,
|
|
538
|
+
quiet: isJson
|
|
539
|
+
});
|
|
540
|
+
if (!isJson) console.log(chalk2.gray(`Permissions: .claude/agentvalet-permissions.md`));
|
|
523
541
|
}
|
|
524
542
|
} catch {
|
|
525
|
-
if (!isJson)
|
|
526
|
-
console.log(chalk2.yellow(`Permissions: run 'agentvalet-register refresh' to generate`));
|
|
527
|
-
}
|
|
543
|
+
if (!isJson) console.log(chalk2.yellow(`Permissions: run 'agentvalet-register refresh' to generate`));
|
|
528
544
|
}
|
|
529
545
|
}
|
|
530
546
|
process.exit(0);
|