@esotech/contextuate 2.0.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 (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +287 -0
  3. package/dist/commands/context.js +80 -0
  4. package/dist/commands/create.js +93 -0
  5. package/dist/commands/index.js +46 -0
  6. package/dist/commands/init.js +452 -0
  7. package/dist/commands/install.js +359 -0
  8. package/dist/commands/remove.js +77 -0
  9. package/dist/commands/run.js +205 -0
  10. package/dist/index.js +96 -0
  11. package/dist/runtime/driver.js +64 -0
  12. package/dist/runtime/tools.js +48 -0
  13. package/dist/templates/README.md +152 -0
  14. package/dist/templates/agents/aegis.md +366 -0
  15. package/dist/templates/agents/archon.md +247 -0
  16. package/dist/templates/agents/atlas.md +326 -0
  17. package/dist/templates/agents/canvas.md +19 -0
  18. package/dist/templates/agents/chronicle.md +424 -0
  19. package/dist/templates/agents/chronos.md +20 -0
  20. package/dist/templates/agents/cipher.md +360 -0
  21. package/dist/templates/agents/crucible.md +375 -0
  22. package/dist/templates/agents/echo.md +297 -0
  23. package/dist/templates/agents/forge.md +613 -0
  24. package/dist/templates/agents/ledger.md +317 -0
  25. package/dist/templates/agents/meridian.md +281 -0
  26. package/dist/templates/agents/nexus.md +600 -0
  27. package/dist/templates/agents/oracle.md +281 -0
  28. package/dist/templates/agents/scribe.md +612 -0
  29. package/dist/templates/agents/sentinel.md +312 -0
  30. package/dist/templates/agents/unity.md +17 -0
  31. package/dist/templates/agents/vox.md +19 -0
  32. package/dist/templates/agents/weaver.md +334 -0
  33. package/dist/templates/framework-agents/base.md +166 -0
  34. package/dist/templates/framework-agents/documentation-expert.md +292 -0
  35. package/dist/templates/framework-agents/tools-expert.md +245 -0
  36. package/dist/templates/standards/agent-roles.md +34 -0
  37. package/dist/templates/standards/agent-workflow.md +170 -0
  38. package/dist/templates/standards/behavioral-guidelines.md +145 -0
  39. package/dist/templates/standards/coding-standards.md +171 -0
  40. package/dist/templates/standards/task-workflow.md +246 -0
  41. package/dist/templates/templates/context.md +33 -0
  42. package/dist/templates/templates/contextuate.md +109 -0
  43. package/dist/templates/templates/platforms/AGENTS.md +5 -0
  44. package/dist/templates/templates/platforms/CLAUDE.md +5 -0
  45. package/dist/templates/templates/platforms/GEMINI.md +5 -0
  46. package/dist/templates/templates/platforms/clinerules.md +5 -0
  47. package/dist/templates/templates/platforms/copilot.md +5 -0
  48. package/dist/templates/templates/platforms/cursor.mdc +9 -0
  49. package/dist/templates/templates/platforms/windsurf.md +5 -0
  50. package/dist/templates/templates/standards/go.standards.md +167 -0
  51. package/dist/templates/templates/standards/java.standards.md +167 -0
  52. package/dist/templates/templates/standards/javascript.standards.md +292 -0
  53. package/dist/templates/templates/standards/php.standards.md +181 -0
  54. package/dist/templates/templates/standards/python.standards.md +175 -0
  55. package/dist/templates/tools/agent-creator.tool.md +252 -0
  56. package/dist/templates/tools/quickref.tool.md +216 -0
  57. package/dist/templates/tools/spawn.tool.md +31 -0
  58. package/dist/templates/tools/standards-detector.tool.md +301 -0
  59. package/dist/templates/version.json +8 -0
  60. package/dist/utils/git.js +62 -0
  61. package/dist/utils/tokens.js +74 -0
  62. package/package.json +59 -0
package/dist/index.js ADDED
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const init_1 = require("./commands/init");
6
+ const remove_1 = require("./commands/remove");
7
+ const run_1 = require("./commands/run");
8
+ const create_1 = require("./commands/create");
9
+ const index_1 = require("./commands/index");
10
+ const context_1 = require("./commands/context");
11
+ const install_1 = require("./commands/install");
12
+ const fs_1 = require("fs");
13
+ const path_1 = require("path");
14
+ const program = new commander_1.Command();
15
+ // Try to read version from package.json
16
+ let version = '0.0.0';
17
+ try {
18
+ const packageJson = JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../package.json'), 'utf-8'));
19
+ version = packageJson.version;
20
+ }
21
+ catch (error) {
22
+ // Ignore error if package.json is not found (e.g. during development)
23
+ }
24
+ program
25
+ .name('contextuate')
26
+ .description('Standardized AI context framework for any project. Powered by Esotech.')
27
+ .version(version);
28
+ program
29
+ .command('init [platforms...]')
30
+ .description('Initialize Contextuate in the current project')
31
+ .option('-f, --force', 'Overwrite existing files')
32
+ .option('-a, --agents <agents...>', 'Install specific agents (e.g., "base archon" or "all")')
33
+ .action(init_1.initCommand);
34
+ program
35
+ .command('remove')
36
+ .description('Remove unmodified platform jump files')
37
+ .action(remove_1.removeCommand);
38
+ program
39
+ .command('create-agent')
40
+ .alias('new-agent')
41
+ .description('Create a new agent definition')
42
+ .argument('[name]', 'Name of the agent (kebab-case)')
43
+ .option('-d, --description <text>', 'Description of the agent')
44
+ .action(create_1.createAgentCommand);
45
+ program
46
+ .command('index')
47
+ .description('Generate a project structure index for AI context')
48
+ .option('-d, --depth <number>', 'Maximum depth of the file tree', '5')
49
+ .option('-f, --force', 'Overwrite existing index')
50
+ .action(index_1.indexCommand);
51
+ program
52
+ .command('add-context')
53
+ .description('Interactively add files to docs/ai/context.md')
54
+ .action(context_1.addContextCommand);
55
+ program
56
+ .command('run')
57
+ .description('Run an agent definition')
58
+ .argument('<agent>', 'Name of the agent to run (e.g. "documentation-expert")')
59
+ .option('--dry-run', 'Simulate execution without running logic')
60
+ .option('--isolation <mode>', 'Isolation mode (worktree, none)', 'none')
61
+ .option('--goal <text>', 'Goal or instructions for the agent')
62
+ .option('--task <name>', 'Load a task context (scope and latest log)')
63
+ .action(run_1.runCommand);
64
+ // Install command with subcommands and flag-based usage
65
+ const install = program
66
+ .command('install')
67
+ .description('Install templates from the Contextuate repository')
68
+ .option('-a, --agents <names...>', 'Install specific agents (use "all" for all)')
69
+ .option('-s, --standards <names...>', 'Install language standards (use "all" for all)')
70
+ .option('-t, --tools <names...>', 'Install tools (use "all" for all)')
71
+ .option('--all', 'Install all available templates')
72
+ .option('-l, --list', 'List available templates')
73
+ .option('-f, --force', 'Overwrite existing files')
74
+ .action(install_1.installCommand);
75
+ // Subcommand: install agents
76
+ install
77
+ .command('agents [names...]')
78
+ .description('Install agent templates')
79
+ .option('--all', 'Install all agents')
80
+ .option('-f, --force', 'Overwrite existing files')
81
+ .action(install_1.installAgentsCommand);
82
+ // Subcommand: install standards
83
+ install
84
+ .command('standards [names...]')
85
+ .description('Install language standard templates')
86
+ .option('--all', 'Install all standards')
87
+ .option('-f, --force', 'Overwrite existing files')
88
+ .action(install_1.installStandardsCommand);
89
+ // Subcommand: install tools
90
+ install
91
+ .command('tools [names...]')
92
+ .description('Install tool templates')
93
+ .option('--all', 'Install all tools')
94
+ .option('-f, --force', 'Overwrite existing files')
95
+ .action(install_1.installToolsCommand);
96
+ program.parse();
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LLMDriver = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const tools_1 = require("./tools");
9
+ class LLMDriver {
10
+ constructor(config, goal, cwd, contextFiles = []) {
11
+ this.activeTools = [];
12
+ this.config = config;
13
+ this.goal = goal;
14
+ this.cwd = cwd;
15
+ this.toolLoader = new tools_1.ToolLoader(cwd);
16
+ this.contextFiles = contextFiles;
17
+ }
18
+ async run() {
19
+ // Load Tools
20
+ if (this.config.capabilities) {
21
+ this.activeTools = await this.toolLoader.loadTools(this.config.capabilities);
22
+ }
23
+ console.log(chalk_1.default.bold('\n[DRIVER] Starting Execution Loop'));
24
+ console.log(`Provider: ${this.config.provider}`);
25
+ console.log(`Model: ${this.config.model}`);
26
+ console.log(`Goal: ${this.goal}`);
27
+ if (this.activeTools.length > 0) {
28
+ console.log(chalk_1.default.bold('\nLoaded Tools:'));
29
+ this.activeTools.forEach(t => console.log(`- ${t.name} (${t.path})`));
30
+ }
31
+ else {
32
+ console.log(chalk_1.default.yellow('\n[INFO] No tools loaded (check agent capabilities)'));
33
+ }
34
+ if (this.contextFiles.length > 0) {
35
+ console.log(chalk_1.default.bold('\nContext Files:'));
36
+ this.contextFiles.forEach(f => console.log(`- ${f}`));
37
+ }
38
+ console.log('------------------------------------------------');
39
+ if (this.config.provider === 'mock') {
40
+ await this.runMockLoop();
41
+ }
42
+ else {
43
+ // Placeholder for real API implementation
44
+ throw new Error(`Provider '${this.config.provider}' not yet implemented.`);
45
+ }
46
+ }
47
+ async runMockLoop() {
48
+ console.log(chalk_1.default.gray('(Mock Mode: Simulating reasoning...)'));
49
+ await new Promise(r => setTimeout(r, 1000));
50
+ console.log(chalk_1.default.yellow('\n🤖 Agent Thought:'));
51
+ console.log('I need to check the files to understand the context.');
52
+ await new Promise(r => setTimeout(r, 500));
53
+ console.log(chalk_1.default.cyan('\n🛠️ Tool Call: list_files'));
54
+ console.log(' path: "."');
55
+ await new Promise(r => setTimeout(r, 500));
56
+ console.log(chalk_1.default.green('\n✅ Tool Result:'));
57
+ console.log(' ["src", "package.json", "README.md"]');
58
+ await new Promise(r => setTimeout(r, 1000));
59
+ console.log(chalk_1.default.yellow('\n🤖 Agent Thought:'));
60
+ console.log('Okay, I see the structure. I have completed the basic check.');
61
+ console.log(chalk_1.default.bold('\n[DRIVER] Execution Complete.'));
62
+ }
63
+ }
64
+ exports.LLMDriver = LLMDriver;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ToolLoader = void 0;
7
+ const fs_extra_1 = __importDefault(require("fs-extra"));
8
+ const path_1 = __importDefault(require("path"));
9
+ class ToolLoader {
10
+ constructor(projectRoot) {
11
+ this.toolsDir = path_1.default.join(projectRoot, 'docs/ai/.contextuate/tools');
12
+ }
13
+ async loadTools(capabilities) {
14
+ const loadedTools = [];
15
+ // 1. Check if tools dir exists
16
+ if (!await fs_extra_1.default.pathExists(this.toolsDir)) {
17
+ console.warn(`[WARN] Tools directory not found at: ${this.toolsDir}`);
18
+ return [];
19
+ }
20
+ // 2. Map capabilities to files
21
+ // Convention: capability "spawn_agent" -> "spawn.tool.md" or "spawn_agent.tool.md"
22
+ // We'll search for matches.
23
+ const files = await fs_extra_1.default.readdir(this.toolsDir);
24
+ for (const cap of capabilities) {
25
+ // rigorous matching:
26
+ // 1. Exact match: cap + ".tool.md"
27
+ // 2. Name match: file starts with cap + "."
28
+ // 3. Simple fuzzy?
29
+ const match = files.find(f => f === `${cap}.tool.md` ||
30
+ f === `${cap.replace(/_/g, '-')}.tool.md` ||
31
+ f.startsWith(`${cap}.`));
32
+ if (match) {
33
+ const toolPath = path_1.default.join(this.toolsDir, match);
34
+ const content = await fs_extra_1.default.readFile(toolPath, 'utf-8');
35
+ loadedTools.push({
36
+ name: cap,
37
+ path: toolPath,
38
+ content: content
39
+ });
40
+ }
41
+ else {
42
+ console.warn(`[WARN] No tool definition found for capability: ${cap}`);
43
+ }
44
+ }
45
+ return loadedTools;
46
+ }
47
+ }
48
+ exports.ToolLoader = ToolLoader;
@@ -0,0 +1,152 @@
1
+ # Contextuate Framework
2
+
3
+ > **DO NOT MODIFY FILES IN THIS DIRECTORY**
4
+ >
5
+ > This folder contains the core Contextuate framework files. These are managed by the installer and will be overwritten during updates.
6
+
7
+ ---
8
+
9
+ ## Quick Start
10
+
11
+ After installation, customize your project context in `docs/ai/context.md`. AI assistants will automatically read this file when they start.
12
+
13
+ ---
14
+
15
+ ## Available Tools
16
+
17
+ Contextuate includes AI tool guides - markdown files that AI assistants read and follow to perform tasks. Ask your AI assistant to use these tools with natural language.
18
+
19
+ ### Standards Detector
20
+
21
+ Analyzes your codebase to detect and document coding standards.
22
+
23
+ **How to use:** Ask your AI assistant:
24
+ > "Detect the coding standards for this project"
25
+ > "Analyze my code and create coding standards"
26
+ > "Generate standards documentation from my source files"
27
+
28
+ **What it does:**
29
+ 1. Scans for source files (PHP, JS, TS, etc.)
30
+ 2. Checks for config files (.eslintrc, phpcs.xml, etc.)
31
+ 3. Analyzes patterns (indentation, naming, braces)
32
+ 4. Creates standards files in `docs/ai/standards/`
33
+
34
+ **Guide:** [tools/standards-detector.tool.md](tools/standards-detector.tool.md)
35
+
36
+ ---
37
+
38
+ ### Quickref Generator
39
+
40
+ Creates condensed, AI-friendly references from large documentation files.
41
+
42
+ **How to use:** Ask your AI assistant:
43
+ > "Generate a quickref for docs/classes/user-service.md"
44
+ > "Create a quick reference for the API documentation"
45
+ > "Make a condensed reference for this class"
46
+
47
+ **What it does:**
48
+ 1. Reads source documentation
49
+ 2. Extracts method/API signatures
50
+ 3. Creates scannable reference tables
51
+ 4. Outputs to `docs/ai/quickrefs/{name}.quickref.md`
52
+
53
+ **When to use:**
54
+ - Documentation exceeds ~200 lines
55
+ - Methods are frequently looked up
56
+ - AI needs method awareness without full context
57
+
58
+ **Guide:** [tools/quickref.tool.md](tools/quickref.tool.md)
59
+
60
+ ---
61
+
62
+ ### Agent Creator
63
+
64
+ Creates new AI agent definitions following Contextuate patterns.
65
+
66
+ **How to use:** Ask your AI assistant:
67
+ > "Create an agent for database operations"
68
+ > "Make a new agent for the authentication system"
69
+ > "Generate an agent definition for React components"
70
+
71
+ **What it does:**
72
+ 1. Determines agent scope and responsibilities
73
+ 2. Creates supporting docs if needed
74
+ 3. Generates agent file from template
75
+ 4. Outputs to `docs/ai/agents/{domain}-expert.md`
76
+
77
+ **Guide:** [tools/agent-creator.tool.md](tools/agent-creator.tool.md)
78
+
79
+ ---
80
+
81
+ ## Directory Structure
82
+
83
+ ```
84
+ docs/ai/
85
+ ├── .context/ # Framework files (DO NOT MODIFY)
86
+ │ ├── agents/ # Base agent definitions
87
+ │ ├── standards/ # Default coding/behavioral standards
88
+ │ ├── templates/ # Platform jump-files and standards templates
89
+ │ ├── tools/ # AI tool guides
90
+ │ └── bin/ # Install/update scripts
91
+ ├── agents/ # Your custom agents (user-editable)
92
+ ├── standards/ # Your project standards (user-editable)
93
+ ├── quickrefs/ # Generated quick references
94
+ ├── tasks/ # Task tracking (gitignored)
95
+ └── context.md # Your project context (user-editable)
96
+ ```
97
+
98
+ ---
99
+
100
+ ## Standards Resolution
101
+
102
+ When AI looks up coding standards for a language:
103
+
104
+ 1. **User Standards (First):** `docs/ai/standards/{language}.standards.md`
105
+ 2. **Framework Standards (Fallback):** `docs/ai/.context/templates/standards/{language}.standards.md`
106
+ 3. **General Principles (Always):** `docs/ai/.context/standards/coding-standards.md`
107
+
108
+ ---
109
+
110
+ ## Framework Scripts
111
+
112
+ ### install.sh
113
+
114
+ ```bash
115
+ # Remote installation
116
+ curl -fsSL https://contextuate.md/install.sh | bash
117
+
118
+ # With options
119
+ curl -fsSL https://contextuate.md/install.sh | bash -s -- --force
120
+ ```
121
+
122
+ **Options:**
123
+ - `--force` - Overwrite existing files
124
+ - `--no-git` - Don't modify .gitignore
125
+
126
+ ### update.sh
127
+
128
+ ```bash
129
+ ./docs/ai/.context/bin/update.sh
130
+ ```
131
+
132
+ Updates framework files while preserving your customizations.
133
+
134
+ ---
135
+
136
+ ## Agents vs Tools
137
+
138
+ | Type | Purpose | Location |
139
+ |------|---------|----------|
140
+ | **Agent** | Persona with expertise, decision-making | `agents/*.md` |
141
+ | **Tool** | Step-by-step process guide | `tools/*.tool.md` |
142
+
143
+ **Agents** define *who* the AI is acting as (e.g., "documentation expert").
144
+ **Tools** define *how* to accomplish a specific task (e.g., "follow these steps to generate a quickref").
145
+
146
+ ---
147
+
148
+ ## Support
149
+
150
+ - Documentation: https://contextuate.md
151
+ - Repository: https://github.com/esotech/contextuate
152
+ - Issues: https://github.com/esotech/contextuate/issues