claude-dev-env 8.48.2 → 8.48.4

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.
@@ -214,7 +214,6 @@ export function preflightSettingsIfNeeded(settingsPath, shouldInstallHooks, io =
214
214
  */
215
215
  export function buildInstallPlan(input) {
216
216
  const io = input.io || {};
217
- const exists = io.existsSync || existsSync;
218
217
  const packageName = input.packageName || 'claude-dev-env';
219
218
 
220
219
  preflightManagedRoot(input.managedRoot, io);
@@ -250,9 +249,6 @@ export function buildInstallPlan(input) {
250
249
  preflightSettingsIfNeeded(settingsPath, shouldInstallHooks, io);
251
250
 
252
251
  const isUpdateRefresh = Boolean(input.isUpdateRefresh);
253
- const shouldPurgeBeforeReinstall = isUpdateRefresh
254
- && !input.selectedGroups
255
- && exists(input.manifestFilePath);
256
252
 
257
253
  return Object.freeze({
258
254
  packageRoot: input.packageRoot,
@@ -261,7 +257,6 @@ export function buildInstallPlan(input) {
261
257
  targetIdentity: input.targetIdentity,
262
258
  selectedGroups: input.selectedGroups,
263
259
  isUpdateRefresh,
264
- shouldPurgeBeforeReinstall,
265
260
  pythonCommand,
266
261
  shouldInstallHooks,
267
262
  priorManifest: Object.freeze({
@@ -277,7 +272,6 @@ export function buildInstallPlan(input) {
277
272
  * High-level mutation kinds the executor applies for this plan (E2 surface).
278
273
  *
279
274
  * @param {{
280
- * shouldPurgeBeforeReinstall: boolean,
281
275
  * shouldInstallHooks: boolean,
282
276
  * selectedGroups: string[]|null,
283
277
  * }} plan
@@ -286,9 +280,6 @@ export function buildInstallPlan(input) {
286
280
  export function describeInstallMutations(plan) {
287
281
  /** @type {string[]} */
288
282
  const allMutations = [];
289
- if (plan.shouldPurgeBeforeReinstall) {
290
- allMutations.push('purge_managed_installation');
291
- }
292
283
  allMutations.push(
293
284
  'ensure_managed_root',
294
285
  'publish_directory_pointers',
package/bin/install.mjs CHANGED
@@ -2597,7 +2597,7 @@ function runFullInstallPrunes(
2597
2597
  * available to a later prune and to uninstall.
2598
2598
  *
2599
2599
  * @param {string[]|null} selectedGroups The `--only` group names, or null for a full install.
2600
- * @param {{isUpdateRefresh?: boolean}} [options] Run options; `isUpdateRefresh` purges before reinstalling.
2600
+ * @param {{isUpdateRefresh?: boolean}} [options] Run options; `isUpdateRefresh` labels the run as an update in the log.
2601
2601
  * @returns {void}
2602
2602
  */
2603
2603
  function install(selectedGroups, options = {}) {
@@ -2674,15 +2674,7 @@ function executeInstallPlanMutations(plan, transactionHelpers) {
2674
2674
  const isUpdateRefresh = plan.isUpdateRefresh;
2675
2675
  const pythonCommand = plan.pythonCommand;
2676
2676
 
2677
- if (plan.shouldPurgeBeforeReinstall) {
2678
- console.log(
2679
- `${PACKAGE_NAME}: --update — removing prior managed files under ${CLAUDE_HOME}, then reinstalling from the package.\n`,
2680
- );
2681
- purgeManagedInstallation({
2682
- isManifestRequired: false,
2683
- throwIfFault,
2684
- });
2685
- } else if (isUpdateRefresh) {
2677
+ if (isUpdateRefresh) {
2686
2678
  const installScope = selectedGroups ? `groups: ${selectedGroups.join(', ')}` : 'full';
2687
2679
  console.log(`${PACKAGE_NAME}: --update — re-running ${installScope} install into ${CLAUDE_HOME}\n`);
2688
2680
  }
@@ -3335,28 +3327,6 @@ function executeUninstallPlan(plan, helpers = {}) {
3335
3327
  return removed;
3336
3328
  }
3337
3329
 
3338
- /**
3339
- * Remove every file the ownership record lists for this managed root.
3340
- *
3341
- * Preflights the uninstall plan (settings JSON must be an object when present)
3342
- * before any removal. When called from `--update` inside an install transaction,
3343
- * pass that transaction's `throwIfFault` so a fault restores the outer snapshot
3344
- * without nesting a second journal.
3345
- *
3346
- * @param {{
3347
- * isManifestRequired: boolean,
3348
- * throwIfFault?: (phase: string) => void,
3349
- * }} options
3350
- * @returns {number|void} 0 when no manifest exists and none is required.
3351
- */
3352
- function purgeManagedInstallation({ isManifestRequired, throwIfFault }) {
3353
- const plan = resolveUninstallPlan(isManifestRequired);
3354
- if (plan.isNoOp) {
3355
- return 0;
3356
- }
3357
- return executeUninstallPlan(plan, { throwIfFault });
3358
- }
3359
-
3360
3330
  /**
3361
3331
  * Uninstall the selected managed root inside a snapshot/restore transaction.
3362
3332
  *
@@ -3435,7 +3405,7 @@ ${PACKAGE_NAME} - Claude Code development standards installer
3435
3405
 
3436
3406
  Usage:
3437
3407
  npx ${PACKAGE_NAME} Install everything into the main default root
3438
- npx ${PACKAGE_NAME} --update Full install: remove prior manifest-tracked files first, then reinstall
3408
+ npx ${PACKAGE_NAME} --update Full install: copy the package over the prior install, then prune files it no longer ships
3439
3409
  npx ${PACKAGE_NAME} --only X Install specific groups
3440
3410
  npx ${PACKAGE_NAME} --target DIR Install into DIR instead of ~/.claude (overrides CLAUDE_CONFIG_DIR)
3441
3411
  npx ${PACKAGE_NAME} --profile ID Install into one named profile root (under the profiles root)
@@ -91,7 +91,6 @@ test('buildInstallPlan is zero-write and freezes a success plan', () => {
91
91
  const plan = buildInstallPlan(planInput(packageRoot, managedRoot));
92
92
  assert.equal(plan.pythonCommand, 'python3');
93
93
  assert.equal(plan.shouldInstallHooks, true);
94
- assert.equal(plan.shouldPurgeBeforeReinstall, false);
95
94
  assert.deepEqual(plan.priorManifest.skills, ['a']);
96
95
  assert.ok(Object.isFrozen(plan));
97
96
  assert.equal(treeStamp(managedRoot) + '//' + treeStamp(packageRoot), before);
@@ -166,7 +165,7 @@ test('settings preflight is hooks-gated; broken manifest stays tolerant', () =>
166
165
  }
167
166
  });
168
167
 
169
- test('update plan marks purge and lists E2 mutation kinds; journal omits hooks', () => {
168
+ test('update plan copies before it prunes and never purges; journal omits hooks', () => {
170
169
  const { root, managedRoot, packageRoot } = sandbox();
171
170
  try {
172
171
  const manifestFilePath = join(managedRoot, '.claude-dev-env-manifest.json');
@@ -177,9 +176,11 @@ test('update plan marks purge and lists E2 mutation kinds; journal omits hooks',
177
176
  targetIdentity: 'profile-a',
178
177
  isUpdateRefresh: true,
179
178
  }));
180
- assert.equal(plan.shouldPurgeBeforeReinstall, true);
181
179
  const allMutations = describeInstallMutations(plan);
182
- assert.ok(allMutations.includes('purge_managed_installation'));
180
+ assert.ok(!allMutations.includes('purge_managed_installation'));
181
+ assert.ok(
182
+ allMutations.indexOf('copy_hook_files') < allMutations.indexOf('prune_retired_and_stale'),
183
+ );
183
184
  assert.ok(allMutations.includes('publish_directory_pointers'));
184
185
  assert.ok(allMutations.includes('merge_hooks_settings'));
185
186
  assert.ok(allMutations.includes('write_manifest'));
@@ -0,0 +1,96 @@
1
+ /**
2
+ * An `--update` reinstall keeps every registered hook script on disk for the
3
+ * whole run, so a live session's hook call never finds its script missing.
4
+ */
5
+
6
+ import { test } from 'node:test';
7
+ import { strict as assert } from 'node:assert';
8
+ import { existsSync, mkdtempSync, rmSync } from 'node:fs';
9
+ import { tmpdir } from 'node:os';
10
+ import { dirname, join } from 'node:path';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { spawn, spawnSync } from 'node:child_process';
13
+ import { INSTALL_FAULT_ENV } from './install-transaction.mjs';
14
+
15
+ const THIS_DIRECTORY = dirname(fileURLToPath(import.meta.url));
16
+ const INSTALLER_PATH = join(THIS_DIRECTORY, 'install.mjs');
17
+ const REGISTERED_HOOK_RELATIVE_PATHS = [
18
+ join('blocking', 'bash_post_call_dispatcher.py'),
19
+ join('blocking', 'verify_before_acting.py'),
20
+ ];
21
+
22
+ function installerEnvironment(homeDirectory) {
23
+ const childEnvironment = {
24
+ ...process.env,
25
+ CDE_INSTALL_PSTACK: '0',
26
+ CDE_INSTALL_USAGE_WRAPUP: '0',
27
+ HOME: homeDirectory,
28
+ USERPROFILE: homeDirectory,
29
+ GIT_CONFIG_GLOBAL: join(homeDirectory, '.gitconfig'),
30
+ CODEX_HOME: join(homeDirectory, '.codex'),
31
+ };
32
+ delete childEnvironment[INSTALL_FAULT_ENV];
33
+ return childEnvironment;
34
+ }
35
+
36
+ function runUpdateWhileWatching(homeDirectory, watchedPaths) {
37
+ return new Promise((resolvePromise, rejectPromise) => {
38
+ const missingCountByPath = new Map();
39
+ let outputText = '';
40
+ let hasExited = false;
41
+ const child = spawn(process.execPath, [INSTALLER_PATH, '--update'], {
42
+ cwd: THIS_DIRECTORY,
43
+ env: installerEnvironment(homeDirectory),
44
+ });
45
+ child.stdout.on('data', (chunk) => { outputText += chunk; });
46
+ child.stderr.on('data', (chunk) => { outputText += chunk; });
47
+ child.on('error', rejectPromise);
48
+ child.on('exit', (exitCode) => {
49
+ hasExited = true;
50
+ resolvePromise({ exitCode, outputText, missingCountByPath });
51
+ });
52
+ const pollOnce = () => {
53
+ if (hasExited) return;
54
+ for (const watchedPath of watchedPaths) {
55
+ if (!existsSync(watchedPath)) {
56
+ missingCountByPath.set(watchedPath, (missingCountByPath.get(watchedPath) ?? 0) + 1);
57
+ }
58
+ }
59
+ setImmediate(pollOnce);
60
+ };
61
+ setImmediate(pollOnce);
62
+ });
63
+ }
64
+
65
+ test('--update never leaves a registered hook script missing mid-install', async () => {
66
+ const homeDirectory = mkdtempSync(join(tmpdir(), 'cdev-update-hooks-'));
67
+ try {
68
+ const firstInstall = spawnSync(process.execPath, [INSTALLER_PATH], {
69
+ cwd: THIS_DIRECTORY,
70
+ encoding: 'utf8',
71
+ env: installerEnvironment(homeDirectory),
72
+ });
73
+ assert.equal(firstInstall.status, 0, firstInstall.stdout + firstInstall.stderr);
74
+ const hooksDirectory = join(homeDirectory, '.agents', 'hooks');
75
+ const watchedPaths = REGISTERED_HOOK_RELATIVE_PATHS.map(
76
+ (relativePath) => join(hooksDirectory, relativePath),
77
+ );
78
+ for (const watchedPath of watchedPaths) {
79
+ assert.equal(existsSync(watchedPath), true, `first install wrote ${watchedPath}`);
80
+ }
81
+
82
+ const updateRun = await runUpdateWhileWatching(homeDirectory, watchedPaths);
83
+
84
+ assert.equal(updateRun.exitCode, 0, updateRun.outputText);
85
+ assert.deepEqual(
86
+ Object.fromEntries(updateRun.missingCountByPath),
87
+ {},
88
+ 'a registered hook script was absent while --update ran',
89
+ );
90
+ for (const watchedPath of watchedPaths) {
91
+ assert.equal(existsSync(watchedPath), true, `--update left ${watchedPath} in place`);
92
+ }
93
+ } finally {
94
+ rmSync(homeDirectory, { recursive: true, force: true });
95
+ }
96
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-dev-env",
3
- "version": "8.48.2",
3
+ "version": "8.48.4",
4
4
  "description": "Claude Code development standards — rules, hooks, agents, commands, and skills",
5
5
  "type": "module",
6
6
  "bin": {
@@ -607,6 +607,7 @@ def read_pull_request(slug: str, number: int, token: str) -> Mapping[str, object
607
607
  def read_blocked_evidence(
608
608
  slug: str,
609
609
  all_pull_request_fields: Mapping[str, object],
610
+ all_rules: list[object] | MergeCheckError,
610
611
  token: str,
611
612
  ) -> BlockedEvidence:
612
613
  """Read what stands behind a ``blocked`` merge state.
@@ -615,6 +616,8 @@ def read_blocked_evidence(
615
616
  slug: The repository as ``owner/name``.
616
617
  all_pull_request_fields: The pull request, carrying its base branch
617
618
  and its head commit.
619
+ all_rules: The base branch rules, or the failure that kept them
620
+ unread.
618
621
  token: The GitHub token the requests authenticate with.
619
622
 
620
623
  Returns:
@@ -628,7 +631,8 @@ def read_blocked_evidence(
628
631
  str(_nested_field(all_pull_request_fields, BASE_KEY, REF_KEY))
629
632
  )
630
633
  head_sha = str(_nested_field(all_pull_request_fields, HEAD_KEY, SHA_KEY))
631
- all_rules = _read_branch_rules(slug, base_ref, token)
634
+ if isinstance(all_rules, MergeCheckError):
635
+ raise all_rules
632
636
  return BlockedEvidence(
633
637
  all_unmet_checks=_read_unmet_checks(slug, head_sha, all_rules, token),
634
638
  behind_by=_read_behind_by(slug, base_ref, head_sha, token),
@@ -636,13 +640,30 @@ def read_blocked_evidence(
636
640
  )
637
641
 
638
642
 
639
- def _read_branch_rules(slug: str, base_ref: str, token: str) -> list[object]:
640
- return _request_list(
641
- BRANCH_RULES_ENDPOINT_TEMPLATE.format(
642
- api_root=GITHUB_API_ROOT, slug=slug, branch=base_ref
643
- ),
644
- token,
645
- )
643
+ def read_branch_rules(
644
+ slug: str, base_ref: str, token: str
645
+ ) -> list[object] | MergeCheckError:
646
+ """Read the rules GitHub reports as active on the base branch.
647
+
648
+ Args:
649
+ slug: The repository as ``owner/name``.
650
+ base_ref: The branch the pull request merges into.
651
+ token: The GitHub token the request authenticates with.
652
+
653
+ Returns:
654
+ The rules, or the failure that kept them unread.
655
+ """
656
+ try:
657
+ return _request_list(
658
+ BRANCH_RULES_ENDPOINT_TEMPLATE.format(
659
+ api_root=GITHUB_API_ROOT,
660
+ slug=slug,
661
+ branch=urllib.parse.quote(base_ref),
662
+ ),
663
+ token,
664
+ )
665
+ except MergeCheckError as failure:
666
+ return failure
646
667
 
647
668
 
648
669
  def read_unstable_checks(
@@ -879,7 +900,11 @@ def _field_at(document: object, all_fields: object, key: str) -> object:
879
900
 
880
901
 
881
902
  def read_merge_queue_ejection(
882
- slug: str, number: int, base_ref: str, token: str
903
+ slug: str,
904
+ number: int,
905
+ base_ref: str,
906
+ all_rules: list[object] | MergeCheckError,
907
+ token: str,
883
908
  ) -> bool:
884
909
  """Read whether the merge queue ejected the pull request's current head.
885
910
 
@@ -891,6 +916,8 @@ def read_merge_queue_ejection(
891
916
  slug: The repository as ``owner/name``.
892
917
  number: The pull request number.
893
918
  base_ref: The branch the pull request merges into.
919
+ all_rules: The base branch rules, or the failure that kept them
920
+ unread.
894
921
  token: The GitHub token the request authenticates with.
895
922
 
896
923
  Returns:
@@ -901,7 +928,9 @@ def read_merge_queue_ejection(
901
928
  MergeCheckError: A read failed, or answered with another shape. A
902
929
  refused GraphQL query names the merge queue that needed it.
903
930
  """
904
- if not _may_merge_through_a_queue(slug, base_ref, token):
931
+ if not isinstance(all_rules, MergeCheckError) and not has_merge_queue_rule(
932
+ all_rules
933
+ ):
905
934
  return False
906
935
  document = _merge_queue_removal_document(slug, number, base_ref, token)
907
936
  return _is_ejected_on_head(
@@ -924,14 +953,6 @@ def _merge_queue_removal_document(
924
953
  ) from failure
925
954
 
926
955
 
927
- def _may_merge_through_a_queue(slug: str, base_ref: str, token: str) -> bool:
928
- try:
929
- all_rules = _read_branch_rules(slug, urllib.parse.quote(base_ref), token)
930
- except MergeCheckError:
931
- return True
932
- return has_merge_queue_rule(all_rules)
933
-
934
-
935
956
  def _list_along(document: object, all_keys: Sequence[str]) -> list[object]:
936
957
  all_records = functools.reduce(
937
958
  functools.partial(_field_at, document), all_keys, document
@@ -1009,11 +1030,10 @@ def main(all_arguments: Sequence[str]) -> int:
1009
1030
  unresolved_thread_count = read_unresolved_thread_count(
1010
1031
  parsed.slug, parsed.number, token
1011
1032
  )
1033
+ base_ref = str(_nested_field(all_pull_request_fields, BASE_KEY, REF_KEY))
1034
+ all_rules = read_branch_rules(parsed.slug, base_ref, token)
1012
1035
  is_ejected_from_merge_queue = read_merge_queue_ejection(
1013
- parsed.slug,
1014
- parsed.number,
1015
- str(_nested_field(all_pull_request_fields, BASE_KEY, REF_KEY)),
1016
- token,
1036
+ parsed.slug, parsed.number, base_ref, all_rules, token
1017
1037
  )
1018
1038
  except MergeCheckError as failure:
1019
1039
  print(failure, file=sys.stderr)
@@ -1022,7 +1042,7 @@ def main(all_arguments: Sequence[str]) -> int:
1022
1042
  if all_pull_request_fields.get(MERGEABLE_STATE_KEY) == MERGEABLE_STATE_BLOCKED:
1023
1043
  try:
1024
1044
  blocked_evidence = read_blocked_evidence(
1025
- parsed.slug, all_pull_request_fields, token
1045
+ parsed.slug, all_pull_request_fields, all_rules, token
1026
1046
  )
1027
1047
  except MergeCheckError as failure:
1028
1048
  print(failure, file=sys.stderr)
@@ -291,10 +291,15 @@ def test_a_ready_pull_request_exits_zero(monkeypatch: pytest.MonkeyPatch) -> Non
291
291
  "read_unresolved_thread_count",
292
292
  lambda slug, number, token: 0,
293
293
  )
294
+ monkeypatch.setattr(
295
+ agent_merge_check,
296
+ "read_branch_rules",
297
+ lambda slug, base_ref, token: [],
298
+ )
294
299
  monkeypatch.setattr(
295
300
  agent_merge_check,
296
301
  "read_merge_queue_ejection",
297
- lambda slug, number, base_ref, token: False,
302
+ lambda slug, number, base_ref, all_rules, token: False,
298
303
  )
299
304
  assert agent_merge_check.main(["jl-cmd/claude-dev-env", "1442"]) == 0
300
305
 
@@ -311,10 +316,15 @@ def test_a_held_pull_request_exits_one(monkeypatch: pytest.MonkeyPatch) -> None:
311
316
  "read_unresolved_thread_count",
312
317
  lambda slug, number, token: 0,
313
318
  )
319
+ monkeypatch.setattr(
320
+ agent_merge_check,
321
+ "read_branch_rules",
322
+ lambda slug, base_ref, token: [],
323
+ )
314
324
  monkeypatch.setattr(
315
325
  agent_merge_check,
316
326
  "read_merge_queue_ejection",
317
- lambda slug, number, base_ref, token: False,
327
+ lambda slug, number, base_ref, all_rules, token: False,
318
328
  )
319
329
  assert agent_merge_check.main(["jl-cmd/claude-dev-env", "1442"]) == 1
320
330
 
@@ -491,6 +501,65 @@ def test_an_unreadable_branch_rule_keeps_the_generic_blocked_reason(
491
501
  assert BLOCKED_HOLD_REASON in line
492
502
 
493
503
 
504
+ def test_a_blocked_pull_request_reads_the_branch_rules_once(
505
+ monkeypatch: pytest.MonkeyPatch,
506
+ capsys: pytest.CaptureFixture[str],
507
+ ) -> None:
508
+ routed_answer = _github_answers(
509
+ MAIN_BRANCH_RULES,
510
+ [
511
+ _check_run("Ruff", "success", run_id=11),
512
+ _check_run("Tip Local green", "success", run_id=12),
513
+ ],
514
+ behind_by=225,
515
+ )
516
+ all_rules_urls: list[str] = []
517
+
518
+ def _answer(url: str, token: str, all_payload_fields: object) -> object:
519
+ if "/rules/branches/" in url:
520
+ all_rules_urls.append(url)
521
+ return routed_answer(url, token, all_payload_fields)
522
+
523
+ exit_code, line = _run_main(monkeypatch, capsys, _answer)
524
+ assert exit_code == 1
525
+ assert BEHIND_MERGE_QUEUE_HOLD_TEMPLATE.format(count=225) in line
526
+ assert len(all_rules_urls) == 1
527
+
528
+
529
+ def test_read_branch_rules_quotes_the_base_branch_and_returns_its_rules(
530
+ monkeypatch: pytest.MonkeyPatch,
531
+ ) -> None:
532
+ all_rules_urls: list[str] = []
533
+
534
+ def _answer(url: str, token: str, all_payload_fields: object) -> object:
535
+ all_rules_urls.append(url)
536
+ return MAIN_BRANCH_RULES
537
+
538
+ monkeypatch.setattr(agent_merge_check, "_request_json", _answer)
539
+ assert (
540
+ agent_merge_check.read_branch_rules(
541
+ "jl-cmd/claude-dev-env", "release/2026 q4", "token"
542
+ )
543
+ == MAIN_BRANCH_RULES
544
+ )
545
+ assert all_rules_urls[0].endswith("/rules/branches/release/2026%20q4")
546
+
547
+
548
+ def test_read_branch_rules_returns_the_failure_of_a_refused_read(
549
+ monkeypatch: pytest.MonkeyPatch,
550
+ ) -> None:
551
+ refusal = agent_merge_check.MergeCheckError("HTTP Error 403: Forbidden")
552
+
553
+ def _refuse(url: str, token: str, all_payload_fields: object) -> object:
554
+ raise refusal
555
+
556
+ monkeypatch.setattr(agent_merge_check, "_request_json", _refuse)
557
+ assert (
558
+ agent_merge_check.read_branch_rules("jl-cmd/claude-dev-env", "main", "token")
559
+ is refusal
560
+ )
561
+
562
+
494
563
  def _evidence(
495
564
  all_unmet_checks: tuple[str, ...] = (),
496
565
  behind_by: int = 0,
@@ -626,7 +695,7 @@ def test_read_blocked_evidence_reads_the_pull_request_4922_shape(
626
695
  ),
627
696
  )
628
697
  assert agent_merge_check.read_blocked_evidence(
629
- "jl-cmd/claude-dev-env", PULL_REQUEST_4922, "token"
698
+ "jl-cmd/claude-dev-env", PULL_REQUEST_4922, MAIN_BRANCH_RULES, "token"
630
699
  ) == _evidence(behind_by=225)
631
700
 
632
701
 
@@ -821,7 +890,7 @@ def test_read_merge_queue_ejection_compares_failed_checks_removals_to_the_head(
821
890
  )
822
891
  assert (
823
892
  agent_merge_check.read_merge_queue_ejection(
824
- "jl-cmd/claude-dev-env", 1442, "main", "token"
893
+ "jl-cmd/claude-dev-env", 1442, "main", MAIN_BRANCH_RULES, "token"
825
894
  )
826
895
  is expected_ejection
827
896
  )