@thatix.io/context-first-agents-cli 0.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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -0
  3. package/dist/commands/add-repo.d.ts +1 -0
  4. package/dist/commands/add-repo.js +54 -0
  5. package/dist/commands/create-orchestrator.d.ts +8 -0
  6. package/dist/commands/create-orchestrator.js +87 -0
  7. package/dist/commands/doctor.d.ts +1 -0
  8. package/dist/commands/doctor.js +66 -0
  9. package/dist/commands/init.d.ts +6 -0
  10. package/dist/commands/init.js +22 -0
  11. package/dist/commands/status.d.ts +1 -0
  12. package/dist/commands/status.js +31 -0
  13. package/dist/commands/update-commands.d.ts +5 -0
  14. package/dist/commands/update-commands.js +7 -0
  15. package/dist/core/install-commands.d.ts +9 -0
  16. package/dist/core/install-commands.js +46 -0
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.js +46 -0
  19. package/dist/templates/commands/en/agents/CONTEXT-CONTRACT.md +63 -0
  20. package/dist/templates/commands/en/agents/implementer.md +27 -0
  21. package/dist/templates/commands/en/agents/integrator.md +22 -0
  22. package/dist/templates/commands/en/agents/reviewer.md +31 -0
  23. package/dist/templates/commands/en/agents/tester.md +22 -0
  24. package/dist/templates/commands/en/orchestrate.md +126 -0
  25. package/dist/templates/commands/pt-BR/agents/CONTEXT-CONTRACT.md +63 -0
  26. package/dist/templates/commands/pt-BR/agents/implementer.md +27 -0
  27. package/dist/templates/commands/pt-BR/agents/integrator.md +23 -0
  28. package/dist/templates/commands/pt-BR/agents/reviewer.md +31 -0
  29. package/dist/templates/commands/pt-BR/agents/tester.md +22 -0
  30. package/dist/templates/commands/pt-BR/orchestrate.md +125 -0
  31. package/dist/templates/orchestrator/ai.properties.md +27 -0
  32. package/dist/templates/orchestrator/context-manifest.example.json +46 -0
  33. package/dist/templates/orchestrator/gitignore +6 -0
  34. package/dist/utils/config.d.ts +81 -0
  35. package/dist/utils/config.js +70 -0
  36. package/dist/utils/paths.d.ts +10 -0
  37. package/dist/utils/paths.js +15 -0
  38. package/package.json +53 -0
  39. package/templates/commands/en/agents/CONTEXT-CONTRACT.md +63 -0
  40. package/templates/commands/en/agents/implementer.md +27 -0
  41. package/templates/commands/en/agents/integrator.md +22 -0
  42. package/templates/commands/en/agents/reviewer.md +31 -0
  43. package/templates/commands/en/agents/tester.md +22 -0
  44. package/templates/commands/en/orchestrate.md +126 -0
  45. package/templates/commands/pt-BR/agents/CONTEXT-CONTRACT.md +63 -0
  46. package/templates/commands/pt-BR/agents/implementer.md +27 -0
  47. package/templates/commands/pt-BR/agents/integrator.md +23 -0
  48. package/templates/commands/pt-BR/agents/reviewer.md +31 -0
  49. package/templates/commands/pt-BR/agents/tester.md +22 -0
  50. package/templates/commands/pt-BR/orchestrate.md +125 -0
  51. package/templates/orchestrator/ai.properties.md +27 -0
  52. package/templates/orchestrator/context-manifest.example.json +46 -0
  53. package/templates/orchestrator/gitignore +6 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thiago Abreu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # Context-First Agents CLI
2
+
3
+ > Evolution of [context-first-cli](https://www.npmjs.com/package/context-first-cli): the
4
+ > same project-agnostic methodology management **plus** dynamic, ephemeral AI-agent
5
+ > orchestration derived from your specs.
6
+
7
+ The Node CLI only **scaffolds and manages** (orchestrator, repos, config, worktrees-ready
8
+ sessions). All agent **orchestration intelligence lives in `.md` command templates** that
9
+ your AI tool runs — never in Node. This keeps the whole flow inside your existing
10
+ command-driven workflow.
11
+
12
+ ```
13
+ spec → complexity → execution DAG → context contract per node → ephemeral agents
14
+ ```
15
+
16
+ ---
17
+
18
+ ## What's new vs. context-first-cli
19
+
20
+ | | context-first-cli | context-first-agents-cli |
21
+ |---|---|---|
22
+ | Work decomposition | you pick which command to run, in a fixed pipeline | `/orchestrate` derives the **minimum agent graph** from the spec |
23
+ | Agents | one serial agent over one big shared context | **N ephemeral agents**, one per responsibility/repo, each with an isolated context |
24
+ | Parallelism | none (sequential phases) | implementers per repo run in parallel, joined by `dependsOn` |
25
+ | Context | everything in one bucket | **context contract per agent** (`select-do-not-dump`, `mustNotAssume`) |
26
+ | Risk review | you remember to trigger it | `riskSignals` auto-trigger an adversarial reviewer |
27
+
28
+ It stays **100% project-agnostic**: the core knows nothing about your stack or domain.
29
+ Everything specific lives in `context-manifest.json`.
30
+
31
+ ---
32
+
33
+ ## Install
34
+
35
+ ```bash
36
+ npm install -g context-first-agents-cli
37
+ # binaries: context-agents (alias: cfa)
38
+ ```
39
+
40
+ ## Quick start
41
+
42
+ ```bash
43
+ # 1. Create an orchestrator
44
+ context-agents create:orchestrator my-orchestrator
45
+ cd my-orchestrator
46
+
47
+ # 2. Register your repositories (with hints so the orchestrator can route)
48
+ context-agents add:repo
49
+
50
+ # 3. Validate the setup
51
+ context-agents doctor
52
+
53
+ # 4. In your AI tool, run the orchestration command:
54
+ /orchestrate <ISSUE-ID or path/to/spec.md>
55
+ ```
56
+
57
+ ## Commands (Node — scaffold/management only)
58
+
59
+ | Command | Purpose |
60
+ |---|---|
61
+ | `create:orchestrator [name]` | New orchestrator (manifest + `.md` commands) |
62
+ | `init` | Install/refresh agent commands in an existing orchestrator |
63
+ | `add:repo` | Add a repo to the manifest (id, role, **hints**, context, testCommand) |
64
+ | `update:commands` | Overwrite the agent command templates |
65
+ | `doctor` | Validate manifest, hints, indexes, installed commands |
66
+ | `status` | Show repos, risk signals, and active sessions |
67
+
68
+ `--lang en|pt-BR` selects the language of the installed `.md` commands.
69
+
70
+ ## The `.md` orchestration layer (the engine)
71
+
72
+ Installed into `.claude/commands/`:
73
+
74
+ - **`orchestrate.md`** — classifies complexity, builds the execution DAG, compiles a
75
+ context contract per node, and spawns ephemeral subagents (Task tool) wave by wave.
76
+ - **`agents/CONTEXT-CONTRACT.md`** — the exact contract shape and the required return format.
77
+ - **`agents/{implementer,reviewer,integrator,tester}.md`** — behavioral archetypes
78
+ (not domain agents). A concrete worker is compiled as
79
+ `archetype + objective + repository + context contract + tools`.
80
+
81
+ ## `context-manifest.json`
82
+
83
+ The single source of project truth (backwards-compatible with context-first-cli, with
84
+ additive fields). See `templates/orchestrator/context-manifest.example.json`.
85
+
86
+ ```jsonc
87
+ {
88
+ "repositories": [
89
+ {
90
+ "id": "service-a",
91
+ "role": "service",
92
+ "hints": ["api", "backend"], // ← how the orchestrator knows a task hits this repo
93
+ "context": ["../metaspecs/specs/api.md"], // ← what an agent here may read
94
+ "testCommand": "npm test"
95
+ }
96
+ ],
97
+ "orchestration": {
98
+ "riskSignals": ["migration", "payment", "security"], // ← trigger adversarial review
99
+ "indexes": ["../metaspecs/specs/index.md"],
100
+ "contextPolicy": "select-do-not-dump",
101
+ "parallelism": { "maxWorkers": 8, "maxPerRepository": 2 }
102
+ }
103
+ }
104
+ ```
105
+
106
+ ## How complexity routing works
107
+
108
+ `/orchestrate` counts, against the spec text:
109
+ - **repoHits** — repos whose `id`/`hints` appear
110
+ - **risks** — `riskSignals` that appear
111
+
112
+ → `simple` (1 repo: implementer + reviewer) · `medium` (impl per repo → integrator →
113
+ tester) · `complex` (medium + adversarial reviewer). A spec may force it via
114
+ `complexity:` frontmatter. Small tasks stay small by design.
115
+
116
+ ## Design rules
117
+
118
+ - **No catalog of domain agents.** Expertise comes from selected context, not personas.
119
+ - **Select, don't dump.** Each agent's context is bounded and auditable.
120
+ - **Specs are normative.** Agents may read them; they must never modify them.
121
+
122
+ ## License
123
+
124
+ MIT
@@ -0,0 +1 @@
1
+ export declare function addRepoCommand(): Promise<void>;
@@ -0,0 +1,54 @@
1
+ import chalk from 'chalk';
2
+ import inquirer from 'inquirer';
3
+ import { loadManifest, saveManifest, exitWithError, } from '../utils/config.js';
4
+ export async function addRepoCommand() {
5
+ console.log(chalk.bold('\nContext-First Agents — add:repo\n'));
6
+ const cwd = process.cwd();
7
+ const manifest = await loadManifest(cwd);
8
+ if (!manifest)
9
+ exitWithError('No context-manifest.json here. Run inside an orchestrator.');
10
+ const a = await inquirer.prompt([
11
+ { type: 'input', name: 'id', message: 'Repository id (folder name):', validate: (v) => !!v || 'required' },
12
+ {
13
+ type: 'list',
14
+ name: 'role',
15
+ message: 'Role:',
16
+ choices: ['application', 'service', 'library', 'metaspecs', 'specs-provider'],
17
+ default: 'application',
18
+ },
19
+ { type: 'input', name: 'url', message: 'Git URL (optional):', default: '' },
20
+ { type: 'input', name: 'mainBranch', message: 'Main branch:', default: 'main' },
21
+ {
22
+ type: 'input',
23
+ name: 'hints',
24
+ message: 'Hints (comma-separated keywords that mean this repo is impacted):',
25
+ default: '',
26
+ },
27
+ {
28
+ type: 'input',
29
+ name: 'context',
30
+ message: 'Context files an agent here may read (comma-separated, optional):',
31
+ default: '',
32
+ },
33
+ { type: 'input', name: 'testCommand', message: 'Test command (optional):', default: '' },
34
+ ]);
35
+ const split = (s) => s.split(',').map((x) => x.trim()).filter(Boolean);
36
+ const repo = {
37
+ id: a.id,
38
+ role: a.role,
39
+ mainBranch: a.mainBranch,
40
+ ...(a.url ? { url: a.url } : {}),
41
+ ...(a.hints ? { hints: split(a.hints) } : {}),
42
+ ...(a.context ? { context: split(a.context) } : {}),
43
+ ...(a.testCommand ? { testCommand: a.testCommand } : {}),
44
+ };
45
+ if (manifest.repositories.some((r) => r.id === repo.id)) {
46
+ exitWithError(`Repository '${repo.id}' already exists in the manifest.`);
47
+ }
48
+ manifest.repositories.push(repo);
49
+ await saveManifest(cwd, manifest);
50
+ console.log(chalk.green(`\n✓ Added '${repo.id}'. Manifest now has ${manifest.repositories.length} repos.\n`));
51
+ if (!repo.hints) {
52
+ console.log(chalk.yellow('Tip: repos without `hints` are harder for the orchestrator to route. Add keywords later.\n'));
53
+ }
54
+ }
@@ -0,0 +1,8 @@
1
+ interface CreateOpts {
2
+ lang?: string;
3
+ project?: string;
4
+ description?: string;
5
+ yes?: boolean;
6
+ }
7
+ export declare function createOrchestratorCommand(name: string | undefined, opts: CreateOpts): Promise<void>;
8
+ export {};
@@ -0,0 +1,87 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import chalk from 'chalk';
4
+ import inquirer from 'inquirer';
5
+ import { templatesDir } from '../utils/paths.js';
6
+ import { installCommands } from '../core/install-commands.js';
7
+ import { ensureDir, pathExists, exitWithError, DEFAULT_ARCHETYPES, DEFAULT_RISK_SIGNALS, } from '../utils/config.js';
8
+ export async function createOrchestratorCommand(name, opts) {
9
+ console.log(chalk.bold('\nContext-First Agents — create:orchestrator\n'));
10
+ // Non-interactive when there is no TTY (CI/pipes) or --yes is passed.
11
+ const interactive = process.stdin.isTTY && !opts.yes;
12
+ let answers;
13
+ if (interactive) {
14
+ answers = await inquirer.prompt([
15
+ {
16
+ type: 'input',
17
+ name: 'name',
18
+ message: 'Orchestrator directory name:',
19
+ default: name ?? 'my-orchestrator',
20
+ when: !name,
21
+ },
22
+ { type: 'input', name: 'project', message: 'Project name:', default: name ?? 'my-project' },
23
+ { type: 'input', name: 'description', message: 'Description:', default: opts.description ?? '' },
24
+ ]);
25
+ }
26
+ else {
27
+ if (!name)
28
+ exitWithError('Non-interactive mode requires a name argument (context-agents create:orchestrator <name>).');
29
+ answers = {
30
+ name,
31
+ project: opts.project ?? name,
32
+ description: opts.description ?? '',
33
+ };
34
+ }
35
+ const dirName = name ?? answers.name;
36
+ const target = path.resolve(process.cwd(), dirName);
37
+ if (await pathExists(target))
38
+ exitWithError(`Directory already exists: ${target}`);
39
+ await ensureDir(target);
40
+ await ensureDir(path.join(target, '.sessions'));
41
+ // Seed a manifest with the orchestration block wired for agent routing.
42
+ const manifest = {
43
+ version: '1.0',
44
+ project: answers.project ?? dirName,
45
+ description: answers.description ?? '',
46
+ repositories: [
47
+ {
48
+ id: 'metaspecs',
49
+ role: 'metaspecs',
50
+ description: 'Normative specifications (source of truth)',
51
+ mainBranch: 'main',
52
+ hints: ['spec', 'adr', 'contract', 'documentation'],
53
+ },
54
+ ],
55
+ orchestration: {
56
+ archetypes: DEFAULT_ARCHETYPES,
57
+ riskSignals: DEFAULT_RISK_SIGNALS,
58
+ parallelism: { maxWorkers: 8, maxPerRepository: 2 },
59
+ contextPolicy: 'select-do-not-dump',
60
+ maxFilesPerWorker: 20,
61
+ indexes: ['../metaspecs/specs/index.md'],
62
+ },
63
+ };
64
+ await fs.writeFile(path.join(target, 'context-manifest.json'), JSON.stringify(manifest, null, 2), 'utf-8');
65
+ // Copy the ai.properties template if present.
66
+ const aiPropSrc = path.join(templatesDir(), 'orchestrator', 'ai.properties.md');
67
+ if (await pathExists(aiPropSrc)) {
68
+ await fs.copyFile(aiPropSrc, path.join(target, 'ai.properties.md'));
69
+ }
70
+ // .contextrc.json (local config, gitignored) — compatible with context-first-cli.
71
+ await fs.writeFile(path.join(target, '.contextrc.json'), JSON.stringify({
72
+ orchestratorRepo: `file://${target}`,
73
+ aiProvider: 'claude',
74
+ commandsDir: '.claude/commands',
75
+ }, null, 2), 'utf-8');
76
+ const gitignoreSrc = path.join(templatesDir(), 'orchestrator', 'gitignore');
77
+ if (await pathExists(gitignoreSrc)) {
78
+ await fs.copyFile(gitignoreSrc, path.join(target, '.gitignore'));
79
+ }
80
+ console.log(chalk.bold('\nInstalling agent command templates:'));
81
+ await installCommands(target, { lang: opts.lang, force: true });
82
+ console.log(chalk.green(`\n✓ Orchestrator created at ${target}`));
83
+ console.log(chalk.gray('\nNext steps:'));
84
+ console.log(chalk.gray(` cd ${dirName}`));
85
+ console.log(chalk.gray(' context-agents add:repo # register your repositories'));
86
+ console.log(chalk.gray(' # then in your AI tool: /orchestrate <ISSUE-ID>\n'));
87
+ }
@@ -0,0 +1 @@
1
+ export declare function doctorCommand(): Promise<void>;
@@ -0,0 +1,66 @@
1
+ import path from 'node:path';
2
+ import chalk from 'chalk';
3
+ import { loadManifest, pathExists } from '../utils/config.js';
4
+ import { repoLocalPath } from '../utils/paths.js';
5
+ export async function doctorCommand() {
6
+ console.log(chalk.bold('\nContext-First Agents — doctor\n'));
7
+ const cwd = process.cwd();
8
+ let problems = 0;
9
+ let warnings = 0;
10
+ const manifest = await loadManifest(cwd);
11
+ if (!manifest) {
12
+ console.log(chalk.red('✗ context-manifest.json not found or invalid.'));
13
+ console.log(chalk.gray(' Run inside an orchestrator, or `create:orchestrator`.\n'));
14
+ process.exitCode = 1;
15
+ return;
16
+ }
17
+ console.log(chalk.green(`✓ Manifest OK — ${manifest.project} (${manifest.repositories.length} repos)`));
18
+ // Commands installed?
19
+ const commandsDir = path.join(cwd, '.claude', 'commands');
20
+ if (await pathExists(path.join(commandsDir, 'orchestrate.md'))) {
21
+ console.log(chalk.green('✓ /orchestrate command installed'));
22
+ }
23
+ else {
24
+ console.log(chalk.red('✗ orchestrate.md missing — run `context-agents init`'));
25
+ problems++;
26
+ }
27
+ // Orchestration block
28
+ const orch = manifest.orchestration;
29
+ if (!orch?.riskSignals?.length) {
30
+ console.log(chalk.yellow('! No orchestration.riskSignals — risky tasks won\'t trigger adversarial review'));
31
+ warnings++;
32
+ }
33
+ else {
34
+ console.log(chalk.green(`✓ ${orch.riskSignals.length} risk signals configured`));
35
+ }
36
+ if (!orch?.indexes?.length) {
37
+ console.log(chalk.yellow('! No orchestration.indexes — agents have no project-wide context router'));
38
+ warnings++;
39
+ }
40
+ // Per-repo checks
41
+ console.log(chalk.bold('\nRepositories:'));
42
+ for (const repo of manifest.repositories) {
43
+ const local = repoLocalPath(cwd, repo);
44
+ const exists = await pathExists(local);
45
+ const status = exists ? chalk.green('found') : chalk.yellow('missing locally');
46
+ const hints = repo.hints?.length ? chalk.gray(`hints: ${repo.hints.join(', ')}`) : chalk.yellow('no hints');
47
+ console.log(` ${exists ? '✓' : '!'} ${repo.id} [${repo.role}] — ${status}; ${hints}`);
48
+ if (!exists)
49
+ warnings++;
50
+ if (!repo.hints?.length && repo.role !== 'metaspecs')
51
+ warnings++;
52
+ if (repo.role === 'application' && !repo.testCommand) {
53
+ console.log(chalk.gray(` (no testCommand — tester agent will fall back to project defaults)`));
54
+ }
55
+ }
56
+ console.log('');
57
+ if (problems)
58
+ console.log(chalk.red(`${problems} problem(s)`));
59
+ if (warnings)
60
+ console.log(chalk.yellow(`${warnings} warning(s)`));
61
+ if (!problems && !warnings)
62
+ console.log(chalk.green('All good. Ready to /orchestrate.'));
63
+ console.log('');
64
+ if (problems)
65
+ process.exitCode = 1;
66
+ }
@@ -0,0 +1,6 @@
1
+ interface InitOpts {
2
+ lang?: string;
3
+ force?: boolean;
4
+ }
5
+ export declare function initCommand(opts: InitOpts): Promise<void>;
6
+ export {};
@@ -0,0 +1,22 @@
1
+ import path from 'node:path';
2
+ import chalk from 'chalk';
3
+ import { installCommands } from '../core/install-commands.js';
4
+ import { loadManifest, pathExists, exitWithError } from '../utils/config.js';
5
+ export async function initCommand(opts) {
6
+ const cwd = process.cwd();
7
+ console.log(chalk.bold('\nContext-First Agents — init\n'));
8
+ const hasManifest = await pathExists(path.join(cwd, 'context-manifest.json'));
9
+ if (!hasManifest) {
10
+ console.log(chalk.yellow('No context-manifest.json here. Run this inside an orchestrator, or use `create:orchestrator` first.'));
11
+ }
12
+ else {
13
+ const manifest = await loadManifest(cwd);
14
+ if (!manifest)
15
+ exitWithError('context-manifest.json is present but could not be parsed.');
16
+ console.log(chalk.gray(`Project: ${manifest.project} (${manifest.repositories.length} repos)`));
17
+ }
18
+ console.log(chalk.bold('\nInstalling agent command templates:'));
19
+ const written = await installCommands(cwd, { lang: opts.lang, force: opts.force });
20
+ console.log(chalk.green(`\n✓ Installed ${written.length} command file(s).`));
21
+ console.log(chalk.gray('\nNext: open your AI tool and run /orchestrate <ISSUE-ID>\n'));
22
+ }
@@ -0,0 +1 @@
1
+ export declare function statusCommand(): Promise<void>;
@@ -0,0 +1,31 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import chalk from 'chalk';
4
+ import { loadManifest, pathExists } from '../utils/config.js';
5
+ export async function statusCommand() {
6
+ console.log(chalk.bold('\nContext-First Agents — status\n'));
7
+ const cwd = process.cwd();
8
+ const manifest = await loadManifest(cwd);
9
+ if (!manifest) {
10
+ console.log(chalk.yellow('No context-manifest.json here.\n'));
11
+ return;
12
+ }
13
+ console.log(chalk.bold(`${manifest.project}`) + chalk.gray(` — ${manifest.description ?? ''}`));
14
+ console.log(chalk.gray(`Repositories (${manifest.repositories.length}):`));
15
+ for (const r of manifest.repositories) {
16
+ console.log(` • ${r.id} [${r.role}]${r.hints?.length ? chalk.gray(` — ${r.hints.join(', ')}`) : ''}`);
17
+ }
18
+ const risk = manifest.orchestration?.riskSignals ?? [];
19
+ if (risk.length)
20
+ console.log(chalk.gray(`\nRisk signals: ${risk.join(', ')}`));
21
+ const sessionsDir = path.join(cwd, '.sessions');
22
+ if (await pathExists(sessionsDir)) {
23
+ const entries = (await fs.readdir(sessionsDir, { withFileTypes: true }))
24
+ .filter((e) => e.isDirectory() && !e.name.startsWith('_') && !e.name.startsWith('.'))
25
+ .map((e) => e.name);
26
+ console.log(chalk.bold(`\nActive sessions (${entries.length}):`));
27
+ for (const s of entries.sort())
28
+ console.log(` • ${s}`);
29
+ }
30
+ console.log('');
31
+ }
@@ -0,0 +1,5 @@
1
+ interface UpdateOpts {
2
+ lang?: string;
3
+ }
4
+ export declare function updateCommandsCommand(opts: UpdateOpts): Promise<void>;
5
+ export {};
@@ -0,0 +1,7 @@
1
+ import chalk from 'chalk';
2
+ import { installCommands } from '../core/install-commands.js';
3
+ export async function updateCommandsCommand(opts) {
4
+ console.log(chalk.bold('\nContext-First Agents — update:commands\n'));
5
+ const written = await installCommands(process.cwd(), { lang: opts.lang, force: true });
6
+ console.log(chalk.green(`\n✓ Updated ${written.length} command file(s).\n`));
7
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copy the agent command templates (.md) into an orchestrator's commands dir.
3
+ * These .md files ARE the orchestration engine — Node only places them.
4
+ */
5
+ export declare function installCommands(orchestratorDir: string, opts?: {
6
+ lang?: string;
7
+ force?: boolean;
8
+ commandsDir?: string;
9
+ }): Promise<string[]>;
@@ -0,0 +1,46 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import chalk from 'chalk';
4
+ import { templatesDir } from '../utils/paths.js';
5
+ import { ensureDir, pathExists } from '../utils/config.js';
6
+ const SUPPORTED_LANGS = ['en', 'pt-BR'];
7
+ /**
8
+ * Copy the agent command templates (.md) into an orchestrator's commands dir.
9
+ * These .md files ARE the orchestration engine — Node only places them.
10
+ */
11
+ export async function installCommands(orchestratorDir, opts = {}) {
12
+ const lang = SUPPORTED_LANGS.includes(opts.lang ?? '') ? opts.lang : 'en';
13
+ const commandsDir = opts.commandsDir ?? '.claude/commands';
14
+ const srcRoot = path.join(templatesDir(), 'commands', lang);
15
+ const destRoot = path.join(orchestratorDir, commandsDir);
16
+ if (!(await pathExists(srcRoot))) {
17
+ // Fall back to en if a lang folder is missing.
18
+ return installCommands(orchestratorDir, { ...opts, lang: 'en' });
19
+ }
20
+ await ensureDir(destRoot);
21
+ const written = [];
22
+ await copyTree(srcRoot, destRoot, Boolean(opts.force), written);
23
+ written.sort();
24
+ for (const f of written)
25
+ console.log(chalk.green(` ✓ ${path.relative(orchestratorDir, f)}`));
26
+ return written;
27
+ }
28
+ async function copyTree(src, dest, force, written) {
29
+ const entries = await fs.readdir(src, { withFileTypes: true });
30
+ for (const e of entries) {
31
+ const s = path.join(src, e.name);
32
+ const d = path.join(dest, e.name);
33
+ if (e.isDirectory()) {
34
+ await ensureDir(d);
35
+ await copyTree(s, d, force, written);
36
+ }
37
+ else {
38
+ if (!force && (await pathExists(d))) {
39
+ console.log(chalk.gray(` · skip (exists) ${e.name}`));
40
+ continue;
41
+ }
42
+ await fs.copyFile(s, d);
43
+ written.push(d);
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { initCommand } from './commands/init.js';
4
+ import { createOrchestratorCommand } from './commands/create-orchestrator.js';
5
+ import { addRepoCommand } from './commands/add-repo.js';
6
+ import { updateCommandsCommand } from './commands/update-commands.js';
7
+ import { doctorCommand } from './commands/doctor.js';
8
+ import { statusCommand } from './commands/status.js';
9
+ const program = new Command();
10
+ program
11
+ .name('context-agents')
12
+ .description('Context-First Agents CLI — scaffold orchestrators and run dynamic, ephemeral AI agents from specs.\n' +
13
+ 'All agent orchestration lives in .md command templates; this Node CLI only scaffolds and manages.')
14
+ .version('0.1.0');
15
+ program
16
+ .command('init')
17
+ .description('Add Context-First Agents command templates to an existing orchestrator')
18
+ .option('-l, --lang <lang>', 'Command language (en, pt-BR)', 'en')
19
+ .option('-f, --force', 'Overwrite existing command files')
20
+ .action(initCommand);
21
+ program
22
+ .command('create:orchestrator [name]')
23
+ .description('Create a new orchestrator directory (context-manifest.json + .md commands)')
24
+ .option('-l, --lang <lang>', 'Command language (en, pt-BR)', 'en')
25
+ .option('-p, --project <name>', 'Project name (non-interactive)')
26
+ .option('-d, --description <text>', 'Project description (non-interactive)')
27
+ .option('-y, --yes', 'Skip prompts and use defaults/flags')
28
+ .action(createOrchestratorCommand);
29
+ program
30
+ .command('add:repo')
31
+ .description('Add a repository to context-manifest.json (with hints/context/testCommand)')
32
+ .action(addRepoCommand);
33
+ program
34
+ .command('update:commands')
35
+ .description('Update the agent command templates in an existing orchestrator')
36
+ .option('-l, --lang <lang>', 'Command language (en, pt-BR)', 'en')
37
+ .action(updateCommandsCommand);
38
+ program
39
+ .command('doctor')
40
+ .description('Validate orchestrator config for agent orchestration (manifest, hints, indexes)')
41
+ .action(doctorCommand);
42
+ program
43
+ .command('status')
44
+ .description('Show orchestrator repos, risk signals, and active sessions')
45
+ .action(statusCommand);
46
+ program.parseAsync(process.argv);
@@ -0,0 +1,63 @@
1
+ # Context Contract (shape)
2
+
3
+ Every ephemeral agent is spawned with a contract. This is the exact object the
4
+ Orchestrator compiles per node and pastes into the subagent's prompt. It is what makes
5
+ each agent's context **small, bounded, and auditable** — the core of the architecture.
6
+
7
+ ```json
8
+ {
9
+ "agentId": "agent-w001",
10
+ "archetype": "implementer",
11
+ "objective": "<the specific, bounded goal for this worker>",
12
+ "repository": "<repo-id or null for session-level workers>",
13
+ "read": [
14
+ { "type": "index", "path": "../metaspecs/specs/index.md", "reason": "project context router" },
15
+ { "type": "hint", "path": "../metaspecs/specs/technical/API_SPECIFICATION.md", "reason": "repo context hint" }
16
+ ],
17
+ "mayDiscover": [
18
+ "references reachable from the indexes above",
19
+ "files in this repository required to complete the objective"
20
+ ],
21
+ "mustNotAssume": [
22
+ "unstated business rules",
23
+ "unindexed external contracts",
24
+ "requirements not present in the approved spec"
25
+ ],
26
+ "writeBoundary": ["assigned worktree for <repo-id>"],
27
+ "limits": { "policy": "select-do-not-dump", "maxFiles": 20 },
28
+ "return": ["summary", "changes", "evidence", "tests", "unresolved", "confidence"]
29
+ }
30
+ ```
31
+
32
+ ## Rules the Orchestrator must enforce when compiling a contract
33
+
34
+ - `read` includes ALL `orchestration.indexes` plus the repo's `context[]` — but only
35
+ paths that actually exist on disk. Drop the rest silently.
36
+ - Session-level workers (integrator, tester, reviewer) have `repository: null` and
37
+ `writeBoundary: ["session artifacts only"]`.
38
+ - Never expand `read` to "the whole repo". Discovery is allowed (`mayDiscover`) but
39
+ starts from the indexes, not from a blind directory dump.
40
+ - The contract is the ONLY project context a subagent receives beyond its objective.
41
+ Do not paste the full conversation into subagents.
42
+
43
+ ## The return shape every agent must produce
44
+
45
+ ```markdown
46
+ ### summary
47
+ <one paragraph: what was done>
48
+
49
+ ### changes
50
+ <files created/modified, per repo>
51
+
52
+ ### evidence
53
+ <commands run, outputs, links>
54
+
55
+ ### tests
56
+ <tests added/run and their result>
57
+
58
+ ### unresolved
59
+ <questions, spec conflicts, Jidoka stops — or "none">
60
+
61
+ ### confidence
62
+ <low | medium | high> + one line why
63
+ ```
@@ -0,0 +1,27 @@
1
+ # Archetype: implementer
2
+
3
+ You are an **ephemeral implementer** for exactly one repository. You will be discarded
4
+ when you return. Domain expertise comes from your context contract, not from a persona.
5
+
6
+ ## You receive
7
+ - `objective`: the bounded goal.
8
+ - `repository`: the repo id and its worktree path.
9
+ - A **context contract** (read scope, writeBoundary, mustNotAssume, limits, return).
10
+
11
+ ## Do
12
+ 1. Read ONLY what your contract's `read` list allows; discover further ONLY from those
13
+ indexes/repo files (`mayDiscover`). Honor `limits.maxFiles`.
14
+ 2. Implement the objective inside your `writeBoundary` (your repo's worktree). Follow the
15
+ patterns you find in the repo and the normative specs. Do not introduce stack not
16
+ documented in the specs without flagging it in `unresolved`.
17
+ 3. Add/adjust tests per the repo's conventions.
18
+ 4. Commit atomically inside the worktree (`feat|fix|refactor|test|docs|chore: … Refs: <ISSUE-ID>`).
19
+
20
+ ## Never
21
+ - Read or modify other repositories.
22
+ - Modify normative specs.
23
+ - Assume anything in `mustNotAssume` — if you need it, stop and put it in `unresolved`.
24
+
25
+ ## Return (exactly this shape)
26
+ summary / changes / evidence / tests / unresolved / confidence
27
+ (see CONTEXT-CONTRACT.md)