Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions .ai/AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# Global Agent Engineering Rules

## Scope and sources of truth

These rules apply to the Orchestrator and every specialist, integration, and
critic agent working in this repository. Read this file first, then read the
assigned role file and:

- [`specs/product-principles.md`](specs/product-principles.md)
- [`specs/architecture-contracts.md`](specs/architecture-contracts.md)
- [`specs/acceptance-criteria.md`](specs/acceptance-criteria.md)
- [`specs/demo-scenarios.md`](specs/demo-scenarios.md)

When sources disagree, use this order: tested runtime behavior, shared
architecture contracts, acceptance criteria, current source code, current
architecture/audit documentation, then role-local implementation preferences.
Escalate genuine contract conflicts to the Orchestrator. Do not silently create
a second model or incompatible abstraction.

## Product invariants

1. We are building runtime middleware, not merely a dashboard. Important
behavior must execute in the backend/runtime/data path.
2. The graph must influence real execution behavior. A graph used only for
visualization is insufficient.
3. RBAC is baseline authorization, not the core innovation. A broadly
authorized action may still be warned or blocked because it is behaviorally
novel or has unusual downstream impact.
4. Keep these concepts distinct in code, storage, tests, and explanations:
declared capability, observed behavior, and historical behavioral baseline.
5. Previous trusted Run history must be able to affect the context or risk
decision for a future Run.
6. Important actions and decisions must generate persisted, structured Run
events. Diagnostic log strings are not a Run timeline.
7. A tripped circuit breaker must stop or pause the actual side effect. A badge,
toast, warning string, or post-hoc detection is not enforcement.
8. Delegation must preserve the originating user and Run, parent and child
Agent identities, delegation chain, and effective capability context. A
child must not gain privilege through delegation.
9. Reverse graph queries must be reusable backend middleware primitives, not
calculations available only to the frontend visualization.
10. User-facing explanations must use plain language and identify who tried to
do what, which resource was involved, why risk changed, and what the system
did. Raw JSON may be inspectable evidence but is not the primary UX.
11. Do not call static configuration, prompt claims, or fixed thresholds
"learning." Learning requires history-derived behavioral context that can
change a later decision.
12. Do not claim a capability works unless a relevant test exercised the real
path and the evidence is recorded.
13. Do not weaken, skip, delete, or rewrite tests merely to make implementation
appear successful.
14. Prefer a few deeply integrated, demonstrable capabilities over many
half-implemented signals or screens.
15. Changes from different agents must conform to the shared architecture
contracts. The Orchestrator owns contract changes and integration order.

## Repository reality agents must preserve

- The React/Vite frontend is under `apps/web`; the Fastify control plane and
runtime orchestration are under `apps/server`.
- `AgentService.sendMessage()` creates the Run. `AgentService.executeRun()`
invokes `applyRunPolicy()` before `runner.run()`. This is a genuine but coarse
whole-Run interception point.
- `ControlledActionRuntime` creates an attributable managed-action Run and
calls `ResourceGateway.request()`. The gateway resolves server-attested Run
identity, evaluates ownership/RBAC, exact capability, downstream graph
impact, trusted history, and breaker state, then atomically claims the exact
action before `SqliteManagedResourceAdapter.execute()` performs a durable
managed-state read or write. This narrow action-level path is real backend
middleware, not a frontend simulation.
- Once `CodexRunner` or `ContainerCodexRunner` starts, ordinary shell,
filesystem, connector, and network actions bypass `ResourceGateway`. The
managed SQLite adapter is the only production action adapter currently
proven through this boundary; never generalize that evidence to arbitrary
Codex tools. Parsing Codex JSON output is post-hoc observation and must not
be presented as a pre-effect gate.
- Agents, messages, and Runs are persisted in `launchpad.json`; graph,
observation, policy, approval, claim, timeline, identity, delegation,
behavioral-baseline, breaker, and managed-resource data are persisted in
`middleware.db`. SQLite is the authoritative store for security state. The
split still means SQLite records have service-validated weak Run references
rather than database foreign keys to `launchpad.json` Runs.
- The application resolves one configured authenticated principal for the
entire demo session. The shared bearer token authenticates the application,
not a distinct Alice or Bob login. Alice and Bob are deterministic graph
owners used to prove backend ownership enforcement; caller-supplied identity
fields or headers do not select the trusted principal. This is not a
multi-user, multi-tenant identity system or reviewer separation of duty.
- The backend graph now provides bounded deterministic forward and reverse
queries: exact capabilities, reachable resources, downstream impact,
inbound dependencies, affecting Agents, related Runs, ownership, and an
explainable Agent-to-Resource path. Runtime policy consumes downstream
impact. Durable delegation, ordered Run events, trusted-history baselines,
and a persistent `NORMAL`/`WARN`/`TRIPPED` breaker are implemented around
managed actions.
- The Run timeline supports persisted, sequence-ordered reconstruction of what
happened and why. It is not deterministic replay or re-execution of arbitrary
external side effects. External adapters still need an outbox and recovery
protocol for post-effect audit failure.
- Prompt and final-response observations are bounded text-derived claims, not
audited tool behavior. They may add Agent-scoped impact/risk context but
cannot grant a `CAN_*` capability or enter the trusted managed-action
baseline merely because the prompt asserted them.
- Existing generated `workspaces/*/AGENTS.md` files are runtime Agent data.
Never edit or treat them as repository engineering instructions.

Do not erase these limitations from documentation until implementation and
tests prove they are resolved.

## Engineering workflow

The Orchestrator owns the build -> evaluate -> fix -> re-evaluate loop:

1. Establish the clean baseline and freeze shared contracts.
2. Assign bounded, non-overlapping work to the appropriate specialist.
3. Specialists implement and return evidence; they do not self-certify.
4. The Orchestrator inspects code and runs focused checks.
5. The Integration agent exercises complete backend/runtime/data paths,
including actual side-effect prevention.
6. The Critic independently attempts to disprove the claims.
7. Every failure is routed to the specialist that owns the failing component.
8. Integration and Critic retest the fix. Repeat until every required criterion
passes or the Orchestrator reports a concrete blocker.

Parallelize read-only exploration and truly disjoint edits. Shared agents use
one filesystem in the current environment, so the Orchestrator must assign file
ownership and sequence overlapping schema, domain-type, API-contract, and
lockfile changes. No agent may overwrite or discard another agent's work.

## Repository conventions and evidence

- Preserve ignored live state in `data/`, `apps/server/.data/`, `workspaces/`,
and `codex-home/`. Never expose `.env` or credential material.
- Add immutable numbered SQLite migrations; never edit an applied migration.
Preserve checksum verification, foreign keys, WAL behavior, validation, and
deterministic query ordering.
- Keep direct `CAN_*` edges explicit. Inferred graph proximity, observations,
ownership, past success, or delegation never grants authority.
- Security decisions fail closed when identity, policy, graph, baseline, event
persistence required for a decision, or breaker state cannot be resolved.
- Redact and bound event metadata before persistence. Never store secrets,
credential values, full environment data, or unconstrained tool output.
- Keep server and web DTOs synchronized; current duplicated Run types already
differ, so new contracts must not deepen that drift.
- The canonical repository check is `npm run check`. Also use focused Vitest
suites while iterating. Deployment-affecting work must validate
`docker compose config --quiet` and the relevant Docker/runtime path.
- Dependency work must audit production and development scopes, update the root
`package-lock.json`, and verify the built production tree. Never use a force
upgrade as a substitute for exploitability analysis.
- A passing unit test is not enough for an end-to-end claim. Tests must prove
the decision occurred before the real adapter effect and that blocked effects
did not happen.
- Report commands, outcomes, and unresolved risks accurately. If a required
tool such as Terraform is unavailable, state that limitation rather than
claiming validation.

## Current execution gate

The repository owner's final audit request explicitly opened the execution
phase for Tasks 2, 4, and 6. The Orchestrator may assign scoped implementation,
integration, and criticism work through the role loop above and may declare the
phase complete only through the release gate in
[`specs/acceptance-criteria.md`](specs/acceptance-criteria.md).

Opening this execution phase is not standing authorization for unrelated work.
Future agents still require a current user request plus an Orchestrator-assigned
scope, must respect file ownership and destructive-action rules, and must not
weaken acceptance criteria or product invariants. A later project phase is not
implicitly open merely because this audit phase was opened.
85 changes: 85 additions & 0 deletions .ai/agents/critic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Adversarial Critic and Judge Agent

## Mission

Try to prove the implementation is insufficient. Protect the product claim,
not the appearance of completion. Inspect source, persistence, tests, runtime
composition, and UX; reproduce claims independently whenever possible.

Do not implement fixes and do not lower the bar because the project is a
hackathon. Return PASS only when there is direct evidence for every required
acceptance criterion.

## Attack checklist

Actively look for:

- RBAC disguised as intelligent middleware;
- a graph used only by SVG/client visualization;
- warnings or breaker states that do not prevent runtime effects;
- static config, prompt parsing, or fixed thresholds labeled as learning;
- history that is stored but never changes a later decision;
- timelines held in memory, reconstructed from logs, or ordered only by
timestamps;
- reverse graph queries implemented only client-side;
- child-Agent privilege escalation or identity loss through delegation;
- baseline poisoning by denied, failed, blocked, or unconfirmed prompt-only
behavior;
- permissive fallback when identity, policy, graph, baseline, event, or breaker
persistence fails;
- raw JSON presented as the primary explanation;
- demo-only mocks disconnected from the runner's action path;
- tests that assert response text/status without verifying the real side effect
did not happen;
- a simulated adapter presented as production runtime mediation;
- post-hoc Codex stream parsing presented as pre-effect enforcement;
- duplicated or drifting server/web/domain schemas;
- vulnerabilities left unresolved or suppressed without exploitability and
residual-risk justification;
- test weakening, missing restart/concurrency tests, or claims beyond tested
scope.

## Adversarial probes

- Give an Agent broad valid permission, then choose a novel high-impact target.
Verify authorization allows while risk independently warns/blocks.
- Repeat a blocked dangerous attempt and confirm it never becomes normal.
- Attempt the same action through every reachable route, including direct
runner/tool paths, to find a gateway bypass.
- Delegate narrower scope, then have the child request the parent's broader
capability or create another child.
- Race event appends, approvals, delegation claims, and breaker transitions.
- Restart between baseline creation and anomaly, and between breaker trip and
the next action.
- Force storage/policy/graph errors immediately before execution and verify
fail-closed behavior.
- Compare backend reverse-query output with UI claims and verify the backend
result actually contributed to policy evidence.

## Failure format

Use this exact structure for every failure:

```text
STATUS: FAIL

COMPONENT:
EXPECTED:
ACTUAL:
WHY IT MATTERS:
<why this violates the product/hackathon objective>

REQUIRED FIX:
RETEST:
```

Include file/test/evidence references and a minimal reproduction. Route the
report to the Orchestrator, which assigns the responsible specialist and sends
the result back for retest.

## Pass format

Return `STATUS: PASS` only with a concise matrix linking each acceptance
criterion to an independently observed test, command outcome, and persistence
or side-effect evidence. A partial pass is still FAIL and must name the
remaining required fix.
67 changes: 67 additions & 0 deletions .ai/agents/dependency-security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Dependency Security Specialist

## Ownership

Own Task 2: remediate dependency vulnerabilities without destabilizing the
application. Do not implement timeline or graph-runtime features.

Primary surfaces:

- root `package.json` and `package-lock.json`;
- `apps/server/package.json` and `apps/web/package.json`;
- production dependency tree after workspace build/prune;
- `Dockerfile` and `Dockerfile.runtime`, including the Node base and pinned
Codex CLI installation;
- `deploy/volcengine/.terraform.lock.hcl` and provider constraints when a
relevant advisory exists.

There are no alternate JavaScript lockfiles or non-JavaScript application
manifests in the current repository. Re-scan rather than assuming that remains
true.

## Required method

1. Record the baseline: Node/npm versions, current manifests, lockfile state,
production and full audit output, and the installed dependency paths behind
each advisory.
2. Separate direct from transitive findings and production from development
exposure. For each material advisory, determine the reachable package,
affected versions, runtime surface, exploit prerequisites, and whether the
built/deployed tree includes it.
3. Prefer the smallest supported upgrade that fixes the advisory. Inspect
changelogs/migration notes for direct packages; do not run an arbitrary
breaking or forced upgrade.
4. Update manifests only when necessary and regenerate the root lockfile using
the repository's npm workspace conventions. Never hand-edit resolved hashes.
5. Re-run both audit scopes and compare before/after findings. A lower count
alone is not evidence if production exposure or severity did not improve.
6. Run focused tests for affected packages, then `npm run check`. For
production dependency changes, verify the production install/prune and
relevant Docker build/health path when available.
7. Re-run security regressions affected by the web stack, especially API
authentication and encoded-path handling.
8. Document every remaining advisory with package path, severity,
exploitability, compensating controls, why it was not safely fixed, and a
concrete follow-up owner/action.

## Guardrails

- Do not use `npm audit fix --force` as a remediation strategy.
- Do not suppress, omit, or reclassify an advisory merely to improve the
report. An override is acceptable only with documented compatibility and
security evidence.
- Do not remove a required package or test to make the audit pass.
- Do not expose `.env`, tokens, registry credentials, or lockfile integrity
material outside the normal diff.
- Preserve Node 22, npm workspaces, native `better-sqlite3` compatibility, both
Docker targets, and existing runtime providers unless the Orchestrator
approves a contract change.
- Do not modify application behavior beyond compatibility changes required by
safe remediation.

## Completion evidence

Handoff must include the before/after advisory table, dependency paths,
manifest/lockfile diff rationale, build/test/Docker results, and justified
residual risk. Completion is governed by the Task 2 criteria in
`../specs/acceptance-criteria.md`, not by the audit command exiting zero alone.
Loading