The Mac workstation (pai-m1) runs Claude Code in bypass-permissions mode
as an always-on AI workstation. Existing security controls (hook scripts,
pre-commit hooks, security-auditor agent) are detection-oriented: they
flag issues but do not remediate them. The scanning tools (semgrep, trivy,
gitleaks) run manually before PRs, not continuously.
Three specific gaps exist:
No remediation loop. The block-destructive.sh and
protect-sensitive.sh hooks block known-bad patterns, but no
process exists to discover new patterns, tighten existing rules,
or apply best practices that no single scanner covers. Security
improvements happen only when Kyle thinks of them.
Detection gaps in existing hooks. The protect-sensitive.sh
hook blocks cat, less, head, tail, curl -d @, base64,
and scp access to sensitive files, but does not block cp, mv,
vim, or other read methods. The block-destructive.sh hook uses
glob matching that multi-line commands or variable indirection could
bypass. These gaps are known but unfixed.
No continuous posture assessment. The workstation's security posture is a snapshot from whenever the Ansible playbook was last updated. There is no process to evaluate whether new attack vectors, configuration drift, or evolving best practices warrant changes.
This matters because the workstation runs AI agents with unrestricted tool access. The security posture directly determines the blast radius of any agent misbehavior or prompt injection attack.
An autonomous process iteratively discovers, implements, verifies, and commits security improvements to the Mac workstation every 30 minutes, with cost controls, run coordination, Discord status updates, and a structured wiki log — until there is nothing meaningful left to improve.
As Kyle, I want an autonomous loop to continuously discover and implement security improvements on my Mac workstation so that the security posture improves over time without my direct involvement.
Acceptance criteria:
As Kyle, I want the loop to stop if daily spend exceeds $150 USD so that costs stay bounded even if the loop runs for days.
Acceptance criteria:
As Kyle, I want the wrapper script to handle concurrent invocations gracefully so that overlapping runs do not corrupt state or waste resources.
Acceptance criteria:
As Kyle, I want the loop to post short status updates to Discord #status-updates so that I can monitor progress without checking the wiki.
Acceptance criteria:
cc-usage MCP availability in this worktree. The cc-usage MCP
exists on the kyle/cc-usage-mcp branch and the main working tree,
but is not present in the sec-improvement-loop worktree. The
branch needs to be rebased onto main or the MCP code pulled in
before the cost gate can work.
Discord channel ID for #status-updates. No channel ID for
#status-updates is currently configured in exports.sh. The
implementation needs to either use the existing
DISCORD_LOG_CHANNEL_ID or add a new env var for the
status-updates channel.
Coordination decision logic. The PRD says the new Claude Code instance decides whether to kill, wait, or skip based on the running instance's log output. The exact heuristic is an implementation detail, but the wrapper script needs to surface enough context (last log lines, runtime duration) for the model to make a reasonable decision.
Verification depth. The loop creates its own verification plans per improvement. There is no prescribed verification method. The appropriate depth per change is left to the model's judgment, but the autonomy smoke test (AC #4 on the hardening story) is mandatory.
Autonomy regression. The loop's primary constraint is "never impact autonomy." But security improvements inherently restrict capabilities. A hook that blocks a new command pattern could break a workflow the model doesn't anticipate. Mitigation: the model tests each change before committing, and Ansible is the rollback.
Ansible playbook corruption. Every change goes through the
playbook. A bad edit could break the entire Mac restore process.
Mitigation: frequent commits mean git revert is always available;
the model should run ansible-playbook --check (dry-run) before
applying.
Cost overrun between checks. The cost check happens before each iteration, but a single iteration could be expensive if the model does extensive research or makes many tool calls. The $150 limit could be exceeded within a single iteration. Mitigation: Sonnet is significantly cheaper than Opus; a single iteration is unlikely to cost more than $5-10.
Diminishing returns before self-termination. The model might not recognize when improvements become trivial and continue making low-value changes. Mitigation: Kyle reviews the wiki log and can manually stop the loop; Discord updates provide visibility.
Lock file stale state. If the wrapper script crashes without cleanup (kill -9, power loss), the lock file persists and blocks future runs. Mitigation: trap-based cleanup and PID validation (check if the PID in the lock file is still running).