universal-agent-protocol 0.10.3 → 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.
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Universal Agent Protocol (UAP) CLI
4
+ *
5
+ * This is the main UAP command-line interface that works independently
6
+ * from opencode. It provides project initialization, configuration,
7
+ * and integration with various agent harnesses.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=uap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uap.d.ts","sourceRoot":"","sources":["../../src/cli/uap.ts"],"names":[],"mappings":";AACA;;;;;;GAMG"}
@@ -0,0 +1,346 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Universal Agent Protocol (UAP) CLI
4
+ *
5
+ * This is the main UAP command-line interface that works independently
6
+ * from opencode. It provides project initialization, configuration,
7
+ * and integration with various agent harnesses.
8
+ */
9
+ import { execSync } from 'child_process';
10
+ import { existsSync, mkdirSync, writeFileSync, readFileSync } from 'fs';
11
+ import path from 'path';
12
+ import { fileURLToPath } from 'url';
13
+ const __filename = fileURLToPath(import.meta.url);
14
+ const __dirname = path.dirname(__filename);
15
+ const projectRoot = path.resolve(__dirname, '..', '..');
16
+ const UAP_VERSION = '2.0.0';
17
+ class UAPCli {
18
+ async run(args) {
19
+ const command = args[0];
20
+ switch (command) {
21
+ case 'init':
22
+ await this.init();
23
+ break;
24
+ case 'setup':
25
+ await this.setup(args.slice(1));
26
+ break;
27
+ case 'install':
28
+ await this.install(args.slice(1));
29
+ break;
30
+ case 'uninstall':
31
+ await this.uninstall();
32
+ break;
33
+ case 'hooks':
34
+ await this.hooks(args.slice(1));
35
+ break;
36
+ case 'plugins':
37
+ await this.plugins(args.slice(1));
38
+ break;
39
+ case 'version':
40
+ case '-v':
41
+ case '--version':
42
+ console.log(`uap version ${UAP_VERSION}`);
43
+ break;
44
+ case '--help':
45
+ case '-h':
46
+ default:
47
+ this.printHelp();
48
+ break;
49
+ }
50
+ }
51
+ printHelp() {
52
+ console.log(`
53
+ Universal Agent Protocol (UAP) v${UAP_VERSION}
54
+ AI agents that learn and remember across sessions
55
+
56
+ USAGE:
57
+ uap <command> [options]
58
+
59
+ COMMANDS:
60
+ init Initialize UAP in current project
61
+ setup [options] Run comprehensive UAP setup
62
+ install <harness> Install UAP plugins for specific harness (opencode, etc.)
63
+ uninstall Remove UAP from current project
64
+ hooks Manage UAP hooks
65
+ plugins List and manage UAP plugins
66
+
67
+ OPTIONS:
68
+ -p, --project Target project directory
69
+ -h, --harness Target agent harness (opencode, claude-code, etc.)
70
+ -f, --force Force operations without confirmation
71
+ -v, --verbose Enable verbose output
72
+ --version Show version number
73
+ --help Show this help message
74
+
75
+ EXAMPLES:
76
+ uap init # Initialize UAP in current directory
77
+ uap setup -p all # Full setup with all components
78
+ uap install opencode # Install UAP plugins for opencode harness
79
+ uap hooks list # List available hooks
80
+ `);
81
+ }
82
+ async init() {
83
+ console.log('🔧 Initializing Universal Agent Protocol...\n');
84
+ const projectDir = process.cwd();
85
+ const uapConfig = path.join(projectDir, '.uap.json');
86
+ const claudeMd = path.join(projectDir, 'CLAUDE.md');
87
+ // Create .uap.json config
88
+ const config = {
89
+ version: UAP_VERSION,
90
+ project: projectDir,
91
+ initialized: true,
92
+ timestamp: new Date().toISOString(),
93
+ features: {
94
+ memory: true,
95
+ hooks: true,
96
+ plugins: true,
97
+ droids: false,
98
+ skills: false,
99
+ },
100
+ };
101
+ writeFileSync(uapConfig, JSON.stringify(config, null, 2));
102
+ console.log('✓ Created .uap.json configuration');
103
+ // Check if CLAUDE.md exists
104
+ if (!existsSync(claudeMd)) {
105
+ console.log('ℹ No CLAUDE.md found. You can create one manually or with: uap setup -p claude-md');
106
+ }
107
+ else {
108
+ console.log('✓ CLAUDE.md detected');
109
+ }
110
+ console.log('\n✅ UAP initialized successfully!');
111
+ console.log(`\nNext steps:`);
112
+ console.log(` uap setup -p all # Run full setup`);
113
+ console.log(` uap install opencode # Install for opencode harness`);
114
+ }
115
+ async setup(args) {
116
+ console.log('🔧 Running UAP setup...\n');
117
+ const projectDir = process.cwd();
118
+ // Check if initialized
119
+ const uapConfigPath = path.join(projectDir, '.uap.json');
120
+ if (!existsSync(uapConfigPath)) {
121
+ console.log('❌ UAP not initialized. Run: uap init');
122
+ return;
123
+ }
124
+ const config = JSON.parse(readFileSync(uapConfigPath, 'utf8'));
125
+ // Install components based on options
126
+ const hasAll = args.includes('-p') || args.includes('--project');
127
+ const setupMemory = hasAll || args.includes('memory');
128
+ const setupHooks = hasAll || args.includes('hooks');
129
+ const setupMCP = hasAll || args.includes('mcp-router');
130
+ if (setupMemory) {
131
+ await this.installMemory(projectDir);
132
+ }
133
+ if (setupHooks) {
134
+ await this.installHooks(projectDir);
135
+ }
136
+ if (setupMCP) {
137
+ await this.installMCPRouter(projectDir);
138
+ }
139
+ // Update config
140
+ config.lastSetup = new Date().toISOString();
141
+ writeFileSync(uapConfigPath, JSON.stringify(config, null, 2));
142
+ console.log('\n✅ UAP setup complete!');
143
+ }
144
+ async install(args) {
145
+ if (args.length === 0) {
146
+ console.log('❌ Please specify a harness: uap install <harness>');
147
+ console.log('Available harnesses: opencode, claude-code, etc.');
148
+ return;
149
+ }
150
+ const harness = args[0];
151
+ console.log(`🔧 Installing UAP plugins for ${harness}...\n`);
152
+ switch (harness) {
153
+ case 'opencode':
154
+ await this.installForOpencode();
155
+ break;
156
+ case 'claude-code':
157
+ await this.installForClaudeCode();
158
+ break;
159
+ default:
160
+ console.log(`ℹ Plugin installation for ${harness} not yet implemented.`);
161
+ console.log('Available harnesses: opencode, claude-code');
162
+ }
163
+ }
164
+ async installForOpencode() {
165
+ const homeDir = process.env.HOME || '';
166
+ const opencodeDir = path.join(homeDir, '.opencode');
167
+ const pluginsDir = path.join(opencodeDir, 'plugin');
168
+ if (!existsSync(opencodeDir)) {
169
+ console.log(`ℹ Opencode not found at ${opencodeDir}`);
170
+ console.log('Installing UAP to opencode...');
171
+ mkdirSync(pluginsDir, { recursive: true });
172
+ }
173
+ else {
174
+ mkdirSync(pluginsDir, { recursive: true });
175
+ }
176
+ await this.copyPluginsToDir(pluginsDir);
177
+ // Create opencode config if needed
178
+ const opencodeConfig = path.join(opencodeDir, 'config.json');
179
+ if (!existsSync(opencodeConfig)) {
180
+ const config = {
181
+ uapEnabled: true,
182
+ uapVersion: UAP_VERSION,
183
+ installedAt: new Date().toISOString(),
184
+ };
185
+ writeFileSync(opencodeConfig, JSON.stringify(config, null, 2));
186
+ console.log('✓ Created opencode config with UAP integration');
187
+ }
188
+ console.log('\n✅ UAP successfully integrated with opencode!');
189
+ }
190
+ async installForClaudeCode() {
191
+ const homeDir = process.env.HOME || '';
192
+ const claudeCodeDir = path.join(homeDir, '.claude', 'code');
193
+ const hooksDir = path.join(claudeCodeDir, '.factory', 'hooks');
194
+ if (!existsSync(claudeCodeDir)) {
195
+ console.log(`ℹ Claude Code not found at ${claudeCodeDir}`);
196
+ console.log('Installing UAP to claude-code...');
197
+ mkdirSync(hooksDir, { recursive: true });
198
+ }
199
+ else {
200
+ mkdirSync(hooksDir, { recursive: true });
201
+ }
202
+ // Copy hook scripts for claude-code from plugin directory
203
+ const hooks = ['session-start.sh', 'pre-compact.sh'];
204
+ for (const hook of hooks) {
205
+ const src = path.join(projectRoot, 'tools', 'agents', 'plugin', hook);
206
+ const dest = path.join(hooksDir, hook);
207
+ if (existsSync(src)) {
208
+ try {
209
+ const content = readFileSync(src, 'utf8');
210
+ writeFileSync(dest, content);
211
+ console.log(`✓ Installed ${hook}`);
212
+ }
213
+ catch (e) {
214
+ console.log(`✗ Failed to install ${hook}: ${e}`);
215
+ }
216
+ }
217
+ else {
218
+ console.log(`ℹ Hook not found: ${hook}`);
219
+ }
220
+ }
221
+ // Create claude-code config if needed
222
+ const claudeConfig = path.join(claudeCodeDir, 'config.json');
223
+ if (!existsSync(claudeConfig)) {
224
+ const config = {
225
+ uapEnabled: true,
226
+ uapVersion: UAP_VERSION,
227
+ installedAt: new Date().toISOString(),
228
+ };
229
+ writeFileSync(claudeConfig, JSON.stringify(config, null, 2));
230
+ console.log('✓ Created claude-code config with UAP integration');
231
+ }
232
+ console.log('\n✅ UAP successfully integrated with claude-code!');
233
+ }
234
+ async copyPluginsToDir(destDir) {
235
+ const uapPlugins = [
236
+ 'uap-commands.ts',
237
+ 'uap-droids.ts',
238
+ 'uap-skills.ts',
239
+ 'uap-patterns.ts',
240
+ 'session-start.sh',
241
+ 'pre-compact.sh',
242
+ ];
243
+ for (const plugin of uapPlugins) {
244
+ const src = path.join(projectRoot, 'tools', 'agents', 'plugin', plugin);
245
+ const dest = path.join(destDir, plugin);
246
+ if (existsSync(src)) {
247
+ try {
248
+ const content = readFileSync(src, 'utf8');
249
+ writeFileSync(dest, content);
250
+ console.log(`✓ Installed ${plugin}`);
251
+ }
252
+ catch (e) {
253
+ console.log(`✗ Failed to install ${plugin}: ${e}`);
254
+ }
255
+ }
256
+ else {
257
+ console.log(`ℹ Plugin not found: ${plugin}`);
258
+ }
259
+ }
260
+ }
261
+ async installMemory(projectDir) {
262
+ console.log('🔧 Setting up memory system...');
263
+ const memoryDir = path.join(projectDir, 'agents', 'data', 'memory');
264
+ mkdirSync(memoryDir, { recursive: true });
265
+ const shortTermDB = path.join(memoryDir, 'short_term.db');
266
+ const longTermDB = path.join(memoryDir, 'long_term.db');
267
+ // Initialize SQLite databases
268
+ try {
269
+ execSync(`sqlite3 ${shortTermDB} "CREATE TABLE IF NOT EXISTS memories (id INTEGER PRIMARY KEY, content TEXT, metadata TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP);"`);
270
+ console.log('✓ Created short-term memory database');
271
+ execSync(`sqlite3 ${longTermDB} "CREATE TABLE IF NOT EXISTS lessons (id INTEGER PRIMARY KEY, title TEXT, content TEXT, category TEXT, importance INTEGER, created_at DATETIME DEFAULT CURRENT_TIMESTAMP);"`);
272
+ console.log('✓ Created long-term memory database');
273
+ }
274
+ catch (e) {
275
+ console.log('ℹ SQLite not available for in-memory setup');
276
+ }
277
+ console.log('✅ Memory system initialized!');
278
+ }
279
+ async installHooks(projectDir) {
280
+ console.log('🔧 Installing UAP hooks...');
281
+ const hooksDir = path.join(projectDir, '.factory', 'hooks');
282
+ mkdirSync(hooksDir, { recursive: true });
283
+ // Copy hook scripts
284
+ const hooks = ['session-start.sh', 'pre-compact.sh'];
285
+ for (const hook of hooks) {
286
+ const src = path.join(projectRoot, '.factory', 'hooks', hook);
287
+ const dest = path.join(hooksDir, hook);
288
+ if (existsSync(src)) {
289
+ try {
290
+ const content = readFileSync(src, 'utf8');
291
+ writeFileSync(dest, content);
292
+ console.log(`✓ Installed ${hook}`);
293
+ }
294
+ catch (e) {
295
+ console.log(`✗ Failed to install ${hook}: ${e}`);
296
+ }
297
+ }
298
+ else {
299
+ console.log(`ℹ Hook not found: ${hook}`);
300
+ }
301
+ }
302
+ console.log('✅ Hooks installed!');
303
+ }
304
+ async installMCPRouter(_projectDir) {
305
+ console.log('🔧 Setting up MCP Router...');
306
+ // MCP router setup would go here
307
+ console.log('ℹ MCP Router configuration pending implementation');
308
+ console.log('✅ MCP Router placeholder created!');
309
+ }
310
+ async uninstall() {
311
+ console.log('❌ UAP uninstall not yet implemented');
312
+ console.log('To manually remove UAP:');
313
+ console.log(' rm -rf .uap.json .factory/hooks agents/data/memory');
314
+ }
315
+ async hooks(args) {
316
+ const command = args[0];
317
+ switch (command) {
318
+ case 'list':
319
+ console.log('Available UAP hooks:');
320
+ console.log(' - session-start: Run at session initialization');
321
+ console.log(' - pre-compact: Run before context compression');
322
+ console.log(' - post-complete: Run after task completion');
323
+ break;
324
+ case 'install':
325
+ await this.installHooks(process.cwd());
326
+ break;
327
+ default:
328
+ this.printHelp();
329
+ }
330
+ }
331
+ async plugins(args) {
332
+ console.log('UAP Plugins:');
333
+ console.log(' - uap-session-hooks: Session management hooks');
334
+ console.log(' - uap-commands: UAP command definitions');
335
+ console.log(' - uap-droids: Specialized agent droids');
336
+ console.log(' - uap-skills: Domain-specific skills');
337
+ console.log(' - uap-patterns: Reusable coding patterns');
338
+ if (args[0] === 'install') {
339
+ await this.install(args.slice(1));
340
+ }
341
+ }
342
+ }
343
+ // Main entry point
344
+ const cli = new UAPCli();
345
+ cli.run(process.argv.slice(2)).catch(console.error);
346
+ //# sourceMappingURL=uap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"uap.js","sourceRoot":"","sources":["../../src/cli/uap.ts"],"names":[],"mappings":";AACA;;;;;;GAMG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC3C,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAExD,MAAM,WAAW,GAAG,OAAO,CAAC;AAE5B,MAAM,MAAM;IACV,KAAK,CAAC,GAAG,CAAC,IAAc;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAExB,QAAQ,OAAO,EAAE,CAAC;YAChB,KAAK,MAAM;gBACT,MAAM,IAAI,CAAC,IAAI,EAAE,CAAC;gBAClB,MAAM;YACR,KAAK,OAAO;gBACV,MAAM,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;gBAChC,MAAM;YACR,KAAK,SAAS;gBACZ,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,C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AC,GAAG,CAAC,wCAAwC,CAAC,CAAC;QACtD,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;QAE1D,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,SAAS,EAAE,CAAC;YAC1B,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;CACF;AAED,mBAAmB;AACnB,MAAM,GAAG,GAAG,IAAI,MAAM,EAAE,CAAC;AACzB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "universal-agent-protocol",
3
- "version": "0.10.3",
3
+ "version": "2.0.0",
4
4
  "description": "Autonomous AI agent memory system with CLAUDE.md protocol enforcement",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -8,7 +8,8 @@
8
8
  "bin": {
9
9
  "qwen-tool-call-test": "./tools/agents/scripts/qwen-tool-call-test.js",
10
10
  "qwen-tool-call-wrapper": "./tools/agents/scripts/qwen-tool-call-wrapper.js",
11
- "fix-qwen-template": "./tools/agents/scripts/fix-qwen-template.js"
11
+ "fix-qwen-template": "./tools/agents/scripts/fix-qwen-template.js",
12
+ "uap": "./dist/cli/uap.js"
12
13
  },
13
14
  "scripts": {
14
15
  "build": "tsc",
@@ -0,0 +1,91 @@
1
+ # UAP Plugins
2
+
3
+ This directory contains all UAP (Universal Agent Protocol) plugins, hooks, and utilities.
4
+
5
+ ## Plugin Files
6
+
7
+ ### TypeScript Plugins
8
+
9
+ - **uap-commands.ts** - Defines UAP-specific commands for opencode integration
10
+ - **uap-droids.ts** - Specialized agent droids (code reviewer, security auditor, etc.)
11
+ - **uap-skills.ts** - Domain-specific skills (git workflow, testing patterns, etc.)
12
+ - **uap-patterns.ts** - Reusable coding patterns distilled from experience
13
+
14
+ ### Shell Hooks
15
+
16
+ - **session-start.sh** - Runs at session initialization to enforce UAP compliance
17
+ - **pre-compact.sh** - Runs before context compression to preserve critical information
18
+
19
+ ## Usage
20
+
21
+ ### Install Plugins
22
+
23
+ To install all UAP plugins for opencode:
24
+
25
+ ```bash
26
+ uap install opencode
27
+ ```
28
+
29
+ This will copy all plugin files to `~/.opencode/plugin/`.
30
+
31
+ ### Available Droids
32
+
33
+ - **code-reviewer** - Reviews code changes for quality and security
34
+ - **security-auditor** - Audits code for security vulnerabilities
35
+ - **performance-optimizer** - Analyzes and optimizes performance bottlenecks
36
+ - **unit-tester** - Generates comprehensive unit tests
37
+ - **debug-helper** - Helps diagnose and fix bugs
38
+
39
+ ### Available Skills
40
+
41
+ - **git-workflow** - Manages git workflows with worktrees and branches
42
+ - **testing-patterns** - Applies testing best practices and patterns
43
+ - **ci-cd-setup** - Configures continuous integration and deployment pipelines
44
+ - **documentation-gen** - Generates and maintains project documentation
45
+
46
+ ### Available Patterns
47
+
48
+ - **generic-uap-patterns** - Distilled patterns from tbench-specific implementation
49
+ - **worktree-isolation** - Use git worktrees for isolated feature development
50
+ - **session-persistence** - Maintain state across sessions using memory system
51
+ - **task-tracking** - Track and manage tasks with UAP task system
52
+ - **agent-coordination** - Coordinate multiple AI agents for complex tasks
53
+
54
+ ## Plugin Manifest
55
+
56
+ Each plugin is registered in the `index.ts` file which exports:
57
+
58
+ - Version information
59
+ - Plugin manifest with hooks, droids, skills, and patterns
60
+ - Individual plugin modules
61
+
62
+ ## Creating New Plugins
63
+
64
+ To add a new plugin:
65
+
66
+ 1. Create a new TypeScript file in this directory
67
+ 2. Export definitions using the appropriate interfaces
68
+ 3. Add to the `index.ts` exports
69
+ 4. Register in the `uapPluginManifest`
70
+
71
+ Example:
72
+
73
+ ```typescript
74
+ export interface MyPlugin {
75
+ id: string;
76
+ name: string;
77
+ description: string;
78
+ enabled: boolean;
79
+ }
80
+
81
+ export const myPlugin: MyPlugin = {
82
+ id: 'my-plugin',
83
+ name: 'My Plugin',
84
+ description: 'Description of my plugin',
85
+ enabled: true,
86
+ };
87
+ ```
88
+
89
+ ## License
90
+
91
+ Part of Universal Agent Protocol v0.10.3
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * UAP Plugin Index
4
+ *
5
+ * This file serves as the main entry point for all UAP plugins.
6
+ * It exports all available plugins, hooks, and utilities.
7
+ */
8
+
9
+ import { uapCommands } from './uap-commands.js';
10
+ import { uapDroids } from './uap-droids.js';
11
+ import { uapSkills } from './uap-skills.js';
12
+ import { uapPatterns } from './uap-patterns.js';
13
+
14
+ export const UAP_VERSION = '0.10.3';
15
+
16
+ export interface UAPPluginManifest {
17
+ name: string;
18
+ version: string;
19
+ description: string;
20
+ hooks?: string[];
21
+ droids?: string[];
22
+ skills?: string[];
23
+ patterns?: string[];
24
+ }
25
+
26
+ export const uapPluginManifest: UAPPluginManifest = {
27
+ name: 'universal-agent-protocol',
28
+ version: UAP_VERSION,
29
+ description: 'Universal Agent Protocol - AI agents that learn and remember across sessions',
30
+ hooks: ['session-start.sh', 'pre-compact.sh'],
31
+ droids: uapDroids.map((d) => d.id),
32
+ skills: uapSkills.map((s) => s.id),
33
+ patterns: uapPatterns.map((p) => p.id),
34
+ };
35
+
36
+ export { uapCommands, uapDroids, uapSkills, uapPatterns };
37
+
38
+ // Default export for easy importing
39
+ export default {
40
+ version: UAP_VERSION,
41
+ manifest: uapPluginManifest,
42
+ commands: uapCommands,
43
+ droids: uapDroids,
44
+ skills: uapSkills,
45
+ patterns: uapPatterns,
46
+ };
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env bash
2
+ # UAP Pre-Compact Hook for Claude Code
3
+ # 1. Checks compliance state and warns on violations
4
+ # 2. Writes a timestamp marker to the daily log before context compaction
5
+ # 3. Marks any agents registered by this session as completed
6
+ # Fails safely - never blocks the agent.
7
+ set -euo pipefail
8
+
9
+ PROJECT_DIR="${CLAUDE_PROJECT_DIR:-.}"
10
+ DB_PATH="${PROJECT_DIR}/agents/data/memory/short_term.db"
11
+ COORD_DB="${PROJECT_DIR}/agents/data/coordination/coordination.db"
12
+
13
+ if [ ! -f "$DB_PATH" ]; then
14
+ exit 0
15
+ fi
16
+
17
+ TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
18
+
19
+ # Record a compaction marker in memory so sessions can detect context resets
20
+ sqlite3 "$DB_PATH" "
21
+ INSERT OR IGNORE INTO memories (timestamp, type, content)
22
+ VALUES ('$TIMESTAMP', 'action', '[pre-compact] Context compaction at $TIMESTAMP');
23
+ " 2>/dev/null || true
24
+
25
+ # Check if any lessons were stored this session
26
+ recent_lessons=$(sqlite3 "$DB_PATH" "
27
+ SELECT COUNT(*) FROM session_memories
28
+ WHERE timestamp >= datetime('now', '-2 hours')
29
+ AND type = 'decision';
30
+ " 2>/dev/null || echo "0")
31
+
32
+ output=""
33
+
34
+ # Compliance reminder on compaction
35
+ output+="<system-reminder>"$'\n'
36
+ output+="## UAP COMPLIANCE REMINDER (Pre-Compact)"$'\n'
37
+ output+=""$'\n'
38
+ output+="Context is being compacted. Before continuing work after compaction:"$'\n'
39
+ output+="1. Re-run: uap task ready"$'\n'
40
+ output+="2. Re-query memory for current task context"$'\n'
41
+ output+="3. Check for stale worktrees: uap worktree list"$'\n'
42
+ output+=""$'\n'
43
+
44
+ if [ "$recent_lessons" = "0" ]; then
45
+ output+="WARNING: No lessons stored this session. Before compaction completes,"$'\n'
46
+ output+="store a summary: sqlite3 ./agents/data/memory/short_term.db \"INSERT INTO session_memories (session_id,timestamp,type,content,importance) VALUES ('current',datetime('now'),'decision','<summary>',7);\""$'\n'
47
+ fi
48
+
49
+ output+="</system-reminder>"$'\n'
50
+
51
+ echo "$output"
52
+
53
+ # Clean up agents with recent heartbeats (likely from this session being compacted)
54
+ if [ -f "$COORD_DB" ]; then
55
+ sqlite3 "$COORD_DB" "
56
+ DELETE FROM work_claims WHERE agent_id IN (
57
+ SELECT id FROM agent_registry
58
+ WHERE status='active' AND last_heartbeat >= datetime('now','-5 minutes')
59
+ );
60
+ UPDATE work_announcements SET completed_at='$TIMESTAMP'
61
+ WHERE completed_at IS NULL AND agent_id IN (
62
+ SELECT id FROM agent_registry
63
+ WHERE status='active' AND last_heartbeat >= datetime('now','-5 minutes')
64
+ );
65
+ UPDATE agent_registry SET status='completed'
66
+ WHERE status='active' AND last_heartbeat >= datetime('now','-5 minutes');
67
+ " 2>/dev/null || true
68
+ fi
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env bash
2
+ # UAP Session Start Hook for Claude Code
3
+ # COMPLIANCE ENFORCEMENT: Outputs mandatory protocol checklist
4
+ # that the AI agent MUST complete before any work begins.
5
+ # Fails safely - never blocks the agent.
6
+ set -euo pipefail
7
+
8
+ PROJECT_DIR="${CLAUDE_PROJECT_DIR:-.}"
9
+ DB_PATH="${PROJECT_DIR}/agents/data/memory/short_term.db"
10
+ COORD_DB="${PROJECT_DIR}/agents/data/coordination/coordination.db"
11
+
12
+ if [ ! -f "$DB_PATH" ]; then
13
+ exit 0
14
+ fi
15
+
16
+ # Clean stale agents from coordination DB (heartbeat >24h old)
17
+ if [ -f "$COORD_DB" ]; then
18
+ sqlite3 "$COORD_DB" "
19
+ DELETE FROM work_claims WHERE agent_id IN (
20
+ SELECT id FROM agent_registry
21
+ WHERE status IN ('active','idle') AND last_heartbeat < datetime('now','-24 hours')
22
+ );
23
+ DELETE FROM work_announcements WHERE agent_id IN (
24
+ SELECT id FROM agent_registry
25
+ WHERE status IN ('active','idle') AND last_heartbeat < datetime('now','-24 hours')
26
+ ) AND completed_at IS NULL;
27
+ UPDATE agent_registry SET status='failed'
28
+ WHERE status IN ('active','idle') AND last_heartbeat < datetime('now','-24 hours');
29
+ DELETE FROM agent_registry
30
+ WHERE status IN ('completed','failed') AND started_at < datetime('now','-7 days');
31
+ DELETE FROM agent_messages WHERE created_at < datetime('now','-24 hours');
32
+ " 2>/dev/null || true
33
+ fi
34
+
35
+ output=""
36
+
37
+ # ============================================================
38
+ # COMPLIANCE ENFORCEMENT BLOCK
39
+ # This is injected as system context. The AI MUST follow these.
40
+ # ============================================================
41
+ output+="<system-reminder>"$'\n'
42
+ output+="## UAP COMPLIANCE - MANDATORY PROTOCOL"$'\n'
43
+ output+=""$'\n'
44
+ output+="You MUST complete these steps IN ORDER before doing ANY work."$'\n'
45
+ output+="Skipping ANY step is a critical protocol violation."$'\n'
46
+ output+=""$'\n'
47
+ output+="### BEFORE WORK (execute these commands NOW):"$'\n'
48
+ output+="1. Run: uap task ready"$'\n'
49
+ output+="2. Run: sqlite3 ./agents/data/memory/short_term.db \"SELECT type, substr(content,1,80) FROM memories ORDER BY id DESC LIMIT 5;\""$'\n'
50
+ output+="3. Run: uap memory query \"<relevant to user request>\""$'\n'
51
+ output+="4. On work request: Run: uap task create --type <task|bug|feature> --title \"<description>\""$'\n'
52
+ output+=""$'\n'
53
+ output+="### DURING WORK:"$'\n'
54
+ output+="5. ALL file changes MUST use worktree: uap worktree create <slug>"$'\n'
55
+ output+="6. Work in .worktrees/NNN-<slug>/ directory"$'\n'
56
+ output+=""$'\n'
57
+ output+="### BEFORE COMMIT:"$'\n'
58
+ output+="7. Self-review: git diff"$'\n'
59
+ output+="8. Run tests if applicable"$'\n'
60
+ output+=""$'\n'
61
+ output+="### AFTER WORK:"$'\n'
62
+ output+="9. Store lesson: sqlite3 ./agents/data/memory/short_term.db \"INSERT INTO session_memories (session_id,timestamp,type,content,importance) VALUES ('current',datetime('now'),'decision','<summary of work and lessons>',7);\""$'\n'
63
+ output+="10. Clean up worktree after PR merge: uap worktree cleanup <id>"$'\n'
64
+ output+=""$'\n'
65
+ output+="FAILURE TO COMPLY = CRITICAL VIOLATION. This is life or death."$'\n'
66
+ output+="</system-reminder>"$'\n\n'
67
+
68
+ # Recent memories (last 24h, high importance)
69
+ recent=$(sqlite3 "$DB_PATH" "
70
+ SELECT type, substr(content, 1, 120) FROM memories
71
+ WHERE timestamp >= datetime('now', '-1 day')
72
+ ORDER BY id DESC
73
+ LIMIT 10;
74
+ " 2>/dev/null || true)
75
+
76
+ if [ -n "$recent" ]; then
77
+ output+="## Recent Memory Context"$'\n'
78
+ output+="$recent"$'\n\n'
79
+ fi
80
+
81
+ # Open loops from session memories
82
+ open_loops=$(sqlite3 "$DB_PATH" "
83
+ SELECT content FROM session_memories
84
+ WHERE type IN ('action','goal','decision')
85
+ AND importance >= 7
86
+ ORDER BY id DESC
87
+ LIMIT 5;
88
+ " 2>/dev/null || true)
89
+
90
+ if [ -n "$open_loops" ]; then
91
+ output+="## Open Loops"$'\n'
92
+ output+="$open_loops"$'\n'
93
+ fi
94
+
95
+ # Stale worktrees warning
96
+ if [ -d "${PROJECT_DIR}/.worktrees" ]; then
97
+ stale_count=$(find "${PROJECT_DIR}/.worktrees" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | wc -l)
98
+ if [ "$stale_count" -gt 0 ]; then
99
+ output+=$'\n'"## Stale Worktrees Warning"$'\n'
100
+ output+="There are $stale_count worktrees. Run 'uap worktree list' and clean up merged ones."$'\n'
101
+ fi
102
+ fi
103
+
104
+ if [ -n "$output" ]; then
105
+ echo "$output"
106
+ fi
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * UAP Commands Plugin for opencode
4
+ *
5
+ * Defines UAP-specific commands that can be used within opencode.
6
+ */
7
+
8
+ export const uapCommands = {
9
+ name: 'uap',
10
+ description: 'Universal Agent Protocol commands',
11
+ commands: [
12
+ {
13
+ name: 'init',
14
+ description: 'Initialize UAP in current project',
15
+ usage: 'uap init',
16
+ },
17
+ {
18
+ name: 'setup',
19
+ description: 'Run comprehensive UAP setup',
20
+ usage: 'uap setup [-p all | memory | hooks | mcp-router]',
21
+ },
22
+ {
23
+ name: 'install',
24
+ description: 'Install UAP plugins for a harness',
25
+ usage: 'uap install <harness>',
26
+ },
27
+ {
28
+ name: 'task',
29
+ description: 'Create and manage tasks',
30
+ usage: 'uap task create --type <task|bug|feature> --title "<description>"',
31
+ },
32
+ {
33
+ name: 'worktree',
34
+ description: 'Manage git worktrees for isolated development',
35
+ usage: 'uap worktree <command>',
36
+ },
37
+ {
38
+ name: 'memory',
39
+ description: 'Query and manage memory system',
40
+ usage: 'uap memory query "<query>"',
41
+ },
42
+ ],
43
+ };
44
+
45
+ export default uapCommands;
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * UAP Droids Plugin for opencode
4
+ *
5
+ * Defines specialized agent droids that can be invoked via UAP.
6
+ */
7
+
8
+ export interface UDroidDefinition {
9
+ id: string;
10
+ name: string;
11
+ description: string;
12
+ category: 'code' | 'review' | 'debug' | 'test' | 'deploy';
13
+ enabled: boolean;
14
+ }
15
+
16
+ export const uapDroids: UDroidDefinition[] = [
17
+ {
18
+ id: 'code-reviewer',
19
+ name: 'Code Reviewer',
20
+ description: 'Reviews code changes for quality and security',
21
+ category: 'review',
22
+ enabled: true,
23
+ },
24
+ {
25
+ id: 'security-auditor',
26
+ name: 'Security Auditor',
27
+ description: 'Audits code for security vulnerabilities',
28
+ category: 'review',
29
+ enabled: false,
30
+ },
31
+ {
32
+ id: 'performance-optimizer',
33
+ name: 'Performance Optimizer',
34
+ description: 'Analyzes and optimizes performance bottlenecks',
35
+ category: 'code',
36
+ enabled: false,
37
+ },
38
+ {
39
+ id: 'unit-tester',
40
+ name: 'Unit Tester',
41
+ description: 'Generates comprehensive unit tests',
42
+ category: 'test',
43
+ enabled: true,
44
+ },
45
+ {
46
+ id: 'debug-helper',
47
+ name: 'Debug Helper',
48
+ description: 'Helps diagnose and fix bugs',
49
+ category: 'debug',
50
+ enabled: true,
51
+ },
52
+ ];
53
+
54
+ export default uapDroids;
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * UAP Patterns Plugin for opencode
4
+ *
5
+ * Provides reusable coding patterns and distilled knowledge from tbench.
6
+ */
7
+
8
+ export interface UpatternDefinition {
9
+ id: string;
10
+ name: string;
11
+ description: string;
12
+ category: 'memory' | 'workflow' | 'architecture' | 'testing';
13
+ tags: string[];
14
+ }
15
+
16
+ export const uapPatterns: UpatternDefinition[] = [
17
+ {
18
+ id: 'generic-uap-patterns',
19
+ name: 'Generic UAP Patterns',
20
+ description: 'Distilled patterns from tbench-specific implementation',
21
+ category: 'workflow',
22
+ tags: ['memory', 'hooks', 'patterns'],
23
+ },
24
+ {
25
+ id: 'worktree-isolation',
26
+ name: 'Worktree Isolation Pattern',
27
+ description: 'Use git worktrees for isolated feature development',
28
+ category: 'workflow',
29
+ tags: ['git', 'isolation', 'parallel'],
30
+ },
31
+ {
32
+ id: 'session-persistence',
33
+ name: 'Session Persistence Pattern',
34
+ description: 'Maintain state across sessions using memory system',
35
+ category: 'memory',
36
+ tags: ['state', 'persistence', 'context'],
37
+ },
38
+ {
39
+ id: 'task-tracking',
40
+ name: 'Task Tracking Pattern',
41
+ description: 'Track and manage tasks with UAP task system',
42
+ category: 'workflow',
43
+ tags: ['tasks', 'tracking', 'management'],
44
+ },
45
+ {
46
+ id: 'agent-coordination',
47
+ name: 'Agent Coordination Pattern',
48
+ description: 'Coordinate multiple AI agents for complex tasks',
49
+ category: 'architecture',
50
+ tags: ['agents', 'coordination', 'parallel'],
51
+ },
52
+ ];
53
+
54
+ export default uapPatterns;
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * UAP Skills Plugin for opencode
4
+ *
5
+ * Defines domain-specific skills that agents can use.
6
+ */
7
+
8
+ export interface USkillDefinition {
9
+ id: string;
10
+ name: string;
11
+ description: string;
12
+ category: 'development' | 'testing' | 'deployment' | 'documentation';
13
+ triggers: string[];
14
+ enabled: boolean;
15
+ }
16
+
17
+ export const uapSkills: USkillDefinition[] = [
18
+ {
19
+ id: 'git-workflow',
20
+ name: 'Git Workflow',
21
+ description: 'Manages git workflows with worktrees and branches',
22
+ category: 'development',
23
+ triggers: ['git', 'branch', 'commit', 'push'],
24
+ enabled: true,
25
+ },
26
+ {
27
+ id: 'testing-patterns',
28
+ name: 'Testing Patterns',
29
+ description: 'Applies testing best practices and patterns',
30
+ category: 'testing',
31
+ triggers: ['test', 'spec', 'coverage'],
32
+ enabled: true,
33
+ },
34
+ {
35
+ id: 'ci-cd-setup',
36
+ name: 'CI/CD Setup',
37
+ description: 'Configures continuous integration and deployment pipelines',
38
+ category: 'deployment',
39
+ triggers: ['ci', 'cd', 'pipeline', 'workflow'],
40
+ enabled: false,
41
+ },
42
+ {
43
+ id: 'documentation-gen',
44
+ name: 'Documentation Generator',
45
+ description: 'Generates and maintains project documentation',
46
+ category: 'documentation',
47
+ triggers: ['doc', 'readme', 'comment'],
48
+ enabled: true,
49
+ },
50
+ ];
51
+
52
+ export default uapSkills;