@contractspec/lib.ai-agent 1.57.0 → 1.59.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/dist/agent/agent-factory.d.ts +67 -71
- package/dist/agent/agent-factory.d.ts.map +1 -1
- package/dist/agent/agent-factory.js +658 -100
- package/dist/agent/agent.test.d.ts +2 -0
- package/dist/agent/agent.test.d.ts.map +1 -0
- package/dist/agent/contract-spec-agent.d.ts +48 -52
- package/dist/agent/contract-spec-agent.d.ts.map +1 -1
- package/dist/agent/contract-spec-agent.js +605 -146
- package/dist/agent/index.d.ts +4 -4
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +2102 -4
- package/dist/agent/json-runner.d.ts +15 -19
- package/dist/agent/json-runner.d.ts.map +1 -1
- package/dist/agent/json-runner.js +672 -57
- package/dist/agent/json-runner.test.d.ts +2 -0
- package/dist/agent/json-runner.test.d.ts.map +1 -0
- package/dist/agent/unified-agent.d.ts +132 -109
- package/dist/agent/unified-agent.d.ts.map +1 -1
- package/dist/agent/unified-agent.js +2011 -293
- package/dist/approval/index.d.ts +3 -2
- package/dist/approval/index.d.ts.map +1 -0
- package/dist/approval/index.js +128 -2
- package/dist/approval/workflow.d.ts +106 -110
- package/dist/approval/workflow.d.ts.map +1 -1
- package/dist/approval/workflow.js +126 -157
- package/dist/exporters/claude-agent-exporter.d.ts +50 -48
- package/dist/exporters/claude-agent-exporter.d.ts.map +1 -1
- package/dist/exporters/claude-agent-exporter.js +258 -203
- package/dist/exporters/index.d.ts +28 -4
- package/dist/exporters/index.d.ts.map +1 -0
- package/dist/exporters/index.js +737 -3
- package/dist/exporters/opencode-exporter.d.ts +47 -45
- package/dist/exporters/opencode-exporter.d.ts.map +1 -1
- package/dist/exporters/opencode-exporter.js +507 -191
- package/dist/exporters/types.d.ts +171 -169
- package/dist/exporters/types.d.ts.map +1 -1
- package/dist/exporters/types.js +1 -0
- package/dist/index.d.ts +15 -39
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3337 -32
- package/dist/interop/index.d.ts +48 -4
- package/dist/interop/index.d.ts.map +1 -0
- package/dist/interop/index.js +709 -3
- package/dist/interop/spec-consumer.d.ts +57 -53
- package/dist/interop/spec-consumer.d.ts.map +1 -1
- package/dist/interop/spec-consumer.js +302 -282
- package/dist/interop/tool-consumer.d.ts +57 -53
- package/dist/interop/tool-consumer.d.ts.map +1 -1
- package/dist/interop/tool-consumer.js +412 -213
- package/dist/interop/types.d.ts +173 -171
- package/dist/interop/types.d.ts.map +1 -1
- package/dist/interop/types.js +1 -0
- package/dist/knowledge/index.d.ts +2 -2
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +66 -2
- package/dist/knowledge/injector.d.ts +16 -20
- package/dist/knowledge/injector.d.ts.map +1 -1
- package/dist/knowledge/injector.js +56 -47
- package/dist/memory/in-memory.d.ts +15 -19
- package/dist/memory/in-memory.d.ts.map +1 -1
- package/dist/memory/in-memory.js +152 -46
- package/dist/memory/index.d.ts +3 -3
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +155 -3
- package/dist/memory/manager.d.ts +32 -36
- package/dist/memory/manager.d.ts.map +1 -1
- package/dist/memory/manager.js +96 -70
- package/dist/memory/memory.test.d.ts +2 -0
- package/dist/memory/memory.test.d.ts.map +1 -0
- package/dist/node/agent/agent-factory.js +661 -0
- package/dist/node/agent/contract-spec-agent.js +607 -0
- package/dist/node/agent/index.js +2103 -0
- package/dist/node/agent/json-runner.js +684 -0
- package/dist/node/agent/unified-agent.js +2019 -0
- package/dist/node/approval/index.js +129 -0
- package/dist/node/approval/workflow.js +129 -0
- package/dist/node/exporters/claude-agent-exporter.js +265 -0
- package/dist/node/exporters/index.js +738 -0
- package/dist/node/exporters/opencode-exporter.js +516 -0
- package/dist/node/exporters/types.js +0 -0
- package/dist/node/index.js +3337 -0
- package/dist/node/interop/index.js +710 -0
- package/dist/node/interop/spec-consumer.js +307 -0
- package/dist/node/interop/tool-consumer.js +419 -0
- package/dist/node/interop/types.js +0 -0
- package/dist/node/knowledge/index.js +67 -0
- package/dist/node/knowledge/injector.js +67 -0
- package/dist/node/memory/in-memory.js +154 -0
- package/dist/node/memory/index.js +156 -0
- package/dist/node/memory/manager.js +105 -0
- package/dist/node/providers/claude-agent-sdk/adapter.js +624 -0
- package/dist/node/providers/claude-agent-sdk/index.js +673 -0
- package/dist/node/providers/claude-agent-sdk/session-bridge.js +149 -0
- package/dist/node/providers/claude-agent-sdk/tool-bridge.js +118 -0
- package/dist/node/providers/index.js +1261 -0
- package/dist/node/providers/opencode-sdk/adapter.js +669 -0
- package/dist/node/providers/opencode-sdk/agent-bridge.js +299 -0
- package/dist/node/providers/opencode-sdk/index.js +703 -0
- package/dist/node/providers/opencode-sdk/tool-bridge.js +141 -0
- package/dist/node/providers/registry.js +89 -0
- package/dist/node/providers/types.js +56 -0
- package/dist/node/schema/index.js +195 -0
- package/dist/node/schema/json-schema-to-zod.js +152 -0
- package/dist/node/schema/schema-output.js +190 -0
- package/dist/node/session/index.js +90 -0
- package/dist/node/session/store.js +90 -0
- package/dist/node/spec/index.js +85 -0
- package/dist/node/spec/registry.js +56 -0
- package/dist/node/spec/spec.js +44 -0
- package/dist/node/telemetry/adapter.js +85 -0
- package/dist/node/telemetry/index.js +86 -0
- package/dist/node/tools/index.js +345 -0
- package/dist/node/tools/knowledge-tool.js +74 -0
- package/dist/node/tools/mcp-client.js +47 -0
- package/dist/node/tools/mcp-server.js +205 -0
- package/dist/node/tools/tool-adapter.js +197 -0
- package/dist/node/types.js +0 -0
- package/dist/providers/claude-agent-sdk/adapter.d.ts +60 -52
- package/dist/providers/claude-agent-sdk/adapter.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/adapter.js +622 -304
- package/dist/providers/claude-agent-sdk/index.d.ts +22 -4
- package/dist/providers/claude-agent-sdk/index.d.ts.map +1 -0
- package/dist/providers/claude-agent-sdk/index.js +672 -4
- package/dist/providers/claude-agent-sdk/session-bridge.d.ts +43 -40
- package/dist/providers/claude-agent-sdk/session-bridge.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/session-bridge.js +121 -130
- package/dist/providers/claude-agent-sdk/tool-bridge.d.ts +63 -60
- package/dist/providers/claude-agent-sdk/tool-bridge.d.ts.map +1 -1
- package/dist/providers/claude-agent-sdk/tool-bridge.js +104 -108
- package/dist/providers/index.d.ts +28 -7
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +1261 -8
- package/dist/providers/opencode-sdk/adapter.d.ts +56 -48
- package/dist/providers/opencode-sdk/adapter.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/adapter.js +667 -274
- package/dist/providers/opencode-sdk/agent-bridge.d.ts +62 -57
- package/dist/providers/opencode-sdk/agent-bridge.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/agent-bridge.js +289 -155
- package/dist/providers/opencode-sdk/index.d.ts +22 -4
- package/dist/providers/opencode-sdk/index.d.ts.map +1 -0
- package/dist/providers/opencode-sdk/index.js +702 -4
- package/dist/providers/opencode-sdk/tool-bridge.d.ts +41 -42
- package/dist/providers/opencode-sdk/tool-bridge.d.ts.map +1 -1
- package/dist/providers/opencode-sdk/tool-bridge.js +121 -107
- package/dist/providers/registry.d.ts +10 -11
- package/dist/providers/registry.d.ts.map +1 -1
- package/dist/providers/registry.js +86 -49
- package/dist/providers/types.d.ts +169 -166
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +54 -42
- package/dist/schema/index.d.ts +3 -3
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +194 -3
- package/dist/schema/json-schema-to-zod.d.ts +23 -26
- package/dist/schema/json-schema-to-zod.d.ts.map +1 -1
- package/dist/schema/json-schema-to-zod.js +138 -110
- package/dist/schema/schema-output.d.ts +29 -32
- package/dist/schema/schema-output.d.ts.map +1 -1
- package/dist/schema/schema-output.js +178 -53
- package/dist/session/index.d.ts +2 -2
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +89 -2
- package/dist/session/store.d.ts +51 -55
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +85 -74
- package/dist/spec/index.d.ts +3 -3
- package/dist/spec/index.d.ts.map +1 -0
- package/dist/spec/index.js +84 -3
- package/dist/spec/registry.d.ts +32 -36
- package/dist/spec/registry.d.ts.map +1 -1
- package/dist/spec/registry.js +51 -60
- package/dist/spec/spec.d.ts +80 -84
- package/dist/spec/spec.d.ts.map +1 -1
- package/dist/spec/spec.js +40 -26
- package/dist/telemetry/adapter.d.ts +33 -37
- package/dist/telemetry/adapter.d.ts.map +1 -1
- package/dist/telemetry/adapter.js +78 -96
- package/dist/telemetry/index.d.ts +2 -2
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +85 -2
- package/dist/tools/index.d.ts +5 -5
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +344 -5
- package/dist/tools/knowledge-tool.d.ts +4 -8
- package/dist/tools/knowledge-tool.d.ts.map +1 -1
- package/dist/tools/knowledge-tool.js +68 -48
- package/dist/tools/mcp-client.d.ts +17 -21
- package/dist/tools/mcp-client.d.ts.map +1 -1
- package/dist/tools/mcp-client.js +42 -53
- package/dist/tools/mcp-server.d.ts +14 -18
- package/dist/tools/mcp-server.d.ts.map +1 -1
- package/dist/tools/mcp-server.js +200 -64
- package/dist/tools/tool-adapter.d.ts +7 -11
- package/dist/tools/tool-adapter.d.ts.map +1 -1
- package/dist/tools/tool-adapter.js +187 -70
- package/dist/tools/tools.test.d.ts +2 -0
- package/dist/tools/tools.test.d.ts.map +1 -0
- package/dist/types.d.ts +108 -111
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -0
- package/package.json +448 -90
- package/dist/_virtual/_rolldown/runtime.js +0 -8
- package/dist/agent/agent-factory.js.map +0 -1
- package/dist/agent/contract-spec-agent.js.map +0 -1
- package/dist/agent/json-runner.js.map +0 -1
- package/dist/agent/unified-agent.js.map +0 -1
- package/dist/approval/workflow.js.map +0 -1
- package/dist/exporters/claude-agent-exporter.js.map +0 -1
- package/dist/exporters/opencode-exporter.js.map +0 -1
- package/dist/interop/spec-consumer.js.map +0 -1
- package/dist/interop/tool-consumer.js.map +0 -1
- package/dist/knowledge/injector.js.map +0 -1
- package/dist/memory/in-memory.js.map +0 -1
- package/dist/memory/manager.js.map +0 -1
- package/dist/providers/claude-agent-sdk/adapter.js.map +0 -1
- package/dist/providers/claude-agent-sdk/session-bridge.js.map +0 -1
- package/dist/providers/claude-agent-sdk/tool-bridge.js.map +0 -1
- package/dist/providers/opencode-sdk/adapter.js.map +0 -1
- package/dist/providers/opencode-sdk/agent-bridge.js.map +0 -1
- package/dist/providers/opencode-sdk/tool-bridge.js.map +0 -1
- package/dist/providers/registry.js.map +0 -1
- package/dist/providers/types.js.map +0 -1
- package/dist/schema/json-schema-to-zod.js.map +0 -1
- package/dist/schema/schema-output.js.map +0 -1
- package/dist/session/store.js.map +0 -1
- package/dist/spec/registry.js.map +0 -1
- package/dist/spec/spec.js.map +0 -1
- package/dist/telemetry/adapter.js.map +0 -1
- package/dist/tools/knowledge-tool.js.map +0 -1
- package/dist/tools/mcp-client.js.map +0 -1
- package/dist/tools/mcp-server.js.map +0 -1
- package/dist/tools/tool-adapter.js.map +0 -1
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, {
|
|
6
|
+
get: all[name],
|
|
7
|
+
enumerable: true,
|
|
8
|
+
configurable: true,
|
|
9
|
+
set: (newValue) => all[name] = () => newValue
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
13
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
14
|
+
|
|
15
|
+
// src/spec/spec.ts
|
|
16
|
+
function defineAgent(spec) {
|
|
17
|
+
if (!spec.meta?.key) {
|
|
18
|
+
throw new Error("Agent key is required");
|
|
19
|
+
}
|
|
20
|
+
if (typeof spec.meta.version !== "string") {
|
|
21
|
+
throw new Error(`Agent ${spec.meta.key} is missing a string version`);
|
|
22
|
+
}
|
|
23
|
+
if (!spec.instructions?.trim()) {
|
|
24
|
+
throw new Error(`Agent ${spec.meta.key} requires instructions`);
|
|
25
|
+
}
|
|
26
|
+
if (!spec.tools?.length) {
|
|
27
|
+
throw new Error(`Agent ${spec.meta.key} must expose at least one tool`);
|
|
28
|
+
}
|
|
29
|
+
const toolNames = new Set;
|
|
30
|
+
for (const tool of spec.tools) {
|
|
31
|
+
if (toolNames.has(tool.name)) {
|
|
32
|
+
throw new Error(`Agent ${spec.meta.key} has duplicate tool name: ${tool.name}`);
|
|
33
|
+
}
|
|
34
|
+
toolNames.add(tool.name);
|
|
35
|
+
}
|
|
36
|
+
return Object.freeze(spec);
|
|
37
|
+
}
|
|
38
|
+
function agentKey(meta) {
|
|
39
|
+
return `${meta.key}.v${meta.version}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/providers/opencode-sdk/tool-bridge.ts
|
|
43
|
+
function specToolToOpenCodeTool(tool) {
|
|
44
|
+
return {
|
|
45
|
+
name: tool.name,
|
|
46
|
+
description: tool.description ?? `Execute ${tool.name}`,
|
|
47
|
+
parameters: normalizeToOpenCodeParameters(tool.schema),
|
|
48
|
+
permission: getPermissionLevel(tool)
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function specToolsToOpenCodeTools(tools) {
|
|
52
|
+
return tools.map(specToolToOpenCodeTool);
|
|
53
|
+
}
|
|
54
|
+
function getPermissionLevel(tool) {
|
|
55
|
+
if (tool.requiresApproval) {
|
|
56
|
+
return "ask";
|
|
57
|
+
}
|
|
58
|
+
if (tool.automationSafe === false) {
|
|
59
|
+
return "ask";
|
|
60
|
+
}
|
|
61
|
+
return "allow";
|
|
62
|
+
}
|
|
63
|
+
function openCodeToolToSpecTool(openCodeTool) {
|
|
64
|
+
return {
|
|
65
|
+
name: openCodeTool.name,
|
|
66
|
+
description: openCodeTool.description,
|
|
67
|
+
schema: openCodeTool.parameters,
|
|
68
|
+
requiresApproval: openCodeTool.permission === "ask",
|
|
69
|
+
automationSafe: openCodeTool.permission === "allow"
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function openCodeToolsToSpecTools(openCodeTools) {
|
|
73
|
+
return openCodeTools.map(openCodeToolToSpecTool);
|
|
74
|
+
}
|
|
75
|
+
function specToolToExternalToolForOpenCode(tool, handler, context) {
|
|
76
|
+
return {
|
|
77
|
+
name: tool.name,
|
|
78
|
+
description: tool.description ?? `Execute ${tool.name}`,
|
|
79
|
+
inputSchema: tool.schema ?? { type: "object" },
|
|
80
|
+
requiresApproval: tool.requiresApproval ?? !tool.automationSafe,
|
|
81
|
+
execute: handler ? async (input) => {
|
|
82
|
+
const fullContext = {
|
|
83
|
+
agentId: context?.agentId ?? "unknown",
|
|
84
|
+
sessionId: context?.sessionId ?? "unknown",
|
|
85
|
+
tenantId: context?.tenantId,
|
|
86
|
+
actorId: context?.actorId,
|
|
87
|
+
metadata: context?.metadata,
|
|
88
|
+
signal: context?.signal
|
|
89
|
+
};
|
|
90
|
+
return handler(input, fullContext);
|
|
91
|
+
} : undefined
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function normalizeToOpenCodeParameters(schema) {
|
|
95
|
+
if (!schema) {
|
|
96
|
+
return { type: "object" };
|
|
97
|
+
}
|
|
98
|
+
if (schema.type === "object") {
|
|
99
|
+
return {
|
|
100
|
+
type: "object",
|
|
101
|
+
properties: schema.properties,
|
|
102
|
+
required: schema.required
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
type: "object",
|
|
107
|
+
properties: {
|
|
108
|
+
value: convertToOpenCodeParameter(schema)
|
|
109
|
+
},
|
|
110
|
+
required: ["value"]
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function convertToOpenCodeParameter(schema) {
|
|
114
|
+
const param = {
|
|
115
|
+
type: schema.type ?? "string"
|
|
116
|
+
};
|
|
117
|
+
if (schema.description) {
|
|
118
|
+
param.description = schema.description;
|
|
119
|
+
}
|
|
120
|
+
if (schema.enum) {
|
|
121
|
+
param.enum = schema.enum;
|
|
122
|
+
}
|
|
123
|
+
if (schema.default !== undefined) {
|
|
124
|
+
param.default = schema.default;
|
|
125
|
+
}
|
|
126
|
+
return param;
|
|
127
|
+
}
|
|
128
|
+
function createToolHandlerMap(tools) {
|
|
129
|
+
const handlers = new Map;
|
|
130
|
+
for (const [name, tool] of Object.entries(tools)) {
|
|
131
|
+
if (tool.execute) {
|
|
132
|
+
handlers.set(name, tool.execute);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return handlers;
|
|
136
|
+
}
|
|
137
|
+
async function executeToolCall(toolCall, handlers) {
|
|
138
|
+
const handler = handlers.get(toolCall.name);
|
|
139
|
+
if (!handler) {
|
|
140
|
+
return {
|
|
141
|
+
tool_call_id: toolCall.id,
|
|
142
|
+
output: `Error: Tool '${toolCall.name}' not found`,
|
|
143
|
+
is_error: true
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const result = await handler(toolCall.arguments);
|
|
148
|
+
return {
|
|
149
|
+
tool_call_id: toolCall.id,
|
|
150
|
+
output: typeof result === "string" ? result : JSON.stringify(result)
|
|
151
|
+
};
|
|
152
|
+
} catch (error) {
|
|
153
|
+
return {
|
|
154
|
+
tool_call_id: toolCall.id,
|
|
155
|
+
output: `Error: ${error instanceof Error ? error.message : String(error)}`,
|
|
156
|
+
is_error: true
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/providers/opencode-sdk/agent-bridge.ts
|
|
162
|
+
function inferAgentType(spec) {
|
|
163
|
+
const hasCodeTools = spec.tools.some((tool) => [
|
|
164
|
+
"write_file",
|
|
165
|
+
"edit_file",
|
|
166
|
+
"create_file",
|
|
167
|
+
"delete_file",
|
|
168
|
+
"bash",
|
|
169
|
+
"execute",
|
|
170
|
+
"run_command",
|
|
171
|
+
"terminal"
|
|
172
|
+
].includes(tool.name.toLowerCase()));
|
|
173
|
+
const instructionsLower = spec.instructions.toLowerCase();
|
|
174
|
+
const hasPlanningKeywords = /\b(plan|design|architect|strategy|analyze|review|assess|evaluate)\b/.test(instructionsLower);
|
|
175
|
+
const hasExplorationKeywords = /\b(search|find|explore|discover|locate|grep|pattern)\b/.test(instructionsLower);
|
|
176
|
+
const hasResearchKeywords = /\b(research|investigate|understand|learn|gather|collect)\b/.test(instructionsLower);
|
|
177
|
+
if (hasCodeTools) {
|
|
178
|
+
return "build";
|
|
179
|
+
}
|
|
180
|
+
if (hasPlanningKeywords && !hasCodeTools) {
|
|
181
|
+
return "plan";
|
|
182
|
+
}
|
|
183
|
+
if (hasExplorationKeywords && !hasResearchKeywords) {
|
|
184
|
+
return "explore";
|
|
185
|
+
}
|
|
186
|
+
return "general";
|
|
187
|
+
}
|
|
188
|
+
function specToOpenCodeConfig(spec, options) {
|
|
189
|
+
const agentType = options?.agentType ?? inferAgentType(spec);
|
|
190
|
+
return {
|
|
191
|
+
name: spec.meta.key,
|
|
192
|
+
version: spec.meta.version,
|
|
193
|
+
description: spec.description ?? spec.meta.description,
|
|
194
|
+
instructions: spec.instructions,
|
|
195
|
+
agent_type: agentType,
|
|
196
|
+
tools: specToolsToOpenCodeTools(spec.tools),
|
|
197
|
+
config: {
|
|
198
|
+
max_steps: options?.maxSteps ?? spec.maxSteps ?? 10,
|
|
199
|
+
temperature: options?.temperature ?? 0.7,
|
|
200
|
+
model: options?.model,
|
|
201
|
+
permissions: buildPermissions(spec)
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
function buildPermissions(spec) {
|
|
206
|
+
const permissions = {};
|
|
207
|
+
for (const tool of spec.tools) {
|
|
208
|
+
if (tool.requiresApproval) {
|
|
209
|
+
permissions[tool.name] = "ask";
|
|
210
|
+
} else if (tool.automationSafe === false) {
|
|
211
|
+
permissions[tool.name] = "ask";
|
|
212
|
+
} else {
|
|
213
|
+
permissions[tool.name] = "allow";
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return permissions;
|
|
217
|
+
}
|
|
218
|
+
function specToOpenCodeMarkdown(spec, options) {
|
|
219
|
+
const agentType = options?.agentType ?? inferAgentType(spec);
|
|
220
|
+
return {
|
|
221
|
+
frontmatter: {
|
|
222
|
+
name: spec.meta.key,
|
|
223
|
+
type: agentType,
|
|
224
|
+
version: spec.meta.version,
|
|
225
|
+
model: options?.model,
|
|
226
|
+
temperature: options?.temperature ?? 0.7,
|
|
227
|
+
max_steps: options?.maxSteps ?? spec.maxSteps ?? 10,
|
|
228
|
+
tools: spec.tools.map((t) => t.name)
|
|
229
|
+
},
|
|
230
|
+
body: buildMarkdownBody(spec)
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
function buildMarkdownBody(spec) {
|
|
234
|
+
const lines = [];
|
|
235
|
+
lines.push(`# ${spec.meta.key}`);
|
|
236
|
+
lines.push("");
|
|
237
|
+
if (spec.description ?? spec.meta.description) {
|
|
238
|
+
lines.push(spec.description ?? spec.meta.description ?? "");
|
|
239
|
+
lines.push("");
|
|
240
|
+
}
|
|
241
|
+
lines.push("## Instructions");
|
|
242
|
+
lines.push("");
|
|
243
|
+
lines.push(spec.instructions);
|
|
244
|
+
lines.push("");
|
|
245
|
+
if (spec.tools.length > 0) {
|
|
246
|
+
lines.push("## Tools");
|
|
247
|
+
lines.push("");
|
|
248
|
+
for (const tool of spec.tools) {
|
|
249
|
+
const permission = tool.requiresApproval ? "(requires approval)" : tool.automationSafe === false ? "(ask mode)" : "";
|
|
250
|
+
lines.push(`- **${tool.name}**: ${tool.description ?? "No description"} ${permission}`.trim());
|
|
251
|
+
}
|
|
252
|
+
lines.push("");
|
|
253
|
+
}
|
|
254
|
+
if (spec.knowledge && spec.knowledge.length > 0) {
|
|
255
|
+
lines.push("## Knowledge Sources");
|
|
256
|
+
lines.push("");
|
|
257
|
+
for (const k of spec.knowledge) {
|
|
258
|
+
const required = k.required ? "(required)" : "(optional)";
|
|
259
|
+
lines.push(`- ${k.key} ${required}`);
|
|
260
|
+
}
|
|
261
|
+
lines.push("");
|
|
262
|
+
}
|
|
263
|
+
return lines.join(`
|
|
264
|
+
`);
|
|
265
|
+
}
|
|
266
|
+
function serializeOpenCodeMarkdown(markdown) {
|
|
267
|
+
const lines = [];
|
|
268
|
+
lines.push("---");
|
|
269
|
+
lines.push(`name: ${markdown.frontmatter.name}`);
|
|
270
|
+
lines.push(`type: ${markdown.frontmatter.type}`);
|
|
271
|
+
if (markdown.frontmatter.version) {
|
|
272
|
+
lines.push(`version: ${markdown.frontmatter.version}`);
|
|
273
|
+
}
|
|
274
|
+
if (markdown.frontmatter.model) {
|
|
275
|
+
lines.push(`model: ${markdown.frontmatter.model}`);
|
|
276
|
+
}
|
|
277
|
+
if (markdown.frontmatter.temperature !== undefined) {
|
|
278
|
+
lines.push(`temperature: ${markdown.frontmatter.temperature}`);
|
|
279
|
+
}
|
|
280
|
+
if (markdown.frontmatter.max_steps !== undefined) {
|
|
281
|
+
lines.push(`max_steps: ${markdown.frontmatter.max_steps}`);
|
|
282
|
+
}
|
|
283
|
+
if (markdown.frontmatter.tools && markdown.frontmatter.tools.length > 0) {
|
|
284
|
+
lines.push(`tools:`);
|
|
285
|
+
for (const tool of markdown.frontmatter.tools) {
|
|
286
|
+
lines.push(` - ${tool}`);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
lines.push("---");
|
|
290
|
+
lines.push("");
|
|
291
|
+
lines.push(markdown.body);
|
|
292
|
+
return lines.join(`
|
|
293
|
+
`);
|
|
294
|
+
}
|
|
295
|
+
function openCodeConfigToSpec(config) {
|
|
296
|
+
return {
|
|
297
|
+
meta: {
|
|
298
|
+
key: config.name,
|
|
299
|
+
version: config.version ?? "1.0.0",
|
|
300
|
+
description: config.description ?? "",
|
|
301
|
+
stability: "experimental",
|
|
302
|
+
owners: [],
|
|
303
|
+
tags: []
|
|
304
|
+
},
|
|
305
|
+
description: config.description,
|
|
306
|
+
instructions: config.instructions ?? "",
|
|
307
|
+
tools: config.tools?.map((tool) => ({
|
|
308
|
+
name: tool.name,
|
|
309
|
+
description: tool.description,
|
|
310
|
+
schema: tool.parameters,
|
|
311
|
+
requiresApproval: tool.permission === "ask",
|
|
312
|
+
automationSafe: tool.permission === "allow"
|
|
313
|
+
})) ?? [],
|
|
314
|
+
maxSteps: config.config?.max_steps ?? 10
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
var init_agent_bridge = () => {};
|
|
318
|
+
|
|
319
|
+
// src/exporters/claude-agent-exporter.ts
|
|
320
|
+
class ClaudeAgentExporter {
|
|
321
|
+
format = "claude-agent";
|
|
322
|
+
export(spec, options = {}) {
|
|
323
|
+
const tools = this.exportTools(spec);
|
|
324
|
+
const config = this.buildConfig(spec, tools, options);
|
|
325
|
+
const claudeMd = options.generateClaudeMd ? this.generateClaudeMd(spec, options) : undefined;
|
|
326
|
+
return {
|
|
327
|
+
config,
|
|
328
|
+
claudeMd,
|
|
329
|
+
tools,
|
|
330
|
+
exportedAt: new Date,
|
|
331
|
+
sourceSpec: agentKey(spec.meta)
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
exportMany(specs, options = {}) {
|
|
335
|
+
return specs.map((spec) => this.export(spec, options));
|
|
336
|
+
}
|
|
337
|
+
validate(spec) {
|
|
338
|
+
const errors = [];
|
|
339
|
+
if (!spec.meta?.key) {
|
|
340
|
+
errors.push("Spec must have a meta.key");
|
|
341
|
+
}
|
|
342
|
+
if (!spec.instructions) {
|
|
343
|
+
errors.push("Spec must have instructions");
|
|
344
|
+
}
|
|
345
|
+
if (!spec.tools || spec.tools.length === 0) {
|
|
346
|
+
errors.push("Spec must have at least one tool");
|
|
347
|
+
}
|
|
348
|
+
for (const tool of spec.tools ?? []) {
|
|
349
|
+
if (!tool.name) {
|
|
350
|
+
errors.push("All tools must have a name");
|
|
351
|
+
}
|
|
352
|
+
if (!tool.description && !tool.name) {
|
|
353
|
+
errors.push(`Tool must have a description or name`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return { valid: errors.length === 0, errors };
|
|
357
|
+
}
|
|
358
|
+
buildConfig(spec, tools, options) {
|
|
359
|
+
const config = {
|
|
360
|
+
model: options.model ?? "claude-sonnet-4-20250514",
|
|
361
|
+
system: this.buildSystemPrompt(spec, options),
|
|
362
|
+
tools,
|
|
363
|
+
max_turns: spec.maxSteps ?? 10
|
|
364
|
+
};
|
|
365
|
+
if (options.computerUse) {
|
|
366
|
+
config.computer_use = true;
|
|
367
|
+
}
|
|
368
|
+
if (options.extendedThinking) {
|
|
369
|
+
config.extended_thinking = true;
|
|
370
|
+
}
|
|
371
|
+
if (options.mcpServers && options.mcpServers.length > 0) {
|
|
372
|
+
config.mcp_servers = options.mcpServers;
|
|
373
|
+
}
|
|
374
|
+
return config;
|
|
375
|
+
}
|
|
376
|
+
buildSystemPrompt(spec, options) {
|
|
377
|
+
const parts = [];
|
|
378
|
+
parts.push(spec.instructions);
|
|
379
|
+
if (spec.knowledge && spec.knowledge.length > 0) {
|
|
380
|
+
parts.push("");
|
|
381
|
+
parts.push("## Knowledge Sources");
|
|
382
|
+
for (const k of spec.knowledge) {
|
|
383
|
+
if (k.instructions) {
|
|
384
|
+
parts.push(`- ${k.key}: ${k.instructions}`);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (spec.policy) {
|
|
389
|
+
parts.push("");
|
|
390
|
+
parts.push("## Policy");
|
|
391
|
+
if (spec.policy.confidence?.min) {
|
|
392
|
+
parts.push(`- Minimum confidence: ${spec.policy.confidence.min}`);
|
|
393
|
+
}
|
|
394
|
+
if (spec.policy.escalation) {
|
|
395
|
+
parts.push("- Escalation policy is configured");
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (options.metadata) {
|
|
399
|
+
parts.push("");
|
|
400
|
+
parts.push("## Additional Context");
|
|
401
|
+
for (const [key, value] of Object.entries(options.metadata)) {
|
|
402
|
+
parts.push(`- ${key}: ${String(value)}`);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
return parts.join(`
|
|
406
|
+
`);
|
|
407
|
+
}
|
|
408
|
+
exportTools(spec) {
|
|
409
|
+
return spec.tools.map((tool) => ({
|
|
410
|
+
name: tool.name,
|
|
411
|
+
description: tool.description ?? `Execute ${tool.name}`,
|
|
412
|
+
input_schema: this.normalizeSchema(tool.schema),
|
|
413
|
+
requires_confirmation: tool.requiresApproval ?? !tool.automationSafe
|
|
414
|
+
}));
|
|
415
|
+
}
|
|
416
|
+
normalizeSchema(schema) {
|
|
417
|
+
if (!schema) {
|
|
418
|
+
return { type: "object" };
|
|
419
|
+
}
|
|
420
|
+
if (schema.type === "object") {
|
|
421
|
+
return {
|
|
422
|
+
type: "object",
|
|
423
|
+
properties: schema.properties,
|
|
424
|
+
required: schema.required
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
type: "object",
|
|
429
|
+
properties: { value: schema },
|
|
430
|
+
required: ["value"]
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
generateClaudeMd(spec, options) {
|
|
434
|
+
const lines = [];
|
|
435
|
+
lines.push("# Agent Configuration");
|
|
436
|
+
lines.push("");
|
|
437
|
+
if (spec.description) {
|
|
438
|
+
lines.push(`> ${spec.description}`);
|
|
439
|
+
lines.push("");
|
|
440
|
+
}
|
|
441
|
+
lines.push("## Metadata");
|
|
442
|
+
lines.push("");
|
|
443
|
+
lines.push(`- **Name**: ${spec.meta.key}`);
|
|
444
|
+
lines.push(`- **Version**: ${spec.meta.version}`);
|
|
445
|
+
if (spec.meta.owners && spec.meta.owners.length > 0) {
|
|
446
|
+
lines.push(`- **Owners**: ${spec.meta.owners.join(", ")}`);
|
|
447
|
+
}
|
|
448
|
+
if (options.model) {
|
|
449
|
+
lines.push(`- **Model**: ${options.model}`);
|
|
450
|
+
}
|
|
451
|
+
lines.push("");
|
|
452
|
+
lines.push("## Instructions");
|
|
453
|
+
lines.push("");
|
|
454
|
+
lines.push(spec.instructions);
|
|
455
|
+
lines.push("");
|
|
456
|
+
if (spec.tools.length > 0) {
|
|
457
|
+
lines.push("## Available Tools");
|
|
458
|
+
lines.push("");
|
|
459
|
+
for (const tool of spec.tools) {
|
|
460
|
+
const flags = [];
|
|
461
|
+
if (tool.requiresApproval) {
|
|
462
|
+
flags.push("requires approval");
|
|
463
|
+
}
|
|
464
|
+
if (tool.automationSafe === false) {
|
|
465
|
+
flags.push("not automation safe");
|
|
466
|
+
}
|
|
467
|
+
const flagStr = flags.length > 0 ? ` (${flags.join(", ")})` : "";
|
|
468
|
+
lines.push(`### ${tool.name}${flagStr}`);
|
|
469
|
+
lines.push("");
|
|
470
|
+
if (tool.description) {
|
|
471
|
+
lines.push(tool.description);
|
|
472
|
+
lines.push("");
|
|
473
|
+
}
|
|
474
|
+
if (tool.schema) {
|
|
475
|
+
lines.push("**Parameters:**");
|
|
476
|
+
lines.push("```json");
|
|
477
|
+
lines.push(JSON.stringify(tool.schema, null, 2));
|
|
478
|
+
lines.push("```");
|
|
479
|
+
lines.push("");
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
if (spec.knowledge && spec.knowledge.length > 0) {
|
|
484
|
+
lines.push("## Knowledge Sources");
|
|
485
|
+
lines.push("");
|
|
486
|
+
for (const k of spec.knowledge) {
|
|
487
|
+
const required = k.required ? "(required)" : "(optional)";
|
|
488
|
+
lines.push(`- **${k.key}** ${required}`);
|
|
489
|
+
if (k.instructions) {
|
|
490
|
+
lines.push(` - ${k.instructions}`);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
lines.push("");
|
|
494
|
+
}
|
|
495
|
+
if (spec.policy) {
|
|
496
|
+
lines.push("## Policy");
|
|
497
|
+
lines.push("");
|
|
498
|
+
if (spec.policy.confidence?.min) {
|
|
499
|
+
lines.push(`- Minimum confidence: ${spec.policy.confidence.min}`);
|
|
500
|
+
}
|
|
501
|
+
if (spec.policy.escalation) {
|
|
502
|
+
lines.push("- Escalation policy configured");
|
|
503
|
+
}
|
|
504
|
+
if (spec.policy.flags && spec.policy.flags.length > 0) {
|
|
505
|
+
lines.push(`- Feature flags: ${spec.policy.flags.join(", ")}`);
|
|
506
|
+
}
|
|
507
|
+
lines.push("");
|
|
508
|
+
}
|
|
509
|
+
if (options.mcpServers && options.mcpServers.length > 0) {
|
|
510
|
+
lines.push("## MCP Servers");
|
|
511
|
+
lines.push("");
|
|
512
|
+
for (const server of options.mcpServers) {
|
|
513
|
+
lines.push(`- **${server.name}**: \`${server.command}${server.args ? " " + server.args.join(" ") : ""}\``);
|
|
514
|
+
}
|
|
515
|
+
lines.push("");
|
|
516
|
+
}
|
|
517
|
+
lines.push("---");
|
|
518
|
+
lines.push("");
|
|
519
|
+
lines.push(`*Generated from ContractSpec: ${agentKey(spec.meta)}*`);
|
|
520
|
+
return lines.join(`
|
|
521
|
+
`);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
function exportToClaudeAgent(spec, options) {
|
|
525
|
+
const exporter = new ClaudeAgentExporter;
|
|
526
|
+
return exporter.export(spec, options);
|
|
527
|
+
}
|
|
528
|
+
function generateClaudeMd(spec, options) {
|
|
529
|
+
const exporter = new ClaudeAgentExporter;
|
|
530
|
+
const result = exporter.export(spec, { ...options, generateClaudeMd: true });
|
|
531
|
+
return result.claudeMd ?? "";
|
|
532
|
+
}
|
|
533
|
+
function validateForClaudeAgent(spec) {
|
|
534
|
+
const exporter = new ClaudeAgentExporter;
|
|
535
|
+
return exporter.validate(spec);
|
|
536
|
+
}
|
|
537
|
+
// src/exporters/opencode-exporter.ts
|
|
538
|
+
init_agent_bridge();
|
|
539
|
+
|
|
540
|
+
class OpenCodeExporter {
|
|
541
|
+
format = "opencode";
|
|
542
|
+
export(spec, options = {}) {
|
|
543
|
+
const jsonConfig = this.buildJsonConfig(spec, options);
|
|
544
|
+
const markdownConfig = this.generateMarkdown(spec, jsonConfig, options);
|
|
545
|
+
return {
|
|
546
|
+
jsonConfig,
|
|
547
|
+
markdownConfig,
|
|
548
|
+
exportedAt: new Date,
|
|
549
|
+
sourceSpec: agentKey(spec.meta)
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
exportMany(specs, options = {}) {
|
|
553
|
+
return specs.map((spec) => this.export(spec, options));
|
|
554
|
+
}
|
|
555
|
+
validate(spec) {
|
|
556
|
+
const errors = [];
|
|
557
|
+
if (!spec.meta?.key) {
|
|
558
|
+
errors.push("Spec must have a meta.key");
|
|
559
|
+
}
|
|
560
|
+
if (!spec.instructions) {
|
|
561
|
+
errors.push("Spec must have instructions");
|
|
562
|
+
}
|
|
563
|
+
for (const tool of spec.tools ?? []) {
|
|
564
|
+
if (!tool.name) {
|
|
565
|
+
errors.push("All tools must have a name");
|
|
566
|
+
}
|
|
567
|
+
if (tool.name && !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(tool.name)) {
|
|
568
|
+
errors.push(`Tool name '${tool.name}' should be a valid identifier (letters, numbers, underscores)`);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
return { valid: errors.length === 0, errors };
|
|
572
|
+
}
|
|
573
|
+
buildJsonConfig(spec, options) {
|
|
574
|
+
const agentType = options.agentType ?? inferAgentType(spec);
|
|
575
|
+
return {
|
|
576
|
+
name: spec.meta.key,
|
|
577
|
+
version: spec.meta.version,
|
|
578
|
+
description: spec.description,
|
|
579
|
+
type: agentType,
|
|
580
|
+
instructions: spec.instructions,
|
|
581
|
+
tools: this.exportTools(spec),
|
|
582
|
+
config: {
|
|
583
|
+
max_steps: options.maxSteps ?? spec.maxSteps ?? 10,
|
|
584
|
+
temperature: options.temperature ?? 0.7,
|
|
585
|
+
model: options.model
|
|
586
|
+
}
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
exportTools(spec) {
|
|
590
|
+
return spec.tools.map((tool) => ({
|
|
591
|
+
name: tool.name,
|
|
592
|
+
description: tool.description ?? `Execute ${tool.name}`,
|
|
593
|
+
schema: tool.schema ?? { type: "object" },
|
|
594
|
+
requires_approval: tool.requiresApproval ?? !tool.automationSafe
|
|
595
|
+
}));
|
|
596
|
+
}
|
|
597
|
+
generateMarkdown(spec, jsonConfig, options) {
|
|
598
|
+
const lines = [];
|
|
599
|
+
lines.push("---");
|
|
600
|
+
lines.push(`name: ${jsonConfig.name}`);
|
|
601
|
+
lines.push(`type: ${jsonConfig.type}`);
|
|
602
|
+
if (jsonConfig.version) {
|
|
603
|
+
lines.push(`version: ${jsonConfig.version}`);
|
|
604
|
+
}
|
|
605
|
+
if (jsonConfig.config.model) {
|
|
606
|
+
lines.push(`model: ${jsonConfig.config.model}`);
|
|
607
|
+
}
|
|
608
|
+
if (jsonConfig.config.temperature !== undefined) {
|
|
609
|
+
lines.push(`temperature: ${jsonConfig.config.temperature}`);
|
|
610
|
+
}
|
|
611
|
+
if (jsonConfig.config.max_steps !== undefined) {
|
|
612
|
+
lines.push(`max_steps: ${jsonConfig.config.max_steps}`);
|
|
613
|
+
}
|
|
614
|
+
if (jsonConfig.tools.length > 0) {
|
|
615
|
+
lines.push("tools:");
|
|
616
|
+
for (const tool of jsonConfig.tools) {
|
|
617
|
+
const permission = tool.requires_approval ? " # requires approval" : "";
|
|
618
|
+
lines.push(` - ${tool.name}${permission}`);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
lines.push("---");
|
|
622
|
+
lines.push("");
|
|
623
|
+
lines.push(`# ${spec.meta.key}`);
|
|
624
|
+
lines.push("");
|
|
625
|
+
if (spec.description) {
|
|
626
|
+
lines.push(spec.description);
|
|
627
|
+
lines.push("");
|
|
628
|
+
}
|
|
629
|
+
lines.push(`> Agent type: **${jsonConfig.type}**`);
|
|
630
|
+
lines.push("");
|
|
631
|
+
lines.push(this.getAgentTypeDescription(jsonConfig.type));
|
|
632
|
+
lines.push("");
|
|
633
|
+
lines.push("## Instructions");
|
|
634
|
+
lines.push("");
|
|
635
|
+
lines.push(spec.instructions);
|
|
636
|
+
lines.push("");
|
|
637
|
+
if (spec.tools.length > 0) {
|
|
638
|
+
lines.push("## Tools");
|
|
639
|
+
lines.push("");
|
|
640
|
+
for (const tool of spec.tools) {
|
|
641
|
+
const approval = tool.requiresApproval ? " *(requires approval)*" : "";
|
|
642
|
+
const safe = tool.automationSafe === false ? " *(not automation safe)*" : "";
|
|
643
|
+
lines.push(`### ${tool.name}${approval}${safe}`);
|
|
644
|
+
lines.push("");
|
|
645
|
+
if (tool.description) {
|
|
646
|
+
lines.push(tool.description);
|
|
647
|
+
lines.push("");
|
|
648
|
+
}
|
|
649
|
+
if (tool.schema && options.includeComments !== false) {
|
|
650
|
+
lines.push("**Parameters:**");
|
|
651
|
+
lines.push("");
|
|
652
|
+
lines.push("```json");
|
|
653
|
+
lines.push(JSON.stringify(tool.schema, null, options.prettyPrint !== false ? 2 : 0));
|
|
654
|
+
lines.push("```");
|
|
655
|
+
lines.push("");
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
if (spec.knowledge && spec.knowledge.length > 0) {
|
|
660
|
+
lines.push("## Knowledge Sources");
|
|
661
|
+
lines.push("");
|
|
662
|
+
for (const k of spec.knowledge) {
|
|
663
|
+
const required = k.required ? "(required)" : "(optional)";
|
|
664
|
+
lines.push(`- **${k.key}** ${required}`);
|
|
665
|
+
if (k.instructions) {
|
|
666
|
+
lines.push(` - ${k.instructions}`);
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
lines.push("");
|
|
670
|
+
}
|
|
671
|
+
if (spec.policy) {
|
|
672
|
+
lines.push("## Policy");
|
|
673
|
+
lines.push("");
|
|
674
|
+
if (spec.policy.confidence?.min) {
|
|
675
|
+
lines.push(`- Minimum confidence: ${spec.policy.confidence.min}`);
|
|
676
|
+
}
|
|
677
|
+
if (spec.policy.escalation) {
|
|
678
|
+
lines.push("- Escalation policy configured");
|
|
679
|
+
}
|
|
680
|
+
lines.push("");
|
|
681
|
+
}
|
|
682
|
+
lines.push("## Configuration");
|
|
683
|
+
lines.push("");
|
|
684
|
+
lines.push("```json");
|
|
685
|
+
lines.push(JSON.stringify(jsonConfig.config, null, options.prettyPrint !== false ? 2 : 0));
|
|
686
|
+
lines.push("```");
|
|
687
|
+
lines.push("");
|
|
688
|
+
lines.push("---");
|
|
689
|
+
lines.push("");
|
|
690
|
+
lines.push(`*Generated from ContractSpec: ${agentKey(spec.meta)}*`);
|
|
691
|
+
lines.push(`*Exported at: ${new Date().toISOString()}*`);
|
|
692
|
+
return lines.join(`
|
|
693
|
+
`);
|
|
694
|
+
}
|
|
695
|
+
getAgentTypeDescription(type) {
|
|
696
|
+
switch (type) {
|
|
697
|
+
case "build":
|
|
698
|
+
return "Primary agent with full tool access for code generation and modification.";
|
|
699
|
+
case "plan":
|
|
700
|
+
return "Restricted agent for analysis and planning. File edits and bash commands require approval.";
|
|
701
|
+
case "general":
|
|
702
|
+
return "General-purpose subagent for complex questions and multi-step tasks.";
|
|
703
|
+
case "explore":
|
|
704
|
+
return "Fast subagent optimized for codebase exploration and pattern searching.";
|
|
705
|
+
default:
|
|
706
|
+
return "";
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
function exportToOpenCode(spec, options) {
|
|
711
|
+
const exporter = new OpenCodeExporter;
|
|
712
|
+
return exporter.export(spec, options);
|
|
713
|
+
}
|
|
714
|
+
function generateOpenCodeMarkdown(spec, options) {
|
|
715
|
+
const exporter = new OpenCodeExporter;
|
|
716
|
+
const result = exporter.export(spec, options);
|
|
717
|
+
return result.markdownConfig;
|
|
718
|
+
}
|
|
719
|
+
function generateOpenCodeJSON(spec, options) {
|
|
720
|
+
const exporter = new OpenCodeExporter;
|
|
721
|
+
const result = exporter.export(spec, options);
|
|
722
|
+
return result.jsonConfig;
|
|
723
|
+
}
|
|
724
|
+
function validateForOpenCode(spec) {
|
|
725
|
+
const exporter = new OpenCodeExporter;
|
|
726
|
+
return exporter.validate(spec);
|
|
727
|
+
}
|
|
728
|
+
export {
|
|
729
|
+
validateForOpenCode,
|
|
730
|
+
validateForClaudeAgent,
|
|
731
|
+
generateOpenCodeMarkdown,
|
|
732
|
+
generateOpenCodeJSON,
|
|
733
|
+
generateClaudeMd,
|
|
734
|
+
exportToOpenCode,
|
|
735
|
+
exportToClaudeAgent,
|
|
736
|
+
OpenCodeExporter,
|
|
737
|
+
ClaudeAgentExporter
|
|
738
|
+
};
|