@danypops/pi-packed 0.22.0 → 0.22.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/extension/src/profile.ts +1 -34
- package/package.json +1 -1
package/extension/src/profile.ts
CHANGED
|
@@ -96,22 +96,6 @@ export function loadProfiles(agentDir: string, cwd: string, projectTrusted: bool
|
|
|
96
96
|
return { ...globalProfiles, ...readProfileFile(join(cwd, CONFIG_DIR_NAME, PROFILE_FILE)) };
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
function loadDefaultProfile(cwd: string, projectTrusted: boolean): string | undefined {
|
|
100
|
-
if (!projectTrusted) return undefined;
|
|
101
|
-
try {
|
|
102
|
-
const path = join(cwd, "pi-setup.json");
|
|
103
|
-
if (!existsSync(path)) return undefined;
|
|
104
|
-
const stat = lstatSync(path);
|
|
105
|
-
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 1024 * 1024) return undefined;
|
|
106
|
-
const value = JSON.parse(readFileSync(path, "utf8")) as { schemaVersion?: unknown; defaultProfile?: unknown };
|
|
107
|
-
return value.schemaVersion === 1 && typeof value.defaultProfile === "string" && PROFILE_NAME.test(value.defaultProfile)
|
|
108
|
-
? value.defaultProfile
|
|
109
|
-
: undefined;
|
|
110
|
-
} catch {
|
|
111
|
-
return undefined;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
99
|
function loadLastProfile(agentDir: string): string | undefined {
|
|
116
100
|
try {
|
|
117
101
|
const path = join(agentDir, LAST_PROFILE_FILE);
|
|
@@ -299,7 +283,7 @@ export function registerProfiles(pi: ExtensionAPI): void {
|
|
|
299
283
|
pi.on("before_agent_start", (event) =>
|
|
300
284
|
activeProfile?.instructions ? { systemPrompt: `${event.systemPrompt}\n\n${activeProfile.instructions}` } : undefined,
|
|
301
285
|
);
|
|
302
|
-
pi.on("session_start", async (
|
|
286
|
+
pi.on("session_start", async (_event, ctx) => {
|
|
303
287
|
try {
|
|
304
288
|
profiles = loadProfiles(agentDir, ctx.cwd, ctx.isProjectTrusted());
|
|
305
289
|
} catch (error) {
|
|
@@ -317,15 +301,6 @@ export function registerProfiles(pi: ExtensionAPI): void {
|
|
|
317
301
|
ctx.ui.notify(`Profile "${flag}" activated`, "info");
|
|
318
302
|
return;
|
|
319
303
|
}
|
|
320
|
-
const defaultProfile = loadDefaultProfile(ctx.cwd, ctx.isProjectTrusted());
|
|
321
|
-
if ((event.reason === "reload" || event.reason === "new") && defaultProfile) {
|
|
322
|
-
if (profiles[defaultProfile]) await apply(defaultProfile, profiles[defaultProfile]!, ctx, false);
|
|
323
|
-
else {
|
|
324
|
-
ctx.ui.notify(`Default profile "${defaultProfile}" is not defined`, "warning");
|
|
325
|
-
setStatus(ctx);
|
|
326
|
-
}
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
304
|
const state = [...ctx.sessionManager.getEntries()]
|
|
330
305
|
.reverse()
|
|
331
306
|
.find(
|
|
@@ -340,14 +315,6 @@ export function registerProfiles(pi: ExtensionAPI): void {
|
|
|
340
315
|
setStatus(ctx);
|
|
341
316
|
return;
|
|
342
317
|
}
|
|
343
|
-
if (defaultProfile) {
|
|
344
|
-
if (profiles[defaultProfile]) await apply(defaultProfile, profiles[defaultProfile]!, ctx, false);
|
|
345
|
-
else {
|
|
346
|
-
ctx.ui.notify(`Default profile "${defaultProfile}" is not defined`, "warning");
|
|
347
|
-
setStatus(ctx);
|
|
348
|
-
}
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
318
|
const last = loadLastProfile(agentDir);
|
|
352
319
|
if (last && profiles[last]) {
|
|
353
320
|
await apply(last, profiles[last]!, ctx, false);
|