@jmcombs/pi-1password 1.0.0 → 1.0.1
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/index.ts +13 -10
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -235,7 +235,7 @@ async function resolveShellValue(raw: unknown): Promise<string | null> {
|
|
|
235
235
|
async function loadShellEnvMap(): Promise<Record<string, string>> {
|
|
236
236
|
const home = homedir() || "/tmp";
|
|
237
237
|
const authPath = join(home, ".pi", "agent", "auth.json");
|
|
238
|
-
const map
|
|
238
|
+
const map = new Map<string, string>();
|
|
239
239
|
|
|
240
240
|
try {
|
|
241
241
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
@@ -248,15 +248,14 @@ async function loadShellEnvMap(): Promise<Record<string, string>> {
|
|
|
248
248
|
|
|
249
249
|
const resolved = await resolveShellValue(val);
|
|
250
250
|
if (resolved !== null) {
|
|
251
|
-
|
|
252
|
-
map[key] = resolved;
|
|
251
|
+
map.set(key, resolved);
|
|
253
252
|
}
|
|
254
253
|
}
|
|
255
254
|
} catch {
|
|
256
255
|
// File missing or unreadable — no shell env injection this session
|
|
257
256
|
}
|
|
258
257
|
|
|
259
|
-
return map;
|
|
258
|
+
return Object.fromEntries(map);
|
|
260
259
|
}
|
|
261
260
|
|
|
262
261
|
// In-memory map for the current session (populated on session_start)
|
|
@@ -302,16 +301,21 @@ async function addAuthEntry(
|
|
|
302
301
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
303
302
|
await mkdir(authDir, { recursive: true });
|
|
304
303
|
|
|
305
|
-
|
|
304
|
+
const existing = new Map<string, unknown>();
|
|
306
305
|
try {
|
|
307
306
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
308
307
|
const raw = await readFile(authPath, "utf8");
|
|
309
|
-
|
|
308
|
+
const parsed: unknown = JSON.parse(raw);
|
|
309
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
310
|
+
for (const [k, v] of Object.entries(parsed as Record<string, unknown>)) {
|
|
311
|
+
existing.set(k, v);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
310
314
|
} catch {
|
|
311
315
|
// File missing or invalid JSON → start fresh
|
|
312
316
|
}
|
|
313
317
|
|
|
314
|
-
const alreadyExists = existing
|
|
318
|
+
const alreadyExists = existing.has(envVar);
|
|
315
319
|
|
|
316
320
|
if (alreadyExists && !options.overwrite) {
|
|
317
321
|
return {
|
|
@@ -322,10 +326,9 @@ async function addAuthEntry(
|
|
|
322
326
|
}
|
|
323
327
|
|
|
324
328
|
// Convention: single quotes around the op:// ref
|
|
325
|
-
|
|
326
|
-
existing[envVar] = `!op read '${opRef}'`;
|
|
329
|
+
existing.set(envVar, `!op read '${opRef}'`);
|
|
327
330
|
|
|
328
|
-
const content = JSON.stringify(existing, null, 2) + "\n";
|
|
331
|
+
const content = JSON.stringify(Object.fromEntries(existing), null, 2) + "\n";
|
|
329
332
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
330
333
|
await writeFile(authPath, content, "utf8");
|
|
331
334
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jmcombs/pi-1password",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "1Password integration for the Pi coding agent. Read secrets and run commands with 1Password credential injection via the op CLI.",
|
|
5
5
|
"homepage": "https://github.com/jmcombs/pi-extensions/tree/main/packages/1password",
|
|
6
6
|
"repository": {
|