sdtk-code-kit 0.3.0 → 0.3.2
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/README.md +204 -204
- package/assets/manifest/toolkit-bundle.manifest.json +147 -147
- package/assets/manifest/toolkit-bundle.sha256.txt +5 -5
- package/bin/sdtk-code.js +14 -14
- package/package.json +44 -44
- package/src/commands/agent-team.js +479 -174
- package/src/commands/build.js +53 -53
- package/src/commands/doctor.js +51 -51
- package/src/commands/generate.js +11 -11
- package/src/commands/guardrails.js +215 -215
- package/src/commands/help.js +266 -257
- package/src/commands/init.js +98 -98
- package/src/commands/plan.js +53 -53
- package/src/commands/readiness.js +77 -77
- package/src/commands/resume.js +61 -61
- package/src/commands/runtime.js +224 -224
- package/src/commands/ship.js +59 -59
- package/src/commands/sleep.js +132 -132
- package/src/commands/start.js +89 -89
- package/src/commands/status.js +77 -77
- package/src/commands/update.js +11 -11
- package/src/commands/verify.js +71 -71
- package/src/index.js +112 -112
- package/src/lib/agent-team-author.js +552 -0
- package/src/lib/agent-team-evidence.js +302 -0
- package/src/lib/agent-team-execute.js +892 -0
- package/src/lib/agent-team-export.js +411 -409
- package/src/lib/agent-team-plan.js +514 -514
- package/src/lib/agent-team-readiness.js +161 -0
- package/src/lib/agent-team-report.js +165 -0
- package/src/lib/agent-team-sleep-execute.js +524 -0
- package/src/lib/agent-team-sleep-session.js +278 -0
- package/src/lib/args.js +107 -107
- package/src/lib/errors.js +41 -41
- package/src/lib/model-provider.js +219 -0
- package/src/lib/powershell.js +65 -65
- package/src/lib/project-target-guard.js +53 -53
- package/src/lib/scope.js +72 -72
- package/src/lib/ship-readiness.js +281 -281
- package/src/lib/sleep-plan.js +175 -175
- package/src/lib/sleep-report.js +229 -229
- package/src/lib/toolkit-payload.js +72 -72
- package/src/lib/trust-events.js +264 -185
- package/src/lib/trust-file-scope.js +154 -154
- package/src/lib/trust-policy.js +212 -212
- package/src/lib/trust-redact.js +58 -35
- package/src/lib/trust-trace.js +179 -179
- package/src/lib/update.js +344 -344
- package/src/lib/workflow-artifact.js +503 -503
- package/src/lib/workflow-build.js +127 -127
- package/src/lib/workflow-doctor.js +83 -83
- package/src/lib/workflow-handoff.js +1029 -1029
- package/src/lib/workflow-intake.js +101 -101
- package/src/lib/workflow-plan.js +193 -193
- package/src/lib/workflow-review-packet.js +650 -650
- package/src/lib/workflow-ship.js +213 -213
- package/src/lib/workflow-state.js +438 -438
- package/src/lib/workflow-verify.js +393 -393
|
@@ -1,409 +1,411 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
// BK-262 Phase B — Agent Team Runtime Adapter Exports.
|
|
4
|
-
//
|
|
5
|
-
// Turns a validated BK-260 agent-team plan into runtime-specific export bundles
|
|
6
|
-
// (per-role prompts + metadata + brief + optional codex review-draft TOML) so a
|
|
7
|
-
// human (or a runtime the human chooses to act on) spends less time hand-writing
|
|
8
|
-
// prompts/assignments and gets consistent scope + evidence requirements.
|
|
9
|
-
//
|
|
10
|
-
// EXPORT/PACKAGING ONLY. This module:
|
|
11
|
-
// - does NOT execute agents, spawn processes, or schedule anything,
|
|
12
|
-
// - does NOT write .codex/agents/**, .claude/**, or any global/user config,
|
|
13
|
-
// - writes only under <project>/.sdtk/agent-team/exports/**,
|
|
14
|
-
// - is not a local LLM runtime and is not Sleep execution.
|
|
15
|
-
|
|
16
|
-
const fs = require("fs");
|
|
17
|
-
const path = require("path");
|
|
18
|
-
const { ValidationError } = require("./errors");
|
|
19
|
-
const {
|
|
20
|
-
loadAgentTeamPlan,
|
|
21
|
-
projectAgentTeamPreview,
|
|
22
|
-
stopConditionIds,
|
|
23
|
-
BOUNDARY_LINE,
|
|
24
|
-
} = require("./agent-team-plan");
|
|
25
|
-
|
|
26
|
-
const EXPORT_SCHEMA = "sdtk.agent-team-export.v1";
|
|
27
|
-
// Mirrors commands/runtime.js VALID_RUNTIMES. `--runtime` selects the export
|
|
28
|
-
// target format the human will hand the bundle to; it is not a per-role spawn.
|
|
29
|
-
const EXPORT_RUNTIMES = Object.freeze(["codex", "claude"]);
|
|
30
|
-
const GOAL_PROMPT_MAX = 4000;
|
|
31
|
-
|
|
32
|
-
// Phrases that would overclaim execution. The verbatim BOUNDARY_LINE deliberately
|
|
33
|
-
// contains "execute" ("does not execute agents"), so the guard targets specific
|
|
34
|
-
// auto-run claims rather than the bare word.
|
|
35
|
-
const OVERCLAIM_PHRASES = Object.freeze([
|
|
36
|
-
"auto-spawn",
|
|
37
|
-
"automatically spawn",
|
|
38
|
-
"automatically run",
|
|
39
|
-
"automatically execute",
|
|
40
|
-
"will execute the",
|
|
41
|
-
"will spawn",
|
|
42
|
-
"will deploy",
|
|
43
|
-
"will publish",
|
|
44
|
-
"spawns subagents automatically",
|
|
45
|
-
]);
|
|
46
|
-
|
|
47
|
-
// Safe single path segment: filename-friendly, no separators, no traversal.
|
|
48
|
-
const SAFE_SEGMENT = /^[A-Za-z0-9._-]+$/;
|
|
49
|
-
|
|
50
|
-
function safeSegment(value, label) {
|
|
51
|
-
const segment = String(value);
|
|
52
|
-
if (
|
|
53
|
-
segment.length === 0 ||
|
|
54
|
-
segment === "." ||
|
|
55
|
-
segment === ".." ||
|
|
56
|
-
segment.includes("/") ||
|
|
57
|
-
segment.includes("\\") ||
|
|
58
|
-
segment.includes("\0") ||
|
|
59
|
-
!SAFE_SEGMENT.test(segment)
|
|
60
|
-
) {
|
|
61
|
-
throw new ValidationError(
|
|
62
|
-
`FAIL_UNSAFE_EXPORT_PATH: ${label} "${segment}" is not a safe path segment (no separators or "."/"..").`
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
return segment;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function asArray(value) {
|
|
69
|
-
return Array.isArray(value) ? value : [];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function roleName(role) {
|
|
73
|
-
return role && typeof role.role === "string" && role.role.length > 0 ? role.role : "unnamed";
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function roleFileBase(role) {
|
|
77
|
-
return roleName(role).toUpperCase();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// --- D3: static, advisory, non-binding suggestions ---------------------------
|
|
81
|
-
// Never a mandated model. Higher reasoning is suggested for review/scope roles.
|
|
82
|
-
function modelSuggestion() {
|
|
83
|
-
return "runtime_default";
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const HIGH_REASONING_ROLES = new Set(["pm", "qa", "arch", "architect", "review", "reviewer"]);
|
|
87
|
-
|
|
88
|
-
function reasoningSuggestion(role) {
|
|
89
|
-
return HIGH_REASONING_ROLES.has(roleName(role)) ? "high" : "medium";
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function sandboxExpectation(canWrite) {
|
|
93
|
-
return canWrite
|
|
94
|
-
? "workspace-write (review the allowed scope before granting write)"
|
|
95
|
-
: "read-only";
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function bulletList(items, fallback) {
|
|
99
|
-
if (!Array.isArray(items) || items.length === 0) {
|
|
100
|
-
return `- ${fallback}`;
|
|
101
|
-
}
|
|
102
|
-
return items.map((item) => `- ${String(item)}`).join("\n");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// --- G2: renderers -----------------------------------------------------------
|
|
106
|
-
|
|
107
|
-
// Bounded, copy-pasteable prompt per role (Codex `/goal` style; Claude reads the
|
|
108
|
-
// same generic packet). Kept compact so it stays < GOAL_PROMPT_MAX.
|
|
109
|
-
function renderGoalText(plan, role, runtime) {
|
|
110
|
-
const stops = asArray(plan.stop_conditions).length > 0 ? asArray(plan.stop_conditions) : stopConditionIds();
|
|
111
|
-
return [
|
|
112
|
-
`# Agent goal — ${plan.feature_key} / ${roleName(role)} (${runtime} export)`,
|
|
113
|
-
"",
|
|
114
|
-
BOUNDARY_LINE,
|
|
115
|
-
"",
|
|
116
|
-
`Role: ${roleName(role)}`,
|
|
117
|
-
`Can write: ${role.can_write ? "yes" : "no (read-only)"}`,
|
|
118
|
-
`Run id: ${plan.run_id}`,
|
|
119
|
-
"",
|
|
120
|
-
"## Objective",
|
|
121
|
-
String(role.objective || "(none declared)"),
|
|
122
|
-
"",
|
|
123
|
-
"## Allowed file scopes (do not write outside these)",
|
|
124
|
-
bulletList(role.allowed_file_scopes, "none (read-only role)"),
|
|
125
|
-
"",
|
|
126
|
-
"## Blocked file scopes (never touch)",
|
|
127
|
-
bulletList(role.blocked_file_scopes, "none declared"),
|
|
128
|
-
"",
|
|
129
|
-
"## Verification commands (run and capture evidence)",
|
|
130
|
-
bulletList(role.verification_commands, "none"),
|
|
131
|
-
"",
|
|
132
|
-
"## Evidence required",
|
|
133
|
-
bulletList(role.evidence_required, "none"),
|
|
134
|
-
"",
|
|
135
|
-
"## Stop conditions (stop and report at any of these)",
|
|
136
|
-
bulletList(stops, "none declared"),
|
|
137
|
-
"",
|
|
138
|
-
"## Boundary",
|
|
139
|
-
"Stay within the allowed scope. Do not spawn processes, publish packages, or deploy.",
|
|
140
|
-
"Ask for parallel subagents only if the plan implies parallel roles; never assume the runtime creates them on its own.",
|
|
141
|
-
BOUNDARY_LINE,
|
|
142
|
-
"",
|
|
143
|
-
].join("\n");
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function projectRole(plan, role, runtime) {
|
|
147
|
-
const goalText = renderGoalText(plan, role, runtime);
|
|
148
|
-
return {
|
|
149
|
-
role: roleName(role),
|
|
150
|
-
runtime_target: runtime,
|
|
151
|
-
can_write: role.can_write === true,
|
|
152
|
-
allowed_file_scopes: asArray(role.allowed_file_scopes),
|
|
153
|
-
blocked_file_scopes: asArray(role.blocked_file_scopes),
|
|
154
|
-
verification_commands: asArray(role.verification_commands),
|
|
155
|
-
evidence_required: asArray(role.evidence_required),
|
|
156
|
-
stop_conditions: asArray(plan.stop_conditions).length > 0 ? asArray(plan.stop_conditions) : stopConditionIds(),
|
|
157
|
-
model_suggestion: modelSuggestion(),
|
|
158
|
-
reasoning_suggestion: reasoningSuggestion(role),
|
|
159
|
-
sandbox_expectation: sandboxExpectation(role.can_write === true),
|
|
160
|
-
goal_text: goalText,
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// --- G1: projection (pure, no fs) --------------------------------------------
|
|
165
|
-
|
|
166
|
-
// Pure projection from an already-validated plan to a runtime export bundle.
|
|
167
|
-
// Fail-closed: reuses the BK-260 preview validation, enforces /goal length and
|
|
168
|
-
// the no-overclaim guard. No fs, no spawn.
|
|
169
|
-
function projectExport(plan, runtime) {
|
|
170
|
-
if (!EXPORT_RUNTIMES.includes(runtime)) {
|
|
171
|
-
throw new ValidationError(
|
|
172
|
-
`Invalid value for --runtime: "${runtime}". Must be one of: ${EXPORT_RUNTIMES.join(", ")}`
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Reuse BK-260 validation — do not re-derive a parallel validator.
|
|
177
|
-
const preview = projectAgentTeamPreview(plan, null);
|
|
178
|
-
if (preview.verdict !== "PASS_AGENT_TEAM_PREVIEW_READY") {
|
|
179
|
-
throw new ValidationError(
|
|
180
|
-
`NEEDS_AGENT_TEAM_PLAN: plan is not export-ready — ${preview.blockers.join("; ")}`
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// Path-segment safety: a hand-edited plan must not escape the export dir via
|
|
185
|
-
// feature_key or a role name like "../PWN". Fail closed before any write.
|
|
186
|
-
safeSegment(plan.feature_key, "feature_key");
|
|
187
|
-
for (const role of asArray(plan.roles)) {
|
|
188
|
-
if (role && typeof role === "object") {
|
|
189
|
-
safeSegment(roleName(role), "role");
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const roles = asArray(plan.roles)
|
|
194
|
-
.filter((role) => role && typeof role === "object")
|
|
195
|
-
.map((role) => projectRole(plan, role, runtime));
|
|
196
|
-
|
|
197
|
-
// /goal length guard.
|
|
198
|
-
for (const role of roles) {
|
|
199
|
-
if (role.goal_text.length >= GOAL_PROMPT_MAX) {
|
|
200
|
-
throw new ValidationError(
|
|
201
|
-
`FAIL_GOAL_PROMPT_TOO_LONG: ${role.role} goal prompt is ${role.goal_text.length} chars (max ${GOAL_PROMPT_MAX}). Link to the plan JSON instead of inlining.`
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// No-overclaim guard + boundary presence.
|
|
207
|
-
for (const role of roles) {
|
|
208
|
-
const lowered = role.goal_text.toLowerCase();
|
|
209
|
-
for (const phrase of OVERCLAIM_PHRASES) {
|
|
210
|
-
if (lowered.includes(phrase)) {
|
|
211
|
-
throw new ValidationError(
|
|
212
|
-
`FAIL_RUNTIME_OVERCLAIM: ${role.role} export text implies execution ("${phrase}"). Export is preview-only.`
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
if (!role.goal_text.includes(BOUNDARY_LINE)) {
|
|
217
|
-
throw new ValidationError(
|
|
218
|
-
`FAIL_RUNTIME_OVERCLAIM: ${role.role} export text is missing the export-only boundary line.`
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Exactly one writer carried through (preview already guarantees this; assert).
|
|
224
|
-
const writers = roles.filter((role) => role.can_write === true);
|
|
225
|
-
if (writers.length !== 1) {
|
|
226
|
-
throw new ValidationError(
|
|
227
|
-
`FAIL_RUNTIME_OVERCLAIM: export must carry exactly one writer role, found ${writers.length}.`
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
return {
|
|
232
|
-
schema_version: EXPORT_SCHEMA,
|
|
233
|
-
feature_key: plan.feature_key,
|
|
234
|
-
run_id: plan.run_id,
|
|
235
|
-
runtime,
|
|
236
|
-
boundary_line: BOUNDARY_LINE,
|
|
237
|
-
generated_at: new Date().toISOString(),
|
|
238
|
-
roles,
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function renderAdapterMetadata(exp) {
|
|
243
|
-
return {
|
|
244
|
-
schema_version: exp.schema_version,
|
|
245
|
-
feature_key: exp.feature_key,
|
|
246
|
-
run_id: exp.run_id,
|
|
247
|
-
runtime: exp.runtime,
|
|
248
|
-
boundary_line: exp.boundary_line,
|
|
249
|
-
generated_at: exp.generated_at,
|
|
250
|
-
roles: exp.roles.map((role) => ({
|
|
251
|
-
role: role.role,
|
|
252
|
-
runtime_target: role.runtime_target,
|
|
253
|
-
can_write: role.can_write,
|
|
254
|
-
allowed_file_scopes: role.allowed_file_scopes,
|
|
255
|
-
blocked_file_scopes: role.blocked_file_scopes,
|
|
256
|
-
verification_commands: role.verification_commands,
|
|
257
|
-
evidence_required: role.evidence_required,
|
|
258
|
-
stop_conditions: role.stop_conditions,
|
|
259
|
-
model_suggestion: role.model_suggestion,
|
|
260
|
-
reasoning_suggestion: role.reasoning_suggestion,
|
|
261
|
-
sandbox_expectation: role.sandbox_expectation,
|
|
262
|
-
})),
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
// Human overview per runtime (D4). Overview-only; adds no authority over the
|
|
267
|
-
// per-role files or metadata.
|
|
268
|
-
function renderRunBrief(exp) {
|
|
269
|
-
const writer = exp.roles.find((role) => role.can_write === true);
|
|
270
|
-
const tomlNote = exp.runtime === "codex"
|
|
271
|
-
? " + `<ROLE>.toml.preview` (review draft, not installed)"
|
|
272
|
-
: "";
|
|
273
|
-
const lines = [
|
|
274
|
-
`# Agent Team Run Brief — ${exp.feature_key} (${exp.runtime})`,
|
|
275
|
-
"",
|
|
276
|
-
exp.boundary_line,
|
|
277
|
-
"",
|
|
278
|
-
`- Run id: ${exp.run_id}`,
|
|
279
|
-
`- Runtime target: ${exp.runtime}`,
|
|
280
|
-
`- Writer role: ${writer ? writer.role : "(none)"}`,
|
|
281
|
-
`- Per-role files: \`<ROLE>.goal.txt\` + \`adapter-metadata.json\` + this brief${tomlNote}`,
|
|
282
|
-
"",
|
|
283
|
-
"## Roles",
|
|
284
|
-
"",
|
|
285
|
-
"| Role | Mode | Allowed scopes | Verification commands |",
|
|
286
|
-
"| --- | --- | --- | --- |",
|
|
287
|
-
];
|
|
288
|
-
for (const role of exp.roles) {
|
|
289
|
-
const mode = role.can_write ? "write" : "read-only";
|
|
290
|
-
lines.push(
|
|
291
|
-
`| ${role.role} | ${mode} | ${role.allowed_file_scopes.length} | ${role.verification_commands.length} |`
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
lines.push("");
|
|
295
|
-
lines.push("## How to use");
|
|
296
|
-
lines.push("");
|
|
297
|
-
lines.push("Review each `<ROLE>.goal.txt`, then paste it into the chosen runtime yourself.");
|
|
298
|
-
lines.push("Nothing here runs an agent; Sleep execution is not available in this phase.");
|
|
299
|
-
lines.push("");
|
|
300
|
-
lines.push("## Boundary");
|
|
301
|
-
lines.push("");
|
|
302
|
-
lines.push(exp.boundary_line);
|
|
303
|
-
lines.push("");
|
|
304
|
-
return lines.join("\n");
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function tomlEscape(value) {
|
|
308
|
-
return String(value).replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// Documented Codex custom-agent sandbox_mode value (advisory only).
|
|
312
|
-
function sandboxModeAdvisory(canWrite) {
|
|
313
|
-
return canWrite ? "workspace-write" : "read-only";
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// Review draft of a Codex custom-agent TOML matching the documented custom-agent
|
|
317
|
-
// shape. Minimum fields: name, description, developer_instructions. Advisory
|
|
318
|
-
// fields use the documented Codex field names (model, model_reasoning_effort,
|
|
319
|
-
// sandbox_mode) and stay commented/non-binding. This is a `.preview` review
|
|
320
|
-
// draft — BK-262 does NOT write .codex/agents/**.
|
|
321
|
-
function renderCodexTomlPreview(exp, role) {
|
|
322
|
-
const name = `${exp.feature_key.toLowerCase()}-${role.role}`;
|
|
323
|
-
const description = `${role.role} role for ${exp.feature_key} (${role.can_write ? "writer" : "read-only"}) — SDTK agent-team export review draft.`;
|
|
324
|
-
return [
|
|
325
|
-
"# REVIEW DRAFT — Codex custom-agent preview. NOT an installed runtime file.",
|
|
326
|
-
`# ${exp.boundary_line}`,
|
|
327
|
-
"",
|
|
328
|
-
`name = "${tomlEscape(name)}"`,
|
|
329
|
-
`description = "${tomlEscape(description)}"`,
|
|
330
|
-
'developer_instructions = """',
|
|
331
|
-
role.goal_text,
|
|
332
|
-
'"""',
|
|
333
|
-
"",
|
|
334
|
-
"# Advisory only (non-binding; documented Codex custom-agent fields; edit before any use):",
|
|
335
|
-
`# model = "${tomlEscape(role.model_suggestion)}"`,
|
|
336
|
-
`# model_reasoning_effort = "${tomlEscape(role.reasoning_suggestion)}"`,
|
|
337
|
-
`# sandbox_mode = "${tomlEscape(sandboxModeAdvisory(role.can_write))}"`,
|
|
338
|
-
"",
|
|
339
|
-
].join("\n");
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// --- G3: writer (fs, bounded to exports/**) ----------------------------------
|
|
343
|
-
|
|
344
|
-
function exportDir(projectPath, exp) {
|
|
345
|
-
const resolved = path.resolve(projectPath || ".");
|
|
346
|
-
// Defense in depth: re-validate segments at path-build time.
|
|
347
|
-
safeSegment(exp.runtime, "runtime");
|
|
348
|
-
safeSegment(exp.feature_key, "feature_key");
|
|
349
|
-
return path.join(resolved, ".sdtk", "agent-team", "exports", exp.runtime, exp.feature_key);
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
// Writes the bundle only under .sdtk/agent-team/exports/<runtime>/<KEY>/.
|
|
353
|
-
// Returns absolute paths written.
|
|
354
|
-
function writeExportBundle(projectPath, exp) {
|
|
355
|
-
const dir = exportDir(projectPath, exp);
|
|
356
|
-
const base = path.resolve(dir);
|
|
357
|
-
|
|
358
|
-
// After computing every output path, assert it stays under the export dir.
|
|
359
|
-
const safePath = (segment) => {
|
|
360
|
-
safeSegment(segment, "output filename");
|
|
361
|
-
const resolved = path.resolve(path.join(base, segment));
|
|
362
|
-
if (resolved !== base && !resolved.startsWith(base + path.sep)) {
|
|
363
|
-
throw new ValidationError(
|
|
364
|
-
`FAIL_UNSAFE_EXPORT_PATH: resolved path "${resolved}" escapes export dir "${base}".`
|
|
365
|
-
);
|
|
366
|
-
}
|
|
367
|
-
return resolved;
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
371
|
-
const written = [];
|
|
372
|
-
|
|
373
|
-
for (const role of exp.roles) {
|
|
374
|
-
const goalPath = safePath(`${role.role.toUpperCase()}.goal.txt`);
|
|
375
|
-
fs.writeFileSync(goalPath, role.goal_text, "utf8");
|
|
376
|
-
written.push(goalPath);
|
|
377
|
-
|
|
378
|
-
// Codex only: review-draft TOML. Claude stays generic (D1) — no toml.preview.
|
|
379
|
-
if (exp.runtime === "codex") {
|
|
380
|
-
const tomlPath = safePath(`${role.role.toUpperCase()}.toml.preview`);
|
|
381
|
-
fs.writeFileSync(tomlPath, renderCodexTomlPreview(exp, role), "utf8");
|
|
382
|
-
written.push(tomlPath);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
const metaPath = safePath("adapter-metadata.json");
|
|
387
|
-
fs.writeFileSync(metaPath, JSON.stringify(renderAdapterMetadata(exp), null, 2), "utf8");
|
|
388
|
-
written.push(metaPath);
|
|
389
|
-
|
|
390
|
-
const briefPath = safePath("RUN_BRIEF.md");
|
|
391
|
-
fs.writeFileSync(briefPath, renderRunBrief(exp), "utf8");
|
|
392
|
-
written.push(briefPath);
|
|
393
|
-
|
|
394
|
-
return written;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
module.exports = {
|
|
398
|
-
EXPORT_SCHEMA,
|
|
399
|
-
EXPORT_RUNTIMES,
|
|
400
|
-
GOAL_PROMPT_MAX,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// BK-262 Phase B — Agent Team Runtime Adapter Exports.
|
|
4
|
+
//
|
|
5
|
+
// Turns a validated BK-260 agent-team plan into runtime-specific export bundles
|
|
6
|
+
// (per-role prompts + metadata + brief + optional codex review-draft TOML) so a
|
|
7
|
+
// human (or a runtime the human chooses to act on) spends less time hand-writing
|
|
8
|
+
// prompts/assignments and gets consistent scope + evidence requirements.
|
|
9
|
+
//
|
|
10
|
+
// EXPORT/PACKAGING ONLY. This module:
|
|
11
|
+
// - does NOT execute agents, spawn processes, or schedule anything,
|
|
12
|
+
// - does NOT write .codex/agents/**, .claude/**, or any global/user config,
|
|
13
|
+
// - writes only under <project>/.sdtk/agent-team/exports/**,
|
|
14
|
+
// - is not a local LLM runtime and is not Sleep execution.
|
|
15
|
+
|
|
16
|
+
const fs = require("fs");
|
|
17
|
+
const path = require("path");
|
|
18
|
+
const { ValidationError } = require("./errors");
|
|
19
|
+
const {
|
|
20
|
+
loadAgentTeamPlan,
|
|
21
|
+
projectAgentTeamPreview,
|
|
22
|
+
stopConditionIds,
|
|
23
|
+
BOUNDARY_LINE,
|
|
24
|
+
} = require("./agent-team-plan");
|
|
25
|
+
|
|
26
|
+
const EXPORT_SCHEMA = "sdtk.agent-team-export.v1";
|
|
27
|
+
// Mirrors commands/runtime.js VALID_RUNTIMES. `--runtime` selects the export
|
|
28
|
+
// target format the human will hand the bundle to; it is not a per-role spawn.
|
|
29
|
+
const EXPORT_RUNTIMES = Object.freeze(["codex", "claude"]);
|
|
30
|
+
const GOAL_PROMPT_MAX = 4000;
|
|
31
|
+
|
|
32
|
+
// Phrases that would overclaim execution. The verbatim BOUNDARY_LINE deliberately
|
|
33
|
+
// contains "execute" ("does not execute agents"), so the guard targets specific
|
|
34
|
+
// auto-run claims rather than the bare word.
|
|
35
|
+
const OVERCLAIM_PHRASES = Object.freeze([
|
|
36
|
+
"auto-spawn",
|
|
37
|
+
"automatically spawn",
|
|
38
|
+
"automatically run",
|
|
39
|
+
"automatically execute",
|
|
40
|
+
"will execute the",
|
|
41
|
+
"will spawn",
|
|
42
|
+
"will deploy",
|
|
43
|
+
"will publish",
|
|
44
|
+
"spawns subagents automatically",
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
// Safe single path segment: filename-friendly, no separators, no traversal.
|
|
48
|
+
const SAFE_SEGMENT = /^[A-Za-z0-9._-]+$/;
|
|
49
|
+
|
|
50
|
+
function safeSegment(value, label) {
|
|
51
|
+
const segment = String(value);
|
|
52
|
+
if (
|
|
53
|
+
segment.length === 0 ||
|
|
54
|
+
segment === "." ||
|
|
55
|
+
segment === ".." ||
|
|
56
|
+
segment.includes("/") ||
|
|
57
|
+
segment.includes("\\") ||
|
|
58
|
+
segment.includes("\0") ||
|
|
59
|
+
!SAFE_SEGMENT.test(segment)
|
|
60
|
+
) {
|
|
61
|
+
throw new ValidationError(
|
|
62
|
+
`FAIL_UNSAFE_EXPORT_PATH: ${label} "${segment}" is not a safe path segment (no separators or "."/"..").`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return segment;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function asArray(value) {
|
|
69
|
+
return Array.isArray(value) ? value : [];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function roleName(role) {
|
|
73
|
+
return role && typeof role.role === "string" && role.role.length > 0 ? role.role : "unnamed";
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function roleFileBase(role) {
|
|
77
|
+
return roleName(role).toUpperCase();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// --- D3: static, advisory, non-binding suggestions ---------------------------
|
|
81
|
+
// Never a mandated model. Higher reasoning is suggested for review/scope roles.
|
|
82
|
+
function modelSuggestion() {
|
|
83
|
+
return "runtime_default";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const HIGH_REASONING_ROLES = new Set(["pm", "qa", "arch", "architect", "review", "reviewer"]);
|
|
87
|
+
|
|
88
|
+
function reasoningSuggestion(role) {
|
|
89
|
+
return HIGH_REASONING_ROLES.has(roleName(role)) ? "high" : "medium";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function sandboxExpectation(canWrite) {
|
|
93
|
+
return canWrite
|
|
94
|
+
? "workspace-write (review the allowed scope before granting write)"
|
|
95
|
+
: "read-only";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function bulletList(items, fallback) {
|
|
99
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
100
|
+
return `- ${fallback}`;
|
|
101
|
+
}
|
|
102
|
+
return items.map((item) => `- ${String(item)}`).join("\n");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// --- G2: renderers -----------------------------------------------------------
|
|
106
|
+
|
|
107
|
+
// Bounded, copy-pasteable prompt per role (Codex `/goal` style; Claude reads the
|
|
108
|
+
// same generic packet). Kept compact so it stays < GOAL_PROMPT_MAX.
|
|
109
|
+
function renderGoalText(plan, role, runtime) {
|
|
110
|
+
const stops = asArray(plan.stop_conditions).length > 0 ? asArray(plan.stop_conditions) : stopConditionIds();
|
|
111
|
+
return [
|
|
112
|
+
`# Agent goal — ${plan.feature_key} / ${roleName(role)} (${runtime} export)`,
|
|
113
|
+
"",
|
|
114
|
+
BOUNDARY_LINE,
|
|
115
|
+
"",
|
|
116
|
+
`Role: ${roleName(role)}`,
|
|
117
|
+
`Can write: ${role.can_write ? "yes" : "no (read-only)"}`,
|
|
118
|
+
`Run id: ${plan.run_id}`,
|
|
119
|
+
"",
|
|
120
|
+
"## Objective",
|
|
121
|
+
String(role.objective || "(none declared)"),
|
|
122
|
+
"",
|
|
123
|
+
"## Allowed file scopes (do not write outside these)",
|
|
124
|
+
bulletList(role.allowed_file_scopes, "none (read-only role)"),
|
|
125
|
+
"",
|
|
126
|
+
"## Blocked file scopes (never touch)",
|
|
127
|
+
bulletList(role.blocked_file_scopes, "none declared"),
|
|
128
|
+
"",
|
|
129
|
+
"## Verification commands (run and capture evidence)",
|
|
130
|
+
bulletList(role.verification_commands, "none"),
|
|
131
|
+
"",
|
|
132
|
+
"## Evidence required",
|
|
133
|
+
bulletList(role.evidence_required, "none"),
|
|
134
|
+
"",
|
|
135
|
+
"## Stop conditions (stop and report at any of these)",
|
|
136
|
+
bulletList(stops, "none declared"),
|
|
137
|
+
"",
|
|
138
|
+
"## Boundary",
|
|
139
|
+
"Stay within the allowed scope. Do not spawn processes, publish packages, or deploy.",
|
|
140
|
+
"Ask for parallel subagents only if the plan implies parallel roles; never assume the runtime creates them on its own.",
|
|
141
|
+
BOUNDARY_LINE,
|
|
142
|
+
"",
|
|
143
|
+
].join("\n");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function projectRole(plan, role, runtime) {
|
|
147
|
+
const goalText = renderGoalText(plan, role, runtime);
|
|
148
|
+
return {
|
|
149
|
+
role: roleName(role),
|
|
150
|
+
runtime_target: runtime,
|
|
151
|
+
can_write: role.can_write === true,
|
|
152
|
+
allowed_file_scopes: asArray(role.allowed_file_scopes),
|
|
153
|
+
blocked_file_scopes: asArray(role.blocked_file_scopes),
|
|
154
|
+
verification_commands: asArray(role.verification_commands),
|
|
155
|
+
evidence_required: asArray(role.evidence_required),
|
|
156
|
+
stop_conditions: asArray(plan.stop_conditions).length > 0 ? asArray(plan.stop_conditions) : stopConditionIds(),
|
|
157
|
+
model_suggestion: modelSuggestion(),
|
|
158
|
+
reasoning_suggestion: reasoningSuggestion(role),
|
|
159
|
+
sandbox_expectation: sandboxExpectation(role.can_write === true),
|
|
160
|
+
goal_text: goalText,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// --- G1: projection (pure, no fs) --------------------------------------------
|
|
165
|
+
|
|
166
|
+
// Pure projection from an already-validated plan to a runtime export bundle.
|
|
167
|
+
// Fail-closed: reuses the BK-260 preview validation, enforces /goal length and
|
|
168
|
+
// the no-overclaim guard. No fs, no spawn.
|
|
169
|
+
function projectExport(plan, runtime) {
|
|
170
|
+
if (!EXPORT_RUNTIMES.includes(runtime)) {
|
|
171
|
+
throw new ValidationError(
|
|
172
|
+
`Invalid value for --runtime: "${runtime}". Must be one of: ${EXPORT_RUNTIMES.join(", ")}`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// Reuse BK-260 validation — do not re-derive a parallel validator.
|
|
177
|
+
const preview = projectAgentTeamPreview(plan, null);
|
|
178
|
+
if (preview.verdict !== "PASS_AGENT_TEAM_PREVIEW_READY") {
|
|
179
|
+
throw new ValidationError(
|
|
180
|
+
`NEEDS_AGENT_TEAM_PLAN: plan is not export-ready — ${preview.blockers.join("; ")}`
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Path-segment safety: a hand-edited plan must not escape the export dir via
|
|
185
|
+
// feature_key or a role name like "../PWN". Fail closed before any write.
|
|
186
|
+
safeSegment(plan.feature_key, "feature_key");
|
|
187
|
+
for (const role of asArray(plan.roles)) {
|
|
188
|
+
if (role && typeof role === "object") {
|
|
189
|
+
safeSegment(roleName(role), "role");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const roles = asArray(plan.roles)
|
|
194
|
+
.filter((role) => role && typeof role === "object")
|
|
195
|
+
.map((role) => projectRole(plan, role, runtime));
|
|
196
|
+
|
|
197
|
+
// /goal length guard.
|
|
198
|
+
for (const role of roles) {
|
|
199
|
+
if (role.goal_text.length >= GOAL_PROMPT_MAX) {
|
|
200
|
+
throw new ValidationError(
|
|
201
|
+
`FAIL_GOAL_PROMPT_TOO_LONG: ${role.role} goal prompt is ${role.goal_text.length} chars (max ${GOAL_PROMPT_MAX}). Link to the plan JSON instead of inlining.`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// No-overclaim guard + boundary presence.
|
|
207
|
+
for (const role of roles) {
|
|
208
|
+
const lowered = role.goal_text.toLowerCase();
|
|
209
|
+
for (const phrase of OVERCLAIM_PHRASES) {
|
|
210
|
+
if (lowered.includes(phrase)) {
|
|
211
|
+
throw new ValidationError(
|
|
212
|
+
`FAIL_RUNTIME_OVERCLAIM: ${role.role} export text implies execution ("${phrase}"). Export is preview-only.`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!role.goal_text.includes(BOUNDARY_LINE)) {
|
|
217
|
+
throw new ValidationError(
|
|
218
|
+
`FAIL_RUNTIME_OVERCLAIM: ${role.role} export text is missing the export-only boundary line.`
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Exactly one writer carried through (preview already guarantees this; assert).
|
|
224
|
+
const writers = roles.filter((role) => role.can_write === true);
|
|
225
|
+
if (writers.length !== 1) {
|
|
226
|
+
throw new ValidationError(
|
|
227
|
+
`FAIL_RUNTIME_OVERCLAIM: export must carry exactly one writer role, found ${writers.length}.`
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
schema_version: EXPORT_SCHEMA,
|
|
233
|
+
feature_key: plan.feature_key,
|
|
234
|
+
run_id: plan.run_id,
|
|
235
|
+
runtime,
|
|
236
|
+
boundary_line: BOUNDARY_LINE,
|
|
237
|
+
generated_at: new Date().toISOString(),
|
|
238
|
+
roles,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function renderAdapterMetadata(exp) {
|
|
243
|
+
return {
|
|
244
|
+
schema_version: exp.schema_version,
|
|
245
|
+
feature_key: exp.feature_key,
|
|
246
|
+
run_id: exp.run_id,
|
|
247
|
+
runtime: exp.runtime,
|
|
248
|
+
boundary_line: exp.boundary_line,
|
|
249
|
+
generated_at: exp.generated_at,
|
|
250
|
+
roles: exp.roles.map((role) => ({
|
|
251
|
+
role: role.role,
|
|
252
|
+
runtime_target: role.runtime_target,
|
|
253
|
+
can_write: role.can_write,
|
|
254
|
+
allowed_file_scopes: role.allowed_file_scopes,
|
|
255
|
+
blocked_file_scopes: role.blocked_file_scopes,
|
|
256
|
+
verification_commands: role.verification_commands,
|
|
257
|
+
evidence_required: role.evidence_required,
|
|
258
|
+
stop_conditions: role.stop_conditions,
|
|
259
|
+
model_suggestion: role.model_suggestion,
|
|
260
|
+
reasoning_suggestion: role.reasoning_suggestion,
|
|
261
|
+
sandbox_expectation: role.sandbox_expectation,
|
|
262
|
+
})),
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Human overview per runtime (D4). Overview-only; adds no authority over the
|
|
267
|
+
// per-role files or metadata.
|
|
268
|
+
function renderRunBrief(exp) {
|
|
269
|
+
const writer = exp.roles.find((role) => role.can_write === true);
|
|
270
|
+
const tomlNote = exp.runtime === "codex"
|
|
271
|
+
? " + `<ROLE>.toml.preview` (review draft, not installed)"
|
|
272
|
+
: "";
|
|
273
|
+
const lines = [
|
|
274
|
+
`# Agent Team Run Brief — ${exp.feature_key} (${exp.runtime})`,
|
|
275
|
+
"",
|
|
276
|
+
exp.boundary_line,
|
|
277
|
+
"",
|
|
278
|
+
`- Run id: ${exp.run_id}`,
|
|
279
|
+
`- Runtime target: ${exp.runtime}`,
|
|
280
|
+
`- Writer role: ${writer ? writer.role : "(none)"}`,
|
|
281
|
+
`- Per-role files: \`<ROLE>.goal.txt\` + \`adapter-metadata.json\` + this brief${tomlNote}`,
|
|
282
|
+
"",
|
|
283
|
+
"## Roles",
|
|
284
|
+
"",
|
|
285
|
+
"| Role | Mode | Allowed scopes | Verification commands |",
|
|
286
|
+
"| --- | --- | --- | --- |",
|
|
287
|
+
];
|
|
288
|
+
for (const role of exp.roles) {
|
|
289
|
+
const mode = role.can_write ? "write" : "read-only";
|
|
290
|
+
lines.push(
|
|
291
|
+
`| ${role.role} | ${mode} | ${role.allowed_file_scopes.length} | ${role.verification_commands.length} |`
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
lines.push("");
|
|
295
|
+
lines.push("## How to use");
|
|
296
|
+
lines.push("");
|
|
297
|
+
lines.push("Review each `<ROLE>.goal.txt`, then paste it into the chosen runtime yourself.");
|
|
298
|
+
lines.push("Nothing here runs an agent; Sleep execution is not available in this phase.");
|
|
299
|
+
lines.push("");
|
|
300
|
+
lines.push("## Boundary");
|
|
301
|
+
lines.push("");
|
|
302
|
+
lines.push(exp.boundary_line);
|
|
303
|
+
lines.push("");
|
|
304
|
+
return lines.join("\n");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function tomlEscape(value) {
|
|
308
|
+
return String(value).replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Documented Codex custom-agent sandbox_mode value (advisory only).
|
|
312
|
+
function sandboxModeAdvisory(canWrite) {
|
|
313
|
+
return canWrite ? "workspace-write" : "read-only";
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Review draft of a Codex custom-agent TOML matching the documented custom-agent
|
|
317
|
+
// shape. Minimum fields: name, description, developer_instructions. Advisory
|
|
318
|
+
// fields use the documented Codex field names (model, model_reasoning_effort,
|
|
319
|
+
// sandbox_mode) and stay commented/non-binding. This is a `.preview` review
|
|
320
|
+
// draft — BK-262 does NOT write .codex/agents/**.
|
|
321
|
+
function renderCodexTomlPreview(exp, role) {
|
|
322
|
+
const name = `${exp.feature_key.toLowerCase()}-${role.role}`;
|
|
323
|
+
const description = `${role.role} role for ${exp.feature_key} (${role.can_write ? "writer" : "read-only"}) — SDTK agent-team export review draft.`;
|
|
324
|
+
return [
|
|
325
|
+
"# REVIEW DRAFT — Codex custom-agent preview. NOT an installed runtime file.",
|
|
326
|
+
`# ${exp.boundary_line}`,
|
|
327
|
+
"",
|
|
328
|
+
`name = "${tomlEscape(name)}"`,
|
|
329
|
+
`description = "${tomlEscape(description)}"`,
|
|
330
|
+
'developer_instructions = """',
|
|
331
|
+
role.goal_text,
|
|
332
|
+
'"""',
|
|
333
|
+
"",
|
|
334
|
+
"# Advisory only (non-binding; documented Codex custom-agent fields; edit before any use):",
|
|
335
|
+
`# model = "${tomlEscape(role.model_suggestion)}"`,
|
|
336
|
+
`# model_reasoning_effort = "${tomlEscape(role.reasoning_suggestion)}"`,
|
|
337
|
+
`# sandbox_mode = "${tomlEscape(sandboxModeAdvisory(role.can_write))}"`,
|
|
338
|
+
"",
|
|
339
|
+
].join("\n");
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// --- G3: writer (fs, bounded to exports/**) ----------------------------------
|
|
343
|
+
|
|
344
|
+
function exportDir(projectPath, exp) {
|
|
345
|
+
const resolved = path.resolve(projectPath || ".");
|
|
346
|
+
// Defense in depth: re-validate segments at path-build time.
|
|
347
|
+
safeSegment(exp.runtime, "runtime");
|
|
348
|
+
safeSegment(exp.feature_key, "feature_key");
|
|
349
|
+
return path.join(resolved, ".sdtk", "agent-team", "exports", exp.runtime, exp.feature_key);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// Writes the bundle only under .sdtk/agent-team/exports/<runtime>/<KEY>/.
|
|
353
|
+
// Returns absolute paths written.
|
|
354
|
+
function writeExportBundle(projectPath, exp) {
|
|
355
|
+
const dir = exportDir(projectPath, exp);
|
|
356
|
+
const base = path.resolve(dir);
|
|
357
|
+
|
|
358
|
+
// After computing every output path, assert it stays under the export dir.
|
|
359
|
+
const safePath = (segment) => {
|
|
360
|
+
safeSegment(segment, "output filename");
|
|
361
|
+
const resolved = path.resolve(path.join(base, segment));
|
|
362
|
+
if (resolved !== base && !resolved.startsWith(base + path.sep)) {
|
|
363
|
+
throw new ValidationError(
|
|
364
|
+
`FAIL_UNSAFE_EXPORT_PATH: resolved path "${resolved}" escapes export dir "${base}".`
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
return resolved;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
371
|
+
const written = [];
|
|
372
|
+
|
|
373
|
+
for (const role of exp.roles) {
|
|
374
|
+
const goalPath = safePath(`${role.role.toUpperCase()}.goal.txt`);
|
|
375
|
+
fs.writeFileSync(goalPath, role.goal_text, "utf8");
|
|
376
|
+
written.push(goalPath);
|
|
377
|
+
|
|
378
|
+
// Codex only: review-draft TOML. Claude stays generic (D1) — no toml.preview.
|
|
379
|
+
if (exp.runtime === "codex") {
|
|
380
|
+
const tomlPath = safePath(`${role.role.toUpperCase()}.toml.preview`);
|
|
381
|
+
fs.writeFileSync(tomlPath, renderCodexTomlPreview(exp, role), "utf8");
|
|
382
|
+
written.push(tomlPath);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const metaPath = safePath("adapter-metadata.json");
|
|
387
|
+
fs.writeFileSync(metaPath, JSON.stringify(renderAdapterMetadata(exp), null, 2), "utf8");
|
|
388
|
+
written.push(metaPath);
|
|
389
|
+
|
|
390
|
+
const briefPath = safePath("RUN_BRIEF.md");
|
|
391
|
+
fs.writeFileSync(briefPath, renderRunBrief(exp), "utf8");
|
|
392
|
+
written.push(briefPath);
|
|
393
|
+
|
|
394
|
+
return written;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
module.exports = {
|
|
398
|
+
EXPORT_SCHEMA,
|
|
399
|
+
EXPORT_RUNTIMES,
|
|
400
|
+
GOAL_PROMPT_MAX,
|
|
401
|
+
SAFE_SEGMENT,
|
|
402
|
+
safeSegment,
|
|
403
|
+
projectExport,
|
|
404
|
+
renderGoalText,
|
|
405
|
+
renderAdapterMetadata,
|
|
406
|
+
renderRunBrief,
|
|
407
|
+
renderCodexTomlPreview,
|
|
408
|
+
exportDir,
|
|
409
|
+
writeExportBundle,
|
|
410
|
+
loadAgentTeamPlan,
|
|
411
|
+
};
|