@miller-tech/uap 1.2.0 → 1.3.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,180 @@
1
+ # OpenCode Integration Quick Reference
2
+
3
+ ## File Structure
4
+
5
+ ```
6
+ .project/
7
+ ├── .opencode/
8
+ │ ├── plugin/
9
+ │ │ ├── your-plugin.ts # Your custom plugin
10
+ │ │ └── index.ts # Optional: aggregate exports
11
+ │ └── package.json # Dependencies (add @opencode-ai/plugin)
12
+ └── opencode.json # OpenCode configuration
13
+ ```
14
+
15
+ ## Plugin Template
16
+
17
+ ```typescript
18
+ import type { Plugin } from '@opencode-ai/plugin';
19
+ import { tool } from '@opencode-ai/plugin';
20
+
21
+ export const MyPlugin: Plugin = async ({ $, directory }) => {
22
+ return {
23
+ // Define tools
24
+ tool: {
25
+ my_tool: tool({
26
+ description: 'What this tool does',
27
+ args: {
28
+ param: tool.schema.string().describe('Parameter'),
29
+ },
30
+ async execute({ param }) {
31
+ const result = await $`command ${param}`;
32
+ return result.stdout.toString();
33
+ },
34
+ }),
35
+ },
36
+
37
+ // Optional: Event hooks
38
+ event: async ({ event }) => {
39
+ if (event.type === 'session.created') {
40
+ console.log('Session started');
41
+ }
42
+ },
43
+ };
44
+ };
45
+ ```
46
+
47
+ ## Available Hooks
48
+
49
+ | Hook | Purpose | Example |
50
+ | ------------------------------------ | -------------------------- | ------------------------------ |
51
+ | `tool` | Define new tools | Custom commands for LLM |
52
+ | `event.session.created` | Session initialization | Load context, initialize state |
53
+ | `event.session.compacting` | Before context compression | Preserve important data |
54
+ | `tool.execute.before` | Before tool runs | Validate args, log activity |
55
+ | `tool.execute.after` | After tool completes | Record results, update state |
56
+ | `tool.definition` | Modify tool descriptions | Add policy constraints |
57
+ | `experimental.chat.system.transform` | Inject system context | RAG retrieval, dynamic context |
58
+ | `middleware` | Transform messages | Pre/post processing |
59
+
60
+ ## Tool Schema Types
61
+
62
+ ```typescript
63
+ // String
64
+ tool.schema.string().describe('Text parameter');
65
+
66
+ // Number with constraints
67
+ tool.schema.number().min(0).max(100).default(50);
68
+
69
+ // Enum
70
+ tool.schema.enum(['read', 'write', 'execute']).default('read');
71
+
72
+ // Array
73
+ tool.schema.array().of(tool.schema.string());
74
+
75
+ // Optional
76
+ tool.schema.string().optional();
77
+ ```
78
+
79
+ ## Common Patterns
80
+
81
+ ### 1. CLI Wrapper
82
+
83
+ ```typescript
84
+ tool({
85
+ description: 'Run external command',
86
+ args: { cmd: tool.schema.string() },
87
+ async execute({ cmd }) {
88
+ return (await $`${cmd}`.quiet()).stdout.toString();
89
+ },
90
+ });
91
+ ```
92
+
93
+ ### 2. File Operations
94
+
95
+ ```typescript
96
+ import { readFile, writeFile } from 'fs/promises';
97
+
98
+ tool({
99
+ description: 'Read project file',
100
+ args: { path: tool.schema.string() },
101
+ async execute({ path }) {
102
+ return await readFile(join(projectDir, path), 'utf-8');
103
+ },
104
+ });
105
+ ```
106
+
107
+ ### 3. Memory Query
108
+
109
+ ```typescript
110
+ tool({
111
+ description: 'Query persistent memory',
112
+ args: { query: tool.schema.string() },
113
+ async execute({ query }) {
114
+ const result = await $`python3 ./scripts/query.py "${query}"`;
115
+ return result.stdout.toString().trim();
116
+ },
117
+ });
118
+ ```
119
+
120
+ ### 4. Context Injection (RAG)
121
+
122
+ ```typescript
123
+ middleware: async (input, next) => {
124
+ const lastMsg = input.messages?.[input.messages.length - 1];
125
+ if (lastMsg?.role === 'user') {
126
+ const context = await queryRAG(lastMsg.content);
127
+ input.messages.push({ role: 'system', content: `<context>${context}</context>` });
128
+ }
129
+ return next(input);
130
+ };
131
+ ```
132
+
133
+ ## Plugin Examples in This Repo
134
+
135
+ | Plugin | File | Purpose |
136
+ | --------------- | ----------------------------------------- | ----------------------------- |
137
+ | Commands | `.opencode/plugin/uap-commands.ts` | CLI commands as tools |
138
+ | Skills | `.opencode/plugin/uap-skills.ts` | Skill loading system |
139
+ | Droids | `.opencode/plugin/uap-droids.ts` | Specialized agent droids |
140
+ | Pattern RAG | `.opencode/plugin/uap-pattern-rag.ts` | On-demand pattern retrieval |
141
+ | Task Completion | `.opencode/plugin/uap-task-completion.ts` | Track task outcomes |
142
+ | Session Hooks | `.opencode/plugin/uap-session-hooks.ts` | Session lifecycle events |
143
+ | Enforcement | `tools/agents/plugins/uap-enforce.ts` | Loop detection, budget limits |
144
+
145
+ ## Dependencies
146
+
147
+ ```json
148
+ {
149
+ "dependencies": {
150
+ "@opencode-ai/plugin": "1.2.16"
151
+ }
152
+ }
153
+ ```
154
+
155
+ ## Debugging
156
+
157
+ ```bash
158
+ # Check plugin loads
159
+ opencode run "What tools are available?"
160
+
161
+ # View logs
162
+ tail -f ~/.opencode/logs/*.log
163
+
164
+ # Test TypeScript syntax
165
+ npx tsc --noEmit .opencode/plugin/your-plugin.ts
166
+ ```
167
+
168
+ ## Best Practices
169
+
170
+ 1. **Error Handling**: Always use `.nothrow()` and check exit codes
171
+ 2. **Security**: Validate inputs, prevent command injection
172
+ 3. **Caching**: Cache expensive operations between tool calls
173
+ 4. **Descriptions**: Write clear, comprehensive tool descriptions
174
+ 5. **Naming**: Use snake_case, prefix with domain (`mydomain_tool`)
175
+ 6. **Context**: Preserve important state across compaction
176
+ 7. **Performance**: Use `--quiet` to reduce output noise
177
+
178
+ ## Full Example
179
+
180
+ See: `.opencode/plugin/uap-commands.ts` for a complete implementation example.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@miller-tech/uap",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Autonomous AI agent memory system with CLAUDE.md protocol enforcement",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",