Skip to content

refactor: concentrate repeated config, receipt and scheduler rules - #16

Merged
renezander030 merged 1 commit into
masterfrom
refactor/lean-deep-modules
Oct 14, 2026
Merged

renezander030 merged 1 commit into
masterfrom
refactor/lean-deep-modules

Conversation

@renezander030

Copy link
Copy Markdown
Owner

Problem

Several rules were written out separately at each call site, so changing one meant finding every copy:

  • the state-path lookup (DRAFTCAT_STATE_PATH → state.path → ./state.db), in six places
  • the 15-field v2 receipt signature mapping, in three signers
  • the credential variable names and the 4h approval-window default, across engine boot, redaction, doctor, tool gate, model policy and relay

Change

Rule Now lives in
State-path lookup resolveStatePath / statePathFromConfigFile (state_path.go)
Signed v2 field set ApprovalEnvelope.FieldsV2() + signApprovalEnvelope()
Credential variable names TokenEnvName / SecretEnvName / APIKeyEnvName + Default*Env in config
Approval-window default TimeoutConfig.OperatorApprovalWindow() + DefaultOperatorApproval
Single ↔ quorum decision shape OperatorDecision.asQuorum / QuorumDecision.asSingle

Narrowed or removed:

  • Scheduler.SetRunning(name, bool) → Release(name). No caller used the true mode.
  • RecordApprovalRow folded into RecordApprovalForRun. Its policy argument was always empty, and the stored row is unchanged.
  • Unused code deleted: toolTicket.consumedAt, Scheduler.MarkRun, ghl.ParseGHLWebhook.

Production code lines: 15,783 → 15,732 (blanks and comments excluded).

Behaviour

No behaviour change. Where existing call sites differed, each keeps its own behaviour:

  • zk-receipt still treats a whitespace-only state.path as unset.
  • The pipeline gate still uses its == 0 approval-timeout check.
  • Each receipt signer keeps its own error path.

The CLI help, the receipt signature field set, the SQLite rows and the relay/Telegram texts are all unchanged.

Validation

Before and after the change (all pass):

  • gofmt, go vet, go build
  • go test -short and the full go test
  • -tags voice vet and test
  • npm ci --ignore-scripts && npm test && npm pack --dry-run
  • go run . validate
  • golangci-lint --new-from-rev=HEAD (0 new issues)
  • contrib/teams-relay vet and build

Output comparison: help output for 14 CLI entry forms and the output of 12 read-only subcommand runs were compared byte-for-byte against master and are identical. The runs covered runs, pending, receipts, budget, zk-receipt, doctor (text and --json) and validate.

New interface tests: one for each consolidated rule: state path, signed field set, env names, approval window, decision shapes.

Two-way door: an internal refactor with no format or interface change, revertable as one commit.

- One state-path resolver (DRAFTCAT_STATE_PATH, then state.path, then
  ./state.db) for the engine and every subcommand.
- ApprovalEnvelope.FieldsV2 defines the signed v2 field set once for all
  three receipt signers.
- Config owns the credential variable names and the approval-window
  default (OperatorApprovalWindow, DefaultOperatorApproval).
- OperatorDecision/QuorumDecision convert between single and quorum shapes.
- Scheduler.SetRunning(name, bool) narrowed to Release(name).
- RecordApprovalRow folded into RecordApprovalForRun; stored rows unchanged.
- Remove unused toolTicket.consumedAt, Scheduler.MarkRun and
  ghl.ParseGHLWebhook.

No behaviour change: CLI help and subcommand output are identical, the
receipt signature and stored formats are unchanged. Adds interface tests
for each consolidated rule.
@renezander030
renezander030 merged commit 448be5a into master Oct 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant