dsh-tg-bridge 1.28.1 → 1.30.0

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/aset-profile.mjs CHANGED
@@ -15,7 +15,7 @@
15
15
  import { createHash } from 'node:crypto';
16
16
  import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
17
17
  import { homedir } from 'node:os';
18
- import { join } from 'node:path';
18
+ import { join, resolve, sep } from 'node:path';
19
19
  import { setAgentPreset, setModel, setSubagents } from './patch-rows.mjs';
20
20
  import { sandboxModeOf, setPermission } from './permission-rows.mjs';
21
21
 
@@ -160,10 +160,17 @@ export function pruneDerived(keep = [], { profiles = PROFILES } = {}) {
160
160
  } catch {
161
161
  return removed;
162
162
  }
163
+ // A recursive delete needs a containment check, not just a name pattern: the
164
+ // root comes from `DSH_HOME`, and `DSH_HOME=C:\` would put "derived profiles"
165
+ // wherever that machine happens to have a matching directory. The prefix check
166
+ // stays as the second line of defence.
167
+ const root = resolve(profiles);
163
168
  for (const entry of entries) {
164
169
  if (!entry.isDirectory() || !entry.name.startsWith(DERIVED_PREFIX) || wanted.has(entry.name)) continue;
170
+ const target = resolve(join(profiles, entry.name));
171
+ if (target !== root && !target.startsWith(root.endsWith(sep) ? root : root + sep)) continue;
165
172
  try {
166
- rmSync(join(profiles, entry.name), { recursive: true, force: true });
173
+ rmSync(target, { recursive: true, force: true });
167
174
  removed.push(entry.name);
168
175
  } catch {
169
176
  // A profile in use by a running turn stays until the next sweep.