(packId, author = "agent")
| 504 | } |
| 505 | |
| 506 | function applyTemplatePack(packId, author = "agent") { |
| 507 | const { id, pack } = getTemplatePackOrThrow(packId); |
| 508 | const ts = nowIso(); |
| 509 | stateCache.templatePackId = id; |
| 510 | stateCache.fieldSuggestions = cloneJson(pack.fieldSuggestions || {}); |
| 511 | stateCache.sectionSchemas = cloneJson(pack.sectionSchemas || {}); |
| 512 | stateCache.sections = (pack.sections || []).map((section) => ({ |
| 513 | ...section, |
| 514 | status: "Not Started", |
| 515 | notes: [], |
| 516 | content: cloneJson(pack.defaultContent?.[section.id] || {}), |
| 517 | filesChanged: [], |
| 518 | lastModified: ts, |
| 519 | })); |
| 520 | stateCache.changeLog = []; |
| 521 | stateCache.contentProposals = []; |
| 522 | stateCache.milestones = []; |
| 523 | stateCache.lastUpdated = ts; |
| 524 | addChange({ |
| 525 | type: "status_change", |
| 526 | summary: `Template pack applied: ${pack.label}.`, |
| 527 | timestamp: ts, |
| 528 | }); |
| 529 | addNote( |
| 530 | stateCache.sections[0]?.id || "hero", |
| 531 | `Applied template pack "${pack.label}".`, |
| 532 | author === "human" ? "human" : "agent", |
| 533 | ); |
| 534 | return { templatePackId: id, label: pack.label, sections: stateCache.sections }; |
| 535 | } |
| 536 | |
| 537 | function createInitialState() { |
| 538 | const ts = nowIso(); |
no test coverage detected