ultra-builder-pro-cli 0.23.0 → 0.24.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.
- package/.ultra-template/docs/research/README.md +4 -4
- package/CHANGELOG.md +45 -0
- package/README.md +21 -18
- package/adapters/_shared/codex-assets.cjs +121 -65
- package/adapters/_shared/interaction-contract.cjs +7 -1
- package/adapters/_shared/provenance.cjs +7 -2
- package/adapters/_shared/runtime-assets.cjs +3 -2
- package/adapters/_shared/runtime-native.cjs +132 -0
- package/adapters/claude.js +60 -30
- package/adapters/codex.js +178 -81
- package/adapters/grok.js +372 -0
- package/adapters/kimi.js +7 -3
- package/adapters/opencode.js +210 -32
- package/agents/code-reviewer.md +4 -2
- package/agents/debugger.md +4 -1
- package/agents/review-code.md +7 -3
- package/agents/review-comments.md +7 -4
- package/agents/review-coordinator.md +11 -7
- package/agents/review-design.md +8 -4
- package/agents/review-errors.md +8 -4
- package/agents/review-spec.md +8 -5
- package/agents/review-tests.md +7 -4
- package/agents/tdd-runner.md +5 -2
- package/bin/install.js +9 -4
- package/bin/orchestrator.js +4 -13
- package/docs/AGENT-CONTEXT.md +141 -229
- package/docs/ARCHITECTURE.md +203 -494
- package/docs/ARTIFACT-AUTHORITY.md +26 -22
- package/docs/PLUGIN-ISOLATION-CONTRACT.md +12 -9
- package/docs/ROADMAP.md +85 -110
- package/docs/RUNTIME-COMPAT-MATRIX.md +139 -175
- package/docs/SKILL-AUTHORING.md +3 -3
- package/docs/STATE-DB-ACCESS-POLICY.md +13 -8
- package/docs/WORKFLOW-LIFECYCLE.md +174 -448
- package/hooks/README.md +11 -8
- package/hooks/active_task_context.py +16 -16
- package/hooks/adapters/grok.py +134 -0
- package/hooks/{context_spine.py → context_envelope.py} +26 -22
- package/hooks/health_check.py +19 -29
- package/hooks/pre_stop_check.py +22 -12
- package/hooks/subagent_tracker.py +1 -1
- package/hooks/workflow_checkpoint.py +14 -13
- package/hooks/workflow_context.py +11 -12
- package/hooks/workflow_resume.py +14 -13
- package/mcp-server/{breadcrumb.cjs → hook-context.cjs} +7 -9
- package/mcp-server/lib/baseline-workflow.cjs +36 -38
- package/mcp-server/lib/canonical-json.cjs +19 -0
- package/mcp-server/lib/change-workflow.cjs +596 -44
- package/mcp-server/lib/context-envelope.cjs +508 -0
- package/mcp-server/lib/decision-records.cjs +337 -0
- package/mcp-server/lib/doctor.cjs +91 -33
- package/mcp-server/lib/init-project.cjs +78 -39
- package/mcp-server/lib/managed-file-write.cjs +116 -0
- package/mcp-server/lib/plan-checkpoint.cjs +177 -0
- package/mcp-server/lib/project-context.cjs +178 -0
- package/mcp-server/lib/stage-checkpoints.cjs +309 -0
- package/mcp-server/lib/state-db.cjs +155 -24
- package/mcp-server/lib/task-ledger.cjs +522 -13
- package/mcp-server/lib/ultra-facade.cjs +630 -442
- package/mcp-server/lib/worker-packet.cjs +358 -0
- package/mcp-server/server.cjs +200 -1103
- package/orchestrator/daemon.cjs +27 -9
- package/orchestrator/parallel-orchestrator.cjs +111 -76
- package/orchestrator/session-runner.cjs +135 -34
- package/package.json +10 -3
- package/skills/ultra-change/SKILL.md +9 -8
- package/skills/ultra-deliver/SKILL.md +3 -3
- package/skills/ultra-dev/SKILL.md +18 -11
- package/skills/ultra-doctor/SKILL.md +2 -2
- package/skills/ultra-init/SKILL.md +6 -5
- package/skills/ultra-init/references/brownfield-adoption.md +11 -8
- package/skills/ultra-plan/SKILL.md +10 -8
- package/skills/ultra-research/SKILL.md +12 -7
- package/skills/ultra-review/SKILL.md +9 -6
- package/skills/ultra-review/references/unified-schema.md +2 -0
- package/skills/ultra-review/scripts/review_wait.py +8 -0
- package/skills/ultra-status/SKILL.md +2 -2
- package/skills/ultra-test/SKILL.md +4 -2
- package/skills/ultra-think/SKILL.md +7 -7
- package/skills/ultra-think/references/interaction-boundary.md +56 -0
- package/spec/cli-protocol.md +80 -199
- package/spec/mcp-tools.yaml +37 -2804
- package/spec/schemas/state-db.sql +107 -4
- package/spec/schemas/{task-ledger.v1.schema.json → task-ledger.v2.schema.json} +70 -6
- package/ultra-tools/commands/status.cjs +369 -243
- package/mcp-server/lib/context-spine.cjs +0 -1208
- package/mcp-server/lib/decision-dialogue.cjs +0 -1128
- package/mcp-server/lib/project-breadcrumb.cjs +0 -173
- package/mcp-server/lib/spec-learning.cjs +0 -284
- package/mcp-server/lib/workflow-state.cjs +0 -3129
- package/skills/ultra-think/references/decision-dialogue.md +0 -155
package/adapters/grok.js
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/** Build a Grok Build native Ultra Builder Pro plugin. */
|
|
4
|
+
|
|
5
|
+
const fs = require('node:fs');
|
|
6
|
+
const os = require('node:os');
|
|
7
|
+
const path = require('node:path');
|
|
8
|
+
const { spawnSync } = require('node:child_process');
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
applyNativeDoctor,
|
|
12
|
+
buildMcpRuntime,
|
|
13
|
+
mcpCommand,
|
|
14
|
+
} = require('./_shared/codex-assets.cjs');
|
|
15
|
+
const {
|
|
16
|
+
copyTree,
|
|
17
|
+
ensureDir,
|
|
18
|
+
isManaged,
|
|
19
|
+
markManaged,
|
|
20
|
+
removeTree,
|
|
21
|
+
writeAtomic,
|
|
22
|
+
} = require('./_shared/file-ops.cjs');
|
|
23
|
+
const {
|
|
24
|
+
parse: parseFrontmatter,
|
|
25
|
+
serialize: serializeFrontmatter,
|
|
26
|
+
} = require('./_shared/frontmatter.cjs');
|
|
27
|
+
const {
|
|
28
|
+
adaptInteractionGuidance,
|
|
29
|
+
} = require('./_shared/interaction-contract.cjs');
|
|
30
|
+
const provenance = require('./_shared/provenance.cjs');
|
|
31
|
+
const {
|
|
32
|
+
CORE_PUBLIC_SKILLS,
|
|
33
|
+
WORKFLOW_HOOK_FILES,
|
|
34
|
+
skillPolicy,
|
|
35
|
+
skillsForRuntime,
|
|
36
|
+
} = require('./_shared/runtime-assets.cjs');
|
|
37
|
+
|
|
38
|
+
const PLUGIN_NAME = 'ultra-builder-pro';
|
|
39
|
+
const MCP_SERVER_NAME = PLUGIN_NAME;
|
|
40
|
+
const PROVENANCE_FILE = 'provenance.json';
|
|
41
|
+
const COMMAND_NAMES = CORE_PUBLIC_SKILLS;
|
|
42
|
+
|
|
43
|
+
function resolveTarget(ctx = {}) {
|
|
44
|
+
if (ctx.configDir) return path.resolve(ctx.configDir);
|
|
45
|
+
if (ctx.scope === 'global') {
|
|
46
|
+
return path.join(ctx.homeDir || os.homedir(), '.grok');
|
|
47
|
+
}
|
|
48
|
+
return path.join(ctx.cwd || process.cwd(), '.grok');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function resolvePluginRoot(ctx = {}) {
|
|
52
|
+
return path.join(resolveTarget(ctx), 'plugins', PLUGIN_NAME);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function resolveRepoRoot(ctx = {}) {
|
|
56
|
+
return ctx.repoRoot || path.resolve(__dirname, '..');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function copySkills(repoRoot, pluginRoot) {
|
|
60
|
+
const copied = [];
|
|
61
|
+
for (const name of skillsForRuntime('grok')) {
|
|
62
|
+
const source = path.join(repoRoot, 'skills', name);
|
|
63
|
+
if (!fs.existsSync(path.join(source, 'SKILL.md'))) {
|
|
64
|
+
throw new Error(`missing allowlisted Grok skill: ${name}`);
|
|
65
|
+
}
|
|
66
|
+
const files = copyTree(source, path.join(pluginRoot, 'skills', name), {
|
|
67
|
+
transform(buffer, relative) {
|
|
68
|
+
if (!relative.endsWith('.md')) return buffer;
|
|
69
|
+
let text = adaptInteractionGuidance(buffer.toString('utf8'), 'grok');
|
|
70
|
+
if (name === 'ultra-review') {
|
|
71
|
+
text = text.replace(
|
|
72
|
+
/(?:the current host's native|the host-native) bounded-worker\s+mechanism/g,
|
|
73
|
+
'Grok Build subagents using the installed read-only agent definitions',
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
if (relative !== 'SKILL.md') return Buffer.from(text);
|
|
77
|
+
const { fm, body } = parseFrontmatter(text);
|
|
78
|
+
if (!fm) throw new Error(`missing frontmatter in Grok skill: ${name}`);
|
|
79
|
+
const policy = skillPolicy(name);
|
|
80
|
+
return Buffer.from(serializeFrontmatter({
|
|
81
|
+
name,
|
|
82
|
+
description: fm.description,
|
|
83
|
+
'user-invocable': policy.userInvocable,
|
|
84
|
+
...(policy.userInvocable ? { 'disable-model-invocation': true } : {}),
|
|
85
|
+
}, body));
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
copied.push(...files.map((relative) => path.join(name, relative)));
|
|
89
|
+
}
|
|
90
|
+
return copied;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function copyCommands(repoRoot, pluginRoot) {
|
|
94
|
+
const copied = [];
|
|
95
|
+
for (const name of COMMAND_NAMES) {
|
|
96
|
+
const source = path.join(repoRoot, 'commands', `${name}.md`);
|
|
97
|
+
if (!fs.existsSync(source)) throw new Error(`missing Grok command: ${name}.md`);
|
|
98
|
+
const target = path.join(pluginRoot, 'commands', `${name}.md`);
|
|
99
|
+
const text = adaptInteractionGuidance(fs.readFileSync(source, 'utf8'), 'grok');
|
|
100
|
+
writeAtomic(target, text);
|
|
101
|
+
copied.push(`${name}.md`);
|
|
102
|
+
}
|
|
103
|
+
return copied;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function copyAgents(repoRoot, pluginRoot) {
|
|
107
|
+
const copied = [];
|
|
108
|
+
const sourceRoot = path.join(repoRoot, 'agents');
|
|
109
|
+
for (const file of fs.readdirSync(sourceRoot).filter((name) => name.endsWith('.md')).sort()) {
|
|
110
|
+
const { fm, body } = parseFrontmatter(
|
|
111
|
+
fs.readFileSync(path.join(sourceRoot, file), 'utf8'),
|
|
112
|
+
);
|
|
113
|
+
if (!fm?.name || !fm?.description) {
|
|
114
|
+
throw new Error(`invalid Grok agent frontmatter: ${file}`);
|
|
115
|
+
}
|
|
116
|
+
const next = { ...fm };
|
|
117
|
+
delete next.model;
|
|
118
|
+
delete next.maxTurns;
|
|
119
|
+
delete next.permissionMode;
|
|
120
|
+
delete next.mcpServers;
|
|
121
|
+
delete next.hooks;
|
|
122
|
+
next.mcpInheritance = 'all';
|
|
123
|
+
const instructions = [
|
|
124
|
+
'Use the immutable Worker Packet supplied by the parent. Echo its exact packet_digest.',
|
|
125
|
+
'Do not call Ultra MCP write tools or mutate another worker artifact.',
|
|
126
|
+
'',
|
|
127
|
+
adaptInteractionGuidance(body, 'grok').trim(),
|
|
128
|
+
'',
|
|
129
|
+
].join('\n');
|
|
130
|
+
writeAtomic(
|
|
131
|
+
path.join(pluginRoot, 'agents', file),
|
|
132
|
+
serializeFrontmatter(next, instructions),
|
|
133
|
+
);
|
|
134
|
+
copied.push(file);
|
|
135
|
+
}
|
|
136
|
+
return copied;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function hookCommand(feature, ...args) {
|
|
140
|
+
return {
|
|
141
|
+
type: 'command',
|
|
142
|
+
command: [
|
|
143
|
+
'python3 "${GROK_PLUGIN_ROOT}/hooks/adapters/grok.py"',
|
|
144
|
+
JSON.stringify(feature),
|
|
145
|
+
...args.map((arg) => JSON.stringify(arg)),
|
|
146
|
+
].join(' '),
|
|
147
|
+
timeout: 10,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function buildHooksManifest() {
|
|
152
|
+
return {
|
|
153
|
+
description: [
|
|
154
|
+
'Ultra hooks are observational except for exact managed-file protection.',
|
|
155
|
+
'Grok ignores SessionStart/PostCompact stdout, so Skills read ultra.context explicitly.',
|
|
156
|
+
].join(' '),
|
|
157
|
+
hooks: {
|
|
158
|
+
SessionStart: [{
|
|
159
|
+
matcher: 'startup|resume|clear|compact',
|
|
160
|
+
hooks: [hookCommand('health_check.py')],
|
|
161
|
+
}],
|
|
162
|
+
PreToolUse: [{
|
|
163
|
+
matcher: 'Edit|Write|MultiEdit|search_replace|apply_patch',
|
|
164
|
+
hooks: [hookCommand('active_task_context.py')],
|
|
165
|
+
}],
|
|
166
|
+
PreCompact: [{
|
|
167
|
+
matcher: 'manual|auto',
|
|
168
|
+
hooks: [hookCommand('workflow_checkpoint.py')],
|
|
169
|
+
}],
|
|
170
|
+
Stop: [{
|
|
171
|
+
hooks: [hookCommand('pre_stop_check.py')],
|
|
172
|
+
}],
|
|
173
|
+
SubagentStart: [{
|
|
174
|
+
hooks: [hookCommand('subagent_tracker.py', 'start')],
|
|
175
|
+
}],
|
|
176
|
+
SubagentStop: [{
|
|
177
|
+
hooks: [hookCommand('subagent_tracker.py', 'stop')],
|
|
178
|
+
}],
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function copyHooks(repoRoot, pluginRoot) {
|
|
184
|
+
const copied = [];
|
|
185
|
+
ensureDir(path.join(pluginRoot, 'hooks', 'adapters'));
|
|
186
|
+
for (const name of WORKFLOW_HOOK_FILES) {
|
|
187
|
+
const source = path.join(repoRoot, 'hooks', name);
|
|
188
|
+
if (!fs.existsSync(source)) throw new Error(`missing allowlisted Grok hook: ${name}`);
|
|
189
|
+
fs.copyFileSync(source, path.join(pluginRoot, 'hooks', name));
|
|
190
|
+
copied.push(name);
|
|
191
|
+
}
|
|
192
|
+
fs.copyFileSync(
|
|
193
|
+
path.join(repoRoot, 'hooks', 'adapters', 'grok.py'),
|
|
194
|
+
path.join(pluginRoot, 'hooks', 'adapters', 'grok.py'),
|
|
195
|
+
);
|
|
196
|
+
copied.push(path.join('adapters', 'grok.py'));
|
|
197
|
+
writeAtomic(
|
|
198
|
+
path.join(pluginRoot, 'hooks', 'hooks.json'),
|
|
199
|
+
`${JSON.stringify(buildHooksManifest(), null, 2)}\n`,
|
|
200
|
+
);
|
|
201
|
+
return copied;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function writeManifests(repoRoot, pluginRoot, runtime) {
|
|
205
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(repoRoot, 'package.json'), 'utf8'));
|
|
206
|
+
const repository = typeof pkg.repository === 'string'
|
|
207
|
+
? pkg.repository.replace(/^git\+/, '').replace(/\.git$/, '')
|
|
208
|
+
: String(pkg.repository?.url || '').replace(/^git\+/, '').replace(/\.git$/, '');
|
|
209
|
+
writeAtomic(path.join(pluginRoot, 'plugin.json'), `${JSON.stringify({
|
|
210
|
+
name: PLUGIN_NAME,
|
|
211
|
+
version: pkg.version,
|
|
212
|
+
description: 'Grok Build native Ultra workflows, Worker Packets, observational hooks, and a project-local MCP safety kernel.',
|
|
213
|
+
author: { name: typeof pkg.author === 'string' ? pkg.author : 'Ultra Builder Pro contributors' },
|
|
214
|
+
homepage: pkg.homepage,
|
|
215
|
+
repository,
|
|
216
|
+
license: pkg.license || 'MIT',
|
|
217
|
+
}, null, 2)}\n`);
|
|
218
|
+
const command = mcpCommand(runtime.launcher);
|
|
219
|
+
writeAtomic(path.join(pluginRoot, '.mcp.json'), `${JSON.stringify({
|
|
220
|
+
mcpServers: {
|
|
221
|
+
[MCP_SERVER_NAME]: {
|
|
222
|
+
type: 'stdio',
|
|
223
|
+
command: command.command,
|
|
224
|
+
args: command.args,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
}, null, 2)}\n`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function validatePlugin(pluginRoot, ctx = {}) {
|
|
231
|
+
const binary = ctx.grokBin || path.join(
|
|
232
|
+
ctx.homeDir || os.homedir(),
|
|
233
|
+
'.grok',
|
|
234
|
+
'bin',
|
|
235
|
+
process.platform === 'win32' ? 'grok.exe' : 'grok',
|
|
236
|
+
);
|
|
237
|
+
if (!fs.existsSync(binary)) return { status: 'unavailable', binary };
|
|
238
|
+
const result = spawnSync(binary, ['plugin', 'validate', pluginRoot], {
|
|
239
|
+
encoding: 'utf8',
|
|
240
|
+
timeout: 30_000,
|
|
241
|
+
});
|
|
242
|
+
if (result.error) throw result.error;
|
|
243
|
+
if (result.status !== 0) {
|
|
244
|
+
throw new Error(
|
|
245
|
+
`grok plugin validate failed: ${(result.stderr || result.stdout || '').trim()}`,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
return { status: 'pass', binary, output: (result.stdout || '').trim() };
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function buildStaging(repoRoot, staging, ctx) {
|
|
252
|
+
const copied = {
|
|
253
|
+
commands: copyCommands(repoRoot, staging),
|
|
254
|
+
skills: copySkills(repoRoot, staging),
|
|
255
|
+
agents: copyAgents(repoRoot, staging),
|
|
256
|
+
hooks: copyHooks(repoRoot, staging),
|
|
257
|
+
};
|
|
258
|
+
const runtime = buildMcpRuntime(repoRoot, staging, { runtime: 'grok' });
|
|
259
|
+
writeManifests(repoRoot, staging, runtime);
|
|
260
|
+
if (fs.existsSync(path.join(repoRoot, 'LICENSE'))) {
|
|
261
|
+
fs.copyFileSync(path.join(repoRoot, 'LICENSE'), path.join(staging, 'LICENSE'));
|
|
262
|
+
}
|
|
263
|
+
markManaged(staging, { adapter: 'grok', plugin: PLUGIN_NAME });
|
|
264
|
+
const validation = validatePlugin(staging, ctx);
|
|
265
|
+
return { copied, validation };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function writeProvenance(repoRoot, pluginRoot) {
|
|
269
|
+
const source = provenance.packageSource(repoRoot);
|
|
270
|
+
const file = path.join(pluginRoot, PROVENANCE_FILE);
|
|
271
|
+
const manifest = provenance.writeProvenance({
|
|
272
|
+
file,
|
|
273
|
+
adapter: 'grok',
|
|
274
|
+
...source,
|
|
275
|
+
roots: { plugin: pluginRoot },
|
|
276
|
+
assets: provenance.assetRefsForTree('plugin', pluginRoot, {
|
|
277
|
+
exclude: ['.ubp-managed', PROVENANCE_FILE],
|
|
278
|
+
}),
|
|
279
|
+
contracts: {
|
|
280
|
+
plugin_manifest: { root: 'plugin', path: 'plugin.json' },
|
|
281
|
+
mcp_registration: { root: 'plugin', path: '.mcp.json' },
|
|
282
|
+
mcp_launcher: { root: 'plugin', path: 'runtime/launch.cjs' },
|
|
283
|
+
native_runtime: { root: 'plugin', path: 'runtime/native-runtime.json' },
|
|
284
|
+
context_envelope_helper: { root: 'plugin', path: 'runtime/hook-context.cjs' },
|
|
285
|
+
hooks_manifest: { root: 'plugin', path: 'hooks/hooks.json' },
|
|
286
|
+
hook_adapter: { root: 'plugin', path: path.join('hooks', 'adapters', 'grok.py') },
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
return { file, manifest };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function install(ctx = {}) {
|
|
293
|
+
const target = resolvePluginRoot(ctx);
|
|
294
|
+
const repoRoot = resolveRepoRoot(ctx);
|
|
295
|
+
if (fs.existsSync(target) && !isManaged(target)) {
|
|
296
|
+
throw new Error(`refusing to replace unmanaged Grok plugin: ${target}`);
|
|
297
|
+
}
|
|
298
|
+
ensureDir(path.dirname(target));
|
|
299
|
+
const staging = fs.mkdtempSync(path.join(path.dirname(target), `${PLUGIN_NAME}-staging-`));
|
|
300
|
+
const backup = `${staging}-previous`;
|
|
301
|
+
let movedPrevious = false;
|
|
302
|
+
let published = false;
|
|
303
|
+
try {
|
|
304
|
+
const built = buildStaging(repoRoot, staging, ctx);
|
|
305
|
+
if (fs.existsSync(target)) {
|
|
306
|
+
fs.renameSync(target, backup);
|
|
307
|
+
movedPrevious = true;
|
|
308
|
+
}
|
|
309
|
+
fs.renameSync(staging, target);
|
|
310
|
+
published = true;
|
|
311
|
+
writeManifests(repoRoot, target, {
|
|
312
|
+
launcher: path.join(target, 'runtime', 'launch.cjs'),
|
|
313
|
+
});
|
|
314
|
+
const provenanceReport = writeProvenance(repoRoot, target);
|
|
315
|
+
if (movedPrevious) removeTree(backup);
|
|
316
|
+
return {
|
|
317
|
+
target,
|
|
318
|
+
...built,
|
|
319
|
+
provenance: provenanceReport,
|
|
320
|
+
trusted: ctx.scope === 'global',
|
|
321
|
+
reload_required: true,
|
|
322
|
+
};
|
|
323
|
+
} catch (error) {
|
|
324
|
+
if (published && fs.existsSync(target)) removeTree(target);
|
|
325
|
+
else if (fs.existsSync(staging)) removeTree(staging);
|
|
326
|
+
if (movedPrevious && fs.existsSync(backup)) fs.renameSync(backup, target);
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function doctor(ctx = {}) {
|
|
332
|
+
const target = resolvePluginRoot(ctx);
|
|
333
|
+
const source = provenance.packageSource(resolveRepoRoot(ctx));
|
|
334
|
+
const report = provenance.inspectProvenance({
|
|
335
|
+
file: path.join(target, PROVENANCE_FILE),
|
|
336
|
+
expectedAdapter: 'grok',
|
|
337
|
+
expectedPackageVersion: source.packageInfo.version,
|
|
338
|
+
});
|
|
339
|
+
try {
|
|
340
|
+
const validation = validatePlugin(target, ctx);
|
|
341
|
+
report.checks.plugin_validation = validation;
|
|
342
|
+
} catch (error) {
|
|
343
|
+
report.checks.plugin_validation = { status: 'fail' };
|
|
344
|
+
report.issues.push({ code: 'PLUGIN_MANIFEST_INVALID', message: error.message });
|
|
345
|
+
}
|
|
346
|
+
return applyNativeDoctor(report, path.join(target, 'runtime'));
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function uninstall(ctx = {}) {
|
|
350
|
+
const target = resolvePluginRoot(ctx);
|
|
351
|
+
const report = { target, removed: {} };
|
|
352
|
+
if (fs.existsSync(target)) {
|
|
353
|
+
if (!isManaged(target)) {
|
|
354
|
+
throw new Error(`refusing to remove unmanaged Grok plugin: ${target}`);
|
|
355
|
+
}
|
|
356
|
+
removeTree(target);
|
|
357
|
+
report.removed.plugin = true;
|
|
358
|
+
}
|
|
359
|
+
return report;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
module.exports = {
|
|
363
|
+
name: 'grok',
|
|
364
|
+
PLUGIN_NAME,
|
|
365
|
+
MCP_SERVER_NAME,
|
|
366
|
+
buildHooksManifest,
|
|
367
|
+
resolveTarget,
|
|
368
|
+
resolvePluginRoot,
|
|
369
|
+
install,
|
|
370
|
+
doctor,
|
|
371
|
+
uninstall,
|
|
372
|
+
};
|
package/adapters/kimi.js
CHANGED
|
@@ -14,7 +14,10 @@ const {
|
|
|
14
14
|
removeTree,
|
|
15
15
|
writeAtomic,
|
|
16
16
|
} = require('./_shared/file-ops.cjs');
|
|
17
|
-
const {
|
|
17
|
+
const {
|
|
18
|
+
applyNativeDoctor,
|
|
19
|
+
buildMcpRuntime,
|
|
20
|
+
} = require('./_shared/codex-assets.cjs');
|
|
18
21
|
const { parse: parseFm, serialize: serializeFm } = require('./_shared/frontmatter.cjs');
|
|
19
22
|
const { adaptInteractionGuidance } = require('./_shared/interaction-contract.cjs');
|
|
20
23
|
const provenance = require('./_shared/provenance.cjs');
|
|
@@ -321,6 +324,8 @@ function writePluginProvenance(repoRoot, target) {
|
|
|
321
324
|
contracts: {
|
|
322
325
|
plugin_manifest: { root: 'plugin', path: 'kimi.plugin.json' },
|
|
323
326
|
mcp_launcher: { root: 'plugin', path: path.join('runtime', 'launch.cjs') },
|
|
327
|
+
native_runtime: { root: 'plugin', path: path.join('runtime', 'native-runtime.json') },
|
|
328
|
+
context_envelope_helper: { root: 'plugin', path: path.join('runtime', 'hook-context.cjs') },
|
|
324
329
|
hook_event_helper: { root: 'plugin', path: path.join('runtime', 'hook-event.cjs') },
|
|
325
330
|
hook_adapter: { root: 'plugin', path: path.join('hooks', 'adapters', 'kimi.py') },
|
|
326
331
|
},
|
|
@@ -442,8 +447,7 @@ function doctor(ctx = {}) {
|
|
|
442
447
|
report.checks.plugin_manifest = { status: manifestOk ? 'pass' : 'fail' };
|
|
443
448
|
report.checks.mcp_registration = { status: mcpOk ? 'pass' : 'fail' };
|
|
444
449
|
report.checks.hook_registration = { status: hooksOk ? 'pass' : 'fail' };
|
|
445
|
-
|
|
446
|
-
return report;
|
|
450
|
+
return applyNativeDoctor(report, path.join(target, 'runtime'));
|
|
447
451
|
}
|
|
448
452
|
|
|
449
453
|
function uninstall(ctx = {}) {
|