agent-purge 0.2.6 → 0.2.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.
Files changed (2) hide show
  1. package/lib/dsh.mjs +19 -4
  2. package/package.json +1 -1
package/lib/dsh.mjs CHANGED
@@ -21,6 +21,16 @@ export const profileDir = (p) => join(dshHome(), "profiles", p);
21
21
  export const pluginDir = (p, name = RESIDENT) => join(profileDir(p), "node_modules", name);
22
22
  const patchFile = (p) => join(profileDir(p), "cordis.patch.yml");
23
23
 
24
+ /**
25
+ * dsh 自己建过的 profile(带 package.json)。
26
+ * 不在这个名单里的目录绝不碰:PROFILE_TEMPLATES 里没有 desktop,我们写个
27
+ * 只有 patch + node_modules 的空目录,dsh 启动时会判定 "profile desktop does not exist" 直接拒绝启动。
28
+ * web / headless 虽然会自动 initProfile,但那是 dsh 的活,不是我们的。
29
+ */
30
+ export function liveProfiles() {
31
+ return DSH_PROFILES.filter((p) => existsSync(join(profileDir(p), "package.json")));
32
+ }
33
+
24
34
  const mark = (name) => [`# >>> agent-purge:${name}`, `# <<< agent-purge:${name}`];
25
35
 
26
36
  /** 这个 package.json 是 agent-purge 写的吗(别碰同名外来目录)。 */
@@ -260,14 +270,17 @@ export function addPlugin(name, source) {
260
270
  const block = `\n${begin}\n- insert:\n - id: ${name}\n name: ${name}\n${end}\n`;
261
271
  const files = [];
262
272
  const touched = []; // { dir, patch, before }:中途抛错时按相反顺序回滚
273
+ // 只装进 dsh 已经建好的 profile;一个都没有说明 dsh 还没跑过
274
+ const targets = liveProfiles();
275
+ if (targets.length === 0) throw new Error("找不到任何 dsh profile(~/.dsh/profiles/*/package.json)—— 先启动一次 dsh,让它把 profile 建好再来装");
263
276
  // 预检:同名目录要么不存在,要么是我们的(package.json 带 agentPurge 标记),否则不碰
264
- for (const p of DSH_PROFILES) {
277
+ for (const p of targets) {
265
278
  const dir = pluginDir(p, name);
266
279
  const meta = join(dir, "package.json");
267
280
  if (existsSync(dir) && !isOurs(meta)) throw new Error(`${dir} 已存在且不是 agent-purge 装的,拒绝覆盖`);
268
281
  }
269
282
  try {
270
- for (const p of DSH_PROFILES) {
283
+ for (const p of targets) {
271
284
  const dir = pluginDir(p, name);
272
285
  const patch = patchFile(p);
273
286
  const before = existsSync(patch) ? readFileSync(patch, "utf8") : null;
@@ -299,7 +312,7 @@ export function addPlugin(name, source) {
299
312
  }
300
313
  throw e;
301
314
  }
302
- return { dirs: files, profiles: DSH_PROFILES };
315
+ return { dirs: files, profiles: targets };
303
316
  }
304
317
 
305
318
  /** 只撤自己那一段:目录 + patch marker,别的配置原样。 */
@@ -339,7 +352,9 @@ export function removePlugin(name) {
339
352
  /** patch 里还挂着这个名字吗(status 用;不许在有其他 insert 时谎报干净)。 */
340
353
  export function hasPlugin(name) {
341
354
  const [begin] = mark(name);
342
- return DSH_PROFILES.every((p) => {
355
+ const targets = liveProfiles();
356
+ if (targets.length === 0) return false;
357
+ return targets.every((p) => {
343
358
  const patch = patchFile(p);
344
359
  return existsSync(join(pluginDir(p, name), "index.js")) && existsSync(patch) && readFileSync(patch, "utf8").includes(begin);
345
360
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-purge",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "One persona, many coding agents: replace or inject system prompts across codex, claude, opencode (v1/v2), grok, omp, hermes, pi, zcode, dsh.",
5
5
  "type": "module",
6
6
  "bin": {