Skip to content

Commit 73ba219

Browse files
committed
feat(container): dynamic system prompts, agent cleanup, and TOUR
Introduce component-based system prompt templating with generate script, clean up agent-system plugin by removing unused scripts/skills/agents, relocate user-level rules out of container defaults, and add codebase navigation docs (TOUR.md, per-package CLAUDE.md files).
1 parent d9cb2db commit 73ba219

40 files changed

Lines changed: 1299 additions & 2273 deletions

CLAUDE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This repository contains three packages. Each package manages its own dependencies independently.
44

5+
For codebase navigation, see [TOUR.md](TOUR.md).
6+
57
## Packages
68

79
| Package | Runtime | Package Manager |

TOUR.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Codebase Tour
2+
3+
## Quick Reference
4+
5+
- **Repo shape:** Monorepo with 3 independent packages — `container/`, `cli/`, `docs/`
6+
- **Languages/Runtimes:** Node.js (container, docs), TypeScript on Bun (cli), Python via pytest (container plugin tests)
7+
- **Package Managers:** npm (`container/`, `docs/`), bun (`cli/`)
8+
- **Test Frameworks:** pytest + `test.js` (container), `bun test` (cli), `astro build` with `starlight-links-validator` (docs)
9+
- **Entry Points:** `container/setup.js`, `cli/src/index.ts`, `docs/astro.config.mjs`
10+
- **Build commands:** `cd container && npm test` · `cd cli && bun test` · `cd docs && npm run build`
11+
12+
## If you need to find...
13+
14+
**Devcontainer install/setup logic**: Start at `container/setup.js` (the `@coredirective/cf-container` npm entry — copies `.devcontainer/` into target projects with checksum/update/preserve semantics). Runtime container declaration is `container/.devcontainer/devcontainer.json` (features, settings, port mappings). The `postStartCommand` orchestrator is `container/.devcontainer/scripts/setup.sh`, which dispatches gated `setup-*.sh` subscripts based on `container/.codeforge/container.json` flags.
15+
16+
**Plugin system**: Plugins live at `container/.devcontainer/plugins/devs-marketplace/plugins/`. There are 13 plugins: `agent-system`, `auto-code-quality`, `codeforge-lsp`, `dangerous-command-blocker`, `git-workflow`, `notify-hook`, `prompt-snippets`, `protected-files-guard`, `session-context`, `skill-engine`, `spec-workflow`, `ticket-workflow`, `workspace-scope-guard`. Plugin hook scripts are Python; unit tests are in `container/tests/plugins/` (loaded via `importlib` for isolation).
17+
18+
**Claude Code config defaults and deploy manifest**: Packaged defaults are in `container/.devcontainer/defaults/codeforge/`. Deploy logic is driven by `container/.devcontainer/defaults/codeforge/file-manifest.json` (id/src/dest/overwrite per file). Project-only overrides and state live in `container/.codeforge/` — never put defaults there.
19+
20+
**System prompts and Claude profiles**: Master template at `container/.devcontainer/defaults/codeforge/claude/system-prompts/template.md` (Jinja2; composes 14 component partials in `components/`, renders to `main.md`/`orchestrator.md`/`writing.md`). Claude Code settings base + model/context profile overlays: `container/.devcontainer/defaults/codeforge/claude/settings/base.json` and `claude/settings/profiles/*.json`; rendered via `generate-settings-profiles.js`.
21+
22+
**CLI commands and command registry**: Entry point `cli/src/index.ts` wires all `registerXxxCommand(parent)` modules. Commands live in `cli/src/commands/<domain>/`. Data access is centralized in `cli/src/loaders/` (reads `~/.claude/` files); output rendering in `cli/src/output/` (text/json/stats per domain).
23+
24+
**`codeforge session search`**: Command module `cli/src/commands/session/search.ts`. Streaming JSONL engine `cli/src/search/engine.ts`; boolean AND/OR/NOT parser `cli/src/search/query-parser.ts`; wire types `cli/src/schemas/session-message.ts`.
25+
26+
**`codeforge doctor` (environment diagnostics)**: `cli/src/commands/doctor/index.ts` — parallel health checks with `--fix` interactive mode.
27+
28+
**Container-proxy detection**: `cli/src/utils/context.ts``isInsideContainer()` and the auto-proxy that re-runs the CLI inside the container via `docker exec` when invoked from the host.
29+
30+
**Codebase indexer**: `cli/src/indexer/` — SQLite-backed symbol index (extractor, scanner, folder rules).
31+
32+
**Plugin management commands**: `cli/src/commands/plugin/` (`list`, `show`, `enable`, `disable`, `hooks`, `agents`, `skills`).
33+
34+
**Documentation pages**: Content in `docs/src/content/docs/`, organized by Starlight topic (`start-here/`, `use/`, `customize/`, `extend/`, `reference/`). One MDX per CodeForge plugin under `extend/plugins/`. Sidebar/topic structure is defined entirely in `docs/astro.config.mjs` — content file + sidebar entry must stay in sync. Content collections registered in `docs/src/content.config.ts`. Custom slot overrides: `docs/src/components/Hero.astro`, `docs/src/components/Header.astro`.
35+
36+
**Changelog (single source of truth)**: `container/.devcontainer/CHANGELOG.md`. The docs site mirrors it via `docs/scripts/sync-changelog.mjs` (auto-runs before `dev` and `build`) — never edit `docs/src/content/docs/reference/changelog.md` directly; it's generated.
37+
38+
**AI assistant reference for the devcontainer**: `container/.devcontainer/AGENTS.md` is the authoritative reference (commands, config, plugins, auth, modification procedures). `container/.devcontainer/AI-CONTEXT.md` is the machine-readable summary with a hard ~700-token ceiling.
39+
40+
**Per-project overrides and state**: `container/.codeforge/container.json` — setup flags, identity, timezone, versionLock, plugin blacklist. Any new override file needs a manifest entry.
41+
42+
**Compose-secret generation**: `container/.devcontainer/scripts/generate-compose.mjs``initializeCommand`; discovers `container/.codeforge/secrets/` files and emits Docker Compose secret mounts.
43+
44+
## Conventions
45+
46+
- **Changelog discipline**: Every change requires an entry in `container/.devcontainer/CHANGELOG.md`, grouped under `###` domain headings (e.g. `### Security`, `### Agent System`). Cross-package changes belong in a single PR, grouped by package in the commit message.
47+
- **Branching**: feature/fix branches → `staging` (integration) → `main` (release). PRs from `staging` to `main` are used for releases. Never commit directly to `main`.
48+
- **Per-package dependencies**: Each package manages its own dependencies — no root lockfile. Run tests in the affected package(s) before committing.
49+
- **Defaults vs. overrides**: Packaged defaults live in `container/.devcontainer/defaults/codeforge/`; `container/.codeforge/` is project-override and state only.
50+
- **Disabling a devcontainer feature**: Set `"version": "none"` in its block in `devcontainer.json` — do not remove the entry (preserves install order).
51+
- **`workspace-scope-guard` is load-bearing**: Do not disable it without explicit user instruction — it enforces file-operation scoping across all agents.

cli/CLAUDE.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# cli
2+
3+
TypeScript/Bun CLI (`codeforge`) for CodeForge development workflows — session search, plugin management, devcontainer control, and environment diagnostics.
4+
5+
Entry: `src/index.ts` — commander root; registers all subcommands and the container-proxy `preAction` hook.
6+
7+
## Key Files
8+
9+
- `src/index.ts` — program root; proxy middleware (auto-forwards to container when outside one)
10+
- `src/commands/session/search.ts``codeforge session search`; boolean query, role/project/time filters
11+
- `src/search/engine.ts` — JSONL streaming search engine; `SearchOptions`, `SearchResult`, `readLines`
12+
- `src/search/query-parser.ts` — AND/OR/NOT AST query parser used by the engine
13+
- `src/search/filter.ts``createFilter(FilterOptions)` predicate factory
14+
- `src/schemas/session-message.ts` — JSONL message types (`SessionMessage`, `SearchableMessage`, extractors)
15+
- `src/loaders/` — file-system loaders: `history-loader`, `session-meta`, `plan-loader`, `task-loader`, `plugin-loader`, `hooks-loader`, `settings-writer`
16+
- `src/output/` — formatters keyed by domain: `text.ts`, `json.ts`, `stats.ts`, `session-list.ts`, `session-show.ts`, `plugin-*.ts`, etc.
17+
- `src/utils/context.ts``isInsideContainer()`, `proxyCommand()` (docker exec)
18+
- `src/utils/time.ts``parseRelativeTime()`, `parseTime()` used by all date-filtered commands
19+
- `src/commands/doctor/index.ts``codeforge doctor`; parallel health checks, `--fix` mode
20+
21+
## Subdirectories
22+
23+
- `src/commands/` — one subdirectory per command group: `session/`, `task/`, `plan/`, `plugin/`, `hooks/`, `config/`, `index/`, `container/`, `mount/`, `doctor/`
24+
- `src/search/` — query parsing, filtering, and JSONL stream engine
25+
- `src/loaders/` — data access layer (reads Claude Code files from `~/.claude/`)
26+
- `src/schemas/` — TypeScript interfaces for JSONL wire formats
27+
- `src/output/` — rendering layer; formatters per domain and format (text/json/stats)
28+
- `src/utils/` — shared utilities: context, docker, glob, time, platform, mitmproxy
29+
- `src/indexer/` — codebase symbol index: `db.ts`, `extractor.ts`, `scanner.ts`, `folders.ts`
30+
- `tests/` — bun test suites, one file per module area
31+
32+
## Dependencies
33+
34+
Imports from: `commander`, `@clack/prompts`, `chalk`, `@devcontainers/cli`
35+
Used by: container package (ships the compiled binary); `codeforge` binary on PATH inside devcontainer
36+
37+
## Conventions
38+
39+
- Every command module exports a single `registerXxxCommand(parent: Command): void` function; registered in `src/index.ts`.
40+
- Command actions wrap their body in `try/catch`; errors print `Error: <message>` to stderr and call `process.exit(1)`.
41+
- Output format controlled by `--format text|json` option; color disabled via `chalk.level = 0` when `--no-color` is passed.
42+
- Loaders live in `src/loaders/`; formatters live in `src/output/`; commands are thin orchestrators that call both.
43+
- Use `Bun.file().stream()` (not `fs.readFile`) for JSONL streaming; see `readLines` in `engine.ts`.
44+
45+
## Build & Test
46+
47+
```
48+
bun run build # bundle to dist/codeforge.js (bun target)
49+
bun run dev # run src/index.ts directly
50+
bun test # run all tests
51+
bun run build:binary # compile self-contained binary
52+
bun run build:binary:linux # cross-compile for linux-x64
53+
```

container/.devcontainer/CLAUDE.md

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,55 @@
1-
@AGENTS.md
1+
# .devcontainer
2+
3+
The CodeForge devcontainer definition — features, plugins, scripts, config defaults, and AI documentation.
4+
5+
Entry: `AGENTS.md` — authoritative reference for all AI assistants; covers config keys, commands, plugins, auth, and modification procedures.
6+
7+
## Key Files
8+
9+
- `devcontainer.json` — container definition: 34+ features, VSCode settings/extensions, port mappings, postStartCommand
10+
- `docker-compose.yml` — base Compose file: image, named volumes, resource limits
11+
- `scripts/setup.sh` — postStartCommand orchestrator; runs all setup-*.sh subscripts, reads flags from `.codeforge/container.json`
12+
- `scripts/generate-compose.mjs` — initializeCommand; discovers `.codeforge/secrets/` and generates `docker-compose.codeforge.yml`
13+
- `scripts/generate-settings-profiles.js` — generates `.generated/codeforge/claude/settings/settings*.json` from base.json + profiles
14+
- `defaults/codeforge/file-manifest.json` — controls which config files deploy to `~/.claude/` on container start; each entry has `id`, `src`, `dest`, `overwrite` (`if-changed`|`always`|`never`)
15+
- `CHANGELOG.md` — user-facing change history (required entry for every PR)
16+
- `AI-CONTEXT.md` — machine-readable environment facts for AI assistants (~700 token target)
17+
18+
## Subdirectories
19+
20+
- `features/` — 34 custom devcontainer features (see list below)
21+
- `plugins/devs-marketplace/` — single marketplace plugin bundle; contains 12 Claude Code plugins under `plugins/`
22+
- `scripts/` — setup-*.sh subscripts + generate-compose.mjs + generate-settings-profiles.js
23+
- `defaults/codeforge/` — packaged config defaults deployed on every container start
24+
- `claude/settings/``base.json` (shared settings) + `profiles/*.json` (model overlays)
25+
- `claude/system-prompts/``template.md` (Jinja2), `main.md`, `orchestrator.md`, `writing.md`, `claude-default.md`, `components/` (14 partials)
26+
- `claude/rules/` — behavioral rules deployed to `~/.claude/rules/` every start
27+
- `claude/router/` — LLM provider routing config
28+
- `claude/statusline/` — ccstatusline widget layout
29+
- `rtk/`, `codex/` — tool-specific configs
30+
31+
## Features (custom, under features/)
32+
33+
agent-browser, ast-grep, biome, ccburn, ccdiag, ccms, ccstatusline, ccusage, chromaterm, claude-code-karma, claude-code-native, claude-code-router, claude-mem, claude-monitor, claude-session-analyzer, codeforge-cli, codex-cli, dprint, hadolint, hermes-agent, kitty-terminfo, lamarck, lsp-servers, mcp-qdrant, notify-hook, oh-my-claude, rtk, ruff, sandcastle, shellcheck, shfmt, tmux, tree-sitter, zsh-completions
34+
35+
## Plugins (under plugins/devs-marketplace/plugins/)
36+
37+
Active: agent-system, auto-code-quality, dangerous-command-blocker, protected-files-guard, session-context, skill-engine, workspace-scope-guard, codeforge-lsp
38+
Archived/disabled: git-workflow, notify-hook, prompt-snippets, spec-workflow, ticket-workflow
39+
40+
## System Prompt Architecture
41+
42+
`defaults/codeforge/claude/system-prompts/` uses a Jinja2 template system:
43+
- `template.md` — master template with named blocks (`{% block identity %}`, etc.) and `{% include "components/…" %}` directives
44+
- `components/` — 14 partial files (identity, guardrails, task-approach, decision-authority, task-intake, code-quality, communication, platform, context-management, tools, subagent-routing, error-recovery, self-review, memory)
45+
- `main.md`, `orchestrator.md`, `writing.md` — rendered variants (deployed via file-manifest)
46+
- `claude-default.md` — fallback prompt for unmodified deployments
47+
48+
## Conventions
49+
50+
- Feature install order is explicit in `devcontainer.json` `overrideFeatureInstallOrder` — runtimes first, then Claude Code, then npm/uv-dependent tools
51+
- Disable a feature without removing it: set `"version": "none"` in its config block
52+
- `overwrite: "never"` entries in file-manifest are one-time seeds (user owns them after first deploy)
53+
- Plugin hook scripts are Python; tested directly via importlib in `container/tests/plugins/`
54+
- AGENTS.md is the source of truth for AI assistants; AI-CONTEXT.md is the machine-readable summary (~700 token hard ceiling)
55+
- `workspace-scope-guard` MUST NOT be disabled without explicit user instruction

container/.devcontainer/defaults/codeforge/claude/rules/auto-memory.md

Lines changed: 0 additions & 61 deletions
This file was deleted.

container/.devcontainer/defaults/codeforge/claude/rules/rtk-awareness.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)