claude-dev-env 7.5.0 → 7.6.1

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 (125) hide show
  1. package/.agents/skills/everything-search/scripts/everything_search.py +11 -0
  2. package/.agents/skills/everything-search/scripts/test_everything_search.py +1 -0
  3. package/.agents/skills/fresh-branch/SKILL.md +1 -0
  4. package/.agents/skills/fresh-branch/scripts/fresh_branch_git_commands.py +3 -0
  5. package/.agents/skills/fresh-branch/scripts/subprocess_window_access.py +43 -0
  6. package/.agents/skills/session-continuity/README.md +19 -9
  7. package/.agents/skills/syncing-submodules/SKILL.md +1 -0
  8. package/.agents/skills/syncing-submodules/scripts/submodule_sync.py +4 -0
  9. package/.agents/skills/syncing-submodules/scripts/subprocess_window_access.py +43 -0
  10. package/.agents/skills/test-runner/SKILL.md +1 -0
  11. package/.agents/skills/test-runner/scripts/preflight_checks.py +5 -0
  12. package/.agents/skills/test-runner/scripts/run_tests.py +11 -0
  13. package/.agents/skills/test-runner/scripts/subprocess_window_access.py +43 -0
  14. package/.agents/skills/test-runner/scripts/test_run_tests.py +9 -7
  15. package/_shared/pr-loop/scripts/check_bugbot_ci.py +3 -0
  16. package/_shared/pr-loop/scripts/check_convergence_gates.py +3 -0
  17. package/_shared/pr-loop/scripts/check_pending_reviews.py +3 -0
  18. package/_shared/pr-loop/scripts/code_rules_gate_parts/added_line_maps.py +3 -0
  19. package/_shared/pr-loop/scripts/code_rules_gate_parts/baseline_import_isolation.py +3 -0
  20. package/_shared/pr-loop/scripts/code_rules_gate_parts/git_blob_readers.py +5 -0
  21. package/_shared/pr-loop/scripts/code_rules_gate_parts/git_file_sets.py +4 -0
  22. package/_shared/pr-loop/scripts/code_rules_gate_parts/staged_test_regression.py +3 -0
  23. package/_shared/pr-loop/scripts/code_rules_gate_parts/staged_test_running.py +3 -0
  24. package/_shared/pr-loop/scripts/codex_usage_probe.py +3 -0
  25. package/_shared/pr-loop/scripts/copilot_quota.py +3 -0
  26. package/_shared/pr-loop/scripts/fetch_copilot_reviews.py +3 -0
  27. package/_shared/pr-loop/scripts/fix_hookspath.py +7 -0
  28. package/_shared/pr-loop/scripts/post_fix_reply.py +4 -0
  29. package/_shared/pr-loop/scripts/preflight.py +7 -0
  30. package/_shared/pr-loop/scripts/preflight_self_heal.py +5 -0
  31. package/_shared/pr-loop/scripts/run_codex_review.py +3 -0
  32. package/_shared/pr-loop/scripts/subprocess_window_access.py +41 -0
  33. package/_shared/pr-loop/scripts/terminology_sweep.py +5 -0
  34. package/_shared/process-tree/scripts/process_tree_kill.py +3 -0
  35. package/_shared/process-tree/scripts/subprocess_window_access.py +41 -0
  36. package/bin/install-constants.mjs +4 -2
  37. package/bin/install-session-continuity.mjs +73 -30
  38. package/bin/install-session-continuity.test.mjs +52 -1
  39. package/bin/install.cursor-rules.test.mjs +57 -15
  40. package/bin/install.mjs +80 -15
  41. package/bin/install.test.mjs +57 -0
  42. package/bin/pstack-model-preferences.claude.json +23 -0
  43. package/hooks/advisory/pr_done_reminder.py +7 -0
  44. package/hooks/advisory/refactor_guard.py +8 -0
  45. package/hooks/advisory/test_pr_done_reminder.py +21 -0
  46. package/hooks/advisory/test_refactor_guard.py +40 -0
  47. package/hooks/blocking/block_main_commit.py +4 -0
  48. package/hooks/blocking/code_rules_comments.py +39 -5
  49. package/hooks/blocking/pii_prevention_blocker_parts/repository_exemption.py +3 -0
  50. package/hooks/blocking/precommit_code_rules_gate.py +3 -0
  51. package/hooks/blocking/tdd_enforcer_parts/content_analysis.py +19 -3
  52. package/hooks/blocking/tdd_enforcer_parts/git_tracking.py +4 -0
  53. package/hooks/blocking/tdd_enforcer_parts/tests/test_content_analysis.py +25 -0
  54. package/hooks/blocking/test_code_rules_enforcer_comment_string_awareness.py +27 -0
  55. package/hooks/blocking/test_code_rules_enforcer_exempt_marker_chained.py +10 -0
  56. package/hooks/git-hooks/git_hooks_constants/verification_notice_constants.py +0 -2
  57. package/hooks/git-hooks/pull_request_handoff.py +3 -0
  58. package/hooks/git-hooks/subprocess_window_access.py +41 -0
  59. package/hooks/git-hooks/test_verification_start.py +4 -0
  60. package/hooks/git-hooks/verification_notice_context.py +3 -0
  61. package/hooks/git-hooks/verification_start.py +7 -8
  62. package/hooks/hooks_constants/code_rules_enforcer_constants.py +2 -0
  63. package/hooks/hooks_constants/subprocess_window.py +141 -0
  64. package/hooks/hooks_constants/subprocess_window_constants.py +9 -0
  65. package/hooks/hooks_constants/test_code_rules_enforcer_constants.py +6 -0
  66. package/hooks/hooks_constants/test_subprocess_window.py +128 -0
  67. package/hooks/lifecycle/enter_worktree_origin_prefetch.py +3 -0
  68. package/hooks/validation/mypy_validator.py +4 -0
  69. package/hooks/validators/README.md +1 -0
  70. package/hooks/validators/git_checks.py +4 -0
  71. package/hooks/validators/health_check.py +3 -0
  72. package/hooks/validators/hook_timing_harness.py +3 -0
  73. package/hooks/validators/mypy_integration.py +4 -0
  74. package/hooks/validators/ruff_integration.py +6 -0
  75. package/hooks/validators/run_all_validators.py +7 -0
  76. package/hooks/validators/subprocess_window_access.py +41 -0
  77. package/hooks/workflow/auto_formatter.py +8 -0
  78. package/hooks/workflow/test_auto_formatter.py +39 -0
  79. package/package.json +1 -1
  80. package/rules/pstack-models.md +4 -3
  81. package/scripts/automatic_advisory/checkout.py +8 -1
  82. package/scripts/automatic_advisory/cli.py +9 -3
  83. package/scripts/automatic_advisory/config/constants.py +0 -2
  84. package/scripts/automatic_advisory/execution.py +7 -1
  85. package/scripts/automatic_advisory/git.py +9 -1
  86. package/scripts/automatic_advisory/process_host.py +3 -0
  87. package/scripts/claude_chain_runner.py +3 -0
  88. package/scripts/gh_artifact_upload.py +3 -0
  89. package/scripts/grok_headless_runner.py +3 -0
  90. package/scripts/grok_patch_artifacts.py +4 -0
  91. package/scripts/grok_worker_preflight.py +3 -0
  92. package/scripts/invoke_code_review.py +3 -0
  93. package/scripts/local_verification/command_runner.py +3 -0
  94. package/scripts/local_verification/git_state.py +3 -0
  95. package/scripts/policy_lint/adapter_detectors.py +48 -2
  96. package/scripts/policy_lint/adapter_pairing.py +150 -2
  97. package/scripts/policy_lint/adapters.py +46 -4
  98. package/scripts/policy_lint/config/approved_test_pairs.py +25 -9
  99. package/scripts/policy_lint/config/constants.py +3 -0
  100. package/scripts/policy_lint/registry.py +1 -1
  101. package/scripts/policy_lint/selection_git.py +11 -0
  102. package/scripts/repository_checks/config/constants.py +5 -0
  103. package/scripts/repository_checks/config/policy_document.py +19 -0
  104. package/scripts/repository_checks/email_exemptions.py +14 -71
  105. package/scripts/repository_checks/path_exemptions.py +35 -0
  106. package/scripts/repository_checks/policy_document.py +120 -0
  107. package/scripts/repository_checks/tracked_secrets.py +27 -4
  108. package/scripts/setup_project_paths.py +3 -0
  109. package/scripts/spawn_grok_batch.py +3 -0
  110. package/scripts/subprocess_window_access.py +41 -0
  111. package/scripts/test_dispatcher_profile_import.py +4 -0
  112. package/scripts/tests/test_automatic_advisory_window_flags.py +17 -11
  113. package/scripts/tests/test_email_exemptions.py +37 -0
  114. package/scripts/tests/test_path_exemptions.py +164 -0
  115. package/scripts/tests/test_policy_document.py +104 -0
  116. package/scripts/tests/test_policy_lint_rules_function_length_scope.py +101 -0
  117. package/scripts/tests/test_policy_lint_rules_pairing.py +375 -0
  118. package/scripts/tests/test_policy_lint_rules_registry.py +116 -0
  119. package/scripts/tests/test_policy_lint_selection.py +34 -0
  120. package/scripts/tests/test_subprocess_window_access.py +118 -0
  121. package/scripts/tests/test_tracked_secrets.py +79 -0
  122. package/scripts/validate_instruction_pairs.py +3 -0
  123. package/scripts/verify_installable_package.py +5 -0
  124. package/scripts/automatic_advisory/window_flags.py +0 -41
  125. package/scripts/repository_checks/config/email_exemptions.py +0 -10
@@ -30,6 +30,8 @@ from pr_converge_skill_constants.constants import (
30
30
  GH_ISSUE_COMMENT_CREATE_PATH_TEMPLATE,
31
31
  )
32
32
 
33
+ from subprocess_window_access import hidden_window_creation_flags
34
+
33
35
 
34
36
  def post_inline_reply(
35
37
  *,
@@ -67,6 +69,7 @@ def post_inline_reply(
67
69
  encoding="utf-8",
68
70
  errors="replace",
69
71
  check=False,
72
+ creationflags=hidden_window_creation_flags(),
70
73
  )
71
74
  if completed_process.returncode != 0:
72
75
  print(f"gh api error: {completed_process.stderr}", file=sys.stderr)
@@ -108,6 +111,7 @@ def post_pr_comment(
108
111
  encoding="utf-8",
109
112
  errors="replace",
110
113
  check=False,
114
+ creationflags=hidden_window_creation_flags(),
111
115
  )
112
116
  if completed_process.returncode != 0:
113
117
  print(f"gh api error: {completed_process.stderr}", file=sys.stderr)
@@ -48,6 +48,8 @@ from reviews_disabled import (
48
48
  is_bugteam_disabled_via_env,
49
49
  )
50
50
 
51
+ from subprocess_window_access import hidden_window_creation_flags, inherited_stream_startup_info
52
+
51
53
 
52
54
  def verify_git_hooks_path(repository_root: Path | None = None) -> int:
53
55
  """Check that core.hooksPath resolves to the claude-dev-env git-hooks directory.
@@ -95,6 +97,7 @@ def verify_git_hooks_path(repository_root: Path | None = None) -> int:
95
97
  encoding="utf-8",
96
98
  errors="replace",
97
99
  check=False,
100
+ creationflags=hidden_window_creation_flags(),
98
101
  )
99
102
  except FileNotFoundError:
100
103
  print(
@@ -201,6 +204,7 @@ def has_discoverable_tests(root: Path) -> bool | None:
201
204
  encoding="utf-8",
202
205
  errors="replace",
203
206
  check=True,
207
+ creationflags=hidden_window_creation_flags(),
204
208
  )
205
209
  except FileNotFoundError:
206
210
  print(
@@ -260,6 +264,7 @@ def run_pytest(
260
264
  command,
261
265
  cwd=str(repository_root),
262
266
  check=False,
267
+ startupinfo=inherited_stream_startup_info(),
263
268
  )
264
269
  if completed.returncode == _pytest_exit_code_no_tests_collected():
265
270
  return 0
@@ -302,6 +307,7 @@ def get_changed_files(repository_root: Path, base_ref: str) -> list[Path] | None
302
307
  encoding="utf-8",
303
308
  errors="replace",
304
309
  check=False,
310
+ creationflags=hidden_window_creation_flags(),
305
311
  )
306
312
  except FileNotFoundError:
307
313
  print(
@@ -398,6 +404,7 @@ def run_pre_commit(repository_root: Path) -> int:
398
404
  list(ALL_PRE_COMMIT_RUN_ALL_FILES_COMMAND),
399
405
  cwd=str(repository_root),
400
406
  check=False,
407
+ startupinfo=inherited_stream_startup_info(),
401
408
  )
402
409
  return completed.returncode
403
410
 
@@ -24,6 +24,8 @@ from pr_loop_shared_constants.preflight_self_heal_constants import ( # noqa: E4
24
24
  ALL_GIT_CONFIG_LOCAL_UNSET_ALL_HOOKS_PATH_ARGUMENTS,
25
25
  )
26
26
 
27
+ from subprocess_window_access import hidden_window_creation_flags
28
+
27
29
 
28
30
  def _is_canonical_hooks_path_entry(
29
31
  raw_hooks_path_entry: str,
@@ -71,6 +73,7 @@ def _canonical_global_hooks_path_is_set(expected_hooks_path_suffix: str) -> bool
71
73
  encoding="utf-8",
72
74
  errors="replace",
73
75
  check=False,
76
+ creationflags=hidden_window_creation_flags(),
74
77
  )
75
78
  except (FileNotFoundError, OSError):
76
79
  return False
@@ -127,6 +130,7 @@ def silently_clear_stale_local_hooks_path_override(
127
130
  encoding="utf-8",
128
131
  errors="replace",
129
132
  check=False,
133
+ creationflags=hidden_window_creation_flags(),
130
134
  )
131
135
  except (FileNotFoundError, OSError):
132
136
  return
@@ -159,6 +163,7 @@ def silently_clear_stale_local_hooks_path_override(
159
163
  encoding="utf-8",
160
164
  errors="replace",
161
165
  check=False,
166
+ creationflags=hidden_window_creation_flags(),
162
167
  )
163
168
  except (FileNotFoundError, OSError):
164
169
  return
@@ -90,6 +90,8 @@ from codex_review_scripts_constants.run_constants import ( # noqa: E402
90
90
  VERSION_PROBE_PATTERN,
91
91
  )
92
92
 
93
+ from subprocess_window_access import hidden_window_creation_flags
94
+
93
95
 
94
96
  def _open_codex_popen(
95
97
  all_arguments: list[str],
@@ -110,6 +112,7 @@ def _open_codex_popen(
110
112
  encoding=stream_encoding if isinstance(stream_encoding, str) else None,
111
113
  env=process_environment if isinstance(process_environment, dict) else None,
112
114
  start_new_session=should_start_new_session(),
115
+ creationflags=hidden_window_creation_flags(),
113
116
  )
114
117
 
115
118
 
@@ -0,0 +1,41 @@
1
+ """Reach the hidden-window helpers from the scripts this directory deploys.
2
+
3
+ The installer copies this directory into a profile that holds no installed
4
+ Python distribution, and this repository's own tests run the deployed scripts
5
+ under ``python -S -E``, which hides every installed package from the child
6
+ process. On both routes ``hooks_constants`` is reachable only through the
7
+ deployed ``hooks`` directory, so this module puts that directory on
8
+ ``sys.path`` and re-exports the helpers a caller asks for::
9
+
10
+ from subprocess_window_access import hidden_window_creation_flags
11
+
12
+ The directory goes on the end of ``sys.path``. ``PathFinder`` runs ahead of
13
+ every editable-install finder, so a trailing entry still selects the deployed
14
+ copy, and the head of ``sys.path`` stays exactly as the caller left it. A
15
+ caller that prepended its own roots keeps them first.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import sys
21
+ from pathlib import Path
22
+
23
+ _subprocess_window_hooks_directory = str(
24
+ Path(__file__).resolve().parents[3] / "hooks"
25
+ )
26
+ if _subprocess_window_hooks_directory not in sys.path:
27
+ sys.path.append(_subprocess_window_hooks_directory)
28
+
29
+ from hooks_constants.subprocess_window import (
30
+ HiddenWindowStartupInfo,
31
+ detached_hidden_window_creation_flags,
32
+ hidden_window_creation_flags,
33
+ inherited_stream_startup_info,
34
+ )
35
+
36
+ __all__ = [
37
+ "HiddenWindowStartupInfo",
38
+ "detached_hidden_window_creation_flags",
39
+ "hidden_window_creation_flags",
40
+ "inherited_stream_startup_info",
41
+ ]
@@ -75,6 +75,8 @@ from pr_loop_shared_constants.terminology_sweep_constants import (
75
75
  TEST_FILE_SUFFIX,
76
76
  )
77
77
 
78
+ from subprocess_window_access import hidden_window_creation_flags
79
+
78
80
  IdentifierTuple = tuple[str, ...]
79
81
 
80
82
 
@@ -656,6 +658,7 @@ def _base_tree_names(
656
658
  timeout=GIT_DIFF_SUBPROCESS_TIMEOUT_SECONDS,
657
659
  check=False,
658
660
  env=repository_environment(),
661
+ creationflags=hidden_window_creation_flags(),
659
662
  )
660
663
  except (subprocess.TimeoutExpired, FileNotFoundError, OSError):
661
664
  continue
@@ -678,6 +681,7 @@ def _run_strict_git(
678
681
  timeout=GIT_DIFF_SUBPROCESS_TIMEOUT_SECONDS,
679
682
  check=False,
680
683
  env=repository_environment(),
684
+ creationflags=hidden_window_creation_flags(),
681
685
  )
682
686
  except (subprocess.TimeoutExpired, OSError) as e:
683
687
  raise RuntimeError(str(e)) from e
@@ -807,6 +811,7 @@ def staged_terminology_findings(repository_root: Path) -> list[str]:
807
811
  timeout=GIT_DIFF_SUBPROCESS_TIMEOUT_SECONDS,
808
812
  check=False,
809
813
  env=repository_environment(),
814
+ creationflags=hidden_window_creation_flags(),
810
815
  )
811
816
  if diff_process.returncode != 0:
812
817
  return []
@@ -39,6 +39,8 @@ from process_tree_scripts_constants.process_tree_kill_constants import ( # noqa
39
39
  WINDOWS_TASKKILL_TREE_FLAG,
40
40
  )
41
41
 
42
+ from subprocess_window_access import hidden_window_creation_flags
43
+
42
44
  process_tree_subprocess_run = subprocess.run
43
45
 
44
46
 
@@ -73,6 +75,7 @@ def _kill_windows_process_tree(process_identifier: int) -> None:
73
75
  stderr=subprocess.DEVNULL,
74
76
  check=False,
75
77
  timeout=PROCESS_TREE_KILL_TIMEOUT_SECONDS,
78
+ creationflags=hidden_window_creation_flags(),
76
79
  )
77
80
  except (subprocess.TimeoutExpired, OSError):
78
81
  return
@@ -0,0 +1,41 @@
1
+ """Reach the hidden-window helpers from the scripts this directory deploys.
2
+
3
+ The installer copies this directory into a profile that holds no installed
4
+ Python distribution, and this repository's own tests run the deployed scripts
5
+ under ``python -S -E``, which hides every installed package from the child
6
+ process. On both routes ``hooks_constants`` is reachable only through the
7
+ deployed ``hooks`` directory, so this module puts that directory on
8
+ ``sys.path`` and re-exports the helpers a caller asks for::
9
+
10
+ from subprocess_window_access import hidden_window_creation_flags
11
+
12
+ The directory goes on the end of ``sys.path``. ``PathFinder`` runs ahead of
13
+ every editable-install finder, so a trailing entry still selects the deployed
14
+ copy, and the head of ``sys.path`` stays exactly as the caller left it. A
15
+ caller that prepended its own roots keeps them first.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ import sys
21
+ from pathlib import Path
22
+
23
+ _subprocess_window_hooks_directory = str(
24
+ Path(__file__).resolve().parents[3] / "hooks"
25
+ )
26
+ if _subprocess_window_hooks_directory not in sys.path:
27
+ sys.path.append(_subprocess_window_hooks_directory)
28
+
29
+ from hooks_constants.subprocess_window import (
30
+ HiddenWindowStartupInfo,
31
+ detached_hidden_window_creation_flags,
32
+ hidden_window_creation_flags,
33
+ inherited_stream_startup_info,
34
+ )
35
+
36
+ __all__ = [
37
+ "HiddenWindowStartupInfo",
38
+ "detached_hidden_window_creation_flags",
39
+ "hidden_window_creation_flags",
40
+ "inherited_stream_startup_info",
41
+ ]
@@ -56,8 +56,10 @@ export const RUN_BACKUP_DIRECTORY_NAME_PATTERN =
56
56
  export const PACKAGE_AGENTS_HOME_DIRECTORY_NAME = '.agents';
57
57
 
58
58
  export const PSTACK_MODEL_RULE_FILE_NAME = 'pstack-models.mdc';
59
- export const PSTACK_CODEX_MODEL_PREFERENCES_FILE_NAME =
60
- 'pstack-model-preferences.codex.json';
59
+ export const PSTACK_SEEDED_MODEL_PREFERENCES_FILE_NAMES = Object.freeze([
60
+ 'pstack-model-preferences.claude.json',
61
+ 'pstack-model-preferences.codex.json',
62
+ ]);
61
63
 
62
64
  /**
63
65
  * The directory name skill directories carry in a package source and under
@@ -44,41 +44,84 @@ export function mergeContinuityHooks(existing, host, script) {
44
44
  return mergedConfiguration;
45
45
  }
46
46
 
47
- async function main() {
48
- const requested = process.argv.slice(2);
49
- const selected = requested.length ? requested : supportedHosts;
47
+ export const CONTINUITY_SCRIPT_MARKER = '/session-continuity/continuity.mjs';
48
+
49
+ export function isContinuityHookCommand(command) {
50
+ return typeof command === 'string' && command.includes(CONTINUITY_SCRIPT_MARKER);
51
+ }
52
+
53
+ export function continuityScriptPath(roots) {
54
+ return join(roots.skillsInstallDirectory, 'session-continuity', 'continuity.mjs');
55
+ }
56
+
57
+ export function continuityHostConfigurationPaths(roots) {
58
+ return {
59
+ claude: join(roots.managedRoot, 'settings.json'),
60
+ codex: join(dirname(roots.codexRulesInstallDirectory), 'hooks.json'),
61
+ cursor: join(roots.cursorInstallDirectory, 'hooks.json'),
62
+ };
63
+ }
64
+
65
+ export function removeContinuityHooks(configuration) {
66
+ let removedCount = 0;
67
+ for (const [event, entries] of Object.entries(configuration.hooks || {})) {
68
+ const kept = entries.flatMap(entry => {
69
+ if (!entry.hooks) {
70
+ if (!isContinuityHookCommand(entry.command)) return [entry];
71
+ removedCount += 1;
72
+ return [];
73
+ }
74
+ const hooks = entry.hooks.filter(hook => !isContinuityHookCommand(hook.command));
75
+ removedCount += entry.hooks.length - hooks.length;
76
+ return hooks.length ? [{ ...entry, hooks }] : [];
77
+ });
78
+ if (kept.length) configuration.hooks[event] = kept;
79
+ else delete configuration.hooks[event];
80
+ }
81
+ return removedCount;
82
+ }
83
+
84
+ function continuityConfigurationPlan(host, path, script) {
85
+ if (!existsSync(dirname(path))) throw new Error(`Host config directory is absent: ${dirname(path)}`);
86
+ const existing = existsSync(path) ? readFileSync(path, 'utf8') : null;
87
+ const merged = mergeContinuityHooks(existing ? JSON.parse(existing) : {}, host, script);
88
+ return { host, path, existing, content: JSON.stringify(merged, null, 2) + '\n' };
89
+ }
90
+
91
+ function applyContinuityConfigurationPlan(plan) {
92
+ if (plan.existing === plan.content) return { host: plan.host, path: plan.path, changed: false };
93
+ if (plan.existing !== null) {
94
+ const backup = `${plan.path}.before-session-continuity`;
95
+ if (!existsSync(backup)) writeFileSync(backup, plan.existing, { flag: 'wx', mode: 0o600 });
96
+ }
97
+ const current = existsSync(plan.path) ? readFileSync(plan.path, 'utf8') : null;
98
+ if (current !== plan.existing) throw new Error(`Config changed during setup: ${plan.path}. Rerun setup.`);
99
+ const temporary = `${plan.path}.continuity-${process.pid}.tmp`;
100
+ writeFileSync(temporary, plan.content, { flag: 'wx', mode: 0o600 });
101
+ renameSync(temporary, plan.path);
102
+ if (readFileSync(plan.path, 'utf8') !== plan.content) throw new Error(`Config read-back mismatch: ${plan.path}`);
103
+ return { host: plan.host, path: plan.path, changed: true };
104
+ }
105
+
106
+ export function configureContinuityHosts(roots, selected) {
50
107
  const unsupported = selected.find(host => !supportedHosts.includes(host));
51
108
  if (unsupported) throw new Error(`Unsupported host ${unsupported}`);
52
- const { resolveInstallRoot } = await import('./resolve-install-root.mjs');
53
- const roots = resolveInstallRoot();
54
- const script = join(roots.skillsInstallDirectory, 'session-continuity', 'continuity.mjs');
109
+ const script = continuityScriptPath(roots);
55
110
  if (!existsSync(script) || !existsSync(join(dirname(script), 'SKILL.md'))) {
56
111
  throw new Error('Run the full claude-dev-env installer from this checkout first so the companion is in the canonical agents home.');
57
112
  }
58
- const paths = {
59
- claude: join(roots.managedRoot, 'settings.json'),
60
- codex: join(dirname(roots.codexRulesInstallDirectory), 'hooks.json'),
61
- cursor: join(roots.cursorInstallDirectory, 'hooks.json'),
62
- };
63
- const plans = selected.map(host => {
64
- const path = paths[host];
65
- if (!existsSync(dirname(path))) throw new Error(`Host config directory is absent: ${dirname(path)}`);
66
- const existing = existsSync(path) ? readFileSync(path, 'utf8') : null;
67
- return { path, existing, content: JSON.stringify(mergeContinuityHooks(existing ? JSON.parse(existing) : {}, host, script), null, 2) + '\n' };
68
- });
69
- for (const plan of plans) {
70
- if (plan.existing === plan.content) { console.log(`Already configured: ${plan.path}`); continue; }
71
- if (plan.existing !== null) {
72
- const backup = `${plan.path}.before-session-continuity`;
73
- if (!existsSync(backup)) writeFileSync(backup, plan.existing, { flag: 'wx', mode: 0o600 });
74
- }
75
- const current = existsSync(plan.path) ? readFileSync(plan.path, 'utf8') : null;
76
- if (current !== plan.existing) throw new Error(`Config changed during setup: ${plan.path}. Rerun setup.`);
77
- const temporary = `${plan.path}.continuity-${process.pid}.tmp`;
78
- writeFileSync(temporary, plan.content, { flag: 'wx', mode: 0o600 });
79
- renameSync(temporary, plan.path);
80
- if (readFileSync(plan.path, 'utf8') !== plan.content) throw new Error(`Config read-back mismatch: ${plan.path}`);
81
- console.log(`Configured and read back: ${plan.path}`);
113
+ const paths = continuityHostConfigurationPaths(roots);
114
+ return selected
115
+ .map(host => continuityConfigurationPlan(host, paths[host], script))
116
+ .map(applyContinuityConfigurationPlan);
117
+ }
118
+
119
+ async function main() {
120
+ const requested = process.argv.slice(2);
121
+ const selected = requested.length ? requested : supportedHosts;
122
+ const { resolveInstallRoot } = await import('./resolve-install-root.mjs');
123
+ for (const result of configureContinuityHosts(resolveInstallRoot(), selected)) {
124
+ console.log(`${result.changed ? 'Configured and read back' : 'Already configured'}: ${result.path}`);
82
125
  }
83
126
  console.log('Review and trust the new hooks in each host.');
84
127
  }
@@ -1,6 +1,30 @@
1
1
  import assert from 'node:assert/strict';
2
2
  import test from 'node:test';
3
- import { continuityHookConfiguration, mergeContinuityHooks } from './install-session-continuity.mjs';
3
+ import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
5
+ import { join } from 'node:path';
6
+ import {
7
+ configureContinuityHosts,
8
+ continuityHookConfiguration,
9
+ mergeContinuityHooks,
10
+ removeContinuityHooks,
11
+ } from './install-session-continuity.mjs';
12
+
13
+ function installRootFixture() {
14
+ const root = mkdtempSync(join(tmpdir(), 'continuity-roots-'));
15
+ const skillsInstallDirectory = join(root, 'agents', 'skills');
16
+ const companionDirectory = join(skillsInstallDirectory, 'session-continuity');
17
+ mkdirSync(companionDirectory, { recursive: true });
18
+ writeFileSync(join(companionDirectory, 'continuity.mjs'), 'export default null;\n');
19
+ writeFileSync(join(companionDirectory, 'SKILL.md'), '# companion\n');
20
+ const managedRoot = join(root, 'claude');
21
+ const codexRulesInstallDirectory = join(root, 'codex', 'rules');
22
+ const cursorInstallDirectory = join(root, 'cursor');
23
+ for (const directory of [managedRoot, codexRulesInstallDirectory, cursorInstallDirectory]) {
24
+ mkdirSync(directory, { recursive: true });
25
+ }
26
+ return { managedRoot, skillsInstallDirectory, codexRulesInstallDirectory, cursorInstallDirectory };
27
+ }
4
28
 
5
29
  test('setup preserves other hooks and settings, is idempotent, and rejects competing profiles', () => {
6
30
  const existing = { permissions: { deny: ['secret'] }, hooks: { SessionStart: [{ hooks: [{ type: 'command', command: 'existing-hook' }] }] } };
@@ -53,3 +77,30 @@ for (const host of ['claude', 'codex']) {
53
77
  }
54
78
  });
55
79
  }
80
+
81
+ test('configureContinuityHosts writes each host config, reads it back, and repeats without a change', () => {
82
+ const roots = installRootFixture();
83
+ const settingsPath = join(roots.managedRoot, 'settings.json');
84
+ writeFileSync(settingsPath, JSON.stringify({ permissions: { deny: ['secret'] } }, null, 2) + '\n');
85
+ const first = configureContinuityHosts(roots, ['claude', 'codex', 'cursor']);
86
+ assert.deepEqual(first.map(result => result.changed), [true, true, true]);
87
+ const written = JSON.parse(readFileSync(settingsPath, 'utf8'));
88
+ assert.deepEqual(written.permissions.deny, ['secret']);
89
+ const command = written.hooks.SessionStart[0].hooks[0].command;
90
+ assert.equal(command.endsWith('session-continuity/continuity.mjs" hook claude'), true);
91
+ const second = configureContinuityHosts(roots, ['claude', 'codex', 'cursor']);
92
+ assert.deepEqual(second.map(result => result.changed), [false, false, false]);
93
+ });
94
+
95
+ test('removeContinuityHooks takes out only the companion registrations', () => {
96
+ const roots = installRootFixture();
97
+ configureContinuityHosts(roots, ['claude']);
98
+ const settingsPath = join(roots.managedRoot, 'settings.json');
99
+ const settings = JSON.parse(readFileSync(settingsPath, 'utf8'));
100
+ settings.hooks.SessionStart.unshift({ hooks: [{ type: 'command', command: 'python other_hook.py' }] });
101
+ const removedCount = removeContinuityHooks(settings);
102
+ assert.equal(removedCount, 3);
103
+ assert.deepEqual(Object.keys(settings.hooks), ['SessionStart']);
104
+ assert.equal(settings.hooks.SessionStart.length, 1);
105
+ assert.equal(settings.hooks.SessionStart[0].hooks[0].command, 'python other_hook.py');
106
+ });
@@ -220,18 +220,60 @@ for (const targetName of [null, 'profile']) {
220
220
  model: 'gpt-5.6-sol',
221
221
  });
222
222
 
223
- const foreignPreferencesPath = join(
223
+ const claudePreferencesPath = join(
224
224
  resolution.agentsHome,
225
225
  'rules',
226
226
  'pstack-model-preferences.claude.json',
227
227
  );
228
- writeFileSync(foreignPreferencesPath, JSON.stringify({
228
+ const seededClaudePreferences = JSON.parse(
229
+ readFileSync(claudePreferencesPath, 'utf8'),
230
+ );
231
+ assert.deepEqual(seededClaudePreferences, {
232
+ host: 'claude',
233
+ modelsByRole: {
234
+ 'feature, refactoring': ['opus'],
235
+ 'bug-fix': ['opus'],
236
+ 'perf-issue': ['fable'],
237
+ hillclimb: ['fable'],
238
+ 'judgment and prose': ['fable'],
239
+ 'hardest tasks': ['fable'],
240
+ 'how explorer': ['sonnet'],
241
+ 'how explainer': ['opus'],
242
+ 'how critics': ['sonnet', 'opus', 'fable'],
243
+ 'why investigators': ['sonnet'],
244
+ 'why synthesizer': ['fable'],
245
+ 'reflect tooling': ['opus'],
246
+ 'reflect judgment, divergent, synthesizer': ['fable'],
247
+ 'arena runners': ['sonnet', 'opus', 'fable'],
248
+ 'arena cross-judge pool': ['opus', 'fable'],
249
+ 'swarm workers': ['sonnet'],
250
+ 'architect runners': ['opus', 'fable'],
251
+ 'interrogate reviewers': ['sonnet', 'opus', 'fable'],
252
+ },
253
+ });
254
+ const claudeSelection = runSelector(selectorPath, {
255
+ host: 'claude',
256
+ inventoryHost: 'claude',
257
+ role: 'swarm workers',
258
+ delegationIndex: 0,
259
+ availableModelIds: ['sonnet', 'opus', 'fable'],
260
+ confirmedSuitableModelIds: [],
261
+ parentFallback: {
262
+ isAllowed: false,
263
+ hasMaterialCapabilityLoss: false,
264
+ },
265
+ });
266
+ assert.deepEqual(claudeSelection.nativeSpawnArguments, {
267
+ model: 'sonnet',
268
+ });
269
+
270
+ writeFileSync(claudePreferencesPath, JSON.stringify({
229
271
  host: 'claude',
230
272
  modelsByRole: {
231
273
  'feature, refactoring': ['confirmed-claude-model'],
232
274
  },
233
275
  }));
234
- const foreignSelection = runSelector(selectorPath, {
276
+ const editedClaudeSelection = runSelector(selectorPath, {
235
277
  host: 'claude',
236
278
  inventoryHost: 'claude',
237
279
  role: 'feature, refactoring',
@@ -243,7 +285,7 @@ for (const targetName of [null, 'profile']) {
243
285
  hasMaterialCapabilityLoss: false,
244
286
  },
245
287
  });
246
- assert.deepEqual(foreignSelection.nativeSpawnArguments, {
288
+ assert.deepEqual(editedClaudeSelection.nativeSpawnArguments, {
247
289
  model: 'confirmed-claude-model',
248
290
  });
249
291
 
@@ -251,7 +293,7 @@ for (const targetName of [null, 'profile']) {
251
293
  assert.equal(manifest.files.includes(sharedPath), true);
252
294
  assert.equal(manifest.files.includes(managedSelectorPath), true);
253
295
  assert.equal(manifest.files.includes(preferencesPath), false);
254
- assert.equal(manifest.files.includes(foreignPreferencesPath), false);
296
+ assert.equal(manifest.files.includes(claudePreferencesPath), false);
255
297
 
256
298
  writeFileSync(sharedPath, 'stale');
257
299
  writeFileSync(preferencesPath, JSON.stringify({
@@ -268,7 +310,7 @@ for (const targetName of [null, 'profile']) {
268
310
  ['user-edited-codex-model'],
269
311
  );
270
312
  assert.deepEqual(
271
- JSON.parse(readFileSync(foreignPreferencesPath, 'utf8'))
313
+ JSON.parse(readFileSync(claudePreferencesPath, 'utf8'))
272
314
  .modelsByRole['feature, refactoring'],
273
315
  ['confirmed-claude-model'],
274
316
  );
@@ -295,7 +337,7 @@ for (const targetName of [null, 'profile']) {
295
337
  assert.equal(existsSync(cursorPath), false);
296
338
  assert.equal(existsSync(selectorPath), false);
297
339
  assert.equal(existsSync(preferencesPath), true);
298
- assert.equal(existsSync(foreignPreferencesPath), true);
340
+ assert.equal(existsSync(claudePreferencesPath), true);
299
341
  } finally {
300
342
  rmSync(homeDirectory, { recursive: true, force: true });
301
343
  }
@@ -317,21 +359,21 @@ test('a blocked shared rule destination rolls back generated Cursor files', () =
317
359
  }
318
360
  });
319
361
 
320
- test('a failed install rolls back a newly seeded Codex preference file', () => {
362
+ test('a failed install rolls back newly seeded host preference files', () => {
321
363
  const homeDirectory = mkdtempSync(join(tmpdir(), 'cdev-pstack-seed-rollback-'));
322
364
  try {
323
- const preferencesPath = join(
324
- homeDirectory,
325
- '.agents',
326
- 'rules',
327
- 'pstack-model-preferences.codex.json',
328
- );
365
+ const preferencesDirectory = join(homeDirectory, '.agents', 'rules');
329
366
  assert.throws(() => runInstaller(
330
367
  homeDirectory,
331
368
  ['--only', 'core'],
332
369
  { CLAUDE_DEV_ENV_INSTALL_FAULT: 'after_file_staging' },
333
370
  ));
334
- assert.equal(existsSync(preferencesPath), false);
371
+ for (const hostName of ['claude', 'codex']) {
372
+ assert.equal(
373
+ existsSync(join(preferencesDirectory, 'pstack-model-preferences.' + hostName + '.json')),
374
+ false,
375
+ );
376
+ }
335
377
  } finally {
336
378
  rmSync(homeDirectory, { recursive: true, force: true });
337
379
  }