hatch3r 1.7.1 → 1.8.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 (189) hide show
  1. package/README.md +38 -12
  2. package/agents/hatch3r-a11y-auditor.md +4 -0
  3. package/agents/hatch3r-architect.md +4 -0
  4. package/agents/hatch3r-ci-watcher.md +4 -0
  5. package/agents/hatch3r-context-rules.md +26 -6
  6. package/agents/hatch3r-creator.md +6 -1
  7. package/agents/hatch3r-dependency-auditor.md +4 -0
  8. package/agents/hatch3r-devops.md +4 -0
  9. package/agents/hatch3r-docs-writer.md +4 -0
  10. package/agents/hatch3r-fixer.md +4 -0
  11. package/agents/hatch3r-handoff-loader.md +243 -0
  12. package/agents/hatch3r-handoff-preparer.md +134 -0
  13. package/agents/hatch3r-implementer.md +12 -0
  14. package/agents/hatch3r-learnings-loader.md +5 -1
  15. package/agents/hatch3r-lint-fixer.md +4 -0
  16. package/agents/hatch3r-perf-profiler.md +8 -0
  17. package/agents/hatch3r-researcher.md +4 -0
  18. package/agents/hatch3r-reviewer.md +94 -0
  19. package/agents/hatch3r-security-auditor.md +24 -0
  20. package/agents/hatch3r-test-writer.md +4 -0
  21. package/agents/modes/requirements-elicitation.md +4 -1
  22. package/agents/modes/similar-implementation.md +6 -0
  23. package/agents/modes/user-flows.md +76 -0
  24. package/agents/shared/quality-charter.md +128 -0
  25. package/agents/shared/user-content-templates.md +31 -1
  26. package/commands/hatch3r-agent-customize.md +4 -0
  27. package/commands/hatch3r-api-spec.md +7 -0
  28. package/commands/hatch3r-benchmark.md +7 -0
  29. package/commands/hatch3r-board-fill.md +8 -0
  30. package/commands/hatch3r-board-groom.md +4 -0
  31. package/commands/hatch3r-board-init.md +51 -0
  32. package/commands/hatch3r-board-pickup.md +8 -0
  33. package/commands/hatch3r-board-refresh.md +4 -0
  34. package/commands/hatch3r-board-shared.md +6 -6
  35. package/commands/hatch3r-bug-plan.md +7 -0
  36. package/commands/hatch3r-codebase-map.md +8 -0
  37. package/commands/hatch3r-command-customize.md +4 -0
  38. package/commands/hatch3r-context-health.md +5 -0
  39. package/commands/hatch3r-create.md +59 -4
  40. package/commands/hatch3r-debug.md +7 -0
  41. package/commands/hatch3r-dep-audit.md +4 -0
  42. package/commands/hatch3r-feature-plan.md +7 -0
  43. package/commands/hatch3r-handoff.md +133 -0
  44. package/commands/hatch3r-healthcheck.md +4 -0
  45. package/commands/hatch3r-hooks.md +4 -0
  46. package/commands/hatch3r-learn.md +16 -0
  47. package/commands/hatch3r-migration-plan.md +7 -0
  48. package/commands/hatch3r-onboard.md +7 -0
  49. package/commands/hatch3r-pr-resolve.md +12 -1
  50. package/commands/hatch3r-project-spec.md +8 -0
  51. package/commands/hatch3r-quick-change.md +11 -2
  52. package/commands/hatch3r-recipe.md +4 -0
  53. package/commands/hatch3r-refactor-plan.md +7 -0
  54. package/commands/hatch3r-release.md +5 -0
  55. package/commands/hatch3r-revision.md +7 -0
  56. package/commands/hatch3r-roadmap.md +8 -0
  57. package/commands/hatch3r-rule-customize.md +4 -0
  58. package/commands/hatch3r-security-audit.md +4 -0
  59. package/commands/hatch3r-skill-customize.md +4 -0
  60. package/commands/hatch3r-test-plan.md +7 -0
  61. package/commands/hatch3r-workflow.md +11 -1
  62. package/dist/cli/index.js +4814 -1130
  63. package/dist/cli/index.js.map +1 -1
  64. package/package.json +10 -5
  65. package/rules/hatch3r-accessibility-standards.md +21 -0
  66. package/rules/hatch3r-accessibility-standards.mdc +21 -0
  67. package/rules/hatch3r-agent-orchestration-detail.md +3 -0
  68. package/rules/hatch3r-agent-orchestration-detail.mdc +3 -0
  69. package/rules/hatch3r-agent-orchestration.md +34 -3
  70. package/rules/hatch3r-agent-orchestration.mdc +34 -3
  71. package/rules/hatch3r-ai-evals.md +158 -0
  72. package/rules/hatch3r-ai-evals.mdc +154 -0
  73. package/rules/hatch3r-ai-ux-patterns.md +131 -0
  74. package/rules/hatch3r-ai-ux-patterns.mdc +127 -0
  75. package/rules/hatch3r-api-design.md +67 -9
  76. package/rules/hatch3r-api-design.mdc +67 -9
  77. package/rules/hatch3r-api-versioning.md +119 -0
  78. package/rules/hatch3r-api-versioning.mdc +115 -0
  79. package/rules/hatch3r-auth-patterns.md +170 -0
  80. package/rules/hatch3r-auth-patterns.mdc +166 -0
  81. package/rules/hatch3r-component-conventions.md +30 -0
  82. package/rules/hatch3r-component-conventions.mdc +30 -0
  83. package/rules/hatch3r-container-hardening.md +131 -0
  84. package/rules/hatch3r-container-hardening.mdc +127 -0
  85. package/rules/hatch3r-contract-testing.md +117 -0
  86. package/rules/hatch3r-contract-testing.mdc +113 -0
  87. package/rules/hatch3r-deep-context.md +2 -0
  88. package/rules/hatch3r-deep-context.mdc +2 -0
  89. package/rules/hatch3r-dependency-management.md +73 -1
  90. package/rules/hatch3r-dependency-management.mdc +72 -0
  91. package/rules/hatch3r-design-system-detection.md +142 -0
  92. package/rules/hatch3r-design-system-detection.mdc +138 -0
  93. package/rules/hatch3r-event-schema-evolution.md +90 -0
  94. package/rules/hatch3r-event-schema-evolution.mdc +86 -0
  95. package/rules/hatch3r-handoff-readiness.md +45 -0
  96. package/rules/hatch3r-handoff-readiness.mdc +40 -0
  97. package/rules/hatch3r-i18n.md +13 -0
  98. package/rules/hatch3r-i18n.mdc +13 -0
  99. package/rules/hatch3r-iteration-summary.md +2 -0
  100. package/rules/hatch3r-iteration-summary.mdc +2 -0
  101. package/rules/hatch3r-migrations.md +61 -16
  102. package/rules/hatch3r-migrations.mdc +61 -16
  103. package/rules/hatch3r-observability-logging.md +1 -1
  104. package/rules/hatch3r-observability-logging.mdc +1 -1
  105. package/rules/hatch3r-observability-metrics.md +1 -1
  106. package/rules/hatch3r-observability-metrics.mdc +1 -1
  107. package/rules/hatch3r-observability-tracing-detail.md +8 -149
  108. package/rules/hatch3r-observability-tracing-detail.mdc +7 -149
  109. package/rules/hatch3r-observability-tracing.md +154 -6
  110. package/rules/hatch3r-observability-tracing.mdc +154 -6
  111. package/rules/hatch3r-observability.md +1 -0
  112. package/rules/hatch3r-observability.mdc +1 -0
  113. package/rules/hatch3r-operability.md +149 -0
  114. package/rules/hatch3r-operability.mdc +145 -0
  115. package/rules/hatch3r-passkey-server.md +181 -0
  116. package/rules/hatch3r-passkey-server.mdc +177 -0
  117. package/rules/hatch3r-progressive-delivery.md +120 -0
  118. package/rules/hatch3r-progressive-delivery.mdc +116 -0
  119. package/rules/hatch3r-resilience-patterns.md +154 -0
  120. package/rules/hatch3r-resilience-patterns.mdc +150 -0
  121. package/rules/hatch3r-secrets-management.md +29 -0
  122. package/rules/hatch3r-secrets-management.mdc +29 -0
  123. package/rules/hatch3r-testing.md +139 -43
  124. package/rules/hatch3r-testing.mdc +139 -43
  125. package/rules/hatch3r-ux-states-and-flows.md +149 -0
  126. package/rules/hatch3r-ux-states-and-flows.mdc +145 -0
  127. package/skills/hatch3r-a11y-audit/SKILL.md +14 -0
  128. package/skills/hatch3r-agent-customize/SKILL.md +10 -0
  129. package/skills/hatch3r-ai-feature/SKILL.md +136 -0
  130. package/skills/hatch3r-api-spec/SKILL.md +73 -0
  131. package/skills/hatch3r-architecture-review/SKILL.md +14 -0
  132. package/skills/hatch3r-bug-fix/SKILL.md +5 -0
  133. package/skills/hatch3r-ci-pipeline/SKILL.md +14 -0
  134. package/skills/hatch3r-cli-aichat/SKILL.md +84 -0
  135. package/skills/hatch3r-cli-ast-grep/SKILL.md +85 -0
  136. package/skills/hatch3r-cli-az-devops/SKILL.md +89 -0
  137. package/skills/hatch3r-cli-bat/SKILL.md +85 -0
  138. package/skills/hatch3r-cli-comby/SKILL.md +85 -0
  139. package/skills/hatch3r-cli-csvkit/SKILL.md +84 -0
  140. package/skills/hatch3r-cli-delta/SKILL.md +86 -0
  141. package/skills/hatch3r-cli-difftastic/SKILL.md +84 -0
  142. package/skills/hatch3r-cli-docker/SKILL.md +89 -0
  143. package/skills/hatch3r-cli-duckdb/SKILL.md +84 -0
  144. package/skills/hatch3r-cli-fd/SKILL.md +85 -0
  145. package/skills/hatch3r-cli-fzf/SKILL.md +84 -0
  146. package/skills/hatch3r-cli-gh/SKILL.md +90 -0
  147. package/skills/hatch3r-cli-glab/SKILL.md +89 -0
  148. package/skills/hatch3r-cli-jq/SKILL.md +89 -0
  149. package/skills/hatch3r-cli-lazygit/SKILL.md +78 -0
  150. package/skills/hatch3r-cli-llm/SKILL.md +84 -0
  151. package/skills/hatch3r-cli-miller/SKILL.md +84 -0
  152. package/skills/hatch3r-cli-mods/SKILL.md +84 -0
  153. package/skills/hatch3r-cli-overview/SKILL.md +60 -0
  154. package/skills/hatch3r-cli-playwright/SKILL.md +89 -0
  155. package/skills/hatch3r-cli-podman/SKILL.md +84 -0
  156. package/skills/hatch3r-cli-qsv/SKILL.md +91 -0
  157. package/skills/hatch3r-cli-ripgrep/SKILL.md +85 -0
  158. package/skills/hatch3r-cli-rtk/SKILL.md +91 -0
  159. package/skills/hatch3r-cli-sd/SKILL.md +85 -0
  160. package/skills/hatch3r-cli-stagehand/SKILL.md +111 -0
  161. package/skills/hatch3r-cli-taplo/SKILL.md +84 -0
  162. package/skills/hatch3r-cli-yq/SKILL.md +85 -0
  163. package/skills/hatch3r-cli-zstd/SKILL.md +85 -0
  164. package/skills/hatch3r-command-customize/SKILL.md +10 -0
  165. package/skills/hatch3r-context-health/SKILL.md +14 -0
  166. package/skills/hatch3r-cost-tracking/SKILL.md +14 -0
  167. package/skills/hatch3r-customize/SKILL.md +17 -0
  168. package/skills/hatch3r-dep-audit/SKILL.md +14 -0
  169. package/skills/hatch3r-design-system-detect/SKILL.md +164 -0
  170. package/skills/hatch3r-feature/SKILL.md +2 -0
  171. package/skills/hatch3r-gh-agentic-workflows/SKILL.md +13 -0
  172. package/skills/hatch3r-handoff-prepare/SKILL.md +160 -0
  173. package/skills/hatch3r-handoff-resume/SKILL.md +171 -0
  174. package/skills/hatch3r-incident-response/SKILL.md +14 -0
  175. package/skills/hatch3r-issue-workflow/SKILL.md +5 -0
  176. package/skills/hatch3r-logical-refactor/SKILL.md +14 -0
  177. package/skills/hatch3r-migration/SKILL.md +14 -0
  178. package/skills/hatch3r-observability-verify/SKILL.md +134 -0
  179. package/skills/hatch3r-perf-audit/SKILL.md +14 -0
  180. package/skills/hatch3r-pr-creation/SKILL.md +14 -0
  181. package/skills/hatch3r-qa-validation/SKILL.md +18 -0
  182. package/skills/hatch3r-recipe/SKILL.md +14 -0
  183. package/skills/hatch3r-refactor/SKILL.md +14 -0
  184. package/skills/hatch3r-release/SKILL.md +14 -0
  185. package/skills/hatch3r-reliability-verify/SKILL.md +146 -0
  186. package/skills/hatch3r-rule-customize/SKILL.md +10 -0
  187. package/skills/hatch3r-skill-customize/SKILL.md +10 -0
  188. package/skills/hatch3r-ui-ux-verify/SKILL.md +138 -0
  189. package/skills/hatch3r-visual-refactor/SKILL.md +15 -1
@@ -1,156 +1,14 @@
1
1
  ---
2
- description: Extended tracing reference -- AI agent instrumentation, tool call audit trails, LLM request tracing, and correlation ID patterns
3
- globs: ["**/*trac*", "**/*span*", "**/*telemetry*", "**/*otel*", "**/*agent*", "**/observability/**"]
2
+ description: "[Deprecated] AI agent tracing detail rule -- consolidated into hatch3r-observability-tracing's AI Agent Instrumentation section"
3
+ globs: ["**/*trac*", "**/*span*", "**/*telemetry*", "**/*otel*", "**/*agent*", "**/observability/**", "**/routes/**", "**/handlers/**", "**/services/**", "**/api/**", "**/middleware/**", "**/controllers/**", "**/lib/**"]
4
4
  alwaysApply: false
5
5
  ---
6
- # Observability -- Tracing Extended Reference
6
+ # Observability -- Tracing Extended Reference (Deprecated Redirect)
7
7
 
8
- On-demand companion to `hatch3r-observability-tracing`. Load when instrumenting AI agent systems, implementing tool call audit trails, or setting up correlation IDs for multi-agent workflows.
8
+ This rule has been merged into `hatch3r-observability-tracing`. Load that rule for AI agent instrumentation, tool call spans, LLM request/response tracing, tool call audit trails, and correlation ID patterns.
9
9
 
10
- ## GenAI Span Attributes
10
+ - See `hatch3r-observability-tracing` § "AI Agent Instrumentation" for: GenAI span attributes, agent invocation spans, tool call spans, LLM request/response tracing, tool call audit trail, correlation IDs for agent workflows.
11
11
 
12
- Use these attributes on all spans representing interactions with generative AI models:
12
+ <!-- DEPRECATED-CONTENT-REMOVED -->
13
13
 
14
- | Attribute | Type | Description | Example |
15
- |-----------|------|-------------|---------|
16
- | `gen_ai.system` | string | GenAI provider system name | `openai`, `anthropic`, `azure_openai` |
17
- | `gen_ai.request.model` | string | Model name as specified in the request | `gpt-4o`, `claude-sonnet-4-20250514` |
18
- | `gen_ai.response.model` | string | Model name as returned in the response | `gpt-4o-2024-08-06` |
19
- | `gen_ai.request.max_tokens` | int | Maximum tokens requested for generation | `4096` |
20
- | `gen_ai.request.temperature` | float | Temperature parameter | `0.7` |
21
- | `gen_ai.response.finish_reasons` | string[] | Reasons the model stopped generating | `["stop"]`, `["length"]` |
22
- | `gen_ai.usage.input_tokens` | int | Tokens in the input/prompt | `1250` |
23
- | `gen_ai.usage.output_tokens` | int | Tokens in the generated output | `530` |
24
-
25
- - Always set `gen_ai.system` and `gen_ai.request.model` on every GenAI span.
26
- - Record `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` from the API response for cost dashboards.
27
- - Use `gen_ai.response.finish_reasons` to detect truncated outputs (`length`) and trigger re-prompting.
28
-
29
- ## Agent Invocation Spans
30
-
31
- Instrument the full lifecycle of an agent invocation with a dedicated span. This span is the parent for all LLM calls, tool executions, and sub-agent delegations.
32
-
33
- - **Span name pattern:** `agent.{agent_name}.invoke`
34
- - **Required attributes:** `agent.id`, `agent.name`, `agent.parent_id`, `agent.task`, `agent.framework`
35
- - **Span events for state transitions:** `agent.planning`, `agent.tool_selection`, `agent.awaiting_human`, `agent.delegating`, `agent.completed`, `agent.error`
36
-
37
- ```typescript
38
- const agentSpan = tracer.startSpan('agent.code_reviewer.invoke', {
39
- attributes: {
40
- 'agent.id': invocationId,
41
- 'agent.name': 'code_reviewer',
42
- 'agent.parent_id': parentAgentId ?? '',
43
- 'agent.task': `review PR #${prNumber}`,
44
- 'agent.framework': 'custom',
45
- },
46
- });
47
- agentSpan.addEvent('agent.planning');
48
- // ... agent reasoning and tool calls happen as child spans ...
49
- agentSpan.addEvent('agent.completed');
50
- agentSpan.end();
51
- ```
52
-
53
- ## Tool Call Spans
54
-
55
- Every tool invocation by an agent creates a child span of the agent invocation span.
56
-
57
- - **Span name pattern:** `tool.{tool_name}.execute`
58
- - **Required attributes:** `tool.name`, `tool.input_hash` (SHA-256), `tool.output_status`, `tool.duration_ms`, `tool.parameters_count`
59
- - Tool spans must be children of the invoking agent span. Set span status to `ERROR` when `tool.output_status` is `error` or `timeout`.
60
- - For tools performing I/O, create nested child spans using appropriate semantic conventions (`http.*`, `db.*`).
61
-
62
- ```typescript
63
- const toolSpan = tracer.startSpan(
64
- 'tool.git_diff.execute',
65
- { attributes: { 'tool.name': 'git_diff' } },
66
- trace.setSpan(context.active(), agentSpan),
67
- );
68
- try {
69
- const result = await tools.gitDiff(params);
70
- toolSpan.setAttributes({
71
- 'tool.output_status': 'success',
72
- 'tool.duration_ms': performance.now() - startTime,
73
- 'tool.input_hash': hashInput(params),
74
- });
75
- } catch (err) {
76
- toolSpan.setAttributes({ 'tool.output_status': 'error' });
77
- toolSpan.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
78
- toolSpan.recordException(err);
79
- throw err;
80
- } finally {
81
- toolSpan.end();
82
- }
83
- ```
84
-
85
- ## LLM Request/Response Tracing
86
-
87
- - **Span name pattern:** `gen_ai.{operation}` (e.g., `gen_ai.chat`, `gen_ai.completion`)
88
- - **Token tracking:** Capture `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. Aggregate in metrics: Counter `gen_ai.tokens_total` with labels `{direction, model, agent_name}`, Histogram `gen_ai.request_duration_ms`.
89
- - **Model version tracking:** Record both `gen_ai.request.model` and `gen_ai.response.model` for drift detection.
90
- - **Retry spans:** Each retry attempt is a separate child span. Set `gen_ai.request.retries` on the final span. Record `http.response.status_code` on failed spans (429 vs 500+).
91
- - Never log raw prompt content or full model responses as span attributes. Use token counts for cost tracking and correlated logs for prompt debugging in non-production environments.
92
- - Sample GenAI spans at 50-100% in production (higher than general spans) because each call is expensive and low volume.
93
-
94
- ## Tool Call Audit Trail
95
-
96
- Maintain a structured audit log for every tool invocation in agentic workflows, separate from tracing spans.
97
-
98
- | Field | Type | Description |
99
- |-------|------|-------------|
100
- | `tool.name` | string | Name of the tool invoked |
101
- | `tool.input_hash` | string | SHA-256 hash of tool input (never log raw input) |
102
- | `tool.output_status` | string | `success`, `error`, `timeout`, or `denied` |
103
- | `tool.duration_ms` | float | Execution time in milliseconds |
104
- | `agent.id` | string | ID of the invoking agent |
105
- | `agent.name` | string | Human-readable agent name |
106
- | `correlation.id` | string | Trace correlation ID |
107
- | `timestamp` | string | ISO 8601 timestamp |
108
- | `session.id` | string | Session identifier |
109
-
110
- - Log tool invocations at `info` level, failures at `error` level with `error.type` and `error.message`.
111
- - Aggregate tool call counts per agent per session for anomaly detection.
112
- - Retain audit logs for a minimum of 90 days.
113
-
114
- ## Correlation IDs for Agent Workflows
115
-
116
- - Use UUIDv4 with workflow-type prefix: `{workflow-type}-{uuid}` (e.g., `agent-run-550e8400-...`).
117
- - Generate at the workflow entry point. Propagate to all sub-agents and tool calls.
118
- - Every log entry, span, and metric must include `correlation.id`.
119
- - Cross-process: propagate via `X-Correlation-ID` header alongside W3C Trace Context.
120
- - Use OpenTelemetry `SpanLink` for cross-workflow references (e.g., agent run triggered by CI event).
121
-
122
- ```typescript
123
- import { randomUUID } from 'node:crypto';
124
- import { context, trace, SpanStatusCode } from '@opentelemetry/api';
125
-
126
- function generateCorrelationId(workflowType: string): string {
127
- return `${workflowType}-${randomUUID()}`;
128
- }
129
-
130
- async function runAgentWorkflow(task: string): Promise<void> {
131
- const correlationId = generateCorrelationId('agent-run');
132
- const tracer = trace.getTracer('agent-orchestrator');
133
- const rootSpan = tracer.startSpan('agent.orchestrator.invoke', {
134
- attributes: {
135
- 'correlation.id': correlationId,
136
- 'agent.name': 'orchestrator',
137
- 'agent.task': task,
138
- },
139
- });
140
- try {
141
- await context.with(trace.setSpan(context.active(), rootSpan), async () => {
142
- await delegateToSubAgent('code_reviewer', {
143
- correlationId,
144
- parentSpanId: rootSpan.spanContext().spanId,
145
- task: 'review changes',
146
- });
147
- });
148
- } catch (err) {
149
- rootSpan.setStatus({ code: SpanStatusCode.ERROR, message: (err as Error).message });
150
- rootSpan.recordException(err as Error);
151
- throw err;
152
- } finally {
153
- rootSpan.end();
154
- }
155
- }
156
- ```
14
+ The full content has been migrated to `hatch3r-observability-tracing`.
@@ -1,16 +1,16 @@
1
1
  ---
2
2
  id: hatch3r-observability-tracing
3
3
  type: rule
4
- description: Distributed tracing and OpenTelemetry core conventions for the project
4
+ description: Distributed tracing, OpenTelemetry conventions, and AI agent instrumentation for the project
5
5
  scope: conditional
6
- globs: "**/*trac*,**/*span*,**/*telemetry*,**/*otel*,**/observability/**"
6
+ globs: "**/*trac*,**/*span*,**/*telemetry*,**/*otel*,**/*agent*,**/observability/**,**/routes/**,**/handlers/**,**/services/**,**/api/**,**/middleware/**,**/controllers/**,**/lib/**"
7
7
  tags: [devops]
8
8
  quality_charter: agents/shared/quality-charter.md
9
9
  cache_friendly: true
10
10
  ---
11
11
  # Observability -- Distributed Tracing & OpenTelemetry
12
12
 
13
- Core distributed tracing and OpenTelemetry conventions. For structured logging see `hatch3r-observability-logging`. For metrics, SLOs, alerting, and dashboards see `hatch3r-observability-metrics`. For AI agent instrumentation, tool call audit trails, and correlation ID patterns see `hatch3r-observability-tracing-detail`.
13
+ Distributed tracing, OpenTelemetry semantic conventions, AI agent instrumentation, tool call audit trails, and correlation ID patterns. For structured logging see `hatch3r-observability-logging`. For metrics, SLOs, alerting, and dashboards see `hatch3r-observability-metrics`.
14
14
 
15
15
  ## Distributed Tracing
16
16
 
@@ -82,6 +82,154 @@ Every telemetry-producing service must declare resource attributes at startup:
82
82
  - Attribute values should be low-cardinality. Never use unbounded values (full URLs with query params, raw SQL) as attribute values.
83
83
  - Prefer semantic convention attributes over custom attributes. Prefix custom attributes with your project namespace (e.g., `myapp.feature.flag_key`).
84
84
 
85
- ### AI Agent Semantic Conventions (Summary)
86
-
87
- Follow the [OpenTelemetry GenAI Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/) for AI/LLM agent instrumentation. Key attributes: `gen_ai.system`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`. For full attribute tables, code examples, tool call audit trails, and correlation ID patterns, see `hatch3r-observability-tracing-detail`.
85
+ ## AI Agent Instrumentation
86
+
87
+ Follow the [OpenTelemetry GenAI Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/) for AI/LLM agent instrumentation.
88
+
89
+ ### GenAI Span Attributes
90
+
91
+ Use these attributes on all spans representing interactions with generative AI models:
92
+
93
+ | Attribute | Type | Description | Example |
94
+ |-----------|------|-------------|---------|
95
+ | `gen_ai.system` | string | GenAI provider system name | `openai`, `anthropic`, `azure_openai` |
96
+ | `gen_ai.request.model` | string | Model name as specified in the request | `gpt-4o`, `claude-sonnet-4-20250514` |
97
+ | `gen_ai.response.model` | string | Model name as returned in the response | `gpt-4o-2024-08-06` |
98
+ | `gen_ai.request.max_tokens` | int | Maximum tokens requested for generation | `4096` |
99
+ | `gen_ai.request.temperature` | float | Temperature parameter | `0.7` |
100
+ | `gen_ai.response.finish_reasons` | string[] | Reasons the model stopped generating | `["stop"]`, `["length"]` |
101
+ | `gen_ai.usage.input_tokens` | int | Tokens in the input/prompt | `1250` |
102
+ | `gen_ai.usage.output_tokens` | int | Tokens in the generated output | `530` |
103
+
104
+ - Always set `gen_ai.system` and `gen_ai.request.model` on every GenAI span.
105
+ - Record `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` from the API response for cost dashboards.
106
+ - Use `gen_ai.response.finish_reasons` to detect truncated outputs (`length`) and trigger re-prompting.
107
+
108
+ ### Agent Invocation Spans
109
+
110
+ Instrument the full lifecycle of an agent invocation with a dedicated span. This span is the parent for all LLM calls, tool executions, and sub-agent delegations.
111
+
112
+ - **Span name pattern:** `agent.{agent_name}.invoke`
113
+ - **Required attributes:** `agent.id`, `agent.name`, `agent.parent_id`, `agent.task`, `agent.framework`
114
+ - **Span events for state transitions:** `agent.planning`, `agent.tool_selection`, `agent.awaiting_human`, `agent.delegating`, `agent.completed`, `agent.error`
115
+
116
+ ```typescript
117
+ const agentSpan = tracer.startSpan('agent.code_reviewer.invoke', {
118
+ attributes: {
119
+ 'agent.id': invocationId,
120
+ 'agent.name': 'code_reviewer',
121
+ 'agent.parent_id': parentAgentId ?? '',
122
+ 'agent.task': `review PR #${prNumber}`,
123
+ 'agent.framework': 'custom',
124
+ },
125
+ });
126
+ agentSpan.addEvent('agent.planning');
127
+ // ... agent reasoning and tool calls happen as child spans ...
128
+ agentSpan.addEvent('agent.completed');
129
+ agentSpan.end();
130
+ ```
131
+
132
+ ### Tool Call Spans
133
+
134
+ Every tool invocation by an agent creates a child span of the agent invocation span.
135
+
136
+ - **Span name pattern:** `tool.{tool_name}.execute`
137
+ - **Required attributes:** `tool.name`, `tool.input_hash` (SHA-256), `tool.output_status`, `tool.duration_ms`, `tool.parameters_count`
138
+ - Tool spans must be children of the invoking agent span. Set span status to `ERROR` when `tool.output_status` is `error` or `timeout`.
139
+ - For tools performing I/O, create nested child spans using appropriate semantic conventions (`http.*`, `db.*`).
140
+
141
+ ```typescript
142
+ const toolSpan = tracer.startSpan(
143
+ 'tool.git_diff.execute',
144
+ { attributes: { 'tool.name': 'git_diff' } },
145
+ trace.setSpan(context.active(), agentSpan),
146
+ );
147
+ try {
148
+ const result = await tools.gitDiff(params);
149
+ toolSpan.setAttributes({
150
+ 'tool.output_status': 'success',
151
+ 'tool.duration_ms': performance.now() - startTime,
152
+ 'tool.input_hash': hashInput(params),
153
+ });
154
+ } catch (err) {
155
+ toolSpan.setAttributes({ 'tool.output_status': 'error' });
156
+ toolSpan.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
157
+ toolSpan.recordException(err);
158
+ throw err;
159
+ } finally {
160
+ toolSpan.end();
161
+ }
162
+ ```
163
+
164
+ ### LLM Request/Response Tracing
165
+
166
+ - **Span name pattern:** `gen_ai.{operation}` (e.g., `gen_ai.chat`, `gen_ai.completion`)
167
+ - **Token tracking:** Capture `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. Aggregate in metrics: Counter `gen_ai.tokens_total` with labels `{direction, model, agent_name}`, Histogram `gen_ai.request_duration_ms`.
168
+ - **Model version tracking:** Record both `gen_ai.request.model` and `gen_ai.response.model` for drift detection.
169
+ - **Retry spans:** Each retry attempt is a separate child span. Set `gen_ai.request.retries` on the final span. Record `http.response.status_code` on failed spans (429 vs 500+).
170
+ - Never log raw prompt content or full model responses as span attributes. Use token counts for cost tracking and correlated logs for prompt debugging in non-production environments.
171
+ - Sample GenAI spans at 50-100% in production (higher than general spans) because each call is expensive and low volume.
172
+
173
+ ### Tool Call Audit Trail
174
+
175
+ Maintain a structured audit log for every tool invocation in agentic workflows, separate from tracing spans.
176
+
177
+ | Field | Type | Description |
178
+ |-------|------|-------------|
179
+ | `tool.name` | string | Name of the tool invoked |
180
+ | `tool.input_hash` | string | SHA-256 hash of tool input (never log raw input) |
181
+ | `tool.output_status` | string | `success`, `error`, `timeout`, or `denied` |
182
+ | `tool.duration_ms` | float | Execution time in milliseconds |
183
+ | `agent.id` | string | ID of the invoking agent |
184
+ | `agent.name` | string | Human-readable agent name |
185
+ | `correlation.id` | string | Trace correlation ID |
186
+ | `timestamp` | string | ISO 8601 timestamp |
187
+ | `session.id` | string | Session identifier |
188
+
189
+ - Log tool invocations at `info` level, failures at `error` level with `error.type` and `error.message`.
190
+ - Aggregate tool call counts per agent per session for anomaly detection.
191
+ - Retain audit logs for a minimum of 90 days.
192
+
193
+ ### Correlation IDs for Agent Workflows
194
+
195
+ - Use UUIDv4 with workflow-type prefix: `{workflow-type}-{uuid}` (e.g., `agent-run-550e8400-...`).
196
+ - Generate at the workflow entry point. Propagate to all sub-agents and tool calls.
197
+ - Every log entry, span, and metric must include `correlation.id`.
198
+ - Cross-process: propagate via `X-Correlation-ID` header alongside W3C Trace Context.
199
+ - Use OpenTelemetry `SpanLink` for cross-workflow references (e.g., agent run triggered by CI event).
200
+
201
+ ```typescript
202
+ import { randomUUID } from 'node:crypto';
203
+ import { context, trace, SpanStatusCode } from '@opentelemetry/api';
204
+
205
+ function generateCorrelationId(workflowType: string): string {
206
+ return `${workflowType}-${randomUUID()}`;
207
+ }
208
+
209
+ async function runAgentWorkflow(task: string): Promise<void> {
210
+ const correlationId = generateCorrelationId('agent-run');
211
+ const tracer = trace.getTracer('agent-orchestrator');
212
+ const rootSpan = tracer.startSpan('agent.orchestrator.invoke', {
213
+ attributes: {
214
+ 'correlation.id': correlationId,
215
+ 'agent.name': 'orchestrator',
216
+ 'agent.task': task,
217
+ },
218
+ });
219
+ try {
220
+ await context.with(trace.setSpan(context.active(), rootSpan), async () => {
221
+ await delegateToSubAgent('code_reviewer', {
222
+ correlationId,
223
+ parentSpanId: rootSpan.spanContext().spanId,
224
+ task: 'review changes',
225
+ });
226
+ });
227
+ } catch (err) {
228
+ rootSpan.setStatus({ code: SpanStatusCode.ERROR, message: (err as Error).message });
229
+ rootSpan.recordException(err as Error);
230
+ throw err;
231
+ } finally {
232
+ rootSpan.end();
233
+ }
234
+ }
235
+ ```
@@ -1,11 +1,11 @@
1
1
  ---
2
- description: Distributed tracing and OpenTelemetry core conventions for the project
3
- globs: ["**/*trac*", "**/*span*", "**/*telemetry*", "**/*otel*", "**/observability/**"]
2
+ description: Distributed tracing, OpenTelemetry conventions, and AI agent instrumentation for the project
3
+ globs: ["**/*trac*", "**/*span*", "**/*telemetry*", "**/*otel*", "**/*agent*", "**/observability/**", "**/routes/**", "**/handlers/**", "**/services/**", "**/api/**", "**/middleware/**", "**/controllers/**", "**/lib/**"]
4
4
  alwaysApply: false
5
5
  ---
6
6
  # Observability -- Distributed Tracing & OpenTelemetry
7
7
 
8
- Core distributed tracing and OpenTelemetry conventions. For structured logging see `hatch3r-observability-logging`. For metrics, SLOs, alerting, and dashboards see `hatch3r-observability-metrics`. For AI agent instrumentation, tool call audit trails, and correlation ID patterns see `hatch3r-observability-tracing-detail`.
8
+ Distributed tracing, OpenTelemetry semantic conventions, AI agent instrumentation, tool call audit trails, and correlation ID patterns. For structured logging see `hatch3r-observability-logging`. For metrics, SLOs, alerting, and dashboards see `hatch3r-observability-metrics`.
9
9
 
10
10
  ## Distributed Tracing
11
11
 
@@ -77,6 +77,154 @@ Every telemetry-producing service must declare resource attributes at startup:
77
77
  - Attribute values should be low-cardinality. Never use unbounded values (full URLs with query params, raw SQL) as attribute values.
78
78
  - Prefer semantic convention attributes over custom attributes. Prefix custom attributes with your project namespace (e.g., `myapp.feature.flag_key`).
79
79
 
80
- ### AI Agent Semantic Conventions (Summary)
81
-
82
- Follow the [OpenTelemetry GenAI Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/) for AI/LLM agent instrumentation. Key attributes: `gen_ai.system`, `gen_ai.request.model`, `gen_ai.usage.input_tokens`, `gen_ai.usage.output_tokens`. For full attribute tables, code examples, tool call audit trails, and correlation ID patterns, see `hatch3r-observability-tracing-detail`.
80
+ ## AI Agent Instrumentation
81
+
82
+ Follow the [OpenTelemetry GenAI Semantic Conventions](https://opentelemetry.io/docs/specs/semconv/gen-ai/) for AI/LLM agent instrumentation.
83
+
84
+ ### GenAI Span Attributes
85
+
86
+ Use these attributes on all spans representing interactions with generative AI models:
87
+
88
+ | Attribute | Type | Description | Example |
89
+ |-----------|------|-------------|---------|
90
+ | `gen_ai.system` | string | GenAI provider system name | `openai`, `anthropic`, `azure_openai` |
91
+ | `gen_ai.request.model` | string | Model name as specified in the request | `gpt-4o`, `claude-sonnet-4-20250514` |
92
+ | `gen_ai.response.model` | string | Model name as returned in the response | `gpt-4o-2024-08-06` |
93
+ | `gen_ai.request.max_tokens` | int | Maximum tokens requested for generation | `4096` |
94
+ | `gen_ai.request.temperature` | float | Temperature parameter | `0.7` |
95
+ | `gen_ai.response.finish_reasons` | string[] | Reasons the model stopped generating | `["stop"]`, `["length"]` |
96
+ | `gen_ai.usage.input_tokens` | int | Tokens in the input/prompt | `1250` |
97
+ | `gen_ai.usage.output_tokens` | int | Tokens in the generated output | `530` |
98
+
99
+ - Always set `gen_ai.system` and `gen_ai.request.model` on every GenAI span.
100
+ - Record `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens` from the API response for cost dashboards.
101
+ - Use `gen_ai.response.finish_reasons` to detect truncated outputs (`length`) and trigger re-prompting.
102
+
103
+ ### Agent Invocation Spans
104
+
105
+ Instrument the full lifecycle of an agent invocation with a dedicated span. This span is the parent for all LLM calls, tool executions, and sub-agent delegations.
106
+
107
+ - **Span name pattern:** `agent.{agent_name}.invoke`
108
+ - **Required attributes:** `agent.id`, `agent.name`, `agent.parent_id`, `agent.task`, `agent.framework`
109
+ - **Span events for state transitions:** `agent.planning`, `agent.tool_selection`, `agent.awaiting_human`, `agent.delegating`, `agent.completed`, `agent.error`
110
+
111
+ ```typescript
112
+ const agentSpan = tracer.startSpan('agent.code_reviewer.invoke', {
113
+ attributes: {
114
+ 'agent.id': invocationId,
115
+ 'agent.name': 'code_reviewer',
116
+ 'agent.parent_id': parentAgentId ?? '',
117
+ 'agent.task': `review PR #${prNumber}`,
118
+ 'agent.framework': 'custom',
119
+ },
120
+ });
121
+ agentSpan.addEvent('agent.planning');
122
+ // ... agent reasoning and tool calls happen as child spans ...
123
+ agentSpan.addEvent('agent.completed');
124
+ agentSpan.end();
125
+ ```
126
+
127
+ ### Tool Call Spans
128
+
129
+ Every tool invocation by an agent creates a child span of the agent invocation span.
130
+
131
+ - **Span name pattern:** `tool.{tool_name}.execute`
132
+ - **Required attributes:** `tool.name`, `tool.input_hash` (SHA-256), `tool.output_status`, `tool.duration_ms`, `tool.parameters_count`
133
+ - Tool spans must be children of the invoking agent span. Set span status to `ERROR` when `tool.output_status` is `error` or `timeout`.
134
+ - For tools performing I/O, create nested child spans using appropriate semantic conventions (`http.*`, `db.*`).
135
+
136
+ ```typescript
137
+ const toolSpan = tracer.startSpan(
138
+ 'tool.git_diff.execute',
139
+ { attributes: { 'tool.name': 'git_diff' } },
140
+ trace.setSpan(context.active(), agentSpan),
141
+ );
142
+ try {
143
+ const result = await tools.gitDiff(params);
144
+ toolSpan.setAttributes({
145
+ 'tool.output_status': 'success',
146
+ 'tool.duration_ms': performance.now() - startTime,
147
+ 'tool.input_hash': hashInput(params),
148
+ });
149
+ } catch (err) {
150
+ toolSpan.setAttributes({ 'tool.output_status': 'error' });
151
+ toolSpan.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
152
+ toolSpan.recordException(err);
153
+ throw err;
154
+ } finally {
155
+ toolSpan.end();
156
+ }
157
+ ```
158
+
159
+ ### LLM Request/Response Tracing
160
+
161
+ - **Span name pattern:** `gen_ai.{operation}` (e.g., `gen_ai.chat`, `gen_ai.completion`)
162
+ - **Token tracking:** Capture `gen_ai.usage.input_tokens` and `gen_ai.usage.output_tokens`. Aggregate in metrics: Counter `gen_ai.tokens_total` with labels `{direction, model, agent_name}`, Histogram `gen_ai.request_duration_ms`.
163
+ - **Model version tracking:** Record both `gen_ai.request.model` and `gen_ai.response.model` for drift detection.
164
+ - **Retry spans:** Each retry attempt is a separate child span. Set `gen_ai.request.retries` on the final span. Record `http.response.status_code` on failed spans (429 vs 500+).
165
+ - Never log raw prompt content or full model responses as span attributes. Use token counts for cost tracking and correlated logs for prompt debugging in non-production environments.
166
+ - Sample GenAI spans at 50-100% in production (higher than general spans) because each call is expensive and low volume.
167
+
168
+ ### Tool Call Audit Trail
169
+
170
+ Maintain a structured audit log for every tool invocation in agentic workflows, separate from tracing spans.
171
+
172
+ | Field | Type | Description |
173
+ |-------|------|-------------|
174
+ | `tool.name` | string | Name of the tool invoked |
175
+ | `tool.input_hash` | string | SHA-256 hash of tool input (never log raw input) |
176
+ | `tool.output_status` | string | `success`, `error`, `timeout`, or `denied` |
177
+ | `tool.duration_ms` | float | Execution time in milliseconds |
178
+ | `agent.id` | string | ID of the invoking agent |
179
+ | `agent.name` | string | Human-readable agent name |
180
+ | `correlation.id` | string | Trace correlation ID |
181
+ | `timestamp` | string | ISO 8601 timestamp |
182
+ | `session.id` | string | Session identifier |
183
+
184
+ - Log tool invocations at `info` level, failures at `error` level with `error.type` and `error.message`.
185
+ - Aggregate tool call counts per agent per session for anomaly detection.
186
+ - Retain audit logs for a minimum of 90 days.
187
+
188
+ ### Correlation IDs for Agent Workflows
189
+
190
+ - Use UUIDv4 with workflow-type prefix: `{workflow-type}-{uuid}` (e.g., `agent-run-550e8400-...`).
191
+ - Generate at the workflow entry point. Propagate to all sub-agents and tool calls.
192
+ - Every log entry, span, and metric must include `correlation.id`.
193
+ - Cross-process: propagate via `X-Correlation-ID` header alongside W3C Trace Context.
194
+ - Use OpenTelemetry `SpanLink` for cross-workflow references (e.g., agent run triggered by CI event).
195
+
196
+ ```typescript
197
+ import { randomUUID } from 'node:crypto';
198
+ import { context, trace, SpanStatusCode } from '@opentelemetry/api';
199
+
200
+ function generateCorrelationId(workflowType: string): string {
201
+ return `${workflowType}-${randomUUID()}`;
202
+ }
203
+
204
+ async function runAgentWorkflow(task: string): Promise<void> {
205
+ const correlationId = generateCorrelationId('agent-run');
206
+ const tracer = trace.getTracer('agent-orchestrator');
207
+ const rootSpan = tracer.startSpan('agent.orchestrator.invoke', {
208
+ attributes: {
209
+ 'correlation.id': correlationId,
210
+ 'agent.name': 'orchestrator',
211
+ 'agent.task': task,
212
+ },
213
+ });
214
+ try {
215
+ await context.with(trace.setSpan(context.active(), rootSpan), async () => {
216
+ await delegateToSubAgent('code_reviewer', {
217
+ correlationId,
218
+ parentSpanId: rootSpan.spanContext().spanId,
219
+ task: 'review changes',
220
+ });
221
+ });
222
+ } catch (err) {
223
+ rootSpan.setStatus({ code: SpanStatusCode.ERROR, message: (err as Error).message });
224
+ rootSpan.recordException(err as Error);
225
+ throw err;
226
+ } finally {
227
+ rootSpan.end();
228
+ }
229
+ }
230
+ ```
@@ -3,6 +3,7 @@ id: hatch3r-observability
3
3
  type: rule
4
4
  description: "[Deprecated] Observability conventions -- split into hatch3r-observability-logging, hatch3r-observability-metrics, and hatch3r-observability-tracing"
5
5
  scope: conditional
6
+ globs: "**/routes/**,**/handlers/**,**/services/**,**/api/**,**/middleware/**,**/controllers/**,**/lib/**,**/observability/**"
6
7
  tags: [devops]
7
8
  quality_charter: agents/shared/quality-charter.md
8
9
  deprecated: true
@@ -1,5 +1,6 @@
1
1
  ---
2
2
  description: "[Deprecated] Observability conventions -- split into hatch3r-observability-logging, hatch3r-observability-metrics, and hatch3r-observability-tracing"
3
+ globs: ["**/routes/**", "**/handlers/**", "**/services/**", "**/api/**", "**/middleware/**", "**/controllers/**", "**/lib/**", "**/observability/**"]
3
4
  alwaysApply: false
4
5
  ---
5
6
  # Observability (Deprecated Redirect)