oneie 3.6.4 → 3.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. package/.claude/commands/one copy.md +565 -0
  2. package/.claude/hooks/README-knowledge-hooks.md +265 -0
  3. package/.claude/hooks/__pycache__/knowledge-post.cpython-313.pyc +0 -0
  4. package/.claude/hooks/__pycache__/knowledge-pre.cpython-313.pyc +0 -0
  5. package/.claude/hooks/__pycache__/todo.cpython-313.pyc +0 -0
  6. package/.claude/hooks/check-filenames.py +40 -0
  7. package/.claude/hooks/clean-post.py +301 -0
  8. package/.claude/hooks/clean-pre.py +308 -0
  9. package/.claude/hooks/done.py +175 -0
  10. package/.claude/hooks/format-hook.sh +75 -0
  11. package/.claude/hooks/hook-logger.sh +59 -0
  12. package/.claude/hooks/knowledge-post.py +251 -0
  13. package/.claude/hooks/knowledge-pre.py +150 -0
  14. package/.claude/hooks/notification-hook.sh +112 -0
  15. package/.claude/hooks/security-hook.sh +157 -0
  16. package/.claude/hooks/tag-all-docs.py +338 -0
  17. package/.claude/hooks/todo.py +298 -0
  18. package/.claude/hooks/validate-ontology-structure.py +455 -0
  19. package/.claude/skills/astro/add-content-collection.md +30 -0
  20. package/.claude/skills/astro/check-build.md +29 -0
  21. package/.claude/skills/astro/create-component.md +29 -0
  22. package/.claude/skills/astro/create-page.md +30 -0
  23. package/.claude/skills/astro/optimize-performance.md +21 -0
  24. package/.claude/skills/convex/check-deployment.md +46 -0
  25. package/.claude/skills/convex/create-mutation.md +405 -0
  26. package/.claude/skills/convex/create-query.md +52 -0
  27. package/.claude/skills/convex/read-schema.md +373 -0
  28. package/.claude/skills/convex/test-function.md +50 -0
  29. package/.claude/skills/deployment/check-deployment-health.md +20 -0
  30. package/.claude/skills/deployment/create-release.md +21 -0
  31. package/.claude/skills/deployment/deploy-cloudflare.md +31 -0
  32. package/.claude/skills/deployment/deploy-convex.md +30 -0
  33. package/.claude/skills/deployment/sync-repositories.md +19 -0
  34. package/.claude/skills/design/check-accessibility.md +21 -0
  35. package/.claude/skills/design/create-component-spec.md +27 -0
  36. package/.claude/skills/design/generate-design-tokens.md +24 -0
  37. package/.claude/skills/design/generate-wireframe.md +30 -0
  38. package/.claude/skills/documentation/create-migration-guide.md +20 -0
  39. package/.claude/skills/documentation/generate-api-docs.md +27 -0
  40. package/.claude/skills/documentation/generate-readme.md +22 -0
  41. package/.claude/skills/documentation/update-knowledge.md +20 -0
  42. package/.claude/skills/integration/connect-external-system.md +21 -0
  43. package/.claude/skills/integration/implement-a2a.md +20 -0
  44. package/.claude/skills/integration/implement-acp.md +20 -0
  45. package/.claude/skills/integration/verify-integration.md +20 -0
  46. package/.claude/skills/ontology/README.md +255 -0
  47. package/.claude/skills/ontology/check-dimension.md +307 -0
  48. package/.claude/skills/ontology/generate-entity-type.md +339 -0
  49. package/.claude/skills/ontology/validate-schema.md +229 -0
  50. package/.claude/skills/ontology/verify-relationships.md +310 -0
  51. package/.claude/skills/problem-solving/analyze-test-failure.md +21 -0
  52. package/.claude/skills/problem-solving/identify-root-cause.md +20 -0
  53. package/.claude/skills/problem-solving/propose-solution.md +29 -0
  54. package/.claude/skills/problem-solving/verify-fix.md +21 -0
  55. package/.claude/skills/sales/generate-demo-script.md +21 -0
  56. package/.claude/skills/sales/qualify-lead.md +30 -0
  57. package/.claude/skills/sales/track-trial.md +20 -0
  58. package/.claude/skills/sales/verify-kyc.md +20 -0
  59. package/.claude/skills/testing/analyze-coverage.md +24 -0
  60. package/.claude/skills/testing/generate-tests.md +24 -0
  61. package/.claude/skills/testing/run-tests.md +27 -0
  62. package/.claude/skills/testing/validate-e2e.md +25 -0
  63. package/.mcp.json +30 -3
  64. package/dist/commands/init.d.ts.map +1 -1
  65. package/dist/commands/init.js +13 -6
  66. package/dist/commands/init.js.map +1 -1
  67. package/dist/utils/installation-setup.d.ts.map +1 -1
  68. package/dist/utils/installation-setup.js +9 -0
  69. package/dist/utils/installation-setup.js.map +1 -1
  70. package/dist/utils/launch-claude.d.ts +3 -2
  71. package/dist/utils/launch-claude.d.ts.map +1 -1
  72. package/dist/utils/launch-claude.js +64 -29
  73. package/dist/utils/launch-claude.js.map +1 -1
  74. package/one/.obsidian/workspace.json +22 -22
  75. package/one/events/CREATE-WEBSITE.md +442 -0
  76. package/one/events/CUSTOM-DOMAIN.md +357 -0
  77. package/one/events/DEPLOYMENT copy.md +426 -0
  78. package/one/events/ECOMMERCE-BEFORE-AFTER.md +251 -0
  79. package/one/events/ECOMMERCE-ENHANCEMENTS.md +576 -0
  80. package/one/events/ECOMMERCE-HIGH-CONVERTING-ELEMENTS.md +421 -0
  81. package/one/events/ECOMMERCE-REFACTOR-SUMMARY.md +196 -0
  82. package/one/events/ECOMMERCE-SETUP-SUMMARY.md +396 -0
  83. package/one/events/INSTALLATION_FOLDERS.md +516 -0
  84. package/one/events/INSTALLATION_FOLDERS_FILES.md +205 -0
  85. package/one/events/INSTALLATION_FOLDERS_SUMMARY.md +419 -0
  86. package/one/events/LICENSE.md +89 -0
  87. package/one/events/MCP-CONFIGURATION.md +336 -0
  88. package/one/events/MCP-SETUP-COMPLETE.md +205 -0
  89. package/one/events/NODE-UPGRADE.md +111 -0
  90. package/one/events/PACKAGE-STRUCTURE.md +310 -0
  91. package/one/events/PLAYBOOK-SETUP-SUMMARY.md +331 -0
  92. package/one/events/PROMPT_FIX_FRONTEND_ONLY.md +567 -0
  93. package/one/events/SIMPLE_FIX_FRONTEND_ONLY.md +262 -0
  94. package/one/events/STRIPE-INTEGRATION.md +414 -0
  95. package/one/events/STRIPE-SETUP-GUIDE.md +462 -0
  96. package/one/events/TRANSPARENCY-FIXES.md +275 -0
  97. package/package.json +4 -2
@@ -0,0 +1,251 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ ONE Platform - Knowledge Tagging Post-Hook
4
+ Tags created/modified artifacts as knowledge in the ontology.
5
+
6
+ This hook runs on PostToolUse to:
7
+ - Create knowledge entries for new artifacts
8
+ - Tag with appropriate labels (file type, dimension, feature)
9
+ - Link knowledge to related things (features, tasks, designs)
10
+ - Optionally generate embeddings for RAG search
11
+ """
12
+ import json
13
+ import sys
14
+ import os
15
+ import hashlib
16
+ from pathlib import Path
17
+ from datetime import datetime
18
+ from typing import Dict, Any, Optional, List
19
+
20
+ # Knowledge artifact types
21
+ KNOWLEDGE_ARTIFACT_TYPES = {
22
+ "code": ["py", "ts", "tsx", "js", "jsx", "astro", "json", "yaml", "yml"],
23
+ "documentation": ["md", "mdx", "txt"],
24
+ "design": ["fig", "sketch", "svg", "png", "jpg"],
25
+ "test": ["test.ts", "test.tsx", "spec.ts", "spec.tsx"],
26
+ "config": ["json", "yaml", "yml", "toml", "ini"],
27
+ }
28
+
29
+ # Knowledge labels based on file location/type
30
+ KNOWLEDGE_LABELS = {
31
+ "/web/src/components": ["component", "frontend", "ui"],
32
+ "/web/src/pages": ["page", "frontend", "routing"],
33
+ "/backend/convex/queries": ["query", "backend", "database"],
34
+ "/backend/convex/mutations": ["mutation", "backend", "database"],
35
+ "/backend/convex/services": ["service", "backend", "business-logic"],
36
+ "/one/things": ["documentation", "ontology", "things"],
37
+ "/one/connections": ["documentation", "ontology", "connections"],
38
+ "/one/events": ["documentation", "ontology", "events"],
39
+ "/one/knowledge": ["documentation", "ontology", "knowledge"],
40
+ "/test": ["test", "quality", "validation"],
41
+ }
42
+
43
+ def get_artifact_type(file_path: str) -> Optional[str]:
44
+ """Determine artifact type from file path"""
45
+ path = Path(file_path)
46
+ ext = path.suffix.lstrip(".")
47
+
48
+ # Check for test files first
49
+ if "test" in path.name or "spec" in path.name:
50
+ return "test"
51
+
52
+ # Check by extension
53
+ for artifact_type, extensions in KNOWLEDGE_ARTIFACT_TYPES.items():
54
+ if any(path.name.endswith(e) for e in extensions):
55
+ return artifact_type
56
+
57
+ return None
58
+
59
+ def get_knowledge_labels(file_path: str) -> List[str]:
60
+ """Generate knowledge labels based on file path"""
61
+ labels = []
62
+
63
+ # Add labels based on path patterns
64
+ for path_pattern, path_labels in KNOWLEDGE_LABELS.items():
65
+ if path_pattern in file_path:
66
+ labels.extend(path_labels)
67
+
68
+ # Add artifact type label
69
+ artifact_type = get_artifact_type(file_path)
70
+ if artifact_type:
71
+ labels.append(artifact_type)
72
+
73
+ # Add dimension label if in /one
74
+ if "/one/" in file_path:
75
+ parts = Path(file_path).parts
76
+ try:
77
+ one_index = parts.index("one")
78
+ if one_index + 1 < len(parts):
79
+ dimension = parts[one_index + 1]
80
+ labels.append(f"dimension-{dimension}")
81
+ except ValueError:
82
+ pass
83
+
84
+ return list(set(labels)) # Remove duplicates
85
+
86
+ def get_inference_context() -> Dict[str, Any]:
87
+ """Load current inference context from todo state"""
88
+ try:
89
+ todo_state_path = Path.home() / ".claude" / "todo-state.json"
90
+ if todo_state_path.exists():
91
+ with open(todo_state_path, 'r') as f:
92
+ state = json.load(f)
93
+ return {
94
+ "inference_number": state.get("current_inference", 0),
95
+ "feature": state.get("feature", "New Feature"),
96
+ "organization": state.get("organization", "Default Org"),
97
+ "person_role": state.get("person_role", "platform_owner"),
98
+ }
99
+ except Exception:
100
+ pass
101
+
102
+ return {
103
+ "inference_number": 0,
104
+ "feature": "New Feature",
105
+ "organization": "Default Org",
106
+ "person_role": "platform_owner",
107
+ }
108
+
109
+ def should_tag_as_knowledge(file_path: str, tool_name: str) -> bool:
110
+ """Determine if artifact should be tagged as knowledge"""
111
+ # Only tag Write and Edit operations
112
+ if tool_name not in ["Write", "Edit", "MultiEdit"]:
113
+ return False
114
+
115
+ # Don't tag temporary files
116
+ if "/tmp/" in file_path or "/.temp/" in file_path:
117
+ return False
118
+
119
+ # Don't tag generated files
120
+ if "/_generated/" in file_path or "/node_modules/" in file_path:
121
+ return False
122
+
123
+ # Only tag known artifact types
124
+ artifact_type = get_artifact_type(file_path)
125
+ if not artifact_type:
126
+ return False
127
+
128
+ return True
129
+
130
+ def generate_content_hash(file_path: str) -> str:
131
+ """Generate SHA256 hash of file content"""
132
+ try:
133
+ with open(file_path, 'rb') as f:
134
+ return hashlib.sha256(f.read()).hexdigest()[:16]
135
+ except Exception:
136
+ return ""
137
+
138
+ def create_knowledge_entry(file_path: str, content: Optional[str] = None) -> Dict[str, Any]:
139
+ """Create knowledge entry for artifact"""
140
+ path = Path(file_path)
141
+ artifact_type = get_artifact_type(file_path)
142
+ labels = get_knowledge_labels(file_path)
143
+ inference_ctx = get_inference_context()
144
+ content_hash = generate_content_hash(file_path)
145
+
146
+ # Build knowledge entry
147
+ entry = {
148
+ "type": "knowledge_item",
149
+ "artifact_type": artifact_type,
150
+ "file_path": str(path.absolute()),
151
+ "file_name": path.name,
152
+ "labels": labels,
153
+ "content_hash": content_hash,
154
+ "created_at": datetime.now().isoformat(),
155
+ "inference_number": inference_ctx["inference_number"],
156
+ "feature": inference_ctx["feature"],
157
+ "organization": inference_ctx["organization"],
158
+ "created_by_role": inference_ctx["person_role"],
159
+ "metadata": {
160
+ "file_size": path.stat().st_size if path.exists() else 0,
161
+ "directory": str(path.parent),
162
+ "extension": path.suffix,
163
+ }
164
+ }
165
+
166
+ # Add content preview if available
167
+ if content:
168
+ entry["content_preview"] = content[:500] if len(content) > 500 else content
169
+ elif path.exists():
170
+ try:
171
+ with open(path, 'r', encoding='utf-8') as f:
172
+ preview = f.read(500)
173
+ entry["content_preview"] = preview
174
+ except Exception:
175
+ pass
176
+
177
+ return entry
178
+
179
+ def save_knowledge_entry(entry: Dict[str, Any]) -> str:
180
+ """Save knowledge entry to knowledge log"""
181
+ # Create knowledge log directory
182
+ knowledge_log_dir = Path.home() / ".claude" / "knowledge-log"
183
+ knowledge_log_dir.mkdir(parents=True, exist_ok=True)
184
+
185
+ # Create daily log file
186
+ log_date = datetime.now().strftime("%Y-%m-%d")
187
+ log_file = knowledge_log_dir / f"knowledge-{log_date}.jsonl"
188
+
189
+ # Append entry
190
+ with open(log_file, 'a') as f:
191
+ f.write(json.dumps(entry) + "\n")
192
+
193
+ return str(log_file)
194
+
195
+ def main():
196
+ """Main hook execution"""
197
+ try:
198
+ # Read hook input from stdin
199
+ hook_input = json.load(sys.stdin)
200
+
201
+ hook_event = hook_input.get("hook_event_name")
202
+ tool_name = hook_input.get("tool_name")
203
+ tool_input = hook_input.get("tool_input", {})
204
+
205
+ # Only process PostToolUse for Write/Edit operations
206
+ if hook_event != "PostToolUse":
207
+ sys.exit(0)
208
+
209
+ file_path = tool_input.get("file_path")
210
+ if not file_path:
211
+ sys.exit(0)
212
+
213
+ # Check if should be tagged as knowledge
214
+ if not should_tag_as_knowledge(file_path, tool_name):
215
+ sys.exit(0)
216
+
217
+ # Create knowledge entry
218
+ content = tool_input.get("content") or tool_input.get("new_string")
219
+ entry = create_knowledge_entry(file_path, content)
220
+
221
+ # Save to knowledge log
222
+ log_file = save_knowledge_entry(entry)
223
+
224
+ # Output post-hook message
225
+ artifact_type = entry["artifact_type"]
226
+ labels = entry["labels"]
227
+ inference_num = entry["inference_number"]
228
+
229
+ msg = f"✨ Knowledge Tagged\n"
230
+ msg += f" Artifact: {entry['file_name']}\n"
231
+ msg += f" Type: {artifact_type}\n"
232
+ msg += f" Labels: {', '.join(labels[:5])}"
233
+ if len(labels) > 5:
234
+ msg += f" (+{len(labels) - 5} more)"
235
+ if inference_num > 0:
236
+ msg += f"\n Inference: {inference_num}/100"
237
+ msg += f"\n Hash: {entry['content_hash']}"
238
+ msg += f"\n → Logged to: {Path(log_file).name}"
239
+
240
+ print(msg)
241
+ sys.exit(0)
242
+
243
+ except json.JSONDecodeError as e:
244
+ print(f"Error: Invalid JSON input: {e}", file=sys.stderr)
245
+ sys.exit(1)
246
+ except Exception as e:
247
+ print(f"Error in knowledge post-hook: {e}", file=sys.stderr)
248
+ sys.exit(1)
249
+
250
+ if __name__ == "__main__":
251
+ main()
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ ONE Platform - Knowledge Tagging Pre-Hook
4
+ Validates that artifacts created will be tagged as knowledge in the ontology.
5
+
6
+ This hook runs on PreToolUse to ensure:
7
+ - Knowledge dimension is properly mapped
8
+ - Artifacts will be categorized correctly
9
+ - Labels and metadata are prepared
10
+ """
11
+ import json
12
+ import sys
13
+ import os
14
+ from pathlib import Path
15
+ from typing import Dict, Any, Optional, List
16
+
17
+ # Knowledge artifact types
18
+ KNOWLEDGE_ARTIFACT_TYPES = {
19
+ "code": ["py", "ts", "tsx", "js", "jsx", "astro", "json", "yaml", "yml"],
20
+ "documentation": ["md", "mdx", "txt"],
21
+ "design": ["fig", "sketch", "svg", "png", "jpg"],
22
+ "test": ["test.ts", "test.tsx", "spec.ts", "spec.tsx"],
23
+ "config": ["json", "yaml", "yml", "toml", "ini"],
24
+ }
25
+
26
+ # Knowledge labels based on file location/type
27
+ KNOWLEDGE_LABELS = {
28
+ "/web/src/components": ["component", "frontend", "ui"],
29
+ "/web/src/pages": ["page", "frontend", "routing"],
30
+ "/backend/convex/queries": ["query", "backend", "database"],
31
+ "/backend/convex/mutations": ["mutation", "backend", "database"],
32
+ "/backend/convex/services": ["service", "backend", "business-logic"],
33
+ "/one/things": ["documentation", "ontology", "things"],
34
+ "/one/connections": ["documentation", "ontology", "connections"],
35
+ "/one/events": ["documentation", "ontology", "events"],
36
+ "/one/knowledge": ["documentation", "ontology", "knowledge"],
37
+ "/test": ["test", "quality", "validation"],
38
+ }
39
+
40
+ def get_artifact_type(file_path: str) -> Optional[str]:
41
+ """Determine artifact type from file path"""
42
+ path = Path(file_path)
43
+ ext = path.suffix.lstrip(".")
44
+
45
+ # Check for test files first
46
+ if "test" in path.name or "spec" in path.name:
47
+ return "test"
48
+
49
+ # Check by extension
50
+ for artifact_type, extensions in KNOWLEDGE_ARTIFACT_TYPES.items():
51
+ if any(path.name.endswith(e) for e in extensions):
52
+ return artifact_type
53
+
54
+ return None
55
+
56
+ def get_knowledge_labels(file_path: str) -> List[str]:
57
+ """Generate knowledge labels based on file path"""
58
+ labels = []
59
+
60
+ # Add labels based on path patterns
61
+ for path_pattern, path_labels in KNOWLEDGE_LABELS.items():
62
+ if path_pattern in file_path:
63
+ labels.extend(path_labels)
64
+
65
+ # Add artifact type label
66
+ artifact_type = get_artifact_type(file_path)
67
+ if artifact_type:
68
+ labels.append(artifact_type)
69
+
70
+ # Add dimension label if in /one
71
+ if "/one/" in file_path:
72
+ parts = Path(file_path).parts
73
+ try:
74
+ one_index = parts.index("one")
75
+ if one_index + 1 < len(parts):
76
+ dimension = parts[one_index + 1]
77
+ labels.append(f"dimension-{dimension}")
78
+ except ValueError:
79
+ pass
80
+
81
+ return list(set(labels)) # Remove duplicates
82
+
83
+ def should_tag_as_knowledge(file_path: str, tool_name: str) -> bool:
84
+ """Determine if artifact should be tagged as knowledge"""
85
+ # Only tag Write and Edit operations
86
+ if tool_name not in ["Write", "Edit", "MultiEdit"]:
87
+ return False
88
+
89
+ # Don't tag temporary files
90
+ if "/tmp/" in file_path or "/.temp/" in file_path:
91
+ return False
92
+
93
+ # Don't tag generated files
94
+ if "/_generated/" in file_path or "/node_modules/" in file_path:
95
+ return False
96
+
97
+ # Only tag known artifact types
98
+ artifact_type = get_artifact_type(file_path)
99
+ if not artifact_type:
100
+ return False
101
+
102
+ return True
103
+
104
+ def main():
105
+ """Main hook execution"""
106
+ try:
107
+ # Read hook input from stdin
108
+ hook_input = json.load(sys.stdin)
109
+
110
+ hook_event = hook_input.get("hook_event_name")
111
+ tool_name = hook_input.get("tool_name")
112
+ tool_input = hook_input.get("tool_input", {})
113
+
114
+ # Only process PreToolUse for Write/Edit operations
115
+ if hook_event != "PreToolUse":
116
+ sys.exit(0)
117
+
118
+ file_path = tool_input.get("file_path")
119
+ if not file_path:
120
+ sys.exit(0)
121
+
122
+ # Check if should be tagged as knowledge
123
+ if not should_tag_as_knowledge(file_path, tool_name):
124
+ sys.exit(0)
125
+
126
+ # Prepare knowledge metadata
127
+ artifact_type = get_artifact_type(file_path)
128
+ labels = get_knowledge_labels(file_path)
129
+
130
+ # Output pre-hook message
131
+ msg = f"📚 Knowledge Pre-Hook\n"
132
+ msg += f" Artifact: {Path(file_path).name}\n"
133
+ msg += f" Type: {artifact_type}\n"
134
+ msg += f" Labels: {', '.join(labels[:5])}"
135
+ if len(labels) > 5:
136
+ msg += f" (+{len(labels) - 5} more)"
137
+ msg += f"\n → Will be tagged in knowledge dimension after creation"
138
+
139
+ print(msg)
140
+ sys.exit(0)
141
+
142
+ except json.JSONDecodeError as e:
143
+ print(f"Error: Invalid JSON input: {e}", file=sys.stderr)
144
+ sys.exit(1)
145
+ except Exception as e:
146
+ print(f"Error in knowledge pre-hook: {e}", file=sys.stderr)
147
+ sys.exit(1)
148
+
149
+ if __name__ == "__main__":
150
+ main()
@@ -0,0 +1,112 @@
1
+ #!/bin/bash
2
+
3
+ # Notification Hook - ONE Platform
4
+ # Sends development notifications via console, system, or file
5
+
6
+ set -e
7
+
8
+ # Source the logger
9
+ source "$CLAUDE_PROJECT_DIR/.claude/hooks/hook-logger.sh"
10
+
11
+ # Configuration
12
+ EVENT="${1:-}"
13
+ MESSAGE="${2:-}"
14
+ TYPE="${3:-info}" # info, success, warning, error
15
+ CHANNEL="${4:-console}" # console, system, file, all
16
+
17
+ # Log start
18
+ log_message "INFO" "notification-hook: $EVENT ($TYPE) via $CHANNEL"
19
+ START_TIME=$(get_time_ms)
20
+
21
+ # Console notification
22
+ send_console() {
23
+ local msg="$1"
24
+ local type="$2"
25
+
26
+ case "$type" in
27
+ "success") echo "✅ $msg" ;;
28
+ "warning") echo "⚠️ $msg" ;;
29
+ "error") echo "❌ $msg" ;;
30
+ *) echo "ℹ️ $msg" ;;
31
+ esac
32
+ }
33
+
34
+ # System notification (macOS/Linux)
35
+ send_system() {
36
+ local title="$1"
37
+ local msg="$2"
38
+
39
+ if command -v osascript &> /dev/null; then
40
+ # macOS
41
+ osascript -e "display notification \"$msg\" with title \"ONE Platform - $title\"" 2>/dev/null || true
42
+ elif command -v notify-send &> /dev/null; then
43
+ # Linux
44
+ notify-send "ONE Platform - $title" "$msg" 2>/dev/null || true
45
+ else
46
+ # Fallback to console
47
+ send_console "$title: $msg" "info"
48
+ fi
49
+ }
50
+
51
+ # File notification
52
+ send_file() {
53
+ local msg="$1"
54
+ local type="$2"
55
+
56
+ local notif_file="$CLAUDE_PROJECT_DIR/.claude/notifications.log"
57
+ local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
58
+
59
+ echo "[$timestamp] [$type] $msg" >> "$notif_file"
60
+ }
61
+
62
+ # Notification templates
63
+ get_template() {
64
+ case "$1" in
65
+ "build-start") echo "Build process started" ;;
66
+ "build-success") echo "Build completed successfully" ;;
67
+ "build-failure") echo "Build failed" ;;
68
+ "test-success") echo "All tests passed" ;;
69
+ "test-failure") echo "Some tests failed" ;;
70
+ "security-warning") echo "Security warning detected" ;;
71
+ "security-block") echo "Security block - operation prevented" ;;
72
+ "session-start") echo "Claude Code session started" ;;
73
+ "session-end") echo "Claude Code session ended" ;;
74
+ *) echo "${MESSAGE:-$1}" ;;
75
+ esac
76
+ }
77
+
78
+ EXIT_CODE=0
79
+ NOTIFICATION_MESSAGE=$(get_template "$EVENT")
80
+
81
+ # Send notification
82
+ case "$CHANNEL" in
83
+ "console")
84
+ send_console "$NOTIFICATION_MESSAGE" "$TYPE"
85
+ ;;
86
+ "system")
87
+ send_system "$EVENT" "$NOTIFICATION_MESSAGE"
88
+ ;;
89
+ "file")
90
+ send_file "$NOTIFICATION_MESSAGE" "$TYPE"
91
+ ;;
92
+ "all")
93
+ send_console "$NOTIFICATION_MESSAGE" "$TYPE"
94
+ send_system "$EVENT" "$NOTIFICATION_MESSAGE"
95
+ send_file "$NOTIFICATION_MESSAGE" "$TYPE"
96
+ ;;
97
+ *)
98
+ echo "❌ Unknown channel: $CHANNEL"
99
+ EXIT_CODE=1
100
+ ;;
101
+ esac
102
+
103
+ # Log notification
104
+ if [ $EXIT_CODE -eq 0 ]; then
105
+ log_message "INFO" "Notification sent: $EVENT"
106
+ fi
107
+
108
+ # Log completion
109
+ END_TIME=$(get_time_ms)
110
+ log_hook_execution "notification-hook" "$EVENT $CHANNEL" "$START_TIME" "$END_TIME" "$EXIT_CODE"
111
+
112
+ exit $EXIT_CODE
@@ -0,0 +1,157 @@
1
+ #!/bin/bash
2
+
3
+ # Security Hook - ONE Platform
4
+ # Protects sensitive files and scans for credentials
5
+
6
+ set -e
7
+
8
+ # Source the logger
9
+ source "$CLAUDE_PROJECT_DIR/.claude/hooks/hook-logger.sh"
10
+
11
+ # Configuration
12
+ FILE_PATH="${1:-}"
13
+ MODE="${2:-protect}" # protect, scan, audit
14
+ ACTION="${3:-warn}" # warn, block, log
15
+
16
+ # Sensitive file patterns
17
+ SENSITIVE_PATTERNS=(
18
+ "**/.env*"
19
+ "**/secrets/**"
20
+ "**/*secret*"
21
+ "**/.ssh/**"
22
+ "**/*.pem"
23
+ "**/*.p12"
24
+ "**/credentials/**"
25
+ "**/*token*"
26
+ )
27
+
28
+ # Credential regex patterns
29
+ CREDENTIAL_PATTERNS=(
30
+ "api[_-]?key[s]?\s*[:=]\s*['\"]?[a-zA-Z0-9_-]{16,}"
31
+ "secret[_-]?key[s]?\s*[:=]\s*['\"]?[a-zA-Z0-9_-]{16,}"
32
+ "password[s]?\s*[:=]\s*['\"]?[a-zA-Z0-9!@#$%^&*()_+-=]{8,}"
33
+ "Bearer [a-zA-Z0-9_.-]{16,}"
34
+ "mongodb://[a-zA-Z0-9_:/@.-]+"
35
+ "postgres://[a-zA-Z0-9_:/@.-]+"
36
+ )
37
+
38
+ # Log start
39
+ log_message "INFO" "security-hook: $MODE mode for ${FILE_PATH:-all files}"
40
+ START_TIME=$(get_time_ms)
41
+
42
+ # Check if file matches sensitive patterns
43
+ is_sensitive_file() {
44
+ local file="$1"
45
+
46
+ for pattern in "${SENSITIVE_PATTERNS[@]}"; do
47
+ # Convert glob to regex
48
+ local regex=$(echo "$pattern" | sed 's/\*\*/.*/' | sed 's/\*/[^\/]*/')
49
+ if [[ "$file" =~ $regex ]]; then
50
+ return 0
51
+ fi
52
+ done
53
+ return 1
54
+ }
55
+
56
+ # Scan file content for credentials
57
+ scan_credentials() {
58
+ local file="$1"
59
+
60
+ if [ ! -f "$file" ]; then
61
+ return 0
62
+ fi
63
+
64
+ local found=0
65
+ for pattern in "${CREDENTIAL_PATTERNS[@]}"; do
66
+ if grep -qE "$pattern" "$file" 2>/dev/null; then
67
+ local line_num=$(grep -nE "$pattern" "$file" | head -1 | cut -d: -f1)
68
+ echo "⚠️ Line $line_num: Potential credential detected"
69
+ log_message "WARN" "Credential pattern in $file:$line_num"
70
+ found=1
71
+ fi
72
+ done
73
+
74
+ return $found
75
+ }
76
+
77
+ # Create audit entry
78
+ audit() {
79
+ local file="$1"
80
+ local event="$2"
81
+ local action="$3"
82
+
83
+ local audit_file="$CLAUDE_PROJECT_DIR/.claude/security-audit.log"
84
+ local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
85
+
86
+ echo "[$timestamp] $event | $file | $action" >> "$audit_file"
87
+ }
88
+
89
+ EXIT_CODE=0
90
+
91
+ case "$MODE" in
92
+ "protect")
93
+ if [ -n "$FILE_PATH" ] && is_sensitive_file "$FILE_PATH"; then
94
+ case "$ACTION" in
95
+ "block")
96
+ echo "🚫 BLOCKED: Cannot modify sensitive file: $FILE_PATH"
97
+ log_message "ERROR" "Blocked: $FILE_PATH"
98
+ audit "$FILE_PATH" "BLOCKED" "sensitive file"
99
+ EXIT_CODE=2
100
+ ;;
101
+ "warn")
102
+ echo "⚠️ WARNING: Modifying sensitive file: $FILE_PATH"
103
+ echo " Ensure no secrets are being committed"
104
+ log_message "WARN" "Sensitive file modified: $FILE_PATH"
105
+ audit "$FILE_PATH" "WARNED" "sensitive file"
106
+ ;;
107
+ "log")
108
+ log_message "INFO" "Sensitive file access: $FILE_PATH"
109
+ audit "$FILE_PATH" "LOGGED" "sensitive file"
110
+ ;;
111
+ esac
112
+ fi
113
+ ;;
114
+
115
+ "scan")
116
+ if [ -n "$FILE_PATH" ] && [ -f "$FILE_PATH" ]; then
117
+ echo "🔍 Scanning $FILE_PATH for credentials..."
118
+ if ! scan_credentials "$FILE_PATH"; then
119
+ echo "✅ No credentials detected"
120
+ audit "$FILE_PATH" "SCAN_PASSED" "clean"
121
+ else
122
+ audit "$FILE_PATH" "SCAN_FAILED" "credentials found"
123
+ if [ "$ACTION" = "block" ]; then
124
+ EXIT_CODE=2
125
+ fi
126
+ fi
127
+ fi
128
+ ;;
129
+
130
+ "audit")
131
+ echo "📋 Security Audit Summary"
132
+ local audit_file="$CLAUDE_PROJECT_DIR/.claude/security-audit.log"
133
+
134
+ if [ -f "$audit_file" ]; then
135
+ echo "Recent events (last 10):"
136
+ tail -10 "$audit_file"
137
+ echo ""
138
+ echo "Statistics:"
139
+ echo " Blocked: $(grep -c "BLOCKED" "$audit_file" 2>/dev/null || echo 0)"
140
+ echo " Warned: $(grep -c "WARNED" "$audit_file" 2>/dev/null || echo 0)"
141
+ echo " Scans failed: $(grep -c "SCAN_FAILED" "$audit_file" 2>/dev/null || echo 0)"
142
+ else
143
+ echo "No audit log found"
144
+ fi
145
+ ;;
146
+
147
+ *)
148
+ echo "❌ Unknown security mode: $MODE"
149
+ EXIT_CODE=1
150
+ ;;
151
+ esac
152
+
153
+ # Log completion
154
+ END_TIME=$(get_time_ms)
155
+ log_hook_execution "security-hook" "$MODE $FILE_PATH" "$START_TIME" "$END_TIME" "$EXIT_CODE"
156
+
157
+ exit $EXIT_CODE