arkgate 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1249 -0
- package/LICENSE +21 -0
- package/README.md +218 -0
- package/SECURITY.md +39 -0
- package/bin/ark-check.mjs +5204 -0
- package/bin/ark-mcp.mjs +898 -0
- package/bin/ark-shared.mjs +1520 -0
- package/bin/ark.mjs +491 -0
- package/dist/eslint/index.cjs +222 -0
- package/dist/eslint/index.cjs.map +1 -0
- package/dist/eslint/index.d.cts +42 -0
- package/dist/eslint/index.d.ts +40 -0
- package/dist/eslint/index.js +193 -0
- package/dist/eslint/index.js.map +1 -0
- package/dist/index.cjs +3080 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +577 -0
- package/dist/index.d.ts +577 -0
- package/dist/index.js +2998 -0
- package/dist/index.js.map +1 -0
- package/dist/nestjs/index.cjs +2332 -0
- package/dist/nestjs/index.cjs.map +1 -0
- package/dist/nestjs/index.d.cts +22 -0
- package/dist/nestjs/index.d.ts +22 -0
- package/dist/nestjs/index.js +2308 -0
- package/dist/nestjs/index.js.map +1 -0
- package/dist/types-DpdVN7Lm.d.cts +1023 -0
- package/dist/types-DpdVN7Lm.d.ts +1023 -0
- package/docs/agent-guide.md +490 -0
- package/docs/ai-gates.md +337 -0
- package/docs/ark-check-example.json +87 -0
- package/docs/assets/ark-write-gate.svg +28 -0
- package/docs/brownfield-adoption.md +87 -0
- package/docs/demos/01-write-gate-self-correction.md +74 -0
- package/docs/demos/02-brownfield-baseline-adoption.md +71 -0
- package/docs/demos/03-copilot-autopilot.md +83 -0
- package/docs/enthusiast/README.md +62 -0
- package/docs/enthusiast/explanation-application-shape.md +29 -0
- package/docs/enthusiast/how-to-agent-gates.md +36 -0
- package/docs/enthusiast/how-to-gallery-starter.md +27 -0
- package/docs/enthusiast/how-to-pick-shape.md +45 -0
- package/docs/enthusiast/how-to-policy-pack.md +37 -0
- package/docs/enthusiast/reference-archetypes.md +36 -0
- package/docs/enthusiast/reference-commands.md +50 -0
- package/docs/enthusiast/tutorial-first-project.md +86 -0
- package/docs/production-hardening.md +59 -0
- package/package.json +125 -0
- package/server.json +39 -0
- package/templates/architecture-playbook.json +339 -0
- package/templates/policy-packs/enthusiast-feature-sliced.json +20 -0
- package/templates/policy-packs/enthusiast-hexagonal.json +18 -0
- package/templates/policy-packs/enthusiast-layered.json +18 -0
- package/templates/policy-packs/enthusiast-monorepo.json +18 -0
- package/templates/skills/ark-adopt.md +103 -0
- package/templates/skills/ark-architect.md +90 -0
- package/templates/skills/ark-autopilot.md +95 -0
- package/templates/skills/ark-contract.md +98 -0
- package/templates/skills/ark-coverage.md +96 -0
- package/templates/skills/ark-explain.md +78 -0
- package/templates/skills/ark-fix.md +96 -0
- package/templates/skills/ark-loop.md +69 -0
- package/templates/skills/ark-place.md +68 -0
- package/templates/skills/ark-runtime.md +62 -0
- package/templates/skills/ark-upgrade.md +109 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ark-autopilot
|
|
3
|
+
description: The end-to-end architecture co-pilot for non-developers. One flow: look at the project, set up the guardrails, then drive the plan to a clean architecture — auto-applying the safe fixes and proposing the rest, always validated by ark-check, never weakening the gate. Composes setup + plan + the apply loop. Autonomous within those limits.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /ark-autopilot — Get to a sound architecture, end to end
|
|
7
|
+
|
|
8
|
+
This is the co-pilot's top-level flow. It composes the three primitives — **plan** (Phase F),
|
|
9
|
+
the guided setup (Phase G), and the **loop** (Phase H) — into one experience that takes a
|
|
10
|
+
non-developer from "I have a project" to "governed, cleaned up, and enforced from now on."
|
|
11
|
+
|
|
12
|
+
**The rule that keeps it safe:** you (the agent) make edits; **Ark decides what may land.** Only
|
|
13
|
+
`mechanical-safe` changes are auto-applied (validated, with rollback); everything `judgment` is
|
|
14
|
+
PROPOSED for a human decision. Code only — never DB/schema, never weakening the gate.
|
|
15
|
+
|
|
16
|
+
## Two entry styles, three operating modes, one contract
|
|
17
|
+
|
|
18
|
+
**Who is driving** (entry style):
|
|
19
|
+
|
|
20
|
+
- **Newbie (default here):** run the WHOLE flow with plain-language explanations and an
|
|
21
|
+
approval prompt before anything non-trivial. The user never needs to know a preset or a rule
|
|
22
|
+
name. This skill is that flow.
|
|
23
|
+
- **Expert:** skip the autopilot and use the pieces directly — `ark init` / `/ark-contract` to
|
|
24
|
+
shape the contract, `ark-check --plan` to see the work, `/ark-fix` for targeted fixes,
|
|
25
|
+
`ark-check --strict-config` as the gate. Point them there and stop.
|
|
26
|
+
|
|
27
|
+
**What Ark is doing right now** (operating mode — read from `ark start` / `--plan` / `--coverage`):
|
|
28
|
+
|
|
29
|
+
- **Suggest** — thin or greenfield project: propose an application shape and install a starter contract.
|
|
30
|
+
- **Adapt** — brownfield or low `governed%`: match the contract to the real layout, raise coverage,
|
|
31
|
+
freeze only real debt. A clean plan with ~0% governed is **not** done — route to `--coverage` / `/ark-adopt`.
|
|
32
|
+
- **Enforce** — `goal.met` is true *and* governed coverage is meaningful: write gate + CI hold the line.
|
|
33
|
+
|
|
34
|
+
Never tell a user "your architecture is guarded" while `--plan` reports `goal.met: false` or
|
|
35
|
+
`governedPercent` is low.
|
|
36
|
+
|
|
37
|
+
## Flow (newbie tier)
|
|
38
|
+
|
|
39
|
+
1. **Set up if needed.** If there's no `ark.config.json`, run the guided setup: `ark start`
|
|
40
|
+
(which itself uses `ark-check --recommend` to suggest a shape in plain language, then writes
|
|
41
|
+
the config + agent/CI gates, and captures the **origin** architecture report under
|
|
42
|
+
`.ark/reports/`). On an established codebase it adopts the real structure. If
|
|
43
|
+
Ark is already set up, skip to step 2.
|
|
44
|
+
|
|
45
|
+
2. **Freeze / confirm the starting picture.** Always run once before changing code:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx ark-check --root . --config ark.config.json --report ark-report.html
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
- If `.ark/reports/origin.json` did not exist, this **creates the origin snapshot** (day-one
|
|
52
|
+
baseline). Do **not** pass `--reset-origin` unless the user explicitly wants a new baseline.
|
|
53
|
+
- Open / point the user at `ark-report.html` (and `.ark/reports/origin.html` when first created).
|
|
54
|
+
- This is the “before” picture the autopilot will improve against.
|
|
55
|
+
|
|
56
|
+
3. **Show the plan.** Run `ark-check --plan` and explain it in outcome terms: how many fixes are
|
|
57
|
+
_safe to auto-apply_ vs _need your decision_ vs _deferred_, and what the goal is (a clean,
|
|
58
|
+
enforced architecture). Confirm before changing anything.
|
|
59
|
+
|
|
60
|
+
4. **Drive the loop.** Hand off to **`/ark-loop`**: in a discardable git worktree, auto-apply
|
|
61
|
+
the `mechanical-safe` steps one at a time (validate with `ark-check`, roll back regressions),
|
|
62
|
+
and PROPOSE each `judgment` step in plain language for a yes/no. Loop until the plan's
|
|
63
|
+
`goal.met` is true or a round makes no progress.
|
|
64
|
+
|
|
65
|
+
5. **Confirm it stays clean.** Verify the gates are installed and active so the architecture is
|
|
66
|
+
enforced from now on (in CI, and at write time if the MCP hook is wired) — the
|
|
67
|
+
"and stays that way" half of the promise. Run the final `ark-check --strict-config`.
|
|
68
|
+
|
|
69
|
+
6. **Close with the after report + evolution.** Run again:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npx ark-check --root . --config ark.config.json --report ark-report.html
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The HTML now includes **Evolution vs origin** (score, governed%, violations, files per layer)
|
|
76
|
+
when origin already existed. Point the user at:
|
|
77
|
+
- `ark-report.html` / `.ark/reports/latest.html` — **after**
|
|
78
|
+
- `.ark/reports/origin.html` — **before** (frozen)
|
|
79
|
+
- `.ark/reports/history/` — optional JSON trail
|
|
80
|
+
|
|
81
|
+
7. **Report honestly, in plain language.** Summarize what was auto-applied, what you proposed
|
|
82
|
+
and the user decided, and what's deferred (and why). Tie the narrative to the before/after
|
|
83
|
+
report numbers. Show the diff. Only merge the worktree back after the user reviews. Never
|
|
84
|
+
report "done / clean" while steps were skipped.
|
|
85
|
+
|
|
86
|
+
## Operating rules
|
|
87
|
+
|
|
88
|
+
- Never weaken the gate to finish: no disabling rules, editing `ark.config.json` to allow a bad
|
|
89
|
+
edge, or baselining a fresh violation. Fix the code, or propose a contract change via
|
|
90
|
+
`/ark-contract` with its before/after impact.
|
|
91
|
+
- If most violations concentrate on one edge, that's a contract smell — stop and route to
|
|
92
|
+
`/ark-contract`, don't grind N fixes.
|
|
93
|
+
- Bias to proposing: when unsure a change preserves behavior, treat it as `judgment`.
|
|
94
|
+
- Everything traces to Ark's own outputs (`ark-check --plan --json`, `--recommend`) — never
|
|
95
|
+
invent architecture advice.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ark-contract
|
|
3
|
+
description: Safely edit ark.config.json (layers, rules, forbiddenGlobals, intent prefixes), validated with strict ark-check. The one sanctioned way to change the architecture contract.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /ark-contract — Evolve the architecture contract safely
|
|
7
|
+
|
|
8
|
+
You are editing `ark.config.json` — the machine-readable contract every gate
|
|
9
|
+
(write gate, CI, ESLint, runtime) enforces. Changes here alter what ALL agents
|
|
10
|
+
and humans are allowed to write, so the bar is: smallest change, validated,
|
|
11
|
+
explained.
|
|
12
|
+
|
|
13
|
+
**No change described?** If invoked with no specific edit, don't guess and don't
|
|
14
|
+
edit anything — the intent is the user's to give. Take the snapshot (step 1) and
|
|
15
|
+
present the evolution options grounded in THIS contract: adopt a `suggestedLayers`
|
|
16
|
+
layer, tighten a permitted/implicit edge to denied, add `forbiddenGlobals` to a
|
|
17
|
+
pure layer, or move a file between layers. While reading the config, surface any
|
|
18
|
+
real classification inconsistency you notice (e.g. an HTTP-client file sitting in
|
|
19
|
+
a non-integration layer via a fallback pattern) — but before calling a move a
|
|
20
|
+
"clean config change", check the file's actual imports against the target layer's
|
|
21
|
+
rules (see step 2's move bullet). Then ask which change to make. Reading the
|
|
22
|
+
contract to produce that is real work, not a stalling question.
|
|
23
|
+
|
|
24
|
+
## Steps
|
|
25
|
+
|
|
26
|
+
1. **Snapshot first** — run `ark-check --root . --config ark.config.json
|
|
27
|
+
--json` and save the result. You must be able to show what the change
|
|
28
|
+
legalized or newly forbids.
|
|
29
|
+
2. **Make the smallest edit** that achieves the user's intent:
|
|
30
|
+
- **New layer**: add `{ name, patterns }`; add `intentPrefixes` if the
|
|
31
|
+
project uses intent naming; wire explicit `rules` edges to its neighbors —
|
|
32
|
+
a layer with no rules is ungoverned, so default to denying edges that match
|
|
33
|
+
the project's existing direction of dependencies.
|
|
34
|
+
- **New rule**: prefer adding a DENIED edge (tightening). For an ALLOWED
|
|
35
|
+
edge (loosening), first check whether any current code depends on it — if
|
|
36
|
+
nothing needs it, don't add it (a permission nobody uses is future debt).
|
|
37
|
+
- **Split a layer into a public surface + internals (the facade fix)**: when a
|
|
38
|
+
check's `summary` shows most violations are ONE edge into a layer (e.g. all of
|
|
39
|
+
app-land importing a kernel/framework), the contract — not the code — is wrong.
|
|
40
|
+
Split the target layer in two: a `<Layer>Api` layer whose patterns cover the
|
|
41
|
+
sanctioned entrypoints app code is meant to import (the target subtrees the
|
|
42
|
+
breakdown points at, e.g. `kernel/app/**`, `kernel/events.ts`), and keep the rest
|
|
43
|
+
as `<Layer>Internal`. Allow the edge into the surface, deny it into internals.
|
|
44
|
+
This legalizes the intended dependency while still forbidding reach-arounds — it
|
|
45
|
+
collapses a wall of false positives to ~0. This is how Ark stays compatible with a
|
|
46
|
+
DI framework: it guards the border, not the framework's insides.
|
|
47
|
+
The surface patterns overlap the internal catch-all, and that is fine: ark-check
|
|
48
|
+
resolves the MOST SPECIFIC pattern per file, so `kernel/app/**` wins over
|
|
49
|
+
`kernel/**` regardless of layer order. Where app code today reaches into internals
|
|
50
|
+
for a legitimate entrypoint, do NOT rewrite every call site: add a barrel module
|
|
51
|
+
inside the surface layer (e.g. `src/kernel/app/facade.ts`) that re-exports exactly
|
|
52
|
+
those entrypoints, then repoint the reach-around imports to the barrel. It is
|
|
53
|
+
behavior-preserving (verify with `tsc --noEmit`) and the imports are now legal.
|
|
54
|
+
- **forbiddenGlobals**: adding one to a domain layer may reveal existing
|
|
55
|
+
violations — run the check, and if there are hits, fix them (`/ark-fix`
|
|
56
|
+
patterns). If they are too numerous to fix now, freezing them in the
|
|
57
|
+
baseline is a valid stopgap but requires explicit user approval first (it
|
|
58
|
+
silences the new violations); never skip the guard because the code is
|
|
59
|
+
dirty today.
|
|
60
|
+
- **Move a file to another layer**: only a config change if the file's
|
|
61
|
+
imports are ALREADY legal under the target layer's rules. Read the file's
|
|
62
|
+
imports, resolve each to its layer, and check the target may import that
|
|
63
|
+
layer. If the file mixes concerns the target can't reach (e.g. an HTTP
|
|
64
|
+
client that also reads a persistence-layer cache, where
|
|
65
|
+
`Integration → Persistence` is denied), moving it BREAKS the contract —
|
|
66
|
+
that's a refactor (split the file so the pure part moves), not a config
|
|
67
|
+
edit. Say so instead of recommending the move; don't discover it only after
|
|
68
|
+
editing the config.
|
|
69
|
+
3. **Validate** — `ark-check --root . --config ark.config.json
|
|
70
|
+
--strict-config` (strict makes config warnings fail; that's intended here).
|
|
71
|
+
4. **Diff the impact** — compare violations before/after. New violations from a
|
|
72
|
+
tightening are expected: list them and fix them now if the set is small; if
|
|
73
|
+
it's large, the baseline stopgap from step 2 applies (approval required).
|
|
74
|
+
|
|
75
|
+
## Related onboarding
|
|
76
|
+
|
|
77
|
+
- Greenfield: adopt shape first via `/ark-architect`, `ark init --archetype`, or
|
|
78
|
+
`ark-check --apply-policy-pack enthusiast-<preset>`.
|
|
79
|
+
- `ark-check --recommend --write-plan` may suggest a `policyPack` in `ark-adoption-plan.json`.
|
|
80
|
+
- Brownfield: prefer `/ark-adopt` before large contract edits.
|
|
81
|
+
|
|
82
|
+
## Operating rules
|
|
83
|
+
|
|
84
|
+
- **Loosening the contract to silence a violation is refused by default.** If
|
|
85
|
+
the user asks for an allowed-edge whose only motivation is one red check,
|
|
86
|
+
explain the port/adapter alternative first (one plain-language paragraph) and
|
|
87
|
+
only proceed if they confirm they want the architectural exception.
|
|
88
|
+
- Keep rules explicit: when adding a layer, state in the report which edges you
|
|
89
|
+
denied and why, so a novice reading it learns the dependency direction.
|
|
90
|
+
- Update generated rule files if the contract summary embedded in them changed:
|
|
91
|
+
re-run `ark-check --install-agent-gates` (no `--force`; mention any
|
|
92
|
+
skipped-because-customized files).
|
|
93
|
+
|
|
94
|
+
## Verify and report
|
|
95
|
+
|
|
96
|
+
End with a passing strict check (or a committed baseline decision). Report:
|
|
97
|
+
the exact config diff, before/after violation counts, what is now
|
|
98
|
+
possible/forbidden in one sentence each, and any follow-ups.
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ark-coverage
|
|
3
|
+
description: Audit which Ark capabilities this project isn't using and report how to close each gap, ranked by value. Autonomous — reads the repo, decides, reports.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /ark-coverage — What Ark can do for you that you're not using
|
|
7
|
+
|
|
8
|
+
You are auditing this project's use of the `arkgate` package. Work
|
|
9
|
+
autonomously: read everything from the repo, never ask questions you can answer
|
|
10
|
+
from files, and end with a ranked report.
|
|
11
|
+
|
|
12
|
+
## Related onboarding
|
|
13
|
+
|
|
14
|
+
- **Greenfield** (new or empty repo): low `governed.percent` → suggest `/ark-architect` or
|
|
15
|
+
`ark-check --recommend`; `ark-check --doctor` includes a "New here?" nudge with
|
|
16
|
+
`recommendCommand` / `initCommand`. Enthusiast track: `docs/enthusiast/how-to-agent-gates.md`.
|
|
17
|
+
- **Brownfield** (existing messy repo): use `/ark-adopt` and `docs/brownfield-adoption.md` —
|
|
18
|
+
diagnose → classify → freeze only real debt. Do **not** send brownfield users to `/ark-architect`.
|
|
19
|
+
|
|
20
|
+
## Operating rules
|
|
21
|
+
|
|
22
|
+
- Gather inputs yourself: `ark.config.json`, `package.json`, `.ark-baseline.json`,
|
|
23
|
+
`.mcp.json`, `AGENTS.md`, agent config dirs (`.claude/`, `.cursor/`, `.codex/`,
|
|
24
|
+
`.windsurf/`, `.clinerules/`, `.kiro/`, `.github/`), CI workflows, and the source tree.
|
|
25
|
+
Read files with the Read tool and use targeted commands — do NOT `cat` whole
|
|
26
|
+
configs or dump the full source tree to the terminal; the report is the output,
|
|
27
|
+
not the raw files. Keep discovery quiet so the run stays readable.
|
|
28
|
+
- This skill makes no changes to project files by default: produce the report,
|
|
29
|
+
then offer to apply the top recommendations. Do not modify files unless the
|
|
30
|
+
user then says yes. (Running `ark-check` may write its own scan cache under
|
|
31
|
+
`node_modules/.cache/` — that's fine; it never touches your source.)
|
|
32
|
+
- Explain each gap in plain language a developer new to architecture governance
|
|
33
|
+
can follow — one sentence of "why this matters" per finding, no jargon without
|
|
34
|
+
a one-line definition.
|
|
35
|
+
|
|
36
|
+
## Checklist to audit (compare repo reality against each capability)
|
|
37
|
+
|
|
38
|
+
1. **Config exists and is strict-clean** — is there an `ark.config.json`? Does
|
|
39
|
+
`ark-check --root . --config ark.config.json --strict-config` pass? Run it.
|
|
40
|
+
2. **Baseline ratchet** — if the check reports violations, is `.ark-baseline.json`
|
|
41
|
+
in use (`--baseline`)? An adopting codebase without a baseline blocks CI or,
|
|
42
|
+
worse, runs without the gate.
|
|
43
|
+
3. **AI write gate per tool** — for every agent config dir that exists, is the Ark
|
|
44
|
+
gate wired? Claude: `PreToolUse` hook calling `ark-mcp --hook` in
|
|
45
|
+
`.claude/settings.json`. Cursor: `.cursor/mcp.json` + `.cursor/rules/ark.mdc`.
|
|
46
|
+
Codex: MCP server registered. Windsurf/Cline/Copilot/Kiro: rule file present.
|
|
47
|
+
4. **Ark skills installed per tool** — do the detected tools have the `/ark-*`
|
|
48
|
+
skills (`.claude/skills/ark-*`, `.cursor/commands/ark-*.md`, etc.)? If not:
|
|
49
|
+
`ark-check --install-agent-gates`.
|
|
50
|
+
5. **CI gate** — `.github/workflows/ark-check.yml` (or equivalent) present and
|
|
51
|
+
running `ark-check`? Is `--require-gates` used so missing gates fail CI?
|
|
52
|
+
6. **ESLint plugin** — is `arkgate/eslint` configured for in-editor
|
|
53
|
+
feedback? (Check eslint config files.)
|
|
54
|
+
7. **Domain purity** — do domain-model layers declare `forbiddenGlobals`
|
|
55
|
+
(e.g. `fetch`, `process`, `Date.now`, `Math.random`)? If domain code calls these
|
|
56
|
+
directly, recommend adding the guard.
|
|
57
|
+
8. **Governed fraction (the headline honesty number)** — call the **`ark_coverage`**
|
|
58
|
+
MCP tool if the `ark` server is available, else run
|
|
59
|
+
`ark-check --root . --config ark.config.json --coverage --json`. It returns
|
|
60
|
+
`governed` (`{ classifiedFiles, totalFiles, percent }`), per-layer file counts, the
|
|
61
|
+
FULL `unclassified` list, `emptyLayers` (patterns matching nothing — usually wrong
|
|
62
|
+
globs, the #1 monorepo mistake), and `suggestions` (each ungoverned directory with a
|
|
63
|
+
PROPOSED canonical layer, or flagged as unrecognized). Lead your report with
|
|
64
|
+
`governed.percent`: **a green check over a low fraction is a false green — the
|
|
65
|
+
codebase is mostly UNCHECKED, not clean.** For every ungoverned directory, give the
|
|
66
|
+
`suggestions` layer as the fix ("classify `src/lib/repositories` → PersistenceAdapters
|
|
67
|
+
via /ark-contract"); for `unrecognized` ones, say it's the user's call. Do NOT
|
|
68
|
+
hand-roll this with `find`/`readdir`.
|
|
69
|
+
9. **Concentrated violations = a contract smell, not debt** — run a normal check
|
|
70
|
+
(`ark-check … --json`) and read `summary`. If `summary.concentrated` is true (most
|
|
71
|
+
violations on one edge), flag it: the contract is probably wrong, not the code — e.g.
|
|
72
|
+
app-land reaching a framework/kernel through a sanctioned entrypoint. Recommend fixing
|
|
73
|
+
the contract (allow the edge, or split the target layer into a public surface +
|
|
74
|
+
internals — /ark-contract) over freezing the false positives.
|
|
75
|
+
10. **Rule coverage** — the `--coverage --json` output lists `layersWithoutRules`:
|
|
76
|
+
layers with no rule edge at all can import anything. Flag those where the
|
|
77
|
+
dependency direction is obvious (e.g. domain → adapters should be denied).
|
|
78
|
+
11. **Runtime kernel** — does the app hand-roll things the kernel ships? Grep for
|
|
79
|
+
homemade event buses, outbox tables, audit logs, workflow/saga orchestration,
|
|
80
|
+
projections. If found, point to the matching `arkgate` module
|
|
81
|
+
(event-bus, outbox, audit, workflow, projections) and `/ark-runtime`. But if the
|
|
82
|
+
repo already runs a DI/kernel framework (dcouplr, NestJS), do NOT recommend
|
|
83
|
+
replacing it — Ark governs the border around it, it doesn't supplant it.
|
|
84
|
+
12. **NestJS adapters** — if `@nestjs/common` is a dependency and
|
|
85
|
+
`arkgate/nestjs` is unused, flag it.
|
|
86
|
+
|
|
87
|
+
## Output format
|
|
88
|
+
|
|
89
|
+
A ranked table (highest value first), then a one-paragraph summary:
|
|
90
|
+
|
|
91
|
+
| # | Unused capability | Evidence in this repo | How to enable (exact command or file) |
|
|
92
|
+
|
|
93
|
+
Close with: "Want me to apply the top N? I'll run the commands/diffs and finish
|
|
94
|
+
with a strict `ark-check`." Apply only what the user approves, then verify with
|
|
95
|
+
`ark-check --root . --config ark.config.json --strict-config` and report the
|
|
96
|
+
final state.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ark-explain
|
|
3
|
+
description: Explain this project's architecture in plain language and generate the showcase HTML report — layers, rules, coverage, gates, and why the contract exists.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /ark-explain — Understand this project's architecture
|
|
7
|
+
|
|
8
|
+
The user wants to understand the architecture, a specific rule, or why the gate blocked them.
|
|
9
|
+
Your job is to **teach with this repo's real data** and leave a shareable visual artifact.
|
|
10
|
+
|
|
11
|
+
## Always do this first (showcase report)
|
|
12
|
+
|
|
13
|
+
1. Run the full HTML report (uses the real contract + coverage + gates):
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx ark-check --root . --config ark.config.json --report ark-report.html
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Prefer the project's package-manager runner if gates already emit one
|
|
20
|
+
(`pnpm … exec ark-check` / `yarn` / `npx`).
|
|
21
|
+
|
|
22
|
+
This also maintains snapshots under **`.ark/reports/`**:
|
|
23
|
+
- `origin.json` / `origin.html` — frozen **first** report (start of the journey)
|
|
24
|
+
- `latest.json` / `latest.html` — every run
|
|
25
|
+
- `history/*.json` — last ~20 machine-readable points for later tooling
|
|
26
|
+
|
|
27
|
+
If origin already exists, the HTML includes **Evolution vs origin** (score, governed%,
|
|
28
|
+
violations, files per layer). Do not delete origin unless the user explicitly wants a
|
|
29
|
+
new baseline (`--reset-origin`).
|
|
30
|
+
|
|
31
|
+
2. Tell the user the path to `ark-report.html` and `.ark/reports/origin.html`.
|
|
32
|
+
Mention `.ark/` should stay gitignored (Ark appends that on first report when possible).
|
|
33
|
+
|
|
34
|
+
3. Optionally also run:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npx ark-check --coverage
|
|
38
|
+
npx ark-check --doctor
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
so your spoken explanation matches the report's governed% and operating mode
|
|
42
|
+
(SUGGEST / ADAPT / ENFORCE).
|
|
43
|
+
|
|
44
|
+
The HTML report is the visual twin of this skill: architecture map, files per layer,
|
|
45
|
+
dependency direction, matrix, violations, enforcement points, Ark fitness score, and a
|
|
46
|
+
**Senior diagnostics** block (coupling fan-in/out, deny density, purity surface, pattern
|
|
47
|
+
forensics, baseline taxonomy) for tech leads.
|
|
48
|
+
|
|
49
|
+
## Spoken / written explanation
|
|
50
|
+
|
|
51
|
+
1. **Load the real contract**: `ark.config.json`, `ark://manifest` if available, `AGENTS.md`.
|
|
52
|
+
2. **If asked generally** ("explain the architecture"), produce a guided tour:
|
|
53
|
+
- Operating mode + governed% (honest: low coverage means green checks almost nothing).
|
|
54
|
+
- Each major layer: name, purpose, one real file from this repo, file count if known.
|
|
55
|
+
- Dependency direction in one short diagram (ASCII is fine).
|
|
56
|
+
- Enforcement points that are actually on: write gate, CI, ESLint, baseline.
|
|
57
|
+
- If a DI/kernel framework border exists, explain public surface vs internals.
|
|
58
|
+
3. **If asked about a specific rule or block**, answer with: the rule, the consequence it
|
|
59
|
+
prevents, and the sanctioned fix (usually a port) — offer `/ark-fix`.
|
|
60
|
+
4. **If asked "what's a port/adapter/saga…"**, two sentences + this-repo example or conventional path.
|
|
61
|
+
|
|
62
|
+
## Operating rules
|
|
63
|
+
|
|
64
|
+
- Prefer generating the HTML report even when the question is narrow — then zoom the prose.
|
|
65
|
+
- Read-only for source code: this skill does not refactor product files (writing the report
|
|
66
|
+
HTML is fine).
|
|
67
|
+
- Calibrate depth: one-rule questions get a paragraph; full tours get structure + report.
|
|
68
|
+
- Every jargon term gets a one-line plain definition on first use.
|
|
69
|
+
- End with:
|
|
70
|
+
- the strict check from `package.json` (or `ark-check --root . --config ark.config.json --strict-config`)
|
|
71
|
+
- `/ark-place` for "where does new code go?"
|
|
72
|
+
- the path to `ark-report.html`
|
|
73
|
+
|
|
74
|
+
## Related
|
|
75
|
+
|
|
76
|
+
- Onboarding: `/ark-architect`, `ark-check --recommend`, `docs/enthusiast/README.md`
|
|
77
|
+
- Brownfield: `/ark-adopt`, `docs/brownfield-adoption.md`
|
|
78
|
+
- Autopilot: `/ark-autopilot` after the user understands the contract
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ark-fix
|
|
3
|
+
description: Resolve Ark architecture violations at the root cause — fix the code (ports, adapters, moves), never weaken the contract. Runs ark-check, fixes, verifies.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /ark-fix — Fix architecture violations properly
|
|
7
|
+
|
|
8
|
+
You are resolving violations reported by `ark-check` or by the Ark write gate.
|
|
9
|
+
Work autonomously end to end: diagnose, fix, verify. Do not ask the user to
|
|
10
|
+
paste output you can generate yourself.
|
|
11
|
+
|
|
12
|
+
## Operating rules
|
|
13
|
+
|
|
14
|
+
- First action: run `ark-check --root . --config ark.config.json --json`
|
|
15
|
+
(add `--baseline .ark-baseline.json` if that file exists) to get the current
|
|
16
|
+
violation list. If the user quoted a specific gate block, start from that one.
|
|
17
|
+
- **Check `summary` before fixing code.** If `summary.concentrated` is true — most
|
|
18
|
+
violations are ONE edge — the fix is almost certainly the CONTRACT, not N code
|
|
19
|
+
changes: app-land is reaching a framework/kernel through a sanctioned entrypoint,
|
|
20
|
+
or a layer needs splitting into a public surface + internals. Stop and hand off to
|
|
21
|
+
`/ark-contract`; don't port-and-adapter your way through hundreds of false
|
|
22
|
+
positives. Fix code only for the genuine, scattered minority.
|
|
23
|
+
- **Fix value edges before type-only ones.** `summary` splits `valueCount` (real
|
|
24
|
+
runtime coupling) from `typeOnlyCount` (`import type …` — erased at compile time, no
|
|
25
|
+
runtime dependency). Prioritize the value edges; a `typeOnly: true` violation almost
|
|
26
|
+
always just means a type lives in the wrong layer (see the type-only pattern below).
|
|
27
|
+
- **Never weaken the gate.** Do not edit `ark.config.json`, add allowed edges,
|
|
28
|
+
delete rules, or regenerate the baseline to make a violation disappear. The fix
|
|
29
|
+
lives in the code. If you become convinced the contract itself is wrong, stop
|
|
30
|
+
and say so with your reasoning — changing the contract is `/ark-contract` and a
|
|
31
|
+
human decision.
|
|
32
|
+
- Take defaults silently and list them at the end. Stop only for destructive
|
|
33
|
+
moves (deleting files, rewriting public APIs).
|
|
34
|
+
|
|
35
|
+
## How to fix each violation class
|
|
36
|
+
|
|
37
|
+
- **Forbidden cross-layer import** (e.g. domain imports a persistence adapter):
|
|
38
|
+
invert the dependency. Define a port (interface) in the layer that needs the
|
|
39
|
+
capability, implement it in the layer that has it, and inject the
|
|
40
|
+
implementation at composition time. Read `ark://manifest` (MCP) or
|
|
41
|
+
`ark.config.json` to see which layers may see which.
|
|
42
|
+
- **File in the wrong layer**: if the import is legitimate but the file lives in
|
|
43
|
+
the wrong directory, move the file to the layer it behaves like and update
|
|
44
|
+
imports. Prefer the smallest move that makes the graph legal.
|
|
45
|
+
- **Forbidden global in domain** (`fetch`, `process`, `Date.now`, `Math.random`, …):
|
|
46
|
+
inject the capability. Add a port (e.g. `Clock`, `IdGenerator`, `HttpPort`)
|
|
47
|
+
with the impure implementation outside the domain, and pass it in.
|
|
48
|
+
- **Intent prefix mismatch**: rename the intent to the layer's declared prefix,
|
|
49
|
+
or move the handler to the layer that owns that prefix.
|
|
50
|
+
- **Type-only inversion** (a lower layer `import type`s something from an upper layer,
|
|
51
|
+
e.g. a domain module importing a type that happens to live in a UI hook): move the
|
|
52
|
+
TYPE down to the layer that owns it (e.g. `src/lib/<domain>/types.ts`), and re-export
|
|
53
|
+
it from the original module for back-compat (`export type { X } from "@/lib/<domain>/types"`)
|
|
54
|
+
so no consumer breaks. This is the highest-volume, safest adoption fix — verify with
|
|
55
|
+
`tsc --noEmit`. It often also breaks a circular dependency that ran through the hook.
|
|
56
|
+
Two cases where the move is NOT mechanical — stop and flag instead of forcing it:
|
|
57
|
+
(a) the type extends a persistence/ORM row (e.g. a Drizzle schema type) — moving it to a
|
|
58
|
+
domain layer would couple domain→Persistence (the write gate will block it), so it needs a
|
|
59
|
+
domain-owned type or port, not a move; (b) the source file mixes the type with runtime
|
|
60
|
+
logic (stubs, helpers, mock builders) — split the types into their own module first, then
|
|
61
|
+
move.
|
|
62
|
+
- **Raw infrastructure access in an orchestration/UI layer** (a route/handler or component
|
|
63
|
+
that runs SQL or imports the DB client directly — e.g. `sqlClient\`SELECT …\`` or
|
|
64
|
+
`import { db } from "@/lib/db"` inside `src/app/**`): this is the value-import counterpart
|
|
65
|
+
to the type-only inversion, and the biggest brownfield cluster. Relocate the data-access
|
|
66
|
+
VERBATIM into a repository/adapter layer: add a business-named method to the repository
|
|
67
|
+
(`ordersRepository.listOpen(projectId)`) containing the SAME query byte-for-byte, and have
|
|
68
|
+
the route call it. Same SQL = same behavior by construction — do NOT rewrite the query
|
|
69
|
+
(`tsc` can't prove two queries return the same rows; a reworded `WHERE` silently changes
|
|
70
|
+
results). Prefer extending an existing domain repository over creating a new one. Two
|
|
71
|
+
cautions: (a) this edits the data layer, which many repos reserve to core maintainers —
|
|
72
|
+
if a `CLAUDE.md`/CODEOWNERS rule restricts it, migrate one route as a demonstrated pattern
|
|
73
|
+
and hand the bulk to a maintainer rather than sweeping hundreds autonomously; (b) a route
|
|
74
|
+
with interleaved transactions / 10+ queries is not a pure relocation — flag it for review.
|
|
75
|
+
See the brownfield burn-down playbook (`docs/brownfield-adoption.md`) for the full sequence.
|
|
76
|
+
|
|
77
|
+
Fix ALL reported violations that share a root cause in one pass — one port in a
|
|
78
|
+
shared module beats N per-file patches. Match the codebase's existing naming and
|
|
79
|
+
port conventions before inventing new ones.
|
|
80
|
+
|
|
81
|
+
## Related onboarding
|
|
82
|
+
|
|
83
|
+
- Prefer `fixClass` / `enthusiastHint` from `ark-check --json` when present.
|
|
84
|
+
- Brownfield burn-down: `/ark-adopt` first; demo `docs/demos/02-brownfield-baseline-adoption.md`.
|
|
85
|
+
- Greenfield: `/ark-architect` prevents many violations before they exist.
|
|
86
|
+
|
|
87
|
+
## Verify and report
|
|
88
|
+
|
|
89
|
+
After edits, run `ark-check --root . --config ark.config.json --strict-config`
|
|
90
|
+
(plus the project's test command if one exists in `package.json`). If the check
|
|
91
|
+
still fails, keep fixing — do not end the turn with a red check unless you are
|
|
92
|
+
blocked on a genuine contract question.
|
|
93
|
+
|
|
94
|
+
Report: violations fixed (before → after count), what pattern you applied
|
|
95
|
+
(in plain language — assume the reader may not know what a "port" is: one line
|
|
96
|
+
of definition), defaults taken, anything intentionally left for the user.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ark-loop
|
|
3
|
+
description: Drive Ark's remediation plan to a clean architecture — a safe, reversible apply loop. Auto-applies only the changes Ark classes mechanical-safe (validating each with ark-check and rolling back regressions), proposes the judgment ones for your decision, and never weakens the gate. Autonomous within those limits.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /ark-loop — Drive the plan to a clean architecture (safely)
|
|
7
|
+
|
|
8
|
+
This is the co-pilot's **loop** primitive: read Ark's classified **plan**, work toward the
|
|
9
|
+
**goal** (zero active violations without weakening the contract), one small step at a time,
|
|
10
|
+
validating every change with `ark-check` and rolling back anything that fails or regresses.
|
|
11
|
+
|
|
12
|
+
**The rule that makes this safe:** you (the agent) make edits; **Ark decides whether they're
|
|
13
|
+
allowed to land.** Only changes Ark classed `mechanical-safe` are auto-applied. Everything
|
|
14
|
+
`judgment` is PROPOSED for a human decision — never applied silently. Code only: never touch
|
|
15
|
+
DB schemas, migrations, or generated files.
|
|
16
|
+
|
|
17
|
+
If Ark isn't set up yet, run `ark start` (or `ark-check --recommend` then `ark init`) first.
|
|
18
|
+
|
|
19
|
+
## Steps
|
|
20
|
+
|
|
21
|
+
1. **Read the plan.** Run `ark-check --plan --json` (add `--baseline .ark-baseline.json` if the
|
|
22
|
+
repo uses a baseline). It returns `goal` (with `met`, `activeViolations`, `autoApplicable`,
|
|
23
|
+
`needsDecision`, `deferred`) and `steps[]`, each tagged `class` (`mechanical-safe` /
|
|
24
|
+
`judgment` / `deferred`) with a `confidence` and a plain-language `rationale`. If
|
|
25
|
+
`goal.met` is already true, report "nothing to do" and stop.
|
|
26
|
+
|
|
27
|
+
2. **Work in a discardable git worktree.** Create one (`git worktree add`) so the entire run is
|
|
28
|
+
reversible and never disturbs the user's working tree. Do all edits there. Nothing is
|
|
29
|
+
permanent until the user reviews the final diff.
|
|
30
|
+
|
|
31
|
+
3. **Apply the `mechanical-safe` steps, one at a time, validated.** For each such step
|
|
32
|
+
(e.g. a type-only import moved to the layer that owns it + a re-export for back-compat):
|
|
33
|
+
- Record the current active-violation count from the plan.
|
|
34
|
+
- Make the edit at the SOURCE (fix the placement; don't add an `ark-*-disable` or edit the
|
|
35
|
+
baseline/config to hide it).
|
|
36
|
+
- Re-run the gate: `ark-check --root . --config ark.config.json --strict-config`
|
|
37
|
+
(or `ark-check --baseline` in ratchet repos). **Keep** the change only if the targeted
|
|
38
|
+
violation is gone AND no NEW violation appeared. Otherwise **roll it back**
|
|
39
|
+
(`git checkout -- <files>`) and mark the step deferred with a one-line reason.
|
|
40
|
+
|
|
41
|
+
4. **Propose the `judgment` steps — do not auto-apply.** For each, present in plain language:
|
|
42
|
+
what it is, the `rationale`, and a concrete proposed approach (e.g. "move this data access
|
|
43
|
+
into a repository," "inject a Clock port"). Apply only the ones the user approves, each with
|
|
44
|
+
the same validate-or-rollback discipline. Repository organization and cross-module refactors
|
|
45
|
+
are the user's call.
|
|
46
|
+
|
|
47
|
+
5. **Loop until dry.** Re-read `ark-check --plan --json` after a round — fixing one edge can
|
|
48
|
+
change others. Repeat step 3 while new `mechanical-safe` steps appear and progress is being
|
|
49
|
+
made. Stop when `goal.met` is true, or when a round applies nothing new (no-progress), or
|
|
50
|
+
when only `judgment`/`deferred` steps remain.
|
|
51
|
+
|
|
52
|
+
6. **Report honestly.** Show the final diff and a summary: what was AUTO-APPLIED (validated),
|
|
53
|
+
what is PROPOSED (awaiting your decision), and what was DEFERRED (and why). Never report a
|
|
54
|
+
clean/green result while steps were skipped. Only merge the worktree back after the user
|
|
55
|
+
reviews. When invoked from **`/ark-autopilot`**, the parent skill already owns the
|
|
56
|
+
before/after HTML reports (`--report` + `.ark/reports/` origin/latest). If you are running
|
|
57
|
+
standalone and the user wants a visual close-out, end with
|
|
58
|
+
`ark-check --report ark-report.html` so evolution vs origin is updated.
|
|
59
|
+
|
|
60
|
+
## Operating rules
|
|
61
|
+
|
|
62
|
+
- Never weaken the gate to make the loop finish: no disabling rules, editing
|
|
63
|
+
`ark.config.json` to allow a bad edge, or baselining a fresh violation. Fix the code, or
|
|
64
|
+
propose a contract change via `/ark-contract` with its before/after impact.
|
|
65
|
+
- If most violations concentrate on one edge, that's a contract smell, not N fixes — stop the
|
|
66
|
+
loop and hand off to `/ark-contract` (a broad `--plan` will show the concentration).
|
|
67
|
+
- `mechanical-safe` is deliberately narrow. When unsure whether a change preserves behavior,
|
|
68
|
+
treat it as `judgment` and propose it. A wrong auto-apply costs more than an extra click.
|
|
69
|
+
- Verify with the gate, not by eye: a step counts as done only when `ark-check` confirms it.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ark-place
|
|
3
|
+
description: "Where does new code go? Names the layer, directory, and naming for a new artifact from the contract, and scaffolds it there. Autonomous."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# /ark-place — Where does this code go?
|
|
7
|
+
|
|
8
|
+
The user describes something they need to build (a saga, a background job, an
|
|
9
|
+
event handler, a repository, an HTTP client, a use case, a projection, …).
|
|
10
|
+
Your job: name the layer it belongs to, the directory, the naming convention,
|
|
11
|
+
and — if they asked to build it — scaffold it there correctly.
|
|
12
|
+
|
|
13
|
+
**No artifact given?** If the skill is invoked with nothing to place, don't error
|
|
14
|
+
and don't guess — the artifact is the one thing only the user knows. Read the
|
|
15
|
+
contract (step 1) and print the placement map from it: one row per declared layer
|
|
16
|
+
with what belongs there, its directory, and which layers it may/may not import,
|
|
17
|
+
plus the not-yet-adopted `suggestedLayers` as a footnote. Then ask what they want
|
|
18
|
+
to place. That map is derived entirely from the repo, so producing it is real work,
|
|
19
|
+
not a stalling question.
|
|
20
|
+
|
|
21
|
+
## Steps
|
|
22
|
+
|
|
23
|
+
1. **Read the contract, not your intuition.** If the `ark` MCP server is available,
|
|
24
|
+
call the **`ark_place`** tool with the target file path — it returns the layer,
|
|
25
|
+
its forbidden globals, and exactly which layers the file may / must not import,
|
|
26
|
+
straight from the contract (no guessing). Otherwise load `ark.config.json` and the
|
|
27
|
+
`ark://manifest` MCP resource (it includes `suggestedLayers` with conventional
|
|
28
|
+
directories for layers not yet adopted). The project's `AGENTS.md` placement table,
|
|
29
|
+
if present, is authoritative too.
|
|
30
|
+
2. **Classify the artifact** by what it does, not what it's called:
|
|
31
|
+
- Pure business rules/entities/value objects → domain-model layer.
|
|
32
|
+
- Orchestrates a use case, no I/O of its own → application layer.
|
|
33
|
+
- Talks to a database, queue, API, filesystem → an adapter layer on the side
|
|
34
|
+
that matches the direction (driven/persistence vs driving/http).
|
|
35
|
+
- Reacts to events, long-running coordination (saga/workflow), scheduled
|
|
36
|
+
jobs, projections → the event/workflow layers if the config declares them.
|
|
37
|
+
3. **Answer concretely**: layer name, target directory (from the layer's
|
|
38
|
+
`patterns`), intent-name prefix if the layer declares `intentPrefixes`, and
|
|
39
|
+
which layers it may/may not import (from `rules`).
|
|
40
|
+
4. **If the layer isn't adopted yet** (suggested but no directory): say so,
|
|
41
|
+
give the conventional directory from `suggestedLayers`, and offer
|
|
42
|
+
`/ark-contract` to adopt it — don't silently drop the code into a
|
|
43
|
+
wrong-but-existing layer.
|
|
44
|
+
5. **If asked to create it**: scaffold the file(s) in place, following the
|
|
45
|
+
nearest existing sibling's style, and any port/adapter split the rules force.
|
|
46
|
+
|
|
47
|
+
## Operating rules
|
|
48
|
+
|
|
49
|
+
- Never ask "which layer do you prefer?" — the contract decides; you translate.
|
|
50
|
+
Only surface a question when the artifact genuinely spans two legal designs
|
|
51
|
+
with different trade-offs, and then recommend one.
|
|
52
|
+
- Explain the placement in one plain-language sentence ("this goes in
|
|
53
|
+
`src/domain` because it's a business rule that shouldn't know about the
|
|
54
|
+
database") — assume the user may be new to layered architecture.
|
|
55
|
+
|
|
56
|
+
## Related onboarding
|
|
57
|
+
|
|
58
|
+
- Run **after** shape adoption: `/ark-architect` or `ark init --archetype` on greenfield;
|
|
59
|
+
`/ark-adopt` on brownfield.
|
|
60
|
+
- `ark-check --recommend` / MCP `ark_recommend` picks phase-1 dirs; gallery starters in
|
|
61
|
+
`examples/*-starter/` show correct placement per archetype.
|
|
62
|
+
- Related demos: `docs/demos/` (write-gate self-correction, brownfield, autopilot).
|
|
63
|
+
|
|
64
|
+
## Verify and report
|
|
65
|
+
|
|
66
|
+
If you created files, run `ark-check --root . --config ark.config.json
|
|
67
|
+
--strict-config` and make it pass. Report: placement + why, files created (if
|
|
68
|
+
any), and the import rules the new code must respect going forward.
|