feat: Marketing qbit and integrated marketing agent (0.1.0) #5

Merged
KofTwentyTwo merged 4 commits from feature/marketing-qbit into develop 2026-10-12 23:19:10 +00:00
4 Commits
Author SHA1 Message Date
james.maesandClaude Opus 5.5 9e71b2956d fix: close the gaps found in code review
HIGH:
- An edit through the UI or API passes the id as a String, so the content
  customizer's old-record lookup missed. The edit then skipped the hash
  recompute, the revision, approval invalidation and the status guard, and
  edited text could go out under the old approval. Ids are now normalized,
  the old row is re-read when it is missing, and the update errors instead
  of failing open. Execution also compares the approval with a hash
  recomputed from the fields it is about to send.
- One failing execution (a CRM outage, a malformed scope, a channel with no
  type) aborted the worker batch on every run and starved every later
  execution. Each execution is now isolated: a failure before the claim
  blocks it with the reason; a failure after the claim leaves it Running for
  its lease to expire into reconciliation. Recipient scopes are validated
  at submit and approve time.

MEDIUM:
- The policy fails closed. Without the default row, or without an explicit
  "on", the agent and execution are off. Configuration Status shows the
  policy state.
- The channel hourly rate and the agent budgets are counted as the system
  user, so record locks can't hide other products' usage.
- The agent's write tools need the requester's marketing.write, and the agent
  revises only content that is still a Draft.
- The entry points of CRM results, readiness checks and starter data check
  their own permission. CRM activities are written with the user's CRM
  permissions (ENFORCE).
- Closing or downgrading an open blocker finding needs
  marketing.approve.hasAccess, whether through the action, the table or the
  API.
- Approve pins the content hash shown on the Review screen. Content that
  changed before execute is skipped ("review it again").

ReviewFixesTest covers each fix. Fixtures create the default policy row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 15:59:56 -05:00
james.maesandClaude Opus 5.5 ed62add2de docs: README, design, operations and starter data
- README: what the qbit does, how to install it, permissions, the UI, and an
  honest table of what is implemented versus what is not configured.
- docs/DESIGN.md:
  - the patterns reused from qbit-assistant, the QQQ AI tool kernel and core
    permission enforcement, the existing qbits, qbit-crm, QQQ messaging and
    the ESB / Quick Search
  - the data model
  - content, revisions and approval
  - execution and the transports
  - measurement
  - the CRM integration
  - the agent and its tools
  - the configuration status
- docs/OPERATIONS.md: every setting, the policy row, the schema workflow, the
  credentials to configure later, run-books (publishing, blocked and ambiguous
  executions, the kill switch, recording outcomes, agent runs), and the scale
  limits stated plainly.
- docs/STARTER-DATA.md: the three products' readiness, the sources verified
  on 2026-10-12, the disputed claims, and the starter campaigns.
- CLAUDE.md / AGENTS.md: the architecture and the generated-code rule.
- Tests use obviously fake key strings.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 15:46:24 -05:00
james.maesandClaude Opus 5.5 094f728d85 test: verification matrix, persistence across restart, provider fixture
Tests for the required checks, and the fixes they drove:

- Unauthorized access is denied with core permission enforcement on.
  Preparation, approval, execution and the agent need separate permissions.
  The optional product security key bounds what users and the agent's tools
  see.
- Drafts are made without publication authority. The agent has no approve,
  schedule or send tool. A draft that cites a non-released claim gets a
  blocker finding, which stops approval.
- Approval is invalidated by any approved-field edit, including a schedule
  change. Status and approval rows can't be forged.
- Pause, resume and cancel. Duplicate scheduling and runs are refused.
  Ambiguous outcomes are reconciled or decided by a person and never retried
  blindly. Repeats are deduplicated by the idempotency key. Retries happen
  only when the request was certainly not sent. Expired leases need
  reconciliation.
- At execution time: the kill switch, the schedule, consent and suppression,
  the bulk limit, channel AI-content rules, and unconfigured transports.
- Outcome events are deduplicated by (source, external id). Raw events and
  unique actors are reported separately, and uninstrumented metrics show as
  "Not measured". CRM import is idempotent, and leads are qualified only by
  an explicit rule.
- Missing provider: the run fails with a plain reason and manual work still
  runs. Provider errors are retried or failed by kind, and no secret appears
  in errors. Budgets, the concurrency limit, cancellation and the model-call
  limit are enforced.
- Persistence across a restart, on the RDBMS module over a file-backed H2
  database created from the shipped DDL.
- The OpenAI-compatible provider is tested against a local HTTP fixture.

Fixes:
- Service entry points run as trusted internal work after their own
  permission check, the same way QQQ trusts nested calls. Agent tools still
  force PermissionEnforcement.ENFORCE.
- Content status and authorType are managed rather than required, and
  productId is derived.
- Schedules are kept to the second, so stored values hash the same as
  approved ones on every database.
- The Result screen lists skipped records with their reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 15:35:26 -05:00
james.maesandClaude Opus 5.5 7a7972d661 feat: Marketing QBit with its agent, approvals and controlled execution
The first version of qbit-marketing. It manages products and their evidence,
campaigns, content with revision history, exact human approval, durable
execution through transports, measurement, and a marketing agent. Everything
lives in 18 standard marketing_* tables inside the host's QQQ app.

- Model: products, audiences, evidence sources, claims (released / planned /
  unverified / disputed), campaigns, channels with their rules, content and
  immutable revisions, approvals, executions and attempts, test deliveries,
  agent runs and steps, findings, metrics, outcome events and the policy.
  scripts/generate-model.py generates the entities, enums and DDL from one
  spec.
- Approval binds a hash of the text, destination, recipient scope, schedule
  and channel. Any edit invalidates it, sends the content back to draft and
  blocks pending executions. System-written tables are read-only and are
  guarded so that only Marketing's services write them.
- Execution: idempotency keys, leases, retries with backoff only when the
  request was certainly not sent, and no blind retry of ambiguous outcomes
  (reconcile, or let a person decide). Every send re-checks the kill switch,
  approval, schedule, channel, transport, AI-content rules, rate limit,
  consent and suppression. A controlled test transport and a QQQ messaging
  email transport are provided.
- Agent: qbit-assistant's model-provider SPI (Anthropic, scripted) plus an
  OpenAI-compatible provider. Narrow typed tools run as the user with
  permission enforcement, inside the untrusted-data envelope, and with
  redaction. The tools can draft and record findings but cannot approve or
  send. Runs are bounded and recorded with their usage and cost.
- CRM: a narrow gateway SPI with a qbit-crm adapter. Results are imported as
  outcome events, and leads are qualified only by a campaign's explicit rule.
- UI: the app home dashboard, record widgets, and streamed-ETL record actions;
  the nav holds only the main and settings tables.
- Starter data: QQQ, gclo and MarkdownViewr for Windows, verified 2026-10-12.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 15:23:38 -05:00