harness-engineer 0.1.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.
@@ -0,0 +1,2344 @@
1
+ import { dedent, escapeTomlString, joinPath, relativePathList, renderTomlArray } from "./utils.js";
2
+ const genericPaths = {
3
+ docsRoot: "docs",
4
+ sourceOfTruthDir: "docs/source-of-truth",
5
+ runbooksDir: "docs/runbooks",
6
+ plansActiveDir: "docs/plans/active",
7
+ plansCompletedDir: "docs/plans/completed",
8
+ logsActiveDir: "logs/codex/active",
9
+ logsCompletedDir: "logs/codex/completed",
10
+ codexDir: ".codex",
11
+ codexAgentsDir: ".codex/agents",
12
+ codexMemoryDir: ".codex/memory",
13
+ codexEnvironmentFile: ".codex/environments/environment.toml",
14
+ };
15
+ const agentAdminPaths = {
16
+ ...genericPaths,
17
+ sourceOfTruthDir: "dev-docs",
18
+ };
19
+ const genericTruthSources = [
20
+ {
21
+ key: "source-of-truth-index",
22
+ path: "docs/source-of-truth/README.md",
23
+ title: "Source Of Truth Index",
24
+ summary: "Describes how the repository stores product, architecture, and delivery truths.",
25
+ },
26
+ {
27
+ key: "project-overview",
28
+ path: "docs/source-of-truth/project-overview.md",
29
+ title: "Project Overview",
30
+ summary: "Captures product goals, users, constraints, and non-goals.",
31
+ },
32
+ {
33
+ key: "system-overview",
34
+ path: "docs/source-of-truth/system-overview.md",
35
+ title: "System Overview",
36
+ summary: "Documents the high-level architecture, boundaries, and main flows.",
37
+ },
38
+ {
39
+ key: "backend-architecture",
40
+ path: "docs/source-of-truth/backend-architecture.md",
41
+ title: "Backend Architecture",
42
+ summary: "Defines backend module ownership, contracts, and implementation boundaries.",
43
+ },
44
+ {
45
+ key: "frontend-architecture",
46
+ path: "docs/source-of-truth/frontend-architecture.md",
47
+ title: "Frontend Architecture",
48
+ summary: "Defines route ownership, UI layering, and interaction boundaries.",
49
+ },
50
+ {
51
+ key: "api-specification",
52
+ path: "docs/source-of-truth/api-specification.md",
53
+ title: "API Specification",
54
+ summary: "Describes API contracts, request and response shapes, and compatibility expectations.",
55
+ },
56
+ {
57
+ key: "integration-and-acceptance",
58
+ path: "docs/source-of-truth/integration-and-acceptance.md",
59
+ title: "Integration And Acceptance",
60
+ summary: "Tracks integration rules, validation evidence, and release readiness expectations.",
61
+ },
62
+ {
63
+ key: "quality-gates",
64
+ path: "docs/source-of-truth/quality-gates.md",
65
+ title: "Quality Gates",
66
+ summary: "Defines the minimum verification bar for shipping changes.",
67
+ },
68
+ ];
69
+ const agentAdminTruthSources = [
70
+ { key: "document-system-index", path: "dev-docs/00-document-system-index.md", title: "Document System Index", summary: "Owns the documentation system, reading order, and truth-source rules." },
71
+ { key: "project-overview", path: "dev-docs/01-project-overview.md", title: "Project Overview", summary: "Defines product positioning, users, MVP boundaries, and non-goals." },
72
+ { key: "system-overview", path: "dev-docs/02-system-overview.md", title: "System Overview", summary: "Defines modular-monolith boundaries and control-plane vs exec-plane ownership." },
73
+ { key: "backend-development-architecture", path: "dev-docs/03-backend-development-architecture.md", title: "Backend Development Architecture", summary: "Defines backend modules, control-plane responsibilities, and implementation sequencing." },
74
+ { key: "frontend-development-architecture", path: "dev-docs/04-frontend-development-architecture.md", title: "Frontend Development Architecture", summary: "Defines console routes, frontend layering, permissions, and SSE integration rules." },
75
+ { key: "api-specification", path: "dev-docs/05-api-specification.md", title: "API Specification", summary: "Defines REST, SSE, pagination, and contract rules." },
76
+ { key: "data-model-specification", path: "dev-docs/06-data-model-specification.md", title: "Data Model Specification", summary: "Defines entities, tables, JSON payload fields, and hot-vs-cold data placement." },
77
+ { key: "enum-state-definitions", path: "dev-docs/07-enum-and-state-definitions.md", title: "Enum And State Definitions", summary: "Defines enums, statuses, and state-machine rules." },
78
+ { key: "error-code-specification", path: "dev-docs/08-error-code-specification.md", title: "Error Code Specification", summary: "Defines platform error codes and their semantics." },
79
+ { key: "common-fields-and-naming", path: "dev-docs/09-common-fields-and-naming.md", title: "Common Fields And Naming", summary: "Defines naming, shared fields, and path rules." },
80
+ { key: "frontend-backend-collaboration", path: "dev-docs/10-frontend-backend-collaboration.md", title: "Frontend Backend Collaboration", summary: "Defines collaboration rules between frontend and backend teams." },
81
+ { key: "integration-and-acceptance", path: "dev-docs/11-integration-and-acceptance.md", title: "Integration And Acceptance", summary: "Defines integration and acceptance evidence requirements." },
82
+ { key: "development-plan", path: "dev-docs/12-development-plan.md", title: "Development Plan", summary: "Documents the phased development plan." },
83
+ { key: "pre-development-checklist", path: "dev-docs/13-pre-development-checklist.md", title: "Pre-Development Checklist", summary: "Lists the minimum checks before feature work begins." },
84
+ { key: "tool-development-plan", path: "dev-docs/14-tool-development-plan.md", title: "Tool Development Plan", summary: "Documents tool-related implementation priorities." },
85
+ { key: "backend-architecture-spec", path: "spec/backend-architecture.md", title: "Backend Architecture Spec", summary: "Provides detailed runtime, control-plane, and module design." },
86
+ { key: "frontend-architecture-spec", path: "spec/frontend-architecture.md", title: "Frontend Architecture Spec", summary: "Provides detailed console structure and UI patterns." },
87
+ { key: "deep-research-report", path: "spec/deep-research-report.md", title: "Deep Research Report", summary: "Captures market and product rationale." },
88
+ { key: "executor-protocol", path: "spec/executor-protocol.md", title: "Executor Protocol", summary: "Defines register, heartbeat, and invoke protocol behavior." },
89
+ { key: "quality-gates", path: "spec/quality-gates.md", title: "Quality Gates", summary: "Defines critical validation rules." },
90
+ { key: "run-stream-event-schema", path: "spec/run-stream-event-schema.md", title: "Run Stream Event Schema", summary: "Defines runtime streaming event contracts." },
91
+ { key: "session-auth-contract", path: "spec/session-auth-contract.md", title: "Session Auth Contract", summary: "Defines session, refresh, and permission version behavior." },
92
+ { key: "settings-secret-contract", path: "spec/settings-secret-contract.md", title: "Settings Secret Contract", summary: "Defines settings and secret behavior." },
93
+ { key: "jobs-retention-operations", path: "spec/jobs-retention-operations.md", title: "Jobs Retention Operations", summary: "Defines jobs and retention operational rules." },
94
+ ];
95
+ const genericRoles = [
96
+ {
97
+ key: "architect-backend",
98
+ name: "architect-backend",
99
+ purpose: "Own backend architecture, service boundaries, and contract-sensitive backend changes.",
100
+ model: "gpt-5.4",
101
+ reasoningEffort: "high",
102
+ memoryFile: ".codex/memory/backend.md",
103
+ runbookFile: "docs/runbooks/backend-agent.md",
104
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
105
+ readFirst: [
106
+ "docs/runbooks/backend-agent.md",
107
+ ".codex/memory/backend.md",
108
+ "docs/source-of-truth/system-overview.md",
109
+ "docs/source-of-truth/backend-architecture.md",
110
+ "docs/source-of-truth/api-specification.md",
111
+ ],
112
+ scope: [
113
+ "Backend services, modules, and contract ownership",
114
+ "API, data model, permission, audit, and governance boundaries",
115
+ "Implementation placement and backend change sequencing",
116
+ ],
117
+ doNot: [
118
+ "Do not redesign frontend information architecture",
119
+ "Do not weaken contract or permission guarantees without truth-source updates",
120
+ "Do not invent new runtime semantics without alignment",
121
+ ],
122
+ handoffRequired: [
123
+ "Touched backend modules and files",
124
+ "Contract, permission, audit, and state impact",
125
+ "Required truth-source updates",
126
+ "Recommended next role",
127
+ ],
128
+ defaultOutput: [
129
+ "Affected backend boundary",
130
+ "Implementation recommendation",
131
+ "Risk and validation notes",
132
+ ],
133
+ },
134
+ {
135
+ key: "architect-frontend",
136
+ name: "architect-frontend",
137
+ purpose: "Own information architecture, route placement, feature boundaries, and frontend contract consumption.",
138
+ model: "gpt-5.4",
139
+ reasoningEffort: "high",
140
+ memoryFile: ".codex/memory/frontend.md",
141
+ runbookFile: "docs/runbooks/frontend-agent.md",
142
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
143
+ readFirst: [
144
+ "docs/runbooks/frontend-agent.md",
145
+ ".codex/memory/frontend.md",
146
+ "docs/source-of-truth/system-overview.md",
147
+ "docs/source-of-truth/frontend-architecture.md",
148
+ "docs/source-of-truth/api-specification.md",
149
+ ],
150
+ scope: [
151
+ "Route ownership and information architecture",
152
+ "Feature, component, and adapter boundaries",
153
+ "Permission, tenant-context, and real-time interaction design",
154
+ ],
155
+ doNot: [
156
+ "Do not invent backend contract fields in UI code",
157
+ "Do not absorb concrete UI polish that belongs to product-ui",
158
+ "Do not turn the product into a chat-first or canvas-first experience",
159
+ ],
160
+ handoffRequired: [
161
+ "Touched routes, features, or adapters",
162
+ "Permission and real-time impact",
163
+ "Contract dependencies",
164
+ "Recommended next role",
165
+ ],
166
+ defaultOutput: [
167
+ "Affected frontend boundary",
168
+ "Architecture recommendation",
169
+ "Risk and validation notes",
170
+ ],
171
+ },
172
+ {
173
+ key: "runtime-integrations",
174
+ name: "runtime-integrations",
175
+ purpose: "Own runtime orchestration, integrations, tool binding, and operational safety boundaries.",
176
+ model: "gpt-5.4",
177
+ reasoningEffort: "high",
178
+ memoryFile: ".codex/memory/runtime.md",
179
+ runbookFile: "docs/runbooks/runtime-agent.md",
180
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
181
+ readFirst: [
182
+ "docs/runbooks/runtime-agent.md",
183
+ ".codex/memory/runtime.md",
184
+ "docs/source-of-truth/system-overview.md",
185
+ "docs/source-of-truth/backend-architecture.md",
186
+ "docs/source-of-truth/api-specification.md",
187
+ ],
188
+ scope: [
189
+ "Runtime orchestration and integration flows",
190
+ "Safety, protocol, and event boundaries",
191
+ "Tool binding and operational reliability",
192
+ ],
193
+ doNot: [
194
+ "Do not move governance responsibility into integration endpoints",
195
+ "Do not weaken preview vs formal safety rules without truth-source updates",
196
+ "Do not redefine UI flows that belong to frontend roles",
197
+ ],
198
+ handoffRequired: [
199
+ "Touched runtime or integration files",
200
+ "Protocol, event, and security impact",
201
+ "Required truth-source updates",
202
+ "Recommended next role",
203
+ ],
204
+ defaultOutput: [
205
+ "Affected runtime boundary",
206
+ "Protocol or implementation recommendation",
207
+ "Risk and validation notes",
208
+ ],
209
+ },
210
+ {
211
+ key: "product-ui",
212
+ name: "product-ui",
213
+ purpose: "Own concrete product pages, components, forms, tables, and detail views within approved frontend architecture.",
214
+ model: "gpt-5.4",
215
+ reasoningEffort: "medium",
216
+ memoryFile: ".codex/memory/frontend.md",
217
+ runbookFile: "docs/runbooks/frontend-agent.md",
218
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
219
+ readFirst: [
220
+ "docs/runbooks/frontend-agent.md",
221
+ ".codex/memory/frontend.md",
222
+ "docs/source-of-truth/frontend-architecture.md",
223
+ ],
224
+ scope: [
225
+ "Pages and shared UI components",
226
+ "Forms, tables, details, timelines, and state feedback",
227
+ "Product UX polish inside approved architecture",
228
+ ],
229
+ doNot: [
230
+ "Do not redefine route ownership or contract semantics",
231
+ "Do not hardcode permission semantics in page components",
232
+ "Do not replace product UX with marketing layout patterns",
233
+ ],
234
+ handoffRequired: [
235
+ "Touched pages and components",
236
+ "UI state and flow changes",
237
+ "Dependent API or permission assumptions",
238
+ "Recommended next role",
239
+ ],
240
+ defaultOutput: [
241
+ "Affected page or component area",
242
+ "Implementation summary",
243
+ "Risk and validation notes",
244
+ ],
245
+ },
246
+ {
247
+ key: "reviewer",
248
+ name: "reviewer",
249
+ purpose: "Own correctness review, regression detection, boundary checks, and documentation drift detection.",
250
+ model: "gpt-5.4",
251
+ reasoningEffort: "high",
252
+ memoryFile: ".codex/memory/decisions.md",
253
+ runbookFile: "docs/runbooks/reviewer-agent.md",
254
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
255
+ readFirst: [
256
+ "docs/runbooks/reviewer-agent.md",
257
+ ".codex/memory/decisions.md",
258
+ "docs/index.md",
259
+ ],
260
+ scope: [
261
+ "Correctness and regression review",
262
+ "Boundary, contract, permission, and state checks",
263
+ "Missing validation or documentation updates",
264
+ ],
265
+ doNot: [
266
+ "Do not reduce review to style-only comments",
267
+ "Do not hide unverified high-risk paths",
268
+ "Do not expand the task into unsolicited refactors",
269
+ ],
270
+ handoffRequired: [
271
+ "Ordered findings with severity",
272
+ "Residual risk and testing gaps",
273
+ "Recommended next role",
274
+ ],
275
+ defaultOutput: [
276
+ "Findings first",
277
+ "Residual risk summary",
278
+ "Next-step recommendation",
279
+ ],
280
+ },
281
+ {
282
+ key: "qa-guard",
283
+ name: "qa-guard",
284
+ purpose: "Own validation closure, test matrix definition, quality-gate checks, and evidence of what was and was not verified.",
285
+ model: "gpt-5.4",
286
+ reasoningEffort: "medium",
287
+ memoryFile: ".codex/memory/decisions.md",
288
+ runbookFile: "docs/runbooks/qa-agent.md",
289
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
290
+ readFirst: [
291
+ "docs/runbooks/qa-agent.md",
292
+ ".codex/memory/decisions.md",
293
+ "docs/source-of-truth/integration-and-acceptance.md",
294
+ "docs/source-of-truth/quality-gates.md",
295
+ ],
296
+ scope: [
297
+ "Validation strategy and execution notes",
298
+ "Quality-gate checks",
299
+ "Explicit verified vs unverified reporting",
300
+ ],
301
+ doNot: [
302
+ "Do not claim tests passed when they were not run",
303
+ "Do not hide blocking gaps in critical flows",
304
+ "Do not replace reviewer correctness checks",
305
+ ],
306
+ handoffRequired: [
307
+ "Executed validations",
308
+ "Unexecuted validations",
309
+ "Blocking and non-blocking risks",
310
+ "Recommended next role",
311
+ ],
312
+ defaultOutput: [
313
+ "Validation matrix",
314
+ "Quality-gate status",
315
+ "Next-step recommendation",
316
+ ],
317
+ },
318
+ ];
319
+ const agentAdminRoles = [
320
+ {
321
+ key: "architect-backend",
322
+ name: "architect-backend",
323
+ purpose: "Own control-plane backend design, module boundaries, and contract-sensitive backend changes.",
324
+ model: "gpt-5.4",
325
+ reasoningEffort: "high",
326
+ memoryFile: ".codex/memory/backend.md",
327
+ runbookFile: "docs/runbooks/backend-agent.md",
328
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
329
+ readFirst: [
330
+ "docs/runbooks/backend-agent.md",
331
+ ".codex/memory/backend.md",
332
+ "dev-docs/02-system-overview.md",
333
+ "dev-docs/03-backend-development-architecture.md",
334
+ "spec/backend-architecture.md",
335
+ ],
336
+ scope: [
337
+ "Control Plane backend modules",
338
+ "API, data model, permission, audit, and governance boundaries",
339
+ "Backend module placement and implementation shape",
340
+ ],
341
+ doNot: [
342
+ "Do not redesign runtime internals that belong to Exec Plane",
343
+ "Do not invent new API or enum semantics without source-of-truth alignment",
344
+ "Do not expand into frontend UI work",
345
+ ],
346
+ handoffRequired: [
347
+ "Touched backend modules and files",
348
+ "Contract, tenant, permission, audit, and state-machine impact",
349
+ "Required document sync",
350
+ "Recommended next role",
351
+ ],
352
+ defaultOutput: [
353
+ "Affected backend boundary",
354
+ "Implementation recommendation",
355
+ "Risk and validation notes",
356
+ ],
357
+ },
358
+ {
359
+ key: "architect-frontend",
360
+ name: "architect-frontend",
361
+ purpose: "Own console information architecture, route placement, feature boundaries, and frontend contract consumption.",
362
+ model: "gpt-5.4",
363
+ reasoningEffort: "high",
364
+ memoryFile: ".codex/memory/frontend.md",
365
+ runbookFile: "docs/runbooks/frontend-agent.md",
366
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
367
+ readFirst: [
368
+ "docs/runbooks/frontend-agent.md",
369
+ ".codex/memory/frontend.md",
370
+ "dev-docs/02-system-overview.md",
371
+ "dev-docs/04-frontend-development-architecture.md",
372
+ "spec/frontend-architecture.md",
373
+ ],
374
+ scope: [
375
+ "Console route ownership",
376
+ "Feature, component, and API adapter boundaries",
377
+ "Permission, tenant-context, and SSE interaction design",
378
+ ],
379
+ doNot: [
380
+ "Do not turn the product into a chat-first or canvas-first UI",
381
+ "Do not invent contract fields outside the backend specification",
382
+ "Do not absorb detailed visual implementation work that belongs to console-ui",
383
+ ],
384
+ handoffRequired: [
385
+ "Touched routes, features, or API adapters",
386
+ "Permission and SSE impact",
387
+ "Contract dependencies",
388
+ "Recommended next role",
389
+ ],
390
+ defaultOutput: [
391
+ "Affected console boundary",
392
+ "Information-architecture recommendation",
393
+ "Risk and validation notes",
394
+ ],
395
+ },
396
+ {
397
+ key: "runtime-executor",
398
+ name: "runtime-executor",
399
+ purpose: "Own runtime orchestration, executor integration, tool binding, and run-chain protocol and safety boundaries.",
400
+ model: "gpt-5.4",
401
+ reasoningEffort: "high",
402
+ memoryFile: ".codex/memory/runtime.md",
403
+ runbookFile: "docs/runbooks/runtime-agent.md",
404
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
405
+ readFirst: [
406
+ "docs/runbooks/runtime-agent.md",
407
+ ".codex/memory/runtime.md",
408
+ "dev-docs/02-system-overview.md",
409
+ "dev-docs/03-backend-development-architecture.md",
410
+ "spec/backend-architecture.md",
411
+ "spec/executor-protocol.md",
412
+ "spec/run-stream-event-schema.md",
413
+ ],
414
+ scope: [
415
+ "Runtime orchestration flow",
416
+ "Executor protocol and safety rules",
417
+ "Tool binding and run event semantics",
418
+ ],
419
+ doNot: [
420
+ "Do not move governance responsibility from Control Plane into executors",
421
+ "Do not weaken preview/formal run safety boundaries",
422
+ "Do not change SSE or protocol semantics without source-of-truth updates",
423
+ ],
424
+ handoffRequired: [
425
+ "Touched runtime or executor files",
426
+ "Protocol, SSE, preview/formal, and security impact",
427
+ "Required document sync",
428
+ "Recommended next role",
429
+ ],
430
+ defaultOutput: [
431
+ "Affected runtime boundary",
432
+ "Protocol or implementation recommendation",
433
+ "Risk and validation notes",
434
+ ],
435
+ },
436
+ {
437
+ key: "console-ui",
438
+ name: "console-ui",
439
+ purpose: "Own concrete console page, component, table, form, and detail-view implementation inside approved frontend architecture.",
440
+ model: "gpt-5.4",
441
+ reasoningEffort: "medium",
442
+ memoryFile: ".codex/memory/frontend.md",
443
+ runbookFile: "docs/runbooks/frontend-agent.md",
444
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
445
+ readFirst: [
446
+ "docs/runbooks/frontend-agent.md",
447
+ ".codex/memory/frontend.md",
448
+ "dev-docs/04-frontend-development-architecture.md",
449
+ "spec/frontend-architecture.md",
450
+ ],
451
+ scope: [
452
+ "Console pages and components",
453
+ "Forms, tables, details, timelines, and state feedback",
454
+ "B-end console UI polish without breaking architecture",
455
+ ],
456
+ doNot: [
457
+ "Do not redefine route ownership or contract semantics without architect-frontend alignment",
458
+ "Do not turn governance pages into marketing or chat UI",
459
+ "Do not hardcode permission semantics in page components",
460
+ ],
461
+ handoffRequired: [
462
+ "Touched pages and components",
463
+ "UI states and flows changed",
464
+ "Dependent API or permission assumptions",
465
+ "Recommended next role",
466
+ ],
467
+ defaultOutput: [
468
+ "Affected page or component area",
469
+ "Implementation summary",
470
+ "Risk and validation notes",
471
+ ],
472
+ },
473
+ {
474
+ key: "reviewer",
475
+ name: "reviewer",
476
+ purpose: "Own correctness review, regression detection, boundary checks, and document drift detection.",
477
+ model: "gpt-5.4",
478
+ reasoningEffort: "high",
479
+ memoryFile: ".codex/memory/decisions.md",
480
+ runbookFile: "docs/runbooks/reviewer-agent.md",
481
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
482
+ readFirst: [
483
+ "docs/runbooks/reviewer-agent.md",
484
+ ".codex/memory/decisions.md",
485
+ "docs/index.md",
486
+ ],
487
+ scope: [
488
+ "Correctness and regression review",
489
+ "Boundary, contract, state, permission, and audit checks",
490
+ "Missing test or document updates",
491
+ ],
492
+ doNot: [
493
+ "Do not expand task scope into unsolicited refactors",
494
+ "Do not reduce review to style-only comments",
495
+ "Do not ignore unverified high-risk paths",
496
+ ],
497
+ handoffRequired: [
498
+ "Ordered findings with severity",
499
+ "Residual risk and testing gaps",
500
+ "Recommended next role",
501
+ ],
502
+ defaultOutput: [
503
+ "Findings first",
504
+ "Residual risk summary",
505
+ "Next-step recommendation",
506
+ ],
507
+ },
508
+ {
509
+ key: "qa-guard",
510
+ name: "qa-guard",
511
+ purpose: "Own validation closure, test matrix definition, quality-gate checks, and evidence of what was and was not verified.",
512
+ model: "gpt-5.4",
513
+ reasoningEffort: "medium",
514
+ memoryFile: ".codex/memory/decisions.md",
515
+ runbookFile: "docs/runbooks/qa-agent.md",
516
+ handoffPathHint: "logs/codex/active/<task-slug>/handoff.md",
517
+ readFirst: [
518
+ "docs/runbooks/qa-agent.md",
519
+ ".codex/memory/decisions.md",
520
+ "dev-docs/11-integration-and-acceptance.md",
521
+ "spec/quality-gates.md",
522
+ ],
523
+ scope: [
524
+ "Validation strategy and execution notes",
525
+ "Quality-gate checks",
526
+ "Explicit verified vs unverified reporting",
527
+ ],
528
+ doNot: [
529
+ "Do not claim tests passed when they were not run",
530
+ "Do not hide blocking gaps in critical flows",
531
+ "Do not replace reviewer correctness checks",
532
+ ],
533
+ handoffRequired: [
534
+ "Executed validations",
535
+ "Unexecuted validations",
536
+ "Blocking and non-blocking risks",
537
+ "Recommended next role",
538
+ ],
539
+ defaultOutput: [
540
+ "Validation matrix",
541
+ "Quality-gate status",
542
+ "Next-step recommendation",
543
+ ],
544
+ },
545
+ ];
546
+ function buildRoleToml(role) {
547
+ return [
548
+ `name = "${escapeTomlString(role.name)}"`,
549
+ `purpose = "${escapeTomlString(role.purpose)}"`,
550
+ `model = "${escapeTomlString(role.model)}"`,
551
+ `reasoning_effort = "${escapeTomlString(role.reasoningEffort)}"`,
552
+ `memory_file = "${escapeTomlString(role.memoryFile)}"`,
553
+ `runbook_file = "${escapeTomlString(role.runbookFile)}"`,
554
+ `handoff_path_hint = "${escapeTomlString(role.handoffPathHint)}"`,
555
+ "",
556
+ `read_first = ${renderTomlArray(role.readFirst)}`,
557
+ "",
558
+ `scope = ${renderTomlArray(role.scope)}`,
559
+ "",
560
+ `do_not = ${renderTomlArray(role.doNot)}`,
561
+ "",
562
+ `handoff_required = ${renderTomlArray(role.handoffRequired)}`,
563
+ "",
564
+ `default_output = ${renderTomlArray(role.defaultOutput)}`,
565
+ ].join("\n");
566
+ }
567
+ function buildCodexConfig(projectName) {
568
+ return dedent(`
569
+ # Project-local Codex baseline for ${projectName}.
570
+ # Verified local baseline: enable multi-agent at the repo level.
571
+ # Fixed role definitions live under \`.codex/agents/\` and are consumed by
572
+ # repository runbooks and bootstrap prompts.
573
+
574
+ [features]
575
+ multi_agent = true
576
+ `);
577
+ }
578
+ function splitMarkdownTitle(document) {
579
+ const normalized = dedent(document).trim();
580
+ const [firstLine = "", ...restLines] = normalized.split("\n");
581
+ const title = firstLine.startsWith("# ") ? firstLine.slice(2).trim() : "Document";
582
+ const body = firstLine.startsWith("# ") ? restLines.join("\n").trim() : normalized;
583
+ return { title, body };
584
+ }
585
+ function localizeMarkdownPair(language, englishDocument, chineseDocument, bilingualTitle) {
586
+ if (language === "en") {
587
+ return englishDocument;
588
+ }
589
+ if (language === "zh") {
590
+ return chineseDocument;
591
+ }
592
+ const english = splitMarkdownTitle(englishDocument);
593
+ const chinese = splitMarkdownTitle(chineseDocument);
594
+ return dedent(`
595
+ # ${bilingualTitle ?? `${english.title} / ${chinese.title}`}
596
+
597
+ ## 中文
598
+
599
+ ${chinese.body}
600
+
601
+ ---
602
+
603
+ ## English
604
+
605
+ ${english.body}
606
+ `);
607
+ }
608
+ function buildActivePlansReadme(language) {
609
+ const english = dedent(`
610
+ # Active Plans
611
+
612
+ This directory stores long-running plans for work that is still in progress.
613
+
614
+ ## 1. When to create a plan
615
+
616
+ Create a plan whenever any of the following is true:
617
+
618
+ - The task spans multiple rounds or multiple threads.
619
+ - The task requires multiple fixed roles.
620
+ - The main thread needs durable context beyond the current conversation.
621
+ - The task is class B or class C.
622
+
623
+ ## 2. File naming
624
+
625
+ Recommended format:
626
+
627
+ - \`YYYY-MM-DD-<task-slug>.md\`
628
+
629
+ ## 3. Minimum template
630
+
631
+ \`\`\`md
632
+ # <task title>
633
+
634
+ ## Background
635
+
636
+ ## Goal
637
+
638
+ ## Scope
639
+
640
+ ## Out Of Scope
641
+
642
+ ## Truth Sources
643
+
644
+ ## Current Decisions
645
+
646
+ ## Work Breakdown
647
+
648
+ ## Validation Plan
649
+
650
+ ## Risks And Blockers
651
+
652
+ ## Required Roles
653
+
654
+ ## Required Memory Or Handoff Updates
655
+ \`\`\`
656
+
657
+ ## 4. Completion
658
+
659
+ Before moving a plan to \`../completed/\`:
660
+
661
+ 1. Record the outcome and residual risk.
662
+ 2. Confirm the handoff and memory files were updated.
663
+ 3. Archive the plan and matching logs.
664
+ `);
665
+ const chinese = dedent(`
666
+ # 进行中的计划
667
+
668
+ 这里存放仍在执行中的长周期任务计划。
669
+
670
+ ## 1. 什么时候需要创建计划
671
+
672
+ 只要满足以下任意条件,就应该创建计划:
673
+
674
+ - 任务会跨越多个回合或多个线程。
675
+ - 任务需要多个固定角色协作。
676
+ - 主线程需要在当前会话之外保留长期上下文。
677
+ - 任务属于 B 类或 C 类。
678
+
679
+ ## 2. 文件命名
680
+
681
+ 推荐格式:
682
+
683
+ - \`YYYY-MM-DD-<task-slug>.md\`
684
+
685
+ ## 3. 最小模板
686
+
687
+ \`\`\`md
688
+ # <任务标题>
689
+
690
+ ## Background
691
+
692
+ ## Goal
693
+
694
+ ## Scope
695
+
696
+ ## Out Of Scope
697
+
698
+ ## Truth Sources
699
+
700
+ ## Current Decisions
701
+
702
+ ## Work Breakdown
703
+
704
+ ## Validation Plan
705
+
706
+ ## Risks And Blockers
707
+
708
+ ## Required Roles
709
+
710
+ ## Required Memory Or Handoff Updates
711
+ \`\`\`
712
+
713
+ ## 4. 完成前检查
714
+
715
+ 在移动到 \`../completed/\` 之前:
716
+
717
+ 1. 记录结果和剩余风险。
718
+ 2. 确认 handoff 与 memory 已更新。
719
+ 3. 归档计划和对应日志。
720
+ `);
721
+ return localizeMarkdownPair(language, english, chinese, "Active Plans / 进行中的计划");
722
+ }
723
+ function buildCompletedPlansReadme(language) {
724
+ const english = dedent(`
725
+ # Completed Plans
726
+
727
+ This directory archives long-running plans that reached a terminal state.
728
+
729
+ ## 1. Before archiving
730
+
731
+ - The active plan has a final outcome summary.
732
+ - Matching run log and handoff files exist under \`logs/codex/\`.
733
+ - Durable conclusions were copied into \`.codex/memory/\` where needed.
734
+ - Required truth-source updates are either complete or explicitly deferred.
735
+
736
+ ## 2. Minimum completion sections
737
+
738
+ Add these sections before moving a plan here:
739
+
740
+ \`\`\`md
741
+ ## Result
742
+
743
+ ## Actual Changes
744
+
745
+ ## Verified
746
+
747
+ ## Unverified
748
+
749
+ ## Residual Risks
750
+
751
+ ## Follow-Up
752
+ \`\`\`
753
+ `);
754
+ const chinese = dedent(`
755
+ # 已完成计划
756
+
757
+ 这里归档已经到达终态的长周期任务计划。
758
+
759
+ ## 1. 归档前确认
760
+
761
+ - active 计划已经补充最终结果摘要。
762
+ - 对应的 run log 与 handoff 已存在于 \`logs/codex/\`。
763
+ - 需要长期保留的结论已同步到 \`.codex/memory/\`。
764
+ - 必需的真源文档更新已经完成,或已明确延期。
765
+
766
+ ## 2. 最小完成段落
767
+
768
+ 移动到这里之前,请至少补齐以下段落:
769
+
770
+ \`\`\`md
771
+ ## Result
772
+
773
+ ## Actual Changes
774
+
775
+ ## Verified
776
+
777
+ ## Unverified
778
+
779
+ ## Residual Risks
780
+
781
+ ## Follow-Up
782
+ \`\`\`
783
+ `);
784
+ return localizeMarkdownPair(language, english, chinese, "Completed Plans / 已完成计划");
785
+ }
786
+ function buildActiveLogsReadme(language) {
787
+ const english = dedent(`
788
+ # Active Codex Logs
789
+
790
+ This directory records run logs and handoffs for in-progress tasks.
791
+
792
+ ## 1. Recommended structure
793
+
794
+ \`\`\`text
795
+ logs/codex/active/
796
+ <task-slug>/
797
+ run.md
798
+ handoff.md
799
+ artifacts/
800
+ \`\`\`
801
+
802
+ ## 2. Minimum \`run.md\` template
803
+
804
+ \`\`\`md
805
+ # <task title>
806
+
807
+ ## Context
808
+
809
+ ## Timeline
810
+
811
+ ## Commands
812
+
813
+ ## Verification Notes
814
+
815
+ ## Open Questions
816
+ \`\`\`
817
+
818
+ ## 3. Minimum \`handoff.md\` template
819
+
820
+ \`\`\`md
821
+ # <task title> Handoff
822
+
823
+ ## Current Goal
824
+
825
+ ## Completed
826
+
827
+ ## In Progress
828
+
829
+ ## Key Files
830
+
831
+ ## Key Decisions
832
+
833
+ ## Risks
834
+
835
+ ## Suggested Next Steps
836
+
837
+ ## Suggested Next Role
838
+ \`\`\`
839
+ `);
840
+ const chinese = dedent(`
841
+ # 进行中的 Codex 日志
842
+
843
+ 这里记录进行中任务的 run log 与 handoff。
844
+
845
+ ## 1. 推荐结构
846
+
847
+ \`\`\`text
848
+ logs/codex/active/
849
+ <task-slug>/
850
+ run.md
851
+ handoff.md
852
+ artifacts/
853
+ \`\`\`
854
+
855
+ ## 2. \`run.md\` 最小模板
856
+
857
+ \`\`\`md
858
+ # <任务标题>
859
+
860
+ ## Context
861
+
862
+ ## Timeline
863
+
864
+ ## Commands
865
+
866
+ ## Verification Notes
867
+
868
+ ## Open Questions
869
+ \`\`\`
870
+
871
+ ## 3. \`handoff.md\` 最小模板
872
+
873
+ \`\`\`md
874
+ # <任务标题> Handoff
875
+
876
+ ## Current Goal
877
+
878
+ ## Completed
879
+
880
+ ## In Progress
881
+
882
+ ## Key Files
883
+
884
+ ## Key Decisions
885
+
886
+ ## Risks
887
+
888
+ ## Suggested Next Steps
889
+
890
+ ## Suggested Next Role
891
+ \`\`\`
892
+ `);
893
+ return localizeMarkdownPair(language, english, chinese, "Active Codex Logs / 进行中的 Codex 日志");
894
+ }
895
+ function buildCompletedLogsReadme(language) {
896
+ const english = dedent(`
897
+ # Completed Codex Logs
898
+
899
+ This directory archives run logs for completed or paused tasks.
900
+
901
+ ## 1. Archive structure
902
+
903
+ Keep the same shape as \`../active/\`:
904
+
905
+ \`\`\`text
906
+ logs/codex/completed/
907
+ <task-slug>/
908
+ run.md
909
+ handoff.md
910
+ artifacts/
911
+ \`\`\`
912
+ `);
913
+ const chinese = dedent(`
914
+ # 已归档的 Codex 日志
915
+
916
+ 这里归档已经完成或暂停的任务日志。
917
+
918
+ ## 1. 归档结构
919
+
920
+ 保持与 \`../active/\` 相同的目录形状:
921
+
922
+ \`\`\`text
923
+ logs/codex/completed/
924
+ <task-slug>/
925
+ run.md
926
+ handoff.md
927
+ artifacts/
928
+ \`\`\`
929
+ `);
930
+ return localizeMarkdownPair(language, english, chinese, "Completed Codex Logs / 已归档的 Codex 日志");
931
+ }
932
+ function buildEnvironmentToml(projectName, devCommand) {
933
+ return dedent(`
934
+ # THIS IS AUTOGENERATED. DO NOT EDIT MANUALLY
935
+ version = 1
936
+ name = "${escapeTomlString(projectName)}"
937
+
938
+ [setup]
939
+ script = ""
940
+
941
+ [[actions]]
942
+ name = "Run"
943
+ icon = "run"
944
+ command = "${escapeTomlString(devCommand)}"
945
+ `);
946
+ }
947
+ function buildGenericAgentsReadme(config) {
948
+ const english = dedent(`
949
+ # Fixed Agent Pool
950
+
951
+ This directory is the repository-owned source of truth for the fixed ${config.projectName}
952
+ Codex role pool.
953
+
954
+ ## Purpose
955
+
956
+ - Keep the same narrow-role subagents reusable across threads.
957
+ - Store role context in repository files instead of relying on chat history.
958
+ - Give the orchestration main thread a stable place to load role scope before dispatching work.
959
+
960
+ ## Fixed roles
961
+
962
+ ${relativePathList(config.roles.map((role) => `${config.paths.codexAgentsDir}/${role.key}.toml`))}
963
+
964
+ ## Dispatch order
965
+
966
+ When dispatching a role, load context in this order:
967
+
968
+ 1. \`.codex/agents/<role>.toml\`
969
+ 2. \`docs/runbooks/<role-runbook>.md\`
970
+ 3. \`.codex/memory/<domain>.md\`
971
+ 4. The latest matching handoff
972
+ 5. The current plan and source-of-truth docs
973
+ `);
974
+ const chinese = dedent(`
975
+ # 固定角色池
976
+
977
+ 这里是 ${config.projectName} 固定 Codex 角色池的仓库内真源。
978
+
979
+ ## 作用
980
+
981
+ - 让同一组窄职责子代理可以跨线程复用。
982
+ - 把角色上下文保存在仓库文件里,而不是仅依赖聊天历史。
983
+ - 给主线程一个稳定入口,在派发前先加载角色边界。
984
+
985
+ ## 固定角色
986
+
987
+ ${relativePathList(config.roles.map((role) => `${config.paths.codexAgentsDir}/${role.key}.toml`))}
988
+
989
+ ## 派发顺序
990
+
991
+ 派发角色时,按以下顺序读取:
992
+
993
+ 1. \`.codex/agents/<role>.toml\`
994
+ 2. \`docs/runbooks/<role-runbook>.md\`
995
+ 3. \`.codex/memory/<domain>.md\`
996
+ 4. 最新对应 handoff
997
+ 5. 当前计划和真源文档
998
+ `);
999
+ return localizeMarkdownPair(config.language, english, chinese, "Fixed Agent Pool / 固定角色池");
1000
+ }
1001
+ function buildMemoryRegistry(config) {
1002
+ const english = dedent(`
1003
+ # Codex Memory Registry
1004
+
1005
+ This directory stores durable memory for ${config.projectName}. It should keep stable
1006
+ facts that future threads can reload before relying on chat history.
1007
+
1008
+ ## 1. Read order
1009
+
1010
+ Main threads and fixed roles should read, in order:
1011
+
1012
+ 1. This file
1013
+ 2. \`../config.toml\`
1014
+ 3. \`../agents/README.md\`
1015
+ 4. The matching \`../agents/<role>.toml\`
1016
+ 5. The matching domain memory
1017
+ 6. The latest handoff
1018
+ 7. The active plan
1019
+
1020
+ ## 2. Memory files
1021
+
1022
+ | File | Purpose |
1023
+ | --- | --- |
1024
+ | \`backend.md\` | Stable backend boundaries, recurring risks, and reading order |
1025
+ | \`frontend.md\` | Stable frontend boundaries, route rules, and UI constraints |
1026
+ | \`runtime.md\` | Stable runtime, integration, and safety boundaries |
1027
+ | \`decisions.md\` | Cross-domain durable decisions and shared operating rules |
1028
+ `);
1029
+ const chinese = dedent(`
1030
+ # Codex Memory 注册表
1031
+
1032
+ 这里存放 ${config.projectName} 的长期记忆,用来在未来线程中优先恢复稳定事实,而不是依赖聊天历史。
1033
+
1034
+ ## 1. 读取顺序
1035
+
1036
+ 主线程和固定角色应按以下顺序读取:
1037
+
1038
+ 1. 本文件
1039
+ 2. \`../config.toml\`
1040
+ 3. \`../agents/README.md\`
1041
+ 4. 对应的 \`../agents/<role>.toml\`
1042
+ 5. 对应领域 memory
1043
+ 6. 最新 handoff
1044
+ 7. active 计划
1045
+
1046
+ ## 2. Memory 文件
1047
+
1048
+ | 文件 | 用途 |
1049
+ | --- | --- |
1050
+ | \`backend.md\` | 稳定的后端边界、重复出现的风险和阅读顺序 |
1051
+ | \`frontend.md\` | 稳定的前端边界、路由规则和 UI 约束 |
1052
+ | \`runtime.md\` | 稳定的运行时、集成与安全边界 |
1053
+ | \`decisions.md\` | 跨领域的长期决策和协作规则 |
1054
+ `);
1055
+ return localizeMarkdownPair(config.language, english, chinese, "Codex Memory Registry / Codex Memory 注册表");
1056
+ }
1057
+ function buildGenericDocsIndex(config) {
1058
+ const english = dedent(`
1059
+ # ${config.projectName} Documentation Index
1060
+
1061
+ This file is the Codex harness entrypoint for the repository. It links source-of-truth docs,
1062
+ fixed role runbooks, durable memory, and task artifacts together.
1063
+
1064
+ ## 1. Read first
1065
+
1066
+ Main-thread default order:
1067
+
1068
+ 1. \`../AGENTS.md\`
1069
+ 2. If present, \`../AGENTS.override.md\`
1070
+ 3. This file
1071
+ 4. \`../.codex/config.toml\`
1072
+ 5. \`../.codex/agents/README.md\`
1073
+ 6. \`../.codex/memory/registry.md\`
1074
+ 7. The matching runbook
1075
+ 8. The most recent handoff
1076
+ 9. Only then the implementation
1077
+
1078
+ ## 2. Source of truth docs
1079
+
1080
+ ${config.truthSources.map((source) => `- \`../${source.path}\` — ${source.summary}`).join("\n")}
1081
+
1082
+ ## 3. Harness-owned files
1083
+
1084
+ - \`../.codex/config.toml\`
1085
+ - \`../.codex/agents/\`
1086
+ - \`../.codex/memory/\`
1087
+ - \`./runbooks/\`
1088
+ - \`./plans/active/\`
1089
+ - \`./plans/completed/\`
1090
+ - \`../logs/codex/active/\`
1091
+ - \`../logs/codex/completed/\`
1092
+ `);
1093
+ const chinese = dedent(`
1094
+ # ${config.projectName} 文档索引
1095
+
1096
+ 这个文件是仓库内 Codex harness 的入口,负责把真源文档、固定角色 runbook、长期 memory 和任务产物串起来。
1097
+
1098
+ ## 1. 优先读取顺序
1099
+
1100
+ 主线程默认顺序:
1101
+
1102
+ 1. \`../AGENTS.md\`
1103
+ 2. 如果存在,再读 \`../AGENTS.override.md\`
1104
+ 3. 本文件
1105
+ 4. \`../.codex/config.toml\`
1106
+ 5. \`../.codex/agents/README.md\`
1107
+ 6. \`../.codex/memory/registry.md\`
1108
+ 7. 对应 runbook
1109
+ 8. 最新 handoff
1110
+ 9. 最后才看具体实现代码
1111
+
1112
+ ## 2. 真源文档
1113
+
1114
+ ${config.truthSources.map((source) => `- \`../${source.path}\` — ${source.title}`).join("\n")}
1115
+
1116
+ ## 3. Harness 自有文件
1117
+
1118
+ - \`../.codex/config.toml\`
1119
+ - \`../.codex/agents/\`
1120
+ - \`../.codex/memory/\`
1121
+ - \`./runbooks/\`
1122
+ - \`./plans/active/\`
1123
+ - \`./plans/completed/\`
1124
+ - \`../logs/codex/active/\`
1125
+ - \`../logs/codex/completed/\`
1126
+ `);
1127
+ return localizeMarkdownPair(config.language, english, chinese, `${config.projectName} Documentation Index / ${config.projectName} 文档索引`);
1128
+ }
1129
+ function buildGenericAgentsMd(config) {
1130
+ return dedent(`
1131
+ # AGENTS.md
1132
+
1133
+ ${config.projectName}'s repository collaboration entrypoint stays short. Detailed truth
1134
+ belongs in \`docs/source-of-truth/\`, \`docs/\`, and \`.codex/memory/\`.
1135
+
1136
+ ## 1. Priorities
1137
+
1138
+ Resolve conflicts in this order:
1139
+
1140
+ 1. The current task
1141
+ 2. \`AGENTS.override.md\`
1142
+ 3. This file
1143
+ 4. \`docs/index.md\`
1144
+ 5. Source-of-truth docs
1145
+ 6. The current code
1146
+ 7. Chat inference
1147
+
1148
+ ## 2. Before starting any task
1149
+
1150
+ Main threads should read:
1151
+
1152
+ 1. \`docs/index.md\`
1153
+ 2. The matching runbook
1154
+ 3. \`.codex/memory/registry.md\`
1155
+ 4. Relevant domain memory
1156
+ 5. The latest handoff
1157
+ 6. Then the code
1158
+
1159
+ ## 3. Long-running task artifacts
1160
+
1161
+ Durable task artifacts live in:
1162
+
1163
+ - \`docs/plans/active/<task-slug>.md\`
1164
+ - \`logs/codex/active/<task-slug>/run.md\`
1165
+ - \`logs/codex/active/<task-slug>/handoff.md\`
1166
+ - \`.codex/memory/*.md\`
1167
+
1168
+ ## 4. Fixed roles
1169
+
1170
+ ${config.roles.map((role) => `- \`${role.key}\``).join("\n")}
1171
+
1172
+ ## 5. Main-thread responsibilities
1173
+
1174
+ The main thread exists to:
1175
+
1176
+ - break work into scoped tasks
1177
+ - choose fixed roles
1178
+ - keep plans, logs, and handoffs current
1179
+ - summarize outputs and identify truth-source updates
1180
+
1181
+ Do not let subagents rely on chat history alone. Point them at repository files first.
1182
+ `);
1183
+ }
1184
+ function buildGenericAgentsOverride(config) {
1185
+ const english = dedent(`
1186
+ # AGENTS.override.md
1187
+
1188
+ This repository is initialized with an explicit language preference.
1189
+
1190
+ ## Language mode
1191
+
1192
+ - Preferred harness language: \`${config.language}\`
1193
+ - Keep the canonical file paths unchanged.
1194
+ - Respect \`docs/index.md\`, runbooks, memory, plans, and logs as repository truth.
1195
+
1196
+ ## Output preference
1197
+
1198
+ - If the task is conversational or documentation-heavy, respond in Chinese when helpful.
1199
+ - Keep code, file paths, CLI commands, and schema keys in their canonical form.
1200
+ - Preserve English headings when they are part of established templates unless the task requires otherwise.
1201
+ `);
1202
+ const chinese = dedent(`
1203
+ # AGENTS.override.md
1204
+
1205
+ 当前仓库使用了明确的语言偏好设置。
1206
+
1207
+ ## 语言模式
1208
+
1209
+ - 当前偏好语言:\`${config.language}\`
1210
+ - 保持标准文件路径不变。
1211
+ - 继续以 \`docs/index.md\`、runbook、memory、plan 和 log 作为仓库真源。
1212
+
1213
+ ## 输出偏好
1214
+
1215
+ - 对话类或文档类任务在有帮助时优先使用中文。
1216
+ - 代码、文件路径、CLI 命令和 schema key 保持其标准写法。
1217
+ - 如果模板本身已经约定英文标题,除非任务明确要求,否则不要随意改动。
1218
+ `);
1219
+ return localizeMarkdownPair(config.language, english, chinese, "AGENTS.override.md / 语言覆盖");
1220
+ }
1221
+ function buildGenericMemoryFiles(language) {
1222
+ return {
1223
+ ".codex/memory/backend.md": localizeMarkdownPair(language, dedent(`
1224
+ # Backend Memory
1225
+
1226
+ ## Stable position
1227
+
1228
+ - The backend exists to own durable service boundaries and governance semantics.
1229
+ - Contract and permission changes must align with source-of-truth docs first.
1230
+ - Shared code should stay focused and not absorb domain logic by accident.
1231
+
1232
+ ## Common risks
1233
+
1234
+ - Letting current code shape override the documented boundary.
1235
+ - Changing API semantics without updating truth sources.
1236
+ - Hiding permission or audit checks inside scattered helpers.
1237
+ `), dedent(`
1238
+ # 后端 Memory
1239
+
1240
+ ## 稳定立场
1241
+
1242
+ - 后端负责长期稳定的服务边界和治理语义。
1243
+ - 合同与权限变化必须先对齐真源文档。
1244
+ - 共享代码应保持聚焦,避免意外吸收领域逻辑。
1245
+
1246
+ ## 常见风险
1247
+
1248
+ - 让当前代码形态反过来覆盖文档边界。
1249
+ - 改了 API 语义却没有更新真源文档。
1250
+ - 把权限或审计检查散落进各种 helper。
1251
+ `), "Backend Memory / 后端 Memory"),
1252
+ ".codex/memory/frontend.md": localizeMarkdownPair(language, dedent(`
1253
+ # Frontend Memory
1254
+
1255
+ ## Stable position
1256
+
1257
+ - The product UI is not a marketing site and not a chat shell by default.
1258
+ - Route ownership, permission rules, and adapter boundaries belong in repository docs.
1259
+ - Shared components should not absorb domain semantics.
1260
+
1261
+ ## Common risks
1262
+
1263
+ - Inventing unconfirmed fields in page code.
1264
+ - Hardcoding permission meaning in UI components.
1265
+ - Letting visual polish rewrite information architecture.
1266
+ `), dedent(`
1267
+ # 前端 Memory
1268
+
1269
+ ## 稳定立场
1270
+
1271
+ - 产品 UI 默认不是营销站,也不是聊天壳。
1272
+ - 路由归属、权限规则和适配层边界都应写在仓库文档里。
1273
+ - 共享组件不应吸收领域语义。
1274
+
1275
+ ## 常见风险
1276
+
1277
+ - 在页面代码里发明未确认字段。
1278
+ - 在 UI 组件里硬编码权限含义。
1279
+ - 用视觉优化改写了信息架构。
1280
+ `), "Frontend Memory / 前端 Memory"),
1281
+ ".codex/memory/runtime.md": localizeMarkdownPair(language, dedent(`
1282
+ # Runtime Memory
1283
+
1284
+ ## Stable position
1285
+
1286
+ - Runtime and integrations own orchestration safety, not product governance.
1287
+ - Preview, formal execution, and side-effect rules must stay explicit.
1288
+ - Event or protocol changes require truth-source alignment before shipping.
1289
+
1290
+ ## Common risks
1291
+
1292
+ - Hardcoding tool behavior inside orchestration code.
1293
+ - Mixing governance ownership into execution endpoints.
1294
+ - Changing event semantics without updating validation docs.
1295
+ `), dedent(`
1296
+ # 运行时 Memory
1297
+
1298
+ ## 稳定立场
1299
+
1300
+ - Runtime 和集成负责编排安全,不负责产品治理。
1301
+ - 预览、正式执行和副作用规则必须保持明确。
1302
+ - 事件或协议变化在发布前必须先对齐真源文档。
1303
+
1304
+ ## 常见风险
1305
+
1306
+ - 在编排代码里硬编码工具行为。
1307
+ - 把治理归属混进执行端点。
1308
+ - 修改事件语义但没更新验证文档。
1309
+ `), "Runtime Memory / 运行时 Memory"),
1310
+ ".codex/memory/decisions.md": localizeMarkdownPair(language, dedent(`
1311
+ # Durable Decisions
1312
+
1313
+ ## Current baseline
1314
+
1315
+ - Repository collaboration is file-first, not chat-history-first.
1316
+ - Long-running work must leave plan, run-log, handoff, and memory traces.
1317
+ - Fixed roles should be reused before creating temporary roles.
1318
+ - Main-thread orchestration should preserve source-of-truth precedence over code drift.
1319
+ `), dedent(`
1320
+ # 长期决策
1321
+
1322
+ ## 当前基线
1323
+
1324
+ - 仓库协作以文件为先,而不是以聊天历史为先。
1325
+ - 长周期工作必须留下计划、运行日志、handoff 和 memory 痕迹。
1326
+ - 在创建临时角色之前,应优先复用固定角色。
1327
+ - 主线程编排应始终让真源文档优先于代码漂移。
1328
+ `), "Durable Decisions / 长期决策"),
1329
+ };
1330
+ }
1331
+ function buildGenericRunbooks(config) {
1332
+ const roleMap = new Map(config.roles.map((role) => [role.key, role]));
1333
+ const runtimeRole = roleMap.get("runtime-integrations");
1334
+ const uiRole = roleMap.get("product-ui");
1335
+ return [
1336
+ {
1337
+ path: "docs/runbooks/codex-main-thread.md",
1338
+ content: localizeMarkdownPair(config.language, dedent(`
1339
+ # Codex Main Thread Runbook
1340
+
1341
+ This runbook constrains the single orchestration thread for ${config.projectName}.
1342
+ The main thread coordinates work, preserves context, and integrates fixed-role outputs.
1343
+
1344
+ ## 1. Read before starting
1345
+
1346
+ 1. \`../../AGENTS.md\`
1347
+ 2. If present, \`../../AGENTS.override.md\`
1348
+ 3. \`../index.md\`
1349
+ 4. \`../../.codex/config.toml\`
1350
+ 5. \`../../.codex/agents/README.md\`
1351
+ 6. \`./main-thread-bootstrap.md\`
1352
+ 7. \`../../.codex/memory/registry.md\`
1353
+ 8. Relevant domain memory
1354
+ 9. The latest handoff
1355
+ 10. Relevant source-of-truth docs
1356
+
1357
+ ## 2. Fixed duties
1358
+
1359
+ - classify the task
1360
+ - define scope and validation
1361
+ - select fixed roles
1362
+ - maintain plan, run log, and handoff
1363
+ - summarize risks and truth-source updates
1364
+
1365
+ ## 3. Fixed role pool
1366
+
1367
+ ${config.roles.map((role) => `- \`${role.key}\``).join("\n")}
1368
+
1369
+ ## 4. Task artifact locations
1370
+
1371
+ - \`../../docs/plans/active/<task-slug>.md\`
1372
+ - \`../../logs/codex/active/<task-slug>/run.md\`
1373
+ - \`../../logs/codex/active/<task-slug>/handoff.md\`
1374
+ `), dedent(`
1375
+ # Codex 主线程 Runbook
1376
+
1377
+ 这个 runbook 约束 ${config.projectName} 的单一编排主线程。
1378
+ 主线程负责协同工作、保留上下文,并整合固定角色的输出。
1379
+
1380
+ ## 1. 开始前先读
1381
+
1382
+ 1. \`../../AGENTS.md\`
1383
+ 2. 如果存在,再读 \`../../AGENTS.override.md\`
1384
+ 3. \`../index.md\`
1385
+ 4. \`../../.codex/config.toml\`
1386
+ 5. \`../../.codex/agents/README.md\`
1387
+ 6. \`./main-thread-bootstrap.md\`
1388
+ 7. \`../../.codex/memory/registry.md\`
1389
+ 8. 相关领域 memory
1390
+ 9. 最新 handoff
1391
+ 10. 相关真源文档
1392
+
1393
+ ## 2. 固定职责
1394
+
1395
+ - 任务分级
1396
+ - 定义范围和验证方式
1397
+ - 选择固定角色
1398
+ - 维护计划、run log 和 handoff
1399
+ - 汇总风险和真源更新
1400
+
1401
+ ## 3. 固定角色池
1402
+
1403
+ ${config.roles.map((role) => `- \`${role.key}\``).join("\n")}
1404
+
1405
+ ## 4. 任务产物位置
1406
+
1407
+ - \`../../docs/plans/active/<task-slug>.md\`
1408
+ - \`../../logs/codex/active/<task-slug>/run.md\`
1409
+ - \`../../logs/codex/active/<task-slug>/handoff.md\`
1410
+ `), "Codex Main Thread Runbook / Codex 主线程 Runbook"),
1411
+ },
1412
+ {
1413
+ path: "docs/runbooks/main-thread-bootstrap.md",
1414
+ content: localizeMarkdownPair(config.language, dedent(`
1415
+ # Main Thread Bootstrap
1416
+
1417
+ This file gives a new orchestration main thread a reusable startup prompt and
1418
+ dispatch templates for the fixed role pool.
1419
+
1420
+ ## 1. Main-thread startup checklist
1421
+
1422
+ 1. Read \`AGENTS.md\`.
1423
+ 2. Read \`AGENTS.override.md\` if it exists.
1424
+ 3. Read \`docs/index.md\`.
1425
+ 4. Read \`.codex/config.toml\`.
1426
+ 5. Read \`.codex/agents/README.md\`.
1427
+ 6. Read \`docs/runbooks/codex-main-thread.md\`.
1428
+ 7. Read \`.codex/memory/registry.md\`.
1429
+ 8. Read relevant domain memory.
1430
+ 9. Read the latest handoff.
1431
+ 10. Read the relevant source-of-truth docs.
1432
+
1433
+ ## 2. Fixed role pool
1434
+
1435
+ ${config.roles.map((role) => `- \`${role.key}\``).join("\n")}
1436
+
1437
+ ## 3. Dispatch templates
1438
+
1439
+ ${config.roles
1440
+ .map((role) => {
1441
+ const outOfScope = role.doNot.map((item) => `- ${item}`).join("\n");
1442
+ const readFirst = role.readFirst.map((item, index) => `${index + 1}. \`${item}\``).join("\n");
1443
+ const output = role.defaultOutput.map((item) => `- ${item}`).join("\n");
1444
+ const handoff = role.handoffRequired.map((item) => `- ${item}`).join("\n");
1445
+ return dedent(`
1446
+ ### \`${role.key}\`
1447
+
1448
+ \`\`\`text
1449
+ You are the \`${role.key}\` fixed role for ${config.projectName}.
1450
+
1451
+ Goal:
1452
+ <fill in the task goal>
1453
+
1454
+ Scope:
1455
+ ${role.scope.map((item) => `- ${item}`).join("\n")}
1456
+
1457
+ Out of scope:
1458
+ ${outOfScope}
1459
+
1460
+ Read first:
1461
+ ${readFirst}
1462
+
1463
+ Expected output:
1464
+ ${output}
1465
+
1466
+ Handoff requirements:
1467
+ ${handoff}
1468
+ \`\`\`
1469
+ `);
1470
+ })
1471
+ .join("\n\n")}
1472
+
1473
+ ## 4. Reuse rules
1474
+
1475
+ 1. Reuse the fixed roles before inventing temporary ones.
1476
+ 2. Keep plans, run logs, handoffs, and memory updated after each round.
1477
+ 3. Point every role at repository files before relying on chat history.
1478
+ `), dedent(`
1479
+ # 主线程启动说明
1480
+
1481
+ 这个文件为新的编排主线程提供可复用的启动提示词和固定角色派发模板。
1482
+
1483
+ ## 1. 主线程启动清单
1484
+
1485
+ 1. 阅读 \`AGENTS.md\`。
1486
+ 2. 如果存在,阅读 \`AGENTS.override.md\`。
1487
+ 3. 阅读 \`docs/index.md\`。
1488
+ 4. 阅读 \`.codex/config.toml\`。
1489
+ 5. 阅读 \`.codex/agents/README.md\`。
1490
+ 6. 阅读 \`docs/runbooks/codex-main-thread.md\`。
1491
+ 7. 阅读 \`.codex/memory/registry.md\`。
1492
+ 8. 阅读相关领域 memory。
1493
+ 9. 阅读最新 handoff。
1494
+ 10. 阅读相关真源文档。
1495
+
1496
+ ## 2. 固定角色池
1497
+
1498
+ ${config.roles.map((role) => `- \`${role.key}\``).join("\n")}
1499
+
1500
+ ## 3. 派发模板
1501
+
1502
+ ${config.roles
1503
+ .map((role) => {
1504
+ const outOfScope = role.doNot.map((item) => `- ${item}`).join("\n");
1505
+ const readFirst = role.readFirst.map((item, index) => `${index + 1}. \`${item}\``).join("\n");
1506
+ const output = role.defaultOutput.map((item) => `- ${item}`).join("\n");
1507
+ const handoff = role.handoffRequired.map((item) => `- ${item}`).join("\n");
1508
+ return dedent(`
1509
+ ### \`${role.key}\`
1510
+
1511
+ \`\`\`text
1512
+ 你是 ${config.projectName} 的 \`${role.key}\` 固定角色。
1513
+
1514
+ Goal:
1515
+ <在这里填写任务目标>
1516
+
1517
+ Scope:
1518
+ ${role.scope.map((item) => `- ${item}`).join("\n")}
1519
+
1520
+ Out of scope:
1521
+ ${outOfScope}
1522
+
1523
+ Read first:
1524
+ ${readFirst}
1525
+
1526
+ Expected output:
1527
+ ${output}
1528
+
1529
+ Handoff requirements:
1530
+ ${handoff}
1531
+ \`\`\`
1532
+ `);
1533
+ })
1534
+ .join("\n\n")}
1535
+
1536
+ ## 4. 复用规则
1537
+
1538
+ 1. 在创造临时角色之前先复用固定角色。
1539
+ 2. 每一轮之后都要更新计划、run log、handoff 和 memory。
1540
+ 3. 让每个角色先读取仓库文件,再依赖聊天历史。
1541
+ `), "Main Thread Bootstrap / 主线程启动说明"),
1542
+ },
1543
+ {
1544
+ path: "docs/runbooks/backend-agent.md",
1545
+ content: localizeMarkdownPair(config.language, dedent(`
1546
+ # Backend Agent Runbook
1547
+
1548
+ This runbook serves \`architect-backend\`.
1549
+
1550
+ ## 1. Scope
1551
+
1552
+ - service modules and backend boundaries
1553
+ - API, data, permission, audit, and governance constraints
1554
+ - implementation placement and backend sequencing
1555
+
1556
+ ## 2. Read before starting
1557
+
1558
+ 1. \`../index.md\`
1559
+ 2. \`../../.codex/memory/backend.md\`
1560
+ 3. \`../../docs/source-of-truth/system-overview.md\`
1561
+ 4. \`../../docs/source-of-truth/backend-architecture.md\`
1562
+ 5. \`../../docs/source-of-truth/api-specification.md\`
1563
+
1564
+ ## 3. Handoff
1565
+
1566
+ Record touched modules, contract impact, validation status, and the next recommended role.
1567
+ `), dedent(`
1568
+ # 后端角色 Runbook
1569
+
1570
+ 这个 runbook 服务于 \`architect-backend\`。
1571
+
1572
+ ## 1. 范围
1573
+
1574
+ - 服务模块和后端边界
1575
+ - API、数据、权限、审计和治理约束
1576
+ - 实现位置和后端变更顺序
1577
+
1578
+ ## 2. 开始前先读
1579
+
1580
+ 1. \`../index.md\`
1581
+ 2. \`../../.codex/memory/backend.md\`
1582
+ 3. \`../../docs/source-of-truth/system-overview.md\`
1583
+ 4. \`../../docs/source-of-truth/backend-architecture.md\`
1584
+ 5. \`../../docs/source-of-truth/api-specification.md\`
1585
+
1586
+ ## 3. Handoff
1587
+
1588
+ 记录受影响模块、合同影响、验证状态和建议的下一角色。
1589
+ `), "Backend Agent Runbook / 后端角色 Runbook"),
1590
+ },
1591
+ {
1592
+ path: "docs/runbooks/frontend-agent.md",
1593
+ content: localizeMarkdownPair(config.language, dedent(`
1594
+ # Frontend Agent Runbook
1595
+
1596
+ This runbook serves both \`architect-frontend\` and \`${uiRole?.key ?? "product-ui"}\`.
1597
+
1598
+ ## 1. Shared scope
1599
+
1600
+ - route ownership and product structure
1601
+ - feature, component, and adapter boundaries
1602
+ - permission, tenant-context, and real-time interaction design
1603
+ - concrete pages, tables, forms, details, and state feedback
1604
+
1605
+ ## 2. Read before starting
1606
+
1607
+ 1. \`../index.md\`
1608
+ 2. \`../../.codex/memory/frontend.md\`
1609
+ 3. \`../../docs/source-of-truth/system-overview.md\`
1610
+ 4. \`../../docs/source-of-truth/frontend-architecture.md\`
1611
+ 5. \`../../docs/source-of-truth/api-specification.md\`
1612
+
1613
+ ## 3. Boundary rule
1614
+
1615
+ Architecture questions should be settled by \`architect-frontend\` before \`${uiRole?.key ?? "product-ui"}\`
1616
+ lands concrete UI changes.
1617
+ `), dedent(`
1618
+ # 前端角色 Runbook
1619
+
1620
+ 这个 runbook 同时服务 \`architect-frontend\` 和 \`${uiRole?.key ?? "product-ui"}\`。
1621
+
1622
+ ## 1. 共享范围
1623
+
1624
+ - 路由归属和产品结构
1625
+ - 特性、组件和适配层边界
1626
+ - 权限、租户上下文和实时交互设计
1627
+ - 具体页面、表格、表单、详情和状态反馈
1628
+
1629
+ ## 2. 开始前先读
1630
+
1631
+ 1. \`../index.md\`
1632
+ 2. \`../../.codex/memory/frontend.md\`
1633
+ 3. \`../../docs/source-of-truth/system-overview.md\`
1634
+ 4. \`../../docs/source-of-truth/frontend-architecture.md\`
1635
+ 5. \`../../docs/source-of-truth/api-specification.md\`
1636
+
1637
+ ## 3. 边界规则
1638
+
1639
+ 架构问题应先由 \`architect-frontend\` 定稿,再由 \`${uiRole?.key ?? "product-ui"}\`
1640
+ 落具体 UI 改动。
1641
+ `), "Frontend Agent Runbook / 前端角色 Runbook"),
1642
+ },
1643
+ {
1644
+ path: "docs/runbooks/runtime-agent.md",
1645
+ content: localizeMarkdownPair(config.language, dedent(`
1646
+ # Runtime Agent Runbook
1647
+
1648
+ This runbook serves \`${runtimeRole?.key ?? "runtime-integrations"}\`.
1649
+
1650
+ ## 1. Scope
1651
+
1652
+ - runtime orchestration and integration flows
1653
+ - tool binding and operational safety
1654
+ - event, protocol, and validation boundaries
1655
+
1656
+ ## 2. Read before starting
1657
+
1658
+ 1. \`../index.md\`
1659
+ 2. \`../../.codex/memory/runtime.md\`
1660
+ 3. \`../../docs/source-of-truth/system-overview.md\`
1661
+ 4. \`../../docs/source-of-truth/backend-architecture.md\`
1662
+ 5. \`../../docs/source-of-truth/api-specification.md\`
1663
+ 6. \`../../docs/source-of-truth/quality-gates.md\`
1664
+ `), dedent(`
1665
+ # Runtime 角色 Runbook
1666
+
1667
+ 这个 runbook 服务于 \`${runtimeRole?.key ?? "runtime-integrations"}\`。
1668
+
1669
+ ## 1. 范围
1670
+
1671
+ - 运行时编排和集成流程
1672
+ - 工具绑定和运行安全
1673
+ - 事件、协议和验证边界
1674
+
1675
+ ## 2. 开始前先读
1676
+
1677
+ 1. \`../index.md\`
1678
+ 2. \`../../.codex/memory/runtime.md\`
1679
+ 3. \`../../docs/source-of-truth/system-overview.md\`
1680
+ 4. \`../../docs/source-of-truth/backend-architecture.md\`
1681
+ 5. \`../../docs/source-of-truth/api-specification.md\`
1682
+ 6. \`../../docs/source-of-truth/quality-gates.md\`
1683
+ `), "Runtime Agent Runbook / Runtime 角色 Runbook"),
1684
+ },
1685
+ {
1686
+ path: "docs/runbooks/reviewer-agent.md",
1687
+ content: localizeMarkdownPair(config.language, dedent(`
1688
+ # Reviewer Agent Runbook
1689
+
1690
+ This runbook serves \`reviewer\`.
1691
+
1692
+ ## 1. Review order
1693
+
1694
+ 1. product direction drift
1695
+ 2. boundary breakage
1696
+ 3. contract, permission, and state regressions
1697
+ 4. missing validation
1698
+ 5. readability and maintainability
1699
+
1700
+ ## 2. Output rule
1701
+
1702
+ Findings come first. If there are no findings, report residual risk and unverified paths anyway.
1703
+ `), dedent(`
1704
+ # Reviewer 角色 Runbook
1705
+
1706
+ 这个 runbook 服务于 \`reviewer\`。
1707
+
1708
+ ## 1. 评审顺序
1709
+
1710
+ 1. 产品方向漂移
1711
+ 2. 边界破坏
1712
+ 3. 合同、权限和状态回归
1713
+ 4. 缺失验证
1714
+ 5. 可读性与可维护性
1715
+
1716
+ ## 2. 输出规则
1717
+
1718
+ 先给 findings。如果没有 findings,也要说明剩余风险和未验证路径。
1719
+ `), "Reviewer Agent Runbook / Reviewer 角色 Runbook"),
1720
+ },
1721
+ {
1722
+ path: "docs/runbooks/qa-agent.md",
1723
+ content: localizeMarkdownPair(config.language, dedent(`
1724
+ # QA Agent Runbook
1725
+
1726
+ This runbook serves \`qa-guard\`.
1727
+
1728
+ ## 1. Scope
1729
+
1730
+ - validation matrix design
1731
+ - quality-gate checks
1732
+ - explicit verified vs unverified reporting
1733
+
1734
+ ## 2. Read before starting
1735
+
1736
+ 1. \`../index.md\`
1737
+ 2. the current plan
1738
+ 3. the current run log and handoff
1739
+ 4. \`../../docs/source-of-truth/integration-and-acceptance.md\`
1740
+ 5. \`../../docs/source-of-truth/quality-gates.md\`
1741
+ `), dedent(`
1742
+ # QA 角色 Runbook
1743
+
1744
+ 这个 runbook 服务于 \`qa-guard\`。
1745
+
1746
+ ## 1. 范围
1747
+
1748
+ - 验证矩阵设计
1749
+ - 质量门禁检查
1750
+ - 明确区分已验证与未验证
1751
+
1752
+ ## 2. 开始前先读
1753
+
1754
+ 1. \`../index.md\`
1755
+ 2. 当前计划
1756
+ 3. 当前 run log 和 handoff
1757
+ 4. \`../../docs/source-of-truth/integration-and-acceptance.md\`
1758
+ 5. \`../../docs/source-of-truth/quality-gates.md\`
1759
+ `), "QA Agent Runbook / QA 角色 Runbook"),
1760
+ },
1761
+ ];
1762
+ }
1763
+ function buildGenericSourceOfTruthFiles(config) {
1764
+ return config.truthSources.map((source) => ({
1765
+ path: source.path,
1766
+ content: localizeMarkdownPair(config.language, dedent(`
1767
+ # ${source.title}
1768
+
1769
+ ${source.summary}
1770
+
1771
+ ## Purpose
1772
+
1773
+ Capture the durable truth for ${config.projectName} in this area.
1774
+
1775
+ ## Current Baseline
1776
+
1777
+ - Fill in the current agreed behavior.
1778
+ - Record decisions before implementation drifts.
1779
+ - Link related plans, handoffs, and validation evidence.
1780
+ `), dedent(`
1781
+ # ${source.title}
1782
+
1783
+ ${source.summary}
1784
+
1785
+ ## 用途
1786
+
1787
+ 在这个领域记录 ${config.projectName} 的长期稳定真相。
1788
+
1789
+ ## 当前基线
1790
+
1791
+ - 在这里补充当前已达成一致的行为。
1792
+ - 在实现漂移之前先记录关键决策。
1793
+ - 关联相关计划、handoff 和验证证据。
1794
+ `), `${source.title} / 中文说明`),
1795
+ }));
1796
+ }
1797
+ function buildGenericManagedFiles(config) {
1798
+ const files = [
1799
+ { path: "AGENTS.md", content: buildGenericAgentsMd(config) },
1800
+ { path: ".codex/config.toml", content: buildCodexConfig(config.projectName) },
1801
+ { path: ".codex/agents/README.md", content: buildGenericAgentsReadme(config) },
1802
+ { path: ".codex/memory/registry.md", content: buildMemoryRegistry(config) },
1803
+ { path: "docs/index.md", content: buildGenericDocsIndex(config) },
1804
+ { path: "docs/plans/active/README.md", content: buildActivePlansReadme(config.language) },
1805
+ { path: "docs/plans/completed/README.md", content: buildCompletedPlansReadme(config.language) },
1806
+ { path: "logs/codex/active/README.md", content: buildActiveLogsReadme(config.language) },
1807
+ { path: "logs/codex/completed/README.md", content: buildCompletedLogsReadme(config.language) },
1808
+ ...buildGenericRunbooks(config),
1809
+ ...buildGenericSourceOfTruthFiles(config),
1810
+ ];
1811
+ if (config.language !== "en") {
1812
+ files.push({
1813
+ path: "AGENTS.override.md",
1814
+ content: buildGenericAgentsOverride(config),
1815
+ });
1816
+ }
1817
+ for (const role of config.roles) {
1818
+ files.push({
1819
+ path: joinPath(config.paths.codexAgentsDir, `${role.key}.toml`),
1820
+ content: buildRoleToml(role),
1821
+ });
1822
+ }
1823
+ for (const [path, content] of Object.entries(buildGenericMemoryFiles(config.language))) {
1824
+ files.push({ path, content });
1825
+ }
1826
+ if (config.devCommand) {
1827
+ files.push({
1828
+ path: config.paths.codexEnvironmentFile,
1829
+ content: buildEnvironmentToml(config.projectName, config.devCommand),
1830
+ });
1831
+ }
1832
+ return files;
1833
+ }
1834
+ function buildAgentAdminDocsIndex() {
1835
+ return dedent(`
1836
+ # AgentAdmin Documentation Index
1837
+
1838
+ This file is the Codex harness entrypoint for the repository. It links source-of-truth docs,
1839
+ runbooks, memory, and task artifacts together.
1840
+
1841
+ ## 1. Read first
1842
+
1843
+ Main-thread default order:
1844
+
1845
+ 1. \`../AGENTS.md\`
1846
+ 2. If present, \`../AGENTS.override.md\`
1847
+ 3. This file
1848
+ 4. \`../.codex/config.toml\`
1849
+ 5. \`../.codex/agents/README.md\`
1850
+ 6. \`../.codex/memory/registry.md\`
1851
+ 7. The matching runbook
1852
+ 8. The latest handoff
1853
+ 9. Then the implementation
1854
+
1855
+ ## 2. Truth-source layering
1856
+
1857
+ - \`../dev-docs/\` owns project, system, backend, frontend, API, data-model, enum, error-code, naming, collaboration, integration, and checklist truths.
1858
+ - \`../spec/\` owns protocol-level and deep-dive design docs.
1859
+ - \`../docs/\` owns Codex harness instructions, plans, and task artifacts.
1860
+
1861
+ ## 3. Harness-owned files
1862
+
1863
+ - \`../.codex/config.toml\`
1864
+ - \`../.codex/agents/\`
1865
+ - \`../.codex/memory/\`
1866
+ - \`./runbooks/\`
1867
+ - \`./plans/active/\`
1868
+ - \`./plans/completed/\`
1869
+ - \`../logs/codex/active/\`
1870
+ - \`../logs/codex/completed/\`
1871
+ `);
1872
+ }
1873
+ function buildAgentAdminAgentsMd() {
1874
+ return dedent(`
1875
+ # AGENTS.md
1876
+
1877
+ AgentAdmin keeps the repository collaboration entrypoint short. Detailed truths live in
1878
+ \`dev-docs/\`, \`spec/\`, \`docs/\`, and \`.codex/memory/\`.
1879
+
1880
+ ## 1. Project direction
1881
+
1882
+ - Java-first, not a chat product or workflow canvas.
1883
+ - Keep a modular monolith and Control Plane / Exec Plane boundaries by default.
1884
+ - Backend stays governance-first; frontend stays console-first.
1885
+ - executor / starter integration remains a differentiated core capability.
1886
+
1887
+ ## 2. Priority order
1888
+
1889
+ Resolve conflicts in this order:
1890
+
1891
+ 1. The explicit task request
1892
+ 2. \`AGENTS.override.md\`
1893
+ 3. This file
1894
+ 4. \`docs/index.md\`
1895
+ 5. \`dev-docs/\` and \`spec/\`
1896
+ 6. Current code
1897
+ 7. Chat inference
1898
+
1899
+ ## 3. Before starting any task
1900
+
1901
+ Main threads read:
1902
+
1903
+ 1. \`docs/index.md\`
1904
+ 2. The matching runbook
1905
+ 3. \`.codex/memory/registry.md\`
1906
+ 4. Relevant domain memory
1907
+ 5. The latest handoff
1908
+ 6. Then the code
1909
+
1910
+ ## 4. Durable task artifacts
1911
+
1912
+ - \`docs/plans/active/<task-slug>.md\`
1913
+ - \`logs/codex/active/<task-slug>/run.md\`
1914
+ - \`logs/codex/active/<task-slug>/handoff.md\`
1915
+ - \`.codex/memory/*.md\`
1916
+
1917
+ ## 5. Fixed roles
1918
+
1919
+ - \`architect-backend\`
1920
+ - \`architect-frontend\`
1921
+ - \`runtime-executor\`
1922
+ - \`console-ui\`
1923
+ - \`reviewer\`
1924
+ - \`qa-guard\`
1925
+ `);
1926
+ }
1927
+ function buildAgentAdminAgentsReadme() {
1928
+ return dedent(`
1929
+ # Fixed Agent Pool
1930
+
1931
+ This directory is the repository-owned source of truth for the fixed AgentAdmin
1932
+ subagent pool.
1933
+
1934
+ ## Purpose
1935
+
1936
+ - Keep the same narrow-role subagents reusable across threads.
1937
+ - Store role context in repo files instead of relying on chat history.
1938
+ - Give the orchestration main thread a stable place to load role scope before dispatching work.
1939
+
1940
+ ## Fixed roles
1941
+
1942
+ - \`architect-backend.toml\`
1943
+ - \`architect-frontend.toml\`
1944
+ - \`runtime-executor.toml\`
1945
+ - \`console-ui.toml\`
1946
+ - \`reviewer.toml\`
1947
+ - \`qa-guard.toml\`
1948
+ `);
1949
+ }
1950
+ function buildAgentAdminMemoryRegistry() {
1951
+ return dedent(`
1952
+ # Codex Memory Registry
1953
+
1954
+ This directory stores reusable durable memory. Its goal is to let future threads read
1955
+ repository facts first, then rely on chat as a supplement.
1956
+
1957
+ ## 1. Read order
1958
+
1959
+ 1. This file
1960
+ 2. \`../config.toml\`
1961
+ 3. \`../agents/README.md\`
1962
+ 4. The matching \`../agents/<role>.toml\`
1963
+ 5. The matching domain memory
1964
+ 6. The latest handoff
1965
+ 7. The active plan
1966
+
1967
+ ## 2. Memory files
1968
+
1969
+ | File | Purpose |
1970
+ | --- | --- |
1971
+ | \`backend.md\` | Stable Control Plane backend boundaries and recurring risks |
1972
+ | \`frontend.md\` | Stable console frontend boundaries, route rules, and UI constraints |
1973
+ | \`runtime.md\` | Stable runtime, executor, tool-binding, and SSE boundaries |
1974
+ | \`decisions.md\` | Cross-domain durable decisions and common operating rules |
1975
+ `);
1976
+ }
1977
+ function buildAgentAdminMemoryFiles() {
1978
+ return {
1979
+ ".codex/memory/backend.md": dedent(`
1980
+ # Backend Memory
1981
+
1982
+ ## 1. Stable position
1983
+
1984
+ - AgentAdmin backend is a governance control plane first, not the business system itself.
1985
+ - The baseline remains a modular monolith with dual-plane boundaries.
1986
+ - \`agentadmin-server\` is the main control-plane application.
1987
+ - \`agentadmin-runtime\` is a shared runtime kernel, not a generic \`core\`.
1988
+ - \`agentadmin-tool-support\` only provides MCP and SYSTEM tool support, not tool governance.
1989
+ `),
1990
+ ".codex/memory/frontend.md": dedent(`
1991
+ # Frontend Memory
1992
+
1993
+ ## 1. Stable position
1994
+
1995
+ - The frontend is a governance console, not a chat shell and not a workflow canvas.
1996
+ - Routes must clearly separate platform, personal, and tenant scopes.
1997
+ - Tenant context belongs in the URL; permissions are determined by permission nodes plus backend payloads.
1998
+ `),
1999
+ ".codex/memory/runtime.md": dedent(`
2000
+ # Runtime Memory
2001
+
2002
+ ## 1. Stable position
2003
+
2004
+ - Runtime is responsible for orchestrating one agent execution, not a heavyweight workflow engine.
2005
+ - Exec Plane owns real execution; Control Plane owns governance, routing, auditing, and observability.
2006
+ - The v1 execution baseline is \`DIRECT_HTTP\`.
2007
+ `),
2008
+ ".codex/memory/decisions.md": dedent(`
2009
+ # Durable Decisions
2010
+
2011
+ ## Current durable decisions
2012
+
2013
+ - AgentAdmin is a Java-first agent access and governance platform.
2014
+ - The architecture stays modular-monolith-first with explicit Control Plane / Exec Plane boundaries.
2015
+ - executor / starter integration remains a core differentiator.
2016
+ - Harness collaboration is file-first: \`docs/\`, \`logs/codex/\`, and \`.codex/memory/\` carry durable context.
2017
+ `),
2018
+ };
2019
+ }
2020
+ function buildAgentAdminRunbooks(config) {
2021
+ return [
2022
+ {
2023
+ path: "docs/runbooks/codex-main-thread.md",
2024
+ content: dedent(`
2025
+ # Codex Main Thread Runbook
2026
+
2027
+ This runbook constrains the single orchestration thread. The main thread is responsible for
2028
+ scoping work, selecting fixed roles, keeping shared context durable, and integrating results.
2029
+
2030
+ ## 1. Read before starting
2031
+
2032
+ 1. \`../../AGENTS.md\`
2033
+ 2. If present, \`../../AGENTS.override.md\`
2034
+ 3. \`../index.md\`
2035
+ 4. \`../../.codex/config.toml\`
2036
+ 5. \`../../.codex/agents/README.md\`
2037
+ 6. \`./main-thread-bootstrap.md\`
2038
+ 7. \`../../.codex/memory/registry.md\`
2039
+ 8. Relevant domain memory
2040
+ 9. The latest handoff
2041
+ 10. Relevant truth-source docs
2042
+
2043
+ ## 2. Fixed role pool
2044
+
2045
+ ${config.roles.map((role) => `- \`${role.key}\``).join("\n")}
2046
+ `),
2047
+ },
2048
+ {
2049
+ path: "docs/runbooks/main-thread-bootstrap.md",
2050
+ content: dedent(`
2051
+ # Main Thread Bootstrap
2052
+
2053
+ This file gives a new orchestration main thread a copy-paste prompt plus fixed-role dispatch templates.
2054
+
2055
+ ## 1. Applicable scenarios
2056
+
2057
+ - A new main thread takes ownership of the AgentAdmin repository.
2058
+ - The main thread needs to absorb background first, then split work and establish fixed roles.
2059
+ - The goal is to reuse repository-owned context instead of relying on the previous chat alone.
2060
+
2061
+ ## 2. Main-thread startup prompt
2062
+
2063
+ \`\`\`text
2064
+ You are now the sole orchestration main thread for AgentAdmin.
2065
+
2066
+ Your job is not to implement everything directly. Read repository truth sources first, reuse
2067
+ harness files, maintain plans, route work into the fixed role pool, and persist durable context.
2068
+
2069
+ Read in this order:
2070
+ 1. AGENTS.md
2071
+ 2. AGENTS.override.md if it exists
2072
+ 3. docs/index.md
2073
+ 4. .codex/config.toml
2074
+ 5. .codex/agents/README.md
2075
+ 6. docs/runbooks/main-thread-bootstrap.md
2076
+ 7. docs/runbooks/codex-main-thread.md
2077
+ 8. .codex/memory/registry.md
2078
+ 9. domain memory files as needed
2079
+ 10. the latest handoff
2080
+ 11. relevant truth-source docs
2081
+
2082
+ The fixed role pool must contain:
2083
+ - architect-backend
2084
+ - architect-frontend
2085
+ - runtime-executor
2086
+ - console-ui
2087
+ - reviewer
2088
+ - qa-guard
2089
+ \`\`\`
2090
+
2091
+ ## 3. Dispatch templates
2092
+
2093
+ ${config.roles
2094
+ .map((role) => {
2095
+ const outOfScope = role.doNot.map((item) => `- ${item}`).join("\n");
2096
+ const readFirst = role.readFirst.map((item, index) => `${index + 1}. \`${item}\``).join("\n");
2097
+ const output = role.defaultOutput.map((item) => `- ${item}`).join("\n");
2098
+ const handoff = role.handoffRequired.map((item) => `- ${item}`).join("\n");
2099
+ return dedent(`
2100
+ ### \`${role.key}\`
2101
+
2102
+ \`\`\`text
2103
+ You are AgentAdmin's \`${role.key}\` fixed role.
2104
+
2105
+ Goal:
2106
+ <fill in the task goal>
2107
+
2108
+ Scope:
2109
+ ${role.scope.map((item) => `- ${item}`).join("\n")}
2110
+
2111
+ Out of scope:
2112
+ ${outOfScope}
2113
+
2114
+ Read first:
2115
+ ${readFirst}
2116
+
2117
+ Expected output:
2118
+ ${output}
2119
+
2120
+ Handoff requirements:
2121
+ ${handoff}
2122
+ \`\`\`
2123
+ `);
2124
+ })
2125
+ .join("\n\n")}
2126
+ `),
2127
+ },
2128
+ {
2129
+ path: "docs/runbooks/backend-agent.md",
2130
+ content: dedent(`
2131
+ # Backend Agent Runbook
2132
+
2133
+ This runbook serves \`architect-backend\`.
2134
+
2135
+ ## 1. Scope
2136
+
2137
+ - Auth / Tenant / RBAC
2138
+ - Agent / Prompt / Tool / Model / Secret / Audit / Jobs
2139
+ - Control-plane Controller / Service / Mapper / DTO / Repository boundaries
2140
+ - API contracts, data models, error codes, naming, and implementation placement
2141
+
2142
+ ## 2. Read before starting
2143
+
2144
+ 1. \`../index.md\`
2145
+ 2. \`../../.codex/memory/backend.md\`
2146
+ 3. \`../../dev-docs/02-system-overview.md\`
2147
+ 4. \`../../dev-docs/03-backend-development-architecture.md\`
2148
+ 5. \`../../dev-docs/05-api-specification.md\`
2149
+ 6. \`../../dev-docs/06-data-model-specification.md\`
2150
+ 7. \`../../dev-docs/07-enum-and-state-definitions.md\`
2151
+ 8. \`../../dev-docs/08-error-code-specification.md\`
2152
+ 9. \`../../dev-docs/09-common-fields-and-naming.md\`
2153
+ 10. \`../../dev-docs/10-frontend-backend-collaboration.md\`
2154
+ 11. \`../../spec/backend-architecture.md\`
2155
+ `),
2156
+ },
2157
+ {
2158
+ path: "docs/runbooks/frontend-agent.md",
2159
+ content: dedent(`
2160
+ # Frontend Agent Runbook
2161
+
2162
+ This runbook serves both \`architect-frontend\` and \`console-ui\`.
2163
+
2164
+ ## 1. Shared scope
2165
+
2166
+ - platform, personal, and tenant console routes
2167
+ - console navigation, page structure, and feature directory boundaries
2168
+ - permission nodes, tenant switching, and SSE flows
2169
+ - forms, tables, detail pages, state feedback, and risk confirmations
2170
+
2171
+ ## 2. Read before starting
2172
+
2173
+ 1. \`../index.md\`
2174
+ 2. \`../../.codex/memory/frontend.md\`
2175
+ 3. \`../../dev-docs/02-system-overview.md\`
2176
+ 4. \`../../dev-docs/04-frontend-development-architecture.md\`
2177
+ 5. \`../../dev-docs/05-api-specification.md\`
2178
+ 6. \`../../dev-docs/07-enum-and-state-definitions.md\`
2179
+ 7. \`../../dev-docs/08-error-code-specification.md\`
2180
+ 8. \`../../dev-docs/09-common-fields-and-naming.md\`
2181
+ 9. \`../../dev-docs/10-frontend-backend-collaboration.md\`
2182
+ 10. \`../../spec/frontend-architecture.md\`
2183
+ `),
2184
+ },
2185
+ {
2186
+ path: "docs/runbooks/runtime-agent.md",
2187
+ content: dedent(`
2188
+ # Runtime Agent Runbook
2189
+
2190
+ This runbook serves \`runtime-executor\`.
2191
+
2192
+ ## 1. Scope
2193
+
2194
+ - agent loading and version resolution
2195
+ - prompt assembly and model selection
2196
+ - tool allowlists, binding, and invocation loops
2197
+ - executor register / heartbeat / invoke
2198
+ - preview / formal run constraints
2199
+ - run / step / event / SSE chains
2200
+
2201
+ ## 2. Read before starting
2202
+
2203
+ 1. \`../index.md\`
2204
+ 2. \`../../.codex/memory/runtime.md\`
2205
+ 3. \`../../dev-docs/02-system-overview.md\`
2206
+ 4. \`../../dev-docs/03-backend-development-architecture.md\`
2207
+ 5. \`../../dev-docs/05-api-specification.md\`
2208
+ 6. \`../../dev-docs/06-data-model-specification.md\`
2209
+ 7. \`../../dev-docs/07-enum-and-state-definitions.md\`
2210
+ 8. \`../../dev-docs/08-error-code-specification.md\`
2211
+ 9. \`../../dev-docs/11-integration-and-acceptance.md\`
2212
+ 10. \`../../spec/backend-architecture.md\`
2213
+ 11. \`../../spec/executor-protocol.md\`
2214
+ 12. \`../../spec/run-stream-event-schema.md\`
2215
+ `),
2216
+ },
2217
+ {
2218
+ path: "docs/runbooks/reviewer-agent.md",
2219
+ content: dedent(`
2220
+ # Reviewer Agent Runbook
2221
+
2222
+ This runbook serves \`reviewer\`.
2223
+
2224
+ ## 1. Review order
2225
+
2226
+ 1. Product-direction drift
2227
+ 2. Module-boundary breakage
2228
+ 3. Tenant, permission, audit, and governance regressions
2229
+ 4. API, state, error-code, and SSE regressions
2230
+ 5. Missing tests or documentation
2231
+ 6. Readability and maintainability
2232
+ `),
2233
+ },
2234
+ {
2235
+ path: "docs/runbooks/qa-agent.md",
2236
+ content: dedent(`
2237
+ # QA Agent Runbook
2238
+
2239
+ This runbook serves \`qa-guard\`.
2240
+
2241
+ ## 1. Scope
2242
+
2243
+ - validation matrix design
2244
+ - unit / integration / contract / E2E / manual verification checklists
2245
+ - quality-gate checks
2246
+ - task-end validation closure
2247
+
2248
+ ## 2. Read before starting
2249
+
2250
+ 1. \`../index.md\`
2251
+ 2. the current plan
2252
+ 3. the current run log and handoff
2253
+ 4. \`../../dev-docs/11-integration-and-acceptance.md\`
2254
+ 5. \`../../dev-docs/13-pre-development-checklist.md\`
2255
+ 6. \`../../spec/quality-gates.md\`
2256
+ `),
2257
+ },
2258
+ ];
2259
+ }
2260
+ function buildAgentAdminTruthSourceFiles(config) {
2261
+ return config.truthSources.map((source) => ({
2262
+ path: source.path,
2263
+ content: dedent(`
2264
+ # ${source.title}
2265
+
2266
+ ${source.summary}
2267
+
2268
+ ## Current Baseline
2269
+
2270
+ - Fill in the durable truth for AgentAdmin in this area.
2271
+ - Update this file before implementation semantics drift.
2272
+ - Link matching plans, handoffs, and validation evidence when relevant.
2273
+ `),
2274
+ }));
2275
+ }
2276
+ function buildAgentAdminManagedFiles(config) {
2277
+ const files = [
2278
+ { path: "AGENTS.md", content: buildAgentAdminAgentsMd() },
2279
+ { path: "AGENTS.override.md", content: buildAgentAdminAgentsMd() },
2280
+ { path: ".codex/config.toml", content: buildCodexConfig(config.projectName) },
2281
+ { path: ".codex/agents/README.md", content: buildAgentAdminAgentsReadme() },
2282
+ { path: ".codex/memory/registry.md", content: buildAgentAdminMemoryRegistry() },
2283
+ { path: "docs/index.md", content: buildAgentAdminDocsIndex() },
2284
+ { path: "docs/plans/active/README.md", content: buildActivePlansReadme(config.language) },
2285
+ { path: "docs/plans/completed/README.md", content: buildCompletedPlansReadme(config.language) },
2286
+ { path: "logs/codex/active/README.md", content: buildActiveLogsReadme(config.language) },
2287
+ { path: "logs/codex/completed/README.md", content: buildCompletedLogsReadme(config.language) },
2288
+ ...buildAgentAdminRunbooks(config),
2289
+ ...buildAgentAdminTruthSourceFiles(config),
2290
+ ];
2291
+ for (const role of config.roles) {
2292
+ files.push({
2293
+ path: joinPath(config.paths.codexAgentsDir, `${role.key}.toml`),
2294
+ content: buildRoleToml(role),
2295
+ });
2296
+ }
2297
+ for (const [path, content] of Object.entries(buildAgentAdminMemoryFiles())) {
2298
+ files.push({ path, content });
2299
+ }
2300
+ if (config.devCommand) {
2301
+ files.push({
2302
+ path: config.paths.codexEnvironmentFile,
2303
+ content: buildEnvironmentToml(config.projectName, config.devCommand),
2304
+ });
2305
+ }
2306
+ return files;
2307
+ }
2308
+ const presetMap = new Map([
2309
+ [
2310
+ "generic-software",
2311
+ {
2312
+ key: "generic-software",
2313
+ defaultLanguage: "en",
2314
+ defaultProjectName: "Acme Platform",
2315
+ paths: genericPaths,
2316
+ roles: genericRoles,
2317
+ truthSources: genericTruthSources,
2318
+ includeOverrideFile: false,
2319
+ buildManagedFiles: buildGenericManagedFiles,
2320
+ },
2321
+ ],
2322
+ [
2323
+ "agentadmin-codex",
2324
+ {
2325
+ key: "agentadmin-codex",
2326
+ defaultLanguage: "zh",
2327
+ defaultProjectName: "AgentAdmin",
2328
+ paths: agentAdminPaths,
2329
+ roles: agentAdminRoles,
2330
+ truthSources: agentAdminTruthSources,
2331
+ includeOverrideFile: true,
2332
+ buildManagedFiles: buildAgentAdminManagedFiles,
2333
+ },
2334
+ ],
2335
+ ]);
2336
+ export function getPreset(key) {
2337
+ const preset = presetMap.get(key);
2338
+ if (!preset) {
2339
+ const available = [...presetMap.keys()].sort().join(", ");
2340
+ throw new Error(`Unknown preset "${key}". Available presets: ${available}.`);
2341
+ }
2342
+ return preset;
2343
+ }
2344
+ //# sourceMappingURL=presets.js.map