@miller-tech/uap 1.2.0 → 1.3.1

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.1",
4
4
  "description": "Autonomous AI agent memory system with CLAUDE.md protocol enforcement",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -248,8 +248,7 @@ output+="│ ${GIT_LINE}$(printf ' %.0s' $(seq 1 $((W - 1 - ${#GIT_LINE}))))│"
248
248
  output+="├$(printf '─%.0s' $(seq 1 $W))┤"$'\n'
249
249
 
250
250
  # Active policies
251
- POLICY_LINE="Policies: [ON] IaC Pipeline [ON] kubectl Backport [ON] File Backup"
252
- output+="│ ${POLICY_LINE}$(printf ' %.0s' $(seq 1 $((W - 1 - ${#POLICY_LINE}))))│"$'\n'
251
+ output+="Policies: [ON] IaC Parity [ON] File Backup$(printf ' %.0s' $(seq 1 $((W - 47))))│"$'\n'
253
252
 
254
253
  # Memory layers
255
254
  L3_STATUS="?"
@@ -283,12 +282,6 @@ output+="### DURING WORK:"$'\n'
283
282
  output+="6. ALL file changes MUST use worktree: uap worktree create <slug>"$'\n'
284
283
  output+="7. Work in .worktrees/NNN-<slug>/ directory"$'\n'
285
284
  output+=""$'\n'
286
- output+="### IaC PIPELINE ENFORCEMENT (MANDATORY):"$'\n'
287
- output+="- NEVER run terraform plan/apply/destroy locally. ALL Terraform ops go through CI/CD pipeline."$'\n'
288
- output+="- kubectl MAY be used to diagnose, test, and verify fixes on clusters."$'\n'
289
- output+="- ANY kubectl-created resource MUST be backported to Terraform .tf files (import or delete/recreate)."$'\n'
290
- output+="- 100% IaC parity required. Infrastructure work is NOT DONE until pipeline apply succeeds + kubectl verifies."$'\n'
291
- output+=""$'\n'
292
285
  output+="### BEFORE COMMIT:"$'\n'
293
286
  output+="8. Self-review: git diff"$'\n'
294
287
  output+="9. Run tests if applicable"$'\n'