Skip to content
Merged
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
6 changes: 4 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Archie — AI-powered architecture analysis and enforcement for coding agents. A
## Repository Layout

- `archie/` — Python package (`archie-cli`): CLI commands, analysis engine, standalone scripts
- `archie/standalone/` — Zero-dependency Python scripts (scanner, renderer, validator, intent layer, health, drift, hooks)
- `archie/standalone/` — Zero-dependency Python scripts (scanner, renderer, validator, intent layer, health, hooks)
- `npm-package/` — NPM distribution (`npx @bitraptors/archie`): copies scripts + Claude Code commands to target projects
- `tests/` — Test suite (pytest)
- `docs/` — Architecture documentation
Expand Down Expand Up @@ -87,7 +87,9 @@ See `archie/benchmark/README.md`.
5. **Render** — Deterministic JSON→Markdown (CLAUDE.md, AGENTS.md, rule files)
6. **Validate** — Cross-reference output against actual codebase
7. **Intent Layer** — AI-generated per-folder CLAUDE.md via bottom-up DAG
8. **Scan report** — Phase 4 of Step 9 writes `.archie/scan_report.md` with ranked findings (so `/archie-share` and future trend runs pick it up)
8. **Finalize** — Health metrics (`health.json` + history), incremental baseline marker, telemetry flush, closing summary

Findings live in `.archie/findings.json` (compounding store: stable ids, verifier + hysteresis in Step 5); `/archie-share` ships them from there. In incremental mode the Risk agent additionally sweeps the changed files against documented invariants and per-folder CLAUDE.md patterns (the recency sweep).

## Key Data Model

Expand Down
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,10 @@ Run `/archie-deep-scan` once for the baseline, then `/archie-deep-scan --increme

Health: Erosion 0.95 (front) / 0.69 (back) · Gini 0.92 / 0.76 · LoC 76,903 / 45,261

Drift: 14 errors (raw ipcRenderer exposure, API key in logs, duplicate startup
Findings: 14 errors (raw ipcRenderer exposure, API key in logs, duplicate startup
handlers, stale WebSocket closures, DI-layer imports from utils, …)
14 warnings (sync I/O in async paths, monolith routers, compat-hook CRUD leak, …)

Top risks: IPC security hole · API key exposure · stale WebSocket state ·
circular deps & layer violations · duplicate startup handler

Semantic duplication: 3 groups (placeholder_resolver clone, dual WebSocketMappingService,
sidebar state in two contexts)
— each verified against its triggering call site before it ships

Archie is now active. Rules will be enforced on every code change.
Run /archie-deep-scan --incremental after code changes to refresh the analysis.
Expand Down
4 changes: 2 additions & 2 deletions archie/assets/gitignore.default
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# were yours. Re-running the installer recreates them.
#
# The architecture snapshot you MAY want to commit lives alongside these and is
# deliberately NOT ignored: blueprint.json, rules.json, scan_report.md,
# findings.json, health.json, c4.json, etc.
# deliberately NOT ignored: blueprint.json, rules.json, findings.json,
# health.json, c4.json, etc.

_install_pkg/
viewer/
Expand Down
2 changes: 1 addition & 1 deletion archie/assets/workflow/_shared/scope_resolution.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Map the answer: Yes → `INTENT_LAYER=yes`, No → `INTENT_LAYER=no`. Expose `IN

### Step F: Persist run context

Write every shell variable that Steps 1–10 depend on into `.archie/deep_scan_state.json` so `/compact` + `--continue` can rehydrate them from disk without relying on orchestrator memory:
Write every shell variable that Steps 1–9 depend on into `.archie/deep_scan_state.json` so `/compact` + `--continue` can rehydrate them from disk without relying on orchestrator memory:

```bash
echo "$WORKSPACES" | python3 .archie/intent_layer.py deep-scan-state "$PWD" save-run-context \
Expand Down
20 changes: 10 additions & 10 deletions archie/assets/workflow/deep-scan/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
name: archie-deep-scan
description: Comprehensive architecture baseline scan (15-20 min). Two-wave AI analysis producing blueprint.json, per-folder CLAUDE.md, AI-synthesized rules, health metrics, and drift detection. Use for first-time baselines or major refactors.
description: Comprehensive architecture baseline scan. Two-wave AI analysis producing blueprint.json, per-folder CLAUDE.md, AI-synthesized rules, and health metrics. Use for first-time baselines or major refactors.
---

# Archie Deep Scan — Comprehensive Architecture Baseline
Expand Down Expand Up @@ -55,18 +55,19 @@ Check the user's message (ARGUMENTS) for flags:
>
> **Treat every item-count anywhere in this workflow — `N-M`, "up to N", "top N", "the N most", "soft floor of N", "a handful", "the most important" — as a FLOOR with no ceiling.** Produce every item that genuinely meets its quality bar; never trim to a number, never stop at a "natural" count. The quality bar is unchanged: do NOT pad, invent, or weaken per-item rigor to inflate counts.
>
> Only two limits survive comprehensive mode: **(1)** the architecture diagram stays **8-12 nodes** (readability), and **(2)** the scripts' mechanical safety/context budgets (per-file read size, per-batch token budget, recursion). Everything else — rules, findings, pitfalls, decisions, trade-offs, components, guidelines, examples, drift findings, naming examples, per-field prose length — is uncapped.
> Only two limits survive comprehensive mode: **(1)** the architecture diagram stays **8-12 nodes** (readability), and **(2)** the scripts' mechanical safety/context budgets (per-file read size, per-batch token budget, recursion). Everything else — rules, findings, pitfalls, decisions, trade-offs, components, guidelines, examples, naming examples, per-field prose length — is uncapped.
>
> Whenever a step dispatches a sub-agent in comprehensive depth, prepend the contract line shown at that dispatch site so the sub-agent inherits this rule.

**If `--from N` is present** (e.g., `{{COMMAND_PREFIX}}archie-deep-scan --from 5`):
1. Set `START_STEP = N` (the number after --from) and `RESUME_ACTION=resume` (so the Resume Prelude rehydrates shell variables from `deep_scan_state.run_context`).
2. Validate prerequisites exist:
1. If N is not between 1 and 9, tell the user the valid range is 1-9 (the pipeline has 9 steps; older versions had a step 10, which no longer exists) and stop.
2. Set `START_STEP = N` (the number after --from) and `RESUME_ACTION=resume` (so the Resume Prelude rehydrates shell variables from `deep_scan_state.run_context`).
3. Validate prerequisites exist:
```bash
python3 .archie/intent_layer.py deep-scan-state "$PROJECT_ROOT" check-prereqs N
```
3. If check fails, tell the user which files are missing and which earlier step to run.
4. If check passes, proceed. Do NOT call `deep-scan-state init` — it would wipe the state the Resume Prelude needs to read.
4. If check fails, tell the user which files are missing and which earlier step to run.
5. If check passes, proceed. Do NOT call `deep-scan-state init` — it would wipe the state the Resume Prelude needs to read.

**If `--continue` is present:**
1. Read state (no prompt — `--continue` is an explicit opt-in):
Expand Down Expand Up @@ -129,7 +130,7 @@ STATUS=$(python3 .archie/intent_layer.py inspect "$PROJECT_ROOT" deep_scan_state
| 6 | AI rule synthesis |
| 7 | Intent Layer |
| 8 | Cleanup |
| 9 | Drift detection |
| 9 | Finalize (health + telemetry) |

Ask the user how to proceed — {{>ask_user}}:
- **question:** (build dynamically) `"A previous deep-scan stopped after Step {LAST} ({step_name})."` — and if `ENRICH_DONE > 0`, append `" The Intent Layer got {ENRICH_DONE} folders in before stopping."` — then `"What do you want to do?"`
Expand Down Expand Up @@ -158,7 +159,7 @@ STATUS=$(python3 .archie/intent_layer.py inspect "$PROJECT_ROOT" deep_scan_state
**For every step below:**
- If the step number < START_STEP, skip it entirely.
- If SCAN_MODE is not set, it defaults to "full" (all existing behavior unchanged).
- **Do NOT ask the user any questions during Steps 1–10. Do NOT offer to skip, reduce scope, or present alternatives for any step. Execute every step fully as documented.** This rule applies ONLY to Steps 1–10. It does NOT apply to Phase 0 / Activation: the scope prompt (Step C) and Intent Layer prompt (Step E) in `scope_resolution.md` are mandatory decision gates and MUST still be asked — see below.
- **Do NOT ask the user any questions during Steps 1–9. Do NOT offer to skip, reduce scope, or present alternatives for any step. Execute every step fully as documented.** This rule applies ONLY to Steps 1–9. It does NOT apply to Phase 0 / Activation: the scope prompt (Step C) and Intent Layer prompt (Step E) in `scope_resolution.md` are mandatory decision gates and MUST still be asked — see below.


## Activation — read these before running any step
Expand Down Expand Up @@ -191,7 +192,6 @@ If `START_STEP > N` (the Preamble decided to skip earlier steps), do not Read or
| 6 | AI rule synthesis | `{{WORKFLOW_ROOT}}/deep-scan/steps/step-6-rule-synthesis.md` |
| 7 | Intent Layer — per-folder CLAUDE.md | `{{WORKFLOW_ROOT}}/deep-scan/steps/step-7-intent-layer.md` |
| 8 | Cleanup | `{{WORKFLOW_ROOT}}/deep-scan/steps/step-8-cleanup.md` |
| 9 | Drift detection & architectural assessment | `{{WORKFLOW_ROOT}}/deep-scan/steps/step-9-drift.md` |
| 10 | Final telemetry flush | `{{WORKFLOW_ROOT}}/deep-scan/steps/step-10-telemetry.md` |
| 9 | Finalize — health metrics, baseline, telemetry flush | `{{WORKFLOW_ROOT}}/deep-scan/steps/step-9-finalize.md` |

Step 3's `orchestration.md` in turn references four sub-agent prompt files plus a shared `grounding-rules.md` (all under `{{WORKFLOW_ROOT}}/deep-scan/steps/step-3-wave1/`) — read those as the orchestration instructs.
5 changes: 5 additions & 0 deletions archie/assets/workflow/deep-scan/fragments/resume-prelude.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ fi
- The consistency check is defensive. Under normal compact-and-resume flow, telemetry step count ≥ last_completed always holds because each step marks its start *before* calling `complete-step N`. A warning here signals something outside the happy path (manual state edit, aborted step, corrupted file).
- `WORKSPACES` is rehydrated as a newline-separated string, matching what Step C's scope picker originally produced. Downstream iteration patterns (`while IFS= read`; `printf '%s\n' "$WORKSPACES" | ...`) work identically.
- If `--from N` is supplied, the orchestrator sets `FROM_STEP=N` before this block runs.
- **Incremental runs:** `changed_files`/`affected_folders` are intentionally NOT persisted (they can be large and go stale). When `SCAN_MODE=incremental`, regenerate them on resume — the baseline marker only moves at Step 9's `save-baseline`, so this reproduces the Preamble's exact output. Steps 3, 5 (the Risk agent's recency sweep depends on it), and 7 all consume this list:

```bash
python3 .archie/intent_layer.py deep-scan-state "$PWD" detect-changes
```

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Telemetry conventions

Every Step 1–9 records its start timestamp to disk via `telemetry.py mark` as its first action. The mark auto-closes the previous step's `completed_at`, mirroring the "next step's start = prior step's end" convention. Step 9 finishes its own completion with `telemetry.py finish`. After Step 10, `telemetry.py write` consumes the persisted `.archie/telemetry/_current_run.json` and emits the final `deep-scan_<timestamp>.json`.
Every Step 1–9 records its start timestamp to disk via `telemetry.py mark` as its first action. The mark auto-closes the previous step's `completed_at`, mirroring the "next step's start = prior step's end" convention. Step 9 finishes its own completion with `telemetry.py finish`, then `telemetry.py write` consumes the persisted `.archie/telemetry/_current_run.json` and emits the final `deep-scan_<timestamp>.json`.

Shell-variable fallback: the existing `TELEMETRY_STEPN_START` shell variables are still set for readability, but they are **not load-bearing** — the disk file is the source of truth. This makes the pipeline safe to `/compact` mid-run without losing timing data.

22 changes: 0 additions & 22 deletions archie/assets/workflow/deep-scan/steps/step-10-telemetry.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ Spawn the **Product** sub-agent only when `DOMAIN_LAW_COUNT` is greater than 0.
- **If SCAN_MODE = "incremental":**
> INCREMENTAL UPDATE. The architecture was previously analyzed — `$PROJECT_ROOT/.archie/blueprint.json` is the current full architecture and `$PROJECT_ROOT/.archie/blueprint_raw.json` carries the structural changes from Step 4. These files changed: [list `changed_files`]. Update ONLY the sections you own that are affected by these changes, and return ONLY what changed — unchanged sections are preserved by the patch merge. Use the 4-field contract (`problem_statement`, `evidence`, `root_cause`, `fix_direction`) when writing finding or pitfall entries.

The `changed_files` list MUST be expanded verbatim into the preamble (one path per line) — the Risk agent's recency sweep reads every file on it against the documented invariants and per-folder CLAUDE.md patterns (see its prompt body). An empty or summarized list silently disables that sweep. **If the list is no longer in context** (resume after `/compact`, `--continue`, or `--from 5`), regenerate it before dispatching — the baseline marker is untouched until Step 9's `save-baseline`, so this reproduces the Preamble's exact output:

```bash
python3 .archie/intent_layer.py deep-scan-state "$PROJECT_ROOT" detect-changes
```

**Output contract — append to each prompt, substituting that sub-agent's output path from the table as the "file path named above":**

```
Expand Down
2 changes: 2 additions & 0 deletions archie/assets/workflow/deep-scan/steps/step-5b-risk.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ The `f_0001` shape we are guarding against: AI sees an AGENTS.md mandate, finds

**APPROACH — anchor synthesis to documented invariants.** Instead of speculatively asking *"what could go wrong?"*, walk the documented invariants in AGENTS.md, root `CLAUDE.md`, per-folder `CLAUDE.md` (Anti-Patterns and Patterns sections — `.archie/maintainer_guardrails.json` if available), and `blueprint.pitfalls`. For each invariant, ask: *"is there code in this corpus that violates it? Quote it verbatim."* If yes ⇒ that quote is the `triggering_call_site` of a finding. If the invariant is real but uniformly enforced ⇒ no finding (and no need to re-emit a pitfall already in the store). This adversarial framing converts the loose "find problems" task into a falsifiable evidence-gathering pass.

**Recency sweep (only when the mode preamble carries a "These files changed:" list — incremental runs).** That list is your sweep scope: Read each listed file (skip ones that no longer exist) plus its folder's `CLAUDE.md` and parent folder's `CLAUDE.md` when they exist. Check each file against the documented invariants exactly as above — the per-folder Patterns/Anti-Patterns are first-class invariants here, alongside `blueprint.json` decisions, trade-offs (`violation_signals`), and pitfalls (`stems_from`). A violation with a verbatim caller becomes a normal finding (full 4-field shape + `triggering_call_site`); folder-pattern erosion with no firing call site is a pitfall (upgrade the existing one if the class is already tracked). The list is bounded by definition — read every file on it; do not sample.

**Primary goal — emit NEW findings.** You have the overall picture (all Wave 1 output plus source files). Your highest-leverage work is surfacing problems that are NOT already in findings.json — things only visible from the whole-system view: cross-component coupling, pattern breakdowns that individual agents miss, constraint violations implied by the decision chain, gaps between what the blueprint claims and what the code does. Spend the bulk of your cognitive budget here. For each new finding: next-free `f_NNNN` id, `first_seen` = today, `confirmed_in_scan` = 1, `depth: "canonical"`, `source: "deep:synthesis"`, AND a non-empty `triggering_call_site`.

**Novelty check before emitting.** Before you add a "new" finding, verify it is genuinely new: scan the existing store for any entry with overlapping `problem_statement` meaning OR overlapping `applies_to` files. If the same problem is already tracked under a different wording, DO NOT mint a new id — instead upgrade the existing entry (see below). A new finding must describe something the store doesn't already cover.
Expand Down
4 changes: 2 additions & 2 deletions archie/assets/workflow/deep-scan/steps/step-7-intent-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TELEMETRY_STEP7_START=$(date -u +"%Y-%m-%dT%H:%M:%SZ")

**If START_STEP > 7, skip this step.**

**If `INTENT_LAYER=no` (user opted out in Step E), skip this entire step.** Print a one-line note to the user: *"Intent Layer skipped (no per-folder CLAUDE.md generated). Root CLAUDE.md + rule files still written. You can run `{{COMMAND_PREFIX}}archie-intent-layer` later if you change your mind."* Then proceed to Step 8. The `intent_layer` telemetry step will record zero elapsed time (its `started_at == completed_at`) and carry `"skipped": true` (see Step 10).
**If `INTENT_LAYER=no` (user opted out in Step E), skip this entire step.** Print a one-line note to the user: *"Intent Layer skipped (no per-folder CLAUDE.md generated). Root CLAUDE.md + rule files still written. You can run `{{COMMAND_PREFIX}}archie-intent-layer` later if you change your mind."* Then proceed to Step 8. The `intent_layer` telemetry step will record zero elapsed time (its `started_at == completed_at`) and carry `"skipped": true` (see Step 9).

**If `INTENT_LAYER=yes`, execute this step fully. Do NOT ask the user whether to run, skip, or reduce scope. Do NOT offer alternatives. Run all batches as instructed below.**

Expand Down Expand Up @@ -65,7 +65,7 @@ Then execute Phases 1–4 from that file, using `PROJECT_ROOT` in place of `$PWD

### ✓ Compact Checkpoint C — after Intent Layer

Only meaningful when `INTENT_LAYER=yes`. Step 7 has just pushed dozens-to-hundreds of {{ANALYSIS_MODEL}} subagent transcripts into conversation context; those are now fully persisted to `.archie/enrichments/*.json` and merged into per-folder `CLAUDE.md` files. Compacting here gives Step 9 (Drift Assessment) a fresh context, which matters because drift assessment reads blueprint + drift_report + CLAUDE.md files and benefits from focused attention.
Only meaningful when `INTENT_LAYER=yes`. Step 7 has just pushed dozens-to-hundreds of {{ANALYSIS_MODEL}} subagent transcripts into conversation context; those are now fully persisted to `.archie/enrichments/*.json` and merged into per-folder `CLAUDE.md` files. Compacting here gives the remaining bookkeeping steps (Cleanup, Finalize) a fresh context, so the run finishes reliably even after a very large Intent Layer pass.

If `INTENT_LAYER=no` (opted out in Step E), skip this checkpoint — Checkpoint A already covered it.

Expand Down
2 changes: 2 additions & 0 deletions archie/assets/workflow/deep-scan/steps/step-8-cleanup.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ TELEMETRY_STEP8_START=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
rm -f .archie/tmp/archie_sub*_$PROJECT_NAME.json .archie/tmp/archie_rules_$PROJECT_NAME.json .archie/tmp/archie_intent_prompt_${PROJECT_NAME}_*.txt .archie/tmp/archie_enrichment_${PROJECT_NAME}_*.json
```

(Artifacts from the retired drift step — `drift_report.json`, `scan_report.md`, `drift_history/` — are swept by the installer's legacy cleanup at upgrade time, not here: that path is allowlisted, `$PROJECT_ROOT`-anchored, and runs for every workspace.)

```bash
python3 .archie/intent_layer.py deep-scan-state "$PROJECT_ROOT" complete-step 8
```
Loading
Loading