joycraft 0.7.12 → 0.7.14

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 (54) hide show
  1. package/README.md +30 -16
  2. package/dist/chunk-7BPB2IKY.js +255 -0
  3. package/dist/chunk-7BPB2IKY.js.map +1 -0
  4. package/dist/chunk-B73DPYYC.js +377 -0
  5. package/dist/chunk-B73DPYYC.js.map +1 -0
  6. package/dist/{chunk-DSVGHVYM.js → chunk-JYPBXPGD.js} +117 -90
  7. package/dist/chunk-JYPBXPGD.js.map +1 -0
  8. package/dist/{chunk-OAC5CVHJ.js → chunk-K4AI6FKB.js} +12 -2
  9. package/dist/chunk-K4AI6FKB.js.map +1 -0
  10. package/dist/{chunk-PBOICMDE.js → chunk-KKDKC4FM.js} +11 -73
  11. package/dist/chunk-KKDKC4FM.js.map +1 -0
  12. package/dist/chunk-OMFGDJW4.js +97 -0
  13. package/dist/chunk-OMFGDJW4.js.map +1 -0
  14. package/dist/chunk-PR4QDKPL.js +3755 -0
  15. package/dist/chunk-PR4QDKPL.js.map +1 -0
  16. package/dist/chunk-Z5JFEGWG.js +563 -0
  17. package/dist/chunk-Z5JFEGWG.js.map +1 -0
  18. package/dist/cli.js +389 -56
  19. package/dist/cli.js.map +1 -1
  20. package/dist/index.d.ts +235 -1
  21. package/dist/index.js +691 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/init-S5JU5BHL.js +60 -0
  24. package/dist/init-S5JU5BHL.js.map +1 -0
  25. package/dist/{init-autofix-YCSDK5ZR.js → init-autofix-WSKUT2HN.js} +4 -3
  26. package/dist/{init-autofix-YCSDK5ZR.js.map → init-autofix-WSKUT2HN.js.map} +1 -1
  27. package/dist/install-manifest-EQHT4474.js +37 -0
  28. package/dist/joycraft-release.json +8 -0
  29. package/dist/release-artifact-4TL5L2ZY.js +14 -0
  30. package/dist/release-resolver-P2H46QTU.js +293 -0
  31. package/dist/release-resolver-P2H46QTU.js.map +1 -0
  32. package/dist/{telemetry-store-X7K5NYWD.js → telemetry-store-IBO5GRTA.js} +2 -2
  33. package/dist/telemetry-store-IBO5GRTA.js.map +1 -0
  34. package/dist/update-HNTXCEKB.js +19 -0
  35. package/dist/update-HNTXCEKB.js.map +1 -0
  36. package/dist/update-check-YT765NE7.js +36 -0
  37. package/dist/update-check-YT765NE7.js.map +1 -0
  38. package/dist/upgrade-LZOND7OZ.js +28 -0
  39. package/dist/upgrade-LZOND7OZ.js.map +1 -0
  40. package/package.json +5 -2
  41. package/dist/chunk-BZW5DR3O.js +0 -91
  42. package/dist/chunk-BZW5DR3O.js.map +0 -1
  43. package/dist/chunk-DSVGHVYM.js.map +0 -1
  44. package/dist/chunk-OAC5CVHJ.js.map +0 -1
  45. package/dist/chunk-PBOICMDE.js.map +0 -1
  46. package/dist/chunk-Q2ZQ6RGD.js +0 -243
  47. package/dist/chunk-Q2ZQ6RGD.js.map +0 -1
  48. package/dist/init-J5Q6RX3K.js +0 -1307
  49. package/dist/init-J5Q6RX3K.js.map +0 -1
  50. package/dist/upgrade-AHUSQZEQ.js +0 -643
  51. package/dist/upgrade-AHUSQZEQ.js.map +0 -1
  52. package/dist/version-B2CCAEMC.js +0 -28
  53. /package/dist/{telemetry-store-X7K5NYWD.js.map → install-manifest-EQHT4474.js.map} +0 -0
  54. /package/dist/{version-B2CCAEMC.js.map → release-artifact-4TL5L2ZY.js.map} +0 -0
@@ -1,643 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- applyGitattributes,
4
- defaultExecutionProfile,
5
- ensureExecutionProfileSection,
6
- ensureFolderMapSection,
7
- getPackageVersion
8
- } from "./chunk-Q2ZQ6RGD.js";
9
- import {
10
- PRIVATE_PROFILE_IGNORES,
11
- PRIVATE_UNTRACK_COMMAND,
12
- applyGitignoreProfile,
13
- resolveGitignoreProfile,
14
- validateGitignoreFlag
15
- } from "./chunk-BZW5DR3O.js";
16
- import "./chunk-OAC5CVHJ.js";
17
- import {
18
- CODEX_SKILLS,
19
- COPILOT_SKILLS,
20
- PI_AGENTS,
21
- PI_EXTENSIONS,
22
- PI_SCRIPTS,
23
- PI_SKILLS,
24
- SKILLS,
25
- TEMPLATES
26
- } from "./chunk-DSVGHVYM.js";
27
- import {
28
- HARNESSES,
29
- LEGACY_CLAUDE_STATE_PATH,
30
- LEGACY_VERSION_FILE,
31
- hashContent,
32
- parseGitignoreProfile,
33
- readVersion,
34
- sanitizeHarnesses,
35
- truncateHash,
36
- writeVersion
37
- } from "./chunk-PBOICMDE.js";
38
-
39
- // src/upgrade.ts
40
- import { existsSync as existsSync2, readFileSync, writeFileSync, mkdirSync as mkdirSync2, rmSync as rmSync2, rmdirSync, chmodSync } from "fs";
41
- import { join as join2, dirname, resolve } from "path";
42
- import { createInterface } from "readline";
43
- import { execFileSync, spawnSync } from "child_process";
44
-
45
- // src/migration.ts
46
- import {
47
- cpSync,
48
- existsSync,
49
- mkdirSync,
50
- readdirSync,
51
- renameSync,
52
- rmSync,
53
- statSync
54
- } from "fs";
55
- import { join } from "path";
56
- var DATE_PREFIX_RE = /^\d{4}-\d{2}-\d{2}-(.+)$/;
57
- function deriveSlug(filename) {
58
- return filename.replace(/\.md$/, "");
59
- }
60
- function slugWithoutDate(slug) {
61
- const m = slug.match(DATE_PREFIX_RE);
62
- return m ? m[1] : null;
63
- }
64
- function listMdFiles(dir) {
65
- if (!existsSync(dir)) return [];
66
- try {
67
- return readdirSync(dir).filter((f) => f.endsWith(".md"));
68
- } catch {
69
- return [];
70
- }
71
- }
72
- function listSubdirs(dir) {
73
- if (!existsSync(dir)) return [];
74
- try {
75
- return readdirSync(dir).filter((name) => {
76
- try {
77
- return statSync(join(dir, name)).isDirectory();
78
- } catch {
79
- return false;
80
- }
81
- });
82
- } catch {
83
- return [];
84
- }
85
- }
86
- function planMigration(projectDir) {
87
- const briefsDir = join(projectDir, "docs", "briefs");
88
- const researchDir = join(projectDir, "docs", "research");
89
- const designsDir = join(projectDir, "docs", "designs");
90
- const specsDir = join(projectDir, "docs", "specs");
91
- const moves = [];
92
- const skipped = [];
93
- const slugSet = /* @__PURE__ */ new Set();
94
- for (const file of listMdFiles(briefsDir)) {
95
- const slug = deriveSlug(file);
96
- slugSet.add(slug);
97
- const move = {
98
- from: join(briefsDir, file),
99
- to: join(projectDir, "docs", "features", slug, "brief.md"),
100
- kind: "brief"
101
- };
102
- if (existsSync(move.to)) skipped.push(move);
103
- else moves.push(move);
104
- }
105
- for (const file of listMdFiles(researchDir)) {
106
- const slug = deriveSlug(file);
107
- slugSet.add(slug);
108
- const move = {
109
- from: join(researchDir, file),
110
- to: join(projectDir, "docs", "features", slug, "research.md"),
111
- kind: "research"
112
- };
113
- if (existsSync(move.to)) skipped.push(move);
114
- else moves.push(move);
115
- }
116
- for (const file of listMdFiles(designsDir)) {
117
- const slug = deriveSlug(file);
118
- slugSet.add(slug);
119
- const move = {
120
- from: join(designsDir, file),
121
- to: join(projectDir, "docs", "features", slug, "design.md"),
122
- kind: "design"
123
- };
124
- if (existsSync(move.to)) skipped.push(move);
125
- else moves.push(move);
126
- }
127
- const briefSlugs = Array.from(slugSet);
128
- const orphanSpecsDirs = [];
129
- for (const subdir of listSubdirs(specsDir)) {
130
- let matchedSlug = null;
131
- if (briefSlugs.includes(subdir)) {
132
- matchedSlug = subdir;
133
- } else {
134
- for (const slug of briefSlugs) {
135
- if (slugWithoutDate(slug) === subdir) {
136
- matchedSlug = slug;
137
- break;
138
- }
139
- }
140
- }
141
- if (matchedSlug) {
142
- const move = {
143
- from: join(specsDir, subdir),
144
- to: join(projectDir, "docs", "features", matchedSlug, "specs"),
145
- kind: "specs-dir"
146
- };
147
- if (existsSync(move.to)) skipped.push(move);
148
- else moves.push(move);
149
- } else {
150
- orphanSpecsDirs.push(subdir);
151
- const move = {
152
- from: join(specsDir, subdir),
153
- to: join(projectDir, "docs", "bugfixes", subdir),
154
- kind: "bugfix-dir"
155
- };
156
- if (existsSync(move.to)) skipped.push(move);
157
- else moves.push(move);
158
- }
159
- }
160
- const plan = {
161
- moves,
162
- slugs: Array.from(slugSet),
163
- orphans: { specsDirs: orphanSpecsDirs }
164
- };
165
- if (skipped.length > 0) plan.skipped = skipped;
166
- return plan;
167
- }
168
- function moveFsItem(from, to) {
169
- mkdirSync(join(to, ".."), { recursive: true });
170
- try {
171
- renameSync(from, to);
172
- } catch (err) {
173
- const code = err.code;
174
- if (code === "EXDEV") {
175
- cpSync(from, to, { recursive: true });
176
- rmSync(from, { recursive: true, force: true });
177
- } else {
178
- throw err;
179
- }
180
- }
181
- }
182
- function applyMigration(plan) {
183
- let applied = 0;
184
- let skipped = plan.skipped?.length ?? 0;
185
- const errors = [];
186
- for (const move of plan.moves) {
187
- if (existsSync(move.to)) {
188
- skipped++;
189
- continue;
190
- }
191
- if (!existsSync(move.from)) {
192
- errors.push({ move, error: `Source missing: ${move.from}` });
193
- continue;
194
- }
195
- try {
196
- moveFsItem(move.from, move.to);
197
- applied++;
198
- } catch (err) {
199
- errors.push({ move, error: err.message });
200
- }
201
- }
202
- return { applied, skipped, errors };
203
- }
204
-
205
- // src/upgrade.ts
206
- function listTrackedHarnessFiles(targetDir) {
207
- const dirs = PRIVATE_PROFILE_IGNORES.map((d) => d.replace(/\/$/, ""));
208
- try {
209
- const out = execFileSync("git", ["ls-files", "-z", "--", ...dirs], {
210
- cwd: targetDir,
211
- encoding: "utf-8",
212
- stdio: ["ignore", "pipe", "ignore"]
213
- });
214
- return out.split("\0").filter((line) => line.length > 0);
215
- } catch {
216
- return [];
217
- }
218
- }
219
- function isStaleVersion(current, latest) {
220
- const currentParts = current.split(".").map(Number);
221
- const latestParts = latest.split(".").map(Number);
222
- const len = Math.max(currentParts.length, latestParts.length);
223
- for (let i = 0; i < len; i++) {
224
- const c = currentParts[i] ?? 0;
225
- const l = latestParts[i] ?? 0;
226
- if (c < l) return true;
227
- if (c > l) return false;
228
- }
229
- return false;
230
- }
231
- async function checkCliVersion() {
232
- try {
233
- const pkgVersion = getPackageVersion();
234
- const res = await fetch("https://registry.npmjs.org/joycraft/latest", {
235
- signal: AbortSignal.timeout(3e3)
236
- });
237
- if (!res.ok) return { stale: false };
238
- const data = await res.json();
239
- if (isStaleVersion(pkgVersion, data.version)) {
240
- return { stale: true, latest: data.version };
241
- }
242
- } catch {
243
- }
244
- return { stale: false };
245
- }
246
- function reexecLatestUpgrade(targetDir, opts, latest) {
247
- const args = ["-y", `joycraft@${latest}`, "upgrade", targetDir];
248
- if (opts.yes) args.push("--yes");
249
- if (opts.gitignore !== void 0) args.push("--gitignore", opts.gitignore);
250
- const spawn = opts.spawnForReexec ?? spawnSync;
251
- const npx = process.platform === "win32" ? "npx.cmd" : "npx";
252
- const result = spawn(npx, args, { stdio: "inherit" });
253
- if (result.error) return false;
254
- if (typeof result.status === "number" && result.status !== 0) {
255
- process.exitCode = result.status;
256
- }
257
- return true;
258
- }
259
- function getManagedFiles(harnesses) {
260
- const files = {};
261
- const wants = (h) => harnesses.includes(h);
262
- if (wants("claude")) {
263
- for (const [name, content] of Object.entries(SKILLS)) {
264
- const skillName = name.replace(/\.md$/, "");
265
- files[join2(".claude", "skills", skillName, "SKILL.md")] = content;
266
- }
267
- }
268
- for (const [name, content] of Object.entries(TEMPLATES)) {
269
- files[join2("docs", "templates", name)] = content;
270
- }
271
- if (wants("codex")) {
272
- for (const [name, content] of Object.entries(CODEX_SKILLS)) {
273
- const skillName = name.replace(/\.md$/, "");
274
- files[join2(".agents", "skills", skillName, "SKILL.md")] = content;
275
- }
276
- }
277
- if (wants("pi")) {
278
- for (const [name, content] of Object.entries(PI_SKILLS)) {
279
- const skillName = name.replace(/\.md$/, "");
280
- files[join2(".pi", "skills", skillName, "SKILL.md")] = content;
281
- }
282
- for (const [name, content] of Object.entries(PI_SCRIPTS)) {
283
- files[join2(".pi", "scripts", "joycraft", name)] = content;
284
- }
285
- for (const [name, content] of Object.entries(PI_EXTENSIONS)) {
286
- files[join2(".pi", "extensions", name)] = content;
287
- }
288
- for (const [name, content] of Object.entries(PI_AGENTS)) {
289
- files[join2(".pi", "agents", name)] = content;
290
- }
291
- }
292
- if (wants("copilot")) {
293
- for (const [name, content] of Object.entries(COPILOT_SKILLS)) {
294
- const skillName = name.replace(/\.md$/, "");
295
- files[join2(".github", "skills", skillName, "SKILL.md")] = content;
296
- }
297
- }
298
- return files;
299
- }
300
- var DEPRECATED_SKILL_DIRS = [
301
- // Pre-rebrand names
302
- "joysmith",
303
- // pre-rebrand main skill
304
- "joysmith-assess",
305
- // merged into joycraft-tune
306
- "joysmith-upgrade",
307
- // merged into joycraft-tune
308
- // Pre-namespace names (bare names without joycraft- prefix)
309
- "tune",
310
- // now /joycraft-tune
311
- "tune-assess",
312
- // merged into joycraft-tune
313
- "tune-upgrade",
314
- // merged into joycraft-tune
315
- "joy",
316
- // merged into joycraft-tune
317
- "interview",
318
- // now /joycraft-interview
319
- "new-feature",
320
- // now /joycraft-new-feature
321
- "decompose",
322
- // now /joycraft-decompose
323
- "session-end"
324
- // now /joycraft-session-end
325
- ];
326
- var DEPRECATED_SKILL_FILES = [
327
- "tune.md",
328
- "joy.md",
329
- "joysmith.md",
330
- "joysmith-assess.md",
331
- "joysmith-upgrade.md",
332
- "tune-assess.md",
333
- "tune-upgrade.md",
334
- "interview.md",
335
- "new-feature.md",
336
- "decompose.md",
337
- "session-end.md"
338
- ];
339
- function cleanupDeprecatedSkills(targetDir) {
340
- const skillsDir = join2(targetDir, ".claude", "skills");
341
- if (!existsSync2(skillsDir)) return 0;
342
- let removed = 0;
343
- for (const name of DEPRECATED_SKILL_DIRS) {
344
- const dir = join2(skillsDir, name);
345
- if (existsSync2(dir)) {
346
- rmSync2(dir, { recursive: true, force: true });
347
- removed++;
348
- }
349
- }
350
- for (const name of DEPRECATED_SKILL_FILES) {
351
- const file = join2(skillsDir, name);
352
- if (existsSync2(file)) {
353
- rmSync2(file);
354
- removed++;
355
- }
356
- }
357
- return removed;
358
- }
359
- function migrateLegacyVersionFile(targetDir) {
360
- const claudeStatePath = join2(targetDir, LEGACY_CLAUDE_STATE_PATH);
361
- const rootStatePath = join2(targetDir, LEGACY_VERSION_FILE);
362
- const legacyPath = existsSync2(claudeStatePath) ? claudeStatePath : existsSync2(rootStatePath) ? rootStatePath : null;
363
- if (legacyPath === null) return false;
364
- let parsed;
365
- try {
366
- parsed = JSON.parse(readFileSync(legacyPath, "utf-8"));
367
- } catch {
368
- rmSync2(legacyPath, { force: true });
369
- cleanupEmptyClaudeState(targetDir);
370
- return true;
371
- }
372
- const version = typeof parsed.version === "string" ? parsed.version : getPackageVersion();
373
- const files = parsed.files && typeof parsed.files === "object" ? parsed.files : {};
374
- const profile = parseGitignoreProfile(parsed.gitignoreProfile) ?? void 0;
375
- const harnesses = sanitizeHarnesses(parsed.harnesses) ?? void 0;
376
- writeVersion(targetDir, version, files, profile, harnesses);
377
- rmSync2(legacyPath, { force: true });
378
- cleanupEmptyClaudeState(targetDir);
379
- return true;
380
- }
381
- function cleanupEmptyClaudeState(targetDir) {
382
- const joycraftDir = join2(targetDir, ".claude", ".joycraft");
383
- const claudeDir = join2(targetDir, ".claude");
384
- try {
385
- rmdirSync(joycraftDir);
386
- } catch {
387
- }
388
- try {
389
- rmdirSync(claudeDir);
390
- } catch {
391
- }
392
- }
393
- function countLines(content) {
394
- return content.split("\n").length;
395
- }
396
- function ensureScriptExecutable(absolutePath) {
397
- if (absolutePath.includes(".pi/scripts/joycraft/") && !absolutePath.endsWith("README.md")) {
398
- try {
399
- chmodSync(absolutePath, 493);
400
- } catch {
401
- }
402
- }
403
- }
404
- async function askUser(question) {
405
- const rl = createInterface({ input: process.stdin, output: process.stdout });
406
- return new Promise((resolve2) => {
407
- rl.question(`${question} [y/N] `, (answer) => {
408
- rl.close();
409
- resolve2(answer.trim().toLowerCase() === "y");
410
- });
411
- });
412
- }
413
- function printMigrationSummary(plan, projectDir) {
414
- console.log("");
415
- console.log("Joycraft is migrating your docs/ to the new per-feature layout:");
416
- console.log("");
417
- const relTo = (p) => p.startsWith(projectDir) ? p.slice(projectDir.length + 1) : p;
418
- const featureMoves = plan.moves.filter((m) => m.kind !== "bugfix-dir");
419
- const bugfixMoves = plan.moves.filter((m) => m.kind === "bugfix-dir");
420
- const bySlug = /* @__PURE__ */ new Map();
421
- for (const move of featureMoves) {
422
- const parts = relTo(move.to).split(/[\\/]/);
423
- const slug = parts.length >= 3 ? parts[2] : "(root)";
424
- if (!bySlug.has(slug)) bySlug.set(slug, []);
425
- bySlug.get(slug).push(move);
426
- }
427
- for (const [slug, moves] of bySlug) {
428
- console.log(` ${slug}/`);
429
- for (const move of moves) {
430
- console.log(` ${relTo(move.from)} \u2192 ${relTo(move.to)}`);
431
- }
432
- }
433
- if (bugfixMoves.length > 0) {
434
- console.log("");
435
- console.log(" Migrating bugfix areas:");
436
- for (const move of bugfixMoves) {
437
- console.log(` ${relTo(move.from)} \u2192 ${relTo(move.to)}`);
438
- }
439
- }
440
- console.log("");
441
- }
442
- function printMigrationBanner() {
443
- console.log("");
444
- console.log('Migration complete. See the README section "Migration: Flat \u2192 Per-Feature Layout"');
445
- console.log("for context on what changed and why. If your project is a git repo, run");
446
- console.log("`git status` to inspect the moves before committing.");
447
- console.log("");
448
- }
449
- function runForcedMigration(projectDir) {
450
- const plan = planMigration(projectDir);
451
- if (plan.moves.length === 0 && plan.orphans.specsDirs.length === 0) {
452
- return;
453
- }
454
- printMigrationSummary(plan, projectDir);
455
- const result = applyMigration(plan);
456
- const attempted = result.applied + result.errors.length;
457
- if (attempted > 0 && result.errors.length / attempted > 0.5) {
458
- console.error("Migration failed for more than half of attempted moves. Aborting upgrade.");
459
- for (const e of result.errors) {
460
- console.error(` ${e.move.from} \u2192 ${e.move.to}: ${e.error}`);
461
- }
462
- throw new Error("Migration aborted: too many failures");
463
- }
464
- if (result.errors.length > 0) {
465
- console.log("Some moves had errors but upgrade will continue:");
466
- for (const e of result.errors) {
467
- console.log(` warn: ${e.move.from} \u2192 ${e.move.to}: ${e.error}`);
468
- }
469
- }
470
- printMigrationBanner();
471
- }
472
- async function upgrade(dir, opts) {
473
- const targetDir = resolve(dir);
474
- if (opts.gitignore !== void 0) validateGitignoreFlag(opts.gitignore);
475
- const cliCheck = await checkCliVersion();
476
- if (cliCheck.stale && cliCheck.latest) {
477
- const pkgVersion2 = getPackageVersion();
478
- console.log(`Joycraft CLI is out of date (you have ${pkgVersion2}, latest is ${cliCheck.latest}).`);
479
- const rerun = opts.yes || process.stdin.isTTY === true && await askUser(`Run joycraft@${cliCheck.latest} via npx now?`);
480
- if (rerun && reexecLatestUpgrade(targetDir, opts, cliCheck.latest)) {
481
- return { cliWasStale: true };
482
- }
483
- console.log("Update and re-run in one step with: npx joycraft@latest upgrade");
484
- return { cliWasStale: true };
485
- }
486
- const hasLegacyState = existsSync2(join2(targetDir, LEGACY_VERSION_FILE)) || existsSync2(join2(targetDir, LEGACY_CLAUDE_STATE_PATH));
487
- const hasSkill = existsSync2(join2(targetDir, ".claude", "skills", "joycraft-tune", "SKILL.md")) || existsSync2(join2(targetDir, ".claude", "skills", "tune", "SKILL.md")) || existsSync2(join2(targetDir, ".claude", "skills", "joy", "SKILL.md")) || existsSync2(join2(targetDir, ".claude", "skills", "joysmith", "SKILL.md"));
488
- if (!readVersion(targetDir) && !hasLegacyState && !hasSkill) {
489
- console.log("This project has not been initialized with Joycraft.");
490
- console.log("Run `npx joycraft init` first.");
491
- return { cliWasStale: false };
492
- }
493
- migrateLegacyVersionFile(targetDir);
494
- const deprecatedRemoved = cleanupDeprecatedSkills(targetDir);
495
- if (deprecatedRemoved > 0) {
496
- console.log(`Removed ${deprecatedRemoved} deprecated skill(s) from previous Joycraft versions.`);
497
- }
498
- runForcedMigration(targetDir);
499
- const pkgVersion = getPackageVersion();
500
- const installed = readVersion(targetDir);
501
- const installedHashes = installed?.files ?? {};
502
- const harnesses = installed?.harnesses ?? HARNESSES;
503
- const managedFiles = getManagedFiles(harnesses);
504
- const resolvedProfile = await resolveGitignoreProfile({
505
- flag: opts.gitignore,
506
- persisted: installed?.gitignoreProfile,
507
- interactive: process.stdin.isTTY === true && !opts.yes,
508
- promptIntro: "\nJoycraft can now control how much of the harness is tracked in git."
509
- });
510
- const gitignoreProfile = resolvedProfile.profile;
511
- applyGitignoreProfile(targetDir, gitignoreProfile);
512
- applyGitattributes(targetDir);
513
- const agentsMdPath = join2(targetDir, "AGENTS.md");
514
- if (existsSync2(agentsMdPath)) {
515
- const existingAgents = readFileSync(agentsMdPath, "utf-8");
516
- let updatedAgents = ensureExecutionProfileSection(
517
- existingAgents,
518
- defaultExecutionProfile(harnesses)
519
- );
520
- if (updatedAgents !== existingAgents) {
521
- console.log(" ~ AGENTS.md (added Execution Profile \u2014 run /joycraft-tune to fill it in)");
522
- }
523
- const withMap = ensureFolderMapSection(updatedAgents, targetDir);
524
- if (withMap !== updatedAgents) {
525
- updatedAgents = withMap;
526
- console.log(" ~ AGENTS.md (folder map regenerated from the tree)");
527
- }
528
- if (updatedAgents !== existingAgents) {
529
- writeFileSync(agentsMdPath, updatedAgents, "utf-8");
530
- }
531
- }
532
- const claudeMdPath = join2(targetDir, "CLAUDE.md");
533
- if (existsSync2(claudeMdPath)) {
534
- const existingClaude = readFileSync(claudeMdPath, "utf-8");
535
- if (!existingClaude.includes("@AGENTS.md")) {
536
- const withMap = ensureFolderMapSection(existingClaude, targetDir);
537
- if (withMap !== existingClaude) {
538
- writeFileSync(claudeMdPath, withMap, "utf-8");
539
- console.log(" ~ CLAUDE.md (folder map regenerated from the tree)");
540
- }
541
- }
542
- }
543
- if (gitignoreProfile === "private") {
544
- const switchingToPrivate = installed?.gitignoreProfile !== "private";
545
- const trackedHarnessFiles = switchingToPrivate ? [] : listTrackedHarnessFiles(targetDir);
546
- if (switchingToPrivate || trackedHarnessFiles.length > 0) {
547
- console.log("");
548
- console.log(" \u26A0 Private profile: harness dirs are gitignored, but git only stops");
549
- console.log(" tracking files you untrack. If any harness files were already");
550
- console.log(` committed${trackedHarnessFiles.length > 0 ? ` (${trackedHarnessFiles.length} still tracked)` : ""}, untrack them with:`);
551
- console.log("");
552
- console.log(` ${PRIVATE_UNTRACK_COMMAND}`);
553
- console.log("");
554
- console.log(" (advisory \u2014 Joycraft never runs git for you)");
555
- }
556
- }
557
- const changes = [];
558
- let upToDate = 0;
559
- for (const [relPath, newContent] of Object.entries(managedFiles)) {
560
- const absPath = join2(targetDir, relPath);
561
- const newHash = hashContent(newContent);
562
- if (!existsSync2(absPath)) {
563
- changes.push({ relativePath: relPath, absolutePath: absPath, newContent, kind: "new" });
564
- continue;
565
- }
566
- const currentContent = readFileSync(absPath, "utf-8");
567
- const currentHash = hashContent(currentContent);
568
- if (currentHash === newHash) {
569
- upToDate++;
570
- continue;
571
- }
572
- const originalHash = installedHashes[relPath];
573
- if (originalHash && truncateHash(currentHash) === originalHash) {
574
- changes.push({ relativePath: relPath, absolutePath: absPath, newContent, kind: "updated" });
575
- } else {
576
- changes.push({ relativePath: relPath, absolutePath: absPath, newContent, kind: "customized" });
577
- }
578
- }
579
- if (changes.length === 0) {
580
- if (resolvedProfile.decided && installed && installed.gitignoreProfile !== gitignoreProfile) {
581
- writeVersion(targetDir, installed.version, installedHashes, gitignoreProfile);
582
- }
583
- console.log("Already up to date.");
584
- return { cliWasStale: false };
585
- }
586
- let updated = 0;
587
- let skipped = 0;
588
- let added = 0;
589
- for (const change of changes) {
590
- if (change.kind === "new") {
591
- mkdirSync2(dirname(change.absolutePath), { recursive: true });
592
- writeFileSync(change.absolutePath, change.newContent, "utf-8");
593
- ensureScriptExecutable(change.absolutePath);
594
- added++;
595
- console.log(` + ${change.relativePath}`);
596
- } else if (change.kind === "updated") {
597
- writeFileSync(change.absolutePath, change.newContent, "utf-8");
598
- ensureScriptExecutable(change.absolutePath);
599
- updated++;
600
- } else if (change.kind === "customized") {
601
- const currentContent = readFileSync(change.absolutePath, "utf-8");
602
- const currentLines = countLines(currentContent);
603
- const newLines = countLines(change.newContent);
604
- const diff = newLines - currentLines;
605
- const diffLabel = diff > 0 ? `+${diff} lines` : diff < 0 ? `${diff} lines` : "same length";
606
- const label = `Customized: ${change.relativePath} (local: ${currentLines} lines, latest: ${newLines} lines, ${diffLabel})`;
607
- if (opts.yes) {
608
- writeFileSync(change.absolutePath, change.newContent, "utf-8");
609
- updated++;
610
- } else {
611
- const accept = await askUser(`${label} \u2014 overwrite with latest?`);
612
- if (accept) {
613
- writeFileSync(change.absolutePath, change.newContent, "utf-8");
614
- ensureScriptExecutable(change.absolutePath);
615
- updated++;
616
- } else {
617
- skipped++;
618
- }
619
- }
620
- }
621
- }
622
- const newHashes = {};
623
- for (const [relPath, content] of Object.entries(managedFiles)) {
624
- const absPath = join2(targetDir, relPath);
625
- if (existsSync2(absPath)) {
626
- const current = readFileSync(absPath, "utf-8");
627
- newHashes[relPath] = hashContent(current);
628
- }
629
- }
630
- writeVersion(targetDir, pkgVersion, newHashes, resolvedProfile.decided ? gitignoreProfile : void 0);
631
- const parts = [];
632
- if (updated > 0) parts.push(`Updated ${updated}`);
633
- if (skipped > 0) parts.push(`skipped ${skipped} (customized)`);
634
- if (added > 0) parts.push(`added ${added} new`);
635
- if (upToDate > 0) parts.push(`${upToDate} already up to date`);
636
- console.log(`
637
- Upgrade complete: ${parts.join(", ")}.`);
638
- return { cliWasStale: false };
639
- }
640
- export {
641
- upgrade
642
- };
643
- //# sourceMappingURL=upgrade-AHUSQZEQ.js.map