@primitive.ai/prim 0.1.0-alpha.120 → 0.1.0-alpha.121
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/README.md +19 -9
- package/SKILL.md +7 -2
- package/dist/{chunk-HXICZG5J.js → chunk-2DNC2MUN.js} +4 -4
- package/dist/{chunk-NQFRQ56V.js → chunk-2PFJJO2M.js} +2 -2
- package/dist/{chunk-P2O7NLVN.js → chunk-4GYJHN26.js} +117 -18
- package/dist/{chunk-5BQ2NEMP.js → chunk-6DEROXLM.js} +2 -2
- package/dist/{chunk-CCGFRNAA.js → chunk-7LXRFXZG.js} +248 -127
- package/dist/{chunk-MWNRXAEB.js → chunk-AKGRY7OU.js} +1 -1
- package/dist/{chunk-L52OD62C.js → chunk-BHT6X3T5.js} +14 -8
- package/dist/{chunk-D235RJNO.js → chunk-DQ4I3FLF.js} +3 -3
- package/dist/{chunk-VOC4KOOP.js → chunk-DVHD6LBQ.js} +2 -2
- package/dist/{chunk-TC4FTRYO.js → chunk-HG7FJK7R.js} +2 -2
- package/dist/{chunk-GYQOZGGF.js → chunk-JXRJLHE4.js} +2 -2
- package/dist/{chunk-2AKDX4RU.js → chunk-JZC2LHS6.js} +1 -1
- package/dist/{chunk-YTF6OCF3.js → chunk-LQLP26RL.js} +5 -5
- package/dist/{chunk-EYBE724K.js → chunk-M4NZJCPQ.js} +4 -4
- package/dist/{chunk-R2NUH4B7.js → chunk-MRDY7VQP.js} +2 -2
- package/dist/{chunk-SLDZJD6Q.js → chunk-NMZSCSMY.js} +1 -1
- package/dist/{chunk-A6M2M5A2.js → chunk-NQZLXYTW.js} +1 -1
- package/dist/{chunk-LTTF4MBE.js → chunk-OXW6PSPT.js} +2 -2
- package/dist/{chunk-U67RBNIZ.js → chunk-S3ZIMGXV.js} +1 -1
- package/dist/{chunk-LBCPRHNG.js → chunk-WN7OURQ3.js} +1 -1
- package/dist/daemon/server.js +78 -16
- package/dist/hook-runtime/daemon/server.js +78 -16
- package/dist/hook-runtime/hooks/post-commit.js +88 -26
- package/dist/hook-runtime/hooks/post-rewrite.js +82 -20
- package/dist/hook-runtime/hooks/post-tool-use.js +82 -20
- package/dist/hook-runtime/hooks/pre-commit.js +9 -5
- package/dist/hook-runtime/hooks/pre-tool-use-worker.js +12 -8
- package/dist/hook-runtime/hooks/prim-hook.js +85 -23
- package/dist/hook-runtime/hooks/session-end.js +75 -13
- package/dist/hook-runtime/hooks/session-start.js +247 -176
- package/dist/hook-runtime/index.js +1147 -692
- package/dist/hook-runtime/statusline-main.js +76 -14
- package/dist/hooks/post-commit.js +7 -7
- package/dist/hooks/post-rewrite.js +6 -6
- package/dist/hooks/post-tool-use.js +15 -15
- package/dist/hooks/pre-commit.js +4 -4
- package/dist/hooks/pre-tool-use-worker.js +9 -9
- package/dist/hooks/prim-hook.js +17 -17
- package/dist/hooks/session-end.js +4 -4
- package/dist/hooks/session-start.js +11 -11
- package/dist/index.js +349 -98
- package/dist/statusline-main.js +76 -14
- package/package.json +3 -2
- package/skills/prim-welcome/SKILL.md +197 -0
|
@@ -9,11 +9,11 @@ import {
|
|
|
9
9
|
hookBlockContractVersion,
|
|
10
10
|
inspectGitHookEntrypoint,
|
|
11
11
|
managedHookBlock
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-AKGRY7OU.js";
|
|
13
13
|
import {
|
|
14
14
|
HttpError,
|
|
15
15
|
getClient
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-S3ZIMGXV.js";
|
|
17
17
|
import {
|
|
18
18
|
atomicWriteFile,
|
|
19
19
|
binFile,
|
|
@@ -27,25 +27,25 @@ import {
|
|
|
27
27
|
setRepoSyncId,
|
|
28
28
|
setRepositoryBindingState,
|
|
29
29
|
withFileLock
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-4GYJHN26.js";
|
|
31
31
|
|
|
32
32
|
// src/commands/skill.ts
|
|
33
|
-
import { createHash as
|
|
33
|
+
import { createHash as createHash3 } from "crypto";
|
|
34
34
|
import {
|
|
35
35
|
constants as constants2,
|
|
36
36
|
closeSync as closeSync2,
|
|
37
|
-
existsSync as
|
|
37
|
+
existsSync as existsSync3,
|
|
38
38
|
fstatSync as fstatSync2,
|
|
39
|
-
lstatSync as
|
|
39
|
+
lstatSync as lstatSync3,
|
|
40
40
|
openSync as openSync2,
|
|
41
|
-
readFileSync as
|
|
41
|
+
readFileSync as readFileSync3,
|
|
42
42
|
readSync as readSync2,
|
|
43
|
-
readdirSync as
|
|
44
|
-
rmdirSync as
|
|
45
|
-
unlinkSync
|
|
43
|
+
readdirSync as readdirSync3,
|
|
44
|
+
rmdirSync as rmdirSync3,
|
|
45
|
+
unlinkSync as unlinkSync2
|
|
46
46
|
} from "fs";
|
|
47
|
-
import { homedir as
|
|
48
|
-
import { dirname as
|
|
47
|
+
import { homedir as homedir3 } from "os";
|
|
48
|
+
import { dirname as dirname3, join as join3, resolve as resolve2 } from "path";
|
|
49
49
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
50
50
|
import { createPatch } from "diff";
|
|
51
51
|
import { parse as parseYaml2 } from "yaml";
|
|
@@ -56,35 +56,120 @@ function printJson(data) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// src/commands/claude-plugin.ts
|
|
59
|
-
import { createHash } from "crypto";
|
|
59
|
+
import { createHash as createHash2 } from "crypto";
|
|
60
60
|
import {
|
|
61
61
|
constants,
|
|
62
62
|
closeSync,
|
|
63
|
-
existsSync,
|
|
63
|
+
existsSync as existsSync2,
|
|
64
64
|
fstatSync,
|
|
65
|
-
lstatSync,
|
|
65
|
+
lstatSync as lstatSync2,
|
|
66
66
|
mkdirSync,
|
|
67
67
|
openSync,
|
|
68
|
-
readFileSync,
|
|
68
|
+
readFileSync as readFileSync2,
|
|
69
69
|
readSync,
|
|
70
|
-
readdirSync,
|
|
70
|
+
readdirSync as readdirSync2,
|
|
71
71
|
realpathSync,
|
|
72
72
|
rmSync,
|
|
73
|
-
rmdirSync
|
|
73
|
+
rmdirSync as rmdirSync2
|
|
74
74
|
} from "fs";
|
|
75
|
-
import { homedir } from "os";
|
|
76
|
-
import { dirname, isAbsolute, join, relative, resolve, sep } from "path";
|
|
75
|
+
import { homedir as homedir2 } from "os";
|
|
76
|
+
import { dirname as dirname2, isAbsolute, join as join2, relative, resolve, sep } from "path";
|
|
77
77
|
import { fileURLToPath } from "url";
|
|
78
78
|
import { parse as parseYaml } from "yaml";
|
|
79
|
-
|
|
79
|
+
|
|
80
|
+
// src/commands/welcome-skill.ts
|
|
81
|
+
import { createHash } from "crypto";
|
|
82
|
+
import { existsSync, lstatSync, readFileSync, readdirSync, rmdirSync, unlinkSync } from "fs";
|
|
83
|
+
import { homedir } from "os";
|
|
84
|
+
import { dirname, join } from "path";
|
|
85
|
+
var WELCOME_SKILL_SOURCE = join("skills", "prim-welcome", "SKILL.md");
|
|
86
|
+
var OWNER = "@primitive.ai/prim";
|
|
87
|
+
var MANIFEST = ".prim-owned.json";
|
|
88
|
+
var digest = (content) => createHash("sha256").update(content).digest("hex");
|
|
89
|
+
var manifestPath = (skillPath) => join(dirname(skillPath), MANIFEST);
|
|
90
|
+
function leafKind(path) {
|
|
91
|
+
try {
|
|
92
|
+
return lstatSync(path).isFile() ? "file" : "foreign";
|
|
93
|
+
} catch (error) {
|
|
94
|
+
if (error.code === "ENOENT") return "missing";
|
|
95
|
+
throw error;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function codexWelcomeSkillPath() {
|
|
99
|
+
return join(homedir(), ".agents", "skills", "prim-welcome", "SKILL.md");
|
|
100
|
+
}
|
|
101
|
+
function welcomeSkillStatus(skillPath) {
|
|
102
|
+
const skillKind = leafKind(skillPath);
|
|
103
|
+
const manifestKind = leafKind(manifestPath(skillPath));
|
|
104
|
+
let manifest;
|
|
105
|
+
if (manifestKind === "file")
|
|
106
|
+
try {
|
|
107
|
+
const value = JSON.parse(readFileSync(manifestPath(skillPath), "utf8"));
|
|
108
|
+
if (value.version === 1 && value.owner === OWNER && /^[a-f0-9]{64}$/u.test(value.contentSha256 ?? ""))
|
|
109
|
+
manifest = value;
|
|
110
|
+
} catch {
|
|
111
|
+
}
|
|
112
|
+
const content = skillKind === "file" ? readFileSync(skillPath, "utf8") : void 0;
|
|
113
|
+
const owned = manifest !== void 0;
|
|
114
|
+
const installed = manifest !== void 0 && content !== void 0 && digest(content) === manifest.contentSha256;
|
|
115
|
+
return {
|
|
116
|
+
installed,
|
|
117
|
+
owned,
|
|
118
|
+
edited: owned && content !== void 0 && !installed,
|
|
119
|
+
target: skillPath,
|
|
120
|
+
content,
|
|
121
|
+
unsafe: skillKind === "foreign" || manifestKind === "foreign"
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function installWelcomeSkill(skillPath, content, dryRun = false) {
|
|
125
|
+
const status = welcomeSkillStatus(skillPath);
|
|
126
|
+
const foreignManifest = existsSync(manifestPath(skillPath)) && !status.owned;
|
|
127
|
+
if (status.unsafe || foreignManifest || status.edited || !status.owned && status.content !== void 0 && status.content !== content) {
|
|
128
|
+
console.error(`Refusing to overwrite a foreign or edited welcome skill at ${skillPath}`);
|
|
129
|
+
return 1;
|
|
130
|
+
}
|
|
131
|
+
if (status.installed && status.content === content) return 0;
|
|
132
|
+
if (dryRun) {
|
|
133
|
+
console.log(`Would write welcome skill to ${skillPath}`);
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
136
|
+
const manifest = { version: 1, owner: OWNER, contentSha256: digest(content) };
|
|
137
|
+
atomicWriteFile(skillPath, content, { ensureParent: true });
|
|
138
|
+
atomicWriteFile(manifestPath(skillPath), `${JSON.stringify(manifest, null, 2)}
|
|
139
|
+
`, {
|
|
140
|
+
ensureParent: true
|
|
141
|
+
});
|
|
142
|
+
console.log(`Installed prim-welcome skill at ${skillPath}`);
|
|
143
|
+
return 0;
|
|
144
|
+
}
|
|
145
|
+
function uninstallWelcomeSkill(skillPath) {
|
|
146
|
+
const status = welcomeSkillStatus(skillPath);
|
|
147
|
+
if (status.unsafe) {
|
|
148
|
+
console.error(`Refusing to remove a non-file welcome skill at ${skillPath}`);
|
|
149
|
+
return 1;
|
|
150
|
+
}
|
|
151
|
+
if (!status.owned) return 0;
|
|
152
|
+
if (status.edited) {
|
|
153
|
+
console.error(`Refusing to remove an edited welcome skill at ${skillPath}`);
|
|
154
|
+
return 1;
|
|
155
|
+
}
|
|
156
|
+
if (existsSync(skillPath)) unlinkSync(skillPath);
|
|
157
|
+
unlinkSync(manifestPath(skillPath));
|
|
158
|
+
if (readdirSync(dirname(skillPath)).length === 0) rmdirSync(dirname(skillPath));
|
|
159
|
+
console.log(`Removed prim-welcome skill from ${skillPath}`);
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/commands/claude-plugin.ts
|
|
164
|
+
var __dirname = dirname2(fileURLToPath(import.meta.url));
|
|
80
165
|
var PLUGIN_DESCRIPTION = "Primitive decision-graph guidance for the prim CLI \u2014 a model-invoked skill installed by prim skill install.";
|
|
81
166
|
var MAX_MANIFEST_BYTES = 64 * 1024;
|
|
82
167
|
var MAX_SKILL_BYTES = 1024 * 1024;
|
|
83
168
|
var REFRESH_LOCK_TIMEOUT_MS = 150;
|
|
84
169
|
var REFRESH_LOCK_POLL_MS = 10;
|
|
85
170
|
function pluginDirFor(cwd, scope) {
|
|
86
|
-
const base = scope === "user" ?
|
|
87
|
-
return
|
|
171
|
+
const base = scope === "user" ? join2(homedir2(), ".claude") : join2(gitToplevel(cwd) ?? cwd, ".claude");
|
|
172
|
+
return join2(base, "skills", "prim");
|
|
88
173
|
}
|
|
89
174
|
function resolvePluginDir(cwd, scope) {
|
|
90
175
|
if (scope && scope !== "user" && scope !== "project") {
|
|
@@ -95,10 +180,10 @@ function resolvePluginDir(cwd, scope) {
|
|
|
95
180
|
}
|
|
96
181
|
function packageVersion() {
|
|
97
182
|
let dir = __dirname;
|
|
98
|
-
while (dir !==
|
|
183
|
+
while (dir !== dirname2(dir)) {
|
|
99
184
|
const p = resolve(dir, "package.json");
|
|
100
|
-
if (
|
|
101
|
-
dir =
|
|
185
|
+
if (existsSync2(p)) return JSON.parse(readFileSync2(p, "utf-8")).version;
|
|
186
|
+
dir = dirname2(dir);
|
|
102
187
|
}
|
|
103
188
|
return "0.0.0";
|
|
104
189
|
}
|
|
@@ -111,13 +196,19 @@ function renderClaudePlugin() {
|
|
|
111
196
|
const version = packageVersion();
|
|
112
197
|
return { manifest: pluginManifest(version), skill: loadSkill(), version };
|
|
113
198
|
}
|
|
199
|
+
function welcomeSkillPath(pluginDir) {
|
|
200
|
+
return join2(dirname2(pluginDir), "prim-welcome", "SKILL.md");
|
|
201
|
+
}
|
|
202
|
+
function welcomeSkillPathFor(cwd, scope) {
|
|
203
|
+
return welcomeSkillPath(pluginDirFor(cwd, scope));
|
|
204
|
+
}
|
|
114
205
|
function removeDirIfEmpty(dir) {
|
|
115
|
-
if (
|
|
206
|
+
if (existsSync2(dir) && readdirSync2(dir).length === 0) rmdirSync2(dir);
|
|
116
207
|
}
|
|
117
208
|
function pluginPaths(dir) {
|
|
118
209
|
return {
|
|
119
|
-
manifestPath:
|
|
120
|
-
skillPath:
|
|
210
|
+
manifestPath: join2(dir, ".claude-plugin", "plugin.json"),
|
|
211
|
+
skillPath: join2(dir, "SKILL.md")
|
|
121
212
|
};
|
|
122
213
|
}
|
|
123
214
|
function pathIsInside(root, path) {
|
|
@@ -127,7 +218,7 @@ function pathIsInside(root, path) {
|
|
|
127
218
|
function managedPathsAreSafe(paths, projectRoot) {
|
|
128
219
|
try {
|
|
129
220
|
const managed = [paths.manifestPath, paths.skillPath];
|
|
130
|
-
if (managed.some((path) => !
|
|
221
|
+
if (managed.some((path) => !lstatSync2(path).isFile())) return false;
|
|
131
222
|
if (projectRoot === void 0) return true;
|
|
132
223
|
const realRoot = realpathSync(projectRoot);
|
|
133
224
|
return managed.every((path) => pathIsInside(realRoot, realpathSync(path)));
|
|
@@ -168,7 +259,7 @@ function hasUsablePrimFrontmatter(skill) {
|
|
|
168
259
|
}
|
|
169
260
|
}
|
|
170
261
|
function inspectRecognizedInstallation(paths, projectRoot) {
|
|
171
|
-
if (!
|
|
262
|
+
if (!existsSync2(paths.manifestPath) || !existsSync2(paths.skillPath)) return;
|
|
172
263
|
if (!managedPathsAreSafe(paths, projectRoot)) return;
|
|
173
264
|
const manifest = readBoundedRegularFile(paths.manifestPath, MAX_MANIFEST_BYTES);
|
|
174
265
|
const parsed = JSON.parse(manifest);
|
|
@@ -182,9 +273,9 @@ function inspectRecognizedInstallation(paths, projectRoot) {
|
|
|
182
273
|
};
|
|
183
274
|
}
|
|
184
275
|
function refreshLockDir(physicalPluginDir) {
|
|
185
|
-
const cacheRoot = process.env.XDG_CACHE_HOME ||
|
|
186
|
-
const identity =
|
|
187
|
-
return
|
|
276
|
+
const cacheRoot = process.env.XDG_CACHE_HOME || join2(homedir2(), ".cache");
|
|
277
|
+
const identity = createHash2("sha256").update(physicalPluginDir).digest("hex");
|
|
278
|
+
return join2(cacheRoot, "prim", "skill-refresh-locks", `${identity}.lock`);
|
|
188
279
|
}
|
|
189
280
|
async function refreshClaudePlugins(cwd, options = {}) {
|
|
190
281
|
const result = { installed: 0, refreshed: 0 };
|
|
@@ -192,7 +283,7 @@ async function refreshClaudePlugins(cwd, options = {}) {
|
|
|
192
283
|
if (options.includeProject !== false) {
|
|
193
284
|
const projectRoot = options.projectRoot ?? gitToplevel(cwd);
|
|
194
285
|
if (projectRoot !== null && isAbsolute(projectRoot)) {
|
|
195
|
-
candidates.push({ dir:
|
|
286
|
+
candidates.push({ dir: join2(projectRoot, ".claude", "skills", "prim"), projectRoot });
|
|
196
287
|
}
|
|
197
288
|
}
|
|
198
289
|
candidates.push({ dir: pluginDirFor(cwd, "user") });
|
|
@@ -207,8 +298,8 @@ async function refreshClaudePlugins(cwd, options = {}) {
|
|
|
207
298
|
}
|
|
208
299
|
};
|
|
209
300
|
const refreshCandidate = () => {
|
|
210
|
-
const { manifestPath, skillPath } = pluginPaths(dir);
|
|
211
|
-
const paths = { manifestPath, skillPath };
|
|
301
|
+
const { manifestPath: manifestPath2, skillPath } = pluginPaths(dir);
|
|
302
|
+
const paths = { manifestPath: manifestPath2, skillPath };
|
|
212
303
|
try {
|
|
213
304
|
let changed = false;
|
|
214
305
|
const current = inspectRecognizedInstallation(paths, projectRoot);
|
|
@@ -220,7 +311,7 @@ async function refreshClaudePlugins(cwd, options = {}) {
|
|
|
220
311
|
}
|
|
221
312
|
if (current.manifest !== desired.manifest) {
|
|
222
313
|
if (!managedPathsAreSafe(paths, projectRoot)) throw new Error("unsafe managed path");
|
|
223
|
-
atomicWrite(
|
|
314
|
+
atomicWrite(manifestPath2, desired.manifest);
|
|
224
315
|
if (!changed) result.refreshed += 1;
|
|
225
316
|
changed = true;
|
|
226
317
|
}
|
|
@@ -240,7 +331,7 @@ async function refreshClaudePlugins(cwd, options = {}) {
|
|
|
240
331
|
};
|
|
241
332
|
try {
|
|
242
333
|
const paths = pluginPaths(dir);
|
|
243
|
-
if (!
|
|
334
|
+
if (!existsSync2(paths.manifestPath) || !existsSync2(paths.skillPath)) continue;
|
|
244
335
|
const physicalPluginDir = realpathSync(dir);
|
|
245
336
|
if (seen.has(physicalPluginDir)) continue;
|
|
246
337
|
seen.add(physicalPluginDir);
|
|
@@ -256,20 +347,25 @@ async function refreshClaudePlugins(cwd, options = {}) {
|
|
|
256
347
|
function installClaudePlugin(cwd, opts) {
|
|
257
348
|
const dir = resolvePluginDir(cwd, opts.scope);
|
|
258
349
|
if (dir === null) return 1;
|
|
259
|
-
const { manifestPath, skillPath } = pluginPaths(dir);
|
|
350
|
+
const { manifestPath: manifestPath2, skillPath } = pluginPaths(dir);
|
|
260
351
|
const { manifest, skill } = renderClaudePlugin();
|
|
261
|
-
const
|
|
262
|
-
const
|
|
263
|
-
|
|
352
|
+
const welcomePath = opts.scope === "user" ? welcomeSkillPath(dir) : null;
|
|
353
|
+
const welcome = welcomePath ? loadSkill(WELCOME_SKILL_SOURCE) : null;
|
|
354
|
+
const manifestCurrent = existsSync2(manifestPath2) ? readFileSync2(manifestPath2, "utf-8") : null;
|
|
355
|
+
const skillCurrent = existsSync2(skillPath) ? readFileSync2(skillPath, "utf-8") : null;
|
|
356
|
+
const welcomeStatus = welcomePath ? welcomeSkillStatus(welcomePath) : null;
|
|
357
|
+
if (manifestCurrent === manifest && skillCurrent === skill && (!welcomePath || welcomeStatus?.installed && welcomeStatus.content === welcome)) {
|
|
264
358
|
console.log("No changes \u2014 prim skill plugin already up to date.");
|
|
265
359
|
return 0;
|
|
266
360
|
}
|
|
361
|
+
if (welcomePath && welcome !== null && installWelcomeSkill(welcomePath, welcome, opts.dryRun) !== 0)
|
|
362
|
+
return 1;
|
|
267
363
|
if (opts.dryRun) {
|
|
268
364
|
console.log(`Would write plugin to ${dir} (.claude-plugin/plugin.json + SKILL.md)`);
|
|
269
365
|
return 0;
|
|
270
366
|
}
|
|
271
|
-
mkdirSync(
|
|
272
|
-
atomicWrite(
|
|
367
|
+
mkdirSync(join2(dir, ".claude-plugin"), { recursive: true });
|
|
368
|
+
atomicWrite(manifestPath2, manifest);
|
|
273
369
|
atomicWrite(skillPath, skill);
|
|
274
370
|
console.log(`Installed prim skill plugin at ${dir}`);
|
|
275
371
|
console.log("Restart Claude Code or run /reload-plugins to load it.");
|
|
@@ -281,14 +377,15 @@ function installClaudePlugin(cwd, opts) {
|
|
|
281
377
|
function uninstallClaudePlugin(cwd, opts) {
|
|
282
378
|
const dir = resolvePluginDir(cwd, opts.scope);
|
|
283
379
|
if (dir === null) return 1;
|
|
284
|
-
const { manifestPath, skillPath } = pluginPaths(dir);
|
|
285
|
-
if (
|
|
380
|
+
const { manifestPath: manifestPath2, skillPath } = pluginPaths(dir);
|
|
381
|
+
if (opts.scope === "user" && uninstallWelcomeSkill(welcomeSkillPath(dir)) !== 0) return 1;
|
|
382
|
+
if (!existsSync2(manifestPath2) && !existsSync2(skillPath)) {
|
|
286
383
|
console.log(`prim skill plugin not present at ${dir}`);
|
|
287
384
|
return 0;
|
|
288
385
|
}
|
|
289
|
-
rmSync(
|
|
386
|
+
rmSync(manifestPath2, { force: true });
|
|
290
387
|
rmSync(skillPath, { force: true });
|
|
291
|
-
removeDirIfEmpty(
|
|
388
|
+
removeDirIfEmpty(join2(dir, ".claude-plugin"));
|
|
292
389
|
removeDirIfEmpty(dir);
|
|
293
390
|
console.log(`Removed prim skill plugin from ${dir}`);
|
|
294
391
|
return 0;
|
|
@@ -297,9 +394,10 @@ function statusClaudePlugin(cwd, opts) {
|
|
|
297
394
|
const dir = resolvePluginDir(cwd, opts.scope);
|
|
298
395
|
if (dir === null) return 1;
|
|
299
396
|
const { skillPath } = pluginPaths(dir);
|
|
300
|
-
const
|
|
397
|
+
const welcome = opts.scope === "user" ? welcomeSkillStatus(welcomeSkillPath(dir)) : void 0;
|
|
398
|
+
const installed = existsSync2(skillPath) && (!welcome || welcome.installed);
|
|
301
399
|
if (opts.json) {
|
|
302
|
-
printJson({ installed, target: dir });
|
|
400
|
+
printJson({ installed, target: dir, ...welcome ? { welcomeSkill: welcome.installed } : {} });
|
|
303
401
|
return installed ? 0 : 1;
|
|
304
402
|
}
|
|
305
403
|
if (installed) {
|
|
@@ -311,7 +409,7 @@ function statusClaudePlugin(cwd, opts) {
|
|
|
311
409
|
}
|
|
312
410
|
|
|
313
411
|
// src/commands/skill.ts
|
|
314
|
-
var __dirname2 =
|
|
412
|
+
var __dirname2 = dirname3(fileURLToPath2(import.meta.url));
|
|
315
413
|
var SKILL_BEGIN = "<!-- BEGIN PRIM SKILL v1 -->";
|
|
316
414
|
var SKILL_END = "<!-- END PRIM SKILL v1 -->";
|
|
317
415
|
var CODEX_GUIDANCE_LIMIT_BYTES = 1024 * 1024;
|
|
@@ -320,7 +418,7 @@ var SKILL_BEGIN_BUFFER = Buffer.from(SKILL_BEGIN);
|
|
|
320
418
|
var SKILL_END_BUFFER = Buffer.from(SKILL_END);
|
|
321
419
|
function readCodexGuidance(path) {
|
|
322
420
|
try {
|
|
323
|
-
const entry =
|
|
421
|
+
const entry = lstatSync3(path);
|
|
324
422
|
if (entry.isSymbolicLink() || !entry.isFile()) return null;
|
|
325
423
|
const fd = openSync2(path, constants2.O_RDONLY | constants2.O_NOFOLLOW);
|
|
326
424
|
try {
|
|
@@ -343,10 +441,10 @@ function readCodexGuidance(path) {
|
|
|
343
441
|
}
|
|
344
442
|
}
|
|
345
443
|
function effectiveCodexGuidance(scope) {
|
|
346
|
-
const override = readCodexGuidance(
|
|
444
|
+
const override = readCodexGuidance(join3(scope, "AGENTS.override.md"));
|
|
347
445
|
if (override === null) return null;
|
|
348
446
|
if (override !== void 0 && override.toString("utf8").trim().length > 0) return override;
|
|
349
|
-
const base = readCodexGuidance(
|
|
447
|
+
const base = readCodexGuidance(join3(scope, "AGENTS.md"));
|
|
350
448
|
return base ?? null;
|
|
351
449
|
}
|
|
352
450
|
function hasUsablePrimBlock(content, visibleBytes) {
|
|
@@ -369,7 +467,7 @@ function hasUsablePrimBlock(content, visibleBytes) {
|
|
|
369
467
|
}
|
|
370
468
|
function hasUsableCodexGuidance(projectRoot) {
|
|
371
469
|
try {
|
|
372
|
-
const codexHome = process.env.CODEX_HOME?.trim() ? resolve2(process.env.CODEX_HOME) :
|
|
470
|
+
const codexHome = process.env.CODEX_HOME?.trim() ? resolve2(process.env.CODEX_HOME) : join3(homedir3(), ".codex");
|
|
373
471
|
const scopes = [
|
|
374
472
|
{ path: codexHome, visibleBytes: CODEX_GUIDANCE_LIMIT_BYTES },
|
|
375
473
|
{ path: projectRoot, visibleBytes: CODEX_DEFAULT_PROJECT_GUIDANCE_BYTES }
|
|
@@ -399,23 +497,23 @@ var AGENT_TARGET = {
|
|
|
399
497
|
var CURSOR_SKILL_OWNER = "@primitive.ai/prim";
|
|
400
498
|
var CURSOR_SKILL_MANIFEST = ".prim-owned.json";
|
|
401
499
|
function sha256(content) {
|
|
402
|
-
return
|
|
500
|
+
return createHash3("sha256").update(content).digest("hex");
|
|
403
501
|
}
|
|
404
502
|
function cursorSkillDirectory(cwd, scope) {
|
|
405
503
|
const base = scope === "user" ? cursorConfigDirectory() : gitToplevel(cwd) ?? cwd;
|
|
406
|
-
return
|
|
504
|
+
return join3(base, scope === "user" ? "skills" : ".cursor/skills", "prim");
|
|
407
505
|
}
|
|
408
506
|
function cursorSkillPaths(cwd, scope) {
|
|
409
507
|
const directory = cursorSkillDirectory(cwd, scope);
|
|
410
508
|
return {
|
|
411
509
|
directory,
|
|
412
|
-
skill:
|
|
413
|
-
manifest:
|
|
510
|
+
skill: join3(directory, "SKILL.md"),
|
|
511
|
+
manifest: join3(directory, CURSOR_SKILL_MANIFEST)
|
|
414
512
|
};
|
|
415
513
|
}
|
|
416
514
|
function readCursorSkillManifest(path) {
|
|
417
515
|
try {
|
|
418
|
-
const value = JSON.parse(
|
|
516
|
+
const value = JSON.parse(readFileSync3(path, "utf8"));
|
|
419
517
|
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
420
518
|
const record = value;
|
|
421
519
|
if (record.version !== 1 || record.owner !== CURSOR_SKILL_OWNER || typeof record.contentSha256 !== "string" || !/^[0-9a-f]{64}$/u.test(record.contentSha256)) {
|
|
@@ -429,7 +527,7 @@ function readCursorSkillManifest(path) {
|
|
|
429
527
|
function cursorSkillStatus(cwd, scope) {
|
|
430
528
|
const paths = cursorSkillPaths(cwd, scope);
|
|
431
529
|
const manifest = readCursorSkillManifest(paths.manifest);
|
|
432
|
-
const content =
|
|
530
|
+
const content = existsSync3(paths.skill) ? readFileSync3(paths.skill, "utf8") : void 0;
|
|
433
531
|
const owned = manifest !== void 0;
|
|
434
532
|
const installed = owned && content !== void 0 && sha256(content) === manifest.contentSha256;
|
|
435
533
|
return {
|
|
@@ -447,8 +545,8 @@ function validCursorSkillScope(scope) {
|
|
|
447
545
|
function installCursorSkill(cwd, opts) {
|
|
448
546
|
const paths = cursorSkillPaths(cwd, opts.scope);
|
|
449
547
|
const status = cursorSkillStatus(cwd, opts.scope);
|
|
450
|
-
const manifestExists =
|
|
451
|
-
const skillExists =
|
|
548
|
+
const manifestExists = existsSync3(paths.manifest);
|
|
549
|
+
const skillExists = existsSync3(paths.skill);
|
|
452
550
|
if (manifestExists && !status.owned || !manifestExists && skillExists || status.edited) {
|
|
453
551
|
console.error(`Refusing to overwrite a foreign or edited Cursor skill at ${paths.skill}`);
|
|
454
552
|
return 1;
|
|
@@ -459,12 +557,12 @@ function installCursorSkill(cwd, opts) {
|
|
|
459
557
|
owner: CURSOR_SKILL_OWNER,
|
|
460
558
|
contentSha256: sha256(content)
|
|
461
559
|
};
|
|
462
|
-
if (status.installed &&
|
|
560
|
+
if (status.installed && readFileSync3(paths.skill, "utf8") === content) {
|
|
463
561
|
console.log(`No changes \u2014 Cursor skill already up to date at ${paths.skill}`);
|
|
464
562
|
return 0;
|
|
465
563
|
}
|
|
466
564
|
if (opts.dryRun) {
|
|
467
|
-
const existing = skillExists ?
|
|
565
|
+
const existing = skillExists ? readFileSync3(paths.skill, "utf8") : "";
|
|
468
566
|
process.stdout.write(createPatch(paths.skill, existing, content, "current", "proposed"));
|
|
469
567
|
return 0;
|
|
470
568
|
}
|
|
@@ -485,10 +583,10 @@ function uninstallCursorSkill(cwd, scope) {
|
|
|
485
583
|
console.error(`Refusing to remove an edited Cursor skill at ${paths.skill}`);
|
|
486
584
|
return 1;
|
|
487
585
|
}
|
|
488
|
-
if (
|
|
489
|
-
if (
|
|
586
|
+
if (existsSync3(paths.skill)) unlinkSync2(paths.skill);
|
|
587
|
+
if (existsSync3(paths.manifest)) unlinkSync2(paths.manifest);
|
|
490
588
|
try {
|
|
491
|
-
if (
|
|
589
|
+
if (readdirSync3(paths.directory).length === 0) rmdirSync3(paths.directory);
|
|
492
590
|
} catch {
|
|
493
591
|
}
|
|
494
592
|
console.log(`Removed Primitive-owned Cursor skill from ${paths.skill}`);
|
|
@@ -498,24 +596,27 @@ function hasUsableCursorSkill(projectRoot) {
|
|
|
498
596
|
return cursorSkillStatus(projectRoot, "project").installed || cursorSkillStatus(projectRoot, "user").installed;
|
|
499
597
|
}
|
|
500
598
|
function userTargetFor(agent) {
|
|
501
|
-
if (agent === "claude") return
|
|
502
|
-
if (agent === "codex")
|
|
599
|
+
if (agent === "claude") return join3(homedir3(), ".claude", "CLAUDE.md");
|
|
600
|
+
if (agent === "codex") {
|
|
601
|
+
const home = process.env.CODEX_HOME?.trim() ? resolve2(process.env.CODEX_HOME) : join3(homedir3(), ".codex");
|
|
602
|
+
return join3(home, "AGENTS.md");
|
|
603
|
+
}
|
|
503
604
|
if (agent === "hermes") {
|
|
504
|
-
return
|
|
605
|
+
return join3(process.env.HERMES_HOME ?? join3(homedir3(), ".hermes"), ".hermes.md");
|
|
505
606
|
}
|
|
506
607
|
return null;
|
|
507
608
|
}
|
|
508
|
-
function loadSkill() {
|
|
609
|
+
function loadSkill(file = "SKILL.md") {
|
|
509
610
|
let dir = __dirname2;
|
|
510
|
-
while (dir !==
|
|
511
|
-
const p = resolve2(dir,
|
|
512
|
-
if (
|
|
513
|
-
dir =
|
|
611
|
+
while (dir !== dirname3(dir)) {
|
|
612
|
+
const p = resolve2(dir, file);
|
|
613
|
+
if (existsSync3(p)) return readFileSync3(p, "utf-8");
|
|
614
|
+
dir = dirname3(dir);
|
|
514
615
|
}
|
|
515
|
-
throw new Error(
|
|
616
|
+
throw new Error(`${file} not found in package`);
|
|
516
617
|
}
|
|
517
618
|
function detectTargets(cwd) {
|
|
518
|
-
return TARGET_CANDIDATES.filter((p) =>
|
|
619
|
+
return TARGET_CANDIDATES.filter((p) => existsSync3(resolve2(cwd, p)));
|
|
519
620
|
}
|
|
520
621
|
function detectNewline(content) {
|
|
521
622
|
return content.includes("\r\n") ? "\r\n" : "\n";
|
|
@@ -542,7 +643,7 @@ function removeBlock(existing) {
|
|
|
542
643
|
return out.replace(/(\r?\n){2,}$/, "$1");
|
|
543
644
|
}
|
|
544
645
|
function atomicWrite(target, content) {
|
|
545
|
-
atomicWriteFile(target, content);
|
|
646
|
+
atomicWriteFile(target, content, { ensureParent: true });
|
|
546
647
|
}
|
|
547
648
|
function resolveTarget(cwd, opts) {
|
|
548
649
|
if (opts.scope && opts.scope !== "user" && opts.scope !== "project") {
|
|
@@ -581,18 +682,22 @@ function runInstall(cwd, opts) {
|
|
|
581
682
|
}
|
|
582
683
|
const target = resolveTarget(cwd, opts);
|
|
583
684
|
if (target === null) return 1;
|
|
584
|
-
const existing =
|
|
685
|
+
const existing = existsSync3(target) ? readFileSync3(target, "utf-8") : "";
|
|
585
686
|
const eol = existing ? detectNewline(existing) : "\n";
|
|
586
687
|
const block = composeBlock(loadSkill(), eol);
|
|
587
688
|
const next = applyBlock(existing, block, eol);
|
|
689
|
+
const installCodexWelcome = () => opts.agent === "codex" && opts.scope === "user" && !opts.target ? installWelcomeSkill(codexWelcomeSkillPath(), loadSkill(WELCOME_SKILL_SOURCE), opts.dryRun) : 0;
|
|
588
690
|
if (next === existing) {
|
|
691
|
+
if (installCodexWelcome() !== 0) return 1;
|
|
589
692
|
console.log("No changes \u2014 skill block already up to date.");
|
|
590
693
|
return 0;
|
|
591
694
|
}
|
|
592
695
|
if (opts.dryRun) {
|
|
696
|
+
if (installCodexWelcome() !== 0) return 1;
|
|
593
697
|
process.stdout.write(createPatch(target, existing, next, "current", "proposed"));
|
|
594
698
|
return 0;
|
|
595
699
|
}
|
|
700
|
+
if (installCodexWelcome() !== 0) return 1;
|
|
596
701
|
atomicWrite(target, next);
|
|
597
702
|
console.log(`Wrote ${Buffer.byteLength(next)} bytes to ${target}`);
|
|
598
703
|
return 0;
|
|
@@ -603,13 +708,16 @@ function runUninstall(cwd, opts) {
|
|
|
603
708
|
if (!validCursorSkillScope(opts.scope)) return 1;
|
|
604
709
|
return uninstallCursorSkill(cwd, opts.scope);
|
|
605
710
|
}
|
|
711
|
+
if (opts.agent === "codex" && opts.scope === "user" && !opts.target) {
|
|
712
|
+
if (uninstallWelcomeSkill(codexWelcomeSkillPath()) !== 0) return 1;
|
|
713
|
+
}
|
|
606
714
|
const target = resolveTarget(cwd, opts);
|
|
607
715
|
if (target === null) return 1;
|
|
608
|
-
if (!
|
|
716
|
+
if (!existsSync3(target)) {
|
|
609
717
|
console.log(`Skill block not present at ${target}`);
|
|
610
718
|
return 0;
|
|
611
719
|
}
|
|
612
|
-
const existing =
|
|
720
|
+
const existing = readFileSync3(target, "utf-8");
|
|
613
721
|
const next = removeBlock(existing);
|
|
614
722
|
if (next === null) {
|
|
615
723
|
console.log(`Skill block not present at ${target}`);
|
|
@@ -633,14 +741,20 @@ function runStatus(cwd, opts) {
|
|
|
633
741
|
}
|
|
634
742
|
const target = resolveTarget(cwd, opts);
|
|
635
743
|
if (target === null) return 1;
|
|
636
|
-
const fileExists =
|
|
637
|
-
let
|
|
744
|
+
const fileExists = existsSync3(target);
|
|
745
|
+
let mainInstalled = false;
|
|
638
746
|
if (fileExists) {
|
|
639
|
-
const content =
|
|
640
|
-
|
|
747
|
+
const content = readFileSync3(target, "utf-8");
|
|
748
|
+
mainInstalled = content.includes(SKILL_BEGIN) && content.includes(SKILL_END);
|
|
641
749
|
}
|
|
750
|
+
const welcome = opts.agent === "codex" && opts.scope === "user" && !opts.target ? welcomeSkillStatus(codexWelcomeSkillPath()) : void 0;
|
|
751
|
+
const installed = mainInstalled && (!welcome || welcome.installed);
|
|
642
752
|
if (opts.json) {
|
|
643
|
-
printJson({
|
|
753
|
+
printJson({
|
|
754
|
+
installed,
|
|
755
|
+
target,
|
|
756
|
+
...welcome ? { welcomeSkill: welcome.installed } : {}
|
|
757
|
+
});
|
|
644
758
|
return installed ? 0 : 1;
|
|
645
759
|
}
|
|
646
760
|
if (!fileExists) {
|
|
@@ -651,6 +765,10 @@ function runStatus(cwd, opts) {
|
|
|
651
765
|
console.log(`PRIM SKILL v1 installed at ${target}`);
|
|
652
766
|
return 0;
|
|
653
767
|
}
|
|
768
|
+
if (mainInstalled && welcome && !welcome.installed) {
|
|
769
|
+
console.log(`No intact prim-welcome skill at ${welcome.target}`);
|
|
770
|
+
return 1;
|
|
771
|
+
}
|
|
654
772
|
console.log(`No PRIM SKILL block at ${target}`);
|
|
655
773
|
return 1;
|
|
656
774
|
}
|
|
@@ -674,14 +792,14 @@ function registerSkillCommands(program) {
|
|
|
674
792
|
|
|
675
793
|
// src/lib/bin-cache.ts
|
|
676
794
|
import { chmodSync, mkdirSync as mkdirSync2 } from "fs";
|
|
677
|
-
import { homedir as
|
|
678
|
-
import { join as
|
|
795
|
+
import { homedir as homedir4 } from "os";
|
|
796
|
+
import { join as join4 } from "path";
|
|
679
797
|
var GIT_HOOK_CACHE_SHELL_DIR = "${XDG_CACHE_HOME:-$HOME/.cache}/prim/bin";
|
|
680
798
|
var GIT_HOOK_CACHE_TTL_MINUTES = 1440;
|
|
681
799
|
var GIT_HOOK_CACHED_BINS = ["prim-post-commit", "prim-post-rewrite"];
|
|
682
800
|
function binCacheDir() {
|
|
683
|
-
const base = process.env.XDG_CACHE_HOME ||
|
|
684
|
-
return
|
|
801
|
+
const base = process.env.XDG_CACHE_HOME || join4(homedir4(), ".cache");
|
|
802
|
+
return join4(base, "prim", "bin");
|
|
685
803
|
}
|
|
686
804
|
function writeAtomic(path, content) {
|
|
687
805
|
atomicWriteFile(path, content, { mode: 384 });
|
|
@@ -694,11 +812,11 @@ function warmBinCache() {
|
|
|
694
812
|
const dir = binCacheDir();
|
|
695
813
|
mkdirSync2(dir, { recursive: true, mode: 448 });
|
|
696
814
|
chmodSync(dir, 448);
|
|
697
|
-
writeAtomic(
|
|
815
|
+
writeAtomic(join4(dir, "node"), process.execPath);
|
|
698
816
|
for (const bin of GIT_HOOK_CACHED_BINS) {
|
|
699
817
|
const file = binFile(bin);
|
|
700
818
|
if (file) {
|
|
701
|
-
writeAtomic(
|
|
819
|
+
writeAtomic(join4(dir, bin), file);
|
|
702
820
|
}
|
|
703
821
|
}
|
|
704
822
|
} catch {
|
|
@@ -939,23 +1057,23 @@ ${end}`;
|
|
|
939
1057
|
|
|
940
1058
|
// src/lib/git-hooks.ts
|
|
941
1059
|
import { execFileSync } from "child_process";
|
|
942
|
-
import { createHash as
|
|
1060
|
+
import { createHash as createHash4, randomUUID } from "crypto";
|
|
943
1061
|
import {
|
|
944
1062
|
constants as constants3,
|
|
945
1063
|
closeSync as closeSync3,
|
|
946
|
-
existsSync as
|
|
1064
|
+
existsSync as existsSync4,
|
|
947
1065
|
fchmodSync,
|
|
948
1066
|
fsyncSync,
|
|
949
|
-
lstatSync as
|
|
1067
|
+
lstatSync as lstatSync4,
|
|
950
1068
|
mkdirSync as mkdirSync3,
|
|
951
1069
|
openSync as openSync3,
|
|
952
|
-
readFileSync as
|
|
1070
|
+
readFileSync as readFileSync4,
|
|
953
1071
|
realpathSync as realpathSync2,
|
|
954
1072
|
renameSync,
|
|
955
|
-
unlinkSync as
|
|
1073
|
+
unlinkSync as unlinkSync3,
|
|
956
1074
|
writeFileSync
|
|
957
1075
|
} from "fs";
|
|
958
|
-
import { basename, dirname as
|
|
1076
|
+
import { basename, dirname as dirname4, isAbsolute as isAbsolute3, join as join5, relative as relative2, resolve as resolve3, sep as sep2 } from "path";
|
|
959
1077
|
var LEGACY_PRIM_CREATED_MARK = "prim-created-hook";
|
|
960
1078
|
var LEGACY_PRIM_OWNED_HEADER = "# prim post-commit hook \u2014 installed by: prim hooks install (prim-managed-hook)";
|
|
961
1079
|
var LEGACY_GLOBAL_OWNED_HEADER = "# prim global post-commit hook (core.hooksPath) \u2014 managed by prim; do not edit.";
|
|
@@ -1090,9 +1208,9 @@ function realpathLoose(path) {
|
|
|
1090
1208
|
let current = resolve3(path);
|
|
1091
1209
|
for (; ; ) {
|
|
1092
1210
|
try {
|
|
1093
|
-
return
|
|
1211
|
+
return join5(realpathSync2.native(current), ...missing);
|
|
1094
1212
|
} catch {
|
|
1095
|
-
const parent =
|
|
1213
|
+
const parent = dirname4(current);
|
|
1096
1214
|
if (parent === current) return resolve3(path);
|
|
1097
1215
|
missing.unshift(basename(current));
|
|
1098
1216
|
current = parent;
|
|
@@ -1105,7 +1223,7 @@ function isWithin(path, directory) {
|
|
|
1105
1223
|
}
|
|
1106
1224
|
function primGitHooksDirectory() {
|
|
1107
1225
|
try {
|
|
1108
|
-
return
|
|
1226
|
+
return join5(primConfigDirectory(), "git-hooks");
|
|
1109
1227
|
} catch {
|
|
1110
1228
|
return void 0;
|
|
1111
1229
|
}
|
|
@@ -1189,8 +1307,8 @@ function resolveEffectiveGitHook(hookName, cwd = process.cwd()) {
|
|
|
1189
1307
|
gitDir: safeGitPath(gitRoot, gitDirValue),
|
|
1190
1308
|
commonDir: safeGitPath(gitRoot, commonDirValue)
|
|
1191
1309
|
};
|
|
1192
|
-
if (basename(hooksDir) === "_" && basename(
|
|
1193
|
-
const hookPath2 = resolve3(
|
|
1310
|
+
if (basename(hooksDir) === "_" && basename(dirname4(hooksDir)) === ".husky") {
|
|
1311
|
+
const hookPath2 = resolve3(dirname4(hooksDir), hookName);
|
|
1194
1312
|
return {
|
|
1195
1313
|
gitRoot,
|
|
1196
1314
|
hooksDir,
|
|
@@ -1210,8 +1328,8 @@ function resolveEffectiveGitHook(hookName, cwd = process.cwd()) {
|
|
|
1210
1328
|
};
|
|
1211
1329
|
}
|
|
1212
1330
|
function assertSafeFile(path, spec) {
|
|
1213
|
-
if (!
|
|
1214
|
-
const stat =
|
|
1331
|
+
if (!existsSync4(path)) return void 0;
|
|
1332
|
+
const stat = lstatSync4(path);
|
|
1215
1333
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > MAX_HOOK_BYTES) {
|
|
1216
1334
|
throw new Error(`unsafe ${spec.hookName} hook target: ${path}`);
|
|
1217
1335
|
}
|
|
@@ -1232,16 +1350,16 @@ function assertUsableHuskyDispatcher(target, spec) {
|
|
|
1232
1350
|
if (!HUSKY_V9_DISPATCHERS.has(normalizedDispatcher)) {
|
|
1233
1351
|
throw new Error(`unrecognized Husky ${spec.hookName} dispatcher: ${target.dispatcherPath}`);
|
|
1234
1352
|
}
|
|
1235
|
-
const huskyRuntime = resolve3(
|
|
1353
|
+
const huskyRuntime = resolve3(dirname4(target.dispatcherPath), "h");
|
|
1236
1354
|
const runtimeStat = assertSafeFile(huskyRuntime, spec);
|
|
1237
1355
|
const runtime = runtimeStat ? readHookFile(huskyRuntime) : void 0;
|
|
1238
|
-
const runtimeHash = runtime ?
|
|
1356
|
+
const runtimeHash = runtime ? createHash4("sha256").update(runtime).digest("hex") : void 0;
|
|
1239
1357
|
if (!runtimeHash || !HUSKY_V9_RUNTIME_HASHES.has(runtimeHash)) {
|
|
1240
1358
|
throw new Error(`unrecognized Husky v9 hook runtime: ${huskyRuntime}`);
|
|
1241
1359
|
}
|
|
1242
1360
|
}
|
|
1243
1361
|
function readHookFile(path) {
|
|
1244
|
-
const value =
|
|
1362
|
+
const value = readFileSync4(path);
|
|
1245
1363
|
return Buffer.isBuffer(value) ? value : Buffer.from(value);
|
|
1246
1364
|
}
|
|
1247
1365
|
function decodeHookText(content, spec) {
|
|
@@ -1313,11 +1431,11 @@ function blockInsertionPoint(content, spec, huskyV8) {
|
|
|
1313
1431
|
var HUSKY_SPEC_MAJOR_RE = /^\s*[~^]?=?\s*v?([0-9]+)(?:\.(?:[0-9]+|[xX*])){0,2}(?:-[0-9A-Za-z.-]+)?\s*$/u;
|
|
1314
1432
|
function declaredHuskyMajor(dir) {
|
|
1315
1433
|
for (let current = resolve3(dir); ; ) {
|
|
1316
|
-
const manifest =
|
|
1317
|
-
if (
|
|
1434
|
+
const manifest = join5(current, "package.json");
|
|
1435
|
+
if (existsSync4(manifest)) {
|
|
1318
1436
|
try {
|
|
1319
|
-
if (
|
|
1320
|
-
const parsed = JSON.parse(
|
|
1437
|
+
if (lstatSync4(manifest).size > MAX_HOOK_BYTES) return void 0;
|
|
1438
|
+
const parsed = JSON.parse(readFileSync4(manifest, "utf8"));
|
|
1321
1439
|
const range = parsed.devDependencies?.husky ?? parsed.dependencies?.husky;
|
|
1322
1440
|
const major = typeof range === "string" ? HUSKY_SPEC_MAJOR_RE.exec(range)?.[1] : void 0;
|
|
1323
1441
|
return major === void 0 ? void 0 : Number(major);
|
|
@@ -1325,20 +1443,20 @@ function declaredHuskyMajor(dir) {
|
|
|
1325
1443
|
return void 0;
|
|
1326
1444
|
}
|
|
1327
1445
|
}
|
|
1328
|
-
const parent =
|
|
1329
|
-
if (parent === current ||
|
|
1446
|
+
const parent = dirname4(current);
|
|
1447
|
+
if (parent === current || existsSync4(join5(current, ".git"))) return void 0;
|
|
1330
1448
|
current = parent;
|
|
1331
1449
|
}
|
|
1332
1450
|
}
|
|
1333
1451
|
function isHuskyV8Hook(hookPath) {
|
|
1334
|
-
const runtime =
|
|
1452
|
+
const runtime = join5(dirname4(hookPath), "_", "husky.sh");
|
|
1335
1453
|
try {
|
|
1336
|
-
const stat =
|
|
1337
|
-
return stat.isFile() && stat.size <= MAX_HOOK_BYTES &&
|
|
1454
|
+
const stat = lstatSync4(runtime);
|
|
1455
|
+
return stat.isFile() && stat.size <= MAX_HOOK_BYTES && readFileSync4(runtime, "utf8").includes("husky_skip_init");
|
|
1338
1456
|
} catch (error) {
|
|
1339
1457
|
if (errorCode(error) !== "ENOENT") return false;
|
|
1340
1458
|
}
|
|
1341
|
-
const major = declaredHuskyMajor(
|
|
1459
|
+
const major = declaredHuskyMajor(dirname4(dirname4(hookPath)));
|
|
1342
1460
|
return major !== void 0 && major <= 8;
|
|
1343
1461
|
}
|
|
1344
1462
|
var TERMINAL_LINE_RE = /^(?:exit|return)(?:\s|;|$)/u;
|
|
@@ -1475,7 +1593,7 @@ function errorCode(error) {
|
|
|
1475
1593
|
function assertTargetUnchanged(path, expected, spec, stat) {
|
|
1476
1594
|
let current;
|
|
1477
1595
|
try {
|
|
1478
|
-
current =
|
|
1596
|
+
current = lstatSync4(path);
|
|
1479
1597
|
} catch (error) {
|
|
1480
1598
|
if (expected === void 0 && errorCode(error) === "ENOENT") return;
|
|
1481
1599
|
throw new Error(`${spec.hookName} hook changed concurrently: ${path}`);
|
|
@@ -1488,7 +1606,7 @@ function assertTargetUnchanged(path, expected, spec, stat) {
|
|
|
1488
1606
|
}
|
|
1489
1607
|
}
|
|
1490
1608
|
function rewriteHookAtomically(path, next, expected, spec, stat) {
|
|
1491
|
-
const parent =
|
|
1609
|
+
const parent = dirname4(path);
|
|
1492
1610
|
mkdirSync3(parent, { recursive: true });
|
|
1493
1611
|
const temporary = resolve3(
|
|
1494
1612
|
parent,
|
|
@@ -1516,7 +1634,7 @@ function rewriteHookAtomically(path, next, expected, spec, stat) {
|
|
|
1516
1634
|
}
|
|
1517
1635
|
}
|
|
1518
1636
|
try {
|
|
1519
|
-
|
|
1637
|
+
unlinkSync3(temporary);
|
|
1520
1638
|
} catch (error) {
|
|
1521
1639
|
if (errorCode(error) !== "ENOENT") {
|
|
1522
1640
|
}
|
|
@@ -1525,7 +1643,7 @@ function rewriteHookAtomically(path, next, expected, spec, stat) {
|
|
|
1525
1643
|
}
|
|
1526
1644
|
function unlinkHookUnchanged(path, expected, stat, spec) {
|
|
1527
1645
|
assertTargetUnchanged(path, expected, spec, stat);
|
|
1528
|
-
|
|
1646
|
+
unlinkSync3(path);
|
|
1529
1647
|
}
|
|
1530
1648
|
function workingLegacyBlock(content, spec) {
|
|
1531
1649
|
try {
|
|
@@ -1589,8 +1707,8 @@ function ensureEffectiveGitHook(hookName, cwd = process.cwd(), options = {}) {
|
|
|
1589
1707
|
function explicitTarget(hookPath, options) {
|
|
1590
1708
|
const absolute = resolve3(hookPath);
|
|
1591
1709
|
return {
|
|
1592
|
-
gitRoot:
|
|
1593
|
-
hooksDir:
|
|
1710
|
+
gitRoot: dirname4(dirname4(absolute)),
|
|
1711
|
+
hooksDir: dirname4(absolute),
|
|
1594
1712
|
hookPath: absolute,
|
|
1595
1713
|
// A `.husky/<hook>` file is run by Husky's dispatcher via `sh`, so it needs
|
|
1596
1714
|
// neither a shebang nor the executable bit.
|
|
@@ -1863,9 +1981,12 @@ export {
|
|
|
1863
1981
|
bindRepositoryWithClient,
|
|
1864
1982
|
bindRepository,
|
|
1865
1983
|
printJson,
|
|
1866
|
-
|
|
1984
|
+
codexWelcomeSkillPath,
|
|
1867
1985
|
hasUsableCodexGuidance,
|
|
1868
1986
|
hasUsableCursorSkill,
|
|
1987
|
+
userTargetFor,
|
|
1869
1988
|
registerSkillCommands,
|
|
1989
|
+
welcomeSkillPathFor,
|
|
1990
|
+
refreshClaudePlugins,
|
|
1870
1991
|
kickDaemonEnsure
|
|
1871
1992
|
};
|