@hasna/hooks 0.14.1 → 0.15.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.
- package/README.md +30 -10
- package/bin/hooks/stop-review.js +17 -9
- package/bin/hooks-mcp.js +741 -311
- package/bin/index.js +1669 -632
- package/bin/native-safety-entry.js +2 -2
- package/bin/native-safety-worker.cjs +37 -35
- package/bin/release-manifest.json +297 -0
- package/bin/serve.js +577 -151
- package/dist/index.js +1809 -1176
- package/dist/lib/error-events.d.ts +59 -0
- package/dist/lib/install-record.d.ts +136 -0
- package/dist/lib/manifest.d.ts +6 -0
- package/dist/lib/release-manifest.d.ts +162 -0
- package/dist/lib/store.d.ts +25 -2
- package/dist/openapi.d.ts +147 -0
- package/dist/registry-auth.d.ts +6 -1
- package/dist/registry-http.d.ts +2 -1
- package/dist/sdk/generated.d.ts +26 -0
- package/dist/sdk/index.js +14 -0
- package/hooks/codewith-native-common.ts +190 -6
- package/hooks/hook-signed-link-guard/README.md +46 -0
- package/hooks/hook-signed-link-guard/src/classify.ts +7 -3
- package/hooks/hook-signed-link-guard/src/jq.ts +205 -34
- package/hooks/hook-stop-review/README.md +5 -2
- package/hooks/hook-stop-review/src/jev.ts +9 -4
- package/hooks/hook-stop-review/src/policy.ts +7 -3
- package/hooks/hook-stop-review/src/runtime.ts +5 -4
- package/hooks/hook-trash-guard/README.md +15 -10
- package/hooks/hook-trash-guard/src/hook.ts +130 -12
- package/hooks/hook-workspace-repos-guard/src/hook.ts +27 -12
- package/hooks/pre-bash/README.md +47 -1
- package/hooks/pre-bash/src/hook.ts +168 -12
- package/hooks/shell-words.ts +40 -2
- package/package.json +3 -2
- package/scripts/build-release-manifest.ts +27 -0
- package/scripts/validate-package.ts +5 -1
- package/scripts/validate-release-manifest.ts +67 -0
package/dist/index.js
CHANGED
|
@@ -581,6 +581,664 @@ var init_redact = __esm(() => {
|
|
|
581
581
|
];
|
|
582
582
|
});
|
|
583
583
|
|
|
584
|
+
// src/lib/registry.ts
|
|
585
|
+
function matcherFor(meta, target) {
|
|
586
|
+
return meta.targetMatchers?.[target] ?? meta.matcher;
|
|
587
|
+
}
|
|
588
|
+
function getHooksByCategory(category) {
|
|
589
|
+
return HOOKS.filter((h) => h.category === category);
|
|
590
|
+
}
|
|
591
|
+
function getHookEvents(hook) {
|
|
592
|
+
return hook.events && hook.events.length > 0 ? hook.events : [hook.event];
|
|
593
|
+
}
|
|
594
|
+
function searchHooks(query) {
|
|
595
|
+
const q = query.toLowerCase();
|
|
596
|
+
return HOOKS.filter((h) => h.name.toLowerCase().includes(q) || h.displayName.toLowerCase().includes(q) || h.description.toLowerCase().includes(q) || h.tags.some((t) => t.includes(q)));
|
|
597
|
+
}
|
|
598
|
+
function getHook(name) {
|
|
599
|
+
return HOOKS.find((h) => h.name === name);
|
|
600
|
+
}
|
|
601
|
+
var HOOK_EVENTS, CLAUDE_TRASH_GUARD_MATCHER = "^(Bash|Monitor|apply_patch|ApplyPatch|functions\\.apply_patch)$", CATEGORIES, HOOKS;
|
|
602
|
+
var init_registry = __esm(() => {
|
|
603
|
+
init_app_home();
|
|
604
|
+
HOOK_EVENTS = [
|
|
605
|
+
"PreToolUse",
|
|
606
|
+
"PostToolUse",
|
|
607
|
+
"Stop",
|
|
608
|
+
"Notification",
|
|
609
|
+
"SessionStart",
|
|
610
|
+
"SessionEnd",
|
|
611
|
+
"UserPromptSubmit",
|
|
612
|
+
"SubagentStart"
|
|
613
|
+
];
|
|
614
|
+
CATEGORIES = [
|
|
615
|
+
"Git Safety",
|
|
616
|
+
"Code Quality",
|
|
617
|
+
"Security",
|
|
618
|
+
"Notifications",
|
|
619
|
+
"Context Management",
|
|
620
|
+
"Workflow Automation",
|
|
621
|
+
"Environment",
|
|
622
|
+
"Permissions",
|
|
623
|
+
"Observability",
|
|
624
|
+
"Agent Teams"
|
|
625
|
+
];
|
|
626
|
+
HOOKS = [
|
|
627
|
+
{
|
|
628
|
+
name: "gitguard",
|
|
629
|
+
displayName: "Git Guard",
|
|
630
|
+
description: "Blocks destructive git operations like reset --hard, push --force, clean -f",
|
|
631
|
+
version: "0.1.0",
|
|
632
|
+
category: "Git Safety",
|
|
633
|
+
event: "PreToolUse",
|
|
634
|
+
matcher: "Bash",
|
|
635
|
+
tags: ["git", "safety", "destructive", "guard"]
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: "branchprotect",
|
|
639
|
+
displayName: "Branch Protect",
|
|
640
|
+
description: "Prevents editing files directly on main/master branch",
|
|
641
|
+
version: "0.1.0",
|
|
642
|
+
category: "Git Safety",
|
|
643
|
+
event: "PreToolUse",
|
|
644
|
+
matcher: "Write|Edit|NotebookEdit",
|
|
645
|
+
tags: ["git", "branch", "protection", "main"]
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
name: "checkpoint",
|
|
649
|
+
displayName: "Checkpoint",
|
|
650
|
+
description: "Creates shadow git snapshots before file modifications for easy rollback",
|
|
651
|
+
version: "0.1.0",
|
|
652
|
+
category: "Git Safety",
|
|
653
|
+
event: "PreToolUse",
|
|
654
|
+
matcher: "Write|Edit|NotebookEdit",
|
|
655
|
+
tags: ["git", "snapshot", "rollback", "backup"]
|
|
656
|
+
},
|
|
657
|
+
{
|
|
658
|
+
name: "worktree-guard",
|
|
659
|
+
displayName: "Worktree Guard",
|
|
660
|
+
description: "Warns on feature work outside managed repos worktrees and blocks scoped destructive operations",
|
|
661
|
+
version: "0.1.0",
|
|
662
|
+
category: "Git Safety",
|
|
663
|
+
event: "PreToolUse",
|
|
664
|
+
matcher: "^(Bash|Write|Edit|MultiEdit|NotebookEdit|apply_patch|ApplyPatch|functions\\.apply_patch|mcp__.*)$",
|
|
665
|
+
tags: ["git", "worktree", "repos", "multi-agent", "safety", "dangerous-ops"]
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
name: "workspace-repos-guard",
|
|
669
|
+
timeoutSeconds: 10,
|
|
670
|
+
displayName: "Workspace Repos Guard",
|
|
671
|
+
description: "Blocks writes and deletes that break the protected repo-checkout structure (~/.hasna/repos/clones canonical, plus legacy ~/workspace/repos during the migration window): writes to a protected root, top-level entry creation, non-org folders, and any delete under a protected root",
|
|
672
|
+
version: "0.1.1",
|
|
673
|
+
category: "Git Safety",
|
|
674
|
+
event: "PreToolUse",
|
|
675
|
+
matcher: "^(Bash|Write|Edit|MultiEdit|NotebookEdit|apply_patch|ApplyPatch|functions\\.apply_patch)$",
|
|
676
|
+
targetMatchers: { claude: "^(Bash|Monitor|Write|Edit|MultiEdit|NotebookEdit|apply_patch|ApplyPatch|functions\\.apply_patch)$" },
|
|
677
|
+
legacyMatchers: ["^(Bash|Write|Edit|MultiEdit|NotebookEdit|apply_patch|ApplyPatch|functions\\.apply_patch)$"],
|
|
678
|
+
tags: ["workspace", "repos", "structure", "guard", "safety", "orgs", "multi-agent"]
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
name: "protected-delete-guard",
|
|
682
|
+
timeoutSeconds: 10,
|
|
683
|
+
displayName: "Protected Delete Guard",
|
|
684
|
+
description: "Refuses rm, rmdir, unlink and find with a delete action on the protected class (/, the system roots, the home directory, ~/.hasna, ~/.ssh, ~/.aws) and on coding-agent session and history stores; only refuses, never rewrites a command and needs no Trash",
|
|
685
|
+
version: "0.1.0",
|
|
686
|
+
category: "Git Safety",
|
|
687
|
+
event: "PreToolUse",
|
|
688
|
+
matcher: "^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$",
|
|
689
|
+
targetMatchers: { claude: "^(Bash|Monitor|apply_patch|ApplyPatch|functions\\.apply_patch)$" },
|
|
690
|
+
tags: ["rm", "delete", "protected", "session-history", "guard", "safety", "bash"]
|
|
691
|
+
},
|
|
692
|
+
{
|
|
693
|
+
name: "trash-guard",
|
|
694
|
+
displayName: "Trash Guard",
|
|
695
|
+
description: "Rewrites rm issued through Bash into `trash guard`, so the delete lands in a recoverable trash store; refuses the delete when there is nothing to redirect to (trash absent, a delete verb it cannot rewrite, or the protected class: /, ~, ~/.hasna, ~/.ssh, ~/.aws)",
|
|
696
|
+
version: "0.1.2",
|
|
697
|
+
category: "Git Safety",
|
|
698
|
+
event: "PreToolUse",
|
|
699
|
+
matcher: "^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$",
|
|
700
|
+
targetMatchers: { claude: CLAUDE_TRASH_GUARD_MATCHER },
|
|
701
|
+
legacyMatchers: ["^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$"],
|
|
702
|
+
tags: ["rm", "delete", "trash", "recoverable", "guard", "safety", "bash"],
|
|
703
|
+
rewritesInput: true,
|
|
704
|
+
timeoutSeconds: 10
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
name: "checktests",
|
|
708
|
+
displayName: "Check Tests",
|
|
709
|
+
description: "Checks for missing tests after file edits",
|
|
710
|
+
version: "0.1.6",
|
|
711
|
+
category: "Code Quality",
|
|
712
|
+
event: "PostToolUse",
|
|
713
|
+
matcher: "Edit|Write|NotebookEdit",
|
|
714
|
+
tags: ["tests", "coverage", "quality"]
|
|
715
|
+
},
|
|
716
|
+
{
|
|
717
|
+
name: "checklint",
|
|
718
|
+
displayName: "Check Lint",
|
|
719
|
+
description: "Runs linting after file edits and creates tasks for errors",
|
|
720
|
+
version: "0.1.7",
|
|
721
|
+
category: "Code Quality",
|
|
722
|
+
event: "PostToolUse",
|
|
723
|
+
matcher: "Edit|Write|NotebookEdit",
|
|
724
|
+
tags: ["lint", "style", "quality"]
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
name: "checkfiles",
|
|
728
|
+
displayName: "Check Files",
|
|
729
|
+
description: "Runs headless agent to review files and create tasks",
|
|
730
|
+
version: "0.1.4",
|
|
731
|
+
category: "Code Quality",
|
|
732
|
+
event: "PostToolUse",
|
|
733
|
+
matcher: "Edit|Write|NotebookEdit",
|
|
734
|
+
tags: ["review", "files", "quality"]
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
name: "checkbugs",
|
|
738
|
+
displayName: "Check Bugs",
|
|
739
|
+
description: "Checks for bugs via headless agent",
|
|
740
|
+
version: "0.1.6",
|
|
741
|
+
category: "Code Quality",
|
|
742
|
+
event: "PostToolUse",
|
|
743
|
+
matcher: "Edit|Write|NotebookEdit",
|
|
744
|
+
tags: ["bugs", "analysis", "quality"]
|
|
745
|
+
},
|
|
746
|
+
{
|
|
747
|
+
name: "checkdocs",
|
|
748
|
+
displayName: "Check Docs",
|
|
749
|
+
description: "Checks for missing documentation and creates tasks",
|
|
750
|
+
version: "0.2.1",
|
|
751
|
+
category: "Code Quality",
|
|
752
|
+
event: "PostToolUse",
|
|
753
|
+
matcher: "Edit|Write|NotebookEdit",
|
|
754
|
+
tags: ["docs", "documentation", "quality"]
|
|
755
|
+
},
|
|
756
|
+
{
|
|
757
|
+
name: "checktasks",
|
|
758
|
+
displayName: "Check Tasks",
|
|
759
|
+
description: "Validates task completion and tracks progress",
|
|
760
|
+
version: "1.0.8",
|
|
761
|
+
category: "Code Quality",
|
|
762
|
+
event: "PostToolUse",
|
|
763
|
+
matcher: "Edit|Write|NotebookEdit",
|
|
764
|
+
tags: ["tasks", "tracking", "quality"]
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
name: "checksecurity",
|
|
768
|
+
displayName: "Check Security",
|
|
769
|
+
description: "Runs security checks via headless agents",
|
|
770
|
+
version: "0.1.6",
|
|
771
|
+
category: "Security",
|
|
772
|
+
event: "PostToolUse",
|
|
773
|
+
matcher: "Edit|Write|NotebookEdit",
|
|
774
|
+
tags: ["security", "audit", "vulnerabilities"]
|
|
775
|
+
},
|
|
776
|
+
{
|
|
777
|
+
name: "packageage",
|
|
778
|
+
displayName: "Package Age",
|
|
779
|
+
description: "Checks package age before install to prevent typosquatting",
|
|
780
|
+
version: "0.1.1",
|
|
781
|
+
category: "Security",
|
|
782
|
+
event: "PreToolUse",
|
|
783
|
+
matcher: "Bash",
|
|
784
|
+
tags: ["npm", "packages", "typosquatting", "supply-chain"]
|
|
785
|
+
},
|
|
786
|
+
{
|
|
787
|
+
name: "pre-bash",
|
|
788
|
+
displayName: "Pre Bash",
|
|
789
|
+
description: "Codewith Bash gate for staged secrets scans before commit/push and comms rechecks before risky operations",
|
|
790
|
+
version: "0.1.0",
|
|
791
|
+
category: "Security",
|
|
792
|
+
event: "PreToolUse",
|
|
793
|
+
matcher: "Bash",
|
|
794
|
+
tags: ["codewith", "bash", "secrets", "gitleaks", "risky-ops"]
|
|
795
|
+
},
|
|
796
|
+
{
|
|
797
|
+
name: "scanoutput",
|
|
798
|
+
displayName: "Scan Output",
|
|
799
|
+
description: "Scans tool output for credential shapes and warns. Detection only \u2014 the output is already persisted when this runs; it cannot redact or prevent",
|
|
800
|
+
version: "0.1.0",
|
|
801
|
+
category: "Security",
|
|
802
|
+
event: "PostToolUse",
|
|
803
|
+
matcher: "Bash",
|
|
804
|
+
tags: ["security", "credentials", "secrets", "detection", "audit"]
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
name: "signed-link-guard",
|
|
808
|
+
displayName: "Signed Link Guard",
|
|
809
|
+
description: "Refuses gh reads that would print composite GitHub content (bodies, comments, reviews, commit messages, check links and details, raw issue/PR/check API objects) where signed action links appear; bounded scalar projections, diffs, lists and writes pass",
|
|
810
|
+
version: "0.1.0",
|
|
811
|
+
category: "Security",
|
|
812
|
+
event: "PreToolUse",
|
|
813
|
+
matcher: "^(Bash|Monitor)$",
|
|
814
|
+
tags: ["github", "gh", "signed-links", "capabilities", "transcript", "guard", "security"],
|
|
815
|
+
timeoutSeconds: 10
|
|
816
|
+
},
|
|
817
|
+
{
|
|
818
|
+
name: "signed-link-output",
|
|
819
|
+
displayName: "Signed Link Output",
|
|
820
|
+
description: "Claude PostToolUse backstop: replaces capability links in tool output \u2014 signature-class query or fragment parameters, and anchored path-borne provider classes such as the Stripe Connect onboarding link \u2014 with a redaction marker (updatedToolOutput, where the running Claude Code supports it) and tells the model not to repeat or store the link. Every string is walked, so nested metadata such as a browser result's `_meta.browser_use.url` is covered. It runs after the tool, so it cannot undo display or other persistence",
|
|
821
|
+
version: "0.1.1",
|
|
822
|
+
category: "Security",
|
|
823
|
+
event: "PostToolUse",
|
|
824
|
+
matcher: "^(Bash|WebFetch|mcp__.*)$",
|
|
825
|
+
tags: ["github", "signed-links", "capabilities", "redaction", "transcript", "security"],
|
|
826
|
+
timeoutSeconds: 10
|
|
827
|
+
},
|
|
828
|
+
{
|
|
829
|
+
name: "phonenotify",
|
|
830
|
+
displayName: "Phone Notify",
|
|
831
|
+
description: "Sends push notifications to phone via ntfy.sh",
|
|
832
|
+
version: "0.1.0",
|
|
833
|
+
category: "Notifications",
|
|
834
|
+
event: "Stop",
|
|
835
|
+
matcher: "",
|
|
836
|
+
tags: ["notification", "phone", "push", "ntfy"]
|
|
837
|
+
},
|
|
838
|
+
{
|
|
839
|
+
name: "agentmessages",
|
|
840
|
+
displayName: "Agent Messages",
|
|
841
|
+
description: "Inter-agent messaging integration for service-message",
|
|
842
|
+
version: "0.1.0",
|
|
843
|
+
category: "Notifications",
|
|
844
|
+
event: "Stop",
|
|
845
|
+
matcher: "",
|
|
846
|
+
tags: ["messaging", "agents", "inter-agent"]
|
|
847
|
+
},
|
|
848
|
+
{
|
|
849
|
+
name: "contextrefresh",
|
|
850
|
+
displayName: "Context Refresh",
|
|
851
|
+
description: "Re-injects important context every N prompts to prevent drift",
|
|
852
|
+
version: "0.1.0",
|
|
853
|
+
category: "Context Management",
|
|
854
|
+
event: "Notification",
|
|
855
|
+
matcher: "",
|
|
856
|
+
tags: ["context", "memory", "prompts", "refresh"]
|
|
857
|
+
},
|
|
858
|
+
{
|
|
859
|
+
name: "precompact",
|
|
860
|
+
displayName: "Pre-Compact",
|
|
861
|
+
description: "Saves session state before context compaction",
|
|
862
|
+
version: "0.1.0",
|
|
863
|
+
category: "Context Management",
|
|
864
|
+
event: "Notification",
|
|
865
|
+
matcher: "",
|
|
866
|
+
tags: ["context", "compaction", "state", "backup"]
|
|
867
|
+
},
|
|
868
|
+
{
|
|
869
|
+
name: "knowledge-context",
|
|
870
|
+
displayName: "Knowledge Context",
|
|
871
|
+
description: "Injects deterministic Knowledge context packs into Codewith SessionStart, UserPromptSubmit, and SubagentStart",
|
|
872
|
+
version: "0.1.6",
|
|
873
|
+
category: "Context Management",
|
|
874
|
+
event: "SessionStart",
|
|
875
|
+
events: ["SessionStart", "UserPromptSubmit", "SubagentStart"],
|
|
876
|
+
matcher: "",
|
|
877
|
+
tags: ["knowledge", "context", "codewith", "deterministic", "session-start", "prompt", "subagent"]
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
name: "mementos-context",
|
|
881
|
+
displayName: "Mementos Prompt Context",
|
|
882
|
+
description: "Retrieves scoped memories for a user prompt, with optional relevance judgments",
|
|
883
|
+
version: "0.1.0",
|
|
884
|
+
category: "Context Management",
|
|
885
|
+
event: "UserPromptSubmit",
|
|
886
|
+
matcher: "",
|
|
887
|
+
timeoutSeconds: 12,
|
|
888
|
+
tags: ["mementos", "memory", "prompt", "codex", "claude", "codewith", "opt-in"]
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
name: "autoformat",
|
|
892
|
+
displayName: "Auto Format",
|
|
893
|
+
description: "Runs project formatter (Prettier, Biome, Ruff, Black, gofmt) after file edits",
|
|
894
|
+
version: "0.1.0",
|
|
895
|
+
category: "Workflow Automation",
|
|
896
|
+
event: "PostToolUse",
|
|
897
|
+
matcher: "Edit|Write",
|
|
898
|
+
tags: ["format", "prettier", "biome", "ruff", "black", "gofmt", "style"]
|
|
899
|
+
},
|
|
900
|
+
{
|
|
901
|
+
name: "autostage",
|
|
902
|
+
displayName: "Auto Stage",
|
|
903
|
+
description: "Automatically git-stages files after Claude edits them",
|
|
904
|
+
version: "0.1.0",
|
|
905
|
+
category: "Workflow Automation",
|
|
906
|
+
event: "PostToolUse",
|
|
907
|
+
matcher: "Edit|Write",
|
|
908
|
+
tags: ["git", "stage", "add", "auto"]
|
|
909
|
+
},
|
|
910
|
+
{
|
|
911
|
+
name: "tddguard",
|
|
912
|
+
displayName: "TDD Guard",
|
|
913
|
+
description: "Blocks implementation edits unless corresponding test files exist",
|
|
914
|
+
version: "0.1.0",
|
|
915
|
+
category: "Workflow Automation",
|
|
916
|
+
event: "PreToolUse",
|
|
917
|
+
matcher: "Edit|Write",
|
|
918
|
+
tags: ["tdd", "tests", "red-green-refactor", "enforcement"]
|
|
919
|
+
},
|
|
920
|
+
{
|
|
921
|
+
name: "envsetup",
|
|
922
|
+
displayName: "Env Setup",
|
|
923
|
+
description: "Warns when nvm, virtualenv, asdf, or rbenv may need activation before commands",
|
|
924
|
+
version: "0.1.0",
|
|
925
|
+
category: "Environment",
|
|
926
|
+
event: "PreToolUse",
|
|
927
|
+
matcher: "Bash",
|
|
928
|
+
tags: ["nvm", "virtualenv", "asdf", "rbenv", "environment", "python", "node"]
|
|
929
|
+
},
|
|
930
|
+
{
|
|
931
|
+
name: "permissionguard",
|
|
932
|
+
displayName: "Permission Guard",
|
|
933
|
+
description: "Auto-approves safe read-only commands and blocks dangerous operations",
|
|
934
|
+
version: "0.1.0",
|
|
935
|
+
category: "Permissions",
|
|
936
|
+
event: "PreToolUse",
|
|
937
|
+
matcher: "Bash",
|
|
938
|
+
tags: ["permission", "allowlist", "blocklist", "safety", "auto-approve"]
|
|
939
|
+
},
|
|
940
|
+
{
|
|
941
|
+
name: "protectfiles",
|
|
942
|
+
displayName: "Protect Files",
|
|
943
|
+
description: "Blocks access to .env, secrets, SSH keys, and lock files",
|
|
944
|
+
version: "0.1.0",
|
|
945
|
+
category: "Permissions",
|
|
946
|
+
event: "PreToolUse",
|
|
947
|
+
matcher: "Edit|Write|Read|Bash",
|
|
948
|
+
tags: ["security", "env", "secrets", "keys", "lock-files", "protect"]
|
|
949
|
+
},
|
|
950
|
+
{
|
|
951
|
+
name: "promptguard",
|
|
952
|
+
displayName: "Prompt Guard",
|
|
953
|
+
description: "Blocks prompt injection attempts and credential access requests",
|
|
954
|
+
version: "0.1.0",
|
|
955
|
+
category: "Permissions",
|
|
956
|
+
event: "PreToolUse",
|
|
957
|
+
matcher: "",
|
|
958
|
+
tags: ["prompt", "injection", "security", "validation", "guard"]
|
|
959
|
+
},
|
|
960
|
+
{
|
|
961
|
+
name: "prompt-guard",
|
|
962
|
+
displayName: "Prompt Guard (Codewith)",
|
|
963
|
+
description: "Codewith UserPromptSubmit guard for obvious pasted prompt-injection and fake policy/freeze instructions",
|
|
964
|
+
version: "0.1.0",
|
|
965
|
+
category: "Permissions",
|
|
966
|
+
event: "UserPromptSubmit",
|
|
967
|
+
matcher: "",
|
|
968
|
+
tags: ["codewith", "prompt", "injection", "policy", "freeze"]
|
|
969
|
+
},
|
|
970
|
+
{
|
|
971
|
+
name: "desktopnotify",
|
|
972
|
+
displayName: "Desktop Notify",
|
|
973
|
+
description: "Sends native desktop notifications via osascript (macOS) or notify-send (Linux)",
|
|
974
|
+
version: "0.1.0",
|
|
975
|
+
category: "Notifications",
|
|
976
|
+
event: "Stop",
|
|
977
|
+
matcher: "",
|
|
978
|
+
tags: ["notification", "desktop", "macos", "linux", "native"]
|
|
979
|
+
},
|
|
980
|
+
{
|
|
981
|
+
name: "slacknotify",
|
|
982
|
+
displayName: "Slack Notify",
|
|
983
|
+
description: "Sends Slack webhook notifications when Claude finishes",
|
|
984
|
+
version: "0.1.0",
|
|
985
|
+
category: "Notifications",
|
|
986
|
+
event: "Stop",
|
|
987
|
+
matcher: "",
|
|
988
|
+
tags: ["notification", "slack", "webhook", "team"]
|
|
989
|
+
},
|
|
990
|
+
{
|
|
991
|
+
name: "soundnotify",
|
|
992
|
+
displayName: "Sound Notify",
|
|
993
|
+
description: "Plays a system sound when Claude finishes (macOS/Linux)",
|
|
994
|
+
version: "0.1.0",
|
|
995
|
+
category: "Notifications",
|
|
996
|
+
event: "Stop",
|
|
997
|
+
matcher: "",
|
|
998
|
+
tags: ["notification", "sound", "audio", "alert"]
|
|
999
|
+
},
|
|
1000
|
+
{
|
|
1001
|
+
name: "sessionlog",
|
|
1002
|
+
displayName: "Session Log",
|
|
1003
|
+
description: `Logs every tool call to SQLite (${getReportedDbPath()})`,
|
|
1004
|
+
version: "0.1.0",
|
|
1005
|
+
category: "Observability",
|
|
1006
|
+
event: "PostToolUse",
|
|
1007
|
+
matcher: "",
|
|
1008
|
+
tags: ["logging", "audit", "session", "history", "jsonl"]
|
|
1009
|
+
},
|
|
1010
|
+
{
|
|
1011
|
+
name: "commandlog",
|
|
1012
|
+
displayName: "Command Log",
|
|
1013
|
+
description: `Logs every Bash command to SQLite (${getReportedDbPath()})`,
|
|
1014
|
+
version: "0.1.0",
|
|
1015
|
+
category: "Observability",
|
|
1016
|
+
event: "PostToolUse",
|
|
1017
|
+
matcher: "Bash",
|
|
1018
|
+
tags: ["logging", "bash", "commands", "audit"]
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
name: "costwatch",
|
|
1022
|
+
displayName: "Cost Watch",
|
|
1023
|
+
description: "Estimates session token usage, persists cost history to SQLite, and warns on budget overrun",
|
|
1024
|
+
version: "0.1.0",
|
|
1025
|
+
category: "Observability",
|
|
1026
|
+
event: "Stop",
|
|
1027
|
+
matcher: "",
|
|
1028
|
+
tags: ["cost", "tokens", "budget", "usage", "monitoring"]
|
|
1029
|
+
},
|
|
1030
|
+
{
|
|
1031
|
+
name: "errornotify",
|
|
1032
|
+
displayName: "Error Notify",
|
|
1033
|
+
description: `Detects tool failures and logs errors to SQLite (${getReportedDbPath()})`,
|
|
1034
|
+
version: "0.1.0",
|
|
1035
|
+
category: "Observability",
|
|
1036
|
+
event: "PostToolUse",
|
|
1037
|
+
matcher: "",
|
|
1038
|
+
tags: ["errors", "failures", "logging", "debugging"]
|
|
1039
|
+
},
|
|
1040
|
+
{
|
|
1041
|
+
name: "spiral-detector",
|
|
1042
|
+
displayName: "Spiral Detector",
|
|
1043
|
+
description: "Interrupts sessions after five consecutive identical command failures",
|
|
1044
|
+
version: "0.1.0",
|
|
1045
|
+
category: "Observability",
|
|
1046
|
+
event: "PostToolUse",
|
|
1047
|
+
matcher: "",
|
|
1048
|
+
tags: ["spiral", "failures", "retries", "safety", "interrupt"]
|
|
1049
|
+
},
|
|
1050
|
+
{
|
|
1051
|
+
name: "scratch-lifecycle",
|
|
1052
|
+
bundledEntry: "bin/hooks/scratch-lifecycle.js",
|
|
1053
|
+
displayName: "Scratch Lifecycle",
|
|
1054
|
+
description: "Records owner, purpose and disposal for each session scratch tree in its Scratchpad manifest, and the close time at session end",
|
|
1055
|
+
version: "0.1.0",
|
|
1056
|
+
category: "Observability",
|
|
1057
|
+
event: "SessionStart",
|
|
1058
|
+
events: ["SessionStart", "SessionEnd"],
|
|
1059
|
+
nativeTargetDispatch: true,
|
|
1060
|
+
timeoutSeconds: 15,
|
|
1061
|
+
matcher: "",
|
|
1062
|
+
tags: ["scratch", "lifecycle", "session", "census", "retention"]
|
|
1063
|
+
},
|
|
1064
|
+
{
|
|
1065
|
+
name: "stylescheck",
|
|
1066
|
+
displayName: "Styles Check",
|
|
1067
|
+
description: "Blocks frontend files with design anti-patterns: hardcoded colors, magic font sizes, inline styles",
|
|
1068
|
+
version: "0.1.0",
|
|
1069
|
+
category: "Code Quality",
|
|
1070
|
+
event: "PreToolUse",
|
|
1071
|
+
matcher: "Write|Edit",
|
|
1072
|
+
tags: ["design", "styles", "frontend", "css", "tailwind", "design-system", "anti-patterns"]
|
|
1073
|
+
},
|
|
1074
|
+
{
|
|
1075
|
+
name: "taskgate",
|
|
1076
|
+
displayName: "Task Gate",
|
|
1077
|
+
description: "Validates task completion criteria before allowing tasks to be marked done",
|
|
1078
|
+
version: "0.1.0",
|
|
1079
|
+
category: "Agent Teams",
|
|
1080
|
+
event: "PostToolUse",
|
|
1081
|
+
matcher: "",
|
|
1082
|
+
tags: ["tasks", "completion", "gate", "quality", "agent-teams"]
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
name: "session-start",
|
|
1086
|
+
displayName: "Session Start",
|
|
1087
|
+
description: "Codewith SessionStart digest for blockers, announcements, identity registration, and heartbeat context",
|
|
1088
|
+
version: "0.1.0",
|
|
1089
|
+
category: "Agent Teams",
|
|
1090
|
+
event: "SessionStart",
|
|
1091
|
+
matcher: "",
|
|
1092
|
+
tags: ["codewith", "session", "context", "conversations", "heartbeat"]
|
|
1093
|
+
},
|
|
1094
|
+
{
|
|
1095
|
+
name: "stop-review",
|
|
1096
|
+
bundledEntry: "bin/hooks/stop-review.js",
|
|
1097
|
+
displayName: "Stop Review",
|
|
1098
|
+
description: "Reviews turn completion against the latest user request and active goal",
|
|
1099
|
+
version: "0.1.1",
|
|
1100
|
+
category: "Agent Teams",
|
|
1101
|
+
event: "Stop",
|
|
1102
|
+
events: ["Stop"],
|
|
1103
|
+
nativeTargetDispatch: true,
|
|
1104
|
+
timeoutSeconds: 20,
|
|
1105
|
+
matcher: "",
|
|
1106
|
+
tags: ["stop", "goals", "continuity", "review"]
|
|
1107
|
+
},
|
|
1108
|
+
{
|
|
1109
|
+
name: "stop-sync",
|
|
1110
|
+
displayName: "Stop Sync",
|
|
1111
|
+
description: "Codewith Stop turn-end heartbeat and best-effort task evidence helper",
|
|
1112
|
+
version: "0.1.0",
|
|
1113
|
+
category: "Agent Teams",
|
|
1114
|
+
event: "Stop",
|
|
1115
|
+
matcher: "",
|
|
1116
|
+
tags: ["codewith", "stop", "heartbeat", "todos", "turn-end"]
|
|
1117
|
+
},
|
|
1118
|
+
{
|
|
1119
|
+
name: "typecheck-gate",
|
|
1120
|
+
displayName: "Typecheck Gate",
|
|
1121
|
+
description: "Runs TypeScript type checking on Stop and blocks if type errors are found",
|
|
1122
|
+
version: "0.1.0",
|
|
1123
|
+
category: "Code Quality",
|
|
1124
|
+
event: "Stop",
|
|
1125
|
+
matcher: "",
|
|
1126
|
+
tags: ["typescript", "typecheck", "types", "quality", "gate"]
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
name: "affected-tests",
|
|
1130
|
+
displayName: "Affected Tests",
|
|
1131
|
+
description: "Maps edited files to their test files and runs them automatically after edits",
|
|
1132
|
+
version: "0.1.0",
|
|
1133
|
+
category: "Code Quality",
|
|
1134
|
+
event: "PostToolUse",
|
|
1135
|
+
matcher: "Edit|Write|NotebookEdit",
|
|
1136
|
+
tags: ["tests", "test-runner", "affected", "quality"]
|
|
1137
|
+
},
|
|
1138
|
+
{
|
|
1139
|
+
name: "conflict-detect",
|
|
1140
|
+
displayName: "Conflict Detect",
|
|
1141
|
+
description: "Blocks edits on files with unresolved git merge conflict markers",
|
|
1142
|
+
version: "0.1.0",
|
|
1143
|
+
category: "Git Safety",
|
|
1144
|
+
event: "PreToolUse",
|
|
1145
|
+
matcher: "Edit|Write",
|
|
1146
|
+
tags: ["git", "conflicts", "merge", "safety"]
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
name: "failure-to-task",
|
|
1150
|
+
displayName: "Failure to Task",
|
|
1151
|
+
description: "Creates a todo task automatically when test or build commands fail",
|
|
1152
|
+
version: "0.1.0",
|
|
1153
|
+
category: "Workflow Automation",
|
|
1154
|
+
event: "PostToolUse",
|
|
1155
|
+
matcher: "Bash",
|
|
1156
|
+
tags: ["failures", "tasks", "tests", "build", "automation"]
|
|
1157
|
+
},
|
|
1158
|
+
{
|
|
1159
|
+
name: "job-folder-guard",
|
|
1160
|
+
displayName: "Job Folder Guard",
|
|
1161
|
+
description: "Adds a notice to the model's context when a Write, Edit, MultiEdit, NotebookEdit or Bash command writes to or uses a harness job folder (<path>/jobs/<id>/tmp/, a Claude Code or Switcher job folder), naming the session's Scratchpad folder instead; never blocks and never changes the permission flow",
|
|
1162
|
+
version: "0.1.0",
|
|
1163
|
+
category: "Workflow Automation",
|
|
1164
|
+
event: "PreToolUse",
|
|
1165
|
+
matcher: "^(Write|Edit|MultiEdit|NotebookEdit|Bash)$",
|
|
1166
|
+
tags: ["scratch", "scratchpad", "jobs", "switcher", "notice"],
|
|
1167
|
+
timeoutSeconds: 5
|
|
1168
|
+
},
|
|
1169
|
+
{
|
|
1170
|
+
name: "filelock",
|
|
1171
|
+
displayName: "File Lock",
|
|
1172
|
+
description: "Auto-checks file locks before edits to prevent multi-agent conflicts",
|
|
1173
|
+
version: "0.1.0",
|
|
1174
|
+
category: "Agent Teams",
|
|
1175
|
+
event: "PreToolUse",
|
|
1176
|
+
matcher: "Edit|Write|NotebookEdit",
|
|
1177
|
+
tags: ["locking", "coordination", "multi-agent", "conflict"]
|
|
1178
|
+
},
|
|
1179
|
+
{
|
|
1180
|
+
name: "announce-start",
|
|
1181
|
+
displayName: "Announce Start",
|
|
1182
|
+
description: "On SessionStart, auto-registers agent, reads messages, and announces to space",
|
|
1183
|
+
version: "0.2.0",
|
|
1184
|
+
category: "Agent Teams",
|
|
1185
|
+
event: "SessionStart",
|
|
1186
|
+
matcher: "",
|
|
1187
|
+
tags: ["announcement", "start", "register", "messages", "agent-teams"]
|
|
1188
|
+
},
|
|
1189
|
+
{
|
|
1190
|
+
name: "announce-stop",
|
|
1191
|
+
displayName: "Announce Stop",
|
|
1192
|
+
description: "On Stop, releases file locks, posts session summary, and updates task statuses",
|
|
1193
|
+
version: "0.1.0",
|
|
1194
|
+
category: "Agent Teams",
|
|
1195
|
+
event: "Stop",
|
|
1196
|
+
matcher: "",
|
|
1197
|
+
tags: ["announcement", "stop", "locks", "summary", "agent-teams"]
|
|
1198
|
+
},
|
|
1199
|
+
{
|
|
1200
|
+
name: "dm-inject",
|
|
1201
|
+
displayName: "DM Inject",
|
|
1202
|
+
description: "Injects unread direct messages into agent context on Notification events",
|
|
1203
|
+
version: "0.1.0",
|
|
1204
|
+
category: "Agent Teams",
|
|
1205
|
+
event: "Notification",
|
|
1206
|
+
matcher: "",
|
|
1207
|
+
tags: ["messages", "dm", "context", "inject", "agent-teams"]
|
|
1208
|
+
},
|
|
1209
|
+
{
|
|
1210
|
+
name: "fleet-catchup",
|
|
1211
|
+
displayName: "Fleet Catchup",
|
|
1212
|
+
description: "On SessionStart, injects unread blockers, channel notifications, and the announcements digest into context (deterministic CLI reads, fail-open)",
|
|
1213
|
+
version: "0.1.0",
|
|
1214
|
+
category: "Agent Teams",
|
|
1215
|
+
event: "SessionStart",
|
|
1216
|
+
matcher: "",
|
|
1217
|
+
tags: ["fleet", "catchup", "blockers", "announcements", "context", "agent-teams"]
|
|
1218
|
+
},
|
|
1219
|
+
{
|
|
1220
|
+
name: "agent-rules-version-check",
|
|
1221
|
+
displayName: "Agent Rules Version Check",
|
|
1222
|
+
description: "On SessionStart, compares the rendered hasna:agent-operating-rules sentinel version against configs state and warns on mismatch",
|
|
1223
|
+
version: "0.1.0",
|
|
1224
|
+
category: "Agent Teams",
|
|
1225
|
+
event: "SessionStart",
|
|
1226
|
+
matcher: "",
|
|
1227
|
+
tags: ["fleet", "rules", "version", "sentinel", "configs", "drift", "agent-teams"]
|
|
1228
|
+
},
|
|
1229
|
+
{
|
|
1230
|
+
name: "fleet-blockers-gate",
|
|
1231
|
+
displayName: "Fleet Blockers Gate",
|
|
1232
|
+
description: "Before tool calls, blocks mutating tools while an unread [FREEZE] blocker is active (TTL-cached conversations check, fail-open <500ms)",
|
|
1233
|
+
version: "0.1.0",
|
|
1234
|
+
category: "Agent Teams",
|
|
1235
|
+
event: "PreToolUse",
|
|
1236
|
+
matcher: "",
|
|
1237
|
+
tags: ["fleet", "freeze", "blockers", "gate", "safety", "agent-teams"]
|
|
1238
|
+
}
|
|
1239
|
+
];
|
|
1240
|
+
});
|
|
1241
|
+
|
|
584
1242
|
// node_modules/zod/v3/helpers/util.js
|
|
585
1243
|
var util, objectUtil, ZodParsedType, getParsedType = (data) => {
|
|
586
1244
|
const t = typeof data;
|
|
@@ -4637,10 +5295,11 @@ __export(exports_manifest, {
|
|
|
4637
5295
|
customHookDir: () => customHookDir,
|
|
4638
5296
|
assertContained: () => assertContained,
|
|
4639
5297
|
ScriptContainmentError: () => ScriptContainmentError,
|
|
5298
|
+
INSTALL_RECORD_FILE: () => INSTALL_RECORD_FILE,
|
|
4640
5299
|
HookIdentityError: () => HookIdentityError,
|
|
4641
5300
|
HOOK_NAME_RE: () => HOOK_NAME_RE
|
|
4642
5301
|
});
|
|
4643
|
-
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync2, readdirSync as readdirSync2, realpathSync, writeFileSync } from "fs";
|
|
5302
|
+
import { existsSync as existsSync4, mkdirSync as mkdirSync2, readFileSync as readFileSync2, readdirSync as readdirSync2, realpathSync, rmSync, writeFileSync } from "fs";
|
|
4644
5303
|
import { basename, dirname, isAbsolute, join as join5, normalize, resolve as resolve2, sep } from "path";
|
|
4645
5304
|
function parseManifest(json) {
|
|
4646
5305
|
const parsed = JSON.parse(json);
|
|
@@ -4767,6 +5426,7 @@ function writeCustomHook(name, manifest, scriptContent, scriptRelPath) {
|
|
|
4767
5426
|
const scriptDir = dirname(scriptPath);
|
|
4768
5427
|
if (scriptDir !== dir)
|
|
4769
5428
|
mkdirSync2(scriptDir, { recursive: true });
|
|
5429
|
+
rmSync(join5(dir, INSTALL_RECORD_FILE), { force: true });
|
|
4770
5430
|
writeFileSync(scriptPath, scriptContent, "utf-8");
|
|
4771
5431
|
writeFileSync(join5(dir, "manifest.json"), JSON.stringify(manifest, null, 2) + `
|
|
4772
5432
|
`, "utf-8");
|
|
@@ -4779,7 +5439,7 @@ function readdirSafe(dir) {
|
|
|
4779
5439
|
return [];
|
|
4780
5440
|
}
|
|
4781
5441
|
}
|
|
4782
|
-
var HOOK_NAME_RE, manifestSchema, ScriptContainmentError, HookIdentityError;
|
|
5442
|
+
var HOOK_NAME_RE, INSTALL_RECORD_FILE = ".hooks-install.json", manifestSchema, ScriptContainmentError, HookIdentityError;
|
|
4783
5443
|
var init_manifest = __esm(() => {
|
|
4784
5444
|
init_zod();
|
|
4785
5445
|
init_config();
|
|
@@ -4812,6 +5472,105 @@ var init_manifest = __esm(() => {
|
|
|
4812
5472
|
};
|
|
4813
5473
|
});
|
|
4814
5474
|
|
|
5475
|
+
// src/lib/resolve.ts
|
|
5476
|
+
import { dirname as dirname2, join as join6 } from "path";
|
|
5477
|
+
import { existsSync as existsSync5 } from "fs";
|
|
5478
|
+
import { fileURLToPath } from "url";
|
|
5479
|
+
function resolveBundledHooksDir(moduleDir = dirname2(fileURLToPath(import.meta.url))) {
|
|
5480
|
+
const sourceLayout = join6(moduleDir, "..", "..", "hooks");
|
|
5481
|
+
if (existsSync5(join6(sourceLayout, "hook-gitguard")))
|
|
5482
|
+
return sourceLayout;
|
|
5483
|
+
return join6(moduleDir, "..", "hooks");
|
|
5484
|
+
}
|
|
5485
|
+
function resolveHookDir(name) {
|
|
5486
|
+
const custom2 = readCustomManifest(name);
|
|
5487
|
+
if (custom2)
|
|
5488
|
+
return customHookDir(name);
|
|
5489
|
+
const meta = getHook(shortManifestName(name));
|
|
5490
|
+
if (!meta)
|
|
5491
|
+
return;
|
|
5492
|
+
const short = shortManifestName(name);
|
|
5493
|
+
const bundledBase = resolveBundledHooksDir();
|
|
5494
|
+
const direct = join6(bundledBase, short);
|
|
5495
|
+
if (existsSync5(direct))
|
|
5496
|
+
return direct;
|
|
5497
|
+
const prefixed = join6(bundledBase, `hook-${short}`);
|
|
5498
|
+
return existsSync5(prefixed) ? prefixed : undefined;
|
|
5499
|
+
}
|
|
5500
|
+
function resolveScriptPath(name) {
|
|
5501
|
+
const custom2 = readCustomManifest(name);
|
|
5502
|
+
if (custom2)
|
|
5503
|
+
return custom2.scriptPath;
|
|
5504
|
+
const meta = getHook(shortManifestName(name));
|
|
5505
|
+
if (meta?.bundledEntry) {
|
|
5506
|
+
if (!/^bin\/hooks\/[a-z0-9-]+\.js$/.test(meta.bundledEntry))
|
|
5507
|
+
return;
|
|
5508
|
+
const bundle = join6(resolveBundledHooksDir(), "..", meta.bundledEntry);
|
|
5509
|
+
return existsSync5(bundle) ? bundle : undefined;
|
|
5510
|
+
}
|
|
5511
|
+
const dir = resolveHookDir(name);
|
|
5512
|
+
if (!dir)
|
|
5513
|
+
return;
|
|
5514
|
+
const script = join6(dir, "src", "hook.ts");
|
|
5515
|
+
return existsSync5(script) ? script : undefined;
|
|
5516
|
+
}
|
|
5517
|
+
function resolveHookMeta(name) {
|
|
5518
|
+
const custom2 = readCustomManifest(name);
|
|
5519
|
+
if (custom2) {
|
|
5520
|
+
const { manifest } = custom2;
|
|
5521
|
+
return {
|
|
5522
|
+
name: shortManifestName(manifest.name),
|
|
5523
|
+
displayName: manifest.description ? manifest.name : manifest.name,
|
|
5524
|
+
description: manifest.description ?? "Custom hook",
|
|
5525
|
+
version: manifest.version,
|
|
5526
|
+
category: "Workflow Automation",
|
|
5527
|
+
event: manifest.events[0] ?? "PostToolUse",
|
|
5528
|
+
events: manifest.events,
|
|
5529
|
+
matcher: "",
|
|
5530
|
+
tags: ["custom"],
|
|
5531
|
+
nativeTargetDispatch: manifest.nativeTargetDispatch,
|
|
5532
|
+
requiresFinalMessage: manifest.requires_final_message,
|
|
5533
|
+
requiresBlock: manifest.requires_block,
|
|
5534
|
+
timeoutSeconds: manifest.timeout_ms === undefined ? undefined : Math.ceil(manifest.timeout_ms / 1000)
|
|
5535
|
+
};
|
|
5536
|
+
}
|
|
5537
|
+
return getHook(shortManifestName(name));
|
|
5538
|
+
}
|
|
5539
|
+
function resolveHook(name) {
|
|
5540
|
+
const custom2 = readCustomManifest(name);
|
|
5541
|
+
if (custom2) {
|
|
5542
|
+
const meta2 = resolveHookMeta(name);
|
|
5543
|
+
return {
|
|
5544
|
+
name: shortManifestName(custom2.manifest.name),
|
|
5545
|
+
source: "custom",
|
|
5546
|
+
version: custom2.manifest.version,
|
|
5547
|
+
events: custom2.manifest.events,
|
|
5548
|
+
description: custom2.manifest.description ?? "Custom hook",
|
|
5549
|
+
scriptPath: custom2.scriptPath,
|
|
5550
|
+
meta: meta2,
|
|
5551
|
+
timeoutMs: custom2.manifest.timeout_ms ?? null
|
|
5552
|
+
};
|
|
5553
|
+
}
|
|
5554
|
+
const meta = getHook(shortManifestName(name));
|
|
5555
|
+
const scriptPath = resolveScriptPath(name);
|
|
5556
|
+
if (!meta || !scriptPath)
|
|
5557
|
+
return;
|
|
5558
|
+
return {
|
|
5559
|
+
name: shortManifestName(name),
|
|
5560
|
+
source: "bundled",
|
|
5561
|
+
version: meta.version,
|
|
5562
|
+
events: meta.events && meta.events.length > 0 ? meta.events : [meta.event],
|
|
5563
|
+
description: meta.description,
|
|
5564
|
+
scriptPath,
|
|
5565
|
+
meta,
|
|
5566
|
+
timeoutMs: null
|
|
5567
|
+
};
|
|
5568
|
+
}
|
|
5569
|
+
var init_resolve = __esm(() => {
|
|
5570
|
+
init_registry();
|
|
5571
|
+
init_manifest();
|
|
5572
|
+
});
|
|
5573
|
+
|
|
4815
5574
|
// src/lib/registry-artifact.ts
|
|
4816
5575
|
import { createHash as createHash3 } from "crypto";
|
|
4817
5576
|
function canonicalJson(value) {
|
|
@@ -4852,6 +5611,382 @@ var init_registry_artifact = __esm(() => {
|
|
|
4852
5611
|
REGISTRY_MAX_BYTES = 2 * 1024 * 1024;
|
|
4853
5612
|
});
|
|
4854
5613
|
|
|
5614
|
+
// src/lib/release-manifest.ts
|
|
5615
|
+
import { createHash as createHash4, randomBytes } from "crypto";
|
|
5616
|
+
import { existsSync as existsSync8, lstatSync as lstatSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync5, realpathSync as realpathSync4, renameSync, writeFileSync as writeFileSync2 } from "fs";
|
|
5617
|
+
import { basename as basename2, dirname as dirname6, join as join10, relative, resolve as resolve4, sep as sep2 } from "path";
|
|
5618
|
+
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
5619
|
+
function sha256(bytes) {
|
|
5620
|
+
return createHash4("sha256").update(bytes).digest("hex");
|
|
5621
|
+
}
|
|
5622
|
+
function isWithin2(child, parent) {
|
|
5623
|
+
return child === parent || child.startsWith(parent + sep2);
|
|
5624
|
+
}
|
|
5625
|
+
function parseReleaseManifest(raw, path) {
|
|
5626
|
+
let parsed;
|
|
5627
|
+
try {
|
|
5628
|
+
parsed = JSON.parse(raw);
|
|
5629
|
+
} catch {
|
|
5630
|
+
throw new ReleaseManifestError(`release manifest (${path}) is not valid JSON`);
|
|
5631
|
+
}
|
|
5632
|
+
const value = parsed;
|
|
5633
|
+
if (value === null || typeof value !== "object" || value.schema !== RELEASE_MANIFEST_SCHEMA || typeof value.package !== "string" || typeof value.version !== "string" || value.hooks === null || typeof value.hooks !== "object" || Array.isArray(value.hooks)) {
|
|
5634
|
+
throw new ReleaseManifestError(`release manifest (${path}) is malformed`);
|
|
5635
|
+
}
|
|
5636
|
+
for (const [name, entry] of Object.entries(value.hooks)) {
|
|
5637
|
+
if (entry === null || typeof entry !== "object" || typeof entry.version !== "string" || typeof entry.script !== "string" || typeof entry.sha256 !== "string" || !/^[0-9a-f]{64}$/.test(entry.sha256)) {
|
|
5638
|
+
throw new ReleaseManifestError(`release manifest (${path}) has a malformed entry for '${name}'`);
|
|
5639
|
+
}
|
|
5640
|
+
}
|
|
5641
|
+
return value;
|
|
5642
|
+
}
|
|
5643
|
+
function releaseRootOf(moduleDir = dirname6(fileURLToPath2(import.meta.url))) {
|
|
5644
|
+
for (let dir = resolve4(moduleDir);; dir = dirname6(dir)) {
|
|
5645
|
+
const name = basename2(dir);
|
|
5646
|
+
if (name === "bin" || name === "dist") {
|
|
5647
|
+
const root = dirname6(dir);
|
|
5648
|
+
if (existsSync8(join10(root, "package.json")) && existsSync8(join10(root, "hooks")))
|
|
5649
|
+
return root;
|
|
5650
|
+
}
|
|
5651
|
+
if (dirname6(dir) === dir)
|
|
5652
|
+
break;
|
|
5653
|
+
}
|
|
5654
|
+
return null;
|
|
5655
|
+
}
|
|
5656
|
+
function loadReleaseAt(root) {
|
|
5657
|
+
const path = join10(root, RELEASE_MANIFEST_RELATIVE_PATH);
|
|
5658
|
+
let raw;
|
|
5659
|
+
try {
|
|
5660
|
+
if (!lstatSync3(path).isFile())
|
|
5661
|
+
throw new ReleaseManifestError(`release manifest (${path}) is not a regular file`);
|
|
5662
|
+
raw = readFileSync5(path);
|
|
5663
|
+
} catch (error) {
|
|
5664
|
+
if (error.code === "ENOENT")
|
|
5665
|
+
return null;
|
|
5666
|
+
throw error instanceof ReleaseManifestError ? error : new ReleaseManifestError(`release manifest (${path}) could not be read`);
|
|
5667
|
+
}
|
|
5668
|
+
return { root: realpathSync4(root), path, sha256: sha256(raw), manifest: parseReleaseManifest(raw.toString("utf8"), path) };
|
|
5669
|
+
}
|
|
5670
|
+
function currentRelease() {
|
|
5671
|
+
if (override !== undefined)
|
|
5672
|
+
return override;
|
|
5673
|
+
const root = releaseRootOf();
|
|
5674
|
+
return root ? loadReleaseAt(root) : null;
|
|
5675
|
+
}
|
|
5676
|
+
function anchorsDir() {
|
|
5677
|
+
return join10(getHooksDataDir(), "release-anchors");
|
|
5678
|
+
}
|
|
5679
|
+
function anchorPathFor(release) {
|
|
5680
|
+
return join10(anchorsDir(), `${sha256(release.root)}.json`);
|
|
5681
|
+
}
|
|
5682
|
+
function anchorStateOf(release) {
|
|
5683
|
+
const path = anchorPathFor(release);
|
|
5684
|
+
let raw;
|
|
5685
|
+
try {
|
|
5686
|
+
if (!lstatSync3(path).isFile())
|
|
5687
|
+
return { state: "invalid", path };
|
|
5688
|
+
raw = readFileSync5(path, "utf8");
|
|
5689
|
+
} catch (error) {
|
|
5690
|
+
if (error.code === "ENOENT")
|
|
5691
|
+
return { state: "absent", path };
|
|
5692
|
+
return { state: "invalid", path };
|
|
5693
|
+
}
|
|
5694
|
+
let anchor;
|
|
5695
|
+
try {
|
|
5696
|
+
anchor = JSON.parse(raw);
|
|
5697
|
+
} catch {
|
|
5698
|
+
return { state: "invalid", path };
|
|
5699
|
+
}
|
|
5700
|
+
if (anchor === null || typeof anchor !== "object" || anchor.schema !== 1 || anchor.package_root !== release.root || typeof anchor.manifest_sha256 !== "string" || !/^[0-9a-f]{64}$/.test(anchor.manifest_sha256)) {
|
|
5701
|
+
return { state: "invalid", path };
|
|
5702
|
+
}
|
|
5703
|
+
if (anchor.manifest_sha256 !== release.sha256) {
|
|
5704
|
+
return { state: "mismatch", path, expected: anchor.manifest_sha256, actual: release.sha256 };
|
|
5705
|
+
}
|
|
5706
|
+
return { state: "match", path, anchor };
|
|
5707
|
+
}
|
|
5708
|
+
function releaseTrustFor(name, actual, scriptPath) {
|
|
5709
|
+
let release;
|
|
5710
|
+
try {
|
|
5711
|
+
release = currentRelease();
|
|
5712
|
+
} catch (error) {
|
|
5713
|
+
if (!(error instanceof ReleaseManifestError))
|
|
5714
|
+
throw error;
|
|
5715
|
+
return { governed: true, ok: false, release: "unreadable", expected: "release-manifest-invalid", reason: "manifest" };
|
|
5716
|
+
}
|
|
5717
|
+
if (!release)
|
|
5718
|
+
return { governed: false };
|
|
5719
|
+
const label = `${release.manifest.package}@${release.manifest.version}`;
|
|
5720
|
+
if (scriptPath !== undefined) {
|
|
5721
|
+
let real;
|
|
5722
|
+
try {
|
|
5723
|
+
real = realpathSync4(scriptPath);
|
|
5724
|
+
} catch {
|
|
5725
|
+
real = resolve4(scriptPath);
|
|
5726
|
+
}
|
|
5727
|
+
if (!isWithin2(real, release.root))
|
|
5728
|
+
return { governed: false };
|
|
5729
|
+
const entry2 = release.manifest.hooks[name];
|
|
5730
|
+
if (entry2 && relative(release.root, real).split(sep2).join("/") !== entry2.script) {
|
|
5731
|
+
return { governed: true, ok: false, release: label, expected: "release-manifest-script-mismatch", reason: "manifest" };
|
|
5732
|
+
}
|
|
5733
|
+
}
|
|
5734
|
+
const entry = release.manifest.hooks[name];
|
|
5735
|
+
if (!entry)
|
|
5736
|
+
return { governed: true, ok: false, release: label, expected: "release-manifest-entry-missing", reason: "unlisted" };
|
|
5737
|
+
const anchor = anchorStateOf(release);
|
|
5738
|
+
if (anchor.state === "mismatch" || anchor.state === "invalid") {
|
|
5739
|
+
return { governed: true, ok: false, release: label, expected: "release-manifest-anchor-mismatch", reason: "anchor" };
|
|
5740
|
+
}
|
|
5741
|
+
if (entry.sha256 !== actual)
|
|
5742
|
+
return { governed: true, ok: false, release: label, expected: entry.sha256, reason: "content" };
|
|
5743
|
+
return { governed: true, ok: true, release: label, expected: entry.sha256, anchored: anchor.state === "match" };
|
|
5744
|
+
}
|
|
5745
|
+
var RELEASE_MANIFEST_SCHEMA = 1, RELEASE_MANIFEST_RELATIVE_PATH = "bin/release-manifest.json", ReleaseManifestError, override;
|
|
5746
|
+
var init_release_manifest = __esm(() => {
|
|
5747
|
+
init_config();
|
|
5748
|
+
init_registry();
|
|
5749
|
+
ReleaseManifestError = class ReleaseManifestError extends Error {
|
|
5750
|
+
constructor(message) {
|
|
5751
|
+
super(message);
|
|
5752
|
+
this.name = "ReleaseManifestError";
|
|
5753
|
+
}
|
|
5754
|
+
};
|
|
5755
|
+
});
|
|
5756
|
+
|
|
5757
|
+
// src/lib/install-record.ts
|
|
5758
|
+
var exports_install_record = {};
|
|
5759
|
+
__export(exports_install_record, {
|
|
5760
|
+
withStableInstall: () => withStableInstall,
|
|
5761
|
+
readInstallRecord: () => readInstallRecord,
|
|
5762
|
+
inspectInstall: () => inspectInstall,
|
|
5763
|
+
finishInstall: () => finishInstall,
|
|
5764
|
+
commitInstall: () => commitInstall,
|
|
5765
|
+
InstallRecordError: () => InstallRecordError,
|
|
5766
|
+
INSTALL_RECORD_SCHEMA: () => INSTALL_RECORD_SCHEMA,
|
|
5767
|
+
INSTALL_RECORD_FILE: () => INSTALL_RECORD_FILE
|
|
5768
|
+
});
|
|
5769
|
+
import { createHash as createHash5, randomBytes as randomBytes2 } from "crypto";
|
|
5770
|
+
import { closeSync as closeSync3, fsyncSync, lstatSync as lstatSync4, mkdirSync as mkdirSync4, openSync as openSync3, readFileSync as readFileSync6, renameSync as renameSync2, rmSync as rmSync2, writeSync } from "fs";
|
|
5771
|
+
import { dirname as dirname7, isAbsolute as isAbsolute4, join as join11, resolve as resolve5, sep as sep3 } from "path";
|
|
5772
|
+
function sha2562(bytes) {
|
|
5773
|
+
return createHash5("sha256").update(bytes).digest("hex");
|
|
5774
|
+
}
|
|
5775
|
+
function recordPath(name) {
|
|
5776
|
+
return join11(customHookDir(name), INSTALL_RECORD_FILE);
|
|
5777
|
+
}
|
|
5778
|
+
function hashOrNull(path) {
|
|
5779
|
+
try {
|
|
5780
|
+
if (!lstatSync4(path).isFile())
|
|
5781
|
+
return NOT_A_FILE;
|
|
5782
|
+
return sha2562(readFileSync6(path));
|
|
5783
|
+
} catch (error) {
|
|
5784
|
+
if (error.code === "ENOENT")
|
|
5785
|
+
return null;
|
|
5786
|
+
throw error;
|
|
5787
|
+
}
|
|
5788
|
+
}
|
|
5789
|
+
function writeFileAtomic(path, bytes, mode) {
|
|
5790
|
+
const tmp = `${path}.tmp-${randomBytes2(8).toString("hex")}`;
|
|
5791
|
+
const fd = openSync3(tmp, "wx", mode);
|
|
5792
|
+
try {
|
|
5793
|
+
writeSync(fd, typeof bytes === "string" ? Buffer.from(bytes, "utf8") : bytes);
|
|
5794
|
+
fsyncSync(fd);
|
|
5795
|
+
} finally {
|
|
5796
|
+
closeSync3(fd);
|
|
5797
|
+
}
|
|
5798
|
+
try {
|
|
5799
|
+
renameSync2(tmp, path);
|
|
5800
|
+
} catch (error) {
|
|
5801
|
+
rmSync2(tmp, { force: true });
|
|
5802
|
+
throw error;
|
|
5803
|
+
}
|
|
5804
|
+
}
|
|
5805
|
+
function scriptPathIn(dir, rel) {
|
|
5806
|
+
if (isAbsolute4(rel))
|
|
5807
|
+
throw new ScriptContainmentError(rel, dir);
|
|
5808
|
+
const target = resolve5(dir, rel);
|
|
5809
|
+
if (target === resolve5(dir) || !target.startsWith(resolve5(dir) + sep3))
|
|
5810
|
+
throw new ScriptContainmentError(rel, dir);
|
|
5811
|
+
if (target === join11(resolve5(dir), "manifest.json") || target === join11(resolve5(dir), INSTALL_RECORD_FILE)) {
|
|
5812
|
+
throw new ScriptContainmentError(rel, dir);
|
|
5813
|
+
}
|
|
5814
|
+
return target;
|
|
5815
|
+
}
|
|
5816
|
+
function readInstallRecord(name) {
|
|
5817
|
+
const path = recordPath(name);
|
|
5818
|
+
let raw;
|
|
5819
|
+
try {
|
|
5820
|
+
if (!lstatSync4(path).isFile())
|
|
5821
|
+
throw new InstallRecordError(`install record (${path}) is not a regular file`);
|
|
5822
|
+
raw = readFileSync6(path, "utf8");
|
|
5823
|
+
} catch (error) {
|
|
5824
|
+
if (error.code === "ENOENT")
|
|
5825
|
+
return null;
|
|
5826
|
+
throw error instanceof InstallRecordError ? error : new InstallRecordError(`install record (${path}) could not be read`);
|
|
5827
|
+
}
|
|
5828
|
+
let value;
|
|
5829
|
+
try {
|
|
5830
|
+
value = JSON.parse(raw);
|
|
5831
|
+
} catch {
|
|
5832
|
+
throw new InstallRecordError(`install record (${path}) is not valid JSON`);
|
|
5833
|
+
}
|
|
5834
|
+
const isHash = (v) => typeof v === "string" && /^[0-9a-f]{64}$/.test(v);
|
|
5835
|
+
const isHashOrNull = (v) => v === null || isHash(v);
|
|
5836
|
+
if (value === null || typeof value !== "object" || value.schema !== INSTALL_RECORD_SCHEMA || typeof value.name !== "string" || typeof value.version !== "string" || typeof value.source !== "string" || value.script === null || typeof value.script !== "object" || typeof value.script.path !== "string" || !isHash(value.script.sha256) || typeof value.script.content_base64 !== "string" || value.manifest === null || typeof value.manifest !== "object" || !isHash(value.manifest.sha256) || typeof value.manifest.content_base64 !== "string" || value.replaces === null || typeof value.replaces !== "object" || !isHashOrNull(value.replaces.script_sha256) || !isHashOrNull(value.replaces.manifest_sha256)) {
|
|
5837
|
+
throw new InstallRecordError(`install record (${path}) is malformed`);
|
|
5838
|
+
}
|
|
5839
|
+
if (value.name !== shortManifestName(name))
|
|
5840
|
+
throw new InstallRecordError(`install record (${path}) names another hook`);
|
|
5841
|
+
const script = Buffer.from(value.script.content_base64, "base64");
|
|
5842
|
+
const manifest = Buffer.from(value.manifest.content_base64, "base64");
|
|
5843
|
+
if (sha2562(script) !== value.script.sha256 || sha2562(manifest) !== value.manifest.sha256) {
|
|
5844
|
+
throw new InstallRecordError(`install record (${path}) does not hash to what it records`);
|
|
5845
|
+
}
|
|
5846
|
+
let parsed;
|
|
5847
|
+
try {
|
|
5848
|
+
parsed = parseManifest(manifest.toString("utf8"));
|
|
5849
|
+
} catch {
|
|
5850
|
+
throw new InstallRecordError(`install record (${path}) holds an invalid manifest`);
|
|
5851
|
+
}
|
|
5852
|
+
if (shortManifestName(parsed.name) !== value.name || scriptRelFor(parsed) !== value.script.path) {
|
|
5853
|
+
throw new InstallRecordError(`install record (${path}) does not agree with the manifest it holds`);
|
|
5854
|
+
}
|
|
5855
|
+
scriptPathIn(customHookDir(name), value.script.path);
|
|
5856
|
+
return value;
|
|
5857
|
+
}
|
|
5858
|
+
function commitInstall(name, manifest, scriptContent, scriptRelPath, options) {
|
|
5859
|
+
const short = shortManifestName(name);
|
|
5860
|
+
const dir = customHookDir(short);
|
|
5861
|
+
if (scriptRelPath !== scriptRelFor(manifest)) {
|
|
5862
|
+
throw new InstallRecordError(`'${short}' cannot be installed: script path '${scriptRelPath}' is not the one its manifest resolves to`);
|
|
5863
|
+
}
|
|
5864
|
+
const scriptPath = scriptPathIn(dir, scriptRelPath);
|
|
5865
|
+
mkdirSync4(dir, { recursive: true });
|
|
5866
|
+
assertContained(scriptPath, dir, scriptRelPath);
|
|
5867
|
+
const scriptBytes = typeof scriptContent === "string" ? Buffer.from(scriptContent, "utf8") : scriptContent;
|
|
5868
|
+
const manifestBytes = options.manifestBytes ?? Buffer.from(JSON.stringify(manifest, null, 2) + `
|
|
5869
|
+
`, "utf8");
|
|
5870
|
+
const manifestPath = join11(dir, "manifest.json");
|
|
5871
|
+
const replaced = { script_sha256: hashOrNull(scriptPath), manifest_sha256: hashOrNull(manifestPath) };
|
|
5872
|
+
if (replaced.script_sha256 === NOT_A_FILE || replaced.manifest_sha256 === NOT_A_FILE) {
|
|
5873
|
+
throw new InstallRecordError(`'${short}' cannot be installed: its script or manifest path holds something that is not a regular file`);
|
|
5874
|
+
}
|
|
5875
|
+
const record = {
|
|
5876
|
+
schema: INSTALL_RECORD_SCHEMA,
|
|
5877
|
+
name: short,
|
|
5878
|
+
version: manifest.version,
|
|
5879
|
+
source: options.source,
|
|
5880
|
+
source_ref: options.sourceRef ?? null,
|
|
5881
|
+
installed_at: new Date().toISOString(),
|
|
5882
|
+
script: { path: scriptRelPath, sha256: sha2562(scriptBytes), content_base64: scriptBytes.toString("base64") },
|
|
5883
|
+
manifest: { sha256: sha2562(manifestBytes), content_base64: manifestBytes.toString("base64") },
|
|
5884
|
+
replaces: replaced
|
|
5885
|
+
};
|
|
5886
|
+
options.onStep?.("before-commit");
|
|
5887
|
+
writeFileAtomic(join11(dir, INSTALL_RECORD_FILE), JSON.stringify(record, null, 2) + `
|
|
5888
|
+
`, 384);
|
|
5889
|
+
options.onStep?.("record-committed");
|
|
5890
|
+
materialize(dir, record, options.onStep);
|
|
5891
|
+
return { dir, scriptPath, record };
|
|
5892
|
+
}
|
|
5893
|
+
function materialize(dir, record, onStep) {
|
|
5894
|
+
const scriptPath = scriptPathIn(dir, record.script.path);
|
|
5895
|
+
const scriptBytes = Buffer.from(record.script.content_base64, "base64");
|
|
5896
|
+
const manifestBytes = Buffer.from(record.manifest.content_base64, "base64");
|
|
5897
|
+
if (hashOrNull(scriptPath) !== record.script.sha256) {
|
|
5898
|
+
mkdirSync4(dirname7(scriptPath), { recursive: true });
|
|
5899
|
+
writeFileAtomic(scriptPath, scriptBytes, 420);
|
|
5900
|
+
}
|
|
5901
|
+
onStep?.("script-written");
|
|
5902
|
+
const manifestPath = join11(dir, "manifest.json");
|
|
5903
|
+
if (hashOrNull(manifestPath) !== record.manifest.sha256)
|
|
5904
|
+
writeFileAtomic(manifestPath, manifestBytes, 420);
|
|
5905
|
+
onStep?.("manifest-written");
|
|
5906
|
+
}
|
|
5907
|
+
function inspectInstall(name) {
|
|
5908
|
+
let record;
|
|
5909
|
+
try {
|
|
5910
|
+
record = readInstallRecord(name);
|
|
5911
|
+
} catch (error) {
|
|
5912
|
+
if (!(error instanceof InstallRecordError) && !(error instanceof ScriptContainmentError))
|
|
5913
|
+
throw error;
|
|
5914
|
+
return { state: "invalid", reason: error.message };
|
|
5915
|
+
}
|
|
5916
|
+
if (!record)
|
|
5917
|
+
return { state: "none" };
|
|
5918
|
+
const dir = customHookDir(name);
|
|
5919
|
+
const unfinished = [];
|
|
5920
|
+
const checks = [
|
|
5921
|
+
["manifest", join11(dir, "manifest.json"), record.manifest.sha256, record.replaces.manifest_sha256],
|
|
5922
|
+
["script", scriptPathIn(dir, record.script.path), record.script.sha256, record.replaces.script_sha256]
|
|
5923
|
+
];
|
|
5924
|
+
for (const [file, path, committed, replaced] of checks) {
|
|
5925
|
+
const actual = hashOrNull(path);
|
|
5926
|
+
if (actual === committed)
|
|
5927
|
+
continue;
|
|
5928
|
+
if (actual === null || actual === replaced) {
|
|
5929
|
+
unfinished.push(file);
|
|
5930
|
+
continue;
|
|
5931
|
+
}
|
|
5932
|
+
return { state: "edited", record, file, expected: committed, actual };
|
|
5933
|
+
}
|
|
5934
|
+
return unfinished.length > 0 ? { state: "unfinished", record, files: unfinished } : { state: "consistent", record };
|
|
5935
|
+
}
|
|
5936
|
+
function finishInstall(name) {
|
|
5937
|
+
const state = inspectInstall(name);
|
|
5938
|
+
if (state.state !== "unfinished")
|
|
5939
|
+
return state;
|
|
5940
|
+
materialize(customHookDir(name), state.record);
|
|
5941
|
+
return inspectInstall(name);
|
|
5942
|
+
}
|
|
5943
|
+
function installFingerprint(name) {
|
|
5944
|
+
let raw = "none";
|
|
5945
|
+
try {
|
|
5946
|
+
raw = sha2562(readFileSync6(recordPath(name)));
|
|
5947
|
+
} catch (error) {
|
|
5948
|
+
if (error.code !== "ENOENT")
|
|
5949
|
+
raw = "unreadable";
|
|
5950
|
+
}
|
|
5951
|
+
if (raw === "none")
|
|
5952
|
+
return raw;
|
|
5953
|
+
try {
|
|
5954
|
+
return `${raw}:${inspectInstall(name).state}`;
|
|
5955
|
+
} catch {
|
|
5956
|
+
return `${raw}:undecidable`;
|
|
5957
|
+
}
|
|
5958
|
+
}
|
|
5959
|
+
function withStableInstall(name, read) {
|
|
5960
|
+
for (let attempt = 0;; attempt++) {
|
|
5961
|
+
let before;
|
|
5962
|
+
try {
|
|
5963
|
+
finishInstall(name);
|
|
5964
|
+
before = installFingerprint(name);
|
|
5965
|
+
} catch {
|
|
5966
|
+
return read();
|
|
5967
|
+
}
|
|
5968
|
+
const value = read();
|
|
5969
|
+
let after;
|
|
5970
|
+
try {
|
|
5971
|
+
after = installFingerprint(name);
|
|
5972
|
+
} catch {
|
|
5973
|
+
return value;
|
|
5974
|
+
}
|
|
5975
|
+
if (after === before || attempt >= 3)
|
|
5976
|
+
return value;
|
|
5977
|
+
}
|
|
5978
|
+
}
|
|
5979
|
+
var INSTALL_RECORD_SCHEMA = 1, InstallRecordError, NOT_A_FILE = "not-a-regular-file";
|
|
5980
|
+
var init_install_record = __esm(() => {
|
|
5981
|
+
init_manifest();
|
|
5982
|
+
InstallRecordError = class InstallRecordError extends Error {
|
|
5983
|
+
constructor(message) {
|
|
5984
|
+
super(message);
|
|
5985
|
+
this.name = "InstallRecordError";
|
|
5986
|
+
}
|
|
5987
|
+
};
|
|
5988
|
+
});
|
|
5989
|
+
|
|
4855
5990
|
// src/lib/store.ts
|
|
4856
5991
|
var exports_store = {};
|
|
4857
5992
|
__export(exports_store, {
|
|
@@ -4874,13 +6009,14 @@ __export(exports_store, {
|
|
|
4874
6009
|
checkScriptHash: () => checkScriptHash,
|
|
4875
6010
|
LockFileError: () => LockFileError
|
|
4876
6011
|
});
|
|
4877
|
-
import { createHash as
|
|
4878
|
-
import { existsSync as
|
|
4879
|
-
import { join as
|
|
6012
|
+
import { createHash as createHash6 } from "crypto";
|
|
6013
|
+
import { existsSync as existsSync9, mkdirSync as mkdirSync5, readFileSync as readFileSync7, writeFileSync as writeFileSync3, renameSync as renameSync3, lstatSync as lstatSync5 } from "fs";
|
|
6014
|
+
import { join as join12 } from "path";
|
|
4880
6015
|
import { readFile } from "fs/promises";
|
|
4881
|
-
import {
|
|
6016
|
+
import { Database as Database2 } from "bun:sqlite";
|
|
6017
|
+
import { randomBytes as randomBytes3 } from "crypto";
|
|
4882
6018
|
function sha256Of(input) {
|
|
4883
|
-
return
|
|
6019
|
+
return createHash6("sha256").update(input).digest("hex");
|
|
4884
6020
|
}
|
|
4885
6021
|
async function sha256File(path) {
|
|
4886
6022
|
const buf = await readFile(path);
|
|
@@ -4889,6 +6025,22 @@ async function sha256File(path) {
|
|
|
4889
6025
|
function storeDb() {
|
|
4890
6026
|
return isLocalStoreRefused() ? null : getDb();
|
|
4891
6027
|
}
|
|
6028
|
+
function readHookRecordReadOnly(name) {
|
|
6029
|
+
if (isLocalStoreRefused())
|
|
6030
|
+
return null;
|
|
6031
|
+
const path = process.env.HASNA_HOOKS_DB_PATH ?? process.env.HOOKS_DB_PATH ?? join12(getHooksDataDir(), "hooks.db");
|
|
6032
|
+
if (path === ":memory:" || !existsSync9(path))
|
|
6033
|
+
return null;
|
|
6034
|
+
let db = null;
|
|
6035
|
+
try {
|
|
6036
|
+
db = new Database2(path, { readonly: true });
|
|
6037
|
+
return getHookRecord(db, name);
|
|
6038
|
+
} catch {
|
|
6039
|
+
return null;
|
|
6040
|
+
} finally {
|
|
6041
|
+
db?.close();
|
|
6042
|
+
}
|
|
6043
|
+
}
|
|
4892
6044
|
function getHookRecord(db, name) {
|
|
4893
6045
|
return db.query("SELECT * FROM hooks WHERE name = ?").get(name);
|
|
4894
6046
|
}
|
|
@@ -4941,11 +6093,11 @@ function assertLockShape(parsed, path) {
|
|
|
4941
6093
|
}
|
|
4942
6094
|
function readLock() {
|
|
4943
6095
|
const path = getLockPath();
|
|
4944
|
-
if (!
|
|
6096
|
+
if (!existsSync9(path))
|
|
4945
6097
|
return { hooks: {} };
|
|
4946
6098
|
let raw;
|
|
4947
6099
|
try {
|
|
4948
|
-
raw =
|
|
6100
|
+
raw = readFileSync7(path, "utf-8");
|
|
4949
6101
|
} catch {
|
|
4950
6102
|
throw new LockFileError(`hooks.lock (${path}) could not be read. Repair: fix permissions or move the file aside and run 'hooks sync'.`);
|
|
4951
6103
|
}
|
|
@@ -4960,15 +6112,15 @@ function readLock() {
|
|
|
4960
6112
|
}
|
|
4961
6113
|
function writeLock(lock) {
|
|
4962
6114
|
const path = getLockPath();
|
|
4963
|
-
|
|
6115
|
+
mkdirSync5(path.substring(0, path.lastIndexOf("/")) || ".", { recursive: true });
|
|
4964
6116
|
const sorted = {};
|
|
4965
6117
|
for (const name of Object.keys(lock.hooks).sort()) {
|
|
4966
6118
|
sorted[name] = lock.hooks[name];
|
|
4967
6119
|
}
|
|
4968
|
-
const tmp = `${path}.tmp-${
|
|
4969
|
-
|
|
6120
|
+
const tmp = `${path}.tmp-${randomBytes3(8).toString("hex")}`;
|
|
6121
|
+
writeFileSync3(tmp, JSON.stringify({ hooks: sorted }, null, 2) + `
|
|
4970
6122
|
`, "utf-8");
|
|
4971
|
-
|
|
6123
|
+
renameSync3(tmp, path);
|
|
4972
6124
|
return path;
|
|
4973
6125
|
}
|
|
4974
6126
|
function setPinnedHook(name, entry) {
|
|
@@ -4980,25 +6132,25 @@ function getPinnedHook(name) {
|
|
|
4980
6132
|
return readLock().hooks[name];
|
|
4981
6133
|
}
|
|
4982
6134
|
function registryManagedMarker(name) {
|
|
4983
|
-
return
|
|
6135
|
+
return join12(getHooksDataDir(), "registry-managed", sha256Of(name) + ".json");
|
|
4984
6136
|
}
|
|
4985
6137
|
function markRegistryManaged(name) {
|
|
4986
6138
|
const path = registryManagedMarker(name);
|
|
4987
6139
|
const content = JSON.stringify({ schema: 1, name }) + `
|
|
4988
6140
|
`;
|
|
4989
|
-
|
|
6141
|
+
mkdirSync5(join12(getHooksDataDir(), "registry-managed"), { recursive: true, mode: 448 });
|
|
4990
6142
|
try {
|
|
4991
|
-
|
|
6143
|
+
writeFileSync3(path, content, { flag: "wx", mode: 384 });
|
|
4992
6144
|
} catch (error) {
|
|
4993
6145
|
if (error.code !== "EEXIST")
|
|
4994
6146
|
throw error;
|
|
4995
6147
|
}
|
|
4996
|
-
if (!
|
|
6148
|
+
if (!lstatSync5(path).isFile() || readFileSync7(path, "utf8") !== content)
|
|
4997
6149
|
throw new Error("REGISTRY_MANAGED_MARKER_INVALID");
|
|
4998
6150
|
}
|
|
4999
6151
|
function isRegistryManaged(name) {
|
|
5000
6152
|
try {
|
|
5001
|
-
|
|
6153
|
+
lstatSync5(registryManagedMarker(name));
|
|
5002
6154
|
return true;
|
|
5003
6155
|
} catch (error) {
|
|
5004
6156
|
if (error.code === "ENOENT")
|
|
@@ -5014,20 +6166,20 @@ function removePinnedHook(name) {
|
|
|
5014
6166
|
writeLock(lock);
|
|
5015
6167
|
return true;
|
|
5016
6168
|
}
|
|
5017
|
-
function pinInstalledHook(name, version,
|
|
6169
|
+
function pinInstalledHook(name, version, sha2563, source, sourceRef) {
|
|
5018
6170
|
const now = new Date().toISOString();
|
|
5019
6171
|
const db = storeDb();
|
|
5020
6172
|
if (db) {
|
|
5021
6173
|
upsertHookRecord(db, {
|
|
5022
6174
|
name,
|
|
5023
6175
|
version,
|
|
5024
|
-
sha256,
|
|
6176
|
+
sha256: sha2563,
|
|
5025
6177
|
source_type: source,
|
|
5026
6178
|
source_ref: sourceRef ?? null,
|
|
5027
6179
|
last_verified_at: now
|
|
5028
6180
|
});
|
|
5029
6181
|
}
|
|
5030
|
-
setPinnedHook(name, { version, sha256, source });
|
|
6182
|
+
setPinnedHook(name, { version, sha256: sha2563, source });
|
|
5031
6183
|
}
|
|
5032
6184
|
function removeHookFromStore(name) {
|
|
5033
6185
|
const removedPin = removePinnedHook(name);
|
|
@@ -5035,7 +6187,7 @@ function removeHookFromStore(name) {
|
|
|
5035
6187
|
const removedRecord = db ? removeHookRecord(db, name) : false;
|
|
5036
6188
|
return { removedPin, removedRecord };
|
|
5037
6189
|
}
|
|
5038
|
-
function checkScriptHash(name, actual) {
|
|
6190
|
+
function checkScriptHash(name, actual, options = {}) {
|
|
5039
6191
|
const canonical = shortManifestName(name);
|
|
5040
6192
|
if (!HOOK_NAME_RE.test(canonical))
|
|
5041
6193
|
return { ok: false, pinned: false, expected: "invalid-hook-name", actual, name };
|
|
@@ -5050,8 +6202,34 @@ function checkScriptHash(name, actual) {
|
|
|
5050
6202
|
}
|
|
5051
6203
|
if (isRegistryManaged(customIdentity ?? canonical))
|
|
5052
6204
|
name = customIdentity ?? canonical;
|
|
5053
|
-
|
|
5054
|
-
|
|
6205
|
+
else if (customIdentity !== undefined) {
|
|
6206
|
+
const installed = inspectInstall(customIdentity);
|
|
6207
|
+
if (installed.state === "invalid") {
|
|
6208
|
+
return { ok: false, pinned: true, expected: "install-record-invalid", actual, name: customIdentity, governedBy: "install-record", state: installed.state };
|
|
6209
|
+
}
|
|
6210
|
+
if (installed.state !== "none") {
|
|
6211
|
+
const label = `${installed.record.name}@${installed.record.version}`;
|
|
6212
|
+
const base = { name: customIdentity, governedBy: "install-record", release: label, state: installed.state };
|
|
6213
|
+
if (installed.state === "edited") {
|
|
6214
|
+
return { ok: false, pinned: true, expected: installed.expected, actual: installed.file === "script" ? actual : installed.actual, ...base, release: null };
|
|
6215
|
+
}
|
|
6216
|
+
const committed = installed.record.script.sha256;
|
|
6217
|
+
return { ok: installed.state === "consistent" && actual === committed, pinned: true, expected: committed, actual, ...base };
|
|
6218
|
+
}
|
|
6219
|
+
} else if (getHook(canonical)) {
|
|
6220
|
+
const release = releaseTrustFor(canonical, actual, resolveScriptPath(canonical));
|
|
6221
|
+
if (release.governed) {
|
|
6222
|
+
if (release.ok)
|
|
6223
|
+
return { ok: true, pinned: true, expected: release.expected, actual, name: canonical, governedBy: "release", release: release.release };
|
|
6224
|
+
const explicit = release.reason === "content" ? getPinnedHook(canonical) : undefined;
|
|
6225
|
+
if (explicit && explicit.sha256 === actual && explicit.release === release.release) {
|
|
6226
|
+
return { ok: true, pinned: true, expected: actual, actual, name: canonical, governedBy: "pin", release: null };
|
|
6227
|
+
}
|
|
6228
|
+
return { ok: false, pinned: true, expected: release.expected, actual, name: canonical, governedBy: "release", release: release.release };
|
|
6229
|
+
}
|
|
6230
|
+
}
|
|
6231
|
+
const db = options.readOnly ? null : storeDb();
|
|
6232
|
+
const record = options.readOnly ? readHookRecordReadOnly(name) : db ? getHookRecord(db, name) : null;
|
|
5055
6233
|
const pin2 = getPinnedHook(name);
|
|
5056
6234
|
const expected = record?.sha256 ?? pin2?.sha256 ?? null;
|
|
5057
6235
|
if (isRegistryManaged(name) && (!pin2 || !pin2.manifest_sha256)) {
|
|
@@ -5064,9 +6242,11 @@ function checkScriptHash(name, actual) {
|
|
|
5064
6242
|
}
|
|
5065
6243
|
}
|
|
5066
6244
|
if (expected !== null && expected !== actual) {
|
|
5067
|
-
return { ok: false, pinned: true, expected, actual, name };
|
|
6245
|
+
return { ok: false, pinned: true, expected, actual, name, governedBy: "pin", release: null };
|
|
5068
6246
|
}
|
|
5069
6247
|
if (expected === null) {
|
|
6248
|
+
if (options.readOnly)
|
|
6249
|
+
return { ok: true, pinned: false, expected: null, actual, name, governedBy: "first-run", release: null };
|
|
5070
6250
|
const now2 = new Date().toISOString();
|
|
5071
6251
|
const version = pin2?.version ?? record?.version ?? "0.0.0";
|
|
5072
6252
|
const source = pin2?.source ?? record?.source_type ?? "local";
|
|
@@ -5080,10 +6260,10 @@ function checkScriptHash(name, actual) {
|
|
|
5080
6260
|
});
|
|
5081
6261
|
}
|
|
5082
6262
|
setPinnedHook(name, { version, sha256: actual, source });
|
|
5083
|
-
return { ok: true, pinned: false, expected: null, actual, name };
|
|
6263
|
+
return { ok: true, pinned: false, expected: null, actual, name, governedBy: "first-run", release: null };
|
|
5084
6264
|
}
|
|
5085
6265
|
const now = new Date().toISOString();
|
|
5086
|
-
if (db) {
|
|
6266
|
+
if (db && !options.readOnly) {
|
|
5087
6267
|
upsertHookRecord(db, {
|
|
5088
6268
|
name,
|
|
5089
6269
|
version: record?.version ?? pin2?.version ?? "0.0.0",
|
|
@@ -5092,16 +6272,29 @@ function checkScriptHash(name, actual) {
|
|
|
5092
6272
|
last_verified_at: now
|
|
5093
6273
|
});
|
|
5094
6274
|
}
|
|
5095
|
-
return { ok: true, pinned: true, expected, actual, name };
|
|
6275
|
+
return { ok: true, pinned: true, expected, actual, name, governedBy: "pin", release: null };
|
|
5096
6276
|
}
|
|
5097
6277
|
async function verifyScriptHash(name, scriptPath) {
|
|
5098
6278
|
return checkScriptHash(name, await sha256File(scriptPath));
|
|
5099
6279
|
}
|
|
5100
6280
|
function retrustHook(name, scriptPath, version, source) {
|
|
5101
|
-
const
|
|
5102
|
-
const
|
|
5103
|
-
|
|
6281
|
+
const scriptBytes = readFileSync7(scriptPath);
|
|
6282
|
+
const actual = sha256Of(scriptBytes);
|
|
6283
|
+
const registryManaged = isRegistryManaged(name);
|
|
6284
|
+
const custom2 = readCustomManifest(name);
|
|
6285
|
+
if (registryManaged && !custom2)
|
|
5104
6286
|
throw new Error("REGISTRY_MANIFEST_REQUIRED");
|
|
6287
|
+
let release;
|
|
6288
|
+
if (custom2 && !registryManaged) {
|
|
6289
|
+
commitInstall(custom2.manifest.name, custom2.manifest, scriptBytes, scriptRelFor(custom2.manifest), {
|
|
6290
|
+
source: "hooks-trust",
|
|
6291
|
+
manifestBytes: readFileSync7(join12(customHookDir(name), "manifest.json"))
|
|
6292
|
+
});
|
|
6293
|
+
} else if (!custom2 && getHook(shortManifestName(name))) {
|
|
6294
|
+
const decided = releaseTrustFor(shortManifestName(name), actual, scriptPath);
|
|
6295
|
+
if (decided.governed)
|
|
6296
|
+
release = decided.release;
|
|
6297
|
+
}
|
|
5105
6298
|
const db = storeDb();
|
|
5106
6299
|
if (db) {
|
|
5107
6300
|
upsertHookRecord(db, {
|
|
@@ -5112,7 +6305,13 @@ function retrustHook(name, scriptPath, version, source) {
|
|
|
5112
6305
|
last_verified_at: new Date().toISOString()
|
|
5113
6306
|
});
|
|
5114
6307
|
}
|
|
5115
|
-
setPinnedHook(name, {
|
|
6308
|
+
setPinnedHook(name, {
|
|
6309
|
+
version,
|
|
6310
|
+
sha256: actual,
|
|
6311
|
+
source,
|
|
6312
|
+
...registryManaged && custom2 ? { manifest_sha256: registryDigest(custom2.manifest) } : {},
|
|
6313
|
+
...release ? { release } : {}
|
|
6314
|
+
});
|
|
5116
6315
|
return { ok: true, pinned: true, expected: actual, actual, name };
|
|
5117
6316
|
}
|
|
5118
6317
|
var LockFileError;
|
|
@@ -5121,6 +6320,10 @@ var init_store = __esm(() => {
|
|
|
5121
6320
|
init_config();
|
|
5122
6321
|
init_manifest();
|
|
5123
6322
|
init_registry_artifact();
|
|
6323
|
+
init_registry();
|
|
6324
|
+
init_resolve();
|
|
6325
|
+
init_release_manifest();
|
|
6326
|
+
init_install_record();
|
|
5124
6327
|
LockFileError = class LockFileError extends Error {
|
|
5125
6328
|
constructor(message) {
|
|
5126
6329
|
super(message);
|
|
@@ -5142,25 +6345,25 @@ __export(exports_profiles, {
|
|
|
5142
6345
|
deleteProfile: () => deleteProfile,
|
|
5143
6346
|
createProfile: () => createProfile
|
|
5144
6347
|
});
|
|
5145
|
-
import { existsSync as
|
|
5146
|
-
import { join as
|
|
6348
|
+
import { existsSync as existsSync13, mkdirSync as mkdirSync10, readFileSync as readFileSync9, writeFileSync as writeFileSync8, readdirSync as readdirSync5, rmSync as rmSync4, cpSync as cpSync2 } from "fs";
|
|
6349
|
+
import { join as join23 } from "path";
|
|
5147
6350
|
function getProfilesDir() {
|
|
5148
|
-
const newDir =
|
|
5149
|
-
const oldDir =
|
|
5150
|
-
if (!
|
|
5151
|
-
|
|
6351
|
+
const newDir = join23(getEffectiveDataRoot(), "profiles");
|
|
6352
|
+
const oldDir = join23(getHomeDir(), ".hooks", "profiles");
|
|
6353
|
+
if (!existsSync13(newDir) && existsSync13(oldDir)) {
|
|
6354
|
+
mkdirSync10(newDir, { recursive: true });
|
|
5152
6355
|
cpSync2(oldDir, newDir, { recursive: true });
|
|
5153
6356
|
}
|
|
5154
6357
|
return newDir;
|
|
5155
6358
|
}
|
|
5156
6359
|
function ensureProfilesDir() {
|
|
5157
6360
|
const dir = getProfilesDir();
|
|
5158
|
-
if (!
|
|
5159
|
-
|
|
6361
|
+
if (!existsSync13(dir)) {
|
|
6362
|
+
mkdirSync10(dir, { recursive: true });
|
|
5160
6363
|
}
|
|
5161
6364
|
}
|
|
5162
6365
|
function profilePath(id) {
|
|
5163
|
-
return
|
|
6366
|
+
return join23(getProfilesDir(), `${id}.json`);
|
|
5164
6367
|
}
|
|
5165
6368
|
function shortUuid() {
|
|
5166
6369
|
return crypto.randomUUID().slice(0, 8);
|
|
@@ -5186,23 +6389,23 @@ function createProfile(input2) {
|
|
|
5186
6389
|
function getProfile(id) {
|
|
5187
6390
|
const path = profilePath(id);
|
|
5188
6391
|
try {
|
|
5189
|
-
if (!
|
|
6392
|
+
if (!existsSync13(path))
|
|
5190
6393
|
return null;
|
|
5191
|
-
return JSON.parse(
|
|
6394
|
+
return JSON.parse(readFileSync9(path, "utf-8"));
|
|
5192
6395
|
} catch {
|
|
5193
6396
|
return null;
|
|
5194
6397
|
}
|
|
5195
6398
|
}
|
|
5196
6399
|
function listProfiles() {
|
|
5197
6400
|
const dir = getProfilesDir();
|
|
5198
|
-
if (!
|
|
6401
|
+
if (!existsSync13(dir))
|
|
5199
6402
|
return [];
|
|
5200
6403
|
try {
|
|
5201
6404
|
const files = readdirSync5(dir).filter((f) => f.endsWith(".json"));
|
|
5202
6405
|
const profiles = [];
|
|
5203
6406
|
for (const file2 of files) {
|
|
5204
6407
|
try {
|
|
5205
|
-
const content =
|
|
6408
|
+
const content = readFileSync9(join23(dir, file2), "utf-8");
|
|
5206
6409
|
profiles.push(JSON.parse(content));
|
|
5207
6410
|
} catch {}
|
|
5208
6411
|
}
|
|
@@ -5225,10 +6428,10 @@ function updateProfile(id, data) {
|
|
|
5225
6428
|
}
|
|
5226
6429
|
function deleteProfile(id) {
|
|
5227
6430
|
const path = profilePath(id);
|
|
5228
|
-
if (!
|
|
6431
|
+
if (!existsSync13(path))
|
|
5229
6432
|
return false;
|
|
5230
6433
|
try {
|
|
5231
|
-
|
|
6434
|
+
rmSync4(path);
|
|
5232
6435
|
return true;
|
|
5233
6436
|
} catch {
|
|
5234
6437
|
return false;
|
|
@@ -5255,7 +6458,7 @@ function importProfiles(profiles) {
|
|
|
5255
6458
|
continue;
|
|
5256
6459
|
}
|
|
5257
6460
|
const path = profilePath(profile.agent_id);
|
|
5258
|
-
if (
|
|
6461
|
+
if (existsSync13(path)) {
|
|
5259
6462
|
skipped++;
|
|
5260
6463
|
continue;
|
|
5261
6464
|
}
|
|
@@ -5278,10 +6481,10 @@ import { hostname as osHostname } from "os";
|
|
|
5278
6481
|
import { isAbsolute as isAbsolute7, join as join24 } from "path";
|
|
5279
6482
|
import { createRequire as createRequire2 } from "module";
|
|
5280
6483
|
import { fileURLToPath as fileURLToPath22 } from "url";
|
|
5281
|
-
import { closeSync as
|
|
6484
|
+
import { closeSync as closeSync6, fstatSync as fstatSync4, lstatSync as lstatSync11, openSync as openSync6, readFileSync as readFileSync21, realpathSync as realpathSync9, statSync as statSync2 } from "fs";
|
|
5282
6485
|
import { O_NOFOLLOW, O_NONBLOCK, O_RDONLY } from "constants";
|
|
5283
|
-
import { basename as basename18, dirname as dirname27, join as
|
|
5284
|
-
import { fileURLToPath as
|
|
6486
|
+
import { basename as basename18, dirname as dirname27, join as join36, relative as relative2, sep as sep11 } from "path";
|
|
6487
|
+
import { fileURLToPath as fileURLToPath5, pathToFileURL } from "url";
|
|
5285
6488
|
function envToken2(name) {
|
|
5286
6489
|
return name.toUpperCase().replace(/-/g, "_");
|
|
5287
6490
|
}
|
|
@@ -5355,7 +6558,7 @@ function o(e2, r2, t2) {
|
|
|
5355
6558
|
}
|
|
5356
6559
|
function entryPoint(directory3) {
|
|
5357
6560
|
const root = realpathSync9(directory3);
|
|
5358
|
-
const fd =
|
|
6561
|
+
const fd = openSync6(join36(root, "package.json"), O_RDONLY | O_NOFOLLOW | O_NONBLOCK);
|
|
5359
6562
|
let pkg;
|
|
5360
6563
|
try {
|
|
5361
6564
|
const stat2 = fstatSync4(fd);
|
|
@@ -5363,7 +6566,7 @@ function entryPoint(directory3) {
|
|
|
5363
6566
|
throw new Error("Invalid Secrets package metadata");
|
|
5364
6567
|
pkg = JSON.parse(readFileSync21(fd, "utf8"));
|
|
5365
6568
|
} finally {
|
|
5366
|
-
|
|
6569
|
+
closeSync6(fd);
|
|
5367
6570
|
}
|
|
5368
6571
|
if (!pkg || typeof pkg !== "object" || !("name" in pkg) || pkg.name !== PACKAGE) {
|
|
5369
6572
|
throw new Error("Invalid Secrets package identity");
|
|
@@ -5375,18 +6578,18 @@ function entryPoint(directory3) {
|
|
|
5375
6578
|
if (/[\\%?#\0]/.test(target) || parts.some((part) => !part || part === "." || part === ".." || part === "node_modules")) {
|
|
5376
6579
|
throw new Error("Invalid Secrets import export");
|
|
5377
6580
|
}
|
|
5378
|
-
const file2 = realpathSync9(
|
|
5379
|
-
const within =
|
|
6581
|
+
const file2 = realpathSync9(join36(root, ...parts));
|
|
6582
|
+
const within = relative2(root, file2);
|
|
5380
6583
|
if (!within || within === ".." || within.startsWith(`..${sep11}`) || !statSync2(file2).isFile()) {
|
|
5381
6584
|
throw new Error("Secrets import export escapes its package or is not a file");
|
|
5382
6585
|
}
|
|
5383
6586
|
return pathToFileURL(file2).href;
|
|
5384
6587
|
}
|
|
5385
6588
|
function resolveInstalledSecrets(parentUrl) {
|
|
5386
|
-
let directory3 = dirname27(
|
|
6589
|
+
let directory3 = dirname27(fileURLToPath5(parentUrl));
|
|
5387
6590
|
for (;; ) {
|
|
5388
6591
|
if (basename18(directory3) !== "node_modules") {
|
|
5389
|
-
const candidate =
|
|
6592
|
+
const candidate = join36(directory3, "node_modules", PACKAGE);
|
|
5390
6593
|
let absent = false;
|
|
5391
6594
|
try {
|
|
5392
6595
|
lstatSync11(candidate);
|
|
@@ -5413,9 +6616,9 @@ function absoluteOverride(env, key2) {
|
|
|
5413
6616
|
return value && isAbsolute7(value) ? value : null;
|
|
5414
6617
|
}
|
|
5415
6618
|
function hasnaHomeDir(env) {
|
|
5416
|
-
const
|
|
5417
|
-
if (
|
|
5418
|
-
return
|
|
6619
|
+
const override2 = absoluteOverride(env, HASNA_HOME_ENV_KEY);
|
|
6620
|
+
if (override2)
|
|
6621
|
+
return override2;
|
|
5419
6622
|
const home = homeDir(env);
|
|
5420
6623
|
return home ? join24(home, HASNA_HOME_DIR) : null;
|
|
5421
6624
|
}
|
|
@@ -5760,13 +6963,13 @@ function resolveCredential(name, env, options = {}) {
|
|
|
5760
6963
|
const overrideKeyName = credentialOverrideEnvKey(name);
|
|
5761
6964
|
const overrideRaw = Object.prototype.hasOwnProperty.call(env, overrideKeyName) ? env[overrideKeyName] : undefined;
|
|
5762
6965
|
if (overrideRaw !== undefined) {
|
|
5763
|
-
const
|
|
5764
|
-
if (!
|
|
6966
|
+
const override2 = overrideRaw.trim();
|
|
6967
|
+
if (!override2) {
|
|
5765
6968
|
throw new CredentialResolutionError(name, `${overrideKeyName} is set but empty. It is a deliberate override, so it is not resolved around: ` + `either give it a real key or unset it to fall back to the credential on disk.`, [overrideKeyName]);
|
|
5766
6969
|
}
|
|
5767
|
-
assertUsableCredential(name, overrideKeyName,
|
|
6970
|
+
assertUsableCredential(name, overrideKeyName, override2);
|
|
5768
6971
|
return sealCredential({
|
|
5769
|
-
apiKey:
|
|
6972
|
+
apiKey: override2,
|
|
5770
6973
|
tier: "override",
|
|
5771
6974
|
source: overrideKeyName,
|
|
5772
6975
|
deliberate: true,
|
|
@@ -6441,7 +7644,7 @@ var init_stop_review_context = __esm(() => {
|
|
|
6441
7644
|
|
|
6442
7645
|
// src/lib/hook-env.ts
|
|
6443
7646
|
import { dirname as dirname39, isAbsolute as isAbsolute36 } from "path";
|
|
6444
|
-
import { existsSync as
|
|
7647
|
+
import { existsSync as existsSync19, realpathSync as realpathSync21, statSync as statSync3 } from "fs";
|
|
6445
7648
|
import { tmpdir as tmpdir3 } from "os";
|
|
6446
7649
|
function isDeniedEnvName(name) {
|
|
6447
7650
|
const upper = name.toUpperCase();
|
|
@@ -6489,7 +7692,7 @@ function isUnsafePathEntry(entry, home) {
|
|
|
6489
7692
|
}
|
|
6490
7693
|
function sanitizeHookPath(pathValue, home) {
|
|
6491
7694
|
const baseline = PATH_BASELINE.slice();
|
|
6492
|
-
if (process.platform === "darwin" &&
|
|
7695
|
+
if (process.platform === "darwin" && existsSync19("/opt/homebrew/bin"))
|
|
6493
7696
|
baseline.push("/opt/homebrew/bin");
|
|
6494
7697
|
const bunDir = dirname39(process.execPath);
|
|
6495
7698
|
const seen = new Set;
|
|
@@ -6623,9 +7826,9 @@ __export(exports_run, {
|
|
|
6623
7826
|
HookTimeoutError: () => HookTimeoutError,
|
|
6624
7827
|
BUN_ISOLATION_FLAGS: () => BUN_ISOLATION_FLAGS
|
|
6625
7828
|
});
|
|
6626
|
-
import { randomBytes as
|
|
7829
|
+
import { randomBytes as randomBytes5 } from "crypto";
|
|
6627
7830
|
import { rmSync as rmSync6, writeFileSync as writeFileSync16 } from "fs";
|
|
6628
|
-
import { basename as basename21, dirname as dirname40, isAbsolute as isAbsolute37, join as
|
|
7831
|
+
import { basename as basename21, dirname as dirname40, isAbsolute as isAbsolute37, join as join49 } from "path";
|
|
6629
7832
|
function extensionOf(scriptPath) {
|
|
6630
7833
|
const base = basename21(scriptPath);
|
|
6631
7834
|
const dot = base.lastIndexOf(".");
|
|
@@ -6696,7 +7899,7 @@ async function readPipeWithDeadline(stream, deadlineMs) {
|
|
|
6696
7899
|
async function executeVerifiedScript(options) {
|
|
6697
7900
|
const scriptDir = dirname40(options.scriptPath);
|
|
6698
7901
|
const interpreter = interpreterFor(options.name, options.scriptPath, options.content);
|
|
6699
|
-
const tempPath =
|
|
7902
|
+
const tempPath = join49(scriptDir, `.hooks-verified-${randomBytes5(12).toString("hex")}.${interpreter.tempExt}`);
|
|
6700
7903
|
let proc = null;
|
|
6701
7904
|
let timedOut = false;
|
|
6702
7905
|
const timeoutTimer = options.timeout ? setTimeout(() => {
|
|
@@ -7247,666 +8450,15 @@ function coerceForSqlite(value) {
|
|
|
7247
8450
|
return JSON.stringify(value);
|
|
7248
8451
|
return String(value);
|
|
7249
8452
|
}
|
|
7250
|
-
// src/
|
|
7251
|
-
|
|
7252
|
-
|
|
7253
|
-
"PreToolUse",
|
|
7254
|
-
"PostToolUse",
|
|
7255
|
-
"Stop",
|
|
7256
|
-
"Notification",
|
|
7257
|
-
"SessionStart",
|
|
7258
|
-
"SessionEnd",
|
|
7259
|
-
"UserPromptSubmit",
|
|
7260
|
-
"SubagentStart"
|
|
7261
|
-
];
|
|
7262
|
-
var CLAUDE_TRASH_GUARD_MATCHER = "^(Bash|Monitor|apply_patch|ApplyPatch|functions\\.apply_patch)$";
|
|
7263
|
-
function matcherFor(meta, target) {
|
|
7264
|
-
return meta.targetMatchers?.[target] ?? meta.matcher;
|
|
7265
|
-
}
|
|
7266
|
-
var CATEGORIES = [
|
|
7267
|
-
"Git Safety",
|
|
7268
|
-
"Code Quality",
|
|
7269
|
-
"Security",
|
|
7270
|
-
"Notifications",
|
|
7271
|
-
"Context Management",
|
|
7272
|
-
"Workflow Automation",
|
|
7273
|
-
"Environment",
|
|
7274
|
-
"Permissions",
|
|
7275
|
-
"Observability",
|
|
7276
|
-
"Agent Teams"
|
|
7277
|
-
];
|
|
7278
|
-
var HOOKS = [
|
|
7279
|
-
{
|
|
7280
|
-
name: "gitguard",
|
|
7281
|
-
displayName: "Git Guard",
|
|
7282
|
-
description: "Blocks destructive git operations like reset --hard, push --force, clean -f",
|
|
7283
|
-
version: "0.1.0",
|
|
7284
|
-
category: "Git Safety",
|
|
7285
|
-
event: "PreToolUse",
|
|
7286
|
-
matcher: "Bash",
|
|
7287
|
-
tags: ["git", "safety", "destructive", "guard"]
|
|
7288
|
-
},
|
|
7289
|
-
{
|
|
7290
|
-
name: "branchprotect",
|
|
7291
|
-
displayName: "Branch Protect",
|
|
7292
|
-
description: "Prevents editing files directly on main/master branch",
|
|
7293
|
-
version: "0.1.0",
|
|
7294
|
-
category: "Git Safety",
|
|
7295
|
-
event: "PreToolUse",
|
|
7296
|
-
matcher: "Write|Edit|NotebookEdit",
|
|
7297
|
-
tags: ["git", "branch", "protection", "main"]
|
|
7298
|
-
},
|
|
7299
|
-
{
|
|
7300
|
-
name: "checkpoint",
|
|
7301
|
-
displayName: "Checkpoint",
|
|
7302
|
-
description: "Creates shadow git snapshots before file modifications for easy rollback",
|
|
7303
|
-
version: "0.1.0",
|
|
7304
|
-
category: "Git Safety",
|
|
7305
|
-
event: "PreToolUse",
|
|
7306
|
-
matcher: "Write|Edit|NotebookEdit",
|
|
7307
|
-
tags: ["git", "snapshot", "rollback", "backup"]
|
|
7308
|
-
},
|
|
7309
|
-
{
|
|
7310
|
-
name: "worktree-guard",
|
|
7311
|
-
displayName: "Worktree Guard",
|
|
7312
|
-
description: "Warns on feature work outside managed repos worktrees and blocks scoped destructive operations",
|
|
7313
|
-
version: "0.1.0",
|
|
7314
|
-
category: "Git Safety",
|
|
7315
|
-
event: "PreToolUse",
|
|
7316
|
-
matcher: "^(Bash|Write|Edit|MultiEdit|NotebookEdit|apply_patch|ApplyPatch|functions\\.apply_patch|mcp__.*)$",
|
|
7317
|
-
tags: ["git", "worktree", "repos", "multi-agent", "safety", "dangerous-ops"]
|
|
7318
|
-
},
|
|
7319
|
-
{
|
|
7320
|
-
name: "workspace-repos-guard",
|
|
7321
|
-
timeoutSeconds: 10,
|
|
7322
|
-
displayName: "Workspace Repos Guard",
|
|
7323
|
-
description: "Blocks writes and deletes that break the protected repo-checkout structure (~/.hasna/repos/clones canonical, plus legacy ~/workspace/repos during the migration window): writes to a protected root, top-level entry creation, non-org folders, and any delete under a protected root",
|
|
7324
|
-
version: "0.1.1",
|
|
7325
|
-
category: "Git Safety",
|
|
7326
|
-
event: "PreToolUse",
|
|
7327
|
-
matcher: "^(Bash|Write|Edit|MultiEdit|NotebookEdit|apply_patch|ApplyPatch|functions\\.apply_patch)$",
|
|
7328
|
-
targetMatchers: { claude: "^(Bash|Monitor|Write|Edit|MultiEdit|NotebookEdit|apply_patch|ApplyPatch|functions\\.apply_patch)$" },
|
|
7329
|
-
legacyMatchers: ["^(Bash|Write|Edit|MultiEdit|NotebookEdit|apply_patch|ApplyPatch|functions\\.apply_patch)$"],
|
|
7330
|
-
tags: ["workspace", "repos", "structure", "guard", "safety", "orgs", "multi-agent"]
|
|
7331
|
-
},
|
|
7332
|
-
{
|
|
7333
|
-
name: "protected-delete-guard",
|
|
7334
|
-
timeoutSeconds: 10,
|
|
7335
|
-
displayName: "Protected Delete Guard",
|
|
7336
|
-
description: "Refuses rm, rmdir, unlink and find with a delete action on the protected class (/, the system roots, the home directory, ~/.hasna, ~/.ssh, ~/.aws) and on coding-agent session and history stores; only refuses, never rewrites a command and needs no Trash",
|
|
7337
|
-
version: "0.1.0",
|
|
7338
|
-
category: "Git Safety",
|
|
7339
|
-
event: "PreToolUse",
|
|
7340
|
-
matcher: "^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$",
|
|
7341
|
-
targetMatchers: { claude: "^(Bash|Monitor|apply_patch|ApplyPatch|functions\\.apply_patch)$" },
|
|
7342
|
-
tags: ["rm", "delete", "protected", "session-history", "guard", "safety", "bash"]
|
|
7343
|
-
},
|
|
7344
|
-
{
|
|
7345
|
-
name: "trash-guard",
|
|
7346
|
-
displayName: "Trash Guard",
|
|
7347
|
-
description: "Rewrites rm issued through Bash into `trash guard`, so the delete lands in a recoverable trash store; refuses the delete when there is nothing to redirect to (trash absent, a delete verb it cannot rewrite, or the protected class: /, ~, ~/.hasna, ~/.ssh, ~/.aws)",
|
|
7348
|
-
version: "0.1.2",
|
|
7349
|
-
category: "Git Safety",
|
|
7350
|
-
event: "PreToolUse",
|
|
7351
|
-
matcher: "^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$",
|
|
7352
|
-
targetMatchers: { claude: CLAUDE_TRASH_GUARD_MATCHER },
|
|
7353
|
-
legacyMatchers: ["^(Bash|apply_patch|ApplyPatch|functions\\.apply_patch)$"],
|
|
7354
|
-
tags: ["rm", "delete", "trash", "recoverable", "guard", "safety", "bash"],
|
|
7355
|
-
rewritesInput: true,
|
|
7356
|
-
timeoutSeconds: 10
|
|
7357
|
-
},
|
|
7358
|
-
{
|
|
7359
|
-
name: "checktests",
|
|
7360
|
-
displayName: "Check Tests",
|
|
7361
|
-
description: "Checks for missing tests after file edits",
|
|
7362
|
-
version: "0.1.6",
|
|
7363
|
-
category: "Code Quality",
|
|
7364
|
-
event: "PostToolUse",
|
|
7365
|
-
matcher: "Edit|Write|NotebookEdit",
|
|
7366
|
-
tags: ["tests", "coverage", "quality"]
|
|
7367
|
-
},
|
|
7368
|
-
{
|
|
7369
|
-
name: "checklint",
|
|
7370
|
-
displayName: "Check Lint",
|
|
7371
|
-
description: "Runs linting after file edits and creates tasks for errors",
|
|
7372
|
-
version: "0.1.7",
|
|
7373
|
-
category: "Code Quality",
|
|
7374
|
-
event: "PostToolUse",
|
|
7375
|
-
matcher: "Edit|Write|NotebookEdit",
|
|
7376
|
-
tags: ["lint", "style", "quality"]
|
|
7377
|
-
},
|
|
7378
|
-
{
|
|
7379
|
-
name: "checkfiles",
|
|
7380
|
-
displayName: "Check Files",
|
|
7381
|
-
description: "Runs headless agent to review files and create tasks",
|
|
7382
|
-
version: "0.1.4",
|
|
7383
|
-
category: "Code Quality",
|
|
7384
|
-
event: "PostToolUse",
|
|
7385
|
-
matcher: "Edit|Write|NotebookEdit",
|
|
7386
|
-
tags: ["review", "files", "quality"]
|
|
7387
|
-
},
|
|
7388
|
-
{
|
|
7389
|
-
name: "checkbugs",
|
|
7390
|
-
displayName: "Check Bugs",
|
|
7391
|
-
description: "Checks for bugs via headless agent",
|
|
7392
|
-
version: "0.1.6",
|
|
7393
|
-
category: "Code Quality",
|
|
7394
|
-
event: "PostToolUse",
|
|
7395
|
-
matcher: "Edit|Write|NotebookEdit",
|
|
7396
|
-
tags: ["bugs", "analysis", "quality"]
|
|
7397
|
-
},
|
|
7398
|
-
{
|
|
7399
|
-
name: "checkdocs",
|
|
7400
|
-
displayName: "Check Docs",
|
|
7401
|
-
description: "Checks for missing documentation and creates tasks",
|
|
7402
|
-
version: "0.2.1",
|
|
7403
|
-
category: "Code Quality",
|
|
7404
|
-
event: "PostToolUse",
|
|
7405
|
-
matcher: "Edit|Write|NotebookEdit",
|
|
7406
|
-
tags: ["docs", "documentation", "quality"]
|
|
7407
|
-
},
|
|
7408
|
-
{
|
|
7409
|
-
name: "checktasks",
|
|
7410
|
-
displayName: "Check Tasks",
|
|
7411
|
-
description: "Validates task completion and tracks progress",
|
|
7412
|
-
version: "1.0.8",
|
|
7413
|
-
category: "Code Quality",
|
|
7414
|
-
event: "PostToolUse",
|
|
7415
|
-
matcher: "Edit|Write|NotebookEdit",
|
|
7416
|
-
tags: ["tasks", "tracking", "quality"]
|
|
7417
|
-
},
|
|
7418
|
-
{
|
|
7419
|
-
name: "checksecurity",
|
|
7420
|
-
displayName: "Check Security",
|
|
7421
|
-
description: "Runs security checks via headless agents",
|
|
7422
|
-
version: "0.1.6",
|
|
7423
|
-
category: "Security",
|
|
7424
|
-
event: "PostToolUse",
|
|
7425
|
-
matcher: "Edit|Write|NotebookEdit",
|
|
7426
|
-
tags: ["security", "audit", "vulnerabilities"]
|
|
7427
|
-
},
|
|
7428
|
-
{
|
|
7429
|
-
name: "packageage",
|
|
7430
|
-
displayName: "Package Age",
|
|
7431
|
-
description: "Checks package age before install to prevent typosquatting",
|
|
7432
|
-
version: "0.1.1",
|
|
7433
|
-
category: "Security",
|
|
7434
|
-
event: "PreToolUse",
|
|
7435
|
-
matcher: "Bash",
|
|
7436
|
-
tags: ["npm", "packages", "typosquatting", "supply-chain"]
|
|
7437
|
-
},
|
|
7438
|
-
{
|
|
7439
|
-
name: "pre-bash",
|
|
7440
|
-
displayName: "Pre Bash",
|
|
7441
|
-
description: "Codewith Bash gate for staged secrets scans before commit/push and comms rechecks before risky operations",
|
|
7442
|
-
version: "0.1.0",
|
|
7443
|
-
category: "Security",
|
|
7444
|
-
event: "PreToolUse",
|
|
7445
|
-
matcher: "Bash",
|
|
7446
|
-
tags: ["codewith", "bash", "secrets", "gitleaks", "risky-ops"]
|
|
7447
|
-
},
|
|
7448
|
-
{
|
|
7449
|
-
name: "scanoutput",
|
|
7450
|
-
displayName: "Scan Output",
|
|
7451
|
-
description: "Scans tool output for credential shapes and warns. Detection only \u2014 the output is already persisted when this runs; it cannot redact or prevent",
|
|
7452
|
-
version: "0.1.0",
|
|
7453
|
-
category: "Security",
|
|
7454
|
-
event: "PostToolUse",
|
|
7455
|
-
matcher: "Bash",
|
|
7456
|
-
tags: ["security", "credentials", "secrets", "detection", "audit"]
|
|
7457
|
-
},
|
|
7458
|
-
{
|
|
7459
|
-
name: "signed-link-guard",
|
|
7460
|
-
displayName: "Signed Link Guard",
|
|
7461
|
-
description: "Refuses gh reads that would print composite GitHub content (bodies, comments, reviews, commit messages, check links and details, raw issue/PR/check API objects) where signed action links appear; bounded scalar projections, diffs, lists and writes pass",
|
|
7462
|
-
version: "0.1.0",
|
|
7463
|
-
category: "Security",
|
|
7464
|
-
event: "PreToolUse",
|
|
7465
|
-
matcher: "^(Bash|Monitor)$",
|
|
7466
|
-
tags: ["github", "gh", "signed-links", "capabilities", "transcript", "guard", "security"],
|
|
7467
|
-
timeoutSeconds: 10
|
|
7468
|
-
},
|
|
7469
|
-
{
|
|
7470
|
-
name: "signed-link-output",
|
|
7471
|
-
displayName: "Signed Link Output",
|
|
7472
|
-
description: "Claude PostToolUse backstop: replaces capability links in tool output \u2014 signature-class query or fragment parameters, and anchored path-borne provider classes such as the Stripe Connect onboarding link \u2014 with a redaction marker (updatedToolOutput, where the running Claude Code supports it) and tells the model not to repeat or store the link. Every string is walked, so nested metadata such as a browser result's `_meta.browser_use.url` is covered. It runs after the tool, so it cannot undo display or other persistence",
|
|
7473
|
-
version: "0.1.1",
|
|
7474
|
-
category: "Security",
|
|
7475
|
-
event: "PostToolUse",
|
|
7476
|
-
matcher: "^(Bash|WebFetch|mcp__.*)$",
|
|
7477
|
-
tags: ["github", "signed-links", "capabilities", "redaction", "transcript", "security"],
|
|
7478
|
-
timeoutSeconds: 10
|
|
7479
|
-
},
|
|
7480
|
-
{
|
|
7481
|
-
name: "phonenotify",
|
|
7482
|
-
displayName: "Phone Notify",
|
|
7483
|
-
description: "Sends push notifications to phone via ntfy.sh",
|
|
7484
|
-
version: "0.1.0",
|
|
7485
|
-
category: "Notifications",
|
|
7486
|
-
event: "Stop",
|
|
7487
|
-
matcher: "",
|
|
7488
|
-
tags: ["notification", "phone", "push", "ntfy"]
|
|
7489
|
-
},
|
|
7490
|
-
{
|
|
7491
|
-
name: "agentmessages",
|
|
7492
|
-
displayName: "Agent Messages",
|
|
7493
|
-
description: "Inter-agent messaging integration for service-message",
|
|
7494
|
-
version: "0.1.0",
|
|
7495
|
-
category: "Notifications",
|
|
7496
|
-
event: "Stop",
|
|
7497
|
-
matcher: "",
|
|
7498
|
-
tags: ["messaging", "agents", "inter-agent"]
|
|
7499
|
-
},
|
|
7500
|
-
{
|
|
7501
|
-
name: "contextrefresh",
|
|
7502
|
-
displayName: "Context Refresh",
|
|
7503
|
-
description: "Re-injects important context every N prompts to prevent drift",
|
|
7504
|
-
version: "0.1.0",
|
|
7505
|
-
category: "Context Management",
|
|
7506
|
-
event: "Notification",
|
|
7507
|
-
matcher: "",
|
|
7508
|
-
tags: ["context", "memory", "prompts", "refresh"]
|
|
7509
|
-
},
|
|
7510
|
-
{
|
|
7511
|
-
name: "precompact",
|
|
7512
|
-
displayName: "Pre-Compact",
|
|
7513
|
-
description: "Saves session state before context compaction",
|
|
7514
|
-
version: "0.1.0",
|
|
7515
|
-
category: "Context Management",
|
|
7516
|
-
event: "Notification",
|
|
7517
|
-
matcher: "",
|
|
7518
|
-
tags: ["context", "compaction", "state", "backup"]
|
|
7519
|
-
},
|
|
7520
|
-
{
|
|
7521
|
-
name: "knowledge-context",
|
|
7522
|
-
displayName: "Knowledge Context",
|
|
7523
|
-
description: "Injects deterministic Knowledge context packs into Codewith SessionStart, UserPromptSubmit, and SubagentStart",
|
|
7524
|
-
version: "0.1.6",
|
|
7525
|
-
category: "Context Management",
|
|
7526
|
-
event: "SessionStart",
|
|
7527
|
-
events: ["SessionStart", "UserPromptSubmit", "SubagentStart"],
|
|
7528
|
-
matcher: "",
|
|
7529
|
-
tags: ["knowledge", "context", "codewith", "deterministic", "session-start", "prompt", "subagent"]
|
|
7530
|
-
},
|
|
7531
|
-
{
|
|
7532
|
-
name: "mementos-context",
|
|
7533
|
-
displayName: "Mementos Prompt Context",
|
|
7534
|
-
description: "Retrieves scoped memories for a user prompt, with optional relevance judgments",
|
|
7535
|
-
version: "0.1.0",
|
|
7536
|
-
category: "Context Management",
|
|
7537
|
-
event: "UserPromptSubmit",
|
|
7538
|
-
matcher: "",
|
|
7539
|
-
timeoutSeconds: 12,
|
|
7540
|
-
tags: ["mementos", "memory", "prompt", "codex", "claude", "codewith", "opt-in"]
|
|
7541
|
-
},
|
|
7542
|
-
{
|
|
7543
|
-
name: "autoformat",
|
|
7544
|
-
displayName: "Auto Format",
|
|
7545
|
-
description: "Runs project formatter (Prettier, Biome, Ruff, Black, gofmt) after file edits",
|
|
7546
|
-
version: "0.1.0",
|
|
7547
|
-
category: "Workflow Automation",
|
|
7548
|
-
event: "PostToolUse",
|
|
7549
|
-
matcher: "Edit|Write",
|
|
7550
|
-
tags: ["format", "prettier", "biome", "ruff", "black", "gofmt", "style"]
|
|
7551
|
-
},
|
|
7552
|
-
{
|
|
7553
|
-
name: "autostage",
|
|
7554
|
-
displayName: "Auto Stage",
|
|
7555
|
-
description: "Automatically git-stages files after Claude edits them",
|
|
7556
|
-
version: "0.1.0",
|
|
7557
|
-
category: "Workflow Automation",
|
|
7558
|
-
event: "PostToolUse",
|
|
7559
|
-
matcher: "Edit|Write",
|
|
7560
|
-
tags: ["git", "stage", "add", "auto"]
|
|
7561
|
-
},
|
|
7562
|
-
{
|
|
7563
|
-
name: "tddguard",
|
|
7564
|
-
displayName: "TDD Guard",
|
|
7565
|
-
description: "Blocks implementation edits unless corresponding test files exist",
|
|
7566
|
-
version: "0.1.0",
|
|
7567
|
-
category: "Workflow Automation",
|
|
7568
|
-
event: "PreToolUse",
|
|
7569
|
-
matcher: "Edit|Write",
|
|
7570
|
-
tags: ["tdd", "tests", "red-green-refactor", "enforcement"]
|
|
7571
|
-
},
|
|
7572
|
-
{
|
|
7573
|
-
name: "envsetup",
|
|
7574
|
-
displayName: "Env Setup",
|
|
7575
|
-
description: "Warns when nvm, virtualenv, asdf, or rbenv may need activation before commands",
|
|
7576
|
-
version: "0.1.0",
|
|
7577
|
-
category: "Environment",
|
|
7578
|
-
event: "PreToolUse",
|
|
7579
|
-
matcher: "Bash",
|
|
7580
|
-
tags: ["nvm", "virtualenv", "asdf", "rbenv", "environment", "python", "node"]
|
|
7581
|
-
},
|
|
7582
|
-
{
|
|
7583
|
-
name: "permissionguard",
|
|
7584
|
-
displayName: "Permission Guard",
|
|
7585
|
-
description: "Auto-approves safe read-only commands and blocks dangerous operations",
|
|
7586
|
-
version: "0.1.0",
|
|
7587
|
-
category: "Permissions",
|
|
7588
|
-
event: "PreToolUse",
|
|
7589
|
-
matcher: "Bash",
|
|
7590
|
-
tags: ["permission", "allowlist", "blocklist", "safety", "auto-approve"]
|
|
7591
|
-
},
|
|
7592
|
-
{
|
|
7593
|
-
name: "protectfiles",
|
|
7594
|
-
displayName: "Protect Files",
|
|
7595
|
-
description: "Blocks access to .env, secrets, SSH keys, and lock files",
|
|
7596
|
-
version: "0.1.0",
|
|
7597
|
-
category: "Permissions",
|
|
7598
|
-
event: "PreToolUse",
|
|
7599
|
-
matcher: "Edit|Write|Read|Bash",
|
|
7600
|
-
tags: ["security", "env", "secrets", "keys", "lock-files", "protect"]
|
|
7601
|
-
},
|
|
7602
|
-
{
|
|
7603
|
-
name: "promptguard",
|
|
7604
|
-
displayName: "Prompt Guard",
|
|
7605
|
-
description: "Blocks prompt injection attempts and credential access requests",
|
|
7606
|
-
version: "0.1.0",
|
|
7607
|
-
category: "Permissions",
|
|
7608
|
-
event: "PreToolUse",
|
|
7609
|
-
matcher: "",
|
|
7610
|
-
tags: ["prompt", "injection", "security", "validation", "guard"]
|
|
7611
|
-
},
|
|
7612
|
-
{
|
|
7613
|
-
name: "prompt-guard",
|
|
7614
|
-
displayName: "Prompt Guard (Codewith)",
|
|
7615
|
-
description: "Codewith UserPromptSubmit guard for obvious pasted prompt-injection and fake policy/freeze instructions",
|
|
7616
|
-
version: "0.1.0",
|
|
7617
|
-
category: "Permissions",
|
|
7618
|
-
event: "UserPromptSubmit",
|
|
7619
|
-
matcher: "",
|
|
7620
|
-
tags: ["codewith", "prompt", "injection", "policy", "freeze"]
|
|
7621
|
-
},
|
|
7622
|
-
{
|
|
7623
|
-
name: "desktopnotify",
|
|
7624
|
-
displayName: "Desktop Notify",
|
|
7625
|
-
description: "Sends native desktop notifications via osascript (macOS) or notify-send (Linux)",
|
|
7626
|
-
version: "0.1.0",
|
|
7627
|
-
category: "Notifications",
|
|
7628
|
-
event: "Stop",
|
|
7629
|
-
matcher: "",
|
|
7630
|
-
tags: ["notification", "desktop", "macos", "linux", "native"]
|
|
7631
|
-
},
|
|
7632
|
-
{
|
|
7633
|
-
name: "slacknotify",
|
|
7634
|
-
displayName: "Slack Notify",
|
|
7635
|
-
description: "Sends Slack webhook notifications when Claude finishes",
|
|
7636
|
-
version: "0.1.0",
|
|
7637
|
-
category: "Notifications",
|
|
7638
|
-
event: "Stop",
|
|
7639
|
-
matcher: "",
|
|
7640
|
-
tags: ["notification", "slack", "webhook", "team"]
|
|
7641
|
-
},
|
|
7642
|
-
{
|
|
7643
|
-
name: "soundnotify",
|
|
7644
|
-
displayName: "Sound Notify",
|
|
7645
|
-
description: "Plays a system sound when Claude finishes (macOS/Linux)",
|
|
7646
|
-
version: "0.1.0",
|
|
7647
|
-
category: "Notifications",
|
|
7648
|
-
event: "Stop",
|
|
7649
|
-
matcher: "",
|
|
7650
|
-
tags: ["notification", "sound", "audio", "alert"]
|
|
7651
|
-
},
|
|
7652
|
-
{
|
|
7653
|
-
name: "sessionlog",
|
|
7654
|
-
displayName: "Session Log",
|
|
7655
|
-
description: `Logs every tool call to SQLite (${getReportedDbPath()})`,
|
|
7656
|
-
version: "0.1.0",
|
|
7657
|
-
category: "Observability",
|
|
7658
|
-
event: "PostToolUse",
|
|
7659
|
-
matcher: "",
|
|
7660
|
-
tags: ["logging", "audit", "session", "history", "jsonl"]
|
|
7661
|
-
},
|
|
7662
|
-
{
|
|
7663
|
-
name: "commandlog",
|
|
7664
|
-
displayName: "Command Log",
|
|
7665
|
-
description: `Logs every Bash command to SQLite (${getReportedDbPath()})`,
|
|
7666
|
-
version: "0.1.0",
|
|
7667
|
-
category: "Observability",
|
|
7668
|
-
event: "PostToolUse",
|
|
7669
|
-
matcher: "Bash",
|
|
7670
|
-
tags: ["logging", "bash", "commands", "audit"]
|
|
7671
|
-
},
|
|
7672
|
-
{
|
|
7673
|
-
name: "costwatch",
|
|
7674
|
-
displayName: "Cost Watch",
|
|
7675
|
-
description: "Estimates session token usage, persists cost history to SQLite, and warns on budget overrun",
|
|
7676
|
-
version: "0.1.0",
|
|
7677
|
-
category: "Observability",
|
|
7678
|
-
event: "Stop",
|
|
7679
|
-
matcher: "",
|
|
7680
|
-
tags: ["cost", "tokens", "budget", "usage", "monitoring"]
|
|
7681
|
-
},
|
|
7682
|
-
{
|
|
7683
|
-
name: "errornotify",
|
|
7684
|
-
displayName: "Error Notify",
|
|
7685
|
-
description: `Detects tool failures and logs errors to SQLite (${getReportedDbPath()})`,
|
|
7686
|
-
version: "0.1.0",
|
|
7687
|
-
category: "Observability",
|
|
7688
|
-
event: "PostToolUse",
|
|
7689
|
-
matcher: "",
|
|
7690
|
-
tags: ["errors", "failures", "logging", "debugging"]
|
|
7691
|
-
},
|
|
7692
|
-
{
|
|
7693
|
-
name: "spiral-detector",
|
|
7694
|
-
displayName: "Spiral Detector",
|
|
7695
|
-
description: "Interrupts sessions after five consecutive identical command failures",
|
|
7696
|
-
version: "0.1.0",
|
|
7697
|
-
category: "Observability",
|
|
7698
|
-
event: "PostToolUse",
|
|
7699
|
-
matcher: "",
|
|
7700
|
-
tags: ["spiral", "failures", "retries", "safety", "interrupt"]
|
|
7701
|
-
},
|
|
7702
|
-
{
|
|
7703
|
-
name: "scratch-lifecycle",
|
|
7704
|
-
bundledEntry: "bin/hooks/scratch-lifecycle.js",
|
|
7705
|
-
displayName: "Scratch Lifecycle",
|
|
7706
|
-
description: "Records owner, purpose and disposal for each session scratch tree in its Scratchpad manifest, and the close time at session end",
|
|
7707
|
-
version: "0.1.0",
|
|
7708
|
-
category: "Observability",
|
|
7709
|
-
event: "SessionStart",
|
|
7710
|
-
events: ["SessionStart", "SessionEnd"],
|
|
7711
|
-
nativeTargetDispatch: true,
|
|
7712
|
-
timeoutSeconds: 15,
|
|
7713
|
-
matcher: "",
|
|
7714
|
-
tags: ["scratch", "lifecycle", "session", "census", "retention"]
|
|
7715
|
-
},
|
|
7716
|
-
{
|
|
7717
|
-
name: "stylescheck",
|
|
7718
|
-
displayName: "Styles Check",
|
|
7719
|
-
description: "Blocks frontend files with design anti-patterns: hardcoded colors, magic font sizes, inline styles",
|
|
7720
|
-
version: "0.1.0",
|
|
7721
|
-
category: "Code Quality",
|
|
7722
|
-
event: "PreToolUse",
|
|
7723
|
-
matcher: "Write|Edit",
|
|
7724
|
-
tags: ["design", "styles", "frontend", "css", "tailwind", "design-system", "anti-patterns"]
|
|
7725
|
-
},
|
|
7726
|
-
{
|
|
7727
|
-
name: "taskgate",
|
|
7728
|
-
displayName: "Task Gate",
|
|
7729
|
-
description: "Validates task completion criteria before allowing tasks to be marked done",
|
|
7730
|
-
version: "0.1.0",
|
|
7731
|
-
category: "Agent Teams",
|
|
7732
|
-
event: "PostToolUse",
|
|
7733
|
-
matcher: "",
|
|
7734
|
-
tags: ["tasks", "completion", "gate", "quality", "agent-teams"]
|
|
7735
|
-
},
|
|
7736
|
-
{
|
|
7737
|
-
name: "session-start",
|
|
7738
|
-
displayName: "Session Start",
|
|
7739
|
-
description: "Codewith SessionStart digest for blockers, announcements, identity registration, and heartbeat context",
|
|
7740
|
-
version: "0.1.0",
|
|
7741
|
-
category: "Agent Teams",
|
|
7742
|
-
event: "SessionStart",
|
|
7743
|
-
matcher: "",
|
|
7744
|
-
tags: ["codewith", "session", "context", "conversations", "heartbeat"]
|
|
7745
|
-
},
|
|
7746
|
-
{
|
|
7747
|
-
name: "stop-review",
|
|
7748
|
-
bundledEntry: "bin/hooks/stop-review.js",
|
|
7749
|
-
displayName: "Stop Review",
|
|
7750
|
-
description: "Reviews turn completion against the latest user request and active goal",
|
|
7751
|
-
version: "0.1.1",
|
|
7752
|
-
category: "Agent Teams",
|
|
7753
|
-
event: "Stop",
|
|
7754
|
-
events: ["Stop"],
|
|
7755
|
-
nativeTargetDispatch: true,
|
|
7756
|
-
timeoutSeconds: 20,
|
|
7757
|
-
matcher: "",
|
|
7758
|
-
tags: ["stop", "goals", "continuity", "review"]
|
|
7759
|
-
},
|
|
7760
|
-
{
|
|
7761
|
-
name: "stop-sync",
|
|
7762
|
-
displayName: "Stop Sync",
|
|
7763
|
-
description: "Codewith Stop turn-end heartbeat and best-effort task evidence helper",
|
|
7764
|
-
version: "0.1.0",
|
|
7765
|
-
category: "Agent Teams",
|
|
7766
|
-
event: "Stop",
|
|
7767
|
-
matcher: "",
|
|
7768
|
-
tags: ["codewith", "stop", "heartbeat", "todos", "turn-end"]
|
|
7769
|
-
},
|
|
7770
|
-
{
|
|
7771
|
-
name: "typecheck-gate",
|
|
7772
|
-
displayName: "Typecheck Gate",
|
|
7773
|
-
description: "Runs TypeScript type checking on Stop and blocks if type errors are found",
|
|
7774
|
-
version: "0.1.0",
|
|
7775
|
-
category: "Code Quality",
|
|
7776
|
-
event: "Stop",
|
|
7777
|
-
matcher: "",
|
|
7778
|
-
tags: ["typescript", "typecheck", "types", "quality", "gate"]
|
|
7779
|
-
},
|
|
7780
|
-
{
|
|
7781
|
-
name: "affected-tests",
|
|
7782
|
-
displayName: "Affected Tests",
|
|
7783
|
-
description: "Maps edited files to their test files and runs them automatically after edits",
|
|
7784
|
-
version: "0.1.0",
|
|
7785
|
-
category: "Code Quality",
|
|
7786
|
-
event: "PostToolUse",
|
|
7787
|
-
matcher: "Edit|Write|NotebookEdit",
|
|
7788
|
-
tags: ["tests", "test-runner", "affected", "quality"]
|
|
7789
|
-
},
|
|
7790
|
-
{
|
|
7791
|
-
name: "conflict-detect",
|
|
7792
|
-
displayName: "Conflict Detect",
|
|
7793
|
-
description: "Blocks edits on files with unresolved git merge conflict markers",
|
|
7794
|
-
version: "0.1.0",
|
|
7795
|
-
category: "Git Safety",
|
|
7796
|
-
event: "PreToolUse",
|
|
7797
|
-
matcher: "Edit|Write",
|
|
7798
|
-
tags: ["git", "conflicts", "merge", "safety"]
|
|
7799
|
-
},
|
|
7800
|
-
{
|
|
7801
|
-
name: "failure-to-task",
|
|
7802
|
-
displayName: "Failure to Task",
|
|
7803
|
-
description: "Creates a todo task automatically when test or build commands fail",
|
|
7804
|
-
version: "0.1.0",
|
|
7805
|
-
category: "Workflow Automation",
|
|
7806
|
-
event: "PostToolUse",
|
|
7807
|
-
matcher: "Bash",
|
|
7808
|
-
tags: ["failures", "tasks", "tests", "build", "automation"]
|
|
7809
|
-
},
|
|
7810
|
-
{
|
|
7811
|
-
name: "job-folder-guard",
|
|
7812
|
-
displayName: "Job Folder Guard",
|
|
7813
|
-
description: "Adds a notice to the model's context when a Write, Edit, MultiEdit, NotebookEdit or Bash command writes to or uses a harness job folder (<path>/jobs/<id>/tmp/, a Claude Code or Switcher job folder), naming the session's Scratchpad folder instead; never blocks and never changes the permission flow",
|
|
7814
|
-
version: "0.1.0",
|
|
7815
|
-
category: "Workflow Automation",
|
|
7816
|
-
event: "PreToolUse",
|
|
7817
|
-
matcher: "^(Write|Edit|MultiEdit|NotebookEdit|Bash)$",
|
|
7818
|
-
tags: ["scratch", "scratchpad", "jobs", "switcher", "notice"],
|
|
7819
|
-
timeoutSeconds: 5
|
|
7820
|
-
},
|
|
7821
|
-
{
|
|
7822
|
-
name: "filelock",
|
|
7823
|
-
displayName: "File Lock",
|
|
7824
|
-
description: "Auto-checks file locks before edits to prevent multi-agent conflicts",
|
|
7825
|
-
version: "0.1.0",
|
|
7826
|
-
category: "Agent Teams",
|
|
7827
|
-
event: "PreToolUse",
|
|
7828
|
-
matcher: "Edit|Write|NotebookEdit",
|
|
7829
|
-
tags: ["locking", "coordination", "multi-agent", "conflict"]
|
|
7830
|
-
},
|
|
7831
|
-
{
|
|
7832
|
-
name: "announce-start",
|
|
7833
|
-
displayName: "Announce Start",
|
|
7834
|
-
description: "On SessionStart, auto-registers agent, reads messages, and announces to space",
|
|
7835
|
-
version: "0.2.0",
|
|
7836
|
-
category: "Agent Teams",
|
|
7837
|
-
event: "SessionStart",
|
|
7838
|
-
matcher: "",
|
|
7839
|
-
tags: ["announcement", "start", "register", "messages", "agent-teams"]
|
|
7840
|
-
},
|
|
7841
|
-
{
|
|
7842
|
-
name: "announce-stop",
|
|
7843
|
-
displayName: "Announce Stop",
|
|
7844
|
-
description: "On Stop, releases file locks, posts session summary, and updates task statuses",
|
|
7845
|
-
version: "0.1.0",
|
|
7846
|
-
category: "Agent Teams",
|
|
7847
|
-
event: "Stop",
|
|
7848
|
-
matcher: "",
|
|
7849
|
-
tags: ["announcement", "stop", "locks", "summary", "agent-teams"]
|
|
7850
|
-
},
|
|
7851
|
-
{
|
|
7852
|
-
name: "dm-inject",
|
|
7853
|
-
displayName: "DM Inject",
|
|
7854
|
-
description: "Injects unread direct messages into agent context on Notification events",
|
|
7855
|
-
version: "0.1.0",
|
|
7856
|
-
category: "Agent Teams",
|
|
7857
|
-
event: "Notification",
|
|
7858
|
-
matcher: "",
|
|
7859
|
-
tags: ["messages", "dm", "context", "inject", "agent-teams"]
|
|
7860
|
-
},
|
|
7861
|
-
{
|
|
7862
|
-
name: "fleet-catchup",
|
|
7863
|
-
displayName: "Fleet Catchup",
|
|
7864
|
-
description: "On SessionStart, injects unread blockers, channel notifications, and the announcements digest into context (deterministic CLI reads, fail-open)",
|
|
7865
|
-
version: "0.1.0",
|
|
7866
|
-
category: "Agent Teams",
|
|
7867
|
-
event: "SessionStart",
|
|
7868
|
-
matcher: "",
|
|
7869
|
-
tags: ["fleet", "catchup", "blockers", "announcements", "context", "agent-teams"]
|
|
7870
|
-
},
|
|
7871
|
-
{
|
|
7872
|
-
name: "agent-rules-version-check",
|
|
7873
|
-
displayName: "Agent Rules Version Check",
|
|
7874
|
-
description: "On SessionStart, compares the rendered hasna:agent-operating-rules sentinel version against configs state and warns on mismatch",
|
|
7875
|
-
version: "0.1.0",
|
|
7876
|
-
category: "Agent Teams",
|
|
7877
|
-
event: "SessionStart",
|
|
7878
|
-
matcher: "",
|
|
7879
|
-
tags: ["fleet", "rules", "version", "sentinel", "configs", "drift", "agent-teams"]
|
|
7880
|
-
},
|
|
7881
|
-
{
|
|
7882
|
-
name: "fleet-blockers-gate",
|
|
7883
|
-
displayName: "Fleet Blockers Gate",
|
|
7884
|
-
description: "Before tool calls, blocks mutating tools while an unread [FREEZE] blocker is active (TTL-cached conversations check, fail-open <500ms)",
|
|
7885
|
-
version: "0.1.0",
|
|
7886
|
-
category: "Agent Teams",
|
|
7887
|
-
event: "PreToolUse",
|
|
7888
|
-
matcher: "",
|
|
7889
|
-
tags: ["fleet", "freeze", "blockers", "gate", "safety", "agent-teams"]
|
|
7890
|
-
}
|
|
7891
|
-
];
|
|
7892
|
-
function getHooksByCategory(category) {
|
|
7893
|
-
return HOOKS.filter((h) => h.category === category);
|
|
7894
|
-
}
|
|
7895
|
-
function getHookEvents(hook) {
|
|
7896
|
-
return hook.events && hook.events.length > 0 ? hook.events : [hook.event];
|
|
7897
|
-
}
|
|
7898
|
-
function searchHooks(query) {
|
|
7899
|
-
const q = query.toLowerCase();
|
|
7900
|
-
return HOOKS.filter((h) => h.name.toLowerCase().includes(q) || h.displayName.toLowerCase().includes(q) || h.description.toLowerCase().includes(q) || h.tags.some((t) => t.includes(q)));
|
|
7901
|
-
}
|
|
7902
|
-
function getHook(name) {
|
|
7903
|
-
return HOOKS.find((h) => h.name === name);
|
|
7904
|
-
}
|
|
8453
|
+
// src/index.ts
|
|
8454
|
+
init_registry();
|
|
8455
|
+
|
|
7905
8456
|
// src/lib/installer.ts
|
|
7906
|
-
|
|
7907
|
-
import {
|
|
8457
|
+
init_registry();
|
|
8458
|
+
import { existsSync as existsSync15, mkdirSync as mkdirSync13, readFileSync as readFileSync16, readdirSync as readdirSync13, realpathSync as realpathSync6, rmdirSync as rmdirSync4, unlinkSync as unlinkSync7, writeFileSync as writeFileSync11 } from "fs";
|
|
8459
|
+
import { join as join26, dirname as dirname19, basename as basename14, resolve as resolve29 } from "path";
|
|
7908
8460
|
import { homedir as homedir8 } from "os";
|
|
7909
|
-
import { fileURLToPath as
|
|
8461
|
+
import { fileURLToPath as fileURLToPath4 } from "url";
|
|
7910
8462
|
|
|
7911
8463
|
// src/lib/readiness-process.ts
|
|
7912
8464
|
var supervisor = String.raw`
|
|
@@ -7972,103 +8524,8 @@ var safeFailureCodes = new Set([
|
|
|
7972
8524
|
"plan_changed"
|
|
7973
8525
|
]);
|
|
7974
8526
|
|
|
7975
|
-
// src/lib/resolve.ts
|
|
7976
|
-
import { dirname as dirname2, join as join6 } from "path";
|
|
7977
|
-
import { existsSync as existsSync5 } from "fs";
|
|
7978
|
-
import { fileURLToPath } from "url";
|
|
7979
|
-
init_manifest();
|
|
7980
|
-
function resolveBundledHooksDir(moduleDir = dirname2(fileURLToPath(import.meta.url))) {
|
|
7981
|
-
const sourceLayout = join6(moduleDir, "..", "..", "hooks");
|
|
7982
|
-
if (existsSync5(join6(sourceLayout, "hook-gitguard")))
|
|
7983
|
-
return sourceLayout;
|
|
7984
|
-
return join6(moduleDir, "..", "hooks");
|
|
7985
|
-
}
|
|
7986
|
-
function resolveHookDir(name) {
|
|
7987
|
-
const custom2 = readCustomManifest(name);
|
|
7988
|
-
if (custom2)
|
|
7989
|
-
return customHookDir(name);
|
|
7990
|
-
const meta = getHook(shortManifestName(name));
|
|
7991
|
-
if (!meta)
|
|
7992
|
-
return;
|
|
7993
|
-
const short = shortManifestName(name);
|
|
7994
|
-
const bundledBase = resolveBundledHooksDir();
|
|
7995
|
-
const direct = join6(bundledBase, short);
|
|
7996
|
-
if (existsSync5(direct))
|
|
7997
|
-
return direct;
|
|
7998
|
-
const prefixed = join6(bundledBase, `hook-${short}`);
|
|
7999
|
-
return existsSync5(prefixed) ? prefixed : undefined;
|
|
8000
|
-
}
|
|
8001
|
-
function resolveScriptPath(name) {
|
|
8002
|
-
const custom2 = readCustomManifest(name);
|
|
8003
|
-
if (custom2)
|
|
8004
|
-
return custom2.scriptPath;
|
|
8005
|
-
const meta = getHook(shortManifestName(name));
|
|
8006
|
-
if (meta?.bundledEntry) {
|
|
8007
|
-
if (!/^bin\/hooks\/[a-z0-9-]+\.js$/.test(meta.bundledEntry))
|
|
8008
|
-
return;
|
|
8009
|
-
const bundle = join6(resolveBundledHooksDir(), "..", meta.bundledEntry);
|
|
8010
|
-
return existsSync5(bundle) ? bundle : undefined;
|
|
8011
|
-
}
|
|
8012
|
-
const dir = resolveHookDir(name);
|
|
8013
|
-
if (!dir)
|
|
8014
|
-
return;
|
|
8015
|
-
const script = join6(dir, "src", "hook.ts");
|
|
8016
|
-
return existsSync5(script) ? script : undefined;
|
|
8017
|
-
}
|
|
8018
|
-
function resolveHookMeta(name) {
|
|
8019
|
-
const custom2 = readCustomManifest(name);
|
|
8020
|
-
if (custom2) {
|
|
8021
|
-
const { manifest } = custom2;
|
|
8022
|
-
return {
|
|
8023
|
-
name: shortManifestName(manifest.name),
|
|
8024
|
-
displayName: manifest.description ? manifest.name : manifest.name,
|
|
8025
|
-
description: manifest.description ?? "Custom hook",
|
|
8026
|
-
version: manifest.version,
|
|
8027
|
-
category: "Workflow Automation",
|
|
8028
|
-
event: manifest.events[0] ?? "PostToolUse",
|
|
8029
|
-
events: manifest.events,
|
|
8030
|
-
matcher: "",
|
|
8031
|
-
tags: ["custom"],
|
|
8032
|
-
nativeTargetDispatch: manifest.nativeTargetDispatch,
|
|
8033
|
-
requiresFinalMessage: manifest.requires_final_message,
|
|
8034
|
-
requiresBlock: manifest.requires_block,
|
|
8035
|
-
timeoutSeconds: manifest.timeout_ms === undefined ? undefined : Math.ceil(manifest.timeout_ms / 1000)
|
|
8036
|
-
};
|
|
8037
|
-
}
|
|
8038
|
-
return getHook(shortManifestName(name));
|
|
8039
|
-
}
|
|
8040
|
-
function resolveHook(name) {
|
|
8041
|
-
const custom2 = readCustomManifest(name);
|
|
8042
|
-
if (custom2) {
|
|
8043
|
-
const meta2 = resolveHookMeta(name);
|
|
8044
|
-
return {
|
|
8045
|
-
name: shortManifestName(custom2.manifest.name),
|
|
8046
|
-
source: "custom",
|
|
8047
|
-
version: custom2.manifest.version,
|
|
8048
|
-
events: custom2.manifest.events,
|
|
8049
|
-
description: custom2.manifest.description ?? "Custom hook",
|
|
8050
|
-
scriptPath: custom2.scriptPath,
|
|
8051
|
-
meta: meta2,
|
|
8052
|
-
timeoutMs: custom2.manifest.timeout_ms ?? null
|
|
8053
|
-
};
|
|
8054
|
-
}
|
|
8055
|
-
const meta = getHook(shortManifestName(name));
|
|
8056
|
-
const scriptPath = resolveScriptPath(name);
|
|
8057
|
-
if (!meta || !scriptPath)
|
|
8058
|
-
return;
|
|
8059
|
-
return {
|
|
8060
|
-
name: shortManifestName(name),
|
|
8061
|
-
source: "bundled",
|
|
8062
|
-
version: meta.version,
|
|
8063
|
-
events: meta.events && meta.events.length > 0 ? meta.events : [meta.event],
|
|
8064
|
-
description: meta.description,
|
|
8065
|
-
scriptPath,
|
|
8066
|
-
meta,
|
|
8067
|
-
timeoutMs: null
|
|
8068
|
-
};
|
|
8069
|
-
}
|
|
8070
|
-
|
|
8071
8527
|
// src/lib/installer.ts
|
|
8528
|
+
init_resolve();
|
|
8072
8529
|
init_manifest();
|
|
8073
8530
|
|
|
8074
8531
|
// src/lib/native-safety.ts
|
|
@@ -8458,6 +8915,9 @@ function installedNativeReadinessCommand(provider) {
|
|
|
8458
8915
|
return buildNativeReadinessCommand({ provider, home: realpathSync3(homedir4()), runtime, runtimeSHA256: pin(runtime, 200000000, true), worker, workerSHA256: pin(worker, 256000, false) });
|
|
8459
8916
|
}
|
|
8460
8917
|
|
|
8918
|
+
// src/lib/registration.ts
|
|
8919
|
+
init_resolve();
|
|
8920
|
+
|
|
8461
8921
|
// src/lib/mementos-options.ts
|
|
8462
8922
|
function validateMementosRegistration(name, value) {
|
|
8463
8923
|
if (value === undefined)
|
|
@@ -8778,16 +9238,16 @@ function matchersOverlap(a, b) {
|
|
|
8778
9238
|
init_store();
|
|
8779
9239
|
|
|
8780
9240
|
// src/lib/codex-settings.ts
|
|
8781
|
-
import { closeSync as
|
|
8782
|
-
import { dirname as
|
|
8783
|
-
import { createHash as
|
|
9241
|
+
import { closeSync as closeSync4, existsSync as existsSync10, lstatSync as lstatSync6, mkdirSync as mkdirSync6, openSync as openSync4, readFileSync as readFileSync8, renameSync as renameSync4, unlinkSync, writeFileSync as writeFileSync4 } from "fs";
|
|
9242
|
+
import { dirname as dirname8 } from "path";
|
|
9243
|
+
import { createHash as createHash7, randomUUID } from "crypto";
|
|
8784
9244
|
var snapshots = new WeakMap;
|
|
8785
9245
|
function current(path) {
|
|
8786
9246
|
try {
|
|
8787
|
-
const stat =
|
|
9247
|
+
const stat = lstatSync6(path);
|
|
8788
9248
|
if (!stat.isFile() || stat.isSymbolicLink() || stat.size > 1048576)
|
|
8789
9249
|
throw new Error("invalid_file");
|
|
8790
|
-
return
|
|
9250
|
+
return readFileSync8(path, "utf8");
|
|
8791
9251
|
} catch (error) {
|
|
8792
9252
|
if (error.code === "ENOENT")
|
|
8793
9253
|
return null;
|
|
@@ -8824,7 +9284,7 @@ function capturedCodexSettings(settings) {
|
|
|
8824
9284
|
function assertSettingsPreimage(raw, expected) {
|
|
8825
9285
|
if (expected === undefined)
|
|
8826
9286
|
return;
|
|
8827
|
-
if (!/^(?:absent|[a-f0-9]{64})$/.test(expected) || (raw === null ? "absent" :
|
|
9287
|
+
if (!/^(?:absent|[a-f0-9]{64})$/.test(expected) || (raw === null ? "absent" : createHash7("sha256").update(raw).digest("hex")) !== expected) {
|
|
8828
9288
|
throw new Error("Hook settings changed since planning; no settings were written.");
|
|
8829
9289
|
}
|
|
8830
9290
|
}
|
|
@@ -8838,11 +9298,11 @@ function writeCodexSettings(path, settings, expectedSha256, beforeWrite) {
|
|
|
8838
9298
|
` });
|
|
8839
9299
|
}
|
|
8840
9300
|
function writeHookSettingsPreimage(path, settings, before, beforeWrite) {
|
|
8841
|
-
|
|
9301
|
+
mkdirSync6(dirname8(path), { recursive: true, mode: 448 });
|
|
8842
9302
|
const lock = `${path}.hooks-write.lock`;
|
|
8843
9303
|
let fd;
|
|
8844
9304
|
try {
|
|
8845
|
-
fd =
|
|
9305
|
+
fd = openSync4(lock, "wx", 384);
|
|
8846
9306
|
} catch {
|
|
8847
9307
|
throw new Error("Codex settings are being edited; retry after the active writer finishes.");
|
|
8848
9308
|
}
|
|
@@ -8852,34 +9312,34 @@ function writeHookSettingsPreimage(path, settings, before, beforeWrite) {
|
|
|
8852
9312
|
throw new Error("Hook settings changed since reading; re-read before retrying.");
|
|
8853
9313
|
const next = JSON.stringify(settings, null, 2) + `
|
|
8854
9314
|
`;
|
|
8855
|
-
|
|
9315
|
+
writeFileSync4(temp, next, { flag: "wx", mode: 384 });
|
|
8856
9316
|
if (current(path) !== before)
|
|
8857
9317
|
throw new Error("Hook settings changed since reading; re-read before retrying.");
|
|
8858
9318
|
beforeWrite?.();
|
|
8859
|
-
|
|
9319
|
+
renameSync4(temp, path);
|
|
8860
9320
|
} finally {
|
|
8861
|
-
if (
|
|
9321
|
+
if (existsSync10(temp))
|
|
8862
9322
|
unlinkSync(temp);
|
|
8863
|
-
|
|
9323
|
+
closeSync4(fd);
|
|
8864
9324
|
unlinkSync(lock);
|
|
8865
9325
|
}
|
|
8866
9326
|
}
|
|
8867
9327
|
|
|
8868
9328
|
// src/lib/claude-skills-coordination.ts
|
|
8869
|
-
import { createHash as
|
|
8870
|
-
import { existsSync as
|
|
9329
|
+
import { createHash as createHash11 } from "crypto";
|
|
9330
|
+
import { existsSync as existsSync12, lstatSync as lstatSync7 } from "fs";
|
|
8871
9331
|
import { homedir as homedir7 } from "os";
|
|
8872
|
-
import { join as
|
|
9332
|
+
import { join as join19, resolve as resolve10 } from "path";
|
|
8873
9333
|
|
|
8874
9334
|
// node_modules/@hasna/skills/dist/index.js
|
|
8875
|
-
import { existsSync as
|
|
9335
|
+
import { existsSync as existsSync11 } from "fs";
|
|
8876
9336
|
import { homedir as homedir6 } from "os";
|
|
8877
|
-
import { join as
|
|
9337
|
+
import { join as join13, resolve as resolve6 } from "path";
|
|
8878
9338
|
import { homedir as pathsResolverHomedir2 } from "os";
|
|
8879
9339
|
import { join as pathsResolverJoin2 } from "path";
|
|
8880
|
-
import { createHash as
|
|
9340
|
+
import { createHash as createHash8 } from "crypto";
|
|
8881
9341
|
import { existsSync as existsSync52, readdirSync as readdirSync3, readFileSync as readFileSync42, statSync as statSync4 } from "fs";
|
|
8882
|
-
import { join as join52, sep as
|
|
9342
|
+
import { join as join52, sep as sep4 } from "path";
|
|
8883
9343
|
import { dirname as dirname32, join as join72, resolve as resolve22 } from "path";
|
|
8884
9344
|
import { createHash as createHash32 } from "crypto";
|
|
8885
9345
|
import { createHash as createHash22 } from "crypto";
|
|
@@ -8887,21 +9347,21 @@ import { lstatSync as lstatSync42, readFileSync as readFileSync62, readdirSync a
|
|
|
8887
9347
|
import { join as join82 } from "path";
|
|
8888
9348
|
import { createHash as createHash52 } from "crypto";
|
|
8889
9349
|
import { createHash as createHash42 } from "crypto";
|
|
8890
|
-
import { closeSync as closeSync22, constants as constants22, fstatSync as fstatSync22, lstatSync as
|
|
8891
|
-
import { basename as
|
|
8892
|
-
import { basename as basename5, isAbsolute as isAbsolute6, join as join92, resolve as
|
|
9350
|
+
import { closeSync as closeSync22, constants as constants22, fstatSync as fstatSync22, lstatSync as lstatSync52, openSync as openSync22, readSync } from "fs";
|
|
9351
|
+
import { basename as basename22, dirname as dirname42, isAbsolute as isAbsolute32, resolve as resolve32 } from "path";
|
|
9352
|
+
import { basename as basename5, isAbsolute as isAbsolute6, join as join92, resolve as resolve62, sep as sep32 } from "path";
|
|
8893
9353
|
import { createHash as createHash62 } from "crypto";
|
|
8894
|
-
import { basename as basename3, dirname as dirname52, isAbsolute as
|
|
8895
|
-
import { createHash as
|
|
8896
|
-
import { closeSync as closeSync32, constants as constants3, fstatSync as fstatSync3, lstatSync as
|
|
8897
|
-
import { basename as basename4, dirname as dirname62, isAbsolute as isAbsolute5, resolve as
|
|
9354
|
+
import { basename as basename3, dirname as dirname52, isAbsolute as isAbsolute42, resolve as resolve42 } from "path";
|
|
9355
|
+
import { createHash as createHash72 } from "crypto";
|
|
9356
|
+
import { closeSync as closeSync32, constants as constants3, fstatSync as fstatSync3, lstatSync as lstatSync62, openSync as openSync32, readSync as readSync2 } from "fs";
|
|
9357
|
+
import { basename as basename4, dirname as dirname62, isAbsolute as isAbsolute5, resolve as resolve52, sep as sep22 } from "path";
|
|
8898
9358
|
import { createHash as createHash33 } from "crypto";
|
|
8899
9359
|
import { lstatSync as lstatSync34, opendirSync as opendirSync6, readFileSync as readFileSync27, readdirSync as readdirSync14, realpathSync as realpathSync14 } from "fs";
|
|
8900
9360
|
import { basename as basename17, dirname as dirname30, isAbsolute as isAbsolute30, join as join42, relative as relative10, resolve as resolve28, sep as sep16 } from "path";
|
|
8901
9361
|
import { isDeepStrictEqual as isDeepStrictEqual9 } from "util";
|
|
8902
|
-
import { dirname as
|
|
8903
|
-
import { lstatSync as lstatSync8, readFileSync as
|
|
8904
|
-
import { dirname as
|
|
9362
|
+
import { dirname as dirname82, isAbsolute as isAbsolute9, join as join102, resolve as resolve7 } from "path";
|
|
9363
|
+
import { lstatSync as lstatSync8, readFileSync as readFileSync82, opendirSync } from "fs";
|
|
9364
|
+
import { dirname as dirname72, isAbsolute as isAbsolute8, sep as sep42 } from "path";
|
|
8905
9365
|
import { createHash as createHash9 } from "crypto";
|
|
8906
9366
|
import { lstatSync as lstatSync9, opendirSync as opendirSync2 } from "fs";
|
|
8907
9367
|
import { dirname as dirname9, isAbsolute as isAbsolute10, join as join112, resolve as resolve8 } from "path";
|
|
@@ -8909,7 +9369,7 @@ import { createHash as createHash10 } from "crypto";
|
|
|
8909
9369
|
import { closeSync as closeSync5, constants as constants5, fstatSync as fstatSync5, lstatSync as lstatSync10, openSync as openSync5, readSync as readSync3 } from "fs";
|
|
8910
9370
|
import { dirname as dirname10, isAbsolute as isAbsolute11, resolve as resolve9 } from "path";
|
|
8911
9371
|
import { createHash as createHash14, randomUUID as randomUUID2 } from "crypto";
|
|
8912
|
-
import { constants as constants7, closeSync as closeSync7, fchmodSync as fchmodSync2, fstatSync as fstatSync7, fsyncSync as fsyncSync3, linkSync as linkSync2, lstatSync as lstatSync12, mkdirSync as mkdirSync42, openSync as openSync7, opendirSync as opendirSync3, readSync as readSync5, renameSync as renameSync22, rmdirSync, rmSync, unlinkSync as unlinkSync2, writeSync as writeSync2 } from "fs";
|
|
9372
|
+
import { constants as constants7, closeSync as closeSync7, fchmodSync as fchmodSync2, fstatSync as fstatSync7, fsyncSync as fsyncSync3, linkSync as linkSync2, lstatSync as lstatSync12, mkdirSync as mkdirSync42, openSync as openSync7, opendirSync as opendirSync3, readSync as readSync5, renameSync as renameSync22, rmdirSync, rmSync as rmSync3, unlinkSync as unlinkSync2, writeSync as writeSync2 } from "fs";
|
|
8913
9373
|
import { dirname as dirname12, isAbsolute as isAbsolute13, join as join14, parse as parse4, resolve as resolve11 } from "path";
|
|
8914
9374
|
import { createHash as createHash13 } from "crypto";
|
|
8915
9375
|
import { createHash as createHash15 } from "crypto";
|
|
@@ -8931,14 +9391,14 @@ import { lstatSync as lstatSync17, readdirSync as readdirSync8, readFileSync as
|
|
|
8931
9391
|
import { lstatSync as lstatSync16, readdirSync as readdirSync7, readFileSync as readFileSync13, realpathSync as realpathSync7 } from "fs";
|
|
8932
9392
|
import { basename as basename8, dirname as dirname17, isAbsolute as isAbsolute18, join as join20, normalize as normalize3 } from "path";
|
|
8933
9393
|
import { createHash as createHash19 } from "crypto";
|
|
8934
|
-
import { fileURLToPath as
|
|
9394
|
+
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
8935
9395
|
import { spawn, spawnSync as spawnSync2 } from "child_process";
|
|
8936
|
-
import { closeSync as closeSync8, constants as constants8, fstatSync as fstatSync8, lstatSync as lstatSync14, openSync as openSync8, readFileSync as readFileSync11, realpathSync as
|
|
9396
|
+
import { closeSync as closeSync8, constants as constants8, fstatSync as fstatSync8, lstatSync as lstatSync14, openSync as openSync8, readFileSync as readFileSync11, realpathSync as realpathSync42 } from "fs";
|
|
8937
9397
|
import { dirname as dirname15, join as join17, parse as parse6, relative as relative3, resolve as resolve14, sep as sep7 } from "path";
|
|
8938
9398
|
import { AsyncLocalStorage } from "async_hooks";
|
|
8939
9399
|
import { execFileSync, spawnSync as spawnSync3 } from "child_process";
|
|
8940
9400
|
import { createHash as createHash20 } from "crypto";
|
|
8941
|
-
import { accessSync, constants as constants9, lstatSync as lstatSync15, mkdirSync as
|
|
9401
|
+
import { accessSync, constants as constants9, lstatSync as lstatSync15, mkdirSync as mkdirSync52, mkdtempSync, readdirSync as readdirSync6, readFileSync as readFileSync12, realpathSync as realpathSync5, rmSync as rmSync22, statSync as statSync7 } from "fs";
|
|
8942
9402
|
import { basename as basename7, delimiter, dirname as dirname16, isAbsolute as isAbsolute16, join as join18, relative as relative4, resolve as resolve15, sep as sep8 } from "path";
|
|
8943
9403
|
import { createHash as createHash23 } from "crypto";
|
|
8944
9404
|
import { closeSync as closeSync19, constants as constants20, fstatSync as fstatSync19, lstatSync as lstatSync32, openSync as openSync19, opendirSync as opendirSync5, readSync as readSync14 } from "fs";
|
|
@@ -8946,14 +9406,14 @@ import { basename as basename15, dirname as dirname28, isAbsolute as isAbsolute2
|
|
|
8946
9406
|
import { isAbsolute as isAbsolute27, join as join40, resolve as resolve25 } from "path";
|
|
8947
9407
|
import { createRequire } from "module";
|
|
8948
9408
|
import { createHash as createHash25, randomUUID as randomUUID3 } from "crypto";
|
|
8949
|
-
import { closeSync as closeSync12, constants as constants12, fstatSync as fstatSync12, fsyncSync as fsyncSync4, lstatSync as lstatSync22, mkdirSync as mkdirSync7, openSync as openSync12, readFileSync as readFileSync18, readSync as readSync7, readlinkSync as readlinkSync5, realpathSync as realpathSync10, renameSync as
|
|
9409
|
+
import { closeSync as closeSync12, constants as constants12, fstatSync as fstatSync12, fsyncSync as fsyncSync4, lstatSync as lstatSync22, mkdirSync as mkdirSync7, openSync as openSync12, readFileSync as readFileSync18, readSync as readSync7, readlinkSync as readlinkSync5, realpathSync as realpathSync10, renameSync as renameSync32, unlinkSync as unlinkSync4, writeFileSync as writeFileSync42 } from "fs";
|
|
8950
9410
|
import { dirname as dirname20, isAbsolute as isAbsolute21, join as join27, resolve as resolve18 } from "path";
|
|
8951
9411
|
import { isDeepStrictEqual as isDeepStrictEqual6 } from "util";
|
|
8952
9412
|
import { createHash as createHash26 } from "crypto";
|
|
8953
9413
|
import { constants as constants13, closeSync as closeSync13, fstatSync as fstatSync13, lstatSync as lstatSync23, openSync as openSync13, readSync as readSync8, readdirSync as readdirSync11, realpathSync as realpathSync11 } from "fs";
|
|
8954
9414
|
import { basename as basename11, dirname as dirname21, isAbsolute as isAbsolute22, join as join28, relative as relative8, resolve as resolve19, sep as sep12 } from "path";
|
|
8955
9415
|
import { createHash as createHash27 } from "crypto";
|
|
8956
|
-
import { closeSync as closeSync14, constants as constants14, fstatSync as fstatSync14, lstatSync as lstatSync24, openSync as openSync14, readSync as readSync9, renameSync as
|
|
9416
|
+
import { closeSync as closeSync14, constants as constants14, fstatSync as fstatSync14, lstatSync as lstatSync24, openSync as openSync14, readSync as readSync9, renameSync as renameSync42, unlinkSync as unlinkSync5, writeFileSync as writeFileSync5 } from "fs";
|
|
8957
9417
|
import { basename as basename12, dirname as dirname22, join as join29 } from "path";
|
|
8958
9418
|
import { lstatSync as lstatSync25, readFileSync as readFileSync19 } from "fs";
|
|
8959
9419
|
import { dirname as dirname23, join as join30, resolve as resolve20, sep as sep13 } from "path";
|
|
@@ -12573,10 +13033,10 @@ var require_resolve_block_map = __commonJS((exports) => {
|
|
|
12573
13033
|
let offset = bm.offset;
|
|
12574
13034
|
let commentEnd = null;
|
|
12575
13035
|
for (const collItem of bm.items) {
|
|
12576
|
-
const { start, key, sep:
|
|
13036
|
+
const { start, key, sep: sep43, value } = collItem;
|
|
12577
13037
|
const keyProps = resolveProps.resolveProps(start, {
|
|
12578
13038
|
indicator: "explicit-key-ind",
|
|
12579
|
-
next: key ??
|
|
13039
|
+
next: key ?? sep43?.[0],
|
|
12580
13040
|
offset,
|
|
12581
13041
|
onError,
|
|
12582
13042
|
parentIndent: bm.indent,
|
|
@@ -12590,7 +13050,7 @@ var require_resolve_block_map = __commonJS((exports) => {
|
|
|
12590
13050
|
else if ("indent" in key && key.indent !== bm.indent)
|
|
12591
13051
|
onError(offset, "BAD_INDENT", startColMsg);
|
|
12592
13052
|
}
|
|
12593
|
-
if (!keyProps.anchor && !keyProps.tag && !
|
|
13053
|
+
if (!keyProps.anchor && !keyProps.tag && !sep43) {
|
|
12594
13054
|
commentEnd = keyProps.end;
|
|
12595
13055
|
if (keyProps.comment) {
|
|
12596
13056
|
if (map.comment)
|
|
@@ -12615,7 +13075,7 @@ var require_resolve_block_map = __commonJS((exports) => {
|
|
|
12615
13075
|
ctx.atKey = false;
|
|
12616
13076
|
if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
|
|
12617
13077
|
onError(keyStart, "DUPLICATE_KEY", "Map keys must be unique");
|
|
12618
|
-
const valueProps = resolveProps.resolveProps(
|
|
13078
|
+
const valueProps = resolveProps.resolveProps(sep43 ?? [], {
|
|
12619
13079
|
indicator: "map-value-ind",
|
|
12620
13080
|
next: value,
|
|
12621
13081
|
offset: keyNode.range[2],
|
|
@@ -12631,7 +13091,7 @@ var require_resolve_block_map = __commonJS((exports) => {
|
|
|
12631
13091
|
if (ctx.options.strict && keyProps.start < valueProps.found.offset - 1024)
|
|
12632
13092
|
onError(keyNode.range, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit block mapping key");
|
|
12633
13093
|
}
|
|
12634
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset,
|
|
13094
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : composeEmptyNode(ctx, offset, sep43, null, valueProps, onError);
|
|
12635
13095
|
if (ctx.schema.compat)
|
|
12636
13096
|
utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
|
|
12637
13097
|
offset = valueNode.range[2];
|
|
@@ -12713,7 +13173,7 @@ var require_resolve_end = __commonJS((exports) => {
|
|
|
12713
13173
|
let comment = "";
|
|
12714
13174
|
if (end) {
|
|
12715
13175
|
let hasSpace = false;
|
|
12716
|
-
let
|
|
13176
|
+
let sep43 = "";
|
|
12717
13177
|
for (const token of end) {
|
|
12718
13178
|
const { source, type } = token;
|
|
12719
13179
|
switch (type) {
|
|
@@ -12727,13 +13187,13 @@ var require_resolve_end = __commonJS((exports) => {
|
|
|
12727
13187
|
if (!comment)
|
|
12728
13188
|
comment = cb;
|
|
12729
13189
|
else
|
|
12730
|
-
comment +=
|
|
12731
|
-
|
|
13190
|
+
comment += sep43 + cb;
|
|
13191
|
+
sep43 = "";
|
|
12732
13192
|
break;
|
|
12733
13193
|
}
|
|
12734
13194
|
case "newline":
|
|
12735
13195
|
if (comment)
|
|
12736
|
-
|
|
13196
|
+
sep43 += source;
|
|
12737
13197
|
hasSpace = true;
|
|
12738
13198
|
break;
|
|
12739
13199
|
default:
|
|
@@ -12771,18 +13231,18 @@ var require_resolve_flow_collection = __commonJS((exports) => {
|
|
|
12771
13231
|
let offset = fc.offset + fc.start.source.length;
|
|
12772
13232
|
for (let i = 0;i < fc.items.length; ++i) {
|
|
12773
13233
|
const collItem = fc.items[i];
|
|
12774
|
-
const { start, key, sep:
|
|
13234
|
+
const { start, key, sep: sep43, value } = collItem;
|
|
12775
13235
|
const props = resolveProps.resolveProps(start, {
|
|
12776
13236
|
flow: fcName,
|
|
12777
13237
|
indicator: "explicit-key-ind",
|
|
12778
|
-
next: key ??
|
|
13238
|
+
next: key ?? sep43?.[0],
|
|
12779
13239
|
offset,
|
|
12780
13240
|
onError,
|
|
12781
13241
|
parentIndent: fc.indent,
|
|
12782
13242
|
startOnNewline: false
|
|
12783
13243
|
});
|
|
12784
13244
|
if (!props.found) {
|
|
12785
|
-
if (!props.anchor && !props.tag && !
|
|
13245
|
+
if (!props.anchor && !props.tag && !sep43 && !value) {
|
|
12786
13246
|
if (i === 0 && props.comma)
|
|
12787
13247
|
onError(props.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${fcName}`);
|
|
12788
13248
|
else if (i < fc.items.length - 1)
|
|
@@ -12834,8 +13294,8 @@ var require_resolve_flow_collection = __commonJS((exports) => {
|
|
|
12834
13294
|
}
|
|
12835
13295
|
}
|
|
12836
13296
|
}
|
|
12837
|
-
if (!isMap && !
|
|
12838
|
-
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end,
|
|
13297
|
+
if (!isMap && !sep43 && !props.found) {
|
|
13298
|
+
const valueNode = value ? composeNode(ctx, value, props, onError) : composeEmptyNode(ctx, props.end, sep43, null, props, onError);
|
|
12839
13299
|
coll.items.push(valueNode);
|
|
12840
13300
|
offset = valueNode.range[2];
|
|
12841
13301
|
if (isBlock(value))
|
|
@@ -12847,7 +13307,7 @@ var require_resolve_flow_collection = __commonJS((exports) => {
|
|
|
12847
13307
|
if (isBlock(key))
|
|
12848
13308
|
onError(keyNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
12849
13309
|
ctx.atKey = false;
|
|
12850
|
-
const valueProps = resolveProps.resolveProps(
|
|
13310
|
+
const valueProps = resolveProps.resolveProps(sep43 ?? [], {
|
|
12851
13311
|
flow: fcName,
|
|
12852
13312
|
indicator: "map-value-ind",
|
|
12853
13313
|
next: value,
|
|
@@ -12858,8 +13318,8 @@ var require_resolve_flow_collection = __commonJS((exports) => {
|
|
|
12858
13318
|
});
|
|
12859
13319
|
if (valueProps.found) {
|
|
12860
13320
|
if (!isMap && !props.found && ctx.options.strict) {
|
|
12861
|
-
if (
|
|
12862
|
-
for (const st of
|
|
13321
|
+
if (sep43)
|
|
13322
|
+
for (const st of sep43) {
|
|
12863
13323
|
if (st === valueProps.found)
|
|
12864
13324
|
break;
|
|
12865
13325
|
if (st.type === "newline") {
|
|
@@ -12876,7 +13336,7 @@ var require_resolve_flow_collection = __commonJS((exports) => {
|
|
|
12876
13336
|
else
|
|
12877
13337
|
onError(valueProps.start, "MISSING_CHAR", `Missing , or : between ${fcName} items`);
|
|
12878
13338
|
}
|
|
12879
|
-
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end,
|
|
13339
|
+
const valueNode = value ? composeNode(ctx, value, valueProps, onError) : valueProps.found ? composeEmptyNode(ctx, valueProps.end, sep43, null, valueProps, onError) : null;
|
|
12880
13340
|
if (valueNode) {
|
|
12881
13341
|
if (isBlock(value))
|
|
12882
13342
|
onError(valueNode.range, "BLOCK_IN_FLOW", blockMsg);
|
|
@@ -13049,7 +13509,7 @@ var require_resolve_block_scalar = __commonJS((exports) => {
|
|
|
13049
13509
|
chompStart = i + 1;
|
|
13050
13510
|
}
|
|
13051
13511
|
let value = "";
|
|
13052
|
-
let
|
|
13512
|
+
let sep43 = "";
|
|
13053
13513
|
let prevMoreIndented = false;
|
|
13054
13514
|
for (let i = 0;i < contentStart; ++i)
|
|
13055
13515
|
value += lines[i][0].slice(trimIndent) + `
|
|
@@ -13067,33 +13527,33 @@ var require_resolve_block_scalar = __commonJS((exports) => {
|
|
|
13067
13527
|
indent = "";
|
|
13068
13528
|
}
|
|
13069
13529
|
if (type === Scalar.Scalar.BLOCK_LITERAL) {
|
|
13070
|
-
value +=
|
|
13071
|
-
|
|
13530
|
+
value += sep43 + indent.slice(trimIndent) + content;
|
|
13531
|
+
sep43 = `
|
|
13072
13532
|
`;
|
|
13073
13533
|
} else if (indent.length > trimIndent || content[0] === "\t") {
|
|
13074
|
-
if (
|
|
13075
|
-
|
|
13534
|
+
if (sep43 === " ")
|
|
13535
|
+
sep43 = `
|
|
13076
13536
|
`;
|
|
13077
|
-
else if (!prevMoreIndented &&
|
|
13537
|
+
else if (!prevMoreIndented && sep43 === `
|
|
13078
13538
|
`)
|
|
13079
|
-
|
|
13539
|
+
sep43 = `
|
|
13080
13540
|
|
|
13081
13541
|
`;
|
|
13082
|
-
value +=
|
|
13083
|
-
|
|
13542
|
+
value += sep43 + indent.slice(trimIndent) + content;
|
|
13543
|
+
sep43 = `
|
|
13084
13544
|
`;
|
|
13085
13545
|
prevMoreIndented = true;
|
|
13086
13546
|
} else if (content === "") {
|
|
13087
|
-
if (
|
|
13547
|
+
if (sep43 === `
|
|
13088
13548
|
`)
|
|
13089
13549
|
value += `
|
|
13090
13550
|
`;
|
|
13091
13551
|
else
|
|
13092
|
-
|
|
13552
|
+
sep43 = `
|
|
13093
13553
|
`;
|
|
13094
13554
|
} else {
|
|
13095
|
-
value +=
|
|
13096
|
-
|
|
13555
|
+
value += sep43 + content;
|
|
13556
|
+
sep43 = " ";
|
|
13097
13557
|
prevMoreIndented = false;
|
|
13098
13558
|
}
|
|
13099
13559
|
}
|
|
@@ -13272,27 +13732,27 @@ var require_resolve_flow_scalar = __commonJS((exports) => {
|
|
|
13272
13732
|
if (!match)
|
|
13273
13733
|
return source;
|
|
13274
13734
|
let res = match[1];
|
|
13275
|
-
let
|
|
13735
|
+
let sep43 = " ";
|
|
13276
13736
|
let pos = first.lastIndex;
|
|
13277
13737
|
line.lastIndex = pos;
|
|
13278
13738
|
while (match = line.exec(source)) {
|
|
13279
13739
|
if (match[1] === "") {
|
|
13280
|
-
if (
|
|
13740
|
+
if (sep43 === `
|
|
13281
13741
|
`)
|
|
13282
|
-
res +=
|
|
13742
|
+
res += sep43;
|
|
13283
13743
|
else
|
|
13284
|
-
|
|
13744
|
+
sep43 = `
|
|
13285
13745
|
`;
|
|
13286
13746
|
} else {
|
|
13287
|
-
res +=
|
|
13288
|
-
|
|
13747
|
+
res += sep43 + match[1];
|
|
13748
|
+
sep43 = " ";
|
|
13289
13749
|
}
|
|
13290
13750
|
pos = line.lastIndex;
|
|
13291
13751
|
}
|
|
13292
13752
|
const last = /[ \t]*(.*)/sy;
|
|
13293
13753
|
last.lastIndex = pos;
|
|
13294
13754
|
match = last.exec(source);
|
|
13295
|
-
return res +
|
|
13755
|
+
return res + sep43 + (match?.[1] ?? "");
|
|
13296
13756
|
}
|
|
13297
13757
|
function doubleQuotedValue(source, onError) {
|
|
13298
13758
|
let res = "";
|
|
@@ -14059,14 +14519,14 @@ var require_cst_stringify = __commonJS((exports) => {
|
|
|
14059
14519
|
}
|
|
14060
14520
|
}
|
|
14061
14521
|
}
|
|
14062
|
-
function stringifyItem({ start, key, sep:
|
|
14522
|
+
function stringifyItem({ start, key, sep: sep43, value }) {
|
|
14063
14523
|
let res = "";
|
|
14064
14524
|
for (const st of start)
|
|
14065
14525
|
res += st.source;
|
|
14066
14526
|
if (key)
|
|
14067
14527
|
res += stringifyToken(key);
|
|
14068
|
-
if (
|
|
14069
|
-
for (const st of
|
|
14528
|
+
if (sep43)
|
|
14529
|
+
for (const st of sep43)
|
|
14070
14530
|
res += st.source;
|
|
14071
14531
|
if (value)
|
|
14072
14532
|
res += stringifyToken(value);
|
|
@@ -15205,18 +15665,18 @@ var require_parser = __commonJS((exports) => {
|
|
|
15205
15665
|
if (this.type === "map-value-ind") {
|
|
15206
15666
|
const prev = getPrevProps(this.peek(2));
|
|
15207
15667
|
const start = getFirstKeyStartProps(prev);
|
|
15208
|
-
let
|
|
15668
|
+
let sep43;
|
|
15209
15669
|
if (scalar.end) {
|
|
15210
|
-
|
|
15211
|
-
|
|
15670
|
+
sep43 = scalar.end;
|
|
15671
|
+
sep43.push(this.sourceToken);
|
|
15212
15672
|
delete scalar.end;
|
|
15213
15673
|
} else
|
|
15214
|
-
|
|
15674
|
+
sep43 = [this.sourceToken];
|
|
15215
15675
|
const map = {
|
|
15216
15676
|
type: "block-map",
|
|
15217
15677
|
offset: scalar.offset,
|
|
15218
15678
|
indent: scalar.indent,
|
|
15219
|
-
items: [{ start, key: scalar, sep:
|
|
15679
|
+
items: [{ start, key: scalar, sep: sep43 }]
|
|
15220
15680
|
};
|
|
15221
15681
|
this.onKeyLine = true;
|
|
15222
15682
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -15370,15 +15830,15 @@ var require_parser = __commonJS((exports) => {
|
|
|
15370
15830
|
} else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
|
|
15371
15831
|
const start2 = getFirstKeyStartProps(it.start);
|
|
15372
15832
|
const key = it.key;
|
|
15373
|
-
const
|
|
15374
|
-
|
|
15833
|
+
const sep43 = it.sep;
|
|
15834
|
+
sep43.push(this.sourceToken);
|
|
15375
15835
|
delete it.key;
|
|
15376
15836
|
delete it.sep;
|
|
15377
15837
|
this.stack.push({
|
|
15378
15838
|
type: "block-map",
|
|
15379
15839
|
offset: this.offset,
|
|
15380
15840
|
indent: this.indent,
|
|
15381
|
-
items: [{ start: start2, key, sep:
|
|
15841
|
+
items: [{ start: start2, key, sep: sep43 }]
|
|
15382
15842
|
});
|
|
15383
15843
|
} else if (start.length > 0) {
|
|
15384
15844
|
it.sep = it.sep.concat(start, this.sourceToken);
|
|
@@ -15572,13 +16032,13 @@ var require_parser = __commonJS((exports) => {
|
|
|
15572
16032
|
const prev = getPrevProps(parent);
|
|
15573
16033
|
const start = getFirstKeyStartProps(prev);
|
|
15574
16034
|
fixFlowSeqItems(fc);
|
|
15575
|
-
const
|
|
15576
|
-
|
|
16035
|
+
const sep43 = fc.end.splice(1, fc.end.length);
|
|
16036
|
+
sep43.push(this.sourceToken);
|
|
15577
16037
|
const map = {
|
|
15578
16038
|
type: "block-map",
|
|
15579
16039
|
offset: fc.offset,
|
|
15580
16040
|
indent: fc.indent,
|
|
15581
|
-
items: [{ start, key: fc, sep:
|
|
16041
|
+
items: [{ start, key: fc, sep: sep43 }]
|
|
15582
16042
|
};
|
|
15583
16043
|
this.onKeyLine = true;
|
|
15584
16044
|
this.stack[this.stack.length - 1] = map;
|
|
@@ -15814,9 +16274,9 @@ function pathsResolverAssertApp2(app) {
|
|
|
15814
16274
|
}
|
|
15815
16275
|
function pathsResolverDataBaseDir(options) {
|
|
15816
16276
|
const env = options.env ?? process.env;
|
|
15817
|
-
const
|
|
15818
|
-
if (typeof
|
|
15819
|
-
return
|
|
16277
|
+
const override2 = env[PATHS_RESOLVER_DATA_ENV];
|
|
16278
|
+
if (typeof override2 === "string" && override2.length > 0)
|
|
16279
|
+
return override2;
|
|
15820
16280
|
const home = options.home ?? pathsResolverHomedir2();
|
|
15821
16281
|
const platform = options.platform ?? process.platform;
|
|
15822
16282
|
return platform === "darwin" ? pathsResolverJoin2(home, "Library", "Application Support", "Hasna") : pathsResolverJoin2(home, ".local", "share", "hasna");
|
|
@@ -15835,7 +16295,7 @@ function effectiveHome() {
|
|
|
15835
16295
|
return process.env["HOME"] || process.env["USERPROFILE"] || homedir6() || "/tmp";
|
|
15836
16296
|
}
|
|
15837
16297
|
function legacyDataRoot() {
|
|
15838
|
-
return
|
|
16298
|
+
return join13(effectiveHome(), ".hasna", "skills");
|
|
15839
16299
|
}
|
|
15840
16300
|
function resolverDataRoot(home = effectiveHome(), env) {
|
|
15841
16301
|
return dataDir2({ app: "skills", home, env });
|
|
@@ -15844,13 +16304,13 @@ function adoptResolverDataRoot2(resolved, env = process.env) {
|
|
|
15844
16304
|
const dataOverride = env.HASNA_DATA_HOME;
|
|
15845
16305
|
if (typeof dataOverride === "string" && dataOverride.trim().length > 0)
|
|
15846
16306
|
return true;
|
|
15847
|
-
return
|
|
16307
|
+
return existsSync11(join13(resolved, DEFAULT_SQLITE_FILENAME)) || existsSync11(join13(resolved, GLOBAL_CONFIG_FILENAME));
|
|
15848
16308
|
}
|
|
15849
16309
|
function exactDataRoot() {
|
|
15850
16310
|
for (const key of [DATA_DIR_ENV, HASNA_SKILLS_HOME_ENV, SKILLS_HOME_ENV]) {
|
|
15851
16311
|
const dir = process.env[key]?.trim();
|
|
15852
16312
|
if (dir)
|
|
15853
|
-
return
|
|
16313
|
+
return resolve6(dir);
|
|
15854
16314
|
}
|
|
15855
16315
|
return;
|
|
15856
16316
|
}
|
|
@@ -15859,7 +16319,7 @@ function getDataRoot() {
|
|
|
15859
16319
|
if (exact)
|
|
15860
16320
|
return exact;
|
|
15861
16321
|
const resolved = resolverDataRoot();
|
|
15862
|
-
return adoptResolverDataRoot2(resolved) ?
|
|
16322
|
+
return adoptResolverDataRoot2(resolved) ? resolve6(resolved) : resolve6(legacyDataRoot());
|
|
15863
16323
|
}
|
|
15864
16324
|
var GLOBAL_ONLY_KEYS = new Set(["sessionPinMigration", "driftReportProject", "driftReportAssignee", "driftReportTodosBin"]);
|
|
15865
16325
|
function getDataDirReadOnly() {
|
|
@@ -16054,7 +16514,7 @@ function collectDirectory(files, dir, rel) {
|
|
|
16054
16514
|
}
|
|
16055
16515
|
function collectFile(files, absolute, rel) {
|
|
16056
16516
|
const buffer = readFileSync42(absolute);
|
|
16057
|
-
files.push(normalizeBundleFile(rel.split(
|
|
16517
|
+
files.push(normalizeBundleFile(rel.split(sep4).join("/"), buffer));
|
|
16058
16518
|
}
|
|
16059
16519
|
function normalizeBundleFile(rel, buffer) {
|
|
16060
16520
|
if (rel === "skill.json") {
|
|
@@ -16079,7 +16539,7 @@ function* bundleHashParts(files) {
|
|
|
16079
16539
|
yield new TextEncoder().encode("\x00");
|
|
16080
16540
|
}
|
|
16081
16541
|
function hashBundleFiles(files) {
|
|
16082
|
-
const hash =
|
|
16542
|
+
const hash = createHash8(CONTENT_HASH_ALGORITHM);
|
|
16083
16543
|
for (const part of bundleHashParts(files))
|
|
16084
16544
|
hash.update(part);
|
|
16085
16545
|
return hash.digest("hex");
|
|
@@ -16590,7 +17050,7 @@ var sameFile = (a, b) => a.dev === b.dev && a.ino === b.ino && a.mode === b.mode
|
|
|
16590
17050
|
function parents(path) {
|
|
16591
17051
|
const result = [];
|
|
16592
17052
|
for (let at = dirname42(path);; at = dirname42(at)) {
|
|
16593
|
-
const stat =
|
|
17053
|
+
const stat = lstatSync52(at, { bigint: true });
|
|
16594
17054
|
need(stat.isDirectory() && !stat.isSymbolicLink(), "path traverses a symlink or non-directory");
|
|
16595
17055
|
result.push([at, stat]);
|
|
16596
17056
|
if (at === dirname42(at))
|
|
@@ -16599,13 +17059,13 @@ function parents(path) {
|
|
|
16599
17059
|
}
|
|
16600
17060
|
function readNativeSettingsWitnessFile(path, budget, filename = "settings.json") {
|
|
16601
17061
|
absolutePath(path);
|
|
16602
|
-
need(
|
|
17062
|
+
need(basename22(path) === filename, `requires ${filename}`);
|
|
16603
17063
|
return readNativeDiscoveryWitnessFile(path, budget);
|
|
16604
17064
|
}
|
|
16605
17065
|
function readNativeDiscoveryWitnessFile(path, budget) {
|
|
16606
17066
|
absolutePath(path);
|
|
16607
17067
|
need(Number.isSafeInteger(budget.remaining) && budget.remaining >= 0, "has an invalid byte budget");
|
|
16608
|
-
const ancestors = parents(path), initial =
|
|
17068
|
+
const ancestors = parents(path), initial = lstatSync52(path, { bigint: true });
|
|
16609
17069
|
need(initial.isFile() && !initial.isSymbolicLink() && initial.size <= BigInt(CLAUDE_SETTINGS_WITNESS_LIMITS.bytes), "is not a bounded regular file");
|
|
16610
17070
|
need(initial.size <= BigInt(budget.remaining), "exceeds its aggregate byte limit");
|
|
16611
17071
|
const fd = openSync22(path, constants22.O_RDONLY | constants22.O_NOFOLLOW | constants22.O_NONBLOCK);
|
|
@@ -16620,10 +17080,10 @@ function readNativeDiscoveryWitnessFile(path, budget) {
|
|
|
16620
17080
|
break;
|
|
16621
17081
|
length += count;
|
|
16622
17082
|
}
|
|
16623
|
-
const after = fstatSync22(fd, { bigint: true }), current2 =
|
|
17083
|
+
const after = fstatSync22(fd, { bigint: true }), current2 = lstatSync52(path, { bigint: true });
|
|
16624
17084
|
need(current2.isFile() && sameFile(opened, after) && sameFile(after, current2) && BigInt(length) === opened.size, "changed during read");
|
|
16625
17085
|
for (const [ancestor, before] of ancestors) {
|
|
16626
|
-
const now =
|
|
17086
|
+
const now = lstatSync52(ancestor, { bigint: true });
|
|
16627
17087
|
need(now.isDirectory() && before.dev === now.dev && before.ino === now.ino && before.mode === now.mode, "parent changed during read");
|
|
16628
17088
|
}
|
|
16629
17089
|
budget.remaining -= length;
|
|
@@ -16881,9 +17341,9 @@ function upgradeClaudeSettingsWitness(previous, reviewedSettingsPath) {
|
|
|
16881
17341
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget), current2 = readNativeSettingsWitnessFile(previous.path, budget);
|
|
16882
17342
|
const beforeDigest = previous.hashMode === undefined || previous.hashMode === "bytes" ? createHash42("sha256").update(before).digest("hex") : settingsDigest(before, previous.hashMode === "claude-settings-v1" ? 1 : 2);
|
|
16883
17343
|
need(beforeDigest === previous.sha256, "reviewed preimage does not match the legacy witness");
|
|
16884
|
-
const
|
|
16885
|
-
need(settingsDigest(before, 3) ===
|
|
16886
|
-
return { path: previous.path, hashMode: "claude-settings-v3", sha256 };
|
|
17344
|
+
const sha2563 = settingsDigest(current2, 3);
|
|
17345
|
+
need(settingsDigest(before, 3) === sha2563, "non-preference settings changed; explicit discovery review required");
|
|
17346
|
+
return { path: previous.path, hashMode: "claude-settings-v3", sha256: sha2563 };
|
|
16887
17347
|
}
|
|
16888
17348
|
function captureClaudeSettingsV4(path, budget = { remaining: 256 * 1024 * 1024 }) {
|
|
16889
17349
|
return { path, hashMode: "claude-settings-v4", sha256: settingsDigest(readNativeSettingsWitnessFile(path, budget), 4) };
|
|
@@ -16901,9 +17361,9 @@ function upgradeClaudeSettingsWitnessV4(previous, reviewedSettingsPath) {
|
|
|
16901
17361
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget), current2 = readNativeSettingsWitnessFile(previous.path, budget);
|
|
16902
17362
|
const beforeDigest = previous.hashMode === undefined || previous.hashMode === "bytes" ? createHash42("sha256").update(before).digest("hex") : settingsDigest(before, previous.hashMode === "claude-settings-v1" ? 1 : previous.hashMode === "claude-settings-v2" ? 2 : 3);
|
|
16903
17363
|
need(beforeDigest === previous.sha256, "reviewed preimage does not match the prior witness");
|
|
16904
|
-
const
|
|
16905
|
-
need(settingsDigest(before, 4) ===
|
|
16906
|
-
return { path: previous.path, hashMode: "claude-settings-v4", sha256 };
|
|
17364
|
+
const sha2563 = settingsDigest(current2, 4);
|
|
17365
|
+
need(settingsDigest(before, 4) === sha2563, "non-preference settings changed; explicit discovery review required");
|
|
17366
|
+
return { path: previous.path, hashMode: "claude-settings-v4", sha256: sha2563 };
|
|
16907
17367
|
}
|
|
16908
17368
|
var V5_DISCOVERY_KEY = /skill|plugin|hook|marketplace/i;
|
|
16909
17369
|
var V5_BOUND_KEYS = new Set(["apiKeyHelper", "awsAuthRefresh", "awsCredentialExport", "otelHeadersHelper", "fileSuggestion", "outputStyle", "agent"]);
|
|
@@ -16980,9 +17440,9 @@ function upgradeClaudeSettingsWitnessV5(previous, reviewedSettingsPath) {
|
|
|
16980
17440
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget), current2 = readNativeSettingsWitnessFile(previous.path, budget);
|
|
16981
17441
|
const beforeDigest = previous.hashMode === undefined || previous.hashMode === "bytes" ? createHash42("sha256").update(before).digest("hex") : settingsDigest(before, previous.hashMode === "claude-settings-v1" ? 1 : previous.hashMode === "claude-settings-v2" ? 2 : previous.hashMode === "claude-settings-v3" ? 3 : 4);
|
|
16982
17442
|
need(beforeDigest === previous.sha256, "reviewed preimage does not match the prior witness");
|
|
16983
|
-
const
|
|
16984
|
-
need(settingsDigestV5(before) ===
|
|
16985
|
-
return { path: previous.path, hashMode: "claude-settings-v5", sha256 };
|
|
17443
|
+
const sha2563 = settingsDigestV5(current2);
|
|
17444
|
+
need(settingsDigestV5(before) === sha2563, "discovery settings changed; explicit discovery review required");
|
|
17445
|
+
return { path: previous.path, hashMode: "claude-settings-v5", sha256: sha2563 };
|
|
16986
17446
|
}
|
|
16987
17447
|
function hashNativeJsonControls(text, excludedMetadata) {
|
|
16988
17448
|
need(Buffer.byteLength(text) <= CLAUDE_SETTINGS_WITNESS_LIMITS.bytes, "exceeds its byte limit");
|
|
@@ -17132,7 +17592,7 @@ var stringArray = (value) => value?.kind === "array" && value.items.every(isStri
|
|
|
17132
17592
|
var stringObject = (value) => value?.kind === "object" && value.entries.every(([, item]) => isString(item));
|
|
17133
17593
|
function claudeMarketplaceEntrySourceValid(source) {
|
|
17134
17594
|
const path = source?.path;
|
|
17135
|
-
return typeof path === "string" && path.length > 0 && path.length <= PATH_CHARACTERS && !/[\x00-\x1f\x7f]/.test(path) &&
|
|
17595
|
+
return typeof path === "string" && path.length > 0 && path.length <= PATH_CHARACTERS && !/[\x00-\x1f\x7f]/.test(path) && isAbsolute42(path) && resolve42(path) === path && basename3(path) === "marketplace.json" && basename3(dirname52(path)) === ".claude-plugin" && typeof source.marketplace === "string" && NAME.test(source.marketplace) && !source.marketplace.includes("..") && typeof source.plugin === "string" && NAME.test(source.plugin);
|
|
17136
17596
|
}
|
|
17137
17597
|
function canonical2(value) {
|
|
17138
17598
|
if (value.kind === "string")
|
|
@@ -17260,7 +17720,7 @@ function captureClaudeMarketplaceEntry(path, marketplace, plugin, budget2 = { re
|
|
|
17260
17720
|
var CLAUDE_ORPHAN_MARKER_MODE = "claude-plugin-orphaned-at-v1";
|
|
17261
17721
|
var CACHE = `${sep22}.claude${sep22}plugins${sep22}cache${sep22}`;
|
|
17262
17722
|
function isClaudePluginCacheOrphanMarker(path) {
|
|
17263
|
-
if (typeof path !== "string" || basename4(path) !== ".orphaned_at" || !isAbsolute5(path) ||
|
|
17723
|
+
if (typeof path !== "string" || basename4(path) !== ".orphaned_at" || !isAbsolute5(path) || resolve52(path) !== path || path.includes("\x00"))
|
|
17264
17724
|
return false;
|
|
17265
17725
|
const at = path.indexOf(CACHE);
|
|
17266
17726
|
if (at < 0 || path.indexOf(CACHE, at + 1) >= 0)
|
|
@@ -17273,7 +17733,7 @@ function same(left, right) {
|
|
|
17273
17733
|
}
|
|
17274
17734
|
function safe(path) {
|
|
17275
17735
|
for (let cursor = path;; cursor = dirname62(cursor)) {
|
|
17276
|
-
if (
|
|
17736
|
+
if (lstatSync62(cursor, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
17277
17737
|
throw new Error("Refusing symlink Claude orphan marker input");
|
|
17278
17738
|
if (dirname62(cursor) === cursor)
|
|
17279
17739
|
break;
|
|
@@ -17285,7 +17745,7 @@ function hashClaudePluginCacheOrphanMarker(path, budget2, changes) {
|
|
|
17285
17745
|
if (changes?.has(path))
|
|
17286
17746
|
throw new Error("Claude orphan markers cannot intersect a planned write");
|
|
17287
17747
|
safe(path);
|
|
17288
|
-
const before =
|
|
17748
|
+
const before = lstatSync62(path, { throwIfNoEntry: false });
|
|
17289
17749
|
if (!before)
|
|
17290
17750
|
return null;
|
|
17291
17751
|
const uid = process.getuid?.();
|
|
@@ -17306,7 +17766,7 @@ function hashClaudePluginCacheOrphanMarker(path, budget2, changes) {
|
|
|
17306
17766
|
}
|
|
17307
17767
|
if (!/^[1-9][0-9]{12}$/.test(bytes.subarray(0, length).toString("latin1")))
|
|
17308
17768
|
throw new Error("Malformed Claude orphan marker timestamp");
|
|
17309
|
-
const after = fstatSync3(fd), current2 =
|
|
17769
|
+
const after = fstatSync3(fd), current2 = lstatSync62(path, { throwIfNoEntry: false });
|
|
17310
17770
|
safe(path);
|
|
17311
17771
|
if (!same(opened, after) || !same(after, current2) || length !== after.size)
|
|
17312
17772
|
throw new Error("Claude orphan marker changed during read");
|
|
@@ -17315,7 +17775,7 @@ function hashClaudePluginCacheOrphanMarker(path, budget2, changes) {
|
|
|
17315
17775
|
throw new Error("Raw discovery aggregate byte limit exceeded");
|
|
17316
17776
|
budget2.remaining -= length;
|
|
17317
17777
|
}
|
|
17318
|
-
return
|
|
17778
|
+
return createHash72("sha256").update(`${CLAUDE_ORPHAN_MARKER_MODE}\x00${path}\x00file`).digest("hex");
|
|
17319
17779
|
} finally {
|
|
17320
17780
|
closeSync32(fd);
|
|
17321
17781
|
}
|
|
@@ -17373,7 +17833,7 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17373
17833
|
text(control.pluginId, 1024);
|
|
17374
17834
|
text(control.namespace, 64);
|
|
17375
17835
|
text(control.pluginParent);
|
|
17376
|
-
requireBound(isAbsolute6(control.pluginParent) &&
|
|
17836
|
+
requireBound(isAbsolute6(control.pluginParent) && resolve62(control.pluginParent) === control.pluginParent && /^[a-f0-9]{64}$/.test(control.manifestSha256));
|
|
17377
17837
|
if (control.remotePluginId !== undefined)
|
|
17378
17838
|
requireBound(typeof control.remotePluginId === "string" && /^[A-Za-z0-9_~-]{1,1024}$/.test(control.remotePluginId));
|
|
17379
17839
|
if (control.skillsOnly !== undefined)
|
|
@@ -17391,7 +17851,7 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17391
17851
|
text(control.pluginId, 1024);
|
|
17392
17852
|
text(control.namespace, 64);
|
|
17393
17853
|
text(control.pluginParent);
|
|
17394
|
-
requireBound(!ids.has(control.pluginId) && isAbsolute6(control.pluginParent) &&
|
|
17854
|
+
requireBound(!ids.has(control.pluginId) && isAbsolute6(control.pluginParent) && resolve62(control.pluginParent) === control.pluginParent && ["local", "git", "npm"].includes(control.sourceType) && typeof control.sourceSha256 === "string" && /^[a-f0-9]{64}$/.test(control.sourceSha256));
|
|
17395
17855
|
ids.add(control.pluginId);
|
|
17396
17856
|
}
|
|
17397
17857
|
}
|
|
@@ -17400,7 +17860,7 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17400
17860
|
requireBound(agent === "gemini" && object(executable) && Object.keys(executable).length === 3 && executable.command === "gemini");
|
|
17401
17861
|
for (const path of [executable.path, executable.target]) {
|
|
17402
17862
|
text(path);
|
|
17403
|
-
requireBound(!/[\x00-\x1f\x7f-\x9f\u200e\u200f\u202a-\u202e\u2066-\u2069]/.test(path) && isAbsolute6(path) &&
|
|
17863
|
+
requireBound(!/[\x00-\x1f\x7f-\x9f\u200e\u200f\u202a-\u202e\u2066-\u2069]/.test(path) && isAbsolute6(path) && resolve62(path) === path);
|
|
17404
17864
|
}
|
|
17405
17865
|
}
|
|
17406
17866
|
if (bridge.disabledBuiltins !== undefined)
|
|
@@ -17428,11 +17888,11 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17428
17888
|
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && Object.keys(proof).every((key) => ["roots", "parents", "directories"].includes(key)) && roots.length + parents2.length > 0 && new Set(roots).size === roots.length && new Set(parents2).size === parents2.length);
|
|
17429
17889
|
for (const root of roots) {
|
|
17430
17890
|
text(root);
|
|
17431
|
-
requireBound(isAbsolute6(root) &&
|
|
17891
|
+
requireBound(isAbsolute6(root) && resolve62(root) === root);
|
|
17432
17892
|
}
|
|
17433
17893
|
for (const parent of parents2) {
|
|
17434
17894
|
text(parent);
|
|
17435
|
-
requireBound(isAbsolute6(parent) &&
|
|
17895
|
+
requireBound(isAbsolute6(parent) && resolve62(parent) === parent);
|
|
17436
17896
|
}
|
|
17437
17897
|
for (const directory of array(proof.directories, AGENT_POLICY_LIMITS.discoveryDirectories)) {
|
|
17438
17898
|
requireBound(object(directory));
|
|
@@ -17452,7 +17912,7 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17452
17912
|
text(input.namespace, 64);
|
|
17453
17913
|
text(input.pluginParent);
|
|
17454
17914
|
text(input.sourceRoot);
|
|
17455
|
-
requireBound(!ids.has(input.pluginId) && [input.pluginParent, input.sourceRoot].every((path) => isAbsolute6(path) &&
|
|
17915
|
+
requireBound(!ids.has(input.pluginId) && [input.pluginParent, input.sourceRoot].every((path) => isAbsolute6(path) && resolve62(path) === path) && typeof input.sourceSha256 === "string" && /^[a-f0-9]{64}$/.test(input.sourceSha256));
|
|
17456
17916
|
ids.add(input.pluginId);
|
|
17457
17917
|
}
|
|
17458
17918
|
if (proof.directories !== undefined)
|
|
@@ -17466,14 +17926,14 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17466
17926
|
const proof = record(value.codexSemanticCache, 9), witness = record(proof.witness, 7);
|
|
17467
17927
|
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && [8, 9].includes(Object.keys(proof).length) && Object.keys(proof).every((key) => ["schema", "configPath", "hookRootAlias", "witness", "appOnlyParents", "previousPolicySha256", "supersededSources", "supersededDirectories", "reviewedHookParents"].includes(key)) && proof.schema === "hasna.codex-semantic-cache-discovery.v1" && typeof proof.previousPolicySha256 === "string" && /^[a-f0-9]{64}$/.test(proof.previousPolicySha256) && [6, 7].includes(Object.keys(witness).length) && Object.keys(witness).every((key) => ["schema", "cacheRoot", "controls", "appOnlyParents", "skills", "sha256", "hookParents"].includes(key)) && witness.schema === "hasna.codex-semantic-cache-witness.v1" && typeof witness.sha256 === "string" && /^[a-f0-9]{64}$/.test(witness.sha256));
|
|
17468
17928
|
text(proof.configPath);
|
|
17469
|
-
requireBound(isAbsolute6(proof.configPath) &&
|
|
17929
|
+
requireBound(isAbsolute6(proof.configPath) && resolve62(proof.configPath) === proof.configPath && basename5(proof.configPath) === "config.toml");
|
|
17470
17930
|
text(witness.cacheRoot);
|
|
17471
|
-
requireBound(isAbsolute6(witness.cacheRoot) &&
|
|
17931
|
+
requireBound(isAbsolute6(witness.cacheRoot) && resolve62(witness.cacheRoot) === witness.cacheRoot);
|
|
17472
17932
|
if (proof.hookRootAlias !== null) {
|
|
17473
17933
|
requireBound(object(proof.hookRootAlias) && Object.keys(proof.hookRootAlias).length === 2);
|
|
17474
17934
|
for (const key of ["alias", "target"]) {
|
|
17475
17935
|
text(proof.hookRootAlias[key]);
|
|
17476
|
-
requireBound(isAbsolute6(proof.hookRootAlias[key]) &&
|
|
17936
|
+
requireBound(isAbsolute6(proof.hookRootAlias[key]) && resolve62(proof.hookRootAlias[key]) === proof.hookRootAlias[key]);
|
|
17477
17937
|
}
|
|
17478
17938
|
}
|
|
17479
17939
|
const parents2 = array(proof.appOnlyParents, 4096);
|
|
@@ -17481,7 +17941,7 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17481
17941
|
requireBound(object(parent) && Object.keys(parent).length === 5 && parent.role === "app-only");
|
|
17482
17942
|
for (const key of ["pluginId", "namespace", "pluginParent", "remotePluginId"])
|
|
17483
17943
|
text(parent[key]);
|
|
17484
|
-
requireBound(isAbsolute6(parent.pluginParent) &&
|
|
17944
|
+
requireBound(isAbsolute6(parent.pluginParent) && resolve62(parent.pluginParent) === parent.pluginParent);
|
|
17485
17945
|
}
|
|
17486
17946
|
if (proof.reviewedHookParents !== undefined)
|
|
17487
17947
|
for (const parent of array(proof.reviewedHookParents, 4096)) {
|
|
@@ -17493,9 +17953,9 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17493
17953
|
text(parent.remotePluginId);
|
|
17494
17954
|
else {
|
|
17495
17955
|
text(parent.marketplaceSourcePath);
|
|
17496
|
-
requireBound(typeof parent.marketplaceSha256 === "string" && /^[a-f0-9]{64}$/.test(parent.marketplaceSha256) && isAbsolute6(parent.marketplaceSourcePath) &&
|
|
17956
|
+
requireBound(typeof parent.marketplaceSha256 === "string" && /^[a-f0-9]{64}$/.test(parent.marketplaceSha256) && isAbsolute6(parent.marketplaceSourcePath) && resolve62(parent.marketplaceSourcePath) === parent.marketplaceSourcePath && basename5(parent.marketplaceSourcePath) === "marketplace.json");
|
|
17497
17957
|
}
|
|
17498
|
-
requireBound(isAbsolute6(parent.pluginParent) &&
|
|
17958
|
+
requireBound(isAbsolute6(parent.pluginParent) && resolve62(parent.pluginParent) === parent.pluginParent);
|
|
17499
17959
|
}
|
|
17500
17960
|
for (const row of [...array(witness.controls, 4096), ...array(witness.appOnlyParents, 4096)]) {
|
|
17501
17961
|
requireBound(object(row));
|
|
@@ -17515,9 +17975,9 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17515
17975
|
text(row.remotePluginId);
|
|
17516
17976
|
else {
|
|
17517
17977
|
text(row.marketplaceSourcePath);
|
|
17518
|
-
requireBound(typeof row.marketplaceSha256 === "string" && /^[a-f0-9]{64}$/.test(row.marketplaceSha256) && isAbsolute6(row.marketplaceSourcePath) &&
|
|
17978
|
+
requireBound(typeof row.marketplaceSha256 === "string" && /^[a-f0-9]{64}$/.test(row.marketplaceSha256) && isAbsolute6(row.marketplaceSourcePath) && resolve62(row.marketplaceSourcePath) === row.marketplaceSourcePath && basename5(row.marketplaceSourcePath) === "marketplace.json");
|
|
17519
17979
|
}
|
|
17520
|
-
requireBound(isAbsolute6(row.pluginParent) &&
|
|
17980
|
+
requireBound(isAbsolute6(row.pluginParent) && resolve62(row.pluginParent) === row.pluginParent);
|
|
17521
17981
|
for (const key of ["manifestSha256", "hooksSha256"])
|
|
17522
17982
|
requireBound(typeof row[key] === "string" && /^[a-f0-9]{64}$/.test(row[key]));
|
|
17523
17983
|
if (row.installation === "remote-receipt")
|
|
@@ -17554,13 +18014,13 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17554
18014
|
if (source.hashMode === CLAUDE_ORPHAN_MARKER_MODE)
|
|
17555
18015
|
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && isClaudePluginCacheOrphanMarker(source.path) && source.managedPlugins === undefined && source.reviewArtifact === undefined);
|
|
17556
18016
|
if (source.hashMode === "executable-v1")
|
|
17557
|
-
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && value.sources.some((row) => row.hashMode === "codex-settings-v6") && isAbsolute6(source.path) &&
|
|
18017
|
+
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && value.sources.some((row) => row.hashMode === "codex-settings-v6") && isAbsolute6(source.path) && resolve62(source.path) === source.path);
|
|
17558
18018
|
if (source.hashMode === "codex-settings-v6") {
|
|
17559
18019
|
const seen = new Set;
|
|
17560
18020
|
for (const hook of array(source.hookSources, AGENT_POLICY_LIMITS.discoverySources)) {
|
|
17561
18021
|
requireBound(object(hook) && Object.keys(hook).length === 2 && Object.keys(hook).every((key) => ["path", "sha256"].includes(key)));
|
|
17562
18022
|
text(hook.path);
|
|
17563
|
-
requireBound(isAbsolute6(hook.path) &&
|
|
18023
|
+
requireBound(isAbsolute6(hook.path) && resolve62(hook.path) === hook.path && !seen.has(hook.path));
|
|
17564
18024
|
seen.add(hook.path);
|
|
17565
18025
|
requireBound(hook.sha256 === null || typeof hook.sha256 === "string" && /^[a-f0-9]{64}$/.test(hook.sha256));
|
|
17566
18026
|
requireBound(value.sources.some((row) => row.path === hook.path && row.sha256 === hook.sha256 && [undefined, "bytes"].includes(row.hashMode) && row.format === undefined && row.fields === undefined));
|
|
@@ -17568,15 +18028,15 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17568
18028
|
} else
|
|
17569
18029
|
requireBound(source.hookSources === undefined);
|
|
17570
18030
|
if (source.hashMode === "claude-plugin-manifest-v1")
|
|
17571
|
-
requireBound(agent === "claude" && value.agent === "claude" && ["automatic", "reviewed"].includes(value.method) && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute6(source.path) &&
|
|
18031
|
+
requireBound(agent === "claude" && value.agent === "claude" && ["automatic", "reviewed"].includes(value.method) && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute6(source.path) && resolve62(source.path) === source.path && source.path.endsWith(join92(sep32, ".claude-plugin", "plugin.json")) && source.managedPlugins === undefined);
|
|
17572
18032
|
if (source.hashMode === "sumi-settings-v1")
|
|
17573
|
-
requireBound(agent === "sumi" && value.agent === "sumi" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute6(source.path) &&
|
|
18033
|
+
requireBound(agent === "sumi" && value.agent === "sumi" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute6(source.path) && resolve62(source.path) === source.path && basename5(source.path) === "sumi.json");
|
|
17574
18034
|
if (source.hashMode === "codex-settings-v1" || source.hashMode === "codex-settings-v2" || (source.hashMode === "codex-settings-v3" || source.hashMode === "codex-settings-v4" || source.hashMode === "codex-settings-v5" || source.hashMode === "codex-settings-v6" || source.hashMode === "codex-settings-v7" || source.hashMode === "codex-settings-v8"))
|
|
17575
|
-
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute6(source.path) &&
|
|
18035
|
+
requireBound(agent === "codex" && value.agent === "codex" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute6(source.path) && resolve62(source.path) === source.path && basename5(source.path) === "config.toml");
|
|
17576
18036
|
if (source.hashMode === "claude-settings-v1" || source.hashMode === "claude-settings-v2" || (source.hashMode === "claude-settings-v3" || source.hashMode === "claude-settings-v4" || source.hashMode === "claude-settings-v5"))
|
|
17577
|
-
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute6(source.path) &&
|
|
18037
|
+
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute6(source.path) && resolve62(source.path) === source.path && basename5(source.path) === "settings.json");
|
|
17578
18038
|
if (source.hashMode === "claude-marketplace-registry" || source.hashMode === "claude-marketplace-registry-v2")
|
|
17579
|
-
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute6(source.path) &&
|
|
18039
|
+
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && !/[\x00-\x1f\x7f]/.test(source.path) && isAbsolute6(source.path) && resolve62(source.path) === source.path && basename5(source.path) === "known_marketplaces.json");
|
|
17580
18040
|
if (source.hashMode === "claude-marketplace-entry-v1")
|
|
17581
18041
|
requireBound(agent === "claude" && value.agent === "claude" && value.method === "reviewed" && claudeMarketplaceEntrySourceValid(source));
|
|
17582
18042
|
if (source.hashMode === "claude-plugin-registry") {
|
|
@@ -17595,7 +18055,7 @@ function assertAgentPolicyCollections(policy) {
|
|
|
17595
18055
|
requireBound(agent === "codex" && value.method === "reviewed" && source.hashMode === "bytes" && object(artifact) && Object.keys(artifact).length === 6 && Object.keys(artifact).every((key) => ["version", "kind", "storeRoot", "originalPath", "sha256", "catalogSha256"].includes(key)) && artifact.version === 1 && artifact.kind === "codex-native-catalog" && artifact.sha256 === source.sha256 && /^[a-f0-9]{64}$/.test(artifact.catalogSha256));
|
|
17596
18056
|
for (const path of [artifact.storeRoot, artifact.originalPath]) {
|
|
17597
18057
|
text(path);
|
|
17598
|
-
requireBound(isAbsolute6(path) &&
|
|
18058
|
+
requireBound(isAbsolute6(path) && resolve62(path) === path);
|
|
17599
18059
|
}
|
|
17600
18060
|
requireBound(source.path === join92(artifact.storeRoot, "agent-discovery", "artifacts", artifact.sha256, "catalog.json"));
|
|
17601
18061
|
}
|
|
@@ -17701,7 +18161,7 @@ var ENV_PREFIX = new RegExp(`^(${PINNED_LAUNCHER_ENV_PREFIXES.join("|")})_`);
|
|
|
17701
18161
|
var ENV_EXACT = new Set(PINNED_LAUNCHER_ENV_NAMES);
|
|
17702
18162
|
var COMMAND_LINE = new RegExp(`^set -- '([^']+)' ${PINNED_LAUNCHER_BUN_FLAGS2.join(" ")} '--cwd=([^']+)' '([^']+)' "\\$@"$`, "m");
|
|
17703
18163
|
var PINNED_LAUNCHER_MAX_BYTES = 16 * 1024;
|
|
17704
|
-
var INSTALLED_PACKAGE = `${
|
|
18164
|
+
var INSTALLED_PACKAGE = `${sep42}node_modules${sep42}@hasna${sep42}skills${sep42}`;
|
|
17705
18165
|
var DRIFT_REPORT_RETRY_MS = 6 * 60 * 60 * 1000;
|
|
17706
18166
|
var DRIFT_REPORT_LOCK_TTL_MS = 3 * 60 * 1000;
|
|
17707
18167
|
var DRIFT_REPORT_WORKER_DEADLINE_MS = DRIFT_REPORT_LOCK_TTL_MS - 30000;
|
|
@@ -17794,10 +18254,10 @@ function assertHermesEnvironment(home) {
|
|
|
17794
18254
|
throw new NativeBridgeIntegrityRefusal("NATIVE_SKILL_DRIFT: Hermes project plugins require a dedicated discovery review");
|
|
17795
18255
|
}
|
|
17796
18256
|
function read(path) {
|
|
17797
|
-
for (let current2 = path;; current2 =
|
|
18257
|
+
for (let current2 = path;; current2 = dirname82(current2)) {
|
|
17798
18258
|
if (lstatSync8(current2, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
17799
18259
|
throw new Error("NATIVE_SKILL_DRIFT: symlink Hermes protection input");
|
|
17800
|
-
if (
|
|
18260
|
+
if (dirname82(current2) === current2)
|
|
17801
18261
|
break;
|
|
17802
18262
|
}
|
|
17803
18263
|
const stat = lstatSync8(path, { throwIfNoEntry: false });
|
|
@@ -17805,7 +18265,7 @@ function read(path) {
|
|
|
17805
18265
|
return null;
|
|
17806
18266
|
if (!stat.isFile() || stat.size > 1024 * 1024)
|
|
17807
18267
|
throw new Error("NATIVE_SKILL_DRIFT: invalid Hermes protection input");
|
|
17808
|
-
return
|
|
18268
|
+
return readFileSync82(path, "utf8");
|
|
17809
18269
|
}
|
|
17810
18270
|
function assertHermesProtection(home, config, command, profile, supervisor2) {
|
|
17811
18271
|
assertHermesEnvironment(home);
|
|
@@ -17837,10 +18297,10 @@ function assertHermesProtection(home, config, command, profile, supervisor2) {
|
|
|
17837
18297
|
}
|
|
17838
18298
|
function assertNoHermesLegacyShadow(root) {
|
|
17839
18299
|
let entries = 0;
|
|
17840
|
-
for (let cursor = resolve7(root);; cursor =
|
|
18300
|
+
for (let cursor = resolve7(root);; cursor = dirname82(cursor)) {
|
|
17841
18301
|
if (lstatSync8(cursor, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
17842
18302
|
throw new NativeBridgeIntegrityRefusal("NATIVE_SKILL_DRIFT: symlink Hermes legacy discovery root");
|
|
17843
|
-
if (
|
|
18303
|
+
if (dirname82(cursor) === cursor)
|
|
17844
18304
|
break;
|
|
17845
18305
|
}
|
|
17846
18306
|
function scan(path, depth) {
|
|
@@ -19028,8 +19488,8 @@ function captureCodexHookMcpDependencies(configPath, reviewed, configText, chang
|
|
|
19028
19488
|
function read2(path) {
|
|
19029
19489
|
const source = rows.get(path);
|
|
19030
19490
|
need5(source);
|
|
19031
|
-
const
|
|
19032
|
-
need5(source.sha256 ===
|
|
19491
|
+
const sha25622 = hashRawDiscoveryFile(path, budget2);
|
|
19492
|
+
need5(source.sha256 === sha25622);
|
|
19033
19493
|
if (changes?.has(path)) {
|
|
19034
19494
|
const text3 = changes.get(path);
|
|
19035
19495
|
need5(Buffer.byteLength(text3) <= 1024 * 1024);
|
|
@@ -19037,11 +19497,11 @@ function captureCodexHookMcpDependencies(configPath, reviewed, configText, chang
|
|
|
19037
19497
|
sources.set(path, { path, sha256: createHash16("sha256").update(text3).digest("hex") });
|
|
19038
19498
|
return text3;
|
|
19039
19499
|
}
|
|
19040
|
-
sources.set(path, { path, sha256:
|
|
19041
|
-
if (
|
|
19500
|
+
sources.set(path, { path, sha256: sha25622 });
|
|
19501
|
+
if (sha25622 === null)
|
|
19042
19502
|
return null;
|
|
19043
19503
|
const text2 = readNativeSettingsWitnessFile(path, budget2, basename6(path));
|
|
19044
|
-
need5(Buffer.byteLength(text2) <= 1024 * 1024 && createHash16("sha256").update(text2).digest("hex") ===
|
|
19504
|
+
need5(Buffer.byteLength(text2) <= 1024 * 1024 && createHash16("sha256").update(text2).digest("hex") === sha25622);
|
|
19045
19505
|
hashNativeJsonControls(text2);
|
|
19046
19506
|
return text2;
|
|
19047
19507
|
}
|
|
@@ -19764,10 +20224,10 @@ function upgradeCodexSettingsWitness(previous, reviewedSettingsPath) {
|
|
|
19764
20224
|
const budget2 = { remaining: 2 * 1024 * 1024 };
|
|
19765
20225
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
19766
20226
|
need7((previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before)) === previous.sha256);
|
|
19767
|
-
const
|
|
19768
|
-
if (settingsDigest2(before) !==
|
|
20227
|
+
const sha25622 = settingsDigest2(current2);
|
|
20228
|
+
if (settingsDigest2(before) !== sha25622)
|
|
19769
20229
|
throw new Error("Codex non-preference settings changed; explicit discovery review required");
|
|
19770
|
-
return { path: previous.path, hashMode: "codex-settings-v2", sha256:
|
|
20230
|
+
return { path: previous.path, hashMode: "codex-settings-v2", sha256: sha25622 };
|
|
19771
20231
|
}
|
|
19772
20232
|
function hashCodexSettingsReplacementV3(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
19773
20233
|
need7(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
@@ -19780,10 +20240,10 @@ function upgradeCodexSettingsWitnessV3(previous, reviewedSettingsPath) {
|
|
|
19780
20240
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
19781
20241
|
const original = previous.hashMode === "codex-settings-v2" ? settingsDigest2(before) : previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before);
|
|
19782
20242
|
need7(original === previous.sha256);
|
|
19783
|
-
const
|
|
19784
|
-
if (settingsDigest2(before, 3) !==
|
|
20243
|
+
const sha25622 = settingsDigest2(current2, 3);
|
|
20244
|
+
if (settingsDigest2(before, 3) !== sha25622)
|
|
19785
20245
|
throw new Error("Codex settings outside the reviewed V3 contract changed; explicit discovery review required");
|
|
19786
|
-
return { path: previous.path, hashMode: "codex-settings-v3", sha256:
|
|
20246
|
+
return { path: previous.path, hashMode: "codex-settings-v3", sha256: sha25622 };
|
|
19787
20247
|
}
|
|
19788
20248
|
function hashCodexSettingsReplacementV4(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
19789
20249
|
need7(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
@@ -19796,10 +20256,10 @@ function upgradeCodexSettingsWitnessV4(previous, reviewedSettingsPath) {
|
|
|
19796
20256
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
19797
20257
|
const original = previous.hashMode === "codex-settings-v3" ? settingsDigest2(before, 3) : previous.hashMode === "codex-settings-v2" ? settingsDigest2(before, 2) : previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before);
|
|
19798
20258
|
need7(original === previous.sha256);
|
|
19799
|
-
const
|
|
19800
|
-
if (settingsDigest2(before, 4) !==
|
|
20259
|
+
const sha25622 = settingsDigest2(current2, 4);
|
|
20260
|
+
if (settingsDigest2(before, 4) !== sha25622)
|
|
19801
20261
|
throw new Error("Codex settings outside the reviewed V4 contract changed; explicit discovery review required");
|
|
19802
|
-
return { path: previous.path, hashMode: "codex-settings-v4", sha256:
|
|
20262
|
+
return { path: previous.path, hashMode: "codex-settings-v4", sha256: sha25622 };
|
|
19803
20263
|
}
|
|
19804
20264
|
function hashCodexSettingsReplacementV5(text2, budget2 = { remaining: 256 * 1024 * 1024 }) {
|
|
19805
20265
|
need7(Buffer.byteLength(text2) <= 1024 * 1024 && budget2.remaining >= Buffer.byteLength(text2));
|
|
@@ -19812,10 +20272,10 @@ function upgradeCodexSettingsWitnessV5(previous, reviewedSettingsPath) {
|
|
|
19812
20272
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
19813
20273
|
const original = previous.hashMode === "codex-settings-v4" ? settingsDigest2(before, 4) : previous.hashMode === "codex-settings-v3" ? settingsDigest2(before, 3) : previous.hashMode === "codex-settings-v2" ? settingsDigest2(before, 2) : previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before);
|
|
19814
20274
|
need7(original === previous.sha256);
|
|
19815
|
-
const
|
|
19816
|
-
if (settingsDigest2(before, 5) !==
|
|
20275
|
+
const sha25622 = settingsDigest2(current2, 5);
|
|
20276
|
+
if (settingsDigest2(before, 5) !== sha25622)
|
|
19817
20277
|
throw new Error("Codex settings outside the reviewed V5 contract changed; explicit discovery review required");
|
|
19818
|
-
return { path: previous.path, hashMode: "codex-settings-v5", sha256:
|
|
20278
|
+
return { path: previous.path, hashMode: "codex-settings-v5", sha256: sha25622 };
|
|
19819
20279
|
}
|
|
19820
20280
|
var V7_DISCOVERY_KEY = /skill|plugin|hook|marketplace|instruction/i;
|
|
19821
20281
|
var V7_BOUND_KEYS = new Set(["mcp_servers", "agents", "project_doc_fallback_filenames", "compact_prompt", "experimental_compact_prompt_file"]);
|
|
@@ -19915,10 +20375,10 @@ function upgradeCodexSettingsWitnessV7(previous, reviewedSettingsPath) {
|
|
|
19915
20375
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
19916
20376
|
const original = previous.hashMode === "codex-settings-v5" ? settingsDigest2(before, 5) : previous.hashMode === "codex-settings-v4" ? settingsDigest2(before, 4) : previous.hashMode === "codex-settings-v3" ? settingsDigest2(before, 3) : previous.hashMode === "codex-settings-v2" ? settingsDigest2(before, 2) : previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before);
|
|
19917
20377
|
need7(original === previous.sha256);
|
|
19918
|
-
const
|
|
19919
|
-
if (settingsDigestV7(before) !==
|
|
20378
|
+
const sha25622 = settingsDigestV7(current2);
|
|
20379
|
+
if (settingsDigestV7(before) !== sha25622)
|
|
19920
20380
|
throw new Error("Codex discovery settings outside the reviewed V7 contract changed; explicit discovery review required");
|
|
19921
|
-
return { path: previous.path, hashMode: "codex-settings-v7", sha256:
|
|
20381
|
+
return { path: previous.path, hashMode: "codex-settings-v7", sha256: sha25622 };
|
|
19922
20382
|
}
|
|
19923
20383
|
function settingsDigestV8(text2) {
|
|
19924
20384
|
need7(Buffer.byteLength(text2) <= 1024 * 1024);
|
|
@@ -19945,10 +20405,10 @@ function upgradeCodexSettingsWitnessV8(previous, reviewedSettingsPath) {
|
|
|
19945
20405
|
const before = readNativeSettingsWitnessFile(reviewedSettingsPath, budget2, "config.toml"), current2 = readNativeSettingsWitnessFile(previous.path, budget2, "config.toml");
|
|
19946
20406
|
const original = previous.hashMode === "codex-settings-v7" ? settingsDigestV7(before) : previous.hashMode === "codex-settings-v5" ? settingsDigest2(before, 5) : previous.hashMode === "codex-settings-v4" ? settingsDigest2(before, 4) : previous.hashMode === "codex-settings-v3" ? settingsDigest2(before, 3) : previous.hashMode === "codex-settings-v2" ? settingsDigest2(before, 2) : previous.hashMode === "codex-settings-v1" ? hashCodexSettingsReplacement(before) : sha2(before);
|
|
19947
20407
|
need7(original === previous.sha256);
|
|
19948
|
-
const
|
|
19949
|
-
if (settingsDigestV8(before) !==
|
|
20408
|
+
const sha25622 = settingsDigestV8(current2);
|
|
20409
|
+
if (settingsDigestV8(before) !== sha25622)
|
|
19950
20410
|
throw new Error("Codex discovery settings outside the reviewed V8 contract changed; explicit discovery review required");
|
|
19951
|
-
return { path: previous.path, hashMode: "codex-settings-v8", sha256:
|
|
20411
|
+
return { path: previous.path, hashMode: "codex-settings-v8", sha256: sha25622 };
|
|
19952
20412
|
}
|
|
19953
20413
|
function captureCodexSettingsV6(path, reviewedSources, budget2 = { remaining: 256 * 1024 * 1024 }, changes) {
|
|
19954
20414
|
const original = readNativeSettingsWitnessFile(path, budget2, "config.toml");
|
|
@@ -20084,10 +20544,10 @@ var DARWIN_HELPER_SHA256 = "3dd94f36877227e0e89055caef077cc5e60d0a46f436e7684598
|
|
|
20084
20544
|
function darwinAcls(entries, deadline) {
|
|
20085
20545
|
if (entries.length > 256)
|
|
20086
20546
|
refused("lock path has too many ancestors");
|
|
20087
|
-
const helper =
|
|
20547
|
+
const helper = fileURLToPath3(new URL("../native/kernel-lock-acl-darwin", import.meta.url));
|
|
20088
20548
|
let fd;
|
|
20089
20549
|
try {
|
|
20090
|
-
if (
|
|
20550
|
+
if (realpathSync42(helper) !== helper)
|
|
20091
20551
|
refused("unsafe ACL helper path");
|
|
20092
20552
|
fd = openSync8(helper, constants8.O_RDONLY | constants8.O_NOFOLLOW | constants8.O_NONBLOCK);
|
|
20093
20553
|
const info = fstatSync8(fd);
|
|
@@ -20152,17 +20612,17 @@ function canonicalRoot(root) {
|
|
|
20152
20612
|
if (!info)
|
|
20153
20613
|
refused("existing lock root is required");
|
|
20154
20614
|
if (info.isSymbolicLink()) {
|
|
20155
|
-
if (process.platform !== "darwin" || cursor !== "/var" && cursor !== "/tmp" ||
|
|
20615
|
+
if (process.platform !== "darwin" || cursor !== "/var" && cursor !== "/tmp" || realpathSync42(cursor) !== `/private${cursor}`)
|
|
20156
20616
|
refused("unsafe lock root path");
|
|
20157
20617
|
} else if (!info.isDirectory())
|
|
20158
20618
|
refused("unsafe lock root path");
|
|
20159
20619
|
}
|
|
20160
|
-
return
|
|
20620
|
+
return realpathSync42(requested);
|
|
20161
20621
|
}
|
|
20162
20622
|
function trustedHelper() {
|
|
20163
20623
|
let helper;
|
|
20164
20624
|
try {
|
|
20165
|
-
helper =
|
|
20625
|
+
helper = realpathSync42("/usr/bin/perl");
|
|
20166
20626
|
} catch {
|
|
20167
20627
|
return refused("trusted system Perl is required");
|
|
20168
20628
|
}
|
|
@@ -20550,7 +21010,7 @@ function skillsState(root, leaf, roots) {
|
|
|
20550
21010
|
verify();
|
|
20551
21011
|
for (const component of chain.slice(1)) {
|
|
20552
21012
|
try {
|
|
20553
|
-
|
|
21013
|
+
mkdirSync52(component, { mode: 448 });
|
|
20554
21014
|
} catch (error) {
|
|
20555
21015
|
if (error.code !== "EEXIST")
|
|
20556
21016
|
throw error;
|
|
@@ -20587,7 +21047,7 @@ function probeParent(roots) {
|
|
|
20587
21047
|
if (lstatSync15(component, { throwIfNoEntry: false }))
|
|
20588
21048
|
continue;
|
|
20589
21049
|
try {
|
|
20590
|
-
|
|
21050
|
+
mkdirSync52(component, { mode: 448 });
|
|
20591
21051
|
} catch (error) {
|
|
20592
21052
|
if (error.code !== "EEXIST")
|
|
20593
21053
|
throw error;
|
|
@@ -20606,7 +21066,7 @@ function removeProbeHome(home) {
|
|
|
20606
21066
|
try {
|
|
20607
21067
|
const stat2 = lstatSync15(home.path, { bigint: true });
|
|
20608
21068
|
if (stat2.isDirectory() && stat2.dev === home.dev && stat2.ino === home.ino)
|
|
20609
|
-
|
|
21069
|
+
rmSync22(home.path, { recursive: true, force: true });
|
|
20610
21070
|
} catch {}
|
|
20611
21071
|
}
|
|
20612
21072
|
function probe(path, args, parent, stdio) {
|
|
@@ -21001,9 +21461,9 @@ function requireRemoteReceiptSnapshot(catalog, cache) {
|
|
|
21001
21461
|
}
|
|
21002
21462
|
function appControls(path, read2) {
|
|
21003
21463
|
const text2 = read2(path);
|
|
21004
|
-
let value,
|
|
21464
|
+
let value, sha25622;
|
|
21005
21465
|
try {
|
|
21006
|
-
|
|
21466
|
+
sha25622 = hashNativeJsonControls(text2);
|
|
21007
21467
|
value = JSON.parse(text2);
|
|
21008
21468
|
} catch {
|
|
21009
21469
|
refuse2();
|
|
@@ -21018,7 +21478,7 @@ function appControls(path, read2) {
|
|
|
21018
21478
|
if (!identifier2(name) || !object4(entry) || !Object.keys(entry).every((key2) => ["id", "category", "required"].includes(key2)) || typeof entry.id !== "string" || !/^[A-Za-z0-9_-]{1,256}$/.test(entry.id) || entry.category !== undefined && (typeof entry.category !== "string" || !entry.category.trim() || entry.category.length > 256 || /[\x00-\x1f\x7f]/.test(entry.category)) || entry.required !== undefined && typeof entry.required !== "boolean")
|
|
21019
21479
|
refuse2();
|
|
21020
21480
|
}
|
|
21021
|
-
return
|
|
21481
|
+
return sha25622;
|
|
21022
21482
|
}
|
|
21023
21483
|
function codexAppDeclarationValid(path) {
|
|
21024
21484
|
try {
|
|
@@ -21033,9 +21493,9 @@ function codexAppDeclarationValid(path) {
|
|
|
21033
21493
|
}
|
|
21034
21494
|
function mcpControls(path, read2) {
|
|
21035
21495
|
const text2 = read2(path);
|
|
21036
|
-
let value,
|
|
21496
|
+
let value, sha25622;
|
|
21037
21497
|
try {
|
|
21038
|
-
|
|
21498
|
+
sha25622 = hashNativeJsonControls(text2);
|
|
21039
21499
|
value = JSON.parse(text2);
|
|
21040
21500
|
} catch {
|
|
21041
21501
|
refuse2();
|
|
@@ -21049,7 +21509,7 @@ function mcpControls(path, read2) {
|
|
|
21049
21509
|
for (const [name, server] of servers)
|
|
21050
21510
|
if (!isCodexLocalStdioMcpServer(name, server))
|
|
21051
21511
|
refuse2();
|
|
21052
|
-
return
|
|
21512
|
+
return sha25622;
|
|
21053
21513
|
}
|
|
21054
21514
|
function isBundledCleanupHooks(root, namespace, value) {
|
|
21055
21515
|
const object4 = (v) => Boolean(v && typeof v === "object" && !Array.isArray(v));
|
|
@@ -22775,12 +23235,12 @@ function writeExecutableCache(dataDir22, entries) {
|
|
|
22775
23235
|
if (lstatSync22(path, { throwIfNoEntry: false })?.isSymbolicLink())
|
|
22776
23236
|
return;
|
|
22777
23237
|
descriptor = openSync12(temporary, constants12.O_WRONLY | constants12.O_CREAT | constants12.O_EXCL | (constants12.O_NOFOLLOW ?? 0), 384);
|
|
22778
|
-
|
|
23238
|
+
writeFileSync42(descriptor, `${JSON.stringify({ schema: CODEX_NATIVE_POLICY_EXECUTABLE_CACHE_SCHEMA, entries: entries.slice(-16) })}
|
|
22779
23239
|
`);
|
|
22780
23240
|
fsyncSync4(descriptor);
|
|
22781
23241
|
closeSync12(descriptor);
|
|
22782
23242
|
descriptor = undefined;
|
|
22783
|
-
|
|
23243
|
+
renameSync32(temporary, path);
|
|
22784
23244
|
} catch {} finally {
|
|
22785
23245
|
if (descriptor !== undefined)
|
|
22786
23246
|
closeSync12(descriptor);
|
|
@@ -23074,12 +23534,12 @@ function recordCodexNativePolicyAcceptance(dataDir22, verification, accepted) {
|
|
|
23074
23534
|
let descriptor;
|
|
23075
23535
|
try {
|
|
23076
23536
|
descriptor = openSync12(temporary, constants12.O_WRONLY | constants12.O_CREAT | constants12.O_EXCL | (constants12.O_NOFOLLOW ?? 0), 384);
|
|
23077
|
-
|
|
23537
|
+
writeFileSync42(descriptor, `${JSON.stringify(value)}
|
|
23078
23538
|
`);
|
|
23079
23539
|
fsyncSync4(descriptor);
|
|
23080
23540
|
closeSync12(descriptor);
|
|
23081
23541
|
descriptor = undefined;
|
|
23082
|
-
|
|
23542
|
+
renameSync32(temporary, path);
|
|
23083
23543
|
} catch (error) {
|
|
23084
23544
|
refuse3("NATIVE_SKILL_POLICY_RECEIPT_FAILED", error.message);
|
|
23085
23545
|
} finally {
|
|
@@ -24002,7 +24462,7 @@ function openNarrowedWitnessLedger(dataDir22, options = { record: true }) {
|
|
|
24002
24462
|
const merged = merge(latest, added);
|
|
24003
24463
|
writeFileSync5(temporary, `${JSON.stringify({ schema: SCHEMA, entries: merged }, null, 2)}
|
|
24004
24464
|
`, { mode: 384, flag: "wx" });
|
|
24005
|
-
|
|
24465
|
+
renameSync42(temporary, path);
|
|
24006
24466
|
entries = merged;
|
|
24007
24467
|
added.length = 0;
|
|
24008
24468
|
} catch {
|
|
@@ -50157,7 +50617,7 @@ function claudeSkillsUsage(before, home) {
|
|
|
50157
50617
|
}
|
|
50158
50618
|
if (events3.length)
|
|
50159
50619
|
evidence.push(`Skills-managed hook entries in ${events3.join(", ")}`);
|
|
50160
|
-
const bridge =
|
|
50620
|
+
const bridge = join19(home, ".claude", "skills", "skills-cli", "SKILL.md");
|
|
50161
50621
|
let bridgePresent;
|
|
50162
50622
|
try {
|
|
50163
50623
|
bridgePresent = lstatSync7(bridge, { throwIfNoEntry: false }) !== undefined;
|
|
@@ -50169,9 +50629,9 @@ function claudeSkillsUsage(before, home) {
|
|
|
50169
50629
|
return evidence;
|
|
50170
50630
|
}
|
|
50171
50631
|
function skillsPolicyLocations(dataDir3) {
|
|
50172
|
-
const state = (path) =>
|
|
50632
|
+
const state = (path) => existsSync12(path) ? "present" : "absent";
|
|
50173
50633
|
if (dataDir3 !== undefined)
|
|
50174
|
-
return [`${
|
|
50634
|
+
return [`${join19(resolve10(dataDir3), "agent-policy.json")} (explicit data directory, absent)`];
|
|
50175
50635
|
const env = process.env, home = env.HOME || env.USERPROFILE || homedir7() || "/tmp", searched = [];
|
|
50176
50636
|
let selected = false;
|
|
50177
50637
|
for (const key2 of ["HASNA_SKILLS_DIR", "HASNA_SKILLS_HOME", "SKILLS_HOME"]) {
|
|
@@ -50182,13 +50642,13 @@ function skillsPolicyLocations(dataDir3) {
|
|
|
50182
50642
|
searched.push(`$${key2} (unset)`);
|
|
50183
50643
|
else {
|
|
50184
50644
|
selected = true;
|
|
50185
|
-
searched.push(`$${key2} -> ${
|
|
50645
|
+
searched.push(`$${key2} -> ${join19(resolve10(value), "agent-policy.json")} (selected, absent)`);
|
|
50186
50646
|
}
|
|
50187
50647
|
}
|
|
50188
|
-
const
|
|
50189
|
-
const base = typeof
|
|
50190
|
-
const xdg =
|
|
50191
|
-
const adopted = typeof
|
|
50648
|
+
const override2 = env.HASNA_DATA_HOME;
|
|
50649
|
+
const base = typeof override2 === "string" && override2.length > 0 ? override2 : process.platform === "darwin" ? join19(home, "Library", "Application Support", "Hasna") : join19(home, ".local", "share", "hasna");
|
|
50650
|
+
const xdg = join19(base, "skills"), xdgPolicy = join19(xdg, "agent-policy.json");
|
|
50651
|
+
const adopted = typeof override2 === "string" && override2.trim().length > 0 || existsSync12(join19(xdg, "server.db")) || existsSync12(join19(xdg, "config.json"));
|
|
50192
50652
|
if (selected)
|
|
50193
50653
|
searched.push(`${xdgPolicy} (not consulted, ${state(xdgPolicy)})`);
|
|
50194
50654
|
else if (adopted) {
|
|
@@ -50196,7 +50656,7 @@ function skillsPolicyLocations(dataDir3) {
|
|
|
50196
50656
|
searched.push(`${xdgPolicy} (selected, absent)`);
|
|
50197
50657
|
} else
|
|
50198
50658
|
searched.push(`${xdgPolicy} (not selected: the directory holds no server.db or config.json and HASNA_DATA_HOME is unset; ${state(xdgPolicy)})`);
|
|
50199
|
-
const legacy =
|
|
50659
|
+
const legacy = join19(home, ".hasna", "skills", "agent-policy.json");
|
|
50200
50660
|
searched.push(selected ? `${legacy} (not consulted, ${state(legacy)})` : `${legacy} (selected, absent)`);
|
|
50201
50661
|
return searched;
|
|
50202
50662
|
}
|
|
@@ -50208,13 +50668,13 @@ function planCoordinatedClaudeSettings(before, replacement, options) {
|
|
|
50208
50668
|
const plan = planClaudeHookEventsUpdate({
|
|
50209
50669
|
...options,
|
|
50210
50670
|
events: selected,
|
|
50211
|
-
expectedSettingsSha256: before === null ? "absent" :
|
|
50671
|
+
expectedSettingsSha256: before === null ? "absent" : createHash11("sha256").update(before).digest("hex"),
|
|
50212
50672
|
replacement
|
|
50213
50673
|
});
|
|
50214
50674
|
if (!plan) {
|
|
50215
50675
|
const usage = claudeSkillsUsage(before, options.home);
|
|
50216
50676
|
if (usage.length)
|
|
50217
|
-
throw new ClaudeSettingsRefusal("skills_policy_unresolved", `Skills manages ${
|
|
50677
|
+
throw new ClaudeSettingsRefusal("skills_policy_unresolved", `Skills manages ${join19(options.home, ".claude", "settings.json")} (${usage.join("; ")}), but no Skills agent policy resolved, ` + "so Hooks cannot coordinate this change and wrote nothing. Locations searched, in Skills resolution order: " + skillsPolicyLocations(options.dataDir).map((location, index) => `${index + 1}) ${location}`).join("; ") + ". Run hooks with the environment that selects the Skills data directory (for example HASNA_SKILLS_DIR), " + "or repair the integration with `skills hook install`.");
|
|
50218
50678
|
}
|
|
50219
50679
|
return plan;
|
|
50220
50680
|
}
|
|
@@ -50230,9 +50690,9 @@ function coordinateClaudeSettings(before, replacement, options, beforeWrite) {
|
|
|
50230
50690
|
// src/lib/target-adapters.ts
|
|
50231
50691
|
init_profiles();
|
|
50232
50692
|
import { spawnSync } from "child_process";
|
|
50233
|
-
import { chmodSync as chmodSync2, existsSync as
|
|
50693
|
+
import { chmodSync as chmodSync2, existsSync as existsSync14, mkdirSync as mkdirSync12, readFileSync as readFileSync10, readdirSync as readdirSync10, rmdirSync as rmdirSync2, statSync, unlinkSync as unlinkSync3, writeFileSync as writeFileSync10, renameSync as renameSync6 } from "fs";
|
|
50234
50694
|
import { tmpdir } from "os";
|
|
50235
|
-
import { basename as basename10, dirname as dirname11, join as
|
|
50695
|
+
import { basename as basename10, dirname as dirname11, join as join25 } from "path";
|
|
50236
50696
|
import { randomUUID as randomUUID5 } from "crypto";
|
|
50237
50697
|
var ADAPTER_TARGETS = ["muse", "kimi", "pi", "cursor"];
|
|
50238
50698
|
function isAdapterTarget(value) {
|
|
@@ -50283,7 +50743,7 @@ function messageOf(error61) {
|
|
|
50283
50743
|
function readJsonObject(path) {
|
|
50284
50744
|
let text3;
|
|
50285
50745
|
try {
|
|
50286
|
-
text3 =
|
|
50746
|
+
text3 = readFileSync10(path, "utf-8");
|
|
50287
50747
|
} catch (error61) {
|
|
50288
50748
|
if (error61?.code === "ENOENT")
|
|
50289
50749
|
return { status: "absent" };
|
|
@@ -50301,16 +50761,16 @@ function readJsonObject(path) {
|
|
|
50301
50761
|
}
|
|
50302
50762
|
function writeText(path, content) {
|
|
50303
50763
|
const dir = dirname11(path);
|
|
50304
|
-
|
|
50305
|
-
const temp =
|
|
50764
|
+
mkdirSync12(dir, { recursive: true });
|
|
50765
|
+
const temp = join25(dir, `.${basename10(path)}.${randomUUID5()}.tmp`);
|
|
50306
50766
|
try {
|
|
50307
50767
|
writeFileSync10(temp, content);
|
|
50308
|
-
if (
|
|
50768
|
+
if (existsSync14(path))
|
|
50309
50769
|
chmodSync2(temp, statSync(path).mode & 4095);
|
|
50310
50770
|
renameSync6(temp, path);
|
|
50311
50771
|
} catch (error61) {
|
|
50312
50772
|
try {
|
|
50313
|
-
if (
|
|
50773
|
+
if (existsSync14(temp))
|
|
50314
50774
|
unlinkSync3(temp);
|
|
50315
50775
|
} catch {}
|
|
50316
50776
|
throw error61;
|
|
@@ -50412,7 +50872,7 @@ function installKimi(hook, command, options, timeoutSeconds) {
|
|
|
50412
50872
|
|
|
50413
50873
|
${kimiBlock(command, timeoutSeconds)}
|
|
50414
50874
|
`;
|
|
50415
|
-
const candidate =
|
|
50875
|
+
const candidate = join25(tmpdir(), `hooks-kimi-config-${randomUUID5()}.toml`);
|
|
50416
50876
|
writeFileSync10(candidate, next);
|
|
50417
50877
|
let validationNote;
|
|
50418
50878
|
try {
|
|
@@ -50427,7 +50887,7 @@ ${kimiBlock(command, timeoutSeconds)}
|
|
|
50427
50887
|
}
|
|
50428
50888
|
} finally {
|
|
50429
50889
|
try {
|
|
50430
|
-
if (
|
|
50890
|
+
if (existsSync14(candidate))
|
|
50431
50891
|
unlinkSync3(candidate);
|
|
50432
50892
|
} catch {}
|
|
50433
50893
|
}
|
|
@@ -50576,29 +51036,29 @@ function museDiagnostic(outcome) {
|
|
|
50576
51036
|
return redactedDiagnostic(outcome.stderr) || redactedDiagnostic(outcome.stdout) || `exit ${outcome.status}`;
|
|
50577
51037
|
}
|
|
50578
51038
|
function removeMuseBundle(bundle) {
|
|
50579
|
-
const manifestPath =
|
|
51039
|
+
const manifestPath = join25(bundle, ".muse-plugin", "plugin.json");
|
|
50580
51040
|
try {
|
|
50581
|
-
if (
|
|
51041
|
+
if (existsSync14(manifestPath))
|
|
50582
51042
|
unlinkSync3(manifestPath);
|
|
50583
51043
|
} catch {}
|
|
50584
|
-
for (const dir of [
|
|
51044
|
+
for (const dir of [join25(bundle, ".muse-plugin"), bundle]) {
|
|
50585
51045
|
try {
|
|
50586
|
-
if (
|
|
51046
|
+
if (existsSync14(dir))
|
|
50587
51047
|
rmdirSync2(dir);
|
|
50588
51048
|
} catch {}
|
|
50589
51049
|
}
|
|
50590
51050
|
}
|
|
50591
51051
|
function museBundles(options) {
|
|
50592
51052
|
const root = musePluginRoot({ home: homeOf(options), env: options.env ?? process.env });
|
|
50593
|
-
if (!
|
|
51053
|
+
if (!existsSync14(root))
|
|
50594
51054
|
return [];
|
|
50595
51055
|
const out = [];
|
|
50596
51056
|
for (const entry of readdirSync10(root)) {
|
|
50597
|
-
const manifestPath =
|
|
50598
|
-
if (!
|
|
51057
|
+
const manifestPath = join25(root, entry, ".muse-plugin", "plugin.json");
|
|
51058
|
+
if (!existsSync14(manifestPath))
|
|
50599
51059
|
continue;
|
|
50600
51060
|
try {
|
|
50601
|
-
const manifest = JSON.parse(
|
|
51061
|
+
const manifest = JSON.parse(readFileSync10(manifestPath, "utf-8"));
|
|
50602
51062
|
for (const capability of manifest.capabilities?.hooks ?? []) {
|
|
50603
51063
|
const command = Array.isArray(capability.command) ? capability.command.join(" ") : "";
|
|
50604
51064
|
const hook = hookFromCommand(command) ?? hookFromMuseCommand(capability.command);
|
|
@@ -50612,10 +51072,10 @@ function museBundles(options) {
|
|
|
50612
51072
|
function museOwnFiles(options) {
|
|
50613
51073
|
const home = homeOf(options);
|
|
50614
51074
|
const env = options.env ?? process.env;
|
|
50615
|
-
const configBase = env.XDG_CONFIG_HOME?.startsWith("/") ? env.XDG_CONFIG_HOME :
|
|
50616
|
-
const dataBase = env.XDG_DATA_HOME?.startsWith("/") ? env.XDG_DATA_HOME :
|
|
50617
|
-
const searched = [
|
|
50618
|
-
const found = searched.filter((path) =>
|
|
51075
|
+
const configBase = env.XDG_CONFIG_HOME?.startsWith("/") ? env.XDG_CONFIG_HOME : join25(home, ".config");
|
|
51076
|
+
const dataBase = env.XDG_DATA_HOME?.startsWith("/") ? env.XDG_DATA_HOME : join25(home, ".local", "share");
|
|
51077
|
+
const searched = [join25(configBase, "muse", "settings.json"), join25(dataBase, "muse")];
|
|
51078
|
+
const found = searched.filter((path) => existsSync14(path));
|
|
50619
51079
|
return { present: found.length > 0, found, searched };
|
|
50620
51080
|
}
|
|
50621
51081
|
function readMuseState(options, runner = options.run ?? defaultRunner) {
|
|
@@ -50669,8 +51129,8 @@ function readMuseState(options, runner = options.run ?? defaultRunner) {
|
|
|
50669
51129
|
function installMuse(hook, command, options, timeoutSeconds) {
|
|
50670
51130
|
const runner = options.run ?? defaultRunner;
|
|
50671
51131
|
const bundle = adapterPath("muse", options, hook);
|
|
50672
|
-
const manifestPath =
|
|
50673
|
-
const existedBefore =
|
|
51132
|
+
const manifestPath = join25(bundle, ".muse-plugin", "plugin.json");
|
|
51133
|
+
const existedBefore = existsSync14(manifestPath);
|
|
50674
51134
|
const manifest = museManifest(hook, command, options, timeoutSeconds);
|
|
50675
51135
|
writeText(manifestPath, `${JSON.stringify(manifest, null, 2)}
|
|
50676
51136
|
`);
|
|
@@ -50729,7 +51189,7 @@ function installMuse(hook, command, options, timeoutSeconds) {
|
|
|
50729
51189
|
}
|
|
50730
51190
|
function readTextState(path) {
|
|
50731
51191
|
try {
|
|
50732
|
-
return { status: "verified", text:
|
|
51192
|
+
return { status: "verified", text: readFileSync10(path, "utf-8") };
|
|
50733
51193
|
} catch (error61) {
|
|
50734
51194
|
if (error61?.code === "ENOENT")
|
|
50735
51195
|
return { status: "absent" };
|
|
@@ -50876,8 +51336,8 @@ function removeFromAdapter(target, hook, options) {
|
|
|
50876
51336
|
return { removed: true };
|
|
50877
51337
|
}
|
|
50878
51338
|
const bundle = adapterPath("muse", options, hook);
|
|
50879
|
-
const manifestPath =
|
|
50880
|
-
const hadBundle =
|
|
51339
|
+
const manifestPath = join25(bundle, ".muse-plugin", "plugin.json");
|
|
51340
|
+
const hadBundle = existsSync14(manifestPath);
|
|
50881
51341
|
const bundleNote = hadBundle ? `the bundle at ${bundle} was left in place` : `no bundle was present at ${bundle}`;
|
|
50882
51342
|
const pluginId2 = `hasna-hook-${hook}`;
|
|
50883
51343
|
const result = (options.run ?? defaultRunner)("muse", ["plugins", "remove", pluginId2, "--json"]);
|
|
@@ -50908,8 +51368,8 @@ function removeFromAdapter(target, hook, options) {
|
|
|
50908
51368
|
}
|
|
50909
51369
|
|
|
50910
51370
|
// src/lib/installer.ts
|
|
50911
|
-
var __dirname2 = dirname19(
|
|
50912
|
-
var HOOKS_DIR =
|
|
51371
|
+
var __dirname2 = dirname19(fileURLToPath4(import.meta.url));
|
|
51372
|
+
var HOOKS_DIR = existsSync15(join26(__dirname2, "..", "..", "hooks", "hook-gitguard")) ? join26(__dirname2, "..", "..", "hooks") : join26(__dirname2, "..", "hooks");
|
|
50913
51373
|
function normalizeHookName(name) {
|
|
50914
51374
|
return name.startsWith("hook-") ? name : `hook-${name}`;
|
|
50915
51375
|
}
|
|
@@ -50998,17 +51458,17 @@ function getSettingsPath(scope = "global", target = "claude", codewithConfigPath
|
|
|
50998
51458
|
const capabilities = getTargetCapabilities(target, capabilityOptions(scope));
|
|
50999
51459
|
if (capabilities)
|
|
51000
51460
|
return capabilities.configPath;
|
|
51001
|
-
return
|
|
51461
|
+
return join26(homedir8(), ".claude", "settings.json");
|
|
51002
51462
|
}
|
|
51003
51463
|
function getHookPath(name) {
|
|
51004
51464
|
const shortName = shortHookName(name);
|
|
51005
51465
|
const resolved = resolveHookDir(shortName);
|
|
51006
51466
|
if (resolved)
|
|
51007
51467
|
return resolved;
|
|
51008
|
-
return
|
|
51468
|
+
return join26(HOOKS_DIR, normalizeHookName(shortName));
|
|
51009
51469
|
}
|
|
51010
51470
|
function hookExists(name) {
|
|
51011
|
-
return
|
|
51471
|
+
return existsSync15(getHookPath(name));
|
|
51012
51472
|
}
|
|
51013
51473
|
var settingsPreimages = new WeakMap;
|
|
51014
51474
|
var unreadableSettings = new WeakMap;
|
|
@@ -51018,7 +51478,7 @@ function readSettings2(scope = "global", target = "claude") {
|
|
|
51018
51478
|
return readCodexSettings(path);
|
|
51019
51479
|
let reason2 = "cannot be read";
|
|
51020
51480
|
try {
|
|
51021
|
-
if (
|
|
51481
|
+
if (existsSync15(path)) {
|
|
51022
51482
|
const text3 = readFileSync16(path, "utf-8");
|
|
51023
51483
|
reason2 = "is not valid JSON";
|
|
51024
51484
|
const value = JSON.parse(text3);
|
|
@@ -51035,7 +51495,7 @@ function readSettings2(scope = "global", target = "claude") {
|
|
|
51035
51495
|
console.warn("[hooks] Cannot read hook settings; repair the selected file before installation.");
|
|
51036
51496
|
}
|
|
51037
51497
|
const empty = {};
|
|
51038
|
-
if (!
|
|
51498
|
+
if (!existsSync15(path))
|
|
51039
51499
|
settingsPreimages.set(empty, { path, text: null });
|
|
51040
51500
|
else
|
|
51041
51501
|
unreadableSettings.set(empty, { path, reason: reason2 });
|
|
@@ -51043,19 +51503,19 @@ function readSettings2(scope = "global", target = "claude") {
|
|
|
51043
51503
|
}
|
|
51044
51504
|
function unreadableSettingsRefusal(settings, path) {
|
|
51045
51505
|
const captured = settingsPreimages.get(settings);
|
|
51046
|
-
if (captured?.path === path && captured.text !== null || !
|
|
51506
|
+
if (captured?.path === path && captured.text !== null || !existsSync15(path))
|
|
51047
51507
|
return;
|
|
51048
51508
|
const failed = unreadableSettings.get(settings);
|
|
51049
51509
|
const reason2 = captured?.path === path ? "was created after Hooks read the settings" : failed?.path === path ? failed.reason : "was not read as a settings object";
|
|
51050
51510
|
return new ClaudeSettingsRefusal("settings_unreadable", `${path} ${reason2}, so Hooks wrote nothing. Repair the file or move it aside, then retry.`);
|
|
51051
51511
|
}
|
|
51052
51512
|
function settingsIdentity(path) {
|
|
51053
|
-
if (
|
|
51513
|
+
if (existsSync15(path))
|
|
51054
51514
|
return realpathSync6(path);
|
|
51055
|
-
return
|
|
51515
|
+
return existsSync15(dirname19(path)) ? join26(realpathSync6(dirname19(path)), basename14(path)) : resolve29(path);
|
|
51056
51516
|
}
|
|
51057
51517
|
function coordinatesWithSkills(path, target) {
|
|
51058
|
-
return target === "claude" && settingsIdentity(path) === settingsIdentity(
|
|
51518
|
+
return target === "claude" && settingsIdentity(path) === settingsIdentity(join26(homedir8(), ".claude/settings.json"));
|
|
51059
51519
|
}
|
|
51060
51520
|
function planClaudeSettingsWrite(before, after, scope = "global") {
|
|
51061
51521
|
if (coordinatesWithSkills(getSettingsPath(scope, "claude"), "claude"))
|
|
@@ -51081,7 +51541,7 @@ function writeSettings(settings, scope = "global", target = "claude", expectedSe
|
|
|
51081
51541
|
const before = settingsPreimages.get(settings);
|
|
51082
51542
|
if (!before || before.path !== path)
|
|
51083
51543
|
throw new Error("Claude settings require a valid captured preimage before installation.");
|
|
51084
|
-
const current2 =
|
|
51544
|
+
const current2 = existsSync15(path) ? readFileSync16(path, "utf8") : null;
|
|
51085
51545
|
if (current2 !== before.text)
|
|
51086
51546
|
throw new Error("Claude settings changed during installation; no settings were written.");
|
|
51087
51547
|
if (coordinateClaudeSettings(before.text, JSON.stringify(settings, null, 2) + `
|
|
@@ -51092,8 +51552,8 @@ function writeSettings(settings, scope = "global", target = "claude", expectedSe
|
|
|
51092
51552
|
return writeHookSettingsPreimage(path, settings, captured.text, beforeWrite);
|
|
51093
51553
|
beforeWrite?.();
|
|
51094
51554
|
const dir = dirname19(path);
|
|
51095
|
-
if (!
|
|
51096
|
-
|
|
51555
|
+
if (!existsSync15(dir)) {
|
|
51556
|
+
mkdirSync13(dir, { recursive: true });
|
|
51097
51557
|
}
|
|
51098
51558
|
writeFileSync11(path, JSON.stringify(settings, null, 2) + `
|
|
51099
51559
|
`);
|
|
@@ -51194,7 +51654,7 @@ function buildCodewithTomlFragment(name, profile, mementos) {
|
|
|
51194
51654
|
function readCodewithConfig(scope, configPath) {
|
|
51195
51655
|
const path = getSettingsPath(scope, "codewith", configPath);
|
|
51196
51656
|
try {
|
|
51197
|
-
return
|
|
51657
|
+
return existsSync15(path) ? readFileSync16(path, "utf-8") : "";
|
|
51198
51658
|
} catch {
|
|
51199
51659
|
return "";
|
|
51200
51660
|
}
|
|
@@ -51202,9 +51662,9 @@ function readCodewithConfig(scope, configPath) {
|
|
|
51202
51662
|
function appendCodewithFragment(fragment, scope, configPath) {
|
|
51203
51663
|
const path = getSettingsPath(scope, "codewith", configPath);
|
|
51204
51664
|
const dir = dirname19(path);
|
|
51205
|
-
if (!
|
|
51206
|
-
|
|
51207
|
-
const existing =
|
|
51665
|
+
if (!existsSync15(dir))
|
|
51666
|
+
mkdirSync13(dir, { recursive: true });
|
|
51667
|
+
const existing = existsSync15(path) ? readFileSync16(path, "utf-8") : "";
|
|
51208
51668
|
const sep11 = existing.trim() ? `
|
|
51209
51669
|
|
|
51210
51670
|
` : "";
|
|
@@ -51731,7 +52191,7 @@ function codewithHasHookEntryInText(configText, name) {
|
|
|
51731
52191
|
}
|
|
51732
52192
|
function codewithHasHookEntry(name, scope = "global") {
|
|
51733
52193
|
const path = getSettingsPath(scope, "codewith");
|
|
51734
|
-
if (!
|
|
52194
|
+
if (!existsSync15(path))
|
|
51735
52195
|
return false;
|
|
51736
52196
|
try {
|
|
51737
52197
|
return codewithHasHookEntryInText(readFileSync16(path, "utf-8"), name);
|
|
@@ -51743,12 +52203,12 @@ function removeStoreDirFailClosed(dir) {
|
|
|
51743
52203
|
const entries = readdirSync13(dir, { withFileTypes: true });
|
|
51744
52204
|
for (const entry of entries) {
|
|
51745
52205
|
if (entry.isDirectory()) {
|
|
51746
|
-
removeStoreDirFailClosed(
|
|
52206
|
+
removeStoreDirFailClosed(join26(dir, entry.name));
|
|
51747
52207
|
}
|
|
51748
52208
|
}
|
|
51749
52209
|
for (const entry of entries) {
|
|
51750
52210
|
if (!entry.isDirectory()) {
|
|
51751
|
-
unlinkSync7(
|
|
52211
|
+
unlinkSync7(join26(dir, entry.name));
|
|
51752
52212
|
}
|
|
51753
52213
|
}
|
|
51754
52214
|
rmdirSync4(dir);
|
|
@@ -51844,7 +52304,7 @@ function uninstallHook(name, scope = "global", target = "claude", options = {})
|
|
|
51844
52304
|
}
|
|
51845
52305
|
if (target === "codewith" || target === "all") {
|
|
51846
52306
|
const codewithPath = getSettingsPath(scope, "codewith");
|
|
51847
|
-
if (
|
|
52307
|
+
if (existsSync15(codewithPath)) {
|
|
51848
52308
|
const before = readFileSync16(codewithPath, "utf-8");
|
|
51849
52309
|
const after = removeCodewithHookEntry(before, shortName);
|
|
51850
52310
|
if (after.removed) {
|
|
@@ -51899,6 +52359,8 @@ function uninstallHook(name, scope = "global", target = "claude", options = {})
|
|
|
51899
52359
|
});
|
|
51900
52360
|
}
|
|
51901
52361
|
// src/index.ts
|
|
52362
|
+
init_registry();
|
|
52363
|
+
init_resolve();
|
|
51902
52364
|
import { readFileSync as readFileSync33 } from "fs";
|
|
51903
52365
|
init_profiles();
|
|
51904
52366
|
init_config();
|
|
@@ -52037,16 +52499,18 @@ init_db();
|
|
|
52037
52499
|
init_db_writer();
|
|
52038
52500
|
init_store();
|
|
52039
52501
|
init_manifest();
|
|
52502
|
+
init_resolve();
|
|
52040
52503
|
|
|
52041
52504
|
// src/lib/custom-install.ts
|
|
52042
52505
|
init_config();
|
|
52043
52506
|
init_manifest();
|
|
52044
|
-
|
|
52045
|
-
import {
|
|
52507
|
+
init_install_record();
|
|
52508
|
+
import { existsSync as existsSync16, mkdirSync as mkdirSync14, mkdtempSync as mkdtempSync2, readFileSync as readFileSync23, rmSync as rmSync5 } from "fs";
|
|
52509
|
+
import { join as join38 } from "path";
|
|
52046
52510
|
import { tmpdir as tmpdir2 } from "os";
|
|
52047
52511
|
function manifestAt(dir) {
|
|
52048
|
-
const path =
|
|
52049
|
-
if (!
|
|
52512
|
+
const path = join38(dir, "manifest.json");
|
|
52513
|
+
if (!existsSync16(path))
|
|
52050
52514
|
return;
|
|
52051
52515
|
try {
|
|
52052
52516
|
return parseManifest(readFileSync23(path, "utf-8"));
|
|
@@ -52064,12 +52528,12 @@ function copyManifestDir(srcDir, source, kind) {
|
|
|
52064
52528
|
function writeFromManifest(manifest, srcDir, source, kind) {
|
|
52065
52529
|
const script = resolveScript(manifest, srcDir);
|
|
52066
52530
|
const name = shortManifestName(manifest.name);
|
|
52067
|
-
const { dir, scriptPath } =
|
|
52531
|
+
const { dir, scriptPath } = commitInstall(name, manifest, script.content, script.path, { source: kind, sourceRef: source });
|
|
52068
52532
|
return { name, version: manifest.version, kind, source, dir, scriptPath };
|
|
52069
52533
|
}
|
|
52070
52534
|
async function cloneToTemp(gitUrl) {
|
|
52071
|
-
const tmp = mkdtempSync2(
|
|
52072
|
-
const proc = Bun.spawn(["git", "clone", "--depth", "1", "--quiet", gitUrl,
|
|
52535
|
+
const tmp = mkdtempSync2(join38(tmpdir2(), "hooks-install-"));
|
|
52536
|
+
const proc = Bun.spawn(["git", "clone", "--depth", "1", "--quiet", gitUrl, join38(tmp, "repo")], {
|
|
52073
52537
|
stdout: "pipe",
|
|
52074
52538
|
stderr: "pipe"
|
|
52075
52539
|
});
|
|
@@ -52082,7 +52546,7 @@ async function cloneToTemp(gitUrl) {
|
|
|
52082
52546
|
rmSync5(tmp, { recursive: true, force: true });
|
|
52083
52547
|
throw new Error(`git clone failed (${exitCode}): ${stderr.trim()}`);
|
|
52084
52548
|
}
|
|
52085
|
-
return
|
|
52549
|
+
return join38(tmp, "repo");
|
|
52086
52550
|
}
|
|
52087
52551
|
function isGitUrl(value) {
|
|
52088
52552
|
return value.startsWith("git@") || value.startsWith("ssh://") || value.startsWith("file://") || value.endsWith(".git");
|
|
@@ -52092,7 +52556,7 @@ function isCustomSource(value) {
|
|
|
52092
52556
|
return true;
|
|
52093
52557
|
if (value.startsWith("http://") || value.startsWith("https://"))
|
|
52094
52558
|
return true;
|
|
52095
|
-
return
|
|
52559
|
+
return existsSync16(value);
|
|
52096
52560
|
}
|
|
52097
52561
|
async function installCustomSource(source) {
|
|
52098
52562
|
if (isGitUrl(source)) {
|
|
@@ -52106,7 +52570,7 @@ async function installCustomSource(source) {
|
|
|
52106
52570
|
if (source.startsWith("http://") || source.startsWith("https://")) {
|
|
52107
52571
|
return installManifestUrl(source);
|
|
52108
52572
|
}
|
|
52109
|
-
if (!
|
|
52573
|
+
if (!existsSync16(source)) {
|
|
52110
52574
|
throw new Error(`No such local path: ${source}`);
|
|
52111
52575
|
}
|
|
52112
52576
|
if (source.endsWith("manifest.json")) {
|
|
@@ -52125,7 +52589,7 @@ async function installManifestUrl(url2) {
|
|
|
52125
52589
|
const inline = manifest.script_kind === "inline" || manifest.script_kind === undefined && manifest.script.includes(`
|
|
52126
52590
|
`);
|
|
52127
52591
|
if (inline) {
|
|
52128
|
-
script = { path:
|
|
52592
|
+
script = { path: scriptRelFor(manifest), content: manifest.script };
|
|
52129
52593
|
} else {
|
|
52130
52594
|
const base = url2.substring(0, url2.lastIndexOf("/"));
|
|
52131
52595
|
const scriptUrl = `${base}/${manifest.script}`;
|
|
@@ -52136,23 +52600,25 @@ async function installManifestUrl(url2) {
|
|
|
52136
52600
|
script = { path: manifest.script, content: await scriptRes.text() };
|
|
52137
52601
|
}
|
|
52138
52602
|
const name = shortManifestName(manifest.name);
|
|
52139
|
-
const { dir, scriptPath } =
|
|
52603
|
+
const { dir, scriptPath } = commitInstall(name, manifest, script.content, script.path, { source: "url", sourceRef: url2 });
|
|
52140
52604
|
return { name, version: manifest.version, kind: "url", source: url2, dir, scriptPath };
|
|
52141
52605
|
}
|
|
52142
52606
|
// src/lib/sync.ts
|
|
52143
52607
|
init_config();
|
|
52144
|
-
|
|
52145
|
-
import {
|
|
52146
|
-
import {
|
|
52608
|
+
init_registry();
|
|
52609
|
+
import { createHash as createHash21, randomUUID as randomUUID7 } from "crypto";
|
|
52610
|
+
import { readFileSync as readFileSync24, lstatSync as lstatSync19, mkdirSync as mkdirSync15, writeFileSync as writeFileSync12, accessSync as accessSync3, constants as constants4, existsSync as existsSync17 } from "fs";
|
|
52611
|
+
import { dirname as dirname31, join as join39, resolve as resolve31, sep as sep17 } from "path";
|
|
52147
52612
|
init_db();
|
|
52148
52613
|
init_store();
|
|
52149
52614
|
init_manifest();
|
|
52615
|
+
init_resolve();
|
|
52150
52616
|
init_registry_artifact();
|
|
52151
52617
|
function sha256OfText(text3) {
|
|
52152
|
-
return
|
|
52618
|
+
return createHash21("sha256").update(text3).digest("hex");
|
|
52153
52619
|
}
|
|
52154
52620
|
function sha256OfPath(path) {
|
|
52155
|
-
return
|
|
52621
|
+
return createHash21("sha256").update(readFileSync24(path)).digest("hex");
|
|
52156
52622
|
}
|
|
52157
52623
|
function collectBundledCatalog() {
|
|
52158
52624
|
const out = [];
|
|
@@ -52323,7 +52789,7 @@ function prepareRegistryCommit(staged) {
|
|
|
52323
52789
|
const script = resolve31(root, item.scriptRel);
|
|
52324
52790
|
if (script !== root && !script.startsWith(root + sep17))
|
|
52325
52791
|
throw new ScriptContainmentError(script, root, item.scriptRel);
|
|
52326
|
-
const manifest =
|
|
52792
|
+
const manifest = join39(root, "manifest.json");
|
|
52327
52793
|
if (script === manifest || script === root)
|
|
52328
52794
|
throw new Error("REGISTRY_SYNC_DESTINATION_INVALID");
|
|
52329
52795
|
for (let path = dirname31(script);; path = dirname31(path)) {
|
|
@@ -52338,24 +52804,24 @@ function prepareRegistryCommit(staged) {
|
|
|
52338
52804
|
if (path === root)
|
|
52339
52805
|
break;
|
|
52340
52806
|
}
|
|
52341
|
-
if (
|
|
52807
|
+
if (existsSync17(root))
|
|
52342
52808
|
assertContained(script, root, item.scriptRel);
|
|
52343
52809
|
inspectFile(script);
|
|
52344
52810
|
inspectFile(manifest);
|
|
52345
52811
|
}
|
|
52346
52812
|
inspectFile(getLockPath());
|
|
52347
52813
|
if (originals.size) {
|
|
52348
|
-
const recovery =
|
|
52349
|
-
|
|
52814
|
+
const recovery = join39(getHooksDataDir(), "registry-preservation", randomUUID7());
|
|
52815
|
+
mkdirSync15(recovery, { recursive: true, mode: 448 });
|
|
52350
52816
|
const receipt = [];
|
|
52351
52817
|
for (const [target, bytes] of originals) {
|
|
52352
|
-
const path =
|
|
52818
|
+
const path = join39(recovery, `${receipt.length}.original`);
|
|
52353
52819
|
writeFileSync12(path, bytes, { flag: "wx", mode: 384 });
|
|
52354
52820
|
if (!readFileSync24(path).equals(bytes))
|
|
52355
52821
|
throw new Error("REGISTRY_PRESERVATION_READBACK_FAILED");
|
|
52356
|
-
receipt.push({ target, preserved: path, sha256:
|
|
52822
|
+
receipt.push({ target, preserved: path, sha256: createHash21("sha256").update(bytes).digest("hex"), readback: true });
|
|
52357
52823
|
}
|
|
52358
|
-
writeFileSync12(
|
|
52824
|
+
writeFileSync12(join39(recovery, "receipt.json"), JSON.stringify(receipt, null, 2) + `
|
|
52359
52825
|
`, { flag: "wx", mode: 384 });
|
|
52360
52826
|
}
|
|
52361
52827
|
for (const item of staged)
|
|
@@ -52548,11 +53014,13 @@ async function installPinnedFromBundled(name, version3) {
|
|
|
52548
53014
|
};
|
|
52549
53015
|
}
|
|
52550
53016
|
// src/serve.ts
|
|
53017
|
+
init_registry();
|
|
52551
53018
|
init_manifest();
|
|
52552
53019
|
init_store();
|
|
53020
|
+
init_resolve();
|
|
52553
53021
|
import { readFileSync as readFileSync25 } from "fs";
|
|
52554
|
-
import { dirname as dirname33, join as
|
|
52555
|
-
import { fileURLToPath as
|
|
53022
|
+
import { dirname as dirname33, join as join43 } from "path";
|
|
53023
|
+
import { fileURLToPath as fileURLToPath6 } from "url";
|
|
52556
53024
|
|
|
52557
53025
|
// src/lib/secure-compare.ts
|
|
52558
53026
|
function secureEqual(a, b) {
|
|
@@ -52729,6 +53197,34 @@ function buildOpenApiDocument(version3) {
|
|
|
52729
53197
|
}
|
|
52730
53198
|
}
|
|
52731
53199
|
},
|
|
53200
|
+
"/v1/events/errors": {
|
|
53201
|
+
post: {
|
|
53202
|
+
summary: "Append one failed hook run (error-only, no content); 120 per key per minute",
|
|
53203
|
+
operationId: "postErrorEvent",
|
|
53204
|
+
security: [{ apiKey: [] }],
|
|
53205
|
+
requestBody: { required: true, content: { "application/json": { schema: { type: "object", additionalProperties: false, required: ["hook", "event", "class", "exit_code", "duration_ms", "station", "harness", "hooks_version", "at"], properties: {
|
|
53206
|
+
hook: { type: "string", pattern: "^[a-z0-9][a-z0-9_-]{0,127}$" },
|
|
53207
|
+
event: { type: "string", pattern: "^[A-Za-z][A-Za-z0-9_]*$", maxLength: 64 },
|
|
53208
|
+
class: { type: "string", enum: ["nonzero-exit", "guard-blocked-unrunnable", "missing-script", "trust-changed", "trust-unreadable", "invalid-options", "start-failed", "timed-out"] },
|
|
53209
|
+
exit_code: { type: ["integer", "null"] },
|
|
53210
|
+
duration_ms: { type: "integer", minimum: 0, maximum: 86400000 },
|
|
53211
|
+
station: { type: "string", maxLength: 64 },
|
|
53212
|
+
harness: { type: "string", enum: ["claude", "codex", "other"] },
|
|
53213
|
+
hooks_version: { type: "string", maxLength: 32 },
|
|
53214
|
+
at: { type: "string", format: "date-time" }
|
|
53215
|
+
} } } } },
|
|
53216
|
+
responses: { "202": { description: "Recorded" }, "400": { description: "Unknown field or invalid value", content: { "application/json": { schema: { $ref: "#/components/schemas/HooksError" } } } }, "429": { description: "More than 120 events from this key in the last minute", content: { "application/json": { schema: { $ref: "#/components/schemas/HooksError" } } } } }
|
|
53217
|
+
}
|
|
53218
|
+
},
|
|
53219
|
+
"/v1/events/errors/summary": {
|
|
53220
|
+
get: {
|
|
53221
|
+
summary: "Hourly counts of failed hook runs by station, hook, event and class",
|
|
53222
|
+
operationId: "getErrorEventSummary",
|
|
53223
|
+
parameters: [{ name: "since", in: "query", required: false, schema: { type: "string", format: "date-time" }, description: "UTC instant within the last 30 days; default 24 hours ago" }],
|
|
53224
|
+
security: [{ apiKey: [] }],
|
|
53225
|
+
responses: { "200": { description: "Counts per hour", content: { "application/json": { schema: { type: "object", properties: { since: { type: "string" }, hours: { type: "array", items: { type: "object", properties: { hour: { type: "string" }, station: { type: "string" }, hook: { type: "string" }, event: { type: "string" }, class: { type: "string" }, count: { type: "integer" } } } } } } } } } }
|
|
53226
|
+
}
|
|
53227
|
+
},
|
|
52732
53228
|
"/v1/selections/{profile}": {
|
|
52733
53229
|
get: {
|
|
52734
53230
|
summary: "Read one exact hosted selection profile",
|
|
@@ -53123,7 +53619,7 @@ class HostedRegistry {
|
|
|
53123
53619
|
init_registry_artifact();
|
|
53124
53620
|
|
|
53125
53621
|
// node_modules/@hasna/contracts/dist/auth/index.js
|
|
53126
|
-
import { createHash as
|
|
53622
|
+
import { createHash as createHash24, createHmac, randomBytes as randomBytes4, timingSafeEqual } from "crypto";
|
|
53127
53623
|
var MAX_TENANT_ID_LENGTH = 64;
|
|
53128
53624
|
var TENANT_ID_PATTERN = new RegExp(`^[A-Za-z0-9][A-Za-z0-9._-]{0,${MAX_TENANT_ID_LENGTH - 1}}$`);
|
|
53129
53625
|
var UUID_HEX = "[0-9a-fA-F]";
|
|
@@ -53789,13 +54285,125 @@ function registryKeyStatus() {
|
|
|
53789
54285
|
}
|
|
53790
54286
|
async function authenticateRegistryRequest(request, verifier) {
|
|
53791
54287
|
const auth = verifier ?? createRegistryVerifier(resolveSigningSecret("hooks", process.env, process.env.HASNA_HOOKS_API_SIGNING_KEY !== undefined ? { envName: "HASNA_HOOKS_API_SIGNING_KEY" } : {}).value, registryKeyStatus());
|
|
54288
|
+
const path = new URL(request.url).pathname;
|
|
53792
54289
|
const decision = await auth.authenticate(request.headers, {
|
|
53793
54290
|
method: request.method,
|
|
53794
|
-
path
|
|
53795
|
-
requiredScopes: [request.method === "GET" ? "hooks:read" : "hooks:write"]
|
|
54291
|
+
path,
|
|
54292
|
+
requiredScopes: [request.method === "GET" || isErrorEventWrite(request.method, path) ? "hooks:read" : "hooks:write"]
|
|
53796
54293
|
});
|
|
53797
54294
|
if (!decision.ok)
|
|
53798
54295
|
throw new RegistryError(decision.status, "REGISTRY_AUTH_" + decision.reason.toUpperCase());
|
|
54296
|
+
return decision.principal.kid;
|
|
54297
|
+
}
|
|
54298
|
+
function isErrorEventWrite(method, path) {
|
|
54299
|
+
return method === "POST" && path.replace(/^\/api\/v1(?=\/|$)/, "/v1") === "/v1/events/errors";
|
|
54300
|
+
}
|
|
54301
|
+
|
|
54302
|
+
// src/lib/error-events.ts
|
|
54303
|
+
init_registry_artifact();
|
|
54304
|
+
var ERROR_EVENT_CLASSES = ["nonzero-exit", "guard-blocked-unrunnable", "missing-script", "trust-changed", "trust-unreadable", "invalid-options", "start-failed", "timed-out"];
|
|
54305
|
+
var ERROR_EVENT_HARNESSES = ["claude", "codex", "other"];
|
|
54306
|
+
var ERROR_EVENT_RETENTION_DAYS = 30;
|
|
54307
|
+
var ERROR_EVENT_RATE_PER_MINUTE = 120;
|
|
54308
|
+
var ERROR_EVENT_MAX_BYTES = 4096;
|
|
54309
|
+
var MAX_SUMMARY_ROWS = 5000;
|
|
54310
|
+
var MAX_EVENT_AGE_MS = 24 * 3600000;
|
|
54311
|
+
var MAX_EVENT_SKEW_MS = 5 * 60000;
|
|
54312
|
+
var quoted2 = (values) => values.map((value) => `'${value}'`).join(",");
|
|
54313
|
+
var ERROR_EVENT_MIGRATIONS = [
|
|
54314
|
+
`CREATE TABLE IF NOT EXISTS hooks_error_events (id BIGSERIAL PRIMARY KEY, key_id TEXT NOT NULL, hook TEXT NOT NULL, event TEXT NOT NULL, class TEXT NOT NULL CHECK(class IN (${quoted2(ERROR_EVENT_CLASSES)})), exit_code INTEGER, duration_ms INTEGER NOT NULL CHECK(duration_ms >= 0), station TEXT NOT NULL, harness TEXT NOT NULL CHECK(harness IN (${quoted2(ERROR_EVENT_HARNESSES)})), hooks_version TEXT NOT NULL, at TIMESTAMPTZ NOT NULL, received_at TIMESTAMPTZ NOT NULL DEFAULT NOW())`,
|
|
54315
|
+
`CREATE INDEX IF NOT EXISTS idx_hooks_error_events_received ON hooks_error_events (received_at)`,
|
|
54316
|
+
`CREATE INDEX IF NOT EXISTS idx_hooks_error_events_key_received ON hooks_error_events (key_id, received_at)`,
|
|
54317
|
+
`CREATE INDEX IF NOT EXISTS idx_hooks_error_events_at ON hooks_error_events (at)`
|
|
54318
|
+
];
|
|
54319
|
+
var FIELDS = ["hook", "event", "class", "exit_code", "duration_ms", "station", "harness", "hooks_version", "at"];
|
|
54320
|
+
var INT32_MIN = -2147483648;
|
|
54321
|
+
var INT32_MAX = 2147483647;
|
|
54322
|
+
function text3(value, field3, max, pattern) {
|
|
54323
|
+
if (typeof value !== "string" || !value.length || value.length > max || !pattern.test(value))
|
|
54324
|
+
throw new RegistryError(400, `ERROR_EVENT_${field3.toUpperCase()}_INVALID`);
|
|
54325
|
+
return value;
|
|
54326
|
+
}
|
|
54327
|
+
function integer4(value, field3, min, max) {
|
|
54328
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < min || value > max)
|
|
54329
|
+
throw new RegistryError(400, `ERROR_EVENT_${field3.toUpperCase()}_INVALID`);
|
|
54330
|
+
return value;
|
|
54331
|
+
}
|
|
54332
|
+
function validateErrorEvent(value, now = Date.now()) {
|
|
54333
|
+
if (!value || typeof value !== "object" || Array.isArray(value))
|
|
54334
|
+
throw new RegistryError(400, "ERROR_EVENT_INVALID");
|
|
54335
|
+
const input2 = value, keys2 = Object.keys(input2);
|
|
54336
|
+
if (keys2.length !== FIELDS.length || keys2.some((key2) => !FIELDS.includes(key2)))
|
|
54337
|
+
throw new RegistryError(400, "ERROR_EVENT_FIELDS_INVALID");
|
|
54338
|
+
if (!ERROR_EVENT_CLASSES.includes(input2.class))
|
|
54339
|
+
throw new RegistryError(400, "ERROR_EVENT_CLASS_INVALID");
|
|
54340
|
+
if (!ERROR_EVENT_HARNESSES.includes(input2.harness))
|
|
54341
|
+
throw new RegistryError(400, "ERROR_EVENT_HARNESS_INVALID");
|
|
54342
|
+
const at = text3(input2.at, "at", 40, /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,6})?Z$/);
|
|
54343
|
+
const when = Date.parse(at);
|
|
54344
|
+
if (!Number.isFinite(when) || when < now - MAX_EVENT_AGE_MS || when > now + MAX_EVENT_SKEW_MS)
|
|
54345
|
+
throw new RegistryError(400, "ERROR_EVENT_AT_INVALID");
|
|
54346
|
+
return {
|
|
54347
|
+
hook: text3(input2.hook, "hook", 128, REGISTRY_NAME),
|
|
54348
|
+
event: text3(input2.event, "event", 64, /^[A-Za-z][A-Za-z0-9_]*$/),
|
|
54349
|
+
class: input2.class,
|
|
54350
|
+
exit_code: input2.exit_code === null ? null : integer4(input2.exit_code, "exit_code", INT32_MIN, INT32_MAX),
|
|
54351
|
+
duration_ms: integer4(input2.duration_ms, "duration_ms", 0, 86400000),
|
|
54352
|
+
station: text3(input2.station, "station", 64, /^[A-Za-z0-9][A-Za-z0-9._-]*$/),
|
|
54353
|
+
harness: input2.harness,
|
|
54354
|
+
hooks_version: text3(input2.hooks_version, "hooks_version", 32, /^[0-9A-Za-z][0-9A-Za-z.+-]*$/),
|
|
54355
|
+
at
|
|
54356
|
+
};
|
|
54357
|
+
}
|
|
54358
|
+
function summarySince(value, now = Date.now()) {
|
|
54359
|
+
if (value === null)
|
|
54360
|
+
return new Date(now - 24 * 3600000).toISOString();
|
|
54361
|
+
const when = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?Z$/.test(value) ? Date.parse(value) : NaN;
|
|
54362
|
+
if (!Number.isFinite(when) || when < now - ERROR_EVENT_RETENTION_DAYS * 24 * 3600000 || when > now)
|
|
54363
|
+
throw new RegistryError(400, "ERROR_EVENT_SINCE_INVALID");
|
|
54364
|
+
return new Date(when).toISOString();
|
|
54365
|
+
}
|
|
54366
|
+
|
|
54367
|
+
class PgErrorEventStore {
|
|
54368
|
+
db;
|
|
54369
|
+
constructor(db) {
|
|
54370
|
+
this.db = db;
|
|
54371
|
+
}
|
|
54372
|
+
async insert(event, keyId) {
|
|
54373
|
+
return (await this.db.run(`INSERT INTO hooks_error_events (key_id,hook,event,class,exit_code,duration_ms,station,harness,hooks_version,at)
|
|
54374
|
+
SELECT ?::text,?::text,?::text,?::text,?::integer,?::integer,?::text,?::text,?::text,?::timestamptz
|
|
54375
|
+
WHERE (SELECT COUNT(*) FROM hooks_error_events WHERE key_id = ?::text AND received_at > NOW() - INTERVAL '60 seconds') < ?::integer`, keyId, event.hook, event.event, event.class, event.exit_code, event.duration_ms, event.station, event.harness, event.hooks_version, event.at, keyId, ERROR_EVENT_RATE_PER_MINUTE)).changes === 1;
|
|
54376
|
+
}
|
|
54377
|
+
async prune() {
|
|
54378
|
+
return (await this.db.run(`DELETE FROM hooks_error_events WHERE received_at < NOW() - INTERVAL '${ERROR_EVENT_RETENTION_DAYS} days'`)).changes;
|
|
54379
|
+
}
|
|
54380
|
+
async summary(since) {
|
|
54381
|
+
return await this.db.all(`SELECT to_char(date_trunc('hour', at AT TIME ZONE 'UTC'), 'YYYY-MM-DD"T"HH24":00:00Z"') AS hour, station, hook, event, class, COUNT(*)::integer AS count
|
|
54382
|
+
FROM hooks_error_events WHERE at >= ?::timestamptz GROUP BY 1,2,3,4,5 ORDER BY 1,2,3,4,5 LIMIT ${MAX_SUMMARY_ROWS}`, since);
|
|
54383
|
+
}
|
|
54384
|
+
}
|
|
54385
|
+
|
|
54386
|
+
class HostedErrorEvents {
|
|
54387
|
+
store;
|
|
54388
|
+
now;
|
|
54389
|
+
prunedAt = 0;
|
|
54390
|
+
constructor(store, now = Date.now) {
|
|
54391
|
+
this.store = store;
|
|
54392
|
+
this.now = now;
|
|
54393
|
+
}
|
|
54394
|
+
async record(value, keyId) {
|
|
54395
|
+
const event = validateErrorEvent(value, this.now());
|
|
54396
|
+
if (this.now() - this.prunedAt >= 3600000) {
|
|
54397
|
+
this.prunedAt = this.now();
|
|
54398
|
+
await this.store.prune().catch(() => 0);
|
|
54399
|
+
}
|
|
54400
|
+
if (!await this.store.insert(event, keyId))
|
|
54401
|
+
throw new RegistryError(429, "ERROR_EVENT_RATE_LIMITED");
|
|
54402
|
+
}
|
|
54403
|
+
async summary(since) {
|
|
54404
|
+
const from = summarySince(since, this.now());
|
|
54405
|
+
return { since: from, hours: await this.store.summary(from) };
|
|
54406
|
+
}
|
|
53799
54407
|
}
|
|
53800
54408
|
|
|
53801
54409
|
// src/registry-http.ts
|
|
@@ -53812,6 +54420,18 @@ function configuredRegistry() {
|
|
|
53812
54420
|
serverRegistry = new HostedRegistry(new PgRegistryStore(new PgAdapterAsync(url2, { timeoutMs: 5000 })));
|
|
53813
54421
|
return serverRegistry;
|
|
53814
54422
|
}
|
|
54423
|
+
var serverErrorEvents;
|
|
54424
|
+
function configuredErrorEvents() {
|
|
54425
|
+
if (serverErrorEvents)
|
|
54426
|
+
return serverErrorEvents;
|
|
54427
|
+
if (getStorageBackend() !== "postgresql")
|
|
54428
|
+
throw new RegistryError(503, "REGISTRY_DATABASE_REQUIRED");
|
|
54429
|
+
const url2 = getStorageDatabaseUrl();
|
|
54430
|
+
if (!url2)
|
|
54431
|
+
throw new RegistryError(503, "REGISTRY_DATABASE_REQUIRED");
|
|
54432
|
+
serverErrorEvents = new HostedErrorEvents(new PgErrorEventStore(new PgAdapterAsync(url2, { timeoutMs: 5000 })));
|
|
54433
|
+
return serverErrorEvents;
|
|
54434
|
+
}
|
|
53815
54435
|
async function registryReady() {
|
|
53816
54436
|
try {
|
|
53817
54437
|
await configuredRegistry().ready();
|
|
@@ -53823,7 +54443,7 @@ async function registryReady() {
|
|
|
53823
54443
|
function json2(body, status = 200, headers = {}) {
|
|
53824
54444
|
return new Response(JSON.stringify(body), { status, headers: { "content-type": "application/json", "cache-control": "no-store", ...headers } });
|
|
53825
54445
|
}
|
|
53826
|
-
async function boundedJson2(request) {
|
|
54446
|
+
async function boundedJson2(request, max = REGISTRY_MAX_BYTES) {
|
|
53827
54447
|
if (!request.body)
|
|
53828
54448
|
throw new RegistryError(400, "REGISTRY_BODY_REQUIRED");
|
|
53829
54449
|
const reader = request.body.getReader(), chunks = [];
|
|
@@ -53833,7 +54453,7 @@ async function boundedJson2(request) {
|
|
|
53833
54453
|
if (next.done)
|
|
53834
54454
|
break;
|
|
53835
54455
|
length += next.value.byteLength;
|
|
53836
|
-
if (length >
|
|
54456
|
+
if (length > max) {
|
|
53837
54457
|
await reader.cancel();
|
|
53838
54458
|
throw new RegistryError(413, "REGISTRY_BODY_TOO_LARGE");
|
|
53839
54459
|
}
|
|
@@ -53845,10 +54465,11 @@ async function boundedJson2(request) {
|
|
|
53845
54465
|
throw new RegistryError(400, "REGISTRY_JSON_INVALID");
|
|
53846
54466
|
}
|
|
53847
54467
|
}
|
|
53848
|
-
async function handleRegistryRequest(request, key2, registry2) {
|
|
54468
|
+
async function handleRegistryRequest(request, key2, registry2, errorEvents) {
|
|
53849
54469
|
try {
|
|
54470
|
+
let keyId = "local";
|
|
53850
54471
|
if (hasRegistrySigningConfiguration())
|
|
53851
|
-
await authenticateRegistryRequest(request);
|
|
54472
|
+
keyId = await authenticateRegistryRequest(request);
|
|
53852
54473
|
else {
|
|
53853
54474
|
if (!isHooksLocalOptIn())
|
|
53854
54475
|
throw new RegistryError(503, "REGISTRY_SIGNING_CONFIGURATION_REQUIRED");
|
|
@@ -53860,6 +54481,12 @@ async function handleRegistryRequest(request, key2, registry2) {
|
|
|
53860
54481
|
throw new RegistryError(401, "REGISTRY_UNAUTHORIZED");
|
|
53861
54482
|
}
|
|
53862
54483
|
const url2 = new URL(request.url), path = url2.pathname.replace(/^\/api\/v1(?=\/|$)/, "/v1");
|
|
54484
|
+
if (path === "/v1/events/errors" && request.method === "POST") {
|
|
54485
|
+
await (errorEvents ?? configuredErrorEvents()).record(await boundedJson2(request, ERROR_EVENT_MAX_BYTES), keyId);
|
|
54486
|
+
return new Response(null, { status: 202, headers: { "cache-control": "no-store" } });
|
|
54487
|
+
}
|
|
54488
|
+
if (path === "/v1/events/errors/summary" && request.method === "GET")
|
|
54489
|
+
return json2(await (errorEvents ?? configuredErrorEvents()).summary(url2.searchParams.get("since")));
|
|
53863
54490
|
const owner2 = registry2 ?? configuredRegistry();
|
|
53864
54491
|
if (path === "/v1/catalog" && request.method === "GET")
|
|
53865
54492
|
return json2(await owner2.catalog());
|
|
@@ -53883,7 +54510,7 @@ async function handleRegistryRequest(request, key2, registry2) {
|
|
|
53883
54510
|
return json2({ error: "REGISTRY_ROUTE_NOT_FOUND" }, 404);
|
|
53884
54511
|
} catch (error61) {
|
|
53885
54512
|
if (error61 instanceof RegistryError)
|
|
53886
|
-
return json2({ error: error61.code }, error61.status);
|
|
54513
|
+
return json2({ error: error61.code }, error61.status, error61.status === 429 ? { "retry-after": "60" } : {});
|
|
53887
54514
|
if (error61 instanceof URIError)
|
|
53888
54515
|
return json2({ error: "REGISTRY_PATH_INVALID" }, 400);
|
|
53889
54516
|
return json2({ error: "REGISTRY_STORAGE_UNAVAILABLE" }, 503);
|
|
@@ -53897,7 +54524,7 @@ var SERVE_HOST = "127.0.0.1";
|
|
|
53897
54524
|
var SERVE_SERVICE_NAME = "hooks-registry";
|
|
53898
54525
|
function packageVersion() {
|
|
53899
54526
|
try {
|
|
53900
|
-
const pkgPath =
|
|
54527
|
+
const pkgPath = join43(dirname33(fileURLToPath6(import.meta.url)), "..", "package.json");
|
|
53901
54528
|
return JSON.parse(readFileSync25(pkgPath, "utf-8")).version || "0.0.0";
|
|
53902
54529
|
} catch {
|
|
53903
54530
|
return "0.0.0";
|
|
@@ -54157,17 +54784,18 @@ async function provisionCloudflareResources(options) {
|
|
|
54157
54784
|
return result;
|
|
54158
54785
|
}
|
|
54159
54786
|
// src/lib/codex-safety-trust.ts
|
|
54160
|
-
import { createHash as
|
|
54161
|
-
import { constants as constants23, closeSync as
|
|
54162
|
-
import { dirname as dirname36, isAbsolute as isAbsolute20, join as
|
|
54787
|
+
import { createHash as createHash36, randomUUID as randomUUID8 } from "crypto";
|
|
54788
|
+
import { constants as constants23, closeSync as closeSync21, fsyncSync as fsyncSync8, fstatSync as fstatSync11, lstatSync as lstatSync35, mkdirSync as mkdirSync17, openSync as openSync21, readFileSync as readFileSync30, realpathSync as realpathSync18, writeFileSync as writeFileSync14 } from "fs";
|
|
54789
|
+
import { dirname as dirname36, isAbsolute as isAbsolute20, join as join46, relative as relative7 } from "path";
|
|
54163
54790
|
import { homedir as homedir10 } from "os";
|
|
54164
54791
|
|
|
54165
54792
|
// src/lib/codex-safety-check.ts
|
|
54166
54793
|
import { spawn as spawn2, execFile as execFile2 } from "child_process";
|
|
54167
|
-
import { createHash as
|
|
54168
|
-
import { constants as constants10, openSync as
|
|
54794
|
+
import { createHash as createHash34 } from "crypto";
|
|
54795
|
+
import { constants as constants10, openSync as openSync11, closeSync as closeSync11, fstatSync as fstatSync9, lstatSync as lstatSync31, readFileSync as readFileSync28, realpathSync as realpathSync17 } from "fs";
|
|
54169
54796
|
import { dirname as dirname35, isAbsolute as isAbsolute17, resolve as resolve35 } from "path";
|
|
54170
54797
|
import { promisify } from "util";
|
|
54798
|
+
init_registry();
|
|
54171
54799
|
|
|
54172
54800
|
// src/lib/native-child-env.ts
|
|
54173
54801
|
var INHERITED = new Set([
|
|
@@ -54213,9 +54841,9 @@ function nativeChildEnv(source, explicit = {}, inherit = () => false) {
|
|
|
54213
54841
|
|
|
54214
54842
|
// src/native-safety.ts
|
|
54215
54843
|
import { execFile } from "child_process";
|
|
54216
|
-
import { closeSync as
|
|
54844
|
+
import { closeSync as closeSync9, constants as constants6, existsSync as existsSync18, fstatSync as fstatSync6, fsyncSync as fsyncSync2, linkSync, lstatSync as lstatSync21, mkdirSync as mkdirSync16, openSync as openSync9, readFileSync as readFileSync26, realpathSync as realpathSync15, renameSync as renameSync8, unlinkSync as unlinkSync9, writeFileSync as writeFileSync13 } from "fs";
|
|
54217
54845
|
import { homedir as homedir9 } from "os";
|
|
54218
|
-
import { dirname as dirname34, isAbsolute as isAbsolute12, join as
|
|
54846
|
+
import { dirname as dirname34, isAbsolute as isAbsolute12, join as join45, resolve as resolve33 } from "path";
|
|
54219
54847
|
class NativeSafetyError extends Error {
|
|
54220
54848
|
code;
|
|
54221
54849
|
reason;
|
|
@@ -54243,8 +54871,8 @@ function canonicalHome(home) {
|
|
|
54243
54871
|
safeDirectory(home);
|
|
54244
54872
|
return resolve33(home);
|
|
54245
54873
|
}
|
|
54246
|
-
function parseRecord(
|
|
54247
|
-
const record6 = JSON.parse(
|
|
54874
|
+
function parseRecord(text4, home) {
|
|
54875
|
+
const record6 = JSON.parse(text4);
|
|
54248
54876
|
if (!record6 || Array.isArray(record6) || Object.keys(record6).sort().join() !== "command,harness,schema" || record6.schema !== "hasna.hooks.native-safety.v1" || record6.harness !== "sumi" || typeof record6.command !== "string")
|
|
54249
54877
|
throw new NativeSafetyError("binding_invalid");
|
|
54250
54878
|
const binding = nativeSafetyCommandBinding(record6.command);
|
|
@@ -54300,10 +54928,10 @@ async function verifyNativeSafetyCommand(command, home = homedir9(), guard = "tr
|
|
|
54300
54928
|
cwd: home,
|
|
54301
54929
|
tool_input: { command: "rm -rf -- '" + path.replaceAll("'", "'\\''") + "'" }
|
|
54302
54930
|
});
|
|
54303
|
-
const refused2 = await evaluateRecord(removal(
|
|
54931
|
+
const refused2 = await evaluateRecord(removal(join45(home, ".ssh")), record8);
|
|
54304
54932
|
if (refused2.decision !== "deny" || !refused2.reason.startsWith("[protected-delete-guard] "))
|
|
54305
54933
|
throw new NativeSafetyError("guard_failed", refused2.decision === "deny" ? refused2.reason.slice(0, 512) : undefined);
|
|
54306
|
-
const ordinary = await evaluateRecord(removal(
|
|
54934
|
+
const ordinary = await evaluateRecord(removal(join45(home, ".hasna-protected-delete-verification-only")), record8);
|
|
54307
54935
|
if (ordinary.decision !== "continue")
|
|
54308
54936
|
throw new NativeSafetyError("guard_failed", ordinary.decision === "deny" ? ordinary.reason.slice(0, 512) : undefined);
|
|
54309
54937
|
return;
|
|
@@ -54312,7 +54940,7 @@ async function verifyNativeSafetyCommand(command, home = homedir9(), guard = "tr
|
|
|
54312
54940
|
const binding = nativeSafetyCommandBinding(command);
|
|
54313
54941
|
if (binding?.name !== guard || binding.home !== home)
|
|
54314
54942
|
throw new NativeSafetyError("binding_invalid");
|
|
54315
|
-
const root =
|
|
54943
|
+
const root = join45(home, ".hasna", "repos", "clones"), probe2 = join45(root, ".hasna-workspace-repos-verification-only");
|
|
54316
54944
|
const verdict2 = await evaluateRecord({
|
|
54317
54945
|
hook_event_name: "PreToolUse",
|
|
54318
54946
|
tool_name: "Bash",
|
|
@@ -54346,7 +54974,7 @@ function need11(condition, code2) {
|
|
|
54346
54974
|
if (!condition)
|
|
54347
54975
|
throw new CodexSafetyError(code2);
|
|
54348
54976
|
}
|
|
54349
|
-
var digest4 = (bytes) =>
|
|
54977
|
+
var digest4 = (bytes) => createHash34("sha256").update(bytes).digest("hex");
|
|
54350
54978
|
function nativeHeader(bytes) {
|
|
54351
54979
|
if (bytes.length < 64 || !["arm64", "x64"].includes(process.arch))
|
|
54352
54980
|
return false;
|
|
@@ -54371,7 +54999,7 @@ function executable2(command) {
|
|
|
54371
54999
|
if (parent === dirname35(parent))
|
|
54372
55000
|
break;
|
|
54373
55001
|
}
|
|
54374
|
-
const fd =
|
|
55002
|
+
const fd = openSync11(path, constants10.O_RDONLY | constants10.O_NOFOLLOW | constants10.O_NONBLOCK);
|
|
54375
55003
|
try {
|
|
54376
55004
|
const stat2 = fstatSync9(fd);
|
|
54377
55005
|
need11(stat2.isFile() && [0, process.getuid?.()].includes(stat2.uid) && !(stat2.mode & 18) && !!(stat2.mode & 64) && stat2.size <= CODEX_EXECUTABLE_MAX_BYTES, "native_unsafe_executable");
|
|
@@ -54380,7 +55008,7 @@ function executable2(command) {
|
|
|
54380
55008
|
need11(nativeHeader(bytes), "native_executable_required");
|
|
54381
55009
|
return { path, sha256: digest4(bytes) };
|
|
54382
55010
|
} finally {
|
|
54383
|
-
|
|
55011
|
+
closeSync11(fd);
|
|
54384
55012
|
}
|
|
54385
55013
|
} catch (error61) {
|
|
54386
55014
|
if (error61 instanceof CodexSafetyError)
|
|
@@ -54596,7 +55224,7 @@ function need13(value, code2 = "native_changed") {
|
|
|
54596
55224
|
if (!value)
|
|
54597
55225
|
throw new CodexTrustError(code2);
|
|
54598
55226
|
}
|
|
54599
|
-
var sha7 = (value) =>
|
|
55227
|
+
var sha7 = (value) => createHash36("sha256").update(value).digest("hex");
|
|
54600
55228
|
function canonical9(value) {
|
|
54601
55229
|
if (Array.isArray(value))
|
|
54602
55230
|
return "[" + value.map(canonical9).join(",") + "]";
|
|
@@ -54639,7 +55267,7 @@ function safeDirectory2(path) {
|
|
|
54639
55267
|
}
|
|
54640
55268
|
function readPrivate(path) {
|
|
54641
55269
|
safeDirectory2(dirname36(path));
|
|
54642
|
-
const fd =
|
|
55270
|
+
const fd = openSync21(path, constants23.O_RDONLY | constants23.O_NOFOLLOW | constants23.O_NONBLOCK);
|
|
54643
55271
|
try {
|
|
54644
55272
|
const s = fstatSync11(fd);
|
|
54645
55273
|
need13(s.isFile() && s.uid === process.getuid?.() && !(s.mode & 63) && s.size <= 4194304, "preimage_unsafe");
|
|
@@ -54647,24 +55275,24 @@ function readPrivate(path) {
|
|
|
54647
55275
|
need13(bytes.length <= 4194304, "preimage_unsafe");
|
|
54648
55276
|
return bytes;
|
|
54649
55277
|
} finally {
|
|
54650
|
-
|
|
55278
|
+
closeSync21(fd);
|
|
54651
55279
|
}
|
|
54652
55280
|
}
|
|
54653
55281
|
function syncDirectory(path) {
|
|
54654
|
-
const fd =
|
|
55282
|
+
const fd = openSync21(path, constants23.O_RDONLY | constants23.O_DIRECTORY | constants23.O_NOFOLLOW);
|
|
54655
55283
|
try {
|
|
54656
|
-
|
|
55284
|
+
fsyncSync8(fd);
|
|
54657
55285
|
} finally {
|
|
54658
|
-
|
|
55286
|
+
closeSync21(fd);
|
|
54659
55287
|
}
|
|
54660
55288
|
}
|
|
54661
55289
|
function exclusive(path, bytes) {
|
|
54662
|
-
const fd =
|
|
55290
|
+
const fd = openSync21(path, constants23.O_CREAT | constants23.O_EXCL | constants23.O_WRONLY | constants23.O_NOFOLLOW, 384);
|
|
54663
55291
|
try {
|
|
54664
55292
|
writeFileSync14(fd, bytes);
|
|
54665
|
-
|
|
55293
|
+
fsyncSync8(fd);
|
|
54666
55294
|
} finally {
|
|
54667
|
-
|
|
55295
|
+
closeSync21(fd);
|
|
54668
55296
|
}
|
|
54669
55297
|
syncDirectory(dirname36(path));
|
|
54670
55298
|
}
|
|
@@ -54677,7 +55305,7 @@ async function inspect(rpc, home, cwd, readiness = false, selected = "trash-guar
|
|
|
54677
55305
|
need13(userLayers.length === 1, "native_config_invalid");
|
|
54678
55306
|
const layer = userLayers[0], path = layer.name.file;
|
|
54679
55307
|
need13(typeof path === "string" && isAbsolute20(path) && typeof layer.version === "string" && /^sha256:[a-f0-9]{64}$/.test(layer.version), "native_config_invalid");
|
|
54680
|
-
const canonicalPath2 = realpathSync18(path), inside =
|
|
55308
|
+
const canonicalPath2 = realpathSync18(path), inside = relative7(home, canonicalPath2);
|
|
54681
55309
|
need13(inside !== "" && !inside.startsWith("..") && !isAbsolute20(inside), "native_config_invalid");
|
|
54682
55310
|
const definition = discovery.data[0].hooks.find((h) => h.key === guard.key);
|
|
54683
55311
|
need13(definition.source === "user", "native_config_invalid");
|
|
@@ -54750,9 +55378,9 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
54750
55378
|
operationId = randomUUID8();
|
|
54751
55379
|
let directory3 = home;
|
|
54752
55380
|
for (const part of [".hasna", "hooks", "native", selected.readiness ? "codex-readiness-trust" : (selected.guard ?? "trash-guard") === "trash-guard" ? "codex-trash-trust" : "codex-" + selected.guard + "-trust", operationId]) {
|
|
54753
|
-
directory3 =
|
|
55381
|
+
directory3 = join46(directory3, part);
|
|
54754
55382
|
try {
|
|
54755
|
-
|
|
55383
|
+
mkdirSync17(directory3, { mode: 448 });
|
|
54756
55384
|
syncDirectory(dirname36(directory3));
|
|
54757
55385
|
} catch (error61) {
|
|
54758
55386
|
if (error61.code !== "EEXIST")
|
|
@@ -54760,8 +55388,8 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
54760
55388
|
}
|
|
54761
55389
|
safeDirectory2(directory3);
|
|
54762
55390
|
}
|
|
54763
|
-
exclusive(
|
|
54764
|
-
exclusive(
|
|
55391
|
+
exclusive(join46(directory3, "config.before"), before.before);
|
|
55392
|
+
exclusive(join46(directory3, "intent.json"), JSON.stringify({ operationId, plan: before.plan, configSHA256: sha7(before.before) }) + `
|
|
54765
55393
|
`);
|
|
54766
55394
|
journal = directory3;
|
|
54767
55395
|
need13(sha7(readPrivate(before.canonicalPath)) === sha7(before.before));
|
|
@@ -54789,7 +55417,7 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
54789
55417
|
nativeAdoptionVerified: false,
|
|
54790
55418
|
unrelatedConfigurationPreserved: true
|
|
54791
55419
|
};
|
|
54792
|
-
exclusive(
|
|
55420
|
+
exclusive(join46(directory3, "receipt.json"), JSON.stringify(receipt) + `
|
|
54793
55421
|
`);
|
|
54794
55422
|
return receipt;
|
|
54795
55423
|
} catch (error61) {
|
|
@@ -54802,7 +55430,7 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
54802
55430
|
if (!journal)
|
|
54803
55431
|
throw new CodexTrustError("trust_refused", undefined, refusal3);
|
|
54804
55432
|
try {
|
|
54805
|
-
exclusive(
|
|
55433
|
+
exclusive(join46(journal, "refused.json"), JSON.stringify({ ok: false, outcome: "refused", operationId, planDigest: selected.expectedPlanDigest, refusal: refusal3 }) + `
|
|
54806
55434
|
`);
|
|
54807
55435
|
} catch {
|
|
54808
55436
|
throw new CodexTrustError("trust_outcome_uncertain", operationId);
|
|
@@ -54815,10 +55443,12 @@ async function applyTrust(options, dependencies = {}) {
|
|
|
54815
55443
|
var planCodexSafetyTrust = (options = {}, dependencies = {}) => planTrust({ ...options, readiness: false }, dependencies);
|
|
54816
55444
|
var applyCodexSafetyTrust = (options, dependencies = {}) => applyTrust({ ...options, readiness: false }, dependencies);
|
|
54817
55445
|
// src/lib/claude-safety-check.ts
|
|
54818
|
-
import { constants as constants25, closeSync as
|
|
54819
|
-
import { createHash as
|
|
54820
|
-
import { dirname as dirname37, isAbsolute as isAbsolute31, join as
|
|
55446
|
+
import { constants as constants25, closeSync as closeSync24, fstatSync as fstatSync21, lstatSync as lstatSync37, openSync as openSync24, readFileSync as readFileSync31, realpathSync as realpathSync19 } from "fs";
|
|
55447
|
+
import { createHash as createHash38 } from "crypto";
|
|
55448
|
+
import { dirname as dirname37, isAbsolute as isAbsolute31, join as join47, resolve as resolve36 } from "path";
|
|
54821
55449
|
import { homedir as homedir11 } from "os";
|
|
55450
|
+
init_registry();
|
|
55451
|
+
|
|
54822
55452
|
class ClaudeSafetyError extends Error {
|
|
54823
55453
|
code;
|
|
54824
55454
|
constructor(code2) {
|
|
@@ -54831,7 +55461,7 @@ function need14(value, code2) {
|
|
|
54831
55461
|
if (!value)
|
|
54832
55462
|
throw new ClaudeSafetyError(code2);
|
|
54833
55463
|
}
|
|
54834
|
-
var sha9 = (value) =>
|
|
55464
|
+
var sha9 = (value) => createHash38("sha256").update(value).digest("hex");
|
|
54835
55465
|
function read3(path) {
|
|
54836
55466
|
try {
|
|
54837
55467
|
const resolved = realpathSync19(path);
|
|
@@ -54841,7 +55471,7 @@ function read3(path) {
|
|
|
54841
55471
|
if (dirname37(parent) === parent)
|
|
54842
55472
|
break;
|
|
54843
55473
|
}
|
|
54844
|
-
const fd =
|
|
55474
|
+
const fd = openSync24(resolved, constants25.O_RDONLY | constants25.O_NOFOLLOW | constants25.O_NONBLOCK);
|
|
54845
55475
|
try {
|
|
54846
55476
|
const s = fstatSync21(fd);
|
|
54847
55477
|
need14(s.isFile() && [0, process.getuid?.()].includes(s.uid) && !(s.mode & 18) && s.size <= 1048576, "settings_unsafe");
|
|
@@ -54849,7 +55479,7 @@ function read3(path) {
|
|
|
54849
55479
|
need14(Buffer.byteLength(raw) <= 1048576, "settings_unsafe");
|
|
54850
55480
|
return { path, resolved, sha256: sha9(raw), raw };
|
|
54851
55481
|
} finally {
|
|
54852
|
-
|
|
55482
|
+
closeSync24(fd);
|
|
54853
55483
|
}
|
|
54854
55484
|
} catch (error61) {
|
|
54855
55485
|
if (error61.code === "ENOENT")
|
|
@@ -54862,9 +55492,9 @@ function read3(path) {
|
|
|
54862
55492
|
async function verifyClaudeSafetyConfiguration(options = {}, dependencies = {}) {
|
|
54863
55493
|
const home = realpathSync19(options.home ?? homedir11()), cwd = realpathSync19(options.cwd ?? process.cwd());
|
|
54864
55494
|
const paths = [
|
|
54865
|
-
options.userSettingsPath ??
|
|
54866
|
-
|
|
54867
|
-
options.localSettingsPath ??
|
|
55495
|
+
options.userSettingsPath ?? join47(home, ".claude/settings.json"),
|
|
55496
|
+
join47(cwd, ".claude/settings.json"),
|
|
55497
|
+
options.localSettingsPath ?? join47(cwd, ".claude/settings.local.json")
|
|
54868
55498
|
];
|
|
54869
55499
|
need14(paths.every((path) => isAbsolute31(path) && resolve36(path) === path), "settings_unsafe");
|
|
54870
55500
|
const inspect2 = () => [...new Set(paths)].map(read3);
|
|
@@ -54917,7 +55547,7 @@ async function verifyClaudeSafetyConfiguration(options = {}, dependencies = {})
|
|
|
54917
55547
|
cwd,
|
|
54918
55548
|
configurationVerified: true,
|
|
54919
55549
|
guardVerified: true,
|
|
54920
|
-
sources: before.map(({ path, sha256 }) => ({ path, sha256 })),
|
|
55550
|
+
sources: before.map(({ path, sha256: sha2563 }) => ({ path, sha256: sha2563 })),
|
|
54921
55551
|
guardSHA256: sha9(guards[0].command),
|
|
54922
55552
|
runtimePolicyVerified: false,
|
|
54923
55553
|
nativeDiscoveryVerified: false,
|
|
@@ -54925,9 +55555,9 @@ async function verifyClaudeSafetyConfiguration(options = {}, dependencies = {})
|
|
|
54925
55555
|
};
|
|
54926
55556
|
}
|
|
54927
55557
|
// src/lib/native-safety-registration.ts
|
|
54928
|
-
import { createHash as
|
|
54929
|
-
import { constants as constants26, closeSync as
|
|
54930
|
-
import { basename as basename20, dirname as dirname38, isAbsolute as isAbsolute34, join as
|
|
55558
|
+
import { createHash as createHash40, randomUUID as randomUUID9 } from "crypto";
|
|
55559
|
+
import { constants as constants26, closeSync as closeSync26, fstatSync as fstatSync24, fsyncSync as fsyncSync10, lstatSync as lstatSync38, mkdirSync as mkdirSync18, openSync as openSync26, readFileSync as readFileSync32, realpathSync as realpathSync20, writeFileSync as writeFileSync15 } from "fs";
|
|
55560
|
+
import { basename as basename20, dirname as dirname38, isAbsolute as isAbsolute34, join as join48, relative as relative11, resolve as resolve37 } from "path";
|
|
54931
55561
|
import { homedir as homedir12 } from "os";
|
|
54932
55562
|
class NativeRegistrationError extends Error {
|
|
54933
55563
|
code;
|
|
@@ -54945,7 +55575,7 @@ var need15 = (value, code2) => {
|
|
|
54945
55575
|
if (!value)
|
|
54946
55576
|
throw new NativeRegistrationError(code2);
|
|
54947
55577
|
};
|
|
54948
|
-
var sha10 = (value) =>
|
|
55578
|
+
var sha10 = (value) => createHash40("sha256").update(value).digest("hex");
|
|
54949
55579
|
function canonical11(value) {
|
|
54950
55580
|
if (Array.isArray(value))
|
|
54951
55581
|
return "[" + value.map(canonical11).join(",") + "]";
|
|
@@ -54979,7 +55609,7 @@ function read5(path) {
|
|
|
54979
55609
|
const suffix = [basename20(path)];
|
|
54980
55610
|
for (;; ) {
|
|
54981
55611
|
try {
|
|
54982
|
-
resolved =
|
|
55612
|
+
resolved = join48(realpathSync20(ancestor), ...suffix);
|
|
54983
55613
|
break;
|
|
54984
55614
|
} catch (missing2) {
|
|
54985
55615
|
if (missing2.code !== "ENOENT" || dirname38(ancestor) === ancestor || suffix.length >= 64)
|
|
@@ -55001,7 +55631,7 @@ function read5(path) {
|
|
|
55001
55631
|
safeDirectory3(dirname38(resolved));
|
|
55002
55632
|
let fd;
|
|
55003
55633
|
try {
|
|
55004
|
-
fd =
|
|
55634
|
+
fd = openSync26(resolved, constants26.O_RDONLY | constants26.O_NOFOLLOW | constants26.O_NONBLOCK);
|
|
55005
55635
|
} catch (error61) {
|
|
55006
55636
|
if (error61.code === "ENOENT")
|
|
55007
55637
|
return { resolved, raw: null, sha256: "absent" };
|
|
@@ -55016,14 +55646,14 @@ function read5(path) {
|
|
|
55016
55646
|
need15(Buffer.from(raw).equals(bytes), "settings_invalid");
|
|
55017
55647
|
return { resolved, raw, sha256: sha10(bytes) };
|
|
55018
55648
|
} finally {
|
|
55019
|
-
|
|
55649
|
+
closeSync26(fd);
|
|
55020
55650
|
}
|
|
55021
55651
|
}
|
|
55022
55652
|
function assertLosslessJson(raw) {
|
|
55023
55653
|
const tokens = /"(?:\\[\s\S]|[^"\\])*"|-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?|true|false|null|[{}\[\],:]/g;
|
|
55024
55654
|
const stack = [];
|
|
55025
|
-
function decimal(
|
|
55026
|
-
const match = /^(-?)([0-9]+)(?:\.([0-9]+))?(?:[eE]([+-]?[0-9]+))?$/.exec(
|
|
55655
|
+
function decimal(text4) {
|
|
55656
|
+
const match = /^(-?)([0-9]+)(?:\.([0-9]+))?(?:[eE]([+-]?[0-9]+))?$/.exec(text4);
|
|
55027
55657
|
need15((match[4]?.replace(/^[+-]/, "").length ?? 0) <= 6, "settings_invalid");
|
|
55028
55658
|
let digits = (match[2] + (match[3] ?? "")).replace(/^0+/, "");
|
|
55029
55659
|
if (!digits)
|
|
@@ -55094,7 +55724,7 @@ function inspect2(options) {
|
|
|
55094
55724
|
const selectedNative = read5(resolve37(nativeHome, options.target === "codex" ? "hooks.json" : "settings.json"));
|
|
55095
55725
|
need15(read5(path).resolved === selectedNative.resolved, "input_invalid");
|
|
55096
55726
|
}
|
|
55097
|
-
const before = read5(path), inside =
|
|
55727
|
+
const before = read5(path), inside = relative11(home, before.resolved);
|
|
55098
55728
|
need15(inside !== "" && !inside.startsWith("..") && !isAbsolute34(inside), "settings_unsafe");
|
|
55099
55729
|
const parsed = validateSettings(before.raw);
|
|
55100
55730
|
let preview2;
|
|
@@ -55125,20 +55755,20 @@ function inspect2(options) {
|
|
|
55125
55755
|
return { home, before, preview: preview2, plan };
|
|
55126
55756
|
}
|
|
55127
55757
|
function syncDirectory2(path) {
|
|
55128
|
-
const fd =
|
|
55758
|
+
const fd = openSync26(path, constants26.O_RDONLY | constants26.O_DIRECTORY | constants26.O_NOFOLLOW);
|
|
55129
55759
|
try {
|
|
55130
|
-
|
|
55760
|
+
fsyncSync10(fd);
|
|
55131
55761
|
} finally {
|
|
55132
|
-
|
|
55762
|
+
closeSync26(fd);
|
|
55133
55763
|
}
|
|
55134
55764
|
}
|
|
55135
55765
|
function exclusive2(path, bytes) {
|
|
55136
|
-
const fd =
|
|
55766
|
+
const fd = openSync26(path, constants26.O_CREAT | constants26.O_EXCL | constants26.O_WRONLY | constants26.O_NOFOLLOW, 384);
|
|
55137
55767
|
try {
|
|
55138
55768
|
writeFileSync15(fd, bytes);
|
|
55139
|
-
|
|
55769
|
+
fsyncSync10(fd);
|
|
55140
55770
|
} finally {
|
|
55141
|
-
|
|
55771
|
+
closeSync26(fd);
|
|
55142
55772
|
}
|
|
55143
55773
|
syncDirectory2(dirname38(path));
|
|
55144
55774
|
}
|
|
@@ -55148,7 +55778,7 @@ function refusalOf(error61) {
|
|
|
55148
55778
|
}
|
|
55149
55779
|
function refuseApply(directory3, operationId, planDigest, refusal3) {
|
|
55150
55780
|
try {
|
|
55151
|
-
exclusive2(
|
|
55781
|
+
exclusive2(join48(directory3, "refused.json"), JSON.stringify({ ok: false, outcome: "refused", operationId, planDigest, refusal: refusal3 }) + `
|
|
55152
55782
|
`);
|
|
55153
55783
|
} catch {
|
|
55154
55784
|
throw new NativeRegistrationError("apply_outcome_uncertain", operationId);
|
|
@@ -55192,9 +55822,9 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
55192
55822
|
const operationId = randomUUID9();
|
|
55193
55823
|
let directory3 = before.home;
|
|
55194
55824
|
for (const part of [".hasna", "hooks", "native", selected.readiness ? "trash-readiness-registration" : selected.guard === "trash-guard" ? "trash-registration" : selected.guard + "-registration", operationId]) {
|
|
55195
|
-
directory3 =
|
|
55825
|
+
directory3 = join48(directory3, part);
|
|
55196
55826
|
try {
|
|
55197
|
-
|
|
55827
|
+
mkdirSync18(directory3, { mode: 448 });
|
|
55198
55828
|
syncDirectory2(dirname38(directory3));
|
|
55199
55829
|
} catch (error61) {
|
|
55200
55830
|
if (error61.code !== "EEXIST")
|
|
@@ -55203,8 +55833,8 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
55203
55833
|
safeDirectory3(directory3);
|
|
55204
55834
|
}
|
|
55205
55835
|
if (before.before.raw !== null)
|
|
55206
|
-
exclusive2(
|
|
55207
|
-
exclusive2(
|
|
55836
|
+
exclusive2(join48(directory3, "settings.before"), before.before.raw);
|
|
55837
|
+
exclusive2(join48(directory3, "intent.json"), JSON.stringify({ operationId, plan }) + `
|
|
55208
55838
|
`);
|
|
55209
55839
|
let writeMayHaveStarted = false;
|
|
55210
55840
|
const beforeWrite = () => {
|
|
@@ -55233,7 +55863,7 @@ async function applyRegistration(options, dependencies = {}) {
|
|
|
55233
55863
|
...selected.readiness ? { readinessRunnerVerified: true } : {},
|
|
55234
55864
|
nativeAdoptionVerified: false
|
|
55235
55865
|
};
|
|
55236
|
-
exclusive2(
|
|
55866
|
+
exclusive2(join48(directory3, "receipt.json"), JSON.stringify(receipt) + `
|
|
55237
55867
|
`);
|
|
55238
55868
|
return receipt;
|
|
55239
55869
|
} catch (error61) {
|
|
@@ -55260,17 +55890,20 @@ function removeProjectHook(name) {
|
|
|
55260
55890
|
}
|
|
55261
55891
|
async function runHook(name, input2, options = {}) {
|
|
55262
55892
|
const { readCustomManifest: readCustomManifest2 } = await Promise.resolve().then(() => (init_manifest(), exports_manifest));
|
|
55263
|
-
const custom3 = readCustomManifest2(name);
|
|
55264
|
-
const resolvedMeta = custom3 ? undefined : getHook(name);
|
|
55265
|
-
if (!custom3 && !resolvedMeta)
|
|
55266
|
-
throw new Error(`Hook '${name}' not found`);
|
|
55267
|
-
const dispatchArgs = nativeTargetArgs(custom3?.manifest.nativeTargetDispatch ?? resolvedMeta?.nativeTargetDispatch, options.target, custom3?.manifest.args);
|
|
55268
|
-
const script = resolveScriptPath(name);
|
|
55269
|
-
if (!script)
|
|
55270
|
-
throw new Error(`Hook script not found: ${name}`);
|
|
55271
55893
|
const { sha256Of: sha256Of2, checkScriptHash: checkScriptHash2 } = await Promise.resolve().then(() => (init_store(), exports_store));
|
|
55272
|
-
const
|
|
55273
|
-
const check2 =
|
|
55894
|
+
const { withStableInstall: withStableInstall2 } = await Promise.resolve().then(() => (init_install_record(), exports_install_record));
|
|
55895
|
+
const { custom: custom3, content, dispatchArgs, script, check: check2 } = withStableInstall2(name, () => {
|
|
55896
|
+
const custom4 = readCustomManifest2(name);
|
|
55897
|
+
const resolvedMeta = custom4 ? undefined : getHook(name);
|
|
55898
|
+
if (!custom4 && !resolvedMeta)
|
|
55899
|
+
throw new Error(`Hook '${name}' not found`);
|
|
55900
|
+
const dispatchArgs2 = nativeTargetArgs(custom4?.manifest.nativeTargetDispatch ?? resolvedMeta?.nativeTargetDispatch, options.target, custom4?.manifest.args);
|
|
55901
|
+
const script2 = resolveScriptPath(name);
|
|
55902
|
+
if (!script2)
|
|
55903
|
+
throw new Error(`Hook script not found: ${name}`);
|
|
55904
|
+
const content2 = readFileSync33(script2);
|
|
55905
|
+
return { custom: custom4, content: content2, dispatchArgs: dispatchArgs2, script: script2, check: checkScriptHash2(name, sha256Of2(content2)) };
|
|
55906
|
+
});
|
|
55274
55907
|
if (!check2.ok) {
|
|
55275
55908
|
throw new Error(`Hook '${name}' script changed since it was trusted (sha256 ${check2.expected} != ${check2.actual}). Run 'hooks trust ${name}' to trust the new content.`);
|
|
55276
55909
|
}
|