claude-dev-env 2.8.0 → 2.10.0
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/CLAUDE.md +8 -2
- package/_shared/pr-loop/CLAUDE.md +1 -1
- package/_shared/pr-loop/audit-contract.md +17 -6
- package/_shared/pr-loop/audit-reply-template.md +4 -4
- package/_shared/pr-loop/code-rules-gate.md +3 -5
- package/_shared/pr-loop/fix-protocol.md +2 -3
- package/_shared/pr-loop/gh-payloads.md +1 -1
- package/_shared/pr-loop/scripts/CLAUDE.md +1 -1
- package/_shared/pr-loop/scripts/README.md +1 -1
- package/_shared/pr-loop/scripts/code_rules_gate.py +2 -0
- package/_shared/pr-loop/scripts/code_rules_gate_parts/gate_running.py +16 -1
- package/_shared/pr-loop/scripts/code_rules_gate_parts/git_blob_readers.py +11 -5
- package/_shared/pr-loop/scripts/preflight.py +9 -4
- package/_shared/pr-loop/scripts/reviews_disabled.py +50 -22
- package/_shared/pr-loop/scripts/tests/conftest.py +20 -0
- package/_shared/pr-loop/scripts/tests/test_claude_permissions_common.py +6 -6
- package/_shared/pr-loop/scripts/tests/test_reviews_disabled.py +50 -6
- package/_shared/pr-loop/scripts/tests/test_revoke_project_claude_permissions.py +1 -1
- package/_shared/pr-loop/state-schema.md +5 -14
- package/agents/CLAUDE.md +2 -2
- package/agents/clean-coder.md +62 -562
- package/agents/code-quality-agent.md +10 -2
- package/agents/code-verifier.md +1 -1
- package/agents/test_agent_frontmatter.py +58 -40
- package/audit-rubrics/CLAUDE.md +2 -1
- package/audit-rubrics/audit-categories.json +704 -0
- package/audit-rubrics/prompts/category-i-concurrency.md +1 -1
- package/bin/CLAUDE.md +16 -5
- package/bin/ever-shipped-skills.mjs +2 -0
- package/bin/install-plan.mjs +402 -0
- package/bin/install-transaction.mjs +455 -0
- package/bin/install.mjs +593 -147
- package/bin/install.plan.test.mjs +194 -0
- package/bin/install.profile-root.test.mjs +154 -0
- package/bin/install.profiles.test.mjs +253 -0
- package/bin/install.settings-defaults.test.mjs +200 -0
- package/bin/install.transaction.test.mjs +400 -0
- package/bin/install.uninstall-transaction.test.mjs +418 -0
- package/bin/merge_managed_permissions.mjs +130 -0
- package/bin/resolve-install-root.mjs +181 -0
- package/bin/select-install-targets.mjs +401 -0
- package/commands/CLAUDE.md +0 -2
- package/docs/CODE_RULES.md +4 -2
- package/docs/references/CLAUDE.md +3 -2
- package/docs/references/advisor-tool.md +44 -6
- package/docs/references/prose-style-enforcement.md +25 -0
- package/docs/references/team-advisor-skill.md +14 -8
- package/hooks/blocking/CLAUDE.md +6 -6
- package/hooks/blocking/_path_setup.py +9 -5
- package/hooks/blocking/code_rules_docstrings.py +124 -30
- package/hooks/blocking/code_rules_enforcer.py +161 -16
- package/hooks/blocking/code_rules_shared.py +40 -23
- package/hooks/blocking/config/CLAUDE.md +3 -5
- package/hooks/blocking/config/prose_style_enforcement_constants.py +38 -0
- package/hooks/blocking/config/test_prose_style_enforcement_constants.py +45 -0
- package/hooks/blocking/eli11_reply_enforcer.py +70 -113
- package/hooks/blocking/hedging_language_blocker.py +103 -20
- package/hooks/blocking/hook_prose_detector_consistency.py +6 -0
- package/hooks/blocking/intent_only_ending_blocker.py +6 -0
- package/hooks/blocking/plain_language_blocker.py +139 -20
- package/hooks/blocking/pre_tool_use_dispatcher.py +102 -20
- package/hooks/blocking/state_description_blocker.py +7 -1
- package/hooks/blocking/tdd_enforcer.py +8 -0
- package/hooks/blocking/test__path_setup.py +28 -0
- package/hooks/blocking/test_code_rules_enforcer_agent_home_tooling.py +99 -0
- package/hooks/blocking/test_code_rules_enforcer_docstring_args_span_scope.py +232 -10
- package/hooks/blocking/test_code_rules_enforcer_ephemeral.py +1 -1
- package/hooks/blocking/test_code_rules_enforcer_join_separator_magic.py +41 -0
- package/hooks/blocking/test_code_rules_enforcer_string_magic.py +98 -0
- package/hooks/blocking/test_eli11_reply_enforcer.py +98 -165
- package/hooks/blocking/test_hedging_language_blocker.py +120 -1
- package/hooks/blocking/test_hook_prose_detector_consistency.py +28 -8
- package/hooks/blocking/test_intent_only_ending_blocker.py +27 -2
- package/hooks/blocking/test_package_inventory_stale_blocker.py +11 -4
- package/hooks/blocking/test_plain_language_blocker.py +129 -19
- package/hooks/blocking/test_plain_language_blocker_allowlist.py +70 -26
- package/hooks/blocking/test_pre_tool_use_dispatcher.py +99 -26
- package/hooks/blocking/test_pre_tool_use_dispatcher_native.py +87 -50
- package/hooks/blocking/test_state_description_blocker.py +45 -2
- package/hooks/blocking/test_stop_dispatcher.py +11 -7
- package/hooks/blocking/test_volatile_path_in_post_blocker.py +12 -12
- package/hooks/blocking/volatile_path_in_post_blocker.py +2 -2
- package/hooks/hooks.json +15 -0
- package/hooks/hooks_constants/CLAUDE.md +14 -3
- package/hooks/hooks_constants/ask_user_question_shape.py +281 -0
- package/hooks/hooks_constants/code_rules_enforcer_constants.py +2 -1
- package/hooks/hooks_constants/code_rules_path_utils_constants.py +1 -0
- package/hooks/hooks_constants/eli11_reply_enforcer_constants.py +5 -12
- package/hooks/hooks_constants/hedging_uncertainty_constants.py +42 -0
- package/hooks/hooks_constants/issue_tracker_session_starter_constants.py +23 -0
- package/hooks/hooks_constants/orchestrator_auto_starter_constants.py +23 -0
- package/hooks/hooks_constants/piped_pytest_blocker_constants.py +4 -1
- package/hooks/hooks_constants/plain_language_blocker_constants.py +4 -1
- package/hooks/hooks_constants/pre_tool_use_dispatcher_constants.py +6 -0
- package/hooks/hooks_constants/project_paths_reader.py +31 -4
- package/hooks/hooks_constants/prose_matcher_precision_constants.py +40 -0
- package/hooks/hooks_constants/pytest_invocation.py +354 -0
- package/hooks/hooks_constants/session_start_injector.py +163 -0
- package/hooks/hooks_constants/session_start_injector_constants.py +46 -0
- package/hooks/hooks_constants/shell_command_pipeline.py +397 -0
- package/hooks/hooks_constants/shell_command_segments.py +5 -0
- package/hooks/hooks_constants/test_ask_user_question_shape.py +167 -0
- package/hooks/hooks_constants/test_project_paths_reader.py +29 -0
- package/hooks/hooks_constants/test_prose_metrics_parity.py +8 -0
- package/hooks/hooks_constants/test_pytest_invocation.py +130 -0
- package/hooks/hooks_constants/test_session_start_injector.py +168 -0
- package/hooks/hooks_constants/test_shell_command_pipeline.py +135 -0
- package/hooks/hooks_constants/volatile_path_in_post_blocker_constants.py +1 -1
- package/hooks/hooks_constants/working_style_prompt_constants.py +30 -0
- package/hooks/observability/CLAUDE.md +2 -0
- package/hooks/observability/prose_matcher_advisory.py +237 -0
- package/hooks/observability/test_prose_matcher_advisory.py +143 -0
- package/hooks/session/CLAUDE.md +9 -1
- package/hooks/session/_path_setup.py +13 -0
- package/hooks/session/issue_tracker_session_starter.py +135 -0
- package/hooks/session/orchestrator_auto_starter.py +100 -0
- package/hooks/session/test__path_setup.py +28 -0
- package/hooks/session/test_issue_tracker_session_starter.py +104 -0
- package/hooks/session/test_orchestrator_auto_starter.py +99 -0
- package/hooks/session/test_working_style_prompt.py +47 -0
- package/hooks/session/untracked_repo_detector.py +1 -24
- package/hooks/session/working_style_prompt.py +36 -0
- package/hooks/validators/_path_setup.py +19 -0
- package/hooks/validators/run_all_validators.py +8 -13
- package/installable-surfaces.manifest.json +21 -0
- package/output-styles/CLAUDE.md +15 -0
- package/package.json +5 -2
- package/rules/CLAUDE.md +1 -0
- package/rules/code-standards.md +33 -7
- package/rules/durable-post-artifacts.md +2 -2
- package/rules/eli11-replies.md +7 -2
- package/rules/hedging-claims.md +4 -2
- package/rules/long-horizon-autonomy.md +3 -1
- package/rules/opus5-communication-contract.md +45 -0
- package/rules/plain-language.md +2 -2
- package/rules/research-mode.md +1 -1
- package/scripts/CLAUDE.md +13 -2
- package/scripts/Sync-RepoMain.ps1 +215 -0
- package/scripts/active_capability_references.py +218 -0
- package/scripts/ci/windows-installer-lifecycle.ps1 +78 -0
- package/scripts/claude_chain_runner.py +394 -6
- package/scripts/claude_chain_usage.py +1 -1
- package/scripts/codex_compat_materializer.py +105 -85
- package/scripts/dev_env_scripts_constants/CLAUDE.md +3 -1
- package/scripts/dev_env_scripts_constants/active_capability_constants.py +46 -0
- package/scripts/dev_env_scripts_constants/claude_chain_constants.py +74 -0
- package/scripts/dev_env_scripts_constants/grok_run_ledger_constants.py +50 -0
- package/scripts/dev_env_scripts_constants/grok_worker_constants.py +104 -0
- package/scripts/dev_env_scripts_constants/verify_installable_package_constants.py +116 -0
- package/scripts/grok_patch_artifacts.py +123 -0
- package/scripts/grok_run_ledger.py +318 -0
- package/scripts/profile-isolation-launchers/config/mcp-bundles.json +25 -0
- package/scripts/profile-isolation-launchers/config/profile-isolation-constants.mjs +60 -0
- package/scripts/profile-isolation-launchers/config/profiles.manifest.json +54 -0
- package/scripts/profile-isolation-launchers/config/shared-allowlist.json +64 -0
- package/scripts/profile-isolation-launchers/launcher-runtime.mjs +180 -0
- package/scripts/profile-isolation-launchers/lib/profile-manifest.mjs +288 -0
- package/scripts/profile-isolation-launchers/mcp-bundles.mjs +275 -0
- package/scripts/profile-isolation-launchers/profile-isolation-contract.test.mjs +221 -0
- package/scripts/profile-isolation-launchers/tests/launcher-runtime.test.mjs +108 -0
- package/scripts/profile-isolation-launchers/tests/mcp-bundles.test.mjs +147 -0
- package/scripts/profile-isolation-launchers/tests/shortcut-contract.test.ps1 +102 -0
- package/scripts/profile-isolation-launchers/tests/version-compatibility.test.mjs +210 -0
- package/scripts/profile-isolation-launchers/version-compatibility.mjs +299 -0
- package/scripts/profile-isolation-launchers/windows/shortcut-inventory.ps1 +127 -0
- package/scripts/profile-isolation-launchers/windows/shortcut-manifest.json +51 -0
- package/scripts/profile-isolation-launchers/windows/shortcut-reconcile.ps1 +77 -0
- package/scripts/spawn_grok_batch.py +556 -9
- package/scripts/test_active_capability_references.py +108 -0
- package/scripts/test_claude_chain_runner.py +414 -82
- package/scripts/test_claude_chain_usage.py +12 -12
- package/scripts/test_grok_patch_artifacts.py +82 -0
- package/scripts/test_grok_run_ledger.py +116 -0
- package/scripts/test_resolve_worker_spawn.py +2 -2
- package/scripts/test_spawn_grok_batch.py +295 -0
- package/scripts/test_verify_installable_package.py +208 -0
- package/scripts/tests/test_codex_compat_materializer.py +33 -0
- package/scripts/verify_installable_package.py +612 -0
- package/settings.json +10 -0
- package/skills/CLAUDE.md +6 -2
- package/skills/_shared/CLAUDE.md +37 -4
- package/skills/_shared/advisor/CLAUDE.md +9 -0
- package/skills/_shared/advisor/advisor-protocol.md +5 -0
- package/skills/_shared/advisor/scripts/README.md +9 -0
- package/skills/_shared/end-of-run-gotcha-recommendations.md +156 -0
- package/skills/_shared/pr-loop/CLAUDE.md +18 -1
- package/skills/_shared/pr-loop/audit-contract.md +5 -0
- package/skills/_shared/pr-loop/audit-reply-template.md +5 -0
- package/skills/_shared/pr-loop/code-rules-gate.md +5 -0
- package/skills/_shared/pr-loop/fix-protocol.md +5 -0
- package/skills/_shared/pr-loop/gh-payloads.md +5 -0
- package/skills/_shared/pr-loop/post-audit-thread-contract.md +5 -0
- package/skills/_shared/pr-loop/precatch-rubric.md +5 -0
- package/skills/_shared/pr-loop/scripts/CLAUDE.md +9 -1
- package/skills/_shared/pr-loop/scripts/RUNTIME_SCRIPTS.md +29 -0
- package/skills/_shared/pr-loop/scripts/audit_category_schema.py +355 -0
- package/skills/_shared/pr-loop/scripts/skills_pr_loop_constants/CLAUDE.md +1 -0
- package/skills/_shared/pr-loop/scripts/skills_pr_loop_constants/audit_category_schema_constants.py +32 -0
- package/skills/_shared/pr-loop/scripts/skills_pr_loop_constants/path_resolver_constants.py +7 -19
- package/skills/_shared/pr-loop/scripts/test_audit_category_schema.py +94 -0
- package/skills/_shared/pr-loop/scripts/test_build_audit_prompt.py +21 -0
- package/skills/_shared/pr-loop/state-schema.md +5 -0
- package/skills/_shared/pr-loop/worker-spawn.md +5 -0
- package/skills/autoconverge/reference/convergence.md +2 -1
- package/skills/autoconverge/reference/stop-conditions.md +5 -3
- package/skills/beat-sheet/SKILL.md +54 -0
- package/skills/beat-sheet/reference/visual-beats.md +29 -0
- package/skills/bugteam/CONSTRAINTS.md +4 -4
- package/skills/bugteam/EXAMPLES.md +1 -1
- package/skills/bugteam/reference/README.md +1 -1
- package/skills/e-code-review/SKILL.md +29 -3
- package/skills/e-code-review/reference/effort-evaluation.md +35 -0
- package/skills/e-code-review/reference/medium.md +15 -4
- package/skills/e-code-review/reference/runner-selection.md +40 -0
- package/skills/e-code-review/scripts/config/e_code_review_effort_constants/__init__.py +41 -0
- package/skills/e-code-review/scripts/config/e_code_review_effort_constants/effort_constants.py +40 -0
- package/skills/e-code-review/scripts/e_code_review_scripts_constants/__init__.py +1 -0
- package/skills/e-code-review/scripts/e_code_review_scripts_constants/finding_pipeline_constants.py +49 -0
- package/skills/e-code-review/scripts/e_code_review_scripts_constants/grok_code_review_constants.py +55 -0
- package/skills/e-code-review/scripts/effort_defaults_evidence.json +186 -0
- package/skills/e-code-review/scripts/effort_evaluation.py +362 -0
- package/skills/e-code-review/scripts/finding_pipeline.py +140 -0
- package/skills/e-code-review/scripts/fixtures/demanding.json +26 -0
- package/skills/e-code-review/scripts/fixtures/easy.json +14 -0
- package/skills/e-code-review/scripts/fixtures/medium.json +20 -0
- package/skills/e-code-review/scripts/grok_code_review.py +230 -0
- package/skills/e-code-review/scripts/test_effort_evaluation.py +180 -0
- package/skills/e-code-review/scripts/test_finding_pipeline.py +197 -0
- package/skills/e-code-review/scripts/test_grok_code_review.py +289 -0
- package/skills/grok-spawn/SKILL.md +5 -0
- package/skills/orchestrator/SKILL.md +5 -0
- package/skills/plan-to-pr/scripts/create_packet.py +4 -4
- package/skills/plan-to-pr/scripts/load_skill_constants.py +41 -0
- package/skills/plan-to-pr/scripts/validate_packet.py +4 -4
- package/skills/plan-to-pr/scripts/validate_protocol.py +4 -1
- package/skills/plan-to-pr/scripts/validate_run.py +4 -1
- package/skills/pr-converge/scripts/check_convergence.py +21 -19
- package/skills/pr-converge/scripts/check_convergence_availability.py +50 -7
- package/skills/pr-converge/scripts/conftest.py +35 -0
- package/skills/pr-converge/scripts/test_check_convergence_availability.py +65 -0
- package/skills/pr-converge/scripts/test_check_convergence_codex.py +11 -1
- package/skills/pr-converge/scripts/test_check_convergence_contract.py +9 -2
- package/skills/pr-loop-cloud-transport/SKILL.md +1 -1
- package/skills/rebase/SKILL.md +15 -3
- package/skills/reviewer-gates/SKILL.md +2 -2
- package/skills/show/SKILL.md +51 -0
- package/skills/show/references/accessibility.md +7 -0
- package/skills/show/references/art.md +3 -0
- package/skills/show/references/charts.md +3 -0
- package/skills/show/references/core-design.md +14 -0
- package/skills/show/references/erds.md +3 -0
- package/skills/show/references/flowcharts.md +3 -0
- package/skills/show/references/host-and-html.md +3 -0
- package/skills/show/references/illustrative-diagrams.md +10 -0
- package/skills/show/references/interaction.md +3 -0
- package/skills/show/references/mockups.md +3 -0
- package/skills/show/references/quality-gates.md +7 -0
- package/skills/show/references/structural-diagrams.md +3 -0
- package/skills/show/references/subject-inventory.md +21 -0
- package/skills/show/references/svg-contract.md +22 -0
- package/skills/show/routing.yaml +30 -0
- package/skills/show/samples/pr1262-v2.svg +222 -0
- package/skills/show/scripts/README.md +6 -0
- package/skills/show/scripts/validate-artifact.py +91 -0
- package/skills/show/scripts/validate-package.py +18 -0
- package/skills/show/templates/html-widget.html +4 -0
- package/skills/show/templates/svg-base.svg +19 -0
- package/skills/show/tests/fixtures/css-var.svg +6 -0
- package/skills/show/tests/fixtures/dead-ref.svg +7 -0
- package/skills/show/tests/fixtures/filled-glyph.svg +8 -0
- package/skills/show/tests/fixtures/inherited-fill.svg +18 -0
- package/skills/show/tests/fixtures/invalid.svg +1 -0
- package/skills/show/tests/fixtures/large-canvas.svg +21 -0
- package/skills/show/tests/fixtures/unfilled-connector.svg +15 -0
- package/skills/show/tests/fixtures/valid.html +1 -0
- package/skills/show/tests/test_validate-artifact.py +74 -0
- package/skills/show/tests/test_validators.py +59 -0
- package/skills/show/workflows/create-visual.md +13 -0
- package/skills/show/workflows/review-visual.md +20 -0
- package/skills/split-pr/SKILL.md +85 -0
- package/skills/split-pr/reference/path-layers.md +16 -0
- package/skills/split-pr/reference/proposal-format.md +15 -0
- package/skills/split-pr/reference/split-further-loop.md +10 -0
- package/skills/split-pr/reference/splitting-principles.md +26 -0
- package/skills/split-pr/scripts/analyze_pr.py +279 -0
- package/skills/split-pr/scripts/categorize_files.py +106 -0
- package/skills/split-pr/scripts/config/__init__.py +1 -0
- package/skills/split-pr/scripts/config/dependency_constants.py +14 -0
- package/skills/split-pr/scripts/config/git_operations_constants.py +36 -0
- package/skills/split-pr/scripts/config/packing_constants.py +61 -0
- package/skills/split-pr/scripts/config/plan_constants.py +49 -0
- package/skills/split-pr/scripts/config/split_pr_constants.py +110 -0
- package/skills/split-pr/scripts/execute_split_slices.py +82 -0
- package/skills/split-pr/scripts/pack_files_into_slices.py +212 -0
- package/skills/split-pr/scripts/split_pr_dependency_graph.py +70 -0
- package/skills/split-pr/scripts/split_pr_git_operations.py +184 -0
- package/skills/split-pr/scripts/split_pr_layer_order.py +58 -0
- package/skills/split-pr/scripts/split_pr_paginate.py +119 -0
- package/skills/split-pr/scripts/split_pr_process_runner.py +52 -0
- package/skills/split-pr/scripts/split_pr_script_types.py +126 -0
- package/skills/split-pr/scripts/split_pr_title.py +41 -0
- package/skills/split-pr/scripts/test_analyze_pr.py +228 -0
- package/skills/split-pr/scripts/test_categorize_files.py +55 -0
- package/skills/split-pr/scripts/test_categorize_files_packing.py +59 -0
- package/skills/split-pr/scripts/test_execute_split_slices.py +99 -0
- package/skills/split-pr/scripts/test_split_pr_dependency_graph.py +47 -0
- package/skills/split-pr/scripts/test_split_pr_git_operations.py +125 -0
- package/skills/split-pr/scripts/test_split_pr_layer_order.py +36 -0
- package/skills/split-pr/scripts/test_split_pr_paginate.py +65 -0
- package/skills/split-pr/scripts/test_split_pr_script_types.py +73 -0
- package/skills/split-pr/scripts/test_split_pr_title.py +28 -0
- package/skills/split-pr/scripts/test_verify_dependency_graph.py +46 -0
- package/skills/split-pr/scripts/test_verify_plan.py +56 -0
- package/skills/split-pr/scripts/test_verify_plan_contract.py +50 -0
- package/skills/split-pr/scripts/test_verify_plan_path_normalization.py +45 -0
- package/skills/split-pr/scripts/verify_dependency_graph.py +111 -0
- package/skills/split-pr/scripts/verify_plan.py +139 -0
- package/skills/task-build/reference/tool-routing.md +3 -0
- package/skills/team-advisor/SKILL.md +23 -44
- package/system-prompts/software-engineer.xml +17 -5
- package/commands/initialize.md +0 -90
- package/commands/stubcheck.md +0 -88
- package/skills/test_markdown_link_integrity.py +0 -107
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Install, update, and uninstall transaction journal for claude-dev-env.
|
|
3
|
+
*
|
|
4
|
+
* Captures the prior managed installation, runs mutations, and restores
|
|
5
|
+
* settings, manifest, managed files, and core.hooksPath when any phase fails.
|
|
6
|
+
*
|
|
7
|
+
* ::
|
|
8
|
+
*
|
|
9
|
+
* const snapshot = capturePriorInstallSnapshot({ managedRoot, ... })
|
|
10
|
+
* try {
|
|
11
|
+
* runWithInstallTransaction({ snapshot, faultPhase, runMutations })
|
|
12
|
+
* } catch {
|
|
13
|
+
* // prior installation restored
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
copyFileSync,
|
|
19
|
+
existsSync,
|
|
20
|
+
lstatSync,
|
|
21
|
+
mkdirSync,
|
|
22
|
+
mkdtempSync,
|
|
23
|
+
readdirSync,
|
|
24
|
+
readlinkSync,
|
|
25
|
+
rmdirSync,
|
|
26
|
+
rmSync,
|
|
27
|
+
symlinkSync,
|
|
28
|
+
unlinkSync,
|
|
29
|
+
writeFileSync,
|
|
30
|
+
} from 'node:fs';
|
|
31
|
+
import { dirname, join } from 'node:path';
|
|
32
|
+
import { execFileSync } from 'node:child_process';
|
|
33
|
+
|
|
34
|
+
/** Env var that forces a throw after a named mutation phase (tests only). */
|
|
35
|
+
export const INSTALL_FAULT_ENV = 'CLAUDE_DEV_ENV_INSTALL_FAULT';
|
|
36
|
+
|
|
37
|
+
/** Journal directory name under the managed root. */
|
|
38
|
+
export const TRANSACTION_JOURNAL_DIRECTORY_NAME = '.claude-dev-env-txn';
|
|
39
|
+
|
|
40
|
+
export const FAULT_PHASES = Object.freeze({
|
|
41
|
+
AFTER_FILE_STAGING: 'after_file_staging',
|
|
42
|
+
AFTER_SETTINGS_WRITE: 'after_settings_write',
|
|
43
|
+
AFTER_GIT_CONFIG: 'after_git_config',
|
|
44
|
+
AFTER_MANIFEST_WRITE: 'after_manifest_write',
|
|
45
|
+
BEFORE_DURABLE_PROMOTION: 'before_durable_promotion',
|
|
46
|
+
AFTER_LINK_PUBLICATION: 'after_link_publication',
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const ALL_FAULT_PHASE_VALUES = Object.freeze(Object.values(FAULT_PHASES));
|
|
50
|
+
|
|
51
|
+
const META_FILE_NAME = 'meta.json';
|
|
52
|
+
const SETTINGS_BLOB_NAME = 'settings.json';
|
|
53
|
+
const MANIFEST_BLOB_NAME = 'manifest.json';
|
|
54
|
+
const FILES_DIRECTORY_NAME = 'files';
|
|
55
|
+
const ENTRY_KIND_FILE = 'file';
|
|
56
|
+
const ENTRY_KIND_SYMLINK = 'symlink';
|
|
57
|
+
const ENTRY_KIND_MISSING = 'missing';
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Fault injection that aborts the install after a named phase.
|
|
61
|
+
*/
|
|
62
|
+
export class InstallTransactionFaultError extends Error {
|
|
63
|
+
/**
|
|
64
|
+
* @param {string} phase
|
|
65
|
+
*/
|
|
66
|
+
constructor(phase) {
|
|
67
|
+
super(`Install fault injection at phase: ${phase}`);
|
|
68
|
+
this.name = 'InstallTransactionFaultError';
|
|
69
|
+
this.phase = phase;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Read the configured fault phase from the environment, or null.
|
|
75
|
+
*
|
|
76
|
+
* @param {NodeJS.ProcessEnv} [environment]
|
|
77
|
+
* @returns {string|null}
|
|
78
|
+
*/
|
|
79
|
+
export function resolveFaultPhaseFromEnvironment(environment = process.env) {
|
|
80
|
+
const rawPhase = environment[INSTALL_FAULT_ENV];
|
|
81
|
+
if (!rawPhase) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
if (!ALL_FAULT_PHASE_VALUES.includes(rawPhase)) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`Unknown ${INSTALL_FAULT_ENV} value "${rawPhase}". `
|
|
87
|
+
+ `Expected one of: ${ALL_FAULT_PHASE_VALUES.join(', ')}`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
return rawPhase;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Throw when the current phase matches the active fault phase.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} currentPhase
|
|
97
|
+
* @param {string|null|undefined} faultPhase
|
|
98
|
+
* @returns {void}
|
|
99
|
+
*/
|
|
100
|
+
export function throwIfFaultPhase(currentPhase, faultPhase) {
|
|
101
|
+
if (faultPhase && faultPhase === currentPhase) {
|
|
102
|
+
throw new InstallTransactionFaultError(currentPhase);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Read global core.hooksPath, or null when unset.
|
|
108
|
+
*
|
|
109
|
+
* @param {{ execFileSync?: typeof execFileSync, env?: NodeJS.ProcessEnv }} [io]
|
|
110
|
+
* @returns {string|null}
|
|
111
|
+
*/
|
|
112
|
+
export function readGlobalCoreHooksPath(io = {}) {
|
|
113
|
+
const execFile = io.execFileSync || execFileSync;
|
|
114
|
+
const environment = io.env || process.env;
|
|
115
|
+
try {
|
|
116
|
+
const value = execFile('git', ['config', '--global', '--get', 'core.hooksPath'], {
|
|
117
|
+
encoding: 'utf8',
|
|
118
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
119
|
+
env: environment,
|
|
120
|
+
});
|
|
121
|
+
const trimmed = String(value).trim();
|
|
122
|
+
return trimmed === '' ? null : trimmed;
|
|
123
|
+
} catch (readError) {
|
|
124
|
+
if (readError && readError.status === 1) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Write or clear global core.hooksPath.
|
|
133
|
+
*
|
|
134
|
+
* @param {string|null} hooksPath
|
|
135
|
+
* @param {{ execFileSync?: typeof execFileSync, env?: NodeJS.ProcessEnv }} [io]
|
|
136
|
+
* @returns {void}
|
|
137
|
+
*/
|
|
138
|
+
export function writeGlobalCoreHooksPath(hooksPath, io = {}) {
|
|
139
|
+
const execFile = io.execFileSync || execFileSync;
|
|
140
|
+
const environment = io.env || process.env;
|
|
141
|
+
if (hooksPath === null || hooksPath === undefined || hooksPath === '') {
|
|
142
|
+
try {
|
|
143
|
+
execFile('git', ['config', '--global', '--unset', 'core.hooksPath'], {
|
|
144
|
+
stdio: 'ignore',
|
|
145
|
+
env: environment,
|
|
146
|
+
});
|
|
147
|
+
} catch (unsetError) {
|
|
148
|
+
if (unsetError && (unsetError.status === 1 || unsetError.status === 5)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
throw unsetError;
|
|
152
|
+
}
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
execFile('git', ['config', '--global', 'core.hooksPath', hooksPath], {
|
|
156
|
+
stdio: 'ignore',
|
|
157
|
+
env: environment,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {string} absolutePath
|
|
163
|
+
* @param {{ existsSync?: typeof existsSync, lstatSync?: typeof lstatSync, readlinkSync?: typeof readlinkSync }} io
|
|
164
|
+
* @returns {{ kind: string, linkTarget?: string }}
|
|
165
|
+
*/
|
|
166
|
+
function classifyPath(absolutePath, io) {
|
|
167
|
+
const exists = io.existsSync || existsSync;
|
|
168
|
+
const lstat = io.lstatSync || lstatSync;
|
|
169
|
+
const readlink = io.readlinkSync || readlinkSync;
|
|
170
|
+
if (!exists(absolutePath)) {
|
|
171
|
+
return { kind: ENTRY_KIND_MISSING };
|
|
172
|
+
}
|
|
173
|
+
const stats = lstat(absolutePath);
|
|
174
|
+
if (stats.isSymbolicLink()) {
|
|
175
|
+
return { kind: ENTRY_KIND_SYMLINK, linkTarget: readlink(absolutePath) };
|
|
176
|
+
}
|
|
177
|
+
if (stats.isFile()) {
|
|
178
|
+
return { kind: ENTRY_KIND_FILE };
|
|
179
|
+
}
|
|
180
|
+
return { kind: ENTRY_KIND_MISSING };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Capture prior settings, manifest, hooksPath, and package-owned files.
|
|
185
|
+
*
|
|
186
|
+
* @param {{
|
|
187
|
+
* managedRoot: string,
|
|
188
|
+
* manifestFilePath: string,
|
|
189
|
+
* settingsPath: string,
|
|
190
|
+
* priorManifestFiles?: string[]|null,
|
|
191
|
+
* journalParentDirectory?: string,
|
|
192
|
+
* io?: object,
|
|
193
|
+
* }} input
|
|
194
|
+
* @returns {object}
|
|
195
|
+
*/
|
|
196
|
+
export function capturePriorInstallSnapshot(input) {
|
|
197
|
+
const io = input.io || {};
|
|
198
|
+
const exists = io.existsSync || existsSync;
|
|
199
|
+
const mkdir = io.mkdirSync || mkdirSync;
|
|
200
|
+
const mkdtemp = io.mkdtempSync || mkdtempSync;
|
|
201
|
+
const copyFile = io.copyFileSync || copyFileSync;
|
|
202
|
+
const writeFile = io.writeFileSync || writeFileSync;
|
|
203
|
+
|
|
204
|
+
const journalParent = input.journalParentDirectory
|
|
205
|
+
|| join(input.managedRoot, TRANSACTION_JOURNAL_DIRECTORY_NAME);
|
|
206
|
+
mkdir(journalParent, { recursive: true });
|
|
207
|
+
const journalRoot = mkdtemp(join(journalParent, 'run-'));
|
|
208
|
+
const filesDirectory = join(journalRoot, FILES_DIRECTORY_NAME);
|
|
209
|
+
mkdir(filesDirectory, { recursive: true });
|
|
210
|
+
|
|
211
|
+
const settingsExisted = exists(input.settingsPath);
|
|
212
|
+
if (settingsExisted) {
|
|
213
|
+
copyFile(input.settingsPath, join(journalRoot, SETTINGS_BLOB_NAME));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const manifestExisted = exists(input.manifestFilePath);
|
|
217
|
+
if (manifestExisted) {
|
|
218
|
+
copyFile(input.manifestFilePath, join(journalRoot, MANIFEST_BLOB_NAME));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const priorHooksPath = readGlobalCoreHooksPath(io);
|
|
222
|
+
/** @type {Array<{ absolutePath: string, kind: string, blobName?: string, linkTarget?: string }>} */
|
|
223
|
+
const allFileEntries = [];
|
|
224
|
+
const priorFiles = Array.isArray(input.priorManifestFiles) ? input.priorManifestFiles : [];
|
|
225
|
+
let entryIndex = 0;
|
|
226
|
+
for (const eachPath of priorFiles) {
|
|
227
|
+
if (typeof eachPath !== 'string' || eachPath.trim() === '') {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const classification = classifyPath(eachPath, io);
|
|
231
|
+
if (classification.kind === ENTRY_KIND_FILE) {
|
|
232
|
+
const blobName = String(entryIndex);
|
|
233
|
+
copyFile(eachPath, join(filesDirectory, blobName));
|
|
234
|
+
allFileEntries.push({
|
|
235
|
+
absolutePath: eachPath,
|
|
236
|
+
kind: ENTRY_KIND_FILE,
|
|
237
|
+
blobName,
|
|
238
|
+
});
|
|
239
|
+
entryIndex += 1;
|
|
240
|
+
} else if (classification.kind === ENTRY_KIND_SYMLINK) {
|
|
241
|
+
allFileEntries.push({
|
|
242
|
+
absolutePath: eachPath,
|
|
243
|
+
kind: ENTRY_KIND_SYMLINK,
|
|
244
|
+
linkTarget: classification.linkTarget,
|
|
245
|
+
});
|
|
246
|
+
} else {
|
|
247
|
+
allFileEntries.push({
|
|
248
|
+
absolutePath: eachPath,
|
|
249
|
+
kind: ENTRY_KIND_MISSING,
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const meta = {
|
|
255
|
+
managedRoot: input.managedRoot,
|
|
256
|
+
settingsPath: input.settingsPath,
|
|
257
|
+
manifestFilePath: input.manifestFilePath,
|
|
258
|
+
settingsExisted,
|
|
259
|
+
manifestExisted,
|
|
260
|
+
priorHooksPath,
|
|
261
|
+
allFileEntries,
|
|
262
|
+
};
|
|
263
|
+
writeFile(join(journalRoot, META_FILE_NAME), `${JSON.stringify(meta, null, 2)}\n`);
|
|
264
|
+
|
|
265
|
+
return Object.freeze({
|
|
266
|
+
journalRoot,
|
|
267
|
+
managedRoot: input.managedRoot,
|
|
268
|
+
settingsPath: input.settingsPath,
|
|
269
|
+
manifestFilePath: input.manifestFilePath,
|
|
270
|
+
settingsExisted,
|
|
271
|
+
manifestExisted,
|
|
272
|
+
priorHooksPath,
|
|
273
|
+
allFileEntries: Object.freeze(allFileEntries.map((eachEntry) => Object.freeze({ ...eachEntry }))),
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Restore the captured prior installation and drop extra write-set paths.
|
|
279
|
+
*
|
|
280
|
+
* @param {ReturnType<typeof capturePriorInstallSnapshot>} snapshot
|
|
281
|
+
* @param {{
|
|
282
|
+
* allWrittenPaths?: string[],
|
|
283
|
+
* io?: object,
|
|
284
|
+
* }} [options]
|
|
285
|
+
* @returns {void}
|
|
286
|
+
*/
|
|
287
|
+
export function restorePriorInstallSnapshot(snapshot, options = {}) {
|
|
288
|
+
const io = options.io || {};
|
|
289
|
+
const exists = io.existsSync || existsSync;
|
|
290
|
+
const copyFile = io.copyFileSync || copyFileSync;
|
|
291
|
+
const mkdir = io.mkdirSync || mkdirSync;
|
|
292
|
+
const unlink = io.unlinkSync || unlinkSync;
|
|
293
|
+
const symlink = io.symlinkSync || symlinkSync;
|
|
294
|
+
const lstat = io.lstatSync || lstatSync;
|
|
295
|
+
|
|
296
|
+
const filesDirectory = join(snapshot.journalRoot, FILES_DIRECTORY_NAME);
|
|
297
|
+
for (const eachEntry of snapshot.allFileEntries) {
|
|
298
|
+
try {
|
|
299
|
+
if (exists(eachEntry.absolutePath)) {
|
|
300
|
+
const stats = lstat(eachEntry.absolutePath);
|
|
301
|
+
if (stats.isFile() || stats.isSymbolicLink()) {
|
|
302
|
+
unlink(eachEntry.absolutePath);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
} catch {
|
|
306
|
+
// keep restoring remaining entries
|
|
307
|
+
}
|
|
308
|
+
if (eachEntry.kind === ENTRY_KIND_FILE && eachEntry.blobName) {
|
|
309
|
+
mkdir(dirname(eachEntry.absolutePath), { recursive: true });
|
|
310
|
+
copyFile(join(filesDirectory, eachEntry.blobName), eachEntry.absolutePath);
|
|
311
|
+
} else if (eachEntry.kind === ENTRY_KIND_SYMLINK && eachEntry.linkTarget) {
|
|
312
|
+
mkdir(dirname(eachEntry.absolutePath), { recursive: true });
|
|
313
|
+
try {
|
|
314
|
+
symlink(eachEntry.linkTarget, eachEntry.absolutePath);
|
|
315
|
+
} catch {
|
|
316
|
+
// platform may reject the link shape; leave missing
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const priorPathSet = new Set(snapshot.allFileEntries.map((eachEntry) => eachEntry.absolutePath));
|
|
322
|
+
const allWrittenPaths = Array.isArray(options.allWrittenPaths) ? options.allWrittenPaths : [];
|
|
323
|
+
for (const eachWrittenPath of allWrittenPaths) {
|
|
324
|
+
if (priorPathSet.has(eachWrittenPath)) {
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
if (eachWrittenPath === snapshot.settingsPath || eachWrittenPath === snapshot.manifestFilePath) {
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
try {
|
|
331
|
+
if (exists(eachWrittenPath)) {
|
|
332
|
+
const stats = lstat(eachWrittenPath);
|
|
333
|
+
if (stats.isFile() || stats.isSymbolicLink()) {
|
|
334
|
+
unlink(eachWrittenPath);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
} catch {
|
|
338
|
+
// keep restoring remaining entries
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (snapshot.settingsExisted) {
|
|
343
|
+
mkdir(dirname(snapshot.settingsPath), { recursive: true });
|
|
344
|
+
copyFile(join(snapshot.journalRoot, SETTINGS_BLOB_NAME), snapshot.settingsPath);
|
|
345
|
+
} else if (exists(snapshot.settingsPath)) {
|
|
346
|
+
try {
|
|
347
|
+
unlink(snapshot.settingsPath);
|
|
348
|
+
} catch {
|
|
349
|
+
// leave in place when unlink fails
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
if (snapshot.manifestExisted) {
|
|
354
|
+
mkdir(dirname(snapshot.manifestFilePath), { recursive: true });
|
|
355
|
+
copyFile(join(snapshot.journalRoot, MANIFEST_BLOB_NAME), snapshot.manifestFilePath);
|
|
356
|
+
} else if (exists(snapshot.manifestFilePath)) {
|
|
357
|
+
try {
|
|
358
|
+
unlink(snapshot.manifestFilePath);
|
|
359
|
+
} catch {
|
|
360
|
+
// leave in place when unlink fails
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
writeGlobalCoreHooksPath(snapshot.priorHooksPath, io);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Remove the journal directory after a successful commit.
|
|
369
|
+
*
|
|
370
|
+
* @param {ReturnType<typeof capturePriorInstallSnapshot>} snapshot
|
|
371
|
+
* @param {{ rmSync?: typeof rmSync, readdirSync?: typeof readdirSync, rmdirSync?: typeof rmdirSync }} [io]
|
|
372
|
+
* @returns {void}
|
|
373
|
+
*/
|
|
374
|
+
export function discardInstallTransactionJournal(snapshot, io = {}) {
|
|
375
|
+
const removeTree = io.rmSync || rmSync;
|
|
376
|
+
const readDirectory = io.readdirSync || readdirSync;
|
|
377
|
+
const removeDirectory = io.rmdirSync || rmdirSync;
|
|
378
|
+
try {
|
|
379
|
+
removeTree(snapshot.journalRoot, { recursive: true, force: true });
|
|
380
|
+
} catch {
|
|
381
|
+
// journal cleanup is best-effort after a successful install
|
|
382
|
+
}
|
|
383
|
+
const journalParent = dirname(snapshot.journalRoot);
|
|
384
|
+
try {
|
|
385
|
+
if (readDirectory(journalParent).length === 0) {
|
|
386
|
+
removeDirectory(journalParent);
|
|
387
|
+
}
|
|
388
|
+
} catch {
|
|
389
|
+
// parent cleanup is best-effort
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Run install mutations inside a snapshot/restore transaction.
|
|
395
|
+
*
|
|
396
|
+
* @param {{
|
|
397
|
+
* snapshot: ReturnType<typeof capturePriorInstallSnapshot>,
|
|
398
|
+
* faultPhase?: string|null,
|
|
399
|
+
* runMutations: (helpers: {
|
|
400
|
+
* throwIfFault: (phase: string) => void,
|
|
401
|
+
* recordWrittenPath: (absolutePath: string) => void,
|
|
402
|
+
* syncWrittenPaths: (allPaths: string[]) => void,
|
|
403
|
+
* }) => void,
|
|
404
|
+
* io?: object,
|
|
405
|
+
* }} input
|
|
406
|
+
* @returns {void}
|
|
407
|
+
*/
|
|
408
|
+
export function runWithInstallTransaction(input) {
|
|
409
|
+
const io = input.io || {};
|
|
410
|
+
/** @type {string[]} */
|
|
411
|
+
const allWrittenPaths = [];
|
|
412
|
+
const faultPhase = input.faultPhase === undefined
|
|
413
|
+
? resolveFaultPhaseFromEnvironment(process.env)
|
|
414
|
+
: input.faultPhase;
|
|
415
|
+
|
|
416
|
+
try {
|
|
417
|
+
input.runMutations({
|
|
418
|
+
throwIfFault: (phase) => throwIfFaultPhase(phase, faultPhase),
|
|
419
|
+
recordWrittenPath: (absolutePath) => {
|
|
420
|
+
if (typeof absolutePath === 'string' && absolutePath !== '') {
|
|
421
|
+
allWrittenPaths.push(absolutePath);
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
syncWrittenPaths: (allPaths) => {
|
|
425
|
+
allWrittenPaths.length = 0;
|
|
426
|
+
for (const eachPath of allPaths) {
|
|
427
|
+
if (typeof eachPath === 'string' && eachPath !== '') {
|
|
428
|
+
allWrittenPaths.push(eachPath);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
},
|
|
432
|
+
});
|
|
433
|
+
discardInstallTransactionJournal(input.snapshot, io);
|
|
434
|
+
} catch (mutationError) {
|
|
435
|
+
try {
|
|
436
|
+
restorePriorInstallSnapshot(input.snapshot, { allWrittenPaths, io });
|
|
437
|
+
} catch (restoreError) {
|
|
438
|
+
const mutationMessage = mutationError instanceof Error
|
|
439
|
+
? mutationError.message
|
|
440
|
+
: String(mutationError);
|
|
441
|
+
const restoreMessage = restoreError instanceof Error
|
|
442
|
+
? restoreError.message
|
|
443
|
+
: String(restoreError);
|
|
444
|
+
throw new Error(
|
|
445
|
+
`Install failed (${mutationMessage}) and restore also failed (${restoreMessage})`,
|
|
446
|
+
);
|
|
447
|
+
}
|
|
448
|
+
try {
|
|
449
|
+
discardInstallTransactionJournal(input.snapshot, io);
|
|
450
|
+
} catch {
|
|
451
|
+
// journal cleanup is best-effort after restore
|
|
452
|
+
}
|
|
453
|
+
throw mutationError;
|
|
454
|
+
}
|
|
455
|
+
}
|