@optimuslabs/harness-map-staging 1.5.43 → 1.5.44

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.
@@ -9,8 +9,11 @@
9
9
  * and each file's hash, never its content); the vault entry is `chmod 000`, and an empty `chmod 000`
10
10
  * folder is left at the original path so that no app (Claude Code re-syncing account skills, a
11
11
  * plugin update) can put the skill back. A receipt whose folder is no longer listed is restored.
12
- * A folder is only ever moved when it is a real directory inside the home folder (never the home
13
- * folder itself) holding a SKILL.md, so a bad path cannot move anything that is not a skill.
12
+ * Any folder the inventory reported is quarantined, wherever it is, as long as it is a real
13
+ * directory holding a SKILL.md and never the home folder or a folder above it, so a bad path cannot
14
+ * move anything that is not a skill. The hooks run as the user, so a folder the user cannot move
15
+ * (owned by root) fails and is logged. A listed path that is a symlink quarantines the folder it
16
+ * points to (`quarantinePath`).
14
17
  */
15
18
  import { createHash } from 'node:crypto';
16
19
  import { chmodSync, existsSync, lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, realpathSync, renameSync, rmdirSync, rmSync, statSync, unlinkSync, writeFileSync, } from 'node:fs';
@@ -25,6 +28,30 @@ function log(message) {
25
28
  function permissionBits(path) {
26
29
  return lstatSync(path).mode & 0o7777;
27
30
  }
31
+ /**
32
+ * The folder a listed path quarantines: the path itself, or, for a symlink, the folder it points to.
33
+ * The skills CLI (`npx skills add`) installs one copy in `~/.agents/skills/<name>` and links each
34
+ * agent's folder to it (`~/.claude/skills/<name>`), and a link was refused, so a skill the server
35
+ * knew only by its link stayed usable by every agent. Quarantining the folder behind the link closes
36
+ * it for every link and every agent reading it. A chain of more than eight links is left as it is,
37
+ * and refused.
38
+ */
39
+ function quarantinePath(dir) {
40
+ let path = resolve(dir);
41
+ for (let hop = 0; hop < 8; hop++) {
42
+ const next = linkTarget(path);
43
+ if (next === null)
44
+ return path;
45
+ path = next;
46
+ }
47
+ return path;
48
+ }
49
+ /** Where the link at `path` leads, or null when `path` is not a link (missing ones included). */
50
+ function linkTarget(path) {
51
+ if (!exists(path) || !lstatSync(path).isSymbolicLink())
52
+ return null;
53
+ return resolve(dirname(path), readlinkSync(path));
54
+ }
28
55
  /** The vault id of an original path: one path, one entry. */
29
56
  function entryId(dir) {
30
57
  return createHash('sha256').update(resolve(dir)).digest('hex').slice(0, 16);
@@ -111,26 +138,31 @@ function sameFiles(a, b) {
111
138
  }
112
139
  /** When the folder at `dir` was quarantined, or null when it is not. */
113
140
  export function quarantinedAt(dir) {
114
- const receipt = readReceipt(entryId(dir));
141
+ const receipt = readReceipt(entryId(quarantinePath(dir)));
115
142
  return receipt && receipt.status !== 'moving' ? receipt.quarantined_at : null;
116
143
  }
117
144
  /**
118
145
  * The receipt of the skill folder quarantined from `dir`, when the empty folder quarantine left
119
146
  * is still there. The collection reports such a path as quarantined: its skill cannot have changed
120
- * since it was moved, and the server keeps the copy it has.
147
+ * since it was moved, and the server keeps the copy it has. A link to a quarantined folder is
148
+ * reported the same way.
121
149
  */
122
150
  export function quarantineReceiptFor(dir) {
123
- if (!isStub(resolve(dir)))
151
+ const path = quarantinePath(dir);
152
+ if (!isStub(path))
124
153
  return null;
125
- const receipt = readReceipt(entryId(dir));
154
+ const receipt = readReceipt(entryId(path));
126
155
  return receipt && receipt.status !== 'moving' ? receipt : null;
127
156
  }
128
- /** Why `dir` must not be moved, or null when it is a real skill folder inside the home folder. */
157
+ /**
158
+ * Why `dir` must not be moved, or null when it is a real skill folder. Any location the inventory
159
+ * reported can be moved (a project on another drive, a shared folder), except the home folder and
160
+ * the folders above it.
161
+ */
129
162
  export function refusalReason(dir, home = homedir()) {
130
- const root = resolve(home);
131
163
  const target = resolve(dir);
132
- if (!target.startsWith(root + sep))
133
- return 'outside the home folder';
164
+ if (isHomeOrAbove(target, home))
165
+ return 'the home folder or above it';
134
166
  if (!existsSync(target))
135
167
  return 'missing';
136
168
  const stat = lstatSync(target);
@@ -138,12 +170,17 @@ export function refusalReason(dir, home = homedir()) {
138
170
  return 'symlink';
139
171
  if (!stat.isDirectory())
140
172
  return 'not a directory';
141
- if (!realpathSync(target).startsWith(realpathSync(root) + sep))
142
- return 'resolves outside the home folder';
173
+ if (isHomeOrAbove(realpathSync(target), realpathSync(home)))
174
+ return 'the home folder or above it';
143
175
  if (!existsSync(join(target, 'SKILL.md')))
144
176
  return 'no SKILL.md';
145
177
  return null;
146
178
  }
179
+ /** Whether `dir` is the home folder or a folder that holds it (`/Users`, `/`). */
180
+ function isHomeOrAbove(dir, home) {
181
+ const folder = dir.endsWith(sep) ? dir : dir + sep;
182
+ return (resolve(home) + sep).startsWith(folder);
183
+ }
147
184
  /** Move a listed folder into the vault, with its receipt, and leave the empty folder behind. */
148
185
  function moveIn(dir, id, entry, outcome) {
149
186
  const receipt = {
@@ -203,9 +240,9 @@ function keepQuarantined(dir, id, receipt, home, outcome) {
203
240
  makeStub(dir);
204
241
  outcome.requarantined.push(dir);
205
242
  }
206
- /** Quarantine one listed folder, or keep it quarantined. */
243
+ /** Quarantine one listed folder (the one a link points to), or keep it quarantined. */
207
244
  function quarantine(entry, home, outcome) {
208
- const dir = resolve(entry.skill_dir);
245
+ const dir = quarantinePath(entry.skill_dir);
209
246
  const id = entryId(dir);
210
247
  let receipt = readReceipt(id);
211
248
  if (receipt?.status === 'moving') {
@@ -334,7 +371,7 @@ function releaseStateLock(lockPath) {
334
371
  }
335
372
  function applyUnderLock(entries, home, outcome) {
336
373
  releaseInPlaceLocks();
337
- const wanted = new Set(entries.map((entry) => entryId(entry.skill_dir)));
374
+ const wanted = new Set(entries.map((entry) => entryId(quarantinePath(entry.skill_dir))));
338
375
  for (const entry of entries) {
339
376
  try {
340
377
  quarantine(entry, home, outcome);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimuslabs/harness-map-staging",
3
- "version": "1.5.43",
3
+ "version": "1.5.44",
4
4
  "description": "CLI helpers for logging hardware UUIDs and posting startup payloads to Optimus Security.",
5
5
  "type": "module",
6
6
  "bin": {