@majkapp/plugin-kit 3.7.3 → 3.7.4
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.
- package/bin/promptable-cli.js +88 -0
- package/docs/AGENTS.md +641 -0
- package/docs/AUTH.md +248 -0
- package/docs/BATCH.md +256 -0
- package/docs/CONFIG_API.md +206 -0
- package/docs/CONVERSATIONS_API.md +283 -0
- package/docs/DELEGATION.md +196 -0
- package/docs/INDEX.md +38 -0
- package/docs/KNOWLEDGE.md +225 -0
- package/docs/PLUGINS.md +356 -0
- package/docs/REPORTS.md +271 -0
- package/docs/SCRIPTING.md +231 -0
- package/docs/SECRETS.md +412 -0
- package/docs/SKILLS.md +514 -0
- package/docs/TASKS.md +622 -0
- package/docs/TOOL_DISCOVERY.md +240 -0
- package/package.json +1 -1
package/docs/REPORTS.md
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
# Reports API
|
|
2
|
+
|
|
3
|
+
Knowledge management with witness-based validation, hierarchical organization, and views.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
handler: async (input, ctx) => {
|
|
9
|
+
// Write a report
|
|
10
|
+
const result = await ctx.majk.reports.write_report({
|
|
11
|
+
path: '/research/api-analysis.md',
|
|
12
|
+
content: '# API Analysis\n\nFindings from the API review...',
|
|
13
|
+
title: 'API Analysis Report',
|
|
14
|
+
tags: ['research', 'api'],
|
|
15
|
+
witness: { file: { path: 'src/api.ts', exists: true } }
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// Read it back
|
|
19
|
+
const report = await ctx.majk.reports.read_report({ report: result.id });
|
|
20
|
+
return { reportId: result.id };
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## API Reference
|
|
25
|
+
|
|
26
|
+
### write_report(input)
|
|
27
|
+
|
|
28
|
+
Write a report to the knowledge base.
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
const result = await ctx.majk.reports.write_report({
|
|
32
|
+
content: string, // Markdown content
|
|
33
|
+
path: string, // Path like '/research/topic.md'
|
|
34
|
+
title?: string,
|
|
35
|
+
partOf?: { parent: string, placeholder?: string }, // Hierarchical relationship
|
|
36
|
+
refs?: string[], // Related report IDs
|
|
37
|
+
tags?: string[],
|
|
38
|
+
status?: string, // 'draft', 'review', 'final'
|
|
39
|
+
witness?: Witness // Validation criteria
|
|
40
|
+
});
|
|
41
|
+
// Returns: { id, path, uri, title?, hasWitness, created }
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### read_report(input)
|
|
45
|
+
|
|
46
|
+
Read a report with optional content expansion.
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
const report = await ctx.majk.reports.read_report({
|
|
50
|
+
report: string, // ID or path
|
|
51
|
+
view?: string, // View name
|
|
52
|
+
expand?: 'link' | 'inline' | 'inline-linked',
|
|
53
|
+
expandDepth?: number,
|
|
54
|
+
offset?: number, // Line offset
|
|
55
|
+
limit?: number, // Line limit
|
|
56
|
+
validate?: boolean, // Run witness validation
|
|
57
|
+
workingDirectory?: string
|
|
58
|
+
});
|
|
59
|
+
// Returns: { id, path, content, validation, ... }
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### list_reports(input?)
|
|
63
|
+
|
|
64
|
+
List and search reports.
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const { reports, total, hasMore } = await ctx.majk.reports.list_reports({
|
|
68
|
+
view?: string,
|
|
69
|
+
pathPrefix?: string, // Filter by path prefix
|
|
70
|
+
tags?: string[],
|
|
71
|
+
status?: string,
|
|
72
|
+
hasWitness?: boolean,
|
|
73
|
+
search?: string, // Text search
|
|
74
|
+
limit?: number,
|
|
75
|
+
offset?: number
|
|
76
|
+
});
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### delete_report(input)
|
|
80
|
+
|
|
81
|
+
Delete a report.
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
const { deleted } = await ctx.majk.reports.delete_report({ report: string });
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### update_report(input)
|
|
88
|
+
|
|
89
|
+
Update with line-based edits.
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
const result = await ctx.majk.reports.update_report({
|
|
93
|
+
report: string,
|
|
94
|
+
edits: [
|
|
95
|
+
{ line: 5, content: 'Updated line 5' },
|
|
96
|
+
{ lines: [10, 15], content: 'Replace lines 10-15' },
|
|
97
|
+
{ after: 20, content: 'Insert after line 20' },
|
|
98
|
+
{ line: 25, delete: true }
|
|
99
|
+
],
|
|
100
|
+
validate?: boolean
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### reorganize_reports(input)
|
|
105
|
+
|
|
106
|
+
Batch move reports.
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
const result = await ctx.majk.reports.reorganize_reports({
|
|
110
|
+
moves: [
|
|
111
|
+
{ from: '/old/path.md', to: '/new/path.md' }
|
|
112
|
+
]
|
|
113
|
+
});
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Template Workflow
|
|
117
|
+
|
|
118
|
+
### start_report(input)
|
|
119
|
+
|
|
120
|
+
Start a report from a template.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
const draft = await ctx.majk.reports.start_report({
|
|
124
|
+
template: 'research-report',
|
|
125
|
+
topic: 'API Security',
|
|
126
|
+
sections: { summary: 'Initial findings...' },
|
|
127
|
+
refs: { codebase: ['src/api.ts', 'src/auth.ts'] }
|
|
128
|
+
});
|
|
129
|
+
// Returns: { handle, preview, missing: { sections, refs } }
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### update_draft(input)
|
|
133
|
+
|
|
134
|
+
Update a draft report.
|
|
135
|
+
|
|
136
|
+
```typescript
|
|
137
|
+
const updated = await ctx.majk.reports.update_draft({
|
|
138
|
+
handle: string,
|
|
139
|
+
sections: { analysis: 'Detailed analysis...' },
|
|
140
|
+
refs: { tests: 'tests/api.test.ts' }
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### preview_draft(input)
|
|
145
|
+
|
|
146
|
+
Preview before finalizing.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
const preview = await ctx.majk.reports.preview_draft({
|
|
150
|
+
handle: string,
|
|
151
|
+
validate: true
|
|
152
|
+
});
|
|
153
|
+
// Returns: { rendered, missing, validation?, ready }
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### finalize_report(input)
|
|
157
|
+
|
|
158
|
+
Finalize and save the report.
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
const result = await ctx.majk.reports.finalize_report({
|
|
162
|
+
handle: string,
|
|
163
|
+
force?: boolean // Finalize even with validation warnings
|
|
164
|
+
});
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Views
|
|
168
|
+
|
|
169
|
+
### create_view(input)
|
|
170
|
+
|
|
171
|
+
Create an LLM-powered view.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
const view = await ctx.majk.reports.create_view({
|
|
175
|
+
name: 'Security Review',
|
|
176
|
+
philosophy: 'Organize reports by security domain and risk level',
|
|
177
|
+
categorizeExisting: true
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### list_views()
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
const { views } = await ctx.majk.reports.list_views();
|
|
185
|
+
// views: Array<{ id, name, isDefault, reportCount }>
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
### get_view_structure(input)
|
|
189
|
+
|
|
190
|
+
Get view tree structure.
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
const structure = await ctx.majk.reports.get_view_structure({ view: 'Security Review' });
|
|
194
|
+
// Returns: { viewId, viewName, tree, reportCount }
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### delete_view(input)
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const { deleted } = await ctx.majk.reports.delete_view({ view: string });
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## Import/Export
|
|
204
|
+
|
|
205
|
+
### import_document(input)
|
|
206
|
+
|
|
207
|
+
Import a file into the knowledge base.
|
|
208
|
+
|
|
209
|
+
```typescript
|
|
210
|
+
const result = await ctx.majk.reports.import_document({
|
|
211
|
+
file: '/path/to/document.md',
|
|
212
|
+
topic: 'research',
|
|
213
|
+
title: 'Imported Doc',
|
|
214
|
+
tags: ['imported'],
|
|
215
|
+
cleanup: true // Delete source after import
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### export_report(input)
|
|
220
|
+
|
|
221
|
+
Export a report to file.
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
const result = await ctx.majk.reports.export_report({
|
|
225
|
+
report: string,
|
|
226
|
+
outputPath: '/output/report.pdf',
|
|
227
|
+
format: 'markdown' | 'html' | 'pdf' | 'docx',
|
|
228
|
+
mode: 'single' | 'hierarchy' | 'inlined'
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### export_all_reports(input)
|
|
233
|
+
|
|
234
|
+
Export all reports.
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
const result = await ctx.majk.reports.export_all_reports({
|
|
238
|
+
outputDir: '/output/',
|
|
239
|
+
format: 'markdown'
|
|
240
|
+
});
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Hierarchical Reports
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
// Create master report
|
|
247
|
+
const master = await ctx.majk.reports.write_report({
|
|
248
|
+
path: '/research/security/security.md',
|
|
249
|
+
content: '# Security Analysis\n\n{{@section:auth}}\n{{@section:api}}'
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
// Create child sections
|
|
253
|
+
await ctx.majk.reports.write_report({
|
|
254
|
+
path: '/research/security/sections/01-auth.md',
|
|
255
|
+
content: '## Authentication\n...',
|
|
256
|
+
partOf: { parent: master.id, placeholder: 'auth' }
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Best Practices
|
|
261
|
+
|
|
262
|
+
1. **Use meaningful paths** - Organize reports hierarchically
|
|
263
|
+
2. **Add witnesses** - Validate reports stay accurate
|
|
264
|
+
3. **Use views** - Organize reports by perspective
|
|
265
|
+
4. **Tag consistently** - Enable filtering and discovery
|
|
266
|
+
5. **Use templates** - Ensure consistent report structure
|
|
267
|
+
|
|
268
|
+
## Next Steps
|
|
269
|
+
|
|
270
|
+
Run `npx @majkapp/plugin-kit --knowledge` - Knowledge tree API
|
|
271
|
+
Run `npx @majkapp/plugin-kit --delegation` - Task delegation
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
# Scripting API
|
|
2
|
+
|
|
3
|
+
Execute JavaScript scripts that orchestrate tool calls with tracing and dry-run support.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
handler: async (input, ctx) => {
|
|
9
|
+
const result = await ctx.majk.scripting.execute_script({
|
|
10
|
+
code: `
|
|
11
|
+
const reports = await tools.ReportsService.list_reports({ limit: 10 });
|
|
12
|
+
console.log('Found', reports.total, 'reports');
|
|
13
|
+
return { count: reports.total };
|
|
14
|
+
`,
|
|
15
|
+
dryRun: false
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return result.result;
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## API Reference
|
|
23
|
+
|
|
24
|
+
### execute_script(input)
|
|
25
|
+
|
|
26
|
+
Execute a JavaScript script.
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
const result = await ctx.majk.scripting.execute_script({
|
|
30
|
+
code?: string, // JavaScript code to execute
|
|
31
|
+
rerun?: string, // Trace ID to re-run
|
|
32
|
+
params?: Record<string, unknown>, // Parameters available as `params`
|
|
33
|
+
dryRun?: boolean, // Mock write operations
|
|
34
|
+
dryRunOptions?: {
|
|
35
|
+
maxAIMocks?: number // Limit AI mock responses
|
|
36
|
+
},
|
|
37
|
+
timeoutMs?: number // Execution timeout
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Returns:
|
|
41
|
+
{
|
|
42
|
+
success: boolean,
|
|
43
|
+
result?: any, // Script return value
|
|
44
|
+
error?: ScriptError,
|
|
45
|
+
traceId: string, // For debugging/re-running
|
|
46
|
+
traceFormatted: string, // Human-readable trace
|
|
47
|
+
trace: {
|
|
48
|
+
summary: ScriptTraceSummary,
|
|
49
|
+
events: ScriptTraceEvent[],
|
|
50
|
+
toolCalls?: ScriptToolCallRecord[]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Tool Access in Scripts
|
|
56
|
+
|
|
57
|
+
Scripts access tools via the `tools` object:
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
// Pattern: tools.ServiceName.function_name(params)
|
|
61
|
+
|
|
62
|
+
// Reports
|
|
63
|
+
const reports = await tools.ReportsService.list_reports({ pathPrefix: '/research/' });
|
|
64
|
+
await tools.ReportsService.write_report({ path: '/output.md', content: '...' });
|
|
65
|
+
|
|
66
|
+
// Delegation
|
|
67
|
+
const teammates = await tools.DelegationService.list_teammates();
|
|
68
|
+
const task = await tools.DelegationService.delegate_task({ teammate: 'dev', task: '...' });
|
|
69
|
+
|
|
70
|
+
// Batch
|
|
71
|
+
const job = await tools.BatchService.create_batch_job({ name: 'Process', ... });
|
|
72
|
+
|
|
73
|
+
// Tool Discovery
|
|
74
|
+
const tools = await tools.ToolDiscoveryService.discover_tools();
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### expand_trace(input)
|
|
78
|
+
|
|
79
|
+
Get details for a specific tool call.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
const details = await ctx.majk.scripting.expand_trace({
|
|
83
|
+
traceId: string,
|
|
84
|
+
callSeq: number // Sequence number from trace
|
|
85
|
+
});
|
|
86
|
+
// Returns: { call, fullParams, fullResult, functionSchema? }
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### list_traces()
|
|
90
|
+
|
|
91
|
+
List recent script executions.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const { traces, count } = await ctx.majk.scripting.list_traces();
|
|
95
|
+
// traces: Array<{ id, storedAt, summary: { success, totalCalls, durationMs, dryRun } }>
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### get_trace_formatted(input)
|
|
99
|
+
|
|
100
|
+
Get formatted trace output.
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
const trace = await ctx.majk.scripting.get_trace_formatted({ traceId: string });
|
|
104
|
+
// Returns: { traceFormatted, success, totalCalls, durationMs }
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Dry-Run Mode
|
|
108
|
+
|
|
109
|
+
Test scripts without making changes:
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
const result = await ctx.majk.scripting.execute_script({
|
|
113
|
+
code: `
|
|
114
|
+
// This won't actually write
|
|
115
|
+
await tools.ReportsService.write_report({
|
|
116
|
+
path: '/test.md',
|
|
117
|
+
content: 'Test content'
|
|
118
|
+
});
|
|
119
|
+
return 'done';
|
|
120
|
+
`,
|
|
121
|
+
dryRun: true
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// Trace shows what WOULD have happened
|
|
125
|
+
console.log(result.traceFormatted);
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Parameterized Scripts
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// First run
|
|
132
|
+
const result = await ctx.majk.scripting.execute_script({
|
|
133
|
+
code: `
|
|
134
|
+
const reports = await tools.ReportsService.list_reports({
|
|
135
|
+
pathPrefix: params.prefix,
|
|
136
|
+
limit: params.limit
|
|
137
|
+
});
|
|
138
|
+
return reports;
|
|
139
|
+
`,
|
|
140
|
+
params: { prefix: '/research/', limit: 5 }
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
// Re-run with different params
|
|
144
|
+
const result2 = await ctx.majk.scripting.execute_script({
|
|
145
|
+
rerun: result.traceId,
|
|
146
|
+
params: { prefix: '/docs/', limit: 10 }
|
|
147
|
+
});
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Complex Orchestration
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const result = await ctx.majk.scripting.execute_script({
|
|
154
|
+
code: `
|
|
155
|
+
// Find all TypeScript files
|
|
156
|
+
const files = await tools.FileSystem.glob({ pattern: 'src/**/*.ts' });
|
|
157
|
+
|
|
158
|
+
// Create batch job to analyze them
|
|
159
|
+
const { job } = await tools.BatchService.create_batch_job({
|
|
160
|
+
name: 'Analyze TS files',
|
|
161
|
+
input: { source: { type: 'list', items: files } },
|
|
162
|
+
processor: { type: 'rpc', functionName: 'analyze_file' },
|
|
163
|
+
autoStart: true
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// Wait for completion
|
|
167
|
+
const result = await tools.BatchService.await_batch_job({ jobId: job.id });
|
|
168
|
+
|
|
169
|
+
// Write summary report
|
|
170
|
+
await tools.ReportsService.write_report({
|
|
171
|
+
path: '/analysis/summary.md',
|
|
172
|
+
content: \`# Analysis Summary\\n\\nProcessed \${result.finalProgress.completedItems} files.\`
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return result.finalProgress;
|
|
176
|
+
`
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
## Error Handling
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const result = await ctx.majk.scripting.execute_script({
|
|
184
|
+
code: `
|
|
185
|
+
try {
|
|
186
|
+
const data = await tools.SomeService.risky_operation();
|
|
187
|
+
return { success: true, data };
|
|
188
|
+
} catch (error) {
|
|
189
|
+
console.error('Operation failed:', error.message);
|
|
190
|
+
return { success: false, error: error.message };
|
|
191
|
+
}
|
|
192
|
+
`
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
if (!result.success) {
|
|
196
|
+
console.log('Script error:', result.error);
|
|
197
|
+
console.log('Trace:', result.traceFormatted);
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Debugging with Traces
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
// Execute script
|
|
205
|
+
const result = await ctx.majk.scripting.execute_script({ code: '...' });
|
|
206
|
+
|
|
207
|
+
// View formatted trace
|
|
208
|
+
console.log(result.traceFormatted);
|
|
209
|
+
|
|
210
|
+
// Inspect specific call
|
|
211
|
+
const callDetails = await ctx.majk.scripting.expand_trace({
|
|
212
|
+
traceId: result.traceId,
|
|
213
|
+
callSeq: 3 // Third tool call
|
|
214
|
+
});
|
|
215
|
+
console.log('Params:', callDetails.fullParams);
|
|
216
|
+
console.log('Result:', callDetails.fullResult);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Best Practices
|
|
220
|
+
|
|
221
|
+
1. **Use dry-run first** - Test scripts before real execution
|
|
222
|
+
2. **Add error handling** - Wrap risky operations in try/catch
|
|
223
|
+
3. **Use parameters** - Make scripts reusable
|
|
224
|
+
4. **Check traces** - Debug issues with trace inspection
|
|
225
|
+
5. **Keep scripts focused** - One clear purpose per script
|
|
226
|
+
|
|
227
|
+
## Next Steps
|
|
228
|
+
|
|
229
|
+
Run `npx @majkapp/plugin-kit --tool-discovery` - Discover available tools
|
|
230
|
+
Run `npx @majkapp/plugin-kit --batch` - Batch processing API
|
|
231
|
+
Run `npx @majkapp/plugin-kit --delegation` - Task delegation API
|