robot_lab-audit 0.2.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.
- checksums.yaml +7 -0
- data/.envrc +3 -0
- data/.github/workflows/deploy-github-pages.yml +52 -0
- data/.loki +10 -0
- data/.quality/reek_baseline.txt +2 -0
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +37 -0
- data/CLAUDE.md +60 -0
- data/COMMITS.md +196 -0
- data/LICENSE.txt +21 -0
- data/README.md +141 -0
- data/Rakefile +132 -0
- data/docs/getting_started.md +129 -0
- data/docs/how_it_works.md +193 -0
- data/docs/index.md +44 -0
- data/docs/querying.md +126 -0
- data/examples/01_basic_usage.rb +294 -0
- data/examples/common.rb +54 -0
- data/lib/robot_lab/audit/event_log.rb +102 -0
- data/lib/robot_lab/audit/hook.rb +146 -0
- data/lib/robot_lab/audit/version.rb +7 -0
- data/lib/robot_lab/audit.rb +31 -0
- data/mkdocs.yml +117 -0
- data/sig/robot_lab/audit.rbs +6 -0
- metadata +96 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1172ca1cc991073953bedbf72f533175c7436852d201e6645ed65d75d7117807
|
|
4
|
+
data.tar.gz: 87aff3fc9ae887a2e774571305e07a6f95ae1837ce1145179cfd6862c90406a9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b377176b95d73963e9cda9bc83a985abaf863a0a8478d0c6ee82b67be49e012e28c77bfe5fba0ac6f6ab58dfea648b8182844bcb9797c93a8c4dab5c3e58ed16
|
|
7
|
+
data.tar.gz: 9b79363dba9c3d3cf7e5982cc097f9e429e89a0ec262e25af65b45a998d62b05449f10a0ae19a195bc566857fa7956e886c8d95db1565cb5b4d9620d684a2a17
|
data/.envrc
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: Deploy Documentation to GitHub Pages
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
- develop
|
|
7
|
+
paths:
|
|
8
|
+
- "docs/**"
|
|
9
|
+
- "mkdocs.yml"
|
|
10
|
+
- ".github/workflows/deploy-github-pages.yml"
|
|
11
|
+
workflow_dispatch:
|
|
12
|
+
|
|
13
|
+
permissions:
|
|
14
|
+
contents: write
|
|
15
|
+
pages: write
|
|
16
|
+
id-token: write
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
deploy:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
steps:
|
|
22
|
+
- name: Checkout code
|
|
23
|
+
uses: actions/checkout@v4
|
|
24
|
+
with:
|
|
25
|
+
fetch-depth: 0
|
|
26
|
+
|
|
27
|
+
- name: Setup Python
|
|
28
|
+
uses: actions/setup-python@v5
|
|
29
|
+
with:
|
|
30
|
+
python-version: 3.x
|
|
31
|
+
|
|
32
|
+
- name: Install dependencies
|
|
33
|
+
run: |
|
|
34
|
+
pip install mkdocs
|
|
35
|
+
pip install mkdocs-material
|
|
36
|
+
pip install mkdocs-macros-plugin
|
|
37
|
+
pip install mike
|
|
38
|
+
|
|
39
|
+
- name: Configure Git
|
|
40
|
+
run: |
|
|
41
|
+
git config --local user.email "action@github.com"
|
|
42
|
+
git config --local user.name "GitHub Action"
|
|
43
|
+
|
|
44
|
+
- name: Build MkDocs site
|
|
45
|
+
run: mkdocs build
|
|
46
|
+
|
|
47
|
+
- name: Deploy to GitHub Pages
|
|
48
|
+
uses: peaceiris/actions-gh-pages@v4
|
|
49
|
+
with:
|
|
50
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
51
|
+
publish_dir: ./site
|
|
52
|
+
keep_files: true
|
data/.loki
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# robot_lab-audit — SQLite-backed execution audit log via the Hook system.
|
|
3
|
+
|
|
4
|
+
import_up "repo_dev.loki"
|
|
5
|
+
|
|
6
|
+
class Tasks
|
|
7
|
+
@@gem_name ||= "robot_lab-audit".freeze
|
|
8
|
+
|
|
9
|
+
header "robot_lab-audit v#{gem_version} — execution audit log"
|
|
10
|
+
end
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
inherit_from: ../.rubocop-base.yml
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- `.loki` Asgard task file: `test`, `rubocop`, `rubocop_fix`, `flog`, `flay`, `quality`, `build`, `install`, `release`, and `console` tasks via the Asgard task runner
|
|
12
|
+
- `flay_check` Rake task: structural code duplication gate (mass threshold 50); integrated into the `quality` Rake task
|
|
13
|
+
- `flay`, `flog`, `rubocop`, and `racc` gems added to development dependencies (`rubocop` was previously absent; `racc` required explicitly for Ruby 4.0 which dropped it from default gems)
|
|
14
|
+
- `test_output.txt`, `flay_output.txt`, `flog_output.txt`, and `rubocop_output.txt` added to `.gitignore`
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- `test/test_helper.rb`: test output redirected to `test_output.txt` via `$stdout` reassignment; `TerminalSummaryReporter` prints a single PASS/FAIL summary line to the terminal
|
|
18
|
+
- `Rakefile`: `rubocop` and `rubocop_fix` tasks removed (now owned by Asgard); `flay_check` integrated into the `quality` gate
|
|
19
|
+
|
|
20
|
+
## [0.1.0] - 2026-05-28
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- `RobotLab::Audit::EventLog` — SQLite-backed append-only log with two tables:
|
|
25
|
+
`network_runs` (one row per `Network#run`) and `audit_events` (one row per robot
|
|
26
|
+
invocation or tool call). Query helpers: `network_runs`, `events_for(run_id)`,
|
|
27
|
+
`recent_errors`.
|
|
28
|
+
- `RobotLab::Audit::Hook` — `RobotLab::Hook` subclass that captures lifecycle events
|
|
29
|
+
via `before/after_network_run`, `before/after_run`, and `before/after_tool_call`.
|
|
30
|
+
Uses thread-local storage to correlate all events within a single network run under
|
|
31
|
+
one `run_id`. Records wall-clock timestamps and duration in milliseconds for each
|
|
32
|
+
event.
|
|
33
|
+
- `RobotLab::Audit.enable(db_path:)` — one-call setup that creates the `EventLog`,
|
|
34
|
+
assigns it to the hook, and registers the hook globally with `RobotLab.on`.
|
|
35
|
+
|
|
36
|
+
[Unreleased]: https://github.com/MadBomber/robot_lab-audit/compare/v0.1.0...HEAD
|
|
37
|
+
[0.1.0]: https://github.com/MadBomber/robot_lab-audit/releases/tag/v0.1.0
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## What This Gem Does
|
|
6
|
+
|
|
7
|
+
`robot_lab-audit` is a SQLite-backed execution audit log for RobotLab. It hooks into the `RobotLab::Hook` system to record every network run, robot invocation, and tool call with timestamps and duration — enabling post-mortem analysis without changing application code.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
bundle exec rake test # Run full test suite
|
|
13
|
+
ruby -Ilib:test test/<file> # Run a single test file
|
|
14
|
+
|
|
15
|
+
bin/console # IRB session with gem loaded
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Enabling
|
|
19
|
+
|
|
20
|
+
```ruby
|
|
21
|
+
require 'robot_lab'
|
|
22
|
+
require 'robot_lab/audit'
|
|
23
|
+
|
|
24
|
+
RobotLab::Audit.enable(db_path: "~/.robot_lab/audit.db")
|
|
25
|
+
# All subsequent network and robot runs are recorded automatically
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
`enable` is idempotent — it wires the hook globally once and is safe to call at boot.
|
|
29
|
+
|
|
30
|
+
## Architecture
|
|
31
|
+
|
|
32
|
+
All source lives under `lib/robot_lab/audit/`.
|
|
33
|
+
|
|
34
|
+
**`Audit`** (`audit.rb`) — Entry point module. `Audit.enable(db_path:)` creates the `EventLog` and registers the `Hook` via `RobotLab.on`. Requires `robot_lab` to be loaded first.
|
|
35
|
+
|
|
36
|
+
**`EventLog`** (`audit/event_log.rb`) — SQLite wrapper. Creates two tables on first open:
|
|
37
|
+
- `network_runs` — one row per `Network#run` call: `run_id`, `network_name`, `input`, `result`, `error_class`, `error_message`, `started_at`, `finished_at`, `duration_ms`
|
|
38
|
+
- `audit_events` — one row per robot run or tool call: same fields plus `event_type` (`"robot_run"` or `"tool_call"`), `robot_name`, `tool_name`
|
|
39
|
+
|
|
40
|
+
Public query methods: `network_runs(limit:)`, `events_for(run_id)`, `recent_errors(limit:)`.
|
|
41
|
+
|
|
42
|
+
**`Hook`** (`audit/hook.rb`) — Subclass of `RobotLab::Hook` with `namespace = :audit`. Uses `Thread.current` keyed locals to track `run_id` and `started_at` across the before/after pairs:
|
|
43
|
+
- `before_network_run` / `after_network_run` — writes the `network_runs` row
|
|
44
|
+
- `before_run` / `after_run` — writes a `"robot_run"` audit event
|
|
45
|
+
- `before_tool_call` / `after_tool_call` — writes a `"tool_call"` audit event
|
|
46
|
+
|
|
47
|
+
All timestamps are UTC ISO 8601 with millisecond precision.
|
|
48
|
+
|
|
49
|
+
## Key Constraints
|
|
50
|
+
|
|
51
|
+
- `robot_lab` must be loaded before `robot_lab/audit` — the Hook subclass requires `RobotLab::Hook` to exist.
|
|
52
|
+
- `EventLog` is not thread-safe by itself; SQLite handles concurrent writes via its own locking.
|
|
53
|
+
- `safe_json` on the hook silently falls back to `inspect` for non-serializable values — do not rely on JSON structure for complex tool arguments.
|
|
54
|
+
- Run IDs are UUIDs stored in `Thread.current` — not propagated across Fibers or Ractors.
|
|
55
|
+
|
|
56
|
+
## Testing
|
|
57
|
+
|
|
58
|
+
- Minitest with SimpleCov (branch coverage tracked, no minimum threshold enforced yet)
|
|
59
|
+
- Tests use `Tmpdir` for isolated SQLite databases — never write to a shared file in tests
|
|
60
|
+
- Coverage baseline: ~47% line / ~3% branch — test suite is thin relative to implementation
|
data/COMMITS.md
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
---
|
|
2
|
+
url: https://www.conventionalcommits.org/en/v1.0.0/
|
|
3
|
+
title: Conventional Commits
|
|
4
|
+
description: A specification for adding human and machine readable meaning to commit messages
|
|
5
|
+
access_date: 2025-07-31T20:51:29.000Z
|
|
6
|
+
current_date: 2025-07-31T20:51:29.601Z
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Conventional Commits
|
|
10
|
+
|
|
11
|
+
A specification for adding human and machine readable meaning to commit messages
|
|
12
|
+
|
|
13
|
+
Quick Summary Full Specification Contribute
|
|
14
|
+
|
|
15
|
+
# Conventional Commits 1.0.0
|
|
16
|
+
|
|
17
|
+
## Summary
|
|
18
|
+
|
|
19
|
+
The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.
|
|
20
|
+
|
|
21
|
+
The commit message should be structured as follows:
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
<type>[optional scope]: <description>
|
|
27
|
+
|
|
28
|
+
[optional body]
|
|
29
|
+
|
|
30
|
+
[optional footer(s)]
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
The commit contains the following structural elements, to communicate intent to the consumers of your library:
|
|
37
|
+
|
|
38
|
+
1. **fix:** a commit of the _type_ `fix` patches a bug in your codebase (this correlates with `PATCH` in Semantic Versioning).
|
|
39
|
+
2. **feat:** a commit of the _type_ `feat` introduces a new feature to the codebase (this correlates with `MINOR` in Semantic Versioning).
|
|
40
|
+
3. **BREAKING CHANGE:** a commit that has a footer `BREAKING CHANGE:`, or appends a `!` after the type/scope, introduces a breaking API change (correlating with `MAJOR` in Semantic Versioning). A BREAKING CHANGE can be part of commits of any _type_.
|
|
41
|
+
4. _types_ other than `fix:` and `feat:` are allowed, for example @commitlint/config-conventional (based on the Angular convention) recommends `build:`, `chore:`,`ci:`, `docs:`, `style:`, `refactor:`, `perf:`, `test:`, and others.
|
|
42
|
+
5. _footers_ other than `BREAKING CHANGE: <description>` may be provided and follow a convention similar to git trailer format.
|
|
43
|
+
|
|
44
|
+
Additional types are not mandated by the Conventional Commits specification, and have no implicit effect in Semantic Versioning (unless they include a BREAKING CHANGE). A scope may be provided to a commit’s type, to provide additional contextual information and is contained within parenthesis, e.g., `feat(parser): add ability to parse arrays`.
|
|
45
|
+
|
|
46
|
+
## Examples
|
|
47
|
+
|
|
48
|
+
### Commit message with description and breaking change footer
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
feat: allow provided config object to extend other configs
|
|
52
|
+
|
|
53
|
+
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Commit message with `!` to draw attention to breaking change
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
feat!: send an email to the customer when a product is shipped
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Commit message with scope and `!` to draw attention to breaking change
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
feat(api)!: send an email to the customer when a product is shipped
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Commit message with both `!` and BREAKING CHANGE footer
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
chore!: drop support for Node 6
|
|
75
|
+
|
|
76
|
+
BREAKING CHANGE: use JavaScript features not available in Node 6.
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Commit message with no body
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
docs: correct spelling of CHANGELOG
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Commit message with scope
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
feat(lang): add Polish language
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Commit message with multi-paragraph body and multiple footers
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
fix: prevent racing of requests
|
|
98
|
+
|
|
99
|
+
Introduce a request id and a reference to latest request. Dismiss
|
|
100
|
+
incoming responses other than from latest request.
|
|
101
|
+
|
|
102
|
+
Remove timeouts which were used to mitigate the racing issue but are
|
|
103
|
+
obsolete now.
|
|
104
|
+
|
|
105
|
+
Reviewed-by: Z
|
|
106
|
+
Refs: #123
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Specification
|
|
111
|
+
|
|
112
|
+
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.
|
|
113
|
+
|
|
114
|
+
1. Commits MUST be prefixed with a type, which consists of a noun, `feat`, `fix`, etc., followed by the OPTIONAL scope, OPTIONAL `!`, and REQUIRED terminal colon and space.
|
|
115
|
+
2. The type `feat` MUST be used when a commit adds a new feature to your application or library.
|
|
116
|
+
3. The type `fix` MUST be used when a commit represents a bug fix for your application.
|
|
117
|
+
4. A scope MAY be provided after a type. A scope MUST consist of a noun describing a section of the codebase surrounded by parenthesis, e.g., `fix(parser):`
|
|
118
|
+
5. A description MUST immediately follow the colon and space after the type/scope prefix. The description is a short summary of the code changes, e.g., _fix: array parsing issue when multiple spaces were contained in string_.
|
|
119
|
+
6. A longer commit body MAY be provided after the short description, providing additional contextual information about the code changes. The body MUST begin one blank line after the description.
|
|
120
|
+
7. A commit body is free-form and MAY consist of any number of newline separated paragraphs.
|
|
121
|
+
8. One or more footers MAY be provided one blank line after the body. Each footer MUST consist of a word token, followed by either a `:<space>` or `<space>#` separator, followed by a string value (this is inspired by the git trailer convention).
|
|
122
|
+
9. A footer’s token MUST use `-` in place of whitespace characters, e.g., `Acked-by` (this helps differentiate the footer section from a multi-paragraph body). An exception is made for `BREAKING CHANGE`, which MAY also be used as a token.
|
|
123
|
+
10. A footer’s value MAY contain spaces and newlines, and parsing MUST terminate when the next valid footer token/separator pair is observed.
|
|
124
|
+
11. Breaking changes MUST be indicated in the type/scope prefix of a commit, or as an entry in the footer.
|
|
125
|
+
12. If included as a footer, a breaking change MUST consist of the uppercase text BREAKING CHANGE, followed by a colon, space, and description, e.g.,_BREAKING CHANGE: environment variables now take precedence over config files_.
|
|
126
|
+
13. If included in the type/scope prefix, breaking changes MUST be indicated by a`!` immediately before the `:`. If `!` is used, `BREAKING CHANGE:` MAY be omitted from the footer section, and the commit description SHALL be used to describe the breaking change.
|
|
127
|
+
14. Types other than `feat` and `fix` MAY be used in your commit messages, e.g., _docs: update ref docs._
|
|
128
|
+
15. The units of information that make up Conventional Commits MUST NOT be treated as case sensitive by implementors, with the exception of BREAKING CHANGE which MUST be uppercase.
|
|
129
|
+
16. BREAKING-CHANGE MUST be synonymous with BREAKING CHANGE, when used as a token in a footer.
|
|
130
|
+
|
|
131
|
+
## Why Use Conventional Commits
|
|
132
|
+
|
|
133
|
+
* Automatically generating CHANGELOGs.
|
|
134
|
+
* Automatically determining a semantic version bump (based on the types of commits landed).
|
|
135
|
+
* Communicating the nature of changes to teammates, the public, and other stakeholders.
|
|
136
|
+
* Triggering build and publish processes.
|
|
137
|
+
* Making it easier for people to contribute to your projects, by allowing them to explore a more structured commit history.
|
|
138
|
+
|
|
139
|
+
## FAQ
|
|
140
|
+
|
|
141
|
+
### How should I deal with commit messages in the initial development phase?
|
|
142
|
+
|
|
143
|
+
We recommend that you proceed as if you’ve already released the product. Typically _somebody_, even if it’s your fellow software developers, is using your software. They’ll want to know what’s fixed, what breaks etc.
|
|
144
|
+
|
|
145
|
+
### Are the types in the commit title uppercase or lowercase?
|
|
146
|
+
|
|
147
|
+
Any casing may be used, but it’s best to be consistent.
|
|
148
|
+
|
|
149
|
+
### What do I do if the commit conforms to more than one of the commit types?
|
|
150
|
+
|
|
151
|
+
Go back and make multiple commits whenever possible. Part of the benefit of Conventional Commits is its ability to drive us to make more organized commits and PRs.
|
|
152
|
+
|
|
153
|
+
### Doesn’t this discourage rapid development and fast iteration?
|
|
154
|
+
|
|
155
|
+
It discourages moving fast in a disorganized way. It helps you be able to move fast long term across multiple projects with varied contributors.
|
|
156
|
+
|
|
157
|
+
### Might Conventional Commits lead developers to limit the type of commits they make because they’ll be thinking in the types provided?
|
|
158
|
+
|
|
159
|
+
Conventional Commits encourages us to make more of certain types of commits such as fixes. Other than that, the flexibility of Conventional Commits allows your team to come up with their own types and change those types over time.
|
|
160
|
+
|
|
161
|
+
### How does this relate to SemVer?
|
|
162
|
+
|
|
163
|
+
`fix` type commits should be translated to `PATCH` releases. `feat` type commits should be translated to `MINOR` releases. Commits with `BREAKING CHANGE` in the commits, regardless of type, should be translated to `MAJOR` releases.
|
|
164
|
+
|
|
165
|
+
### How should I version my extensions to the Conventional Commits Specification, e.g. `@jameswomack/conventional-commit-spec`?
|
|
166
|
+
|
|
167
|
+
We recommend using SemVer to release your own extensions to this specification (and encourage you to make these extensions!)
|
|
168
|
+
|
|
169
|
+
### What do I do if I accidentally use the wrong commit type?
|
|
170
|
+
|
|
171
|
+
#### When you used a type that’s of the spec but not the correct type, e.g. `fix` instead of `feat`
|
|
172
|
+
|
|
173
|
+
Prior to merging or releasing the mistake, we recommend using `git rebase -i` to edit the commit history. After release, the cleanup will be different according to what tools and processes you use.
|
|
174
|
+
|
|
175
|
+
#### When you used a type _not_ of the spec, e.g. `feet` instead of `feat`
|
|
176
|
+
|
|
177
|
+
In a worst case scenario, it’s not the end of the world if a commit lands that does not meet the Conventional Commits specification. It simply means that commit will be missed by tools that are based on the spec.
|
|
178
|
+
|
|
179
|
+
### Do all my contributors need to use the Conventional Commits specification?
|
|
180
|
+
|
|
181
|
+
No! If you use a squash based workflow on Git lead maintainers can clean up the commit messages as they’re merged—adding no workload to casual committers. A common workflow for this is to have your git system automatically squash commits from a pull request and present a form for the lead maintainer to enter the proper git commit message for the merge.
|
|
182
|
+
|
|
183
|
+
### How does Conventional Commits handle revert commits?
|
|
184
|
+
|
|
185
|
+
Reverting code can be complicated: are you reverting multiple commits? if you revert a feature, should the next release instead be a patch?
|
|
186
|
+
|
|
187
|
+
Conventional Commits does not make an explicit effort to define revert behavior. Instead we leave it to tooling authors to use the flexibility of _types_ and _footers_ to develop their logic for handling reverts.
|
|
188
|
+
|
|
189
|
+
One recommendation is to use the `revert` type, and a footer that references the commit SHAs that are being reverted:
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
revert: let us never again speak of the noodle incident
|
|
193
|
+
|
|
194
|
+
Refs: 676104e, a215868
|
|
195
|
+
|
|
196
|
+
```
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dewayne VanHoozer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# robot_lab-audit
|
|
2
|
+
|
|
3
|
+
A [RobotLab](https://github.com/MadBomber/robot_lab) extension gem that writes a
|
|
4
|
+
structured execution audit log to SQLite. Every network run, robot invocation, and
|
|
5
|
+
tool call is recorded as a row — timestamps, inputs, outputs, errors, and duration —
|
|
6
|
+
so you can query what happened after the fact.
|
|
7
|
+
|
|
8
|
+
Plugs into RobotLab's `Hook` system. Zero changes to your robots or networks; opt in
|
|
9
|
+
by calling `RobotLab::Audit.enable`.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add to your Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem "robot_lab-audit"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install directly:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
gem install robot_lab-audit
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
require "robot_lab"
|
|
29
|
+
require "robot_lab/audit"
|
|
30
|
+
|
|
31
|
+
RobotLab::Audit.enable(db_path: "~/.robot_lab/audit.db")
|
|
32
|
+
|
|
33
|
+
# All network runs and robot runs from here on are logged automatically.
|
|
34
|
+
network = RobotLab.create_network(...)
|
|
35
|
+
network.run(message: "do something")
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
The database file and any missing parent directories are created automatically.
|
|
39
|
+
|
|
40
|
+
### What gets logged
|
|
41
|
+
|
|
42
|
+
| Table | One row per | Key columns |
|
|
43
|
+
|-------|-------------|-------------|
|
|
44
|
+
| `network_runs` | `Network#run` call | `run_id`, `network_name`, `input`, `result`, `error_*`, `started_at`, `finished_at`, `duration_ms` |
|
|
45
|
+
| `audit_events` | `Robot#run` or `Tool#call` | `run_id`, `event_type`, `robot_name`, `tool_name`, `input`, `output`, `error_*`, `started_at`, `finished_at`, `duration_ms` |
|
|
46
|
+
|
|
47
|
+
`event_type` is `"robot_run"` or `"tool_call"`. All input/output values are JSON.
|
|
48
|
+
Timestamps are ISO 8601 with millisecond precision.
|
|
49
|
+
|
|
50
|
+
All events within a single `Network#run` share the same `run_id`, so you can
|
|
51
|
+
reconstruct the full execution trace for any network run.
|
|
52
|
+
|
|
53
|
+
Standalone `Robot#run` calls (outside a network) are also recorded; their `run_id`
|
|
54
|
+
column will be `nil`.
|
|
55
|
+
|
|
56
|
+
### Querying the log
|
|
57
|
+
|
|
58
|
+
`EventLog` provides three convenience methods:
|
|
59
|
+
|
|
60
|
+
```ruby
|
|
61
|
+
log = RobotLab::Audit::Hook.event_log
|
|
62
|
+
|
|
63
|
+
log.network_runs(limit: 100) # recent network runs, newest first
|
|
64
|
+
log.events_for("some-run-id") # all events for one run, ordered by time
|
|
65
|
+
log.recent_errors(limit: 50) # events where error_class is not null
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Each method returns an array of hashes keyed by column name.
|
|
69
|
+
|
|
70
|
+
You can also query the SQLite database directly with any SQL tool:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
sqlite3 ~/.robot_lab/audit.db \
|
|
74
|
+
"SELECT event_type, robot_name, tool_name, duration_ms, error_class
|
|
75
|
+
FROM audit_events
|
|
76
|
+
WHERE run_id = 'some-run-id'
|
|
77
|
+
ORDER BY started_at;"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Scoping to a robot or network
|
|
81
|
+
|
|
82
|
+
`RobotLab::Audit.enable` registers the hook globally. To limit logging to a specific
|
|
83
|
+
robot or network, register the hook directly on that object instead:
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
RobotLab::Audit::Hook.event_log = RobotLab::Audit::EventLog.new(db_path: "audit.db")
|
|
87
|
+
|
|
88
|
+
robot.on(RobotLab::Audit::Hook)
|
|
89
|
+
# or
|
|
90
|
+
network.on(RobotLab::Audit::Hook)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Schema
|
|
94
|
+
|
|
95
|
+
```sql
|
|
96
|
+
CREATE TABLE network_runs (
|
|
97
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
98
|
+
run_id TEXT NOT NULL UNIQUE,
|
|
99
|
+
network_name TEXT,
|
|
100
|
+
input TEXT,
|
|
101
|
+
result TEXT,
|
|
102
|
+
error_class TEXT,
|
|
103
|
+
error_message TEXT,
|
|
104
|
+
started_at TEXT NOT NULL,
|
|
105
|
+
finished_at TEXT,
|
|
106
|
+
duration_ms REAL
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
CREATE TABLE audit_events (
|
|
110
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
111
|
+
run_id TEXT,
|
|
112
|
+
event_type TEXT NOT NULL,
|
|
113
|
+
robot_name TEXT,
|
|
114
|
+
tool_name TEXT,
|
|
115
|
+
input TEXT,
|
|
116
|
+
output TEXT,
|
|
117
|
+
error_class TEXT,
|
|
118
|
+
error_message TEXT,
|
|
119
|
+
started_at TEXT NOT NULL,
|
|
120
|
+
finished_at TEXT,
|
|
121
|
+
duration_ms REAL
|
|
122
|
+
);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Development
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
bundle install
|
|
129
|
+
bundle exec rake test # run tests
|
|
130
|
+
bundle exec rake # default: test
|
|
131
|
+
bin/console # IRB with gem loaded
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Contributing
|
|
135
|
+
|
|
136
|
+
Bug reports and pull requests are welcome on GitHub at
|
|
137
|
+
https://github.com/MadBomber/robot_lab-audit.
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
MIT. See [LICENSE.txt](LICENSE.txt).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
|
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
|
7
|
+
t.libs << 'test'
|
|
8
|
+
t.libs << 'lib'
|
|
9
|
+
t.test_files = FileList['test/**/*_test.rb', 'test/**/test_*.rb'].exclude('**/*_helper.rb')
|
|
10
|
+
t.verbose = true
|
|
11
|
+
t.ruby_opts << '-rtest_helper'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
task default: :test
|
|
15
|
+
|
|
16
|
+
desc 'Run tests with verbose output'
|
|
17
|
+
task :test_verbose do
|
|
18
|
+
ENV['TESTOPTS'] = '--verbose'
|
|
19
|
+
Rake::Task[:test].invoke
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
desc 'Run a single test file'
|
|
23
|
+
task :test_file, [:file] do |_t, args|
|
|
24
|
+
ruby "test/#{args[:file]}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
desc 'Check code complexity with Flog (warn >=20, fail >=50)'
|
|
28
|
+
task :flog_check do
|
|
29
|
+
require 'flog'
|
|
30
|
+
|
|
31
|
+
method_warn = 20.0
|
|
32
|
+
method_fail = 50.0
|
|
33
|
+
|
|
34
|
+
flogger = Flog.new(all: true)
|
|
35
|
+
flogger.flog(*Dir.glob('lib/**/*.rb'))
|
|
36
|
+
|
|
37
|
+
warnings = []
|
|
38
|
+
failures = []
|
|
39
|
+
|
|
40
|
+
flogger.each_by_score do |method, score|
|
|
41
|
+
next if method.end_with?('#none')
|
|
42
|
+
|
|
43
|
+
if score > method_fail
|
|
44
|
+
failures << "#{format('%.1f', score)}: #{method}"
|
|
45
|
+
elsif score > method_warn
|
|
46
|
+
warnings << "#{format('%.1f', score)}: #{method}"
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
unless warnings.empty?
|
|
51
|
+
puts "\nFlog warnings (#{method_warn}–#{method_fail}) — target for future refactoring:"
|
|
52
|
+
warnings.each { |v| puts " #{v}" }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
if failures.empty?
|
|
56
|
+
puts "\nFlog: no methods exceed the failure threshold (>=#{method_fail})"
|
|
57
|
+
else
|
|
58
|
+
puts "\nFlog failures (>=#{method_fail}) — must be refactored:"
|
|
59
|
+
failures.each { |v| puts " #{v}" }
|
|
60
|
+
abort "\nFlog quality gate failed: #{failures.size} method(s) exceed #{method_fail}"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
desc 'Check for structural code duplication with Flay (mass >= 50)'
|
|
65
|
+
task :flay_check do
|
|
66
|
+
require 'flay'
|
|
67
|
+
|
|
68
|
+
mass_threshold = 50
|
|
69
|
+
|
|
70
|
+
flay = Flay.new({ mass: mass_threshold, diff: false, verbose: false, summary: false, timeout: 60 })
|
|
71
|
+
flay.process(*Dir.glob('lib/**/*.rb'))
|
|
72
|
+
flay.analyze
|
|
73
|
+
|
|
74
|
+
if flay.hashes.empty?
|
|
75
|
+
puts "\nFlay: no structural duplication detected (mass >= #{mass_threshold})"
|
|
76
|
+
else
|
|
77
|
+
puts "\nFlay found structural duplication (mass >= #{mass_threshold}):"
|
|
78
|
+
flay.report
|
|
79
|
+
abort "\nFlay quality gate failed: #{flay.hashes.length} pattern(s) detected"
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
desc 'Run all quality checks: tests (with coverage), RuboCop, Flog, and Flay'
|
|
84
|
+
task :quality do
|
|
85
|
+
gates = [
|
|
86
|
+
['Tests + Coverage', 'bundle exec rake test'],
|
|
87
|
+
['RuboCop', 'bundle exec rubocop'],
|
|
88
|
+
['Flog Complexity', 'bundle exec rake flog_check'],
|
|
89
|
+
['Flay Duplication', 'bundle exec rake flay_check']
|
|
90
|
+
]
|
|
91
|
+
|
|
92
|
+
results = gates.map do |label, command|
|
|
93
|
+
puts "\n#{'=' * 60}"
|
|
94
|
+
puts "Quality Gate: #{label}"
|
|
95
|
+
puts '=' * 60
|
|
96
|
+
[label, system(command) ? :pass : :fail]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
green = ->(s) { "\e[32m#{s}\e[0m" }
|
|
100
|
+
red = ->(s) { "\e[31m#{s}\e[0m" }
|
|
101
|
+
width = results.map { |label, _| label.length }.max
|
|
102
|
+
|
|
103
|
+
puts "\n#{'=' * 60}"
|
|
104
|
+
puts 'Quality Gate Summary'
|
|
105
|
+
puts '=' * 60
|
|
106
|
+
results.each do |label, status|
|
|
107
|
+
badge = status == :pass ? green.call('PASS') : red.call('FAIL')
|
|
108
|
+
puts " [#{badge}] #{label.ljust(width)}"
|
|
109
|
+
end
|
|
110
|
+
puts '-' * 60
|
|
111
|
+
|
|
112
|
+
passed = results.count { |_, s| s == :pass }
|
|
113
|
+
failed = results.count { |_, s| s == :fail }
|
|
114
|
+
tally = "#{passed} passed, #{failed} failed"
|
|
115
|
+
puts " #{failed.zero? ? green.call(tally) : red.call(tally)}"
|
|
116
|
+
puts '=' * 60
|
|
117
|
+
|
|
118
|
+
abort "\n#{red.call('Quality gate failed.')}" unless failed.zero?
|
|
119
|
+
puts "\n#{green.call('All quality gates passed.')}"
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
namespace :docs do
|
|
123
|
+
desc 'Build MkDocs documentation'
|
|
124
|
+
task :build do
|
|
125
|
+
sh 'mkdocs build'
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
desc 'Serve MkDocs documentation locally on http://localhost:8000'
|
|
129
|
+
task :serve do
|
|
130
|
+
sh 'mkdocs serve'
|
|
131
|
+
end
|
|
132
|
+
end
|