ronce-racine 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/AGENTS.md +90 -0
  2. package/LICENSE +21 -0
  3. package/README.md +281 -0
  4. package/agents/code-reviewer.md +33 -0
  5. package/agents/qa-tester.md +28 -0
  6. package/dist/hooks/README.md +182 -0
  7. package/dist/hooks/bash-npm-silent.mjs +81 -0
  8. package/dist/hooks/session-inject.mjs +53 -0
  9. package/dist/hooks/session-precompact.mjs +36 -0
  10. package/dist/hooks/session-writer.mjs +142 -0
  11. package/dist/hooks/skill-reminder.mjs +89 -0
  12. package/dist/hooks/truncate-bash-output.mjs +46 -0
  13. package/dist/hooks/truncate-output.mjs +88 -0
  14. package/dist/hooks/worktree-env-setup.mjs +123 -0
  15. package/dist/install.js +962 -0
  16. package/docs/adopting-a-repo.md +80 -0
  17. package/docs/architecture.md +76 -0
  18. package/docs/decisions.md +72 -0
  19. package/docs/developing.md +143 -0
  20. package/docs/evaluating-skills.md +41 -0
  21. package/docs/git-worktrees.md +62 -0
  22. package/docs/rules/clean-architecture-deps.md +66 -0
  23. package/docs/rules/commits.md +59 -0
  24. package/docs/rules/detection-gap-protocol.md +55 -0
  25. package/docs/rules/error-handling-discipline.md +62 -0
  26. package/docs/rules/minimal-code.md +58 -0
  27. package/docs/rules/no-raw-sql-interpolation.md +57 -0
  28. package/docs/rules/pre-commit-secret-detection.md +54 -0
  29. package/docs/rules/secure-logging.md +53 -0
  30. package/docs/rules/sql-migrations-discipline.md +58 -0
  31. package/docs/rules/subscription-cleanup.md +63 -0
  32. package/docs/rules/test-discipline.md +66 -0
  33. package/docs/rules/ui-states-complete.md +52 -0
  34. package/docs/templates/SKILL.template.md +66 -0
  35. package/docs/templates/rule.template.md +16 -0
  36. package/docs/writing-a-rule.md +43 -0
  37. package/docs/writing-a-skill.md +118 -0
  38. package/package.json +45 -0
  39. package/rules/clean-architecture-deps.md +20 -0
  40. package/rules/commits.md +16 -0
  41. package/rules/detection-gap-protocol.md +35 -0
  42. package/rules/error-handling-discipline.md +23 -0
  43. package/rules/minimal-code.md +32 -0
  44. package/rules/no-raw-sql-interpolation.md +20 -0
  45. package/rules/pre-commit-secret-detection.md +14 -0
  46. package/rules/secure-logging.md +16 -0
  47. package/rules/sql-migrations-discipline.md +18 -0
  48. package/rules/subscription-cleanup.md +22 -0
  49. package/rules/test-discipline.md +20 -0
  50. package/rules/ui-states-complete.md +23 -0
  51. package/scripts/subscription-leak-scan.ts +53 -0
  52. package/skills/adversarial-feature-challenge/README.md +65 -0
  53. package/skills/adversarial-feature-challenge/SKILL.md +96 -0
  54. package/skills/adversarial-feature-challenge/assets/fuzz-payloads.txt +60 -0
  55. package/skills/adversarial-feature-challenge/templates/challenge-report.md +42 -0
  56. package/skills/api-contract-versioning/README.md +62 -0
  57. package/skills/api-contract-versioning/SKILL.md +76 -0
  58. package/skills/api-contract-versioning/templates/consumer-inventory.md +29 -0
  59. package/skills/audit-architecture/README.md +56 -0
  60. package/skills/audit-architecture/SKILL.md +97 -0
  61. package/skills/audit-architecture/reference/ar-architecture.md +275 -0
  62. package/skills/audit-architecture/reference/di-disponibilite.md +252 -0
  63. package/skills/audit-architecture/reference/im-incidents.md +217 -0
  64. package/skills/audit-architecture/reference/pa-pannes.md +362 -0
  65. package/skills/audit-architecture/reference/re-recuperation.md +300 -0
  66. package/skills/audit-architecture/reference/sc-scalabilite.md +173 -0
  67. package/skills/audit-architecture/reference/su-support.md +180 -0
  68. package/skills/audit-ci-cd/README.md +54 -0
  69. package/skills/audit-ci-cd/SKILL.md +124 -0
  70. package/skills/audit-ci-cd/reference/artefacts.md +39 -0
  71. package/skills/audit-ci-cd/reference/deploiement.md +100 -0
  72. package/skills/audit-ci-cd/reference/dora.md +94 -0
  73. package/skills/audit-ci-cd/reference/iac.md +40 -0
  74. package/skills/audit-ci-cd/reference/pipeline-ci.md +36 -0
  75. package/skills/audit-ci-cd/reference/supply-chain.md +44 -0
  76. package/skills/audit-compliance/README.md +69 -0
  77. package/skills/audit-compliance/SKILL.md +176 -0
  78. package/skills/audit-compliance/reference/conformite-rgpd.md +295 -0
  79. package/skills/audit-compliance/reference/finops.md +318 -0
  80. package/skills/audit-compliance/reference/gouvernance-donnees.md +238 -0
  81. package/skills/audit-industrialisation/README.md +53 -0
  82. package/skills/audit-industrialisation/SKILL.md +251 -0
  83. package/skills/audit-observability/README.md +64 -0
  84. package/skills/audit-observability/SKILL.md +134 -0
  85. package/skills/audit-observability/reference/alerting.md +214 -0
  86. package/skills/audit-observability/reference/logging.md +114 -0
  87. package/skills/audit-observability/reference/metriques.md +166 -0
  88. package/skills/audit-observability/reference/traces-dashboards.md +90 -0
  89. package/skills/audit-performance-frontend/README.md +91 -0
  90. package/skills/audit-performance-frontend/SKILL.md +194 -0
  91. package/skills/audit-performance-frontend/reference/assets-cache-network.md +129 -0
  92. package/skills/audit-performance-frontend/reference/css-rendering-pipeline.md +154 -0
  93. package/skills/audit-performance-frontend/reference/html-critical-path.md +128 -0
  94. package/skills/audit-performance-frontend/reference/js-engine-runtime.md +280 -0
  95. package/skills/audit-performance-frontend/reference/memory-gc.md +126 -0
  96. package/skills/audit-performance-frontend/reference/profiling-tooling.md +98 -0
  97. package/skills/audit-quality/README.md +85 -0
  98. package/skills/audit-quality/SKILL.md +126 -0
  99. package/skills/audit-quality/reference/qa-devops.md +539 -0
  100. package/skills/audit-quality/reference/qu-qualite-donnees.md +402 -0
  101. package/skills/audit-report/README.md +72 -0
  102. package/skills/audit-report/SKILL.md +241 -0
  103. package/skills/audit-report/reference/scoring-model.md +45 -0
  104. package/skills/audit-security/README.md +72 -0
  105. package/skills/audit-security/SKILL.md +140 -0
  106. package/skills/audit-security/reference/auth-identite.md +98 -0
  107. package/skills/audit-security/reference/autorisation.md +66 -0
  108. package/skills/audit-security/reference/chiffrement-tls.md +97 -0
  109. package/skills/audit-security/reference/detection-patching.md +67 -0
  110. package/skills/audit-security/reference/incident-response.md +98 -0
  111. package/skills/audit-security/reference/reseau-conteneurs.md +72 -0
  112. package/skills/audit-security/reference/secrets.md +36 -0
  113. package/skills/audit-testing/README.md +82 -0
  114. package/skills/audit-testing/SKILL.md +131 -0
  115. package/skills/audit-testing/reference/golden-dataset.md +65 -0
  116. package/skills/audit-testing/reference/resilience-chaos.md +93 -0
  117. package/skills/audit-testing/reference/tests-contractuels.md +65 -0
  118. package/skills/audit-testing/reference/tests-e2e-flaky.md +67 -0
  119. package/skills/audit-testing/reference/tests-unit-integ-ci.md +125 -0
  120. package/skills/bug-ticket-root-cause/README.md +67 -0
  121. package/skills/bug-ticket-root-cause/SKILL.md +86 -0
  122. package/skills/bug-ticket-root-cause/templates/bug-ticket.md +43 -0
  123. package/skills/bug-triage-structured/README.md +63 -0
  124. package/skills/bug-triage-structured/SKILL.md +104 -0
  125. package/skills/bug-triage-structured/templates/bug-triage.md +38 -0
  126. package/skills/ci-pipeline-orchestration/README.md +55 -0
  127. package/skills/ci-pipeline-orchestration/SKILL.md +110 -0
  128. package/skills/commit-readiness-review/README.md +66 -0
  129. package/skills/commit-readiness-review/SKILL.md +82 -0
  130. package/skills/commit-readiness-review/scripts/precommit-scan.ts +81 -0
  131. package/skills/comprehensive-test-strategy/README.md +64 -0
  132. package/skills/comprehensive-test-strategy/SKILL.md +108 -0
  133. package/skills/comprehensive-test-strategy/reference/testing-advanced.md +85 -0
  134. package/skills/daily-workflow-optimization/README.md +56 -0
  135. package/skills/daily-workflow-optimization/SKILL.md +80 -0
  136. package/skills/database-schema-evolution/README.md +54 -0
  137. package/skills/database-schema-evolution/SKILL.md +107 -0
  138. package/skills/ddd-backend-implementation/README.md +63 -0
  139. package/skills/ddd-backend-implementation/SKILL.md +95 -0
  140. package/skills/design-system-component-lifecycle/README.md +56 -0
  141. package/skills/design-system-component-lifecycle/SKILL.md +97 -0
  142. package/skills/design-system-component-lifecycle/templates/component-contract.md +43 -0
  143. package/skills/detection-sweep/README.md +58 -0
  144. package/skills/detection-sweep/SKILL.md +93 -0
  145. package/skills/detection-sweep/scripts/sweep.ts +80 -0
  146. package/skills/domain-modeling-design/README.md +57 -0
  147. package/skills/domain-modeling-design/SKILL.md +83 -0
  148. package/skills/frontend-fullstack-implementation/README.md +60 -0
  149. package/skills/frontend-fullstack-implementation/SKILL.md +133 -0
  150. package/skills/frontend-spec-call-site-audit/README.md +66 -0
  151. package/skills/frontend-spec-call-site-audit/SKILL.md +82 -0
  152. package/skills/frontend-spec-call-site-audit/scripts/audit-entry-points.ts +79 -0
  153. package/skills/frontend-spec-call-site-audit/templates/ticket-frontend.md +32 -0
  154. package/skills/merge-request-review/README.md +60 -0
  155. package/skills/merge-request-review/SKILL.md +77 -0
  156. package/skills/merge-request-review/templates/mr-review-report.md +29 -0
  157. package/skills/production-incident-diagnostic/README.md +63 -0
  158. package/skills/production-incident-diagnostic/SKILL.md +103 -0
  159. package/skills/production-incident-diagnostic/templates/incident-report.md +33 -0
  160. package/skills/qa-session-intake/README.md +56 -0
  161. package/skills/qa-session-intake/SKILL.md +78 -0
  162. package/skills/recording-decisions/README.md +91 -0
  163. package/skills/recording-decisions/SKILL.md +84 -0
  164. package/skills/recurring-bug-root-cause/README.md +64 -0
  165. package/skills/recurring-bug-root-cause/SKILL.md +93 -0
  166. package/skills/recurring-bug-root-cause/scripts/detect-recurring-fixes.ts +46 -0
  167. package/skills/recurring-bug-root-cause/templates/postmortem-recidive.md +37 -0
  168. package/skills/refactoring-shared-component-api/README.md +50 -0
  169. package/skills/refactoring-shared-component-api/SKILL.md +84 -0
  170. package/skills/refactoring-shared-component-api/scripts/sweep-call-sites.ts +85 -0
  171. package/skills/refactoring-shared-component-api/templates/migration-checklist.md +19 -0
  172. package/skills/validating-features-end-to-end/README.md +50 -0
  173. package/skills/validating-features-end-to-end/SKILL.md +90 -0
  174. package/skills/visual-regression-check/README.md +51 -0
  175. package/skills/visual-regression-check/SKILL.md +89 -0
  176. package/skills/writing-robust-tests/README.md +53 -0
  177. package/skills/writing-robust-tests/SKILL.md +88 -0
  178. package/templates/.adopted.example +8 -0
  179. package/templates/anti-drift.gitlab-ci.yml +23 -0
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * PreToolUse hook for Bash: adds `--silent` to a bare `npm install` / `npm ci`
4
+ * to reduce the install noise injected into the assistant's context.
5
+ *
6
+ * Conservative approach:
7
+ * - Only rewrites a single, non-compound `npm install` / `npm ci` / `npm i`
8
+ * with NO positional package (flags allowed). `npm install <pkg>` is a
9
+ * deliberate dependency add → left untouched.
10
+ * - Skips compound/piped commands (`&&`, `||`, `;`, `|`, backticks, `$(`):
11
+ * rewriting them is unsafe.
12
+ * - Adds only the `--silent` flag: it does NOT wrap the command in a pipe, so
13
+ * the real exit code is preserved (a failed `npm ci` still fails).
14
+ * - Does not touch a command that is already `--silent`/`--quiet`/`-s`.
15
+ *
16
+ * Bypass strategy: if the command contains `# no-silent`, we leave it untouched.
17
+ *
18
+ * @version 2.0.0
19
+ * @last-reviewed 2026-07-10
20
+ */
21
+ import { readFileSync } from 'node:fs';
22
+ function readStdin() {
23
+ try {
24
+ return readFileSync(0, 'utf-8');
25
+ }
26
+ catch {
27
+ return '';
28
+ }
29
+ }
30
+ function shouldRewrite(cmd) {
31
+ const trimmed = cmd.trim();
32
+ // Explicit bypass: a `# no-silent` comment anywhere in the command
33
+ if (trimmed.includes('# no-silent'))
34
+ return false;
35
+ // Skip compound/piped/substituted commands - rewriting them is unsafe
36
+ if (/[;&|`]|\$\(/.test(trimmed))
37
+ return false;
38
+ // Match ONLY a bare `npm install`/`npm ci`/`npm i` with no positional
39
+ // package (flags allowed). `npm install lodash` is a deliberate add → skip.
40
+ if (!/^npm\s+(install|ci|i)((?:\s+-{1,2}\S+)*)\s*$/.test(trimmed))
41
+ return false;
42
+ // Already silent → we add nothing
43
+ if (/--silent|--quiet|(^|\s)-s(\s|$)/.test(trimmed))
44
+ return false;
45
+ return true;
46
+ }
47
+ function rewrite(cmd) {
48
+ // Add `--silent` after the npm subcommand. No pipe → exit code preserved.
49
+ return cmd.replace(/^(\s*npm\s+(?:install|ci|i))\b/, '$1 --silent');
50
+ }
51
+ function main() {
52
+ const raw = readStdin();
53
+ if (!raw) {
54
+ process.exit(0); // no input, let it through
55
+ }
56
+ let parsed;
57
+ try {
58
+ parsed = JSON.parse(raw);
59
+ }
60
+ catch {
61
+ process.exit(0);
62
+ }
63
+ if (parsed.tool_name !== 'Bash')
64
+ process.exit(0);
65
+ const cmd = parsed.tool_input?.command ?? '';
66
+ if (!shouldRewrite(cmd))
67
+ process.exit(0);
68
+ const updated = rewrite(cmd);
69
+ const output = {
70
+ hookSpecificOutput: {
71
+ hookEventName: 'PreToolUse',
72
+ permissionDecision: 'allow',
73
+ permissionDecisionReason: 'Added --silent (bash-npm-silent hook)',
74
+ updatedInput: {
75
+ command: updated,
76
+ },
77
+ },
78
+ };
79
+ process.stdout.write(JSON.stringify(output));
80
+ }
81
+ main();
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * SessionStart hook - re-injects the session memo as additionalContext
4
+ * after a context compaction.
5
+ *
6
+ * The memo is read from `~/.claude/projects/<repo-slug>/sessions/<branch>.md`
7
+ * (written by session-writer). If no memo exists for the current branch,
8
+ * silent exit 0.
9
+ *
10
+ * Event : SessionStart
11
+ * Matcher : compact (only activates after a compaction)
12
+ * Input : stdin JSON { session_id?: string, ... }
13
+ * Output : stdout JSON { hookSpecificOutput: { hookEventName, additionalContext } } - or nothing if absent
14
+ *
15
+ * @version 1.0.0
16
+ * @last-reviewed 2026-06-25
17
+ */
18
+ import { readFileSync, existsSync } from 'node:fs';
19
+ import { sessionPathFor, currentBranch } from './session-writer.mjs';
20
+ const REPO_ROOT = process.env.CLAUDE_PROJECT_DIR ?? process.cwd();
21
+ function main() {
22
+ // Drain stdin (unused but required so as not to block the pipe)
23
+ try {
24
+ readFileSync(0, 'utf-8');
25
+ }
26
+ catch { /* ignore */ }
27
+ const branch = currentBranch(REPO_ROOT);
28
+ const memoPath = sessionPathFor(REPO_ROOT, branch);
29
+ if (!existsSync(memoPath)) {
30
+ process.exit(0);
31
+ }
32
+ try {
33
+ const content = readFileSync(memoPath, 'utf-8').trim();
34
+ if (!content) {
35
+ process.exit(0);
36
+ }
37
+ process.stdout.write(JSON.stringify({
38
+ hookSpecificOutput: {
39
+ hookEventName: 'SessionStart',
40
+ additionalContext: [
41
+ '## Context from the previous session',
42
+ '',
43
+ content,
44
+ '',
45
+ '_This context was preserved automatically before the compaction._',
46
+ ].join('\n'),
47
+ },
48
+ }));
49
+ }
50
+ catch { /* non-fatal - a hook must never break the session */ }
51
+ process.exit(0);
52
+ }
53
+ main();
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * PreCompact hook - persists a fresh session memo BEFORE a compaction, so the
4
+ * SessionStart(compact) hook can re-inject up-to-date context afterwards.
5
+ *
6
+ * Note: PreCompact CANNOT influence the compaction summary itself (the event has
7
+ * no mechanism to inject text into the summary prompt; `systemMessage` is only a
8
+ * user-facing notice). So instead of trying to steer the summary, this hook
9
+ * captures the current context to disk - the same memo file session-writer uses:
10
+ * `~/.claude/projects/<repo-slug>/sessions/<branch>.md`.
11
+ *
12
+ * Event : PreCompact
13
+ * Matcher : (none - applies to every compaction)
14
+ * Input : stdin JSON { transcript_path?: string, cwd?: string }
15
+ * Output : nothing (silent exit 0)
16
+ *
17
+ * @version 2.0.0
18
+ * @last-reviewed 2026-07-10
19
+ */
20
+ import { readFileSync } from 'node:fs';
21
+ import { persistMemo } from './session-writer.mjs';
22
+ const REPO_ROOT = process.env.CLAUDE_PROJECT_DIR ?? process.cwd();
23
+ function main() {
24
+ let event = {};
25
+ try {
26
+ const raw = readFileSync(0, 'utf-8').trim();
27
+ if (raw)
28
+ event = JSON.parse(raw);
29
+ }
30
+ catch { /* fail-open */ }
31
+ const repoRoot = event.cwd ?? REPO_ROOT;
32
+ const now = new Date().toISOString().replace('T', ' ').slice(0, 16);
33
+ persistMemo(repoRoot, event.transcript_path, now);
34
+ process.exit(0);
35
+ }
36
+ main();
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Stop hook - writes the session memo OUTSIDE the repo, to
4
+ * `~/.claude/projects/<repo-slug>/sessions/<branch>.md`.
5
+ *
6
+ * The file is stored outside the repository to avoid polluting git status
7
+ * and to stay relevant independently of the target project.
8
+ *
9
+ * Event : Stop
10
+ * Matcher : (none - applies to every session end)
11
+ * Input : stdin JSON { transcript_path?: string, stop_hook_active?: boolean }
12
+ * Output : nothing (silent exit 0)
13
+ *
14
+ * @version 1.0.0
15
+ * @last-reviewed 2026-06-25
16
+ */
17
+ import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
18
+ import { join } from 'node:path';
19
+ import { homedir } from 'node:os';
20
+ import { spawnSync } from 'node:child_process';
21
+ import { pathToFileURL } from 'node:url';
22
+ const REPO_ROOT = process.env.CLAUDE_PROJECT_DIR ?? process.cwd();
23
+ function readStdin() {
24
+ try {
25
+ return readFileSync(0, 'utf-8');
26
+ }
27
+ catch {
28
+ return '';
29
+ }
30
+ }
31
+ function parseTranscript(path) {
32
+ try {
33
+ return readFileSync(path, 'utf-8')
34
+ .split('\n')
35
+ .filter(l => l.trim())
36
+ .map(l => { try {
37
+ return JSON.parse(l);
38
+ }
39
+ catch {
40
+ return null;
41
+ } })
42
+ .filter((e) => e !== null);
43
+ }
44
+ catch {
45
+ return [];
46
+ }
47
+ }
48
+ /** Walks back through the transcript entries to find the last user message. */
49
+ function extractLastUserMessage(entries) {
50
+ for (let i = entries.length - 1; i >= 0; i--) {
51
+ const entry = entries[i];
52
+ if (entry.type !== 'user')
53
+ continue;
54
+ const content = entry.message?.content;
55
+ if (typeof content === 'string' && content.trim())
56
+ return content.slice(0, 600);
57
+ if (Array.isArray(content)) {
58
+ const block = content.find(b => b.type === 'text' && b.text?.trim());
59
+ if (block?.text)
60
+ return block.text.slice(0, 600);
61
+ }
62
+ }
63
+ return null;
64
+ }
65
+ function git(args, cwd) {
66
+ const r = spawnSync('git', args, { cwd, encoding: 'utf-8', timeout: 5000 });
67
+ return r.stdout?.trim() ?? '';
68
+ }
69
+ /** Returns the repository's current branch (fallback: 'master'). */
70
+ export function currentBranch(repoRoot) {
71
+ return git(['rev-parse', '--abbrev-ref', 'HEAD'], repoRoot) || 'master';
72
+ }
73
+ /**
74
+ * Slugifies an absolute path by replacing `/` with `-`, matching the
75
+ * Claude Code convention for `~/.claude/projects/<slug>/`.
76
+ */
77
+ export function repoSlug(absPath) {
78
+ return absPath.replace(/\//g, '-');
79
+ }
80
+ /**
81
+ * Slugifies a branch name into a safe filename (`/` is problematic on
82
+ * most filesystems).
83
+ */
84
+ export function branchSlug(branch) {
85
+ return branch.replace(/[/\\]/g, '_').replace(/[^A-Za-z0-9._-]/g, '_');
86
+ }
87
+ /** Home directory, honoring $HOME (os.homedir() ignores it on POSIX). */
88
+ function home() {
89
+ return process.env.HOME || homedir();
90
+ }
91
+ /** External sessions directory for a given repository. */
92
+ export function sessionsDir(repoRoot) {
93
+ return join(home(), '.claude', 'projects', repoSlug(repoRoot), 'sessions');
94
+ }
95
+ /** Full path of the session memo for a given branch. */
96
+ export function sessionPathFor(repoRoot, branch) {
97
+ return join(sessionsDir(repoRoot), `${branchSlug(branch)}.md`);
98
+ }
99
+ /** Builds the memo markdown. Pure and deterministic given `now`. */
100
+ export function buildMemo(branch, lastIntent, now) {
101
+ const lines = [
102
+ `# Session - ${now}`,
103
+ '',
104
+ `**Branch:** \`${branch}\``,
105
+ ];
106
+ if (lastIntent) {
107
+ lines.push('', '## Latest user intent', `> ${lastIntent.replace(/\n/g, '\n> ')}`);
108
+ }
109
+ lines.push('', '---', '_session memo (ronce-racine)_');
110
+ return lines.join('\n');
111
+ }
112
+ /** Reads the transcript, builds the memo and writes it to disk. Fail-open. */
113
+ export function persistMemo(repoRoot, transcriptPath, now) {
114
+ try {
115
+ const entries = transcriptPath ? parseTranscript(transcriptPath) : [];
116
+ const branch = currentBranch(repoRoot);
117
+ const lastIntent = extractLastUserMessage(entries);
118
+ mkdirSync(sessionsDir(repoRoot), { recursive: true });
119
+ writeFileSync(sessionPathFor(repoRoot, branch), buildMemo(branch, lastIntent, now), 'utf-8');
120
+ }
121
+ catch { /* non-fatal - a hook must never break the session */ }
122
+ }
123
+ function main() {
124
+ let event = {};
125
+ try {
126
+ const raw = readStdin().trim();
127
+ if (raw)
128
+ event = JSON.parse(raw);
129
+ }
130
+ catch { /* fail-open */ }
131
+ // Resolve the repository root: prefer the event's cwd field, then env, then cwd()
132
+ const repoRoot = event.cwd ?? REPO_ROOT;
133
+ const now = new Date().toISOString().replace('T', ' ').slice(0, 16);
134
+ persistMemo(repoRoot, event.transcript_path, now);
135
+ process.exit(0);
136
+ }
137
+ // Only run main() if the file is launched directly (not imported).
138
+ // Canonical ESM test: compare the module URL to the actual entry point.
139
+ // Works under tsx (process.argv[1] → .ts path) and with a compiled bundle.
140
+ const isMain = import.meta.url === pathToFileURL(process.argv[1] ?? '').href;
141
+ if (isMain)
142
+ main();
@@ -0,0 +1,89 @@
1
+ #!/usr/bin/env -S npx tsx
2
+ /**
3
+ * UserPromptSubmit hook: suggests the relevant skills given the prompt.
4
+ *
5
+ * Self-maintained: reads the skills' descriptions (frontmatter) and matches the
6
+ * quoted triggers + the words of the name against the prompt.
7
+ * NEVER blocks (exit 0 no matter what); emits nothing if there is no match.
8
+ *
9
+ * settings.json wiring (see hooks/README.md):
10
+ * "UserPromptSubmit": [{ "hooks": [{ "type": "command",
11
+ * "command": "npx tsx $CLAUDE_PROJECT_DIR/.claude/hooks/skill-reminder.ts" }] }]
12
+ *
13
+ * @version 1.0.0
14
+ * @last-reviewed 2026-06-25
15
+ */
16
+ import { readFileSync, readdirSync, existsSync } from "node:fs";
17
+ import { join, dirname } from "node:path";
18
+ import { fileURLToPath } from "node:url";
19
+ const MIN_TRIGGER_LEN = 4; // ignore triggers that are too short (noise)
20
+ const MAX_SUGGESTIONS = 3;
21
+ function readStdin() {
22
+ try {
23
+ return readFileSync(0, "utf8");
24
+ }
25
+ catch {
26
+ return "";
27
+ }
28
+ }
29
+ function skillsDir() {
30
+ const candidates = [
31
+ process.env.CLAUDE_PROJECT_DIR && join(process.env.CLAUDE_PROJECT_DIR, ".claude/skills"),
32
+ join(process.cwd(), ".claude/skills"),
33
+ join(process.cwd(), "skills"),
34
+ join(dirname(fileURLToPath(import.meta.url)), "../skills"),
35
+ ].filter((p) => Boolean(p));
36
+ return candidates.find((p) => existsSync(p));
37
+ }
38
+ /** A skill's triggers: quoted strings from the description + words of the name. */
39
+ function triggers(name, description) {
40
+ const quoted = [...description.matchAll(/"([^"]+)"|«\s*([^»]+?)\s*»/g)].map((m) => m[1] || m[2]);
41
+ const nameWords = name.split("-").filter((w) => w.length >= MIN_TRIGGER_LEN);
42
+ return [...quoted, ...nameWords]
43
+ .map((t) => t.toLowerCase().trim())
44
+ .filter((t) => t.length >= MIN_TRIGGER_LEN);
45
+ }
46
+ function loadSkills(dir) {
47
+ const out = [];
48
+ for (const name of readdirSync(dir)) {
49
+ const p = join(dir, name, "SKILL.md");
50
+ if (!existsSync(p))
51
+ continue;
52
+ const raw = readFileSync(p, "utf8");
53
+ const fm = /^---\n([\s\S]*?)\n---/.exec(raw);
54
+ const desc = fm && /description:\s*(.*)/.exec(fm[1]);
55
+ if (desc)
56
+ out.push({ name, triggers: triggers(name, desc[1]) });
57
+ }
58
+ return out;
59
+ }
60
+ function main() {
61
+ const dir = skillsDir();
62
+ if (!dir)
63
+ return;
64
+ let prompt = "";
65
+ try {
66
+ prompt = (JSON.parse(readStdin()).prompt || "").toLowerCase();
67
+ }
68
+ catch {
69
+ return;
70
+ }
71
+ if (!prompt)
72
+ return;
73
+ const scored = loadSkills(dir)
74
+ .map((s) => ({ name: s.name, hits: s.triggers.filter((t) => prompt.includes(t)).length }))
75
+ .filter((s) => s.hits > 0)
76
+ .sort((a, b) => b.hits - a.hits)
77
+ .slice(0, MAX_SUGGESTIONS);
78
+ if (!scored.length)
79
+ return;
80
+ const list = scored.map((s) => s.name).join(", ");
81
+ console.log(`Skills potentially relevant to this request: ${list}. Invoke them via the Skill tool if they apply.`);
82
+ }
83
+ try {
84
+ main();
85
+ }
86
+ catch {
87
+ /* a hook must never break the session */
88
+ }
89
+ process.exit(0);
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Helper script invoked by truncate-output.ts (PreToolUse hook).
4
+ * Runs a bash command (decoded from the TRUNCATE_CMD_B64 variable),
5
+ * captures the output and truncates it if the command succeeds and the output
6
+ * exceeds the character threshold.
7
+ * On error (exit ≠ 0), the full output is preserved for debugging.
8
+ *
9
+ * @version 1.0.0
10
+ * @last-reviewed 2026-06-25
11
+ */
12
+ import { spawnSync } from 'node:child_process';
13
+ export const THRESHOLD = 4000;
14
+ export const HEAD_LINES = 20;
15
+ export const TAIL_LINES = 20;
16
+ export function truncateOutput(output) {
17
+ if (output.length <= THRESHOLD)
18
+ return output;
19
+ const lines = output.split('\n');
20
+ if (lines.length <= HEAD_LINES + TAIL_LINES)
21
+ return output;
22
+ const omitted = lines.length - HEAD_LINES - TAIL_LINES;
23
+ const head = lines.slice(0, HEAD_LINES).join('\n');
24
+ const tail = lines.slice(-TAIL_LINES).join('\n');
25
+ return `${head}\n\n... [${omitted} lines omitted of ${lines.length}, ${output.length} chars total] ...\n\n${tail}`;
26
+ }
27
+ function main() {
28
+ const encoded = process.env.TRUNCATE_CMD_B64;
29
+ if (!encoded)
30
+ process.exit(0);
31
+ const cmd = Buffer.from(encoded, 'base64').toString('utf-8');
32
+ const result = spawnSync('bash', ['-c', `( ${cmd}\n) 2>&1`], {
33
+ encoding: 'utf-8',
34
+ maxBuffer: 50 * 1024 * 1024,
35
+ stdio: ['inherit', 'pipe', 'inherit'],
36
+ });
37
+ const output = result.stdout ?? '';
38
+ const exitCode = result.status ?? 1;
39
+ if (exitCode !== 0) {
40
+ process.stdout.write(output);
41
+ process.exit(exitCode);
42
+ }
43
+ process.stdout.write(truncateOutput(output));
44
+ }
45
+ if (process.argv[1]?.endsWith('truncate-bash-output.ts'))
46
+ main();
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * PreToolUse hook for Bash: wraps verbose commands (cargo build/test,
4
+ * npm install, git log, curl…) so their output is truncated when it
5
+ * exceeds a character threshold. Error output (exit ≠ 0) is always
6
+ * preserved in full so as not to hide debugging information.
7
+ *
8
+ * Uses base64 encoding to pass the original command to the
9
+ * truncate-bash-output.ts script, avoiding shell-escaping problems.
10
+ *
11
+ * Bypass strategy: if the command contains `# no-truncate`, we leave it untouched.
12
+ *
13
+ * @version 2.0.0
14
+ * @last-reviewed 2026-07-10
15
+ */
16
+ import { readFileSync } from 'node:fs';
17
+ const VERBOSE_PATTERNS = [
18
+ /^\s*cargo\s+(build|test|clippy|check|fmt|doc|run)/,
19
+ // `npm install`/`npm ci` are handled by the bash-npm-silent hook (avoid a
20
+ // two-hook conflict on the same command - PreToolUse updatedInput is last-wins).
21
+ /^\s*npm\s+run\s+(build|test|typecheck|lint)\b/,
22
+ /^\s*npx\s+(vitest|tsc|nuxi|tsx)\b/,
23
+ /^\s*git\s+(log|diff)\b/,
24
+ /^\s*curl\s/,
25
+ /^\s*docker\s+(build|logs)\b/,
26
+ /^\s*rustup\s/,
27
+ ];
28
+ const SKIP_PATTERNS = [
29
+ /\|\s*(head|tail|grep|wc|less|more|awk|sed|cut|sort|uniq|jq)\b/,
30
+ /# no-truncate/,
31
+ /truncate-bash-output/,
32
+ ];
33
+ export function isVerboseCommand(cmd) {
34
+ if (SKIP_PATTERNS.some(p => p.test(cmd)))
35
+ return false;
36
+ const parts = cmd.split(/&&|\|\|/).map(s => s.trim());
37
+ return parts.some(part => VERBOSE_PATTERNS.some(p => p.test(part)));
38
+ }
39
+ export function wrapCommand(cmd, hookDir) {
40
+ const encoded = Buffer.from(cmd).toString('base64');
41
+ // Run the helper via `npx tsx` (works on any Node ≥ 18) rather than
42
+ // `node --experimental-strip-types` (only Node ≥ 22.6), matching how the
43
+ // hooks themselves are wired in settings.json.
44
+ return `TRUNCATE_CMD_B64=${encoded} npx -y tsx '${hookDir}/truncate-bash-output.ts'`;
45
+ }
46
+ function readStdin() {
47
+ try {
48
+ return readFileSync(0, 'utf-8');
49
+ }
50
+ catch {
51
+ return '';
52
+ }
53
+ }
54
+ function main() {
55
+ const raw = readStdin();
56
+ if (!raw)
57
+ return;
58
+ let parsed;
59
+ try {
60
+ parsed = JSON.parse(raw);
61
+ }
62
+ catch {
63
+ return;
64
+ }
65
+ if (parsed.tool_name !== 'Bash')
66
+ return;
67
+ const cmd = parsed.tool_input?.command ?? '';
68
+ if (!cmd || !isVerboseCommand(cmd))
69
+ return;
70
+ // Resolving the hooks directory: the CLAUDE_PROJECT_DIR variable takes priority,
71
+ // otherwise a path relative to this file (for local execution / tests)
72
+ const hookDir = process.env.CLAUDE_PROJECT_DIR
73
+ ? `${process.env.CLAUDE_PROJECT_DIR}/.claude/hooks`
74
+ : new URL('.', import.meta.url).pathname.replace(/\/$/, '');
75
+ const output = {
76
+ hookSpecificOutput: {
77
+ hookEventName: 'PreToolUse',
78
+ permissionDecision: 'allow',
79
+ permissionDecisionReason: 'Auto-truncate verbose output (truncate-output hook)',
80
+ updatedInput: {
81
+ command: wrapCommand(cmd, hookDir),
82
+ },
83
+ },
84
+ };
85
+ process.stdout.write(JSON.stringify(output));
86
+ }
87
+ if (process.argv[1]?.endsWith('truncate-output.ts'))
88
+ main();
@@ -0,0 +1,123 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * SessionStart hook - symlink .env in a linked worktree.
4
+ *
5
+ * If the session starts in a linked git worktree (not the main worktree),
6
+ * and the main repo has a `.env` but the current worktree does not,
7
+ * creates a `.env` → `<main-repo>/.env` symlink in the worktree.
8
+ *
9
+ * Behavior:
10
+ * - Absolutely fail-open: any error (no git, no worktree, no .env,
11
+ * symlink already present, insufficient permissions) → silent exit 0.
12
+ * - Idempotent: if the symlink already exists and points to the right place, do nothing.
13
+ * - Never overwrites an existing .env (file or symlink to another target).
14
+ *
15
+ * Event : SessionStart
16
+ * stdin input : JSON { cwd?: string, ... } (read but not required)
17
+ * Output : nothing (silent exit 0)
18
+ *
19
+ * @version 1.0.1
20
+ * @last-reviewed 2026-07-20
21
+ */
22
+ import { readFileSync, existsSync, symlinkSync, lstatSync, readlinkSync, unlinkSync } from 'node:fs';
23
+ import { join, resolve } from 'node:path';
24
+ import { spawnSync } from 'node:child_process';
25
+ import { pathToFileURL } from 'node:url';
26
+ /** Runs a git command and returns trimmed stdout, or '' on failure. */
27
+ function git(args, cwd) {
28
+ const r = spawnSync('git', args, { cwd, encoding: 'utf-8', timeout: 5000 });
29
+ if (r.status !== 0 || r.error)
30
+ return '';
31
+ return r.stdout?.trim() ?? '';
32
+ }
33
+ /**
34
+ * Determines whether `dir` is a linked git worktree (not the main worktree).
35
+ * Method: in a linked worktree, `--git-dir` ≠ `--git-common-dir`.
36
+ * In the main worktree, the two are identical (or `--git-common-dir` is the same directory).
37
+ */
38
+ function isLinkedWorktree(dir) {
39
+ const gitDir = git(['rev-parse', '--git-dir'], dir);
40
+ const commonDir = git(['rev-parse', '--git-common-dir'], dir);
41
+ if (!gitDir || !commonDir)
42
+ return false;
43
+ // Resolve to an absolute path to compare unambiguously
44
+ const absGitDir = resolve(dir, gitDir);
45
+ const absCommonDir = resolve(dir, commonDir);
46
+ return absGitDir !== absCommonDir;
47
+ }
48
+ /**
49
+ * Returns the current worktree's root via `git rev-parse --show-toplevel`.
50
+ */
51
+ function worktreeRoot(dir) {
52
+ return git(['rev-parse', '--show-toplevel'], dir);
53
+ }
54
+ /**
55
+ * Returns the main repo's root from the git-common-dir.
56
+ * A linked worktree's git-common-dir is `<main-repo>/.git`;
57
+ * its parent is therefore the main repo's root.
58
+ */
59
+ function mainRepoRoot(dir) {
60
+ const commonDir = git(['rev-parse', '--path-format=absolute', '--git-common-dir'], dir);
61
+ if (!commonDir)
62
+ return '';
63
+ // commonDir points to the main repo's .git directory
64
+ return resolve(commonDir, '..');
65
+ }
66
+ function main() {
67
+ // Consume stdin (required by some Claude Code harnesses)
68
+ try {
69
+ readFileSync(0, 'utf-8');
70
+ }
71
+ catch { /* no stdin, not blocking */ }
72
+ const cwd = process.env.CLAUDE_PROJECT_DIR ?? process.cwd();
73
+ // Exit silently if we are not in a linked worktree
74
+ if (!isLinkedWorktree(cwd))
75
+ return;
76
+ const wtRoot = worktreeRoot(cwd);
77
+ const mainRoot = mainRepoRoot(cwd);
78
+ if (!wtRoot || !mainRoot)
79
+ return;
80
+ const envMain = join(mainRoot, '.env');
81
+ const envWt = join(wtRoot, '.env');
82
+ // The main repo must have a .env
83
+ if (!existsSync(envMain))
84
+ return;
85
+ // If a .env already exists in the worktree, do not overwrite it.
86
+ // (lstat, not existsSync: existsSync follows symlinks and reports a BROKEN
87
+ // symlink as absent - symlinkSync would then fail EEXIST and never repair it.)
88
+ let entry;
89
+ try {
90
+ entry = lstatSync(envWt);
91
+ }
92
+ catch { /* no entry: fall through and create */ }
93
+ if (entry) {
94
+ if (!entry.isSymbolicLink())
95
+ return; // a real file: never touch it
96
+ try {
97
+ if (resolve(wtRoot, readlinkSync(envWt)) === envMain && existsSync(envWt))
98
+ return; // already correct
99
+ }
100
+ catch {
101
+ return; /* unreadable link → exit without overwriting */
102
+ }
103
+ if (existsSync(envWt))
104
+ return; // valid symlink to another target: never touch it
105
+ // Broken symlink: it holds no data - replace it with the correct link.
106
+ try {
107
+ unlinkSync(envWt);
108
+ }
109
+ catch {
110
+ return;
111
+ }
112
+ }
113
+ // Create the .env → <main-repo>/.env symlink
114
+ try {
115
+ symlinkSync(envMain, envWt);
116
+ }
117
+ catch { /* non-fatal - insufficient permissions or race condition */ }
118
+ }
119
+ // Only run main() if the file is launched directly (not imported).
120
+ const isMain = import.meta.url === pathToFileURL(process.argv[1] ?? '').href;
121
+ if (isMain)
122
+ main();
123
+ process.exit(0);